akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int n;
    cin >> n;
    int h;
    int prev = 0, tmp = 0;
    int ans = 0;
    rep(i, n) {
        cin >> h;
        if (h <= prev) {
            tmp++;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }
        prev = h;
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int a, b, x;
  scanf("%d %d %d", &a, &b, &x);
  if(x>=a){
    if(x-a<=b){
      printf("YES");
    }else if(x-a>b){
      printf("NO");
    }
  }else if(x<a){
    printf("NO");
  }
  return 0;
}

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

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

//read_kaisetsu
int main() {
    int n;cin>>n;
    int c_a = 0;
    int c_b = 0;
    int c_ab = 0;
    int ans = 0;
    
    rep(i,n){
        string s;cin>>s;
        int m = s.size();
        rep(j,m-1)if(s[j]=='A' && s[j+1] =='B')++ans;
        if(s[m-1]=='A' && s[0]=='B')++c_ab;
        else if(s[0]=='B')++c_b;
        else if(s[m-1]=='A')++c_a;
    }
    int ans2 = c_ab + min(c_a, c_b);
    if(c_ab > 0 && c_a == 0 && c_b ==0)--ans2;
    cout<<ans + ans2<<endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9
typedef pair<int, int> p;

p pos[900001]; // 値Kが書かれている座標(i,j)
int H, W, D;
int Q; // クエリ数
int L[100000];
int R[100000];

int cost[900001]; // cost[i] : 駒を(i%D)が書かれたマスからiが書かれたマスまでDずつ移動させるときのコスト

void input() {
	cin >> H >> W >> D;
	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			int a; cin >> a;
			pos[a].first = i;
			pos[a].second = j;
		}
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) cin >> L[i] >> R[i];
}

void preparation() {
	for (int i = 1; i <= D; i++) {
		int k = 0;
		while (i + (k+1) * D <= H*W) {
			p c_pos = pos[i + k * D]; // 移動前
			p n_pos = pos[i + (k + 1)*D]; // 移動先

			cost[i + (k + 1)*D] = cost[i + k * D] + abs(c_pos.first - n_pos.first) + abs(c_pos.second - n_pos.second);
			k++;
		}
	}
}

void solve() {
	for (int i = 0; i < Q; i++) {
		cout << cost[R[i]] - cost[L[i]] << " ";
	}
}

int main() {
	input();
	preparation();
	solve();

	return 0;
}

Measured memory_bytes: 5504
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;

int main(){

  int n;cin>>n;
  map<int,int>mp;
  rep(i,0,n){
    int a;cin>>a;
    rep(j,a-1,a+2)mp[j]++;
  }

  int ma=0;
  for(map<int,int>::iterator itr=mp.begin();itr!=mp.end();itr++){
    ma=max(ma,itr->second);
  }

  out(ma);

  return 0;
}


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

int main(){
  string s[3];
  for(int i=0;i<3;++i){
    cin >> s[i];
  }
  
  int turn =0;
  while(true){
    int now = turn;
    if(s[now].empty())break;
    turn = s[now][0] -'a';//s[now][0]==s[i].at(0)
    s[now].erase(0,1);
  }
  if(turn == 0)cout << 'A' << endl;
  else if(turn == 1)cout << 'B' << endl;
  else cout << 'C' << endl;
  
}


Measured memory_bytes: 256
import numpy as np
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
s = [[a%10,a//10*10+10,a],[b%10,b//10*10+10,b],[c%10,c//10*10+10,c],[d%10,d//10*10+10,d],[e%10,e//10*10+10,e]]
s.sort()
for i in range(5):
    if s[0][0] == 0:
        s[0][1]-=10
        s.append(s.pop(0))
    else:
        break
s = np.array(s)
ans = s[0][2] + sum(s[1:,1])
print(ans)

Measured memory_bytes: 27084
def resolve():
    n, l, t = map(int, input().split())
    lx, lw = [], []
    while True:
        try:
            x, w = map(int, input().split())
            lx.append(x)
            lw.append(w)
        except EOFError:
            break
    cnt = 0
    zero = 0
    x0 = lx[0]
    if lw[0] == 1:
        for i in range(1, n):
            if lw[i] == 2 and t * 2 >= lx[i] - lx[0]:
                cnt += (t * 2 - (lx[i] - lx[0])) // l + 1
        for i in range(n):
            if lw[i] == 1:
                lx[i] = (lx[i] + t) % l
            else:
                lx[i] = (lx[i] - t) % l
        slx = sorted(lx)
        for i in range(n):
            if (x0 + t) % l == slx[i]:
                zero = (i - cnt) % n
        for i in range(n):
            print(slx[(zero + i) % n])
    else:
        for i in range(1, n):
            if lw[i] == 1 and t * 2 >= l + lx[0] - lx[i]:
                cnt += (t * 2 - (l + lx[0] - lx[i])) // l + 1
        for i in range(n):
            if lw[i] == 1:
                lx[i] = (lx[i] + t) % l
            else:
                lx[i] = (lx[i] - t) % l
        slx = sorted(lx)
        for i in range(n-1, -1, -1):
            if (x0 - t) % l == slx[i]:
                zero = (i + cnt) % n
        for i in range(n):
            print(slx[(zero + i) % n])
resolve()

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

int main(){
  int N,Q;
  string S;
  cin>>N>>Q>>S;
  int count=0;
  vector<int> AC(N,0);
  for (int i=0;i<N-1;i++){
    if (S.at(i)=='A'){
      if (S.at(i+1)=='C'){
        count++;
      }
    }
    AC.at(i+1)=count;
  }
  int l,r;
  for (int i=0;i<Q;i++){
    cin>>l>>r;
    cout<<AC.at(r-1)-AC.at(l-1)<<endl;
  }
}

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

int main(){
    int n, k;
    string s;
    cin >> n >> k >> s;
    vector<int> v;
    if(s[0] != '1') v.push_back(0);
    int pos = 0;
    while(pos < n){
        int to = pos;
        while(to+1 < n && s[pos] == s[to+1])  to++;
        v.push_back(to-pos+1);
        pos = to+1;
    }
    if(s.back() != '1') v.push_back(0);
    int sum = 0;
    for(pos = 0; pos < v.size() && pos < 2*k+1; pos++){
        sum += v[pos];
    }
    int l = 0, ans = sum;
    while(pos < v.size()){
        sum -= v[l++];
        sum -= v[l++];
        sum += v[pos++];
        sum += v[pos++];
        ans = max(ans, sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}
// const int MOD = 2019;
long long qpow(long long a, long long b) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}

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

    LL x;
    cin >> x;
    map<LL, LL> m;
    for (LL i = -1000; i <= 1000; i++) {
        LL p5 = qpow(i, 5);
        // cout << i << ":" << p5 << '\n';
        if (m.count(p5 - x)) {
            cout << i << " " << m[p5 - x] << '\n';
            // cout << p5 << " " << qpow(i, 5) << '\n';
            break;
        }
        m[p5] = i;
    }

    return 0;
}


Measured memory_bytes: 3680
#include <algorithm>
#include <iostream>
using namespace std;
int dp[100005], a[100005], n;
int LIS_nlgn() {
  int len = 1;dp[0] = a[0];
  for (int i = 1; i < n; ++i) {
    if (a[i] >= dp[len - 1]) dp[len++] = a[i];
    else {
      *upper_bound(dp, dp + len, a[i]) = a[i];
    }
  }
  return len;
}
int main() {
  cin >> n;
  for (int i = n - 1; i >= 0; i--) cin >> a[i];
  cout << LIS_nlgn() << endl;
}

Measured memory_bytes: 1024
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<long long> x(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i];

    }
    if (n == 1) {
        cout << abs(x[0]) << endl;
        return 0;
    }
    long long minx = 10000000000;

    for (int left = 0; left + k - 1 < n; left++) {
        int right = left + k - 1;
        long long cost = 0;
        if (x[left] >= 0) {
            cost = x[right];
        }
        else if (x[right] >= 0) {
            cost = x[right] - x[left] + min(x[right], -x[left]);
        }
        else {
            cost = -x[left];
        }
        minx = min(minx, cost);
    }
    cout << minx << endl;
    return 0;
}

Measured memory_bytes: 1024
n=str(input())
s=len(n)
if n[s-1]=="2" or n[s-1]=="4" or n[s-1]=="5" or n[s-1]=="7" or n[s-1]=="9":
    print("hon")
elif n[s-1]=="0" or n[s-1]=="1" or n[s-1]=="6" or n[s-1]=="8":
    print("pon")
else:
    print("bon")

Measured memory_bytes: 9060
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define All(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
#define IN(a, b, x) (a<=x&&x<b)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<ll>>;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename t, typename u, typename Comp=less<>>
bool chmax(t& xmax, const u& x, Comp comp={}) { if(comp(xmax, x)) { xmax = x; return true; } return false;}
template<typename t, typename u, typename Comp=less<>>
bool chmin(t& xmin, const u& x, Comp comp={}) { if(comp(x, xmin)) { xmin = x; return true;} return false;}
const int INF = 1e9;
const ll infl = ll(1e18)+5;
/*
*ios::sync_with_stdio(false);
*cin.tie(0);
*/

int main(){
  string s;
  int k= 0;
  cin >> k >> s;
  
  if(s.size() <= k) cout << s << endl;
  else{
    string ss = s.substr(0,k);
    cout << ss << "..." << endl;
  }
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;



int main() {
  int r,g,b;
  	ci(r>>g>>b);
  int n;
  	ci(n);
  int ans=0;
  
 FOR(i,0,n+1){
   FOR(j,0,n+1){
     int now=(i*r+j*g);
    
     if((n-now)%b==0&&now<=n){
	ans++;
     }
     }
   }
 
  co(ans)
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b;
  int ans;
  scanf("%d%d",&a,&b);
  if((a+b)%2!=0){
    puts("IMPOSSIBLE");
  }
  else{
    ans=(a+b)/2;
    printf("%d",ans);
  }
  return 0;
}

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

struct day{
    int option1;
    int option2;
    int option3;
};

int findmaxhap(vector<day> &vacation)
{
    int n = vacation.size();
    vector<day> cumulative(n);
    cumulative[0].option1 = vacation[0].option1;
    cumulative[0].option2 = vacation[0].option2;
    cumulative[0].option3 = vacation[0].option3;
    for (int i = 1; i < n; i++)
    {
        cumulative[i].option1 = vacation[i].option1 + max(cumulative[i - 1].option2, cumulative[i - 1].option3);
        cumulative[i].option2 = vacation[i].option2 + max(cumulative[i - 1].option1, cumulative[i - 1].option3);
        cumulative[i].option3 = vacation[i].option3 + max(cumulative[i - 1].option1, cumulative[i - 1].option2);
    }
   
    return max(cumulative[n-1].option1, max(cumulative[n-1].option2, cumulative[n-1].option3));
}
int main()
{
    int n;
    cin >> n;
    vector<day> vacation(n);
    for (int i = 0; i < n; i++)
    {
        cin >> vacation[i].option1;
        cin >> vacation[i].option2;
        cin >> vacation[i].option3;
    }
    cout << findmaxhap(vacation);
    return 0;
}

Measured memory_bytes: 5600
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let h: usize = read();
    let w: usize = read();
    let k: usize = read();
    let mut maps: Vec<Vec<char>> = Vec::new();

    for _ in 0..h {
        let s = (&read::<String>()).chars().collect();
        maps.push(s);
    }

    let mut ans = 0;
    for i in 0..(1 << h) - 1 {
        for t in 0..(1 << w) - 1 {
            let mut black = 0;
            for row in 0..h {
                for column in 0..w {
                    if (i >> row & 1) == 0 && (t >> column & 1) == 0 && maps[row][column] == '#' {
                        black += 1;
                    }
                }
            }
            if black == k {
                ans += 1;
            }
        }
    }
    print!("{}", ans);
}


Measured memory_bytes: 2120
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    cout<<endl;
    string s;
    for(int i=0;i<h;i++){
        cin>>s;
        cout<<"#"<<s<<"#"<<endl;
    }
    for(int i=0;i<w+2;i++){
        cout<<"#";
    }
    
}


Measured memory_bytes: 256
n=int(input())
a=sorted(list(map(int,input().split())))
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
b=groupby(a)
l=len(b)
if l==1:
    print(b[0][1])
elif l==2:
    if b[1][0]-b[0][0]>1:
        print(max(b[1][1],b[0][1]))
    else:
        print(b[1][1]+b[0][1])
else:
    m=0
    for i in range(l-2):
        x=b[i+1][1]
        if b[i+1][0]-b[i][0]==1:
            x+=b[i][1]
        if b[i+2][0]-b[i+1][0]==1:
            x+=b[i+2][1]
        m=max(m,x)
    print(m)


Measured memory_bytes: 13964
package main

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

func parseInt(s string) (n int) {
	n, _ = strconv.Atoi(s)
	return n
}

func main() {
	var n, x, t int
	fmt.Scan(&n)
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	w := make([]int, n)
	for i := range w {
		s.Scan()
		w[i] = parseInt(s.Text())
		t += w[i]
	}
	mid := t / 2

	for i := 0; i < n; i++ {
		x += w[i]
		if x > mid {
			if x-mid < mid-(x-w[i]) {
				fmt.Println(x - (t - x))
				break
			} else {
				fmt.Println(t - 2*(x-w[i]))
				break
			}
		}
	}
}


Measured memory_bytes: 640
/*
    author: Salam_35
    Created at :

*/

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

/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    
    string s;
  cin >> s;
  cout<<s[0]<<s[1]<<s[2]<<endl;
}
/*
         remember:
         ll vs int
         array size
         case for 1 2 3 
*/


Measured memory_bytes: 3632
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
									`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	a := make([]int, n)
	a0 := 0

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		if i%2 == 0 {
			a0 += a[i]
		} else {
			a0 -= a[i]
		}
	}

	ans := make([]string, n)
	ans[0] = strconv.Itoa(a0)

	for i := 1; i < n; i++ {
		a0 = 2*a[i-1] - a0
		ans[i] = strconv.Itoa(a0)
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, strings.Join(ans, " "))
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}


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

#define INF INT32_MAX

int main()
{
	long long L, R;

	cin >> L >> R;

	long long ans = INF;
	R = min( R, L + 2019 );
	for( long long i = L; i <= R - 1; i++ ) {
		for( long long j = i + 1; j <= R; j++ ) {
			ans = min( ans, (i * j) % 2019 );
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#define S true
#define W false
using namespace std;
int N;
string s;
bool ans[100000];
bool check(){

  for(int i=1;i<=N-1;i++){
    if(s[i]=='o'){
      if(ans[i]==S){
	if(ans[(i+1)%N]!=ans[i-1])return false;
      }
      else{
	if(ans[(i+1)%N]==ans[i-1]) return false;
      }
    }
    else{
      if(ans[i]==S){
	if(ans[(i+1)%N]==ans[i-1])return false;
      }
      else{
	if(ans[(i+1)%N]!=ans[i-1]) return false;
      }
    }
  }
  if(s[0]=='o'){
    if(ans[0]==S){
      if(ans[1]==ans[N-1])return true;
      else return false;
    }
    else{
      if(ans[1]!=ans[N-1])return true;
      else return false;
    }
    
  }
  else{
     if(ans[0]==S){
      if(ans[1]!=ans[N-1])return true;
      else return false;
    }
     else{
      if(ans[1]==ans[N-1])return true;
      else return false;
    }
  }

  
}

bool func(){
  for(int i=1;i<N-1;i++){
    if(s[i]=='o'){
      if(ans[i]==S){ans[i+1]=ans[i-1];}
      else {ans[i+1]=!ans[i-1]; }
    }
    else if(s[i]=='x'){
      if(ans[i]==S){ans[i+1]=!ans[i-1];}
      else {ans[i+1]=ans[i-1];}
    }
  }
  return check();
}
int main(){
  cin >> N;
  cin >> s;

  ans[0]=S;
  ans[1]=S;
  if(func()){
    for(int i=0;i<N;i++){
      if(ans[i]==S)cout << 'S';
      else cout << 'W';
    }
    cout << endl;
    return 0;
  }
  
  ans[0]=S;
  ans[1]=W;
  if(func()){
    for(int i=0;i<N;i++){
      if(ans[i]==S)cout << 'S';
      else cout << 'W';
    }
    cout << endl;
    return 0;
  }
  
  ans[0]=W;
  ans[1]=S;
  if(func()){
    for(int i=0;i<N;i++){
      if(ans[i]==S)cout << 'S';
      else cout << 'W';
    }
    
    cout << endl;
    return 0;
  }
  
  ans[0]=W;
  ans[1]=W;
  if(func()){
    for(int i=0;i<N;i++){
      if(ans[i]==S)cout << 'S';
      else cout << 'W';
    }
    cout << endl;
    return 0;
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 640
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int64_t rll() {
	long long n;
	scanf("%lld", &n);
	return n;
}

int main() {
	int l = ri();
	int r = ri();
	if (r - l + 1 >= 2019) {
		std::cout << 0 << std::endl;
		return 0;
	}
	int res = 1000000000;
	for (int i = l; i <= r; i++) {
		for (int j = l; j < i; j++) {
			res = std::min<int>(res, (int64_t) i * j % 2019);
		}
	}
	std::cout << res << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

#define repeat_with_index(n, i) for(int i=0;i<n;i++)
#define repeat(n) for(int __i=0;__i<n;__i++)
#define repete_from_to(from, to, i) for(int i=from;i<=to;i++)
#define multi_cin(n, array) repeat_with_index(n,i){cin>>array[i];}
#define assign_if_smaller(var, val) if(var>val)var=val;
#define assign_if_larger(var, val) if(var<val)var=val;

using namespace std;

int coin_value[] = {1, 5, 10, 50, 100, 500};

int pay_count(int price, int *coins) {
  int count = 0;

  repeat_with_index(6, i) {
    int _count = min(price / coin_value[5 - i], coins[5 - i]);
    price -= _count * coin_value[5 - i];
    count += _count;
  }

  if (price != 0) return -1;

  return count;
}

int change_count(int price) {
  int count = 0;

  repeat_with_index(6, i) {
    int _count = price / coin_value[5 - i];
    price -= _count * coin_value[5 - i];
    count += _count;
  }

  return count;
}

int main(int argc, char const* argv[])
{
  while (true) {
    int price; cin >> price;
    if (price == 0) break;

    int coins[6];
    multi_cin(6, coins);

    int count = 6000;

    repete_from_to(price, price + 499, p) {
      int p_count = pay_count(p, coins);
      if (p_count == -1) continue;

      int c_count = change_count(p - price);

      assign_if_smaller(count, p_count + c_count);
    }

    cout << count << endl;
  }
  return 0;
}

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

int main() {
  int N;
  cin >> N;
  if(N / 10 == 0) {
    cout << N << endl;
  }
  else if(N/100 == 0) {
    cout << 9 << endl;
  }
  else if(N/1000 == 0) {
    cout << 9 + (N-99) << endl;
  }
  else if(N/10000 == 0) {
    cout << 909 << endl;
  }
  else if(N == 100000){
    cout << 90909 << endl;
  }
  else {
    cout << 909 + (N-9999);
  }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class A
{
	public static void Main()
	{
		string S = Console.ReadLine();
		int ans = 700;
		for(int i = 0; i < 3; i++)
			if(S[i] == 'o')
				ans += 100;

		Console.WriteLine(ans);
	}
}





Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i=s;i<n;++i)
#define drep(i,s,n) for (int i=n;i>=s;--i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;
int gcd(int a,int b)
{if (a%b == 0) return(b);
 else          return(gcd(b,a%b));}
int lcm(int a,int b)
{return a*b/gcd(a,b);}
void printv(vector<auto> v) {cout<<'[';rep(i,0,v.size()){cout<<v[i]<<',';}cout<<']'<<endl;}
void printvv(vector<vector<auto>> vv)
{
  cout<<'['<<endl;
  rep(q,0,vv.size()){cout<<'[';rep(p,0,vv.at(q).size())cout<<vv.at(q).at(p)<<',';cout <<']'<<endl;}
  cout<<']'<<endl;
}
void solve(); int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}
int step_x[] = {-1,0,0,1};
int step_y[] = {0,-1,1,0};
const long long INF = 1000000;
//------------------------------------------------------------
ll n,m,num;
void solve()
{
    cin >> n >> m;
    vector<ll> v(1000000);
    vector<ll> dp(1000000);
    rep(i,0,m) {cin >> v[i];}

    dp[0]=1;
    num=0;

    rep(i,1,n+1)
    {
      // iが1で床がる
      if(i==1&&find(all(v), 1)==v.end())
      {
        dp[1]=1;
      }
      // iは床がある
      else if(i!=v[num])
      {
        dp[i]=dp[i-1]+dp[i-2];
      }
      else{
        dp[i]=0;
        num++;
      }
      dp[i]%=1000000007;
    }

    print(dp[n]);

    return;
}



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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << (a + b) % 24 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include<complex>

#define EPS 1e-10

using namespace std;
typedef complex<double> P;

static inline double outp(const P &a, const P &b){
  return (conj(a)*b).imag();
}

int main(){
  int n;
  int cc = 1;
  while(scanf("%d", &n), n){
    vector<P> p(n);
    double ans = 0.0;

    REP(i,n){
      double x, y;
      scanf("%lf%lf", &x, &y);
      p[i] = P(x, y);
    }

    REP(i,n){
      int j = (i + 1) % n;
      ans += outp(p[i], p[j]) / 2.0;
    }

    printf("%d %.1f\n", cc++, std::abs(ans));
  }
  return 0;
}

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

int able(int clas,int a,int b);

int main(void){
	int N,A,B,clas,res=0;

	cin>>N>>A>>B;

	for(int i=0;i<N;i++){
	cin>>clas;
	res = res + able(clas,A,B);
	}

	cout<<res<<endl;
	return 0;
}

int able(int clas,int a,int b){
	if(clas<a||clas>=b)return 1;
	else return 0;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# 解説AC
# https://img.atcoder.jp/abc143/editorial.pdf
N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

A = np.array(A, dtype=int)
C = np.bincount(A, minlength=N + 2)
D = np.bincount(C, minlength=N + 2)

ld = (D * np.arange(len(D))).cumsum()
ud = D[::-1].cumsum()[::-1]

X = np.arange(1, N + 1, dtype=int)
# L[x]: x 回取れるときの最大の長さ k
L = np.zeros(N + 1, dtype=int)
L[X] = (ld[X] + X * ud[X + 1]) // X

i = len(L) - 1
for k in range(1, N + 1):
    while i > 0 and L[i] < k:
        i -= 1
    print(i)


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


def main():
    """Function."""
    a, b = map(str, input().split())

    if a == "H":
        if b == "H":
            print("H")
        else:
            print("D")
    if a == "D":
        if b == "H":
            print("D")
        else:
            print("H")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
function Main(input){
  input=input.trim().split(/\s+/).map(x=>x-0);
  var N=input.shift();
  var M=input.shift();
  var X=input.shift();
  var d=0, u=M-1;
  var m=Math.floor((d+u)/2);
  while(d<=u){
    if(X<input[m])u=m-1;
    else d=m+1;
    m=Math.floor((d+u)/2);
  }
  console.log(Math.min(m+1,M-m-1));
}

Main(require('fs').readFileSync('/dev/stdin','utf8'));


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

int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K<=A){
    cout << K << endl;
  }
  else if(K<=B){
    cout << A << endl;
  }
  else{
    cout << 2*A+B-K << endl;
  }
}

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

using namespace std;

priority_queue<int> a;
int n,m;

void disCount();
void printSum();

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        a.push(x);
    }
    disCount();
    printSum();
    return 0;
}
void disCount() {
    for (int i = 0; i < m; i++) {
        int x = a.top();
        a.pop();
        a.push(x / 2);
    }
}

void printSum() {
    long long res = 0;
    for (int i = 0; i < n; i++) {
        res += a.top();
        a.pop();
    }
    cout << res;
}


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

using namespace std;

#define ll long long
#define pb push_back
#define F first
#define S second
#define rf(i,a,b) for(int (i) = (a); (i) <= (b); (i)++)
#define rb(i,b,a) for(int (i) = (b); (i) >= (a); (i)--)
#define watch(x) cout << (#x) << " = " << (x) << endl
#define test(t) int(testCnt) = 0; int(t); cin >> (t); while(t -- && ++testCnt)

const int INF = 2e9 + 7;
const int MAXA = 1e5 + 10;
const ll MOD = (ll) 1e9 + 7;
const ll INFLL = 9e18 + 7;

typedef pair<int, int> ii;
typedef pair<ii, int> II;
typedef vector<int> vi;
typedef vector<ii> vii;

int n, k, a[MAXA];
bool f[MAXA];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        //freopen("in.in", "r", stdin);
    #endif
    cin >> n;
    cin >> k;
    rf(i, 1, n) cin >> a[i];
    sort(a + 1, a + n + 1);
    rf(i, a[1], k) {
        rf(j, 1, n) {
            if(i >= a[j] && f[i] != 1){
                //cout << i << endl;
                f[i] =  1 - f[i - a[j]];
            }
        }
    }
    //rf(i, 1, k) cout << f[i] << " "; cout << endl;
    if(f[k]) cout << "First";
    else cout << "Second";
    return 0;
}


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

int main(){
   ll n,k;
   cin>>n>>k;
   vector<ll> a(n);
   rep(i,n) cin>>a[i];

   ll p=0;
   ll q=1e9;
   while(q-p!=1){
      ll c=(p+q)/2;
      ll j=0;
      rep(i,n){
         j+=(a[i]+c-1)/c;
         if((a[i]+c-1)/c) j--;
         if(j>k) break;
      }
      if(j>k) p=c;
      else q=c;
   }
   cout<<q<<endl;
}

Measured memory_bytes: 4844
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)

using namespace std;

inline int Read(){
	char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	int x = c - '0'; c = getchar();
	while(c <= '9' && c >= '0') x = x * 10 + c - '0', c = getchar();
	return x;
}

const int N = 200010;

struct Graph{
	int Begin[N], Next[N << 1], to[N << 1], e;

	Graph(){
		e = 0;	
	}
	
	void add(int u, int v){
		to[++e] = v, Next[e] = Begin[u], Begin[u] = e;
		to[++e] = u, Next[e] = Begin[v], Begin[v] = e;
	}
}A, B;

int depa[N], depb[N], fa[N];
bool vis[N];

void DFSA(int o, int f = 0){
	for(int i = A.Begin[o]; i; i = A.Next[i]){
		int u = A.to[i];
		if(u == f) continue;
		depa[u] = depa[o] + 1;
		fa[u] = o;
		DFSA(u, o);
	}
}

bool check(int u, int v){
	int d = 0;
	if(depa[u] < depa[v]) swap(u, v);
	while(depa[u] > depa[v] && d < 3) u = fa[u], ++d;
	while(u != v && d < 3) u = fa[u], v = fa[v], d += 2;
	return d > 2;
}

int ans;

void DFSB(int o, int f = 0){
	ans = max(ans, depa[o]);
	vis[o] = true;
	for(int i = B.Begin[o]; i; i = B.Next[i]){
		int u = B.to[i];
		if(u == f) continue;
		depb[u] = depb[o] + 1;
		if(depa[u] <= depb[u]) continue;
		DFSB(u, o);
	}
}

int n, p, q;

int main(){
	n = Read(), q = Read(), p = Read();
	For(i, 2, n){
		int u = Read(), v = Read();
		B.add(u, v);
	}
	For(i, 2, n){
		int u = Read(), v = Read();
		A.add(u, v);
	}
	DFSA(p), DFSB(q);
	For(i, 1, n - 1){
		int u = B.to[i * 2], v = B.to[i * 2 - 1];
		if((vis[u] || vis[v]) && check(u, v)){
			puts("-1");
			return 0;
		}
	}
	printf("%d\n", ans * 2);
	return 0;
}

Measured memory_bytes: 19072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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


  ll n;
  cin >> n;
  vector<int> b(n);    
  rep(i,n){
    cin >> b[i];   
  }
  vector<int> ans;
  bool ok = true;
  while(ok && !b.empty()){
    for(int i=b.size()-1;i>=0;i--){
      if(b[i]==i+1){
	//	auto it = b+i;
	b.erase(b.begin()+i);
	ans.pb(i+1);
	break;
      }
      if(i==0) ok=false;
    }
  }
  if(ok){
    for(int i=ans.size()-1;i>=0;i--){
      cout << ans[i] << endl;
    }    
  }
  else cout << -1 << endl;
  return 0;
    

}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

// #define INF 1e+9
// #define MAX_N 100050

// int dp[MAX_N];
// int n;
// vector<int> a;

// void LIS() {
//     fill(dp, dp+n, INF);
//     for (int i=0; i<n; ++i) {
//         *lower_bound(dp, dp+n, a[i]) = a[i];
//     }
//     cout << lower_bound(dp, dp+n, INF) - dp << endl;
// }

int ans[200020];
int a[200020];
vector<vector<int>> v(200020);
int dp[200020];
int INF = 1e9;
int n;

void dfs(int p, int pre){
    auto itr = lower_bound(dp,dp+n,a[p]);
    int tmp = *itr;
    *lower_bound(dp,dp+n,a[p]) = a[p];
    ans[p] = lower_bound(dp,dp+n,INF)-dp;
    for(auto i:v[p]){
        if(i == pre)continue;
        dfs(i,p);
    }
    *itr = tmp;
}

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

    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        dp[i] = INF;
    }
    for(int i=1;i<n;i++){
        int x,y;
        cin>>x>>y;
        x--,y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    dfs(0,-1);
    for(int i=0;i<n;i++){
        cout << ans[i] << "\n";
    }
    


}

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

int main() {
  int N;
  cin >> N;
  int i;
  string ans;
  if (N < 1200) {
    ans = "ABC";
  } else if (N < 2800) {
    ans = "ARC";
  } else {
    ans = "AGC";
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
using System;
class Prpgram
{
    static void Main(string[] args)
    {
        string inputA = Console.ReadLine();
        string inputB = Console.ReadLine();

        int A = int.Parse(inputA);
        int B = int.Parse(inputB);

        int ans = 6 - (A + B);
        Console.Write(ans);    
    }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

void dfs(int pos, LL cost);

vector< pair<int, LL> > tree[SIZE];
LL k_dist[SIZE];
bool visit[SIZE];

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

    int n;
    cin >> n;

    for( int i = 0; i < n - 1; ++i ) {
        int a, b;
        LL cost;
        cin >> a >> b >> cost;

        tree[a].pb(MP(b, cost));
        tree[b].pb(MP(a, cost));
    }

    int q, k;
    cin >> q >> k;
    dfs(k, 0);
    
    for( int i = 0; i < q; ++i ) {
        int x, y;
        cin >> x >> y;
        cout << k_dist[x] + k_dist[y] << endl;

    }

    return 0;
}

void dfs(int pos, LL cost) {
    if( visit[pos] ) {
        return;

    }
    visit[pos] = true;
    k_dist[pos] = cost;
    for( int i = 0; i < tree[pos].size(); ++i ) {
        dfs(tree[pos][i].F, cost + tree[pos][i].S);

    }

    return;
}



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


int main(){
	    int N; cin >> N;
        vector<int> A(N, 0);
        vector<ll> cnt(N, 0);
        ll sum = 0;
        rep(i, N){
            int a; cin >> a;
            a--;
            A[i] = a;
            cnt[a]++;
        }

        rep(i, N){
            if(cnt[i] == 0 || cnt[i] == 1) continue;
            sum += cnt[i] * (cnt[i] - 1) / 2;
        }

        rep(i, N){
            cout << sum - (cnt[A[i]] - 1) << endl;
        }
}


Measured memory_bytes: 4992
#include<cstdio>
#include<iostream>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<list>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<iomanip>
#include<fstream>
#include<ctime>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;

map<LL, int> mapa;
int n, i, a;
LL sum, res;

int main() {
scanf("%d", &n);
mapa.clear();
mapa[0] = 1;
sum = 0;
res = 0;
for (i=0;i<n;i++) {
	scanf("%d", &a);
	sum += a;
	res += mapa[sum];
	mapa[sum]++;
}
printf("%lld\n", res);
return 0;
}



Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  ll ans = 0;
  ans += b*(a/(b+c));
  a -= (a/(b+c))*(b+c);
  //cout << ans << a << endl;
  if(a > b){
    cout << ans + b << endl;
  }
  else{
    cout << ans + a << endl;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>

int main(){
	int n, f = 0;
	std::cin >> n;
	while(n--){
		if(f++)std::cout << "\n";
		int sudoku[9][9], map[9][9];
		memset(map, 0, sizeof(map));
		for(int i=0;i<81;i++)
			std::cin >> sudoku[i/9][i%9];
		
		int check[10][2];

		for(int i=0;i<9;i++){
			memset(check, -1, sizeof(check));
			for(int j=0;j<9;j++){
				int x = check[sudoku[i][j]][1],
					y = check[sudoku[i][j]][0];
				if(x != -1){
					map[y][x] = 1;
					map[i][j] = 1;
				}
				
				check[sudoku[i][j]][0] = i;
				check[sudoku[i][j]][1] = j;
			}
		}
		
		for(int i=0;i<9;i++){
			memset(check, -1, sizeof(check));
			for(int j=0;j<9;j++){
				int x = check[sudoku[j][i]][1],
					y = check[sudoku[j][i]][0];
				if(x != -1){
					map[y][x] = 1;
					map[j][i] = 1;
				}
				
			check[sudoku[j][i]][0] = j;
			check[sudoku[j][i]][1] = i;
			}
		}
		
		for(int i=0;i<9;i++){
			int sx = i % 3, sy = i / 3;//¶ãÌî_
			memset(check, -1, sizeof(check));
			for(int j=0;j<3;j++){
				for(int k=0;k<3;k++){
					int x = check[sudoku[sy*3+j][sx*3+k]][1],
						y = check[sudoku[sy*3+j][sx*3+k]][0];
					if(x != -1){
						map[y][x] = 1;
						map[sy*3+j][sx*3+k] = 1;
					}
					
					check[sudoku[sy*3+j][sx*3+k]][0] = sy*3+j;
					check[sudoku[sy*3+j][sx*3+k]][1] = sx*3+k;
				}
			}
		}
		
		for(int i=0;i<9;i++){
			for(int j=0;j<9;j++){
				if(map[i][j])
					std::cout << "*" << sudoku[i][j];
				else
					std::cout << " " << sudoku[i][j];
			}
			std::cout << "\n";
		}
	}
        return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
char inp[100005];
int main(){
	scanf("%s",inp);
	int n=strlen(inp),l=0,r=n-1,la=0,ra=0;
	for(;l<r;){
		while(l<r && inp[l]=='x')++l;
		while(l<r && inp[r]=='x')--r;
		if(l<r){
			if(inp[l]!=inp[r]){
				printf("-1");
				return 0;
			}
			if(l+la<n-1-r+ra){
				la=n-1-r+ra-l;
			}
			if(l+la>n-1-r+ra){
				ra=l+la-n+1+r;
			}
			++l;
			--r;
		}
	}
	if(l==r && inp[l]!='x'){
		if(l+la<n-1-r+ra){
			la=n-1-r+ra-l;
		}
		if(l+la>n-1-r+ra){
			ra=l+la-n+1+r;
		}
	}
	printf("%d",la+ra);
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>
#include <set>
//#include <bits/stdc++.h>
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
using namespace std;
#define ALL(X) X.begin(),X.end()
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=2147483647;
const ll LLMAX=9223372036854775807;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    cin>>N;
    
    N%=10;
    
    if(N==3)printf("bon\n");
    else if(N==0 || N==1 || N==6 || N==8)printf("pon\n");
    else printf("hon\n");
    
    return 0;
}


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

const int maxn = 1e5 + 5;
long long dp[maxn];

int main() {
    for (int i = 0; i < maxn; ++i) dp[i] = -1e15;
    dp[0] = 0;
    int n, w; scanf("%d%d", &n, &w);
    for (int i = 0; i < n; ++i) {
        int x, y; scanf("%d%d", &x, &y);
        for (int j = w; j >= x; --j) dp[j] = max(dp[j], dp[j - x] + y);
    }
    printf("%lld\n", *max_element(dp, dp + w + 1));
}


Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=10005;
int tab[MAXN];

int count(int *S, int m, int n){
    int p[n+1];
    int INF=1000000000;
    for(int i=0;i<=n;i++)
        p[i]=INF;
    p[0]=0;
    for(int i=0;i<m;i++)
        for(int j=S[i];j<=n;j++)
            p[j]=min(p[j],1+p[j-S[i]]);
    return p[n];
}

int main(){
    int n,m,t;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++)
        scanf("%d",&tab[i]);
    printf("%d\n",count(tab,m,n));
}

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

int main() {
    int n,k,h,ans=0;
    cin >> n >> k;
    rep(i,n){
        cin >> h;
        if (h>=k) ans++;
    }
    cout << ans << endl;
}

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

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

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

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

int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s;cin>>s;
    int n=s.length();
    int visited[n]={};
    ll ans=0;
    int M=2019;
    int powers[n];
    for(int i=0;i<n;i++)
    {
        powers[i]=powmp(10,i,M);
    }
    f(i,1,n)
    {
        int curr=0;
        int cunt=0;
        if(visited[n-i]) continue;
        for(int j=n-i;j>=0;j--)
        {
            curr+=(int)(s[j]-'0')*powers[n-i-j];
            curr%=M;
            if(curr==0) 
            {
                cunt++;
                ans+=cunt;
                if(j) visited[j-1]=1;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5296