akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>

using namespace std;

char m[102][102];
int w, h;

void dfs(char s, int x, int y) {
    if (m[x][y] == s) {
        m[x][y] = '!';
        dfs(s, x + 1, y);
        dfs(s, x - 1, y);
        dfs(s, x, y + 1);
        dfs(s, x, y - 1);
    }
}

bool solve() {
    cin >> h >> w;
    if (w == 0 && h == 0) {
        return false;
    }
    string temp;
    for (int i = 0; i < 102; i++) {
        for (int j = 0; j < 102; j++)
            m[i][j] = '!';
    }
    for (int i = 0; i < h; i++) {
        cin >> temp;
        for (int j = 0; j < w; j++) {
            m[j + 1][i + 1] = temp[j];
        }
    }
    int count = 0;
    for (int x = 1; x <= w; x++) {
        for (int y = 1; y <= h; y++) {
            if (m[x][y] != '!') {
                count++;
                dfs(m[x][y], x, y);
            }
        }
    }
    cout << count << endl;
    return true;
}

int main(void) {
    while (solve());
}


Measured memory_bytes: 3332
using System;
using System.Linq;

    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var result = "";
            while (N!=0)
            {
                if(N%2!=0)
                {
                    N--;
                    result = "1"+result;
                }
                else
                {
                    result = "0" + result;
                }
                N /= -2;
            }
            if (!result.Any()) result = "0";
            Console.WriteLine(result);
        }
    }

Measured memory_bytes: 11220
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

const int INF = 10000000;
using namespace std;
typedef long long  ll;
const int MAX = 10000;

/** Problem0200 : Traveling Alone : One-way Ticket of Youth **/
int costG[100][100];
int timeG[100][100];

int main()
{
	int n, m, a, b, c, t;
	
	while (cin >> n >> m, n!=0 && m!=0) {
		rep(i, 100) {
			rep(j, 100) {
				costG[i][j]=INF;
				timeG[i][j]=INF;
			}
		}
		
		rep(k, n) {
			cin >> a >> b >> c >> t;
			a--; b--;
			costG[a][b] = c;
			costG[b][a] = c;
			timeG[a][b] = t;
			timeG[b][a] = t;
		}
		
		rep(k, m) {
			rep(i, m) {
				rep(j, m) {
					costG[i][j] = min(costG[i][j], costG[i][k]+costG[k][j]);
					timeG[i][j] = min(timeG[i][j], timeG[i][k]+timeG[k][j]);
				}
			}
		}
		
		int k, p, q, r;
		cin >> k;
		rep(i, k) {
			cin >> p >> q >> r;
			p--; q--;
			if (r==0) {
				cout << costG[p][q] << endl;
			} else {
				cout << timeG[p][q] << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1236
N = int(input())
A = list(map(int,input().split()))
X = list(map(abs,A))

s = sum(X)
count = 0
for a in A:
    if a < 0:
        count += 1

if count % 2 == 0:
    print(s)
else:
    print(s - 2 * min(X))

Measured memory_bytes: 14332
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
using namespace std;
using namespace __gnu_pbds;

#define sp << " " <<
#define mod 1000000007
#define PI 3.14159265358979323
#define y second
#define x first
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define pqueue priority_queue< ll >
//#define pdqueue priority_queue< ll,vector<ll> ,greater< ll > >
#define codejamDebug(x) cout<<"Case #"<<x<<": ";
#define debug(x) cout<<"Case "<<x<<": "
#define rep(i,n) for(long long i=0;i<n;i++)
#define f(i,a,b) for(long long i = a; i < b; i++)
#define fd(i,a,b) for(long long i = a; i >=b; i--)
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long int           ll;
typedef long double             ld;
typedef unsigned long long int ull;
typedef vector <int>            vi;
typedef vector <ll>            vll;
typedef pair <int, int>        pii;
typedef pair <ll, ll>          pll;
typedef vector < pii >        vpii;
typedef vector < pll >        vpll;
typedef vector <string>         vs;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//Handle:cyber_rajat

int main(int argc, char const *argv[])
{
	sync;
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/
	ll A,B,C,D;
	cin>>A>>B>>C>>D;
	ll q1=A/C;
	ll r1=A%C;
	ll q2=B/C;
	ll ans1=q2-q1;
	if(r1==0)ans1++;

	ll p1=A/D;
	ll rr1=A%D;
	ll p2=B/D;
	ll ans2=p2-p1;
	if(rr1==0)ans2++;

	ll lcm=(C*D)/__gcd(C,D);

	ll l1=A/lcm;
	ll lq1=A%lcm;
	ll l2=B/lcm;
	ll ansl=l2-l1;
	if(lq1==0)ansl++;
	//cout<<lcm sp ansl sp ans1 sp ans2<<endl;
	cout<<B-A+1-(ans1+ans2-ansl)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,a,b;
int main()
{
    cin >> n >> a >> b;
    if((b-a)%2==0){
        cout<<"Alice";
        return 0;
    }
    if((b-a)%2==1){
        cout<<"Borys";
        return 0;
    }
    
    
    
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    if (n % 2 == 0){
        cout << "0.50000000000" << endl;
        return 0;
    }
    double a = n;
    double b = (n+1)/2;
    cout << setprecision(20);
    cout << b / a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

int main(){
    vector<int> A(9);
    for(int i=0;i<9;i++){
        cin>>A[i];
    }
    int N;
    cin>>N;

    int b;
    vector<int> C(9,0);
    for(int i=0;i<N;i++){
        cin>>b;
        for(int j=0;j<9;j++){
            if(A[j]==b){
                C[j]=1;
            }
        }
    }
    /*
    for(auto p:C){
        cout<<p<<" ";
    }
    cout<<endl;
    //*/

    int ans=0;
    if(C[0]*C[1]*C[2]+C[3]*C[4]*C[5]+C[6]*C[7]*C[8]){
        ans=1;
    }
    if(C[0]*C[3]*C[6]+C[1]*C[4]*C[7]+C[2]*C[5]*C[8]){
       ans=1; 
    }
    if(C[0]*C[4]*C[8]+C[2]*C[4]*C[6]){
        ans=1;
    }
    if(ans){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#define X 100000

typedef struct{
  int p,l,r;
}N;

N T[X];
int n, D[X];

void print(int);
int rec(int, int);

int main(){

  int i,j,ne,d,v,c,l;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    T[i].p = T[i].l = T[i].r = -1;

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

  for(i=0;i<n;i++)
    if(T[i].p == -1) ne=i;

  rec(ne,0);
  for(i=0;i<n;i++)
    print(i);

  return 0;
}

void print(int x){
  int i,c;

  printf("node %d: parent = %d, depth = %d, ",x,T[x].p,D[x]);

  if(T[x].p == -1)
    printf("root, [");

  else if(T[x].l == -1)
    printf("leaf, [");

  else printf("internal node, [");

  for(i=0,c=T[x].l; c!=-1; i++,c=T[c].r){
    if(i)printf(", ");
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int a,int b){

  D[a] = b;
  if(T[a].r != -1) rec(T[a].r,b);
  if(T[a].l != -1) rec(T[a].l,b+1);
}



Measured memory_bytes: 6476
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0;i<N;i++) {
            A[i] = sc.nextInt();
        }

        if (N%2==0) {
            // long tmp_1 = 0L;
            // long tmp_2 = 0L;
            // for (int i=0;i<N;i++) {
            //     if (i%2==0) tmp_1+=A[i];
            //     else tmp_2+=A[i];
            // }
            // System.out.println(Math.max(tmp_1, tmp_2));

            long[][] dp = new long[N][2];
            long INF = 2_000_000_000_000_000_000L;
            for (int i=0;i<N;i++) {
                for (int j=0;j<2;j++) {
                    dp[i][j] = -INF;
                }
            }
            dp[0][0] = A[0];
            dp[0][1] = 0L;
            dp[1][1] = A[1];
            for (int i=1;i<N;i++) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][0]);
                if (i-2>=0) {
                    dp[i][0] = Math.max(dp[i][0], dp[i-2][0]+A[i]);
                    dp[i][1] = Math.max(dp[i][1], dp[i-2][1]+A[i]);
                }
            }
            long ans = dp[N-1][0];
            ans = Math.max(ans, dp[N-1][1]);
            System.out.println(ans);
        } else {
            long[][] dp = new long[N][3];
            long INF = 2_000_000_000_000_000_000L;
            for (int i=0;i<N;i++) {
                for (int j=0;j<3;j++) {
                    dp[i][j] = -INF;
                }
            }
            dp[0][0] = A[0];
            dp[0][1] = 0L;
            dp[0][2] = 0L;
            dp[1][1] = A[1];
            for (int i=1;i<N;i++) {
                dp[i][1] = Math.max(dp[i][1], dp[i-1][0]);
                dp[i][2] = Math.max(dp[i][2], dp[i-1][1]);
                if (i-2>=0) {
                    dp[i][0] = Math.max(dp[i][0], dp[i-2][0]+A[i]);
                    dp[i][1] = Math.max(dp[i][1], dp[i-2][1]+A[i]);
                    dp[i][2] = Math.max(dp[i][2], dp[i-2][2]+A[i]);
                }
            }
            System.out.println(dp[N-1][2]);
        }
    }
}


Measured memory_bytes: 65664
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
vector<int>pat[100000];
bool flag[100000];
int dfs(int node)
{
	if (flag[node])return -1;
	flag[node] = true;
	int ans = 0;
	for (int i = 0; i < pat[node].size(); i++)ans ^= dfs(pat[node][i]) + 1;
	return ans;
}
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0; i < num - 1; i++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--, zb--;
		pat[za].push_back(zb);
		pat[zb].push_back(za);
	}
	if (dfs(0) == 0)printf("Bob\n");
	else printf("Alice\n");
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;


int main() {

    ll a, b;
    cin >> a >> b;

    if(a + b == 15){
        cout << "+" << endl;
    }else if(a * b == 15){
        cout << "*" << endl;
    }else{
        cout << "x" << endl;
    } 

}

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

//bfs

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

  vector<set<int>> Hai(N);
  vector<set<int>> rHai(N);

  rep(i,N-1){
    int x,y;
    cin >> x >> y;
    Hai.at(x-1).insert(y-1);
    rHai.at(y-1).insert(x-1);
  }

  vector<int> counter(N,0);

  rep(i,Q){
    int p,x;
    cin >> p >> x;
    counter.at(p-1) += x;
  }

  vector<bool> Ok(N,false);
  queue<int> q;
  q.push(0);

  while(! q.empty()){
    int a = q.front();
    Ok.at(a) = true;

    for(auto val : Hai.at(a)){
      if(Ok.at(val) == false){
        q.push(val);
        counter.at(val) += counter.at(a);
      }
    }
    for(auto val : rHai.at(a)){
      if(Ok.at(val) == false){
        q.push(val);
        counter.at(val) += counter.at(a);
      }
    }

    q.pop();

  }


  rep(i,N){
    cout << counter.at(i) << " ";
  }

  cout << endl;



 
}


Measured memory_bytes: 41344
void main() {
	auto N = ri;
	auto S = rs;
	ulong res = ulong.max;
	auto A = new int[](N);

	// i番目含め左から今までのWの個数
	A[0] = S[0] == 'W';
	foreach(i; 1..N) A[i] = S[i] == 'W' ? A[i-1]+1 : A[i-1];

	// i番目含め左から今までのEの個数
	// C[i] = (i+1) - A[i];
	// 下二行はどちらも同じ結果をもつ

	//auto C = iota(1, N+1).map!(a => a - A[a-1]).array;
	// auto C = iota(N).map!(a => (a+1) - A[a]).array;
	auto C = (int n) {
		return n+1 - A[n];
	};

	foreach(i; 0..N) {
		ulong tmp;
		tmp += C(N-1) - C(i); // リーダーより右でEを向いている人の数
		tmp += i < 1 ? 0 : A[i-1]; // リーダーより左でWを向いている人の数
		res = min(res, tmp);
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  int x=m/n;//最も効率が良い＝すべて等しいときを超える答えはない
  while(true){
    int temp=m-x*n;//これでnこの数がtemp+x,x,x,x,,,となる
    //cout<<x<<" "<<temp<<endl;
    if(temp%x==0) break;
    x--;
    if(x==1)  break;
  }
  cout<<x<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;
typedef long long int llint;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	char s[110];
	cin >> s;
	if (strlen(s) < 4) {
		cout << "No" << endl;
		return 0;
	}
	if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I') {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
/*
        karmany evadhikaras te
        ma phalesu kadacana 
        ma karma-phala-hetur bhur
        ma re sango'stv akarmani (B.G.-2.47)
 
Translation:
        Lord Krsna to Arjuna.
You have a right to perform your prescribed duty, 
but you are not entitled to the fruits of action. 
Never consider yourself the cause of the results of your activities, 
and never be attached to not doing your duty.    
*/
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define int long long
const int N = 200005;
const ll mod = 2000000011;
#define ld long double
#define PI 3.14159265358979323846
const int INF = 10000000;

void flash()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(2);
}

//3. Structure or classes
//3. Ends here

//1. Data structures declaration here
vector<int>c;
vector<vector<int> >a;
int n,m,x;
//1. Ends here

//2. Extra Functions here

//2. Ends here


void solve();
int32_t main()
{
    flash();
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
        //cout<<"\n";
    }
    return 0;
}

void solve()
{
    cin>>n>>m>>x;

    a.resize(n,vector<int>(m));
    c.resize(n);
    

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

    int all = 1<<n;

    int minCost=1e9;

    for(int mask=0;mask<all;mask++){
        vector<int>rev(m);
        int cost=0;

        for(int i=0;i<n;i++){
            if((mask>>i)&1){
                cost+=c[i];
                for(int j=0;j<m;j++){
                    rev[j]+=a[i][j];
                }
            }
        }

        bool ok=1;
        for(int i=0;i<m;i++){
            if(rev[i]<x){
                ok=0;
                break;
            }
        }

        if(ok==1){
            minCost=min(minCost,cost);
        }
    }

    if(minCost==1e9){
        cout<<-1<<"\n";
    }
    else cout<<minCost<<"\n";

    return;

}
// how r u bro

Measured memory_bytes: 3632
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

bool vel(V<ll> &dists, const VV<PLL> &edges) {
    ll N = dists.size();
    for(ll i__ = 0; i__ <= 2 * N; i__++) {
        bool update = false;
        for(ll i = 0; i < N; i++) {
            for(auto &&edge : edges[i]) {
                ll nxt, cost;
                tie(nxt, cost) = edge;
                ll cur_d = dists[nxt];
                ll update_d = dists[i] + cost;
                if(update_d < cur_d) {
                    if(nxt == N - 1) update = true;
                    dists[nxt] = update_d;
                }
            }
        }
        if(i__ >= N && update) return false;
    }
    return true;
}

int main() {
    ll N, M, P;
    cin >> N >> M >> P;
    VV<PLL> edges(N);
    for(ll i = 0; i < M; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        edges[a].emplace_back(b, P - c);
    }

    V<ll> dists(N, inf);
    dists[0] = 0;
    bool ok = vel(dists, edges);
    DEBUG(dists);
    if(ok) cout << max<ll>(0, -dists[N - 1]) << endl;
    else cout << -1 << endl;
    return 0;
}


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

int main(){
	int gx, gy, p, count;
	int x1, x2, y1, y2;
	int map[16][16], right[16][16], down[16][16];
	for(cin >> count;count>0;count--){
		cin >> gx >>gy;
		cin >> p;
		for(int i=0; i<16; i++){
			for(int j=0; j<16; j++) map[i][j]=0, right[i][j]=1, down[i][j]=1;
		}
		for(int i=0; i<p; i++){
			cin >> x1 >> y1 >> x2 >> y2;
			if(y1==y2) right[max(x1, x2)][y1]=0;
			if(x1==x2) down[x1][max(y1,y2)]=0;
		}
		map[0][0] = 1;
		for(int y=0; y<=gy; y++){
			for(int x=0; x<=gx; x++){
				if(x!=0){
					if(right[x][y]) map[x][y]+=map[x-1][y];
				}
				if(y!=0){
					if(down[x][y]) map[x][y]+=map[x][y-1];
				}
			}
		}
		if(map[gx][gy]==0) cout << "Miserable Hokusai!" << endl;
		else cout << map[gx][gy] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
 
#define rp(i, k, n) for (int i = k; i < n; i++)
using ll = long long;
using ld = double;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
// const ll MOD = 998244353;
const double PI=3.14159265358979323846;



int main() {
    string s; cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n+10, vector<ll>(2));
    dp[0][1] = 1;
    rp(i, 0, n) {
        int m = s[i] - '0';
        dp[i+1][0] = min(dp[i][1] + (10 - m), dp[i][0] + m);
        dp[i+1][1] = min(dp[i][1] + (10 - m - 1), dp[i][0] + (m+1));
    }
    cout << dp[n][0] << endl;
    return 0;
}


Measured memory_bytes: 58896
#include<bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

int n,k;
const int N=1e5+5;
int has[N],h[N];
int rec(int curr){
	if(curr>n)return 1e10;
	if(curr==n)return 0;
	int &ans=has[curr];
	if(ans!=-1)return ans;
	ans=1e10;
	for(int i=1;i<=k && i+curr<=n;i++){
         ans=min(ans,abs(h[curr]-h[curr+i])+rec(curr+i));
    }
    return ans;

}
int32_t main() {
     IOS;
	cin>>n>>k;
	memset(has,-1,sizeof(has));
    for(int i=1;i<=n;i++){
		cin>>h[i];
	}
//	n--;
	cout<<rec(1);
	return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

ll n,k,c,id;
vector<ll> G[100002];
vector<ll> p,dep,s,deg,hei;
ll mdepth = 0;
bool did[100002];

void print(ll i){
	cout << "node " << i << ": ";
	cout << "parent = " << p[i];
	cout << ", sibling = " << s[i];
	cout << ", degree = " << deg[i];
	cout << ", depth = " << dep[i];
	cout << ", height = " << hei[i] << ", ";
	if(p[i]==-1){
		cout << "root\n"; 
	}else if(G[i][0]+G[i][1] == -2){
		cout << "leaf\n";
	}else{
		cout << "internal node\n";
	}
}


void dfs(ll from){
	if(G[from][0]!=-1 && G[from][1]!=-1){
		s[G[from][0]] = G[from][1];
		s[G[from][1]] = G[from][0];
	}
	for(auto to:G[from]){
		if(to>=0 && !did[to]){
			did[to] = true;
			p[to] = from;
			dep[to] = dep[from] + 1;
			mdepth = max(mdepth,dep[to]);
			dfs(to);
		}
	}
}

void calc_h(){
	FOR(i,0,n){
		if(G[i][0]+G[i][1] == -2){
			ll now=i,h=0;
			while(now>=0){
				hei[now] = max(hei[now],h);
				h++;
				now = p[now];
			}
		}
	}
}



int main () {
	cin >> n;
	if(n==1){
		cout << "node 0: parent = -1, sibling = -1, degree = 0, depth = 0, height = 0, root" << endl;
		return 0;
	}
	deg.resize(n,0);
	FOR(i,0,n){
		cin >> id;
		G[id].resize(2);
		cin >> G[id][0] >> G[id][1];
		FOR(j,0,2){
			deg[id] += (G[id][j]>=0);
		}
	}

	ll root = -1;
	FOR(i,0,n){
		for(auto ch:G[i]){
			did[ch] = true;
		}
	}
	FOR(i,0,n)if(!did[i])root = i;
	
	memset(did,0,sizeof(did));
	p.resize(n,-1);
	s.resize(n,-1);
	dep.resize(n,0);
	hei.resize(n,0);

	did[root] = true;
	dfs(root);
	calc_h();

	FOR(i,0,n){
		print(i);
	}
	


}


Measured memory_bytes: 5560
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int a[100005],b[100005];
int main()
{
 int A,B,M;
 int ans,mina=1e9,minb=1e9;
 cin>>A>>B>>M;
 for(int i=1;i<=A;i++)
 {
  cin>>a[i];
  mina=min(mina,a[i]);
 }
 for(int i=1;i<=B;i++)
 {
  cin>>b[i];
  minb=min(minb,b[i]);
 }
 ans=mina+minb;
 for(int i=1;i<=M;i++)
 {
  int x,y,c;
  cin>>x>>y>>c;
  ans=min(ans,a[x]+b[y]-c);
 }
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 1024
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;
    ll n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    cin>>n;
    ll a[n-1], b[n-1], c[n-1];
    for(i=0; i<n-1; i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    for(i=0; i<n-1; i++){
        s=b[i]+a[i];
        for(j=i+1; j<n-1; j++){
            if(s>b[j]){
                k=s/c[j];
                if(k*c[j]!=s){
                    h=(k+1)*c[j]-s;
                    s+=h;
                    s+=a[j];
                }
                else{
                    s+=a[j];
                }
            }
            else{
                k=b[j]-s;
                s+=k;
                s+=a[j];
            }
        }
        cout<<s<<endl;
    }
    cout<<0<<endl;

    return 0;
}



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



char ara[4];
char art[4];

int main()
{

    for(int i=0;i<=2;i++)
    {
        scanf("%c",&ara[i]);
    }


    if(ara[1]=='B')
     ara[1]='R';

    else
        ara[1]='B';

    printf("%s\n",ara);

}


Measured memory_bytes: 1572
h,w,a,b = map(int,input().split())

for i in range(h):
    if i<b:
        for k in range(a):
            print(1,end='')
        for l in range(w-a):
            print(0,end='')
        print()
    if i>=b:
        for k in range(a):
            print(0,end='')
        for l in range(w-a):
            print(1,end='')
        print()


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

const int mod = 1e9+7;
int dp[1<<21];

int main() 
{
	int n;
	scanf("%d", &n);
	vector<vector<int>> v(n+1, vector<int>(n+1));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			scanf("%d", &v[i][j]);
		}
	}
	dp[0] = 1;
	for(int i = 0; i < (1<<n); i++) {
		bitset<32> bit_(i);
		int one = bit_.count();
		for(int j = 0; j < n; j++) {
			if(v[one][j] == 1) {
				if(!(i&(1<<j))) {
					dp[(1<<j)|i] += dp[i];
					dp[(1<<j)|i] %= mod;
					// printf("___dp[(1<<j)|i] : %d___ : %d\n", dp[(1<<j)|i], (1<<j)|i);
				}
			}
		}
	}
	printf("%d\n", dp[(1<<n)-1]);
}

Measured memory_bytes: 11916
N = int(input())
dp = [0]
six = 0
nine = 0
co = 0
for i in range(N+1):
    if i % (6**(six)) == 0:
        if 6**six > 9**nine:
            co = i
        six += 1
    if i % (9**(nine)) == 0:
        if 6**six < 9**nine:
            co = i
        nine += 1
    if i == 0:
        continue
    dpi = min(dp[i-1],dp[i-6**(six-1)],dp[i-9**(nine-1)])
    dp.append(dpi+1)
print(dp[N])

Measured memory_bytes: 3860
//vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> A(n);
  rep(i,n) cin >> A.at(i);
  int sum=0;
  rep(i,n) sum += A.at(i);
  if(sum%(4*m)==0)  sum = sum/(4*m);
  else sum = sum/(4*m) +1;
  
//  cout <<sum;
  sort(A.begin(), A.end());
  reverse(A.begin(), A.end());
  int count=0;
  rep(i,m){
    if(A.at(i)>=sum)count++;
  }
  if(count==m)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=1005,lim=N*10;
int flag[lim],p[N],n,cnt;

int main(){
	read(n),p[++cnt]=1;
	for(int i=2;cnt<=n*2;i++)
		if(!flag[i]){
			p[++cnt]=i;
			for(int j=i*i;j<lim;j+=i)
				flag[j]=1;
		}
	rep(i,1,n){
		rep(j,1,n)
			if((i+j)&1){
				ll res=(ll)p[(i+j-1)/2]*p[(i+j+1)/2];
				res*=(ll)p[(i+3*n-j-1)/2]*p[(i+3*n-j+1)/2];
				printf("%lld ",res+1);
			}
			else{
				ll res=(ll)p[(i+j)/2]*p[(i-j+3*n)/2];
				printf("%lld ",res);
			}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
#include<math.h>
#define ull unsigned long long int
using namespace std;
int main()
{
ull a,b,k;
cin>>a>>b;
k=(a+b)/2;
if(llabs(a-k)==llabs(b-k))
	cout<<k<<endl;
else
	cout<<"IMPOSSIBLE"<<endl;


return 0;
}

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

#define MX (1<<18)+150
#define MOD 1000000007

using std::cerr;
using std::endl;

int n, m, a[MX], fac[MX], ifac[MX], inv[MX], bin[MX], pop[MX], f[MX];

int C(int x, int y){
	if(x < y) return 0;
	return 1ll * fac[x] * ifac[y] % MOD * ifac[x-y] % MOD;
}

int main(){
	scanf("%d%d", &n, &m);
	fac[0] = ifac[0] = inv[1] = 1;
	for(int i = 2; i < MX; i++) inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
	for(int i = 1; i < MX; i++) fac[i] = 1ll * fac[i-1] * i % MOD;
	for(int i = 1; i < MX; i++) ifac[i] = 1ll * ifac[i-1] * inv[i] % MOD;
	for(int i = 0; i < MX; i++) pop[i] = pop[i >> 1] + (i & 1);
	for(int i = 1; i < 20; i++) bin[i] = 1 << (i-1);
	for(int i = 1; i <= m; i++)
		scanf("%d", &a[i]);
	std::sort(a + 1, a + m + 1, [](int x, int y){return x > y;});
	f[0] = 1;
	for(int i = 1; i <= m; i++)
		for(int S = (1 << n) - 1; ~S; S--)
			for(int j = 1; j <= n; j++) if(S & bin[j])
				f[S] = (f[S] + 1ll * f[S ^ bin[j]] * C((1<<n)-a[i]-S+bin[j], bin[j]-1) % MOD * fac[bin[j]] % MOD) % MOD;
	int ans = 0;
//	for(int i = 0; i < (1 << n); i++)
//		std::cout << i << ' ' << (f[i] + MOD) % MOD << endl;
	for(int i = 0; i < (1 << n); i++){
		int now = 1ll * fac[(1<<n)-i-1] * f[i] % MOD;
		if(pop[i]&1) ans = (ans - now) % MOD;
		else		 ans = (ans + now) % MOD;
	}
	ans = 1ll * ans * (1 << n) % MOD;
	printf("%d\n", (ans + MOD) % MOD);
	return 0;
}

Measured memory_bytes: 5632
using System;
//using System.Collections.Generic;
//using System.Collections;
using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      int N = int.Parse(Console.ReadLine());
      int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

      var B = A.Select(c => c.ToString()).ToArray();
      Console.WriteLine(String.Join(" ", B));

      insertionSort(N, A);
    }
    public static void insertionSort(int N, int[] A)
    {
      for (int i = 1; i <= N - 1; i++)
      {
        int v = A[i];
        int j = i - 1;
        while (j >= 0 && A[j] > v)
        {
          A[j + 1] = A[j];
          j--;
          A[j + 1] = v;
        }
        var B = A.Select(c => c.ToString()).ToArray();
        Console.WriteLine(String.Join(" ", B));
      }
    }
  }
}








Measured memory_bytes: 9780
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n,x;
    cin >> n>>x;
    vector<int> v(n);
    REP(i,n){scanf("%d",&v[i]);}
    long long int result=0,eat;
    FOR(i,1,n){
        if(v[i]+v[i-1]>x){
            eat= min(v[i], v[i] + v[i - 1]-x);
            result += eat;
            v[i] -= eat;
        }

        if(v[i]+v[i-1]>x){
            eat=min(v[i-1], v[i] + v[i - 1]-x);
            result += eat;
            v[i - 1] -= eat;
        }

    }
    printf("%lld\n", result);

    return 0;
}

Measured memory_bytes: 640
//#pragma GCC optimize("Ofast")
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

#define blanco 0
#define negro 1
#define no_visitado -1

void dfs(int nodo, int color, vec< vec<pair<int, int>> > &arbol, vec<int> &visitados){
  if( visitados[nodo] != no_visitado ) return;
  visitados[nodo] = color;

  int color_distinto;
  if( color == blanco ) color_distinto = negro;
  else color_distinto = blanco;

  for(auto it: arbol[nodo]){
    int color_paso;
    if( it.second % 2 == 0 ) color_paso = color;
    else color_paso = color_distinto;
    dfs(it.first, color_paso, arbol, visitados);
  }

}

int main(){
  IOS;

  int n; cin>>n;
  vec< vec<pair<int, int>> > arbol(n);
  for(int i=0; i<n-1; i++){
    int v1, v2, d; cin>>v1>>v2>>d;
    v1--; v2--;
    arbol[v1].push_back({v2, d});
    arbol[v2].push_back({v1, d});
  }

  vec<int> visitados(n, no_visitado);
  dfs(0, blanco, arbol, visitados);

  for(auto it: visitados) cout<<it<<endl;

  return 0;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    string s;
    cin>>s;
    sort(ALL(s));
    if(s=="abc")cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int L[500000],R[500000];
int cnt=0,stn=2000000000;

void merge(int s[],int n,int left,int mid,int right);
void mergesort(int s[],int n,int left,int right);

int main(){
  int i,n;
  int s[500000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]); 

  mergesort(s,n,0,n);

  for(i=0;i<n-1;i++) printf("%d ",s[i]);
  printf("%d",s[n-1]);
  printf("\n");
  printf("%d\n",cnt);

  return 0;
}

void merge(int s[],int n,int left,int mid,int right){
  int i,j=0,k;  
  int n1=mid-left;
  int n2=right-mid;

  for(i=0;i<n1;i++) L[i]=s[left+i];
  for(i=0;i<n2;i++) R[i]=s[mid+i];
  L[n1]=R[n2]=stn;
  i=0;
  for(k=left;k<right;k++){
    cnt++;
    if(L[i]<=R[j]){
      s[k]=L[i++];
    }
    else s[k]=R[j++];
  }
}

void mergesort(int s[],int n,int left,int right){
  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    mergesort(s,n,left,mid);
    mergesort(s,n,mid,right);
    merge(s,n,left,mid,right);
  }
}

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

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

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,k;
    cin >> n >> k;
    if ((n-1)*(n-2) < k*2) {
        cout << -1 << endl;
        return 0;
    }
    bool g[100][100];
    int l = (n-1)*(n-2)/2-k;
    for (int i = 0;i < n;++i) for (int j = 0;j < n;++j) g[i][j] = false;
    for (int i = 1;i < n;++i) g[0][i] = true;
    for (int i = 1;i < n;++i) {
        for (int j = i+1;j < n;++j) {
            if (l == 0) break;
            g[i][j] = true;
            l--;
        }
    }
    vector<P> ans;
    for (int i = 0;i < n;++i) for (int j = i+1;j < n;++j) if (g[i][j]) ans.push_back(P(i+1,j+1));
    int m = ans.size();
    cout << m << endl;
    for (int i = 0;i < m;++i) cout << ans[i].first << " " << ans[i].second << "\n";
    return 0;
}

Measured memory_bytes: 384
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

int main() {

    int D, N;
    cin >> D >> N;

    int sum = 0;
    for (int i = 1;; i++) {
        int d = i;
        int c = 0;
        while (d % 100 == 0) c++, d /= 100;
        if (c == D) sum++;
        if (sum == N) {
            cout << i << endl;
            return 0;
        }
    }

}






















































Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    X=int(input())
    X-=int(input())
    X%=int(input())
    print(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
import java.util.Scanner;

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

	int N = sc.nextInt();
	int X[] = new int[N];
	int min = 0;
	for (int i = 0; i < N; i++) {
	    X[i] = sc.nextInt();
	    min += (X[i] - 1) * (X[i] - 1);
	}

	int count = 0;
	for (int i = 2; i < 101; i++) {
	    for (int j = 0; j < N; j++) {
		count += (X[j] - i) * (X[j] - i);
	    }

	    if (min > count)
		min = count;

	    count = 0;
	}

	System.out.println(min);
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main() {
	int N, i;
	cin >> N;
	vector<pair<long, long>> AB(N);
	for (pair<long, long>& i : AB) cin >> i.first >> i.second;
	sort(AB.begin(), AB.end(), [](pair<long, long>& a, pair<long, long>& b)->bool { return a.second < b.second; });
	for (i = 1; i < N; ++i) AB[i].first += AB[i - 1].first;
	for (i = 0; i < N; ++i) {
		if (AB[i].first > AB[i].second) break;
	}
	if (N == i) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  ll N;
  cin >> N;
  ll mod = 1000000007;
  ll r10 = 1, r9 = 1, r8 = 1;
  for (int i=0; i<N; i++) {
    r10 = (r10*10) % mod;
    r9 = (r9*9) % mod;
    r8 = (r8*8) % mod;
  }
  if (r10 + r8 < 2*r9) {
    r10 += mod;
    r8 += mod;
  }
  ll ans = (r10 - 2*r9 + r8) % mod;
  cout << ans << endl;
}


Measured memory_bytes: 3616
fun main(args: Array<String>) {
    a91(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

fun a91(args: Array<String>) {
    if (args.size != 1) {
        throw IllegalArgumentException()
    }
    val (a, b, price) = args[0].split(" ").map { it.toInt() }
    println(if (a + b >= price) "Yes" else "No")
}

Measured memory_bytes: 38080
/******************************************
*    AUTHOR:         Atharva Sarage       *
*    INSTITUITION:   IIT HYDERABAD        *
******************************************/
#include<bits/stdc++.h>
#warning Check Max_Limit,Overflows
using namespace std;
# define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
# define ff first
# define ss second
# define pb push_back
# define mod 1000000007
# define ll long long 
# define db double
# define inf 1e9
# define mx2 100005
# define mx 3005
ll dp[mx][mx],pre[mx][mx];
int main()
{
	IOS;
	ll n;
	cin>>n;
	string s;
	cin>>s;
	dp[0][1]=1;
	pre[0][1]=1;
	for(ll i=1;i<n;i++)
	{
		if(s[i-1]=='<')
		{
			dp[i][1]=0;
			for(ll j=2;j<=i+1;j++)
			{
				dp[i][j]=pre[i-1][j-1];				
			}
		}
		else
		{
			for(ll j=1;j<i+1;j++)
			{
				dp[i][j]=(pre[i-1][i]-pre[i-1][j-1]+mod)%mod; // j+1 to i-1
			}
			dp[i][i+1]=0;
		}
		pre[i][0]=0;
		for(ll j=1;j<=i+1;j++)
		{
			pre[i][j]=(pre[i][j-1]+dp[i][j])%mod;
		}
	}
	cout<<pre[n-1][n]<<endl;
}


Measured memory_bytes: 139648
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, a, b;
  cin >> n >> a >> b;

  int total = 0;
  for (int i = 1; i <= n; i++) {
    int sum = 0;
    int tmp = i;
    while (1) {
      sum += tmp % 10;
      tmp = tmp / 10;
      if (tmp < 1) {
        break;
      }
    }
    if (a <= sum && sum <= b) {
      total += i;
    }
  }

  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<40;

int main(){
    int n,m;
    cin>>n>>m;
    vector<tuple<int,int,int>> t;
    vector<ll> dist(1050,inf);
    for(int i=0;i<m;++i){
        int a,b,c;
        cin>>a>>b>>c;
        t.emplace_back(--a,--b,-c);
    }
    dist[0] = 0;
    for(int i=0;i<n-1;++i){
        for(int j=0;j<m;++j){
            int a,b,c;
            tie(a,b,c) = t[j];
            dist[b] = min(dist[b] , dist[a] + c);
        }
    }
    ll ans = dist[n-1];
    for(int i=0;i<n-1;++i){
         for(int j=0;j<m;++j){
            int a,b,c;
            tie(a,b,c) = t[j];
            dist[b] = min(dist[b] , dist[a] + c);
        }
    }
    if(ans != dist[n-1]){
        cout << "inf" << endl;
    }else cout << -ans << endl;
    return 0;
}



Measured memory_bytes: 256
/** selection sort by ascending order **/

#include <stdio.h>

int main(){
  int i,j,N,cnt=0,swap,minj;

  //scanf N
  scanf("%d",&N);

  //making array
  int A[N];

  //complete array
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }

  //selecting
  for(i=0;i<N-1;i++){
    minj = i; //first
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){ //update minj
        minj = j;
      }
    }
    //changing
    if(minj != i) {
      swap = A[i];
      A[i] = A[minj];
      A[minj] = swap;
      cnt++; //count
    }
  }

  for(i=0;i<N-1;i++){
    printf("%d ",A[i]);
  } 
  printf("%d\n",A[i]);
  printf("%d\n",cnt);


  return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  string S;
  IN(S);
  ll K;
  IN(K);

  ll L = min((ll)S.size(), K);
  REP(i,L){
    if(S[i]!='1'){
      OUT(S[i]);
      return 0;
    }
  }
  OUT(1);

  return 0;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n;
	cin >> n;
	long long ans = 1;
	for(int i = 0; i < n; i++) {
		long long t;
		cin >> t;
		ans = ans / __gcd(ans, t) * t;
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
int main(){
	int i=0,j=0,k,num,num2;
    char s='a',p='a',str[101],str2[101],ans=0;
	while(s!='\n'){
        scanf("%c",&s);
        str[i]=s;
        i++;
    }
	num=i-1;
	while(p!='\n'){
        scanf("%c",&p);
        str2[j]=p;
        j++;
    }
	num2=j-1;
	for(i=0;i<num;i++){
		for(j=0,k=i;j<num2;j++,k++){
			if(str2[j]!=str[k])break;
			if(k==num-1)k=-1;
			if(j==num2-1){
				ans=1;
				std::cout<<"Yes"<<std::endl;
			}	
		}
		if(ans==1)break;
	}
	if(ans==0)std::cout<<"No"<<std::endl;
    return 0;
}

Measured memory_bytes: 1152