akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


bitset<13000> dp[85][85];
int A[85][85];
int B[85][85];

int main(){
  int H, W;
  cin >> H >> W;
  int ret = 0;
  rep(i,H){
    rep(j,W){
      cin >> A[i][j];
      ret += A[i][j];
    }
  }
  rep(i,H){
    rep(j,W){
      cin >> B[i][j];
    }
  }
  
  dp[0][0][abs(A[0][0]-B[0][0])+6500] = true;
  dp[0][0][abs(B[0][0]-A[0][0])+6500] = true;

  rep(i,H){
    rep(j,W){
      if(i+1<H){
        dp[i+1][j] |= (dp[i][j] << abs(A[i+1][j]-B[i+1][j]));
        dp[i+1][j] |= (dp[i][j] >> abs(A[i+1][j]-B[i+1][j]));
      }
      if(j+1<W){
        dp[i][j+1] |= (dp[i][j] << abs(A[i][j+1]-B[i][j+1]));
        dp[i][j+1] |= (dp[i][j] >> abs(A[i][j+1]-B[i][j+1]));
      }
    }
  }
  
  rep(i,13000){
    if(dp[H-1][W-1][i]){
      ret = min(ret, abs(i-6500));
    }
  }

  cout << ret << endl;
  
  return 0;
}




Measured memory_bytes: 11008
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const ll MOD = 1e9 + 7;

ll lgput(ll b, int p) {
    ll ans = 1;
    while(p) {
        if(p % 2)
          ans = (ans * b) % MOD;
        b = (b * b) % MOD;
        p /= 2;
    }
    return ans;
}

ll invmod(ll x) {
    return lgput(x, MOD - 2);
}

int main() {

    ios::sync_with_stdio(false);

    int n, m, k;
    cin >> n >> m >> k;
    vector<ll> fact(n * m + 1, 1);
    for(int i = 1; i <= n * m; i ++)
      fact[i] = (i * fact[i - 1]) % MOD;
    ll comb = (((fact[n * m - 2] * invmod(fact[k - 2])) % MOD) * invmod(fact[n * m - k])) % MOD;

    ll s = 0;
    for(int i = -(n - 1); i <= n - 1; i ++)
      for(int j = -(m - 1); j <= m - 1; j ++) {
        s = (s + (1LL * (abs(i) + abs(j)) * (n - abs(i)) * (m - abs(j))) % MOD) % MOD;
        //cout << i << " " << j << " -> " << s << endl;
       }
    s = (s * comb) % MOD;
    cout << (s * invmod(2)) % MOD;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define ld long double
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define deb(x) cout<< #x << '=' << x <<endl
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int r,c,k;
    cin>>r>>c>>k;
    char a[r][c];
    for(int i = 0; i<r; i++){
        for(int j = 0; j<c; j++){
            cin>>a[i][j];
        }
    }
    vector<int> cr(r,0) ,cc(c,0);
    int total = 0;
    for(int i = 0; i<r; i++){
        int c1 = 0;
        for(int j = 0; j<c; j++){
            if(a[i][j] == '#'){
                c1++;
                total++;
            }
        }
        cr[i] = c1;
    }
    for(int i = 0; i<c; i++){
        int c1 = 0;
        for(int j = 0; j<r; j++){
            if(a[j][i] == '#'){
                c1++;
            }
        }
        cc[i] = c1;
    }
    int ans = 0;
    int n = sz(cr);
    int m = sz(cc);
    for(int m1 = 0; m1<(1 << n); m1++){
        int sum = 0;
        int selected = 0;
        vector<int> pos;
        for(int i = 0; i<n; i++){
            if(m1 & (1 << i)){
                sum += cr[i];
                selected++;
                for(int j = 0; j<c; j++){
                    if(a[i][j] == '#'){
                        pos.pb(j);
                    }
                }
            }
        }
        int s2;
        for(int m2 = 0; m2<(1 << m); m2++){
            s2 = 0;
            int ct = 0;
            for(int i = 0; i<m; i++){
                if(m2 & (1 << i)){
                    ct = cc[i];
                    for(auto e : pos){
                        if(i == e){
                            ct--;
                        }
                    }
                    s2 += ct;
                }
            }
            if(k == total - (sum + s2)){
                ans++;
            }
        }
    }
    cout<<ans;
     
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,k[100000],sum=0;
  cin>>n;
  for(int i=0;i<n;++i){
    cin>>k[i];
    while(k[i]%2==0){
      k[i]/=2;
      sum+=1;
    }
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())
r = 0
if X == 3:
  r += 100000
if X == 2:
  r += 200000
if X == 1:
  r += 300000
if Y == 3:
  r += 100000
if Y == 2:
  r += 200000
if Y == 1:
  r += 300000
if X == 1 and Y == 1:
  r += 400000
print(r)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c; 
cin >> a >> b >> c; 
if(a > b) swap(a, b); 
if(b > c) swap(b, c); 
if(a > b) swap(a, b); 
  cout << a << " " << b << " " << c << endl;
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long n;
	cin>>n;
	long ans = 1;
	long x = pow(10,9) + 7;
	for (int i = 1; i <= n; i++){
		ans *= i;
		ans %= x;
	}
	
	cout<<ans;
	
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include <algorithm>
using namespace std;

int main()
{
	string N;
	cin >> N;
	
	int num = 0;
	for(int i=0;i<4;i++) if(N[i]=='2') num++;
	
	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin>>s;
  while ( cin>>s ) {
    int a=0;
    for ( char c: s ) {
      a+='9'-c;
    }
    cout << ( a%18>8?"Fabre":"Audrey" ) << " wins." << endl;
  }
}

Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    int n, i, j, k;
    int b, f, r, v;
    int count[4][3][10] = {0};

    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d %d %d %d", &b, &f, &r, &v);
        count[b - 1][f - 1][r - 1] += v;
    }
    
    for(i = 0; i < 4; i++){
        for(j = 0; j < 3; j++){
            for(k = 0; k < 10; k++){
                printf(" %d", count[i][j][k]);
                if(k == 9) putchar('\n');
                if(i != 3 && j == 2 && k == 9) printf("####################\n");
            }
        }
    }
    return 0;
} 


Measured memory_bytes: 3144
#include <iostream>
#include <string>

using namespace std;

int main(){
	int K, X;

	cin >> K >> X;

	int a;

	a = K * 500;

	if(a >= X){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
k=int(input())
ans=[[i for i in range(1,10)]]
d=9
while d<k:
    ans.append([])
    for i in ans[-2]:
        x=str(i)
        z=int(x[-1])
        if z==0:
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        elif 1<=z<=8:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
            ans[-1].append(x+str(z+1))
        else:
            ans[-1].append(x+str(z-1))
            ans[-1].append(x+str(z))
    d+=len(ans[-1])
l=len(ans[-1])
v=sorted([int(i) for i in ans[-1]])

print(v[k-(d-l)-1])

Measured memory_bytes: 23388
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
    while(true) {
        int n; scanf("%d", &n);
        if(n==0) break;
        char *str = new char[102];
        scanf("%s", str);
        while(n--) {
            strcat(str, "x");
            char *str2 = new char[strlen(str)*2+2];
            int idx = 0;
            char last = str[0];
            int cnt = 1;
            for(int i = 1; str[i]; i++) {
                if(last == str[i]) {
                    cnt++;
                } else {
                    idx += sprintf(str2+idx, "%d%c", cnt, last);
                    last = str[i];
                    cnt = 1;
                }
            }
            delete[] str;
            str = str2;
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n, i, j, k;
	cin >> n;
	vector<vector<bool>> c(n, vector<bool>(n, false));

	if (n % 2 == 0) {
		for (i = 0; i < n / 2; i++) {
			c[i][n - 1 - i] = true;
			c[n - 1 - i][i] = true;
		}
	}
	else {
		for (i = 0; i < n / 2; i++) {
			c[i][n - 2 - i] = true;
			c[n - 2 - i][i] = true;
		}
	}

	vector<pair<int, int>> ans;
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++) {
			if (!c[i][j]) ans.push_back({ i, j });
		}
	}

	cout << ans.size() << "\n";
	for (auto p : ans) cout << p.first + 1 << " " << p.second + 1 << "\n";


	return 0;
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
#define p pair<pair<string,int>,int>
using namespace std;
int main(){
	string S;
	cin>>S;
	int part1=stoi(S.substr(0,2));
	int part2=stoi(S.substr(2));
	if(part1>0 && part1<=12 && part2>0 && part2<=12){
		cout<<"AMBIGUOUS";
	}else if(part1>0 && part1<=12){
		cout<<"MMYY";
	}else if(part2>0 && part2<=12){
		cout<<"YYMM";
	}else{
		cout<<"NA";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int v[21],c[21];

int main(){
    int n;
    int out=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    for(int i=0; i<n; i++){
        cin>>c[i];
        if(v[i]>c[i]){
            out+=v[i]-c[i];
        }
    }

    cout<<out<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P; 

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, init, n) for(ll i = init; i <(ll)(n); i++)

int main() {

    int N;
    cin >> N;
    cout << (N / 3) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int dp[1001][1001];
bool field[1001][1001];
int main(){
    int n,w,h;
    while(scanf("%d%d%d",&h,&w,&n),n){
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
                scanf("%d",&field[i][j]);

        fill(*dp,*dp+1001*1001,0);
        dp[0][0]=n-1;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                int latte=dp[i][j];
                dp[i+1][j]+=latte/2;
                dp[i][j+1]+=latte/2;
                if(latte&1){
                    if(field[i][j])dp[i][j+1]++;
                    else dp[i+1][j]++;
                }
            }
        }

        int y=0,x=0;
        while(true){
            if(y>=h||x>=w){
                printf("%d %d\n",y+1,x+1);
                break;
            }
            if(dp[y][x]&1)field[y][x]=field[y][x]?false:true;
            if(field[y][x])x++;
            else y++;
        }
    }

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            printf("%d ",dp[i][j]);
        }
        puts("");
    }

    return 0;
}

Measured memory_bytes: 5924
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [0] * N
dp[0] = 0
temp = [10**4] * K


for n in range(1, N):
	#print(dp)
	if n < K:
		for k in range(n):
			temp[k] = dp[k] + abs(h[n] - h[k])
			
	else:
		for k in range(K):
			temp[k] = dp[n - k - 1] + abs(h[n] - h[n - k - 1])
	dp[n] = min(temp)
	#print(temp)

#print(dp)
print(dp[N - 1])

Measured memory_bytes: 52448
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,i,temp = 0,count = 0;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i <n;++i){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    int ans = 0;
    for(i = 0;i < n;++i){
        if(a.at(i) != temp){
            temp = a.at(i);
            ans += count%2;
            count = 1;
        }else{
            ++count;
        }
    }
    ans += count%2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;


int main() {
    double a, t, r;
    double mp, res;
    cin >> a >> t >> r;
    mp = a / t;
    res = r / mp;
    if (fmod(res, 1) == 0.0) {
        printf("%.1f\n", res);
    } else {
        printf("%.6f\n", res);
    }
    return 0;
}



Measured memory_bytes: 3356
#include <iostream>
#include <vector>

using namespace std;

const int max_lim = 50001;
bool prime[max_lim];
vector<int> look;

void init()
{
    for (int i = 0; i < max_lim; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < max_lim; i++) 
        for (int j = 2 * i; j < max_lim; j += i)
            prime[j] = false;

    for (int i = 2; i < max_lim; i++)
        if (prime[i])
            look.push_back(i);
}

int main()
{
    int n;

    init();
    while (cin >> n, n) {
        int ans = 0;

        for (int i = 0; 2 * look[i] <= n; i++) 
            if (n - look[i] > 0 && prime[n - look[i]])
                ans++;

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1320
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main() {
    ll h,w;
    string a[1001];
    std::cin >> h>>w;
    for (int i = 0; i < h; i++) {
        std::cin >> a[i];
    }
    ll dp[1001][1001];
    
    ll mod = 1000000000 + 7;
    
    dp[0][0] = 1;
    
    for (int i = 0; i < h; i++) {
        
        for (int j = 0; j < w; j++) {
            if(i!=0 || j!=0){
                dp[i][j] = 0;
            }
            if(a[i][j]=='#'){
                continue;
            }
            if(i>0){
                if(a[i-1][j]=='.'){
                    dp[i][j] += dp[i-1][j];
                    dp[i][j] %= mod;
                }
            }
            if(j>0){
                if(a[i][j-1]=='.'){
                    dp[i][j] += dp[i][j-1];
                    dp[i][j] %= mod;
                }
            }
        }
    }
    
    std::cout << dp[h-1][w-1] << std::endl;
    
}

Measured memory_bytes: 9088
/*May The Force Be With Me*/
#include <bits/stdc++.h>
#include <stdio.h>
#include <ctype.h>
#pragma GCC optimize ("Ofast")
#define ll long long
#define MOD 1000000007
#define endl "\n"
#define vll vector<long long>
#define mll map<long long,long long>
#define pll pair<long long, long long>
#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define pb push_back
#define f first
#define s second
#define inf INT_MAX
#define size_1d 10000000
#define size_2d 1000
#define rep(i,v,n) for(ll i = v; i < n; i++)
//Snippets: delta, sieve, fastexp, dfs, bfs, dijkstra, floodfill

using namespace std;

ll n;

void Input() {
	cin >> n;
}

void Solve() {
	vector<double> a(n + 1);
	for (ll i = 1; i <= n; i++) cin >> a[i];
	vector<double> b(n + 1, 0);
	b[0] = 1;
	for (ll i = 1; i <= n; i++) {
		for (ll j = i; j >= 1; j--) {
			b[j] += a[i] * b[j - 1];
			b[j - 1] = (1 - a[i]) * b[j - 1];
		}
	}
	double ans = 0;
	for (ll i = n / 2 + 1; i <= n; i++)ans += b[i];
	cout.precision(12);
	cout << ans;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll T = 1;
	//cin >> T;
	//ll t = 1;
	while (T--) {
		Input();
		//cout << "Case " << t << ": ";
		Solve();
		//t++;
	}
	return 0;
}

Measured memory_bytes: 3892
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
//#include <functional>
#include <queue>
//#include <stack>
//#include <set>
#include <cmath>
//#include <bitset>
#include <map>
using namespace std;
typedef long long ll;

int main() {
  int N,K;
  cin >> N >> K;
  int V[N];
  for(int i=0; i<N; i++){
    cin >> V[i];
  }
  ll ans = 0;
  for(int i=K; i>=0; i--){
    //    if(i%2 != K%2) continue;
    //    if(K%2==1 && i==K/2) continue;
    if(i > N) continue;
    int toru = max(0,i - (K-i));
    //    int modosu = K-i;
    int hidari=i;
    int migi=0;
    for(int l=0; l <= i; l++){
      int value[i];
      for(int j=0; j<hidari; j++){
	value[j] = V[j];
      }
      for(int j=0; j<migi; j++){
	value[j+hidari] = V[N-1-j];
	//	cout << "migi " << V[N-1-j] << endl;
      }
      sort(value, value+i);
      ll tmp_ans=0;
      ll tmp_ans_2=0;
      //      cout << "toru "<<toru << endl;
      for(int j=0; j < toru; j++){
	  tmp_ans += value[i-1-j];	  
      }
      for(int j=toru; j < i; j++){
	if(value[i-1-j] > 0){
	  tmp_ans += value[i-1-j];
	}
      }
      
      hidari--;
      migi++;    
      ans= max(ans, tmp_ans);
    }
  }

  cout << ans << endl;
	       
	       


  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		String s=in.next();
		if(s.charAt(0)!=s.charAt(1)||s.charAt(0)!=s.charAt(2)||s.charAt(1)!=s.charAt(2))
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
	}
}
	

Measured memory_bytes: 23892
N, x = map(int, input().split())
A = [int(_) for _ in input().split()]

eat = 0
for i in range(N-1):
    if A[i] + A[i+1] > x:
        over = A[i]+A[i+1]-x
        A[i+1] -= min(over, A[i+1])
        eat += over

print(eat)

Measured memory_bytes: 14540
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    int s = 0;

    // 入力
    cin >> s;

    // 100の位
    a = s / 100;

    // 10の位
    b = (s / 10) % 2;

    // 1の位
    c = s % 2;

    // 出力
    cout << a + b + c << endl;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans;
  if (N%2 == 0) {
    ans = N/2*N/2;
  }
  else {
    ans = N/2*(N/2+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a,b;
	char c,d;
	scanf("%d%c%c%d",&a,&d,&c,&b);
	while(c=='+'||c=='-'||c=='*'||c=='/'){
		if(c=='+') printf("%d\n",a+b);
		else if(c=='-') printf("%d\n",a-b);
		else if(c=='*') printf("%d\n",a*b);
		else printf("%d\n",a/b);
		scanf("%d%c%c%d",&a,&d,&c,&b);
	}
	return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main(){
    int s;
    cin>>s;
    ll mod = 1e9+7;
    vector<ll> a(s+1,0);
    a[0] = 1;
    for(int i=0; i<s; i++){
        for(int j=3; j+i<=s; j++){
            a[j+i] += a[i];
            a[j+1] %= mod;
            a[i] %= mod;
        }
    }
    cout<<a[s]%mod<<endl;
}

Measured memory_bytes: 3636
#[allow(unused_macros)]
macro_rules! p {
    ($x:expr $(, $tail:expr)*) => {
        let mut s = String::new();
        s.push_str(format!("{:?}", $x).as_str());
        $(
            s.push_str(format!(", {:?}", $tail).as_str());
        )*
        println!("{}", s);
    };
}

#[allow(unused_macros)]
macro_rules! pl {
    ($($x:expr), *) => {
        $(println!("{:?}", $x);)*
    };
}

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    println!("{}", solve(stdin!()));
}

fn solve(src: String) -> String {
    input! {
        source = src,
        h: i32,
        w: i32,
        hh: i32,
        ww: i32,
    }
    let mut ans = h * w;
    ans -= hh * w;
    ans -= ww * h;
    ans += std::cmp::min(hh,ww) * std::cmp::max(hh,ww);
    ans.to_string()
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input.to_string()), $output);
            )*
        }
    };
}

test! {
r"3 2
2 1
" => "1",
r"5 5
2 3
" => "6",
r"2 4
2 4
" => "0",
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;

int main() {
  int dice[6];
  for (int i=0; i<6; i++) cin >> dice[i];
  int mdice[6];
  for (int i=0; i<6; i++) cin >> mdice[i];

  string s = "XEEENEEENEEESEEESEEENEEEN";
  string ans = "No";

  for (int i=0; i<s.size(); i++) {
    int temp = dice[0];
    switch(s[i]) {
    case 'E':
      dice[0] = dice[3];
      dice[3] = dice[5];
      dice[5] = dice[2];
      dice[2] = temp;
      break;
    case 'W':
      dice[0] = dice[2];
      dice[2] = dice[5];
      dice[5] = dice[3];
      dice[3] = temp;
      break;
    case 'S':
      dice[0] = dice[4];
      dice[4] = dice[5];
      dice[5] = dice[1];
      dice[1] = temp;
      break;
    case 'N':
      dice[0] = dice[1];
      dice[1] = dice[5];
      dice[5] = dice[4];
      dice[4] = temp;
      break;
    }

    if ((dice[0] == mdice[0]) && (dice[1] == mdice[1]) && (dice[2] == mdice[2]) &&
        (dice[3] == mdice[3]) && (dice[4] == mdice[4]) && (dice[5] == mdice[5]))
      ans = "Yes";
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    long W;
    cin >> W;
    
    
    vector<long> wt(n);
    vector<long long> val(n);
    
    for(int i=0;i<n;i++)
    {
        cin >> wt[i] >> val[i];
    }
    
    
    long long dp[n+1][W+1];
    
    for(long i=0;i<=W;i++)
        dp[0][i] = 0;
    for(int i=0;i<=n;i++)
        dp[i][0] = 0;
    
    for(int i=1;i<=n;i++)
    {
        for(long j=1;j<=W;j++)
        {
            if(wt[i-1]<=j)
            {
                dp[i][j] = max(val[i-1]+dp[i-1][j-wt[i-1]],dp[i-1][j]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout << dp[n][W] << "\n";
}

Measured memory_bytes: 82340
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long INF = 1LL << 60;
template <class T> bool chmin(T& a, T b){if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b){if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int main()
{
  int D, N;
  cin >> D >> N;
  
  if (N == 100) N++;
  
  int ans = pow(100, D) * N;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int pos;
  bool flag = false;
  string s, t;

  cin >> s >> t;

  for (int i = (int)s.size() - (int)t.size(); i >= 0 && !flag; i--) {
    for (int j = 0; j < (int)t.size() && !flag; j++) {
      if (s[i + j] != t[j] && s[i + j] != '?') {
        break;
      } else if (j == (int)t.size() - 1) {
        pos = i;
        flag = true;
      }
    }
  }

  if (flag) {
    for (int i = 0; i < (int)s.size(); i++) {
      if (i == pos) {
        cout << t;
        i += (int)t.size() - 1;
      } else if (s[i] == '?') {
        cout << 'a';
      } else {
        cout << s[i];
      }
    }
  } else {
    cout << "UNRESTORABLE";
  }

  return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
p = [int(i) for i in input().split()]
graph = [[] for _ in range(n+1)]
group = [0]*(n+1)
ans = 0
for _ in range(m):
    x, y = map(int, input().split())
    graph[x].append(y)
    graph[y].append(x)
for i, num in enumerate(p, 1):
    space = [i]
    for point in space:
        if group[point]:
            continue
        group[point] = i
        space.extend(graph[point])
    ans += group[num] == group[i]
print(ans)


Measured memory_bytes: 28900
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

func setBit(d, n int) int {
	t := 1 << uint(n)
	return d | t
}

func intAbs(n int) int {
	return int(math.Abs(float64(n)))
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	S := readBigLine()
	K, _ := strconv.ParseInt(readBigLine(), 10, 64)

	for i := int64(0); i < K; i++ {
		s := string(S[i])
		if s != "1" {
			fmt.Println(s)
			return
		}
	}
	fmt.Println("1")
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int N,a,b,c,d;
  a=0;
  b=0;
  c=0;
  d=0;
  cin >> N;
  rep(i,N){
    string S;
    cin >> S;
    if(S=="AC"){
      a++;
    }
    else if (S=="WA"){
      b++;
    }
    else if (S=="TLE"){
      c++;
    }
    else if (S=="RE"){
      d++;
    }
  }
  cout << "AC x " << a << endl;
  cout << "WA x " << b << endl;
  cout << "TLE x " << c << endl;
  cout << "RE x " << d << endl;
  
}

Measured memory_bytes: 3628
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
diff_list = []
for i in range(N):
  tmp = T - H[i]*0.006
  diff = abs(A-tmp)
  diff_list.append(diff)
ans = diff_list.index(min(diff_list)) + 1
print(ans)

Measured memory_bytes: 62656
# -*- coding: utf-8 -*-
import numpy as np

inputs = input().split(' ')
N = int(inputs[0])
M = int(inputs[1])
cards = input().split(' ')
cards = [int(x) for x in cards]
cards.sort()

BC = []
for _ in range(M):
    inputs = input().split(' ')
    inputs = [int(x) for x in inputs]
    BC.append({'B': inputs[0], 'C': inputs[1]})

idx = 0
BC.sort(key=lambda x: x['C'], reverse=True)
for bc in BC:
    if idx >= N:
        break
    for _ in range(bc['B']):
        c = bc['C']
        if cards[idx] >= c:
            break
        else:
            cards[idx] = c
            idx += 1
            if idx >= N:
                break

print(sum(cards))

Measured memory_bytes: 54392
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n;
	cin>>n;
	set<int> num;
	rep(i,n){
		int a;
		cin>>a;
		if(num.count(a)){
			num.erase(num.find(a));
		}else{
			num.insert(a);
		}
	}
	cout<<num.size()<<endl;
}

Measured memory_bytes: 4992
//abc151_c.cpp
//Sun Jan 12 20:59:39 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	ll n,m;
	cin >> n >> m;

	int done[n];
	fill(done,done+n,0);
	ll wrong[n];
	fill(wrong,wrong+n,0);
	for (int i=0;i<m;i++){
		int p;
		string s;
		cin >> p >> s;
		p--;
		if (done[p]==0){
			if (s=="AC"){
				done[p] = 1;
			}else {
				wrong[p]++;
			}
		}
	}

	ll anscorrect = 0;
	ll answrong = 0;
	for (int i=0;i<n;i++){
		if (done[i]==1){
			anscorrect++;
			answrong += wrong[i];
		}
	}

	cout << anscorrect << " " << answrong << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;

int main(void){
    int ans=0,n,dish_num,A[20],B[20],C[20];
    cin >> n;
	for(int i=0;i<n;i++){
		cin >> A[i];
	}
	for(int i=0;i<n;i++){
		cin >> B[i];
	}
	for(int i=0;i<n-1;i++){
		cin >> C[i];
	}

	for(int i=0;i<n;i++){
		dish_num = A[i];
		// Bの得点処理
		ans = ans + B[dish_num-1];

		// Cの得点処理
		if(i >= 1){
			if(A[i] - A[i-1] == 1){
				ans = ans + C[dish_num-2];
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")`  

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int x = 100;
    for (int i = 0; i < 4000; i++) {
        if (x >= n) {
            cout << i << "\n";
            return 0;
        }
        x += x/100;
    }
}
/*

*/  


Measured memory_bytes: 3636
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll A, ll B) {
  int ans{0};
  if (A>=13) {
    ans = B;
  } else if (A>=6) {
    ans = B/2;
  }
  cout << ans << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  solve(A, B);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
typedef long long ll;
typedef pair<int, int> P;

int main(){
  int n;
  string sn;
  set<string> s;
  int i;
  cin >>n;
  rep(i,n){
  cin>>sn;
  s.insert(sn);}
    
  cout<<s.size();
  return 0;
}

Measured memory_bytes: 19252
// ConsoleApplication11.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << a + b / 2 << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#define FOR(i,k,n) for((i)=(k);(i)<(n);(i)++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define pb push_back
#define all(a) (a).begin(),(a).end()  //greater<int>()
using namespace std;

int main(){
	int N,i,a,count;
	count = 0;
	cin>>N;
	vector<int> A;

	REP(i,N){
   		cin>>a;
   		A.pb(a);
	}

	REP(i,N){
		if(A[i]%2==1) count+=1;
	}

	if(count%2==0){
		cout<<"YES"<<endl;
		return 0;
	}


	cout<<"NO"<<endl;
   	return 0;
}


Measured memory_bytes: 892
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<time.h>
#include<iomanip>
#define PI 3.14159265358979

using namespace std;
typedef unsigned long long ull;

template<typename T>
double rad(T r) {
	return r * 180 / acos(-1);
}

int main() {
	double a, b, x_;
	cin >> a >> b >> x_;
	double x = x_ / a;
	if (x * 2 / b <= a) {
		cout << setprecision(200) << rad(atan2(b, x * 2 / b))<< endl;
	}
	else {
		double y = x * 2 / a - b;
		cout << setprecision(200) << rad(atan2(b - y, a)) << endl;
	}
}

/*
*/

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>

typedef long long ll;

typedef struct{
    long long big;
    long long small;
    long long sum;
    long long takahashi;
    long long aoki;
} food_t;

int strsort(const void *A, const void *B){
    ll P;
    P=((food_t*)A)->big-((food_t*)B)->big;
    if (P!=0){return -1*P;}
    P=((food_t*)A)->small-((food_t*)B)->small;
    if (P!=0){return -1*P;}
    return 0;
}

int strsort2(const void *A, const void *B){
    ll P;
    P=((food_t*)A)->sum-((food_t*)B)->sum;
    if (P!=0){return -1*P;}
    P=((food_t*)A)->small-((food_t*)B)->small;
    if (P!=0){return -1*P;}
    return 0;
}

long long max(long long A,long long B){
    return A>B?A:B;
}

long long min(long long A,long long B){
    return A<B?A:B;
}

int main(void){
    int n;
    scanf("%d",&n);
    long long a[n],b[n],ans=0;
    food_t food[n];
    for (int i=0; i<n; i++){
        scanf("%lld%lld",&a[i],&b[i]);
        food[i].big=max(a[i],b[i]);
        food[i].small=min(a[i],b[i]);
        food[i].sum=a[i]+b[i];
        food[i].takahashi=a[i];
        food[i].aoki=b[i];
    }
    qsort (food,n,sizeof(food_t),strsort2);
    for (int i=0; i<n; i++){
        if (i%2==0){
            ans+=food[i].takahashi;
        } else {
            ans-=food[i].aoki;
        }
    }
    printf("%lld\n",ans);
    return 0;   
}

Measured memory_bytes: 7164
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 5005;
const int MAX_K = 5005;

int N, K;
vector<int> a;
bool dp[MAX_N][MAX_K]; // dp[x][y] := x 枚目をみたとき、総和を y にできるか？

bool solve(int x){

	memset(dp, false, sizeof(dp));
	dp[0][0] = true;
	rep (j, N){
		rep (k, K){
			if (dp[j][k]){
				dp[j+1][k] |= true;
				if (x != j && k + a[j] < K) dp[j + 1][k + a[j]] |= true;
			} // end if
		} // end rep
	} // end rep

	for (int k = max(0, K - a[x]); k < K; ++k){
		if (dp[N][k]){	
			return true;
		} // end if
	} // end for

	return false;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> K;
	a.clear(); a.resize(N, 0);
	rep (i, N){
		cin >> a[i];
	} // end rep

	sort(ALL(a));

	int ok = N;
	int ng = -1;
	while(abs(ok - ng) > 1){
		int mid = (ok + ng) / 2;
		if (solve(mid)){
			ok = mid;
		}else{
			ng = mid;
		} // end if
	} // end while
	
	cout << ok << endl;

	return 0;
}

Measured memory_bytes: 24704
n = int(input())
a =list(map(int,input().split()))
s =sum(a)
x = [0]*1000001
for i in a:
    x[i] += 1

q = int(input())
for i in range(q):
    b,c = map(int,input().split())
    s -= b*x[b]
    s += c*x[b]
    x[c] += x[b]
    x[b] = 0
    print(s)

Measured memory_bytes: 23632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string word,ans;
    int i=0;
    while(cin>>word)
    {   i++;
         ans+=(word[0]-32);
        if(i==3)
        {
            cout<<ans<<endl;
            i=0;
            ans="";
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <set>
#include <math.h>
#include <cmath>
#define ll long long

using namespace std;

int main(){

  int X;
  cin >> X;

  int F = X / 500;
  X = X % 500;
  int f  = X / 5;
  cout << F*1000 + f*5 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int N, ans=0;
	string S;

	cin >> S;
	N = S.length();

	if( S.length() < 26 ){
		char add = 'a';
		rep(i,26) for(auto c: S) if( add == c ) add++;
		cout << S + add << endl;
	}else if( S == string("zyxwvutsrqponmlkjihgfedcba") ){
		cout << -1 << endl;
		return 0;
	}else{
		// priority_queue<char> que;
		// que.push(S.back());
		// S.pop_back();
		// while( S.back() > que.top() ){
		// 	que.push(S.back());
		// 	S.pop_back();
		// }
		string ans;
		rrep(i,N) if( S[i-1] < S[i] ){
			ans = S.substr(0, i-1);
			vector<char> v;
			char nex = 'z';
			reps(j,i-1,N){
				if( S[j] > S[i-1] ) chmin(nex, S[j]);
				v.push_back(S[j]);
			}
			sort(all(v));
			ans += nex;
			//for(auto c: v) if(c != nex) ans += c;
			break;
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int a;
	cin >> a;
	if (a>=400 && a<=599){
		cout << 8;
	}
	else if (a>=600 && a<=799){
		cout << 7;
	}
	else if (a>=800 && a<=999){
		cout << 6;
	}
	else if (a>=1000 && a<=1199){
		cout << 5;
	}
	else if (a>=1200 && a<=1399){
		cout << 4;
	}
	else if (a>=1400 && a<=1599){
		cout << 3;
	}
	else if (a>=1600 && a<=1799){
		cout << 2;
	}
	else{
		cout << 1;
	}
}

	

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct Dinic{
  const int INF=1<<28;
  
  struct edge {
    int to,cap,rev;
    edge(){}
    edge(int to,int cap,int rev):to(to),cap(cap),rev(rev){}
  };

  int n;
  vector<vector<edge> > G;
  vector<map<int,int> > M;
  vector<int> level,iter;

  Dinic(){}
  Dinic(int sz):n(sz),G(n),M(n),level(n),iter(n){}
  
  void add_edge(int from,int to,int cap){
    M[from][to]=G[from].size();
    M[to][from]=G[to].size();
    G[from].push_back(edge(to,cap,G[to].size()));
    // undirected
    //G[to].push_back(edge(from,cap,G[from].size()-1));
    // directed
    G[to].push_back(edge(from,0,G[from].size()-1));
  }
  
  void bfs(int s){
    fill(level.begin(),level.end(),-1);
    queue<int> que;
    level[s]=0;
    que.push(s);
    while(!que.empty()){
      int v=que.front();que.pop();
      for(int i=0;i<(int)G[v].size();i++){
	edge &e = G[v][i];
	if(e.cap>0&&level[e.to]<0){
	  level[e.to]=level[v]+1;
	  que.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v,int t,int f){
    if(v==t) return f;
    for(int &i=iter[v];i<(int)G[v].size();i++){
      edge &e=G[v][i];
      if(e.cap>0&&level[v]<level[e.to]){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d>0){
	  e.cap-=d;
	  G[e.to][e.rev].cap+=d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s,int t,int lim){
    int flow=0;
    for(;;){
      bfs(s);
      if(level[t]<0||lim==0) return flow;
      fill(iter.begin(),iter.end(),0);
      int f;
      while((f=dfs(s,t,lim))>0){
	flow+=f;
	lim-=f;
      }
    }
  }

  int max_flow(int s,int t){
    return max_flow(s,t,INF);
  }

  //cap==1 only
  bool back_edge(int s,int t,int from, int to){
    for(int i=0;i<(int)G[from].size();i++) {
      edge& e=G[from][i];
      if(e.to==to) {
	if(e.cap==0&&max_flow(from,to,1)==0) {
	  max_flow(from,s,1);
	  max_flow(t,to,1);
	  return 1;
	}
      }
    }
    return 0;
  }
};
//END CUT HERE

signed main(){
  int V,E;
  cin>>V>>E;
  Dinic dinic(V);
  for(int i=0;i<E;i++){
    int u,v,c;
    cin>>u>>v>>c;
    dinic.add_edge(u,v,c);
  }
  cout<<dinic.max_flow(0,V-1)<<endl;
  return 0;
}

/*
  verified on 2017/06/29
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=jp
*/

Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std; 

#define sz(x) ((int)x.size())
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll; 


string s; 
bool can_reach(int p, int q){
  while(p!=q){
    if(p+1<=q && s[p+1]!='#'){
      p++; 
    }
    else if(p+2<=q && s[p+2]!='#'){
      p+=2;
    }
    else {
      break; 
    }
  }
  return p==q; 
}

bool can_cross(int p, int q){
  for(int i=p;i+2<=q;i++){
    if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.'){
      return 1;
    }
  }
  return 0; 
}

int main(){
  int n,a,b,c,d; 
  cin>>n>>a>>b>>c>>d>>s; 
  a--; b--; c--; d--; 
  if(can_reach(a,c) && can_reach(b,d) && c<d){
    cout<<"Yes"<<endl; 
  }
  else if( c>d && can_reach(a,c) && can_reach(b,d) && can_cross(b-1,d+1)){
    cout<<"Yes"<<endl; 
  }
  else {
    cout<<"No"<<endl; 
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, n)
    {
        ans += (1 + i) * (n - i);
    }
    rep(i, n - 1)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if (a > b)
            swap(a, b);
        ans -= (a + 1) * (n - b);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main () {
    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> x(n);
        for (int i = 0; i < n; i++) {
            cin >> x[i];
        }

        if (n <= k) {
            cout << 0 << endl;
            continue;
        }

        sort(x.begin(), x.end());
        vector<int> diff(n - 1);
        for (int i = 0; i < n - 1; i++) {
            diff[i] = x[i + 1] - x[i];
        }
        sort(diff.begin(), diff.end());

        long long sum = 0;
        for (int i = 0; i < n - k; i++) {
            sum += diff[i];
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 1860
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  int a[3];
  C3(a[0],a[1],a[2]);
  int s5=0;
  bool s7 = false;
  rep(i,0,3){
    if(a[i] == 5 )
      s5++;
    else if(a[i] == 7)
      s7 = true;
    else{
      NO;
      ret 0;
    }
  }

  if(s7&&s5==2)
    YES;
  else
    NO;
  ret 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		TreeMap<String,List<Integer>> map=new TreeMap<>();
		int q=Integer.parseInt(in.next());
		for(int i=0;i<q;i++) {
			int odr=Integer.parseInt(in.next());
			
			switch(odr) {
			case 0:
				String key0=in.next();
				int x0=Integer.parseInt(in.next());
				List<Integer> ls0;
				if(map.containsKey(key0)) {
					ls0=map.get(key0);
					ls0.add(x0);
					map.put(key0,ls0);
				}
				else {
					ls0=new ArrayList<>();
					ls0.add(x0);
					map.put(key0, ls0);
				}
				break;
				
			case 1:
				String key1=in.next();
				if(map.containsKey(key1)) {
					List<Integer> ls1=map.get(key1);
					for(int j=0;j<ls1.size();j++)out.println(ls1.get(j));
				}
				break;
				
			case 2:
				String key2=in.next();
				map.remove(key2);
				break;
				
			case 3:
				String L=in.next(),R=in.next();
				NavigableMap<String,List<Integer>> sub=map.subMap(L, true, R, true);
				Iterator<NavigableMap.Entry<String,List<Integer>>> itr=sub.entrySet().iterator();
				while(itr.hasNext()) {
					NavigableMap.Entry<String,List<Integer>> entry=itr.next();
					List<Integer>ls3=entry.getValue();
					String key3=entry.getKey();
					for(int j=0;j<ls3.size();j++) {
						out.println(key3+" "+ls3.get(j));
					}
				}
				break;
			}
		}
		out.flush();
	}

}


Measured memory_bytes: 138420