akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <iostream>
#include <cstring> 
#include<algorithm>
#include<numeric>
#include<vector>
#define lowbit(x) x&-x
#define il inline
#define mod 1000000007
#define inf 1000000000
#define maxn 10000005
#define maxprime 3000005
using namespace std;
typedef long long int ll;
ll n,k;
inline int read() {
    ll ress = 0;
    char cd = getchar();
    while(!isdigit(cd)) cd = getchar();
    while(isdigit(cd)) ress = (ress << 1) + (ress << 3) + (cd ^ 48), cd = getchar();
    return ress;
}
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",max(a+b,max(a-b,a*b)));
}

Measured memory_bytes: 256
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
import bisect
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
#
# インデックス系
# int min_y = max(0, i - 2), max_y = min(h - 1, i + 2);
# int min_x = max(0, j - 2), max_x = min(w - 1, j + 2);
#
#
import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
#mod = 998244353
from sys import stdin
readline = stdin.readline
def readInts():
  return list(map(int,readline().split()))
def readTuples():
    return tuple(map(int,readline().split()))
def I():
  return int(readline())
s = input()
l = len(s)
ans = [1] * l
for i in range(l):
    if s[i] == 'R' and s[i+1] == 'R':
        ans[i+2] += ans[i]
        ans[i] = 0
for i in range(l-1,0,-1):
    if s[i-1] == 'L' and s[i] == 'L':
        ans[i-2] += ans[i]
        ans[i] = 0
print(*ans)


Measured memory_bytes: 12092
#include <bits/stdc++.h>
using namespace std;
int main() {
   // cout<<"Hello World!";
   int n;
   cin>>n;
   int a;
   double b;
   for(int i=0;i<n;i++){
       cin>>a;
       b+=1.0/a;
   }
   cout<<fixed<<setprecision(12)<<1.0/b<<endl;

   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { -1, 0, 0, 1 };
const ll dy[4] = { 0, -1, 1, 0 };
const ll INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
struct Accelerate_Cin {
	Accelerate_Cin() {
		cin.tie(0);
		ios::sync_with_stdio(0);
		cout << fixed << setprecision(20);
	};
};
///////////////////////////////////////

//解１：完全グラフの辺に各値をあてはめる
int main() {
	int N; cin >> N;
	int k = 0;
	for (int i = 1; i <= sqrt(2 * N)+1; ++i) {
		if (i*(i - 1) == 2 * N) {
			k = i;
		}
	}
	if (k == 0)cout << "No" << endl;
	else {
		cout << "Yes" << endl;
		cout << k << endl;
		vector <vector<pii>>G;
		G.resize(k);
		const int m = k + (k - 1) / 2;
		vector<bool>visited(m);
		int key = 1;
		for (int i = 0; i < k; ++i) {
			for (int j = i + 1; j < k; ++j) {
				G[i].push_back({ j,key });
				G[j].push_back({ i,key });
				key++;
			}
		}
		for (int i = 0; i < k; ++i) {
			cout << k - 1 << " ";
			for (int j = 0; j < k - 1; ++j) {
				cout << G[i][j].second << " ";
			}
			cout << endl;
		}
	}
	return 0;
}


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

int main(){
  int a,b,ab,x,y;
  cin >> a >> b >> ab >> x >> y;
  int ans=0;
  if(a+b>ab*2){
    ans+=min(x,y)*ab*2;
    if(x>y){
      ans+=min(ab*(x-y)*2,a*(x-y));
    }else{
      ans+=min(ab*(y-x)*2,b*(y-x));
    }
  }else{
    ans=a*x+b*y;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int n = stdIn.nextInt();
        int[] t = new int[n+1];
        for(int i=0;i<n*(n-1)/2;i++){
            int a = stdIn.nextInt();
            int b = stdIn.nextInt();
            int c = stdIn.nextInt();
            int d = stdIn.nextInt();
            if(c>d){
                t[a]+=3;
            }
            else if(c<d){
                t[b]+=3;
            }
            else{
                t[a]+=1;
                t[b]+=1;
            }
        }
        int[] r = new int[n];
        for(int i=1;i<=n;i++){
            r[i-1] = t[i];
        }
        Arrays.sort(r);
        int[] r2 = new int[n+1];
        int cnt = 1;
        int z;
        for(int i=n-1;i>=0;){
            z=0;
            for(int j=1;j<=n;j++){
                if(r[i]==t[j]){
                    r2[j] = cnt;
                    z++;
                }
            }
            cnt+=z;
            i-=z;
        }
        for(int i=1;i<=n;i++){
            System.out.println(r2[i]);
        }
    }
}

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

int main(void){
    // Your code here!
    int A,B;
    cin >> A >> B;
 
            if(B == 1){
                cout << 0 << endl;
            }else if(A >= B){
                cout << 1  <<endl;
            }else{
                cout << ( ( (B-A)%(A-1) )?((B-A)/(A-1) + 2 ):((B-A)/(A-1) + 1) ) << endl;
            }
    
}

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

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

    vector<int> x(n), y(n), h(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];

    int ax, ay, ah;
    for (int cx = 0; cx <= 100; cx++) {
        for (int cy = 0; cy <= 100; cy++) {
            int ch;
            for (int i = 0; i < n; i++) {
                if (h[i] == 0) continue;
                ch = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
            }
            for (int i = 0; i < n; i++) {
                if (max(ch - abs(x[i] - cx) - abs(y[i] - cy), 0) != h[i]) break;
                if (i == n - 1) ax = cx, ay = cy, ah = ch;
            }
        }
    }

    cout << ax << " " << ay << " " << ah << endl;
}


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

bool check(int x)
{
	if(x==1) return 0;
	int s=sqrt(x);
	for(int i=2;i<=s;++i) if(x%i==0) return 0;
	return 1;
}

int main()
{
	int x;
	scanf("%d",&x);
	for(int i=x;;++i) {
		if(check(i)) {
			printf("%d",i);
			return 0;
		}
	}
}

Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <iostream>
using namespace std ;

int main()
{
  int n;
  cin>>n;
  int m;
  m=n*n;
  int o;
  o=m*n;
  cout<<n+m+o;
    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

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




























int main(){
    ll n;
    cin >> n;
    string ans;
    ll k = 1;
    while(n){
        ll c = (n / k) % 26;
        if(c == 0) c += 26;
        ans += (char)('a' + c - 1);
        n -= k * c;
        k *= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}


Measured memory_bytes: 3628
import sys
from collections import defaultdict, deque, Counter
import math

# import copy
from bisect import bisect_left, bisect_right
import heapq

sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline

getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)


def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD


def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD


def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

def kaijyo(n):
    ret = [1]
    for i in range(1, n + 1):
        ret.append((ret[-1] * i)% MOD)
    return ret

def warshall_floyd(d, n):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid

    def pos(self, x, y):
        return y * (self.w + 2) + x + 1

    def search(self):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]

        ans = 0
        for i in range(1, self.h + 1):
            for j in range(1, self.w + 1):
                pass # ここから何か書いてね

def solve():
    h, w, a, b = getList()
    if a > w // 2 or b > h // 2:
        print("No")
        return

    for i in range(b):
        print("1" * a + "0" * (w-a))
    for i in range(h - b):
        print("0" * a + "1" * (w - a))



def main():
    n = getN()
    for _ in range(n):
        solve()


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

Measured memory_bytes: 68308
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl
#define debug2(x, y) debug(x), debug(y)
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

struct DSU{
	int S;
	struct node{
		int parent; ll sum;
	};
	vector<node> dsu;
	DSU(int n){
		S = n;
		rep(i, n){
			node tmp;
			tmp.parent = i; tmp.sum = 1;
			dsu.pb(tmp);
		}
	}
	int root(int u){
		if(dsu[u].parent == u) return u;
		dsu[u].parent = root(dsu[u].parent);
		return dsu[u].parent;
	}
	void merge(int u, int v){
		u = root(u); v = root(v);
		if(u == v) return;
		if(getsum(u) < getsum(v)) swap(u, v);
		dsu[v].parent = u;
		dsu[u].sum += dsu[v].sum;
	}
	bool sameset(int u, int v){
		if(root(u) == root(v)) return true;
		return false;
	}	
	ll getsum(int u){
		return dsu[root(u)].sum;
	}
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m;
	cin >> n >> m;
	DSU dsu(n);
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--, b--;
		dsu.merge(a, b);
	}
	ll ans = 0;
	rep(i, n) ans = max(ans, dsu.getsum(i));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 7436
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    string s;
    cin >> s;

    a = (s[0]-'0')*10 + (s[1]-'0');
    b = (s[2]-'0')*10 + (s[3]-'0');
    
    bool f1=true, f2=true;
    if( (a>0)&&(a<13)) f2=true;
    else f2=false;

    if( (b>0)&&(b<13) ) f1=true;
    else f1=false;

    
    if( f1&&f2 ) cout << "AMBIGUOUS" << endl;
    else if( f1 ) cout << "YYMM" << endl;
    else if( f2 ) cout << "MMYY" << endl;
    else cout << "NA" << endl;

    return 0;

}



Measured memory_bytes: 256
#include<stdio.h>


int main()
{
	int i = 0 , j ;

	while( ++i < 10 )
	{
		j = 0 ;
		while( ++j < 10 )
		{
			printf( "%dx%d=%d\n" ,i ,j ,i * j ) ;
		}
	}


	return 0 ;
}

Measured memory_bytes: 524
import itertools
H, W, K = map(int, input().split())
ans = 0
pattern = []

for i in range(H):
  pattern.append(list(input()))

for i in itertools.product([0,1], repeat=H):
  for j in itertools.product([0,1], repeat=W):
    numsharp = 0
    for h in range(H):
      for w in range(W):
        if i[h] == 0 and j[w] == 0:
          if pattern[h][w] == '#':
            numsharp += 1
    if numsharp == K:
      ans += 1

print(ans)

Measured memory_bytes: 73684
#include <stdio.h>

int main(void) {
	int k;
	double ak;
	double sum;

	while(scanf("%lf", &ak) != EOF) {
		sum = 0.0;
		for(k = 0; k < 10; k++) {
			sum += ak;
			if(k % 2) 
				ak /= 3;
			else
				ak *= 2;
		}

		printf("%lf\n", sum);
	}

	return 0;
}

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

using namespace std;

int main(){

  int n;
  scanf("%d", &n);

  int mn = INT_MAX;
  int mx = -INT_MAX;
  for(int i = 0; i < n; i++ ){
    int x;
    scanf("%d", &x );
    mx = max( x, mx );
    mn = min( x, mn );
  }
  printf("%d\n", mx - mn );
  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    n = II()
    a = [7,5,3]
    if n in a:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


Measured memory_bytes: 38512
fn main() {
    let mut n = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse::<u64>().unwrap()
    };
    if n % 2 == 1 {
        println!("0");
        return;
    }
    let mut ans = 0;
    while n > 0 {
        ans += n / 10;
        n /= 5;
    }
    println!("{}", ans)
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> cnt(n + 1);
  for (int x = 1; x <= 100; ++x) {
    for (int y = 1; y <= 100; ++y) {
      for (int z = 1; z <= 100; ++z) {
        int a = x * x + y * y + z * z + x * y + y * z + z * x;
        if (a <= n) {
          ++cnt[a];
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    cout << cnt[i] << '\n';
  }

  return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int64_t N, A, B;
    cin >> N >> A >> B;

    if(B + A-1 <= N && N <= A*B) {
        int now = 0;
        for(int i=1; i<=A; i++) {
            int cnt = min(N-A+i, B);
            now += cnt;
            N -= cnt;
            for(int j=0; j<cnt; j++) {
                cout << now-j << endl;
            }
        }
    } else {
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
#define _USE_MATH_DEFINES
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define PI acos(-1.0)
#define EPS 1e-9 //epsilon 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define go(i,a,n) for(int i=a;i<n;i++)
#define og(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(i,n) go(i,0,n)
#define per(i,n) og(i,0,n)
#define sz(x) (x.size())
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
#define all(x) x.begin(),x.end()
#define rall(x) (x).rbegin(),(x).rend()
#define pr(x) cout<<(x)<<endl
#define exist(e,s) ((s).find(e)!=(s).end()) //Element e in structure s
#define existstr(c,s) ((s).find(c) !=string::npos) //Character in structure
#define fo(x,s) for(auto &x:s) //for all x in structure s
typedef vector<int> vi;typedef vector<ll> vll;typedef vector< vector<int> > vvi;
typedef vector< vector<ll> > vvll;typedef pair<int,int> ii;typedef pair<int, pair<int,int> > iii;
typedef pair<ll,ll> pll;typedef vector<ii> vii;typedef vector<iii> viii;typedef map<int,int> mii;
const int inf=1e9+7; //10^9 +7
inline void rvi(vi& v, int n){int temp; go(i,0,n){cin>>temp;v.pb(temp);}}
inline void rvll(vll& v, int n){ll temp;go(i,0,n){cin>>temp;v.pb(temp);}}
inline void prvi(vi&a){go(i,0,a.size()){cout<<a[i]<<" ";}cout<<endl;}
inline void prvll(vll&a){go(i,0,a.size()){cout<<a[i]<<" ";}cout<<endl;}
inline void prmii(map<int,int>& m){for(auto x:m){cout<<x.fi<<" "<<x.se<<endl;}}
inline vll prefixsum(vi& a){vll b;b.pb(a[0]);go(i,1,a.size()){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vi& a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];og(i,0,sz(a)-1){b[i]=a[i]+b[i+1];}return b;}
inline vll prefixsum(vll& a){vll b;b.pb(a[0]);go(i,1,a.size()){b.pb(a[i]+b[i-1]);}return b;}
inline vll suffixsum(vll& a){vll b(sz(a));b[sz(a)-1]=a[sz(a)-1];og(i,0,sz(a)-1){b[i]=a[i]+b[i+1];}return b;}
void solve();
int main(){ios;solve();return 0;}
//--------SOLVE---------------------------------------------------------------------
void solve()
{
 	ll n,m;
 	cin>>n>>m;
 	vll a(n);
 	rep(i,n) cin>>a[i];
 	vll p=prefixsum(a);
 	rep(i,n) p[i]=p[i]%m;
 	map<ll,ll> mapi;
 	rep(i,n) mapi[p[i]]++;
 	auto it=mapi.begin();
 	ll count=0;
 	if(it->fi==0) count+=it->se;
 	fo(x,mapi)
 	{
 		if(x.se>1)
 		{
 			count+=(x.se*(x.se-1))/2;
 		}
 	}
 	cout<<count<<endl;
}

Measured memory_bytes: 5748
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>

using namespace std;

int prime(int x) {
	for (int i = 3; i * i <= x; i += 2)
		if (x % i == 0) return 0;
	return 1;
}

vector<int> ans;

int main() {
	for (int i = 11; i <= 5555; i += 10)
		if (prime(i)) ans.push_back(i);
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) cout << ans[i] << ' ';
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    int alice = 0, bob = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0)
            alice += a.at(i);
        else
            bob += a.at(i);
    }
    cout << (alice - bob) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>
#include <list>
#include <numeric>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	ll n, W;
	cin >> n >> W;
	vector<pair<ll, ll>> wv(n);
	ll baseWeight = inf;
	rep(i, n) {
		cin >> wv[i].first >> wv[i].second;
		baseWeight = min(baseWeight, wv[i].first);
	}
	vector<vector<ll>> wvn(4, vector<ll>());
	rep(i, 4) {
		wvn[i].push_back(0); // 入れないパターン
	}
	rep(i, n) {
		wvn[wv[i].first - baseWeight].push_back(wv[i].second);
	}

	rep(i, 4) {
		sort(wvn[i].begin() + 1, wvn[i].end() , greater<ll>());
	}

	// 重さは4通り
	// 各重さの荷物をそれぞれ何個持っていくか決める
	// 線を三本いれる

	ll ans = 0;
	ll sumw0 = -baseWeight;
	ll sumv0 = 0;
	rep(i, (int)wvn[0].size()) { // 0の個数
		sumw0 += baseWeight;
		sumv0 += wvn[0][i];
		ll sumw1 = -(baseWeight + 1) ;
		ll sumv1 = 0;
		rep(j, (int)wvn[1].size()) { // 1の個数
			sumw1 += baseWeight + 1;
			sumv1 += wvn[1][j];
			ll sumw2 = -(baseWeight + 2);
			ll sumv2 = 0;
			rep(k, (int)wvn[2].size()) { // 2の個数
				sumw2 += baseWeight + 2;
				sumv2 += wvn[2][k];
				ll left = W - sumw0 - sumw1 - sumw2;
				if (left < 0) break;
				ll sumw3 = -(baseWeight + 3);
				ll sumv3 = 0;
				ll sum = sumv0 + sumv1 + sumv2;
				// 残り入れれるだけ入れる
				rep(l, (int)wvn[3].size()) {
					sumw3 += baseWeight + 3;
					sumv3 += wvn[3][l];
					if (left < sumw3) break;
					//cout << i << ", " << j << ", " << k << ", " << l << endl;
					ans = max(ans, sum + sumv3);
				}
			}
		}
	}

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


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if(s[0]>='a' && s[0]<='z') {
        cout << "a\n";
    } else {
        cout << "A\n";
    }
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);

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

ll lcm(ll a, ll b)
{
   return a * (b / gcd(a, b));
}

int main(){
  int N;
  cin >> N;
  ll ans;
  cin >> ans;
  REP(i,N-1){
    ll t;
    cin >> t;
    ans = lcm(t,ans);
  }
  cout << ans << endl;


}



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

const int maxn = 2e5 + 10;

int n;
int a[maxn];
string ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
}

void solve(){
    sort(a, a + n);
    ans = "YES";
    for(int i = 1; i < n; i++)
        if(a[i] == a[i - 1])
            ans = "NO";
}

void out(){
    cout << ans;
}


Measured memory_bytes: 1024
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let a: isize = read!();
    let b: isize = read!();
    let _c: usize = read!();
    let k: usize = read!();

    let answers = [a - b, b - a];

    let ans = answers[k % 2];
    println!("{}", ans);
}


Measured memory_bytes: 2120
n=int(input())
S=list(input())
if len(set(S))==1:
    print(0)
    exit()
W,B=[0]*n,[0]*n
if S[0]=='.':
    W[0]=1
else:
    B[0]=1
for i in range(1,n):
    if S[i]=='.':
        W[i]=W[i-1]+1
        B[i]=B[i-1]
    else:
        W[i]=W[i-1]
        B[i]=B[i-1]+1
cnt1=float('inf')
for i in range(n-1):
    w=W[i]
    b=B[-1]-B[i]
    tmp=n-w-b
    cnt1=min(cnt1,tmp)
for i in reversed(range(n)):
    if S[i]=='.':
        break
cnt2=S[:i+1].count('#')
for i in range(n-1):
    if S[i]=='#':
        break
cnt3=S[i+1:].count('.')
print(min(cnt1,cnt2,cnt3))

Measured memory_bytes: 15748
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        while (scanner.hasNext()) {
           int d = scanner.nextInt();
           int sum = 0;
           
           for (int i = 0; i < (600-d)/d; i++) {
               sum += d * ((i+1)*d *(i+1)*d);
           }
           System.out.println(sum);
        }
    }
}

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

using namespace std;

#define rep(i,a,b) for(int i = a; i<int(b);++i)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define trav(a,c) for(auto a: c)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pii;

vi mem;
vector<vi> e;


bool isPath(ll v, ll l){
    if(mem[v]!=-1) return mem[v];
    bool ans = (e[v].size()<=2);
    rep(i,0,e[v].size()){
        if(e[v][i]!=l) {
			ans = ans&&isPath(e[v][i],v);
		}
    }
    return mem[v] = ans;
}

ll ans = 0;

void dfs(ll v, ll l){
	ll numPaths = 0;
    rep(i,0,e[v].size())
        if(e[v][i]!=l) {
            if(isPath(e[v][i],v)){
                numPaths++;
            } else{
                dfs(e[v][i],v);
            }
        }
	if(numPaths>0)
		ans += numPaths-1;
}
int main(){
	cin.sync_with_stdio(false);
    ll n;
    cin>>n;
	e.resize(n);
    mem.resize(n,-1);
    rep(i,0,n-1){
		ll a,b;
		cin>>a>>b;
		e[a].push_back(b);
		e[b].push_back(a);
    }
    rep(i,0,n){
        if(e[i].size()>2){
			dfs(i,-1);
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<1<<endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
long long int dp[3010][3010];
int main(){
    long long int n,l,r,i,a[3010];
    cin>>n;
    for(i=1;i<n+1;i++){
        cin>>a[i];
    }
    for(l=n;l>0;l--){
        for(r=1;r<n+1;r++){
            if(l>r) dp[l][r]=0;
            else if(l==r) dp[l][r]=a[l];
            else dp[l][r]=max(a[l]-dp[l+1][r] , a[r]-dp[l][r-1]);
        }
    }
    cout<<dp[1][n];
    
}

Measured memory_bytes: 70784
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
#include <stdlib.h>
typedef long long ll;
const int MYINF = 1e9+7;
typedef int bool;
const bool true = 1;
const bool false = 0;

#define MAX_N 1000010

typedef struct node_st {
	int v;
	struct node_st *next;
} node_t;

node_t *G[MAX_N];
int n;
int connected[MAX_N];
int color;

node_t *add_node(node_t *node, int v) {
	node_t *new = malloc(sizeof(node_t));
	new->v = v;
	new->next = node;
	return new;
}

void add(int u, int v) {
	G[u] = add_node(G[u], v);
	G[v] = add_node(G[v], u);
}

void dfs(int v) {
	node_t *p;
	if (connected[v]) return;
	connected[v] = color;
	for (p = G[v]; p != NULL; p = p->next) {
		dfs(p->v);
	}
}

int main(int argc, char **argv)
{
	int i, m, q, u, v;

	scanf("%d %d", &n, &m);
	for (i = 0; i < m; i++) {
		scanf("%d %d", &u, &v);
		add(u, v);
	}

	for (i = 0; i < n; i++) {
		color = i + 1;
		dfs(i);
	}

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d %d", &u, &v);
		if (connected[u] == connected[v]) puts("yes");
		else puts("no");
	}

	return 0;
}

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

int main() {
  int h,w;
  cin >>h>>w;
  char a[h][w];
  bool hantei[h];
  bool hantei2[w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<h;i++){
    bool check=false;
    for(int j=0;j<w;j++){
      if(a[i][j]=='.')check=true;
      else {
        check=false;
        break;
      }
    }
    if(check==true)hantei[i]=true;
    else hantei[i]=false;
  }
  for(int j=0;j<w;j++){
    bool check=false;
    for(int i=0;i<h;i++){
      if(a[i][j]=='.')check=true;
      else {
        check=false;
        break;
      }
    }
    if(check==true)hantei2[j]=true;
    else hantei2[j]=false;
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(hantei[i]==false&&hantei2[j]==false)cout<<a[i][j];
    }
    if(hantei[i]==false)cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int digit(int n)
{
    int d = 1;

    while (n / 10 > 0)
    {
        d++;
        n /= 10;
    }

    return d;
}

int main(void)
{
    int n;
    int ans = 0;

    cin >> n;

    for (int i = 1; i <= n; i++)
    {
        if (digit(i) % 2 == 1)
        {
            ans++;
        }
    }

    cout << ans << endl;
}

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

int main(void)
{
    int a = 0, b = 0, k = 0;
    int chk_flg = 0;

    scanf("%d", &k);
    scanf("%d%d", &a, &b);

    for(int i = a; i <= b; i++){
        if(i % k == 0)
            chk_flg = 1;
    }

    if(chk_flg == 1)
        printf("OK");
    else
        printf("NG");

    return 0;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	int x,y; scanf("%d%d",&x,&y);

	int ans=0;
	if     (x==3) ans+=100000;
	else if(x==2) ans+=200000;
	else if(x==1) ans+=300000;
	if     (y==3) ans+=100000;
	else if(y==2) ans+=200000;
	else if(y==1) ans+=300000;
	if(x==1 && y==1) ans+=400000;
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {

	int W;
	int H;
	int x;
	int y;
	int r;

	cin >> W >> H >> x >> y >> r;
	if (x + r > W||y+r>H ||x-r <0||y-r<0 ) {
		cout << "No" << endl;
	}
	else{
			cout << "Yes" << endl;
	}
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    
	int n, p[10],ps[10], q[10],qs[10]; cin >> n;
	for (int i = 0; i < n; i++) { cin >> p[i]; ps[i] = p[i]; }
	for (int i = 0; i < n; i++) { cin >> q[i]; qs[i] = q[i]; }
	sort(ps, ps + n); 
	sort(qs, qs + n);

	int a = 1;
	do{
		for (int i = 0; i < n; i++) {
			if (ps[i] != p[i]) { break; }
			if (i == n - 1) { goto aend; }
		}
		a++;
	} while (next_permutation(ps, ps + n));
aend:

	int b = 1;
	do {
		for (int i = 0; i < n; i++) {
			if (qs[i] != q[i]) { break; }
			if (i == n - 1) { goto bend; }
		}
		b++;
	} while (next_permutation(qs, qs + n));
bend:

	cout << abs(a - b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	for (;;) {
		int h, w, x, y;
		scanf("%d %d", &h, &w);
		if (h == 0 & w == 0) {
			return 0;
		}
		for (y = 0; y < h; y++) {
			for (x = 0; x < w; x++) {
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
}

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

using namespace std;

template <class T>inline T updmax(T &a, T b) { return a = max(a, b); }
template <class T>inline T updmin(T &a, T b) { return a = min(a, b); }

template <unsigned long long mod> class modint {
public:
	unsigned long long v;
	modint(const long long x = 0) : v(x % mod) {}
	modint operator+(const modint rhs) { return modint(*this) += rhs; }
	modint operator-(const modint rhs) { return modint(*this) -= rhs; }
	modint operator*(const modint rhs) { return modint(*this) *= rhs; }
	modint operator/(const modint rhs) { return modint(*this) /= rhs; }
	modint operator-() { return modint(mod-this->v); }
	modint &operator+=(const modint rhs) {
		v += rhs.v;
		if (v >= mod)v -= mod;
		return *this;
	}
	modint &operator-=(const modint rhs) {
		if (v < rhs.v)v += mod;
		v -= rhs.v;
		return *this;
	}
	modint &operator*=(const modint rhs) {
		v = v * rhs.v % mod;
		return *this;
	}
	modint inverse(modint a) {
		unsigned long long exp = mod - 2;
		modint ret(1ULL);
		while (exp) {
			if (exp % 2) {
				ret *= a;
			}
			a *= a;
			exp >>= 1;
		}
		return ret;
	}
	modint &operator/=(modint rhs) {
		(*this) *= inverse(rhs);
		return *this;
	}
};

const int MOD = 1000000007;
using mint = modint<MOD>;

mint dp[61][2][2][2];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	long long L, R;
	cin >> L >> R;
	bitset<60> l(L), r(R);
	dp[0][0][0][0] = 1;
	for(int i=0; i < 60; i++){
		for(int a=0; a < 2; a++){
			for(int b=0; b < 2; b++){
				for(int c=0; c < 2; c++){
					//x = 0, y = 0
					if(b || !l[59-i])dp[i+1][a][b][c || r[59-i]] += dp[i][a][b][c];
					//x = 0, y = 1
					if(a && (b || !l[59-i]) && (c || r[59-i]))dp[i+1][a][b][c] += dp[i][a][b][c];
					//x = 1, y = 1
					if(c || r[59-i])dp[i+1][1][b || !l[59-i]][c] += dp[i][a][b][c];
				}
			}
		}
	}
	mint ret = 0;
	for(int a=0; a < 2; a++){
		for(int b=0; b < 2; b++){
			for(int c=0; c < 2; c++){
				ret += dp[60][a][b][c];
			}
		}
	}
	cout << ret.v << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repeat(i,a,b) for(int i=(a),_=(b);i<_;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,_=(a);i>=_;i--)
#define mst(a,a0) memset(a,a0,sizeof(a))
//#define vector basic_string
#define fi first
#define se second
#ifndef qwq
int cansel_sync=(ios::sync_with_stdio(0),cin.tie(0),0);
#endif
//mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N=200010; typedef long long ll; const int inf=~0u>>2; const ll INF=~0ull>>2; ll read(){ll x; if(scanf("%lld",&x)==-1)exit(0); return x;} typedef double lf; typedef long double llf; const lf pi=acos(-1.0); lf readf(){lf x; if(scanf("%lf",&x)==-1)exit(0); return x;} template<typename T> T sqr(const T &x){return x*x;} typedef pair<int,int> pii;
const int mod=(1?1000000007:998244353); ll mul(ll a,ll b,ll m=mod){return a*b%m;} ll qpow(ll a,ll b,ll m=mod){ll ans=1; for(;b;a=mul(a,a,m),b>>=1)if(b&1)ans=mul(ans,a,m); return ans;} ll getinv(ll v,ll m=mod){return qpow(v,m-2,m);}
#define int ll
map<int,int> mp;
int n,a,b,c,d;
void push(int n,int cost){
	if(mp.count(n))mp[n]=min(mp[n],cost);
	else mp[n]=cost;
}
void solve(){
	cin>>n>>a>>b>>c>>d;
	mp.clear();
	mp[n]=0;
	while(1){
		auto it=--mp.end();
		int n=it->fi,cost=it->se;
		if(n==0){cout<<cost<<endl; return;}
		if(n%2==0)push(n/2,cost+a);
			else push(n/2+1,cost+a+d),push(n/2,cost+a+d);
		push(n/3,cost+b+d*(n%3));
		push(n/3+1,cost+b+d*(3-n%3));
		push(n/5,cost+c+d*(n%5));
		push(n/5+1,cost+c+d*(5-n%5));
		if(n<int(1e18)/d)
			push(0,cost+d*n);
		mp.erase(--mp.end());
	}
}
signed main(){
	int T; cin>>T;
	while(T--){
		solve(); 
	}
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int count = 0;
    for (int i = 1; i <= N; i++){
        if(N % i == 0){
            int M = N / i;
            if(M < 10 && i < 10){
                count += 1;
            }
        }
    }
    if (count == 0){
        cout << "No";
    }else{
        cout << "Yes";
    }
}


Measured memory_bytes: 256
n = int(input())
cr = [tuple(map(int, input().split())) for _ in range(n)]
cb = [tuple(map(int, input().split())) for _ in range(n)]

cb.sort(key=lambda xy: xy[0])
cr.sort(key=lambda xy: xy[1], reverse=True)

npair = 0
for (bx, by) in cb:
    for (rx, ry) in cr:
        if rx < bx and ry < by:
            npair += 1
            cr.remove((rx, ry))
            break

print(npair)





Measured memory_bytes: 3064
n=int(input())
a=list(map(int,input().split()))
cnt=0
b=[]
for i in range(n):
  if a[i]<0:
    cnt+=1
  b.append(abs(a[i]))
if cnt%2==0:
  print(sum(b))
else:
  b.sort()
  print(sum(b[1:])-b[0])

Measured memory_bytes: 14224
/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int sum(int x) {
    int res = 0;
    while (x > 0) res += x % 10, x /= 10;
    return res;
}

int main() {
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    int res = 10000000;
    for (int i = 1; i < n; i++) {
        int a = i, b = n - i;
        res = min(res, sum(a) + sum(b));
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main()
{
	int W, H, N;
	int x;
	int y;
	int a;
	int wmin = 0;
	int hmin = 0;
	
	std::cin >> W;
	std::cin >> H;
	std::cin >> N;
	
	for(int i = 0; i < N; i++)
	{
		std::cin >> x;
		std::cin >> y;
		std::cin >> a;
		
		if(a == 1)
		{
			if(wmin < x)
			{
				wmin = x;
			}
		}
		else if(a == 2)
		{
			if(W > x)
			{
				W = x;
			}
		}
		else if(a == 3)
		{
			if(hmin < y)
			{
				hmin = y;
			}
		}
		else if(a == 4)
		{
			if(H > y)
			{
				H = y;
			}
		}
	}
	
	int w = W - wmin;
	int h = H - hmin;
	int ans = 0;
	if(w > 0 && h > 0)
	{
		ans = w * h;
	}
	
	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 256
// AtCoder template
// sabaより胡蝶しのぶさんの方が可愛いのではないか？
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)


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

    ll n,k; cin >> n >> k;
    if(n <= k) cout << min(k-n, n) << endl;
    else cout << min(n%k, abs(n%k - k)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> A(N), B(N);
    REP(i, N) {
        cin >> A[i];
        B[i] = max(A[i], 0LL);
    }
    vector<ll> ASUM(N + 1, 0), BSUM(N + 1, 0);
    REP(i, N) {
        ASUM[i + 1] = ASUM[i] + A[i];
        BSUM[i + 1] = BSUM[i] + B[i];
    }
    ll ans = 0;
    REP(i, N - K + 1) {
        ans = max(ans, BSUM[i] + BSUM[N] - BSUM[i + K] + max(0LL, ASUM[i + K] - ASUM[i]));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6412
n = int(input())
z = [[0] * 101 for _ in range(101)]
xyh = [tuple(map(int, input().split())) for _ in range(n)]
xyh = sorted(xyh, key=lambda x: x[2], reverse=True)

for xi in range(101):
    for yi in range(101):
        hi = 0
        allok = True
        for i in range(n):
            x,y,h = xyh[i]
            if i == 0:
                hi = abs(xi - x) + abs(yi - y) + h
            if max(hi - abs(xi - x) - abs(yi - y), 0) != h:
                allok = False
        if allok:
            print(xi, yi, hi)
            exit()



Measured memory_bytes: 9304
#include <iostream>
using namespace std;
 
int main ()
{
	int a, b;
  	int max = 0;	
  	cin >> a >> b;
  	
  	if(a > b)
    {
      max = a + a-1;
    }
  
  	if(b > a)
    {
      max = b + b-1;
    }
  
  	if(a == b)
    {
      max = a+b;
    }
  	
  	cout << max << endl;
  
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
template<C T>void pr(T a){cout<<a;ln;}
template<C T,C T2>void pr(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll n;
  R n;
  ll a[n],c[111],M=0;
  mem(c);
  rep(i,n) {
    R a[i];
    c[a[i]]++;
    M=max(M,a[i]);
  }
  ll x=(M+1)/2;
  REP(i,1,M+1) {
    bool f=0;
    if(i<x&&c[i]) f=1;
    if(i==x) {
      if(M%2) {
        if(c[i]!=2) f=1;
      } else {
        if(c[i]!=1) f=1;
      }
    }
    if(i>x&&c[i]<2) f=1;
    if(f) {
      pr("Impossible");
      return;
    }
  }
  pr("Possible");
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }
        long[] dp = new long[W + 1];
        for (int i = 0; i < N; i++) {
            for (int j = W; j >= w[i]; j--) {
                dp[j] = Math.max(dp[j], dp[j - w[i]] + v[i]);
            }
        }
        long res = 0;
        for (int i = 0; i <= W; i++) {
            res = Math.max(res, dp[i]);
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 23380
first_input = gets.split().map(&:to_i);
weather_map=Array.new(first_input[0]);
for i in 0...first_input[0]
  weather_map[i] = gets();
end
#result = Array.new(fisrt_input[0]);
for l in 0...first_input[0]
  for x in 0...first_input[1]
    for i in 0..x
      if(weather_map[l][x - i] == "c" && x != first_input[1]-1)
        print(i);print(" ");
        break
      end
      if(weather_map[l][x - i] == "c" && x == first_input[1]-1)
        print(i);
        break
      end
      if(i == x && x != first_input[1]-1)
        print("-1");print(" ");
      end
      if(i == x && x == first_input[1]-1)
        print("-1");
      end
    end
  end
  puts();
end

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

long long pattern_sum(string &S, int order, vector<bool> plus){
  if (order == S.size()){
    int start = 0, length = 0, sum = 0;
    for (int i=0; i<S.size(); i++){
      if (!(plus.at(i))) length++;
      else{
        sum += stoi(S.substr(start, length));
        start = i;
        length = 1;
      }
      if (length == S.size() && length > 1){
        return stoi(S.substr(0,1))*pow(10, length-1) + stoi(S.substr(1));
      }else if (length == S.size() && length == 1){
        return stoi(S.substr(0,1));
      }
      if (i == S.size()-1){
        sum += stoi(S.substr(start));
      }
    }
    return sum;
  }
  
  long long ans=0;
  for (int i=0; i<2; i++){
    plus.at(order) = i==0 ? false : true;
    ans += pattern_sum(S, order+1, plus);
  }
  return ans;
}

int main() {
  string S;
  cin >> S;
  
  vector<bool> plus(S.size());
  plus.at(0) = false;
  
  cout << pattern_sum(S, 1, plus) << endl;
  
}


Measured memory_bytes: 4052
#include <iostream>
#include <vector>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
constexpr int MOD = 1000000007;


int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    cin >> S >> T;

    vector<vector<unsigned int>> dp(N + 1, vector<unsigned int>(M + 1));
    REP(i, N + 1) dp[i][0] = 1;
    REP(j, M + 1) dp[0][j] = 1;
    REP(i, N) REP(j, M)
    {
        dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] + (S[i] != T[j] ? MOD - dp[i][j] : 0);
        dp[i + 1][j + 1] %= MOD;
    }
    cout << dp[N][M] << endl;
}


Measured memory_bytes: 16000
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "vector"
using namespace std;
#define MAXN 106
#define P 1000000007
int n;
int A[MAXN];
int Pow( int x , int a ) {
    int cur = x % P , ans = 1;
    while( a ) {
        if( a & 1 ) ans = 1ll * ans * cur % P;
        cur = 1ll * cur * cur % P , a >>= 1;
    }
    return ans;
}
pair<int,int> solve( int l , int r , int c ) {
//    cout << l << ' ' << r << endl;
    if( l > r ) return make_pair( 1 , 0 );
    int h = 0x3f3f3f3f;
    for( int i = l ; i <= r ; ++ i ) h = min( h , A[i] );
    vector<int> pos;
    pos.push_back( l - 1 );
    for( int i = l ; i <= r ; ++ i ) if( A[i] == h ) pos.push_back( i );
    pos.push_back( r + 1 );
    int nm = pos.size() - 2;
    int re = 1 , tot = 1;
    for( int i = 0 ; i < pos.size() - 1 ; ++ i ) {
        pair<int,int> ret = solve( pos[i] + 1, pos[i + 1] - 1, h );
        re = 1ll * re * ret.first % P , tot = 1ll * tot * ( ret.first + ret.second ) % P;
//        cout << l << ' ' << r << ' ' << pos[i] + 1 << ' ' << pos[i + 1] << ' ' << re << ' ' << tot << endl;
    }
    return make_pair( 1ll * re * Pow( 2 , h - c ) % P , ( 1ll * re * ( Pow( 2 , h - c ) - 2 ) % P + 1ll * Pow( 2 , nm ) * tot % P ) % P );
}
int main() {
    cin >> n;
    for( int i = 1 ; i <= n ; ++ i ) scanf("%d",&A[i]);
    cout << solve( 1 , n , 0 ).second << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    bc = [[int(_) for _ in input().split()] for i in range(q)]

    ans = sum(a)
    a = collections.Counter(a)
    for b, c in bc:
        if b not in a:
            print(ans)
            continue
        b_num = a[b]
        ans -= b_num * b
        ans += b_num * c
        if c in a:
            a[c] += b_num
        else:
            a[c] = b_num
        a[b] = 0
        print(ans)

    return


if __name__ == "__main__":
    main()
    sys.exit(0)

Measured memory_bytes: 105956