akhauriyash/Code-Regression huggingface dataset:
#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> d(N);
  rep(i, N) cin >> d[i];

  int ans = 0;
  rep(i, N) rep(j, N) {
    if (i != j)
      ans += d[i] * d[j];
  }

  ans /= 2;

  cout << ans << endl;
}

Measured memory_bytes: 256
n, x = map(int, input().split())

if x == 1 or x == 2 * n - 1:
    print("No")
else:
    print("Yes")
    if n == 2:
        print(1, 2, 3, sep="\n")
        exit()
    if x == 2:
        li = [x + 1, x, x - 1, x + 2]
    else:
        li = [x - 1, x, x + 1, x - 2]

    others = [e for e in range(1, 2 * n) if e not in li]
    ans = others[:n-2] + li + others[n-2:]

    print(*ans, sep="\n")


Measured memory_bytes: 17688
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
#include <string>
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;

int main(){
    int n; cin >> n;
    int yes=0;
    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            if(i*j==n) yes++;
        }
        
    }
    if(yes) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
    string s;
    vector<string> div = {"maerd", "remaerd", "esare", "resare"};

    cin>> s;
    reverse(s.begin(), s.end());
   
    int i=0;
    while(1){
        bool flag = false;
        for(int j=0; j<4; j++){
            
            if(i+div[j].size()-1>s.size()-1){
                continue;
            }
            if(s.substr(i, div[j].size()) == div[j]){
                flag=true;
                i += div[j].size();
                break;
            }
        }

        if(!flag){
            cout<< "NO" << endl;
            return 0;
        }
        if(i>=s.size()){
            break;
        }
    }

    cout<< "YES" <<endl;
    return 0;
}

Measured memory_bytes: 3728
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = scan.next();
        StringBuilder current = new StringBuilder(s);
        for (int i = 0; i < 5 && current.length() > 0; i++) {
            current = remove(current, "eraser");
            current = remove(current, "erase");
            current = remove(current, "dreamer");
            current = remove(current, "dream");
        }
        System.out.println(current.length() == 0 ? "YES" : "NO");
    }
    private StringBuilder remove(StringBuilder sb, String search) {
        StringBuilder result = new StringBuilder();
        char[] d = search.toCharArray();
        int length = search.length();
        for (int i = 0; i < sb.length(); i++) {
            boolean ng = false;
            for (int j = 0; j < length; j++) {
                if (sb.length() <= i + j) {
                    ng = true;
                    break;
                }
                if (sb.charAt(i+j) != d[j]) {
                    ng = true;
                    break;
                }
            }
            if (!ng) {
                i = i + length - 1;
                continue;
            }
            result.append(sb.charAt(i));
        }
        return result;
    }
}


Measured memory_bytes: 27816
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int H,W;
	while(true){
		scanf("%d %d",&H,&W);
		if(H == 0 && W == 0) break;
		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i+j)%2 == 0) printf("#");
				else{
					printf(".");
				}
			}
			printf("\n");
		}
		printf("\n");
	}
}


Measured memory_bytes: 2604
import java.util.Scanner;

public class Main {

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

        double distanceSum = 0.0;
        int count = 0;
        for (int i = 0; i < n - 1; i++) {
            for (int j = i + 1; j < n; j++) {
                distanceSum += Math.sqrt(Math.pow((x[i] - x[j]), 2.0) + Math.pow(y[i] - y[j], 2.0));
                count++;
            }
        }
        double averageDistance = distanceSum / count;
        double ans = averageDistance * (n - 1);
        System.out.println(ans);
    }

}


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

int main(){
  int N,M,C,A,ans=0;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i=0; i<M; i++){
    cin >> B.at(i);
  }
  for(int i=0; i<N; i++){
    int sum=C;
    for(int j=0; j<M; j++){
      cin >> A;
      sum+=A*B.at(j);
    }
    if(sum>0){
      ans++;
    }
  }
  cout << ans << endl;
}

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 h, n, a = 0;
    cin >> h >> n;
    rep (i, n)
    {
        int x;
        cin >> x;
        a += x;
    }

    if (a >= h)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define DB double
#define INF 1145141919810364364
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define rep(i,n) FOR(i,0,n)
#define MOD 1000000007
//#define MOD 998244353
#define ERR 0.00000001
#define NUM 200010

void swap(LL* a,LL* b){LL tmp=*a;*a=*b;*b=tmp;}
void YN(int a){if(a==1)printf("Yes\n");if(a==0)printf("No\n");}
LL lpow(LL a,LL n){LL ans=pow(a,n)*10;if(ans%10<5)return ans/10;return ans/10+1;}
LL dup(LL a,LL d){if(a%d==0)return a/d;else return a/d+1;}
LL GCD(LL a,LL b){LL c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
LL LCM(LL a,LL b){return a*b/GCD(a,b);}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int lcmpr(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return -1;if(*(LL*)a<*(LL*)b)return 1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int ccmpr(const void* a,const void* b){return *(char*)b-*(char*)a;}
int scmp(const void* a,const void* b){return strcmp((char*)a,(char*)b);}
int scmpr(const void* a,const void* b){return strcmp((char*)b,(char*)a);}
LL mod(LL a,LL m){if(a<0)return a%m+m;else return a%m;}
LL DIV(LL a,LL d){LL m=MOD,x=1,y=0,k;while(m){k=d/m;d-=k*m;swap(&m,&d);x-=k*y;swap(&x,&y);}return mod(a*mod(x,MOD),MOD);}
LL FAC(LL a){LL i,ans=1;FOR(i,1,a+1){ans*=i;if(MOD>0&&ans>MOD)ans%=MOD;}return ans;}
LL POW(LL a,LL n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return ans;}
LL fact[NUM],finv[NUM],inv[NUM];
void comi(){LL i;fact[0]=fact[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fact[i]=fact[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
LL com(LL n,LL k){if(n<k||n<0||k<0)return 0;return fact[n]*(finv[k]*finv[n-k]%MOD)%MOD;}

int main(){
  LL a,b,c,i,ans=0;
  scanf("%lld%lld%lld",&a,&b,&c);
  if(4*a*b<c*c+a*a+b*b-2*a*c-2*b*c+2*a*b&&c-a-b>0)YN(1);
  else YN(0);

  //printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main()
{
  int n;

  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  
  int score = 0;
  for (int i = 1; i <= 100; i++) {
    int count = 0;
    for (int j = 0; j < n; j++) {
      if (p[j] >= i) {
        count++;
      }
     if (count > score) score = i;
    }
  }

  cout << score << endl;
}



Measured memory_bytes: 3092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;


public class Main{
	
	static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    }
	static int a[];
	static long dp[][];  //stores max possible from current position
	
	
	//dp(i,j) = Math.max(a[i]+Math.min(dp(i+2,j),dp(i+1,j-1)),a[j]+Math.min(dp(i+1,j-1),dp(i,j-2)))
	public static void main(String[] args) 
	{
		OutputStream outputStream = System.out;
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(outputStream);
        int n = sc.nextInt();
        dp = new long[n][n];
        a = new int[n];
        long sum = 0;
        for(int i = 0; i < n; i++)
        {	
        	a[i] = sc.nextInt();
        	sum += a[i];
        }
        long x = 0, y = 0, z = 0;
        for(int gap = 0; gap < n; gap++)
        {
        	for(int i = 0, j = gap; j < n; i++, j++)
        	{
        		x = i+2<= j?dp[i+2][j]:0;
        		y = i+1<=j-1?dp[i+1][j-1]:0;
        		z = i<=j-2?dp[i][j-2]:0;
        		dp[i][j] = Math.max((long)a[i]+Math.min(y,x),(long)a[j]+Math.min(y,z));
        	}
        }
        x = dp[0][n-1];
        y = sum-x;
        out.println(x-y);
        out.close();
	}

}


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

long long f[25000005];

int main(){
	int n; cin>>n;
	int a[3],b[3];
	for (int i=0;i<3;i++)
		cin>>a[i];
	for (int i=0;i<3;i++)
		cin>>b[i];
	for (int i=0;i<3;i++)
		if (a[i]<b[i]){
			for (int j=a[i];j<=n;j++)
				f[j]=max(f[j],f[j-a[i]]+b[i]);
		}
	long long s=0;
	for (int i=0;i<=n;i++)
		s=max(s,f[i]-i);
	n+=s;
	memset(f,0,sizeof(f));
	for (int i=0;i<3;i++)
		if (a[i]>b[i]){
			for (int j=b[i];j<=n;j++)
				f[j]=max(f[j],f[j-b[i]]+a[i]);
		}
	s=0;
	for (int i=0;i<=n;i++)
		s=max(s,f[i]-i);
	printf("%lld\n",s+n);
	return 0;
}


Measured memory_bytes: 195584
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n,m = nm()
print(n*(n-1)//2 + m*(m-1)//2)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <functional>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#define SIZE 205

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int dp[2][SIZE][SIZE];
int A[SIZE][SIZE];

int main()
{
	int h,w;
	scanf("%d %d",&h,&w);
	for(int i=0;i<h;i++)
	{
		for(int j=0;j<w;j++)
		{
			scanf("%d",&A[i][j]);
		}
	}
	int pos=0;
	memset(dp,-1,sizeof(dp));
	dp[pos][0][0]=A[0][0];
	for(int i=1;i<=h+w-2;i++)
	{
		pos^=1;
		memset(dp[pos],-1,sizeof(dp[pos]));
		for(int j=0;j<w;j++)
		{
			for(int k=0;k<w;k++)
			{
				if(dp[pos^1][j][k]==-1) continue;
				for(int x=j;x<=j+1;x++)
				{
					for(int y=k;y<=k+1;y++)
					{
						int s=i-x,t=i-y;
						if(s<0||s>=h||t<0||t>=h||x>=w||y>=w) continue;
						dp[pos][x][y]=max(dp[pos][x][y],dp[pos^1][j][k]+A[s][x]+(s==t?0:A[t][y]));
					}
				}
			}
		}
	}
	printf("%d\n",dp[pos][w-1][w-1]);
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>

int main(void){
	char str[21], tmp[21];
	int i, len;
	
	scanf("%s", tmp);
	
	len = strlen(tmp);
	
	for (i = 0; i < len; i++){
		str[i] = tmp[len-i-1];
		printf("%c", str[i]);
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 524
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

MOD = 10**9 + 7

N,K = map(int,input().split())
A = np.array(input().split(), dtype=np.int64)

# 同じグループ内
def type_1():
    bl1 = A[:,None] > A[None,:]
    bl2 = np.arange(N,dtype=np.int64)[:,None] < np.arange(N,dtype=np.int64)[None,:]
    x = ((bl1 & bl2)*1).astype(np.int64).sum() % MOD
    return x*K%MOD

def type_2():
    # グループ間
    counter = np.bincount(A)
    cum = counter.cumsum()
    larger = N-cum
    x = (larger * counter % MOD).sum() % MOD
    y = K*(K-1)//2 % MOD
    return x*y%MOD

answer = (type_1() + type_2()) % MOD
print(answer)

Measured memory_bytes: 82664
#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;
  int a[3*N];
  rep(i, 3*N){
    cin >> a[i];
  }
  sort(a, a + 3*N, greater<int>());
  
  long long sum = 0;
  rep(i, N){
    sum += a[2*i + 1];
  }
  cout << sum << endl;
}


Measured memory_bytes: 1408
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
int ma(int a,int b){
if(a>b)
    return a;
else return b;
}
int main()
{
   int n;
   cin>>n;
   int a[n][3];
   for(int i=0;i<n;i++){
    cin>>a[i][0]>>a[i][1]>>a[i][2];
   }
   int b[n][3];
   b[0][0]=a[0][0];b[0][1]=a[0][1];b[0][2]=a[0][2];

   for(int i=1;i<n;i++){
    for(int j=0;j<3;j++){
        b[i][j]=a[i][j]+ma(b[i-1][(j+1)%3],b[i-1][(j+2)%3]);
    }

   }
   cout<<max(max(b[n-1][0],b[n-1][1]),b[n-1][2]);
}


Measured memory_bytes: 2560
m = int(input())
for _ in range(m):
    ss = set()
    s = input()
    length = len(s)
    for i in range(1, length):
        left = s[:i]
        right = s[i:]
        ss |= {left + right, left + right[::-1], left[::-1] + right, left[::-1] + right[::-1],
                right + left, right + left[::-1], right[::-1] + left, right[::-1] + left[::-1]}
    print(len(ss))



Measured memory_bytes: 5620
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int[] dish = new int[5];
		int min = 10;

		for(int i = 0; i < 5; i++) {
			dish[i] = sc.nextInt();
			int temp = dish[i] % 10;//1の位を取ってくる

			if(0 < temp && temp < min) {//0より大きく、minより小さければ
				min = temp;
			}
		}

		int totalTime = 0;
		for(int i = 0; i < dish.length; i++) {
			if(dish[i] % 10 != 0) {//1の位が0以外のものはすべて切り上げを行う //このままだと、最後に運ばれるdishの時間が余計に加算される
				totalTime += (dish[i]/10 + 1) * 10;
			}else {//1の位が0の場合はそのまま足し算
				totalTime += dish[i];
			}
		}

		min = 10 - min;//1の位が最も小さい値から10を引けば、加算分を引くことが出来る
		System.out.println(totalTime-min);
	}

}


Measured memory_bytes: 35800
N = input()

x = len(N)
if int(N[x-1]) == 3:
    print("bon")
elif int(N[x-1]) == 0 or int(N[x-1]) == 1 or int(N[x-1]) == 6 or int(N[x-1]) == 8:
    print("pon")
else:
    print("hon")

Measured memory_bytes: 9184
N,M = map(int,input().split())

A_list = list(map(int,input().split()))
A_list.sort()

change_list = []
for i in range(M):
    B,C = map(int,input().split())
    change_list.append([C,B])
change_list.sort(reverse=True)
cnt = 0
ans = 0
for i in range(M):
    for card in A_list[cnt:cnt+change_list[i][1]]:
        if card < change_list[i][0]:
            ans += change_list[i][0]
        else:
            ans += card
    cnt += change_list[i][1]
ans += sum(A_list[cnt:])
print(ans)

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nl = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nl[0];
        var l = nl[1];

        var apples = E.Range(1, n).Select(x => l + x - 1).ToArray();
        var pie = apples.Sum() - apples.OrderBy(x => Math.Abs(x)).First();
        Console.WriteLine(pie);
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<'\n';}
//*************useless stuff*************//
#define TC 0
#define mod 10000007
#define N 1000009
bool arr[N];
void solve(int T) {
    int n;
    cin>>n;

    ll sum = 0;


    rep(i,1,n){
        if(i<5 and i!=3){
            sum+=i;
        }else if(i==3){
            continue;
        }else if(i%3==0 or i%5==0) continue;
        else sum+=i;

    }

    cout<<sum<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}


Measured memory_bytes: 3604
N,*as=$<.read.split.map(&:to_i)
rlim = 10**5
arr = Array.new(rlim+1,0)
as.each do |a|
    arr[a] += 1
end

l = 0
r = 10**5
count = 0
loop do
    l += 1 while l <= rlim && arr[l] < 2
    break if rlim < l
    r -= 1 while 0 <= r && arr[r] < 2
    if l == r
        count += arr[l] / 2 * 2
        break
    end
    n = [arr[l],arr[r]].min - 1
    arr[l] -= n
    arr[r] -= n
    count += 2*n
end

puts N-count

Measured memory_bytes: 21888
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

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

    int count = 0;
    char tmp = s[0];
    for(int i = 0; i < s.size() - 1; i++){
        if(tmp != s[i + 1]){
            count++;
            tmp = s[i + 1];
        }
    }

    cout << count + 1 << endl;
}

Measured memory_bytes: 512
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

string s;
vector<vector<string>> dp;

bool comp(const string &a,const string &b){
    if(a=="-1"){return true;}
    if(b=="-1"){return false;}
    if(a=="-2"){return true;}
    if(b=="-2"){return false;}
    if(a.size()!=b.size()){return a.size()<b.size();}
    return a<b;
}

//[l,r)
string & dfs(ll l,ll r){
    if(dp[l][r]!="-1"){return dp[l][r];}
    if(l>=r){return dp[l][r]="-2";}
    if(r-l==1 && s[l]=='0'){return dp[l][r]="0";}
    if(s[l]=='0'){return dp[l][r]="-2";}
    string ret;
    bool j=true;
    for(ll i=l;i<r && j;i++){
        if('0'<=s[i] && s[i]<='9'){
            ret.push_back(s[i]);
        }
        else if(s[i]=='?'){ret.push_back('9');}
        else{j=false;}
    }
    if(j){return dp[l][r]=ret;}
    if(r-l<6){return dp[l][r]="-2";}
    if(s[l+1]!='(' && s[l+1]!='?'){return dp[l][r]="-2";}
    if(s[r-1]!=')' && s[r-1]!='?'){return dp[l][r]="-2";}
    if(s[l]=='L'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(i+1,r-1)=="-2"){continue;}
            if(comp(dp[l][r],dfs(l+2,i))){dp[l][r]=dp[l+2][i];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    else if(s[l]=='R'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(l+2,i)=="-2"){continue;}
            if(comp(dp[l][r],dfs(i+1,r-1))){dp[l][r]=dp[i+1][r-1];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    else if(s[l]=='?'){
        for(ll i=l+3;i<r-2;i++){
            if(s[i]!=',' && s[i]!='?'){continue;}
            if(dfs(l+2,i)=="-2" || dfs(i+1,r-1)=="-2"){continue;}
            if(comp(dp[l][r],dp[i+1][r-1])){dp[l][r]=dp[i+1][r-1];}
            if(comp(dp[l][r],dp[l+2][i])){dp[l][r]=dp[l+2][i];}
        }
        if(dp[l][r]=="-1"){dp[l][r]="-2";}
        return dp[l][r];
    }
    return dp[l][r]="-2";
}


int main(){
    cin>>s;
    dp.resize(s.size(),vector<string>(s.size()+1,"-1"));
    dfs(0,s.size());
    if(dp[0][s.size()]=="-2"){cout<<"invalid"<<endl;}
    else{cout<<dp[0][s.size()]<<endl;}
    
    
    return 0;
}



Measured memory_bytes: 3260
using System;

namespace ITP1_5_D
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            for(int i = 1; i <= n; i++)
            {
                if (i % 3 == 0)
                    Console.Write(" {0}", i);
                else
                    Include3(i);
            }
            Console.WriteLine();
        }

        static void Include3(int i)
        {
            var x = i;
            while (x > 0)
            {
                if (x % 10 == 3)
                {
                    Console.Write(" {0}", i);
                    return;
                }
                x /= 10;
            }
        }
    }
}

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

//int a[26]={0};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	long n=s.length(),i,c=0;
	for(i=0;i<n;i++)
	{
	    if(s[i]!=t[i])
	    c++;
	}
	/*for(i=0;i<26;i++)
	{
	    if(a[i]!=0)
	    c++;
	}*/
	cout<<c<<endl;
	return 0;
}

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

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

    int n, k, s;
    cin >> n >> k >> s;

    vector<int> A(n);
    for(int i = 0; i < n; i++){
        if(i < k) A[i] = s;
        else{
            if(s == 1e9){
                A[i] = 1;
            }else{
                A[i] = s + 1;
            }
        }
    }

    for(auto x: A){
        cout << x << ' ';
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n,m;
    cin >> n>> m;
    vvll gura(n);
    vector<ll>high(n);
    for(int i=0;i<n;i++){
        cin >> high.at(i);
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin >>a >>b;
        a--;b--;
        gura.at(a).push_back(b);
        gura.at(b).push_back(a);
    }
    ll ans = 0;
    for(int i=0;i<n;i++){
        int from = high.at(i);
        bool che = true;
        for(int j=0;j<gura.at(i).size();j++){
            int next = gura.at(i).at(j);
            if(from<=high.at(next))che=false;
        }
        if(che)ans++;
    }
    cout <<ans << endl;
}
    



Measured memory_bytes: 9860
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int h,w,d;cin >> h >> w >> d;
  vector<pair<int,int>> a(h*w+1,make_pair(0,0));
  rep(i,h*w){
    int tmp;
    cin >> tmp;
    a[tmp] = make_pair(i/w+1,i%w+1);
  }
  vector<int> b(h*w+1);
  for(int i = d+1;i <= h*w;i++){
    b[i] = b[i-d]+abs(a[i].first-a[i-d].first)+abs(a[i].second-a[i-d].second);
  }
  int q; cin >> q;
  rep(i,q){
    int l,r; cin >> l >> r;
    cout << b[r]-b[l] << endl;
  }
  
  //rep(i,h*w+1){
  //  printf("i=%d (%d,%d)\n",i,a[i].first,a[i].second);
  //}
  return 0;
}

Measured memory_bytes: 2176
hon = [2, 4, 5, 7, 9]
pon = [0, 1, 6, 8]
bon = [3]
n = input()
if int(n[-1]) in hon:
    print('hon')
elif int(n[-1]) in pon:
    print('pon')
elif int(n[-1]) in bon:
    print('bon')

Measured memory_bytes: 9156
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using Graph = vector<vector<int>>;

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

vector<bool> seen;

void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

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

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

bool permutation(vector<int>& vec, vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        //cout << vec.at(i);
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

/*bool nibu(vector<int>& retu,int key) {

}*/

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    string S;
    cin >> S;
    vector<char> retu(26);
    for (int i = 0; i < S.size(); i++) {
        retu.at(S.at(i) - 97)++;
    }
    for (int i = 0; i < 26; i++) {
        if (retu.at(i) == 0) {
            char c = i + 97;
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main()
{
  int a[100],i;
  for(i=0;i<5;i++)
  {
    cin>>a[i];
  }
  for(i=0;i<5;i++)
  {
    if(a[i]==0)
    {
      cout<<i+1<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;
using namespace __gnu_pbds;

tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderset;

const int N=2e5+5;
int n,a[N];

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int d;
    cin>>d;
    int t=d%10;
    if(t==3) cout<<"bon";
    else if(t==0||t==1||t==6||t==8) cout<<"pon";
    else cout<<"hon";
}


Measured memory_bytes: 3660
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <cmath>
#include <climits>

#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue

using namespace std;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
ll dp[100001], dp_c[100001];
ll max_dp[100001], max_dp_c[100001];

int main(int argc, char const* argv[])
{
  int n;
  ll C;
  cin >> n >> C;
  vector<ll> x, v;
  for(int i = 0; i < n; i++){
    ll a, b;
    cin >> a >> b;
    x.pb(a);
    v.pb(b);
  }
  fill(dp, dp + n + 1, -linf);
  fill(dp_c, dp_c + n + 1, -linf);
  ll res = 0;
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    dp[i + 1] = dp[i] + v[i];
    if(i != 0)dp[i + 1] -= x[i] - x[i - 1];
    else dp[i + 1] -= x[i];
    res = max(res, dp[i + 1]);
  }
  dp_c[n] = 0;
  for(int i = n - 1; i >= 0; i--){
    dp_c[i] = dp_c[i + 1] + v[i];
    if(i != n - 1)dp_c[i] -= x[i + 1] - x[i];
    else dp_c[i] -= C - x[i];
    res = max(res, dp_c[i]);
  }

  max_dp[0] = dp[0];
  for(int i = 0; i < n; i++){
    max_dp[i + 1] = max(max_dp[i], dp[i + 1]);
  }
  max_dp_c[n] = dp_c[n];
  for(int i = n - 1; i >= 0; i--){
    max_dp_c[i] = max(max_dp_c[i + 1], dp_c[i]);
  }

  for(int i = 0; i < n; i++){
    res = max(res, dp[i + 1] - x[i] + max_dp_c[i + 1]);
    res = max(res, dp_c[i] - (C - x[i]) + max_dp[i]);
  }

  cout << res << endl;
	return 0;
}


Measured memory_bytes: 5100
n = gets.to_i
p = n.times.map{gets.to_i-1}
c = Array.new(n,0)
n.times do |i|
    if p[i] == 0
        c[0] = 1
    else
        c[p[i]] = c[p[i]-1]+1
    end
end
puts n-c.max

Measured memory_bytes: 5428
N,M = (int(i) for i in input().split())
dic = {}
drink = M
money = 0
for i in range(N):
  a,b = (int(i) for i in input().split())
  if a not in dic:
    dic[a] = b
  else:
    dic[a] += b
c = sorted(dic.keys())
for j in c:
  if drink > dic[j]:
    money += j * dic[j]
    drink -= dic[j]
  else:
    money += j * drink
    break
print(money)

Measured memory_bytes: 17892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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 _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int h,w;
    cin>>h>>w;
    int g[10][10];
    rep(i,10) rep(j,10) cin>>g[i][j];
    rep(k,10){
        rep(i,10){
            rep(j,10){
                if(g[i][j]>g[i][k]+g[k][j]){
                    g[i][j]=g[i][k]+g[k][j];
                }
            }
        }
    }
    int ans=0;
    rep(i,h*w){
        int tmp;
        cin>>tmp;
        if(tmp==-1)continue;
        ans+=g[tmp][1];
    }
    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-1)-a.at(0) << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc094/tasks/abc094_b
n, m, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
masu = [0] * (n + 1)
for r in a:
    masu[r] = 1
print(min(sum(masu[0:x + 1]), sum(masu[-n - 1 + x:])))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
using namespace std;


int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;

    if(s.size() % 2 != 0){
        cout << "No" << endl;
    }else{
        rep(i,n/2){
            if(s[i] == s[i+n/2]){
                continue;
            }else{
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;

    }


}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>

using namespace std;
typedef long long ll;

char a[100000+5];

int main()
{
	int x,y;
	scanf("%d %d",&x,&y);
	scanf("%s",a);
	int len=strlen(a);
	bool f=1;
	for(int i=0;i<len;i++){
		if(i!=(x)&&!(a[i]>='0'&&a[i]<='9')){
			f=0;
			break;
		}
		else if(i==(x)&&(a[i]!='-')){
			f=0;
			break;
		}
	}
	if(f){
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}	 


Measured memory_bytes: 256
R=range
def F(a,b):A=len(a);r=[all([len(set([a[i+j],b[j],'?']))<3for j in R(min(A-i,len(b)))])for i in R(A)];return r+[1]
def Z(X):
 i,j,k=X;U,V,W=M[i][j],M[j][k],M[i][k];A,B,C=map(len,[S[i]for i in X]);q=1e5
 for l in R(A+1):
  if U[l]:
   for r in R(l,A+B+1):
    if(B<r-l or V[r-l])*W[min(A,r)]:q=min(q,max(A,l+B,r+C))
 return q
T=R(3)
S=[input()for i in T]
M=[[F(S[i],S[j])for j in T]for i in T]
from itertools import *;print(min([Z(i)for i in permutations(T)]))

Measured memory_bytes: 56028
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
#define INF (1 << 29)
using namespace std;

int main(){
    int n, M = 1000000007;
    int m[100005][2], temp[100005], te[100005];
    int maxi = 0;
    cin >> n;
    rep(i,n){
        int inp;
        cin >> inp;
        te[i] = inp;
        if(inp > maxi){
            maxi = inp;
            m[i][0] = 0;
        }else{
            m[i][0] = maxi;
        }
    }

    rep(i,n) cin >> temp[i];
    maxi = 0;
    for(int i = n - 1; i >= 0; i--){
        if(temp[i] > maxi){
            maxi = temp[i];
            m[i][1] = 0;
        }else{
            m[i][1] = maxi;
        }
    }

    bool c= false;
    rep(i,n){
        if(m[i][0] == 0 && te[i] > temp[i]){
            c = true;
            break;
        }
    }
    rep(i,n){
        if(m[i][1] == 0 && temp[i] > te[i]){
            c = true;
            break;
        }
    }

    if(c){
        cout << 0 << endl;
    }else{
        long long ans = 1;
        rep(i,n){
            if(min(m[i][0], m[i][1]) == 0) continue;
            ans*=min(m[i][0], m[i][1]) % M;
            ans%=M;
        }
        cout << ans << endl;
    }
}


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

int main(){

    int n,a;
    cin >> n >> a;

    if(n%500<=a){
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) (x).begin(), (x).end()
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cerr << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  string s, t;
  cin >> s >> t;
  const int   slen = s.size(), tlen = t.size();
  vector<int> sv(slen), tv(tlen);
  rep (i, slen) sv[i] = s[i] - 'a';
  rep (i, tlen) tv[i] = t[i] - 'a';
  vector<bool> alp(26);
  allrep (c, tv) alp[c] = true;
  allrep (c, sv) alp[c] = false;
  if (find(all(alp), true) != alp.end()) {
    cout << -1 << endl;
    return 0;
  }
  vector<vector<int>> alp_pos(26);
  rep (i, slen) alp_pos[sv[i]].push_back(i);
  int cnt = 0, now = -1;
  rep (i, tlen) {
    auto itr = upper_bound(all(alp_pos[tv[i]]), now);
    if (itr != alp_pos[tv[i]].end()) {
      now = *itr;
    } else {
      now = alp_pos[tv[i]].front();
      ++cnt;
    }
  }
  cout << (lint)slen * cnt + now + 1 << endl;
  return 0;
}

Measured memory_bytes: 1996
#include<iostream>
#include<map>
#include<set>
using namespace std;
typedef struct node{
    int id;
    node *left, *right;
    node(int id):id(id),left(NULL),right(NULL){}
} Node;
class Solution{
private:
       map<int,Node*> hashMapping;
       set<int> rootCandidates, nonRootNodes;

       Node* createNode(int ID){
              if(ID!=-1){
               if(hashMapping.find(ID) == hashMapping.end()){
                    hashMapping[ID] = new Node(ID);
              } 
              return hashMapping[ID];
           }else{
              return NULL; 
           }
       }
       void preorder(Node* root){
         if(root==NULL){
             return;
         }else{
             cout<<" "<<root->id;
             preorder(root->left);
             preorder(root->right);
         }
       }
       void inorder(Node* root){
          if(root==NULL){
             return;
          }else{
             inorder(root->left);
             cout<<" "<<root->id;
             inorder(root->right);
          }
       }
       void postorder(Node* root){
          if(root==NULL){
             return;
          }else{
             postorder(root->left);
             postorder(root->right);
             cout<<" "<<root->id;
         }
       }
public:
     node* buildTree(){
           hashMapping.clear();
           rootCandidates.clear();
           nonRootNodes.clear();
           int num,rootID=-1;
           cin>>num;
           while(num--){
                 int ID,leftID,rightID;
                 cin>>ID>>leftID>>rightID;
                 if(nonRootNodes.find(ID) == nonRootNodes.end()){
                    rootCandidates.insert(ID);
                 }
                 nonRootNodes.insert(leftID);
                 rootCandidates.erase(leftID);
                 nonRootNodes.insert(rightID);
                 rootCandidates.erase(rightID);
                 createNode(ID)->left = createNode(leftID); 
                 createNode(ID)->right = createNode(rightID); 
           }
           return hashMapping[*rootCandidates.begin()];
     }
void printPreOrder(node *root){
         cout<<"Preorder"<<endl;
         preorder(root);
         cout<<endl;
     }
void printInOrder(node *root){
         cout<<"Inorder"<<endl;
         inorder(root);
         cout<<endl;
     }
void printPostOrder(node *root){
         cout<<"Postorder"<<endl;
         postorder(root);
         cout<<endl;
    }
} sln;
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
    node *root = sln.buildTree(); 
    sln.printPreOrder(root);
    sln.printInOrder(root);
    sln.printPostOrder(root);
    return 0;
}

Measured memory_bytes: 1212
//Algorithms and Data Structures I - Graph II - Single Source Shortest Path II
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

class MyList extends ArrayList<Node> {
	public Node getNode(int u) {
		Node ret = null;
		for(Node n:this){
			if(u==n.u){
				ret = n;
			}
		}
		return ret;
	}
}

class Node implements Comparable<Node> {
	public  int     u,
		            k,
			        d = Integer.MAX_VALUE;
	public  int[][] adj;
	boolean S;

	Node(int u, int k) {
		this.u = u;
		this.k = k;
		adj    = new int[2][k];
	}

	public int compareTo(Node n) {
		return this.d - n.d;
	}
}

class Main {

	private static ArrayList<Node>       Q   = new ArrayList<Node>();
	private static HashMap<Integer,Node> map = new HashMap<Integer,Node>();

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node source = null,
			 nd;
		for(int i=0;i<n;i++){
			nd = new Node(sc.nextInt(), sc.nextInt());
			for (int j = 0; j < nd.k; j++) {
				nd.adj[0][j] = sc.nextInt();
				nd.adj[1][j] = sc.nextInt();
			}
			if (nd.u == 0) { nd.d   = 0 ;
			                 source = nd;}
			else           {Q.add(nd)   ;}
			map.put(nd.u, nd);
		}
		relax(source);

		while(!Q.isEmpty()){
			Collections.sort(Q);
			relax(Q.remove(0));
		}

		for(int i=0;i<n;i++){
			nd = map.get(i);
			System.out.println(nd.u+" "+nd.d);
		}
	}

	private static void relax(Node n){
		Node t;
		int  l;
		for(int i=0;i<n.k;i++){
			t = map.get(n.adj[0][i]);
			l = n.d+n.adj[1][i];
			if(!t.S && l<t.d){
				t.d=l;
			}
		}
		n.S = true;
	}
}

Measured memory_bytes: 249128
import sys
import itertools
import collections
sys.setrecursionlimit(10**7)
def lmi(): return list(map(int, input().split()))

n = int(input())
x = [0] * n
y = [0] * n
for i in range(n):
    x[i], y[i] = lmi()

d = []
for i in range(n):
    for j in range(n):
        d.append((x[i]-x[j], y[i]-y[j]))

c = collections.Counter(d)
if n != 1:
    c1 = c.most_common()[1]
    print(n - c1[1])
else:
    print(1)


Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp37 {
    class Program {
        static void Main(string[] args) {
            string S = Console.ReadLine();

            char[] c = new char[3];

            c[0] = S[0];
            c[1] = S[1];
            c[2] = S[2];

            Console.WriteLine(c.Where(x => x == '1').Count());
                

        }
    }
}


Measured memory_bytes: 11220
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define MP make_pair
typedef long long ll;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;

/*** chmax, chmin ***/

// a < b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmax(T &a, const T &b) {
	if (a < b) {
		a = b; 
		return true;
	}
	return false;
}
// a > b ならば a を b で更新
// 更新されたら true を返す
template <typename T>
bool chmin(T &a, const T &b) {
	if (a > b) {
		a = b; 
		return true;
	}
	return false;
}

/*** chmax, chmin ここまで ***/

/*** MOD CALCULATION ***/

const int MOD = 1e9+7;
const int MAX = 510000;

ll addM(ll a, ll b){
	return (a + b) % MOD;
}

ll mulM(ll a, ll b){
	ll temp = (a * b) % MOD;
  	while(temp<0){ temp += MOD; }
  	return temp;
}

ll powM(ll a, ll b){
	if(b == 0) return 1;
  	else if(b == 1) return a%MOD;
  	else if(b%2==0) return mulM(powM(a,b/2),powM(a,b/2));
  	else return mulM(a,mulM(powM(a,(b-1)/2),powM(a,(b-1)/2)));
}

// b^{-1} = b^{p-2} (mod p)
// a/b = a*b^{p-2} (mod p)
ll divM(ll a, ll b){ 
  	return mulM(a,powM(b,MOD-2));
}

// n!, (n!)^{-1} のテーブル作成
ll fac[MAX], finv[MAX], inv[MAX];
void COMBinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    rep3(i,2,MAX-1){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COMB(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

/*** MOD CALCULATION ここまで ***/

void Main()
{
   	int N, K;
  	cin >> N >> K;
  	vector<int> A(N);
  	rep(i,N) cin >> A[i];
  	sort(A.begin(), A.end());
	COMBinit();
	ll ans = 0;
  	rep(i,N-K+1){
		ans = addM(ans, mulM(COMB(N-(i+1),K-1), A[N-i-1] - A[i]));  
    }
  	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}


Measured memory_bytes: 12672
#include<bits/stdc++.h>
using namespace std;
double n,k,ans=0,z[30];
int main(){
	cin>>n>>k;
	z[1]=1;
	for (int i=2;i<=20;i++) z[i]=z[i-1]*2;
	for (double i=1;i<=n;i++){
		double x=1;
		for (int j=1;j<=20;j++)
			if (z[j]*i>=k){
				x=x/z[j]/n;
				break;
			}
		ans+=x;
	}
	printf("%.12f",ans);
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,a,b;cin>>n>>a>>b;
  cout<<(n-a+1)*(n-b+1)<<endl;
}

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

int main() {
  long H,W,M;
  cin>>H>>W>>M;
  vector<long>K(M);
  vector<long>O(M);
  long h=H+1;
  long w=W+1;
  int m=max(h,w);
  vector<long>A(m,0);
  vector<long>B(m,0);
  vector<long>a(m,0);
  vector<long>b(m,0);
  vector<long>D(m,0);
  vector<long>d(m,0);
  for(long i=0;i<M;i++){
    cin>>K[i]>>O[i];
    A[K[i]]++;
    B[O[i]]++;
    a[K[i]]++;
    b[O[i]]++;
    D[K[i]]++;
    d[O[i]]++;
  }
  long C=0;
  long c=0;
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(long i=0;i<m;i++){
    if(a[0]==D[i]){
      c=i;
      break;
    }
  }
  for(long i=0;C<a[0];i++){
    if(K[i]==c){
      b[O[i]]--;
      C++;
    }
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  int ANS=a[0]+b[0];
  long E=0;
  sort(B.begin(),B.end());
  reverse(B.begin(),B.end());
  for(long i=0;i<m;i++){
    if(B[0]==d[i]){
      c=i;
      break;
    }
  }
  for(int i=0;E<B[0];i++){
    if(O[i]==c){
      A[K[i]]--;
      E++;
    }
  }
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int ans=A[0]+B[0];
  
  cout<<max(ANS,ans)<<endl;
}


Measured memory_bytes: 22000