akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int h,w;
string s[30];
vector<vector<int>> dis(30,vector<int>(30,-1));
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1}; 
int bfs(int sx,int sy, int gx, int gy){
    queue<pair<int,int>> que;
    que.push({sx,sy});
    dis[sx][sy] = 0;
    while(!que.empty()){
        int x = que.front().first, y = que.front().second;
        que.pop();
        for(int i = 0;i < 4; i++){
            int nx = x + dx[i], ny = y + dy[i];
            if(nx >= 0 && nx < h && ny >= 0 && ny < w && s[nx][ny] == '.'){
                if(dis[nx][ny] == -1){
                    if(nx == gx && ny == gy) return dis[x][y] + 1;
                    else if(dis[nx][ny] == -1){
                        dis[nx][ny] = dis[x][y] + 1;
                        que.push({nx,ny});
                    }
                }
            }
        }
    }
}
void init(){
    rep(i,30) rep(j,30) dis[i][j] = -1;
}
int main(){
    cout << fixed << setprecision(10);
    cin >> h >> w;
    rep(i,h) cin >> s[i];
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(s[i][j] == '.'){
                rep(k,h){
                    rep(l,w){
                        if(i == k && j == l) continue;
                        else if(s[k][l] == '.'){
                            ans = max(ans,bfs(i,j,k,l));
                            init();
                        }
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

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


int main(){
	
	int a[10];
	double u,v;
	
	while(scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9],&u,&v)!=EOF){
		int sum = 0;
		rep(i,10)sum+=a[i];
		
		double par = u/(u+v);
		double pos = sum*par;
		
		int sum2 = 0;
		rep(i,10){
			sum2 += a[i];
			if(sum2+0.0000001>pos){
				printf("%d\n",i+1);
				break;
			}
		}
	}
	
}

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

using namespace std;


int main()
{
    string a,b,c; cin>>a>>b>>c;
    int sa=a.length();
    int sb=b.length();
    int sc=c.length();
    int pa=0,pb=0,pc=0;
    int p=1;
    while(1)
    {
        if(p==1)
        {
            if(pa==sa)
            {
                cout<<"A"; return 0;
            }
            char x=a[pa];
            if(x=='a') p=1;
            else if(x=='b') p=2;
            else p=3;
            pa++;
            continue;
        }
        else if(p==2)
        {
            if(pb==sb)
            {
                cout<<"B"; return 0;
            }
            char x=b[pb];
            if(x=='a') p=1;
            else if(x=='b') p=2;
            else p=3;
            pb++;
            continue;
        }
        else if(p==3)
        {
            if(pc==sc)
            {
                cout<<"C"; return 0;
            }
            char x=c[pc];
            if(x=='a') p=1;
            else if(x=='b') p=2;
            else p=3;
            pc++;
            continue;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> s(n);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  if (sum % 10 != 0) {
    cout << sum << endl;
    return 0;
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if ((sum - s[i]) % 10 != 0) {
      cout << sum - s[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
int main(){
 int i,r,n,p,c;
 for(;scanf("%d%d",&n,&r),n;){
  std::vector<int> v;
  for(i=n;i;i--)v.push_back(i);
  for(i=0;i<r;i++)scanf("%d%d",&p,&c),p--,std::rotate(v.begin(),v.begin()+p,v.begin()+p+c);
  printf("%d\n",v[0]);
 }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(n + 2);
	rep(i, n) cin >> v[i + 1];
	
	ll sum = 0;
	rep(i, n + 1) sum += abs(v[i + 1] - v[i]);
	rep(i, n){
		ll ans = sum;
		ans += abs(v[i + 2] - v[i]);
		ans -= abs(v[i + 1] - v[i]) + abs(v[i + 2] - v[i + 1]);
		cout << ans << endl;
	}
	
	return 0;
}

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

int n,m;
vector<vector<int>> e;
vector<int> length;
queue<int> vertex;

void bfs(int i){
  for(int x:e[i]){
    if(length[(x+n)%(3*n)]>length[i]+1){
      length[(x+n)%(3*n)]=length[i]+1;
      vertex.push((x+n)%(3*n));
    }
  }
}

int main(){
  cin>>n>>m;
  e.resize(3*n);
  length.resize(3*n);
  for(int i=0; i<3*n; ++i)length[i]=1000000000;
  
  for(int i=0; i<m; ++i){
    int u,v; cin>>u>>v;
    e[u-1].push_back(v-1+n);
    e[u-1+n].push_back(v-1+2*n);
    e[u-1+2*n].push_back(v-1);
  }
  int s,t; cin>>s>>t;

  length[s-1]=0;
  vertex.push(s-1);
  while(!vertex.empty()){
    bfs(vertex.front());
    vertex.pop();
  }

  if(length[t-1]==1000000000)cout<<-1<<endl;
  else cout<<length[t-1]/3<<endl;
}


Measured memory_bytes: 17792
import sys
import bisect
input = sys.stdin.readline

def main():
    N = int(input())

    dic = {}
    for i in range(N):
        a = int(input())
        if a in dic:
            dic[a] += 1
        else:
            dic[a] = 1
    
    ans = 0
    for num, count in dic.items():
        if count&1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 15076
#include<stdio.h>
int t[101];
int c[100];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<=a;i++){
			scanf("%d",t+i);
		}
		for(int i=0;i<=a;i++){
			int I=0;
			
			for(int j=0;j<=a;j++)if(i!=j)c[I++]=t[j];
			bool ok=true;
			for(int j=1;j<a;j++)if(c[1]-c[0]!=c[j]-c[j-1])ok=false;
			if(c[1]<=c[0])ok=false;
			if(ok){
				printf("%d\n",t[i]);
				break;
			}
		}
	}
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

#define N 1000000007

int main(void){
    int H,W,K;
    scanf("%d%d%d",&H,&W,&K);

    //ans[H][W]は、縦の長さがH,終点がWのあみだくじの本数
    long ans[H+1][W+1];
    //初期値のans[0]を格納
    ans[0][1]=1;
    for(int i=2;i<=W;i++) ans[0][i]=0;

    //DP表を更新する
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            ans[i][j]=0;
            //ans[i][j]がどう変わるのかを考える
            for(int k=0;k<(1<<(W-1));k++){
                //amida...あみだくじとして成立するなら0,しないなら1
                int amida=0;
                for(int l=0;l<(W-2);l++){
                    if(k&(1<<l) && k&(1<<(l+1))) amida=1;
                }

                //あみだくじとして成立しないならスキップ
                if(amida) continue;

                //左にずれて来るのを受け入れる
                if(j<W && (k>>(j-1))&1) ans[i][j]=(ans[i][j]+ans[i-1][j+1])%N;
                //右にずれて来るのを受け入れる
                else if(j>1 && (k>>(j-2))&1) ans[i][j]=(ans[i][j]+ans[i-1][j-1])%N;
                //そのまま
                else ans[i][j]=(ans[i][j]+ans[i-1][j])%N;
            }
        }
    }
    
    printf("%ld\n",ans[H][K]);

    return 0;
}

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

using namespace std;

typedef long long ll;

const ll M = 1000000007;
ll n, a, b;
ll ans;

ll f(ll p, ll q)
{
    if(q == 0) return 1;
    ll t = f(p, q / 2);
    if(q % 2 == 1) return t * t % M * p % M;
    return t * t % M;
}

int main()
{
    scanf("%lld%lld%lld", &n, &a, &b);
    ans = f(2, n);
    ll x = 1, y = 1;
    for(ll i = 1; i <= a; i++)
    {
        x *= n - i + 1;
        x %= M;
        x *= f(i, M - 2);
        x %= M;
    }
    for(ll i = 1; i <= b; i++)
    {
        y *= n - i + 1;
        y %= M;
        y *= f(i, M - 2);
        y %= M;
    }
    ans -= x + y + 1;
    ans = (ans + 3 * M) % M;
    printf("%lld\n", ans);
    return 0;
}


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

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

typedef pair<int,int> P;
const int hmax=1001,wmax=1001;
const int INF=1000100100;
char mp[hmax][wmax];
int d[hmax][wmax];
int h,w,n,ans=-1,total=0;
int sy,sx;
int dy[4]={-1,0,1,0},dx[4]={0,1,0,-1};
int gy[hmax*wmax],gx[hmax*wmax];


int bfs(){
    cin >> h >> w;
    rep(i,h)rep(j,w) d[i][j]=INF;
    queue<P> q;
    rep(i,h)rep(j,w){
        cin >> mp[i][j];
        if(mp[i][j]=='#'){
            gy[total]=i;
            gx[total]=j;
            total++;
            d[i][j]=0;
        }
    }
    rep(i,total) q.push(P(gy[i],gx[i]));
    while(q.size()){
        P p=q.front();
        q.pop();
        rep(i,4){
            int y=p.first+dy[i],x=p.second+dx[i];
            if(0<=y&&y<h&&0<=x&&x<w&&d[y][x]==INF&&mp[y][x]!='#'){
                q.push(P(y,x));
                d[y][x]=d[p.first][p.second]+1;
            }
        }
    }
    rep(i,h)rep(j,w){
        ans=max(ans,d[i][j]);
    }
    return ans;
}

int main(){
    cout << bfs() << endl;
    return 0;
}













Measured memory_bytes: 21136
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def solve(N: int, K: int):
    print(int(math.log(N)/math.log(K))+1)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
signed main(){
  int N,M;
  cin>>N>>M;
  int ans=((N-M)*100+M*1900)*(1<<M);
  cout<<ans<<endl;
  }


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

int main(){
	int n[1000000]={0};
	int x, ans=0;
	
	for(int i=1; i<=999999; i++){
		if(i==1) n[i]=-1;
		else if(n[i]==0){
			for(int k=2; k*i<=999999; k++){
				n[k*i]=-1;
			}
		}
	}
	
	while(cin>>x){
		ans=x;
		for(int j=1; j<=x; j++) ans+=n[j];
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define ZERO(a) memset(a,0,sizeof(a))
using namespace std;
typedef signed long long ll;

void solve(){
 string s;
 int n,h;
 while(1){
  cin>>s;
  if(s=="-") break;
  cin>>n;
  FOR(i,n){
   cin>>h;
   s=s.substr(h,s.length()-h)+s.substr(0,h);
  }
  cout<<s<<endl;
 }
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 1216
import math
import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,s = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    mod = 998244353
    ans = 0
    dp = np.zeros(s+1,dtype=int)
    for j in range(n):
        dp[0] += 1
        aj = a[j]
        ndp = dp*1
        if s >= aj:
            dp[s-aj] *= (n-j)
        ndp[aj:] += dp[:-aj]
        ndp %= mod
        dp = ndp
    print(dp[s])
    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 14456
S=list(input())
T=list(input())

a={}
b={}

for i in range(len(S)):
  if S[i] in a:
    a[S[i]].append(i)
  else:
    a[S[i]]=[i]
  if T[i] in b:
    b[T[i]].append(i)
  else:
    b[T[i]]=[i]

if sorted(a.values())==sorted(b.values()):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 16944
#include<bits/stdc++.h>
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;


const int maxn = 3000;
int dp[2][maxn][maxn],a[maxn];
int n,sum=0;

int solve(int I,int l,int r)
{
	if( l > r )return 0;
	if( dp[I][l][r] != -1 )return dp[I][l][r];
	if( I&1 )dp[I][l][r]=min( - a[l] + solve(I^1,l+1,r) , - a[r] + solve(I^1,l,r-1) );
	else dp[I][l][r]=max( a[l] + solve(I^1,l+1,r) , a[r] + solve(I^1,l,r-1) );
	return dp[I][l][r];
	
}
int32_t main()
{
	IOS
	memset(dp,-1,sizeof(dp));
	
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>a[i],sum+=a[i];
	
	cout << solve(0,0,n-1) << endl;
	
	
	
	
}


Measured memory_bytes: 141056
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let s = scan!();

    let mut inputs = vec![];
    for c in s.chars() {
        if c == 'B' {
            inputs.pop();
        } else {
            inputs.push(c);
        }
    }
    println!("{}", inputs.into_iter().collect::<String>())
}


Measured memory_bytes: 4352
#include<stdio.h>
 
main(){
 
	char c[3];
  	int i,count=0;
  	for(i=0;i<3;i++){
      	scanf("%c",&c[i]);
      	if(c[i]=='1'){
        	count ++;
        }
    }
  printf("%d",count);
 
}

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

int main(){
	char c;
	cin >> c;
	if( c=='a' || c=='e' || c=='i' || c=='o' || c=='u' ){
		cout << "vowel" << endl;
	}
	else{
		cout << "consonant" << endl;
	}

}


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

#define dump(...) cout<<'L'<<__LINE__<<": "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	os<<'(';
	print_tuple<Args...>(os,t);
	return os<<')';
}

struct Die{
	array<int,6> faces;
	Die(){
		faces[0]=2; faces[1]=5;
		faces[2]=3; faces[3]=4;
		faces[4]=1; faces[5]=6;
	}
	void Rotate(int a,int b,int c,int d){
		swap(faces[a],faces[b]);
		swap(faces[b],faces[c]);
		swap(faces[c],faces[d]);
	}
	void TurnU(){Rotate(4,0,5,1);}
	void TurnD(){Rotate(4,1,5,0);}
	void TurnL(){Rotate(4,2,5,3);}
	void TurnR(){Rotate(4,3,5,2);}
};
bool operator<(const Die& a,const Die& b){
	return lexicographical_compare(begin(a.faces),end(a.faces),begin(b.faces),end(b.faces));
}
bool operator>(const Die& a,const Die& b){
	return lexicographical_compare(begin(b.faces),end(b.faces),begin(a.faces),end(a.faces));
}

template<typename Functor>
struct functor_traits{
	template<typename C,typename Ret,typename Arg,typename... Args>
	static Arg helper(Ret(C::*)(Arg,Args...));
	template<typename C,typename Ret,typename Arg,typename... Args>
	static Arg helper(Ret(C::*)(Arg,Args...)const);
	typedef decltype(helper(&Functor::operator())) first_argument_type;
};
template<typename Compare,typename T=typename functor_traits<Compare>::first_argument_type>
priority_queue<T,vector<T>,Compare> make_priority_queue(Compare comp){
	return priority_queue<T,vector<T>,Compare>(move(comp));
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vector<vector<int>> grid(h,vector<int>(w));
		for(int i=0;i<h;i++)
			for(int j=0;j<w;j++)
				cin>>grid[i][j];
		int si,sj,gi,gj; cin>>si>>sj>>gi>>gj;
		
		auto pq=make_priority_queue([](tuple<Die,int,int,int> a,tuple<Die,int,int,int> b){
			return get<3>(a)>get<3>(b);
		});
		pq.emplace(Die(),si,sj,0);
		set<tuple<Die,int,int>> vis;
		while(pq.size()){
			Die d; int i,j,c; tie(d,i,j,c)=pq.top(); pq.pop();
			if(vis.count(make_tuple(d,i,j))) continue;
			vis.insert(make_tuple(d,i,j));
			if(i==gi && j==gj){
				cout<<c<<endl;
				break;
			}
			function<void(Die&)> turns[]={&Die::TurnU,&Die::TurnD,&Die::TurnL,&Die::TurnR};
			for(int k=0;k<4;k++){
				int ni=i+"\xff\x1\0\0"[k],nj=j+"\0\0\xff\x1"[k];
				if(0<=ni && ni<h && 0<=nj && nj<w){
					Die t=d;
					turns[k](t);
					pq.emplace(t,ni,nj,c+t.faces[5]*grid[ni][nj]);
				}
			}
		}
	}
}

Measured memory_bytes: 1356
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const ll INF = 1<<30;
const ll MOD = (ll)1e9 + 7;
const ll MAX_N = (ll)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(ll i = 0; i < (ll) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    ll n, k; cin >> n >> k;
    vector<ll> v(32, 1LL);
    ll p = 1LL;
    for(int i = 1; i < v.size(); i++)
    {
        p *= k;
        v[i] = p;
    }
    for(int i = 0; i < v.size(); i++)
    {
        if(v[i] > n)
        {
            if(i == 0) cout << 1 << endl;
            else
            {
                cout << i << endl;
            }
            return;
        }
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

int main(){
  long long int A,B,K;
  cin >> A >> B >>K;
  if(A>=K){
    cout << A-K << ' ' << B << endl;
    return 0;
  }
  if(A<K && K-A<=B){
    cout << 0 << ' ' <<  B-K+A << endl;
    return 0;
  }
  if(B<K-A){
    cout << 0 << ' ' << 0 << endl;
    return 0;
  }
}



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

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    int P = 0;
    for(int i = 0; i <= N; i++){
        if(i == 0){
            P = P + abs(A[i]);
        }else if(i == N){
            P = P + abs(A[i-1]);
        }else{
            P = P + abs(A[i-1] - A[i]);
        }
    }

    for(int i = 0; i < N; i++){
        if(i == 0){
            cout << P - abs(A[i]) - abs(A[i+1] - A[i]) + abs(A[i+1]) << endl;
        }else if(i == N-1){
            cout << P - abs(A[i]) - abs(A[i] - A[i-1]) + abs(A[i-1]) << endl;
        }else{
            cout << P - abs(A[i-1] - A[i]) - abs(A[i] - A[i+1]) + abs(A[i-1] - A[i+1]) << endl;
        }
    }


    return 0;
}

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


//This code is written by Sneh Thakkar.

/*       AUTHOR NAME:

        _/_/_/_/   _/\        _/     _/_/_/_/_/    _/      _/
       _/         _/ _\      _/     _/            _/      _/
      _/_/_/_/   _/   _\    _/     _/_/_/_/_/    _/_/_/_/_/
           _/   _/     _\  _/     _/            _/      _/
    _/_/_/_/   _/       _\_/     _/_/_/_/_/    _/      _/
       
        
*/

using namespace std;

#define ll long long
#define ld double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007

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

int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    map<string,ll>mp;
    ll n;
    cin>>n;
    if(n%1000==0)
    cout<<0<<endl;
    else
    cout<<(n/1000+1)*1000-n;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {

		int x = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		System.out.println( solve(x,a,b) );
	}
	
	int solve(int x,int a,int b){
		return (x-a)%b;
	}
}


Measured memory_bytes: 23636
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;

int main() {
	string s;
	cin >> s;
	ll count = 0,size=s.size();
	for (ll i = 0;i< size / 2; i++) {
		if (s[i] != s[size - i - 1])count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
# coding=utf-8

def main():
    while True:
        line = raw_input()
        if line == '-1 -1 -1':
            break
        middle, final, re = map(int, line.split())
        if middle == -1 or final == -1:
            grade = 'F'
        elif middle + final >= 80:
            grade = 'A'
        elif 65 <= middle + final < 80:
            grade = 'B'
        elif 50 <= middle + final < 65:
            grade = 'C'
        elif 30 <= middle + final < 50:
            if 50 <= re:
                grade = 'C'
            else:
                grade = 'D'
        elif middle + final < 30:
            grade = 'F'
        print grade

if __name__ == '__main__':
    main()

Measured memory_bytes: 4232
#include<stdio.h>
#define N 500000

int b,a[N];

void maxHeapify(int i){
  int c;
  int l = 2 * i;
  int r = 2 * i + 1;
  int max=0;
  if(l <= b && a[l] > a[i]){
    max = l;
  }
  else {
    max = i;
  }

  if(r <= b && a[r] > a[max]){
    max = r;
  }

  if(max != i){
    c = a[i];
    a[i] = a[max];
    a[max] = c;
    maxHeapify(max);
  }
}

  main(){
    int i;

    scanf("%d",&b);
    for(i=1;i<=b;i++){
      scanf("%d",&a[i]);
    }
    for(i=b/2;i>=1;i--){
      maxHeapify(i);
    }
    for(i=1;i<=b;i++){
      printf(" %d",a[i]);
    }
    printf("\n");
    return 0;
  }

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


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


int main() {
	ll a, b;
	cin >> a >> b;
	if (a < b)cout << 0 << endl;
	else cout << 10 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fst first
#define snd second
const ll mod = 1000000007;
const ll INF = (1LL << 59);
const double dINF = 1000000000000000000.0;

struct Bar {
	ll x, y, r;
};

Bar p[1010];

int main(){
	cin >> p[0].x >> p[0].y >> p[1].x >> p[1].y;
	p[0].r = p[1].r = 0;

	double d[1010];
	bool used[1010];
	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i + 2].x >> p[i + 2].y >> p[i+2].r;
	}
	n += 2;
	for (int i = 1; i < n; i++) {
		d[i] = dINF;
		used[i] = false;
	}
	d[0] = 0.0; used[0] = false;
	while (1) {
		double min_=dINF;
		for (int i = 0; i < n; i++) {
			if (used[i])continue;
			min_ = min(min_, d[i]);
		}
		if (min_ == dINF)break;
		for (int i = 0; i < n; i++) {
			if (d[i] == min_) {
				for (int j = 0; j < n; j++) {
					if (used[j])continue;
					d[j] = min(d[j], d[i] + max(0.0, sqrt((p[i].x - p[j].x)*(p[i].x - p[j].x) + (p[i].y - p[j].y)*(p[i].y - p[j].y)) - p[i].r - p[j].r));
				}
				used[i] = true;
			}
		}
	}
	printf("%.15lf\n", d[1]);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int x;cin>>x;
    if(x==0)cout<<1<<endl;
    else cout<<0<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>
#include<complex>

using namespace std;

#define fr first
#define sc second

const int di[] = {-1,-1,0,1,1,1,0,-1};
const int dj[] = {0,1,1,1,0,-1,-1,-1};

typedef pair<int,int> pi;
typedef pair< pi, pi > ppi;
typedef double elem;
typedef complex<elem> point;

elem cross(point a, point b){
  return a.real() * b.imag() - a.imag() * b.real();
}

class State
{
public:
  int dir;
  int i,j;  
  State():i(0),j(0){}
  State(int d, int i, int j):dir(d),i(i),j(j){}
};

void bfs(int M[][84], const State &init, vector<point> &bends){
  queue<State> qs;
  qs.push(init);
  bends.push_back( point(init.j,init.i) );
  int n = 0;
  while(!qs.empty()){
    State now = qs.front();
    qs.pop();
    //cout << now.i << ' ' << now.j << endl;
    M[now.i][now.j] = 0;
    for(int i = now.dir; i < 8+now.dir; ++i){
      int t = i%8;
      if( M[now.i+di[t]][now.j+dj[t]] == 1 ){
	State next( t, now.i+di[t], now.j+dj[t] );
	qs.push( next );
	if( t != now.dir && n > 0 ){
	  bends.push_back( point( now.j, now.i ) );
	}
	break;
      }
    }
    ++n;
  }
}

elem area(const vector<point> &v)
{
  elem ret = 0;
  int n = v.size();
  for(int i = 0; i < v.size(); ++i){
    ret += cross( v[i], v[(i+1)%n] );
  }
  return ret/2.0;
}

int main()
{
  int tc = 0;
  while(true){
    int M[1003][84]={{0,},};
    string s;
    map<int,int> ans;
    int h;
    cin >> h;
    if( h == 0 )break;
    getline(cin,s);
    if( tc > 0 )
      cout << "----------" << endl;
    ++tc;
    for(int i = 0; i < h; ++i){
      getline(cin,s);
      for(int j = 0; j < s.length(); ++j){
	M[i+1][j+1] = (s[j] == '*' ? 1 : 0);
      }
    }
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < 82; ++j){
	if( M[i+1][j+1] == 1 ){
	  vector<point> bends;
	  bfs( M, State(2,i+1,j+1), bends );
	  for(int k = 0; k < bends.size(); ++k){
	    if( k == 1 )
	      bends[k] = bends[k] + point(1,0);
	    if( k == 2 )
	      bends[k] = bends[k] + point(1,1);
	    if( k == 3 ){
	      bends[k] = bends[k] + point(0,1);
	    }
	    //cout << bends[k] << ' ';
	  }
	  int A = (int)area(bends);
	  ans[A ]++;
	}
      }
    }
    for(map<int,int>::iterator itm = ans.begin();
	itm != ans.end();
	++itm)
      {
	cout << itm->first << ' ' << itm->second << endl;
      }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <unordered_map> 

using namespace std;

std::unordered_map<long long,long long> c;

void decompositPrime(long long n)
{
    long long a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            n /= a;
            // cout << a << " * ";
            c[a] += 1;
        } else {
            a++;
        }
    }
    // cout << n << endl;
    c[n]++;
}

int main(void) {
    long long n;
    long long p;
    long long ans=1;
    cin >> n;  cin >> p;
    decompositPrime(p);
    
    for (auto itr = c.begin(); itr != c.end(); itr++) {
        // cout << itr->first << " -> " << itr->second << endl;
        while( itr->second >= n ) {
            itr->second -= n;
            ans *= itr->first;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#! /usr/bin/env python3

N = int(input())
A = list(map(int, input().split()))
t4 = 0
t2 = 0
for i in A:
    if i % 4 == 0:
        t4 += 1
    elif i % 2 == 0:
        t2 += 1
print(['No', 'Yes'][N//2<=(t4 + t2//2)])

Measured memory_bytes: 14252
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<pii>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define clr(x, y) memset(x,y,sizeof(x));
#define IO ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define all(x) x.begin(),x.end()
#define rep(i, m, n) for(int i=m ; i<n ; i++)
#define forr(i, m, n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define re return
const int N = 1e5 + 5;
const ll mod = 1e9 + 7;
using namespace std;
bool vis[N];
vector<vi > graph;

int main() {
    IO;
    int n, m;
    cin >> n >> m;
    graph.resize(n + 2);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        graph[x].pb(y);
        graph[y].pb(x);
    }


    queue<int> qu;
    qu.push(1);
    vis[1] = 1;
    vector<int> ans(n + 1, 0);

    while (!qu.empty()) {
        int siz = qu.size();
        for (int i = 0; i < siz; i++) {
            int v = qu.front();
            qu.pop();

            for (auto u : graph[v]) {
                if (vis[u] == 0) {
                    ans[u] = v;
                    vis[u] = 1;
                    qu.push(u);
                }
            }
        }
    }

    for (int i = 1; i <= n; i++) {
        if (vis[i] == 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    for (int i = 2; i <= n; i++) {
        cout << ans[i] << endl;
    }


}


Measured memory_bytes: 10272
def main():
    n,k=map(int,input().split())
    h=list(map(int,input().split()))
    dp=[10**5]*n
    dp[0]=0
    for i in range(1,n):
        dp[i]=min(dp[j]+abs(h[j]-h[i]) for j in range(max(0,i-k),i))
    print(dp[n-1])
    
main()


Measured memory_bytes: 13980
#include <stdio.h>
int num[50];

swap(int a,int b){
    int tmp;
    tmp=num[a];
    num[a]=num[b];
    num[b]=tmp;
}

int main(){

  int w,n,a,b,i;

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

  for(i=1;i<=w;i++){
    num[i]=i;
  }
  for(i=1;i<=n;i++){
    scanf("%d,%d",&a,&b);
    swap(a,b);
  }
  for(i=1;i<=w;i++){
    printf("%d\n",num[i]);
  }
  return 0;
}


Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, b, c, d, e, k; cin >> a >> b >> c >> d >> e >> k;

  if (e - a <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  return 0;
}


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

int main() {
  // ここにプログラムを追記
  int A,B,count=0;
  cin >> A >> B;
  
  int x1,x2,x4,x5,j,i;
  for(int j=A ; j<=B ;j++){
    i=j;
    
    x1=i%10;
    i=i/10;
    
    x2=i%10;
    i=i/100;
    
    x4=i%10;
    i=i/10;
    
    x5=i%10;
    i=i/10;
    
    if(x1==x5 && x2==x4){
      count++;
      //cout << j << endl;
    }
    //cout << i << endl;
  }
  cout << count << endl;
  
}

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

int main() {
 int n,m,x;
 cin>>n>>m>>x;
 int a[n];
 for(int i=0;i<n;i++) a[i]=0;
 for(int i=0;i<m;i++){
   int t;
   cin>>t;
   a[t-1] ++;
 }
 int c0=0,cn=0;
 for(int i=x-1;i>=0;i--){
   c0 += a[i];
 }
 for(int i=x-1;i<n;i++){
   cn += a[i];
 }
 // cout<<c0<<" "<<cn<<endl;
 cout<<min(c0,cn)<<endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<bitset>
#include<algorithm>
#include<climits>
#include<vector>
#include<deque>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> P;
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define dump(a) rep(i,a.size()){ cout<<a[i]<<" "; } cout<<endl;
#define dumparr(a,n) rep(i,n){ cout<<a[i]<<" "; } cout<<endl;
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define INF INT_MAX/3
#define FINF DBL_MAX/3
#define EPS 1e-7

/*
 *
 */

int main(){
  ll x1,y1,x2,y2;
  cin>>x1>>y1>>x2>>y2;
  ll x3,y3,x4,y4;

  x3 = x2 - y2 + y1;
  y3 = y2 + x2 - x1;

  x4 = x3 - y3 + y2;
  y4 = y3 + x3 - x2;

  cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

signed main(){
	ll a,b,c,k;cin>>a>>b>>c>>k;
	if(k%2==1){
		cout<<b-a<<endl;
	}
	else{
		cout<<a-b<<endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector> 
#include<cstring>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> list[maxn];
int vis[maxn];
int lose=0;
void bfs(int ne,int be,int re)
{
	if(!lose)
	{
		if(vis[ne]==-1)
			vis[ne]=re;
		else
			if(vis[ne]!=re)
			{
				lose=1;
				return;
			}
			else
				return;
		for(int i=0;i<list[ne].size();i++)
		{
			if(list[ne][i]!=be)
				bfs(list[ne][i],ne,!re);	
		}
	
	}
	
}
int main()
{
	long long m,n;
	cin>>m>>n;
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		list[x].push_back(y);
		list[y].push_back(x);
	}
	memset(vis,-1,sizeof(vis));
	bfs(1,0,1);
	long long q=0,p=0;
	for(int i=1;i<=m;i++)
	{
		if(vis[i]==1)
			q++;
		else
			p++;
	}
	if(lose)
		cout<<m*(m-1)/2-n<<endl;
	else
		cout<<q*p-n<<endl;
	
	return 0;
}

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

const int mod = 2019;

int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  ll num = 0;
  ll p = 1;
  map<ll, ll> md;
  md[0]++;
  ll count = 0;
  for(auto x:s) {
    num = num + (x - '0') * p;
    num = num % mod;
    p = p * 10 % mod;
    ++md[num];
    // cout << num << endl;
  }

  for(auto m: md) {
    // cout << m.first << endl;
    count += m.second * (m.second - 1) /2;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 3772
//| #######################|
//|  ADARSH SINGH KUSHWAHA |
//| ###################### | 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Bahut_tej ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define fr(i,a,b) for(ll i=a;i<b;i++)
#define frb(i, a, b) for(ll i = a - 1; i >= b; i--)
#define pb push_back
#define ff first
#define ss second
#define mp map<ll,ll>
#define v vector<ll>
#define srt(v) sort(v.begin(),v.end())
#define mod 1000000007 
#define max 1000001
bool prime[max];
void seive(){
    memset(prime,true,sizeof(prime));
    prime[0]=false;
    prime[1]=false;
    for(int i=2;i*i<=max;i++){
        if(prime[i]){
            for(int j=i*i;j<=max;j+=i){
                prime[j]=false;
            }
        }
    }
}
void solve(){
    string s;
    cin>>s;
    ll n=s.size();
    ll sum=0;
    for(ll i=0;i<n;i++){
        sum+=(s[i]-'0');
    }
    if(sum%9==0){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}
int main() {
    Bahut_tej;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif  
        //int t;
        //cin>>t;
        //while(t--){
            solve();
        //}
        return 0;
    }


Measured memory_bytes: 3716
def dot(u,v):
    return(u[0]*v[0] + u[1]*v[1])

def solve(v):
    eps = 1e-10
    xa,ya,xb,yb,xc,yc,xd,yd = v
    if abs(dot( (xb-xa, yb-ya), (xd-xc, yd-yc)) ) < eps:
        return(True)
    else:
        return(False)

while True:
    try:
        v = map(float, input().strip().split())
        if solve(v):
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

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

using ll=long long;

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

    vector<ll> a(2*n),b(2*n);
    for(int i=0;i<2*n;i++) cin>>a[i];
    for(int i=0;i<2*n;i++) cin>>b[i];
    
    ll psum=0;
    ll bsum=0;
    multiset<ll> ps;
    multiset<ll> ns;
    for(int i=1;i<2*n-1;i++){
        bsum+=b[i];
        if(a[i]-b[i]>=0){
            ps.insert(a[i]-b[i]);
            psum+=a[i]-b[i];
        }
        else ns.insert(a[i]-b[i]);
    }
    
    while(q--){
        int p;
        ll ax,bx;
        cin>>p>>ax>>bx;
        p--;
        if(p==0 || p==2*n-1){
            a[p]=ax;
            b[p]=bx;
        }
        else{
            bsum+=bx-b[p];
            if(a[p]-b[p]>=0){
                ps.erase(ps.find(a[p]-b[p]));
                psum-=a[p]-b[p];
            }
            else{
                ns.erase(ns.find(a[p]-b[p]));
            }
            a[p]=ax,b[p]=bx;
            if(a[p]-b[p]>=0){
                ps.insert(a[p]-b[p]);
                psum+=a[p]-b[p];
            }
            else ns.insert(a[p]-b[p]);
        }
        if(n==1){
            cout<<a[0]+a[1]<<endl;
        }
        else if(ns.size()%2){
            ll vp=*ps.begin();
            ll vn=*(--ns.end());
            cout<<a[0]+a[2*n-1]+bsum+psum+max(-vp,vn)<<endl;
        }   
        else{
            cout<<a[0]+a[2*n-1]+psum+bsum<<endl;
        }                 
    }


    return 0;
}

Measured memory_bytes: 14208
#include <stdio.h>

int check(int *b, int n)
{
    int i;

#if 0
    printf("[");
    for (i = 0; i < n; i++){
        printf("%d ", b[i]);
    }
    printf("]\n");
#endif    
    for (i = 0; i < n; i++){
        if (b[i] != i + 1){
            return (0);
        }
    }
    return (1);
}

int main(void)
{
    int N, n;
    int block[10000];
    int cnt;
    int i, j;
    
    while (1){
        scanf("%d", &N);
        if (N == 0){
            break;
        }

        
        for (i = 0; i < N; i++){
            scanf("%d", &block[i]);
        }
        
        cnt = 0;
        n = N;
        block[n] = 0;
        while (1){
            if (check(block, n) == 1){
                printf("%d\n", cnt);
                break;
            }
            cnt++;
            if (cnt > 10000){
                printf("-1\n");
                break;
            }
            for (n = 0; block[n] != 0; n++);
            block[n] = n;
            block[n + 1] = 0;
            for (i = 0; i < n; i++){
                block[i]--;
            }
            
            for (i = j = 0; i <= n; i++){
                if (block[i] != 0){
                    block[j] = block[i];
                    j++;
                }
            }
            block[j] = 0;
            n = j;
//            for (; j <= n; j++){
//                block[j] = 0;
//            }

        }
    }
    return (0);
}

        
        

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

vector<vector<int>> G;
vector<int> preorder;
vector<int> low;
using P = pair<int,int>;

void lowlink(int v,int prev, int &pre, vector<P>& ans){
  preorder[v]=pre;
  low[v]=pre;
  for(auto to:G[v]){
    if(preorder[to]==-1){
      lowlink(to,v,++pre,ans);
      if(low[to]==preorder[to]){
        ans.emplace_back(min(v,to),max(v,to));
      }
      low[v]=min(low[v],low[to]);
    }else if(to!=prev){
      low[v]=min(low[v],preorder[to]);
    }
  }
}

int main(){
  int V,E;
  cin>>V>>E;
  G.resize(V);
  preorder.resize(V,-1);
  low.resize(V);

  for(int i=0;i<E;i++){
    int s,t;
    cin>>s>>t;
    s--;t--;
    G[s].push_back(t);
    G[t].push_back(s);
  }
  int p=1;
  vector<P> ans;
  lowlink(0,-1,p,ans);
  cout<<ans.size()<<endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Long x = scanner.nextLong();
        Long y = scanner.nextLong();
        Long z = scanner.nextLong();

        Long rest_of_takahshi_cokie = x - z;
        Long rest_of_aoki_cokie = rest_of_takahshi_cokie + y;

        if(rest_of_takahshi_cokie > 0) {
            System.out.println(rest_of_takahshi_cokie + " " + y);
        } else {
            if (rest_of_aoki_cokie < 0) {
                System.out.println(0 + " " + 0);
            } else{
                System.out.println(0 + " " + rest_of_aoki_cokie);
            }
        }
    }
}

Measured memory_bytes: 21844
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>

int main(void){

    int N;
    long long x;

    scanf("%d%lld", &N, &x);

    long long a[N];

    for(int i = 0; i < N; i++){
        scanf("%lld", &a[i]);
    }

    long long ans = 0;

    for(int i = 1; i < N; i++){
        if(a[i-1] + a[i] > x){
            ans += a[i-1] + a[i] - x;
            if(a[i-1] <= x){
                a[i] = x - a[i-1];
            }else{
                a[i] = 0;
                a[i-1] = x;
            }
        }
    }

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

    return 0;
}

Measured memory_bytes: 2512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _0000
{
    class Program
    {
        static void Main(string[] args)
        {
            // 1x1=1から9x9=81までの九九を出力して終了するプログラム

            for (int i = 0; i < 9; i++) 
            {
                for (int j = 0; j < 9; j++)
                {
                    Console.WriteLine((i + 1).ToString() + "x" + (j + 1).ToString() + "=" + ((i + 1) * (j + 1)));
                }
            }
        }
    }
}



Measured memory_bytes: 15756
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
	string s;
	int n;
	cin >> n >> s;
	int d[26] = {0};
	rep(i, 0, s.size()){
		if(s[i] != '+') d[s[i] - 'a']++;
	}
	int cnt = 0;
	int d2[10] = {0};
	rep(i, 0, 26){
		if(d[i]){
			cnt++;
			d2[d[i]]++;
		}
	}
	int ans = cnt - 1 + d2[1];
	rep(i, 2, 10){
		ans += min(3 * d2[i], 4 + d2[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3196
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

count = 0
x = 0  # 持ち越しキャパシティ
for i in range(N):
    a = A[i]
    b = B[i]
    # print(a, b)
    if x < a:  # 持ち越し分では足りない
        count += x
        a = a - x  # a: 残りの敵

        if a <= b:  # 全部倒せる
            count += a
            # 持ち越し分の計算
            x = b - a
        else:
            count += b
            x = 0
    else:  # 持ち越し分でモンスター全部倒した
        count += a
        x = b
    # print(count)

# print('x:', x)
# count += min(x, A[N])
if A[N] >= x:
    count += x
else:
    count += A[N]
print(count)


Measured memory_bytes: 19156
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
double a,b,c,d,e,f;
double x,y;
while(cin >> a >> b >> c >> d >> e >> f){
  x = (double)((e*c-b*f) / (a*e-b*d));
  y = (double)((-(d*c)+a*f) / (a*e-b*d));
  if(x == 0){x = 0;}
  if(y == 0){y = 0;}
  printf("%.3f %.3f\n",x,y);
 }
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define rmin(r, x) r = min(r, x)
#define rmax(r, x) r = max(r, x)
#define ends ' '
#define endl '\n'
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main(void) {
    fastio;
    ll n;  cin >> n;
    --n;
    ll ans = 0;
    for(int a = 1; a <= n; ++a) {
        ans += n / a;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3644
def solve(N,a):
    suma = 0
    SUM = sum(a)
    MIN = 10**15
    for i in a[:(N-1)]:
        suma+=i
        MIN = min(MIN,abs(2*suma-SUM))
    return abs(MIN)

if __name__ == "__main__":
    N = int(input())
    a = list(map(int,input().split()))
    print(solve(N,a))

Measured memory_bytes: 24816