akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define N 100005
#define mod 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define lb(arr,n,x) lower_bound(arr,arr+n,x)-arr
#define ub(arr,n,x) upper_bound(arr,arr+n,x)-arr
#define endl "\n"
#define PI 3.14159265358979323846  /* pi */
#define sqr(x) (x)*(x)
#define sign(x) (x>0)-(x<0)
#define is_poweroftwo(n) (n&& !(n&(n-1)))
#define all(v)  ((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.
#define int long long
#define debug(x) cout<<(#x)<<" is "<<(x)<<endl
#define AagLgaDe ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef long double ld;
 
//Calculation of (x^y)%mm
ll mod_exp(ll x,ll y,ll mm)
{
    if(y==0)
        return(1);
    else if(y%2==0)
        return(mod_exp((x*x)%mm,y/2,mm));
    else
        return((x*mod_exp((x*x)%mm,(y-1)/2,mm))%mm);
}
bool isPowerOfTwo(int n) 
{ 
   if(n==0) 
   return false;
   return (ceil(log2(n)) == floor(log2(n))); 
}
 
//int x1[]={+1,-1,+0,+0};
//int y1[]={+0,+0,+1,-1};
//int x2[]={+0,+0,+1,-1,-1,+1,-1,+1};
//int y2[]={-1,+1,+0,+0,+1,+1,-1,-1};
//int x3[]={-2,-2,-1,-1,+1,+1,+2,+2};
//int y3[]={-1,+1,-2,+2,-2,+2,-1,+1};
 
int solve()
{
	int n, k;
	cin>>n>>k;
	int arr[n];
	rep(i,n)
		cin>>arr[i];
	vector<int> dp(n, INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n)
				dp[j]=min(dp[j], abs(arr[j]-arr[i])+dp[i]);
		}
	}
	return dp[n-1];
}
 
signed main() {
  	AagLgaDe
    // int t;cin>>t;while(t--)
	   cout<<solve();
 
 
return 0;
}

Measured memory_bytes: 4772
def prime_factorize(n):
    result = []
    if n % 2 == 0:
        t = 0
        while n % 2 == 0:
            n //= 2
            t += 1
        result.append((2, t))
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i != 0:
            continue
        t = 0
        while n % i == 0:
            n //= i
            t += 1
        result.append((i, t))
        if n == 1:
            break
    if n != 1:
        result.append((n, 1))
    return result

N = int(input())

result = 0
for p, e in prime_factorize(N):
    i = 1
    while e >= i:
        result += 1
        e -= i
        i += 1
print(result)


Measured memory_bytes: 9384
#include<bits/stdc++.h>
using namespace std;
int i,j,n,a,m;
double c,k,l=1,ans;
int main(){
  cin>>n;
  vector<vector<int>> d(n,vector<int>(2));
  for(;i<n;i++)for(j=0;j<2;j++)cin>>d[i][j];

  vector<int> o(n);
  for(i=0;i<n;i++)o[i]=i;
  do{
    for(c=0,i=1;i<n;i++){
      int x=d[o[i]][0]-d[o[i-1]][0];
      x*=x;
      int y=d[o[i]][1]-d[o[i-1]][1];
      y*=y;
      c+=sqrt(x+y);
    }
    ans+=c;
    k++;
  }while(next_permutation(o.begin(),o.end()));
  printf("%.10f", ans/k);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		long H = scan.nextLong(), W = scan.nextLong();
		if(H == 1 || W == 1) {
			System.out.println(1);
		}else{
			System.out.println(Math.round(H  * W / 2.0));
		
		}
	}
	
}

Measured memory_bytes: 21844
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=list(ns())
ans=S[0:3]
print(''.join(ans))


Measured memory_bytes: 10424
#include <stdio.h>

int main()
{

int a[10000], min, max, n, i;
long long sum = 0;
scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%d", &a[i]);
sum += a[i];
}
max = min = a[0];
for(i = 1; i < n; i++){
if(a[i] > max)max = a[i];
if(a[i] < min)min = a[i];
}
printf("%d %d %lld\n", min, max, sum);

return 0;
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,x;
    
    cin>>a;
    cin>>b;
    cin>>c;
    d=0;
    
for(x=a; x<=b; x++){
    if(c%x==0){
       d++;
    }
  }
  
  cout << d << endl;
}



Measured memory_bytes: 3108
#include <cstdio>
#include <algorithm>
#include <queue>
#include <string>
#include <iostream>
#include <vector>

using namespace std;

string tmp;
int str[101000];

vector<pair<int,int>> vt;

int n;
int main(){
	//freopen("input.txt","r",stdin);
	cin>>tmp;
	n = tmp.length();

	for(int i = 0 ; i < n ; i++){
		str[i+1] = tmp[i]-'0';
	}
	if(str[1]== 0 || str[n-1] ==0 || str[n] == 1 ){
		puts("-1");
		return 0;
	}

	bool flag = 0;
	for(int i = 1 ; i <= n ; i++){
		if(i >= n-i)	break;
		if(str[i] != str[n-i]){
			flag = 1;
			break;
		}
	}
	if(flag){
		puts("-1");
		return 0;
	}

	int curr = 1;
	for(int i = 2 ; i <= n ; i++){
		
			if(str[i-1]){
				vt.push_back({curr,i});
				curr = i;
			}
			else{
				vt.push_back({curr,i});
			}
		
	}

	for(auto i : vt){
		printf("%d %d\n",i.first,i.second);
	}

}

Measured memory_bytes: 2804
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S,T,U,R;
  int N;
  cin>>S;
  N=S.size();
  R=S;
  reverse(R.begin(),R.end());
  if(S!=R){cout<<"No"<<endl;return 0;}
  T=S.substr(0,(N-1)/2);
  R=T;
  reverse(R.begin(),R.end());
  if(T!=R){cout<<"No"<<endl;return 0;}
  U=S.substr((N+3)/2-1);
  R=U;
  reverse(R.begin(),R.end());
  if(U==R)cout<<"Yes"<<endl;else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
 int N,W;
 cin>>N>>W;
 
 int v[N],w[N];
 
 for(int i=0;i<N;i++){
    cin>>v[i]>>w[i];
 }
 
 int DP[N+1][W+1];
 
 for(int j=0;j<=W;j++){
    DP[0][j]=0;
 }
 
 for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
        if(j<w[i-1]){
            DP[i][j]=DP[i-1][j];
        }else{
            if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
                DP[i][j]=DP[i-1][j];
            }else{
                DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
            }
        }
    }
 }
 cout<<DP[N][W]<<endl;
return 0;
}

Measured memory_bytes: 6996
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

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

void Main(){
    int N, M;
    cin >> N >> M;
    vec<P> A(N), C(M);
    REP(i, N){
        cin >> A[i].fi >> A[i].se;
    }
    REP(i, M){
        cin >> C[i].fi >> C[i].se;
    }
    REP(i, N){
        ll mn = LONG_LONG_MAX;
        int mn_i = 0;
        REP(j, M){
            if(chmin(mn, abs(A[i].fi-C[j].fi)+abs(A[i].se-C[j].se))){
                mn_i = j;
            }
        }
        cout << mn_i+1 << el;
    }
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 444444;
int n;char s[N];
Vi a,b,c;int nxt[N];
int main() {
	scanf("%s",s+1);n=strlen(s+1);
	if(s[1]!='1'||s[n]=='1'){puts("-1");return 0;}
	rep(i,1,n-1)if(s[i]^s[n-i]){puts("-1");return 0;}
//	per(i,n-1,1)if(s[i]=='1')a.pb(i);
	/*rep(t,0,SZ(a)-1){
		if()
	}*/
	for(int i=n,j=n;i>=1;i--){nxt[i]=j;if(s[i]=='1')j=i;}
	per(i,n-1,1){
		int j=nxt[i];//per(k,n-1,i+1)if(s[k]=='1')j=k;
		b.pb(i);c.pb(j);
	}
	per(i,SZ(b)-1,0)printf("%d %d\n",b[i],c[i]);
	return 0;
}

Measured memory_bytes: 2932
program main
  implicit none
  integer(8) :: n, i, d, e, k, res, x, b(0:42)
  integer(8), allocatable :: a(:)
  read (*, *) n, k
  allocate (a(n))
  read (*, *) a

  b(:) = 0
  do i = 1, n
    do d = 0, 42
      if (btest(a(i), d)) b(d) = b(d) + 1
    end do
  end do

  res = f(k, b, n)
  do d = 0, 42
    x = k
    if (.not. btest(x, d)) cycle
    x = ibclr(x, d)
    do e = 0, d - 1
      if (b(e) * 2 >= n) then
        x = ibclr(x, e)
      else
        x = ibset(x, e)
      end if
    end do
    res = max(res, f(x, b, n))
  end do
  print "(i0)", res
  contains

  integer(8) function f(x, b, n)
    integer(8), intent(in) :: x, b(0:42), n
    integer(8) :: d
    f = 0
    do d = 0, 42
      if (btest(x, d)) then
        f = f + (n - b(d)) * 2 ** d
      else
        f = f + b(d) * 2 ** d
      end if
    end do
  end function
end program main


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int n;
ll k;
vector<ll>v1,v2;
bool judge(ll m)
{
    m++;
    ll ans=0;
    ll s1=v1.size(),s2=v2.size();
    if(m==0)
    {
        for(int i=0;i<s2;i++)
            if(v2[i]==0) ans+=s1;
        ans+=(ll)s1*(s1-1)/2;
        ans+=(ll)s2*(s2-1)/2;
        ans=(ll)n*(n-1)/2-ans;
        return ans>=k;
    }
    if(m>0)
    {
        for(int i=0;i<s1-1;i++)
        {
            ll x=m/v1[i];
            if(m%v1[i]) x++;
            int k=lower_bound(v1.begin()+i+1,v1.end(),x)-v1.begin();
            ans+=s1-k;
        }
        for(int i=0;i<s2-1;i++)
        {
            if(v2[i]==0) continue;
            ll x=m/v2[i];
            if(m%v2[i]) x++;
            int k=lower_bound(v2.begin()+i+1,v2.end(),x)-v2.begin();
            ans+=s2-k;
        }
        ans=(ll)n*(n-1)/2-ans;
        return ans>=k;
    }
    if(m<0)
    {
        m*=-1;
        ans+=(ll)s1*(s1-1)/2;
        ans+=(ll)s2*(s2-1)/2;
        for(int i=0;i<s1;i++)
        {
            ll x=m/v1[i];
            int k=upper_bound(v2.begin(),v2.end(),x)-v2.begin()-1;
            ans+=k+1;
        }
        ans=(ll)n*(n-1)/2-ans;
        return ans>=k;
    }
}
int main()
{
    scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++)
    {
        int x;scanf("%d",&x);
        if(x<0) v1.push_back(-x);
        else v2.push_back(x);
    }
    sort(v1.begin(),v1.end());
    sort(v2.begin(),v2.end());
    ll l=-1e18,r=1e18,ans;
    while(l<=r)
    {
        ll m=l+r>>1;
        if(judge(m)) ans=m,r=m-1;
        else l=m+1;
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 2548
#include<iostream>
#include<string>
#include<cmath>
#include <algorithm>
using namespace std;
 
int main(){
  int N;
  int W[110];
  int T = 0;
  
  cin >> N ;
  for(int i=0;i<N;++i) cin >> W[i];
  
  int counter = 1;
  int res = 100000;
  
  for(int i=1;i<N;++i){
    int L=0,R=0;
    for(int j=0;j<i;++j) L += W[j];
    for(int j=i;j<N;++j) R += W[j];
    if(res > abs(L-R)) res = abs(L-R);
  }
  cout << res << endl;
}

Measured memory_bytes: 256
# 行に一個もない場所を探しておく
H, W, K = map(int, input().split())
S = [list(input()) for _ in range(H)]

no_berry = [i for i in range(H) if S[i].count('#') == 0]
#print(no_berry)
answer = [[] for _ in range(H)]
#print(answer)
cur = 0
cur2 = 0
for i in range(H):
    if i in no_berry:
        if i != 0 and i-1 not in no_berry:
            answer[i] = answer[i-1]
        continue
    if i != 0:
        cur2 = cur
    for j in range(W):
        if S[i][j] == '#':
            cur += 1
        if j == 0 and i not in no_berry:
            cur2 += 1
        answer[i].append(max(cur, cur2, 1))
for i in range(H-2, -1, -1):
    if answer[i] == []:
        answer[i] = answer[i+1]
for i in range(1, H):
    if answer[i] == []:
        answer[i] = answer[i-1]
for x in answer:
    print(*x)


Measured memory_bytes: 8400
#include <cstdio>
char s[310][310];
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	int ans = 0;
	for (int k = -n + 1; k < n; k++) {
		int b = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				b &= s[i][j] == s[(j+k+n)%n][(i-k+n)%n];
			}
		}
		if (!b) continue;
		b = k < 0 ? -k : k;
		ans += n - b;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=200005;
const int mo=1000000007;
int cnt[N],a[N];
int val1[N],val2[N];
int val3[N],val4[N];
int vpr[N],vsu[N];
int pre[N],suf[N];
int ifac[N],iinv[N];
int n,ans,V,S[N];
int power(int x,int y){
	int s=1;
	for (;y;y/=2,x=1ll*x*x%mo)
		if (y&1) s=1ll*s*x%mo;
	return s;
}
int func(int l,int r){
	if (pre[r-1]>=l+1) return 0;
	return 1ll*vpr[l-1]*vsu[r+1]%mo*val4[l]%mo*val3[r]%mo*ifac[r-1]%mo*iinv[l]%mo;
}
struct TARR{
	int t[N];
	void change(int x,int v){
		for (;x<=n;x+=x&(-x)) t[x]=(t[x]+v)%mo;
	}
	int ask(int x){
		ll ans=0;
		for (;x;x-=x&(-x)) ans+=t[x];
		return ans%mo;
	}
	int ask(int l,int r){
		l=max(l,1); r=min(r,n);
		if (l>r) return 0;
		return (ask(r)+mo-ask(l-1))%mo;
	}
}T1,T2,T3;
void update(int x,int y){
	if (a[x]>a[y]) ans=(ans+mo-func(a[y],a[x]))%mo;
	if (a[x]<a[y]) ans=(ans+func(a[x],a[y]))%mo;
}
int main(){
	scanf("%d",&n);
	For(i,1,n) scanf("%d",&a[i]),cnt[a[i]]++;
	For(i,1,n) S[i]=S[i-1]+cnt[i];
	V=1;
	For(i,1,n){
		val1[i]=val2[i]=val3[i]=1;
		For(j,S[i-1]+1,S[i]){
			val1[i]=1ll*val1[i]*(i-j+1)%mo;
			val2[i]=1ll*val2[i]*(i-j)%mo;
			if (j!=S[i-1]+1)
				val3[i]=1ll*val3[i]*(i-j+1)%mo;
		}
		val4[i]=1ll*val1[i]*(i-S[i])%mo;
		V=1ll*V*val1[i]%mo;
	}
	if (!V) return puts("0"),0;
	vpr[0]=vsu[n+1]=1;
	For(i,1,n) vpr[i]=1ll*vpr[i-1]*val1[i]%mo;
	Rep(i,n,1) vsu[i]=1ll*vsu[i+1]*val1[i]%mo;
	pre[0]=0; suf[n+1]=n+1;
	For(i,1,n) pre[i]=(val2[i]==0?i:pre[i-1]);
	Rep(i,n,1) suf[i]=(val2[i]==0?i:suf[i+1]);
	For(i,1,n) if (!val2[i]) val2[i]=1;
	ifac[0]=1;
	For(i,1,n) ifac[i]=1ll*ifac[i-1]*val2[i]%mo;
	iinv[n]=power(ifac[n],mo-2);
	Rep(i,n,1) iinv[i-1]=1ll*iinv[i]*val2[i]%mo;
	For(i,1,n){
		int vl=1ll*vpr[a[i]-1]*val4[a[i]]%mo*iinv[a[i]]%mo;
		int vr=1ll*vsu[a[i]+1]*val3[a[i]]%mo*ifac[a[i]-1]%mo;
		ans=(ans+1ll*(i-1-T1.ask(a[i]-1))*V)%mo;
		ans=(ans+1ll*(i-1-T1.ask(a[i]))*V)%mo;
		ans=(ans+mo-1ll*vl*T2.ask(a[i]+1,suf[a[i]+1])%mo)%mo;
		ans=(ans+1ll*vr*T3.ask(pre[a[i]-1],a[i]-1)%mo)%mo;
		//For(j,1,i-1) update(j,i);
		T1.change(a[i],1);
		T2.change(a[i],vr);
		T3.change(a[i],vl);
	}
	ans=1ll*ans*(mo+1)/2%mo;
	printf("%d\n",ans);
}
//return 1ll*vpr[l-1]*vsu[r+1]%mo*val4[l]%mo*val3[r]%mo*ifac[r-1]%mo*iinv[l]%mo;

Measured memory_bytes: 12800
#include <stdio.h>
using namespace std;

int main()
{
    int a, b, r;
    scanf("%d %d", &a, &b);

    r = a % b;
    while(r != 0){
        int t = b % r;
        b = r; // gcd
        r = t; // remainder
    }

    printf("%d\n", b);
    return 0;
}


Measured memory_bytes: 2716
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

const int dev = 1000000007;
typedef unsigned long long ull;


ull power2(int m){
    if(m==0) return 1ull;
    return (2*power2(m-1))%dev;
}

int main(){
    int n, A;
    cin >> n;
    vector<int> As((n+1)/2, 0);
    if (n%2 == 1){
        for (int i=0;i<n;i++){
            cin >> A;
            if(A%2 == 0 && A >= 0 && A < n){
                As[A/2]++;
            }
        }
        bool flag = true;
        for (int i=1;i<(n+1)/2;i++){
            if(As[i] != 2) flag = false;
        }
        if(flag && As[0] == 1){
            cout << power2(n/2) << endl;
        }else{
            cout << 0 << endl;
        }
    }else{
        for (int i=0;i<n;i++){
            cin >> A;
            if(A%2 == 1 && A > 0 && A < n){
                As[A/2]++;
            }
        }
        bool flag = true;
        for (int i=0;i<(n+1)/2;i++){
            if(As[i] != 2) flag = false;
        }
        if(flag){
            cout << power2(n/2) << endl;
        }else{
            cout << 0 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1280
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>

const int MaxN = 1e5;
using namespace std;

map <string,int> a;
map <string,int> d;
string b[105],c[105];
int n, m;

int main()
{
	cin >> n;
	int y = 0;
	for(int i = 1;i <= n;i++)
	{
		cin >> b[i];
		a[b[i]]++;
	}
	cin >> m;
	for(int i = 1;i <= m;i++)
	{
		cin >> c[i];
		d[c[i]]++;
	}
	for(int i = 1;i <= n;i++)
	{
		if(a[b[i]] - d[b[i]] > y) y = a[b[i]] - d[b[i]];
	}
	for(int i = 1;i <= m;i++)
	{
		if(a[c[i]] - d[c[i]] > y) y = a[c[i]] - d[c[i]];
	}
	cout << y << endl;
	return 0;
}


Measured memory_bytes: 256
## abc070d: Transit Tree Path
 
n = int(input())
 
T = [None]*(n+1)
for _ in range(n-1):
    v1,v2,d = map(int, input().split())
    if(T[v1] is None): T[v1] = [[v1,v2,d]]
    else: T[v1].append([v1,v2,d])
    if(T[v2] is None): T[v2] = [[v2,v1,d]]
    else: T[v2].append([v2,v1,d])

q,k = map(int, input().split())

depth = [0]*(n+1)
visit = [False]*(n+1)
depth[k] = 0
visit[k] = True
stack = T[k]
while stack:
    p,c,d = stack.pop()
    if visit[c]: continue
    visit[c] = True
    depth[c] = depth[p] + d
    for pp,cc,dd in T[c]:
        if not visit[cc]: stack.append([pp,cc,dd])
 
for _ in range(q):
    v1,v2 = map(int, input().split())
    print(depth[v1]+depth[v2])

Measured memory_bytes: 51412
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    char c;
    cin >> c;
    if(c == 'A') cout << 'T' << endl;
    if(c == 'T') cout << 'A' << endl;
    if(c == 'C') cout << 'G' << endl;
    if(c == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int N,R;
	cin >> N>>R;
	if (N < 10) {
		R += 100 * (10 - N);
	}
	cout << R << endl;
}

Measured memory_bytes: 256
s=input()
xy=list(map(int,input().split()))
p=[[0],[0]]
i=0
for c in s:
    if c=='F':
        p[i][-1]+=1
    else:
        i^=1
        p[i].append(0)
a=[1,1]
for i in range(2):
    s0=set((p[i][0],))
    for j in range(1,len(p[i])):
        s1=set()
        for e in s0:
            s1.add(e+p[i][j])
            s1.add(e-p[i][j])
        s0=s1
    if xy[i] not in s0:
        a[i]=0
print(['No','Yes'][all(a)])

Measured memory_bytes: 48348
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll a, b, c;
    cin >> a >> b >> c;

    if(a+b>=c){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int *p; // parent array
int *r;

void MakeSet(int x){
    p[x] = x;
    r[x] = 0;
};

int Find(int x){
    if(p[x] == x) return x;

    return p[x] = Find(p[x]);
};

void Unite(int x, int y){
    x = Find(x);
    y = Find(y);

    if(x != y){
        if(r[x] < r[y]){
            p[x] = y;
        }else
        {
            p[y] = x;
            if(r[x] == r[y]){
                ++r[x];
            }
        }
    }


};

int main() {

    int n,q; // initial conditions
    unsigned int action; // operation type
    int op1, op2;
    int *ans;
    int cnt = 0;

    cin >> n >> q;
    p = new int[n];
    r = new int[n];
    ans = new int[q];
    for (int i = 0; i < n; ++i) {
        MakeSet(i);
    }
    for (int i = 0; i < q; ++i) {

        cin >> action >> op1 >> op2;
        if (action == 0){
            Unite(op1, op2);
        } else if(action == 1){
            if (Find(op1) == Find(op2)){
                ans[cnt] = 1;
                cnt++;
            } else{
                ans[cnt] = 0;
                cnt++;
            }
        }

    }
    for(int i = 0; i < cnt; ++i){
        cout << ans[i] << endl;
    }


    return 0;
}


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

using namespace std;
using ll = long long;

vector<ll> h, f;
double slope(int i, int j) {
  return (f[i] - f[j] + h[i] * h[i] - h[j] * h[j]) / 2.0 / (h[i] - h[j]);
}

int main() {
  int n;
  ll c;
  cin >> n >> c;
  h.resize(n); f.resize(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  vector<int> q(n);
  q[0] = 0;
  int l = 0, r = 0;
  for (int i = 1; i < n; ++i) {
    while (l < r && slope(q[l], q[l+1]) <= h[i]) ++l;
    f[i] = f[q[l]] + (h[q[l]] - h[i]) * (h[q[l]] - h[i]) + c;
    while (l < r && slope(q[r-1], q[r]) >= slope(q[r], i)) --r;
    q[++r] = i;
  }
  cout << f[n-1] << '\n';
  return 0;
}


Measured memory_bytes: 7200
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl //[l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<endl;out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n,m,x,y,xn,ym;

signed main(){
    io();

    in(n,m,x,y);
    xn=x;ym=y;
    int a;
    rep(i,n){
        in(a);
        xn=max(a,xn);
    }
    rep(i,m){
        in(a);
        ym=min(a,ym);
    }
    //show(x,y,xn,ym);
    if(x>=y||xn>=y||ym<=x||ym<=xn){
        puts("War");
    }else{
        puts("No War");
    }

    return 0;
}


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

int n,pos;
vector<int>pre,in,post;

void rec(int l,int r){
  if(l>=r)return;
  int root=pre[pos++];
  int m=distance(in.begin(),find(in.begin(),in.end(),root));
  rec(l,m);
  rec(m+1,r);
  post.push_back(root);
}

void solve(){
  pos=0;
  rec(0,pre.size());
  for(int i=0;i<n;i++){
    if(i)cout<<" ";
    cout<<post[i];
  }
  cout<<endl;
}

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

  for(int i=0;i<n;i++)
    {
      cin>>k;
      pre.push_back(k);
    }
  for(int i=0;i<n;i++){
    cin>>k;
    in.push_back(k);
  }
  solve();

  return 0;
}








Measured memory_bytes: 3128
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int H, W, N;
  cin >> H >> W >> N;
  if (H < W) swap(H, W);
  int ans = 0;
  int M = 0;
  for (int i = 0; i < W; ++i) {
    if (M >= N) break;
    M += H;
    ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 typedef long long unsigned int ll;
int main() {
    int N;
    cin >> N;

    map<int, int> m;
    //++m[0]; // 初期値 0

    int num;
    
    for(int i=1;i<N+1;i++){
        cin >> num;
        m[num] = i;
    }

    for(int i=1;i<N+1;i++){
        cout << m[i] << " ";
    }

    cout << endl;
}

// //配列
// vector<int> vec(N);
// for (int i = 0; i < N; i++) {
// cin >> vec.at(i);
// }

// //配列の要素数
// 配列変数.size();

// //初期値の指定
// vector<型> 配列名(要素数, 初期値);

// //要素の追加
// vec.push_back(10);

Measured memory_bytes: 5504
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	int n;

	cin>>n;

	vi p(n);

	rep(i, n){
		cin>>p[i];
	}
	sort(all(p));

	int ans=0;
	rep(i, n-1){
		ans+=p[i];
	}
	cout<<ans+p[n-1]/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n,n){  //,演算子、最後の式を評価
        vector<vector<int>> graph(10,vector<int>(10,99999999));
        int used[10]={0};
        for(int i=0;i<n;i++){
            int a,b,c;
            cin>>a>>b>>c;
            graph[a][b]=c;
            graph[b][a]=c;
            used[a]++;
            used[b]++;
        }
        for(int i=0;i<10;i++){
           //if(used[i])
                graph[i][i]=0;
        }
        for(int k=0;k<10;k++){
            for(int i=0;i<10;i++){
                for(int j=0;j<10;j++){
                    if(graph[i][j]>graph[i][k]+graph[k][j])
                        graph[i][j]=graph[i][k]+graph[k][j];
                }
            }
        }
        int min=99999999;
        int minpos;
        for(int i=0;i<10;i++){
            if(used[i]==0) continue;
            int sum=0;
            for(int j=0;j<10;j++){
                if(used[j]>0){
                    sum+=graph[i][j];
                }
            }
            if(min>sum){
                min=sum;
                minpos=i;
            }
        }
        cout<<minpos<<" "<<min<<endl;
    }
}



Measured memory_bytes: 3144
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main 
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		int i=0;
		int j=0;
		BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
		String str1 = input.readLine();
		int n = Integer.parseInt(str1);
		String[] CardName = new String[n];
		for(i=0;i<n;i++)
		{
			String str2 = input.readLine();
			CardName[i] = str2;
		}
		String[] AllCard = {"S 1","S 2","S 3","S 4","S 5","S 6","S 7","S 8","S 9","S 10","S 11","S 12","S 13",
				"H 1","H 2","H 3","H 4","H 5","H 6","H 7","H 8","H 9","H 10","H 11","H 12","H 13",
				"C 1","C 2","C 3","C 4","C 5","C 6","C 7","C 8","C 9","C 10","C 11","C 12","C 13",
				"D 1","D 2","D 3","D 4","D 5","D 6","D 7","D 8","D 9","D 10","D 11","D 12","D 13"};
		for(i = 0;i < 52;i++)
		{
			for(j = 0;j < n;j++)
			{
				if(AllCard[i].equals(CardName[j]))
				{
					break;
				}
				if(j == n-1)
				{
					System.out.println(AllCard[i]);
				}
			}
		}
		
	}
}



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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

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

int dp[999999];

int n;
vec<int> six, nine;

signed main() {
	cin >> n;

	rep (i, 999999) {
		dp[i] = 1e18;
	}
	dp[0] = 0;

	int num = 6;
	while (1) {
		if (num > n) break;
		six.push_back(num);
		num *= 6;
	}
	num = 9;
	while (1) {
		if (num > n) break;
		nine.push_back(num);
		num *= 9;
	}

	rep (i, n) {
		rep (j, six.size()) {
			chmin(dp[i+six[j]], dp[i] + 1);
		}
		rep (j, nine.size()) {
			chmin(dp[i+nine[j]], dp[i] + 1);
		}
	}

	int base = 0;
	int plus = 0;
	for (int i = n; i >= 0; i--) {
		if (dp[i] != 1e18) {
			base = dp[i];
			plus = n - i;
			break;
		}
	}
	// dbg2(base, plus)

	cout << base + plus << endl;

	return 0;
}

Measured memory_bytes: 8064
def sort(n1, n2, n3):
	n=[n1, n2, n3]
	t=len(n)
	for i in range(t-1):
		for j in range(i+1, t):
			if n[i] > n[j]:
				n[i],n[j] = n[j],n[i]
	return n

if __name__ == '__main__':
	A, B, C=map(int, input().split())
	N=0
	arr=[]
	flag=1
	if(A%2==1 or B%2==1 or C%2==1):
		flag=0

	while(flag):
		A, B, C = sort(A,B,C)
		arr.append([A,B,C])
		sum = A+B+C
		A=(sum-A)/2
		B=(sum-B)/2
		C=(sum-C)/2
		N+=1
		if(A%2==1 or B%2==1 or C%2==1):
			flag=0
		for i in range(len(arr)-1):
			if(arr[i] == [A,B,C]):
				flag = 0
				N=-1
	print(N)

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;

void main()
{
	int[31] stu;
	foreach (i; 0..28) {
		stu[readln.chomp.to!int]++;
	}
	foreach (i; 1..31) {
		if (!stu[i]) i.writeln;
	}
}

Measured memory_bytes: 1072
#include <cstdio>

int main(){
    char S[5];
    scanf("%s",S);
    int z = 0;
    for(int i = 0; i < 4; i++){
        if(S[i] == '+'){
            z++;
        }else if(S[i] == '-'){
            z--;
        }
    }
    printf("%d\n",z);

    return 0;
}

Measured memory_bytes: 128
n, y = map(int, input().rstrip().split())
a, b, c = -1, -1, -1

for i in range(n+1):
    for j in range(n+1-i):
        if 10000*i + 5000*j + 1000*(n-i-j) ==  y:
            a, b, c = i, j, n-i-j
            break
    else:
        continue
    break
print(a, b, c)

Measured memory_bytes: 40684
str1 = gets.chomp
str2 = gets.chomp
lenStr1 = str1.length
lenStr2 = str2.length
matrix = Array.new
(lenStr2+1).times{|i| matrix.push(Array.new(lenStr1,0))}
for i in 1..lenStr1 do
 matrix[0][i] = i
end
for i in 1..lenStr2 do
 matrix[i][0] = i
end
for i in 1..lenStr1 do
 for j in 1..lenStr2 do
  x = (str1[i-1] == str2[j-1]) ? 0 : 1
  y = matrix[j][i-1] + 1
  z = matrix[j-1][i] + 1
  matrix[j][i] = [matrix[j-1][i-1]+x,y,z].min
 end
end
print("#{matrix[lenStr2][lenStr1]}\n")

Measured memory_bytes: 20604
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

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

	cout << max(max(a * 2 - 1, b * 2 - 1), a + b) << endl;

	return 0;
}

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

using namespace std;

int main(void)
{
  int n, k;
  cin >> n >> k;
  LL answer = n-k+1;
  cout << answer << endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    
    int a[N];
    int mp[9];

    for(int i=0;i<9;i++) mp[i] = 0;

    for(int i=0;i<N;i++){
        cin >> a[i];
        if(0<a[i] && a[i]<400){
            mp[0]++;
        }
        else if(400<=a[i] && a[i]<800){
            mp[1]++;
        }
        else if(800<=a[i] && a[i]<1200){
            mp[2]++;
        }
        else if(1200<=a[i] && a[i]<1600){
            mp[3]++;
        }
        else if(1600<=a[i] && a[i]<2000){
            mp[4]++;
        }
        else if(2000<=a[i] && a[i]<2400){
            mp[5]++;
        }
        else if(2400<=a[i] && a[i]<2800){
            mp[6]++;
        }
        else if(2800<=a[i] && a[i]<3200){
            mp[7]++;
        }
        else if(3200<=a[i]){
            mp[8]++;
        }
    }


    int cnt = 0;
    for(int i=0;i<8;i++){
        if(mp[i]>0){
            cnt++;
        }
    }
    int mins=0;
    if(cnt == 0 && mp[8]>0){
        mins = 1;
    }else{
        mins = cnt;
    }
    
    int maxs = cnt + mp[8];

    cout << mins << " "<< maxs << endl;
    
}

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

void prians(bool answer) {
  if(answer)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int n;
int l[15] = {0}, sum = 0, ma = 0;
bool ch = 0;

int main() {
  cin >> n;
  for(int i = 0; i < n; ++i) cin >> l[i];
  for(int i = 0; i < n; ++i) sum += l[i];
  for(int i = 0; i < n; ++i) ma = max(ma, l[i]);
  prians(sum - ma > ma);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

#define seg_len (1<<20)

ll seg[seg_len*2];

void change(int ind, char c) {
  ind += seg_len;
  int v = (int)c - (int)'a';
  seg[ind] = 1<<v;
  while(true) {
    ind /= 2;
    if(ind == 0) break;
    seg[ind] = seg[ind*2] | seg[ind*2+1];
  }
  return;
}

ll culc(int l, int r) {
  l += seg_len;
  r += seg_len;
  ll tmp = 0;
  while(l<r) {
    if(l%2==1) {
      tmp |= seg[l];
      l++;
    }
    l /= 2;
    if(r%2==1) {
      tmp |= seg[r-1];
      r--;
    }
    r /= 2;
  }
  int ret = 0;
  while(tmp>0) {
    if(tmp%2==1) ret++;
    tmp /= 2;
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  rep(i,s.size()) {
    int v = (int)s[i] - (int)'a';
    seg[i+seg_len] = 1<<v;
  }
  for(int i = seg_len-1; i>=1; i--) seg[i] = seg[i*2] | seg[i*2+1];
  int q;
  cin >> q;
  vi ans;
  rep(i,q) {
    int com;
    cin >> com;
    if(com==1) {
      int ind;
      cin >> ind;
      ind--;
      char c;
      cin >> c;
      s[ind] = c;
      change(ind,c);
    }
    if(com==2) {
      int l, r;
      cin >> l >> r;
      l--;
      ans.push_back(culc(l,r));
    }
  }
  rep(i,ans.size()) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 13316
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <tuple>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repd(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define repdm(i, a, b) for (ll i = (ll)(a); i > (ll)(b); i--)

int main()
{

  double W, H, X, Y;
  cin >> W >> H >> X >> Y;

  double xs, ys;

  printf("%.12f", W * H / 2);
  char same = W / 2 == X & H / 2 == Y ? '1' : '0';
  cout << " " << same;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
-- import qualified Data.ByteString as BS
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
--import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Fixed
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
--import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
import Text.Printf
import System.IO
-- import System.IO.Unsafe
 
-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
getDoubles = map readDouble . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
tjoin :: (Show a, Show b) => (a, b) -> String
tjoin (x, y) = show x ++ (' ' : show y)
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
coverC :: Ord a => (a, a) -> a -> Bool
coverC (l,r) x = l<=x && x<=r
coverH :: Ord a => (a, a) -> a -> Bool
coverH (l,r) x = l<=x && x<r
ibsearch :: (Int -> Bool) -> (Int,Int) -> Int
ibsearch f (ok,ng) = if abs (ok-ng) <= 1 then ok else let mid = (ok + ng) `div` 2 in ibsearch f (if f mid then (mid,ng) else (ok,mid))
whenM :: Monad m => m Bool -> m () -> m ()
whenM c a = c >>= flip when a
unconsU :: [a] -> (a, [a])
unconsU (x:xs) = (x, xs)
-- templete

riffle n cards c = rsub b a
  where
    (a, b) = splitAt (n`div`2) cards
    rsub [] _ = []
    rsub x y = let (xt,xd) = splitAt c x in let (yt,yd) = splitAt c y in xt ++ yt ++ rsub xd yd

main = do
    eof <- isEOF
    unless eof $ do
        [n, r] <- getInts
        cs <- getInts
        let cards = [0..n-1]
        print $ last $ foldl (riffle n) cards cs
        main


Measured memory_bytes: 4236
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
typedef pair<int,int> ii;
const double pi=3.141592653589793238462643383279;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin>>x;
	int lol=0;
	for(int i=-1000;i<=1000;i++)
	{
		for(int j=-1000;j<=1000;j++)
		{
			if(pow(i,5)-pow(j,5)==x)
			{
				lol=1;
				cout<<i<<" "<<j<<endl;
				break;
			}
		}
		if(lol)break;
	}
}

Measured memory_bytes: 4116
#include <complex>
#include <iostream>
using namespace std;
typedef complex<double> P;
int main() {
  int n; cin >> n;
  while(n--) {
    double ra,rb;
    double x1,y1,x2,y2;
    cin >> x1>>y1>>ra>>x2>>y2>>rb;
    P a(x1,y1), b(x2,y2);
    double d = abs(a-b);
    if (d<ra-rb) cout << 2;
    else if (d<rb-ra) cout << -2;
    else if (d<=ra+rb) cout << 1;
    else cout << 0;
    cout << endl;
  }
}


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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef _DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main() {

    string s;
    int c[26]={0};
    cin>>s;
    rep(i,s.length())
    {
        c[s[i]-'a']++;
    }
    rep(i,26){
        if(c[i]==0){cout << (char)('a'+i) << endl; return 0;}
    }
    cout << "None" << endl;
    
    return 0;
}


Measured memory_bytes: 512