akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
 
int main(){
    string S,T;
    cin>>S>>T;
    bool flg=false;
    rep(i,0,S.size()){
        S.push_back(S[0]);
        S.erase(S.begin());
        if(S==T)flg=true;
    }
    cout<<(flg ? "Yes":"No")<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
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;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//indexは
long long INF = 1LL<<60;

int n;
void gene(int i,int rest,string s){
    if(s.size()==n){
        cout<<s<<endl;
        return;
    }
    if(i>n||rest<0)return;
    i++;
    rest--;
    for(int j=0;j<i+1;j++){
        //stringは記憶領域を共通してる?明示しないとコピー取らない?
        string t=s;
        char tmp='a'+j;
        if(tmp!='a'){
            char fb=tmp-1;
            if(t.find(fb)==string::npos)continue;
        }
        gene(i,rest,t+=tmp);
    }
}

int main( ){
    cin>>n;
    gene(0,n,"");
    return 0;
}




Measured memory_bytes: 1536
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdlib>
#include<cstdio>
#include<utility>
#include<list>
using namespace std;
int solve(int n){
	int sum=0;
	while(n>0){
		sum += n%10;
		n /= 10;
	}
	return sum;
}

int main(){
	int n,A,B;
	cin>>n>>A>>B;
	int ans=0;

	for(int i=1;i<=n;i++){
		int sum = solve(i);
		if(A<=sum && sum <=B)ans += i;
	}

	cout<< ans <<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		int n = sc.nextInt();
		PriorityQueue<Double> queue = new PriorityQueue<Double>();
		for(int i = 0; i < n ; i++) {
			queue.add(sc.nextDouble());
		}
		
		while(true) {
			double a = queue.poll();
			
			if(queue.isEmpty()) {
				System.out.println(a);
				return;
			}
			
			double b = queue.poll();
			queue.offer((a+b)/2);
			
		}
	}
}


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

int main(){
  int x = 0, y = 0, z = 0;
  int a, b, c;

  while(cin >> a >> b >> c){
    if(a + b <= c || a + c <= b || b + c <= a){
      break;
    }

    a *= a;
    b *= b;
    c *= c;

    if(a + b == c || a + c == b || b + c == a){
      x++;
    }
    else if(abs(a - b) < c && c < a + b ||
            abs(a - c) < b && b < a + c ||
            abs(b - c) < a && a < b + c){
      y++;
    }
    else{
      z++;
    }
  }

  cout << x + y + z << " " << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 1164
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	start, xs, ys := parseOperations(s)
	var x, y int
	fmt.Scan(&x, &y)
	if isReachablePoint(x-start, y, xs, ys) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func isReachablePoint(x, y int, mxs, mys []int) bool {
	return isReachable(x, mxs) && isReachable(y, mys)
}

// const max = 8000

func isReachable(goal int, diff []int) bool {
	possibilities := make([]map[int]struct{}, 2)
	possibilities[0] = map[int]struct{}{0: struct{}{}}
	for i := 1; i < len(diff)+1; i++ {
		possibilities[i%2] = map[int]struct{}{}
		for k := range possibilities[(i-1)%2] {
			pos := k + diff[i-1]
			possibilities[i%2][pos] = struct{}{}
			pos = k - diff[i-1]
			possibilities[i%2][pos] = struct{}{}
		}
	}
	_, ok := possibilities[len(diff)%2][goal]
	return ok
}

func parseOperations(s string) (start int, xs, ys []int) {
	progress := 0
	for len(s) > 0 {
		if s[0] == 'T' {
			start = progress
			progress = 0
			s = s[1:len(s)]
			break
		}
		progress++
		s = s[1:len(s)]
	}
	if len(s) == 0 {
		start = progress
		return
	}
	mode := 0
	for len(s) > 0 {
		if s[0] == 'T' {
			if mode == 0 {
				if progress > 0 {
					ys = append(ys, progress)
				}
			} else {
				if progress > 0 {
					xs = append(xs, progress)
				}
			}
			mode ^= 1
			progress = 0
		} else {
			progress++
		}
		s = s[1:len(s)]
	}
	if mode == 0 {
		if progress > 0 {
			ys = append(ys, progress)
		}
	} else {
		if progress > 0 {
			xs = append(xs, progress)
		}
	}
	return
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n;
long long ans,dp[2*N];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		long long a;
		cin>>a;
		dp[i+1]=dp[i]+a;
	}
	ans=1e18;
	for(int i=1;i<n;i++)
		ans=min(ans,abs((dp[n]-dp[i])-dp[i]));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
dic = []

for i in range(n):
    a, b = map(str, input().split())
    dic.append([a, int(b), i + 1])
 
dic.sort(key= lambda x: x[1], reverse= True)
dic.sort(key= lambda x: x[0])

for i in range(n):
    print(dic[i][2])

Measured memory_bytes: 3060
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  int n;
  readf("%s\n", &n);
  
  auto a = new int[](n);
  foreach (i; 0..n) {
    a[i] = readln.chomp.to!int;
  }
  int cnt, i;
  while (true) {
    if (a[i] == -1) {
      writeln("-1");
      break;
    } 
    cnt++;
    if (a[i] == 2) {
      writeln(cnt);
      break;
    }
    auto tmp = i;
    i = a[i] - 1;
    a[tmp] = -1;
  }
}


Measured memory_bytes: 3452
//実験 %2しないver オーバーフロー？
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

//vector< vector<int> > v (size1, vector<int>(size2) );
vector< vector<pair<ll,ll>> > cost(100005);
stack<ll> s;
vector<bool> B(100005);
vector<ll> cost1(100005);
vector<ll> ans(100005);
ll a;

void dfs(){
    if(s.empty()==false){
        a=s.top();
        //cout<<'a'<<a<<endl;
        if(cost[a].size()==0){
            s.pop();
        }else {
            if(B[cost[a].back().first]==false){
                s.push(cost[a].back().first);
                B[cost[a].back().first]=true;
                cost1[cost[a].back().first]=cost1[a]+cost[a].back().second;
                //cout<<cost[a].back().first<<' '<<cost1[cost[a].back().first]<<endl;
                /*if((cost1[cost[a].back().first])%2==0){
                    ans[cost1[cost[a].back().first]]=0;
                }else{
                    ans[cost1[cost[a].back().first]]=1;
                }*/
                cost[a].pop_back();
            }else if(cost[a].size()>1){
                swap(cost[a].back(),cost[a].front());
            }else{
                cost[a].pop_back();
            }
        }
        dfs();
    }
}


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

    ll N;
    cin>>N;

    ll u,v,w;

    FOR(i,0,N-1){
        cin>>u>>v>>w;
        cost[u].push_back({v,w});
        cost[v].push_back({u,w});
    }
    
    FOR(i,1,100005){
        B[i]=false;
    }

    s.push(1);
    cost1[1]=0;
    B[1]=true;
    dfs();
    FOR(i,1,N+1){
        //cout<<i<<' '<<cost1[i]<<endl;
        if(cost1[i]%2==0){
            cout<<0<<endl;
        }else cout<<1<<endl;
    }
}

Measured memory_bytes: 9472
import math
N, D = map(int, input().split())
x = []
for i in range(N):
    x.append(list(map(int, input().split())))
count = 0
for i in range(N):
    for j in range(i+1, N):
        cnt = 0
        for k in range(D):
            cnt += abs(x[i][k] - x[j][k]) ** 2
        ans = math.sqrt(cnt)
        if ans.is_integer():
            count += 1
print(count)






Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=0;
    if(a<=b&&b<=c){
        if(b-a<=d&&c-b<=d) ans=1;
    }
    else if(a>=b&&b>=c){
        if(a-b<=d&&b-c<=d) ans=1;
    }
    else if(a>=c){
        if(a-c<=d) ans=1;
    }
    else if(c>=a){
        if(c-a<=d) ans=1;
    }
    if(ans==1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#define p printf("%d %d %d ",i
i;L;a;main(l){for(scanf("%d",&L);L>>l;)a+=L>>l++-1&1;printf("%d %d ",l,l*2-2+a);for(;++i<l;)p,i+1,0),p,i+1,a=1<<i-1),L&a&&p,l,L-=a);}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# F - Select Half

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

# memo[i][m] a[0:i+1]からm個選ぶときの最大値
memo = [{} for i in range(n)]
memo[0] = {0: 0, 1: a[0]}
memo[1] = {1: max(a[:2])}

for i in range(2, n):
    m = (i + 1) // 2
    memo[i][m] = max(memo[i - 1][m], memo[i - 2][m - 1] + a[i])
    if i % 2 == 0:
        memo[i][m + 1] = memo[i - 2][m] + a[i]

print(memo[-1][n // 2])


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

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

  int count_odd = 0;
  int a;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    if (a % 2 == 1)
    {
      count_odd++;
    }
  }

  if (count_odd % 2 == 1)
  {
    cout << "NO" << endl;
  }
  else
  {
    cout << "YES" << endl;
  }
}

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

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

using namespace std;

int m2i(string s) {
  int v = 0;
  for (int i = 0; i < s.size(); ++i) {
    switch(s[i]) {
     case 'm':
      if (i == 0) v = 1000;
      else v = (s[i-1] - '0') * 1000;
      break;
     case 'c':
      if (i == 0 || (s[i-1] > '9' || s[i-1] < '0')) v += 100;
      else v += (s[i-1] - '0') * 100;
      break;
     case 'x':
      if (i == 0 || (s[i-1] > '9' || s[i-1] < '0')) v += 10;
      else v += (s[i-1] - '0') * 10;
      break;
     case 'i':
      if (i == 0 || (s[i-1] > '9' || s[i-1] < '0')) v += 1;
      else v += s[i-1] - '0';
      break;
    }
  }
  return v;
}

string i2m(int n) {
  string v;
  if (n >= 2000) {
    v += '0' + (n / 1000);
  }
  if (n >= 1000) {
    v += 'm';
    n %= 1000;
  }
  if (n >= 200) {
    v += '0' + (n / 100);
  }
  if (n >= 100) {
    v += 'c';
    n %= 100;
  }
  if (n >= 20) {
    v += '0' + (n / 10);
  }
  if (n >= 10) {
    v += 'x';
    n %= 10;
  }
  if (n >= 2) {
    v += '0' + n;
  }
  if (n >= 1) {
    v += 'i';
  }
  return v;
}

int main() {
  int n;
  cin >> n;
  REP(i,n) {
    string a;
    string b;
    cin >> a >> b;
    int ai = m2i(a);
    int bi = m2i(b);
    cout << i2m(ai + bi) << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include<iostream>
#define int long long
using namespace std;
const int mod = 1e9+7;
int n , k , ans=0;
struct matrix
{
	int m[51][51];
	matrix(){
		for(int i=0 ; i<51 ; ++i)
			for(int j = 0 ; j<51 ; ++j)
				m[i][j] = 0;
	}
	matrix operator*(const matrix &x)const{
		matrix c;
		for(int i=1 ; i<=n ; ++i)
			for(int j=1 ; j<=n ; ++j)
				for(int k=1 ; k<=n ; ++k)
					c.m[i][j] = (c.m[i][j]%mod + ((x.m[i][k]%mod) * (m[k][j]%mod))%mod)%mod;
		return c;
	}
}G,C;
 
matrix fpow(matrix M , int p){
	matrix c;
	for(int i=1 ; i<=n ; ++i)
		for(int j=1 ; j<=n ; ++j)
			if(i==j) c.m[i][j] = 1;
	for( ; p ; p>>=1 , M = M*M) if(p & 1) c = c * M;
	return c;
}
main(){ios::sync_with_stdio(false),cin.tie(0);
	cin >> n >> k;
	for(int i=1 ; i<=n ; ++i)
		for(int j=1 ; j<=n ; ++j)
			cin >> G.m[i][j];
	C = fpow(G , k);
	for(int i=1 ; i<=n ; ++i)
		for(int j=1 ; j<=n ; ++j){
			if(C.m[i][j]) ans+=C.m[i][j];
			if(ans >= mod) ans-=mod;
		}
 
	cout << ans <<'\n';
}

Measured memory_bytes: 512
N = int(input())
CSF = [list(map(int, input().split())) for _ in range(N - 1)]
for i in range(N):
    t = 0
    for c, s, f in CSF[i:]:
        if t > s:
            if t % f:
                t += f - t % f
        else:
            t = s
        t += c
    print(t)


Measured memory_bytes: 3188
/***************************************************
	> File Name: Unkown_Error.cpp
	> Author: Zcorpio
	> Mail: 1113043195@qq.com 
	> Created Time: [Data_Deleted]
***************************************************/
#include<bits/stdc++.h>
#define int long long
#define rint register int
#define mst(a,b) memset(a,b,sizeof(a))
#define go(u) for(int i=head[u],v=to[i];i;v=to[i=nxt[i]])
#define F(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define R(i,a,b) for(register int i=(a),i##_end=(b);i>=i##_end;--i)
#define File(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
using namespace std;
//const int mod=1e9+7;
//const int mod=998244353;
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
/*
template<typename T> inline T max(T a,T b){return a>b?a:b;}
template<typename T> inline T min(T a,T b){return a<b?a:b;}
template<typename T> inline T abs(T a){return a>0?a:-a;}
template<typename T> inline bool chkmin(T &a,T b){return a<b?a=b,1:0;}
template<typename T> inline bool chkmax(T &a,T b){return a>b?a=b,1:0;}
template<typename T> inline T gcd(T a,T b){T t;if(a<b)
{while(a){t=a;a=b%a;b=t;}return b;}else{while(b){t=b;b=a%b;a=t;}return a;}}
template<typename T> inline T sqr(T x){return x*x;}
inline void write(T k,char ch=0)
{
	if(k<0)k=-k,putchar('-');
	if(k>=10)write(k/10);
	putchar(k%10+'0');
	if(ch)putchar(ch);
}
inline void add(int u,int v)
{
	cnt++;
	nxt[cnt]=head[u];
	to[cnt]=v;
	head[u]=cnt;
}
*/
inline int read()
{
	int x=0;
	bool f=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') f=1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return f?-x:x;
}
const int maxn=1e6+3;
int a[maxn],f[maxn],n;
ll maxa=-1,maxf=-1,k;
bool chk(ll x)
{
	ll tmp=k;
	F(i,1,n)
	{
		ll qw=x/f[n-i+1];
		if(a[i]>qw) tmp-=(a[i]-qw);
	}
	if(tmp<0) return false;
	else return true;
}
signed main()
{
	//File("");
	n=read(),k=read();
	F(i,1,n) a[i]=read();
	F(i,1,n) f[i]=read();
	sort(a+1,a+n+1);
	sort(f+1,f+n+1);
	ll l=0,r=(ll)a[n]*f[n],ans=0;
	while(l<=r)
	{
		ll mid=(l+r)>>1;
		if(chk(mid))
			ans=mid,r=mid-1;
		else l=mid+1;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5888
n = int(input())
d1 = []
d2 = []
for i in range(n):
  x,y = map(int,input().split())
  d1.append(x-y)
  d2.append(x+y)
one = max(d1)-min(d1)
two = max(d2)-min(d2)
print(max(one,two))

Measured memory_bytes: 100488
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

typedef long long ll;

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

// const int C ;
// const int M = 1000000007;

const int MAX_SIZE = 1000010;
const long long MOD = 1000000007;

long long inv[MAX_SIZE];
long long fact[MAX_SIZE];
long long factinv[MAX_SIZE];

void init() {
  inv[1] = 1;
  for (int i=2; i<MAX_SIZE; i++) {
    inv[i] = ((MOD - inv[MOD%i]) * (MOD/i))%MOD;
  }
  fact[0] = factinv[0] = 1;
  for (int i=1; i<MAX_SIZE; i++) {
    fact[i] = (i * fact[i-1])%MOD;
    factinv[i] = (inv[i] * factinv[i-1])%MOD;
  }
}

long long C(int n, int k) {
  if (n >=0 && k >= 0 && n-k >= 0) {
    return ((fact[n] * factinv[k])%MOD * factinv[n-k])%MOD;
  }
  return 0;
}

long long power(long long x, long long n) {
  if (n == 0) {
    return 1;
  } else if (n%2 == 1) {
    return (x * power(x, n-1)) % MOD;
  } else {
    long long half = power(x, n/2);
    return (half * half) % MOD;
  }
}

long long gcm(long long a, long long b) {
  if (a < b) {
    return gcm(b, a);
  }
  if (b == 0) return a;
  return gcm(b, a%b);
}

int main () {
  init();
  int N;
  cin >> N;
  int A[100010];
  for (auto i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A+N);
  bool isodd = (N%2 == 1);
  for (auto i = 0; i < N; i++) {
    if (isodd ^ (A[i]%2 == 1)) {
      
    } else {
      cout << 0 << endl;
      return 0;
    }
  }
  if (isodd) {
    for (auto i = 0; i < N; i++) {
      if (i%2 == 0) {
        if (A[i] != i) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (A[i] != i+1) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(2, (N-1)/2) << endl;
    return 0;
  } else {
    for (auto i = 0; i < N; i++) {
      if (i%2 == 0) {
        if (A[i] != i+1) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        if (A[i] != i) {
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << power(2, N/2) << endl;
    return 0;
  }
}


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

int main() {
	string week[7] = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" };
	string d;
	cin >> d;

	int i = 0;
	while (week[i] != d) ++i;

	cout << 7 - i;
	
	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
void _(ll&a , ll b)
{
    a=(a%mod+b%mod)%mod;
    a=(a+mod)%mod;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll x,k;cin >> x >> k;
    x%=k;
    cout << min(x,k-x);
    }

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define INT_MAX 0x7FFFFFFFLL
using namespace std;
typedef long long LL;

LL gcd(LL a, LL b) {
  while(a % b != 0) {
    LL t = a % b;
    a = b;
    b = t;
  }
  return b;
}

LL lcb(LL a, LL b) {
  LL r = a * b / gcd(a, b);
  if(r > INT_MAX)
    return INT_MAX;
  else
    return r;
}

int is_hlcb(LL x, LL* A, int N) {
  REP(i, N) {
    if(x % A[i] == 0) return false;
    if(x * 2 % A[i] != 0) return false; 
  }
  return true;
}

int main(){
  int N;
  LL M;
  LL A[100000];
  cin >> N >> M;
  LL lcb_all = 1;
  REP(i, N) {
    cin >> A[i];
    lcb_all = lcb(A[i], lcb_all);
  }
  LL ret = 0;
  if(lcb_all / 2 <= M && is_hlcb(lcb_all / 2, A, N)) {
    ret = 1 + (M - lcb_all / 2) / lcb_all;
  }
  cout << ret << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll x, y, z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}


Measured memory_bytes: 3584
#include "bits/stdc++.h" // 提出時こちらで問題なし
using namespace std;

int main() {
	int num_N = 0;
	cin >> num_N;

	vector<int> hash(10001, 0);
	int sum = 0;

	for (int x = 1; x < 100; x++) {
		for (int y = 1; y < 100; y++) {
			for (int z = 1; z < 100; z++) {
				sum = pow((x + y + z), 2) - (x * y + y * z + z * x);
				if (sum > 10000) {
					break;
				}
				hash[sum]++;
			}
		}
	}
	for (int i = 1; i <= num_N; i++) cout << hash[i] << endl;
	return 0;
}


Measured memory_bytes: 3532
#include <iostream>
#include <vector>

int main(){
	std::vector<int> rail;
	std::vector<int> out;
	int a;

	while(std::cin >> a){
		if(a != 0){
			rail.push_back(a);
		}else if(a == 0){
			out.push_back(rail.back());
			rail.pop_back();
		}else{
			break;
		}
	}

	for(int i=0; i<(int)out.size(); ++i){
		std::cout << out.at(i) << std::endl;
	}
}

Measured memory_bytes: 1216
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)

#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    
    string s;
    cin >> s;
    int init=0;
    rep(i,4)
    {
    	if(s[i]=='+') init++;
    	else init--;
    }
    cout << init << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

// ll modpow(ll x, ll n){
//     if(n == 0) return 1;

//     ll res = modpow(x, n/2);
//     if(n%2 == 0) return res*res%mod;
//     else return (res*res%mod)*x%mod;
// }

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

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

//typedef tuple<ll, ll, ll> T;
// get<K>(tuple型の変数)

//using T = tuple<int, int, int, int>;


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

    ll n; cin >> n;
    ll ans = 1e15;
    for(ll i=1; i*i<=n; ++i){
        if(n%i == 0) chmin(ans, i + n/i - 2);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <valarray>
#include <iterator>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) container.begin(), container.end()
#define RALL(container) container.rbegin(), container.rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int n, m;

int dist(vi &s, vi &t){
	int q=count(ALL(s), 1);
	int j=0,k=0;
	int res = 0;
	REP(i, q){
		while(!s[j++]);
		while(!t[k++]);
		res += abs(j-k);
	}
	return res;
}

main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vi d(n), e(m);
	REP(i, n) cin >> d[i];
	REP(i, m) cin >> e[i];
	int ans = INF;
	REP(k, 2){
		vi tar;
		int t=k;
		FOR(it, e){
			REP(i, *it) tar.push_back(t);
			t=!t;
		}
		if(count(ALL(tar), 0) != count(ALL(d), 0)) continue;
		ans = min(ans, dist(d, tar));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1228
n,ma,mb = gets.split.map(&:to_i)
abc = n.times.map{gets.split.map(&:to_i)}

inf = 10**9
dp = 411.times.map{[inf]*411}
dp[0][0] = 0

abc.each{|a,b,c|
  400.downto(a){|i|
    400.downto(b){|j|
      if dp[i][j] > dp[i-a][j-b]+c
        dp[i][j] = dp[i-a][j-b]+c;
      end
    }
  }
}

min = inf
for i in 1...400/[ma,mb].max
  min = dp[ma*i][mb*i] if min > dp[ma*i][mb*i]
end

p (min==inf)? -1 : min


Measured memory_bytes: 5116
#include <stdio.h>

int main(void){
	int n;
	int i;
	scanf("%d\n",&n);
	for(i=0;i<n;i++){
	int a, b, c, d;

	scanf("%d %d %d", &a, &b, &c);

	if (a<b){
		d = b;
		b = a;
		a = d;
 	}
 	if (a<c){
 		d = c;
 		c = a;
 		a = d;
 	}
 	if (a*a == b*b + c*c)
 		printf("YES\n");
 	else
 		printf("NO\n");	
 	}


return 0;


}

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

int main(){
    int n, q, t;
    string name;
    queue<pair<string, int>> Q;
    
    cin >> n >> q;
    
    for(int i = 0; i < n; i++){
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }
    
    pair<string, int> u;
    int elaps = 0, a;
    
    while(!Q.empty()){
        u = Q.front(); Q.pop();
        a = min(u.second, q);
        u.second -= a;
        elaps += a;
        if(u.second > 0) Q.push(u);
        else cout << u.first << " " << elaps << endl;
    }
}


Measured memory_bytes: 6184
def calculate(arr):

    if len(arr) == 1:
        return arr[0]
    if len(arr) == 2:
        result = (arr[0] + arr[1]) / 2
        return result

    if len(arr) > 2:
        res = (arr[-1] + arr[-2]) / 2
        newArr = arr[:-2]
        newArr.append(res)
        return calculate(newArr)

def rank(arr):
    lastIndex = len(arr) - 1
    while lastIndex > 0:
        for i in range(lastIndex):
            if arr[i + 1] > arr[i]:
                tmp = arr[i + 1]
                arr[i + 1] = arr[i]
                arr[i] = tmp

        lastIndex = lastIndex - 1
    return arr

N = int(input())
S = input().split(" ")
arr = list(map(int, list(S)))
newArr = rank(arr)

result = calculate(list(arr))
print(result)

Measured memory_bytes: 3064
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let A = read_line().trim().parse::<i32>().unwrap();
	let B = read_line().trim().parse::<i32>().unwrap();
	let C = read_line().trim().parse::<i32>().unwrap();
	let X = read_line().trim().parse::<i32>().unwrap();

	let mut count = 0;
	for a in 0..(A+1) {
		for b in 0..(B+1) {
			for c in 0..(C+1) {
				if X == (500*a) + (100*b) + (50*c) {
					count+=1;
				}
			}
		}

	}
	println!("{}",count);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;
 
int main(){
  int a,b;
  cin >> a >> b;
  cout << (a+b)%24 << endl;
  return 0;
}


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

namespace AtTest
{
    class ARC101_C
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var minusX = new List<long>();
            var plusOrZeroX = new List<long>();

            for (int i = 0; i < n; i++)
            {
                long x = long.Parse(input[i]);
                if (x < 0)
                {
                    minusX.Add(x);
                }
                else
                {
                    plusOrZeroX.Add(x);
                }
            }
            long[] minuses = minusX.ToArray();
            Array.Reverse(minuses);
            minuses = minuses.Select(x => x *= -1).ToArray();
            long[] pluses = plusOrZeroX.ToArray();

            long minDistance = -1;
            if (k <= minuses.Length)
            {
                minDistance = minuses[k - 1];
            }
            for(int i = 0; i < pluses.Length; i++)
            {
                int minusCnt = k - i - 1;
                if (minusCnt > minuses.Length) continue;

                long plusDist = 2 * pluses[i];
                long minusDist = pluses[i];
                if (minusCnt > 0)
                {
                    plusDist += minuses[minusCnt - 1];
                    minusDist += 2 * minuses[minusCnt - 1];
                }
                long min = plusDist < minusDist ? plusDist : minusDist;
                if (minDistance == -1 || minDistance > min)
                {
                    minDistance = min;
                }
            }

            Console.WriteLine(minDistance);
        }
    }
}


Measured memory_bytes: 26464
# A - Falling Asleep

def main():
	numOfSongs = int(input())
	songList = [input().split() for i in range(numOfSongs)]
	asleepSong = input()
	index = search(songList, asleepSong)[0]
	seconds = sumSeconds(songList[(index+1):])
	print(seconds)
	# print(search(songList, asleepSong))

def search(list, value):
	return [i for i, x in enumerate(list) if x[0] == value]

def sumSeconds(lst):
	sum = 0
	for s in lst:
		sum += int(s[1])
	return sum

main()

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
char st[100005];
int main(){
    int n,K,i,j,k,l;
    scanf("%s",st);
    scanf("%d",&K);
    n = strlen(st);
    for(i=0;i<n;i++){
        j = 'z'-st[i]+1;
        if(st[i]!='a'&&j<=K){
            st[i] = 'a';
            K-=j;
        }
    }
    K%=26;
    while(K>0){
        if(st[n-1]<'z')st[n-1]++;
        else st[n-1] = 'a';
        K--;
    }
    printf("%s\n",st);
    return 0;
}




Measured memory_bytes: 512
K = int(input())

lunlun = list(map(str, [1,2,3,4,5,6,7,8,9]))

def concat(org):
  end = int(org[-1])
  r = []
  if end != 0:
    r.append(org + str(end-1))
  r.append(org + str(end))
  if end != 9:
    r.append(org + str(end+1))
  return r

t = [str(i) for i in range(1, 10)]
for i in range(2, 11):
  r = []
  for e in t:
    r.extend(concat(e))
  t = r
  lunlun.extend(t)

# print(lunlun)
# print(len(lunlun))
print(lunlun[K-1])


Measured memory_bytes: 18448
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int H, W, K;
char* Matrix;
int answer = 0;

int count_black (int h_hiddens[], int w_hiddens[]) {
  int i, j;
  int count = 0;
  for (i = 0; i < H; i++) {
    if (h_hiddens[i]) continue;
    for (j = 0; j < W; j++) {
      if (w_hiddens[j]) continue;
      if (Matrix[i * W + j] == '#') count++;
    }
  }
  return count;
}

void count_case (int h_hiddens[], int w_hiddens[], int h_progress, int w_progress) {
  int count = count_black(h_hiddens, w_hiddens);

  if (w_progress < W) {
    count_case(h_hiddens, w_hiddens, h_progress, w_progress + 1);
    int w_hiddens_clone[W];
    memcpy(w_hiddens_clone, w_hiddens, sizeof(int) * W);
    w_hiddens_clone[w_progress] = 1;
    count_case(h_hiddens, w_hiddens_clone, h_progress, w_progress + 1);
  } else if (h_progress < H) {
    count_case(h_hiddens, w_hiddens, h_progress + 1, w_progress);
    int h_hiddens_clone[W];
    memcpy(h_hiddens_clone, h_hiddens, sizeof(int) * H);
    h_hiddens_clone[h_progress] = 1;
    count_case(h_hiddens_clone, w_hiddens, h_progress + 1, w_progress);
  } else if (count == K) {
    answer += 1;
  }
}

int main (void) {
  scanf("%d%d%d", &H, &W, &K);
  int i, j;
  Matrix = malloc(sizeof(char) * H * W);
  int h_hiddens[H];
  int w_hiddens[W];
  for (i = 0; i < H; i++) {
    scanf("%s", Matrix + i * W);
    h_hiddens[i] = 0;
  }
  for (j = 0; j < W; j++) {
    w_hiddens[j] = 0;
  }
  count_case(h_hiddens, w_hiddens, 0, 0);
  free(Matrix);
  printf("%d\n", answer);
}

Measured memory_bytes: 1708
#include <cstdio>
#include <cmath>
#define LOOP(index,times) for(int index=0;index<times;index++)
using namespace std;

int main(){

int a,b;

while(scanf("%d %d",&a,&b) != EOF){

printf("%d\n",int(log10(a+b))+1);

}
return 0;		
}

Measured memory_bytes: 1072
a = input()

if a == 'SUN':
  print(7)
elif a == 'MON':
  print(6)
elif a == 'TUE':
  print(5)
elif a == 'WED':
  print(4)
elif a == 'THU':
  print(3)
elif a == 'FRI':
  print(2)
else:
  print(1)

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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vector<ll> acc(n + 1);
    acc[1] = acc[0];
    for(int i=0;i<n-1;i++){
        if(s[i] == 'A' && s[i+1] == 'C') acc[i+2] = acc[i+1] + 1;
        else acc[i+2] = acc[i+1];
    }
    for(int i=0;i<q;i++){
        int l, r; cin >> l >> r;
        if(l - 2 >= 0 && s[l-2] == 'A' && s[l-1] == 'C'){
            cout << acc[r] - acc[l-1] - 1 << endl;
        }else{
            cout << acc[r] - acc[l-1] << endl;
        }
    }
}


Measured memory_bytes: 1872
# その23
# ABC118 B - Foods Loved by Everyone

n,m = map(int,input().split())
K_2=[]
t = 0
for i in range(n):
    A, *K =list(map(int,input().split()))
    K_2 +=K
K_3 = list(set(K_2))
for j in range(len(K_3)):
    K_4 = K_2.count(K_3[j])
    if K_4 == n:
        t +=1
print(t)

Measured memory_bytes: 62908
NIL = -1
class Node():
    def __init__(self, val):
        self.val = val
        self.parent = NIL
        self.left = NIL
        self.right = NIL
    def __str__(self):
        return "val:{}, parent:{}, left:{}, right:{}".format(self.val, self.parent, self.left, self.right)
        
class Tree():
    def __init__(self):
        self.Nodes = {}
        self.Nodes[NIL] = Node(NIL)
        self.root = self.Nodes[NIL]
        
    def insert(self, node):
        y = self.Nodes[NIL]
        x = self.root
        while x.val != NIL:
            y = x
            if(node.val < x.val):
                x = self.Nodes[x.left]
            else:
                x = self.Nodes[x.right]
        node.parent = y.val
        
        if(y.val == NIL):
            self.root = node
        elif(node.val < y.val):
            y.left = node.val
        else:
            y.right = node.val
        self.Nodes[node.val] = node

    def getPreOrder(self):
        return self.preParse(self.root.val, [])    
        
    def getInOrder(self):
        return self.inParse(self.root.val, [])
    
    def getPostOrder(self):
        return self.postParse(self.root.val, [])
        
    def inParse(self, u, res):
        if(u == NIL):
            return
        self.inParse(self.Nodes[u].left, res)
        res += [u]
        self.inParse(self.Nodes[u].right, res)
        return res

    def postParse(self, u, res):
        if(u == NIL):
            return
        self.postParse(self.Nodes[u].left, res)
        self.postParse(self.Nodes[u].right, res)
        res += [u]
        return res
    
    def preParse(self, u, res):
        if(u == NIL):
            return 
        res += [u]
        self.preParse(self.Nodes[u].left, res)
        self.preParse(self.Nodes[u].right, res)
        return res
        
n = int(input())

tree = Tree()
for row in range(n):
    operate = input().split()
    if(operate[0] == "insert"):
        tree.insert(Node(int(operate[1])))
        
    if(operate[0] == "print"):
        print(" {}".format( " ".join([str(ss) for ss in tree.getInOrder()])))
        print(" {}".format( " ".join([str(ss) for ss in tree.getPreOrder()])))


Measured memory_bytes: 162312
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;int main(){int n,i;vector<int> h;for(i=0;i<10;++i)cin>>n,h.push_back(n);sort(h.begin(),h.end());for(i=9;i>6;i--)cout<<h[i]<<endl;}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <iomanip>
#define For(i,j,k) for(int i=j;i<=k;i++)
#define Dow(i,j,k) for(int i=j;i>=k;i--)
#define LL long long
using namespace std ;

inline LL read() {
	LL x = 0 , f = 1 ;
	char ch = getchar() ;
	while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar() ; }
	while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar() ; }
	return x * f ;
}

const int N = 2e5+11;
int n,x,tot;
int a[N],id[N];

int main() {
	n=read();
	For(i, 1, n) a[i]=read();
	int x = n;
	while(x>0) {
		id[++tot]=x;
		x-=2;
	}
	int l, r=n-1;
	if(n&1) l=2;
	else l=1;
	while(l<=r) {
		id[++tot]=l;
		l+=2;
	}
	For(i, 1, tot) 
		printf("%d ",a[ id[i] ]);
}









Measured memory_bytes: 3712
#include <iostream>
#include <vector>

using namespace std;

long long MOD = 1000000000+7;

int main() {
  long long N; cin >> N;
  vector<long long> A(N);
  vector<long long> s(N+1);
  for (long long i = 0; i < N; i++) cin >> A[i];
  s[0] = 0;
  for (long long i = 0; i < N; i++) {
    s[i+1] = (s[i]+A[N-1-i]) % MOD;
  }
  long long result = 0;
  for (long long i = 0; i < N-1; i++) {
    long long tmp = (A[i]*s[N-1-i]) % MOD;
    result = (result + tmp) % MOD;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 6364
N,M,X,Y=map(int,input().split(" "))
x=list(map(int,input().split(" ")))
y=list(map(int,input().split(" ")))

flug1=False
flug2=False
Z=0
for i in range(X,Y+1):
    for j in range(N):
        if i<=x[j]:
            flug1=True
            break

    for j in range(M):
        if i>y[j]:
            flug1=True
            break

    if flug1==False:
        flug2=True
        Z=i
        
    flug1=False

if flug2:
    if Z>X and Z<=Y:
        print("No War")
    else:
        print("War")
else:
    print("War")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int i,n,mid=0,max=0;
  cin >>n;
  vector<int> data(n),tmp(n);

  for(i=0;i<n;i++){
    cin>>data.at(i);
  }
  tmp=data;
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  max=data.at(0);
  mid=data.at(1);

  for(i=0;i<n;i++){
    if(tmp.at(i)==max){
      cout<<mid<<endl;
    }else{
      cout<<max<<endl;
    }
  }


  return 0;
}


Measured memory_bytes: 3200
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>

int main(void) {
    int n;
    std::scanf("%d", &n);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        std::scanf("%d %d", &l, &r);
        ans += r - l + 1;
    }
    std::printf("%d\n", ans);
    return 0;
}

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

using namespace std;

#define show(x) cerr << #x << " = " << x << endl;


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

  vector<int> v(n);

  int votes = 0;

  while(n--)
  {
    int e;
    cin>>e;
    votes+= e;
    v.push_back(e);

  }

  sort(v.rbegin(), v.rend());

  int popularSeleted = 0;
  for(int i=0; i<m;i++)
  {
    if(4*m*v[i]>=votes)
    {
      popularSeleted++;
    }
  }

  string ans = (popularSeleted==m?"Yes":"No");
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int count = 0;
        int p = 0;
        for (int i = 0 ; i < n - 1 ; i++) {
            if (p == 0) {
                p = a[i + 1] - a[i];
            } else if (p > 0) {
                if (a[i + 1] - a[i] < 0) {
                    count++;
                    p = 0;
                }
            } else {
                if (a[i + 1] - a[i] > 0) {
                    count++;
                    p = 0;
                }
            }
        }

        System.out.println(count + 1);
    }

}


Measured memory_bytes: 51640
#!/usr/bin/env python3
import sys


def solve(A: int, B: int):
    if A >=13:
        print(B)
    elif A >=6 and A <= 12:
        print(int(B/2) )
    else:
        print(0)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 1000000007; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;

int N;
void dfs(string s, char mx){
  if(s.length() == N) cout << s << endl;
  else{
    for(char c = 'a'; c <= mx; c++){
      dfs(s+c, ((c == mx)? char(mx+1): mx));
    }
  }
}

signed main() {
  cin >> N;

  dfs("", 'a');

  return 0;
}

Measured memory_bytes: 1536
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD  998244353
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	string s;
	cin >> s;
	int a = 10 * (s[0] - '0') + s[1] - '0';
	int b = 10 * (s[2] - '0') + s[3] - '0';
	if (1 <= a && a <= 12) {
		if (1 <= b && b <= 12) {
			cout << "AMBIGUOUS" << endl;
			return 0;
		}
		else {
			cout << "MMYY" << endl;
			return 0;
		}
	}
	else {
		if (1 <= b && b <= 12) {
			cout << "YYMM" << endl;
			return 0;
		}
		else {
			cout << "NA" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256