akhauriyash/Code-Regression huggingface dataset:
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end
  puts gets.chop.chars.map{"x"}.join
  
  

Measured memory_bytes: 1788
/*
      author : Nishikawa
      created: 04.08.2020 19:35:20
*/

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


int main(){
    int K;
    cin >> K;
    if(K%2==0 || K%5==0){
        cout << -1 << endl; 
        return 0;
    }

    int L;
    if(K%7==0) L=9*K/7;
    else L=9*K;

    int pord=10%L;
    int count=1;
    while(1){
        if(pord==1){
            break;
        }
        else{
            pord=(pord*10)%L;
        }
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>

int N,F[44];

int main(){

  int i,j,n;

  scanf("%d",&n);
  printf("%d\n",fibonacci(n));

  return 0;
}



int fibonacci(int n){

  if(n==0 || n==1)
    return F[n]=1;
  if(F[n]!=0)
    return F[n];
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

Measured memory_bytes: 596
from collections import Counter # 重複個数のカウント: Counter(num_list)

def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    ans = 0

    count_dict = Counter(num_list)

    for k, v in count_dict.items():
        if k == v:
            continue
        if k < v:
            ans += v - k
        else:
            ans += v
            
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 68136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int d,n;
  cin>>d>>n;
  int ans=0;
  if(d==0){
    if(n==100) ans=101;
    else ans=n;
  }else if(d==1){
    if(n==100) ans=10100;
    else ans=100*n;
  }else{
    if(n==100) ans=1010000; 
    else ans=10000*n;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
	int n,x,a;
	while(1){
		cin >> n >> x;
		if( n == 0 && x == 0)break;
		a = 0;
		int i,j,k;
		for( i = 1; i <= n; i++){
			for( j = i+1; j <= n; j++){
				for( k = j+1; k <= n ; k++){
					if( i + j + k == x){
						a++;
					}
				}
			}
		}
		cout << a << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import std.array;
import std.conv;
import std.math;
import std.algorithm;
import std.string;
import std.stdio;

void main() {
	int n, stride;
	readf("%s %s\n", &n, &stride);
	auto steps = readln.chomp.split(' ').map!(to!int).array;

	auto dp = new int[n];
	dp[1..$] = int.max;

	foreach (i;0..n - 1) {
		foreach (j;i + 1..i + 1 + stride) {
			if (j >= n) {
				break;
			}

			dp[j] = min(dp[j], dp[i] + abs(steps[i] - steps[j]));
		}
	}

	writeln(dp[n - 1]);
}


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

using namespace std;

int main() {
    int n; cin>>n;
    
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t.at(i);
    }
    
    int m; cin>>m;
    //m回 tの操作をする
    
    vector<int> a(m);
    
    for (int i = 0; i < m; i++) {
        //tの添字pをxに変更して、tの要素の和
        int p, x, s = 0;
        cin >> p >> x;
        p = p - 1;
        vector<int> result = t;
        result.at(p) = x;
        for (int j = 0; j < result.size(); j++) {
            s += result.at(j);
        }
        a.at(i) = s;
        
    }
    
    for (int i = 0; i < m; i++) {
        cout << a.at(i) << endl;
    }
}

Measured memory_bytes: 3180
#!/usr/bin/env ruby

require 'bigdecimal'
require 'bigdecimal/math'
include BigMath

a, b, h ,m = gets.chomp.split(' ').map(&:to_s)

rad_a = -(BigDecimal(h) + BigDecimal(m) / 60) / 12 * ( 2 * Math::PI)
rad_b = -(BigDecimal(m) / 60) * ( 2 * Math::PI)

prec = 10
a_x = cos(rad_a, prec) * 0 - sin(rad_a, prec) * a.to_i
a_y = sin(rad_a, prec) * 0 + cos(rad_a, prec) * a.to_i

b_x = cos(rad_b, prec) * 0 - sin(rad_b, prec) * b.to_i
b_y = sin(rad_b, prec) * 0 + cos(rad_b, prec) * b.to_i

# puts a_x
# puts a_y
# puts b_x
# puts b_y
puts sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2, prec)



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

const int MAX_RC = 7;
int R, C, K;
char grid[MAX_RC][MAX_RC];
char gg[MAX_RC][MAX_RC];

int count() {
  int ans = 0;
  for (int r = 0; r < R; ++r)
    for (int c = 0; c < C; ++c)
      ans += (gg[r][c] == '#');
  return ans;
}

int main() {
  scanf("%d %d %d ", &R, &C, &K);
  for (int r = 0; r < R; ++r) {
    for (int c = 0; c < C; ++c) {
      grid[r][c] = getchar();
    }
    scanf(" ");
  }
  int cc = 0;
  int mm = (1 << (R + C)) - 1;
  for (int i = 0; i <= mm; ++i) {
    memcpy(gg, grid, sizeof(gg));
    for (int r = 0; r < R; ++r) {
      if (!(i & (1 << r))) continue;
      for (int c = 0; c < C; ++c)
        gg[r][c] = 'r';
    }
    for (int r = 0; r < C; ++r) {
      if (!(i & (1 << (r+R)))) continue;
      for (int c = 0; c < R; ++c)
        gg[c][r] = 'r';
    }
    if (count() == K) cc++;
  }
  printf("%d\n", cc);
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;typedef long long ll;typedef string str;
typedef vector<str> vst;
typedef vector<ll> vll;
// for (ll i=0;i<n;i++) {
// sort(.begin(),.end());
int main(){
  str s,t,ans="UNRESTORABLE";
  cin>>s>>t;
  ll ns=s.size(),nt=t.size();
  
  if (ns>=nt) {
    str h;
    for (ll i=ns-1;i>=nt-1;i--) {
      h=s;
      for (ll j=0;j<nt;j++) {
        if (h[i-j]!=t[nt-1-j] && h[i-j]!='?') {
          break;
        }
        else {
          h[i-j]=t[nt-1-j];
        }
        if (j==nt-1) {
          goto loopend1;
        }
      }
      if (i==nt-1) {
        goto loopend2;
      }
    }
    loopend1:
    for (ll i=0;i<ns;i++) {
      if (h[i]=='?') h[i]='a';
    }
    ans=h;
  }
  loopend2:
  cout<<ans<<endl;
}

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

using namespace std;

int main() {

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

    int score = 0;
    score = max(a, b);
    score += max(max(a, b) - 1, min(a, b));

    cout << score << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner inputs = new Scanner(System.in);
		int n = inputs.nextInt();
		Long[] nums = new Long[n];
		//stores value, how many
		HashMap<Long,Long> map = new HashMap<Long,Long>();
		for(int i=0;i<n;i++) {
			nums[i]=inputs.nextLong();
			if(!map.containsKey(nums[i])) {
				map.put(nums[i], 0L);
			}
			map.put(nums[i], map.get(nums[i])+1);
		}
		long tot = 0;
		Set<Long> temp = map.keySet();
		for(Long i:temp) {
			long curr = map.get(i);
			if(curr>=2) {
				tot+=comb(curr);
			}
		}
		for(int k=0;k<n;k++) {
			long sum =tot;
			long bad = nums[k];
			long am = map.get(bad);
			if(am>=2) {
				sum+= (-1*am+1);
			}
			System.out.println(sum);
		}
		
	}
	static long comb(long n)
	{
		return n*(n-1)/2;
	}
}


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

using namespace std;
typedef long long LL;
const int N = 200010;
const LL INF = 1e18 + 10;

LL n, k;
LL A[N];
LL A0[N], A1[N], top0, top1, cnt;

bool Check(LL x) {
    LL sum = 0, sum2 = 0; // res > x
    if(x < 0) {
        sum2 = 0;
        int pos = top1;
        for(int i = 1;i <= top0; ++i) {
            while(A0[i] * A1[pos] >= -x && pos) pos--;
            sum2 += pos;
        }
        sum += sum2;
        sum += top0 * (top0 - 1) / 2;
        sum += top1 * (top1 - 1) / 2;
        sum += cnt * (n - cnt);
        sum += cnt * (cnt - 1) / 2;

    } else if(x > 0) {
        sum2 = 0;
        int pos = top1;
        for(int i = 1;i <= top1; ++i) {
            while(A1[i] * A1[pos] > x && pos) pos--;
            sum2 += pos; if(pos >= i) sum2--;
        }
        sum2 /= 2;
        sum += (top1 * (top1 - 1) / 2 - sum2);
        sum2 = 0; pos = top0;
        for(int i = 1;i <= top0; ++i) {
            while(A0[i] * A0[pos] > x && pos) pos--;
            sum2 += pos; if(pos >= i) sum2--;
        }
        sum2 /= 2;
        sum += (top0 * (top0 - 1) / 2 - sum2);
    } else {
        sum += (top1 * (top1 - 1) + top0 * (top0 - 1)) / 2;
    }
    // cout << "Check at " << x << " " << sum << " " << sum2 << endl;
    return sum < k;
}

int main() {
    scanf("%lld%lld", &n, &k); k = n * (n - 1) / 2 - k + 1;
    for(int i = 1;i <= n; ++i)  
        scanf("%lld", &A[i]);

    for(int i = 1;i <= n; ++i) {
        if(A[i] < 0) A0[++top0] = -A[i];
        else if(A[i] > 0) A1[++top1] = A[i];
        else cnt++;
    }

    sort(A0 + 1, A0 + 1 + top0); sort(A1 + 1, A1 + 1 + top1);

    LL L = -INF, R = INF;

    while(R - L > 1) {
        LL mid = (L + R) >> 1;
        if(Check(mid)) R = mid;
        else L = mid;
    }
    printf("%lld\n", R);
    return 0;
}

Measured memory_bytes: 4096
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


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

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)


















int main(){
    ll s, w;
    cin >> s >> w;
    if(s > w){
        cout << "safe" << endl;
    }
    else{
        cout << "unsafe" << endl;
    }
}

Measured memory_bytes: 3636
h, w = map(int, input().split())
hb = h // 2
wb = w // 2
if h == 1 or w == 1:
    print(1)
elif h % 2 == 0:
    print(hb * w)
elif w % 2 == 0:
    print(wb * h)
else:
    print((wb + 1) * (hb + 1) + wb * hb)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    swap(a, b);
    swap(a, c);

    cout << a << ' ' << b << ' ' << c << endl;

    return 0;
}

Measured memory_bytes: 256
D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]
lastday=[0 for j in range(26)]
points=[0 for i in range(D)]
t=[0 for i in range(D)]
total=[0 for i in range(D)]
# first day
lastday=[lastday[i]+1 for i in range(26)]
bestpoint=0
for i in range(26):
    temp=lastday
    temp[i]=0
    minus=sum([x*y for (x,y) in zip(c,temp)])
    temppoint=s[0][i]-minus
    if bestpoint<temppoint:
        today=i
        bestpoint=temppoint
        minusb=minus
lastday[today]=0
t[0]=today+1
total[0]=s[0][today]-minusb



for days in range(1,D):
    lastday=[lastday[i]+1 for i in range(26)]
    bestpoint=0
    for i in range(26):
        temp=lastday
        temp[i]=0
        minus=sum([x*y for (x,y) in zip(c,temp)])
        temppoint=total[days-1]+s[days][i]-minus
        if bestpoint<temppoint:
            today=i
            bestpoint=temppoint
            minusb=minus
    lastday[today]=0
    t[days]=today+1
    total[days]=total[days-1]+s[days][today]-minusb
    
for ts in t:
    print(ts)

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

int main()
{
    setprecision(10);
    int n;
    cin>>n;
    
    if(n%2==0)
    {
        float t = (n-2)/2;
        printf("%0.10f",(t+1)/(double)n);
        //cout<<(t+1)/(float)n<<endl;
    }
    else 
    {
        float p = (n-1)/2;
        printf("%0.10f",(p+1)/(double)n);
        //cout<<(p+1)/(double)n<<endl;
    }
    return 0;
}


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

using namespace std;

#define reset(x) memset(x, 0, sizeof(x));
#define recopy(a, b) memcpy(b, a, sizeof(a));
typedef unsigned long long ULL;
typedef long long LL;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 10;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> v;
    v.push_back(0);
    int a;
    for (int i = 0; i < n; i++) {
        cin >> a;
        v.push_back(a);
    }
    LL ans = 0;
    for (int i = 1; i <= n; i++) {
        if (v[i] < v[i - 1]) {
            ans += v[i - 1] - v[i];
            v[i] += v[i - 1] - v[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4256
#include <iostream>
#include <vector>
using namespace std;
int n,m,u,v,s;
vector<int> a[9];
bool z[9];

void f(int p, int q) {
	if(q==n) {s++; return;}
	for(int i=0; i<a[p].size(); i++) {
		if(!z[a[p][i]]) {
			z[a[p][i]] = 1;
			f(a[p][i], q+1);
			z[a[p][i]] = 0;
		}
	}
}

int main() {
	cin>>n>>m;
	while(m--) {
		cin>>u>>v;
		a[u].push_back(v);
		a[v].push_back(u);
	}
	z[1] = 1;
	f(1,1);
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

struct UnionFind {
    // par[i]:iの親の番号　(例) par[3] = 99 : 3の親が99
    vector<int> par;

    UnionFind(int N) : par(N) {  // 初期化
        for (int i = 0; i < N; i++)
            par[i] = i;
    }

    void print(){
       for (int i = 0; i < par.size(); i++)
            printf("par[%d] = %d\n",i, par[i]);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[rx] = ry;
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(){
        int N = par.size();
        set<int> s;
        for (int i = 0; i < N; i++) {
            s.insert(root(i));
        }
        return s.size();
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    
    vec<int> A(M), B(M);
    vec<int> is(N,0);
    rep(i, M) {
        cin >> A[i] >> B[i];
        --A[i],--B[i];
        is[A[i]] = 1;
        is[B[i]] = 1;
        uf.unite(A[i],B[i]);
    }
    int zero = 0;
    rep(i,N) if(is[i] == 1) ++zero;

    map<int,ll> mp;
    rep(i,N) {
        ++mp[uf.root(i)];
    }

    ll ans = 0;
    for(auto [f,s]:mp){
        ans = max(ans,s);
    }
    if(ans == 0 &&zero !=0){
        cout << 1 << endl;
        return 0;
    }
    cout << ans << endl;
}


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

if sum(a) < x:
    print(n - 1)
elif sum(a) == x:
    print(n)
else:
    a.sort()
    for i, num in enumerate(a):
        if x >= num: x -= num
        else:
            print(i)
            break


Measured memory_bytes: 3316
sa = list(reversed(input()))
sb = list(reversed(input()))
sc = list(reversed(input()))

turn = sa.pop()

while True:
    if (turn == "a" and not sa) or (turn == "b" and not sb) or (turn == "c" and not sc):
        break
    elif turn == "a":
        turn = sa.pop()
    elif turn == "b":
        turn = sb.pop()
    else:
        turn = sc.pop()

print(turn.upper())

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int tc = 1;
    // cin >> tc;
    while(tc--) {
        int x, n;
        cin >> x >> n;
        vector<int> freq(102, 0);
        while(n--) {
            int num;
            cin >> num;
            freq[num]++;
        }
        
        int res = -1, diff = INT_MAX;
        for(int i=0; i<102; i++) {
            if(freq[i] == 0 && abs(i - x) < diff) {
                diff = abs(i - x);
                res = i;
            }
        }
        cout << res << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3584
/***************************************************
 * Problem Name : B.cpp
 * Problem Link :
 * OJ           :
 * Verdict      : Trying
 * Date         : 2020-03-17
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm ( ll a, ll b ) {
    return ( a / __gcd ( a, b ) ) * b;
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10) << fixed;
    ll n, a, b;
    cin >> n >> a >> b;
    ll to = n / (a + b);
    ll md = n % (a + b);
    cout << ((to*a) + min(a, md)) << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

// FIXME:　クラス名をMainに修正してからコミットすること。
class Main {

    // エントリポイント
    public static void main(String args[]) {
        doLogic();
    }

    // 定数
    private static final int TOP = 0;
    private static final int NORTH = 1;
    private static final int EAST = 2;
    private static final int SOUTH = 3;
    private static final int WEST = 4;

    // フィールド
    private static int sum = 1;
    private static int[] dice = new int[5]; // TOP, NORTH, EAST, SOUTH, WEST を保持

    /**
     * サイコロに対するコマンドを実行する。
     *
     * @param command コマンド
     */
    private static void doCommand(String command) {
        int tmp = 0;
        if ("Right".equals(command)) {
            tmp = dice[4];
            for (int j = 3; j >= 1; j--) {
                dice[j + 1] = dice[j];
            }
            dice[1] = tmp;

        } else if ("Left".equals(command)) {
            tmp = dice[1];
            for (int j = 1; j <= 3; j++) {
                dice[j] = dice[j + 1];
            }
            dice[4] = tmp;

        } else if ("North".equals(command)) {
            dice[NORTH] = dice[TOP];
            dice[TOP] = dice[SOUTH];
            dice[SOUTH] = 7 - dice[NORTH];

        } else if ("South".equals(command)) {
            dice[SOUTH] = dice[TOP];
            dice[TOP] = dice[NORTH];
            dice[NORTH] = 7 - dice[SOUTH];

        } else if ("East".equals(command)) {
            dice[EAST] = dice[TOP];
            dice[TOP] = dice[WEST];
            dice[WEST] = 7 - dice[EAST];

        } else if ("West".equals(command)) {
            dice[WEST] = dice[TOP];
            dice[TOP] = dice[EAST];
            dice[EAST] = 7 - dice[WEST];
        }
    }

    /**
     * 標準入力を1行読む（例外処理を切り出し）
     *
     * @param reader 入力ストリーム
     * @return 1行分のデータ
     */
    private static String readLine(BufferedReader reader) {
        String line = null;
        try {
            line = reader.readLine();
        } catch (IOException e) {
            throw new RuntimeException();
        }
        return line;
    }

    /**
     * メインロジック
     *
     */
    private static void doLogic() {

        // 標準入力のストリームを作成する
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        String input = null;
        while (true) {
            input = readLine(reader);
            int loop = Integer.parseInt(input);

            // 終了判定を行う
            if (loop == 0) {
                break;
            }

            // 初期化する
            sum = 1;
            dice[0] = 1;
            dice[1] = 5;
            dice[2] = 3;
            dice[3] = 2;
            dice[4] = 4;

            // 指定された数だけコマンドを実行する
            for (int i = 0; i < loop; i++) {
                String command = readLine(reader);
                doCommand(command);
                sum += dice[0];
            }
            System.out.println(sum);

        }
    }
}

Measured memory_bytes: 21812
#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 = 1001001001;

int main() {
  int n, min_cnt = INF;
  cin >> n;
  rep(i, n) {
    ll a;
    cin >> a;
    int cnt = 0;
    while (a % 2 == 0) {
      a /= 2;
      cnt++;
    }
    min_cnt = min(min_cnt, cnt);
    // cerr << min_cnt << endl;
  }
  cout << min_cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#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(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define dup(x,y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,v.size())i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,v.size())s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(v.size())o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio cin.tie(nullptr); std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
#define myloopset int loop = 1; if(argc>2) loop =stoi(argv[2]); rep(i,loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a,T b){if(a>b){a=b; return 1;}else return 0;}
template <class T> T chmax(T &a,T b){if(a<b){a=b; return 1;}else return 0;}
const int dx[4] = {0,1,0,-1};
const int dy[4] = {-1,0,1,0};
const int mod = 1000000007;

void Main(){
  ll a,b,c;
  cin>>a>>b>>c;
  if(c-(a+b)>=0){
    std::cout << (((a*b*4) < (c-(a+b))*(c-(a+b)))? "Yes":"No") << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }

    


} signed main(int argc,char** argv)
{fastio; myio; myloopset Main();}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <vector>
#include <cstdlib>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(ll &f){
    f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
}
ll cnt[10005];
string s;
ll f[DMAX];
ll n,p;
ll ans=0;
ll pol=1;
int main(){
    mem(cnt,0);
    read(n),read(p);
    cin>>s;
    if(p==2 || p==5){
        for(int i=0;i<s.size();i++){
            ll pos=ll(s[i]-'0');
            if(pos%p==0){
                ans+=(i+1);
            }
        }
        cout<<ans<<endl;
        return 0;
    }
    reverse(s.begin(),s.end());
    f[0]=0;
    for(ll i=0;i<n;i++){
        ll pos=ll(s[i]-'0');
        f[i+1]=(f[i]+pol*pos)%p;
        pol=pol*10%p;
    }
    cnt[0]++;
    for(ll i=0;i<n;i++){
        ans+=cnt[f[i+1]];
        cnt[f[i+1]]++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<tuple>
using namespace std;
tuple<int, int, int>x[1 << 17];
int n, maxn, a, b, c, s;
int dx[2][3] = { { 1,1,0 },{0,-1,-1} }, dy[2][3] = { { 0,1,1 },{1,1,0} };
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a >> b >> c; x[i] = make_tuple(a, b, c); }
	sort(x, x + n);
	for (int i = 0; i < n; i++) {
		for (int h = 0; h < 2; h++) {
			for (int j = 0; j < 8; j++) {
				s = 0;
				for (int k = 0; k < 3; k++) {
					if ((j / (1 << k)) % 2 == 0) {
						int c = lower_bound(x, x + n, make_tuple(get<0>(x[i]) + dx[h][k], get<1>(x[i]) + dy[h][k], 0)) - x;
						if (get<0>(x[c]) == get<0>(x[i]) + dx[h][k] && get<1>(x[c]) == get<1>(x[i]) + dy[h][k]) {
							s += get<2>(x[c]);
						}
					}
				}
				maxn = max(maxn, s + get<2>(x[i]));
			}
		}
	}
	cout << maxn << " / 1" << endl;
	return 0;
}

Measured memory_bytes: 4256
#include <stdio.h>

int main(int argc, const char * argv[]){
    int n,m;
    char c,s[5]={'S','H','C','D','\0'};
    static int card[4][13];
    scanf("%d\n",&n);
    
    for(int i=0;i<n;i++){
        scanf("%c %d\n",&c,&m);
        for(int j=0;j<4;j++)
            if(s[j]==c)
                card[j][m-1]=1;
    }
    
    for(int i=0;i<4;i++)
        for(int j=0;j<13;j++)
            if(card[i][j]==0)
                printf("%c %d\n",s[i],j+1);
    
    return 0;
}


Measured memory_bytes: 2076
def resolve():
    '''
    code here
    '''
    x = int(input())
    if x%11 != 0:
        print((x//11)*2 + (x%11)//7 +1)
    else:
        print((x//11)*2 + (x%11)//7)


if __name__ == "__main__":
    resolve()


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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;

int main() {
    lli n;
    cin1(n);
    lli d[n];
    ncin1(n,d);
    lli ans = 0;
    REP(i,0,n) {
        REP(j,0,n) {
            if (i == j)
                continue;
            ans += d[i] * d[j];
        }
    }
    cout << ans/2 << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;

public class Main {

  private static void solve() {
    long n = nl();
    int m = 62;

    int mod = (int) 1e9 + 7;

    long[][] dp = new long[m + 1][3];
    dp[m][0] = 1;
    for (int i = m - 1; i >= 0; i--) {
      int d = (int) ((n >> i) & 1);

      for (int j = 0; j <= 2; j++) {
        for (int k = 0; k <= 2; k++) {
          int ns = Math.min(2, j * 2 + d - k);
          if (ns < 0)
            continue;
          dp[i][ns] += dp[i + 1][j];
          dp[i][ns] %= mod;
        }
      }
    }
    System.out.println(Arrays.stream(dp[0]).sum() % mod);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 37376
#include <bits/stdc++.h>
using namespace std;
int dx[8] = {1,0,-1,0,1,-1,-1,1};//右、上、左、下、右上、左上、左下、右下のつもり
int dy[8] = {0,1,0,-1,1,1,-1,-1};//実際は色々反転している。どうせ4か8方向調べるから関係ないとしている。
bool seen[60][60]={true};
int h,w;
void dfs(vector<vector<int> > &G,int i,int j){
    if(G[i][j]) seen[i][j] = true;
    for(int k=0;k<8;k++){
	int di = i + dx[k];
	int dj = j + dy[k];
	if(di < 0 || h <= di || dj < 0 || w <= dj)continue;
	
	if(seen[di][dj]==false) dfs(G,di,dj);
    }
}
int main(void){
    while(cin >> w >> h){
	if(w == 0 && h== 0) break;
	for(int i=0;i<h;i++)for(int j=0;j<w;j++) seen[i][j] = true;
	vector<vector<int> > G(h,vector<int>(w));
	for(int i=0;i<h;i++){
	    for(int j=0;j<w;j++){
		cin >> G[i][j];
		if(G[i][j]) seen[i][j] = false;
	    }
	}
	int t =0;
	for(int i=0;i<h;i++){
	    for(int j=0;j<w;j++){
		if(seen[i][j]) continue;
		dfs(G,i,j);
		t++;
	    }
	}
	cout << t << endl;
    }

    return 0;
}



Measured memory_bytes: 3276
a,b = map(int,input().split())

import math
ans=0
for i in range(1,1500):
    price8 = math.floor(i*0.08)
    price10 = math.floor(i*0.10)
    if a==price8 and b==price10:
        ans=1
        break
if ans==1:
    print(i)
else:
    print(-1)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct segtree{
    static const int SEG=1<<18;
    vint dat;
    segtree():dat(SEG*2){}
    void update(int k,int x){
        k+=SEG-1;
        chmax(dat[k],x);
        while(k){
            k=(k-1)/2;
            dat[k]=max(dat[k*2+1],dat[k*2+2]);
        }
    }
    int query(int a,int b,int k=0,int l=0,int r=SEG){
        if(r<=a||b<=l)return 0;
        if(a<=l&&r<=b)return dat[k];
        return max(query(a,b,k*2+1,l,(l+r)/2),query(a,b,k*2+2,(l+r)/2,r));
    }
};


int N;
int A[111111],B[111111];

vint x[222222];
vint y[222222];

signed main(){
    scanf("%lld",&N);

    vint vs;
    rep(i,N){
        scanf("%lld%lld",&A[i],&B[i]);
        vs.pb(A[i]);
        vs.pb(B[i]);
    }

    sort(all(vs));vs.erase(unique(all(vs)),vs.end());
    rep(i,N){
        A[i]=lower_bound(all(vs),A[i])-vs.begin();
        B[i]=lower_bound(all(vs),B[i])-vs.begin();
        x[A[i]].pb(B[i]);
        y[B[i]].pb(A[i]);
    }

    segtree latte,malta;
    for(int i=0;i<222222;i++){
        vpint c,d;
        for(auto w:x[i]){
            c.pb({w,malta.query(0,w)+1});
        }
        for(auto w:y[i]){
            d.pb({w,latte.query(0,w)+1});
        }
        for(auto p:c)latte.update(p.fi,p.se);
        for(auto p:d)malta.update(p.fi,p.se);
    }

    cout<<max(latte.query(0,vs.size()),malta.query(0,vs.size()))<<endl;
    return 0;
}

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

using namespace std;

const int size = 2e5+10;
const int INF = 1e9;


int main() {
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n,m,k;
	vector <int> a(size);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.begin() + n);
	vector <int> b(size);
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	sort(b.begin(), b.begin() + m);
	int l1 = 0;
	int l2 = 0;
	while (l1 < n && l2 < m) {
		while (l1 < n && a[l1] < b[l2])
			l1++;
		if (l1 < n && a[l1] == b[l2]) {
			l1++;
			l2++;
		}
		else {
			cout << "NO" << '\n';
			return 0;
		}
	}
	if (l2 < m)
		cout << "NO" << '\n';
	else
		cout << "YES" << '\n';
	
	


	return 0;
}

Measured memory_bytes: 2424
#include <bits/stdc++.h> 
using namespace std; 
int gi() { 
	int res = 0, w = 1; 
	char ch = getchar(); 
	while (ch != '-' && !isdigit(ch)) ch = getchar(); 
	if (ch == '-') w = -1, ch = getchar(); 
	while (isdigit(ch)) res = res * 10 + ch - '0', ch = getchar(); 
	return res * w; 
}
const int Mod = 1e9 + 7; 
int fpow(int x, int y) {
	int res = 1; 
	while (y) {
		if (y & 1) res = 1ll * res * x % Mod; 
		x = 1ll * x * x % Mod; 
		y >>= 1; 
	} 
	return res; 
} 
const int MAX_N = 2e5 + 5; 
int N, X, Y; 
int fac[MAX_N], ifc[MAX_N]; 
vector<int> pot[MAX_N]; 
int main () { 
#ifndef ONLINE_JUDGE 
    freopen("cpp.in", "r", stdin); 
#endif 
	N = gi(), X = gi(), Y = gi(); 
	for (int i = fac[0] = 1; i <= N; i++) fac[i] = 1ll * fac[i - 1] * i % Mod; 
	ifc[N] = fpow(fac[N], Mod - 2); 
	for (int i = N - 1; ~i; i--) ifc[i] = 1ll * ifc[i + 1] * (i + 1) % Mod; 
	for (int i = 1; i <= N; i++) { 
		int c = gi(), w = gi(); 
		pot[c].push_back(w); 
	} 
	for (int i = 1; i <= N; i++) sort(pot[i].begin(), pot[i].end());
	pot[0].push_back(Mod); 
	int mn1 = 0, mn2 = 0; 
	for (int i = 1; i <= N; i++) { 
		if (!pot[i].size()) continue; 
		if (pot[mn1][0] > pot[i][0]) mn2 = mn1, mn1 = i; 
		else if (pot[i][0] < pot[mn2][0]) mn2 = i; 
	} 
	if (!mn2 || pot[mn1][0] + pot[mn2][0] > Y) return puts("1") & 0; 
	int tms = 1, sum = 0; 
	for (int i = 1; i <= N; i++) { 
		if (!pot[i].size() || i == mn1 || pot[mn1][0] + pot[i][0] > Y) continue; 
		int mx = upper_bound(pot[i].begin(), pot[i].end(), Y - pot[mn1][0]) - pot[i].begin(); 
		mx = max((int)(upper_bound(pot[i].begin(), pot[i].end(), X - pot[i][0]) - pot[i].begin()), mx); 
		sum += mx, tms = 1ll * tms * ifc[mx] % Mod; 
	} 
	int mx = max(upper_bound(pot[mn1].begin(), pot[mn1].end(), X - pot[mn1][0]) - pot[mn1].begin(),
				 upper_bound(pot[mn1].begin(), pot[mn1].end(), Y - pot[mn2][0]) - pot[mn1].begin()); 
	sum += mx, tms = 1ll * tms * ifc[mx] % Mod; 
	printf("%lld\n", 1ll * fac[sum] * tms % Mod); 
    return 0; 
} 

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);

    int n;
    cin >> n;

    n = n % 10;

    if(n == 3) cout << "bon";
    else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon";
    else cout << "hon";

}








Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		StringTokenizer st = new StringTokenizer(br.readLine());
		int N = Integer.parseInt(st.nextToken());
		int M = Integer.parseInt(st.nextToken());
		
		if(N==M)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

}

Measured memory_bytes: 32720
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long A = scan.nextLong();
        long B = scan.nextLong();
        if (B == 1) {
            System.out.println(0);
            return;
        }
        long depth = 0;
        long current = 1;
        while (current < B)  {
            depth += 1;
            current *= A;
        }
        long target_sockets = p(A, depth - 1);
        long current_sockets = target_sockets;
        long answer = s(A, depth - 2);
        current = 0;
        for (long i = 0; i < target_sockets; i++) {
            current += A;
            answer += 1;
            if (B <= current + target_sockets - i - 1) {
                break;
            }
        }
        System.out.println(answer);
    }
    private long s(long A, long n) {
        long x = p(A, n + 1) - 1;
        return x / (A - 1);
    }
    private long p(long A, long depth) {
        int current = 1;
        for (long i = 0; i < depth; i++) {
            current *= A;
        }
        return current;
    }
}


Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc *bufio.Scanner = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}()

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextStrings(n int) []string {
	strings := make([]string, n)
	for i := 0; i < n; i++ {
		strings[i] = nextString()
	}
	return strings
}

func count(strings []string) []string {
	mp := map[string]int{}
	mx := 0
	for _, v := range strings {
		if n, exist := mp[v]; exist {
			n++
			mp[v] = n
			if mx < n {
				mx = n
			}
		} else {
			mp[v] = 1
			if mx < 1 {
				mx = 1
			}
		}
	}

	mxStrings := []string{}
	for k, v := range mp {
		if mx == v {
			mxStrings = append(mxStrings, k)
		}
	}
	sort.Strings(mxStrings)
	return mxStrings
}

func main() {
	n := nextInt()
	strings := nextStrings(n)
	for _, s := range count(strings) {
		fmt.Println(s)
	}
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;


vector<pair<int,int>> g[MAX_N];
map< pair<int,int>, vector<pair<int,int>> > g2;
map< pair<int,int>, int > memo; // <pos, prev>, dist

int main2() {
  REP(i, MAX_N) g[i].clear();

  int N = nextInt();
  int M = nextInt();
  
  REP(i, M) {
    int x = nextInt() - 1;
    int y = nextInt() - 1;
    int c = nextInt();
    g[x].push_back({y, c});
    g[y].push_back({x, c});
    g2[{x,c}].push_back({y, c});
    g2[{y,c}].push_back({x, c});
  }

  memo.clear();
  deque< pair<int,int> > q;
  q.push_back( {0, -1} );
  memo[{0, -1}] = 0;

  for (; q.size() > 0 ;) {
    auto cur = q.front(); q.pop_front();

    const int cost = memo[cur];
    if (cur.first == N-1) {
      cout << cost << endl;
      return 0;
    }

    if (cur.second == -1) {

      for (auto e : g[cur.first]) {
        if (memo.count(e) == 0 || memo[e] > cost+1) {
          q.push_back(e);
          memo[e] = cost+1;
        }
      }

    } else {

      for (auto e : g2[cur]) {
        if (cur.second == e.second) {
          if (memo.count(e) == 0 || memo[e] > cost) {
            q.push_front(e);
            memo[e] = cost;
          }
        }
      }

      {
        auto e = cur;
        e.second = -1;
        if (memo.count(e) == 0 || memo[e] > cost) {
          q.push_front(e);
          memo[e] = cost;
        }
      }

    }
  }
  cout << -1 << endl;

  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 75904
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int H,W,K;
vector<string> pond;
int sx,sy,tx,ty;
void input(){
    fast_io();
    cin >> H >> W >> K;
    cin >> sx >> sy >> tx >> ty;
    sx--,sy--;
    tx--,ty--;
    for (int i = 0; i < H; i++)
    {
        string s; cin >> s;
        pond.push_back(s);
    }
}

#define x first
#define y second

int solve(){
    queue<pair<int,pii> > q;
    q.emplace(0,make_pair(sx,sy));
    vector<vector<int>> dist(H,vector<int>(W,INT_INF));
    dist[sx][sy] = 0;
    map<pii,pii> pref;
    while (!q.empty())
    {
        int d = q.front().first;
        pii cur = q.front().second;
        q.pop();
        if(dist[cur.x][cur.y]<d) continue;
        dist[cur.x][cur.y]=d;
        for (int k = 0; k < 4; k++)
        {
            for (int t = 1; t <= K; t++)
            {
                pii next = cur;
                next.x += t*dx[k];
                next.y += t*dy[k];
                if(next.x<0 || next.x>=H) break;
                if(next.y<0 || next.y>=W) break;
                if(pond[next.x][next.y]=='@') break;
                if(dist[next.x][next.y]<=dist[cur.x][cur.y]) break;
                if(dist[next.x][next.y]<=d+1) continue;
                dist[next.x][next.y]=d+1;
                pref[next] = cur;
                if(next.x==tx && next.y==ty) break;
                q.emplace(d+1,next);
            }
        }
    }
    if(dist[tx][ty]==INT_INF) {cout << -1 << endl; return 0;}
    else cout << dist[tx][ty] << endl;      
    return 0;
}   

#undef x
#undef y

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 56208
import sys

n = int(input())
a = [int(input()) for i in range(n)]
a = [i for i in a]


switch = 1

c = 0
while True:
    switch = a[switch-1]
    c += 1
    if switch == 2:
        break
    
    if c > 10**6:
        print(-1)
        sys.exit()
        break

print(c)

Measured memory_bytes: 55512
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c= list(map(int,input().split()))
cnt=0
for i in range(n-1):
    if a[i+1] == a[i]+1:
        cnt+=c[a[i]-1]

print(sum(b)+cnt)

Measured memory_bytes: 39704