akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

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

//scanf("%lld", &);
//cin >> ;
//cout << ans << endl;

ll N, M, K, i, j, k, l, ans, cnt = 0;

typedef struct _F{
    ll sum = 0;
    vector<ll> A;
}F;

bool fCheck(F f, ll X){
    ll i;
    REP(i, f.A.size()){
        if(f.A.at(i) < X){
            return false;
        }
    }
    return true;
}

int main(){
    //cin >> ;
    //cout << ans << endl;
    ll a, nowP, nextP, ansP;
    vector<ll> A;//町は添字に合わせる。
    // 通ってきた履歴を保存するMAP　町i, 経由数
    map<ll,ll> route;

    scanf("%lld", &N);
    scanf("%lld", &K);

    REP(i, N){
        scanf("%lld", &a);
        A.push_back(a - 1);
    }

    cnt = 0;
    nowP = 0;
    route[nowP] = cnt;//初期地点追加
    REP(i, K + 1){
        nextP = A.at(nowP);
        //次の町に行ったことがあるかどうかチェック
        if(route.find(nextP) != end(route)){
            //存在する場合　以降はループするので計算する
            //次の町へ行ってループになるので、cnt + 1 と　次の街の経由数の差がループする回数になる。
            ll notRoop = route.at(nextP);//ループしない部分で必要な回数
            ll roop = (cnt + 1) - notRoop;//ループ一周に必要な回数
            // K - notRoop = a 最低限必要な部分を引く
            // (a) % roop = ループの始点から何個経由した場所か。 →　その場所がanser
            nowP = nextP;//0回の場合用初期化 & 始点を現在位置に
            REP(j, (K - notRoop) % roop){
                nowP = A.at(nowP);
            }
            cout << (nowP + 1) << endl;//出力時、添字にならないように注意
            return 0;
        }
        
        cnt++;
        route[nextP] = cnt;
        ansP = nowP;
        nowP = nextP;//現在位置を更新
    }


    cout << (ansP + 1) << endl;//出力時、添字にならないように注意
    return 0;
}

Measured memory_bytes: 14864
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <array>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S;
    int ans=700;
    cin>>S;
    for(int i=0;i<3;i++){
        if(S[i]=='o')ans+=100;
    }
    cout<<ans<<endl;
    return 0;
}

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

int main(void) {
	int N, M;

	cin >> N;

	vector<string> Bword(N);
	for (int i = 0; i < N; i++)
	{
		cin >> Bword.at(i);
	}

	cin >> M;

	vector<string> Rword(M);
	for (int i = 0; i < M; i++)
	{
		cin >> Rword.at(i);
	}

	

	int MaxMoney = 0;
	for (int i = 0; i < N; i++)
	{
		if (Bword.at(i) == "0")
		{
			continue;
		}
		else
		{
			int count = 0;
			string esc = Bword.at(i);
			for (int j = 0; j < N; j++)
			{
				if (esc == Bword.at(j))
				{
					Bword.at(j) = "0";
					count++;
				}
			}
			for (int j = 0; j < M; j++)
			{
				if (esc == Rword.at(j))
				{
					Rword.at(j) = "0";
					count--;
				}
			}

			if (MaxMoney < count)
			{
				MaxMoney = count;
			}
		}
	}

	cout << MaxMoney << endl;

	return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n), y(n);
    int tmpx,tmpy;
    rep(i,n){
        cin >> a[i];
        rep(j,a[i]){
            cin >> tmpx >> tmpy;
            tmpx--;
            x[i].push_back(tmpx);
            y[i].push_back(tmpy);
        }
    }
    int ans = 0;
    for(int bit = 0; bit < (1 << n); ++bit ){ // 正直者を全探索
        bool isTrue = true;
        rep(i,n){
            if(bit&(1<<i)){ // 正直な場合矛盾があるか
                rep(j,a[i]){
                    if((bit&(1<<x[i][j])) != (y[i][j]<<x[i][j])){ // 矛盾
                        isTrue = false;
                        break;
                    }
                }
            }
            if(!isTrue) break;
        }
        if(isTrue){
            ans = max(ans, int(__builtin_popcount(bit)));
        }
    } 
    cout << ans << endl;
}

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

using namespace std;

int main(){
  string a, b;
  cin >> a >> b;
  if(a == b) {
    cout << "EQUAL" << endl;
  } else if(a.size() < b.size()) {
    cout << "LESS" << endl;
  } else if(a.size() > b.size()) {
    cout << "GREATER" << endl;
  } else {
    if (a < b) {
      cout << "LESS" << endl;
    } else {
      cout << "GREATER" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define int long long int 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vii vector<int>
#define mii map<int,int>
#define mod 1000000007
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define pqmin priority_queue<int,vector<int>,greater<int>>
#define pqmax priority_queue<int>
using namespace std;
int32_t main()
{
    IOS;
   int a;
   cin>>a;
   string s;
   cin>>s;
   if(a<3200){
       cout<<"red"<<endl;
   }
   else
   cout<<s<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            if (s != new string(s.Reverse().ToArray()))
            {
                Console.WriteLine("No");
                return;
            }

            string sub1 = s.Substring(0, (s.Length - 1) / 2);
            if (sub1 != new string(sub1.Reverse().ToArray()))
            {
                Console.WriteLine("No");
                return;
            }

            string sub2 = s.Substring((s.Length + 2) / 2);
            if (sub2 != new string(sub2.Reverse().ToArray()))
            {
                Console.WriteLine("No");
                return;
            }

            Console.WriteLine("Yes");
        }
    }
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  int res = 0;

  auto dfs = [&](auto& f, int cur, int d)->void{
    if (d == n) {
      res += (cur % 2 == 0);
      return ;
    }
    for (int i = -1; i <= 1; i++) {
      f(f, cur * (a[d] + i), d + 1);
    }
  };

  dfs(dfs, 1, 0);
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 3612
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] h = new int[n];

        int[] lis = new int[n];
        for(int i = 0; i < n; i++){
            h[i] = sc.nextInt();
        }

        lis[0] = 0;
        int ans = 0;
        for(int i = 1; i < n; i++){
            if(h[i - 1] >= h[i]){
                lis[i] = lis[i - 1] + 1;
                ans = Math.max(ans, lis[i]);
            } else{
                lis[i] = 0;
            }
        }

        System.out.println(ans);
        return;
    }
}

Measured memory_bytes: 59268
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ii> P;
typedef unsigned long long int ull;
const int MOD=1e9+7;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e9;

int main(){
    int n;cin>>n;
    if(n%1000==0) cout<<0<<endl;
    else cout<<1000-n%1000<<endl;
}

Measured memory_bytes: 3632
from itertools import accumulate

N, M, K = map(int, input().split())
a = [0] + list(accumulate(int(i) for i in input().split()))
b = [0] + list(accumulate(int(i) for i in input().split()))

cnt = 0
best0 = M
for i in range(N+1):
    ai = a[i]
    for j in range(best0, -1, -1):
        bj = b[j]
        if ai + bj <= K:
            cnt = max(cnt, i + j)
            best0 = j
            break

print(cnt)

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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve()
{
    string s; cin >> s;
    vector<int> v(26, 0);
    for (char c : s) ++v[c - 'a'];
    for (int c : v) if (c % 2 != 0) {
         cout << "No" << '\n';
         return;
    }
    cout << "Yes" << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3592
r,g,b,n = map(int,input().split())
l = [r,g,b]
l.sort()
count = 0
for i in range(n//l[2]+1):
    for j in range((n-l[2]*i)//l[1]+1):
        if (n-i*l[2]-j*l[1])%l[0] == 0:
            count += 1
print(count)

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

int main() {
	int d, n;
	cin >> d >> n;
	if(n==100)
		cout << (n+1) * (int)pow(100, d) << endl;
	else
		cout << n * (int)pow(100, d) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int time[] = new int[n];
        for(int i = 0; i < n; i++){
        	time[i] = sc.nextInt();
        }
        int k = sc.nextInt();
        for(int i = 0; i < k; i++){
        	int p = sc.nextInt();
            int a = time[p - 1];
            time[p - 1] = sc.nextInt();
            int sum = 0;
            for(int j = 0; j < n; j++){
            	sum += time[j];
            }
            System.out.println(sum);
            time[p - 1] = a;
        }
    }
}

Measured memory_bytes: 36384
#include <iostream>

using namespace std;
using ll = long long;

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

ll dp[105][2][5];

int main() {
  string s;
  cin >> s;
  int M;
  cin >> M;
  int n = s.size();

  dp[0][0][0] = 1;
  rep(i, n) rep(j, 2) for (int k = 0; k <= M; ++k) {
    int D = s[i] - '0';
    for (int d = 0; d <= (j ? 9 : D); ++d) {
      dp[i + 1][j || d < D][min(M + 1, (k + (d != 0)))] += dp[i][j][k];
    }
  }

  cout << dp[n][0][M] + dp[n][1][M] << endl;
  return 0;
}


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

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;
                        
vector< int > g[N];
int n, q;
ll ans[N];
void dfs(int v, int p){	
	for(auto to : g[v]){
		if(to == p)
			continue;
		ans[to] += ans[v];
		dfs(to, v);
	}
}                        
int main()
{                   
	scanf("%d%d", &n, &q);
	for(int i = 1; i < n; i++){
		int v, u;
		scanf("%d%d", &v, &u);
		g[v].pb(u);
		g[u].pb(v);
	}
	for(int i = 1; i <= q; i++){
		int v, x;
		scanf("%d%d", &v, &x);
		ans[v] += x;
	}
	dfs(1, 1);
	for(int i = 1; i <= n; i++)
		printf("%lld ", ans[i]);
	return 0;
}



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

int main(int argc, char *argv[])
{
    int H, W;

    for (;;) {
        scanf("%d%d", &H, &W);
        if ((H == 0) && (W == 0)) {
            break;
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (i % 2 == j % 2) {
                    printf("#");
                } else {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }

    return 0;
}


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

int main(){
    vector<int> data={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int K;
    cin >> K;
    cout << data.at(K-1) << endl;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP2(i,n,s) for(int i=(int)s;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int n;cin>>n;
    map<ll, int> map;
    REP(i,n) {
        int a;cin>>a;
        map[a]++;
    }

    int res = 0;
    FOR(i,map){
        if((i->second)%2==1) res++;
    }

    cout << res << endl;
}


Measured memory_bytes: 6528
#include <iostream>
int main(void) {
    int a;
    a=0;
    std::string s;
    std::cin>>s;
    for(int i=0;i<4;i++){
        if(s[i]=='+'){
            a=a+1;
        } else if(s[i]=='-'){
            a=a-1;
        }
        else {return 0;}
    }
    std::cout<<a<<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a == b){
        printf("a == b\n");
    }else if(a < b){
        printf("a < b\n");
    }else{
        printf("a > b\n");
    }
    return 0;
}


Measured memory_bytes: 2068
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int K = sc.nextInt();
		
		int ans = 0;
		if(K>1) {
			ans = N - K;
		}else {
			ans = 0;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 22868
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = i+1; j <= N; j++) {
			int box = i ^ j;
			int ret = 1;
			while (box) {
				if (box & 1) {
					cout << ret << " ";
					break;
				}
				box >>= 1;
				ret++;
			}
		}
		cout << endl;
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s=="SUN"){cout<<"7"<<endl;
    }else if(s=="MON"){cout<<"6"<<endl;
    }else if(s=="TUE"){cout<<"5"<<endl;
    }else if(s=="WED"){cout<<"4"<<endl;
    }else if(s=="THU"){cout<<"3"<<endl;
    }else if(s=="FRI"){cout<<"2"<<endl;
    }else if(s=="SAT"){cout<<"1"<<endl;}
    return 0;
}

Measured memory_bytes: 256
h, w, n = map(int,input().split())
sr, sc = map(int,input().split())
s = input()[::-1]
t = input()[::-1]

#安全な範囲を考える
l = 1
r = w
u = 1
d = h

if s[0] == "L":
    l += 1
elif s[0] == "R":
    r -= 1
elif s[0] == "U":
    u += 1
else:
    d -= 1
for i in range(1,n):
    if t[i] == "L":
        r = min(r+1,w)
    elif t[i] == "R":
        l = max(l-1,1)
    elif t[i] == "U":
        d = min(d+1,h)
    else:
        u = max(u-1,1)
    if s[i] == "L":
        l += 1
    elif s[i] == "R":
        r -= 1
    elif s[i] == "U":
        u += 1
    else:
        d -= 1
    if l > r or u > d:
        print("NO")
        exit()

if l <= sc and sc <= r and u <= sr and sr <= d:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 3888
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

#include<vector>
template<typename T>
void div(vector<T> &vec,T n)
{
	for(T i=1;i*i<=n;i++)
	{
		if(n%i==0)
		{
			vec.push_back(i);
			if(/*i!=1 && */i*i!=n)
				vec.push_back(n/i);
		}
	}
	return;
}

lint N,K;
lint A[510];
lint sum;

bool check(lint d)
{
	lint r[510]={};
	for(int i=1;i<=N;i++)
		r[i]=A[i]%d;
	sort(r+1,r+N+1);

	lint lsum[510]={};
	lint rsum[510]={};
	for(int i=1;i<=N;i++)
		lsum[i]=lsum[i-1]+r[i];
	for(int i=N;i>=1;i--)
		rsum[i]=rsum[i+1]+d-r[i];

	for(int i=1;i<N;i++)
	{
		if(lsum[i]==rsum[i+1] && lsum[i]<=K)
			return true;
	}

	return false;
}

int main()
{

	cin >> N >> K;
	for(int i=1;i<=N;i++)
	{
		cin >> A[i];
		sum+=A[i];
	}

	vector<lint> divs;
	div(divs,sum);

	lint ans=1;
	for(auto&& i:divs)
	{
		if(ans>i)continue;
		if(check(i))
			ans=max(ans,i);
	}

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


Measured memory_bytes: 256
N , M = map(int,input().split())
L = []
transit1 = set()
transit2 = set()
for _ in range(M):
    t = tuple(map(int,input().split()))
    L.append(t)
for x in L :
    if x[1] == N:
        transit1.add(x[0])
    if x[0] == 1:
        transit2.add(x[1])
if transit1 & transit2 == set():
    print("IMPOSSIBLE")
else:
    print("POSSIBLE")


Measured memory_bytes: 37160
# import sys
# readline = sys.stdin.readline
# generator = (readline().strip() for _ in range(N))

# N, M = map(int, input().split())
# As = list(map(int, input().split()))
# queries = (input() for _ in range(N))


def solve():
    N, M = input().split()

    n = int(N)
    f = float(M)
    m = int(f * 100 + 0.1)
    ans = n * m // 100

    return ans


def main():
    print(solve())


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define H_MAX 50
#define W_MAX 50

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

namespace patch {
  template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
}
int answer = 0;

bool check_all_visited(bool* visited, int num) {
  rep(i,num){
    if(visited[i] == true)
      continue;
    else
      return false;
  }
  return true;
}
void dfs(int v, bool *visited, bool hoge[][8], int m) {
  if (check_all_visited(visited, m) == true) {
    answer += 1;
    return;
  } else {
    rep(i,m) {
      if(hoge[v][i] == true && visited[i] == false) {
	visited[i] = true;
	dfs(i, visited, hoge, m);
	visited[i] = false;
      }
    }
    return;
  }
}
  

int main() {
  int n,m;
  vector<pii> p_vec;
  pii p;
  cin >> n >> m;
  bool hoge[n][8];
  rep(i,n) {
    rep(j,n) {
      hoge[i][j] = false;
    }
  }
  rep(i,m) {
    cin >> p.fi >> p.se;
    p_vec.pb(p);
    hoge[p.fi-1][p.se-1] = true;
    hoge[p.se-1][p.fi-1] = true;
  }

  bool visited[8];
  rep(i,n) {
    visited[i] = false;
  }
  visited[0] = true;
  dfs(0, visited, hoge, n);

  cout << answer << endl;

  return 0;
}
 

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
n, q = map(int, input().split())
cnt = [0] * n
tree = [[] for i in range(n)]
for i in range(n - 1):
    a, b = map(int, input().split())
    tree[a - 1].append(b - 1)
    tree[b - 1].append(a - 1)

for i in range(q):
    p, x = map(int, input().split())
    cnt[p - 1] += x

def dfs(cur, par):
    for chi in tree[cur]:
        if chi == par:
            continue
        cnt[chi] += cnt[cur]
        dfs(chi, cur)
dfs(0, -1)
print(*cnt)

Measured memory_bytes: 230932
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>

using namespace std;

using ll = long long;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)
#define FOR(i, a, b) for(long long i = (a);i < (b); ++i)

static int mod = 1000000007;

int N;
ll vote[1000][2];
ll k, j, A, B;

int main() {
	cin >> N >> A >> B;
	rep(i, N - 1) {
		cin >> k >> j;
		ll mul = max((A - 1) / k, (B - 1) / j) + 1;
		A = mul * k;
		B = mul * j;
	}
	cout << A + B << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#include <cassert>
#define maxn 100005
using namespace std;
typedef long long ll;
const int LEN = 100000;

struct fastio{
  char s[LEN + 5]; int len,it;
  fastio(){
    it = len = 0;
  }
  char get(){
    if(it < len) return s[it++];
    it = 0, len = fread(s,1,LEN,stdin);
    return len ? s[it++] : EOF;
  }
  bool notend(){
    char c;
    for(c = get();c == ' ' || c == '\n';c = get());
    if(it) it--;
    return c != EOF;
  }
  void put(char c){
    if(len == LEN) fwrite(s,1,LEN,stdout), len = 0;
    s[len++] = c;
  }
  void flush(){
    fwrite(s,1,len,stdout);
    len = 0;
  }
}buff,bufo;
inline ll getll(){
  char c; ll res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get())
    res = (res << 3) + (res << 1) + (c - '0');
  return sig * res;
}
inline int getint(){
  char c; int res = 0, sig = 1;
  for(c = buff.get();c < '0' || c > '9';c = buff.get()) if(c == '-') sig = -1;
  for(;c >= '0' && c <= '9';c = buff.get())
    res = (res << 3) + (res << 1) + (c - '0');
  return sig * res;
}
inline void putll(ll x){
  if(!x) bufo.put('0');
  else if(x < 0) bufo.put('-'), x = -x;
  char s[25]; int k = 0;
  while(x){
    s[++k] = x % 10 + '0';
    x /= 10;
  }
  for(int i = k;i >= 1;i--) bufo.put(s[i]);
}
inline void putint(int x){
  if(!x) bufo.put('0');
  else if(x < 0) bufo.put('-'), x = -x;
  char s[15]; int k = 0;
  while(x){
    s[++k] = x % 10 + '0';
    x /= 10;
  }
  for(int i = k;i >= 1;i--) bufo.put(s[i]);
}
int n,m;
vector <int> adj[maxn];
int dfn[maxn],ind;
int dfs(int u,int f){
  dfn[u] = ++ind;
  int cnt = 0, to1 = 0;
  for(int i = 0;i < (int)adj[u].size();i++){
    int v = adj[u][i];
    if(v == f) continue;
    if(!dfn[v]){
      if(dfs(v,u)){
        cnt++;
        if(cnt == 1) to1 = v;
        else if(cnt == 2){
          printf("%d %d\n",u,to1);
          printf("%d %d\n",u,v);
          cnt = 0;
        }
      }
    }else if(dfn[u] > dfn[v]){
      cnt++;
      if(cnt == 1) to1 = v;
      else if(cnt == 2){
        printf("%d %d\n",u,to1);
        printf("%d %d\n",u,v);
        cnt = 0;
      }
    }
  }
  if(cnt){
    printf("%d %d\n",u,f);
    printf("%d %d\n",u,to1);
    return 0;
  }
  return 1;
}
int main(){
  n = getint(), m = getint();
  for(int i = 1;i <= m;i++){
    int u = getint(), v = getint();
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if(m & 1){
    puts("-1");
    return 0;
  }
  dfs(1,-1);
  return 0;
}


Measured memory_bytes: 15104
n=gets.to_i
ans=n
(n+1).times do |i|
  count=0
  t=i
  while t>0
    count+=t%6
    t/=6
  end
  t=n-i
  while t>0
    count+=t%9
    t/=9
  end
  ans=count if ans>count
end
puts ans


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

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

void solve() 
{
    int n;cin>>n;
    REP(i,n){
        int x;cin>>x;
        if(x%2==0){
            if(x%3!=0&&x%5!=0){cout<<"DENIED"<<endl;return;}
        }
    }
    cout<<"APPROVED"<<endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()
const int INF = 1e9;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PII;

/* struct P {
	int x, y, n;
	P(int n, int x, int y):n(n), x(x), y(y){}
	P(){}
}; */


/** Problem2155 : Infected Computer **/
struct E {
	int t, s, d;
	E(int t_, int s_, int d_):t(t_), s(s_), d(d_){}
	E(){}
};

bool cmp(const E &a, const E &b)
{
	return a.t < b.t;
}

const int MAX = 20000;

int main()
{
	int N, M;
	while (cin>>N>>M, N||M) {
		set<int> infected;
		vector<E> ls(M);
		
		infected.insert(0);
		
		rep(i, M) {
			cin>>ls[i].t>>ls[i].s>>ls[i].d;
			ls[i].s--, ls[i].d--;
		}
		sort(ALL(ls), cmp);
		
		int now = -1;
		vector<int> tmp;
		rep(i, M) {
			if (now != ls[i].t) {
				rep(j, tmp.size()) infected.insert(tmp[j]);
				tmp.clear();
				now = ls[i].t;
			}
			
			if (infected.count(ls[i].s)) {
				tmp.push_back(ls[i].d);
			}
		}
		rep(j, tmp.size()) infected.insert(tmp[j]);
		
		cout << infected.size() << endl;
	}
}

Measured memory_bytes: 2236
#include <bits/stdc++.h>
using namespace std;
#define ld long long double
#define ll long long
#define mod 1000000007
#define scl(x) scanf("%lld",&x)
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}

ll power(ll a,ll b) {
    ll res=1LL;
    while(b>0){
        if(b&1) res = mul(res,a);
        b/=2;
        a = mul(a,a);
    }
    return res%mod;
}


int main(){
    ll n,k;
    cin >> n >> k;
    ll cnt=0;
    for(ll i=0;i<n;i++) {
        ll a;
        cin >> a;
        if(a >= k)cnt++;
    }
    cout << cnt << endl;
}

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

int main() {
	int m,f,r;
	for(;cin>>m>>f>>r;)
	{
		if(m==-1&&f==-1&&r==-1)break;
		else if(m==-1||f==-1)cout<<"F"<<endl;
		else if(m+f>=80)cout<<"A"<<endl;
		else if(m+f>=65)cout<<"B"<<endl;
		else if(m+f>=50)cout<<"C"<<endl;
		else if(m+f>=30&&r>=50)cout<<"C"<<endl;
		else if(m+f>=30)cout<<"D"<<endl;
		else cout<<"F"<<endl;
	}
	return 0;
}

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

int main() {
    int N,result,before;
    int* a;
    int* b;
    int* c;
    cin >> N;
    a = new int[N];
    b = new int[N];
    c = new int[N];

    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    for(int i=0;i<N-1;i++){
        cin >> c[i];
    }
    before=0;
    result=0;
    for(int i=0;i<N;i++){
        result+=b[a[i]-1];
        //cout << "test " << result << endl;

        if(before==(a[i]-1)){
            result+=c[a[i]-1-1];
            //cout << "test " << result << endl;

        }
        before=a[i];
    }
    cout << result << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define MAX 100
#define int long long
using namespace std; 
  
void printString(int n) 
{ 
    char str[MAX];
    int i = 0;
  	while (n > 0) 
    { 
         int rem = n % 26; 
  		if (rem == 0) 
        { 
            str[i++] = 'z'; 
            n = (n / 26) - 1; 
        } 
        else 
        { 
            str[i++] = (rem - 1) + 'a'; 
            n = n / 26; 
        } 
    } 
    str[i] = '\0'; 
  	reverse(str, str + strlen(str)); 
    cout << str << endl; 
  	return; 
} 
  
 
int32_t main() 
{ 
	int N;
	cin>>N;
    printString(N); 
    return 0; 
}

Measured memory_bytes: 3604
{
  const process = (a: number, p: number): number => {
    const kakera = a * 3 + p
    return Math.floor(kakera / 2)
  }

  const Main = (input: string): string => {
    const a: string[] = input.split(" ")
    const na: number[] = a.map((e) => parseInt(e))

    const res = process(na[0], na[1]) + ""
    console.log(res)
    return res
  }
  Main(require("fs").readFileSync("/dev/stdin", "utf8"))
}


Measured memory_bytes: 7372
#!/usr/bin/env python3
#dp4 #Knapsack 1

def d():
    n,W = map(int,input().split())
    #縦:品物　横:重さ
    dp = [[0]*(W+1) for _ in range(n+1)]
    #dp[i][j]:i個の品物があり、容量jのときの価値の最大値
    wv = [list(map(int,input().split())) for _ in range(n)]

    for i in range(1,n+1):
        for j in range(1,W+1):
            #i番目の品物を用いるとき
            #i番目の品物の重さより容量が小さいとき(i番目の品物を使えないとき)
            if j < wv[i-1][0]:
                #i-1番目の品物までを用いたときと価値は同じ
                dp[i][j] = dp[i-1][j]
            else:#i番目の品物を使えるとき
                #i番目の品物を用いるか用いないか
                #i-1番目までの品物を用いたときの価値とi-1番目までの品物にi番目の品物を加えたときを比較
                dp[i][j] = max(dp[i-1][j],dp[i-1][j - wv[i-1][0]] + wv[i-1][1])
    print(dp[n][W])

if __name__ == '__main__':
    d()


Measured memory_bytes: 118512
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string.h>
#include <iostream>
#include <vector>
using namespace std;

struct UF {
    vector<int> data;
    UF(int n) {
        data.resize(n, -1);
    }
    int root(int i) {
        return data[i] < 0 ? i : data[i] = root(data[i]);
    }
    int size(int i) {
        i = root(i);
        return -data[i];
    }
    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y) return;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
    }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
};


int N,K,L;
int tree[200000];
int rnk[200000];

int main() {
  cin >> N >> K >> L;
  int p[K], q[K], r[L], s[L];
  UF a(N), b(N);
  for (int i = 0; i < K; i++){
    int p, q;
    cin >> p >> q;
    p--;q--;
    a.unite(p, q);
  }
  for (int i = 0; i < L; i++){
    int p, q;
    cin >> p >> q;
    p--;q--;
    b.unite(p, q);
  }

  map<pair <int, int>, int> m;
  for ( int i = 0; i < N; i++) {
    pair<int, int> p(a.root(i), b.root(i));
    m[p]+= 1;
  }

  for (int i = 0; i < N; i++) {
    if (i != 0) cout << ' ';
    pair<int, int> p(a.root(i), b.root(i));
    cout << m[p];
  }
}


Measured memory_bytes: 13568
import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main 
{
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		int a=ni(),b=ni();
		char[][] hola=new char[100][100];
		for(int i=0; i<50; i++)
			for(int j=0; j<100; j++)
			{
				hola[i][j]='.';
			}
		for(int i=50; i<100; i++)
			for(int j=0; j<100; j++)
			{
				hola[i][j]='#';
			}
		a--;
		b--;
		for(int i=0; i<a; i++)
		{
			hola[51+2*(i/50)][(2*i)%100]='.';
		}
		for(int i=0; i<b; i++)
		{
			hola[2*(i/50)][(2*i)%100]='#';
		}
		pr("100 100");
		for(int i=0; i<100; i++)
		{	
			for(int j=0; j<100; j++)
				p(hola[i][j]);
			pr();
		}
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 24916
import math
a, b = map(int, input().split())
if ((a + 1)* 12.5 - 1 - b * 10) * (a * 12.5 - (b + 1) * 10 + 1)> 0:
    print(-1)
    exit()
print(max(math.ceil(a * 12.5), b * 10))

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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int  N = sc.nextInt();
        long[][] s = new long[N][3];
        for(int i = 0; i < N; i++){
            s[i][0] = sc.nextLong();
            s[i][1] = sc.nextLong();
            s[i][2] = s[i][0] + s[i][1];
        }
        Arrays.sort(s, (x, y) -> Long.compare(y[2], x[2]));
        long ans = 0;
        for(int i = 0; i < N; i++){
            if(i % 2 == 0) ans += s[i][0];
            else ans -= s[i][1];
        }

        System.out.println(ans);
        sc.close();
    }

}


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

void solve(){
	int n;
	cin >> n;
	int arr[4] = {0};
	string s;
	for(int i =0; i < n; i++){
		cin >> s;
		if(s == "AC") arr[0]++;
		else if(s == "WA") arr[1]++;
		else if(s == "TLE") arr[2]++;
		else arr[3]++;
	}
	cout << "AC x "<< arr[0] << endl;
	cout << "WA x "<< arr[1] << endl;
	cout << "TLE x "<< arr[2] << endl;
	cout << "RE x "<< arr[3] << endl;

}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
		
	int t = 1;

	while(t--){
		solve();
	}

	return 0;
}

Measured memory_bytes: 3584
a,b,c,d,r=map(int,input().split())

if a>0:
	if c<0:
		print("No")
		exit()

if a<0:
	if c>0:
		print("No")
		exit()		

if b>0:
	if d<0:
		print("No")
		exit()

if b>0:
	if d<0:
		print("No")
		exit()

a=abs(a)
b=abs(b)
c=abs(c)
d=abs(d)

a-=r*2
b-=r*2
c-=r
d-=r

if 0<=c and 0<=d and 0<=a and 0<=b and c<=a and d<=b:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 7692
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c, t;
    cin >> a >> b >> c;
    
    // a <= b ???
    if(a > b) {
        t = b;
        b = a;
        a = t;
    // b <= c ???
    } 
    if (b > c) {
        t = c;
        c = b;
        b = t;
    } 
     // a <= b ???
    if(a > b) {
        t = b;
        b = a;
        a = t;
    }
    
    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 3092
S = input()
for i in range(len(S)):
    for j in range(i,len(S)+1):
        if S[:i]+S[j:] == "keyence":
            print("YES")
            exit()
for k in range(len(S)):
    if S[i::i+8] == "keyence":
        print("YES")
        exit()
print("NO")

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

using namespace std;

const int N = 100005;

int main() {
    
    int n;
    cin >> n;
    
    set<string> vis;
    string last;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        if (vis.find(s) != vis.end()) {
            cout << "No\n";
            return 0;
        }
        
        if (i > 1 && s[0] != last.back()) {
            cout << "No\n";
            return 0;
        }
        vis.insert(s);
        last = s;
    }
    
    printf("Yes\n");
    
    return 0;
}

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

template <typename T> T load() { T r; cin >> r; return r; }
template <typename T> vector<T> loadMany(int n) { vector<T> rs(n); generate(rs.begin(), rs.end(), &load<T>); return rs; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    auto n = load<int>();
    auto w = load<int>();
    auto m = n*1000;
    auto dyn = vector<long long>(m+1, numeric_limits<long long>::max()/2);
    dyn[0] = 0ll;
    for (auto i=0; i<n; ++i) {
        auto weight = load<int>();
        auto value = load<int>();
        for (auto j=m; j-value>=0; --j)
            dyn[j] = min(dyn[j], dyn[j-value] + weight);
    }
    for (auto r=m; r>=0; --r) {
        if (dyn[r] <= w) {
            cout << r << '\n';
            break;
        }
    }
}


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    string s ;
    cin >> s ;

    if ( s == "ARC" ) cout << "ABC" ;
    else cout << "ARC" ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i = 1 ; i <= t ; i ++ )
    {
        solve ( i ) ;
    }

    return 0;
}


Measured memory_bytes: 3624
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean bl = true;
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt();
            n -= a;
            if (n < 0) {
                bl = false;
                break;
            }
        }
        System.out.println(bl?n:-1);
    }
}


Measured memory_bytes: 46176
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v.push_back(x);
    }

    // x coordinates delta between collided cylinder which radius are a and b
    auto delta = [](double a, double b) {
        // d^2 + (b  - a)^2 = (b + a)^2
        // d = sqrt((b + a)^2 - (b - a)^2)
        // d = sqrt(4 * a * b)
        return 2 * sqrt(a * b);
    };

    double sum_ = 0;
    vector<double> cylinderXCoordinates;
    for (int i = 0; i < v.size(); ++i) {
        // first, collided with left wall
        double max_ = v[i];
        // find rightmost cylinder x coordinates
        for (int j = i - 1; j >= 0; --j) {
            auto d = cylinderXCoordinates[j] + delta(v[j], v[i]);
            max_ = max(max_, d);
        }
        cylinderXCoordinates.push_back(max_);
        sum_ = max(sum_, max_ + v[i]);
    }
    printf("%.8f\n", sum_);
}


Measured memory_bytes: 3272
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut four = 0;
    let mut two = 0;
    let mut other = 0;
    for &i in a.iter() {
        if i % 4 == 0 {
            four += 1;
        } else if i % 2 == 0 {
            two += 1;
        } else {
            other += 1;
        }
    }
    if two > 0 {
        other += 1;
    }
    if other <= four + 1 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 6396
/*
 * Author:heroming
 * File:heroming.cpp
 * Time:2016/12/18 20:05:44
 */
#include <vector>
#include <list>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;

#define px first
#define py second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define clr(v, e) memset(v, e, sizeof(v))
#define rep(it, v) for (auto it : v)
#define forn(i, n) for (int i = 0; i < (n); ++ i)
#define rforn(i, n) for (int i = (n) - 1; i >= 0; -- i)
#define form(i, a, b) for (int i = (a); i <= (b); ++ i)
#define rform(i, a, b) for (int i = (b); i >= (a); -- i)
#define forv(i, v) for (int i = 0; i < sz(v); ++ i)
#define iter(it, v) for (auto it = v.begin(); it != v.end(); ++ it)

typedef long long lint;
typedef vector<int> vint;
typedef vector<string> vstring;
typedef pair<int, int> pint;
typedef vector<lint> vlint;
typedef vector<pint> vpint;

const int maxn = 100010;
const lint mod = 1e9 + 7;

int n, x;
int cnt[maxn];

lint power(lint w, lint m) {
    lint ret = 1, e = w;
    while (m) {
        if (m & 1) ret = ret * e % mod;
        m >>= 1;
        e = e * e % mod;
    }
    return ret;
}

int main() {
    while (scanf("%d", &n) != EOF) {
        clr(cnt, 0);
        forn (i, n) {
            scanf("%d", &x);
            ++ cnt[x];
        }
        bool valid = 1;
        if (n & 1) {
            if (cnt[0] != 1) {
                valid = 0;
            } else {
                for (int i = 2; i <= n - 1; i += 2) {
                    if (cnt[i] != 2) {
                        valid = 0;
                        break;
                    }
                }
            }
        } else {
            for (int i = 1; i <= n - 1; i += 2) {
                if (cnt[i] != 2) {
                    valid = 0;
                    break;
                }
            }
        }
        if (valid) {
            printf("%I64d\n", power(2, n >> 1));
        } else {
            printf("0\n");
        }
    }
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std ;
int main()
{
	char x;
	int a ,b ;
	cin>>a>>x>>b;
	switch (x)
	{
	case '+':
		cout<<a+b;
		break;
	case '-':
		cout<<a-b;
		break;
	}

return 0 ;
}


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

string s[1001];
int memo[1001][1001];
int n;

int calcWidth(int x, int y){
	int result = 1;
	if(s[y][x] == '*') return 0;
	if(x+1 < n) result += memo[y][x+1]; 
	return result;
}

int solve(int x, int y){
	int result = 0;
	int minWidth = 9999;
	for (int i = y; i < n; i++) {
		minWidth = min(minWidth, memo[i][x]);
		if(minWidth < i-y+1) break;
		result = i-y+1;
	}
	return result;
}

int main(){
	string tmp;
	int ans;
	while (getline(cin, tmp)) {
		n = atoi(tmp.c_str());
		if(n == 0) break;
		for (int i = 0; i < n; i++) {
			getline(cin, s[i]);
		}
		for (int y = 0; y < n; y++) {
			for (int x = n-1; x >= 0; x--) {
				memo[y][x] = calcWidth(x, y);
			}
		}
		ans = 0;
		for (int y = 0; y < n; y++) {
			for (int x = 0; x < n; x++) {
				ans = max(ans, solve(x, y));
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
void print() { cout << "\n"; }
template <class T> void print(const T &x) { cout << x << "\n"; }
template <class T, class... Args> void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
template <class T> void printVector(const vector<T> &v) {
    for(const T &x : v) {
        cout << x << " ";
    }
    cout << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int s, w;
    cin >> s >> w;
    print(w >= s ? "unsafe" : "safe");
}

Measured memory_bytes: 3652
class queue():

    data = []
    cnt = 0

    def __init__(self):
        self.cnt = 0

    def add(self, a):
        self.data.append(a)

    def get(self):
        target = self.data[self.cnt]
        self.cnt += 1
        return target


buf = queue()

n, q = map(int, input().split())
for _ in range(n):
    name, time = input().split()
    time = int(time)

    buf.add([name, time])

finished = []
now = 0
while True:
    name, time = buf.get()
    if time - q > 0:
        buf.add([name, time-q])
        now += q
    else:
        finished.append([name, now+time])
        now += time

    if len(buf.data) == buf.cnt:
        break

for i in finished:
    print(i[0], i[1])


Measured memory_bytes: 34604