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

int main(){
    int N;
    pair<int, int> BA[200000];
    cin >> N;
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        BA[i] = {b, a};
    }
    sort(BA, BA+N);

    int64_t sum = 0;
    for(int i=0; i<N; i++){
        sum += BA[i].second;
        if(sum > BA[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,m;
    cin>>n>>m;
    UnionFind tree(n);
    int p[n];
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--;y--;
        tree.unite(x,y);
    }
    int cnt=0;
    rep(i,n){
        if(tree.same(i,p[i])){
            cnt++;
        }
    }
    cout<<cnt<<endl;


    return 0;
}


Measured memory_bytes: 4004
import numpy as np

n,k,q = map(int,input().split())
d = [int(input()) for i in range(q)]
 
p=np.full(n,k)
z=np.full(n,-1*q)

p=p+z

for a in range(0,q):
  p[d[a]-1]+=1
 
for l in range(0,n):
  if p[l]>0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 18876
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(){
  string str, order, p;
  int a, b, q;

  cin >> str >> q;
  for(int i = 0; i < q; i++){
    cin >> order >> a >> b;
    if(order == "print"){
      cout << str.substr(a, b-a+1) << endl;
    }
    else if(order == "reverse"){
      reverse(str.begin()+a, str.begin()+b+1);
    }
    else if(order == "replace"){
      cin >> p;
      str.replace(a, b-a+1, p);
    }
  }

  return 0;
}



Measured memory_bytes: 3200
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

h, n = MAP()
a = [0]*n
b = [0]*n
dp = [inf]*(h+1)
dp[0] = 0
# dp[j]: ダメージ>=jとするために必要な魔力の最小値

for i in range(n):
    a[i], b[i] = MAP()

for i in range(n):
    for j in range(0,h+1):
        if j < a[i]:
            dp[j] = min(dp[j], b[i])
        else:
            dp[j] = min(dp[j], dp[j-a[i]]+b[i])

print(dp[h])

Measured memory_bytes: 75784
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		double N=stdIn.nextDouble();
		double K=stdIn.nextDouble();
		double a=0;
		double z=1,y=0,x=0,w=1,k=(double)1/N;
		while(z<=N){
			if(z>=K)
				a+=k;
			else{
				x=z;
				while(true){
					x*=2;
					w*=(double)0.5;
					y++;
					if(x>=K)
						break;
				}
				a+=k*w;
			}
			w=1;
			z++;
		}
		System.out.println(a);
	}
}

Measured memory_bytes: 23252
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

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

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

void f(ll rest,string s){
    if(rest==0){
        cout<<s<<endl;
    }else{
        for(char c='a';c<='c';c++){
            f(rest -1,s+c);
        }
    }
}


int main(){
    ll n,c=0;
    cin>>n;
    c+=1000*(n/500);
    n=n%500;
    while(n>=5){
        c+=5;
        n-=5;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str1 = br.readLine();
    String[] str2 = str1.split(" ");
    int a = Integer.parseInt(str2[0]);
    int b = Integer.parseInt(str2[1]);
    int c = Integer.parseInt(str2[2]);

    if (a < b && b < c)
      System.out.println("Yes");
    else
      System.out.println("No");
    }
}

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

typedef long long ll;

int main()
{
	ll a, b, n;
  	cin >> a >> b >> n;
  	if(b - 1 <= n)
    {
  		cout << (a * (b - 1)) / b << endl;
    }
  	else
    {
    	cout << (a * n) / b << endl;
    }
}


Measured memory_bytes: 3628
import sys
from collections import deque

sys.setrecursionlimit(500005)
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().strip()

h, w = na()
ch, cw = na()
dh, dw = na()

b = []
for i in range(h):
    b.append(ns())

q = deque()
q.append((ch-1, cw-1))
ds = [9999999999] * (h*w)
ds[(ch-1)*w+cw-1] = 0

di = ((1, 0), (0, 1), (-1, 0), (0, -1))
while q:
    r, c = q.popleft()
    for k in di:
        nr, nc = r + k[0], c + k[1]
        if 0 <= nr < h and 0 <= nc < w and b[nr][nc] == "." and ds[nr*w+nc] > ds[r*w+c]:
            ds[nr*w+nc] = ds[r*w+c]
            q.appendleft((nr, nc))
    for nr in range(r-2, r+3):
        for nc in range(c-2, c+3):
            if 0 <= nr < h and 0 <= nc < w and b[nr][nc] == "." and ds[nr * w + nc] > ds[r * w + c] + 1:
                ds[nr * w + nc] = ds[r * w + c] + 1
                q.append((nr, nc))

if ds[(dh-1)*w+dw-1] > 9999999:
    print(-1)
else:
    print(ds[(dh-1)*w+dw-1])



Measured memory_bytes: 85184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main{
	public static void main(String[] args) {
		SC sc=new SC(System.in);
		int V=sc.nextInt();
		int E=sc.nextInt();
		long[] distance=new long[V*V];
		long[] nega=new long[V];
		long[] rinsetu=new long[V*V];
		long INF=10000000007L;
		Arrays.fill(rinsetu, INF);
		Arrays.fill(nega, INF);
		Arrays.fill(distance,INF);
		int start=0;
		nega[start]=0;
		for(int i=0; i<E; i++) {
			long from=sc.nextLong();
			long to=sc.nextLong();
			long cost=sc.nextLong();
			rinsetu[(int)(from*V+to)]=cost;
			distance[(int)(from*V+to)]=cost;
		}
		for(int i=0; i<V; i++) {
			distance[i*V+i]=0;
		}

		for(int i=0; i<V; i++) {
			boolean update=false;
			for(int j=0; j<V; j++) {
				for(int k=0; k<V*V; k++) {
					if(nega[k/V]<INF && nega[k%V]>nega[k/V]+rinsetu[k]) {
						nega[k%V]=nega[k/V]+rinsetu[k];
						update=true;
					}
				}
				if(update==false) {
					break;
				}
				else if(i==V-1) {
					pl("NEGATIVE CYCLE");
					System.exit(0);
				}
			}
		}
		for(int i=0; i<V; i++) {
			for(int j=0; j<V; j++) {
				for(int k=0; k<V; k++) {
					distance[j*V+k]=Math.min(distance[j*V+k], distance[j*V+i]+distance[i*V+k]);
					//要は、0-(V-1)までの数字のうち3つを選ぶってことしてるだけって感じする
				}
			}
		}
		StringBuilder sb=new StringBuilder();
		for(int i=0; i<V*V; i++) {
			if(i%V==0) {
				sb=new StringBuilder();
			}
			if(i%V==V-1) {
				if(distance[i]>=2000000001) {
					sb.append("INF");
				}
				else {
					sb.append(distance[i]);
				}
				pl(sb.toString());
			}
			if(distance[i]>=2000000001) {
				sb.append("INF ");
			}
			else {
				sb.append(distance[i]+" ");
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
}


Measured memory_bytes: 37468
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>
#include<vector>
#include<map>
#include<iomanip>
using namespace std;
#define fr first
#define sc second
typedef pair<int,int> P;
int main(){
  int X,Y,Z,N,E,A;
  while(cin >> X >> Y >> Z , X){
    int jump[X];
    P ivent[Y+1];
    for(int i = 0 ; i <= Y ; i++ ) ivent[i] = P( 0 , 0 );
    double dp[51][5001]={{}};
    dp[0][0] = 1.0;

    for(int i = 0 ; i < X ; i++ ){
      cin >> jump[i];
    }
    for(int i = 0 ; i < Z ; i++ ){
      cin >> N >> E >> A;
      switch(E){
      case 1: ivent[N].fr = A; break;
      case 2: ivent[N].sc = A; break;
      case 3: ivent[N].sc = -A; break;
      }
    }
    for(int i = 0 ; i < Y ; i++ ){
      for(int j = 0 ; j <= i*100 ; j++ ){
        if(dp[i][j]){
          for(int k = 0 , p_mas , p_money ; k < X ; k++ ){
            p_mas = min( i + jump[k] , Y );
            p_money = max(0,ivent[p_mas].sc + j );
            p_mas = min( p_mas + ivent[p_mas].fr , Y );

            dp[p_mas][p_money] += dp[i][j] / X;
          }
        }
      }
    }
    double ans = 0.0;
    for(int i = 0 ; i < 5001 ; i++ ){
      ans += dp[Y][i] * i;
    }
    cout << (int)ans << endl;
  }
}

Measured memory_bytes: 3156
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>

using namespace std;

int main(){

    long long a,b,c,x=0,y=0,i,j;
    cin>>a>>b>>c;
    i=b-1;j=a-c;
    if((c-b)%2==0){x+=((c-b)/2);}
    else{x+=min(i,j);x+=1;x+=(c-b-1)/2;}
    cout << x <<  endl;
}
    

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

#define N 100100

int n, m, a[N], b[N];
vector <int> vec[N];

int main() {
    cin >> n >> m;
    multiset <int> S;
    for (int i = 0; i < n; i ++) {
        cin >> a[i] >> b[i];
        if (m >= a[i]) vec[a[i]].push_back(b[i]);
    }
    long long rlt = 0;
    for (int i = 1; i <= m; i ++) {
        for (auto x : vec[i]) S.insert(-x);
        if (!S.empty()) rlt -= *S.begin(), S.erase(S.begin());
    }
    cout << rlt << endl;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
vector<int> black,white;
vector<int> ch[3],e[N];
int dep[N],ans[N];
void dfs(int x,int fath){
	dep[x]=dep[fath]+1;
	if(dep[x]&1) black.push_back(x);
	else white.push_back(x);
	for(int i=0;i<e[x].size();++i)
		if(e[x][i]!=fath) dfs(e[x][i],x);
}
int main(){
	int n,x,y;cin>>n;
	for(int i=1;i<n;++i)
		cin>>x>>y,e[x].push_back(y),e[y].push_back(x);
	dfs(1,0);
	int sz=(n/3);
	if(black.size()>white.size()) swap(black,white);
	if(black.size()<=sz){
		int now=3;
		for(int i=0;i<black.size();++i)
			ans[black[i]]=now,now+=3;
		int T=0;if(now>n) now=++T;
		for(int i=0;i<white.size();++i){
			ans[white[i]]=now,now+=3;
			if(now>n) now=++T;
		}
	}
	else{
		int now=1;
		for(int i=0;i<black.size();++i){
			ans[black[i]]=now,now+=3;
			if(now>n) now=3;
		}
		int T=now;now=2;
		for(int i=0;i<white.size();++i){
			ans[white[i]]=now,now+=3;
			if(now>n) now=T;
		}
	}
	for(int i=1;i<=n;++i)
		cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 21556
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n;
    cin >> n;
    ll v=-1;
    ll ans=-1;
    rep(i,n){
        ll a,b;
        cin >> a >> b;
        if(a>v){
            ans=a+b;
            v=a;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void) {
	
	int sei[999][3], sum[999], m, f, r, cnt = 0;
	for(m = 0; 999 > m; m++){
		for(f = 0; 3 > f; f++){
			sei[m][f] = 0;
		}
		sum[m] = 0;
	}
	
	scanf("%d %d %d", &m, &f, &r);
	while(1){
		sei[cnt][0] = m;
		sei[cnt][1] = f;
		sei[cnt][2] = r;
		sum[cnt] = sei[cnt][0] + sei[cnt][1] ;
		cnt++;
		scanf("%d %d %d", &m, &f, &r);
		if(m == -1 && f == -1 && r == -1){
			break;
		}
	}
	
	for(m = 0; cnt > m; m++){
		if(sei[m][0] == -1 || sei[m][1] == -1){
			printf("F\n");
		}
		else{
			if(sum[m] >= 80)
				printf("A\n");
			if(sum[m] >= 65 && sum[m] < 80)
				printf("B\n");
			if(sum[m] >= 50 && sum[m] < 65)
				printf("C\n");
			if(sum[m] >= 30 && sum[m] < 50){
				if(sei[m][2] >= 50)
					printf("C\n");
				else
					printf("D\n");
			}
			if(sum[m] < 30)
				printf("F\n");
		}
	}
	
	
	
	
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
typedef long long ll;

bool ok(string s) {
   char a = s[0];
   REP(i,s.size()) {
      if(s[i] != a) return false;
   }
   return true;
}

bool exist(string s, char a) {
   REP(i,s.size()) if(s[i] == a) return true;
   return false;
}

int cnt(string s, char c) {
   if(!exist(s,c)) return 1e9;
   int ret = 0;
   while(!ok(s)) {
      string t;
      REP(i,s.size()-1) {
         if(s[i] == c || s[i+1] == c) t.push_back(c);
         else t.push_back('?');
      }
      s = t;
      ret++;
   }
   return ret;
}

int main() {

   string s; cin >> s;

   if(s.size() == 1) {
      cout << 0 << endl;
      return 0;
   }
   
   int ans = 1e9;
   for(char a = 'a'; a <= 'z'; a++) {
      ans = min(ans,cnt(s,a));
   }

   cout << ans << endl;

   return 0;
}

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

inline int plu( int x, int y )
{
	return x+y;
}
inline int sub( int x, int y )
{
	return x-y;
}
inline int multi( int x, int y )
{
	return x*y;
}
inline int maxn( int num1, int num2, int num3 )
{
	if( num1 >= num2 && num1 >= num3 )
		return num1;
	else if( num2 >=num1 && num2 >=num3 )
		return num2;
	else
		return num3;
}

int main()
{
	int a, b;
	
	while( ~scanf("%d%d", &a, &b ) )
	{
		int temp;
		temp = maxn( plu(a,b), sub(a,b), multi(a,b) );
		printf("%d\n", temp ); 
	
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
    int N; cin >> N;

    double total = 0;
    vector<double> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i] = 1/A[i];
        total += A[i];
    }

    cout << setprecision(10) << (double)1/total << endl;

    return 0;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  string T = "";
  for(int i = 0;i < (S.size()/2);i++){
    char A = S.at(i);
    T += A;
  }
  
  bool ans = false;
  if(S == (T + T)) ans = true;
 
  if(ans){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl; 
  }
  
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  cin >> a[0];
  int r=a[0];
  for(int i=1;i<n;i++){
    cin >> a[i];
    if(r>=a[i]+2){cout << "No" << endl;
                 return 0;}
    if(r<a[i]){r=a[i];}
  
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>

using namespace std;

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

int main(){
    int a, b;
    cin >> a >> b;
    if (a % 2 == 1 && b % 2 == 1){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }
    
}

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

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

  int i = n % 10;

  if (i == 3) {
    cout << "bon" << endl;
  } else if (i == 0 || i == 1 || i == 6 || i == 8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;
typedef long long ll;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;

        ll ret = 0;
        vector<vector<ll>> wantFront, wantBack;
        for (int i = 0; i < n; i++) {
            int k, l, r;
            cin >> k >> l >> r;
            if (l >= r) {
                ret += l;
                wantFront.push_back({k, l - r});
            } else {
                ret += r;
                wantBack.push_back({n - k, r - l});
            }
        }

        sort(wantFront.begin(), wantFront.end());
        int next = 0;
        priority_queue<ll, vector<ll>, greater<>> que;
        for (int place = 0; place <= wantFront.size(); place++) {
            while (next < wantFront.size() && (wantFront[next][0] <= place || place == wantFront.size())) {
                que.push(wantFront[next++][1]);
            }

            while (que.size() > place) {
                ret -= que.top();
                que.pop();
            }
        }

        sort(wantBack.begin(), wantBack.end());
        next = 0;
        que = priority_queue<ll, vector<ll>, greater<>>();
        for (int place = 0; place <= wantBack.size(); place++) {
            while (next < wantBack.size() && (wantBack[next][0] <= place || place == wantBack.size())) {
                que.push(wantBack[next++][1]);
            }

            while (que.size() > place) {
                ret -= que.top();
                que.pop();
            }
        }

        cout << ret << endl;
    }
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll a;
    long double b;
    cin>>a>>b;
    ll c=(b*100+0.5);
    cout <<a*c/100<<endl;
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define ROOP(i, N) for(int i=0; i++; i<N)
#define RVROOP(i, N) for(int i=N; i--; i>=0)
#define ALL(v) v.begin(), v.end()
const int INF = 1e9;
const int MAX = 510000;
const int MOD = 1000000007;
using namespace std;
typedef long long ll;

/*DP使ったほうがよくない？？WOWWOW*/

int main(){
  int N; cin>>N;
  cout<<N/2+N%2<<endl;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;

pair<string,int> P[101],Q[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>P[i].first>>P[i].second;
		Q[i]=P[i];
		P[i].second=-P[i].second;
	}
	sort(P,P+N);
	FOR(i,N) {
		P[i].second=-P[i].second;
		FOR(j,N) if(Q[j]==P[i]) cout<<j+1<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void warshall_floyd(long long n,vector<vector<long long>>& d) {
    for (long long k = 0; k < n; k++) {          // 経由する頂点
        for (long long i = 0; i < n; i++) {      // 始点
            for (long long j = 0; j < n; j++) {  // 終点
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}
int main() {
    ll h, w;
    cin >> h >> w;
    vector<vector<ll>> c(10);
    for (ll i = 0; i < 10; i++) {
        for (ll j = 0; j < 10; j++) {
            ll t;
            cin >> t;
            c[i].push_back(t);
        }
    }
    warshall_floyd(10, c);

    vector<vector<ll>> a(h);
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w;j++){
            ll s;
            cin >> s;
            a[i].push_back(s);
        }
    }
    ll ans = 0;
    for (ll i = 0; i < h; i++) {
        for (ll j = 0; j < w;j++){
            if (a[i][j] != -1) ans += c[a[i][j]][1];
        }
    }
    cout << ans << endl;
}


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


void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    Tuple!(long, long)[] B;
    long ans = 0;

    foreach (i; 0..N) {
        if (K >= A[i][0]) B ~= tuple(A[i][0], A[i][1]);
    }

    for (int b = bsr(K); b >= 0; --b) {
        long tmp = 0;
        Tuple!(long, long)[] C;
        bool k = (K & (1L << b)) > 0;
        if (k) {
            foreach (i; 0..B.length) {
                bool a = (B[i][0] & (1L << b)) > 0;
                if (!a) tmp += B[i][1];
            }
        } else {
            foreach (i; 0..B.length) {
                bool a = (B[i][0] & (1L << b)) > 0;
                if (!a) C ~= B[i];
            }
            B = C.dup;
        }
        ans = max(tmp, ans);
    }

    ans = max(ans, B.map!(b => b[1]).sum);
    ans.writeln;
}


Measured memory_bytes: 22908
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <iomanip>

typedef long long ll;
typedef long double ld;

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

#define rep(i, N) for (ll i = 0; i < (ll)(N); ++i)
#define ALL(a) (a).begin(),(a).end()

const ll inf = 1e18+7;
const ll mod = 1e9+7;

ll GetDigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ll k=100,l=0,ans=0;
    vector<ll> C(5,0);
    rep(i,5){
        cin >> C[i];
        if(C[i]%10!=0&&C[i]%10<k){
            k=C[i]%10;
            l=i;
        }
    }
    for(ll i=0;i<5;i++){
        if(i!=l){
            if(C[i]%10==0){
                ans+=C[i];
            }else{
                ans+=C[i]+(10-C[i]%10);
            }
        }
    }
    ans+=C[l];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 62;
constexpr auto mod = 1000000007;
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; }

int main() {
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    FOR(i, n)cin >> a[i] >> b[i];
    ll ans = 0, m = 0;
    for (int i = n - 1; i >= 0; i--) {
        a[i] += m;
        ll B = (a[i] / b[i] + (bool)(a[i] % b[i])) * b[i];
        ans += B - a[i];
        m += B - a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
/*
___ is a raging sadist.
*/

//Destroy all WA at test 2

#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define PI 3.14159265
const ll MOD = 1000 * 1000 * 1000 + 7;
const ll MOD1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        if (x<=100000000)
        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 






int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

    ll n,m,k;
    cin>>n>>m>>k;  

    char a[n][m];  ll total=0; ll how_many=0;

    For(i,0,n)
    {
        For(j,0,m)
        {
           cin>>a[i][j];
           if (a[i][j]=='#')
            how_many+=1;
        }
    }




    for(int i=0;i<=(int)(1<<n)-1;i++)
    {   
        vector <ll> rows;

        for(int k=0;k<n;k++)
        {
            if (i&(1<<k))
                rows.pb(k);
        }

        for(int j=0;j<=(int)(1<<m)-1;j++)
        {
            vector <ll> columns;

            for(int l=0;l<m;l++)
            {
                if (j&(1<<l))
                    columns.pb(l);
            }

    
                ll check[n][m];
                For(g,0,n)
                {
                    For(h,0,m)
                    check[g][h]=0;
                }

                 ll cnt=0;

                for(int s=0;s<siz(rows);s++)
                {
                    for(int q=0;q<m;q++)
                    {
                        if (a[rows[s]][q]=='#'&&check[rows[s]][q]==0)
                        {
                            check[rows[s]][q]=1;
                            cnt+=1;
                        }
                    }
                }

               // cout<<siz(rows)<<' '<<cnt<<endl;

                for(int s=0;s<siz(columns);s++)
                {
                    for(int q=0;q<n;q++)
                    {
                        if (a[q][columns[s]]=='#'&&check[q][columns[s]]==0)
                        {
                            check[q][columns[s]]=1;
                            cnt+=1;
                        }
                    }
                }

                //cout<<cnt<<endl;

                if (how_many-cnt==k)
                    total+=1;
        }
    }


    cout<<total;

return 0;
}

Measured memory_bytes: 3648
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 200005;
vector<int> G[N];
long long ans = 0;
int n;
void dfs(int u,int par){
	if (u < par) ans += 1LL * u * (par - u);
	else ans += 1LL * (u - par) * (n - u + 1);
	for (auto v : G[u]){
		if (v != par){
			dfs(v, u);
		}
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	up(i,1,n-1){
		int u,v; cin >> u >> v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	cout << ans;
}

Measured memory_bytes: 23916
#include<stdio.h>
#define MAX 100
#define INFTY 2001

int main(){
  int n, i, j, e, sum;
  int M[MAX][MAX];
  int u, v;
  int minv;
  int d[MAX];
  int p[MAX];
  int vis[MAX];

  scanf("%d", &n);

  for (i = 0; i< n; i++){
    for (j = 0; j < n; j++){
      scanf("%d", &e);
      if(e==-1) M[i][j] = INFTY;
      else M[i][j] = e;
    }
  }

  for (i = 0; i < n; i++){
    d[i] = INFTY;
    p[i] = -1;
    vis[i] = 0;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;
    for (i = 0; i < n; i++){
      if (minv > d[i] && !vis[i]){
        u = i;
        minv = d[i];
      }
    }
    if (u == -1) break;
    vis[u] = 1;
    for (v = 0; v < n; v++){
      if (!vis[v] && M[u][v] != INFTY){
        if (d[v] > M[u][v]){
          d[v] = M[u][v];
          p[v] = u;
        }
      }
    }
  }

  sum = 0;

  for (i = 0; i < n; i++){
    if (p[i] != -1) sum += M[i][p[i]];
  }

  printf("%d\n", sum);

  return 0;
}



Measured memory_bytes: 2088
n = gets.to_i
a = gets.split.map(&:to_i)

map =
  a.inject(Hash.new(0)) do |result, ai|
    result[ai] += 1 
    result
  end

ans = 0
map2, map3 = [], []
map.each do |k, v|
  if v >= 3
    map3 << [k, v]
  elsif v == 2
    map2 << k
  else
    ans += 1
  end
end

map3.each do |x|
  m = (x[1] - 3) % 2 + 1
  if m == 1
    ans += 1
  else
    map2 << x[0]
  end
end

ans += (map2.size / 2) * 2
puts ans



Measured memory_bytes: 14596
# -*- coding: utf-8 -*-
from sys import stdin

def Euclid(a,b):
    m = max(a,b)
    n = min(a,b)
    if m == n:
        return m
    else:
        return Euclid(n, m-n)

N, M = [int(x) for x in stdin.readline().rstrip().split()]
S = stdin.readline().rstrip()
T = stdin.readline().rstrip()
euc = Euclid(N,M)

if S[::N//euc] == T[::M//euc]:
    print((N * M) // euc)
else:
    print(-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 5LL << 60;
const ll mod = 1e9 + 7;

int main() {
	int N;
	cin >> N;
	int B[N];
	for(int i = 0; i < N; i++) cin >> B[i];

	int ans = B[0] + B[N - 2];
	for(int i = 1; i < N - 1; i++) {
		ans += min(B[i - 1], B[i]);
	}
	cout << ans;
	return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<int> x={};
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      x.push_back(0);
    }else if(s[i]=='1'){
      x.push_back(1);
    }else{
      if(x.size()>0){
        x.pop_back();
      }else{
        continue;
      }
    }
  }
  for(int i=0;i<x.size();i++){
    cout << x[i] ;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d,res1,res2,t,bcnn;
int main(){
    cin>>a>>b>>c>>d;
    bcnn=(c/__gcd(c,d))*d;
    t=a-1;
    res1=b-t;
    res2=(ll)(b/c)+(ll)(b/d)-(ll)(b/(bcnn))-((ll)(t/c)+(ll)(t/d)-(ll)(t/(bcnn)));
   cout<<res1-res2;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  if (N<105){
    cout << 0 << endl;
  }
  else if (N<135){
    cout << 1 << endl;
  }
  else if (N<165){
    cout << 2 << endl;
  }
  else if (N<189){
    cout << 3 << endl;
  }
  else if (N<195){
    cout << 4 << endl;
  }
  else {
    cout << 5 << endl;
  }
}

Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

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

  int n; cin >> n;
  int h[n]; rep(i, n) cin >> h[i];

  int dp[n + 5];
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < n; ++i){
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
  }

  print(dp[n - 1]);

  return 0;
}

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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n , m , k , t;
int a[MAXX];

int main()
{
    _FastIO;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> k;
        for(int j = 0; j < k; j++){
            cin >> t;
            a[t]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < 31; i++){
        if(a[i] == n)
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int n,x;

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

    int mi = 1000;
    int sum = 0;

    for (int i = 0; i < n; i++)
    {
        int m;
        cin>>m;
        sum += m;
        mi = min(mi,m);
    }
    
    cout << n + (x-sum)/mi << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int x=0,y=0,mxx=0,mxy=0,dx,dy,d=0;  
    while(cin>>dx>>dy){
      if(dx==0&&dy==0)break;
      x+=dx;
      y+=dy;
      int nd=x*x+y*y;
      if(d==nd&&mxx<x)mxx=x,mxy=y;
      if(d<nd)d=nd,mxx=x,mxy=y;
      
    }
    cout<<mxx<<' '<<mxy<<endl;
  }
  return 0;
}

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

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

	if (a == b && b == c) {
		cout << 1 << endl;
	}
	else if (a == b || b == c || c == a) {
		cout << 2 << endl;
	}
	else {
		cout << 3 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
#define vall(x) (x).begin(), (x).end()
using namespace std;
using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
template <class T1, class T2>
void vadd(vector<T1> &v, T2 x);

#define int long long int
int cnt[26][4000] = {};
void solve(long long N, std::string S)
{
  rep(i, N)
  {
    rep(j, 26)
    {
      cnt[j][i + 1] = cnt[j][i];
    }
    cnt[S[i] - 'A'][i + 1]++;
  }
  lli ret = 0;
  rrep(k, N) rep(j, k)
  {
    if (S[k] == S[j])
      continue;
    rep(i, 26) if (i != S[k] - 'A' && i != S[j] - 'A') ret += cnt[i][j + 1];
    int I = j - (k - j);
    //cout << k << " " << j << " " << ret << endl;
    if (I >= 0 && I != j && I != k)
    {
      if (S[I] == S[j] || S[I] == S[k])
        continue;
      ret--;
    }
  }
  cout << ret << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::string S;
  std::cin >> S;
  solve(N, S);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}

template <class T1, class T2>
void vadd(vector<T1> &v, T2 x)
{
  for (auto &s : v)
    s += T2(x);
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  string s, t; cin >> s >> t;
  for(int i=n; i>=0; i--) {
    string s_ = s.substr(n-i);
    string t_ = t.substr(0, i);
    if(s_ == t_) {
      cout << n*2-i << "\n";
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
    long long  W, H, x, y, r;
    cin>>W>>H>>x>>y>>r;
    if((x+r)>W || (x-r)<0 || (y+r)>H || (y-r)<0 || x<0 || y<0)
    cout<<"No";
    else cout<<"Yes";
    cout<<"\n";
    return 0;
}



Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int a,b,c,d;

int main() {
    cin >> a >> b >> c >> d;
    if (a+b>c+d) cout << "Left" << endl;
    else if (a+b==c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()


int main(){
    int n; cin>>n;
    V p(n);
    rep(i,0,n) cin>>p[i];
    sort(p.begin(),p.end());
    ll ans=0;
    rep(i,0,n-1) ans+=p[i];
    ans+=p[n-1]/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
# coding:utf-8

import sys
import itertools

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    A = [II() for _ in range(5)]
    k = II()

    judge = True
    for x, y in itertools.combinations(A, 2):
        if y - x > k:
            judge = False
            break

    return 'Yay!' if judge else ':('


print(main())


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

using namespace std;

const int N = 200005;

long long b[N], f[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  long long sum = 0;
  for (int i = 1; i < N; i++) {
    b[i] = (f[i] == 0) ? 0 : f[i] * (f[i] - 1) / 2;
    sum += b[i];
  }
  for (int i = 0; i < n; i++) {
    long long foo = f[a[i]] - 1;
    foo = (foo == 0) ? 0 : foo * (foo - 1) / 2;
    cout << sum - b[a[i]] + foo << '\n';
  }
  return 0;
}

Measured memory_bytes: 5504
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
int a[1000010];
struct Val{
	int pos,val;
	Val(int a=0,int b=0)
	{
		pos=a;
		val=b;
	}
};
bool operator <(const Val& a,const Val& b)
{
	return a.val>b.val;
}
priority_queue<Val>q;
int pre[2000010],nxt[2000010];
int f[2000010],g[2000010];
int sum1[2000010];
int sum2[2000010];
bool vis[2000010];
int main()
{
	long long ans=0;
	int n,L;
	scanf("%d %d",&n,&L);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		f[i]=g[i]=1;
		pre[i]=i-1;
		nxt[i]=i+1;
		q.push(Val(i,a[i]));
	}
	nxt[n]=0;
	int tot=n;
	while(!q.empty())
	{
		int pos=q.top().pos;
		q.pop();
		if(vis[pos])continue;
		int lpos=pos,rpos=pos;
		while(a[pre[lpos]]==a[pos])lpos=pre[lpos];
		while(a[nxt[rpos]]==a[pos])rpos=nxt[rpos];
		int cnt=0;
		int lst=0;
		for(int i=lpos;i!=nxt[rpos];i=nxt[i])
		{
			cnt++;
			if(i<=n)lst=cnt;
			sum1[cnt]=sum1[cnt-1]+f[i];
			sum2[cnt]=sum2[cnt-1]+g[i];
			vis[i]=true;
			if(lst&&cnt>=L)
				ans+=(long long)g[i]*sum1[min(lst,cnt-L+1)];
		}
		if(cnt<L){
			nxt[pre[lpos]]=pre[nxt[rpos]]=0;
			continue;
		}
		for(int i=1;i<cnt/L;i++)
		{
			nxt[tot+i]=tot+i+1;
			pre[tot+i+1]=tot+i;
		}
		for(int i=1;i<=cnt/L;i++)
			a[tot+i]=a[pos]+1;
		nxt[pre[lpos]]=tot+1;pre[tot+1]=pre[lpos];
		pre[nxt[rpos]]=tot+cnt/L;nxt[tot+cnt/L]=nxt[rpos];
		for(int i=1;i<=cnt/L;i++)
		{
			g[tot+i]=sum2[min((i+1)*L-1,cnt)]-sum2[i*L-1];
			int ii=cnt/L-i+1;
			f[tot+i]=sum1[cnt-ii*L+1]-sum1[max(cnt-(ii+1)*L+1,0)];
		}
		q.push(Val(tot+1,a[tot+1]));
		tot+=cnt/L;
		/*
		printf("current ans=%lld\n",ans);
		printf("a:");
		for(int i=nxt[0];i;i=nxt[i])
			printf(" %d",a[i]);
		printf("\nf:");
		for(int i=nxt[0];i;i=nxt[i])
			printf(" %d",f[i]);
		printf("\ng:");
		for(int i=nxt[0];i;i=nxt[i])
			printf(" %d",g[i]);
		printf("\n\n");
		*/
	}
	printf("%lld\n",ans+n);
	return 0;
}

Measured memory_bytes: 22768
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


const ll MOD = 998244353;

ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}

const int MX = 420000;
ll fc[MX], bfc[MX];

ll cnk(int n, int k) {
	return fc[n] * bfc[k] % MOD * bfc[n - k] % MOD;
}

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	int n;
	fc[0] = 1;
	for (int i = 1; i < MX; ++i)
		fc[i] = fc[i - 1] * i % MOD;
	for (int i = 0; i < MX; ++i)
		bfc[i] = pw(fc[i], MOD - 2);
	ll a, b, k;
	cin >> n;
	cin >> a >> b;
	cin >> k;
	ll ans = 0;
	for (ll c = 0; c <= n && c * a <= k; ++c) {
		ll d = (k - c * a) / b;
		if (d > n || c * a + d * b != k)
			continue;
		ans = (ans + cnk(n, c) * cnk(n, d)) % MOD;
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 6784
(defn coins [A,B,C,X](count (filter #(= X(reduce + %)) (for [a (map #(* 500 %) (range (inc A))) b (map #(* 100 %) (range (inc B))) c (map #(* 50 %) (range (inc C)))] [a b c]))))
(println (coins (bigint (read-line)) (bigint (read-line)) (bigint (read-line)) (bigint (read-line))))

Measured memory_bytes: 88860
#include<bits/stdc++.h>
using namespace std;
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define pb push_back
#define mp make_pair
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define in auto&it
#define out auto it
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
const double pi = acos(-1);
#define err(x) cerr<<#x<<" = "<<x<<'\n';
int main() {
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
		freopen("error.txt", "w", stderr);
	#endif
	fastio
	// double d,t,s;
	// cin>>d>>t>>s;
	// if(d/s<=t) cout<<"Yes";
	// else cout<<"No";
	
	string s,t;
	cin>>s>>t;
	int mi=INT_MAX;
	for(int i=0;i<s.size()-t.size()+1;++i){
		int cnt=0;
		for(int j=0;j<t.size();++j){
			if(s[i+j]!=t[j]) ++cnt;
		}
		mi=min(mi,cnt);
	}
	cout<<mi;
	return 0;
}

Measured memory_bytes: 3656
# 切り方は3通りです

# 1. 縦または横に大体三等分する
# 2. 縦または横に三分の一未満で最大切り取ったあと、
#   横または縦に大体二等分する
# 3. 縦または横に三分の一以上で最大切り取ったあと、
#   横または縦に大体二等分する


H, W = map(int, input().split())

if (H%3)*(W%3)==0:
  print(0)
else:
  d1 = min(H, W)
  ah = H//3
  h = H-ah
  d2 = abs(((W+1)//2)*h - ah*W)
  aw = W//3
  w = W-aw
  d3 = abs(((H+1)//2)*w - aw*H)
  ah = (H+2)//3
  h = H-ah
  d4 = abs((W//2)*h - ah*W)
  aw = (W+2)//3
  w = W-aw
  d5 = abs((H//2)*w - aw*H)

  print(min(d1,d2,d3,d4,d5))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,d;
  cin >> n >> d;
  int hani = d*2+1;
  int ac = n/hani;
  if(n%hani==0){
    cout << ac << endl;
  } else {
    cout << ac+1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main{

	static int []S;
	public static long sort(int s,int e)
	{
		if(e<=s)
			return 0;
		int mid=(s+e)/2;
		long ans=0;
		ans+=sort(s,mid);
		ans+=sort(mid+1,e);
		int []l=new int [mid-s+1];
		for(int i=0;i<l.length;i++)
			l[i]=S[i+s];
		int[] r=new int [e-mid];
		for(int i=mid+1;i<=e;i++)
		{
			r[i-(mid+1)]=S[i];
		}
		int i=0;
		int j=0;
		
		for(int k=s;k<=e;k++)
		{
			if(i==l.length)
				S[k]=r[j++];
			else if(j==r.length)
				S[k]=l[i++];
			else if(l[i]<=r[j])
			{
				ans+=r.length-j;
				S[k]=l[i++];
				
			}
			else
			{
				S[k]=r[j++];
				
			}
		}
		return ans;
		
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc=new Scanner(System.in);
		PrintWriter  out=new PrintWriter(System.out);
		int n=sc.nextInt();
		int []a=new int [n];
		int hi=0;
		for(int i=0;i<n;i++)
		{
			a[i]=sc.nextInt();
			hi=Math.max(hi,a[i]);
		}
		int lo=1;
		long min=(n*1L*(n-1)/2+n+1)/2;
		int ans=-1;
		// binary search on the greatest x such that the # of pairs(l,r) such that m(l,r) is >=x is>= (n*(n-1)/2)/2
		while(lo<=hi) 
		{
			int mid=(lo+hi)/2;
			
			
				
			S=new int [n+1];
			
			for(int i=1;i<=n;i++)
			{
				if(a[i-1]>=mid)
					S[i]=1;
				else
					S[i]=-1;
				S[i]+=S[i-1];
			}
			
			
			
			long inversions=sort(0,n);
			
			
			if(inversions>=min)
			{
				ans=mid;
				lo=mid+1;
			}
			else
				hi=mid-1;
					
		}
		out.println(ans);
		out.close();
	}
	
	
	static class Scanner {
        StringTokenizer st;
        BufferedReader br;
 
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }
 
        public Scanner(FileReader s) {
            br = new BufferedReader(s);
        }
 
        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }
 
        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }
 
        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }
 
        public String nextLine() throws IOException {
            return br.readLine();
        }
        public boolean ready() throws IOException {return br.ready();}
        public double nextDouble() throws IOException {return Double.parseDouble(next());}
       
    }

}

Measured memory_bytes: 145408