akhauriyash/Code-Regression huggingface dataset:
from itertools import accumulate, chain, islice

N = int(input())
A = [int(input()) for _ in range(N)]

L = accumulate(A, max)
R = accumulate(reversed(A), max)

L = chain([-1], L)
R = chain([-1], R)
R = islice(reversed(list(R)), 1, None)

M = (max(l, r) for l, r in zip(L, R))

for m in M:
    print(m)


Measured memory_bytes: 14076
"""
勝利条件
    最後のリンゴを取る
    1種類で2個のリンゴを残す
    2種類で2個2個のリンゴを残す
    3種類で2個2個2個のリンゴを残す

    1種類で4個のリンゴを残す
    2種類で4個4個のリンゴを残す


    全種類のリンゴを偶数にするゲーム
    全種類のリンゴが偶数じゃない場合は勝てるゲーム
    1つでも奇数があれば勝てるゲーム
    
"""

n = int(input())
a = [int(input()) % 2 != 0 for _ in range(n)]  # 奇数ならTrue、偶数ならFalse

if any(a):
    print("first")
else:
    print("second")



Measured memory_bytes: 3888
#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node *next;
}node;

void push(node **ref, int data){
    node *newn = malloc(sizeof(node));
    newn->data = data;
    newn->next = (*ref);
    (*ref) = newn;
}
int pop(node **ref){
    int x = (*ref)->data;
    (*ref) = (*ref)->next;
    return x;
}
void show(node **ref){
    if((*ref)->next == NULL){
        printf("%d", (*ref)->data);
        return;
    }else{
        show(&(*ref)->next);
        printf(" %d", (*ref)->data);
    }
}

node *lefts;
node *regions;
node *volumes;

int main(){
    lefts = NULL;
    regions = NULL;
    volumes = NULL;
    node *temp;
    char c;
    int i, l, height, a, v, count;
    a = i = v = count = 0;
    while((c = getchar())!=EOF){
        if(c == '\\'){
            push(&lefts, i);
        }else if(c == '/'){
            if(lefts!= NULL){
                l = pop(&lefts);
                height = i - l;
                v += height;
                while(regions != NULL && regions->data > l){
                    height += volumes->data;
                    pop(&regions);
                    pop(&volumes);
                    count--;
                }
                push(&regions, l);
                push(&volumes, height);
                count++;
            }
        }
        i++;
    }
    printf("%d\n%d", v, count);
    if(volumes != NULL) {
        printf(" ");
        show(&volumes);
    }
    printf("\n");
    return 0;
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;
string s;
ll w[2*100000+1],b[2*100000+1];

int main(){
    cin >> n >> s;
    rep(i,n){
        b[i+1] = b[i] + (s[i] == '#');
        w[i+1] = w[i] + (s[i] == '.');
    }
    if(w[n] == n){
        cout << 0 << endl;
        return 0;
    }
    ll ans = INF;
    rep(i,n+1){
        ans = min(ans, b[i] + w[n] - w[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3716
/* be name khoda */

// #define stream_enable
#define long_enable

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>

// #include <bits/stdc++.h>
// #include <numeric>
// #include <iomanip>
// #include <cmath>
// #include <bitset>
// #include <fstream>

using namespace std;

#ifdef stream_enable
#define cin sss
#endif

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<vi> vii;
typedef vector<pii> vpii;

const ll MOD = 1000000007;

const long long BIG = 1446803456761533460LL;
const int Big = 336860180;

#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define pb push_back

#define debug(x) cout << #x << " -> " << (x) << endl;
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl;
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl;
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl;
#define debugp(x) cout << #x << " -> " << "(" << (x).ff << ", " << (x).ss << ")" << endl;
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].ff << ", " << (x)[i1_dap].ss << ")" << endl; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_da].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = (a + (b)) % MOD
#define Mul(a, b) a = (a * (b)) % MOD

stringstream sss;

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

const ll maxn = 100010;

void MAIN() {

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << (a != c) << endl;

}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    // cout << fixed << setprecision(10);
    sss << R"(
11 30
12 1

    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
void main() {
	long n, m, l;
	"%d %d %d\n".readf(&n, &m, &l);
	long[][] a, b;
	foreach (_n; 0..n) a ~= readln.split.to!(long[]);
	foreach (_m; 0..m) b ~= readln.split.to!(long[]);
	foreach (_a; a) {
		long[] c = [];
		foreach (_l; 0..l) {
			long s = 0;
			foreach (_m; 0..m) s += _a[_m] * b[_m][_l];
			c ~= s;
		}
		c.to!(string[]).join(" ").writeln;
	}
}

Measured memory_bytes: 3688
#include <iostream>
#define INF 2000000000
using namespace std;

int L[250001],R[250001];
int cnt;

void merge(int a[],int l,int m,int r){
	int n1=m-l;
	int n2=r-m;
	for(int i=0;i<n1;i++)
		L[i]=a[l+i];
	for(int i=0;i<n2;i++)
		R[i]=a[m+i];
	L[n1]=INF;
	R[n2]=INF;
	int i=0,j=0;
	for(int k=l;k<r;k++){
		if(L[i]<=R[j])
			a[k]=L[i++];
		else
			a[k]=R[j++];
		cnt++;
	}
}

void mergesort(int a[],int l,int r){
	if(l+1<r){
		int m=(l+r)/2;
		mergesort(a,l,m);
		mergesort(a,m,r);
		merge(a,l,m,r);
	}
}

int main(){
	int n,a[500000];
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	mergesort(a,0,n);
	for(int i=0;i<n;i++)
		cout<<a[i]<<((i!=n-1)?' ':'\n');
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 6952
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long a = sc.NextLong();
        long b = sc.NextLong();
        long c = sc.NextLong();
        long d = sc.NextLong();

        long answer = long.MinValue;

        answer = Math.Max(answer, a * c);
        answer = Math.Max(answer, a * d);
        answer = Math.Max(answer, b * c);
        answer = Math.Max(answer, b * d);

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

map<ll, ll> memo;
ll a,b,c,d;

ll solve(ll n)
{
    // 再帰的にnを求める
    if (n==0) return 0;
    if (n==1) return d;
    if (memo.count(n)) return memo[n];
    ll d2 = (n/2)*2;
    ll u2 = ((n+1)/2)*2;
    ll d3 = (n/3)*3;
    ll u3 = ((n+2)/3)*3;
    ll d5 = (n/5) * 5;
    ll u5 = ((n+4)/5)*5;

    ll res = 1e18;
    // n<10^18, d<10^9より、普通に計算するとoverflowしうる
    if (n < res/d) res = n * d; 

    res = min(res, llabs(u2-n) * d + a + solve(u2/2));
    res = min(res, llabs(d2-n) * d + a + solve(d2/2));
    res = min(res, llabs(u3-n) * d + b + solve(u3/3));
    res = min(res, llabs(d3-n) * d + b + solve(d3/3));
    res = min(res, llabs(u5-n) * d + c + solve(u5/5));
    res = min(res, llabs(d5-n) * d + c + solve(d5/5));

    memo[n] = res;

    return res;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int t;
    cin >> t;
    rep(i,t)
    {
        memo.clear();
        ll n;
        cin >>  n >> a >> b >> c >> d;

        cout << solve(n) << endl;
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

long double EPS = 1E-14;

bool sgn(double a, double b) {
    return a < b - EPS;
}

int main() {
    long double a, b, c;
    cin >> a >> b >> c;

    if (sqrt(a) + sqrt(b) + EPS < sqrt(c)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

template <typename T>
inline void read(T &x)
{
    T data = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch))
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (isdigit(ch))
    {
        data = (data << 3) + (data << 1) + ch - '0';
        ch = getchar();
    }
    x = f * data;
}
const int maxn = 3e5 + 9;
map<pii, int> mp;
int row[maxn], col[maxn];
signed main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("data.txt", "w", stdout);
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //std::cout.tie(0);
    int n, m, s;
    read(n), read(m), read(s);
    for (int i = 1; i <= s; ++i)
    {
        int x, y;
        read(x), read(y);
        mp[make_pair(x, y)]++;
        row[x]++, col[y]++;
    }
    int maxh = *max_element(row + 1, row + n + 1);
    int maxw = *max_element(col + 1, col + m + 1);
    vi h, w;
    for (int i = 1; i <= n; ++i)
    {
        if (row[i] == maxh)
            h.emplace_back(i);
    }
    for (int i = 1; i <= m; ++i)
    {
        if (col[i] == maxw)
            w.emplace_back(i);
    }
    for (int i = 0; i < h.size(); ++i)
        for (int j = 0; j < w.size(); ++j)
            if (mp[make_pair(h[i], w[j])] == 0)
            {
                cout << maxh + maxw << endl;
                return 0;
            }
    cout << maxh + maxw - 1 << endl;

    //fclose(stdin);
    //fclose(stdout);
    return 0;
}

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

using namespace std;

#define ll long long
#define rep(i,p,q) for(ll i = p;i < q;i++)

vector<string> waku;
ll ind;

void countUp(string s, ll deg, ll num){
    if(ind >= waku.size()) return ;
    string nextUpper = s + to_string(num);
    if(deg == 1){
            waku[ind] = nextUpper;
            ind++;
            return;
    }
    rep(i,-1,2){
        if(num + i < 0 || num + i > 9) continue;
        else{
            countUp(nextUpper, deg - 1, num + i);
        }
    }
}

int main(void){
    ll k;
    cin >> k;
    waku = vector<string>(k,"");
    ind = 0;
    ll deg = 1;
    while(ind < k){
        rep(i,1,10){
            countUp("", deg, i);
            if(ind >= k) break;
        }
        deg++;
    }
    cout << waku[k-1] << endl;
}

Measured memory_bytes: 5760
n, c, k = map(int, input().split())
t = list()
for i in range(n):
    t.append(int(input()))
t.sort()
flag = 0
cnt = 0
state = 0
for i in range(0,n):
    if flag != 0:
        flag = flag - 1
        state = 0
    else:
        for j in range(0,min(c,n-i)):
            if t[i+j]-t[i] <= k and j == min(c-1,n-i-1): 
                cnt = cnt + 1
                flag = min(c-1,n-i-1)        
                state = 1
                break
            elif t[i+j]-t[i] <= k:
                state = 2
            elif t[i+j]-t[i] > k:
                cnt = cnt + 1
                flag = j-1
                state = 3
                break
print(cnt)

Measured memory_bytes: 13212
import java.util.*;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();

		String next = A.substring(0, 1);
		A = A.substring(1, A.length());
		//System.out.println(A);
		for(;;){
			if(next.equals("a")){
				if(A.isEmpty()){
					System.out.println("A");
					return;
				}
				next = A.substring(0, 1);
				A = A.substring(1, A.length());
			}else if(next.equals("b")){
				if(B.isEmpty()){
					System.out.println("B");
					return;
				}
				next = B.substring(0, 1);
				B = B.substring(1, B.length());
			}else{
				if(C.isEmpty()){
					System.out.println("C");
					return;
				}
				next = C.substring(0, 1);
				C = C.substring(1, C.length());
			}
		}
    }
}


Measured memory_bytes: 35780
/**
 * @author karayuu
 */
fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map { it.toInt() }

    /* 下手なことせず、総当たりで比較するのが最善 */
    if (a + b == c || a + c == b || b + c == a) {
        print("Yes")
    } else {
        print("No")
    }
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(auto &e : A) cin >> e;
    int ans = 0;
    for(int i = 0; i < N; ++i) {
        int n = i + 1;
        if(n % 2 && A[i] % 2) ans++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,ans{};
    cin>>n;
    Fr(l,n) ans+=l*(n+1-l);
    fr(i,n-1){
        ll u,v;
        cin>>u>>v;
        if(u>v) swap(u,v);
        ans-=u*(n+1-v);
    }
    cout<<ans<<'\n';
}

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

int  main()
{
	int n; cin >> n;
	vector <int> a(n);
	set <int> st;
	map<int, int> mp;
	rep(i, n)
	{
		cin >> a[i];
		mp[a[i]]++;
		mp[a[i]-1]++;
		mp[a[i]+1]++;
	}
	int ans = 0;
	int cnt = 0;
	for(int i = 0; i < n; i++)
	{
		ans = max(ans, mp[a[i]]);
		ans = max(ans, mp[a[i]-1]);
		ans = max(ans, mp[a[i]+1]);
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  int n;cin>>n;
  vector<pair<int,int>> pts;
  int a,b;
  for(int i=0;i<n;++i){
    cin>>a>>b;
    pts.push_back(make_pair(a,b));
  }
  
  map<string,int> mp;
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      if(i!=j){
        a = pts[i].first - pts[j].first;
        b = pts[i].second - pts[j].second;
        string key = to_string(a) + "_" + to_string(b);
        mp[key] ++;
      }
    }
  }
  
  int result = n;
  for(auto i:mp){
    result = min(result,n-i.second);
  }
  
  cout<<result<<endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;

int main()
{
	string S,T;
	cin >> S >> T;
	int T_size = T.size();
	int S_size = S.size();
	int ans = T_size;
	for(int i=0;i<=S_size-T_size;i++)
	{
		int count = 0;
		
		for(int j=0;j<T_size;j++)
		{
			if(S.at(i+j)!=T.at(j))
			{
				count++;
			}
		}
		ans =min(ans,count);
	}
	
	cout << ans <<endl;
}

Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main()
{
  int K, A, B;
  cin >> K >> A >> B;
  long ans = 1;
  if (B - A <= 2)
  {
    ans += K;
  }
  else
  {
    long t = max(0, (K - (A - 1)) / 2);
    ans += (B - A) * t + (K - 2 * t);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=200005;
const int M=4005;
const int mod=1000000007;

int n,mx=2000,ans;
int dp[M][M],a[N],b[N],fac[N],inv[N];

int quickpow(int x,int y){
	int s=1;
	for (;y;y>>=1,x=1ll*x*x%mod)
		if (y&1) s=1ll*s*x%mod;
	return s;
}

void init(int n){
	int i;
	fac[0]=inv[0]=1;
	for (i=1;i<=n;i++) fac[i]=1ll*fac[i-1]*i%mod;
	inv[n]=quickpow(fac[n],mod-2);
	for (i=n-1;i;i--) inv[i]=1ll*inv[i+1]*(i+1)%mod;
}

int C(int x,int y){
	if (x<y) return 0;
	return 1ll*fac[x]*inv[y]%mod*inv[x-y]%mod;
}

int main(){
	int i,j;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d%d",&a[i],&b[i]);
	for (i=1;i<=n;i++) dp[-a[i]+mx][-b[i]+mx]++;
	init(N-5);
	for (i=0;i<=mx+mx;i++)
		for (j=0;j<=mx+mx;j++){
			if (i) (dp[i][j]+=dp[i-1][j])%=mod;
			if (j) (dp[i][j]+=dp[i][j-1])%=mod;
		}
	
	for (i=1;i<=n;i++){
		(ans+=dp[a[i]+mx][b[i]+mx])%=mod;
		(ans-=C(a[i]+a[i]+b[i]+b[i],a[i]+a[i]))%=mod;
	}
	ans=1ll*ans*quickpow(2,mod-2)%mod;
	ans=(ans%mod+mod)%mod;
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 65920
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
bool isvalid(ll x,ll y,ll n, ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
vector<ll>v[100011];

int main() {
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n,k;
    cin>>n;

    ll ap[n+11];
    ll ans = 1000;

    for(ll i=0;i<n;i++){
        cin>>ap[i];
    }

    ll rem = 0;
    ll stock = 0;
    for(ll i=0;i<n;){
        // cout<<i<<" ";
        ll val = ap[i];
        ll indx = i+1;
        for(ll j=i+1;j<n;j++){
            indx = j;
            if(val>=ap[j]){
                val = ap[j];
            }else{
                // indx = j;
                break;
            }
        }
        // cout<<indx<<" ";
        // cout<<val<<" ";
        stock = ans/val;
        rem = ans%val;
        val = ap[indx];
        i = indx;
        for(ll j = indx;j<n;j++){
            // i = j;
            indx  = j;
            if(val<=ap[j]){
                val = ap[j];
                // i = 
            }else{
                // i = j;
                break;
            }
            // indx = j;
        }
        if(indx == n-1){
            i = n;
        }else{
            i = indx;
        }
        // cout<<i<<" ";
        // cout<<val<<" ";
        ans = stock*val;
        ans += rem;
        // cout<<ans<<" ";
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 5988
#include<stdio.h>
#include<stdlib.h>
#include<string.h>


struct node{
  int key;
  struct node *next;
  struct node *prev;
};



typedef struct node *NodePointer;

NodePointer nil;




void init(){

  nil=(NodePointer)malloc(sizeof(struct node));

  nil->next=nil;
  nil->prev=nil;

}


NodePointer Search(int key){

  NodePointer a=nil->next;

  while(a != nil && a->key != key){

    a=a->next;
  }


  return a;
}



void Output(){
  
  NodePointer a=nil->next;
  
  int count=0;
  
  
  
  while(1){
    
    if(a==nil){break;}
    
    if(count==0){printf("%d",a->key);}
    else{printf(" %d",a->key);}
    
    
    count++;
    a=a->next;
    
  }
  
  printf("\n");
  
}





void deleteNodePointer(NodePointer a){
  if(a==nil){return ;}

  a->prev ->next=a->next;
  a->next ->prev=a->prev;

  free(a);

}




void deleteFirst(){

  deleteNodePointer(nil->next);
}





void deleteLast(){
  deleteNodePointer(nil->prev);

}





void deleteKey(int a){
  deleteNodePointer(Search(a));

}





void insertKey(int key){

  NodePointer a=(NodePointer )malloc(sizeof(NodePointer));

  a->key=key;


  a->next=nil->next;

  nil->next->prev=a;

  nil->next=a;
  a->prev=nil;
  
}


int main(){

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

  int i;

  
  char com[20];
  int key;
  
  init();

  
  for ( i = 0; i < number; i++ ){
    scanf("%s%d", com, &key);

    if ( com[0] == 'i' ) {
      insertKey(key);
    }

    
    else  {
      //printf("now deletekey\n")
      if(strlen(com)==6){deleteKey(key);}
      
      
      else {


	
	if ( com[6] == 'F'){
	  //printf("now deleteFirst\n");
	  deleteFirst();
	}


	else if ( com[6] == 'L' ) {
	  deleteLast();
	  //printf("now deleteLast\n");
	}
	
	
      }
    }
  }


  
  Output();
  return 0;
}




Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)

int main(void){
    ll N;
    cin >> N;
    ll A[N];
    ll num[N];
    rep(i,N)num[i]=0;
    rep(i,N){
        cin >> A[i];
        A[i]--;
        num[A[i]]++;
    }
    ll ans = 0;
    rep(i,N){
        if(num[i] < 2)continue;
        ans += (num[i] * (num[i]-1)) / 2;
    }
    rep(i,N){
        if(num[A[i]] < 2)cout << ans << endl;
        else{
            ll sub = (num[A[i]] * (num[A[i]] -1) / 2) - ((num[A[i]]-1) * (num[A[i]] -2) / 2);
            cout << ans - sub << endl;
        }
    }
    return 0;
}

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

int main() {

  int N, P_COUNT,W_COUNT,G_COUNT,Y_COUNT;
  P_COUNT = 0;
  W_COUNT = 0;
  G_COUNT = 0;
  Y_COUNT = 0;
  
  cin >> N;
  
  for (int i = 0; i < N-1; i++) {
    string S;
    cin >> S;
    
    if (S == "P"){P_COUNT =1;}
    else if (S == "W"){W_COUNT =1;}
    else if (S == "G"){G_COUNT =1;}
    else {Y_COUNT =1;}
  
  }
  
  if (P_COUNT+W_COUNT+G_COUNT+Y_COUNT == 3)
  {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s1,s2;
    cin>>s1>>s2;
    bool flag=1;
    for(int i=0; i<s1.size(); i++)
    {
        if(s1[i]!=s2[i])
            flag=0;
    }
    if(flag)
        cout<<"Yes"<<'\n';
    else
        cout<<"No"<<'\n';
    return 0;
}


Measured memory_bytes: 3640
N= map(int, input().split())
p = list(map(int, input().split()))
p_sort = sorted(p)

ans=0
for i in range(0,len(p),1):
    if(p[i]!=p_sort[i]):
        ans = ans+1
if (ans >=3):
    print("NO")
else:
    print("YES")

Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

//AtCoder Grand Contest 043
//A	Range Flip Find Route
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = Integer.parseInt(sc.next());
		int W = Integer.parseInt(sc.next());
		char[][] g = new char[H][];
		for (int i = 0; i < H; i++) {
			g[i] = sc.next().toCharArray();
		}
		sc.close();

		int dp[][] = new int[H][W];
		for (int i = 0; i < H; i++) {
			Arrays.fill(dp[i], Integer.MAX_VALUE);
		}

		if (g[0][0] == '#') {
			dp[0][0] = 1;
		} else {
			dp[0][0] = 0;
		}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i+1 < H) {
					int change = 0;
					if (g[i][j] == '.' && g[i+1][j] == '#' ) {
						change = 1;
					}
					dp[i+1][j] = Math.min(dp[i+1][j], dp[i][j] + change);
				}
				if (j+1 < W) {
					int change = 0;
					if (g[i][j] == '.' && g[i][j+1] == '#') {
						change = 1;
					}
					dp[i][j+1] = Math.min(dp[i][j+1], dp[i][j] + change);
				}
			}
		}
		System.out.println(dp[H-1][W-1]);
	}
}


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

using namespace std;

long long minN(long long prev, long long next) {
    long long n = prev / next;
    if (prev % next != 0) {
        ++n;
    }
    return n;
}

void Main() {
    long long N;
    cin >> N;
    pair<long long, long long> ta;
    for (long long i = 0; i < N; ++i) {
        long long T, A;
        cin >> T >> A;
        if (i == 0) {
            ta = make_pair(T, A);
            continue;
        }

        long long n1 = minN(ta.first, T);
        long long n2 = minN(ta.second, A);
        long long n = max(n1, n2);
        ta.first = n * T;
        ta.second = n * A;
    }

    cout << (ta.first + ta.second) << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3604
#include <stdio.h>

//0 pushBack(x) Aの末尾に整数xを挿入する
//1 randomAccess(p) Aの要素a_pの値を出力する
//2 popBack() Aの末尾の要素を削除する

int main(){
    int q;
    scanf("%d",&q);

    int cmd,p;
    int tail=0;
    long A[q];

    for(int i=0;i<q;i++){
        scanf("%d",&cmd);
        if(cmd==0){
            scanf("%d",&p);
            A[tail]=p;
            tail++;
        }else if(cmd==1){
            scanf("%d",&p);
            printf("%ld\n",A[p]);
        }else if(cmd==2){
            A[tail]=-1;
            tail--;
        }
    }
}


Measured memory_bytes: 3284
#include<iostream>
#define MAX 100005
#define MAX_K 1000000000
using namespace std;

long long a[MAX],c[MAX],d[MAX];

int main() {
	int k;
	cin >> k;
	for (int i = 0; i < k; i++) {
		cin >> a[k-i];
	}
	bool flag = 1;
	c[1] = 2; d[1] = 2;
	if (a[1] != 2) { cout << -1 << endl; return 0; }
	for (int i = 1; i < k; i++) {
		if (c[i] % a[i + 1] == 0) {
			c[i+1] = c[i];
		}
		else {
			c[i+1] = ((c[i] / a[i + 1])+1)*a[i + 1];
		}
		if ((d[i] + a[i]) % a[i + 1] == 0) {
			d[i + 1] = d[i]+a[i] - a[i + 1];
		}
		else {
			d[i + 1] = ((d[i]+a[i]) / a[i + 1])*a[i + 1];
		}
		if (c[i + 1] >= d[i] + a[i]) {
			cout << -1 << endl; return 0;
		}
	}
	cout << c[k] << ' ' << d[k] +a[k] -1<< endl;
}



Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void){
	int K,A,B,i;
	char str[1000];
 
	fgets(str, sizeof(str), stdin);
	K=atoi(strtok(str," "));

	fgets(str, sizeof(str), stdin);
	A=atoi(strtok(str," "));
	B=atoi(strtok(NULL," "));

	for(i=A;i<B;i++){
		if(i%K ==0) break;
	}
	if( (i<B) || (B%K==0) ){
		printf("OK\n");
	}else{
		printf("NG\n");
	}

	return 0;
}

Measured memory_bytes: 2016
//author: Harsh Nema
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
vector<ll>adj[100005];
int main()
{
    fastio;
    ll n=0,m=0;
    cin>>n>>m;
    ll x=0,y=0;
    for(ll i=0;i<n;++i){
        cin>>x>>y;
        adj[x].pb(y);
    }
    ll ans=0;
    priority_queue<ll>pq;
    for(ll i=m-1;i>=0;--i){  //iterating through each day
        for(auto x:adj[m-i]) pq.push(x);
        if(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 9020
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    ABC= LI()
    ans = len(set(ABC))
    if ans == 2:
        print("Yes")
    else:
        print("No")




if __name__ == "__main__":
	main()

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> ok(n + 2, true);
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        ok[a] = false;
    }
    ok[n + 1] = false;
    vector<ll> dp(n + 1,0);
    dp[0] = 1;
    for (int i = 0; i < n; i++)
    {
        for (int j = i+1; j <= min(n,i+2); j++)
        {
            if(ok[j])
            {
                dp[j] += dp[i];
                dp[j] %= mod;
            }
        }
        
    }
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<string>
#include<set>
#include<vector>

using namespace std;

const int maxn = 1005;
typedef long long ll;

int a[2][maxn];
ll dp[2][maxn];

int main(){
    int n;
    scanf("%d",&n);
    for(int i=0;i<=1;i++)
    for(int j=1;j<=n;j++){
        scanf("%d",&a[i][j]);
    }
    for(int i=1;i<=n;i++) dp[0][i]=dp[0][i-1]+a[0][i];
    for(int i=1;i<=n;i++) dp[1][i]=max(dp[0][i],dp[1][i-1])+a[1][i];
    cout<<dp[1][n]<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int[] q = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };
	int[] a;

	int compare(String a, String b) {
		if (a == null) {
			a = "";
		}
		if (b == null) {
			b = "";
		}

		int result = Integer.compare(a.length(), b.length());
		if (result == 0) {
			result = a.compareTo(b);
		}
		return result;
	}

	String max(String s1, String s2) {
		if (compare(s1, s2) > 0) {
			return s1;
		} else {
			return s2;
		}
	}

	Map<Integer, String> memo = new HashMap<>();

	String dfs(int n) {
		if (n == 0) {
			return "";
		}

		String x = memo.get(n);
		if (x != null) {
			return x;
		}

		String ans = null;
		for (int i = 0; i < a.length; i++) {
			int newN = n - q[a[i]];

			if (newN < 0) {
				continue;
			}

			String tmp = dfs(newN);
			if (tmp == null) {
				continue;
			}

			ans = max(ans, a[i] + tmp);
		}

		memo.put(n, ans);

		return ans;

	}

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int M = sc.nextInt();

		a = new int[M];
		for (int i = 0; i < M; i++) {
			a[i] = sc.nextInt();
		}

		out.println(dfs(N));

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 321040
arr = gets.chomp.split.map(&:to_i)

def priceAB(arr, i)
  x = arr[3]-i > 0 ? arr[3]-i : 0
  y = arr[4]-i > 0 ? arr[4]-i : 0
  arr[0] * x + arr[1] * y + arr[2] * i*2
end

AB0 = priceAB(arr, 0)
AB1 = priceAB(arr, 1)

if AB0 < AB1
  puts AB0
else
  s = arr[-2..-1].min
  e = arr[-2..-1].max
  c = AB0

  for i in s..e do
    tmp = priceAB(arr, i)
    c = c < tmp ? c : tmp
  end

  puts c

end



Measured memory_bytes: 1788
N, M = map(int, input().split())
memo = [0]*(N+1)
memo[0] = 1
mod = 10**9+7

for _ in range(M):
    ai = int(input())
    memo[ai] = None

if memo[1] != None:
    memo[1] = 1

for i in range(2, N+1):
    tmp = 0
    if memo[i] == None:
        continue
    if memo[i-1] != None:
        tmp += memo[i-1]
    if memo[i-2] != None:
        tmp += memo[i-2]
    memo[i] = tmp % mod

if memo[N] == None:
    print(0)
else:
    print(memo[N]%mod)


Measured memory_bytes: 6964
#include<iostream>
using namespace std;
int a1,a2,b1,b2;
int main(){
	cin>>a1>>a2>>b1>>b2;
	if(a1+a2>b1+b2)cout<<"Left"<<endl;
	if(a1+a2==b1+b2)cout<<"Balanced"<<endl;
	if(a1+a2<b1+b2)cout<<"Right"<<endl;
	return 0;
}

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

int main() {
  ll n,k;
  cin >> n >> k;
  ll ans = 0;
  for(ll i = k; k < n + 2; k++){
    ll a, b;
    a = (k-1) * k / 2;
    b = (2*n-k+1) * k / 2;
    ans += (b - a + 1) % 1000000007;
  }
  cout << ans % 1000000007;
  return 0;
}

Measured memory_bytes: 3632
import itertools
import numpy as np
n,m = map(int,input().split())
a = [0] * m
b = [0] * m
ans = 0
for i in range(m):
    a[i], b[i] = map(int, input().split())
    
gudge = np.zeros((n, n), dtype = np.int64)
for i in range(m):
    gudge[a[i]-1][b[i]-1] = 1
    gudge[b[i]-1][a[i]-1] = 1

retsu = [i+2 for i in range(n-1)]
p = itertools.permutations(retsu, n-1)

for v in p:
    path = [1]+list(v)
    flag = 1
    for i in range(n-1):
        if gudge[path[i]-1][path[i+1]-1] != 1:
            flag = 0
            break
            
    ans += flag
    
print(ans)

Measured memory_bytes: 12416
from sys import stdin
N = int(input())
A = [int(x) for x in stdin.readline().split(' ')]

cnt = 0
for i in range(N-1):
    for j in range(0, N-1-i):
        if (A[j] > A[j + 1]):
            A[j], A[j + 1] = (A[j + 1], A[j])
            cnt += 1
print(' '.join(map(str, A)))
print(cnt)



Measured memory_bytes: 5604
n, a, b, c, d = gets.split.map(&:to_i)
ss = gets.chomp

ac = ss[a - 1...c]
bd = ss[b - 1...d]

valid = true
if c < d
  valid = false if ac.include?("##") || bd.include?("##")
elsif c > d
  valid = false if !ss[b - 2..d].include?("...")
end

puts valid ? "Yes" : "No"


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

#define mod 998244353

long long dp[300001];

int a[300001];

int N;

long long f(int i) {
    stack<int> st;
    
    for(int i = 0; i < N; i++) {
        if(st.size() > 0) {
            if(st.top() % 2 == a[i] % 2) {
                st.pop();
            }else st.push(a[i]);
        }else st.push(a[i]);
    }
    long long cnt = 0;
    while(!st.empty()) {
        if(st.top() % 2) cnt++;
        st.pop();
    }
    return cnt;

}


int main() {
    // oh hi mark
    int n; cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int look = 1;
    int cnt = 0;
    for(int i = 0;i < n; i++) {
        if(a[i] == look) {
            cnt++;
            look++;
        }
    }
    if(cnt == 0) cout << -1 << endl;
    else cout << n - cnt << endl;
    return 0;
}


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

int main(){
  string str;
  cin >> str;
  for(int i=0; i<str.size(); i++){
    if(i%2==0){
      if(str[i]!='R' && str[i]!='U' && str[i]!='D'){
        cout << "No" <<endl;
        return 0;
      }
    }else{
      if(str[i]!='L' && str[i]!='U' && str[i]!='D'){
        cout << "No" <<endl;
        return 0;
      }      
    }
  }
  cout << "Yes" <<endl;
}

Measured memory_bytes: 256
N = int(input())
ans = 1
cnt = 0
for n in range(1, N+1):
    a = n
    c = 0
    while(True):
        if a % 2 !=0:
            break
        c += 1
        a //= 2
    if c > cnt:
        cnt = c
        ans = n
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int p[110001];
    rep(i, N) cin >> p[i];
    int ans = 0;
    rep(i, N - 1) {
        if(p[i] == i + 1) {swap(p[i], p[i + 1]); ans++;}
    }
    rep(i, N) if(p[i] == i + 1) ans++; 
    cout << ans << endl;

    return 0;
}


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

int main(){
  string classes[1111];
  int mo,af;
  int to[1111],money[1111];
  for(int i=0;i<9;i++){
    cin >> classes[i];
    cin >> mo >> af;
    to[i] = mo + af;
    money[i] = mo*200 + af*300;
  }
  for(int i=0;i<9;i++){
    cout << classes[i] << " " << to[i] << " " << money[i] << endl;;
  }
}

Measured memory_bytes: 1220
#include <stdio.h>
#include <math.h>

int main(){

  int a[10010],i,n,max,min;
  long long sum;
  // a[0] , a[1] , ... , a[10009]
  scanf("%d",&n); 
 
  max = -1000000;
  min = 1000000;
  sum = 0;

  for(i = 1;i < n + 1;i++){
    scanf("%d",&a[i]);
    if(a[i] > max){
      max = a[i];
    }
    if(a[i] < min){
      min = a[i];
    }
    sum = sum + a[i];
  }

  printf("%d %d %lld\n",min,max,sum);

  return 0;
}

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

int main(){
    int x;
    cin >> x;
    for (int i = 1; i <= x; i++) {
        if (i % 3 == 0 || i % 10 == 3 || (i/10)%10 == 3 || (i/100)%10 == 3 || (i/1000)%10 == 3) {
            cout << " " << i;
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3088
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))

res = 0
prev = -1
for i in range(n):
    res += b[a[i]-1]
    if prev+1 == a[i]:
        res += c[prev-1]
    prev = a[i]

print(res)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int M = 100001;
int n, i, j, k, h[M], ans[M];
int main ()
{
    cin >> n >> k;
    for(i = 1; i <= n; i++) cin >> h[i], ans[i] = INT_MAX; ans[1] = 0;
    for(i = 2; i <= n; i++)
    {
        for(j = i-1; j >= max(1, i-k); j--)
        {
            ans[i] = min(ans[i], ans[j]+abs(h[i]-h[j]));
        }
    }
    cout << ans[n] << endl;
}


Measured memory_bytes: 4404
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
vector<vector<pii> >G(100010);
ll d[100010];
void dfs(int i,int p,int w){
    d[i]=d[p]+w;
    rep(j,G[i].size()){
        if(G[i][j].first==p)continue;
        dfs(G[i][j].first,i,G[i][j].second);
    }
}
int main(){
    int n;cin>>n;
    rep(i,n-1){
        int a,b,c;cin>>a>>b>>c;
        G[a].pb(make_pair(b,c));
        G[b].pb(make_pair(a,c));
    }
    int q,k;cin>>q>>k;
    dfs(k,0,0);
    rep(i,q){
        int x,y;cin>>x>>y;
        cout<<d[x]+d[y]<<endl;
    }
}

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

#define int long long int
#define mod 1000000007

int power(int x, unsigned int y, int p)
{
    int res = 1;     // Initialize result

    x = x % p; // Update x if it is more than or
                // equal to p

    if (x == 0) return 0; // In case x is divisible by p;

    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

signed main()
{
   int n;
   cin>>n;
   if(n<2) cout<<0<<endl;
   else if(n==2) cout<<2<<endl;
   else
   {
       int a = power(9,n,mod);
       int b = power(9,n,mod);
       int c = power(8,n,mod);

       int res = (a+b)%mod;
       res = (res-c+mod)%mod;
       res = (power(10,n,mod) - res + mod)%mod;
       cout<<res<<endl;
   }
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int H, W; string A[1010];
mint dp[1010][1010];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> H >> W;
    rep(y, 0, H) cin >> A[y];

    dp[0][0] = 1;
    rep(y, 0, H) rep(x, 0, W) {
        if (y + 1 < H and A[y + 1][x] != '#') dp[y + 1][x] += dp[y][x];
        if (x + 1 < W and A[y][x + 1] != '#') dp[y][x + 1] += dp[y][x];
    }
    cout << dp[H - 1][W - 1] << endl;
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<unordered_set>
#include<map>
#include<deque> 
#include<cstring>
#include<utility>
#include<queue>
#include<string>
#include<iomanip>
#include<unordered_map>
#include<list>
using namespace std;
#define int unsigned long long
#define pb push_back
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define LM LONG_MAX
#define LS LONG_MIN
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
void print(vector<pair<int,int> >&v){fr(i,v.size())cout<<v[i].F<<" "<<v[i].S<<endl;cout<<endl;}
void print(int arr[],int n){for(int i=0;i<n;i++)cout<<arr[i]<<" ";cout<<endl;}
bool sortbysec(const pair<pair<int,int>,int> &a,const pair<pair<int,int>,int> &b){return (a.first.second < b.first.second);}
int32_t main()
{
	int cnt=0;
	int n;
	cin>>n;
	int arr[n];
	fr(i,n)cin>>arr[i];
	sort(arr,arr+n);
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			cnt+=(lower_bound(arr,arr+n,arr[i]+arr[j])-arr-j-1);
		}
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String target = "E869120";
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (target.equals(sc.next())) {
                count++;
            }
        }
        System.out.println(count);
    }
}



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

long long gcd2(long long x,long long y) {
    if(y == 0) return x;
    return gcd2(y,x % y);
}

long long lcm2(long long x,long long y) {
    return x / gcd2(x,y) * y;
}

long long lcm(vector<long long> a) {
    long long ans = a[0];
    for(long long i = 1; i < a.size(); i++) {
      ans = lcm2(ans,a[i]);
    }
    return ans;
}

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        cin >> a[i];
    }
    cout << lcm(a) << endl;
    return 0;
}

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

struct Y{
  string n; int b,e;
  Y(void){}
  Y(string a,int x,int y):n(a),b(x),e(y){}
  bool operator<(const Y a)const{return b<a.b;}
};

int main(){
  int n,q,i;
  int a,b,y,l,r,m;
  string name;
  Y e[1010];

  std::ios::sync_with_stdio(false);
  while(cin >> n >> q, n+q){
    for(i=0;i<n;i++){
      cin >> name >> a >> b;
      e[i] = Y(name,b-a+1,b);
    }
    sort(e,e+n);
    for(i=0;i<q;i++){
      cin >> y;
      l=-1,r=n;
      while(r-l>1){
	m = (l+r)/2;
	if(e[m].e>=y)r = m;
	else l = m;
      }

      if(r==n || e[r].b>y)cout << "Unknown\n";
      else cout << e[r].n << " " << y-e[r].b+1 << endl;
    }
  }
}

Measured memory_bytes: 1284
#include<stdio.h>

int main (void){

    int H,W,h,w,white;

    scanf("%d",&H);
    scanf("%d",&W);
    scanf("%d",&h);
    scanf("%d",&w);

    white = (H*W) - (h*W+w*H) + (h*w);

    printf("%d",white);

    return 0;
}


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

int main()
{
  int N, A, B;
  cin >> N;

  if(N==1) cout << "Hello World" << endl;
  else {
    cin >> A >> B;
    cout << A+B << endl;
  }
}

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

using namespace std;

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

void Main()
{
	int i = 1;
	while(true){
		int x;
		cin >> x;
		if(x == 0){
			break;
		}
		cout << "Case " << i << ": " << x << endl;
		i++;
	}
}

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



Measured memory_bytes: 3020