akhauriyash/Code-Regression huggingface dataset:
'use strict'

function Main(input) {
  const a = Number(input.split(' ')[0]);
  const b = Number(input.split(' ')[1]);

  if(a + b === 15) {
    console.log('+');
  } else if(a * b === 15) {
    console.log('*');
  } else {
    console.log('x');
  }

}

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

Measured memory_bytes: 21064
#include<stdio.h>
int main()
{
  int a,ba,i,j,h[20],stk;
  char b[200];
  while(1){
    scanf("%d",&a);
    if(a==0)break;
    scanf("%s",b);
    j=0;
    ba=0;
    for(i=0;i<a;i++)h[i]=0;
    for(i=0;i<100;i++){
      if(b[i]=='M')h[j]++;
      else if(b[i]=='S'){
	ba+=h[j]+1;
	h[j]=0;
      }else if(b[i]=='L'){
	h[j]+=ba+1;
	ba=0;
      }
      j++;
      if(j==a)j=0;
    }
    for(i=0;i<a*2;i++){
      for(j=1;j<a;j++){
	if(h[j]<h[j-1]){
	  stk=h[j];
	  h[j]=h[j-1];
	  h[j-1]=stk;
	}
      }
    }
    for(i=0;i<a;i++){
      printf("%d ",h[i]);
    }
    printf("%d\n",ba);
  }
  return 0;
}

Measured memory_bytes: 1032
import java.util.Scanner;
public class Main {
@SuppressWarnings("resource")
public static void main(String[] args) {
	Scanner sc =new Scanner(System.in);
	long A=sc.nextInt();
	long B=sc.nextInt();
	System.out.println(lcm(A,B));
}
static long lcm (long a, long b) {
	long temp;
	long c = a;
	c *= b;
	while((temp = a%b)!=0) {
		a = b;
		b = temp;
	}
	return (c/b);
}
}

Measured memory_bytes: 22608
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

offset = 3000

n, a = [int(item) for item in input().split()]
x = [int(item) - a for item in input().split()]

dp = [0] * 6000
dp[0 + offset] = 1

for item in x:
    if item < 0:
        for i in range(6000):
            if dp[i] == 0:
                continue 
            dp[i + item] += dp[i]
    else:
        for i in range(6000 - 1, -1, -1):
            if dp[i] == 0:
                continue 
            dp[i + item] += dp[i]
print(dp[offset] - 1)

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

using namespace std;

typedef long long ll;

int main(){
ll N,Q; cin >> N >> Q;
  vector<pair<ll,pair<ll,ll> >> event_sort;
  for(ll i = 0 ; i < N; i++){
    ll s,t,x; cin >> s >> t >> x;
    event_sort.push_back(make_pair(s-x,make_pair(-1,x)));
    event_sort.push_back(make_pair(t-x,make_pair(0,x)));}
  
    for(ll j = 0; j < Q; j++){
      ll d; cin >> d;
      event_sort.push_back(make_pair(d,make_pair(1,j)));}
    
    sort(event_sort.begin(),event_sort.end());
    
    multiset<ll> mp;
    
    vector<ll> answer(Q,0);
    
    for(ll i = 0; i < (2 *N + Q); i++){
      ll p,q,r;
      p = event_sort[i].first;
      q = event_sort[i].second.first;
      r = event_sort[i].second.second;
      if( q == -1){ 
        mp.insert(r);}
      else if( q == 0){
        mp.erase(mp.lower_bound(r));}
      else{
        if( mp.empty()){ answer[r] = -1;}
        else{
        answer[r] = *(mp.begin());}} }
    
    for(ll i = 0; i < Q; i++){
      cout << answer[i] <<endl; }
    return 0;}
        
      


Measured memory_bytes: 28260
//aea ctmr
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
//v.erase(unique(v.begin(),v.end()),v.end());
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define PI 3.14159265358979323846
 
typedef long double ld;
typedef long long ll;
const ll N = 100500;
const ll mod = 1e9 + 7;
using namespace std;
 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << endl;}
 
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1<<" | ";
  __f(comma+1, args...);}
#else
#define trace(...)
#endif




int main(){
    fastio;
    
    int n, m;
    cin >> n >> m;
    if(500 * n >= m) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using namespace std;

int main() {

    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    int tmp;

    int right=-100;
    for(int i=0; i < N; i++) {
        cin >> tmp;
        right = max(tmp, right);
    }

    int left=100;
    for(int i=0; i < M; i++) {
        cin >> tmp;
        left = min(tmp, left);
    }

    if(right < left && X < left && Y > right) {
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math

def solve(N: int, T: "List[int]", A: "List[int]"):
    current = [T[0],A[0]]
    for i in range(1,N):
        t = T[i]
        a = A[i]
        if current[0]>t or current[1]>a:
            multi = max((current[0]+t-1)//t,(current[1]+a-1)//a)
            t = t*multi
            a = a*multi
        
        current[0]=t
        current[1]=a

    print(sum(current))
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    T = [int()] * (N)  # type: "List[int]"
    A = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        T[i] = int(next(tokens))
        A[i] = int(next(tokens))
    solve(N, T, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
string divide[4]={"dream","erase","eraser","dreamer"};
string s;
bool DFS(int n){
    if(n==s.size())return true;
    for(string i:divide){
        if(n+i.size()<=s.size()&& s.substr(n,i.size())==i){
            if(DFS(n+i.size()))return true;
        }
    }
    return false;
}
int main(){
    cin>>s;
    cout<<(DFS(0) ? "YES" :"NO")<<endl;
}

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

int main(){

	cout << fixed << setprecision(12);
	double x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;

	double X = pow(x1 - x2, 2);
	double Y = pow(y1 - y2, 2);

	cout << sqrt(X + Y) << endl;
	return 0;


}



Measured memory_bytes: 3288
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main
{

	public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args)
	{
		// TODO 自動生成されたメソッド・スタブ
		try
		{
			String str1[] = input(1);
			String str2[] = input(Integer.parseInt(str1[0]));
			int[] a = new int[str2.length];
			for(int i = 0; i < str2.length; i++)
			{
				a[i] = Integer.parseInt(str2[i]);
			}
			int swa = BubbleSort(a);
			for(int i = 0; i < a.length; i++)
			{
				System.out.print(a[i]);
				if(i != a.length - 1) System.out.print(" ");
			}
			System.out.println("\n" + swa);
		}
		catch(IOException e)
		{
		}
	}

	public static int BubbleSort(int a[])
	{
		int swapp = 0;
		boolean flag = true;
		while(flag)
		{
			flag = false;
			for(int i = 0; i < a.length - 1; i++)
			{
				if(a[i] > a[i+1])
				{
					swapp++;
					swap(a, i, i+1);
					flag = true;
				}
			}
		}
		return swapp;
	}

	public static void swap(int a[], int x, int y)
	{
		int tmp = a[x]; a[x] = a[y]; a[y] = tmp;
	}

	/*
	public static int Calc(int[] a, int f, int e)
	{
		ArrayList<Integer> list[] = new ArrayList[2];
		return e;
	}
	//*/

	public static String[] input(int Num) throws IOException
	{
		String str[] = new String[Num];
		String str2 = br.readLine();
		int j = 0;
		for(int i = 0; i < Num; i++)
		{
			if(i < Num - 1)
			{
				str[i] = str2.substring(j, str2.indexOf(" ", j));
				j = str2.indexOf(" ", j) + 1;
			}
			else
			{
				str[i] = str2.substring(j);
			}
		}
		return str;
	}

}



Measured memory_bytes: 24372
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;

const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;

struct edge{int to,cost;};

struct State{
    int d,m,n;
    bool operator<( const State& right ) const {
        return d > right.d;
    }
};

int d[1<<6][108];
int cake[6];
int m,n,k,di;

int str2index(string str){
    if(str[0]=='H'){
        return 0;
    }else if(str[0]=='D'){
        return 1;
    }else if(str[0]=='C'){
        return atoi(str.erase(0, 1).c_str())+1;
    }else{
        return atoi(str.erase(0, 1).c_str())+1+m;
    }
}

int main(){
    while(1){
        scanf("%d%d%d%d",&m,&n,&k,&di);
        if(!n)break;

        vector<vector<edge> > g(n+m+2);
        for(int i=0;i<m;i++){
            scanf("%d",&cake[i]);
        }
        for(int i=0;i<di;i++){
            string a,b;
            int c;
            cin >> a >> b >> c;
            int a_i = str2index(a), b_i = str2index(b);
            g[a_i].push_back((edge){b_i,c});
            g[b_i].push_back((edge){a_i,c});
        }

        for(int i=0;i<(1<<m);i++){
            for(int j=0;j<n+m+2;j++){
                d[i][j] = INF;
            }
        }


        d[(1<<m)-1][0] = 0;
        priority_queue<State> que;
        que.push((State){0,(1<<m)-1,0});

        while(que.size()){
            State p = que.top(); que.pop();
            //printf("p.d=%d p.m=%d p.n=%d\n",p.d,p.m,p.n);
            if(d[p.m][p.n] < p.d) continue;
            for(int i=0;i<g[p.n].size();i++){
                int next_d = p.d+g[p.n][i].cost*k;
                if(2<=g[p.n][i].to&&g[p.n][i].to<m+2){
                    int m_i = g[p.n][i].to - 2;
                    if((p.m>>m_i)&1){
                        next_d -= cake[m_i];
                        int next_m = p.m^(1<<m_i);
                        if(next_d < d[next_m][g[p.n][i].to]){
                            d[next_m][g[p.n][i].to] = next_d;
                            que.push((State){next_d,next_m,g[p.n][i].to});
                        }
                    }
                }else{
                    if(next_d < d[p.m][g[p.n][i].to]){
                        d[p.m][g[p.n][i].to] = next_d;
                        que.push((State){next_d,p.m,g[p.n][i].to});
                    }
                }
            }
        }

        int ans = INF;
        for(int i=(1<<m)-1;i>=0;i--) ans = min(ans, d[i][1]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
long long a[201000]={0},b[201000];
int main()
{
	long long s,sum=0;
	cin>>s;
	for(int i=1;i<=s;i++)
	{
		cin>>b[i];
		a[b[i]]+=1;
	}
	/*for(int i=1;i<=s;i++)
		cout<<a[i]<<" ";*/
	for(int i=1;i<=s;i++)
			sum=sum+a[i]*(a[i]-1)/2;
	//cout<<sum<<endl;
	for(int i=1;i<=s;i++)
		if(a[b[i]]==0||a[b[i]]==1)
			cout<<sum<<endl;
		else
			cout<<sum-a[b[i]]+1<<endl;
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   // #ifndef ONLINE_JUDGE
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   // #endif
   int n;
   cin >> n;
   vector<int> a(n),b(n);
   set<pii> sa,sb;
   f(i,0,n){
      cin >> a[i];
      sa.insert({a[i],i});
   }
   f(i,0,n){
      cin >> b[i];
      sb.insert({b[i],i});
   }
   vector<int> val1(n,0),val2(n,0);
   while(!sa.empty()){
      auto k = sa.end();
      k--;
      sa.erase(k);
      int in = (*k).S;
      int sm = a[(in-1+n)%n]+a[(in+1)%n];
      if(!sm) continue;
      int kk = a[in]/sm;
      if(kk){
         a[in] -= kk*sm;
         val1[in] += kk;
         sa.insert({a[in],in});
      }
   }
   while(!sb.empty()){
      auto k = sb.end();
      k--;
      sb.erase(k);
      int in = (*k).S;
      int sm = b[(in-1+n)%n]+b[(in+1)%n];
      if(!sm) continue;
      int kk = b[in]/sm;
      if(kk){
         b[in] -= kk*sm;
         val2[in]+=kk;
         sb.insert({b[in],in});
      }
   }
   int ans = 0;
   f(i,0,n){
      if(a[i]!=b[i]){
         cout << "-1\n";
         return 0;
      }
      ans += val2[i];
      ans -= val1[i];
   }
   cout<< ans << '\n';
   return 0;
}

Measured memory_bytes: 31488
<?php
    /*
        Problem URL : http://abc059.contest.atcoder.jp/tasks/abc059_a

        Score  :
        Result :
        Time   : ms
        Memory : KB
     */

    ini_set('error_reporting', E_ALL & ~E_NOTICE);

    // define('DEBUG', true);
    define('DEBUG', false);

    if (DEBUG) {
        $start = microtime(true);
    }

    $a = explode(" ", trim(fgets(STDIN)));

    foreach ($a as $str) {
        echo strtoupper(substr($str, 0, 1));
    }
    echo PHP_EOL;


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

int main()
{
    int n;
    cin >> n;
    vector<int> b(n + 1);
    rep(i, 0, n - 1)
        cin >> b[i + 1];
    b[0] = b[1];
    b[n] = b[n - 1];

    int ans = 0;
    rep(i, 0, n)
        ans += min(b[i], b[i + 1]);
    cout << ans << endl;
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n, k;
	cin >> n >> k;
	cout << (int)(log(n) / log(k)) + 1;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 512
/*+lmake
 * STD = c++14
 * DEFINE += WAAUTOMATON
 */
#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#ifdef WAAUTOMATON
#define debug(args...)                                                                             \
    {                                                                                              \
        dbg, args;                                                                                 \
        cerr << endl;                                                                              \
    }
#define massert(x) assert(x)
#else
#define debug(args...) // Just strip off all debug tokens
#define massert(x)
#endif
struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;
const LL kcz=1e9+7;
LL qpow(LL x,LL n=kcz-2)
{
	LL ans=1;
	while(n>0) {
		if (n&1) ans=ans*x%kcz;
		x=x*x%kcz;
		n/=2;
	}
	return ans;
}
const int MAXN=100000;
LL sum[MAXN+10];
void solve(long long n, vector<long long> a){
	for(int i=1; i<=n; ++i) {
		sum[i]=(sum[i-1]+qpow(i))%kcz;
	}
	LL ans=0;
	for(int i=1; i<=n; ++i) {
		ans+=a[i-1]*(sum[i]+sum[n-i+1]-1+kcz)%kcz;
		ans%=kcz;
	}	
	for(int i=1; i<=n ;++i) {
		ans*=i;
		ans%=kcz;
	}
	cout<<ans<<endl;
}

int main(){	
#ifdef WAAUTOMATON
	//freopen("in.txt","r",stdin);
#endif
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int cnt1[100003],cnt2[100003],n,x,mx1,mx2,x1,x2;
int main(){
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x;
		if(i%2==0)
		{
			cnt1[x]++;
			if(mx1<cnt1[x])
				mx1=cnt1[x],
				x1=x;
		}
		else
		{
			cnt2[x]++;
			if(mx2<cnt2[x])
				mx2=cnt2[x],
				x2=x;
		}
	}
	sort(cnt1,cnt1+100003);
	sort(cnt2,cnt2+100003);
	if(x1!=x2)
		cout<<n-mx1-mx2;
	else
		cout<<n-max(mx1+cnt2[100001],mx2+cnt1[100001]);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <tuple>

using namespace std;

class Solver {
};


int main() {
	while (true) {
		int n, m, w, h, s;
		cin >> n >> m >> w >> h >> s;
		if (n == 0)break;

		vector<int> ls(m);
		vector<int> rs(m);
		for (int i = 0; i < m; i++) {
			cin >> ls[i] >> rs[i];
		}

		vector<tuple<double, double>> xys;
		for (int i = 0; i < n; i++) {
			double x, y;
			cin >> x >> y;
			xys.emplace_back(x, y);
		}

		vector<double> range_s(m);
		vector<int> range_cnt(m, 0);
		double s_sum = 0;
		for (int i = 0; i < m; i++) {
			double s_tmp = (ls[i] + rs[i]) * 0.5 * w;
			range_s[i] = s_tmp - s_sum;
			s_sum = s_tmp;
		}

		for (int i = 0; i < n; i++) {
			int bottom = -1;
			int top = m - 1;
			double x, y;
			tie(x, y) = xys[i];
			while (bottom + 1 < top) {
				int mid = (bottom + top + 1) / 2;

				double yy = (rs[mid] - ls[mid]) * x / w + ls[mid];
				if (yy >= y)top = mid;
				else bottom = mid;
			}

			range_cnt[top]++;
		}

		vector<int> sums(m, 0);
		sums[0] = range_cnt[0];
		for (int i = 1; i < m; i++) {
			sums[i] = sums[i - 1] + range_cnt[i];
		}

		int res = n;
		for (int i = 0; i < m; i++) {
			int bottom = i;
			int top = m;
			while (bottom + 1 < top) {
				int mid = (bottom + top) / 2;
				int l_delta = ls[mid];
				int r_delta = rs[mid];
				if (i > 0) {
					l_delta -= ls[i - 1];
					r_delta -= rs[i - 1];
				}
				double sum_tmp = (l_delta + r_delta) * 0.5 * w;
				double remain_s = h * w - sum_tmp;

				if (remain_s >= s)bottom = mid;
				else top = mid;
			}

			double l_d = ls[bottom];
			double r_d = rs[bottom];
			if (i > 0) {
				l_d -= ls[i - 1];
				r_d -= rs[i - 1];
			}
			double sum = (l_d + r_d) * 0.5 * w;
			if (w * h - sum < s)continue;

			int tmp = sums[m - 1] - sums[bottom];
			if (i > 0)tmp += sums[i - 1];
			res = min(res, tmp);
		}

		cout << res << endl;
	}
}


Measured memory_bytes: 4096
A = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
S = input()
for i in range(26):
	if not A[i] in S:
		print(A[i])
		exit()
print("None")


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  ll a, b;
  cin >> a >> b;

  for (ll i = a; i <= b; ++i) {
    if (i % k == 0) {
      cout << "OK" << endl;
      return 0;
    }
  }
  cout << "NG" << endl;
  
  return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

    int n;
    cin >> n;
    
    int tmp;
    int ans = 1;
    int cnt = 0;
    int maxcnt = 0;
  
    for(int i= 1;i<=n;++i){
        tmp = i;
        cnt =0;
        while(1){
            if(tmp%2 == 0) {
                cnt++;
                tmp /= 2;
                }else{
                 break;
                }
        }
        if(maxcnt < cnt) {
            maxcnt = cnt;
            ans = i; 
        };
    };
        cout << ans << endl;

    return 0;
};


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

int main(){

 int a,b;
 cin >> a >> b;

 if(a < b){
  cout<< "a < b" << endl;
 }else if(a > b){
 cout << "a > b" << endl;
}else{
cout <<"a == b" << endl;
}
return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FUP(i, a, b) for(auto i = a; i <= b; i++)
#define FDOWN(i, a, b) for(auto i = a; i >= b; i--)
#define MS(a, b) memset(a, b, sizeof(a))
#define ALL(v) v.begin(), v.end()
#define CIN(a) cin >> a;
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a
#define COUT2(a, b) cout << a << ' ' << b
#define COUT3(a, b, c) cout << a << ' ' << b << ' ' << c
#define ENDL cout << '\n'
int dy[4] = { -1, 1, 0, 0 };
int dx[4] = { 0, 0, 1, -1 };

int N;
vector<pair<ll, ll>> V;
map<ll, ll> M;
ll answer = 0;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	CIN(N);
	while (N--)
	{
		int num;
		CIN(num);
		M[num]++;
	}
	for (auto iter : M)
	{
		V.push_back({ iter.first, iter.second });
	}
	if (V.size() < 3)
	{
		COUT(0);
		return 0;
	}
	FUP(i, 0, V.size() - 3)
	{
		FUP(j, i + 1, V.size() - 2)
		{
			FUP(k, j + 1, V.size() - 1)
			{
				if (V[i].first + V[j].first > V[k].first)
				{
					answer += (V[i].second * V[j].second * V[k].second);
				}
				else break;
			}
		}
	}
	COUT(answer);

	return 0;
}

Measured memory_bytes: 3640
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String ans = "No";
        if(s.startsWith("YAKI")){
            ans = "Yes";
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 23636
/*
    Created by Rahul Goel.
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/*******************************************************************************/
using namespace std;
using namespace __gnu_pbds;
template < typename T >
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*******************************************************************************/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template < typename T, typename... Args >
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%MOD + MOD)%MOD; }
/*******************************************************************************/
ll mod_prod() { return 1LL; }
template< typename T, typename... Args >
T mod_prod(T a, Args... args) { return (a * mod_prod(args...))%MOD; }
/*******************************************************************************/
#ifdef ONLINE_JUDGE
#define endl '\n'
#endif
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
using pii = pair < ll, ll >;
using vi = vector < ll >;
using vb = vector < bool >;
using vvi = vector < vector < ll > >;
using vvb = vector < vector < bool > >;
using vpii = vector < pii >;
using vvpii = vector < vector < pii > >;
/*******************************************************************************/
//.-.. . -. -.- .- .. ... .-.. --- ...- .
/*
    Code begins after this.
*/

ll solve() {
    string s;
    cin >> s;
    if (s.back() == 's') {
        s += "es";
    } else {
        s += "s";
    }
    cout << s << endl;
    return 0;
}

signed main() {
    fastio;

    ll t = 1;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <set>
#include<unordered_map>


using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a, b;
    cin >> n >> a >> b;
    int c = abs(a - b);
    if(c%2==0)
        cout << "Alice" << endl;
        else
            cout << "Borys" << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int n=s.size();
  int j=s.size()-1;
  int findID=-1;
  int findID2=-1;
  for(int i=0;i<n;++i) {
    if(s[i]=='A') {
      findID=i;
      break;}
  }
  for(int i=0;i<n;++i) {
    if(s[j]=='Z') {
      findID2=j;
      break;}
    --j;
  }
  int ans=findID2-findID+1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+7;
int main()
{
	long long n,k;
	cin>>n>>k;
	vector<long long> h(n);
	for(long long i=0;i<n;i++){
		cin>>h[i];
	}
	// Initialise the vector elements with INF
	vector<long long> dp(n, INF);
	dp[0] = 0;
	for(long long i=0;i<n;i++){
		for(long long j=i+1;j<=i+k;j++){
			if(j<n)
				dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

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

int main() {
  int N;
  cin >> N;

  long long sum = 0;
  for (int i = 0; i <= N; i++) {
    if (!(i % 3 == 0 || i % 5 == 0)) {
      sum += i;
    }
  }
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3676
S=str(input())
T=str(input())
ss=len(S)
tt=len(T)
nax=0
ans=0
for i in range(ss-tt+1):
    for j in range(tt):
        if S[i+j]==T[j]:
            ans+=1
    nax=max(nax,ans)
    ans=0

print(tt-nax)


Measured memory_bytes: 67436
fun main(args: Array<String>) {
  val (a, b) = readLine()!!.split(" ").map { it.toInt() }
  val m = Math.min(a, b)
  val dif = Math.abs(a - b)
  if (dif % 2 == 1) {
    println("IMPOSSIBLE")
    return
  }
  println(dif / 2 + m)
}


Measured memory_bytes: 37952
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
using namespace std;
const int max_n = 100000+5;
long long cnt[111];
long long m,n,a=0,b,W;
const int INF = 1e9+1;
const int mod = 1e9 + 7;
long dist[max_n],s[max_n],w[max_n],v[max_n];
long long dp[max_n];
vector<vector<int> > G;
bool isprime(long long xx){
    if(xx == 2) return true;
    if(xx % 2==0 || xx<2)    return false;
    long long ii = 3;
    while(ii*ii <= xx){
        if(xx %ii == 0) return false;
        ii += 2;
    }
    return true;
}
long long gcd(long long xx, long long yy){
    if(yy == 0) return xx;
    long long k = xx/yy;
    long long c = xx - k*yy;
    return gcd(yy, c);
}
void solve(){
    for(int i=0 ; i<n ; i++){
        *lower_bound(dp, dp+n+1, s[i]) = s[i];
    }
    printf("%ld\n", lower_bound(dp,dp+n+1, INF) - dp);
}
int main(){
    cin >> n ;
    for(int i=0 ; i<n ; i++){
        cin >> s[i];
    }
    for(int i=0 ; i<=n ; i++){
        dp[i] = INF;
    }
    solve();
    return 0;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, b, n) for (int i = b; i < (n); ++i)

using namespace std;

// template<class... A> void prints()      { std::cout << std::endl; }
// template<class... A> void prints_rest() { std::cout << std::endl; }
// template<class T, class... A> void prints_rest(const T& first, const A&... rest) { std::cout << " " << first; prints_rest(rest...); }
// template<class T, class... A> void prints(const T& first, const A&... rest)      { std::cout << first; prints_rest(rest...); }

void solve(int H, int W, vector<string> S) {
  vector<vector<int>> horiz(H, vector<int>(W, 0));
  REP(h, H) {
    REP(w, W) {
      const auto obs = S[h].find('#', w);
      const int end = (obs == string::npos ? W : (int)obs);
      FOR (i, w, end)
	horiz[h][i] = end - w;
      w = end;
    }
  }

  // REP(h, H) {
  //   REP(w, W)
  //     cout << horiz[h][w];
  //   cout << endl;
  // }
  // cout << endl;
    
  vector<vector<int>> verti(H, vector<int>(W, 0));
  REP(w, W) {
    REP(h, H) {
      int end = h - 1;
      FOR(i, h, H) {
	if (S[i][w] == '#') {
	  end = i;
	  break;
	}
      }
      if (end == h - 1)
	end = H;
      // prints("h",h,"w",w,"end",end);
      FOR (i, h, end)
	verti[i][w] = end - h;
      h = end;
    }
  }

  // REP(h, H) {
  //   REP(w, W)
  //     cout << verti[h][w];
  //   cout << endl;
  // }

  int ans = 0;
  REP(h, H) {
    REP(w, W) {
      // skip obstalce cell
      if (S[h][w] == '#')
	continue;
      // count lighted cells
      int num_lighted_cells = -1;
      // up and down
      num_lighted_cells += verti[h][w];
      // left and right
      num_lighted_cells += horiz[h][w];

      ans = max(ans, num_lighted_cells);
    }
  }
  cout << ans << endl;
}

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

  int H, W;
  cin >> H >> W;

  vector<string> S(H);
  for(int i = 0 ; i < H ; i++)
    cin >> S[i];

  solve(H, W, move(S));
  return 0;
}


Measured memory_bytes: 35968
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    A,B,C=MI()
    print(max(0,C-(A-B)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))

satisf=0
index=100
for i in range(N):
   if A[i]-index==1:
      satisf=satisf+C[index-1]
   satisf=satisf+B[A[i]-1]
   index=A[i]

print(satisf)

Measured memory_bytes: 3064
import numpy as np
count = np.count_nonzero
N, K = list(map(int, input().split()))
A = np.array(list(map(int, input().split())))
div = 1000000007
s = 0
s2 = 0
for i, n in enumerate(A):
    tmp = A < n
    s += count(tmp[i+1:])
    s2 += count(tmp)

print(((s * K) + (s2 * (K-1) * K // 2)) % div)


Measured memory_bytes: 14444
l, r = map(int, input().split())
if r - l + 1 >= 2019:
  print(0)
else:
  ans = 2019
  for i in range(l, r):
    for j in range(i+1, r+1):
      mod = (i*j) % 2019
      ans = min(ans, mod)
  print(ans)


Measured memory_bytes: 9160
#!/usr/bin/env python3
import sys


def solve(A):
    print(A[0:3])
    return 0

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = next(tokens)  # type: int
    solve(A)

if __name__ == '__main__':
    main()

Measured memory_bytes: 8984
#if 0
????????????????§£????????????????????????????????????????????????AOJ????????????????????????????????????wrong???answer?????????????????????
????????§?????????????????\????????????????????£??????????????§??????????????????????????????????????¨???????????????
???????????????????????? Union Find Tree ???????????????????????????????????????????????????????????????????????????Root?????¢?????°??????????????¨??§??????
??????????????§???????????????????????????????????????????????¢??°???????????¢??°?????????????????£??????????????°???????????°???????\???????????????¨???????????¨???
????????????????????????
Minimum Spanning Tree ???????????§???????????¶??????????????????????????¨????????????????????¨?????????????????????????????????????????????????????£?????????
???????????????????????????????????????
#endif

#include <iostream>
#include<algorithm>
using namespace std;


struct edge
{
   int cost;
   int src;
   int dst;
};

edge e[5001];
int A[101][101];
int M=0;
int P[101];

void init(int N)
{
  for (int i=0; i<=N; ++i) P[i] = i;
}

int root(int a)
{
  if (P[a] == a) return a;
  return (P[a] = root(P[a]));
}

bool is_same_set(int a, int b)
{
  return root(a) == root(b);
}

void unite(int a, int b)
{
  P[root(a)] = root(b);
}

void checkEdges(int n)
{
    for(int r=0;r<n;r++)
    {
        for(int c=r+1;c<n;c++)
            {
                if(A[r][c]>-1)
                    {
                        e[M].cost=A[r][c];
                        e[M].src=r;
                        e[M].dst=c;
                        M+=1;
                    }
            }
    }
}

bool cmp(edge e1,edge e2)
{
    return e1.cost<=e2.cost;
}
int main()
{
    int n,count=0;
    cin>>n;
    init(n);
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++){
                cin>>A[i][j];
        }
    }
    checkEdges(n);
    sort(e,e+M,cmp);
    for (int i=0; i<M; ++i)
    {
        if(is_same_set(e[i].src,e[i].dst))
        {
            continue;
        }
        unite(e[i].dst,e[i].src);
        count+=e[i].cost;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3148
using System;
class main
{
    static void Main(string[] args)
    {
        string s = string.Empty;
        while ((s = Console.ReadLine()) != null)
        {
            string[] s1 = s.Split(' ');
            long[] a = new long[3];
            a[0] = long.Parse(s1[0]);
            a[1] = long.Parse(s1[1]);
            a[2] = 0;
            Array.Sort(a);
            Array.Reverse(a);
            long c = a[0] * a[1];
            if (a[1] != 0)
            {
                while (true)
                {
                    a[2] = a[1];
                    a[1] = a[0] % a[1];
                    a[0] = a[2];
                    if (a[1] == 0)
                    {
                        Console.WriteLine("{0} {1}", a[0], (c / a[0]));
                        break;
                    }
                }
            }
            else
            {
                Console.WriteLine("{0} {1}", a[0], (c / a[0]));
            }
        }
    }
}

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

int main(){
    int n,n1,n2,m=1,i;
    scanf("%d",&n);
    while((m<<1)<=n)m<<=1;
    if(n==m){printf("No");return 0;}
    n1=n+1;n2=n<<1;
    printf("Yes\n1 2\n2 3\n3 %d\n%d %d\n%d %d\n",n1,n1,n+2,n+2,n+3);
    for(i=4;i<n;i+=2)printf("%d %d\n%d %d\n%d %d\n%d %d\n",n1,i,i,i|1,n1,n+(i|1),n+(i|1),n+i);
    if(!(n&1)){
        printf("%d %d\n",m,n);
        if(n==m+2)printf("3 %d\n",n2);
        else printf("%d %d\n",n2-m+1,n2);
    }
    return 0;
}

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

#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define MOD2 998244353

template<class T,class U>bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U>bool chmin(T &a, const U &b){if(b<a){a=b;return 1;}return 0;}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef long double ld;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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



int ok[1000010];
int main(){

    bool flag=false;
    ll ans=0,sum=0;

    fill(ok,ok+1000010,1);

    int n;
    cin>>n;
    vector<int> a(n);
    map<int,int> fq;

    rep(i,n){
        cin>>a[i];
        fq[a[i]]++;
    }

    sort(all(a));

    for(auto p : fq){
        int frq = p.second;
        int num = p.first;

        if(ok[num] == 1 && frq == 1){
            ++ans;
            //db2(num,frq);ln;
        }

        int i = 2*num;
        while(1){
            if(i > 1000000)break;
            ok[i]=-1;
            i += num;
        }
    }

    cout<<ans<<endl;

    //cout <<fixed<<setprecision(16)<< << endl;

    //if(flag)cout << "Yes" <<endl;
    //elsmpe cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 17252
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

    /*
    ||||||||||||||||||||||||||||||||||||||||||||||||
       |      |||         |      ||||    ||||  |   |
      | |     |   |      | |     |   |  |      |   |
     |   |    |    |    |   |    |   |  |      |   |
    |||||||   |    |   |||||||   |||     |||   |||||
    |     |   |   |    |     |   | |        |  |   |
    |     |   |||      |     |   |  ||  ||||   |   |
    ||||||||||||||||||||||||||||||||||||||||||||||||

    */
    using namespace std;
    //#include "testlib.h"
    #define ff first
    #define ss second
    #define mp make_pair
    #define all(v) v.begin(),v.end()
    #define int long long
    #define ll long long
    #define M 1000000007
    #define inputarr(a,n) for(int i=0;i<n;++i) cin>>a[i]
    #define GCD(m,n) __gcd(m,n)
    #define LCM(m,n) m*(n/GCD(m,n))
    #define mii  map<ll ,ll >
    #define msi  map<string,ll >
    #define mis  map<ll int, string>
    #define rep(a,b)    for(ll i=a;i<b;i++)
    #define rep0(n)    for(ll i=0;i<n;i++)
    #define repi(i,a,b) for(ll i=a;i<b;i++)
    #define pb push_back
    #define vi vector<ll>
    #define mp make_pair
    #define vs vector<string>
    #define ppb pop_back
    #define endl '\n'
    #define asdf ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define r0 return 0;
    #define FORD(i, a, b) for (int i = (int) (a); i >= (int) (b); --i)
    #define FORE(it, c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
    #define inputoutput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
    #define input freopen("input.txt", "r", stdin);
    #define Set(a, s) 4(a, s, sizeof (a))
    #define FOR repi
    #define pii pair<int,int>
    //#define float long double
    ll max(ll a, ll b) { return (a > b)? a : b;}
    int min(int a, int b) { return (a < b)? a : b;}


     int solve()
     {
        int n;
        cin>>n;
        vi a(n);
        inputarr(a,n);
        int sum=0;
        rep0(n) sum=a[i]-sum;
        int x=sum/2;
        cout<<sum<<" ";
        sum=0;
        rep0(n-1){
            sum=a[i]-sum;
            int ans=2*sum-pow(-1,i)*2*x;
            cout<<ans<<" ";
        }
        }
    signed main()
    {   
        asdf
        int t=1;
        //cin>>t;
        while(t--)
        {
            solve();
        }     
        
}

Measured memory_bytes: 2176
n=int(input())

basis=[26**i for i in range(12)]
l=[]
s=0
for b in basis:
    s+=b
    l.append(s)    

i=0
f=12
while(f-i>1):
#     print(f-i)
    x=(i+f)//2
    if l[x]>n:
        f=x
    else:
        i=x

k=n-l[i]
length=i+1

res=[]
for i in range(length):
    q=k//26
    r=k%26
    k=q
    res.append(r)

ans=list(map(lambda x: chr(ord("a")+x),list(reversed(res))))
print("".join(ans))

Measured memory_bytes: 8976
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int x,a,b;
int main()
{
	while(~scanf("%d%d%d",&x,&a,&b))
	{
		printf("%d\n",(x-a)%b);
	}
	return 0;
	
 } 

Measured memory_bytes: 128
#include <iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
using namespace std;
int main (void) {
    long long int N,K,sum;
    cin >> N >> K;
    sum = K;
    N--;
    while(N--)  sum*=(K-1);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)
int main(){
  ll h,c[10][10],ans=0;
  cin>>h>>h;
  fr(i,10) fr(j,10) cin>>c[i][j];
  fr(k,10) fr(i,10) fr(j,10) c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
  for(;cin>>h;) if(h>=0) ans+=c[h][1];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

vector<vector<int> > to;
vector<int> ans;

void dfs(int v,int p=-1){
  rep(i,to[v].size()){
    int nv=to[v][i];
    if(nv==p) continue;
    ans[nv]+=ans[v];
    dfs(nv,v);
  }
}

int main(){
  int n,q; cin >> n >> q;
  to.resize(n);
  ans.resize(n);
  rep(i,n-1){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,q){
    int a,b;
    cin >> a >> b;
    a--;
    ans[a]+=b;
  }
  dfs(0);
  rep(i,n){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 32896
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif


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

    ll N; cin >> N;
    vll a(N);
    rep(i,N) cin >> a[i];
    rep(i, N) if(a[i] == 0) {
        cout << 0 << endl;
        return 0;
    }

    boost::multiprecision::uint128_t ans = 1, INF = 1000000000000000000;
    rep(i, N) {
        ans *= a[i];
        if(INF < ans) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
}


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

void print(vector<int> x){
  for (int n = 0; n < x.size(); n++){
    cout << x.at(n) << " ";
  }
  cout << endl;
}

int main(){
  int64_t N;
  cin >> N;

  vector<int> D;
  N--;

  // 桁数を確定する
  int64_t pow26 = 26;
  int d = 1;
  
  while(N >= pow26){
    N -= pow26;
    pow26 *= 26;
    d++;
  }

  //cout << d << ":" << N << endl;

  // Nを26進数としてd桁表示する
  for (int n = 0; n < d; n++){
    D.push_back(N % 26);
    N /= 26;
  }

  reverse(D.begin(), D.end());
  //print(D);

  for (int n = 0; n < D.size(); n++){
    cout << (char)('a' + D.at(n));
  }
  cout << endl;
}


Measured memory_bytes: 3616
#include<stdio.h>

int main(void)
{
        int input = 0,train[10];
        int i = 1;

        for(i=1;i<=10;i++)
        {
                train[10] = 0;
        }


        i = 1;
        while(scanf("%d",&input) != EOF)
        {

                if(input != 0)
                {
                        train[i] = input;
                        i++;
                }
                else if(input == 0)
                {
                        i--;
                        printf("%d\n",train[i]);
                }
        }
        return 0;
}

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

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

int X, Y, A, B, C;
priority_queue<int, vector<int>, greater<int>> pq;
vector<int> a, b, c;

int ans;
int max_ans = 0;

void update(int x)
{
    if(pq.size() != Y)
    {
        ans += x;
        pq.push(x);
    }
    else
    {
        int v = pq.top();
        pq.pop();
        ans -= v;
        x = max(x, v);
        pq.push(x);
        ans += x;
    }
}

signed main()
{
    cin >> X >> Y >> A >> B >> C;

    int v;
    rep(i, A)
    {
        cin >> v;
        a.push_back(v);
    }
    rep(i, B)
    {
        cin >> v;
        b.push_back(v);
    }
    rep(i, C)
    {
        cin >> v;
        c.push_back(v);
    }

    sort(a.rbegin(), a.rend());
    sort(b.rbegin(), b.rend());
    sort(c.rbegin(), c.rend());

    int aa = max(X - C, 0ll), cc = min(X, C);

    rep(i, B)update(b[i]);
    rep(i, C)
    {
        if(i < cc)ans += c[i];
        else update(c[i]);
    }
    max_ans = ans;
    rep(i, min(X, A))
    {
        if(i < aa)ans += a[i];
        else
        {
            ans += a[i];
            ans -= c[cc - 1 - (i - aa)];
            update(c[cc - 1 - (i - aa)]);
        }
        max_ans = max(ans, max_ans);
    }

    cout << max_ans << endl;

    return 0;
}


Measured memory_bytes: 7112
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("Ofast")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair<int,int>pi;
typedef vector<int>vi;

const int MAXN=100005;
const int MOD=1000000007;

#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
#define UP(v,x) (upper_bound(all(v),(x))-(v).begin())

int X,N,P[MAXN];
bool flag[MAXN];

main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin>>X>>N;
	FOR(i,1,N) {
		cin>>P[i];
		flag[P[i]]=1;
	}
	int bestdif = 1e9;
	int best = 1e9;
	FOR(i,-1,101){
		if(i>=0 && flag[i]) continue;
		int dif = abs(i-X);
		if (dif < bestdif) {
			best=i;
			bestdif = dif;
		}
		else if (dif == bestdif){
			best = min(best, i);
		}
	}
	cout<<best;	
}


Measured memory_bytes: 3620