akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> Name(n, vector<Type>(m, d))
#define P pair
using namespace std;
using ll = long long;

const int INF = 1e8;

int main(void) {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int n;
	cin >> n;
	vector<int> a(n);

	rep(i,n) cin >> a[i];
	

	int ans = -1;
	int tmp = 0;
	int cnt = 1;
	rep(i, n) {
		if (a[i] == cnt) {
			if (ans == -1) ans = tmp;
			else ans += tmp;
			tmp = 0;
			cnt += 1;
		}
		else tmp++;
	}

	if (ans == -1) cout << -1 << endl;
	else cout << ans + tmp << endl;

	return 0;
}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  int w[k+k][k+k],b[k+k][k+k];
  for(int i=0;i<k+k;i++){
    fill(w[i],w[i]+k+k,0);
    fill(b[i],b[i]+k+k,0);
  }
  for(int i=0;i<n;i++){
    int x,y;cin>>x>>y;
    char c;cin>>c;
    if(c=='B')b[y%(2*k)][x%(2*k)]++;
    if(c=='W')w[y%(2*k)][x%(2*k)]++;
  }
  int sb[k+k+1][k+k+1],sw[k+k+1][k+k+1];
  sb[0][0]=0;
  sw[0][0]=0;
  for(int i=0;i<=k+k;i++){
    sb[0][i]=0;
    sb[i][0]=0;
    sw[i][0]=0;
    sw[0][i]=0;
  }
  for(int i=1;i<=k+k;i++){
    for(int j=1;j<=k+k;j++){
      sb[i][j]=sb[i-1][j]+sb[i][j-1]-sb[i-1][j-1];
      sw[i][j]=sw[i-1][j]+sw[i][j-1]-sw[i-1][j-1];
      sb[i][j]+=b[i-1][j-1];
      sw[i][j]+=w[i-1][j-1];
    }
  }
  int ans=0;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      int sum=sw[i][j];
      sum+=sb[i][j+k]-sb[i][j];
      sum+=sb[i+k][j]-sb[i][j];
      sum+=sw[i+k][j+k]-sw[i][j+k]-sw[i+k][j]+sw[i][j];
      sum+=sw[i][k+k]-sw[i][j+k];
      sum+=sb[i+k][k+k]-sb[i][k+k]-sb[i+k][j+k]+sb[i][j+k];
      sum+=sw[k+k][k+k]-sw[i+k][k+k]-sw[k+k][j+k]+sw[i+k][j+k];
      sum+=sb[k+k][j+k]-sb[i+k][j+k]-sb[k+k][j]+sb[i+k][j];
      sum+=sw[k+k][j]-sw[i+k][j];
      ans=max(ans,sum);
      int summ=sb[i][j];
      summ+=sw[i][j+k]-sw[i][j];
      summ+=sw[i+k][j]-sw[i][j];
      summ+=sb[i+k][j+k]-sb[i][j+k]-sb[i+k][j]+sb[i][j];
      summ+=sb[i][k+k]-sb[i][j+k];
      summ+=sw[i+k][k+k]-sw[i][k+k]-sw[i+k][j+k]+sw[i][j+k];
      summ+=sb[k+k][k+k]-sb[i+k][k+k]-sb[k+k][j+k]+sb[i+k][j+k];
      summ+=sw[k+k][j+k]-sw[i+k][j+k]-sw[k+k][j]+sw[i+k][j];
      summ+=sb[k+k][j]-sb[i+k][j];
      ans=max(ans,summ);
    }
  }
  cout<<ans<<endl;
}
      

Measured memory_bytes: 62720
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

	public void Proc()
	{
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        int[,] retsu = new int[inpt[0], inpt[1]];
        int[] vector = new int[inpt[1]];

        for (int i = 0; i<retsu.GetLength(0); i++) {
            inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            for (int j = 0; j < inpt.Length; j++) {
                retsu[i, j] = inpt[j];
            }
        }
        for (int i = 0; i < vector.Length; i++) {
            vector[i] = int.Parse(Reader.ReadLine());
        }

        System.Text.StringBuilder ans = new System.Text.StringBuilder();
        for (int i = 0; i < retsu.GetLength(0); i++) {
            int tmp = 0;
            for (int j = 0; j < vector.Length; j++) {
                tmp += retsu[i, j] * vector[j];
            }
            ans.AppendLine(tmp.ToString());
        }
        Console.Write(ans.ToString());
    }




    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"


3 4
1 2 0 1
0 3 0 1
4 1 1 0
1
2
3
0


";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

Measured memory_bytes: 9744
A="AKIHABARA"
data=[0,4,6,8]
AD=list(A)
S=set(); S.add(A)
for i in range(2):
    for j in range(2):
        for k in range(2):
            for l in range(2):
                tmp=AD.copy()
                # print(AD)
                # print(tmp)
                if i: tmp[0]=""
                if j: tmp[4]=""
                if k: tmp[6]=""
                if l: tmp[8]=""
                S.add(''.join(tmp))


s=input()
if s in S:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
def main():
    N = int(input())

    book = []

    for i in range(N):
        S, P = input().split()
        P = int(P)
        book.append((i + 1, S, P))

    book.sort(key=lambda x: (x[1], x[2] * -1))

    for i, _, _ in book:
        print(i)


main()


Measured memory_bytes: 3060
N=int(input())
S=input()
a,t=0,0
for i in S:
    if i==")":
        t+=1
        a=max(a,t)
    else:
        t-=1
b,t=0,0
for i in range(N-1,-1,-1):
    if S[i]=="(":
        t+=1
        b=max(b,t)
    else:
        t-=1
print("("*a,end="")
print(S,end="")
print(")"*b,end="")

Measured memory_bytes: 3064
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String args[]){
		Scanner sc =  new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0; i < n; i++ ){
			double Ax = sc.nextDouble();
			double Ay = sc.nextDouble();
			double Bx = sc.nextDouble();
		    double By = sc.nextDouble();
		    double Cx = sc.nextDouble();
		    double Cy = sc.nextDouble();
		    double Dx = sc.nextDouble();
		    double Dy = sc.nextDouble();
		    double cross = Math.abs( (Bx - Ax) * (Dy - Cy) - (By - Ay) * (Dx - Cx) );
		    if(cross<1e-10){
		    	System.out.println("YES");
		    }else{
		    	System.out.println("NO");
		    }
		}
	}
}

Measured memory_bytes: 29944
import * as fs from 'fs';

namespace AtCoder.abc084 {

    export class Program {

        constructor(private readonly args: string[][]) {
        }

        /**
         * in
         *
         * out
         *
         */
        main(this: Program): void {
            const [m]: number[] = this.args[0].map(Number);
            console.log(24+(24-m));
        }
    }
}

const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
const prg: AtCoder.abc084.Program = new AtCoder.abc084.Program(args);
prg.main();


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
unsigned long long getSumD ( unsigned long long x ) {
    return x == 0 ? 0 : x%10 + getSumD( x/10 );
}
int main () {

    long long n;
    cin >> n;
    if ( n%getSumD(n) ) {
        cout << "No\n";
    }else {
        cout << "Yes\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//Union-Find;
#define MAX_N 200000
int par[MAX_N];
int siz[MAX_N];
int Rank[MAX_N];
void init(int n){
    rep(i,n){
        par[i]=i;
        siz[i]=1;
        Rank[i]=0;
    }
}
int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}
void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(Rank[x]<Rank[y]){
        par[x]=y;
        siz[par[x]]=siz[x]+siz[y];
    }else{
        par[y]=x;
        siz[par[y]]=siz[x]+siz[y];
        if(Rank[x]==Rank[y])Rank[x]++;
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}

//library end
int n,r;
signed main(){
    cin>>n>>r;
    if(n>=10)cout<<r<<endl;
    else{
        cout<<r+100*(10-n)<<endl;
    }
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int k; cin >> k;
	int ans = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			for (int c = 1; c <= k; c++) {
				ans += __gcd(a, __gcd(b, c));
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    llong X;
    cin >> X;
    if(X>=30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iomanip>
#include <sstream>
 
int main(void)
{
    int64_t N;
    std::cin >> N;

    std::vector<int64_t> A(N+1);

    int64_t count = 0;
    int64_t num = 1;
    for (int64_t i = 0; i < N; ++i) {
        int64_t a;
        std::cin >> a;
        if (a != num) {
            count++;
        } else {
            num++;
        }
    }

    if (count == N) {
        count = -1;
    }

    std::cout << count << std::endl;

    return 0;
}

Measured memory_bytes: 1920
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = sc.nextInt()
        val a = IntArray(n)
        for (i in 0 until n) {
            a[i] = sc.nextInt()
        }
        var c = 0
        for (i in 0 until n) {
            if (i+1 != a[i]) {
                c++
            }
        }
        if (c > 2) {
            println("NO")
        } else {
            println("YES")
        }
    } catch (e: Exception) {
        println(e)
    }
}

Measured memory_bytes: 31124
import sys
N = int(input())
if N>=4:
    C=[0]*N
    C[0]=0
    C[1]=0
    C[2]=1
    n=2
    #フィボナッチ数列のイメージ
    while True:
        n=n+1
        C[n]=C[n-1]+C[n-3]
        #print(n,C[n])
        if n==(N-1):
            break
    print(C[N-1]%(10**9+7))
if N==3:
    print(1)
if N<=2:
    print(0)

Measured memory_bytes: 9188
N = int(input())
A = list(map(int, input().split()))


"""
a xor b と　a+b の比較
・a+bには桁上がりがあるが、a xor bにはないので、　a+b >= a xor b
　等号が成立するのは、aとbの各bitで一致するものがないときか。

毎回bitごとに確認して被ったら左端のやつを除外して～はしんどいので、普通に累積和とxorでよさそう
a+b = a xor b なら、(a+b) xor c = (a xor b) xor c　なので、基本的に累積和管理でOK
"""


ans = 0
total = 0
r = 0
for l in range(N):
    while r <= N-1 and total + A[r] == total ^ A[r]:
        total += A[r]
        r += 1
        

    ans += r-l
    
    total -= A[l]        

print(ans)

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

using namespace std;

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

typedef long long ll;
typedef long double ld;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int h, n;
    cin >> h >> n;
    vector<int> dp(h + 1, Inf);
    dp[0] = 0;
    rep (i, n) {
        int a, b;
        cin >> a >> b;
        rep (j, h) {
            int t = min(h, j + a);
            dp[t] = min(dp[t], dp[j] + b);
        }
    }
    cout << dp[h] << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using p = pair<int,int>;
int main(){
	int n;
  	cin >> n;
	auto v = vector<int>(100001,0);
  	for (int i = 0; i < n; i++)
	  {
		  cin >> v[i];
	  }
	auto v1 = vector<int>(100001,0);
	auto v2 = vector<int>(100001,0);
	for (size_t i = 0; i < n; i++)
	{
		if(i%2==0){
			v1[v[i]]++;
		}else{
			v2[v[i]]++;
		}
	}
	
	auto n1 = max_element(v1.begin(),v1.end());
	auto n2 = max_element(v2.begin(),v2.end());
	auto ans = n - *n1 - *n2;

	if(n1-v1.begin() == n2-v2.begin()){
		
	sort(v1.begin(),v1.end(),greater<int>());
	sort(v2.begin(),v2.end(),greater<int>());

		ans = min(n-*++v1.begin()-*v2.begin(),n-*v1.begin()-*++v2.begin());
	}

	cout << ans;


}


Measured memory_bytes: 1408
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  string S; cin >> S;
  int N = S.size(); int cnt = 0;
  rep(i, (N+1)/2){
    if(S[i] != S[N-1-i]) cnt++;
  }
  cout << cnt << endl;
 }

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

int main(){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;

    if(a1 + a2 + a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()

count = 0
result = 0
for i in range(len(s)):
  if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T' :
    count += 1
  else:
    if result < count:
      result = count
      count =0

if result < count:
  result = count

print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N, X; cin >> N >> X; 
	int S[210] = {}; 
	for(int i = 0; i < N; i++) cin >> S[i]; 
	sort(S, S+N); 
	long long P = 1000000007; 
	long long dp[205][100010] = {}; 
	dp[0][X] = 1; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j <= X; j++){
			if(dp[i][j] == 0) continue; 
			for(int k = 0; k < N; k++){
				if(j < S[k]){
					dp[i+1][j] += dp[i][j] * (N - k - i); 
					dp[i+1][j] %= P; break; 
				}
				dp[i+1][j % S[k]] += dp[i][j]; 
				dp[i+1][j % S[k]] %= P; 
			}
		}
	}
	long long ans = 0; 
	for(int i = 1; i <= X; i++){
		ans += dp[N][i] * i % P; 
		ans %= P; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 160512
#include<stdio.h>
#include<algorithm>
using namespace std;
long long mod=1000003;
long long inv[1000003];
long long dp[1100][1100];
long long sum[1100][2];
long long dp2[1100][2];
int gcd(int a,int b){
	while(a){
		b%=a;int c=a;a=b;b=c;
	}
	return b;
}
int num[1100];
long long calc(int a,int b){
	if(~dp[a][b])return dp[a][b];
	long long ret=0;
	for(int i=0;i<=a;i++){
		for(int j=0;j<=b;j++)sum[j][0]=sum[j][1]=dp2[j][0]=dp2[j][1]=0;
		dp2[i][0]=1;sum[i][0]=1;
		for(int j=i+1;j<=b;j++){
			dp2[j][1]=(sum[j-1][0]+mod-sum[max(0,j-1-a)][0])%mod;
			if(j==b)dp2[j][0]=(dp2[j][0]+sum[j-1][1]+mod-sum[max(0,j-1-(a-i))][1])%mod;
			else dp2[j][0]=(dp2[j][0]+sum[j-1][1]+mod-sum[max(0,j-1-a)][1])%mod;
			sum[j][0]=(sum[j-1][0]+dp2[j][0])%mod;
			sum[j][1]=(sum[j-1][1]+dp2[j][1])%mod;
		}
		ret=(ret+dp2[b][0]+dp2[b][1])%mod;
	}
	ret=ret*2%mod;
	return dp[a][b]=ret;
}
int main(){
	int a,b;
	inv[1]=1;
	for(int i=2;i<mod;i++)inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	for(int i=1;i<1100;i++){
		int c=i;
		int v=2;
		while(c>1){
			if(c%v==0){
				c/=v;num[i]++;
			}else v++;
		}
	}
	/*for(int i=1;i<=1050;i++){
		for(int j=0;j<1100;j++)sum[j][0]=sum[j][1]=0;
		for(int j=0;j<1100;j++)dp2[j][0]=dp2[j][1]=0;
		for(int j=1;j<=i;j++)dp2[j][0]=1;
		sum[1][0]=dp2[1][0];
		for(int j=2;j<=1050;j++){
			dp2[j][1]=(sum[j-1][0]+mod-sum[max(0,j-1-i)][0])%mod;
			dp2[j][0]=(dp2[j][0]+sum[j-1][1]+mod-sum[max(0,j-1-i)][1])%mod;
			sum[j][0]=(sum[j-1][0]+dp2[j][0])%mod;
			sum[j][1]=(sum[j-1][1]+dp2[j][1])%mod;
		}
	//	for(int j=0;j<=1050;j++)dp[i][j]=dp2[j][1]*j;
		for(int j=1;j<=1050;j++){
			for(int k=1;k*k<=j;k++){
				if(j%k==0){
					int n=j/k;
					if(num[j]%2==num[n]%2)dp[i][j]=(dp[i][j]+dp2[n][1]*n)%mod;
					else dp[i][j]=(dp[i][j]+mod-dp2[n][1]*n%mod)%mod;
				}
				if(k*k!=j&&j%k==0){
					int n=k;
					if(num[j]%2==num[n]%2)dp[i][j]=(dp[i][j]+dp2[n][1]*n)%mod;
					else dp[i][j]=(dp[i][j]+mod-dp2[n][1]*n%mod)%mod;
				}
			}
		}
	}*/
	for(int i=0;i<1100;i++)for(int j=0;j<1100;j++)dp[i][j]=-1;
	while(scanf("%d%d",&a,&b),a){
		int ad=0;
		if(b>=a)ad=2;
		if(b>=a)b=a-1;
		long long ret=0;
		for(int i=1;i<=a;i++){
			int t=gcd(i,a);
			ret=(ret+calc(min(t-1,b),t))%mod;
		}
		//printf("%lld\n",ret);
		ret=ret*inv[a]%mod;
		printf("%lld\n",(ret+ad)%mod);
	}
}

Measured memory_bytes: 18332
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
/*--Input//////////////////////////////////////////////////*/
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
    cin >> first;
    IN(rest...);
    return;
}
#define SS(T, ...)      T __VA_ARGS__; IN(__VA_ARGS__);
#define SV(type,c,n) vector<type> c(n);for(auto& i:c)cin >> i;
/*--Output/////////////////////////////////////////////////*/
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
inline int p(void){cout << endl; return 0;}
template<class Head> int p(Head&& head){cout << head;p();return 0;} template<class Head,class... Tail> int p(Head&& head,Tail&&... tail){cout<<head<<" ";p(forward<Tail>(tail)...);return 0;}
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>
#define debug(x) cerr<<#x<<" "<<x<<'\n';
#define all(x) (x).begin(),(x).end()
#define bit(n) (1LL<<(n))

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; }
bool cmp(pair<ll,ll> a, pair<ll,ll> b) { return a.second < b.second; }

const int MOD = 1000000007;

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

ll divi_wa(ll n,ll m){
    ll ans = 0;
    for (ll i = 0; n>0 ; i++)
    {
        ans+=(n%m);//n進法での各けたの数の和を取る
        n = n/m;
    }
    return ans;
}
vl divisor(ll n){
    vector<ll> ret;
    for(ll i = 1; i * i <= n; i++) {
        if(n % i == 0) {
            ret.push_back(i);
            if(i * i != n) ret.push_back(n / i);
        }
    }
    return ret;
}

int main() {
    SS(ll,n,s);
    if(n==s){
        p(n+1);
        return 0;
    }
    else if(n<=1000000){ //全探索
        rep(i,n-1){
            if(divi_wa(n,i+2)==s){
                p(i+2);
                return 0;
            }
        }
    }else{
        auto v=divisor(n-s);
        sort(v.begin(),v.end());
        rep(i,v.size()){
            if(divi_wa(n,v[i]+1)==s){
                p(v[i]+1);
                return 0;
            }
        }
    }
    p(-1);
}


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

int n, a[100009]; vector<int>vec;

int main() {
	cin >> n; int cnt = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (i >= 2 && a[i] == a[i - 1]) cnt++;
		else if (i >= 2) { vec.push_back(cnt); cnt = 1; }
	}
	vec.push_back(cnt);
	int F = 0; for (int i = 0; i < vec.size(); i++) F += vec[i] / 2;
	cout << F << endl;
	return 0;
}

Measured memory_bytes: 256
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
//typedef complex<double>P;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
const double pi = acos(-1);//3.1415926535897932384626433832795028...
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

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

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

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

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

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

double add(double a, double b) {
	if (abs(a + b) < EPS*(abs(a) + abs(b))) { return 0; }
	return a + b;
}


//↑template↑

int main() {
	ll n, k[200005], l[200005], on, tw;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> k[i];
		l[i] = k[i];
	}
	sort(k, k + n);
	reverse(k, k + n);
	on = k[0], tw = k[1];
	for (int i = 0; i < n; ++i) {
		if (l[i] == on) { cout << tw; }
		else { cout << on; }
		cout << endl;
	}
}

Measured memory_bytes: 4736
import queue
N, M = map(int, input().split())
ParentNum = [None] * N
EdgeFrom = [[] for _ in range(N)]
EdgeTo = [[] for _ in range(N)]
for _ in range(N - 1 + M):
    A, B = map(int, input().split())
    EdgeFrom[B-1].append(A-1)
    EdgeTo[A-1].append(B-1)

for i in range(N):
    if not EdgeFrom[i]:
        ParentNum[i] = 0
        ParentNode = i
        break

Q = queue.Queue()
Q.put(ParentNode)
while not Q.empty():
    currentNode = Q.get()
    for node in EdgeTo[currentNode]:
        if len(EdgeFrom[node]) > 1:
            EdgeFrom[node].remove(currentNode)
        else:
            ParentNum[node] = currentNode + 1
            Q.put(node)
for item in ParentNum:
    print(item)

Measured memory_bytes: 38672
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

ll solve(){
    ll res = 0;
    ll N; cin >> N;
    vector<ll> P(N);
    for(auto& in:P) {cin >> in; in--; }
    vector<ll> a(N);
    for(int i = 0; i < N;i++){
        a[P[i]] = i;
    }
    ll now = 1;
    ll tmp = 1;
    for(int i = 0; i < N-1;i++){
        if(a[i] < a[i+1]){
            now++;
            tmp = max(tmp,now);
        }else{
            now = 1;
        }
    }
    res = N - tmp;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}


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

int main() {
    int x,n;
  cin >> x >> n;
    int a[105];
    for(int i=0; i<= 101; i++) a[i]=0;
    for(int i=0; i<n; i++){
        int y;
        cin >> y;
        a[y]++;
    }
    for(int i=0; i<=200; i++){
        if(x-i>=0 && a[x-i]==0){
            cout << x-i << endl;
            return 0;
        }
        if(x+i<=101 && a[x+i]==0){
            cout << x+i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3652
k = int(input())
ans = 0
import queue

q = queue.Queue()
for i in range(1,10):
    q.put(i)

for i in range(k):
    ans = q.get()
    if ans%10 != 0:
        x = 10*ans + ans%10 - 1
        q.put(x)
    y = 10*ans + ans%10
    q.put(y)
    if ans%10 != 9:
        z = 10*ans + ans%10 + 1
        q.put(z)

print(ans)

Measured memory_bytes: 57428
def cal():

    a, b, c, k = input().split(" ")
    a = int(a)
    b = int(b)
    c = int(c)
    k = int(k)
    ans = 0
    if k <= a:
        ans = k
    elif a < k <= (a+b):
        ans = a
    elif k > (a+b):
        ans = a - (k - (a+b))
    print(ans)



cal()

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

long long N,M;
long long p[100001];
long long tmpx,tmpy;
long long par[100001];

long long root(long long x){
    if(par[x] == x){
        return x;
    }else{
        return par[x] = root(par[x]);
    }
}

void unite(long long x, long long y){
    // std::cout << x<<" "<< y << std::endl;
    x=root(x);
    y=root(y);
    // std::cout << x<<" "<< y << std::endl;
    if(x==y) return;
    par[x]=y;
}

bool same(long long x,long long y){
    return root(x)==root(y);
}

int main() {
    
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> p[i+1];
    }
    
    for (int i = 0; i < N; i++) {
        par[i+1]=i+1;
    }
    
    for (int i = 0; i < M; i++) {
        cin >>tmpx>>tmpy;
        unite(tmpx,tmpy);
    }
    
    long long count=0;
    
    for (int i = 1; i <= N; i++) {
        if(same(i,p[i])){
            count++;
        }
    }
    std::cout << count << std::endl;
}






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

using namespace std;

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

int main() {
    int N, M;
    cin >> N >> M;
    int a[100], b[100], c[100], d[100];
    rep(i, N)cin >> a[i] >> b[i];
    rep(i, M)cin >> c[i] >> d[i];


    rep(i, N) {
        int p[100] = {};
        rep(j, M) {
            p[j] = abs(a[i] - c[j]) + abs(b[i] - d[j]);
        }
        cout << min_element(p, p + M) - p + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#define ll long long
#define N 2000086
using namespace std;
int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
bool bo1[N],bon[N];
int main(){
	//freopen("1.in","r",stdin);
	int n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		if(u>v)swap(u,v);
		bo1[v]|=(u==1);bon[u]|=(v==n);
	}
	bool flag=0;
	for(int i=2;i<=n;i++)
		if(bo1[i]&&bon[i])flag=1;
	if(flag)printf("POSSIBLE");else printf("IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 640
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    lenth = len(s)
    itr = itertools.product([0,1],repeat=lenth-1)
    ans = 0

    for i in itr:
        tmp = s[0]
        cnt = 0
        for plus,char in zip(i, s[1:]):
            if plus == 1:
                cnt += int(tmp)
                tmp = char
            else:
                tmp += char
        cnt += int(tmp)
        ans += cnt

    print(ans)                
        
main()            


Measured memory_bytes: 74968
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ALDS1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int v, j;
            for (int k = 0; k < n - 1; k++)
            {
                Console.Write(a[k] + " ");
            }
            Console.WriteLine(a[n - 1]);
            for (int i = 1; i < n; i++)
            {
                v = a[i];
                j = i - 1;
                while (j >= 0 && a[j] > v)
                {
                    a[j + 1] = a[j];
                    j--;
                }
                a[j + 1] = v;
                for (int k = 0; k < n-1; k++)
                {
                    Console.Write(a[k] + " ");
                }
                Console.WriteLine(a[n - 1]);
            }
        }
    }
}


Measured memory_bytes: 16288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 
int A, B, C;
 
int main(void){
	
	scanf("%d %d %d", &A, &B, &C);
	
	if(A <= C && C <= B) printf("Yes\n");
	else printf("No\n");
	
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

#include <string>

using namespace std;

string leet(string, int, int);    // 変換関数

int main(){
		int N;	cin >> N;
    string str;	cin >> str;
		int K;	cin >> K;
    str = leet(str, N, K);
    cout << str << endl;
    return 0;
}

// 変換関数

string leet(string str, int size, int tgt){

    for(int i=0;i<size;++i)

        if(str[i]!=str[tgt-1]) str[i]='*';

    return str;

};


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

# https://atcoder.jp/contests/abc155/submissions/12182341
def main(N, K, Ap, Am):
    p = len(Ap)
    m = len(Am)
    Ap.sort()
    Am.sort(reverse=True)
    U = 10 ** 18
    L = - 10 ** 18

    while U - L > 1:
        # print("U: {}  L:{}".format(U, L))
        mid = (U+L)//2
        cnt = 0
        if mid >= 0:
            cnt += p*m
            i = p
            t = 0
            for a in Ap:
                while i and Ap[i-1] * a > mid: i -= 1
                t += i
                if a*a <= mid: t -= 1
            cnt += t//2
            i = m
            t = 0
            for a in Am:
                while i and Am[i-1] * a > mid: i -= 1
                t += i
                if a*a <= mid: t -= 1
            cnt += t//2
        else:
            i = m
            for a in Ap:
                while i and Am[i-1] * a <= mid: i -= 1
                cnt += m - i   
        
        if cnt < K:
            L = mid
        else:
            U = mid
        # print("after U: {}  L:{}".format(U, L))
    
    print(U)


    return

if __name__ == '__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
    K = int(next(tokens))  # type: int
    Ap = []
    Am = []
    # A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    for _ in range(N):
        t = int(next(tokens))
        if t>=0:
            Ap.append(t)
        elif t<0:
            Am.append(t)
    main(N, K, Ap, Am)


Measured memory_bytes: 78584
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int main(){
    int a;
    cin >> a;
    if(a<1200){
        put("ABC");
    }else if(a<2800){
        put("ARC");
    }else{
        put("AGC");
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {


	public static void main(String[] args) {
		
		Main answer = new Main();
		long solution = answer.solve();
		System.out.println(solution);
	}

	private long [] dp = new long[100001];

	private long solve() {
		Arrays.fill(dp, -1);
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		Map<Integer, List<Integer>> graph = new HashMap<>();
		for(int i=0;i<M;i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			List<Integer> vertices = graph.getOrDefault(u, new ArrayList<Integer>());
			vertices.add(v);
			graph.put(u, vertices);
		}
		long answer=0;
		for(int i=0;i<=N;i++) {
			long path = pathLength(graph, i);
			answer = Math.max(answer, path);
			//System.out.printf("path length from %d: %d\n", i, path);
		}
		return answer;
	}

	private long pathLength(Map<Integer, List<Integer>> graph, int u) {
		long answer =0;
		//System.out.printf("dp[%d]: %d\n", u, dp[u]);
		if (dp[u] !=-1) return dp[u];
		if (!graph.containsKey(u)) {
			dp[u]=0;
			return 0;
		} else {
			List<Integer> children = graph.get(u);			 
			//System.out.printf("children of %d: %s\n", u, Arrays.toString(children.toArray(new Integer[children.size()])));
			for(int v: graph.get(u)) {
				long path = pathLength(graph, v);
				//System.out.printf("length of %d: %d\n", v, path);
				answer = Math.max(answer, path);
			}
		}
		dp[u] = 1+ answer;
		//System.out.printf("dp[%d]: %d\n", u, dp[u]);
		return dp[u];
	}

}

Measured memory_bytes: 85420
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 n;
vector<i64> a;
int main() {
  cin >> n;
  read_n(a, n);

  i64 s = 0;
  for (i64 x : a) s ^= x;
  for (i64 i = 0; i < n; ++i) a[i] &= ~s;

  for (i64 i = 59, k = 0; i >= 0; --i) {
    bool f = false;
    for (i64 j = k; j < n; ++j) {
      if ((1ll << i) & a[j]) {
        swap(a[k], a[j]);
        f = true;
        break;
      }
    }
    if (!f) continue;
    for (i64 j = 0; j < n; ++j) {
      if (j != k && (1ll << i) & a[j]) a[j] ^= a[k];
    }
    ++k;
  }

  /*
  for (i64 i = 0; i < n; ++i) {
    for (i64 j = 59; j >= 0; --j) {
      cout << ((1ll << j) & a[i] ? '1' : '0');
    }
    cout << endl;
  }
  */

  i64 x = 0;
  for (i64 y : a) x ^= y;
  cout << s + 2 * x << endl;
  return 0;
}


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

int main(){
    int n, l;
    cin >> n >> l;
    int arr[n+1];
    for(int i=1; i<n+1; i++){
        arr[i] = i;
    }
    for(int i=1; i<n+1; i++){
        arr[i] = arr[i] + l -1;
    }
    int min = 1000;
    int sonuc;
    for(int i=1; i<n+1; i++){
        if(abs(arr[i]) < min){
            min = abs(arr[i]);
            sonuc = i;
        }
    }
    int cntr = 0;
    for(int i=1; i<n+1; i++){
        cntr += arr[i];
    }
    cout << cntr- arr[sonuc];
    return 0;
}


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

struct Node{
	int key;
	Node *left,*right,*parent;
	bool visited;
};

Node *root,*NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	z = (Node*)malloc(sizeof(Node));
	z->key=k;
	z->left=NIL;
	z->right=NIL;
	while(x!=NIL){
		y=x;
		if(z->key < x->key){
			x=x->left;
		} else {
			x=x->right;
		}
	}
	z->parent=y;
	if(y==NIL){
		root=z;
	}else{
		if(z->key < y->key){
			y->left=z;
		}else{
			y->right=z;
		}
	}
}

Node* find(int key){
	Node *cur=root;
	while(cur!=NIL){
		if(cur->key==key) return cur;
		if(cur->key>key) cur=cur->left;
		else cur=cur->right;
	}
	return cur;
}

void resetVisitedFlag(){
	stack<Node*>st;
	st.push(root);
	while(st.size()!=0){
		Node *cur=st.top(); st.pop();
		if(cur!=NIL) {
			cur->visited=false;
			st.push(cur->left);
			st.push(cur->right);
		}
	}
}

void inOrder(){
	resetVisitedFlag();
	stack<Node*>st;
	st.push(root);
	while (st.size()!=0){
		Node* cur=st.top()->	left;
		while(cur!=NIL && !cur->visited){
			st.push(cur);
			cur=cur->left;
		}
		cur=st.top(); st.pop();
		cout << " " << cur->key;
		cur->visited=true;
		Node *right=cur->right;
		if(right!=NIL&&!right->visited){
			st.push(right);
		}
	}
	cout << endl;
}

void preOrder(){
	stack<Node*> st;
	st.push(root);
	while(st.size()!=0){
		Node *cur=st.top(); st.pop();
		if(cur!=NIL){
			cout << " " << cur->key;
			st.push(cur->right);
			st.push(cur->left);
		}
	}
	cout << endl;
}

int main(){
	int n,k;
	cin >> n;
	for(int i=0;i<n;i++){
		string cmd;
		cin >> cmd;
		if(cmd=="insert"){
			cin >> k;
			insert(k);
		} else if(cmd=="find"){
			cin >> k;
			if(find(k)!=NIL){
				cout << "yes" << endl;
			} else {
				cout << "no" << endl;
			}
		} else if (cmd=="print"){
			inOrder();
			preOrder();
		}
	}
	return 0;
}



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

using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int y1, x1, y2, x2;
    cin >> y1 >> x1 >> y2 >> x2;
    y1--; x1--; y2--; x2--;

    vector<string> C(h);
    for (auto &c: C)
        cin >> c;

    queue<array<int, 3>> Q;
    Q.push({y1, x1, 0});
    const constexpr int INF = 1e9;
    vector<vector<int>> D(h, vector<int>(w, INF));

    vector<int> dy = {0, 0, 1, -1}, dx = {1, -1, 0, 0};
    D[y1][x1] = 0;

    while (!Q.empty()){
        auto [y, x, d] = Q.front();
        Q.pop();
        for (int i = 0; i < 4; i++){
            for (int j = 1; j <= k; j++){
                int ny = y + dy[i] * j;
                int nx = x + dx[i] * j;
                if (ny < 0 or ny >= h or nx < 0 or nx >= w)
                    break;
                if (D[ny][nx] <= d)
                    break;
                if (C[ny][nx] == '@')
                    break;
              	if (D[ny][nx] <= d + 1)
                  	continue;
                Q.push({ny, nx, d + 1});
                D[ny][nx] = d + 1;
            }
        }
    }

    if (D[y2][x2] == INF){
        puts("-1");
        return 0;
    }

    cout << D[y2][x2] << endl;
}


Measured memory_bytes: 12100
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll fact[400005];

ll extgcd(ll a,ll b,ll& x,ll& y){
	ll d=a;
	if(b!=0LL){
		d=extgcd(b,a%b,y,x);
		y-=(a/b)*x;
	}else{
		x=1;
		y=0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (m+x%m)%m;
}

ll mod_fact(ll n,ll p,ll& e){
	e=0;
	if(n==0)return 1;
	ll res=mod_fact(n/p,p,e);
	e+=n/p;
	if(n/p%2!=0){
		return res*(p-fact[n%p])%p;
	}
	return res*fact[n%p]%p;
}

ll mod_comb(ll n,ll k,ll p){
	if(n<0 || k<0 || n<k)return 0;
	ll e1,e2,e3;
	ll a1=mod_fact(n,p,e1),a2=mod_fact(k,p,e2),a3=mod_fact(n-k,p,e3);
	if(e1>e2+e3)return 0;
	return a1*mod_inverse(a2*a3%p,p)%p;
}

int main(void){
	int n,k;
	scanf("%d%d",&n,&k);
	fact[0]=1;
	for(ll i=1;i<=400000;i++){
		fact[i]=fact[i-1]*i%MOD;
	}
	ll ans=1;
	for(int i=1;i<=min(n-1,k);i++){
		ll val=mod_comb(n,i,MOD);
		ll val2=mod_comb(i+(n-i-1),i,MOD);
		ans+=val*val2%MOD;
		ans%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3328
/*
Mangal bhavan amangal haari
Drabahu su Dasharath achar Bihari
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hoi hai wohi jo Raam rachi raakha
Ko kari tarak badhave saakha
Raam Siya Raam Siya Raam jai jai Raam
Ho dheeraj dharam mitra aru naari
Aapad kaal parakhiye chaari
Ho jehike jehi par satya sanehu
So tehi milay na kachhu sandehu
Ho jaaki rahi bhawana jaisi
Prabhu murati dekhi tin taisi
Ho Raghukul reet sada chali aayi
Praan jaaye par vachan na jaayi
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Ho hari anant hari katha ananta
Kahahi sunahi bahuvidhi sab santa
Raam Siya Raam Siya Raam jai jai Raam, Raam
Raam Siya Raam Siya Raam jai jai Raam
Raam Siya Raam Siya Raam jai jai Raam
*/


#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
//auto->.
//map<int,int>::iterator i
vector<int> sieve(int n) 
{ 

    vector<bool> prime(n+1,true); 
       
    prime[0] = false; 
    prime[1] = false; 
    int m = sqrt(n); 
   vector<int> ans;

    for (int p=2; p<=m; p++) 
    { 
    
        if (prime[p]) 
        { 
         
            for (int i=p*2; i<=n; i += p) 
            prime[i] = false; 
        } 
    }  
    //vector<int> ans; 
    for (int i=0;i<n;i++) 
        if (prime[i]) 
            ans.push_back(i); 
    return ans; 
}

int gcd(int a,int b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int mod = 1e9 + 7;
int power(int a , ll b)
{
	int res = 1;
	while(b)
	{
		if(b & 1)
			res = 1LL * res * a ;//% mod;
		a = 1LL * a * a ;//% mod;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
ll min(int a,ll b)
{
	if(a>b)
	return b;
	return a;
}
ll max(int a,ll b)
{
	if(a>b)
	return a;
	return b;
}
ll myXOR(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}
int conti(int x)
{
	if(x<1)
	return 0;
	if(x%4==0)
	return x;
	if(x%4==1)
	return 1;
	if(x%4==2)
	return x+1;
	if(x%4==3)
	return 0;
}
 
bool ispfsq(long double x) 
{   
  // Find floating point value of  
  // square root of x. 
  long double sr = sqrt(x); 
  
  // If square root is        an integer 
  return ((sr - floor(sr)) == 0); 
}
#define PI 3.141592653589793


vector<int > adj[200005];
bool visited[2005][2005];
int ch[100005],dep[100005];
void solve()
{
int n;
int h,w,k;
cin>>h>>w>>k;
string s[h];
for(int i=0;i<h;i++)
{
	cin>>s[i];
}
int a=0;
for(int mask=0;mask<=(1<<h)-1;mask++)
{
	for(int mask1=0;mask1<=(1<<w)-1;mask1++)
	{
		int ans=0;
		for(int i=0;i<h;i++)
		{
			for(int j=0;j<w;j++)
			{
			//	cout<<(mask>>i)<<" "<<i<<" "<<(mask1>>j)<<" "<<j<<"\n";
				if(((mask>>i)&1)==0&&((mask1>>j)&1)==0&&s[i][j]=='#')
				{
					ans+=1;
				}
			}
		}
	//	cout<<ans<<"\n";
		if(ans==k)
		a++;
	}
}
cout<<a;
}

int main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
int mul=0;
if(mul==1)
{
 int t;
    cin>>t;
   while(t--)
    {
		solve();
	cout<<"\n";
    }
    
}
else
{
//	fun();
	solve();
}
}

Measured memory_bytes: 8372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define x first
#define y second
#define mod 1e9+7
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rof(i,a,b) for(ll i=a;i>b;i--)


vector<ll> a[500001];vector<ll> b[500001];
bool visited[500001];
vector<vector<ll>> c(500001);// components // size nhi diya to 2d vector nahi chalte IMPORTANT
//To search ki konsa element konse component me // use  component number and line 22
//or can also use vector<unordered_map<ll,ll>> c(500001) and c[index][i]++ on line 22
ll compno[500001];
void component_dfs(ll index,ll i)
{  visited[i]=true;  c[index].pb(i);  compno[i]=index;
   for(auto it=a[i].begin();it!=a[i].end();it++)
       if(!visited[*it])  component_dfs(index,*it);
}

//int main() me components(0,n) or (1,n) as per question
void components(ll start,ll n)
{ll index=0;
   for(ll i=start;i<=n;i++)
        { if(!visited[i])   component_dfs(index,i);
            index++;
        }
}

// ll bfs(ll st,ll en) // shortest path bw start and end
// {  ll ans=0;
//  queue<int> q; q.push(st); q.push(-1);
//  while(!q.empty())
//  {
//    if(q.front()==-1) {ans++;q.pop();if(!q.empty()) q.push(-1);continue;}
//    int f=q.front();q.pop();visited[f]=true;
//    if(f==en) break;
//    for(auto it=a[f].begin();it!=a[f].end();it++) if(!visited[*it]) {q.push(*it);visited[*it]=true;}
//  }
//  return ans;
// }

// void dfs(ll i)
// {  visited[i]=true;  
//    for(auto it=a[i].begin();it!=a[i].end();it++)
//        if(!visited[*it]) dfs(*it);
//    jo bhi main kaam ho
// }

void solve()
{
    
ll n,m,k; cin>>n>>m>>k;

f(i,0,m)
{
    ll x,y; cin>>x>>y;
    a[x].pb(y); a[y].pb(x);
}
f(i,0,1+n) visited[i] = false;
f(i,0,k)
{
  ll x,y;cin>>x>>y;
  b[x].pb(y);b[y].pb(x);
}
components(1,n);
ll ans=0;
ll out[n+1];
f(i,0,1+n) visited[i] = false;
for(int i=0;i<c.size();i++)
{
    for(int j=0;j<c[i].size();j++)
    {
      ans=c[i].size()-1;
        ll no=c[i][j];
        ans=ans-a[no].size();
        for(auto it=b[no].begin();it!=b[no].end();it++)
        {
            if(compno[no]==compno[*it])
              ans--;
        }
    out[c[i][j]]=ans;
    }
}
f(i,1,1+n) cout<<out[i]<<" ";
}
int main()
{

ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t=1;
   // cin>>t;
    while(t--)
    {
    
    solve();
    
    }

}

Measured memory_bytes: 48248
#include <iostream>

using namespace std;

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

	long long h, n, w, temp;
	for(h = 1; h <= 3500; ++h) {
		for(n = 1; n <= 3500; ++n) {
			temp = 4 * h * n - N * n - N * h;
			if(temp == 0) {
				continue;
			}
			w = (N * h * n) / temp;
			if(w >= 0 && N * (h * n + n * w + w * h) == 4 * h * n * w) {
				goto end;
			}
		}
	}
end:
	cout << h << " " << n << " " << w;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  if (n % 2 == 0)
    cout << n / 2 << endl;
  else
    cout << n / 2 + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define LSOne(i) (i&(-i))
#define rep(i,a,b) for(int(i)=(a);(i)<(b);i++)
#define rrep(i,a,b) for(int(i)=(a);(i)>(b);i--)
#define BUG(x) {cout<<#x<<" = "<<x<<endl;}
#define left(x) (x<<1)
#define right(x) ((x<<1) +1)
#define middle(s,e)(s+(e-s)/2)
#define size_tree(n) 2*(int)pow(2,ceil(log2(n)))
#define CL(A,I) (memset(A,I,sizeof(A)))
#define endl '\n'
#define PHAS(_n) (pbits[(_n)>>5] & (1u << ((_n) & 0x1f)))
#define PSET(_n) (pbits[(_n)>>5] |= (1u << ((_n) & 0x1f)))
//unsigned int pbits[200000000/32+1];

static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const long double epsilon = 1e-15;
static const long double pi = acos((long double) -1);
using namespace std;
inline void init_io(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef long long ll;
const int MAX_N = 100001;

/*
struct data{
  string s;
  int p,i;
  data():s(""), p(0), i(0){};
  data(string s_, int p_, int i_) : s(s_),p(p_), i(i_){};
  bool operator < (data other) const {
	if(s==other.s)
		return p>other.p;
    return s < other.s;
  }
};
*/

int arr[3*MAX_N];

void rarr(int n){
        rep(i,0,n)
            cin>>arr[i];
}


int main()
{
        init_io();
        cin>>arr[0]>>arr[1]>>arr[2];
        sort(arr,arr+3);
        cout<<arr[0]+arr[1]<<endl;
        return 0;
}

Measured memory_bytes: 256