akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb(v) push_back(v)
#define all(s) s.begin(),s.end()
int main() {
	//code
	
     ios_base::sync_with_stdio(false); 
     cin.tie(NULL);
      string s1,s2;
      cin>>s1>>s2;
      int n1,n2;
      n1=s1.length();
      n2=s2.length();
      int dp[n1+1][n2+1];
      
        for(int i=0;i<=n1;i++)
        {
        	  for(int j=0;j<=n2;j++)
        	  {
        	  	  if(i==0||j==0)
        	  	  dp[i][j]=0;
        	  	  else if(s1[i-1]==s2[j-1])
        	  	  {
        	  	  	dp[i][j]=1+dp[i-1][j-1];
				 }
				 else
				  dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			  }
		}
		int i=n1,j=n2;
		string s="";
		while(dp[i][j]!=0)
		{
			int a=dp[i-1][j];
			int b=dp[i][j-1];
			int c=dp[i-1][j-1];
			if(dp[i][j]==a)
			i--;
			else if(dp[i][j]==b)
			j--;
			else
			{
				s+=s1[i-1];
				i--;
				j--;
			}
		}
		reverse(all(s));
		cout<<s<<endl;
       
 return 0;

}



Measured memory_bytes: 35456
n=int(input())
b=list(map(int,input().split()))
ans=[]
for i in range(n):
    t=1
    tmp=0
    for j in range(len(b)):
        if b[t-1]==t:
            tmp=t
        t+=1
    if tmp==0:
        print(-1)
        exit()
    else:
        ans.append(b.pop(tmp-1))
        
if b:
    print(-1)
else:
    print(*ans[::-1])

Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define Mod 1000000007

int main() {
    string s;
    cin>>s;
    ll k;
    cin>>k;
    if(s[0]!=s[s.length()-1]){
        ll count=0;
        for (int i = 0; i < s.length()-1; ++i) {
            if(s[i]==s[i+1]){
                count++;
                i++;
            }
        }
        cout<<k*count<<endl;
        return 0;
    }
    else{
        for (int i = 0; i < s.length(); ++i) {
            if(s[i]!=s[0]){
                goto out;
            }
        }
        cout<<s.length()*k/2<<endl;
        return 0;
        out:;
        int count1=0;
        while(s[0]==s[count1])count1++;
        int count2=0;
        while(s[0]==s[s.length()-count2-1])count2++;
        int count=0;
        for (int j = count1; j <s.length()-count2-1 ; ++j) {
            if(s[j]==s[j+1]){
                count++;
                j++;
            }
        }
        //cout<<count<<count1<<count2<<endl;
        cout<<((count1+count2)/2)*(k-1)+count*k+count1/2+count2/2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int main(void){
    // Your code here!
    char S[4];
    
    scanf("%s",S);
    
    if(!strcmp(S,"RRR"))
    {
        printf("3\n");
    }
    else if(!strcmp(S,"SRR") || !strcmp(S,"RRS"))
    {
        printf("2\n");
    }
    else if(!strcmp(S,"SSS"))
    {
        printf("0\n");
    }
    else
    {
        printf("1\n");
    }
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int a, b;
	cin >> a >> b;
	if(a+b >= 10) puts("error");
	else cout << a+b << endl;
 	return 0;
}

Measured memory_bytes: 256
import fractions

def get_num(N, num1, num2):
    lcm = num1 * num2 // fractions.gcd(num1, num2)
    return N - N // num1 - N // num2 + N // lcm


A, B, C, D = map(int, input().split())

print(get_num(B, C, D) - get_num(A - 1, C, D))

Measured memory_bytes: 5304
import math
L = int(input())
N = math.floor(math.log2(L))+1
M = N*2-2

add_path = []
for i in range(1,N)[::-1]:
    if L-2**(i-1) >= 2**(N-1):
        add_path.append([i, L-2**(i-1)])
        L -= 2**(i-1)

print(N, M+len(add_path))
[print(i, i+1, 2**(i-1)*j) for i in range(1,N) for j in range(2)]
[print(i[0], N, i[1]) for i in add_path]

Measured memory_bytes: 3316
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define MOD 1000000007 //10^9+7
#define INF 1000000000 //10^9

int main (int argc, const char * argv[])
{
    for (int i=1;i<10; i++) {
        for (int j=1; j<10; j++) {
            printf("%dx%d=%d\n",i,j,i*j);
        }
    }
    
    
    return 0;
}

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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
//    ll ma=-1e9-1,mi=1e9+1,res,r;
//    res=ma;
//    for(int i=0;i<n;i++){
//        cin >> r;
//        res=max(res,r-mi);
//        if(r<mi)mi=r;
//    }
////    cout << "max:mi " << ma << ":" << mi << endl;
//    cout << res << endl;

    ll r;
    cin >> r;
    ll mi=r,res=-1e9;
    for(int i=1;i<n;i++){
        cin >> r;
        res=max(res,r-mi);
        if(mi>r)mi=r;
    }
    cout << res << endl;
}



Measured memory_bytes: 3192
#include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    cin >> state;
    if (N != 1)
    {
        long sum = 0;
        char moto = state[0];

        int k = 0;
        bool flag = true;
        for (int i = 1; i < N; i++)
        {
            if (state[i] != moto)
            {
                if (flag)
                {
                    k++;
                    flag = false;
                }
                state[i] = moto;
            }
            else
            {
                flag = true;
            }
            if(K <= k && flag) break;
        }

        for (int i = 1; i < N; i++)
        {
            if (state[i] == state[i - 1])
            {
                sum++;
            }
        }
        cout << sum << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>

using namespace std;


int main() {
  int s, N, K;
  cin >> N >> K;
  s=0;
  for(int i=0;i<N;i++)
  {
    int t;
    cin >> t;
    s += min(abs(t), abs(t-K)) * 2;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
//go:generate echo "https://atcoder.jp/contests/abc173/tasks/abc173_b"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) Ints(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *scanner) Strings(l int) []string {
	if l == 0 {
		return []string{}
	}
	sl := make([]string, l, l)
	for i := range sl {
		sl[i] = s.String()
	}
	return sl
}

func solve(S, labels []string) []int {
	c := make([]int, len(labels), len(labels))
	for _, s := range S {
		for i, l := range labels {
			if s == l {
				c[i]++
			}
		}
	}
	return c
}

func run(r io.Reader, w io.Writer) {
	scan := newScanner(r)
	N := scan.Int()
	S := scan.Strings(N)
	labels := []string{"AC", "WA", "TLE", "RE"}
	c := solve(S, labels)
	for i, l := range labels {
		fmt.Fprintf(w, "%s x %d\n", l, c[i])
	}
}

func main() {
	run(os.Stdin, os.Stdout)
}


Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double D, T, S;

  cin >> D >> T >> S;
 
  // ここにプログラムを追記
  
  if(D/S<=T){
  cout << "Yes" << endl;
  }else{
  cout << "No" << endl;

  }
}

Measured memory_bytes: 3680
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int main(void){
	ll a,b,v,w,t;
	std::cin >> a >> v >> b >> w >> t;
	if(a==b){
		std::cout << "YES" << std::endl;
	}else if(v <= w){
		std::cout << "NO" << std::endl;
	}else{
		std::cout << ((abs(a-b)<=abs(v-w)*t)?"YES":"NO") << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s[n];
  int t[n],i,sum=0;
  for( i=0;i<n;i++)
  {
    cin>>s[i];
    cin>>t[i];
  }
  string x;
  cin>>x;
  for( i=0;i<n;i++)
  {
    if(x==s[i])
  break;
  }
  for(int j=i+1;j<n;j++)
  {
    sum=sum+t[j];
  }
  cout<<sum;

}

Measured memory_bytes: 256
program main
  implicit none
  character(100000) :: s
  logical :: appear(26)
  integer :: i, j
  read(*, *) s
  appear(:) = .false.
  do i = 1, len(trim(s))
    j = ichar(s(i:i)) - ichar("a") + 1
    appear(j) = .true.
  end do
  do i = 1, 26
    if (.not. appear(i)) then
      write(*, "(a)") char(i + ichar("a") - 1)
      stop 0
    end if
  end do
  write(*, "(a)") "None"
end program main


Measured memory_bytes: 700
MOD = 10 ** 9 + 7


H, W = map(int, raw_input().split())

fields = []
for _ in xrange(H) : 
    fields.append(list(raw_input().strip()))

dp = [[0 for _ in xrange(W)] for _ in xrange(H)]

for r in xrange(H) : 
    if fields[r][0] == '#' : 
        break

    dp[r][0] = 1

for c in xrange(W) : 
    if fields[0][c] == '#' : 
        break

    dp[0][c] = 1


for r in xrange(1, H) : 
    for c in xrange(1, W) : 
        if fields[r][c] == '#' : 
            continue

        dp[r][c] = dp[r - 1][c] + dp[r][c - 1]


print dp[-1][-1] % MOD



Measured memory_bytes: 165508
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0].split(" ")[0]);
    var K = Number(lines[0].split(" ")[1]);
    var X = lines[1].split(" ").map(i => Number(i));

    var ans = Infinity;

    for (var i = 0; i + K - 1 < N; i++) {
        var left = i; var right = i + K - 1;

        var result_1 = Math.abs(X[left]) + Math.abs(X[right] - X[left]);  // 0 --> Right --> Left
        var result_2 = Math.abs(X[right]) + Math.abs(X[right] - X[left]); // 0 --> Left --> Right

        ans = Math.min(ans, result_1, result_2);
    }
    console.log(ans)
});

Measured memory_bytes: 27596
n = int(input())
list_a = list(map(int, input().split()))
multi_4 = 0
multi_2 = 0
multi_o = 0
for a in list_a:
  if a % 4 == 0:
    multi_4 += 1
  elif a % 2 == 0:
    multi_2 += 1
  else:
    multi_o += 1

if multi_2 > 1:
  if multi_4 >= (n - multi_2) / 2:
    print("Yes")
  else:
    print("No")
else:
  if multi_4 >= (n - 1) / 2:
    print("Yes")
  else:
    print("No")

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 10010, M = 1000010, mod = 1e9 + 7;

int n;
int a[N], f[M];
int primes[M], cnt;
bool st[M];

int qp(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b & 1) res = (LL)res * a % mod;
		a = (LL)a * a % mod;
		b >>= 1;
	}
	return res;
}

void init(int n)
{
	for (int i = 2; i <= n; i ++ )
	{
		if (!st[i]) primes[cnt ++ ] = i;
		for (int j = 0; primes[j] <= n / i ; j ++ )
		{
			st[primes[j] * i] = true;
			if (i % primes[j] == 0) break;
		}
	}
}

int main()
{
	init(M - 1);
	
	cin >> n;
	for (int i = 0; i < n; i ++ )
	{
		cin >> a[i];
		
		int x = a[i];
		for (int i = 2; i <= x / i; i ++ )
			if (x % i == 0)
			{
				int cnt = 0;
				while (x % i == 0)
				{
					cnt ++ ;
					x /= i;
				}
				f[i] = max(f[i], cnt);
			}
		if (x > 1) f[x] = max(f[x], 1);
	}
	
	int s = 1;
	for (int i = 2; i < M; i ++ ) s = (LL)s * qp(i, f[i]) % mod;
	
	int res = 0;
	for (int i = 0; i < n; i ++ ) res = (res + (LL)s * qp(a[i], mod - 2) % mod) % mod;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 5888
#!/usr/bin/env python

from collections import deque, defaultdict
import itertools as ite
import sys
import math
from decimal import *

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

N = input()
memo = [[0 for i in range(10)] for j in range(10)]
for i in range(1, N + 1):
    S1 = i % 10
    S2 = 0
    hoge = i
    while hoge > 0:
        S2 = hoge % 10
        hoge /= 10
    memo[S1][S2] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += memo[i][j] * memo[j][i]
print ans

Measured memory_bytes: 34664
#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 pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,m,a,b;
int h[5010];
vector<int> g[5010];

int main(){
	cin >> n >> m;
	REP(i,0,m){
		cin >> a >> b; a--; b--;
		g[a].push_back(b);
		h[b]++;
	}
	
	queue<int> qu;
	REP(i,0,n) if(!h[i]) qu.push(i);
	
	vector<int> vec;
	bool f=false;
	while(!qu.empty()){
		auto p=qu.front(); qu.pop();
		
		int c=0;
		vec.push_back(p);
		for(auto v:g[p]){
			h[v]--;
			if(!h[v]) qu.push(v),c++;
		}
		
		if(c>1) f=true;
	}
	
	for(auto v:vec) cout << v+1 << endl;
	cout << f << endl;
	return 0;
}



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

using namespace std;
int h, w, k;
bool check_bit_set(int mask ,int i) {
  return (mask & (1 << i)) > 0;
}
bool is_valid(int mask, vector <string> m, int k) {
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (check_bit_set(mask, i) || check_bit_set(mask, j + h)) {
        m[i][j] = '*';
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      ans += m[i][j] == '#';
    }
  }

  return ans == k;
}
void print(vector <string>& m) {
  for (int i = 0; i < h; ++i) cout << m[i] << endl;
}
int main() {
  cin >> h >> w >> k;
  vector <string> m(h);
  for (int i = 0; i < h; ++i) {
    cin >> m[i];
  }

  int mask = (1 << (h + w));
  int ans = 0;
  for (int i = 0; i < mask; ++i) {
   // print(m);
    ans += is_valid(i, m, k);
  }

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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define erep(i, n) for(int i = 0; i <= (n); i++)
#define all(a) (a).begin(),(a).end()
#define SORT(a) sort(all(a))
#define rSORT(a, i) sort(all(a),(i))

using ll = long long;
constexpr ll INF = 10000000000;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1E-11;

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; }

//fixed << setprecision(10)

int main() {
	int h, w; cin >> h >> w;
	vector<string>maze(h);
	rep(i, h)cin >> maze[i];

	int cnt = 0;
	rep(i, h) {
		rep(j, w) {
			if (maze[i][j] == '.') {
				cnt++;
			}
		}
	}


	vector<int>dy = { 1,0,-1,0 };
	vector<int>dx = { 0,-1,0 ,1 };

	vector<vector<int>>dis(h, vector<int>(w, -1));

	queue <pair<int,int>>bfs;

	dis[0][0] = 1;
	bfs.push({ 0,0 });


	while (!bfs.empty()) {
		int y, x;
		tie(y, x) = bfs.front();
		bfs.pop();

		for (int i = 0; i < 4; i++) {
			int next_y = y + dy[i];
			int next_x = x + dx[i];

			if (next_y < 0 || next_y >= h || next_x < 0 || next_x >= w)continue;
			if (dis[next_y][next_x] != -1)continue;
			if (maze[next_y][next_x] == '#')continue;

			dis[next_y][next_x] = dis[y][x] + 1;
			bfs.push({ next_y,next_x });
		}
	}
	if (dis[h - 1][w - 1] == -1) {
		cout << -1 << endl;
	}
	else {
		cout << cnt - dis[h - 1][w - 1] << endl;
	}
}


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

int main()
{
    string S = "";
    cin >> S;

    int num = atoi(S.c_str());
    int first = num / 100;
    int second = num % 100;

    bool yymm = false, mmyy = false;
    // YYMMのチェック
    if (0 <= first && first <= 99 && 1 <= second && second <= 12)
    {
        yymm = true;
    }

    // MMYY
    if (1 <= first && first <= 12 && 0 <= second && second <= 99)
    {
        mmyy = true;
    }

    string result = "";
    if (mmyy)
    {
        if (yymm)
        {
            result = "AMBIGUOUS";
        }
        else
        {
            result = "MMYY";
        }
    }
    else
    {
        if (yymm)
        {
            result = "YYMM";
        }
        else
        {
            result = "NA";
        }
    }
    cout << result << endl;
}

Measured memory_bytes: 256
def main():
    s = input()
    
    k = len(s)
    if k == 1:
        ans = int(s)
    else:
        ans = 9 * (k-1) + int(s[0]) - 1
        
        for i in range(1, k):
            if s[i] != "9":
                break
                
        else:
            ans += 1
    
    print(ans)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
int main() {

int m,n; cin>>n>>m;
  vector<int>a(m);
  
  int b=0;
  rep(i,m){cin>>a.at(i);b=b+a.at(i);}
  
  int ans;
  if(b>n){ans=-1;}
  else{ans=n-b;}
  
  cout<<ans<<endl;
    
  

}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] timeList = new int[n];
      for(int i=0;i<n;i++){
        timeList[i]=sc.nextInt();
      }      
      int m =  sc.nextInt();
      for(int i=0;i<m;i++){
       int[] timeListWK = new int[n];
       System.arraycopy(timeList,0,timeListWK,0,timeList.length);
       int p = sc.nextInt();
       int x = sc.nextInt();
       timeListWK[p-1] = x;
       int count =0;
       for(int j=0;j<timeListWK.length;j++){
         count = count + timeListWK[j];
       }
       System.out.println(count);
      } 
	}
}

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

using namespace std;

int main() {
  int N, M;
  cin >> N >> M;
  vector<string> A(N), B(M);
  for (int i = 0; i < N; ++i) cin >> A[i];
  for (int i = 0; i < M; ++i) cin >> B[i];
  string ans = "No";
  for (int i1 = 0; i1 < N - M + 1; ++i1)
    for (int j1 = 0; j1 < N - M + 1; ++j1) {
      bool f = 1;
      for (int i2 = 0; i2 < M; ++i2)
        if (A[i1 + i2].substr(j1, M) != B[i2]) f = 0;
      if (f) ans = "Yes";
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    long test=1;
// 	cin>>test;	
	while(test--)
	{
	long a,b,c,d,i,n,arr[3];
		cin>>arr[0]>>arr[1]>>arr[2];
		sort(arr,arr+3);
		if(arr[0]==5 && arr[1]==5 && arr[2]==7)
		cout<<"YES";
		else cout<<"NO";
		
 	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll fac[200005];
ll ifac[200005];
int n,m,k;
const ll mod = 1000000007;
ll mexp(ll x, ll y)
{
    if(!y) return 1;
    if(y & 1) return x * mexp(x*x%mod, y>>1) % mod;
    else return mexp(x*x%mod, y>>1);
}
ll binom(ll a, ll b)
{
    if(a < b) return 0;
    ll ret = 1;
    ret = fac[a];
    ret *= ifac[a-b];
    ret %= mod;
    ret *= ifac[b];
    ret %= mod;
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >>k;
    fac[0] = 1;
    for(int i=1;i<=n*m;i++)
        fac[i] = i * fac[i-1] % mod;
    ifac[n*m] = mexp(fac[n*m], mod-2);
    for(int i=n*m-1;i>=0;i--)
        ifac[i] = (i+1) * ifac[i+1] % mod;

    ll ans = binom(n*m-2, k-2);
    ll ans2 = 0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            ll tmp = 0;
            tmp = m * (binom(i, 2) + binom(n-i+1, 2));
            tmp += n * (binom(j, 2) + binom(m-j+1, 2));
            ans2 = (ans2 + tmp) % mod;
        }
    }
    ans2 = ans2 * mexp(2, mod-2) % mod;
    cout << ans * ans2 % mod;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

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

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

int main() {
    int N;
    cin >> N;
    lli ans = 0;
    REP(i, 0, N) {
        int A;
        cin >> A;
        ans += A - 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <complex>
#include <fstream>
#include <cmath>

using namespace std;

int abs2(int m, int n){
    if(m>n){
        return m-n;
    }else{
        return n-m;
    }
}

int main(void){
    int x, a, b;
    cin >> x >> a >> b;
    cout << ((abs2(a,x) > abs2(b,x)) ? "B" : "A") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long int a,b,k;
	scanf("%lld %lld %lld",&a,&b,&k);
	if(a>k){
		a=a-k;
	}
	else{
		k=k-a;
		a=0;
		if(k>b){
			b=0;
		}
		else{
			b=b-k;
		}
	}
	printf("%lld %lld\n",a,b);
	return 0;
}

Measured memory_bytes: 1736
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <iomanip>
#include <deque>
#include <queue>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <sstream>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
ll pow(ll N, ll P){
    if(P==0) return 1;
    if(P%2==0){
        ll t = pow(N, P/2);
        return t*t;
    }
    return N * pow(N, P-1);
}
ll modpow(ll N, ll P,ll k){
    if(P==0) return 1;
    if(P%2==0){
        ll t = modpow(N, P/2,k)%k;
        return t*t%k;
    }
    return N * modpow(N, P-1,k)%k;
}
ll modkai(ll n,ll m,ll k){//n*(n-1)*(n-2)*...(m+1)%k
    if(n == m)return 1;
    return modkai(n-1,m,k)*n%k;
}
ll mod_cnb(ll n,ll m,ll k){//nCm%k,kは十分大きい素数
  int m_=modkai(m,0,k);
  return modkai(n,n-m,k)*modpow(m_,k-2,k)%k;
}
ll gcd(ll n,ll m){
    ll n_ = max(n,m);
    ll m_ = min(n,m);
    if(n_%m_ == 0)return m_;
    return gcd(m_,n_%m_);
}
ll lcm(ll n,ll m){
    return n*m/gcd(n,m);
}

int main(){
    ll x,y,z,k;cin>>x>>y>>z>>k;
    vector<ll>a(x),b(y),c(z),d;
    rep(i,x)cin>>a[i];
    rep(i,y)cin>>b[i];
    rep(i,z)cin>>c[i];
    priority_queue<ll>s,ans;
    rep(i,x){
        rep(j,y){
            s.push(a[i]+b[j]);
        }
    }
    for(int i=0;i<k&&!s.empty();i++){
        d.push_back(s.top());
        s.pop();
    }
    rep(i,z){
        rep(j,d.size()){
            ans.push(c[i]+d[j]);
        }
    }
    rep(i,k){
        cout<<ans.top()<<endl;
        ans.pop();
    }

}

Measured memory_bytes: 43144
def main():
    N = int(input())
    a = [int(i) for i in input().split()]
    area = 0
    
    b = 0
    tmp = 0

    sort_a = sorted(a, reverse=True)
    for num in sort_a:
        if(num == tmp):
            if(b > 0):
                area = num * b
                break
            else:
                b = num
                tmp = 0
        else:
            tmp = num
    
    print(area)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 14252
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
int main() {
    ll A, B; cin >> A >> B;
    ll G = __gcd(A, B);

    set<int> S;
    for(ll i=2; i*i<=G; i++) {
        while(G % i == 0) S.insert(i), G /= i;
    }
    if(G > 1) S.insert(G);

    cout << S.size() + 1 << endl;
    return 0;
}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll x; cin >> x;
    ll a,b;
    rep(i,-500,500){
        rep(j,-500,500){
            if(pow(i,5)-pow(j,5) == x){
                a = i;
                b = j;
            }
        }
    }
    cout << a << " " << b << endl;
}

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

const int MAX_N = 100001;
struct edge {int u,v,cost;};
struct vertex {int x,y,v;};
typedef struct edge edge;
vector<edge> es;
bool comp(const edge& e1,const edge& e2){
  return e1.cost<e2.cost;
}

bool comp1(vertex  p1,vertex p2){
  return p1.x<p2.x;
}

bool comp2(vertex  p1,vertex p2){
  return p1.y<p2.y;
}
int par[MAX_N];
int rank1[MAX_N];
void init (int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    rank1[i]=0;
  }
}

int find (int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x]=find(par[x]);
  }
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y) return;
  if(rank1[x]<rank1[y]){
    par[x] = y;
  }else{
    par[y]=x;
    if(rank1[x] == rank1[y]) rank1[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

int kruskal(int V,int E){
  sort(es.begin(),es.end(),comp);
  init(V);
  int res=0;
  for(int i=0;i<E;i++){
    edge e=es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}
int main (){
  int n;
  cin >> n;
  vector<vertex> xy;
  for(int i=0;i<n;i++){
    int t1,t2;
    cin >> t1 >> t2 ;
    vertex v = {t1,t2,i};
    xy.push_back(v);
  }
  sort(xy.begin(),xy.end(),comp1);

  for(int i=0;i<n;i++){
    int p,next;
    p=i-1;
    next=i+1;
    if(p>=0){
      edge t1;
      t1.u = xy[p].v;
      t1.v = xy[i].v;
      t1.cost = abs(xy[i].x-xy[p].x);
      es.push_back(t1);
    }
    if(next<n){
      edge t;
      t.u = xy[i].v;
      t.v = xy[next].v;
      t.cost = abs(xy[i].x-xy[next].x);
      es.push_back(t);
    }
  }
  sort(xy.begin(),xy.end(),comp2);

  for(int i=0;i<n;i++){
    int p,next;
    p=i-1;
    next=i+1;
    if(p>=0){
      edge t;
      t.u = xy[p].v;
      t.v = xy[i].v;
      t.cost = abs(xy[i].y-xy[p].y);
      es.push_back(t);
    }
    if(next<n){
      edge t;
      t.u = xy[i].v;
      t.v = xy[next].v;
      t.cost = abs(xy[i].y-xy[next].y);
      es.push_back(t);
    }
  }
  //cout<<es.size()<<endl;
  //V = n;
  //E = ((n-2)*2+2)*2;
  cout<<kruskal(n,es.size())<<endl;
  return 0;
}


Measured memory_bytes: 9584
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<int> a(N * N, -1);
    vector<pair<int, int>> events;
    for (int i = 1; i <= N; i++) {
      int x;
      cin >> x;
      --x;
      a[x] = i;
      events.emplace_back(x, i);
    }
    sort(events.begin(), events.end());
    bool ok = true;
    for (int i = 0, k = 0; i < N; i++) {
      int lim = events[i].first, val = events[i].second;
      int rem = val - 1;
      while (rem > 0 && k < lim) {
        if (a[k] == -1) {
          a[k] = val;
          --rem;
        }
        ++k;
      }
      if (rem > 0) {
        ok = false;
        break;
      }
    }
    for (int i = N - 1, k = N * N - 1; i >= 0; i--) {
      int lim = events[i].first, val = events[i].second;
      int rem = N - val;
      while (rem > 0 && k > lim) {
        if (a[k] == -1) {
          a[k] = val;
          --rem;
        }
        --k;
      }
      if (rem > 0) {
        ok = false;
        break;
      }
    }
    if (ok) {
      cout << "Yes" << endl;
      for (int x : a) {
        cout << x << " ";
      }
      cout << endl;
    } else {
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 2176
#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;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) if ((a[i]%2) == 0) {
        if ((a[i]%3) == 0 || (a[i]%5) == 0) continue;
        else {
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    
    return 0;
}

Measured memory_bytes: 256
w, h, n = gets.split().map(&:to_i)
x = Array.new(n)
y = Array.new(n)
a = Array.new(n)
n.times do |i|
  x[i], y[i], a[i] = gets.split().map(&:to_i)
end
s = Array.new(h-1)
h.times do |i|
  s[i] = Array.new(w-1)
  w.times do |j|
    s[i][j] = false
  end
end

n.times do |i|
  case a[i]
  when 1
    j = 0
    k = 0
    while j < h
      k=0
      while k < x[i]
        s[j][k] = true
        k += 1
      end
      j += 1
    end
  when 2
    j = 0
    k = x[i]
    while j < h
      k = x[i]
      while k < w
        s[j][k] = true
        k += 1
      end
      j += 1
    end
  when 3
    j = 0
    k = 0
    while j < y[i]
      k = 0
      while k < w
        s[j][k] = true
        k += 1
      end
      j += 1
    end
  when 4
    j = y[i]
    k = 0
    while j < h
      k = 0
      while k < w
        s[j][k] = true
        k += 1
      end
      j += 1
    end
  end
end

m = 0
h.times do |i|
  w.times do |j|
    if s[i][j] == false
      m += 1
    end
  end
end

puts m


Measured memory_bytes: 1916
r, g, b, n = map(int, input().split())

cnt = 0

for red in range(n // r + 1):

    for green in range((n - r * red) // g + 1):

        blue = n - red * r - green * g

        if blue >= 0 and blue % b == 0:

            cnt += 1

print(cnt)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e14+4;
const int Nmax=2e5+1;
const int Nd=61;

int main(){
  int n ;cin >>n;
  map<int,int> m;
  int a;
  rep(i,n){
    cin>>a;
    m[a]++;
  }
  ll siz=m.size();
  if(siz%2==0){
    cout<<siz-1<<endl;
  }else{
    cout<<siz<<endl;
  }

  return 0;


}


Measured memory_bytes: 8260
import java.util.*;

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

    for (int i = 0; i < N; i++) {
      for (int j = 0; j < 2; j++) {
        weightValues[j][i] = scan.nextInt();
      }
    }
    scan.close();

    System.out.println(knapsack2(weightValues, N, W));
  }

  private static long knapsack2(int[][] weightValues, int N, int W) {
    if (N == 0 || W == 0)
      return 0;

    int maxPossibleSum = 0;
    for (int i = 0; i < N; i++)
      maxPossibleSum += weightValues[1][i];

    long MAX_VAL = Long.MAX_VALUE;
    long[] dp = new long[maxPossibleSum + 1];
    Arrays.fill(dp, MAX_VAL);
    dp[0] = 0;

    for (int i = 0; i < N; i++) {
      int currentValue = weightValues[1][i];
      int currentWeight = weightValues[0][i];
      for (int j = dp.length - currentValue; j >= 0; j--) {
        if (dp[j] == MAX_VAL) continue;
        int combinedValue = currentValue + j;
        long combinedWeight = currentWeight + dp[j];
        if (combinedWeight < dp[combinedValue]) {
          dp[combinedValue] = combinedWeight;
        }
      }
    }
    for (int i = dp.length - 1; i >= 0; i--) {
      if (dp[i] <= W) return i;
    }

    return 0;
  }

}

Measured memory_bytes: 22228
import java.util.*;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	Scanner sc = new Scanner(System.in);
	int[][] map;
	int h = 10;
	int w = 10;
	int[] a = {1, 0, -1, 0, 1, -1, 1, -1, 2, 0, -2, 0};
	int[] b = {0, 1, 0, -1, 1, 1, -1, -1, 0, 2, 0, -2};
	int count;
	int max;
	void run(){
		map = new int[h][w];
		max = 0;
		count = h*w;
		while(sc.hasNext()){
			String[] i = sc.next().split(",");
			int x = Integer.parseInt(i[0]);
			int y = Integer.parseInt(i[1]);
			int s = Integer.parseInt(i[2]);
			drop(x, y, s);
		}
		System.out.println(count+"\n"+max);
	}
	void drop(int x, int y, int s){
		ink(x, y);
		for(int i=0; i<s*4; i++)
			ink(x+a[i], y+b[i]);
		}
	void ink(int x, int y){
		if(x>=0 && y>=0 && x<10 && y<10){
			map[x][y]++;
			if(max < map[x][y]) max = map[x][y];
			if(map[x][y]==1) count--;
		}
	}
}

Measured memory_bytes: 17144
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <array>
#include <utility>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
using ll = long long;
using VI = vector<int>;


int main() {
    int n;
    cin >> n;
    vector<long> a, b;

    for (int i = 0; i < n+1; i++)
    {
        int in;
        cin >> in;
        a.push_back(in);
    }
    for (int i = 0; i < n; i++)
    {
        int in;
        cin >> in;
        b.push_back(in);
    }
    long ans = 0;
    for (int i = 0; i < n; ++i) {
        if (b[i] == 0) continue;
        if (b[i] <= a[i]) {
            ans += b[i];
            continue;
        }
        if (b[i] <= a[i] + a[i + 1]) {
            ans += b[i];
            b[i] -= a[i];
            a[i + 1] -= b[i];
            continue;
        }

        ans += a[i] + a[i + 1];
        a[i] = 0;
        a[i + 1] = 0;
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2548
#include<iostream>
using namespace std;
int main()
{
    int n,a,b,i;
    cin>>n;
    if(n==1){
        cout<<"Hello World"<<endl;
    }else if(n==2){

            cin>>a>>b;
            cout<<a+b<<endl;
        

    }
    return 0;
}


Measured memory_bytes: 256
import Data.Array (listArray, (!))

lucas n = lucas' n where
  memo = listArray (0,n) $ fmap lucas' [0..n]
  lucas' 0 = 2
  lucas' 1 = 1
  lucas' n = memo ! (n-1) + memo ! (n-2)

main :: IO ()
main = getLine >>=
  print .
  lucas .
  (read :: String -> Int)

Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int n;
    cin >> n;
    if(n % 1000 == 0){
        cout << 0 << endl;
    }
    else{
        cout << (n / 1000 + 1) * 1000 - n << endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    vector <long long> vect(n+1,1);
    long long a[n+1][n+1];
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<n;j++)
            cin>>a[i][j];
    }
    long long total=0,i;
    for(i=0;i<n*(n-1)/2;i++)
    {
        stack <long long> st1;
        for(int j=1;j<=n;j++)
        {
            if(vect[j]!=n)
            {
                long long a1=a[j][vect[j]];
                if(a[a1][vect[a1]]==j)
                    st1.push(j);
            }
        }
        if(st1.size()==0)
        {
            cout<<-1;
            return 0;
        }
        total+=st1.size()/2;
        while(!st1.empty())
        {
            vect[st1.top()]++;
            st1.pop();
        }
        if(total==n*(n-1)/2)
        break;
    }
    cout<<i+1;
    return 0;
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

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

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

void Main(){
    int H,W,K; cin >> H >> W >> K;
    char c[H][W]; REP(i,H)REP(j,W) cin >> c[i][j];

    int ans = 0;
    REP(i,1<<H)REP(j,1<<W){
        VI h,w;
        REP(k,H) if((i>>k) & 1) h.push_back(k);
        REP(k,W) if((j>>k) & 1) w.push_back(k);
        char a[H][W]; REP(s,H)REP(t,W) a[s][t] = c[s][t];

        for(int s : h){
            REP(k,W) a[s][k] = '.';
        }
        for(int s : w){
            REP(k,H) a[k][s] = '.';
        }

        int cnt = 0;
        REP(s,H)REP(t,W) if(a[s][t]=='#') cnt++;

        if(cnt == K) ans++;
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>

int main(void)
{
	int sum;
	int book;
	int i;

	while (1){

		scanf("%d", &sum);
		if (!sum){
			break;
		}

		for (i = 0; i < 9; i++){
			scanf("%d", &book);

			sum -= book;
		}

		printf("%d\n", sum);
	}

	return (0);
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int a,b;
long long ans;
int n;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a>>b;
        if(a>=b)
        ans+=a-b+1;
        else ans+=b-a+1;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-10;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

int main() {
	ll n;
	cin >> n;
	vector<ll> x(n), y(n);
	vector<ll> tmp;
	int odd;
	bool ok = true;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		if (i == 0)
			odd = mod(x[i] + y[i], 2);
		else {
			if (odd != mod(x[i] + y[i], 2)) ok = false;
		}
		if (odd == 0) x[i]--;
	}
	if (!ok) {
		dump(-1);
		return 0;
	}
	vector<ll> d;
	for (ll i = 0; i < 31; i++) {
		d.push_back(1ll << i);
	}
	dump(odd == 1 ? 31 : 32);
	if (odd == 0) cout << 1 << " ";
	for (int i = 0; i < d.size(); i++) {
		cout << d[i];
		if (i != d.size() - 1) cout << " ";
	}
	cout << endl;
	for (int i = 0; i < n; i++) {
		if (odd == 0) cout << "R";
		ll U = (x[i] + y[i] + (1ll << 31) - 1) / 2;
		ll V = (x[i] - y[i] + (1ll << 31) - 1) / 2;
		for (int j = 0; j < d.size(); j++) {
			ll t = 1ll << j;
			if ((U & t) == t && (V & t) == t) cout << "R";
			if ((U & t) == t && (V & t) != t) cout << "U";
			if ((U & t) != t && (V & t) == t) cout << "D";
			if ((U & t) != t && (V & t) != t) cout << "L";
		}
		cout << 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++)
#define REPR(i, n) for(int i = n - 1; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n;
    cin >> n;
    vll a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll res = 0;
    REP(i, n - 2){
        vll c = {a[i], a[i + 1], a[i + 2]};
        VSORT(c);
        if(c[1] == a[i + 1]) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>

using namespace std;

int main() {
	int n, m, x;

	cin >> n >> m >> x;

	vector<vector<int>> a(n, vector<int>(m));
	vector<int> c(n);
	for (int i = 0;i < n;i++) {
		cin >> c[i];
		for (int j = 0;j < m;j++) {
			cin >> a[i][j];
		}
	}

	int ans = 12345678;
	int all = 1 << n;

	for (int mask = 0;mask < all;mask++) {
		vector<int> level(m);
		int cost = 0;
		for (int i = 0;i < n;i++) {
			if ((mask >> i) & 1) {
				cost += c[i];
				for (int j = 0;j < m;j++) {
					level[j] += a[i][j];
				}
			}
		}
		bool ok = true;
		for (int j = 0;j < m;j++) {
			if (level[j] < x)ok = false;
		}
		if (ok) ans = min(ans, cost);

	}

	if (ans == 12345678)cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
 
using namespace std;
 
int main() {
	ios_base :: sync_with_stdio(false);
	int n = 0;
	long long k = 0;
	cin >> n >> k;
	vector < int > p(n + 2, 0);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		p[i]--;
	}
	vector < int > used(n + 2, -1);
	used[0] = 0;
	int cp = 0;
	int ct = 0;
	while (k > 0) {
		k--;
		ct++;
		cp = p[cp];
		if (used[cp] != -1) {
			break;
		}
		used[cp] = ct;
	}
    if (k != 0)
	k %= (ct - used[cp]);
	while (k > 0) {
		k--;
		cp = p[cp];
	}
	cout << cp + 1;
	return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
#include <cmath>
using namespace std;


vector<pair<long long, int>> item;

vector<long long> t;

void update(int v, int tl, int tr, int pos, long long val)
{
	if (tl == tr)
	{
		t[v] = val;
		return;
	}

	int tm = (tl + tr) >> 1;
	int lc = (v << 1), rc = (v << 1) + 1;

	if (pos <= tm)
	{
		update(lc, tl, tm, pos, val);
	}
	else
	{
		update(rc, tm + 1, tr, pos, val);
	}

	t[v] = max(t[lc], t[rc]);
}

long long get(int v, int tl, int tr, int l, int r)
{
	if (l > r)
	{
		return 0;
	}

	if (l == tl && r == tr)
	{
		return t[v];
	}

	int tm = (tl + tr) >> 1, lc = (v << 1), rc = (v << 1) + 1;
	return max(get(lc, tl, tm, l, min(tm, r)), get(rc, tm + 1, tr, max(tm + 1, l), r));
}


void solve()
{
	int n;
	cin >> n;

	item.resize(n);

	for (int i = 0; i < n; i++)
	{
		cin >> item[i].second;
	}

	for (int i = 0; i < n; i++)
	{
		cin >> item[i].first;
	}


	int mx = 2 * 1e+5 + 1;


	t.assign(4 * mx, 0);


	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		long long getmax = get(1, 0, mx - 1, 0, item[i].second - 1);
		long long dp = getmax + item[i].first;
		update(1, 0, mx - 1, item[i].second, dp);
		ans = max(ans, dp);
	}

	cout << ans;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

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

Measured memory_bytes: 9600
#include<cstdio>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cmath>

using namespace std;
typedef long long ll;


int main(void)
{
	string s = "CODEFESTIVAL2016";
	char str[20];
	cin >> str;

	int ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (str[i] != s[i])ans++;
	}
	cout << ans << endl;
	return 0;
}

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

def main():
    N, M = map(int,input().split())
    maxval = 10 ** (5 + 3 + 2)
    dp = [maxval] * (2 ** N)

    dp[0] = 0
    opened = set()
    opened.add(0)

    for Ki in range(M):
        a, b = map(int,input().split())
        c = 0
        clist = list(map(int,input().split()))
        for ci in clist:
            c |= 1 << (ci - 1)

        newopen = set()
        for op in opened:
            check = op | c
            chkval = dp[op] + a
            if dp[check] > chkval:
                dp[check] = chkval
                newopen.add(check)
            newopen.add(c)

        opened = opened | newopen
        
    ans = dp[-1]
    if ans == maxval:
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4128
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
#define fi first
#define se second
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,n,j,i,k,x,y,z;
    string s;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y;
    return 0;
    
}
    


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

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

    int count[15][15]={};
    reps(i,n){
	if(i%10==0){
	    continue;
	}
	int a=i%10,b=i;
	while(b>=10){
	    b/=10;
	}
	count[b][a]++;
    }

    int sum=0;
    reps(i,n){
	if(i%10==0){
	    continue;
	}
	int a=i%10,b=i;
	while(b>=10){
	    b/=10;
	}
	sum+=count[a][b];
    }
    cout<<sum<<'\n';

    return 0;
}


Measured memory_bytes: 256