akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

typedef struct TREE {
	int pair;
	int ans_pos;
};
int ans_color[100000];
vector <vector <TREE>> trees(100001);


void paint_edge(int from, int here, int edge_color) {
	int size = trees[here].size();
	int color = 1;
	for (int i = 0; i < size; i++) {
		int next_tree = trees[here].at(i).pair;
		if (next_tree != from) {
			// paint color
			if (color == edge_color) color++;
			ans_color[trees[here].at(i).ans_pos] = color;
			paint_edge(here, next_tree, color);
			color++;
		}
	}
}


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

	for (int i = 0; i <= N; i++)  trees[i].clear();
	for (int i = 1; i <= N-1; i++) {
		int a, b;
		cin >> a >> b;
		TREE t;
		t.pair = b;
		t.ans_pos = i;
		trees[a].push_back(t);
		t.pair = a;
		trees[b].push_back(t);
	}
	paint_edge(0, 1, 0);

	int K = 0;
	for (int i = 1; i <= N; i++) {
		K = max(K, (int)trees[i].size());
	}

	cout  << K << endl;
	for (int i = 1; i <= N-1; i++) {
		cout << ans_color[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 9344
import java.util.Scanner;
import java.util.Arrays;
import java.util.List;

public class Main {

    static List<Integer> A;
    static List<Integer> B;
    static List<Integer> C;

    public static void main(String args[]) {

        A = Arrays.asList(1, 3, 5, 7, 8, 10, 12);
        B = Arrays.asList(4, 6, 9, 11);
        C = Arrays.asList(2);
 
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();

        String answer = isSameGroup(x, y) ? "Yes" : "No";
        System.out.println(answer);
    }

    private static boolean isSameGroup(int x, int y) {
        if ((A.contains(x) && A.contains(y))
           || (B.contains(x) && B.contains(y))
           || (C.contains(x) && C.contains(y))) {
            return true;
        } else {
            return false;
        }

    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using ll = long long;
using namespace std;

long long a[105]/*weight*/, v[105]/*value*/;
long long dp[105][100005], n, w;
bool used[105][100005];

long long rec(long long pos, long long cur_w){
    if(pos == n){return 0;}
    if(used[pos][cur_w]){return dp[pos][cur_w];}
    used[pos][cur_w] = 1;
    long long r1 = -2e9, r2 = -2e9;
    r1 = rec(pos+1, cur_w);
    if(cur_w + a[pos] <= w){r2 = rec(pos+1, cur_w+a[pos]) + v[pos];}
    dp[pos][cur_w] = max(r1, r2);
    return dp[pos][cur_w];
}

int main() {
    cin>>n>>w;
    for(long long i = 0; i < n; i++){
        cin>>a[i]>>v[i];
    }
    cout<<max(rec(1, 0), rec(1, a[0])+v[0]);
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  int len = s.length();
  int answer = len;
  for (int i=0; i < len-1; i++)
    if (s[i]!=s[i+1]) answer = min(answer, max(i+1, len-i-1));
  cout << answer << endl;
  return 0;
}


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

struct node{
  struct node *migi;
  struct node *hidari;
  struct node *oya;
  int key;
};
typedef struct node * Node;

Node root,NIL;

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key )
      u = u->hidari;
    else u = u->migi;
  }
  return u;
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->hidari = NIL;
  z->migi = NIL;

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

  z->oya = y;

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

void sounyuu(Node u){
  if ( u == NIL ) return;
  sounyuu(u->hidari);
  printf(" %d", u->key);
  sounyuu(u->migi);
}

void kensaku(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  kensaku(u->hidari);
  kensaku(u->migi);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i=0 ; i<n ; i++ ){
    scanf("%s", com);

    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);

      if ( t != NIL )
	printf("yes\n");
      else printf("no\n");
    }

    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }

    else if ( com[0] == 'p' ){
      sounyuu(root);
      printf("\n");
      kensaku(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20436
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
 
flag = False
for i in range(H):
    for j in range(W):
        if s[i][j] == '#':
            if (j-1 >= 0 and s[i][j-1] == '.') and (j+1 < W and s[i][j+1] == '.') and (i-1 >= 0 and s[i-1][j] == '.') and (i+1 < H and s[i+1][j] == '.'):
                print('No')
                flag = True
                break
    if flag:
        break
else:
    print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(int, char**)
{

	string s;
	unsigned long long ans = 0;
	std::cin >> s;

	unsigned int tail = 0;
	for (uint i = 0; i < s.length(); i++) {
		if(s[i] == 'W') {
			int m = i - tail;
			ans += m;
      
			tail++;
		}

	}

	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main( )
{
    int n,i,j,sum=0;
    cin>>n;
    char a[n],b[n],c[n];  //三个二维数组存三个字符串
    scanf("%s %s %s",a,b,c);  //输入三个字符串
    for(i=0;i<n;i++)
    {

        if(a[i]!=b[i])  //ab不相等的情况下
        {
            if(a[i]!=c[i]&&b[i]!=c[i])  //三个不相等，变换两次
                sum+=2;
            if(a[i]!=c[i]&&b[i]==c[i])  //bc相等，和a不同，变换一次
                sum+=1;
            if(a[i]==c[i])  //ac相等，变换一次
                sum+=1;
        }
        if(a[i]==b[i])  //ab相等的情况下
        {
            if(a[i]!=c[i])  //ac不相等，变换一次
                sum++;
        }

    }
    cout<<sum<<endl;
    return 0;
}


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

void prime_factor(const int n, map<int, long long>& mp) {
    int n_ = n;
    for (int i = 2; i * i <= n; ++i) {
        int cnt = 0;
        while (n_ % i == 0) {
            ++cnt;
            n_ /= i;
        }
        if (cnt) mp[i] += cnt;
    }
    if (n_ != 1) mp[n_] += 1;
}

int main() {
    int N;  cin >> N;
    map<int, long long> mp;
    for (int i = 1; i <= N; ++i) {
        prime_factor(i, mp);
    }
    const int MOD = 1e9 + 7;
    long long ans = 1;
    for (auto e : mp) {
        ans = ans * (e.second + 1) % MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=2e5+11;
int n,ans;
int sz[N],x[N],y[N];
ll a[N],sum[N];
struct node{
	ll d;
	int id;
	inline void in(){
		gi(d);
	}
	inline bool operator<(node A)const{
		return d<A.d;
	}
}p[N];
int main(){
	gi(n);
	rep(i,1,n)
		sz[i]=1,sum[i]=0;
	rep(i,1,n)
		p[i].in(),p[i].id=i;
	sort(p+1,p+n+1);
	rep(i,1,n)
		a[i]=p[i].d;
	_rep(i,n,2){
		int pos=lower_bound(a+1,a+n+1,p[i].d-n+2*sz[p[i].id])-a;
		if(a[pos]!=p[i].d-n+2*sz[p[i].id]||p[i].id==p[pos].id){
			puts("-1");
			return 0;
		}
		sz[p[pos].id]+=sz[p[i].id];
		sum[p[pos].id]+=sum[p[i].id]+sz[p[i].id];
		x[++ans]=p[pos].id,y[ans]=p[i].id;
	}
	if(sum[p[1].id]!=a[1]){
		puts("-1");
		return 0;
	}
	rep(i,1,ans)
		printf("%d %d\n",x[i],y[i]);
	return 0;
}

Measured memory_bytes: 9088
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_HUMAN_MAX		100000									// 最大人数
#define D_MOD			1000000007								// 除数

// 内部変数
static int si1Abs[D_HUMAN_MAX];									// 絶対値
static int siHCnt;												// 人数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpT, *szpFpA;
#endif

// パターン数取得
int
fGetCnt(
)
{
	int i;

	// 絶対値取得
	for (i = 0; i < siHCnt; i++) {
		int liAbs;
#ifdef D_TEST
		fscanf(szpFpT, "%d", &liAbs);
#else
		fscanf(stdin, "%d", &liAbs);
#endif

		// 値チェック
		if (siHCnt % 2 == 0) {			// 偶数
			if (liAbs % 2 == 0) {			// 偶数
				return 0;
			}
		}
		else {							// 奇数
			if (liAbs % 2 == 1) {			// 奇数
				return 0;
			}
		}

		// データ数
		if (si1Abs[liAbs] >= 2) {		// 既に２件あり
			return 0;
		}
		else {
			si1Abs[liAbs]++;
		}
	}

	// 0データチェック
	if (si1Abs[0] >= 2) {			// ２件あり
		return 0;
	}

	// 指数
	int liCnt = siHCnt / 2;

	// パターン数
	int liRet = 1;
	for (i = 0; i < liCnt; i++) {
		liRet *= 2;
		liRet %= D_MOD;
	}

	return liRet;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// データ初期化
	memset(si1Abs, 0, sizeof(si1Abs));							// 絶対値

	// テストファイルオープン
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpT = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#endif

	// 人数取得
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpT);
#else
	fgets(lc1Buf, sizeof(lc1Buf), stdin);
#endif
	sscanf(lc1Buf, "%d", &siHCnt);

	// パターン数取得
	int liCnt = fGetCnt();

	// 結果セット
	sprintf(lc1Out, "%d\n", liCnt);

	// 結果表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpT);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 512
N, A, B, C = map(int, input().split())
L = []
for _ in range(N):
    L.append(int(input()))


def test(n, a, b, c, na, nb, nc):
    """
    :param n: 使用している竹の本数
    :param a: 竹aの長さ
    :param b: 竹bの長さ
    :param c: 竹cの長さ
    :param na: 竹aに使用した本数
    :param nb: 竹bに使用した本数
    :param nc: 竹cに使用した本数
    :return: 消費MP
    """
    if n == N:
        # 最終MPの確定
        if min(na, nb, nc) == 0:
            return 10**9
        else:
            mp = 0
            mp += (na-1) * 10 if na else 0
            mp += (nb-1) * 10 if nb else 0
            mp += (nc-1) * 10 if nc else 0
            mp += abs(A-a) + abs(B-b) + abs(C-c)
            return mp
    else:
        mp1 = test(n+1, a, b, c, na, nb, nc)  # 使用しない
        mp2 = test(n+1, a+L[n], b, c, na+1, nb, nc)  # 竹aに適用
        mp3 = test(n+1, a, b+L[n], c, na, nb+1, nc)  # 竹bに適用
        mp4 = test(n+1, a, b, c+L[n], na, nb, nc+1)  # 竹cに適用
        return min(mp1, mp2, mp3, mp4)


print(test(0, 0, 0, 0, 0, 0, 0))


Measured memory_bytes: 9208
h,w = map(int,input().split())
a =[]
for i in range(h):
    a.append(list(map(int,input().split())))
y = []
x = []
Y = []
X = []
n = 0
for i in range(h):
    for j in range(w):
        if a[i][j]%2 != 0:
            if j<w-1:
                n += 1
                y.append(i)
                x.append(j)
                Y.append(i)
                X.append(j+1)
                a[i][j+1] += 1
            elif i <h-1:
                n += 1
                y.append(i)
                x.append(j)
                Y.append(i+1)
                X.append(j)
                a[i+1][j] += 1
print(n)
for i in range(n):
    print(y[i]+1,x[i]+1,Y[i]+1,X[i]+1)

Measured memory_bytes: 15716
#include<bits/stdc++.h>
using namespace std ; 
#define ll long long
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
#define test  ll int tcase ; cin>>tcase ; while(tcase--) 
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
    io ; 
        int a[5] ; for(int i = 0 ;i<5 ; i++) cin>>a[i] ;

        ll int mul=1 ; 
        for(int i = 0 ; i<5 ; i++){
            mul*=a[i] ; 
            if(mul==0){
                cout<<i+1<<"\n" ; return 0 ; 
            }
        }
    
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+10;
ll n,S;
ll a[N],p[N],tag[N];
ll ans;
int main(){
	cin>>n>>S;
	for (int i=1;i<=n;i++)
		scanf("%lld%lld",&a[i],&p[i]);
	int l=1,r=n;
	while (a[l]<=S&&S<=a[r]){
		if (p[l]>=p[r]){
			if (!tag[l])ans+=a[r]-a[l],tag[l]=1;
			p[l]+=p[r];
			r--;
		}
		else {
			if (!tag[r])ans+=a[r]-a[l],tag[r]=1;
			p[r]+=p[l];
			l++;
		}
	}
	ans+=max(abs(S-a[l]),abs(S-a[r]));
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]

A, B = map(int, input().split())

def gcd(a, b):  # a >= b
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

hoge = gcd(A, B)

ans = 1
i = 2
while i * i <= min(A, B):
    if hoge % i == 0:
        ans += 1
        while hoge % i == 0:
            hoge /= i
    i += 1
if hoge != 1:
    ans += 1
    
print(ans)


Measured memory_bytes: 40172
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int v[51];

int main()
{
    int n, k, score, res = 0;
    cin >> n >> k;

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

    for (int i = 0; i <= k; i++)
    {

        int get, pack;

        get = min(i, n);
        pack = k - i;

        //左と右に回数振り分け
        int l, r;
        for (int g = 0; g <= get; g++)
        {
            score = 0;

            l = g;
            r = get - g;

            vector<int> p;
            //左から取る
            for (int j = 0; j < l; j++)
            {
                score += v[j];
                p.push_back(v[j]);
                //printf("l score=%d v=%d\n", score, v[j]);
            }

            //右から取る
            for (int j = 0; j < r; j++)
            {
                score += v[n - j - 1];
                p.push_back(v[n - j - 1]);
                //printf("r score=%d v=%d\n", score, v[n - j - 1]);
            }

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

            //詰める
            for (int j = 0; j < pack && j < p.size(); j++)
            {
                if (p[j] >= 0)
                {
                    break;
                }
                else
                {
                    score -= p[j];
                }
            }

            //printf("l=%d r=%d score=%d pack=%d\n", l, r, score, pack);
            res = max(res, score);
        }
    }

    cout << res << endl;
}

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

using namespace std;

using ull = unsigned long long;

int main() {
    int N;
    ull num = 0;
    cin >> N;
    for(int i = 0; i < N; ++i) {
        if(i+1 < 10){
            num++;
        }
        if(100 <= i+1 && i+1 < 1000){
            num++;
        }
        if(10000 <= i+1 && i+1 < 100000){
            num++;
        }
    }
    cout << num <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//

int main(void){
	int N,C,s,t,c,a[100010][32],b[100010]={},large=-1;
	scanf("%d%d",&N,&C);
	reg(i,1,100008)reg(j,1,C)a[i][j]=0;
	rep(i,N){
		scanf("%d%d%d",&s,&t,&c);
		a[s][c]++;
		a[t][c]--;
	}
	reg(i,1,100008){
		reg(j,1,C){
			if(a[i][j]>0){
				b[i-1]+=a[i][j];
			}else{
				b[i]+=a[i][j];
			}
		}
	}
	rep(i,100008){
		b[i+1]+=b[i];
		large = max(large,b[i]);
	}
	printf("%d\n",large);
}

Measured memory_bytes: 13312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MA=4294967295;

int main(){
	int n;
	cin>>n;
	int w[n],cum[n]={};
	int s=0;
	for(int i=0;i<n;i++){
		cin>>w[i];
	}	
	// sort(w,w+n);
	int ans=100000;
	for(int i=0;i<n;i++){
		s+=w[i];
		// if((i==n-1)||(w[i]!=w[i+1])){
		cum[i]=s;
		// }
	}
	for(int i=0;i<n;i++){
		// cout<<cum[i]<<" ";
		ans=min(ans,max(2*cum[i]-s,s-2*cum[i]));
	}
	// cout<<endl<<s<<endl;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>
#include <cmath>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define int long long // at least int64 > 9*10^18
#define ENDL '\n'
#define rep(i,n) for(int i = 0; i < (n); i++)
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n;
	std::cin >> n;
	if(n%2==1) {
		print(0);
		return 0;
	}
	int sum = 0;
	for(int i=5;i<n;i*=5) {
		sum+=n/2/i;
	}
	print(sum);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for(int i = 0; i < n; i++){
    cin >> x[i] >> y[i];
  }
  double ans = 0;
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      ans+=sqrt((x[i]-x[j])*(x[i]-x[j]) + (y[i]-y[j])*(y[i]-y[j]));
    }
  }
  double p = ans/n;
  cout << fixed << setprecision(10);
  cout << p << endl;
}

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

int N,A,B,C,X,Y,ans;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> N >> A >> B >> C >> X,N){
        ans=0;
        for (int i=0;i<N;++i){
            if (i!=0) ++ans,X=(A*X+B)%C;
            cin >> Y;
            while(ans<=10000&&X!=Y) ++ans,X=(A*X+B)%C;
        }
        cout << (ans<=10000?ans:-1) << endl;
    }
}


Measured memory_bytes: 3140
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long


int collats(int n){
  if(n%2==1&&n>1)return 3*n+1;
  else return n/2;
}
int main(){
  int s;cin>>s;
  vector<int> a(1000000);
  a[0]=s;
  int cnt=0;
  for(int i=1;i<1000000;i++){
    a[i]=collats(a[i-1]);
    if(a[i]==4){
      cnt=i;
      break;
    }
  }
  cout<<cnt+4<<endl;
}


Measured memory_bytes: 4096
n,q = map(int, input().split())
P = {}
Q = []
for i in range(n):
    a,b = input().split()
    P[a] = int(b)
    Q.append(a)
time = 0

while len(Q) > 0:
    if P[Q[0]] > q:
        time += q
        P[Q[0]] -= q
        Q.append(Q[0])
    else:
        time += P[Q[0]]
        P[Q[0]] = 0
        print("{} {}".format(Q[0], time))
    Q.remove(Q[0])


Measured memory_bytes: 11960
//#include <bits/stdc++.h>
 #include <algorithm>
  #include <bitset>
  #include <complex>
  #include <deque>
  #include <exception>
  #include <fstream>
  #include <functional>
  #include <iomanip>
  #include <ios>
  #include <iosfwd>
  #include <iostream>
  #include <istream>
  #include <iterator>
  #include <limits>
  #include <list>
  #include <locale>
  #include <map>
  #include <memory>
  #include <new>
  #include <numeric>
  #include <ostream>
  #include <queue>
  #include <set>
  #include <sstream>
  #include <stack>
  #include <stdexcept>
  #include <streambuf>
  #include <string>
  #include <typeinfo>
  #include <utility>
  #include <valarray>
  #include <vector>
  #include <array>
  #include <atomic>
  #include <chrono>
  #include <condition_variable>
  #include <forward_list>
  #include <future>
  #include <initializer_list>
  #include <mutex>
  #include <random>
  #include <ratio>
  #include <regex>
  #include <scoped_allocator>
  #include <system_error>
  #include <thread>
  #include <tuple>
  #include <typeindex>
  #include <type_traits>
  #include <unordered_map>
  #include <unordered_set>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;



int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall

  ini(n);
  ini(n1);
  ini(x);
  FOR(i,0,10){
      x*=n;
      x-=n1;
      out(x);
  }
  
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		long X = sc.nextLong();
		long Y = sc.nextLong();
		int count = 1;
		int a = 0;
		while( a==0 ){
			X = X*2;
			if( X>Y ){
				a = 1;
				break;
			}else{
				count++;
			}
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<vector>
#include<cmath>
int main(void){
    int x;
    std::cin >> x;
    bool flag = 0;
    for(int i = -1000; i < 1000; i++){
	for(int j = -1000; j < 1000; j++){
	    if(std::pow(i, 5) - std::pow(j, 5) == x){
		std::cout << i << " " << j << std::endl;
		flag = 1;
		return 0;
	    }
	}
    }
    return 0;
}


Measured memory_bytes: 4016
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define ifaxb(a, x, b) if (a < x && x < b)  // 比較は昇順
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define all(x) x.begin(), x.end()
#define pi 3.1415926536
#define ff first
#define ss second
#define pq priority_queue
#define ipair pair<int, int> s
#define lpair pair<LL, LL>
#define MP make_pair
#define INF 2147483647
#define _INF -2147483647
#define MM multimap
#define PB push_back
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int InputW;
    int InputS = 0;
    vector<int> S;

    for (int i = 0; i < N; i++) {
        cin >> InputW;
        InputS += InputW;
        S.push_back(InputS);
    }

    for (int i = 0; i < N; i++) {
        S[i] = abs(S[N - 1] - 2 * S[i]);
    }
    sort(all(S));
    cout << S[0] << endl;
}

Measured memory_bytes: 256
import os
import sys

import numpy as np


def solve(inp):
    def scc(n, links, rev_links):
        stack = np.zeros(n * 2, np.int64)
        checked = np.zeros(n, np.int8)
        postorder = np.zeros(n, np.int64)
        pi = 0

        for v in range(n):
            if checked[v]:
                continue

            # DFS1
            stack[0] = 0
            stack[1] = v
            si = 2
            while si > 0:
                i = stack[si - 2]
                v = stack[si - 1]
                if i == 0 and checked[v]:
                    si -= 2
                    continue
                checked[v] = 1
                l = len(links[v])
                while i < l and checked[links[v][i]] == 1:
                    i += 1
                if i == l:
                    postorder[pi] = v
                    pi += 1
                    si -= 2
                    continue
                stack[si - 2] = i + 1
                stack[si] = 0
                stack[si + 1] = links[v][i]
                si += 2

        postorder = postorder[::-1]
        checked = np.zeros(n, np.int8)
        sccs = []

        for v in postorder:
            if checked[v]:
                continue

            # DFS2
            stack[0] = v
            si = 1
            checked[v] = 1
            scc = [v]
            while si > 0:
                si -= 1
                v = stack[si]
                for u in rev_links[v]:
                    if checked[u] == 0:
                        checked[u] = 1
                        stack[si] = u
                        si += 1
                        scc.append(u)
            sccs.append(scc)

        return sccs

    n = inp[0]
    m = inp[1]
    aaa = inp[2::2]
    bbb = inp[3::2]

    int_list = [0]
    int_list.clear()
    links = [int_list.copy() for _ in range(n)]
    rev_links = [int_list.copy() for _ in range(n)]

    for i in range(m):
        a = aaa[i]
        b = bbb[i]
        if a != b:
            links[a].append(b)
            rev_links[b].append(a)

    return scc(n, links, rev_links)


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8[:],)', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
ans = solve(inp)
print(len(ans))
for scc in ans:
    print(len(scc), *scc)


Measured memory_bytes: 241864
#include<stdio.h>
 
void swap(int* a,int* b){
  int tmp=*a;
  *a=*b;
  *b=tmp;
}
 
int Partition(int A[],int p,int r){
  int x = A[r];
  int i=p-1,j;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      swap(&A[i],&A[j]);
    }
  }
  swap(&A[i+1],&A[r]);
  return i+1;
}
 
int main(){
  int n,i,x;
  int A[100000];
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  x=Partition(A,0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==x)printf("[");
    printf("%d",A[i]);
    if(i==x)printf("]");
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)
#define MOD 1000000007
#define deb(n) cout<<"[ "#n<<" = "<<n<<" ]"<<endl;
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const long long  MAX = 1 << 18;
int case_no = 1;
#define w(x) int x; cin>>x; while(x--)

int main() {
	FIO
	int n, mxm;
	long long ans = 0;
	cin >> n;
	vector<int> arr(n);
	for(int i = 0; i < n; i++) cin >> arr[i];
	mxm = arr[0];
	for(int i = 1; i < n; i++) {
		if(mxm > arr[i]) {
			ans += abs(arr[i] - mxm);
		}
		mxm = max(mxm, arr[i]);
	}
	cout << ans << endl;

	return 0;
}

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

int main(void){
    string S;
    string headbuf = "";
    string footbuf = "";
    int Q, Tbuf, Fbuf;
    char Cbuf;
    int inverted = 0;
    cin >> S;
    cin >> Q;
    for(int i=0; i<Q; i++){
        cin >> Tbuf;
        if(Tbuf == 1){
            inverted = 1-inverted;
        }else{
            cin >> Fbuf;
            cin >> Cbuf;
            if((Fbuf+inverted)%2 == 1){
                headbuf += Cbuf;
            }else{
                footbuf += Cbuf;
            }
        }
    }
    if(inverted == 0){
        reverse(headbuf.begin(), headbuf.end());
        cout << headbuf << S << footbuf << endl;
    }else{
        reverse(footbuf.begin(), footbuf.end());
        reverse(S.begin(), S.end());
        cout << footbuf << S << headbuf << endl;
    }
    return 0;
}

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


ll fun(ll n, ll x)
{
	if (x > n)return 0;
	bool i3 = false, i5 = false, i7 = false;
	for (ll i = x; i > 0; i /= 10){
		if (i % 10 == 3)i3 = true;
		if (i % 10 == 5)i5 = true;
		if (i % 10 == 7)i7 = true;
	}
	ll res = fun(n, x * 10 + 3) + fun(n, x * 10 + 5) + fun(n, x * 10 + 7);
	if (i3 && i5 && i7)res++;
	return res;
}
	

int main()
{
	ll n, ans = 0;
	cin >> n;
	cout << fun(n,0) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include <algorithm>
#include <functional>

using namespace std;

int main (void){
    int H,M,N;
    cin >> H >> M >> N ;
    int sum=0;
    int kai=0;
    int h = H;
    int m = M;
    for(int i=0;i<H*M;i++){
        if(sum >= N){
            kai = i;
            break;
        }
        else{
            if(h>m){
                sum+=h;
                m--;
            }
            else{
                sum+=m;
                h--;
            }
        }
    }   
    cout << kai << endl;
    return 0; 
}

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

int arr[200005];
int n;
int main() 
{
	cin>>n;
	for(int i = 0; i < n- 1 ; i++){
		int x ; cin>>x;
		arr[x]++;
	}
	for(int i = 1 ;i <= n ;i++)
		cout<<arr[i]<<endl;
    return 0;
} 



Measured memory_bytes: 4400
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
while(true){
   var ab=arr.shift().split(" ").map(Number);
   if(ab.join(" ")=="0 0")break;
   var a=ab[0];
   var b=ab[1];
   var A=[];
   var B=[];
   for(i=1;i<=Math.sqrt(a);i++){
      if(a%i==0)A.push([a/i,i]);
   }
   for(i=1;i<=Math.sqrt(b);i++){
      if(b%i==0)B.push([b/i,i]);
   }
   var min=Infinity;
   A.forEach(function(va){
      B.forEach(function(vb){
         var c=[va[0],va[1],vb[0],vb[1]];
         c.sort(function(a,b){return a-b;});
         min=Math.min(min,Math.pow(c[0]-c[1],2)+Math.pow(c[1]-c[2],2)+Math.pow(c[2]-c[3],2));
      });
   });
   console.log(min);
}

Measured memory_bytes: 20236
#include <iostream>
using namespace std;
int main()
{
  string w;
  cin >> w;
  int a[26] = {0};
  for (int i = 0; i < w.length(); i++)
    a[w.at(i) - 'a']++;
  string ans = "Yes";
  for (int i = 0; i < 26; i++)
  {
    if (a[i] % 2 != 0)
      ans = "No";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
INF = 1e9

n = int(input())
adj_matrix = [list(map(int, input().split())) for i in range(n)]


def prim(x):
    isVisited = [False] * x
    d = [INF] * x 
    d[0] = 0
    p = [-1] * x 
    
    while True:
        min_cost = INF
        
        for i in range(x):
            if isVisited[i] != True and d[i] < min_cost:
                min_cost = d[i]
                u = i
        
        if min_cost == INF:
            break
        
        isVisited[u] = True
        
        for v in range(x):
            if isVisited[v] != True and adj_matrix[u][v] != -1:
                if adj_matrix[u][v] < d[v]:
                    d[v] = adj_matrix[u][v]
                    p[v] = u
    return sum(d)

print(prim(n))

Measured memory_bytes: 7952
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;
const double EPS=1e-10;

ll N;
double px[201],py[201],pz[201];
double vx[201],vy[201],vz[201];
double r[201],vr[201];
double CollisionTime(ll a,ll b){
    double pxDif=px[a]-px[b];
    double pyDif=py[a]-py[b];
    double pzDif=pz[a]-pz[b];
    double vxDif=vx[a]-vx[b];
    double vyDif=vy[a]-vy[b];
    double vzDif=vz[a]-vz[b];
    double rSum=r[a]+r[b];
    double vrSum=vr[a]+vr[b];
    double A=vxDif*vxDif+vyDif*vyDif+vzDif*vzDif-vrSum*vrSum;
    double B=pxDif*vxDif+pyDif*vyDif+pzDif*vzDif+rSum*vrSum; // b/2
    double C=pxDif*pxDif+pyDif*pyDif+pzDif*pzDif-rSum*rSum;
    if(abs(A)<EPS){
        if(abs(B)<EPS){
            return INF;
        }
        else if(B>0){
            return INF;
        }else{
            return -C/(2*B);
        }
    }
    if(B*B-A*C < EPS)return INF;
    double ans1=(-B-sqrt(B*B-A*C) )/A;
    if(ans1>EPS)return ans1;
    return INF;
}
int main(){
    cout<<setprecision(10);
    while(cin>>N,N!=0){
        for(ll i=0;i<N;i++){
            cin>>px[i]>>py[i]>>pz[i]>>vx[i]>>vy[i]>>vz[i]>>r[i]>>vr[i];
        }
        vector<pair<double,P>> v;
        for(ll i=0;i<N;i++){
            for(ll j=i+1;j<N;j++){
                v.push_back( make_pair(CollisionTime(i,j),P(i,j)) );
            }
        }
        for(ll i=0;i<N;i++){
            v.push_back( make_pair(r[i]/vr[i],P(-1,i) ) );
        }
        sort( v.begin(),v.end() );
        bool erased[201]={};
        double ans[201]={};
        for(auto x:v){
            if(x.second.first==-1 && !erased[x.second.second]){
                erased[x.second.second]=true;
                ans[x.second.second]=x.first;
            }else{
                if(!erased[x.second.first] && !erased[x.second.second]){
                    erased[x.second.first] = true;
                    erased[x.second.second]= true;
                    ans[x.second.first] = x.first;
                    ans[x.second.second]= x.first;
                }
            }
        }
        for(ll i=0;i<N;i++){
            printf("%.10lf\n",ans[i]);
        }
    }
    return 0;
}


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

int main(){
  long long n; cin >> n;
  long long a, b, cnt = 0;
  a = n / 500;
  cnt += a * 1000;
  b = (n - a * 500) / 5 * 5;
  cnt += b;
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N);
  VEC(ll, A, N);
  int cnt = 0;
  rep(i, 0, N) {
    if (A[i] < 0) {
      cnt++;
      A[i] = abs(A[i]);
    }
  }
  sort(all(A));
  ll ans = accumulate(all(A), 0ll);
  if (cnt % 2) {
    ans -= A[0] * 2ll;
  }
  print(ans);
}


Measured memory_bytes: 1024
N,M=map(int,input().split())

intv = [1,N]
for i in range(M):
  L,R=map(int,input().split())
  if intv[0] < L:
    intv[0] = L
  if R < intv[1]:
    intv[1] = R

#print(intv)
print(max(intv[1]-intv[0]+1,0))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#define ll long long int
using namespace std;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if (a >= k)
	{
		ans += k;
	}
	else
	{
		ans += a;
		k = k - a;
		if (k >= b)
		{
			k = k - b;
			ans += (-1 * k);
		}
	}
	cout << ans;
	return 0;

}

Measured memory_bytes: 3636
#include <iostream>
#include <stack>

int main(void) {
    std::stack<char> st;

    for (char ch; std::cin >> ch; st.push(ch));
    do {
        std::cout << st.top();
        st.pop();
    } while (!st.empty());
    std::cout << std::endl;

    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;

    loop(i,1,10)
    {
        loop(j,1,10)
        {
            if(i*j==n)
            {
                cout<< "Yes";
                return 0;
            }
        }
    }
    cout<< "No";
    return 0;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mod %
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
    int n; cin >> n;
    vector<int> d(n); rep(i,n) cin >> d.at(i);

    int s = d.size();
    sort(d.begin(),d.end());

    cout << d.at((s-1)/2+1) - d.at((s-1)/2) << endl;
}

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

int kotak[5][5];

int main()
{
	for(int a=0;a<3;a++)
	{
		for(int b=0;b<3;b++)
		{
			cin>>kotak[a][b];
		}
	}
	int a=0;
	int sel1=abs(kotak[a][0]-kotak[a][1]), sel2=abs(kotak[a][1]-kotak[a][2]);
	bool check=1;
	for(a=1;a<3;a++)
	{
		int h1=abs(kotak[a][0]-kotak[a][1]), h2=abs(kotak[a][1]-kotak[a][2]);
		if(sel1!=h1 || sel2!=h2)
		{
			check=0;
			break;
		}
	}
	if(check)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	cout<<endl;
	return 0;
}

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

int main(void) {
  int N, M;

  while (1) {
    vector<int> masu, dice;
    cin >> N >> M;
    if (N == 0 && M == 0) break;

    for (int i = 0; i < N; i++) {
      int tmp;
      cin >> tmp;
      masu.push_back(tmp);
    }
    for (int i = 0; i < M; i++) {
      int tmp;
      cin >> tmp;
      dice.push_back(tmp);
    }
  
    int pos = 1, turn = 1;

    while (turn < M) {
      pos += dice[turn-1];
      pos += masu[pos-1];
      if (pos >= N) break;
      turn++;
    }

    cout << turn << endl;
  }

  return 0;
}

Measured memory_bytes: 1228
(let* ((n (concatenate 'list (read-line))))
  (if (and (not (find #\L (loop :for k :in n :by #'cddr :collect k)))
           (not (find #\R (loop :for k :in (cdr n) :by #'cddr :collect k))))
      (princ "Yes")
      (princ "No")))

Measured memory_bytes: 9572
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c,d,x,y,z;
string s,t;
//

signed main() {
  RAPID;
  IN2(a,b);
  OUT(2*b-a);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using P = pair<int, int>;

int main(){
	int n;
    cin >> n;
    VI a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end());
    bool flag = true;
    rep(i,n-1){
        if(a[i] == a[i+1]) flag = false;
    }

    if(flag) cout << "YES" << endl;
    else cout << "NO" << endl; 

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
int main()
{
	int n,t,m;
	scanf("%d",&n);
	t=sqrt(n);
	m=t*t;
	if(n==t*t)
	printf("%d\n",n);
	else
	printf("%d\n",m);
	return 0;
} 

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

using namespace std;

int main(){
        int N, K;
        cin>>N>>K;
        vector <int> x(N);
        int res=0;
        for(int i=0;i<N;i++){
                cin>>x[i];
                res+=min(x[i], K-x[i]);
        }
        cout<<2*res<<endl;
        return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut aa: [usize; n],
    }

    let mut count = 0;
    let mut prev = 0;

    for i in 0..n {
        
        count += (prev + aa[i]) / 2;
        if aa[i] > 0 {
            prev = (prev + aa[i]) % 2;
        } else {
            prev = 0;
        }
        
    }

    println!("{}", count);
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  map<ll,ll> cnt;
  REP(i, 3){
    ll a; cin >>a;
    cnt[a]++;
  }
  ll ans = 0;
  FOREACH(x, cnt) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
/*関数プロトタイプ宣言*/
void diceRoll(int *d, char *r);
int main() {
	int dice1[6];	/*１つ目のサイコロ*/
	int max = 0;	/*１つ目のサイコロの面で最大の数字*/
	int dice2[6];	/*２つ目のサイコロ*/
	int front;		/*２つ目のサイコロの前面*/
	int flag = 1;	/*フラグ*/

	/*１つ目のサイコロの作成*/
	for (int i = 0; i < 6; i++) {
		scanf("%d", &dice1[i]);
		/*maxの取得*/
		if (max < dice1[i]) {
			max = dice1[i];
		}
	}

	/*１つ目のサイコロの上面がmaxと違うとき*/
	if (dice1[0] != max) {
		/*maxが１つ目のサイコロの前面にあったとき*/
		if (dice1[1] == max) {
			diceRoll(dice1, "N");
		}
		/*右面にあったとき*/
		else if (dice1[2] == max) {
			diceRoll(dice1, "W");
		}
		/*左面にあったとき*/
		else if (dice1[3] == max) {
			diceRoll(dice1, "E");
		}
		/*後面にあったとき*/
		else if (dice1[4] == max) {
			diceRoll(dice1, "S");
		}
		/*底面にあったとき*/
		else if (dice1[5] == max) {
			diceRoll(dice1, "NN");
		}
	}

	/*２つ目のサイコロの作成*/
	for (int i = 0; i < 6; i++) {
		scanf("%d", &dice2[i]);
		/*maxの取得*/
		if (max < dice2[i]) {
			max = dice2[i];
		}
	}

	/*２つ目のサイコロの上面がmaxと違うとき*/
	if (dice2[0]!= max) {
		//maxが２つ目のサイコロの前面にあったとき
		if (dice2[1] == max) {
			diceRoll(dice2, "N");
		}
		//右面にあったとき
		else if (dice2[2] == max) {
			diceRoll(dice2, "W");
		}
		//左面にあったとき
		else if (dice2[3] == max) {
			diceRoll(dice2, "E");
		}
		//後面にあったとき
		else if (dice2[4] == max) {
			diceRoll(dice2, "S");
		}
		//底面にあったとき
		else if (dice2[5] == max) {
			diceRoll(dice2, "NN");
		}
		//同じ面がなかったとき
		else {
			flag = 0;
		}
	}
	//前面の設定
	front = dice2[1];

	//２つ目のサイコロの前面が１つ目のサイコロと違うとき
	if (flag && dice1[1] != front) {
		//２つ目のサイコロの前面が１つ目のサイコロの右面にあったとき
		if (dice1[2] == front) {
			diceRoll(dice2, "L");
		}
		//左面にあったとき
		else if (dice1[3] == front) {
			diceRoll(dice2, "R");
		}
		//後面にあったとき
		else if (dice1[4] == front) {
			diceRoll(dice2, "RR");
		}
		//同じ面がなかったとき
		else {
			flag = 0;
		}
	}
	//２つのサイコロが同一だった場合
	if (flag && dice1[2] == dice2[2] && dice1[3] == dice2[3]
		&& dice1[4] == dice2[4] && dice1[5] == dice2[5]) {
		printf("Yes\n");
	}
	//同一でなかった場合
	else {
		printf("No\n");
	}

	return 0;
}

void diceRoll(int *d, char *r) {
	int x;        //入れ替え用変数
	for (int i = 0; r[i] != '\0'; i++) {
		switch (r[i]) {
			//右に転がす
		case 'E':
			x = d[0];
			d[0] = d[3];
			d[3] = d[5];
			d[5] = d[2];
			d[2] = x;
			break;
			//奥に転がす
		case 'N':
			x = d[0];
			d[0] = d[1];
			d[1] = d[5];
			d[5] = d[4];
			d[4] = x;
			break;
			//手前に転がす
		case 'S':
			x = d[0];
			d[0] = d[4];
			d[4] = d[5];
			d[5] = d[1];
			d[1] = x;
			break;
			//左に転がす
		case 'W':
			x = d[0];
			d[0] = d[2];
			d[2] = d[5];
			d[5] = d[3];
			d[3] = x;
			break;
			//右に９０度回す
		case 'R':
			x = d[1];
			d[1] = d[2];
			d[2] = d[4];
			d[4] = d[3];
			d[3] = x;
			break;
			//左に９０度回す
		case 'L':
			x = d[1];
			d[1] = d[3];
			d[3] = d[4];
			d[4] = d[2];
			d[2] = x;
			break;
		}
	}
}


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

using namespace std;
typedef long long int ll;

const ll mod = 1e9 + 7;


void solve()
{
	int n;
	cin >> n;
	int cnt= 0, flag = 0;
	int mas = 0;
	for(int i = 0; i <n; i++)
	{
		int x, y;
		cin >> x >> y;
		if(x == y) cnt++;
		else
		{
			mas = max(mas,cnt);
			cnt = 0;
		}
	}
	if(max(cnt,mas) >= 3) cout << "Yes\n";
	else cout << "No\n";
}

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
//	cin >> t;
	while(t--)
	{
		solve();
	}
}


Measured memory_bytes: 3640