akhauriyash/Code-Regression huggingface dataset:
void main() {
	auto S = rs;
	("A" ~ S[8] ~ "C").writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for ( int i = 0; i < (n) ; i++)
typedef long long ll;
/* main */
int main() {
  ll n, ans = 0;
  map<string, int> mp;
  cin >> n;
  string s;
  rep(i, n) {
    cin >> s;
    sort(s.begin(), s.end());
    mp[s]++;
  }
  for (auto& p : mp){
    int s = p.second;
    ans += (ll)s * (s - 1) / 2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 11136
import math

def sum_digits(n):
    r = 0
    while n / 10 > 0:
        r += n % 10
        n = math.floor(n/10)
    return r


if __name__ == '__main__':
    n = int(input())

    s = sum_digits(n)
    if n % s == 0:
        print('Yes')
    else:
        print('No')


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

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> w(n),sum(n);
    rep(i,n){
        cin >> w[i];
        if(i == 0){
            sum[i] = w[i];
        }else{
            sum[i] = w[i] + sum[i-1];
        }
    }
    int min = -1, eval = 0;
    rep(i, n-1){
        eval = abs((sum[n-1] - sum[i]) - sum[i]);
        if(min < 0 || eval < min){
            min = eval;
        }
    }
    cout << min << endl;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(string.Join(Environment.NewLine, Enumerable.Repeat(0, int.Parse(Console.ReadLine().Split(' ')[0])).Select(_ => Console.ReadLine().ToCharArray()).Where(p => p.Any(q => q == '#')).Transpose().Where(p => p.Any(q => q == '#')).Transpose().Select(p => new string(p))));
        }
    }

    static class Ex
    {
        public static IEnumerable<T[]> Transpose<T>(this IEnumerable<IEnumerable<T>> source)
        {
            var es = source.Select(p => p.GetEnumerator()).ToArray();
            while(es.All(p => p.MoveNext()))
            {
                yield return Array.ConvertAll(es, p => p.Current);
            }
        }
    }
}


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

using namespace std;

#define N 300000

int n,tmp,sum,bit,cnt[N],a[N],b[N],ans[30];

bool cmp(int x,int y){return (x&((1<<bit)-1))<(y&((1<<bit)-1));}

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (int i=1;i<=n;++i) scanf("%d",&b[i]);
	for (bit=0;bit<=28;++bit){
		sort(a+1,a+n+1,cmp); sort(b+1,b+n+1,cmp);
		for (int i=1;i<=n;++i) cnt[i]=cnt[i-1]+(b[i]>>bit&1);
		for (int i=1,j=n;i<=n;++i){
			for (;j>=1&&(a[i]&((1<<bit)-1))+(b[j]&((1<<bit)-1))>=(1<<bit);--j);
			int sum=cnt[j]+(n-j)-(cnt[n]-cnt[j]);
			if (a[i]>>bit&1) sum=n-sum;
			ans[bit]^=sum&1;
		}
	}
	for (int i=0;i<=28;++i) tmp=tmp+ans[i]*(1<<i);
	printf("%d\n",tmp);
	
	return 0;
}
			

Measured memory_bytes: 2560
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long k = scanner.nextLong();
        long n = scanner.nextLong();
        long max = -1;
        long maxValue = -1;
        List<Long> hs = new ArrayList<>();
        long last = 0;
        long first = -1;
        long c = Long.MIN_VALUE;
        long count = -1;
        for (int i = 0; i < n; i++) {
            c = scanner.nextLong();
            hs.add(c);
            count++;
            if (first == -1) {
                first = c;
                last = c;
            } else {
                if (c - last > maxValue) {
                    maxValue = c - last;
                    max = count;
                }
                last = c;
            }
        }
        if (maxValue < k - c + first) {
            maxValue = k - c + first;
            max = 1;
        }
        if (max == n-1) {
            if (maxValue < hs.get(0) + k - hs.get(hs.size()-1)) {
                System.out.println(hs.get(hs.size()-1));
                return;
            }
        }
        if (max == 1) {
            System.out.println(hs.get(hs.size()-1) - hs.get(0));
            return;
        }
        long f = hs.get(Math.toIntExact(max - 1));
        long l = k - hs.get(Math.toIntExact(max));
        long r = f + l;
        System.out.println(r);
    }

}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  string s;
  cin >> s;
  char last = 'A';
  int bc = 0;
  ll res = 0;
  for(char c : string(s.rbegin(),s.rend())){
    if(c == 'A'){
      int k = 0;
      if(last == 'B'){
        k = bc/2;
      }
      res += k;
      bc = k*2;
    }else{
      if(c != last){
        bc++;
        last = c;
      }else{
        bc = 1;
      }
    }
  }
  cout << res << "\n";





  return 0;
}

Measured memory_bytes: 772
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef pair<int,int> pa;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
const int N=5e3+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
ll fac[M],ifac[M],dp[N][N];
int n,k;
il ll C(ll n,ll m){
	if(n<0||m<0||n<m)return 0;
	return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main(){
	read(n,k);
	if(k==1)return puts("1"),0;
	fac[0]=1;rep(i,1,n*k)fac[i]=(fac[i-1]*i)%mod;
	ifac[n*k]=qpow(fac[n*k],mod-2,mod);
	repd(i,n*k-1,0)ifac[i]=ifac[i+1]*(i+1)%mod;
	dp[0][0]=1;
	rep(i,0,n)rep(j,i,n){
		if(i)dp[i][j]=dp[i-1][j];	
		if(j)dp[i][j]=(dp[i][j]+dp[i][j-1]*C(i+j*(k-1)-1,k-2))%mod;
	}
	cout<<fac[n]*dp[n][n]%mod;
}

Measured memory_bytes: 144640
#include <cstdio>

long long S;
long long dfs(long long x, long long ex)
{
	long long t = x % 10, ans = x + ex, p = 10; x /= 10;
	for (; x; t += (x % 10) * p, x /= 10, p *= 10)
		ans += dfs(x, ex + t);
	return ans;
}

int main()
{
	scanf("%lld", &S), printf("%lld\n", dfs(S, 0));
	return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>
#include <iterator>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

typedef  unsigned long long ull;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }


struct E {
	int to, rev, cap;
	E(int to, int rev, int cap) : to(to), rev(rev), cap(cap) {}
};

const int MAX_V = 1000;
int level[MAX_V], iter[MAX_V];
vector<E> e[MAX_V];

void add_edge(int f, int t, int c) {
	e[f].push_back(E(t, sz(e[t]), c));
	e[t].push_back(E(f, sz(e[f]) - 1, c));
}

void bfs(int s) {
	memset(level, -1, sizeof(level));
	queue<int> q;
	level[s] = 0;
	q.push(s);
	while (!q.empty()) {
		int v = q.front(); q.pop();
		for (auto t : e[v]) {
			if (t.cap > 0 && level[t.to] < 0) {
				level[t.to] = level[v] + 1;
				q.push(t.to);
			}
		}
	}
}

int dfs(int v, int t, int f) {
	if (v == t) return f;
	for (int &i = iter[v]; i < sz(e[v]); i++) {
		E& _e = e[v][i];
		if (_e.cap > 0 && level[v] < level[_e.to]) {
			int d = dfs(_e.to, t, min(f, _e.cap));
			if (d > 0) {
				_e.cap -= d;
				e[_e.to][_e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s, int t) {
	int flow = 0;
	while (true) {
		bfs(s);
		if (level[t] < 0) return flow;
		memset(iter, 0, sizeof(iter));
		int f;
		while ((f = dfs(s, t, ten(8))) > 0) {
			flow += f;
		}
	}
}

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	FOR(i, n - 1) cin >> v[i + 1];
	int st = n, ed = n + 1;
	FOR(i, n - 1) {
		int u, v, p; cin >> u >> v >> p;
		add_edge(u, v, p);
	}
	add_edge(st, 0, ten(8));
	FOR(i, n) if (v[i] != 0) {
		add_edge(i, ed, ten(8));
	}

	int ans = max_flow(st, ed);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1308
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Rep(i,v) rep(i,0,(int)v.size()-1)
#define lint long long
#define ull unsigned lint
#define db long double
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define gc getchar()
#define debug(x) cerr<<#x<<"="<<x
#define sp <<" "
#define ln <<endl
using namespace std;
typedef pair<int,int> pii;
typedef set<int>::iterator sit;
inline int inn()
{
	int x,ch;while((ch=gc)<'0'||ch>'9');
	x=ch^'0';while((ch=gc)>='0'&&ch<='9')
		x=(x<<1)+(x<<3)+(ch^'0');return x;
}
char s[1000010];
int main()
{
	int n=inn();scanf("%s",s+1);
	int q=inn();
	while(q--)
	{
		lint ans=0,sm=0;
		int pt=0,cnt=0,k=inn();
		for(int i=1,j=i-k;i<=n;i++,j++)
		{
			if(j>=1&&s[j]=='D') sm-=pt,cnt--;
			if(j>=1&&s[j]=='M') pt--;
			if(s[i]=='D') cnt++;
			else if(s[i]=='M') pt++,sm+=cnt;
			else if(s[i]=='C') ans+=sm;
		}
		printf("%lld\n",ans);
	}
	return 0;
}

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

string s;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> s;
    reverse(s.begin(), s.end());
    int l = 0;
    while (l < s.size()) {
		if (s.size() - l < 5) {
			cout << "NO";
			return 0;
		}		
		
		if (s.substr(l, 5) == "maerd") {
			l += 5;
		} else if (s.substr(l, 5) == "esare") {
			l += 5;
		} else if (s.size() - l >= 6 && s.substr(l, 6) == "resare") {
			l += 6;
		} else if (s.size() - l >= 7 && s.substr(l, 7) == "remaerd") {
			l += 7;
		} else {
			cout << "NO";
			return 0;
		}
	}
	
	cout << "YES";
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    int n;
    cin >> n;
    cout << (n * n + n) / 2 << '\n';
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc140/tasks/abc140_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,K; cin >> N >> K;
    string S; cin >> S;
    for(int i = 0; i < N-1;i++){
        if(S[i] == 'R' && S[i+1] == 'R') res++;
    }
    for(int i = 1; i < N;i++){
        if(S[i-1] == 'L' && S[i] == 'L') res++;
    }
    
    res = min(N-1,res + 2*K);
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 512
import numpy as np

inputs = raw_input().replace("\n", "").split(" ")
N, x = map(int, inputs)
inputs = raw_input().replace("\n", "").split(" ")
a_list = np.asarray(sorted(map(int, inputs)))

a_sum = np.sum(a_list)

if a_sum < x:
    print N - 1
elif a_sum == x:
    print N
else:
    if a_list[0] > x:
        print 0
    else:
        b_sum_list = np.asarray([np.sum(a_list[:i+1]) for i in xrange(N) ])
        max_index = np.max(np.where(b_sum_list <= x)[0])
        print max_index + 1

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

#define INF 100000000
#define MOD9(a) (a%1000000009)
#define MOD7(a) (a%1000000007)
#define ABS(a) (a<0?-(a):a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define REP(i,a) for(int i=0;i<a;i++) 

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

  if(a == b+c || b == a+c || c == a+b){
    cout << "Yes" << endl; 
  }else{
    cout << "No" << endl; 
  }

}



Measured memory_bytes: 256
def gcd(a,b): 
    if a == 0: 
        return b 
    return gcd(b % a, a) 
  
def lcm(a,b): 
    return (a*b) / gcd(a,b) 

def main():
    A, B = list(map(int, input().split()))

    print(int(lcm(A,B)))

if __name__ == "__main__":
    main()


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

using namespace std;

int main() {
  int a, b;
  cin >> a >> b;
  for (int i = 1; i <= 1000000; ++i) {
    if (i * 2 / 25 == a && i / 10 == b) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}

Measured memory_bytes: 256
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}
ll mypow(ll n,ll p){
  if (p == 0)return 1;
  if (p == 1)return n;
  ll ret=mypow(n,p/2);
  ret=ret*ret;
  if (p&1)ret=ret*n;
  return ret;
}

const int N = 2000;
int table[N][N];

ll solve(int n, vector<ll>&in, ll x){
  rep(i,n){
    rep(j,n){
      table[i][j] = in[(i-j+n)%n];
    }
    REP(j,1,n){
      table[i][j] = min(table[i][j], table[i][j-1]);
    }
  }

  ll ret = accumulate(begin(in), end(in), 0LL);
  rep(j,n){
    ll tmp = j * x;
    rep(i,n){
      tmp += table[i][j];
    }
    ret = min(ret, tmp);
  }
  return ret;
}
 
int main(){
  int n;
  ll x;
  cin >> n >> x;
  vector<ll> in(n);
  rep(i,n)cin>>in[i];
  cout << solve(n, in, x) << endl;
  return 0;
}
 
 


Measured memory_bytes: 15872
#include<iostream>
#include<algorithm>
#include<math.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<random>
#include<numeric>
#include<string>
#include<stack>
#include<cstring>
typedef long long ll;
typedef long double ld;
using namespace std;
ll dx[] = { 0,0,1,-1 };
ll dy[] = { 1,-1,0,0 };

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b)*b;
}
int main() {
	ll N;
	cin >> N;
	ll sum = 0;
	ll s[1000];
  	ll cnt=0;
	for (ll i = 0; i < N; i++) {
		cin >> s[i];
		sum += s[i];
      	if(s[i]%10==0)
          cnt++;
	}
  	
	sort(s, s + N);
  	ll ans;
  	if(cnt==N)
      ans=0;
	if (sum % 10 != 0) {
		ans =sum;
	}
	else {
		for (ll i = 0; i < N; i++) {
			if (s[i] % 10 != 0) {
				sum -= s[i];
				ans = sum;
				break;
			}
		}
	}
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>  
#include<algorithm>  
using namespace std;  
const int maxn = 107;  
int n,a[maxn];  
int main()  
{  
    cin>>n;  
    for(int i=1;i<=n;i++)cin>>a[i];  
    sort(a+1,a+1+n);  
    int sum1 = 0;  
    int sum2 = 0;  
    for(int i=1;i<=n;i+=2)  
    {  
        sum1+=a[i];  
    }  
    for(int i=2;i<=n;i+=2)  
    {  
        sum2+=a[i];  
    }  
    if(n&1)cout<<sum1-sum2<<endl;  
    else cout<<sum2-sum1<<endl;  
    return 0;  
}  

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.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, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
const int dx[4] = {1, 0, -1, 0} , dy[4] = {0, 1, 0, -1};
/*mod逆元*/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;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

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

    int n; cin >> n;
    map<int,int> mp;
    while(n--){
        int a; cin >> a;
        mp[a]++; a--;
        mp[a]++; a+=2;
        mp[a]++;
    }
    int ans = 1;
    for(auto x : mp) chmax(ans,x.second);
    out(ans);

    return 0;
}

Measured memory_bytes: 6144
# from math import gcd
from fractions import gcd
import sys

N, M = map(int, input().split())
S = input()
T = input()

d = gcd(N, M)
m = N * M // d

for i in range(d):
    if S[i * (N // d)] != T[i * (M // d)]:
        print(-1)
        sys.exit()

print(m)


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

int main() {
	int N;
	std::cin >> N;
	std::vector<int> button(N);
	for (int i = 0; i < N; i++) {
		std::cin >> button.at(i);
	}

	int light = 0;
	int cnt = 0;
	while (light != 1 && cnt < N) {
		light = button.at(light) - 1;
		cnt++;
	}

	if (light != 1) {
		std::cout << -1 << std::endl;
	}else{
		std::cout << cnt << std::endl;
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 888
import sys
count = 0

def insertionSort(A, n, g):
    global count
    for i in range(n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            count += 1
        A[j+g] = v
    return A

def shellSort(A, n):
    for i in range(m):
        insertionSort(A, n, G[i])
    return A

n = int(input())
A = []
for i in range(n):
    A.append(int(input()))

G = [1]
m = 1
while True:
    x = 3 * G[m-1] + 1
    if x >= n: break
    G.append(x)
    m += 1
G = G[::-1]

shellSort(A, n)

print(m)
print(' '.join([str(i) for i in G]))
print(count)
for i in A:
    print(i)

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

int main() {
  string S;
  cin >> S;
  
  	if (S.at(0) == S.at(1)) {
      cout << "Bad" << endl;
    }
  	else if (S.at(1) == S.at(2)) {
      cout << "Bad" << endl;
    }
  	else if (S.at(2) == S.at(3)) {
      cout << "Bad" << endl;
    }
  	else {
      cout << "Good" << endl;
    }
}

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

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

  int n,x;
  cin >> n >> x;
  int d;
  int ans = 0;
  int dmin = 1000;
  for(int i = 0; i < n; i++){
    cin >> d;
    x -= d;
    ans++;
    dmin = min(dmin, d);
  }
  if(x > 0) ans += x / dmin;

  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++)
    cin >> a.at(i);
  
  sort(a.begin(), a.end());
  
  cout << a.at(n/2) - a.at(n/2-1) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, std::vector<long long> A){
  vector<ll> a(N);
  for (int i = 0; i < N-1; i++) {
    a[A[i]-1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << a[i] << endl;
  }
}

int main(){
    long long N;
	scanf("%lld",&N);
	std::vector<long long> A(N-2+1);
	for(int i = 0 ; i < N-2+1 ; i++){
		scanf("%lld",&A[i]);
	}
    solve(N, std::move(A));
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> dic;
    map<ll, ll> first;
    map<ll, ll> second;

    rep(i, n)
    {
        cin >> a.at(i);
        if (!dic.count(a.at(i))) {
            dic[a.at(i)] = 1;
        } else {
            dic[a.at(i)]++;
        }
    }

    ll sum = 0;
    for (auto p : dic) {
        auto key = p.first;
        auto value = p.second;
        first[key] = value * (value - 1) / 2;
        second[key] = (value - 1) * (value - 2) / 2;
        sum += first[key];
    }

    rep(i, n)
    {
        cout << sum - first[a.at(i)] + second[a.at(i)] << endl;
    }
}

Measured memory_bytes: 26880
#include<iostream>
using namespace std;
#define ll long long
#include<bits/stdc++.h>
int main(){
  string s;
  cin>>s;
  int n=s.size();
  string p=s.substr(0,n/2);
  string r=s.substr((n/2)+1);
  if(p==r)
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

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

int main() {
    int a,b,n;
  cin >> a >> b;
  if(a>b){
    n += a;
    a--;
  }else{
    n += b;
    b--;
  }
    if(a>b){
    n += a;
    a--;
  }else{
    n += b;
    b--;
  }

    cout << n << endl;
}

Measured memory_bytes: 256
<?php

(new Main)->execute();


class Rectangle
{
    private $height;
    private $width;
    private $style;

    private $rectangle = [];

    public function __construct($height, $width, $style)
    {
        $this->height = $height;
        $this->width  = $width;
        $this->style  = $style;

        $this->rectangle = $this->make();
    }

    private function make()
    {
        $rectangle = [];
        for ($height = 0; $height < $this->height; $height++) {
            $rectangle[$height] = str_repeat($this->style, $this->width);
        }
        return $rectangle;
    }

    private function setColsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            for ($width = 0; $width < $thickness; $width++) {
                $this->rectangle[$height][$width]                = $style;
                $this->rectangle[$height][$this->width - $width - 1] = $style;
            }
        }
    }

    private function setRowsInnerFrame($thickness, $style)
    {
        foreach ($this->rectangle as $height => $_) {
            if ($height >= $thickness) { return; }

            $this->rectangle[$height]                 = str_repeat($style, $this->width);
            $this->rectangle[$this->height - $height - 1] = str_repeat($style, $this->width);
        }
    }

    public function setInnerFrame($thickness = 1, $style = '#')
    {
        if ($thickness > $this->width) {
            $thickness = $this->width;
        }

        $this->setRowsInnerFrame($thickness, $style);
        $this->setColsInnerFrame($thickness, $style);

        return $this;
    }

    public function get()
    {
        return implode(PHP_EOL, $this->rectangle).PHP_EOL;
    }
}

class Main
{
    public function execute()
    {
        while (true) {
            list($height, $width) = $this->getStdinExplodedBy(' ');
            if ($this->invalid($height, $width)) { return; }

            $rectangle = (new Rectangle($height, $width, '.'))
                ->setInnerFrame()
                ->get();

            $this->draw($rectangle);
        }
    }

    private function getStdinExplodedBy($delimiter)
    {
        return explode($delimiter, trim(fgets(STDIN)));
    }

    private function invalid($height, $width)
    {
        return $height == 0 && $width == 0;
    }

    public function draw($shape)
    {
        echo $shape, PHP_EOL;
    }
}

Measured memory_bytes: 15516
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    
    int n, l;
    cin >> n >> l;
    vector<string> S(n);
    rep(i, n) {
        cin >> S[i];
    }

    sort(S.begin(), S.end());
    rep(i, n) {
        cout << S[i];
    }
    cout<< endl;
}

Measured memory_bytes: 256
a, b, c, d = [int(x) for x in list(input())]
# a, b, c, d = 1, 2, 2, 2
# ans = a


# op1, op2, op3 = '', '', ''
# for i in range(2):
#     for j in range(2):
#         for k in range(2):
#             if i:
#                 ans -= b
#             else:
#                 ans += b
#             if j:
#                 ans -= c
#             else:
#                 ans += c
#             if k:
#                 ans -= d
#             else:
#                 ans += d

#             if ans == 7:
#                 # OK
#                 op1 = '-' if i else '+'
#                 op2 = '-' if j else '+'
#                 op3 = '-' if k else '+'

# print(f'{a}{op1}{b}{op2}{c}{op3}{d}')

# 調べた。bit全探索
# op = [[None] * 3 for _ in range(2 ** 3)]
nums = (b, c, d)
for i in range(2 ** 3):
    ans = a
    op = []
    for shift in range(3):
        if i >> shift & 1:
            op.append('+')
            ans += nums[shift]
        else:
            op.append('-')
            ans -= nums[shift]
    if ans == 7:
        print(a, op[0], b, op[1], c, op[2], d, '=7', sep='')
        break


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#define int long long
using namespace std;

const int mod = 1e9 + 7;
const int TREE_SZ = 1 << 19;

vector<int> mx(TREE_SZ, -2e18);

int get_max(int v, int l, int r, int L, int R) {
    if (r <= L || R <= l) {
        return -2e18;
    }
    if (L <= l && r <= R) {
        return mx[v];
    }
    int m = (l + r) / 2;
    return max(
                get_max(2 * v + 1, l, m, L, R),
                get_max(2 * v + 2, m, r, L, R)
            );
}

void set_elem(int v, int l, int r, int i, int x) {
    mx[v] = max(mx[v], x);
    if (l == r - 1) {
        return;
    }
    int m = (l + r) / 2;
    if (i < m) {
        set_elem(2 * v + 1, l, m, i, x);
    } else {
        set_elem(2 * v + 2, m, r, i, x);
    }
}

int32_t main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    vector<int> b = a;
    sort(b.begin(), b.end());
    map<int, int> M;
    for (int i = 0; i < n; i++) {
        M[b[i]] = i;
    }
    for (int i = 0; i < n; i++) {
        a[i] = M[a[i]];
        //cerr << a[i] << " ";
    }
    //cerr << endl;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int cur = max(get_max(0, 0, n, 0, a[i]), 0ll) + p[i];
        //cerr << cur << endl;
        set_elem(0, 0, n, a[i], cur);
        ans = max(ans, cur);
    }
    cout << ans << endl;
}


Measured memory_bytes: 24636
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

const int MAX_N = 100;
int G[100][100];
int N;
VI dist(110);
int k[100];

void dikstra(int s) {

	priority_queue<pii, vector<pii>, greater<pii> >que;
	dist[s] = 0;
	que.push(pii(0, s));
	while (!que.empty()) {
		pii p = que.top();
		que.pop();
		int v = p.second;
		if (dist[v] < p.first)continue;
		REP(i, N) {
			if (G[v][i] == LLINF)continue;
			if (dist[i] > dist[v] + G[v][i]) {
				dist[i] = dist[v] + G[v][i];
				que.push(pii(dist[v], i));
			}
		}
	}
}

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

	cin >> N;
	REP(i, N) {
		dist[i] = INF;
		REP(j, N)G[i][j] = LLINF;
	}
	
	REP(i, N) {
		int a;
		cin >> a >> k[i];
		REP(j, k[i]) {
			int b, c;
			cin >> b >> c;
			G[a][b] = c;
		}
	}

	dikstra(0);
	


	REP(i, N)cout << i << " " << dist[i] << endl;
	//cout << dist[N - 1] << endl;
	return 0;
}




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

import sys

DEBUG = False

def solve():
    return


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def printbingo(bingo):
    if not DEBUG:
        return
    for y in range(0, 3):
        for x in range(0, 3):
            print(bingo[y][x], end=" ")
        print()


def main():
    bingo = [[]] * 3
    bingo[0] = read_int_list()
    bingo[1] = read_int_list()
    bingo[2] = read_int_list()
    locs = {}
    for y in range(0, 3):
        for x in range(0, 3):
            locs[bingo[y][x]] = (y, x)
    printbingo(bingo)
            
    n = read_int()
    for _ in range(0, n):
        b = read_int()
        if b in locs:
            bingo[locs[b][0]][locs[b][1]] = -1
    printbingo(bingo)
    
    # column check
    for y in range(0, 3):
        is_bingo = True
        for x in range(0, 3):
            if bingo[y][x] != -1:
                is_bingo = False
                break
        if is_bingo:
            print("Yes")
            return
    # row check
    for x in range(0, 3):
        is_bingo = True
        for y in range(0, 3):
            if bingo[y][x] != -1:
                is_bingo = False
                break
        if is_bingo:
            print("Yes")
            return
    # cross check
    for (y, x), (dy, dx) in [((0, 0), (1, 1)), ((0, 2), (1, -1))]:
        is_bingo = True
        while is_bingo and 0 <= y < 3 and 0 <= x < 3:
            #dprint(f"(x,y):{(x, y)}, (dx,dy):{(dx,dy)}, bing[y][x]: {bingo[y][x]}")
            if bingo[y][x] != -1:
                is_bingo = False
                break
            y += dy
            x += dx
        if is_bingo:
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
n, a, b = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n-1):
  if (l[i+1]-l[i])*a <= b:
    ans += (l[i+1]-l[i])*a
  else:
    ans += b
print(ans)

Measured memory_bytes: 62704
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int MAX_N = 100050;
V(bool) isp(MAX_N, true);

void judp() {
    isp[0] = false;
    isp[1] = false;
    for(int i=2; i*i<MAX_N; i++) {
        if(isp[i]==false) continue;
        for(int j=i*2; j<MAX_N; j+=i) {
            isp[j] = false;
        }
    }
}


signed main() {
    int Q;
    cin >> Q;
    vi l(Q), r(Q);
    rep(i, Q) cin >> l[i] >> r[i];

    judp();
    vi sums(100050, 0);
    FOR(i, 1, 100050) {
        if(isp[i] && isp[(i+1)/2] && i%2) sums[i] = sums[i-1] + 1;
        else sums[i] = sums[i-1];
    }

    rep(i, Q) {
        int temp = sums[r[i]] - sums[l[i]-1];
        cout << temp << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2944
#include<stdio.h>

#define N 100001
#define NIL -1

struct Node{
  int parent, left, right;
};

struct Node Tree[N];
int Depth[N], Height[N];

void setDepth(int, int);
int setHeight(int);
int Sibling(int);
void Print(int);

int main(){
  int n,i,num,l,r;
  int root = 0;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++) Tree[i].parent = NIL;

  for(i = 0 ; i < n ; i++){
    scanf("%d%d%d",&num,&l,&r);
    Tree[num].left = l;
    Tree[num].right = r;
    if(l != NIL) Tree[l].parent = num;
    if(r != NIL) Tree[r].parent = num;
  }

  for(i = 0 ; i < n ; i++) if(Tree[i].parent == NIL) root = i;

  setDepth(root,0);
  setHeight(root);

  for(i = 0 ; i < n ; i++) Print(i);

  return 0;
}

void setDepth(int x, int y){
  if(x == NIL) return;
  Depth[x] = y;
  setDepth(Tree[x].left, y+1);
  setDepth(Tree[x].right, y+1);
}

int setHeight(int x){
  int h1 = 0, h2 = 0;
  if(Tree[x].left != NIL) h1 = setHeight(Tree[x].left) + 1;
  if(Tree[x].right != NIL) h2 = setHeight(Tree[x].right) + 1;

  if(h1 > h2) return Height[x] = h1;
  else return Height[x] = h2;
}

int Sibling(int x){
  if(Tree[x].parent == NIL) return NIL;
  if(Tree[Tree[x].parent].left != x && Tree[Tree[x].parent].left != NIL){
    return Tree[Tree[x].parent].left;
  }
  if(Tree[Tree[x].parent].right != x && Tree[Tree[x].parent].right != NIL){
    return Tree[Tree[x].parent].right;
  }

  return NIL;
}

void Print(int x){
  int degree = 0;
  printf("node %d: ",x);
  printf("parent = %d, ",Tree[x].parent);
  printf("sibling = %d, ",Sibling(x));
  if(Tree[x].left != NIL) degree++;
  if(Tree[x].right != NIL) degree++;
  printf("degree = %d, ",degree);
  printf("depth = %d, ",Depth[x]);
  printf("height = %d, ",Height[x]);

  if(Tree[x].parent == NIL){
    printf("root\n");
  }
  else if(Tree[x].left == NIL && Tree[x].right == NIL){
    printf("leaf\n");
  }
  else printf("internal node\n");
}



Measured memory_bytes: 2148
#include<bits/stdc++.h>
#define int           long long
#define pb            push_back
#define ppb           pop_back
#define si            set <int>
#define endl          '\n'
#define fr            first
#define sc            second     
#define rep(i,a,b)    for(int  i=a;i<b;i++)
#define repr(i,a,b)      for(int i=b-1;i>=a;i--)
#define trav(it,v)      for(auto it=v.begin();it!=v.end();it++)
#define all(v)        v.begin(),v.end()
#define srt(v)        sort(all(v))
#define vs            vector<string>
#define sz(x)         (int )x.size()
#define M             1000000007
#define bs            binary_search
#define sp(n)         setprecision(n)
#define spl           " "
#define arr(a,n)      rep(i,0,n) cin>>a[i]
#define mod           998244353
#define MAXN             10001

using namespace std;

bool sortinrev(const pair<int,int> &a,  
               const pair<int,int> &b) 
{ 
       return (a.first > b.first); 
} 


//int dx[4]={0,0,1,-1};
//int dy[4]={1,-1,0,0};
void solve()
{
    
    int n,k;
    cin>>n>>k;
    if(n>k)
        n=n%k;
    cout<<min(k-n,n);

    
    
}	
	


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t=1;
    //cin>>t;
    while(t--)
    {
    	solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define MAXN 2*int(1e5)+5
#define endl '\n'
#define ll long long
#define f first
#define s second
#define int long long
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<ll, ll> pii;
const ll mod = 1e9+7;
 
int32_t main(){
	int n, r, d;
	cin >> n >> r >> d;
	vector<pii> v(n);
	for(pii &i : v)
		cin >> i.f >> i.s;
	sort(v.begin(), v.end());
		
	ll last = 0;
	ll qtd = 0, ans = 0;
	set<pii> rmv;
	
	
	for(int i = 0; i < n; i++) {
		
		for(auto &x : rmv) {
			if(x.f < v[i].f) {
				qtd -= x.s;
				rmv.erase(x);
			}
			else break;
		}
		
		v[i].s -= qtd;
		if(v[i].s <= 0) continue;
		
		
		
		ll k = (v[i].s+d-1)/d;
		ans += k;
		qtd += k*d;
		last = v[i].f+2*r;
		
 
		
		rmv.insert({last, k*d});
		
	}
	
	cout << ans << endl;
 
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-10;
const bool debug = 0;
//---------------------------------//

vector<int> z_algorithm(string s) {
	vector<int> res(s.size());
	
	res[0] = s.size();
	
	int i = 1, j = 0;
	
	while (i < s.size()) {
		while (i + j < s.size() && s[j] == s[i + j]) j++;
		res[i] = j;
		if (j == 0) { i++; continue; }
		int k = 1;
		while (i + k < s.size() && k + res[k] < j) res[i + k] = res[k], k++;
		i += k;
		j -= k;
	}
	
	return res;
}

string S, T;
ll l, r;
ll cnt[100][26], size[100], ans[26]; // g^i(S)の各文字の数, |g^i(S)|
string s0, s1; // g^0(S), g^1(S)

ll solve(ll x, int c) {
	ll p = 0, pos = x;
	REP(i, 100) if (size[i] >= x) { p = i; break; }
	
	ll res = 0;
	
	while (p > 1) {
		if (pos >= size[p - 1]) {
			res += cnt[p - 1][c];
			pos -= size[p - 1];
			p -= 2;
		}
		else {
			p -= 1;
		}
	}
	
	res += count(s1.begin(), s1.begin() + pos, c + 'a');
	return res;
}

ll solve2(ll x, int c) {
	if (x <= 0) return 0;
	
	ll res = 0;
	if (x <= size[1]) {
		res += count(s1.begin(), s1.begin() + x, c + 'a');
	}
	else {
		ll b = cnt[1][c] - cnt[0][c], ts = size[1] - size[0]; // Tに含まれる文字cの数, |T|
		
		res += b * (x / ts);
		res += count(T.begin(), T.begin() + (x % ts), c + 'a');
	}
	
	return res;
}

int main() {
	cin >> S >> l >> r;
	
	s0 = S.substr(0, S.size() / 2);
	
	vector<int> z = z_algorithm(s0);
	int k = INF;
	FOR(i, 1, z.size()) if (z[i] + i == s0.size()) chmin(k, s0.size() - z[i]);
	if (k == INF) k = s0.size();
	
	T = s0.substr(0, k);
	s1 = s0 + T;
	
	size[0] = s0.size();
	REP(i, s0.size()) cnt[0][s0[i] - 'a']++;
	
	size[1] = s1.size();
	REP(i, s1.size()) cnt[1][s1[i] - 'a']++;
	
	if (s0.size() % k == 0) {
		REP(i, 26) ans[i] = solve2(r, i) - solve2(l - 1, i);
	}
	else {
		FOR(i, 2, 100) {
			size[i] = size[i - 1] + size[i - 2];
			REP(j, 26) cnt[i][j] = cnt[i - 1][j] + cnt[i - 2][j];
			if (size[i] > 1000000000000000000ll) break;
		}
		
		REP(i, 26) ans[i] = solve(r, i) - solve(l - 1, i);
	}
	
	REP(i, 26) printf("%lld%c", ans[i], i == 25 ? '\n' : ' ');
}

Measured memory_bytes: 1284
s = input()
n = len(s)

s1 = s[:(n-1)//2]
s2 = s[(n+3)//2 - 1:]

if s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1] :
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
w = input()
alp = ["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"]

for i in alp:
    if w.count(i)%2 != 0:
        ans = 0
        break
    else:
        ans= 1
print("Yes" if ans == 1 else"No")

Measured memory_bytes: 3060
#include <stdio.h>

int
main(int argc, char *argv[])
{
  long long a, b, x, i = 0;
  scanf("%lld %lld %lld", &a, &b, &x);

  if(a == 0)printf("%lld\n", (b / x) + 1);
  else printf("%lld", (b / x) - ((a - 1) / x));

  

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <string>
using namespace std;
typedef long long ll;

int main(void){
    ll n,k;
    cin>>n>>k;
    
    set<ll> s;
    vector<ll> m(n+1,0);
    
    
    for(ll i=0;i<n;++i){
        ll t;
        cin>>t;
        s.insert(t);
        m[t]++;
    }
    sort(m.begin(),m.end(),greater<ll>());
    ll cnt=0;
    for(ll i=k;i<n;++i){
        cnt+=m[i];
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 14004