akhauriyash/Code-Regression huggingface dataset:
import math

K = int(input())
ans = 0
for a in range(1, K+1):
    for b in range(1, K + 1):
        ab_gcd = math.gcd(a, b)
        for c in range(1, K + 1):
            ans += math.gcd(ab_gcd, c)
print(ans)


Measured memory_bytes: 9136
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
AtoZ = [chr(i) for i in range(65,65+26)]
atoz = [chr(i) for i in range(97,97+26)]

def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())


A,B,C = inpl()
if A == B:
	print(C)
elif B == C:
	print(A)
else:
	print(B)

Measured memory_bytes: 5356
template<class T> inline void chmin(T & a, const T b) { if (a > b) a = b; }
template<class T> inline void chmax(T & a, const T b) { if (a < b) a = b; }
typedef long long llong;

#include <bits/stdc++.h>
using namespace std;
int N, A, B, C;
vector<int> L;

int rec(int i, int a, int b, int c) {
	if (i == N) {
		if (!a || !b || !c) return 100000;
		return abs(a - A) + abs(b - B) + abs(c - C);
	}

	int res = rec(i + 1, a, b, c);
	res = min(res, rec(i + 1, a + L[i], b, c) + (a ? 10 : 0));
	res = min(res, rec(i + 1, a, b + L[i], c) + (b ? 10 : 0));
	res = min(res, rec(i + 1, a, b, c + L[i]) + (c ? 10 : 0));
	return res;
}

int main(void) {
	cin >> N >> A >> B >> C;
	L.resize(N);
	for (int i = 0; i < N; i++) cin >> L[i];

	cout << rec(0, 0, 0, 0) << endl;

	return 0;
}

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

using namespace std;

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

   int sum = 0;
   int temp = n;

   while(temp > 0){
       sum += temp % 10;
       temp /= 10;
   }

   if(n % sum == 0){
       cout << "Yes" << endl;
   }
   else {
       cout << "No" << endl;
   }

}

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

int main() {
    int N;
    cin >> N;
    int num_100 = N / 100;
    int num_10 = (N - num_100 * 100) / 10;
    int num_1 = (N - num_100 * 100 - num_10 * 10);
    if(num_100 == num_1) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

const int maxn=4e6+10;

bitset<maxn> b;

int main(){

    int n;
    scanf("%d",&n);
    b[0]=1;
    int sum=0;
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        b|=b<<x;
        sum+=x;
    }
    for(int i=(sum+1)/2;i<=sum;i++){
        if(b[i]) {
            printf("%d\n",i);
            return 0;
        }
    }
}


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

int main() {
    int n,k,q;
    cin>>n>>k>>q;
    
    vector<int> point(n);
    for(int i=0; i<q; i++){
        int a;
        cin>>a;
        point.at(a-1)++;
    }

    for(int i=0; i<n; i++){
        if(point.at(i)+k-q>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }

}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int a,b,c,i,min,sa[6];
  scanf("%d %d %d",&a,&b,&c);
  sa[0]=abs(a-b)+abs(b-c);
  sa[1]=abs(a-b)+abs(c-b);
  sa[2]=abs(a-c)+abs(c-b);
  sa[3]=abs(a-b)+abs(b-c);
  sa[4]=abs(c-a)+abs(a-b);
  sa[5]=abs(b-c)+abs(c-a);
  min=sa[0];
  for(i=0;i<6;i++){
    if(min>sa[i]){
      min=sa[i];
    }
  }
  printf("%d",min);
  return 0;       
}

Measured memory_bytes: 128
import java.util.*;

class P
{
	int name;
	int time;
	P(int name, int time)
	{
		this.name = name;
		this.time = time;
	}
}
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			if(n == 0)
			{
				break;
			}
			List<P> list = new ArrayList<P>();
			for(int i = 0; i < n; ++i)
			{
				int c1 = stdIn.nextInt();
				int m1 = stdIn.nextInt();
				int s1 = stdIn.nextInt();
				int m2 = stdIn.nextInt();
				int s2 = stdIn.nextInt();
				int m3 = stdIn.nextInt();
				int s3 = stdIn.nextInt();
				int m4 = stdIn.nextInt();
				int s4 = stdIn.nextInt();
				list.add(new P(c1, (m1 + m2 + m3 + m4) * 60 + (s1 + s2 + s3 + s4)));
			}
			Collections.sort(list, new Comparator<P>()
			{ 
				public int compare(P t1, P t2)
				{
					return (t1.time - t2.time); 
				}
			} );
			System.out.println(list.get(0).name);
			System.out.println(list.get(1).name);
			System.out.println(list.get(n - 2).name);
		}
	}
}

Measured memory_bytes: 13000
#include <string>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,h[100005];
ll dp[100005];
 
int main()  {

  int N,K;
  int h,k;
  std::cin >> N >> K;
  std::cin >> n >> k;
  //printf("%d,%d,%d,%d",N,K,n,k);
  printf("%d",N*K-N*k-K*n+k*n);
  
   
}

Measured memory_bytes: 256
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

vector<vi> groups;
vpii edges;
int main() {
    int N;
    cin >> N;

    int i;
    if (N & 1) {
        vi v;
        v.pb(N);
        groups.pb(v);
        v.resize(2);
        for (i = 1; i <= N/2; i++) {
            v[0] = i,v[1] = N-i;
            groups.pb(v);
        }
    }
    else {
        vi v;
        v.resize(2);
        for (i = 1; i <= N/2; i++) {
            v[0] = i,v[1] = N-i+1;
            groups.pb(v);
        }
    }
    int j,k,l;
    for (i = 0; i < groups.size(); i++) {
        for (j = i+1; j < groups.size(); j++) {
            for (k = 0; k < groups[i].size(); k++) {
                for (l = 0; l < groups[j].size(); l++) edges.pb(mp(groups[i][k],groups[j][l]));
            }
        }
    }
    printf("%d\n",edges.size());
    for (i = 0; i < edges.size(); i++) printf("%d %d\n",edges[i].first,edges[i].second);

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int num, i, a;
	cin >> num;
	vector<list<int>> d(num);
	rep(i, num - 1) {
		cin >> a;
		d[a - 1].push_back(i + 1);
	}
	rep(i, num) {
		cout << d[i].size() <<"\n";
	}
	return 0;
}


Measured memory_bytes: 14032
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long const MOD = 1000000007;

long long modpow(long long a, long long b)
{
    long long res = 1;
    long long base = a;
    while(b > 0)
    {
        if (b & 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        b >>= 1;
    }
    res %= MOD;
    return res;
}

long long modinv(long long num)
{
    return modpow(num, MOD - 2);
}


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

    long long base = modpow(3, (ll)L.size());
    long long ans = 1;
    
    ans = 0;
    long long same = 1;
    long long inv3 = modinv(3);
    // cout << inv3 << endl;
    // cout <<(long long) MOD * MOD << endl;
    // cout << "***********" << endl;
    for (int i = 0; i < L.size(); i++)
    {
        // cout << base << ' ' << base * inv3 << ' ' << inv3 % MOD << endl;
        base = (base * inv3) % MOD;
        if (L[i] == '1')
        {
            ans = (ans + base * same) % MOD;
            same = (2 * same) % MOD;
        }
        // cout << same << ' ' << base << endl;
    }
    ans = (ans + same) % MOD;
    cout << ans << endl;
   	return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

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

		for(int i=0;i<s.length()-1;i++) {
			if(s.charAt(i)==s.charAt(i+1)) {
				System.out.println("Bad");
				break;
			}
			if(i==s.length()-2) System.out.println("Good");
		}
	}
}

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

int main(){
	string x;
	cin>>x;
	if(x=="Sunny")	cout<<"Cloudy"<<endl;
	if(x=="Rainy")	cout<<"Sunny"<<endl;
	if(x=="Cloudy")	cout<<"Rainy"<<endl;
	
	
}

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

int main(){
  int n,a,b,max,min;
  cin >> n;
  cin >> a;
  cin >> b;
  max = 0;
  min = 0;

  max = std::min({a,b});
  min = std::max({0,(a+b)-n});

  cout << max << " " << min << endl;
  return 0;

}


Measured memory_bytes: 256
/// Comentary AC
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){ 
    int H; cin >> H;
    int W; cin >> W;
    vector<string> a(H);
    
    for (int i=0;i<H;i++) cin >> a[i];
    
    vector<bool> row(H,false);
    vector<bool> col(W,false);
    for (int i=0;i<H;i++){
        for (int j=0;j<W;j++){
            if (a[i][j]=='#') {
                row[i]=true;
                col[j]=true;
            }
        }
    }

    for (int i=0;i<H;i++){
        if (row[i]){
            for (int j=0;j<W;j++){
                if (col[j]) cout << a[i][j];
            }
            cout << endl;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
struct UnionFind
{
  vector< int > data;
  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }
  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }
  void unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x != y) {
      if(data[x] > data[y]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
  }
};   
int main()
{
  int N, M, power[100001];
  power[0] = 1;
  for(int i = 1; i < 100001; i++) {
    power[i] = 1LL * power[i - 1] * 2 % mod;
  }
  while(scanf("%d %d", &N, &M), N) {
    UnionFind tree(N);
    for(int i = 0; i < M; i++) {
      int x, y;
      scanf("%d %d", &x, &y);
      tree.unite(--x, --y);
    }
    int group = 0;
    for(int i = 0; i < N; i++) {
      group += tree.find(i) == i;
    }
    printf("%d\n", power[group] + (group != N));
  }
}

Measured memory_bytes: 1964
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int func1(int,int);
int func2(int,int);
int car[15],cnt1,cnt2;
int main(void)
{
	int n,i,j,f,x;
	scanf("%d",&n);
	for(i=0;i<n;i++)	{
		for(j=1;j<=13;j++)	car[j]=2;
		car[7]=0;	car[0]=0;	car[14]=0;
		for(j=0;j<6;j++)	{
			scanf("%d",&f);
			car[f]=1;
		}
		cnt1=6;	cnt2=6;
		x=func1(7,7);
//		printf("x=%d\n",x);
		if(x>0)	printf("yes\n");
		else printf("no\n");
	}
	return 0;
}
int func1(int left,int right)
{
	int i,j,x1,x2,f1,f2,x;

//	printf("1 %d %d\n",left,right);

	f1=0;	f2=0;
	if(car[left-1]==1 && cnt1==1)	{
		return 100;
	}
	else if(car[right+1]==1 && cnt1==1)	{
		return 100;
	}
	else {
		if(car[left-1]==1)	{
			f1=1;
			cnt1--;
			car[left-1]=0;
			x1=func2(left-1,right);
			car[left-1]=1;	
			cnt1++;
		}
		if(car[right+1]==1)	{
			f2=1;
			cnt1--;
			car[right+1]=0;
			x2=func2(left,right+1);
			car[right+1]=1;
			cnt1++;
		}
	}
	if(f1==0 && f2==0)	return func2(left,right);
	if(f1==1 && f2==1)	return max(x1,x2);
	if(f1==1 && f2==0)	return x1;
	if(f1==0 && f2==1)	return x2;
}
int func2(int left,int right)
{
	int i,j,x1,x2,f1,f2,x;
	
//	printf("2 %d %d\n",left,right);
	
	f1=0;	f2=0;
	if(car[left-1]==2 && cnt2==1)	{
		return -100;
	}
	else if(car[right+1]==2 && cnt2==1)	{
		return -100;
	}
	else {
		if(car[left-1]==2)	{
			f1=1;
			cnt2--;
			car[left-1]=0;
			x1=func1(left-1,right);
			car[left-1]=2;	
			cnt2++;
		}
		if(car[right+1]==2)	{
			f2=1;
			cnt2--;
			car[right+1]=0;
			x2=func1(left,right+1);
			car[right+1]=2;
			cnt2++;
		}
	}
	if(f1==0 && f2==0)	return func1(left,right);
	if(f1==1 && f2==1)	return min(x1,x2);
	if(f1==1 && f2==0)	return x1;
	if(f1==0 && f2==1)	return x2;
}
	


Measured memory_bytes: 2688
N = int(input())
D = list(map(int, input().split()))
dp = [0] * N
for i in D:
  dp[i] += 1
ans = 1 if dp[0] == 1 and D[0] == 0 else 0
for i in range(1, N):
  ans *= dp[i-1] ** dp[i]
  ans %= 998244353
print(ans)

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

//各桁の和を求める関数
int sumofdigit(int a){
  int sum = 0;
  while(a > 0){
    sum += a % 10;
    a /= 10;
  }
  return sum;
}

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  
  for(int i = 1; i <= N; i++){
    if(sumofdigit(i) >= A && sumofdigit(i) <= B){
      total += i;
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 256
import sys
import numpy as np
import collections
n,k = [int(x) for x in sys.stdin.readline().split()]
r = collections.defaultdict(int)
for i in range(n):
	a, b = [int(x) for x in sys.stdin.readline().split()]
	r[a] += b
d = sorted(r.items())
c = 0
for i,j in enumerate(d):
	c += j[1]
	if c >= k:
		print(int(j[0]))
		break

Measured memory_bytes: 23564
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    while(cin>>n&&n){
        vector<string> vs(n);
        rep(i,n)cin>>vs[i];
        
        int ans = 0;
        bool status = false;
        bool l=false, r=false;
        
        for(auto elm:vs){
            if(elm[1]=='u'){
                if(elm[0]=='l') l=true;
                else r=true;

                if(status==false && l && r){
                    status = true;
                    ans++;
                }

            }else{
                if(elm[0]=='l') l=false;
                else r=false;

                if(status==true && !l && !r){
                    status = false;
                    ans++;
                }

            }
        }
        cout<<ans<<endl;
    }
}

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

int N,M;
int r[1010] = {};
int main(){
    cin >> N >> M;
    int c,d;
    for(int i=1;i<=M;i++){
        cin >> c >> d;
        r[c+1]++; r[d+1]--;        
    }
    for(int i=1;i<=N;i++) r[i] += r[i-1];
    int ans = 0;
    for(int i=1;i<=N;i++){
        if(r[i]>=1) ans += 3;
        else ans++;
    }
    cout << ++ans << endl;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>
#pragma warning(disable : 4996)
char c[201], d[101];
int main() {
	while (~scanf("%s", c)) {
		if (strlen(c) % 2 == 1) {
			printf("NA\n");
		}
		else {
			bool flag = false;
			for (int i = 0; i < strlen(c); i += 2) {
				int a = c[i] - 48, b = c[i + 1] - 48;
				if (a == 0 || a > 6 || b == 0 || b > 5) {
					printf("NA"); flag = true; break;
				}
				else {
					int e = (a - 1) * 5 + (b - 1);
					switch (e) {
					case 26: d[i / 2] = '.'; break;
					case 27: d[i / 2] = '?'; break;
					case 28: d[i / 2] = '!'; break;
					case 29: d[i / 2] = ' '; break;
					default: d[i / 2] = (char)(e + 97); break;
					}
				}
			}
			if (!flag) {
				for (int i = 0; i < strlen(c) / 2; i++) {
					printf("%c", d[i]);
				}
			}
			printf("\n");
		}
	}
	return 0;
}

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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    unordered_map<string, unsigned long> mp;
    for(unsigned long i{0}; i < N; ++i){
        string S;
        cin >> S;
        ++mp[S];
    }
    for(const auto& s : {"AC", "WA", "TLE", "RE"})cout << s << " x " << mp[s] << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) rep(i,0,n)

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(a,min(b,c))<<" "<<max(a,max(b,c))<<endl;
}


Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b[] = new int[a];
		int c = 0;
		for (int i = 0; i < b.length -1 ;i++) {
			c = s.nextInt();
			b[c - 1] += 1;
		}
		for(int j = 0; j < b.length; j++) {
			System.out.println(b[j]);
		}

	}

}

Measured memory_bytes: 61580
import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = Integer.parseInt(sc.next());
    	int Y = Integer.parseInt(sc.next());

    	loop: for (int a=0; a<=N; a++){
    		for (int b=0; b<=N-a; b++){
    			if ((a*10000 + b*5000 + (N-a-b)*1000)==Y){
    				System.out.println(a + " " + b + " " + (N-a-b));
    				break loop;
    			}

    			if (a == N && b == N-a){
    				System.out.println("-1 -1 -1");
    			}
    		}
    	}
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<string>
using namespace std;
int main()
{
  int a,b,i;
  string s;
  cin >> a >> b >> s;
  for(i=0;i<a;i++)
    if(s[i]=='-'){
      cout << "No" << endl;
      return 0;
    }
  if(s[a]!='-'){
    cout << "No" << endl;
    return 0;
  }
  for(i=a+1;i<a+b+1;i++)
    if(s[i]=='-'){
      cout << "No" << endl;
      return 0;
    }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 384
<?php
$ans = 0;
define('MAX', 2000);

fscanf(STDIN, "%d", $N);
$L = explode(" ", trim(fgets(STDIN)));
$max = max($L);
$sum = array_pad(array(), MAX + 1, 0);
foreach ($L as $v) {
    $sum[$v]++;
}
for ($i = 1; $i <= MAX; $i++) {
    $sum[$i] = $sum[$i - 1] + $sum[$i];
}
sort($L);
for ($i = 0; $i < $N - 2; $i++) {
    for ($j = $i + 1; $j < $N - 1; $j++) {
        $x = $L[$i] + $L[$j] - 1;
        $ans += $sum[$x] - $j - 1;
    }
}
echo $ans;


Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <utility>
#include <iomanip>
using namespace std;
typedef long long ll;

int main(){
	ll a,b,f=0,tmp=1;
	cin>>a>>b;
	a-=1;
	vector<ll>ans1;
	vector<ll>ans2;
	for(ll i=1;;i*=2){
		if((a-(i-1))<=0) break;
		ll tmp= ( (a-(i-1)) / (i*2) ) * (i) + min( ( (a-(i-1))%(i*2) ) , i );
		ans1.push_back(tmp);
	}
	for(ll i=1;;i*=2){
		if((b-(i-1))<=0) break;
		ll tmp= ( (b-(i-1)) / (i*2) ) * (i) + min( ( (b-(i-1))%(i*2) ) , i );
		ans2.push_back(tmp);
	}
	vector<ll>ans3(ans2.size());
	for(ll i=0;i<ans1.size();i++){
		ans3[i]=ans2[i]-ans1[i];
	}
	for(ll i=ans1.size();i<ans2.size();i++){
		ans3[i]=ans2[i];
	}
	for(ll i=0;i<ans3.size();i++){
		if(ans3[i]%2==1){
			f+=tmp;
		}
		tmp*=2;
	}
	cout<<f;
}



Measured memory_bytes: 256
k, s = list(map(int, input().split()))

minz = max(0, s-2*k)
maxz = min(s, k)

def f(s, k):
    if k >= s:
        return (s+1)
    else:
        return (2*k-s)+1

ans = 0
for i in range(minz, maxz+1):
    ans += f(s-i, k)

print(ans)

Measured memory_bytes: 9196
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
#from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi
#from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [LI()for i in range(n)]
#inf = 10**17
#mod = 10**9 + 7
#s=input().rstrip()
    
r=I()
print(2*r*pi)

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll a, b, t;
  cin >> a >> b >> t;
  cout << t / a * b<< endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    cout << c - min(a - b, c) << endl;

    return 0;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n: proconio::marker::Chars,
    }
    let c = n[n.len() - 1];
    let ans = match c {
        '2' | '4' | '5' | '7' | '9' => "hon",
        '0' | '1' | '6' | '8' => "pon",
        '3' => "bon",
        _ => "",
    };
    println!("{}", ans);
}


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

int N, M, L;
int P[100], T[100], V[100];
double prob[55][100];

void calc(int x)
{
	double p = P[x] / 100.0;
	double rest[55][55];

	for(int i=0; i<=M; i++)
	for(int j=0; j<=M; j++)
		rest[j][i] = 0.0;

	rest[0][0] = 1.0;

	for(int i=0; i<M; i++)
	for(int j=0; j<M; j++)
	{
		rest[i+1][j] += rest[i][j] * (1-p);
		rest[i+1][j+1] += rest[i][j] * p;
	}


	for(int i=0; i<=M; i++)
		prob[i][x] = rest[M][i];
}

void solve()
{
	for(int i=0; i<N; i++)
		calc(i);

	for(int i=0; i<N; i++)
	{
		double res = 0.0;
		for(int j=0; j<=M; j++)
		{
			double p = prob[j][i];
			double ltm = 1.0*L/V[i] + (T[i]*j);

			for(int k=0; k<N; k++)
			{
				if(k==i) continue;
				
				double t = 0.0;
				for(int l=0; l<=M; l++)
				{
					double rtm = 1.0*L/V[k] + (T[k]*l);
					if(ltm < rtm) t += prob[l][k];
				}

				p *= t;
			}

			res += p;
		}

		cout.setf(ios::fixed);
		cout.precision(11);
		cout << res << endl;
	}
}



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

	for(int i=0; i<N; i++)
		cin >> P[i] >> T[i] >> V[i];

	solve();

}

Measured memory_bytes: 992
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	ll N;
	cin >> N;
	string S, T;
	cin >> S >> T;
	for (ll n = 0; n < S.size(); n++) {
		cout << S.substr(n, 1);
		cout << T.substr(n, 1);
	}
	cout << "\n";
	return 0;
}


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

int main() {

    long N, M;
    cin >> N >> M ;

    int A[M];
    for (int i = 0; i < M; i++) {
       cin >> A[i];
    }

    for (int i = 0; i < M; i++) {
        N -= A[i];
    }

    cout << max(N, -1L) << endl;

    return 0;
}


Measured memory_bytes: 3636
#include <cstdio>
#include <climits>
#include <cstring>
#include <algorithm>

const int MAXN = 12;

char str[MAXN];

int getInt(char *p) {
    return (p[0] - '0') * 100 + (p[1] - '0') * 10 + p[2] - '0';
}

int main() {
    scanf("%s", str);
    int n = std::strlen(str);

    int ans = INT_MAX;
    for (int i = 0; i + 2 < n; i++) ans = std::min(ans, std::abs(getInt(str + i) - 753));
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 128
n,*a=map(int,open(0).read().split())
ans=0
s=sum(a)
p=1
b=True
for j in a:
    if p<j:
        print(-1)
        exit()
    ans+=p
    p-=j
    s-=j
    if p<s and b:
        if p*2<s:p*=2
        else:p=s
    if p==s:b=False
print(ans)

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

int main() {
  int n, max_v = 0;
  cin >> n;
  string s;
  map<string, int> S;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (S.count(s))
      S[s]++;
    else
      S[s] = 1;
  }
  for (auto m : S) {
    max_v = max(max_v, m.second);
  }
  
  for (auto m : S) {
    if (m.second == max_v) cout << m.first << endl;
  }
}

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

int main(){

  int n,x;

  while(cin >> n >> x,n+x){
    int cnt=0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	for(int k=j+1;k<=n;k++){
	  if(i+j+k==x) cnt++;
	}
      }
    }
    cout << cnt << endl;
  }
  return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> p(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += p[i];
  }
  int maxsum = sum;
  int maxindex = k - 1;
  for (int i = k; i < n; i++) {
    sum = sum + p[i] - p[i - k];
    if (sum > maxsum) {
      maxsum = sum;
      maxindex = i;
    }
  }
  int ans = k;
  for (int j = 0; j < k; j++) {
    ans += p[maxindex - j];
  }
  cout << fixed << setprecision(10) << (double)(ans / 2.0) << endl;


  return 0;
}


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

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(),greater<int>());
    int score = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            score += a[i];
        } else {
            score -= a[i];
        }
    }
    cout << score << endl;
}


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

void solve(){
  int a, b; cin >> a >> b;
  if(a * b % 2 == 0) cout << "Even\n";
  else cout << "Odd\n";
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
edges = []
for _ in range(M):
    s,t,d = map(int,input().split())
    edges.append((s,t,d))

cost = [-1*float("INF") for _ in range(N+1)]
cost[1] = 0
count = 0
while count < N:
    count += 1
    for s,t,d in edges:
        if cost[s] + d > cost[t]:
            cost[t] = cost[s] + d
ans = cost[N]

negative = [False]*(N+1)
count = 0
while count <= N:
    count += 1
    for s,t,d in edges:
        if cost[s] + d > cost[t]:
            cost[t] = cost[s] + d
            negative[t] = True
for s,t,d in edges:
        if negative[s]:
            negative[t] = True

if negative[N]:
    print("inf")
else:
    print(ans)

Measured memory_bytes: 75140
s=input()

ans='Yes'

if len(s)%2==0:
  for i in range(len(s)):
    if i%2==0:
      if s[i]=='h':
        ans='Yes'
      else:
        ans='No'
        break
    else:
      if s[i]=='i':
        ans='Yes'
      else:
        ans='No'
        break
else:
  ans='No'

print(ans)

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

class Info
{
	public:
	int id;
	string name;
	int p;
};

bool cmp(const Info& lhs,const Info& rhs)
{
	if(lhs.name!=rhs.name)
		return lhs.name<rhs.name;
	return lhs.p>rhs.p;
}

int main()
{
	int N;
	Info info[110]={};

	cin >> N;
	for(int i=0;i<N;i++)
	{
		cin >> info[i].name >> info[i].p;
		info[i].id=i;
	}

	sort(info,info+N,cmp);

	for(int i=0;i<N;i++)
	{
		cout << info[i].id+1 << endl;
	}


	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

vector<ll> calc(const string& s) {
  ll n = SZ(s);
  vector<ll> res(n);
  vector<ll> num(26, -1);
  ll p = 0, c = 0;
  REP(i, n) {
    ll t = s[i] - 'a';
    if (num[t] == -1) {
      num[t] = c;
      res[i] = num[t];
      c++;
      continue;
    }
    res[i] = num[t];
  }
  return res;
}

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

  cout << (calc(s) == calc(t) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3848
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append([i+1,a[i]])
b.sort(key = lambda x:x[1])
for i in range(n):
    if i != n-1:
        print(b[i][0],end=" ")
    else:
        print(b[i][0])

Measured memory_bytes: 22604
#include <iostream>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
using namespace std;
typedef pair<string, int> P;

int iti;
string n;
map<string, int> m;
queue<P> que;
map<string, int>::iterator ite;

void solve(){
	que.push(P("01234567", 0));
	m.insert(make_pair("01234567", 0));
	while(que.size()){
		P p = que.front(); que.pop();
		for(int i = 0; i < 8; i++){
			if(p.first[i] == '0') iti = i;
		}
		if(iti != 3 && iti != 7){
			swap(p.first[iti], p.first[iti+1]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti], p.first[iti+1]);
		}
		if(iti != 0 && iti != 4){
			swap(p.first[iti], p.first[iti-1]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti], p.first[iti-1]);
		}
		if(iti <= 3){
			swap(p.first[iti+4], p.first[iti]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti+4], p.first[iti]);
		}
		else{
			swap(p.first[iti-4], p.first[iti]);
			ite = m.find(p.first);
			if(ite == m.end()){
				que.push(P(p.first, p.second+1));
				m.insert(make_pair(p.first, p.second+1));
			}
			swap(p.first[iti-4], p.first[iti]);
		}
	}
}

int main(){
	solve();
	char trash;
	while(cin >> trash){
		n.push_back(trash);
		for(int i = 1; i < 8; i++){
			cin >> trash;
			n.push_back(trash);
		}
		cout << m[n] << endl;
		n.clear();
	}
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> x(N, vector<int> (2));
    rep(i, N) cin >> x[i][0] >> x[i][1];
    double sum = 0;
    rep(i,N-1) for(int j = i+1; j < N; j++) sum += 2 * (N-1)* sqrt(pow(x[i][0]-x[j][0],2)+pow(x[i][1]-x[j][1],2));
    cout << setprecision(14) << sum / (N * (N-1)) << endl;
    return 0;
}

Measured memory_bytes: 256
import collections

def cmd():
    N, X, Y = map(int, input().split())

    X -= 1
    Y -= 1
    distance = []
    dappend = distance.append

    for i in range(N-1):
        for j in range(i+1,N):
            tmp = min(abs(i-j), abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j))
            distance.append(tmp)

    count = collections.Counter(distance)

    for s in range(1, N):
        print(count.get(s, 0))

if __name__ == "__main__":
    cmd()


Measured memory_bytes: 67808
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = chomp(readline())
	x,y = readline() |> split |> parseMap
	h = Int[]
	v = Int[]
	f = 0
	c = 0
	for i in 1:length(s)
		if s[i] == 'T'
			if f == 0
				push!(h,c)
				f = 1
			else
				push!(v,c)
				f = 0
			end
			c = 0
		else
			c += 1
		end
	end
	if s[length(s)] == 'F'
		if f == 0
			push!(h,c)
		else
			push!(v,c)
		end
	end
	sh = sum(h)
	dph = zeros(Int,length(h), 2*sh+1)
	if length(h)>0
		dph[1,sh+1+h[1]] = 1
	end
	for i in 2:length(h)
		for j in 1:2*sh+1
			if j <= h[i]
				dph[i,j] = dph[i-1,j+h[i]]
			elseif j >= 2*sh+1-h[i]
				dph[i,j] = dph[i-1,j-h[i]]
			else
				dph[i,j] = max(dph[i-1,j+h[i]], dph[i-1,j-h[i]])
			end
		end
	end
	sv = sum(v)
	dpv = zeros(Int,length(v), 2*sv+1)
	if length(v)>0
		dpv[1,sv+1+v[1]] = 1
		dpv[1,sv+1-v[1]] = 1
	end
	for i in 2:length(v)
		for j in 1:2*sv+1
			if j <= v[i]
				dpv[i,j] = dpv[i-1,j+v[i]]
			elseif j >= 2*sv+1-v[i]
				dpv[i,j] = dpv[i-1,j-v[i]]
			else
				dpv[i,j] = max(dpv[i-1,j+v[i]], dpv[i-1,j-v[i]])
			end
		end
	end
	if sh+x+1<0||sh+x+1>2*sh+1||sv+y+1<0||sv+y+1>2*sv+1
		println("No")
	elseif length(h) == 0 && length(v) == 0
		println(x==0&&y==0?"Yes":"No")
	elseif length(h) == 0
		println(x==0&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	elseif length(v) == 0
		println(dph[length(h),sh+x+1]==1&&y==0?"Yes":"No")
	else
		println(dph[length(h),sh+x+1]==1&&dpv[length(v),sv+y+1]==1?"Yes":"No")
	end
end
main()


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

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

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

ll ll_pow(ll a, ll n){
    ll ans = 1;
    FOR(i, 0, n){
        ans *= a;
    }
    return ans;
}

vector<ll> coins;
ll memo[100010];

// a円で支払う最小回数
ll rec(ll a){
    if(memo[a]!=0){
        return memo[a];
    }

    if(a==0) return 0;

    ll min_num = inf;
    for(ll c : coins){
        if(a-c<0) continue;

        ll num = rec(a-c) + 1;
        min_num = min(min_num, num);
    }

    return memo[a] = min_num;
}

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

    // input
    ll N;
    cin >> N;

    coins.push_back(1);
    FOR(i, 1, 7){
        coins.push_back(ll_pow(6, i));
    }
    FOR(i, 1, 6){
        coins.push_back(ll_pow(9, i));
    }
    sort(ALL(coins), greater<ll>());

    ll ans = rec(N);
    p(ans);
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define MAX 3000
int dp[MAX+1][MAX+1];
//dp[i][j] represents from ith index to m and jth index to n what is the LCS
string getit(string &p,string &q,int i,int j,int len){
    string lcs="";
    while(len>0){
        if(p[i]==q[j]){
            lcs.push_back(p[i]);
            i++;
            j++;
            len--;
        }
        else{
            if(dp[i+1][j]>dp[i][j+1]){
                i++;
            }
            else{
                j++;
            }
        }
    }
    return lcs;
}
int LENLCS(string &p,string &q,int i,int j){
    if(i>=p.length() || j>=q.length()) return 0;
    if(dp[i][j]>-1) return dp[i][j];
    if(p[i]==q[j]){
        return dp[i][j]=1+LENLCS(p,q,i+1,j+1);
    }
    else{
        return dp[i][j]=max(LENLCS(p,q,i+1,j),LENLCS(p,q,i,j+1));
    }
}
string getLCS(string p,string q,int i,int j){
    int len=LENLCS(p,q,i,j);
    return getit(p,q,0,0,len);
}
int main(){
    memset(dp,-1,sizeof(dp));
    string s,t;
    cin>>s>>t;
    cout<<getLCS(s,t,0,0)<<endl;
}

Measured memory_bytes: 35968
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
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 MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    ll n; cin >> n;
    ll sum = 0;

    for(ll i=1; i<=n; i++){
        if((i%3!=0) && (i%5!=0)) sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
int main()
{
    int x,n; cin>>x>>n;
    int ans,min=9999;
    int a[n],b[105]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        b[a[i]]=1;
    }
    //sort(a,a+n);
    for(int i=-5;i<105;i++)
    {
        if(b[i]!=1)
        {
            if(abs(x-i)<min)
            {
                min = abs(x-i);
                ans = i;
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3652
import fractions


def main() -> None:
    N = int(input())
    A = list(map(int, input().split()))

    gcd_l = [0]
    gcd_r = [0]
    for i in range(N):
        gcd_l.append(fractions.gcd(gcd_l[i], A[i]))
        gcd_r.append(fractions.gcd(gcd_r[i], A[-(i + 1)]))
    gcd_r = gcd_r[::-1]

    ans = []
    for i in range(N):
        ans.append(fractions.gcd(gcd_l[i], gcd_r[i + 1]))

    print(max(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 16148
n = int(input())
a = list(map(int, input().split()))

def maxheapify(a, i):
    l = i*2 + 1
    r = i*2 + 2

    if r < n:
        if a[l] > a[i]:
            largest = l
        else:
            largest = i
        if a[r] > a[largest]:
            largest = r

        if largest != i:
            memo = a[i]
            a[i] = a[largest]
            a[largest] = memo
            maxheapify(a, largest)

    elif l < n:
        if a[l] > a[i]:
            largest = l
        else:
            largest = i
        if largest != i:
            memo = a[i]
            a[i] = a[largest]
            a[largest] = memo
            maxheapify(a, largest)

for i in reversed(range(n)):
    maxheapify(a, i)

print("", *a)


Measured memory_bytes: 63696
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N){
        ll a;
        cin >> a;
        A[a - 1] = i + 1;
    }

    rep(i, N) print(A[i]);





    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iostream>
// #include <unordered_map>
#define vi vector <ull>
#define ii pair<ull,ull>
#define vii vector<ii>
 
#define seti set<ull>
#define mii map<ull,ull>
#define um unordered_map
#define ll long long
#define ull  long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100100
#define _ << " " <<

ull mod = 1e9+7;
 
using namespace std;

double p[3001];
double dp[3001][3001];

double rec(int n, int m){
	// if(n < 0 || m < 0) return 0.0;
	if(n < m) return 0.0;
	if(n == 0) return 1.0;
	if(dp[n][m] != -1) return dp[n][m];
	return dp[n][m] = rec(n-1, m)*(1-p[n]) + rec(n-1, m-1)*p[n]; 
}


void solve(){
	int n;
	cin >> n;

	for(int i = 0; i < 3001; i++){
		for(int j = 0; j < 3001; j++){
			dp[i][j] = -1;
		}
	}

	for(int i = 0; i < n; i++){
		cin >> p[i+1];
	}
	
	cout << setprecision(10) << rec(n, (n+1)/2);

}
 
 
int main(){
	// freopen("data.in", "r", stdin);
	// freopen("data.out", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ull q;
	// cin >> q;
	q = 1;
	for(ull i = 0; i < q; i++){
		// cout << "Case #" << i+1 << ":" << endl;
 
		solve();
		// cout << endl;
	}
 
	
 
	return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int colors[100] = {};
  int count = 0;
  rep(i, 3) {
    int color;
    cin >> color;
    if (!colors[color - 1]) {colors[color - 1]++; count++;}
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c = gets.split(" ").map{|x|x.to_f}
p a * Math.sin(c * Math::PI / 180) * b / 2
p a + b + (a**2 + b**2 - 2 * a * b * Math.cos(c * Math::PI / 180))**0.5
p (a * Math.sin(c * Math::PI / 180) * b / 2) * 2 / a

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

const int MAX_N = 1003;
int N;
int T[MAX_N];
int A[MAX_N];

void solve()
{
	ll a=T[0],b=A[0];
	for(int i=1;i<N;++i){
		ll p = T[i], q = A[i];
		//np>=a && nq>=b
		const ll n = max((a+p-1)/p,(b+q-1)/q);
		a=n*p,b=n*q;
	}
	cout << a+b;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Edge
{
  int to, id;
};
vector<vector<Edge>> g;
vector<int> ans;
void dfs(int v, int c = -1, int p = -1)
{
  int k = 1;
  for (auto u : g[v])
  {
    int ei = u.id;
    if (u.to == p)
      continue;
    if (k == c)
      k++;
    ans[ei] = k;
    k++;
    dfs(u.to, ans[ei], v);
  }
}
int main()
{
  int N;
  cin >> N;
  g.resize(N);
  ans = vector<int>(N - 1);
  for (int i = 0; i < N - 1; i++)
  {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back((Edge){b, i});
    g[b].push_back((Edge){a, i});
  }
  dfs(0);
  int mx = 0;
  for (int i = 0; i < N; i++)
  {
    mx = max(mx, int(g[i].size()));
  }
  cout << mx << endl;
  for (int i = 0; i < N - 1; i++)
  {
    cout << ans[i] << endl;
  }
  return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

ll func(ll p) {
    if(p%4==1) return 1;
    if(p%4==3) return 0;
    if(p%4==2) return p+1;
    if(p%4==0) return p;
}

int main(void) {
    ll a, b;
    cin >> a >> b;

    ll ans = func(a-1) ^ func(b);

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


Measured memory_bytes: 256
#include<cstdio>

int main(){
    int i,j;
    char s[2000];
    for(j=1;;j++){
        scanf("%s",s);
        if(s[0] == '0') break;      
        int t = '0'- 48;
    for( i = 0; s[i] != '\0';i++){
        t += s[i]-48;  
    }
    printf("%d\n",t);
    }
    return 0;
}


Measured memory_bytes: 2740
/**
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=100200;
ll i,j;
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n,x,t;
cin>>n>>x>>t;
ll ans=0;
ans=(n/x)*t;
if(n%x!=0)
{
    ans+=t;
}
cout<<ans;
return 0;
}


Measured memory_bytes: 3648
# 2019/03/03
# AtCoder Beginner Contest 120 - C

# Input
s = input()

rcnt = 0
bcnt = 0

# Count Red and Blue
for idx in range(len(s)):
    if int(s[idx]) == 0:
        rcnt += 1
    else:
        bcnt += 1

# Calc
rem = abs(rcnt - bcnt)
ans = len(s) - rem

# Output
print(ans)


Measured memory_bytes: 3188
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
from fractions import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')


n = I()
A = LI()
# L = list(accumulate(A, gcd))
# R = list(accumulate(reversed(A), gcd))
tmpl = 0
tmpr = 0
L = []
R = []
for i in range(n):
    tmpl = gcd(tmpl, A[i])
    tmpr = gcd(tmpr, A[-1-i])
    L.append(tmpl)
    R.append(tmpr)

R = list(reversed(R))
# print(L)
# print(R)

ans = max(L[n-2], R[1])
for i in range(1, n-1):
    ans = max(ans, gcd(L[i-1], R[i+1]))

print(ans)


Measured memory_bytes: 94816
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @n = gets.to_s.to_i
  end

  def solve
    ans = Hash.new(0)
    n.times do
      s = gets.chomp
      ans[s] += 1
    end
    ans
  end

  def show(ans)
    %w[AC WA TLE RE].each do |key|
      printf("%s x %d\n", key, ans[key])
    end
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14364
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>


using namespace std;


int main(){
    string S,T;
    cin >> S >> T;

    int ans = 0;

    if(S[0] == T[0]){
        ans++;
    }
    if(S[1] == T[1]){
        ans++;
    }
    if(S[2] == T[2]){
        ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 256