akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <int, int> ii;

const int mod = 1e9 + 7;
const ll INF = (1LL<<50);
const double EPSILON = 0.001;
const int N = 100005;
int see[N];
vi adj[N];
void dfs(int x){
	see[x] = 1;
	for(int i:adj[x]){
		if(!see[i])
			dfs(i);
	}
}
int main(){
	fastio;
	int n,m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int x,y;
		cin >> x >> y;
		adj[x].pb(y);
		adj[y].pb(x);
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(!see[i]){
			dfs(i);
			ans++;
		}
	}
	cout << ans-1 << '\n';
	return 0;
}


Measured memory_bytes: 9956
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a = []
for _ in range(M):
    a.append(int(input()))

if M > 0:
    for i in range(M-1):
        if a[i+1] - a[i] == 1:
            print(0)
            exit()

check = set(a)
if 1 in check:
    dp = [0, 0, 1]
elif 2 in check:
    dp = [0, 1, 0]
else:
    dp = [0, 1, 2]
if N < 3:
    print(dp[N])
    exit()
for i in range(3, N+1):
    if i in check:
        dp.append(0)
    else:
        dp.append((dp[-1] + dp[-2])%1000000007)

print(dp[-1])

Measured memory_bytes: 10124
#include <iostream>
using namespace std;
int main(){
int A,B;
cin>>A >>B;
if (A==1){
	A=14;
}
if (B==1){
	B=14;	
}
if (A==B){
	cout<<"Draw"<<endl;
	return 0;
}
if(A>B){
	cout<<"Alice"<<endl;
}
else{
	cout<<"Bob"<<endl;
}
return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cassert>
#include<algorithm>
#define llong long long
using namespace std;

const int N = 5e5;
llong a[N+3];
llong lim[N+3];
llong s[N+3];
int n,q;

llong absl(llong x) {return x<0?-x:x;}

int main()
{
	scanf("%d%lld",&n,&s[0]);
	for(int i=1; i<=n; i++)
	{
		scanf("%lld",&a[i]);
		s[i] = min(absl(s[i-1]-a[i]),s[i-1]);
	}
	lim[n+1] = 0;
	for(int i=n; i>=1; i--)
	{
		if(lim[i+1]>=a[i]/2) {lim[i] = lim[i+1]+a[i];}
		else {lim[i] = lim[i+1];}
	}
//	printf("lim: "); for(int i=1; i<=n; i++) printf("%lld ",lim[i]); puts("");
	scanf("%d",&q);
	while(q--)
	{
		int x; scanf("%d",&x);
		if(lim[x+1]>=s[x-1]) {puts("NO");}
		else {puts("YES");}
	}
	return 0;
}

Measured memory_bytes: 13696
from sys import stdin
N, W = map(int, input().split())
s = list(list(map(int, line.split())) for line in stdin.read().splitlines())

sumv = sum(s[i][1] for i in range(N))

INF = float('inf')
dp = [INF] * (sumv + 1)  # minimum w required to achieve  value V. dp[v] = w
dp[sumv] = sum(s[i][0] for i in range(N))
dp[0] = 0

for n in range(N):
    w0, v0 = s[n]
    for v in range(sumv, v0 - 1, -1):
        dp[v] = min(dp[v], dp[v - v0] + w0)

for i in range(sumv, -1, -1):
    if dp[i] <= W:
        print(i)
        break


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

int gcd(int a, int b) {
  if (a < b) swap(a, b);
  while (b) {
    int c = a % b;
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int N, K, g = 0, ma = 0;
  scanf("%d%d", &N, &K);
  for (int i = 0; i < N; i++) {
    int t; scanf("%d", &t);
    g = __gcd(g, t);
    ma = max(ma, t);
  }
  if (K % g == 0 && K <= ma) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

bool visited[100];
int g[100][100];
int sz[100];
int n;
bool flag[100];

int dfs(int now) {
  visited[now] = 1;
  flag[now] = 1;
  int res = 0;
  REP(i, sz[now]) {
    if (visited[g[now][i]]) continue;
    res = max(res, dfs(g[now][i]));
  }
  visited[now] = 0;
  return res + 1;
}

int main() {
  while(cin >> n, n) {
    memset(g,0,sizeof(g));
    int num[100];
    memset(num,0,sizeof(num));
    memset(sz,0,sizeof(sz));
    memset(flag,0,sizeof(flag));
    REP(i, n) {
      int a, b;
      cin >> a >> b;
      a--; b--;
      g[a][sz[a]++] = b;
      g[b][sz[b]++] = a;
      num[a]++;
      num[b]++;
    }
    int ans = 0;
    for (int i=1; i<100; ++i) {
      bool tmp[100];
      memcpy(tmp, flag, sizeof(flag));
      REP(j, 100) {
        if (num[j] == i && tmp[j] == 0) {
          ans = max(ans, dfs(j));
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 908
#include <stdio.h>
int main() {
	int n, a[100000], pos = 1, cnt = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	while (pos != 2) {
		int buf = a[pos - 1];
		a[pos - 1] = -1;
		pos = buf;
		if (pos == -1) {
			cnt = -1;
			break;
		}
		cnt++;
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll x,y;
    cin>>x>>y;
    cout<<x+y/2;
}


Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    int index = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (a[i] == 1){
            index = i;
        }
    }
    cout << (n - 1 + k - 1 -1) / (k-1) << endl;




    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define inf 99999999
#define itn int
#define NMAX 100010
ll n,k,m,x,y;
int main(){
    FAST;
    cin>>x;
    int flag=0;
    for(ll i=1;;++i){
        for(ll j=-i;j<i;++j){
            if(i*i*i*i*i-j*j*j*j*j==x){
                x=i;y=j;flag=1;break;
            }
        }
        if(flag==1) break;
    }
    cout<<x<<" "<<y;
    return 0;
}


Measured memory_bytes: 3588
"use strict"
const input = require('fs').readFileSync('/dev/stdin','utf8');
const arr = input.split('\n')
for (let i in arr) {
	const list = arr[i].split(' ');
	const w = parseInt(list[0]);
	const h = parseInt(list[1]);
	if (w === 0 && h === 0) break;
	printFrame(w, h);
	console.log('');
}

function printFrame(w, h) {
	let line = '';
	const edge = '#';
	const inside = '.';
	for (let i = 0; i < w; i++) {
		for (let j = 0 ;j < h; j++) {
			if (isEdge(i, j, w, h)) line += edge;
			else line += inside;
		}
		console.log(line);
		line = '';
	} 
}

function isEdge(i, j, w, h) {
	if (i == 0) return true;
	if (i == w - 1) return true;
	if (j == 0) return true;
	if (j == h - 1) return true;
	return false;
}


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

int N;
string s;

int main(){
    cin >> N >> s;
    int count = 0;
    for(int i = 0; i < N; i++){
        if(s[i] == 'R'){
            count++;
        }
    }
    
    if(count > N - count){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> B(m);
    int ans=0;
    for(int i = 0 ; i < m ; i ++){
       cin>>B.at(i) ;
    }
    vector<int> A(m); 
    for(int i=0; i<n;i ++){
        int C=0;
        for(int k=0;k<m;k++){
            cin >>A.at(k);
            C+=A.at(k)*B.at(k);
            if(k==m-1&&C+c>0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

typedef long long ll;
typedef complex<double> Vec;

const ll MOD = 1e9 + 7;
ll N, K;
ll M;
vector<ll> Mult;
vector<vector<ll>> Dp;

void init() {
  set<ll> s_values;
  for (ll i = 1; i * i <= N; ++i) {
    s_values.insert(i);
    s_values.insert(N / i);
  }
  vector<ll> values;
  for (ll v : s_values) values.push_back(v);
  M = values.size();
  Mult.resize(M);
  for (ll i = 0; i < M; ++i) Mult[i] = values[i] - (i == 0 ? 0 : values[i - 1]);
}
int main() {
  cin >> N >> K;
  init();
  Dp.resize(K + 1);
  for (auto &dp : Dp) dp.resize(M);
  fill(Dp[0].begin(), Dp[0].end(), 1);
  for (ll k = 0; k < K; ++k) {
    for (ll i = 0; i < M; ++i) {
      Dp[k + 1][i] = Mult[i] * Dp[k][M - 1 - i] % MOD;
      if (i > 0) (Dp[k + 1][i] += Dp[k + 1][i - 1]) %= MOD;
    }
  }
  cout << Dp[K][M - 1] << endl;
  return 0;
}


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

using namespace std;

const int NMAX = 1e5;
const int mod = 1e9 + 7;

int N;
int dp[NMAX + 5][3];
vector<int> edg[NMAX + 5];

void DFS(int nod, int fth)
{
    dp[nod][0] = dp[nod][1] = 1;
    for(auto nxt: edg[nod])
        if(nxt != fth)
        {
            DFS(nxt, nod);
            dp[nod][1] = (1LL * dp[nod][1] * dp[nxt][0]) % mod;
            dp[nod][0] = (1LL * dp[nod][0] * dp[nxt][2]) % mod;
        }

    dp[nod][2] = (dp[nod][0] + dp[nod][1]) % mod;
}

int main()
{
    cin >> N;
    for(int i = 1; i < N; i++)
    {
        int x, y;
        cin >> x >> y;
        edg[x].push_back(y);
        edg[y].push_back(x);
    }

    DFS(1, 0);
    int ans = dp[1][2];
    cout << ans << '\n';

    exit(0);
}

Measured memory_bytes: 13824
N, M = [int(x) for x in input().split()]

dp = [0] * (N + 1)
dp[0] = 1
a = []
ans = 1

for i in range(M):
	a.append(int(input()))
	if i > 0:
		if a[i] - a[i - 1] == 1:
			ans = 0
			break
	dp[a[i]] = 'broken'

if ans == 0:
	print(ans)
else:
	if dp[1] != 'broken':
		dp[1] = 1

	if N == 1:
		print(ans)
	else:
		for i in range(N - 1):
			tmp = 0
			if dp[i] != 'broken':
				tmp += dp[i]
			if dp[i + 1] != 'broken':
				tmp += dp[i + 1]
			if dp[i + 2] != 'broken':
				dp[i + 2] = tmp
		print(dp[N] % 1000000007)

Measured memory_bytes: 462708
import sys
input = sys.stdin.readline

N, T = map(int, input().split())
c = [0] * N
t = [0] * N

for i in range(N):
    c[i], t[i] = map(int, input().split())

C = []
for j in range(N):
    if t[j] <= T:
        C.append(c[j])

if len(C) == 0:
    print('TLE')
else:
    print(min(C))

Measured memory_bytes: 3064
N = int(input())
l = list(map(int, input().split()))

def check(la):
    c = 0
    for i in range(len(la)):
        if la[i] % 2 == 0:
            c += 1
    if c == len(la):
        return True
    else:
        return False
        
ans = 0
while check(l):
    for i in range(N):
        l[i] = l[i]/2
    ans += 1

print(ans)

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

int s[100001],t[100001] , p[100001];

int x[100001];
int y[100001];
int X[100001];
int Y[100001];
int main(){
	int n,m;
	while(cin >> n >> m){
		for(int i = 0 ; i < n ; i++){
			cin >> s[i] >> t[i];
		}
		for(int i = 0 ; i < m ; i++){
			cin >> p[i];
		}
		sort(p,p+m);
		
		x[0] = p[0];
		y[0] = 0;
		X[0] = 1;
		Y[0] = 0;
		for(int i = 1 ; i < m ; i++){
			x[i] = x[i-1] + ((i+1)%2) * (p[i]-p[i-1]);
			y[i] = y[i-1] + ((i+0)%2) * (p[i]-p[i-1]);
			X[i] = (i+1)%2;
			Y[i] = i%2;
		}
		long long ans = 0; 
		for(int i = 0 ; i < n ; i++){
			if(s[i] > t[i]){
				int a = (upper_bound(p,p+m,s[i])-p)-1;
				int b = (upper_bound(p,p+m,t[i]))-p; 
				if(a==-1 || b == m){
					ans += s[i]-t[i];
				}else{//1 2 3 5 
					ans += (s[i]-p[a]);
					if((b-a)%2){
						if( X[a] == 0) ans += x[a]-x[b];
						else		   ans += y[a]-y[b];
						ans += (p[b]-t[i]);
					}else{
						//1 2 3 4 5 
						//cout << a << " " << b << " " << (s[i]-p[a]) << endl;
						if( X[a] == 0) ans += x[a]-x[b];
						else		   ans += y[a]-y[b];
					}
				}
			}else{
				int a = (upper_bound(p,p+m,s[i])-p);
				int b = (upper_bound(p,p+m,t[i])-1)-p;
				if(b==-1 || a == m){
					ans += t[i]-s[i];
				}else{
					ans += (p[a]-s[i]);
					if((b-a)%2){
						if( X[a] == 1) ans += x[b]-x[a];
						else		   ans += y[b]-y[a];
						ans += (t[i]-p[b]);
					}else{
						if( X[a] == 1) ans += x[b]-x[a];
						else		   ans += y[b]-y[a];
					}
				}
				// 2 3
				
				// 2 2
				// 1 0
				// 0 3
				// 0 1
			}
		}
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 3568
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	int flag1=0,flag2=0;
	cin>>n;
	unsigned long long sum=1ull,temp;
	for (int i=0;i<n;i++)
	{
		cin>>temp;
		if (temp==0)   flag1=1;
		else
		{
			if (log2(sum)+log2(temp)>=64)   flag2=1;
		}
		sum*=temp;
	}
	if (flag1)   cout<<0;
	else
	{
		if (flag2||sum>1000000000000000000)   cout<<-1;
		else   cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 3820
/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

void yesno(int ans) {
	if (ans == 1) {	printf("Yes\n");
	} else {		printf("No\n");	}
	return;
}

void okng(int ans) {
	if (ans == 1) { printf("OK\n");
	} else { 		printf("NG\n");	}
	return;
}

ll A[200002] = {0};
ll a[200002] = {0};
//int ans[200002] = {0};
int main()
{
	int N = 0, K = 0;
	scanf("%d %d", &N, &K);
	int i = 0;
	for (i = 1; i <= N; i++) {
		scanf("%lld", &A[i]);
	}

	memset(a, 0, sizeof(a));
//	memset(ans, -1, sizeof(ans));
	int start_k = 1;
	if (start_k < 1) {
		start_k = 1;
	}
	int j = start_k;
	ll add = 1;
	for (i = start_k; i <= N; i++) {
		add += A[i];
		if (i >= K) {
//			printf("i=%d val=%d\n", i, add);
			a[i] = add;
			add -= A[j];
			j++;
		}
	}
	int ans = 0;
	for (i = K+1; i <= N; i++) {
//		printf("i=%d a[i-1]=%d, a[i]=%d\n", i, a[i-1], a[i]);
		if (a[i-1] < a[i]) {
			ans = 1;
		} else {
			ans = 0;
		}
		yesno(ans);
	}


	//yesno(ans);
	//okng(ans);
	return 0;
}


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

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


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll n, d, a; cin >> n >> d >> a;
    vector<P> m(n);
    ll ans = 0;

    rep(i, n) {
        ll x, h; cin >> x >> h;
        m[i] = make_pair(x, h);
    }
    sort(ALL(m));

    vector<ll> s(n+1, 0); // 合計

    rep(i, n) {
        if(s[i] < m[i].second) {
            ll num = (m[i].second-s[i]+a-1)/a; // 個数
            ll right  = m[i].first + d*2; // 届く範囲
            // 爆発が届く限界
            auto iter = upper_bound(ALL(m), make_pair(right, INF)) - m.begin();

            // imos
            s[i] += num*a;
            s[iter] -= num*a;
            ans += num;
        }

        s[i+1] += s[i];
    }
    /*
    rep(i, n+1) {
        cout << s[i] << endl;
    }
    */

    cout << ans << endl;    

    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 7988
N = int(input())
A = list(map(int,input().split()))
B = sorted(A)
C = [0 for i in range(N+1)]

bef = 0
for i in range(N):
  if bef!=B[i]:
    bef = B[i]
    C[B[i]] = 1
  else: C[B[i]]+=1

sum = 0
for i in range(N+1):
  sum += C[i]*(C[i]-1)//2
#  print(sum)

for i in range(N):
  dif = C[A[i]]*(C[A[i]]-1)//2 - (C[A[i]]-1)*(C[A[i]]-2)//2
  print(sum-dif)

#print(N,A,B,C,sum)

Measured memory_bytes: 26140
from collections import deque

def resto(n,m,ab):

    oya=[[] for _ in range(n)]
    ko=[[] for _ in range(n)]

    for i,y in ab:
        oya[y-1]+=[i-1]
        ko[i-1]+=[y-1]

    root=0
    for i in range(n+m):
        if len(oya[i])==0:
            root=i
            break

    oya[root]=['a']
    deq=deque([root])
    while len(deq)>0:
        z=deq.popleft()
        for i in ko[z]:
            if len(oya[i])!=1:
                oya[i].remove(z)
            else:
                deq.append(i)

    ans=[str(0)+'\n' if i[0]=='a' else str(i[0]+1)+'\n' for i in oya ]

    return ''.join(ans)

n,m=map(int,input().split())
print(resto(n,m,[list(map(int,input().split())) for _ in range(n+m-1)]))

Measured memory_bytes: 89788
#include <stdio.h>
#include <string.h>

int main(void){
   
   int N;
   char A[200],B[200],C[200];
   
   scanf("%d",&N);
   scanf("%s",A);
   scanf("%s",B);
   scanf("%s",C);
   
   int i;
   int count = 0;
   for(i = 0;i < N;i++){
      if(A[i] == B[i] && B[i] == C[i]){
         //Do nothing
      }
      else if(A[i] == B[i] && B[i] != C[i]){
         count = count + 1;
      }
      else if(A[i] != B[i] && B[i] == C[i]){
         count = count + 1;
      }
      else if(A[i] == C[i] && A[i] != B[i]){
         count = count + 1;
      }
      else if(A[i] != B[i] && B[i] != C[i] && A[i] != C[i]){
         count = count + 2;
      }
      else {
         printf("Error\n");
         exit(1);
      }
   }

   printf("%d\n",count);
   
   return 0;
}


Measured memory_bytes: 128
N, K = gets.split.map(&:to_i)
S = gets.chomp.split('').map(&:to_i) + [-1]

bs = []
len = 0
(N+1).times do |i|
    if i==0 || S[i] == S[i-1]
        len += 1
    else
        bs.push([S[i-1], len])
        len = 1
    end
end

ans = 0
sum = 0
rev = 0

que = []

bs.each do |bit, len|
    sum += len
    que.push([bit, len])
    rev += 1 if bit == 0
    while rev > K
        b, l = que.shift
        rev -= 1 if b == 0
        sum -= l
    end
    ans = sum if ans < sum
end
puts ans

Measured memory_bytes: 17916
#include <bits/stdc++.h>
#define ll long long int
#define inv(name,Type,size) vector<Type> name(size);for(int index=0;index<n;index++) cin>>name[index];
#define F(a,n,i) for(int i=a;i<n;i++)
#define pb push_back
#define endl "\n"
#define mod 10000000007
#define modpro 99824435
using namespace std;

void solve(){
	int n,k;
	cin>>n>>k;
	inv(a,int,n);
	int count=0;
	F(0,n,i){
		if(a[i]>=k) count++;
	}
	cout<<count;
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  
  //int t;cin>>t;while(t--) solve(),cout<<endl;
  solve();
}



Measured memory_bytes: 3668
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int s;
    cin >> s;
    int m = s;
    vector<int> a(10000);
    a[m]+=1;
    rep(i,1000001){
        if(m%2==0){
            m/=2;
            a[m]+=1;
            if(a[m]==2){
                cout << i+2;
                return 0;
            }
        }
        else{
            m = 3*m + 1;
            a[m]+=1;
            if(a[m]==2){
                cout << i+2;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    int mn = inf;
    ll sum = 0;
    rep(i,n) {
        int a,b;
        cin >> a >> b;
        if(a > b) chmin(mn,b);
        sum += a;
    }
    cout << (mn == inf ? 0 : sum-mn) << endl;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

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


int main() {
	ll n,k;
	ll ans = 0;
	cin >> n >> k;
	if (k == 0) {
		cout << n * n << endl;
		return 0;
	}

	for (ll b = k + 1; b <= n; b++) {
		ll s = (n / b) * b;

		ans += max(0LL, (n / b) * (b - k));
		//cout << "b:" << b << " s:" << s << " ans1:" << (n / b) * (b - k) << endl;
		if (n - s >= 1) {

			ans += max(n - s - k + 1, 0LL);
			//cout << "ans1:" << max(n - s - k, 0) << endl;
		}
		//cout << "b:" << b << " s:" << s << " ans1:" << (n / b) * (b - k) << " ans0:"  << n - s - k + 1 << endl;
		
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int num;

  scanf("%d", &num);

  switch(num % 10){
    case 0:
      printf("pon");
      break;
    case 1:
      printf("pon");
      break;
    case 2:
      printf("hon");
      break;
    case 3:
      printf("bon");
      break;
    case 4:
      printf("hon");
      break;
    case 5:
      printf("hon");
      break;
    case 6:
      printf("pon");
      break;
    case 7:
      printf("hon");
      break;
    case 8:
      printf("pon");
      break;
    case 9:
      printf("hon");
      break;
  }
}


Measured memory_bytes: 1732
#include<stdio.h> 

#define NMAX 100000
#define QMAX 50000

int main(){
  int i,j,k,n,q,count=0,S[NMAX],T[QMAX],left=0,right,mid;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }

  right=i;
  
  for(k=0;k<q;k++){
    while(left<right){
      mid=(left+right)/2;
      if(S[mid]==T[k]){
	count++;
	//printf("hoge\n");
	break;	
      }
      else if(T[k]<S[mid]){
	right=mid;
      }
      else if(T[k]>S[mid]){
	left=mid+1;
      }
    }
    right=n;
    left=0;
  }
  printf("%d\n",count);
  return 0;
}
    
    
      
      
      
  



Measured memory_bytes: 2288
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

int main() {
    long long A;
    double B;
    cin >> A >> B;

    long long Bl = (B + 0.005)  * 100LL;
    long long ans = A * Bl;
    ans /= 100LL;

    cout << ans << endl;

    return 0;
}


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

ll zetai(ll a,ll b){
  if(a>b) return a-b;
  else return b-a;
}

int main(){
  int x; cin>>x;
  if(x>=30) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  
  return 0;
}


Measured memory_bytes: 3608
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val A = Array.fill(N)(sc.nextLong())
    // 1からNまでの整数のうちどれかが書かれたカードをたくさん持っている
    // 整数iが書かれたカードをA_i枚持っている
    // 2枚のカードについて、それらに書かれた整数の差の絶対値が1以下の時、
    // これらをペアにすることができる. => つまり, iをペアにできるのはi-1,i+1のみ
    // 同じカードが複数のペアに使われないように、できるだけ多くのペアを作りたい
    // 作れるペアの個数の最大値
    // 同じ数のカードだけで完結する場合, 完結させた方がいいとは限らない
    // 最初から偶数枚用意しているカードを使いきるのもNG
    // i - 1のカードが奇数枚, iのカードが偶数枚, i + 1のカードが奇数枚の時
    // (i - 1, i), (i, i + 1)のペアを作ることで最大化できるため
    // なので, 基本的には, カードが奇数枚あるか, 偶数枚あるか, だけを考える必要がある
    // こういうことができるかは, 順番に繋がっているか繋がっていないか, だけで, どこからペアを作るかの順番は関係ない
    // 0番目の数から順番に, 奇数が出たら, 持ち越しする, 連番のカードが続く限り, 持ち越し続けても問題ない
    // 連番のカードが続くうちで, 奇数のカードが出たら相殺できる, 連番が止まったタイミングで持ち越し不可能になるので
    // カードはロストする. ロストしたカードの数を数えておく. 全てのカードの合計から, ロストしたカードの数を引いて2で割った数が解答となる
    def solve(N: Int, A: Array[Long]): Long = {
      @scala.annotation.tailrec
      def recursive(i: Int, lost: Int): Int = {
        if (i >= N) lost
        else if (A(i) % 2 == 1) recursiveFindingOddCard(i + 1, lost)
        else recursive(i + 1, lost)
      }
      @scala.annotation.tailrec
      def recursiveFindingOddCard(i: Int, lost: Int): Int = {
        if (i >= N) lost
        else if (A(i) == 0) recursive(i + 1, lost + 1)
        else if (A(i) % 2 == 1) recursive(i + 1, lost)
        else recursiveFindingOddCard(i + 1, lost)
      }
      (A.sum - recursive(0, 0)) / 2
    }

    println(solve(N, A))
  }

}


Measured memory_bytes: 70844
#include<cstdio>
using namespace std;

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

    double ans = (double)a * b / 2;
    int num = (a == x * 2 && b == y * 2) ? 1 : 0;
    printf("%.10f %d\n",ans, num);
}

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

int main(){
    int C[9];
    for(int i=0;i<9;i++) cin >> C[i];

    //int a1 =0;
    if((C[3]-C[0]== C[4]-C[1])&&(C[4]-C[1]==C[5]-C[2])&&(C[6]-C[0]== C[7]-C[1])&&(C[7]-C[1]==C[8]-C[2])) cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 256
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())
print(li[k-1])


Measured memory_bytes: 2940
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
A = [A11, A12, A13, A21, A22, A23, A31, A32, A33]
bingo = [0, 0, 0, 0, 0, 0, 0, 0, 0]
N = int(input())
B = []
for _ in range(N):
    B.append(int(input()))

for i, b in enumerate(B):
    for j, a in enumerate(A):
        if a == b:
            bingo[j] = 1

if (bingo[0] == bingo[1] == [2] == 1) or (bingo[3] == bingo[4] == bingo[5] == 1) or (bingo[6] == bingo[7] == bingo[8] == 1) or (bingo[0] == bingo[3] == bingo[6] == 1) or (bingo[1] == bingo[4] == bingo[7] == 1) or (bingo[2] == bingo[5] == bingo[8] == 1) or (bingo[0] == bingo[4] == bingo[8] == 1) or (bingo[2] == bingo[4] == bingo[6] == 1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cassert>
#include <ctime>
#include <map>
#include <queue>
#include <set>
#include <cmath>
#include <list>
using namespace std;

vector <int> construct(int x) {
	if (x == 0) {
		vector <int> X;
		X.push_back(x);
		return X;
	}else {
		vector <int> vv = construct(x - 1);
		vector <int> X;
		for (int i = 0; i < (int) vv.size(); i++)
			X.push_back(vv[i]);
		for (int i = 0; i < (int) vv.size() - 1; i++)
			X.push_back(vv[vv.size() - 1 - i] + (1 << (x - 1)));
		return X;
	}
}

int prime[11000];
bool used[11000];

int s1[1100], s2[1100];
int len;

long long a[600][600];
vector <long long> VV;

#define K 503

void check(long long x, long long y) {
	// printf("%lld %lld\n", x, y);
	assert(max(x, y) % min(x, y) == K);
}

int main() {
	for (int i = 2; i <= 10000; i++) {
		if (!used[i]) {
			prime[++len] = i;
			for (int j = 2 * i; j <= 10000; j += i)
				used[j] = true;
		}
	}
	int base = 3;
	for (int i = 1; i <= 500; i++) {
		if (i % 2 == 1) {
			s1[i] = prime[base + i / 2];
		}else {
			s1[i] = 2 * prime[base + i / 2 - 1] * prime[base + i / 2] + 1;
		}
	}

	base = 260;

	for (int i = 1; i <= 500; i++) {
		if (i % 2 == 1) {
			s2[i] = prime[base + i / 2];
		}else {
			s2[i] = 3 * prime[base + i / 2 - 1] * prime[base + i / 2] + 1;
		}
	}

	prime[0] = 1;

	// printf("lol %d\n", prime[110]);

	for (int i = 1; i <= 500; i++)
		for (int j = 1; j <= 500; j++) {
			if ((i + j) % 2 == 0) {
				a[i][j] = i * prime[110 + (j + 1) / 2];
			}else {
				if (i > 1)
					a[i][j] = 1LL * (i - 1) * i * (i + 1) * prime[110 + j / 2] * prime[110 + j / 2 + 1] + K;
				else
					a[i][j] = 1LL * i * (i + 1) * prime[110 + j / 2] * prime[110 + j / 2 + 1] + K;
			}
		}
	// printf("?? %lld %lld\n", a[1][1], a[2][2]);
	// printf("%d %d\n%d %d\n", s1[1], s1[2], s2[1], s2[2]);
	for (int i = 1; i <= 500; i++)
		for (int j = 1; j <= 500; j++) {
			assert(a[i][j] <= 1e15);
			VV.push_back(a[i][j]);
		}
	sort(VV.begin(), VV.end());
	for (int i = 1; i < 250000; i++) {
		// printf("?? %d %lld\n", i, VV[i]);
		// printf("%d\n", );
		assert(VV[i] != VV[i - 1]);
	}

	// printf("!! %lld %lld\n", a[1][1], a[2][1]);
	for (int i = 1; i <= 500; i++)
		for (int j = 1; j <= 500; j++) {
			if (i > 1) check(a[i][j], a[i - 1][j]);
			if (i < 500) check(a[i][j], a[i + 1][j]);
			if (j > 1) check(a[i][j], a[i][j - 1]);
			if (j < 500) check(a[i][j], a[i][j + 1]);
		}

	int N;
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++)
			printf("%lld ", a[i][j]);
		printf("\n");
	}
}


Measured memory_bytes: 7280
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
typedef pair<int, int> P;
#define INF (1<< 26)
set<P> obst;
int h, w, n, x, y;

int leftmost[216000];
int main(){
  for(int i = 0;i < 216000;i++)leftmost[i] = INF;
  cin >> h >> w >> n;
  for(int i = 0;i < n;i++){
    cin >> x >> y;x--,y--;
    obst.insert(P(x,y));
  }
  int i = 0, j = 0;
  while (true) {
    leftmost[j] = min(leftmost[j], i);
    i++;if(obst.count(P(i,j)))break;
    if(obst.count(P(i,j+1)) == 0)j++;
    if(i >= h|| j >= w)break;
  }

  int ans = h;

  for(auto it: obst){
    if(it.first <= leftmost[it.second])continue;
    ans = min(ans, it.first);
  }
  cout << ans << endl;
}

Measured memory_bytes: 10496
using System.Linq;
using System;

public class B
{
    public int c { get; set; }
    public int w { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var cL = int.Parse(line[2]);
        line = Console.ReadLine().Trim().Split(' ');
        var lim = Array.ConvertAll(line, int.Parse);
        var bs = new B[n];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var c = int.Parse(line[0]) - 1;
            var w = int.Parse(line[1]);
            bs[i] = new B { c = c, w = w };
        }
        var sc = new int[cL];
        var ret = 0; var count = 0;
        foreach (var x in bs.OrderByDescending(y => y.w))
        {
            if (sc[x.c] < lim[x.c]) { ret += x.w; sc[x.c]++; count++; }
            if (count == m) break;
        }
        Console.WriteLine(ret);
    }
}




Measured memory_bytes: 19944
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char ch=getchar();
    while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int n,k;
const int maxn=1e5+7;
LL a[maxn];
LL b[maxn];
int cntx,cnty;

int main()
{
    n=read();k=read();
    for(int i=1;i<=n;i++){
        a[i]=read();
    }
    LL ans=0x3f3f3f3f3f3f3f3fll;
    for(int i=1;i+k-1<=n;i++){
        int l=i,r=i+k-1;
        ans=min(ans,a[r]-a[l]+min(abs(a[r]),abs(a[l])));
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }
  }
  int top(){return s[0];}
  int right(){return s[2];}
  int left(){return s[3];}
  int front(){return s[1];}
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++)if(a.s[i]!=b.s[i])return false;
  return true;
}
int main(){
  Dice d[100];
  int n;
  cin>>n;
  for(int i=0;i<n;i++)for(int j=0;j<6;j++)cin>>d[i].s[j];
  bool ff=true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
        d[l].roll('R');
        for(int j=0;j<4;j++){
          d[l].roll('N');
          if(same(d[k],d[l]))f=true;
        }
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
        d[l].roll('N');
        if(same(d[k],d[l]))f=true;
      }
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
        d[l].roll('N');
        if(same(d[k],d[l]))f=true;
      }
      if(f)ff=false;
    }
  }
  cout<<(ff?"Yes":"No")<<endl;
  return 0;
}



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

bool kansu( long long int n ) {

  if ( n < 0 ) return false;

  long long int m = n;
  char c[5];
  long long int k;
  for ( k = 0; m != 0; k++ ) {
    c[k] = m % 10 + '0';
    m /= 10;
  }
  for ( int i = 0; i < k; i++ ) {
    if ( c[i] != c[ k-i-1 ] ) return false;
  }
  return true;

}

int main() {

  long long int n;
  cin >> n;

  for ( int i = 0; true; i++ ) {

    if ( kansu( n - i ) == true ) {
      cout << n - i << endl;
      break;
    }
    if ( kansu( n + i ) == true ) {
      cout << n + i << endl;
      break;
    }

  }

  return 0;

}

Measured memory_bytes: 1160
import java.util.*;

public class Main{

public static void main ( String[] args){

Scanner str = new Scanner(System.in);

int a = str.nextInt();

int b = str.nextInt();

int c = str.nextInt();

if(a<b && b<c){

System.out.println("Yes");

}

else{

System.out.println("No");

}

}

}


Measured memory_bytes: 26124
h, w = map(int, input().split())
a = [[i & 1 for i in map(int, input().split())] for _ in range(h)]

n = 0
operations = []
for i in range(h):
    for j in range(w - 1):
        if a[i][j]:
            a[i][j + 1] ^= a[i][j]
            n += 1
            operations.append((i + 1, j + 1, i + 1, j + 2))

for i in range(h - 1):
    if a[i][-1]:
        a[i + 1][-1] ^= a[i][-1]
        n += 1
        operations.append((i + 1, w, i + 2, w))

print(n)
for y1, x1, y2, x2 in operations:
    print(y1, x1, y2, x2)


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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0; i < n; i += 2){
        if(a[i]%2 == 1) cnt += 1;
    }
    cout << cnt << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,_4,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define _repis(i,a,b,s) for(int i=a, i##_len(b); i<i##_len; i+=s)
#define REP(...) _overload3(__VA_ARGS__,_repis,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl

ll gcdl(ll a,ll b){ // log N
    while((a%=b)&&(b%=a));
    return a+b;
}

ll lcml(ll a,ll b){
    return a/gcdl(a,b)*b;
}

int gcd(int a,int b){ // log N
    while((a%=b)&&(b%=a));
    return a+b;
}

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

int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    set<int> w,s;
    REP(i,f/100+1){
        REP(j,f/100+1){
            w.insert(i*a+j*b);
        }
    }
    REP(i,f*e/100+1){
        REP(j,f*e/100+1){
            s.insert(i*c+j*d);
        }
    }

    int ma_w=1,ma_s=-1;
    REP(i,1,f/100+1){ // water
        if(!w.count(i))continue;
        REP(j,f-i*100+1){
            if(!s.count(j))continue;
            if(i*e>=j){
                if(ma_s*i<j*ma_w){
                    ma_w=i;
                    ma_s=j;
                }
            }
        }
    }
    cout<<ma_w*100+ma_s<<" "<<ma_s<<endl;
    return 0;
}


Measured memory_bytes: 5888
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
#define PB push_back
#define fi first
#define se second
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 100;

int n, ff[2][maxn + 5], aa[2][maxn + 5];

int main() {
    scanf("%d", &n);
    REP(i,1,n) scanf("%d", &aa[0][i]);
    REP(i,1,n) scanf("%d", &aa[1][i]);
    ff[0][1] = aa[0][1], ff[1][1] = aa[0][1] + aa[1][1];
    for(int i = 2; i <= n; ++i) {
        ff[0][i] = ff[0][i-1] + aa[0][i];
        ff[1][i] = max(ff[0][i], ff[1][i-1]) + aa[1][i];
    }
    printf("%d\n", ff[1][n]);
    return 0;
}


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

using namespace std;

void solve(){
	int n; cin>>n;
	int a[n];
	unordered_map<int, int> m;
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		m[a[i]]++;
	}
	int ans = 0;
	for(auto& it : m){
		if(it.first > it.second) ans+=it.second;
		else ans += (it.second - it.first);
	}
	cout << ans << '\n';
}

int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	int cs = 1;
	while(t--){
		//cout << "Case #" << cs << ":\n";
		solve();
		cs++;
	}
	return 0;
}


Measured memory_bytes: 7540
x = int(input())

for a in range(200):
    for b in range(200):
        if pow(a, 5) - pow(b, 5) == x:
            print(a, b)
            exit()
        if pow(-a, 5) - pow(b, 5) == x:
            print(-a, b)
            exit()
        if pow(a, 5) - pow(-b, 5) == x:
            print(a, -b)
            exit()
        if pow(-a, 5) - pow(-b, 5) == x:
            print(-a, -b)
            exit()


Measured memory_bytes: 9212
const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);
const list = line.slice(1, line.length-1).map(x => parseInt(x));

const head = list[0];
const tail = list.slice(1);

const ans = tail.reduce((acc, x) => {
    acc.result = Math.max(acc.result, x - acc.min);
    acc.min = Math.min(acc.min, x);
    return acc;
}, { result : -Infinity, min : head });

console.log(ans.result);


Measured memory_bytes: 43888
def gcd(a,b):
    x=max(a,b)
    y=min(a,b)
    if x%y==0:
        return y
    else:
        while x%y!=0:
            z=x%y
            x=y
            y=z
        else:
            return z
        
def lcm(a,b):
    return int(a*b//gcd(a,b))

N=int(input())

a=int(input())

for n in range(1,N):
    b=int(input())
    a=lcm(a,b)
print(a)

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll H, W, A, B;
    cin >> H >> W >>A >> B;

    vector<string> ansS(H);
    vector<ll> countH(W, 0);
    REP(i, H)
    {
        REP(j, W)
        {
            if (i < B)
            {
                if (j < A)
                {
                    ansS[i].push_back('0');
                }
                else
                {
                    ansS[i].push_back('1');
                }
            }
            else
            {
                if (j < A)
                {
                    ansS[i].push_back('1');
                }
                else
                {
                    ansS[i].push_back('0');
                }
            }
        }
    }

    REP(i, H)
    {
        cout << ansS[i] << endl;
    } 
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mk make_pair
#define rint register int
using namespace std;
inline int read(){int w=1,s=0;char ch=getchar();while(!isdigit(ch)){if(ch=='-')w=-1;ch=getchar();}while(isdigit(ch)){s=s*10+ch-'0';ch=getchar();}return w*s;}
int N;
int tong1[100010];
int tong2[100010]; 
int main()
{
	N=read();
	for(rint i=1;i<=N;++i) if(i&1) tong1[read()]++;else tong2[read()]++;
	int Max1=0,num1,Max2=0,num2,Max3=0,num3,Max4=0,num4;
	for(rint i=0;i<=100000;++i)
	{
		if(tong1[i]>Max1) Max2=Max1,num2=num1,Max1=tong1[i],num1=i;
		else if(tong1[i]>Max2) Max2=tong1[i],num2=i;
		if(tong2[i]>Max3) Max4=Max3,num4=num3,Max3=tong2[i],num3=i;
		else if(tong2[i]>Max4) Max4=tong2[i],num4=i;
	}
	if(num1!=num3){
		cout<<N-Max1-Max3<<"\n";
		return 0;
	}
	else 
	{
		cout<<min(N-Max1-Max4,N-Max2-Max3);
		return 0;
	}
	return 0;
}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define FOR(i,n) for((i)=0; (i)<(n); (i)++)
//全部priority_queueにつっこんだんじゃ、1000^3のsortでTLE。
//入れる数制限しないと
/*
struct cake{
  ll i;
  ll j;
  ll k;
};
*/
//pqに、はじめABCの1番目を入れる
//つぎに211,121,112を入れてメモしておく
//とりだしたのが211だったら、311,221,212をいれる
//このとき入ってないかの判定がむずいな
//4次元配列作る？1000*1000*1000*2とか無理くさいか
//3次元配列のmapって可能なんだっけ
//いけた。boolの初期値=0=false
//pqにいれたらtrueにしとく。
//trueだったらスルー、なかんじでいけそう
//structでpqのなかにいれようとしたらなんかエラー

int main(){
  ll X,Y,Z,K,i,j,k;
  cin>>X>>Y>>Z>>K;
  vector<ll> A(X,0),B(Y,0),C(Z,0),tmp(3,0);
  priority_queue<pair<ll,vector<ll>>> pq;
  map<vector<ll>,bool> mp;
  FOR(i,X){
    ll a; cin>>a; A[i]=a;
  }
  FOR(i,Y){
    ll b; cin>>b; B[i]=b;
  }
  FOR(i,Z){
    ll c; cin>>c; C[i]=c;
  }
  sort(A.begin(), A.end(), greater<ll>());
  sort(B.begin(), B.end(), greater<ll>());
  sort(C.begin(), C.end(), greater<ll>());
  pq.push(make_pair(A[0]+B[0]+C[0],tmp));
  mp[tmp]=true;
  FOR(i,K){
    cout<<pq.top().first<<endl;
    vector<ll> d=pq.top().second;
    pq.pop();
    FOR(j,3){
      d[j]++;
      if(!mp[d] &&d[0]<X &&d[1]<Y &&d[2]<Z){
        pq.push(make_pair(A[d[0]]+B[d[1]]+C[d[2]],d));
        mp[d]=true;
      }
      d[j]--;
    }
  }
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct segtree {
	int N, dat[2 * 300000];
	segtree() {}
	segtree(int n) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++)
			dat[i] = INF;
	}
	// update k th element
	void update(int k, int a) {
		k += N - 1; // leaf
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}
	// min [a, b)
	int query(int a, int b) { return query(a, b, 0, 0, N); }
	int query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return INF;
		if (a <= l && r <= b) return dat[k];
		int m = (l + r) / 2;
		return min(query(a, b, k * 2 + 1, l, m), query(a, b, k * 2 + 2, m, r));
	}
};


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

	ll sum = 0;
	vector<ll> a(n), b(n);
	vector<pll> sa(n);

	REP(i, n) {
		cin >> a[i] >> b[i];
		sa[i] = { a[i] + b[i],i };
	}


	sort(ALL(sa),greater<pll>());
	ll ans = 0;

	REP(i, n) {
		if (i % 2 == 0) {
			ans += a[sa[i].second];
		}
		else{
			ans -= b[sa[i].second];
		}
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3328