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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2, class T3> void add( T1 &x, T2 y, T3 m = MOD )
{
	x += y;
	if( x >= m )
		x -= m;
}

template<class T1, class T2, class T3> void sub( T1 &x, T2 y, T3 m = MOD )
{
	x -= y;
	if( x < 0 )
		x += m;
}

ll dp[1050], ndp[1050];

int main() 
{
	fastio();

	ll d,g;
	cin>>d>>g;

	g /= 100;

	memset(dp,0,sizeof(dp));
	memset(ndp,0,sizeof(ndp));
	// dp[i] = max score with i problems
	for(int i=0;i<d;i++)
	{
		int problems, bonus;
		cin>>problems>>bonus;
		bonus /= 100;

		for(int j=0;j<1005;j++)
		{
			for(int use=0;use<=problems;use++)
			{
				ll consider = dp[j] + use*(i+1) + ( use == problems ? bonus : 0 );
				ndp[j+use] = max( ndp[j+use], consider );
			}
		}

		for(int j=0;j<1005;j++)
		{
			dp[j] = ndp[j];
			ndp[j] = 0;
		}
	}

	for(int j=0;j<1005;j++)
	{
		if( dp[j] >= g )
		{
			cout<<j,nl;
			break;
		}
	}



	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int[] v=new int[n];
    for(int i=0;i<n;i++){
      v[i]=sc.nextInt();
    }
    int[] c=new int[n];
    for(int i=0;i<n;i++){
      c[i]=sc.nextInt();
    }
    int max=0;
    for(int i=0;i<n;i++){
      max+=Math.max(v[i]-c[i],0);
    }
    System.out.println(max);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

int main(){
  vector<int> a;
  int N;
  int b;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> b;
    a.push_back(b);
  }
  sort(a.begin(),a.end());
  int count1=1,count2=0;
  for(int i=1;i<N;i++){
    if(a[i-1]<=399&&a[i]>=400&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=799&&a[i]>=800&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=1199&&a[i]>=1200&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=1599&&a[i]>=1600&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=1999&&a[i]>=2000&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=2399&&a[i]>=2400&&a[i]<3200){
      count1++;
    }else if(a[i-1]<=2799&&a[i]>=2800&&a[i]<3200){
      count1++;
    }
    if(a[i]>=3200){
      count2++;
    }
  }
  if(count2==0){
    count2=count1;
  }else{
    count2+=count1;
  }
  cout << min(count1,count2)<<" "<<max(count1,count2)<<endl;
}


Measured memory_bytes: 256
from itertools import *
N = int(input())
A = list(accumulate(map(int,input().split())))
l = 0
r = 2
t = A[-1]
a = t

for m in A[1:-2]:
  while abs(t-2*A[r]+m)>abs(t-2*A[r+1]+m):
    r+=1
  while abs(m-2*A[l])>abs(m-2*A[l+1]):
    l+=1
  x = sorted([A[l],m-A[l],A[r]-m,t-A[r]])
  a = min(a,x[3]-x[0])

print(a)

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

int main(){

  string a, b;
  cin >> a;
  cin >> b;
  for (int i = 0; i < 3; i++){
    if (a[i] != b[2-i]){
        printf("NO\n");
        return 0;
    }
  }

  printf("YES\n");

  return 0;
}


Measured memory_bytes: 256
S = list(input())

left =  ''.join(S[0:2])
right = ''.join(S[2:4])


left_flag = 0
right_flag = 0
if int(left) <= 12 and left != '00':
    left_flag = 1

if int(right) <= 12 and right != '00':
    right_flag = 1


if left_flag == 1 and right_flag == 0:
    print('MMYY')
elif left_flag == 1 and right_flag == 1:
    print('AMBIGUOUS')
elif left_flag == 0 and right_flag == 1:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3064
D,G=map(int,input().split()) 
box=[] 
for i in range(D): 
    box.append(list(map(int,input().split()))) 
box.insert(0,[0,0]) #数を１番目に合わせるため 
info=[[0,0] for i in range(2**D)] #各全完の組での点数、解いた問題数の記憶
info2=[[0]*(D+1) for i in range(2**D)] #i番目を何問解いているか？

for i in range(2**D): #全完したものをinfoに追加
    for j in range(1,D+1): #100j点の問題は全完するか 
        if (i>>(j-1))&1: 
            info[i][0]+=box[j][1]+j*100*box[j][0] 
            info[i][1]+=box[j][0] 
            info2[i][j]=box[j][0] #ｊ番目を全問解いている。

for i in range(2**D):
    score=G-info[i][0]
    if score<=0:
        continue
    else:
        n=D
        while score>0:
            num=box[n][0]-info2[i][n] #残りの問題数
            #print(num)
            #print(str(i)+":"+str(score))
            if num!=0:
                for j in range(1,num+1):
                    score -= 100*n
                    info[i][1]+=1 #解いた数を増やす
                    if j==num: #ボーナス点追加
                        score-=box[n][1]
                    if  score<=0:
                        break
            n-=1
            
l=len(info)
for i in range(l-1):
    min=info[i][1]
    m=info[i]
    t=i
    for j in range(i+1,l):
        if min>info[j][1]:
            min=info[j][1]
            t=j
    info[i]=info[t]
    info[t]=m
print(info[0][1])

Measured memory_bytes: 3316
<?php
// Your code here!
$k = trim(fgets(STDIN));
fscanf(STDIN,"%d %d",$a,$b);
$baisu = range($a,$b);
// var_dump($baisu);
$ans = 0;
for($i=0; $i<count($baisu); $i++){
    if($baisu[$i] % $k == 0){
        // var_dump(baisu[$i] % $k)
        $ans = 1;
        break;
    }
}
if($ans == 1){
    echo "OK";
}else{
    echo "NG";
}

?>

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

a.sort(reverse=True)
even = []
for i in range(n):
    if a[i] % 2 == 0:
        even.append(a[i])

three = 0
for i in range(len(even)):
    sub = even[i]
    while sub % 2 == 0:
        three += 1
        sub = sub / 2

print(three)

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

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;cin>>n;
    map<int,int> m;
    int x = (int)sqrt(n);
    
    for(int i=1;i<=x;i++) {
        for(int j=1;j<=x;j++) {
            for(int k=1;k<=x;k++) {
                int sum = (i*i) + (j*j) + (k*k) + (i*j) + (j*k) + (i*k);
                m[sum]++;
            }
        }
    }
    
    for(int i=1;i<=n;i++) {
        cout << m[i] << "\n";
    }
    
    
    return 0;
}

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

int main(void) {
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  //since a<b<c<d<e, we should check only  whether a<e holds
  if(e-a <= k) {
    cout << "Yay!" << endl;
  } else {
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ps_input=[[int(j) if n==0 else j for n,j in enumerate(input().split())]for i in range(m)]

ac_count = [0]*n
penalty= [0]*n
for ps in ps_input:
    if ps[1]=='AC':
        if ac_count[ps[0]-1]==0:
            ac_count[ps[0]-1]=1
    if ps[1]=='WA':
        if ac_count[ps[0]-1]==1:
            continue
        penalty[ps[0]-1]+=1
ans_ac=0
ans_penalty=0
for a,p in zip(ac_count,penalty):
    if a==1:
        ans_ac+=1
        ans_penalty+=p
print(ans_ac,ans_penalty)

Measured memory_bytes: 25080
#include <iostream>

using namespace std;

int main()
{
    int r,x,d;
    int n;
    int v;
    int a;
    int y;
    int p;
    int m;
    int u;
    int o;
    int e;
    int q;
    cin >>r>>d>>x;
    n=r*x-d;
    cout<<n<< endl;
    v=n*r-d;
    cout<<v<<endl;
    a=v*r-d;
    cout<<a<<endl;
    y=a*r-d;
    cout<<y<<endl;
    p=y*r-d;
    cout<<p<<endl;
    m=p*r-d;
    cout<<m<<endl;
    o=m*r-d;
    cout<<o<<endl;
    u=o*r-d;
    cout<<u<<endl;
    e=u*r-d;
    cout<<e<<endl;
    q=e*r-d;
    cout<<q<<' ';
    return 0;

}


Measured memory_bytes: 256
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    s = input()
    n = len(s) - 2
    if s[0] == s[-1]:
        n += 1

    if n % 2:
        ans = 'First'
    else:
        ans = 'Second'

    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int n;
    cin >> n;
    vector<int> div(n+1);
    for (int i=1; i<=n; i++){
        for (int j=i; j<=n; j+=i)
            div[j] += 1;
    }
    long long ans = 0;
    for (int i=1; i<n; i++)
        ans += div[i];
    cout << ans << "\n";
}

Measured memory_bytes: 7128
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007,N=200001;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll fac[N],finv[N],inv[N];
void cominit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=mod-inv[mod%i]*(mod/i)%mod;
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}

vector<vector<ll> > g(N);
ll pa[N];
ll dpinline[N],dpin[N],dpout[N],dpoutline[N];
void dfs1(ll now,ll p){
	pa[now]=p;
	dpinline[now]=0;
	dpin[now]=1;
	for(auto& to:g[now]){
		if(to==p)continue;
		dfs1(to,now);
		dpinline[now]+=dpinline[to];
		(dpin[now]*=finv[dpinline[to]])%=mod;
		(dpin[now]*=dpin[to])%=mod;
	}
	(dpin[now]*=fac[dpinline[now]])%=mod;
	dpinline[now]++;
}
void dfs2(ll now,ll p){
	vector<ll> v1,v2,v3,v4;
	for(auto& to:g[now]){
		if(to==p)v1.pb(1),v2.pb(1),v3.pb(0),v4.pb(0);
		else{
			v1.pb((dpin[to]*finv[dpinline[to]])%mod);
			v2.pb((dpin[to]*finv[dpinline[to]])%mod);
			v3.pb(dpinline[to]);
			v4.pb(dpinline[to]);
		}
	}
	int niko=v1.size();
	for(int i=1;i<niko;i++) (v1[i]*=v1[i-1])%=mod,v3[i]+=v3[i-1];
	for(int i=niko-2;i>=0;i--) (v2[i]*=v2[i+1])%=mod,v4[i]+=v4[i+1];
	for(int i=0;i<niko;i++){
		int to=g[now][i];
		if(to==p) continue;
		ll ret=(dpout[now]*finv[dpoutline[now]])%mod,line=dpoutline[now];
		if(i>0) (ret*=v1[i-1])%=mod,line+=v3[i-1];
		if(i<niko-1) (ret*=v2[i+1])%=mod,line+=v4[i+1];
        (ret*=fac[line])%=mod;
	    dpoutline[to]=line+1,dpout[to]=ret;
		dfs2(to,now);
	}
}

int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(false);
    cominit();
	ll n,a,b;
	cin>>n;
	for(int i=1;i<n;i++){
		cin>>a>>b;
		a--,b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	dfs1(0,-1);
	dpout[0]=1;
	dpoutline[0]=0;
	dfs2(0,-1);
	for(int i=0;i<n;i++){
		ll line=dpoutline[i];
		ll ans=(dpout[i]*finv[dpoutline[i]])%mod;
		for(auto& to:g[i]){
			if(to==pa[i])continue;
			line+=dpinline[to];
			(ans*=dpin[to])%=mod;
			(ans*=finv[dpinline[to]])%=mod;
		}
		(ans*=fac[line])%=mod;
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 36224
#include<stdio.h>
#define MAX 2000010

int Tree[MAX]; // Tree
int n;

void maxHeapify(int i){
  int largest ,exchange, l, r;
  l = getLeft(i);
  r = getRight(i);
  
  if( ( n >= l ) && ( Tree[l] > Tree[i] ) )largest = l;

  else largest = i;
  
  if( ( n >= r ) && ( Tree[r] > Tree[largest] ) )largest = r;

  if (largest != i){

    exchange =  Tree[i];
    Tree[i] = Tree[largest];
    Tree[largest] = exchange;
    maxHeapify(largest);

  }  
}

void buildMaxHeap(){
  int i;
  for (i = (n/2); i >= 1; i--){
    maxHeapify(i);
  }
}

void heapIncrease(int i, int key){
  int exchange;
  if(key < Tree[i])printf("new key is smallar than current key\n");
  
  Tree[i] = key;

  while(( i > 1 ) && ( Tree[getParent(i)] <  Tree[i] )){
    exchange = Tree[i];
    Tree[i] = Tree[getParent(i)];
    Tree[getParent(i)] = exchange;
    i = getParent(i);
  }

}
void maxHeapInsert( key ){
  n = n + 1;
  Tree[n] = -2000000;
 heapIncrease(n, key);
}



int heapExtractMax(){
  int max;
  if( n < 1 )return -1;
  max = Tree[1];
  Tree[1] = Tree[n];
  --n;
  maxHeapify(1);
  return max;
}

int getParent( int i ){
  return i/2;
}

int getLeft(int i){
  return (2*i);
}

int getRight(int i){
  return (2*i + 1);
}


main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  while(1){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      maxHeapInsert(x);
    } else if ( com[0] == 'e' && com[1] == 'x'){
      scanf("%d", &x);
      printf("%d\n",heapExtractMax());
    } else if ( com[0] == 'e' && com[1] == 'n'){
      break;
    }
  }

  return 0;
}

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


int count(long long int  x){
	int res = 0;
	while(x>0){
		x = x/10;
		res++;
	}
	return res;
}


int main(){

	long long int n;
	cin>>n;


	int res = n;
	for(long long int i=1;i*i<=n;i++){
		if(n%i==0){
			res = i;
			//cout<<i<<endl;
		}
	}
	cout<<count(n/res);

}

Measured memory_bytes: 256
x,y,a,b,c=[int(i) for i in input().split()]
p=[int(i) for i in input().split()]
q=[int(i) for i in input().split()]
r=[int(i) for i in input().split()]

p=sorted(p)[::-1]
q=sorted(q)[::-1]

s=p[:x]+q[:y]+r[:]
s=sorted(s)[::-1]
ans=sum(s[:x+y])
print(ans)

Measured memory_bytes: 24232
#include<bits/stdc++.h>
using namespace std;
int ans=0;
void add(int x){
    if (x==1) ans+=300000;
    if (x==2) ans+=200000;
    if (x==3) ans+=100000;
}
int main(){
    int x,y;
    scanf("%d%d",&x,&y);
    add(x);
    add(y);
    if (x==1&&y==1) ans+=400000;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repin(a, n)  \
    vector<ll> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repins(a, n)     \
    vector<string> a(n); \
    rep(i, n) { cin >> a[i]; }
#define repind(a, n)     \
    vector<double> a(n); \
    rep(i, n) { cin >> a[i]; }
#define in(a) \
    ll a;     \
    cin >> a;
#define ins(a) \
    string a;  \
    cin >> a;
#define ind(a) \
    double a;  \
    cin >> a;
template <class T>
inline void out(T a) {
    cout << a << endl;
}
inline void out(double a) { printf("%.10f\n", a); }
#define all(x)        (x).begin(), (x).end()
#define rep2(i, a, b) for (ll i = (a); i < (b); ++i)
#define yes           out("Yes");
#define no            out("No");

int main() {
    in(n);
    ll ans = 0;
    vector<ll> a(n + 1);

    rep2(i, 1, n + 1) {
        for (ll j = i; j < n + 1; j += i) {
            a[j]++;
        }
    }

    rep2(i, 1, n + 1) {
        ans += i * a[i];
    }

    out(ans);
}

Measured memory_bytes: 81372
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ld a,b,x;
    cin >> a >> b >> x;
    if(a*a*b==x){
        cout << 0 << endl;
        return 0;
    }
    if(x>=a*a*b/2){
        ld ans=atan(a*a*a/(2*(a*a*b-x)));
        cout << fixed << setprecision(10) << 90-ans*180/PI << endl;
        return 0;
    }
    cout << fixed << setprecision(10) << 90-atan(2*x/(a*b*b))*180/PI << endl;
}

Measured memory_bytes: 3836
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn gcd(mut a: usize, mut b: usize) -> usize {
    if a<b {
        let mut tmp = a;
        a = b;
        b = tmp;
    } 
    let mut r = a % b;
    while r!=0 {
        a = b;
        b = r;
        r = a % b;
    }
    b
}

#[fastout]
fn main() {
    input!{
        n: usize,
        a: [usize;n],
    }
    
    let mut primes: Vec<usize> = vec![0;1000_000];
    // let mut primes: Vec<usize> = vec![0;11];
    let mut ok = true;
    for i in 0..n {
        let s = (a[i] as f64).sqrt().ceil() as usize;
        let mut a_tmp = a[i];
        for j in 2..s+1 {
            if a_tmp%j==0 {
                while a_tmp%j==0 {
                    a_tmp /= j;
                }
                if primes[j]!=0  {
                    ok = false;
                    break;
                } else {
                    primes[j] += 1;
                } 
            }
        }
        if a_tmp!=1 {
            if primes[a_tmp]!=0 {
                ok = false;
            }
            if primes[a_tmp]==0 {
                primes[a_tmp] += 1;
            }
        }
        if ok==false {
            break;
        }
    }
    // debug!(primes);

    if ok==true {
        println!("pairwise coprime");
        return;
    } else {
        let mut ret = a[0];
        for i in 1..n {
            ret = gcd(ret, a[i]);
        }
        if ret==1 {
            println!("setwise coprime");
        } else {
            println!("not coprime");
        }
    }

}


Measured memory_bytes: 18172
#include <iostream>

using namespace std;
int N, M, Q;
int F[500][500];
int P[500][500];

int sub(int a, int b) {
  return F[a][b];
}

int main() {
  cin >> N >> M >> Q;
  for (int i = 0; i < M; ++i) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    ++P[l][r];
  }
  
  for (int i = N - 1; i >= 0; --i) {
    for (int j = i; j < N; ++j) {
      if (i == j) {
        F[i][j] = P[i][j];
      } else {
        F[i][j] = F[i][j - 1] + F[i + 1][j] - F[i + 1][j - 1] + P[i][j];
      }
    }
  }
  
  for (int i = 0; i < Q; ++i) {
    int a, b;
    cin >> a >> b;
    cout << sub(a - 1, b - 1) << endl;  
  }
}


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

int main(){
int n,m;
cin>>n>>m;
vector<vector<int>>vec(m);
rep(i,m){
int k;cin>>k;
vec[i].resize(k);
rep(j,k){
cin>>vec[i][j];
--vec[i][j];
}
}
vector<int>p(m);
rep(i,m)cin>>p[i];
int ans=0;
for(int i=0;i<(1<<n);++i){
bool ok=true;
rep(j,m){
int c=0;
for(int id:vec[j]){
if((i>>id)&1){++c;}
}
c%=2;
if(c!=p[j]){
ok=false;
}
}
if(ok){++ans;}

}


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

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

using namespace std;
 
#define MD 1000000007
typedef long long int ll;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans=a*100+b*10+c;
    if(ans%4==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    return 0;
}

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

N=int(input())
A=nl()

ans=1

for i in A:
    if(i==0):
        print(0)
        sys.exit(0) 
for i in A:
    ans*=i
    if(10**18<ans):
        print(-1)
        sys.exit(0)

print(ans)

Measured memory_bytes: 23864
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

static const int MAX = 100002;

int n;
int K;
vector<P> G[MAX];
void BFS(int s, vector<int>& ans){
    queue<P> que;
    que.push(make_pair(s, 0));
    while(!que.empty()){
        int u = que.front().first;
        int pre = que.front().second;
        que.pop();
        int tmp = 0;
        rep(i, G[u].size()){
            int v = G[u][i].second;
            int index = G[u][i].first;
            tmp++;
            if(pre==tmp) tmp++;
            ans[index] = tmp;
            que.push(make_pair(v, tmp));
        }
        chmax(K, tmp);
    }
}

int main() {
    cin >> n;
    K=0;

    rep(i, n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(make_pair(i, b));
    }
    vector<int> ans(n-1, 0);
    BFS(0, ans);

    cout << K << endl;
    rep(i, n-1){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5120
#include<iostream>
#include<cmath>
#include<string>
using namespace std;
int main(void)
{
	int n,x=0,i,max=0;
	string s;
	cin>>n>>s;
	for(i=0;i<n;i++)
	{
		if(s[i]=='I')
		{
			x++;
			if(x>max)
			{
				max=x;
			}
		}
		else if(s[i]=='D'){
			x--;
		}
	}
	cout<<max;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,x,y,z,l,n,m,a;
  long long min,max,sum;

  cin >> n >> m;
  vector<vector<int>> A(n, vector<int>(m, 0));
  vector<int> b(m);
  
  for (int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  for(int i = 0; i < m; i++){
    cin >> b.at(i);   
  }
  
  for(int i = 0; i < n; i++){
    sum = 0;
  	for(int j = 0; j < m; j++){
      sum += b.at(j) * A.at(i).at(j);
    }
    cout << sum << endl;
  }

}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

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

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    int k;
    cin >> n >> k;

    string s;
    cin >> s;

    s[k-1] += 32;

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
import itertools
import math
n = int(input())
xy = [list(map(int,input().split()))for _ in range(n)]

ans = 0
for i in itertools.permutations(range(n), n):
    tmp = i[0]
    for j in i:
        ans += (((xy[tmp][0]-xy[j][0])**2 + (xy[tmp][1]-xy[j][1])**2)**0.5)
        tmp = j
print(ans/math.factorial(n))

Measured memory_bytes: 3064
import sys
input = lambda: sys.stdin.readline().rstrip()
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
mod = 1000000007

a, b, c, k = map(int, input().split())

ans = 0
if k <= a:
    ans += k
else:
    ans += a
    if k - a <= b:
        pass
    else:
        ans += -1 *(k - a - b)

print(ans)

Measured memory_bytes: 70964
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  ll k; cin>>k;
  bool c=1;
  rep(i,s.size()){
    if(s[i]!='1'){
      if(i>=k)
      cout<<1<<endl;
      else
      cout<<s[i]<<endl;
      c=0;
      break;
    }
  }
  if(c)
  cout<<1<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <set>
#include <vector>
#include <functional>
#include <map>
#include <queue>
using namespace std;
int main()
{
  int X,Y;
  long long M;
  cin>>X>>Y;
  if (X%Y==0) cout<<"-1\n";
  else cout<<X<<endl;
  //system("pause");
  return 0;
}

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



int main(){
    ll a,b,c;cin>>a>>b>>c;
    bool bol;
    if(a==b){
        if(a!=c){
            bol=true;
        }else{
            bol=false;
        }
    }else{
        if(a==c){
            bol=true;
        }else if(b==c){
            bol=true;
        }else{
            bol=false;
        }
    }
    if(bol){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
    return 0;
}



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

struct TS{
    int n;
    vector< vector<int> > edge;
    vector<int> res;

    void init(int size){
        n = size;
        edge.assign(n, vector<int>());
    }

    void add_edge(int from, int to){
        if(from < 0 || from >= n || to < 0 || to >= n){
            //
            return;
        }
        edge[from].push_back(to);
    }

    bool topological_sort(){
        vector<int> deg(n, 0);
        queue<int> q;

        for(int i = 0; i < n; i++){
            for(int j = 0; j < edge[i].size(); j++){
                deg[edge[i][j]]++;
            }
        }

        for(int i = 0; i < n; i++){
            if(deg[i] == 0)q.push(i);
        }

        res.clear();
        while(!q.empty()){
            int v = q.front(); q.pop();
            res.push_back(v);
            for(int i = 0; i < edge[v].size();i++){
                if(--deg[edge[v][i]] == 0){
                    q.push(edge[v][i]);
                }
            }
        }

        return res.size() == n;
    }
};
int main(void){
    int n, m, p[100000];
    TS ts;
    cin >> n >> m;
    ts.init(n);
    for(int i=0;i<n-1+m;i++){
        int a, b;
        cin >> a >> b;
        ts.add_edge(--a, --b);
    }
    ts.topological_sort();
    p[ts.res[0]] = 0;
    for(int i=0;i<n;i++){
        int v = ts.res[i];
        for(int j=0;j<ts.edge[v].size();j++){
            p[ts.edge[v][j]] = v+1;
        }
    }

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


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

using namespace std;

#define vec vector
#define ALL(x) (x).begin(), (x).end()

typedef unsigned int ui;
typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;

const int inf = 1e9;
const ll inf64 = 1e18;

int main() {

#ifdef debug
    freopen("input.txt", "r", stdin);
#endif

    int n, k;

    cin >> n >> k;

    ll res = 0;

    for(int b = 1;b <= n;b++) {
        for(int p = 0;p * b <= n;p++) {
            int l = 1;
            int r = n;
            l = max(l, p * b + k);
            r = min(r, b * p + b - 1);
            if(l <= r) {
                res += r - l + 1;
            }
        }
    }

    cout << res << "\n";

    return 0;
}


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

int main() {
  int a, b;
  string reply;

  cin >> a >> b;

  if (((a %= 2) == 0) || ((b %= 2) == 0)) {
    reply = "Even";
  } else {
    reply = "Odd";
  }
  cout << reply << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

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

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

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


int main(){
ll a,b;
cin>>a>>b;
if(a<=b){
    cout<<a<<endl;
}
else{
    cout<<a-1<<endl;
}
}









Measured memory_bytes: 256
def main():
    S = input().strip()
    T = input().strip()
    result = solve(S, T)
    print(result)


def solve(S, T) -> int:
    count = 0
    for i in range(len(S)):
        if S[i] != T[i]:
            count += 1
    return count


if __name__ == '__main__':
    main()


Measured memory_bytes: 9432
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, r;
    cin >> n >> r;
    if (n >= 10)
    {
        cout << r << endl;
    }
    else
    {
        cout << r + 100 * (10 - n) << endl;
    }
}

Measured memory_bytes: 764
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn calc(v: usize, n: usize, used: usize) -> usize {
    if v > n {
        return 0;
    }
    let mut ret = 0;
    if used == 7 {
        ret = 1;
    }
    for i in 0..3 {
        let nused = used | (1 << i);
        let t = [7, 5, 3][i];
        let nv = v * 10 + t;
        ret += calc(nv, n, nused);
    }
    return ret;
}

fn main() {
    let n = read::<usize>();
    let ans = calc(0, n, 0);
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int H, W, N;
string S, T;

bool check(int x, int ux, char tc, int ti, char ac, int ai){
	for(int i = 0; i < N; i++){
		if(S[i] == tc){
			x += ti;
			if(x < 0 || ux <= x){
				return true;
			}
		}

		if(T[i] == ac){
			if(0 <= x + ai && x + ai < ux){
				x += ai;
			}
		}
	}

	return false;
}

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

	cin >> H >> W >> N;

	int sr, sc;
	cin >> sr >> sc;
	sr--;
	sc--;

	cin >> S >> T;

	if(check(sr, H, 'D', 1, 'U', -1)){
		// cout << 1 << endl;
		cout << "NO" << endl;
		return 0;
	}

	if(check(sr, H, 'U', -1, 'D', 1)){
		// cout << 2 << endl;
		cout << "NO" << endl;
		return 0;
	}

	if(check(sc, W, 'R', 1, 'L', -1)){
		// cout << 3 << endl;
		cout << "NO" << endl;
		return 0;
	}

	if(check(sc, W, 'L', -1, 'R', 1)){
		// cout << 4 << endl;
		cout << "NO" << endl;
		return 0;
	}

	cout << "YES" << endl;
}


Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  int n,m;
  cin >> n >> m;
  vector<char> ans(n,'a');
  bool ok = true;
  rep(i,m){
    int s;
    char c;
    cin >> s >> c;
    if(ans[s-1]=='a'){
      ans[s-1] = c;
    }
    else if(c!=ans[s-1]){
      ok=false;
    }
  }
  
  if(!ok) cout << -1 << endl;
  else if(n==1){
    if(ans[0]=='a') cout << 0 << endl;
    else cout << ans[0] << endl;
  }
  else{
    if(ans[0]=='0' || !ok)  cout << -1 << endl;
    else{
      rep(i,n){
	if(ans[i]=='a'){
	  if(i==0) cout << 1;
	  else cout << 0;
	}
	else cout << ans[i];
      }
      cout << endl;
    }
  }


  return 0;
    

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    string S, res;
	cin >> S;
    int Ssize = S.size();
    res = "YES";
    for (int i = Ssize - 1; i >= 0; i--) {
        if (S[i] == 'e' && S[i-1] == 's' && S[i-2] == 'a' && S[i-3] == 'r' && S[i-4] == 'e') {
            i -= 4;
        } else if (S[i] == 'm' && S[i-1] == 'a' && S[i-2] == 'e' && S[i-3] == 'r' && S[i-4] == 'd') {
            i -= 4;
        } else if (S[i] == 'r' && S[i-1] == 'e' && S[i-2] == 's' && S[i-3] == 'a' && S[i-4] == 'r' && S[i-5] == 'e') {
            i -= 5;
        } else if (S[i] == 'r' && S[i-1] == 'e' && S[i-2] == 'm' && S[i-3] == 'a' && S[i-4] == 'e' && S[i-5] == 'r' && S[i-6] == 'd') {
            i -= 6;
        } else {
            res = "NO";
            break;
        }
    }
    cout << res << endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string s;
  cin >> s;
  int n=s.size();
  int k=0;
  
  for(int i=0;i<n/2;i++){
    if(s.at(i)!=s.at(n-1-i)){
      k++;
      break;
    }
  }
  
  if(k==0){
    for(int i=0;i<n/4;i++){
      if(s.at(i)!=s.at(n/2-1-i)){
        k++;
        break;
      }
    }
  }
    
  if(k==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <stdio.h>

using namespace std;

int main() {
	double a, b, c, d, e, f;
	double x, y;

		while(cin >> a >> b >> c >> d >> e >> f){

		y = (c * d - a * f) / (b * d - a * e);
		x = (c - (b * y)) / a;

		printf("%.3f %.3f\n", x, y);

	}
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int n;cin>>n;
  vi d(n);
  rep(i,n) cin>>d.at(i);
  sort(all(d));
  cout<<d.at(n/2)-d.at(n/2-1)<<endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        long X = RLong();
        var ans = 0L;
        ans += (X / 500) * 1000;
        X %= 500;
        ans += X / 5*5;
        WriteLine(ans);
            
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 27524
N=gets.to_i
S=gets.chomp
check=false
if N % 2 == 0
  first = S[0..(N/2-1)]
  second = S[N/2..-1]
  if first == second
    check=true
  end
end
if check
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 3836
#include<stdio.h>
#define N 250



int main(){
  int i,n,j,a;
  int A[N];

  scanf("%d",&n);

  for(i = 1 ; i<=n ; i++){
    scanf("%d",&A[i]);
  }

  for(i = 1 ; i<=n ; i++){
    j=a=i;
    
    printf("node %d: key = %d, ",i,A[i]);
    if(j/2 >= 1) printf("parent key = %d, ",A[a/2]);
    if(2*j <= n) printf("left key = %d, ",A[a*2]);
    if(2*j+1 <= n) printf("right key = %d, ",A[a*2+1]);
    printf("\n");
  }
 
  return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

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

    int sum1=0;
    for(int i=0; i<n; i++){
        if(i % 2 == 0 && s[i] == '1') sum1++;
        if(i % 2 == 1 && s[i] == '0') sum1++;
    }

    int sum2=0;
    for(int i=0; i<n; i++){
        if(i % 2 == 0 && s[i] == '0') sum2++;
        if(i % 2 == 1 && s[i] == '1') sum2++;
    }

    cout << min(sum1, sum2) << endl;
}

Measured memory_bytes: 512
fun main(args: Array<String>) {
    val mod = 1000000007L
    
    val (N, K) = readInputLine().split(" ").map { it.toInt() }
    
    val AArr = readInputLine().split(" ").map { it.toInt() }

    var innerCnt = 0L
    var allCnt = 0L
    
    for (i in 0 until N) {
        var befCnt = 0L
        var aftCnt = 0L
        for (j in 0 until N) {
            if (AArr[i] > AArr[j]) {
                if (i > j) {
                    allCnt++
                } else {
                    innerCnt++
                    allCnt++
                }
            }
        }
    }
    
    val ans = ((innerCnt * K.toLong()) % mod + (allCnt * (K.toLong() * (K - 1).toLong() / 2L % mod) % mod)) % mod

    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int N, M, K;
vector<int> Y[300301];
int cnt[300301];
priority_queue<int> pq, del;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> M >> K;
	for(int i=0; i<K; i++)
	{
		int y, x;
		cin >> y >> x;
		Y[y].push_back(x);
		cnt[x]++;
	}

	for(int x=1; x<=M; x++)
		pq.push(cnt[x]);

	int res = 0;
	for(int y=1; y<=N; y++)
	{
		for(int x : Y[y])
		{
			del.push(cnt[x]);
			cnt[x]--;
			pq.push(cnt[x]);
		}

		while(!pq.empty() && !del.empty() && pq.top() == del.top())
			pq.pop(), del.pop();
		
		if (pq.empty())
		{
			int val = (int)Y[y].size();
			res = max(res, val);
		}
		else
		{
			int val = pq.top() + (int)Y[y].size();
			res = max(res, val);
		}

		for(int x : Y[y])
		{
			del.push(cnt[x]);
			cnt[x]++;
			pq.push(cnt[x]);
		}
	}
	cout << res;
	return 0;
}

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

typedef long long ll;

int main() {
    string s, t;
    int n;
    cin >> s >> t;
    vector<int> start(26, -1);
    vector<int> goal(26, -1);

    n = s.size();
    for (int i = 0; i < n; i++) {
        int a = s[i] - 'a';
        int b = t[i] - 'a';
        if (start[a] == -1 && goal[b] == -1) {
            start[a] = b;
            goal[b] = a;
        } else {
            if (start[a] != b || goal[b] != a) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 776
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }
    

    Scanner cin;


    List<int>[] es;
    int[] color;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        es = new List<int>[N];
        for (int i = 0; i < N; i++)
        {
            es[i] = new List<int>();
        }

        for (int i = 0; i < N - 1; i++)
        {
            int a = cin.nextInt() - 1;
            int b = cin.nextInt() - 1;
            es[a].Add(b);
            es[b].Add(a);
        }
        color = new int[N];
        for (int i = 0; i < N; i++)
        {
            color[i] = -1;
        }

        Queue<int> q = new Queue<int>();
        q.Enqueue(0);
        color[0] = 0;
        q.Enqueue(N - 1);
        color[N - 1] = 1;
        
        while(q.Count != 0)
        {
            int now = q.Dequeue();
            foreach (var next in es[now])
            {
                if (color[next] != -1) continue;
                color[next] = color[now];
                q.Enqueue(next);
            }
        }

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

        if (A > B) Console.WriteLine("Fennec");
        else Console.WriteLine("Snuke");
        
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 29272
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, c; cin >> n >> c;
  vector<vector<int> > cnt(3, vector<int>(c, 0)), d(c, vector<int>(c));
  REP(i, c) REP(j, c) cin >> d[i][j];
  REP(i, n) REP(j, n) {
    int cij; cin >> cij; --cij;
    ++cnt[(i + j) % 3][cij];
  }
  int ans = INF;
  REP(i, c) {
    int iwakan1 = 0;
    REP(x, c) iwakan1 += cnt[0][x] * d[x][i];
    REP(j, c) {
      if (j == i) continue;
      int iwakan2 = 0;
      REP(x, c) iwakan2 += cnt[1][x] * d[x][j];
      REP(k, c) {
        if (k == i || k == j) continue;
        int iwakan3 = 0;
        REP(x, c) iwakan3 += cnt[2][x] * d[x][k];
        chmin(ans, iwakan1 + iwakan2 + iwakan3);
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

#define intt long long 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n;
int a[N];

int main() {

	FAST;

	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256