akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.buffer.readline

N = int(input())
K = int(input())

LN = len(str(N))

def keta1(n):
    s = str(n)
    return (len(s) - 1) * 9 + int(s[0])
#print(keta1(N))


def keta2(n):
    if n < 10:
        return 0
    cnt2 = [0] * 101
    for i in range(2, 101):
        cnt2[i] = 9 * 9 * (i - 1)
    tmp2 = 0
    for i in range(len(str(n))):
        tmp2 += cnt2[i]
    tmp2 += (int(str(n)[0]) - 1) * keta1((10 ** (len(str(n))  - 1)) - 1) + keta1(int(str(n)[1:]))
    return tmp2

def keta3(n):
    cnt3 = [0] * 101
    for i in range(3, 101):
        cnt3[i] = 9 * 9 * 9 * (i - 1) * (i - 2) // 2
    tmp3 = 0
    for i in range(len(str(n))):
        tmp3 += cnt3[i]
    tmp3 += (int(str(N)[0]) - 1) * keta2((10 ** (len(str(n))  - 1)) - 1) + keta2(int(str(n)[1:]))
    
    return tmp3

if K == 1:
    print(keta1(N))
elif K == 2:
    print(keta2(N))
elif K == 3:
    print(keta3(N))

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

int main(){
	string s; cin>>s;
	int ans=0;
	for(int i=1;i<s.size();++i){
		if(s.at(i-1)!=s.at(i))continue;
		if(s.at(i)=='1')s.at(i)='0';
		else s.at(i)='1';
		++ans;
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
 
int main(){
    int N;
    cin >> N;
    vector<pair<int,int>> A(N);
    rep(i,N){
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(),A.end());
    rep(i,N)cout << A[i].second+1 << endl;
}

Measured memory_bytes: 1664
import java.{util => ju}
object Main {
    var a: Array[ Array[Char] ] = new Array[ Array[Char] ](2)
    var n: Int = 0
    var m: Int = 0

    def go(p: (Int, Int)): List[(Int,Int)] = {
        val (x,y) = p
        return List( (x-1,y), (x+1,y), (x,y-1), (x,y+1) )
    }

    def valid(p: (Int, Int)): Boolean = {
        val (x,y) = p
        return x >= 0 && y >= 0 && x < n && y < m && a(x)(y) == '.'
    }

    def solveQueue(q: List[(Int, Int)], done: List[(Int, Int)], d: Int):Int = {
        if(q.isEmpty)   return 0
        var q1 = q.map(go(_))
        var q2 = List[(Int, Int)]()
        for(x <- q1) q2 = q2 ++ x
        var q3 = q2.distinct.filter(valid)
        var newq = q3.filter(!done.contains(_))
        return Math.max(d, solveQueue(newq, done ++ newq, d+1))
    }

    def solve(xs: Int, ys: Int): Int = {
        return solveQueue(List( (xs, ys) ), List( (xs,ys) ), 0)
    }

    def main(args: Array[String]) = {
        import scala.io.StdIn.readLine
        var Array(nn, mm) = readLine.split(" ").map(_.toInt)
        n = nn; m = mm;
        a = new Array[ Array[Char] ](n)
        for(i <- 0 until n) a(i) = readLine.toCharArray

        var ans = 0
        for(i <- 0 until n)
            for(j <- 0 until m)
                if(a(i)(j) == '.')
                    ans = Math.max(ans, solve(i, j))
        printf("%d\n", ans)
    }
}


Measured memory_bytes: 113856
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define eb emplace_back

int in(){int x;cin>>x;return x;}
main(){
    while(1){
        int t=in();
        int p=in();
        int r=in();
        if(!t and !p and !r)exit(0);
        vector<vector<int>> pen(t,vector<int>(p));
        vector<int> T(t),cnt(t);
        rep(i,r){
            int id=in()-1;
            int pid=in()-1;
            int tim=in();
            string val;cin>>val;
            if(val[0]=='C'){
                T[id]+=tim;
                T[id]+=pen[id][pid]*1200;
                cnt[id]++;
            }
            else pen[id][pid]++;
        }
        vector<int> id(t);
        iota(id.begin(),id.end(),0);
        sort(id.begin(),id.end(),[&](int x,int y){
            if(cnt[x]!=cnt[y]) return cnt[x]>cnt[y];
            else if(T[x]!=T[y]) return T[x]<T[y];
            else return x<y;
        });
        rep(i,t){
            cout<<id[i]+1<<" "<<cnt[id[i]]<<" "<<T[id[i]]<<endl;
        }
    }
}


Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <iomanip>


using namespace std;

int main() {
    double l;
    cin >> l;

    double answer = (l / 3.0) * (l / 3.0) * (l / 3.0);

    cout << setprecision(15) << answer << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var H, W, N int

func main() {
	H = readint()
	W = readint()
	N = readint()
	ans := 0
	pc := max(H, W)
	for N > ans*pc {
		ans++
	}
	fmt.Println(ans)
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


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

using namespace std;
typedef pair<int, int> P;

int main()
{
	int n;
	scanf("%d", &n);
	vector<int> v;
	for(int k=3; k<=55555; k++){
		int e=0;
		for(int d=2; d*d<=k; d++){
			if(k%d==0) e=1;
		}
		if(e==0 && k%5==1){
			v.push_back(k);
		}
	}
	for(int i=0; i<n; i++){
		printf("%d ", v[i]);
	}
	printf("\n");
	return 0;
}

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

int main(){
    int n,k;

    cin >> n >> k;

    vector<int> h(n);

    for(int i = 0; i < n; ++i) cin >> h[i];

    sort(h.begin(),h.end());

    int ans = abs(h[0] - h[k - 1]);

    for(int i = 1; i < h.size() - k + 1; ++i){
        if(ans > abs(h[i] - h[i + k - 1])) ans = abs(h[i] - h[i + k - 1]);
    }
        


    cout << ans << endl;
}

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

#define MAX(a,b) (a > b) ? a : b
#define MIN(a,b) (a < b) ? a : b
const int inf = 1000000000; // 10^9

int main(){
   int n,m;scanf("%d%d",&n,&m);
   int a[51],b[51],c[51],d[51];
   long int ans[51];
   for(int i = 0;i < n;i++)scanf("%d%d",&a[i],&b[i]);
   for(int i = 0;i < m;i++)scanf("%d%d",&c[i],&d[i]);
   for(int i = 0;i < n;i++){
      int _shortest = inf;
      for(int j = m-1;j >= 0;j--){
         //printf("i:%d,abs:%d\n",i,(abs(a[i]-c[j])+abs(b[i]-d[j])));
         if(_shortest >= abs(a[i]-c[j])+abs(b[i]-d[j])){
            ans[i]=j+1;
            _shortest=(abs(a[i]-c[j])+abs(b[i]-d[j]));
         }
      }
   }
   for(int i = 0;i < n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 128
<?php
$score = 0;
$out = 0;
$runners = array(false, false, false);
$inning = 0;

$n = trim(fgets(STDIN));
while($inning < $n) {
	$event = trim(fgets(STDIN));
	switch($event) {
		case "HIT":
			hit();
			break;
		case "HOMERUN":
			homerun();
			break;
		case "OUT":
			out();
			break;
	}
}


function hit() {
	global $score, $runners;
	if ($runners[2]) {
		$score++;
		$runners[2] = false;
	}
	if ($runners[1]) {
		$runners[1] = false;
		$runners[2] = true;
	}
	if ($runners[0]) {
		$runners[0] = false;
		$runners[1] = true;
	}
	$runners[0] = true;
}

function homerun() {
	global $score, $runners;
	foreach ($runners as $r) {
		if ($r) {
			$score++;
		}
	}
	$score++;
	$runners = array(false, false, false);
}

function out() {
	global $score, $out, $runners, $inning;
	$out++;
	if ($out == 3) {
		echo $score . "\n";
		$score = 0;
		$runners = array(false, false, false);
		$out = 0;
		$inning++;
	}
}

Measured memory_bytes: 6604
n = int(input())
a,b,c = [sorted(list(map(int,input().split())),reverse=True) for i in range(3)]
comp1 = []
i,j = 0,0
cnt = 0
while i<n:
    while j<n and b[j]>a[i]:
        cnt+=1
        j+=1
    comp1.append(cnt)
    i+=1
comp2 = []
i,j = 0,0
cnt = 0
while i<n:
    while j<n and c[j]>b[i]:
        cnt+=1
        j+=1
    comp2.append(cnt)
    i+=1
x = [0]
for i in range(n):
    x.append(x[i]+comp2[i])
ans = 0
for i in comp1:
    ans += x[i]
print(ans)

Measured memory_bytes: 27380
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2242

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;

vector<tuple<int, int, string>> V;
int N, Q;

int main() {
  while (cin >> N >> Q && N) {
    V.clear();
    for (int i=1; i<=N; i++) {
      string en;
      int eby, wy;
      cin >> en >> eby >> wy;
      int fy = wy - eby + 1;
      V.push_back(make_tuple(fy, -1*wy, en));
    }
    V.push_back(make_tuple(-1, 1, "dummy"));
    sort(V.begin(), V.end());
    for (int i=0; i<Q; i++) {
      int q;
      cin >> q;
      int ind = V.size()-1;
      for (unsigned int i=0; i<V.size(); i++) {
	int temp = get<0>(V[i]);
	if (temp > q) {
	  ind = i-1;
	  break;
	}
      }
      if (-1 * get<1>(V[ind]) >= q) {
	cout << get<2>(V[ind]) << " " << q - get<0>(V[ind]) + 1 << endl;
      } else {
	cout << "Unknown" << endl;
      }
    }
  }
}

Measured memory_bytes: 1296
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

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

    cout << (b - 1 + (a - 1) - 1) / (a - 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> pi;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	int n; cin >> n;
	vector<lli> a(3*n);
	rep(i, 3*n) cin >> a[i];
	sort(a.begin(), a.end());
	lli ans = 0;
	rep(i, n) ans += a[3*n-2-i*2];
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2688
import itertools
from operator import mul
from functools import reduce

def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

def combinations_with_replacement_count(n, r):
    return combinations_count(n + r - 1, r)

n,m,q = list(map(int,input().split()))
a = [list(map(int,input().split())) for i in range(q)]

a_ = []
b_ = []
c_ = []
d_ = []
for i in range(q):
    a_.append(a[i][0])
    b_.append(a[i][1])
    c_.append(a[i][2])
    d_.append(a[i][3])

cnt = combinations_with_replacement_count(m, n)

m_ = []
for i in range(m):
    m_.append(i+1)

res_ = []
res = 0
h_list = list(itertools.combinations_with_replacement(m_,n))
for i in range(cnt):
    A = h_list[i]
    res = 0
    for l in range(q):
        if(A[b_[l]-1] - A[a_[l]-1] == c_[l]):
            res += d_[l]
    res_.append(res)

print(max(res_))


Measured memory_bytes: 25728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (ll i = 0; i < N; i++) {
        cin >> a[i];
        a[i] = a[i] - i;
    }
    sort(ALL(a));
    ll b = a[N/2];
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        ans += abs(a[i] - b);
    }
    printf("%lld\n", ans);

}

Measured memory_bytes: 4848
#include<stdio.h>
int pal(int x){
    char str[10];
    sprintf(str, "%d", x);
    //printf("==> %s \n", str);
    return (str[0] == str[4] && str[1] == str [3]);
}
int main(){
    int a,b, acont=0;
    scanf("%d %d", &a, &b);
    for(int i = a; i <= b; i++){
        if(pal(i))
            acont ++;
    }
    printf("%d\n",acont);
    return 0;
}


Measured memory_bytes: 128
k=int(input())  

a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(a[k-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 2e5 + 10;

vector<int> g[MAX], h[MAX];
vector<int> f1(MAX,-1), f2(MAX,-1);
vector<int> C[MAX];
vector<bool> vis(MAX,0);

int id1 = -1;
int id2 = -1;

void DFS1(int v){

	f1[v] = id1;
	vis[v] = 1;

	for(auto u : g[v]){
		if(vis[u]) continue;
		DFS1(u);
	}

}

void DFS2(int v){

	C[f1[v]].pb(id2);
	f2[v] = id2;
	vis[v] = 1;

	for(auto u : h[v]){
		if(vis[u]) continue;
		DFS2(u);
	}
	
}

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

	int N,K,L;

	cin >> N >> K >> L;

	while(K--){
		int x,y;
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}

	while(L--){
		int x,y;
		cin >> x >> y;
		h[x].pb(y);
		h[y].pb(x);
	}	

	for(int i = 1; i <= N; i++){
		if(!vis[i]){
			id1++;
			DFS1(i);
		}
	}

	vis = vector<bool>(MAX,0);

	for(int i = 1; i <= N; i++){
		if(!vis[i]){
			id2++;
			DFS2(i);
		}
	}

	for(int i = 1; i <= N; i++){
		if(C[i].size())
			sort(C[i].begin(), C[i].end());
	}

	for(int i = 1; i <= N; i++){
		int at = f1[i];
		int val = f2[i];
		cout << upper_bound(C[at].begin(), C[at].end(), val) - lower_bound(C[at].begin(), C[at].end(), val) << " \n"[i==N];
	}

	return 0;
}


Measured memory_bytes: 28692
//
// Created by nuwaisir on ৬/১১/১৯.
//

#include<bits/stdc++.h>

using namespace std;
#define ll long long

#define MOD 1000000007

long long bigmod ( long long a, long long p, long long m )
{
    long long res = 1;
    long long x = a;

    while ( p )
    {
        if ( p & 1 ) //p is odd
        {
            res = ( res * x ) % m;
        }
        x = ( x * x ) % m;
        p = p >> 1;
    }

    return res;
}
int main(){
    ios_base :: sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    ll n, i, j, cost, l, x, y;
    string s;
    cin >> n >> s;
    vector<char> ch;
    char c = 'A';
    for(i=0;i<26;i++){
        ch.push_back(c);
        c++;
    }

    for(i=0;s[i];i++){
        cout << (ch[(s[i] - 65 + n) % 26]);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

set<ll>q;
void dep(ll now,ll cnt){
	if(cnt==12){
		return ;
	}
	q.insert(now);
	dep(now*10+now%10,cnt+1);
	if(now%10!=0){
		dep(now*10+now%10-1,cnt+1);
	}
	if(now%10!=9){
		dep(now*10+now%10+1,cnt+1);
	}
}
int main() {
	ll n;
	cin>>n;
	for(ll i=1;i<=9;i++){
		dep(i,0);
	}
	auto itr=q.begin();
	for(ll i=0;i<n-1;i++){
		itr++;
	}
	cout << *itr;
	return 0;
}

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

int main(){
    long long n,d;
    cin>>n>>d;
    long long x,y,cnt=0;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        double ans=sqrt(((double)(x*x)+(double)(y*y)));
        if(ans<=d) cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

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

H,W = map(int, input().split())
dp = [[] for _ in range(H)]
for i in range(H):
	data = input()
	for j in range(W):
		if data[j] == "." : dp[i].append(1)
		else : dp[i].append(0)
for i in range(H):
	for j in range(W):
		if(dp[i][j]!=0):
			if(i > 0 and j > 0) : dp[i][j] = dp[i-1][j]+dp[i][j-1]
			elif(i > 0) : dp[i][j] = dp[i-1][j]
			elif(j > 0) : dp[i][j] = dp[i][j-1]
print(dp[H-1][W-1]%(10**9+7))

Measured memory_bytes: 209148
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

int main(void){
  int N; cin >> N;
  vector<int> a(N);
  for (auto& ai : a)
    cin >> ai;
  int res = 0;
  for (int i = 0; i < N; ++i)
    if (i % 2 == 0 && a[i] % 2)
      ++res;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	string str;
	cin >> str;
	
	REP(i,str.size())
	{
		if(str[i] == ',')
		{
			cout << ' ' ;
		}
		else
		{
			cout << str[i];
		}
	}
	cout << endl;
	
	return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  N=2*M+1;
  if(M%2==0){
    for(int i=1; i<=M/2; i++){
      cout << i << " " << M+1-i << endl;
    }
    for(int i=1; i<=M/2; i++){
      cout << M+i << " " << N+1-i << endl;
    }
  }
  else{
    for(int i=1; i<=(M-1)/2; i++){
      cout << i << " " << M+1-i << endl;
    }
    for(int i=1; i<=(M+1)/2; i++){
      cout << M+i << " " << N+1-i << endl;
    }
  }
}

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

int main() {
  int k;
  int s[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin>>k;
  cout<<s[k-1]<<endl;
}


Measured memory_bytes: 256
n = int(input())
data = [[]for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        data[i].append(list(map(int, input().split())))
max_honest = 0
def bfs(honest):
    if len(honest) == n:
        global max_honest
        for i in range(len(data)):
            if honest[i] == 1:
                for j in data[i]:
                    target, istrue = j
                    if (honest[target-1] == 1 and istrue == 0) or (honest[target-1] == 0 and istrue == 1):
                        return
            else:
                continue
        max_honest = max(max_honest, honest.count(1))
    else:
        bfs(honest + [0])
        bfs(honest + [1])
bfs([])
print(max_honest)





Measured memory_bytes: 3064
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

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

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

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

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

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
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; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  ll g = gcd(a, b);
  return a/g*b;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int W, H, N; cin >> W >> H >> N;
    VI X(N), Y(N), A(N);
    REP(i,N)
    {
        cin >> X[i] >> Y[i] >> A[i];
    }
    
    VI X_r(1,INF), X_l(1,-1), Y_d(1,-1), Y_u(1,INF);
    REP(i, N)
    {
        if (A[i]==2) X_r.push_back(X[i]);
        else if (A[i]==1) X_l.push_back(X[i]);
        else if (A[i]==4) Y_u.push_back(Y[i]);
        else if (A[i]==3) Y_d.push_back(Y[i]); 
    }
    SORT(X_r);SORT(X_l);SORT(Y_d);SORT(Y_u);

    int x_r = min(X_r.front(),W);
    int x_l = max(X_l.back(), 0);
    int y_u = min(Y_u.front(), H);
    int y_d = max(Y_d.back(), 0);
    
    cout << max(0, x_r - x_l) * max(0, y_u - y_d) << endl;
    return 0;
}



Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort()
if N%2==1:
    collect=list(range(0,N))[::2]*2
    collect.remove(0)
elif N % 2 == 0:
    collect = list(range(1, N))[::2] * 2

collect.sort()
if collect!=A:
    print(0)
else:
    print(2**(N//2)%(10**9+7))


Measured memory_bytes: 13880
import java.util.*;

class Main{
	public static void main(String[] args){
		
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		int c,d = 0;
		int[] array = new int[a];
		
		for(int i=0;i<a;i++){
			array[i] = sc.nextInt();
		}
		output(array);
		
		for(int b=1;b<array.length;b++){
			c = array[b];
			d = b-1;
			while(d>=0 && array[d] > c){
				array[d+1] = array[d];
				d--;
			}
			array[d+1] = c;
			output(array);
		}
	}
		
		static void output(int[] a){
			for (int i=0; i<a.length; i++) {
				System.out.print(a[i]);
				if(i<a.length-1){
					System.out.print(" ");
				}else{
					System.out.println();
				}
			}
		}
}


Measured memory_bytes: 34052
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
ans = n * (n + 1) // 2
for i in range(1, n):
    for j in range(i + 1, n + 1):
        ans += gcd(i, j) * 6

for i in range(1, n - 1):
    for j in range(i + 1, n):
        for k in range(j + 1, n + 1):
            x = gcd(i, j)
            ans += gcd(x, k) * 6


print(ans)


Measured memory_bytes: 9204
# 累積和(max)
N = int(input())
a = [int(input()) for _ in range(N)]
lam = a[:]
ram = a[:]
for i in range(1, N):
  lam[i] = max(lam[i], lam[i - 1])
for i in range(N - 2, -1, -1):
  ram[i] = max(ram[i], ram[i + 1])
print(ram[1])
for i in range(1, N - 1):
  print(max(lam[i - 1], ram[i + 1]))
print(lam[N - 2])


Measured memory_bytes: 15652
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

lint mod;
vector<int> G[100010];
vector<lint> dp[100010];

lint dfs1(int v, int prev){
    lint ret = 1;
    rep(i, G[v].size()){
        int nv = G[v][i];
        if(nv == prev) continue;
        dp[v][i] = dfs1(nv, v);
        (ret *= dp[v][i] + 1) %= mod;
    }
    return ret;
}

void dfs2(int v, int prev, lint num){
    int sz = G[v].size();
    rep(i, sz)if(G[v][i] == prev) dp[v][i] = num;
    vector<lint> L(sz+1), R(sz+1);
    L[0] = R[sz] = 1;
    rep(i, sz){
        L[i+1] = L[i] * (dp[v][i] + 1) % mod;
        R[sz-1-i] = R[sz-i] * (dp[v][sz-i-1] + 1) % mod;
    }
    rep(i, sz)if(G[v][i] != prev) dfs2(G[v][i], v, L[i]*R[i+1] % mod);
}

int main(){
    int n;
    scanf("%d%lld", &n, &mod);
    rep(i, n-1){
        int a, b;
        scanf("%d%d", &a, &b);
        G[--a].push_back(--b);
        G[b].push_back(a);
    }
    rep(i, n) dp[i].resize(G[i].size());
    dfs1(0, -1);
    dfs2(0, -1, 0);
    rep(i, n){
        lint ans = 1;
        for(lint t: dp[i]) (ans *= t+1) %= mod;
        printf("%lld\n", ans);
    }
}

Measured memory_bytes: 22528
#include <bits/stdc++.h>
#define VI vector<int>
#define VVI vector<vector<int>>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  if(n<b){
    int A = floor((double)a * n / b);
    cout << A << endl;
  }else{
    int A = floor((double)a * (b - 1) / b);
    int B = floor((double)(b - 1) / b);
    cout << A - B << endl;
  }

    return 0;
}


Measured memory_bytes: 3748
def count(n, s, i, arr)
  if arr.size == n
    return s == arr.inject(:+) ? 1 : 0
  end

  ans = 0
  i.upto(9) do |j|
    arr.push(j)
    ans += count(n, s, j+1, arr)
    arr.pop
  end
  return ans
end

while gets
  n,s = $_.split(' ').map(&:to_i)
  break if n == 0 && s == 0
  puts count(n, s, 0, [])
end

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

int main(){
    int N;  cin >> N;
    string S;  cin >> S;
    int cnt = 0;
    for(int i=0; i<N-2; i++){
        if(S.substr(i, 3) == "ABC"){
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

int main(void)
{
	char a[100];
	int len;
	int i;
	int ans;
	
	scanf("%s",a);
	len = strlen(a);
	
	for(i=0;i<len/2;i++)
		if(a[i]!=a[len-1-i])
			ans++;
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

    class Program
    {
        static void Main()
        {
            int count = int.Parse(Console.ReadLine());
            List<string> input = new List<string> { };
            
            for(int i = 0; i < count; i++)
            {
                input.Add(Console.ReadLine());
            }

            Console.WriteLine(input.Distinct().Count());
        }
    }

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

const string YES = "YES";
const string NO = "NO";

void solve(std::string S)
{
    array<string, 4> words = { "dream", "dreamer", "erase", "eraser" };
    auto pos = S.size();
    while (pos != 0) {
        bool found = false;
        for (auto&& word : words) {
            auto find_pos = S.rfind(word, pos - 1);
            if (find_pos != string::npos && find_pos == pos - word.size()) {
                found = true;
                pos = find_pos;
                break;
            }
        }
        if (!found) {
            cout << NO << endl;
            return;
        }
    }

    cout << YES << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
// clang-format off
int main(){
    std::string S;
    std::cin >> S;
    cin.tie(nullptr);
    cout.tie(nullptr);
	ios_base::sync_with_stdio(false);
    solve(S);
    return 0;
}


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

int N, W;
int v[100], w[100];
int DP[10001];

int main(void) {
  cin >> N >> W;
  for (int i=0; i<N; i++) {
    cin >> v[i] >> w[i];
  }

  for (int i=0; i<N; i++) {
    for (int j=w[i]; j<=W; j++) {
      DP[j] = max(DP[j], DP[j-w[i]]+v[i]);
    }
  }

  cout << DP[W] << endl;

  return 0;
}

Measured memory_bytes: 1204
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=16000+100;
    string s;
    int x,y;
    //滚动数组
    int xreach[2][MAXN];
    int yreach[2][MAXN];
    vector<int>step;
    void calReach(){
        int xf=0;
        xreach[xf][8000]=true;
        // xreach[xf][8000+step[0]]=true;
        for(int u=0;u<step.size();u+=2){
            memset(xreach[xf^1],0,sizeof(xreach[xf^1]));
            for(int p=0;p<MAXN;p++){
                if(xreach[xf][p]){
                    xreach[xf^1][p+step[u]]=true;
                    if(u>0)xreach[xf^1][p-step[u]]=true;
                }
            }
            xf=xf^1;
        }
        int yf=0;
        yreach[yf][8000]=true;
        for(int u=1;u<step.size();u+=2){
            memset(yreach[yf^1],0,sizeof(yreach[yf^1]));
            for(int p=0;p<MAXN;p++){
                if(yreach[yf][p]){
                    yreach[yf^1][p+step[u]]=true;
                    yreach[yf^1][p-step[u]]=true;
                }
            }
            yf=yf^1;
        }
        if(xreach[xf][8000+x]&&yreach[yf][8000+y])cout<<"Yes";
        else cout<<"No";
    }
    void solve(){
        cin>>s>>x>>y;
        int n=s.size();
        int head=0;
        while(head<n){
            int cnt=0;
            while(head<n&&s[head]=='F'){
                cnt++;
                head++;
            }
            head++;
            step.push_back(cnt);
        }
        calReach();
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 512
n,t=map(int,input().split())
dp=[[0]*(t+3001)for _ in range(n+1)]
ans=0
ab=[list(map(int,input().split()))for _ in range(n)]
ab.sort()
for i in range(1,n+1):
    a,b=ab[i-1]
    for j in range(t):
        dp[i][j]=max(dp[i-1][j],dp[i][j])
        dp[i][j+a]=dp[i-1][j]+b
        ans=max(dp[i][j],dp[i][j+a],ans)
print(ans)   

Measured memory_bytes: 217248
def gcd(x, y):
    while y > 0:
        r = x%y
        x = y
        y = r
    return x

def lcm(x, y):
    return x//gcd(x, y)*y

def modpow(x, n, mod):
    res = 1
    while n > 0:
        if n%2 == 1:
            res = res*x%mod
        x = x*x%mod
        n >>= 1
    return res

mod = 10**9+7

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

g = 0
for x in a:
    g = gcd(g, x)

l = 1
for i in range(n):
    a[i] //= g
    l = lcm(l, a[i])
l %= mod

ans = 0
for i in range(n):
    ans += l*modpow(a[i], mod-2, mod)
    ans %= mod

print(ans)

Measured memory_bytes: 43740
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        Integer n = scanner.nextInt();
        List<Integer> list = new ArrayList<Integer>();
        List<Integer> sorted = new ArrayList<Integer>();
        for (int index = 0 ; index < n ; index++) {
          Integer integer = scanner.nextInt();
          list.add(integer);
          sorted.add(integer);
        }
        Collections.sort(sorted);
        
        int errorcount = 0;
        for(int k = 0; k < n;k++) {
          if(!list.get(k).equals(sorted.get(k))) {
            errorcount++;
          }
        }
        
        if(errorcount == 0 || errorcount == 2) {
          System.out.println("YES");
        } else {
          System.out.println("NO");
        }
          
    }
}

Measured memory_bytes: 21844
def main(q: int, h: int, s: int, d: int, n: int):
    print((n // 2) * min(q * 8, h * 4, s * 2, d) + (n % 2) * min(q * 4, h * 2, s))


if __name__ == "__main__":
    q, h, s, d = map(int, input().split())
    n = int(input())

    main(q, h, s, d, n)


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

using namespace std;

int main(){
    int cost[1010];
    int vote[1010];
    int n, m;
    fill(cost, cost+1010, 0);
    fill(vote, vote+1010, 0);

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

    int maxVote = 0;
    for(int i=0; i < m; i++){
        int standard;
        cin >> standard;
        for(int j=0; j < n; j++){
            if(cost[j] <= standard){
                vote[j]++;
                maxVote = max(maxVote, vote[j]);
                break;
            }
        }
    }
    for(int i=0; i < n; i++){
        if(maxVote == vote[i]){
            cout << i+1 << endl;
            break;
        }
    }

}

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

int main() {
  string s,t;
  cin>>s>>t;
  bool ex=true;
  int ch=-1;
  queue<int>q;
  rep(i,s.size()-t.size()+1){
    rep2(j,i,t.size()+i){
      ex=true;
      if(s.at(j)!=t.at(j-i)&&s.at(j)!='?'){
        ex=false;
        break;
      }
    }
    if(ex){
      q.push(i);
    }
  }
  if(q.empty()){
    cout<<"UNRESTORABLE"<<endl;
  }
  else{ 
    
    ch=q.front();
    q.pop();
    string f=s;
    rep2(i,ch,ch+t.size()){
      f.at(i)=t.at(i-ch);
    }
    rep(i,s.size()){
      if(f.at(i)=='?'){
        f.at(i)='a';
      }
    }    
    while(!q.empty()){
      ch=q.front();
      q.pop();
      string g=s;
      rep2(i,ch,ch+t.size()){
        g.at(i)=t.at(i-ch);
      }
      rep(i,s.size()){
        if(g.at(i)=='?'){
          g.at(i)='a';
        }
      }   
      if(f>g){
        f=g;
      }
    }
    cout<<f<<endl;
  } 
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

void calc(string prefix, int left, int used) {
  if(left == 0) {
    cout << prefix << endl;
    return;
  }
  for(int i = 0; i < used; ++i) {
    char c = 'a' + i;
    calc(prefix + c, left - 1, used);
  }
  char cn = 'a' + used;
  calc(prefix + cn, left - 1, used + 1);
}

int main(){
  int N;
  cin >> N;
  calc("", N, 0);
}

Measured memory_bytes: 1536
N, A = map(int, input().split())
x = [int(_) for _ in input().split()]
M = 2500
dp = [[[0]*(N+1) for _ in range(M+1)] for _ in range(N+1)]
dp[0][0][0] = 1

for i in range(1, N+1):
    for j in range(M+1):
        for k in range(i+1):
            dp[i][j][k] = dp[i-1][j][k]
            if j >= x[i-1] and k > 0:
                dp[i][j][k] += dp[i-1][j-x[i-1]][k-1]

ans = 0
for i in range(1, N+1):
    ans += dp[N][A*i][i]

print(ans)

Measured memory_bytes: 103900
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

int dp[3003][3003];

int main(){
  string s,t;
  cin>>s>>t;
  int n = s.size();
  int m = t.size();

  fill(dp[0], dp[n+1], 0);
  rep(i,n){
    rep(j,m){
      dp[i+1][j+1] = max({dp[i][j] + (s[i]==t[j]), dp[i+1][j], dp[i][j+1]});
    }
  }

  string ans;
  int ci = n, cj = m;
  while(dp[ci][cj] > 0){
    if(dp[ci-1][cj-1]+1 == dp[ci][cj] && s[ci-1] == t[cj-1]){
      ci--;cj--;
      ans.pb(s[ci]);
    } else {
      if(dp[ci-1][cj] > dp[ci][cj-1]) ci--;
      else cj--;
    }
  }

  reverse(all(ans));

  cout << ans << endl;


  return 0;
}


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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<ll> a(N);
	for(int i=0;i<N;i++)cin >> a[i];
	ll ans = 0;
	for(int i=0;i<N;i++){
		while(i+1<N && a[i]==a[i+1])i++;
		if(i+1<N&&a[i]<a[i+1]){
			while(i+1<N&&a[i]<=a[i+1])i++;
		}else if(i+1<N&&a[i]>a[i+1]){
			while(i+1<N&&a[i]>=a[i+1])i++;
		}
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
int main (void)
{
   int n,i,j,a[101];
   
   scanf("%d\n",&n);
   for(i=0;i<n;i++)
      scanf("%d",&a[i]);
   for(j=0;j<n;j++){
      if(a[j] % 2 == 0 && a[j] % 3 != 0 && a[j] %5 !=0){
         printf("DENIED\n");
         return 0;
         }
   } 
   printf("APPROVED\n");
   return 0;	   
}
	


Measured memory_bytes: 128
#include<bits//stdc++.h>
using namespace std;
int main(){
  int a[3];cin >> a[0] >> a[1] >> a[2];
  sort(a,a+3);
  if(a[0] == 5 && a[1] == 5 && a[2] == 7) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
from math import factorial
pos = map(int, input().split())
p = 10**9 + 7
x, y = sorted(pos)

if (x+y) % 3 != 0:
    print(0)
    exit()

n = (-x + 2 * y) // 3
m = (-y + 2 * x) // 3

# Python3 function to
# calculate nCr % p


def ncr(n, r, p):
    # initialize numerator
    # and denominator
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
                      p - 2, p)) % p


ans = ncr(n+m, n, p)
print(ans)


Measured memory_bytes: 3064
from string import ascii_lowercase
s = input()
k = int(input())

def main(s, k):
    alp = ascii_lowercase
    num = {char: i for i, char in enumerate(alp)}

    ns = [num[char] for char in s]

    for i in range(len(ns)):
        v = ns[i]
        if v != 0 and 26 - v <= k:
            ns[i] = 0
            k -= 26 - v

    ns[-1] = (ns[-1] + k) % 26

    return ''.join(alp[n] for n in ns)
print(main(s, k))

Measured memory_bytes: 94212
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;
const int MAX_N=1e5;

signed main(){
    int N;cin>>N;
    int dp[N+1];
    vector<int> cp[200000];
    REP(i,200000)cp[i].clear();
    vector<int>C(N);
    REP(i,N){
        int a;cin>>a;a--;
        C[i]=a;
        cp[a].pb(i);
    }
    dp[0]=1;
    REP(i,N){
        dp[i+1]=dp[i]%MOD;
        int color=C[i];
        int it=lower_bound(all(cp[color]),i)-cp[color].begin();
        if(it!=0){
            int d=cp[color][it-1];
            if(i-d>1)dp[i+1]+=dp[d+1];
        }
      	dp[i+1]%=MOD;
    }
    cout<<dp[N]<<endl;
}

Measured memory_bytes: 14336
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
int main(){
  ll n;cin >> n;
  vector<ll> a(n),b(n);
  for(ll i=0;i<n;i++){cin >> a[i];b[i]=a[i]-i-1;}
  sort(b.begin(),b.end());
  int c=b.size()%2==0?(b[b.size()/2-1]+b[b.size()/2])/2:b[b.size()/2];
  ll sum=0;
  for(auto&x:b)sum+=abs(x-c);
  cout << sum << endl;}
  

Measured memory_bytes: 3328
import java.util.Scanner;

class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        long a = in.nextLong(), b = in.nextLong(), x = in.nextLong();
        long sum = 0;
        System.out.println(b / x - a / x + (a % x == 0 ? 1 : 0));
    }
}


Measured memory_bytes: 21844
import math
N = int(input())
LCM = 1
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
for i in range(N):
    T = int(input())
    LCM = LCM * T // gcd(LCM, T)
print(LCM)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  cin >> N;
  int A[N];
  int result[N];
  for(int a = 0;a < N;a++){
   cin >> A[a];
    result[A[a] - 1] = a + 1;
  }

  
  for(int a = 0;a < N;a++)cout <<result[a]<< " ";
 
}

Measured memory_bytes: 1536
#include<stdio.h>
int main ()
{
    int n,m;
    scanf ("%d%d",&n,&m);
    int arr[n],count,i;
    int sum =0;
    for (i = 0 ; i< n ;i++)
    {
        scanf ("%d",&arr[i]);
        sum = sum+arr[i];
    }
    if (sum%2==0)
    sum = sum/(4*m);
    else sum = sum/(4*m)+1;
    count=0;
    for (i = 0 ;i <n ;i++)
    {
        if (arr[i]>= sum)
        {
            count++;
        }
    }
    if (count >= m)
        printf ("Yes\n");
    else printf ("No\n");
    return 0;
}


Measured memory_bytes: 128
n = int(input())
if n < 10:
  print(n)
elif n < 100:
  print(9)
elif n < 1000:
  print(9+(n-99))
elif n < 10000:
  print(9+900)
elif n < 100000:
  print(9+900+(n-9999))
else:
  print(90909)

Measured memory_bytes: 38384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define MEMSET(a, n, x) REP(i, n) a[i]=x;
#define ARRIN(a, n) REP(i, n) cin>>a[i];
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;

struct qq{
  int y;
  int x;
  int v;
};

int main(){
  int h, w;
  queue<qq> q;
  cin>>h>>w;
  char a[h+2][w+2];
  REP(i, h+2)REP(j, w+2){
    a[i][j]='#';
  }
  REP(i, h){
    REP(j, w){
      cin>>a[i+1][j+1];
      if(a[i+1][j+1]=='#'){
        q.push({i+1, j+1, 0});
      }
    }
  }
  int ans=0, i, j;
  while(!q.empty()){
    qq p = q.front();
    q.pop();
    i=p.y;
    j=p.x;

    ans=max(ans, p.v);
    if(a[i+1][j]=='.') a[i+1][j]='#', q.push({i+1, j, p.v+1});
    if(a[i-1][j]=='.') a[i-1][j]='#', q.push({i-1, j, p.v+1});
    if(a[i][j+1]=='.') a[i][j+1]='#', q.push({i, j+1, p.v+1});
    if(a[i][j-1]=='.') a[i][j-1]='#', q.push({i, j-1, p.v+1});
  }
  ECHO(ans);
  return 0;
}


Measured memory_bytes: 13328
#include<bits/stdc++.h>
using namespace std;
     
#define int long long
#define hell 1000000007  
#define endl "\n"
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX_SIZE 10000000000
 
int32_t main()
{   
    io
    
    int a, b;
    cin>>a>>b;

    if(a>=1 && b>=1 && a<=9 && b<=9)
    {
        cout<<a*b;
    }
    else
        cout<<"-1";
    

return 0;
}

Measured memory_bytes: 256
while True:
     
    Y = input().split("/")
    if Y[0] == "#":
        break
    L = [[False for i in range(9)]for i in range(9)]

    MX = 1
    MY = len(Y)

    for i in range(len(Y)):
        p = 0
        for str_ in Y[i]:
            #print(i,str_)

            if str_ == "b":
                L[i][p] = True
                p += 1
            else:
                p += int(str_)
            MX = max(MX,p)

    #print(L)

    y1,x1,y2,x2 = map(int,input().split(" "))

    #print(y1,x1,y2,x2)

    L[y1-1][x1-1] = False
    L[y2-1][x2-1] = True

    #print(L)

    #print(MX,MY)

    ans = ""
    f = False

    for y in range(MY):
        ans_ = ""
        cnt = 0
        for x in range(MX):
            if L[y][x]:#b
                if cnt > 0:
                    ans_ += str(cnt)
                ans_ += "b"
                cnt = 0
            else:#
                cnt += 1
        if cnt > 0:
            ans_ += str(cnt)
        if y != MY-1:
            ans_ += "/"
        ans += ans_
    print(ans)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define RANGE(i,n) for(int i=0;i<n;i++)
typedef long long ll;

using namespace std;

signed main() {
    string S;
    cin >> S;
    int s_size = S.size();
    bool init = true;
    int count_A = 0;
    int count_B = 0;
    RANGE(i,s_size){
        int s_int = S[i] - '0';
        if(s_int == init){
            count_A++;
        }else{
            count_B++;
        }
        init = !init;
    }
    int ans = min(count_A, count_B);
    cout << ans  << endl;

}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;
using ll = long long;
const int INF = 999999999;

int main() {
    int N, M; cin >> N >> M;
    priority_queue<pair<int, int>> A;
    for (int i = 0; i < N; ++i) {
        int inp; cin >> inp;
        A.push(make_pair(inp, 1));   // Ai has one
    }
    for (int i = 0; i < M; ++i) {
        int b, c; cin >> b >> c;
        A.push(make_pair(c, b));
    }

    ll rtn = 0;
    for (int i = 0; i < N; ++i) {
        pair<int, int> p = A.top();
        A.pop();
        rtn += p.first;
        p.second--;
        if (p.second != 0) A.push(p);
    }

    cout << rtn << endl;
}

Measured memory_bytes: 2420
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef long long ll;

const int MAX_SIZE = 10000;


vector<vector<vector<int> > > dp[31];

void dfs(int n,vector<int> v){
	if(n == 0){
		
		return;
	}
	for(int i = n; i >= 1; i--){
		vector<int> vv = v;
		vv.push_back(i);
		cout << i << " " << flush;
		dfs(n-i,v);
		for(int j = 0; j < vv.size(); j++){
			cout << vv[j] << " " << flush;
		}
	}
}

int main(){

	vector<int> b;
//	dfs(5,b);

	vector<vector<vector<int> > > howToPut[31];
	vector<int> tmp;
	tmp.push_back(1);
	vector<vector<int> > fff;
	fff.push_back(tmp);
	howToPut[1].push_back(fff);
	for(int i = 2; i < 31; i++){
		//cout << i << endl;
		vector<vector<int> > how;
		tmp.clear();
		tmp.push_back(i);
		how.push_back(tmp);
		howToPut[i].push_back(how);
		
		for(int j = i-1; j >= 1; j--){
			vector<vector<int> > nvvi;
			vector<int> c;
			c.push_back(j);
			nvvi.push_back(c);
			for(int k = 0; k < howToPut[i-j].size(); k++){
				vector<vector<int > > tnvvi = nvvi;
				if(howToPut[i-j][k][0][0] > j){
					continue;
				}
				for(int l = 0; l < howToPut[i-j][k].size(); l++){
					tnvvi.push_back(howToPut[i-j][k][l]);
				}
				howToPut[i].push_back(tnvvi);
			}
		}
	}
	
	int n;
	while(cin >> n && !(n == 0)){
		for(int i = 0; i < howToPut[n].size(); i++){
			for(int j = 0; j < howToPut[n][i].size(); j++){
				for(int k = 0; k < howToPut[n][i][j].size(); k++){
					cout << howToPut[n][i][j][k];
				}
				if(j != howToPut[n][i].size()-1)
					cout << " " << flush;
			}
			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 8900