akhauriyash/Code-Regression huggingface dataset:
// Original macro is in https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = || -> String {
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
 
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
 
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
 
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
 
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
 
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
 
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

// for adhoc read (ex. https://atcoder.jp/contests/abc112/tasks/abc112_a)
#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}
fn main() {
    input!{ n: i32, k: i32 }
    if n % k == 0 {
        println!("{}", 0);
    } else {
        println!("{}", 1);
    }
}

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

signed
main(){
	int n,p;
	while(cin >> n >> p && !(n==0 && p==0))
	{
			vector<int> s(n,0);
			int index = 0;
			int bowl = p;

			while(1)
			{
					if(bowl == 0)
					{
							bowl += s[index];
							s[index] = 0;
					}
					else
					{
							s[index]++;
							bowl--;
					}

					if(s[index]==p)
					{
							cout << index << endl;
							break;
					}else{
							index = (index+1) % n;
					}
			}
	}
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;

  S[K - 1] = tolower(S[K - 1]);
  cout << S;
  return 0;
}

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

int m, w;

int bm[15];
int bw[15];

int dp[30][10000];

int pow2(int n){
  return n*n;
}

long long dfs(int i, int bit){
  if(i == m) return 0;
  if(dp[i][bit] != -1) return dp[i][bit];

  long long ret = dfs(i+1,bit);
  for(int j = 0;j < w;j++){
    if((bit & (1 << j)) == 0){
      ret = max(ret, dfs(i+1, bit | (1 << j)) + abs(bm[i]-bw[j]) * pow2(abs(bm[i]-bw[j])-30));
    }
  }

  return dp[i][bit] = ret;
}

int main(){
  while(cin >> m >> w, m != 0){

    for(int i = 0;i < m;i++){
      cin >> bm[i];
    }

    for(int i = 0;i < w;i++){
      cin >> bw[i];
    }

    memset(dp,-1,sizeof(dp));

    cout << dfs(0, 0) << endl;
  }
}





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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  string a, b;
  cin >> a >> b;
  int n = stoi(a + b);
  for (int i = 1; i <= n; i++) {
    if (i * i == n) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < (ll) n; i++)
#define xrep(i,x,n) for(ll i = (ll) x; i < (ll) n; i++)
#define vl vector<long long>
#define vs vector<string>
#define all(A) A.begin(), A.end()

int main() {
    ll n, l; cin >> n >> l;
    vs s(n);
    rep(i,n) cin >> s[i];

    sort(all(s));

    string ans = "";
    rep(i,n){
        ans += s[i];
    }

    cout << ans << endl;
}

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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int n,i;
	char s[N];
	ll arr[26]={0};
	cin>>n;
	cin>>s;
	for(i=0;i<n;i++){
		arr[s[i]-'a']++;
	}	
	ll ans = 1;
	for(i=0;i<26;i++){
		if(arr[i]){
			ans = (ans*(1+arr[i]))%mod;
		}
	}
	cout << (ans-1+mod)%mod << endl;
	
		
	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#define N 100
main(){
  int n,i,j,A[N],b,c=0;
  scanf("%d",&n);  /* 並べる数字の個数 */
  for(i = 0; i < n; i++){
    scanf("%d",&A[i]); 
  }
  for(i = 0; i < n; i++){
    for(j = n-1; i < j; j--){
      if(A[j] < A[j-1]){ 
	b = A[j];
	A[j] = A[j-1];  /* 並び換え部分 */
	A[j-1] = b;
	c++;
      }
    }
  }
  for(i = 0; i < n-1; i++){
    printf("%d ",A[i]);
  }
  printf("%d\n",A[n-1]);
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 600
n, m = map(int, input().split())
a = sorted(list(map(int, input().split())))
w = [tuple(map(int, input().split()))for _ in range(m)]
w.sort(key=lambda x: x[1], reverse=True)
ans = 0
p, i = 0, 0
b, c = w[i][0], w[i][1]
while p < n and i < m:
    cur = a[p]
    if cur < c:
        b -= 1
        ans += c
    else:
        ans += cur
    if b == 0:
        i += 1
        if i == m:
            ans += sum(a[p+1:])
            break
        b, c = w[i][0], w[i][1]
    p += 1
print(ans)

Measured memory_bytes: 22476
// ConsoleApplication4.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) > abs(x - b))cout << "B";
	else cout << "A";
	return 0;
}



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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
  long long int ans=0;
  int K,N;
  int A[200000];
  scanf("%d %d",&K,&N);
  for(int m=0;m<N;m++){
      scanf("%d",&A[m]);
  }
  qsort(A,N,sizeof(int),compare_int);
  int max=0;
  int num;
  for(int m=0;m<N-1;m++){
      int a=A[m+1]-A[m];
      if(max<a){
            num=m;
            max=a;
        }
  }
  if(max<K-A[N-1]+A[0]){
      num=N-1;
      max=K-A[N-1]+A[0];
  }
  printf("%d",K-max);

}

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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    while(n){
        ++ans ;
        n/=k;
    }cout << ans;
    return 0;
}


Measured memory_bytes: 256
# 完全二部グラフで大丈夫なら全部大丈夫(最悪で大丈夫かどうか)
# 簡単のためN=3kとする(3の倍数以外でもほとんど同じなので)
# 0,1,2がk個ずつ

# 1-1,2-2間に辺があるとダメ(これだけを避ければよい)
#   1-2,1-0,2-1,2-0,0-0はOKなので

# 二部グラフで片側の頂点が2k以上(もう一方がk個以下)の場合
#   2k以上の方に1,2を割り当てて、反対側をすべて0にする

# 両方とも(k,2k)の場合
# 両方k以上なのでLを1、Rを2で埋めて残りを0で埋める


def main():
    from collections import deque
    from itertools import chain
    import sys
    input = sys.stdin.readline

    # INPUT
    N = int(input())

    graph = tuple(set() for _ in range(N))
    for _ in range(N - 1):
        a, b = (int(x) - 1 for x in input().split())
        graph[a].add(b)
        graph[b].add(a)

    # BFS
    dq = deque([0])
    parity = [-1] * N
    parity[0] = 0
    size_0 = 0
    while dq:
        v = dq.popleft()
        p = parity[v]
        if p == 0:
            size_0 += 1
        np = 1 ^ p
        for u in graph[v]:
            if ~parity[u]: continue
            parity[u] = np
            dq.append(u)

    # SOLVE
    k = N // 3  # 3の倍数の個数
    g1 = iter(range(1, N + 1, 3))  # rangeのままだとchain(g1,g2,g3)としたときg3が途中から始まらない
    g2 = iter(range(2, N + 1, 3))  # range != iteratorなので消費が共有されないため
    g3 = iter(range(3, N + 1, 3))
    if size_0 <= k:  # parity=0を3の倍数で埋め,残りを余った数で埋める
        g123 = chain(g1, g2, g3)
        ret = (next(g3) if p == 0 else next(g123) for p in parity)

    elif N - size_0 <= k:  # parity=1を3の倍数で埋め,残りを余った数で埋める
        g123 = chain(g1, g2, g3)
        ret = (next(g3) if p == 1 else next(g123) for p in parity)

    else:  # parity=0を(mod3=1)で,parity=1を(mod3=2)で埋め,残りを3の倍数で埋める
        g13 = chain(g1, g3)
        g23 = chain(g2, g3)
        ret = (next(g13) if p == 0 else next(g23) for p in parity)

    print(*ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 81120
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
void io(){ ios_base::sync_with_stdio(false);cin.tie(NULL);  cout.tie(NULL);}
int main()
{
    //io();
    ll tt;
    tt=1;
    cout<<fixed;
    while(tt--)
    {
       double r;
       cin>>r;
       cout<<acos(-1)*2*r;
    }
}


Measured memory_bytes: 3728
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <climits>

//find out the use of the below
#include <list>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <memory.h>
#include <cassert>

using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define mp(a,b) make_pair((a),(b))
#define pii pair<int,int>
#define pll pair<LL,LL>
#define pdd pair<double,double>
#define pb push_back
#define x first
#define y second
#define sqr(x) ((x)*(x))
#define EPS 1e-6
#define MEM(x) memset(x,0,sizeof(x))
#define MEMS(x) memset(x,-1,sizeof(x))
#define pi acos(-1)

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt","w", stdout);
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> ve(n+1);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &ve[i]);
    vector<int> dp(n+1, INT_MAX);
    dp[1] = 0;
    for (int i = 2; i <=n; ++i){
        for (int j = 1; j <=k; ++j){
            if (i-j < 1)
                break;
            dp[i] = min(dp[i], dp[i-j]+abs(ve[i-j]-ve[i]));
        }
    }
    cout << dp[n];
    return 0;
}
/* BEFORE submitting, check for:
 *  1. Integer overflow
 *  2. Float/Double precision errors
 *  3. Array index out of bounds
 *  4. Edge cases.(n=1, n=max, etc.)
 *  5. Time complexity. No TLEs
 */



Measured memory_bytes: 1024
x=[0,0,0,0]
y=['AC x ','WA x ','TLE x ','RE x ']

n=int(input())

for i in range(n):
    a=input()  
    if a=='AC':
        x[0]=x[0]+1
    elif a=='WA':
        x[1]=x[1]+1
    elif a=='TLE':
        x[2]=x[2]+1
    else:
        x[3]=x[3]+1
    
for i in range(4):
    x[i]=str(x[i])
    y[i]=y[i]+x[i]
    print(y[i])


Measured memory_bytes: 9136
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var s = bufio.NewScanner(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
	s.Split(bufio.ScanWords)

	n := 0
	if s.Scan() {
		n, _ = strconv.Atoi(s.Text())
	}

	T := make(map[string]int)
	for i := 0; s.Scan() && i < n; i++ {
		cmd := s.Text()
		if cmd[0] == 'f' {
			s.Scan()
			if _, ok := T[s.Text()]; ok {
				fmt.Fprintln(w, "yes")
			} else {
				fmt.Fprintln(w, "no")
			}
			continue
		}
		s.Scan()
		T[s.Text()] = 0
	}

	w.Flush()
}



Measured memory_bytes: 33212
#include<cstdio>
#include<iostream>
#define tin int
#define itn int
#define tni int
#define nit int
#define nti int
using namespace std;
#define maxn 1004

int i,n,a,b,num=0;

int ws(itn a)
{
	tni sum=0;
	while(a>0)
	{
		sum+=a%10;
		a/=10;
	}
	return sum;	
}

int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(i=1;i<=n;++i)
	{
		if((ws(i)>=a)&&(ws(i)<=b))
		{
			num+=i;
		}
	}
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

void solve1();
int score1();
int change(int, int, int);
vector<int> changeT(vector<int>);

int ti;
int D;
int sumC;
int k = 26;
int score;
vector<int> c(k), t, tz;
vector<vector<int>> s;

int main() {
	srand((unsigned)time(NULL));
	cin >> D;
	s.resize(D);

	rep(i, k) {
		cin >> c[i];
		sumC += c[i];
	}
	rep(i, D) {
		s[i].resize(k);
		rep(j, k) {
			cin >> s[i][j];
		}
	}
	t.resize(D);

	rep(i, D) {
		t[i] = rand() % 26;
	}
	score = score1();

	solve1();

	//cout << score << endl;
	//score = score1();
	//cout << score << endl;


	rep(i, D) {
		cout << t[i] + 1 << endl;
	}

}

void solve1() {

	ti = clock();
	int count = 0;

	while (1) {
		count++;
		double time = (double)(clock() - ti) / CLOCKS_PER_SEC;
		if (time > 1.9) {
			break;
		}

		int no = 5;
		int sz = score;
		tz = t;
		//vector<P> temp;
		rep(i, no) {
			int d = rand() % D;
			int q = rand() % k;
			sz = change(sz, d, q);
			//temp.push_back(mp(d, q));
		}

		if (sz > score) {
			score = sz;
			t = tz;
		}
		
	}

	//cout << count << endl;
}

vector<int> changeT(vector<int> t) {
	int no = 5;
	rep(i, no) {
		int d = rand() % D;
		int q = rand() % k;
		t[d] = q;
	}
	return t;
}

int score1() {
	//最後にコンテストが行われた日
	vector<int> last(k, -1);
	int ans = 0;

	rep(i, D) {
		ans += s[i][t[i]];
		last[t[i]] = i;
		rep(j, k) {
			ans -= c[j] * (i - last[j]);
		}
		//cout << ans << endl;
	}
	return ans;
}

int change(int score, int d, int q) {
	score += s[d][q] - s[d][tz[d]];
	int x = d + 1;
	while (x != D && tz[x] != q) {
		x++;
	}
	int y = d - 1;
	while (y >= 0 && tz[y] != q) {
		y--;
	}
	score += c[q] * (d - y) * (x - d);

	x = d + 1;
	while (x != D && tz[x] != tz[d]) {
		x++;
	}
	y = d - 1;
	while (y >= 0 && tz[y] != tz[d]) {
		y--;
	}
	score -= c[tz[d]] * (d - y) * (x - d);

	tz[d] = q;
	return score;
}

Measured memory_bytes: 3720
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

int main(){
      
  fastio();
  int n,m,i,j,k,ans;
  cin>>n>>m>>k;
  int t=0;
  vi fac;
  fac.pb(1);
  for(i=2;i<=min(n,m);i++)
  {
  	if(n%i==0 && m%i==0)
  		fac.pb(i);
  }

  for(i=fac.size()-1;i>=0;i--)
  {
  	t++;
  	if(t==k)
  	{
  		ans=fac[i];
  		break;
  	}
  }
  cout<<ans;
  return 0;
}

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

int main(int argc, const char * argv[]) {



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

    /////////////////////
    // Write code below /
    /////////////////////
    int x;

    cin>>x;

    if(x<1200){
        cout<<"ABC"<<endl;
    }
    else{
        cout<<"ARC"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python
import sys
if sys.version_info[0]>=3: raw_input=input

def insertionSort(a,g):
	global cnt
	for i in range(g,len(a)):
		v = a[i]
		j = i - g
		while j >= 0 and a[j] > v:
			a[j+g] = a[j]
			j = j - g
			cnt+=1
			a[j+g] = v

def shellSort(a):
	global cnt
	cnt = 0
	g = []
	h = 1
	while h <= len(a):
		g.append(h)
		h = 3*h+1
	g.reverse()
	m = len(g)
	print(m)
	print(' '.join(map(str,g)))
	for i in range(m):
		insertionSort(a,g[i])

a=[int(raw_input()) for i in range(int(raw_input()))]
shellSort(a)
print(cnt)
for e in a: print(e)

Measured memory_bytes: 47252
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a,b;
    cin >> a >>b;
    int m=max(a+b,a-b);
    cout << max(m,a*b);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

const int MAX_N = 700;
const int MAX_M = 700 * 699 / 2;

int N, M;
int A[MAX_M];
int B[MAX_M];
bool e[MAX_N][MAX_N];
bool used[MAX_N];


int black;
int white;
int color[MAX_N];

bool dfs(int v, int c) {
  used[v] = true;
  color[v] = c;
  if(c == 0) white++;
  else black++;
  REP(u, N) {
    if(e[v][u]) {
      if(used[u]) {
        if(color[u] != 1 - c) return false;
      } else {
        if(!dfs(u, 1 - c)) return false;
      }
    }
  }
  return true;
}

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

  REP(i, N) REP(j, N) e[i][j] = true;
  REP(i, N) e[i][i] = false;

  REP(i, M) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    e[A[i]][B[i]] = false;
    e[B[i]][A[i]] = false;
  }

  REP(i, N) used[i] = false;

  vi s, t;
  REP(i, N) {
    if(!used[i]) {
      white = 0;
      black = 0;
      if(!dfs(i, 0)) {
        cout << -1 << endl;
        return 0;
      }
      s.push_back(white);
      t.push_back(black);
    }
  }

  int num = s.size();
  bool dp[num + 1][2 * MAX_N];
  REP(i, num + 1) REP(j, 2 * MAX_N) dp[i][j] = false;
  dp[0][0] = true;
  REP(i, num) {
    REP(j, N) {
      if(dp[i][j]) {
        dp[i + 1][j + s[i]] = true;
        dp[i + 1][j + t[i]] = true;
      }
    }
  }

  int ans = N * (N - 1) / 2;
  REP(j, N + 1) {
    if(dp[num][j]) {
      ans = min(ans, (j * (j - 1) / 2) + ((N - j) * (N - j - 1) / 2));
    }
  }

  cout << ans << endl;


  return 0;
}


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

int T;
int main(){
  cin>>T;
  while(T--){
    int N,D;
    cin>>N>>D;
    int A=D&127;
    int B=D-A;

    if(N%2==0){
      cout<< B*N + 127*(N-1) + (127-A) <<endl;
    }else{
      cout<< B*N + 127*(N-1) + A <<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())

if A == B and B == C:
  if A % 2 == 0:
    print(-1)
    exit(0)
  else:
    print(0)
    exit(0)

cnt = 0
for _ in range(1000):
  if A % 2 == 1 or B % 2 == 1 or C % 2 == 1:
    print(cnt)
    exit(0)
  tA, tB, tC = A, B, C
  A = (tB + tC) // 2
  B = (tA + tC) // 2
  C = (tA + tB) // 2
  cnt += 1


Measured memory_bytes: 69812
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	"sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

type Cake struct {
	x, y, z int
}

type ByTotal []Cake

func (a ByTotal) Len() int           { return len(a) }
func (a ByTotal) Less(i, j int) bool { return total(a[i]) > total(a[j]) }
func (a ByTotal) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

var total func(cake Cake) int

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	C := make([]Cake, N)
	for i := 0; i < N; i++ {
		C[i].x, C[i].y, C[i].z = sc.nextInt(), sc.nextInt(), sc.nextInt()
	}
	ans := 0
	for _, dx := range []int{1, -1} {
		for _, dy := range []int{1, -1} {
			for _, dz := range []int{1, -1} {
				total = func(cake Cake) int {
					return cake.x*dx + cake.y*dy + cake.z*dz
				}
				sort.Sort(ByTotal(C))
				var x, y, z int
				for i := 0; i < M; i++ {
					x += C[i].x
					y += C[i].y
					z += C[i].z
				}
				sum := abs(x) + abs(y) + abs(z)
				if ans < sum {
					ans = sum
				}
			}
		}
	}
	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> v(n);
  rep(i,n) {
    int k;
    cin >> k;
    v[i].resize(k);
    rep(j,k) cin >> v[i][j];
  }
  vector<int> ans(m);
  for (vector<int> u: v) {
    for (int i: u) {
      ans[i-1]++;
    }
  }
  int res = 0;
  rep(i,m) {
    if (ans[i] == n) res++;
  }
  cout << res << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int n,diff;
    int i = 0;
    int a = 0;
    int b = 0;
    int total = 0;
    int w[100];
    int result = 10000;

    if(scanf("%d", &n) < 1){
        exit(1);
    }
    for (int i = 0; i < n; ++i) {
        if(scanf("%d", &w[i]) < 1){
            exit(1);
        }
        total += w[i];
    }
    
    for(i = 0; i < n; i++){
        a += w[i];
        b = total - a;
        diff = abs(a-b);
        
        if(result > diff){
            result = diff;
        }
    }

    printf("%d", result);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














string N;
int dp[1010101][2];
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	reverse(all(N));

	int n = N.length();
	rep(i, 0, n + 1) rep(d, 0, 2) dp[i][d] = inf;
	dp[0][0] = 0;
	rep(i, 0, n) rep(d, 0, 2) if (dp[i][d] != inf) {
		int c = N[i] - '0';

		if (c == 9 and d == 1) chmin(dp[i + 1][1], dp[i][d]);
		else {
			if (d == 1) c++;

			chmin(dp[i + 1][0], dp[i][d] + c);
			chmin(dp[i + 1][1], dp[i][d] + 10 - c);
		}
	}

	int ans = min(dp[n][0], dp[n][1] + 1);
	cout << ans << endl;
}







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

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

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    ll ans = k * pow(k - 1, n - 1);
    cout << ans << endl;
}


Measured memory_bytes: 3892
V,E = map(int,input().split())
edges = []
for _ in range(E):
    s,t,w = map(int,input().split())
    edges.append((w,s,t))
edges.sort()

# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        # sizeの大きいほうがx
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合に属するかの判定
def same(x, y):
    return find(x) == find(y)


# xが属する集合の個数
def size(x):
    return -par[find(x)]

# 初期化
# 根なら-size,子なら親の頂点
par = [-1]*V
ans = 0
for e in edges:
    if same(e[1],e[2]):
        continue
    ans += e[0]
    unite(e[1],e[2])
print(ans)





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

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

using namespace std;
using ll = long long;
int mod = 1000000007;

ll inconvenience(ll n){
    return n*(n-1)/2;
}

struct UnionFind {
    vector<ll> par;
    
    UnionFind(ll n) : par(n, -1) { }
    void init(ll n) { par.assign(n, -1); }
    
    ll root(ll x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }
    
    bool merge(ll x, ll y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    ll size(int x) {
        return -par[root(x)];
    }
};

int main(void){
    ll N, M; cin >> N >> M;
    vector<ll> ans(M, 0);
    ans[M-1] = inconvenience(N);
    UnionFind uf(N);
    pair<ll, ll> bridges[M];
    rep(i, M){
        ll A, B; cin >> A >> B;
        bridges[i].first = A-1;
        bridges[i].second = B-1;
        //bridges[i].first = i;
        //bridges[i].second = (i+1) % M;
        //連結する
        //木iと木jが連結した時、不便さはi.size * j.size減る
        //UF木の大きさを格納しておきたい
    }
    rep(i, M-1){
        if(!uf.issame(bridges[M-1-i].first, bridges[M-1-i].second))
            ans[M-2-i] = ans[M-1-i] - uf.size(bridges[M-1-i].first)*uf.size(bridges[M-1-i].second);
        else ans[M-2-i] = ans[M-1-i];
        uf.merge(bridges[M-1-i].first, bridges[M-1-i].second);
    }

    rep(i, M) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 4480
<?php
fscanf(STDIN,"%d",$a);


if($a >= 400 && $a <= 599){
    echo 8;
}else if($a >= 600 && $a <= 799){
    echo 7;
}else if($a >= 800 && $a <= 999){
    echo 6;
}else if($a >= 1000 && $a <= 1199){
    echo 5;
}else if($a >= 1200 && $a <= 1399){
    echo 4;
}else if($a >= 1400 && $a <= 1599){
    echo 3;
}else if($a >= 1600 && $a <= 1799){
    echo 2;
}else if($a >= 1800 && $a <= 1999){
    echo 1;
}

?>

Measured memory_bytes: 16144
N = int(input())

xList = []
yList = []

for i in range(N):
    x, y = map(int, input().split())
    xList.append(x)
    yList.append(y)

xsum = sum(xList)
ysum = sum(yList)

sum = 0
for i in range(N):
    isum = 0
    for j in range(N):
        length = ((xList[i]-xList[j])**2 + (yList[i]-yList[j])**2)**0.5
        isum += length
    isum /= N
    sum += isum



print(sum)

Measured memory_bytes: 38384
#include<stdio.h>
int main(){
  int n,a,b,tmp,hoge,ans=0,i;
  scanf("%d%d%d",&n,&a,&b);
  for(i=1;i<=n;i++){
    tmp=i;
    hoge=0;
    while(tmp>0){
      hoge+=tmp%10;
      tmp/=10;
    }
    if(a<=hoge && hoge<=b)
      ans+=i;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e18;
const ll mod=1e9+7;

int main(){
    ll n,k;
    cin >> n >> k;
    if(k==1) cout << 0 << endl;
    else cout << n-k << endl;
    return 0;
}


Measured memory_bytes: 3516
#include<bits/stdc++.h>
using namespace std;
pair<int,int> bri[100002];
int parent[100002],data[100002];
int n,m;
int find(int x){
	if(x==parent[x]) return x;
	return parent[x]=find(parent[x]);
}
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++) parent[i]=i;
	for(int i=1;i<=m;i++){
		scanf("%d %d",&bri[i].first,&bri[i].second);
	} 
	for(int i=1;i<=n;i++) data[i]=1;
	stack<long long> s;
	long long tot=(long long)(n)*(n-1)/2;
	s.push(tot);
	for(int k=m;k>=2;k--){
		int i=k;
		if(find(bri[i].first)!=find(bri[i].second)){
//			cout<<find(bri[i].first)<<" "<<find(bri[i].second)<<" "<<data[find(bri[i].second)]<<" "<<data[find(bri[i].first)]<<endl;
			tot-=data[find(bri[i].second)]*data[find(bri[i].first)];
			data[find(bri[i].second)]+=data[find(bri[i].first)];
			parent[find(bri[i].first)]=find(bri[i].second);
		}
		s.push(tot);
	}
	for(int i=1;i<=m;i++) {
		printf("%lld\n",s.top());
		s.pop();
	}
	return 0;
}

Measured memory_bytes: 3484
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll k;
  cin >> k;
  cout << k * k / 4 << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i< (n); ++i)
     
    int main() {
     
        int k, n;
        cin >> k >> n;
        vector<int> a(n);
        rep(i,n) cin >> a[i];
        a.push_back(a[0]+k);
        
        int l = 0;
        rep(i,n) {
            l = max(l, a[i+1]-a[i]);
        }
        int ans = k-l;
        cout << ans << endl;
        return 0;
    }

Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
int a[5], k;
scanf("%d%d%d%d%d%d", a, a + 1, a + 2, a + 3, a + 4, &k);
sort(a, a + 5);
puts(a[4] - a[0] <= k ? "Yay!" : ":(");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;

    while (cin >> n && n) {
        VI a(n);
        REP(i,n) cin >> a[i];
        sort(a.begin(), a.end());
        int ans = 1e9;
        REP(i,n-1) ans = min(ans, a[i+1]-a[i]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3044
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;
using Pl = pair<int,ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N = 100005;
const ll lmod = 1e9+7;

ll a[MAX_N],dp[MAX_N][2];

int main(){
  int K; cin >> K ;
  rep(i,K) scanf("%lld",a+K-1-i);
  bool possible = (a[0]==2LL);
  dp[0][0] = dp[0][1] = 2LL;
  a[K] = 1LL;
  rep(i,K){
    // min
    dp[i+1][0] = dp[i][0];
    // max
    dp[i+1][1] = (dp[i][1] + a[i] - 1LL);
    dp[i+1][0] = ((dp[i+1][0] + a[i+1] - 1LL) / a[i+1]) * a[i+1];
    dp[i+1][1] = (dp[i+1][1] / a[i+1] ) * a[i+1];
    // cout << dp[i+1][0] << ", " << dp[i+1][1] << endl;
    possible &= ((dp[i+1][0] > 0) && (dp[i+1][0] <= dp[i+1][1]));
    if(!possible){
      cout << "-1" << endl;
      return 0;
    }
  }
  cout << dp[K][0] << " " << dp[K][1] << endl;
  return 0;
}

Measured memory_bytes: 2560
import java.util.*;

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

    String S = sc.next();



    int firstA = S.indexOf("A");
    int lastZ  = S.lastIndexOf("Z");
    System.out.println( lastZ - firstA + 1 );


  }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll INF = 1LL << 61;
const int MAX_N = 15;
int N;
ll X[MAX_N], Y[MAX_N], P[MAX_N];

ll ans[MAX_N];
ll dp1[MAX_N+1][MAX_N+1];
ll dp2[MAX_N+1][MAX_N+1];

ll rec(const vector<pair<ll, ll>>& at, ll dp[MAX_N+1][MAX_N+1], int R, int K) {
  if (dp[R][K] != -1) return dp[R][K];
  ll res = INF;
  if (R <= K) { chmin(res, 0LL); }
  else if (K == 0) {
    ll val = 0;
    for (int i = 0; i < R; i++) {
      val += at[i].second * abs(at[i].first);
    }
    chmin(res, val);
  } else if (K >= 1) {
    for (int L = 0; L < R; L++) {
      for (int z = L; z < R; z++) {
        ll val = 0;
        for (int i = L; i < R; i++) {
          val += at[i].second * abs(at[i].first - at[z].first);
        }
        chmin(res, val + rec(at, dp, L, K-1));
      }
    }
    for (int L = 0; L < R; L++) {
      ll val = 0;
      for (int i = L; i < R; i++) {
        val += at[i].second * abs(at[i].first);
      }
      chmin(res, val + rec(at, dp, L, K));
    }
  }
  return dp[R][K] = res;
}

int main2() {

  N = nextLong();
  REP(i, N) {
    X[i] = nextLong();
    Y[i] = nextLong();
    P[i] = nextLong();
  }

  REP(i, N+1) ans[i] = INF;

  REP(s, 1<<N) {
    vector<pair<ll, ll>> x, y;
    REP(i, N)
      if (s >> i & 1) x.push_back({X[i], P[i]});
      else y.push_back({Y[i], P[i]});

    sort(ALL(x));
    sort(ALL(y));
    CLR(dp1, -1);
    CLR(dp2, -1);

    for (int a = 0; a <= N; a++) {
      for (int b = 0; b + a <= N; b++) {
        ll cost1 = rec(x, dp1, x.size(), a);
        ll cost2 = rec(y, dp2, y.size(), b);
        chmin(ans[a+b], cost1 + cost2);
      }
    }

  }
  REP(i, N+1)
    cout << ans[i] << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

const int N = 2005;
const long long mod = 1e9 + 7;

long long mod_pow(long long x, long long n){
	long long ret = 1;
	while (n){
		if (n & 1) ret = ret * x % mod;
		x = x * x % mod;
		n >>= 1;
	}
	return ret;
}

long long p[N * N], inv[N * N];
long long dp[N][N];

long long C(int x, int y){
	if (x < y) return 0;
	return p[x] * inv[y] % mod * inv[x - y] % mod;
}

int main(){
	int n, k;
	scanf("%d %d",&n,&k);
	if (k == 1){
		printf("1\n");
		return 0;
	}
	p[0] = inv[0] = 1;
	for (int i = 1; i <= n * k; i++){
		p[i] = p[i - 1] * i % mod;
		inv[i] = mod_pow(p[i], mod - 2);
	}
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++){
		for (int j = 0; j <= i; j++){
			dp[i][j] += dp[i - 1][j];
			dp[i][j] %= mod;
			if (j){
				dp[i][j] += dp[i][j - 1] * C(n - i + (n - j + 1) * (k - 1) - 1, k - 2) % mod * (n - j + 1) % mod;
				dp[i][j] %= mod;
			}
		}
	}
	printf("%lld\n", dp[n][n]);
	return 0;
} 

Measured memory_bytes: 92928
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

using lint = long long;
using ldouble = long double;

vector<pair<char, int>> input() {
    vector<pair<char, int>> ret;
    while (true) {
        char c;
        cin >> c;
        if (c == '$') break;
        int l;
        cin >> l;
        ret.emplace_back(c, l);
    }
    return ret;
}

void print(vector<pair<char, int>> A) {
    for (auto p : A) {
        cout << p.first << " " << p.second << " ";
    }
    cout << "$" << endl;
}

int main() {
    auto A = input(), B = input(), C = input();

    for (int L = 0; L + B.size() <= A.size(); ++L) {
        bool judge = true;
        for (int i = 0; i < B.size(); ++i) {
            if (A[L + i].first != B[i].first) judge = false;
        }

        if (A[L].second < B[0].second) judge = false;
        for (int i = 1; i < B.size() - 1; ++i) {
            if (A[L + i].second != B[i].second) judge = false;
        }
        if (A[L + B.size() - 1].second < B[B.size() - 1].second) judge = false;

        if (!judge) continue;

        vector<pair<char, int>> ans;

        copy(A.begin(), A.begin() + L, back_inserter(ans));

        if (B.size() > 1 && A[L].second > B[0].second) {
            ans.emplace_back(A[L].first, A[L].second - B[0].second);
        }

        copy(C.begin(), C.end(), back_inserter(ans));

        if (A[L + B.size() - 1].second > B[B.size() - 1].second) {
            ans.emplace_back(A[L + B.size() - 1].first, A[L + B.size() - 1].second - B[B.size() - 1].second);
        }

        copy(A.begin() + L + B.size(), A.end(), back_inserter(ans));

        bool update = true;
        while (update) {
            update = false;

            A.clear();
            for (int i = 0; i < ans.size(); ++i) {
                if (i < ans.size() - 1 && ans[i].first == ans[i + 1].first) {
                    A.emplace_back(ans[i].first, ans[i].second + ans[i + 1].second);
                    update = true;
                    ++i;
                } else {
                    A.push_back(ans[i]);
                }
            }
            ans = A;
        }

        break;
    }

    print(A);
    return 0;
}



Measured memory_bytes: 3184
import numpy as np

n, m = list(map(int, input().split()))

ks = []
ss = []
for i in range(m):
    row = list(map(int, input().split()))
    k = row.pop(0)
    ss.append(row)


ps = list(map(int, input().split()))

ks = np.array(ks, dtype=np.int64)
ps = np.array(ps, dtype=np.int64)

masks = []
for s in ss:
    mask = sum([2 ** (a - 1)for a in s])
    masks.append(mask)


# 電球iにつながっていて、ONになっているスイッチの個数を2で割ったあまり
def calc_switch_state(i, switch_state):
    num_on = 0
    mask = masks[i]
    switch_state = switch_state & mask
    while switch_state > 0:
        num_on += switch_state % 2
        switch_state //= 2

    return num_on % 2

# i 番目の電球がスイッチの状態sで点灯するかどうか
def is_light_on(i, switch_state):
    return calc_switch_state(i, switch_state) == ps[i]

# 探索
total = 0
for state in range(2**n):
    if all([is_light_on(i, state) for i in range(m)]):
        total += 1

print(total)

Measured memory_bytes: 21400
N=input()
ans=0
if len(N)%2==0:
    for i in range(len(N)//2):
        ans+=9*100**i
    print(ans)
else:
    for j in range(len(N)//2):
        ans+=9*100**j
    ans+=int(N)-10**(len(N)-1)+1
    print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	
	public static void Main(string[] args)
	{
		var x = Console.ReadLine().ToLong();
		long t = 100;
		for(int i = 1; i < 999999; i++)
		{
			t = (long)(t * 1.01);
			if(t >= x)
			{
				Console.WriteLine(i);
				return;
			}
			
		}
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}

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

import sys
import os


n, k = map(int, input().split())
#print(k, '??°??§????????????')

W = []
for i in range(n):
    W.append(int(input()))

def check(P):
    # ?????????P?????\?????¨??????????????????????????????????????????????????¢??°
    weight_index = 0
    for i in range(k):
        current_weight = 0
        while current_weight + W[weight_index] <= P:
            #print('i', i, W[weight_index], '?????????')
            current_weight += W[weight_index]
            weight_index += 1
            if weight_index == len(W):
                # ??¨??¨?????£???
                return len(W)
    return weight_index

P_min = 1
P_max = 100000 * 10000
P_mid = None
while True:
    P_mid = (P_min + P_max) // 2
    loaded_num = check(P_mid)

    if loaded_num < n:
        # ????????????????????????
        P_min = P_mid
    else:
        # ??????????????????????????§???P??????????????¢???
        P_max = P_mid

    if P_max - P_min <= 1:
        break

# ??????
if check(P_min) == n:
    print(P_min)
else:
    print(P_max)

Measured memory_bytes: 11472
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

int W,H;

int field[110][110];
int done[110][110];
int dfs(int x,int y,int gx,int gy,int col){
	if(x < 0 || y < 0 || field[y][x] == 0 || field[y][x] != col) return 0;
	if( x == gx && y == gy ){
		return 1;
	}
	if(done[y][x]) return false;
	else done[y][x] = true;
	if( dfs(x+1,y,gx,gy,col) ) return true;
	if( dfs(x-1,y,gx,gy,col) ) return true;
	if( dfs(x,y+1,gx,gy,col) ) return true;
	if( dfs(x,y-1,gx,gy,col) ) return true;
	
	
}
int main(){
	ios_base::sync_with_stdio(false);
	while(cin >> W >> H && W){
		for(int i = 0 ; i < 110 ; i++)
			for(int j = 0 ; j < 110 ; j++) 
				field[i][j] = done[i][j] = 0;
		int sx,sy,gx,gy,n;
		cin >> sx >> sy >> gx >> gy >> n;
		//sx--,sy--;
		//gx--,gy--;
		for(int i = 0 ; i < n ; i++){
			int c,d,x,y;
			cin >> c >> d >> x >> y;
			//x--,y--;
			if( d == 0 ){
				for(int i = 0 ; i < 3 ; i++)
					for(int j = 0 ; j < 4 ; j++)
						field[y+i][x+j] = c;
			}else{
				for(int i = 0 ; i < 4 ; i++)
					for(int j = 0 ; j < 3 ; j++)
						field[y+i][x+j] = c;
			}
		}
		/*for(int i = 0 ; i < H ; i++){
			for(int j = 0 ; j < W ; j++) cout << field[i][j];
			cout << endl;
		}*/
		cout << (dfs(sx,sy,gx,gy,field[sy][sx])?"OK":"NG") << endl;
	}
	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <math.h>
#include <iostream>
#include <stdlib.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
int main(void){
    int N,M;
    cin >> N >> M;
    priority_queue<long> A;
    long tmp;
    REP(i,N){
        cin >> tmp;
        A.push(tmp);
    }
    long largest;
    REP(i,M){
        largest = A.top();
        A.pop();
        A.push((long)largest/2);
    }
    long min_cost=0;
    while(!A.empty()){
        min_cost += A.top();
        A.pop();
    }
    cout << min_cost << endl;
    return 0;
}

Measured memory_bytes: 1400
# Traveling
# https://atcoder.jp/contests/abc086/tasks/arc089_a
#
step = [0]
x = [0]
y = [0]
res = 'Yes'

N = gets.strip.to_i
N.times do
  tmp = gets.strip.split(' ').map(&:to_i)
  step.push tmp[0]
  x.push tmp[1]
  y.push tmp[2]
end

1.upto(N) do |n|
  dis = (x[n] - x[n-1]).abs + (y[n] - y[n-1]).abs
  cnt = (step[n] - step[n-1]).abs
  if dis > cnt || (dis % 2) != (cnt % 2)
    res = 'No'
    break
  end
end

puts res

Measured memory_bytes: 4292
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
  	val N = sc.nextInt()
  	val H = IntArray(N){0}
  	for (i in 0 until N) {
  	    H[i] = sc.nextInt()
    }
    var ans = 0
    val list = mutableListOf(H.toMutableList())
    while (list.size>0) {
        var lis = list.removeAt(0)
        val min = lis.min()!!
        ans += min
        for (i in 0 until lis.size) lis[i] -= min
        while (lis.size > 0) {
            val id = lis.indexOf(0)
            if (id == -1) {
                list.add(lis)
                break
            }
            id is Int
            if (id != 0) {
                list.add(lis.subList(0,id))
            }
            lis = lis.drop(id+1).toMutableList()
        }
    }
    println(ans)
}

Measured memory_bytes: 35804