akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;

namespace abc125
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var vs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var cs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();

            var output = 0;
            for (var i = 0; i < vs.Length; i++)
            {
                var d = vs[i] - cs[i];
                if (d > 0)
                {
                    output += d;
                }
            }
            Console.WriteLine(output);
        }
    }
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n; cin >> n;
	vl a(n);
	FOR(i,0,n) cin >> a[i];
	sort(all(a));
	vl s(n+1);
	FOR(i,0,n) s[i+1] = s[i] + a[i];

	ll k = 0, res = -oo;
	FOR(i,1,n) {
		ll cur = s[n] - 2*s[i];
		if (cur > res) res = cur, k = i;
	}
	
	cout << res << endl;

	FOR(i,k+1,n) {
		cout << a[0] << " " << a[i] << endl;
		a[0] -= a[i];
	}
	
	FOR(i,0,k) {
		cout << a[k] << " " << a[i] << endl;
		a[k] -= a[i];
	}

	

}



Measured memory_bytes: 3456
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#define INF 1LL<<60
#define MAX_N 100005
#define MAX_M 300005
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
struct edge{
	int t;
	ll dist;
	edge(){}
	edge(int tt,ll dd){
		t=tt;
		dist=dd;
	}
};

int n,m;
ll x,h[MAX_N];
vector<edge> G[MAX_N];
ll dp[MAX_N];

ll dijk(){
	for(int i=0;i<MAX_N;i++){
		dp[i]=INF;
	}
	priority_queue<P,vector<P>,greater<P> > que;
	que.push(P(0,0));
	dp[0]=0;
	while(que.size()){
		P p=que.top();
		que.pop();
		ll cost=p.first;
		int v=p.second;
		if(cost>dp[v])continue;
		if(v==n-1){
			if(cost>x)return cost+h[n-1];
			else return cost+h[n-1]-(x-cost);
		}
		for(int i=0;i<G[v].size();i++){
			edge e=G[v][i];
			ll ncost=cost+e.dist;
			ll ph=max(x-cost,0LL);
			if(ph-e.dist<0LL)ncost+=e.dist-ph;
			if(ph-e.dist>h[e.t])ncost+=ph-e.dist-h[e.t];
			if(ncost<dp[e.t]){
				dp[e.t]=ncost;
				que.push(P(ncost,e.t));
			}
		}
	}
	return -1;
}

int main(void){
	scanf("%d%d%lld",&n,&m,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&h[i]);
	}
	for(int i=0;i<m;i++){
		int a,b;
		ll d;
		scanf("%d%d%lld",&a,&b,&d);
		a--;
		b--;
		if(h[a]>=d)G[a].push_back(edge(b,d));
		if(h[b]>=d)G[b].push_back(edge(a,d));
	}
	printf("%lld\n",dijk());
	return 0;
}

Measured memory_bytes: 21224
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    ll n, x, m;
    cin >> n >> x >> m;
    vector<int> id(m,-1);
    vector<int> a;
    int len = 0;
    ll tot = 0;
    while (id[x] == -1) {
        a.push_back(x);
        id[x] = len;
        len++;
        tot += x;
        x = (x*x)%m;
    }

    int c = len-id[x];
    ll s = 0;
    for (int i = id[x]; i < len; i++) s += a[i];

    ll ans = 0;
    if (n <= len) {
        rep(i,n) ans += a[i];
    }
    else {
        ans += tot;
        n -= len;
        ans += s*(n/c);
        n %= c;
        rep(i,n) ans += a[id[x]+i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3996
WHITE = 0
GRAY = 1
BLACK = 2

n = int(input())

M = [[0] * n for i in range(n)]

d = [0] * (n)
f = [0] * (n)
color = [WHITE] * (n)


time = 0

def dfs_visit(u):
    global time
    time += 1
    color[u] = GRAY
    d[u] = time
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            dfs_visit(v)
    color[u] = BLACK
    time += 1
    f[u] = time

def dfs():
    for u in range(n):
        if color[u] == WHITE:
            dfs_visit(u)

    for u in range(n):
        print("{} {} {}".format(u+1, d[u], f[u]))


if __name__ == "__main__":
    for i in range(n):
        arr = list(map(int, input().split()))
        for v in (arr[2:]):
            M[arr[0]-1][v-1] = 1

    dfs()



Measured memory_bytes: 5748
#include <iostream>
#include <string>
#include <vector>

int N, K;
std::vector<int> d;
std::vector<std::vector<int>> A;

void input(){
  int i,j;
    
  std::cin >> N >> K;
  d.resize(K);
  A.resize(K);
  
  for(i=0; i<K; i++){
    std::cin >> d[i];
    A[i].resize(d[i]);
    
    for(j=0; j<d[i]; j++){
      std::cin >> A[i][j];
    }
  }
}

void solve(){
  int ans=0;
  bool have;
  
  for(int i=1; i<=N; i++){
    have=false;
    for(auto v:A){
      for(auto p:v){
        if(p==i) have=true;
      }
    }
    if(!have) ans++;
  }
  std::cout << ans << std::endl;
}

int main(){
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3656
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
#define rep(i,a,b) for (int i=(a);i<=(b);i++)
#define Rep(i,a,b) for (int i=(a);i<(b);i++)
using namespace std;
char s[30];
int c[30];
char ans;
bool check(){
	Rep(i,0,26)if (c[i]==0){
		ans=i+'a';
		return true;
		}
	return false;
}
int main(){
	cin >> s;
	int l=strlen(s);
	Rep(i,0,l)c[s[i]-'a']++;
	if (check()){
		printf("%s",s);
		putchar(ans);
		puts("");
		return 0;
	}
	else{
		int lst=l-1;
		while (true){
			c[s[lst]-'a']--;
			s[lst]++;while(s[lst]>'z'){lst--;if (lst<0){
				puts("-1");
				return 0;
			}
		c[s[lst]-'a']--;
		s[lst]++;
		}
			c[s[lst]-'a']++;
			if (c[s[lst]-'a']==1){
				rep(i,0,lst)putchar(s[i]);
				puts("");
				return 0;
			}
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
long long mod = 1000000007;
long long power(long long m,long long n){
    long long res = 1;
    if(n > 0){
        res = power(m,n / 2);
        if(n % 2 == 0){
            res = (res * res) % mod;
        }
        else{
            res = (((res * res) % mod) * m) % mod;
        }
    }
    return res;
}
int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> fac(n + 1);
  fac[0] = 1;
  for(int i = 1;i <= fac.size() - 1;i++){
    fac[i] = (fac[i - 1] * i) % mod;
  }
  vector<ll> kazu(n);
  for(int i = 0;i <= n - 1;i++){
    cin >> kazu[i];
  }
  sort(kazu.begin(),kazu.end());
  ll dai = 0;
  ll syou = 0;
  for(int i = k - 1;i <= n - 1;i++){
    ll kasann = 0;
    kasann = 1;
    kasann *= fac[i] * power(fac[k - 1],mod - 2),kasann %= mod;
    kasann *= power(fac[i - k + 1],mod - 2),kasann %= mod;
    kasann *= kazu[i],kasann % mod;
    dai += kasann,dai %= mod;
    //dai = (dai + (((fac[i] * power(fac[k - 1],mod - 2)) % mod * power(fac[i - k + 1],mod - 2)) % mod * kazu[i]) % mod) % mod; 
    //cout << "dai" << dai << endl;
  }
  for(int i = 0;i <= n - k;i++){
    ll kasann = 0;
    kasann = 1;
    kasann *= fac[n - i - 1] * power(fac[k - 1],mod - 2),kasann %= mod;
    kasann *= power(fac[n - i - k],mod - 2),kasann %= mod;
    kasann *= kazu[i],kasann %= mod;
    syou += kasann,syou %= mod;
    //syou = (syou + (((fac[n - i - 1] * power(fac[k - 1],mod - 2)) % mod * power(fac[n - i - k],mod - 2)) % mod * kazu[i]) % mod) % mod;
  }
  ll kotae = 0;
  kotae = (dai - syou) % mod;
  if(kotae < 0){
    //cout << 0 << endl;
    kotae += mod;
  }
  //cout << kotae << " " << dai << " " << syou << endl;
  cout << kotae << endl;
  return 0;
}

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

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i=0; i<N-2; i++){
    if(S.at(i)=='A' && S.at(i+1)=='B' && S.at(i+2)=='C') ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
list = []
time = 0

n.times do |i|
	name, quantum = gets.chomp.split
	list << [name, quantum.to_i]
end

loop do
	head = list.shift
	exit if head == nil
	
	time += head[1] < q ? head[1] : q
	remain = head[1] - q
	
	if remain > 0
		list.push([head[0], remain])
	else
		puts "#{head[0]} #{time}"
	end
end



Measured memory_bytes: 11708
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  vector<ll> a(n), b(m);
  rep(i, n) cin >> a[i];
  rep(i, m) cin >> b[i];
  vector<ll> sa(n+1), sb(m+1);
  rep(i, n) sa[i+1] = a[i]+sa[i];
  rep(i, m) sb[i+1] = b[i]+sb[i];
  ll ans = 0;
  rep(i, n+1) {
    if (k-sa[i] < 0)
      break;
    auto it = upper_bound(sb.begin(), sb.end(), k-sa[i]);
    chmax(ans, i+it-sb.begin()-1LL);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9532
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial



def main():
    a, b, x = map(int, input().split())
    aaa = (a - 1) // x
    bbb = b // x
    print(bbb - aaa)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
from collections import Counter
n = int(input())
ss = [input() for _ in range(n)]
m = int(input())
ts = [input() for _ in range(m)]

c0 = Counter(ss) - Counter(ts)
if c0:
    word, count = c0.most_common(1)[0]
    print(count)
else:
    print(0)

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

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

    vector<vector<int>> black(50, vector<int>(100, 0)); // 100 x 50 の黒マス
    vector<vector<int>> white(50, vector<int>(100, 1)); // 100 x 50 の白マス

    A--;
    B--;

    int x = 1;
    int y = 1;
    rep(i, A) {
        black[y][x] = 1;
        x += 2;
        if (x > 98) {
            x = 1;
            y += 2;
        }
    }

    x = 1;
    y = 1;
    rep(i, B) {
        white[y][x] = 0;
        x += 2;
        if (x > 98) {
            x = 1;
            y += 2;
        }
    }

    cout << 100 << " " << 100 << endl;
    rep(i, 2) {
        vector<vector<int>> board = black;
        if (i == 1) board = white;

        rep(h, 50) {
            rep(w, 100) {
                if (board[h][w] == 0) cout << "#";
                else cout << ".";
            }
            cout << endl;
        }
    }
}


Measured memory_bytes: 256
//*****Jai Mata di*****//

#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
const int mod=1e9+7;
const int N=2e5+15;
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

vector<int>adj[N];
int d[4][2]={{-1,0},{1,0},{0,-1},{0,1}};
int h[N];

ll power(ll a,ll b,ll md)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return power((a*a)%md,b/2,md);
    else
        return (a*power(a,b-1,md))%md;
}


void solve(){
 
    int dp[300001] = {0,};
    for(int i=1; i<=300000; i++)
        dp[i] = dp[i%__builtin_popcountll(i)] + 1;
 
    int n;
    cin >> n;
    string s;
    cin >> s;
 
    int rem1 = 0;
    int rem2 = 0;
    int bits = 0;
 
    int ten1[n];
    int ten2[n];
    for(int i=0; i<s.size(); i++)
        if(s[i] == '1')
            bits++;
        
    int div1 = bits+1;
    int div2 = bits-1;
 
    for(int i=n-1, r=1; i>=0; i--)
    {
        ten1[i] = r;
        rem1 = (rem1+r*(s[i]=='1'))%div1;
        r = (r*2)%div1;
    }
 
    if(div2>0)
    {
        for(int i=n-1, r=1; i>=0; i--)
        {
            ten2[i] = r;
            rem2 = (rem2+r*(s[i]=='1'))%div2;
            r = (r*2)%div2;
        }
    }
    for(int i=0; i<n; i++)
    {
        if(s[i]=='1')
        {
            if(div2==0)
                cout << 0 << endl;
            else
            {
            ll t = (rem2 - ten2[i]+div2)%div2;
            cout << dp[t]+1 << endl;
            }
        }
        else
        {
            ll t = (rem1 + ten1[i]+div1)%div1;
            cout << dp[t]+1 << endl;
        }
    }
}

int main()
{
    Nitroboost;
    solve();
}

Measured memory_bytes: 11184
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string strOdd,strEven;
	cin >> strOdd >> strEven;
	int sizeOdd = strOdd.size();
	int sizeEven = strEven.size();
	int N = max(sizeOdd,sizeEven);
	for(int i=0;i<N;++i){
		if( i < sizeOdd ){
			cout << strOdd[i];
		}
		if( i < sizeEven ){
			cout << strEven[i];
		}
	}
	cout << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


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

using namespace std;
int main(void){
  int N, min, max;
  int a[100];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  //ソートしてmaxとminをとる。
  sort(a, a + N);
  min = a[0], max = a[N - 1];
  cout << max - min << endl;
  return 0;
}


Measured memory_bytes: 256
def C():
    n, m, x = map(int, input().split())
    books = [tuple(map(int, input().split())) for i in range(n)]
    books = list(zip(*books))
    res = []
    for i in range(2**n):
        flag = True
        pattern = list(map(int, bin(i)[2:].zfill(n)))
        for j in range(m):
            skill = sum(map(lambda x,y: x*y, pattern, books[j+1]))
            if skill < x:
                flag = False
                break
        if flag:
            cost = sum(map(lambda x,y: x*y, pattern, books[0]))
            res.append(cost)
    if res != []:
        print(min(res))
    else:
        print(-1)
C()

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    char c; cin >> c;
    switch (c){
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
        cout << "vowel" << endl;
        break;
    default:
        cout << "consonant" << endl;
        break;
    }
    return 0;
}


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

int main(){
        int n;
        ll t[1010],a[1010];
        ll tsum,asum;
        cin >> n;
        rep(i,n) cin >> t[i] >> a[i];
        tsum = t[0]; asum = a[0];
        for(int i = 1; i < n; i++) {
                ll coefficient = (ll)max(ceil((long double)tsum/t[i]),ceil((long double)asum/a[i]));
                tsum = t[i] * coefficient;
                asum = a[i] * coefficient;
        }
        cout << tsum + asum << endl;
        return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define repn(i,n) for(ll i=0;i<=(ll)(n);i++)
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
//cin.tie(0);
//ios::sync_with_stdio(false);

ll dp[40][401][401];// 0==-400 400==0  800 = 400

void init(){
  for(int i=0;i < 40;i++)
  {
    for(int k=0;k < 401;k++)
    {
      for(int j=0;j < 401;j++)
      {
        dp[i][k][j]=INF;
      }
    }
  }
}

signed main(){
  ll n,ma,mb;cin>>n>>ma>>mb;
  init();
  
  for(int i=0;i < n;i++)
  {
    ll a,b,c;
    cin>>a>>b>>c;

    dp[i][a][b]=min(c,dp[i][a][b]);

    if(i){
      for(int j=1;j < 401;j++)
      {
        for(int k=1;k < 401;k++)
        {
          dp[i][j][k]=min(dp[i][j][k],dp[i-1][j][k]); 
          if(0<j-a && 0<k-b) dp[i][j][k]=min(dp[i][j][k],dp[i-1][j-a][k-b]+c);
        }
      }
    }

  }
  ll ans=INF;

  for(int i=0;i < 401;i++)
  {
    if(i*ma<=400 && i*mb<=400)ans=min(ans,dp[n-1][i*ma][i*mb]);
  }

  if(INF <= ans)cout<<-1<<endl;
  else cout<<ans<<endl;

}


Measured memory_bytes: 50432
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  map<ll,ll>cnt;
  for(int i=0;i<n;i++){
    ll a;cin>>a;
    cnt[-a]++;
  }
  ll ans = 0;
  ll kake = -1;
  for(auto a:cnt){
    if(a.S >= 4){
      if(kake > 0){
	cout<<-a.F*kake<<endl;
      }else{
	cout<<(-a.F)*(-a.F)<<endl;
      }
      return 0;
    }else if(a.S >= 2){
      if(kake > 0){
	cout<<kake*(-a.F)<<endl;
	return 0;
      }else{
	kake = -a.F;
      }
    }
  }
  cout<<0<<endl;
  return 0;
}



Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,int>psi;

int a[1000];
int main()
{
    string s;   cin>>s;

    for(int i=0;i<3;i++)
    {
        if(s[i]-'0'==s[i+1]-'0')
            return cout<<"Bad",0;
    }
    cout<<"Good";
}


Measured memory_bytes: 256
from collections import deque
S = deque(input())
Q = int(input())
count = 0
for i in range(Q):
    l = list(input().split())
    if len(l) == 1:
        count +=1
    else:
        l[1] = int(l[1])
        if count%2 == 1:
            if l[1] == 1:
                l[1] = 2
            else:
                l[1] = 1
        if l[1] == 1:
            S.appendleft(l[2])
        else:
            S.append(l[2])

if count%2 == 0:
    print(''.join(list(S)))
else:
    S.reverse()
    print(''.join(list(S)))



Measured memory_bytes: 8564
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define print(x) cout << (x) << '\n'

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

const int INF = 1e9;
int h, w;
char board[1010][1010];
int dis[1010][1010];

int bfs(){
  queue<pii> q;

  rep(i, h){
    rep(j, w){
      if (board[i][j] == '#'){
        q.push(pii(i, j)); dis[i][j] = 0;
      }
    }
  }

  while (!q.empty()){
    pii p = q.front(); q.pop();
    for (int i = 0; i < 4; ++i){
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx >= 0 && nx < h && ny >= 0 && ny < w && dis[nx][ny] == INF){
        dis[nx][ny] = dis[p.first][p.second] + 1; q.push(pii(nx, ny));
      }
    }
  }

  int mx = -1;
  for (int i = 0; i < h; ++i){
    for (int j = 0; j < w; ++j){
      mx = max(mx, dis[i][j]);
    }
  }

  return mx;
}

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

  cin >> h >> w;
  rep(i, h){
    rep(j, w) cin >> board[i][j];
  }

  fill(dis[0], dis[1010], INF);

  print(bfs());

  return 0;
}

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

char conv(char a)
{
  if(a=='0') return '1';
  return '0';
}

int mis(string S, char a)
{
  char cur=a;
  string::iterator itr;
  int cnt=0;
  for(itr=S.begin(); itr!=S.end(); itr++)
  {
    if(cur!=*itr) cnt++;
    cur = conv(cur);
  }
  return cnt;
}

int main()
{
  string S;
  cin >> S;
  int tmp;
  tmp = min(mis(S,'0'),mis(S,'1'));
  cout << tmp << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
 
                int a = sc.nextInt();
                int b = sc.nextInt();

		List<String> list = new ArrayList<String>();



		for(int i = 0; i < a; i++){
			list.add(sc.next());
		}

                Collections.sort(list); 
 
		for(int i = 0; i < list.size() ; i++){
                  System.out.print(list.get(i));
		}
     }
}              

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

int main()
{
	int N;
	cin >> N;
	vector<int> T(N + 1);
	int T_sum = 0;
	for (int i = 1; i <= N; i++)
	{
		cin >> T[i];
		T_sum += T[i];
	}
	int M;
	cin >> M;
	vector<int> P(M + 1);
	vector<int> X(M + 1);
	for (int i = 1; i <= M; i++)
	{
		cin >> P[i];
		cin >> X[i];
	}
	for (int i = 1; i <= M; i++)
	{
		int ans = T_sum - T[P[i]] + X[i];
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
    int x;
    cin >> x;
    if (x==0) {
        cout << 1;
    }
    else if (x==1) {
        cout << 0;
    }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<iostream>
#include<string>
#include<map>

using namespace std;

int n;

int a[3][101];

int main(void){

cin >> n;


for(int k = 1; k <= 2; k++){
  for (int i = 1; i <= n ; i++){
    cin >> a[k][i];
  }
}

int maxm = 0;
for(int i = 1; i <= n; i++){
  maxm += a[1][i];
}
maxm += a[2][n];
int nowm = maxm;
for (int i = n; i >= 2; i--){
  nowm -= a[1][i];
  nowm += a[2][i-1];
  maxm = max(maxm, nowm);
}

cout << maxm << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include<algorithm> 
#include <iomanip>
#include <math.h>
#include <cctype>
//小文字を大文字 c-0x20;


#define db double
#define vi vector<int>
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define maxn 5005
#define mod 998244353
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpi vector<pii>
#define vpll vector<pll>
#define vv(z,a,b) vector<vector<int>>z(a,vector<int>(b))
#define vvll(z,a,b) vector<vector<ll>>z(a,vector<ll>(b))
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) begin(c),end(c)
#define fix(k) fixed<<setprecision(k)
#define PI 3.141592653589793
using namespace std;


bool hantei(int i){
    int youso=0;
    for(int j=1;j<=i;j++){
        if(i%j==0)youso++;
    }
    if(youso==8)return true;
    else return false;
}

int main(){
    int n;cin>>n;int flag=0;
    for(int i=1;i<=n;i++){
        if(i%2==0)continue;
        if(hantei(i))flag++;
    }
    cout<<flag<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
ll mod=1e9+7;
int main(){
	int n;
	ll ans=1;
	cin >>n;
	string s[2];
	cin>>s[0]>>s[1];
	char last[2]={'0','0'};
	int flag=0;
	for(int i=0;i<n;i++){
		flag=0;
		if(s[0][i]==s[1][i]){
			flag+=1;
		}
		if(last[0]==last[1] and last[1]!='0'){
			flag+=2;
		}
	//	clog<<flag<<endl;
		switch(flag){
			case 0:
			ans*=3;
			if(i==0){
				ans=6LL;
			}
			break;
			case 1:
			if(i==0){
				ans=3LL;
			}
				break;
			case 2:
				ans *= 2;
				break;
			case 3:
				ans *= 2;
				break;
		}

		ans%=mod;
		last[0]=s[0][i];
		last[1]=s[1][i];
		if(flag==0 or flag==2){
			i++;
		}
	}
	cout<<ans<<endl;
}

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

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

  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  set<int> w;
  set<int> s;
  for (int i = 0; i <= f + 1; i += 100 * a) {
    for (int j = 0; j < f - i + 1; j += 100 * b) {
      if (i == 0 && j == 0) continue;
      w.insert(i + j);
    }
  }
  for (int i = 0; i < f + 1; i += c) {
    for (int j = 0; j < f - i + 1; j += d) {
      s.insert(i + j);
    }
  }
  int u = 0, v = 0;
  for (auto &y : w) {
    for (auto &x : s) {
      if (y + x > f) break;
      if ((100 + e) * x > (y + x) * e) break;
      if (x * u >= v * (y + x)) {
        u = y + x;
        v = x;
      }
    }
  }
  cout << u << " " << v << '\n';
  return 0;
}

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

int main() {
  int n;
  cin>>n;
  int d[n];
  for (int i=0; i<n; i++) cin>>d[i];
  int m;
  cin>>m;
  int t[m];
  for (int i=0; i<m; i++) cin>>t[i];
  int i_t = 0;
  int i_d = 0;
  sort(d, d + n);
  sort(t, t + m);
  while (i_d < n && i_t < m) {
    if (d[i_d] == t[i_t]) {
      ++i_d;
      ++i_t;
    } else if (d[i_d] > t[i_t]) {
      cout<<"NO"<<endl;
      return 0;
    } else {
      ++i_d;
    }
  }
  if (i_t == m) {
    cout<<"YES"<<endl;
  } else {
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 300005

using namespace std;
typedef long long int ll;

struct BIT
{
	int bit[SIZE];
	
	void init()
	{
		memset(bit,0,sizeof(bit));
	}
	void add(int k,int x)
	{
		k++;
		while(k<SIZE)
		{
			bit[k]+=x;
			k+=k&-k;
		}
	}
	int get(int k)
	{
		k++;
		int ret=0;
		while(k>0)
		{
			ret+=bit[k];
			k-=k&-k;
		}
		return ret;
	}
};
BIT bit;
vector <int> dv[SIZE];
vector <int> back[SIZE];
int ans[SIZE];
int cnt[SIZE];

int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<n;i++)
	{
		int l,r;
		scanf("%d %d",&l,&r);
		cnt[r]++;
		back[l-1].push_back(r);
	}
	bit.init();
	for(int i=1;i<=m;i++)
	{
		for(int j=i;j<=m;j+=i) dv[j].push_back(i);
	}
	for(int i=m;i>=1;i--)
	{
		bit.add(i,cnt[i]);
		for(int j=0;j<back[i].size();j++) bit.add(back[i][j],-1);
		for(int j=0;j<dv[i].size();j++)
		{
			int v=dv[i][j];
			ans[v]+=bit.get(i+v-1);
		}
	}
	for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 27648
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
//typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){int i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll N;
vector<vector<ll>> edge;
vector<ll> A;
bool jd=true;

ll dfs(ll u,ll p){
  vector<ll> num;
  ll sum=0;
  for(auto &v:edge[u]){
    if(v!=p){
      ll ret=dfs(v,u);
      //cout<<v+1<<" "<<ret<<endl;
      num.push_back(ret);
      sum+=ret;
    }
    if(!jd){return 0;}
  }
  if(num.empty()){return A[u];}
  if(p==-1 && (int)edge[u].size()==1){jd&=(sum==A[u]); return 0;}
  sort(num.begin(),num.end(),greater<ll>());
  if(sum<A[u] || sum>A[u]*2){jd=false; return 0;}
  ll rem=sum-A[u];
  if(sum-num[0]<rem){jd=false; return 0;}
  return sum-rem*2;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  edge.resize(N);
  A.resize(N);
  cin>>A;
  for(int i=1;i<N;i++){
    ll a,b;
    cin>>a>>b;
    a--; b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  jd&=(dfs(0,-1)==0);
  cout<<(jd?"YES":"NO")<<endl;


  return 0;
}


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

using namespace std;
using ll = long long;


int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  ll n;
  cin >> n;
  vector<ll>a (n);
  ll nax = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    nax = max (nax, a[i]);
  }
  sort (begin (a), end (a) );
  ll ans = 0;
  for (ll i = 1; i <= nax; i++) {
    ll idx = lower_bound (begin (a), end (a), i) - begin (a);
    if (idx - 1 == n - 1 - idx) {
      ans++;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder {
    class _042b {
        static void Main() {
            string[] nl = Console.ReadLine().Split(' ');
            int n = int.Parse(nl[0]);
            int l = int.Parse(nl[1]);
            var list = new List<string>();
            for(int i = 0; i<n; i++) {
                list.Add(Console.ReadLine());
            }
            list.Sort();
            foreach(string s in list) {
                Console.Write(s);
            }
            Console.WriteLine("");
        }
    }
}

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

int f[10][10], x[23], y[23], dat[10][10], dx[]{ 1,-1,0,0 }, dy[]{ 0,0,1,-1 };

int main() {
	int m, n;
	while (scanf("%d%d", &m, &n), m) {
		int p = 0, sx, sy;
		rep(i, n)rep(j, m) {
			scanf("%d", &f[i][j]);
			if (f[i][j] == 1)x[p] = i, y[p] = j, dat[i][j] = p++;
			if (f[i][j] == 2)sx = i, sy = j;
		}
		map<P, int>dp;
		rep(k, 4) {
			for (int nx = sx, ny = sy; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
				if (f[nx][ny] == 1) {
					dp[{1 << dat[nx][ny], dat[nx][ny]}] = 1;
					break;
				}
			}
		}
		int ans = 0, o = 0;
		rep(i, 1 << p)rep(j, p) {
			if (dp.find({ i,j }) == dp.end())continue;
			if (i == (1 << p) - 1) {
				if (x[j] == sx || y[j] == sy)ans += dp[{i, j}];
				continue;
			}
			rep(k, 4) {
				for (int nx = x[j], ny = y[j]; 0 <= nx&&nx < n && 0 <= ny&&ny < m; nx += dx[k], ny += dy[k]) {
					if (f[nx][ny] == 1 && !(i >> dat[nx][ny] & 1)) {
						dp[{i | 1 << dat[nx][ny], dat[nx][ny]}] += dp[{i, j}];
						break;
					}
				}
			}
			if (++o >= 10000)dp.erase({ i,j });
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 9128
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
#define INF 1e9
#define DEBUG(x) cout<<"debug: "<<x<<endl

int n, m;
int main() {
    cin >> n >> m;
    vector<int> graph[n];
    rep(i, 0, m){
        int a, b; cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queue<int> q;
    vector<int> ans(n, -1);
    q.push(0);
    while (q.size()) {
        int i = q.front(); q.pop();
        for(auto x : graph[i]){
            if(ans[x] != -1) continue;
            ans[x] = i;
            q.push(x);
        }
    }

    cout << "Yes" << endl;
    rep(i, 1, n){
        cout << ans[i]+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 9740
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

ll gcd(ll a, ll b) {
    if (b == 0){
        return a;
    } else {
        return gcd(b, a%b);
    }
}

int main(void) {
    int n, x;
    cin >> n >> x;
    vector<int> a(n);

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        // offset
        a[i] -= x;
    }

    ll res = abs(a[0]);
    for(int i = 0; i < n; ++i) {
        res = gcd(res, abs(a[i]));
    }

    cout << res << endl;

    // int d = 1;
    // int dstop = abs(a[0] - a[1]);
    // int out = 0;

    // n^2 間に合わない
    // for(int d = 1; d < dstop; ++d) {
    //     bool ok = true;

    //     for(int i = 0; i < n; ++i) {
    //         if((a[i] - x)%d != 0){
    //             // cout << a[i] << "%" << d << "=" << a[i]%d << endl;
    //             ok = false;
    //             break;
    //         } else {
    //             // cout << a[i] << "%" << d << "= 0" << endl;
    //         }
    //     }

    //     if (ok) {
    //         out = d;
    //     }
    // }

    // int out;
    // cout << out << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
const ll mod9 = 998244353;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod9 + mod9) % mod9;
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = modu(a); b; a = modu(a * a) , b >>= 1){
        if (b & 1) res = modu(res * a);
    }
    return res;
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N,S;
    cin >> N >> S;
    vector<ll> cou(10000);
    vector<ll> A(N);
    vector<ll> answers(10000);
    REP(i,N)cin >> A[i];
    REP(i,N){
        RREP(l,S+2+A[i]){
            if(l-A[i] >= 0){
                answers[l] += modu(answers[l] + answers[l-A[i]]);
            }else{
                answers[l] += answers[l];
            }
            answers[l] = modu(answers[l]);
        }
        answers[A[i]]+=modpow(2,i);
        answers[A[i]] = modu(answers[A[i]]);
    }
    cout << modu(answers[S]) << "\n";
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define coc g[node][i]
#define mod 1000000007
#define inf 1000000009
#define N 1000005
using namespace std;

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

int n,w[N],mn;//max diye degisken ismi alamazsin
// max adli fonksiyon oldugu icin
// genel olarak olimpiyatcilar mx ismini kullanir.

int aralikbul(int t)
{
  int a1 = 0,a2 = 0; // a1 büyük olanlar
  for (int i = 0; i < n; i++) {
    if (i > t)
    {
      a1 += w[i];
    }
    else
     a2 += w[i];
  }
  // cout << t << " " << a1 << " " << a3
  return abs(a1 - a2);
}

int main() {
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    cin >> n;

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

    mn = aralikbul(0);
    // cout << w[0] << " " << mn << " " << endl;
    for (int i = 1; i < n; i++) {
      // cout << w[i] << " " << mn << " " << aralikbul(w[i]) << endl;
      mn = min(aralikbul(i), mn);
    }

    cout << mn;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;
#define x first
#define y second
#define mp make_pair

int a, b;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
cout << max(0, a - 2 * b) << endl;

return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)


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


N, Q = map(int, input().split())
ab = [[] for _ in range(N)]
for i in range(N-1):
  a, b = map(int, input().split())
  ab[a-1].append(b)
  ab[b-1].append(a)

P = [0 for _ in range(N)]
for i in range(Q):
  p, x = map(int, input().split())
  P[p-1] += x


def dfs(p, par):
  for i in ab[p-1]:
    if i != par:
      P[i-1] += P[p-1]
      dfs(i, p)


dfs(1, -12345)
print(" ".join(map(str, P)))


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

typedef vector<int> vi;
typedef set<int> si;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define onesNumber(x) builtin_popcount(x) //builtin_popcount(ll)
#define testCases int t; cin >> t; while(t--)
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x * y / gcd(x, y))
const double PI = acos(-1.0);
const int N = 1e3 + 6;
const int MD = 1e5 * 4;

void solve(){

}

int main()
{
    //ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //testCases
        //solve();
    ll n, d, cnt = 0;
    cin >> n >> d;
    for(int i = 0; i < n; i++){
        ll x, y;
        cin >> x >> y;
        if((x * x) + (y * y) <= d * d)
            cnt++;
    }
    cout << cnt;


    return 0;
}


Measured memory_bytes: 3544
#include <stdio.h>
#include <math.h>
 
int main()
{
    double x1, y1, x2, y2;
     
    scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2);
    printf("%.8lf\n", hypot(x1-x2, y1-y2));
    return 0;
}


Measured memory_bytes: 2148
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int K,X;
	scan(K>>X);
	if(500*K>=X) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 256
//I read the news today, oh boy
//About a lucky man who made the grade
 
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(x) ll((x).size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cerr << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define For(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
#define roF(i,a,b) for(ll i = ll(a); i >= ll(b); i--)
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const ll N=1e6;

int main(){
	fastio;
	string s, t; cin>>s>>t;
	ll ans=0;
	For(i,0,sz(t)) if(s[i]!=t[i]) ans++;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3812
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

struct union_find{
  vector<int> par,r;

  union_find(int n){
  	par.resize(n);
  	r.resize(n);
  	for(int i = 0; i < n; i++) par[i] = i,r[i] = 0;
  }

  int find(int x){
    if(par[x] == x) return x;
    else return find(par[x]);
  }

  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(r[x] < r[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(r[x] == r[y]) r[x]++;
    }
  }

  bool same(int x,int y){
  	return find(x) == find(y);
  }
};

int main()
{
	int n,k,l;
	cin >> n >> k >> l;

	union_find road(n),train(n);
	for(int i = 0; i < k; i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		if(!road.same(a,b)) road.unite(a,b);
	}
	for(int i = 0; i < l; i++){
		int a,b;
		cin >> a >> b;
		a--,b--;
		if(!train.same(a,b)) train.unite(a,b);
	}

	vector<pair<int,int> > com(n);
	map<pair<int,int> ,int> s;
	for(int i = 0; i < n; i++){
		com[i].first = road.find(i);
		com[i].second =  train.find(i);
		s[com[i]]++;
	}

	for(int i = 0; i < n; i++){
		cout << s[com[i]] << " ";
	}printf("\n");

	return 0;
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
int main() {
	string S;
	cin >> S;
	ll K;
	cin >> K;
	vector<int> vec;
	int len = 1;
	for (int i = 1; i < S.size(); i++) {
		if (S[i] == S[i - 1]) {
			len++;
		} else {
			vec.push_back(len);
			len = 1;
		}
	}
	vec.push_back(len);
	if(vec.size() == 1) {
		cout << K*S.size()/2 << endl;
		return 0;
	}
	ll sum = 0;
	for (int v: vec) {
		sum += v/2;
	}
	sum *= K;
	if (S[0] == S.back()) {
		ll tmp = vec[0]/2 + vec.back()/2 - (vec[0] + vec.back())/2;
		sum -= (K-1) * tmp;
	}
	cout << sum << endl;
}

Measured memory_bytes: 256
K,A,B = map(int,input().split())

ans = 0
if A+2 >= B or K+2 < A:
    ans = K + 1
else:
    tmp = K - A

    if tmp%2 == 1:
        I = tmp+1
        I //= 2
        ans = I *B - (I-1)*A
    else:
        I = tmp
        I //= 2
        ans = 1 + I*B - (I-1)*A

print(ans)


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

using namespace std;
int n;
int a[55];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);
    double ans=1.0*(a[1]+a[2])/2.0;
    for(int i=3;i<=n;i++)
    {
        ans=1.0*(ans+a[i])/2.0;
    }
    printf("%.10f",ans);
    return 0;
}


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

int main() {
  long N, K;
  cin >> N >> K;
  if (N == K) {
    cout << 0 << endl;
  } else if (N < K) {
    cout << min(N, K-N) << endl;
  } else {
    cout << min(N-(N/K)*K, ((N/K)+1)*K-N) << endl;
  }
}


Measured memory_bytes: 3540
#include<stdio.h>
#include<tuple>
#include<string>
#include<algorithm>
#include<iostream>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef tuple<int,int,int> t3;

const int MX = 200005;
const int MM = 924844033;

ll D[MX];
int N, M;
ll K;

struct trans{
	int t[MX];
	trans operator*(const trans &l)const{
		trans res;
		for(int i = 1; i <= N-1; i++) res.t[i] = t[l.t[i]];
		return res;
	}
};

int main()
{
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%lld", D+i);
	trans A, B;
	for(int i = 1; i <= N-1; i++) A.t[i] = B.t[i] = i;

	scanf("%d%lld", &M, &K);
	for(int i = 1; i <= M; i++){
		int a;
		scanf("%d", &a);
		swap(A.t[a-1], A.t[a]);
	}
	while(K){
		if( K&1 ) B = B * A;
		A = A*A; K /= 2;
	}
	ll cur = D[1];
	for(int i = 1; i <= N; i++){
		printf("%lld\n", cur);
		int a = B.t[i];
		cur += D[a+1] - D[a];
	}
}


Measured memory_bytes: 4736
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n, q;
  cin >> n;
  vector<ll> man(100005, 0);
  set<ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    man[a]++;
  }

  ll result = 0;
  rep(i,100001) {
    result += i * man[i];
  }
  
  cin >> q;
  rep(i,q) {
    ll b, c;
    cin >> b >> c;
    ll tmp = man[b];
    man[b] = 0;
    man[c] += tmp;

    result -= b * tmp;
    result += c * tmp;

    cout << result << endl;
  }
}


Measured memory_bytes: 3932
N = int(input())
S = []
T = []
for i in range(N):
    A = int(input())
    if A % 10 == 0:
        S.append(A)
    else:
        T.append(A)
if len(T) == 0:
    print(0)
else:
    T_new = []
    for i in range(len(T)):
        max = 0
        for j in range(len(T)):
            if max < T[j]:
                max = T[j]
                num = j
        T_new.append(max)
        T[num] = 0
    SUM =sum(T_new)
    if SUM % 10 == 0:
        SUM = SUM - T_new[len(T_new)-1]
    print(SUM+sum(S))


Measured memory_bytes: 3064
import numpy as np
N = int(input())
hlist = np.array([_ for _ in map(int,input().split())])

max = np.max(hlist)
min = np.min(hlist)

newlist = np.zeros_like(hlist)
num = 0

list = []
#+++++
for i in range(1,N):
    sa = hlist[i-1]-hlist[i]
    if sa > 0:
        list.append(sa)
list.append(hlist[N-1])

print(sum(list))


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

int main(){
  string s;
  std::cin >> s;

  do {
    s.erase(s.size()-2);
  } while(s.substr(0,s.size()/2)!=s.substr(s.size()/2,s.size()/2));

  std::cout << s.size() << '\n';


  return 0;
}


Measured memory_bytes: 256