akhauriyash/Code-Regression huggingface dataset:
import sys
input = lambda : sys.stdin.readline().rstrip()

s = input()

left = s[:2]
right = s[2:]

if 1 <= int(left) <= 12 and 1 <= int(right) <= 12:
    print("AMBIGUOUS")
elif 1 <= int(left) <= 12:
    print("MMYY")
elif 1 <= int(right) <= 12:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define read(arr,n)	for(int i=0;i<n;i++) cin>>arr[i];
#define print(arr,n) for(int i=0;i<n;i++) cout << arr[i]<<' ';cout << endl;
typedef int int32;
#define int ll

using namespace std;

typedef long long ll;

void solve() {
	ll a, b;	cin >> a >> b;
	ll price1, price2;

	for (int i =0; i < 5000; i++) {
		price1 = 8*i/100; 	price2 = 10*i/100;
		if (price1 == a && price2 == b) {
			cout << i << endl;	return;
		}
	}
	cout << -1 << endl;	return;
}

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


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

using namespace std;
using ll = long long;

int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    ll ans=0;
    for(int i = 0;i < n;++i) {
        cin>>a[i];
    }
    sort(a.rbegin(),a.rend());
    int k=n-2;
    ans += a[0];
    for(int i = 1;i < n;++i) {
        if(k<=0)break;
        if(k==1){
            ans+=a[i];
            k=0;
        }
        else if(k>=2){
            ans+=a[i]*2;
            k-=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int n,m;
int a[N][N], used[N][N];
int S, T, tot, to[N * N * 2], nex[N * N * 2], final[N * 2], f[N * N * 2];
int e[N][N], ans[N][N];

void _link(int x, int y, int fl) {
	to[++tot] = y, nex[tot] = final[x], final[x] = tot;
	f[tot] = fl;
}

void link(int x, int y, int fl) {
	_link(x, y, fl), _link(y, x, 0);
}

int dis[N * 2];

void bfs() {
	for(int i = 1; i <= T; i++) dis[i] = -1;
	static int Q[N * 2]; int h = 0, t = 0;
	Q[++t] = S;
	dis[S] = 0;
	while(h < t) {
		int x = Q[++h];
		for(int i = final[x]; i; i = nex[i]) if(f[i]) {
			int y = to[i]; if (dis[y] == -1) {
				dis[y] = dis[x] + 1;
				Q[++t] = y;
			}
		}
	}
}

int go(int x,int flow) {
	if (x == T) return flow;
	int used = 0;
	for(int i = final[x]; i; i = nex[i]) if(f[i] && dis[x] + 1 == dis[to[i]]) {
		int y = to[i];
		int take = go(y, min(f[i], flow - used));
		used += take;
		f[i] -= take;
		f[i ^ 1] += take;
		if (used == flow) return used;
	}
	return used;
}

void work(int col) {
	tot = 1;
	memset(final, 0, sizeof final);
	S = n + n + 1, T = S + 1;
	for(int i = 1; i <= n; i++) {
		link(S, i, 1);
		for(int j = 1; j <= m; j++) if (!used[i][j]) {
			e[i][j] = tot + 1;
			link(i, n + 1 + (a[i][j] - 1) / m, 1);
		}
	}

	for(int i = 1; i <= n; i++) {
		link(n + i, T, 1);
	}

	while(bfs(), dis[T] != -1)
		go(S, 1e9);

	for(int i = 1; i <= n; i++) 
		for(int j = 1; j <= m; j++) if (!used[i][j]) {
			if (f[e[i][j]] == 0) {
				ans[i][col] = a[i][j];
				used[i][j] = 1;
				break;
			}
		}
}

int g[N];
int main() {
	cin>>n>>m;
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) scanf("%d", &a[i][j]);
	}

	for(int i = 1; i <= m; i++) {
		work(i);
	}

	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) printf("%d ",ans[i][j]);
		printf("\n");
	}

	for(int i = 1; i <= m; i++) {
		for(int j = 1; j <= n; j++) g[j] = ans[j][i];
		sort(g + 1, g + 1 + n);
		for(int j = 1; j <= n; j++) ans[j][i] = g[j];
	}
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) printf("%d ",ans[i][j]);
		printf("\n");
	}	
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int a,b,c,x;
	cin >> a >> b >> c;
	x=max({a,b,c})*3-a-b-c;
	cout << (x%2?(x+3)/2:x/2) << endl;
	return 0;
}

Measured memory_bytes: 256
#-*- using:utf-8 -*-
import time

def solve_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)
  return divisors


def solve_favorite_nums(N, divisors):
  favorite_num_list = []
  for divisor in divisors:
    m = N // divisor - 1
    if (m == 1 or m == 0):
      pass
    elif (N % m == N // m):
      favorite_num_list.append(m)
  return favorite_num_list



if __name__ == '__main__':
  start = time.time()

  N = int(input())
  divisors = solve_divisors(N)
  favorite_nums = solve_favorite_nums(N, divisors)
  print(sum(favorite_nums))

  elapsed_time = time.time() - start
  # print ("time:{0}".format(elapsed_time) + "[sec]")



Measured memory_bytes: 39148
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.Scanner; 
import java.util.StringTokenizer; 
  
public class Main 
{ 
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() 
        { 
            br = new BufferedReader(new
                     InputStreamReader(System.in)); 
        } 
  
        String next() 
        { 
            while (st == null || !st.hasMoreElements()) 
            { 
                try
                { 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException  e) 
                { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() 
        { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() 
        { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() 
        { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
    public static void main (String[] args) {
        FastReader ob = new FastReader();
       int a = ob.nextInt(),b=ob.nextInt(),h=ob.nextInt();
       int ans = (h*a)+ (h*(b-a))/2;
       System.out.println(ans);
        
    }
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// Let's get AC!

int N, M;
int label[200000];
int cnt[200000][2];
set<int> out[200000];
queue<int> emp, finished;
bool used[200000];

int main(){
    
    cin >> N >> M;
    rep(i, N){
        char c;
        cin >> c;
        if(c == 'A')label[i] = 0;
        if(c == 'B')label[i] = 1;
    }
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        out[a].insert(b);
        out[b].insert(a);
    }

    rep(v, N){
        for(int u : out[v]){
            cnt[v][label[u]]++;
        }
        if(cnt[v][0] == 0 || cnt[v][1] == 0){
            used[v] = true;
            emp.push(v);
            finished.push(v);
        }
    }

    while(emp.size()){
        int v = emp.front();
        emp.pop();
        for(int u : out[v])if(!used[u]){
            if(--cnt[u][label[v]] == 0){
                used[u] = true;
                emp.push(u);
                finished.push(u);
            }
        }
    }
    
    if(finished.size() >= N)cout << "No\n";
    else cout << "Yes\n";

}

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

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

  string ans = (N != 0 ? "" : "0");
  while (N != 0) {
    if (N % -2 != 0) {
      ans = "1" + ans;
      N -= 1;
    } else {
      ans = "0" + ans;
    }
    N /= -2;
  }

  printf("%s", ans.c_str());
  return 0;
}

Measured memory_bytes: 256
/**
    @Author:Monk78
    @Topic:
**/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll>Vl;
typedef pair<ll,ll>PII;
typedef vector<PII>Vll;
typedef vector<pair<ll,pair<ll,ll> > >Vlll;
typedef priority_queue<ll>PQL;
typedef map<ll,ll>MP;
#define S second
#define F first
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end));i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mod 1000000009
#define MAX 100005
#define f(i,a,b) for(int i=(a);i<(b);i++)
#define rf(i,a,b) for(int i=(a);i>=b;i--)
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
#define vpshVar() int main()
vpshVar(){
    ll N,K;
    sl(N);sl(K);
    ll h[N];
    for(ll i=0;i<N;i++) sl(h[i]);
    ll dp[N];

    ms(dp,mod);
       dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(ll i=1;i<N;i++){
            ll j=i-K;
            if(j<0)j=0;
        for(;j<i;j++){
            if(dp[i]>dp[j]+abs(h[i]-h[j]))
                dp[i]=dp[j]+abs(h[i]-h[j]);
        }
    }
    pl(dp[N-1]);
return 0;
}


Measured memory_bytes: 1920
N = int(input())
CSF = [map(int, input().split()) for _ in range(N-1)]
C, S, F = [list(i) for i in zip(*CSF)]

for i in range(N):
    if i == N-1:
        print(0)
    else:
        t = S[i]
        for j in range(N-i-1):
            t = max(((t+F[i+j]-1)//F[i+j])*F[i+j], S[i+j])+C[i+j]
        print(t)

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

int main() {
  int n;
  long long sum = 0;

  cin >> n;

  vector<pair<int, int>> p(n);

  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    p[i] = make_pair(b, a);
  }

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

  for (int i = 0; i < n; i++) {
    sum += p[i].second;
    if (p[i].first < sum) {
      cout << "No";
      return 0;
    }
  }

  cout << "Yes";
  return 0;
}

Measured memory_bytes: 1920
import bisect

ss = input()
tt = input()

def main(ss, t):
	d = {}
	s_uq = set(ss)
	for t in set(tt):
		if t not in s_uq:
			print(-1)
			return
		d[t] = []

	
	for i, s in enumerate(ss):
		if s in d.keys():
			d[s].append(i)

	max_d = {key:max(val) for (key, val) in d.items()}
	
	loop_cnt = 0
	idx = -1
	for t in tt:
		if idx >= max_d[t]:
			loop_cnt += 1
			idx = -1
		idx = d[t][bisect.bisect_right(d[t], idx)]

	print(loop_cnt * len(ss) + idx + 1)
		
main(ss, tt)

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

struct Node{
  int key;
  Node *p, *l, *r;
};


Node *NIL, *root;

void preorder(Node *u){
  if(u == NIL) return;
  cout << ' ' << u->key;
  preorder(u->l);
  preorder(u->r);
}

void inorder(Node *u){
  if(u == NIL) return;
  inorder(u->l);
  cout << ' ' << u->key;
  inorder(u->r);
}

/*void Postorder(int u){
  if(u == -1) return;
  Postorder(T[u].l);
  Postorder(T[u].r);
  cout << ' ' << u;
}
*/

void insert(int k){
  Node *y = NIL;
  Node *x = root;

  Node *z;

  z = new Node[1];

  z->key = k;
  z->p = NIL;
  z->r = NIL;
  z->l = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key) x = x->l;
    else x = x->r;
  }

  z->p = y;

  if(y == NIL){
    root = z;
  }
  else if(z->key < y->key) y->l = z;
  else y->r = z;
}

void find(int k){
  Node *x = root;
  while(x != NIL){
    if(k == x->key) break;
    else if(k > x->key) x = x->r;
    else x = x->l;
  }

  if(x == NIL) cout << "no" << endl;
  else cout << "yes" << endl;
}

Node *getMinimum(Node *x){
  while(x->l != NIL){
    x = x->l;
  }
  return x;
}

Node *getsuccessor(Node *x){
  if(x->r != NIL) return getMinimum(x->r);

  Node *y = x->p;
  while(y != NIL && x == y->r){
    x = y;
    y = y->p;
  }
  return y;
}


void deletex(int k){
  Node *z = root;
  while(z->key != k){
    if(k > z->key) z = z->r;
    else z = z->l;
  }
  Node *y;

  if(z->l == NIL || z->r == NIL) y = z;
  else y = getsuccessor(z);

  Node *x;

  if(y->l != NIL) x = y->l;
  else x = y->r;

  if(x != NIL) x->p = y->p;

  if(y->p == NIL) root = x;
  else if(y == y->p->l) y->p->l = x;
  else y->p->r = x;

  if(y != z) z->key = y->key;
}





int main(){

  int n;

  cin >> n;

  int *A = new int[n + 1];

  for(int i = 1; i <= n; i++){
    cin >> A[i];
  }

  for(int i = 1; i <= n; i++){
    cout << "node " << i << ": key = " << A[i] << ", ";
    if(i / 2 >= 1){
      cout << "parent key = " << A[i / 2] << ", ";
    }
    if(i * 2 <= n){
      cout << "left key = " << A[i * 2] << ", ";
    }
    if(i * 2 + 1 <= n){
      cout << "right key = " << A[i * 2 + 1] << ", ";
    }
    cout << endl;
  }



/*  for(int k = 0; k < n; k++){

    cin >> x;

    for(int i = 0; i < 2; i++){
      cin >> y;
      T[y].parent = x;
      if(i == 0){
      T[x].l = y;
      }
      else{
        T[x].r = y;
      }
    }
  }

/*
  cout << "Inorder" << endl;
  Inorder(r);
  cout << endl;


  cout << "Preorder" << endl;
  Preparse(r);
  cout << endl;


  cout << "Postorder" << endl;
  Postorder(r);
  cout << endl;
*/

  return 0;
}



Measured memory_bytes: 3044
while True:
    n, x = map(int,input().split())
    count=0
    if n == x == 0:
        break
    else:
        ls = []
        for i in range(1,n+1):
            ls.append(i)

        for s in ls:
            num1 = s

            for j in ls:
                if num1 == j:
                    break
                else:
                    num2 = j
                    if x < num1+num2:
                        break

                for k in ls:
                    if num1 == k:
                        break
                    elif num2 == k:
                        break
                    elif num1+num2+k == x:
                        count+=1
                    else:
                        pass
    print(count)

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

using namespace std;

int main()
{
	int n;
	string s[300];
	cin >> n;
	for(int i = 0; i < n; i++)cin >> s[i];
	int ans = 0;
	for(int mx = 0; mx < n; mx++)
	{
		bool ok = true;
		for(int x = 0; x < n; x++)
		{
			for(int y = 0; y < n; y++)
			{
				if(s[(x + mx) % n][y] != s[(y + mx) % n][x])ok = false;
			}
		}
		if(ok)ans++;
	}
	cout << ans * n << endl;

	return 0;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;

// Call gen_f to generate factiorials
// Be sure about MOD 
// Call get_c(i, j) to obtain c[i][j]

const ll MOD = 1e9 + 7;

const int MAXF = 2e5 + 5;

ll f[MAXF], f_inv[MAXF];

ll pow_mod(ll a, ll st) {
	ll ans = 1ll;
	for(; st; st >>= 1ll) {
		if (st & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}

ll get_inv(ll v) {
	return pow_mod(v, MOD - 2);
}

void gen_f() {
	f[0] = 1;
	REP(i, 1, MAXF) {
		f[i] = (f[i - 1] * i) % MOD;
	}
	f_inv[MAXF - 1] = get_inv(f[MAXF - 1]);
	for(int i = MAXF - 2; i >= 0; i--) {
		f_inv[i] = (f_inv[i + 1] * (i + 1)) % MOD;
	}
}

ll get_c(int i, int j) {
	if (j > i || j < 0) {
		return 0ll;
	}
	return (((f[i] * f_inv[j]) % MOD) * f_inv[i - j]) % MOD;
}

void solve(){
	gen_f();
	int b, w;
	cin >> b >> w;
	ll p0, q0, p1, q1, p2, q2;
	p0 = 0, p1 = 0, p2 = 1;
	q0 = 1, q1 = 1, q2 = 1;
	REPN(i, 1, b + w) {
		p2 = (q2 - p0 - p1 + 2 * MOD) % MOD;
		ll p3, q3;
		p3 = (2 * p1 + p2) % MOD;
		q3 = (2 * q2) % MOD;
		
		/*printf("%lld %lld\n", p0, q0);
		printf("%lld %lld\n", p2, q2);
		printf("%lld %lld\n", p1, q1);
		printf("%lld %lld\n", p3, q3);*/
		
		ll ans = (p3 * get_inv(q3)) % MOD;
		printf("%lld\n", ans);
		
		q0 = (q0 * 2) % MOD;
		q1 = (q1 * 2) % MOD;
		q2 = (q2 * 2) % MOD;
		if (i >= b) {
			p0 = (2 * p0 + get_c(i - 1, b - 1)) % MOD;
		}
		if (i >= w) {
			p1 = (2 * p1 + get_c(i - 1, w - 1)) % MOD;
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for(int i=0; i<H; i++) cin >> a.at(i);
    
    for(int i=0; i<W+2; i++) cout << '#';
    cout << endl;
    for(int i=0; i<H; i++){
        for(int j=0; j<W+2; j++){
            if(j == 0 || j == W+1) cout << '#';
            else if(j == 1) cout << a.at(i);
        }
        cout << endl;
    }
    for(int i=0; i<W+2; i++) cout << '#';
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(), v.end()
#define dcout cout << fixed << setprecision(15)
#define arep(i, a) for(auto i : a)
#define F first
#define S second
#define VE vector<int>
#define pb(x) push_back(x)
#define MOD 1000000007
#define INF 10000000000
#define int long long
#define KETA(n) floor(log10(n) + 1)
using namespace std;
signed main() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b != c)
        cout << "Yes";
    else if(b == c && c != a)
        cout << "Yes";
    else if(c == a && a != b)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v,int N,bool visited[nmax]){
  bool all_visited = true;

  for(int i = 0; i < N; i++){
    if(visited[i] == false) all_visited = false;
  }

  if(all_visited){
  return 1;
  }

  int ret = 0;

  rep(i,N){
  if(graph[v][i] == false) continue;
  if(visited[i]) continue;

  visited[i] = true;
  ret+=dfs(i,N,visited);
  visited[i] = false;
  }

  return ret;
}

int main(){
  int n,m;
  cin >> n >> m;
  rep(i,m) {
    int a,b;
    cin >> a >> b;
    graph[a-1][b-1] = graph[b-1][a-1] = true;
  }

  bool visited[nmax];
  rep(i,n){
    visited[i] = false;
  }

  visited[0] = true;
  cout << dfs(0,n,visited) << endl;

    
  return 0;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = na()
b = na()

attack = 0
apre = a[0]
for ai, bi in zip(a[1:], b):
    attackleft = min(apre, bi)
    attack += attackleft
    bi -= attackleft
    attackright = min(ai, bi)
    attack += attackright
    apre = ai - attackright

print(attack)


Measured memory_bytes: 18624
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

#define MAX 100000
#define WRONG 1
#define RIGHT 0

typedef struct
{
  int value;
  char picture;
} Card;

void swap_v(Card [],int,int);
void swap_p(Card [],int,int);
int Judge(Card [],Card [],int);
void QuickSort(Card [],int,int);
int Partition(Card [],int,int);
void MergeSort(Card [],int,int);
void Merge(Card [],int,int,int);

int main()
{
  Card A[MAX],B[MAX];
  int n,value;
  char picture;
  int i;

  scanf("%d",&n);
  for (i = 0;i < n;i++){
    scanf(" %c %d",&A[i].picture,&A[i].value);
  B[i] = A[i];
  }

QuickSort(A,0,n - 1);
MergeSort(B,0,n);

if (Judge(A,B,n))
printf("Not stable\n");

else
  printf("Stable\n");

for (i = 0;i < n;i++){
  printf("%c %d\n",A[i].picture,A[i].value);
}

  return 0;
}

void swap_v(Card A[], int a, int b)
{
  int temp;

  temp = A[a].value;
  A[a].value = A[b].value;
  A[b].value = temp;
}

void swap_p(Card A[], int a, int b)
{
  char temp;

  temp = A[a].picture;
  A[a].picture = A[b].picture;
  A[b].picture = temp;
}

int Judge(Card A[],Card B[],int n){
  int i;

  for (i = 0;i < n;i++){
    if (A[i].picture != B[i].picture)
    return WRONG;
  }

  return RIGHT;
}

void QuickSort(Card A[], int p, int r)
{
  int q;

  if (p < r)
  {
    q = Partition(A, p, r);
    QuickSort(A, p, q - 1);
    QuickSort(A, q + 1, r);
  }
}

int Partition(Card A[], int p, int r)
{
  int x;
  int i, j;

  i = p - 1;
  x = A[r].value;

  for (j = p; j < r; j++)
  {
    if (A[j].value <= x)
    {
      i++;
      swap_v(A, i, j);
      swap_p(A, i, j);
    }
  }

  swap_v(A, i + 1, r);
  swap_p(A, i + 1, r);

  return i + 1;
}

void MergeSort(Card A[], int left, int right)
{
  int mid;

  if (left + 1 < right)
  {
    mid = (left + right) / 2;

    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A, left, mid, right);
  }
}

void Merge(Card A[], int left, int mid, int right)
{
  Card *L, *R;
  int n1, n2;
  int i, j, k;

  n1 = mid - left;
  n2 = right - mid;

  L = (Card *)malloc(sizeof(Card) * (n1 + 1));
  R = (Card *)malloc(sizeof(Card) * (n2 + 1));

  for (i = 0; i < n1; i++)
    L[i] = A[left + i];

  for (i = 0; i < n2; i++)
    R[i] = A[mid + i];

  L[n1].value = INT_MAX;
  R[n2].value = INT_MAX;
  i = 0;
  j = 0;

  for (k = left; k < right; k++)
  {
    if (L[i].value <= R[j].value)
    {
      A[k] = L[i];
      i++;
    }

    else
    {
      A[k] = R[j];
      j++;
    }

  }

}


Measured memory_bytes: 20552
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
	cin >> n;
	long long int a[100];
	a[0]=2;
	a[1]=1;
	for(int i=2;i<=n;i++){
		a[i]=a[i-2]+a[i-1];
	}
	cout << a[n] << endl;
	return 0;
}

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#include <unordered_set>

#define _USE_MATH_DEFINES
#include <math.h>


#include <vector>
#include <list>

#include <set>
#include <map>

#include <unordered_map>

#include <queue>

#include <string>

#include <vector>

#define sqr(x) (x) * (x)

#include <algorithm>
#include <functional>

#include <bitset>

#include <functional>

#include <chrono>

typedef unsigned int u32;
typedef int i32;

typedef unsigned long long int u64;
typedef long long int i64;

typedef uint16_t u16;
typedef int16_t i16;

typedef uint8_t u8;
typedef int8_t i8;


using namespace std;
using namespace std::chrono;

struct less_key
{
    bool operator() (pair<i64, i64> p1, pair<i64, i64> p2)
    {
        return p1.first < p2.first || (p1.first == p2.first && p1.second < p2.second);
    }
};

struct pair_hash {
public:
    std::size_t operator()(const std::pair<u64, u64> &x) const
    {
        return std::hash<u64>()(x.first) ^ std::hash<u64>()(x.second);
    }
};

const i64 mod = 1000000007ll;
const i64 smod = 999983;

// del

const i64 MAXN = 200005;

i64 n;

i64 a[MAXN];

list<i64> b;

int main() {
    cin >> n;

    for (i64 i = 1; i <= n; i++) {
        cin >> a[i];
        b.push_back(a[i]);
    }
    reverse(b.begin(), b.end());

    vector<i64> r;

    while (b.size()) {
        i64 i = b.size();
        bool f = false;
        auto it = b.begin();

        while (it != b.end()) {
            if (i == *it) {
                r.push_back(i);
                b.erase(it);
                f = true;
                break;
            }
            i--;
            it++;
        }

        if (!f) {
            cout << -1 << endl;
            return 0;
        }
    }

    reverse(r.begin(), r.end());

    for (auto p : r) {
        cout << p << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys

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

for i in range(1, n):
    print(' '.join(list(map(str, a))))
    key = a[i]
    j = i - 1
    while j >= 0 and a[j] > key:
        a[j + 1] = a[j]
        j -= 1
    a[j + 1] = key

print(' '.join(list(map(str, a))))


Measured memory_bytes: 5608
from operator import itemgetter
import sys
input = sys.stdin.readline

n = int(input())
s = []
for i in range(n):
    ts, tp = input().split()
    s.append([ts, int(tp), i+1])
s.sort(key=itemgetter(1), reverse=True)
s.sort(key=itemgetter(0))
for i in s:
    print(i[2])

Measured memory_bytes: 3060
now=input()

while now!="#":
    order_raw = input()
    order = [int(s)-1 for s in order_raw.split(' ')]

    box = [[]]
    for n in now:
        if n=='/':
            box.append([])
        elif n=='b':
            box[-1].append('b')
        else:
            for _ in range(int(n)):
                box[-1].append('.')

    box[order[0]][order[1]] = '.'
    box[order[2]][order[3]] = 'b'

    res=""
    index=0
    for bo in box:
        for b in bo:
            if b=='b':
                if index>0:
                    res+=str(index)
                    index=0
                res+="b"
            else:
                index+=1
        if index>0:
            res+=str(index)
            index=0
        res+="/"

    print(res[:-1])

    now=input()

            
        
        



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

#define INF 10000001

#define MOD 1000000007

typedef long long ll;

int main(void){
  int n;
  std::cin >> n;

  std::vector<std::pair<int,int>> v(n);
  int x,l;
  for(int i=0; i<n; i++){
    std::cin >> x >> l;
    v[i] = std::make_pair(l+x,x-l);
  }
  std::sort(v.begin(),v.end());

  int ans = 0, t = -INF;
  for(int i=0; i<n; i++){
    if(t <= v[i].second){
      t = v[i].first;
      ans++;
    }
  }

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


Measured memory_bytes: 1024
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "a.cpp"

int main() {
  ll a;
  cin >> a;
  cout << a + a*a + a*a*a << el;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

int main() {
    char b;
    cin >> b;
    
    if (b == 'A') cout << 'T';
    if (b == 'T') cout << 'A';
    if (b == 'G') cout << 'C';
    if (b == 'C') cout << 'G';
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long l=2,r=2,n,ans[100005];
int main()
{
	cin>>n;
	for(int i=1; i<=n; i++)cin>>ans[i];
	for(int i=n; i>=1; i--)l=((l-1)/ans[i]+1)*ans[i],r=r/ans[i]*ans[i]+ans[i]-1;
	if(l>r)cout<<-1;else cout<<l<<" "<<r;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct Graph {
    int i, score;
    vector<int> to;
    bool path        = true;
    bool check_score = true;
};

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

    int N;
    cin >> N;
    vector<int> a(N - 1), b(N - 1);
    REP(i, N - 1) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    vector<int> c(N);
    REP(i, N) cin >> c[i];

    SORT(c);
    ll sum = 0;

    vector<Graph> G(N);
    REP(i, N - 1) {
        G[i].i = i;
        G[a[i]].to.push_back(b[i]);
        G[b[i]].to.push_back(a[i]);
    }
    G[N - 1].i = N - 1;

    sort(ALL(G), [&](const Graph x, const Graph y) {
        return x.to.size() > y.to.size();
    });

    int now = N - 1;
    queue<int> q;
    q.push(G[0].i);
    sort(ALL(G), [&](const Graph x, const Graph y) { return x.i < y.i; });
    G[q.front()].path = false;

    while (!q.empty()) {
        int v      = q.front();
        G[v].score = c[now];
        now--;
        q.pop();
        REP(i, G[v].to.size()) {
            int aa = G[v].to[i];
            if (G[aa].path) {
                q.push(aa);
                G[aa].path = false;
            }
        }
    }
    ll ans = 0;
    q.push(0);
    G[0].check_score = false;
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        REP(i, G[v].to.size()) {
            int aa = G[v].to[i];
            if (G[aa].check_score) {
                ans += min(G[aa].score, G[v].score);
                q.push(aa);
                G[aa].check_score = false;
            }
        }
    }

    std::cout << ans << '\n';
    REP(i, N) { cout << G[i].score << " "; }
    std::cout << '\n';

    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;


class Main{
    public static void main(String[] a){
		Scanner sc = new Scanner(System.in);
		int numone = 0;
		int numtwo = 0;
		int numthree = 0;
		int x;
		for (int i=0; i<10; i++) {
			x = sc.nextInt();
			if (numone <= x) {
				numthree = numtwo;
				numtwo = numone;
				numone = x;
			} else if (numtwo <= x) {
				numthree = numtwo;
				numtwo = x;
			}else if (numthree <= x) {
				numthree = x;
			}
		}
		System.out.println(numone + "\n" + numtwo + "\n" + numthree);
	}
}

Measured memory_bytes: 26132
def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    mod = 998244353
    ans = 0
    dp = [0]*S

    for i, a in enumerate(A):
        dp[0] +=1
        if a > S:
            continue

        ans += dp[S-a]*(N-i)

        for j, x in enumerate(dp[:S-a]):
            dp[j+a] += x
    print(ans % mod)


main()


Measured memory_bytes: 3816
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <tuple>
#define rf(x) (x)=0;while(*p<48)im=*p=='-';while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15);if(im)(x)=-(x);
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define revv(V) reverse(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define clv(V) (V).clear()
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
#define MAXN (100005)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;

int X[MAXN];
int N, A, B;
ll Ans;

int main() {
	scanf("%d%d%d", &N, &A, &B);
	for(int i = 1; i <= N; i++) scanf("%d", &X[i]);
	for(int i = 1; i < N; i++) Ans += min((ll)B, (ll)(X[i+1] - X[i]) * A);
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
char A[22][23];
int B[22][22];
int vis[22][23];
#define fi first
#define se second
#define P pair<int,int>
queue<P> q;
queue<P> qq;
int N,K;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
int bfs(int x,int y)
{
    int ans = 0;

    q.push({x,y});
    while(!q.empty())
    {
        P a = q.front();
        qq.push(a);
        q.pop();
        ans = max(ans,B[a.fi][a.se]);
        int v=B[a.fi][a.se];
        for(int i=0; i<4; i++)
            if(a.fi+dx[i]>=0&&a.fi+dx[i]<N&&a.se+dy[i]>=0&&a.se+dy[i]<K)
            {
                if(A[a.fi+dx[i]][a.se+dy[i]]!='#'&&B[a.fi+dx[i]][a.se+dy[i]]==0&&(a.fi+dx[i]!=x||a.se+dy[i]!=y))
                {
                    B[a.fi+dx[i]][a.se+dy[i]]=v+1;
                    q.push({a.fi+dx[i],a.se+dy[i]});
                }
            }
    }
    while(!qq.empty())
    {
        B[qq.front().fi][qq.front().se]=0;
        qq.pop();
    }
    return ans;
}
signed main()
{

    scanf("%lld%lld",&N,&K);
    for(int i=0; i<N; i++)
    {
        scanf("%s",A[i]);

    }
    int ans =0;
    for(int i=0; i<N; i++)
    {
        for(int j=0; j<K; j++)
        {
            if(A[i][j]!='#')
            {
                ans=max(ans,bfs(i,j));
            }
        }
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner stdin = new Scanner(System.in);

		String regex = "\\d{" + stdin.nextInt() + "}-\\d{" + stdin.nextInt() + "}";
		String result = "No";
		if (stdin.next().matches(regex)) {
			result = "Yes";
		}

		System.out.println(result);
	}

}


Measured memory_bytes: 23892
// 177

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>
#include <cmath>

using namespace std;
using ll = long long int;
#define NUM 1000000007

int main(){
    int s;
    ll ans = 0;
    cin >> s;
    vector<vector<ll>> v(s, vector<ll>(s+1, 0));
    for(int i=0; i<v.size(); i++){
        v.at(i).at(0) = 1;
    }
    for(int i=1; i<v.size(); i++){
        for(int j=1; j<i+1; j++){
            v.at(i).at(j) = (v.at(i-1).at(j-1) + v.at(i-1).at(j))%NUM;
        }
    }
    for(int i=1; s>=3*i; i++){
        ans += v.at(s-i*2-1).at(i-1);
        ans %= NUM;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int main() {
    ll A, B, C, D; cin >> A >> B >> C >> D;
    ll lcm = C * D / __gcd(C, D);
    ll mx = B - A + 1;
    
    mx -= B / C;
    mx -= B / D;
    mx += B / lcm;
    
    mx += (A - 1) / C;
    mx += (A - 1) / D;
    mx -= (A - 1) / lcm;
    
    cout << mx;
    
    return 0;
}

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

using namespace std;

const int N = 3003, md = 998244353;
int dp[N][N];

inline int add(int x, int y) {
  x += y;
  if (x >= md) {
    x -= md;
  }
  if (x < 0) {
    x += md;
  }
  return x;
}

inline int mult(int x, int y) {
  return (long long) x * y % md;
}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b] = 1;
  for (int i = a; i <= c; i++) {
    for (int j = b + (i == a); j <= d; j++) {
      dp[i][j] = add(mult(dp[i - 1][j], j), mult(dp[i][j - 1], i));
      dp[i][j] = add(dp[i][j], -mult(dp[i - 1][j - 1], mult(i - 1, j - 1)));
    }
  }
  cout << dp[c][d] << '\n';
  return 0;
}


Measured memory_bytes: 38712
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 2000000000
#define PI 3.14159265358979323846
using namespace std;
bool isprime(int x)
{
	for(int i = 3; i <= (int)(sqrt((double)(x))); i++)
		if(x%i==0)
			return false;
	return true;
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	vector<long long>v;
	v.push_back(2);
	for(int i = 3; i <= 1000000; i+=2)
		if(isprime(i))
			v.push_back(i);
	long long n;
	cin >> n;
	long long ans=0;
	for(int i = 0; i < v.size(); i++)
	{
		int nb=0;
		while(n%v[i]==0)
		{
			nb++;
			n/=v[i];
		}
		for(int j = 1; j <= nb; j++)
		{
			ans++;
			nb-=j;
		}
	}
	if(n!=1)
		ans++;
	cout << ans << '\n';
}

Measured memory_bytes: 4276
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	    Scanner scan = new Scanner(System.in);


	    for(;;){
		    int str1 = Integer.parseInt(scan.next());
		    int str2 = Integer.parseInt(scan.next());

	    	if(str1 == 0 && str2 == 0){
	    		break;
	    	}else if(str1 <= str2){
	    	    System.out.println(str1 +" "+ str2);
	    	}else{
	    	    System.out.println(str2 +" "+ str1);
	    	}
	    }

	}
}

Measured memory_bytes: 23364
#pragma region cp-helper
#include <bits/stdc++.h>
using namespace std;
#define AC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ll long long
#define ull unsigned long long
#define ii pair<ll, ll>
#define lll pair<ll, ll>
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define vll vector<lll>
#define vvl vector<vl>
#define vii vector<ii>
#define all(a) a.begin(), a.end()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(a, b)
#define umap unordered_map
#define uset unordered_set
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
#define qmod %mod
#define pls signed
#define give main()
const int mod = 1000000007;
#pragma endregion

const int N = 100005;

int n, k, t;

pls give {
    AC; 
    cin >> n >> k;
    t = n%k;
    cout << min(t, abs(t-k)) << nl;
}
    

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int main() {

  while(1){
    int n;
    cin>>n;
    if(n == 0) break;
    string s[50];
    REP(i,0,n){
      cin>>s[i];
    }
    string ns[50];
    REP(i,0,n){
      ns[i] = "";
      REP(j,0,s[i].size()){
        string c;
        if(j == 0||s[i][j-1]=='a'||s[i][j-1]=='i'||s[i][j-1]=='u'||s[i][j-1]=='e'||s[i][j-1]=='o'){
          c = string() + s[i][j];
        }else{
          c = "";
        }
        ns[i] += c;
      }
    }
    int k = 1;
    bool flag;
    while(k <= 50){
      //test
      //cout<<"k: "<<k<<endl;
      //
      set<string> se;
      flag = true;
      REP(i,0,n){
        string ts;
        if(ns[i].size() > k) ts = ns[i].substr(0,k);
        else ts = ns[i];
        if(se.find(ts) != se.end()){
          flag = false;
          break;
        }
        se.insert(ts);
      }
      if(flag){
        cout<<k<<endl;
        break;
      }
      k++;
    }
    if(!flag) cout<<-1<<endl;

  }

  return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    long long n,tmp;
    bool hold=true;
    cin>>n;
    for(long long i=0; i<n; i++){
    	cin>>tmp; 
    	hold = tmp%2!=0?false:hold;
    }
    if(!hold) cout << "first";
    else cout << "second";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

const int M=100;
int a[3][3];

int main(){
	for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin>>a[i][j];
	bool B=0;
	for(int i=0;i<=M;i++) for(int j=0;j<=M;j++) for(int k=0;k<=M;k++){
		bool t=1;
		for(int l=0;l<3;l++){
			int A=a[l][0]-i,B=a[l][1]-j,C=a[l][2]-k;
			if(A!=B||B!=C) t=0;
		}
		B|=t;
	}
	cout<<(B?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}


signed main() {

    int n;
    cin >> n;
    vector<pii> s(n), t(n);
    for(int i = 0; i < n; i++) {
        cin >> s[i].first >> s[i].second;
    }

    for(int i = 0; i < n; i++) {
        cin >> t[i].first >> t[i].second;
    }
    sort(ALL(s));
    sort(ALL(t));
    
    int ans = 0;

    for(int i = 0; i < n; i++) {
        int c = -1;
        for(int j = 0; j < n; j++) {
            if(s[j].first > t[i].first) break;
            if(s[j].second > t[i].second) continue;

            if(c == -1) c = j, ans++;
            else if(s[c].second < s[j].second) c = j;
        }
        if(~c) s[c].second = INF;
    }

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



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

int sumofdigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int main() {
  int n, l;
  std::cin >> n >> l;
  
  std::vector<std::string> s(n);
  for (int i = 0; i < n; i++) {
    std::cin >> s.at(i);
  }
  
  std::sort(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    std::cout << s.at(i);
  }
  std::cout << '\n';
}

Measured memory_bytes: 256
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


H, W = mi()

# 移動できない
if H == 1 or W == 1:
    print(1)
# 縦偶数
elif H % 2 == 0:
    print(H * W // 2)
# 縦奇数 かつ　横偶数
elif W % 2 == 0:
    print(H * W // 2)
# 縦奇数 かつ　横奇数
else:
    print((H * W // 2) + 1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (ll)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// ll        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll n;
  cin >> n;
  vector<ll> x(n), y(n);
  rep(i, n) { cin >> x[i] >> y[i]; }
  vector<ll> route(n);
  iota(ALL(route), 0);
  map<ll, ll> sum;
  ll baai = 0;
  do {
    baai++;
    repz(i, 1, n) {
      ll now = route[i], bef = route[i - 1];
      ll tempx = x[now] - x[bef];
      ll tempy = y[now] - y[bef];
      tempx *= tempx;
      tempy *= tempy;
      sum[tempx + tempy]++;
    }
  } while (next_permutation(ALL(route)));
  ld temp = 0;
  for (pair<ll, ll> i : sum) {
    temp += sqrt((ld)i.F) * (ld)i.S;
  }
  cout << fixed << setprecision(15) << temp / baai << endl;
  return 0;
}


Measured memory_bytes: 256