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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
   string s; cin>>s;
	cout<<std::count(s.begin(), s.end(), '1'); 
    return 0;
}


Measured memory_bytes: 3640
import std.stdio, std.string, std.conv;
import std.typecons;
import std.algorithm, std.array, std.range, std.container;
import std.math;

void main() {
	auto S = readln.split[0];
    auto cnt = 0;
    string[] answers = [ "" ];
    while (cnt < S.length) {
        if ( S[cnt] == 'A' || S[cnt] == 'T' || S[cnt] == 'G' || S[cnt] == 'C') {
            answers[$-1] ~= S[cnt];
         }
        else {
            answers ~= "";
        }
        cnt++;
    }
    string ans;
    answers.each!(x => x.length > ans.length ? (ans = x) : "");
    ans.length.writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int tt, tk, at, ak;
  cin >> tt >> tk >> at >> ak;
  while (1) {
    at -= tk;
    if (at <= 0) {
      cout << "Yes" << '\n';
      break;
    }
    tt -= ak;
    if (tt <= 0) {
      cout << "No" << '\n';
      break;
    }
  }
}

Measured memory_bytes: 3620
#include <cctype>
#include <cstdio>
#include <string>
#include <iostream>
using namespace std;
int main(){
	string s;
	cin >> s;
	if (s[0] == 'A'){
		int count = 0, pos;
		for (int i = 2; i < s.size() - 1; i++){
			if (s[i] == 'C'){
				count++;
				pos = i;
			}
		}
		if (count == 1){
			for (int i = 1; i < s.size(); i++){
				if (i != pos && isupper(s[i])){
					printf("WA\n");
					return 0;
				}
			}
			printf("AC\n");
		}else{
			printf("WA\n");
		}
	}else{
		printf("WA\n");
	}
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> a(M), b(M);
  REP(i,M){
    cin >> a[i] >> b[i];
    --a[i];
    --b[i];
  }

  map<int,int> mp;
  REP(i,M) {
    if((a[i] == 0) || (a[i] == N - 1)) ++mp[b[i]];
    if((b[i] == 0) || (b[i] == N - 1)) ++mp[a[i]];
  }

  string ret = "IMPOSSIBLE";
  for(auto e: mp) if(e.second > 1) ret = "POSSIBLE";

  cout << ret << endl;
  return 0;
}



Measured memory_bytes: 11136
import sys

f_i = sys.stdin

n = int(f_i.readline())

class VCost:
    def __init__(self, v, cost):
        self.v_n = v
        self.cost = cost
    def __lt__(self, other):
        return self.cost < other.cost
    def __gt__(self, other):
        return self.cost > other.cost

adj = [[VCost(int(v), int(c)) for v, c in zip(x.split()[2::2], x.split()[3::2])] for x in f_i]

import heapq

def dijkstra():
    PQ = []
    isVisited = [False] * n
    distance = [999900001] * n

    distance[0] = 0
    heapq.heappush(PQ, VCost(0, 0))
    
    while PQ:
        uc = heapq.heappop(PQ)
        u = uc.v_n

        if uc.cost > distance[uc.v_n]:
            continue

        isVisited[u] = True
        
        for vc in adj[u]:
            v = vc.v_n
            if isVisited[v] == True:
                continue
            t_cost = distance[u] + vc.cost
            if t_cost < distance[v]:
                distance[v] = t_cost = distance[u] + vc.cost
                heapq.heappush(PQ, VCost(v, t_cost))

    for v, d in enumerate(distance):
        print(v, d)


dijkstra()

Measured memory_bytes: 121776
N=int(input())
h=list(map(int, input().split()))
h=[0]+h
dp=[10*10]*(N+1)
dp[1]=0
for n in range(2,N+1):
  if n>2:
  	dp[n]=min(dp[n-1]+abs(h[n-1]-h[n]),dp[n-2]+abs(h[n-2]-h[n]))
  else:
    dp[n]=dp[n-1]+abs(h[n]-h[n-1])
print(dp[N])
         

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

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  char c[H][W];
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> c[i][j];
    }
  }
  int ans = 0;
  for(unsigned int maskR = 0; maskR < (1 << H); maskR++){
    for(unsigned int maskC = 0; maskC < (1 << W); maskC++){
      int black = 0;
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          if(((maskR >> i) & 1) == 0 && ((maskC >> j) & 1) == 0 && c[i][j] == '#'){
            black++;
          }
        }
      }
      if(black == K){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

using namespace std;


#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
     
#define ll long long int
#define ld long double


#define fr first
#define se second



#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))


#define pb push_back
#define mp make_pair

#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))

#define easm(a, b) (a + b - 1)/b 


#define PI 3.141592653589793238
#define E  2.718281828459045235


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


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

int dp[3003][3003], ls, lt;
string s, t;

int solve(int i, int j){
  if(i >= ls || j >= lt)return 0;
  int &re = dp[i][j];
  if(re != -1)return re;
  int c1 = 0, c2 = 0;
  if(s[i] == t[j])return 1 + solve(i + 1, j + 1);
  c1 = solve(i + 1, j);
  c2 = solve(i, j + 1);
  return re = max(c1, c2);
}

void build(int i, int j){
  if(i >= ls || j >= lt)return;
  if(s[i] == t[j]){cout << s[i]; build(i + 1, j + 1);return;}
  int c1 = solve(i + 1, j);
  int c2 = solve(i, j + 1);
  if(c1 >= c2)
    build(i + 1, j);
  else
    build(i, j + 1);
}

int main(){
  IOS;
  //freopen("input.in", "r", stdin);
  //freopen("output.txt", "w", stdout);
  clock_t z = clock();
  cin >> s >> t;
  ls = sz(s);
  lt = sz(t);
  emla(dp, -1);
  solve(0, 0);
  build(0, 0);
  debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -integer overflow
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a/gcd(a,b)*b;}
// head


const int mxN = 3e2 + 3;
int n, a[3];
// dp[i][j][k]: expectation
// i dishes with one
// j dishes with two
// k dishes with three
double dp[mxN][mxN][mxN];
int main() {
	ios::sync_with_stdio(0); 
	cin.tie(0); cout.tie(0);
	
	cin >> n;
	int x;
	rep(i, 0, n){
		cin >> x, --x;
		++a[x];
	}
	dp[0][0][0] = 0;
	rep(k, 0, a[2] + 2){
		rep(j, 0, a[1] + a[2] + 2){
			rep(i, 0, a[0] + a[1] + a[2] + 2){
				int s = i + j + k;
				if(!s) continue;
				double val = 1.0 * n / s;
				if (i) val += 1.0 * dp[i - 1][j][k] * i / s;
				if (j) val += 1.0 * dp[i + 1][j - 1][k] * j / s;
				if (k) val += 1.0 * dp[i][j + 1][k - 1] * k / s;
				dp[i][j][k] = val;
			}
		}
	}
	printf("%.20lf\n", dp[a[0]][a[1]][a[2]]);
}




Measured memory_bytes: 217472
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	const inputLines = input.split("\n");
	const line0 = inputLines[0];
	const n = parseInt(line0, 10);
	var s = "hon";
	const last = n%10;
	if (last === 0 ||last === 1 ||last === 6 ||last === 8) {
		s = "pon";
	}
	if (last === 3) {
		s = "bon";
	}

	//出力
	console.log('%s',s);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

// node index.js
// 1
// 2 3
// test
// (Ctrl + D)

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

int main(){
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B;
  R = C + D;
  
  if(L > R){
    cout << "Left" << endl;
  }
  
  else if(L == R){
    cout << "Balanced" << endl;
  }
  
  else if(L < R){
    cout << "Right" << endl;
  }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<queue>
#include<bitset>
#include<complex>
#include<cmath>
using namespace std;
template<typename __T>
inline void read(__T &x)
{
    x=0;
    int f=1;char c=getchar();
    while(!isdigit(c)){if(c=='-')	f=-1;c=getchar();}
    while(isdigit(c))	{x=x*10+c-'0';c=getchar();}
    x*=f;
}
int n;
int main()
{
	int ans=0;
	read(n);
	int a,b;
	while(n--)
	{
		read(a);
		read(b);
		while(a%b)
			a-=(a/b+1)*(1+(a%b-1)/(a/b+1));
		ans^=(a/b);
	}
	if(ans)
		printf("Takahashi\n");
	else
		printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 256
N = int(input())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

satisfaction = 0

for i in range(N):
    satisfaction += B[A[i]-1]

for i in range(1,N):
    if A[i] - A[i-1] == 1:
        satisfaction += C[A[i-1]-1]
        
print(satisfaction)

Measured memory_bytes: 3064
from collections import Counter
import time

def SL(S):
    t = ["S"]*len(S)
    for i in range(len(S)-2,-1,-1):
        if S[i] > S[i+1] or (S[i] == S[i+1] and t[i+1] == "L"):
            t[i] = "L"
    return t

def LMS(t):
    lms = [False]*len(t)
    for i in range(1,len(t)):
        if t[i-1] == "L" and t[i] == "S":
            lms[i] = True
    return lms

def Bucket(S):
    bucket = Counter(S)
    tmp = 0
    for i in sorted(bucket):
        bucket[i] = {"chead":tmp,"ctail":tmp+bucket[i]-1}
        tmp = bucket[i]["ctail"]+1
    return bucket

def STEP2(S,t,bucket,SA):
    for i in range(len(SA)):
        tmp = SA[i]-1
        if t[tmp] == "L" and tmp > -1:
            head = bucket[S[tmp]]["chead"]
            SA[head] = tmp
            bucket[S[tmp]]["chead"]+=1

def STEP3(S,t,SA):
    bucket = Bucket(S)
    for i in range(len(SA)-1,-1,-1):
        tmp = SA[i]-1
        if t[tmp] == "S" and tmp > -1:
            tail = bucket[S[tmp]]["ctail"]
            SA[tail] = tmp
            bucket[S[tmp]]["ctail"]-=1
        
def InducedSorting(S):
    l = len(S)
    t = SL(S)
    lms = LMS(t)
    bucket = Bucket(S)
    SA=[-1]*l
    P1 = [i for i in range(l) if lms[i]]
    #STEP1
    for i,j in enumerate(lms):
        if j:
            tail = bucket[S[i]]["ctail"]
            SA[tail] = i
            bucket[S[i]]["ctail"] -= 1
    #STEP2
    STEP2(S,t,bucket,SA)
    #STEP3
    STEP3(S,t,SA)
    #Construct S1 from pseudoSA
    prev = None
    Name = [None]*l
    name = 0
    S1 = []
    for i in SA:
        if lms[i]:
            if prev and not i == len(S)-1:
                j = 0
                while(True):
                    if not S[i+j] == S[prev+j] or not t[i+j] == t[prev+j]:
                        name+=1
                        break
                    if j>0 and lms[i+j]:
                        break
                    j+=1
            Name[i] = name
            prev = i
    for i in Name:
        if not i == None:
            S1.append(i)
    #Construct SA1 from S1
    uniq = True
    dtmp = {}
    #for i in Counter(S1):
    #    if Counter(S1)[i] > 1:
    #        uniq = False
    #        break
    for i in S1:
        if i in dtmp:
            uniq = False
            break
        else:
            dtmp[i] = True
    
    if uniq:
        SA1 = [None]*len(S1)
        for i,j in enumerate(S1):
            SA1[j] = i
    else:
        SA1 = InducedSorting(S1)
    
    #Inducing SA from SA1 STEP1
    bucket = Bucket(S)
    SA=[-1]*l
    for i in SA1[::-1]:
        p = P1[i]
        tail = bucket[S[p]]["ctail"]
        SA[tail] = p
        bucket[S[p]]["ctail"] -= 1
    #Inducing SA from SA1 STEP2
    STEP2(S,t,bucket,SA)
    #Inducing SA from SA1 STEP3
    STEP3(S,t,SA)
    return SA

def contain(T,sa,P):
    a = 0
    b = len(T)
    while(b-a > 1):
        c = (a+b)//2
        if T[sa[c]:sa[c]+len(P)] < P:
            a = c
        else:
            b = c
    return P == T[sa[b]:sa[b]+len(P)]

T = input()
Q = int(input())
P = [input() for _ in range(Q)]
SA = InducedSorting(T+"$")
for i in P:
    if contain(T,SA,i):
        print(1)
    else:
        print(0)


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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(max(max(a,b),c)==a+b+c-max(max(a,b),c)){
    cout <<"Yes"<<endl;
    return 0;
  }
  cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        while (in.hasNext()) {
            int n = in.nextInt();
            int x = in.nextInt();

            if (n == 0) {
                break;
            }

            int ret = 0;
            int n3min = x / 3;
            for (int n3 = n; n3 >= n3min; n3--) {
                int x2 = x - n3;
                int n2 = n3 - 1;

                int max = (x2 - 1) / 2;
                int hosei = x2 - 1 - n2;
                max -= (hosei > 0) ? hosei : 0;

                ret += (max < 0) ? 0 : max;
            }

            sb.append(ret).append("\n");
        }

        System.out.print(sb.toString());
    }
}

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

int main(){
  ll n,m,a,b;
  cin>>n>>m;
  a=min(n,m);
  b=max(n,m);
  ll ans;
  if(a==1){
    if(b==1) ans=1;
    else ans=b-2;
  }else if(a==2) ans=0;
  else ans=(a-2)*(b-2);
  cout<<ans<<endl;
}


Measured memory_bytes: 3596
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int n = 0;
    for(int i=0;i<2;i++){
      if(a>=b){
        n += a;
        a -= 1;
      }else{
        n += b;
        b -= 1;
      }
    } 
    System.out.println(n);
  }
}











Measured memory_bytes: 21844
n,t = map(int, input().split())
a = list(map(int, input().split()))

b = float('inf')

c = 0

ans = 0

for i in range(n):
    if a[i]<b:
        b = a[i]
    if a[i]-b == c:
        ans += 1
    elif a[i]-b > c:
        c = a[i]-b
        ans = 1

print(ans)


Measured memory_bytes: 63600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>

using namespace std;

int main()
{
    int n, ans = 0;
    cin >> n;
    vector<int> p(n);
    for(int i = 0; i < n; i++)
    {
        cin >> p.at(i);
        if(i > 1)
        {
            if(p.at(i - 1) < p.at(i) && p.at(i - 1) >= p.at(i - 2)) ans++;
            else if(p.at(i - 1) >= p.at(i) && p.at(i - 1) < p.at(i - 2)) ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <numeric>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
	int r[4], p[4], a, b, c, d;

	while (true)
	{
		cin >> r[0] >> r[1] >> r[2] >> r[3];

		if (r[0] == 0 && r[1] == 0 && r[2] == 0 && r[3] == 0) { break; }

		iota(p, p + 4, 0);

		do
		{
			int a = r[p[0]], b = r[p[1]], c = r[p[2]], d = r[p[3]];

			if      (a + b + c + d == 10) { cout << a << " + " << b << " + " << c << " + " << d << endl; goto Exit; }
			else if (a + b + c - d == 10) { cout << a << " + " << b << " + " << c << " - " << d << endl; goto Exit; }
			else if (a + b - c - d == 10) { cout << a << " + " << b << " - " << c << " - " << d << endl; goto Exit; }
			else if (a * b + c + d == 10) { cout << a << " * " << b << " + " << c << " + " << d << endl; goto Exit; }
			else if (a * b + c - d == 10) { cout << a << " * " << b << " + " << c << " - " << d << endl; goto Exit; }
			else if (a * b - c - d == 10) { cout << a << " * " << b << " - " << c << " - " << d << endl; goto Exit; }
			else if (a - b * c + d == 10) { cout << a << " - " << b << " * " << c << " + " << d << endl; goto Exit; }
			else if (a * b + c * d == 10) { cout << a << " * " << b << " + " << c << " * " << d << endl; goto Exit; }
			else if (a * b - c * d == 10) { cout << a << " * " << b << " - " << c << " * " << d << endl; goto Exit; }
			else if (a * b * c + d == 10) { cout << a << " * " << b << " * " << c << " + " << d << endl; goto Exit; }
			else if (a * b * c - d == 10) { cout << a << " * " << b << " * " << c << " - " << d << endl; goto Exit; }
			else if (a * b * c * d == 10) { cout << a << " * " << b << " * " << c << " * " << d << endl; goto Exit; }
			else if ((a + b) * c + d == 10) { cout << "(" << a << " + " << b << ")" << " * " << c << " + " << d << endl; goto Exit; }
			else if ((a + b) * c - d == 10) { cout << "(" << a << " + " << b << ")" << " * " << c << " - " << d << endl; goto Exit; }
			else if ((a - b) * c + d == 10) { cout << "(" << a << " - " << b << ")" << " * " << c << " + " << d << endl; goto Exit; }
			else if ((a - b) * c - d == 10) { cout << "(" << a << " - " << b << ")" << " * " << c << " - " << d << endl; goto Exit; }
			else if ((a + b) * (c + d) == 10) { cout << "(" << a << " + " << b << ")" << " * " << "(" << c << " + " << d << ")" << endl; goto Exit; }
			else if ((a + b) * (c - d) == 10) { cout << "(" << a << " + " << b << ")" << " * " << "(" << c << " - " << d << ")" << endl; goto Exit; }
			else if ((a - b) * (c - d) == 10) { cout << "(" << a << " - " << b << ")" << " * " << "(" << c << " - " << d << ")" << endl; goto Exit; }

		} while (next_permutation(p, p + 4));

		cout << 0 << endl;

	Exit:;
	}

	return 0;
}

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

const int MAX = 100;
const int INF = 1 << 29;

int main()
{
	while (true) {
		int N, M, L, K, A, H;
		cin >> N >> M >> L >> K >> A >> H;

		if (N == 0 && M == 0 && L == 0 && K == 0 && A == 0 && H == 0) {
			break;
		}

		int cost[MAX][MAX];
		bool freeze[MAX];

		for (int i = 0; i < N; i++) {
			freeze[i] = false;
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i == j) {
					cost[i][j] = 0;
				}
				else {
					cost[i][j] = INF;
				}
			}
		}

		for (int i = 0; i < L; i++) {
			int temp;
			cin >> temp;
			freeze[temp] = true;
		}

		freeze[A] = true;
		freeze[H] = true;

		for (int i = 0; i < K; i++) {
			int X, Y, T;
			cin >> X >> Y >> T;

			cost[X][Y] = T;
			cost[Y][X] = T;
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
				}
			}
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (freeze[i] == false || freeze[j] == false) {
					cost[i][j] = 0;
				}
			}
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (cost[i][j] > M) {
					cost[i][j] = 0;
				}
			}
		}

		for (int i = 0; i <N; i++) {
			for (int j = 0; j < N; j++) {
				for (int k = 0; k < N; k++) {
					if (cost[j][i] == 0 || cost[i][k] == 0) {
						continue;
					}

					if (cost[j][k] == 0) {
						cost[j][k] = cost[j][i] + cost[i][k];
					}
					else {
						cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
					}
				}
			}
		}

		if (cost[A][H] == 0) {
			cout << "Help!" << endl;
		}
		else {
			cout << cost[A][H] + max(0, cost[A][H] - M) << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3144
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,m;
vector<P> G[55];
ll S[22],pow2[55];

ll dfs(int s,int e,int tar){
    ll res=-1;
    ll R=(1ll << e);
    if (s==tar) return R;
    for(P t:G[s]){
        if (t.second==e) continue;
        res=max(res,dfs(t.first,t.second,tar));
    }
    if (res==-1) return -1;
    if (e==-1) return res;
    return res|R;
}

void solve(){
    cin >> n;
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(P(b-1,i));
        G[b-1].push_back(P(a-1,i));
    }
    pow2[0]=1;
    rep(i,n){
        pow2[i+1]=pow2[i]*2ll;
    }
    cin >> m;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        S[i]=dfs(a-1,-1,b-1);
        //cout << bitset<51>(S[i]) << endl;
    }
    
    int M=(1 << m);
    //cout << M << endl;
    ll ans=0;
    Rep(s,1,M){
        int nu=0,nu2=0;
        ll T=0;
        rep(i,m){
            if (s & (1ll << i)) {
                T|=S[i];
                nu2+=1;
            }
        }
        rep(k,n-1){
            if (T & (1ll << k)) nu+=1;
        }
        //cout << bitset<20>(s) << " " << bitset<51>(T) << " " << pow2[n-1-nu] << endl;
        if (nu2%2==1) ans+=pow2[n-1-nu];
        else ans-=pow2[n-1-nu];
    }
    //cout << ans << endl;
    cout << pow2[n-1]-ans << endl;

}

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

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

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(i, vec) for(auto &(i) : (vec))


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bool find(int n, vector<bool> &s_data, bool first, bool second){
  vector<bool> Data(n + 1);
  Data.at(0) = first; Data.at(1) = second;
  for(int i = 1; i < n; i++) Data.at(i + 1) = Data.at(i - 1)^Data.at(i)^s_data.at(i);
  if(Data.at(n) == first) if((first == s_data.at(0)) == (second == Data.at(n-1))){
    REP(i, n) putchar(Data.at(i) ? 'S' : 'W');
    putchar('\n');
    return true;
  }
  return false;
}

int main(void){
  int n; cin >> n;
  string s; cin >> s;
  vector<bool> s_data(n);
  REP(i, n) s_data.at(i) = (s.at(i) == 'o');
  if(find(n, s_data, true, true)) return 0;
  if(find(n, s_data, true, false)) return 0;
  if(find(n, s_data, false, true)) return 0;
  if(find(n, s_data, false, false)) return 0;
  cout << "-1\n";
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char const *argv[]) {

  int num;
  int *line;
  int i,j,k;
  int key;

  scanf("%d",&num);
  line = (int *)malloc(num * sizeof(int));

  for( i = 0 ; i < num ; i++ ){
    scanf("%d",&line[i]);
  }

  for( i = 1 ; i < num ; i++ ){

    key = line[i];
    j = i - 1;

    for( k = 0 ; k < num ; k++ ){
      printf("%d",line[k]);
      if ( k != num-1 )
        printf(" ");
    }
    printf("\n");

    while( line[j] > key ){


      line[j+1] = line[j];
      j--;

    }

    line[j+1] = key;

  }

  for( k = 0 ; k < num ; k++ ){
    printf("%d",line[k]);
    if( k != num-1 )
      printf(" ");
  }
  printf("\n");

  free(line);


  return 0;
}

Measured memory_bytes: 604
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        long n = scanner.nextLong();
        long ans = 0;
        for (long k = 1; k * (k + 1) < n; ++k) {
            if (n % k == 0) {
//                assert n / k - 1 > k;
                ans += n / k - 1;
            }
        }
        writer.println(ans);

        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


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

int main(){
    ll n,m;
    cin>>n>>m;
    ll c[m];
    rep(i,m)cin>>c[i];
    vector<ll> dp(n+1,1e9);
    dp[0]=0;
    rep(i,n){
        rep(j,m){
            if(i+c[j]<=n)dp[i+c[j]]=min(dp[i+c[j]],dp[i]+1);
        }
    }
    cout<<dp[n]<<endl;
}



Measured memory_bytes: 3112
#
import sys
import math
import numpy as np
import itertools

MOD = 1000000007
# いくつか入力
n,m = (int(i) for i in input().split())  

# n行の数をリストに
if m > 0:
    a = [int(input()) for i in range(m)]
else:
    a = []
a.append(9999999) # sentinel
dame=0

b=[1]
if a[dame]==1:
    dame += 1
    b.append(0)
else:
    b.append(1)

for i in range(2,n+1):
    if i==a[dame]:
        dame += 1
        b.append(0)
    else:
        c=(b[i-1]+b[i-2]) % MOD
        b.append(c)

#print(a,b)
print(b[n])


Measured memory_bytes: 17012
# A - Colorful Transceivers
# A さんと C さんが会話できるなら　YES!!!!
# 条件1： A さんと C さんの距離が d 以下
# 条件2： A さんと B さんの距離が d 以下　∧ B さんと C さんの距離が d 以下


# A さん a [m]
# B さん b [m]
# C さん c [m]
# D さん d [m]

# 標準入力 a b c d
a, b, c, d = map(int, input().split(maxsplit=4))
# print(a)
# print(b)
# print(c)
# print(d)


# A さんと C さんの距離を計算
distance_ac = abs(a - c)
# print(distance_ac)

# A さんと B さんの距離を計算
distance_ab = abs(a - b)
# print(distance_ab)

# B さんと C さんの距離を計算
distance_bc = abs(b - c)
# print(distance_bc)


if distance_ac <= d:    # 条件1
    print('Yes')
elif distance_ab <= d:  # 条件2
    if distance_bc <= d:
        print('Yes')
    else:
        print('No')
else:
    print('No')



Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF=1e9+7;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int A,B;
	cin >> A >> B;
	cout << A*B << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>

using namespace std;

int main(void)
{
    int H, W, h, w;

    cin >> H >> W >> h >> w;

    cout << (H-h)*(W-w) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
double a,aa[110000],ab[110000],b=0.0,e;
int d=1;
string s;
signed main()
{
	cin>>a;
	rep(i,a){
		cin>>aa[i]>>ab[i];
	}
	rep(i,a){
		d*=i+1;
	}
	e=d*1.0;
	d=d*(a-1)/(a*(a-1)/2);
	rep(i,a){
		rep(j,i){
			b+=sqrt(pow(aa[i]-aa[j],2)+pow(ab[i]-ab[j],2)*1.0)*d*1.0;
		}
	}
	printf("%.9f",b*1.0/e);
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut min = 1000000000;
    for i in a {
        let mut num = i;
        let mut cnt = 0;
        loop {
            if num % 2 != 0 {
                break;
            }
            num /= 2;
            cnt += 1;
        }
        min = std::cmp::min(min, cnt);
    }
    println!("{}", min);
}


Measured memory_bytes: 4352
using System;
//using System.Collections.Generic;

public class ProCon
{
    public static void Main(){     
        string number =　Console.ReadLine();
        long sum = 0;
        for(int i = 1; i <= int.Parse(number); i++)
        {
              if(i % 3 == 0 || i % 5 == 0);
            else sum = sum + i;
        }
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 27528
import array
import collections
import heapq

INF = 1e9

N = int(input())

AdjacentVertex = collections.namedtuple('AdjacentVertex', 'vertex cost')
adjacency_list = collections.defaultdict(set)

NO_VERTEX = -1
 
def compute_mst_prim(max_v, adj_list):
    pred = collections.defaultdict(lambda: NO_VERTEX)
    key = collections.defaultdict(lambda: INF)
    key[0] = 0
    pq = [(key[v], v) for v in range(max_v)]
    heapq.heapify(pq)
    in_pq = array.array("B", (True for _ in range(max_v)))
    while pq:
        _, u = heapq.heappop(pq)
        in_pq[u] = False
        for v, v_cost in adj_list[u]:
            if in_pq[v]:
                weight = v_cost
                if weight < key[v]:
                    pred[v] = u
                    key[v] = weight
                    heapq.heappush(pq, (weight, v))
                    in_pq[v] = True
    return (pred, key)

for i in range(N):
    u = list(map(int, input().split()))
    for j in range(N):
        if u[j] == -1:
            adjacency_list[i].add(AdjacentVertex(j, INF))
            adjacency_list[j].add(AdjacentVertex(i, INF))
        else:
            adjacency_list[i].add(AdjacentVertex(j, u[j]))
            adjacency_list[j].add(AdjacentVertex(i, u[j]))

(_, key) = compute_mst_prim(N, adjacency_list)

print(sum(key.values()))

Measured memory_bytes: 9620
using System;
 
namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine().Split(' ');
            var a = int.Parse(str[0]);
            var b = int.Parse(str[1]);
            var t = int.Parse(str[2]);
        
            Console.WriteLine(t / a * b);
        }
    }
}

Measured memory_bytes: 11092
from collections import defaultdict
N, M = map(int, input().split())
A = list(map(int, input().split()))
f, mod_dic, ret = [A[0]], defaultdict(list), 0
mod_dic[A[0] % M].append(0)
for i in range(1, N):
    f.append(f[i - 1] + A[i])
    mod_dic[f[i] % M].append(i)
for k, v in mod_dic.items():
    if k == 0:
        ret += len(v)
    if len(v) > 1:
        ret += len(v) * (len(v) - 1) / 2
print(int(ret))

Measured memory_bytes: 24816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int a, b;
    vector<int> G[n];
    int outdeg[2][n];
    fill(outdeg[0], outdeg[2], 0);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        outdeg[s[a] - 'A'][b]++;
        if (a == b) continue;
        G[b].emplace_back(a);
        outdeg[s[b] - 'A'][a]++;
    }
    set<int> S;
    bool deleted[n] = {};
    int sum = n;
    rep(i, n) {
        int mn = min(outdeg[0][i], outdeg[1][i]);
        if (mn == 0){
            S.emplace(i);
            deleted[i] = true;
            sum--;
        }
    }
    while(!S.empty()){
        int v = *S.begin();
        S.erase(S.begin());
        for(int from : G[v]){
            if (deleted[from]) continue;
            outdeg[s[v] - 'A'][from]--;
            if (outdeg[s[v] - 'A'][from] == 0) {
                S.emplace(from);
                deleted[from] = true;
                sum--;
            }
        }
    }
    cout << (sum > 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 20448
#include <stdio.h>
 
#define MN 1000001
 
int main(void)
{
    int n;
    int i, j;
    int pn[MN];
     
    for (i = 0; i < MN; i++){
        pn[i] = 1;
    }
     
    pn[0] = pn[1] = 0;
     
    for (i = 2; i * i < MN; i++){
        if (pn[i] == 1){
            for (j = i * i; j < MN; j += i){
                pn[j] = 0;
            }
        }
    }
     
    for (i = 1; i < MN - 1; i++){
        pn[i + 1] += pn[i];
    }
     
    while (scanf("%d", &n) != EOF){
        printf("%d\n", pn[n]);
    }
     
    return (0);
}

Measured memory_bytes: 4504
def main():
  N = int(input())
  S = input()
  a = 0
  ans = ''
  
  for i in S:
    a = ord(i) + N 
    
    if (ord(i) + N) - ord('Z') > 0:
      a = (ord(i) + N) - 26
      
    ans += chr(a)
      
  print(ans)

  
  
main()

Measured memory_bytes: 9104
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys


def main():
    h, w = [int(v) for v in sys.stdin.readline().rstrip().split(' ')]

    field = []

    for i in range(h):
        field.append([int(v) for v in sys.stdin.readline().rstrip().split(' ')])
            
    move = [[False for j in range(w)] for i in range(h)]
    count = 0

    for i in range(h):
        if (i&1)==1:
            for j in range(w-2, -1, -1):
                if (field[i][j+1]&1)==1:
                    move[i][j+1] = True
                    field[i][j+1] -= 1
                    field[i][j] += 1
                    count += 1
            if i<h-1 and (field[i][0]&1)==1:
                move[i][0] = True
                field[i][0]-=1
                field[i+1][0]+=1
                count += 1
        else:
            for j in range(1, w, +1):
                if (field[i][j-1]&1)==1:
                    move[i][j-1] = True
                    field[i][j-1] -= 1
                    field[i][j] += 1
                    count += 1
            if i<h-1 and (field[i][w-1]&1)==1:
                move[i][w-1] = True
                field[i][w-1]-=1
                field[i+1][w-1]+=1
                count += 1

    print(count)
    for i in range(h):
        if (i&1)==1:
            for j in range(w-2, -1, -1):
                if (move[i][j+1]):
                    print(i+1,j+2,i+1,j+1)
            if move[i][0]:
                print(i+1,1,i+2,1)
        else:
            for j in range(1, w, +1):
                if (move[i][j-1]):
                    print(i+1,j,i+1,j+1)
            if move[i][w-1]:
                print(i+1,w,i+2,w)

if __name__=="__main__":
    main()


Measured memory_bytes: 9912
#include <stdio.h>

int calcpos(char c) {
    switch (c) {
        case 'M':
            return 0;
        case 'A':
            return 1;
        case 'R':
            return 2;
        case 'C':
            return 3;
        case 'H':
            return 4;
    }

    return -1;
}

char S[15];

int main()
{
    long long counts[5] = {0,0,0,0,0};
    int pos;

    int N;
    scanf("%d", &N);

    for (int i = 1; i <= N && !feof(stdin); ++i) {
        scanf("%s", S);

        pos = calcpos(S[0]);
        if (pos != -1) ++counts[pos];
    }

    long long res = 0;
    for (int i = 0; i <= 2; ++i) {
        for (int j = i + 1; j <= 3; ++j) {
            for (int x = j + 1; x <= 4; ++x) {
                res += counts[i] * counts[j] * counts[x];
            }
        }
    }

    printf("%lld", res);

    return 0;
}


Measured memory_bytes: 128
INTEGER A,B,K
READ*,A,B,K
DO I=MIN(A,B),1,-1
  IF (MOD(A,I)==0.AND.MOD(B,I)==0) THEN
    K=K-1
    IF (K==0)THEN
    PRINT"(I0)",I
    STOP
    ENDIF
  ENDIF
END DO
END

Measured memory_bytes: 256
N,M=map(int,input().split())
X=sorted(list(map(int,input().split())))

if N >= M:
  print(0)
  exit()
D=[0]*(M-1)
for i in range(1,M):
  D[i-1] = X[i]-X[i-1]
D.sort()
D.reverse()
D_pass=0
for i in range(N-1):
  D_pass+=D[i]
print(X[-1]-X[0]-D_pass)

Measured memory_bytes: 13960
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N = int(input())
    A = list(map(int, input().split()))

    lcm_A = A[0]
    for a in A:
        lcm_A = lcm(lcm_A, a)

    result = 0
    for a in A:
        result += (lcm_A - 1) % a

    print(result)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3316
#include <algorithm>
#include <bits/stdc++.h>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define rep(X, Y) for (int(X) = 0; (X) < (Y); ++(X))
#define rrep(X, Y) for (int(X) = (Y)-1; (X) >= 0; --(X))
#define itrep(X, Y) for (auto(X) = (Y).begin(); (X) != (Y).end(); (X)++)
#define all(X) (X).begin(), (X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define print(x) cout << x << endl

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const string YES = "Yes";
const string NO = "No";

void solve(long long N, long long M, std::vector<std::string> A,
           std::vector<std::string> B) {
  rep(i, N) {
    rep(j, N) {
      if (A[i][j] == B[0][0]) {
        bool ok = true;
        rep(i2, M) {
          rep(j2, M) {
            if (i + i2 >= N || j + j2 >= N || A[i + i2][j + j2] != B[i2][j2]) {
              ok = false;
              break;
            }
          }
          if (!ok) {
            break;
          }
        }
        if (ok) {
          print(YES);
          return;
        }
      }
    }
  }
  print(NO);
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<std::string> A(N);
  for (int i = 0; i < N; i++) {
    std::cin >> A[i];
  }
  std::vector<std::string> B(M);
  for (int i = 0; i < M; i++) {
    std::cin >> B[i];
  }
  solve(N, M, std::move(A), std::move(B));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//this code is written by Itst
using namespace std;

#define int long long
signed main(){
	static int A[100003] , ans[100003];
	int N , sum = 0;
	cin >> N;
	for(int i = 1 ; i <= N ; ++i){
		cin >> A[i]; sum += A[i];
	}
	for(int i = 1 ; i < N ; i += 2) sum -= 2 * A[i];
	ans[N] = sum;
	for(int i = N - 1 ; i ; --i)
		ans[i] = A[i] * 2 - ans[i + 1];
	for(int i = 1 ; i <= N ; ++i)
		cout << ans[i] << ' ';
	return 0;
}


Measured memory_bytes: 2816
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
    private static Scanner scanner;
    public static void main(String[] args){
        scanner = new Scanner(System.in);
        LinkedList<String> name = new LinkedList<String>();
        LinkedList<Integer> time = new LinkedList<Integer>();
        int length = scanner.nextInt();
        int q = scanner.nextInt();
        int qTime = 0;
        for(int i = 0;i < length;i++){
            name.add(scanner.next());
            time.add(scanner.nextInt());
        }
        while(!name.isEmpty()){
            if(time.peek() <= q){
                System.out.print(name.poll() + " ");
                qTime = qTime + time.poll();
                System.out.println(qTime);
            }else{
                name.add(name.poll());
                time.add(time.poll() - q);
                qTime = qTime + q;
            }
        }
    }

}

Measured memory_bytes: 78924
import sys

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


def input():
    return sys.stdin.readline().strip()


def main():
    N, A, B, C, D = map(int, input().split())
    A -= 1
    B -= 1
    C -= 1
    D -= 1
    S = input()

    # 二個以上連続で岩があったら無理
    for i in range(A + 1, max(C, D)):
        if S[i] == S[i + 1] == "#":
            print("No")
            return

    # 追い抜かす必要がない
    if C < D:
        print("Yes")
        return
    else:
        # 追い抜かす必要がある
        # 3つ以上連続で岩が置かれていない区間があれば良い
        for i in range(B - 1, D):
            if S[i] == S[i + 1] == S[i + 2] == ".":
                print("Yes")
                return

        print("No")
        return


main()


Measured memory_bytes: 9508
/**
 *   created: 18 August 2019  19:06:17
**/
#include<bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef vector< pair<int , int> > vii;
typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long , long long> pll;
typedef vector< pair<long long , long long> > vll;

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================
ll fun(ll a){
    if(a%4==0)
        return a;
    if(a%4==1)
        return 1;
    if(a%4==2)
        return a+1;
    return 0;
}
int main()
{
    optimizeIO();
    int tt=1;
    // cin>>tt;
    while(tt--){
       ll a,b;
       cin>>a>>b;
       cout<<(fun(a-1)^fun(b));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	cout << 180 * N - 360 << endl;
	return 0;
}



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

using namespace std;

int main()
{
    int total,i,j;
    string str;

    cin>>total>>str;

    int c=0,len= total-1;
    vector <int> v;
    map<char,int> mp;

    for(i=0;i<=len;i++)
    {
        mp[str[i]]=1;

        c=0;
        map<char,int> mpp;

        for(j=i+1;j<total;j++)
        {
            if( (mp[str[j]]) && (mpp[str[j]]==0) )
                {
                    c++;
                    mpp[str[j]]=1;
                }


        }

        v.push_back(c);

    }

    sort(v.begin(),v.end());
    len= v.size();
    printf("%d\n",v[len-1]);

    return 0;

}


Measured memory_bytes: 256
n = int(input())
pre_t, pre_x, pre_y = 0, 0, 0
for i in range(n):
    t , x, y = map(int, input().split())
    dt = t - pre_t
    dist = abs(x - pre_x) + abs(y -pre_y)
    if dist > dt or (dist+dt)%2 != 0:

        print("\nNo") 
        exit()
    pre_t, pre_x, pre_y = t, x, y
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ALL(v) v.begin(),v.end()
#define UN(v) sort(ALL(v)),v.erase(unique(ALL(v)))
#define FILL(x,y) memset(x,y,sizeof(x))
#define EACH(v,it) for(__typeof(v.begin()) it=v.begin();it!=v.end();it++)
#define FIO ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
int n;
pii a[200005];
int ans;
/*---main code---*/

void sol(int x)
{
//	cout<<1<<'\n';
	if(a[x].second)
	{
		return ;
	}
	a[x].second=1;
	int p=1;
	while(p<=a[x].first)
	{
		p<<=1;
	}
	int pos=upper_bound(a,a+n,make_pair(p-a[x].first,0))-a-1;
//	cout<<pos<<'\n';
	if(pos<n&&a[pos].first+a[x].first==p)
	{
		ans++;
//		cout<<x<<' '<<pos<<'\n';
		a[pos].second=1;
	}
	return ;
}

int main()
{
	FIO;
//	cout<<1;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i].first;
	}
//	cout<<1;
	sort(a,a+n);
//	cout<<1;
	for(int i=n-1;i>=0;i--)
	{
		sol(i);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 1792