akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define print(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<ll,ll>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

int main(){
    ll N; cin >> N;
    vector<ll> num, primes;
    for(ll i = 2; i <= 101000; ++i) num.pb(i);
    while(num.size()){
        primes.pb(num[0]);
        for(ll j = num.size()-1;j>=0;--j){
            if(num.at(j) % num.at(0) == 0) num.erase(num.begin() + j);
        }
    }
    
    rep(i,sz(primes)) if(primes[i] >= N){print(primes[i]); break;}

    return 0;
}

Measured memory_bytes: 1400
#include<stdio.h>
#include<string.h>
#include<math.h>
int main() {
	int i,j;
	char w[100][100];
	scanf("%d %d",&i,&j);
	for(int a=0; a<i; a++) {
		getchar();
		for(int b=0; b<j; b++) {
			scanf("%c",&w[a][b]);
		}
	}
	for(int a=0; a<i; a++) {
		for(int b=0; b<j; b++) {
			printf("%c",w[a][b]);
		}
		printf("\n");
		for(int b=0; b<j; b++) {
			printf("%c",w[a][b]);
		}
		printf("\n");
	}
	return 0;
}

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

#define endl "\n"
#define all(x) x.begin(),x.end()
#define pb push_back
#define ff first 
#define ss second 
#define pii pair<int,int>
#define vi vector<int>
#define vc vector<char>
#define vii vector<pii>
#define vvi vector<vi>
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int N=100*1000;
const int mod=1e9+7;

int min3(int a,int b,int c){return min(a,min(b,c));}
int max3(int a,int b,int c){return max(a,max(b,c));}
int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

//#define int int64_t
//int a[N+2];

int32_t  main(){
	IOS;
  int a,b,c;cin>>a>>b>>c;
  if(a==b && b==c)cout<<"Yes\n";
  else cout<<"No\n";

  return 0;
}



Measured memory_bytes: 256
def calc(n):
    if n == 0:
        return -1
    s = 0
    n_ = n
    while n:
        s += n%10
        n //= 10
    return n_/s

# res = []
# for i in range(1,10**6):
#     res.append((i/sunuke(i), i))
#     # print(i, i/sunuke(i))
# res.sort()
# max_i = 0
# ret = []
# for v, i in res:
#     if i > max_i:
#         max_i = i
#         print(i, v)
#         ret.append(i)
# print(ret)

k = int(input())
for i in range(1, min(9,k)+1):
    print(i)
cnt = min(9,k)
i = min(9,k)
d = 1

while cnt < k:
    # print(i,d)
    while calc(i+d) > calc(i+d*10):
        d *= 10
    i +=d
    print(i)
    cnt += 1

# vv = [30999,39999]
# for v in vv:
#     print(v, v/sunuke(v), 10)

Measured memory_bytes: 3188
def main():
    import sys
    input = sys.stdin.readline

    JUDGE = 'AC', 'WA', 'TLE', 'RE'

    ctr = dict()
    for case in JUDGE:
        ctr[case] = 0

    N = int(input())
    for _ in range(N):
        s = input().rstrip()
        ctr[s] += 1

    for case in JUDGE:
        print(case, 'x', ctr[case])


if __name__ == '__main__':
    main()


Measured memory_bytes: 9192
//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it before "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    string str;
    cin >> str;
    int ok = 0;
    for (int i = 0;str[i];i ++) if (str[i] == '7') ok = 1;
    if (ok) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3168
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[2 * n];
        for (int i = 1; i <= 2 * n; i++) {
            arr[i - 1] = i;
        }
        int[] next = new int[2 * n];
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int x = sc.nextInt();
            if (x == 0) {
                for (int j = 0; j < n; j++) {
                    next[2 * j] = arr[j];
                    next[2 * j + 1] = arr[n + j];
                }
            } else {
                System.arraycopy(arr, x, next, 0, 2 * n - x);
                System.arraycopy(arr, 0, next, 2 * n - x, x);
            }
            System.arraycopy(next, 0, arr, 0, 2 * n);
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < 2 * n; i++) {
            sb.append(arr[i]).append("\n");
        }
        System.out.print(sb);
    }
}



Measured memory_bytes: 29780
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int room[5][4][11] = {0};
    int i=0,j=0,k=0,b=0,f=0,r=0,v=0,count=0;
    scanf("%d",&count);
    for(i=1;i<=count;i++){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        room[b][f][r]+=v;
    }
    for(i=1;i<5;i++){
        for(j=1;j<4;j++){
            for(k=1;k<11;k++){
                printf(" %d",room[i][j][k]);
            }
            printf("\n");
        }
        if(i<4){
            printf("####################\n");
        }
    }
    return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s; cin >> s;
    int ans = INF;
    for(char i = 'a'; i <= 'z'; i++) {
        int ans2 = 0;
        int cnt = 0;
        bool flag = false;
        for(int j = s.size()-1; j >= 0; j--) {
            if(i==s[j]) {
                ans2 = max(ans2,cnt);
                cnt = 0;
                flag = true;
                continue;
            }
            cnt++;
        }
        if(flag) {
            ans2 = max(ans2,cnt);
            ans = min(ans,ans2);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<vector>
#include<iostream>

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

using namespace std;

int n,val[40];
vector<int> G[40];

bool vis[40],used[40];

void dfs1(int u,vector<int> &order){
	vis[u]=true;
	order.push_back(u);
	rep(i,G[u].size()){
		int v=G[u][i];
		if(!vis[v]) dfs1(v,order);
	}
}

int res;
void dfs2(int i,const vector<int> &order,int sum){
	// pruning!!
	int sum2=0;
	for(int j=i;j<order.size();j++) sum2+=val[order[j]];
	if(sum+sum2<=res) return;

	if(i==order.size()){
		res=max(res,sum);
		return;
	}

	int u=order[i];

	// 頂点 u を選べるかどうかを判定
	bool ok=true;
	rep(j,G[u].size()){
		int v=G[u][j];
		if(used[v]) ok=false;
	}

	int res=0;
	if(u!=0){
		dfs2(i+1,order,sum);
	}
	if(ok){
		used[u]=true;
		dfs2(i+1,order,sum+val[u]);
		used[u]=false;
	}
}

int main(){
	for(;cin>>n,n;){
		rep(u,n) G[u].clear();

		int nf=0;
		map<string,int> f;
		rep(i,n){
			string s;
			int tmp,m; cin>>s>>tmp>>m;
			if(f.count(s)==0) f[s]=nf++;
			int u=f[s];
			val[u]=tmp;
			rep(i,m){
				string t; cin>>t;
				if(f.count(t)==0) f[t]=nf++;
				int v=f[t];
				G[u].push_back(v);
			}
		}

		rep(u,n){
			vis[u]=false;
			used[u]=false;
		}

		int ans=0;
		rep(u,n) if(!vis[u]) {
			vector<int> order;
			dfs1(u,order);
			res=0;
			dfs2(0,order,0);
			ans+=res;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 956
#include <iostream>
#include <string>

using namespace std;

int main(){
	

	int dc[13];
	dc[1]=31;
	dc[2]=29;
	dc[3]=31;
	dc[4]=30;
	dc[5]=31;
	dc[6]=30;
	dc[7]=31;
	dc[8]=31;
	dc[9]=30;
	dc[10]=31;
	dc[11]=30;
	dc[12]=31;

	string week[8];
	week[0]="Monday";
	week[1]="Tuesday";
	week[2]="Wednesday";
	week[3]="Thursday";
	week[4]="Friday";
	week[5]="Saturday";
	week[6]="Sunday";

	int month;
	int day;
	while(cin>>month>>day&&!(month==0&&day==0)){
		int passingDay=2;
		for(int i = 1; i < month; i++){
			passingDay+=dc[i];
		}
		passingDay+=day;
		cout<<week[passingDay%7]<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> V(N), C(N);
    for (int n = 0; n < N; ++n) {
        cin >> V[n];
    }
    for (int n = 0; n < N; ++n) {
        cin >> C[n];
    }
    int Res = 0;
    for (int n = 0; n < N; ++n) {
        int Tmp = V[n] - C[n];
        if (Tmp > 0) Res += Tmp;
    }
    cout << Res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){

    int N,A,sum=0; cin >> N;
    
    for(int i=0;i<N;i++){ cin >> A; if(A%2==1){sum++;} }
    
    if(sum %2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3564
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		while (solv(sc)) {
			;
		}

		sc.close();

	}

	private boolean solv(Scanner sc) {
		int w = sc.nextInt();
		int h = sc.nextInt();

		if (w == 0 && h == 0) {
			return false;
		}

		int[][][] m = new int[h + 2][w + 2][4];

		for (int i = 0; i <= h + 1; i++) {
			for (int j = 0; j <= w + 1; j++) {
				Arrays.fill(m[i][j], 1);
			}
		}

		// 読み込みがバグってる
		for (int j = 1; j <= h - 1; j++) {
			for (int i = 1; i <= w - 1; i++) {
				int n = sc.nextInt();
				m[j][i][1] = n;
				m[j][i + 1][3] = n;
			}
			for (int i = 1; i <= w; i++) {
				int n = sc.nextInt();
				m[j][i][2] = n;
				m[j + 1][i][0] = n;
			}
		}
		for (int i = 1; i <= w - 1; i++) {
			int n = sc.nextInt();
			m[h][i][1] = n;
			m[h][i + 1][3] = n;
		}

		Queue<List<Integer>> q = new ArrayDeque<>();
		q.add(Arrays.asList(1, 1));

		int[][] a = new int[h + 1][w + 1];
		int[] dy = { -1, 0, 1, 0 };
		int[] dx = { 0, 1, 0, -1 };

		a[1][1] = 1;

		while (!q.isEmpty()) {
			List<Integer> l = q.poll();
			int y = l.get(0);
			int x = l.get(1);

			if (x == w && y == h) {
				break;
			}

			for (int i = 0; i < 4; i++) {
				if (m[y][x][i] == 0 && a[y + dy[i]][x + dx[i]] == 0) {
					a[y + dy[i]][x + dx[i]] = a[y][x] + 1;
					q.add(Arrays.asList(y + dy[i], x + dx[i]));
				}
			}
		}

		out.println(a[h][w]);

		return true;
	}

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



Measured memory_bytes: 70444
str = gets.chomp
n = gets.to_i

n.times{

ord = gets.split

d = ord[0][2]

a = ord[1].to_i
b = ord[2].to_i

case d

when "i"
puts str[a, b-a+1]

when "p"
t = ord[3]

for i in 0..(b-a)
str[a+i] = t[i]
end

when "v"
t = str.clone

for i in 0..(b-a)
str[a+i] = t[b-i]
end

end

}





Measured memory_bytes: 6884
#pragma GCC optimize("Ofast")  
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define int long long 
#define endl "\n"
#define all(x) (x).begin(),(x).end()
const int MOD = 1e9+7;
const int mxN = 2e5+3;

void solve(){
	char c;
	cin >> c;
	int x = (int)c;
	if(x>=65 and x<=90)cout << "A" << endl;
	else if(x>=97 and x<=122)cout << "a" << endl;
}

int32_t main(){
	IO;
	
	int nT = 1;
	//cin >> nT;
	for(int i = 1; i <= nT; ++i)
		solve();
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

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

int AH[100];
int AL[100];
int main(){
    int N;
    cin >> N;
    int inp;

    cin >> AH[0];
    REP(i,N-1){
        cin >> inp;
        AH[i+1] = inp + AH[i];
    }

    cin >> AL[0];
    REP(i,N-1){
        cin >> inp;
        AL[i+1] = inp + AL[i];
    }

    int sum;
    int max = AH[0] + AL[N-1];
    for(int i = 1; i < N; i++){
        sum = AH[i] + (AL[N-1] - AL[i-1]);
        if(sum > max)
            max = sum;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200010;

#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> pii;
#define INF 0x3f3f3f3f
int mod = 1000000007;
	
int main()
{
	//freopen("in.txt", "r", stdin);
	long long x, y;
	while (cin >> x >> y)
	{
		int cnt = 0;
		for (; x <= y; x <<= 1)
		{
			cnt++;
		}
		printf("%d\n", cnt);
	}

   	return 0;
}

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

ll S[1<<16], dp[1<<16];

int A[16][16];

int N;

int main() {
	cin >> N;
	for(int i = 0; i < N; i++) for(int j = 0; j < N; j++) cin >> A[i][j];
	for(int k = 1; k < (1<<N); k++) {
		ll &r = S[k];
		for(int i = 0; i < N; i++) if(k & (1<<i))
			for(int j = i+1; j < N; j++) if(k & (1<<j))
				r += A[i][j];
	}
	for(int k = 1; k < (1<<N); k++) {
		ll &r = dp[k];
		for(int v = k; v; v = (v-1) & k) {
			ll t = S[v] + dp[k^v];
			if(r < t) r = t;
		}
	}
	cout << dp[(1<<N)-1] << endl;
	return 0;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

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

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int r,g;cin>>r>>g;){
		cout<<2*g-r<<endl;
	}
}


Measured memory_bytes: 256
card_exists = {
    "S" : [False for _ in range(13)],
    "H" : [False for _ in range(13)],
    "C" : [False for _ in range(13)],
    "D" : [False for _ in range(13)]
}

card_count = int(input())
for i in range(card_count):
    suit, num = input().split()
    card_exists[suit][int(num) - 1] = True

for suit in card_exists.keys():
    for idx, exists in enumerate(card_exists[suit]):
        if not exists:
            print(suit, str(idx + 1))



Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int leng;
  cin >>leng;
  map<char,long long>rgb;
  string s;
  cin >>s;
  rgb['R']=0,rgb['G']=0,rgb['B']=0;
  for(int i=0;i<leng;i++){
    rgb.at(s.at(i))++;
  }
  long long tmp=0;
  for(int i=0;i<leng-2;i++){
    for(int j=1;i+j+j<leng;j++){
      if((s.at(i)==s.at(i+j)||s.at(i)==s.at(i+2*j))||s.at(i+j)==s.at(i+2*j)){
        continue;
      }
      else{
        tmp++;
      }
    }
  }
  cout <<rgb.at('R')*rgb.at('G')*rgb.at('B')-tmp<<endl;
}

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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n; cin >> n;
    vector<ll> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];

    ll res1 = 0, res2 = 0;

    int par = 0;
    ll sum = 0;
    for (int i = 0; i < n; i++){
        sum += arr[i];
        if (i % 2 == par) {
            if (sum >= 0) {
                res1 += sum + 1;
                sum = -1;
            }
        } else {
            if (sum <= 0){
                res1 += -sum + 1;
                sum = 1;
            }
        }
    }
    par = 1;
    sum = 0;
    for (int i = 0; i < n; i++){
        sum += arr[i];
        if (i % 2 == par) {
            if (sum >= 0) {
                res2 += sum + 1;
                sum = -1;
            }
        } else {
            if (sum <= 0){
                res2 += -sum + 1;
                sum = 1;
            }
        }
    }
    debug(res1);
    debug(res2);
    cout << min(res1, res2) << endl;
}


Measured memory_bytes: 1024
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD 1000000007
#define ALL(a) (a).begin(), (a).end()
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>
#define sec second

inline int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
    return x*f;
}

int main()
{
 	ios::sync_with_stdio(false);
	cin.tie(0);
 	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ll n,k;
	cin>>n>>k;
	ll x=n/k;
	
	cout<<min(n-k*x,k*(x+1)-n)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stdio.h>

using namespace std;

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

	int d = a / b;
	int r = a % b;
	double f = double(a) / b;

	printf("%d %d %.5lf\n", d, r, f);

	return 0;
}



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

void initialize(int K, const auto& f, auto& V, auto& index) {
  int id = 0;
  vector<int> e(K);
  iota(begin(e), end(e), 0);
  do {
    index[e] = id++;
    V.emplace_back([e, &f](auto l, auto r) {
      for(auto i: e) if(f[l][i] != f[r][i]) return f[l][i] > f[r][i];
      return false;
    });
  } while(next_permutation(begin(e), end(e)));
}

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

  vector<vector<int>> f(N, vector<int>(K));
  for(auto& i: f) for(auto& j: i) cin >> j;

  vector<set<int, function<bool(int, int)>>> V;
  map<vector<int>, int> index;
  initialize(K, f, V, index);

  int D;
  cin >> D;
  vector<vector<int>> G(N);
  vector<int> indegree(N);
  for(auto i = 0; i < D; ++i) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    G[a].emplace_back(b);
    ++indegree[b];
  }

  vector<int> e(K);
  for(auto& i: e) cin >> i;
  for(auto& i: e) --i;
  auto order = index[e];

  int R;
  cin >> R;
  vector<pair<int, int>> update;
  for(auto i = 0; i < R; ++i) {
    int m;
    cin >> m;
    vector<int> e(K);
    for(auto& i: e) cin >> i;
    for(auto& i: e) --i;
    update.emplace_back(m, index[e]);
  }

  vector<bool> visited(N);
  for(auto i = 0; i < N; ++i) if(!indegree[i]) for(auto& j: V) j.insert(i);
  for(auto step = 0; step < N; ++step) {
    if(update.front().first <= step) {
      order = update.front().second;
      update.erase(begin(update));
    }
    while(visited[*V[order].begin()]) V[order].erase(*V[order].begin());
    auto v = *V[order].begin();
    visited[v] = true;
    cout << v + 1 << endl;
    for(auto i: G[v]) if(!visited[i]) if(! --indegree[i]) for(auto& j: V) j.insert(i);
  }
}

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

int main(){
    int n,m;
    int A[110][110],b[110];
    cin >> n >> m;    
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin >> A[i][j];
        }
    }
    for(int i=0; i<m; i++){
        cin >> b[i];
    }
    int c;
    for(int i=0; i<n; i++){
        c = 0;
        for(int j=0; j<m; j++){
            c += A[i][j]*b[j];
        }
        cout << c << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
from sys import stdin, setrecursionlimit as srl
from threading import stack_size
srl(int(1e9)+7)
stack_size(int(1e8))

def get(i, value, vis):
    if vis[i]:
        return value[i]
    vis[i] = True
    ans = 0
    for j in adj[i]:
        ans = max(ans, 1+get(j, value, vis))
    value[i] = ans
    return ans


n, m = map(int, input().split())
adj = {}
for i in range(n):
    adj[i] = []
for i in range(m):
    x, y = map(int,input().split())
    adj[x-1].append(y-1)
vis = [False for i in range(n)]
value = [0 for i in range(n)]
for i in range(n):
    value[i] = get(i, value, vis)
x = 0
for i in value:
    x = max(x, i)
print(x)


Measured memory_bytes: 71992
inputted = list(map(int, input().split()))
r = inputted[0]
D = inputted[1]
x2000 = inputted[2]

x_i_1 = (lambda r, D: lambda xi: r * xi - D)(r, D)


for i in range(1, 10 + 1):
    current = x_i_1(x2000) if i == 1 else x_i_1(prev)
    print(current)
    prev = current


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	/** 100 */
	private static final int HUNDRED = 100;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int d = scanner.nextInt(), n = scanner.nextInt();
			int pow = 1;
			for (int i = 0; i < d; i++) {
				pow *= HUNDRED;
			}
			System.out.println(((HUNDRED == n) ? (n + 1) : n) * pow);
		}
	}
}


Measured memory_bytes: 35632
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

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

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{

    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}


Measured memory_bytes: 3652
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>

using namespace std;
int main() {
    int A, B;

    cin >> A >> B;
    if(A < 10 && B < 10) {
        cout << A * B << endl;
    } else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    ArrayList<Integer> dislike = new ArrayList<Integer>();
    for(int i = 0; i < K; i++) {
      dislike.add(sc.nextInt());
    }
    int ans = N;
    for(int i = N; i < 100 * N; i++) {
      int count = 0;
      int temp = i;
      while(temp > 0) {
        int digit = temp % 10;
        temp /= 10;
        if(dislike.contains(digit)) count++;
      }
      if(count == 0) {
        ans = i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
 
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
  mint operator()(int n, int k, int a) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[n-k];
  }
} comb(600010);

int main(){
    ll N,M;
    cin >> N >> M;
    mint ans = comb(M,N,0);
    ll a = -1;
    REP(i,1,N+1){
        ans += mint(a)*comb(N,i)*comb(M-i,N-i,0);
        if(a==1){
            a = -1;
        }else{
            a = 1;
        }
    }
    cout << (ans*comb(M,N,0)) << endl;
}


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

namespace ITP1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            //与えられた数列を逆順に出力する
            //1行目 n 数列の長さ　2行目 ai i番目の数
            //n≤100
            //0≤ai<1000

            int n = int.Parse(Console.ReadLine());          //数列の長さを取得
            string[] str = Console.ReadLine().Split(' ');   //数列を取得
            Array.Reverse(str);                             //要素の順番を反転させる

            int i;

            for (i = 0; i < n-1; i++)                       //n-1番目までの配列が入力されたとき
            {
                Console.Write(str[i]+" ");                  //数値と空白を出力
            }
            for (i = n - 1; i < n; i++)                     //n番目の配列が入力されたとき
            {
                Console.Write(str[i]);                      //数値を出力
            }

            Console.WriteLine();



        }
    }
}



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


int main() {
    int n;
    long long count[31];

    fill(count, count+31, 0);
    count[0] = 1;
    for (int i = 1; i <= 30; i++) {
        count[i] += count[i-1];
        if (i >= 2) {
            count[i] += count[i-2];
        }
        if (i >= 3) {
            count[i] += count[i-3];
        }
    }

    while (cin >> n, n) {
        cout << (count[n] / 3650 + (count[n]%3650 > 0)) << endl;
    }

    return 0;
}

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


using namespace std;


typedef long long ll;

const int MAX_N = 100000 + 21;

vector<int> neib[MAX_N];

void addEdge ( int a , int b ) {
  neib[a].push_back ( b );
}

int CntNePara;
int both;

bool Visited[MAX_N][2];


void DFS ( int v , int par ) {
  if ( Visited[v][par] ) return;
  
  Visited[v][par] = true;
  //cout << "DFS : " << v << " / " << par << endl; 
  
  for ( auto a : neib[v] ) {
    DFS ( a , par ^ 1 );
  }
}


int main() {
  int n,m;
  scanf ( "%i %i" , &n , &m );
  
  for ( int i = 0 ; i < m ; i++ ) {
    int a , b;
    scanf ( "%i %i" , &a , &b);
    addEdge ( a , b);
    addEdge ( b , a );
  }
  
  CntNePara = 0;
  both = 0;
  DFS ( 1,0 );
  
  for ( int i = 1 ; i <= n ; i++ ) {
    if ( Visited[i][1] ) CntNePara++;
    if ( Visited[i][1] and Visited[i][0] ) both++;  
  }
  
  
  ll ans = 0;
  
  
  for ( int i = 1 ; i <= n ; i++ ){
    if ( Visited[i][0] ) {
      
      
      if ( Visited[i][1] )
        ans += ( CntNePara - 1 );
      else
        ans += ( CntNePara );
        
    }
  }
  
  
  ans -= (both * 1LL * ( both - 1 ) )/ 2;
  
  
  
  
  
  printf ( "%lld \n" , ans - m );
  
  
  
}


Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int b,r,g,c,s,t;
	while(1){
		cin>>b>>r>>g>>c>>s>>t;
		if(b==0 && r==0 && g==0 && c==0 && s==0 && t==0) break;
		o(100+15*(b+r)+7*g+2*c+13*(5*b+3*r)-3*(t-5*b-3*r-s));
	}
}

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

const long long INF = 1e18 + 7;

int main() {
  vector<long long> x(2), y(2);
  cin >> x[0] >> x[1] >> y[0] >> y[1];
  if ( x[0] < 0 && 0 < x[1] ) { x.push_back(0); }
  if ( y[0] < 0 && 0 < y[1] ) { y.push_back(0); }
  long long ans = -INF;
  for ( int i = 0; i < x.size(); i++ ) {
    for ( int j = 0; j < y.size(); j++ ) {
      ans = max(ans, x[i]*y[j]);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
char S[300][301];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> S[i];
	int ans = 0;
	for (int B = 0; B < N; B++) {
		bool ok = 1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (S[i][(j + B) % N] != S[j][(i + B) % N]) {
					ok = 0;
					break;
				}
			}
			if (!ok) break;
		}
		if (ok) ans += N;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s,t;
    cin >> s;
    cin >> t;
    for(int i=0; i < s.size() ; i++){
        if(s[i] != t[i]){
            cout << "No" << endl;
            return 0;
            }
        }
    if(s.size() + 1 == t.size()){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
n=int(input())

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
if n==1:
    print(0)
    exit(0)
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a = factorization(n)

# print(a)
n = len(a)

cnt =0
for i in range(n):
    k = a[i][1]

    fr=1
    cnt+=1
    for j in range(2,k+1):
        fr+=j
        if k-fr>=0:
            cnt+=1

print(cnt)


Measured memory_bytes: 9460
//minpro2019_a.cpp
//Sat Feb  9 20:55:54 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	if (k<=(n+1)/2){
		cout << "YES" << endl;
	}else {
		cout << "NO" << endl;
	}
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args )
    {
        Scanner scan = new Scanner(System.in);
    
        int K = scan.nextInt();

        String S = scan.next();

        if(S.length() > K){

            System.out.println(S.substring(0, K)+"...");

        }else{
            System.out.println(S);
        }
    }
}


Measured memory_bytes: 38544
/* date 18/05/19
*   Author: sir_code_a_lot
*/
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007; //10e+7;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     int n;
     cin>>n;
     int last=n%100;
     int first=n/100;
    // cout<<first<<last;
    if(last==0 && first==0){
    	   cout<<"NA"<<"\n";}
    else{
            if(last<=12&&first<=12&&(first!=0&&last!=0)){
    		cout<<"AMBIGUOUS"<<'\n';
    	}
    	else if(last<=12&&first>=0&&last!=0){
    		cout<<"YYMM"<<'\n';
    	}
    	else if(last>=0&&first<=12&first!=0){
    		cout<<"MMYY"<<'\n';
    	}
    	else cout<<"NA"<<'\n';
    }

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define rep(i,k,n) for (ll i = k; i < n; ++i)
#define inputar(a,n) ll a[n];rep(i,0,n)cin>>a[i]
#define PI 3.14159265
const int MOD=1e9+7;


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

#define test4(x,y,z,a) cerr<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cerr<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cerr<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cerr<<"x is "<<x<<endl;

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

int main()
{
    IOS;
    ll n;
    cin>>n;
    ll a[n+1];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==2)
    {
        cout<<max(a[0],a[1])<<endl;
        return 0;
    }
    ll pre[n+1],suf[n+1];
    ll c=a[0];
    for(int i=0;i<n;i++)
    {
        c=gcd(c,a[i]);
        pre[i]=c;
    }
    c=a[n-1];
    for(int i=n-1;i>=0;i--)
    {
        c=gcd(c,a[i]);
        suf[i]=c;

        // cout<<c<<endl;
    }
    ll mx=0;
    for(int i=1;i<n-1;i++)
    {
        ll ans=gcd(pre[i-1],suf[i+1]);
        mx=max(ans,mx);
        // cout<<ans<<endl;
    }
    mx=max(mx,suf[1]);
    mx=max(mx,pre[n-2]);
    cout<<mx<<endl;
}

Measured memory_bytes: 2560
package main

import (
	"fmt"
)

func main() {
	var e, n, i, count int64
	fmt.Scan(&n)
	a := make(map[int64]int64)
	b := make(map[int64]int64)

	for i = 1; i <= n; i++ {
		fmt.Scan(&e)
		a[i+e]++
		b[i-e]++
	}
	for index := range a {
		if int64(index) > 0 && b[index] != 0 {
			count += a[index] * b[index]
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 23816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
#define pb push_back
#define F  first
#define S  second
#define int ll
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define edl "\n"
#define ceils(s,n) (s+n-1)/n
#define str string
#define add insert
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, N = 1e5 + 10;
const ll LINF = LLONG_MAX;
ll a,b,c,n,sum;
string s1,s2,s;

int32_t main() {
    fast();
    ll d1,m1,d2,m2;
    cin >> m1 >> d1 >> m2 >> d2;

    if(m1!=m2)
        cout<<1;
    else
        cout<<0;
    cerr << "\nTime taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

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

int main()
{
	int n, m, distance[100][100]{}, edge[100][100]{};
	std::fill(distance[0], distance[0] + 10000, 1000000000);
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; i++)
	{
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		a--; b--;
		distance[a][b] = distance[b][a]
		= edge[a][b] = edge[b][a] = c;
	}
	for (int i = 0; i < n; i++)
		distance[i][i] = 0;

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				distance[j][k] = std::min(distance[j][k], distance[j][i] + distance[i][k]);
	
	int count{};
	for(int i = 0; i < n; i++)
		for (int j = i + 1; j < n; j++)
			if (distance[i][j] < edge[i][j])
				count++;
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] age)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuffer sb = new StringBuffer();

		String[] input = br.readLine().split(" ");
		double a = Double.parseDouble(input[0]);
		double b = Double.parseDouble(input[1]);
		int C = Integer.parseInt(input[2]);

		double S = 0.5*a*b*(Math.sin(Math.toRadians(C)));
		double h = b*(Math.sin(Math.toRadians(C)));
		double L = a+b+(Math.sqrt(Math.pow(a, 2)+Math.pow(b, 2)-(2*a*b*Math.cos(Math.toRadians(C)))));

		String Sans = String.format("%.6f", S);
		String hans = String.format("%.6f", h);
		String Lans = String.format("%.6f", L);

		sb.append(Sans).append("\n").append(Lans).append("\n").append(hans).append("\n");
		System.out.print(sb);
	}
}

Measured memory_bytes: 24620
#include <bits/stdc++.h>
#define ll long long
#define C(i,j) (fac[i] * inv[j] % Mod * inv[(i)-(j)] % Mod)
using namespace std;
const ll N = 10000010;
const ll Mod = 1e9+7;
inline ll read()
{
  ll p=0; ll f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}

ll n,k; ll fac[N],inv[N];

ll f[2010][2010];
void upd(ll &x,ll y){x=(x+y)%Mod;}

int main()
{

  n = read(); k = read();

  fac[0] = 1; for(ll i=1;i<=n*k+n+k;i++) fac[i] = i;
  inv[0] = inv[1] = 1; for(ll i=2;i<=n*k+n+k;i++) inv[i] = (Mod - Mod / i) * inv[Mod%i] % Mod;
  for(ll i=1;i<=n*k+n+k;i++) fac[i] = fac[i-1] * i % Mod,inv[i] = inv[i-1] * inv[i] % Mod;

  f[0][0] = 1; k--; if(!k){printf("1\n"); return 0;}
  for(ll i=0;i<=n;i++)
  {
    for(ll j=i;j<=n;j++)
    {
      if(i) upd(f[i][j] , f[i-1][j]);
      if(j) upd(f[i][j] , f[i][j-1] * C(j*k+i-1,k-1) % Mod);
    }
  }

  return printf("%lld\n",f[n][n] * fac[n] % Mod),0;
}

Measured memory_bytes: 96512
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<string.h>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;

int N;

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

int ball[10];

//int B = 0, C = 0;

int bfs(int n, int B, int C) {
	
	if (n == 10) {
		return true;
	}

	if (B < ball[n]) {
		B = ball[n];
		return bfs(n + 1, B, C);
	}
	if (C < ball[n]) {
		C = ball[n];
		return bfs(n + 1, B , C);
	}
	
	return false;

}

void input(void) {
	for (int i = 0; i < 10; i++) {
		CI ball[i];
	}
	return;
}


int main(void) {
	CI N;

	for (int i = 0; i < N; i++) {
		input();
		if (bfs(0, 0, 0)) {
			CO "YES" E
		}
		else {
			CO "NO" E
		}
	}
	
	return 0;
}

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

using namespace std;


int main(int argc, char *argv[])
{
    
    
    
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    
    int r, c;
    int matrix[110][110] = {0};
    
    cin >> r >> c;
    
    for (int i =0; i<r; i++) {
        for (int j =0; j<c; j++) {
            cin >> matrix[i][j];
            matrix[r][j] += matrix[i][j];
            matrix[i][c] += matrix[i][j];
            matrix[r][c] += matrix[i][j];
        }
    }
    
    for (int i = 0; i <= r; i++) {
        for (int j = 0; j <= c; j++) {
            if (j == c) {
                cout << matrix[i][j];
                continue;
            }
            cout << matrix[i][j] << " ";
        }
        cout << endl;
    }
    
    return 0;
}



Measured memory_bytes: 3268
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

ll l[200005];
ll pref[200005];
void solve() {
  int n;
  ll x;
  cin >> n >> x;
  ll ret = n * x;
  vector<ll> scale;
  scale.push_back(5);
  scale.push_back(5);
  while(scale.size() <= n) {
    scale.push_back(scale.back() + 2);
  }
  for(int i = 0; i < n; i++) {
    cin >> l[i];
    pref[i+1] = pref[i] + l[i];
  }
  ll inc = 9e18;
  for(int k = 1; k <= n; k++) {
    int curr = n;
    vector<ll> amts;
    while(curr > 0) {
      int next = max(0, curr - k);
      amts.push_back(pref[curr] - pref[next]);
      curr = next;
    }
    ll cand = 0;
    for(int i = 0; i < amts.size(); i++) {
      ll maxCan = (9e18 - cand) / amts[i];
      if(scale[i] >= maxCan) {
        cand = 9e18;
        break;
      }
      cand += amts[i] * scale[i];
    }
    inc = min(inc, (ll)(cand + x * k));
  }
  cout << ret + inc << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


Measured memory_bytes: 8048
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef long double ld;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define ITR(x, c) for(__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
ld dist(ld a, ld b, ld c, ld d) {
    return sqrt((a - c) * (a - c) + (b - d) * (b - d));
}
int main() {
    const ld eps=1e-7;
    cin >> n;
    long double z, r;
    vector<long double> X, Y;
    rep(i, n) {
        cin >> z >> r;
        X.push_back(z);
        Y.push_back(r);
    }


        ld ANS = 999999999999, a, b, c, d, e, f, p, q;
        rep(i, n) {
            rep(j, i) {
                rep(h, j) {
                    t=1;
                    a = X[i];
                    b = Y[i];
                    c = X[j];
                    d = Y[j];
                    e = X[h];
                    f = Y[h];
                    if((a * (d - f) + c * (f - b) + e * (b - d))==0)continue;
                        p = ((a * a + b * b) * (d - f) +
                             (c * c + d * d) * (f - b) +
                             (e * e + f * f) * (b - d)) /
                            (2 * (a * (d - f) + c * (f - b) + e * (b - d)));
                    q = -((a * a + b * b) * (c - e) + (c * c + d * d) * (e - a) +
                         (e * e + f * f) * (a - c)) /
                        (2 * (a * (d - f) + c * (f - b) + e * (b - d)));
                    if(p<0||p>1000||q<0||q>1000)continue;
                    rep(l, n) {
                        if(dist(p, q, X[l], Y[l]) >
                           dist(p, q, X[i], Y[i]) + eps)
                            t = 0;
                    }
                    if(t==1){
                        ANS = min(ANS, dist(p, q, X[i], Y[i]));
                    }
                }
            }
        }

        rep(i,n){
            rep(j,i){
                a = X[i];
                b = Y[i];
                c = X[j];
                d = Y[j];
                p=(a+c)/2;
                q=(b+d)/2;
                t=1;
                rep(l, n) {
                    if(dist(p, q, X[l], Y[l]) > dist(p, q, X[i], Y[i]) + eps)
                        t = 0;
                }
                if(t == 1) {
                    ANS = min(ANS, dist(p, q, X[i], Y[i]));
                }
            }
        }
        cout << setprecision(10) << ANS << endl;
}

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

int cnt;
vector<int> G;

vector<int> insertion_sort(vector<int> A, int n, int g) {
  int v, j;
  for (int i = g; i < n; i++) {
    v = A.at(i);
    j = i - g;
    while (j >= 0 && A.at(j) > v) {
      A.at(j+g) = A.at(j);
      j -= g;
      cnt++;
    }
    A.at(j+g) = v;
  }
  return A;
}

vector<int> shell_sort(vector<int> A, int n) {
  // Gを生成
  int h = 1;
  while (h <= n) {
    G.push_back(h);
    h = 3 * h + 1;
  }
  
  for (int i = G.size() - 1;  i >= 0; i--) {
    A = insertion_sort(A, n, G.at(i));
  }
  return A;
}
  
int main() {
  // Input
  int n;
  cin >> n;
  
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A.at(i);
  }
  
  // Compute
  cnt = 0;
  A = shell_sort(A, n);
  
  // Output
  
  cout << G.size() << endl;
  
  for (int i = G.size() - 1; i >= 0; i--) {
    if (i != G.size() - 1) {
      cout << " ";
    }
    cout << G.at(i);
  }
  cout << endl;
  
  cout << cnt << endl;
  
  for (int i = 0; i < n; i++) {
    cout << A.at(i) << endl;
  }
}


Measured memory_bytes: 14376