akhauriyash/Code-Regression huggingface dataset:
require 'prime'
N = gets.to_i
DS = N.prime_division
def dig(m,i,&f)
  if i == DS.size
    return f.call(m)
  end
  a,b = DS[i]
  (0..b).each{ |j| dig(m*(a**j), i+1, &f) }
end

ans = N.to_s.size
dig(1,0) { |a| ans = [ans, [a,N/a].map{ |x| x.to_s.size }.max].min }
p ans


Measured memory_bytes: 2300
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define N 3010
using namespace std;
struct edges{
	int to,pre;
}e[N<<1];int h[N],etop,a[N];
inline int add_edge(int u,int v)
{	return e[++etop].to=v,e[etop].pre=h[u],h[u]=etop;	}
int can(int x,int fa=0)
{
	for(int i=h[x];i;i=e[i].pre)
	{
		int y=e[i].to;if(y==fa) continue;
		if(a[x]>a[y]&&!can(y)) return true;
	}
	return false;
}
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<n;i++)
	{
		int u,v;scanf("%d%d",&u,&v);
		add_edge(u,v),add_edge(v,u);
	}
	for(int i=1;i<=n;i++)
		if(can(i)) printf("%d ",i);
	return !printf("\n");
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int sum1 = 0;
		int sum2 = 0;

		for (int i = 0; i < a; i++) {
			String b = scanner.next();
			String c = scanner.next();
			if (b.compareTo(c) > 0)
				sum1 += 3;
			else if (b.compareTo(c) < 0)
				sum2 += 3;
			else {
				sum1 += 1;
				sum2 += 1;
			}
		}
		System.out.println(String.format("%d %d", sum1, sum2));
	}
}


Measured memory_bytes: 31044
N=int(input())
A=list(map(int,input().split()))
B=[]
for i in range(N):
  B.append(A[i]-(i+1))
B.sort()
if N%2==0:
  a=N/2
  b=int((B[int(a)]+B[int(a-1)])/2)
else:
  a=(N+1)/2
  b=B[int(a-1)]
for i in range(N):
  B[i]=abs(B[i]-b)
print(sum(B))
 
  
  

Measured memory_bytes: 30848
N,K = map(int,input().split())
def solve1(dice,K):
    i = 0
    while dice < K :
        dice = dice * 2
        i += 1
    return i
ans = 0
for p in range(1,N+1,1):
    ans += (1/N)*(1/2)**solve1(p,K)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define P 1000000007
#define ll long long
using namespace std;

ll a[2001];
ll inv[2001];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main(){
  ll N,K,z1,z2,x = 1;
  cin >> N >> K;
  a[0] = 1;
  inv[0] = 1;
  FOR(i,1,N+1){
    x = (x*i)%P;
    a[i] = x;
    inv[i] = modinv(x,P);
  }
  FOR(i,1,K+1){
    if(N - K < i-1) cout << 0 << endl;
    else{
    z1 = ((a[N-K+1] * inv[i] % P) * inv[N-K-i+1] % P);
    z2 = ((a[K-1] * inv[i-1] % P) * inv[K-i] % P);
    cout << z1 * z2 % P << endl;
    }
   }  
  return 0;
}

Measured memory_bytes: 256
import sys

def insertionSort(A, N):
    for n in range(N-1):
        print (A[n], end=" ")
    print(A[N-1])
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j + 1] = A[j]
            j = j - 1
        A[j + 1] = v
        
        for n in range(N-1):
            print (A[n], end=" ")
        print(A[N-1])
    return A

N = int(input())
A = input()
A = A.split(" ")
for i in range(N):
    A[i] = int(A[i])
val = insertionSort(A, N)

Measured memory_bytes: 8084
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int left  = sc.nextInt()+sc.nextInt();
        int right = sc.nextInt()+sc.nextInt();
        if (left>right){
            System.out.println("Left");
        }else if(left==right){
            System.out.println("Balanced");
        }else {
            System.out.println("Right");
        }
    }
}


Measured memory_bytes: 35704
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <iomanip>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
struct city{ll num, pref, year; str id;};
bool comp_year(city a, city b){
  return a.year<b.year;
}
bool comp_num(city a, city b){
  return a.num<b.num;
}

int main(){
  ll n,m;
  cin >> n >> m;
  vector<city> prefs[n];
  REP(i,m){
    city temp;
    temp.num = i;
    cin >> temp.pref >> temp.year;
    temp.pref--;
    prefs[temp.pref].push_back(temp);
  }
  vector<city> all;
  REP(i,n){
    sort(prefs[i].begin(),prefs[i].end(),comp_year);
    ostringstream sout;
    sout << setfill('0') << setw(6) << i+1;
    str pref_str = sout.str();
    REP(j,prefs[i].size()){
      ostringstream sout2;
      sout2 << setfill('0') << setw(6) << j+1;
      str order_str = sout2.str();
      prefs[i][j].id = pref_str + order_str;
      all.push_back(prefs[i][j]);
    }
  }
  sort(all.begin(),all.end(),comp_num);
  REP(i,all.size()){
    cout << all[i].id << endl;
  }
  return 0;
}


Measured memory_bytes: 16748
/*
ID: learnin7
TASK: test
LANG: C++                 
*/
/* LANG can be C++11 or C++14 for those more recent releases */
#include<bits/stdc++.h>

/*  Macros from Endagorion */
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;


int main(){
        
    ios_base::sync_with_stdio(0);
    
    //ofstream fout ("test.out");
    //ifstream fin ("test.in");
    //fin >> a >> b;
    //fout << a+b << endl;
    int n;
    cin>>n;
    int a[n];
    bool vis[n] = {false};
    forn(i,n){
        int x;
        cin>>x;
        x--;
        a[i] = x;
    }
    int cnt=0;
    for(int i=0;i<n;i++){
        if(a[a[i]] == i)   cnt++;
    }
    cout<<cnt/2<<endl;
    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i,m,n) for(int i = m;i < n;i++)
#define pb(n) push_back(n)
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl;
#define Vecpr vector<pair<lli,lli>>
#define mod 1000000007;
int main() {
  lli A,B=1,C=0,D=0,F=0;
  cin >> A >> B;
  rep(i,0,A+1){
    rep(j,0,A+1){
      if(B-(i+j)<A+1&&B-(i+j)>-1)D++;
    }
  }
  Out(D);
}

Measured memory_bytes: 256
N = int(input())
S = [list(input()) for i in range(2)]
i = 0
ans = 1
mod = 10**9+7
if S[0][i]==S[1][i]:
    ans = 3
    i += 1
    flag = 0
else:
    ans = 6
    i += 2
    flag = 1
while i<N:
    if flag==0 and S[0][i]==S[1][i]:
        ans *= 2
        ans %= mod
        i += 1
        flag = 0
    elif flag == 1 and S[0][i]==S[1][i]:
        i += 1
        flag = 0
    elif flag == 0 and S[0][i]!=S[1][i]:
        ans *= 2
        ans %= mod
        i += 2
        flag = 1
    else:
        ans *= 3
        ans %= mod
        i += 2
        flag = 1
print(ans)


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

int main() {
  double A, B, C, D;
  cin >> A >> B >> C >> D;
  if (ceil(C / B) <= ceil(A / D)) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}




Measured memory_bytes: 3724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1e16;
int main()
{
   int n,m,r;
   ll mn=inf;
   cin>>n>>m>>r;
   ll dist[n+3][n+3];
   for(int i=1;i<=n;i++)
   {
   	for(int j=1;j<=n;j++)
   	dist[i][j]=inf;
   }
   int a[r+3];
   for(int i=0;i<r;i++)
   cin>>a[i];
   sort(a,a+r);
   for(int i=0;i<m;i++)
   {
   	int l,r,x;
   	cin>>l>>r>>x;
   	dist[l][r]=x;
   	dist[r][l]=x;
   }
   for(int i=1;i<=n;i++)
   dist[i][i]=0;
   for(int k=1;k<=n;k++)
   {
   	for(int i=1;i<=n;i++)
   	{
   		for(int j=1;j<=n;j++)
   		{
   			if(dist[i][j]>dist[i][k]+dist[k][j])
   			dist[i][j]=dist[i][k]+dist[k][j];
   		}
   	}
   	
    }
    while(next_permutation(a,a+r))
    {
    	ll su=0;
    	for(int i=1;i<r;i++)
    	su+=dist[a[i]][a[i-1]];
    	mn=min(mn,su);
    }
    cout<<mn;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

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

int n, x, m;
vector<int> l;
vector<int> r;
vector<int> s;

int max_sum = -(1 << 30);
vector<int> ans;

vector<int> v;

void rec(int depth) {
    if (depth == n) {
        for (int j = 0; j < m; ++j) {
            int t = 0;
            for (int k = l[j]; k <= r[j]; ++k) {
                t += v[k];
            }
            if (t != s[j]) {
                return;
            }
        }
        int t = 0;
        for (int j = 0; j < n; ++j) {
            t += v[j];
        }
        if(t > max_sum) {
            max_sum = t;
            ans = v;
        }
    } else {
        for (int j = 0; j <= x; ++j) {
            v.push_back(j);
            rec(depth+1);
            v.pop_back();
        }
    }
}

int main() {
    cin >> n >> x >> m;
    l.resize(m);
    r.resize(m);
    s.resize(m);

    for (int j = 0; j < m; ++j) {
        cin >> l[j] >> r[j] >> s[j];
        --l[j]; --r[j];
    }

    rec(0);

    if (ans.size() == 0) {
        cout << -1 << endl;
    } else {
        cout << ans[0];
        for (int j = 1; j < ans.size(); ++j) {
            cout << ' ' << ans[j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3168
#pypy3でAC

import sys
def input():
    return sys.stdin.readline()[:-1]

N, W = map(int, input().split())
w, v = [], []
for i in range(1, N+1):
    _w, _v = map(int, input().split())
    w.append(_w)
    v.append(_v)

V = sum(v)
#i個目までの品物から価値がj以上になるように選んだときの重さの最小値
dp = [[float("inf")]*(V+1) for _ in range(N+1)]
dp[0][0] = 0
"""
i番目を選ぶ場合
dp[i][j] = dp[i-1][j-v] + w
i番目を選ばない場合
dp[i][j] = dp[i-1][j]
"""

for i in range(1, N+1):
    for j in range(V+1):
        if j - v[i-1] >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i-1]] + w[i-1])
        else:
            dp[i][j] = dp[i-1][j]

# dp[N][j]がW以下であるような最大のjを探す
for j in range(V+1):
    if dp[N][j] <= W:
        ans = j
print(ans)

Measured memory_bytes: 308168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
bool used[100010];
bool flag = false;
vector<int> G[100010];

int dfs(int v, int p){
    for(auto u : G[v]){
        if(u != p) dfs(u, v);
    }
    if(!used[v]){
        used[v] = true;
        if(!used[p]) used[p] = true;
        else flag = true;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    used[0] = true;
    dfs(1, 0);
    cout << (flag ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 5888
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define MAX 510000
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;



int main(){
    ll n,a,b; cin >> n >> a >> b;
    if(n==1){
        if(a != b){
            puts("0");
            return 0;
        }else{
            puts("1");
            return 0;
        }
    }else{
        if(a > b){
            puts("0");
            return 0;
        }
        else if(a == b){
            puts("1");
            return 0;
        }
        n -= 2;
        ll right = a+b;
        ll left = a+b;
        rep(i,n){
            left += a;
            right += b;
        }
        cout << right - left + 1 << endl;
    }
}

Measured memory_bytes: 256
import "dart:io";

void main (){
	String w = stdin.readLineSync();
    int output = rainySeason(w);
    print(output);
	
}

int rainySeason(String weather) {
  if (weather.contains('R')) {
    if (weather.contains('RR')) {
      if (weather.contains('RRR')) {
        return 3;
      }
      return 2;
    }
    return 1;
  } else {
    return 0;
  }
}

Measured memory_bytes: 13184
N = int(input())
A = sorted(list(map(int, input().split())), reverse=True)

from collections import deque
q = deque([])

ans = 0
i = 0
for i in range(N):
    a = A[i]
    if i == 0:
        q.append(a)
    else:
        q.append(a)
        q.append(a)    
        s = q.popleft()
        ans += s

print(ans)    

Measured memory_bytes: 94236
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
P = 110000
MOD = 10 ** 9 + 7
S = [0] * P
dp = [[0] * P for i in range(110)]
num = [0] * P
i = 1
t = 0
while i <= N:
    j = N // i
    if i <= j:
        num[t] = 1
        t += 1
        i += 1
    else:
        num[t] = N // j - i + 1
        i = N // j + 1
        t += 1


dp[0][0] = 1
for k in range(K):
    S = [0] * P
    for j in range(t + 1):
        S[j + 1] = S[j] + dp[k][j]
        S[j + 1] %= MOD
    for j in range(t):
        dp[k + 1][j] = S[t - j] * num[j]
        dp[k + 1][j] %= MOD

ans = 0
for i in range(t + 1):
    ans += dp[K][i]
    ans %= MOD
print(ans)



Measured memory_bytes: 172956
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n, ara[100001];

    cin >> n;

    for(int i = 0; i < n; i++)cin >> ara[i];

    int dp[100001];

    dp[0] = 0, dp[1] = abs(ara[0] - ara[1]);

    for(int i = 2; i < n; i++)
        dp[i] = min(dp[i - 1] + abs(ara[i] - ara[i - 1]), dp[i - 2] + abs(ara[i] - ara[i - 2]));

    cout << dp[n - 1] << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int dx[]={-1,0,0,1},dy[]={0,-1,1,0};
int a[1001][1001];
pint p[1000002];
int b[1000002],c[1000002];
int main(){
    int h,w;
    cin>>h>>w;
    rep(i,h)rep(j,w){
        cin>>a[i][j];
        p[a[i][j]]={j,i};
    }
    int ans=0;
    rep(l,h*w){
        int j=p[l+1].first,i=p[l+1].second;
        int cnt=0;
        rep(k,4){
            int ty=i+dy[k],tx=j+dx[k];
            if(ty>=0&&tx>=0&&ty<h&&tx<w&&a[ty][tx]<a[i][j]){
                if(b[a[ty][tx]]==-1){
                    if(b[l+1]==0) c[l+1]=a[ty][tx],b[l+1]=1;
                    else if(b[l+1]==1&&c[l+1]!=a[ty][tx]){
                        ++ans,b[l+1]=2;cnt=4;break;
                    }
                }
                else if(b[a[ty][tx]]==1){
                    if(b[l+1]==0){
                        c[l+1]=c[a[ty][tx]];
                        b[l+1]=1;
                    }
                    else{
                        if(c[l+1]!=c[a[ty][tx]]){
                            b[l+1]=2;
                            ++ans;cnt=4;break;
                        }        
                    }
                }
                else if(b[a[ty][tx]]==2){
                    b[l+1]=2;
                    ++ans;cnt=4;break;
                }
            }
            if(ty>=0&&tx>=0&&ty<h&&tx<w&&a[ty][tx]<a[i][j]) ++cnt;
        }
        if(cnt==0) b[l+1]=-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 22628
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <tuple>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
using namespace std;

#define ll int64_t
const long MOD = 1e9 + 7;


int main()
{
    ll a,b,x;
    cin >> a>>b >>x;
 	
  	ll a1 = (a-1)/x;
  	
  	ll b1 = b/x;
  
  
  	if (a==0)a1=-1;
  
	cout << (b1-a1);

    return 0;
}


Measured memory_bytes: 256
def main():
    N, K = list(map(int, input().strip().split()))
    num_counts = {}
    for _ in range(N):
        a, b = list(map(int, input().strip().split()))
        if a in num_counts:
            num_counts[a] += b
        else:
            num_counts[a] = b

    num_counts = sorted(num_counts.items(),
                        key=lambda x: x[0])
    for n, c in num_counts:
        if K - c <= 0:
            print(n)
            break
        K -= c

if __name__ == '__main__':
    main()


Measured memory_bytes: 15080
n,*a=map(int,open(0).read().split())
ans=[]
if sum(t for t in a if t>0)>sum(-t for t in a if t<0):
    i=0
    while a[i]<0:i+=1
    for j in range(n):
        if a[j]>0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]<0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(1,n):
        ans+=[(i,i+1)]
else:
    i=0
    while a[i]>0:i+=1
    for j in range(n):
        if a[j]<0and i!=j:
            a[i]+=a[j]
            ans+=[(j+1,i+1)]
    for j in range(n):
        if a[j]>0:
            a[j]+=a[i]
            ans+=[(i+1,j+1)]
    for i in range(n,1,-1):
        ans+=[(i,i-1)]
print(len(ans))
for t in ans:print(*t)

Measured memory_bytes: 3064
import heapq
t = int(input())
for i in range(t):
    n = int(input())
    ans = 0
    cl,cr = 0,0
    lisl = []
    lisr = []
    rs = 0
    ls = 0
    for i in range(n):
        k,l,r = map(int,input().split())
        a = r-l
        s = (l>r)
        if a<0:
            lisl.append([k,l,r,-a,s])
            rs += r
        else:
            lisr.append([k,l,r,a,s])
            ls += l
    lisl.sort(key=lambda x: x[0])
    lisr.sort(key=lambda x: x[0],reverse=1)
    h = []
    cntl = 0
    cntr = 0
    for i in lisl:
        heapq.heappush(h,i[3])
        cntl += 1
        if cntl > i[0]:
            heapq.heappop(h)
            cntl -= 1
    hr = []
    for i in lisr:
        heapq.heappush(hr,i[3])
        cntr += 1
        if cntr > n-i[0]:
            heapq.heappop(hr)
            cntr -= 1
    print(rs+sum(h)+ls+sum(hr))

Measured memory_bytes: 132472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=1LL<<61;

typedef pair<ll,pll> ppll;

int main() {
  ll h,w,k;
  cin >> h >> w >> k;
  ll sx,sy,gx,gy;
  cin >> sy >> sx >> gy >> gx;
  sx--,sy--,gx--,gy--;
  vector<string> maze(h);
  for(ll i=0;i<h;i++) cin >> maze[i];
  mat d(h,vec(w,-1));
  vector<mat> al(h,mat(w,vec(4,0)));
  queue<pll> q;
  d[sy][sx]=0;
  q.push({sy,sx});
  while(q.size()) {
    ll y=q.front().first;
    ll x=q.front().second;
    ll dis=d[y][x];
    q.pop();
    for(ll i=1;x+i<w&&i<=k;i++) {
      ll nx=x+i;
      if(al[y][nx][0]||(d[y][nx]<dis+1&&d[y][nx]!=-1)||maze[y][nx]=='@') break;
      d[y][nx]=dis+1;
      al[y][nx][0]=1;
      q.push({y,nx});
    }
    for(ll i=1;x-i>=0&&i<=k;i++) {
      ll nx=x-i;
      if(al[y][nx][1]||(d[y][nx]<dis+1&&d[y][nx]!=-1)||maze[y][nx]=='@') break;
      d[y][nx]=dis+1;
      al[y][nx][1]=1;
      q.push({y,nx});
    }
    for(ll i=1;y+i<h&&i<=k;i++) {
      ll ny=y+i;
      if(al[ny][x][2]||(d[ny][x]<dis+1&&d[ny][x]!=-1)||maze[ny][x]=='@') break;
      d[ny][x]=dis+1;
      al[ny][x][2]=1;
      q.push({ny,x});
    }
    for(ll i=1;y-i>=0&&i<=k;i++) {
      ll ny=y-i;
      if(al[ny][x][3]||(d[ny][x]<dis+1&&d[ny][x]!=-1)||maze[ny][x]=='@') break;
      d[ny][x]=dis+1;
      al[ny][x][3]=1;
      q.push({ny,x});
    }
  }
  cout << d[gy][gx] << endl;
}

Measured memory_bytes: 152712
n = int(input())
moji = input()
res = 'Yes'
if n % 2 == 1:
    res = 'No'
else:
    for i in range(int(n/2)):
        if moji[i] != moji[int(n/2)+i]:
            res = 'No'
            break
      
print(res)


Measured memory_bytes: 2940
#include <iostream>
#include <fstream>

#include <string>

using namespace std;

struct Dice {
    int top,s,e;
    int face[6];
};

void my_rotate(struct Dice *d, char op){
    int top_prev = d->top;
    int s_prev = d->s;
    int e_prev = d->e;
    switch(op){
        case 'S':
            d->top = 7 - s_prev;
            d->s = top_prev;
            break;
        case 'E':
            d->top = 7 - e_prev;
            d->e = top_prev;
            break;
        case 'W':
            d->top = e_prev;
            d->e = 7 - top_prev;
            break;
        case 'N':
            d->top = s_prev;
            d->s = 7-top_prev;
            break;
    }
}

int main(){

    struct Dice d;
    struct Dice *pd = &d;
    string operation;
    for(int i=0;i<6;i++){
         cin >> pd->face[i];
    }
    cin >> operation;

    d.top = 1;
    d.s = 2;
    d.e = 3;

    for(int i=0;i<operation.size();i++){
        my_rotate(pd,operation[i]);
    }

    cout << d.face[d.top - 1] << endl;

    







    
    return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int N, M;
	cin >>N >>M;
	vector<vector<int>> A(N, vector<int> (M, 0));
	for (int i=0; i<N; i++)
		for (int j=0; j<M; j++)
			cin >>A.at(i).at(j);
	int S=N;
	vector<bool> DEL(M+1, false);
	vector<int> ix(N, 0);
	for (int i=0; i<M; i++) {
		vector<int> C(M+1, 0);
		for (int j=0; j<N; j++) {
			while(DEL.at(A.at(j).at(ix.at(j))))
				ix.at(j)++;
			C.at(A.at(j).at(ix.at(j)))++;
		}
		int SS=0;
		int MM=0;
		for (int k=1; k<=M; k++)
			if (C.at(k)>SS) {
				MM=k;
				SS=C.at(k);
			}
		S=min(S, SS);
		DEL.at(MM)=true;
	}
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;cin>>n;
    string s;
    bool color['Z']={0};
    int ans=0;
    for(int i=0;i<n;i++){
        cin>>s;
        color[s[0]]=true;;
    }
    for(int i='A';i<'Z';i++){
        if(color[i]) ans++;
    }
    if(ans==3) cout<<"Three"<<endl;
    else if(ans==4) cout<<"Four"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#define INT_MAX 100000

using namespace std;

int lmap[201][201],smap[201][201];
int dp[201][2];
vector<int> order;

int main(){
  int n,m,r,i,j,k;
  while(scanf("%d %d",&n,&m),n){
    order.clear();
    for(i=0;i<201;i++){
      for(j=0;j<201;j++)
	lmap[i][j]=smap[i][j]=INT_MAX;
      dp[i][0]=dp[i][1]=0;
    }

    for(i=0;i<m;i++){
      int x,y,t;
      char w;
      scanf("%d %d %d %c",&x,&y,&t,&w);
      if(w=='L')
	lmap[x][y]=lmap[y][x]=min(lmap[x][y],t);
      else
	smap[x][y]=smap[y][x]=min(smap[x][y],t);
    }
    
    scanf("%d",&r);
    for(i=0;i<r;i++){
      scanf("%d",&j);
      order.push_back(j);
    }

    for(i=1;i<=n;i++) lmap[i][i]=smap[i][i]=0;

    for(k=1;k<=n;k++)
      for(i=1;i<=n;i++)
	for(j=1;j<=n;j++){
	  lmap[i][j] = min(lmap[i][j],lmap[i][k]+lmap[k][j]);
	  smap[i][j] = min(smap[i][j],smap[i][k]+smap[k][j]);
	}
    
    for(i=r-2;i>=0;i--)
      for(j=1;j<=n;j++){
	int mint=INT_MAX;
	for(k=1;k<=n;k++){
	  int tmp;
	  if(k!=j)
	    tmp = dp[k][~i&1]+lmap[order[i+1]][k]+smap[k][j]+lmap[j][order[i]];
	  else
	    tmp = dp[k][~i&1]+lmap[order[i+1]][order[i]];
	  mint = min(mint,tmp);
	}
	dp[j][i&1] = mint;
      }

    printf("%d\n",dp[order[0]][0]);
  }
}

Measured memory_bytes: 1140
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int h, w;
  map<char, pii> m = {
    {'>', mp(0, 1)}, {'v', mp(1, 0)}, {'<', mp(0, -1)}, {'^', mp(-1, 0)}};
  while (cin >> h >> w, h) {
    vs s(h);
    rep(i, h) cin >> s[i];
    int i = 0, j = 0;
    for (;;) {
      if (s[i][j] == '*') {
        cout << "LOOP" << endl;
        goto next;
      }
      if (s[i][j] == '.') {
        cout << j << ' ' << i << endl;
        goto next;
      }
      pii p   = m[s[i][j]];
      s[i][j] = '*';
      i += p.fi;
      j += p.se;
    }
  next:;
  }
}

Measured memory_bytes: 3048
N = int(input())


def is_valid(last_4):
    cand = [last_4]
    for i in range(3):
        cand.append(last_4[:i] + last_4[i + 1] + last_4[i] + last_4[i + 2:])

    for m in cand:
        if "AGC" in m:
            return False
    return True


memo = [{} for i in range(N + 1)]
mod = 10**9 + 7


def dfs(index, last_3):
    if last_3 in memo[index].keys():
        return memo[index][last_3]
    elif index == N:
        return 1
    else:
        s = 0
        for c in "AGCT":
            if is_valid(last_3 + c):
                s = (s + dfs(index + 1, last_3[1:] + c)) % mod
        memo[index][last_3] = s
        return s


print(dfs(0, "HHH"))


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    int keta = 1;
    int n = N;
    while (n > 0){
        n /= 10;
        if (n > 0){
            keta++;
        } else {
            break;
        }
    }
    int ans;
    if (keta == 6) {
        ans = (99999 - 9999) + (999 - 99) + 9;
    } else if (keta == 5){
        ans = (N - 9999) + (999 - 99) + 9;
    } else if (keta == 4){
        ans = (999 - 99) + 9;
    } else if (keta == 3){
        ans = (N - 99) + 9;
    } else if (keta == 2){
        ans = 9;
    } else if (keta == 1){
        ans = N;
    }
    cout << ans << endl;
}

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

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

    return true;
}

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

    ll q;
    cin >> q;

    vector<ll> numlikeprime(100001, 0);
    rep(i, 100002){
        if(i<2) continue;
        numlikeprime[i] = numlikeprime[i-1];
        if(is_prime(i) && is_prime((i+1)/2)) ++numlikeprime[i];
    }

    rep(i, q){
        int l, r;
        cin >> l >> r;

        cout << numlikeprime[r] - numlikeprime[l-1] << "\n";
    }

    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  vi b(n);
  rep(i,n) cin >> b[i];
  vi c(n);
  rep(i,n) cin >> c[i];
  sort(a.begin(), a.end());
  sort(c.begin(), c.end());
  //newline;
  //showv(a);
  //showv(b);
  //showv(c);
  ll ans = 0;
  rep(i,n) {
    ll x = lower_bound(rng(a), b[i]) - a.begin();
    ll z = c.end() - upper_bound(rng(c), b[i]);
    //show2(x,z);
    ans += x*z;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1408
from math import floor
a,b,n = map(int,input().split())
ans = 0
if n <= b:
    for i in range(max(0,n-9),n+1):
        ans = max(ans,floor(a*i/b) - a*floor(i/b))
else:
    for i in range(max(0,b-10),min(n,b+10)):
        ans = max(ans,floor(a*i/b) - a*floor(i/b))
print(ans)

Measured memory_bytes: 62096
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <assert.h>
#include <string>
#include <set>
#include <map>
using namespace std;
#define LL long long

int n,q;
int S[200005], T[200005] , X[200005];
vector < int > id;
vector < int > comp;
int st[1000005 * 4], lazy[1000005*4];
set < int > Set;
int Time[200005];

bool cmp( int a, int b ){
	return S[a] - X[a] < S[b] - X[b];
}

void build( int p, int s, int e ){
	st[p] = 1e9 + 7;
	lazy[p] = 0;
	if ( s == e ){
		return;
	}

	int m = ( s + e ) >> 1;
	build(p*2+1,s,m);
	build(p*2+2,m+1,e);
}

void pd( int p, int s, int e ){
	if ( s < e && lazy[p] > 0 ){
		int v = lazy[p];
		lazy[p] = 0;

		if ( lazy[p*2+1] == 0 ) lazy[p*2+1] = v;
		else lazy[p*2+1] = min( lazy[p*2+1] , v );

		if ( lazy[p*2+2] == 0 ) lazy[p*2+2] = v;
		else lazy[p*2+2] = min( lazy[p*2+2] , v );

		st[p*2+1] = min( st[p*2+1] , v );
		st[p*2+2] = min( st[p*2+2] , v );
	}
}

void upd( int p, int s, int e, int l, int r, int x ){
	if ( s < e && lazy[p] > 0 ) pd(p,s,e);
	if ( s == l && e == r ){
		st[p] = min(st[p],x);
		if ( lazy[p] == 0 ) lazy[p] = x;
		else lazy[p] = min( lazy[p] , x );
		return;
	}

	int m = ( s + e ) / 2;
	if ( l <= m ) upd(p*2+1,s,m,l,min(m,r),x);
	if ( m < r ) upd(p*2+2,m+1,e,max(m+1,l),r,x);
}

int query( int p, int s, int e, int x ){
	if ( s < e && lazy[p] > 0 ) pd(p,s,e);
	if ( s == e ){
		return st[p];
	}
	int m = ( s + e ) / 2;
	if ( x <= m ) return query(p*2+1,s,m,x);
	else return query(p*2+2,m+1,e,x);
}

int main(){
	scanf("%d%d",&n,&q);
	for ( int i = 0; i < n; i++ ){
		scanf("%d%d%d",&S[i],&T[i],&X[i]);
		T[i]--;
		id.push_back(i);
		Set.insert(S[i]-X[i]);
		Set.insert(T[i]-X[i]);
	}

	for ( int i = 0; i < q; i++ ){
		scanf("%d",&Time[i]);
		Set.insert(Time[i]);
	}

	for ( auto it : Set ){
		comp.push_back(it);
	}

	sort(id.begin(),id.end(),cmp);
	build(0,0,comp.size()-1);
	for ( int i = n-1; i >= 0; i-- ){
		int idx = id[i];
		int L = lower_bound(comp.begin(),comp.end(),S[idx]-X[idx]) - comp.begin();
		int R = lower_bound(comp.begin(),comp.end(),T[idx]-X[idx]) - comp.begin();
		upd(0,0,comp.size()-1, L,R, X[idx]);
	}

	for ( int i = 0; i < q; i++ ){
		int pos = lower_bound(comp.begin(),comp.end(),Time[i]) - comp.begin();
		int ans = query(0,0,comp.size()-1, pos);
		if ( ans > 1e9 ) printf("-1\n");
		else printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 57708
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define SORT(v) sort(v.begin(),v.end())
#define fori(i,a,b) for(ll i=a;i<b;i++)
#define M 1000000007
#define deb(x) cout<< #x << " " << x << endl;

double pi=3.14159265358979323846;

typedef pair<int,int> pii;
typedef pair<long long int, long long int>pll;
typedef vector<int>vi;
typedef vector<long long int>vl;
#define MAXN 10000001

int main ()
{
    ll T;
    T=1;
    //cin>>T;
    while(T--)
    {
   
   int x,n;
   cin>>x>>n;
    	set<int> st;
    	if(n==0)cout<<x<<endl;
    	else{
    	fori(i,0,n){int x;cin>>x;st.insert(x);}
            int d=INT_MAX,ans=0;
            for(int i=0;i<102;i++){
            	if(st.count(i)==0){
            		if(abs(x-i)<d){ans=i;d=abs(x-i);}
            	}
            }
    cout<<ans<<endl;
    	}
    
    	
    	
    }
    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

//template
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define repr(i,n) for(ll i=n;i>0;i--)
#define all(v) v.begin(),v.end()
#define in cin>>
#define out cout<<
#define en <<endl
const ll INF = 10000000000000;

int main()
{
	ll a,b;
	in a >> b;
	if (a > b)
	{
		rep(i, a)
			out b ;
	}
	else
	{
		rep(i, b)
			out a ;
	}
	out endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll n;
ll two_pow[61];

bool C(ll v){
	ll cnt=0;
	for(int i=1;i<=60;i++){
		cnt+=n/two_pow[i];
		cnt-=(n-v)/two_pow[i];
		if(cnt<=-(1LL<<60))return false;
		cnt-=v/two_pow[i];
		if(cnt>=(1LL<<60))return true;
		if(cnt<=-(1LL<<60))return false;
	}
	return cnt>0LL;
}

int main(void){
	two_pow[0]=1;
	for(int i=0;i<60;i++){
		two_pow[i+1]=two_pow[i]*2LL;
	}
	scanf("%lld",&n);
	if(n%2LL==0){
		printf("%lld\n",1LL);
		return 0;
	}
	ll l=1;
	while(l<n){
		if(C(l))break;
		else l*=2LL;
	}
	if(l>=n){
		printf("%lld\n",n+1LL);
	}else{
		printf("%lld\n",l);
	}
	return 0;
}

Measured memory_bytes: 3196
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;


long long N;
long long T[100005];
long long A[100005];

long long Tans[100005];
bool Tfix[100005];

long long Aans[100005];
bool Afix[100005];

bool ng;

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

	Tans[0] = T[0];
	Tfix[0] = true;

	Aans[N-1] = A[N-1];
	Afix[N-1] = true;

	for(int i = 1; i < N; i++){ 
		if(T[i-1] < T[i]){
			Tfix[i] = true;
			Tans[i] = T[i];
		}else{
			Tans[i] = T[i];
		}
	}

	for(int i = N - 2; i >= 0; i--){ 
		if(A[i] > A[i+1]){
			Afix[i] = true;
			Aans[i] = A[i];
		}else{
			Aans[i] = A[i];
		}
	}

	/*
	for(int i = 0; i < N; i++){
		if(Tfix[i]){
			cout << i << "(fix) :"  << Tans[i] << endl;
		}else{
			cout << i << "(max) :"  << Tans[i] << endl;
		}
	}

	for(int i = 0; i < N; i++){
		if(Afix[i]){
			cout << i << "(fix) :"  << Aans[i] << endl;
		}else{
			cout << i << "(max) :"  << Aans[i] << endl;
		}
	}
	*/

	long long ans = 1;
	for(int i = 0; i < N; i++){
		if(Tfix[i] && Afix[i]){
			if(Tans[i] != Aans[i]){
				ans = 0;
			}
		}else if(!Tfix[i] && Afix[i]){
			if(Tans[i] < Aans[i]){
				ans = 0;
			}
		}else if(Tfix[i] && !Afix[i]){
			if(Tans[i] > Aans[i]){
				ans = 0;
			}
		}else{
			long long mini = min(Tans[i], Aans[i]);
			ans *= mini;
			ans %= DIV;
		}
	}
	cout << ans << endl;
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
using ll = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;

int main() {
  ll n,d; cin>>n>>d;
  int ans = 0;
  rep(i, n) {
    ll x,y; cin>>x>>y;
    if (x * x + y * y <= d * d) ans++;
  }
  cout << ans;
}


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

int main() {
    std::string input;
    std::cin >> input;

    bool yes = true;
    for (int i = 0; i < input.size(); i++) {
        const char c = input[i];
        switch (c)
        {
            case 'R':
                if ((i+1) % 2 == 0) {
                    yes = false;
                    goto END;
                }
                break;
            case 'L':
                if ((i+1) % 2 == 1) {
                    yes = false;
                    goto END;
                }
                break;
        }
    }

END:
    std::cout << (yes ? "Yes" : "No") << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int N;
    cin >> N;
    VS S(N);
    rep(i,N){
        cin >> S[i];
    }
    map<string, int> count;
    rep(i,N){
        count[S[i]]++;
    }
    vector<pair<int, string>> A;
    stl_rep(itr, count){
        A.PB(pair<int, string>(itr->S, itr->F));
    }
    sort(all(A));
    reverse(all(A));
    VS ans;
    rep(i,A.size()){
        ans.PB(A[i].S);
        if(i!=A.size()-1){
            if(A[i].F>A[i+1].F){
                break;
            }
        }
    }
    sort(all(ans));
    rep(i,ans.size()){
        cout << ans[i] << endl;
    }
}

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

const int INF = 1e9;

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> adj[n + 1];
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	
	vector<int> dist(n + 1, INF);
	vector<int> ant(n + 1, 0);
	
	set<pair<int, int>> est;
	est.insert({0, 1});
	dist[1] = 0;
	while (!est.empty()) {
		int v = est.begin()->second;
		est.erase(est.begin());
		for (int u : adj[v]) {
			if (dist[v] + 1 < dist[u]) {
				ant[u] = v;
				dist[u] = dist[v] + 1;
				est.insert({dist[u], u});
			}
		}
	}
	
	for (int i = 2; i <= n; i++) {
		if (!ant[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	
	cout << "Yes" << endl;
	for (int i = 2; i <= n; i++) {
		cout << ant[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 14780
import java.util.Scanner;

public class Main{
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1 = s.substring(0, 2);
		String s2 = s.substring(2, 4);
		int ss1 = Integer.parseInt(s1);
		int ss2 = Integer.parseInt(s2);
		
		if(1 <= ss1 && ss1 <= 12 && 1 <= ss2 && ss2 <= 12) {
			System.out.println("AMBIGUOUS");
		}else if(1 <= ss1 && ss1 <= 12) {
			System.out.println("MMYY");
		}else if(1 <= ss2 && ss2 <= 12) {
			System.out.println("YYMM");
		}else {
			System.out.println("NA");
		}
	}
}

Measured memory_bytes: 21716
#include <iostream>

using namespace std;

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

	int a[100];

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

	for (int i = n-1 ; i >= 0 ; i--)
	{
		if (i != n -1)
		{
			cout << " ";
		}
		cout << a[i];
	}
	cout << endl;

	return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin>>s;
    if(s[0]=='R'&&s[1]=='R'&&s[2]=='R')
    {
        cout<<"3";
        //return 0;
    }
    else if(s[0]=='R'&&s[1]=='R'||s[1]=='R'&&s[2]=='R')
    {
        cout<<"2";
        //return 0;
    }
    else if(s[0]=='R'||s[1]=='R'||s[2]=='R')
    {
        cout<<"1";
    }
    else
        cout<<"0";
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5+5;

int N;
lli A,B;
lli h[MAX];

bool er(lli k){
	lli p[MAX];
	lli ex=0;
	rep(i,N){
		p[i]=max((lli)0,h[i]-B*k);
		if(p[i]!=0)p[i]=(p[i]-1)/(A-B)+1;
		ex+=p[i];
	}
	if(ex<=k)return true;
	else return false;
}

int main(){
	cin>>N>>A>>B;
	rep(i,N)cin>>h[i];

	int lb=-1, ub=1e9;
	while(ub-lb>1){
		int mid=(ub+lb)/2;
		if(er(mid))ub=mid;
		else lb=mid;
	}
	cout<<ub;
}

Measured memory_bytes: 1024
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Queue;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();   //4
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;  //2-1=0
			int degree = in.nextInt();//1
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1; //4-1=3
				tmp.add(idx2);// adds 3
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		System.out.println(adjList);
		adjMatrix[0][0] = (adjList.get(0).get(0));
		
		//Assign the matrix 0's
		for (int i=0; i<totalVertex;i++) {
			for (int j =0; j < totalVertex; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		// uses index to change 0 to 1
		for (int i=0; i <totalVertex;i++) {
			for (int j=0; j< adjList.get(i).size(); j++) {
				adjMatrix[i][adjList.get(i).get(j)] = 1;
			}
		}
		System.out.println(Arrays.deepToString(adjMatrix));
		
		for(int i =0; i < totalVertex;i++) {
			for (int j =0; j < totalVertex; j++) {
				System.out.print(adjMatrix[i][j]);
				if(j == totalVertex-1) {
					
				}
				else {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
		//complete the following
	}
	int visited[];
	int distance[];
	public void bfs() {
		
		visited = new int[totalVertex];
		distance = new int[totalVertex];
		Queue<Integer> q = new LinkedList<>();
		q.add(0); // start at node 1
		//set distance to -1
		for(int i=0; i<distance.length;i++) {
			distance[i] = -1;
		}
		distance[0] = 0;
		
		while (!q.isEmpty()) {
			//if visited
			int v = q.remove();
			
			// if not visited
				// adding links to q and updating distance
				for(int i=0; i<adjList.get(v).size();i++) {
					int u = adjList.get(v).get(i);
					if(distance[u]!=-1) continue;
					distance[u] = distance[v] + 1;
					q.add(u);
				}
			
	    }
		for (int i=0; i<totalVertex; i++) {
			System.out.println(i+1 + " " + distance[i]);		
		}
    }
	public int checkVisited(int node) {
		for(int i=0; i<visited.length;i++) {
			if (visited[i]==node) {
				return 1;
			}
		}
		return 0;
	}
}
//change class name GraphRepresentation to Main() for submission to AIZU
public class Main{
	
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		//g.printAdjMatrix();
		g.bfs();
	}
}


Measured memory_bytes: 28212
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,a1,b;
  int c=1;
  cin>>a>>b;
  if(b==1){
    cout<<0;
    return 0;
  }
  a1=a;
  while(a<b){
    c++;
    a+=(a1-1);
  }
  cout<<c;
  return 0;
}

Measured memory_bytes: 256