akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


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

	double ans = 0;
	REP(i, N)
	{
		double x;
		string u;
		cin >> x >> u;
		if (u == "JPY")
		{
			ans += x;
		}
		else
		{
			ans += (x * 380000);
		}
	}

	cout << fixed << setprecision(10) << ans << endl;;
}



Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
#include <ctime>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  string s;
  ll res = 0;
  s = "3";
  while(1){
    //cout << s << endl;
    if(n < stoll(s))break;
    bool ok3 = false;
    bool ok5 = false;
    bool ok7 = false;
    for(int j = 0;j < s.size();j++){
      if(s[j] == '3')ok3 = true;
      if(s[j] == '5')ok5 = true;
      if(s[j] == '7')ok7 = true;
    };
    if(ok3 && ok5 && ok7){
      //cout << s << endl;
      res++;
    }
    for(int i = s.size() - 1;i >= 0;i--){
      if(s[i] == '3'){
        s[i] = '5';
        break;
      }
      else if(s[i] == '5'){
        s[i] = '7';
        break;
      }
      else s[i] = '3';
      if(i == 0){
        s = '3' + s;
        for(int j = 0;j < s.size();j++)s[j] = '3';
        break;
      }
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
A=set()
B=set()
for _ in range(m):
    a,b=map(int,input().split())
    if a==1:
        B.add(b)
    if b==n:
        A.add(a)
    
if len(A&B)!=0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")



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

#define fo(i,s,t) for(int i = s; i <= t; ++ i)
const int maxn = 200050;

int n, a[maxn], l, r, b[maxn];

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	b[n/2+1] = a[1]; l = r = n/2+1;
	for(int i = 2; i <= n; i += 2)
	{
		-- l; ++ r;
		if((n-i+1)%2==1) b[l] = a[i], b[r] = a[i+1];
		else b[r] = a[i], b[l] = a[i+1];
	}
	fo(i,1,n) printf("%d ",b[i]);
	return 0;
}

Measured memory_bytes: 3712
#include<stdio.h>
int main(){
  long a;
  long b;
  long k;
  scanf("%ld %ld %ld",&a,&b,&k);
  
  if(k<=a){
    printf("%ld %ld",a-k,b);
  }
  else if(a+b>k){
    //printf("%lu",a+b);
    printf("%ld %ld",0,a+b-k);
  }
  else printf("0 0");
}


Measured memory_bytes: 128
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

main :: IO ()
main = do
    n <- fst . fromJust . B.readInt <$> B.getLine
    as <- V.fromList . B.words <$> B.getLine
    let printn i = do
            B.putStr $ as `V.unsafeIndex` i
            B.putStr " "
    mapM_ printn [(n - 1), (n - 3) .. 0]
    mapM_ printn $ if odd $ V.length as then [1, 3 .. (n - 1)] else [0, 2 .. (n - 1)]


Measured memory_bytes: 24956
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;
	cin >> n;
	
	if(n < 1200)
	{
		cout << "ABC" << endl;
	}
	else
	{
		cout << "ARC" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;




int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	map<int, int> m, d;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		ans += d[x + i];
		ans += m[i - x];
		m[x + i]++;
		d[i - x]++;
		
	}
	cout << ans;
}

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

 int main()
 {
    int n,k,l=0,m;
    scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++)
    {
        scanf("%d",&m);
        if (m>=k)
            l++;
        }
        printf("%d",l);
 }


Measured memory_bytes: 256
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
	static boolean[][] judge;
	static int[] fieldX = {-1,0,1,0}, 
			fieldY = {0,-1,0,1};
	static void doing(int x, int y) {
		judge[y][x] = false;
		for (int i = 0; i < 4; i++) {
			if (judge[y+fieldY[i]][x+fieldX[i]]) doing(x + fieldX[i], y + fieldY[i]);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		while (sc.hasNext()) {
			judge = new boolean[20][20];
			for (int i = 1; i <= 12; i++){
				String temp = sc.next();
				for (int x = 1; x <= 12; x++) {
					judge[i][x] = temp.charAt(x - 1) == '1';
				}
			}
			int cnt = 0;
			for (int i = 1; i <= 12; i++) {
				for (int x = 1; x <= 12; x++) {

					if (judge[i][x]){ cnt++; doing(x, i);
					}

				}
			}
			out.println(cnt);
		}
		out.flush();
	}
}

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

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}
constexpr ll TEN(ll n){return n==0?1:10ll*TEN(n-1);}

constexpr ll inf = TEN(9)+5;
constexpr ll linf = 3*TEN(18);

const int mod = TEN(9)+7;

ll inv[200010];
ll fac[200010], fac_inv[200010];
ll C(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return ((fac[n] * fac_inv[k] % mod) * fac_inv[n - k]) % mod;
}
void comb_init()
{
    int N = 200005;
    inv[1] = 1;
    for (int i = 2; i <= N; ++i) {
        inv[i] = mod - (mod / i) * inv[mod % i] % mod;
    }
    fac[0] = fac_inv[0] = 1;
    for (int i = 1; i <= N; ++i) {
        fac[i] = (fac[i - 1] * i) % mod;
        fac_inv[i] = (fac_inv[i - 1] * inv[i]) % mod;
    }
}

signed main()
{
    comb_init();
    int S; cin >> S;

    int ans = 0;

    int cnt = 0;

    while (S - 2 > 0) {
        cnt++;
        S -= 2;

        ans += C(S - 1, cnt - 1);
        if (ans >= mod) ans -= mod;
    }

    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

const int MAX = 10000000;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/
/****** define variable start ******/
ll h, w;
ll cw, ch, dh, dw;
vector<vector<string>> s;
Graph G;
/******* define variable end *******/

typedef pair<ll, ll> P;
vector<ll> d;

void dijkstra(ll s){
	priority_queue<P, vector<P>, greater<P>> que;
	for(ll i = 0; i < h * w; i++) d[i] = INF;
	d[s] = 0;
	que.push(P(0, s));

	while(!que.empty()){
		P p = que.top(); que.pop();
		ll v = p.second;
		if(d[v] < p.first) continue;
		for(ll i = 0; i < G[v].size(); i++){
			Edge e = G[v][i];
			if(d[e.to] > d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

int solve() {
	cin >> h >> w;
	cin >> ch >> cw >> dh >> dw;
	s.resize(h, vector<string>(w));
	d.resize(h * w);
	REP(i, h){
		string tmp;
		cin >> tmp;
		REP(j, w){
			s[i][j] = tmp.substr(j, 1);
		}
	}
	G.resize(h * w);
	REP(i, h){
		REP(j, w){
			if(s[i][j] == "."){
				REP(h_magic, 5){
					REP(w_magic, 5){
						if(i + h_magic - 2 < h && i + h_magic - 2 >= 0 && j + w_magic - 2 < w && j + w_magic - 2 >= 0){
							if(s[i+h_magic-2][j+w_magic-2] == "."){
								if(abs(h_magic-2) + abs(w_magic-2) >= 2){
									Edge e = {w * (i + h_magic - 2) + (j + w_magic - 2), 1};
									G[w * i + j].push_back(e);
								}else{
									Edge e = {w * (i + h_magic - 2) + (j + w_magic - 2), 0};
									G[w * i + j].push_back(e);
								}
							}
						}
					}
				}
			}
		}
	}
	dijkstra((ch-1) * w + (cw-1));
	if(d[(dh-1) * w + (dw-1)] == INF) cout << -1 << endl;
	else cout << d[(dh-1) * w + (dw-1)] << endl;
	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...)
#endif
typedef long long ll;
typedef long double ld;
typedef complex<ll> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.txt", "r", stdin);
		//freopen("b.txt", "w", stdout);
	#endif

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

	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n-1);
	for (auto &i : a) cin >> i, --i;
	for (auto &i : b) cin >> i;
	for (auto &i : c) cin >> i;

	int ans = 0, last = -2;
	for (int i = 0; i < n; ++i)
	{
		ans += b[a[i]];
		if (a[i] == last+1) ans += c[a[i]-1];
		last = a[i];
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int i,a,b,j,s=0;
	cin>>a;
	for(int i=0;i<a;i++){
		cin>>b;
		if(b==2||b==3)s++;
		else{
		for(j=2;j*j<b;j++){
			if(b%j==0)break;
			if((j+1)*(j+1)>b)s++;
		}	}
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>

using namespace std;

int main() {
  int n;
  int a[201];
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  bool is_even = true;
  while(is_even) {
    for (int i = 0; i < n; i++) {
        if (a[i] % 2 == 0) {
          a[i] /= 2;
        } else {
          is_even = false;
          //cout << a[i] << endl;
          //cout << "break" << endl;
          break;
        }
    }
    if (is_even) {
      //cout << "count up----" << endl;
      count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
decode = ["afkpuz",
          "bglqv.",
          "chmrw?",
          "dinsx!",
          "ejoty "]
while True:
    try:
        line = map(int,list(raw_input()))
    except EOFError:
        break
    if len(line)%2 == 1 or 0 in line:
        print "NA"
        continue
    try:
        print "".join(decode[j-1][i-1]
                      for i,j in zip(line[::2],line[1::2]))
    except IndexError:
        print "NA"

Measured memory_bytes: 4216
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010

int main(){
	lint n,k;cin>>n>>k;
	liv a(n);rep(i,n)cin>>a[i];
	sort(all(a));
	lint ans=0;
	if(a[0]>k){ cout<<0<<endl;return 0; }
	rep(i,n){
		if(k>=a[i])k-=a[i],++ans;
		else{
			cout<<ans<<endl;return 0;
		}
	}if(!k)cout<<ans<<endl;
	else cout<<ans-1<<endl;
}

//sub-EOF


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int K,L = 0;
    cin >> K;
    for(int i = 0; i < K; i++){
        for(int j = 0; j < K; j++){
            if((i+1)%2 == 0 && (j+1)%2 != 0)
                L++;
                if((i+1)%2 != 0 && (j+1)%2 == 0)
                L++;
        }
    }
    cout << L/2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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;
}
///////////////////////////////////////////////

/*（๑•﹏•๑｀) */

int main() {
    int A[5] = {};
    int m = 0;
    REP(i,5){
        cin >> A[i];
        if (A[i] % 10 != 0){
            chmax(m,10 - (A[i] % 10));
            A[i] = (A[i] / 10) * 10 + 10;
        }
    }

    int ans = A[0] + A[1] + A[2] + A[3] + A[4] - m;
    cout << ans << "\n";


}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int n,i;
	int ans[64]={0};
	
	ans[0]=ans[1]=1;
	ans[2]=2;
	
	for(i=3;i<31;i++)
	{
		ans[i]=ans[i-1]+ans[i-2]+ans[i-3];
	}
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		cout << ans[n]/3650+1 << endl;
		
	}
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep1(i,n,a)    for(int i=0;i<n;i+=a)
#define rep2(i,n,a)    for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep1(i,n,1)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define trav(a,x)      for(auto x:a)
#define endl           "\n"
#define eb             emplace_back
#define fr             first
#define sc             second
#define gcd(a,b)       __gcd(a,b)
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)         (int)a.size()
#define pii            pair<int,int>
#define psi            pair<string,int>
#define pss            pair<string,string>
#define pll            pair<ll,ll>
#define vec            vector<int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
// syntax for min priority_queue of pairs
// priority_queue<pair<ll,ll>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
int solve(){
 int n;cin>>n;
 ll dp[n+1];
 ll arr[n+1];
 rep3(n)cin>>arr[i+1];
 dp[1]=0;
 dp[2]=abs(arr[2]-arr[1]);
 for(int i=3;i<=n;i++){ 
    dp[i]=dp[i-1]+abs(arr[i-1]-arr[i]);
    dp[i]=min(dp[i-2]+abs(arr[i-2]-arr[i]),dp[i]);
 }
 //for(int i=1;i<=n;i++)cout<<dp[i]<<" ";cout<<endl;
 cout<<dp[n]<<endl;   
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

Measured memory_bytes: 1792
fun main(args: Array<String>) {
        val input = read()
        println(cardGameForTwo(input))
    }

    data class Inputs(val count: Int, val cards: List<Int>)

    fun read(): Inputs {
        return Inputs(
            Integer.parseInt(readLine()!!),
            readLine()!!.split(' ').map { Integer.parseInt(it) }
        )
    }

    fun cardGameForTwo(inputs: Inputs): Int {
        val sorted = inputs.cards.sortedDescending()

        val alice = sorted.withIndex().sumBy { if (it.index % 2 == 0) it.value else 0 }
        val bob = sorted.withIndex().sumBy { if (it.index % 2 == 1) it.value else 0 }
        return alice - bob
    }

Measured memory_bytes: 38108
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif


struct edge {
  ll to, cost;
};
typedef pair<ll, ll> P;

ll V;
vector<edge> g[MAX]; // 頂点iのedgeを格納
ll d[MAX];
ll dans[MAX];

void dijkstra(ll s){
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, LLINF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;
        for(ll i=0; i<g[v].size(); i++){
            edge e = g[v][i];
            if(d[e.to] > d[v] + e.cost){
                // 更新
                d[e.to] = d[v] + e.cost;
				dans[e.to] = v;
                que.push(P(d[e.to], e.to));
            }
        }
    }

    // dがsからの各頂点への最短距離なので
    // rep(i, V){
    //     cout << d[i] << endl;;
    // }
}

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int N, M; cin >> N >> M;
	V = N;
	rep(i, M){
		int a, b;cin >> a >> b;
		a--; b--;
		g[a].push_back({b, 1});
		g[b].push_back({a, 1});
	}

	// d[0] =0;
	memr(dans, -1);
	dijkstra(0);

	bool ok = true;
	rep(i, N-1){
		if(dans[i+1] == -1) ok = false;
	}

	if(!ok){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
		rep(i, N-1){
			cout << dans[i+1] + 1 << endl;
		}
	}

	return 0;
}


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

#define int long long

#define pii pair<int, int>

#define x1 x1228
#define y1 y1228

#define left left228
#define right right228

#define pb push_back
#define eb emplace_back

#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << endl; 
#define TIME (ld)clock()/CLOCKS_PER_SEC

using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 500 + 7, mod = 1e9 + 7, MAXN = 1e6 + 7;
const double eps = 1e-9;
const ll inf = 1e18;
mt19937 rnd(time(0));
int n; 
int p[MAXN]; 
int dist[maxn][maxn]; 
int a[maxn][maxn]; 

vector<int> dx = {0, 0, -1, 1}; 
vector<int> dy = {-1, 1, 0, 0}; 

bool check(int x, int y) {
    return x >= 0 && y >= 0 && x < n && y < n; 
}

void bfs(int x, int y) {
    deque<pii> q;
    q.pb({x, y});
    while (q.size()) {
        pii t = q.front(); 
        q.pop_front(); 
        int xx = t.ff; 
        int yy = t.ss; 
        for (int dir = 0; dir < 4; ++dir) {
            int xx1 = xx + dx[dir]; 
            int yy1 = yy + dy[dir]; 
            if (check(xx1, yy1) && dist[xx1][yy1] > dist[xx][yy] + a[xx][yy]) {
                dist[xx1][yy1] = dist[xx][yy] + a[xx][yy];
                q.pb({xx1, yy1});  
            }
        }                
    }    
}

void solve() {
    for (int i = 0; i < maxn; ++i) for (int j = 0; j < maxn; ++j) dist[i][j] = inf; 
    for (int i = 0; i < maxn; ++i) for (int j = 0; j < maxn; ++j) a[i][j] = 1; 
    cin >> n;
    for (int i = 0; i < n * n; ++i) {                    
        cin >> p[i], --p[i]; 
    }                
    for (int i = 0; i < n * n; ++i) {
        int x = i / n; 
        int y = i % n; 
        dist[x][y] = min(dist[x][y], x); 
        dist[x][y] = min(dist[x][y], y); 
        dist[x][y] = min(dist[x][y], n - x - 1); 
        dist[x][y] = min(dist[x][y], n - y - 1); 
    }
    int ans = 0;                        
    for (int i = 0; i < n * n; ++i) {
        int x = p[i] / n; 
        int y = p[i] % n; 
        a[x][y] = 0; 
        ans += dist[x][y]; 
        bfs(x, y); 
    }  
    cout << ans << '\n'; 
}                                
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

Measured memory_bytes: 9624
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	fmt.Println(min(n%k, abs(k-n%k)))
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 512
#include <utility> // pair make_pair
using std::swap; // c++11
using std::pair;
using std::make_pair;
#include <tuple> // tuple(c++11) make_tuple(c++11)
using std::tuple; // get<address>(variable)
using std::make_tuple;
#include <string> // string stoi(c++11) stoll(c++11) to_string(c++11)
using std::string;
using std::stoi;
using std::stoll;
using std::to_string;
#include <queue> // queue priority_queue
using std::queue;
using std::priority_queue;
#include <stack> // stack
using std::stack;
#include <vector> // vector
using std::vector;
#include <map> // map
using std::map;
#include <set> // set
using std::set; // insert erase find count
#include <algorithm> // min max
using std::sort;
using std::lower_bound; // iterator,  >=
using std::upper_bound; // iterator,  >
using std::min;
using std::max;
using std::min_element; // iterator
using std::max_element; // iterator
#include <complex> // complex
using std::complex; // real imag
#include <iostream> // cin cout
using std::cin;
using std::cout;
using std::endl;
#include <iomanip> // setprecision fixed(manipulator)
using std::setprecision;
using std::fixed;
#include <cmath>
#include <cstdio>

#define lli long long int
#define INF (int)1e09
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define EFOR(i, m, n) for (int i = m; i <= n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REFOR(i, m, n) for (int i = m; i >= n; i--)
#define VSORT(v) sort((v).begin(), (v).end()) // sort vector
typedef pair<int, int> PI;
typedef tuple<int, int, int> TI;
template <typename T> using Vec = vector<T>; // c++11

int main(void) {
    int x;
    int y;
    int z;
    cin >> x >> y >> z;
    cout << (x - z) / (y + z) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string get(const vector<int>& a) {
	cout << "?";
	for (auto x : a) cout << " " << x+1;
	cout << endl;
	string buf;
	cin >> buf;
	if (buf == "-1") throw 1;
	return buf;
}

int main() {
	string buf;
	int N;
	cin >> N;
	if (N == 1) {
		cout << "? 1" << endl;
		cin >> buf;
		if (buf == "Red") {
			cout << "! RB" << endl;
		} else {
			cout << "! BR" << endl;
		}
		return 0;
	}
	vector<int> a0, a1, a2;
	for (int i = 0; i < N; ++ i) a1.push_back(i);
	for (int i = N; i < 2*N; ++ i) a2.push_back(i);
	if (get(a1) != "Red") swap(a1, a2);
	while (a1.size() > 1) {
		int n = a1.size() / 2;
		vector<int> a11(a1.begin(), a1.begin()+n);
		vector<int> a12(a1.begin()+n, a1.end());
		vector<int> a21(a2.begin(), a2.begin()+n);
		vector<int> a22(a2.begin()+n, a2.end());
		vector<int> b = a0;
		b.insert(b.end(), a11.begin(), a11.end());
		b.insert(b.end(), a22.begin(), a22.end());
		if (get(b) == "Red") {
			a0.insert(a0.end(), a22.begin(), a22.end());
			a1.swap(a11);
			a2.swap(a21);
		} else {
			a0.insert(a0.end(), a11.begin(), a11.end());
			a1.swap(a12);
			a2.swap(a22);
		}
	}
	string res(2*N, '?');
	for (auto x : a0) res[x] = '-';
	res[a1[0]] = 'R';
	res[a2[0]] = 'B';
	for (int i = 0; i < 2*N; ++ i) {
		if (res[i] == '?') {
			vector<int> b = a0;
			b.push_back(i);
			res[i] = get(b)[0];
		}
	}
	vector<int> a3, a4;
	for (int i = 0; i < 2*N; ++ i) {
		if (res[i] == 'R') a3.push_back(i);
		if (res[i] == 'B') a4.push_back(i);
	}
	vector<int> c { -1 };
	c.insert(c.end(), a3.begin(), a3.begin() + (N/2));
	c.insert(c.end(), a4.begin(), a4.begin() + (N/2));
	for (int i = 0; i < 2*N; ++ i) {
		if (res[i] == '-') {
			c[0] = i;
			res[i] = get(c)[0];
		}
	}
	cout << "! " << res << endl;
}


Measured memory_bytes: 724
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10


N = INT()

print((1000 - N%1000)%1000)

Measured memory_bytes: 10488
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, K;
string S;
vi va, vb;
int a[111][111];
int d[111];
set<int> st;
void input() {
  ;
  cin>>N>>K;
  rep(i,0,K-1){
    cin>>d[i];
    rep(j,0,d[i]-1){
      cin>>a[i][j];
      st.insert(a[i][j]);
    }
  }
  ;
}
void solve() {
  cout<<N-st.size()<<endl;
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define loop(v, st, en) for (int v = st; v < en; v++)
typedef long long ll;
typedef vector<int> vi;
int main () {
    int n ,cnt=0, arr[40];
    cin>>n;
    loop(i,0,n)cin>>arr[i];
    loop(i,1,n-1){
        if(arr[i]>arr[i-1] && arr[i]<arr[i+1])cnt++;
        if(arr[i]<arr[i-1] && arr[i]>arr[i+1])cnt++;
    }
    cout<<cnt;
    return 0;
}

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

int main() {
    int x, y;
    cin >> x >> y;
    int answer =0;
    for(int i = 0; i <=x; i++){
        int j = x -i;
        if(i * 2 + j * 4 == y){
            answer++;
        }
    }
    /*for (int i = 0; i <= x; i++){   
        for (int j = 0; i <= x; i++){
            if(i + j == x && 2*i + 4 * j == y  ){
                answer++;
            }
        }
    
    } */
    if(answer > 0){
        cout << "Yes" << endl;
    }
    else if(answer == 0){
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3632
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll a[100005];
int main() {
	int n;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	ll ans = 0;
	for (auto id : mp) {
		if (id.first > id.second) {
			ans += id.second;
		}
		else if (id.first < id.second) {
			ans += id.second - id.first;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7040
###for decant
###num配列修正版

n, m = input().split()
N = int(n)
M = int(m)
P = [input().split() for i in range(M)]

#numをwa_arr(int)とac_flag(bool)に分割
wa_arr=[0 for _ in range(N)]
ac_flag=[False for _ in range(N)]

for i in range(M):
    #問題番号
    q_num=int(P[i][0]) - 1
    #値が True か False になるので==はいらない
    if ac_flag[q_num]:
        #ACしてたらループ内の以下の処理は打ち切る
        continue
    if P[i][1] == "AC":
        ac_flag[q_num]=True
    else:
        wa_arr[q_num] += 1

cntac=0
cntwa = 0

for j in range(N):
    #ACしている問題のみWA数を追加
    if ac_flag[j]:
        cntac += 1
        cntwa += wa_arr[j]
print(cntac, cntwa)

Measured memory_bytes: 33908
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;

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

inline int encode(const vi &x, const int &w){
  int res = 0, k = 1;
  for(int p : x){
    res += k * p;
    k <<= 8;
  }
  return res;
}

inline vi decode(int x, const int &n, const int &w){
  int k = 1<<8;
  vi res(n);
  rep(i,n){
    res[i] = x & (k-1);
    x >>= 8;
  }
  return res;
}

short memo[1<<24];

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

  int h,w,n;
  string g[16];
  while(cin >> w >> h >> n, w){
    cin.ignore();

    vi start(n), end(n);
    rep(i,h){
      getline(cin,g[i]);
      rep(j,w){
	if(islower(g[i][j]))start[g[i][j]-'a'] = i*w+j;
	if(isupper(g[i][j]))end[g[i][j]-'A'] = i*w+j;
      }
    }
    int start_id = encode(start,w);
    int end_id = encode(end,w);

    vector<int> edge[256];
    rep(i,h)rep(j,w){
      if(g[i][j] == '#')continue;
      rep(d,5){
	int ny = i+dy[d], nx = j+dx[d];
	if(g[ny][nx] !='#')edge[i*w+j].push_back(ny*w+nx);
      }
    }

    memset(memo,-1,sizeof(memo));
    memo[start_id] = 0;
    queue<int> q;
    q.push(start_id);
    
    while(q.size()){
      int cur_id = q.front(); q.pop();
      vi cur = decode(cur_id,n,w), nxt(n);

      vi dir(n,0);
      while(dir[n-1]<(int)edge[cur[n-1]].size()){
	bool f = true;
	rep(i,n)nxt[i] = edge[cur[i]][dir[i]];

	for(int i=0;f && i<n;i++){
	  for(int j=0;f && j<i;j++){
	    if(nxt[i] == nxt[j])f = false;
	    if(nxt[i] == cur[j] && nxt[j] == cur[i])f = false;
	  }
	}

	if(f){
	  int nxt_id = encode(nxt, w);
	  if(memo[nxt_id] < 0){
	    memo[nxt_id] = memo[cur_id] + 1;
	    if(nxt_id == end_id)goto OUTPUT;
	    q.push(nxt_id);
	  }
	}

	dir[0]++;
	for(int i=0;i<n-1;i++){
	  if(dir[i]==(int)edge[cur[i]].size())dir[i] = 0, dir[i+1]++;
	}
      }

    }
  OUTPUT: cout << memo[end_id] << endl;
  }
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

LL fac[SIZE], finv[SIZE], inv[SIZE];
void combInit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for( int i = 2; i < SIZE; ++i ) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = (finv[i - 1] * inv[i]) % MOD;

    }
}

LL comb(int n, int k) {
    if( n < k ) return 0;
    if( n < 0 || k < 0 ) return 0;
    return (fac[n] * (finv[k] * finv[n - k] % MOD)) % MOD;

}

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int r,g;
    cin >> r >> g;
    cout << g * 2 - r << endl;
    return 0;
}


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

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

  vector<int> t(N), x(N), y(N);
  rep(i, N) cin >> t[i] >> x[i] >> y[i];

  bool ok = true;

  int ct = 0, cx = 0, cy = 0;
  rep(i, N) {
    int dd = abs(x[i] - cx) + abs(y[i] - cy);
    int dt = t[i] - ct;
    ct = t[i], cx = x[i], cy = y[i];
    if ((dd == 0 && dt >= 2 && dt % 2 == 0) || (dd <= dt && dt % dd == 0))
      continue;
    ok = false;
    break;
  }

  if (ok)
    puts("Yes");
  else
    puts("No");
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	int a,b; cin>>a>>b;
	ll c=a*b;
	cout<<(c%2==0 ? "Even":"Odd");
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=20005;
int b[N],n,x;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)scanf("%d",&x),b[x]+=i;
	for (int i=1;i<=n;i++)printf("%d ",(n+1)*i);
	puts("");
	for (int i=1;i<=n;i++)printf("%d ",(n+1)*(n-i+1)+b[i]);
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

void solve()
{
	vector<int> triangleNum;
	int a = 1;
	while(a * (a + 1) / 2 <= 100000)
	{
		triangleNum.push_back(a * (a + 1) / 2);
		++a;
	}
	int N;
	while(cin >> N, N)
	{
		vector<int> b(N);
		int sum = 0;
		for(int i = 0; i < N; ++i)
		{
			cin >> b[i];
			sum += b[i];
		}
		int index = -1;
		for(int i = 0; i < triangleNum.size(); ++i)
		{
			if(triangleNum[i] == sum)
			{
				index = i + 1;
			}
		}
		if(index == -1)
		{
			cout << -1 << endl;
			continue;
		}
		else if(index == b.size())
		{
			bool initOk = true;
			for(int i = 0; i < index; ++i)
			{
				if(b[i] != i + 1)
				{
					initOk = false;
					break;
				}
			}
			if(initOk)
			{
				cout << 0 << endl;
				continue;
			}
		}

		int count = 1;
		while(count < 10000)
		{
			vector<int> next;
			for(int i = 0; i < b.size(); ++i)
			{
				if(b[i] != 1)
				{
					next.push_back(b[i] - 1);
				}
			}
			next.push_back(b.size());

			if(next.size() == index)
			{
				bool ok = true;
				for(int j = 0; j < index; ++j)
				{
					if(next[j] != j + 1)
					{
						ok = false;
						break;
					}
				}
				if(ok)
				{
					cout << count << endl;
					break;
				}
			}
			++count;
			b = next;
		}
		if(count >= 10000)
		{
			cout << -1 << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
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 f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
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 pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

const int mxn = 2e5 + 100;
vi adj[mxn];
bool vis[mxn];
set<int> s;

void dfs(int v)
{
	vis[v] = 1;
	s.insert(v);
	for(int u : adj[v])
	{
		if(!vis[u])
			dfs(u);
	}
}

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

	int n, m, i, ans = 0, a , b;
	cin >> n >> m;
	while(m--)
	{
		cin >> a >> b;
		adj[a].eb(b);
		adj[b].eb(a);
	}
	for(i = 1; i <= n; i++)
	{
		if(!vis[i])
			dfs(i);
		ans = max(sz(s), ans);
		s.clear();
	}
	cout << ans;
}

Measured memory_bytes: 33528
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
//const long long MOD = 1000000007;
const long long MOD = 998244353;

using namespace std;

void solve()
{
    int a, b, c, d;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    c -= a;
    d -= b;

    int i;
    for (i = 0; i < c; i++) {
        printf("R");
    }
    for (i = 0; i < d; i++) {
        printf("U");
    }
    for (i = 0; i < c; i++) {
        printf("L");
    }
    for (i = 0; i < d; i++) {
        printf("D");
    }
    printf("D");
    for (i = 0; i < c+1; i++) {
        printf("R");
    }
    for (i = 0; i < d+1; i++) {
        printf("U");
    }
    printf("LU");
    for (i = 0; i < c+1; i++) {
        printf("L");
    }
    for (i = 0; i < d+1; i++) {
        printf("D");
    }
    printf("R");
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 128
#include <cstdio>
#include <set>

using namespace std;

int main(void) {
  int n, m;
  multiset<int> s;

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a; scanf("%d", &a);
    s.insert(a);
  }
  scanf("%d", &m);
  bool ok = true;
  for (int i = 0; i < m; i++) {
    int a; scanf("%d", &a);
    auto it = s.find(a);
    if (it == s.end()) {
      ok = false;
      break;
    }
    s.erase(it);
  }
  puts(ok ? "YES" : "NO");
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define lowbit(x) ((x)&(-(x)))
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const int maxn = 1e5 + 10;
int n, m;
int main()
{
    scanf("%d %d", &n, &m);
    printf("%d", n*(n-1)/2+m*(m-1)/2);
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

const int MAX_V = half_inf;

struct edge {
    ll to, cost;
};

ll n, q, k;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<> > que;
    fill(d, d + n, ll_inf);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); // queから最短距離が最小のものを取り出す
        que.pop();
        ll v = p.second; // 最短距離が最小のものの頂点
        if (d[v] < p.first) continue; // すでに最短距離が小さければ
        rep(i, G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                // 頂点vから張っている頂点への最短距離を求め，それを次にqueに入れる．
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i, n - 1) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        edge e1 = {b, c};
        G[a].emplace_back(e1);
        edge e2 = {a, c};
        G[b].emplace_back(e2);
    }
    cin >> q >> k;
    k--;
    dijkstra(k);
    rep(i, q) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        cout << d[x] + d[y] << endl;
    }
    return 0;
}

Measured memory_bytes: 11120
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int a, b;
    cin >> a >> b;
    
    if(a <= 8 && b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;

    return 0;
    
}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

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

const int inf=100000000;



int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n; cin>>n;
    vector<tuple<string, int, int>> bb;
    REP(i,n)
    {
    string s; int p;
    cin>>s>>p;
    int id=i+1;
    bb.emplace_back(s,100-p,id);
    }

    sort(begin(bb),end(bb));

    for(auto& x :bb)
    {
        int ans=get<2>(x);
        cout<<ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
bool flag = true;
  while(flag){
    int a, b;
    cin >> a >> b;
    if(a==0&&b==0)break;
    if(a>b)swap(a,b);
    cout << a << ' '<< b<< endl;
  }
}



Measured memory_bytes: 3084
from fractions import gcd
def factorization(n): # => {prime:count,...}
    fac = {}
    count = 0
    while n % 2 == 0:
        n //= 2
        count += 1
    if count > 0:
        fac[2] = count
    for i in range(3, int(n ** .5) + 1, 2):
        count = 0
        while n % i == 0:
            n //= i
            count += 1
        if count > 0:
            fac[i] = count
    if n > 1:
        fac[n] = 1
    return fac

A, B = map(int, input().split())
fac = factorization(gcd(A, B))
print(len(fac) + 1)


Measured memory_bytes: 10836