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

set<char> aops[3]; // 演算子の優先順位

template<class T> struct Parser {
    // results
    int root;                       // vals[root] is the answer
    vector<T> vals;                 // value of each node
    vector<char> ops;               // operator of each node ('a' means leaf values)
    vector<int> left, right;        // the index of left-node, right-node
    vector<int> ids;                // the node-index of i-th value
    int ind = 0;
    
    void init() {
        vals.clear(); ops.clear(); left.clear(); right.clear(); ids.clear();
        ind = 0;
    }
    
    // generate nodes
    int newnode(char op, int lp, int rp, T val = 0) {
        ops.push_back(op); left.push_back(lp); right.push_back(rp);
        if (op == 'a') {
            vals.push_back(val);
            ids.push_back(ind++);
        }
        else {
            if (op == '+') vals.push_back(vals[lp] + vals[rp]);
            else if (op == '-') vals.push_back(vals[lp] - vals[rp]);
            else if (op == '*') vals.push_back(vals[lp] * vals[rp]);
            ids.push_back(-1);
        }
        return (int)vals.size() - 1;
    }
    
    // main solver
    T solve(const string &S) {
        int p = 0;
        root = expr(S, p);
        return vals[root];
    }
    
    // parser
    int expr(const string &S, int &p, int depth = 0) {
        if (depth < 3) {
            int lp = expr(S, p, depth + 1);
            while (p < (int)S.size() && aops[depth].count(S[p])) {
                char op = S[p]; ++p;
                int rp = expr(S, p, depth + 1);
                lp = newnode(op, lp, rp);
            }
            return lp;
        }
        else {
            if (S[p] == '(') {
                ++p;                    // skip '('
                int lp = expr(S, p, 0);
                ++p;                    // skip ')'
                return lp;
            }
            else {
                /* each process */
                long long val = 0;
                while (S[p] >= '0' && S[p] <= '9') {
                    val *= 10;
                    val += (int)(S[p] - '0');
                    ++p;
                }
                return newnode('a', -1, -1, val);
            }
        }
    }
};

int main() {
    string S; cin >> S;
    Parser<long long> ps;
    long long res = -LONG_MAX;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                for (int it = 0; it < 3; ++it) aops[it].clear();
                aops[i].insert('+');
                aops[j].insert('-');
                aops[k].insert('*');
                Parser<long long> ps;
                long long tmp = ps.solve(S);
                res = max(res, tmp);
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3224
import java.util.Arrays;
import java.util.Scanner;
public class Main{
  public static void main(String[] arsgs){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int l = sc.nextInt();
    String[] s = new String[n];
    for (int i = 0; i < n; i++){
      s[i] = sc.next();
    }
    Arrays.sort(s);
    for (int j = 0; j < n; j++){
      System.out.print(s[j]);
    }
  }
}

Measured memory_bytes: 23380
import sys,re
c=lambda l,n:re.sub("[a-z]",lambda x:chr((ord(x.group(0))-97+n)%26+97),l)
for i in sys.stdin:
	n=0
	while not re.search("th(e|is|at)",c(i,n)):n+=1
	print c(i,n).strip()

Measured memory_bytes: 4200
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <climits>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)
#define rep1(i, n) for(int i = 1; i <= (int) n; i++)



int main() {
    int n;
    cin >> n;
    map<int,bool> mp;
    rep(i,n) {
        int a;
        cin >> a;
        mp[a] = !mp[a];
    }
    int ans = 0;
    for (auto itr = mp.begin(); itr != mp.end(); itr++)
    {
        if (itr->second) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4864
#include<iostream>
#include<math.h>

using namespace std;

int main(){
  int A,B,C,K;
  cin >> A >> B;
  C = fabs(A+B);
  if(C%2==1){
    cout << "IMPOSSIBLE";
    return 0;
  }
  K = (A+B)/2;
  cout << K << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    vector<long long> a(n + 1);
    for (int i = n; i >= 0; i--) cin >> a[i];
    //for (int i = n; i >= 0; i--) a[i] = 1;
    long long g = abs(a[n]);
    for (int i = 0; i <= n; i++) if (a[i] != 0) g = __gcd(g, abs(a[i]));
    for (int i = 0; i <= n; i++) a[i] /= g;
    vector<int> vec;
    for (int i = 2; i * i <= g; i++)
    {
        while (g % i == 0)
        {
            g /= i;
            vec.push_back(i);
        }
    }
    if (g > 1)
    {
        vec.push_back(g);
    }
    for (int p = 2; p <= 2 * n; p++)
    {
        int t = 1; for (int j = 2; j < p; j++) if (p % j == 0) t = 0;
        if (t == 1)
        {
            vector<long long> poly = a;
            for (int i = 0; i <= n; i++) poly[i] = (poly[i] % p + p) % p;
            for (int i = n; i - p + 1 >= 0; i--)
            {
                poly[i - p + 1] = (poly[i - p + 1] + poly[i]) % p;
                poly[i] = 0;
            }
            int fl = 0;
            for (int i = 0; i <= n; i++) if (poly[i] % p != 0) fl = 1;
            if (a[0] % p == 0 && fl == 0) vec.push_back(p);
            //cout << p << " ";
            //for (int i = n; i >= 0; i--) cout << poly[i] << " "; cout << "\n";
        }
    }
    sort(vec.begin(), vec.end());
    vec.resize(unique(vec.begin(), vec.end()) - vec.begin());
    for (auto e : vec) cout << e << "\n";
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 384
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, *x = (int(i) for i in sys.stdin.read().split())
    s_x = list(sorted(x))
    half = n // 2
    m_s, m_l = s_x[half - 1], s_x[half]
    for i in x:
        print(m_l if i < m_l else m_s)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 25052
#include <bits/stdc++.h>
using namespace std;
int main(){
        string S;
        cin >> S;
    for ( int i=0;i<S.size();i++ ){
            if ( i%2 == 0 && S.at(i) == 'L' ){
                cout << "No" << endl;
                break;
            }
             if ( i%2 == 1 && S.at(i) == 'R' ){
                cout << "No" << endl;
                break;
            }
        else {
          if(i  <  S.size() -1){
            continue;
            }
          else if( i  == S.size() -1){
            cout << "Yes" << endl;
            }
        }
        }
}    

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int N;
    int tmp = 0,ans=0;
    string S;
    cin >> N;
    cin >> S;
    for(int i = 0; i< N; i++){
        if(S[i]=='A'){
            tmp = 1;
        }else if(tmp==1 && S[i]=='B'){
            tmp = 2;
        }else if(tmp==2 && S[i]=='C'){
            tmp = 0;
            ans++;
        }else{
            tmp=0;
        }
    }
    cout << ans << endl; 
}

Measured memory_bytes: 256
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let n: u32 = sc.read();
    println!("{}", n*n*n);
}

use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
 
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
 
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }
 
    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }
 
    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}


Measured memory_bytes: 5024
get_string(String) :-
  current_input(Input),
  read_string(Input, ' \n', '', _, String).
 
get_number(Number) :-
  get_string(String),
  number_string(Number, String).

seven(['7'|_]).
seven([_|L]) :- seven(L).

main :-
  get_string(S),
  string_chars(S,L),
  seven(L)->writeln('Yes');writeln('No').

Measured memory_bytes: 7960
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

        int n = scanner.nextInt();
        int[] s = scanInt(scanner, n);

        int q = scanner.nextInt();
        int[] t = scanInt(scanner, q);

        System.out.println(IntStream.of(t).map(i -> binarySearch(s, i)).sum());
    }

    private static int binarySearch(int[] s, int key) {
        int left = 0;
        int right = s.length;
        while (left < right) {
            int mid = (left + right) / 2;
            if (s[mid] == key) {
                return 1;
            } else if (s[mid] > key) {
                right = mid;
            } else {
                left = mid + 1;
            }
        }
        return 0;
    }

    private static int[] scanInt(Scanner scanner, int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = scanner.nextInt();
        return a;
    }
}



Measured memory_bytes: 69688
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int a,b,t;
  cin>>a>>b>>t;
  int x=t*1.0/a;
  x=x*b;
  cout<<x<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <math.h>
#include <list>
#include <stack>
#include <set>
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <cstdlib>
#include <typeinfo>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b > c + d)cout << "Left" << endl;
	else if (a + b == c + d)cout << "Balanced" << endl;
	else cout << "Right" << endl;
	return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;

fn get_one<T : FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().parse().ok().unwrap();
}

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let v : Vec<i32> = get_vec();
    let k = v[0];
    let s = v[1];
    let mut ans = 0;
    for i in 0..(k+1) {
        for j in 0..(k+1) {
            if i + j + k >= s && i + j <= s {
                //println!("{} {}", i, j);
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


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

using namespace std;

int main()
{
	string crypt;

	while (cin >> crypt){
		int index;

		while ((index = crypt.find('@')) != string::npos){
			string enc(crypt[index + 1] - '0', crypt[index + 2]);
			crypt = crypt.substr(0, index) + enc + crypt.substr(index + 3, crypt.size() - index - 3);
		}

		cout << crypt << endl;
	}

	return (0);
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ks ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fr first
#define sc second
#define pb push_back
#define pf push_front
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>pa;
const int maxn=1e6+177;
const ll mod=0x3f3f3f3f3f3f3f3f;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
template<class T>inline void read(T &res){
    char c;T flag=1;
    while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
    while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
void wenjian(){freopen("concatenation.in","r",stdin);freopen("concatenation.out","w",stdout);}
void tempwj(){freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){a %= mod;ll ans = 1;while(b){if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}


int ans[maxn];
int main(){
    int n;
    scanf("%d",&n);
    memset(ans,0,sizeof(ans));
    int now;
    for(int i=1;i*i<=n;i++){
        for(int j=1;j*j<=n;j++){
            for(int k=1;k*k<=n;k++){
                now=i*i+j*j+k*k+i*j+j*k+k*i;
                ans[now]++;
            }
        }

    }
    for(int i=1;i<=n;i++){


        printf("%d\n",ans[i]);
    }


}


Measured memory_bytes: 7648
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,k,i;
    cin>>n>>k;
    ll x[n],ans=1e10,tp;
    for (i=0;i<n;i++)
        cin>>x[i];
    for (i=0;i<n-k+1;i++)
    {
        if (x[i]<=0 && x[i+k-1]<=0)
            tp=abs(x[i]);
        else if (x[i]>=0 && x[i+k-1]>=0)
            tp=x[i+k-1];
        else
            tp=min(2*abs(x[i])+x[i+k-1],abs(x[i])+2*x[i+k-1]);
        ans=min(ans,tp);
    }
    cout<<ans<<endl;
}

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


def solve(b: str):
    if b == "A":
        print("T")
    if b == "T":
        print("A")
    if b == "C":
        print("G")
    if b == "G":
        print("C")


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    b = next(tokens)  # type: str
    solve(b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3068
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int n;
	cin >> n;
	int64_t A[n+1];
	int64_t B[n];
	rep(i, n+1) cin >> A[i];
	rep(i, n) cin >> B[i];

	int64_t res = 0;
	int64_t x;
	rep(i, n) {
		x = min(B[i], A[i]);
		A[i] -= x;
		B[i] -= x;
		res += x;
		x = min(A[i+1], B[i]);
		A[i+1] -= x;
		B[i] -= x;
		res += x;
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
# AtCoder Beginner Contest 062
# A - Grouping
x, y = map(int, input().split())
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]
if x in A and y in A:
    print('Yes')
elif x in B and y in B:
    print('Yes')
elif x in C and y in C:
    print('Yes')
else:
    print('No')

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

int main() {
  int n;
  cin >> n;
  string str = to_string(n);
  bool flg = false;
  
  for (int i = 0; i < str.size(); i++) {
    if (str[i] == '7') {
      flg = true;
    }
  }

  if (flg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
#define ll long long int 
#define pb push_back
#define mp make_pair
using namespace std;
int main()
{
	ll n,m,i,j,k,flag=0;
	cin>>n>>m;
	char ch[n][m];
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			cin>>ch[i][j];
		}
	}
	vector<ll> vir,vic;
	for(i=0;i<n;i++){
		flag=0;
		for(j=0;j<m;j++){
			if(ch[i][j]=='#'){
				flag=1;
			}
		}
		if(flag==0){
			vir.pb(i);
		}
	}
	for(j=0;j<m;j++){
		flag=0;
		for(i=0;i<n;i++){
			if(ch[i][j]=='#'){
				flag=1;
			}
		}
		if(flag==0){
			vic.pb(j);
		}
	}
	for(i=0;i<n;i++){
		ll count=0;
		for(j=0;j<m;j++){
			flag=0;
			for(k=0;k<vir.size();k++){
				if(vir[k]==i){
					flag=1;
				}
			}
			for(k=0;k<vic.size();k++){
				if(vic[k]==j){
					flag=1;
				}
			}
			if(flag==0){
				cout<<ch[i][j];
				count=1;
			}
		}
		if(count==1){
			cout<<endl;
		}
	}
}  

Measured memory_bytes: 256
def prime_factorization(n):
    """
    nを素因数分解して素因数のリストを返却する
    """
    if n < 2:
        return [n]

    primes = []
    while n % 2 == 0:
        primes.append(2)
        n //= 2
    i = 3
    while i ** 2 <= n:
        while n % i == 0:
            primes.append(i)
            n //= i
        i += 2
    if n != 1:
        primes.append(n)
    return primes


n = int(input())

print('{}: {}'.format(n, ' '.join(map(str, prime_factorization(n)))))



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

int main() {
  
  int N, c;
  char a;
  cin >> N;
  
  for (int i = 0; i < N; i++) {
    cin >> a;
    
    if (a == 'Y') {
      c++;
    }
    
  }
  
  if (c > 0) {
    cout << "Four" << endl;
  }
  
  else {
    cout << "Three" << endl;
  }
  
}

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

long long GCD(long long a, long long b) 
{ 
    if(b==0) 
        return a; 
    return GCD(b, a%b);  
      
}

long long LCM(long long a, long long b)
{
    long long gcd=GCD(a,b);
     return (a*b)/gcd;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    long long i, j, k, n, m, t, x, y, z, s=0, c=0, l;
    string a, b;
    cin >> a >> b;
    for(i=0; i<a.size(); i++)
    {
        if(a[i]!=b[i])
            s++;
    }
    cout << s << endl;
}


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

int main() {
	int A , B ;
	cin >> A >> B;
  	int kaibunsu = 0;
  	for(int i = A; i <= B; i++){
    	if(i / 10000 == i % 10 && i % 10000 / 1000 == i % 100 / 10){
        	kaibunsu++;
        }
    }
  	cout << kaibunsu << endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws NumberFormatException{

		//?????£?????????
		int numN;
		int build;
		int floor;
		int room;
		int menber = 0;
		
		String s = "";
		String output = "";

		//[?£?][????±?][??¨?±?]
		int college[][][] = new int[4][3][10];
		String[] NumList = new String[4];

		Scanner sc = null;

		try {

				sc = new Scanner(System.in);
			int n = sc.nextInt();

			//?????????????????°?????£??\
			numN = n;

			//?????±???????????????
			for (int i = 1; i <= numN; i++) {

				for (int j = 0; j < NumList.length; j++) {

					s = sc.next();
					NumList[j] = s;
				}

				build  = (Integer.parseInt(NumList[0])) - 1;
				floor  = (Integer.parseInt(NumList[1])) - 1;
				room   = (Integer.parseInt(NumList[2])) - 1;
				menber = Integer.parseInt(NumList[3]);

				//?????±?????????
				college[build][floor][room] += menber;

				//??¨?±?????????°????????????
				//menber = 0;
			}

			for (int i = 0; i < college.length; i++) {

				for (int j = 0; j < college[0].length; j++) {
					//????????????
					for (int k = 0; k < college[0][0].length; k++) {
						output += " ";
						//??¨?±??????????
						output += college[i][j][k];
					}
					System.out.println(output);
					output = "";
				}
				if(i != college.length - 1){
					System.out.println("####################");
				}
			}
		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 28704
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
using ll = long long;

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

	int N, L;
	cin >> N >> L;
	vector<int> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}

	int last = -1;
	for (int i = 0; i < N - 1; i++) {
		if (a[i] + a[i + 1] >= L) {
			last = i;
			break;
		}
	}

	if (last == -1) {
		cout << "Impossible" << endl;
	} else {
		cout << "Possible" << endl;
		for (int i = 0; i < last; i++) {
			cout << i+1 << endl;
		}
		for (int i = N - 1; i > last + 1; i--) {
			cout << i << endl;
		}
		cout << last + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1280
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 9e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){a=b; return true;} return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){a=b; return true;} return false; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class ATrapezoids {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int a, b, h;
	    in >> a >> b >> h;
	    out << (a+b)*h/2 << endl;
	}
};


int main() {
	ATrapezoids solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

int main(){
  string s;cin >> s;
  int c = s.find("C"),f = s.rfind("F");
  bool ans = c != -1 && f != -1 && c < f;
  cout <<(ans? "Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=2e9;
int main(){
	int n;
	cin>>n;
	ll a,b;
	cin>>a>>b;
	rep(i,n-1){
		ll s,t;
		cin>>s>>t;
		if(a<=s&&b<=t){
			a=s;b=t;
		}else if((double)a/s<(double)b/t){
//			ll q=ceil((double)b/t);
			ll q=(b-1)/t+1;
			a=s*q;b=t*q;
		}else{
//			ll q=ceil((double)a/s);
			ll q=(a-1)/s+1;
			a=s*q;b=t*q;		
		}
	}
	cout<<a+b<<endl;
}










Measured memory_bytes: 256
N = int(input())
dic = {}
for i in range(N):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1
max_val = max(dic.values())
rst = [ key for key, val in dic.items() if val == max_val ]
[ print(i) for i in sorted(rst) ]

Measured memory_bytes: 36444
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	long long X, K, D; 
	cin >> X >> K >> D; 
	X = abs(X); 
	long long t = X / D; 
	if(K < t) cout << X - K * D << "\n"; 
	else if(K % 2 == t % 2) cout << X % D << "\n"; 
	else cout << D - X % D << "\n"; 
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=100005,mod=4000007;
int n,father[N];
queue<PI> q;
ll ycl[N];
vector<int> v[N];
struct has_table{
	bool has[mod]; int b[mod];
	ll a[mod],v[mod];
	inline void insert(int xx,int yy,int jb){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]+=jb; return;
			}
		}
	}
	inline void clear(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				has[i]=1; a[i]=x; b[i]=0; return;
			}
		}
	}
	inline int find(int xx,int yy){
		ll x=ycl[xx]*n+ycl[yy];
		for(int i=x%mod;;i=i+1==mod?0:i+1){
			if(!has[i]||a[i]==x){
				return b[i];
			}
		}
	}
}Ma,er;
inline int getfather(int x){
	return father[x]==x?x:father[x]=getfather(father[x]);
}
int main(){
	srand(time(0));
	n=read();
	for(int i=1;i<=n;i++)ycl[i]=(ll)rand()<<32|rand();
    for(int i=1;i<=n*2-2;i++){
        int x=read(),y=read(); 
        v[x].push_back(y); v[y].push_back(x);
        Ma.insert(x,y,1); Ma.insert(y,x,1);
        if(Ma.find(x,y)==2)q.push(mp(x,y));
    }
    for(int i=1;i<=n;i++)father[i]=i;
    while(!q.empty()){
    	int x=q.front().first,y=q.front().second; q.pop();
		x=getfather(x); y=getfather(y); if(x==y){puts("NO"); return 0;}
		if(v[x].size()<v[y].size()) swap(x,y); 
		er.insert(x,y,1); er.insert(y,x,1); 
		//cout<<x<<" "<<y<<endl;
        for(unsigned i=0;i<v[y].size();i++){ 
            int to=v[y][i]; if(er.find(y,to)){continue;}
            //if(y!=3||to!=3)cout<<x<<" "<<y<<" "<<to<<" "<<er.find(y,to)<<endl;
            er.insert(to,y,1); er.insert(y,to,1); v[to].push_back(x);
            Ma.insert(to,x,1); Ma.insert(x,to,1);
            if(Ma.find(to,x)==2)q.push(mp(to,x));
            v[x].push_back(to);
        }
        father[y]=x; v[y].clear();
    }
    int ans=0;
    for(int i=1;i<=n;i++)ans+=father[i]==i;
    if(ans==1) puts("YES"); else puts("NO");
    return 0;
}

Measured memory_bytes: 113024
// AtCoder Grand Contest 013
// C - Ants on a Circle

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;


const int MAX_N = 100000;

int N;
ll L, T;
ll x[MAX_N], xa[MAX_N];
int w[MAX_N];

int main() {

    ll d, k;
    int li, ri, slide;

    cin >> N >> L >> T;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> w[i];
        w[i] = (w[i] == 1 ? 1 : -1);
        xa[i] = ((x[i] + w[i] * T) % L + L) % L;
    }
    sort(xa, xa + N);

    k = 0;
    for (int i = 1; i < N; i++) {
        d = (x[i] + w[i] * T) - (x[0] + w[0] * T);
        k += (d > 0) ? (d / L) : (-d / L + 1);
    }
    k = (k * w[0] + N) % N;
    li = lower_bound(xa, xa + N, ((x[0] + w[0] * T) % L + L) % L) - xa;
    ri = upper_bound(xa, xa + N, ((x[0] + w[0] * T) % L + L) % L) - xa;
    slide = (ri - li >= 2 && w[0] > 0 ? li + 1 : li);

    for (int i = 0; i < N; i++) {
        cout << xa[(N + slide - k + i) % N] << endl;
    }

    return 0;

}



Measured memory_bytes: 3200
#include <stdio.h>

int read(void)
{
    int ret;
    scanf("%d", &ret);
    return ret;
}

int main(void)
{
    int i, idx = 0;
    int data[10000];

    while((data[idx++] = read()) != 0);

    for(i=0;i<idx-1;i++) {
        printf("Case %d: %d\n", i+1, data[i]);
    }
    return 0;
}

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

using namespace std;

int main(){
    //真ん中の方は反転の時に必ず同じ動きをする．真ん中以外は自由に動ける(要検証)ので，真ん中がどれだけ同じ符号か？を調べれば良い．
    string str;
    cin>>str;
    int N=str.size();
    int count=0;
    char key=str[N/2];
    int right=(N+1)/2;
    int left=N/2-1;
    while(str[right]==key && str[left]==key){
        right++;
        left--;
        count++;
        if(left<0) break;
    }
    int ans=count+(N+1)/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.Aising_2020
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] lrd = ReadInts();
            int l = lrd[0];
            int r = lrd[1];
            int d = lrd[2];

            int res = 0;
            for(int i=l; i <= r; i++)
            {
                if (i % d == 0)
                {
                    res++;
                }
            }

            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  
  int ansH;
  int ansW;
  
  for (int i=1; i<=W; i++) {
    if (N <= H*i) {
      ansH = i;
      break;
    }
  }
  for (int i=1; i<=H; i++) {
    if (N <= W*i) {
      ansW = i;
      break;
    }
  }
  
  cout << min(ansH, ansW) << endl;
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n;
    cin >> n;
    string word, previous_word;
    bool flag = true;
    map<string, bool> history;
    cin >> previous_word;
    history[previous_word] = true;
    rep(i, n - 1) {
        cin >> word;
        if(word[0] != previous_word[previous_word.size() - 1]) {
            flag = false;
        } else if(history[word]) {
            flag = false;
        }

        previous_word = word;
        history[previous_word] = true;
    }
    if(flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int main() {
  int A,B,X;
  cin >> X >> A >> B;
  if ( B > A+X ){
    cout << "dangerous" << endl;
    
  }else if ( B <= A ){
    cout << "delicious" << endl;

  }else{
    cout << "safe" << endl;
  }
}

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

int main()
{
    long n, tmp;

    std::cin >> n;
    std::vector<long> add(100), res(101);
    for (int i = 0; i < 100; i++)
    {
        add[i] = i * i;
        res[i + 1] = 0;
    }

    for (int i = 0; i < n; i++)
    {
        std::cin >> tmp;
        for (int j = 0; j < 100; j++)
        {
            res[j + 1] += add[std::abs(tmp - j - 1)];
        }
    }
    int min = res[1];
    for (int i = 0; i < 100; i++)
    {
        if (min > res[i + 1])
            min = res[i + 1];
    }
    std::cout << min << std::endl;
}

Measured memory_bytes: 256
n = int(input())
s = list(input())
for i in range(len(s)):
    if ord(s[i]) + n <= 90:
        s[i] = chr(int(ord(s[i])) + n)
    else:
        s[i] = chr(65 + int(ord(s[i]) + n) - 91)
print("".join(s))


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<cctype>
#include<string>

using namespace std;

int main()
{
  int n,m;

  while(1){
    
    int high=0,p[50][1000];

    cin>>n>>m;
    if(n==0 && m==0)return 0;
    for (int i=0;i<m;i++){
      for(int j=0;j<n;j++){
	cin>>p[i][j];
      }
    }

    for (int i=0;i<n;i++){
      int s=0;
      for(int j=0;j<m;j++){
	s+=p[j][i];
      }
      if(high<s){
	high=s;
	}
    }
    cout<<high<<endl;
  }
      return 0;
  
}


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

using namespace std;
using ll = long long;

int main() {
    int N, K, C;
    string T;
    cin >> N >> K >> C;
    cin >> T;

    vector<int> R(N, 0), S(N, 0);

    int l = C + 1, cnt = 0;
    for(int i = 0; i < N; i++, l++) {
        S[i] = cnt;
        if(l > C && T[i] == 'o') {
            l = 0;
            cnt++;
        }
    }
    l = C + 1, cnt = 0;
    for(int i = N - 1; i >= 0; i--, l++) {
        R[i] = cnt;
        if (l > C && T[i] == 'o') {
            l = 0;
            cnt++;
        }
    }

    for(int i = 0; i < N; i++) {
        if(T[i] == 'o' && S[i] + R[i] < K) {
            cout << i + 1 << endl;
        }
    }
}

Measured memory_bytes: 3332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		StringBuilder builder = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			if (line.isEmpty()) {
				break;
			}
			String[] lines = new String[9];
			lines[0] = line;
			for (int i = 1; i < 9; i++) {
				lines[i] = reader.readLine();
			}
			int[] nums = new int[4];
			int count = 0;
			for (int i = 0; i < 8; i++) {
				for (int j = 0; j < 8; j++) {
					if (lines[i].charAt(j) == '1') {
						nums[count] = i * 8 + j;
						count++;
						if (count == 4) {
							break;
						}
					}
				}
			}
			int result = nums[3] - nums[0];
			switch (result) {
			case 9:
				System.out.println("A");
				break;
			case 24:
				System.out.println("B");
				break;
			case 3:
				System.out.println("C");
				break;
			case 15:
				System.out.println("D");
				break;
			case 10:
				System.out.println("E");
				break;
			case 17:
				System.out.println("F");
				break;
			default:
				System.out.println("G");
				break;
			}
		}
	}
}

Measured memory_bytes: 16880
# ABC060D - Simple Knapsack (ARC073D)
# exhaustive search
from itertools import accumulate


def main():
    N, W, *A = map(int, open(0).read().split())
    V, x = [[] for _ in range(4)], A[0]  # x: w1 (W1 ≤ wi ≤ w1 + 3)
    for i in range(0, 2 * N, 2):  # group by weight
        w, v = A[i : i + 2]
        V[w - x] += [v]
    for i in range(4):  # V[i][j] := max value of picking up j items from group i
        V[i] = tuple(accumulate([0] + sorted(V[i], reverse=1)))
    L = [len(v) for v in V]
    ans = 0
    for i in range(L[0]):
        for j in range(L[1]):
            for k in range(L[2]):
                w = i * x + j * (x + 1) + k * (x + 2)
                if w > W:
                    break
                l = min(L[3] - 1, (W - w) // (x + 3))
                v = V[0][i] + V[1][j] + V[2][k] + V[3][l]
                ans = max(ans, v)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
N = int(input())
T, A = map(int, input().split())
Hs = list(map(int,input().split()))
ts = []
for H in Hs:
    ts.append(T - H * 0.006)
min_t = 10**6
min_idx = 0
for idx, t in enumerate(ts):
    if abs(t - A) < min_t:
        min_t = abs(t - A)
        min_idx = idx
print(min_idx+1)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>
int main()
{
    int x,i,j,ans=0;
    scanf("%d",&x);
    if(x==1){printf("1");
    return 0;}
    for(i=2;i<32;i++){
        for(j=2;j<10;j++){
            if(pow(i,j)<=x&&pow(i,j)>ans){
                ans=pow(i,j);
                if(pow(i,j)>1000)break;
            }
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
# 累積和
# PyPy なら通る
N, M, Q = map(int, input().split())

t = [[0] * (N + 1) for _ in range(N + 1)]
for _ in range(M):
    L, R = map(int, input().split())
    t[L][R] += 1

for i in range(N + 1):
    for j in range(N):
        t[i][j + 1] += t[i][j]

result = []
for _ in range(Q):
    p, q = map(int, input().split())
    result.append(sum(t[i][q] - t[i][i - 1] for i in range(p, q + 1)))
#print('\n'.join(str(v) for v in result))
print(*result, sep='\n')


Measured memory_bytes: 89892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s,t;
	cin>>s>>t;
	vector<ll>a[26];
	for(ll i=0;i<s.size();i++){
		ll now=s[i]-'a';
		a[now].push_back(i+1);
	}
	for(ll i=0;i<26;i++){
		sort(a[i].begin(),a[i].end());
	}
	ll ans=0;
	ll cnt=1;
	for(ll i=0;i<t.size();i++){
		ll now=t[i]-'a';
		if(a[now].size()==0){
			cout << -1;
			return 0;
		}
		auto itr=lower_bound(a[now].begin(),a[now].end(),cnt);
		if(itr==a[now].end()){
			ans+=s.size()-cnt+1;
			itr=a[now].begin();
			ans+=*itr;
			cnt=*itr+1;
		}
		else{
			ans+=*itr-cnt+1;
			cnt=*itr+1;
		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

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

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int N; cin >> N;
    VI A(N);
    REP(i,N)
    {
        cin >> A[i];
    }

    //B1
    ll B1=0;
    int n=1;
    REP(i,N)
    {
        B1 += A[i] * n;
        n *= -1;
    }
    cout << B1 << " ";
    
    ll B = B1;
    REP(i, N-1)
    {
        B = 2*A[i]-B;
        cout << B << " ";
    }
    cout << endl;
  
    return 0;
}



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

int main() {
  int n, a;
  cin >> n >> a;
  vector<int> x(n);
  for (auto &i : x) {
    cin >> i;
  }

  vector<vector<vector<lint>>> dp(2, vector<vector<lint>>(n + 2, vector<lint>(3000, 0))); // dp[pos][picked][sum]

  dp[n & 1][0][0] = 1;

  for (int i = n - 1; i >= 0; i--) {
    for (int picked = 0; picked <= n; picked++) {
      for (int sum = 0; sum < 2600; sum++) {
        dp[i & 1][picked][sum] = dp[(i + 1) & 1][picked][sum];;
      }
    }
    for (int picked = 1; picked <= n; picked++) {
      for (int sum = x[i]; sum <=2600; sum++) {
        dp[i & 1][picked][sum] += dp[(i + 1) & 1][picked - 1][sum - x[i]];
      }
    }
  }

  lint ans = 0;
  for (int picked = 1; picked <= n; picked++) {
    ans += dp[0][picked][a * picked];
  }

  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 


// int dp[305][305];
int main() {
  int n; cin >> n;
  vvi a(n, vi(n));
  rep(i,n) rep(j,n) cin >> a[i][j];
  // fill(dp, sizeof(dp), INF):
  vector<vll> dp(n, vll(n, INF));
  rep(i, n) rep(j, n) {
    dp[i][j] = a[i][j];
  }
  rep(k, n) rep(i, n) rep(j, n) chmin(dp[i][j], dp[i][k] + dp[k][j]);

  // rep(i, n){
      // rep(j, n) {
        // cout << dp[i][j] << " ";
      // }
    // cout << endl;
  // }
  rep(i, n) rep(j, n) {
    if (i==j) continue;
    if (dp[i][j] < a[i][j]) {
      cout << -1 << endl;
      return 0;
    }
  }
  ll ans = 0;
  rep(i, n) rep(j, n) ans+=a[i][j];
  rep(i,n) {
    rep(j, n) {
      if (i==j )continue;
      int path = a[i][j];
      rep(k,n) {
        if (k==i || k==j) continue;
        ll detour = dp[i][k] + dp[k][j];
        if (detour == path) {
          ans -= path;
          break;
        } if (detour < path) {
          cout << -1 << endl;
          return 0;
        }
      }
    }
  }
  ans /=2;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 4756
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    ll pt = 0, px = 0, py = 0;
    bool ans = true;
    rep(i, n){
        ll t, x, y; cin >> t >> x >> y;
        ll dx = abs(x-px);
        ll dy = abs(y-py);
        ll dt = abs(t-pt);
        px = x; py = y; pt = t;
        if(dt<(dx+dy)) ans = false;
        if(dt%2 != (dx+dy)%2) ans = false;
    }
    (ans) ? Yes() : No();
}

Measured memory_bytes: 256
char r[99],*R,g[99],*G,d[99],*D;main(c){for(;scanf("%s%s%s",r,g,d)>1;puts(G))for(D=d,R=r,G=g,c=*G++;*(G-1);)c==*D?*D++,c=*R++:(putchar(c),c=*G++);exit(0);}

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

int main() {
  int A, B;
  cin >> A >> B;
  int c=0;
  int x;
  for (int N=A; N<=B; N++) {
    int y=N, M=0;
    
    while (y>0) {
    x = y%10;
    y = y/10;
    M = M*10 + x;
    }

    if (N == M) {
      c++;
    }
    
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int cmp(const void *a,const void *b){
    return *(int*)a-*(int*)b;
}
int main(void){
    int n;
    int i,sum=0,t;
    int s[100];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&s[i]);
    }
    for(i=0;i<n;i++){
        sum+=s[i];
    }
    qsort(s,n,sizeof(s[0]),cmp);
    //for(i=0;i<n;i++)printf("%d\n",s[i]);

    if(sum%10!=0){
        printf("%d\n",sum);
        return 0;
    }
    i=0;
    while(1){
        if(i==n){
            sum=0;
            break;
        }
        if((sum-s[i])%10!=0){
            sum=sum-s[i];
            break;
        }
        i++;
    }
        printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int sum = 0;

    	for(int i =0 ;i<2;i++){

    		if(A>B){
    			sum += A;
    			A--;
    		}else{
    			sum += B;
    			B--;
    		}

    		    	}

    	System.out.println(sum);



}

}

Measured memory_bytes: 22612