akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long ll;
typedef int keytype;

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

/* a[0], ..., a[n-1] の数の最大公約数 */
int ngcd(int n, int a[])
{
    int i, d;

    d = a[0];
    for (i = 1; i < n && d != 1; i++)
        d = gcd(a[i], d);
    return d;
}

void quicksort(keytype a[], int first, int last)
{
    int i, j;
    keytype x, t;

    x = a[(first + last) / 2];
    i = first;  j = last;
    for ( ; ; ) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i >= j) break;
        t = a[i];  a[i] = a[j];  a[j] = t;
        i++;  j--;
    }
    if (first  < i - 1) quicksort(a, first , i - 1);
    if (j + 1 < last) quicksort(a, j + 1, last);
}

int is_prime(int x){
    if(x <= 1) return 0;
    for(int i = 2; i * i <= x; i++){
        if(x % i == 0) return 0;
    }
    return 1;
}

int is_substr(char s[], char t[], int i){
    int flag = 1;

    if(s[i] == '\0') flag = 0;

    for(int j = 0; j < strlen(t); ++j, ++i){
        if(s[i] != t[j]){
            flag = 0;
            break;
        }
    }
    return flag;
}

// factor list, number of factors, natural number
void factorize(int ftr[], int *num, int n){
    int a = 2, cnt = 0;

    while(n >= a){
        if(n % a == 0){
            n = n / a;
            ftr[cnt++] = a;
        }else{
            a++;
        }
    }
    *num = cnt;
}

//#define N 5
//int p[N + 1];
int nextperm(int p[], int N)  /* 辞書式順序で次の順列 */
{
    int i, j, t;

    i = N - 1;
    p[0] = 0;  /* 番人 */
    while (p[i] >= p[i + 1]) i--;
    if (i == 0) return 0;  /* 完了 */
    j = N;
    while (p[i] >= p[j]) j--;
    t = p[i];  p[i] = p[j];  p[j] = t;
    i++;  j = N;
    while (i < j) {
        t = p[i];  p[i] = p[j];  p[j] = t;  i++;  j--;
    }
    return 1;  /* 未了 */
}

void comb(int size1, int size2, int v[size1][size2]){
  for(int i = 0; i < size1; i++){
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for(int k = 1; k < size1; k++){
    for(int j = 1; j < k; j++){
      v[k][j] = (v[k-1][j-1] + v[k-1][j]);
    }
  }
}

int abs_val(int a, int b){
    if(a > b) return a - b;
    else return b - a;
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

const int inf = 1012345678;
int main(){
    ll l, r;

    scanf("%lld %lld", &l, &r);

    int min = 2018;
    if((r - l) >= 2019){
        min = 0;
    }else{
        for(ll i = l; i < r; ++i){
            for(ll j = i + 1; j <= r; ++j){
                if(((i * j) % 2019) < min){
                    min = (i * j) % 2019;
                }
            }
        }
    }

    printf("%d\n", min);

    return 0;
}


Measured memory_bytes: 1704
N, M, X = map(int, input().split())
C = []
A = []
for i in range(N):
  c = list(map(int, input().split()))
  C.append(c[0])
  A.append(c[1:])
ans = sum(C) + 1
for n in range(1 << N):
  p = [0 for j in range(M)]
  q = 0
  for i in range(N):
    t = (n >> i) & 1
    q += t * C[i]
    for j in range(M):
      p[j] += t * A[i][j]
  f = 0
  for j in range(M):
    if p[j] < X:
      f = 1
      break
  if f == 0:
    ans = min(ans, q)
if ans > sum(C):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  multiset<int> s;
  rep(i,n) {
    int a;
    scanf("%d",&a);
    s.insert(a);
  }
  int ans = 0;
  while (sz(s)) {
    auto it = s.end();
    --it;
    int a = *it;
    s.erase(it);
    int b = 1;
    while (b <= a) b <<= 1;
    b -= a;
    auto jt = s.find(b);
    if (jt != s.end()) {
      ++ans;
      s.erase(jt);
    }
  }
  cout<<ans<<endl;

  return 0;
}






















Measured memory_bytes: 9600
#include "bits/stdc++.h"
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define all(V) (V).begin(), (V).end() 
using namespace std;
typedef long long ll;

int main() {fio;
	ll h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout <<  (h2 - h1) * 60 + m2 - m1 - k;

    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

int main() {
  int N;
  cin >> N;
  vector<int> H;
  rep(i, N) {
	int h;
	cin >> h;
	H.push_back(h);
  }
  bool ok = true;
  rep2(i, 1, N) {
	if(H[i-1] > H[i]) {
	  if(H[i-1] > H[i] + 1) {
		ok = false;
		break;
	  }
	  H[i]++;
	} 
  }
  cout << (ok ? "Yes" : "No") << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);
 
	int k, x;
	cin>>k>>x;
	if(k*500 >= x){
		cout<<"Yes"<<'\n';
	}else{
		cout<<"No"<<'\n';
	}
 
	return 0;
}

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

int main(){
    int n; cin>>n;
    char s[100+1];
    char t[100+1];
    vector<char> ans;
    cin>>s>>t;

    for(int i=0; i<n; i++){
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }
    for(int i=0; i<ans.size(); i++)cout<<ans[i];
    cout<<endl;
}

Measured memory_bytes: 256
M=10**9+7
def comb(n,k):
  a=b=1
  for i in range(1,k+1):
    a=a*n%M
    b=b*i%M
    n-=1
  return a*pow(b,M-2,M)
n,a,b=map(int,input().split())
print((pow(2,n,M)-1-comb(n,a)-comb(n,b))%M)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
	string S;
	cin >> S;
	int count = 700;
	for (int i = 0; i < 3; ++i)
	{
		if(S[i] == 'o')count += 100;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
 
		try (Scanner scan = new Scanner(System.in)) {
 
			long x = scan.nextLong();
			long y = scan.nextLong();
 
			if(y > x) {
				long swap = x;
				x = y;
				y = swap;
			}
			
			Long s = 2L;
			long gcd = gcd(x, y);
       
			int ans = 1;
			while (s <= Math.sqrt(gcd)) {
				if ( gcd % s == 0 ) ans++;
				
				while ( gcd % s == 0 ) gcd /= s;
					s++;
				
			}
			if ( gcd != 1 ) ans++;
			System.out.println(ans);
		}
	}
  
  	private static long gcd(long x, long y) {
  		if(y == 0) return x;
     	return gcd(y, x%y);     
    }
}

Measured memory_bytes: 37332
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for ai in range(a + 1):
    for bi in range(b + 1):
        for ci in range(c + 1):
            if ai * 500 + bi * 100 + ci * 50 == x:
                ans += 1

print(ans)


Measured memory_bytes: 39536
#include <vector>
#include <iostream>
#include <algorithm>

#define ARC(i, a, b) for(ull i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(ull i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)

using ull = unsigned long long;

int main(){
	ull n, k, a[110000], sum = 0, b[45] = {}, keta, ans = 0;
	std::cin >> n >> k;
	RC(i, n){
		std::cin >> a[i];
		sum += a[i];
	}
	for(ull i = 0, j = 1; j <= k || (keta = i) && 0; ++i, (j <<= 1)) RC(k, n) b[i] += a[k] ^ j;

	if(!k){
		std::cout << sum << std::endl;
		return 0;
	}

	while(k){
		ull tmp = sum;
		RC(i, keta) if((k >> i) & 1 && b[i] > sum) tmp += b[i] - sum;

	//	std::cout << k << ' ' << tmp << std::endl;

		if(tmp > ans) ans = tmp;


		ull i = 1, j;
		while(k & i) i <<= 1;
		if(i > k) break;
		else k -= i;
	}

	std::cout << ans << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>  
#define sl(x) scanf("%lld",&x)  
#define pl(x) printf("%lld\n",x)   
using namespace std;  
const int N = 1e6+5;  
const int mod = 998244353;  
const int INF = 0x3f3f3f3f;  
typedef long long ll;  
ll inv(ll b)  
{  
    if(b == 1)  
    return 1;  
    return (mod-mod/b)*inv(mod%b)%mod;  
}  
ll fac[N];  
ll C(ll n,ll m)  
{  
    ll t = (fac[m]*fac[n-m])%mod;  
    return (fac[n]*inv(t))%mod;  
}  
ll ans[N][2];  
int main()  
{  
    ll n,i,a,b,k;  
    fac[0] = 1;  
    fac[1] = 1;  
    for(i = 2;i <= 3e5+5;i++)  
    fac[i] = (fac[i-1]*i)%mod;  
    sl(n);sl(a);sl(b);sl(k);  
    ll cnt = 0;  
    for(i = 0;i <= n;i++)  
    {  
        if(k-(i*a) >= 0 && (k-a*i)%b == 0 && (k-a*i)/b <= n)  
        {  
            ans[cnt][0] = i;  
            ans[cnt++][1] = (k-a*i)/b;  
        }  
    }  
    ll res=0;  
    for(i = 0;i < cnt;i++)  
    {  
        res = (res+C(n,ans[i][0])*C(n,ans[i][1])%mod)%mod;  
    }  
    pl(res);  
}  

Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iostream>
#include <deque>
#include <math.h>
#include <cstdio>
#include <set>
#include <iomanip>
typedef  long long ll;
using namespace std;

int main(void) {
	int n, k;
	cin >> n >> k;
	vector<int> x(n);
	for (int i = 0; i < n; i++) cin >> x[i];
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += 2 * min(x[i], abs(k - x[i]));
	}
	cout<< ans << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args)
    {
        Scanner scanner = new Scanner(System.in);
        int X = scanner.nextInt();
        int Y = scanner.nextInt();
        int Z = scanner.nextInt();
        System.out.println(Z + " " + X + " " + Y);
    }
}


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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first

int k;
ll s=0;

int main(){
  cin >> k;
  for(int i=1;i<=k;++i){
    for(int j=1;j<=k;++j){
        for(int l=1;l<=k;++l){
            s+=__gcd(__gcd(i,j),l);
        }
    }
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <array>
#include <vector>
#include <algorithm>
#include <string>

struct node
{
  int val;
  node* parent;
};

struct DisjointSet
{
  std::vector<int> rank, p;
  DisjointSet () = default;
  DisjointSet(const int n)
  {
    rank.resize(n, 0);
    p.resize(n, 0);
    for (int i=0; i<n; ++i)
      makeSet(i);
  }

  void makeSet(int i)
  {
    p[i] = i;
    rank[i] = 0;
  }

  // int findSet(int x)
  // {
  //   auto y = x;
  //   while (y != p[y])
  //     {
  //       y = p[y];
  //     }
  //   while (x != p[x])
  //     {
  //       x = p[x];
  //       p[x] = y;
  //     }
  //   return y;
  // }

  int findSet(int x)
  {
    if (x != p[x])
      {
        p[x] = findSet(p[x]);
      }
    return p[x];
  }
  bool same (int x, int y)
  {
    return findSet(x) == findSet(y);
  }

  void unite (int x, int y)
  {
    auto rep_x = findSet(x), rep_y = findSet(y);
    if (rank[rep_x] < rank[rep_y])
      p[rep_x] = rep_y;
    else if (rank[rep_x] > rank[rep_y])
      p[rep_y] = rep_x;
    else
      {
        p[rep_x] = rep_y;
        rank[rep_y]++;
      }
  }

};

int main ()
{
  const int nmax = 10005;
  int n, q;
  std::cin >> n >> q;
  DisjointSet ds(n);

  int x, y, com;
  for (int i=0; i<q; ++i)
    {
      std::cin >> com >> x >> y;

      if (com == 0)
        {
          ds.unite(x, y);
        }
      else if (com == 1)
        {
          if (ds.same(x, y))
            std::cout << 1 << std::endl;
          else
            std::cout << 0 << std::endl;
        }
    }
}




Measured memory_bytes: 3184
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define c second
#define w first
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
// #define debug
// #define TRACE(x)

using namespace std;
using pii = pair<int, int>;

typedef long long llint;

const int MAXN = 200010;
const int MOD = 1e9 + 7;

llint mpow(int a, int m) {
  if (m == 0) return 1;
  if (!(m & 1)) {
    llint t = mpow(a, m / 2);
    return t * t % MOD;
  }
  return mpow(a, m - 1) * a % MOD;
}

int n, x, y, f[MAXN], inv[MAXN], bio[MAXN], best[MAXN];
pii p[MAXN];
vector<int> cols, e[MAXN];
llint sol = 1;

void dfs(int i) {
  cols.push_back(p[i].c);
  bio[i] = 1;
  
  for (int j : e[i])
    if (!bio[j])
      dfs(j);
}

int main(void) {
  memset(best, -1, sizeof(best));
  f[0] = inv[0] = 1;
  FOR(i, 1, MAXN) {
    f[i] = (llint)f[i - 1] * i % MOD;
    inv[i] = mpow(f[i], MOD - 2);
  }
  
  scanf("%d %d %d",&n,&x,&y);
  REP(i, n) 
    scanf("%d %d",&p[i].c,&p[i].w);
    
  sort(p, p + n);
  int prv = -1;

  REP(i, n)
    if (best[p[i].c] == -1)
      best[p[i].c] = i;
    else if (p[best[p[i].c]].w + p[i].w <= x) {
      e[best[p[i].c]].push_back(i);
      e[i].push_back(best[p[i].c]);
    }


  REP(i, n)
    if (prv == -1 || p[i].c != p[prv].c) {
      REP(j, n) 
	if ((p[i].c == p[j].c && p[i].w + p[j].w <= x) ||
	    (p[i].c != p[j].c && p[i].w + p[j].w <= y)) {
	  e[i].push_back(j);
	  e[j].push_back(i);
	}
      if (prv != -1) break;
      prv = i;
    }

  REP(i, n) {
    if (bio[i]) continue;
    cols.clear();
    dfs(i);
    sort(cols.begin(), cols.end());

    int k = (int)cols.size();

    sol = sol * f[k] % MOD;
    int curr = 0;
    REP(j, k) {
      ++curr;
      if (j == k-1 || cols[j] != cols[j+1]) {
	sol = sol * inv[curr] % MOD;
	curr = 0;
      }
    }
  }

  cout << sol << endl;
  
  return 0;
}


Measured memory_bytes: 18120
//longest directed path

#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<iomanip>
#define ll long long
using namespace std;
class graph
{
ll n;
ll m;
vector< vector<ll> > adj;
vector<ll> dp;
public:
	graph(ll in,ll im)
	{
		n=in;
		m=im;
		adj.resize(n+1);
		dp.resize(n+1,0);	
	}
	
	
	void addEdge(ll x,ll y)
	{
		adj[x].push_back(y);
	}
	
	
	ll dfs(ll vert,vector<bool>& visited)
	{
		ll lp=0;
		for(auto it:adj[vert])
		{
			if(visited[it])
			{
				lp=max(lp,dp[it]+1);
			}
			else
			{
				ll temp=dfs(it,visited)+1;
				lp=max(lp,temp);
			}
		}
		visited[vert]=true;
		dp[vert]=lp;
		return dp[vert];
	}
	
	void disp()
	{
		for(auto it:dp)
		{
			cout<<it<<" ";
		}
	}
	
	ll f_max()
	{
		ll max=INT_MIN;
		for(ll i=1;i<=n;i++)
		{
			if(dp[i]>max)
			max=dp[i];
		}
		return max;	
	}	
};
int main()
{
	ll n,m,x,y;
	cin>>n>>m;
	graph g(n,m);
	vector<bool> visited(n+1,false);
	for(ll i=0;i<m;i++)
	{
		cin>>x>>y;
		g.addEdge(x,y);
	}
	for(ll i=1;i<=n;i++)
	{
		if(!visited[i])
		g.dfs(i,visited);
	}
	cout<<g.f_max();
	return 0;
}


Measured memory_bytes: 8832
# GRL_2_A: Minimum Spanning Tree

from collections import namedtuple
from heapq import heappop, heappush


class UnionFind:
    def __init__(self, n):
        self.nodes = [i for i in range(n)]
        self.sizes = [1 for _ in range(n)]

    def union(self, p, q):
        rp = self.root(p)
        rq = self.root(q)
        if self.sizes[rp] > self.sizes[rq]:
            self.nodes[rq] = rp
            self.sizes[rp] += self.sizes[rq]
        else:
            self.nodes[rp] = rq
            self.sizes[rq] += self.sizes[rp]

    def connected(self, p, q):
        return self.root(p) == self.root(q)

    def root(self, p):
        while p != self.nodes[p]:
            self.nodes[p] = self.nodes[self.nodes[p]]
            p = self.nodes[p]

        return p


WEIGHT_MAX = 10 ** 10
WeightedEdge = namedtuple('WeightedEdge', ('src', 'dest', 'weight'))


class Digraph:
    def __init__(self, v):
        self.v = v
        self._edges = [[] for _ in range(v)]

    def add(self, edge):
        self._edges[edge.src].append(edge)

    def adj(self, v):
        return self._edges[v]

    def edges(self):
        for es in self._edges:
            for e in es:
                yield e


def mst_kruskal(graph):
    edges = []
    for e in graph.edges():
        heappush(edges, (e.weight, e))

    uf = UnionFind(graph.v)
    conn = 0
    weight = 0
    while conn < graph.v-1:
        w, e = heappop(edges)
        if not uf.connected(e.src, e.dest):
            uf.union(e.src, e.dest)
            conn += 1
            weight += w

    return weight


def run():
    v, e = [int(i) for i in input().split()]
    graph = Digraph(v)

    for _ in range(e):
        s, t, w = [int(i) for i in input().split()]
        graph.add(WeightedEdge(s, t, w))

    print(mst_kruskal(graph))


if __name__ == '__main__':
    run()



Measured memory_bytes: 32672
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
using namespace std;

vector<pair<double, double>> v;

int n;

void koch() {
	double sr1=0.0, sr2=0.0, sl1=0.0, sl2=0.0;
	double ur=0.0, ul=0.0;
	vector<pair<double, double>> v2;
	v2 = v;
	int num = 0;
	double dist = 0.0;
	double dist_x = 0.0, dist_y = 0.0;
	int mc, ms;
	for(int i = 0; i < v.size()-1; i++) {
		double p1 = (v[i+1].first-v[i].first);
		double p2 = (v[i+1].second-v[i].second);
		int mc = 1;
		int ms = 1;

		sr1 = (v[i].first*2.0+v[i+1].first*1.0)/3.0;
		sl1 = (v[i].second*2.0+v[i+1].second*1.0)/3.0;
		sr2 = (v[i].first*1.0+v[i+1].first*2.0)/3.0;
		sl2 = (v[i].second*1.0+v[i+1].second*2.0)/3.0;
		dist_x = sr2-sr1;
		dist_y = sl2-sl1;
		//dist = sqrt((sr2-sr1)*(sr2-sr1)+(sl2-sl1)*(sl2-sl1));
		ur = sr1+dist_x*cos(M_PI/3) - dist_y*sin(M_PI/3);
		ul = sl1+dist_x*sin(M_PI/3) + dist_y*cos(M_PI/3);

		v2.insert(v2.begin()+num+1, make_pair(sr1, sl1));
		v2.insert(v2.begin()+num+2, make_pair(ur, ul));
		v2.insert(v2.begin()+num+3, make_pair(sr2, sl2));
		num+=4;

	}

	v = v2;

}


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

	v.push_back(make_pair(0.0,0.0));
	v.push_back(make_pair(100.0, 0.0));
	for(int i = 0; i < n; i++) {
		koch();
	}

	for(int i = 0; i < v.size(); i++) {
		printf("%.10lf %.10lf\n", v[i].first, v[i].second);
	}

	return 0;
}



Measured memory_bytes: 3260
N, L = map(int, input().split())
taste = []
taste_abs = []
for i in range(1,N+1):
    taste.append(L + i - 1)
    taste_abs.append(abs(L + i - 1))

if sum(taste) >= 0:
    print(sum(taste) - min(taste_abs))
else:
    print(sum(taste) + min(taste_abs))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep2(i, x, n) for (int i = x; i < ( n ); ++i )
#define rep(i,n) for (int i = 0; i < ( n ); ++i )
using namespace std;
using ll = long long;
using ull = unsigned long long;
using p  = pair<int, int>;
using vec_int = vector<int>;
using vec_str = vector<string>;
#define INF (1<<29)
ll ans = 0;

int main()
{
    int N = 0;
    string S;

	cin >> N;
	cin >> S;

    int rgb_count[3] = {0, 0, 0};
    vec_int rgb(N);
    rep(i,N) {
        char s = S[i];
        if(s == 'R') rgb[i] = 0;
      	else if(s == 'G') rgb[i] = 1;
        else if(s == 'B') rgb[i] = 2;
    }
  
  	vec_int cnt(3);
	rep(i, N) cnt[rgb[i]]++;
 	ans = 1;
	rep(i, 3) ans *= cnt[i];

    rep(j, N) rep(i, j) {
        int k = j + (j-i);
        if(k< N) {
            if(rgb[i] == rgb[j]) continue;
            if(rgb[i] == rgb[k]) continue;
            if(rgb[k] == rgb[j]) continue;
            ans--;
        }
    }

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


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

using namespace std;

int main(int argc, char *argv[]) {
    int64_t X;
    cin >> X;
    int64_t t = X / 500;
    X = X - (t * 500);
    int64_t f = X / 5;
    int64_t ans = (1000 * t) + (5 * f); 
    cout << ans << endl;
    return 0;
}


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

#define ll long long int
#define pii pair<int,int>

const ll sz=1e5+100;
ll parent[sz], ran[sz];
ll ans=0;

void init(ll n)
{
    for(ll i=0;i<=n;i++) parent[i]=i, ran[i]=1;
}

ll Find(ll x)
{
    if(parent[x]==x) return x;
    else return (parent[x]=Find(parent[x]));
}

void Union(ll a,ll b)
{
    ll x=Find(a);
    ll y=Find(b);
    if(x==y) return ;
    ll p=ran[x], q=ran[y];
    ans-=(p*q);

    if(ran[x]>ran[y]){
       ran[x]+=ran[y];
       parent[y]=x;
    }
    else{
        ran[y]+=ran[x];
        parent[x]=y;
    }
}

int main()
{
    ll n,m,i,j,k;
    cin>>n>>m;

    pii ara[m];
    ans=(n*(n-1))/2ll;

    for(i=0;i<m;i++) cin>>ara[i].first>>ara[i].second;
    ll mem[m];

    init(n);
    for(i=m-1;i>=0;i--){
        mem[i]=ans;
        Union(ara[i].first, ara[i].second);
    }

    for(i=0;i<m;i++) cout<<mem[i]<<'\n';
}


Measured memory_bytes: 6676
#include <bits/stdc++.h>
#include<iomanip>
// #define int long long
#define ll long long
#define FOR(P,Q) for(P=0;P<Q;P++)
#define FORR(P,Q) for(P=1;P<=Q;P++)
#define FORS(i,s) for(i=0;s[i]!='\0';i++)
#define pb push_back
using namespace std;

/*std::cout << std::fixed;
    std::cout << std::setprecision(14);
    std::cout << d;
*/
    
int main()
{
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  #ifndef ONLINE_JUDGE
	freopen("error.txt","w",stderr);
	#endif

	int n;
  int i,a[22],c=0;
  cin>>n;
  FORR(i,n){
    cin>>a[i];
  }
	for(i=2;i<n;i++){
    int M=max(a[i-1],max(a[i],a[i+1]));
    int m=min(a[i-1],min(a[i],a[i+1]));
    if(a[i]!=M&&a[i]!=m)
      {c++;
        cerr<<a[i]<<" ";
      }
  }
  cout<<c;

return 0;
}

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

count = 0
for i in range(N):
  if A[i] < B[i]:
    count += A[i]
    B[i] -= A[i]
    if A[i+1] < B[i]:
      count += A[i+1]
      A[i+1] = 0
    else:
      count += B[i]
      A[i+1] -= B[i]
  else:
    count += B[i]

print(count)

Measured memory_bytes: 19156
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(int, H, W);
    auto mat = makeV(0, H, W);

    rep(i, 0, H) rep(j, 0, W) read(mat[i][j]);

    vector<pair<pii, pii>> ans;
    ans.reserve(H * W);

    for (int i = 0; i < H; ++i) {
        if (i & 1) {
            repr(j, W-1, 1) {
                if (mat[i][j] & 1) {
                    ++mat[i][j-1];
                    ans.emplace_back(pii(i, j), pii(i, j-1));
                }
            }
            if (i + 1 < H && (mat[i][0] & 1)) {
                ++mat[i+1][0];
                ans.emplace_back(pii(i, 0), pii(i + 1, 0));
            }
        } else {
            rep(j, 0, W-1) {
                if (mat[i][j] & 1) {
                    ++mat[i][j+1];
                    ans.emplace_back(pii(i, j), pii(i, j+1));
                }
            }
            if (i + 1 < H && (mat[i][W-1] & 1)) {
                ++mat[i+1][W-1];
                ans.emplace_back(pii(i, W-1), pii(i + 1, W-1));
            }
        }
    }

    print(ans.size());
    for (const auto &e : ans) {
        auto s = e.first;
        auto t = e.second;
        print(s.first + 1, s.second + 1, t.first + 1, t.second + 1);
    }

    return 0;
}


Measured memory_bytes: 8832
from sys import stdin
input = stdin.readline

def cumsum(xs):
    result = [xs[0]]
    for x in xs[1:]:
        result.append(result[-1] + x)
    return result

n = int(input().rstrip())
a = list(map(int, input().rstrip().split()))

ans = 0
MOD = 1000000007
s = cumsum(list(reversed(a)))

for i in range(n-1):
    ans += a[i] * s[n-2-i]

print(ans % MOD)


Measured memory_bytes: 31380
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

typedef pair<int, pii> pip;
 
 
 
const int INF = 1000000;
const double EPS = 1e-8;
const int mod = 1e9 + 7;

int dp[1000010];
int p[40];

bool isPrime[1000010];
//vi primes;

int main(){
	fill(isPrime+2, isPrime+1000010, true);
	for(int i= 2; i < 1000010; i++){
		if(isPrime[i]){
			//primes.pb(i);
			for(int j = i+i; j < 1000010; j+=i){
				isPrime[j]=false;
			}
		}
	}

	int n, x;
	while(cin>>n>>x){
		if(n == 0 && x == 0){
			break;
		}
		for(int i = 0; i < n; i++){
			cin>>p[i];
		}
		for(int i= 0; i <= x; i++){
			dp[i] = INF;
		}
		dp[0] = 0;
		for(int i = 0; i < n; i++){
			for(int j = p[i]; j <= x; j++){
				dp[j] = min(dp[j], dp[j-p[i]]+1);
			}
		}
		bool f = false;
		for(int i = x; i > 0; i--){
			if(dp[i]!=INF && isPrime[i]){
				cout<<i<<endl;
				f=true;
				break;
			}
		}
		if(!f){
			cout<<"NA"<<endl;
		}
	}
}

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

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

  int sum=0;
  int m=N;
  while(m > 0){
    sum += m%10;
    m /= 10;
  }

  if(N%sum==0) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

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


using namespace std;
using vi=vector<int>;


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n);

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

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

	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <cmath>
using namespace std;


bool Get_triangle(int a,int b,int c){
    if(pow(a,2)+pow(b,2) == pow(c,2))
        return true;
    else
        return false;
}


string Judge_triangle(int a,int b,int c){
    if(Get_triangle(a,b,c) || Get_triangle(b,c,a) ||Get_triangle(c,a,b)){
        return "YES";
    }
    else{
        return "NO";
    }
}

bool Judge_line(int x){
    if(1<=x || x<=1000 || ceil(x) == floor(x))
        return true;
    else
        return false;
}

int main(){
  int N;
  int a,b,c;
  int n=0;
    
    while(1){

  cin >> N;
    
        if(N > 1000 || ceil(N) != floor(N)){
            
        }
    else
        break;
    }
    
    string x[N];

while(N > 0 && cin >> a >> b >> c){
    
    
    while(1){
        if(Judge_line(a) && Judge_line(b) && Judge_line(c)){
            x[n] = Judge_triangle(a,b,c);
            N--;
            n++;
            break;
        }
        
        else{
            break;
        }
  }
}
    for(int i = 0;i < n;i++)
        cout << x[i] << endl;
    
  return 0;
}



Measured memory_bytes: 3124
x,n = map(int,input().split())
if n == 0:
    print(x)
    exit()
P = [*map(int,input().split())]
ans = 100 + 100 # inf = x + d + 1
for d in range(100): # [0,100)
    now_diff = abs(ans - x)
    min_x, max_x = x - d, x + d
    if min_x not in P:
        if now_diff > abs(min_x - x): ans = min_x
    elif max_x not in P:
        if now_diff > abs(max_x - x): ans = max_x
print(ans)


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

#define INF (1<<31)-1
#define LINF (1LL<<63)-1LL
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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);}

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

int main(){

    bool flag=false;
    ll ans=LINF,sum=0;

    int n,m,x;
    cin>>n>>m>>x;

    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));

    rep(i,n){
        cin>>c[i];

        rep(j,m){
            cin>>a[i][j];
        }
    }

    rep(i, 1<<n){
        vector<ll> ustd(m,0);
        int cost = 0;

        int tmp = i;
        rep(j,n){
            if(tmp%2==0){
                cost += c[j];
                rep(k,m){
                    ustd[k] += a[j][k];
                }
            }
            tmp/=2;
        }

        bool ok = true;
        rep(j,m){
            if(ustd[j] < x)ok = false;
        }
        if(ok)chmin(ans,cost);
    }

    if(ans == LINF)ans = -1;

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int N = scan.nextInt();
        scan.nextLine();

        int out = 0;

        for (int i=0; i < N; i++){
            int a = scan.nextInt();
            if ((i+1) %2 == 1 && a % 2 == 1){
                out ++;
            }
        }
        System.out.println(out);
    }
}


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

int main(int argc, char const *argv[]) {
  int n, m, a, b;
  cin >> n >> m;
  vector <int> flag(100, 0);
  for (int i = 0;i < m;i++) {
    cin >> a >> b;
    flag.at(a-1)++;
    flag.at(b-1)++;
  }
  for (int i = 0;i < n;i++) {
    cout << flag.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n, l = map(int, input().split())
apple = [i for i in range(l, l+n)]
total = sum(apple)

ans = float('inf')
ans2 = 0
for i in range(n):
    tmp = total - apple[i]
    if ans > abs(total - tmp):
        ans = abs(total - tmp)
        ans2 = tmp

print(ans2)

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

int n, p[10], q[10], a[10];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) scanf("%d", &p[i]);
    for (int i = 0; i < n; ++i) scanf("%d", &q[i]);
    for (int i = 0; i < n; ++i) a[i] = i + 1;
    int b = 0, c = 0, cnt = 1;
    do {
        int f1 = 1, f2 = 1;
        for (int i = 0; i < n; ++i) if (a[i] != p[i]) f1 = 0; if (f1) b = cnt;
        for (int i = 0; i < n; ++i) if (a[i] != q[i]) f2 = 0; if (f2) c = cnt;
        ++cnt;
    } while (std ::next_permutation(a, a + n));
    printf("%d\n", abs(b - c));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    vll A(N);
    rep(i,N) cin >> A[i];

    ll Xor = 0;
    for(ll i = 2; i < N; i++) Xor ^= A[i];
    ll x = A[0], y = A[1];

    // x^y = x + y + 2*(x&y)
    ll And = x + y - Xor;
    // パリティ的に無理
    if(And % 2 || And < 0) {
        cout << -1 << endl;
        return 0;
    }
    And /= 2;

    // XorとAnd両方にビット立たせるx,yは存在しない
    if(Xor & And) {
        cout << -1 << endl;
        return 0;
    }

    ll ans = And;
    for(ll b = 1ll<<40; b >= 1; b /= 2) {
        if(Xor & b && ans + b <= x) ans += b;
    }

    if(ans == 0 || x < ans) {
        cout << -1 << endl;
        return 0;
    }

    cout << x - ans << endl;
}


Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), k = sc.nextInt();
		int ans = 1;

		for (int i = 0; i < n; i++) {
			if (ans * 2 < ans + k) {
				ans *= 2;
			} else {
				ans += k;
			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 19924
import java.awt.Point;
import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;
 
public class Main {
     
    static int M, T, P, R;
    static int[] m, t, p, j;
	
    static void start()
    {
    	int[] ans = new int[T];
        int[] times = new int[T];
        
        
        for(int team = 0;team < T;team++)
        {
        	ans[team] = times[team] = 0;
        	for(int pro = 0;pro < P;pro++)
        	{
        		int sum = 0;
        		for(int i = 0;i < R;i++)
        		{
        			if(t[i] == (team+1) && p[i] == (pro+1))
        			{
        				if(j[i] == 0)
        				{
        					ans[team]++;
        					times[team] += sum + m[i];
        					break;
        				}
        				else
        				{
        					sum += 20;
        				}
        			}
        		}
        	}
        }
        
        int[] order = new int[T];
        for (int i = 0; i < T; i++) {
			order[i] = i+1;
		}
        
        // ひっくり返す
        int[] anss = ans;
        int[] timess = times;
        int[] orderr = order;
        
        ans = new int[T];
        times = new int[T];
        order = new int[T];
        
        for (int i = 0; i < T; i++) {
			ans[i] = anss[T-1-i];
			times[i] = timess[T-1-i];
			order[i] = orderr[T-1-i];
		}
        
        for (int i = T; i > 0; i--) {
			for (int k = 0; k < (i - 1); k++) {
				if ( (ans[k] < ans[k + 1]) || (ans[k] == ans[k + 1] && times[k] > times[k + 1])) {
					int tmp;
					tmp = ans[k];      ans[k] = ans[k+1];    ans[k+1] = tmp;
					tmp = times[k];      times[k] = times[k+1];    times[k+1] = tmp;
					tmp = order[k];      order[k] = order[k+1];    order[k+1] = tmp;
				}
			}
		}
        
        System.out.print(order[0]);
        for (int i = 1; i < T; i++) {
        	if( (ans[i] == ans[i-1]) && (times[i] == times[i-1]) )
        		System.out.print("=");
        	else
        		System.out.print(",");
        	
        	System.out.print(order[i]);
		}
        System.out.print("\n");
    }
     
    public static void main(String[] args)
    {
         
        Scanner sca = new Scanner(System.in);
        
        while(true)
        {
        	M = sca.nextInt();
            T = sca.nextInt();
            P = sca.nextInt();
            R = sca.nextInt();
            
            if(M == 0) break;
            
            m = new int[R];
            t = new int[R];
            p = new int[R];
            j = new int[R];
            
            for(int i = 0;i < R;i++)
            {
            	m[i] = sca.nextInt();
            	t[i] = sca.nextInt();
            	p[i] = sca.nextInt();
            	j[i] = sca.nextInt();
            }
            
            start();
        }
        
    }
}

Measured memory_bytes: 59900
#include <stdio.h>

int main  (){
	int a;
	int A;
	char alpha;

	scanf("%c", &alpha);

	if ( alpha >= 'A' && alpha <= 'Z'){
		printf("A\n");
	}
	else {
		printf("a\n"); 
	}	
	
	return 0;
}

Measured memory_bytes: 1580
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int n;
int a[200005];
int main() {
  scanf("%d", &n);
  int tot = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    tot ^= a[i];
  }
  for (int i = 0; i < n; i++) {
    printf("%d ", (tot ^ a[i]));
  }
  printf("\n");
}

Measured memory_bytes: 4604
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 20

# 3 <= N <= 10^5+1, Nは奇数
N = int(stdin.readline().rstrip())
# 0 <= A <= 10^9
A = [int(x) for x in stdin.readline().rstrip().split()]

# 山xに降った雨量
x = [0] * N

#2 * A_i = x_i + x_i+1

x_1 = 0
tmp = 0
for i in range(N):
    if i % 2 == 0:
        tmp += 2*A[i]
    else:
        tmp -= 2*A[i]

x_1 = tmp // 2

x[0] = x_1

for i in range(1, N):
    x[i] = 2*A[i-1] - x[i-1]

print(*x, sep=" ")

Measured memory_bytes: 89580
#include <bits/stdc++.h>
#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = (int)1e9 + 7;

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

    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, n) cin >> a[i];

    LL ans = 0;
    vector<LL> vec;
    REP(i, n){
        LL sum = a[i];
        vec.pb(a[i]);
        FOR(j, i+1, n){
            sum += a[j];
            vec.pb(sum);
        }
    }

    for(LL i = 60; i >= 0; i--){
        int cnt = 0;
        REP(j, vec.size()){
            if((vec[j] & ans) == ans && vec[j] & (1LL << i)){
                cnt++;
            }
        }
        if(cnt >= k) ans |= (1LL << i);
    }
    cout << ans << endl;
}


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

int N;
int A[1000010];
int flag[1000010];

int gcd(int a, int b) {
   while (b) {
       int t = a;
       a = b;
       b = t%b;
   }
   return a;
}

vector<P> factorize(int n) {
    vector<P> res;
    for (int i=2; i*i<=n; i++) {
        int cnt = 0;
        while (n%i==0) {
            cnt++;
            n /= i;
        }
        if (cnt>0) res.pb(P(i, cnt));
    }
    if (n!=1) res.pb(P(n, 1));
    return res;
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N;
    rep(i, N) cin >> A[i];
    if (N>78500) {
        bool F = true;
        rep(i, N) if (A[i]!=1) F = false;
        if (F) cout << "pairwise coprime" << endl;
        else {
            int G = 0;
            rep(i, N) G = gcd(G, A[i]);
            if (G==1) cout << "setwise coprime" << endl;
            else cout << "not coprime" << endl;
        }
    }
    else {
        bool F = true;
        
        rep(i, N) {
            vector<P> fct = factorize(A[i]);
            //cout << "i" << A[i] << endl;
            rep(j, fct.size()) {
                int p = fct[j].first;
                //cout << p << endl;
                if (flag[p]==1) F = false;
                flag[p] = 1;
            }
        }
        
        if (F) cout << "pairwise coprime" << endl;
        else {
            int G = 0;
            rep(i, N) G = gcd(G, A[i]);
            if (G==1) cout << "setwise coprime" << endl;
            else cout << "not coprime" << endl;
        }
    }
}

Measured memory_bytes: 12044
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long w,h;
	cin>>w>>h;
	if(w==1 || h==1){
		cout<<1<<endl;
	}
	else if(w*h%2==0){
		cout<<w*h/2<<endl;
	}
	else{
		cout<<w*h/2+1<<endl;
	}
  return(0);
}

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

int main(void){

    string S;
    cin >> S;
    map<char,int> mp;
        
    for(int i = 0; i < S.size();i++){
        mp[S[i]]++;
    }
    
    if(S.size()!=26){

        string s;
        for(char i = 'a'; i <= 'z';i++){
            if(mp[i]==0){
                s = {i};
                break;
            }
        }
        
        cout << S << s<< endl;
        
    }else{
        
        if(S == "zyxwvutsrqponmlkjihgfedcba"){
            cout << -1 <<endl;
            return 0;
        }
        
        
        string T = S;
        next_permutation(S.begin(), S.end());
        
        string ans = "";
        for(int i = 0; i < S.size();i++){
            ans += S.substr(i,1);
            if(S[i] > T[i])break;
        }
        cout << ans <<endl;
        
        //priority_queue<char> que; 

        
    }
}

Measured memory_bytes: 3632
n,m,l=map(int,input().split())
abc=[list(map(int,input().split())) for _ in [0]*m]
q=int(input())
st=[list(map(int,input().split())) for _ in [0]*q]
inf=10**12
dist=[[inf]*n for _ in [0]*n]
for i in range(n):
    dist[i][i]=0
for a,b,c in abc:
    dist[a-1][b-1]=c
    dist[b-1][a-1]=c
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j])
inf=10**3
dist2=[[inf]*n for _ in [0]*n]
for i in range(n):
    for j in range(n):
        if dist[i][j]<=l:
            dist2[i][j]=1
for k in range(n):
    for i in range(n):
        for j in range(n):
            dist2[i][j]=min(dist2[i][j],dist2[i][k]+dist2[k][j])
for i in range(n):
    for j in range(n):
        if dist2[i][j]==inf:
            dist2[i][j]=-1
        else:
            dist2[i][j]-=1
for s,t in st:
    print(dist2[s-1][t-1])

Measured memory_bytes: 83928
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

import java.util.*;
import java.util.Collections; // sorting use
import java.io.*;
import static java.lang.System.*;

public class Main{
	public static void main(String[] args){
		int a,b;
		int k;
		Scanner sc = new Scanner(System.in);
		a = sc.nextInt();
		b = sc.nextInt();
		k = (a + b) / 2;

		if(Math.abs(k - a) == Math.abs(k - b))	out.println(k);
		else out.println("IMPOSSIBLE");
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;

typedef long long ll;

int main() {
  string N; cin >> N;
  vector<string>data;
  data.push_back("3");
  data.push_back("5");
  data.push_back("7");
  string tmp[3];
  tmp[0] = "3";
  tmp[1] = "5";
  tmp[2] = "7";  


  for (int i = 0; i < data.size(); i++ ) {
    if ( data.size() >= 100000 ) break;
    for ( int j = 0; j < 3; j++ ) {
      data.push_back(data[i]+tmp[j]);
    }
  }
  
  int cnt = 0;
  bool f7;
  bool f5;
  bool f3;
  bool other;
  vector<string>ans;
  
  for ( int i = 0; i < data.size(); i++ ) {
    f7 = false;
    f5 = false;
    f3 = false;
    other = true;
    if ( data[i].size() < N.length()+1  ) {
      int num = atoi(data[i].c_str());
      int n = atoi(N.c_str());
      if ( num <= n ) {
	//	cout << data[i] << endl;
	for ( int j = 0; j < data[i].size(); j++ ) {
	  if ( data[i][j] == '3' ) f3 = true;
	  else if ( data[i][j] == '5' ) f5 = true;
	  else if ( data[i][j] == '7' ) f7 = true;
	  else other = false;
	}
	if ( f7 && f5 && f3 && other ) {
	  ans.push_back(data[i]);
	  //cout << "ans" << data[i] << endl;
	  cnt++;
	}
      }
    }
  }

  //  for ( int i = 0; i < ans.size(); i++ ) {
  //    cout << ans[i] << endl;
  //  }
  
  cout << cnt << endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN
#define INF         100000000000000000
#define PI          3.1415926535897932384626433832795l



#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)






// struct mycomp {
//     bool operator() (const pair<int,int> &a, const pair<int,int> &b) const{
//         if (a.second-a.first != b.second-b.first)
//         return (a.second-a.first > b.second-b.first);
//         return a.first < b.first;
//     }
// };



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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif

	int n;
	cin>>n;
	int rem = n%10;
	if(rem==2 or rem==4 or rem==5 or rem==7 or rem==9)
	{
		p("hon");

	}
	else if(rem==0 or rem==1 or rem==6 or rem==8)
	{
		p("pon");
		
	}
	else

		p("bon");
	return 0;
}

Measured memory_bytes: 3628