akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll h, w; cin >> h >> w;
    vector<string> c(h);
    REP(i, h) cin >> c[i];
    
    vector<ll> imin(w, INF), imax(w, -INF);
    REP(i, h) REP(j, w) {
        if (c[i][j] == 'B') {
            chmin(imin[j], i);
            chmax(imax[j], i);
        }
    }

    ll ans = 0;
    REP(j, w) RANGE(k, j, w-1) {

        if (imin[j] == INF || imin[k] == INF) continue;

        ll dj = k - j; // >= 0
        ll dimax = max({
            abs(imin[j] - imin[k]),
            abs(imin[j] - imax[k]),
            abs(imax[j] - imin[k]),
            abs(imax[j] - imax[k])
        });
        chmax(ans, dj + dimax);

    }

    cout << ans << endl;
    
}


Measured memory_bytes: 3780
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
CD = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in AB:
    ans, maxD = 0, 10 ** 10
    for i, (c, d) in enumerate(CD):
        if abs(a - c) + abs(b - d) < maxD:
            ans, maxD = i + 1, abs(a - c) + abs(b - d)
    print(ans)


Measured memory_bytes: 3060
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        S: String,
        T: String,
    };
    let c = S.chars().zip(T.chars()).fold(0, |acc, (s, t)| acc + if s == t {1} else {0});
    println!("{}", c);

}


Measured memory_bytes: 2084
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main() {
  int N,M;
  int L,R;
  int ans=0;
  cin >> N>>M;
  vector<int> list(N);
  rep(i, M) {
    cin >> L >>R;
    if (list[L - 2] == 0) {
      rep(i, L-1) {
        list[i]=1;
      }
    }
    if (list[R] == 0) {
      for (int i = R; i < N; i++) {
        list[i] = 1;
      }
    }
  }
  rep(i, N) { 
    if (list[i] == 0) {
      ans++;
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main()
{
  int h,w,i,j,hw,ij,mini,minj;

  while(1){
    scanf("%d%d",&h,&w);
    if(h==0 &&w==0)break;

    hw=h*h+w*w;
    mini=150;
    minj=150;
    for(i=1;i<150;i++){
      for(j=i+1;j<150;j++){
	ij=i*i+j*j;
        if((hw<ij||((ij==hw) &&h<i)) && mini*mini+minj*minj>ij){
          mini=i;
          minj=j;
	  // printf("%d %d\n",mini,minj);
	}
      }
    }
    printf("%d %d\n",mini,minj);
  }
  return 0;
}

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

int main(){
  int N;
  cin>>N;
  vector<int> V(N);
  vector<int> C(N);
  vector<int> val(N);
  int value=0;
  
  for(int i=0;i<N;i++)
    cin>>V.at(i);
  for(int i=0;i<N;i++)
    cin>>C.at(i);
  for(int i=0;i<N;i++){
    val.at(i)=V.at(i)-C.at(i);
    if(val.at(i)>0)
      value+=val.at(i);
  }
  cout<<value<<endl;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v)                                                            \
  do {                                                                         \
    x = max(x, v);                                                             \
  } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

template <typename T>
using reversed_priority_queue =
    std::priority_queue<T, std::vector<T>, std::greater<T>>;
const int dy[] = {-1, 0, 1, 0};
const int dx[] = {0, 1, 0, -1};
const ll INF = 10000;
ll H, W;
string s[20];
vector<ll> edges[400];

ll id(ll y, ll x) { return y * W + x; }

vector<ll> dijk(ll v, ll H, ll W) {
  vector<ll> res(H * W, INF);
  reversed_priority_queue<PLL> q;
  q.push(PLL(0, v));
  while (!q.empty()) {
    auto t = q.top();
    q.pop();
    ll d = t.first, v = t.second;
    if (res[v] != INF)
      continue;
    res[v] = d;
    for (auto nv : edges[v]) {
      q.push(PLL(d + 1, nv));
    }
  }
  return res;
}

signed main() {
  cin >> H >> W;
  rep(y, H) cin >> s[y];
  rep(y, H) rep(x, W) rep(k, 4) {
    if (s[y][x] == '#')
      continue;
    ll nx = x + dx[k], ny = y + dy[k];
    if (nx >= 0 && ny >= 0 && nx < W && ny < H && s[ny][nx] == '.') {
      edges[id(y, x)].push_back(id(ny, nx));
      edges[id(ny, nx)].push_back(id(y, x));
    }
  }
  ll ans = 0;
  rep(y, H) rep(x, W) {
    if (s[y][x] == '#')
      continue;
    auto d = dijk(id(y, x), H, W);
    for (auto p : d) {
      if (p == INF)
        continue;
      chmax(ans, p);
    }
    // printf("y=%d x=%d v=%d: ", y, x, id(y, x));
    // for (auto p : d) {
    //  printf("%d ", p);
    //}
    // printf("\n");
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n = int(input())
s = list(input())

R=[0]*n
G=[0]*n
B=[0]*n

for i in range(n):
    if s[i]=='R':
        R[i]=1
    elif s[i]=='G':
        G[i]=1
    elif s[i]=='B':
        B[i]=1

ans=0
for i in range(n):
    if R[i]==1:
        lG=sum(G[:i])
        lB=sum(B[:i])
        rG=sum(G[i:])
        rB=sum(B[i:])
        ans+=(lG+rG)*(lB+rB)
        for j in range(1,n//2+1):
            if R[i]==1:
                if 0<=i-j<n and 0<=i+j<n:
                    if G[i-j]==1 and B[i+j]==1:
                        ans-=1
                    if B[i-j]==1 and G[i+j]==1:
                        ans-=1
                if 0<=i-2*j<n:
                    if G[i-j]==1 and B[i-2*j]==1:
                        ans-=1
                    if B[i-j]==1 and G[i-2*j]==1:
                        ans-=1
                if 0<=i+2*j<n:
                    if G[i+j]==1 and B[i+2*j]==1:
                        ans-=1
                    if B[i+j]==1 and G[i+2*j]==1:
                        ans-=1

print(ans)

Measured memory_bytes: 74296
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <string>
#include <queue>

#define MAX_W 30
#define MAX_H 30

using namespace std;

int inf = 1<<29;

int H, W;
int map[MAX_W+1][MAX_H+1];
int dist[MAX_W+1][MAX_H+1][4];
int c[4];
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

struct state{
	int dist, x, y, dr;
	state(int a,int b, int c, int d):dist(a),x(b),y(c),dr(d){}
};

bool operator<(const state& a, const state& b){ return a.dist > b.dist; }

int solve(){
	for (int i = 0; i < W; i++)
	{
		for (int j = 0; j < H; j++)
		{
			for (int k = 0; k < 4; k++)
			{
				dist[i][j][k] = inf;
			}
		}
	}
	priority_queue<state> Q;
	Q.push(state(0, 0, 0, 0));
	while(!Q.empty()){
		state tp = Q.top(); Q.pop();
		if(tp.x == W-1 && tp.y == H-1) return tp.dist;
		if(dist[tp.x][tp.y][tp.dr] != inf) continue;
		dist[tp.x][tp.y][tp.dr] = tp.dist;
		for (int i = 0; i < 4; i++)
		{
			int nx = tp.x+dx[i], ny = tp.y+dy[i], ndr = i;
			if(0 <= ny && ny < H && 0 <= nx && nx < W && dist[nx][ny][ndr] == inf){
				int odr = (tp.dr+map[tp.x][tp.y])%4;//????????????????????£??????????????????
				int cost;
				if(map[tp.x][tp.y] == 4){
					cost = c[(ndr-tp.dr+4)%4];
				}else{
					if(odr == ndr){
						cost = 0;
					}else{
						cost = c[(ndr-tp.dr+4)%4];
					}
				}
				Q.push(state(tp.dist+cost, nx, ny, ndr));
			}
		}
	}
	return -1;
}

int main(){
	while(1){
		cin >> W >> H;
		if(W == 0) break;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				cin >> map[j][i];
			}
		}
		for (int i = 0; i < 4; ++i)
		{
			cin >> c[i];
		}
		cout << solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 1344
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;

int m,g;
int card[7],num[7];
int dp[10][10000];
int n;

int solve(int idx,int sum){
  if(sum == n) return 1;
  if(idx == m) return 0;
  if(sum > n) return 0;
  if(dp[idx][sum] != -1) return dp[idx][sum];
  
  int ret = 0;
  for(int i=0;i<=num[idx];i++){
    ret += solve(idx+1,sum+(card[idx]*i));
  }
  return dp[idx][sum] = ret;
}

int main(){
  while(cin >> m , m){
    for(int i=0;i<m;i++){
      cin >> card[i] >> num[i];
    }
    cin >> g;
    for(int i=0;i<g;i++){
      cin >> n;
      memset(dp,-1,sizeof(dp));
      cout << solve(0,0) << endl;
    }
  }
}

Measured memory_bytes: 1556
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char * argv[])
{
    string line;
    while (getline(cin, line)) {
        for (unsigned int i = 0; i < line.size(); ++i) {
            if (i == 4) {
                cout << " ";
            }
            cout << line[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

double dp[101][101];
double table[100][100];

int main(){

	int n,m;
	while(~scanf("%d %d",&n,&m)){
		if(n==m && m==0) break;
		for(int y=0;y<n;y++){
			for(int x=0;x<n;x++){
				scanf("%lf",&table[y][x]);
			}
		}

		fill((double*)dp,(double*)dp+101*101,0.0);
		for(int i=0;i<n;i++) dp[0][i] = 1.0;

		for(int k=0;k<m-1;k++){
			for(int i=0;i<n;i++){
				for(int j=0;j<n;j++){
					dp[k+1][i] = max(dp[k][j]*table[j][i],dp[k+1][i]);
				}
			}
		}

		double res = -1.0;
		for(int i=0;i<n;i++) res = max(res,dp[m-1][i]);

		printf("%.2lf\n",res);
	}
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Small__Large__or_Equal
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int[] nums = { int.Parse(input[0]), int.Parse(input[1]) };
            if (nums[0] > nums[1])
            {
                Console.WriteLine("a > b");
            }
            else if ((nums[0] < nums[1]))
            {
                Console.WriteLine("a < b");
            }
            else
            {
                Console.WriteLine("a == b");
            }


        }
    }
}



Measured memory_bytes: 15932
N,K=map(int,input().split())
R,S,P=map(int,input().split())
T=input()

ans=0
A=[]
for i in range(K):
    if T[i]=='r':
        ans+=P
        A.append('p')
    elif T[i]=='s':
        ans+=R
        A.append('r')
    else:
        ans+=S
        A.append('s')

for i in range(K,N):
    if T[i]=='r':
        if A[i-K]!='p':
            ans+=P
            A.append('p')
        else:
            A.append('x')
    elif T[i]=='s':
        if A[i-K]!='r':
            ans+=R
            A.append('r')
        else:
            A.append('x')
    else:
        if A[i-K]!='s':
            ans+=S
            A.append('s')
        else:
            A.append('x')

print(ans)

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

const int maxn=100005;

int a[maxn],b[maxn],c[maxn];

long long pre[maxn],suf[maxn];

int main(){
	int x,y,z;
	scanf("%d %d %d",&x,&y,&z);
	int n=x+y+z;
	
	vector<pair<int,int> >v;
	for (int i=0;i<n;i++){
		scanf("%d %d %d",a+i,b+i,c+i);
		v.push_back(make_pair(a[i]-b[i],i));
	}
	
	sort(v.begin(),v.end());
	
	priority_queue<pair<int,int> >s;
	
	for (int ind=0;ind<n;ind++){
		int i=v[ind].second;
		if(s.size()<y){
			s.push(make_pair(c[i]-b[i],i));
			pre[ind]=pre[ind-1]+b[i];
		}
		
		else{
			pair<int,int>p=s.top();
			int cur=c[i]-b[i];
			if(cur>p.first){
				pre[ind]=pre[ind-1]+c[i];
			}
			
			else{
				s.pop();
				pre[ind]=pre[ind-1]+b[i]+c[p.second]-b[p.second];
				s.push(make_pair(cur,i));
			}
		}
	}

	priority_queue<pair<int,int> >pq;
	
	for (int ind=n-1;ind>=0;ind--){
		int i=v[ind].second;
		if(pq.size()<x){
			pq.push(make_pair(c[i]-a[i],i));
			suf[ind]=suf[ind+1]+a[i];
		}
		
		else{
			pair<int,int>p=pq.top();
			int cur=c[i]-a[i];
			if(cur>p.first){
				suf[ind]=suf[ind+1]+c[i];
			}
			
			else{
				pq.pop();
				suf[ind]=suf[ind+1]+a[i]+c[p.second]-a[p.second];
				pq.push(make_pair(cur,i));
			}
		}
	}
	
	long long ans=0;
	for (int i=y-1;n-1-i>=x;i++){
		ans=max(ans,pre[i]+suf[i+1]);
	}
	
	printf("%lld",ans);
}

Measured memory_bytes: 5492
#include <iostream>

using namespace std;

int main(void)
{
    int K;
    int A, B;
  
    cin >> K;
    cin >> A >> B;
    
    for(int i = A; i <= B; i++)
    {
        if( (i % K) == 0 )
        {
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}


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

typedef long long ll;
using namespace std;
const int maxn = 1e5+7;
int val[maxn];
int main() {
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=1,u,v;i<=m;++i){
        scanf("%d%d",&u,&v);
        val[u]++;
        val[v]++;
    }
    for(int i=1;i<=n;++i){
        if(val[i]&1){
            printf("NO");
            return 0;
        }
    }
    printf("YES");
    return 0;
}

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

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main(void){
  string s;
  cin>>s;
  cout<<(s[0] == s[2]?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = CIn.ReadInt();
            var m = n / 2;
            var ans=new long[2];
            var flg = new bool[2];
            var a = new long[n];
            for(var i=0;i < n; i++)
            {
                a[i] = CIn.ReadInt();
            }

            Array.Sort(a);
            Array.Reverse(a);
            ans[0] = a[0];
            flg[0] =  flg[1] = true;
            var score=(long)0;
            
            for(var i = 1; i < n; i++)
            {
                var tmp = System.Math.Min(a[i], a[0] - a[i]);
                if (score < tmp)
                {
                    score = tmp;
                    ans[1] =a[i];
                }
            }


            Console.WriteLine("{0} {1}", ans[0], ans[1]);
            
        }
    }

    class CIn
    {
        private static readonly Queue<string> fieldBuffer = new Queue<string>();

        public static string Read()
        {
            if (fieldBuffer.Count == 0)
            {
                foreach (var field in Console.ReadLine().Split())
                {
                    fieldBuffer.Enqueue(field);
                }
            }
            return fieldBuffer.Dequeue();
        }

        public static int ReadInt() => int.Parse(Read());
        public static long ReadLong() => long.Parse(Read());
        public static double ReadDouble() => double.Parse(Read());

        public static string[] ReadStringArray(long n)
        {
            var array = new string[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = Read();
            }
            return array;
        }

        public static int[] ReadIntArray(long n)
        {
            var array = new int[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadInt();
            }
            return array;
        }

        public static long[] ReadLongArray(long n)
        {
            var array = new long[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadLong();
            }
            return array;
        }

        public static double[] ReadDoubleArray(long n)
        {
            var array = new double[n];
            for (var i = 0; i < n; i++)
            {
                array[i] = ReadDouble();
            }
            return array;
        }
    }
}


Measured memory_bytes: 23008
N,Q = map(int,input().split())
s = input()
al = [0] * N
al[0] = 0
for i in range(1,N):
    if s[i-1:i+1] == 'AC':al[i] = al[i-1]+1
    else:al[i]=al[i-1]
for _ in range(Q):
    l,r = map(int,input().split())
    print(al[r-1]-al[l-1])

Measured memory_bytes: 6140
#include <stdio.h>

void dfs();
void visit(int);

int n,color[101] = {},d[101],f[101],G[101][101];

int main(){
  int id,i,j;

  scanf("%d",&n);
  
  for(i = 1; i < n+1;i++){
    scanf("%d%d",&G[i][0],&G[i][1]);
    
   for(j = 0;j < G[i][1]; j++){
     scanf("%d",&G[i][2+j]);
    }
  }
  dfs();
  return 0;
}

void dfs(){
  int i;
  
  for(i = 1; i < n+1;i++){
    if(color[i] == 0)visit(i);
  }

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

void visit(int u){
  int i;
  int static time = 0;
  
  color[u] = -1;
  d[u] = ++time;
  
  for(i = 0; i < G[u][1];i++){
    if(color[G[u][2+i]] == 0)visit(G[u][2+i]);
  }
  color[u] = -2;
  f[u] = ++time;
}



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

long long int MOD = 1000000007;

int main() {
  int N;
  cin >> N;
  
  vector<bool> P(N + 1, false);
  for (int i = 2; i <= N; i++) {
    bool X = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) X = false;
    }
    if (X) P.at(i) = true;
  }
  
  long long int ans = 1;
  for (int i = 2; i <= N; i++) {
    if (P.at(i) == false) continue;
    long long int k = 0;
    for (int j = 2; j <= N; j++) {
      int t = j;
      while (t % i == 0) {
        k++;
        t /= i;
      }
    }
    ans = ans * (k + 1) % MOD;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
const int N = 300000;
int a[N];
int sum[N];
void generate(){
  rep(i,N)a[i]=i%2;
  for(int i=3;i*i < N;i+=2){
    if (a[i])
      for(int j=2*i;j<N;j+=i)a[j]=false;
  }
  a[1]=true;a[2]=true;
  int cnt=0;
  sum[0]=0;
  REP(i,1,N){
    sum[i]=sum[i-1];
    if (a[i])sum[i]++;
  }

}

main(){
  generate();
  int n;
  while(cin >>n && n){
    cout << sum[2*n]-sum[n] << endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    vector<string> s(3);
    for(int i = 0; i<3;i++){
        cin >> s[i];
    }
/*    
    rep(i,3){
        cout << s[i];
    }
    cout << endl;
*/ 
    if(s[0]+s[1]+s[2] == "AAA" || 
        s[0]+s[1]+s[2] == "BBB"){
            cout << "No" << endl;
        }else{
            cout << "Yes" << endl;
        }
}

Measured memory_bytes: 256
n = int(input())
f = [list(map(int,input().split())) for i in range(n)]
p = [list(map(int,input().split())) for i in range(n)]
print(max(sum(p[j][sum(i>>k&1 and f[j][k] for k in range(10))] for j in range(n)) for i in range(1,2**10)))


Measured memory_bytes: 3060
a = list(input())
b = list(input())
c = list(input())
A, B, C = map(len, (a, b, c))
OFFSET = 4000
L = 8001
ab = [True] * L
ac = [True] * L
bc = [True] * L

for i in range(A):
    for j in range(B):
        if a[i] != b[j] and a[i] != '?' and b[j] != '?':
            k = i - j + OFFSET
            ab[i - j + OFFSET] = False  # BをAからi-jずらした時を考える

for i in range(A):
    for j in range(C):
        if a[i] != c[j] and a[i] != '?' and c[j] != '?':
            ac[i - j + OFFSET] = False  # CをAからi-jずらした時を考える

for i in range(B):
    for j in range(C):
        if b[i] != c[j] and b[i] != '?' and c[j] != '?':
            bc[i - j + OFFSET] = False  # CをBからi-jずらした時を考える

ans = float('inf')
for i in range(L):  # Bの左端をずらす
    for j in range(L):  # Cの左端をずらす
        k = j - i + OFFSET
        if k >= L or k < 0:
            continue
        if ab[i] and ac[j] and bc[k]:
            head = min(i, j, OFFSET)
            tail = max(A + OFFSET, B + i, C + j)
            ans = min(ans, tail - head)

print(ans)


Measured memory_bytes: 52572
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << "=" << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << " "
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<ll> ans(s.size(),1);

    loop(i, s.size()){
        if(s[i] == 'R'){
            if(s[i+1] == 'R'){
                ans[i+2] += ans[i];
                ans[i] = 0;
            }
        }
    }
    for(ll i = s.size()-1;i >= 0;i--){
        if(s[i] == 'L'){
            if(s[i-1] == 'L'){
                ans[i-2] += ans[i];
                ans[i] = 0;
            }
        }
    }
    loop(i, s.size()){
        cout << ans[i] << endl;
    }
}

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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int ans,cnt;
string s,t,s1,s2;

signed main() {
    cin >> s;
    for(auto i : s) if (i != 'x') t.pb(i);
    rep(i,t.size()/2) {
        if (t[i] != t[t.size()-1-i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,s.size()) {
        s1.pb(s[i]);
        if (s[i] != 'x') cnt++;
        if (cnt == t.size()/2+1) {
            s1.pop_back();
            cnt=0;
            break;
        }
    }
    repm(i,s.size()) {
        s2.pb(s[i]);
        if (s[i] != 'x') cnt++;
        if (cnt == t.size()/2+1) {
            s2.pop_back();
            break;
        }
    }
    int i1=0,i2=0;
    while(i1 != s1.size() && i2 != s2.size()) {
        if (s1[i1] != s2[i2]) {
            ans++;
            if (s1[i1] == 'x') i1++;
            if (s2[i2] == 'x') i2++;
        } else i1++, i2++;
    }
    ans += max(s1.size()-i1, s2.size()-i2);

    cout << ans << endl;
}





Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}


int main(){
	int N;
	cin >> N;
	vector<int> A(N);
	rep(i, N) cin >> A[i], A[i]--;

	int ans = 0;
	for(int i = 0; i < N; i++){
		ans += (A[A[i]] == i);
	}

	Cout(ans/2);
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    int N;
    N = inputValue();
    int i;
    int seki = N;
    for(i=9;i>0;i--){
        if(seki%i==0){
            seki=seki/i;
            break;
        }
    }
    if(seki > 9){
        cout << "No" << endl;
        return 0;
    }else{
        cout << "Yes" << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define pb push_back
#define si second
#define int unsigned long long
#define mod 1000000007
#define debug(x) cout << #x << " " << x <<endl;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define double long double
#define all(o) o.begin(),o.end()
using namespace std;
int power(int x, int y)
{
    int res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1; // y = y/2
        x = (x*x) % mod;
    }
    return res%mod;
}
int inv(int  n)
{
    return power(n,mod-2)%mod;
}


int m[3][3],a[3][3],c[3][3];

void multiply(int a[][3],int b[][3])
{
    int i,j,k;
    for(i=0;i<3;i++)
        for(j=0;j<3;j++){
            c[i][j]=0;
            for(k=0;k<3;k++)
            {   c[i][j]+=a[i][k]%mod*b[k][j]%mod;
                c[i][j]%=mod;
            }
        }
    for(i=0;i<3;i++)
        for(j=0;j<3;j++)
            a[i][j]=c[i][j];
}
void expo(int n){
   // cout<<"n is "<<n<<"\n";
    while(n){
        if(n&1)
            multiply(a,m);
        multiply(m,m);
        n>>=1;
    }
}
int32_t main(){

    fast
    string s;
    cin>>s;
    if(s.back()=='s')
        cout<<s<<"es\n";
    else cout<<s<<"s\n";
}




 

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
using namespace std;

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

    int n;
    string a, b, c;
    cin >> n >> a >> b >> c;

    int count = 0;
    REP(i, n) {
        if (a == b && b == c)
            break;

        if (a[i] != b[i] && b[i] == c[i]) {
            a[i] = b[i];
            count++;
        } else if (a[i] == b[i] && b[i] != c[i]) {
            c[i] = b[i];
            count++;
        } else if (a[i] == c[i] && a[i] != b[i]) {
            b[i] = a[i];
            count++;
        } else if (a[i] != b[i] && b[i] != c[i]) {
            a[i] = b[i];
            c[i] = b[i];
            count += 2;
        }
    }

    cout << count << endl;

    return 0;
}

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




int main() {
	
	int a, b;

	std::cin >> a >> b;

	printf("%d %d\n", a * b, 2 * a + 2 * b);

	//system("pause");
	return 0;
}


Measured memory_bytes: 3100
import itertools as it


N = int(input())
s = list(map(int, input().split()))
s.sort()
count = 0


c = it.combinations(s, 3)

for i in c:
    if i[0] == i[1] or i[1] == i[2] or i[2] == i[0]:
        continue
    elif (i[0] + i[1]) > i[2]:
        count += 1

print(count)

Measured memory_bytes: 9120
using System;
using System.Collections.Generic;//list用
using System.Text.RegularExpressions;//正規表現用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;
//デリゲータの使い方をマスターしたい
 
class Program
{
    Hashtable ht = new Hashtable();
    static List<double> s = new List<double>();
    static double result;
    static int K;
    StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく
static double tmpre;
 
 
    static void Main()
    {
        //Modular mo = new Modular();//素数で割った余りを出せで使う★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）()内は初期値
        //Node no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        // delegate int CFunc();//下関数に使うデリゲータ。コイツと同じ引数と戻り値で関数作って、下の評価式の部分に関数名※（）いらないを入れる。
        //PriorityQueue pr = new PriorityQueue<>(評価式);//優先度付キュー★Enqueue()で格納、Dequeue()で取りだし。引数は評価式（大と小のどちらが優先か）。
        Read1();
        Read2(K);
      tmpre=1;
      for(int i=1;i<=K;i++){tmpre=tmpre*s[i-1];}
      double waruall=0;
      double waru=1;
      for(int j=1;j<=K;j++){
        waru=1;
      for(int i=1;i<=K;i++){if(i!=j){waru=waru*s[i-1];}}
        waruall+=waru;
      }
      result=tmpre/waruall;
        Console.WriteLine(result.ToString());
    }
 
 
    static void Read1()
    {
        string tmp = Console.ReadLine();
        K = int.Parse(tmp);
    }
 
    static void Read2(int kosuu)
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < kosuu; i++) { s.Add(double.Parse(tmp[i])); }
    }
 
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}

// head


int m,n,k,res,tmp,tmp2,tmp3,h,x,y;
VI a;
deque<PII> que;
string s;
//VI b;
vector<PII> g[2100600];
int b[2100000];
int c[210000] = {};
int rui[210000];
set<int> ch;



signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
    rep(i,0,n)cin>>b[i];
  b[0]-=1;
  rep(i,1,n){
    if (b[i] > b[i-1]) b[i]-=1;
    else if (b[i] <b[i-1]){cout<<"No"<<endl; exit(0);}
  }
  cout<<"Yes"<<endl;
}


Measured memory_bytes: 52864
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};


int main(){
  int k;
  cin>>k;
  vector<in> lun={1,2,3,4,5,6,7,8,9};
  queue<in> q;
  rep(i,9)
    q.push(i+1);
  int count=9;
  
  while(count<100000){
    
    in a = q.front();
    in b = 10 * a+( a % 10);
    q.pop();
    if(a%10!=0) {q.push(b-1); lun.push_back(b-1);} 
    q.push(b);lun.push_back(b);
    if((a%10)!=9) {q.push(b+1);lun.push_back(b+1);}
    count++;
  }
  cout<<lun.at(k-1)<<endl;
}

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

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)

/* REPmacro */
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define EACH(begin, end) for(auto itr = (begin); itr != (end); itr++)

/* function */
#define IN(x) cin >> x
#define DEBUG(x) cerr << (x) << " "
#define PRINT(x) cout << (x) << endl
#define BR cout << endl

/* const */
const int INF = 1001001001; // 10^9
const ll LINF = 1001001001001001001; // 10^18
const int MOD = 1e9 + 7;



ll N = 0;
ll ret = 0;
vector<ll> A;
vector<ll> B;

void input() {
  IN(N);
  ll tmp;
  REP(i,N+1) {
    IN(tmp);
    A.push_back(tmp);
  }
  REP(i,N) {
    IN(tmp);
    B.push_back(tmp);
  }
}

void solve() {
  ll cnt = 0;
  REP(i, N) {
    ll atk;
    atk = min(A[i], B[i]);
    B[i] -= atk;
    cnt += atk;
    atk = min(A[i+1], B[i]);
    A[i+1] -= atk;
    cnt += atk;
  }
  PRINT(cnt);
}

int main(void){
  input();
  solve();
}


Measured memory_bytes: 2676
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define int unsigned long long
#define f first
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll cfmod = 998244353;
const int MAXN = 1e5+5;

int a, b, c, n, m, k;
string s, s1, s2, t;

int32_t main() {
	cin >> n;
	if(n & 1) cout << 0 << endl;
	else {	
		ll ans = 0;
		int x = 10;
		while(x <= n) {
			ans += n/x;
			x *= 5;
		}
		cout << ans << endl;
	}
}
		
			




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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
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; }
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    string s; cin >> s;
    int n = (int)s.length();
    vector<int> ans, c;
    int cnt = 0;
    char prev = 'A';
    rep(i, n){
        if(s[i] != prev){
            if(cnt != 0) c.emplace_back(cnt);
            cnt = 0;
            prev = s[i];
        }
        cnt++;
    }
    c.emplace_back(cnt);

    rep(i, c.size()){
        rep(j, c[i]-1){
            ans.emplace_back(0);
        }
        ans.emplace_back(ceil((double)c[i]/2) + floor((double)c[i+1]/2));
        ans.emplace_back(floor((double)c[i]/2) + ceil((double)c[i+1]/2));
        rep(j, c[i+1]-1){
            ans.emplace_back(0);
        }
        i++;
    }
    rep(i, ans.size()){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1592
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

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

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int a, b;
  cin >> a >> b;
  int k = b - a;
  cout << k * (k - 1) / 2 - a << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{

    int a, b, t;
    cin >> a >> b >> t;

    int biscount = 0;

    for (int i = a; i <= t; i += a)
    {
        biscount += b;
    }

    cout << biscount << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
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++)

void solve(){


    return;
}

int main()
{
    int N;
    cin >> N;
    vector<int> p(N), q(N), r(N);
    rep(i,N) cin >> p[i];
    rep(i,N) cin >> q[i];

    //copy(p.begin(),p.end(),r.begin());
    r = p;
    sort(r.begin(),r.end());
    int i=0;
    int ip = 0;
    int iq = 0;
    do{
        if(r == p) ip = i;
        if(r == q) iq = i;
        i++;
    }while(next_permutation(r.begin(),r.end()));

    
    cout << abs(ip - iq) << endl;

    return 0;
}
//Ctrl+Shift+Bでコンパイルと実行を行ってデバッグすること

Measured memory_bytes: 256
s = input()
p ="Yes"
for i in range(len(s)//2):
  if s[i] != s[len(s) -1 -i]:
    p = "No"
for i in range(len(s)//2):
  if s[i] != s[len(s)//2 -1 -i]:
    p = "No"
print(p)

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

map<long long, long long> m;

bool IsPrime(long long num) {
    if (num < 2)
        return true;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;  // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            // 素数ではない
            return false;
        }
    }
    // 素数
    return true;
}

long long nCr(const long long n, long long r) {
    if (n == 0) { return 0; }
    if (r == 0) { return 1; }
    if (r == 1) { return n; }
    if (n == r) { return 1; }

    if (r > n / 2) { r = n / 2; }

    long long result = 1;
    for (long long i = 1; i <= r; i++) { result *= (n - i + 1) / i; }

    return (result);
}

void decompositPrime(long long n) {
    // 割る数の初期値
    long long a = 2;
    while (n >= a * a) {
        if (n % a == 0) {
            m[a]++;
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    m[n]++;
}

int main() {
    //
    long long a, b;
    long long cnt = 0;
    cin >> a >> b;

    decompositPrime(a);
    decompositPrime(b);

    m[1]++;
    for (auto itr : m) {
        if (a % itr.first == 0 && b % itr.first == 0) {
            if (IsPrime(itr.first) == true) cnt++;
        }
    }

    cout << cnt;

    //
}

Measured memory_bytes: 3684
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <map>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <functional>

#define MOD (1000000007)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> tup;
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];


ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

map<ll,ll> prime;//素因数分解でそれぞれの素数がいくつ出てきたかを保存するmap

//O(√n)
//整列済み(mapはkeyで自動で整列される)
void prime_factorize(ll n){
    if(n<=1) return;
    ll l=sqrt(n);
   for(ll i=2;i<=(ll)(l);i++) { //
        if(n%i==0){
            prime_factorize(i);prime_factorize(ll(n/i));return;
        }
    }
    //mapでは存在しないkeyの場合も自動で構築される
    prime[n]++;return;
}



int main() {

    ll N;
    cin >> N;
    N--;
    vector<char> p;
    for(int i = 0;;i++) {
        p.push_back('a' + (N%26));
        N /= 26;
        if(N == 0) break;
        N--;
    }

    for(int i =  p.size()-1; i >= 0; i--) {
        cout << p[i];
    }
    cout << endl;
        

    return 0;    
}



Measured memory_bytes: 3720
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, a[200010];
map<int, int> mp;
int ans;

signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;
	}
	sort(a, a + n);
	reverse(a, a + n);
	for (int i = 0; i < n - 1; i++) {
		int b = 0;
		for (int j = 0;; j++) {
			if (a[i] < (1 << j)) {
				b = (1 << j) - a[i];
				break;
			}
		}
		if (a[i] == b && 2 <= mp[a[i]]) {
			ans++;
			mp[a[i]] -= 2;
		}
		if (a[i] != b && 1 <= mp[a[i]] && 1 <= mp[b]) {
			ans++;
			mp[a[i]]--;
			mp[b]--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 26752
import sys
from collections import deque
from itertools import *

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

def binary_search(list, target):
    left = 0
    right = len(list) - 1
    while left <= right:
        center = int((left + right) / 2)
        if list[center] == target:
            return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1
    return None

n = I()
s = LI()
q = I()
t = LI()
ans = 0
for t_t in t:
    if binary_search(s,t_t) is not None:
        ans += 1
print(ans)


Measured memory_bytes: 16552
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

int main()
{
    string S;
    cin >> S;
    if(S == "AAA" || S == "BBB") cout << "No\n";
    else cout << "Yes\n";
}

Measured memory_bytes: 256
# ABC176 D Wizard 
# 地図系。ワープ有　01BFS??

from collections import deque
H,W = map(int,input().split())
sx,sy = map(int,input().split())
gx,gy = map(int,input().split())
sx,sy,gx,gy = sx-1,sy-1,gx-1,gy-1

C=[list(input()) for i in range(H)]
inf = float("inf")

for i in range(H):
    for j in range(W):
        if C[i][j] == ".":
            C[i][j] =0
        else:
            C[i][j]=1

d0=[[1,0],[0,1],[-1,0],[0,-1]]
d1=[[-2,-2],[-2,-1],[-2,0],[-2,1],[-2,2],[-1,-2],[-1,-1],[-1,1],[-1,2],\
   [0,-2],[0,2],[1,-2],[1,-1],[1,1],[1,2],[2,-2],[2,-1],[2,0],[2,1],[2,2]]

dist = [[inf]*W for i in range(H)]
dist[sx][sy]=0
que=deque([[0,sx,sy]])

while que:
    L,x,y = que.popleft()
    for dx,dy in d0:
        nx,ny=x+dx,y+dy
        if 0<=nx<H and 0<=ny<W and L+C[nx][ny] < dist[nx][ny] and C[nx][ny]==0:
            dist[nx][ny] = L+C[nx][ny]
            que.appendleft([L,nx,ny])
            
    for dx,dy in d1:
        nx,ny=x+dx,y+dy
        if 0<=nx<H and 0<=ny<W and L+C[nx][ny]+1 < dist[nx][ny] and C[nx][ny]==0:
            dist[nx][ny] = L+C[nx][ny]+1
            que.append([L+1,nx,ny])
ans=dist[gx][gy]
if ans==inf:print(-1)
else: print(ans)

Measured memory_bytes: 179540
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>

#define REP(i,x,y) for(ll i=x;i<=y;i++)
typedef long long ll;
using namespace std;

string s;
ll alph[30];
ll const MAX = 100005;
ll v[MAX];

int main() {
	cin >> s;
	ll n = s.size();
	if (n == 2) {
		if (s[0] == s[1]) {
			cout << 1 << " " << 2 << endl;
		}
		else {
			cout << -1 << " " << -1 << endl;
		}
		return 0;
	}
	REP(let, 0, 25) {
		v[0] = 0;
		REP(i, 1, n) {
			char c = s[i - 1];
			v[i] = v[i - 1];
			if (c == 'a' + let) {
				v[i]++;
			}
		}
		REP(i, 1, n) {
			v[i] = 2 * v[i]- i;
		}
		REP(i, 0, n - 2) {
			if (v[i] < v[i + 2]) {
				cout << i + 1 << " " << i + 2 << endl;
				return 0;
			}
		}
		REP(i, 0, n - 3) {
			if (v[i] < v[i + 3]) {
				cout << i + 1 << " " << i + 3 << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << endl;
}


Measured memory_bytes: 1280
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let X: i128 = sc.get();
    let X = X.abs();
    let K: i128 = sc.get();
    let D: i128 = sc.get();
    let ans = if D * K <= X {
        X - D * K
    } else {
        if K % 2 == X / D % 2 {
            X % D
        } else {
            D - X % D
        }
    };
    println!("{}", ans);
}


Measured memory_bytes: 2160