akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int N=sc.nextInt();
        int A[];
        A=new int[N];
        for(int i=0;i<N;i++) A[i]=sc.nextInt();
        Arrays.sort(A);
        boolean ans=true;
        for(int i=0;i<N-1;i++) if(A[i]==A[i+1]) ans=false;
        System.out.println(ans?"YES":"NO");
    }
}

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

vector<int> to[100005];

int main(){
    int n,m;
    cin >> n >> m;
    rep(i,m){
        int a,b;
        cin >> a >>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    queue<int> q;
    vector<int> dist(n,INF);
    vector<int> pre(n,-1);
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int u:to[v]){
            if(dist[u]!=INF) continue;
            dist[u] = dist[v] + 1;
            pre[u] = v;
            q.push(u);
        }
    }
    cout << "Yes" << endl;
    rep(i,n){
        if(i==0) continue;
        int ans = pre[i];
        ans++;
        cout << ans << endl;
    }
}

Measured memory_bytes: 10708
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        t: usize,
        cases: [(u64, u64, u64, u64, u64);t],
    }

    for (n, a, b, c, d) in cases {
        let mut memo: HashMap<u64, u64> = HashMap::new();
        let ans = solve(n, a, b, c, d, &mut memo);
        println!("{}", ans);
    }
}

fn solve(n: u64, a: u64, b: u64, c: u64, d: u64, memo: &mut HashMap<u64, u64>) -> u64 {
    if n == 0 {
        return 0;
    }
    if n == 1 {
        return d;
    }
    if let Some(&n) = memo.get(&n) {
        return n;
    }

    let mut res = d.saturating_mul(n);

    //A
    if n % 2 == 0 {
        res = min(res, solve(n / 2, a, b, c, d, memo) + a);
    } else {
        let plus = 2 - (n % 2);
        res = min(res, solve(n / 2 + 1, a, b, c, d, memo) + a + d * plus);

        let minus = n % 2;
        res = min(res, solve(n / 2, a, b, c, d, memo) + a + d * minus);
    }

    //B
    if n % 3 == 0 {
        res = min(res, solve(n / 3, a, b, c, d, memo) + b);
    } else {
        let plus = 3 - (n % 3);
        res = min(res, solve(n / 3 + 1, a, b, c, d, memo) + b + d * plus);

        let minus = n % 3;
        res = min(res, solve(n / 3, a, b, c, d, memo) + b + d * minus);
    }

    //C
    if n % 5 == 0 {
        res = min(res, solve(n / 5, a, b, c, d, memo) + c);
    } else {
        let plus = 5 - (n % 5);
        res = min(res, solve(n / 5 + 1, a, b, c, d, memo) + c + d * plus);

        let minus = n % 5;
        res = min(res, solve(n / 5, a, b, c, d, memo) + c + d * minus);
    }

    memo.insert(n, res);
    res
}


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

int main(){
	int hee[1000];
	int n;
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>> hee[i];
	}
	for(int j=n; j>=1; j--){
		cout<<hee[j];
		if(j>1){
			cout<<' ';
		}
	}
	cout<<endl;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(void){
	 int i,j,data[10],tmp;
	  for(i=0;i<10;i++){
	    scanf("%d",&data[i]);
	  }
	  for(i=0;i<10;i++){
	    for(j=9;j>i;j--){
	      if(data[j]>data[j-1]){
	    tmp=data[j];
	    data[j]=data[j-1];
	    data[j-1]=tmp;
	      }
	    }
	  }
	  for(i=0;i<3;i++){
	    printf("%d\n",data[i]);
	  }
	  return(0);
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	char c[2][3] = {0};
	rep (i, 2) rep (j, 3) cin >> c[i][j];

	bool ok = true;
	rep (j, 3){
		if (c[0][j] != c[1][3-j-1]){
			ok = false;
			break;
		} // end if
	} // end rep

	cout << (ok ? "YES" : "NO") << endl;
	
	return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]A - HEX
            var s = Console.ReadLine();
            var X = s.Substring(0, 1);
            var Y = s.Substring(2, 1);

            int x = Convert.ToInt32(X, 16);
            int y = Convert.ToInt32(Y, 16);

            if (x < y)
            {
                Console.WriteLine("<");
            }
            else if(x > y)
            {
                Console.WriteLine(">");
            }
            else
            {
                Console.WriteLine("=");
            }
        }
    }
}

Measured memory_bytes: 11220
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>

using namespace std;

const int maxn = 55;

long long a[maxn];
long long c[maxn][maxn];

void init(){
    c[0][0] = 1;
    for(int i = 1;i <= 50;i++){
        c[i][0] = 1;
        c[i][i] = 1;
        for(int j = 1;j < i;j++){
            c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
        }
    }
}

int main(){
    init();
    int n;
    int A,B;
    scanf("%d%d%d",&n,&A,&B);
    for(int i = 1;i <= n;i++){
        cin >> a[i];    }
    sort(a + 1,a + 1 + n);
    long long sum = 0;
    for(int i = 0;i < A;i++){
        sum += a[n - i];
    }
    double ans = sum / (1.0 * A);
    printf("%.10lf\n",ans);
    if(sum == a[n] * A){
        int num = 0;
        for(int i = 1;i <= n;i++){
            if(a[i] == a[n]) num++;
        }
        long long ans = 0;
        for(int i = A;i <= min(num,B);i++){
            ans += c[num][i];
        }
        cout << ans << endl;
    }else{
        int num = 0;
        int num1 = 0;
        for(int i = n - A + 1;i <= n;i++){
            if(a[i] == a[n - A + 1]){
                num1++;
            }
        }
        for(int i = 1;i <= n;i++){
            if(a[i] == a[n - A + 1]){
                num++;
            }
        }
        cout << c[num][num1] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from collections import deque

N = int(input())
P = list(map(int, input().split()))

def nears(n):
    ret = []
    if n%N != 0:
        ret.append(n-1)
    if n%N != N-1:
        ret.append(n+1)
    if n//N != 0:
        ret.append(n-N)
    if n//N != N-1:
        ret.append(n+N)
    return ret

NeedS = []
for p in range(N**2):
    NeedS.append(min([p%N, p//N, N-1-p%N, N-1-p//N]))

isChecked = [False]*(N**2)
ans = 0
for p in P:
    p -= 1
    ans += NeedS[p]
    isChecked[p] = True
    q = deque()
    q.append(p)
    while q:
        p = q.popleft()
        d = NeedS[p]
        if not isChecked[p]: d += 1
        for np in nears(p):
            if d < NeedS[np]:
                NeedS[np] = d
                q.append(np)
print(ans)

Measured memory_bytes: 173864
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define mp 			make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define mx 101
using namespace std;
ll arr[101];
vector<ll>v;

void sieve()
{
	ll i,j;
	for(i=2;i<=mx;i+=2)
	arr[i]=1;
	for(i=3;i<=mx;i+=2)
	{
		if(!arr[i])
		for(j=i*i;j<=mx;j+=2*i)
		arr[j]=1;
	}
	v.pb(2);
	for(i=3;i<=mx;i+=2)
	if(!arr[i])
	v.pb(i);
}

ll fun(ll n,ll x)
{
    ll c=0,r=x;
    while(r<=n)
    {
        c+=n/r;
        r*=x;
    }
    return c;
}

void solve()
{
	ll n;
	cin>>n;
    ll i,p,q;
    ll s=0;
    ll k=v.size();
    for(i=0;i<k;i++)
    {
        for(p=i+1;p<k;p++)
        {
            for(q=p+1;q<k;q++)
            {
                ll c1=fun(n,v[i]);
                ll c2=fun(n,v[p]);
                ll c3=fun(n,v[q]);
                if(c1>=2 and c2>=4 and c3>=4)
                s++;
                if(c1>=4 and c2>=2 and c3>=4)
                s++;
                if(c1>=4 and c2>=4 and c3>=2)
                s++;
            }
        }
    }
	//cout<<s<<" ";
    for(i=0;i<k;i++)
    {
        for(p=i+1;p<k;p++)
        {
            ll c1=fun(n,v[i]);
            ll c2=fun(n,v[p]);
		//	if(v[i]==2 and v[p]==3)
			//cout<<c1<<c2<<"s ";
            if(c1>=2 and c2>=24)
            s++;
            if(c1>=24 and c2>=2 )
            s++;
            if(c1>=14 and c2>=4 )
            s++;
            if(c1>=4 and c2>=14 )
            s++;
        }
    }
	//cout<<s<<" ";
    for(i=0;i<k;i++)
    {
        ll c1=fun(n,v[i]);
        if(c1>=74)
        s++;
    }
    cout<<s;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	sieve();
	ll t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int m;
    int a = 1,b = 4,c,d,e = 6;
    int y = 2004;
    int ans;
    while(1){
        scanf("%d %d",&m,&d);
        if(m == 0 && d == 0) break;
        if(m == 1 || m == 10) c = 1;
        else if(m == 2 || m == 3 || m == 11) c = 4;
        else if(m == 4 || m == 7) c = 0;
        else if(m == 5) c = 2;
        else if(m == 6) c = 5;
        else if(m == 8) c = 3;
        else if(m == 9 || m == 12) c = 6;
        ans = (a + b + c + d + e) % 7;
        if(m == 1 || m == 2) ans = (a + b + c + d + e - 1) % 7;
        switch(ans){
            case 0:
                printf("Saturday\n");
                break;
            case 1:
                printf("Sunday\n");
                break;
            case 2:
                printf("Monday\n");
                break;
            case 3:
                printf("Tuesday\n");
                break;
            case 4:
                printf("Wednesday\n");
                break;
            case 5:
                printf("Thursday\n");
                break;
            case 6:
                printf("Friday\n");
                break;
        }
    }
    return 0;
}

Measured memory_bytes: 584
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)




void swap(ll *a, ll *b){
    ll t;
    t = *a;
    *a = *b;
    *b = t;
}


int main() {
    ll q;
    cin >> q;
    
    REP(i, q){
        ll a, b;
        cin >> a >> b;
        
        if(a > b) swap(&a, &b);
        
        if(a == b || a + 1 == b){
            cout << 2 * a - 2 << '\n';
        }
        else{
            ll l = 0, r = 1e9, c = (l + r) / 2;
            while(r - l > 1){
                if(c * c < a * b){
                    l = c;
                }
                else{
                    r = c;
                }
                c = (l + r) / 2;
            }
            
            if(c * (c + 1) >= a * b){
                cout << 2 * c - 2 << '\n';
            }
            else{
                cout << 2 * c - 1 << '\n';
            }
        }
    }
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())
c = [input() for _ in range(h)]

ans = 0
for bit_h in range(1 << h):
    for bit_w in range(1 << w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if (bit_h >> i) & 1 == 1 or (bit_w >> j) & 1 == 1:
                    continue
                if c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            ans += 1

print(ans)


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ll x;
  cin >> x;

  ll ans = x / 500 * 1000;
  x %= 500;
  ans += x / 5 * 5;
  cout << ans << endl;



  
  return 0;
}

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

using namespace std;

const int MAX_N = 1e6 + 200, mod = 998244353;

int n, upper, ai[MAX_N], bi[MAX_N], ci[MAX_N];

int fpow(int bas, int tim)
{
	int ret = 1;
	while (tim)
	{
		if (tim & 1)
			ret = 1LL * ret * bas % mod;
		bas = 1LL * bas * bas % mod;
		tim >>= 1;
	}
	return ret;
}

const int inv2 = fpow(2, mod - 2);

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &ai[i]), bi[ai[i]]++;
	upper = *max_element(ai + 1, ai + 1 + n);
	for (int i = 1; i <= upper; i++)
		ci[i] = fpow(i, mod - 2);
	for (int i = 1; i <= upper; i++)
		for (int j = (i << 1); j <= upper; j += i)
			ci[j] = (0LL + ci[j] + mod - ci[i]) % mod;
	int ans = 0;
	for (int d = 1; d <= upper; d++)
	{
		int p1 = 0, p2 = 0;
		for (int i = d; i <= upper; i += d)
			p1 = (0LL + p1 + 1LL * bi[i] * i % mod) % mod, p2 = (0LL + p2 + 1LL * bi[i] * i % mod * i % mod) % mod;
		int pans = (0LL + 1LL * p1 * p1 % mod + mod - p2) % mod * inv2 % mod;
		ans = (0LL + ans + 1LL * pans * ci[d] % mod) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12328
/*بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم*/

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

const int mx=1e5+5;
vector <int> edges[mx];
int DP[mx];
bool vis[mx];

bool check (vector <int>& val,int b,int mid)
{
    int i,j;
    bool ret=true;
    i=0;
    j=val.size()-1;
    while (i<j) {
        if (i==mid) i++;
        if (j==mid) j--;
        if (val[i]+val[j]>b) {
            ret=false;
            break;
        }
        else i++,j--;
    }
    return ret;
}

bool DFS (int u,int b)
{
    vis[u]=true;
    bool ret=true;
    vector <int> val;

    for (auto v : edges[u]) {
        if (!vis[v]) {
            ret=(ret & DFS(v,b));
            val.push_back(DP[v]);
        }
    }
    if (!ret) return ret;
    if (val.empty()) {
        DP[u]=1;
        return true;
    }
    int m=val.size();
    if (m%2==0) {
        val.push_back(0);
        m++;
    }
    sort(val.begin(),val.end());

    int hi,lo,mid,ans=-1;
    lo=0,hi=m-1;
    while (lo<=hi) {
        mid=(lo+hi)/2;
        if (val[mid]<=b && check(val,b,mid)) {
            ans=mid;
            hi=mid-1;
        }
        else lo=mid+1;
    }
    if (ans==-1) return false;
    else {
        DP[u]=1+val[ans];
        return true;
    }
}

int main ()
{
    int i,n;

    scanf ("%d",&n);
    for (i=1;i<n;i++) {
        int u,v;
        scanf ("%d %d",&u,&v);
        edges[u].push_back(v);
        edges[v].push_back(u);
    }

    int u,hi,lo,mid,ans,cnt=0;
    for (i=1;i<=n;i++) {
        cnt+=edges[i].size()%2;
        if (edges[i].size()==1) u=i;
    }

    lo=1,hi=n-1;
    while (lo<=hi) {//cout<<lo<<endl;
        mid=(lo+hi)/2;
        memset(vis,0,sizeof(vis));
        if (DFS(u,mid)) {
            ans=mid;
            hi=mid-1;
        }
        else lo=mid+1;
    }
    printf ("%d %d\n",cnt/2,ans);

    return 0;
}


Measured memory_bytes: 18688
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() 
{
  int N;
  cin>>N;
  vector<pair<int,int>>D(N);
  for(int i=0;i<N;++i)
  {
    cin>>D[i].first;
    cin>>D[i].second;
  }

  priority_queue<int>anses;
  int ans=0;
  for (auto&&d:D)
  {
    if(d.first==d.second)
    {
      ++ans;
    }
    else
    {
      anses.push(ans);
      ans=0;
    }
    
  }
  
  ans>=3||anses.top()>=3?cout<<"Yes"<<endl:cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e7+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
vector<int> table;
bool is_prime[1000100];
int prime[1000100];

int main(){
	for (int i = 0;; i++){
		if (7 * i + 1 > 300000)break;
		table.push_back(7 * i + 1);
		if (7 * i + 6 > 300000)break;
		table.push_back(7 * i + 6);
	}
	fill(is_prime, is_prime + 1000100, 1);
	is_prime[1] = 0;
	int p = 0;
	for (int i = 0; i < table.size(); i++){
		if (is_prime[table[i]]){
			prime[p++] = table[i];
			for (int j = 2 * table[i]; j <= 300000; j += table[i]){
				is_prime[j] = 0;
			}
		}
	}
	while (cin >> n&&n != 1){
		vector<int> ans;
		for (int i = 0; i < p; i++){
			if (n%prime[i] == 0){
				ans.push_back(prime[i]);
			}
		}
		cout << n << ":";
		REP(i, ans.size()){
			cout << " " << ans[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 4240
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		InputStream in = System.in;

		sc = new Scanner(in);

		int N = sc.nextInt();
		long[] A = new long[N];
		int answer = 0;
		boolean run = true;

		for(int i = 0; i < N; i++){
			A[i] = sc.nextLong();
		}

		while(run){
			for(int i = 0; i < N; i++){
				if(A[i] % 2 != 0){
					run = false;
					break;
				}else{
					A[i] /= 2;
				}
			}
			answer++;
			//System.out.println(answer);
		}
		System.out.println(answer-1);
	}
}

Measured memory_bytes: 22996
#include<iostream>
using namespace std;
#include<cstring>
int main()
{
	char a[100008];
	cin>>a;
	int la=strlen(a);
	for(int i=0;i<la;i++)
	{
		if(a[i]!='C')continue;
		for(int j=i+1;j<la;j++)
		if(a[j]=='F')
		{
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int[,] G = new int[N, N];
		for(int i = 0; i < N; i++)
		{
			string S = GetString();
			for(int j = 0; j < N; j++)
				G[i, j] = (S[j] == '1') ? 1 : 0;
		}

		int[] color = Enumerable.Repeat(-1, N).ToArray();
		if(!isBipartite(N, G, color, 0, 0))
		{
			Console.WriteLine(-1);
			return;
		}

		int[,] d = new int[N, N];
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				d[i, j] = (i == j) ? 0 : (G[i, j] == 1) ? 1 : 100000;

		warshall_floyd(ref d);
		int D = 0;
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				chmax(ref D, d[i, j]);

		Console.WriteLine(D + 1);
	}

	private bool isBipartite(int N, int[,] G, int[] color, int v, int c)
	{
		color[v] = c;
		for(int u = 0; u < N; u++)
		{
			if(G[v, u] == 0)
				continue;

			if(color[u] == -1)
			{
				if(!isBipartite(N, G, color, u, c ^ 1))
					return false;
			}
			else if(color[u] == c)
				return false;			
		}
		return true;
	}

	private static void warshall_floyd(ref int[,] d)
	{
		int V = d.GetLength(0);
		for(int k = 0; k < V; k++)
			for(int i = 0; i < V; i++)
				for(int j = 0; j < V; j++)
					d[i, j] = Math.Min(d[i, j], d[i, k] + d[k, j]);
	}

	private void chmax(ref int x, int y) => x = Math.Max(x, y);
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


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

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 
ll dp[2][(1<<21)+1];
#define MOD 1000000007
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n][n] = {};
    vector<int> s[n];
    for(int i=0;i<n;++i)
    {
      for(int j=0;j<n;++j)
      {
        int tmp;
        cin >> tmp;
        if(tmp){
          s[i].push_back(j);
        }
      }
    }
    int cur = 0;
    int nxt = 1;
    dp[cur][0] = 1;
    for(int i=0;i<n;++i)
    {
      for(int tgt : s[i])
      {
        for(int j=0;j<(1<<n);++j)
        {
          if((j & (1 << tgt)) != 0) continue;

          dp[nxt][j | (1 << tgt)] += dp[cur][j];
          if(dp[nxt][j | (1 << tgt)] > MOD){
            dp[nxt][j | (1 << tgt)] -= MOD;
          }
        }
      }
      cur = 1 - cur;
      nxt = 1 - nxt;
    }
    cout << dp[cur][(1<<n)-1] << endl;
}

Measured memory_bytes: 33024
#include "bits/stdc++.h"
using namespace std;
int main() {
  cin.tie(0); ios_base::sync_with_stdio(false);
  int N, L; cin >> N >> L;
  vector<string> S(N); for (auto& s : S) cin >> s;
  sort(S.begin(), S.end());
  for (auto s : S) cout << s;
  cout << endl;
  return 0;
}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int a,b;
  cin>>a>>b;
  if(a==b)puts("Draw");
  else{
    if(a==1)puts("Alice");
    else if(b==1)puts("Bob");
    else puts(a<b?"Bob":"Alice");
  }
  return 0;
}


Measured memory_bytes: 764
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
#define MOD 1000000007
using namespace std;
typedef long long ll;
char s[MAXN];
int n,cnt[30];
ll pre,ans;
int main(){
	SF("%d",&n);
	SF("%s",s);
	for(int i=0;i<n;i++)
		cnt[s[i]-'a']++;
	pre=1;
	for(int i=25;i>=0;i--){
		ans+=cnt[i]*pre;
		ans%=MOD;
		pre=pre*(cnt[i]+1)%MOD;
	}
	PF("%lld",ans);
}

Measured memory_bytes: 256
a,b,c,k=map(int,input().split())
ai=0
bi=0
ci=0
if a >= k:
  ai=k
else:
  ai=a
  if b>= k-ai:
    bi=k-ai
  else:
    bi=b
    ci= k - ai - bi
print(ai-ci)
        


Measured memory_bytes: 9116
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = unsigned long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;


int main() {
string S;
  in(S);
  if(S=="ABC") out("ARC");
  else out("ABC");
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll n,k,sum;
struct jz
{
	ll key[51][51];
};
jz mul(jz a,jz b)
{
	jz c;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			c.key[i][j]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			for(int l=1;l<=n;l++)
				c.key[i][j]=(c.key[i][j]+a.key[i][l]*b.key[l][j])%mod;
	return c; 
}
jz ksm(jz a,ll b)
{
	jz base,res;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			base.key[i][j]=a.key[i][j],res.key[i][j]=0;
	for(int i=1;i<=n;i++)
		res.key[i][i]=1;
	while(b)
	{
		if(b&1)
			res=mul(res,base);
		base=mul(base,base);
		b>>=1;
	}
	return res;
}
int main()
{
	jz a,ans,base;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			cin>>a.key[i][j];
	for(int i=1;i<=n;i++)
		base.key[1][i]=1;
	ans=mul(base,ksm(a,k));
	for(int i=1;i<=n;i++)
		sum=(sum+ans.key[1][i])%mod;	
	cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 512
def binarySearch(key, array):
        left = 0
        right = len(array)
        while left < right:
                mid = (left + right) // 2
                if array[mid] == key:
                        return 1
                elif key < array[mid]:
                        right = mid
                else:
                        left = mid + 1
        return 0

num = int(input())
array = list(map(int, input().split()))

num2 = int(input())
array2 = list(map(int, input().split()))

count = 0
for i in range(num2):
        if binarySearch(array2[i], array):
                count += 1

print(count)


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

int main() {
	int n, y;
	cin >> n >> y;
	/*if (y > n * 10000) {
		cout << "0 0 0" << endl;
		return 0;
	}*/
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n - i;j++) {
			int l = n - (i + j);
			if (i * 10000 + j * 5000 + l * 1000 == y) {
				cout << i << " " << j << " " << l << endl;
				return 0;
			}

		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}

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

int main() {
  int a[26]={0};
  int n;
  cin >> n;
  r(i,n){
    string s;
    cin >> s;
    unordered_map<int,int> m;
    r(j,s.size()){
      m[s[j]-'a']++;
    }
   if(i){
     r(j,26){
      a[j]=min(m[j],a[j]);
    }
   }
    else  r(j,26)a[j]=m[j];
  }
  int i = 0;
  while(i<26){
    while(a[i]>0){
      cout<<char('a'+i);
      a[i]--;
    }
    i++;
  }
  cout<<endl<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n,m;
int main()
{
	cin>>n>>m;
	if(n>0&&m>0) cout<<"Positive";
	else if(n==0||m==0) cout<<"Zero";
	else if((n<0&&m>0)||(n>0&&m<0)) cout<<"Zero";
	else if(n<0&&m<0) {
		int x;
		x=(-1*n)-(-1*m)+1;
		if(x%2==0) cout<<"Positive";
		else cout<<"Negative";
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	int N,M;
	int A[51],B[51];
	int i,j,k;
	
	int x,y;
	int length[51];
	int parent[51];
	
	int cnt=0;
	int cnt1=0;
	
	cin>>N>>M;
	
	for(i=1;i<=M;i++){
		cin>>A[i]>>B[i];
	}
	
	for(i=1;i<=N;i++){
		length[i]=1;
		parent[i]=i;
	}
	
	for(i=1;i<=M;i++){
		
		cnt=0;
		for(k=1;k<=N;k++){
			length[k]=1;
			parent[k]=k;
		}
		for(j=1;j<=M;j++){
			if(i==j){
				continue;
			}
			x=A[j];
			
			while(x!=parent[x]){
				x=parent[x];
			}
			
			y=B[j];
			
			while(y!=parent[y]){
				y=parent[y];
			}
			if(x!=y){
				cnt++;
				if(length[x]<length[y]){
					parent[x]=y;
				}
				else if(length[x]>length[y]){
					parent[y]=x;
				}
				else{
					parent[y]=x;
					length[x]++;
				}
			}
		}
		
		//cout<<cnt<<endl;
		
		if(cnt!=N-1){
			cnt1++;
		}
		
		
		
		
	}
	
	cout<<cnt1<<endl;
	
	
	return 0;
	
}
	
			
			
			
			

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = (int)1e6 + 5;
bool p[MAX_N];
vector<int> prime;

void make_prime (void ){

	prime.clear();
	fill (p, p+MAX_N, true );
	p[0] = false;
	p[1] = false;
	for (int i = 2; i < MAX_N; i++ ){
		if (p[i] ){
			for (int j = 2*i; j < MAX_N; j+= i ){
				p[j] = false;
			} // end for
		} // end if
	} // end for
	rep (i, MAX_N )
		if (p[i] ) prime.push_back (i );
}
			
int main()
{
	ios_base::sync_with_stdio(0);
	make_prime ();
	int N, P;
	while (cin >> N >> P ){
		if (N == -1 && P == -1 ) break;
		vector<int> pp; pp.clear();
		rep (i, prime.size() ){
			if (prime[i] > N ) pp.push_back (prime[i] );
			if (pp.size() >= P ) break;
		} // end rep
		vector<int> res; res.clear();
		rep (i, P ){
			for (int j = i; j < P; j++ ){
				res.push_back (pp[i] + pp[j] );
			} // end for
		} // end rep
		sort (ALL (res ) );
		cout << res[P-1] << endl;
	} // end while
 
	return 0;
}

Measured memory_bytes: 2612
# 2019-11-20 12:21:36(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# import re
# import heapq
# import array
# from scipy.misc import comb # (default: exact=False)
# import numpy as np 


def main():
    s = sys.stdin.readline().rstrip()

    count = 0
    for i in range(len(s)-1):
        if s[i+1] != s[i]:
            count+= 1

    print(count)


if __name__ == "__main__":
    main()


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

int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);
  string s;
  cin>>s;
  if(s.size() < 2) {cout<<-1<<' '<<-1; return 0;}
  if(s.size() == 2) {
  	if(s[0] == s[1]) cout<<1<<' '<<2;
    else cout<<-1<<' '<<-1;
    return 0;
  }
  int x=-1,y=-1;
  for (int i=0;i<s.size()-2;i++){
    if (s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i]){
      x=i+1;
      y=i+3;
      break;
    }
  }cout<<x<<' '<<y<<endl;
  return 0;

}

Measured memory_bytes: 3720
#include <iostream>
#define abs(x) (x) > 0 ? (x) : -(x)
using namespace std;

int main() {
    string S;
    cin >> S;
    int mi = 1010;
    for (int i = 0; i + 3 <= S.size(); i++) {
        int x = 0;
        for (int j = i; j < i + 3; j++) {
            x = x * 10 + (S[j] - 48);
        }
        mi = min(mi, abs(753 - x));
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, init, n) for(int i = init; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
 
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to, cost;
};
 
const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
 
    vector<int> E(N, 0), W(N, 0);
 
    if(S[0] == 'W')
        W[0]++;
    
    if(S[N - 1] == 'E')
        E[N - 1]++;
 
    FOR(i, 1, N)
    {
        if(S[i] == 'W')
        {
            W[i] += W[i - 1] + 1;
        }
        else
        {
            W[i] = W[i - 1];
        }
    }
 
    for(int i = N - 2; 0 <= i; i--)
    {
        if(S[i] == 'E')
        {
            E[i] += E[i + 1] + 1;
        }
        else
        {
            E[i] = E[i + 1];
        }
    }
 
    int ans = iINF;
 
    REP(i, N)
    {
        ans = min(ans, E[i] + W[i] - 1);
    }
 
    cout << ans << endl;
 
    return 0;
}

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

S = {}
for i in range(N):
  s = [0 for _ in range(26)]
  tmp = input()
  for j in range(10):
    s[ord(tmp[j]) - ord("a")] += 1
  
  s = ",".join(map(str, s))
  if s in S:
    S[s] += 1
  else:
    S[s] = 1

ans = 0
for v in S.values():
  if v > 1:
    for i in range(1, v):
      ans += i

print(ans)

Measured memory_bytes: 21600
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;

int main(){
    ll n;
    cin >> n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ll N=n/i;
        //cerr<<N<<endl;
        ans+=N*(N+1)*i/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> v(n + 10);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum ^= v[i];
  }
  for (int i = 0; i < n; i++) {
    cout << (sum ^ v[i]) << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4024
n = int(raw_input())
p = [0 for i in range(0, 101)]
m = [[0 for i in range(0, 101)] for j in range(0, 101)]

for i in range(1, n+1):
   p[i-1], p[i] = map(int, raw_input().split())
     
for k in range(2, n+1):
   for i in range(1, n-k+2):
      j = i+k-1
      m[i][j] = float("inf")
      for l in range(i, j):
         m[i][j] = min(m[i][j], m[i][l] + m[l+1][j] + p[i-1]*p[l]*p[j])
 
print m[1][n]

Measured memory_bytes: 6540
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(0, i, N)
    {
        cin >> A.at(i);
        mp[A.at(i)]++;
    }
    sort(all(A));

    vector<ll> memo(1000100, 0);
    for (auto m : mp)
    {
        if (m.second > 1)
        {
            if (memo.at(m.first) == 1)
            {
                continue;
            }
            for (ll i = m.first; i <= 1000000; i += m.first)
            {
                memo.at(i) = 1;
            }
        }
    }

    ll ans = 0;

    rep(0, i, N)
    {
        if (memo.at(A.at(i)) == 1)
        {
            continue;
        }
        
        ans++;
        for (ll j = A.at(i); j <= 1000000; j += A.at(i))
        {
            memo.at(j) = 1;
        }
    }

    cout << ans << endl;
}

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

int main() {
  long long N,p,t,j,f,ans;
  cin>>N;
  f=-1;
  vector<long long>a(N),b(1000);
  for(int i=0;i<999;i++){
    b[i]=0;
  }
  for(int i=0;i<N;i++){
    cin>>a[i];
    p=a[i];
    j=0;
    while(p>0){
      b[j]+=p%2;
        p/=2;
      j++;
    }
  }
    for(int i=0;i<999;i++){
      if(b[i]!=0){
        f=i;
      }
  }
  if(f>=0){
  for(int i=0;i<N;i++){
    j=0;
    ans=0;
    t=1;
    while(j<=f){
      ans+=t*((a[i]%2+b[j])%2);
        a[i]/=2;
      t*=2;
      j++;
    }
    cout<<ans;
      if(i!=N-1){
        cout<<" ";
      }
  }
  cout<<endl;
  }
  else{
     for(int i=0;i<N;i++){
    cout<<0;
      if(i!=N-1){
        cout<<" ";
      }
     }
  }
}


Measured memory_bytes: 4776
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
//#include <bits/stdc++.h>

using namespace std;

int main(){
    string s;

    cin >> s;

    int cnt0 = 0;
    int cnt1 = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == '0') cnt0++;
        else cnt1++;
    }

    cout << min(cnt1, cnt0)*2 << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;


public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int max = Math.max(sc.nextInt(),sc.nextInt());
    int n = sc.nextInt();
    int ans = n/max;
    if(n%max!=0) ans++;
    System.out.println(ans);
  }

}


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

int main() {
    int N;
    cin >> N;
    int first_digit = N - (N / 10)*10;
    switch(first_digit) {
        case 2:
        case 4:
        case 5:
        case 7:
        case 9:
            cout << "hon";
            break;
        case 0:
        case 1:
        case 6:
        case 8:
            cout << "pon";
            break;
        case 3:
            cout << "bon";
            break;
    }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main(){
    int n; cin >> n;
    int cnt;
    string s; cin >> s;
    for (int i=0; i < s.size(); i++) {
        cnt = n;
        if (s[i] + cnt > 'Z') {
            cnt -= 'Z' - s[i] + 1;
            s[i] = 'A' + cnt;
        }
        else { 
            s[i] = s[i] + cnt;
        }   
        cout << s[i];
    }
}

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

bool seen[110000];
ll vec[110000];
map<pair<int,int>,ll> ma;
 
void dfs(const vector<vector<ll>> &G,int v){
  seen[v]=true;
  for(auto next_v:G[v]){
    if(seen[next_v])continue;
    vec[next_v]=vec[v]+ma[{v,next_v}];
    dfs(G,next_v);
  }
}
 
int main(){
  int n;
  cin>>n;
  vector<vector<ll>> g(n);
  for(int i=0;i<n-1;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    ma[{a,b}]=c;
    ma[{b,a}]=c;
  }
  int q,k;
  cin>>q>>k;
  k--;
  vec[k]=0;
  dfs(g,k);
  for(int i=0;i<q;i++){
    int a,b;
    cin>>a>>b;
    a--;
    b--;
    cout<<vec[a]+vec[b]<<endl;
  }
}

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

// #define DEBUG 1

#define int long long
#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define fill1(a,z) fill_n(a, sizeof(a)/sizeof(a[0]), z)
#define fill2(a,z) fill_n(a[0], sizeof(a)/sizeof(a[0][0]), z)
#define fill3(a,z) fill_n(a[0][0], sizeof(a)/sizeof(a[0][0][0]), z)
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) {for (auto x : v) {pr(x)} nl}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;
typedef pair<int,int> edge; 

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

void build_odd_tree(int n, int offset, vector<edge>& edges) 
{
    for (int i=2; i<=n; i++) {
        edges.push_back({1,i}); 
        edges.push_back({i,(i^1)+offset}); 
    }   
    edges.push_back({3+offset, 1+offset}); 
}

int32_t main()
{
    #ifdef DEBUG
    //freopen("C.txt","r",stdin);
    //freopen("","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n; 
    cin >> n; 
    vector<edge> edges; 
    
    if (n < 3) {
        cout << "No" << endl; 
        return 0; 
    }
    else if (n%2 == 1) {
        build_odd_tree(n, n, edges); 
    }
    else if (n%2 == 0) {
        build_odd_tree(n-1, n, edges); 
        
        
        // find first 1 bit 
        int bit = 0; 
        for (; bit <= 20; bit++) {
            if (n & (1<<bit)) 
                break; 
        }
        int a = 1<<bit; 
        int b = n ^ a; 
        if (b == 0) {
            // means n is a power of 2 
            cout << "No" << endl; 
            return 0; 
        }
        // connect n nodes through the path n -- a -- 1 -- 1^b -- n
        edges.push_back({a,n}); 
        edges.push_back({1^b, n+n});   
    }
    
    cout << "Yes" << endl; 
    for (edge e : edges) {
        cout << e.first << " " << e.second << endl;
    }
    return 0;
}


Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
const int N=300005;
long long z;
int n,l,c0,c1,c2,x[N],t[N],f[N];
int main() 
{
	scanf("%d%d",&n,&l);
	for (int i=0;i<n;i++)scanf("%d",&x[i]);
	z=1;
	for (int i=0;i<n;i++)
	 {
		scanf("%d",&t[i]);
		z+=t[i]/(2*l);t[i]%=2*l;
		if (t[i]>0)
		 {
			z++;
			int f=(t[i]<=(l-x[i])*2),g=(t[i]<=(x[i])*2);
			if (i==n-1)
			 {
				if (f)z--;
				break;
			 }
			if (g)
			 {
				c0++;
				if (f)c2++;
			 }
			else if (f)c1++;
			while (c0-c2<c1+c2)
			 {
				if (c2>0)c2--;
				else c1--;
			 }
		 }
	 }
	z-=c1+c2;
	printf("%lld\n",z*l*2);
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N; cin >> N;
    ll MAX = 30;
    ll bin[N][MAX];
    ll ans[N][MAX];
    rep(i, N){
        ll a;
        cin >> a;
        rrep(j, MAX - 1, 0){
            bin[i][j] = a % 2;
            a = a / 2;
        }
    }
    rep(j, MAX){
        ll tmp = 0;
        rep(i, N){tmp += bin[i][j];}
        if (tmp % 2 == 0){
            rep(i, N){ans[i][j] = bin[i][j];}
        } else {
            rep(i, N){ans[i][j] = (bin[i][j] == 0) ? 1 : 0;}
        }
    }
    // rep(i, N){rep(j, MAX){cout << ans[i][j] << " ";} cout << endl;}

    rep(i, N){
        ll tmp = 0;
        rep(j, MAX){
            tmp = tmp * 2 + ans[i][j];
        }
        cout << tmp << " ";
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 97336
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
//#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvector(name,typ,m,n)vector<vector<typ> > name(m,vector<typ> (n))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
ll ceil(ll a,ll b){
    return ((a+b-1)/b);
}
const int INF = 1000000000;
const ll INF64 = 9223372036854775807ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;
//mapは、if関数などで覗いただけで構成されるので注意しよう！
int main(){
    int n,m,c;
    std::cin >> n>>m>>c;
    VEC(int,b,m);
    int ans=0;
    rep(i,n){
        VEC(int,a,m);
        int d=c;
        rep(j,m){
            d+=a[j]*b[j];
        }
        if(d>0)ans++;
    }
    std::cout << ans << std::endl;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  int N;
  cin >> N;

  long long a[N];
  long long ret = 0;
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    ret += a[i] - 1;
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256