akhauriyash/Code-Regression huggingface dataset:
while True :
    a, b = map(int, input().split())

    if a == 0 :
        break
    else :
        if a <= b :
                X, Y = b, a
        else :
            X, Y = a, b
            
        cnt = 0
                
        def Euc(X, Y, cnt) :
            while Y != 0 :
                cnt += 1
                X %= Y
                X, Y = Y, X
                
            return X, cnt
            
        print(Euc(X, Y, cnt)[0], Euc(X, Y, cnt)[1])




Measured memory_bytes: 5612
#include <iostream>
using namespace std;
int main() {
        int n, y;
        cin >> n >> y;
        y /= 1000;
        for (int i=0; i<=n; i++) {
                for (int j=0; j<=n-i; j++) {
                        if (i + 5*j + 10*(n-i-j) == y) {
                                cout << n-i-j << " " << j << " " << i << endl;
                                return 0;
                        }
                }
        }
        cout << "-1 -1 -1" << endl;
        return 0;
}


Measured memory_bytes: 256
// AOJ 2419 Acrophobia
// 2018.4.8 bal4u

#include <stdio.h>
#include <string.h>

#define QMAX 15000
typedef struct { char r, c, roll; short t; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int r, int c, int roll, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].r = r, que[i].c = c, que[i].roll = roll, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define ABS(a)   ((a)>=0?(a):-(a))
#define INF  0x3030
int   W, H;
char  map[103][103];
char  roll[103][103]; int sz;
char  cost[103][103];
short dist[103][103][1<<5];
int   mv[4][2] = {{-1,0},{0,1},{1,0},{0,-1}};

int dijkstra(int sr, int sc, int gr, int gc, int all)
{
	int i, r, c, nr, nc, ro, t, nt, x;

	memset(dist, INF, sizeof(dist));
	qsize = 0;
	enq(sr, sc, 0, 0);
	while (qsize) {
		r = que[0].r, c = que[0].c, ro = que[0].roll, t = que[0].t, deq();
		if (r == gr && c == gc && ro == all) break;
		if (dist[r][c][ro] <= t) continue;
		dist[r][c][ro] = t;
		for (i = 0; i < 4; i++) {
			nr = r + mv[i][0], nc = c + mv[i][1];
			if (nr < 0 || nr >= H || nc < 0 || nc >= W || map[nr][nc] == '#') continue;
			nt = t + cost[r][c];
			if (dist[nr][nc][x=(ro|roll[nr][nc])] <= nt) continue;
			enq(nr, nc, x, nt);
		}
	}
	return t;
}

int main()
{
	int r, c, d, nr, nc;
	int sr, sc, gr, gc;
	char buf[20];

	fgets(buf, 20, stdin), sscanf(buf, "%d%d", &W, &H);
	sz = 0; for (r = 0; r < H; r++) {
		fgets(map[r], 103, stdin);
		for (c = 0; c < W; c++) {
			if      (map[r][c] == 'S') sr = r, sc = c;
			else if (map[r][c] == 'G') gr = r, gc = c;
			else if (map[r][c] == 'M') roll[r][c] |= 1<<sz++;
		}
	}
	memset(cost, 1, sizeof(cost));
	for (r = 0; r < H; r++) for (c = 0; c < W; c++) if (map[r][c] == '#') {
		for (nr = r-3; nr <= r+3; nr++) for (nc = c-3; nc <= c+3; nc++) {
			if (nr < 0 || nr >= H || nc < 0 || nc >= W) continue;
			d = ABS(nr-r); if (d < ABS(nc-c)) d = ABS(nc-c);
			d = 4-d;
			if (d > cost[nr][nc]) cost[nr][nc] = d;
		}
	}
	printf("%d\n", dijkstra(sr, sc, gr, gc, (1<<sz)-1));
	return 0;
}


Measured memory_bytes: 2536
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define trav(a, x) for(auto& a : x)
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;

int main(){
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);

    int n,m;
    cin >> n >> m;
    vvi g(n+1);
    vvi gi(n+1);
    vi nb(n+1);
    int a,b;
    rep(i,0,n+m-1){
        cin >> a >> b;
        g[a].push_back(b);
        gi[b].push_back(a);
        nb[b]++;
    }

    int c=0;
    int lbl[100009];
    int ord[100009];
    vi zeros;
    rep(i,0,n){
        if(nb[i]==0){
            zeros.push_back(i);
        }
    }
    int z;
    while(sz(zeros)>0){
        z=zeros.back();
        zeros.pop_back();
        lbl[z]=c;
        ord[c]=z;
        c++;
        trav(v,g[z]){
            nb[v]--;
            if(nb[v]==0){
                zeros.push_back(v);
            }
        }
    }
    vi par(n+1);
    rep(i,0,n){
        z=ord[i];
        int best=0;
        int bestv=-1;
        trav(v,gi[z]){
            if(lbl[v]>bestv){
                best = v;
                bestv = lbl[v];
            }
        }
        par[z]=best;
    }
    rep(i,1,n+1){
        cout << par[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 13312
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	s := next()
	ans := 0
	for _, v := range s {
		switch v {
		case '+':
			ans++
		case '-':
			ans--
		}
	}
	fmt.Println(ans)
}


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

int main() {
  int n, d;
  cin >> n >> d;

  int base = d * 2 + 1;
  if (n % base != 0) {
    cout << n / base + 1 << endl;
  } else {
    cout << n / base << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
digits = []
i = 1
while N != 0:
    if N % pow(2,i) == 0:
        digits.append('0')
    else:
        digits.append('1')
        N -= pow(-2,i-1)
    i += 1

if digits:
    print("".join(reversed(digits)))
else:
    print("0")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 123;
#define int long long 
int n, m;
pair <int, int> a[maxn];
string s[60], t[60];
main () { 
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;

    multiset<int> q;
    for(int i = 1; i <= n; i++) {
    	int x;
    	cin >> x;
    	q.insert(x);
    }

    for(int i = 1; i <= m; i++) {
    	int x = *q.rbegin();
    	q.erase(q.find(x));
    	x /= 2;
    	q.insert(x);
    }

    int ans = 0;
    while(q.size()) {
    	int x = *q.begin();
    	ans += x;
    	q.erase(q.find(x));
    }
    cout << ans;
}




Measured memory_bytes: 8340
from collections import Counter
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

n = int(input())
insu = []
for i in range(2, n+1):
  insu = insu + prime_decomposition(i)
insu_c = Counter(insu)

r = 1
mod = 10**9 + 7
for c in insu_c.values():
  r *= (c+1)
  r %= mod
print(r)

Measured memory_bytes: 3316
{-# LANGUAGE BangPatterns #-}

module Main where

import Data.Char
import Data.List
import Control.Monad
import Control.Monad.ST
import Control.Monad.State.Strict
import Data.Array.ST
import Data.Array.Unboxed
import Control.Applicative
import Text.Printf
import Debug.Trace


readInt :: IO Int
readInt = read <$> (input `seq` input)
    where input = do
            !c <- getChar
            if isDigit c || c == '-'
                then (c :) <$> input
                else return []

prints :: Show a => [a] -> IO ()
prints as = putStrLn $ concat $ intersperse " " $ map show as

main = f =<< replicateM 2 readInt

f [n, x]
  | n == 0 && x == 0 = return ()
  | otherwise = print a >> main
  where a = (flip execState) 0 $ do
                forM_ [1..n] $ \i ->
                    forM_ [i+1..n] $ \j ->
                        let k = x - i - j
                        in when (j < k && k <= n) (modify (+1))


Measured memory_bytes: 5120
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
	int s, a, b, x[30];
	int w, n; cin >> w >> n;
	for (int i = 0; i < w; i++) {
		x[i] = i + 1;
	}
	for (; n > 0; n--) {
		scanf("%d,%d", &a, &b);
		s = x[a - 1];
		x[a - 1] = x[b - 1];
		x[b - 1] = s;
	}
	for (int i = 0; i<w; i++) {
		cout << x[i] << endl;
	}
}


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

int main() {
	int n;
	n = 4;
	std::vector<int> vec(n);
	for (int i = 1; i < n; i++) {
		std::cin >> vec.at(i);
	}
	std::sort(vec.begin(), vec.end());
	std::cout << vec[1] << " " << vec[2] << " " << vec[3] << std::endl;
}


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

int main(int argc, const char * argv[]) {
    double x1, y1, x2, y2;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    printf("%.8lf\n", sqrt(pow((x2-x1),2)+pow((y2-y1),2)));
    return 0;
}



Measured memory_bytes: 2108
#include<iostream> 
#include<vector> 
#include<algorithm> 
using namespace std; 
#define lld long long int
#define X 1000000007
#define fast();  ios_base::sync_with_stdio(false); cin.tie(0);
# define rec(i,n) for(int i=0;i<n;i++) 
#define w(t) int t; cin>>t; while(t--)
int h,w; 
char a[1000][1000]; 
lld dp[1000][1000]; 
int main()
{
    fast(); 
     cin>>h>>w; 
     rec(i,h) 
       rec(j,w) 
          { dp[i][j]=0; 
          cin>>a[i][j]; 
          }
       rec(i,w) 
        { if(a[0][i]=='#')
           { break;  }
          dp[0][i]=1; 
        } 
           rec(i,h) 
        { if(a[i][0]=='#')
           { break; }
         dp[i][0]=1; 
        } 
        for(int i=1;i<h;i++) 
          for(int j=1;j<w;j++) 
           { if(a[i][j]=='#') 
               { dp[i][j]=0; 
                 continue; }
             dp[i][j]=dp[i-1][j] +dp[i][j-1]; 
             dp[i][j]%=X; 
           }
      cout<<dp[h-1][w-1]<<endl; 
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 200005;

char str[MAXN];
int fail[MAXN];
lint dp[222];
lint cnt[222][26];

vector<lint> solve(lint p, int s, int t){
	memset(dp, 0, sizeof(dp));
	memset(cnt, 0, sizeof(cnt));
	vector<lint> dap(26);
	dp[0] = s;
	dp[1] = s+t;
	vector<int> v;
	for(int i=0; i<s; i++){
		cnt[0][str[i] - 'a']++;
	}
	for(int i=0; i<s+t; i++){
		cnt[1][str[i] - 'a']++;
	}
	for(int i=2; i<100; i++){
		for(int j=0; j<26; j++){
			cnt[i][j] = cnt[i-1][j] + cnt[i-2][j];
		}
		dp[i] = (dp[i-1] + dp[i-2]);
		if(dp[i] >= p){
			for(int j=i; j>=0; j--){
				while(p >= dp[j]){
					p -= dp[j];
					v.push_back(j);
				}
			}
			break;
		}
	}
	for(int i=0; i<p; i++){
		dap[str[i] - 'a']++;
	}
	for(auto &i : v){
		for(int j=0; j<26; j++){
			dap[j] += cnt[i][j];
		}
	}
	return dap;
}

int main(){
	scanf("%s", str);
	int p = 0;
	for(int i=1; str[i]; i++){
		while(p && str[i] != str[p]) p = fail[p];
		if(str[i] == str[p]) p++;
		fail[i + 1] = p;
	}
	int n = strlen(str);
	int s = n / 2 - fail[n / 2];
	int t = fail[n / 2];
	lint l, r; cin >> l >> r;
	auto x = solve(r, s, t);
	auto y = solve(l - 1, s, t);
	for(int i=0; i<26; i++){
		printf("%lld ", x[i] - y[i]);
	}
}


Measured memory_bytes: 1408
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;
using ll = long long;

const ll infl = 1LL << 60;
ll mul(ll a, ll b)
{
    if (infl / a < b)
        return infl;
    return min(infl, a * b);
}
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
ll lcm(ll a, ll b)
{
    if (a == infl || b == infl)
        return infl;
    return mul(a / gcd(a, b), b);
}

int main(void)
{
    int k;
    cin >> k;
    long long sum = 0;
    rep(a, 1, k + 1)
    {
        rep(b, 1, k + 1)
        {
            rep(c, 1, k + 1)
            {
                sum += gcd(gcd(a, b), c);
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3632
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
void *wmem;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
template<class T> inline void walloc1d(T **arr, int x, void **mem = &wmem){
  static int skip[16]={0, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
  (*mem) = (void*)( ((char*)(*mem)) + skip[((unsigned long long)(*mem)) & 15] );
  (*arr)=(T*)(*mem);
  (*mem)=((*arr)+x);
}
inline void rd(long long &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline int Digit_L(T n){
  int res=0;
  while(n){
    res++;
    n /= 10;
  }
  return res;
}
template<class T> int Factor_L(T N, T fac[], int fs[]){
  T i;
  int sz=0;
  if(N%2==0){
    fac[sz] = 2;
    fs[sz] = 1;
    N /= 2;
    while(N%2==0){
      N /= 2;
      fs[sz]++;
    }
    sz++;
  }
  for(i=3;i*i<=N;i+=2){
    if(N%i==0){
      fac[sz] = i;
      fs[sz] = 1;
      N /= i;
      while(N%i==0){
        N /= i;
        fs[sz]++;
      }
      sz++;
    }
  }
  if(N > 1){
    fac[sz] = N;
    fs[sz] = 1;
    sz++;
  }
  return sz;
}
template<class T> int Divisor_L(T N, T res[], void *mem = wmem){
  T *fc;
  int *fs, fsz, i, j, k, s, sz=0;
  walloc1d(&fc, 100, &mem);
  walloc1d(&fs, 100, &mem);
  fsz =Factor_L(N, fc, fs);
  res[sz++] = 1;
  for(i=0;i<(fsz);i++){
    s = sz;
    k = s * fs[i];
    for(j=0;j<(k);j++){
      res[sz++] = res[j] * fc[i];
    }
  }
  sort(res, res+sz);
  return sz;
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
char memarr[96000000];
long long N;
int ys;
long long y[100000];
int main(){
  int i, res=1073709056;
  wmem = memarr;
  rd(N);
  ys =Divisor_L(N, y);
  for(i=0;i<(ys);i++){
    chmin(res, max_L(Digit_L(y[i]),Digit_L(N/y[i])));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190827-1

// --- original code ---
// ll N;
// int ys; ll y[1d5];
// {
//   int i, res = int_inf;
//   rd(N);
//   ys = Divisor(N, y);
//   rep(i,ys) res <?= max( Digit(y[i]), Digit(N/y[i]) );
//   wt(res);
// }


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



int main(){
  int a;
  cin >> a;
  int big = 0;
  int ans = 0;
  for(int i = 0;i < a;i++){
    if(i == 0){
      int d;
      cin >> d;
      big = d;
      ans++;
    }else{
      int d;
      cin >> d;
      if(big <= d){
        big = d;
        ans++;
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
  double  x,menseki,ensyu;
  double ritu = 3.141592653589;
  cin >> x;
  menseki = x * x * ritu;
  ensyu = 2 * x * ritu;
  printf("%.6f",menseki);
  cout << " ";
  printf("%.6f\n",ensyu);
  return 0;
}

Measured memory_bytes: 1252
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int a, siz;
	char c[1000], mj[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
	scanf("%s", c);
	siz = strlen(c);
	for (int i = 0; i < siz; i++)
	{
		a = c[i];
		if (a >= 68)
			cout << mj[a-68];
		else
			cout << mj[a+23-65];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3148
<?php
$N = (int)fgets(STDIN);
$A = array_map(function ($n) {
    return (int)$n;
}, explode(' ', fgets(STDIN)));

$memo_l = [];
$memo_r = [];
for ($i = 0; $i < $N; $i++) {
    $var_l = - $A[$i] - ($i + 1);
    $var_r = $A[$i] - ($i + 1);
    if (!array_key_exists($var_l, $memo_l)) {
        $memo_l[$var_l] = 0;
    }
    if (!array_key_exists($var_r, $memo_r)) {
        $memo_r[$var_r] = 0;
    }
    $memo_l[$var_l] += 1;
    $memo_r[$var_r] += 1;
}


$ans = 0;
foreach ($memo_l as $var_l => $num_l) {
    $num_r = $memo_r[$var_l];
    if ($num_r) {
        $ans += $num_l * $num_r;
    }
}


echo $ans;

Measured memory_bytes: 49712
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define PI acos(-1)
#define eps 1e-10
#define mem(x) memset(x,0,sizeof(x))
#define _for(x,y,z) for(int (x)=(y);(x)<=(z);(x)++)
#define __for(x,y,z) for(int (x)=(y);(x)>=(z);(x)--)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD)
{ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
template< typename T > inline void read(T &x) {
    static bool fr_f; static char fr_ch;
    fr_f=0; x=0; fr_ch=getchar();
    while(fr_ch<'0' || '9'<fr_ch) {if(fr_ch=='-') fr_f=1; fr_ch=getchar();}
    while('0'<=fr_ch && fr_ch<='9') {x=(x<<1)+(x<<3)+fr_ch-'0'; fr_ch=getchar();}
    if(fr_f) x=-x;
}
const int inf=-0x3f3f3f3f;
const int MAX=10000005;
const int MOD=1e9+7;
int a[1000009],b[1000009];
int main(){
    ll n,m,cc=0,dd=0;
    cin>>n;
    for(int i=0;i<n;i++ )
    scanf("%d",&a[i]);
    for(int i=0;i<n;i++ )
    scanf("%d",&b[i]);
    for(int i=0;i<n;i++ )
    {
        if(b[i]>=a[i])
        {
            cc+=(b[i]-a[i])/2;
        }
        else
        {
            dd+=(a[i]-b[i]);
        }
    }
    if(cc>=dd)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <string>
#include <queue>
#include <utility>
#include <math.h>
using namespace std;

int main(void){
 int N,sum = 0;
 cin >> N;
 long long B[N-1];
 long long A[N];
 for(int i = 0;i<N-1;i++){
     cin >> B[i];
 }
 A[0] = B[0];
 for(int i = 0;i<N-2;i++){
     if(B[i] > B[i+1]){
         A[i+1] = B[i+1];
     }else{
         A[i+1] = B[i];
     }
 }
 A[N-1] = B[N-2];


 for(int i=0;i<N;i++){
     sum = sum + A[i];
 }
 cout << sum << endl;
 return 0;
}

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

typedef pair< pair<int,int> , pair<int,int> > DATA;
DATA in[10000];

bool cmp1( const DATA &a , const DATA &b ){
	return a.first < b.first;
}
bool cmp2( const DATA &a , const DATA &b ){
	return a.second < b.second;
}
int main(){
	int n,q;
	while(cin >> n >> q && n){
		vector< pair<int,int> > tr[10001] , tc[10001];
		for(int i = 0 ; i < n ; i++){
			int x1 , y1 , x2 , y2;
			scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
			in[i].first.first   = x1;
			in[i].first.second  = x2;
			in[i].second.first  = y1;
			in[i].second.second = y2;
		}
		sort(in,in+n,cmp1);
		for(int i = 0 ; i < n ; i++){
			int x1 , y1 , x2 , y2;
			x1 = in[i].first.first;
			x2 = in[i].first.second;
			y1 = in[i].second.first;
			y2 = in[i].second.second;
			for(int i = y1 ; i < y2 ; i++) tr[i].push_back(make_pair(x1,x2));
		}
		sort(in,in+n,cmp2);
		for(int i = 0 ; i < n ; i++){
			int x1 , y1 , x2 , y2;
			x1 = in[i].first.first;
			x2 = in[i].first.second;
			y1 = in[i].second.first;
			y2 = in[i].second.second;
			if(q==2) for(int i = x1 ; i < x2 ; i++) tc[i].push_back(make_pair(y1,y2));
		}
		int area = 0 , perimeter = 0;
		// merge
		for(int i = 0 ; i < 10001 ; i++){
			if(tr[i].size() == 0) continue;
			//sort(tr[i].begin(),tr[i].end());
			
			int s = tr[i][0].first , e = tr[i][0].second;
			for(int j = 1 ; j < tr[i].size() ; j++){
				int S = tr[i][j].first , E = tr[i][j].second;
				if(S <= e){
					e = max(E,e);
				}else{
					area += e-s;
					perimeter += 2;
					s = S;
					e = E;
				}
			}
			perimeter += 2;
			area += e-s;
		}
		
		if(q == 2){
			for(int i = 0 ; i < 10001 ; i++){
				if(tc[i].size() == 0) continue;
				//sort(tc[i].begin(),tc[i].end());
				int s = tc[i][0].first , e = tc[i][0].second;
				for(int j = 1 ; j < tc[i].size() ; j++){
					int S = tc[i][j].first , E = tc[i][j].second;
					if(S <= e){
						e = max(E,e);
					}else{
						//cerr << s << "|" << e << endl;
						perimeter += 2;
						//c[i].push_back( make_pair(s,e) );
						s = S;
						e = E;
					}
				}
				//cerr << s << "|" << e << endl;
				perimeter += 2;
				//c[i].push_back( make_pair(s,e) );
			}
		}
		if(q == 1){
			cout << area << endl;
		}else{
			cout << area << endl;
			cout << perimeter << endl;
		}
	}
	
}

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

int frac(int n){
    if(n==0){
        return 1;
    }
    int ans=1;
    for(int i=1;i<=n;i++){
        ans = ans * i;
    }
    return ans;
}


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

    long long P,Q,P_10=0,Q_10=0;
    int P_bit[N],Q_bit[N];


    for(int i=0;i<N;i++){
        P_bit[i] = 1;
        Q_bit[i] = 1;
    }


    for(int i=0;i<N;i++){
        cin >> P;
        
        P_bit[P-1] = 0;

        int cnt=0;

        for(int i=0;i<P;i++){
            cnt += P_bit[i];
        }

        P_10 += cnt *frac(N-i-1);
    }

    for(int i=0;i<N;i++){
        cin >> Q;
        
        Q_bit[Q-1] = 0;

        int cnt=0;

        for(int i=0;i<Q;i++){
            cnt += Q_bit[i];
        }

        Q_10 += cnt *frac(N-i-1);
    }


    cout << abs(P_10-Q_10) << endl;

    return 0;

}

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i] < l[j] and l[j] < l[k] and l[i] < l[k]:
              if l[i] + l[j] > l[k] and  l[k] + l[j] > l[i] and  l[i] < l[j] + l[k]:
                ans += 1
print(ans)

Measured memory_bytes: 9200
N = int(input())
s = [int(input()) for i in range(N)]
ld = sorted(s, reverse=True)
D = int(s.index(ld[0]))

if N == 1:
    print(s[0])
else:
    for i in range(D):
        print(ld[0])
    print(ld[1])
    for i in range(N-D-1):
        print(ld[0])

Measured memory_bytes: 14112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000
int main() {
    long long n;
    cin >> n;
    long long a[n+1];
    for(long long i=0;i<n+1;i++) a[i] = INF;
    a[0] = 0;
    a[1] = 1;

    for(long long i=2;i<n+1;i++) {
        if(a[i]==INF) {

            for(long long j=i;j<n+1;j+=i) {

                if(a[j]==INF) a[j] = i;
            }
        }    
    }
    long long l[n+1];
    for(long long i=0;i<n+1;i++) l[i] = 0;

    long long p;
    for(long long i=2;i<n+1;i++) { 
        p = i;
        while(p!=1) {
            l[a[p]] +=1;
            p = p/a[p];      
        }
    }
    long long ans = 1;
    for(long long i=0;i<n+1;i++) {
        ans*=(l[i]+1);
        ans = ans % 1000000007;
    }
    cout << ans << endl;
}

//100 * 99 * 98


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

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


int main(){

    long long int n, m;
    cin>>n>>m;
    long long int result;
    if(n==2||m==2){
        result = 0;
    }else if(n==1&&m==1){
        result = 1;
    }else if(n==1||m==1){
        result = max(n, m) - 2;
    }else{
        result = (n - 2) * (m - 2);
    }

    cout << result << endl;

    return 0;
}

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

int main() {
  int N,Z,W;
  cin >> N >> Z >> W;
  vector<int> a(N);
  
  for (int i=0; i<N; i++) {
    cin >> a[i];
  }
  int ans = abs(a[N-1] - W);
  int term = 1000000007;
  for (int i=0; i<N-1; i++) {
    term = abs(a[i] - a[N-1]);
    for (int j=i+1; j<N-1; j++) {
      term = min(term,abs(a[j]-a[N-1]));
    }
    ans = max(ans,term);
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 200000
int main(){
    int n,R[MAX],i,minv,maxv;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d",&R[i]);
    }
    minv=R[0];
    maxv=R[1]-R[0];
    for(i=1; i<=n-1; i++){
        if(maxv<R[i]-minv)maxv=R[i]-minv;
        if(minv>R[i])minv=R[i];
    }
    printf("%d\n",maxv);
    return 0;
}


Measured memory_bytes: 2636
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

fn main() {
    input! {
        s: chars
    }

    let set = s .iter().cloned().collect::<std::collections::HashSet<_>>();
    println!("{}", if set.len() == s.len() {"yes"} else {"no"});
}

Measured memory_bytes: 4352
import java.util.*;
public class Main {

  public static void main (String[] args) {
	
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int[] L = new int[N+1];
  
    L[0] = 0;
    for (int i = 1; i <= N; i++) {
      L[i] = L[i-1] + sc.nextInt();
    }
    sc.close();

    int count = 0;
  
    if(L[N] <= X){
      count = N+1;
    } else {
      for (int i = 0; i <= N; i++) {
        if(L[i] <= X){
          count++;
        }
      }
    }
    
    System.out.println(count);

  }

}

Measured memory_bytes: 22996
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner ipt = new Scanner(System.in);
		int a = ipt.nextInt(), b = ipt.nextInt(), c = 0, ans = 0;
		while (true) {
			if (b == 1)
				break;
			ans++;
			if (ans != 1)
				c += (a - 1);
			else
				c = a;
			if (c >= b)
				break;
		}
		System.out.println(ans);
		ipt.close();
	}
}


Measured memory_bytes: 21204
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b >> c;
  cout << c << " " << a << " " << b << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int abs(int x){
  if (x>0){
    return x;
  } else {
    return -x;
  }
}
int main(){
  int W,a,b;
  cin >> W >> a >> b;
  if (abs(a-b)<=W){
    cout << 0;
  } else {
    cout << abs(a-b)-W;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <limits.h>
#include <assert.h>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long int
#define db double
#define ldb long double
#define MOD 1000000007
#define FI first
#define SE second
#define INF INT_MAX
#define NINF INT_MIN
#define L_INF LLONG_MAX
#define L_NINF LLONG_MIN
#define gc getchar
#define sz size

void fsscan()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void scan(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}

int main()
{
    //Write Your Code Here
    int a,b;
    string s;
    cin>>a>>b;
    cin>>s;
    int l=s.sz();
    if(s[a]!='-')
    {
        cout<<"No";
        return 0;
    }
    int flag=0;
    int c=0;
    for(int i=0;i<l;i++)
    {
        if(i==a)
        continue;
        
        int temp=s[i]-48;
        
        if((temp>=0&&temp<=9))
        {
            c++;
        }
            
    }
    if(c==l-1)
    cout<<"Yes";
    else
    cout<<"No";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 998244353;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	map<ll, ll> m;
	for (ll i = 0; i < N; ++i)
	{
		ll a; cin >> a;
		if (a == 0 && i != 0)
		{
			std::cout << 0 << std::endl;
			return 0;
		}
		++m[a];
	}

	if (m[0] != 1)
	{
		std::cout << 0 << std::endl;
	}
	else
	{
		ll res{1};
		for (auto &p : m)
		{
			for (ll i = 0; i < p.second; ++i)
			{
				if (p.first == 0) continue;
				(res *= m[p.first-1]) %= MOD;
			}
		}

		std::cout << res << std::endl;
	}
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
ll a[22];
signed main() {
	ll n, ans = 0;
	cin >> n;
	rep(i, n)cin >> a[i];
	for (int i = 0; i < n - 2; i++) {
		if (a[i + 1] != min({ a[i],a[i + 1],a[i + 2] }) && a[i + 1] != max({ a[i],a[i + 1],a[i + 2] }))ans++;
	}
	cout << ans << endl;
	ggr
}



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

typedef vector<int> vi;
typedef long long int ll;

int main(){

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, x;
	cin >> n >> x;

	ll sum = 0;
	vi a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}

	if(x > sum){
		cout << n - 1;
		return 0;
	}

	if(x == sum){
		cout << n;
		return 0;
	}

	sort(a.begin(), a.end());
	int count = 0;
	int i = 0;
	while(x > 0){
		x -= (a[i]);
		if(x >= 0){
			count++;
		}else{
			break;
		}
		i++;
	}

	cout << count;

	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  string s; std::cin >> s;
  ll n = s.size(), ans = 0, cnt = 0;
  rep(i, n) {
    if (s[i] == 'A') cnt++;
    else if (i+1 < n && s.substr(i, 2) == "BC") ans += cnt, i++;
    else cnt = 0;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 720
#include<stdio.h>
int main(){
  int a[5],n,i,j,tmp;
  for(n=0;n<5;n++){
    scanf("%d",&a[n]);
  }
  for(i=0;i<4;i++){
    for(j=4;j>i;j--){
      if(a[j]>a[j-1]){
	tmp=a[j];
	a[j]=a[j-1];
	a[j-1]=tmp;
      }
    }
  }
  printf("%d %d %d %d %d\n",a[0],a[1],a[2],a[3],a[4]);
  return (0);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define int long long
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) (x).size())
#define mp make_pair
#define pb push_back
#define forn(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

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




void solve() {
    int s, w;
    cin >> s >> w;
    if (w >= s) cout << "unsafe";
    else cout << "safe";
}



int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
#else
    solve();
#endif
    return 0;
}


Measured memory_bytes: 3616
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;

#define MOD 1000000007

struct BIT{
	vector<int> b;

	BIT(int n): b(n + 1) {}

	int sum(int i){
		int s = 0;
		while(i > 0){
			s += b[i];
			i -= i & -i;
		}
		return s;
	}

	void add(int i, int x){
		while(i < b.size()){
			b[i] += x;
			i += i & -i;
		}
	}
};

int fact[100001];

int main(){
	fact[0] = 1;
	for(LL i = 1; i <= 100000; ++i){
		fact[i] = fact[i-1] * i % MOD;
	}

	int n, r, s, t;
	while(scanf("%d%d", &n, &r) == 2){
		vector<int> p(n);
		for(int i = 0; i < n; ++i){
			p[i] = i + 1;
		}
		for(int i = 0; i < r; ++i){
			scanf("%d%d", &s, &t);
			swap(p[s-1], p[t-1]);
		}

		BIT bit(n);
		int ans = 0;
		for(int i = 0; i < n; ++i){
			LL s = bit.sum(p[n - 1 - i]);
			ans = (ans + s * fact[i]) % MOD;
			bit.add(p[n - 1 - i], 1);
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 2064
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

int main() {
	int n, m;
	cin >> n >> m;
	vector<P> vec(m);
	rep(i, m) {
		int s, c;
		cin >> s >> c;
		--s;
		vec[i].first = s;
		vec[i].second = c;
	}
	rep(x, 1000) {
		string st = to_string(x);
		if (st.size() != n) continue;
		bool ok = true;
		rep(i, m) {
			if (st[vec[i].first] - '0' != vec[i].second) ok = false;
		}
		if (ok) {
			cout << st << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s, d;
bool check(int train,int n){
  if(!train) return true;
  int shift = pow(2,train);
  if(n + shift > d) return false;
  for(int i = 0; i < 32; i++){
    if(abs(n) & (1<<i)){
      if(i && (1<<i) % shift == 0) return true;
      else return false;
    }
  }
  return true;
}
int cnt(int no){
  int i = 0;
  while(check(i,no)) i++;
  return i - 1;
}
int solve(int now, int cost){
  if(now == d) return cost;
  int train = cnt(now);
  if(now + pow(2,train) <= d){
    return solve(now+pow(2,train),cost+1);
  }else{
    return solve(now,cost+1);
  }
}
int main(){
  int N;
  cin >> N;
  while(N--){
    cin >> s >> d;
    cout << solve(s,0) << endl;
  }
}

Measured memory_bytes: 1200
#include "bits/stdc++.h"
using namespace std;

int main(){
  int n, k, d, t, c(0);
  cin >> n >> k;
  vector<vector<int>> snacks(n + 1);
  for (int i = 0; i < k; ++i) {
    cin >> d;
    //snukes.resize(d);
    for (int j = 0; j < d; ++j) {
      cin >> t;
      snacks[t].push_back(i + 1);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (snacks[i].empty()) c++;
  }
  cout << c << endl;
  return 0;
}

Measured memory_bytes: 3664
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>



using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)
























int main(){
    string s;
    cin >> s;
    
    bool f1 = false, f2 = false;
    if(s[0] == '0'){
        if(s[1] >= '1'){
            f1 = true;
        }
    }
    else if(s[0] == '1'){
        if(s[1] <= '2'){
            f1 = true;
        }
    }
    if(s[2] == '0'){
        if(s[3] >= '1'){
            f2 = true;
        }
    }
    else if(s[2] == '1'){
        if(s[3] <= '2'){
            f2 = true;
        }
    }
    
    if(f1 && f2){
        cout << "AMBIGUOUS" << endl;
    }
    else if(f1){
        cout << "MMYY" << endl;
    }
    else if(f2){
        cout << "YYMM" << endl;
    }
    else{
        cout << "NA" << endl;
    }
}

Measured memory_bytes: 256
use std::io;
use std::str::FromStr;

fn input_char_vec() -> Vec<char> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().chars().collect()
}

fn main() {
    let s = input_char_vec();
    let mut red = 0i32;
    let mut blue = 0i32;
    for c in &s {
        if *c == '0' {
            red += 1;
        } else {
            blue += 1;
        }
    }
    println!("{}", s.len() as i32 - (red - blue).abs());
}


Measured memory_bytes: 4352
def main():

    n = int(input())

    ans = n / 1.08

    ans_int = int(ans)
    #print(ans_int)

    if int(ans_int * 1.08) == n:
        print(str(ans_int))
    elif int((ans_int+1) * 1.08) == n:
        print(str(ans_int+1))
    else:
        print(':(')




if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define P (3)

int b64(char ch) {
    if('A'<=ch && ch<='Z') return ch-'A';
    if('a'<=ch && ch<='z') return ch-'a'+26;
    if('0'<=ch && ch<='9') return ch-'0'+52;
    return ch=='+' ? 62 : 63;
}

int w, h, p, f[1024][1024], m[128][128], tmp[128][128];
char tf[1000][200], tm[100][20];
typedef unsigned long long hash;
hash hori[1024][1024], hs[8];

int main() {
    for(;;) {
        scanf("%d%d%d", &w, &h, &p);
        if(w==0 && h==0 && p==0) return 0;
        rep(i, h) scanf(" %s", tf[i]);
        rep(i, p) scanf(" %s", tm[i]);
        memset(f, 0, sizeof(f));
        rep(i, h) for(int j=0; tf[i][j]; j++) {
            const int x = b64(tf[i][j]);
            rep(k, 6) if(x&(1<<k)) f[i][j*6+5-k] = 1;
        }
        memset(m, 0, sizeof(m));
        rep(i, p) for(int j=0; tm[i][j]; j++) {
            const int x = b64(tm[i][j]);
            rep(k, 6) if(x&(1<<k)) m[i][j*6+5-k] = 1;
        }
        rep(d, 8) {
            memcpy(tmp, m, sizeof(m));
            rep(i, p) rep(j, p) m[p-1-j][i] = tmp[i][j];
            if(d==4) {
                memcpy(tmp, m, sizeof(m));
                rep(i, p) rep(j, p) m[i][p-1-j] = tmp[i][j];
            }
            hs[d] = 0;
            rep(i, p) rep(j, p) hs[d] = hs[d]*P+m[i][j];
        }
        hash t = 1;
        rep(i, p) t *= P;
        rep(i, h) {
            hash k = 0;
            rep(j, w) {
                k = k*P+f[i][j];
                if(j>=p) k -= t*f[i][j-p];
                hori[i][j] = k;
            }
        }
        hash tt = 1;
        rep(i, p) tt *= t;
        int ans = 0;
        for(int i=p-1; i<w; i++) {
            hash k = 0;
            rep(j, h) {
                k = k*t+hori[j][i];
                if(j>=p) k -= tt*hori[j-p][i];
                if(j>=p-1) rep(z, 8) if(hs[z]==k) { ans++; break; }
            }
        }
        printf("%d\n", ans);
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rep2(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rev(i, n) for (int (i) = (n)-1; (i) >= 0; (i)--)
#define rev2(i, a, b) for (int (i) = (a)-1; (i) >= (b); (i)--)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pll = pair<long long, long long>;
template<class T> using Vec = vector<T>;
template<class T> using VVec = vector<vector<T>>;
long long TEN(int i) {return !i ? 1 : TEN(i-1)*10LL;}
template<class T, class U> 
bool chmin(T& a, const U& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T, class U> 
bool chmax(T& a, const U& b) {if (a < b) {a = b; return 1;} return 0;}

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

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//

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

	ll ans = -1 * TEN(18);
	chmax(ans, max({a * c, a * d, b * c, b * d}));
	if (a < 0 && b > 0 || c < 0 && d > 0) chmax(ans, 0);

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

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	// keisan
	if(n == 3 || n == 5 || n == 7){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	// syutsuryoku
}

Measured memory_bytes: 3584
# 累積和

import math
def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

# 2017数 かどうかのマップ
data = [0] * 10**5
# 処理系
for i in range(1, 10**5 + 1):
    if is_prime(i) and is_prime((i+1)//2):
        data[i-1] = 1

cumulative_sum = [0] * 10**5
cumulative_sum[0] = data[0]
for i in range(10**5 - 1):
    cumulative_sum[i+1] += cumulative_sum[i] + data[i+1]

# s_0 = 0 となるように
cumulative_sum = [0] + cumulative_sum

q = int(input())
for _ in range(q):
    l, r = map(int, input().split())
    print(cumulative_sum[r] - cumulative_sum[l-1])
    # print(sum(data[l:r+1]))


Measured memory_bytes: 13096
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>

using namespace std;

int main()
{
  int N, K;
  cin >> N >> K;
  int ans = K;
  for (int i = 1; i < N; ++i) {
    ans *= (K - 1);
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> nums(N);
  for (int i = 0; i < N; i++) {
    cin >> nums.at(i);
  }
  
  sort(nums.begin(), nums.end());
  reverse(nums.begin(), nums.end());
  
  int answer = 0;
  for (int i = 0; i < N; i++) {
    if ((i + 1) % 2 != 0) {
      answer += nums.at(i);
    } 
    else {
      answer -= nums.at(i);
    }
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <cmath>

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)

int main() {
  
  //input
  inputInt2(a,b);
  
  //main
  int ans = max(a+b, a-b);
  ans = max(ans, a*b);
  // 出力
  
  cout << ans << endl;
    
  return 0;
}

Measured memory_bytes: 256