akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

vector<int> num;

long long sequence(int s) {
  long long sum = s;
  long long res = 0;
  
  for (int i = 1; i < num.size(); i++) {
    if (sum > 0) {
      if (sum + num[i] >= 0) {
        res += 1 + num[i] + sum;
        sum = -1;
      } else {
        sum += num[i];
      }
    } else {
      if (sum + num[i] <= 0) {
        res += 1 - num[i] - sum;
        sum = 1;
      } else {
        sum += num[i];
      }
    }
  }
  
  return res;
}

int main() {
  int n; cin >> n;
  
  num.resize(n);
  for (int i = 0; i < n; i++) cin >> num[i];
  
  long long ans1;
  long long ans2;
  
  if (num[0] == 0) {
    ans1 = sequence(1) + 1;
    ans2 = sequence(-1) + 1;
  } else if (num[0] > 0) {
    ans1 = sequence(num[0]);
    ans2 = sequence(-1) + num[0] + 1;
  } else {
    ans1 = sequence(1) + abs(num[0]) + 1;
    ans2 = sequence(num[0]);
  }
  
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 640
n = int(input())
s = []
for i in range(n):
    s.append(input())
m = int(input())
t = []
for i in range(m):
    t.append(input())
ans = []
for _ in s:
    ans.append(s.count(_)-t.count(_))
if max(ans) >= 0:
    print(max(ans))
else:
    print(0)


Measured memory_bytes: 3060
orders = {
    'North': (2, 6, 3, 4, 1, 5),
    'East': (4, 2, 1, 6, 5, 3),
    'West': (3, 2, 6, 1, 5, 4),
    'South': (5, 1, 3, 4, 6, 2),
    'Right': (1, 3, 5, 2, 4, 6),
    'Left': (1, 4, 2, 5, 3, 6)
}

while True:
    n = int(input())
    if not n:
        break
    dice = list(range(1, 7))
    top = 1

    while n:
        dice = [dice[s - 1] for s in orders[input().strip()]]
        top += dice[0]
        n -= 1
    print(top)

Measured memory_bytes: 7728
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	int i,n;
 	string s,t,m;
 	cin>>n;
 	cin>>s>>t;
 	for(i=0;i<2*n;i++)
 	{
 		if(i%2==0)
 			m+=(char)(s[i/2]);
 		else
 			m+=(char)(t[i/2]);
 		
	 }
 	cout<<m<<endl;
 }

Measured memory_bytes: 3636
#include "bits//stdc++.h"
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()

ll mod_pow(ll a, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2);
		return (tmp * tmp) % MOD;
	}
	return (a * mod_pow(a, n - 1)) % MOD;
}

vector<ll> fact;
vector<ll> inv_fact;

void comb_init(int n) {
	fact.resize(n + 1);
	inv_fact.resize(n + 1);
	fact[0] = inv_fact[0] = 1;
	for (int i = 1; i <= n; i++) {
		fact[i] = (fact[i - 1] * i) % MOD;
		inv_fact[i] = (inv_fact[i - 1] * mod_pow(i, MOD - 2)) % MOD;
	}
}

ll comb(int n, int k) {
	if (n < k) return 0;
	ll ret = fact[n];
	(ret *= inv_fact[k]) %= MOD;
	(ret *= inv_fact[n - k]) %= MOD;
	return ret;
}

set<int> G[200000];
set<int> tmp[200000];
vector<int> forest[200000];
vector<int> comp;
int in[200000];
bool vis[200000];
int collect[200000];
ll dp[200000];
int sum[200000];

void dfs(int v) {
	vis[v] = 1;
	comp.push_back(v);
	for (int to : G[v]) {
		if (vis[to]) continue;
		dfs(to);
	}
}
ll calc(int v) {
	sum[v] = 1;
	if (forest[v].size() == 0) return dp[v] = 1;
	for (int child : forest[v]) {
		calc(child);
		sum[v] += sum[child];
	}
	ll ans = 1;
	int rest = sum[v] - 1;
	for (int child : forest[v]) {
		(ans *= comb(rest, sum[child])) %= MOD;
		(ans *= dp[child]) %= MOD;
		rest -= sum[child];
	}
	return dp[v] = ans;
}
int main() {
	int N;
	cin >> N;
	comb_init(2 * N);
	rep(i, 2 * N) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		G[y].insert(x + N);
		G[x + N].insert(y);
		tmp[y].insert(x + N);
		tmp[x + N].insert(y);
	}
	ll ans = 1;
	int tot= 2 * N;
	rep(i, 2 * N) {
		if (vis[i]) continue;
		comp.clear();
		dfs(i);
		int deg = 0;
		for (int v : comp) deg += G[v].size();
		if (comp.size() != deg / 2) {
			cout << 0 << endl;
			return 0;
		}
		queue<int> leaf;
		for (int v : comp) if (tmp[v].size() == 1) leaf.push(v);
		while (!leaf.empty()) {
			int x = leaf.front(); leaf.pop();
			int y = *tmp[x].begin();
			collect[x] = y;
			tmp[x].erase(y);
			tmp[y].erase(x);
			if (tmp[y].size() == 1) leaf.push(y);
		}
		int head = -1;
		for (int v : comp) {
			if (tmp[v].size()) {
				head = v;
				break;
			}
		}
		ll mul = 0;
		for (int to : tmp[head]) {
			collect[head] = to;
			int prev = head;
			int now = to;
			while (now != head) {
				for (int x : tmp[now]) {
					if (x != prev) {
						collect[now] = x;
						prev = now;
						now = x;
						break;
					}
				}
			}
			for (int v : comp) in[v] = 0;
			for (int v : comp) {
				forest[v].clear();
				for (int x : G[v]) {
					if (x < collect[v]) {
						forest[v].push_back(x);
						in[x]++;
					}
				}
			}
			ll t = 1;
			int rest = comp.size();
			for (int v : comp) {
				if (in[v] == 0) {
					calc(v);
					(t *= comb(rest, sum[v])) %= MOD;
					(t *= dp[v]) %= MOD;
					rest -= sum[v];
				}
			}
			(mul += t) %= MOD;
		}
		(ans *= mul) %= MOD;
		(ans *= comb(tot, comp.size())) %= MOD;
		tot -= comp.size();
	}
	cout << ans << endl;
}


Measured memory_bytes: 70648
H,W=map(int,input().split())
a=[]
for i in range(H):
  a.append(list(map(int,input().split())))
#print(a)

ans=[]
N=0
for i in range(H):
  for j in range(W):
    if j<W-1:
      if a[i][j]%2==1:
        a[i][j+1]+=1
        a[i][j]-=1
        ans.append([i+1,j+1,i+1,j+1+1])
        N+=1
    else:
      if a[i][j]%2==1 and i!=H-1:
        a[i+1][j]+=1
        a[i][j]-=1
        ans.append([i+1,j+1,i+1+1,j+1])
        N+=1
    #print(a,N)

print(N)
for i in ans:
  print(" ".join(map(str,i)))

Measured memory_bytes: 29812
import java.util.*;

public class Main {
    
    public static int[][] map;
    public static int[][] move = {{0,1}, {1,0}, {-1,0}, {0,-1}};
    public static int[][] move2 = {{1,1}, {1,-1}, {-1,1}, {-1,-1}};
    public static boolean[][] used;
    public static int dx;
    public static int dy;
    public static int s;
    
    public static void drop(int x, int y, int z) {
        if(!(0<=x && x<10 && 0<=y && y<10)) return;
        if(Math.abs(dx-x) + Math.abs(dy-y) > z) return;
        if(used[x][y]) return;
        
        map[x][y]++;
        used[x][y] = true;
        for(int k=0; k<4; k++) {
            drop(x + move[k][0], y + move[k][1], z);
        }
    }
    
    public static void main(String[] args) {
        try(Scanner sc = new Scanner(System.in)) {
            map = new int[10][10];
            while(sc.hasNext()) {
                String[] str = sc.next().split(",");
                dx = Integer.parseInt(str[0]);
                dy = Integer.parseInt(str[1]);
                s = Integer.parseInt(str[2]);
                used = new boolean[10][10];
                drop(dx, dy, (s == 3 ? 2:1));
                if(s == 2) {
                    for(int k=0; k<4; k++) {
                        int x = dx + move2[k][0];
                        int y = dy + move2[k][1];
                        if(0<=x && x<10 && 0<=y && y<10) map[x][y]++;
                    }
                }
            }
            int cnt = 0;
            int max = 0;
            for(int x=0; x<10; x++) {
                for(int y=0; y<10; y++) {
                    if(map[x][y] == 0) cnt++;
                    max = Math.max(max, map[x][y]);
                }
            }
            System.out.println(cnt);
            System.out.println(max);
        }
    }
}



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

using namespace std;

int main(void){
	int n;
	string str;
	cin >> n;
	cin.get();
	for(int i = 0;i < n;i++){
		getline(cin,str);
		while(str.find("Hoshino") != string::npos){
			int lc = str.find("Hoshino");
			lc += 6;
			str[lc] = 'a';
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    if(N==3||N==5||N==7){
        cout1("YES");
    }else{
        cout1("NO");
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MAX=100005;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,n){cout<<arr[i][j]<<" ";}cout<<endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,x,y;
    cin>>h>>w>>x>>y;
    ll ans=h*w+x*y-h*y-w*x;
    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 256
s = list(str(input()))
n = len(s)

dl = {'A':0, 'C':0, '?':0}
dr = {'A':0, 'C':0, '?':0}

dls = []
drs = []

import copy

for i in range(n):
    if s[i] == 'A' or s[i] == 'C':
        dl[s[i]] += 1
    elif s[i] == 'B':
        dl_ = copy.copy(dl)
        dls.append(dl_)
    else:
        dl_ = copy.copy(dl)
        dls.append(dl_)
        dl[s[i]] += 1
    j = n - 1- i
    if s[j] == 'A' or s[j] == 'C':
        dr[s[j]] += 1
    elif s[j] == 'B':
        dr_ = copy.copy(dr)
        drs.append(dr_)
    else:
        dr_ = copy.copy(dr)
        drs.append(dr_)
        dr[s[j]] += 1

drs = list(reversed(drs))
#print(dls)
#print(drs)

ans = 0
mod = 10**9+7

def power(a, n, mod):
  bi=str(format(n,"b")) #2進数
  res=1
  for i in range(len(bi)):
    res=(res*res) %mod
    if bi[i]=="1":
      res=(res*a) %mod
  return res

for i in range(len(dls)):
    a = (dls[i]['A']*power(3, dls[i]['?'], mod) + dls[i]['?']*power(3, max(0, dls[i]['?']-1), mod))%mod
    b = (drs[i]['C']*power(3, drs[i]['?'], mod) + drs[i]['?']*power(3, max(0, drs[i]['?']-1), mod))%mod
    ans += (a*b)%mod
    #print(ans)
ans %=mod
print(ans)

Measured memory_bytes: 112248
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let read() = Console.ReadLine()
let reads () = Console.ReadLine().Split()
let read2 () = reads() |> (fun x -> x.[0], x.[1])
let read3 () = reads() |> (fun x -> x.[0], x.[1], x.[2])
let read4 () = reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let tmap2 f1 f2 (t1, t2) = (f1 t1, f2 t2)
let tmap3 f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let tmap4 f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)
let readAs f = read() |> f
let readAs2 f1 f2 = read2 () |> tmap2 f1 f2
let readAs3 f1 f2  f3 = read3 () |> tmap3 f1 f2 f3
let readAs4 f1 f2 f3 f4 = read4 () |> tmap4 f1 f2 f3 f4
let readInt () = readAs int
let readInt2 () = readAs2 int int
let readInt3 () = readAs3 int int int
let readInt4 () = readAs4 int int int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"


// The main contents of this submission are below this line.

let x, y, z = readInt3 ()
(x - z) / (y + z) |> puts


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    int Count = 1;
    int D = 0;
    for(int i = 0; i < N; i++){
        D +=L[i];
        if(D > X) break;
        Count++;
    }
    cout << Count << endl;
}


Measured memory_bytes: 256
/*
*
*Problem Link : https://atcoder.jp/contests/dp/tasks/dp_d
*Platform: atcoder
*Status: correct
*Author: Mayukh Chakrabarti
*
*/

#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false)
#define boost cin.tie(NULL)
#define booster cout.tie(NULL)
#define endl "\n"
typedef long long int lld;

#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;

using namespace std;

int main(){
	
	lld N,W;
	cin>>N>>W;
	
	int w[N],p[N];
	
	//Taking inputs of weight and profit of items
	for(lld i=0;i<N;i++)
		cin>>w[i]>>p[i];
	
	lld dp[N+1][W+1];
	
	for(lld i=0; i<=N; i++){
		
		for(lld j=0; j<=W; j++){
			
			if(i==0 || j==0)
				dp[i][j]=0;
			
			else if(w[i-1] <= j )
				dp[i][j]= max(dp[i-1][j] , dp[i-1][j-w[i-1]] + p[i-1] );
				
			else
				dp[i][j]= dp[i-1][j];
			
		}
	}
	
	//PNF(dp,N+1,W+1);
	cout<<dp[N][W];
	
	return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const ll MOD=1e9+7;

int main(){

  int n, m;
  cin >> n >> m;
  if(n > m){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

	return 0;
}

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

typedef long long ll;

int n;
ll p;
string s;

map<int,ll> cnt;

int main(){
	cin >> n >> p;
	cin >> s;
	if(p==2){
		ll ans = 0ll;
		for(int i=s.size()-1;i>=0;i--){
			int cur = s[i] - '0';
			if(cur % 2 == 0){
				ans += (ll)i+1;
			}
		}
		cout << ans << endl;
		return 0;
	} else if(p==5){
		ll ans = 0ll;
		for(int i=s.size()-1;i>=0;i--){
			int cur = s[i] - '0';
			if(cur % 5 == 0){
				ans += (ll)i+1;
			}
		}
		cout << ans << endl;
		return 0;
	}
	ll mult = 1ll;
	ll pref = 0ll;
	cnt[0]++;
	ll ans = 0ll;
	for(int i=s.size()-1;i>=0;i--){
		ll tmp = s[i] -'0';
		tmp *= mult;
		tmp %= p;
		mult*=10ll;
		mult%=p;
		pref += tmp;
		pref%=p;
		ans += cnt[pref];
		cnt[pref]++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1028
#include <stdio.h>
#include<math.h>
 
int main()
{
long long int N,l;
int a[100001]={0};
scanf("%lld",&N);
for(int i=1;i<=sqrt(N);i++)
{
    for(int j=1;j<=sqrt(N);j++)
    {
        for(int k=1;k<=sqrt(N);k++)
        {
            l=i*i+j*j+k*k+i*j+i*k+j*k;
          a[l]++;
        }
    }
}
for(int i=0;i<N;i++)
{
printf("%d\n",a[i+1]);
}
}

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

const int MOD = (int)1e9+7;

int main(){
	int N,K,R,S,P;
	string T;
	cin >> N >> K >> R >> S >> P >> T;

	int ans=0;
	vector<vector<int>> dp(N+1,vector<int>(3,0));
	for(int i=0;i<N;i++){
		int a=0;
		int b=0;
		int c=0;
		if(i-K>=0){
			a=dp.at(i-K).at(0);
			b=dp.at(i-K).at(1);
			c=dp.at(i-K).at(2);
		}
		if(T.at(i)=='r'){
			dp.at(i).at(0)=max(b,c);
			dp.at(i).at(1)=max(a,c);
			dp.at(i).at(2)=max(a+P,b+P);
		}
		if(T.at(i)=='s'){
			dp.at(i).at(0)=max(b+R,c+R);
			dp.at(i).at(1)=max(a,c);
			dp.at(i).at(2)=max(a,b);
		}
		if(T.at(i)=='p'){
			dp.at(i).at(0)=max(b,c);
			dp.at(i).at(1)=max(a+S,c+S);
			dp.at(i).at(2)=max(a,b);
		}
	}
	for(int i=N-1;i>N-1-K;i--){
		ans+=max({dp.at(i).at(0),dp.at(i).at(1),dp.at(i).at(2)});
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 5760
n=io.read("*n")
a={}
for i=1,n do
    x=io.read("*n")
    if not a[x] then
        a[x]=1
    else
        a[x]=a[x]+1
    end
end

max=0
for integer,_ in pairs(a) do
    counter=a[integer]
    if a[integer-1] then
        counter=counter+a[integer-1]
    end
    if a[integer+1] then
        counter=counter+a[integer+1]
    end
    max=math.max(counter,max)
end
print(max)

Measured memory_bytes: 3440
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << endl;
    return 0;
  }
  cout << (h * w + 1) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
using namespace std;

#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll n;
        cin>>n;
        ll a[100005];
        for(int i=1;i<=n;i++)
        	cin>>a[i];
        ll s=0;
        for(int i=1;i<=n;i++)
        {
        	if(i&1)
        		s+=a[i];
        	else
        		s-=a[i];
        }
        ll ans[100005];
        ans[1]=s;
        ans[n]=2*(a[n]-ans[1]/2);
        for(int i=2;i<n;i++)
        {
        	ans[i]=2*(a[i-1]-ans[i-1]/2);
        }
        for(int i=1;i<=n;i++)
        	cout<<ans[i]<<" ";

    }
    return 0;
}

Measured memory_bytes: 2944
using System;
using System.IO;
using System.Linq;

class A
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

		var h = Read();
		var n = h[0];

		var uf = new UF(n);

		for (int i = 0; i < h[1]; i++)
		{
			var q = Read();
			if (q[0] == 0)
				uf.Unite(q[1], q[2]);
			else
				Console.WriteLine(uf.AreUnited(q[1], q[2]) ? 1 : 0);
		}
		Console.Out.Flush();
	}
}

class UF
{
	int[] p;
	public UF(int n) { p = Enumerable.Range(0, n).ToArray(); }

	public void Unite(int a, int b) { if (!AreUnited(a, b)) p[p[b]] = p[a]; }
	public bool AreUnited(int a, int b) => GetRoot(a) == GetRoot(b);
	public int GetRoot(int a) => p[a] == a ? a : p[a] = GetRoot(p[a]);
}


Measured memory_bytes: 41776
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
//		out.println(123);
		// 1 - always
		// 2 - 1 >= 1
		// 3 --> 1 >= 1, 2 >= 3
		// 4 --> 1 >= 1, 2 >= 3, 3 >= 5
		
		// second?
		// 1 - always
		// 2 - always
		// 3 - 2 >= 1
		// 4 - 2 >= 1, 3 >= 3
		// 5 - 2 >= 1, 3 >= 3, 4 >= 5
		
		int n = nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
		}
		
		int ret = 1;
		int cnt = 0;
		
		for (int i = 0; i < n; i++) {
			while (cnt <= i) {
				cnt++;
			}
			while (cnt < n && a[cnt - 1] >= 2 * (cnt - i) - 1) {
				cnt++;
			}
			ret = (int)((long)ret * (cnt - i) % P);
		}
		
		out.println(ret);
	}
	
	static final int P = 1_000_000_007;

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 37704
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね

int main(){
    int n,k;
    cin >> n>> k;
    vector<int> a(n);
    ll sum=0;
    rep(i,n){
        cin >> a[i];
        sum+=a[i];
    }
    set<ll> s;
    for(int i=1;i*i<=sum;i++){
        if(sum%i==0){
            s.insert(i);
            s.insert(sum/i);
        }
    }
    ll ans=1;
    for(ll x:s){
        ll need;
        {
            vector<ll> r(n);
            rep(i,n) r[i]=a[i]%x;
            sort(r.begin(),r.end());
            ll rSum=0;
            rep(i,n)rSum+=x-r[i];//初期化
            ll lSum=0;//初期化
            need=1e18;
            rep(i,n){
                lSum+=r[i];
                rSum-=x-r[i];
                need=min(need,max(lSum,rSum));
            }
        }
        if(need<=k)ans=max(ans,x);
    }
    cout<<ans<<endl;
    return 0;
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

struct T {
  int s, n;
};


int main() {
  int m;
  while(cin >> m) {
    if(!m) return 0;
    T card[7] = {};
    rep(i, 0, m) {
      int a, b;
      cin >> a >> b;
      card[i].s = a;
      card[i].n = b;
    }
    int pat[7001] = {};
    rep(i, 0, m) {
      dep(j, 7000, 0) {
        if(pat[j]) {
          rep(k, 1, card[i].n + 1) pat[j + card[i].s * k] += pat[j];
        }
      }
      rep(j, 1, card[i].n + 1) pat[card[i].s * j]++;
    }

    int g;
    cin >> g;
    rep(i, 0, g) {
      int n;
      cin >> n;
      cout << pat[n] << endl;
    }
  }
}

Measured memory_bytes: 3160
#include <iostream>

using namespace std;

int main()
{
    int N, M;

    cin >> N >> M;

    // 偶 + 偶 or 奇 + 奇
    int ansN = N < 2 ? 0 : N * (N - 1) / 2;
    int ansM = M < 2 ? 0 : M * (M - 1) / 2;

    int ans = ansN + ansM;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
	
		
		int p=sc.nextInt();
		int q=sc.nextInt();
		int r=sc.nextInt();
		
		
		System.out.println(Math.min(p+q, Math.min(q+r, r+p)));
	}


}


Measured memory_bytes: 23124
using namespace std;
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#define w(x) int x;cin>>x;while(x--)

#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define ll long long

void abc()
{
	FIO;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
}





int main()
{
	abc();

	int n;
	cin >> n;
	vector<vector<int>> v(n, vector<int>(2));
	for (int i = 0; i < n; i++) {
		cin >> v[i][0] >> v[i][1];
	}

	bool res = false;
	int count = 0;
	for (int i = 0; i < n ; i++) {
		if (v[i][0] == v[i][1]) {
			count++;
		}
		else {
			count = 0;
		}
		if (count == 3) {
			res = true;
			break;
		}
	}

	if (res) cout << "Yes";
	else cout << "No";

}

Measured memory_bytes: 3656
count = 0

while True:
    H, W = map(int, input().split())

    if H + W == 0:
        break

    for hi in range(H):
        if hi == 0 or hi == H - 1:
            print("#"*W)
        else:
            for wi in range(W):
                if wi == 0 or wi == W - 1:
                    print("#", end="")
                else:
                    print(".", end="")
            print()
    print()



Measured memory_bytes: 7004
import math

N = int(input())
x = [0] * N
y = [0] * N
l = 0

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

for i in range(N):
  for j in range(i+1, N):
    l += math.sqrt((x[i] - x[j])**2 + (y[i] - y[j])**2)

n = math.factorial(N)
m = 2 * math.factorial(N-1)
print(l * m / n)

Measured memory_bytes: 3064
#include<cstdio>
typedef long long LL;
using namespace std;
const int N=1e6+5;
int n;
char s[N];
inline bool chk(){
	int u=0,v=0,w=0;
	for(int i=0;i<=n;++i){
		if(u==v)w=(w+s[i])&1;
		if(i<n)u+=__builtin_ctz(n-i),v+=__builtin_ctz(i+1);
	}
	return w;
}
int main(){
	scanf("%d%s",&n,s);
	if(!--n)putchar(*s);else{
		for(int i=0;i<=n;++i)--s[i];
		if(chk())putchar(49);else{
			bool ok=1;
			for(int i=0;i<=n;++i)
			if(s[i]==49)ok=0;else if(s[i]==50)--s[i];
			if(ok&&chk())putchar(50);else putchar(48);
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print1(a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=200005;
//i_am_noob
int a,b,c;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> a >> b >> c;
	if(a>b) swap(a,b);
	print1((c+b-1)/b);
	return 0;
}

Measured memory_bytes: 256
#include "stdio.h"

int main(void)
{
    int a[3], empty;
    scanf("%d%d%d", &a[0], &a[1], &a[2]);

    if (a[0] > a[1])
    {
        empty = a[1];
        a[1] = a[0];
        a[0] = empty;
    }

    if (a[1] > a[2])
    {
        empty = a[2];
        a[2] = a[1];
        a[1] = empty;
    }

    if (a[0] > a[1])
    {
        empty = a[1];
        a[1] = a[0];
        a[0] = empty;
    }

    printf ("%d", a[2] - a[0]);
    return (0);
}


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

int main()
{
        ll N; cin >> N;
        vector<ll> A(N, 0);
        vector<ll> B(N, 0);
        vector<ll> C(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> A[i];
        }
        for (int i = 0; i < N; ++i) {
                cin >> B[i];
        }
        for (int i = 0; i < N; ++i) {
                cin >> C[i];
        }
        sort(A.begin(), A.end());
        sort(B.begin(), B.end());
        sort(C.begin(), C.end());

        ll ans = 0;
        for (int i = 0; i < N; ++i) {
                ll tmp = B[i];
                auto it1 = lower_bound(A.begin(), A.end(), tmp);
                ll tmp1 = it1 - A.begin();
                auto it2 = upper_bound(C.begin(), C.end(), tmp);
                ll tmp2 = C.end() - it2;
                tmp1 *= tmp2;
                ans += tmp1;
        }
        cout << ans << endl;


}


Measured memory_bytes: 2560
#include<algorithm>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<string>
#include<vector>
#define rep0_n(i,n) for(int i=0; i<n; i++)
#define rep1_n(i, n) for(int i=1; i<n+1; i++)
#define reps_n(i, s, n) for(int i=s; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
 double w,h,x,y;
  cin >> w >> h >> x >> y;
  cout << setprecision(7) << w*h/2.0 << " ";
  if( w/2 == x and h/2 == y ){
    cout << 1;
  }else{
    cout << 0;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<random>
#include<map>
#include<queue>
using namespace std;

int main(){

  int n;
  while(cin >> n){
    if( n == 0 ) break;

    vector<int> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int sum = accumulate(a.begin(), a.end(), 0) - *max_element(a.begin(), a.end()) - *min_element(a.begin(), a.end());

    sum /= n-2;
    cout << sum << endl;
  }

  return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
	int h,w,i,ii;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0&&w==0)break;
		for(i=0;i<h;i++){
			for(ii=0;ii<w;ii++){
				if((i%2==0&&ii%2==0)||(i%2!=0&&ii%2!=0)){
					printf("#");
				}
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
/*********ANISH***********ANISH*************ANISH***********ANISH******/
#define pb push_back
#define ll long long
#define ff first
#define ss second
ll max(ll a,ll b)
{
    if(a>b) return a;
    return b;
}
ll min(ll a,ll b)
{
    if(a<b) return a;
    return b;
}
/********ANISH************ANISH*************ANISH**********ANISH*********/
int n,k;
ll h[100010];
ll dp[100010];
ll fun(int pos,int des)
{
    if(pos>des)
        return INT_MAX;
    if(pos==des)
        return 0;
    if(dp[pos]!=-1) return dp[pos];
    ll cost=INT_MAX;
    for(int i=pos+1;i<=min(des,pos+k);++i)
        cost=min(cost,abs(h[i]-h[pos])+fun(i,des));
    return dp[pos]=cost;
}
int main()
{
    int t;
    t=1;
    while(t--)
    {
      cin>>n>>k;
      for(int i=0;i<n;++i) cin>>h[i];
      memset(dp,-1,sizeof(dp));
      cout<<fun(0,n-1);
    }
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
ll cnt[26];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	for(char c: s)
		cnt[c-'a']++;
	ll ans = 1;
	for(int i=0; i<26; i++) {
		ans *= (cnt[i]+1);
		ans %= MOD;
	}
	cout << (ans+MOD-1)%MOD;
}

Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main (void) {
    int n, k;
    cin >> n >> k;
    int v[2 * n];
    rep(i, n) {
        cin >> v[i];
        v[i+n] = v[i];
    }

    int mval = 0;
    rep(num_pop, min(n, k)+1) {
        int num_push = min(n, k - num_pop);
        // cout << num_pop << " " << num_push << endl;
        rep(left, num_pop+1) {
            priority_queue<int> q;
            int val = 0;
            rep(i, num_pop) {
                int x = v[n - left + i];
                val += x;
                q.push(-x);
            }
            rep(i, num_push) {
                if (q.empty()) break;
                if (q.top() < 0) break;
                val += q.top();
                q.pop();
            }
            // cout << "pop" << num_pop << " push" << num_push << " left" << left << " val" << val << endl;
            mval = max(mval, val);
        }
    }

    cout << mval << endl;
    return 0;
}



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

int main(){
	int n, k;
	string s;
	cin >> n >> k >> s;
	
	vector<pair<int, int>> kukaku(n);
	int index = -1, iflag;
	rep(i, n){
		int convert = (s.at(i) - '0');
		if(i == 0 || iflag != convert){
			index++;
			kukaku.at(index).first = convert;
			iflag = convert;
		}
		kukaku.at(index).second++;
	}
	
	
	int ans;
	int temp = 0;
	for(int j = 0, count = 0; j < index+1; j++){
		if(kukaku.at(j).first == 0){
			count++;
			if(count > k) break;
		}
		temp += kukaku.at(j).second;
	}
	ans = temp;
	
	int i1;
	if(kukaku.at(0).first == 0){
		i1 = 0 + k * 2;
	}else{
		i1 = 1 + k * 2;
	}
	for(; i1 < index+1; i1 = i1 + 2){
		temp -= kukaku.at(i1 - k*2).second;
		if(i1-k*2 > 0) temp -= kukaku.at(i1-k*2-1).second;
		temp += kukaku.at(i1).second;
		if(i1 < index) temp += kukaku.at(i1+1).second;
		ans = max(ans, temp);
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1280
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,x,y;
    cin>>n>>x>>y;
    x--,y--;
    vi d(n);
    rep(i,n-1){
        Rep(j,i+1,n){
            int a=min({j-i,abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)});
            d[a]++;
        }
    }
    Rep(i,1,n)cout<<d[i]<<endl;
}

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

#define endl '\n'
#define ll long long
#define re register
#define pb(x) push_back(x)
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
const db pi = acos(-1);
const long long infl = LLONG_MAX;

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

bool comp(pll a,pll b){
	if((a.ff*1.0)/a.ss==(b.ff*1.0)/b.ss){
		return a.ff>b.ff;
	}
	return (a.ff*1.0)/a.ss>(b.ff*1.0)/b.ss;
}

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

ll t,i,x,j,y,z=0,k,n,ii;

cin>>k>>n;	
ll dp[10001];

rep(i,0,10001,1){
	dp[i]=infl;
}
rep(i,0,n,1){
	cin>>x>>y;
	rep(j,0,min(10001LL,x+1),1){
		dp[j]=min(dp[j],y);
	}
	rep(j,x,10001,1){
		dp[j]=min(dp[j],y+dp[j-x]);
	}
}

ce(dp[k])
}
//139815


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

typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

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

    int sn = n/10000000000 + (n/1000000000)%10 +
      (n/100000000)%10 + (n/10000000)%10 + 
      (n/1000000)%10 + (n/100000)%10 +  (n/10000)%10 +
      (n/1000)%10 +  (n/100)%10 +  (n/10)%10 +  (n)%10;
    
    if(n%sn == 0) cout << "Yes";
    else cout <<"No";
}


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

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
#define BIG(c) (c)-0x20
#define SMALL(c) (c)+0x20
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      int N, X;
      cin >> N >> X;
      vector<int> vec (N);
      for(int i = 0;i < N;i++){
          cin >> vec[i];
      }

      int i = 0;
      int dis = 0;
      for(i = 0;i <= N;i++){
          if(dis > X){
              cout << i << endl;
              return 0;
          }
          else{
              dis += vec[i];
          }
      }
      cout << i << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e2+5;
#define int long long
int h, w, n, r, c;
set<pair<int,int>> S;
int cnt[N];
signed main(){
	cin >> h >> w >> n;
  	cnt[0] = (h-2)*(w-2);
  	while(n--){
   		cin >> r >> c;
    	r--; c--;
    	S.insert({r,c});
    	for(int p=max((int)0,r-2);p<=min(h-3,r);p++){
      		for(int q=max((int)0,c-2);q<=min(w-3,c);q++){
       	 		int tmp = 0;
        		for(int i=p;i<=p+2;i++){
          			for(int j=q;j<=q+2;j++){
            			if(S.count({i,j})) tmp++;
          			}
        		}
        		cnt[tmp]++;
        		cnt[tmp-1]--;
      		}
    	}
  	}
  	for(int i=0;i<=9;i++) cout << cnt[i] << endl;
  	return 0;
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A;
  for (int i = 0; i < N; i++)
  {
    int tmp;
    cin >> tmp;
    if (i == 0 || tmp != A.back())
      A.push_back(tmp);
  }
  int size = A.size(), ans = 1, t = 0;
  for (int i = 1; i < size; i++)
    if (t != i - 1 && (A[i - 2] < A[i - 1]) != (A[i - 1] < A[i]))
    {
      ans++;
      t = i;
    }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  if(D==1) cout<<1<<endl;
  else cout<<0<<endl;;
}

Measured memory_bytes: 256
package main
 
import (
	"fmt"
	"math"
)
 
var N, ANS int
func main() {
	ANS = 10000000000000000
	fmt.Scan(&N)
	I := int(math.Sqrt(float64(N)))
	for i := 1; i <= I; i++ {
		j := N / i
		if N % i == 0 {
		    ANS = min(ANS, i + j)
		} 
	}
	fmt.Println(ANS -2)
}

func calc(n int) {
	next := n / 2
	amari := n % 2
	fmt.Printf("n = %v, next = %v, amari = %v\n",n ,next, amari)
	if next == 0 {return}
	calc(next)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
 
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
 
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

Measured memory_bytes: 1792
import sys

N, Y = map(int, input().split())

for i in range(N+1):
    for j in range(N+1-i):
        x = i
        y = j
        z = N - i - j
        if (10000*x + 5000*y + 1000*z) == Y:
            print("{} {} {}".format(x,y,z))
            sys.exit()

print("{} {} {}".format(-1,-1,-1))

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

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vec;
typedef std::vector<ld> vecld;
typedef std::vector< std::vector<ll> > vecvec;
typedef std::pair<ll, ll> pr;
typedef std::vector< pr > vpr;

#define tin ll t;cin>>t;while(t--)
#define fio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define sz(a) (ll)((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define trvect(c,i) for(vector<ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define trset(c,i) for(set<ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define trmap(c,i) for(map<ll,ll>::iterator i = (c).begin(); i != (c).end(); i++)
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define present(c,x) ((c).find(x) != (c).end())
#define ff first
#define ss second
#define mk make_pair
#define sq(a) (a)*(a)
#define cube(a) (a)*(a)*(a)
#define cnti(x) (__builtin_popcount(x)) //number of set bits in x
#define mst(c) memset((c),0,sizeof((c)))


int main(){


	//fio;

	/////////////////////////////////////////

ll a,b;
cin>>a>>b;
cout<<max(a+b,max(a-b,a*b));





	////////////////////////////////////////////////




    return 0;












}


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

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

typedef pair<int, int> pii;

const long MAX_N = 100 * 1000 + 24, INF = 1e9 + 24;

int n, m, s;
int dist[MAX_N];
bool mark[MAX_N];
vector<pii> G[MAX_N];
set<pii> st;

void dfs (int v) {
  mark[v] = true;
  for (auto e : G[v]) {
    if (mark[e.F] == 0) dfs (e.F);
  }
}

int main() {
  memset(mark, 0, sizeof (mark));
  memset(dist, 63, sizeof (dist));
  cin>>n>>m>>s;
  int u, v, w;
  for (int i = 0; i < m; i++) {
    cin>>u>>v>>w;
    G[u].pb(mp(v, w));
    //G[v].pb(mp(u, w));
  }
  //cerr<<"out"<<endl;
  dfs(s);
  st.insert(mp(s, 0));
  dist[s] = 0;
  for (int i = 0; i < n; i++) {
    if (i != s and mark[i]) {
      st.insert(mp(i, INF));
    }
  }
  while (st.size()) {
    pii t = *st.begin();
    st.erase(st.begin());
    for (auto e : G[t.F]) {
      if (dist[e.F] > dist[t.F] + e.S) {
        st.erase(mp(e.F, dist[e.F]));
        dist[e.F] = dist[t.F] + e.S;
        st.insert(mp(e.F, dist[e.F]));
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dist[i] > INF) cout<<"INF"<<endl;
    else cout<<dist[i]<<endl;
  }
}



Measured memory_bytes: 18984
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;

#define pb push_back
#define fi first
#define se second
#define in insert
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int mod = 1e9 + 7;
const int inf = 1e9;

template <class T>
istream& operator>>(istream& ss, vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss >> v[i];
    return ss;
}

template <class T> 
ostream& operator<<(ostream& ss, const vector<T>& v) {
    for (int i = 0; i < v.size(); i++) ss << v[i] << ' ';
    return ss;
}

ll binpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1) {
            res *= a;
            res %= m;
        }
        a *= (a % m);
        a %= m;
        n >>= 1;
    }
    return res % m;
}

ll gcd(ll a, ll b) {
    return b ? gcd (b, a % b) : a;
}

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

const int N = 1e5 + 5;
vi adj[N];
bool used[N];
int p[N];
void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    queue<int> q;
    q.push(1);
    used[1] = true;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (auto to : adj[v]) {
            if (used[to]) continue;
            used[to] = true;
            q.push(to);
            p[to] = v;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!used[i]) {
            cout << "No";
            return;
        }
    }
    cout << "Yes\n";
    for (int i = 2; i <= n; ++i) cout << p[i] << "\n";
}

int main() {
    speed;
    int t = 1;
    //cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
}

Measured memory_bytes: 10508
n,m = map(int,input().split())
root = [[] for _ in range(n)]
for i in range(m):
    aa,bb =map(int,input().split())
    aa-=1
    bb-=1
    root[aa].append(bb)
    root[bb].append(aa)

from collections import deque

q = deque([(-1,0)])
been=[0]*n
ans=[0]*n
been[0]=1
while q:
    parent,now = q.popleft()
    ans[now]=parent
    
    for to in root[now]:
        if been[to]==0:
            q.append((now,to))
            been[to]=1

print("Yes")
for i in range(1,n):
    print(ans[i]+1)


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

using namespace std;

int main()
{
    int A, B;
    
    cin >> A >> B;
    
    auto ans = A + B;
    if (ans >= 24)
    {
        ans -= 24;
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 256