akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  char c;
  cin >> c;
  if (c=='A') cout << 'T' << endl;
  else if (c=='T') cout << 'A' << endl;
  else if (c=='G') cout << 'C' << endl;
  else cout << 'G' << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

	int N;
	cin >> N;
	int res = 0;
	rep(i, 0, N) {
		int tmp;
		cin >> tmp;
		res += (tmp - 1);
	}
	cout << res << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
const int N=1e4+5,M=1e9+7;
const ull base=13331;
const double Pi=acos(-1.0);
const ll C=299792458;
int main(){
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
		cout<<max(a+b,max(2*a-1,2*b-1))<<endl;;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    if(A>=K){
        A = A - K;
        K = 0;
    }else{
        K -= A;
        A = 0;
    }
    if(B>=K){
        B = B - K;
        K = 0;
    }else{
        K -= K;
        B = 0;
    }

    printf("%ld %ld\n", A, B);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string str;
    cin >> str;
    string copy;
    int m;
    cin >> m;
    for(int i=0;i<m;i++){
        string a;
        cin >> a;
        if(a=="print"){
            int x,y;
            cin >> x >> y;
            cout << str.substr(x,y-x+1) << endl;
        }
        if(a=="replace"){
            int p,q;
            cin >> p >> q;
            string r;
            cin >> r;
            str.replace(p,q-p+1,r);
        }
        if(a=="reverse"){
            copy=str;
            int s,t;
            cin >> s >> t;
            for(int j=s;j<=t;j++){
                str.at(j)=copy.at(t-j+s);
            }
        }
    }
}


Measured memory_bytes: 3192
n, x = map(int, input().split())
lst = list(map(int, input().split()))
for i in range(n):
  lst[i] = abs(lst[i]-x)

from fractions import gcd # gcd(a, b) で a, b の最大公約数を求める

def gcds(List): #list[a[0], a[1], ... , a[n]]の最大公約数を求める
  if len(List) == 1:
    return List[0]
  ans = gcd(List[0], List[1])
  for i in range(2, len(List)):
    ans = gcd(ans, List[i])
  return ans

print(gcds(lst))

Measured memory_bytes: 82708
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	ll n;
	cin >> n;
	if(n>=30)
		cout << "Yes\n" ;
	else
		cout << "No\n" ;
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3648
#include <stdio.h>

#define MAX_N 100
#define INF 1e9

int head,tail,que[MAX_N];

void push(int);
int pop(void);
int isEmpty(void);

int main(){
  int n,u,k,v,i,j,dist[MAX_N];
  int G[MAX_N][MAX_N];
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    for(j = 0 ; j < n ; j++){
      G[i][j] = 0;
    }
    que[i] = -1;
    dist[i] = INF;
  }
  for(i = 0 ; i < n ; i++){
    scanf("%d%d",&u,&k); u--;
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v); v--;
      G[u][v] = 1;
    }
  }
  head = tail = 0;
  dist[0] = 0;
  push(0);
  while(!isEmpty()){
    int v = pop();
    for(i = 0 ; i < n ; i++){
      if(G[v][i] == 0){ continue; }
      if(dist[v] + 1 < dist[i]){
        dist[i] = dist[v] + 1;
        push(i);
      }
    }
  }
  for(i = 0 ; i < n ; i++){
    printf("%d %d\n",i+1,(dist[i] == INF ? -1 : dist[i]));
  }
  return 0;
}

void push(int x){
  que[tail%MAX_N] = x;
  tail++;
}

int pop(){
  int res = que[head%MAX_N];
  que[head%MAX_N] = -1;
  head++;
  return res;
}

int isEmpty(){
  return (head == tail);
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define db2(a,b) cout << a << " " << b << endl
#define dbp(a) cout << a.first << " " << a.second << endl
#define adb(a) for(auto i:a) cout << i << " "; cout << endl
#define adb2(a) for(auto i:a) cout << i.first << " " << i.second << endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define N 100010
using namespace std;

vector< vector<int> > graph;
bool vis[N] = {false};
map<int, int> cnt;
long long h[N];

void dfs(int v)
{
    vis[v] = true;
    cnt[h[v]]++;

    for(auto x:graph[v])
        if(!vis[x])
            dfs(x);
}

int main()
{
    fastIO;
    long long n, m;
    cin >> n >> m;

    long long i;
    for(i=0;i<n;i++) cin >> h[i];

    graph.resize(n);
    long long x, y;
    for(i=0;i<m;i++)
    {
        cin >> x >> y;
        x--, y--;

        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    long long ans = 0, mx;
    for(i=0;i<n;i++)
    {
        mx = 0;
        for(auto x:graph[i]) mx = max(mx, h[x]);
        if(h[i] > mx) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 9248
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.BigInteger;
public class Main
{
    public static void main(String[]args)
    {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Solver solver = new Solver();
        int ca = 1;
        solver.solve(ca,in,out);
        out.close();
    }
    static class Solver
    {

        public void solve(int ca,InputReader in,PrintWriter out)
        {
            while(ca -- != 0)
            {
                int cnt[] = new int[10];
                for(int i = 0;i<4;i++)
                {
                    cnt[in.nextInt()]++;
                }
                if(cnt[1] == 1 && cnt[9] == 1 && cnt[7] == 1 && cnt[4] == 1)
                {
                    out.print("YES");
                }
                else
                {
                    out.println("NO");
                }

            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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 BigInteger nextBigInteger()
        {
            return new BigInteger(next());
        }

    }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define inf 100000000000
using namespace std;

long long dis[310][310];
long long End[310][310];

int main(){
    int n,m,l;
	scanf("%d %d %d",&n,&m,&l);
	for(int i=1; i<=n; i++)
	    for(int j=1; j<=n; j++) dis[i][j]=inf,End[i][j]=inf;
	for(int i=1; i<=m; i++){
		int x,y,z;
		scanf("%d %d %d",&x,&y,&z);
		dis[x][y]=dis[y][x]=z;
	}
	for(int i=1; i<=n; i++)
	    for(int j=1; j<=n; j++){
	    	for(int k=1; k<=n; k++){
	    		dis[j][k]=min(dis[j][k],dis[j][i]+dis[i][k]);
			}
		}
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++) if(dis[i][j]<=l) End[i][j]=1;
	}
	for(int i=1; i<=n; i++)
	    for(int j=1; j<=n; j++)
	       for(int k=1; k<=n; k++){
	       	    End[j][k]=min(End[j][k],End[j][i]+End[i][k]);
		   }
	int q;
	scanf("%d",&q);
	while(q--){
		int x,y;
		scanf("%d %d",&x,&y);
		if(End[x][y]!=inf) printf("%ld\n",End[x][y]-1);
		else printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define mod 1000000007
#define db(a) cout << a << endl
#define adb(a) for(auto i:a) cout << i << " "
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 200010
using namespace std;

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

    cout << (s[0] == t[0]) + (s[1] == t[1]) + (s[2] == t[2]) << endl;
}

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

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			String[] se = s.split(" ");
			int in1 = Integer.valueOf(se[0]);
			int in2 = Integer.valueOf(se[1]);
			int in3 = Integer.valueOf(se[2]);
			if (in1 == 0 && in2 == 0 && in3 == 0)
				break;
			doMain(++inCnt, in1, in2, in3);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int in1, int in2, int in3) {
		int f = 0;
		for (int i = in1; i <= in2; i++)
			if ((in3 % i) == 0)
				f++;

		System.out.println(f);

	}
}

Measured memory_bytes: 24416
#include<bits/stdc++.h>
#define re register
#define rep(i,a,b) for(re int i=a,i##end=b; i<=i##end; i++)
#define drep(i,a,b) for(re int i=a,i##end=b; i>=i##end; i--)
#define repp(i,a,b) for(re int i=a,i##end=b; i<i##end; i++)
#define drepp(i,a,b) for(re int i=a,i##end=b; i>i##end; i--)
#define Erep(i,x) for(int i=head[x]; ~i; i=Edge[i].nxt)
#define ll long long
#define debug(x) cerr<<#x<<" = "<<x<<endl
#define lowbit(x) (x&-x)
#define ms(x,a) memset(x,a,sizeof x)
using namespace std;
template <class T> inline bool Max(T &x, T y){
	return x<y?x=y,1:0;
}
template <class T> inline bool Min(T &x, T y){
	return x>y?x=y,1:0;
}
template <class T> inline T rd() {
	static char ch;static bool neg;
	static T x=0;
	for(ch=neg=0;ch<'0' || '9'<ch;neg|=ch=='-',ch=getchar());
	for(x=0;'0'<=ch && ch<='9';(x*=10)+=ch-'0',ch=getchar());
	return x=(neg?-x:x);
}
const int mod=998244353,oo=1e9,M=2e5+5;
int X[M],Y[M];
struct node{
	int x,y;
}A[M];
int n;
struct BIT{
	int sum[M];
	inline void Modify(int x){
//		if(x<=0) return;
		while(x<=n) sum[x]++, x+=lowbit(x);
		return;
	}
	inline int Sum(int x){
//		if(x<=0) return 0;
		int res=0;
		while(x>0) res+=sum[x], x-=lowbit(x);
		return res;
	}
	inline void clear(){
		rep(i,0,n) sum[i]=0;
	}
}bit;
ll fpow[M];
inline bool cmp(node x, node y) { return x.y<y.y; }
inline void Add(ll &x, ll y) { x+=y; x+=(x<=0)?(mod):(0); x-=(x>=mod)?(mod):(0); return; }
int main(){
//	freopen("test.in","r",stdin);
//	freopen("test.out","w",stdout);
	fpow[0]=1;
	n=rd<int>();
	rep(i,1,n) fpow[i]=fpow[i-1]*2%mod;
	repp(i,0,n) A[i].x=rd<int>(),A[i].y=rd<int>(),X[i]=A[i].x,Y[i]=A[i].y;
	sort(X,X+n); sort(Y,Y+n);
	repp(i,0,n) A[i].x=lower_bound(X,X+n,A[i].x)-X+1,A[i].y=lower_bound(Y,Y+n,A[i].y)-Y+1;
	ll ans=1ll*n*(fpow[n]-1)%mod;
	sort(A,A+n,cmp);
	repp(i,0,n){
		Add(ans,-fpow[i]+1); Add(ans,-fpow[n-1-i]+1);
		Add(ans,-fpow[i]+1); Add(ans,-fpow[n-1-i]+1);
	}
	repp(i,0,n){
		int res=bit.Sum(A[i].x);
		Add(ans,fpow[res]-1); Add(ans,fpow[i-res]-1);
		bit.Modify(A[i].x);
	}
	bit.clear();
	drep(i,n-1,0){
		int res=bit.Sum(A[i].x);
		Add(ans,fpow[res]-1); Add(ans,fpow[n-1-i-res]-1);
		bit.Modify(A[i].x);
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int P, Q, R;
  cin >> P >> Q >>R;
  
  int a, b, c;
  
  a= P+Q, b= Q+R ,c= R+P;
  
  int ans;
  
  ans = min(a,b);
  ans = min(ans,c);
  cout << ans << endl;
  return 0;
}

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

int num[100010],n;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

int main()
{
	n=rd();
	for (int i=1;i<=n;i++) num[i]=rd();
	sort(num+1,num+n+1);
	if (num[n]==0) { puts("Yes");return 0; }
	if (n%3) { puts("No");return 0; }
	for (int i=1;i<=n/3;i++) if (num[i]!=num[1]) { puts("No");return 0; }
	for (int i=1;i<=n/3;i++) if (num[n/3+i]!=num[n/3+1]) { puts("No");return 0; }
	for (int i=1;i<=n/3;i++) if (num[n/3*2+i]!=num[n]) { puts("No");return 0; }
	if (num[1]==(num[n/3+1]^num[n])) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 640
//Problem: ABC 172 D
//Progress: Working
#include <vector>
#include <iostream>
#include <cstring>
typedef long long int ll;
using namespace std;

const ll maxN = 1e7;

ll dp[maxN+1];
ll t;
ll ans = 0;

void init(){
	for(ll i=2; i<=t; i++){
		dp[i] += 2;
		for(ll j=2; j*i <= t; j++){
			dp[i*j] += 1;
		}
		ans += i*dp[i];
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> t;
	init();
	cout << ans + 1LL;
	return 0;
}

Measured memory_bytes: 81784
<?php
fscanf(STDIN, "%d", $num_count);

$num_arr = array_map("intval", explode(" ", trim(fgets(STDIN))));

$prev = $num_arr[0];
$count = 0;
for ($i = 1; $i < $num_count-1; $i++) {
    if (($prev < $num_arr[$i] && $num_arr[$i] < $num_arr[$i+1]) || ($prev > $num_arr[$i] && $num_arr[$i] > $num_arr[$i+1])) {
        ++$count;
    }
    $prev = $num_arr[$i];
}

echo $count, "\n";

Measured memory_bytes: 3828
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    Map<Integer,Integer> mp=new HashMap<>();
    for(int i=0;i<n;i++){
      int a=sc.nextInt();
      mp.put(a,mp.getOrDefault(a,0)+1);
    }
    int del=0;
    for(Map.Entry<Integer,Integer> me:mp.entrySet()){
      del+=Math.max(me.getValue()-1,0);
    }
    del=(del+1)/2*2;
    System.out.println(n-del);
  }
}

Measured memory_bytes: 59492
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        int r = sc.nextInt();
        int d = sc.nextInt();
      	int n = 0;
      	
      	for(int i=l; i<=r; i++){
        	if(i%d==0){
            	n += 1;
            }
        }
      	System.out.println(n);
	}
}

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

using namespace std;

#define int long long

typedef pair<int,int> ii;

int l;
int w[61];
vector<ii> E;

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

	cin >> l;
	for (int i=2;i<=20;i++)
		E.push_back(ii(i-1,i));
	l--;
	int MSB;
	for (int i=19;i>=0;i--)
		if ((l >> i) & 1)
		{
			MSB = i;
			break;
		}
	for (int i=0;i<MSB;i++)
		{
			w[E.size()] = (1<<i);
			E.push_back(ii(20-i-1,20-i));
		}
	int cur = (1 << MSB);	
	for (int i=MSB-1;i>=0;i--)
		if ((l >> i) & 1)
		{
			w[E.size()] = cur;
			E.push_back(ii(1,20-i));
			cur |= (1 << i);
		}
	w[E.size()] = cur;
	E.push_back(ii(1,20));
	cout << 20 << ' ' << E.size() << '\n';
	for (int i=0;i<E.size();i++)
		cout << E[i].first << ' ' << E[i].second << ' ' << w[i] << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) 
#define ll long long
int main()
{ 
    cool;
    string s,str1="",str2="";
    int i,f=0;
    cin>>s;
    for(i=0;i<s.size()/2;i++)
    {
    	if(s[i]!=s[s.size()-1-i])
    	{
    		f=1;
    		break;
		}
	}
	for(i=0;i<s.size()/2;i++)
	str1+=s[i];
	for(i=s.size()/2+1;i<s.size();i++)
	str2+=s[i];
	//cout<<str1<<" "<<str2<<"\n";
	if(f==0&&str1==str2)
	cout<<"Yes";
	else
	cout<<"No";
    return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())

f = False
for i in range(1, 10000):
    used = set([])
    if (a*i)%b == c:
        f = True
        break
    if (a*i)%b in used:
        break
    else:
        used.add((a*i)%b)
if f:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 38896
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    int t;
    cin >> t ;
    while(t--){
        int n,k;
        cin >> n >> k;
        vector<int> x(n);
        rep(i,n) cin >> x[i];
        vector<int> dist(n-1);
        rep(i,n-1) dist[i] = x[i+1] - x[i];
        sort(dist.begin(),dist.end());
        int ans = 0;
        rep(i,n-k){
            ans += dist[i];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
const int N(3003);
int64_t dp[N][N], v[N];
int n;
inline int64_t Solve(int l, int r) {
    if (l > r)
        return 0;
    if (l == r)
        return v[l];
    if (dp[l][r] != -1)
        return dp[l][r];
    dp[l][r] = max(v[l] - Solve(l + 1, r), v[r] - Solve(l, r - 1));
    return dp[l][r];
}
int main() {
    DAU
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> v[i];
        dp[i][i] = v[i];
    }
    cout << Solve(1, n);
    PLEC
}

Measured memory_bytes: 70912
num2alpha = lambda c: chr(c+64)
h,w = map(int,input().split())
a=0
b=0
for i in range(h):
    s = input().split()
    for j in range(w):
        if(s[j]=="snuke"):
            a=i+1
            b=j+1
            break
a=str(a)
b=num2alpha(b)
b=str(b)
s=[b,a]

print(''.join(s))


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

int main(){
	unsigned long int N,A,B;
	
	cin >> N >> A >> B;
	
	unsigned long int sum_ab=A+B;
	unsigned long int mod=N%sum_ab;
	unsigned long int div=N/sum_ab;
	
	unsigned long int ans = div*A;
	if(mod>A)ans += A;
	else ans += mod;
	
	cout << ans << endl;	
}

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

int N,K;

int main(){
    cin >> N >> K;
    double ret=0;
    for(int i = 1;i<=N;i++){
        double tmp=1.0/N;
        int now=i;
        while(now<K){
            now*=2;
            tmp/=2;
        }
        ret+=tmp;
    }
    printf("%.12f\n",ret);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
void out_vec(vector<int> vec, int len_vec)
{
    for (int i = 0; i < len_vec; i++)
    {
        cout << vec[i];
        if (i == len_vec - 1)
            cout << "\n";
        else
            cout << " ";
    }
}

void bubbleSort(vector<int> vec, int len_vec)
{
    bool sort_flag = true;
    int swap_count = 0;
    while (sort_flag == true)
    {
        sort_flag = false;
        for (int i = len_vec - 1; i >= 1; i--)
        {
            if (vec[i] < vec[i - 1])
            {
                swap(vec[i], vec[i - 1]);
                sort_flag = true;
                swap_count++;
            }
        }
    }
    out_vec(vec, len_vec);
    cout << swap_count << "\n";
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];
    bubbleSort(A, N);
    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    string s;
    int k;
    cin>>s>>k;
    int n=s.size();
    rep(i,n){
        if(s[i]!='a'){
            int x=26-(s[i]-'a');
            if(k>=x){
                s[i]='a';
                k-=x;
            }
        }
        
    }
    

    k%=26;
    
    while(k>0){
        if(s[n-1]=='z' && k>0) s[n-1]='a';
        else s[n-1]++;
        k--;
    }


    cout<<s<<endl;
} 


Measured memory_bytes: 3720
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

t = 0
k= int(input(''))+1

#cnt={}

for l in range(1,k):
    for m in range(l,k):
        for n in range(m,k):
#            print("{}/{}/{}".format(l,m,n))
#            key = '-'.join(map(str,sorted([l,m,n])))
#            if not key in cnt.keys():
#                cnt[key] = 0
#            cnt[key]+=1
            if l==m and l==n:
                t+= gcd_list([l,m,n])
#                print("{}/{}/{} -> {} a".format(l,m,n,gcd(l,m,n)))
            elif l==m or l==n or m ==n:
                t+= gcd_list([l,m,n])*3
#                print("{}/{}/{} -> {} b".format(l,m,n,gcd(l,m,n)))
            elif l!=m and m!=n:
                t+= gcd_list([l,m,n])*6
#                print("{}/{}/{} -> {} c".format(l,m,n,gcd(l,m,n)))

#for a,b in cnt.items():
#    print("{} -> {}".format(a,b))
print(t)


Measured memory_bytes: 9640
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  int id,parent,left,right;
};


Node A[100000];

void heap(Node A[],int H){
  for(int i=1;i<=H;i++){
    if(i==1){
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
    else {
      A[i].parent=A[i/2].key;
      A[i].left=A[2*i].key;
      A[i].right=A[2*i+1].key;
    }
  }
}


int main(){
  int H=0;
  cin>>H;
  for(int i=1;i<=H;i++){
    cin>>A[i].key;
    A[i].id=i;
  }
  heap(A,H);
  for(int i=1;i<=H;i++){
    cout<<"node "<<A[i].id<<": key = "<<A[i].key<<", ";
    if(i==1){
      cout<<"left key = "<<A[i].left<<", right key = "<<A[i].right<<", "<<endl;
    }
    else{
      if(A[i].left==0&&A[i].right!=0){
	cout<<"parent key = "<<A[i].parent<<", right key = "<<A[i].right<<", "<<endl;
      }
      else if(A[i].left!=0&&A[i].right==0){
	cout<<"parent key = "<<A[i].parent<<", left key = "<<A[i].left<<", "<<endl;
      }
      else if(A[i].left==0&&A[i].right==0){
	cout<<"parent key = "<<A[i].parent<<", "<<endl;
      }
      else {
	cout<<"parent key = "<<A[i].parent<<", left key = "<<A[i].left<<", right key = "<<A[i].right<<", "<<endl;
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3016
import heapq
import math

n, m = map(int, input().split())
a = list(map(int, input().split()))

a = list(map(lambda x: x*(-1), a))
heapq.heapify(a)

for i in range(m):
    max = heapq.heappop(a)
    heapq.heappush(a, math.ceil(max/2))

print(-sum(a))

Measured memory_bytes: 14532
while true
  w, h = gets.split.map(&:to_i)
  break if w == 0
  xh = {}; yh = {}
  xa = []; ya = []
  xa << 0; xa << w
  ya << 0; ya << h
  points = []
  gets.to_i.times do
    point = gets.split.map(&:to_i)
    points << point
    xa << point[0]; xa << point[2]
    ya << point[1]; ya << point[3]
  end
  xa = xa.uniq; xa.sort!; ya = ya.uniq; ya.sort!
  xs = xa.size; ys = ya.size
  xa.each_with_index{ |a, i| xh[a] = i+1 }
  ya.each_with_index{ |b, i| yh[b] = i+1 }
  fld = Array.new(ys+1){ Array.new(xs+1, true) }
  fld[0].fill(false); fld[ys].fill(false)
  fld.map{ |arr| arr[0] = arr[xs] = false }

  for point in points
    x1, y1, x2, y2 = point
    for a in (yh[y1]...yh[y2])
      for b in (xh[x1]...xh[x2])
        fld[a][b] = false
      end
    end
  end
  ret = 0
  for y in (1...ys)
    for x in (1...xs)
      next unless fld[y][x]
      arr = []
      arr << [y, x]
      until arr.empty?
        ny, nx = arr.shift
        [[-1,0],[0,-1],[1,0],[0,1]].each do |dy, dx|
          px = nx+dx; py = ny+dy
          if fld[py][px]
            arr << [py, px] 
            fld[py][px] = false
          end
        end
      end
      ret += 1
    end
  end
  p ret
end

Measured memory_bytes: 14224
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll maxx = 100005;
bool vis[maxx];
ll dp[maxx];
ll n,m;
vector<ll> a[maxx];
void dfs(ll node){
    vis[node] = true;
    for(auto child : a[node]){
        if(!vis[child]){
            dfs(child);
        }
        dp[node] = max(dp[node], 1+dp[child]);
    }
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(ll i=0;i<m;i++){
        ll x,y;
        cin>>x>>y;
        a[x].push_back(y);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]){
            dfs(i);
        }
    }
    ll ans = INT_MIN;
    for(ll i=1;i<=n;i++){
        ans = max(ans, dp[i]);
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 8704
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	x1, y1, x2, y2 := nextInt(), nextInt(), nextInt(), nextInt()

	fmt.Println(x2+y1-y2, -x1+x2+y2, x1+y1-y2, -x1+x2+y1)
}


Measured memory_bytes: 640
import java.util.*;
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		int[] a = new int[5];
		for(int i=0; i<5; i++){
			a[i] = stdIn.nextInt();
		}
		boolean jdg;
		do{
			jdg = true;
			for(int i=0; i<4; i++){
				if(a[i]<a[i+1]){
					int t = a[i];
					a[i] = a[i+1];
					a[i+1] = t;
					jdg = false;
				}
			}
		} while(jdg == false);
		
		for(int i=0; i<5; i++) System.out.print(a[i] + (i==4 ? "" : " "));
		System.out.println("");
		
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void)
{
  string s;
  cin >> s;
  if(s[0] == s[1] && s[0] != s[2] && s[2] == s[3]) cout << "Yes\n";
  else if(s[0] == s[2] && s[0] != s[1] && s[1] == s[3]) cout << "Yes\n";
  else if(s[0] == s[3] && s[0] != s[1] && s[1] == s[2]) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}



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

void bubbleSort(int A[], int N, int &count) {
    int flag = 1;
    int i = 0;
    while (flag) {
        flag = 0;
        for (int j = N - 1; j >= i + 1; --j) {
            if (A[j - 1] > A[j]) {
                int temp = A[j - 1];
                A[j - 1] = A[j];
                A[j] = temp;
                count += 1;
                flag = 1;
            }
        }
        ++i;
    }
}

int main() {
    int N, count = 0;
    int A[100];
    cin >> N;
    for(int i = 0; i < N; ++i) {cin >> A[i];}
    
    bubbleSort(A, N, count);
    for (int i = 0; i < N; ++i) {
        if (i > 0)
            cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3116
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#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=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, x, y; cin >> n >> x >> y;
    ll a[2001]; INITA(a, 0, 2000, 0);
    FOR(i, 1, n-1) {
        FOR(j, i+1, n) {
            int dist = min(j-i, abs(y-j)+abs(x-i)+1);
            a[dist]++;
        }
    }
    FOR(i, 1, n-1) {
        cout << a[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3660
#include <float.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  string s;
  cin >> s;
  string res;
  if (s == "Sunny")
    res = "Cloudy";

  else if (s == "Cloudy")
    res = "Rainy";
  else
    res = "Sunny";
  cout << res << endl;
}

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

long long MOD=1000000007LL;

int main(){
	string L;
	cin >> L;
	int N=L.size();

	long long dp[N+1][2];
	//dp[i][1]:L未満が確定
	for(int i=0;i<N+1;i++)for(int j=0;j<2;j++)dp[i][j]=0;
	dp[0][0]=1;
	
	for(int i=0;i<N;i++){
		dp[i+1][1]+=dp[i][1]*3;
		dp[i+1][0]+=dp[i][0];
		if(L[i]=='1'){
			dp[i+1][1]+=dp[i][0];
			dp[i+1][0]+=dp[i][0];
		}	
		dp[i+1][0]%=MOD;
		dp[i+1][1]%=MOD;
	}
	
	cout << (dp[N][0]+dp[N][1])%MOD << endl;
	
	return 0;
}

Measured memory_bytes: 2048
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	int w=Integer.parseInt(input.readLine());
	int a[]=new int[w];
	for(int i=0;i<w;i++)
	    {
		a[i]=i+1;
	    }
	int n=Integer.parseInt(input.readLine());
	for(int i=0;i<n;i++)
	    {
		String str=input.readLine();
		String str_ary[]=str.split(",");
		int b[]=new int [2];
		
			b[0]=Integer.parseInt(str_ary[0])-1;
			b[1]=Integer.parseInt(str_ary[1])-1;
		int tmp=a[b[0]];
		a[b[0]]=a[b[1]];
		a[b[1]]=tmp;
	    }
for(int i=0;i<w;i++)
	    {
		System.out.println(a[i]);
	    }
    }
}

Measured memory_bytes: 16924
#include <stdio.h>

int main(void)
{
	int N;
	int a[1000], b[1000], c[1000];
	int n;
	
	scanf("%d", &N);
		n = N;
		while(n != 0){
			scanf("%d %d %d", &a[n], &b[n], &c[n]);
			n--;
		}
		while(N != 0){
			if((a[N] * a[N]) + (b[N] * b[N]) == (c[N] * c[N])){
				printf("YES\n");
			}
			else if((a[N] * a[N]) + (c[N] * c[N]) == (b[N] * b[N])){
				printf("YES\n");
			}
			else if((c[N] * c[N]) + (b[N] * b[N]) == (a[N] * a[N])){
				printf("YES\n");
			}
			else{
				printf("NO\n");
			}
			N--;
	}
	return(0);
}

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

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

    long n,m;
    cin >> n;
    cin >> m;

    long scc_count = 0;
    long tmp_n = n;
    long tmp_m = m;

    while(tmp_n > 0 && tmp_m > 1){
        ++scc_count;
        tmp_n -= 1;
        tmp_m -= 2;
    }

    if(tmp_m > 3){
        scc_count += tmp_m / 4;
    }

    cout << scc_count << endl;

    return 0;
}


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

int main() {
  vector<vector<int>> a(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  bool ans = false;
  if (a.at(0).at(1) - a.at(0).at(0) == a.at(1).at(1) - a.at(1).at(0)
      && a.at(0).at(1) - a.at(0).at(0) == a.at(2).at(1) - a.at(2).at(0)) {
    if (a.at(0).at(2) - a.at(0).at(1) == a.at(1).at(2) - a.at(1).at(1)
        && a.at(0).at(2) - a.at(0).at(1) == a.at(2).at(2) - a.at(2).at(1)) {
      
      if (a.at(1).at(0) - a.at(0).at(0) == a.at(1).at(1) - a.at(0).at(1)
          && a.at(1).at(0) - a.at(0).at(0) == a.at(1).at(2) - a.at(0).at(2)) {
        if (a.at(2).at(0) - a.at(1).at(0) == a.at(2).at(1) - a.at(1).at(1)
          && a.at(2).at(0) - a.at(1).at(0) == a.at(2).at(2) - a.at(1).at(2)) {
          ans = true;
        }
      }
      
    }
  }
  
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 764
#include<iostream>
using std::cout;
using std::cin;
using std::endl;

#include<string>
using std::string;

#include<set>
using std::set;

int main()
{
  int n;
  cin >> n;
  
  set<string> s;
  string tmp;
  for (int i = 0; i < n; i ++)
  {
    cin >> tmp;
    s.insert(tmp);
  }
  
  cout << s.size() << endl;
  return 0;
}

Measured memory_bytes: 19228
#include <stdio.h>
int main(void){
 int a,b,c,d;
 scanf("%d%d%d%d",&a,&b,&c,&d);
 printf("%d %d %d %d",c-(d-b),d+c-a,c-(d-b)-(c-a),d+c-a-(d-b));
 return 0;
}


Measured memory_bytes: 128
N, Y = map(int, input().split())
x,y,z = 0,0,0
for x in range(0, N + 1):
    for y in range(0, N - x +1):
        z = N - x - y
        if 10000 * x + 5000 * y + 1000 * z == Y:
            break
    if 10000 * x + 5000 * y + 1000 * z == Y :
        break

if 10000 * x + 5000 * y + 1000 * z == Y :
    print(x,y,z)
else:
    print(-1,-1,-1)

Measured memory_bytes: 3064
/*luogu-remote-enable*/
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <algorithm>

namespace Proxy
{
    const int N=100000*2+5;
    int t, cnt;
    struct NODE
    {
        int knf;
        bool f;
    } a[N];

    inline bool cmp(NODE a, NODE b) { return a.knf > b.knf; }

    #define read(a) do{                                     \
        register char c;                                    \
        while(!isdigit(c=getchar())); a=c^48;               \
        while(isdigit(c=getchar())) a=(a<<1)+(a<<3)+(c^48); \
    } while(false)
} 

using namespace Proxy;

int main(void)
{
    int n, h; read(n); read(h);
    for(int i=1; i<=n; ++i)
    {
        ++t; read(a[t].knf);
        ++t; read(a[t].knf);
        //a[t++] isn't able!
        a[t].f=true;
    }
    std::sort(a+1, a+t+1, cmp);

    for(int i=1; i<=t; ++i)
    {
        if(a[i].f)
        {
            ++cnt, h-=a[i].knf;
            if(h<=0) return printf("%d\n", cnt)&0;
        }
        else
        {
            cnt+=h/a[i].knf+(h%a[i].knf!=0);
            return printf("%d\n", cnt)&0;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;
                   
int n,m;
string s,t;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>s>>t;
  n=(int)s.length();
  m=(int)t.length();
  bool tflag=0;
  //cerr<<1<<endl;
  for(int i=n-m;i>=0;i--){
    bool flag=1;
    for(int j=0;j<m;j++){
      if(t[j]!=s[i+j] && s[i+j]!='?'){
        flag=0;
        break;
      }
    }
    //cerr<<11<<endl;
    if(flag){
      tflag=1;
      for(int j=0;j<m;j++){
        s[i+j]=t[j];
      }
      break;
    }
  }
  //cerr<<2<<endl;
  for(int i=0;i<n;i++){
    if(s[i]=='?'){
      s[i]='a';
    }
  }
  if(tflag){
    cout<<s<<"\n";
  }else cout<<"UNRESTORABLE"<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

ll n, q, i, j, x;
vector<ll> ops;
ll todo[maxN];

ll sums[maxN], k;
ll cnt[maxN];

int main()
{
//    freopen("test.in","r",stdin);

    scanf("%lld%lld", &n, &q);
    ops = {n};
    for (i = 1; i <= q; i++) {
        scanf("%lld", &x);

        while (!ops.empty()) {
            if (ops.back() < x) break;
            ops.pop_back();
        }

        ops.pb(x);
    }

    q = ops.size();
    for (i = 0; i < ops.size(); i++)
        todo[i + 1] = ops[i];

    cnt[q] = 1;
    for (i = q; i > 1; i--) {
        if (cnt[i] == 0) continue;
        k = todo[i];

        while (k >= todo[1]) {
            ll pos = upper_bound(todo + 1, todo + q + 1, k) - todo - 1;
            pos = min(pos, i - 1);

            cnt[pos] += (k / todo[pos]) * cnt[i];
            k %= todo[pos];
        }

        sums[k] += cnt[i];
        cnt[i] = 0;
    }

    sums[todo[1]] += cnt[1];
    for (i = n; i > 0; i--)
        sums[i] += sums[i + 1];

    for (i = 1; i <= n; i++)
        printf("%lld\n", sums[i]);

    return 0;
}


Measured memory_bytes: 4980
A = gets.chomp.to_i
B = gets.chomp.to_i
C = gets.chomp.to_i
X = gets.chomp.to_i

count = 0

(0..A).each do |a|
  (0..B).each do |b|
    y = X - 500 * a - 100 * b
    count += 1 if y >= 0 && y % 50 == 0 && y / 50 <= C
  end
end

puts count


Measured memory_bytes: 1788
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Akash
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CVacation solver = new CVacation();
        solver.solve(1, in, out);
        out.close();
    }

    static class CVacation {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int a[][] = new int[n + 5][3];
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 3; j++) {
                    a[i][j] = in.nextInt();
                }
            }

            int dp[][] = new int[n + 5][3];
            dp[0][0] = a[0][0];
            dp[0][1] = a[0][1];
            dp[0][2] = a[0][2];

            for (int i = 1; i < n; i++) {
                for (int j = 0; j < 3; j++) {
                    if (j == 0)
                        dp[i][j] = a[i][j] + Math.max(dp[i - 1][1], dp[i - 1][2]);
                    if (j == 1)
                        dp[i][j] = a[i][j] + Math.max(dp[i - 1][0], dp[i - 1][2]);
                    if (j == 2)
                        dp[i][j] = a[i][j] + Math.max(dp[i - 1][1], dp[i - 1][0]);
                }
            }

            out.println(Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2])));

        }

    }
}



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

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
    a, b = [int(_) - 1 for _ in input().split()]
    edge[a].append((b, i))
    edge[b].append((a, i))
ans = [0] * (N - 1)
colors_num = max([len(_) for _ in edge])
colors = list(range(colors_num))


def dfs(v, pv, pc):
    valid_colors = filter(lambda c: c != pc, colors)
    childs = filter(lambda c: c[0] != pv, edge[v])
    for ((cv, ci), color) in zip(childs, valid_colors):
        ans[ci] = color + 1
        dfs(cv, v, color)


dfs(0, -1, -1)
print(colors_num)
print(*ans)


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

int main() {
	int n;
	cin >> n;
	int h[100001];
	for (int i = 0; i < n; ++i) cin >> h[i];
	int a = 0, b = abs(h[0] - h[1]);
	for (int i = 2; i < n; ++i) {
		int tmp = b;
		b = min(a + abs(h[i]-h[i-2]), b + abs(h[i]-h[i-1]));
		a = tmp;
	}
	cout << b << endl;
	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    if(S.size()%2){
        cout<<NO<<endl;
        return;
    }
    for(int i=0;i<S.size();i+=2)
    {
        if(S[i]=='h'&&S[i+1]=='i')continue;
        cout<<NO<<endl;
        return;
    }
    cout<<YES<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

int main() {
	int n;
	cin >> n;
	int a[2][110];
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	int ans = 0;
	int answer = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= i; j++) {
			ans += a[0][j];
		}
		for (int j = i; j < n; j++) {
			ans += a[1][j];
		}
		answer = max(ans, answer);
		ans = 0;
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
int main(void)
{
    int a[100],n,count=0;
    int alice=0,bob=0;
    scanf("%d",&n);
    for(int i = 0;i < n;i++)
        scanf("%d",&a[i]);
    std::sort(a,a+n);
    for(int i = n-1;i>=0;i--){
        if(count%2 == 0){
            alice += a[i];
        }else{
        bob += a[i];
        }
        count++;
    }
    printf("%d\n",alice - bob);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int money[]={1000,500,100};
using namespace std;
int main(){
    int a,b;
    while(scanf("%d%d",&a,&b),a,b){
        int x = b-a;
        int check[5] = {0};
        int q = 0;
        for(;;){
            if(x == 0)break;
            if(x - money[q] >= 0){
                check[q]++;
                x = x - money[q];
            }
            else q++;
        }
        printf("%d %d %d\n",check[2],check[1],check[0]);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;

int main() {
	int n;
	double square_sum = 0;
	int sum = 0;
	double mean;
	double square_mean;
	double variance;
	double stddeviation;
	while(cin >> n, n != 0) {
		int s[n];
		for(int i = 0; i < n; i++) {
			cin >> s[i];
			sum += s[i];
			square_sum += s[i] * s[i];
		}
		mean = (double)sum / n;
		square_mean = (double)square_sum / n;
		variance = square_mean - mean * mean;
		stddeviation = sqrt(variance);
		printf("%.6lf\n", stddeviation);
		sum = 0;
		square_sum = 0;
	}
}


Measured memory_bytes: 3184
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<pll,pll> ppll;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    ll h,w;
    cin >> h >> w;
    vector<vector<int>> a(h,vector<int>(w,0));
    int odd = 0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> a[i][j];
            if(a[i][j]%2 == 1) odd++;
        }
    }

    vector<ppll> res;
    int num = 0;
    int x = 0, y = 0;
    for(int itr = 0;itr < h*w; itr++){
        if(a[x][y] %2 == 1) num++;

        int nx = x, ny = y;
        if(x%2 == 0){
            if(ny == w-1) nx++;
            else ny++;
        }else{
            if(ny == 0) nx++;
            else ny--;
        }
        if(num%2 == 1) if(num < odd) res.push_back(ppll(pll(x,y),pll(nx,ny)));
        x = nx;
        y = ny;
    }

    cout << res.size() << endl;
    for(auto p : res){
        cout << p.first.first+1;
        cout << " ";
        cout << p.first.second+1;
        cout << " ";
        cout << p.second.first+1;
        cout << " ";
        cout << p.second.second+1 << endl;
    }

    return 0;
}



Measured memory_bytes: 8400
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	ll x, y;
	cin >> x >> y;
    ll ans = abs(abs(x)-abs(y));
    if (x*y < 0) ++ans;
    else if (x*y == 0 and x>y) ++ans;
    else if (x>y) ans += 2;
    
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

 int main()
 {
   int i , j, b, v, k, A[200], flag=1, count=0;
   scanf("%d",&b);
   for(i=0; i < b; i++){
    scanf("%d",&A[i]);
   }

    while(flag){
    flag = 0;
    for(j=b-1; j>=1; j--){
      if(A[j] < A[j-1]){
    k = A[j];
    A[j] = A[j-1];
    A[j-1] = k;
    count++;
    flag = 1;
      }
    }
  }
         for(k=1; k<=b; k++){
    if (k > 1){
    printf(" ");
    }
    printf("%d", A[k-1]);
  }
    printf("\n");
    
  printf("%d\n",count);
    
   return 0;
    }

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> PII;


int main(){
  int N;
  cin>>N;
  VI P(N);
  int X=0;
  rep(i,N){
    cin>>P[i];
    if(P[i]!=i+1) X++;
  }
  if(X==2||X==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}


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<ll, ll>P;

int main() {
	ll n;
	while (cin >> n, n) {
		map<ll, ll>mp;
		map<ll, ll>pos;
		rep(i, n) {
			ll e, p, q; cin >> e >> p >> q;
			mp[e] += p*q; pos[e] = i;
		}
		vector<P>v;
		for (P i : mp)v.push_back(i);
		sort(v.begin(), v.end(), [&](P a, P b) {return pos[a.first] <= pos[b.first]; });
		bool flag = true;
		for (P i : v) {
			if (i.second >= 1000000) {
				cout << i.first << endl;
				flag = false;
			}
		}
		if (flag)puts("NA");
	}
}

Measured memory_bytes: 3260
import std.stdio, std.string, std.array, std.conv, std.algorithm, std.typecons, std.range, std.container, std.math, std.algorithm.searching, std.functional,std.mathspecial;

void main(){
    auto str=readln().chomp;
    writeln(str.length/2-str.count!(s=>s=='p'));
}

Measured memory_bytes: 2428
package main

import (
  "bufio"
  "fmt"
  "os"
  "strconv"
  "strings"
)

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,1000000)}
  n := input.NextInt()
  s := input.NextIntArray()
  m := int64(0)
  u := make([]bool,n)
  for c:=1;c<n-1;c++ {
    f := int64(0)
    for k:=0;c<n-1-k*c;k++ {
      u[k*c] = true
      if u[n-1-k*c] { break }
      f += int64(s[n-1-k*c])+int64(s[k*c])
      if m < f { m = f }
    }
    for k:=0;k*c<n-1;k++ { u[k*c] = false }
  }
  fmt.Println(m)
}

type Input struct {
  reader *bufio.Reader
}
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int {
  n,_ := strconv.Atoi(i.NextLine())
  return n
}
func(i *Input) NextIntArray() []int {
  s := strings.Split(i.NextLine()," ")
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if ((b - a) == (c - b)) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256