akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    std::ios::sync_with_stdio(false);

    int n; int a;
    cin >> n >> a;
    cout << n * n - a << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A=list(map(int,input().split()))
    A.sort()
    print(A[2]-A[0])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
    //write code  here

    int N,K;
    cin >> N >> K;

    vector<int>A(N);

    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;

        for (int j = 0; j < d; ++j) {
            int a;
            cin >> a;
            A.at(a-1)++;
        }
    }

    sort(A.begin(),A.end());
    int i=0;
    int ans = 0;
    while(A.at(i)==0){
        ans++;
        i++;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
n = int(input())
dp = [[0]*3 for _ in range(n+1)]

for i in range(n):
    abc = list(map(int, input().split()))
    dp[i+1][0] = max(dp[i][1]+abc[1], dp[i][2]+abc[2])
    dp[i+1][1] = max(dp[i][0]+abc[0], dp[i][2]+abc[2])
    dp[i+1][2] = max(dp[i][0]+abc[0], dp[i][1]+abc[1])
print(max(dp[-1]))

Measured memory_bytes: 22764
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	int res = 1;
	for (int i = 0; i < N; i++) {
		res = min(res + K, res * 2);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
"""
author : halo2halo
date : 23, Jan, 2020
"""

import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M, X, Y = map(int, readline().split())
x = [int(x) for x in readline().split()]
y = [int(y) for y in readline().split()]

x.append(X)
y.append(Y)
# print(x)
# print(y)
print("No War" if max(x)<min(y) else "War")


Measured memory_bytes: 12456
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int H = sc.nextInt();
        int W = sc.nextInt();
        
        int[][] fields = new int[H][W];
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                fields[i][j] = sc.nextInt();
            }
        }
        
        int cnt = 0;
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                
                if( fields[i][j] % 2 == 0 ) continue;
                
                if( j + 1 < W && fields[i][j] % 2 == 1 ){
                    fields[i][j]--;
                    fields[i][j+1]++;
                    cnt++;
                    sb.append( (i+1) + " " + (j+1) + " " + (i+1) + " " + (j+2) ).append("\r\n");
                } else if( i + 1 < H ){
                    fields[i][j]--;
                    fields[i+1][j]++;
                    cnt++;
                    sb.append( (i+1) + " " + (j+1) + " " + (i+2) + " " + (j+1) ).append("\r\n");
                }
            }
        }
        
        System.out.println(cnt);
        System.out.println(sb.toString());
        
    }
}


Measured memory_bytes: 94052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n,k;
    cin>>n>>k;
    vector<bool> use(10,true);
    rep(i,k){
        int d;
        cin>>d;
        use[d]=false;
    }

    for(int i=n;i<1000000;i++){
        string s=to_string(i);
        int m=s.size();
        bool ok=true;
        rep(j,m){
            int x=s[j]-'0';
            if(!use[x]){
                ok=false;
                break;
            }
        }
        if(ok){
            cout<<i<<endl;
            return 0;
        }
    }
}




Measured memory_bytes: 256
n=int(input())
l=[0 for _ in range(n)]

for i in range(n-1):
  c,s,f=map(int,input().split())
  l[i]=s+c
  for j in range(i):
    l[j]=max(s,((l[j]-1)//f+1)*f)+c  
for m in l:
  print(m)
    

Measured memory_bytes: 9056
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main(){
  string p;//A=0,Y=1,X=2,Z=3,W=4,B=5
  char now;

  for(int i=0;i<100;i++){
    now='A';
    cin >>p;
    if(p == "#")break;
    for(int j=0;j<p.size();j++){
      if(now=='A'){
	if(p[j]=='0')  now='X';
	else if(p[i]=='1') now='Y';
      }
      else if(now=='Y'){
	if(p[j]=='0') now='X';
	else if(p[j]=='1') now='D';}
      else if(now=='X'){
	if(p[j]=='1') now='Z';
	else if(p[j]=='0') now='D';}
      else if(now=='Z'){
	if(p[j]=='0')now='W';
	else if(p[j]=='1')now='B';}
      else if(now=='W'){
	if(p[j]=='0') now='B';
	else if(p[j]=='1')now='Y';}
      else if(now=='B'){
	if(p[j]=='0')now='Y';
	else if(p[j]=='1')now='X';}
     
    }
    if(now=='B')printf("Yes\n");
    else printf("No\n");
  }
	  
  return 0;}	
      

Measured memory_bytes: 1168
#include<bits/stdc++.h>
using namespace std ;
map<string ,int > mp;

int main()
{
	int n;
	cin>>n;
	string a;
	int ans=0;
	for(int i=0;i<n;i++){
		cin>>a;
		mp[a]++;
		ans=max(ans,mp[a]);
	}
	for(auto i : mp){
		if(i.second==ans){
			cout<<i.first<<endl; 
		}
	}
} 

Measured memory_bytes: 25216
import copy
from collections import defaultdict

N, M = map(int, input().split())
org_arr = [list(map(int, input().split())) for _ in range(M)]
arr = copy.copy(org_arr)
arr.sort(key=lambda x:x[1])
arr.sort(key=lambda x:x[0])

count = 1
dic = {}
for i in range(len(arr)):
    dic[arr[i][1]] = count
    if i == len(arr)-1:
        break
    if arr[i][0] == arr[i+1][0]:
        count += 1
    else:
        count =1


for i in org_arr:
    ans = str(i[0]).zfill(6)+str(dic[i[1]]).zfill(6)
    print(ans)

Measured memory_bytes: 116532
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n,a,b;

int main(void){
	scanf("%lld%lld%lld",&n,&a,&b);
	ll tu=n/(a+b);
	ll ans=tu*a;
	ll rest=n-tu*(a+b);
	ans+=min(rest,a);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
using System;
namespace q1
{
  class q2
  {
    static void Main()
    {
      string[] n = Console.ReadLine().Split();
      int N = int.Parse(n[0]);
      int M = int.Parse(n[1]);
      if(N==M)
      {
        Console.WriteLine("Yes");
      }
      else
      {
        Console.WriteLine("No");
      }
    }
  }
}


Measured memory_bytes: 27440
import collections, scipy.misc 
n, p = map(int, input().split())
a = list(map(int, input().split()))

for i in range(n):
    a[i] %= 2
c = collections.Counter(a)
zero = c[0]
one = c[1]
ans = 0
if p == 0:
    s = 0
else:
    s = 1
for i in range(s, one + 1, 2):
    ans += 2 ** zero * scipy.misc.comb(one, i, exact=True)

print(ans)

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

using namespace std;

int main()
{
  string W;
  cin >> W;
  bool f = true;
  for(char i = 'a'; i <= 'z'; i++) {
    f &= count(begin(W), end(W), i) % 2 == 0;
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, d; cin >> n >> d;

    int a = d * 2 + 1;
    int b = n / a;
    if(n <= b * a){
        cout << n / a << endl;
    }else{
        cout << n / a + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 3596
<?php
$line = fgets(STDIN);
list($w, $h, $x, $y, $r) = explode(' ', $line);

$c_l = $x - $r;
$c_r = $x + $r;
$c_t = $y + $r;
$c_b = $y - $r;

if (0 <= $c_l && $c_r <= $w && 0 <= $c_b && $c_t <= $h) echo "Yes\n";
else echo "No\n";

Measured memory_bytes: 15424
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
int64_t GCD(int64_t a,int64_t b){
    return b == 0 ? a : GCD(b, a % b);
   
}
int main(){
   int k;
   cin>>k;
   int sum=0;
   //time_t now=time();
   for(int a=1;a<=k;a++){
       for(int b=1;b<=k;b++){
           for(int c=1;c<=k;c++){
               sum += GCD(a,GCD(b,c));
           }
       }
   }
   cout<<sum<<endl;
   //cout<<time()-now<<endl;
}

Measured memory_bytes: 3636
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[][] J, O, I;
	void run() {
		Scanner sc = new Scanner(System.in);
		int m = sc.nextInt();
		int n = sc.nextInt();
		int k = sc.nextInt();
		J = new int[m+1][n+1];
		O = new int[m+1][n+1];
		I = new int[m+1][n+1];
		for(int i=1;i<=m;i++) {
			String str = sc.next();
			for(int j=1;j<=n;j++) {
				J[i][j] = J[i][j-1] + J[i-1][j] - J[i-1][j-1];
				O[i][j] = O[i][j-1] + O[i-1][j] - O[i-1][j-1];
				I[i][j] = I[i][j-1] + I[i-1][j] - I[i-1][j-1];
				switch ( str.charAt(j-1) ) {
				case 'J': J[i][j]++; break;
				case 'O': O[i][j]++; break;
				case 'I': I[i][j]++; break;
				}
			}
		}
//		for(int[] a: J) debug(a);
//		for(int[] a: O) debug(a);
//		for(int[] a: I) debug(a);
		for(int i=0;i<k;i++) {
			int p[] = new int[4];
			for(int j=0;j<4;j++) p[j] = sc.nextInt();
			int js = J[p[2]][p[3]] - J[p[2]][p[1]-1] - J[p[0]-1][p[3]] + J[p[0]-1][p[1]-1];
			int os = O[p[2]][p[3]] - O[p[2]][p[1]-1] - O[p[0]-1][p[3]] + O[p[0]-1][p[1]-1];
			int is = I[p[2]][p[3]] - I[p[2]][p[1]-1] - I[p[0]-1][p[3]] + I[p[0]-1][p[1]-1];
			System.out.println(js + " " + os + " " + is);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/12/30  Problem: AOJ 0531 / Link: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0531  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----

座標圧縮 + imos

----解説ここまで---- */

/* 入力は破壊される されたくないときはvectorをかえせばよい */
int compress(int *x1, int *x2, int w, int n) {
	vector<int>xs;
	FOR(i, 0, n) {
		for (int d = -1; d <= 1; d++) {
			if (x1[i] + d >= 0 && x1[i] + d < w)xs.push_back(x1[i] + d);
			if (x2[i] + d >= 0 && x2[i] + d < w)xs.push_back(x2[i] + d);
		}
	}
	SORT(xs);
	UNIQ(xs);
	FOR(i, 0, n) {
		x1[i] = lower_bound(ALL(xs), x1[i]) - xs.begin();
		x2[i] = lower_bound(ALL(xs), x2[i]) - xs.begin();
	}
	return SZ(xs);
}

int x1[1003];	int x2[1003];	int yy1[1003];	int y2[1003];
short int masu[5003][5003];
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int W, H, N;
	
	while (scanf("%d%d", &W, &H), H || W) {
		scanf("%d", &N);
		FOR(i, 0, N) {
			scanf("%d%d%d%d", &x1[i], &yy1[i], &x2[i], &y2[i]);
			// [1,2)
		}
		W = compress(x1, x2, W, N);
		H = compress(yy1, y2, H, N);

		
		fill(*masu, *masu + 5003 * 5003, 0);
		FOR(i, 0, N) {
			masu[ yy1[i] ][ x1[i] ]++;
			masu[ yy1[i] ][ x2[i] ]--;
			masu[ y2[i] ][ x1[i] ]--;
			masu[ y2[i] ][ x2[i] ]++;
		}
		FOR(i, 0, H + 1) {
			FOR(j, 0, W + 1) {
				masu[i][j] += (i - 1 >= 0 ? masu[i - 1][j] : 0) + (j - 1 >= 0 ? masu[i][j - 1] : 0) - (i - 1 >= 0 && j - 1 >= 0 ? masu[i - 1][j - 1] : 0);
			}
		}
		
		LL ans = 0;
		FOR(i, 0, H) {
			FOR(j, 0, W) {
				if (masu[i][j])continue;
				ans++;
				queue<PII>q;
				q.push(PII(i, j));
				while (!q.empty()) {
					PII a = q.front(); q.pop();
					int y = a.first, x = a.second;
					if (masu[y][x])continue;
					masu[y][x] = 1;
					FOR(k, 0, 4) {
						int ny = y + DY[k], nx = x + DX[k];
						if (0 <= ny&&ny < H && 0 <= nx && nx < W) {
							if (masu[ny][nx] == 0) {
								q.push(PII(ny, nx));
							}
						}
					}

				}
			}
		}
		printf("%lld\n", ans);

	}
	
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 998244353
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 100005;
int D[MAX_N];

int DD[MAX_N];

signed main()
{
  int N; cin >> N;

  REP(n,N) {
    cin >> D[n];
    DD[D[n]]++;
  }

  if(DD[0] != 1 || D[0] != 0) {
    cout << 0 << endl;
    return 0;
  }

  int ans = 1;
  FOR(i,1,N) {
    if(D[i] > 0) {
      ans *= DD[D[i]-1];
    }
    ans %= MOD;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define all(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
using ll=long long int;
using ppi=pair<ll,ll>;
using pql =priority_queue<ll, vector<ll>, greater<ll>>;
using pq=priority_queue<ll>;

int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>h(n);
    rep(i,n){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    ll ans=0;
    rep(i,n-k){
        ans+=h[i];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<queue>
using namespace std;

int main() {
	int A, B; cin >> A >> B;
	if (A >= 13)cout << B << endl;
	else if (A >= 6 && A <= 12)cout << B / 2 << endl;
	else cout << 0 << endl;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

int main(void){
    int n, m, l;
    int i, j, k;
    cin >> n >> m >> l;
    double A[100][100]={0}, B[100][100]={0}, C[100][100]={0};
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    for(i=0;i<m;i++){
        for(j=0;j<l;j++){
            cin >> B[i][j];
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<l;j++){
            for(k=0;k<m;k++){
                C[i][j]+=A[i][k]*B[k][j];
            }
            if(j==0) printf("%.0lf", C[i][j]);
            else printf(" %.0lf", C[i][j]);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3516
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 15
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, k = LI()
A = LI()
acc = [0] + list(accumulate(A))
plus_acc = [0] + list(accumulate([i if i > 0 else 0 for i in A]))
ans = -INF
for l in range(n - k + 1):
    r = l + k
    ans = max(ans, max(acc[r] - acc[l], 0) + plus_acc[l] + plus_acc[n] - plus_acc[r])

print(ans)

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

using namespace std;

int main() {
  int N, alice = 0, bob = 0;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end(), greater<int>());
  for (int i = 0; i < N; ++i) {
    if (i % 2) {
      bob += a.at(i);
    } else {
      alice += a.at(i);
    }
  }

  cout << alice - bob << endl;

  return 0;
}

Measured memory_bytes: 3592
// Header {{{
#include <bits/stdc++.h>

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

ll gcd(ll x, ll y) {
    if (x>y)
        return gcd(y,x);
    while(x!=0) {
        ll t = x;
        x = y%x;
        y = t;
    }
    return y;
}

ll lcm(ll x, ll y){
    return x/gcd(x,y)*y;
}

signed main() {
    // if m = lcm(a1,a2,..,an)-1, then f will be largest value.
    // The largest value is equal to sum of (a_i - 1).
    ll n,ans=0;
    cin>>n;
    rep(i,0,n){
        ll a;
        cin>>a;
        ans+=a-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

	int H, W, i, u;

	while (1) {

		scanf("%d %d", &H, &W);

		if (H == 0 && W == 0)break;

		for (i = 0; i < H; i++) {

			for (u = 0; u < W; u++) {

				printf("#");

			}

			printf("\n");

		}

		printf("\n");

	}
	
	return 0;

}


Measured memory_bytes: 2052
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, N: int):
    if N < B - 1:
        x = N
        print(int(A * x / B))
    else:
        x = B - 1
        print(int(A * x / B))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    N = int(next(tokens))  # type: int
    solve(A, B, N)

if __name__ == '__main__':
    main()

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

//const long double PIL = 3.141592653589793238462643383279502884L;
//const double PI = 3.14159265358979323846;

#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()
#define what_is(x) cerr << #x << " is " << x << endl;

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<long long>;
using vii = vector<pair<int,int>>;

int main() {
	//~ ios::sync_with_stdio(0);
	//~ cin.tie(0);
	int x[2];
	cin >> x[0] >> x[1];
	int answer = 0;
	for (int i = 0; i < 2; i++) {
		if (x[i] == 1)
			answer += 300000;
		else if (x[i] == 2)
			answer += 200000;
		else if (x[i] == 3)
			answer += 100000;
	}
	if (x[0] == 1 && x[1] == 1) answer += 400000;
	cout << answer << endl;
}


Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;
 
    class Program
    {
    static bool BSI(int[] a,int k)
    {
    int min = 0;
    int max = a.Length - 1;
    while (!(max < min))
    {
    var m = min + (max - min) / 2;
    if (a[m] > k)
    {
    max = m - 1;
    continue;
    }
    else if (a[m] < k)
    {
    min = m + 1;
    }else
    return true;
    }
    
    
   return false;
    }
        static void Main(string[] args)
        {
    Console.ReadLine();
var S=    Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

    Console.ReadLine();
var T=    Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
int c = 0;
foreach (var s in T)
{
c += BSI(S,s) ? 1 : 0;
}
Console.WriteLine(c);
}
    }


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int B[n-1];
    for(int i=0;i<n-1;i++) cin >> B[i];
    int A[n];
    A[n-1] = B[n-2];
    A[n-2] = B[n-2];
    for(int i=n-3;i>=0;i--){
        A[i+1] = min(A[i+1],B[i]);
        A[i] = B[i];
    }
    long ans=0;
    for(int i=0;i<n;i++) ans += A[i];
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>
#include<ctype.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void pV(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int kaku_i_no_wa(int n){
    int sum = 0;
    while(n!=0){
        sum += n % 10;
        n /= 10;
    }
    return sum;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N;
    cin >> N;

    int min = 1000;
    FOR(a, 1, N){
        int b = N - a;
        int sum = kaku_i_no_wa(a) + kaku_i_no_wa(b);
        //pn(sum);
        if(sum < min){
            min = sum;
        }
    }

    p(min);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  string s;
  cin>>s;
  if( (s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]) || (s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]) || (s[0]==s[3]&&s[2]==s[1]&&s[0]!=s[1]) ) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

fn main() {
    input! {
    s: Chars,
    t: Chars
    }
    let n = s.len();
    let mut ks = vec![0; 27];
    let mut kt = vec![0; 27];
    for i in 0..n {
        let cs = s[i] as u8 as usize - 96;
        let ct = t[i] as u8 as usize - 96;
        if (ks[cs] > 0 && ks[cs] != ct) || (kt[ct] > 0 && kt[ct] != cs) {
            println!("No");
            return
        }
        ks[cs] = ct;
        kt[ct] = cs;
    }
    println!("Yes");
}


Measured memory_bytes: 4000
// J4180449 三宅亮輔
// 問題名
// - Single Source Shortest Path 1
// 問題URL
// - https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A
// 所要時間
// -
// 学んだこと
//
//
//

#include <bits/stdc++.h>
using namespace std;

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

ll V, E, r;

ll d[100000];

struct Edge {
    ll to, cost;
};

vector<Edge> v[100000];
const ll INF = 0xfffffffffffffff;

priority_queue<P, vector<P>, greater<P> /**/> q;

int main() {
    cin >> V >> E >> r;

    for(ll i = 0; i < E; i++) {
        ll from, to, cost;
        cin >> from >> to >> cost;

        Edge e1;
        e1.to = to;
        e1.cost = cost;

        v[from].push_back(e1);
    }
    for(ll i = 0; i < V; i++)
        d[i] = INF;

    q.push(P(0, r));

    while(!q.empty()) {
        P p = q.top();
        q.pop();
        ll from = p.second;
        ll dist = p.first;
        if(d[from] <= dist)
            continue;
        d[from] = dist;

        for(ll i = 0; i < v[from].size(); i++) {
            Edge e = v[from][i];
            ll to = e.to;
            ll cost = e.cost;
            ll new_d = d[from] + cost;

            if(d[to] > new_d) {
                q.push(P(new_d, to));
            }
        }
    }

    for(ll i = 0; i < V; i++)
        if(d[i] == INF)
            cout << "INF" << endl;
        else
            cout << d[i] << endl;
}


Measured memory_bytes: 21488
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e18;
const ll mod = 1e9 + 7;

int main(){
    int q;
    cin >> q;
    REP(i,q){
        ll a ,b;
        cin >> a >> b;
        if(b < a)swap(a,b);
        if(a == b)dump(2 * a - 2);
        else if(a + 1 == b)dump(2 * a - 2);
        else {
            ll c = ceil(sqrt(a * b)) - 1;
            if(c * (c + 1) >= a * b)dump(2 * c - 2);
            else dump(2 * c - 1);
        }
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    string s;
    ll K;
    cin >> s >> K;

    ll N = s.size();
    vector<ll> len;
    REP(i, N){
    	int j = i;
    	while(j<N && s[i]==s[j]){
    		j++;
    	}
    	len.push_back(j-i);
    	i = j-1;
    }

    //cout << len << endl;

    ll res = 0;
    if(len.size()==1){
    	res = (N*K)/2;
    }else{
    	if(s[0] == s[N-1]){
    		ll tmp = 0;
    		for(int i=1;i<len.size()-1;i++){
    			tmp += len[i]/2;
    		}
    		res += K*tmp;

    		res += len[0]/2;
    		res += len.back()/2;

    		res += (K-1)*((len[0] + len.back())/2);
    	}else{
    		REP(i, len.size()){
    			res += (len[i]/2);
    		}
    		res *= K;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
    int n,k;
    cin >> n >> k;
    vector<char> v(k);
    for (int i=0;i<k;i++) cin >> v[i];
    bool ans;
    ans=true;
    bool x ;
    x=false;
    while(ans){
        string now;
        now=to_string(n);
        for (int h=0;h < now.size();h++){
            for (int j=0;j <k;j++){
                 if (now[h]==v[j]){
                     x=true;
                     break;
                 }
            }
            if (x){
                x=false;
                break;
            }
            if (h==now.size()-1) ans=false;
        }
        n++;
    }
    n--;
    cout << n << endl;
    return 0;
}


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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<tuple<int, string, int>> s(N);
    for(int i=0; i<N; ++i){
        get<0>(s[i]) = i+1;
        cin >> get<1>(s[i]) >> get<2>(s[i]);
    }
    sort(s.begin(), s.end(), [](auto l, auto r){
        if(get<1>(l)<get<1>(r)) return true;
        else if(get<1>(l)==get<1>(r)) return get<2>(l)>get<2>(r);
        else return false;
    });
    for(int i=0; i<N; ++i){
        cout << get<0>(s[i]) << endl;
    }
}


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

int n, r[1000];
long long w[1000];
bool dp[2][1001];

int main(){
  std::ios::sync_with_stdio(false);
  while(cin >> n,n){
    int sumr = 0, sumw = 0, id = 0;
    for(int i=0;i<n;i++){
      cin >> r[i] >> w[i];
      sumr += r[i]; sumw += w[i];
      if(r[id] < r[i])id = i;
    }

    int lim = 2*r[id]-sumr;
    if(lim<=0){
      cout << sumr + sumw << endl;
      continue;
    }

    for(int j=0;j<=lim;j++)dp[0][j] = false;
    dp[0][0] = true;
    
    for(int i=0;i<n;i++){
      int now = i&1, nxt = 1-now;
      for(int j=0;j<=lim;j++)dp[nxt][j] = false;
      for(int j=0;j<=lim;j++){
	if(dp[now][j]){
	  dp[nxt][j] = true;
	  if(i!=id && j+w[i]<=lim)dp[nxt][j+w[i]] = true;
	}
      }
    }
    
    int tmp = 0;
    for(int i=0;i<=lim;i++){
      if(dp[n&1][i])tmp = i;
    }
    cout << sumr + sumw + lim - tmp << endl;
  }
}

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

using namespace std;

int main() {
	string s;
	cin >> s;

	if (s == "SUN") {
		cout << 7;
	}
	else if (s == "MON") {
		cout << 6;
	}
	else if (s == "TUE") {
		cout << 5;
	}
	else if (s == "WED") {
		cout << 4;
	}
	else if (s == "THU") {
		cout << 3;
	}
	else if (s == "FRI") {
		cout << 2;
	}
	else if (s == "SAT") {
		cout << 1;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>


#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define LOWER(a,x) lower_bound(ALL(a), x) - a.begin() - 1;
#define COUNT(a,x)  upper_bound(ALL(a), x) - lower_bound(ALL(a), x);
#define MCOUNT(a,x,y) upper_bound(ALL(a), y) - lower_bound(ALL(a), x);
#define scan(x) scanf("%lld",&x);
#define inf 5555555555555555555
#define mod 1000000007
#define pi 3.14159265358979323846
#define pb push_back
#define F first
#define S second
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef map<ll, ll> MAP;
typedef set<ll> SET;
ll n = 0, m = 0, ans = 0, sum = 0, cnt = 0, tmp = 0, ma = 0, mi = 0;
string s;
bool flag, ok;
ll dx[4] = { 1,-1,0,0 }, dy[4] = { 0,0,1,-1 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

ll a[MAX];
int main(void) {
  cin >> n;
  m = (n + 1) % 2;
  a[0]++;
  ans = 1;
  FOR(i, 0, n) {
	cin >> tmp;
	if (tmp % 2 != m || a[tmp]>=2) {
	  cout << "0" << endl;
	  return 0;
	}
	if (!a[tmp]) (ans *= 2) %= mod;
	a[tmp]++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    t = LI()
    a = LI()
    b = LI()
    a[0] -= b[0]
    a[1] -= b[1]
    if t[0]*a[0] == -t[1]*a[1]:
        print("infinity")
        return
    if a[0] < 0:
        a[0] *= -1
        a[1] *= -1
    if t[0]*a[0]+t[1]*a[1] > 0:
        print(0)
        return
    A = t[0]*a[0]+t[1]*a[1]
    k = t[0]*a[0]
    l = 0
    r = 10**20
    while r-l > 1:
        x = (l+r) >> 1
        if A*x+k > 0:
            l = x
        else:
            r = x
    ans = 2*l+1
    if A*r+k == 0:
        ans += 1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 40944
import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;
 
class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a[] = new int[n];
        for(int i = 0; i < n; i++){
            int h = sc.nextInt();
            a[h-1] = i; 
        }
        for(int i = 0; i < n-1;i++){
            System.out.print((a[i]+1)+" ");
        }
        System.out.println(a[n-1]+1);
    }
}

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

int main(void) {
  int N;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  for (int i = 0; i < N - 1; i++) {
    if (A[i] == A[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = 1 << 29;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const int MAX_V = 500;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



ll gcd(ll a,ll b){
    if(b ==0) return a;
    return gcd(b,a%b);
}



void solve() {
    ll k;
    cin>>k;
    ll ans = 0;
    rep2(i,1,k+1){
        rep2(j,1,k+1){
            rep2(l,1,k+1){
                ans += gcd(gcd(i,j), l);
            }
        }
    }
    cout<<ans<<endl;

    
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);


    ll t=1;
    
    // cin>>t;

    rep(i,t){
        solve(); 
    }

    return 0;
}


Measured memory_bytes: 3636
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <math.h> // sqrt
using namespace std;

int main() {
    int X, Y;
    cin >> X >> Y;
    bool check = false;
    for (int i = 0; i < X + 1; i++) {
        if (Y - 4 * i == 2 * (X - i)) {
            cout << "Yes" << endl;
            check = true;
            break;
        }
    }
    if (!check) {
        cout << "No" << endl;
    }
}

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

using namespace std;

template<typename T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << "[";
  for (T &i: v) os << i << ",";
  os << "]";
  return os;
}

template<class TH> void _dbg(const char *sdbg, TH h){ cout<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cout<<*sdbg++;
  cout<<'='<<h<<','; _dbg(sdbg+1, a...);
}

#ifdef __DJKIM613
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#endif

typedef tuple<int, int> pii;

int dirx[4] = {0, 0, 1, -1};
int diry[4] = {1, -1, 0, 0};

int N, M;
char S[1010][1010];
int CK[1010][1010];
queue<pii> Q;
int main(void){
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr), cout.tie(nullptr);

  cin >> N >> M;
  for(int i = 1 ; i <= N ; i++) {
    for(int j = 1 ; j <= M ; j++) cin >> S[i][j];
  }

  int ans = 0;
  for(int i = 1 ; i <= N ; i++){
    for(int j = 1 ; j <= M; j++) if(S[i][j] == '#') Q.push(make_tuple(i, j)), CK[i][j] = 1;
  }

  int x, y;
  while(Q.size()){
    tie(x, y) = Q.front();  Q.pop();
    for(int i = 0 ; i < 4 ; i++) {
      int nx = x + dirx[i];
      int ny = y + diry[i];
      if(!(1 <= nx && nx <= N && 1 <= ny && ny <= M)) continue;
      if(!CK[nx][ny]) CK[nx][ny] = CK[x][y] + 1, Q.push(make_tuple(nx, ny)), ans = max(ans, CK[nx][ny] - 1);
    }
  }

  cout << ans << '\n';
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> pint;
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) 
#define repi(i,start,end) for(int i=start,temp=(int)(end);i<end;++i)
#define rfor(v,x) for(const auto& x : v) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n)
#define vsort(v) sort(v.begin(), v.end())
#define vfsort(v,lambda) sort(v.begin(),v.end(),lambda)
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,v.size()) {cin >> v[i];}
//最終奥義
//#define int long long
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 (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());
signed main(void){
  int n;cin >> n;
  vint a(n),b(n),c(n-1);
  rep(i,n){
    int t;cin >> t;
    a[i]=t-1;
  }
  vin(b);vin(c);
  
  int ans=b[a[0]];
  repi(i,1,n){
    ans+=b[a[i]];
    if(a[i-1]+1==a[i]){
      ans+=c[a[i-1]];
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[N], b[N];
char s[N], t[N] = "0keyence";
int f[N][10], g[N][10], cnt[10];
int main() {
	scanf("%s", s + 1);
	n = strlen(s + 1);
	if (s[1] == 'k') f[1][1] = 1;
	if (s[n] == 'e') g[n][7] = 1;
	for (int i = 2; i <= n; ++i)
		for (int j = 1; j < 7; ++j)
			if (f[i - 1][j] && t[j + 1] == s[i]) f[i][j + 1] = 1;
	for (int i = n - 1; i >= 1; --i)
		for (int j = 7; j > 1; --j)
			if (g[i + 1][j] && t[j - 1] == s[i]) g[i][j - 1] = 1;
	for (int i = 1; i <= n; ++i)
		for (int j = 1; j <= 7; ++j) {
			if (f[i][7] || g[i][1]) {
				puts("YES");
				return 0;
			}
			cnt[j] += g[i][j];
		}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= 7; ++j)
			cnt[j] -= g[i][j];
		for (int j = 1; j < 7; ++j) {
			if (f[i][j] && cnt[j + 1]) {
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;n>i;++i)
#define MOD 1000000007
using namespace std;
using ll=int64_t;
using pii=pair<int,int>;
using vi=vector<int>;
using VI=vector<ll>;
using vis=vector<string>;
using vvi=vector<vi>;
int gcd(int a,int b){
    if(a%b==0)
    return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
   return a*b/gcd(a,b);
}
bool prime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0)
        return false;
    }
    return true;
}
int main(){
    string s;
    cin>>s;
    int ans=0;
    if(s[0]=='S'&&s[1]=='S'&&s[2]=='S')
    ans=0;
    else if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
    ans=3;
    else if(s[0]!=s[1]&&s[0]==s[2])
    ans=1;
    else if((s[0]!=s[1]&&s[1]==s[2]&&s[1]=='R')||(s[0]==s[1]&&s[1]!=s[2]&&s[0]=='R'))
    ans=2;
    else
    ans=1;
    cout<<ans<<endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 51;
const int MAXM = 100010;
const int MAXK = 510;
const int MAXQ = 200010;

int n, m, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,n) cin >> a[i];
    int res = 0;
    FOR(j,1,m) {
        int remain = m - j;
        FOR(l,0,n) {
            int r = j - l;
            if (r < 0 || r > n || l+r > n) continue;
            vector<int> b;
            FOR(k,1,l) b.emplace_back(a[k]);
            FORE(k,n,n-r+1) b.emplace_back(a[k]);
            sort(ALL(b));
            int sum = 0;
            FOR(k,0,SZ(b)-1)
                if (b[k] < 0 && k+1 <= remain) continue;
                else sum += b[k];

            if (sum == 100) cout << l << ' ' << r << endl;
            res = max(res, sum);
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int k;
    cin >> k;
    
    queue<ll> que;

    for(int i = 1; i < 10; i++){
        que.push(i);
    }
    int count = 0;
    while(1){

        ll x = que.front();
        count++;
        
        if(count == k){
            cout << x << endl;
            return 0;
        }
        que.pop();

        if(x % 10 != 0){
            que.push(10*x + (x%10) - 1);
        }

        que.push(10*x+(x%10));

        if(x % 10 != 9){
            que.push(10*x+(x%10)+1);
        }

    }

}


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

#define PB emplace_back

using namespace std;

const int N = 1e5+100;

long long int dp[3][N], mod = 1e9+7;

vector<long long int> v[N];

void dfs(int x=0, int px=-1) {
    dp[0][x]=dp[1][x]=1;
    for(int u: v[x]) {
        if(u!=px) {
            dfs(u,x);
            dp[0][x]*=dp[1][u]+dp[0][u];
            dp[1][x]*=dp[0][u];
            dp[0][x]%=mod;
            dp[1][x]%=mod;
        }
    }
}

int main () {
    long long int n;
    cin >> n;
    for(int i = 0 ; i < n - 1 ; i++ ) {
        long long int u1, u2;
        cin >> u1 >> u2;
        u1--;
        u2--;
        v[u1].PB(u2);
        v[u2].PB(u1);
    }
    dfs();
    cout << (dp[0][0]+dp[1][0])%mod;
}


Measured memory_bytes: 13056
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<ll> cnt(1e6,0);
  ll sum=0;
  for(int i=0;i<N;i++){
    int A;
    cin >> A;
    cnt.at(A)++;
    sum+=A;
  }
  int Q;
  cin >> Q;

  for(int _=0;_<Q;_++){
    int B,C;
    cin >> B >> C;
    ll tmp=cnt.at(B);
    cnt.at(B)=0;
    cnt.at(C)+=tmp;
    sum-=B*tmp;
    sum+=C*tmp;
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 11056
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
//#include<ctype.h>
//#define pi acos(-1.0)
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
//#define MIN(a,b) a<b?a:b
int main() {
	char ans[100];
	int y, m, d;
	for (;~fscanf(stdin, "%d%d%d", &y, &m, &d); P(s, ans)) {
		int sirial = y * 416 + m * 32 + d;
		if (sirial < 777384) sprintf(ans, "%s", "pre-meiji");
		else if (sirial < 795646) sprintf(ans, "%s %d %d %d", "meiji", y - 1867, m, d);
		else if (sirial < 801625) sprintf(ans, "%s %d %d %d", "taisho", y - 1911, m, d);
		else if (sirial < 827464) sprintf(ans, "%s %d %d %d", "showa", y - 1925, m, d);
		else sprintf(ans, "%s %d %d %d", "heisei", y - 1988, m, d);
	}
	return 0;
}

Measured memory_bytes: 612