akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const ll mod = 1e9 +7;


int main() {
    

    string s;
    ll k;
    cin >> s >> k;
    
    string ss = s + s;
    
    ll st = 0;
    bool f = 0;
    if (s.size() == 1)
    {
        f = 1;
    }
    for (int i = 1; i < s.size(); ++i)
    {
        if (s[i] != s[i - 1])
        {
            st = i;
            break;
        }
        if (i == s.size() - 1)
        {
            f = 1;
            break;
        }
    }
    if (f)
    {
        cout << (s.size() * k) / 2ll << endl;
        return 0;
    }
    
    ll c1 = 0, c2 = 0, c3 = 0;
    
    for (int i = 1; i < st; ++i)
    {
        if (ss[i] == ss[i - 1])
        {
            c1++;
            i++;
        }

    }
    for (int i = st + 1; i < st + s.size(); ++i)
    {
        if (ss[i] == ss[i - 1])
        {
            c2++;
            i++;
        }

    }
    
    for (int i = st + 1; i < s.size(); ++i)
    {
        if (ss[i] == ss[i - 1])
        {
            c3++;
            i++;
        }

    }
    
    
    ll ret = c1 + (k - 1ll) * c2 + c3;
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 256
# ABC148a


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)
    # 再帰関数を使わない限りPypyで出すこと

    a = int(input())
    b = int(input())
    print(*set([1, 2, 3]).difference(set([a]), set([b])))
    #sys.stderr.write('Error occurred!')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
n=int(input())
a=[0]+list(map(int,input().split()))+[0]
sm=0
for i in range(n+1):
  sm+=abs(a[i]-a[i+1])
for i in range(1,n+1):
  print(sm+abs(a[i+1]-a[i-1])-(abs(a[i]-a[i-1])+abs(a[i]-a[i+1])))

Measured memory_bytes: 86856
N, M = map(int, input().split())
d = [[] for _ in range(200001)]
for i in range(M):
    a, b = map(int, input().split())
    d[a].append(b)
    d[b].append(a)

ans = 'IMPOSSIBLE'
for i in d[1]:
    if N in d[i]:
        ans = 'POSSIBLE'
        break

print(ans)

Measured memory_bytes: 38320
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << "\n";
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << "\n";
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << "\n";
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll A, B, K;
  cin >> A >> B >> K;
  if(B-A>2*K-2){
    //A, A+1, ..., A+K-1, B-K+1, B-K+2, ... B
    //B-K+1 > A+K-1
    //B-A > 2*K-2
    rep(i, 0, K){
      cout << A+i << "\n";
    }
    rep(i, 0, K){
      cout << B-K+1+i << "\n";
    }
    return 0;
  }

  rep(i, A, B+1){
    cout << i << "\n";
  }

  return 0;
}

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

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

int main(void){
	int n;
	int count[51];

	rep(i,51) count[i] = 0;
	rep(a,10)rep(b,10)rep(c,10)rep(d,10){
		count[a+b+c+d]++;
	}

	while(cin>>n){
		cout<<count[n]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll n,k,q;
  cin >> n >> k >> q;
  vector<ll> ans(n,k-q);
  rep(i,q){
    ll a;
    cin >> a;
    ans[a-1]++;
  }
  rep(i,n){
    cout << (ans[i] > 0 ? "Yes" : "No" ) << endl;
  }
}


Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final int A = sc.nextInt();
			final int B = sc.nextInt();
			
			ArrayList<LinkedList<Integer>> units = new ArrayList<LinkedList<Integer>>();
			for(int i = 0; i < B; i++){ units.add(new LinkedList<Integer>()); }
			
			int rest = N;
			/*
			for(int i = A - 1; i >= 0; i--){
				units.get(0).addLast(N - i);
				rest--;
			}
			*/
			
			for(int i = 0; i < B; i++){
				final int curr_rest = rest;
				for(int j = 0; j < Math.min(A, curr_rest - (B - (i + 1))); j++){
					//System.out.println(rest);
					units.get(i).addFirst(rest);
					rest--;
				}
			}
			
			boolean flg = true;
			int curr_A = 0;
			for(final LinkedList<Integer> list : units){
				flg &= !list.isEmpty();
				curr_A = Math.max(curr_A, list.size());
			}
			//System.out.println(rest + " : " + units);
			
			if(rest != 0 || !flg || curr_A != A){
				System.out.println(-1);
			}else{
				boolean first = true;
				for(final LinkedList<Integer> list : units){
					for(final int id : list){
						System.out.print((first ? "" : " ") + id);
						first = false;
					}
				}
				System.out.println();
			}
			
			
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 82272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int mi=10000;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    int count=0;
    while(a%2==0){
      count++;
      a/=2;
    }
    mi=min(mi,count);
  }
  cout<<mi<<endl;
}
  

Measured memory_bytes: 256
n,e[28],s[7],b;C(d,i){for(i=s[d]?s[d]=0,n:0;i--;e[i]%10-d||C(e[i]/10))e[i]/10-d||C(e[i]%10);}main(i,d){for(;~scanf("%d",&n);b=!puts(!b&&d<3&&d-1?"Yes":"No")){for(i=n;i--;e[i]=d)scanf("%d",&d),b^=1<<d/10^1<<d%10,s[d/10]=s[d%10]=1;C(*e/10);for(d=0;b;d++)b&=b-1;for(i=7;i--;s[i]=0)b|=s[i];}}

Measured memory_bytes: 0
#include <stdio.h>

int prim();

#define empty -1
#define true 1
#define WHITE 0
#define BLACK 2
#define MAX 2000
#define INF 10000000
#define NIL -1

int aij[MAX][MAX],pi[MAX],d[MAX],color[MAX];
int N;

int main()
{
  int a,b,i,j,sum;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      scanf("%d",&aij[i][j]);
      if(aij[i][j]==-1){
        aij[i][j]=INF;
      }
    }
  }
  sum=prim();
  printf("%d\n",sum);
  return 0;
}

int prim(){
  int i,u,r=0,mincost,sum=0,v;
  for(u=0;u<N;u++){
    d[u] = INF;
    pi[u] = NIL;
    color[u] = WHITE;
  }
  d[r] = 0;

  while(true){
    mincost = INF;
    u=-1;
    for(i=0;i<N;i++){
      if(color[i] != BLACK && d[i] < mincost){
        mincost = d[i];
        u=i;
      }
    }
    if(u == NIL){
      break;
    }
    color[u] = BLACK;
    for(v=0;v<N;v++){
      if(color[v] != BLACK && aij[u][v]!=INF && aij[u][v] < d[v]){
        pi[v] = u;
        d[v] = aij[u][v];
      }
    }
  }

  for(i=0;i<N;i++){
    if(pi[i]!=empty){
      sum += d[i];
    }
  }
  return sum;
}

Measured memory_bytes: 1044
/**
 *    author:  Mohamad Milhem
**/

#include <bits/stdc++.h>
#include <stdio.h>

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;
#define decimalpoint cout << std::fixed << setprecision(5)
int h,n;
int yes[1003], no[1003];
int dp[10005];



long long calc(int now){
	if (now <= 0)return 0;

	if (dp[now] != -1)return dp[now];


	long long ans = 2e9;

	for (int i = 0 ; i < n ; i++){
		ans = min(ans, calc(now - yes[i]) + no[i]);
	}

	return dp[now] = ans;
}








void solve(){

	cin >> h >> n;

	for (int i = 0 ; i < n ; i++){
		cin >> yes[i] >> no[i];
	}

	memset(dp, -1 , sizeof dp);


	cout << calc(h) << endl;


}



int main()
{
    FAST;
    int t;
    t = 1;

    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 4152
/**
 *    author:  Aurthur
 *    Created : 12.09.2020       
**/
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <vector>
#include <map>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, a, n) for(int i = a; i < n; ++i)
#define per(i, a, n) for(int i = n-1; i >= a; --i)
#define mp make_pair
typedef long long ll;
using namespace std;
int main()
{
	int x;
	scanf("%d", &x);
	if(x == 0) printf("1\n");
	else printf("0\n");
	return 0;
}


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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const ll INF = 1e9;

int main() {
  ll a, b, c, d;
  fscanf(stdin, "%lld %lld %lld %lld ", &a, &b, &c, &d);
  ll res = -INF*INF;
  res = max(res, a*c);
  res = max(res, a*d);
  res = max(res, b*c);
  res = max(res, b*d);
  fprintf(stdout, "%lld\n", res);
  return 0;
}


Measured memory_bytes: 3788
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int x;
    while(cin>>x){
        for(int i=0;i<15;i++){
            if(x&1){
                cout<<pow(2,i);
                x=x>>1;
                if(x)cout<<' ';
            }
            else x=x>>1;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1272
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

#define DEFMOD(mod, type) typedef ModInt<mod, int> type;     \
                          type operator "" _m(unsigned long long x) {   \
                              type res = x; return res; \
                          }

template<int mod, class itype> struct ModInt {
    int val;
    ModInt() {
        val = 0;
    }
    ModInt(int a) {
        val = a % mod;
    }
};

/* MODIFY AS NEEDED */

DEFMOD(1000000007, mi)

template<int mod, class itype> ModInt<mod, itype> fpow(ModInt<mod, itype> base, int exponent)
{
    ModInt<mod, itype> ans = 1_m;
    ModInt<mod, itype> cur = base;
    while (exponent) {
        if (exponent & 1) ans = ans * cur;
        cur = cur * cur; exponent >>= 1;
    }
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator+(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ll val = (ll)(a.val) + (ll)(b.val);
    if (val >= mod) val -= mod;
    ans.val = val; return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator-(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = a.val - b.val;
    if (ans.val < 0) ans.val += mod;
    return ans;
}

template<int mod, class itype> ModInt<mod, itype> operator*(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
    ModInt<mod, itype> ans;
    ans.val = ((ll)(a.val) * (ll)(b.val)) % (ll)mod;
    return ans;
}

// PRIME MOD ONLY!
template<int mod, class itype> ModInt<mod, itype> operator/(ModInt<mod, itype> a, ModInt<mod, itype> b)
{
#ifndef ONLINE_JUDGE
    if (b.val == 0) {
        fprintf(stderr, "Division by zero :(\n"); abort();
    }
#endif
    return a * fpow(b, mod - 2);
}

mi f[2005][2005];
int n, k;

mi fact[4000005];
mi ifact[4000005];

mi C(int x, int y)
{
    return fact[x] * ifact[y] * ifact[x-y];
}

int main()
{
    fact[0] = 1_m;
    for (int i = 1; i <= 4000000; i++) {
        fact[i] = (mi)i * fact[i-1];
    }
    ifact[4000000] = 1_m / fact[4000000];
    for (int i = 3999999; i >= 0; i--) {
        ifact[i] = ifact[i+1] * (mi)(i + 1);
    }
    scanf("%d%d", &n, &k);
    if (k == 1) {
        printf("1"); return 0;
    }
    f[0][0] = 1_m;
    for (int j = 1; j <= n; j++) {
        for (int i = n; i >= 0; i--) {
            f[i][j] = (i > 0 ? C(k * j - i - 1, k - 2) * f[i-1][j-1] : 0_m)
                + f[i+1][j];
        }
    }
    printf("%d", (f[0][n] * fact[n]).val);
    return 0;
}


Measured memory_bytes: 50140
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v:Vec<char> = Vec::new();
	for i in iter {
		v.push(i.chars().collect::<Vec<char>>()[0]);
	}
	if v[0] == 'H' {
		println!("{}", v[1]);
	}else{
		if v[1] == 'H' {
			println!("D");
		}else{
			println!("H");
		}
	}
}

Measured memory_bytes: 4476
#include <bits/stdc++.h>
#define ll long long
#define fr(i,p,n) for(ll i=p;i<n;i++)
#define fr1(i,p,n) for(ll i=p;i>=n;i--)
#define pb push_back
#include <stdio.h>
#define PI 3.14159265358979323846
#define MOD 1000000007
#define precise cout << std::setprecision(10) << std::fixed;
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios::sync_with_stdio(0);
    int t=1;
    //cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int h[n];
        int dp1[n],dp2[n];
        fr(i,0,n) cin>>h[i];
        dp1[0]=dp2[0]=0;
        dp2[1]=10005;
        dp1[1]=abs(h[1]-h[0]);
        fr(i,2,n)
        {
            dp1[i]=min(dp1[i-1]+abs(h[i]-h[i-1]),dp2[i-1]+abs(h[i]-h[i-1]));
            dp2[i]=min(dp1[i-2]+abs(h[i]-h[i-2]),dp2[i-2]+abs(h[i]-h[i-2]));
        }
        cout<<min(dp1[n-1],dp2[n-1])<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>

using namespace std;

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int n;
VI g[100000];
int d[100000]; // depth
bool did[100000];

void dfs(int p){
	EACH(i,g[p]){
		int np=*i;
		if(did[np])continue;
		did[np]=true;
		d[np] = d[p]+1;
		dfs(np);
	}
}

int up(int p){
	EACH(i,g[p]){
		if(d[p]>d[*i])return *i;
	}
	return -1;
}

int count(int p, int e){
	int res=1;
	EACH(i,g[p]){
		if(d[p]>d[*i])continue;
		if(*i==e)continue;
		res+=count(*i, -1);
	}
	return res;
}

int main() {
	cin>>n;
	REP(i,n-1){
		int a,b;
		cin >> a >> b;
		a--;b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	// DFS
	did[0]=true;
	dfs(0);

	int white=0;

	int before = n-1, now = up(n-1);
	while(now){
		int db = d[now], dw = d[n-1]-d[now];
		if(db > dw){
			white+=count(now, before);
		}
		before = now;
		now = up(now);
	}
	white+=count(n-1, -1);
	if(n-white>white){
		cout << "Fennec";
	}else{
		cout << "Snuke";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 9344
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	long long t, tt;
	long long x, xx, xxx;
	long long y, yy, yyy;
	long long z, zzz;
	long long ans;
	scanf("%lld %lld", &t, &tt);
	scanf("%lld %lld", &x, &xx);
	scanf("%lld %lld", &y, &yy);
	x = x * t;
	y = y * t;
	xx = xx * tt;
	yy = yy * tt;
	xxx = x + xx;
	yyy = y + yy;
	if (xxx == yyy) {
		printf("infinity\n");
		return 0;
	}
	if (xxx > yyy) {
		swap(x, y);
		swap(xx, yy);
		swap(xxx, yyy);
	}
	if (x < y) {
		printf("0\n");
		return 0;
	}
	z = x - y;
	zzz = yyy - xxx;
		ans = z / zzz;
		ans = ans * 2;
		if ((z%zzz) > 0)ans++;
		printf("%lld\n",ans);
		

	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdint>
#include <cstddef>
#include <algorithm>
#include <vector>

int disappear(std::vector<std::vector<int> > &p) {
  size_t W=p.size(), H=p[0].size();
  std::vector<std::vector<int> > to_erase(W, std::vector<int>(H));
  int diff=0;

  for (size_t i=0; i<H; ++i) {
    int l=2, r=3;
    if (p[2][i] == 0) continue;

    while (l > 0) {
      if (p[l][i] == p[l-1][i]) {
	--l;
      } else {
	break;
      }
    }

    while (r < 5) {
      if (p[r][i] == p[r-1][i]) {
	++r;
      } else {
	break;
      }
    }

    if (r-l < 3)
      continue;

    diff += (r-l)*p[2][i];
    for (int j=l; j<r; ++j)
      to_erase[j][i] = 1;
  }

  for (size_t j=0; j<W; ++j) {
    std::vector<int> tmp(H);
    size_t k=0;
    for (size_t i=H; i--;) {
      if (to_erase[j][i]) continue;
      if (p[j][i] == 0) break;

      tmp[k++] = p[j][i];
    }

    std::reverse(tmp.begin(), tmp.end());
    p[j] = std::move(tmp);
  }

  return diff;
}

int solve_testcase() {
  size_t H, W=5;
  scanf("%zu", &H);
  if (H == 0)
    return 1;

  int score=0;
  std::vector<std::vector<int> > board(W, std::vector<int>(H));  // irreg
  for (size_t i=0; i<H; ++i) {
    for (size_t j=0; j<W; ++j) {
      scanf("%d", &board[j][i]);
    }
  }

  int diff;
  while ((diff = disappear(board))) {
    score += diff;
  }

  printf("%d\n", score);
  return 0;
}

int main() {
  while (!solve_testcase()) {}

  return 0;
}

Measured memory_bytes: 2656
#include<bits/stdc++.h>
using namespace std;
#include<cstdio>
#define el "\n"
#define sp " "
typedef long long ll;

main()
{
	ios_base::sync_with_stdio(false);
		cin.tie(NULL);
  	ll n,m;
  cin>>n>>m;
  if(n==m)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(int i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(int i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << " "; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  string s; cin >> s;
  int K; cin >> K;
  int n = s.size();

  VVV dp(K+2, VV(n+1, V(n+1)));

  rep(k, K+1) rep(i, n) rep(j, n) {
    chmax(dp[k][i+1][j+1], dp[k][i+1][j]);
    chmax(dp[k][i+1][j+1], dp[k][i][j+1]);
    chmax(dp[k][i+1][j+1], dp[k][i][j] + (s[i] == s[n-1-j]));
    chmax(dp[k+1][i+1][j+1], dp[k][i+1][j]);
    chmax(dp[k+1][i+1][j+1], dp[k][i][j+1]);
    chmax(dp[k+1][i+1][j+1], dp[k][i][j] + 1);
  }
  int ans = 0;
  rep(i, n+1) chmax(ans, dp[K][i][n-i]*2);
  rep(i, n) chmax(ans, dp[K][i+1][n-i]*2-1);
  
  // rep(i, n+1) cout << dp[0][i] << "\n";

  // cout << "\n";

  // VV a(n+1, V(n+1));
  // rep(i, n) rep(j, n) if (s[i] == s[n-1-j]) ++a[i][j];
  // rep(i, n+1) cout << a[i] << "\n";

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


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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    vector<ll> a(N);
    rep(i,N) cin >> a[i];

    ll key = 1;
    ll ans = 0;
    rep(i,N)
    {
        if( a[i] == key ) key++;
        else
        {
            ans++;
        }
    }
    if( ans == N ) cout << -1 << endl;
    else cout << ans << endl;
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  int L,R;
  L = A+B;
  R = C+D;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (L < R) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define itn int
#define gI gi
 
using namespace std;
 
typedef long long ll;
 
inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}
 
inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}
 
int n, m, a[100003];
char s[100003];
 
int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi(), m = gi();
	if (n > m) swap(n, m);
	for (int i = 1; i <= m; i+=1) cout << n;
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
// C.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

int main(int argc, char *argv[]) {
	int n;
	cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; ++i) {
		cin >> x[i];
	}
	vector<int> y = x;
	sort(y.begin(), y.end());
	int a = y[n / 2 - 1], b = y[n / 2];
	for (int i = 0; i < n; ++i) {
		cout << (x[i] < b ? b : a) << endl;
	}
	return 0;
}


Measured memory_bytes: 3712
fun main(args: Array<String>) {
    c76(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun c76(args: Array<String>) {
    val s = args[0]
    val t = args[1]

    var ans: String? = null
    for (sindex in (0 until s.length - (t.length - 1))) {
        var unable = false
        val orig = s.replace('?', 'a').toMutableList()
        for (tindex in (0 until t.length)) {
            if (s[sindex + tindex] == '?' || s[sindex + tindex] == t[tindex]) {
                orig[sindex + tindex] = t[tindex]
            } else {
                unable = true
                break
            }
        }
        if (unable) {
            continue
        } else {
            val candidate = orig.joinToString(separator = "")
            if (ans == null) {
                ans = candidate
            } else {
                ans = if (ans < candidate) ans else candidate
            }
        }
    }

    println(ans ?: "UNRESTORABLE")
}

Measured memory_bytes: 33808
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if(a>=2*b)
	{
		printf("%d\n",a-2*b);
	}
	else
	{
		printf("0\n");
	 } 
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b;
  cin >> a >> b;
  if((a-b)%2!=0)cout << "IMPOSSIBLE" << endl;
  else cout << (a+b)/2 << endl;
}  


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main{
  static int n;
  static int[] s;

  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    n = sc.nextInt();
    s = new int[n];
    for(int i = 0; i < n; i++){
      s[i] = sc.nextInt();
    }

    int sum = 0;
    for(int i = 0; i < n; i++){
      sum += s[i];
    }

    if(sum % 10 != 0){
      System.out.println(sum);
      return;
    }

    int max = 0;
    for(int i = 0; i < n; i++){
      if((sum - s[i]) % 10 != 0){
        max = Math.max(max, sum - s[i]);
      }
    }

    System.out.println(max);
  }
}


Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
//#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;
int n,m,ok;

map<string,int> mp;
set<string> st[maxn];

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin>>n;
	int ans = 0;
	for(int i = 1; i <= n; i++) 
	{
		cin>>s;
		mp[s]++;
		ans = max(ans,mp[s]);
		st[mp[s]].insert(s);
	}
	for(auto i : st[ans])
	{
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 42752
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct tree{
  vector <int> children;
  string str;
  int d;
};

vector <tree> ts;
int v[1005]={};
void saiki(int n){
  if(v[n]==0){
    string buf="";
    for(int i=0;i<ts[n].d;i++) buf+=".";
    cout << buf << ts[n].str << endl;
    v[n]=1;
    for(int i=0;i<ts[n].children.size();i++){
      saiki(ts[n].children[i]);
    }
  }
}
int main(){
  int n;
  int b;
  string buf;
  tree t;
  
  int i,j,k;
  cin >> n;
  cin >> k;
  cin >> t.str;
  t.d=0;
  ts.push_back(t);
  for(i=1;i<n;i++){
    cin >> k;
    k--;
    cin >> t.str;
    t.d=ts[k].d+1;
    ts[k].children.push_back(i);
    ts.push_back(t);
  }
  for(i=0;i<n;i++){
    saiki(i);
  }
}

Measured memory_bytes: 2176
#coding:utf-8
#解き直し
n = int(input())
b = list(map(int, input().split()))

a = []
# 最初は強制的にbの最初の値が入る
a.append(b[0])

# 2番目からn-1番目まではb[i], b[i-1]の最小値が入る
for i in range(1, n-1):
    a.append(min(b[i], b[i-1]))

# 最後はbの最後の要素が入る
a.append(b[n-2])
#print(a)
print(sum(a))

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

#ifdef LOCAL
#include "prabh.hpp"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define rrange(v) v.rbegin(), v.rend()
#define mod (int)(1e9 + 7)
#define inf (int)(5e18)
#define N (int)(1e6 + 10)

using namespace std;

void solve() {
	vector<int> cnt(N);
	for (int i = 1; i < N; i++) {
		for (int j = i; j < N; j += i)
			cnt[j]++;
	}
	int n; cin >> n;
	int ans = 0;
	for (int i = 1; i < n; i++)
		ans += cnt[n - i];

	cout << ans << endl;

}
// Remember to clear the global containers



// Got stuck and want to leave ? look at the bottom once..
int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
	// cin >> t_c;
	while (t_c--)
		solve();
}
/* Come on Dude .. Dont get up until u get the solution
 * Giving up not gonna help ryt ? So get ur lazy ass to code already
 * You can do it ... Stay Calm and Dont Panic :)
 */


Measured memory_bytes: 11056
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>

using namespace std;

int main() {

  while ( true ) {
    int n, a, b, c, x;
    cin >> n >> a >> b >> c >> x;
    if ( n == 0 ) break;
    
    vector<int> ys(n);
    for ( int i = 0; i < n; i++ ) {
      cin >> ys[ i ];
    }
    
    bool success = false;
    int index = 0;
    for ( int i = 0; i <= 10000; i++ ) {
      if ( x == ys[ index ] ) {
	index++;
      }
      if ( index == n ) {
	cout << i << endl;
	success = true;
	break;
      }
      x = ( a * x + b ) % c;
    }
    if ( !success ) {
      cout << -1 << endl;
    }    
  }  
}

Measured memory_bytes: 1196
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def main():
	n, k = map(int, input().split())

	ans = 0
	tmp = 1/n

	for i in range(1, n+1):
		if i >= k:
			ans += tmp
			continue
		count = 0
		num = i
		while True:
			num *= 2
			count += 1
			if num >= k:
				ans += tmp * pow(0.5, count)
				break

	print(ans)



if __name__ == '__main__':
	import sys
	sys.exit(main())


Measured memory_bytes: 2940
/*******************************
 * written by Koki Riho
 * Rih0z https://github.com/Rih0z
 *******************************/

#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<numeric>
#include<algorithm>

#define DEBUG false

#define FOR(i , a, b) for(size_t i = a ; i < b ; i++ )
#define REP(i,b) FOR(i , 0 , b)
#define RFOR(i,a,b) for(size_t i = a-1 ; i >= b ; i--)
#define RREP(i,a) RFOR(i,a,0)



typedef long long ll;
using namespace std;

int scanInt(void);
string scanString(void);

void scanLlArr(ll *a , int n);
void scanCharArr(char *string);

void printInt(int p);
void printLlArr(ll *a);
void printCharArr(char *string);


void perSum(ll *a , ll *sum ,int n);

/*************Global variable  **************/
int N ;
string S ;
char str[26];
std::map<char,int> M ;
/*******************************/
int func(string s , string t ){
  int ans = 0 ;
  for(char c = 'a' ; c <= 'z' ; c++ ){
  bool founds = false ;
  bool foundt = false ;
    for(int i = 0 ; i < s.length(); i++){
      if(s[i] == c)
        founds = true;
    
    }

    for(int i = 0 ; i < t.length(); i++){
      if(t[i] == c)
        foundt = true;
    
    }
    if(founds && foundt)
      ans++;
  }
  return ans;
}

int main(){
  if (DEBUG){
    std::printf("******debug mode********\n");
  }
  cin >> N >> S ;
  int ans = 0 ;
  for(int i =0 ; i < N; i++ ){
    int tmp = func(S.substr(0,i),S.substr(i));
    ans = max(tmp,ans);
  
  }
  cout << ans << endl ;

  if (DEBUG){
    std::printf("******debug********\n");

    std::printf("******debug********\n");
  }
  return 0 ;
}

//各地点までの部分和を計算する
void perSum(ll *a , ll *sum ,int n){
  int i ;
  sum[0] = a[0];
  for(i = 1 ; i < n ; i++){
    sum[i] = a[i] + sum[i-1];
  }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

const int MAX_V = 10, INF = 1 << 24;
int V;
int d[MAX_V], used[MAX_V], cost[MAX_V][MAX_V];

void dijkstra(int s){
	std::fill(d, d+MAX_V, INF);
	std::fill(used, used+MAX_V, 0);

	d[s] = 0;

	while(true){
		int v = -1;
		for(int u=0;u<V;u++){
			if(!used[u] && (v == -1 || d[u] < d[v])){
				v = u;
			}
		}

		if(v == -1){
			break;
		}

		used[v] = 1;
		for(int u=0;u<V;u++){
			d[u] = std::min(d[u], d[v] + cost[v][u]);
		}
	}
}

int getCost(int s){
	dijkstra(s);
	int res = 0;
	for(int i=0;i<V;i++){
		if(i != s){
			res += d[i];
		}
	}

	return res;
}

int main(){
	int n = 0;
	while(std::cin >> n, n){
		for(int i=0;i<MAX_V;i++){
			std::fill(cost[i], cost[i]+MAX_V, INF);
		}
		V = 0;

		for(int i=0;i<n;i++){
			int a, b, c;
			std::cin >> a >> b >> c;
			cost[a][b] = c;
			cost[b][a] = c;
			V = std::max(V, std::max(a+1, b+1));
		}

		int res = INF, town = 0;
		for(int i=V-1;i>=0;i--){
			int v = getCost(i);
			if(v <= res){
				res = v;
				town = i;
			}
		}
		std::cout << town << " " << res << std::endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef int64_t llong;


int main(){
    char x,y;
    cin >> x >> y;
    map<char,int> A;
    A['A']=1;
    A['B']=2;
    A.insert(make_pair('C',3));
    A.insert(make_pair('D',4));
    A['E']=5;
    A['F']=6;
    if( A[x] < A[y]) cout << '<' << endl;
    if( A[y] < A[x]) cout << '>' << endl;
    if( A[x] == A[y]) cout << '=' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint         = long long;
constexpr lint inf = 1LL << 60;
constexpr lint mod = 1000000007;

template <int mod = mod>
struct modint {
    lint v;
    modint() : v(0) {}
    modint(signed v) : v(v) {}
    modint(lint t) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    modint pow(lint k) {
        modint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static modint add_identity() { return modint(0); }
    static modint mul_identity() { return modint(1); }
    modint inv() { return pow(mod - 2); }

    modint &operator+=(modint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    modint &operator-=(modint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    modint &operator*=(modint a) {
        v = v * a.v % mod;
        return *this;
    }
    modint &operator/=(modint a) { return (*this) *= a.inv(); }

    modint operator+(modint a) const { return modint(v) += a; };
    modint operator-(modint a) const { return modint(v) -= a; };
    modint operator*(modint a) const { return modint(v) *= a; };
    modint operator/(modint a) const { return modint(v) /= a; };

    modint operator-() const { return v ? modint(mod - v) : modint(v); }

    bool operator==(const modint a) const { return v == a.v; }
    bool operator!=(const modint a) const { return v != a.v; }
    bool operator<(const modint a) const { return v < a.v; }
};
using mint = modint<mod>;
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<vector<vector<mint>>> dp(m + 1, vector<vector<mint>>(n + 1, vector<mint>(n + 1, 0)));
    dp[0][1][1] = 1; // step, visited, scc
    for (lint i = 0; i < m; ++i) {
        for (lint j = 1; j <= n; ++j) {
            for (lint k = 1; k <= j; ++k) {
                if (j != n) {
                    dp[i + 1][j + 1][k] += dp[i][j][k] * (n - j);
                }
                dp[i + 1][j][j] += dp[i][j][k] * (k);
                dp[i + 1][j][k] += dp[i][j][k] * (j - k);
            }
        }
    }
    cout << dp[m][n][n] << "\n";
    return 0;
}

Measured memory_bytes: 216832
#include <stdio.h>
#define MAXN 105
#define MAXNC 10005

int main()
{
    int h, w, n;
    while(scanf("%d%d", &h, &w) != EOF)
    {
        int a[MAXN][MAXN], color[MAXNC];
        scanf("%d", &n);
        for(int i = 0; i < n; i++)
            scanf("%d", &color[i]);
        int c = 0;
        for(int i = 0; i < h; i++)
        {
            if(i%2 == 0)
                for(int j = 0; j < w; j++)
                {
                    a[i][j] = c + 1;
                    color[c]--;
                    if(color[c] == 0)
                        c++;
                }

            else
                for(int j = w -1; j >= 0; j--)
                {
                    a[i][j] = c + 1;
                    color[c]--;
                    if(color[c] == 0)
                        c++;
                }
        }
        for(int i = 0; i < h; i++)
            for(int j = 0; j < w; j++)
            {
                printf("%d",a[i][j]);
                if(j == w - 1)
                    printf("\n");
                else
                    printf(" ");
            }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define sc(x) scanf("%d",&x);
int main(){
    int n, k, x;
    ll sum = 0, ans = 0;
    sc(n) sc(k)
    vector<int> vec(200000);
    for (int i = 0; i < n; i++){
        sc(x)
        vec[x] += 1;
    }
    sort(vec.begin(), vec.end(), greater<int>());
    for (int i = 0; i < vec.size(); i++){
        sum += 1;
        if (sum > k) ans += vec[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
long long power(long long a,long long now) {
	long long ans = 1;
	while (now != 0) {
		if (now % 2 == 1) {
			ans *= a;
			ans %= MAX_MOD;
		}
		now /= 2;
		a *= a;
		a %= MAX_MOD;
	}
	return ans;
}
long long inv(long long a) {
	return power(a, MAX_MOD - 2);
}
long long permutation(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
	}
	return ans;
}
long long combination(long long a, long long b) {
	long long ans = 1;
	for (long long i = 0; i < b; ++i) {
		ans *= (a - i);
		ans %= MAX_MOD;
		ans *= inv(i + 1);
		ans %= MAX_MOD;
	}
	return ans;
}
int main() {
	long long n, k;
	cin >> n >> k;
	cout << combination(k, n) << endl;
}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    struct dice{int u,e,w,n,s,d;
    void rotate(char c){
        int temp=u;
        if(c=='E'){u=w;w=d;d=e;e=temp;}
        else if(c=='W'){u=e;e=d;d=w;w=temp;}
        else if(c=='N'){u=s;s=d;d=n;n=temp;}
        else if(c=='S'){u=n;n=d;d=s;s=temp;}
    }
    bool hikaku(dice q){
        int counter=0;
        if(u==q.u)counter++;
        if(s==q.s)counter++;
        if(e==q.e)counter++;
        if(w==q.w)counter++;
        if(n==q.n)counter++;
        if(d==q.d)counter++;
        if(counter==6)return true;else return false;
    }
    };
    dice a,b;
    in(a.u,a.s,a.e,a.w,a.n,a.d);
    in(b.u,b.s,b.e,b.w,b.n,b.d);
    int x,y;
    string s="NNNNENNNN";
    rep(i,9){
        if(a.s==b.s)break;
        b.rotate(s[i]);
    }
    int counter=0;
    while(!a.hikaku(b)){
        b.rotate('E');
        counter++;
        if(counter>=8){
            out("No");
            return 0;
        }
    }
    out("Yes");
}


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

using namespace std;
#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

int mini = INT_MAX;
int n, m, x;


vector<vector<int>> A;
vector<int> cost;
void brutef(int i, vector<int> sum, vector<bool> inc){
  //cout << i << endl;
  //for (int j = 0; j < n; j++) cout << int(inc[j]) << " ";
  //cout << endl;
  if (i != n - 1)  
  brutef(i + 1, sum, inc);
  inc[i] = true;
  for (int j = 0; j < m; j++) sum[j] += A[i][j];
  bool flag = false;
  for (int j = 0; j < m; j++) if (sum[j] < x) flag = true;
  int tot = 0;
  if (!flag) {
    for (int j = 0; j < n; j++) if (inc[j] == true) tot += cost[j];
    mini = min(mini, tot);
    //cout << "WOW " << i << " " << tot << endl;
  }
  else if (i < n - 1) {
    inc[i] = true;
    brutef(i + 1, sum, inc);
  }
}
int main()
{
    quicker
    //int n, m, x;
    //vector<vector<int>> A(n, vector<int>(m, 0));
    cin >> n >> m >> x;
    A = vector<vector<int>>(n,vector<int>(m, 0));
    cost = vector<int>(n, 0);
    for (int i = 0; i < n; i++){
      cin >> cost[i];
      for (int j = 0; j < m; j++){
        cin >> A[i][j];
      }
    }
    vector<int> sum(m , 0);
    vector<bool> inc(n, false);
    brutef(0, sum, inc);
    if (mini == INT_MAX) mini = -1;
    cout << mini;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    vector<pair<int, int>> v;
    for (int i = -1000; i <= 1000; i++) {
        v.push_back({i, pow(i, 5)});
    }
    int ans = 0;
    for (int i = 0; i < (int)v.size(); i++) {
        for (int j = i + 1; j < (int)v.size(); j++) {
            if (v[i].second - v[j].second == x || v[j].second - v[i].second == x) {
                cout << max(v[i].first, v[j].first) << " " << min(v[i].first, v[j].first);
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4152
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int dp[110], price[110];
int solve(int id, vector< vector< vector<int> > >& recipe) {
    if(dp[id] != INF) return dp[id];

    dp[id] = price[id];
    for(auto vec : recipe[id]) {
        int sum = 0;
        for(auto e : vec) {
            sum += solve(e, recipe);
        }
        chmin(dp[id], sum);
    }
    return dp[id];
}
 
signed main() {
    int N, M;
    while(cin >> N, N) {
        int id = 0;
        map<string, int> stoid;

        for(int i=0; i<N; i++) {
            string s;
            cin >> s >> price[i];
            stoid[s] = id++;
        }

        cin >> M;
        fill(dp, dp + N, INF);
        vector< vector< vector<int> > > recipe(N);
        for(int i=0; i<M; i++) {
            string s; cin >> s;
            int idx = stoid[s];

            int K; cin >> K;
            vector<int> tmp_list;
            for(int j=0; j<K; j++) {
                string t; cin >> t;
                tmp_list.push_back(stoid[t]);
            }
            recipe[idx].push_back(tmp_list);
        }

        string x; cin >> x;
        cout << solve(stoid[x], recipe) << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]

mean = sum(a) / n

ans = [200, 200]

for i in range(n):
    if abs(mean - a[i]) < ans[1]:
        ans = [i, abs(mean - a[i])]

print(ans[0])


Measured memory_bytes: 38256