akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] arg) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        if(IntStream.rangeClosed(1,9)
                .filter(i->
                        IntStream.rangeClosed(1, 9)
                                .filter(j->i*j==N)
                                .findAny()
                                .isPresent()
                )
                .findAny()
                .isPresent()
        ){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        return;
    }
}


Measured memory_bytes: 27092
#include <bits/stdc++.h>
#define debug(x) cout << #x << " = " << x << '\n'

using ll = long long;
using namespace std;

const int MOD = 1e9 + 7;
const int N = 1010;
char grid[N][N];
int dp[N][N];

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

#ifdef LOCAL_DEFINE
	freopen("in.txt", "r", stdin);
#endif

	int n, m;
	cin >> n >> m;

	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> grid[i][j];

	dp[1][1] = 1;

	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (grid[i][j] == '#')
				continue;
			dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1];
			dp[i + 1][j + 1] %= MOD;
		}
	}

	cout << dp[n][m] << '\n';

	return 0;
}

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

vector<int> pre, in, post;
int preidx;

void func(int l, int r){
  if(r-l<1) return;
  //cout << l << " " << r << endl;
  //find pre[preidx] in in[begin:end]
  int mid = -1;
  for(int i = l; i < r; i++){
    if(in[i] == pre[preidx]){
      mid = i;
      break;
    }
  }
  assert(mid != -1);
  preidx++;
  if(mid != l){
    func(l, mid);
  }
  func(mid+1, r);
  post.push_back(in[mid]);
}

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

  int n; cin >> n;
  pre.resize(n);
  in.resize(n);
  post.clear();
  preidx = 0;

  for(int i = 0; i < n; i++) cin >> pre[i];
  for(int i = 0; i < n; i++) cin >> in[i];
  func(0, n);

  for(int i = 0; i < n; i++){
    cout << post[i];
    if(i == n-1) cout << endl;
    else cout << " ";
  }

  return 0;
}

Measured memory_bytes: 1224
A = int(input())
B = int(input())
C = int(input())
X = int(input())

count = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if a * 500 + b * 100 + c * 50 == X:
                count += 1

print(count)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
int main()
{
    int R;
    std::cin >> R;

    std::string ans = "AGC";
    if (R < 1200) {
        ans = "ABC";
    }
    else if (R < 2800) {
        ans = "ARC";
    }

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

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int main() {
   ll a, b;
   cin >> a >>b;
   if (a == 0||b==0) {
      puts("Zero");
      return 0;
   }

   if (a < 0 && b < 0) {
      ll cnt = abs(a - b) + 1;
      if (cnt&1LL) {
         puts("Negative");
      } else {
         puts("Positive");
      }
      return 0;
   }

   if (a < 0 && b > 0) {
      puts("Zero");
      return 0;
   }

   puts("Positive");

   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int sec,h,m,s;
	scanf("%d",&sec);
	h = (int)sec/3600;
	m = (int)(sec-h*3600)/60;
	s = sec-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}



Measured memory_bytes: 2108
// 1137
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int n; cin >> n;
    string s; cin >> s;
    int val = 0, x = 0;
    For(i, 0, n) {
        if(s[i] == 'I') {
            x++;
            if(x > val) val = x;
        }
        else {
            x--;
        }
    }
    cout << val;



    
    
    
    return 0;
}

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

using namespace std;

typedef tuple< int, int, int, int > S;

int main()
{
  int N, T[50], C[50];

  while(cin >> N, N) {
    for(int i = 0; i < N; i++) cin >> T[i] >> C[i];

    priority_queue< S, vector< S >, greater< S > > que;
    for(int i = 0; i < N; i++) que.emplace(0, T[i], C[i], 0);
    int mark[2] = {};
    while(!que.empty()) {
      int now, tim, cnt, line;
      tie(now, tim, cnt, line) = que.top();
      que.pop();
      if(cnt == 0) continue;
      line ^= 1;
      if(line == 0) --cnt;
      now = max(now + tim, mark[line]);
      mark[line] = max(mark[line], now);
      que.emplace(now, tim, cnt, line);
    }
    cout << mark[0] << endl;
  }
}

Measured memory_bytes: 3092
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

/*ここまでテンプレ*/

int N;
int num[4];
char Op[3];

bool dfs(int n, int sum)
{
	//3つとも決めたら判定
	if (n == 3) return sum == 7;

	//Op_nが+のとき
	if (dfs(n + 1, sum + num[n + 1])) return true;

	//Op_Nが-のとき
	if (dfs(n + 1, sum - num[n + 1])) return true;
}

void solve()
{
	int sum = num[0];

	for (int i = 0; i <= 2; i++)
	{
		if (dfs(i + 1, sum + num[i + 1]))
		{
			Op[i] = '+';
			sum += num[i + 1];
			continue;
		}
		else
		{
			Op[i] = '-';
			sum -= num[i + 1];
			continue;
		}
	}
}

/*ここからmain関数*/

int main()
{
	cin >> N;

	num[0] = N / 1000;
	num[1] = (N / 100) % 10;
	num[2] = (N / 10) % 10;
	num[3] = N % 10;

	solve();

	cout << num[0] << Op[0] << num[1] << Op[1] << num[2] << Op[2] << num[3] << "=7";

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX],n;

int Partition(int p,int r){
	int x=A[r],i=p-1,j,t;
	
	for(j=p;j<r;j++){
		if(A[j]<=x){
			t=A[++i]; A[i]=A[j]; A[j]=t;
		}
	}
	
	t=A[++i]; A[i]=A[r]; A[r]=t;
	
	return i; 
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&A[i]);
	
	int q=Partition(0,n-1);
	
	for(int i=0;i<n;i++){
		if(i) printf(" ");
		if(i==q) printf("[");
		printf("%d",A[i]);
		if(i==q) printf("]");
	}
	printf("\n");
	
	return 0;
}



Measured memory_bytes: 2976
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
//a<b
long pgcd(long a,long b){
  if(a==0)
    return b;
  else
    return pgcd(b%a,a);
}

long gcd(long a, long b){
  return pgcd(min(a,b), max(a,b));
}

int m,n;//blue,red
int c[500][500];
long b[500], r[500];
bool v[500];
int p[500];

bool match(int b){
  // printf("match b:=%d\n", b);
  if(b<0) return true;
  rep(j,n){
    if(!c[b][j] || v[j]) continue;
    // printf("v[%d]=true;\n",j);
    v[j]=true;
    if(match(p[j])) {
      p[j]=b;
      return true;
    }
  }
  return false;
}

int main(){
  while(scanf("%d %d", &m, &n),m+n) {
    rep(i,m) scanf(" %ld", b+i);
    rep(j,n) scanf(" %ld", r+j);
    
    rep(i,m) rep(j,n) c[i][j]=gcd(b[i],r[j]) > 1 ? 1 : 0;
    
    // rep(i,m) {
    //   rep(j,n) printf(c[i][j] ? " o" : " x");
    //   printf("\n");
    // }
    
    rep(j,n) p[j]=-1;
    
    int count=0;
    rep(i,m){
      // rep(j,n) printf("p[%d]=%d\n",j,p[j]);
      // printf("\n");
      rep(j,n) v[j]=false;
      if(match(i)) count++;
    }
    printf("%d\n",count);
  }
}

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

int main(){


  //入力値
  int a,b,w;
  //差
  int result;

  //入力
  cin>>w>>a>>b;

  //aよりbのほうが大きかった場合
  if(a<b){
    result = b - (a + w);
    //差が0以上の場合
    if(result>0)
      cout<<result<<endl;
    //差がない（連結している）場合
    else
      cout<<0<<endl;
  }
  //bよりaが大きい場合
  else{
    result = a - (b + w);
    //差が0以上の場合
    if(result>0)
      cout<<result<<endl;
    //差がない（連結している）場合
    else
      cout<<0<<endl;
  }

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int q;
    cin >> q;
    bool reverse = false;
    vector<char> front, end;
    for(int i = 0; i < q; i++){
        int t;
        cin >> t;
        if(t == 1){
            reverse = !reverse;
        } else if(t == 2){
            int f;
            cin >> f;
            char c;
            cin >> c;
            if(f == 1){
                if(reverse){
                    end.push_back(c);
                } else {
                    front.push_back(c);
                }
            } else if(f == 2){
                if(reverse){
                    front.push_back(c);
                } else {
                    end.push_back(c);
                }
            }
        }
    }
    if(reverse){
        for(vector<char>::reverse_iterator ritr = end.rbegin(); ritr != end.rend(); ritr++){
            cout << *ritr;
        }
        for(string::reverse_iterator ritr = s.rbegin(); ritr != s.rend(); ritr++){
            cout << *ritr;
        }
        for(vector<char>::iterator itr = front.begin(); itr != front.end(); itr++){
            cout << *itr;
        }
    } else {
        for(vector<char>::reverse_iterator ritr = front.rbegin(); ritr != front.rend(); ritr++){
            cout << *ritr;
        }
        cout << s;
        for(vector<char>::iterator itr = end.begin(); itr != end.end(); itr++){
            cout << *itr;
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
n = int(input())
ab = [list(map(int, input().split())) for x in range(n)]

cnt = 0
for a, b in reversed(ab):
    # diff = a - b + cnt
    # if diff < 0:
    #     cnt -= diff
    # else:
    a += cnt
    # diffb = diff % b
    # if diffb:
    #     cnt += b - diffb
    if a % b:
        cnt += b * (a // b + 1) - a
print(int(cnt))



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

int main() {
    int N, K, ans=0, d, tmp;
    cin >> N >> K;
    vector<int> a(N, 0);

    for(int i=0; i<K; i++){
	cin >> d;
	for(int j=0; j<d; j++){
	    cin >> tmp;
	    tmp--;
	    a[tmp]++;
	}
    }

    for(int i=0; i<N; i++){
	if(a[i]==0)
	    ans++;
    }

    cout << ans << endl;
} 




Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    long long ssum =0;
    long long wsum =0;
    double temp=0;
    double water;
    double sugar;
    for(int i=0;i<31;i++){
        for(int j=0;j<31;j++){
            for(int k=0;k<200;k++){
                for(int l=0;l<200;l++){
                    water = a*i*100+b*j*100;
                    if(water==0){
                        break;
                    }
                    sugar = c*k+d*l;
                    if((water+sugar<=f)&&(a*i+b*j)*e>=sugar){
                        double sw = sugar/(water+sugar);
                        if(sw>temp){
                            temp = sw;
                            
                            ssum = sugar;
                            wsum = water+sugar;
                            
                        }
                    }
                }
            }
        }
    }
    if(wsum==0){
        wsum = a*100;
    }
    cout << wsum << " " << ssum << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0) break;
			ArrayList<Stack<Integer>> pile = new ArrayList<Stack<Integer>>();
			for(int i = 0; i < n; i++){
				pile.add(new Stack<Integer>());
				pile.get(i).add(i + 1);
			}
			while(true){
				int from = sc.nextInt();
				int to = sc.nextInt();
				if((from|to)==0)break;
				int [] fromind = find(from, pile);
				int [] toind = find(to, pile);
				if(to == 0){
					if(fromind[1] == 0) continue;
					while(true){
						int num = pile.get(fromind[0]).pop();
						if(num == from){
							for(int i = 0; i < pile.size(); i++){
								if(pile.get(i).size() == 0){
									pile.get(i).add(num);
									break;
								}
							}
							break;
						}
						for(int i = 0; i < pile.size(); i++){
							if(pile.get(i).size() == 0){
								pile.get(i).add(num);
								break;
							}
						}
					}
				}
				else if(fromind[0] == toind[0]){
					if(fromind[1] >= toind[1]){
						//ok
					}
					else{
						while(true){
							int num = pile.get(fromind[0]).pop();
							if(num == from){
								for(int i = 0; i < pile.size(); i++){
									if(pile.get(i).contains(to)){
										pile.get(i).add(num);
										break;
									}
								}
								break;
							}
							for(int i = 0; i < pile.size(); i++){
								if(pile.get(i).size() == 0){
									pile.get(i).add(num);
									break;
								}
							}
						}
					}
				}
				else{
					while(true){
						int num = pile.get(fromind[0]).pop();
						if(num == from){
							for(int i = 0; i < pile.size(); i++){
								if(pile.get(i).contains(to)){
									pile.get(i).add(num);
									break;
								}
							}
							break;
						}
						for(int i = 0; i < pile.size(); i++){
							if(pile.get(i).size() == 0){
								pile.get(i).add(num);
								break;
							}
						}
					}
				}
			}
			ArrayList<Integer> pilesize = new ArrayList<Integer>();
			for(int i = 0; i < n; i++){
				if(pile.get(i).size() == 0)continue;
				pilesize.add(pile.get(i).size());
			}
			Collections.sort(pilesize);
			for(int size: pilesize){
				System.out.println(size);
			}
			System.out.println("end");
		}
	}

	private int[] find(int from, ArrayList<Stack<Integer>> pile) {
		for(int i = 0; i < pile.size(); i++){
			for(int j = 0; j < pile.get(i).size(); j++){
				if(pile.get(i).get(j) == from){
					return new int[]{i,j};
				}
			}
		}
		return null;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

Measured memory_bytes: 41860
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
int n,root;
int p[maxn],key[maxn];
int ch[maxn][2],val[maxn],mx[maxn],mn[maxn],good[maxn];
inline void upd(int x)
{
	mn[x]=val[x];
	mx[x]=val[x];
	good[x]=1;
	if(ch[x][0])
	{
		if((!good[ch[x][0]])||mx[ch[x][0]]>val[x])good[x]=0;
		if(good[x])
		{
			mn[x]=mn[ch[x][0]];
		}
		else
		{
			mn[x]=mn[ch[x][0]]<mn[x]?mn[ch[x][0]]:mn[x];
			mx[x]=mx[ch[x][0]]>mx[x]?mx[ch[x][0]]:mx[x];
		}
	}
	if(ch[x][1])
	{
		if(good[x]&&((!good[ch[x][1]])||val[x]>mn[ch[x][1]]))good[x]=0;
		if(good[x])
		{
			mx[x]=mx[ch[x][1]];
		}
		else
		{
			mn[x]=mn[ch[x][1]]<mn[x]?mn[ch[x][1]]:mn[x];
			mx[x]=mx[ch[x][1]]>mx[x]?mx[ch[x][1]]:mx[x];
		}
	}
}
inline int merge(int p,int q)
{
//	cout<<"merge "<<p<<" "<<q<<endl;
	if(!p||!q)return p+q;
	if(key[p]>key[q])
	{
		ch[p][1]=ch[p][1]?merge(ch[p][1],q):q;
		upd(p);
		return p;
	}
	else
	{
		ch[q][0]=ch[q][0]?merge(p,ch[q][0]):p;
		upd(q);
		return q;
	}
}
inline void upd2(int x)
{
	mn[x]=ch[x][0]?mn[ch[x][0]]:val[x];
	mx[x]=ch[x][1]?mx[ch[x][1]]:val[x];
	good[x]=1;
}
inline int merge2(int p,int q)
{
//	cout<<"merge "<<p<<" "<<q<<endl;
	if(!p||!q)return p+q;
	if(key[p]>key[q])
	{
		ch[p][1]=ch[p][1]?merge2(ch[p][1],q):q;
		upd2(p);
		return p;
	}
	else
	{
		ch[q][0]=ch[q][0]?merge2(p,ch[q][0]):p;
		upd2(q);
		return q;
	}
}
inline pii solve(int x,int bound)
{
	if(!x)return make_pair(0,0);
//	cout<<"solve "<<val[x]<<" "<<bound<<" "<<mx[x]<<" "<<good[x]<<endl;//system("pause");
	if(mx[x]<bound)return make_pair(0,x);
	pii res;
	if(good[x])
	{
		if(mn[x]>bound)return make_pair(x,0);
		
		if(!ch[x][0]||(bound>val[x]))
		{
			res=solve(ch[x][1],bound);
			ch[x][1]=0;
			if(ch[x][0])upd2(x);
			else
			{
				mn[x]=mx[x]=val[x];
				good[x]=1;
			}
			res.second=merge(x,res.second);
			return res;
		}
		else
		{
			res=solve(ch[x][0],bound);
			ch[x][0]=0;
			upd2(x);
			res.first=merge2(res.first,x);
			return res;
		}
	}
	pii lft=solve(ch[x][0],bound);
	if(lft.first)bound=mx[lft.first];
	int rson=ch[x][1];
	ch[x][0]=ch[x][1]=0;
	upd(x);
	if(val[x]>bound)
	{
		lft.first=merge2(lft.first,x);
		bound=val[x];
	}
	else
	{
		lft.second=merge(lft.second,x);
	}
	pii rht=solve(rson,bound);
	return make_pair(merge2(lft.first,rht.first),merge(lft.second,rht.second));
}
vector<int> a;
int main()
{
	scanf("%d",&n);
/*	n=200000;
	a.resize(n);
	for(int i=0;i<n;i++)a[i]=i+1;
	random_shuffle(a.begin(),a.end());
	for(int i=1;i<=n;i++)p[i]=a[i-1];*/
	for(int i=1;i<=n;i++)scanf("%d",&p[i]);
	for(int i=1;i<=n;i++)
	{
		val[i]=p[i];
	//	cout<<p[i]<<endl;
		mx[i]=mn[i]=p[i];
		good[i]=1;
		key[i]=rand();
		root=merge(root,i);
	//	cout<<root<<endl;
	}
//	cout<<"here\n";
//	cout<<val[root]<<endl;
	int turn=0;
	pii res;
	while(!good[root])
	{
		turn++;
	//	if(turn%10000==0)cout<<turn<<endl;
		res=solve(root,0);
	//	system("pause");
		root=merge(res.second,res.first);
	}
	printf("%d\n",turn);
	return 0;
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		double d = sc.nextDouble();
		double xy[][] = new double[2][n];
		int count=0;

		for(int i=0;i<n;i++) {
			xy[0][i]=sc.nextInt();
			xy[1][i]=sc.nextInt();
		}

		for(int i=0;i<n;i++) {
			if(Math.sqrt((xy[0][i]*xy[0][i])+(xy[1][i]*xy[1][i]))<=d) {
				count++;
			}
		}
			System.out.println(count);




	}

}

Measured memory_bytes: 64236
# 2019/09/09

from itertools import accumulate

n=int(input())
a=sorted(list(map(int,input().split())))

acc=[0]+list(accumulate(a))
acc.pop()
acc.pop()
cnt=1
next=a.pop()

while a and acc:
    aa=a.pop()
    ac=acc.pop()
    if (aa+ac)*2>=next:
        cnt+=1
    else:break
    next=aa

print(cnt)

Measured memory_bytes: 14428
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    deque<char> dq;
    string S;
    cin >> S;
    REP(i,S.size()) dq.push_back(S[i]);
    int Q;
    cin >> Q;
    bool flg = true;//先頭
    while(Q--){
        int T;
        cin >> T;
        if(T == 1){
            flg ^= 1;
        }
        else{
            int F;
            char C;
            cin >> F >> C;
            if(F == 1){
                if(flg) dq.push_front(C);
                else dq.push_back(C);
            }
            else{
                if(flg) dq.push_back(C);
                else dq.push_front(C);
            }
        }
        //cout << Q << " " << dq.size() << endl;
    }
    while(!dq.empty()){
        if(flg){
            cout << dq.front();
            dq.pop_front();
        }
        else{
            cout << dq.back();
            dq.pop_back();
        }
    }
    cout << endl;
}

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

int main(void){
    int h, w;
    int H, W;

    cin >> H >> W >> h >> w;

    int count = 0;
    rep(i, H - h)
        rep(j, W - w)
            count++;
    cout << count << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main(void){
    string input;
    
    while(getline(cin, input), !cin.eof()){
        int a, b;
        int d, r;
        double f;
        
        sscanf(input.c_str(), "%d %d\n", &a, &b);
        
        d = a / b;
        r = a % b;
        f = (double)a / (double)b;
        
        printf("%d %d %lf\n", d, r, f);
    }
    return(0);
}



Measured memory_bytes: 3292
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long int ll;

bool isIt753(ll num){
	if(num == 0){
		return false;
	}
	bool threeUsed = false;
	bool fiveUsed = false;
	bool sevenUsed = false;
	ll a = num % 10;
	num = num / 10;
	while( a != 0){
		if( a == 3){
			threeUsed = true;
		}else if( a == 5){
			fiveUsed = true;
		}else if( a == 7){
			sevenUsed = true;
		}else{
			return false;
		}
		a = num % 10;
		num = num / 10;
	}
	return threeUsed & fiveUsed & sevenUsed;
}

int count753(ll num,ll n){
	if( num > n) return 0;
	int sum = 0;
	sum += count753( num*10 + 3,n);
	sum += count753( num*10 + 5,n);
	sum += count753( num*10 + 7,n);
	if( isIt753(num) == true) sum++;
	return sum;
}

int main()
{
	ll n;
	cin>>n;
	ll num = 0;
	cout<<count753(num,n)<<endl;
	return 0;
}



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

using namespace std;

int main() {
    string s;
    bool flag = false;

    while (cin >> s) {
        int sz = s.size();
        if (s[sz - 1] == ',' || s[sz - 1] == '.') s = s.substr(0, (sz--) - 1);
        if (sz >= 3 && sz <= 6) {
            if (flag) cout << " ";
            cout << s;
            flag = true;
        }
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3196
#!/usr/bin/env python3
import bisect

def main():
    na = list(map(int, input().split()))
    N, M, X = na[0], na[1],na[2]
    A = list(map(int, input().split()))

    i = bisect.bisect_left(A, X)

    print(min(i, M - i))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<stack>
#include<cstdlib>
using namespace std;

int main(){
	string word;
	stack<int> S;
	int a,b;
	while(cin >> word){
		if (word == "+"){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(a+b);
		}
		else if (word == "-"){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(b-a);
		}
		else if (word == "*"){
			a = S.top();
			S.pop();
			b = S.top();
			S.pop();
			S.push(b*a);
		}
		else{
			a = atoi(word.c_str());
			S.push(a);
		}
	}
	a = S.top();
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1204
S = list(input())
f = True
for i in range(len(S)):
    if i % 2 == 0:
        if S[i] == "L":
            f = False
    elif i % 2 != 0:
        if S[i] == "R":
            f = False
if f:
    print("Yes")
else:
    print("No")

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

int main()
{
    int x, a, b;

    cin >> x >> a >> b;

    if(abs(x - a) < abs(x - b)) {
        cout << "A" << endl;
    } else {
        cout << "B" << endl;
    }

    return (0);
}


Measured memory_bytes: 256
a = gets.to_i
b = gets.to_i
c = gets.to_i
d = gets.to_i
e = gets.to_i

candidate = []
[a,b,c,d,e].permutation(5).to_a.each do | abcde |
  sum = 0
  abcde.each_with_index do | n, i |
    sum += n
    if i != 4 and sum%10 != 0
      sum = sum + (10-sum%10)
    end
  end
  candidate << sum
end

p candidate.min

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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int H, W, K;
string C[10];
bool fh[7], fw[7];

int main() {
    cin >> H >> W >> K;
    rep(i, H) cin >> C[i];
    // bit
    int ans = 0;
    for (int b=0; b<(1<<(H+W)); ++b) {
        rep(i, 7) fh[i] = fw[i] = false;
        for (int h = 0; h < H; ++h) {
            if ((b >> h) & 1) {
                fh[h] = true;
            }
        }
        for (int w = H; w < H + W; ++w) {
            if ((b >> w) & 1) {
                fw[w-H] = true;
            }
        }

        int cnt = 0;
        for (int r = 0; r < H; ++r) {
            for (int c = 0; c < W; ++c) {
                if (!fh[r] and !fw[c] and C[r][c] == '#') {
                    cnt++;
                }
            }
        }
        if (cnt == K) {
            //bitset<10> ok(b);
            //cout << ok << endl;
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,t;
  cin >> n >> t;
  int ans = MOD;
  rep(i,n){
    int cost,time;
    cin >> cost >> time;
    if(time <= t) ans = min(ans,cost);
  }
  if(ans == MOD) cout << "TLE" << endl;
  else cout << ans << endl;
}



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

int main(){
    ll N,M;
    cin >> N >> M;
    if (N == 1 && M == 1){
        cout << 1 << endl;
    }
    else if (N == 1){
        if (M >= 3){
            cout << M - 2 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else if (M == 1){
        if (N >= 3){
            cout << N - 2 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }
    else if (M == 2 || N == 2){
        cout << 0 << endl;
    }
    else{
        cout << (M - 2) * (N - 2) << endl;
    }
}



Measured memory_bytes: 256
n, k, q = list(map(int, input().split()))
a = [int(input()) for _ in range(q)]
score = [k] * n
for i in range(q):
    score[a[i]-1] += 1
for i in range(n):
    score[i] -= q
for i in range(n):
    if score[i] <= 0:
        print('No')
    else:
        print('Yes')


Measured memory_bytes: 11776
import java.util.*;import java.io.*;import java.math.*;
public class Main
{
    public static void process()throws IOException
    {
        int N=ni();
        int M=ni();
        if(N==M)
            pn("Yes");
        else
            pn("No");
    }
 
    static AnotherReader sc;
    static PrintWriter out;
    public static void main(String[]args)throws IOException
    {
        boolean oj = true;
        if(oj){sc=new AnotherReader();out=new PrintWriter(System.out);}
        else{sc=new AnotherReader(100);out=new PrintWriter("output.txt");}
        int t=1;
        // t=ni();
        while(t-->0) {process();}
        out.flush();out.close();  
    }
 
    static void pn(Object o){out.println(o);}
    static void p(Object o){out.print(o);}
    static void pni(Object o){out.println(o);out.flush();}
    static int ni()throws IOException{return sc.nextInt();}
    static long nl()throws IOException{return sc.nextLong();}
    static double nd()throws IOException{return sc.nextDouble();}
    static String nln()throws IOException{return sc.nextLine();}
    static int[] nai(int N)throws IOException{int[]A=new int[N];for(int i=0;i!=N;i++){A[i]=ni();}return A;}
    static long[] nal(int N)throws IOException{long[]A=new long[N];for(int i=0;i!=N;i++){A[i]=nl();}return A;}
    static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);}
    static int bit(long n)throws IOException{return (n==0)?0:(1+bit(n&(n-1)));}
 
/////////////////////////////////////////////////////////////////////////////////////////////////////////
 
    static class AnotherReader{BufferedReader br; StringTokenizer st;
    AnotherReader()throws FileNotFoundException{
    br=new BufferedReader(new InputStreamReader(System.in));}
    AnotherReader(int a)throws FileNotFoundException{
    br = new BufferedReader(new FileReader("input.txt"));}
    String next()throws IOException{
    while (st == null || !st.hasMoreElements()) {try{
    st = new StringTokenizer(br.readLine());}
    catch (IOException  e){ e.printStackTrace(); }}
    return st.nextToken(); } int nextInt() throws IOException{
    return Integer.parseInt(next());}
    long nextLong() throws IOException
    {return Long.parseLong(next());}
    double nextDouble()throws IOException { return Double.parseDouble(next()); }
    String nextLine() throws IOException{ String str = ""; try{
    str = br.readLine();} catch (IOException e){
    e.printStackTrace();} return str;}}
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
}

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

int main() {
	char b;
  	cin >> b ;
  
  	if(b == 'A') cout << 'T' << endl;
  	if(b == 'T') cout << 'A' << endl;
  	if(b == 'C') cout << 'G' << endl;
  	if(b == 'G') cout << 'C' << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int k = sc.nextInt();
		String s = sc.next();
		
		if(s.length() <= k) {
			System.out.println(s);
		}else {
			for(int i = 0; i < k; i++) {
				System.out.print((char)s.charAt(i));
			}
			System.out.println("...");
		}
	}
	
}


Measured memory_bytes: 27068
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n;
  cin>>n;
  if(n>=400&&n<=599)
    cout<<"8"<<endl;
  else if(n>=600&&n<=799)
    cout<<"7"<<endl;
  else if(n>=800&&n<=999)
    cout<<"6"<<endl;
  else if(n>=1000&&n<=1199)
    cout<<"5"<<endl;
  else if(n>=1200&&n<=1399)
    cout<<"4"<<endl;
  else if(n>=1400&&n<=1599)
    cout<<"3"<<endl;
  else if(n>=1600&&n<=1799)
    cout<<"2"<<endl;
  else if(n>=1800&&n<=1999)
    cout<<"1"<<endl;
    
	return 0;
}

Measured memory_bytes: 3672
# import itertools
n, m = map(int, input().split())
s = []
for i in range(m):
    s.append(list(map(int, input().split())))
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    b = list(str(bin(i))[2:].zfill(n))
    # print(b)
    ok = True
    for j in range(m):
        Sum = 0
        for k in range(s[j][0]):
            Sum += int(b[s[j][k+1] - 1])
        # print(i, j, Sum)
        if Sum % 2 != p[j]:
            ok = False
    if ok:
        ans += 1
print(ans)        
# print(s, p)

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

int INF=1e9;

void dijkstra(int a,int b,int *mindist,int cost[101][101],bool *used,int n){
  
  int cur,cur_spot;
  
  for(int i=0 ; i < 101 ; i++){
    mindist[i]=INF;
    used[i]=0;
  }
  
  mindist[a]=0;
  
  for(int _=0 ; _ < n ; _++){
    cur=INT_MAX;
    for(int i=1 ; i <= n ;i++){
      if(mindist[i] <= cur && used[i] == 0){
	cur = mindist[i];
	cur_spot=i;
      }
    }
    
    used[cur_spot]=1;
    
    for(int i=1 ; i <= n ; i++){
      if(cost[cur_spot][i] != -1){
	if(mindist[i] > mindist[cur_spot]+cost[cur_spot][i]){
	  mindist[i]=mindist[cur_spot]+cost[cur_spot][i];
	}
      }
    }
  }
  
  if(mindist[b] != INF){
    cout <<mindist[b]<<endl;
  }else{
    cout <<"-1"<<endl;
  }

}
int main(){
  
  int n,k,mindist[101],a,b,c,d,e,first;
  int cost[101][101];
  bool used[101];
  
  while(1){
  
    cin >>n>>k;
    if( n == 0 && k == 0)break;
    
    for(int i=0 ; i < 101 ; i++){
      for(int j=0 ; j < 101 ; j++){
	cost[i][j]= -1;
      }
    }
    
    for(int i=0 ; i < k ; i++){
      
      cin >>first;
      
      if(first == 0){
	cin >>a>>b;
	dijkstra(a,b,mindist,cost,used,n);
      }else{
	cin >>c>>d>>e;
	if(cost[c][d] > e || cost[c][d] == -1){
	   cost[c][d]=e;
	   cost[d][c]=e;
	}
      }
    }
    
  }
  return 0;
}

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

const int MAXN = 1E5+2;

int n, m, v, p;
vector<int> a(MAXN, 0), s(MAXN, 0);

signed main(){
	cin >> n >> m >> v >> p;
	for(int i=1; i<= n; ++i){
		cin >> a[i];
	}
	sort(a.begin()+1, a.begin()+n+1);
	for(int i=1; i<= n; ++i) s[i] = s[i-1] + a[i];
	int ans = p;
	for(int i=1; i<= n-p; ++i){
		int lower = upper_bound(a.begin()+1, a.begin()+n+1, a[i]) - a.begin()-1;
		if(lower > n-p) ++ans;
		else{
			if(v <= p-1 + lower){
				if(a[i]+m >= a[n-p+1]) ++ans;
			}
			else{
				int cur = (a[i]+m)*(n-p-lower+1) - (s[n-p+1] - s[lower]) - (v-p-lower+1)*m;
				if(a[i]+m >= a[n-p+1] && cur >= 0) ++ans;
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
using namespace std;
int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if((a&b&1) && ((c^d)&1)){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <bitset>
#include <list>
#include <cmath>
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int even = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a.at(i);
		if (a.at(i) % 2 == 0) {
			even++;
		}
	}

	cout << pow(3, n) - pow(2, even) << endl;

	return 0;
}

Measured memory_bytes: 512
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var a = input[1].split(' ');
    a = a.map(str => parseInt(str, 10));
    var b = input[2].split(' ');
    b = b.map(str => parseInt(str, 10));
    var c = input[3].split(' ');
    c = c.map(str => parseInt(str, 10));

    var sp = 0;
    var eat = 0;

    for(var i = 0; i < n; i++){
        eat = a[i];
        sp += b[eat-1];
        sp += ((i < n-1) && (a[i] + 1 == a[i+1])) ? c[eat-1] : 0;
    }

    console.log(sp);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){
	
	int a,b; //a:street going north and south, b:street going east and west
	
	while(std::cin >> a >> b){
		
		if(a == 0 && b == 0) break;
		
		int n; // number of junction under construction
		std::cin >> n;
		
		std::vector<std::vector<int>> junction(b, std::vector<int>(a,0));

		for(int i=0; i<n; ++i){
			int x,y;  //junction under construction
			std::cin >> x >> y;
			junction[y-1][x-1] = -1;
		}
		
		// count school road
		junction[0][0] = 1;
		for(int i=0; i<b; ++i){
			for(int j=0; j<a; ++j){
				if( junction[i][j] != -1){
					if(i != 0 && junction[i-1][j] != -1){ //row
						junction[i][j] += junction[i-1][j];
					}
					if(j != 0 && junction[i][j-1] != -1){ //col
						junction[i][j] += junction[i][j-1];
					}
				}
			}
		}
		
		/* check
		for(auto row_it = junction.begin(); row_it != junction.end(); ++row_it){
			for(auto col_it = row_it->begin(); col_it != row_it->end(); ++col_it){
				std::cout << *col_it << std::endl;
			}
		}
		*/
		
		std::cout << junction[b-1][a-1] << std::endl;
	}
	
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define all(v)   v.begin(), v.end()
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define Th third
#define START cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
#define isOdd(n)    (n&1)
#define LLMAX LLONG_MAX
#define LLMIN LLONG_MIN
#define IMN INT_MIN
#define IMX INT_MAX
#define pow(n, m) power((ll)n, (ll)m)
#define numOfDigits(n)  ((n)? (ll)(log10(n))+1 : 1)
#define mem(x, val)    memset(x, val, sizeof(x)) //be careful
#define MOD 1000000007

typedef long long ll;
typedef long double ld;
typedef double dd;
typedef pair<int, int> pii;

const ll N = 105, M = 1e5, INF = 1e13;
int n, cap;
int v[N], w[N];
ll dp[N][M + 5];
ll solve(int i, int rem){
    if(rem<0) return INF;
    if(i==n) return (rem==0?0:INF);

    ll &ret = dp[i][rem];
    if(~ret) return ret;
    ret = min(solve(i+1, rem), w[i] + solve(i+1, rem - v[i]));

    return ret;
}
int main()
{
    START
    //freopen("test cases\\.txt", "r", stdin) ;
    cin>>n>>cap;
    for(int i =0; i<n; i++){
        cin>>w[i]>>v[i];
    }
    mem(dp, -1);
    for(int i =1e5; i>=0; i--){//trying all sums and take the maximum possible one
        ll ans = solve(0, i);
        if(ans<=cap)
            return cout<<i, 0;
    }
	return 0;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

ll f(ll k, vector<ll>& a, int n) {
  ll ans=0;
  rep(i,n) {
    ans+=a[i]^k;
  }
  return ans;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  ll K;
  cin>>n>>K;
  vector<ll> a(n);
  rep(i,n)cin>>a[i];
  ll ans=0;
  K+=1;
  rep(i,41) {
    if(!(K&(1LL<<i)))
      continue;
    ll tmp=0;
    rep(j,41) {
      ll mask=1LL<<j;
      ll one=0;
      rep(k,n) {
        if(mask&a[k])
          one++;
      }
      if(i>j) {
        tmp+=max(one,n-one)*mask;
      } else if(j==i) {
        tmp+=one*mask;
      } else { // j>i
        if(mask&K) {
          tmp+=(n-one)*mask;
        } else {
          tmp+=one*mask;
        }
      }
    }
    ans=max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  if(n%10==3){
    cout << "bon" << endl;
  }else if(n%10==0||n%10==1||n%10==6||n%10==8){
    cout << "pon" << endl;
  }else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3636
x, y = map(int, input().split())
scores = [300000, 200000, 100000]
ans = 0
if x <= 3:
    ans += scores[x - 1]
if y <= 3:
    ans += scores[y - 1]
if x == 1 and y == 1:
    ans += 400000
print(ans)

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

int main(void)
{
	int testcase;
	cin >> testcase;
	while (testcase--){
		int money, year, n;
		int ret = 0;
		cin >> money >> year >> n;
		while (n--){
			int type, charge, tmp = money;
			long double per;
			cin >> type >> per >> charge;
			// 単利
			if (type == 0){
				int a = 0;
				for (int i = 0; i < year; i++){
					a += floor((tmp * per));
					tmp -= charge;
				}
				ret = max(ret, a + tmp);
			}
			// 複利
			else {
				for (int i = 0; i < year; i++){
					tmp += floor((tmp * per));
					tmp -= charge;
				}
				ret = max(ret, tmp);
			}
		}
		cout << ret << endl;
	}

	return 0;
}

Measured memory_bytes: 1236
n,m = map(int,input().split())
h = [int(i) for i in input().split()]
ab = [[int(i) for i in input().split()] for j in range(m)]

li = [1 for i in range(n)]

ans = 0
for i in range(m):
    if h[ab[i][0]-1] > h[ab[i][1]-1]:
        li[ab[i][1]-1] = 0
    elif h[ab[i][0]-1] < h[ab[i][1]-1]:
        li[ab[i][0]-1] = 0
    else:
        li[ab[i][1]-1] = 0
        li[ab[i][0]-1] = 0

ans = 0
for i in li:
    ans += i
print(ans)
    




Measured memory_bytes: 30368
from operator import itemgetter

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(m)], key=itemgetter(1))
removed = -1
ans = 0

for a, b in ab:
    # a が removed より大きい = まだ取り除いてない
    if a > removed:
        removed = b - 1
        ans += 1

print(ans)

Measured memory_bytes: 29920
def main():
    A, B = [int(x) for x in input().split()]
    if B == 1:
        print(0)
        return
    count = 1
    B -= A
    while B > 0:
        B -= (A - 1)
        count += 1
    print (count)

if __name__ == "__main__":
    main()


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

using namespace std;

int main() {

    int a, b, c, d, e;
    int sa, sb, sc, sd, se, mins;
    cin >> a >> b >> c >> d >> e;

    sa = a % 10;
    mins = sa;
    sb = b % 10;
    if(mins == 0){
        mins = sb;
    }else if( sb == 0){
        
    }else{
        mins = (sb < mins ? sb : mins);
    }
    
    sc = c % 10;
    if(mins == 0){
        mins = sc;
    }else if( sc == 0){
        
    }else{
        mins = (sc < mins ? sc : mins);
    }

    sd = d % 10;
    if(mins == 0){
        mins = sd;
    }else if( sd == 0){
        
    }else{
        mins = (sd < mins ? sd : mins);
    }

    se = e % 10;
    if(mins == 0){
        mins = se;
    }else if( se == 0){
        
    }else{
        mins = (se < mins ? se : mins);
    }

    a /= 10; 
    a *= 10;
    if(sa != 0) a += 10;
    b /= 10;
    b *= 10;
    if(sb != 0) b += 10;
    c /= 10;
    c *= 10;
    if(sc != 0) c += 10;
    d /= 10;
    d *= 10;
    if(sd != 0) d += 10;
    e /= 10;
    e *= 10;
    if(se != 0) e += 10;

    if( mins == 0){
        cout << (a + b + c +d + e) << endl;
    }else{
        cout << (a + b + c + d + e) - (10 - mins) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
(defun max-value ()
  (let ((n (read))
        (a-sum 0)
        (b nil))
    (dotimes (i (1- n))
      (setf b (cons (read) b)))
    (setf a-sum (+ a-sum (car b) (nth (- n 2) b)))
    (dotimes (i (- n 1))
      (unless (= i 0)
        (setf a-sum (+ a-sum (min (nth (1- i) b) (nth i b))))))
    (format t "~a" a-sum)))

(max-value)

Measured memory_bytes: 13288
N = int(input())
A = list(map(int, input().split()))
L = 0
AS = []
for i in A:
  L += i
  AS.append(L)
R = L
for i in range(N-1):
  X = AS[i]
  Y = L - X
  R = min(R,abs(X - Y))
print(R)

Measured memory_bytes: 26024
#include<stdio.h>

int main()
{
    int n,i;

    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(i%3==0)printf(" %d",i);
        else
        {
            int s=i;
            while(s)
            {
                if(s%10==3)
                {
                    printf(" %d",i);
                    break;
                }
                s/=10;
            }
        }
    }
    printf("\n");
    return 0;
    }



Measured memory_bytes: 2104
import bisect
import collections
import functools
import heapq
import math
import sys
from collections import deque
from collections import defaultdict
input = sys.stdin.readline
MOD = 10**9+7

kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

N,K = map(int,(input().split()))
a = list(map(int,(input().split())))
a.sort()
ans = 0
for i in range(1,N-K+2):
    ans += (a[-i] - a[i-1]) * nCr(N-i,K-1)
    ans %= MOD

print(ans)

Measured memory_bytes: 59944
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <algorithm>
#define lson l, m, rt<<1
#define rson m+1, r, rt<<1 |1
#define lowbit(x) x&(-x)
#define LL long long
using namespace std;
const int maxn = 1e5;
struct node
{
    int v, c;
    bool operator< (const node& tmp) const {
        return v > tmp.v;
    }
}a[maxn+10];
map<int, int>has;

int main()
{
    int n, cnt, num;
    LL ans;
    while(~scanf("%d", &n)) {
        cnt = 0;
        has.clear();
        for(int i = 0;i < n;i++) {
            scanf("%d", &num);
            if(has.count(num) == 0) {
                a[++cnt].v = num;
                a[cnt].c = 0;
                has[num] = cnt;
            }
            a[has[num] ].c ++;
        }
        sort(a+1, a+cnt+1);
        ans = 1;
        num = 0;
        for(int i = 1;i <= cnt && num < 2;i++) {
            //printf("i %d, v %d, c %d\n", i, a[i].v, a[i].c);
            if(a[i].c >= 2) {
                a[i].c -= 2;
                ans *= a[i].v;
                num ++;
                if(num < 2 && a[i].c >= 2) {
                    ans *= a[i].v;
                    num ++;
                }
            }
        }
        printf("%lld\n", num==2?ans:0);
    }
    return 0;
}
/*
6
3 1 2 4 2 1
4
1 2 3 4
10
3 3 3 3 4 4 4 5 5 5
*/


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <random>
#include <unordered_map>
#include <unordered_set>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef complex<ld> com;
constexpr int inf = 1000000010;
constexpr ll INF = 1000000000000000010;
constexpr ld eps = 1e-12;
constexpr ld pi = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }


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

	ll n;
	cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		ll c = n / i;
		ans += c * (c + 1) / 2 * i;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 3652
N = int(input())
A = [0] *N
B = [0]*N
for i in range(N):
    a, b = map(int,input().split())
    A[i] = a
    B[i] = b
A = sorted(A)
B = sorted(B)
if N %2 ==1:
    M = (N+1)//2
    left = A[M-1]
    right = B[-M]
    ans = right - left +1
else:
    M1 = N//2
    M2 = M1+1
    left1 = A[M1-1]
    right1 =B[-M1]
    left2 = A[M2-1]
    right2  =B[-M2]
    ans = right2 + right1 -left1-left2+1
print(ans)


Measured memory_bytes: 85292