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

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

void unq(auto &a){
  sort(all(a));
  a.resize(unique(all(a))-a.begin());
}

const int N=500005;

vector<int>rv[(1<<20)];

void solve(){
	int n;
	cin>>n;
	vi a(n);
	cin>>a;
	int xr=0;
	for(int i=0;i<n;i++){
		xr^=a[i];
		rv[xr].pb(i);
		a[i]=xr;
	}
	if(a.back()){
		int ans=0;
		int i=a.back();
		vi zz;
		for(auto j:rv[i]){
			zz.pb(j);
		}
		for(auto j:rv[0]){
			zz.pb(j);
		}
		int dp[2];
		dp[0]=1;
		dp[1]=0;
		sort(all(zz));
		dp[0]=1;
		for(int j=0;j<zz.size();j++){
			if(a[zz[j]]==i){
				add(dp[1],dp[0]);
			}
			else{
				add(dp[0],dp[1]);
			}
		}
		add(ans,dp[0]);
		cout<<ans;
		return;
	}
	int ans=0;
	for(int i=1;i<(1<<20);i++){
		vi zz;
		if(rv[i].size()==0){
			continue;
		}
		int dp[2];
		dp[0]=1;
		dp[1]=0;
		for(int j=0;j<rv[i].size();j++){
			int cnt=0;
			int up=n;
			up=rv[i][j];
			int lw=0;
			if(j){
				lw=rv[i][j-1]+1;
			}
			cnt=lower_bound(all(rv[0]),up)-lower_bound(all(rv[0]),lw);
			if(j==0){
				cnt++;
			}
			add(dp[0],mul(cnt,dp[1]));
			add(dp[1],dp[0]);
		}
		add(ans,dp[1]);
	}
	int cnt=0;
	for(auto i:a){
		if(i==0){
			cnt++;
		}
	}
	debug(cnt);
	add(ans,powz(2,cnt-1));
	cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //~cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}


Measured memory_bytes: 36980
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
int a[5];
int main() {
	a[1] = read(); a[2] = read(); a[3] = read();
	sort(a + 1, a + 4);
	printf("%d", abs(a[2] - a[1]) + abs(a[3] - a[2]));
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <array>
#include <vector>
#include <utility>
#include <bitset>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

using ll = long long;
using p = pair<ll, ll>;

constexpr ll INF = 1LL << 62;
constexpr ll MAX_N = 200;

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

    ll N, H;
    cin >> N >> H;

    vector<ll> A(N), B(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }

    sort(A.begin(), A.end());
    ll a = A.back();

    sort(B.begin(), B.end(), greater<ll>());

    ll b_count = 0;
    ll b_sum = 0;
    for (ll i = 0; i < N; i++) {
        if (B[i] > a) {
            b_count++;
            b_sum += B[i];
            if (b_sum >= H) {
                break;
            }
        }
    }

    ll count = b_count;

    if (b_sum < H) {
        ll rest = H - b_sum;
        count += (rest + a - 1) / a;
    }

    cout << count << endl;

    return 0;
}




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

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <ll, ll> dl;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <vi> graph;

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

	int n;
	cin >> n;
	string a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	int costo = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == b[i] && a[i] == c[i]) {
			continue;
		} else if ((a[i] == b[i]) || (a[i] == c[i]) || (b[i] == c[i])) {
			costo++;
		} else {
			costo += 2;
		}
	}
	cout << costo << "\n";
	return 0;
}


Measured memory_bytes: 256
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a = sorted(a)
print(len(a[:a.index(x)]) if len(a[:a.index(x)+1]) <= len(a[a.index(x)+1:]) else len(a[a.index(x)+1:]))

Measured memory_bytes: 9168
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int ans;
        if(a>=b-W&&a<=b+W) ans=0;
        else if(a+W<b){
            ans = b-a-W;
        }
        else ans = a-b-W;
        System.out.println(ans);

    }
}


Measured memory_bytes: 25172
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;

vector<ll> divisor(ll n)
{
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) {
                res.push_back(n / i);
            }
        }
    }

    return res;
}

ll digit(ll a, ll b) {
    int ca = 0, cb = 0;
    while (a != 0) {
        a /= 10;
        ca++;
    }
    while (b != 0) {
        b /= 10;
        cb++;
    }
    return max(ca, cb);
}

int main()
{
    ll N;
    cin >> N;

    ll ans = INF;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ans = min(ans, digit(i, N / i));
        }
    }

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

Measured memory_bytes: 256
#include <stdio.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail++;
    if(tail>=LEN+1){
        tail=0;
    }
}

P dequeue(){
    P p = Q[head];
    head++;
    if(head>=LEN+1){
        head=0;
    }
    return p;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  head = 1;
  tail = 1;

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    tail++;
  }
  
  while(head!=tail){
      u = dequeue();
      if(u.t<=q){
          elaps+=u.t;
          printf("%s %d\n",u.name,elaps);
      }else{
          elaps += q;
          u.t-=q;
          enqueue(u);
      }
  }
  
  return 0;
}



Measured memory_bytes: 11836
//MD. HASNAIN ALI (UNSOLVED)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define MAX(a,b) (a>b? a:b)
#define SWAP(a,b) {        \
                    a=a+b; \
                    b=a-b; \
                    a=a-b; }
#define ll long long



int main()
{
    int x[5];
    int i;
    for(i=0;i<5;i++)
    {
        scanf("%d",&x[i]);
    }
    for(i=0;i<5;i++)
    {
        if(x[i]==0)
        {
            printf("%d\n",i+1);
            break;
        }
    }




    return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n ; ++i)
#define REP(i,a,b) for(int i=a; i<b; ++i)
typedef long long ll;
//プロトタイプ宣言
int gcd(int , int);


int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    if(i%2 == 1){
      if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}








































//以下、ライブラリ
//ユークリッドの互除法

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



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

int main() {
 int l,r,d;
  
  cin>>l>>r>>d;
  
  int ans=0;
  
  for(int i=l;i<=r;i++){
  	if(i%d==0)ans++;
  }
  
  cout<<ans<<endl;

}

Measured memory_bytes: 3584
import numpy as np
import math

line = input().split()
x1 = int(line[0])
y1 = int(line[1])
x2 = int(line[2])
y2 = int(line[3])

a = x2-x1
b = y2-y1
r = math.sqrt(a*a + b*b)


x3 = x2 - b
y3 = y2 + a
x4 = x3 - a
y4 = y3 - b

print("{} {} {} {}".format(x3, y3, x4, y4))


Measured memory_bytes: 12496
# https://beta.atcoder.jp/contests/abc109/tasks/abc109_b


def solve():
    n = int(input())
    words = [input() for _ in range(n)]

    if len(words) is not len(set(words)):
        print('No')
        exit()

    for i in range(1, len(words)):
        if words[i-1][-1] != words[i][0]:
            print('No')
            exit()
    else:
        print('Yes')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
#include<iostream>
using namespace std;
typedef struct
{
	int use;
	int turn;
}node;
node bo[100000];
int main()
{
	int n;
	cin>>n;
	for(int i = 1; i <= n; i++){
		cin>>bo[i].turn ;
		bo[i].use = 0;
	}
	int j = 1, flag = 0, count = 0;
	while(j != 2 && bo[j].use == 0){
		bo[j].use = 1;
		j = bo[j].turn ;
		if(j == 2) flag = 1;
		count++;
	}
	if(flag == 1) cout<<count<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    f = [0 for i in range(N)]
    f[0] = 0
    f[1] = abs(h[1] - h[0])
    if N > 2:
        f[2] = min(abs(h[2] - h[0]), abs(h[2] - h[1]))
        for i in range(N-2):
            f[i+2] = min(f[i] + abs(h[i+2] - h[i]), f[i+1] + abs(h[i+2] - h[i+1]))
    print(f[N-1])
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18112
#include<bits/stdc++.h>
#define ll long long
#define rep(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
int main()
{
  int n,k,ans;
  cin >> n >> k;
  if((n-k)%(k-1)==0)ans=((n-k)/(k-1))+1;
  else ans=((n-k)/(k-1))+2;
  printf("%d",ans);
}

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

int main() {
  long long int N, K;
  cin >> N >> K;
  
  long long int ans = 0;
  long long int zero = 0;
  
  if (K != 0) {
    for (long long int b = K + 1; b <= N; b++) {
      ans += (N / b) * (b - K) + max(N % b - K + 1, zero);
    }
  }
  
  else ans = N * N;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int UF[210000];
int FIND(int a){
	if(UF[a]<0)return a;
	return UF[a]=FIND(UF[a]);
}
void UNION(int a,int b){
	a=FIND(a);b=FIND(b);if(a==b)return;UF[a]+=UF[b];UF[b]=a;
}
pair<int,pair<int,int> >edge[210000];
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++)UF[i]=-1;
	for(int i=0;i<a-1;i++){
		int p,q,r;scanf("%d%d%d",&p,&q,&r);
		edge[i]=make_pair(r,make_pair(p,q));
	}
	std::sort(edge,edge+a-1);
	long long ret=0;
	for(int i=0;i<a-1;i++){
		ret+=(long long)(-UF[FIND(edge[i].second.first)])*(-UF[FIND(edge[i].second.second)])*edge[i].first;
		UNION(edge[i].second.first,edge[i].second.second);
	}
	printf("%lld\n",ret);
}

Measured memory_bytes: 4272
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(int, K);
    CINS(int, A, N);

    int ans = 1;
    N -= K;
    while ( N > 0)
    {
        ans++;
        N -= (K-1);
    }
    
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

int main(int argc, char const *argv[]) {
	int N,K;
	std::cin >> N >> K;
	std::vector<pair<int,int>> v;
	std::vector<long long> x,y;
	for (size_t i = 0; i < N; i++) {
		int a,b;
		std::cin >> a >> b;
		v.push_back(make_pair(a,b));
		x.push_back(a);
		y.push_back(b);
	}
	sort(x.begin(),x.end());
	sort(y.begin(),y.end());

	long long ans = (x[N-1] - x[0]) * (y[N-1] - y[0]);
	for (size_t i = 0; i < N; i++) {
		for (size_t j = i; j < N; j++) {
			for (size_t k = 0; k < N; k++) {
				for (size_t l = k; l < N; l++) {
					int num = 0;
					for (size_t m = 0; m < v.size(); m++) {
						if (x[i] <= v[m].first && v[m].first <= x[j] && y[k] <= v[m].second && v[m].second <= y[l]) {
							num++;
						}
					}

					if (num >= K) {
						ans = min(ans, 1LL * ((x[j]-x[i]) * (y[l]-y[k])));
					}
				}
			}
		}
	}

	std::cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 384
import Control.Monad
import Control.Applicative
import Data.List

splitN _ [] = []
splitN n x = take n x : splitN n (drop n x)

printMatrix = mapM_ putStrLn . map (unwords . map show)

main = do
	[n, m, l] <- (map read . words) <$> getLine
	a <- replicateM n $ (map read . words) <$> getLine
	b <- replicateM m $ (map read . words) <$> getLine
	printMatrix $ splitN l $ [sum (zipWith (*) a' b') | a' <- a, b' <- transpose b]

Measured memory_bytes: 12280
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const int INF = 1e3;
typedef long double ld;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(){
  int n,m;  cin >> n >> m;
  int d[n][m];
  rep(i,0,n)rep(j,0,m){
    d[i][j] = INF;
  }
  char s[n][m];
  int black = 0;
  rep(i,0,n)rep(j,0,m){
    cin >> s[i][j];
    if(s[i][j]=='#') black++;
  }
  d[0][0] = 0;
  queue<P> que;
  que.push(P(0,0));
  int cnt = 0;
  while(que.size()){
    P p = que.front();  que.pop();
    int x = p.fi, y = p.se;
    rep(i,0,4){
      int nx = x+dx[i], ny = y+dy[i];
      if(nx<0||ny<0||nx>=n||ny>=m||s[nx][ny]=='#')  continue;
      if(d[nx][ny]==INF){
        que.push(P(nx,ny));
        d[nx][ny] = d[x][y] + 1;
      }
    }
  }
  if(d[n-1][m-1]==INF){
    cout << -1 << endl;
  }else{
    cout << n*m - d[n-1][m-1] - 1 - black << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pii;
 
#define REP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define PER(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)

ll ii(){ ll x; cin >> x; return x; }
string is(){ string x; cin >> x; return x; }
void oi(ll x){ cout << x; }
void od(ld x){ cout << fixed << setprecision(10) << x; }
void os(string x){ cout << x; }
void oie(ll x){ cout << x << endl; }
void ode(ld x){ cout << fixed << setprecision(10) << x << endl; }
void ose(string x){ cout << x << endl; }
void oe(){ cout << endl; }

ll modpow(ll a, ll n, ll m){
    ll ret=1;
    while(n>0){
        if(n&1){ ret=ret*a%m; }
        a=a*a%m;
        n>>=1;
    }
    return ret;
}

ll m=1000000007;
ll dp[200000];

int main(){
    ll N=ii();
    ll K=ii();
    ll sum=0;

    PER(i,K,1){
        dp[i]=modpow(K/i,N,m);
        for(ll j=i*2;j<=K;j+=i){
            dp[i]-=dp[j];
            dp[i]=(dp[i]+m)%m;
        }
        sum+=i*dp[i];
        sum%=m;
    }
    oie(sum);
    return 0;
}


Measured memory_bytes: 4328
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;


int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x,y;
  cin>>x>>y;
  cout<<6-x-y<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define endl "\n"
using namespace std;

bool sortbysec(const pair<ll,ll> &a, 
              const pair<ll,ll> &b) 
{ 
    return (a.second < b.second); 
} 

ll maxSubArraySum(ll a[], ll size) 
{ 
    ll max_so_far = INT_MIN, max_ending_here = 0; 
  
    for (ll i = 0; i < size; i++) 
    { 
        max_ending_here = max_ending_here + a[i]; 
        if (max_so_far < max_ending_here) 
            max_so_far = max_ending_here; 
  
        if (max_ending_here < 0) 
            max_ending_here = 0; 
    } 
    return max_so_far; 
} 

ll findSubarraySum(ll arr[], ll n, ll sum = 0) 
{
    unordered_map<ll, ll> prevSum;
    ll res = 0;
    ll currsum = 0;
    for (ll i = 0; i < n; i++)
    {
        currsum += arr[i];
        if (currsum == sum) res++;
        if (prevSum.find(currsum - sum) != prevSum.end()) res += (prevSum[currsum - sum]);
        prevSum[currsum]++;
    }
    return res; 
} 
ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
ll powmp(ll x, ll y, ll p) 
{ 
    ll res = 1;     x = x % p;   
    while (y > 0) 
    {  
        if (y & 1)  res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p;   
    } 
    return res; 
} 

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n,k;cin>>n>>k;
    map<int,int> vis;
    ll a[n+1];
    vector<ll> v;
    f(i,1,n+1) cin>>a[i];
    v.pb(1);
    int f=0,s=0;
    int it=1;
    vis[1]++;
    while(1)
    {
        it=a[it];
        if(it==a[it])
        {
            f=it;
            break;
        }
        if(vis[it])
        {
            s=it;
            break;
        }
        vis[it]++;
        v.pb(it);
    }
    if(f)
    {
        if(k<v.size()) cout<<v[k%v.size()]<<endl;
        else cout<<it<<endl;
    }
    else
    {
        ll spos;
        f(i,0,v.size())
        {
            if(v[i]==s) spos=i;
        }
        vector<ll> an;
        f(i,spos,v.size()) an.pb(v[i]);
        if(k<v.size()) cout<<v[k%v.size()]<<endl;
        else
        {
            k-=spos;
            cout<<an[k%(ll)an.size()]<<endl;
        }
        
    }
    
}


Measured memory_bytes: 17908
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
    mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { mint res(*this); return res+=a; }
    mint operator-(const mint a) const { mint res(*this); return res-=a; }
    mint operator*(const mint a) const { mint res(*this); return res*=a; }
    mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; }
    // for prime mod
    mint inv() const { return pow(mod-2); }
    mint& operator/=(const mint a) { return (*this) *= a.inv(); }
    mint operator/(const mint a) const { mint res(*this); return res/=a; }
};

int main(){
  string s;
  int d;
  cin >> s >> d;
  int n = s.size();
  vector<vector<vector<mint>>> dp(10010, vector<vector<mint>>(2, vector<mint>(105,0)));
  dp[0][0][0]=1;
  rep(idx,n)rep(j,d)rep(k,2){
    int up = (int)(s[idx]-'0');
    rep(m,10){
      if(k==0 && up<m) continue;
      dp[idx+1][k|(m<up)][(m+j)%d] += dp[idx][k][j];
    }
  }
  mint ans = dp[n][0][0] + dp[n][1][0] -1; //without 0
  cout << ans.x << ln;
  return 0;
}

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

template<class T>
inline vector<pair<T, T> > primeFactorize(T n) {
    vector<pair<T, T> > res;
    for (T a = 2; a * a <= n; a++) {
        if (n % a != 0) continue ;
        T ex = 0;
        while (n % a == 0) {
            ++ex;
            n /= a;
        }
        res.push_back({a, ex});
    }
    if (n != 1) res.push_back({n, 1});
    return res;
}

int main(){
    cin.tie(0)->sync_with_stdio(false);

	ll n;
	cin >> n;

	map<ll, ll> p;
	for (ll i = 1; i <= n; i++) {
		vector<pair<ll, ll> > tmp;
		tmp = primeFactorize(i);
		for (auto x : tmp)
			p[x.first] += x.second;
	}

	ll res = 1;
	for (auto x : p) {
		res *= x.second + 1;
		res %= MOD;
	}
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3668
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

H,W,N = map(int,input().split())
y,x = map(int,input().split())
S = input()
T = input()

def is_out(now,adv,back,L,R):
    for i in range(N):
        if S[i] == adv:
            now += 1
            if now > R:
                return True
        if T[i] == back:
            now = max(now - 1,L)
    return False

ans = is_out(x,'R','L',1,W) | is_out(-x,'L','R',-W,-1) | is_out(y,'D','U',1,H) | is_out(-y,'U','D',-H,-1)
print('NO' if ans else 'YES')

Measured memory_bytes: 3768
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[111111],cur,cnt;
bool f[111111];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	cur=1;f[1]=1;
	while(1)
	{
		cnt++;
		cur=a[cur];
		if (cur==2) break;
		else if (f[cur]) 
		{
			cout<<-1<<endl;
			return 0;
		}
		f[cur]=1;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

struct Edge {
  int t,next;
  Edge() {}
  Edge(int a,int b):t(a),next(b) {}
};

Edge e[1005];
int head[1005],num[1005];

bool can[2][5005];
int f[1005];

bool dfs(int x) {
  int cur=0,sum=0;
  for(int i=head[x];i;i=e[i].next)
    if (!dfs(e[i].t)) return 0;
  memset(can[cur],0,sizeof(can[cur]));
  can[cur][0]=1;
  for(int i=head[x];i;i=e[i].next) {
  	int u=e[i].t;
  	cur^=1;
  	memset(can[cur],0,sizeof(can[cur]));
  	for(int j=num[u];j<=num[x];j++)
  	  can[cur][j]|=can[cur^1][j-num[u]];
  	for(int j=f[u];j<=num[x];j++)
  	  can[cur][j]|=can[cur^1][j-f[u]];
  	sum+=num[u]+f[u];
  }
  for(int i=num[x];i>=0;i--)
    if (can[cur][i]) {
    	f[x]=sum-i;
    	return 1;
	}
  return 0;
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=2;i<=n;i++) {
  	int x;
  	scanf("%d",&x);
  	e[i]=Edge(i,head[x]);
  	head[x]=i;
  }
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  puts((dfs(1))?"POSSIBLE":"IMPOSSIBLE");
  return 0;
}

Measured memory_bytes: 256
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;

int n,x,ans;
vector<int>vec;

int32_t main(){_
    //freopen("input","r",stdin);
	cin >> n;
	for(int i = 1;i <= n;i++)
	{
		cin >> x;
		vec.pb(x);
	}
	sort(vec.begin(),vec.end());
	for(int i = 1;i < sz(vec);i++)
	{
		ans += vec[i] - vec[i - 1];
	}
	rc(ans);
}

Measured memory_bytes: 256
/*g++ main.cpp -o main.out*/
/*./main.out*/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define LD long double
#define Mod 1000000007
#define L_Mod 17100000013

const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;

#define NO_TLE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define ree(a,n) memset(a,n,sizeof(a));

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define red(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i))

double a[55];

int main()
{
    //NO_TLE
    int n;
    cin>>n;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    double tmp=a[0];
    rer(i,1,n-1)
    {
        tmp=(tmp+a[i])/2.0;
    }
    cout<<tmp<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int sa(int a, int b) {
  if(a > b) {
    return a - b;
  }
  else {
    return b - a;
  }
}
int main () {
  int X, N;
  cin >> X >> N;
  vector<int> q(N);
  for(int i = 0; i < N; i++) {
    cin >> q.at(i);
  }
  bool S = true;
  int ans = 100;
  int ansans = 0;
  for(int i = 0;i < 201; i++) {
    for(int j = 0; j < N; j++) {
      if(i == q.at(j)) {
        S = false;
        break;
      }
    }
    if(S) {
      if(ans > sa(X, i)) {
        ans = sa(X, i);
        ansans = i;
      }
    }
    S = true;
  }
  cout << ansans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define RST(a) memset(a, 0, sizeof(a))
#define RSTV(a, v) memset(a, v, sizeof(a))
#define FOR(i, a, b) for (auto i = (a); i < (b); ++i)
const int INF = 0x3f3f3f3f;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int s[a][b];
  FOR(i, 0, a) FOR(j, 0, b) cin >> s[i][j];
  int cnt = 0;
  FOR(i, 0, a) FOR(j, i + 1, a) {
    int tmp = 0;
    FOR(k, 0, b) tmp += pow(s[i][k] - s[j][k], 2);
    int t = sqrt(tmp);
    if (t * t == tmp) ++cnt;
  }
  cout << cnt;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long h = sc.nextLong();
		long w = sc.nextLong();

		if(h==1 || w==1) {
			System.out.println(1);
			return;
		}

		double total = (h*w);

		long ans = Math.round(total/2.0);

		System.out.println(ans);

	}
}


Measured memory_bytes: 23252
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [] xs = new int[n];
        int [] ys = new int[n];
        for(int i = 0; i < n; i++) {
            xs[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++) {
            ys[i] = sc.nextInt();
        }
        double d1 = 0;
        double d2 = 0;
        double d3 = 0;
        double di = 0;
        for(int i = 0; i < n; i++) {
            double d = xs[i] - ys[i];
            if(d < 0) d = -d;
            d1 += d;
            d2 += d*d;
            d3 += d*d*d;
            if(d > di) di = d;
        }
        d2 = Math.sqrt(d2);
        d3 = Math.pow(d3, 1./3);
        
        NumberFormat format = NumberFormat.getInstance();
        format.setMaximumFractionDigits(5);
        format.setMinimumFractionDigits(5);
        format.setGroupingUsed(false);
        System.out.println("" + format.format(d1));
        System.out.println("" + format.format(d2));
        System.out.println("" + format.format(d3));
        System.out.println("" + format.format(di));
    }
}

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

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

	deque<int> b;
	for( int i = 0; i < n; i++ ) {
		if( i % 2 ) b.push_front( a[i] );
		else b.push_back( a[i] );
	}
	if( n % 2 ) reverse( b.begin(), b.end() );

	for( int i = 0; i < n; i++ ) {
		if( i ) cout << " ";
		cout << b[i];
	}
	cout << endl;
}


Measured memory_bytes: 4840
X, K, D = list(map(int, input().split()))

if X == 0:
    if K % 2 == 0:
        print(0)
    else:
        print(abs(D))
elif 0 < X:
    x = round(X / D)
    if x <= K:
        if (K - x) % 2 == 0:
            print(abs(X - x * D))
        else:
            if 0 < X - x * D:
                print(abs(X - (x + 1) * D))
            else:
                print(abs(X - (x - 1) * D))
    else:
        print(abs(X - K * D))
else:
    x = round(- X / D)
    if x < K:
        if (K - x) % 2 == 0:
            print(abs(X + x * D))
        else:
            if 0 < X + x * D:
                print(abs(X + (x - 1) * D))
            else:
                print(abs(X + (x + 1) * D))
    else:
        print(abs(X + K * D))


Measured memory_bytes: 9176
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int N;
  int L;
  int S=0;
  //int s;
  cin >> N >> L;
  int a[N];

  for(int i=1;i<=N;i++){
    a[i-1]=L+i-1;
    S=S+a[i-1];
  }
  const int s=S;
  int sa=0;
  int saisyou=100000;
  for(int i=1;i<=N;i++){
    if(a[i-1]<0){
      a[i-1]=a[i-1]*(-1);
      if(a[i-1]<saisyou){
        saisyou=a[i-1];
        sa=a[i-1]*(-1);
      }
    }
    else{
      if(a[i-1]<saisyou){
        saisyou=a[i-1];
        sa=a[i-1];
      }
    }

  }
  S=S-sa;
  cout << S << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
#define SoArrt(a, n) sort(a, a + n);
#define SoArrtR(a, n) sort(a, a + n, std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    ll a, b, c;

	cin >> a >> b >> c;

	ll x, y;
	ll diff;

	x = a / 2;
	y = a - x;
	x *= b * c;
	y *= b * c;
	diff = Abs(x - y);

	x = b / 2;
	y = b - x;
	x *= a * c;
	y *= a * c;
	Min(diff, Abs(x - y));

	x = c / 2;
	y = c - x;
	x *= a * b;
	y *= a * b;
	Min(diff, Abs(x - y));

	Out(diff);
	
	return 0;
}


Measured memory_bytes: 256
implicit none
integer:: n,i,j,count,a,b,keta_sum, s_int,k
character(5) :: s

read(5,*) n,a,b

count=0

do i=1,n
    keta_sum=0
    write (s,"(i0)") i
    
    do j=1, len(s)
        if (s(j:j)/="") then
            read (s(j:j),*) s_int
            keta_sum=keta_sum+s_int
        endif
    enddo
    
        if (keta_sum>=a .and. b>=keta_sum) then
            count=count+i
        endif
         
enddo

write(6,*) count

end

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h,w;
  cin>>h>>w;
  vector<string> g(h);
  for(int i=0;i<h;i++)cin>>g[i];
  vector<vector<int>> d(h,vector<int>(w,-1));
  vector<pair<int,int>> q;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(g[i][j]=='#'){
        q.emplace_back(i,j);
        d[i][j]=0;
      }
    }
  }
  for(int b=0;b<(int)q.size();b++){
    for(int dx=-1;dx<=1;dx++){
      for(int dy=-1;dy<=1;dy++){
        if(dx*dx+dy*dy==1){
          int xk=q[b].first+dx;
          int yk=q[b].second+dy;
          if(xk>=0 && yk>=0 && xk<h && yk<w && d[xk][yk]==-1){
            q.emplace_back(xk,yk);
            d[xk][yk]=d[q[b].first][q[b].second]+1;
          }
        }
      }
    }
  }
  cout << d[q.back().first][q.back().second] << '\n';
  return 0;
}


Measured memory_bytes: 15596
#include<cstdio>
#include<algorithm>
#include<vector>
#include<iostream>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,n) for(int i=1;i<=n;i++)
vector<int> t;
vector<int> w;
int main(){
	while(1){
		w.clear();
		t.clear();
	int n,m;
	cin>>n>>m;
	if(n==0)break;
	t.push_back(0);
	
	rep(i,n){
		int a;
		cin>>a;
		t.push_back(a);
	}
	n++;
	sort(t.begin(),t.end());
	rep(i,n){
		rep(j,n){
			w.push_back(t[i]+t[j]);
		}
	}
	sort(w.begin(),w.end());
	int ans=0;
	rep(i,w.size()){
		vector<int>::iterator a=upper_bound(w.begin(),w.end(),m-w[i]);
		if(a==w.begin())continue;
		ans=max(ans,*(a-1)+w[i]);
	}
	printf("%d\n",ans);
}
}

Measured memory_bytes: 4960
from math import sqrt

N, D = (int(i) for i in input().split())  
X = [[int(i) for i in input().split()] for i in range(N)] 


def calc_distance(A, B):

    distance = 0
    for a, b in zip(A, B):
        distance += (a - b)**2
    
    return sqrt(distance)

ans = 0
for i in range(N):
    for j in range(N):
        if i == j: continue
        d = calc_distance(X[i], X[j])
        if d.is_integer(): ans += 1


print(int(ans/2))

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
int main(){
	int w[10];
	int k[10];
	int i,j;
	for(i=0;i<10;i++){
		scanf("%d",&w[i]);
	}
	for(i=0;i<10;i++){
		scanf("%d",&k[i]);
	}
	int maxw,maxk,dataw,datak;
	for(i=0;i<10;i++){
		maxw=0;
		maxk=0;
		dataw=-1;
		datak=-1;
		for(j=i;j<10;j++){
			if(w[j]>maxw){
				maxw=w[j];
				dataw=j;
			}
			if(k[j]>maxk){
				maxk=k[j];
				datak=j;
			}
		}
		w[dataw]=w[i];
		w[i]=maxw;
		k[datak]=k[i];
		k[i]=maxk;
	}
	printf("%d ",w[0]+w[1]+w[2]);
	printf("%d\n",k[0]+k[1]+k[2]);
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
int main() {
  int a, b, c ;
  cin >> a >> b >> c;
  if (a*b > c) {
    cout << c << endl;
  } else {
    cout << a*b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N,M = (int(x) for x in input().split())
Con = [[] for I in range(0,M)]
for T in range(0,M): Con[T] = [int(x) for x in input().split()][1:]
Lights = [int(x) for x in input().split()]
Count = 0
for TT in range(0,pow(2,N)):
    Flag = True
    Switch = list(int(x) for x in list(('{:0'+str(N)+'b}').format(TT,'b')))
    for T in range(0,M):
        if sum(Switch[x-1] for x in Con[T])%2!=Lights[T]:
            Flag = False
            break
    if Flag: Count += 1
print(Count)

Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
using sint = int64_t;

template<class T> T read() {
	T t;
	cin >> t;
	return t;
}

template<class T> vector<T> read_vector(sint n) {
	vector<T> vs;
	for (sint i = 0; i < n; ++i) {
		vs.push_back(read<T>());
	}
	return vs;
}

inline void write() {
}

template<class T> void write(T const& t) {
	cout << t;
}

template<class T> void write(vector<T> const& ts) {
	if (ts.size() > 0) {
		cout << ts[0];
	}
	for (size_t i = 1; i < ts.size(); ++i) {
		cout << ' ' << ts[i];
	}
}

template<class T, class... Args> void write(T const& t, Args const&... args) {
	cout << t << ' ';
	write(args...);
}

template<class... Args> void writeln(Args const&... args) {
	write(args...);
	cout << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin .exceptions(ios_base::badbit | ios_base::failbit);
	cout.exceptions(ios_base::badbit | ios_base::failbit);
	cin .tie(nullptr);
	cout.tie(nullptr);
	cout.precision(16);
	void run();
	run();
	return 0;
}

void run() {
	auto const N = read<sint>();
	auto const S = read<string>();

	sint nSlimes = 1;
	for (sint i = 1; i < N; ++i) {
		if (S[i - 1] != S[i]) {
			++nSlimes;
		}
	}
	writeln(nSlimes);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define all(a)  (a).begin(),(a).end()

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

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

const ll INF = 1LL << 60;

int main(){
  int n; cin >> n;
  ll sum = 0;
  vi a(n);
  rep(i, n){
    cin >> a[i];
    sum += a[i];
  }
  vector<ll> ans(n);
  ans[0] = sum;
  for (int i = 0; 2*i+1 <= n-2; i++) {
    ans[0] -= 2*a[2*i+1];
  }
  rep(i, n-1) ans[i+1] = 2*a[i]-ans[i];
  rep(i, n) std::cout << ans[i] << '\n';

}


Measured memory_bytes: 2432
from collections import Counter

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

N = int(input())
counter = Counter()
for i in range(2, N+1):
    counter.update(Counter(prime_factorize(i)))
ans = 1
for value in counter.values():
    ans *= (value + 1)
print(ans % (10**9 + 7))

Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <set>

using namespace std;
using ll = long long;
const int MOD=1000000007;

int main(int argc, char**argv){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (int i = 0; i < h; i++){
        cin >> s[i];
    }

    for (int i = 0; i < h; i++){
        for (int k = 0; k < w; k++){
            if (s[i][k] == '#'){
                cout << s[i][k];
            }else{
                int out = 0;
                if (k > 0 && s[i][k-1] == '#') out++;
                if (k < w-1 && s[i][k+1] == '#') out++;
                if (i > 0 && s[i-1][k] == '#') out++;
                if (i < h-1 && s[i+1][k] == '#') out++;

                if (k > 0 && i > 0 && s[i-1][k-1] == '#') out++;
                if (i > 0 && k < w-1 && s[i-1][k+1] == '#') out++;
                if (i < h-1 && k > 0 && s[i+1][k-1] == '#') out++;
                if (i < h-1 && k < w-1 && s[i+1][k+1] == '#') out++;
                cout << out;
            }
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        String[] groups = {
            ",1,3,5,7,8,10,12,",
            ",4,6,9,11,",
            ",2,",
        };

        int x = sc.nextInt();
        int y = sc.nextInt();

        int g1;
        for (g1 = 0; g1 < groups.length; ++g1) {
            if (groups[g1].indexOf("," + x + ",") >= 0) {
                break;
            }
        }
        int g2;
        for (g2 = 0; g2 < groups.length; ++g2) {
            if (groups[g2].indexOf("," + y + ",") >= 0) {
                break;
            }
        }
        _out.println((g1 == g2 ? "Yes" : "No"));
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 23252
INF = 2000000000
def merge(a, left, mid, right)
  cnt = 0
  n1 = mid - left
  n2 = right - mid
  l = []
  r = []
  (n1).times do |i|
    l[i] = a[left + i]
  end
  (n2).times do |i|
    r[i] = a[mid + i]
  end
  l[n1] = r[n2] = INF
  i = 0
  j = 0
  for k in left...right do
    if l[i] <= r[j]
      a[k] = l[i]
      i = i + 1
    else
      a[k] = r[j]
      j = j + 1
      cnt += n1 - i
    end
  end
  return cnt
end

def mergeSort(a, left, right)
  if left + 1 < right
    mid = (left + right) / 2
    v1 = mergeSort(a, left, mid)
    v2 = mergeSort(a, mid, right)
    v3 = merge(a, left, mid, right)
    return v1 + v2 + v3
  else
    return 0
  end
end

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
puts mergeSort(a, 0, a.size())

Measured memory_bytes: 37616
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin >> n;
    ll ans = 1e12;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            ans = min(ans, i + (n / i));
        }
    }
    cout << ans - 2;

    return 0;
}


Measured memory_bytes: 3648
#--Papers, Please

N = int(input())
List = [int(i) for i in input().split()]

for i in range(N):
  xx = int(List[i])
  if xx % 2 == 0:
    if (xx % 3 == 0 or xx % 5 == 0):
      pass
    else:
      print ("DENIED")
      exit()
  else:
    pass

print("APPROVED")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N; cin >> N;
    int ans = 0;
    for(int i=1; i<=N; i++){
        int d = 0;
        int c = i;
        while(c){
            d++;
            c/=10;
        }
        if(d%2) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var r = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var H = r[0];
            var W = r[1];
            List<string> lineInfo = new List<string>();
            for (int i = 0; i < H; i++)
            {
                lineInfo.Add(Console.ReadLine());
            }

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (lineInfo[i][j] == '#')
                    {
                        if (!Check(lineInfo,i,j))
                        {
                            Console.WriteLine("No");
                            return;
                        }
                    }
                }
            }
            Console.WriteLine("Yes");
        }

        public static bool Check(List<string> info, int h, int w)
        {
            return Left(info, h, w) || Right(info, h, w) || Up(info, h, w) || Down(info, h, w);
        }
        public static bool Left(List<string> info,int h, int w)
        {
            if (w == 0)
            {
                return false;
            }

            if (info[h][w] == info[h][w - 1])
            {
                return true;
            }
            return false;
        }
        public static bool Right(List<string> info, int h, int w)
        {
            if (w == info[0].Length - 1)
            {
                return false;
            }

            if (info[h][w] == info[h][w + 1])
            {
                return true;
            }
            return false;
        }
        public static bool Up(List<string> info, int h,int w)
        {
            if (h == 0)
            {
                return false;
            }

            if (info[h][w] == info[h - 1][w])
            {
                return true;
            }
            return false;
        }
        public static bool Down(List<string> info, int h , int w)
        {
            if (h == info.Count())
            {
                return false;
            }

            if (info[h][w] == info[h + 1][w])
            {
                return true;
            }
            return false;
        }
    }
}

Measured memory_bytes: 13268
import scala.annotation.tailrec
import scala.collection.mutable
import scala.io.StdIn._
object Main extends App {
  loop
  def loop: Unit = {
    val Array(w, h) = readLine.trim.split(' ').map(_.toInt)
    if (w == 0) return
    val state = Array.tabulate(h){_ ⇒ readLine.trim.toCharArray}
    val start = (0 until h).flatMap(y ⇒ (0 until w).find(x ⇒ state(y)(x) == '@').map(x ⇒ Point(x, y))).head
    val queue = mutable.Queue[Point](start)
    var count = 1
    while(queue.nonEmpty){
      val p = queue.dequeue()
      for (n ← p.neighbor if (0 until h).contains(n.y) && (0 until w).contains(n.x) && state(n.y)(n.x) == '.') {
        state(n.y)(n.x) = '#'
        queue.enqueue(n)
        count += 1
      }
    }
    println(count)
    loop
  }
  case class Point(x: Int, y: Int) {
    def neighbor = Array(Point(x + 1, y), Point(x - 1, y), Point(x, y + 1), Point(x, y - 1))
  }
}


Measured memory_bytes: 58448