akhauriyash/Code-Regression huggingface dataset:
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int mod=1e9+7;
inline int qpow(int a,int b) { int c=1;
    for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) c=1ll*c*a%mod;
    return c;
}

int n,X,Y,Z;
int dp[45][1<<17];

int main() {
    n=read(),X=read(),Y=read(),Z=read();
    int Haiku=(1<<(Z-1))|(1<<(Y+Z-1))|(1<<(X+Y+Z-1));
    int lim=(1<<(X+Y+Z))-1;
    dp[0][0]=1;
    for (re int i=0;i<n;++i)
        for (re int S=0;S<=lim;++S) {
            if (!dp[i][S]) continue;
            for (re int j=1;j<=10;++j) {
                int T=((S<<j)|(1<<(j-1)))&lim;
                if ((T&Haiku)!=Haiku)
                    dp[i+1][T]=(dp[i+1][T]+dp[i][S])%mod;
            }
        }
    int ans=0;
    for (re int i=0;i<=lim;++i) ans=(ans+dp[n][i])%mod;
    printf("%d\n",(qpow(10,n)-ans+mod)%mod);
    return 0;
}


Measured memory_bytes: 20864
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	int X;
	int T;
	cin >> N >> X >> T;
	int A = N % X;
	int B = (N - A) / X;
	int ans;
	if (A > 0) {
		ans = (B + 1) * T;
	} else {
		ans = B * T;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
    
    int H, W;
    cin >> H >> W;
    char a[102][102];
    
    for(int i = 0; i <= H+1; i++){
        for(int j = 0; j <= W+1; j++){
            if(i == 0 || i == H+1 || j == 0 || j == W+1) a[i][j] = '#';
            else cin >> a[i][j];
            
        }
    }
    
    for(int i = 0; i <= H+1; i++){
        for(int j = 0; j <= W+1; j++){
            cout  << a[i][j];
        }cout << endl;
    }

} 


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<vector<pair<int, int>>> g(n);
  for(int i=0;i<n-1;++i) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;v--;
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  stack<int> st;
  vector<bool> sel(n);
  st.push(0);
  sel[0] = true;
  vector<int> ans(n, -1);
  ans[0] = 0;
  while(!st.empty()) {
    int now = st.top(); st.pop();
    int sz = g[now].size();
    for(int i=0;i<sz;++i) {
      pair<int, int> nt = g[now][i];

      if(!sel[nt.first]) {
        sel[nt.first] = true;
        if(nt.second % 2 == 0) {
          ans[nt.first] = ans[now];
        } else {
          ans[nt.first] = !ans[now];
        }
        st.push(nt.first);
      }
    }
  }
  for(int i=0;i<n;++i) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 6784
from collections import deque
N,K = map(int,input().split())
H = list(map(int,input().split()))
H.sort(reverse=True)
deqH = deque(H)
if N <= K:
    print(0)
else:
    for i in range(K):
        deqH.popleft()
        #H.remove(max(H))
        #print(H)
    print(sum(deqH))


Measured memory_bytes: 106736
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
#define Maxn 100010
int h[Maxn];
int main(){
	scanf("%d",&n);
	bool flag=true;
	for(register int i=1;i<=n;++i)scanf("%d",&h[i]);
	for(register int i=1;i<n;++i){
		if(h[i]!=h[i-1])h[i]--;
	}
	for(register int i=1;i<n;++i)
	    if(h[i]>h[i+1])flag=false;
	if(flag)puts("Yes");
	else puts("No");
} 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b, t;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b >> t;
	cout << t / a * b << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
     
    while(true){
        int n,m,a;
        int h,p,q;
        cin >> n >> m >> a;
        if(n==0&&m==0&&a==0){
                break;
        }
         
        int amida[101][1001]={{0}};
         
        for(int i=0;i<m;i++){
            cin >> h >> p >> q;
            amida[p][h]=1;
        }
         
        for(int j=1000;j>0;j--){
            if(amida[a][j]==1) a++; //????????????
            else if(amida[a-1][j]==1) a--; //???
        }
         
        cout << a << endl;
    }
     
    return 0;
}

Measured memory_bytes: 1564
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,M=MAP()
L=LIST()
maxa=-(10**10)
sums=sum(L[:M])
maxa=max(maxa,sums)
for i in range(N-M):
  sums=sums-L[i]+L[i+M]
  maxa=max(maxa,sums)
print((maxa+M)/2)

Measured memory_bytes: 32356
#部分集合組(Sk)がmこあると仮定すると、S1とS2...Sm,S2とS3...Sm,...,Sm-1とSmの、1*m-1C2=Σ(1<=i<=m-1)i=(m(m-1)/2)組の共通要素をとることがわかる
#これら共通要素関係をs1==s2,s1==s3,....,s1==sm,s2==s3,s2==s4,...s2==sm,.......,sm-1==smと捉えると、(Siのある数字siとSjのある数字sjが一致という意味)
#共通要素関係について以下のことがわかる

#*si==sj、sk==slにて、i!=kまたはj!=l(<=>not((i==k)and(j==l)))ならば(si==sj)!=(sk==sl)

#(i)(i==k),(j==l),(j==k),(i==l)のいずれか一つの関係をとる時、i==kのみ時のみ考えれば十分である。
#*の前提が成り立たないとすれば、si==sj、sk==slの関係はsi==sj、si==slの関係で、si==sj==slとなり、Sに3つ同じ整数が入ることとなり矛盾
#(ii)(i==k),(j==l),(j==k),(i==l)の関係をどれもとらない時、
#*の前提が成り立たないとすれば、si==sj、sk==slの関係でsi==sj==sk==slとなり、Sに4つ同じ整数が入ることとなり矛盾
#よって、(m(m-1)/2)この共通要素は各々異なる整数で共通要素をとるということがわかる。

#一方ここまでの考察で、共通要素を取らない整数はN-(m(m-1)/2)こあることがわかるが、実はこれは0でなければならない
#共通要素を取らない整数をSaとSbに割り振ったとする
#(i)a!=bの時、sa==sbという、新たな共通要素ができる。ただ一番最初に任意の二つの集合をとってsi==sjの関係を前もって関係を構成した前提で議論しているため、どれか一つは共通要素が2つ以上になってしまい、矛盾
#(ii)a==bの時、ある集合Saに同じ数字が2つ含まれることになるが、{1,2,..N}の部分集合の組にならず矛盾。

#以上の議論からN=(m(m-1))/2<=>2N=m(m-1)が成り立つmにて、Skの数がmこになるよう、(m(m-1))/2この関係をs1==s2==1,s1==s3==2,...,s1==sm==m-1,s2==s3==m,s2==s4==m+1,...,sm-1==sm==(m(m-1))/2のように割り振ればok
#(すると、Skの要素数は自然と2N/m=m-1で揃う)

N=int(input())
num=0
flag=0
#N<=10^5なので2<=m<1000を探せば十分
for i in range(2,1000):
    if 2*N==i*(i-1):
        num=i
        flag=1
        break
if flag==0:
    print("No")
else:
    l=[[] for _ in range(num)]
    cnt=1
    for i in range(num):
        for j in range(i+1,num):
            l[i].append(cnt)
            l[j].append(cnt)
            cnt=cnt+1
    print("Yes")
    print(num)
    for i in range(num):
        print(num-1,*l[i],sep=" ")


Measured memory_bytes: 47068
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    string S;
    cin>>S;
    S = " " + S;
    
    for(char c='a'; c<='z'; c++){
        int pre=-2;
        rep(i,S.size()){
            if(S[i]==c){
                if(i-pre<=2){
                    cout2(pre,i);
                    return 0;
                }else{
                    pre=i;
                }
            }
        }
    }
    cout2(-1,-1);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int N=200010;
ll a[N];
int n, m;
int main(){
	int t;
	// while(){
		int k;
		scanf("%d%d",&n,&k);
		vector<ll> v, v1;
		ll mod=1e9+7;
		for(int i=0; i<n; ++i){
			scanf("%lld",a+i);
			if(a[i]>=0){
				v.push_back(a[i]);
			}
			else{
				v1.push_back(-a[i]);
			}
		}
		sort(v.begin(), v.end());
		sort(v1.begin(), v1.end());
		ll ans=1;
		if(n==k){
			for(int i=0; i<n; ++i){
				ans*=a[i];
				ans%=mod;
			}
			if(ans<0)ans+=mod;
			cout<<ans<<endl;
			return 0;
		}
		if(k%2){
			if(v.size()==0){
				for(int i=0; i<k; ++i){
					ans*=-v1[i];
					ans%=mod;
				}
				if(ans<0)ans+=mod;
				cout<<ans<<endl;
				return 0;
			}
			--k;
			ans=v.back();
			v.pop_back();
		}
		while(k>0){
			ll tmp1=-1, tmp2=-1;
			if(v.size()>=2){
				tmp1=v.back()*v[((int)v.size())-2];
			}
			if(v1.size()>=2){
				tmp2=v1.back()*v1[((int)v1.size())-2];
			}
			assert(tmp1>=0 || tmp2>=0);
			if(tmp1>tmp2){
				tmp1%=mod;
				ans*=tmp1;
				ans%=mod;
				v.pop_back();
				v.pop_back();
			}
			else{
				tmp2%=mod;
				ans*=tmp2;
				ans%=mod;
				v1.pop_back();
				v1.pop_back();
			}
			k-=2;
		}
		ans%=mod;
		if(ans<0)ans+=mod;
		cout<<ans<<endl;
		return 0;
}

Measured memory_bytes: 6616
#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--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n,m,q;cin>>n>>m>>q;
  vector<vector<int>>t(n+1, vector<int>(n+1));
  rep(i, m){
    int l,r; cin>>l>>r;
    l--;r--;
    t[l][r]++;
  }
  rep(i, n)rep(j, n-1)t[i][j+1] += t[i][j];
  rrep1(i, n-1)rep(j, n)t[i-1][j] += t[i][j];

  rep(i, q){
    int l,r; cin>>l>>r;
    l--;r--;
    cout<<t[l][r]<<endl;
  }

  return 0;

  rep(i, n){
    rep(j, n)cout<<t[i][j]<<' ';
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 1920
import sys
import numpy as np

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    _ = INT()
    A = np.array(LIST())
    ans = A.argsort() + 1
    print(*ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 23472
n = int(input())
a = list(input())
b = list(input())
c = list(input())
d = []
for i in range(n):
    if a[i] == b[i] == c[i]:
        d.append(0)
    elif a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
        d.append(1)
    else:
        d.append(2)
print(sum(d))

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    long a,b,ans=0,nans=0,i;
    cin>>a>>b;
    
    if(a<=b)
    {
        ans = a;
        nans = b;
    }
    else
    {
        ans = b;
        nans = a;
    }
        
    for(i=0;i<nans;i++)
    {
        cout<<ans;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
    unsigned int a = 200010, z = 0;
    char s[200010];

    scanf("%s", s);

    for (unsigned int i = 0; i < strlen(s); ++i) {
        if (s[i] == 'A' && a >= i) {
            a = i;
        }

        if (s[i] == 'Z') {
            z = i + 1;
        }
    }

    printf("%i\n",z - a);
    return 0;
}

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

vector<pair<ll, ll>> prime_factorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; a++)
    {
        if (N % a != 0)
        {
            res.push_back({a, 0});
            continue;
        }
        ll ex = 0; // 指数

        // 割れる限り割り続ける
        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }

        // その結果を push
        res.push_back({a, ex});
    }

    // 最後に残った数について
    if (N != 1)
    {
        res.push_back({N, 1});
    }
    return res;
}

int main()
{
    ll A, B;
    cin >> A >> B;

    vector<pair<ll, ll>> prime_factors_a = prime_factorize(A);
    vector<pair<ll, ll>> prime_factors_b = prime_factorize(B);

    ll ans = 1;
    for (int i = 0; i < min(prime_factors_a.size(), prime_factors_b.size()); i++)
    {
        auto a = prime_factors_a.at(i);
        auto b = prime_factors_b.at(i);
        if (a.first == b.first && a.second > 0 && b.second > 0)
        {
            ans++;
        }
    }

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

Measured memory_bytes: 41808
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;


int a,b,ab;

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

    ab = a * b;
    if(ab % 2 == 0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
 
    
    
    return 0;
}


Measured memory_bytes: 3096
c[100],n,k,a,b,x,y,M,m;Z(){for(x=a=0;a<=n-k;x=x>y?x:y,a++)for(y=1,b=0;b<k;b++)y*=c[a+b];}
main(i,j,t){for(;scanf("%d%d",&n,&k),n;printf("%d\n",m-M)){
	for(i=0;i<n;i++)scanf("%d",c+i);
	Z();M=x;
	for(m=i=0;i<n;i++)for(j=i+1;j<n;j++){
		t=c[i],c[i]=c[j],c[j]=t;
		Z();m=m>x?m:x;
		t=c[i],c[i]=c[j],c[j]=t;
	}
}exit(0);}

Measured memory_bytes: 600
from collections import defaultdict

n = int(raw_input())
arr = map(int, raw_input().split())

cnt = defaultdict(int)
for x in arr:
    cnt[x] += 1

ans = 0
for k in cnt:
    if cnt[k] >= k:
        ans += cnt[k] - k
    else:
        ans += cnt[k]

print ans


Measured memory_bytes: 54592
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

N, K = map(int, input().split())
A = np.array(list(map(int, input().split())))

roop = []
flg = [0] * (N+1)
k = 1 
while True:
	roop.append(k)
	flg[k] = 1
	k = A[k-1]
	if flg[k] == 1:
		root = k
		break

i = 0
while True:
	if roop[i] == root:
		break
	i += 1

l_saisho = i
l_roop = len(roop) - i

if K < l_saisho:
	print(roop[K])
else:
	K -= l_saisho
	div, mod = divmod(K, l_roop)
	print(roop[i:][mod])

Measured memory_bytes: 51028
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
using namespace std;

bool isPal(int n) {
  string s;
  while(n) {
    s.pb((char)(n%10 + '0'));
    n /= 10;
  }
  string s2(s);
  reverse(s2.begin(), s2.end());
  return s == s2;
}

int main() {
  int a,b;
  cin>>a>>b;
  int ans = 0;
  fr(i,a,b+1) {
    ans += isPal(i);
  }
  cout<<ans;
}

Measured memory_bytes: 256
var
  k,s,i,j,x,sum:longint;
begin
  readln(k,s);
  for i:=0 to k do
    for j:=0 to k do
    begin
      x:=s-i-j;
      if (i+j+x=s) and (x>=0) and (x<=k) then inc(sum);
    end;
  writeln(sum);
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, M, V, P; cin >> N >> M >> V >> P;
  vector<ll> A(N, 0);
  REPLL(i, N){
    cin >> A[i];
  }
  sort(A.begin(), A.end());
  vector<ll> AA(N, 0);
  REPLL(i, N){
    if(i){
      AA[i] = AA[i-1] + A[i];
    }else{
      AA[i] = A[i];
    }
  }
  ll res = 0;
  REPLL(i, N-P){
    if(A[N-P] > A[i]+M || (N-P-i)*(A[i]+M)-(AA[N-P]-AA[i]) < M*V-M*(P+i > V ? V : P+i)){
      res++;
    }
  }
  cout << N - res << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;

int main()
{
    int K;
    string S;
    cin >> K >> S;
    
    if (K >= S.size()) {
        cout << S << endl;
    } else {
        string T = S.substr(0, K);
        T += "...";
        cout << T << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
N=int(input())
A=list(map(int,input().split()))
oneton=(N*(N+1))//2
flag=1
allsum=sum(A)
dif=[]
for i in range(N):
    dif.append(A[(i+1)%N]-A[i%N])
#print(dif)
#print(allsum,oneton)
if allsum%oneton!=0:
    flag=0
else:
    opnum=allsum//oneton        
    l=[opnum]*N                 
    #print(l)
    for i in range(N):
        if l[i]<dif[i]:         
            flag=0
            break
        else:                   
            diff=l[i]-dif[i]    
            useminus=diff//N    
            opnum=opnum-useminus
            l[i]=l[i]-(useminus*N)
    if opnum!=0:                    
        flag=0
    for i in range(N):              
        if l[i]!=dif[i]:
            flag=0
if flag==0:
    print("NO")
else:
    print("YES")




Measured memory_bytes: 64412
#include <iostream>
using namespace std;
int m,n,conx[200],cony[200],fieldx[1000],fieldy[1000],sconx[200],scony[200];

void solve() {

  for(int i=0;i<n;i++) {
    bool detect;
    for(int j=0;j<m;j++) {
      sconx[j] = conx[j] + (fieldx[i]-conx[0]);
      scony[j] = cony[j] + (fieldy[i]-cony[0]);
    }

    for(int j=0;j<m;j++) {
      detect = false;
      for(int k=0;k<n;k++) {
        if(sconx[j] == fieldx[k] && scony[j] == fieldy[k]) {
          detect = true;
        }
      }
      if(!detect) break;
    }
    if(!detect) continue;
    cout << fieldx[i]-conx[0] << " " << fieldy[i]-cony[0] << endl;
  }
}

int main() {
  while(cin >> m) {
    if(m == 0) break;
    for(int i=0;i<m;i++) {
      cin >> conx[i] >> cony[i];
    }
    cin >> n;
    for(int i=0;i<n;i++) {
      cin >> fieldx[i] >> fieldy[i];
    }
    solve();
  }
}

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

using namespace std;


int main() {
    long long N,K; cin >> N >> K;
    long long ans = 0ll;

    if(K==0) {
        cout << N*N << endl;
        return 0;
    }

    for(long long b=1ll;b<=N;b++) {
        long long res = N%b;
        long long p = N/b;
        ans += p * max(0ll, b-K) + max(0ll, res-K+1ll);
    }

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


Measured memory_bytes: 256
import Foundation
// Decimal型の有効桁数は38桁
let N = readLine()!.components(separatedBy: " ").map { Int($0)! }.first!
let A = readLine()!.components(separatedBy: " ").map { Int($0)! }
let sortedA = A.sorted()

var dp = Array(repeating: true, count: sortedA.last! + 1)
var count = 0

for i in 0..<N {
    guard dp[sortedA[i]] else { continue }
    if 0 < i, sortedA[i] == sortedA[i - 1] {
        dp[sortedA[i]] = false
    }
    
    var a = sortedA[i] * 2
    while a <= sortedA.last! {
        dp[a] = false
        a += sortedA[i]
    }
}

for i in 0..<N {
    if dp[A[i]] {
        count += 1
    }
}

print(count)


Measured memory_bytes: 21124
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(){
    int bunndo[10]={1,2,4,8,16,32,64,128,256,512},n,cnt=0;
    while(cin>>n){
        bool num[10]={0};
        for(int i=9;i>=0;i--){
            if(n-bunndo[i]>=0){
                n=n-bunndo[i];
                num[i]=1;
                if(n==0)break;
            }
        }
        for(int i=0;i<10;i++){
            if(num[i]==1){
                if(cnt==0){
                    cnt=1;
                    cout<<bunndo[i];
                }else{
                    cout<<" "<<bunndo[i];
                }
            }
        }
        cnt=0;
        cout<<endl;
    }
    return 0;
}

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

int main() {
  int A, B, a, b, c, d, e, cnt;
  cnt = 0;
  cin >> A >> B;

  for (int i = A; i < B + 1; i++) {
    a = i / 10000;
    b = (i / 1000) % 10;
    c = (i / 100) % 10;
    d = (i / 10) % 10;
    e = i % 10;

    if (a == e && b == d) {
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
n, m, l = map(int, input().split())
a = [[v for v in list(map(int, input().split()))] for i in range(n)]
b = [[v for v in list(map(int, input().split()))] for i in range(m)]
c = [[sum([a[j][x] * b[x][i] for x in range(m)]) for i in range(l)] for j in range(n)]
for i in range(n):
    print(' '.join(map(str, c[i])))

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

int main() {
	int n,x;cin>>n>>x;
	int m[n];
	int min=10000;
	for(int i=0;i<n;i++){
		cin>>m[i];
		x-=m[i];
		if(min>m[i])min=m[i];
	}
	int ans=n;
	ans+=x/min;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int A, B, K;

  cin >> A >> B >> K;

  for (int i=A; i<=B; i++) {
    if (i < A+K || B-K < i) {
      printf("%d\n", i);
    } else {
      i = B-K;
    }
  }

  return 0;
}


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

struct order {
	int p, c;
};

int main()
{
	int n, r, p;
	vector<order> o;
	order t;
	
	while (cin >> n >> r, n | r) {
		o.clear();
		p = 1;
		
		for (int i = 0; i < r; i++) {
			cin >> t.p >> t.c;
			o.push_back(t);
		}
		
		for (int i = o.size() - 1; i >= 0; i--) {
			if (p <= o[i].c) {
				p += o[i].p - 1;
			} else if (p - o[i].c <= o[i].p - 1) {
				p = p - o[i].c;
			}
		}
		
		cout << n - p + 1 << endl;
	}
	
	return 0;
}

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

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  COMinit();
  int n,k;
  long long m;
  cin >> n >> m >> k;
  if(m==1){
    if(k==n-1)cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
  }
  long long ans=0,p=998244353;
  long long q[n];
  q[0]=1;
  rep(i,n-1)q[i+1]=(m-1)*q[i]%p;
  rep(i,k+1){
    //if(i<=10)cout << COM(n-1,i) << " " << m << " " << q[n-1-i] << endl;
    ans=(ans+((COM(n-1,i)*m)%p)*q[n-1-i])%p;
    //if(i<=100)cout << ans << endl;
  }
  cout << ans << endl;
}

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

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef long long ll;
typedef pair<int, int> pi;

int n;
vector<vector<int> > adjList, id;
vector<int> start, finish, dp;
bool isCycle;

int backtrack(int node){

    if (start[node] != -1 && finish[node] == -1)
        isCycle = true;

    int &ret = dp[node];
    if (ret != -1) return ret;

    ret = 0;
    start[node] = 1;
    for (auto child : adjList[node])
        ret = max(ret, backtrack(child) + 1);

    finish[node] = 1;
    return ret;
}

int mapping(int x, int y){
    if (x>y) swap(x, y);
    return id[x][y];
}

int main() {
    //freopen("in.txt", "r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>n;
    int e = n*(n-1); e/=2;
    
    adjList.assign(e, vector<int>());
    id.assign(n, vector<int>(n));
    start.assign(e, -1);
    finish.assign(e, -1);
    dp.assign(e, -1);

    int A[n][n];
    for (int i=0;i<n;++i){
        for (int j=0;j<n-1;++j){
            cin>>A[i][j];
            A[i][j]--;
        }
    }

    int cnt = 0;
    for (int i=0;i<n;++i){
        for (int j=i+1;j<n;++j){
            id[i][j] = cnt++;
        }
    }

    for (int i=0;i<n;++i){
        for (int j=0;j<n-1;++j){
            A[i][j] = mapping(i, A[i][j]);
        }
    }

    for (int i=0;i<n;++i){
        for (int j=0;j<n-2;++j){
            adjList[A[i][j]].emplace_back(A[i][j+1]);
        }
    }

    int ans = 0;
    for (int i=0;i<e;++i){
        ans = max(ans, backtrack(i) + 1);
    }

    if (isCycle) cout<<"-1"<<endl;
    else cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 41472
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
using namespace std;
typedef long long ll;
#define free  freopen ("input.txt", "r", stdin);freopen ("output.txt", "w", stdout);
#define Fast  ios::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second

bool vowel(char che)
{
    if (che == 'A' || che == 'E' || che == 'I' || che == 'O' || che == 'U' || che == 'Y')
        return true;
    else
        return false;
}

const int N = 1e6+5;
const int mod = 1e9+7;
ll a[N], b[N], c[N], d, dp, dis, tree[N];
pair <int, int> p;
char o;
bool mark[N], h;
string s, s1;
stack <int> st;
set <ll> st1, st2;
deque <int> dq;
vector <int> vt, vs, vm;
//int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};


int main()
{
    Fast
    ll t, n, m, k = 0, f = 0, sum = 0, ans = 0, n1 = 0;
    cin  >> s;
    n = s.size();
    cout << s;
    if (s[n-1] == 's')
        cout << "es";
    else
        cout << "s";
}


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

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0) break;

    unsigned int p = 0,ptmp;
    int j[65000];

    for(int i = 0;i < n;i++){
      scanf("%d",&ptmp);
      p += ptmp;
    }
    for(int i = 0;i < n-1;i++) scanf("%d",&j[i]);

    sort(j,j+n-1,greater<int>());

    int ntmp = n;

    for(int i = 0;i < n-1;i++){
      if(p * ntmp <= (p+j[i]) * (ntmp-1)){
        ntmp--;
        p += j[i];
      }else{
        break;
      }
    }
    cout << p * ntmp << endl;
  }
  return 0;
}





Measured memory_bytes: 3440
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#define DIVCEIL(A,B) ((A+(B-1))/B)
using namespace std;
#define LL long long

void solve(long long N, long long H, std::vector<long long> a, std::vector<long long> b){
    priority_queue<pair<LL, LL>> q;
    for(LL i=0; i<N; i++){
        q.push(make_pair(a[i], 0));
        q.push(make_pair(b[i], 1));
    }
    LL ans=0;
    while(H>0){
        auto p = q.top();
        if(p.second){
            H-=p.first;
            ans++;
            q.pop();
        }else{
            ans += (H+p.first-1)/p.first;
            break;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long H;
    scanf("%lld",&H);
    std::vector<long long> a(N);
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, H, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 7792
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int mod=1e9+7;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
ll qpow(ll a,ll b){ll ans=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)ans=ans*a%mod;a=a*a%mod;}return ans;}
ll gcd(ll a,ll b){return b>0?gcd(b,a%b):a;}

int a[maxn];

int main(){
    ll n,m,T;
    ll k,a,b;
    cin>>k>>a>>b;
    if(b-a>2&&k>=a+1){
        ll temp=k-a+1;
        ll ans=a+1ll*(temp/2)*(b-a)+temp%2;
        //cout<<temp<<"--------"<<(temp/2)*(b-a)<<endl;
        cout<<ans<<endl;
    }else{
        cout<<k+1<<endl;
    }

    return 0;
}



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

int main(void){
    int n,k;
    string s;
    cin >> n >> s >> k;
    for(int i = 0;i < n;i++){
        if(s[i] != s[k-1])cout << "*";
        else cout << s[i];
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int horieyui[2048];

int main(void) {
	int N, X, Y;
	int node, kyori;
	if (scanf("%d%d%d", &N, &X, &Y) != 3) return 1;
	/* 双方向なので、自分より大きい番号の頂点だけ見ればよい */
	for (node = 1; node <= N; node++) {
		for (kyori = 1; kyori < N; kyori++) {
			if (node <= X) {
				if (X - node >= kyori) {
					horieyui[kyori]++;
				} else {
					int yoryoku = kyori - (X - node) - 1;
					int left = node + kyori;
					int right = Y - yoryoku;
					if (left < right) {
						horieyui[kyori] += 2;
					} else if (left == right) {
						horieyui[kyori]++;
					}
					if (yoryoku > 0 && N - Y >= yoryoku) {
						horieyui[kyori]++;
					}
				}
			} else if (node <= Y) {
				int saitan_y_direct = Y - node;
				int saitan_y_candidate = (node - X) + 1;
				int is_direct = saitan_y_direct <= saitan_y_candidate;
				int saitan_y = is_direct ? saitan_y_direct : saitan_y_candidate;
				if (is_direct) {
					if (N - node >= kyori) horieyui[kyori]++;
				} else {
					if (kyori < saitan_y) {
						horieyui[kyori]++;
					} else {
						int back_nokori = kyori - saitan_y;
						if (kyori + back_nokori < Y - node) {
							horieyui[kyori] += 2;
						} else if (kyori + back_nokori == Y - node) {
							horieyui[kyori]++;
						}
						if (N - Y >= back_nokori && back_nokori > 0) {
							horieyui[kyori]++;
						}
					}
				}
			} else {
				if (N - node >= kyori) horieyui[kyori]++;
			}
		}
	}
	for (kyori = 1; kyori < N; kyori++) {
		printf("%d\n", horieyui[kyori]);
	}
	return 0;
}


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

int main(){
  int x;cin>>x;
  double i=2;
  double ans=1;
  if(x==1000){ans=x;}
  else{
    while(i<10){
      double d=1/i;
      int p =pow(x,d);
      ans=max(ans,pow(p,i));
      //cout<<p<<" "<<d<<" "<<pow(p,i)<<endl;
      i++;
    }
  }
  cout<<ans;

}

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

const ll MOD = 1e9+7;

//verified AOJ GRL_3
#define MAX_V 1000
vector<int> G[MAX_V];   //辺
vector<int> rG[MAX_V];  //逆辺
vector<string> str;

void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v, bool used[MAX_V], vector<int> &vs){     //末端から遠いノードから順に、たどり着けるノードをvsに入れていく
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){   //逆辺を使って末端に近いノードから順にDFS
    used[v] = true;
    sccs.push_back(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }
    
    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.push_back(sccs);
        }
    }
    return k;
}

void getSccedGraph(vector<vector<int>> each_scc, vector<int> cmp, vector<int> newGraph[MAX_V]){   //sccの結果からグラフを得る O(E)くらい？ verified ARC030-C
    rep(i,each_scc.size()){
        set<int> edges;
        rep(j,each_scc[i].size()){
            rep(k,G[each_scc[i][j]].size()){
                int to = G[each_scc[i][j]][k];
                if( cmp[to]!=i )edges.insert(cmp[to]);
            }
        }
        for(auto &edge:edges)newGraph[i].pb(edge);
    }
}

vector<int> nG[MAX_V], rnG[MAX_V];

ll dp[MAX_V];
ll dfs(int cur){
    if(dp[cur]!=-1)return dp[cur];
    if(rnG[cur].size()==0)return dp[cur] = 2;
    
    ll ret = 1;
    for(auto e:rnG[cur]){
        (ret *= dfs(e))%=MOD;
    }
    
    return dp[cur] = (ret+1)%MOD;
}


int main(){
    rep(i,MAX_V)dp[i] = -1;
    int v,e;
    cin>>v>>e;
    
    rep(i,e){
        int s,t;
        cin>>s>>t;
        s--,t--;
        
        add_edge(s,t);
    }
    vector<vector<int>> each_scc;  //それぞれの強連結成分のリスト
    vector<int> cmp(MAX_V);        //あるノードが属している強連結成分の番号( 多分each_sccに対応している )
    int k = scc(v,each_scc,cmp);   //強連結成分の個数
    
    getSccedGraph(each_scc, cmp, nG);
    
    rep(i,MAX_V){
        for(auto e:nG[i]){
            rnG[e].pb(i);
        }
    }
    
    vector<int> zero_deg;
    rep(i,k){
        if(nG[i].size()==0)zero_deg.pb(i);
    }
    
    
    ll ans = 1;
    for(auto elm:zero_deg){
        (ans *= dfs(elm))%=MOD;
    }
    cout<<ans<<endl;
    
}



Measured memory_bytes: 3440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 110;
int dp[maxn][maxn];
int main()
{
    int n;
    cin>>n;
    for (int k = 0; k <=9 ; k ++) {
        dp[1][k]=1;
    }
    for (int i = 2; i <=10 ; i ++) {
        for (int j = 0; j <=9 ; j ++) {
            dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
        }
    }
    queue<int> que;
    int l=0, r = 0, flag=0;
    for (int j = 1; j <=10 ; j ++) {
        for (int i = 1; i <=9 ; ++i) {
            if(n<=dp[j][i]){
                l=j;
                r=i;
                flag=1;
                break;
            }
            n-=dp[j][i];
        }
        if(flag==1)break;
    }
    l--;
    que.push(r);
    while(l!=0){
        if(n<=dp[l][r-1]){
            r--;
            que.push(r);
        }else{
            n-=dp[l][r-1];
            if(n<=dp[l][r]){
                que.push(r);
            }else{
                n-=dp[l][r];
                r++;
                que.push(r);
            }
        }
        l--;
    }
    while(!que.empty()){
        int now=que.front();
        cout<<now;
        que.pop();
    }
    return 0 ;
}


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

int main(){
	int N , M; cin >> N >> M;
	int a, b;
	vector<pair<int64_t, int>> c(N);//配列の宣言
for(int i = 0; i < N ; i++){
  cin >> a >> b;
  c[i] = make_pair(a,b);//配列型のpairに代入
}
sort(c.begin(),c.end());

	int64_t sum = 0;
	int j = 0;
	while(M > 0){
		if(M >= c[j].second ){
			sum += c[j].first * c[j].second;
			M -= c[j].second; 
		}
		else{
			sum += c[j].first * M;
			M = 0;
		}
		j++;
		
	}
	cout << sum << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<utility>
#include<cmath>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define all(v) v.begin(),v.end()
using namespace std;

const double eps = 1e-8;
const double INF = 1e5;

typedef pair<int,int> P;
typedef double Real;
typedef complex<Real> Point;
typedef vector<Point> G;

double cross(const Point& a,const Point& b){//calculate ad-bc(vector product)
	return imag(conj(a)*b);
}

struct L:public vector<Point>{//line data
	L(const Point &a,const Point &b){
		push_back(a);
		push_back(b);
	}
};

int main(){
	int n,m;
	while(1){
		cin>>n>>m;
		if(!n && !m)break;
		long long cost[m+1][m+1],ti[m+1][m+1];
		rep(i,m+1)rep(j,m+1)cost[i][j]=ti[i][j]=INF;
		int a,b,c,t;
		rep(i,n){
			cin>>a>>b;
			cin>>cost[a][b]>>ti[a][b];
			cost[b][a]=cost[a][b];
			ti[b][a]=ti[a][b];
		}
		loop(k,1,m+1){
			loop(i,1,m+1){
				loop(j,1,m+1){
					cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
					ti[i][j]=min(ti[i][j],ti[i][k]+ti[k][j]);
				}
			}
		}
		int k,p,q,r;
		cin>>k;
		rep(i,k){
			cin>>p>>q>>r;
			if(r==0){
				cout<<cost[p][q]<<endl;
			}else{
				cout<<ti[p][q]<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1320
/*input
5 3
1 2
3 4
5 1
*/

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

const int N = 200005;
vector<int> e[N];
vector<int> c;

int dfs(int id) {
    if (c[id] != 0) return 0;
    c[id] = 1;
    int res = 1;
    rep(i, e[id].size()) {
        res += dfs(e[id][i]);
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        e[a].push_back(b);
        e[b].push_back(a);
    }

    c.resize(n);
    int ans = 0;
    rep(i, n) {
        if (c[i] != 0) continue;
        ans = max(ans, dfs(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 21036
using System;
using System.Linq;

namespace AOJ.intro
{
    namespace ITP_1_4_D
    {
        static public class MinMaxAndSum
        {
            static public void Main()
            {
                int n;
                n = int.Parse(Console.ReadLine());
                var intArray = new long[n];

                string[] inputData = Console.ReadLine().Split();
                if(n != inputData.Length){
                    Console.WriteLine("The value is invalid.");
                    return;
                }
                
                for(int i = 0; i < n; ++i){
                    intArray[i] = int.Parse(inputData[i]);
                }
                Console.WriteLine("{0} {1} {2}",intArray.Min(), intArray.Max(), intArray.Sum());
            }
        }
    }
}


Measured memory_bytes: 10248
#include <bits/stdc++.h>
#define sp ' '
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod = 1000000007;
const int mod998 = 998244353;

int N, Z, W, a[2000];

int main() {
	cin >> N >> Z >> W;
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	cout << max(abs(W - a[N - 1]), ((N == 1) ? 0 : abs(a[N - 2] - a[N - 1]))) << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = IR(n)
    dp = [float("inf")]*n
    for i in a:
        j = bisect.bisect_left(dp,i)
        dp[j] = i
    print(n-dp.count(float("inf")))
    return

#Solve
if __name__ == "__main__":
    solve()



Measured memory_bytes: 10716
n = int(input())
d = [int(e) for e in input().split()]
d.sort()
sum = 0
if d[n//2] == d[n//2-1]:
    print(0)
    exit()
else:
    for i in range(d[n//2]-d[n//2-1]):
        #print(d[n//2-1]+i+1)
        sum+=1

print(sum)

Measured memory_bytes: 14428
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
long long int mod = 998244353;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<ll> G[100005];
vector<P> tree[100010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
//↓,→,↑,←
 
#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,a,b) for(i=a;i<=b;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll abc,ll bed){
	//aのb乗を計算する
	if(bed==0){return 1;}
	else{
		ll ced = rui(abc,bed/2);
		ced *= ced;
		ced %= mod;
		if(bed%2==1){ced*=abc; ced%=mod;}
		return ced;
	}
} 

ll i,j,k,ii,jj;
ll n,m,num,sumxor,sum,ans;
ll a,b,c,d,e,f,g,h,w,v;
ll x[800005],y[800005],z[900005];
char s[500][500];

ll gcd(ll x,ll y){
	if(y>x)swap(x,y);
	if(x==y || y==0){
		return x;
	}else{
		return gcd(y,x%y);
	}
}


int main(){	
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin >> a;
		x[i] = abs(a - k);
	}
	for(i=0;i<n-1;i++){
		x[i+1] = gcd(x[i],x[i+1]);
	}
	p(x[n-1]);
	
	return 0;
}

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

int main()
{
    int s;
    double w, h;
    char p;

    while( cin >> s >> p >> w >> p >> h )
    {
        double bmi = w / ( h * h );
        if( bmi >= 25 )
            cout << s << endl;
    }

    return 0;
}


Measured memory_bytes: 3164
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 998244353
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAXN = 6060;
int dp[MAXN],ndp[MAXN],n,s;
int a[MAXN],present[MAXN];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  cin >> n >> s;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  // present[0]=1;
  dp[0]=1;
  int ans = 0;
  for(int i=1;i<=n;i++){
    for(int j=0;j<MAXN;j++){
      ndp[j] = 0;
    }
    for(int j=MAXN-1;j>=0;j--){
      if(j+a[i]<MAXN && dp[j]>0 ){
        ndp[j+a[i]] = (ndp[j+a[i]]+dp[j])%mod;
        // cerr << j+a[i] << " -- " << ndp[j+a[i]] << endl;
      }
      ndp[j] = dp[j];
    }
    ndp[a[i]] = (ndp[a[i]]+i-1)%mod;
    for(int j=0;j<MAXN;j++){
      dp[j] = ndp[j];
    }
    ans = (ans+dp[s])%mod;
    // cerr << dp[2] << endl;
  }
  // cout << dp[2] << endl;
  // cout << dp[s] << endl;
  cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 384
// 4/29
// Greedyな過去問攻略

#include <iostream>
#include <string>
using namespace std;

int main() {
    // string coffee = "coffee";
    string S;
    cin >> S;

    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(int i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  vector<vector<ll>>a(h,vector<ll>(w));
  auto b=a;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h)rep(j,w)cin>>b[i][j];
  ll geta=80*160,sz=geta*2+7;
  vector<vector<vector<bool>>>dp(h,vector<vector<bool>>(w,vector<bool>(geta*2+7)));
  auto isin=[&](ll y,ll x){
    if(y>=0&&y<h&&x>=0&&x<w)return 1;
    return 0;
  };
  ll d=a[0][0]-b[0][0];
  dp[0][0][geta-d]=1;
  dp[0][0][geta+d]=1;
  rep(i,h)rep(j,w){
    //if(i==0&&j==0)continue;
    d=a[i][j]-b[i][j];
    rep(k,sz){
      if(isin(i-1,j)){
        if(dp[i-1][j][k]==0)continue;
        dp[i][j][k-d]=1;
        dp[i][j][k+d]=1;
      }
    }
    rep(k,sz){
      if(isin(i,j-1)){
        if(dp[i][j-1][k]==0)continue;
        dp[i][j][k-d]=1;
        dp[i][j][k+d]=1;
      }
    }
  }
  ll res=1e9;
  rep(i,sz){
    if(dp[h-1][w-1][i])chmin(res,abs(i-geta));
  }
  cout<<res<<endl;


  return 0;

}


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

string S;
string cf = "CODEFESTIVAL2016";

int main() {
    cin >> S;

    int ans = 0;
    for (int i = 0; i < S.length(); i++) {
        if (S[i] != cf[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256