akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int N;
int A[1 << 18], B[1 << 18];

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

	vector<int> V1, V2;
	for (int i = 1; i <= N; i++) V1.push_back(A[i]);
	for (int i = 1; i <= N; i++) V2.push_back(B[i]);
	sort(V1.begin(), V1.end());
	sort(V2.begin(), V2.end());

	int S1 = V1[N / 2]; if (N % 2 == 0) S1 = V1[N / 2] + V1[(N - 2) / 2];
	int S2 = V2[N / 2]; if (N % 2 == 0) S2 = V2[N / 2] + V2[(N - 2) / 2];
	cout << S2 - S1 + 1 << endl;
	return 0;
}

Measured memory_bytes: 7176
loop do
  n, m = gets.split.map(&:to_i)
  if n == 0 && m == 0 then
  	break
  end
  table = (1..n).to_a
  del = m - 1
  while table.size > 1 do
  	table.delete_at(del)
  	del += m - 1
  	while del >= table.size do
  	  del -= table.size
    end
  end
  puts table
end

Measured memory_bytes: 6136
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
int row[3000][3000], column[3000][3000];
string grid[3000];
signed main() {
  int H, W;
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> grid[i];
    for (int j = 0; j < W; j++) {
      if (grid[i][j] == '.') {
        if (j == 0) {
          row[i][j] = 1;
        } else {
          row[i][j] = row[i][j-1]+1;
        }
      } else {
        row[i][j] = 0;
      }
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = 0; j < H; j++) {
      if (grid[j][i] == '.') {
        if (j == 0) {
          column[j][i] = 1;
        } else {
          column[j][i] = column[j-1][i]+1;
        }
      } else {
        column[j][i] = 0;
      }
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = W-1; j > 0; j--) {
      if (row[i][j-1] != 0 && row[i][j] != 0) {
        row[i][j-1] = row[i][j];
      }
    }
  }
  for (int i = 0; i < W; i++) {
    for (int j = H-1; j > 0; j--) {
      if (column[j][i] != 0 && column[j-1][i] != 0) {
        column[j-1][i] = column[j][i];
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      //cout << max(row[i][j]+column[i][j]-1, 0LL);
      ans = max(ans, row[i][j]+column[i][j]-1);
    }
    //cout << endl;
  }
  cout << ans << endl;
}



Measured memory_bytes: 100224
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Collections;

public class Main{

	// a < b
	public static int eukleides(int a, int b){
		if(b % a == 0){
			return a;
		}
		int mod = b % a;
		
		return eukleides(mod, a);
	}

	public static void main(String... args){
		Scanner scan = new Scanner(System.in);
		LinkedList<Integer> points = new LinkedList<>();
		LinkedList<Integer> distances = new LinkedList<>();
		int answer;
		int min = Integer.MAX_VALUE;
		
		// input
		final int NUM = scan.nextInt();
		for(int i = 0; i <= NUM; i++){
			points.add(scan.nextInt());
		}
		
		// sort
		Collections.sort(points);
		
		// check distance
		while(points.size() > 1){
			distances.add((points.poll() - points.peek()) * -1);
		}
		
		// sort
		Collections.sort(distances);
		
		while(distances.size() > 1){
			distances.addFirst(eukleides(distances.poll(), distances.poll()));
		}
		
		System.out.println(distances.poll());
		
		
		

	}
}

Measured memory_bytes: 62688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define speed ios::sync_with_stdio(0); cin.tie(0);
int const N = 1e5 + 2;
int n, arr[100010], ans, dp[100010];

int main(){
	speed
	cin>>n;
	f(i, 0, n)cin >> arr[i];
	dp[n - 1] = 0;
	dp[n - 2] = abs(arr[n - 1] - arr[n - 2]);
	for (int i = n - 3; i >= 0; i--){
		dp[i] = min(abs(arr[i] - arr[i + 2]) + dp[i + 2], abs(arr[i] - arr[i + 1]) + dp[i + 1]);
	}
	cout << dp[0] << endl;

}

Measured memory_bytes: 1024
s = input()

ans = "WA"
if s[0] == 'A' and s[2:-1].count('C') == 1 and s[1] != 'C' and s[-1] != 'C':
    s2 = s.replace('A', 'a').replace('C', 'c')
    if s2 == s.lower():
        ans = "AC"
print(ans)

Measured memory_bytes: 3060
X=int(input())
if 400<=X and X<=599 :
  print(8)
elif 600<=X and X<=799 :
  print(7)
elif 800<=X and X<=999 :
  print(6)
elif 1000<=X and X<=1199 :
  print(5)
elif 1200<=X and X<=1399 :
  print(4)
elif 1400<=X and X<=1599 :
  print(3)
elif 1600<=X and X<=1799 :
  print(2)
else:
  print(1)


Measured memory_bytes: 9180
# from pprint import pprint
# import math
# import collections

# n = int(input())
h, w = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
s = []
for i in range(h):
    s.append(list(input()))

# すべての黒マスについて、上下左右に隣接している黒マスがあるかどうかを調べてあればOK
check = [[None] * w for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            check[i][j] = False
            if i > 0 and s[i - 1][j] == '#':
                check[i][j] = True

            if i < h - 1 and s[i + 1][j] == '#':
                check[i][j] = True

            if j > 0 and s[i][j - 1] == '#':
                check[i][j] = True

            if j < w - 1 and s[i][j + 1] == '#':
                check[i][j] = True
        else:
            check[i][j] = True

if all([all(c) for c in check]):
    print('Yes')
else:
    print('No')


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

int main()
{
	double x=0, y=0, rad=M_PI/2;
	
	while(1){
		int a,b;
		cin>>a;
		cin.ignore();  // 1文字読み捨てる
		cin>>b;
		if(a==0&&b==0){
			break;
		}
		x += a*cos(rad);
		y += a*sin(rad);
		rad -= b*(M_PI/180);
	}
	cout<<(int)x <<endl;
	cout<<(int)y <<endl;
	
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

bool check(const string& s) {
	char list[] = {'A', 'C', 'G', 'T'};
	bool flag = true;
	for (auto u : s) {
		bool f = false;
		rep(i, 4) if (u == list[i]) f = true;
		if (!f) flag = false;
	}
	return flag;
}

int main(int argc, char const *argv[])
{
	string s; cin >> s;
	int ans = 0;
	int size = s.size();
	rep(i, s.size()) {
		reps(len, 1, size - i + 1) {
			if (check(s.substr(i, len))) ans = max(ans, len);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  [n, m, c] <- map read . words <$> getLine
  bs <- map read . words <$> getLine
  ass <- replicateM n $ map read . words <$> getLine
  let calc a b = c + sum (zipWith (*) a b)
  print . length $ filter (>0) $ map (calc bs) ass


Measured memory_bytes: 1020
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
n,m=map(int,input().split())
l=[-1]*n
z=n*(n-1)//2
input()
m-=1
b=[input().split() for _ in range(m)]
c=[0]*m+[z]
def r(s):
  t=l[s]
  if t<0:
    return s
  else:
    l[s]=r(t)
    return l[s]
def f(s):
  return r(int(s)-1)
for i in range(m-1,-1,-1):
  x,y=map(f,b[i])
  if x!=y:
    s,t=l[x],l[y]
    z-=s*t
    if s>t:
      l[x]=y
      l[y]+=s
    else:
      l[y]=x
      l[x]+=t
  c[i]=z
for x in c:
  print(x)

Measured memory_bytes: 39496
#include<iostream>
using namespace std;
int main(){
	int n,a;
	cin>>n>>a;
	if(n<500){
		if(n<=a) cout<<"Yes";
		else cout<<"No";
		return 0;
	} 
	
	int k=n%500;
	if(k<=a) cout<<"Yes";
	if(k>a) cout<<"No";
	return 0;
} 

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

typedef long long ll;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = a; i >= (n); i--)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll d, g, p[11], c[11], result = INF;
  vector<int> ch;
  cin >> d >> g;
  FOR(i, 1, d + 1) ch.pb(i);
  FOR(i, 1, d + 1) cin >> p[i] >> c[i];
  do {
    ll cnt = 0, sum = 0;
    for(auto x: ch) {
      if((g - sum) > p[x] * x * 100 + c[x]) {
        cnt += p[x];
        sum += p[x] * x * 100 + c[x];
      } else {
        if((g - sum) > (p[x] * x * 100)) {
          cnt += p[x];
          sum += p[x] * x * 100 + c[x];
        } else {
          ll num = ceil(g - sum) / (x * 100);
          cnt += num;
          sum += num * x * 100;
        }
      }
      if(sum >= g) break;
    }
    result = min(result, cnt);
  }while (next_permutation(ch.begin(), ch.end()));
  cout << result << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define VI vector<int>
#define pb push_back
#define LL long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
const int MAXN = 1e5;
vector<pii> g[MAXN+10];
int n;
int d[MAXN+10];
int c[MAXN+10];
void dfs(int cur, int prev, int col){
	int e = 1;
	for(int i = 0; i < (int)g[cur].size(); i++){
		int next = g[cur][i].first;
		if(next == prev) continue;
		if(e == col) e++;
		c[g[cur][i].second] = e;
		dfs(next, cur, e);
		e++;
	}
}
int main(){
	scanf("%d", &n);
	int mxdeg = 0;
	for(int i = 0; i < n-1; i++){
		int u, v;
		scanf("%d %d", &u, &v);
		g[u].pb(mp(v,i));
		g[v].pb(mp(u,i));
		d[u]++; d[v]++;
		mxdeg = max(mxdeg, max(d[u], d[v]));
	}

	dfs(1, 1, 0);
	printf("%d\n", mxdeg);
	for(int i = 0; i < n-1; i++) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 9600
#include <stdio.h>

int main(void) {
	int h1,h2,t;
	int tyouhoukei=0,hisigata=0;
	while(1) {
		if(scanf("%d,%d,%d",&h1,&h2,&t)==-1)break;
		if(h1==h2)hisigata++;
		if(h1*h1+h2*h2==t*t)tyouhoukei++;
	}
	printf("%d\n",tyouhoukei);
	printf("%d\n",hisigata);
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int i;
  for(i=0;s[i]!='\0';i++);
  if(s[i-1]=='s')
    cout<<s<<"es";
  else
    cout<<s<<"s";
  return 0;
} 

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

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

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    Int n, k;
    cin >> n >> k;
    n = n - (n / k * k);
    Int ans = min(n, abs(n - k));

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int c[3][3];
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			cin >> c[i][j];
	bool flag = true;
	for (int i = 1; i < 3; ++i)
		for (int j = 1; j < 3; ++j)
			if (c[i - 1][j] - c[i - 1][j - 1] != c[i][j] - c[i][j - 1]) flag = false;
	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define MOD  1000000007
#define inf  1e18
#define ll long long
#define multiply(x) x*x*(x-=1)

#define ar array
#define wt(x) int x;cin>>x;while(x--)
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> pbds;
 void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
 
#ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);
  freopen("output1.txt","w",stdout);
#endif
 
 
}

int32_t main() {
   c_p_c();
  
       int n;
       cin>>n;
       if(n%10==3){
        cout<<"bon";

       }
       else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout<<"pon";
       }
       else{
        cout<<"hon";
       }
        
        
    
    return 0;
 }


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

const int MOD = (int)1e9+7;

class Union_Find_size{
public:
	vector<int> Parent;

	//コンストラクタ
	Union_Find_size(int N){
		Parent=vector<int>(N,-1);
	}

	//木の根を求める
	int root(int x){
		if(Parent.at(x)<0)	return x;
		//経路圧縮しながら return する
		return Parent.at(x)=root(Parent.at(x));
	}

	//xの属する木の要素数を調べる
	int size(int x){
		return -Parent.at(root(x));
	}

	//xとyが同じ集合に属するかを判定する
	bool same(int x,int y){
		return root(x)==root(y);
	}

	//xとyの属する集合を併合する
	void unite(int x,int y){
		x=root(x);
		y=root(y);
		if(x==y)	return;

		if(size(x)<size(y))	swap(x,y);
		Parent.at(x)+=Parent.at(y);
		Parent.at(y)=x;
	}
};

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> A(M);
	vector<int> B(M);
	for(int i=0;i<M;i++){
		cin >> A.at(i) >> B.at(i);
		A.at(i)--;
		B.at(i)--;
	}

	Union_Find_size Uni(N);
	vector<long long> ans(M);
	long long count=(long long)N*(N-1)/2;
	for(int i=M-1;i>=0;i--){
		ans.at(i)=count;
		if(!Uni.same(A.at(i),B.at(i))){
			count-=(long long)Uni.size(A.at(i))*Uni.size(B.at(i));
			Uni.unite(A.at(i),B.at(i));
		}
	}

	for(int i=0;i<M;i++){
		cout << ans.at(i) << endl;
	}

	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000000;
const long long LINF = 1e18;
const int MAX = 510000;

int main(){
	int n;
	float a, t;
	float mini = INF;
	int ans = 0;
	cin >> n >> t >> a;
	vector<float> h(n);
	for (int i = 0; i < n; i++) {
		cin >> h.at(i);
		h.at(i) = t - 0.006 * h.at(i);
		if (abs(a - h.at(i)) < mini) {
			mini = abs(a - h.at(i));
			ans = i;
		}
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 3748
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

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

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll n,m;
    cin >> n >> m;

    priority_queue<ll,vector<ll>> pq;

    for(int i = 0; i < n; i++){
        ll a;
        cin >> a;
        pq.push(a);
    }

    for(int i = 0; i < m; i++){
        ll t = pq.top();
        pq.pop();
        pq.push(t/2);
    }

    ll ans = 0;

    while(!pq.empty()){
        ans += pq.top();
        pq.pop();
    }

    cout << ans << endl;

    return 0;
}

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

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

	int x;
	cin >> x;

	int count = 0;

	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				int res = 500 * i + 100 * j + 50 * k;
				if (res == x) count++;
			}
		}
	}

	cout << count << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;
#define ll long long

int N;
int ans;

void check(ll x) {
  bool a=false, b=false, c=false;
  while(x>0) {
    if(x%10 == 3) a = true;
    if(x%10 == 5) b = true;
    if(x%10 == 7) c = true;
    x/=10;
  }
  if(a&b&c) ans++;
}

void dfs(ll x) {
  if (x <= N) {
    check(x);
    dfs(x*10+3);
    dfs(x*10+5);
    dfs(x*10+7);
  }
}

int main() {
  cin >> N;
  dfs(0);
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
l = 'abcdefghijklmnopqrstuvwxyz'
name = ''
while N > 0:
    t1 = N // 26
    t2 = N % 26
    if t2 == 0:
        t1 -= 1
    name = l[t2-1] + name
    N = t1
print(name)

Measured memory_bytes: 9184
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=2e5+100;
ll seg[4*N];
void shift(ll nod){
    if (seg[nod]==1){
        seg[nod*2]=1;
        seg[nod*2+1]=1;
    }
}
void upd(ll nod,ll l,ll r,ll L,ll R){
    if (l>=R || L>=r){
        return ;
    }
    if (l>=L && r<=R){
        seg[nod]=1;
        return ;
    }
    shift(nod);
    ll mid=(r+l)/2;
    upd(nod*2,l,mid,L,R);
    upd(nod*2+1,mid,r,L,R);
}
ll get(ll nod,ll l,ll r,ll id){
    if (r-l==1){
        return seg[nod];
    }
    shift(nod);
    ll mid=(r+l)/2;
    if (mid>id){
        return get(nod*2,l,mid,id);
    }
    else{
        return get(nod*2+1,mid,r,id);
    }
}
ll k;
vector <pii> h;
ll st[N];
ll fn[N];
vector <int> g[N];
ll cnt=0;
ll par[N];
vector <int> t;
ll par1[N];
ll dfs(ll v,ll p,ll hi){
    par1[v]=p;
    t.pb(v);
    ll z=t.size();
    z-=k;
    z=max((ll)0,z);
    par[v]=t[z];
    h.pb({hi,v});
    st[v]=cnt;
    for (int i=0;i<g[v].size();i++){
        ll u=g[v][i];
        if (u==p){
            continue;
        }
        cnt++;
        dfs(u,v,hi+1);
    }
    t.pop_back();
    fn[v]=cnt;
}
int32_t main(){
    ll n;
    cin >> n >> k;
    ll ans=0;
    ll x;
    cin >> x;
    if (x!=1){
        ans++;
    }
    for (int i=2;i<=n;i++){
        cin >> x;
        g[x].pb(i);
        g[i].pb(x);
    }
    upd(1,0,N,0,1);
    dfs(1,1,0);
    sort(h.begin(),h.end());
    reverse(h.begin(),h.end());
    for (int i=0;i<n-1;i++){
        ll v=h[i].S;
        ll u=par[v];
        //cout << v << " " << u << endl;
        ll z=get(1,0,N,st[v]);
        if (z==1 || par1[u]==1){
            continue;
        }
        ans++;
        upd(1,0,N,st[u],fn[u]+1);
    }
    cout << ans;
}


Measured memory_bytes: 28824
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second>b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    //     freopen("output.txt","w",stdout);
    // #endif
}
int main()
{
    vok();
    int n,m;
    IN n>>m;
    vector<int> h(n);
    loop(i,0,n)
    {
        IN h[i];
    }
    set<int> graph[n];
    loop(i,0,m)
    {
        int a,b;
        IN a>>b;
        a--, b--;
        graph[a].insert(h[b]);
        graph[b].insert(h[a]);
    }
    int ans=0;
    loop(i,0,n)
    {
        if(!int(graph[i].size()))
        {
            ans++;
            continue;
        }
        int high=*graph[i].rbegin();
        if(h[i]>high)
        {
            ans++;
        }
    }
    OUT ans<<endl
    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

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

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

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

struct edge {
  double l;
  int a, b;
  bool operator<(const edge &r) const {
    return l > r.l;
  }
};

class UnionFind {
public:
  const static int MAX_N = 10010;
  int par[MAX_N];
  int s[MAX_N];
  UnionFind() { init(); }
  UnionFind(int n) { init(n); }
  void init() { for(int i=0; i<MAX_N; ++i) par[i] = i, s[i] = 1; }
  void init(int n) { for(int i=0; i<n; ++i) par[i] = i, s[i] = 1; }
  int find(int x) {
    if(par[x] == x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(s[x] < s[y]) par[x] = y, s[y] = s[x] + s[y];
    else par[y] = x, s[x] = s[x] + s[y];
  }
  bool same(int x, int y) { return find(x) == find(y);}
};
UnionFind uf;

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

  int n, m;
  cin >> n >> m;
  VI x(n), y(n);
  REP(i, n) cin >> x[i] >> y[i];
  double ret = 0;
  vector<edge> v;
  REP(i, m) {
    int a, b;
    cin >> a >> b; a--, b--;
    double dist = sqrt((x[a]-x[b])*(x[a]-x[b]) + (y[a]-y[b])*(y[a]-y[b]));
    v.PB({dist, a, b});
    ret += dist;
  }

  // cout << ret << endl;
  sort(ALL(v));

  REP(i, m) {
    if(!uf.same(v[i].a, v[i].b)) {
      uf.unite(v[i].a, v[i].b);
      ret -= v[i].l;
    }
  }

  cout << fixed << setprecision(15) << ret << endl;

  return 0;
}



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

int digsum(int i){
    if(i) return i%10 + digsum((i-i%10)/10);
    else return 0;
}

int main() {
	int N;
	cin >> N;
	int m=100;
	for(int A=1; A*2<=N; ++A) m=min(m, digsum(A)+digsum(N-A));
	cout << m << endl;
	return 0;
}


Measured memory_bytes: 256
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n;
	cin >> n;
	n %= 10;

	if(n == 2 || n == 4 || n == 5 || n == 7 || n == 9) puts("hon");
	else if(n == 3) puts("bon");
	else puts("pon");

	return 0;
}


Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
from collections import defaultdict


n, m = map(int, input().split())

y = []
dic = {}
for _ in range(m):
    pi, yi = map(int, input().split())
    y.append(yi)
    dic[yi] = pi

d = defaultdict(int)
id_dict = {}

for yi, pi in sorted(dic.items()):
    d[pi] += 1
    id_dict[yi] = '{:0>6}{:0>6}'.format(pi, d[pi])

for yi in y:
    print(id_dict[yi])


Measured memory_bytes: 49676
i,a[1<<17],b[1<<17];c;
main(s){
	for(;~(c=getchar_unlocked());)c>10?a[i]=a[i]*10+c-48:i++;
	for(b[i=s]=1;!b[s=a[s]]++&&s-2;i++);
	printf("%d",s==2?i:-1);
}

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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int cnt[200];
ll sqr(int a)
{
    return a * a;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    int n;
    cin >> n;
    int x[n + 1];
    FOR(i, 1, n)
    {
        cin >> x[i];
        cnt[x[i]] = 1;
    }
    int s = 0, d = 0;
    ll ans = LINF;
    FOR(i, 1, 100)
    {
        ll t = 0;
        FOR(j, 1, n)
            t += sqr(i - x[j]);
        ans = min(ans, t);
    }

    cout << ans;
    return 0;
}


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

#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)

using namespace std;
using ll = long long;
using pos = pair<ll, ll>;

string s;

void solve();

int main() {
   solve();
   return 0;
}

void solve() {
	cin >> s;
	for (ll i = 0; i < s.size(); i++) {
		if (!(i % 2)) cout << s[i];
	}
	cout << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[200009],c,p[800009],x,y,ans,b[200009];
ll best(ll d,ll l,ll r)
{
    if(r<=x)
    return p[d];
    ll m=(l+r)/2;
    if(x<=m)
    return best(d*2,l,m);
    return max(best(d*2,l,m),best(d*2+1,m+1,r));
}
void up(ll d,ll l,ll r)
{
    if(l==r)
    return void(p[d]=y);
    ll m=(l+r)/2;
    if(x<=m)
    up(d*2,l,m);
    else up(d*2+1,m+1,r);
    p[d]=max(p[d*2],p[d*2+1]);
    return;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(ll i=0;i<n;i++)
    cin>>a[i];
for(ll i=0;i<n;i++)
    cin>>b[i];
for(ll i=0;i<n;i++){
    x=a[i];
    y=best(1,1,n)+b[i];
    ans=max(ans,y);
    up(1,1,n);
}
cout<<ans;
return 0;
}


Measured memory_bytes: 10712
//2018年  3月 26日 月曜日 03:11:26 JST
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, M;
ll dp[2][5010];
string str;

ll mod_pow(ll a, ll n) {
	if(n == 0) return 1;
	ll res = mod_pow(a, n / 2);
	if(n % 2 == 0) return res * res % mod;
	else return a * res % mod * res % mod;
}

void solve() {
	cin >> N;
	cin >> str;
	M = sz(str);
	dp[0][0] = 1;

	int now = 0, to = 1;
	rep(i, 0, N) {
		rep(j, 0, i + 1) dp[to][j] = 0;
		rep(j, 0, i + 1) {
			ADD(dp[to][max(j - 1, 0)], dp[now][j]);
			ADD(dp[to][j + 1], dp[now][j] * 2 % mod);
		}
		swap(now, to);
	}
	cout << dp[now][M] * mod_pow(mod_pow(2, M), mod - 2) % mod << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 384
n = int(input())
A = list(map(int, input().split()))
A.sort()
maxim = A.pop()

desire = maxim//2
desire += maxim % 2
check = maxim
ans = 0
for a in A:
    delta = abs(desire-a)
    if delta < check:
        check = delta
        ans = a

print(maxim, ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h){
        cin >> s[i];
    }
    rep(j, w + 2) cout << '#';
    cout << endl;
    rep(i, h){
        cout << '#';
        rep(j, w) cout << s[i][j];
        cout << '#' << endl;
    }
    rep(j, w + 2) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/*
FordFulkerson alg for MaxFlow_MinCut
11 farvardin 94
the edges are two ways 
gets edges and their capacities and print MaxFlow!
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=1e7;
const int SIZE=1e3;
int n,m,s,t,cpc[SIZE][SIZE],f;
bool pth=true,mark[SIZE];
vector<int>g[SIZE],lst;
void g_maker()
{
	cin>>n>>m;
	s=0,t=n-1;
	for(int i=1;i<=m;i++)
	{
		int k1,k2,cap;
		cin>>k1>>k2>>cap;
		cpc[k1][k2]=cap;
		g[k1].push_back(k2);
		g[k2].push_back(k1);
    }
}
int mincpcfinder()
{
	int out=INF;
	for(int i=0;i<lst.size()-1;i++)
		if(cpc[lst[i]][lst[i+1]]<out)
			out=cpc[lst[i]][lst[i+1]];
	return out;
}
void back()
{
	int mincpc=mincpcfinder();
	f+=mincpc;
	for(int i=0;i<lst.size()-1;i++)
    {
		cpc[lst[i]][lst[i+1]]-=mincpc;
		cpc[lst[i+1]][lst[i]]+=mincpc;
    }
}
void dfs(int v)
{
	lst.push_back(v);
	mark[v]=true;
	for(int i=0;i<g[v].size();i++)
    if(!mark[g[v][i]] && !pth && cpc[v][g[v][i]]>0)
			if(g[v][i]==t)
			{
				lst.push_back(t);
				pth=true;
				back();
			}
			else
				dfs(g[v][i]);
	lst.pop_back();
}
void flow()
{
	while(pth)
    {
		pth=false;
		lst.clear();
		fill(mark,mark+SIZE,false);
		dfs(s);
    }
}
int main()
{
	g_maker();
	flow();
	cout<<f<<endl;
	return 0;
}

Measured memory_bytes: 1652
// https://atcoder.jp/contests/abc115/tasks/abc115_c
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")

#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
using namespace std;
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))

int main() {
    int n, k, hmin = INT_MAX;
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    int h[n];

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    sort(h, h + n);

    // 小さい順に並び替えた後、k個の高さの差を計算する
    for (int i = 0; i < n - k + 1; i++) {
        hmin = min(hmin, h[i + k - 1] - h[i]);
    }

    cout << hmin << endl;

    return 0;
}


Measured memory_bytes: 640
from collections import defaultdict

ABC = sorted(map(int, input().split()))

count = 0
D = defaultdict(list)
for i, x in enumerate(ABC):
    D[x % 2].append(i)
for l in D.values():
    if len(l) == 2:
        count += 1
        for i in l:
            ABC[i] += 1
count += (ABC[2] - ABC[0]) // 2 + (ABC[2] - ABC[1]) // 2
print(count)


Measured memory_bytes: 3316
#include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;

struct Seg{
	int s,e,no;
	Seg(){}
	Seg(int a,int b,int c):s(a),e(b),no(c){}
};

vector<Seg> v;
void write(int l,int s){
	for(int i=0;s;i++){
		if(v[i].no!=-1)continue;
		int t = v[i].e-v[i].s;
		if(t<=s){
			v[i].no=l;
			s-=t;
		}else{
			t = v[i].s;
			v[i].s += s;
			v.insert(v.begin()+i,Seg(t,t+s,l));
			s=0;
		}
	}
}
void del(int l){
	for(int i=0;i<v.size();i++){
		if(v[i].no==l){
			v[i].no=-1;
		}
	}
}
void read(int p){
	for(int i=0;i<v.size();i++){
		if(v[i].s<=p&&p<v[i].e){
			cout<<v[i].no<<endl;
			return;
		}
	}
}
int main(){
	int n;
	while(cin>>n,n){
		v.clear();
		v.push_back(Seg(0,1000000000+1,-1));
		while(n--){
			char com;
			cin>>com;
			if(com=='W'){
				int l,s;
				cin>>l>>s;
				write(l,s);
			}else if(com=='D'){
				int l;
				cin>>l;
				del(l);
			}else {
				int p;
				cin>>p;
				read(p);
			}
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 1328
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int num[4][3][10] = {};
  for(int i=0; i<n; i++){
	int b,f,r,v;
	cin>>b>>f>>r>>v;
	num[b-1][f-1][r-1] += v;
  }

  for(int i=0;i<4;i++){
	if(i) cout<<"####################"<<endl;

  for(int j=0;j<3;j++){
    for(int k=0; k<10; k++){
	cout<<" "<<num[i][j][k];
	}
	cout<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

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

  int x,y;
  cin >> x >> y;
  if(x + y >= 10){
    cout << "error" << endl;
  }else{
    cout << x + y << endl;
  }
  
}

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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    int count;
    scanf("%lld", &N);
    ans = 0;
    if ( N < 105 ) cout << 0 << endl;
    else{
        if ( N % 2 == 0) N -= 1; 
        while ( N >= 105 ){
            count = 0;
            for ( int i = 1; i <= N; i++ ){
                if ( N % i == 0 ) count += 1; 
            }
            N -= 2;
            if ( count == 8 ) ans += 1;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long int> vt(n, 0), va(n, 0);
    for (int i = 0; i < n; i++) {
        cin >> vt[i] >> va[i];
    }
    long long int t = vt[0], a = va[0];
    for (int i = 1; i < n; i++) {
        long long int e = max(t / vt[i] + 1, a / va[i] + 1);
        long long int b = 1;
        while (b < e) {
            long long int m = b / 2 + e / 2 + (b % 2 + e % 2) / 2;
            if (t <= vt[i] * m && a <= va[i] * m) {
                e = m;
            } else {
                b = m + 1;
            }
        }
        t = vt[i] * b;
        a = va[i] * b;
    }
    cout << t + a << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define rep(i,m) for(long long i=0; i<m; i++)
#define per(i,m) for(long long i=m-1; i>=0; i--)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define ROF(i,n,m) for(long long i=n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
#define EPS (1e-7)
#define INF (1e18)
#define PI (acos(-1))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
typedef pair<ll, ll> LP;

ll POW(ll x,ll n){
  if(n==0)return 1;
  if(n%2==0)return POW(x*x%MOD,n/2);
  return x*POW(x,n-1)%MOD;
}

ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}
 
ll KAI(ll m)
{
  if(m<0) return 0;
  if(m==0) return 1;
  return m*KAI(m-1)%MOD;
}
 
ll extGCD(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll d = extGCD(b, a%b, y, x);
    y -= a / b * x;
    return d;
}
 
inline ll mod(ll a, ll m) {
    return (a % m + m) % m;
}
 
ll modinv(ll a) {
    ll x, y;
    extGCD(a, MOD, x, y);
    return mod(x, MOD);
}
 
ll COM(ll m,ll n)
{
  if(m<n) return 0;
  if(n<0) return 0;
  if(n==0) return 1;
  if(m==n) return 1;
  return KAI(m)%MOD*modinv(KAI(n)%MOD*KAI(m-n)%MOD)%MOD;
}

ll DEC(ll x,ll m,ll n)
{
  return x%POW(m,n+1)/POW(m,n);
}

ll keta(ll x,ll n)
{
  if(x==0)return 0;
  return keta(x/n,n)+1;
}

ll DIV(ll x,ll n)
{
  if(x==0)return 0;
  return x/n+DIV(x/n,n);
}


int main()
{
  ll n,ans;
  ans=0;
  char a[200],b[200],c[200];
  cin >> n;
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n)cin >> c[i];
  rep(i,n){if(a[i]==b[i]&&b[i]==c[i])ans+=0;
           else if(a[i]==b[i]||b[i]==c[i]||a[i]==c[i])ans+=1;
           else ans+=2;
          }
  printf("%lld",ans);  
}

Measured memory_bytes: 256
N,M,Q=map(int,input().split())
L = []
for i in range(Q):
  L.append(list(map(int, input().split())))
  L[i][0]-=1
  L[i][1]-=1

import itertools
l =list(range(1,M+1))
v=list(itertools.combinations_with_replacement(l,N))
ans=0
for arr in v:
  score=0
  for a,b,c,d in L:
    if (arr[b] - arr[a])==c:      
      score+=d
  ans=max(ans,score)
print(ans)


Measured memory_bytes: 21484
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> c(H);
    for(int i = 0; i < H; i++) {
        cin >> c[i]; 
    }

    int ans = 0;
    for(int i = 0; i < (1 << H); i++) {
        for(int j = 0; j < (1 << W); j++) {
            int num_black = 0;
            for(int k = 0; k < H; k++) {
                for(int l = 0; l < W; l++) {
                    if(!(((1 << k) & i) or ((1 << l) & j)) and (c[k][l] == '#')) {
                        num_black++;
                    }
                }
            }

            if(num_black == K) {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
  vector<int> a(5);
  rep(i,5) cin >> a[i];

  int res = 2e9;

  sort(a.begin(), a.end());
  do {
    int tmp = 0;
    int prev = 0;
    for (int i = 0; i < 5; i++) {
      tmp += a[i];
      if (tmp % 10 == 0) continue;
      if (i < 4) tmp += 10 - (tmp % 10);
    }
    res = min(res, tmp);
  } while (next_permutation(a.begin(), a.end()));
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n,m,a,b,ans,c;
	cin >> n >> m;
	ans = c = m;
	while (n--) {
		cin >> a >> b;
		if (c < 0) continue;
		c = c + a - b;
		if (c < 0) ans = 0;
		if (ans < c) ans = c;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3084
// #pragma GCC optimize("unroll-loops", "omit-frame-pointer", "inline")
// #pragma GCC option("arch=native", "tune=native", "no-zero-upper")
// #pragma GCC
// target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("tree-vectorize","openmp","predictive-commoning")
// #pragma GCC option("D_GLIBCXX_PARALLEL","openmp")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

#define endl "\n"

template <class T>
vector<T> divisor(T n) {
  vector<T> ret;
  for (T i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

void solve() {
  int N, M;
  cin >> N >> M;
  auto div = divisor(M);
  int ans = -1;
  for (int d : div) {
    if (M / d >= N) chmax(ans, d);
  }
  cout << ans << endl;
  return;
}

signed main() {
  fastio();
  solve();
  //   int t;
  //   cin >> t;
  //   while (t--) solve();

  // int t; cin >> t;
  // for(int i=1;i<=t;i++){
  //   cout << "Case #" << i << ": ";
  //   solve();
  // }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

int main() {
	int a,b;
	while(scanf("%d %d",&a,&b),a|b) {
		int dp[17][17]={0};
		bool bad[16][16]={0};
		int n;
		scanf("%d",&n);
		for(int i=0;i<n;i++) {
			int x,y;
			scanf("%d %d",&x,&y);
			bad[x-1][y-1]=1;
		}
		dp[0][0]=1;
		for(int i=0;i<a;i++) {
			for(int j=0;j<b;j++) {
				if(!bad[i+1][j]) dp[i+1][j]+=dp[i][j];
				if(!bad[i][j+1]) dp[i][j+1]+=dp[i][j];
			}
		}
		printf("%d\n",dp[a-1][b-1]);
	}
}

Measured memory_bytes: 1028
{-# OPTIONS_GHC -O2 #-}
import Control.Applicative
import qualified Data.HashMap.Strict as Map

main = do
    [_,capa] <- map (read :: String -> Int) . words <$> getLine
    goods <- map (map (read :: String -> Int) . words) . lines <$> getContents
    print $ maximum $ map snd $ Map.toList (resolve capa (Map.fromList (zip [0..capa] [0,0..])) goods)

resolve capa capaMap ([v,w]:xs)
  | xs == []  = koushin'
  | otherwise = resolve capa koushin' xs
  where
    koushin' =  koushin capaMap [v,w] 0
    koushin capaMap [v,w] n
      | n == 0 && capaMap Map.! w <= v      = next'
      | n > (capa - w)                      = capaMap
      | capaMap Map.! (n+w) >= v + oldValue = next
      | otherwise                           = next'
      where
        oldValue = capaMap Map.! n
        next     = koushin capaMap [v,w] (n+1)
        next'    = koushin (Map.insert (n+w) (v + oldValue) capaMap) [v,w] (n+1)

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cout << a[n - 1 - i];
        if(i == n - 1) break;
        cout << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 3120
#include <stdio.h>

int main(void) {
    int n;
    scanf("%d", &n);

    int change;
    int mod = n % 1000;
    if(mod == 0){
        printf("%d\n",mod);
    }else{
        change = 1000 - mod;
        printf("%d\n",change);
    }
}

Measured memory_bytes: 1708
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>

using namespace std;
using ll = long long;

const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b; cin >> a >> b;
    cout << max({a + b, a - b, a * b}) << endl;
    return 0;
}



Measured memory_bytes: 256
import Control.Monad -- for replicateM_
import Data.List -- for sort


{-
deal :: IO()
deal = do 
    [n, x] <- map read . words <$> getLine
    info <- replicateM (n-1) getWeight
    -- graph <- buildTree info [[[]]]
    putStrLn $ show info

main :: IO()
main = getLine >>= flip replicateM_ deal . read 
-}

solve :: [Integer] -> Integer -> Integer
solve (x:xs) nowMax
    | null xs = delta
    | otherwise = delta + solve xs newMax
    where 
       delta = if nowMax > x then nowMax - x else 0 
       newMax = if x > nowMax then x else nowMax

main :: IO()
main = do 
    getLine
    li <- map read . words <$> getLine
    putStrLn $ show $ solve li 0


Measured memory_bytes: 64268
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

int main()
{
 
//  int a, b, c, d, e, X, Y;
  int a, b, c,  d, e,f;
  //  double  c;
//  long long  A[1000001]={};
  int  A[2001][1001]={};
  int  B[2000001]={};
  int  ans[100003]={};
  int  sum[100003]={};
  int  cnt_flag[100003]={};

  int  L[1003]={};


//  long long  a, b, c, d, X, Y;
//  long long   d, X, Y;
  long long JPY;
  double BTC;
  char s[200001][1001]={};
  char t[200001][1001]={};
  char u[200001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k,point;
  int point_A=0, point_B=0;
  int flag=0;
//  int flag[10000003]={};
  int tmp=0;
//  int min=1000000;
  int min=10;
  int len=0;
  int cnt=0;
  int cnt0=0;
  int cnt1=0;
  int num=0;
//  double ans=0.0;
//  long long ans=0;
  int max=0;
//  int sum=0;
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
//  scanf("%lld %lld", &a, &b);
 
  scanf("%d%d", &a, &b);
  



  printf("%d\n",a-b+1);
//    else  
  
return 0;
}


Measured memory_bytes: 128