akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

vector<int> suuzi(ll a) {
    vector<int> kk;
    while (1) {
        v = a % 10;
        kk.emplace_back(v);
        if (a < 10) {
            break;
        }
        a /= 10;
    }
    reverse(kk.begin(), kk.end());
    return kk;
}

int main(void) {
    cin >> n;
    vector<vector<ll> > dp(10, vector<ll>(10, 0));

    vector<int> nn = suuzi(n);
    
    for (i = 0; i <= n; ++i) {
        vector<int> num = suuzi(i);
        dp[num[0]][num[num.size() - 1]]++;
    }

    a = 0;

    for (i = 1; i < 10; ++i) 
        for (j = 1; j < 10; ++j)
            a += dp[i][j] * dp[j][i];

    cout << a << endl; 

    return 0;
}



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

using namespace std;


/* Driver program to test above function */
int main() 
{ 
	vector<int> ABC(11);
	for(int i = 0; i < 3; i++){
		int idx; cin >> idx;
		ABC[idx]++;
	}
	if(ABC[5] == 2 && ABC[7] == 1) cout << "YES\n";
	else cout << "NO\n";
	return 0; 
} 


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

using namespace std;

int main() {
	int N;
	cin >> N;
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i++) {
		for (int j = 0; j < N; j++) {
			if (S[i] == 'Z') S[i] = 'A';
			else S[i]++;
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <set>
#include <vector>
#include <cmath>
#include <string>
#define ll long long
#define read(x) scanf("%d",&x);
#define readll(x) cin>>x;
#define FOR(x,a,b) for(int x=a;x<b;x++)
#define MP make_pair
#define PB push_back
#define pii pair<int,int>
#define readN(N,X) for(int i=0;i<N;i++) cin>>X[i];
#define pff pair<double,double>
using namespace std;

long long fastpow(int a, int b, int MOD)
{
    long long x=1,y=a; 
    while(b > 0)
    {
        if(b%2 == 1)
        {
            x=(x*y) % MOD;
        }
        y = (y*y) % MOD;
        b /= 2;
    }
    return x;
}

long long InverseEuler(int n, int MOD)
{
    return fastpow(n,MOD-2,MOD);
}
 
long long f[300000];
bool init;
long long C(int n, int r, int MOD)
{
    if (!init){
        init=1;
        f[0]=1;
        for (int i=1; i<300000;i++)
            f[i]= (f[i-1]*i) % MOD;
        
    }
    return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
int N;
int a[220000];
int b[220000];

int main(){
  std::ios::sync_with_stdio(false);    
  cin>>N;
  readN(N,a);
  for (int i=0;i<N;i++){
    b[i] = a[i];
  }
  sort(a, a+N);

  for (int i=0;i<N;i++){
    if (b[i] < a[N/2]) cout<<a[N/2]<<endl;
    else cout<<a[N/2-1]<<endl;
  }
}


Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;

long long int gcd(long long int m,long long int n){
	if(m==0||n==0){
		return 0;
	}
	while(true){
		if(m>n){
			m %=n;
			if(m==0){
				return n;
			}
		}
		else{
			n %=m;
			if(n==0){
				return m;
			}
		}

	}
}
long long int lcm(long long int m,long long int n){
	if(m==0||n==0){
		return 0;		
	}
	else{
		return ((m/gcd(m,n))*n);
	}
}

int main() {
	long long int a,b,G,L;
	while(true){
		cin>>a>>b;
		if (cin.eof())break;
		G=gcd(a,b);
		L=lcm(a,b);
		cout<<G<<" "<<L<<endl;
	}
}

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

int main(void){
    int a, b, ans;
	char op;
	while(1){
		cin >>a >>op >>b;
		if(op=='?'){
			break;
		}
		switch(op){
		case '+':
			ans=a+b;
			break;
		case '-':
			ans=a-b;
			break;
		case '*':
			ans=a*b;
			break;
		case '/':
			ans=a/b;
			break;
		}
		cout <<ans <<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i32>();
    let (n, l) = (v[0], v[1]);
    let mut tastes = vec![0i32; n as usize];
    for i in 0..n {
        tastes[i as usize] = l + i;
    }
    let mut ans = tastes.iter().sum::<i32>();
    let mut min_idx = 0;
    for i in 0..n {
        if tastes[min_idx].abs() > tastes[i as usize].abs() {
            min_idx = i as usize;
        }
    }
    ans -= tastes[min_idx];

    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<iostream>
int main() {
	int a, b;
	std::cin >> a >> b;
	if ((a + b) % 2 == 0) {
		std::cout << (a + b) / 2 << std::endl;
	}
	else {
		std::cout << (a + b) / 2+1 << std::endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
const int maxn=1e5+10;
int n,a,b,c,d;
struct da{int a,b,c;char d;}pre[maxn][5][5][5];
bool dp[maxn][5][5][5];
char s[5],ans[maxn];
int main()
{
	scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
	dp[0][min(a,4)][min(b,4)][min(c,4)]=1;
	for (int i=1;i<=n;i++)
	{
		scanf("%s",s+1);
		if (s[1]=='A' && s[2]=='B')
		{
			for (int j=0;j<=4;j++)
			 for (int k=0;k<=4;k++)
			  for (int l=0;l<=4;l++)
			  if (dp[i-1][j][k][l])
			  {
			   	if (j>=1) dp[i][j-1][min(k+1,4)][l]=1,pre[i][j-1][min(k+1,4)][l]={j,k,l,'B'};
			   	if (k>=1) dp[i][min(j+1,4)][k-1][l]=1,pre[i][min(j+1,4)][k-1][l]={j,k,l,'A'};
			  }
		}
		if (s[1]=='A' && s[2]=='C')
		{
			for (int j=0;j<=4;j++)
			 for (int k=0;k<=4;k++)
			  for (int l=0;l<=4;l++)
			  if (dp[i-1][j][k][l])
			  {
			   	if (j>=1) dp[i][j-1][k][min(l+1,4)]=1,pre[i][j-1][k][min(l+1,4)]={j,k,l,'C'};
			   	if (l>=1) dp[i][min(j+1,4)][k][l-1]=1,pre[i][min(j+1,4)][k][l-1]={j,k,l,'A'};
			  }
		}
		if (s[1]=='B' && s[2]=='C')
		{
			for (int j=0;j<=4;j++)
			 for (int k=0;k<=4;k++)
			  for (int l=0;l<=4;l++)
			  if (dp[i-1][j][k][l])
			  {
			   	if (k>=1) dp[i][j][k-1][min(l+1,4)]=1,pre[i][j][k-1][min(l+1,4)]={j,k,l,'C'};
			   	if (l>=1) dp[i][j][min(k+1,4)][l-1]=1,pre[i][j][min(k+1,4)][l-1]={j,k,l,'B'};
			  }
		}
	}
	bool ok=0; da now={0,0,0,'A'};
	for (int i=0;i<=4;i++)
	 for (int j=0;j<=4;j++)
	  for (int k=0;k<=4;k++) 
	  if (dp[n][i][j][k]) {ok=1; now={i,j,k,'A'};}
	if (!ok) {printf("No\n"); return 0;}
	printf("Yes\n");
	for (int i=n;i>=1;i--) ans[i]=pre[i][now.a][now.b][now.c].d,now=pre[i][now.a][now.b][now.c];
	for (int i=1;i<=n;i++) printf("%c\n",ans[i]);
return 0;
}

Measured memory_bytes: 211440
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
const int INF=10000000;
int map[21][21];
 
int main(void){
    int a,b,c;
    int d[4];
    int ans;
    int n,m;
    for(a=0;a<=20;a++){
        for(b=0;b<=20;b++){
            map[b][a]=INF;
            if(b==a)map[b][a]=0;
        }
    }
    cin >> n;
    cin >> m;
    for(a=0;a<m;a++){
        scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3]);
        map[d[0]][d[1]]=d[2];
        map[d[1]][d[0]]=d[3];
    }
    for(a=1;a<=n;a++){
        for(b=1;b<=n;b++){
            for(c=1;c<=n;c++){
                map[c][b]=min(map[c][b],map[c][a]+map[a][b]);
            }
        }
    }
    scanf("%d,%d,%d,%d",&d[0],&d[1],&d[2],&d[3]);
    ans=d[2]-d[3]-map[d[0]][d[1]]-map[d[1]][d[0]];
    cout << ans <<endl;
    return 0;
}


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

int main(){
    int n,cnt =0;
    int max = 0;
    string s;
    cin >> n >> s;
    int a[30] = {}, b[30]={};
    
    for(int i=0; i< n ; i++){
        for(int j=0; j< n ; j++){
            if(j < (i+1)){
                a[s[j] - '0' - 49]++;
            }else{
                b[s[j] - '0' - 49]++;
            }
        }
        for (int j = 0; j < 26; j++) {
            if (a[j] > 0 && b[j]>0) {
                cnt++;
            }
            a[j]=0;
            b[j]=0;
        }
        
        if(cnt > max){
            max = cnt;
        }
        cnt = 0;

    }
    
    cout << max << endl;
    
    return 0;
}


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

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000001;
using namespace std;
typedef long long ll;

int n;
int a[100100];

int main(){
  std::cin >> n ;
  a[0] = 0;
  rep(i,1,n+1)std::cin >> a[i];
  a[n+1] = 0;
  ll all=0;
  rep(i,1,n+2){
    all += abs(a[i]-a[i-1]);
  }
  rep(i,1,n+1){
    ll res = all +abs(a[i+1]-a[i-1]) -abs(a[i+1]-a[i])-abs(a[i]-a[i-1]);
    std::cout << res << '\n';
  }
}


Measured memory_bytes: 1664
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace

solve :: Int -> [Int] -> [Int]
solve n xs = map f xs
  where
    m = n `div` 2
    [p,q] = take 2 $ drop (m - 1) $ sort xs
    f x | x <= p    = q
        | otherwise = p

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> [Int]
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      line2:remLines2 = remLines1
      xs = map readBInt line2
  in solve n xs

outAnswer :: [Int] -> IO ()
outAnswer xs = putStr $ unlines $ map show xs

main :: IO ()
main = outAnswer . tmain =<< B.getContents


Measured memory_bytes: 47484
from collections import Counter

from scipy.misc import comb

N, A, B = map(int, input().split())
v = [int(x) for x in input().split()]

v = sorted(v, reverse=True)
m = sum(v[:A]) / A

c = Counter(v)
w = sorted(list(set(v[:A])), reverse=True)
if len(w) > 1:
    n = 0
    for x in w[:-1]:
        n += c[x]
    a = A - n
    b = A - n
    p = c[w[-1]]
else:
    a = A
    b = min(B, c[w[0]])
    p = c[w[0]]

ans = 0
for i in range(a, b + 1):
    ans += comb(p, i, exact=True)

print('{:f}'.format(m))
print(ans)


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

int main() {
    int N, M;
    cin >> N >> M;
    int l = 1, r = N + 1;
    for(int i=0; i<M; ++i) {
        int L,R;
        cin >> L >> R;
        l = max(l, L);
        r = min(r, R + 1);
    }
    cout << max(r - l, 0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  ll n;
  cin >> n;

  ll low = 0, high = 100000;
  while(high - low > 1){
    ll mid = (low + high) / 2;
    if(mid * mid <= n){
      low = mid;
    }
    else{
      high = mid;
    }
  }

  cout << (low * low) << endl;

  return 0;
}


Measured memory_bytes: 508
#include <iostream>
#include <string.h>

using namespace std;
 
int main(){
  int N;
  char S[10000];
  cin >> N >> S;
  
  for(int i = 0;i < strlen(S);i++){
    if(S[i] + N <= 'Z'){
      S[i] = S[i] + N;
    }else{
      S[i] = S[i] + N - 'Z' - 1 + 'A';
    }
  }
  
  for(int i = 0;i < strlen(S);i++){
    cout << S[i];
  }
  
}

Measured memory_bytes: 256
K , A , B = map(int, input().split())
ma = 0
if A >= B:
    ma = K + 1
elif A < B:
    if (K-A+1)%2 == 0:
        ma = max(((K-A+1)//2-1)*(B-A)+B,K+1)
    elif (K-A+1)%2 == 1:
        ma = max(((K-A+1)//2-1)*(B-A)+B+1,K+1)
print(ma)


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	if a > b {
		a, b = b, a
	}

	if a == 1 && b == 2 {
		fmt.Println(3)
	} else if a == 1 && b == 3 {
		fmt.Println(2)
	} else if a == 2 && b == 3 {
		fmt.Println(1)
	}
}


Measured memory_bytes: 512
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

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")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    let a:i32 = read();    
    let b:i32 = read();

    println!("{}", max(a+b,max(a-b,a*b)));

}


Measured memory_bytes: 4352
#!/usr/bin/env python3

import math

n, k = list(map(int, input().split()))

ans = 0
for i in range(1, n+1):
    x = max(0, math.ceil(math.log(k/i, 2)))
    # print(x)
    ans += 1/n*(0.5)**x
print(ans)


Measured memory_bytes: 2940
from math import factorial

mod = 10**9 + 7

H, W, A, B = map(int, input().split())
memo_fact = [1] * (H + W - 1)
memo_denometer = {}
for i in range(1, H + W - 1):
    memo_fact[i] = memo_fact[i - 1] * i % mod

def nCr(n,r):
    numerator = memo_fact[n]
    if (n, r) in memo_denometer:
        denometer = memo_denometer[(n, r)]
    else:
        denometer = pow(memo_fact[r], mod-2, mod) * pow(memo_fact[n-r], mod-2, mod)
    return (numerator * denometer) % mod

result = 0
for i in range(1, H - A + 1):
    result += (nCr((B-1)+(i-1), i-1) * nCr((W-B-1)+(H-i), W-B-1)) % mod
print(int(result % mod))

Measured memory_bytes: 10868
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
  string s;
   int n,a,b;
   cin >>n>>s;
   a=0;
   rep(i,n-2){
     b=i;
    if(s.at(b)=='A'&&s.at(b+1)=='B'&&s.at(b+2)=='C'){
    a++;
    }
   }
   cout<<a<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll a,b,c;
    cin>>a>>b>>c;
    if(a+b-c<0&&(a+b-c)*(a+b-c)>4*a*b) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rapido ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

void solve()
{
  string s;cin>>s;
  int sum=0;
  for(char c:s)
  sum+=c-'0';
  
  if(sum%9==0)
  cout<<"Yes"<<endl;
  else
  cout<<"No"<<endl;
}
int32_t main()
{
    rapido;
    int t;
    // cin>>t;
    t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 3760
/// 20-01-2018
/// MD:NUR ALAM
/// Eastern University of Bangladesh

#include "bits/stdc++.h"

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = (a); i < (b); ++i)
#define fo(i, a, b) for (int i = (a); i <(b); ++i)
#define fors(i, s) for (int i = 0; s[i]; ++i)
#define rs(x) scanf("%s", (x))
#define mp make_pair
#define pb push_back
#define mso(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define len(X) strlen(x)

using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef long double lu;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpll;
typedef pair<int,int> Pll;
typedef map<string,int>msi;
typedef set<int>se;

template<class t> void _r(t &x) { cin >> x; }
void _r(int &x) { scanf("%d", &x); }
void _r(int64_t &x) { scanf("%lld", &x); }
void _r(double &x) { scanf("%lf", &x); }
void _r(char &x) { scanf(" %c", &x); }
void _r(char *x) { scanf("%s", x); }
void r() {}
template<class t, class... u> void r(t &head, u &... tail) { _r(head); r(tail...); }
template<class t> void _w(const t &x) { cout << x; }
void _w(const int &x) { printf("%d", x); }
void _w(const int64_t &x) { printf("%lld", x); }
void _w(const double &x) { printf("%.16f", x); }
void _w(const char &x) { putchar(x); }
void _w(const char *x) { printf("%s", x); }
template<class t,class u> void _w(const pair<t,u> &x) {_w(x.f); putchar(' '); _w(x.s);}
void w() {}
template<class t, class... u> void w(const t &head, const u &... tail) { _w(head); putchar(sizeof...(tail) ? ' ' : '\n'); w(tail...); }
template<class t, class... u> void debug(const t &head, const u &... tail) {
#ifdef HOME
#endif
}

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

int main()
{
   set<int>s;
   int n;
   r(n);
   ll a[n];
   fo(i,0,n)
   {
       r(a[i]);
   }
   fo(i,0,n)
   {
       s.insert(a[i]);
   }
   w(s.size());
}


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

int main(){
  int h = 0, m = 0, s = 0;
  cin >> s;
  h = (s >= 3600) ? (s / (60 * 60)) : 0;
  m = (s >= 60) ? ((s % 3600) / 60) : 0;
  s = (s % 60);
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}



Measured memory_bytes: 3100
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from collections import deque,defaultdict,Counter
def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    deg = [0] * N
    for _ in range(M + N - 1):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        deg[b] += 1
        G[a].append(b)
    
    ans = [-1] * N
    for i in range(N):
        if deg[i] == 0:
            root = i
            ans[root] = 0
            break
    
    q = deque([root])
    while q:
        v = q.popleft()
        for e in G[v]:
            deg[e] -= 1
            if deg[e] == 0:
                ans[e] = v + 1
                q.append(e)
    print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 30096
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    cout << (n + 1) % 2 << endl;
    return 0;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    ans = 0
    for i in range(1, N+1):
        target = i
        current = 1
        while True:
            target = i * current
            current += 1
            if target > N:
                break
            ans += target
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 73076
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N;
vector<i64> A;
vector<i64> B;

int main() {
  cin >> N;
  A.resize(N);
  B.resize(N);
  rep(i,0,N - 1) cin >> A[i];
  rep(i,0,N - 1) cin >> B[i];
  {
    i64 s = 0;
    i64 t = 0;
    rep(i,0,N - 1) s += A[i];
    rep(i,0,N - 1) t += B[i];
    if(s < t) {
      cout<< -1 << endl;
      return 0;
    }
  }
  priority_queue<i64> que;
  i64 neg = 0;
  i64 cnt = 0;
  rep(i,0,N - 1) {
    if(A[i] >= B[i]){
      que.push(A[i] - B[i]);
    }
    else {
      cnt++;
      neg += B[i] - A[i];
    }
  }
  while(neg > 0) {
    cnt++;
    i64 d = que.top();
    que.pop();
    neg -= d;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 2936
def main():
    n = int(input())
    a = list(map(int,input().split()))
    sa,wa = {},{}
    for i in range(n):
        if a[i]+i+1 not in wa.keys():
            wa[a[i]+i+1]=1
        else:
            wa[a[i]+i+1]+=1
        if i-a[i] >0:
            if i+1-a[i] not in sa.keys():
                sa[i+1-a[i]]=1
            else:
                sa[i+1-a[i]]+=1
    ans = 0
    for k in sa.keys():
        if k in wa.keys():
            ans += sa[k]*wa[k]
    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
    auto j = [](string s) {
        string t(s.rbegin(), s.rend());
        return s == t;
    };
    string s;
    cin >> s;
    int n = s.length();
    string f = s.substr(0,(n-1)/2);
    string b = s.substr((n+1)/2);
    if (j(s) && j(f) && j(b)) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
use std::cmp::min;
use core::ops::Bound::Excluded;
use core::ops::Bound::Included;
use std::collections::BTreeSet;
use std::cmp::Ordering;
use std::fmt::Debug;

fn read_line() -> String {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).expect("No Line");
    buffer
}
fn read_lines<R, T: Fn(&str)->R> (count: usize, transformer: T) -> Vec<R> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(transformer(buffer.trim()));
        buffer.clear();
    }
    vec
}
fn read_value<T: std::str::FromStr>() -> T {
    read_line().trim().parse().ok().unwrap()
}
fn read_values<T: std::str::FromStr>() -> Vec<T> {
    read_line().trim().split(' ').map(|x| x.parse().ok().expect("Can't Parse")).collect::<Vec<T>>()
}
fn read_tabulate<T: std::str::FromStr>(count: usize) -> Vec<T> {
    let mut buffer = String::new();
    let mut vec = Vec::with_capacity(count);
    for _ in 0 .. count {
        std::io::stdin().read_line(&mut buffer).expect("No Line");
        vec.push(buffer.trim().parse().ok().expect("Can't Parse"));
        buffer.clear();
    }
    vec
}
macro_rules! define {
    () => {};
    ($($token:tt)*) => {
        let mut iter = read_values::<String>().into_iter();
        define_iter!(iter, $($token)*);
    };
}
macro_rules! define_iter {
    ($iter:expr) =>{};
    ($iter:expr,) =>{};
    ($iter:expr, $id:ident:$t:tt $($tail:tt)*) => {
        let $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*);
    };
    ($iter:expr, mut $id:ident:$t:tt $($tail:tt)*) => {
        let mut $id: $t = $iter.next().unwrap().parse().ok().expect("Can't Parse");
        define_iter!($iter, $($tail)*)
    };
}
macro_rules! freeze {
    ($($id:ident), *) => {
        $(let $id = $id;)*
    };
}
struct KeyValue<K, V> {
    key: K,
    value: V
}
impl <K: PartialOrd, V> PartialEq for KeyValue<K, V> {
    fn eq(&self, other: &Self) -> bool {
        self.key.eq(&other.key)
    }
}
impl <K: PartialOrd, V> Eq for KeyValue<K, V> {}
impl <K: PartialOrd, V> PartialOrd for KeyValue<K, V> {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        self.key.partial_cmp(&other.key)
    }
}
impl <K: PartialOrd, V> Ord for KeyValue<K, V> {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.key.partial_cmp(&other.key).ok_or("Can't Compare").unwrap()
    }
}

fn main() {
    define! {
        n: usize
        a: i64
        b: i64
    }
    let cities = read_values::<i64>();
    let mut min_time = vec![0; n];
    for i in 1 .. n {
        min_time[i] = min_time[i - 1] + min(a * (cities[i] - cities[i - 1]), b);
    }
    println!("{}", min_time.last().unwrap());
}


Measured memory_bytes: 3900
N, M = map(int,input().split())
sc = []
for _ in range(M):
    s, c = input().split()
    s = int(s)
    if s > N:
        print('-1')
        exit()
    sc.append([s, c])

ans = -1
if N == 1:
    start = 0
else:
    start = 10 ** (N - 1)
for i in range(start, 10 ** N):
    str_num = str(i)
    for s, c in sc:
        if str_num[s - 1] != c:
            break
    else:
        ans = i
        break
print(ans)


Measured memory_bytes: 9200
#include <iostream>
#include <vector>
using namespace std;
using graph = vector<vector<int>>;
using ll = long long;
using p = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main()
{
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if (a == 0)
    {
        cout << 1 << endl;
    }
    else if (b == 0)
    {
        cout << 2 << endl;
    }
    else if (c == 0)
    {
        cout << 3 << endl;
    }
    else if (d == 0)
    {
        cout << 4 << endl;
    }
    else if (e == 0)
    {
        cout << 5 << endl;
    }
}


Measured memory_bytes: 3592
r,c=(int(x) for x in input().split())
count=0
answer_lst=[]
while count<r:
    line=input().split()
    lst=[]
    total=0
    for i in line:
        lst.append(int(i))
        total+=int(i)
    lst.append(total)
    answer_lst.append(lst)
    count+=1
lst2=[]
for l in range(c+1):
    total2=0
    for m in answer_lst:
        total2+=m[l]
    lst2.append(total2)
answer_lst.append(lst2)
for ans in answer_lst:
    print(*ans)


Measured memory_bytes: 6236
#include <bits/stdc++.h>
using namespace std;
int xa[1100];
int ya[1100];
bool vis[1100];
int xb[1100],yb[1100],pr[1100];
vector<int> v[1100];
bool dfs(int x)
{
    for(int i=0;i<v[x].size();i++)
    {
        int u=v[x][i];
        if(!vis[u])
        {
            vis[u]=1;
            if(!pr[u]||dfs(pr[u]))
            {
                pr[u]=x;
                pr[x]=u;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
int n;
cin>>n;

for(int i=1;i<=n;i++)
cin>>xa[i]>>ya[i];
for(int i=1;i<=n;i++)
cin>>xb[i]>>yb[i];
for(int i=1;i<=n;i++)
{
    for(int j=1;j<=n;j++)
    {
        if(xa[i]<xb[j]&&ya[i]<yb[j])
        {
            v[i].push_back(j+n);
            v[j+n].push_back(i);
        }
    }
}
int ans=0;
for(int i=1;i<=n;i++)
{
    memset(vis,0,sizeof(vis));
    if(dfs(i))
    ans++;
}
cout<<ans;
return 0;
}
 


Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS * max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x * x + y * y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;

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

	vector < pair < pair <string, int>, int> > vp;

	for (int i = 0; i < N; ++i)
	{
		string s;
		int p;
		cin >> s >> p;

		vp.push_back(make_pair(make_pair(s, -p), i+1));
	}

	sort(vp.begin(), vp.end());

	for (int i = 0; i < N; ++i)
	{
		cout << vp[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF (1<<29)
 
int main()
{
    int m, nmin, nmax;
    while (cin >> m >> nmin >> nmax, m) {
        vector<int> P(m);
        for (int i = 0; i < m; i++) {
            cin >> P[i];
        } 
        int gap = P[nmin-1] - P[nmin], res = nmin;
        for (int i = nmin; i < nmax; i++) {
            if (gap < P[i] - P[i+1]) {
                gap = P[i] - P[i+1];
                res = i + 1;
            } else if (gap == P[i] - P[i+1]) {
                res = i + 1;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using Graph=vector<vector<int>>;
#define MOD 1000000007

int main(){
  string S;
  cin>>S;
  int N=S.size();
  bool flag=true;
  int i=N-1;
  while(i>=0){
    if(S.at(i)=='m'){
      if(i<4){
        flag=false;
        break;
      }
      if(S.at(i-1)!='a'||S.at(i-2)!='e'||S.at(i-3)!='r'||S.at(i-4)!='d'){
        flag=false;
        break;
      }
      i-=5;
    }else if(S.at(i)=='e'){
      if(i<4){
        flag=false;
        break;
      }
      if(S.at(i-1)!='s'||S.at(i-2)!='a'||S.at(i-3)!='r'||S.at(i-4)!='e'){
        flag=false;
        break;
      }
      i-=5;
    }else if(S.at(i)=='r'){
      if(i<5){
        flag=false;
        break;
      }
      if(S.at(i-1)!='e'){
        flag=false;
        break;
      }
      i-=2;
      if(S.at(i)=='m'){
        if(i<4){
          flag=false;
          break;
        }
        if(S.at(i-1)!='a'||S.at(i-2)!='e'||S.at(i-3)!='r'||S.at(i-4)!='d'){
          flag=false;
          break;
        }
        i-=5;
      }else if(S.at(i)=='s'){
        if(i<3){
          flag=false;
          break;
        }
        if(S.at(i-1)!='a'||S.at(i-2)!='r'||S.at(i-3)!='e'){
          flag=false;
          break;
        }
        i-=4;
      }else{
        flag=false;
        break;
      }
    }else{
      flag=false;
      break;
    }
  }
  if(flag){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() {
	int perimeter, houses;
	cin >> perimeter >> houses;
	int distance, maxDistance = 0;
	vector<int> arr;
	for (int i = 0; i < houses; i++) {
		cin >> distance;
		arr.push_back(distance);
	}
	for (int i = 0; i < houses - 1; i++) {
		if (maxDistance < (arr[i + 1] - arr[i])) {
			maxDistance = arr[i + 1] - arr[i];
		}
		if (i == houses - 2 && maxDistance < (perimeter - arr[houses - 1] + arr[0])) {
			maxDistance = perimeter - arr[houses - 1] + arr[0];
		}
	}
	cout << perimeter - maxDistance << endl;
	return 0;
}

Measured memory_bytes: 1400
N = int(input())
V = list(map(int, input().split()))

even = {}
odd = {}


for i in range(N):
    if(i%2==0):
        if odd.get(V[i],None)==None:
            odd[V[i]]=1
        else:
            odd[V[i]]+=1
    else:
        if even.get(V[i],None)==None:
            even[V[i]]=1
        else:
            even[V[i]]+=1


max_odd_k = max(odd, key=odd.get)
max_even_k = max(even, key=even.get)
max_odd_v = max(odd.values())
max_even_v = max(even.values())
len_odd = len(odd)
len_even = len(even)

if(max_odd_k!=max_even_k):
    print(N-max_odd_v-max_even_v)
    exit()

if((len_odd==1)&(len_even==1)):
    print(N//2)
    exit()


if(len_odd==1):
    del even[max_even_k]
    max2_even_v = max(even.values())
    print(N-max_odd_v-max2_even_v)
    exit()

if(len_even==1):
    del odd[max_odd_k]
    max2_odd_v = max(odd.values())
    print(N-max2_odd_v-max_even_v)
    exit()

del even[max_even_k]
max2_even_v = max(even.values())
del odd[max_odd_k]
max2_odd_v = max(odd.values())

print(min((N-max2_odd_v-max_even_v),(N-max_odd_v-max2_even_v)))
#print()


Measured memory_bytes: 17632
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n > 0) {
        n /= k;
        ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
s = input()
count = 0
for i in range(len(s)):
  if len(s) % 2 == 0:
    limit = len(s) / 2
  else:
    limit = len(s) // 2 + 1
  
  if i >= limit:
    break
  
  if s[i] != s[-i-1]:
    count += 1
  

print(count)

Measured memory_bytes: 3060
import math

N,D = map(int,input().split())
L = []
ans = 0 
for _ in range(N):
  X = list(map(int,input().split()))
  L.append(X)
for i in range(N - 1):
  for j in range(i + 1,N):
    con = 0
    for k in range(D):
      con += (L[i][k] - L[j][k]) ** 2
    if  int(math.sqrt(con)) ** 2 == con:
      ans += 1

print(ans)
      

Measured memory_bytes: 9208
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))

now = A[0]
ret = 0
for i in range(n):
    x = B[i]

    if now <= x:
        x -= now
        ret += now
        now = A[i + 1]

        if x <= 0:
            continue
        
        if now <= x:
            ret += now
            now = 0
        else:
            now -= x
            ret += x
    
    else:
        ret += x
        now = A[i + 1]

print(ret)

Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


int main(){
    int N;
    cin >> N;
    if(N % 10 == 9 || N / 10 == 9) cout<< "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i) 
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
/*
　　　　　 　 _... ..._
　　　　　 , ´⌒ ⌒ヽ
　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
　　　　　　△ﾑ,8ﾑﾌつ
　　　　　/(ﾝ_/＿ヽ＼
　　　　 ～～i_ﾌ_ﾌ～´
*/
	int a, b;
	int c = 0;
	int d = 0;
	int count = 0;
	cin >> a >> b;
	rep1(i, a) {
		rep1(j, b) {
			if (j >= 10) {
				if (j % 10 >= 2) {
					if ((j - (j % 10)) / 10 >= 2) {
						if (i == (j % 10) * ((j - (j % 10))) / 10) {
							++count;
						}
					}
				}
			}
		}
	}
	cout << count << endl;
	return 0;
} 

Measured memory_bytes: 888
private fun readAtOnce(): List<String> = readLine()!!.split(" ")
private fun readInts(): List<Int> = readAtOnce().map(String::toInt)
private fun readLongs(): List<Long> = readAtOnce().map(String::toLong)
private fun zeroArray(size: Int): IntArray = IntArray(size) { 0 }
private fun Int.repeat(predicate: (Int) -> Unit) = repeat(this, predicate)

fun main(array: Array<out String>) {
    val (N, M) = readInts()
    val s = zeroArray(M)
    val c = zeroArray(M)
    M.repeat {
        val (_s, _c) = readInts()
        s[it] = _s
        c[it] = _c
    }

    println(
            (0 until 1000)
                    .filter { it.toString().length == N }
                    .filter { (0 until M).all { m -> "${it}XXXXXX"[s[m] - 1].toString() == c[m].toString() } }
                    .min() ?: -1
    )
}

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

int main(){
  int x;
  cin >> x;
  ll hap = (x/500)*1000+x%500-(x%500%5);
  printf("%lld\n", hap);
  return 0;
}


Measured memory_bytes: 3764
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;

int main() {
	int n;
	cin >> n;
	int a[100001];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	long long ans = 0, ans2 = 0, sum = 0;
	bool b = 1;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (!b&&sum > 0) {
			ans += abs(sum) + 1;
			sum = -1;
		}
		else if (b&&sum < 0) {
			ans += abs(sum) + 1;
			sum = 1;
		}
		if (sum == 0) {
			ans++;
			sum = b * 2 - 1;
		}
		b = 1 - b;
	}
	b = 0, sum = 0;
	for (int i = 0; i < n; i++) {
		sum += a[i];
		if (!b&&sum > 0) {
			ans2 += abs(sum) + 1;
			sum = -1;
		}
		else if (b&&sum < 0) {
			ans2 += abs(sum) + 1;
			sum = 1;
		}
		if (sum == 0) {
			ans2++;
			sum = b * 2 - 1;
		}
		b = 1 - b;
	}
	cout << min(ans, ans2) << endl;
}

Measured memory_bytes: 640
using System;




class Test {

    static void Main() {

        int m1=0,m2=0,m3=0,h;
        int i;

        for (i = 0; i < 10; i++)
        {

            h = int.Parse(Console.ReadLine());

            if (m1 < h)
            {
                m3 = m2;
                m2 = m1;
                m1 = h;
            }
            else if (m2 < h)
            {
                m3 = m2;
                m2 = h;
            }
            else if(m3 < h)
            {
                m3 = h;
            }

           
        }
 
        Console.WriteLine("{0}\n{1}\n{2}", m1, m2, m3);

        }
    
}

Measured memory_bytes: 5624
#define debug_interval ','
#define dump_interval ' '
#define debug_toggle 1
//{
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INT_MAX LLONG_MAX
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define fi first
#define se second
#define mp make_pair
#define rev reverse
#define dans dump(ans)
#define MOD 1000000007
#define amp(v,n) (v).count(n)?v[n]++:v[n]=1;

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cerr<<endl;}
template<class...A> inline void debug_rest() {cerr<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cerr<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cerr<<first,debug_rest(rest...);}
//}

typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
template<int m>class mint{private:int i;public:mint() : i(0){}mint(int i): i((i%m+m)%m){}mint operator+(const mint& o){return o.i+i;}mint operator*(const mint& o){return o.i*i;}mint operator-(){return -i;}operator int() {return i;}};

int a,b,c,d,e,f;
string s,t,u;

main(){
	int a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
	}
	sort(a,a+3);
	cout<<abs(a[0]-a[1])+abs(a[1]-a[2])<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<string>
#include<cstring>
#include<time.h>
#include<iomanip>
#include<list>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<random>
#include<bitset>
#include <queue>
#include <map>


using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;


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


int N;
struct node {
	vector<int> link;
	int a;
};
vector<node> nod;
vector<int> res;
void f(vector<int>& dp, int t, int par) {
	auto it = lower_bound(dp.begin(), dp.end(), nod[t].a);
	bool pop;
	int buf;
	int idx;
	if (it == dp.end()) {
		dp.push_back(nod[t].a);
		pop = true;
	}
	else {
		buf = *it;
		idx = distance(dp.begin(), it);
		*it = nod[t].a;
		pop = false;
	}
	res[t] = dp.size();
	for (int i : nod[t].link) {
		if (i == par) continue;
		f(dp, i, t);
	}
	if (pop) dp.pop_back();
	else dp[idx] = buf;
}
int main() {
	cin >> N;
	nod.resize(N);
	res.resize(N);
	rep(i, N) cin >> nod[i].a;
	rep(i, N - 1) {
		int u, v;
		cin >> u >> v;
		u--;
		v--;
		nod[u].link.push_back(v);
		nod[v].link.push_back(u);
	}
	vector<int> v;
	f(v, 0, -1);
	rep(i, N)cout << res[i] << endl;
	return 0;
}


Measured memory_bytes: 30764
sa=list(str(input()))
sb=list(str(input()))
sc=list(str(input()))

card={"a":sa,"b":sb,"c":sc}

answer={"a":"A","b":"B","c":"C"}

turn="a"

while True:
    if len(card[turn])==0:
        break
    next_turn=card[turn][0]
    card[turn]=card[turn][1:]
    turn=next_turn

print(answer[turn])


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

using namespace std;

int main(){
    int N, Q;
    int a[100005];
    int c[100005];
    std::string s;
    cin >> N >> Q >> s;

    int i, j;
    int m, n;

    a[0] = 0;
    for(i=0; i<N; i++){
        if(s[i] == 'A' && s[i+1] == 'C') a[i+1] = a[i] + 1;
        else a[i+1] = a[i];
    }

    for(i=1; i<=Q; i++){
        cin >> m >> n;
        c[i] = a[n-1] - a[m-1];
    }
    for(i=1; i<=Q; i++) cout << c[i] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector <int> primes;
    SieveOfEratosthenes(1e6,primes);
    int p=primes.size();
    int test=0;
    ll a=nxtl(),b=nxtl();
    set <ll> s1,s2;
    for(int i=0;i<p&&primes[i]*primes[i]<=a;i++)
    {
        if(a%primes[i]==0)
        {
            s1.insert(primes[i]);
            while(a%primes[i]==0)
                a/=primes[i];
        }
    }
    if(a>1)
        s1.insert(a);
    for(int i=0;i<p&&primes[i]*primes[i]<=b;i++)
    {
        if(b%primes[i]==0)
        {
            s2.insert(primes[i]);
            while(b%primes[i]==0)
                b/=primes[i];
        }
    }
    if(b>1)
        s2.insert(b);
    for(auto it=s1.begin();it!=s1.end();it++){
        if(s2.count(*it))
            test++;
        //cout<<*it<<" ";
    }
    //cout<<endl;
        
    cout<<test+1<<endl;
    
    
    return 0;   
}


 
 


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

int main() {
  string s;
  int K;
  cin >> s >> K;
  long long ans = 0;
  vector<vector<bool>> notZero(s.size(), vector<bool>(s.size()));
  if(s.size() < K) {
    cout << 0 << endl;
    return 0;
  }
  for(int i=0;i<s.size();i++) {
    if(s[i] != '0') notZero[i][i] = true;
    for(int j=i+1;j<s.size();j++) {
      if(notZero[i][j-1]) notZero[i][j] = true;
      else if(s[j] != '0') notZero[i][j] = true;
    }
  }
  if(K == 1) {
    for(int i=0;i<s.size();i++) {
      if(i == 0) ans += s[i] - '0';
      else ans += 9;
    }
  }
  else if(K == 2) {
    for(int i=0;i<s.size();i++) {
      int digit_i = s[i] - '0';
      for(int j=i+1;j<s.size();j++) {
        int digit_j = s[j] - '0';
        if(i == 0) {
          if(j == 1) ans += digit_j + (digit_i-1) * 9;
          else if(notZero[i+1][j-1]) ans += digit_i * 9;
          else ans += digit_j + (digit_i-1) * 9;
        }
        else ans += 81;
      }
    }
  }
  else if(K == 3) {
    for(int i=0;i<s.size();i++) {
      int digit_i = s[i] - '0';
      for(int j=i+1;j<s.size();j++) {
        int digit_j = s[j] - '0';
        for(int k=j+1;k<s.size();k++) {
          int digit_k = s[k] - '0';
          int alt;
          if(digit_j == 0) alt = 0;
          else alt = (digit_k + (digit_j-1) * 9) + (digit_i-1) * 9 * 9;
          if(i == 0) {
            if(j == 1) {
              if(k == 2) ans += alt;
              else if(notZero[j+1][k-1]) ans += digit_j * 9 + (digit_i-1) * 9 * 9;
              else ans += alt;
            }
            else if(notZero[i+1][j-1]) ans += digit_i * 9 * 9;
            else {
              if(k == j+1) ans += alt;
              else if(notZero[j+1][k-1]) ans += digit_j * 9 + (digit_i-1) * 9 * 9;
              else ans += alt;
            }
          }
          else ans += 729;
        }
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
inputStr = input()

def _rot13(c):
    if 'A' <= c and c <= 'Z':
        # 13 文字分ずらす
        return chr((ord(c) - ord('A') + n) % 26 + ord('A'))

    if 'a' <= c and c <= 'z':
        # 13 文字分ずらす
        return chr((ord(c) - ord('a') + n) % 26 + ord('a'))

    # その他の文字は対象外
    return c


def rot13(s):
    # ジェネレータ内包表記で文字列に ROT13 を適用する
    g = (_rot13(c) for c in s)
    # 文字列に直す
    return ''.join(g)



print(rot13(inputStr))


Measured memory_bytes: 3060