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

using namespace std;

typedef long long ll;

int main(){
  int x, pre, post;
  cin >> x;
  pre = x / 100;
  post = x - pre*100;
  if((1<=pre && pre<=12) && (post>12 || post==0)) cout << "MMYY" << endl;
  else if((1<=post && post<=12) && (pre>12 || pre==0)) cout << "YYMM" << endl;
  else if((1<=pre && pre<=12) && (1<=post && post<=12)) cout << "AMBIGUOUS" << endl;
  else cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vint a(3);
    int ans = 6;
    REP(i,3){
        cin >> a[i];
        ans -= a[i];
    }
    cout << ans << endl;
    return 0;
}

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

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

Measured memory_bytes: 384
# include <stdio.h>
# include <bits/stdc++.h>
using namespace std;
# define fi cin
# define fo cout
# define x first
# define y second
# define ll long long
# define IOS ios_base :: sync_with_stdio(0);cin.tie(0)
# define p(v) cerr << #v << " = " << v << '\n'
# define p2(v) cerr << #v << " = " << (complex < int > (v.x,v.y)) << '\n'
# define vi vector < int >
# define vl vector < ll >
# define pii pair < int , int >
# define mp make_pair
# define db long double
# define pb push_back
# define pdd pair < db , db >
int main(void)
{
    #ifdef CF
    freopen("input","r",stdin);
    #endif // CF
    srand(time(0));
    fo << fixed << setprecision(7);
    cerr << fixed << setprecision(7);
    static int s[1 << 20];
    int n;
    fi>>n;
    int cnt = 0;
    static int v[1 << 20];
    static int p[1 << 20];
    for (int i = 1;i <= n;++i)
        fi>>v[i],p[i] = i;
    sort(p + 1,p + 1 + n,[&](int a,int b)
         {
            return v[a] < v[b];
         });
    for (int i = 1;i <= n;++i)
    {
        s[v[p[i]]] = p[i];
        for (int j = 1;j < p[i];++j)
        {
            ++cnt;
            if (cnt > v[p[i]])
                return puts("No") * 0;
            if (s[cnt])
                --j;
            else
                s[cnt] = p[i];
        }
    }
    cnt = 1;
    multiset < int > M;
    for (int i = 1;i <= n * n;++i)
    {
        if (cnt <= n && i == v[p[cnt]])
        {
            for (int j = p[cnt] + 1;j <= n;++j)
                M.insert(p[cnt]);
            ++cnt;
        }
        if (!s[i])
        {
            if (M.empty())
                return puts("No") * 0;
            s[i] = *M.begin();
            M.erase(M.begin());
        }
    }
    fo << "Yes\n";
    for (int i = 1;i <= n * n;++i)
        fo << s[i] << " \n"[i == n * n];
    cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
    return 0;
}


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

int main() {
	int n,d[100],a=0;
	int i,j;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>d[i];
	}
	for(j=0;j<n-1;j++){
		for(i=j+1;i<n;i++){
			a+=d[j]*d[i];
	}
}
cout<<a<<endl;	
	return 0;
}


Measured memory_bytes: 256
// ALDS1_11_A.cpp
// Graph I - Graph

#include <iostream>
#include <vector>
using namespace std;

void print(vector<vector<int>> &A, int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) cout << " ";
            cout << A[i][j];
        }
        cout << endl;
    }
}

int main()
{
    int n;
    cin >> n;
    int id;
    int num;
    vector<vector<int>> A(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        cin >> id >> num;
        if (num == 0) continue;
        else {
            int tmp;
            for (int j = 0; j < num; j++) {
                cin >> tmp;
                A[id - 1][tmp - 1] = 1;
            }
        }
    }

    print(A, n);

    return 0;
}

Measured memory_bytes: 3148
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int a, b, c, t;
	scanf("%d%d%d", &a, &b, &c);
	int ans=0;
	while(a%2==0 && b%2==0 && c%2==0){
		if(a==b && b==c){
			puts("-1");
			return 0;
		}
		int A=a/2, B=b/2, C=c/2;
		a=B+C, b=C+A, c=A+B;
		ans++;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        String[] ns1 = n.split("");
        List<String> s = Arrays.asList(ns1);
        List<String> kotae = new ArrayList<>();
        int x = 0;
        int y = 0;
        int z = 0;
        for(int i = 0; i < s.size(); i++){
            if (s.get(i).equals("1")){
                kotae.add("9");
            }
            else if(s.get(i).equals("9")){
                kotae.add("1");
            }
        }
        if(kotae.size() == 1){
            z = Integer.parseInt(kotae.get(0)) * 1;
        }
        else if(kotae.size() == 2){
            y = Integer.parseInt(kotae.get(0)) * 10;
            z = Integer.parseInt(kotae.get(1)) * 1;
        }
        else if(kotae.size() == 3){
            x = Integer.parseInt(kotae.get(0)) * 100;
            y = Integer.parseInt(kotae.get(1)) * 10;
            z = Integer.parseInt(kotae.get(2)) * 1;
        }

        System.out.println(x + y + z);
    }
}


Measured memory_bytes: 22740
///   ***   ---   |||         In the name of ALLAH        |||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);


#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}



const int mx = 1e5+123;
ll a[mx], b[mx];

int main()
{
    optimize();

    int n;
    ll ans = 0;

    cin >> n;
    for ( int i = 1; i <= n+1; i++ ) cin >> a[i];
    for ( int i = 1; i <= n; i++ ) cin >> b[i];

    for ( int i = n; i >= 1; i-- ) {
        ans += min ( a[i+1], b[i] );
        b[i] -= min ( a[i+1], b[i] );
        ans += min ( a[i], b[i] );
        a[i] -= min ( a[i], b[i] );
    }

    cout << ans;


    return 0;
}


















Measured memory_bytes: 1792
n, m = map(int, input().split())
h = list(map(int, input().split()))

f = [0] * 10 ** 5
c = {}
for i in range(m):
    a, b = map(int, input().split())
    if b < a:
        a, b = b, a
    if a not in c:
        c[a] = [b]
    else:
        c[a].append(b)


for k, v in c.items():

    for i in v:
        if h[k-1] < h[i-1]:
            f[k-1] = 1
        elif h[k-1] > h[i-1]:
            f[i-1] = 1
        else:
            f[k-1] = 1
            f[i-1] = 1

ans = 0
for i in range(n):
    if f[i] == 0:
        ans += 1

print(ans)


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

int main() {
  int a, b;
  cin >> a >> b;
  if (a%3 == 0 || b%3 == 0 || (a + b)%3 == 0) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
a, b = map(int,input().split())

if a > 0:
    print("Positive")
elif a == 0:
    print("Zero")
else:
    if b >= 0:
        print("Zero")
    else:
        if (b - a) % 2 != 0:
            print("Positive")
        else:
            print("Negative")

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
public class Aprob {
    public static void Main() {
        string[] readSome = new string[2];
        readSome = Console.ReadLine().Split(' ');
        if (readSome[0] == "H") {
            if (readSome[1] == "H") {
                Console.WriteLine("H");
            } else {
                Console.WriteLine("D");
            }
        } else {
            if (readSome[1] == "H") {
                Console.WriteLine("D");
            } else {
                Console.WriteLine("H");
            }
        }
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, ans = 0;
    string S;
    cin >> N >> S;
    for(int i = 0; i < N - 2; i++){
        if(S.at(i) == 'A'){
            if(S.at(i + 1) == 'B'){
                if(S.at(i + 2) == 'C'){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main ()
{
	int a,b;
	cin >> a >> b;
	cout << a/b << " " << a%b << " ";
	double ans;
	ans=1.0*a/b;
	printf("%f\n",ans);
	return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.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;

int findSumOfDigits(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
 }

int main() {
  int N; cin >> N;
  int sum = findSumOfDigits(N);
  if (N % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
n, m = map(int, input().split())
S = [list(map(int, input().split()[1:])) for _ in range(m)]
P = list(map(int, input().split()))

count = 0
for i in range(2 ** n):

    # switch state
    switches = [0] * n
    for j in range(n):
        if ((i >> j) & 1):
            switches[j] = 1
    
    # light state
    lights = [0] * m
    for k in range(m):
        on_num = sum(map(lambda x: switches[x-1], S[k]))
        if on_num % 2 == P[k]:
            lights[k] = 1
    
    # are all lights on?
    if all(light == 1 for light in lights):
        count += 1

print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0; i<n; i++) cin >> s[i];
 
  map<int, int> mp;
  for(int i=0; i<26; i++){
    mp[i] = 0;
  }
  for(int i=0; i<s[0].size(); i++) mp[s[0][i]-'a']++;
  for(int i=1; i<n; i++){
    map<int,int> num;
    for(int j=0; j<26; j++){
      num[j] = 0;
    }
    for(int j=0; j<s[i].size(); j++){
      num[s[i][j]-'a']++;
    }
    for(int j=0; j<26; j++){
      mp[j] = min(mp[j], num[j]);
    }
  }
  string ss = "";
  for(int i=0; i<26; i++){
    if(mp[i]>0){
      for(int j=0; j<mp[i]; j++){
        ss += i+'a';
      }
    }
  }
  cout << ss << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,x;
  cin >> a>>b>>c>>x;
  int ans =0;
  for(int i=0;i<=a;i++){
    for(int j =0;j<=b;j++){
      int C = (x - i*500 - j*100)/50;
      if(C<=c&& C>=0){
        ans++;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define sz(c) ((int)(c).size())

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const int MAX=1e5+5;
const ll MOD=1e9+7;

ll adm(ll a, ll b){
	return (a+b)%MOD;
}
ll tim(ll a, ll b){
	return (a*b)%MOD;
}
ll extgcd(ll a,ll b,ll& x, ll& y){
	ll d=a;
	if(b!=0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	}
	else{
		x = 1; y = 0;
	}
	return d;
}
ll mod_inv(ll a){
	ll m=MOD;
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

int main(){
	ll N,A,B,C;
	cin>>N>>A>>B>>C;
	
	ll co[MAX];
	//N+i-1 C N-1
	co[0]=1;
	rep1(i,N-1){
		co[i]=tim(co[i-1],N+i-1);
		co[i]=tim(co[i],mod_inv(i));
	}
	
	ll up=0,dw=1,ans=100;
	ans=tim(ans, mod_inv(100-C));
	rep(i,2*N)dw=tim(dw, A+B);
	
	ll awin[MAX], bwin[MAX];
  	ll q=mod_inv(A+B);
  
  	awin[0]=1;
	rep(i,N)awin[0]=tim(awin[0], A);
	rep(i,N)awin[0]=tim(awin[0], A+B);
	rep1(i,N-1){
		awin[i]=tim(awin[i-1],B);
		awin[i]=tim(awin[i],q);
	}
	rep(i,N){
		awin[i]=tim(awin[i],co[i]);
		awin[i]=tim(awin[i],N+i);
	}
  
	bwin[0]=1;
	rep(i,N)bwin[0]=tim(bwin[0], B);
	rep(i,N)bwin[0]=tim(bwin[0], A+B);
	rep1(i,N-1){
		bwin[i]=tim(bwin[i-1],A);
		bwin[i]=tim(bwin[i],q);
	}
	rep(i,N){
		bwin[i]=tim(bwin[i],co[i]);
		bwin[i]=tim(bwin[i],N+i);
	}
	
	rep(i,N){
		up=adm(up, awin[i]);
		up=adm(up, bwin[i]);
	}
	ans=tim(ans, up);
	ans=tim(ans, mod_inv(dw));
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cassert>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<utility>
using namespace std;

int n;
vector<vector<int> > edges;
bool input(){
  edges.clear();
  int m;
  cin>>n>>m;
  if(n==0&&m==0)return false;
  edges.resize(n);
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  return true;
}

int solve(){
  vector<int> ans;
  for(int i=0;i<edges[0].size();i++){
    ans.push_back(edges[0][i]);
  }
  int size= ans.size();
  for(int i=0;i<size;i++){
    for(int j=0;j<edges[ans[i]].size();j++){
      if(edges[ans[i]][j]!=0)ans.push_back(edges[ans[i]][j]);
    }
  }
  sort(ans.begin(),ans.end());
  ans.erase(unique(ans.begin(),ans.end()) , ans.end());
  return ans.size();
}

int main(){
  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1384
<?php
$result = "Good";
$input = str_split(trim(fgets(STDIN)));
for ($i = 0; $i < count($input) - 1; $i++) {
  if ($input[$i] == $input[$i + 1]) {
    $result = "Bad";
    break;
  }
}
echo $result,PHP_EOL;;

Measured memory_bytes: 4728
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


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

    vector<int> y(n);

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

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


    for(int i = 0; i < n; i++){
        y[i] = abs(x - y[i]);
    }

    int ans = gcd(y[0], y[1]);

    for(int i = 1; i < n - 1; i++){
        ans = gcd(ans, y[i + 1]);
    }

    cout << ans << endl;
    
}



Measured memory_bytes: 640
using System;
using System.Linq;

static class C
{
    private const long Cap = Int64.MaxValue / 4;

    static void Main()
    {
        int n = Int32.Parse(Console.ReadLine());
        long[] a = Console.ReadLine().Split().Select(Int64.Parse).ToArray();

        long[] x = new long[n + 1];
        x[0] = 1;
        for (int i = 0; i <= n - 1; i++)
        {
            x[i + 1] = (x[i] - a[i]) * 2;
            x[i + 1] = Math.Min(x[i + 1], Cap);
        }

        long[] y = new long[n + 1];
        y[n] = a[n];
        for (int i = n - 1; i >= 0; i--)
        {
            y[i] = y[i + 1] + a[i];
        }

        long ans = 0;
        for (int i = 0; i <= n; i++)
        {
            if (x[i] < a[i])
            {
                ans = -1;
                break;
            }
            ans += Math.Min(x[i], y[i]);
        }

        Console.WriteLine((ans == 0) ? -1 : ans);
    }
}


Measured memory_bytes: 30512
def f a, r, n, m
	cl = a.map{|l| l.first}.group_by{|x|x}.map{|k, v| [k, v.size]}
	res = cl.max_by{|k, v| v}[1]
#	p a
#	p res
	return res if r==1
	return res if res == (n + r - 1) / r
	
	rl = cl.select{|k, v| v==res}.map{|k, v| k}
#	p rl
	[rl.sample].each{|rt|
		a2 = a.map{|l| l.reject{|x| x==rt}}
		mmm = f(a2, r-1, n, m)
		res = mmm if mmm<res
	}
	return res
end

n, m = gets.split.map(&:to_i)
a = n.times.map{gets.split.map(&:to_i)}

r = f(a, m, n, m)
puts r

Measured memory_bytes: 143612
def make_divisors(n,m):
    divisors = []
    for i in range(1,n+1):
        if n % i == 0 and m % i == 0:
            divisors.append(i)
    divisors.sort()
    return divisors
n,m,k = map(int,input().split())
if n <= m:
    c = make_divisors(n,m)
else:
    c = make_divisors(m,n)
c.reverse()
print(c[k-1])

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{int sum=0,n,l[100000],i,j,temp;
scanf("%d",&n);
for(i=0;i<2*n;i++)
{scanf("%d",&l[i]);
}
for(i=0;i<2*n-1;i++)
{for(j=0;j<2*n-1-i;j++)
  {if(l[j+1]<l[j]){temp=l[j];l[j]=l[j+1];l[j+1]=temp;
  }
  }
}
for(j=0;j<2*n;j=j+2)
{if(l[j]<=l[j+1]){sum+=l[j];
}
else{sum+=l[j+1];
}
}
printf("%d",sum);
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  int a,b;
  cin >> a >> b;
  int s=a-2*b;
  if(s>0){
    cout << s << endl;

}else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
def main():
    """
    問題が 3問出題され、
    1問目の配点は A点以下、
    2問目の配点は A+1点以上 B点以下、
    3問目の配点は  B+1点以上である。
    """
    S = input()
    ans = f(S)
    if ans:
        print("YES")
    else:
        print("NO")


def f(S):
    n = len(S)
    ok = False
    target = "keyence"
    for i in range(n):
        for j in range(i, n):
            # print(S[:i], S[i:j], S[j:])
            if S[:i] == target:
                return True
            elif S[:i] + S[j:] == target:
                return True
            elif S[j:] == target:
                return True

    return False


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

//-------------------------------------------------
//--Binary Indexed Tree (Sum only)
//-------------------------------------------------
template<typename T>
class BIT
{
private:
    const int n;
    ::std::vector<T> data;
public:
    BIT(int n):n(n),data(n+1){
        for(int i=1; i<=n; i++) data[i] = 0;
    }
    BIT(const ::std::vector<T> &v):n(v.size()),data(n+1){
        for(int i=1; i<=n; i++) data[i] = v[i-1];
        for(int i=1; i<n; i++){
            int j = i+(i&-i);
            if(j<=n) data[j] += data[i];
        }
    }
    void add(int k, T x){k++;
        for(int i=k; i<=n; i+=i&-i) data[i] += x;
    }
    T query(int k){
        T ret=0;
        for(int i=k; i>0; i-=i&-i) ret += data[i];
        return ret;
    }
    T query(int a, int b){return query(b)-query(a);}
    void update(int k, T x){
        T upd = x-query(k, k+1);
        add(k, upd);
    }
    T operator[](int k){return query(k, k+1);}
};

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

int main(void)
{
    int N,Q; cin>>N>>Q;
    vll a(N);
    rep(i,N) cin>>a[i];
    BIT<ll> bit(a);
    while(Q--){
        int t,x,y; cin>>t>>x>>y;
        if (t==0){
            bit.add(x,y);
        }else{
            cout<<bit.query(x,y)<<"\n";
        }
    }
    return 0;
}


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

ll power (ll n, ll k) {
	if (k == 0) return 1;
	ll t = power (n, k / 2);
	if (k % 2 == 0) return t * t;
	return (t * t * n);
}

vl v[11][11];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll k;
	cin >> k;
	vl p;
	for (ll i = 0; i <= 9; i++) {
		v[1][i].pb(i);
		if (i != 0) p.pb(i);
	}
	for (ll i = 2; i <= 10; i++) {
		if (sz(p) == 100000) break;
		for (ll j = 0; j <= 9; j++) {
			if (sz(p) == 100000) break;
			for (ll k : v[i - 1][j - 1]) {
				if (sz(p) == 100000) break;
				v[i][j].pb(k + power(10, i - 1) * j);
				if (j != 0) p.pb(k + power(10, i - 1) * j);
			}
			for (ll k : v[i - 1][j]) {
				if (sz(p) == 100000) break;
				v[i][j].pb(k + power(10, i - 1) * j);
				if (j != 0) p.pb(k + power(10, i - 1) * j);
			}
			if (j != 9) {
				for (ll k : v[i - 1][j + 1]) {
					if (sz(p) == 100000) break;
					v[i][j].pb(k + power(10, i - 1) * j);
					if (j != 0) p.pb(k + power(10, i - 1) * j);
				}
			}
		}
	}
	cout << p[k - 1] << "\n";
 	return 0;
}

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

int main()
{
   int n; cin >> n;
   int a[n+1], b[n+1];
   for(int i =0; i < n; i++)
   {
      cin >> a[i]  >> b[i];
   }
   sort(a, a+n);
   sort(b, b+n);
   int x, y;
   if(n&1)
   {
      x = a[n/2];
      y = b[n/2];
   }
   else
   {
      x = (a[n/2 - 1] + a[n/2]);
      y = (b[n/2 - 1] + b[n/2]);
   }
   cout << y - x + 1;

}


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

int main(){
	int N, i;
	cin >> N;
	int A[N+1];
	for(i=2; i<=N; i++){
		cin >> A[i];
	}
	
	int count[N+1]={0};
	for(i=2; i<=N; i++){
		count[A[i]]++;
	}
	for(i=1; i<=N; i++){
		cout << count[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5156
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[3000],b[3000],c[3001][3001];
int main(void)
{
	int n,s,t,i,j,m;
	scanf("%d %d %d",&m,&s,&t);
	for(i=0;i<m;i++){
		scanf("%d %d",&a[i],&b[i]);
	}
	for(i=0;i<=m;i++){
		for(j=0;j<=s;j++){
			c[i][j]=0;
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<=s;j++){
			if(j+b[i]<=s&&c[i+1][j+b[i]]<a[i]+c[i][j]&&(j+b[i]<=t||j>=t)){
				c[i+1][j+b[i]]=a[i]+c[i][j];
			}
			if(c[i+1][j]<c[i][j]){
				c[i+1][j]=c[i][j];
			}
		}
	}
/*	for(i=0;i<=m;i++){
		for(j=0;j<=s;j++){
			printf("%d ",c[i][j]);
		}
		printf("\n");
	}
*/	n=0;
	for(i=0;i<=s;i++){
		if(n<c[m][i]){
			n=c[m][i];
		}
	}
	printf("%d\n",n);
	return 0;
}

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

const int S=1<<20;
char buf[S],*H,*T;
inline char Get()
{
	if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
	if(H==T) return -1;return *H++;
}
inline int read()
{
	int x=0;char c=Get();
	while(!isdigit(c)) c=Get();
	while(isdigit(c)) x=x*10+c-'0',c=Get();
	return x;
}

const int N=100010;
struct Edge{int to,next;} e[N<<1];
int h[N],sum=0,n;
int deg[N],g[N];

void add_edge(int u,int v)
{
	e[++sum].to=v;
	e[sum].next=h[u];
	h[u]=sum;
}

int dfs(int u,int fa)
{
	int falun=0;
	for(int tmp=h[u];tmp;tmp=e[tmp].next)
	{
		int v=e[tmp].to;
		if(v==fa) continue;
		falun+=dfs(v,u);
	}
	if(falun>=2) puts("First"),exit(0);
	return falun^1;
}

int main()
{
	int u,v;
	n=read();
	for(int i=1;i<n;i++)
	{
		u=read();v=read();
		add_edge(u,v);
		add_edge(v,u);
	}
	puts(dfs(1,0)?"First":"Second");
	return 0;
}

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

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

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b,c,d,area1,area2;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    area1=a*b;
    area2=c*d;
    if(area1>=area2) printf("%d",area1);
    else printf("%d",area2);
    return 0;
}

Measured memory_bytes: 128
// AOJ 2089 Mysterious Dungeons
// 2018.3.24 bal4u

#include <stdio.h>
#include <string.h>
#include <ctype.h>

#define QMAX  230500
typedef struct { char r, c; short s; int t; } Q;
Q q[QMAX+2]; int top, end;
short mk[31][31][1<<13];
char map[33][33];
char c2i[128]; int sz;
int  mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int main()
{
	int W, H, i, r, c, nr, nc, t, s, ns, a, ans;
	int sr, sc, gr, gc;
	char buf[10], *p;
	
	while (fgets(p=buf, 10, stdin) && *p != '0') {
		sscanf(p, "%d%d", &W, &H);
		sz = 0; memset(c2i, 0, sizeof(c2i));
		for (r = 0; r < H; r++) {
			fgets(p=map[r], 33, stdin);
			for (c = 0; c < W; c++) {
				if      (*p == '@') sr = r, sc = c, *p = '.';
				else if (*p == '<') gr = r, gc = c, *p = '.';
				else if (islower(*p)) {
					if (!c2i[*p]) c2i[*p] = (sz<<2)|1, c2i[toupper(*p)] = ((sz++)<<2)|3;
					*p = c2i[*p]>>1;
				} else if (isupper(*p)) {
					if (!c2i[*p]) c2i[*p] = (sz<<2)|3, c2i[tolower(*p)] = ((sz++)<<2)|1;
					*p = c2i[*p]>>1;
				}
				p++;
			}
		}
		memset(mk, 0x55, sizeof(mk));
		q[0].r = sr, q[0].c = sc, q[0].t = 0, q[0].s = 0, mk[sr][sc][0] = 0;
		top = 0, end = 1, ans = -1;
		while (top != end) {
			r = q[top].r, c = q[top].c, t = q[top].t, s = q[top++].s;

			if (r == gr && c == gc) { ans = t; break; }
			if (mk[r][c][s] < t) continue;

			for (i = 0; i < 4; i++) {
				nr = r + mv[i][0], nc = c + mv[i][1], ns = s;
				if (map[nr][nc] == '#') continue;
				if ((a = map[nr][nc]) < 32) {
					if (a & 1) { if (!(s & (1<<(a>>1)))) continue; }
					else ns = s ^ (1<<(a>>1));
				}
				if (mk[nr][nc][ns] > t+1) {
					mk[nr][nc][ns] = t+1;
					q[end].r = nr, q[end].c = nc, q[end].t = t+1, q[end++].s = ns;
				}
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 18676
import scala.io.StdIn._

object Main extends App {

  val A = Array.fill(3)(readLine().split(" ").map(_.toInt))
  val n = readInt()
  val B = Array.fill(n)(readInt())



  def solve(): String = {
    val r = Array.fill(3, 3)(false)
    for {
      i <- 0 until 3
      j <- 0 until 3
      k <- 0 until n
    } {
      if(A(i)(j) == B(k)) r(i)(j) = true
    }

    var ans = "No"
    for(i <- 0 until 3)
      if(r(0)(i) && r(1)(i) && r(2)(i)) ans = "Yes"
    for(i <- 0 until 3)
      if(r(i)(0) && r(i)(1) && r(i)(2)) ans = "Yes"
    if(r(0)(0) && r(1)(1) && r(2)(2)) ans = "Yes"
    if(r(0)(2) && r(1)(1) && r(2)(0)) ans = "Yes"
    ans
  }

  println(solve())

}



Measured memory_bytes: 54860
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {

	char ch;

	while(1) {

		scanf("%c", &ch);

		if(ch == '\n') {
			cout << endl; 
			break;
		}

		ch = toupper(ch);

		cout << ch;
	}

	return 0;
}

Measured memory_bytes: 1148
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;

#define llset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define en '\n'
#define S second
#define F first
#define pll pair<ll,ll>
#define PB push_back

const ll N = 1e6+7;
ll mod = 1e9+7;
#define calncr for(int i=1  ;i<=1e6;i++) fac[i] = (fac[i-1]*i)%mod;
ll fac[N] = {0};

ll gen_base(const ll before, const ll after) {
    auto seed = std::chrono::high_resolution_clock::now().time_since_epoch().count();
    std::mt19937 mt_rand(seed);
    int base = std::uniform_int_distribution<ll>(before+1, after)(mt_rand);
    return base % 2 == 0 ? base-1 : base;
}

ll pow(ll a,ll b)
{
    if(!b)
        return 1;
    ll p = pow(a,b/2);
    if(b%2)
        return (a*((p*p)%mod))%mod;
    else
        return (p*p)%mod;
}

ll modInv(ll a)
{
    //cout<<a<<" "<<mod<<en;
    return pow(a%mod,mod-2);
}

ll nCr(ll n,ll r)
{
    return (fac[n]*modInv((fac[r]*fac[n-r])%mod))%mod;
}

ll hashf(ll r,ll x,ll mod)
{
    return (x+r)%mod;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    fac[0] = 1;
    calncr;
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll cnt[n]={0};
    for(ll i=0;i<n;i++){
        if(s[i]=='R')
            cnt[i]++;
        if(i)
            cnt[i]+=cnt[i-1];
    }
    ll ans = min(cnt[n-1],n-cnt[n-1]);
    ans = min(ans, cnt[n-1]-cnt[cnt[n-1]-1]);
    cout<<ans<<en;
}


Measured memory_bytes: 13152
#include<stdio.h>
int N,A[105],i,j;
long long dp[105][30];

int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
		scanf("%d",A+i);
	dp[0][A[0]]=1;
	for(i=1;i<N-1;i++)
		for(j=0;j<=20;j++)
		{
			if(j-A[i]>=0)
				dp[i][j-A[i]]+=dp[i-1][j];
			if(j+A[i]<=20)
				dp[i][j+A[i]]+=dp[i-1][j];
		}
	printf("%lld\n",dp[N-2][A[N-1]]);
	return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;

void solve() {
	cin >> N >> K;
	cout << N - K + 1 << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

int main() {
    int a,b;
    cin >> a >> b;
    if (a == b) cout << "Draw" << endl;
    else if (a==1) cout << "Alice" << endl;
    else if (b==1) cout << "Bob" << endl;
    else if (a>b) cout << "Alice" << endl;
    else cout << "Bob" << endl;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

int main(){
  int N,K;
  cin>>N>>K;
  if(K==1){
    cout<<0<<endl;
    return 0;
  }
  N-=K;
  cout<<N<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#define rep(i,n) for(int i=0;i<n;++i)
#define pi pair<int,int>

const long INF = 10101010;

using namespace std;

int h, w, add, ans, B[101][101], di[4][2] = { { 0,1 },{ 1,0 },{ -1,0 },{ 0,-1 } };
char A[101][101];
queue <pi> q; pi st, go;

int main() {
	cin >> h >> w;
	rep(i, h) rep(j, w) {
		cin >> A[i][j];
		if (A[i][j] == '#') add++;
		B[i][j] = INF;
	}
	B[0][0] = 0;
	add = h * w - add - 1;

	st.first = 0; st.second = 0;

	q.push(st);
	while (!q.empty()) {
		pi x = q.front();
		q.pop();
		rep(i, 4) {
			int X = x.first + di[i][0], Y = x.second + di[i][1];
			if (X >= 0 && Y >= 0 && X < h && Y < w) {
				if (A[X][Y] != '#' && B[X][Y] == INF) {
					q.push(pair<int, int>(X, Y));
					B[X][Y] = B[x.first][x.second] + 1;
				}
			}
		}
	}

	if (B[h - 1][w - 1] == INF) cout << -1 << endl;
	else cout << add - B[h - 1][w - 1] << endl;

	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> ls(n);

  rep(i, n) {
    cin >> ls[i];
  }
  sort(ls.begin(), ls.end()); 

  int sum = 0;
  rep(i, n-1) {
    sum += ls[i];
  }

  if (ls[n-1] < sum) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
	int a , b;
	scanf("%d", &a );
	b = sqrt(a);
	if(b*b==a)
		printf("%d",a);
		else
			printf("%d",b*b);
			return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    // H,W,h,wを取得
    int H = sc.nextInt(); //列数
    int W = sc.nextInt(); //行数
    int h = sc.nextInt(); //黒塗り列数
    int w = sc.nextInt(); //黒塗り行数
    // 出力
    System.out.println(H*W-(h*W+H*w)+h*w);
  }
/*
  public static int countSum(int num){
    int sum=0;
    // 各桁の和
    while(num>0){
      sum += num%10;
      num=num/10;
    }
    return sum;
  }
  */
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    vector<int> a(n);
    REP(i,n) cin>>a[i];
    VSORT(a);
    ll ans=1;
    if(n%2==0){
        for(int i=0;i<n;i+=2){
            if(a[i]==a[i+1]){
                ans*=2;
                ans%=MOD;
            }
            else{
                cout<<0<<endl;
                return 0;
            }
        }
    }
    else{
        if(a[0]!=0){
            cout<<0<<endl;
            return 0;
        }
        for(int i=1;i<n;i+=2){
            if(a[i]==a[i+1]){
                ans*=2;
                ans %= MOD;
            }
            else{
                cout<<0<<endl;
                return 0;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>

struct Node {int p,l,r;};

struct Node T[100005];
int n;

void pre(int u){
  if(u==-1) return;
  printf(" %d",u);
  pre(T[u].l);
  pre(T[u].r);

}

void in(int u){
  if(u==-1) return;
  in(T[u].l);
  printf(" %d",u);
  in(T[u].r);

}

void post(int u){
  if(u==-1) return;
  post(T[u].l);
  post(T[u].r);
  printf(" %d",u);

}

int main(){
  int i,j,a,l,r,root;
  scanf("%d",&n);
  for(i=0;i<n;i++) T[i].p=-1;

  for(i=0;i<n;i++){
    scanf("%d%d%d",&a,&l,&r);
    T[a].l=l;
    T[a].r=r;
    if(l!=-1)T[l].p=a;
    if(r!=-1)T[r].p=a;
    
  }
  for(i=0;i<n;i++){
    if(T[i].p==-1) root=i;
  }

  printf("Preorder\n");
  pre(root);
  printf("\n");
  printf("Inorder\n");
  in(root);
  printf("\n");
  printf("Postorder\n");
  post(root);
  printf("\n");

  return 0;
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
// #include <bits/stdtr1c++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;


/*#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/

/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;

#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#define MAX                 300005
#define MOD                 1000000009
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 1<<29       // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f

pll v[MAX];
ll ara[MAX];
int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ll N,Q,x;
    sll(N,Q);
    FOR(i,0,N)sl(ara[i]);
    FOR(i,0,Q){
        ll b,c;
        sll(b,c);
        v[i] = MP(c,b);
    }
    sort(ara,ara+N);
    sort(v,v+Q);
    ll ans=0;
    ll tmp1=N-1,tmp2=Q-1;
    FOR(i,1,N+1){
        if(ara[tmp1] > v[tmp2].ff){
            ans += ara[tmp1];
            tmp1--;
        }
        else{
            ans+= v[tmp2].ff;
            v[tmp2].ss--;
            if(v[tmp2].ss<=0)tmp2--;
        }
    }
    pf("%lld\n",ans);
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif

    return 0;
}

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

using namespace std;

const int N = 1234567;

vector <int> g[N];

int dfs(int v) {
  vector <int> a;
  for (int j = 0; j < (int) g[v].size(); j++) {
    int u = g[v][j];
    a.push_back(dfs(u));
  }
  sort(a.begin(), a.end());
  int z = 0;
  for (int i = 0; i < (int) a.size(); i++) {
    z = max(z, a[i]) + 1;
  }
  return z;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    g[p].push_back(i);
  }
  printf("%d\n", dfs(0));
  return 0;
}


Measured memory_bytes: 41728
import java.util.*;
import java.util.Map.Entry;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.rmi.server.UnicastRemoteObject;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int a=sc.nextInt();
        int b=sc.nextInt();
        int c = a*b;
        c=max(a-b,c);
        c=max(a+b,c);
      
        out.println(c);
        out.flush();
    }



    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
}

class P {
	int x, y;
	P(int  x, int y) {
	  this.x=x;
	  this.y=y;
	}
}


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int a,b;
//    P(int a, int b) {
//    	this.b=b;
//    	this.a=a;
//    }
//
//    public int compareTo(P p){
//        return b-p.b;
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 20948
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];

    auto ok = new bool[](N);
    auto p = new int[](N);
    auto ans = 0;
    auto pena = 0;

    foreach (_; 0..M) {
        auto t = readln.split;
        auto a = t[0].to!int - 1;
        auto b = t[1];
        if (ok[a]) continue;
        if (b == "WA") {
            p[a] += 1;
        } else {
            ans += 1;
            pena += p[a];
            ok[a] = true;
        }
    }

    writeln(ans, " ", pena);
}

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

vector<int> greedy(int k, int c, string &s) {
    vector<int> res(k);
    int cur = 0;
    for (int i = 0; i < k; ++i) {
        while (s[cur] == 'x') ++cur;
        res[i] = cur;
        cur += c + 1;
    }
    return res;
}

int main() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    vector<int> left = greedy(k, c, s);
    reverse(s.begin(), s.end());
    vector<int> right = greedy(k, c, s);
    for (int i = 0; i < k; ++i) {
        right[i] = n - right[i] - 1;
    }
    reverse(right.begin(), right.end());
    for (int i = 0; i < k; ++i) {
        if (left[i] == right[i]) cout << left[i] + 1 << endl;
    }
}


Measured memory_bytes: 3332
#include<iostream>
#include<stdlib.h>
#include<stack>
#include<stdio.h>
using namespace std;

int main()
{
	char s[100];
	stack<int> st;
	
	while(~scanf("%s", s))
	{
		if(s[0] == '+')
		{
			int a = st.top(); 
			st.pop();
			int b = st.top();
			st.pop();
			st.push(a + b); 
		}
		else if(s[0] == '-')
		{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(b - a);
		}
		else if(s[0] == '*')
		{
			int a = st.top();
			st.pop();
			int b = st.top();
			st.pop();
			st.push(a * b);
		}
		else
		{
			st.push(atoi(s));
		}
	}
	cout<<st.top()<<endl;
	return 0;
}


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x) cout<<#x<<" = "<<(x)<<endl;
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  int d; cin >> d;
  cout << "Christmas";
  REP(i,abs(d-25)) cout << " Eve";
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
const long long MAXN = 2e3+5;
const long long MOD = 1e9+7;
long long arr[MAXN];
long long arr2[MAXN];
long long dp[MAXN][MAXN];
int main(){
    long long n,m;
    cin>>n>>m;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    for(long long i=1;i<=m;i++){
        cin>>arr2[i];
    }
    for(long long i=1;i<=n;i++){
        for(long long j=1;j<=m;j++){
            dp[i][j] = dp[i-1][j]+dp[i][j-1];
            dp[i][j]%=MOD;
            dp[i][j]-=dp[i-1][j-1];
            dp[i][j]+=MOD;
            dp[i][j]%=MOD;
            if(arr[i] == arr2[j]){
                dp[i][j] += dp[i-1][j-1]+1;
                dp[i][j]%=MOD;
            }
        }
    }
    dp[n][m]++;
    dp[n][m]%=MOD;
    cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n; cin>>n;
	ll mat[10][10];
	for(int i=0;i<10;i++)
	{
		for(int j=0;j<10;j++) 
			mat[i][j]=0;
	}
	ll ANS=0;
	string str;
	for(ll i=1;i<=n;i++)
	{
		ll a,b;
		str=to_string(i);
		a = int(str[0])-'0';
		b = int(str[str.length()-1])-'0';
		//cout << a << " " << b << "\n";
		mat[a][b]+=1;
	}
	// for(int i=0;i<10;i++)
	// {
	// 	for(int j=0;j<10;j++) 
	// 		//cout << mat[i][j] << " " << i << " " << j <<"\n";
	// }
	for(ll i=1;i<=n;i++){
		ll a,b;
		str = to_string(i);
		a = int(str[0])-'0';
		b = int(str[str.length()-1])-'0';
		ANS+=mat[b][a];
	}
	cout << ANS << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)

{
 int a,b,c;
 int count=0;
 int i;

 scanf("%d %d %d",&a,&b,&c);
 for(i=a;i<=b;i++){
 if(c%i==0) count++;
 }
 printf("%d\n",count);
 
 return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	
	int n, x = 0, a;
	
	cin>>n;
	
	a = n;
	
	for(;n>0;){
		x += n%10;
		n = n/10;
	}
	
	
	
	if( a%x == 0 ){
		cout<<"Yes"<<endl;
	}
	else{cout<<"No"<<endl;}
	
	return 0;
}

Measured memory_bytes: 256