akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys
import math

debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
#        for line in sys.stdin:
#            lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    n = [int(e) for e in lines[0].split(" ")][0]
    a = [int(e) for e in lines[1].split(" ")]

    return (n, a)

def solve(n, a):

    current_num = 1
    count = 0
    result = []
    for i in range(n):
        if a[i] != current_num:
            count = count + 1
        else:
            current_num = current_num + 1
            result.append(a[i])
    
    if debug:
        log("result=%s" % result)
        log("count=%s" % count)
    
    if result == []:
        count = -1

    for i in range(1, len(result) + 1):
        if result[i-1] != i:
            if debug:
                log("result[%d]=%s" % (i, result[i-1]))
            count = -1
            break


    return count

def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r)
    else:
        print("%s" % result)

if __name__ == '__main__':

    main()
	

Measured memory_bytes: 26396
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>


int main(){
  int a,b,c,k,i;
  //int n=0,i=0,d=0,x=1,y=1,z=1,m=0;//a[200000],j=0;
  //char s[200000];
  
  scanf("%d %d %d\n",&a,&b,&c);
  scanf("%d",&k);
  //printf("%d %d %d %d\n",a,b,c,k);
  for(i=0;i<k;i++){
    if(a>=b){
      b=b*2;
      //printf("b=%d",b);
    }
    else if(a<b && c<=b){
      c=c*2;
      //printf("c=%d",c);
    }
  }
  if(c>b && b>a)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <deque>
#include <cassert>
#define pb push_back
#define x first
#define y second
#define files(FileName) read(FileName); write(FileName)
#define read(FileName) freopen((FileName + ".in").c_str(), "r", stdin)
#define write(FileName) freopen((FileName + ".out").c_str(), "w", stdout)
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }

const string FILENAME = "input";
const int MAXN = 1e5 + 5;

int n, m;
int cnt[MAXN];
bool can[MAXN];

int main() {
	ios::sync_with_stdio(false);
	srand(time(0));
	//read(FILENAME);
	can[1] = true;
	cin >> n >> m;
	for (int i = 1; i <= n; ++i)
		cnt[i] = 1;
	while (m--) {
		int a, b;
		cin >> a >> b;
		if (can[a]) {
			can[b] = true;
			if (cnt[a] == 1) {
				can[a] = false;
			}
		}
		--cnt[a];
		++cnt[b];
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += can[i];
	cout << ans << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<(n);i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;


int main(void){ios::sync_with_stdio(false);cin.tie(0);
    
    int i,n,m,j;
    cin>>n>>m;
    int p[m][2];
    vector<vector<int> > v(n,vector<int>());
    map<int,int> ma;
    for(i=0;i<m;i++){
    	cin>>p[i][0]>>p[i][1];
//    	cout<<p[i][0]-1<<" "<<p[i][1]<<endl;
    	v[p[i][0]-1].push_back(p[i][1]);
	}
	for(i=0;i<n;i++) sort(v[i].begin(),v[i].end());
	for(i=0;i<n;i++){
		for(j=0;j<v[i].size();j++){
			ma[v[i][j]]=j+1;
		}
	}
    for(i=0;i<m;i++){
    	printf("%06d%06d\n",p[i][0],ma[p[i][1]]);
	}
    
    
    
	return 0;
}


Measured memory_bytes: 12416
import sys
import os
import itertools
import numpy as np
from collections import deque
import math

def main():
    if os.getenv("ENV")=='LOCAL':
        sys.stdin = open(os.path.dirname(__file__)+'/input.txt', 'r')

    N,D=map(int, input().split())

    ans=0
    for i in range(N):
        X,Y = map(int, input().split())
        if D>=math.sqrt(Y*Y+X*X):
            ans+=1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 27008
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;

int main()
{
    string s;
    cin >> s;
    int ans = INF;
    int digit;
    rep(i, 0, s.size()-2){
        digit = 100;
        int x = 0;
        rep(j, i, i+3){
            x += (s[j] - '0')*digit;
            digit /= 10;
            //cout << digit << " ";
        }
        ans = min(ans, abs(x - 753));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

int dfs(int t, int v, vector<vector<int>> adj, vector<P>& ts) {
    if (ts[v].first != 0) return t;

    t++;
    ts[v].first = t;
    for (auto e : adj[v]) {
        t = dfs(t, e, adj, ts);
    }
    t++;
    ts[v].second = t;
    return t;
}

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

    int n;
    cin>>n;
    vector<vector<int>> adj(n);
    rep(i, n) {
        int u, k, v;
        cin>>u>>k; u--;
        rep(j, k) {
            cin>>v; v--;
            adj[u].push_back(v);
        }
    }

    vector<P> ts(n);
    int t = 0;
    rep(i, n) {
        if (ts[i].first != 0) continue;
        t = dfs(t, i, adj, ts);
    }
    rep(i, n) {
        cout<<i + 1<<" "<<ts[i].first<<" "<<ts[i].second<<endl;
    }
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll A,V,B,W,T;
int main(){
    scanf("%lld%lld%lld%lld%lld",&A,&V,&B,&W,&T);
    if(W>=V){puts("NO");}
    else if(W<V){
        if(abs(B-A)<=T*(V-W))puts("YES");else puts("NO");
    }
    return 0;
}


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

using namespace std;

#define il inline
#define re register
#define Rep(i, s, e) for (re int i = s; i <= e; ++i)
#define Dep(i, s, e) for (re int i = s; i >= e; --i)
#define file(a) freopen(#a".in", "r", stdin), freopen(#a".out", "w", stdout)

typedef long long ll;

il int read() {
    int x = 0; bool f = true; char c = getchar();
    while (!isdigit(c)) {if (c == '-') f = false; c = getchar();}
    while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
    return f ? x : -x;
}

int main() {
    ll n = read(), d = read(), ans = 0;
    Rep(i, 1, n) {
        ll x = read(), y = read();
        ans += (x * x + y * y <= d * d);
    }
    printf("%d", ans);
    return 0;
}

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

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


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int>b(N+1,0);
    for (int i = 0; i < M; ++i) {
        int a;
        cin >> a;
        b[a] = 1;
    }

    vector<ll>ans(N+1, 0);
    ans[0] = 1;
    ans[1] = 1;
    for (int i = 2; i < N+1; ++i) {
        if(b[i-1] == 0) ans[i] += ans[i-1];
        if(b[i-2] == 0) ans[i] += ans[i-2];
        ans[i] %= mod;
    }

    cout << ans[N];
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
ll gcd(ll m, ll n){
	ll k=min(m,n),l=max(m,n);
	if(!k)return l;
	return gcd(l%k,k);
}
bool present[100000]={0};
ll ld[1000005]={0};
void pre(){
	for(int i=1;i<1000005;i++)ld[i]=i;
	for(int i=2;i*i<1000005;i++){
		if(ld[i]==i){
			for(int j=i*i;j<1000005;j+=i){
				if(ld[j]==j)ld[j]=i;
			}
		}
	}
}
int main(){
	pre();
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll gcda=a[0];
	bool pc=1,sw=0;
	set<ll> s;
	while(a[0]>1){
		s.insert(ld[a[0]]);
		a[0]/=ld[a[0]];
	}
	for(int i=1;i<n;i++){
		set<ll> l;
		gcda=gcd(gcda,a[i]);
		while(a[i]>1){
			l.insert(ld[a[i]]);
			a[i]/=ld[a[i]];
		}
		for(auto j=l.begin();j!=l.end();j++){
			if(s.find(*j)==s.end()){
				s.insert(*j);
			}
			else{
				pc=0;
			}
		}

	}
	if(pc){
		cout<<"pairwise coprime";
	}
	else if(gcda==1){
		cout<<"setwise coprime";
	}
	else{
		cout<<"not coprime";
	}

}


Measured memory_bytes: 22872
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int a = Integer.parseInt(sc.next());
	static int b = Integer.parseInt(sc.next());
	public static void main(String[] args) {
		if (b%a==0) {
			System.out.println(a+b);
		} else {
			System.out.println(b-a);
		}
	}
}


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

using namespace std;

static const int N = 1000;

int lcs(string X, string Y) {
    int c[N + 1][N + 1];

    int m = X.size();
    int n = Y.size();

    X = ' ' + X;
    Y = ' ' + Y;

    int maxl = 0;

    // Initialize
    for (int i = 0; i <= m; i++) c[i][0] = 0;
    for (int j = 0; j <= n; j++) c[0][j] = 0;

    for (int i = 1; i <= m; i++) {
        for (int j = 1; j <= n; j++) {
            if (X[i] == Y[j]) {
                c[i][j] = c[i - 1][j - 1] + 1;
            } else {
                c[i][j] = max(c[i - 1][j], c[i][j - 1]);
            }

            maxl = max(maxl, c[i][j]);
        }
    }

    return maxl;
}

int main() {
    string s1, s2;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> s1 >> s2;
        cout << lcs(s1, s2) << endl;
    }

    return 0;
}



Measured memory_bytes: 7028
N = int(input())
H = list(map(int, input().split()))

prev = H[0]
cnt = 0
ans = 0
for i in range(1, N):
    if H[i] <= prev:
        cnt += 1
        ans = max(ans, cnt)
        prev = H[i]
        #cnt = max(cnt, )
    else:
        ans = max(ans, cnt)
        cnt = 0
        prev = H[i]

print(ans)

Measured memory_bytes: 14252
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef std::vector<ll> vll;
typedef std::pair<ll,ll> pll;
typedef std::vector<vll> vvll;

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define ff first
#define ss second
#define mk make_pair
const ll N = 1e5 + 10;
const ll m = 1e9+7;
ll n;
vll g[N];
ll dp1[N];
ll dp2[N];
ll go1(ll s, ll par);
ll go2(ll s, ll par);

ll go2(ll s , ll par)
{
	ll &ans = dp2[s];
	if(ans != -1)
		return ans;

	ans = 1;
	for(auto x: g[s])
	{
		if(x != par)
		{
			ans*= go1(x , s);
			ans%=m;
		}
	}

	return ans;
}



ll go1(ll s , ll par)
{
	ll &ans = dp1[s];
	if(ans != -1)
		return ans;
	ll white = go2(s , par);
	ll black = 1;
	for(auto x : g[s])
	{
		if(x != par)
		{
			black*=go2(x , s);
			black%=m; 
		}
	}
	ans = (white + black)%m;
	return ans;
}


signed main()
{

	fast;
	memset(dp1 , -1 , sizeof dp1);
	memset(dp2 , -1 , sizeof dp2);


////////////////////////////////////////////////////////////////////////////////////////////
	cin >> n;

	rep(i,0,n-1)
	{
		ll u , v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}

	cout<<go1(1 , -1)<<endl;









////////////////////////////////////////////////////////////////////////////////////////////


	return 0;
}


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

using namespace std;

int main() {

    string s;

    while(cin >> s) {

        int len = s.size();
        int num[len + 1];
        int sum = 0;

        for(int i = 0; i < len; ++i) {
            switch(s[i]) {
                case 'I':
                    num[i] = 1;
                    break;
                case 'V':
                    num[i] = 5;
                    break;
                case 'X':
                    num[i] = 10;
                    break;
                case 'L':
                    num[i] = 50;
                    break;
                case 'C':
                    num[i] = 100;
                    break;
                case 'D':
                    num[i] = 500;
                    break;
                case 'M':
                    num[i] = 1000;
                    break;
            }
        }

        num[len] = 1;

        for(int i = len - 1; i >= 0; --i) {
            if(num[i] < num[i + 1]) {
                sum -= num[i];
            } else {
                sum += num[i];
            }
        }

        cout << sum << endl;

    }

    return 0;

}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

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

	vector<long long> a(n);
	long long s = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		s += a[i];
	}

	vector<long long> f(n);
	int fmin = 1e6 + 1;
	for (int i = 0; i < n; ++i) {
		cin >> f[i];
		if (f[i] < fmin) {
			fmin = f[i];
		}
	}

	sort(a.begin(), a.end());
	sort(f.begin(), f.end());

	long long start = 0;
	long long end = 1e12;
	while (start < end) {
		long long lim = (start + end) / 2;
		long long count = 0;
		for (int i = 0; i < n; ++i) {
			if (a[i] * f[n - i - 1] > lim) {
				count += a[i] - lim / f[n - i - 1];
			}
		}

		if (count <= k) {
			end = lim;
		}
		else {
			start = lim + 1;
		}
	}

	cout << end;

	return 0;
}


Measured memory_bytes: 3328
N, D = map(int, input().split())
dot = [list(map(int, input().split())) for i in range(N)]

ans = 0
for i in range(N):
    for j in range(i+1, N):
        dist = 0
        for k in range(D):
            dist += (dot[i][k] - dot[j][k])**2
        if int(dist**(1/2))**2 == dist:
            ans += 1
print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
int A[1 << 18 + 1];
int mx1[1 << 18], mx2[1 << 18];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < (1 << N); ++i){
        cin >> A[i];
        mx1[i] = 1 << 18; 
        mx2[i] = 1 << 18; 
    }
    mx1[0] = 0;

    int ans = 0;
    for(int i = 1; i < (1 << N); ++i){
        mx1[i] = i;
        for(int j = 0; j < N; ++j){
            if(i >> j & 1){
                int to = i ^ 1 << j;

                auto update = [i](int idx){
                    if(A[idx] > A[mx1[i]]) mx2[i] = mx1[i], mx1[i] = idx;
                    else if(idx != mx1[i] && A[idx] > A[mx2[i]]) mx2[i] = idx;
                };

                update(mx1[to]);
                update(mx2[to]);
            }
        }
        chmax(ans, A[mx1[i]] + A[mx2[i]]);
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
    string O, E;
    cin >> O >> E;
    string ans = "";
    rep(i, O.size()) {
        ans += O.at(i);
        if (i < E.size()) ans += E.at(i);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main() {
  char x[1010];
  while (true) {
    scanf("%s", x);
    if (x[0] == '0') break;
    int sum = 0, i = 0;
    while (x[i]) {
      sum += x[i] - '0';
      i++;
    }
    printf("%d\n", sum);
  }
  
  return 0;
}


Measured memory_bytes: 2708
#W,H,x,y=(int(x) for x in input().split())

def Solve():
    N,X=(int(x) for x in input().split())
    L=[int(x) for x in input().split()]
    dis=0
    count=1
    for i in range(N):
        dis+=L[i]
        if dis>X:
            return count
        count+=1
    return N+1
print(Solve())


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;
#define rep(i,n) for(int i=0; i<n; i++)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてから使う
#define INF 2147483647
#define LLINF 9223372036854775807LL

int search(int n,int k,vector<int>h){
  vector<ll>dp(n, INF);
  dp[0] = 0;
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n && j<=i+k; j++){
      dp[j] = min(dp[j],dp[i]+abs(h[i]-h[j]));
    }
  }
  return dp[n-1];
}

int main(){
  int n,k; cin>>n>>k;
  vector<int>h(n); rep(i,n) cin>>h[i];
  cout << search(n,k,h) << endl;
}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;

    while(cin>>a>>b>>c)
    {
        if (a==b && b==c && c==a)
            cout<<"Yes"<<endl;
        else if(c>a && c<b)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int n;
  while(scanf("%d", &n),n){
    int max=0,min=1000,s;
    long sum=0;
    for(int i=0; i<n; i++){
      scanf("%d",&s);
      sum+=s;
      max=max<s ? s : max;
      min=s<min ? s : min;
    }
    printf("%ld\n", (sum-min-max)/(n-2));
  }
}

Measured memory_bytes: 0
h, w = map(int, input().split())
visited = [[False] * w for _ in range(h)]
pts = []
for i in range(h):
    s = input().rstrip()
    for j in range(w):
        if s[j] == '#':
            visited[i][j] = True
            pts.append((i, j))
res = 0
ds = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while True:
    new_pts = []
    for i, j in pts:
        for dx, dy in ds:
            new_i = i + dy
            new_j = j + dx
            if 0 <= new_i < h and 0 <= new_j < w and not visited[new_i][new_j]:
                visited[new_i][new_j] = True
                new_pts.append((new_i, new_j))
    if len(new_pts) > 0:
        res += 1
        pts = new_pts
    else:
        break
print(res)

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

using namespace std;

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    int i,j,tmp=k;
    while(tmp<=b){
        if(tmp>=a){
            cout << "OK";
            break;
        }
        if(k==1){
            cout << "OK";
            break;
        }
        tmp+=k;
    }
    //cout << "tmp" <<tmp;
    if(tmp>b)
        cout << "NG";

}


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

double dp[100010][50]; // ティツェツ、テ・ツキツョテ」ツ?古ァツキツゥテ」ツ??」ツ?ョテ」ツ?ァテ」ツつオテ」ツδ愿」ツつ古」ツつ?
double ans[100010];

void solve(){
    rep(i,100010)rep(j,50) dp[i][j] = 0;
    dp[0][1] = 1;
    ans[0] = 1;
    double ps = 1;
    for(int d = 1; d < 100010; d++){
        double p = 1;
        for(int i = 1; i < 50; i++){
            dp[d][0] += dp[d-1][i-1] * (1-p);
            dp[d][i] += dp[d-1][i-1] * p;
            ps += dp[d-1][i-1] * p;
            p *= 0.5;
        }
        ans[d] = ps;
    }
}

int main(){
    int n;
    solve();
    while(cin >> n && n){
        printf("%.10lf\n", ans[n-1]);
    }
}

Measured memory_bytes: 41020
n = int(input())
l = list(map(int, input().split()))

summ = 0
n = l[0]

for i in l[1:]:

  if n < i:  
    summ += n
    n = i
   
  else:
    summ += i
    
if n < summ:
  print('Yes')
  
else:
  print('No')
  


Measured memory_bytes: 2940
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10^^9;

void main() {
  try {
    for (; ; ) {
      const H = readInt();
      const W = readInt();
      auto S = new string[H];
      foreach (x; 0 .. H) {
        S[x] = readToken();
      }
      
      auto dp = new int[][](H, W);
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        dp[x][y] = INF;
      }
      dp[0][0] = (S[0][0] == '#') ? 1 : 0;
      
      auto vis = new bool[][](H, W);
      foreach (x; 0 .. H) foreach (y; 0 .. W) {
        if (x + 1 < H && S[x + 1][y] != '#') chmin(dp[x + 1][y], dp[x][y]);
        if (y + 1 < W && S[x][y + 1] != '#') chmin(dp[x][y + 1], dp[x][y]);
        foreach (xx; x .. H) foreach (yy; y .. W) {
          vis[xx][yy] = (x == xx && y == yy) ||
                        (S[xx][yy] == '#' && x < xx && vis[xx - 1][yy]) ||
                        (S[xx][yy] == '#' && y < yy && vis[xx][yy - 1]);
          if (vis[xx][yy]) {
            chmin(dp[xx][yy], dp[x][y] + 1);
            if (x == 0 && y == 0) {
              chmin(dp[xx][yy], 1);
            }
          }
        }
      }
      debug {
        foreach (x; 0 .. H) {
          writeln(dp[x]);
        }
      }
      writeln(dp[H - 1][W - 1]);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

bool isacgt(char c) {
    return c == 'A' ||
           c == 'C' ||
           c == 'G' ||
           c == 'T';
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    string s;
    cin >> s;
    int ans = 0, len = 0;
    for(char c : s) {
        if(isacgt(c)) len += 1;
        else          len = 0;
        ans = max(ans, len);
    }
    cout << ans << endl;
}

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)

ll solve(vector<ll>vect,ll n,ll k)
{
   vector<ll>dp(n,0);
   dp[0]=0;
   dp[1]=abs(vect[0]-vect[1]);

   for(int i=2;i<n;i++)
   {
       ll j=i-1;
       dp[i]=1e18;
       ll temp_ans;

       while(j>=0 && j>=i-k )
       {

           temp_ans= abs(vect[j]-vect[i])+dp[j];
           dp[i]=min(temp_ans,dp[i]);
           j--;

       }

   }

    return dp[n-1];

}


int main()
{

	ll n,k;
	 cin>>n>>k;
	 vector<ll>vect(n);
	 f(i,0,n)
        cin>>vect[i];

    ll ans=solve(vect,n,k);
    cout<<ans<<"\n";

	return 0;
}













Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_len=(n); i<i##_len; ++i)
#define FOR(i, a, b) for (int i=(a); i<(b); ++i)
using ll = long long;
using namespace std;

bool solve(string S)
{
    string A = "keyence";
    if (S == A) return true;

    REP(i, S.size())
    {
        if (A[i] == '\0') { return true; }
        if (S[i] != A[i]) { break; }
    }

    REP(i, S.size())
    {
        int r = S.size()-i-1;
        int n = A.size()-i-1;

        if (S[r] != A[n]) { break; }
        if (A[n] ==  'k') { return true; }
    }

    int cursor = A.size()-1;
    REP(i, S.size())
    {
        if (S[i] != A[i]) { break; }
        --cursor;
    }

    REP(i, S.size())
    {
        int r = S.size()-i-1;
        int n = A.size()-i-1;
        if (S[r] != A[n]) { break; }
        if (i ==  cursor) { return true; }
    }

    return false;
}

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

    cout << (solve(S) ? "YES" : "NO") << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

const ll MOD = 1e9 + 7;

int main()
{
    ll n, m, x[112345], y[112345];
    cin >> n >> m;
    REP(i, n)
    cin >> x[i];
    REP(i, m)
    cin >> y[i];

    ll areax = 0;
    ll areay = 0;

    REP(i, n)
    {
        areax += (i + 1 - 1) * x[i] - (n - i - 1) * x[i];

        areax %= MOD;
    }

    REP(i, m)
    {
        areay += (i + 1 - 1) * y[i] - (m - i - 1) * y[i];

        areay %= MOD;
    }

    cout << (areax * areay) % MOD << endl;

    return 0;
}

Measured memory_bytes: 1792
using namespace std;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int c[3][3] = {0};
    int a[3] = {0};
    int b[3] = {0};

    for (int i = 0; i < 3; i++){
        for (int k = 0; k < 3; k++){
            cin >> c[i][k];
        }
    }

    for (int i = 0; i < 3; i++){
        b[i] = c[0][i] - 0;
    }

    for (int i = 1; i < 3; i++){
        a[i] = c[i][0] - b[0];
    }


    bool flag = true;
    for (int i = 0; i < 3; i++){
        for (int k = 0; k < 3; k++){
            if (c[i][k] != a[i] + b[k]){
                flag = false;
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename T >
vector< T > slide_min(const vector< T > &v, int k)
{
  deque< int > deq;
  vector< T > ret;
  for(int i = 0; i < v.size(); i++) {
    while(!deq.empty() && v[deq.back()] >= v[i]) {
      deq.pop_back();
    }
    deq.push_back(i);
    if(i - k + 1 >= 0) {
      ret.emplace_back(v[deq.front()]);
      if(deq.front() == i - k + 1) deq.pop_front();
    }
  }
  return (ret);
}

int main() {
  int N, X;
  cin >> N >> X;
  vector< int > A(N);
  cin >> A;
  for(int i = 0; i < N; i++) A.push_back(A[i]);

  int64 ret = infll;
  for(int t = 0; t < N; t++) {
    auto v = slide_min(A, t + 1);
    int64 add = 0;
    for(int j = 0; j < N; j++) {
      add += v[v.size() - j - 1];
    }
    chmin(ret, add + 1LL * t * X);
  }
  cout << ret << endl;
}



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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, ans = 0;
    string s, token;
    cin >> n >> s;

    rep(i, s.length() - 2) {
        token = s.substr(i, 3);
        if(token=="ABC") ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    def nCr(n,r):
        a=1
        x=n
        while(x!=n-r):
          a*=x
          x-=1
        b=1
        x=r
        while(x!=0):
          b*=x
          x-=1
        return a//b

    INF=10**9+7
    N,m=map(int,input().split())


    sum=1
    yd = {}
    i = 2
    while m != 1:
      while m % i == 0:
        if i in yd:
          yd[i] += 1
        else:
          yd[i] = 1
        m //= i
      i += 1
    for b in yd.values():
        if b<N-1:
            sum*=nCr(N-1+b,b)
        else:
            sum*=nCr(N-1+b,N-1)
        sum%=INF  
    print(sum)
if __name__ == '__main__':
    main()


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

int gcd(int a, int b) {return b?gcd(b, a%b):a;}
int lcm(int a, int b) {return a/gcd(a, b)*b;}

int main() {
    int n, m; cin >> n >> m;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int max_loop = lcm(n, m);
    int ans = 0;
    for (int i = 0; i < max_loop;) {
        int mx = -1e9, mn = 1e9;
        for (int j = 0; j < m; i++, j++) {
            mx = max(mx, a[i%n]);
            mn = min(mn, a[i%n]);
        }
        ans += mx - mn;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; i++)
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
#define all(vec) vec.begin(), vec.end()
#define MOD (int) (1e9 + 7)
using namespace std;
typedef pair<int, int> P;
struct edge {
	int to, cost;
};

class dijkstra {
  private:
	int V;
	int d[100002];
	priority_queue<P, vector<P>, greater<>> que;

  public:
	dijkstra(int v, int s, vector<edge> G[]) {
		V = v;
		update(s, G);
	}

	void update(int s, vector<edge> G[]) {
		fill(d, d + V + 1, 100000000000ll);
		d[s] = 0;
		que.push(make_pair(0, s));
		while (!que.empty()) {
			P p = que.top();
			que.pop();
			int v = p.second;
			if (d[v] < p.first)
				continue;
			rep(i, G[v].size()) {
				edge e = G[v][i];
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push(make_pair(d[e.to], e.to));
				}
			}
		}
	}

	int find(int e) {
		return d[e];
	}
};

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

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

bool prime(int a) {
	if (a == 1)
		return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;
	}
	return true;
}

class Union_Find {
  private:
	vector<int> t, s;

  public:
	Union_Find(int max_length) {
		rep(i, max_length + 1) {
			t.push_back(i);
			s.push_back(1);
		}
	}

	void Union(int x, int y) {
		if (same(x, y))
			return;
		int tx = Find(x), ty = Find(y);
		if (s[tx] < s[ty]) {
			s[ty] += s[tx];
			t[tx] = ty;
		}
		else if (s[tx] > s[ty]) {
			s[tx] += s[ty];
			t[ty] = tx;
		}
		else if (tx > ty) {
			t[tx] = ty;
			s[ty] += s[tx];
		}
		else {
			t[ty] = tx;
			s[tx] += s[ty];
		}
	}

	int Find(int n) {
		if (t[n] == n)
			return n;
		else
			return t[n] = Find(t[n]);
	}

	bool same(int x, int y) {
		return Find(x) == Find(y);
	}

	int get_Size(int a) {
		return s[a];
	}
};

set<int> prime_num_factor(int n) {
	if (n < 2)
		return set<int>();
	set<int> prime;
	prime.insert(2);
	for (int i = 3; i <= n; i++) {
		for (int it : prime) {
			if (it * it > i) {
				prime.insert(i);
				break;
			}
			if (i % it == 0)
				break;
		}
	}
	return prime;
}
vector<int> primeFactorization(int n) {
	vector<int> re;
	int cnt = 2;
	while (n != 1) {
		if (n % cnt != 0) {
			cnt++;
			continue;
		}
		n /= cnt;
		re.push_back(cnt);
	}
	return re;
}
signed main() {
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	vector<int> sorted_p = p;
	sort(sorted_p.begin(), sorted_p.end());
	int cnt=0;
	rep(i, n) if (sorted_p[i] != p[i]) cnt++;
	if(cnt<=2)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
const ll inf = 1e9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const ll MAX = 1e7 + 20;
#define fast ios_base:: sync_with_stdio( false ); cin.tie(0); cout.tie(0);
#define eb              emplace_back
#define em              emplace
#define pb              push_back
#define Mp              make_pair
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep1(i,n)       for(int i=1;i<=n;i++)
#define rrep(i,a,n)     for(int i=a;i<=n;i++)
#define per(i,n,a)      for(int i=n;i>=a;i--)
#define pf(n)           printf("%lld",n)
#define pfi(n)          printf("%d",n)
#define sp              printf(" ")
#define ln              "\n"

#define pi acos(-1.0)
#define mod 1000000007

///Library
#define mem(a,b) memset(a,b,sizeof(a))
#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sq(x) (x)*(x)


///vector
#define Lower_bound(vec,value) lower_bound(vec.begin(),vec.end(),value)
#define Upper_bound(vec,value) upper_bound(vec.begin(),vec.end(),value)


//template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
//template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }


int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/

    fast
    string a;
    cin>>a;
    for(int i=0; i<a.size(); i++)
    {
        cout<<'x';
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define N 1000000

int binarySearch(int A[N],int n, int key){
  int left=0;
  int right=0;
  int mid;
  right = n;
  while(left<right){
    mid = (left+right)/2;
    if(A[mid] == key){
      return 1;
    }
    if(key < A[mid]){
      right = mid;
    }
    else left = mid + 1;
  }
  return 0;
}

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






Measured memory_bytes: 2192
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod_) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod_;
		}
		x = x * x % mod_;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}
/*--------Library Zone!--------*/


signed main() {
	stack<char>st;
	string s; cin >> s;
	rep(i, s.size()) {
		if (st.empty())st.push(s[i]);
		else if (st.top() == 'S' && s[i] == 'T')st.pop();
		else st.push(s[i]);
	}
	cout << st.size() << endl;
}


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

bool field[100][100];

void migi(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x+i] = 1;
	}
}
void sita(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y+i][x] = 1;
	}
}
void hidari(int y,int x,int j)
{
	for(int i=1;i<=j;i++){
		field[y][x-i] = 1;
	}
}
void ue(int y,int x,int j)
{
	if(j <= 1)
		return;
	for(int i=1;i<=j;i++){
		field[y-i][x] = 1;
	}
}	
int main()
{
	int a;
	cin >> a;
	for(int i=0;i<a;i++){
		int n;
		cin >> n;
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				field[j][k] = 0;
			}
		}
		int y=n-1,x=0;
		for(int j=0;j<n;j++){
			field[y-j][x] = 1;
		}
		y = 0;
		
		for(int j=n-1;j>=0;j-=2){
			migi(y,x,j);
			x = x+j;
			sita(y,x,j);
			y = y+j;			
			j-=2;
			hidari(y,x,j);
			x = x-j;
			ue(y,x,j);
			y = y-j;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(field[i][j] == 1)
					cout << '#';
				else
					cout << ' ';
			}
			cout << endl;
		}
		if(i !=a-1)
			cout << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
  int N[51] = {0}, M;
  int a, b, i;
  cin >> N[51] >> M;

    for(i = 0; i < M; i++)
    {
      cin >> a >> b;
      N[a - 1] += 1;
      N[b - 1] += 1;
    }

    for(i = 0; i < N[51]; i++)
    {
      cout << N[i] << endl;
    }
  return 0;
}

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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
#define debug(x)  cout << #x << " = " << (x) << endl;
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//グラフ用
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};	
//ここから書き始める

ll combination(ll n, ll i){
	ll count = 0;
	ll multi = 1;
	ll div =1;
	int limit = i;
	while(count < limit){
		multi *= n;
		n--;
		multi/= count+1;
		count ++ ;
	}
	return multi / div;
}

int main()
{
	cout <<setprecision(10);
	int n , i ;
	string s ,t ;
	cin >> n >> s >> t;

	for(i = 0 ; i < n ; i++){
		if(s.substr(i,n-i)==t.substr(0,n-i)){
			break;
		}
	}
	cout << n + i << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<double> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef pair<int,pii> pip;
typedef vector<pip>vip	;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1<<30;
int sosu[1000001]={1,1,0};
int main(){
	for(int i=2;i*i<=1000001;i++)if(sosu[i]==0)
	for(int j=i*2;j<1000001;j+=i)sosu[j]=true;
	rep(i,1000001)sosu[i]^=1;
	rep(i,1000000)sosu[i+1]+=sosu[i];
	
	int n;
	while(cin>>n,n){
		int out=0;
		rep(i,n){
			int a,b;
			cin>>a>>b;
			int s=max(0,a-b-1),t=min(a+b,1000000);
			int co=sosu[t]-sosu[s];
			if(co==0)out--;
			else out+=co-1;
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 5064
#include<iostream>
#include<cstdio>
#define ll long long  

using namespace std;

ll xor_n(ll n)
{
    ll t=n&3;
    if (t&1) return t/2ull^1;
    return t/2ull^n;
}

int main()
{
	ll a,b;
	cin>>a>>b;
	ll o=xor_n(a-1);
	ll u=xor_n(b);
	o=o^u;
	cout<<o<<endl;
	return 0;
 } 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back

using namespace std;
using ll = long long;
using P = pair<int,int>;

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

int main() {
  int n,m;
  cin >> n >> m;
  int ans = 0;
  if(n >= 2) {
    ans += n * (n - 1) / 2;
  }
  if(m >= 2) ans += m * (m - 1) / 2;
  cout << ans << endl;

  return 0;
}


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

int main() {
  ll h, n;
  cin >> h >> n;
  ll a;
  rep(i,n){
    cin >> a;
    h -= a;
  }
  if(h<=0) {
    cout << "Yes"  << endl;
  }
  else {
    cout << "No" <<endl;
  }
  return 0;
}


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

using namespace std ;
typedef long long ll;
typedef pair <int , int >pi;
typedef vector <int> vi ;
typedef vector <string> si;



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

	int i ;
	cin >> i ;

	if ( i >= 30) {
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0 ;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, m, a[100100], res;
map<ll, ll> mp;

int main(void){
    // Your code here!
    cin >> n >> m;
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (ll i = 0; i <= n; i++) {
        mp[a[i] % m]++;
    }
    for (auto itr = mp.begin(); itr != mp.end(); ++itr){
        if (itr->second < 2) continue;
        res += itr->second * (itr->second - 1) / 2;
    }
    cout << res << endl;
}


Measured memory_bytes: 4992
from collections import Counter

N = int(input())
V = list(map(int, input().split()))

even_cnt = Counter(V[0::2])
odd_cnt = Counter(V[1::2])

even_kv = [(k, v) for k, v in even_cnt.items()]
odd_kv = [(k, v) for k, v in odd_cnt.items()]

even_kv.append((None, 0))
odd_kv.append((None, 0))

even_kv.sort(key=lambda kv: -kv[1])
odd_kv.sort(key=lambda kv: -kv[1])

if even_kv[0][0] == odd_kv[0][0]:
    count = max(even_kv[0][1]+odd_kv[1][1],
                even_kv[1][1]+odd_kv[0][1])
else:
    count = even_kv[0][1] + odd_kv[0][1]
print(N-count)

Measured memory_bytes: 27132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int h = Integer.parseInt(sa[1]);
		int[] a = new int[n];
		int[] b = new int[n];
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]);
			b[i] = Integer.parseInt(sa[1]);
		}
		br.close();

		int max = 0;
		for (int i = 0; i < n; i++) {
			max = Math.max(max, a[i]);
		}

		Arrays.parallelSort(b);
		List<Integer> list = new ArrayList<Integer>();
		int ans = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (b[i] < max) {
				break;
			}
			list.add(b[i]);
			h -= b[i];
			ans++;
			if (h <= 0) {
				System.out.println(ans);
				return;
			}
		}

		System.out.println(ans + (h + max - 1) / max);
	}
}


Measured memory_bytes: 48996
N, X, M = map(int,input().split())
ans = 0
ls = [X%M] + [-1]*(M+1)
ls_app = [0]*(M+1)

for i in range(N):
    a = ls[i]
    ls_app[a] = i
    ls[i+1] = pow(a,2,M)
    if i+1 < N and ls_app[ls[i+1]] != 0:
        b = ls[i+1]
        L = ls.index(b)
        R = i
        len_roop = R - L + 1
        p = (N - L) // len_roop
        q = (N - L) % len_roop
        break
else:
    for i in range(N):
        ans += ls[i]
    print(ans)   
    exit()
    
sum_roop = 0        
for i in range(L, R+1):
    sum_roop += ls[i]
    
sum_edge = 0
for i in range(L, L+q):
    sum_edge += ls[i] 
    
for i in range(L):
    ans += ls[i]
else:
    ans += sum_roop * p + sum_edge        
    
print(ans) 

Measured memory_bytes: 13320
n, k = map(int, input().split())

from math import factorial
# math.factorial(n) nの階乗

def combination(n, k):
    return factorial(n) // factorial(k) // factorial(n - k)

for i in range(1, k+1):
    if i <= n-k+1:
        print(combination(n-k+1, i)*combination(k-1,i-1)%(10**9+7))
    else:
        print(0)


Measured memory_bytes: 69976
# dp
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
dp = [[0]*(N) for _ in range(2)]

dp[0][0] = A[0][0]
dp[1][0] = A[0][0] + A[1][0]
for i in range(1, N):
  dp[0][i] = dp[0][i-1] + A[0][i]
  dp[1][i] = max(dp[0][i],dp[1][i-1]) + A[1][i]
  
print(dp[1][-1])  

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

int main(){
    string S;
    int ans = 0;

    cin >> S;

    for (int i = 0; i < 4; i++){
        if (S[i] == '+')
            ans++;
        else
            ans--;
        }


        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++)
const int INF = 1e9;

int main(){
  int h, n;
  cin >> h >> n;
  int a[n], b[n];
  int m = 1;
  rep(i,n) {
    cin >> a[i] >> b[i];
    m = max(m,a[i]);
  }
  int d = h+m+1;
  vector<int> dp(d,INF);
  dp[0] = 0;
  rep(i,n) {
    rep(j,d) {
      if(j-a[i] >= 0) dp[j] = min(dp[j],dp[j-a[i]]+b[i]);      
    }
  }
  int ans = INF;
  for(int i = h; i < d; i++) ans = min(ans,dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
#define w(x) int x; cin>>x; while(x--)
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
int main(){
#ifndef ONLINE_JUDGE 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll a,b;
	cin>>a>>b;
	if(a%b==0)
		cout<<a/b;
	else
		cout<<a/b+1;

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int l, r, d;
  cin >> l >> r >> d;
  cout << r/d - (l-1)/d << "\n";
  return 0;
}


Measured memory_bytes: 3648