akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int id;
};
typedef struct node * Node;
Node root;

void insert(int k){//入力したい値
  Node x = root;
  Node parent = NIL;
  Node z;//新しいノード

  z = malloc(sizeof(struct node));//初期化
  z->id = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL){//子供のいち　左右　決定、　ついでにその時の親も
    parent = x; 
    if (z->id < x->id)x = x->left; 
    else x = x->right; 
  }
  
  z->parent = parent;

  if (parent == NIL)root=z;
  else if (z->id < parent->id)parent->left = z; // z を y の左の子にする//親の設定
  else parent->right = z; // z を y の右の子にする
}
//=============出力
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->id);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->id);
  preorder(u->left);
  preorder(u->right);
}
//===============
int main(){
  int n, i, x;
  char com[20];
  
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    
    if ( com[0] == 'i' ){//insert command
      scanf("%d", &x);
      insert(x);
    }
    else{//出力 print command
      inorder(root);
      printf("\n");
      
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}




Measured memory_bytes: 25176
def inpl(): return [int(i) for i in input().split()]

K = int(input())
A = list(reversed(inpl()))
X,Z = 2,2
for Ai in A:
    X = -(-X//Ai)*Ai
    if X > Z:
        print(-1)
        break
    Z = (Z//Ai)*Ai + Ai-1
else:    
    print(X, Z)


Measured memory_bytes: 14252
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#define INF 40
using namespace std;

int ball[12];
int flag ;
stack<int> A, B;


void dfs(int s)
{
	if (s >= 10)
	{
		flag = 1;
		return;
	}
	else if (ball[s] < A.top() && ball[s] < B.top())
	{
		return;
	}
	else {
		if (ball[s] > A.top())
		{
			A.push(ball[s]);
			dfs(s+1);
			A.pop();
		}
		if (ball[s] > B.top())
		{
			B.push(ball[s]);
			dfs(s+1);
			B.pop();
		}
	}
}


int main()
{
	int n;
	while (~scanf("%d",&n))
	{
		while (n--)
		{
			flag = 0;
			while (!A.empty())
			{
				A.pop();
			} 
			while (!B.empty())
			{
				B.pop();
			}
			A.push(0);
			B.push(0);
			memset(ball, 0, sizeof(ball));
			for (int i = 0;i < 10;i++)
			{
				scanf("%d", &ball[i]);
			}
			dfs(0);
			if (flag) printf("YES\n");
			else printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2580
f = lambda: map(int,input().split())
n = int(input())
a = sorted(list(f()))
s = [a[0]]
for i in range(n-1):
    s.append(s[-1]+a[i+1])
ans = 1
for i in range(2,n+1):
    if s[-i]*2<a[-i+1]:
        break
    ans += 1
print(ans)

Measured memory_bytes: 14316
#include <stdio.h>

int main(void){
	int n,a,s,t;
	while(1){
		s=0;
		scanf("%d",&n);
		if(n==0){
			return 0;;
		}
		for(t=0;t<n/4;t++){
			scanf("%d",&a);
			s+=a;
		}
		printf("%d\n",s);
	}
}

Measured memory_bytes: 600
/**
 *   author: malviyanshiv
 *   created: 09 January 2019  23:27:27
**/

#include <bits/stdc++.h>

using namespace std;

#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 PB push_back
#define MP make_pair
#define MOD 1000000007
#define INF 0x7fffffff
#define MAX 100005

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

void fastscan(int &x){
    bool neg=false;
    register int c;
    x =0;
    c=getchar();
    if(c=='-'){
        neg = true;
        c=getchar();
    }
    for(;(c>47 && c<58);c=getchar())
        x = (x<<1) + (x<<3) +c -48;
    if(neg)
        x *=-1;
}

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

vector<int> dp(MAX, -1);
vector<int> h(MAX);

int cal(int idx, int k ){
    if( idx <= 0 )
        return 0;
    if( dp[idx] != -1 )
        return dp[idx];

    int res = INF;
    for(int i = 1; i <=k; i++ )
        if( idx-i < 0 )
            break;
        else
            res = min( res, cal(idx-i, k) + abs(h[idx]-h[idx-i]));
    return dp[idx] = res;
}


int main(){
	optimizeIO();
    int n, k;
    cin >> n >> k;
    REP(i, 0, n)
        cin >> h[i];

    cout << cal(n-1, k ) << endl;
	
	return 0;
}


Measured memory_bytes: 7296
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long r = sc.NextLong();
        long g = sc.NextLong();
        long b = sc.NextLong();
        long n = sc.NextLong();

        long answer = 0;
        for (int i = 0; i * r <= n; i++)
        {
            for (int j = 0; j * g <= n; j++)
            {
                if (i * r + j * g > n)
                {
                    break;
                }

                long mod = n - i * r - j * g;

                if (mod % b == 0)
                {
                    answer++;
                }
            }
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

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

ll I, O, T, J, L, S, Z;

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> I >> O >> T >> J >> L >> S >> Z;
    ll ans = O + I / 2 * 2 + J / 2 * 2 + L / 2 * 2;
    if(I > 0 and J > 0 and L > 0){
        ans = max(ans, O + 3 + (I - 1) / 2 * 2 + (J - 1) / 2 * 2 + (L - 1) / 2 * 2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
while True:
    N = int(input())
    if N == 0:
        break
    PPP = []

    for i in range(N):
        P = set(list(map(int, input().split()))[1:])
        PPP.append(P)


    K = set(list(map(int, input().split()))[1:])
    # print(PPP)
    # print(K)

    potential = []
    for i, p in enumerate(PPP):
        hoge = K - p
        if len(hoge) == 0:
            potential.append(i+1)

    if len(set(potential)) != 1:
        print(-1)
    else:
        print(potential[-1])



Measured memory_bytes: 6332
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
multiset<string>s;
int main(){
	scanf("%d%d%d",&a,&b,&c);
	for(int i=1;i<=a;++i)s.insert("a");
	for(int i=1;i<=b;++i)s.insert("b");
	for(int i=1;i<=c;++i)s.insert("c");
	while(s.size()>1){
		string ss=*s.begin()+*--s.end();
		s.erase(s.begin());
		s.erase(--s.end());
		s.insert(ss);
	}
	cout<<*s.begin();
	return 0;
}

Measured memory_bytes: 384
from typing import Collection

from collections import defaultdict
n = int(input())

f = defaultdict(int)
for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            d = x * x + y * y + z * z + x * y + y * z + z * x
            if 1 <= d <= 10 ** 4:
                f[d] += 1
for i in range(1, n + 1):
    print(f[i])

Measured memory_bytes: 10868
#include <stdio.h>

int main(){

  int H,W,i,j,k;
  while(1){
  scanf("%d%d",&H,&W);
  if(H==0&&W==0) break;
  

  for(k=0;k<H;k++){
    for(j=0;j<W;j++){
      printf("#");
     }
     printf("\n");
   }
  printf("\n");
 }
  return 0;
}

Measured memory_bytes: 1000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

const int MAXN = 1e6+210;
ll M = 1e9+7;
ll powM(ll b, ll p) {
  if (p==0) return 1;
  ll ans = powM(b, p/2);
  ans = ans*ans%M;
  if (p%2) ans*=b;
  return ans%M;
}
ll inv(ll a)  {
  return powM(a, M-2);
}
ll fact[MAXN], invf[MAXN];

ll dp[MAXN], any[MAXN];

ll n, h, d;

int main(){
  cin.tie(0); ios_base::sync_with_stdio(0);
  fact[0] = invf[0] = 1;
  for(ll i = 1;i<MAXN;i++) {
    fact[i] = fact[i-1]*i%M;
    invf[i] = inv(fact[i]);
  }
  cin >> n >> h >> d;
  ll magic = 0;
  for(int j=1;j<=n;j++) {
    magic = (magic+fact[j])%M;
  }
  //cerr << "MAGIC IS " << magic <<endl;
  dp[h] = inv(magic);
  ll cum = dp[h];
  for(int i=h-1;i>=0;i--) {
    dp[i] = magic*cum%M;
    cum+=dp[i];
    //cerr << i << " " << dp[i] << " " << cum <<endl;
    if (i+d<=h) cum= (cum -dp[i+d]+M)%M;
    cum = (cum+M)%M;
  }
  cout << (dp[0]*fact[n]%M+M)%M <<endl;
}


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

int main(){
        int n;cin>>n;
        int v[n][3],dp[n][3];
        for(int i=0;i<n;i++)
        {
            cin>>v[i][0]>>v[i][1]>>v[i][2];

        }dp[0][0]=v[0][0];dp[0][1]=v[0][1];dp[0][2]=v[0][2];
         for(int i=1;i<n;i++)
         {
          dp[i][0]= v[i][0]+max(dp[i-1][1],dp[i-1][2]);
          dp[i][1]= v[i][1]+max(dp[i-1][0],dp[i-1][2]);
          dp[i][2]= v[i][2]+max(dp[i-1][1],dp[i-1][0]);
         }
         cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
	return 0;
}




Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;

int n;
typedef pair<int, int> P; //<cost, to>
vector<P> node[10];
priority_queue<P, vector<P>, greater<P> > que;

int dijkstra(int s, int city);

int main(){
  while(cin >> n, n){
    int city = -1;
    for(int i = 0; i < 10; i++) node[i].clear();
    for(int i = 0; i < n; i++){
      int a, b, c;
      cin >> a >> b >> c;
      node[a].push_back(P(c, b));
      node[b].push_back(P(c, a));
      city = max(city, a);
      city = max(city, b);
    }
    P mini = P(0, INT_MAX);
    for(int i = 0; i <= city; i++){
      int x = dijkstra(i, city);
      if(mini.s > x){
	mini.f = i;
	mini.s = x;
      }
    }

    cout << mini.f << " " << mini.s << endl;
  }
}

int dijkstra(int s, int city){
  int allcost = 0;
  for(int i = 0; i <= city; i++){
    que.push(P(0, s));
    int mincost = INT_MAX;
    bool moved[10][10] = {{false}};
    while(!que.empty()){
      P now = que.top(); que.pop();
      if(i == now.s) mincost = min(mincost, now.f);
      else{
	for(int j = 0; j < node[now.s].size(); j++){
	  P next = node[now.s][j];
	  if(!moved[now.s][next.s]){
	    moved[now.s][next.s] = true;
	    moved[next.s][now.s] = true;
	    next.f += now.f;
	    que.push(next);
	  }
	}
      }
    }
    allcost += mincost;
  }
  return allcost;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
const long long m=1e18;

int main(){
    int n;
    cin>>n;
    long long ans=1;
    vector<long long> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==0) {cout<<0<<endl; return 0;}
    }
    for(int i=0;i<n;i++){
        long long b=m/ans;
        if(a[i]>b) {cout<<-1<<endl; return 0;}
        ans*=a[i];
        if(ans>m){ cout<<-1<<endl;  return 0;}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<61;
const ll mod=1e9+7;

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 main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll i,j;
	ll n;
	cin>>n;
	int cnt=0;
	for(i=2;i*i<=n;i++){  //3桁以上
		ll nn=n;
		while(nn%i==0) nn/=i;
		if(nn%i==1) cnt++;
	}
	cnt++; //2桁 10
	n--;
	for(i=1;i*i<=n;i++){
		if(n%i==0) {
			j=n/i;
			if(i<j) cnt++;
		}
	}
	   // 2桁 p1 mod r
	   //n-1=pr 0<p<r


	cout<<cnt<<endl;
 
}

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

typedef long long ll;

ll table[45];
bool flg[45];

ll fib(int n){
    if(flg[n])return table[n];
    else{
        flg[n]=true;
        return table[n]=fib(n-1)+fib(n-2);
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    table[0]=table[1]=1;
    flg[0]=flg[1]=true;
    int n;
    cin >> n;
    cout << fib(n) << endl;
}



Measured memory_bytes: 3192
// template.cpp

// Defines.
//#define DEBUG
#define NUMBER_OF_DIGITS 6

// Includes.
#include <bits/stdc++.h>

#ifdef DEBUG
#include <chrono>
#endif

// Usings.
using namespace std;

// Main function.
int main()
{
#ifdef DEBUG
	chrono::system_clock::time_point start, end;
	
	start = chrono::system_clock::now();
#endif
	
	// settings.
	ios::sync_with_stdio(false);
	
	//cout << fixed;
	//cout << setprecision(NUMBER_OF_DIGITS);
	
	// logic.
	int n;
	cin >> n;
	
	bool flag = false;
	for (int i = 1; i <= 9; i++)
	{
		for (int j = 1; j <= 9; j++)
		{
			if (n == (i * j))
			{
				flag = true;
				goto END;
			}
		}
	}
	
END:
	if (flag == true)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

#ifdef DEBUG
	end = chrono::system_clock::now();
	
	double elapsed = chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
	cout << elapsed << "[ms]" << endl;
#endif
	
	return 0;
}


Measured memory_bytes: 3652
<?php

$input = trim(fgets(STDIN));
$input = explode(" ", $input);

$a = (int)$input[0];
$b = (int)$input[1];
$k = (int)$input[2];

for ($i=0; $i < $k; $i++) { 
	if ($i %2 === 0) {
		if ($a % 2 === 1) {
			$a -= 1;
		}
		$a = $a /2;
		$b += $a;
	}else{
		if ($b % 2 === 1) {
			$b -= 1;
		}
		$b = $b /2;
		$a += $b;
	}
}
echo $a . ' ' . $b ;

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

int main() {
    int h, w;
    cin >> h >> w;
    char s[h][w];
    rep(i, h) rep(j, w) cin >> s[i][j];

    rep(y, h) rep(x, w) {
        if (s[y][x] == '.') continue;

        bool ok = false;
        for (int dy = -1; dy <= 1; dy += 2) {
            int my = y + dy;
            if (my >= 0 && my < h) {
                if (s[my][x] == '#') ok = true;
            }
        }
        for (int dx = -1; dx <= 1; dx += 2) {
            int mx = x + dx;
            if (mx >= 0 && mx < w) {
                if (s[y][mx] == '#') ok = true;
            }
        }

        if (!ok) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M)
{
  int ret = n % m;
  if (ret < 0)
    ret += m;
  return ret;
}

int exp(int n, int k)
{
  if (k == 0)
    return 1;
  if (k == 1)
    return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2)
    ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b)
{
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution()
{
  string s;
  cin >> s;
  int m = 0;
  for (char c : s)
  {
    m = m * 10 + (c - '0');
    m %= 9;
  }
  if (m == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

int32_t main()
{
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--)
    solution();
}


Measured memory_bytes: 3748
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <limits.h>
#include <stdbool.h>

typedef double db;
typedef long int li;
typedef long long int lli;
typedef long ld;
typedef long lld;

#define pi M_PI
#define in scanf
#define out printf
#define inf INT_MAX
#define rep(i,n) for(int i=0;i<n;++i)
#define debugd(d) printf("%d\n",d)
#define debugs(s) printf("%s\n",s)
#define debugc(c) printf("%c\n",c)
#define debugf(f) printf("%f\n",f)


int main (void)
{
	int n;
	in("%d\n",&n);
	if(n==1)
	{
		puts("3");
		return 0;
	}
	lli ret=-1;
	int precol=-1;
	char str[n+1];
	int i;
	gets(str);
	for(i=0;i<n-1;++i)
	{
		if(str[i]==str[i+1]){
			if(precol==0)
			{
				ret *= 3;
			}
			else if (precol == 1)
			{
				ret *= 2;
			}
			else 
			{
				ret = 6;
			}
			precol = 0;
			++i;
		}
		else if(str[i]!=str[i+1])
		{
			if(precol == 0)
			{
				ret *= 1;
			}
			else if(precol==1)
			{
				ret *= 2;
			}
			else
			{
				ret = 3;
			}
			precol = 1;
		}
		ret %= 1000000007;

	}
	if(precol==1) {
		ret *= 2;
		ret %= 1000000007;
	}
	printf("%lld\n",ret);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

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

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return ('0' <= c && c <= '9')?(c - '0'):-1;}


bool isPrime(ll n) {
  if(n == 1)return false;
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}


// TODO: write
int main() {
  string s,t;cin>>s>>t;
  rep(i,s.size()+1){
    if(s == t){
      print("Yes");
      return 0;
    }
    string u = t;
    rep(j,t.size())t[(j+1)%t.size()] = u[j];
  }
  print("No");
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q; cin >> n >> q;
    string s; cin >> s;
    int table[100001] = {0};
    int c = 0;
    rep(i, s.size()) {
        if (s[i] == 'C' && s[i - 1] == 'A') {
            c++;
            table[i] = c;
        } else {
            table[i] = c;
        }
        
    }/*
    rep(i, n + 1) {
        cout << table[i] << " ";
    }
    cout << endl;*/
    rep(i, q) {
        int a, b; cin >> a >> b; a--; b--;
        cout << table[b] - table[a] << endl;
    }
}


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

int N, counta;

void print(vector<int> x, vector<int> y){
	int size = x.size(), temi;
	if(!size) return;
	vector<int> temp1, temp2, temp3, temp4;
	for(int i = 0; i < size; i++){
		if(i)temp1.push_back(x[i]);
		if(y[i] == x[0]){ temi = i; break;}
		temp2.push_back(y[i]);
	}
	for(int i = temi+1; i < size; i++)temp4.push_back(y[i]),temp3.push_back(x[i]);
	print(temp1,temp2);
	print(temp3,temp4);
	
	cout<<(counta++?" ":"")<<x[0];
}

int main(){
	int a;
	vector<int> n, m;
	cin>>N;
	
	for(int i = 0; i < N; i++){
		cin>>a;
		n.push_back(a);
	}
	
	for(int i = 0; i < N; i++){
		cin>>a;
		m.push_back(a);
	}
	
	print(n,m);
	
	cout<<endl;
	return 0;
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    ll n, k;
    cin >> n >> k;
    if(k > (n-1)*(n-2)/2){
        ppp(-1);
        return 0;
    }

    cout << n-1+(n-1)*(n-2)/2-k << endl;
    for(int i = 2; i <= n; ++i){
        printf("%d %d\n", 1, i);
    }
    cout << flush;


    int cnt = 0;
    for(int i = 2; i <= n; ++i){
        for(int j = i+1; j <= n; ++j){
            if(cnt >= (n-1)*(n-2)/2-k){
                cout << flush;
                return 0;
            }
            ++cnt;
            printf("%d %d\n", i, j);
        }
    }

    return 0;
}


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

int main()
{
    long long W, H, x,y;

    cin >> W>>H>>x>>y;

    double ans = (double)W * H / 2.0;

    if(x==W/2.0 && y==H/2.0){
        cout << showpoint<<ans << " " << 1;
    }else{
        cout << showpoint << ans << " " << 0;
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
//main function
fn main() {
    let s: String = read();
    let _t: String = read();
    let a: i8 = read();
    let b: i8 = read();
    let u: String = read();
    if s==u {
	println!("{} {}",a-1,b);
    }else{
	println!("{} {}",a,b-1);
    }

}


Measured memory_bytes: 4352
#include <atcoder/string>
#include <bits/stdc++.h>

using namespace std;
using namespace atcoder;

int main()
{
  string s;
  cin >> s;
  int n = s.size();
  vector<int> lcp = lcp_array(s, suffix_array(s));
  cout << 1ll * n * (n + 1) / 2 - accumulate(lcp.begin(), lcp.end(), 0LL);
}

Measured memory_bytes: 15668
class Queue():
    def __init__(self):
        self.size = 0
        self.Max = 100000
        self.queue = [None]

    def isEmpty(self):
        return self.size == 0

    def isFull(self):
        return self.size >= self.Max

    def enqueue(self, x):
        if self.isFull():
            print("Queue overflow!")
        else:
            self.queue.append(x)
            self.size += 1

    def dequeue(self):
        if self.isEmpty():
            print("Queue underflow!")
        else:
            self.size -= 1
            return self.queue.pop(1)

p_queue = Queue()
e_time = 0
ans = ""

n, q = map(int, input().split())

for i in range(n):
    process = input().split()
    process[1] = int(process[1])
    p_queue.enqueue(process)

while not p_queue.isEmpty():
    process = p_queue.dequeue()
    if process[1] <= q:
        e_time += process[1]
        ans += "{0} {1}\n".format(process[0], e_time)
    else:
        e_time += q
        process[1] -= q
        p_queue.enqueue(process)

print(ans, end = "")

Measured memory_bytes: 19728
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = 1000000005;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    // code here
    int N, M;
    cin >> N >> M;
    vector<int> v(N, -1);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        if (v[s] != -1 && v[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        v[s] = c;
    }
    vector<int> ans(N, 0);
    for (int i = 0; i < N; i++) {
        if (v[i] != -1) {
            ans[i] = v[i];
        }
    }
    if (ans[0] == 0) {
        if (N != 1) {
            if (v[0] != -1) {
                cout << -1 << endl;
                return 0;
            }
            ans[0] = 1;
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ios>//左右揃え
#include<iomanip>//setwで幅指定

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007LL

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

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define Boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const long MOD = 1000000007;

void Crack() {
	long long x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    long long cnt = 0,p = x/d;
    long long ans = 0;
    if(k<=p) ans = x - k*d;
    else {
        ans = x - p*d;
        k = k - p;
        if(ans>abs(ans-d)) {
            k--;
            ans = abs(ans-d);
        }
        if(k%2==1) ans = min(ans-d,min(ans,ans+d));
    }
    cout << abs(ans) << endl;
}

int main() {
	Boost;
    Crack();
	return 0;
}

Measured memory_bytes: 3548
(defparameter *string* (concatenate 'list (read-line)))
(defparameter *answer* (concatenate 'list (read-line)))
(defparameter *length* (length *string*))
(format t "~A" (if (loop :for k :from 0 :upto *length* initially (setf (cdr (last *string*)) *string*) thereis(equal (subseq *string* k (+ k *length*)) *answer*))
                   "Yes"
                   "No"))

Measured memory_bytes: 3684
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int max = 0;
        int sabun = 0;

        for(int i =0;i<n;i++){
            a[i] = sc.nextInt();
        }

        for(int i = 0;i<n-1;i++){
            for(int j = i+1;j<n;j++){
                sabun = Math.abs(a[i]-a[j]);
                if(max<sabun){
                    max = sabun;
                }
            }
        }
        System.out.println(max);

    }
}


Measured memory_bytes: 21844
#include<cstdio>
using namespace std;
int main(void){
	int i,j,n,A[1000000];
	char str[1000];

	for( ; ; ){
		fgets(str,sizeof(str),stdin);
		sscanf(str,"%d",&n); i=0;
		if(n== -1) break;
		while(n!=0){
			A[i]=n%4;
			n/=4;
			i+=1;			
		}
		if(str[0]=='0')
			printf("%d",n);			
		else{
			for(j=i-1;j>=0;j--)
				printf("%d",A[j]);}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2620
program strings_of_impurity
  implicit none
  character(100000) :: s, t
  integer :: n, m, i, j, k, idx(26) = -1, nxt(100000,26) = 0
  integer(8) :: ans = 0_8
  logical :: ng(26) = .true.
  read(*,*) s
  read(*,*) t
  n = len_trim(s)
  m = len_trim(t)
  do i = 1, n
    j = ord(s(i:i))
    ng(j) = .false.
  end do
  do i = 1, m
    j = ord(t(i:i))
    if (ng(j)) then
      write(*,'(i0)') -1
      stop
    end if
  end do
  do i = n, 1, -1
    j = ord(s(i:i))
    idx(j) = n+i
  end do
  do i = n, 1, -1
    k = ord(s(i:i))
    do j = 1, 26
      if (idx(j) < 0) cycle
      nxt(i,j) = idx(j)-i
    end do
    idx(k) = i
    if (s(i:i) == t(1:1)) ans = int(i,8)
  end do
  do i = 2, m
    j = mod(ans-1_8,int(n,8))+1
    ans = ans+int(nxt(j,ord(t(i:i))),8)
  end do
  write(*,'(i0)') ans
contains
  integer function ord(s)
    character(1), intent(in) :: s
    ord = ichar(s)-96
  end
end program strings_of_impurity

Measured memory_bytes: 10892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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;}
const ll INF = 1LL<<60;
/*template*/
ll x[100];

int main()
{
  ll n;cin>>n;
  for(ll i=0;i<n;i++){
    cin>>x[i];
  }
  ll ans=INF;
  for(ll i=1;i<=100;i++){
    ll k=0;
    for(ll j=0;j<n;j++){
      k+=pow(x[j]-i,2);
    }
    chmin(ans,k);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

vvl G;
vl ans;  // ans[v] : 頂点vのカウンターの値

void dfs(ll v, ll p = -1) {
    // 行きの処理はこのへんに書く
    if(p != -1) {
        ans[v] += ans[p];
    }
    for(auto u : G[v]) {
        if(u == p) {
            continue;
        }
        dfs(u, v);
        // 帰りの処理はこのへんに書く
    }
}

int main() {
    ll n, q;
    cin >> n >> q;    

    G.resize(n);
    rep(i, n-1) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].pb(b);
        G[b].pb(a);
    }

    ans.resize(n);
    rep(loop, q) {
        ll p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    const ll root = 0;
    dfs(root);

    rep(v, n) {
        cout << ans[v] << " ";
    }

    re0;
}

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

const int maxn=2e5+10;

int n,deg[maxn];
int tote,FIR[maxn],TO[maxn],NEXT[maxn];
bool vis[maxn];
queue<int> q;

void addedge(int u,int v)
{
	TO[++tote]=v;
	NEXT[tote]=FIR[u];
	FIR[u]=tote;
}

int main()
{
#ifdef h10
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
	int i,u,v;
	scanf("%d",&n);
	if (n&1) {puts("First"); return 0;}
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		addedge(u,v);
		addedge(v,u);
		deg[u]++; deg[v]++;
	}
	for (i=1;i<=n;i++)
		if (deg[i]==1) q.push(i);
	vis[0]=1;
	for (i=1;i<=n>>1;i++)
	{
		u=v=0;
		while (vis[u]) u=q.front(),q.pop();
		for (int p=FIR[u];p;p=NEXT[p])
		{
			v=TO[p];
			if (!vis[v]) break;
		}
		if (vis[v]) {puts("First"); return 0;}
		vis[u]=vis[v]=1;
		for (int p=FIR[v];p;p=NEXT[p])
		{
			u=TO[p];
			if (!vis[u]&&(--deg[u])==1) q.push(u);
		}
	}
	puts("Second");
}


Measured memory_bytes: 2944
#include <iostream>
using namespace std ;
int main()
{
  int x , y ;
	cin >> x >> y ;
	if((x%2==0&&y%2==0) || (x%2==1&&y%2==1))
      cout << (x+y)/2 ;
	else 
      cout << "IMPOSSIBLE" ;
	return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll fen[500005][26];
void upd(ll i, ll j, ll v )
{
	for(;i<500005;i+=(i&(-i)))
	{
		//cout<<i<<" ";
		fen[i][j]+=v;
	}
	//cout<<"\n";
}
ll ch(ll i, ll j)
{
	ll out=0;
	for(;i>0;i-=(i&(-i)))
	{
		out+=fen[i][j];
	}
	return out;
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	string s;
	cin>>s;
	for(ll i=0;i<n;i++)
	{
		upd(i+1,s[i]-'a',1);
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll x;
		cin>>x;
		if(x==1)
		{
			ll i;
			char c;
			cin>>i>>c;
			i--;
			upd(i+1,s[i]-'a',-1);
			s[i]=c;
			upd(i+1,s[i]-'a',1);
		}
		else
		{
			ll l,r;
			cin>>l>>r;
			ll out=0;
			for(ll i=0;i<26;i++)
			{
				if(ch(r,i)-ch(l-1,i)>0)
				{
					out++;
				}
			}
			cout<<out<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 102556
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define ff first
#define ss second
 
#ifndef ONLINE_JUDGE
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif
 
const int inf = 2e18;
const int ninf = -2e18-5;
const int mod = 1e9 + 7;

signed main(){
 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
 
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	int n; cin>>n;
	vector<int> arr(n);
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	int ans = 0;
	for(int i=0; i<n-2; i++){
		for(int j=i+1; j<n-1; j++){
			for(int k=j+1; k<n; k++){
				vector<int> v = {arr[i], arr[j], arr[k]};
				sort(v.begin(), v.end());
				if(v[0]!=v[1] && v[1]!=v[2] && v[0]!=v[2] && v[0]+v[1]>v[2]){
					// cout<<v[0]<<" "<<v[1]<<" "<<v[2]<<endl;
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

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

    vector <int> height(no_of_stones + 1, 0);
    for(int i = 1; i <= no_of_stones; i++)
        cin >> height[i];

    vector <int> minimum_cost(no_of_stones + 1);
    minimum_cost[2] = abs(height[2] - height[1]);
    for(int i = 3; i <= no_of_stones; i++)
        minimum_cost[i] = min(minimum_cost[i - 1] + abs(height[i] - height[i - 1]),
                              minimum_cost[i - 2] + abs(height[i] - height[i - 2]));

    cout << minimum_cost[no_of_stones];
    return 0;
}

Measured memory_bytes: 4044
program sample
    implicit none
    real(8)::x,y,z
    integer(8) :: a,b,c,i,j,m,n,k,a1,b1,c1
    
    
  
    read(*,*) n

    if (mod(n*100,108)==0)then
        write(*,*) n*100/108
    else 
        a=1+int(n/1.08)
        if (a<(n+1)/1.08)then
            write(*,*)a
        else
            write(*,*)':('
        end if
    end if
    stop
end program sample
  



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

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, Y;
	cin >> N >> Y;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= N - i; j++) {
			if (i * 10000 + j * 5000 + (N - i - j) * 1000 == Y) {
				cout << i << " " << j << " " << N - i - j << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

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

string S;
map<char, int>m;

int main(){
  m['1']=0;m['7']=0;m['4']=0;m['8']=1;m['2']=1;m['9']=2;m['6']=2;m['3']=2;
  while(cin >> S && S != "#"){
    int res = INF;
    rep(s,2){
      int cnt=0;
      int f[2]={-1,3}; //0:left 1:right
      int leg=s;
      // left
      rep(i,S.size()){
	int pos = m[S[i]];
	if(leg){
	  if(f[leg^1] <= pos){
	    f[leg] = pos;
	    leg ^= 1;
	  }else{
	    f[leg^1] = pos;
	    cnt++;
	  }
	}else{
	  if(pos <= f[leg^1]){
	    f[leg] = pos;
	    leg ^= 1;
	  }else{
	    f[leg^1] = pos;
	    cnt++;
	  }
	}
	//	cout << f[0] << " " << f[1] << " " << leg << " " << cnt << endl;
      }
      //      cout << cnt << endl << endl;;
      res = min(res, cnt);
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1320
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

int cnt(int a, int b, int c) {
	int fst = ((a + c - 1) / c) * c;
	int lst = (b / c) * c;
	if (fst > lst) return 0;
	return ((lst / c) - (fst / c) + 1);
}

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

	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << b - a + 1 - (cnt(a, b, c) + cnt(a, b, d) - cnt(a, b, c * d / __gcd(c, d))) << endl;
}


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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	int a, b ;
	cin >> a>> b ;
	if(a <= 9 && b <= 9) {
		cout << a * b << endl;
	}else puts("-1");
}


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

int main(){
  int N,T,A;
  cin >> N >> T >> A;
  
  vector<int> H(N);
  double min = 10000;
  int target = 0;
  
  for(int i=0; i<N; i++){
    cin >> H.at(i);
    
    double temp = T - 0.006 * H.at(i);
    double dif = abs(A-temp);
    if(min > dif){
      min = dif;
      target = i + 1;
    }
  }
  
  cout << target << endl;
}


Measured memory_bytes: 3572
N,M = map(int,input().split())
gakusei = []
for i in range(N):
    a,b = map(int,input().split())
    gakusei.append((a,b))
check = []
for i in range(1,M+1):
    c,d = map(int,input().split())
    check.append((c,d))
for i in range(N):
    a,b = gakusei[i]
    z = 10**9
    m = 0
    for j in range(1,M+1):
        c,d = check[j-1]
        x = max(a-c,c-a) + max(b-d,d-b)
        if x < z:
            m = j
            z = x
    print(m)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(){
    int N, M;  cin >> N >> M;
    
    int ans = 1;
    for(int g=1; g*g<=M; g++){
        if(M%g==0){
            if(M/g >= N){
                ans = max(ans, g);
            }
            int h = M/g;
            if(M/h >= N){
                ans = max(ans, h);
            }
        }
    }
    cout << ans << endl;
}   


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int a;
	int b;
	int c;
	scanf("%d %d %d", &a, &b, &c);
	if(a+b>=c){
		printf("%d\n",b+c);
	}else{
		printf("%d\n",a+b+1+b);
	}
}


Measured memory_bytes: 128
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

h,w = li()
inp = [lc() for _ in range(h)]
grid = [[-1]*w for _ in range(h)]
for i, row in enumerate(inp):
    for j, col in enumerate(row):
        if inp[i][j] == ".":
            grid[i][j] = 0
        else:
            grid[i][j] = 1

dis = [-1, 0, 1, 0]
djs = [0, -1, 0, 1]
hasVisited = [[False]*w for _ in range(h)]

def dfs(sti, stj, h, w):
    stack = [(sti, stj)]
    cnt_white = 0
    cnt_black = 0
    while stack:
        i,j = stack.pop()
        for di, dj in zip(dis, djs):
            if 0 <= i+di < h and 0 <= j+dj < w:
                if (not hasVisited[i+di][j+dj]) and (grid[i+di][j+dj] != grid[i][j]):
                    hasVisited[i+di][j+dj] = True
                    if grid[i+di][j+dj] == 0:
                        cnt_white += 1
                    else:
                        cnt_black += 1
                    stack.append((i+di, j+dj))
               
    return cnt_white * cnt_black

ans = 0
for r in range(h):
    for c in range(w):
        if hasVisited[r][c]:
            continue
        
        cnt = dfs(r,c,h,w)
        ans += cnt
        
print(ans)
        

Measured memory_bytes: 57820
#include <iostream>
#include <vector>
#include <string>



using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main()
{
    string s;
    cin >> s;
    string res = (s == "ABC") ? "ARC" : "ABC";
    cout << res;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;


const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()

int main(){
    int sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    int lx=gx-sx,ly=gy-sy;

    cout<<string(ly,'U')<<string(lx,'R');
    cout<<string(ly,'D')<<string(lx,'L');
    cout<<'L'<<string(ly+1,'U')<<string(lx+1,'R')<<'D';
    cout<<'R'<<string(ly+1,'D')<<string(lx+1,'L')<<'U'<<endl;//外側を回っているので移動距離は１伸びる……！

    return 0;
}

//a=97,z=122

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define MOD 1e9+7;

using ll = long long;
using namespace std;

int main() {
    unordered_map<int, int> mp;
    int N, ans = 0;
    cin >> N;

    rep(i, N) {
        int A;
        cin >> A;
        auto itr = mp.find(A);
        if(itr != mp.end()) 
            mp[A]++;
        else
            mp[A] = 1;
    }
    
    auto itr = mp.begin();
    while(itr != mp.end()) {
        if( (itr -> second) %2 == 1 )
            ans++;
        itr++;
    }

    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4388
#include <string>
#include <iostream>
#include <set>
using namespace std;

set<string> data;
char *ans[1000000];
int cor = 0;

int main(){
	int n;
	string A,B;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> A >> B;
		if(A == "insert"){
			data.insert(B);
		}
		else if(A == "find"){
			if(data.find(B) == data.end())
				ans[cor] = "no";
			else
				ans[cor] = "yes";
			cor++;
		}
	}
	for(int i = 0;i < cor;i++)
		cout << ans[i] << endl;
	return 0;
}



Measured memory_bytes: 35976