akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define mod (1000000000+7)
#define N (10007)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

int main(void){
    ll n;
    cin>>n;
    vector<ll>a(3*n),l(2*n+1),r(2*n+1);
    for(ll i=0; i<3*n;i++)cin>>a[i];
    priority_queue<ll,vector<ll>,greater<ll>>p;
    for(ll i=0;i<n;i++){
        l[i+1]=l[i]+a[i];
        p.push(a[i]);
    }
    for(ll i=n;i<2*n;i++){
        ll x=p.top();
        if(a[i]>x){
            l[i+1]=l[i]-x+a[i];
            p.pop();
            p.push(a[i]);
        }
        else l[i+1]=l[i];
    }
    priority_queue<ll,vector<ll>,less<ll>>q;
    for(ll i=0;i<n;i++){
        r[i+1]=r[i]+a[3*n-1-i];
        q.push(a[3*n-1-i]);
    }
    for(ll i=n;i<2*n;i++){
        ll x=q.top();
        if(a[3*n-i-1]<x){
            r[i+1]=r[i]-x+a[3*n-i-1];
            q.pop();
            q.push(a[3*n-i-1]);
        }
        else r[i+1]=r[i];
    }
    ll ans=-(ll)100000000000000;
    for(ll i=n;i<=2*n;i++){
        ans=max(ans,l[i]-r[3*n-i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 8052
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll N;
	cin>>N;
	string S;
	cin>>S;
	if(N%2==1){
		cout<<"No";
		return 0;
	}
	REP(i,N/2){
		if(S[i]!=S[i+N/2]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a,b,c,n,t[1000001],ansno;
double weight,height,bmi,bmi2,ansbmi;
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    ansbmi=99999.9;
    ansno=9999999;
    for(int i=0;i<n;i++){
      cin>>a>>height>>weight;
      height/=100.0;
      bmi=weight/(height*height);
 
      bmi2=22.0-bmi;
       
      if(bmi2<0.0)bmi2*=-1.0;
      //cout<<bmi2<<endl;
      if(ansbmi>bmi2){
    ansbmi=bmi2;
    ansno=a;
      }
      if(ansbmi==bmi2&&ansno>a){
    ansbmi=bmi2;
    ansno=a;
      }
 
    }
    cout<<ansno<<endl;
     
  }
  return 0;
}

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

struct UnionFind{
  vector<int> par;

  UnionFind(int N) : par(N){ //作成
    for(int i = 0; i< N; i++){
      par[i] = i;
    }
  }

  int root(int x){
    if(par[x] == x){
      return x;
    }
    return par[x] = root(par[x]);
  }

  void unite(int x, int  y){ //結合
    int rx  = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx]  = ry;
  }

  bool same(int  x, int y){ //確認
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }

};


int N,  M;

int main(){
  cin >> N >>  M;
  vector<int> p(N);
  for(int i =  0; i<N; i++){
    cin >> p.at(i);
  }
  UnionFind uu = UnionFind(N+1);
  int buf1, buf2;
  for(int i =0; i<M; i++){
    cin >> buf1 >> buf2;
    uu.unite(buf1, buf2);
  }
  int ans =0;
  for(int i = 0; i<N; i++){
    if(uu.same(i+1,p.at(i))){
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
from sys import stdin
from itertools import accumulate

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

MOD = 10**9 + 7

N = d_in()
A_list = ds_in()

def factorial(N):
    val = 1
    for i in range(1, N+1):
        val = (val * i) % MOD
    return val

def recursive_square(n, m, p):
    """ n**p (mod m) """
    if p == 0:
        return 1 % m
    if p % 2 == 0:
        root = recursive_square(n, m, p//2) % m 
        return (root ** 2) % m
    else:
        return ((n % m) * recursive_square(n, m, p-1)) % m
        
def factorize(n):
    if n == 1:
        return [(1, 1)]
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n //= b
            e += 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

N_factorial = factorial(N)

Coefs = []
lastval = 0
Inv = dict()
for i in range(1, N+1):
    fac = factorize(i)
    temp = N_factorial
    for f in fac:
        if f[0] not in Inv.keys():
            Inv[f[0]] = recursive_square(f[0], MOD, MOD-2)
        for _ in range(f[1]):
            temp = (temp * Inv[f[0]]) % MOD
    lastval = (lastval + temp) % MOD
    Coefs.append(lastval)

if N == 1:
    print(A_list[0])
else: 
    ans = 0
    for i in range(N):
        ans = (ans + A_list[i] * (Coefs[i] + Coefs[N-i-1] - Coefs[0])) % MOD 
    print(ans)



Measured memory_bytes: 14252
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int cmpfunc(const void *a, const void *b)
{
	return (*(int *)a - *(int *)b);
}

int main(void)
{
	int N, M, X, Y;
	scanf("%d %d %d %d", &N, &M, &X, &Y);

	int array[N];
	int array2[M];

	for (int i = 0; i < N; i++)
		scanf("%d", &array[i]);

	for (int i = 0; i < M; i++)
		scanf("%d", &array2[i]);

	qsort(array, N, sizeof(int), cmpfunc);
	qsort(array2, M, sizeof(int), cmpfunc);
	int C = 201;
	int res[C];

	memset(res, 0, sizeof(res[0]) * C);
	int index = 0;
    
	if (array[N-1]>=array2[0])
	{
      printf("War");
	  return 0;
	}

	for (int i = array[N-1]+1; i <=array2[0]; i++)
	{

		res[index] = i;
		index++;
	}
    int count = 0;

	for (int i = 0; i < index; i++)
	{
		if (res[i] > X && res[i] <= Y)
		{
			count++;
		}
	}

     if (count == 0)printf("War");
	 else printf("No War");

	return 0;
} 


Measured memory_bytes: 128
class dice:
    def __init__(self,label):
        self.top, self.front, self.right, self.left, self.rear, self.bottom \
                = label
  
    def roll(self,op):
        if   op=='N': self.top, self.front, self.bottom, self.rear = \
                                self.front, self.bottom, self.rear , self.top
        elif op=='E': self.top, self.left , self.bottom, self.right = \
                                self.left , self.bottom, self.right, self.top
        elif op=='W': self.top, self.right, self.bottom, self.left = \
                                self.right, self.bottom, self.left , self.top
        elif op=='S': self.top, self.rear , self.bottom, self.front = \
                                self.rear , self.bottom, self.front, self.top
  
    def print_top(self): print(self.top)
    def print_right(self): print(self.right)
  
    def get_label(self):
        return [self.top, self.front, self.right, self.left, self.rear, self.bottom]
 
    def compare(self, label):
        for op in 'EEENEEENEEESEEESEEENEEEN':
            if self.get_label() == label:
                return True
            self.roll(op)
        else:
            return False
   
if __name__=='__main__':
    n = int(input())
    L = []
    for i in range(n):
        label = list(map(int,input().split()))
        for d in L:
            if d.compare(label): break
        else:
            L.append(dice(label))
            continue
        print('No')
        break
    else:
        print('Yes')


Measured memory_bytes: 5608
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int H,W;
    int ans=0,maxans=0;
    string fie[1002],ansfie[2];
    cin>>H>>W;
    for(int i=0;i<H;i++)cin>>fie[i];
    for(int i=0;i<2;i++)cin>>ansfie[i];
    for(int i=0;i<H-1;i++){
        for(int j=0;j<W-1;j++){
            if(fie[i][j]==ansfie[0][0]&&fie[i][j+1]==ansfie[0][1]&&fie[i+1][j]==ansfie[1][0]&&fie[i+1][j+1]==ansfie[1][1])ans++;
        }
    }
    maxans=ans;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            for(int k=0;k<3;k++){
                int a=0,b=0;
                char p;
                if(k==0)p='J';
                if(k==1)p='O';
                if(k==2)p='I';
                if(i!=H-1&&j!=W-1){
                    if(fie[i][j]==ansfie[0][0]&&fie[i][j+1]==ansfie[0][1]&&fie[i+1][j]==ansfie[1][0]&&fie[i+1][j+1]==ansfie[1][1])a++;
                    if(p==ansfie[0][0]&&fie[i][j+1]==ansfie[0][1]&&fie[i+1][j]==ansfie[1][0]&&fie[i+1][j+1]==ansfie[1][1])b++;
                }
                if(i!=0&&j!=W-1){
                    if(fie[i-1][j]==ansfie[0][0]&&fie[i-1][j+1]==ansfie[0][1]&&fie[i][j]==ansfie[1][0]&&fie[i][j+1]==ansfie[1][1])a++;
                    if(fie[i-1][j]==ansfie[0][0]&&fie[i-1][j+1]==ansfie[0][1]&&p==ansfie[1][0]&&fie[i][j+1]==ansfie[1][1])b++;
                }
                if(i!=H-1&&j!=0){
                    if(fie[i][j-1]==ansfie[0][0]&&fie[i][j]==ansfie[0][1]&&fie[i+1][j-1]==ansfie[1][0]&&fie[i+1][j]==ansfie[1][1])a++;
                    if(fie[i][j-1]==ansfie[0][0]&&p==ansfie[0][1]&&fie[i+1][j-1]==ansfie[1][0]&&fie[i+1][j]==ansfie[1][1])b++;
                }
                if(i!=0&&j!=0){
                    if(fie[i-1][j-1]==ansfie[0][0]&&fie[i-1][j]==ansfie[0][1]&&fie[i][j-1]==ansfie[1][0]&&fie[i][j]==ansfie[1][1])a++;
                    if(fie[i-1][j-1]==ansfie[0][0]&&fie[i-1][j]==ansfie[0][1]&&fie[i][j-1]==ansfie[1][0]&&p==ansfie[1][1])b++;
                }
                maxans=max(maxans,ans+b-a);
            }
        }
    }
    cout<<maxans<<endl;
    return 0;
}

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

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int ans=0;
	if(s[0]=='1') ans++;
	if(s[1]=='1') ans++;
	if(s[2]=='1') ans++;
	cout<<ans;
int ans2;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define pival 3.14159265359
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pqq priority_queue
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl '\n'
ll power(ll x, ll y, ll p)
{ 
    ll res = 1;  
    x = x % p;
    while (y > 0) { 
        if (y & 1) res = (res * x) % p; 
        y = y >> 1;
        x = (x * x) % p;   
    } 
    return res; 
}
const ll L = 1e5 + 5;
const ll logn = 20;
ll parent[L];
ll dp[L][logn + 5];
vector <ll> ad[L];
ll vis[L];
ll depth[L];
void dfs(ll ind, ll par)
{
	vis[ind] = 1;
	parent[ind] = par;
	for (ll v : ad[ind]) {
		if (!vis[v]) {
			depth[v] = depth[ind] + 1;
			dfs(v, ind);		
		}
	}
}
ll lca(ll u, ll v)
{
	if (depth[u] < depth[v])
		swap(u, v);
	ll dist = depth[u] - depth[v];
	for (ll i = logn; i >= 0; i--) {
		ll temp = dist - (1 << i);
		if (temp >= 0) {
			dist -= (1 << i);
			u = dp[u][i];
		}
	}
	if (u == v)
		return u;
	for (ll i = logn; i >= 0; i--) {
		if (dp[u][i] != dp[v][i]) {
			u = dp[u][i];
			v = dp[v][i];
		} 
	}
	return parent[u];
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 	ll n, u, v;
 	cin >> n >> u >> v;
 	u--, v--;
 	depth[v] = 0;
 	ll x, y;
 	for (ll i = 1; i < n; i++) {
 		cin >> x >> y;
 		x--, y--;
 		ad[x].pb(y);
 		ad[y].pb(x);
 	}
 	dfs(v, v);
 	for (ll i = 0; i < n; i++) {
 		for (ll j = 0; j <= logn; j++) {
 			dp[i][j] = 0;
 		}
 	}
 	for (ll i = 0; i < n; i++) {
 		dp[i][0] = parent[i];
 	}
 	for (ll j = 1; j <= logn; j++) {
 		for (ll i = 0; i < n; i++) {
 			dp[i][j] = dp[dp[i][j - 1]][j - 1];
 		}
 	}
 	ll ans = depth[u] - 1;
 	for (ll i = 0; i < n; i++) {
 	 	ll com = lca(u, i);
 		ll dist1 = depth[com];
 		ll dist2 = depth[u] - depth[com];
 		if (dist1 > dist2) {
 			ans = max(ans, depth[i] - 1);
 		}
 	}
 	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 30336
#include<string>
#include<sstream>
#include<iostream>

using namespace std;

int main(){
	for(int m,n;cin>>m>>n,m;){
		static bool flg[1000];
		static int bef[1000],nxt[1000];
		for(int i=0;i<m;i++)	flg[i]=true,bef[i]=(i+m-1)%m,nxt[i]=(i+1)%m;

		int pos=0,num=m;
		for(int i=1;i<=n;i++){
			string s;	cin>>s;
			if(num==1)	continue;

			bool ok=true;
			if(i%15==0){	if(s!="FizzBuzz")	ok=false;	}
			else if(i%3==0){	if(s!="Fizz")	ok=false;	}
			else if(i%5==0){	if(s!="Buzz")	ok=false;	}
			else{
				stringstream ss;	ss<<i;
				if(s!=ss.str())	ok=false;
			}

			if(!ok){
				flg[pos]=false;
				int tmpb=bef[pos],tmpn=nxt[pos];
				bef[tmpn]=tmpb;
				nxt[tmpb]=tmpn;
				num--;
			}
			pos=nxt[pos];
		}

		for(int i=0,j=0;i<m;i++)	if(flg[i])	cout<<(j++?" ":"")<<i+1;
		cout<<endl;
	}

	return 0;
}

Measured memory_bytes: 952
#include <bits/stdc++.h> 
using namespace std; 
typedef   long  long int ll;
int main () 
{
  ll a,b,c;cin>>a>>b>>c;
  ll k=c-(a+b);
  ll m=k*k,n=4*a*b;
  if (k<0) m=0-m;
if (m>n) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int const maxn=2e5+5;
ll const INF=1e18;
ll a[maxn],b[maxn],res;
int n;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
ll get(int l,int pos,int r){
    res=min(res,max(max(b[l],b[pos]-b[l]),max(b[r]-b[pos],b[n]-b[r]))-min(min(b[l],b[pos]-b[l]),min(b[r]-b[pos],b[n]-b[r])));
}
void dfs(int pos){
    int l=lower_bound(b+1,b+n+1,b[pos]>>1)-(b+1);
    int r=lower_bound(b+1,b+n+1,b[pos]+((b[n]-b[pos])>>1))-(b+1);
    get(l,pos,r);
    if(l+1<pos) get(l+1,pos,r);
    if(r+1<n) get(l,pos,r+1);
    if(l+1<pos&&r+1<n) get(l+1,pos,r+1);
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        a[i]=read();
        b[i]=b[i-1]+a[i];
    }
    res=INF;
    for(int i=2;i<=n-2;i++) dfs(i);
    printf("%lld\n",res);
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using Lint=long long;


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

    int N,T; cin>>N>>T;
    vector<int> sum(T+1);
    for(int i=0;i<N;i++){
        int l,r; cin>>l>>r;
        sum[l]++; sum[r]--;
    }
    for(int i=1;i<=T;i++) sum[i]+=sum[i-1];
    int ans=0;
    for(int i=0;i<=T;i++) chmax(ans,sum[i]);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3352
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N; cin>>N;
	vector<int> A(N);
	map<int,int> cnt;
	rep(i,N){
		cin>>A[i];
		cnt[A[i]]++;
	}
	sort(all(A));
	int ans = 0;
	for(int i = N-1; i>= 0; --i){
		if(cnt[A[i]] < 1)continue;
		--cnt[A[i]];
		int need = pow(2LL, (int)log2(A[i])+1) - A[i];
		// printf("%d,%d\n", A[i], need);
		if(cnt[need] > 0){
			++ans;
			--cnt[need];
		}
	}
	cout<<ans<<endl;
}

// int main(){
// 	int N; cin>>N;
// 	vector<ll> A(N);
// 	map<ll,ll> hash;
// 	priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> Q;
// 	rep(i,N){cin>>A[i]; hash[A[i]]++;}
// 	rep(i,N){
// 		ll cand = 0;
// 		ll t = 2;
// 		while(t < 1000000100){
// 			if(hash.count(t - A[i]) == 1){
// 				if(A[i] == t-A[i]){
// 					if(hash[A[i]] >= 2){++cand;}
// 				}else{
// 					++cand;
// 				}
// 			}
// 			t *= 2;
// 		}
// 		if(cand != 0){
// 			Q.push(make_pair(cand, i));
// 		}
// 	}
// 	// while(!Q.empty()){
// 	// 	cout<<Q.top().second<<" has "<<Q.top().first<<endl;
// 	// 	Q.pop();
// 	// }
// 	// return 0;
// 	ll ans = 0;
// 	while(!Q.empty()){
// 		ll e = A[Q.top().second];
// 		Q.pop();
// 		if(hash[e] <= 0)continue;
// 		ll t = 2;
// 		while(t < 1000000100){
// 			if(hash[t-e] > 0){
// 				++ans;
// 				--hash[t-e];
// 				--hash[e];
// 				break;
// 			}
// 			t *= 2;
// 		}
// 	}
// 	cout<<ans<<endl;
// 	return 0;
// }

Measured memory_bytes: 22924
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn main() {
  let n: u32 = read();
  
  let ans = if n % sum_each_digits(n) == 0 { "Yes" } else { "No" };
  println!("{}", ans);
}

fn sum_each_digits(x: u32) -> u32 {
  x.to_string().chars().fold(0, |a, c| a + c.to_digit(10).unwrap())
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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

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

VVI E(5050);
VI used(5050,0);
VI ans;

void  topo(int x){
    if(used[x]) return;
    used[x]=1;
    for(int e:E[x]){
        topo(e);
    }
    ans.pb(x);
}

int main(){
    int i,j;
    int n,m;
    cin>>n>>m;
    vector<vector<bool> > v(n,vector<bool>(n));
    for(i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        x--; y--;
        v[x][y]=1;
        E[y].pb(x);
    }
    for(i=0;i<n;i++) topo(i);
    for(i=0;i<n;i++) cout<<ans[i]+1<<endl;
    for(i=1;i<n;i++){
        if(v[ans[i-1]][ans[i]]!=1){
            cout<<1<<endl;
            break;
        }
        if(i==n-1) cout<<0<<endl;
    }
}


Measured memory_bytes: 7100
#include <cstdio>
#include <iostream>

int main() {
  uint32_t n = 0;
  scanf("%d", &n);

  int i = 0;
  uint64_t t = 0;
  uint64_t p = 0;
  for (int i = 0; i < n; i++) {
    scanf("%llu", &t);
    if (!p) {
      p = t;
    } else {
      if (t == p) {
        continue;
      }
      if (t > p) {
        auto tmp = t;
        t = p;
        p = tmp;
      }
      auto a = p;
      auto b = t;

      uint64_t r = a % b;
      while (r != 0) {
		a = b;
        b = r;
        r = a % b;
      }
      p = (p / b) * t;
    }
  }

  std::cout << p << std::endl;
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i];
    int counter=0;
    for(int i=0;i<n;i++)
    {
        while(arr[i]>0&&arr[i]%2==0)
        {
            arr[i]/=2;
            counter++;
        }
    }
    cout<<counter<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cctype>
#include <iostream>
#include <cstring>
#include <algorithm>
#define R register
#define IN inline
#define W while
#define ls (now << 1)
#define rs ((now << 1) | 1)
#define MX 200500
#define gc getchar()
#define ll long long
template <class T>
IN void in(T &x)
{
	x = 0; R char c = gc;
	for (; !isdigit(c); c = gc);
	for (;  isdigit(c); c = gc)
	x = (x << 1) + (x << 3) + c - 48;
}
template <class T> IN T max(T a, T b) {return a > b ? a : b;}
template <class T> IN T min(T a, T b) {return a < b ? a : b;}
template <class T> IN T abs(T a) {return a > 0 ? a : -a;}
int n, q;
struct Node
{
	ll val[3], tag;
	Node(){std::memset(val, 63, sizeof(val));}
}tree[MX << 2];
IN void pushup(R int now)
{
	tree[now].val[0] = min(tree[ls].val[0], tree[rs].val[0]);
	tree[now].val[1] = min(tree[ls].val[1], tree[rs].val[1]);
	tree[now].val[2] = min(tree[ls].val[2], tree[rs].val[2]);
}
IN void pushdown(R int now)
{
	if (tree[now].tag)
	{
		tree[ls].val[0] += tree[now].tag;
		tree[ls].val[1] += tree[now].tag;
		tree[ls].val[2] += tree[now].tag;
		tree[ls].tag	+= tree[now].tag;
		tree[rs].val[0] += tree[now].tag;
		tree[rs].val[1] += tree[now].tag;
		tree[rs].val[2] += tree[now].tag;
		tree[rs].tag	+= tree[now].tag;
		tree[now].tag = 0;
	}
}
void modify(R int now, R int lef, R int rig, R int pos, R ll v)
{
	if (lef == rig)
	{
		tree[now].val[0] = v;
		tree[now].val[1] = v - pos;
		tree[now].val[2] = v + pos;
		return;
	}
	pushdown(now);
	int mid = lef + rig >> 1;
	if (pos <= mid) modify(ls, lef, mid, pos, v);
	else modify(rs, mid + 1, rig, pos, v);
	pushup(now);
}
IN void add(R ll v)
{
	tree[1].tag += v;
	tree[1].val[0] += v;
	tree[1].val[1] += v;
	tree[1].val[2] += v;
}
ll query(R int now, R int lef, R int rig, R int lb, R int rb, R int id)
{
	if (lef >= lb && rig <= rb) return tree[now].val[id];
	pushdown(now);
	int mid = lef + rig >> 1; ll ret = LONG_LONG_MAX;
	if (lb <= mid) ret = query(ls, lef, mid, lb, rb, id);
	if (rb > mid) ret = min(ret, query(rs, mid + 1, rig, lb, rb, id));
	return ret;
}
int main(void)
{
	int a, b, last, cur, del;
	ll res1, res2, res3;
	in(n), in(q), in(a), in(b);
	in(last);
	modify(1, 1, n, b, abs(last - a));
	modify(1, 1, n, a, abs(last - b));
	W (--q)
	{
		in(cur); del = abs(last - cur);
		res1 = query(1, 1, n, cur, cur, 0) + del;
		res2 = query(1, 1, n, 1, cur, 1) + cur;
		res3 = query(1, 1, n, cur + 1, n, 2) - cur;
		res1 = min(res1, min(res2, res3));
		add(del);
		modify(1, 1, n, last, res1);
		last = cur;
	}
	printf("%lld", tree[1].val[0]);
}

Measured memory_bytes: 25344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define pi 2*acos(0.0)
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define mod 1000000007
int main()
{
    FIO;

    ///freopen("in.txt","r",stdin);
    ///freopen("output.txt","w",stdout);
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll cnt=0,mn=a;
    cnt = (n%a==0)?n/a:(n/a)+1;
    if(b>=mn)cnt++;
    else {cnt  = (n%b==0)?(n/b)+1:(n/b)+2;mn =b;}
    if(c>=mn)cnt++;
    else {cnt = (n%c==0)?(n/c)+2 : (n/c)+3; mn=c; }
    if(d>=mn)cnt++;
    else {cnt = (n%d==0)?(n/d)+3 : (n/d)+4 ; mn=d;}
    if(e>=mn)cnt++;
    else {cnt = (n%d==0)?(n/e)+4 : (n/e)+5;}
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 100005
#define ll long long
#define MOD 1000000007
using namespace std;

ll x[MAXN],y[MAXN];
ll n,m;


int main(){
	
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld",&x[i]);
	}
	for(int i=1;i<=m;i++){
		scanf("%lld",&y[i]);
	}
	ll totx=0;
	int before=0;
	for(int i=2;i<=n;i++){
		x[i-1]=x[i]-x[i-1];
		before=(before+(i-1)*x[i-1])%MOD;
		totx=(totx+before)%MOD;
	}
	
	ll toty=0;
	before=0;
	for(int i=2;i<=m;i++){
		y[i-1]=y[i]-y[i-1];
		before=(before+(i-1)*y[i-1])%MOD;
		toty=(toty+before)%MOD;
	}
	ll ans=totx*toty%MOD;
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 1664
n, m = map(int, input().split())
abList = [list(map(int, input().split())) for _ in range(n)]
abList.sort()
abSum = 0
abNum = m
for ab in abList:
    a, b = ab[0], ab[1]
    if b >= abNum:
        abSum += abNum * a
        break
    else:
        abSum += b * a
        abNum -= b
print(abSum)


Measured memory_bytes: 27752
N = int(input())
A = [int(a) for a in input().split()]
B = [int(a) for a in input().split()]

def xor(L):
    a = 0
    for l in L: a ^= l
    return a

def chk(L1, L2, k):
    L1.sort()
    L2.sort()
    s, j = 0, 0
    for i in range(N)[::-1]:
        while j < N and L1[i] + L2[j] < k:
            j += 1
        s += N - j
    return s % 2 * k

t = (xor(A) ^ xor(B)) * (N % 2)
for i in range(28):
    m = (1 << i+1) - 1
    t ^= chk([a&m for a in A], [b&m for b in B], m + 1)

print(t)

Measured memory_bytes: 136844
#include <iostream>
using namespace std;
int main()
{
    int i, n, input, max=-1000000, min=1000000;
    long long int sum = 0;
    cin >> n;
    
    for(i=1; i<=n; i++)
    {
        cin >> input;
        sum = sum + input;
        if ( input > max)
        max = input;
        if ( input < min)
        min = input;
    }
    cout << min << " " << max << " " << sum << endl;
}


Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <set>
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
typedef long long LL;


string a;
int main() {
	int s = 0;
	cin >> a;
	REP(i, 0, 16) {
		s += a[i] != "CODEFESTIVAL2016"[i];
	}
	cout << s << endl;
	return 0;
}

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

# スペース区切りの整数の入力
N,M = map(int, input().split())


# スペース区切りの整数の入力
list = list(map(int, input().split()))


A=sum(list)

Z=A/4/M



index=0


for num in range(N):
    if list[num]>=Z:
        index=index+1


if index>=M:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 12488
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ


		Scanner sc = new Scanner(System.in);

		//入力表示
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		int c=a+b;
		int d=a-b;
		int e=a*b;

		int ans=Math.max(c,Math.max(d,e));

		 System.out.println(ans);
	}

}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    unsigned long long int  H, W;
    cin >> H >> W;

    if (H == 1){
        cout << 1 << endl;
        return 0;
    }
    if(W==1){
        cout << 1 << endl;
        return 0;
    }
    if((H%2 == 0) && (W%2 == 0)){
        cout << H * W / 2 << endl;
    }
    if((H%2 == 1) && (W%2 == 0)){
        cout << (H/2) * (W/2) + ((H+1)/2) * (W/2) << endl;
    }
    if((H%2 == 0) && (W%2 == 1)){
        cout << (H/2) * (W/2) + (H/2) * ((W+1)/2) << endl;
    }
    if((H%2 == 1) && (W%2 == 1)){
        cout << (H/2) * (W/2) + ((H+1)/2) * ((W+1)/2) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Name: Bus Line
//Level: 2
//Category: シミュレーション
//Note: 

/**
 * 1周ぶんの系列を埋め込んでおき、適宜出力する。
 * 直線部のバス停が指定された時は別途対応する。
 */
#include <iostream>
#include <vector>

using namespace std;

const int ROUTE[] = {
    0,1,2,3,4,5,6,7,8,9,5,4,3,2,1
};

bool solve(bool first) {
    int a, b;
    cin >> a >> b;
    if(a <= 5 && b <= 5) {
        bool first = true;
        for(int i = a; i != b; i += a<b?1:-1) {
            if(!first) cout << ' ';
            cout << i;
            first = false;
        }
        cout << ' ' << b;
    } else {
        int cur = 0;
        while(ROUTE[cur] != a) ++cur;
        cout << ROUTE[cur];
        while(ROUTE[cur] != b) {
            cur = (cur + 1) % (sizeof(ROUTE) / sizeof(int));
            cout << ' ' << ROUTE[cur];
        }
    }
    cout << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout.setf(ios::fixed);
    cout.precision(2);

    bool first = true;
    int N;
    cin >> N;
    while(N-- && solve(first)) {
        first = false;
    }
    return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

#define MAX 100005
#define NIL -1

struct Node {
    int parent, left, right;
};

Node T[MAX];
int  n, D[MAX], H[MAX];

void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].left != NIL) {
        h1 = setHeight(T[u].left) + 1;
    }
    if (T[u].right != NIL) {
        h2 = setHeight(T[u].right) + 1;
    }
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u) {
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u) {
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;

    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";

    if (T[u].parent == NIL) {
        cout << "root" << endl;
    } else if (T[u].left == NIL && T[u].right == NIL) {
        cout << "leaf" << endl;
    } else {
        cout << "internal node" << endl;
    }
}

int main() {
    ios::sync_with_stdio(false), H[MAX];
    cin.tie(0);

    // cout << fixed << setprecision(5);

    int v, l, r, root = 0;
    cin >> n;
    rep(i, n) { T[i].parent = NIL; }
    rep(i, n) {
        cin >> v >> l >> r;
        T[v].left  = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    rep(i, n) {
        if (T[i].parent == NIL) root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    rep(i, n) print(i);

    return 0;
}



Measured memory_bytes: 3132
#include<bits/stdc++.h>
using namespace std;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define stoink stack<ll>
#define vec vector <ll>
#define vg vector<vector<ll> >
#define vgw vector<vector<pair<ll,ll> >
#define pa pair<ll,ll>
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 1000000000000
#define mod 998244353
ll n,w;
vec dp;
vec weight,value;
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n >> w;
	weight.resize(n);
	value.resize(n);
	ll i;
	ll sum = 0;
	for(i = 0 ; i < n ; i++) {
		cin >> weight[i] >> value[i];
		sum += value[i];
	}
	dp.resize(sum+1,inf);
	ll j;
	dp[0] = 0;
	for(i = 0 ; i < n ; i++) {
		for(j = sum; j >= value[i] ;j--) {
			dp[j] = min(dp[j],dp[j - value[i]] + weight[i]);
		}
	}
	ll ans = -1;	
	for(i = 0 ; i <= sum ; i++) {
		if(dp[i] <= w)
			ans = max(ans,i);
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   int n,k;
   cin>>n>>k;
   string s;
   cin>>s;
   for(int i=0;i<n;i++){
       if(i==k-1){
           if(s.at(i)=='A')cout<<"a";
           else if(s.at(i)=='B')cout<<"b";
           else cout<<"c";
       }else{
           cout<<s.at(i);
       }
   }
   cout<<endl;
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M INT_MAX
int dp[4][5001][2];
int main(void){
	int n,nn,ti[10001],i,j,k,t,p,pp;
	cin>>n;
	nn=n/2;
	for(i=0;i<n-1;i++) cin>>ti[i];
	ti[n-1]=0;
//	for(i=0;i<n;i++) cout<<ti[i]<<endl; 
	for(i=0;i<=2;i++){
		for(j=0;j<=nn;j++) dp[i][j][0]=M,dp[i][j][1]=M;
	}
	dp[0][1][0]=ti[0];
	for(i=0;i<n-1;i++){
		if(i%2==0)p=0,pp=1;
		else p=1,pp=0;
		for(j=0;j<=nn;j++) dp[pp][j][0]=M,dp[pp][j][1]=M;
		for(j=1;j<=nn;j++){
			if(dp[p][j][0]!=M){
				dp[pp][j][1]=min(dp[pp][j][1],dp[p][j][0]);
				t=dp[p][j][0]-ti[i]+ti[i+1];
				dp[pp][j+1][0]=min(dp[pp][j+1][0],t);
			}
			if(dp[p][j][1]!=M){
				dp[pp][j][1]=min(dp[pp][j][1],dp[p][j][1]);
				t=dp[p][j][1]+ti[i+1]+ti[i];
				dp[pp][j+1][0]=min(dp[pp][j+1][0],t);
			}
		}
	}
	cout<<min(dp[1][nn][0],dp[1][nn][1])<<endl;
	return 0;
}


Measured memory_bytes: 3256
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 5010;
bool f[N][N], g[N][N];
int n, k, a[N], s[N];
int main() {
	scanf("%d%d",&n,&k); LL sum = 0;
	rep(i,1,n) scanf("%d",&a[i]), sum += a[i];
	if (sum < k) { printf("%d\n",n); return 0; }
	f[0][0] = true;
	rep(i,1,n) {
		rep(j,0,k) f[i][j] = f[i - 1][j];
		rep(j,a[i],k) f[i][j] |= f[i - 1][j - a[i]];
	}
	g[n + 1][0] = true;
	dep(i,n,1) {
		rep(j,0,k) g[i][j] = g[i + 1][j];
		rep(j,a[i],k) g[i][j] |= g[i + 1][j - a[i]];
	}
	int ans = 0;
	rep(i,1,n) {
		memset(s, 0, sizeof(s));
		rep(j,0,k) if (g[i + 1][j]) s[j] = 1;
		rep(j,1,k) s[j] += s[j - 1];
		if (a[i] >= k) continue;
		bool nes = false;
		Rep(j,k) {
			int t = k - a[i] - 1 - j;
			if (f[i - 1][j] && s[k - 1 - j] != (t < 0 ? 0 : s[t])) nes = true;
		}
		if (!nes) ans ++;
	}
	cout <<ans<<endl;
	return 0;
}


Measured memory_bytes: 49280
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        String[] array = str.split(" ");
        int[] num =new int[3];
        for(int i=0;i<3;i++){
            num[i]=Integer.parseInt(array[i]);
        }
        String str2 = sc.nextLine();       
        String[] array2 = str2.split(" ");
        int[] num2 = new int[num[1]];
        for(int i=0;i<array2.length;i++){
            num2[i]=Integer.parseInt(array2[i]);
        }
        int low=0;
        int high=0;
        for(int i=0;i<array2.length;i++){
            if(num2[i]<num[2]){
                low++;
            }else{
                high++;
            }
        }
        int min=Math.min(low, high);
        System.out.println(min);
    }
}

Measured memory_bytes: 21844
import math
import sys
import itertools

n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
e=[0]*m
for i in range(q): 
  a[i],b[i],c[i],d[i]=map(int,input().split())
for j in range(m):
  e[j]=j+1
total=0
maxnum=0
num=1<<len(e)
for current in itertools.combinations_with_replacement(e, n):
  if(len(current)==n):
    total=0
    #print(current)
    for i in range(q):
      if current[b[i]-1]-current[a[i]-1]==c[i]:
        total+=d[i]
    #print(total)
    maxnum=max(maxnum,total)
print(maxnum)  


Measured memory_bytes: 9120
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()
A = LIST()

ans = 0
tmp = sum(A)
for i in range(N-1):
    # 減らす分, 減らさなくてこともある
    a = max(A[i] + A[i+1] - X, 0)

    A[i+1] = max(0, A[i+1]-a)
    # A[i]で残り減らす必要ある分
    b = max(0, a - A[i+1])
# print(A)
# print(ans)
c = 0
if A[0] + A[1] > X:
    c = A[0] + A[1] - X
A[0] = A[0] - c
print(tmp-sum(A))

Measured memory_bytes: 14884
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef long long ll;
const int INF = 1e9;
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<int> > adj(10,vector<int>(10));
    rep(i,10)rep(j,10)cin >> adj[i][j];

    rep(k,10){
        rep(i,10){
            rep(j,10){
                adj[i][j] = min(adj[i][j], adj[i][k] + adj[k][j]);
            }
        }
    } 
    int res = 0;
    rep(i,H){
        rep(j,W){
            int a;
            cin >> a;
            if(a != -1)res += adj[a][1];
        }
    }
    cout << res << endl;
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

ll fast(ll x,ll y){
    ll res=1;
    while(y){
        if(y&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        y >>= 1;
    }
    return res;
}

ll inv(ll n){
    return fast(n,mod-2);
}


void pre(){


}


void solve(){

    int n,m,k;
    cin >> n >> m >> k; 
    ll a[n+1];
    ll b[m+1];
    for(int i=1;i<n+1;i++){
        cin >> a[i];
    }
    ll pre[m+1];
    pre[0] = 0;
    for(int i=1;i<m+1;i++)
        cin >> b[i] , pre[i] = pre[i-1] + b[i];
    vector<ll> dp(n+m+1,oo);
    dp[0] = 0;
    ll cur=0;
    for(ll i=0;i<n+1;i++){
        if(i)cur += a[i];
        if(cur > k)break;
        ll rem = k - cur;
        ll pos = upper_bound(pre+1,pre+m+1,rem) - pre;
        pos--;
        dp[i + pos] = cur + pre[pos];
    }
    ll ans=0;
    for(int i=1;i<=m+n;i++){
        if(dp[i] <= k)
            ans = max(ans , (ll)i);
    }
    cout << ans << endl;

}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input00.txt","r",stdin);
    // #endif
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,count=0;cin >> n;
  vector<long long> a(n+1),b(n);
  for (int i=0;i<n+1;i++) cin >> a[i];
  for (int i=0;i<n;i++) cin >> b[i];
  for (int i=n-1;i>=0;i--) {
    if (a[i+1]<=b[i]) {b[i]-=a[i+1];count+=a[i+1];a[i+1]=0;}
	else {count+=b[i];a[i+1]-=b[i];b[i]=0;}
	if (a[i]<=b[i]) {b[i]-=a[i];count+=a[i];a[i]=0;}
	else {count+=b[i];a[i]-=b[i];b[i]=0;}
  }
  cout << count << endl;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

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

struct edge { int to,cost; };
const int MOD=1e9+7;

int main() {






  ll INF = LLONG_MAX/4;
  ll n,m,r; cin >> n >> m >> r;
  vector<ll> r_vec(r);
  REP(i,r){
    cin >> r_vec[i];
    r_vec[i]--;
  }
  sort(ALL(r_vec));
  vector<vector<ll>> ab(n,vector<ll>(n,INF));
  REP(i,m){
    ll a,b,c; cin >> a >> b >> c;
    a--;b--;
    ab[a][b] = c;
    ab[b][a] = c;
  }

  REP(k,n)REP(i,n)REP(j,n){
    ab[i][j] = min(ab[i][j], ab[i][k] + ab[k][j]);
  }

  ll res = INF;
  do{
    ll temp = 0;
    REP(i,r-1){
      temp += ab[r_vec[i]][r_vec[i+1]];
    }
    res = min(res,temp);
  }while(next_permutation(ALL(r_vec)));

  cout << res << endl;

  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int a,ans=1,x,y=0;
int main()
{
    cin>>a;
    for(int i=1;i<=a;i++)
        {
            if(i%2==1)
            {
                x++;
            }
            if(i%2==0)
            {
                y++;
            }
            ans=x*y;
        }
    cout<<ans;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <vector>

using namespace std;

int main()
{
  short a[3000], b[3000];
  short count = 0;

  while(1)
  {
    scanf("%hd %hd", &a[count], &b[count]);
    
    if (a[count] == 0 && b[count] == 0)
    {
      break;
    }

    if (a[count] > b[count])
    {
      int tmp = a[count];
      a[count] = b[count];
      b[count] = tmp;
      count++;
      continue;
    }

    count++;
  }

  for (int i = 0; i < 3000; i++)
  {
    if (a[i] == 0 && b[i] == 0)
    {
      break;
    }
    printf("%d %d\n", a[i], b[i]);
  }

  return 0;
}


Measured memory_bytes: 2616
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;

int main()
{
	int n;
	while (cin >> n&&n)
	{
		vs a;
		FOR(i, n)
		{
			string s; cin >> s;
			a.push_back(s);
		}
		FOR(i, n)
		{
			int s[5] = { 5,7,5,7,7 };
			int now = i;
			bool ok = true;
			for (int j = 0; j < 5; j++)
			{
				for (; now < n; now++)
				{
					if (s[j] == 0)break;
					if (s[j] < 0)
					{
						ok = false;
						break;
					}
					s[j] -= a[now].size();
				}
			}
			for (int j = 0; j < 5; j++)
			{
				if (s[j] != 0)ok = false;
			}
			if (ok)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 3132
import java.util.Scanner;
/**
 * @author saiyo
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		//int x = scan.nextInt();
		//int y = scan.nextInt();
		
		//Seisu s = new Seisu(x, y);
		//s.kouyaku();

		int con = scan.nextInt();
		
		int[] num = new int[con];
		for(int i = 0; i < con; i++){
			num[i] = scan.nextInt();
		}
		Seisu s = new Seisu(num);
		System.out.println(s.getProfit());
		
		//s.countSosu();
		/*
		Sort s = new Sort(num);
		s.printSort();
		s.insertionSort();
		*/
	}

}

class Seisu{
	private int x, y;
	private int snum[];
	
	Seisu(int x, int y){
		if(x >= y){
			this.x = x;
			this.y = y;
		}else{
			this.x = y;
			this.y = x;
		}
		
	}
	
	Seisu(int snum[]){
		this.snum = new int[snum.length];
		for(int i = 0; i < snum.length; i++){
			this.snum[i] = snum[i];
		}
	}
	
	public int getProfit(){
		int fstM = this.snum[0], sa, maxProfit = this.snum[1] - this.snum[0];
		for(int i = 1; i < this.snum.length; i++){
			sa = this.snum[i] - fstM;
			if(fstM > this.snum[i]){
				fstM = this.snum[i];
			}
			if(sa > maxProfit){
				maxProfit = sa;
			}
			
		}
		return maxProfit;
	}
	
	public void countSosu(){
		int con = 0;
		for(int nu: this.snum){
			con += isSosu(nu);
		}
		System.out.println(con);
	}
	
	public int isSosu(int num){
		for(int i = 2; i < Math.sqrt(num) + 1; i++){

			if(num % i == 0 && num != 2){
				return 0;
			}
			
		}
		return 1;
	}
	
	public void kouyaku(){
		System.out.println(modSeisu(this.x, this.y));
	}
	
	
	public int modSeisu(int x, int y){
		if(x % y == 0){
			return y;
		}else{
			return modSeisu(y , x % y);
		}
	}
}

class Sort{
	private int[] sorted;
	
	Sort(int[] sorted){
		this.sorted = new int[sorted.length];
		for(int i = 0; i < sorted.length; i++){
			this.sorted[i] = sorted[i];
		}
	}
	
	public void insertionSort(){
		int v, j;
		for(int i = 1; i < this.sorted.length; i++){
			v = this.sorted[i];
			j = i - 1;
			while(j >= 0 && this.sorted[j] > v){
				this.sorted[j + 1] = this.sorted[j];
				j--;
			}
			this.sorted[j + 1] = v;
			printSort();
		}
	}
	
	public void printSort(){
		for(int i  = 0; i < this.sorted.length - 1; i++){
			System.out.print(this.sorted[i] + " ");
		}
		System.out.println(this.sorted[this.sorted.length - 1]);
	}
}



Measured memory_bytes: 100260
#include <stdio.h>

int main(void){
    long long int h;
    long long int w;
    scanf("%lld %lld",&h,&w);
    if(h==1 || w==1){
        printf("1");
    }
    else if((h*w)%2==1){
        printf("%lld",((h*w)/2)+1);
    }
    else{
        printf("%lld",(h*w)/2);
    }
    return 0;
}

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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

LL dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
LL dy[] = {0, 0, 1, -1, -1, 1, -1, 1};

///**************************DONE****************************///

int main()
{
    int x, y;
    cin >> x >> y;

    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            if(i + j == x && i * 2 + j * 4 == y)
                return cout << "Yes\n", 0;
        }
    }

    cout << "No\n";
    return 0;
}


Measured memory_bytes: 3568