akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;

int num[20000];
bool used[20000];

int main(){
	int n;
	while(cin >> n && n){
		int count1 = n, count2 = n;
		bool update = true;
		bool bad = false;
		fill(used, used + 2 * n, false);
		for(int i = 0; i < 2 * n; i++){
			cin >> num[i];
		}
		while(update){
			update = false;
			for(int i = 0; i < n; i++){
				if(!used[i])
					if(num[i] == 0){
						used[i] = true;
						count2--;
						update = true;
					}else if(num[i] == count1){
						used[i] = true;
						count2--;
						for(int j = n; j < 2 * n; j++){
							if(!used[j]) num[j]--;
						}
						update = true;
					}
			}
			for(int i = n; i < 2 * n; i++){
				if(!used[i])
					if(num[i] == 0){
						used[i] = true;
						count1--;
						update = true;
					}else if(num[i] == count2){
						used[i] = true;
						count1--;
						for(int j = 0; j < n; j++){
							if(!used[j]) num[j]--;
						}
						update = true;
					}
			}
			if(bad) break;
		}
		if(count1 == 0 && count2 == 0 && !bad) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, h[200010], ma[200010];
  cin >> n >> m;
  for(int i=1; i<=n; i++) {
    ll height;
    cin >> height;
    h[i] = height;
    ma[i] = 0;
  }
  for (int i=0; i<m; i++) {
    int a, b;
    cin >>a>>b;
    ma[a] = max(ma[a],h[b]);
    ma[b] = max(ma[b],h[a]);
  }
  int ans =0;
  for (int i=1; i<=n; i++) {
    if (h[i] > ma[i]) {
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

int main() {
    int q;
    cin >> q;
    vector<int> num(100010);
    num[1] = 0;
    REP(i, 100000){
        if(i % 2 == 1 && prime(i) && prime((i+1)/2))num[i] = num[i-1]+1;
        else num[i] = num[i-1];
    }
    rep(i, q){
        int l, r;
        cin >> l >> r;
        cout << num[r]-num[l-1] << endl;
    }
}

Measured memory_bytes: 1024
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal
from argparse import ArgumentParser

args=ArgumentParser()
args.add_argument('-loc', '--local', type=bool,default=False)
LOCAL=args.parse_args().local

def input(): 
    x=sys.stdin.readline(); 
    if x[-1]=="\n": 
        return x.rstrip() 
    return x
    
def printe(*x):_=print("## ",*x,file=sys.stderr) if LOCAL else 0
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    N = int(input())
    #N, K = map(int, input().split())
    cs = list(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列

    cs.sort()
    p2=[pow(2,i,mod) for i in range(N+1)]
    ans=0

    x=2*p2[N-1]**2%mod
    y=4*p2[N-2]**2%mod

    for i,c in enumerate(cs):
        if i<(N-1):
            ans+=y*c%mod*(N-1-i)
            ans%=mod
        ans+=x*c
        ans%=mod
    print(ans)
        


if __name__ == "__main__":
    main()

Measured memory_bytes: 116576
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int H,W;
    string s[102];
    cin >> H >> W;
    s[0] = string(W+2,'#');
    s[H+1] = string(W+2,'#');
    for(int i = 1;i <= H;i++){
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    for(int i = 0;i <= H+1;i++){
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 256
N=int(input())
L=[str(i) for i in [11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,
  881,911,941,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381,1451]]

print(" ".join(L[:N]))

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val zorome = intArrayOf(111, 222, 333, 444, 555, 666, 777, 888, 999)
    val n = readLine()!!.toInt()
    for (x in n..999) {
        if (zorome.indexOf(x) != -1) {
            println(x)
            break
        }
    }
}


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

int main() {
  int N;
  cin >> N;
  vector<int> b(N);
  for (int i = 0; i < N; i++) {
    cin >> b[i];
  }
  
  int a = 1;
  int x = 0;
  for (int i = 0; i < N; i++) {
    a = b[a - 1];
    x++;
    if (a == 2)
      break;
    if (i == N - 1)
      x = -1;
  }
  cout << x << endl;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000
 
int L[MAX/2+2],R[MAX/2+2];
int cnt;
 
void merge(int A[], int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for(int i = 0; i < n1; i++) L[i] = A[left + i];
    for(int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for(int k = left; k < right; k++) {
        cnt++;
        if(L[i] <= R[j]) {
            A[k] = L[i++];
        }
        else {
            A[k] = R[j++];
        }
    }   
} 
 
void mergeSort(int A[], int left, int right) {
    if(left + 1 < right) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}
 
int main() {
    int A[MAX], n, i;
    cnt = 0;
     
    cin >> n;
    for(i = 0; i < n; i++) cin >> A[i];
     
    mergeSort(A, 0, n);
     
    for(i = 0; i < n; i++){
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
     
    cout << cnt << endl;
     
    return 0; 
}

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

#define MAX 500005
#define INF 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

void merge(int A[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  for ( int i = 0; i < n1; i++ ) L[i] = A[left + i];
  for ( int i = 0; i < n2; i++ ) R[i] = A[mid + i];
  L[n1] = R[n2] = INF;
  int i = 0, j = 0;
  for ( int k = left; k < right; k++ ) {
    cnt++;
    if ( L[i] <= R[j] ) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(int A[], int left, int right) {
  if ( left + 1 < right ) {
    int mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}

int main() {
  int n;
  int A[MAX];

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

  mergeSort(A, 0, n);

  for ( int i = 0; i < n; i++ ) {
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  cout << endl << cnt << endl;

  return 0;
}

Measured memory_bytes: 7024
#include<iostream>
using namespace std;
int main(){
	int a,lowest,total=0;
	for(int i=0;i<5;i++){
		cin>>a;
		if(a%10&&(!i||a%10<lowest))lowest=a%10;
		total+=(a+9)/10*10;
	}
	cout<<total+lowest-(lowest?10:0)<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<climits>

using namespace std;


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

int main(){

    int N,K;
    cin >> N >> K;
    vector<int> hVec(N);
    for(int i = 0; i < N;i++) cin >> hVec.at(i);


    vector<int> dp(N+K,INT_MAX);
    dp[0] = 0;
    for(int i =0; i < N ; i++){
        for(int j = 1; j<=K; j++){
            chmin(dp[i+j],dp[i] + abs(hVec[i] - hVec[i+j]));
        }
    }

    cout << dp[N-1];
    
    return 0;

}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	bool ans = true;
	int line = a[0]-1;
	for(int i=1; i<n; i++){
		if(a[i]<line){
			ans = false;
			break;
		}
		if(a[i]-1>line){
			line = a[i]-1;
		}
	}
	cout << (ans?"Yes":"No") << endl;
}

Measured memory_bytes: 640
n = int(input())
a = list(map(int,input().split()))

a.sort(reverse=True)
for i in range(len(a)-1):
    if a[i] == a[i+1]:
        a1 = a[i]
        break
    elif i == len(a)-2:
        print(0)
        exit()
    else:
        continue
b = []
l=0
for i in range(len(a)):
    if a[i] == a1 and l<2:
        l += 1
    else:
        b.append(a[i])
b.sort(reverse=True)
for i in range(len(b)-1):
    if b[i] == b[i+1]:
        a2 = b[i]
        break
    elif i == len(b)-2:
        print(0)
        exit()
    else:
        continue
print(a1*a2)


Measured memory_bytes: 14480
#include<stdio.h>

int main()
{
     int W,H,x,y,r;
     scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
     if(x - r < 0 || x+r >W || y - r <0 || y + r > H){
          printf("No\n");
     }else if(x-r>=0 && x+r<=W && y-r>=0 && y+r<=H){
            printf("Yes\n");
     }
     return 0;
}


Measured memory_bytes: 2112
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30


int main(){
    std::ios_base::sync_with_stdio(false);
    int N,A,B;
    cin >> N >> A >> B;

    int _a=0, a_b=0, b_=0;
    REP(i,N){
        int p; cin >> p;
        if(p<=A){
            _a++;
        } else if(p>=A+1 && p<=B){
            a_b++;
        } else {
            b_++;
        }
    }

    cout << min(_a, min(a_b, b_)) << endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define vci vector<ll>
#define vcs vector<string>
#define vcp vector<pair<ll, ll>>
#define vct vector<tuple<ll, ll, ll>>
using namespace std;
//vector<vector<ll>> vv(n, vector<ll>(n));

typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

int main()
{
	ll n;
	cin >> n;
	if (n / 100 == n % 10) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
import math

def main():
    N = int(input())
    ans = [0]*(N+1)

    rn = math.ceil(math.sqrt(N))

    for x in range(1,rn):
        for y in range(1,rn):
            for z in range(1,rn):
                k = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if k <= N:
                    ans[k-1] += 1
    
    for i in range(len(ans) - 1):
        print(ans[i])
    
main()

Measured memory_bytes: 68908
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		x := i
		if x%3 == 0 {
			fmt.Print(" ", x)
		} else {
			for x > 0 {
				if x%10 == 3 {
					fmt.Print(" ", i)
					break
				} else {
					x /= 10
				}
			}
		}
	}
	fmt.Println()
}



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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;


const int N = 100010;
const ll MOD = 1e9+7;
vi adj[N];
bool visited[N];
int n;
ll A[N], B[N];

void dfs(int v) {
	if(visited[v]) return;
	visited[v] = true;

	int count = 0;
	ll W = 1, D = 1;
	for(auto u : adj[v]) {
		if(!visited[u]) {
			dfs(u);
			count++;

			W *= (A[u] + B[u]);
			D *= (A[u]);
			W %= MOD;
			D %= MOD;
		}
	}
	if(count == 0) {
		A[v] = 1;
		B[v] = 1;
	} else {
		A[v] = W;
		B[v] = D;
	}
}

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	cin >> n;
	M00(i, n-1) {
		int u, v;
		cin >> u  >> v;
		u--; v--;
		adj[u].pb(v);
		adj[v].pb(u);
	}
	dfs(0);
	finish((A[0] + B[0]) % MOD);
}


Measured memory_bytes: 14336
/* ex7_3
  */

#include <stdio.h>
#include <stdlib.h>

int main(void){
    int height, width; //変数の定義
    int i, j;
    char **ptr; //入力の表を記憶する二次元配列
    int *row ,*col;


    scanf("%d %d", &height, &width);

    ptr = (char**)calloc(height, sizeof(char*));
    if(ptr == NULL){
        exit(1);
    }
    for(i = 0; i < height; i++){
        ptr[i] = (char*)calloc(width+1, sizeof(char));
        if(ptr[i] == NULL){
            exit(1);
        }
    }


    for(i=0; i<height; i++){ //入力の表を二次元配列に記憶
        for(j=0; j<width+1; j++){
            scanf("%c", &ptr[i][j]);
        }
    }

    row = (int*)calloc(height, sizeof(int));
    if(row ==NULL){
        exit(1);
    }

    col = (int*)calloc(width, sizeof(int));
    if(col ==NULL){
        exit(1);
    }


    for(i=0; i<height; i++){ //二次元配列を全探索して、#がある行、列を記憶
        for(j=0; j<width+1; j++){
            if (ptr[i][j] == '#'){
                row[i] = 1;
                col[j] = 1;
            }
        }
    }
    for(i=0; i<height; i++){
        if(row[i] == 1){ //i番目の行に#が含まれている
            for(j=0; j<width+1; j++){
                if(col[j] == 1){ //j番目の列にも#が含まれている
                    printf("%c", ptr[i][j]);//出力
                }
            }
            printf("\n"); //一行出力したら改行
        }
    }

    for(i = 0; i < height; i++){
        free(ptr[i]);
    }
    free(ptr);

   
        free(row);
        free(col);
    

    return 0;
}


Measured memory_bytes: 1668
N = int(input())
S = list(input())
R = []
G = []
B = []
Rsize =0
Gsize =0
Bsize =0
for i in range(0,N,1):
    if S[i] == "R":
        Rsize+=1
    elif S[i] == "G":
        Gsize+=1
    elif S[i] == "B":
        Bsize+=1
counter = Rsize*Gsize*Bsize
for i in range(0,N-1,1):
    for j in range(i+1,N,1):
        k = 2*j - i
        if k < N:
            if S[i]!=S[j] and S[j]!=S[k] and S[i]!=S[k]:
                counter -=1
print(counter)

Measured memory_bytes: 68444
#include <stdio.h>

int main(void){
	unsigned long int i,j,sum;
	unsigned int count = 0;
	while(1){
		if(scanf("%ld %ld",&i,&j)==EOF)	break;
		
		sum = i+j;
		count = 0;
		for(unsigned long int dec=10;dec<=1000000;dec*=10){
			if(sum < dec)	break;
			count ++;
		}
		printf("%d\n",count+1);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;

#define p(x) cout << x << endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define range(i, begin, end) for (int i = begin; i < (int)(end + 1); i++)
#define all(x) (x).begin(), (x).end()

vector<int> to[200005];
vector<int> ans;

void dfs(int start, int origin) {
  for (int u : to[start]) {
    if (u == origin) {
      continue;
    }
    ans[u] += ans[start];
    dfs(u, start);
  }
}

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

  vector<int> as(n - 1), bs(n - 1), ps(q), xs(q);
  rep(i, n - 1) { cin >> as[i] >> bs[i]; }
  rep(i, q) { cin >> ps[i] >> xs[i]; }

  rep(i, n - 1) {
    to[as[i] - 1].push_back(bs[i] - 1);
    to[bs[i] - 1].push_back(as[i] - 1);
  }

  ans.resize(n);
  rep(i, q) { ans[ps[i] - 1] += xs[i]; }

  dfs(0, -1);

  rep(i, n) { p(ans[i]); }

  return 0;
}


Measured memory_bytes: 27904
#include<iostream>
using namespace std;
int main(void)
{
    int a,b,fl;
    while(cin>>a>>b)
    {
        fl=0;
        for(int i=1;fl==0;i++)
        {
            if(a%i==0&&b%(a/i)==0)
            {
                cout<<a/i<<" ";
                fl++;
            }
            else;
        }
        fl=0;
        for(int i=1;fl==0;i++)
        {
            if((a*i)%b==0)
            {
                cout<<a*i<<endl;
                fl++;
            }
            else;
        }
    }
    return 0;
}


Measured memory_bytes: 3080
class English
  def initialize
    @lists = {}
    @max_test = ""
    @max_size = 0
    @fre_text = ""
    @text = $stdin.gets.chomp.split(' ')

    @text.each do |t|
      if @max_size < t.size
        @max_size = t.size
        @max_text = t
      end

      if @lists.has_key?(t)
        @lists[t] += 1
      else
        @lists[t] = 1
      end
    end

    max = 0

    @lists.each_pair do |t, count|
      if max < count
        max = count
        @fre_text = t
      end
    end

    puts "#{@fre_text} #{@max_text}"
  end
end

e = English.new

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  long n,a[200000],sum[200000];
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> a[i];

  long cnt1 = 0;
  for(int i = 0; i < n; i++) {
    if(i == 0) sum[i] = a[i];
    else sum[i] = sum[i-1] + a[i];

    if(i % 2 == 0 & sum[i] <= 0) {
      cnt1 += abs(sum[i]) + 1;
      sum[i] = 1;
    }
    else if(i % 2 == 1 & sum[i] >= 0) {
      cnt1 += abs(sum[i]) + 1;
      sum[i] = -1;
    }
  }
  long cnt2 = 0;
  for(int i = 0; i < n; i++) {
    if(i == 0) sum[i] = a[i];
    else sum[i] = sum[i-1] + a[i];

    if(i % 2 == 0 & sum[i] >= 0) {
      cnt2 += abs(sum[i]) + 1;
      sum[i] = -1;
    }
    else if(i % 2 == 1 & sum[i] <= 0) {
      cnt2 += abs(sum[i]) + 1;
      sum[i] = 1;
    }
  }

  cout << min(cnt1,cnt2) << endl;
  return 0;
}

Measured memory_bytes: 5180
#include<iostream>
#include<iomanip>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


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

	int N;
	cin >> N;
	vector<int> P(N), Q(N);
	REP(i, N) cin >> P[i];
	REP(i, N) cin >> Q[i];
	vector<int> R(N);
	REP(i, N) R[i] = i + 1;
	int i = 0;
	int a = 0, b = 0;
	do {
		if (a > 0 && b > 0) break;
		++i;

		if (P == R) a = i;
		if (Q == R) b = i;

	} while (next_permutation(R.begin(), R.end()));

	cout << abs(a - b) << endl;

	return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define rep(i,N) for(int i=0;i<N;i++)

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

  int N;
  cin>>N;
  vector<int>p(N);
  for(auto&it:p)cin>>it;
  ll ans=0;
  for(int i=0;i<N;i++){
    if(p[i]==i+1){
      ans++;
      if(i+1<N&&p[i+1]==i+2)i++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include<cstdio>
int main()
{
	int n;
	scanf("%d",&n);
	long long x=0LL,y=0LL,z=0LL,a,b,t;
	for(int i=0;i<n;i++)
	{
		scanf("%lld%lld%lld",&t,&a,&b);
		long long len=a-x+b-y,tim=t-z;
		if(tim<len||(tim-len)%2)
		{
			printf("No\n");
			return 0;
		}
		x=a,y=b,z=t;
	}
	printf("Yes\n");
}

Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int n, i, top, south, east, a, b;
  char houkou[6];

  while(1){
    top = 1;
    south = 2;
    east = 3;
    a = 1;
    scanf("%d",&n);
    if(n == 0) break;
    for(i = 0 ; i < n ; i++){
      scanf("%s",&houkou);
      switch(houkou[0]){
      case 'N':
	b = top;
	a += south;
	top = south;
	south = 7 - b;
	break;
      case 'S':
	b = top;
	a += 7 - south;
	top = 7 - south;
	south = b;
	break;
      case 'E':
	b = top;
	a += 7 - east;
	top = 7 - east;
	east = b;
	break;
      case 'W':
	b = top;
	a += east;
	top = east;
	east = 7 - b;
	break;
      case 'R':
	b = south;
	a += top;
	south = east;
	east = 7 - b;
	break;
      case 'L':
	b = south;
	a += top;
	south = 7 - east;
	east = b;
	break;
      }
    }
    printf("%d\n",a);
  }

  return 0;

}

Measured memory_bytes: 604
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.AGC026
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            long[,] query = new long[t, 4];
            for (int i = 0; i < t; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                query[i, 0] = long.Parse(input[0]);
                query[i, 1] = long.Parse(input[1]);
                query[i, 2] = long.Parse(input[2]);
                query[i, 3] = long.Parse(input[3]);
            }

            for (int i = 0; i < t; i++)
            {
                if (Eternal(query[i, 0], query[i, 1], query[i, 2], query[i, 3]))
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }

        static bool Eternal(long a, long b, long c, long d)
        {
            if (b > d || b > a) return false;//絶対無理のパターン
            if (b <= c) return true;//絶対okのパターン

            long margin = a % b;
            if (c < margin) return false;
            if (d % b == 0) return true;
            Stack<long> stack = new Stack<long>();
            long delta = d % b;

            while (!stack.Contains(margin))
            {
                stack.Push(margin);
                long cnt = (c - margin) / delta + 1;
                margin += delta * cnt;
                margin %= b;
                if (c < margin) return false;
            }
            return true;
        }
    }
}

Measured memory_bytes: 13248
#include <cstdio>
const int N = 100050;
typedef long long LL;
int son[N][2], cnt = 1;
int dep[N];
LL SG[N];
char s[N];
inline LL lowbit(LL x) {
  return x & -x;
}
int main() {
  int n;
  LL l;
  scanf("%d%lld", &n, &l);
  for (int i = 0; i < n; ++i) {
    scanf("%s", s);
    int o = 0;
    for (int j = 0; s[j]; ++j) {
      int t = s[j] - '0';
      if (!son[o][t])
        dep[son[o][t] = cnt++] = dep[o] + 1;
      o = son[o][t];
    }
  }
  for (int i = cnt - 1; ~i; --i) {
    if (!son[i][0] && !son[i][1]) SG[i] = 0;
    else {
      LL SG0 = son[i][0] ? SG[son[i][0]] : lowbit(l - dep[i]);
      LL SG1 = son[i][1] ? SG[son[i][1]] : lowbit(l - dep[i]);
      SG[i] = SG0 ^ SG1;
    }
  }
  puts(SG[0] ? "Alice" : "Bob");
  return 0;
}


Measured memory_bytes: 2176
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    ll h1,m1,h2,m2,K;
    cin>>h1>>m1>>h2>>m2>>K;
    ll time_left=0;
    if(m2<m1)
    {
        m2+=60;
        h2--;
    }
    if(h2<h1)
    {
        h2+=24;
    }
    time_left=(h2-h1)*60+(m2-m1);
    cout<<max(0LL,time_left-K)<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b;
    cin >> a >> b;
    if ((a == 0) || (b == 0)) {
        cout << "Zero" << endl;
    }
    else if ((a < 0) && (b < 0)) {
        ll cnt = abs(a - b) + 1;
        if (cnt % 2 == 0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    else if ((a < 0) && (b > 0)) {
        cout << "Zero" << endl;
    }
    else if ((a > 0) && (b > 0)) {
        cout << "Positive" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <iostream>
#include <functional>

using namespace std;

int main()
{
		int i, num;
        deque< int > index;
		int d[5];
		cin >> d[0] >> d[1] >> d[2] >> d[3] >> d[4];	   
	    for ( i = 0; i < 5; i++ ) {
              index.push_back( d[i] );
       }
       sort( index.begin(), index.end(), greater< int >() );

       deque< int >::iterator it = index.begin();
        for ( i = 0; i < 5; i++ ) {
              cout << *it;
			  if( i != 4 ){
				  cout << " ";
			  }
              it++;
       }
		cout << endl;

        return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef pair<int, int> P;
string str[100];
bool used[100];
int main() {
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> str[i];
	}
	vector<P> v;
	for (int i = 0; i < N; i++) {
		int s = 0;
		int m = 0;
		for (int j = 0; j < str[i].size(); j++) {
			if (str[i][j] == '(') s++;
			else s--;
			m = min(s, m);
		}
		if (s >= 0) v.emplace_back(s, m);
	}
	int l = 0;
	while (1) {
		bool update = 0;
		for (int i = 0; i < v.size(); i++) {
			if (used[i] || l < -v[i].second) continue;
			l += v[i].first;
			used[i] = 1;
			update = 1;
		}
		if (!update) break;
	}
	for (int i = 0; i < v.size(); i++) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	v.clear();
	for (int i = 0; i < N; i++) {
		int s = 0;
		int m = 0;
		for (int j = str[i].size() - 1; j >= 0; j--) {
			if (str[i][j] == ')') s++;
			else s--;
			m = min(s, m);
		}
		if (s >= 0) v.emplace_back(s, m);
	}
	memset(used, 0, sizeof(used));
	int r = 0;
	while (1) {
		bool update = 0;
		for (int i = 0; i < v.size(); i++) {
			if (used[i] || r < -v[i].second) continue;
			r += v[i].first;
			used[i] = 1;
			update = 1;
		}
		if (!update) break;
	}
	for (int i = 0; i < v.size(); i++) {
		if (!used[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	if (l == r) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

int n;
ll k;
vector<ll> score_0(100);
vector<ll> score_1(100);
vector<ll> i_cost(100);
vector<ll> i_score(100);

ll solve(ll cost, ll score, int d) {
    ll c = 1ll<<d;
    if(d==0) {
        if(cost + 1ll > k) return score + score_0[0];
        else return score + i_score[0];
    }
    if(cost + c <= k) {
        return max(solve(cost+c, score+score_1[d], d-1), score+score_0[d]+i_score[d-1]);
    }
    else return solve(cost, score+score_0[d], d-1);
}

int main() {
    cin >> n >> k;
    rp(i, 0, n) {
        ll a; scanf("%lld", &a);
        ll s = 1ll;
        rp(j, 0, 50) {
            if(s & a) score_0[j] += s;
            else score_1[j] += s;
            s*=2;
        }
    }
    if(score_0[0] < score_1[0]){
        i_score[0] = score_1[0];
        i_cost[0] = 1ll;
    }
    else i_score[0] = score_0[0];
    rp(i, 1, 50) {
        if(score_0[i] < score_1[i]) {
            i_score[i] = i_score[i-1] + score_1[i];
            i_cost[i] = i_cost[i-1] + (1ll<<i); 
        }
        else {
            i_score[i] = i_score[i-1] + score_0[i];
            i_cost[i] = i_cost[i-1];
        }
        // printf("i = %d score_0 = %lld score_1 = %lld i_score=%lld i_cost=%lld\n", i, score_0[i], score_1[i], i_score[i], i_cost[i]);
    }
    cout << solve(0ll, 0ll, 50) << endl;
    return 0;
}



Measured memory_bytes: 3696
#include <stdio.h>

int main(void) {
  int i, j, k, v, a[100], n, l;
  char buf[2];
  scanf("%d", &l);
  for (n = 0; n < l && (j = scanf("%d%1[\n]", a+n, buf)) == 1; n++) ;
  if (j == 2)
  n++;

  for (k = 0; k < n; k++) {
    printf("%d", a[k]);
    if (k < n - 1) {
      printf(" ");
    }
  }
  printf("\n");

  for (i = 1; i < n; i++) {
    v = a[i];
    j = i - 1;
    while (j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    for (k = 0; k < n; k++) {
      printf("%d", a[k]);
      if (k < n - 1) {
        printf(" ");
      }
    }
    printf("\n");
  }

  return 0;
  }



Measured memory_bytes: 2136
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define setbitc(x) __builtin_popcount(x)
#define init(x,a) memset(x,a,sizeof(x))
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
ll n,m,k,ar[N],br[N];
string s,s1;
//Variables End

int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
    	ll n,m,v,p;
		cin>>n>>m>>v>>p;
		vector<ll> in(n,0),pre(n,0);
		map<ll,ll> ma;
		rep(i,0,n){cin>>in[i];ma[in[i]]++;}
		sort(all(in));
		pre[0]=in[0];
		rep(i,1,n)pre[i]=pre[i-1]+in[i];
		ll ans=0;
		rep(i,0,n)
		{
			ll t1=upper_bound(all(in),in[i]+m)-in.begin();
			ll t2=upper_bound(all(in),in[i])-in.begin();
			ll cnt=n-t1;
			if(cnt>=p)continue;
			t1=n-(p-1);
			if(t1==t2){ans++;continue;}
			ll V=v-t2-(n-t1);
			if(V<=0){ans++;continue;}
			ll add=(t1-t2)*(in[i]+m)-pre[t1-1]+pre[t2-1];
			if(add>=m*V)ans++;
		}        
		cout<<ans<<endl;
    }
    return 0;
        
}

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

int main() {
  int n,cnt=0,l;
  cin >> n;
  set <int> S;
  vector<int>a(1000010,0);

  for (int i = 0; i < n; i++) {
    cin >> l;
    a.at(l)++;
    S.insert(l);
  }

  for (auto value : S) {
    if (a.at(value)!= 1) continue;
    bool check = 1;   
    set <int> T;
    for (int i = 1; i*i <= value; i++) {
      if (value%i == 0) {
        T.insert(i);
        T.insert(value/i);
      }
    }
    T.erase(value);
  
    for (auto value2 : T) {
        if (S.count(value2)) {
          check = 0;
          break;
        }
      }
      if (check) cnt++; 
  }
  cout << cnt << endl;
}

Measured memory_bytes: 16456
import java.util.*;

public class Main {
    static List<List<Integer>> searchIsland(int i, int j, int h, int w, List<List<Integer>> island) {
        if(island.get(i).get(j) == 0) return island;
        island.get(i).set(j,0);
        if(i+1 < h && j+1 < w) island = searchIsland(i+1, j+1, h, w, island);
        if(i+1 < h && j-1 >= 0) island = searchIsland(i+1, j-1, h, w, island);
        if(i-1 >= 0 && j+1 < w) island = searchIsland(i-1, j+1, h, w, island);
        if(i-1 >= 0 && j-1 >= 0) island = searchIsland(i-1, j-1, h, w, island);
        if(i+1 < h) island = searchIsland(i+1, j, h, w, island);
        if(i-1 >= 0) island = searchIsland(i-1, j, h, w, island);
        if(j+1 < w) island = searchIsland(i, j+1, h, w, island);
        if(j-1 >= 0) island = searchIsland(i, j-1, h, w, island);
        return island;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            List<List<Integer>> island = new ArrayList<>();
            int w = sc.nextInt();
            int h = sc.nextInt();
            if(w == 0 && h == 0) break;

            for(int i = 0; i < h; i++) {
                List<Integer> list = new ArrayList<>();
                for(int j = 0; j < w; j++) {
                    int x = sc.nextInt();
                    list.add(x);
                }
                island.add(list);
            }

            int count = 0;
            for(int i = 0; i < h; i++) {
                for(int j = 0; j < w; j++) {
                    if(island.get(i).get(j) == 1) {
                        count++;
                        island = searchIsland(i, j, h, w, island);
                    }
                }
            }
            System.out.println(count);
        }
    }
}


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

int MAX_VALUE = 10e5;

vector<bool> make_primes(int n) {
    vector<bool> is_prime(n + 1, true);
    is_prime[0] = false;
    is_prime[1] = false;
    for (int i = 2; i <= n; ++i) {
        for (int j = i * 2; j <= n; j += i) {
            is_prime[j] = false;
        }
    }
    return is_prime;
}

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

    vector<pair<int, int>> data(n);
    for (int i = 0; i < n; ++i) {
        cin >> data[i].first >> data[i].second;
    }

    vector<bool> is_prime = make_primes(MAX_VALUE);
    vector<int> prime_counter(MAX_VALUE + 1);
    for (int i = 2; i <= MAX_VALUE; ++i) {
        prime_counter[i] = prime_counter[i - 1];
        if (is_prime[i] && is_prime[(i + 1) / 2]) {
            ++prime_counter[i];
        }
    }

    for (int i = 0; i < n; ++i) {
        int ans =
            prime_counter[data[i].second] - prime_counter[data[i].first - 1];
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5504
def main():
  n, m = input_list()
  p = prime_factorize(m)
  pc = collections.Counter(p)
  ans = 1
  for k, v in pc.items():
    if v >= n:
      ans *= k ** (v//n)
  print(ans)
  
def input_list():
  return list(map(int, input().split()))

def input_list_str():
  return map(str, input().split())

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

import math
import fractions
import collections
from functools import reduce
main()

Measured memory_bytes: 5076
n,x = map(int,input().split())
l_list = list(map(int,input().split()))
total = 0
ans = 0
#print(l_list)
for i in range(n):
    if total <= x:
        ans += 1
    else:
        break
    total += l_list[i]
if total <=x:
    ans += 1
print(ans)


Measured memory_bytes: 38256
#include <iostream>
#include <vector>
#include <string>
#include<map>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int N;
    cin >> N;
    long long count = 0;
    for (int i = 1; i <= N; i++) {
        if (i % 3 == 0 || i % 5 == 0) {

        }
        else {
            count = count + i;
        }
    }
    cout << count << endl;

    return 0;
}



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

int x[2000],y[2000];
int xx[2000],yy[2000];
int dx[]{-1,1,1,-1},dy[]{-1,1,-1,1};
string s="LRDU";

int main(){
	int n;scanf("%d",&n);
	set<int>se;
	rep(i,n){
		scanf("%d%d",&x[i],&y[i]);
		se.insert(abs((x[i]+y[i])%2));
		xx[i]=x[i]-y[i];
		yy[i]=x[i]+y[i];
	}
	if(se.size()>1){
		puts("-1");return 0;
	}
	vector<ll>v;
	if(*se.begin()==0)v.push_back(1);
	rep(i,35){
		v.push_back(1LL<<i);
	}
	reverse(v.begin(),v.end());
	cout<<v.size()<<endl;
	rep(i,v.size()){
		printf("%lld ",v[i]);
	}
	puts("");
	rep(i,n){
		ll X=xx[i],Y=yy[i];
		string ans;
		for(ll d:v){
			int id=-1;
			rep(k,4){
				if(X*dx[k]>=0&&Y*dy[k]>=0)id=k;
			}
			X-=dx[id]*d;Y-=dy[id]*d;
			ans+=s[id];
		}
		printf("%s\n",ans.data());
	}
}

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

#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 300;

int n;
char grid[N][2 * N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			cin >> grid[i][j];
		}
		for (int j = 0; j < n; ++j) grid[i][j + n] = grid[i][j];
	}
	
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		bool valid = true;
		for (int j = 0; j < n; ++j) {
			for (int k = 0; k < n; ++k) {
				if (grid[j][k + i] != grid[k][j + i]) valid = false;
			}
		}
		
		if (valid) ++ans;
	}
	
	cout << ans * n;
}


Measured memory_bytes: 3796
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
#define outdicimal out << fixed << setprecision(10)//TODO 小数点以下の桁数の変更
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;


class AAtCoderBeginnerContest999 {
public:
	void solve(std::istream& in, std::ostream& out) {
    string s;
    in >> s;
    REP(i, s.length()){
      if(s[i] == '1'){
        s[i] = '9';
      }
      else if(s[i] == '9'){
        s[i] = '1';
      }
    }
    out << s << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	AAtCoderBeginnerContest999 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
As = []
for i in range(N):
  A = int(input())
  As.append(A)
def find2(s, A):
  import math
  a = 0
  b = len(s)
  while a < b:
    i = (a+b)//2
    if s[i] < A:
      b = i
    else:
      if a == i:
        break
      a = i
  return b

num = 1
c = As[0]
s = [c]
for i in range(1,N):
  A = As[i]
  index = find2(s, A)
  #index = -1
  #for j in range(len(s)):
  #  if s[j] < A:
  #    index = j
  #    break
  #print(s, A, index)
  if index < len(s):
    #print(i, A, "B", index)
    s[index] = A
  else:
    #print(i, A, "C")
    num += 1
    s.append(A)
    c = A
print(num)


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


int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int L = x[0], R = x[0];
  rep(i,n){
    L=min(L,x[i]);
    R=max(R,x[i]);
  }
  int minv = INF;
  for(int p = L; p <= R; ++p){
    int sum = 0;
    rep(i,n){
      sum += (x[i]-p)*(x[i]-p);
    }
    minv = min(sum,minv);
  }
  cout << minv << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  ll x,n,ans=0,t=0,r=0;cin>>x>>n;
  ll a[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  for(int i=0;i<=100;i++){
    for(int j=0;j<n;j++){
      if(a[j]!=x+i){t++;}
      if(a[j]!=x-i){r++;}
    }
      if(r==n){ans=x-i;break;}
      if(t==n){ans=x+i;break;}
    t=0;r=0;
  }
  if(n==0){ans=x;}
  cout << ans<<endl;
}

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // int num, a, b, c, d;
    // cin >> num;
    // d = num % 10;
    // num /= 10;
    // c = num % 10;
    // num /= 10;
    // b = num % 10;
    // num /= 10;
    // a = num % 10;
    
    int a[4];
    string s;
    cin >> s;
    for(int i=0; i<4; i++)a[i] = s[i] - '0';
    
    for(int i=0; i<2; i++){
        for(int j=0; j<2; j++){
            for(int k=0; k<2; k++){
                int sum = a[0];
                if(i==0)sum += a[1];
                else sum -= a[1];
                if(j==0) sum += a[2];
                else sum -= a[2];
                if(k==0) sum += a[3];
                else sum -= a[3];
                
                if(sum==7){
                    char op1, op2, op3;
                    if(i==0)op1 = '+';
                    else op1 = '-';
                    if(j==0) op2 = '+';
                    else op2 = '-';
                    if(k==0) op3 = '+';
                    else op3 = '-';
                    cout << a[0] << op1 << a[1] << op2 << a[2] << op3 << a[3] << "=7" << endl;
                    exit(0);
                }
            }
        }
    }
    // cout << a << b << c << d << endl;
    
    
}

Measured memory_bytes: 256
import sys
S = input()
A = S[0]
B = S[1]
C = S[2]
D = S[3]
if int(A) + int(B) + int(C) + int(D) == 7:
    print(A + '+' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) + int(D) == 7:
    print(A + '-' + B + '+' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) + int(D) == 7:
    print(A + '+' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) + int(D) == 7:
    print(A + '-' + B + '-' + C + '+' + D + '=7')
    sys.exit()
if int(A) + int(B) + int(C) - int(D) == 7:
    print(A + '+' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) + int(C) - int(D) == 7:
    print(A + '-' + B + '+' + C + '-' + D + '=7')
    sys.exit()
if int(A) + int(B) - int(C) - int(D) == 7:
    print(A + '+' + B + '-' + C + '-' + D + '=7')
    sys.exit()
if int(A) - int(B) - int(C) - int(D) == 7:
    print(A + '-' + B + '-' + C + '-' + D + '=7')
    sys.exit()


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 128
int data[MAX];
int top = 0;
void initialize();
int isFull();
int isEmpty();
void push(int);
int pop();
int main(void){
    int a, b;
    char s[100];
    while(scanf("%s", s) != EOF){
        if(s[0] == '+'){
            a = pop();
            b = pop();
            push(a + b);
        } else if(s[0] == '-'){
            a = pop();
            b = pop();
            push(b - a);
        } else if(s[0] == '*'){
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }
    printf("%d\n", pop());

    return 0;
}
void initialize(){
    top = 0;
    return;
}
int isFull(){
    return top == MAX;
}
int isEmpty(){
    return top == 0;
}
void push(int num){
    top++;
    data[top] = num;
    return;
}
int pop(){
    top--;
    return data[top+1];
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

ll square(ll a){
    ll left=0, right=a;
    while(right-left>1){
        ll mid=(left+right)/2;
        if(mid*mid>=a) right=mid;
        else left=mid;
    }
    return left;
}

int main(){
    ll q; cin>>q;
    rep(i,q){
        ll a,b; cin>>a>>b;
        if(a==b) {
            cout<<2*a-2<<endl;
            continue;
        }
        if(a>b) swap(a,b);
        if(a+1==b) {
            cout<<2*a-2<<endl;
            continue;
        }
        ll c=ceil(sqrt(a*b))-1;
        if(c*(c+1)>=a*b){
            cout<<2*c-2<<endl;
        }else{
            cout<<2*c-1<<endl;
        }
    }
}

Measured memory_bytes: 256