akhauriyash/Code-Regression huggingface dataset:
/*
Competitive programming template
Author: Aswin Sampath

*/


#include<bits/stdc++.h>

using namespace std;


typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<ll>vl;
typedef vector<int>vi;
typedef priority_queue<ll,vl,greater<ll>()> pq_ll_min;
typedef priority_queue<ll> pq_ll_max; 
typedef stack<ll> s;
typedef queue<ll> q;


#define pi 3.141592653589793
#define PI  acos(-1.0)
#define space " "
#define endl '\n'
#define F first
#define S second
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)

#define FAST {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define testcase ll t;cin>>t;while(t--)
#define dbxstl(x){for(auto ele:x)cout<<ele<<space; cout<<endl;}
#define dbxval(x){cout<<x<<endl;}

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

void solve(){
    printf("Hello\n");
}

int main(int argc, char const *argv[])
{
    int n;
    scanf("%d",&n);
    vector<int>h(n);
    for(int &x:h){
        scanf("%d",&x);
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(auto j:{i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
    }
    printf("%d\n",dp[n-1]);
    return 0;
}



Measured memory_bytes: 1024
package main

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

// 行列の積
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	nml := strings.Split(sc.Text(), " ")
	n, _ := strconv.Atoi(nml[0])
	m, _ := strconv.Atoi(nml[1])
	l, _ := strconv.Atoi(nml[2])
	A := make([][]string, n)
	B := make([][]string, m)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i] = make([]string, m)
		for j, v := range strings.Split(sc.Text(), " ") {
			A[i][j] = v
		}
	}
	for i := 0; i < m; i++ {
		sc.Scan()
		B[i] = make([]string, l)
		for j, v := range strings.Split(sc.Text(), " ") {
			B[i][j] = v
		}
	}

	C := make([][]int64, n)
	for i := 0; i < n; i++ {
		C[i] = make([]int64, l)
		for j := 0; j < l; j++ {
			for k := 0; k < m; k++ {
				v1 := parseInt64(A[i][k])
				v2 := parseInt64(B[k][j])
				C[i][j] += v1 * v2
			}
		}
	}

	s := ""
	for _, x := range C {
		for _, y := range x {
			s += fmt.Sprintf("%v ", y)
		}
		s = strings.TrimSpace(s) + "\n"
	}
	fmt.Print(s)
}

func parseInt64(s string) int64 {
	v, _ := strconv.ParseInt(s, 10, 64)
	return v
}



Measured memory_bytes: 8244
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, std.bitmanip;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto A = N.iota.map!(_ => readln.split.map!(to!long).array).array;
    long ans = 0;

    foreach (x; [-1, 1])
        foreach (y; [-1, 1])
            foreach (z; [-1, 1]) {
                auto B = new long[][](N, 3);
                foreach (i; 0..N)
                    foreach (j; 0..3)
                        B[i][j] = A[i][j];
                foreach (i; 0..N) {
                    B[i][0] *= x;
                    B[i][1] *= y;
                    B[i][2] *= z;
                }
                long[] tmp = new long[](3);
                B.sort!"a[0]+a[1]+a[2] > b[0]+b[1]+b[2]"();
                foreach (i; 0..M) foreach (j; 0..3) tmp[j] += B[i][j];
                ans = max(ans, abs(tmp[0]) + abs(tmp[1]) + abs(tmp[2]));
            }

    ans.writeln;
}


Measured memory_bytes: 2812
#include<iostream>
#include<queue>
#include<algorithm>
using namespace std;

class FC{
public:
	int p[31];
	int n;

	bool is_over(){
		return p[1]==p[2]&&p[2]==p[3]&&p[3]==p[4]&&p[4]==p[5]
			&&p[5]==p[6]&&p[6]==p[7]&&p[7]==p[8]&&p[8]==p[9]
			&&p[10]==p[11]&&p[11]==p[12]
			&&p[13]==p[14]&&p[14]==p[15]
			&&p[16]==p[17]&&p[17]==p[18]
			&&p[19]==p[20]&&p[20]==p[21]
			&&p[22]==p[23]&&p[23]==p[24]&&p[24]==p[25]&&p[25]==p[26]
			&&p[26]==p[27]&&p[27]==p[28]&&p[28]==p[29]&&p[29]==p[30];
	}
	void rot1(){
		swap(p[7],p[22]);swap(p[8],p[23]);swap(p[9],p[24]);
		swap(p[13],p[18]);swap(p[10],p[12]);
	}
	void rot2(){
		swap(p[1],p[28]);swap(p[2],p[29]);swap(p[3],p[30]);
		swap(p[15],p[16]);swap(p[19],p[21]);
	}
	void rot3(){
		swap(p[1],p[24]);swap(p[4],p[27]);swap(p[7],p[30]);
		swap(p[10],p[21]);swap(p[16],p[18]);
	}
	void rot4(){
		swap(p[3],p[22]);swap(p[6],p[25]);swap(p[9],p[28]);
		swap(p[12],p[19]);swap(p[13],p[15]);
	}
};

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

	for(int i=0;i<N;i++){
		FC now;
		for(int j=1;j<=30;j++)
			cin>>now.p[j];
		now.n=0;

		queue<FC> que;
		que.push(now);
	
	      	while(!que.empty()){
			now=que.front();
			que.pop();

			if(now.is_over()){
				cout<<now.n<<endl;
				break;
			}
			
			FC nex1=now; nex1.rot1(); nex1.n++; que.push(nex1);
			FC nex2=now; nex2.rot2(); nex2.n++; que.push(nex2);
			FC nex3=now; nex3.rot3(); nex3.n++; que.push(nex3);
			FC nex4=now; nex4.rot4(); nex4.n++; que.push(nex4);
		}
	}

	return 0;
}

Measured memory_bytes: 13780
#include <stdio.h>

int main(void){
	while(1){
		int n, a, b, c, i;
	
		scanf(" %d", &n);
		if(n==0) break;
	
		for(i=0; i<n; i++){
			int r=0;
			scanf(" %d %d %d", &a, &b, &c);
			
			if(a==100 || b==100 || c==100) r=2;
			else if((a+b)/2.0 >= 90) r=2;
			else if((a+b+c)/3.0 >= 80) r=2;
			else if((a+b+c)/3.0 >= 70) r=1;
			else if( ((a+b+c)/3.0 >= 50) && (a>=80 || b>=80) ) r=1;
			
			if(r==2) printf("A\n");
			else if(r==1) printf("B\n");
			else printf("C\n");
		}
	
	}

	return 0;
}

Measured memory_bytes: 584
#include<bits/stdc++.h>
using namespace std;
bool tmp(pair<int,int>a,pair<int,int>b) {
	return a.first<b.first;
}
int main() {
	pair<int,int>a[100000];
	int n,m;
	long long yen=0;
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>a[i].first>>a[i].second;
	sort(a,a+n,tmp);
	for(int i=0;i<n,m>0;i++) {
		if(m>a[i].second) yen+=(long long)a[i].first*a[i].second;
		else yen+=(long long)m*a[i].first;
		m-=a[i].second;
	}
	cout<<yen<<endl;
	return 0;
}

Measured memory_bytes: 1024
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll n;
vector<ll> v;
vector<ll> w;
vector<vector<ll>> dp;
int main(void){
    cin >> n;
    v.resize(n + 1);
    w.resize(n + 1);
    dp.resize(513, vector<ll>(100000 + 1, 0));

    for(ll i = 1; i < n + 1; i++){
        cin >> v[i] >> w[i];
    }

    dp[0][0] = 0;
    for(ll i = 1; i <= min(n, 512LL); i++){
        for(ll j = 0; j <= 100000; j++){
            ll past = (i) / 2;
            if(j + w[i] <= 1e5) dp[i][j + w[i]] = max(dp[i][j + w[i]], dp[past][j] + v[i]);
            dp[i][j] = max(dp[i][j], dp[past][j]);
        }
    }

    //dfs1(0, 0);
    //cout << log2(262143) << endl;

    ll q;
    cin >> q;
    rep(i, q){
        ll u, l;
        cin >> u >> l;
        ll now = u;
        ll ans = 0;
        vector<pair<ll,ll>> items;
        if(u < 512){
            ans = dp[now][l];
            cout << ans << endl;
            continue;
        } 
        while(now >= 512){
            items.push_back({v[now], w[now]});
            now = (now) / 2;
        }

        for(ll bit = 0; bit <(1LL << (ll)items.size()); bit++){
            ll sumv = 0;
            ll sumw = 0;
            rep(j, items.size()){
                if(bit & (1LL << j)){
                    sumv += items[j].first;
                    sumw += items[j].second;
                }
            }
            if(now >= 512) {
                cout << "e" << endl;
            }
            if(sumw > l) continue;
            ans = max(ans, sumv + dp[now][max(0LL,l - sumw)]);
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 410292
import java.io.*;
import java.util.*;

class Main {

	private static int f(long a) {
		int count = 0;
		while (a > 0) {
			count++;
			a /= 10;
		}

		return count;
	}

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();

		int a = f(N);
		for (long i = 1; i * i <= N; i++) {
			if (N % i != 0) continue;
			int x = Math.max(f(i), f(N / i));
			a = Math.min(a, x);
		}

		System.out.println(a);
	}
}


Measured memory_bytes: 23892
#include<stdio.h>
int main(void){
	int H,W,c=0;
	int a,b=1;
	while(1){
		scanf("%d %d",&H,&W);
		if(c==1){
			printf("\n");
		}
		else{
			c=1;
		}
		for(a=1;a<=H;a++){
			if(a%2==0){
				for(b=1;b<=W;b++){
					if(b%2==0){
						printf("#");
					}
					else{
						printf(".");
					}
				}
			}
			else{
				for(b=1;b<=W;b++){
					if(b%2==0){
						printf(".");
					}
					else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		if(H==0&&W==0){
					break;
				}
	}
	return 0;

}

Measured memory_bytes: 2692
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[100010];
bool used[100010];

vector<int> G[100010];

int dfs(int v) {
    if (used[v]) return dp[v];
    used[v] = true;
    int tmp = 0;
    for( auto next : G[v]) {
        tmp = max(tmp, dfs(next) + 1);
    }
    return dp[v] = tmp;
}



int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
    }
    int ans = 0;
    rep(i, N) ans = max(ans, dfs(i));
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8320
#include <stdio.h>
#include <math.h>

typedef struct{
  double x;
  double y;
}Point;

void koch(int n, Point a, Point b){
  Point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  if(n==0)return;

  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;

  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;

  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  printf("%.8f %.8f\n", s.x, s.y);

  koch(n-1,s,u);
  printf("%.8f %.8f\n", u.x, u.y);

  koch(n-1,u,t);
  printf("%.8f %.8f\n", t.x, t.y);

  koch(n-1,t,b);
}

int main(){
  Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;

  b.x = 100;
  b.y = 0;

  printf("%.8f %.8f\n", a.x, a.y);

  koch(n,a,b);

  printf("%.8f %.8f\n", b.x, b.y);

  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll N, X, D; cin >> N >> X >> D;
    ll curLo = 0;
    ll curHi = 0;
    
    if (D == 0) {
        if (X == 0) {
            cout << 1 << endl; return 0;
        } else {
            cout << 1+N << endl; return 0;
        }
    }
    
    if (D < 0) D *= -1, X *= -1;
    bool oNeg = X < 0;
    ll oX = X;
    X = abs(X) % abs(D);
    if (oNeg) X = abs(D) - X;
    X %= D;

    map<ll, vpl> ranges;

    F0R(i, N+1) {
        if (i > 0) curLo += i-1;
        if (i > 0) curHi += (N - i);
        ll oMod = i; 
        oMod %= D;
        oMod *= X;
        if (oMod < 0) {
            oMod *= -1;
            oMod %= D;
            oMod = D - oMod;
        }
        oMod %= D;
        if (!ranges.count(oMod)) {
            vpl blank; ranges[oMod] = blank;
        }
        ll oVal = i; 
        oVal *= oX;
        bool mod = (abs(oVal) % D && oVal < 0);
        oVal /= D; if (mod) oVal--;
//        cout << i << " " << oVal << endl;
        ranges[oMod].pb({curLo + oVal, curHi + oVal});

    }

    ll ans = 0;
    for (auto it = ranges.begin(); it != ranges.end(); it++) {
        vpl cur = it->s;
        ll lst = -1000000000000000000;
//        cout << it->f << endl;
        sort(all(cur));
        F0R(i, sz(cur)) {
            ll lo = cur[i].f, hi = cur[i].s;
//            cout << lo << " " << hi << endl;
            if (hi > lst) {
                ans += (hi - max(lo, lst+1)) + 1;
                lst = hi;
            }
            
        }
    }

    cout << ans << endl;

	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 22144
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if b-a<=k and c-a<=k and d-a<=k and e-a<=k and c-b<=k and d-b<=k and e-b<=k and d-c<=k and e-c<=k and e-d<=k:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include <list>
using namespace std;
class myprocess{
public:
	string name;
	int times;
};
int main(){
	std::list<myprocess> pq;
	int n,time;
	cin >> n >> time;
	for(int i=0;i<n;++i){
		myprocess p;
		cin >> p.name >> p.times;
		pq.push_back(p);
	}
	int pass=0;
	while(pq.size() > 0) {
		myprocess current = *pq.begin();
		if (current.times <= time) {
			pass += current.times;
			cout << current.name << " " << pass << std::endl;
			pq.pop_front();
		} else {
			pass += time;
			current.times -= time;
			pq.pop_front();
			pq.push_back(current);
		}
	}
}

Measured memory_bytes: 1304
n,x,y = map(int,input().split())

def dist(i,j):
  return min(j-i, abs(x-i) + abs(y-j) + 1, abs(x-j) + abs(y-i) + 1)

listlist = [0]*(n-1)

for i in range(1,n):
  for j in range(i+1,n+1):
    distance = dist(i,j)
    listlist[distance-1] = listlist[distance-1] + 1
    
for k in listlist:
  print(k)


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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,j,a,b;
	cin >> n >> m;
	ll arr[n+2],hash[n+2]={0};
	for(i=1;i<=n;i++)
	{
		cin >> arr[i];
	}
	for(i=0;i<m;i++)
	{
		cin >> a >> b;
		if(arr[a]>arr[b])
		{
			hash[b]=1;
			// cout << b << " hi1\n";
		}
		else if(arr[a]<arr[b])
		{
			hash[a]=1;
			// cout << a << " hi2\n";

		}
		else
		{
			hash[a]=1;
			hash[b]=1;
			// cout << a << " " << b << " hi3\n";

		}
	}
	k=0;
	for(i=1;i<n+1;i++)
	{
		if(hash[i]==0)
		{
			k++;
			// cout << hash[i] << " i=" << i << endl;
		}
	}
	cout << k << "\n";
	return 0;
}

Measured memory_bytes: 5196
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

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

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int r;
    cin >> r;
    cout << 3*r*r << endl;

    return 0;
}


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

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1

    return table

divs = num_divisors_table(n)

res = 0
for i in range(1, n+1):
    res += i * divs[i]

print(res)



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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio ios::sync_with_stdio(false); cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main(){
	int n, k;
	string s;
	fastio;
	// #ifndef LOCAL
 //    	freopen("input.in", "r", stdin);
 //    	freopen("output.out", "w", stdout);
	// #endif
    cin >> n >> s >> k;
    for(auto i : s){
    	if(i != s[k-1]) cout << '*';
    	else cout << i;
    }
    cout << endl;
	return 0;
}

// template function
ll gcd(int a, int b) { 
	if (b == 0) return a; 
	return gcd(b, a % b);  
} 

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

ll powm(ll a, ll b){
	ll x=1, y=a; 
    while (b > 0) {
        if (b%2) x = (x*y) % mod;
        y = (y*y) % mod;
        b /= 2;
    }
    return x % mod;
}

ll multm(ll a, ll b){
	return ((a%mod) * (b%mod)) % mod;
}

ll divm(ll a, ll b){
	return (a * powm(b, mod - 2)); 
}

ll subm(ll a, ll b){
	a -= b;
  	if (a < 0) a += mod;
	return a;
}

ll addm(ll a, ll b){
	a += b;
  	if (a >= mod) a -= mod;
  	return a;
}

Measured memory_bytes: 256
s = list(input())

for i in range(4):
    s[i] = int(s[i])

a = s[0]*10 + s[1]
b = s[2]*10 + s[3]


if a >= 13 and b >= 13:
    print("NA")
elif a >= 13 and b <= 12:
    if b > 0:
        print("YYMM")
    else:
        print("NA")
elif a <= 12 and b >= 13:
    if a > 0:
        print("MMYY")
    else:
        print("NA")
else:
    if a == 0 and b == 0:
        print("NA")
    elif a == 0:
        print("YYMM")
    elif b == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,n,s) for(int i=(int)(s);i<(int)(n);++i)
#define RREP(i,n,s) for(int i=(int)(s);i>=(int)(n);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

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

    int M = max(a, max(b, c));

    cout << 10*M + (a+b+c-M) << endl;
}


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

int main(){
  
  char ch;
  int d;
  int sum = 0;
  while(1){
    scanf("%c",&ch);
    if(ch == '\n'){
      if(sum == 0){
	break;
      }
      else{
	printf("%d\n",sum);
	sum = 0;
      } 
    }else{
      d = ch -'0';
      sum += d;
    }
  }
  return 0;
}   



Measured memory_bytes: 3208
#include<iostream>
#include<vector>
using namespace std;
vector<int> b;
int main(void){
	int N,M,C;
	cin >> N >> M >> C;
	b = vector<int>(M);
	for(int i=0;i<M;i++) cin >> b[i];
	
	int ans = 0;
	for(int i=0;i<N;i++){
		int total = 0;
		for(int j=0;j<M;j++){
			int A;
			cin >> A;
			total += A * b[j];
		}
		total += C;
		if(total > 0) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
const int maxn=100;
string s[maxn];
int m[28];
bool comp(int a,int  b)
   	{
   	  return a>b; 	
	}
int main ()
{
	int n;
	cin>>n;
	getchar();
	int ans=0;
    for (int i=0;i<3;++i)
       getline(cin,s[i]);
    for (int i=0;i<n;++i)
       {
       		memset(m,0,sizeof(m));
       	 	for (int j=0;j<3;++j)
       	    	{
       	    	  m[s[j][i]-'a']++;
				}
			sort(m,m+27,comp);
			ans=ans+3-m[0];
	   }
	printf ("%d\n",ans);
 } 

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

int main()
{
  double w, h, x, y;
  cin >> w >> h >> x >> y;

  double rec = 0.5 * w * h;

  int ans = 0;
  if (2 * x == w && 2 * y == h)
  {
    ans = 1;
  }
  cout << fixed << setprecision(6) << rec << " " << ans << endl;
}


Measured memory_bytes: 3752
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int n;
int costs[100001], dp[100001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n; forl(i, 0, n) cin >> costs[i];
	forl(i, 0, 100001) dp[i] = INT_MAX;
	dp[0] = 0;
	forl(i, 0, n) {
		dp[i+1] = min(dp[i+1], dp[i]+abs(costs[i]-costs[i+1]));
		dp[i+2] = min(dp[i+2], dp[i]+abs(costs[i]-costs[i+2]));
	}
	println(dp[n-1]);
}


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

vector<vector<int>> ab;
vector<bool> chk_flg;
int ans = 0;
int n, m;

void dfs ( int x = 0 ) {
    chk_flg[x] = true;
    for ( auto n: ab[x] ) {
        if ( chk_flg[n] ) continue;
        dfs(n);
    }
    bool chk_all = true;
    for ( int i = 0; i < n; i++ ) {
        if ( !chk_flg[i] ) chk_all = false;
    }

    if ( chk_all ) {
        ans++;
    }
    chk_flg[x] = false;
}

int main() {

    cin >> n >> m;

    ab.resize(n);
    chk_flg.resize(n);
    for ( int i = 0; i < n; i++ ) {
        ab[i].resize(1);
        chk_flg[i] = false;
    }

    for ( int i = 0; i < m; i++ ) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        ab[a].push_back(b);
        ab[b].push_back(a);
    }

    dfs();

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265


void f(int x,int y,int s){
  int ans =0;
  for(int i=1;i<=s;i++){
    for(int j=1;j<=s-i;j++){
      if((i*(100+x)/100)+(j*(100+x)/100)==s){
  
        int z = (i*(100+y)/100)+(j*(100+y)/100);

        ans = max(ans,z);
      }
    }
  } 
  cout<<ans<<endl;
}


int main(){

  int x,y;
  int s;

  while(1){
    cin>>x>>y>>s;
    if(x==0) break;
    f(x,y,s);
  }

  return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

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

	N = "x" + N;
	int n = N.size();
	Int dp[110][5][2] = { 0 };
	dp[0][0][1] = 1;
	for (int i = 1; i < n; ++i) {
		int x = N[i] - '0';
		// j := 各桁の値
		for (int j = 0; j < 10; ++j) {
			// k := 0でない数字の数
			for (int k = 0; k <= K + 1; ++k) {
				if (j < x) {
					if (j == 0) {
						dp[i][k][0] += dp[i-1][k][0] + dp[i-1][k][1];
					} else if (k > 0) {
						dp[i][k][0] += dp[i-1][k-1][0] + dp[i-1][k-1][1];
					}
				}
				if (j == x) {
					if (j == 0) {
						dp[i][k][0] += dp[i-1][k][0];
						dp[i][k][1] += dp[i-1][k][1];
					} else if (k > 0) {
						dp[i][k][0] += dp[i-1][k-1][0];
						dp[i][k][1] += dp[i-1][k-1][1];
					}
				}
				if (j > x && k > 0) {
					dp[i][k][0] += dp[i-1][k-1][0];
				}
			}
		}
	}

	Int ans = dp[n - 1][K][0] + dp[n - 1][K][1];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
int main(){
    int64_t n;
    int64_t a,b,c,d,e;
    cin >> n>> a>>b>>c>>d>>e;
    cout << fixed << setprecision(20);
    cout << 4+ (int64_t) ceil(double(n)/min(a,min(b,min(c,min(d,e)))))<<endl;
}

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

int main(void) {
  int a, b, c, count = 0;

  if(scanf("%d %d %d", &a, &b, &c) == 1);

  if(a > b) {
    printf("0");
    return 0;
  }

  while(a <= b) {
    b = b - a;
    count++;
    if(count == c) {
      break;
    }
  }

  printf("%d", count);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long long a,b,aa=0,bb=0;
  cin>>a>>b;
  for(int i=1; i<=b; i++){
    aa=aa*10+a;
  }
  for(int i=1; i<=a; i++){
    bb=bb*10+b;
  }
  string A=to_string(aa);
  string B=to_string(bb);
  cout<<(A>=B?B:A)<<endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n;
	scanf("%d", &n);
	vector<int> A(n), B(n), P(n);
	const int M = 20005;
	for (int i = 0; i < n; ++i) {
		A[i] = i * M + 1;
		B[i] = (n - 1 - i) * M + 1;
	}
	for (int i = 0; i < n; ++i) {
		scanf("%d", &P[i]);
		--P[i];
		A[P[i]] += i;
	}
	for (int x : A) printf("%d ", x);
	printf("\n");
	for (int x : B) printf("%d ", x);
	printf("\n");
}


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

struct edge {
    int to, cost;
};

int N;
vector<edge> G[100000];
vector<bool> v(100000);
vector<bool> color(100000);
void dfs(int s) {
    v[s] = true;
    for (int i = 0; i < G[s].size(); i++) {
        edge e = G[s][i];
        if (!v[e.to]) {
            if (e.cost % 2 == 0) {
                color[e.to] = color[s];
                dfs(e.to);
            } else {
                color[e.to] = !color[s];
                dfs(e.to);
            }
        }
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int u, v, w;
        cin >> u >> v >> w;
        u--, v--;
        G[u].push_back({v, w});
        G[v].push_back({u, w});
    }
    color[0] = 1;
    dfs(0);
    for (int i = 0; i < N; i++) {
        cout << color[i] << endl;
    }
}

Measured memory_bytes: 8320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

const int MAX_H = 500;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 100000;                  // 10^5
// const int MAX_N = 1000000000;              // 10^9
// const ll  MAX_N = 1000000000000000000;     // 10^18
// const int BASE  = 1000000000 + 7;          // 10^9 + 7
// const int INFI  = 1000000000 + 7;          // 10^9 + 7
// const ll INFL  = 1000000000000000000 + 7; // 10^18 + 7

int H, W, R, C;
int S[MAX_H + 1];

bool judge() {
  if (H % R == 0 && W % C == 0) return false;

  int n = (W % C == 0)? H: W;
  int k = (W % C == 0)? R: C;

  memset(S, 0, sizeof(S));

  S[n] = 1;
  for (int i = 0; i < n / k; i++) {
    int y = n - i * k;
    S[y - k] = S[y] + 1;
  }

  for (int i = 0; i < n - k; i++) {
    if (S[i] == 0) {
      for (int j = i; j + k < n; j += k) S[j + k] = S[j] - 1;
    }
  }

  return true;
}

void solve() {
  if (judge()) {
    cout << "Yes" << endl;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        int x = (W % C == 0)? i: j;
        cout << S[x + 1] - S[x] << " ";
      }
      cout << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

int main() {
  cin >> H >> W >> R >> C;

  solve();

  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> p(M+2);
    vector<string> S(M+2);
    rep(i,M) cin >> p[i] >> S[i];
    vector<int> WA(N+2);
    vector<int> AC(N+2);
    rep2(i,N+1) {
        WA[i] = 0;
        AC[i] = 0;
    }
    rep(i,M) {
        if(S[i]=="WA" && AC[p[i]]==0) WA[p[i]]++;
        else if(S[i]=="AC" && AC[p[i]]==0) AC[p[i]]++;
    }
    rep2(i,N+1) {
        if(AC[i] == 0) WA[i]=0;
    }
    int ans1 = 0;
    int ans2 = 0;
    rep2(i,N+1) {
        ans1+=AC[i];
        ans2+=WA[i];
    }
    cout << ans1 << " " << ans2 << endl;
    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
#include<vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 1000005
#define MOD 998244353
#define NIN -100000000
#define EPS 0.0000000001
int a[MAX];
int cnt[MAX];
int main()
{
    int n,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        cnt[a[i]]++;
    }
    int ans=0;
    for(i=0;i<n;i++)
    {
        if(cnt[a[i]]>1||cnt[1]>1) continue;
        if(a[i]!=1&&cnt[1]>0) continue;
        for(j=2;j*j<=a[i];j++)
        {
            if(a[i]%j) continue;
            if(cnt[a[i]/j]>0||cnt[j]>0)
            {
                break;
            }
        }
        if(j*j>a[i]) ans++;
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 8472
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

struct Edge {
	ll src;
	ll dst;
	ll lgt;
	ll cost;
};

using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(ll a, ll b, ll lgt, ll cost, Graph& g) {
	g[a].pb(Edge{a,b,lgt,cost});
	g[b].pb(Edge{b,a,lgt,cost});
}

ll n,m;

vector<ll> dijkstra(ll s, Graph g) {
	vector<ll> dist(n,INF*INF);
	dist[s]=0;
	priority_queue<P,vector<P>,greater<P>> q;
	q.push(P(0,s));
	while(!q.empty()) {
		ll d=q.top().first;
		ll p=q.top().second;
		q.pop();
		if(dist[p]!=d) continue;
		REP(i,(ll)g[p].size()) {
			ll l=g[p][i].lgt;
			ll np=g[p][i].dst;
			if(dist[np]>d+l) {
				dist[np]=d+l;
				q.push(P(dist[np],np));
			}
		}
	}
	return dist;
}

ll solve() {
	Graph g(n);
	REP(i,m) {
		ll u,v,d,c;
		cin>>u>>v>>d>>c;
		u--;
		v--;
		add_edge(u,v,d,c,g);
	}
	vector<ll> min_dist=dijkstra(0,g);
	ll ans=0;
	FOR(i,1,n) {
		ll min_d=min_dist[i];
		ll buf=INF*INF;
		REP(j,g[i].size()) {
			if(min_d==g[i][j].lgt+min_dist[g[i][j].dst]) {
				buf=min(buf,g[i][j].cost);
			}
		}
		ans+=buf;
	}
	return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>n>>m;
		if(n==0&&m==0) break;
		cout<<solve()<<endl;
	}
}



Measured memory_bytes: 6760
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;

typedef long long ll;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
const ll INF = 1000000000000000;

struct edge {
    int from, to;
    ll cost;
    edge(int f, int t, ll c) : from(f), to(t), cost(c) {}
    edge() {}
};

const int MAXV = 1024;
const int MAXE = 2048;
edge es[MAXE];
ll dist[MAXV];

int main(void) {
    int V, E, r;
    cin >> V >> E >> r;
    for (int i = 0; i < E; i++) {
        int s, t;
        ll d;
        cin >> s >> t >> d;
        es[i] = edge(s, t, d);
    }
    for (int i = 0; i < V; i++) {
        dist[i] = INF;
    }
    dist[r] = 0;
    int cnt = 0;
    while (1) {
        bool update = false;
        for (int i = 0; i < E; i++) {
            edge e = es[i];
            if (dist[e.to] > dist[e.from] + e.cost && dist[e.from] != INF) {
                dist[e.to] = dist[e.from] + e.cost;
                update = true;
            }
        }
        if (!update) break;
        cnt++;
        if (cnt > V) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (int i = 0; i < V; i++) {
        if (dist[i] >= INF) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

long long int lcm(long long int a, long long int b)
{
    long long int x, tmp, r;
    x = a * b;
    if (a < b)
    {
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while (r != 0)
    {
        a = b;
        b = r;
        r = a % b;
    }
    return x / b;
}

int main()
{
   int n;
   cin>>n;
   int a;
   long long int ans=0;
   rep(i,n){
       cin>>a;
       ans+=a-1;
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 100100;
const int S = 400400;
const int A = 26;
int n, m, q;
int go[S][A];
int cnt[S];
int term[S];
string s[N];
int a[N][A][A];
int b[N];

int solve() {
	int p;
	string w;
	cin >> p >> w;
	p--;
	int ans = 1 + b[p];
	for (int i = 0; i < A; i++)
		for (int j = i + 1; j < A; j++)
			ans += a[p][(int)(w[j] - 'a')][(int)(w[i] - 'a')];
	return ans;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

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

	m = 1;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		int v = 0;
		for (char cc : s[i]) {
			int c = (int)(cc - 'a');
			if (go[v][c] == 0) go[v][c] = m++;
			v = go[v][c];
			cnt[v]++;
		}
		term[v]++;
	}
	for (int i = 0; i < n; i++) {
		int v = 0;
		for (char cc : s[i]) {
			b[i] += term[v];
			int c = (int)(cc - 'a');
			for (int x = 0; x < A; x++) {
				if (x == c || go[v][x] == 0) continue;
				a[i][c][x] += cnt[go[v][x]];
			}
			v = go[v][c];
		}
	}
	cin >> q;
	while(q--)
		cout << solve() << "\n";

	return 0;
}


Measured memory_bytes: 279932
A, B, C, D = map(int, input().split())
l = [0] * 102

l[A] += 1
l[B] -= 1
l[C] += 1
l[D] -= 1

for i in range(1, len(l)):
    l[i] += l[i - 1]

ans = 0

for i in range(0, len(l)):
    if l[i] == 2:
        ans += 1

print(ans)


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

using namespace std;
//131073
typedef pair<int, int> pii;
typedef long long ll;
multiset<int>s;
multiset<int>::iterator it;

const int maxn = 100000 + 10;
int a[maxn];
int dfs(int k, int n, int idx, int l , int r){
    int res = 1;
    l --;
    r = n - r;
    if( l > 0)res += l % (k - 1) == 0 ? l / (k - 1): l / (k - 1) + 1;
    if( r > 0)res += r % (k - 1) == 0 ? r / (k - 1): r / (k - 1) + 1;
   return res;
}

int main(){
    ios_base::sync_with_stdio(0);
    int n, k;
    cin >> n >> k;

        int idx = 0;
        for (int i = 0; i < n; ++i) {
            cin >> a[i];
            if (a[i] == 1)idx = i + 1;
        }
        int res = (idx - 1) % (k - 1) == 0 ? (idx - 1) / (k - 1) : (idx - 1) / (k - 1) + 1;
        res += (n - idx) % (k - 1) == 0 ? (n - idx) / (k - 1) : (n - idx) / (k - 1) + 1;
        for (int i = 0; i <= min(idx, k-1); ++i) {
            int l = idx - i;
            int r = idx + k - 1 - i;
            res = min(res, dfs(k, n, idx, l , r));
        }
        if (n == k)res = 1;
        cout << res << '\n';
    return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);

		int h = sc.nextInt();
		int w = sc.nextInt();
		int m = sc.nextInt();

		HashMap<Integer, Integer> hMap = new HashMap<Integer, Integer>();
		HashMap<Integer, Integer> wMap = new HashMap<Integer, Integer>();
		HashSet<String> set = new HashSet<String>();

		for (int i=0; i<m; i++){
			int bh = sc.nextInt();
			int bw = sc.nextInt();

			if (hMap.containsKey(bh)){
				hMap.put(bh, hMap.get(bh)+1);
			} else {
				hMap.put(bh, 1);
			}
			if (wMap.containsKey(bw)){
				wMap.put(bw, wMap.get(bw)+1);
			} else {
				wMap.put(bw, 1);
			}
			String val = bh + "," + bw;
			set.add(val);
		}

        List<Map.Entry> hMapValuesList = new ArrayList<Map.Entry>(hMap.entrySet());

        Collections.sort(hMapValuesList, new Comparator<Map.Entry>() {

            @Override

            public int compare(Entry entry1, Entry entry2) {

                return ((Integer) entry2.getValue()).compareTo((Integer) entry1
                        .getValue());
            }
        });

        List<Map.Entry> wMapValuesList = new ArrayList<Map.Entry>(wMap.entrySet());

        Collections.sort(wMapValuesList, new Comparator<Map.Entry>() {

            @Override

            public int compare(Entry entry1, Entry entry2) {

                return ((Integer) entry2.getValue()).compareTo((Integer) entry1
                        .getValue());
            }
        });

		int ans = 0;
		int maxhValue=(int) hMapValuesList.get(0).getValue();
		int maxwValue=(int) wMapValuesList.get(0).getValue();
		boolean finish = false;

		for (int i=0; i<hMapValuesList.size(); i++){

			int hKey = (int) hMapValuesList.get(i).getKey();
			int hValue = (int) hMapValuesList.get(i).getValue();

			if (maxhValue != hValue){
				break;
			}

			for (int j=0; j<wMapValuesList.size(); j++){

				int wKey = (int) wMapValuesList.get(j).getKey();
				int wValue = (int) wMapValuesList.get(j).getValue();

				if (maxwValue != wValue){
					break;
				}

				int exp = hValue + wValue;

				String val = hKey + "," + wKey;
				if (set.contains(val)){
					exp--;
				} else {
					finish = true;
				}
				ans = Math.max(ans, exp);
				if (finish){
					break;
				}
			}
			if (finish){
				break;
			}

		}
		System.out.println(ans);

	}


}

Measured memory_bytes: 142984
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <list>
#include <cmath>
#include <numeric>
#include <sstream>
#include <iomanip>
#include <set>
using ll = long long;
using namespace std;
#define INF 999999999

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;


class Main{
  public static void main(String[] args)throws IOException{
	
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();

	String[] strAry = str.split(" ");
	
	int x = Integer.parseInt(strAry[0]);
	int y = Integer.parseInt(strAry[1]);

	System.out.println(x*y +" "+ 2*(x+y));
  }
}

Measured memory_bytes: 24160
#include<iostream>

using namespace std;
int c[1000];//97
int main()
{
    for(int i=0;i<3;i++){
        scanf("%d",&c[i]);
    }
    if(c[0]==c[1])printf("%d",c[2]);
    else if(c[1]==c[2])printf("%d",c[0]);
    else printf("%d",c[1]);

    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define LOG1(a)			  cerr<< #a << " = " << (a) << "\n"
#define LOG2(a, b)		  cerr<< #a << " = " << (a) << ", " << #b << " = " << (b) << "\n"
#define endl "\n"

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;

const ll INF = 1e18;
const int inf = 1e9;
const int MOD = 1e9 + 7;
const int nax = 1000000 + 10;

int n, arr[nax];
int main()
{
    ios::sync_with_stdio(0);
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    int cnt = 0;
    int pos = -1;
    int len = s.length();
    for(int i = 0; i < len; i++)
    {
        if(s[i] == '-')
        {
            cnt++;
            pos = i + 1;
        }
    }
    if(cnt != 1 || len != a + b + 1)
    {
        cout << "No";
        return 0;
    }
    if(pos - 1!= a) cout << "No";
    else cout << "Yes";
    return 0;
}


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

typedef unsigned long long ulli;

const ulli B = 1000000007ULL;
const int MAXN = 300005;
int n, m;
string s;
ulli Bn[MAXN];
ulli sum_h[MAXN];

int main() {
  for (int i = 0; i < MAXN; ++i) {
    if (i == 0) Bn[i] = 1;
    else Bn[i] = Bn[i-1] * B;
  }
  while (cin >> n >> m) {
    cin >> s;
    sum_h[0] = 0;
    for (int i = 0; i < n; ++i) {
      sum_h[i+1] = sum_h[i] + s[i] * Bn[i];
    }
    set<ulli> t;
    int l = 0, r = 0;
    while (m--) {
      string q; cin >> q;
      if (0) {
      } else if (q == "L++") {
        l++;
      } else if (q == "L--") {
        l--;
      } else if (q == "R++") {
        r++;
      } else if (q == "R--") {
        r--;
      }
      ulli hash = (sum_h[r+1] - sum_h[l]) * Bn[n-r];
      t.insert(hash);
    }
    cout << t.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 20032
from itertools import accumulate

MOD = 10 ** 9 + 7

N, K = map(int, input().split())
As = list(map(int, input().split()))

dp = [0] * (K+1)
dp[0] = 1
for A in As:
    accDP = [0] + list(accumulate(dp))
    accDP = [accDPi % MOD for accDPi in accDP]
    dp = [(accDP[j+1] - accDP[max(0, j-A)]) % MOD for j in range(K+1)]

print(dp[K])


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

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

int main(){
  ll a,b;
  ll v,w;
  cin >> a >> v;
  cin >> b >> w;
  ll t;
  cin >> t;

  if(a<b){
    ll blast = b+t*w;
    ll alast = a+t*v;
    if(alast>=blast) cout << "YES";
    else cout << "NO";
  }else{
    ll blast = b-t*w;
    ll alast = a-t*v;
    if(alast<=blast) cout << "YES";
    else cout << "NO";
  }
}

Measured memory_bytes: 3636
def abc094B():
    n = input().split()
    n = list(map(int, n))
    a = input().split()
    a = list(map(int, a))
    count = 0
    for i in a:
        if n[2] > i:
            count += 1
    print(min(count, n[1] - count))


abc094B()

Measured memory_bytes: 3064
a, b = map(int, input().split())

if a <= 0 and 0 <= b:
    print("Zero")
elif 0 < a:
    print("Positive")
elif a < 0 and 0 <= b:
    print("Zero")
else:
    if abs(a - b) % 2 == 1:
        print("Positive")
    else:
        print("Negative")
        
        

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    string ans = "NO";
    if (b-a==c-b) ans = "YES";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <iostream>

using namespace std;

int main(void) {
    int x, y;
    cin >> x >> y;
    bool t = false, k = false;
    // 鶴の検査
    if ((4*x - y)%2 == 0) {
        if (4*x - y >= 0) {
            t = true;
        }
    }
    // 亀の検査
    if ((y - 2*x)%2 == 0) {
        if (y - 2*x >= 0) {
            k = true;
        }
    }

    if (t && k) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define inf (long long)(2e18)
using namespace std;

long long n;
vector<long long> a;

long long solve();
bool check(long long x);

int main() {
  cin >> n;
  a.resize(n);
  for (auto& p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long l = 0, r = n + 2;
  while (r - l > 1) {
    long long mid = (l + r) / 2;
    if (check(mid))
      r = mid;
    else
      l = mid;
  }
  return r;
}

bool check(long long x) {
  using P = pair<long long, long long>;
  vector<P> now(1, P(0, 0));
  for (int i = 0; i < n; ++i) {
    P nxt = P(0, 0);
    while (now.back().first >= a[i] || nxt.second + 1 > x) {
      if (now.size() == 1) return 0;
      nxt = now.back();
      now.pop_back();
    }
    nxt.first = min(nxt.first - 1, a[i] - 1);
    if (nxt.first > now.back().first) now.push_back(nxt);
    ++nxt.first;
    ++nxt.second;
    if (nxt.first) now.push_back(nxt);
    nxt.first = a[i];
    nxt.second = 1;
    if (nxt.first > now.back().first) now.push_back(nxt);
  }
  return 1;
}

Measured memory_bytes: 11696