akhauriyash/Code-Regression huggingface dataset:
N,M=gets.chomp.split(" ").map(&:to_i)
KEYS=[]
M.times do
    x,y=gets.chomp.split(" ").map(&:to_i)
    KEYS.push([x,y])
end
groups={}
KEYS.each do |x,y|
    groups[x] ||= []
    groups[x].push(y)
end
ORDERS={}
groups.keys.each do |x|
    groups[x] = groups[x].sort
    groups[x].each_with_index do |y,index|
        key="#{x}_#{y}"
        ORDERS[key]=index+1
    end
end
KEYS.each do |x,y|
    key="#{x}_#{y}"
    puts "#{format('%06d', x)}#{format('%06d', ORDERS[key])}"
end


Measured memory_bytes: 46700
inp = input().split()
n,k = map(int, inp)
nums = list(input().split())
nums_list = list(map(int, nums))
kill_en_hp = 0
if len(nums_list) < k:
    print(0)
else:
    nums_list.sort(reverse=True)
    nums_list_2 = nums_list[k:]
    print(sum(nums_list_2))

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

int gcd(int a, int b, int c){
    int min;
    int ans = 1;
    if(a < b && a < c){
        min = a;
    }else if(b < a && b < c){
        min = b;
    }else{
        min = c;
    }
    for(int i=min; i>0; i--){
        if(a%i == 0 && b%i == 0 && c%i == 0){
            ans = i;
            break;
        }
    }
    return ans;
}

int main(){
    int K;
    cin >> K;
    long long ans = 0;

    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                ans += gcd(i, j, k);
                // cout << gcd(i, j, k) << endl;
            }
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,i;
  cin>>n>>k;
  string s;
  cin>>s;
  int res=1;
  int l=0,r=1;
  int t=(s[0]=='1')?0:1;
  while(r<n)
  {
    if(s[r-1]=='1' && s[r]=='0')
    {
   		t++;
      	if(t>k)
        {
          while(1)
          {
            l++;
            if(s[l-1]=='0' && s[l]=='1') break;
          }
          t--;
        } 
    }
    res=max(res,r-l+1);
    r++;
  }
  cout<<res;
  return 0;	
}


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


int main(void){
  int K,S,ans=0;
  cin >> K >> S;
  for(int X=0;X<=K;X++){
    for(int Y=0;Y<=K;Y++){
      int Z=S-X-Y;
      if(0<=Z && Z<=K) ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}
  

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  sort(begin(a),end(a));

  ll ans = 0;
  for(int i=0;i<n;++i)for(int j=i+1;j<n;++j)for(int k=j+1;k<n;++k){
    if(a[i]==a[j] or a[j]==a[k] or a[k]==a[i])continue;
    if(a[i]+a[j]>a[k]){
      ans++;
    }
  }
  cout<<(ans)<<endl;

}


Measured memory_bytes: 3628
//Volume0-0062
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		//declare
		final int    LEN = 10;
		      int [] ar  = new int[LEN];
		      char[] ch;

		//input
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
        	 ch = sc.nextLine().toCharArray();
        	 for(int i=0;i<LEN;i++){
        		 ar[i] = Character.digit(ch[i], 10);
        	 }

        	 //calculate
        	 for(int i=1;i<LEN;i++){
        		 for(int j=0;j<LEN-i;j++){
        			 ar[j] = (ar[j]+ar[j+1]) % 10;
        		 }
        	 }

        	 //output
        	 System.out.println(ar[0]);
        }
	}
}

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

namespace HABIT{
    #define f(a,b,c,d) for(register int a=b,c=d;a<=c;a++)
    #define g(a,b,c,d) for(register int a=b,c=d;a>=c;a--)
    #define LOCAL
    typedef int i32;
    typedef unsigned int u32;
    typedef long long int i64;
    typedef unsigned long long int u64;
    typedef pair<i32,i32> pii;
    const i32 MAXN=1024;
    typedef i32 ar[MAXN];
    
    template<typename T> inline T Max(T a) { return a; }
    template<typename T,typename... Args> inline T Max(T a,Args... args){
        T b=Max(args...);
        return (a>b)?a:b;
    }
    template<typename T> inline T Min(T a) { return a; }
    template<typename T,typename... Args> inline T Min(T a,Args... args){
        T b=Min(args...);
        return (a<b)?a:b;
    }

    #ifdef LOCAL
        inline char gc() { return getchar(); }
    #else
        inline char gc() {
            static char s[1<<20|1]={0},*p1=s,*p2=s;
            return (p1==p2)&&(p2=(p1=s)+fread(s,1,1<<20,stdin),p1==p2)?EOF:*(p1++);
        }
    #endif
    inline i64 read(){
        register i64 ans=0;register char c=gc();register bool neg=0;
        while(c<48||c>57) neg^=!(c^'-'),c=gc();
        while(c>=48&&c<=57) ans=(ans<<3)+(ans<<1)+(c^48),c=gc();
        return neg?-ans:ans;
    }

    char Output_Ans[1<<20|1],*Output_Cur=Output_Ans;
    inline void output() { Output_Cur-=fwrite(Output_Ans,1,Output_Cur-Output_Ans,stdout); }
    inline void print(char c){
        if(Output_Cur-Output_Ans+1>>20) output();
        *(Output_Cur++)=c;
    }
    inline void print(char *s) { while(*s) print( *(s++) ); }
    inline void print(u64 x){
        if(!x) { print('0'); return ; }
        char buf[30]={0},*p=buf+28;
        while(x) *(p--)=x%10+48,x/=10;
        print(p+1);
    }
    inline void print(u32 x) { print( (u64)x ); }
    inline void print(i64 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
    inline void print(i32 x){
        if(x<0) print('-'),x=-x;
        print( (u64)x );
    }
}
using namespace HABIT;

int main(){
    char s1[16]={0},s2[16]={0};
    scanf("%s\n%s",s1,s2);
    f(i,0,I,strlen(s1)-1) if(s1[i]!=s2[i]){
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    output();
    return 0;
}

Measured memory_bytes: 3772
'''
a = a1 + a2 + a3 ・・・ai
b = b1 + b2 + b3 ・・・bj
a + b <= K なれば良い
そして、本の数の最大数を求めるから、
つまり、i + j の最大の値を求める

１，まず、考えられる解法が全検索である。
しかし、N=M=200000 の場合には間に合わない。

２，次にiについてのみ考える。
i = 0,1・・・N
そして、bj <= K-ai
であるようなjの最大値を求める。

i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''
N, M, K = map(int,input().split())

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

#リストだと、0から始まるため、i + jの最初を０にしている
a, b = [0], [0]
#足していった合計をリストに足している
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])


ans, j = 0, M

'''
aのリストは低い数字からみて、bのリストは高い数字から見る
i=0 のときのjの最大値は、 j = M, M-1 
このように降順に走査すると、最初に bj <= K-ai 左の式が成立したjを求める。
このjをbest0とする

i=1 のときに選択可能なjの最大値を求める。
この最大値はbest0以下であるため、ｊ＝best0から始めることができる
'''
# N + 1 している理由は、0がリストの最初にあるため。
#そして、0から始まる

for i in range(N+1):
    if a[i] > K:
        break
    # print(a[i])
    while b[j] > K -a[i]:
        #降順なので−１している
        j -= 1
        # print(b[j])
    #ansにi+jの最大値を返している
    ans = max(ans, i + j)
print(ans)


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

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

    string S;
    int check = 0;
    for(int i = 0; i < N; i++){
        cin >> S;
        if(S == "Y"){
            check = 1;
            break;
        }
    }

    if(check == 0) cout << "Three" << endl;
    else           cout << "Four"  << endl;
}


Measured memory_bytes: 3592
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    class UnionFind(object):
        def __init__(self, n=1):
            # 木の親要素を管理するリストparをつくります。
            # par[x] == xの場合には、そのノードが根であることを示します。
            # 初期状態では一切グループ化されていないので、すべてのノードが根になりますね。
            self.par = [i for i in range(n)]
            # 木の高さを持っておき、あとで低い方を高い方につなげる。初期状態は0
            self.rank = [0 for _ in range(n)]
            self.size = [1 for _ in range(n)]
    
        def find(self, x):
            """
            x が属するグループを探索：
            ある２つの要素が属する木の根が同じかどうかをチェックすればよい。
            つまり、親の親の親の・・・と根にたどり着くまで走査すればよい。
            再帰。
            """
            # 根ならその番号を返す
            if self.par[x] == x:
                return x
            # 根でないなら、親の要素で再検索
            else:
                # 一度見た値については根に直接繋いで経路圧縮
                # 親を書き換えるということ
                self.par[x] = self.find(self.par[x])
                return self.par[x]
    
        def union(self, x, y):
            """
            x と y のグループを結合
            """
            # 根を探す
            x = self.find(x)
            y = self.find(y)
            # 小さい木に結合して経路圧縮
            if x != y:
                if self.rank[x] < self.rank[y]:
                    x, y = y, x
                # 同じ長さの場合rankが1増える
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1
                # 低い方の木の根を高い方の根とする
                self.par[y] = x
                self.size[x] += self.size[y]
    
        def is_same(self, x, y):
            """
            x と y が同じグループか否か
            """
            return self.find(x) == self.find(y)
    
        def get_size(self, x):
            """
            x が属するグループの要素数
            """
            x = self.find(x)
            return self.size[x]
    
    N,M,K=map(int,input().split())
    uf = UnionFind(N)  # ノード数Nでクラス継承
    friends_cnt=[0]*N
    for i in range(M):
        # A,Bはノード
        A, B = map(int, input().split())
        A-=1
        B-=1
        friends_cnt[A]+=1
        friends_cnt[B]+=1
    
        # 連結クエリ union
        uf.union(A, B)
    
    blocks=[[] * N for i in range(N)]
    for i in range(K):
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        blocks[x].append(y)
        blocks[y].append(x) # 有向ならコメントアウト
    
    for i in range(N):
        ans=uf.get_size(i)-friends_cnt[i]-1
        for j in blocks[i]:
            if uf.is_same(i,j):
                ans-=1
        print(ans,end=' ')
    print()

    
    

    

resolve()

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

const string week[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };

int zeller(int y, int m, int d) {
  if (m < 3) { --y; m += 12; }
  return (y+y/4-y/100+y/400+(13*m+8)/5+d) % 7;
}

int main() {
	int m, n;
	while ( cin >> m >> n, m | n) {
		cout << week[zeller(2004, m, n)] << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
n=int(input())
h=list(map(int,input().split()))
cnt=0
mini=min(h)
for i in range(len(h)):
    h[i]-=mini
cnt+=mini
for i in range(n):
    while h[i]>0:
        cnt+=1
        for j in range(0,n-i):
            if h[i+j]==0:
                break
            else:
                h[i+j]-=1
print(cnt)

Measured memory_bytes: 40432
#include "bits/stdc++.h"
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
  int n;
  cin>>n;
  double ans=0.0;
  while(n--){
    double a;
    string b;
    cin>>a>>b;
    if(b=="JPY"){
      ans+=(double)a;
    }else{
      ans+=a*380000.0;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define M 1046527
int n;
char H[M][12];
int getChar(char);

int main(void){
	int i;
	char arr[12];
	char com[10];
	for(i=0;i<M;i++){
		H[i][0] = '\0';
	}
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s", com, arr);
		if(com[0] == 'i'){
			insert(arr);
		}
		if(com[0] == 'f'){
			if(search(arr)){
				printf("yes\n");
			}
			else printf("no\n");
		}
		
	}

}
int h1(int key){
	return key % M;
}

int h2(int key){
	return 1+(key %(M -1));
}

long long getKey(char str[]){
	long long total=0, p = 1,i;
	for(i=0; i<strlen(str); i++){
		total += p*(getChar(str[i]));
		p *= 5;
	}
	return total;
}
int getChar(char c){
	if(c =='A') return 1;
	else if(c== 'C') return 2;
	else if(c == 'G') return 3;
	else if(c == 'T') return 4;
	else return 0;
}

int insert(char str[]){
	long long i,h;
	long long key;
	key = getKey(str);
	for(i=0; ;i++){
		h = (h1(key)+ i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) {
			strcpy(H[h], str);
			return 0;
		}
	}
	return 0;
}

int search(char str[]){
	long long i,h;
	long long key;
	key = getKey(str);
	for(i=0; ;i++){
		h = (h1(key)+ i * h2(key)) % M;
		if(strcmp(H[h],str) == 0) return 1;
		else if(strlen(H[h]) == 0) return 0;
	}
	return 0;
}


Measured memory_bytes: 14064
n = int(input())
a = list(map(int,input().split()))
b = []
i=0
while n-1-i>=0:
    b.append(str(a[n - 1 - i]))
    i += 2
if n%2==0:
    for i in range(0,n,2):
        b.append(str(a[i]))
else:
    for i in range(1,n,2):
        b.append(str(a[i]))
b=' '.join(b)
print(b)

Measured memory_bytes: 28100
#include <stdio.h>
#include <stdlib.h>
int compR(const void* a,const void* b){long la=*(long*)a,lb=*(long*)b;return (lb>la)-(lb<la);}
int min(int a,int b){return (a<b)?a:b;}
int main(void){
    int X,Y,Z,K;
    scanf("%d%d%d%d",&X,&Y,&Z,&K);
    long A[X],B[Y],C[Z];
    for(int i=0;i<X;i++)scanf("%ld",&A[i]);
    for(int i=0;i<Y;i++)scanf("%ld",&B[i]);
    for(int i=0;i<Z;i++)scanf("%ld",&C[i]);
    qsort(A,X,sizeof(long),compR);
    qsort(B,Y,sizeof(long),compR);
    qsort(C,Z,sizeof(long),compR);
    int i,j,k,size=0;
    long ans[1000000];
    for(i=1;i<=min(K,X);i++)for(j=1;j<=min(K/i,Y);j++)for(k=1;k<=min(K/(i*j),Z);k++)
        ans[size++]=A[i-1]+B[j-1]+C[k-1];
    qsort(ans,size,sizeof(long),compR);
    for(i=0;i<K;i++)printf("%ld\n",ans[i]);
}


Measured memory_bytes: 3580
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
//#include<bits/extc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)
#define index Index
#define Line pll
typedef long long LL;
LL dp[100005][2];
vector<int> v[100005];
int mod=1e9+7;
void dfs(int x,int f){
    LL w=1,b=1;
    for(auto it:v[x]){
        if(it!=f){
            dfs(it,x);
            w*=(dp[it][0]+dp[it][1]);
            b*=dp[it][0];
            w%=mod;
            b%=mod;
        }
    }
    dp[x][0]=w;
    dp[x][1]=b;
  //  printf("%d %d %d\n",x,dp[x][0],dp[x][1]);
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1,0);
    printf("%lld\n",(dp[1][0]+dp[1][1])%mod);
}


Measured memory_bytes: 11392
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, a, b, s = 0;
	cin >> n >> m;
	priority_queue<pair<long long, long long>> pq;
	for (i = 0; i < n; i++) {
		cin >> a >> b;
		pq.push({ -a, b });
	}
	for (i = 0; i < m; i++) {
		a = -pq.top().first;
		b = pq.top().second;
		pq.pop();

		s += a;
		if (b > 1) pq.push({ -a, b - 1 });
	}
	cout << s << "\n";


	return 0;
}

Measured memory_bytes: 2420
# encoding: utf-8

import sys
from collections import deque


class Solution:
    @staticmethod
    def doubly_linked_list():
        # write your code here
        array_length = int(input())
        task_deque = deque()
        _input = sys.stdin.readlines()

        for i in range(array_length):
            l_arg = _input[i].split()
            action = _input[i].split()[0]
            if len(l_arg) > 1:
                value = _input[i].split()[-1]
            # print(action, 'v', value)

            if action == 'insert':
                task_deque.appendleft(value)
            elif action == 'deleteFirst':
                task_deque.popleft()
            elif action == 'deleteLast':
                task_deque.pop()
            elif action == 'delete':
                try:
                    task_deque.remove(value)
                except Exception as e:
                    pass
        print(" ".join(task_deque))


if __name__ == '__main__':
    solution = Solution()
    solution.doubly_linked_list()

Measured memory_bytes: 214216
#include <iostream>
#include <cstring>
#include <math.h>
using namespace std;
int a[100001], dp[100001], n;
int solve(int i){
	if(dp[i] != -1){
		return dp[i];
	}
	if(i == n - 1){
		return 0;
	}
	if(i == n - 2){
		return abs(a[i] - a[i + 1]);
	}
	return dp[i] = min(solve(i + 1) + abs(a[i] - a[i + 1]), solve(i + 2) + abs(a[i] - a[i + 2]));
}
int main() {
	cin >> n;
	for(int i = 0; i < n; ++i){
		dp[i] = -1;
	}
	for(int i = 0; i < n; ++i){
		scanf("%d", &a[i]);
	}
	cout << solve(0);
	return 0;
}

Measured memory_bytes: 2560
X, Y = gets.split.map(&:to_i)

cnt = 0
elem = X

loop {
    if elem <= Y then
        cnt += 1

        i = 2
        nextelem = elem
        loop {
            nextelem *= i
            if nextelem.to_s.split.map(&:to_i).inject(0){|s,n|s+=n} >= elem then
                elem = nextelem
                break
            end
            i += 1
        }

    else
        break
    end
}

puts cnt


Measured memory_bytes: 3836
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int[] array = new int[n];

        for (int i = 0; i < n; i++) {
            array[Integer.parseInt(sc.next()) - 1] = i + 1;
        }

        System.out.println(Arrays.stream(array).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
    }
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    cin >> n;

    ll ret = 0;
    FOR(i, 1, n+1) {
        ll sz = to_string(i).size();
        if(sz%2) ret++;
    }
    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 256
M = 1046527
$h = []

def getChar(ch)
	case ch
	when "A"
		return 1
	when "C"
		return 2
	when "G"
		return 3
	when "T"
		return 4
	else
		return 0;
	end
end

def getKey(str)
	sum = 0
	p = 1
	str.size.times do |i|
		sum += p * getChar(str[i])
		p *= 5
	end
	return sum
end

def h1(key)
	return key % M
end

def h2(key)
	return 1 + (key % (M - 1))
end

def find(str)
	key = getKey(str)
	i = 0
	loop do
		h = (h1(key) + i * h2(key)) % M
		return true if $h[h] == str
		return false if $h[h] == nil
		i += 1
	end
	return false
end

def insert(str)
	key = getKey(str)
	i = 0
	#puts key
	loop do
		h = (h1(key) + i * h2(key)) % M
		if $h[h] == str
			return 1
		elsif $h[h] == nil
			$h[h] = str
			return 0
		end
		i += 1
	end
	return 0
end


M.times do |i|
	$h[i] = nil
end
n = gets.to_i
n.times do |ind|
	#puts ind
	com, str = gets.split
	if com[0] == "i"
		insert(str)
	else
		if find(str)
			puts "yes"
		else
			puts "no"
		end
	end
end

Measured memory_bytes: 39376
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
int main(){
    int n; cin>>n;
    int a[110];
    rep(0,i,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    int alice = 0;
    int bob = 0;
    rep(0,i,n){
        if(i%2==0){
            alice += a[i];
        }else{
            bob += a[i];
        }
    }

    cout << alice-bob << endl;
}

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

int main()
{
  
  
  int n,k;
  cin>>n>>k;
  int dp[n+1];
  dp[1]=0;

  int h[n+1];
  
  for(int i=1;i<=n;i++)
    cin>>h[i];
  
  for(int i=2;i<=n;i++)
  {
    int temp=1e9;
    for(int j=max(1,i-k);j<i;j++)
      temp=min(temp,dp[j]+abs(h[j]-h[i]));
    dp[i]=temp;
  }

  cout<<dp[n];
  return 0;  
}   

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int N,x,i,a[111];
	cin >> N >> x;
	for(i=0; i<N; i++)
		cin >> a[i];
	sort(a, a+N);
	for(i=0; i<N; i++){
		if(x < a[i])
			break;
		x -= a[i];
	}
	if(i == N && x != 0)
		i--;
	cout << i << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define INF 1e9
using ll = int64_t;
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

void Main() {
  //自動整形防止用コメント
  std::string s;
  std::cin >> s;
  std::vector<bool> v(26, false);
  for (auto &x : s) {
    v[x - 'a'] = true;
  }

  for (size_t i = 0; i < 26; i++) {
    if (!v[i]) {
      std::cout << (char)(i + 'a') << '\n';
      return;
    }
  }

  std::cout << "None" << '\n';
  return;
}

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


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


int check_prime_num(int num){
      /* 判定フラグ */
  int flag = 1;
    /* 素数かどうかを判定 */
  for(int i=2;i<num;++i ) {
    if( num%i==0 ) {
      flag = 0;
      break;
    }
  }
  return flag;

}

int main(void){
    int N;
    int array[10000],a=0;
    scanf("%d",&N);
    for(int i = 6; i < 55555; i+=5){
        if(check_prime_num(i)) {
            array[a] = i;
            a++;
            if(N == a) break;
        }
    }
    for(int i = 0; i < a;i++) printf("%d ",array[i]);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

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

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}
int n, m;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n>>m;
	vector<int> l(m), r(m);
	rep(i, 0, m) cin >> l[i] >> r[i];
	sort(l.begin(), l.end(), greater<int>());
	sort(r.begin(), r.end());
	if(r[0]<l[0]){
		cout << 0;
	}else{
		cout << r[0] - l[0] + 1;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define inf 999999999
#define loop(i, a, b) for (int i = (a), i##len = (b); i < i##len; ++i)
#define rep(i, n) loop(i, 0, n)
#define lin long long

lin n;
lin a[200001];

int main(void)
{
    cin >> n;
    rep(i, n)
    {
        cin >> a[i];
    }

    lin res = 0;
    lin pointer = n;
    for(lin i = n - 1; i >=0; i--)
    {
        lin current = i - pointer;
        if(current < 0)
            current = 0;

        if(current == a[i])
            continue;
        else if(current > a[i])
        {
            res = -1;
            break;
        }
        else
        {
            res += a[i];
            pointer = i - a[i];
            if(pointer < 0)
            {
                res = -1;
                break;
            }
        }
    }

    cout << res << endl;

    return 0;
}


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


const int MAX=1100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(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;
}


int main() {
  int x,y;
  cin >> x >> y;
  long long int ans;
  if((x+y)%3!=0) ans=0;
  else{
    int n=(-x+2*y)/3;
    int m=(2*x-y)/3;
    if(n<0 || m<0) ans=0;
    else{
      COMinit();
      ans=COM(n+m, n);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 25984
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int a[101][101],a1[101][101],a2[101][101],i,j,k,ii,mx,n,sum;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		for(j=1;j<=n;j++)	scanf("%d",&a[i][j]);
	}
	for(i=0;i<=n;i++)	{
		for(j=0;j<=n;j++)	{
			a1[i][j]=0;	a2[i][j]=0;
		}
	}
	for(i=1;i<=n;i++)	{
		for(j=1;j<=n;j++)	a1[i][j]=a1[i][j-1]+a[i][j];
	}
	for(j=1;j<=n;j++)	{
		for(i=1;i<=n;i++)	a2[i][j]=a2[i-1][j]+a1[i][j];
	}
//	for(i=0;i<=n;i++)	{
//		for(j=0;j<=n;j++)	printf("%3d ",a2[i][j]);
//		printf("\n");
//	}
	mx=a[1][1];
	for(i=0;i<n;i++)	{
		for(j=0;j<n;j++)	{
			for(k=i+1;k<=n;k++)	{
				for(ii=j+1;ii<=n;ii++)	{
					sum=a2[k][ii]-a2[k][j]-a2[i][ii]+a2[i][j];
					mx=max(sum,mx);
//					printf("i=%d j=%d k=%d ii=%d mx=%d\n",i,j,k,ii,mx);
				}
			}
		}
	}
	printf("%d\n",mx);
	return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpi(x1) fprintf(stderr, "#%s.%d (%s) = (%d)\n", __func__, __LINE__, #x1, x1);
#define dumpii(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%d, %d)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpiii(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%d, %d, %d)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);

struct Solver {
  int x, y;
  int res;
  Solver(int x_, int y_) : x(x_), y(y_) {
    if( x <= y and (y <= 0 or 0 <= x) ) {
      res = std::abs(x - y);
    }
    else if( (x < 0 or 0 < y) and y < x ) {
      res = 2 + std::abs(x - y);
    }
    else {
      res = 1 + std::abs((-x) - y);
    }
  }
  int f() {
    return res;
  }
};

int main() {
  int x, y;
  scanf("%d %d", &x, &y);
  Solver s(x, y);
  printf("%d\n", s.f());
  
  return 0;
}

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

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

int main() {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        int ma = -1;
        bool f = false;
        rep(i, n) { 
                cin >> a[i];
                if (k == a[i]) f = true;
                ma = max(ma, a[i]);
        }
        if (f) {
                cout << "POSSIBLE" << endl;
                return 0;
        }
        if (ma < k) { 
                cout << "IMPOSSIBLE" << endl;
                return 0;
        } else if (ma == k) {
                cout << "POSSIBLE" << endl;
        }
        int ans = a[0];
        for (int i = 1; i < n; i ++) {
                ans = __gcd(ans, a[i]);
        }
        if (ans == 1 || k % ans == 0) {
                cout << "POSSIBLE" << endl;
        } else {
                cout << "IMPOSSIBLE" << endl;
        }
        return 0;
}



Measured memory_bytes: 640
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

i = 0
ans = 0
while i < N:
    tmp = A[i]
    count = 0
    while i < N and A[i] == tmp:
        count += 1
        i += 1
    ans += count % 2

print(ans)


Measured memory_bytes: 13184
use std::cmp::*;
use std::collections::VecDeque;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let k = int();
    let mut q = (1..10)
        .map(|i| ('0' as u8) + i)
        .map(|i| {
            let mut vec = VecDeque::new();
            vec.push_front(i as char);
            vec
        })
        .collect::<VecDeque<VecDeque<char>>>();

    let mut count = 0;
    while q.len() > 0 {
        let mut cur = q.pop_front().unwrap();
        count += 1;
        //println!("{}", cur.iter().collect::<String>());
        if count == k {
            for c in cur {
                print!("{}", c);
            }
            println!("");
            return;
        }
        let last = cur.back().unwrap();
        if last > &'0' {
            let mut minus1 = cur.clone();
            minus1.push_back((*last as u8 - 1) as char);
            q.push_back(minus1);
        }

        let mut simple = cur.clone();
        simple.push_back(last.clone());
        q.push_back(simple);

        if last < &'9' {
            let mut plus1 = cur.clone();
            plus1.push_back((*last as u8 + 1) as char);
            q.push_back(plus1);
        }
    }
}


Measured memory_bytes: 24828
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 2e5 + 4;
int a[N], b[N], n;
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        a[i] = i * n;
    for (int j = 1; j <= n; j++)
        b[j]= (n - j + 1) * n;
    for (int i = 1, x; i <= n; i++) {
        scanf("%d", &x);
        if(i != n) b[x]--;
        a[x] -= (n - i);
        //printf("%d ", a[x] + b[x]);//
    }
    //printf("\n");//
    for (int i = 1; i <= n; i++) {
        printf("%d ", a[i]);
    }
    printf("\n");
    for (int i = 1; i <= n; i++) {
        printf("%d ", b[i]);
    }
    printf("\n");
}

Measured memory_bytes: 640
#include <cstdio>
#include <string>
#include <iostream>
#include <cmath>
#include <vector>
#include <stack>

using namespace std;

int main(void) {
	
	int N, data, cnt=0;
	unsigned int i;

	vector<int> mochi;

	cin >> N;

	mochi.resize(N);

	while (N--) {
		cin >> data;
		for (i = 0; i < mochi.size(); i++) {
			if (data == mochi[i])
				break;
		}
		if (i == mochi.size()) {
			mochi.push_back(data);
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#define NIL -1
#define Max 100005
typedef struct{
  int parent;
  int left;
  int right;
}Node;

Node T[Max];
int depth[Max];
void r(int,int);
void r(int node ,int parent){
  depth[node] = parent;
  if(T[node].right != NIL){
    r(T[node].right,parent);
  }
  if(T[node].left != NIL){
    r(T[node].left,parent + 1);
  }
}
int main(){
  int Num,Index,node,left=0,root,n,i,j;
  scanf("%d",&n);
  for(i = 0;i < n;++i){
    T[i].right=NIL;
    T[i].left=T[i].right;
    T[i].parent=T[i].left;
  }
  for(i = 0;i < n;++i){
    scanf("%d %d",&Index,&Num);
    for(j = 0;j<Num;++j){
      scanf("%d",&node);
      if(j == 0){
	T[Index].left = node;
      }
      else{
	T[left].right = node;
      }
      left = node;
      T[node].parent = Index;
    }
  }
    
  for(i = 0;i < n;++i){
    if(T[i].parent == NIL){
      root = i;
    }
  }
   
  r(root,0);
            
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ", i,T[i].parent, depth[i]);
    
    if(T[i].parent == NIL){
      printf( "root, ");
    }else if(T[i].left == NIL){
      printf("leaf, ");
    }else{
      printf("internal node, ");
    }
    printf("[");
    
    for(j = 0,left = T[i].left;left != NIL;++j,left = T[left].right){
      if(j)printf(", ");
      printf("%d", left);
    }
    printf("]\n");
  }
  return 0;
}



Measured memory_bytes: 6424
if __name__ == '__main__':

	n = int(input())
	A = input().split()

	n2 = int(input())

	for i in range(n2):
		a,b = map(int,input().split())

		B = list(reversed(A[a:b]))
		A = A[0:a]+B+A[b:n]

	print(*A)



Measured memory_bytes: 5824
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		int[] in;
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			in = new int[n];
			for(int i = 0; i < n; i++){
				in[i] = sc.nextInt();
			}
			System.out.println(maxSumSequence(in));
		}
		sc.close();
	}
	
	static long maxSumSequence(int[] args) {
		long maxsum = args[0];
		for(int i = 0; i < args.length; i++) {
			for(int j = i; j < args.length; j++) {
				long sum = sumSequence(args, i, j);
				if(sum > maxsum) {
					maxsum = sum;
				}
			}
		}
		return maxsum;
	}
	
	static long sumSequence(int[] args, int from, int to) {
		long result = 0;
		for(int i = from; i <= to; i++) {
			result += args[i];
		}
		return result;
	}
}

Measured memory_bytes: 26532
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = (n-1); i >= 0; i--)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define reab(i, a, b) for (int i = (a)-1; i >= (b); i--)
#define ALL(a) (a).begin(),(a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
inline ll divceil(ll a, ll b){return (a+b-1) / b;}
const int MOD = 1000000007;
/* END OF TEMPLATE */

// < val の要素数
int CountLower(const vll &vec, ll val){
    return distance(vec.begin(), lower_bound(ALL(vec), val));
}
// <= val の要素数
int CountLowerE(const vll &vec, ll val){
    return distance(vec.begin(), upper_bound(ALL(vec), val));
}
// > val の要素数
int CountUpper(const vll &vec, ll val){
    return distance(upper_bound(ALL(vec), val), vec.end());
}
// >= val の要素数
int CountUpperE(const vll &vec, ll val){
    return distance(lower_bound(ALL(vec), val), vec.end());
}

int main(){
    ll n, m;
    cin >> n >> m;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(ALL(a));
    vp q(m);
    rep(i, m){
        cin >> q[i].second >> q[i].first;
    }
    sort(ALL(q), greater<pair<ll, ll>>());
    vll d(n, 0);
    ll cnt = 0;
    rep(i, m){
        rep(j, q[i].second){
            d[cnt] = q[i].first;
            cnt++;
            if(cnt >= n) goto NS;
        }
    }
    NS:
    ll ans = 0;
    rep(i, n){
        ans += max(a[i], d[i]);
    }
    cout << ans << endl;
}

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

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    H, W = mi()
    a, b = mi()
    print((H-a) * (W-b))


if __name__ == "__main__":
    main()


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

int main() {
  int N,S=0;
  vector<int> vecA(N);
  vector<int> vecB(N);
  vector<int> vecC(N-1);
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> vecA[i];
  }
  for(int i = 0; i < N; i++){
    cin >> vecB[i];
    S += vecB[i];
  }
  for(int i = 0; i < N-1; i++){
    cin >> vecC[i];
  }
  for(int i = 0; i < N-1; i++){
    if(vecA[i+1] - vecA[i] == 1){
      S += vecC[vecA[i]-1];
    }
  }
  cout << S <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

signed main(){
    ll N, H, W;
    cin >> N >> H >> W;
    PRINT((N - H + 1) * (N - W + 1));
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;
const double PI = acos(-1);

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(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;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
  vector<int> p;
  vector<int> s;
  void init(int n) {
    p.resize(n, -1);
    s.resize(n, 1);
  }
  int find(int n) {
    if(p[n] == -1) return n;
    else return find(p[n]);
  }
  int size(int n) {
    return s[find(n)];
  }
  void unite(int n, int m) {
    int pn = find(n);
    int pm = find(m);
    if(pn == pm) return;
    if(s[pn] > s[pm]) {
      s[pn] = s[pn] + s[pm];
      p[pm]= pn;
    } else {
      s[pm] = s[pm] + s[pn];
      p[pn] = pm;
    }
  }
};

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int n = s.size();
  rep(i, s.size()-1) {
    if(s[i] == 'a') continue;
    int a = 26 - (s[i] - 'a');
    if(a > k) continue;
    else {
      s[i] = 'a';
      k -= a;
    }
  }
  k %= 26;
  rep(i, k) {
    if(s[n-1] == 'z') s[n-1] = 'a';
    else s[n-1]++;
  }
  cout << s << endl;
}


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

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
}


int main()
{
    fastIO();

    map <int, int> mp;
    bool flag = true;
    int n, m;
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int s, c;
        cin >> s >> c;
        if(mp.find(s) ==  mp.end()){
            mp[s] = c;
        }
        else if(mp[s] != c){
            flag = false;
        }
    }
    if(!flag){
        cout << -1 << '\n';
        return 0;
    }
    if(n!= 1 && mp.find(1)!= mp.end() && mp[1] == 0){
        cout << -1 << '\n';
        return 0;
    }
    if(n == 1 && mp.find(1) == mp.end())
        mp[1] = 0;
    for(int i=1;i<=n;i++){
        if(i == 1 && mp.find(1) == mp.end()){
            mp[1] = 1;
        }
        cout << mp[i];
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

const ll MXN=100005;
vector<edge> G[MXN];
vector<bool> B(MXN,false);
vl ans(MXN);

void bfs(ll x,ll d){
  B[x]=true;
  ans[x]=d;
  ll k=G[x].size();
  rep(i,k){
    if(B[G[x][i].to]==false){
      bfs(G[x][i].to,G[x][i].cost+d);
    }
  }
}

  
int main() {
  ll N;
  cin >> N;
  rep(i,N-1){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  bfs(K,0);
  rep(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;y--;
    cout << ans[x]+ans[y] << " ";
  }
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll h){
    if(h==1){return 1;}
    else{
        ll ret = 1+ 2*f(h/2);
        return ret;
        }
}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h;
    cin>>h;
    ll ans = f(h);
    cout<<ans;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n = int(input())
s = 0
for i in range(1,n+1):
    if i%3==0 or i%5==0:
        pass
    else:
        s += i
print(s)

Measured memory_bytes: 68440
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdlib.h>

using namespace std;

string S;
string T;

int main(){
    cin >> S;
    cin >> T;

    for(int i = 0;i < S.length();i++){

        if( S.length() + 1 != T.length() ){
            cout << "No" << endl;
            exit(0);
        }

        if(S.substr(i,1) != T.substr(i,1) ){
            cout << "No" << endl;
            exit(0);
        } 
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define repX(i, n ,x) for (int i = x; i < (int)(n); ++i)
#define repBack(i, n) for (int i = n; i >= 0; --i)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,K;
    cin >> N >> K;
    int ans = 0;
    rep(i,N){
        int H;
        cin >> H;
        if(K<=H)ans ++;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256