akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
import heapq
from operator import itemgetter

T=int(input())
for tests in range(T):
    N=int(input())
    C=[tuple(map(int,input().split())) for i in range(N)]

    ANS=0
    LEFT=[]
    RIGHT=[]
    
    for k,l,r in C:
        if l>r:
            ANS+=r
            LEFT.append((k,l-r))
        else:
            ANS+=l
            RIGHT.append((k,r-l))

    LEFT.sort(key=itemgetter(0),reverse=True)
    H=[]
    ind=0

    for i in range(N,0,-1):
        while ind<len(LEFT) and LEFT[ind][0]>=i:
            heapq.heappush(H,-LEFT[ind][1])
            ind+=1

        if H:
            ANS+=-heapq.heappop(H)

    RIGHT.sort(key=itemgetter(0))
    H=[]
    ind=0

    for i in range(N):
        while ind<len(RIGHT) and RIGHT[ind][0]<=i:
            heapq.heappush(H,-RIGHT[ind][1])
            ind+=1

        if H:
            ANS+=-heapq.heappop(H)

    print(ANS)

Measured memory_bytes: 60352
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N];
int num[N],g=0;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	long long res=a[n-1],cnt=0;
	num[g++]=a[n-2];
	int l=0;
	for(int i=n-3;i>=0;i--){
		res+=num[l];
		cnt++;
		if(cnt==2)l++,cnt=0;
		num[g++]=a[i];
	}
	cout<<res;
} 

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=n-1;i > m;i--)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define Vec(K,L,N,S) vector<L> K(N,S);
#define DV(K,L,N,M) vector<vector<L>> K(N, vector<L>(M));
#define mod 1000000007;
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
lli gcd(lli num1, lli num2){
    return num2 != 0 ? gcd(num2, num1 % num2) : num1;
}
lli lcm(lli num1, lli num2){
    return num1 / gcd(num1, num2) * num2;
}
int main(){
  lli A,B,D,E,N,M,K,sum=0,num=0,ans=0;
  cin >> N;
  Vec(C,lli,N,0);Vec(S,lli,N,0);Vec(F,lli,N,0);
  Vec(P,lli,N,0);
  rep(i,0,N-1)cin >> C[i] >> S[i] >> F[i];
  rep(i,0,N-1)P[i]=C[i]+S[i];
  rep(i,0,N-2)rep(j,i+1,N-1){
    if(P[i]%F[j]==0&&P[i]>=S[j])P[i]+=C[j];
    else if(P[i]%F[j]!=0&&P[i]>=S[j])P[i]+=F[j]-P[i]%F[j]+C[j];
    else P[i]=P[j];
  }
  rep(i,0,N)Out(P[i]);
}



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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(20) << fixed;

    int n;
    int a, b;
    cin >> n >> a >> b;
    int c0 = 0, c1 = 0, c2 = 0;
    for (int i = 0; i < n; ++i) {
        int p;
        cin >> p;
        if (p <= a) c0++;
        else if (p <= b) c1++;
        else c2++;
    }
    cout << min({c0, c1, c2}) << endl;
    return 0;
}


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

int main() {
  long n, k;
  cin >> n >> k;
  long ans = 1, sigma = n*(n+1)/2;
  for (long i=k; i<=n; i++) {
    ans += sigma - (n-i)*(n-i+1)/2 - (i-1)*i/2 + 1;
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(){
	int n, m; //文字列の大きさ
	int i,j;
	int k,l;
	int x;
	scanf("%d %d", &n, &m);
	char A[n+1][n+1];
	char B[m+1][m+1];

	for(j = 0; j < n; j++){
		scanf("%s", A[j]);
	}
	
	for(j = 0; j < m; j++){
		scanf("%s", B[j]);
	}

	for(i = 0; i <= n-m; i++){
		for(j = 0; j <= n-m; j++){
			//どっかしらがfitした
			if(A[j][i] == B[0][0]){
				x = 1;
				for(k = 0; k < m; k++){
					for(l = 0; l < m; l++){
						if(A[j+l][i+k] != B[k][l]){
							x = 0;
							break;	//一致しなかったら強制退出
						}
					}
					//途中でおわったやつ　or ぜんぶループしたやつもここ出てくる
					if(x == 0) break;	//途中でbreakしたやつは用なしだからbreak
				}
				if(x == 1){
					printf("Yes\n");
					return 0;
				}
			}
			//全箇所fitしなかったやつがでてくる，B[1][1]を調べるループ開始
		}
	}

	printf("No\n");

	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int ans = 0;
        String tmp = s.substring(0, 1);
        for (int i = 1; i < s.length(); i++) {
            if(!s.substring(i, i + 1).equals(tmp)) {
                ans++;
                tmp = s.substring(i, i + 1);
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 48300
#include<stdio.h>
int main(void)
{
	int a,n,x,y,i,sum;
	sum=0;
	scanf("%d",&n);
	a=n;
	for(i=0;i<9;i++){
		sum=sum+n%10;
		n/=10;
		//printf("sum=%d\n",sum);
	}
	if(a%sum==0){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


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

int main() {
  int n,x,ma;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin>>a.at(i);
  vector<int> b(n);
  for(int i=0;i<n;i++)cin>>b.at(i);
  x=ma=0;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<=i;j++){
      x+=a.at(j);
    }
    for(int k=i;k<n;k++){
      x+=b.at(k);
    }
    ma=max(ma,x);
    x=0;
  }
  cout<<ma<<endl;
}


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

using namespace std;


const long long MOD = 1000000007;

long long fastPower(long long exp, long long base)
{
    long long sol = 1;
    long long p=1;
    while(exp > 0)
    {
        if(exp & 1)  ///este echivalent cu exp % 2 == 1
            p = (p* (base%MOD))%MOD;
        base = ((base%MOD) * (base%MOD) )% MOD;
        exp = exp>>1; ///este echivalent cu p = p/2
    }
    return p;
}

int main()
{
    int n, i, j;
    long long x;
    cin>>n;
    long long sum = 0;
    long long sqsum = 0;
    for(i=1;i<=n;i++)
    {
        cin>>x;
        sum = (sum + x)%MOD;
        x = x * x;
        sqsum = (sqsum + x)%MOD;
    }
    sum = sum * sum;
    sum = (sum - sqsum)%MOD;
    long long sol = (sum * fastPower(MOD-2,2))%MOD;
    sol =sol % MOD;

    cout<<sol;


}


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


#define	ll_int	long long int
#define	BUCKET_SIZE	1000000
#define	SUB_SIZE	1000


int ELEMENT_N;

typedef struct data_t{
	ll_int num;
	int n;
	struct data_t *next;
} DATA_T;

DATA_T **S;


// ハッシュテーブルの初期化
void Init()
{
	int i;

	for(i = 0; i < BUCKET_SIZE; i++)
		S[i] = NULL;
}


ll_int Hash(ll_int num)
{
	return num / SUB_SIZE;
}


DATA_T *Find(ll_int num)
{
	ll_int h;
	DATA_T *p;


	h = Hash(num);

	for(p = S[h]; p != NULL; p = p->next){
		if(num == p->num)
			return p;
	}

	return NULL;
}


void Insert(ll_int num)
{
	ll_int h;
	DATA_T *p;
	DATA_T *i, *j;


	if(( p = Find(num) )){
		p->n++;
		return;
	}


	/* 挿入処理(比較して該当する場所へ突っ込む) */
	if( ( p = (DATA_T *)malloc(sizeof(DATA_T)) ) == NULL){
		printf("malloc error\n");
		exit(1);
	}

	p->num = num;
	p->n = 1;
	h = Hash(num);

	if(S[h] == NULL){
	// 該当する添え字の箱が空の場合
		S[h] = p;
		p->next = NULL;
	}else if(num < S[h]->num){
	// 該当する添え字の先頭に挿入
		p->next = S[h];
		S[h] = p;
	}else{
	// 先頭以降への挿入
		for(i = S[h], j = i->next; j != NULL; i = j, j = j->next){
			if(i->num < num && num < j->num){
				i->next = p;
				p->next = j;
				break;
			}
		}

		if(j == NULL){
		// 最後尾に突っ込む
			i->next = p;
			p->next = j;
		}
	}

	ELEMENT_N++;
}


void Delete(ll_int num)
{
	DATA_T *p, *q;
	ll_int h;


	if(Find(num) == NULL)
		return;


	h = Hash(num);
	p = S[h];
	ELEMENT_N--;

	// 先頭にある場合の処理
	if(num == p->num){
		S[h] = p->next;
		free(p);
		return;
	}

	// 先頭以降の処理
	for(q = p->next;; p = q, q = q->next){
		if(num == q->num){
			p->next = q->next;
			free(q);
			break;
		}
	}
}


// lとrを基準にハッシュテーブルの添え字を計算、条件にあった数値を出力
void Dump(ll_int l, ll_int r)
{
	DATA_T *p;
	ll_int start_h, end_h;
	ll_int i;


	start_h = Hash(l);
	end_h = Hash(r);

	for(i = start_h; i <= end_h; i++){
		for(p = S[i]; p != NULL; p = p->next){
			if(r < p->num)
				return;

			if(l <= p->num && p->num <= r)
				printf("%lld\n", p->num);
		}
	}
}


int main()
{
	int q;
	int query;
	ll_int num, l, r;
	DATA_T *p;
	int i;


	ELEMENT_N = 0;
	S = (DATA_T **)malloc(sizeof(DATA_T *) * BUCKET_SIZE);

	scanf("%d", &q);

	for(i = 0; i < q; i++){
		scanf("%d", &query);

		if(query == 0){
		// insert
			scanf("%lld", &num);
			Insert(num);
			printf("%d\n", ELEMENT_N);
		}else if(query == 1){
		// find
			scanf("%lld", &num);
			if(( p = Find(num) ))
				printf("1\n");
			else
				printf("0\n");
		}else if(query == 2){
		// Delete
			scanf("%lld", &num);
			Delete(num);
		}else if(query == 3){
		// Dump
			scanf("%lld %lld", &l, &r);
			Dump(l, r);
		}
	}

	return 0;
}


/*
	1,ハッシュ関数でいつも使う「find」でDumpしようと思ったがタイムオーバー
	->失敗：いちいちfindで探索してると間に合わない

	2,ハッシュテーブルからデータを取り出してクイックソートからのDumpもタイムオーバー
	->失敗：いちいちソートしてるから間に合わない

	3,ハッシュテーブル自体を特殊な形にする
	->成功：ハッシュテーブルとほぼ同じだが箱の扱いを以下のようにする
	S[num] は「100 * num ～ 100 * num + 99」までの数値を入れる
	例：S[0]は0～99、S[100]は10000～10099という具合

	そしてInsertは数値の並びが昇順になるように処理

	これによって全ての操作が高速になる
*/


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

int main() {
 string s, t;
  cin >> s >> t;
  if(s.at(0) == t.at(2) && s.at(1) == t.at(1) && s.at(2) == t.at(0) ){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
}


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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll ans=10000000;
    int n;
    cin>>n;
    vi v;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        v.pb(k);
    }
    for(int i=-100;i<=100;i++){
        ll count=0;
        for(int j=0;j<n;j++){
            count+=(v[j]-i)*(v[j]-i);
        }
        if(count<ans)
            ans=count;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().strip().split())

# visited = [False for _ in range(N)]
# def dfs(v): # vertices & parent idx
#     visited[v]=True
#     for child in to[v]:
#         if visited[child]==True:
#             continue
#         ans[child]+=ans[v]
#         dfs(child)
# def dfs(v,p=-1): # vertices & parent idx
#     for child in to[v]:
#         if child==p:
#             continue
#         ans[child]+=ans[v]
#         dfs(child,v)

to=[[] for j in range(N)] # N points
ans=[0]*N # N points

for i in range(N-1):
    a,b=map(int, input().strip().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)

for i in range(Q):
    p,x=map(int, input().strip().split())
    p-=1
    ans[p]+=x

# dfs(0)
stack=[0]
visited=[False]*N
while stack:
    v=stack.pop()
    visited[v]=True
    for child in to[v]:
        if visited[child] ==False:
            # visited[v]=True
            ans[child]+=ans[v]
            stack.append(child)
for i in range(N):
    print(ans[i],end=' ')
# print(ans)

Measured memory_bytes: 52656
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    class BIT:
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
            self.depth=n.bit_length()
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
        
        def lower_bound(self,x):
            sum_=0
            pos=0
            for i in range(self.depth,-1,-1):
                k=pos+(1<<i)
                if k<=self.num and sum_+self.dat[k]<x:
                    sum_+=self.dat[k]
                    pos+=1<<i
            return pos, sum_
    
    Q=int(input())
    Query=[]
    unique_a=set()
    for _ in range(Q):
        q=tuple(map(int,input().split()))
        if q[0]==1:
            unique_a.add(q[1])
            Query.append(q)
        else:
            Query.append((q[0],0,0))
    unique_a=list(unique_a)
    unique_a.sort()
    d={x:i for i,x in enumerate(unique_a)}
    b0=BIT(len(unique_a))
    b1=BIT(len(unique_a))
    sum_b=0
    sum_a=0
    c=0
    for i,(q,a,b) in enumerate(Query,1):
        if q==1:
            b0.add(d[a],1)
            b1.add(d[a],a)
            c+=1
            sum_a+=a
            sum_b+=b
        else:
            index,_=b0.lower_bound(-(-c//2))
            x=unique_a[index]
            tmp=b1.sum(index)
            z=b0.sum(index)
            y=(z*2-c)*x-tmp*2+sum_a+sum_b
            print(x,y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 101976
S = input()
T = ''
for i in range(int(len(S)/5)+1):
    if len(S) != len(T):
        if S[len(S)-len(T)-1] == 'm':
            T = 'dream' + T
        elif S[len(S)-len(T)-1] == 'e':
            T = 'erase' + T
        elif S[len(S)-len(T)-3:len(S)-len(T)] == 'mer':
            T = 'dreamer' + T
        elif S[len(S)-len(T)-3:len(S)-len(T)] == 'ser':
            T = 'eraser' + T
        else:
            break

if S == T:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3532
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ":" << p.second;
    return os;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
    const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};

    for (;;) {
        int N; cin >> N;
        if (N == 0) break;
        vll L(N);
        vi S(N);
        REP(i, N) {
            int m; cin >> m >> L[i];
            REP(j, m) {
                int s, e; cin >> s >> e;
                FOR(t, s, e) {
                    S[i] |= 1<<t-6;
                }
            }
        }

        vll dp(1<<16);
        REP(i, N) {
            REP(s, 1<<16) {
                if ((s & S[i]) == 0) {
                    chmax(dp[s | S[i]], dp[s] + L[i]);
                }
            }
        }
        ll ans = *max_element(ALL(dp));
        cout << ans << endl;
    }

    return 0;

}



Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
using namespace std;

int main(){
  int t,p,r;

  while(cin>>t>>p>>r&&t|p|r){
    vector<pair<int, pair<int, int> > > team(t);
    vector<pair<int, int> > problem;

    // initialize
    for(int i=0;i<t;i++){
      team[i].first=0;
      team[i].second.first=0;
      team[i].second.second=i+1;
    }

    for(int i=0;i<r;i++){
      int tid,pid,time;
      string message;
      cin >> tid >> pid >> time >> message;

      if(message=="WRONG"){
        problem.push_back(make_pair(pid, tid));
      }else{
        team[tid-1].first++;
        for(int j=0;j<problem.size();j++){
          if(problem[j].first==pid&&problem[j].second==tid){
            team[tid-1].second.first+=1200;
          }
        }
        team[tid-1].second.first+=time;
      }
    }

    sort(team.begin(), team.end(), greater<pair<int, pair<int, int> > >());

    for(int i=0;i<=t-1;i++){
      for(int j=i+1;j<=t-1;j++){
        if(team[i].first==team[j].first&&team[i].second.first>team[j].second.first){
          swap(team[i],team[j]);
        }
      }
    }

    for(int i=0;i<=t-1;i++){
      for(int j=i+1;j<=t-1;j++){
        if(team[i].first==team[j].first&&team[i].second.first==team[j].second.first&&team[i].second.second>team[j].second.second){
          swap(team[i],team[j]);
        }
      }
    }

    for(int i=0;i<t;i++){
      cout << team[i].second.second << " " << team[i].first << " " << team[i].second.first << endl;
    }

  }

  return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define SZ(x) ((int)(x).size())
#define MEM(x,a) memset(x,a,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
const ll mod=1000000007,N=1e5+5,M=1e5+5,INF=0x3f3f3f3f;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//head

int main(void){
    int k;
    cin>>k;
    ll sum=0;
    rep(i,1,k+1)rep(j,1,k+1)rep(o,1,k+1)sum+=gcd(i,gcd(j,o));
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3636
IDENTIFICATION DIVISION.
 PROGRAM-ID. TEST134.

 DATA DIVISION.
 WORKING-STORAGE SECTION.
  01 INP   PIC 9(3).
  01 ANS   PIC ZZZZZZ9.

 PROCEDURE DIVISION.
  ACCEPT INP.
  COMPUTE ANS = 3 * INP * INP.
  DISPLAY ANS.

 STOP RUN. 

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(int i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()

int main() {
    while(1) {
      string s; cin >> s;
      if(s.empty()) return 0;
      int a=0, b=0;
      rep(i, s.size()-2) {
        string d = s.substr(i, 3);
        if(d == "JOI") a++;
        if(d == "IOI") b++;
    }
      cout << a << endl;
      cout << b << endl;
    }
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <fstream>
#include <string>
#include <sstream>
#include <algorithm>
#include <climits>
#include <cmath>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
    int l, r, d;
    cin >> l >> r >> d;
    int left = l % d ? (l / d + 1) * d : l;
    int right = r % d ? (r / d) * d  : r;
    int count = (right - left) / d;
    cout << count + 1 << "\n";
	return 0;
}


Measured memory_bytes: 3192
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

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 (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  constexpr int MOD = 1e9 + 7;
  int H, W;
  cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  REP(i, H) {
    REP(j, W) { cin >> grid[i][j]; }
  }

  vector<vector<int>> dp(H + 1, vector<int>(W + 1, 0));
  dp[0][1] = 1;
  FOR(i, 1, H + 1) {
    FOR(j, 1, W + 1) {
      if (grid[i - 1][j - 1] == '.') {
        dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
        dp[i][j] %= MOD;
      } else {
        dp[i][j] = 0;
      }
    }
  }
  cout << dp[H][W] << endl;

  return 0;
}

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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    string S;
    cin >> N >> S;
    int accblack[N] = {0}, accwhite[N] = {0};
    rep(i, N){
        if(i == 0 && S[i] == '#') accblack[i] = 1;
        else if(i == 0) continue;
        else if(S[i] == '#') accblack[i] = accblack[i-1]+1;
        else accblack[i] = accblack[i-1];
    }
    for(int i = N-1; i >= 0; i--){
        if(i == N-1 && S[i] == '.') accwhite[i] = 1;
        else if(i == N-1) continue;
        else if(S[i] == '.') accwhite[i] = accwhite[i+1]+1;
        else accwhite[i] = accwhite[i+1];
    }
    int ans = 1000000;
    rep(i, N){
        int val; if(i != N-1) val = accblack[i]+accwhite[i+1]; else val = accblack[i]; 
        if(val <= ans) ans = val;
    }
    cout << min(ans, accwhite[0]) << endl;
    return 0;
}

void solve(){}

Measured memory_bytes: 2180
// abc141_d
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    priority_queue<double> pq(ALL(A));

    REP(i, M){
        double x = pq.top(); pq.pop();
        pq.push(x / 2.0);
    }

    ll ans = 0;
    REP(i, N){
        ans += (int)pq.top();
        pq.pop();
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1408
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
H = list(map(int, sys.stdin.buffer.readline().split()))

H = np.array(H, dtype=int)

ans = 0
while H.max() > 0:
    l = 0
    r = 0
    while l < N:
        while l < N and H[l] <= 0:
            l += 1
        r = l
        while r < N and H[r] > 0:
            r += 1
        if l < N:
            ans += 1
        l = r
    H -= 1
print(ans)


Measured memory_bytes: 13564
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N (5000)
//n<=500

int n, m;
vector<int> e[N];
vector<int>ne[N];
set<int>nn[N];
vector<int>ree[N];
vector<int>vs;
bool used[N];
int tpord[N];
vector<int>rtpord[N];


void dfs(int v) {
	used[v] = true;
	f(i, e[v].size()) {
		if (!used[e[v][i]])dfs(e[v][i]);
	}
	vs.push_back(v);
	return;
}

void redfs(int v, int k) {
	used[v] = true;
	tpord[v] = k;
	rtpord[k].push_back(v);
	f(i, ree[v].size()) {
		if (!used[ree[v][i]])redfs(ree[v][i], k);
	}
}

int scc(void) {
	memset(used, 0, sizeof(used));
	vs.clear();
	f(i, n) {
		if (!used[i])dfs(i);
	}
	memset(used, 0, sizeof(used));
	int k = -1;
	for (int i = vs.size() - 1; i >= 0; i--) {
		if (!used[vs[i]]) {
			k++;
			redfs(vs[i], k);
		}
	}
	f(i, n) {
		f(j, e[i].size()) {
			if (nn[tpord[i]].count(tpord[e[i][j]]) == 0 && tpord[e[i][j]] != tpord[i]) {
				ne[tpord[i]].push_back(tpord[e[i][j]]);
				nn[tpord[i]].insert(tpord[e[i][j]]);
			}
		}
	}
	k++;
	return k;
}


int main(void) {
	int x, y;
	long long z;
	int q;
	int asd;
	scanf("%d %d", &n, &m);
	f(i, m) {
		scanf("%d %d", &x, &y);
		x--;
		y--;
		e[x].push_back(y);
		ree[y].push_back(x);
	}
	q = scc();
  f(i,q)sort(rtpord[i].begin(),rtpord[i].end());
	f(i, n) {
		asd = tpord[i];
		f(j, rtpord[asd].size()) {
			printf("%d", rtpord[asd][j]+1);
			if ((j + 1) < rtpord[asd].size())printf(" ");
		}
		printf("\n");
	}
	

	return 0;
}


Measured memory_bytes: 4664
#pragma GCC optimize("O3")
#define first x
#define second y
#include <bits/stdc++.h>

using namespace std;

enum {MOD0 = 1000000000, MOD7 = 1000000007, MOD9 = 1000000009};
typedef unsigned short ushort;typedef unsigned int uint;typedef long long ll;typedef unsigned long long ull;
#ifndef CrafterKolyan
#define endl '\n'
#endif

signed main() {
#ifndef CrafterKolyan
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
    int n;
    cin >> n;
    int ans = 0;
    while (n--) {
        int x;
        cin >> x;
        while (!(x & 1)) {
            ++ans;
            x >>= 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int n,a[3010],sum[3010],dp[3010][3010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(int i=1;i<=n;i++){cin>>a[i];dp[i][i]=a[i];sum[i]=sum[i-1]+a[i];}
	for(int l=2;l<=n;l++){
		for(int i=1,j=i+l-1;j<=n;i++,j++){
			int val=sum[j]-sum[i-1];
			int ans1=val-dp[i+1][j],ans2=val-dp[i][j-1];
			dp[i][j]=max(ans1,ans2);
		}
	}
	cout<<dp[1][n]-(sum[n]-dp[1][n])<<endl;
	return 0;
}

Measured memory_bytes: 70144
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct line{
	int l,r;
	bool friend operator <(line i,line j){
		return (i.l==j.l)?i.r<j.r:i.l<j.l;
	}
}a[N];
int pre[N],nxt[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>a[i].l>>a[i].r;
	sort(a+1,a+n+1);
	pre[0]=nxt[n+1]=1e9;
	for(int i=1;i<=n;++i)
		pre[i]=min(pre[i-1],a[i].r);
	for(int i=n;i>=1;--i)
		nxt[i]=min(nxt[i+1],a[i].r);
	int ans=0;
	for(int i=1;i<n;++i)
		ans=max(ans,max(pre[i]-a[i].l+1,0)+max(nxt[i+1]-a[n].l+1,0));
	int L=a[n].l,R=pre[n];
	for(int i=1;i<=n;++i)
		ans=max(ans,max(R-L+1,0)+a[i].r-a[i].l+1);
	cout<<ans;
	return 0;
}
 

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;


int main(){
	int h,w, n; cin >>h>>w>>n;
	vector<int> vec;
	for(int i = 1; i <= n; ++i){
		int a; cin >> a;
		for(int j = 0; j < a; ++j){
			vec.push_back(i);
        }
    }
	
	vector<vector<int> > ans(h, vector<int> (w));
	int cur=0;
  
	for(int i = 0; i < h; ++i){
if(i% 2==0){
		for(int j = 0; j < w; ++j){
			ans[i][j]=vec[cur];
			++cur;
        }
        }
else{
        for(int j = w-1; j >= 0; --j){
        	ans[i][j]=vec[cur];
        	++cur;
       }
}
       
    }
    
    for(int i = 0; i < h; ++i){
    	for(int j = 0; j < w; ++j){
    	    cout << ans[i][j] << ' ';
        }
        cout << endl;
    }
    
    return 0;
}

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

map<ll, ll> factorize(ll g){
    map<ll, ll> ret;
    if(g == 1){
        ret[1]++;
        return ret;
    }
    ll d = 2;
    while(d*d <= g){
        if(g % d == 0){
            ret[d]++;
            g /= d;
            while(g % d == 0){
                ret[d]++;
                g /= d;
            }
        }
        d++;
    }
    if(g != 1) ret[g]++;
    return ret;
}


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

    map<ll, ll> cnt;
    rep(i, 2, N+1){
        auto t = factorize(i);
        for(auto p : t){
            cnt[p.first] += p.second;
        }
    }

    ll ans = 1;
    ll mod = 1e9+7;
    for(auto c : cnt){
        if(c.first == 1) continue;
        ans *= (c.second+1)%mod;
        ans %= mod;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<P> a(n);
    rep(i,n) cin>>a[i].first>>a[i].second;
    rep(i,n-2) {
        if (a[i].first == a[i].second && a[i+1].first == a[i+1].second && a[i+2].first == a[i+2].second) {
            cout << "Yes" << '\n';
            return 0;
        }
    }

    cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<"\n"

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

  IN(N);

  int now = 0,
      cur_x = 0,
      cur_y = 0;
  REP(i, N) {
    IN(t); IN(x); IN(y);
    int d = abs(cur_x - x) + abs(cur_y - y);
    if (t - now < d || (d - (t - now)) % 2 != 0) {
      OUT("No");
      return 0;
    }
    now = t;
    cur_x = x;
    cur_y = y;
  }
  OUT("Yes");

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

#define MAX_NUM 1000000
ll n;

void Main() {
  //自動整形防止用コメント
  std::cin >> n;
  std::cout << (n * (n - 1)) / 2 << '\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: 256
q=int(input())
query=[list(map(int,input().split())) for _ in range(q)]
def factorize(n):
    if n==0:
        return 0
    a=[]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<=n:
        if n%f==0:
            a.append(f)
            n//=f
        else:
            f+=2
    if n!=1:
        a.append(n)
    return len(a)
s=[0]*100001 #s[i]==1:iが素数
for i in range(100001):
    s[i]=factorize(i)
j=[0]*100001
count=0
for i in range(100000):
    if s[i]==1:
        if s[(i+1)//2]==1:
            count+=1
            j[i]=count
        else:
            j[i]=count
    else:
        j[i]=count
for l,r in query:
    print(j[r]-j[l-1])

Measured memory_bytes: 28980
mod = 10**9+7
n,m = map(int,input().split())	
x = list(map(int,input().split()))	
y = list(map(int,input().split()))
x.sort()
y.sort()

x_sum = 0
for i in range(1,n):
    x_sum += (x[i]-x[i-1])*i*(n-i)
    x_sum = x_sum%mod
y_sum = 0
for i in range(1,m):
    y_sum += (y[i]-y[i-1])*i*(m-i)
    y_sum = y_sum % mod
print(x_sum*y_sum%mod)

Measured memory_bytes: 18576
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
struct point {
	ll firs, seco;
	ll sum;
	int ls;
};
vector <point> v;
bool operator < (const point& a, const point& b) {
	return a.sum < b.sum;
}
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++) {
    	ll a, b;
    	cin >> a >> b;
    	v.push_back ((point){a, b, a + b, i});
	}
	sort (v.begin(), v.end());
	reverse (v.begin(), v.end());
	ll ret = 0;
	for (int i = 0; i < v.size(); i ++)
    	if (i % 2 == 0)
			ret += v[i].firs;
		else
			ret -= v[i].seco;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 6256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main()
{
    std::string S;
    std::cin >> S;
    bool b = true;
    for (int i = 1; i < S.length(); i += 2)
    {
        if (S[i] == 'R')
        {
            b = false;
            break;
        }
    }

    for (int i = 0; i < S.length(); i += 2)
    {
        if (S[i] == 'L')
        {
            b = false;
            break;
        }
    }

    if (b) { std::cout << "Yes" << std::endl; }
    else
    {
        std::cout << "No" << std::endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int e = 2e6 + 69;

vector<int>rel[e];
bool checked[e];

void dfs(int i){
    checked[i] = false;
    for (int j : rel[i])
    {
        if(checked[j]) dfs(j);
    }    
}

int main(){
    int n,m;
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b, c;
        cin>> a >> b >> c;
        rel[a-1].push_back(b-1);
        rel[b-1].push_back(a-1);
    }
    memset(checked,true,sizeof(checked));
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if(checked[i]){
            dfs(i);
            sum ++ ;
        }
    }
    cout << sum << endl; 
}

Measured memory_bytes: 58656
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var N int

type Edge Pair

var G [][]Edge
var res []int

func dfs(v, p, c int) {
	res[v] = c
	for _, e := range G[v] {
		if e.a == p {
			continue
		} else if e.b&1 > 0 {
			dfs(e.a, v, 1-c)
		} else {
			dfs(e.a, v, c)
		}
	}
}

func main() {
	fmt.Scan(&N)
	G = make([][]Edge, N)
	for i := 0; i < N-1; i++ {
		var u, v, w int
		fmt.Scan(&u, &v, &w)
		u--
		v--
		G[u] = append(G[u], Edge{v, w})
		G[v] = append(G[v], Edge{u, w})
	}
	res = make([]int, N)
	dfs(0, -1, 1)
	for i := 0; i < N; i++ {
		fmt.Println(res[i])
	}
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type pairs []Pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


Measured memory_bytes: 24192
#include <iostream>
#include <numeric>
#include <iomanip>
#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
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)




int main() {
	int H,W,N;
	cin >> H>>W>>N;
	
	cout << (N-1)/max(H,W)+1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
 int temp;
 int n;
 int count=0;

 scanf("%d",&n);
 temp=n/1000;
 if (temp==2) count++;
 n=n-1000*temp;
 temp=n/100;
 if (temp==2) count++;
 n=n-100*temp;
 temp=n/10;
 if (temp==2) count++;
 n=n-10*temp;
 if (n==2) count++;

 printf("%d\n",count);
 return 0;
}


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"
#define int ll

int D;
const int N=26;
vector<vector<int>>s;
vector<int>c;

ll score(vector<int>&t){
  ll score=0;
  ll ans=0;
  vector<int>last(N,-1);
  for(int i=0;i<D;i++){
    ans+=s[i][t[i]];
    last[t[i]]=i;
    for(int j=0;j<N;j++){
      if(last[j]==-1)ans-=c[j]*(i+1);
      else ans-=c[j]*(i-last[j]);
    }
    score+=max(ans+1000000,0ll);
  }
  return score;
}

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

  cin>>D;
  c.resize(N);
  for(int i=0;i<N;i++)cin>>c[i];
  s.resize(D,vector<int>(N));
  for(int i=0;i<D;i++)for(int j=0;j<N;j++)cin>>s[i][j];

  ll MaxScore=0;
  vector<int>ans;
  for(int i=0;i<1000;i++){
    vector<int>t(D);
    std::mt19937 rand_src(i);
    for(int j=0;j<D;j++)t[j]=rand_src()%N;
    ll s=score(t);
    if(MaxScore<s)ans=t,MaxScore=s;
  }

  for(auto it:ans)cout<<it+1<<endl;
  //cout<<MaxScore<<endl;
  return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
using namespace std;

int main(){
	string str;
	
	cin >> str;
	
	for(string::iterator it = str.begin(); it != str.end(); ++it){
		*it = ((*it - 'A') - 3 + 26) % 26 + 'A';
	}
	
	cout << str << endl;
	return 0;
}

Measured memory_bytes: 1180
using System;
 
class Program {
  static void Main() {
    int n = int.Parse(Console.ReadLine());
    var s = Console.ReadLine();
    var t = Console.ReadLine();
    int i = 0;
    for ( ; i < n; i++) {
      if (s.Substring(i) == t.Substring(0, n - i)) break;
    }
    Console.WriteLine(i + t.Length);
  }
}

Measured memory_bytes: 11092
# -*- coding: utf-8 -*-
"""
Created on Sun Sep 13 02:42:27 2020

@author: liang
"""

N, M = map(int, input().split())
drinks = list()
for i in range(N):
  a, b = map(int,input().split())
  drinks.append((a,b))

drinks.sort(key = lambda x: x[0])
#print(drinks)
ans = 0
i = 0
while M > 0:
    a, b = drinks[i]
    i += 1
    if M <= b:
        ans += a*M
        M = 0
    else:
        ans += a*b
        M -= b
    #print(ans,M)
print(ans)

Measured memory_bytes: 23628
n = gets.chomp.to_i

arr = n.times.map { |i|
    p, s = gets.chomp.split(" ")
    [i + 1, p, s.to_i]
}

arr.sort_by! { |row|
    [row[1], -row[2]]
}.each { |row|
    puts row[0]
}

Measured memory_bytes: 14260
x = int(input())
n = 2*10**5
table = [2] * (n+1)
table[1] = 1
for i in range(2, n//2+1):
  for j in range(2*i, n+1, i):
    table[j] += 1
for i in range(x, n+1):
  if table[i] == 2:
    print(i)
    exit()

  

Measured memory_bytes: 72396
object Main extends App {
  val Array(n, m) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  var total = array.sum
  var count = 0

  if (total % (4 * m) == 0) {
    count = array.count(x => x >= total / (4 * m))
  } else {
    count = array.count(x => x >= total / (4 * m) + 1)
  }

  if (count < m) {
    println("No")
  } else {
    println("Yes")
  }
}


Measured memory_bytes: 27064
#include <bits/stdc++.h>
using namespace std;
long long h, n, a, b, sol[20010], ans, inf=9583958392581539LL;
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> h >> n;
for (int i=1; i<=h+10005; i++) sol[i]=inf;
for (int i=0; i<n; i++){
	cin >> a >> b;
	for (int i=a; i<=h+10005; i++)
		sol[i]=min(sol[i], sol[i-a]+b);
} ans=inf;
for (int i=h; i<=h+10005; i++) ans = min(ans, sol[i]);
cout << ans;
return 0;
}

Measured memory_bytes: 384
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


n,y=get_i
money=[10000,5000,1000]
ans=[-1,-1,-1]
(n+1).times do|i|
  (n+1).times do|j|
    if n>=i+j and y==i*money[0]+j*money[1]+(n-i-j)*money[2]
      ans=[i,j,n-i-j]
    end
  end
end
puts ans.join(" ")

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
#define llx(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len) {char ss[len];scanf("%s",ss);(st)=ss;}
using namespace std;
long long n,m,i,j,dp[(1<<18)+5][3],ans[(1<<18)+5],num[(1<<18)+5];
void upd(long long x,long long y)
{
	if (dp[x][0]==y||dp[x][1]==y) return;
	if (num[dp[x][1]]<num[y])
	{
		dp[x][1]=y;
		if (num[dp[x][0]]<num[dp[x][1]]) swap(dp[x][0],dp[x][1]);
	}
}
int main()
{
	scanf("%lld",&n);
	m=(1<<n);
	for (i=0;i<m;i++)
	{
		scanf("%lld",&num[i]);
		dp[i][0]=i;
	}
	for (i=0;i<m;i++)
	{
		for (j=0;j<n;j++)
		{
			if (!((i>>j)&1))
			{
				upd((i|(1<<j)),dp[i][0]);
				upd((i|(1<<j)),dp[i][1]);
			}
		}
	}
	for (i=1;i<m;i++)
	{
		ans[i]=max(ans[i-1],num[dp[i][0]]+num[dp[i][1]]);
		printf("%lld\n",ans[i]);
	}
	return 0;
}

Measured memory_bytes: 13312
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const ll v = 3001;
ll dp[v][v];

ll length(string& s,string& t,ll i,ll j)
{
   // memset(dp,-1,sizeof(dp));
    //Base case
    if(i>=s.size() || j>=t.size())
    return 0;

    //Lookup
    if(dp[i][j] != -1)
    return dp[i][j];

    //Rec case
    if(s[i] == t[j])
    return dp[i][j] = 1 + length(s,t,i+1,j+1);

    else
    return dp[i][j] = max(length(s,t,i+1,j), length(s,t,i,j+1));
}

int main()
{
   fast_io;
    string s,t;
    cin>>s>>t;
     memset(dp,-1,sizeof(dp));

    //cout<<length(s,t,0,0)<<endl;
  ll len = length(s,t,0,0);
  ll i=0,j=0;

   string ans = " ";
   while(len)
   {
       if(s[i] == t[j])
       {
           ans.pb(s[i]);
           i++;
           j++;
           len--;
       }
       else
       {
           if(dp[i][j+1] > dp[i+1][j])
           j++;
           else
           i++;
       }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 74312
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

ll n;

int main() {
    cin >> n;
    vector<ll> C(n-1, 0);
    vector<ll> S(n-1, 0);
    vector<ll> F(n-1, 0);
    for(int i = 0; i < n-1; ++i) {
        cin >> C.at(i) >> S.at(i) >> F.at(i);
    }

    for(int i = 0; i < n; ++i) {
        int start = i;
        vector<ll> cans(n, 0);
        for(int j = start; j < n-1; ++j) {
            if(j == start) {
                // startは始発電車
                cans.at(j+1) = S.at(j) + C.at(j);
            }else {
                ll next = cans.at(j);
                if(cans.at(j) % F.at(j) != 0) {
                    next += F.at(j) - (cans.at(j)%F.at(j));
                }
                cans.at(j+1) = C.at(j) + max(next, S.at(j));
            }
        }
        cout << cans.at(n-1) << endl;
    }
}

Measured memory_bytes: 256