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

s = input()

index = 0
count = 0

cash1 = ""
cash2 = ""

while(True):
    #もしindex==0なら、cash1にs[0]を格納
    if index == 0:
        cash1 = s[0]
#        print("count+1")
        count += 1
        index += 1
    #そうでないなら、cash2にs[index]を格納
    else:
        cash2 = s[index]

        #比較を行う
        #異なるならば
        if cash1 != cash2:
#            print("-----")
#            print("cash1="+cash1)
#            print("cash2="+cash2)
#            print("異なる")
            #cash1をcash2で更新して、次のループへ
            cash1 = cash2
#            print("count+1")
            count += 1
            index += 1
        #同じならば(cash1 == cash2)
        else:
#            print("-----")
#            print("cash1="+cash1)
#            print("cash2="+cash2)
#            print("同じ")
            #cash1に2文字のダミーxxを入れる
            cash1 = "xx"
            index += 2

            #indexがオーバーフローしてなかったらカウント
            if not(index > len(s)):
#                print("count+1")
                count += 1

        #indexがオーバーフローしたら終了
#        print("index="+str(index))
        if index >= len(s):
            break

print(count)


Measured memory_bytes: 3500
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

#define int long long
#define endl "\n"

const long long INF = (long long)1e18;
const long long MOD = 1'000'000'007; 

string yn(bool f){return f?"Yes":"No";}
string YN(bool f){return f?"YES":"NO";}



signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int M;
	cin>>M;
	
	cout<<24-M + 24<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


int main() {
	int64_t N;
	cin >> N;

	string s = to_string(N);
	int sum = 0;
	rep(i, s.size()) {
		int num = s[i] - '0';
		sum += num;
	}
	if (N%sum==0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main (){
    int n,m;cin>>n>>m;
    vector<int>V(n);
    for(int i=0;i<n;i++)cin >> V[i];
    sort(V.rbegin(),V.rend());
    int denom = 4*m;
    int sum = accumulate(V.begin(),V.end(),0);
    double border = (sum*1.0)/(1.0*denom);
    int cnt=0;
    for(int i=0;i<n;i++){
        if(V[i]>=border)cnt++;
    }
    if(cnt>=m)cout<<"Yes";
    else cout<<"No";
    //main();
    return 0;
}


Measured memory_bytes: 256
K, N = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
l = [0]*N
l[0] = A[0] +K - A[N-1]
for i in range(1,N):
    l[i]= A[i] -A[i-1]

    
print(K-max(l))

Measured memory_bytes: 25840
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <functional>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007

using namespace std;

int main(){
    lli n;
    string s,t,ans;
    lli i,j;
    cin>>n>>s>>t;
    rep(i,0,n){
        string scom,tcom;
        scom=s.substr(i,n-i);
        tcom=t.substr(0,n-i);
//        cout<<scom<<"と"<<tcom<<"が一致するかを調べる"<<endl;
        if(scom==tcom){
//            cout<<"一致した"<<endl;
            s=s.substr(0,i);
            break;
        }
    }
    ans=s+t;
//    cout<<ans<<endl;
    cout<<ans.size()<<endl;
}

Measured memory_bytes: 256
import itertools
N,C=map(int, input().split())
D=[list(map(int, input().split())) for _ in range(C)]
cl_cnt=[[0 for _ in range(C) ] for _ in range(3)]
for i in range(N):
    ci=list(map(int, input().split()))
    for j, cij in enumerate(ci):
        cl_cnt[(i+j)%3][cij-1]+=1 

cost=[[0 for _ in range(C) ] for _ in range(3)]
for i in range(3):
    for j in range(C):
        for k in range(C):
            cost[i][k]+=(D[j][k])*cl_cnt[i][j]

ans=1000*500*500
for i, j, k in itertools.permutations(range(C),3):
    ans=min(cost[0][i]+cost[1][j]+cost[2][k], ans)
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vector<int> > vvi;
typedef vector<vector<double> > vvd;

int main(){


    int x, y;
    cin >> x >> y;

    if( (x*y)%2 == 0 ) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 500500;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
char s[maxn];
const int base = 233;
int pw[maxn];
int h[maxn];
int n;
int gd0[maxn], gd1[maxn];
inline int sub(int l,int r) {
	return (h[r] + ll(mod - h[l - 1]) * pw[r - l + 1]) % mod;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> s + 1, n = strlen(s + 1);
	if(std::count(s + 1,s + n + 1, s[1]) == n) {
		cout << n << '\n' << 1 << '\n';
		return 0;
	}
	*pw = 1;
	rep(i, 1, n) {
		pw[i] = pw[i - 1] * 233ll % mod;
		h[i] = (h[i - 1] * 233ll + s[i]) % mod;
		gd0[i] = gd1[i] = 1;
	}
	rep(i, 1, n) {
		for(int j = i + i;j <= n;j += i) {
			if(sub(j - i + 1, j) != sub(1, i)) break;
			gd0[j] = 0;
		}
		for(int j = n - i - i + 1;j >= 1;j -= i) {
			if(sub(j, j + i - 1) != sub(n - i + 1, n)) break;
			gd1[j] = 0;
		}
	}
	if(gd0[n]) {
		cout << 1 << '\n' << 1 << '\n';
		return 0;
	}
	int ans = 0;
	for(int i = 1;i < n;++i) {
		ans += gd0[i] && gd1[i + 1];
	}
	cout << 2 << '\n' << ans << '\n';
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef pair<string,int> SP;
int a[20];
int main(){
  int n, b = 0;
  cin >> n;
  REP(i,n){
    cin >> a[i];
  }
  REP(i,n-2){
    if(((a[i+1] < a[i]) && (a[i+1] > a[i+2])) || ((a[i+1] > a[i]) && (a[i+1] < a[i+2])))b++;
  }
  cout << b;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    long long sum = 0;
    int s;
    scanf("%d",&s);
    for(int i = 0; i <= s; i++){
        if(i%3!=0 && i%5!=0){
            sum += i;
        }
    }
    printf("%lld",sum);

}


Measured memory_bytes: 2148
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

ans = 0
prev = -9
n.times{|i|
  ans += b[a[i]-1]
  ans += c[prev] if prev+1 == a[i]-1
  prev = a[i]-1
}
p ans

Measured memory_bytes: 1788
#include <iostream>
#include <math.h>
#include <algorithm>
#include <cstring>
using namespace std;

const int X = 1;
const int Y = 2;

int N = 0;

int A[2001];
int dp[2][2000][2001];

int F(bool chara, int i, int xi) {
	if (dp[chara][i][xi] >= 0) {
		return dp[chara][i][xi];
	}
	int score = 0;
	int fnum = 0;
	if (i == N - 1) {
		score = abs(A[xi] - A[N - 1]);
	}
	else if (!chara) {
		for (int j = i; j <= N - 2; j++) {
			fnum = F(true, j + 1, j);
			if (score <= fnum) {
				score = fnum;
			}
		}
		if (score <= abs(A[xi] - A[N - 1])) score = abs(A[xi] - A[N - 1]);
	}
	else {
		for (int j = i; j <= N - 2; j++) {
			fnum = F(false, j + 1, j);
			if (score >= fnum) {
				score = fnum;
			}
		}
		if (score >= abs(A[xi] - A[N - 1])) score = abs(A[xi] - A[N - 1]);
	}
	return dp[chara][i][xi] = score;
}

int main()
{
	memset(dp, -1, sizeof(dp));
	int z, w;
	cin >> N >> z >> w;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	A[2000] = w;
	int s = F(false, 0, 2000);
	cout << s;
    return 0;
}



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

using namespace std;
#define int long long


signed main(){
    int N;
    cin >> N;
    
    int cnt = 0;
    for(int i=1;i<N;i++){
        int k = N-i;
        if(k != 0 && i != k) cnt++;
    }
    
    cout << cnt/2 << endl;
    
    return 0;
}


Measured memory_bytes: 256
import math
K = int(input())
ans = 0
for i in range(K):
  for t in range(K):
    for j in range(K):
      gcd1 = math.gcd(i+1,t+1)
      gcd2 = math.gcd(gcd1,j+1)
      ans += gcd2
print(ans)

Measured memory_bytes: 69376
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n,k; cin >> n >> k; vl cost(n); vl dp(n,INT_MAX);
  dp[0] = 0;
  
  rep(i,n) cin >> cost[i];
  
  for(ll i=0; i < n; i++){
    for(ll j=1; j <= k; j++){
      if(i-j >= 0){
        dp[i] = min(dp[i],dp[i-j]+abs(cost[i]-cost[i-j]));
      }
    }
  }
  
  
  cout << dp[n-1] << endl;
  
  
}
    

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 4005;

int n, m;
int bino[MAXN][MAXN];
int dp[MAXN][MAXN];
int ps[MAXN][MAXN];

int choice(int x, int y){
	if(y > x || y < 0) return 0;
	return bino[x][y];
}

int main(){
	cin >> n >> m;
	for(int i=0; i<=4000; i++){
		bino[i][0] = 1;
		ps[i][0] = 1;
		for(int j=1; j<=i; j++){
			bino[i][j] = (bino[i-1][j] + bino[i-1][j-1]) % mod;
			ps[i][j] = (ps[i][j-1] + bino[i][j]) % mod;
		}
	}
	for(int i=0; i<MAXN; i++){
		for(int j=0; j<MAXN; j++){
			if(i == 0){
				dp[i][j] = 1;
				continue;
			}
			dp[i][j] = dp[i-1][j];
			if(j > 0) dp[i][j] += ps[j-1][min(j-1, i)];
			dp[i][j] %= mod;
		}		
	}
	lint ans = 0;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=i; j++){
			int p = j, q = i - j;
			ans += 1ll * dp[p][q] * choice(m - 1, m - q - 1);
			ans %= mod;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 186752
#include<stdio.h>
#include<algorithm>
const int maxm=10001;
int u[maxm];
void makeset()
{
    for(int i=1;i<maxm;i++)
        u[i]=i;
}
int Find(int x)
{
    if(x!=u[x])
    {
        u[x]=Find(u[x]);
    }
    return u[x];

}
int Union(int a1,int a2)
{
    int r1=Find(a1);
    int r2=Find(a2);
    if(r1!=r2)
    {u[r2]=r1;
    return 1;
    }
    return 0;
}
using namespace std;
int main()
{
    long long int m,i,j,k,n,a,b;

    while(scanf("%lld%lld",&n,&m)!=EOF)
    {
        if(n<=0&&m>=0)
        {
           printf("Zero\n") ;
        }

            if(m<0&&(m-n-1)%2==0)
        {
            printf("Positive\n");
        }
        if(m<0&&(m-n)%2==0)
            printf("Negative\n");
        if(n>0) printf("Positive\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
int main(){
	while(1){
		int a;
		std::cin>>a;
		if(a==0)break;
		std::vector<int> vec(a);
		bool f=false;
		for(int i=0;i<a;i++){
			std::cin>>vec[i];
			if(vec[i]>=2)f=true;
		}
		if(f){
			int n=0;
			int m=0;
			for(int i=0;i<a;i++){
				if(vec[i]==0)m++;
			}
			if(a==1)n=2;
			if(a>=2){
				n=a+1;
				n-=m;
			}
			std::cout<<n<<std::endl;
		}else{
			std::cout<<"NA"<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1232
# -*- coding: utf-8 -*-

import itertools
comb = list(map(''.join, itertools.product("ACGT", repeat=4)))

mod = int(1e9) + 7

N = int(input())

dp = {c: [0, 0] for c in comb}
dp["TTTT"] = [1, 0]

for _ in range(N):
    dp_new = {c: [0, 0] for c in comb}
    for k in dp:
        for b in "ACGT":
            if k[2:4] + b in ("AGC", "ACG", "GAC") or k[1:4] + b in ("ACGC", "AGGC", "ATGC", "AGCC", "AGGC", "AGTC"):
                dp_new[k[1:4] + b][1] += dp[k][0]
                dp_new[k[1:4] + b][1] += dp[k][1]
            else:
                dp_new[k[1:4] + b][0] += dp[k][0]
                dp_new[k[1:4] + b][1] += dp[k][1]
    dp = dp_new


print((4 ** N - sum([dp[k][1] for k in dp])) % mod)


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (size_t i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)

const static int MOD = 1000000000 + 7;
const static llong INF = 1LL << 60;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

const static int MAX_N = 100010;
vector<vector<pair<int, llong> > > G;
int visit[MAX_N + 1] = {};
llong dist[MAX_N + 1] = {};

void dfs(int s, llong cost) {
    if (visit[s] == 1) return;

    visit[s] = 1;
    for (size_t i = 0; i < G[s].size(); ++i) {
        if (visit[G[s][i].first] == 1) continue;

        dist[G[s][i].first] = G[s][i].second + cost;
        dfs(G[s][i].first, dist[G[s][i].first]);
    }

    return;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    G.resize(n);
    rep(i, n - 1) {
        int a, b;
        llong c;
        cin >> a >> b >> c;
        G[a - 1].push_back(make_pair(b - 1, c));
        G[b - 1].push_back(make_pair(a - 1, c));
    }

    int q, k;
    cin >> q >> k;

    dfs(k - 1, 0);

    vector<llong> ans(q);
    rep(i, q) {
        int x, y;
        cin >> x >> y;
        if (x == k) {
            ans[i] = dist[y - 1];
        } else if (y == k) {
            ans[i] = dist[x - 1];
        } else {
            ans[i] = dist[x - 1] + dist[y - 1];
        }
    }

    rep(i, q) {
        cout << ans[i] << endl;
    }

    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int inf = 1e9;
const ll INF = 1e18;
const ll mod = 1e9 + 7;

clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n, i, j;
  cin >> n;
  ll a[n];
  forn(0, n, i){
    cin >> a[i];
  }
  sort(a, a + n);

  ll ans = 0;

  forn(0, n, i){
    forn(i + 1, n, j){
      ll sum = a[i] + a[j];
      auto itr = lower_bound(a + j, a + n, sum) - a;
      itr--;
      ans += itr - j;
    }
  }

  cout << ans << '\n';

  ktj();
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();
		long x = sc.nextLong();
		long y = sc.nextLong();
		System.out.println(Math.min(n, k) * x + Math.max(n - k, 0) * y);
	}
}

Measured memory_bytes: 21332
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

int mod = 1e9+7;

vi a;
int get_index(int x) {
  int len = a.size();
  rep (i, len) {
    if (a[i] == x) {
      return i;
    }
  }
  return -1;
}

ll po(ll k, ll x) {
  if (x == 0) {
    return 1;
  }
  if (x == 1) {
    return k % mod;
  }
  ll y = po(k, x/2);
  y = y * y % mod;
  if (x % 2 == 1) {
    y = y * k % mod;
  }
  return y;
}

vll get_nck(int m) {
  vll ret(m+1, 1);
  rep (i, m) {
    ret[i+1]  = ret[i] * (m - i);
    ret[i+1] %= mod;
    ret[i+1] *= po(i+1, mod-2);
    ret[i+1] %= mod;
  }
  return ret;
}


int main() {
  int n;
  scanf("%d", &n);
  a.resize(n+1);
  set<int> si;
  int f1, f2;
  rep (i, n+1) {
    scanf("%d", &a[i]);
    if (si.find(a[i]) != end(si)) {
      f1 = get_index(a[i]);
      f2 = i;
    }
    si.insert(a[i]);
  }

  debug2(f1, f2);
  int left = f1;
  int mid = f2 - f1 - 1;
  int right = n - f2;
  debug(left);
  debug(mid);
  debug(right);
  auto nck = get_nck(n+1);
  /*
  auto nck1 = get_nck(left);
  rep (i, left+1) {
    nck[i+1] += (mod - nck1[i]);
    nck[i+1] %= mod;
  }
  auto nck2 = get_nck(right);
  rep (i, right + 1) {
    nck[i+1] += (mod - nck2[i]);
    nck[i+1] %= mod;
  }
  */
  auto nck3 = get_nck(left + right);
  rep (i, left + right + 1) {
    nck[i+1] += (mod - nck3[i]);
    nck[i+1] %= mod;
  }

  FOR (i, 1, n+2) {
    printf("%lld\n", nck[i]);
  }

  return 0;
}


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

int     main()
{
    int K, N; cin >> K >> N;
    vector<int> a(N);
    vector<int> b(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    for (int i = 0; i < N - 1; i++) b[i] = abs(a[i] - a[i + 1]);
    b[N - 1] = K - a[N - 1] + a[0];
    sort(b.begin(), b.end()); //, greater<int>());
    //for (int i = 0; i < N; i++) cout << b[i] << endl;
    int res = 0;
    for (int i = 0; i < N - 1; i++) res += b[i];
    cout << res << endl;
}

Measured memory_bytes: 1792
fun main(args: Array<String>){
    val s = readLine()!!
    val k = readLine()!!.toInt()
    val list = mutableListOf<String>()
    var i = 0
    while (i < k){
        for (j in 0 until s.length - i){
            val sub = s.slice(j..j+i)
            if(!list.contains(sub)){
                list.add(sub)
            }
        }
        i++
    }
    list.sort()
    println(list[k - 1])
}

Measured memory_bytes: 37108
#include<bits/stdc++.h>
using namespace std;
const int maxn=25;
inline int read(){
	char c=getchar();int t=0,f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){t=(t<<3)+(t<<1)+(c^48);c=getchar();}
	return t*f;
}
int n;
int pos[maxn],b[maxn],c[maxn];
int main(){
	n=read();
	for(int i=1;i<=n;i++)pos[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	for(int i=1;i<n;i++)c[i]=read();
	int ans=0;
	for(int i=1;i<=n;i++){
		ans+=b[pos[i]];
		if(i>1&&pos[i-1]==pos[i]-1)ans+=c[pos[i-1]];
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
m,n= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
print((m*3+n)//2)

Measured memory_bytes: 5332
#include <iostream>
#include <utility>
#include <stdint.h>
#include <set>

using namespace std;

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

  uint count = 0;

  for (uint number = 0; number<1000; ++number) {
    uint hundreds = number/100;
    uint tens = (number%100)/10;
    uint ones = number%10;

    uint ii,jj,kk;
    for (ii=0; ii<N-2; ++ii)
      if ((S[ii]-'0')==hundreds)
	break;
    for (jj=ii+1; jj<N-1; ++jj)
      if ((S[jj]-'0')==tens)
	break;
    for (kk=jj+1; kk<N; ++kk)
      if ((S[kk]-'0')==ones) {
	++count;
	break;
      }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
x = gets.to_i

if x <= 599
    puts 8
elsif x <= 799
    puts 7
elsif x <= 999
    puts 6
elsif x <= 1199
    puts 5
elsif x <= 1399
    puts 4
elsif x <= 1599
    puts 3
elsif x <= 1799
    puts 2
else
    puts 1
end

Measured memory_bytes: 14284
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    vector<char> alphabet;
    for (char i = 'a'; i <= 'z' ; i++) {
        alphabet.push_back(i);
    }
    int n;
    string s;
    cin >> n;
    int ALP[n][26];
    for (int i = 0; i < n; i++) for (int j = 0; j < 26; j++) {
        ALP[i][j] = 0;
    }
    for (int i = 0; i < n; i++) {
        cin >> s;
        for (int j = 0; j < s.size(); j++) {
            int m = s[j] - 'a';
            ALP[i][m]++;
        }
    }
    int ANS[26];
    for (int j = 0; j < 26; j++) {
        int tmp, cnt = 100;
        for (int i = 0; i < n; i++) {
            tmp = ALP[i][j];
            cnt = min(cnt, tmp);
        }
        ANS[j] = cnt;
    }
    for (int i = 0; i < 26; i++) {
        int a = ANS[i];
        for (int j = 0; j < a; j++) {
            cout << alphabet[i];
        }
    }
    cout << endl;
    return 0;
}


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

vector<int> split(const string &str, char sep) {
  vector<int> v;
  stringstream ss(str);
  string buffer;
  while( getline(ss, buffer, sep) ) {
    v.push_back(stoi(buffer));
  }
  return v;
}

int main() {
  vector<vector<int>> dp;
  string s;
  while (cin >> s) {
    vector<int> v = split(s, ',');
    dp.push_back(v);
  }
  for (int i = 0; i < dp.size() - 1; ++i) {
    for (int j = 0; j < dp[i + 1].size(); ++j) {
      if (i >= dp.size() / 2) {
        dp[i + 1][j] += max(dp[i][j], dp[i][j + 1]);
      } else {
        if (j == 0) {
          dp[i + 1][j] += dp[i][j];
        } else if (j == dp[i + 1].size() - 1) {
          dp[i + 1][j] += dp[i][j - 1];
        } else {
          dp[i + 1][j] += max(dp[i][j - 1], dp[i][j]);
        }
      }
    }
  }
  cout << dp[dp.size() - 1][0] << endl;
  return 0;
}



Measured memory_bytes: 3028
#!/usr/bin/env python3
import sys


def solve(N: int, X: "List[int]"):
    answer = 10**9
    for i in range(101):
        tmp = 0
        for j in range(N):
            tmp += (X[j]-i)**2
        answer = min(tmp,answer)
    print(answer)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, X)

if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int m=n;
    int num_dig=0;
    while( m > 0 )
    {
        num_dig++;
        m/=10;
    }
    if( num_dig == 1 )
        cout<<n<<endl;
    else if( num_dig == 2 )
        cout<<9<<endl;
    else if( num_dig == 3 )
        cout<<9 + (n - 100 + 1)<<endl;
    else if( num_dig ==  4)
        cout<<9+900<<endl;
    else if( num_dig == 5 )
        cout<<9+900+(n-10000+1)<<endl;
    else if( num_dig ==  6)
        cout<<9+900+90000<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();
    for i in 1..s.len() {
        if s[i - 1] == 'A' && s[i] == 'C' {
            return "Yes".to_string();
        }
    }
    return "No".to_string();
}


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

int main() {
  int a, b, c, o, r = 0;
  cin >> a >> b >> c;
  o = a % 2 + b % 2 + c % 2;
  if(o == 1) {
    a += !(a & 1);
    b += !(b & 1);
    c += !(c & 1);
    r++;
  }
  if(o == 2) {
    a += a & 1;
    b += b & 1;
    c += c & 1;
    r++;
  }
  r += (max(a, max(b, c)) * 3 - a - b - c) / 2;
  cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int W,H,N;
    cin >> W >> H >> N;
    cout << (W+H)*N/2 << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())

s = 0
d = {}
for x in [int(a) for a in input().split(" ")]:
    s = s + x
    if s not in d:
        d[s] = 0
    d[s] = d[s]+1

ret = 0
for x in d:
    if d[x]>1:
        ret = ret + d[x]*(d[x]-1)//2
    if x==0:
        ret = ret + d[x]

print(ret)


Measured memory_bytes: 39700
#include <iostream>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int SS = 0;
    for (int n=1; n<=N; n++){
        string s = to_string(n);
        int sum = 0;
        for (int i=0; i<s.length(); i++){
            sum += (int)s[i] - '0';
        }
        if (A<=sum && sum<=B) SS += n;
    }
    cout << SS << endl;
}

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

const double pi = 3.14159265359;

int main(){
  double A,B,H,M;
  cin >> A >> B >> H >> M;
  
  double kakuA = H*30.0 + M*0.5 , kakuB = M*6.0;
  double X = abs(kakuA - kakuB);
  if(X>180.0) X = 360.0 - X;
  X *= (pi/180.0);
  
  double ans = A*A + B*B - A*B*cos(X)*2;
  ans = sqrt(ans);
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int cnt[N] = {};
int main() {
    int n, k, d;
    cin >> n >> k;
    for (int i = 1, x; i <= k; i++) {
        cin >> d;
        while (d--) {
            cin >> x;
            cnt[x]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        ans += cnt[i] == 0;
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3620
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())

d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
for (a, b), n in d.items():
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)


Measured memory_bytes: 49384
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	char C = getcha();
	int A = C - '0';
	while ((C = getcha()) >= '0') A = A * 10 + C - '0';
	return A;
}

const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(int X) {
	if (!X) {
		*di++ = '0';
		*di++ = '\n';
	}
	int keta = 0;
	char C[10];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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


	int N = getint(), M = getint(), Q = getint();
	int T[502][502] = {};
	rep(i, M) {
		int l = getint(), r = getint();
		T[l][r]++;
	}
	for (int i = N; i >= 1; i--) {
		for (int j = i + 1; j <= N; j++) {
			T[i][j] = T[i][j - 1] + T[i + 1][j] - T[i + 1][j - 1] + T[i][j];
		}
	}
	rep(i, Q) {
		int p = getint(), q = getint();
		putint(T[p][q]);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

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

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	int dp[n];
	for(int i=0;i<n;i++)
	{
	    dp[i]=INT_MAX;
	}
	dp[0]=0;
	dp[1]=abs(a[0]-a[1]);
	for(int i=1;i<n;i++)
	{
	    for(int j=1;j<=k;j++)
	    {
	        if(i>=j)
	        {
	            
	            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	        }
	        
	    }
	}
	cout<<dp[n-1]<<endl;
	return 0;
}

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

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    int total = 0;
    for (int i=1; i<=N; i++) {
        int sum = 0;
        int x = i;
        while (x!=0) {
            sum += x%10;
            x /= 10;
        }
        if (A <= sum && sum <=B) total += i;
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define lint long long

const int INF = 1e9;
const int MOD = 1e9+7;
const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;
lint n;
vector<lint> v;

int main(){
  cin >> n;
  for(lint i=1;i<=n;i++){
    lint k;
    cin >> k;
    v.pb(k-i);
  }
  sort(v.begin(),v.end());
  lint ans = 0;
  REP(i,n){
    ans += abs(v[i]-v[n/2]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2420
import java.util.*;

public class Main {

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

	int mod = 1000000007;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int a[] = new int[n];
		for(int i=0; i<n; i++) {
			int v = sc.nextInt();
			a[v]++;
		}
		if(n%2 != 0 && a[0]!=1) {
			System.out.println(0);
			sc.close();
			return;
		}
		int s;
		if(n%2==0) {
			s=1;
		}else {
			s=2;
		}
		for(int i=s; i<n; i+=2) {
			if(a[i] != 2) {
				System.out.println(0);
				sc.close();
				return;
			}
		}
		//2^(n/2)
		long ans = pow(2, n/2);
		System.out.println(ans);
		sc.close();
	}

	public long  pow(int n, int k) {
		if(k==0) return 1;
		if(k%2 == 0) {
			long tmp = pow(n, k/2);
			long ret = tmp * tmp;
			ret %= mod;
			return ret;
		}else {
			long tmp = pow(n, k-1);
			long ret = tmp * n;
			ret %= mod;
			return ret;

		}
	}
}


Measured memory_bytes: 59400
N,Q=[int(i) for i in input().rstrip().split()]
S = input().strip()
lr_list=[[int(j) for j in input().split()] for i in range(Q)]

calc_cnt=[0]
for i in range(1,len(S)):
    sub_str = S[(i-1):(i+1)]
    
    if sub_str == "AC":
        calc_cnt += [calc_cnt[i-1] + 1]
    else:
        calc_cnt += [calc_cnt[i-1]]
        

for l,r in lr_list:
    ans = calc_cnt[r-1] - calc_cnt[l-1]
    print(ans)


Measured memory_bytes: 24432
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;


long mod = 1000000007;

//aのp乗を求めるアルゴリズム
//p=62の時、pの変化は、62->31->30->15->14->7->6->3->2->1->0
//と、半分半分になっていく
//よって、計算量はO(logp)になる
long modpow(long a, int p) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		//pが偶数の時
		int halfP = p / 2;
		long half = modpow(a, halfP);
		//a^(p/2) をhalfとして、half*halfを計算
		return half * half % mod;
	}
	else {
		//pが奇数の時は、
		//pを偶数にするために1減らす
		return a * modpow(a, p - 1) % mod;
	}
}


//(10*9*8)/(3*2*1);
//10*9*8 -> ansMul
//3*2*1 -> ansDiv
long calcComb(int a, int b) {
	if (b > a - b) return calcComb(a, a - b);


	long ansMul = 1;
	long ansDiv = 1;
	for (int i = 0; i < b; i++)
	{
		ansMul *= (a - i);
		ansDiv *= (i + 1);
		ansMul %= mod;
		ansDiv %= mod;
	}
	//ansMul / ansDivをやりたい
	//ansDivの逆元を使って求めよう！

	long ans = ansMul * modpow(ansDiv, mod - 2) % mod;
	return ans;
}


int main() {
	int N, M;
	cin >> N >> M;

	int MNokori = M;
	long ans = 1;
	for (int i = 2; i * i <= MNokori; i++)
	{
		if (MNokori % i == 0) {
			int cnt = 0;
			while (MNokori % i == 0) {
				cnt++; MNokori /= i;
			}
			//cntが2^Xとか3^XのXの部分
			ans *= calcComb(N + cnt - 1, N - 1); //N-1はcntと同じ
			ans %= mod;
		}
	}
	if (MNokori != 1) {
		//最後に素数が残ってる分を処理する
		ans *= calcComb(N + 1 - 1, N - 1); //N-1はcntと同じ
		ans %= mod;
	}

	cout << ans << endl;
}





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

int main(){
  long N,K;cin>>N>>K;
  vector<long> A(N);
  for(int i=0;i<N;i++) cin>>A.at(i);
  sort(A.begin(),A.end());
  long left=1;
  long right=A.at(N-1);
  while(left<right){
    long X=(left+right)/2;
    long ans=0;
    for(int i=0;i<N;i++){
      ans+=A.at(i)/X;
      if(A.at(i)%X==0) ans--;
    }
    if(ans>K) left=X+1;
    else right=X;
  }
  cout<<right<<endl;
}
//test.

Measured memory_bytes: 4732
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

int main() {
	int N;
	int A[100005];
	cin >> N;
	REP(i, N) {
		cin >> A[i];
	}

	int ans = 1;
	int inode = 0;//-1なら減少，0なら平坦，1なら増加
	for(int i = 1; i < N; i++) {
		if (A[i - 1] < A[i]) {
			if (inode == -1) {
				ans++;
				inode = 0;
				continue;
			}
			inode = 1;
		}
		else if (A[i - 1] == A[i]) {
			//ans++;
			//inode = 0;
			continue;
		}
		else {
			if (inode == 1) {
				ans++;
				inode = 0;
				continue;
			}
			inode = -1;
		}
	}

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//BEGIN CUT HERE
// longest prefix suffix matching of [0, i)
vector<int> knuth_morris_pratt(const string &s){
  int n=s.size();
  vector<int> kmp(n+1,-1),mp(n+1,-1);
  for(int i=0,j=-1;i<n;i++){
    while(~j&&s[i]!=s[j]) j=kmp[j];
    kmp[i+1]=mp[i+1]=++j;
    if(i+1<n&&s[i+1]==s[j]) kmp[i+1]=kmp[j];
  }
  return mp;
}
vector<int> minimun_period(const string &s){
  auto mp=knuth_morris_pratt(s);
  for(int i=1;i<(int)mp.size();i++) mp[i]=i-mp[i];
  return mp;
}
//END CUT HERE

//INSERT ABOVE HERE
signed ABC135_D(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s,t;
  cin>>s>>t;

  int n=s.size(),m=t.size();

  string b;
  while(b.size()<t.size()) b+=s;
  auto mp=knuth_morris_pratt(t+'$'+b+b);

  vector<int> match(n);
  for(int i=m+1;i<=m+n;i++)
    match[i-(m+1)]=mp[i+m]==m;

  vector< vector<int> > G(n);
  for(int i=0;i<n;i++)
    if(match[i]) G[i].emplace_back((i+m)%n);

  vector<int> indeg(n,0);
  for(int i=0;i<n;i++)
    for(int j:G[i]) indeg[j]++;

  queue<int> que;
  for(int i=0;i<n;i++)
    if(indeg[i]==0) que.emplace(i);

  vector<int> dp(n,0);
  while(!que.empty()){
    int v=que.front();que.pop();
    for(int u:G[v]){
      chmax(dp[u],dp[v]+1);
      indeg[u]--;
      if(indeg[u]==0) que.emplace(u);
    }
  }

  for(int i=0;i<n;i++){
    if(indeg[i]!=0){
      cout<<-1<<endl;
      return 0;
    }
  }

  cout<<*max_element(dp.begin(),dp.end())<<endl;
  return 0;
}
/*
  verified on 2019/08/21
  https://atcoder.jp/contests/abc135/tasks/abc135_f
*/

signed ARC060_F(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  string w;
  cin>>w;

  int n=w.size();
  if(w==string(n,w[0])){
    cout<<n<<endl<<1<<endl;
    return 0;
  }

  auto mp=minimun_period(w);
  if(n%mp[n]!=0||n==mp[n]){
    cout<<1<<endl<<1<<endl;
    return 0;
  }

  string w_rev=w;
  reverse(w_rev.begin(),w_rev.end());
  auto mp_rev=minimun_period(w_rev);

  int cnt=0;
  for(int i=1;i<n;i++){
    int j=n-i;
    if(i%mp[i]==0&&i>mp[i]) continue;
    if(j%mp_rev[j]==0&&j>mp_rev[j]) continue;
    cnt++;
  }
  cout<<2<<endl<<cnt<<endl;
  return 0;
}
/*
  verified on 2019/08/21https://atcoder.jp/contests/arc060/tasks/arc060_d
*/

signed main(){
  //ABC135_D();
  ARC060_F();
  return 0;
}


Measured memory_bytes: 7052
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;


int main()
{
  ll n,k,s=0;
  cin>>n>>k;
  ll a[n];
  for(ll i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  for(ll i=0;i<k;i++)
  {
  	s=s+a[i];
  }
  cout<<s<<endl;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){
	
	int n;cin >> n;
	int k = n;
	
	if(n == 1){
		cout << 1 << endl << 1 << endl;
		return 0;
	}
	
	bool flag = (n % 2 == 1);
	n = (n + 3) / 4;n *= 2;
	cout << n << endl;
	REP(i,n){
		REP(j,n){
			int out;
			if(i % 2){
				out = (i + j) % n;
			}
			else {
				out = n + ((i + j) % n);
				if(out >= k)out -= n;
			}
			cout << out+1 << " ";
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using llint = long long int;
using namespace std;

int main() {
    fastIO;
    int n, k;
    cin >> n >> k;

    vector<int> H(n);
    rep(i, n) cin >> H.at(i);
    int cnt = 0;
    for (auto h : H) {
        if (h >= k)
            cnt++;
    }
    cout << cnt << endl;
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL r,D,x;
  cin >> r >> D >> x;
  REP(i,10){
    x = r * x - D;
    cout << x << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<double,double> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

template<class T, int SZ> struct sums {
    T sum[SZ][SZ];
    sums () { memset(sum,0,sizeof sum); }
    void init() {
        FOR(i,1,SZ) FOR(j,1,SZ) 
            sum[i][j] += sum[i][j-1]
            +sum[i-1][j]-sum[i-1][j-1];
    }
    T get(int X1, int X2, int Y1, int Y2) {
        return sum[X2][Y2]-sum[X1-1][Y2]
        	-sum[X2][Y1-1]+sum[X1-1][Y1-1];
    }
};

sums<int,2001> s[2];
int N,K,ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N >> K;
    F0R(i,N) {
        int x,y; char c; cin >> x >> y >> c;
        x %= 2*K, y %= 2*K; x ++, y ++;
        s[c == 'B'].sum[x][y] ++;
    }
    s[0].init(), s[1].init();
    for (int i = 0; i+K-1 < 2*K; ++i) for (int j = 0; j+K-1 < 2*K; ++j) {
        vi a = {-1,i-1,i+K-1,2*K-1};
        vi b = {-1,j-1,j+K-1,2*K-1};
        int tmp = 0;
        F0R(I,3) F0R(J,3) tmp += s[(I+J)&1].get(a[I]+2,a[I+1]+1,b[J]+2,b[J+1]+1);
        ans = max(ans,max(tmp,N-tmp));
    }
    cout << ans;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


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

using namespace std;
int n;
int ar[100005][4];
int mem[100005][4];

int solve(int ind,int prv){
    if(ind==n){
        return 0;
    }
    if(mem[ind][prv]!=-1){
        return mem[ind][prv];
    }
    int ret=0;
    if(prv==0){
        ret=max(ret,solve(ind+1,1)+ar[ind][1]);
        ret=max(ret,solve(ind+1,2)+ar[ind][2]);
    }else if(prv==1){
        ret=max(ret,solve(ind+1,2)+ar[ind][2]);
        ret=max(ret,solve(ind+1,0)+ar[ind][0]);
    }else if(prv==2){
        ret=max(ret,solve(ind+1,0)+ar[ind][0]);
        ret=max(ret,solve(ind+1,1)+ar[ind][1]);
    }else {
        ret=max(ret,solve(ind+1,0)+ar[ind][0]);
        ret=max(ret,solve(ind+1,1)+ar[ind][1]);
        ret=max(ret,solve(ind+1,2)+ar[ind][2]);
    }
    return mem[ind][prv]=ret;
}

int main() {
    //freopen("input.in", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    memset(mem,-1,sizeof mem);
    cin>>n;
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++)
        {
            cin>>ar[i][j];
        }
    }
    cout<<solve(0,3)<<endl;
    return 0;
}

Measured memory_bytes: 8064
#include <stdio.h>

#define N_MAX   100000
#define W_MAX   100000
#define H_MAX   100000

int MIN(int a,int b){return a<b?a:b;}
int MAX(int a,int b){return a<b?b:a;}

int width[W_MAX+2]    = {};
int height[H_MAX+2]   = {};

int main(void){
    int N,W,H,x,y,w;
    int i,j;
    int M;
    
    scanf("%d %d %d",&N,&W,&H);
    for( i=0; i<N; i++){
        scanf("%d %d %d",&x,&y,&w);
        width[MAX(0,x-w)]++;
        width[MIN(H+1,x+w)]--;
        height[MAX(0,y-w)]++;
        height[MIN(W+1,y+w)]--;
    }
    
    M=N;
    for( i=0; i<W; i++){
        if( M > width[i] ){
            M = width[i];
        }
        width[i+1] += width[i];
    }
    
    if( M <= 0 ){
        M = N;
        for( i=0; i<H; i++){
            if( M > height[i] ){
                M = height[i];
            }
            height[i+1] += height[i];
        }
    }
    
    if( M <= 0 ){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
}




Measured memory_bytes: 2504
import java.util.Scanner; 
 public class Main {   
 	public static void main(String[] args) {        
 	Scanner sc = new Scanner(System.in);     
 	int w = sc.nextInt();     
 	int n = sc.nextInt();     
 	int[] values = new int[w];     
 	for (int i = 0; i < values.length; i++) {       
 	values[i] = i + 1;     
 }     
 for (int i = 0; i < n; i++) {       
 	String str = sc.next();       
 	String[] ab = str.split(",");       
 int a = Integer.parseInt(ab[0]) - 1;       
 int b = Integer.parseInt(ab[1]) - 1; 
 int num;

 num=values[a];
 values[a]=values[b];
 values[b]=num; 
 }
 for(int x=0;x<w;x++){
 System.out.println(values[x]) ;
}  
} 
}

Measured memory_bytes: 26172
N = int(input())
C = list(input())
i = 0
j = N-1
cnt = 0
while i < j:
    if (C[j] == 'R') and (C[i] == 'W'):
        C[i], C[j] = C[j], C[i]
        i = i + 1
        j = j - 1
        cnt = cnt + 1
    elif (C[j] == 'R'):
        i = i + 1
    else:
        j = j - 1
print(cnt)

Measured memory_bytes: 10800
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin>>N;
  double A[N] ,sum=0;
  for(int i=0;i<N;i++) {
    cin>>A[i];
    sum+=1/A[i];
  }
  cout<<1/sum<<endl;
  return 0;
}


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

ll n,m,a[100009],sum;

ll f(ll x){
    ll num=0,y=n-1;
    rep(i,n){
        while(y>=0&&a[i]+a[y]>=x){
            sum+=a[y]*(n-i);
            y--;
        }
        sum+=(n-y-1)*a[i];
        num+=n-y-1;
    }
    return num;
}

int main(){
    cin>>n>>m;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    ll l=0,r=1e18;
    while(l+1<r){
        ll mid=(l+r)/2;
        if(f(mid)<=m)r=mid;
        else l=mid;
    }
    sum=0ll;
    cout<<l*(m-f(r))+sum<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>> a;
  int s=a%10;
  int b=a/10%10;
  if(s==9||b==9){
    cout <<"Yes"<< "\n";
  }else{
    cout <<"No"<<"\n";
  }
}

Measured memory_bytes: 256