akhauriyash/Code-Regression huggingface dataset:
// Author -- Frame

#include<bits/stdc++.h>

#define lowbit(x) ((x)&(-(x)))
#define Finline __inline__ __attribute__ ((always_inline))
#define DEBUG fprintf(stderr,"Running on Line %d in Function %s\n",__LINE__,__FUNCTION__)
#define SZ(x) ((int)x.size())
#define mkpr std::make_pair
#define pb push_back

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef std::pair<int,int> pi;
typedef std::pair<ll,ll> pl;

const int inf=0x3f3f3f3f,Inf=0x7fffffff;
const ll INF=0x3f3f3f3f3f3f3f3f;

Finline uint rnd()
{
	static uint seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
template <typename _Tp>_Tp gcd(const _Tp &a,const _Tp &b){return (!b)?a:gcd(b,a%b);}
template <typename _Tp>Finline _Tp abs(const _Tp &a){return a>=0?a:-a;}
template <typename _Tp>Finline _Tp max(const _Tp &a,const _Tp &b){return a<b?b:a;}
template <typename _Tp>Finline _Tp min(const _Tp &a,const _Tp &b){return a<b?a:b;}
template <typename _Tp>Finline void chmax(_Tp &a,const _Tp &b){(a<b)&&(a=b);}
template <typename _Tp>Finline void chmin(_Tp &a,const _Tp &b){(b<a)&&(a=b);}
template <typename _Tp>Finline void read(_Tp &x)
{
	char ch(getchar());
	bool f(false);
	while(ch<48||ch>57) f|=ch==45,ch=getchar();
	x=ch&15,ch=getchar();
	while(ch>=48&&ch<=57) x=(((x<<2)+x)<<1)+(ch&15),ch=getchar();
	if(f) x=-x;
}
template <typename _Tp,typename... Args>Finline void read(_Tp &t,Args &...args){read(t);read(args...);}
template <typename _Tp,typename... Args>Finline _Tp min(const _Tp &a,const _Tp &b,const Args &...args){return a<b?min(a,args...):min(b,args...);}
template <typename _Tp,typename... Args>Finline _Tp max(const _Tp &a,const _Tp &b,const Args &...args){return a<b?max(b,args...):max(a,args...);}
Finline int read_str(char *s)
{
	char ch(getchar());
	while(ch==' '||ch=='\r'||ch=='\n') ch=getchar();
	char *tar=s;
	*tar=ch,ch=getchar();
	while(ch!=' '&&ch!='\r'&&ch!='\n'&&ch!=EOF) *(++tar)=ch,ch=getchar();
	return tar-s+1;
}

const int N=(1<<18)+5;
const int mod=1000000007;
template<typename _Tp1,typename _Tp2>Finline void add(_Tp1 &a,_Tp2 b){(a+=b)>=mod&&(a-=mod);}
template<typename _Tp1,typename _Tp2>Finline void sub(_Tp1 &a,_Tp2 b){(a-=b)<0&&(a+=mod);}
int p[N],h,n,m;
int sum[N],ans;
std::vector<int> v;
void mark(int x,int val)
{
	v.pb(x);
	while(x)
	{
		val=1ll*val*x%mod;
		add(sum[x],val);
		x>>=1;
	}
}
void calc(int x,int val)
{
	while(x)
	{
		val=1ll*val*x%mod;
		add(ans,1ll*sum[x^1]*val%mod*(x>>1)%mod);
		x>>=1;
	}
}
void dfs1(int x,int val)
{
	val=1ll*val*x%mod;
	if((x<<1)>n) mark(p[x-m]+m,val);
	else dfs1(x<<1,val),dfs1(x<<1|1,val);
}
void dfs2(int x,int val)
{
	val=1ll*val*x%mod;
	if((x<<1)>n) calc(p[x-m]+m,val);
	else dfs2(x<<1,val),dfs2(x<<1|1,val);
}
int main()
{
	read(h);
	n=(1<<h)-1;
	m=1<<(h-1);
	for(int i=0;i<m;++i) read(p[i]),--p[i];
	for(int i=1;i<m;++i)
	{
		dfs1(i<<1,i);
		dfs2(i<<1|1,1);
		while(!v.empty())
		{
			int cur=v.back();
			while(cur) sum[cur]=0,cur>>=1;
			v.pop_back();
		}
	}
	printf("%d\n",ans);
	return 0;
}


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;
int p[maxn];
void run_case()
{
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> p[i];
    }
    sort(p + 1, p + 1 + n);
    int ans = 0;
    for (int i = 1; i <= k; i++)
    {
        ans += p[i];
    }
    cout << ans << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3684
n = int(input())
x = list(map(int, input().split()))
if min(x) == max(x):
    print(0)
    exit()

dist_min = 9999999999999
for i in range(min(x),max(x)):
    dist_sum = 0
    for j in range(n):
        dist_sum += (x[j] - i)**2
    if dist_sum < dist_min:
        dist_min = dist_sum

print(dist_min)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

    ll j = 0;
    rep(i, 9) {
        if("AKIHABARA"[i] == s[j]) {
            j++;
        }
        else if("AKIHABARA"[i] != 'A') {
            out("NO");
            re0;
        }
    }

    if(j == s.size()) {
        out("YES");
    }
    else {
        out("NO");
    }
    
    re0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int result = 0;
        result += (X / 500) * 1000;
        int remain = X % 500;
        result += (remain / 5) * 5;
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MAX_V=114514LL;
//const ll MAX = 510000LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
//約数の列挙O(√n)
vector<ll>divisor(ll n){
  vector<ll>res;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      res.push_back(i);
      if(i != n/i) res.push_back(n/i);
    }
  }
  return res;
}
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll comb(ll n, ll r){
  ll res=1;
    for(ll i=0;i<r;i++){
      res*=n-i;
      res%=MOD;
    }
  res*=modpow(factorial(r),MOD-2,MOD);
  res%=MOD;
  return res;
}
ll sum[114514*2];
//ll flag[114514*2];
//ll dp[114514*2];
vl cnt(114514*2);
vvl G(114514*2);
void dfs(ll now,ll pr,ll num){
  //if(flag[i])return dp
  sum[now]=num+cnt[now];
  for(auto t:G[now]){
    if(t==pr)continue;
    dfs(t,now,sum[now]);
  }
  //return dp[pr]+count[now];
  return;
}
int main(){
  
  ll n,q;cin>>n>>q;
  vl a(n-1),b(n-1);
  //vvl G(n);
  rep(i,n-1){
    cin>>a[i]>>b[i];a[i]--;b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  vl p(q),x(q);
  // vl count(n);
  rep(i,q){
    cin>>p[i]>>x[i];p[i]--;
    cnt[p[i]]+=x[i];
  }
  dfs(0,-1,0);
  rep(i,n-1)cout<<sum[i]<<" ";
  cout<<sum[n-1]<<endl;
}


  



Measured memory_bytes: 33024
# coding: utf-8
# Your code here!
s=list(input())
t=list(input())
ans='No'
for i in range(len(s)):
    tmp=s[len(s)-1]
    s.pop(len(s)-1)
    s.insert(0,tmp)
    if s==t:
        ans='Yes'
        break
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define print(v) cout<<v<<endl
#define first(v) get<0>(v)
#define second(v) get<1>(v)
#define third(v) get<2>(v)
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    ll a;
    for(ll i=0;i<N;i++){
        cin>>a;
    ;}


    print((N+K-3)/(K-1));



    
    return 0;
}


Measured memory_bytes: 256
/***** TheAnshul *****/

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vii         vector<pair<ll int, ll int>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
using namespace std;
#define N  100005
ll dp[1005][1005];
char a[1005][1005];
void solve()
{
	ll n,m;
	cin>>n>>m;
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
			cin>>a[i][j];
	}
	a[1][1]='#';
	dp[1][1]=1;
	rep(i,1,n+1)
	{
		rep(j,1,m+1)
		{
			if(a[i][j]=='#')
				continue;
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
		}
	}
	cout<<dp[n][m]%hell;
	return;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	time
	return 0;
}

Measured memory_bytes: 9088
N, A = map(int, input().split())
x = []
x = list(map(int, input().split()))

dp = [[[0 for i in range(2555)] for j in range(55)] for k in range(55)]

dp[0][0][0] = 1

for i in range(N):
    for j in range(N):
        for k in range(2501):
            if dp[i][j][k] <= 0:
                continue
            dp[i+1][j][k] += dp[i][j][k]
            dp[i+1][j+1][k+x[i]] += dp[i][j][k]

res = 0
for i in range(1, N+1):
    res += dp[N][i][i*A]
print(res)


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

int main(){
	int x,y,p;

	for (;;)
	{
		cin >> x >> y;
		
		if (x > y)
		{
			p = x;
			x = y;
			y = p;

		}
		if (x == 0&&y == 0)break;
		cout << x << " " << y << endl;
		
	}

		return 0;
}

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

int main(){

    string s;
    cin>>s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1'){    //要素と比較にはシングルクォーテーション
                            //シングルクォーテーションは文字リテラル自体を渡す
            s.replace(i,1,"9"); //replaceの引数にはダブルクォーテーション
                                //ダブルクォーテーションは文字列のアドレス(先頭？)を渡す
        }else{
            s.replace(i,1,"1");
        }
    }
    cout<<s<<endl;
} 

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

int main() {
	int a, b;
	cin >> a >> b;
	if (a + b == 15)cout << "+" << endl;
	else if (a * b == 15)cout << "*" << endl;
	else cout << "x" << endl;
}

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

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if (a.at((a.size()-1)) == b.at(0) && b.at((b.size()-1)) == c.at(0)) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    while(N){
        vector<int> V(N);
        rep(i,0,N)cin >> V[i];
        sort(V.begin(), V.end());
        int mind = INF;
        rep(i,1,N)mind = min(mind, V[i] - V[i-1]);
        cout << mind << endl;
        cin >> N;
    }
}


Measured memory_bytes: 3136
/// * BISMILLAH * ///
#include<bits/stdc++.h>
/// Try to solve it, even though you may not solve it  ----- Aspot ///
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
if (c >= a && c <= a + b)
cout << "YES";
else
cout << "NO";
}

Measured memory_bytes: 256
-- ABC113 B
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  n <- readLn :: IO Int
  (t:a:_)<- fmap (map read . words) getLine :: IO [Int]
  hs <- fmap (map read . words) getLine :: IO [Int]
  print $ solve t a hs

solve t a hs = fst m
  where
    temps = zip [1..] $ map ((\x -> abs (x - (fromIntegral a))) . (temperature t)) hs
    m = minimumBy (\x y -> compare (snd x) (snd y)) temps


temperature :: Int -> Int -> Double
temperature t h = (fromIntegral t) - (fromIntegral h) * 0.006


Measured memory_bytes: 1276
a, b = map(int, input().split())
if a == 1:
    a = 14
if b == 1:
    b = 14
def calc(a, b):
    if a > b:
        return 'Alice'
    elif a < b:
        return 'Bob'
    else:
        return 'Draw'
print(calc(a, b))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E18;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){fastio
    ll n,m;cin>>n>>m;
    ll k;cin>>k;
    ll a[n+1],b[m+1];
    rep(i,0,n-1)cin>>a[i];
    a[n]=inf;
    rep(i,0,m-1)cin>>b[i];
    b[m]=inf;
    ll suma[n+1],sumb[m+1];
    suma[0]=0;
    rep(i,1,n){
        suma[i]=suma[i-1]+a[i-1];
    }
    sumb[0]=0;
    rep(i,1,m){
        sumb[i]=sumb[i-1]+b[i-1];
    }
    ll ans=0;
    rep(i,0,n){
        ll t=k-suma[i];
        if(t<0){
            break;
        }
        ll l=0,r=m+1;
        while(r-l>1){
            ll mid=(r+l)/2;
            if(sumb[mid]<=t){
                l=mid;
            }else{
                r=mid;
            }
        }
        ans=max(ans,i+l);
        //cout<<t<<' '<<i<<' '<<l<<endl;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 9908
#include "bits/stdc++.h"
using namespace std;

#define REP(i, s, n) for(int i = (s); i < int(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(co) co.begin(), co.end()

int dp[201][201];

int main()
{
	int d, n; cin >> d >> n;
	vector<int> ts(d), as(n), bs(n), cs(n);
	rep(i, d) cin >> ts[i];
	rep(i, n) cin >> as[i] >> bs[i] >> cs[i];

	rep(i, n) if (ts[0] < as[i] || bs[i] < ts[0]) dp[0][i] = -(1 << 29);
	REP(i, 1, d) rep(j, n)
	{
		int t = ts[i], a = as[j], b = bs[j], c = cs[j];
		if (a <= t && t <= b) rep(k, n)
		{
			dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(cs[k] - c));
		}
	}

	cout << *max_element(dp[d - 1], dp[d - 1] + n) << endl;

	return 0;
}

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

int N, M;
vector<P> G[100100];
int visited[100100];
int dist[100100];

void bfs(int s) {
    deque<int> q;
    q.pb(s);
    visited[s] = 1;
    
    while (q.size()) {
        int v = q.front(); q.pop_front();
        rep(i, G[v].size()) {
            int nv = G[v][i].first, w = G[v][i].second;
            if (visited[nv]==-1) {
                visited[nv] = 1;
                dist[nv] = dist[v]+w;
                q.pb(nv);
            }
            else {
                if (dist[nv]!=dist[v]+w) {
                    cout << "No" << endl;
                    exit(0);
                }
            }
        }
    }
}

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> M;
    rep(i, M) {
        int L, R, D; cin >> L >> R >> D;
        G[L-1].pb(P(R-1, D));
        G[R-1].pb(P(L-1, -D));
    }
    rep(i, N) visited[i] = -1;
    rep(i, N) if (visited[i]==-1) bfs(i);
    cout << "Yes" << endl;
}

Measured memory_bytes: 14848
//A to Z String

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end()
#define pb push_back
const int inf = 2147483647;

int main (){
    string s,ss;cin>>s;
    ss=s;reverse(range(ss));
    ll a = s.find("A");
    ll b = ss.find("Z");
    cout << s.size()-a-b << endl;
    return 0;
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

void priq(queue<ll>& q)
{
    cout << "=======" << endl;
    queue<ll> tmp(q);
    while(! tmp.empty()) {
        cout << tmp.front() << ' ';
        tmp.pop();
    }
    cout << "========" << endl;
}

int main()
{
    ll N, M;
    cin >> N >> M;
    vllvll Mat(N, vll(0));
    ll a, b;
    rep(i, 0, M) {
        cin >> a >> b;
        --a; --b;
        Mat[a].push_back(b);
        Mat[b].push_back(a);

    }



    int WHITE = 0;
    int GRAY = 1;
    int BLACK = 2;
    vll color(N, WHITE);
    vll dist(N, INF);
    ll start = 0;
    ll prev = 0;
    queue<ll> q;
    q.push(start);
    color[start] = GRAY;
    dist[start] = 0;

    while (! q.empty()) {
        ll node = q.front(); q.pop();
        prev = node;
        for (ll adj : Mat[node]) {
            if (color[adj] == WHITE) {
                color[adj] = GRAY;
                dist[adj] = prev;
                q.push(adj);
            }
        }
        color[node] = BLACK;
    }

    bool flg = false;
    rep(i, 1, N) {
        if (dist[i] >= (1LL<<59)) {
            flg = true;
        }
    }
    if (flg) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        rep(i, 1, N) {
            if (dist[i] == INF)
                cout << -1 << endl;
            else
                cout << dist[i]+1 << endl;
        }
    }
}

Measured memory_bytes: 13732
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

template bsearch(alias fun) {

    import std.functional: unaryFun;
    alias f = unaryFun!fun;

    int bsearch(T)(T[] arr) {
        if (arr.empty) return -1;

        if (!f(arr[0])) return -1;

        if (f(arr[$-1])) return arr.length.to!int - 1;

        int l, r = arr.length.to!int - 1;
        while (l+1 < r) {
            auto m = (l+r)/2;
            if (f(arr[m])) {
                l = m;
            } else {
                r = m;
            }
        }
        return l;
    }
}

size_t[][26] D;

void main()
{
    auto s = readln.chomp.to!(char[]);
    auto t = readln.chomp.to!(char[]);

    foreach (i, c; s) {
        D[c - 'a'] ~= i;
    }

    ulong cnt;
    size_t p;
    bool first = true;
    foreach (c; t) {
        auto d = D[c - 'a'];

        if (d.empty) {
            writeln(-1);
            return;
        }

        if (first) {
            first = false;
            if (d[0] == 0) {
                continue;
            }
        }

        if (d[$-1] <= p) {
            p = d[0];
            ++cnt;
            continue;
        } else if (d[0] > p) {
            p = d[0];
            continue;
        }

        auto l = bsearch!(i => i <= p)(d);
        p = d[l+1];
    }
    writeln(s.length * cnt + p + 1);
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define ll long long

#define for(i,a,b) for (i=a; i<b; i++)
#define forb(i,a,b) for (i=a; i>b; i--)
#define all(S) S.begin(),S.end()
#define sort(S) sort(all(S))

const int inf = 1e9+7;
const ll INF = 1e18;

int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(false);
    int n,m,i;
    cin >> n >> m;
    int l = 1;
    int r = n;
    for (i,0,m)
    {
        if (r-l==n/2 && n%2==0)
            r--;
        if (l+l-2==n/2 && n%2==0)
            r--;
        cout << l << " " << r << endl;
        l++;
        r--;
    }
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll n, m;

ll d[1100][1100]; // 結果
struct edge { ll to, cost; };
vector<edge> g[1100][1100]; //隣接リスト to, cost
void dijkstra(ll k, ll a) {
	priority_queue<P, vector<P>, greater<P> > q;
	fill(d[k], d[k] + n + 10, INF);
	d[k][a] = 0;
	q.push(P(0, a));
	while (!q.empty()) {
		P p = q.top();
		q.pop();
		ll v = p.second;
		if (d[k][v] < p.first) continue;
		REP(i, g[k][v].size()) {
			edge e = g[k][v][i];
			if (d[k][e.to] > d[k][v] + e.cost) {
				d[k][e.to] = d[k][v] + e.cost;
				q.push(P(d[k][e.to], e.to));
			}
		}
	}
}

vector<P> t;
vector<ll> s[1100], ans2;
ll st;

void dfs(ll a, ll b) {
	REP(i, s[a].size()) {
		//cout << d[st][s[a][i]] << endl;
 		if (d[st][s[a][i]] == b - 1) {
			//cout << "aaaa" << endl;
			ans2.push_back(s[a][i]);
			dfs(s[a][i], b - 1);
			break;
		}
	}
}

int main() {
	cin >> n >> m;
	REP(i, m) {
		ll a, b;
		cin >> a >> b;
		a--;
		b--;
		t.push_back(P(a, b));
		s[b].push_back(a);
	}
	ll ans = INF;
	REP(i, n) {
		REP(j, m) {
			ll a = t[j].first, b = t[j].second;
			if (b == i)g[i][a].push_back({ n, 1 });
			else g[i][a].push_back({ b, 1 });
		}
		dijkstra(i, i);
		if (ans > d[i][n]) {
			ans = d[i][n];
			st = i;
		}
	}
	if (ans == INF){
		cout << -1 << endl;
		return 0;
	}
	cout << ans << endl;
	dfs(st, ans);
	REP(i, ans2.size()) {
		cout << ans2[i] + 1 << endl;
	}
}

Measured memory_bytes: 87424
#include<stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	long int a[85];
	for(int i=0;i<n;i++){
		scanf("%ld",&a[i]);
	}
	long int s=1000;
	for(int i=0;i<n-1;i++){
		if(a[i+1]>a[i]){
			long int x;
			x=s/a[i];
			s=s%a[i]+x*a[i+1];
		}
	}
	printf("%ld",s);
}

Measured memory_bytes: 3228
import math
from functools import lru_cache
def Frog1():
    n = int(input())
    h = list(map(int,input().split(' ')))
    @lru_cache(None)
    def Solve(i):
        if i==n-1:
            return 0
        if i==n-2:
            return abs(h[i]-h[i+1])
        return min(Solve(i+1)+abs(h[i]-h[i+1]),Solve(i+2)+abs(h[i]-h[i+2]))
    dp = [0]*n
    for i in reversed(range(n)):
        if i==n-1:
            dp[i] = 0
        elif i==n-2:
            dp[i] = abs(h[i]-h[i+1])
        else:
            dp[i] = min(dp[i+1]+abs(h[i]-h[i+1]),dp[i+2]+abs(h[i]-h[i+2]))
    print(dp[0])
def Frog2():
    n,k = input().split(' ')
    n,k = int(n),int(k)
    h = list(map(int, input().split(' ')))
    @lru_cache(None)
    def Solve(i):
        if i==n-1:
            return 0
        ans = math.inf
        for j in range(1,k+1):
            new_i = i+j
            if new_i<=n-1:
                ans = min(ans , Solve(new_i)+abs(h[i]-h[new_i]))
            else:
                break
        return ans

    dp = [0]*n
    for i in reversed(range(n)):
        if i==n-1:
            dp[i] = 0
        else:
            ans = math.inf
            for j in range(1,k+1):
                new_i = i+j
                if new_i<=n-1:
                    ans = min(ans,dp[new_i]+abs(h[i]-h[new_i]))
                else:
                    break
            dp[i] = ans
    print(dp[0])

def Vacation():
    n = int(input())
    gain = []
    for i in range(n):
        a = list(map(int,input().split(' ')))
        gain.append(a)
    @lru_cache(None)
    def Solve(i,prevj):
        if i==n:
            return 0
        ans = -math.inf
        m = list({0,1,2} - {prevj})
        for j in m:
            ans = max(ans,Solve(i+1,j)+gain[i][j])
        return ans

    dp = [[0 for j in range(3)] for i in range(n+1)]
    for i in reversed(range(n+1)):
        for prevj in range(3):
            if i!=n:
                ans = -math.inf
                m = m = list({0,1,2} - {prevj})
                for j in m:
                    ans = max(ans,dp[i+1][j]+gain[i][j])
                dp[i][prevj] = ans
    print(max(dp[0]))
Vacation()

Measured memory_bytes: 103588
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 1010
#define M 5010
ll n, x[N], d[N], dp[M];
vector<ll> g[N];

void rec(ll u){
	if(g[u].size()==0){
		d[u] = 0;
		return;
	}
	for(int v: g[u]) rec(v);
	mset(dp, 0);
	dp[0] = 1;
	ll sum = 0;
	for(int v: g[u]){
		sum += x[v] + d[v];
		for(int i = x[u]; i >= 0; i--){
			dp[i] = (i>=x[v]?dp[i-x[v]]:0) | (i>=d[v]?dp[i-d[v]]:0);
		}
	}
	for(int i = x[u]; i >= 0; i--){
		if(dp[i]){
			if(sum<i) continue;
			d[u] = sum-i;
			return;
		}
	}
	d[u] = INF;
}

int main(){
	cin>>n;
	rep(i, n-1){
		ll p; cin>>p;
		g[p-1].push_back(i+1);
	}
	rep(i, n) cin>>x[i];
	rec(0);
	cout<<(d[0]<INF?"POSSIBLE":"IMPOSSIBLE")<<endl;
	return 0;
}


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

// #include<cstdio>

int main(){
  int count[5][4][11]={};
  int n, b, f, r, v;

  cin >> n;

  for (int i=0; i<n; i++){
    cin >> b >> f >> r >> v;
    count[b][f][r]+=v;
  }

  for (int i=1; i<=4; i++){
    for (int j=1; j<=3; j++){
      for (int k=1; k<=10; k++){
	cout << ' ' << count[i][j][k];
      }
      cout << "\n";
    }
    if (i<4){
      cout << "####################\n";
    }
  }

  return 0;
}

Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
#include<cassert>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

struct Mo{
  using F = function<void(int)>;
  vector<int> ls,rs,ord;
  int n,width,nl,nr,ptr;//widthは分割するバレットの幅
  F expandL,expandR;
  F shrinkL,shrinkR;

  Mo(int n,int width,F expandL,F expandR,F shrinkL,F shrinkR):
    n(n),width(width),nl(0),nr(0),ptr(0),
    expandL(expandL),expandR(expandR),
    shrinkL(shrinkL),shrinkR(shrinkR){}

  Mo(int n,int width,F expand,F shrink){
    *this=Mo(n,width,expand,expand,shrink,shrink);
  }

  void add(int l,int r){//区間[l,r)
    ls.emplace_back(l);
    rs.emplace_back(r);
  }

  void build(){
    ord.resize(ls.size());
    iota(ord.begin(),ord.end(),0);
    sort(ord.begin(),ord.end(),
         [&](int a,int b){
           if(ls[a]/width!=ls[b]/width) return ls[a]<ls[b];
           if(rs[a]==rs[b]) return ls[a]<ls[b];
           return bool((rs[a]<rs[b])^((ls[a]/width)&1));
         });
  }

  int process(){
    if(ptr==(int)ord.size()) return -1;
    const int idx=ord[ptr++];
    while(nl>ls[idx]) expandL(--nl);
    while(nr<rs[idx]) expandR(nr++);
    while(nl<ls[idx]) shrinkL(nl++);
    while(nr>rs[idx]) shrinkR(--nr);
    return idx;
  }
};



void solve(){
  int n,q;
  cin >> n >> q;
  vector<int> c(n),cnt(n),ans(q);
  rep(i,n) {
    cin >> c[i];c[i]--;
  }
  int num=0;
  auto expand=[&](int k){
    num+=cnt[c[k]]++==0;
  };
  auto shrink=[&](int k){
    num-=--cnt[c[k]]==0;
  };
  Mo mo(n,1000,expand,shrink);
  rep(i,q){
    int l,r;cin >> l >> r;l--;
    mo.add(l,r);
  }
  mo.build();
  rep(i,q){
    int k=mo.process();
    ans[k]=num;
  }
  rep(i,q){
    cout << ans[i] << "\n";
  }
}

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

Measured memory_bytes: 15652
function main(input) {
    const args = input.split(' ');
    const a = parseInt(args[0], 10);
    const b = parseInt(args[1], 10);

    if ((a * b) % 2 === 0) {
        console.log('Even');
    } else {
        console.log('Odd');
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 30564
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

using ll = long long;
using ull = unsigned long long;

int main() {
    int a;
    string s;
    cin >> a >> s;
    cout << (a < 3200 ? "red" : s) << endl;

    return 0;
}

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

int main()
{
	int N;
	cin >> N;
	N %= 10;
	if (N == 2 || N == 4 || N == 5 || N == 7 || N == 9 ) cout << "hon" << endl;
	else if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
	else cout << "bon" << endl;
	return 0;
}

Measured memory_bytes: 3620
t1, t2 = map(int, input().split())
a1, a2 = map(int, input().split())
b1, b2 = map(int, input().split())

ave_a, ave_b = t1 * a1 + t2 * a2, t1 * b1 + t2 * b2
if ave_a < ave_b:
    a1, a2, b1, b2 = b1, b2, a1, a2
    ave_a, ave_b = ave_b, ave_a

if ave_a == ave_b:
    print('infinity')
    exit()

first, second = t1 * (b1 - a1), ave_a - ave_b
ans = first // second * 2 + (first % second != 0)
print(max(0, ans))


Measured memory_bytes: 62000
#include <iostream>

using namespace std;
typedef long long ll;

const ll INF = 1e18;

int N;
ll a[55];

int main() {
        cin >> N;
        for (int i=0; i<N; i++)
                cin >> a[i];

        ll minK = INF;
        for (int K=0; K<=N; K++) {
                ll dk = 0;
                for (int i=0; i<N; i++)
                        dk += (a[i]+K+1)/(N+1);

                if (dk >= K)
                        minK = min(minK, K+(dk-K)*(N+1));
        }

        cout << minK << "\n";
}

Measured memory_bytes: 256
N = int(input())
l = [input() for i in range(N)]
mydict = {}
times = [1]*N
count = 0
value = 1

for i in range(N):
    l[i] = ''.join(sorted(l[i]))
    if l[i] in mydict.keys():
        count += times[mydict[l[i]]]
        times[mydict[l[i]]] += 1
    else:
        mydict[l[i]] = value
        value += 1
print(count)

Measured memory_bytes: 23056
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

int main(){
  ll n;
  cin>>n;
  string s;
  while(n){
    n--;
    s.push_back((char)('a'+n%26));
    n/=26;
  }
  reverse(s.begin(),s.end());
  cout<<s<<endl;
  return(0);
}

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

int N, M, Q; 
vector<vector<int>> sum;

int buildSumTable(vector<int> L, vector<int> R){
    sum = vector<vector<int>>(N + 1, vector<int>(N + 1, 0));
    for(int i=0; i<M; i++) sum[L[i]][R[i]]++;

    for(int i=1; i<=N; i++){
        for(int j=1; j<=N; j++){
            sum[i][j] += sum[i-1][j];
            sum[i][j] += sum[i][j-1];
            sum[i][j] -= sum[i-1][j-1];
        }
    }
}

int getSumRange(int L, int R){
    int ans = sum[R][R] - sum[R][L-1] - sum[L-1][R] + sum[L-1][L-1];
    return ans;
}

int main() {
    cin >> N >> M >> Q;
    vector<int> L(M), R(M);
    for(int i=0; i<M; i++) cin >> L[i] >> R[i];
    vector<int> p(Q), q(Q);
    for(int i=0; i<Q; i++) cin >> p[i] >> q[i];

    buildSumTable(L, R);

    for(int i=0; i<Q; i++){
        int ans = getSumRange(p[i], q[i]);
        cout << ans << endl;
    }
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>


#include <sstream>      // std::ostringstream
template <typename T> std::string tostr(const T& t)
{
    std::ostringstream os; os<<t; return os.str();
}

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N,K;
vector <int > D;
int c;

bool isokdisit(int a){

	do{
		int num = a % 10;
		REP(j,K)
			if(D[j] == num)
				return false;
		a = a/10;

	}while(a != 0);


	return true;
}



int main()
{

	cin >> N >> K;

	D.resize(K);

	REP(i,K){
		cin >> D[i];
	}


	while(!isokdisit(N)){
		N++;
	}
	cout << N << endl;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <stdio.h>
#include <math.h>
#include <utility>
#include <algorithm>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector<string> s(n);
	int cnt = 0;
	int fBlist = 0;
	int bAlist = 0;
	int vlist = 0;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < s[i].size() - 1; j++) {
			if (s[i][j] == 'A') {
				if (s[i][j + 1] == 'B') {
					cnt++;
				}
			}
		}
		if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A') vlist++;
		else if (s[i][0] == 'B')fBlist++;
		else if (s[i][s[i].size() - 1] == 'A')bAlist++;
	}
	if (vlist != 0) {
		cnt += vlist;
		if (fBlist + bAlist == 0) {
			cnt--;
		}
	}
	cnt += fBlist < bAlist ? fBlist : bAlist;
	cout << cnt;
	return 0;
}


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

const int MAX_SUM = 3e5;
const int INF = 1LL << 60;

signed main(void){
  
  int A,B,C,X,Y; cin >> A >> B >> C >> X >> Y;
  int ans = INF;
  for(int z = 0; z <= MAX_SUM; z += 2){ //ABピザの枚数で全探索する
    
    int x = max(X-z/2,0LL);
    int y = max(Y-z/2,0LL);
    
    ans = min(ans, x*A+y*B+z*C);
    
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	string a, b;
	cin >> a >> b;
	int n = a.length(), m = b.length();
	vector<vector<int> > dp(n+5,vector<int>(m+5));
	//int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i-1] == b[j-1]) {
				dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1);
			} else {
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
			//ans = max(ans,dp[i][j]);
		}
	}
	int x = n, y = m;
	vector<char> lcs;
	while (x > 0 && y > 0) {
		if (a[x-1] == b[y-1]) {
			lcs.emplace_back(a[x-1]);
			x--; y--;
		}
		else if (dp[x-1][y] > dp[x][y-1]) x--;
		else y--;
	}
	reverse(lcs.begin(),lcs.end());
	for (auto it: lcs) cout << it;
	return 0;
}


Measured memory_bytes: 35712
#include <cstdio>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <bits/stdc++.h>
#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

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

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());


int main() {
    unsigned int  A,B,Q;

    cin >> A>>B>>Q;
    vector<lli> s(A+2);
    vector<lli> t(B+2);
    s.front() = t.front() = -BOUND;
    s.back() = t.back()= BOUND;

    for(int i = 1; i<A+1; i++){
        cin >> s[i];
    }
    for(int i = 1; i<B+1; i++){
        cin >> t[i];
    }
    for(int i=0; i<Q; i++){
        lli key;
        cin >> key;
        auto sa = upper_bound( s.begin(), s.end(), key );
        auto sb = sa-1;

        auto tc = upper_bound( t.begin(), t.end(), key );
        auto td = tc-1;

        ll ans = min({ abs(*sa-key)+abs(*tc-*sa),
                       abs(*sa-key)+abs(*td-*sa),
                       abs(*sb-key)+abs(*tc-*sb),
                       abs(*sb-key)+abs(*td-*sb),
                       abs(*tc-key)+abs(*sa-*tc),
                       abs(*tc-key)+abs(*sb-*tc),
                       abs(*td-key)+abs(*sa-*td),
                       abs(*td-key)+abs(*sb-*td) });
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
template<typename T>
void print(T x) {
    cout << x << endl;
}
int main(void) {
    vector<int> vc(3);
    rep(i, 3) cin >> vc[i];
    sort(vc.begin(), vc.end());
    int ans = vc[2]*10 + vc[1] + vc[0];
    cout << ans;
}


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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
//~ const int mod = (int)1e9 + 7;
const int mod = 998244353;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

string conv(int a){stringstream ss;ss << a;string str = ss.str();return str;}
string conv(char a){stringstream ss;ss << a;string str = ss.str();return str;}
int conv(string a){stringstream geek(a); int x = 0; geek >> x;   return x;}


int main(void) 
{	
	int n, k; cin>> n >> k;
	double ans = 0;
	rep(i,1,n){
		int t= 0;
		int ktmp = i;
		while(ktmp < k){
			ktmp *=2;
			t++;
		}
		//cout<<(1.0/n)*1.0/pow(2.0,t)<<endl;
		ans += (1.0/n)*1.0/pow(2.0,t);
	}
	//cout<<ans;
	cout<<std::setprecision(9)<<ans<<endl;
	return 0;
} 


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

#define ld long double

using namespace std;

int main () {

    ios_base::sync_with_stdio(false);

    ld a, b, x;
    cin >> a >> b >> x;

    if(x*2 > a*a*b){
        x = a*a*b - x;
        cout << setprecision(20) << (ld) 90 /(ld) asin(1) * atan(x /a/a/a*2);
    }else{
        ld val = x/ a / b /b;
        val*=2;
        val = atan(val);

        ld pi = asin(1)*2;
        val*=90;
        val/=pi/2;
        val = 90 - val;
        cout << setprecision(20) << val;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
B = [int(x) for x in input().split()]
A = [0] * N
A[0] = B[0]
for i in range(1,N-1):
  A[i] = min(B[i-1],B[i])
A[N-1] = B[N-2]
print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin >> N;
    vel H(N); rep(i,N) cin >> H[i];

    ll maxh = H[0];
    rep(i,N) {
        if(maxh < H[i]) maxh = H[i];
        if(maxh -2 >= H[i]) {cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
import math
a, b, C = map(int, input().split())
C_radian = math.radians(C)

S = a * b * math.sin(C_radian) / 2

l = a ** 2 + b ** 2 - 2 * a * b * math.cos(C_radian)
l = math.sqrt(l) + a + b

h = b * math.sin(C_radian)

print(S)
print(l)
print(h)


Measured memory_bytes: 5708
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int wa(int x){
  int ret = 0;
  while(x){
    ret += x % 10;
    x /= 10;
  }
  return ret;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N;
  int ans = 1e9;
  FOR(a,1,N){
    int b = N - a;
    ans = min(ans, wa(a) + wa(b));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out


int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    int p,q,r;
    cin>>p>>q>>r;
    cout<<min(min(p+q,p+r),q+r)<<endl;
    
//////////////////////////////////////////////////////
return 0;}







Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long A, B, N;

  std::cin >> A >> B >> N;

  long long x = A * N / B;
  long long y = N / B * A;
  long long d = x - y, dp = d;

  long long n = N - N % B;

  x = A * n / B;
  y = n / B * A;

  dp = std::max(d = x - y, dp);
    
  if (n > 0) {
    n --;

    x = A * n / B;
    y = n / B * A;
    
    dp = std::max(d = x - y, dp);
  }

  std::cout << dp << std::endl;

  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, X, Y; cin >> N >> X >> Y;

    vector<int> D(N);
    for (int i = 1; i <= N; i++) {
        for(int j = i + 1; j <= N; j++) {
            int d = min(j - i, abs(i - X) + abs(j - Y) + 1);
            D[d]++;
        }
    }

    REP(i, 1, N) cout << D[i] << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    pair <int,int> a[n];
    for(int i = 0; i < n; i++){
        scanf("%d %d", &a[i].first, &a[i].second);
    }
    sort(a,a+n);
    int ans = n;
    int l = a[0].first + a[0].second;
    for(int i = 1; i < n; i++){
        if (l > a[i].first - a[i].second){
            l = min(l, a[i].first + a[i].second);
            ans--;
        }else{
            l = a[i].first + a[i].second;
        }
    }
    printf("%d\n", ans);
    
}

Measured memory_bytes: 896