akhauriyash/Code-Regression huggingface dataset:
n, a, b, c = map(int, input().split())
bamboos = []
for i in range(n):
    bamboo = int(input())
    bamboos.append(bamboo)

def Base_10_to_n(X, n):
    X_dumy = X
    out = ''
    while X_dumy>0:
        out = str(X_dumy%n)+out
        X_dumy = int(X_dumy/n)
    return out

def calc_score(group, target):
    score = 0
    if len(group) > 1:
        score += 10 * (len(group) - 1)
    length = sum(group)
    score += abs(length - target)
    return score

min_score = 10**12
for i in range(4**n):
    num = Base_10_to_n(i, 4).zfill(n)
    score = 0
    group_A = []
    group_B = []
    group_C = []
    for j in range(n):
        if num[j] == '1':
            group_A.append(bamboos[j])
        elif num[j] == '2':
            group_B.append(bamboos[j])
        elif num[j] == '3':
            group_C.append(bamboos[j])
    if len(group_A) == 0 or len(group_B) == 0 or len(group_C) == 0:
        continue
    else:
        score += calc_score(group_A, a)
        score += calc_score(group_B, b)
        score += calc_score(group_C, c)

    if score < min_score:
        min_score = score

print(min_score)

Measured memory_bytes: 9188
S = input()
T = input()

def shi(array):
    out = array[-1]+array[:-1]   
    return out

#print(shi(S)
    
for i in range(0,len(S)):
    if S == T:
        print('Yes')
        break
    if i == len(S) - 1:
        print('No')
    T = shi(T)

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

using i64 = long long int;

int c[51][51] = {0};

void bfs(int w, int h, int x, int y){
    if(x < 0 || x >= w)return;
    if(y < 0 || y >= h)return;
    if(c[y][x] == 0)return;

    c[y][x] = 0;
    for(int dy=-1;dy<=1;++dy){
        for(int dx=-1;dx<=1;++dx)
            bfs(w, h, x+dx, y+dy);
    }
}

int main(){
    int w, h;
    while(cin >> w >> h, w != 0){
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j)
                cin >> c[i][j];
        }

        int ans = 0;
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                if(c[i][j] == 1){
                    bfs(w, h, j, i);
                    ans++;
                }
            }
        }

        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3276
print((function ()
	local h = {}
	for i=1,tonumber(io.stdin:read("*l")) do
		local s = io.stdin:read("*l")
		if h[s] ~= nil then h[s] = h[s]+1 else h[s] = 1 end
	end
	for i=1,tonumber(io.stdin:read("*l")) do
		local s = io.stdin:read("*l")
		if h[s] ~= nil then h[s] = h[s]-1 else h[s] = -1 end
	end

	local r = 0
	for _,v in pairs(h) do if v > r then r = v end end
	return r
end)())

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

#include <stdio.h>
using namespace std;
long long F[100+1][100*1000+1];
long long MM = 1e9 + 7;

int main() {

  int N, K; // K < 1e5, N < 100

  cin >> N >> K;

  vector<int> A(N+1); // ai < K < 1e5

  for (auto i = 1; i <=N; i++) cin >> A.at(i);

  
  // F[i][j], 1..n..i, j total candies

  vector<long long> csum[2];
  csum[0] = vector<long long>(100*1000+1, 0);
  csum[1] = vector<long long>(100*1000+1, 0);
  int turn = 0;

  for (int j=0; j <= K; j++) {
    if (j <= A.at(1))  F[1][j] = 1; else F[1][j] = 0;
    if (j == 0) csum[1-turn].at(j) = F[1][j]; 
    else csum[1-turn].at(j) = (csum[1-turn].at(j-1) + F[1][j]) % MM;
  }

  for (int i=2; i <= N; i++) {
    turn = 1 - turn;
    for (int j=0; j <= K; j++) {
      int r = j; // candies
      int l = max(0, j - A.at(i));
      if (l==0) {
        F[i][j] = csum[turn].at(r);
      } else {
        F[i][j] = (csum[turn].at(r) - csum[turn].at(l-1) + MM) % MM;
      }

      if (j == 0) csum[1-turn].at(j) = F[i][j]; 
      else csum[1-turn].at(j) = (csum[1-turn].at(j-1) + F[i][j]) % MM;
    }
  }

  cout << F[N][K] << endl;
  return 0;
}

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

std :: map < int, int > cnt ;

int main ( )  {
	int n ;
	scanf ( "%d", & n ) ;

	for ( int i = 1 ; i <= n ; ++ i )  {
		static int x ;
		
		scanf ( "%d", & x ) ;
	
		++ cnt [x] ;
	}

	int ans ( 0 ) ;

	for ( std :: map < int, int > :: iterator it = cnt.begin ( ) ; it != cnt.end ( ) ; ++ it )  {
		ans += it -> second - it -> first >= 0 ? it -> second - it -> first : it -> second ;
	} 

	return ! printf ( "%d\n", ans ) ;
}


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

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

    if (n > k)
    {
        cout << x * k + y * (n - k) << endl;
    }
    else
    {
        cout << x * n << endl;
    }
}

Measured memory_bytes: 256
use std::fmt::Write;
use std::io::*;

fn main() {
	let input = {
		let mut buf = vec![];
		stdin().read_to_end(&mut buf);
		unsafe { String::from_utf8_unchecked(buf) }
	};
	let lines = input.split('\n');

	let mut table = vec![];

	for line in lines.take(2) {
		let mut iter = line.split(' ').map(|s| s.parse::<u32>().unwrap());
		let n = iter.next().unwrap() as usize;

		table.reserve(n);

		for _ in 0..n {
			let (h, m) = (iter.next().unwrap(), iter.next().unwrap());
			table.push(h * 60 + m);
		}
	}

	table.sort();
	table.dedup();

	let mut res = String::with_capacity(5 * table.len());
	for v in table {
		write!(res, "{}:{:02} ", v / 60, v % 60);
	}
	println!("{}", res.trim_right());
}



Measured memory_bytes: 5036
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    final int SHEEP_NUM = s.nextInt();
    final int WOLF_NUM = s.nextInt();

    if (SHEEP_NUM <= WOLF_NUM) {
        System.out.println("unsafe");
    } else {
        System.out.println("safe");
    }
  }
}

Measured memory_bytes: 35788
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    string s;
    int ac=0,wa=0,tle=0,re=0;
    for(int i=0;i<N;i++){
        cin>>s;
        if(s=="AC"){
            ac++;
        }
        else if(s=="WA"){
            wa++;
        }
        else if(s=="TLE"){
            tle++;
        }
        else{
            re++;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<ac<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<wa<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<tle<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<re;
}

Measured memory_bytes: 3612
def main(N,Y):
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            if 10000*i + 5000*j + 1000*k == Y:
                return i,j,k
    else:
        return -1,-1,-1

N,Y = map(int, input().split())
print(*main(N,Y))

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

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

	string S;
	cin >> S;

	vector<LL> white_ruiseki(N+1);
	for (int i = 1; i <= N; i++)
	{
		white_ruiseki[N - i] = white_ruiseki[N - i + 1];
		if (S[N-i] == '.') {
			white_ruiseki[N-i]++;
		}
	}

	vector<LL> black_ruiseki(N+1);
	for (int i = 1; i <= N; i++)
	{
		black_ruiseki[i] = black_ruiseki[i - 1];
		if (S[i-1] == '#') {
			black_ruiseki[i]++;
		}
	}

	LL ans = 1LL << 60;
	for (int i = 0; i <= N; i++)
	{
		chmin(ans, white_ruiseki[i] + black_ruiseki[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3844
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a==b&&b==c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21716
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
int main()
{
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin>>a>>b>>c;
	d=max(a,b);
	d=max(d,c);
	printf("%d\n",a+b+c-d);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define ANS 7

using namespace std;

int num[4];
bool FIND;
string res;

void dfs(int sum, string str) {
	if (!FIND) {
		int ind = str.length() + 1;
		if (ind == 4) {
			if (sum == ANS) {
				res = str;
				FIND = true;
			}
			return;
		}
		string temp1 = str+"+";
		dfs(sum+num[ind],temp1);
		string temp2 = str+"-";
		dfs(sum-num[ind],temp2);
	}
	return;
}

int main(void) {
	string str;
	cin >> str;
	for (int i = 0; i < 4; ++i) {
		num[i] = str[i] - '0';
	}
	res = "";
	FIND = false;
	dfs(num[0],"");
	res += "=";
	for (int i = 0; i < 4; ++i) {
		cout << str[i] << res[i];
	}
	cout << ANS << endl;
	return 0;
}


Measured memory_bytes: 256
A,B,C=input().split()
X=int(A)
Y=int(B)
Z=int(C)
def swap(a, b):
    temp = a
    a = b
    b = temp
    return a,b

X,Y= swap(X,Y)
X,Z= swap(X,Z)
print(X,Y,Z)

Measured memory_bytes: 3060
N = int(input())
C,S,F = [],[],[]
for i in range(N-1):
    c,s,f = map(int,input().split())
    C.append(c)
    S.append(s)
    F.append(f)
for i in range(N):
    j = i
    ans = 0
    while j < N-1:
        if ans < S[j]:
            ans = S[j]+C[j]
        else:
            if ans % F[j] == 0:
                ans = ans + C[j]
            else:
                ans = ans + (F[j] - (ans % F[j])) + C[j]
        j += 1
    print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vp;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

string strtoint(int p, int a) {
	string sp, sa;
	rep(i, 0, 6) {
		sp += char(p % 10 + '0'); p /= 10;
	}
	rep(i, 0, 6) {
		sa += char(a % 10 + '0'); a /= 10;
	}
	reverse(all(sp)); reverse(all(sa));
	return sp + sa;
}

int N, M;
vp Q[MAX_N];
string ans[MAX_N];

void solve() {
	cin >> N >> M;
	rep(i, 0, M) {
		int a, b; cin >> a >> b;
		Q[a].pb(pi(b, i));
	}
	for(int i = 1; i <= N; i++) {
		sort(all(Q[i]));
		rep(j, 0, sz(Q[i])) {
			pi p = Q[i][j];
			ans[p.sec] = strtoint(i, j + 1);
		}
	}
	rep(i, 0, M) cout << ans[i] << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

struct edge { int to,cost; };

const int MAX = 100001;
const int MOD = 1e9+7;
ll permutations[MAX+1];

void init() {
  permutations[0] = 1;
  permutations[1] = 1;
  FOR(i,2,MAX+1) {
    permutations[i] = permutations[i-1]*i%MOD;
  }
}

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

  if (abs(N-M)>1) {
    OUT(0);
    return 0;
  }

  if (N==M) {
    OUT(2*permutations[N]*permutations[M]%MOD);
  } else {
    OUT(permutations[M]*permutations[N]%MOD);
  }

  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		char[] ary = S.toCharArray();
		int A = 0;
		int B = 0;

		for(int i = 0; i < ary.length; i++) {
			if(ary[i] == 'A') {
				A = i;
				break;
			}
		}
		for(int j = ary.length-1; j > 0; j--) {
			if(ary[j] == 'Z') {
				B = j;
				break;
			}
		}
		System.out.println(B-A+1);
	}

}


Measured memory_bytes: 28628
#include<stdio.h>
#define MAX 100
#define INFTY 1e7
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n;
int m[MAX][MAX];
void dijkstra() 
{
    int minv;
    int d[MAX],color[MAX];
    for(int i = 0; i < n; i++ )
    {
        d[i] = INFTY;
        color[i] = WHITE;
    }
    d[0] = 0;
    color[0] = GRAY;
    while(1)
    {
        minv = INFTY;
        int u = -1;
        for( int i = 0 ; i < n; i++ )
        {
            if( minv > d[i] && color[i] != BLACK )
            {
                u = i;
                minv = d[i];
            }
        }
        if( u == -1 ) break;
        color[u] = BLACK;
        for(int v = 0; v < n; v++ )
        {
            if(color[v] != BLACK && m[u][v] != INFTY )
            {
                if(d[v] > d[u] + m[u][v])
                {
                    d[v] = d[u] + m[u][v];
                    color[v] = GRAY;
                }
            }
        }
    }
    for( int i = 0; i < n; i++ ) 
    {
        if(d[i] == INFTY) 
            printf("%d -1\n",i);
        else
            printf("%d %d\n",i, d[i]);
    }
}

int main() 
{
    scanf("%d",&n);
    for( int i = 0; i < n; i++ ) 
    {
        for(int j = 0; j < n; j++ )
        {
            m[i][j] = INFTY;
        }
    }
    int k, c, u, v;
    for( int i = 0; i < n; i++ )
    {
        scanf("%d %d ",&u,&k);
        for(int j= 0; j < k; j++ ) 
        {
            scanf("%d %d ",&v,&c);
            m[u][v] = c;
        }
    }
    dijkstra();
    return 0;
}


Measured memory_bytes: 2060
#!/usr/bin/perl

$line = 0;
while (<>) {
    chomp;
    if($line == 0) {
        $n = $_;
    } else {
        @a = split /\s+/, $_;
    }
    $line++;
}

foreach $a (@a) {
    if($a % 4 == 0) {
        $n4++;
    } elsif($a % 2 == 0) {
        $n2++;
    } else {
        $no++;
    }
}

if ($n % 2 == 0) {
    $d = $n / 2 - $n4;
    if($n / 2 <= $n4) {
        print "Yes\n";
    } elsif($d * 2 <= $n2) {
        print "Yes\n";
    } else {
        print "No\n";
    }
} else {
    $d = ($n - 1) / 2 - $n4;
    if(($n - 1)/ 2 <= $n4) {
        print "Yes\n";
    } elsif($d * 2 + 1 <= $n2) {
        print "Yes\n";
    } else {
        print "No\n";
    }
}


Measured memory_bytes: 17132
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		int sft[] = createSft();
		int cnt = 0;
		for(int i = 0; i < 30000; i++) {
			if(sft[i] <= n) cnt++;
			else break;
		}
		System.out.println(cnt);
	}
	int[] createSft() {
		int num[] = new int[30000];
		Arrays.fill(num, 1000000000);
		int idx = 0;
		for(int i = 3; i < 10; i++) {
			for(int j = 0; j < Math.pow(3, i); j++) {
				String s = CHSft(j, i);
				if(s.indexOf('3') >= 0 && s.indexOf('5') >= 0 && s.indexOf('7') >= 0) {
					num[idx] = Integer.parseInt(s);
					idx++;
				}
			}
		}
		return num;
	}
	String CHSft(int n, int d) {
		String s1 = "000000000" + Integer.toString(n, 3);
		String s2 = s1.substring(s1.length() - d);
		String s3 = s2.replace('2', '7');
		String s4 = s3.replace('1', '5');
		String s5 = s4.replace('0', '3');
		return s5;
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}


Measured memory_bytes: 38996
#include<stdio.h>
#include<iostream>
using namespace std;

int main(){

int N,A,B,X,C;
while(1){

cin>>N>>A>>B>>C>>X;
if(N==0&&A==0&&B==0&&C==0&&X==0)break;

int y[102]={};

for(int i=0;i<N;i++)
{
cin>>y[i];
}
int z[102]={};
int c=0;int d=(A*X+B)%C;
int h=0;d=X;bool f=true;
while(h<N){
	
	if(c>10000){c=-1;break;}
else if(d==y[h]&&f==true){z[h]=h;h++;f=false;}
else{f=true;
d=(A*d+B)%C;c++;
}
}/*
for(int i=0;i<N;i++)
{if(i>0)cout<<" ";
cout<<z[i];
}*/

cout<<c<<endl;
}
return  0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

class Data{
public:
	char name;
	int win{0},draw{0},lose{0};
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	while(true){
		int N=in();
		if(!N) break;

		vector<Data> T(N);
		REP(i,N){
			T[i].name=in<char>();
			REP(j,N-1){
				int v=in();
				if(!v) T[i].win++;
				else if(v==1) T[i].lose++;
				else T[i].draw++;
			}
		}
		sort(ALL(T),[](Data& l,Data& r){return l.win==r.win?l.lose<r.lose:l.win>r.win;});
		REP(i,N){
			out(T[i].name);
		}
	}
	return 0;
}



Measured memory_bytes: 3092
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;

ll num[8][8], dp[101][8];
ll h, w, k;

bool nth_bit(int n,int bit) {
	if ((bit >> n) & 1) {
		return true;
	}
	return false;
}

int main() {
	cin >> h >> w >> k;

	

	for (int bit = 0; bit < (1 << w - 1); bit++) {
		bool ok = 1;
		for (int i = 0; i < w-2; i++) {
			if (nth_bit(i, bit) && nth_bit(i + 1, bit)) {
				ok = 0;
			}
		}
		if (!ok) continue;

		vector<int> P(w);
		for (int i = 0; i < w; i++)P[i] = i;

		for (int i = 0; i < w - 1; i++) {
			if (nth_bit(i, bit)) {
				swap(P[i],P[i+1]);
			}
		}

		for (int i = 0; i < w;i++) {
			num[i][P[i]]++;
		}
	}

	dp[0][0] = 1;

	
	rep(i, 1, h+1) {
		rep(j, 0, w) {
			rep(k, 0, w) {
				dp[i][j] += (dp[i-1][k] * num[k][j])%MOD;
			}
		}
	}

	cout << dp[h][k-1] % MOD << endl;




	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int n,m,i,j;
	char s[1024][2][16],t[16];
	while(scanf("%d",&n) , n != 0){
		for(i = 1;i <= n;i++){scanf("%s%s",s[i][0],s[i][1]);}
		scanf("%d",&m);
		for(i = 1;i <= m;i++){
			scanf("%s",t);
			for(j = 1;j <= n;j++){
				if(s[j][0][0] == t[0]){printf("%c",s[j][1][0]);break;}
				if(j == n){printf("%c",t[0]);}
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 580
def main22():
    strbuf = input("");
    strbufs = strbuf.split();
    buf = [];
    for i in range(2):
        buf.append(int(strbufs[i]));
    strbuf = input("");
    strbufs = strbuf.split();
    buf2 = [];
    for i in range(buf[0]):
        buf2.append(int(strbufs[i]));
    if buf[0] == 2:
        if buf2[0] + buf2[1] >= buf[1]:
            print("Possible");
            print(1);
        else:
            print("Impossible");
    else:
        point = -1;
        for i in range((buf[0] - 1)):
            if buf2[i] + buf2[i+1] >= buf[1]:
                point = i+1;
                break;
        if point == -1:
            print("Impossible");
        else:
            print("Possible");
            if point != 1:
                for i in range(point-1):
                    print(i+1);
            if point != buf[0] - 1:
                for i in range(buf[0]-1,point,-1):
                    print(i);
            print(point);

if __name__ == '__main__':
    main22()

Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define ii pair<int, int>
#define fi first
#define sc second
using namespace std;

const int N = 1e5 + 5;

int d[N], v[N];
vector<int> adj[N];

int dfs(int i) {
	v[i] = 1;
	for (int j = 0; j < (int) adj[i].size(); j++) {
		int t = adj[i][j];
		if (v[t]) t = d[t] + 1; else t = dfs(t);
		d[i] = max(d[i], t);
	}
	return d[i] + 1;
}

int main() {
	int n, m; cin >> n >> m;
	ii s[N];
	for (int i = 1; i <= n; i++) {
		s[i].second = i;
	}
	for (int i = 1; i <= m; i++) {
		int u, v; cin >> u >> v;
		adj[v].push_back(u);
		s[u].first += 1;
	}
	sort(s + 1, s + n + 1);
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (!v[s[i].second]) {
			dfs(s[i].second);
			ans = max(ans, d[s[i].second]);
		}
	}
	cout << ans << '\n';
}

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

int main(){
  int d;
  cin >> d;
  
  if (d==22)
    cout << "Christmas Eve Eve Eve" << endl;
  else if(d==23)
    cout << "Christmas Eve Eve" << endl;
  else if(d==24)
    cout << "Christmas Eve" << endl;
  else if(d==25)
    cout << "Christmas" << endl;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

/*************** using variables **************/
int N, C;
vector<int> s, t, c;
int imos[200005][31];
int imos2[200005];
/**********************************************/

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

    cin >> N >> C;
    s.resize(N);
    t.resize(N);
    c.resize(N);
    REP(i, N) cin >> s[i] >> t[i] >> c[i];
    
    REP(j, 31) REP(i, 200005) imos[i][j] = 0;
    REP(i, 200005) imos2[i] = 0;

    REP(i, N){
        imos[s[i]*2][c[i]]++;
        imos[t[i]*2+1][c[i]]--;
    }

    REP(j, 31) REP(i, 200005){
        imos[i+1][j] += imos[i][j];
    }
    
    bool flag = false;
    REP(j, 31) REP(i, 200005){
        if(!flag && imos[i][j] == 1) {
            imos2[max(0, i-1)]++;
            flag = true;
        }else if(flag && imos[i][j] == 0){
            imos2[i]--;
            flag = false;
        }
    }

    REP(i, 200005){
        imos2[i+1] += imos2[i];
    }


    int ans = 0;
    REP(i, 200005){
        ans = max(ans, imos2[i]);
    }

    cout << ans << endl;


}


Measured memory_bytes: 26496
import * as fs from 'fs';


//in
// 4 150
// 150 140 100 200
//out
// 2
const main = (inp: string) => {
    const [n, k]: number[] = inp.split('\n')[0].split(' ').map(Number);
    const h: number[] = inp.split('\n')[1].split(' ').map(Number);
    let ans: number = 0;
    for (let i: number = 0; i < n; i++) {
        if (h[i] >= k)
            ans++;
    }
    console.log(ans);
};

main(fs.readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 16588
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

const int MAX = 2001; // change here as problems
const int MOD = 1000000007;

int64_t fac[MAX], inv[MAX], finv[MAX]; // arrays for factorial, inverse (mod p), and inverse of factorial, respectively

void table() {
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int64_t comb(int n, int k) {
    return fac[n] * finv[k] % MOD * finv[n - k] % MOD;
}

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k; cin >> n >> k;
    
    table();
    
    for (int i = 1; i <= k; i++) {
        if (k - i >= 0 && n - k + 1 >= i) cout << comb(n - k + 1, i) * comb(k - 1, k - i) % MOD << endl;
        else cout << 0 << endl;
    }
    
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  
  vector<int> v(n);
  for (int i=0; i<n; i++){
    cin >> v.at(i);
  }
  sort(v.begin(), v.end(), greater<int>());
  
  int alice = 0;
  int bob = 0;
  for (int i=0; i<n; i++){
    if (i%2 == 0){
      alice += v.at(i);
    } else {
      bob += v.at(i);
    }
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#define mem(a) memset(a, 0, sizeof(a))
using namespace std;
typedef pair<int, int> Pii;
typedef long long LL;
const int MAXN =100005;
const int inf = 0x3f3f3f3f;
const int Mod = 100000000;
int a[MAXN];
bool vis[MAXN];
int flag;
void dfs(int cur, int step)
{
    if(flag)
    {
        return;
    }
    vis[cur]=true;
    if(cur==2)
    {
        printf("%d\n", step);
        flag=2;
        return;
    }
    if(vis[a[cur]])
    {
        flag=1;
        return;
    }
    dfs(a[cur], step+1);
}
int main()
{
    int n;
    scanf("%d", &n);
    for(int i=1;i<=n;++i)
        scanf("%d", &a[i]);
    memset(vis, false, sizeof(vis));
    flag=0;
    dfs(1, 0);
    if(flag==1)
        printf("-1\n");
    return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout<<fixed;

    #ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    #endif // _DEBUG

    int n, k;
    cin >> n >> k;
    vector<double> v(n);
    cin >> v[0];
    v[0] = (v[0] + 1.0) / 2.0;
    for (int i = 1; i < n; ++i) {
        cin >> v[i];
        v[i] = (v[i] + 1.0) / 2.0;
        v[i] += v[i-1];
    }
    double ans = v[k-1];
    for (int i = k; i < n; i++) {
        double sum = v[i] - v[i-k];
        ans = max(ans, sum);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1792
import heapq

x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort(reverse=True)
b.sort(reverse=True)
c.sort(reverse=True)

registered = set()
pool = []

heapq.heappush(pool, (-(a[0] + b[0] + c[0]), (0, 0, 0)))
registered.add((0, 0, 0))

for rank in range(k):
    value, (i, j, k) = heapq.heappop(pool)
    print(-value)
    if i + 1 < x and (i + 1, j, k) not in registered:
        heapq.heappush(pool, (-(a[i + 1] + b[j] + c[k]), (i + 1, j, k)))
        registered.add((i + 1, j, k))
    if j + 1 < y and (i, j + 1, k) not in registered:
        heapq.heappush(pool, (-(a[i] + b[j + 1] + c[k]), (i, j + 1, k)))
        registered.add((i, j + 1, k))
    if k + 1 < z and (i, j, k + 1) not in registered:
        heapq.heappush(pool, (-(a[i] + b[j] + c[k + 1]), (i, j, k + 1)))
        registered.add((i, j, k + 1))



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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector< vector< ul > > path(n, vector< ul >(0));
  for (ul i=0; i<m; ++i) {
    ul u, v;
    cin >> u >> v;
    u--; v--;
    path[u].push_back(v);
  }
  ul s, t;
  cin >> s >> t;
  s--; t--;
  vector< vector< bool > > v(3, vector< bool >(n, false));
  priority_queue< tuple< ul, ul >, vector< tuple< ul, ul > >, greater< tuple< ul, ul > > > q;
  q.push(make_tuple(0, s));
  while (!q.empty()) {
    auto tp = q.top();
    q.pop();
    ul step = get<0>(tp), idx = get<1>(tp);
    if (v[step%3][idx]) continue;
    v[step%3][idx] = true;
    if (step%3==0 && idx == t) {
      cout << step/3 << endl;
      return 0;
    }
    for (auto c : path[idx]) q.push(make_tuple(step+1, c));
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 7412
import sys
input = sys.stdin.readline
N = int(input())
a = list(map(int, input().split()))
mx = max(a)
table = [0] * (mx + 1)
for x in a: table[x] += 1
#print(table)
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors

res = set(a)
#print(res)
for i in range(1, mx + 1):
  if table[i] == 0: continue
  for j in range(i, mx + 1, i):
    if i == j:
      if table[j] > 1:
        res.discard(j)
      continue
    if table[j]: res.discard(j)
print(len(res))

Measured memory_bytes: 119196
using System;

namespace Exawizards_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            if (a == b && b == c)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF 1145141919
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(bit)

using namespace std;

int main(void){
  string S;
  long long int ans=0,keisu=1;
  cin >> S;
  int L=S.length();
  for(int i=0;i<Flag(L-1);i++){
    keisu=1;
    ans+=(S[L-1]-'0');
    for(int j=1;j<L;j++){
      if(i&Flag(j-1)) keisu*=10;
      else keisu=1;
      ans+=(S[L-j-1]-'0')*keisu;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] s = br.readLine().split(" ");
		int[] S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = Integer.parseInt(s[i]);
		}
		margeSort(S, 0, n);
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append(S[i]).append((i != n - 1) ? " " : "\n");
		}
		sb.append(count).append("\n");
		System.out.print(sb);
	}
	public static int count = 0;
	public static void marge(int[] A, int left, int middle, int right) {
		int n1 = middle - left;
		int n2 = right - middle;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for (int i = 0; i < n1; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = A[middle + i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		for (int k = left; k < right; k++) {
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
			}
			count++;
		}
	}
	public static void margeSort(int[] A, int left, int right) {
		if ((left + 1) < right) {
			int middle = (left + right) / 2;
			margeSort(A, left, middle);
			margeSort(A, middle, right);
			marge(A, left, middle, right);
		}
	}
}

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

int main(){
	int n, a[100], i;
	cin>>n;
	for(i=n-1;i>=0;i--){
		cin>>a[i];
	}
	for(i=0;i<n;i++){
		cout<<a[i];
		if(i!=n-1){
			cout<<' ';
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1160
N=int(input())
H=list(map(int, input().split()))
D=[0 for i in range(N+1)]
#D[i]をiまでで、最短コストとなるやりかたとする。
if N==1:
    D[N]=0
if N==2:
    D[N]=abs(H[1]-H[0])
if N>2:
    for i in range(N+1):
        if i==0:
            D[i]=0
        if i==1:
            D[i]=0
        if i==2:
            D[i]=abs(H[1]-H[0])
        if i>2:
            D[i]=min((D[i-2]+abs(H[i-1]-H[i-3])) , (D[i-1]+abs(H[i-1]-H[i-2])))
print(D[N])

Measured memory_bytes: 13776
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int k = sc.nextInt();
		
		// 計算
		int result = 0;
		result = k/2 * ((k + 1)/2);
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  string s;
  cin >> s;
  bool can = false;
  for (int i=0; i<s.size(); i++) {
    if (s[i]=='C') {
      for (int j=i+1; j<s.size(); j++) {
        if (s[j]=='F') {
          can = true;
          break;
        }
      }
    }
    if (can) break;
  }
  if (can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
using namespace std;

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

  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }

  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, s, n) for(int i = s; i < n; i++)
#define rrep(i, s, n) for(int i = s; i > (s)-(n); i--)
#define pr(s) std::cout << s << std::endl
#define prb(s) std::cout << s
using namespace std;



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


  int n, a;
  cin >> n >> a;

  if (n%500 <= a) pr("Yes");
  else pr("No");


  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
X = sorted(list(map(int, input().split())))

h = []
ans = 0

if N < M:
    for i in range(M-1):
        h.append(X[i+1] - X[i])
    h = sorted(h)
    ans = max(ans, sum(h[:M - N]))

print(ans)

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

N = int(input())
A = list(map(int, input().split()))

ans = 0
sumA = 0
sumA_2 = 0
for i in A:
    sumA = (sumA + i) % MOD
    sumA_2 = (sumA_2 + i**2 ) % MOD

ans = (sumA * sumA - sumA_2) % MOD

if ans % 2 == 0:
    print(ans//2)
else:
    print((ans + MOD) // 2)

Measured memory_bytes: 31432
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y,h2,m2;
	ll		ans = 0;
	string	s;
	cin >> h >> m >> h2 >> m2 >> k;
	a = h*60+m;
	b = h2*60+m2;
	ans = b - a - k;
	//vector<ll>	aa(n);
	//for(i=0;i<n;i++) cin >> aa[i];
	//vector<ll>	dp(n+1,INFL);
	//vector<vector<ll>>	dp2(x , vector<ll>(y,INFL));

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


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

int main(){
    int x,y,i,j; char c;
    cin>>x>>y;
    for(i=0;i<=x+1;i++){
        for(j=0;j<=y+1;j++){
            if(i==0||i==x+1) cout<<'#';
            else if(j==0||j==y+1) cout<<'#';
            else {
                cin>>c; cout<<c;
            }
        }
        cout<<'\n';
    }
	return 0;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int main() {
   int n;
   string s;
   cin >> n >> s;
   string t = "";
   int ans = 0;
   for (int i = 0; i < n-1; i++) {
      t += s[i];
      int a[30] = {0};
      for (char c : t) a[c-'a']++;
      string x = s.substr(i+1, n);
      int b[30] = {0};
      for (char c : x) b[c-'a']++;

      int sum = 0;
      rep (k, 26) {
         if (a[k] && b[k]) sum++;
      }
      ans = max(ans, sum);
   }
   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, [graph1; $len:expr]) => {{
        let mut g = vec![vec![]; $len];
        let ab = read_value!($next, [(usize1, usize1)]);
        for (a, b) in ab {
            g[a].push(b);
            g[b].push(a);
        }
        g
    }};
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => (read_value!($next, usize) - 1);
    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        read_value!($next, [$t; len])
    }};
    ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error"));
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        x: i64, k: i64, d: i64,
    }
    let mut x = x.abs();
    if k % 2 == 1 {
        x = (x - d).abs()
    }
    let q = min(k / 2, x / (2 * d));
    let q1 = min(k / 2, x / (2 * d) + 1);
    puts!("{}\n", min((x - q * 2 * d).abs(), (x - q1 * 2 * d).abs()));
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 2280
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector <int> p(n);
    vector <int> dp(n);
    int currentMin = n+1;
    int ans = 0;

    for(int i = 0; i < n; i++){
        cin >> p[i];
        currentMin=min(currentMin,p[i]);
        dp[i]=currentMin;
        //cout << p[i] << " " << dp[i] << endl;
        if(dp[i]>=p[i]){
            ans++;
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4844
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
    char c;
    cin >> c;
    cout << ((c >= 'a' && c <= 'z') ? 'a' : 'A') << endl;
    return 0;
}

Measured memory_bytes: 3616
N = int(input())
X = [0] * (N + 1)
for i in range(1, 101):
    for j in range(1, 101):
        for k in range(1, 101):
            a = i ** 2 + j ** 2 + k ** 2 + i * j + j * k + i * k
            if a <= N:
                X[a] += 1
for a in X[1:]:
    print(a)

Measured memory_bytes: 9376
#include<stdio.h>
#define MAX 100005
#define NIL -1

/*
 p: parent
 l: left-child
 r: right sibling
 */
struct Node{ int p, l, r;};
struct Node T[MAX]; // Tree
int n;
/*

 ...

 */

int getDepth(int u){
  int d = 0, i;
  for(i=u; T[i].p!=NIL; i=T[i].p, d++);
  return d;
}

void print(int u){
  int b=getDepth(u), c=T[u].l;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, b);
  if(b==0) printf("root, ");
  else if (T[u].l!=NIL) printf("internal node, ");
  else printf("leaf, ");
  printf("[");
  if(T[u].l==NIL)
    printf("]\n");
  else {
    while(1){
      printf("%d", c);
      if(T[c].r==NIL){
	printf("]\n");
	break;
      }
      else printf(", ");
      c=T[c].r;
    }
  }

 /*

...
...
...

   */
}

main(){
  int i, j, d, v, c, l, a;

  scanf("%d", &n);

  for ( i = 0; i < n; i++ ) {
    T[i].p = T[i].l = T[i].r = NIL; //NIL = 空の設定値
  }

  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &v, &d);
    for ( j = 0; j < d; j++ ){
      scanf("%d", &c);
      T[c].p=v;
      if(j==0) 
	T[v].l=c;
      else T[a].r=c;
      a=c;
    }
  }
  



  /*

    ...

   */

  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, M; cin >> N >> M;
	vi occ (N);
	F0R(i, M) {
		int a, b; cin >> a >> b; --a; --b;
		occ[a]++; occ[b]++;
	}
	bool fail = false;
	F0R(i, N) if (occ[i] % 2 == 1) fail = true;
	if (fail) {
		print("NO");
	} else {
		print("YES");
	}
}

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

int main()
{
	int N;
	cin >> N;
	for (int a = 1; a <= 9; ++a)
	{
		for (int b = a; b <= 9; ++b)
		{
			if (a*b == N)
			{
				cout << "Yes";
				return 0;
			}
		}
	}
	cout << "No";
}


Measured memory_bytes: 256
A = int(input())
B = int(input())

if (A == 1 and B == 2) or (A == 2 and B == 1):
    print(3)

if (A == 1 and B == 3) or (A == 3 and B == 1):
    print(2)

if (A == 3 and B == 2) or (A == 2 and B == 3):
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h> 
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;

int main(){
    int a,b;
    cin>>a>>b;
    if(b==1){
        cout<<0<<endl;
        return 0;
    }
    int sum=a;
    int i=1;
    while(sum<b){
        sum+=(a-1);
        ++i;
    }
    cout<<i<<endl;
}

Measured memory_bytes: 3620