akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
 
#define MAX 2000001
 
int heap[MAX];
int heap_size;
 
int parent(int i){
  return i/2;
}
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}
 
void maxHeapify(int i){
  int l, r, L, tmp;
  l=left(i);
  r=right(i);
  if(l <= heap_size && heap[l] > heap[i]){
   L=l;
  }
  else{
   L = i;
  }
 
  if(r <= heap_size && heap[r] > heap[L]){
   L=r;
  }
  if(L != i){
    tmp=heap[i];
    heap[i] = heap[L];
    heap[L] = tmp;
    maxHeapify(L);
  }
}
 
void buildMaxHeap(){
  int i;
  for(i = heap_size/2; i > 0; i--){
    maxHeapify(i);
  }
}
 
void heapIncreaseKey(int i, int key){
  int tmp;
 
  heap[i] = key;
 
  while(i > 1 && heap[parent(i)] < heap[i]){
    tmp = heap[i];
    heap[i] = heap[parent(i)];
    heap[parent(i)] = tmp;
    i = parent(i);
  }
}
 
void maxHeapInsert(int key){
  heap_size = heap_size + 1;
  heap[heap_size] = INT_MIN;
  heapIncreaseKey(heap_size, key);
}
 
int heapExtractMax(){
  int max = heap[1];
 
  heap[1] = heap[heap_size];
  heap_size = heap_size - 1;
  maxHeapify(1);
 
  return max;
}
 
int main(void){
  int i,key;
  char com[MAX-1];
 
  for(i = 1; i <= MAX-1; i++){
    scanf("%s",com);
    if(com[0] == 'i'){
      scanf("%d",&key);
      maxHeapInsert(key);
    }else if(com[0] == 'e' && com[1] == 'x'){
      printf("%d\n",heapExtractMax());
    }else if(com[0] == 'e' && com[1] == 'heap_size'){
      break;
    }
  }
 
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL A, B, C, K;
  cin >> A >> B >> C >> K;

  LL ans = (K%2==0?A-B:B-A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

H1,M1,H2,M2,K=nm()

smin=60*(H2-H1)+M2-M1

print(smin-K)

Measured memory_bytes: 10404
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  rep(i, N) cin >> A.at(i);

  B.at(0) = 0;
  for (int i = 1; i < N; i++){
    B.at(i) = A.at(i) - A.at(i-1);
  }

  bool flag1 = true, flag2 = true;

  int ans = 0;

  rep(i,N){
    if(B.at(i) > 0) flag2 = false;
    else if (B.at(i) < 0) flag1 = false;

    if (!flag1 && !flag2){
      ans++;
      flag1 = true;
      flag2 = true;
    } 
  }

  ans++;

  cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    vector<int> a;
    for(int i = 0 ; i < s.length() ; i++){
        a.push_back(s[i]-'0');  //配列に各桁の数を格納
    }

    ll ans = 0;

    for(int bit = 0 ; bit < (1 << s.length()-1) ; bit++){
        ll tmp = a[0]; //保留中の数を格納、1桁目を入れておく
        for(int i = 0 ; i < s.length()-1; i++){
            if(bit>>i&1){ //trueなら保留中の数を足す
                ans += tmp;
                tmp = a[i+1];
            }else{ //falseなら10倍して次の数を足す
                tmp = tmp * 10 + a[i+1];
            }
        }
        ans += tmp; //最後まで保留された数を足しておく
    }
    cout << ans;
}




Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	n := getInt()
	W := getInt()

	ws := make([]int, n)
	vs := make([]int, n)
	for i := 0; i < n; i++ {
		ws[i] = getInt()
		vs[i] = getInt()
	}

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, W+1)
	}

	for i := 1; i < n+1; i++ {
		for j := range dp[i-1] {
			if j-ws[i-1] >= 0 {
				dp[i][j] = max(dp[i][j], dp[i-1][j-ws[i-1]]+vs[i-1])
			}
			dp[i][j] = max(dp[i][j], dp[i-1][j])
		}
	}

	fmt.Println(dp[n][W])
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 81792
// 23:22

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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

ll solve(const string S, const ll K) {
    vector<ll> succs;

    char prev = S[0];
    ll count = 1;
    for (int i = 1; i < (int) S.size(); i++) {
        if (S[i] == prev) {
            count++;
        } else {
            succs.push_back(count);
            count = 1;
            prev = S[i];
        }
    }
    succs.push_back(count);

    ll ans = 0;
    if ((int) succs.size() == 1) {
        ans = (succs[0] * K) / 2;
    } else {
        for (int i = 1; i < (int) succs.size() - 1; i++) {
            ans += (succs[i] / 2) * K;
        }
        ans += succs[0] / 2;
        ans += succs[(int) succs.size() - 1] / 2;
        if (S[0] == S[(int) S.size() - 1]) {
            ans += ((succs[0] + succs[(int) succs.size() - 1]) / 2) * (K - 1);
        } else {
            ans += (succs[0] / 2) * (K - 1);
            ans += (succs[(int) succs.size() - 1] / 2) * (K - 1);
        }
    }

    return ans;
}

int main(void) {
    string S;
    cin >> S;

    ll K;
    cin >> K;

    cout << solve(S, K) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int W,a,b;
  cin>>W>>a>>b;
  vector<int>l(2);
  l.at(0)=a;
  l.at(1)=b;
  sort(l.begin(),l.end());
  cout<<max(0,l.at(1)-(l.at(0)+W))<<endl;
}

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

int main() {
  int a;
  cin >> a;
  int b;
  cin >> b;
  if (a%2 != 0 && b%2 != 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}
    

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

#define ASORT(arr, n)          sort(arr,arr+n)
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for (int i=0; i<n; i++)
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI                  acos(-1.0)

using namespace std;

typedef long long              ll;
typedef unsigned long long     ull;
typedef vector<int>            vi;

const double eps = 1e-9;


int main()
{
  fastIO();


/* C T */
ll an , leg;
	cin>>an>>leg;
	if(an*2<=leg && an*4>=leg && leg%2==0)
	{
		cout<<"Yes"<<'\n';
	}
/*	else if(leg%2==0)
	{
		cout<<"Yes"<<'\n';
	} */
	else 
	{
		cout<<"No"<<'\n';
	}
 return 0;
 }


Measured memory_bytes: 3596
#include <stdio.h>
 
int main(void){

  char a[10],b[10],c[10];
  
  scanf("%s %s %s",&a,&b,&c);
  
  a[0] = a[0] - 0x20;
  b[0] = b[0] - 0x20;
  c[0] = c[0] - 0x20;
  
  printf("%c%c%c\n",a[0],b[0],c[0]);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

struct DATA{
  string name;
  int point;
  vector<int> time;
};

bool SortName(const DATA&, const DATA&);

int main(){
  int i, j, n, m, x, max, minpoint;
  vector<int> check;
  vector<int>::iterator iter;
  string answername;
  DATA onedata;
  vector<DATA> data;

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

    for(i=0, max=0, onedata.point=0; i<n; ++i){
      cin >> onedata.name >> m;
      for(j=0; j<m; ++j){
	cin >> x;
	if(max < x) max = x;
	onedata.time.push_back(x);
      }
      data.push_back(onedata);
      onedata.time.clear();
    }

    sort(data.begin(), data.end(), SortName);

    for(i=0; i<=max; ++i){
      for(j=0; j<data.size(); ++j){
	iter = find(data[j].time.begin(), data[j].time.end(), i);
	if(iter != data[j].time.end())
	  check.push_back(j);
      }

      if(check.size() == n){
	for(j=0; j<data.size(); ++j)
	  ++data[j].point;
      }else if(check.size() != 0){
	for(j=0; j<check.size(); ++j)
	  data[check[j]].point += (n + 1 - check.size());
      }
      check.clear();
    }

    for(i=0, minpoint=1000; i<data.size(); ++i){
      if(minpoint > data[i].point){
	answername = data[i].name;
	minpoint = data[i].point;
      }
    }

    cout << minpoint << " " << answername << endl;
    data.clear();
  }

  return 0;
}

bool SortName(const DATA& x, const DATA& y){
  return x.name < y.name;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
#define ALL(a)  (a).begin(),(a).end()
const ll INF = 1e18+18;
const ll MAX = 200000;
const ll MOD = 1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
static const long double pi = 3.141592653589793;



int main(){
    ll N;
    cin>>N;
    ll Ans=0;
    rep(i, N){
        ll l, r;
        cin>>l>>r;
        Ans+=(r-l+1);
    }
    cout<<Ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000007; 
 
 long long  accumulate(long long k){
  long long  times;
  times=k*(k+1)/2;
  return times%mod;
 }
 
int main(){
 long long  n,k,count,count2,ans;
  count=0;
  count2=0;
  vector<long long > num;
  cin>>n>>k;
  for(int i=0;i<n;i++){
    long long  tmp;
    cin>>tmp;
    num.push_back(tmp);
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(num[i]>num[j]){
        count++;
      }else if(num[i]<num[j]){
        count2++;
      }
    }
  }
  ans=(count*accumulate(k)+count2*accumulate(k-1))%mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
a = set(s + t)
ans = 0
for i in a:
  yen = 0
  yen += s.count(i)
  yen -= t.count(i)
  ans = max(ans, yen)
print(ans)

Measured memory_bytes: 3060
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long double lb;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

const int N = 605;

vector <int> adj[N];
double f[N], g[N], _f[N], _g[N], dis[N], ans;
int x[N * N], y[N * N], vis[N];
int n, m;

int main() {
    read(n); read(m);
    for(register int i = 1; i <= m; i++) {
        read(x[i]); read(y[i]);
        adj[x[i]].push_back(y[i]);
    }
    f[1] = 0; g[1] = 1;
    for(register int u = 1; u <= n; u++) {
        for(register int i = 0; i < (int)adj[u].size(); i++) {
            int v = adj[u][i];
            f[v] += f[u] * (1.0 / adj[u].size()) + g[u] * (1.0 / adj[u].size());
            g[v] += g[u] * (1.0 / adj[u].size());
        }
    }
    ans = f[n];
    for(register int i = 1; i <= n; i++) {
        for(register int j = i; j <= n; j++) _f[j] = _g[j] = 0;
        _f[i] = 0; _g[i] = 1;
        for(register int u = i; u <= n; u++) {
            for(register int i = 0; i < (int)adj[u].size(); i++) {
                int v = adj[u][i];
                _f[v] += _f[u] * (1.0 / adj[u].size()) + _g[u] * (1.0 / adj[u].size());
                _g[v] += _g[u] * (1.0 / adj[u].size());
            }       
        }
        dis[i] = _f[n];
    }
    for(register int i = 1; i <= m; i++) {
        if(adj[x[i]].size() == 1) continue;
        double now = f[n] - (dis[y[i]] * g[x[i]] + f[x[i]]) * (1.0 / adj[x[i]].size()) - 1.0 / adj[x[i]].size() / g[x[i]];
        for(register int j = 0; j < (int)adj[x[i]].size(); j++) {
            int v = adj[x[i]][j];
            if(v == y[i]) continue;
            now += (dis[v] * g[x[i]] + f[x[i]]) * (1.0 / (adj[x[i]].size() - 1) - 1.0 / adj[x[i]].size());
            now -= 1.0 / adj[x[i]].size() / g[x[i]];
            now += 1.0 / (adj[x[i]].size() - 1) / g[x[i]];
        }
        ans = min(ans, now);
    }
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define mod 1000000007
#define PI 3.1415926535897932384626433
#define se second
#define fi first
#define pb push_back
#define endl "\n"
#define rep(i,n) for(int i=0;i<=n;i++)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef set < string > sst;
typedef set < long long > sl;
typedef queue < long long > que;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef vector < pair < long long, long long > > vpl;
typedef pair < long long, unsigned long long > pul;

const int MAX = 1000001;

// array to store prime factors
int factor[MAX] = { 0 };

// function to generate all prime factors
// of numbers from 1 to 10^6
void generatePrimeFactors()
{
    factor[1] = 1;

    // Initializes all the positions with their value.
    for (int i = 2; i < MAX; i++)
        factor[i] = i;

    // Initializes all multiples of 2 with 2
    for (int i = 4; i < MAX; i += 2)
        factor[i] = 2;

    // A modified version of Sieve of Eratosthenes to
    // store the smallest prime factor that divides
    // every number.
    for (int i = 3; i * i < MAX; i++) {
        // check if it has no prime factor.
        if (factor[i] == i) {
            // Initializes of j starting from i*i
            for (int j = i * i; j < MAX; j += i) {
                // if it has no prime factor before, then
                // stores the smallest prime divisor
                if (factor[j] == j)
                    factor[j] = i;
            }
        }
    }
}

// function to calculate number of factors
int calculateNoOFactors(int n)
{
    if (n == 1)
        return 1;

    int ans = 1;

    // stores the smallest prime number
    // that divides n
    int dup = factor[n];

    // stores the count of number of times
    // a prime number divides n.
    int c = 1;

    // reduces to the next number after prime
    // factorization of n
    int j = n / factor[n];

    // false when prime factorization is done
    while (j != 1) {
        // if the same prime number is dividing n,
        // then we increase the count
        if (factor[j] == dup)
            c += 1;

        /* if its a new prime factor that is factorizing n,
           then we again set c=1 and change dup to the new
           prime factor, and apply the formula explained
           above. */
        else {
            dup = factor[j];
            ans = ans * (c + 1);
            c = 1;
        }

        // prime factorizes a number
        j = j / factor[j];
    }

    // for the last prime factor
    ans = ans * (c + 1);

    return ans;
}

//================================================================================*

int main(){
    fast;
    generatePrimeFactors();
    int n,ans=0;
    cin >> n;
    // if(n==1000000){
    //     cout << 13969985;
    //     return 0;
    // }
    for(int i=1;i<n;i++){
        int fac = calculateNoOFactors(n-i);
        ans += fac;
    }
    cout << ans;
    return 0;
}


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

typedef long long ll;

class UnionFind {
public:
	vector<int> parent;

	UnionFind(int n) {
		parent = vector<int>(n, -1);
	}

	int root(int x) {
		if (parent[x] < 0) return x;
		return parent[x] = root(parent[x]);
	}

	int size(int x) {
		return -parent[root(x)];
	}

	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;

		if (size(x) < size(y)) swap(x, y);

		parent[x] += parent[y];
		parent[y] = x;

		return;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

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

	vector<ll> ans(M);
	ans[M - 1] = (ll)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];
		if (!Uni.same(A[i], B[i])) {
			ans[i - 1] -= (ll)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.unite(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++) cout << ans[i] << endl;

	return 0;
}


Measured memory_bytes: 3328
def nC2(n):
    return n * (n - 1) // 2


N = int(input())
A = list(map(int, input().split()))
cnt = {}

for a in A:
    cnt[a] = cnt.get(a, 0) + 1

base = sum(map(lambda x: nC2(x), cnt.values()))

for a in A:
    print(base - nC2(cnt[a]) + nC2(cnt[a] - 1))


Measured memory_bytes: 26140
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    if (a < b) {
        for (int i = 0; i != b; i++) {
            printf("%d",a);
        }
    }
    else {
        for (int i = 0; i != a; i++) {
            printf("%d",b);
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
#include <time.h>
#pragma warning(disable:4996) 

typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define LINF3 1000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[200005];
int dp[200005][3];

void solve()
{
    int n;
    scanf("%d%s", &n, str);
    int i;
    int cnt = 0;
    for (i = 0; i < n; i++) {
        if (str[i] == '1') cnt++;
    }

    vector<int> ans(cnt + 1);
    for (i = 1; i <= cnt; i++) {
        int curr = i;
        int tmp = 0;
        while (curr) {
            if (curr % 2) tmp++;
            curr /= 2;
        }
        ans[i]=ans[i%tmp]+1;
    }

    int sum0 = 0;
    vector<int> a0(n);
    if (cnt - 1 != 0) {
        int curr = 1;
        for (i = 0; i < n; i++) {
            a0[i] = curr;
            sum0 = (sum0 + (str[n - 1 - i] == '1' ? curr : 0))%(cnt-1);
            curr = curr * 2 % (cnt - 1);
        }
    }
    int sum1 = 0;
    vector<int> a1(n);
    if (cnt + 1 != 0) {
        int curr = 1;
        for (i = 0; i < n; i++) {
            a1[i] = curr;
            sum1 = (sum1 + (str[n - 1 - i] == '1' ? curr : 0))%(cnt+1);
            curr = curr * 2 % (cnt + 1);
        }
    }

    vector<int> a(n);
    for (i = 0; i < n; i++) {
        int tmp = (str[i] == '1' ? cnt - 1 : cnt + 1);
        if (tmp == 0) {
            a[i] = -1;
        }
        else if(str[i] == '1') {
            a[i] = (sum0 - a0[n - 1 - i] + (cnt - 1)) % (cnt - 1);
        }
        else {
            a[i] = (sum1 + a1[n - 1 - i]) % (cnt + 1);
        }
    }

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

    }
    return;
}

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


Measured memory_bytes: 5672
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    bool ans = (s[2]==s[3] && s[4]==s[5]);
    cout << (ans? "Yes" : "No") << endl;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
    ll n,k,ans = 0.0;
    cin >> n >> k;
    ans = n % k;
    cout << min(ans,abs(ans - k)) << endl;
    return 0;
}

Measured memory_bytes: 3612
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main (){
    int s;
    cin >> s;
    int i = 1;
    while (1)
    {
        if(s == 4 || s == 2 || s == 1){
            cout<< i+3 << endl;
            return 0;
        }
        if(s %2 ==1){
            s  = 3*s +1;
            i++;
        }
        else {
            s = s/2;
            i++;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine((int)Math.Pow(double.Parse(Console.ReadLine()), 2d));
            //int r = int.Parse(Console.ReadLine());
            //Console.WriteLine(r * r);
        }
    }
}

//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 27588
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long sum = 0;
    int add = 1;
    int ans = 0;
    do {
      sum += add;
      add++;
      ans++;
    } while (sum < X);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
_, K = gets.split(" ").map( & :to_i)
candles = gets.split(" ").map( & :to_i)

min_dist = Float::INFINITY
candles.each_with_index do |c, idx|
  c1 = candles[idx + K - 1]
  break if c1.nil?

  dist = if c1 * c < 0
           c1 - c + [-c, c1].map(&:abs).min
         else
           [c, c1].map(&:abs).max
         end
  min_dist = [min_dist, dist].min
end

puts min_dist


Measured memory_bytes: 11012
n = int(input())
d,x = map(int,input().split())
cnt = 0

for i in range(n):
    s = int(input())
    c = 1
    dcnt = 1
    while dcnt <=d :
        dcnt = c * s + 1
        cnt += 1
        c += 1

print(cnt + x)

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

const ll mod = 1000000007;
const ll INF = 1001001001;

int main(){
    int n; cin >> n;
    vector<ll> a(n), sum(n+1);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    for(int i = 0; i < n; i++){
        sum[i+1] = sum[i] + a[i];
    }
    int tmp = 0;
    for(int i = 0; i < n - 1; i++){
        if(sum[i+1] * 2 < a[i + 1]){
            tmp = i + 1;
        }
    }
    cout << n - tmp << endl;
}


Measured memory_bytes: 4792
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int n;
  cin >> n;
  vector<string> S(n);
  REP(i, n) cin >> S.at(i);
  string ans = "";
  sort(S.at(0).begin(), S.at(0).end());
  for (auto s : S.at(0)) {
    bool FLG = true;
    for (int j = 1; j < n; j++) {
      bool flag = false;
      for (int k = 0; k < S.at(j).size(); k++) {
        if (s == S.at(j).at(k)) {
          S.at(j).at(k) = '0';
          flag = true;
          break;
        }
      }
      if (!flag) {
        FLG = false;
        break;
      }
    }
    if (FLG) ans += s;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    now = A[0]
    for i in range(1, N):
        if A[i] >= now:
            now = A[i]
        else:
            ans += now - A[i]
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 92152
import sys
n=int(input())
a=sorted(list(map(int,input().split())))
ans=1
flag=(n+1)%2
if flag==0:
  if a[0]==0:
    a.pop(0)
  else:
    print(0)
    sys.exit()
else:
  if a[0]==a[1]==1:
    a.pop(0)
    a.pop(0)
    ans*=2
  else:
    print(0)
    sys.exit()
for i in range((n-flag-1)//2):
  if a[i*2]==a[i*2+1]==flag+(i+1)*2:
    ans*=2
  else:
    print(0)
    sys.exit()
print(ans%(10**9+7))

Measured memory_bytes: 83544
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N,Y,x=0,y=0,z=0,sum=0,max=0;
	cin>>N>>Y;
	int r=(Y%5000)/1000;
	for(int i=0;5*i+r<=N;i++){
		z=5*i+r;
		sum=Y-1000*z;
		max=10000*(N-z);
		x=N-z;
		y=0;
		while(max>=sum&&x>=0){
			if(max==sum){
				cout<<x<<" "<<y<<" "<<z;
				return 0;
			}
			max=max-5000;
			y++;
			x=x-1;
		}
	}
	cout<<-1<<" "<<-1<<" "<<-1;
}

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

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    rep(i,m) cin >> a[i] >> b[i];
    scc_graph g(n);
    rep(i,m){
        g.add_edge(a[i], b[i]);
    }
    vector<vector<int> > ans = g.scc();
    int K = ans.size();
    cout << K << endl;
    rep(i,K){
        int l = ans[i].size();
        cout << l << " ";
        rep(j,l){
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 44404
#include <iostream>
using namespace std;
int w,h;
int mp[20][20],memo[20][20];
int dx[] = {-1,0,1};

void saiki(int x,int y) {
  if(y >= h-1) memo[y][x]++;
  else if(mp[y][x] != 1) {
    for(int i=0;i<3;i++) {
      int nx = dx[i]+x, ny = y+1;
      if(nx <0|| nx >= w ||mp[ny][nx] == 1) continue;
      if(memo[ny][nx] > 0 && mp[ny][nx] == 0) memo[y][x] += memo[ny][nx];
      else if(mp[ny][nx] == 0){
	saiki(nx,ny);
	memo[y][x] += memo[ny][nx];
      }
      else if(nx==x && mp[ny][nx] == 2){
	int ty = ny;
	while(mp[ty][nx] == 2) ty+=2;
	if(mp[ty][nx] == 0 && memo[ty][nx] == 0){
	  saiki(nx,ty);
	  memo[y][x] += memo[ty][nx];
	}
	else if(mp[ty][nx] == 0 && memo[ty][nx] > 0) memo[y][x] += memo[ty][nx];
      }
    }
    if(memo[y][x] == 0) mp[y][x] = -1;
  }
}
  
int main() {
  while(1) {
    cin >> w >> h;
    if(w == 0 && h == 0) break;
    for(int i=0;i<=19;i++)
      for(int j=0;j<=19;j++)memo[i][j] = mp[i][j] = 0;
    
    for(int i=0;i<h;i++)
      for(int j=0;j<w;j++)cin >> mp[i][j];
 
    for(int i=0;i<w;i++) 
      if(mp[0][i] !=1) saiki(i,0);
    
    int cnt = 0;
    for(int i=0;i<w;i++)
      if(memo[0][i] > 0) cnt+=memo[0][i];
    cout <<cnt<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#テストケース追加と聞いたのでテスト
n,d,a= map(int, input().split( ))
ms = []
for i in range(n):
    xi,hi = map(int, input().split( ))
    tmp = 0
    if hi%a:
        tmp+=1
    ms.append([xi,hi//a+tmp])

ms.sort()
ans = ms[0][1]
tmp = ms[0][1]
from collections import deque

Q = deque()
Q.append(0)

for i in range(1,n):

    while Q:###ifから変更
        tmp2 = Q.popleft();
        if ms[tmp2][0]+2*d<ms[i][0]:###tmpじゃないわms[tmp2][0]だわ
            tmp -= ms[tmp2][1]
        else:
            Q.appendleft(tmp2)
            break###
    ms[i][1]-=tmp###
    ms[i][1] = max(ms[i][1],0)###

    if ms[i][1]>0:
        #ms[i][1]-=tmp　二回引いてるわ
        ans += ms[i][1]
        Q.append(i)
        tmp += ms[i][1]
print(ans)


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	cout.tie(NULL);
	int n, d;	cin >> n >> d;
	int ans = 0;
	for (int i = 0; i < n; i += 1) {
		int x, y;	cin >> x >> y;
		double t = sqrt(pow(x, 2) + pow(y, 2) * 1.0);
		if (t <= (double)d)
			ans++;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3692
s = input()
p = list(map(int,s))

for x in range(2**3):
    ans = p[0]
    for y in range(3):
        if (x>>y)&1:
            ans += p[y+1]
        else:
            ans -= p[y+1]
    if ans == 7:
        kotae = format(x,"#05b")

kotae = kotae[2:]
for z in range(3):
    print(str(p[z]),end="")
    if kotae[-z-1] == str(1):
        print("+",end="")
    else:
        print("-",end="")

print(str(p[3]) + "=7" )


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

int main(){
  int t, h, m, s;

  cin >> t;

  h = t/(60*60);
  t = t % (60*60);
  m = t/60;
  s = t % 60;

  cout << h << ":" << m << ":" << s << endl;

  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin >> a >> b;

    int ans = 10;
    int tax_eight = 0;
    int tax_ten = 0;
    while(1){
        tax_eight = floor(ans * 0.08);
        tax_ten = floor(ans * 0.1);

        if(tax_eight == a and tax_ten == b){
            cout << ans;
            break;
        }
        if(ans == 1001){
            cout << -1;
            break;
        }
        ans++;
    }
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

struct Mod {
    static constexpr auto kMod = 1000000007L;

    Mod() : n(0) {}
    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const { return (n * (m.n % kMod)) % kMod; }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p / 2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kMod - 2);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return *this;
    }

    Mod operator+(Mod m) const { return (n + m.n) % kMod; }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

    Mod operator-(Mod m) const { return (kMod + n - m.n) % kMod; }

    Mod& operator-=(Mod m) {
        *this = *this - m;
        return *this;
    }

    int64_t n;
};

int main() {
    int64_t n, k;
    cin >> n >> k;

    vector<int64_t> a(n);
    for (auto&& aa : a) {
        cin >> aa;
    }

    sort(a.begin(), a.end());

    vector<Mod> fact(n + 1, 1L);
    for (auto i : irange(2L, n + 1)) {
        fact[i] = fact[i - 1] * i;
    }

    Mod ans;
    for (auto i : irange(0L, n)) {
        if (i >= k - 1) {
            // C(i, k - 1)
            ans += fact[i] / fact[k - 1] / fact[i - k + 1] * a[i];
        }

        if (i <= n - k) {
            // C(n - i - 1, k - 1)
            ans -= fact[n - i - 1] / fact[k - 1] / fact[n - k - i] * a[i];
        }
    }

    cout << ans.n << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#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 fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,s=0,t=0;
cin >> n;
int a[n],b[n],c[n-1];
for(int i=0;i<n;i++){
   cin >> a[i];
}
for(int i=0;i<n;i++){
   cin >> b[i];
}
for(int i=0;i<n-1;i++){
   cin >> c[i];
}
for(int i=0;i<n;i++){
   s += b[i];
}
for(int i=0;i<n-1;i++){
   if(a[i]+1==a[i+1]){
      t += c[a[i]-1];
   }
}
cout << s+t << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
mod=10**9+7
h,w,a,b=map(int,input().split())
F,I=[0]*(h+w+2),[0]*(h+w+2)
def inv(n):
  return pow(n,mod-2,mod)
F[0],F[1],I[0],I[1]=1,1,1,1
for i in range(2,h+w+2):
  F[i]=i*F[i-1]%mod
  I[i]=inv(F[i])
def c(a,b):
  return F[a+b]*I[a]*I[b]%mod
ans=0
for i in range(b+1,w+1):
  ans+=(c(h-a-1,i-1)*c(a-1,w-i))%mod
print(ans%mod)

Measured memory_bytes: 18764
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define PI 3.14159265358979
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
// using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

// modint
const int MOD = 1000000007;

class mint
{
  ll x;

public:
  mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const
  {
    return mint(-x);
  }

  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)
  {
    mint res(*this);
    return res += a;
  }

  mint operator-(const mint &a)
  {
    mint res(*this);
    return res -= a;
  }

  mint operator*(const mint &a)
  {
    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)
  {
    mint res(*this);
    return res /= a;
  }

  friend ostream &operator<<(ostream &os, const mint &m)
  {
    os << m.x;
    return os;
  }
};

vector<pair<long long, int>> factorize(long long N)
{
  vector<pair<long long, int>> res;
  for (long long i = 2; i * i <= N; i++)
  {
    if (N % i != 0)
      continue;
    res.emplace_back(i, 0);
    while (N % i == 0)
    {
      N /= i;
      res.back().second++;
    }
  }
  if (N != 1)
    res.emplace_back(N, 1);
  return res;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> num(1100000, 0);
  for (auto &it : A)
  {
    cin >> it;
    auto pf = factorize(it);
    for (auto p : pf)
      num[p.first] = max(num[p.first], p.second);
  }

  mint LCM = 1;
  for (int v = 2; v < 1100000; v++)
  {
    mint now = v;
    LCM *= now.pow(num[v]);
  }

  mint ans = 0;
  for (auto a : A)
    ans += LCM / a;
  cout << ans << endl;
  return 0;
}

// LをA1,..., ANの最小公倍数とする．Bi = L/Aiと定めるとBiは条件を満たすため答えは\sigma(L/Ai)である．しかしLは非常に大きな数であるためそのまま計算することは出来ない．そこで，Lを素因数分解した形で保持し，計算することを考える．


Measured memory_bytes: 4608
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll n;
vector<complex<ll>>pos,neg,a;
bool cmp(complex<ll>p,complex<ll>q)
{
	if(p.imag()==0 and q.imag()==0)
		return p.real()>q.real();
	return (conj(p)*q).imag()>0;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    rep(i,0,n)
    {
    	ll x,y;
    	cin>>x>>y;
    	if(x==0 and y==0)
    		continue;
    	if(y>=0)
    		pos.pb({x,y});
    	else
    		neg.pb({x,y});
    }
    sort(all(pos),cmp);
    sort(all(neg),cmp);
    for(auto i:pos)
    	a.pb(i);
    for(auto i:neg)
    	a.pb(i);
    n=sz(a);
    ll ans=0;
    rep(i,0,n)
    {
    	ll sx=0,sy=0;
    	rep(j,0,n)
    	{
    		sx+=a[(i+j)%n].real();
    		sy+=a[(i+j)%n].imag();
    		ans=max(ans,sx*sx+sy*sy);
    	}
    }
    printf("%0.12lf", sqrt(double(ans)));
}


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

int main()
{
    long long N;
    cin >> N;
    vector<long long> A(N);

    long long sum = 0;
    for(long long i = 0; i < N; i++)
    {
        scanf("%lld",&A[i]);
        sum += A[i];
    }
    
    long long sumA = 0;
    for(long long i = 1; i <= N-1; i+=2) sumA += A[i];
    vector<long long> X(N);
    X[0] = sum - 2*sumA;
    for(long long i = 1; i < N; i++)
        X[i] = 2*A[i-1] - X[i-1];

    for(long long i = 0; i < N; i++)
    { 
        if(i == N-1) cout << X[i] << endl;
        else cout << X[i] << " ";
    }

    return 0;
}

Measured memory_bytes: 2944
#if 0
#endif

#include <iostream>
#include <string>
#include <set>
using namespace std;

struct pos
{
    int x;
    int y;
};
bool state[25][25];
int result = 1, width, height;

void tansaku(pos cur)
{
    // 右へ
    if (cur.x < width - 1 && state[cur.x + 1][cur.y])
    {
        state[cur.x + 1][cur.y] = false;
        result++;
        tansaku({.x = cur.x + 1, .y = cur.y});
    }
    // 左へ
    if (0 < cur.x && state[cur.x - 1][cur.y])
    {
        state[cur.x - 1][cur.y] = false;
        result++;
        tansaku({.x = cur.x - 1, .y = cur.y});
    }
    // 上へ
    if (0 < cur.y && state[cur.x][cur.y - 1])
    {
        state[cur.x][cur.y - 1] = false;
        result++;
        tansaku({.x = cur.x, .y = cur.y - 1});
    }
    // 下へ
    if (cur.y < height - 1 && state[cur.x][cur.y + 1])
    {
        state[cur.x][cur.y + 1] = false;
        result++;
        tansaku({.x = cur.x, .y = cur.y + 1});
    }
}

int main()
{
    while (cin >> width >> height && (width != 0 || height != 0))
    {
        result = 1;
        pos cur;

        for (int y = 0; y < height; y++)
        {
            string word;
            cin >> word;
            for (int x = 0; x < width; x++)
            {
                char c = word[x];
                if ('.' == c)
                {
                    state[x][y] = true;
                }
                else if ('@' == c)
                {
                    state[x][y] = false;
                    cur.x = x;
                    cur.y = y;
                }
                else if ('#' == c)
                {
                    state[x][y] = false;
                }
            }
        }
        tansaku(cur);
        cout << result << endl;
    }
}



Measured memory_bytes: 3212
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

def popcount(i):
    return bin(i).count('1')

def dfs(i, N, nodes, src, dest):
    """ DFS(木、再帰、重みなし) """

    dist = [INF] * N
    def rec(u, prev, c):
        if u == dest:
            return True
        dist[u] = c
        for v in nodes[u]:
            if v != prev:
                if rec(v, u, c+1):
                    # 目的の頂点に到達したら、それに至る辺集合をbitで持っておく
                    A[i] |= 1 << edges[(u, v)]
                    return True
        return False
    rec(src, -1, 0)

N = INT()
nodes = [[] for i in range(N)]
edges = {}
for i in range(N-1):
    a, b = MAP()
    a -= 1; b -= 1
    nodes[a].append(b)
    nodes[b].append(a)
    edges[(a, b)] = i
    edges[(b, a)] = i

M = INT()
# A[i] := 条件iで白くしなければいけない辺の集合
A = [0] * M
for i in range(M):
    u, v = MAP()
    u -= 1; v -= 1
    dfs(i, N, nodes, u, v)

# 全通り数から、包除原理に基づいて足し引きしていく
ans = 2 ** (N-1)
for S in range(1, 1<<M):
    # Sで表される条件の集合において、白くしなければならない辺の集合S2
    S2 = 0
    for i in range(M):
        if S & 1<<i:
            S2 |= A[i]
    # 白くしなければならない辺の数
    edgecnt = popcount(S2)
    # 今回の状態Sを作るパターンの通り数(2^白黒自由に選べる辺の数)
    cnt = 2**(N-1-edgecnt)
    if popcount(S) % 2 == 1:
        ans -= cnt
    else:
        ans += cnt
print(ans)


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

string s;

int main(){
    cin >> s;
    int N = s.length();
    string s_r = s;
    reverse(s_r.begin(), s_r.end());
    // 条件1
    if( s_r != s ) { cout << "No"; return 0; }
    
    // 条件2
    auto s2 = s.substr(0, (N-1)/2);
    auto s2r = s2;
    reverse( s2r.begin(), s2r.end() );
    if( s2r != s2 ) { cout << "No"; return 0; }

    // 条件3
    auto s3 = s.substr((N+3)/2-1);
    auto s3r = s3;
    reverse( s3r.begin(), s3r.end() );
    if( s3r != s3 ) { cout << "No"; return 0; }

    cout << "Yes";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD ((int)(1e9+7))
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define float long double

int ans=0;

int32_t main()
{
	IOS
	int n;cin>>n;
	vector<vector<int>>A(3,vector<int>(n+1)),dp(3,vector<int>(n+1));
	
	for(int i=1;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin>>A[j][i];
		}
	}
	
	for(int i=0;i<3;i++)
	{
		dp[i][1]=A[i][1];
	}
	
	for(int i=2;i<=n;i++)
	{
		for(int j=0;j<3;j++)
		{
			dp[j][i]=max( dp[(j+1)%3][i-1]+A[j][i] , dp[(j+2)%3][i-1]+A[j][i] );
		}
	}
	cout<<max({dp[0][n],dp[1][n],dp[2][n]})<<endl;
	
}
			
	
	
	
	
	

	

	

	
		


Measured memory_bytes: 5752
/**
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=jp
 */

#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <sstream>
#include <vector>

void printVector(const std::vector<double> &v) {
  std::ostringstream oss;
  oss << std::fixed << std::setprecision(8);
  std::copy(v.begin(), v.end() - 1, std::ostream_iterator<double>(oss, " "));
  oss << v.back();
  std::cout << oss.str() << std::endl;
}

void kochCurve(std::vector<double> &p1, std::vector<double> &p2,
               unsigned short n) {
  if (n == 0) {
    return;
  }
  const double Pi = atan((double)INFINITY) * 2;
  const double cos60 = cos(Pi * 60 / 180);
  const double sin60 = sin(Pi * 60 / 180);
  std::vector<double> s = {(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3};
  std::vector<double> t = {(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3};
  std::vector<double> u = {(t[0] - s[0]) * cos60 - (t[1] - s[1]) * sin60 + s[0],
                           (t[0] - s[0]) * sin60 + (t[1] - s[1]) * cos60 +
                               s[1]};
  kochCurve(p1, s, n - 1);
  printVector(s);
  kochCurve(s, u, n - 1);
  printVector(u);
  kochCurve(u, t, n - 1);
  printVector(t);
  kochCurve(t, p2, n - 1);
}

int main(int argc, char const *argv[]) {
  unsigned short n;
  std::string Param;
  std::istringstream Stream;
  getline(std::cin, Param);
  Stream.str(Param);
  Stream >> n;
  Stream.clear();
  std::vector<double> p1 = {0, 0};
  std::vector<double> p2 = {100, 0};
  printVector(p1);
  kochCurve(p1, p2, n);
  printVector(p2);

  return 0;
}

Measured memory_bytes: 3508
#include<stdio.h>

int main(void) {
	char s[4];

	scanf("%s", &s);

	if (s[1] == 'R')
	{
		printf("ABC\n");
	}
	else if (s[1] == 'B')
	{
		printf("ARC\n");
	}
	

	return 0;
}

Measured memory_bytes: 1624