akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    string s;
    cin >> s;

    int ans;
    for(int i = 1; i < s.size(); i++){
        bool flag = true;
        if((s.size()-i)%2 == 0){
        for(int j = 0; j < (s.size()-i)/2; j++){
            if(s[j] != s[(s.size()-i+1)/2+j]) flag = false;
        }
        if(flag){
            ans = s.size()-i;
            break;
        } 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#ABC169 C-Multiplication3
class Calc():
  def multi(self,x,y):
    x, y, sign, rslt = str(x)+".", str(y)+".",1 ,""
    if x[0]=="-":
      sign*=-1
      x=x[1:]
    if y[0]=="-":
      sign*=-1
      y=y[1:]
    x,y=x.split("."),y.split(".")
    x2 = [int(x[1][-i-1]) for i in range(len(x[1]))] + [int(x[0][-i-1]) for i in range(len(x[0]))]
    y2 = [int(y[1][-i-1]) for i in range(len(y[1]))] + [int(y[0][-i-1]) for i in range(len(y[0]))]
    sum=[0]*(len(x2)+len(y2))
    for i, p in enumerate(y2):
      for j, q in enumerate(x2):
        K=i+j
        sum[K]+=p*q
        while sum[K]>9:
          sum[K+1], sum[K] = sum[K+1] + int(sum[K]/10) , sum[K]%10
          K+=1
    for i in range(len(sum)): rslt+=str(sum[-i-1])
    dclen=len(x[1])+len(y[1])
    if dclen>0: rslt=rslt[:len(rslt)-dclen]+"."+rslt[len(rslt)-dclen:len(rslt)]
    for i in range(len(rslt)):
      if rslt[i]=="0" and (rslt[i+1] if i<len(rslt)-1 else ".")!="." : continue
      else:
        rslt=rslt[max(i,0):]
        break
    if "." in rslt: rslt=rslt[:rslt.index(".")] #(小数点以下切捨て)
    return ("-" if sign==-1 else "")+rslt

A,B=input().split()
print( Calc().multi(A,B) )

Measured memory_bytes: 9312
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n,t,a;cin >> n >>t >>a;
    t--;a--;
    vvl g(n);
    rep(i,n-1){
        ll x,y;cin >>x >>y;x--;y--;
        g[x].pb(y); g[y].pb(x);
    }
    vl dist(n,-1);
    queue<ll> que;
    que.push(t);
    dist[t]=0;
    while(!que.empty()){
        ll v=que.front();que.pop();
        for(auto nv:g[v]){
            if(dist[nv]!=-1)continue;
            dist[nv]=dist[v]+1;
            que.push(nv);
        }
    }
    vl dist2(n,-1);
    que.push(a);
    dist2[a]=0;
    while(!que.empty()){
        ll v=que.front();que.pop();
        for(auto nv:g[v]){
            if(dist2[nv]!=-1)continue;
            dist2[nv]=dist2[v]+1;
            que.push(nv);
        }
    }
    ll ans=0;
    rep(i,n){
        if(dist[i]<dist2[i]){
            if(g[i].size()==1){
                chmax(ans,dist2[i]-1);
            }
            else chmax(ans,dist2[i]);
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 8064
#include <stdio.h>

int main(){
  char n[3];
  int tmp;

  scanf("%s", n);
  
  for(int i=0; i<3; i++){
    tmp = n[i] - 48;
    if(tmp == 7){
      printf("Yes\n");
      break;
    }
    if(i == 2){
      printf("No\n");
    }
  }


  return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iomanip>

using namespace std;
// for loop
#define F(i, L, R) for(int i = L; i < R; i++)
#define FE(i, L, R) for(int i = L; i <= R; i++)
// for (reversed)
#define FR(i, L, R) for(int i = L; i > R; i--)
#define FRE(i, L, R) for(int i = L; i >= R; i--)

// data types
#define ul unsigned long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned shoft

// vectors
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define ALL(c) (c).begin(),(c).end()
#define last(vec) vec.size()-1
#define lastEle(vec) vec[last(vec)]

// debug
#define DBG(vari) cerr<<#vari<<" = "<<(vari)<<endl;
#define printA(a, L, R) FE(i, L, R) cout << a[i] << (i==R?'\n':' ')
#define printAF(a, L) printA(a, 0, L-1)
#define printV(a) printA(a, 0, a.size()-1)

// utils
#define char2int(c) (c-'0')
#define bit(x, i) (x&(1<<i))
#define space ' '
#define PI 3.14159265358979323

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

    short data[4][3][10] = {0};
    short b,f,r,v;
    F(i, 0, n){
        cin >> b >> f >> r >> v;
        data[b-1][f-1][r-1] += v;
    }

    F(i, 0, 4){
       // create a buillding
       F(k, 0, 3){
           F(l, 0, 10){
               cout << space << data[i][k][l];
           }
           cout << endl;
       }
       if(i == 3)break;
       string wall = "";
       F(l, 0, 20) wall += '#';
       cout << wall << endl;
    }
}



Measured memory_bytes: 3204
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Queue;
import java.util.Scanner;

//Mysterious Onslaught
public class Main{

	int[] d;
	int res, M = (0x1f)<<20;
	List<Integer>[] mask;
	
	void f(int S, int depth, int k){
		if((S&M)==0){
			res = Math.min(res, depth+d[S]);
			return;
		}
		if(res<=depth|| k==5)return;
		for(int m:mask[k]){
			f(S^m, depth+1, k+1);
		}
		f(S, depth, k+1);
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		d = new int[1<<20];
		int INF = 1<<28;
		Arrays.fill(d, INF);
		d[0] = 0;
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(0);
		while(!q.isEmpty()){
			int S = q.poll();
			for(int i=0;i<4;i++)for(int j=0;j<5;j++)for(int h=i;h<4;h++)for(int w=j;w<5;w++){
				int ns = S;
				for(int y=i;y<=h;y++)for(int x=j;x<=w;x++)ns^=1<<(y*5+x);
				if(d[ns]==INF){
					d[ns] = d[S]+1;
					q.add(ns);
				}
			}
		}
		mask = new List[5];
		for(int j=0;j<5;j++){
			mask[j] = new ArrayList<Integer>();
			for(int h=4;h>=0;h--)for(int w=j;w<5;w++){
				int m = 0;
				for(int y=4;y>=h;y--)for(int x=j;x<=w;x++)m+=1<<(y*5+x);
				mask[j].add(m);
			}
		}
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int x = 0;
			for(int i=0;i<n;i++)for(int j=0;j<n;j++)if(sc.nextInt()==1)x|=1<<(i*5+j);
			res = 9;
			if(n<=4)res=d[x];
			else f(x, 0, 0);
			while(res--!=0)System.out.print("myon");
			System.out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 55000
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int n,ans;

int main(){
	cin>>n;
	cin>>a>>b>>c;
	for(int i=0;i<n;i++){
		if(a[i]==b[i]&&b[i]==c[i]) ans+=0;
		else if(a[i]==b[i]||a[i]==c[i]||b[i]==c[i]) ans+=1;
		else ans+=2;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

        int r,c,lsum,tmp;
        cin >> r >> c;
        int num[101] = {};

        for(int i = 0; i < r; i++){
                lsum = 0;
                for(int j = 0; j < c; j++){
                        cin >> tmp;
                        lsum += tmp;
                        num[j] += tmp;
                        num[c] += tmp;
                        
                        cout << tmp << " ";

                        if(j == (c - 1)) cout << lsum << "\n";

                }
        }

        for(int k = 0; k <= c; k++){
                cout << num[k];
                if(k != c) cout << " ";
                else cout << "\n";
        }

        return 0;
}

Measured memory_bytes: 1160
k = int(input())
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[k-1])

Measured memory_bytes: 3316
#include<stdio.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
int n;
int main(){
	scanf("%d",&n);
	fo(i,1,9) if (i*111>=n){
		printf("%d\n",i*111);
		return 0;
	}
	return 0;
}

Measured memory_bytes: 128
import numpy as np
import math
import sys
sys.setrecursionlimit(10000000)

def main():
    S = input()
    N = len(S)
    num = 1
    i = 1
    last = S[0] # 前回が1文字
    if N == 2:
        if S[0] == S[1]:
            print(1)
        else:
            print(2)
        sys.exit() 
    
    while(i < N):
        if last == S[i]:
            last = S[i] + S[i+1] if i < N - 1 else S[i]
            i += 2
        else:
            if i == N - 2 and S[i] == S[i+1]:
                # if last == S[i] + S[i + 1]:
                #     break
                # else:
                num += 1
                break
            else:
                last = S[i]
                i += 1
        num += 1
        # print(i, num)
    
    print(num)
            


if __name__ == '__main__':
    main()

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


using namespace std;

int cost[10];
int c[10][10];
bool visit[10][10];

int findMin(int a){
	if(a==1)
		return 0;
	for(int i=0;i<10;i++){
		if(!visit[a][i] and c[a][i]<cost[a]){
			visit[a][i]=true;
			int s = findMin(i);
			if(s+c[a][i]<cost[a])
				cost[a] = s+c[a][i];
		}
	}
	return cost[a];

}


int main() {

	int h,w;
	cin >> h >> w;
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			cin >> c[i][j];
			if(i==j)
				visit[i][j] = true;
			if(j==1)
				cost[i] = c[i][j];
		}
	}
	cost[1]=0;
	for(int i=0;i<=9;i++){
		for(int j=0;j<10;j++){
			for (int k = 0; k < 10; k++){
				if(j==k)
					visit[j][k]=true;
				else
					visit[j][k]=false;
			}
		}
		findMin(i);
		//cout << cost[i] << endl;
	}
	int mp=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			int a;
			cin>>a;
			if(a!=-1)
				mp+=cost[a];
		}
	}
	cout << mp;
}

Measured memory_bytes: 256
N,X=map(int, raw_input().split())

a,p=[1], [1]
for i in range(N):
	a.append(a[-1]*2+3)
	p.append(p[-1]*2+1)

def f(N,X):
	if N==0:
		return 0 if X<=0 else 1
	elif X<=1 + a[N-1]:
		return f(N-1,X-1)
	else:
		return p[N-1]+1+f(N-1, X-2-a[N-1])

print f(N,X)

Measured memory_bytes: 28524
// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;


// Code from Here -------------------------------------------------------------------------------


signed main() {
	tezz
	int p,n;
	cin >> p >> n;
	int dis=0;
	vi a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(i!=0){
			dis=max(dis,a[i]-a[i-1]);
		}
	}
	dis = max(dis, a[0]+p-a[n-1]);
	cout << p-dis;

	return 0;
}  


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if((A+B)%2 == 1){
        cout << "IMPOSSIBLE"<< endl;
    }
    else{
    cout << (A+B)/2 << endl;
    }
    return 0;

} 

Measured memory_bytes: 256
/*
@Author
   Sujeet Kushwaha
*/
 
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
#define ll long long int
#define fast ios_base::sync_with_stdio(false)
#define fast_input cin.tie(NULL)
#define fast_output cout.tie(NULL)
#define vi vector<long long int> 
#define vp vector<pair<long long int ,long long int>>
#define pb push_back
#define mp make_pair
#define pp pop_back
#define iter vector<int>::iterator
#define pa pair<long long int ,long long int> 
#define f(a,b) for(int a=0;a<b;a++)
#define mod 1000000007
#define F first
#define S second
#define sett set<long long int>
#define um unordered_map<ll,ll>
#define ordered_set tree<pa, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
// ll powmod(ll a, ll b)
// {
//     ll res = 1;
//     while (b) {
//         if (b&1) {
//             res *= a;
//             res %= mod;
//         }
//         b >>= 1;
//         a = (a * a) % mod;
//     }
 
//     return res;
// }
 
// ll modInv(ll a)
// {
//     return powmod(a, mod - 2);
// }
// int fastread(){
//     int x=0;
//     int c = getchar_unlocked();
//     while(c<48)
//         c = getchar_unlocked();
//     while(c>=48){
//         x = x*10 + (c - 48);
//         c = getchar_unlocked();
//     }
//     return x;
// }
bool comp(pa a,pa b)
{
   if(a.F==b.F)
      return a.S<b.S;
   return a.F<b.F;
}
void solve()
{
 ll n;
  cin>>n;
  if(n%2)
  {
     cout<<0;
    return;
  }
  ll sum = 0;
    while (n) {
      sum += n / 5 / 2;
      n /= 5;
    }

  cout<<sum;
}
int main() {
	fast;
	fast_input;
	fast_output;
	
	  solve();
	
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/03/05  Problem: 066_arc_b / Link: https://arc066.contest.atcoder.jp/tasks/arc066_b?lang=en  ----- */
/* ------問題------

正の整数 N が与えられます。 2 つの整数 u,v(0≦u,v≦N) であって、ある非負整数 a,b が存在して、a xor b=u、a+b=v となるようなものが何通りあるかを求めてください。 ここで、xor はビットごとの排他的論理和を表します。 なお、答えは非常に大きくなることがあるので、109+7 で割った余りを求めてください。

-----問題ここまで----- */
/* -----解説等-----

OEISさん…(A007729)
を使ってまずO(N logN)の部分和を求めることができる。
部分和と数列からいい感じに部分和を作り出すことができる。
変形によって部分和は再帰的に求めることができるので、O(logN)で解ける。

部分和のサイズをn+1にしてハマった。
部分和から部分和みたいなときは関係性が知りたいので数字は気にしなくてもいいかも…

----解説ここまで---- */

LL ans = 0LL;

//LL solve(int u, int v) {
//	FOR(a, 0, 1000) {
//		FOR(b, 0, 1000) {
//			if ((a^b) == u && (a + b == v)) {
//				return 1;
//			}
//		}
//	}
//
//	return 0;
//}


LL solve(LL x ) {
	if (x < 2)return x;
	if (x % 2 == 0) {
		return solve(x / 2);
	}
	else {
		return( solve((x - 1) / 2) + solve((x + 1) / 2))%MOD;
	}
 }

LL solvesum(LL x) {
	LL ret = 0;
	FOR(i, 0, x+2) {
		ret += solve(i);
	}

	return ret;
}


map<LL, LL >memo;
map<LL, int >look;
LL solveQ(LL x) {
	if (x < 2)return (x);
	if (look[x])return memo[x];
	LL & ret = memo[x];
	ret = ( solveQ((x)/2) + solveQ((x-1) / 2)+ solveQ((x +1) / 2)) % MOD;
	look[x] = 1;
	return ret;
}


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


	//FOR(N, 1, 20) {
	//	LL ret = 0;
	//	FOR(u, 0, N + 1) {
	//		FOR(v, 0, N + 1) {
	//			ret += (solve(u, v));
	//		}
	//	}
	//	debug(ret);
	//}
	//VI test({ 1, 2, 4, 5, 8, 10, 13, 14, 18, 21, 26, 28, 33, 36, 40, 41, 46, 50, 57, 60 });
	//FOR(i, 0, 10000) {
	//	assert(solvesum(i) == solveQ(1 + i));
	//	if (i % 10 == 0)cout << i << endl;
	//	//cout<< test[i]<<", "<<solvesum(i) << ", "<<solveQ(1+i)<< endl;
	//}
	LL N; cin >> N;
	ans = solveQ(N+1);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
from sys import stdin

def main():

    input = stdin.readline

    N,K = map(int,input().split())
    p_list = [(p+1)/2 for p in list(map(int,input().split()))]

    # Sを計算
    S = [0]
    for p in p_list:
        S.append(S[-1] + p)
        # print(S)

    # i:i+kを計算

    maxs = 0
    for i in range(N-K+1):
        p_num = S[i+K] - S[i]
        if(maxs < p_num):
            maxs = p_num
    
    print(maxs)

if __name__ == "__main__":
    main()

Measured memory_bytes: 24404
#include"bits/stdc++.h"
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

int N;

signed main(){
	cin >> N;
	if(N%10 == 3) cout << "bon" << endl;
	else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
}

Measured memory_bytes: 3660
void main(){
	int[] ab = _scanln();
	(ab[0] * ab[1]).writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2760
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,x,y=map(int,input().split())
    x-=1; y-=1

    E=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v=map(int,input().split())
        u-=1; v-=1
        E[u].append(v)
        E[v].append(u)

    # x から y への path を作る(depthも)
    Q=[(x,-1)]
    prev=[None]*n
    prev[x]=-1
    depth=[None]*n
    depth[x]=0
    while(Q):
        v,p=Q.pop()
        for nv in E[v]:
            if(nv==p): continue
            prev[nv]=v
            depth[nv]=depth[v]+1
            Q.append((nv,v))

    z=y
    path=[]
    while(z!=-1):
        path.append(z)
        z=prev[z]

    # y からの depth
    Q=[(y,-1)]
    depth2=[None]*n
    depth2[y]=0
    while(Q):
        v,p=Q.pop()
        for nv in E[v]:
            if(nv==p): continue
            depth2[nv]=depth2[v]+1
            Q.append((nv,v))

    k=len(path)
    s,t=path[k//2-1],path[k//2]

    Q=[(x,-1)]
    can=[0]*n
    can[x]=1
    while(Q):
        v,p=Q.pop()
        for nv in E[v]:
            if(nv==p): continue
            if((v,nv)==(s,t) or (v,nv)==(t,s)): continue
            can[nv]=1
            Q.append((nv,v))

    d1,z=max((depth2[v],v) for v in range(n) if(can[v]))
    d2=depth[z]
    # print(d1,d2)
    # if((d1+d2)&1):
    #     d1-=1

    print(d1-1)
resolve()

Measured memory_bytes: 71224
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using Debug = System.Diagnostics.Debug;
using System.Runtime.CompilerServices;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

static class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        long res = 0;
        long[] charCount = new long[26];
        for (int i = 0; i < s.Length; i++) charCount[s[i] - 'a']++;
        for (int i = 1; i < 26; i++)
        {
            res += charCount.Take(i).Sum() * charCount[i];
        }
        Console.WriteLine(res + 1);
    }
}


Measured memory_bytes: 13792
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<vector>
#include<cstdio>
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
vector<int> ans;
int n,num2,num3;
inline void Push(int j)
{
    ans.push_back(2+j);
    ans.push_back(3+j);
    ans.push_back(4+j);
    ans.push_back(8+j);
    ans.push_back(9+j);
    ans.push_back(10+j);
}
int main()
{
    n=read();
    if(n==3) return 0*puts("2 5 63");
    if(n==4) return 0*puts("2 5 20 63");
    if(n==5) return 0*puts("2 3 4 6 9");
    Push(0);
    for(int j=2;ans.size()+5000<n;j+=2) Push(j*6);
    for(int k=6;ans.size()<n;k+=6) ans.push_back(k);
    for(int i=0;i<ans.size();++i) printf("%d ",ans[i]);
    return 0;
}

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

using Tree = std::vector<std::vector<uint32_t>>;
Tree V;
std::vector<uint32_t> values;

void Run(uint32_t i, uint32_t f, uint32_t sum) {
  auto c = values[i];
  values[i] += sum;
  for (const auto &e: V[i]) {
    if (e != f) {
      Run(e, i, sum + c);
    }
  }
}

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

  uint32_t N, Q;

  std::cin >> N >> Q;

  V.resize(N);
  values.resize(N);
  
  for (uint32_t i = 0; i < N - 1; i++) {
    uint32_t ti, ni;
    std::cin >> ti >> ni;
    V[ti - 1].push_back(ni - 1);
    V[ni - 1].push_back(ti - 1);
  }

  for (uint32_t i = 0; i < Q; i++) {
    uint32_t ti, ac;
    std::cin >> ti >> ac;
    values[ti - 1] += ac;
  }

  Run(0, -1, 0);

  std::cout << values[0];
  for (uint32_t i = 1; i < N; i++) {
    std::cout << " " << values[i];
  }
  std::cout << std::endl;

  return 0;
}


Measured memory_bytes: 23552
from fractions import gcd


def solve(string):
    a, b = map(int, string.split())
    g = gcd(a, b)
    ans = 1 if g % 2 else 2
    while g % 2 == 0:
        g //= 2
    for i in range(3, int(g**0.5) + 1, 2):
        if g % i == 0:
            ans += 1
        while g % i == 0:
            g //= i
    return str(ans + 1) if g > 1 else str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 5048
//https://atcoder.jp/contests/abc109/tasks/abc109_d
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll H,W; cin>>H>>W;
    vector<vector<ll>> ahw(H+1,vector<ll>(W+1));
    FOR(y,1,H+1){
        auto&& v=ahw.at(y);
        FOR(x,1,W+1){
            cin>>v.at(x);
        }
    }
    bool flag=false;
    ll px=-1,py=-1;
    vector<tuple<ll,ll,ll,ll>> ans;
    FOR(y,1,H+1){
        auto&& v=ahw.at(y);
        auto check_func = [&](ll iy,ll ix){
            if (flag){
                ans.emplace_back(make_tuple(py,px,iy,ix));
                //cout<<py<<" "<<px<<" "<<iy<<" "<<ix<<endl;
            }
            if(ahw.at(iy).at(ix)%2==1){
                flag = !flag;
            }
            px=ix;
            py=iy;
        };
        if(y%2==0){//<-
            for(ll x=W;x>=1;--x){
                check_func(y,x);
            }
        } else {//->
            FOR(x,1,W+1){
                check_func(y,x);
            }
        }
    }
    cout<<ans.size()<<endl;
    for(const auto& a:ans){
        cout<<get<0>(a)<<" "<<get<1>(a)<<" "<<get<2>(a)<<" "<<get<3>(a)<<endl;
    }

    return 0;
}

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

#define MAXN 1000000007

typedef long long ll;

using namespace std;

int M[2][52];

ll func ( int N )
{
  ll ans;
  int pos,pre; // 縦:pre = 0, 横:pre = 1

  if ( M[0][0] == M[1][0] ) ans = 3,pos = 1,pre = 0;
  else ans = 6,pos = 2,pre = 1;

  while ( pos < N ) {
    if ( pre == 1 ) {
      if ( M[0][pos] == M[1][pos] ) {
         pos++; pre = 0;
      } else {
        pos += 2; ans *= 3; pre = 1;
      }
    } else {
      if ( M[0][pos] == M[1][pos] ) {
        ans *= 2; ++pos; pre = 0;
      } else {
        ans *= 2; pos += 2; pre = 1;
      }
    }
  }

  return ans % MAXN;
}

int main()
{
  int N;
  string s;

  cin >> N;

  cin >> s;
  for ( int i = 0; i < s.size(); ++i ) M[0][i] = s[i]-'A';

  cin >> s;
  for ( int i = 0; i < s.size(); ++i ) M[1][i] = s[i]-'A';

  cout << func(N) << "\n";
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#define int long long
#define INF 1ll<<60
using namespace std;
int gcd(int a,int b){
	if(a%b==0)
		return b;
	return gcd(b,a%b);
}
signed main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int N;
  cin>>N;
  vector<int>vet(N);
  double soma=0;
  for(int i=0;i<N;i++){
  	cin>>vet[i];
  	soma+=1.0/vet[i];
  }
  cout<<1.0/soma<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

int main(void)
{
	int n;
	int y;
	cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int k = n-i-j;
			if (k < 0)
				continue;
			if (10000*i+5000*j+1000*k == y) {
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1e9;
const int MOD = 1e9+7;

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

    int n; cin >> n;
    vector<int> a(n, 0);
    rep(i, n-1) {
        int x; cin >> x; x--;
        a[x]++;
    }

    rep(i, n) cout << a[i] << endl;
}

Measured memory_bytes: 3960
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll Q,M,K,P,A,B,C,N,X;

    long double x;

    string S;

    vector<ll>  aa;

    cin >>N;

    if(N%10==3)cout<<"bon"<<endl;
    else if(N%10==0 ||N%10==1||N%10==6||N%10==8)cout<<"pon"<<endl;
    else cout<<"hon"<<endl;
    
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
const ll INF = 1e9 + 7;
typedef pair<int,int> P;

int main(){
    ll N,A,B; cin >> N >> A >> B;
    ll ans=0;
    ll shou=N/(A+B);
    ll ama=N%(A+B);

    ans+=shou*A;

    if (ama<=A) ans+=ama;
    else ans+=A;

    cout << ans;
}

Measured memory_bytes: 3652
n = int(input())
arr = {}

for i in range(n):
    s = input()
    if not s in arr:
        arr[s] = 1
    else:
        arr[s] += 1

max_count = max(arr.values())
dic = [key[0] for key in arr.items() if key[1] == max_count]

out_sort = sorted(dic)
for i in out_sort:
    print(i)


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int N,A,B;
int ret[4020];

int ask(int a,int b) {
	string s;
	cout<<"? "<<a<<" "<<b<<endl;
	cin>>s;
	return s[0]=='Y';
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	if(A<=B) {
		cout<<"Impossible"<<endl;
		return;
	}
	
	N=A+B;
	vector<int> path;
	y = B;
	FOR(i,N) {
		if(path.empty() || ask(i,path.back())) {
			path.push_back(i);
		}
		else {
			path.pop_back();
			y--;
		}
		if(path.size()>y) break;
	}
	
	x = path.front();
	FOR(i,N) ret[i]=ask(x,i);
	cout<<"!";
	FOR(i,N) cout<<ret[i];
	cout<<endl;
	
	
	
	
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		sum += v[i];
	}
	int add = 0;
	int ans = 1e9;
	for (int i = 0; i < n; ++i) {
		add += v[i];
		ans = min(ans,abs(add-(sum - add)));
	}
	cout << ans;
}



















Measured memory_bytes: 256
/* ITP1_11_B */
#include <stdio.h>

#define HEXA 6

/* ??¢?????????????????????????????? */
short surface_index(short array_sh[], short size, short surf_num);
/* ?????¢?????????????????????????????? */
short get_right_surf_idx(short top_idx, short front_idx);

int main(void)
{
	short surface[HEXA];
	short ii;
	for( ii = 0; ii < HEXA; ii++ )
	{
		surface[ii] = 0;
		scanf("%hd", &surface[ii]);
	}
	
	short question_num = 0;
	scanf("%hd", &question_num);
	
	short top = 0, front = 0;
	short top_idx = 0, front_idx = 0, right_idx = 0;
	
	for( ii = 0; ii < question_num; ii++ )
	{
		scanf("%hd %hd", &top, &front);
		top_idx = surface_index(surface, HEXA, top);
		front_idx = surface_index(surface, HEXA, front);
		right_idx = get_right_surf_idx(top_idx, front_idx);
		printf("%hd\n", surface[right_idx]);
	}
	
	return 0;
}

/* ??¢?????????????????????????????? */
short surface_index(short array_sh[], short size, short surf_num)
{
	short ii;
	for( ii = 0; ii < size; ii++ )
	{
		if( surf_num == array_sh[ii] )
		{
			return ii;
		}
	}
	return -1;
}

/* ?????¢?????????????????????????????? */
short get_right_surf_idx(short top_idx, short front_idx)
{
	short ret_idx = 0;
	switch( top_idx )			// ?????¢?????????????????????????¢????
	{
	case 0:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 1:
			return 2;
		case 2:
			return 4;
		case 3:
			return 1;
		case 4:
			return 3;
		}
		break;
	case 1:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 0:
			return 3;
		case 2:
			return 0;
		case 3:
			return 5;
		case 5:
			return 2;
		}
		break;
	case 2:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 0:
			return 1;
		case 1:
			return 5;
		case 4:
			return 0;
		case 5:
			return 4;
		}
		break;
	case 3:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 0:
			return 4;
		case 1:
			return 0;
		case 4:
			return 5;
		case 5:
			return 1;
		}
		break;
	case 4:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 0:
			return 2;
		case 2:
			return 5;
		case 3:
			return 0;
		case 5:
			return 3;
		}
		break;
	case 5:
		switch( front_idx )		// ??£??¢?????????????????????????¢????
		{
		case 1:
			return 3;
		case 2:
			return 1;
		case 3:
			return 4;
		case 4:
			return 2;
		}
		break;
	}
	return -1;
}

Measured memory_bytes: 596
use std::io;

fn printnum(x: i32){
    println!("{}", x);
}

fn sum(x: i32, y: i32) -> i32{
    x + y
}

fn read() -> i32{
    let mut x = String::new();
    io::stdin().read_line(&mut x).expect("read_line error");
    let x = x.trim().parse().expect("parse error");
    x
}

fn main() {
    let mut a = [0; 5];
    let mut idx = 0;
    loop {
        if idx == a.len() { break; }
        a[idx] = read();
        idx = idx + 1;
    }
    let k = read();
    println!("{}",if a[4] - a[0] <= k { "Yay!" } else { ":(" });
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n;
string s[2];

ll solve() {
    int i;
    ll res;
    bool prev;
    if (s[0][0] == s[1][0]) {
        i = 1;
        res = 3;
        prev = true;
    } else {
        i = 2;
        res = 6;
        prev = false;
    }

    while (i < n) {
        if (s[0][i] == s[1][i]) {
            if (prev) res = (res * 2) % mod;
            prev = true;
            i++;
        } else {
            if (prev) res = (res * 2) % mod;
            else res = (res * 3) % mod;
            prev = false;
            i += 2;
        }
    }
    return res;
}

void input() {
    cin >> n;
    cin >> s[0] >> s[1];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, x;

    cin >> n >> x;

    int m[n];
    int ans = n;

    int i;

    rep(i, n) {
        cin >> m[i];

        x -= m[i];
    }

    sort(m, m + n);

    ans += x / m[0];

    Out(ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  for(int i=0;i<100;i++){
    a-=d;
    c-=b;
    if(c<=0){
      cout << "Yes" << endl;
      return 0;
    }
    if(a<=0){
      cout<< "No" << endl;
      return 0;
    }
  }
}


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

using namespace std;

const int INF = 1 << 30;

int main()
{
  int N, S[10][3];

  while(scanf("%d", &N), N) {

    for(int i = 0; i < N; i++) {
      for(int j = 0; j < 3; j++) scanf("%d", &S[i][j]);
      sort(S[i], S[i] + 3);
    }

    vector< int > g[10], vs;

    for(int i = 0; i < 12; i++) {
      for(int j = 0; j < 60; j++) {
        for(int k = 0; k < 60; k++) {
          int a = k, b = j, c = (i * 60 + j) / 12;
          for(int l = 0; l < N; l++) {
            bool flag = false;
            do flag |= (S[l][0] - a + 60) % 60 == (S[l][1] - b + 60) % 60 && (S[l][0] - a + 60) % 60 == (S[l][2] - c + 60) % 60;
            while(next_permutation(begin(S[l]), end(S[l])));
            if(flag) g[l].push_back(i * 3600 + j * 60 + k);
          }
        }
      }
    }

    for(int i = 0; i < N; i++) {
      copy(begin(g[i]), end(g[i]), back_inserter(vs));
    }
    sort(begin(vs), end(vs));
    vs.erase(unique(begin(vs), end(vs)), end(vs));

    int ret = INF, now;
    for(int &t : vs) {
      int res = 0, i = 0;
      while(i < N) {
        auto p = lower_bound(begin(g[i]), end(g[i]), t);
        if(p == end(g[i])) break;
        res = max(res, *p - t);
        i++;
      }

      if(i == N && ret > res) ret = res, now = t;
    }
    printf("%02d:%02d:%02d ", now / 3600, now / 60 % 60, now % 60);
    now += ret;
    printf("%02d:%02d:%02d\n", now / 3600, now / 60 % 60, now % 60);
  }
}

Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 8000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int from,to,cost;};
int pow2(int n,int i){if(i==1)return n;return n*pow(n,i-1);};

typedef long long ll;

using namespace std;


int ans,ans2;
int n,m;
int dp[111111];
string s,t;
signed main(){

    map<char,vector<int>> lis;
    cin>>s>>t;
    rep(i,s.size()){
        lis[s[i]].push_back(i);
    }
    int befindex=0;
    rep(i,t.size()){
        if(lis[t[i]].size()==0){
            ans=-1;
            break;
        }
        if(i==0){
            ans+=lis[t[i]][0]+1;
            befindex=lis[t[i]][0];
            DEB(lis[t[i]][0])END;
            continue;
        }

        int key=befindex;
        auto it_ok=upper_bound(lis[t[i]].begin(),lis[t[i]].end(),befindex);
        int ok=it_ok-lis[t[i]].begin();
        //DEB(lis[t[i]][ok])END
        if(ok==lis[t[i]].size()){
            ans+=s.size()-befindex-1+lis[t[i]][0]+1;//その文字が一番はじめにでてくるindex
            befindex=lis[t[i]][0];
            DEB(lis[t[i]][0])END
            DEB(ans)END
        }
        else{
            ans+=lis[t[i]][ok]-befindex;
            befindex=lis[t[i]][ok];
            DEB(lis[t[i]][ok])END
            DEB(ans)END
        }
    }
    cout<<ans<<endl;
}

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

int main() {
    while (true) {
        int px, py; cin >> px >> py;
        if (px==0) break;
        int n; cin >> n;
        bool dp[10][10];
        for (int i=0; i<10; i++) for (int j=0; j<10; j++) dp[i][j] = false;
        dp[py][px] = true;
        bool ndp[10][10];
        bool judge = true;
        
        for (int i=0; i<n; i++) {
            for (int j=0; j<10; j++) for (int k=0; k<10; k++) ndp[j][k] = false;
            for (int j=0; j<10; j++) {
                for (int k=0; k<10; k++) {
                    if (j-2>=0) for (int l=k-1; l<=k+1; l++) if (0<=l && l<10) ndp[j-2][l] |= dp[j][k];
                    if (j+2<10) for (int l=k-1; l<=k+1; l++) if (0<=l && l<10) ndp[j+2][l] |= dp[j][k];
                    if (k-2>=0) for (int l=j-1; l<=j+1; l++) if (0<=l && l<10) ndp[l][k-2] |= dp[j][k];
                    if (k+2<10) for (int l=j-1; l<=j+1; l++) if (0<=l && l<10) ndp[l][k+2] |= dp[j][k];
                }
            }
            
            int xi, yi; cin >> xi >> yi;
            swap(xi, yi);
            bool flag = false;
            
            for (int dx=-1; dx<=1; dx++) {
                for (int dy=-1; dy<=1; dy++) {
                    if (!(0<=xi+dx && xi+dx<10 && 0<=yi+dy && yi+dy<10)) continue;
                    if (ndp[xi+dx][yi+dy]) flag = true;
                }
            }
            
            judge &= flag;
            
            for (int j=0; j<10; j++) {
                for (int k=0; k<10; k++) {
                    if (!(xi-1<=j && j<=xi+1 && yi-1<=k && k<=yi+1)) ndp[j][k] = false;
                }
            }
            
            swap(dp, ndp);
        }
        
        cout << (judge ? "OK":"NA") << endl;
    }
}


Measured memory_bytes: 3008
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
string N;

int main() {
  INCANT;
  cin >> N;
  string ans = N=="ABC"?"ARC":"ABC";
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-


# 入力を整数に変換して受け取る
def input_int():
    return int(input())


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return map(int, input().split())


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    c = input()
    alphabet = "abcdefghijklmnopqrstuvwxyz"

    return alphabet[alphabet.index(c) + 1]


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ff(i,n) for(i=0;i<n;i++)
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg=998244353;
ll power(ll x,ll y)
{
	ll ss=1;
	if(y==0)
	return ss;
	ll h=(power(x,y/2))%bg;
	h=(h*h)%bg;
	ll gg=(x*h)%bg;
	if(y%2==1)
	 return gg;
	else
	 return h;
}
ll modinv(ll k)
{
	return (power(k,bg-2))%bg;
}
ll dp[500001];
int main()
{
    ll arr[3][3],i,j;
	string ans="No";
	for(i=0;i<3;i++)
	   for(j=0;j<3;j++)
	      cin>>arr[i][j];
	ll n;
	cin>>n;
	set<ll>set1;
	ff(i,n)
	{
	    ll x;
		cin>>x;
		set1.insert(x); 	
	}
	for(i=0;i<3;i++)
	{
	    ll f=0;
		for(j=0;j<3;j++)
		{
		    if(set1.find(arr[i][j])!=set1.end())
			   f++;	
		}
		if(f==3)
		   ans="Yes";	
	}
	for(i=0;i<3;i++)
	{
	    ll f=0;
		for(j=0;j<3;j++)
		{
		    if(set1.find(arr[j][i])!=set1.end())
			   f++;	
		}
		if(f==3)
		   ans="Yes";	
	}
	if(set1.find(arr[0][0])!=set1.end() && set1.find(arr[1][1])!=set1.end() && set1.find(arr[2][2])!=set1.end())
	    ans="Yes";
	if(set1.find(arr[0][2])!=set1.end() && set1.find(arr[1][1])!=set1.end() && set1.find(arr[2][0])!=set1.end())
	    ans="Yes";
	cout<<ans;			   
    return 0;
}

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]

a, b, c, x, y = MAP()
if c * 2 > a + b:
    print(a * x + b * y)
else:
    mn = min(x, y)
    mx = max(x, y)
    if x >= y:
        print(min(mn * c * 2 + (x - mn) * a, mx * c * 2))
    else:
        print(min(mn * c * 2 + (y - mn) * b, mx * c * 2))

Measured memory_bytes: 60268
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100500];
int flag[100500];
bool cmp(int a,int b){
    return a>b;
}
string sum(string s1,string s2)
{
    if(s1.length()<s2.length())
    {
        string temp=s1;
        s1=s2;
        s2=temp;
    }
    int i,j;
    for(i=s1.length()-1,j=s2.length()-1;i>=0;i--,j--)
    {
        s1[i]=char(s1[i]+(j>=0?s2[j]-'0':0));   //注意细节
        if(s1[i]-'0'>=10)
        {
            s1[i]=char((s1[i]-'0')%10+'0');
            if(i) s1[i-1]++;
            else s1='1'+s1;
        }
    }
    return s1;
}
string Mult(string s,int x)
{
    reverse(s.begin(),s.end());
    int cmp=0;
    for(int i=0;i<s.size();i++)
    {
        cmp=(s[i]-'0')*x+cmp;
        s[i]=(cmp%10+'0');
        cmp/=10;
    }
    while(cmp)
    {
        s+=(cmp%10+'0');
        cmp/=10;
    }
    reverse(s.begin(),s.end());
    return s;
}
string Multfa(string x,string y)  //大数乘法
{
    string ans;
    for(int i=y.size()-1,j=0;i>=0;i--,j++)
    {
        string tmp=Mult(x,y[i]-'0');
        for(int k=0;k<j;k++)
            tmp+='0';
        ans=sum(ans,tmp);
    }
    return ans;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",a+i);
    }
    memset(flag,0,sizeof(flag));
    sort(a,a+n,cmp);
    int x,y;
    x=y=0;
    int fg=0;
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]&&!flag[i]){
            if(!x) x=a[i];
            else{
                y=a[i];
                break;
            }
            flag[i]=1;
            flag[i+1]=1;
        }
    }
    char x1[15],y1[15];
    sprintf(x1,"%d",x);
    sprintf(y1,"%d",y);
    string s=Multfa(x1,y1);
    cout<<s<<endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

// {{{
template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar[0].size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

template<typename T>
T digitsum(T x){
    T y=0;
    while(x){
        y += x % 10;
        x /= 10;
    }

    return y;
}
// }}}
/* vim:set foldmethod=marker: */

int main(int argc, char const* argv[])
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    if (b <= c || d <= a) {
        cout << 0 << endl;
    }else{
        cout << min(b,d) - max(a,c) << endl;;
    }

    return 0;
}

// sortの仕方
// int a[N];
// array<int,N> ar;
// vector<int> v;
//
// sort(a, a+N); // 配列
// sort(ar.begin(), ar.end()); // array
// sort(v.begin(), v.end()); // vector 昇順
// sort(v.begin(), v.end(), greater<int>()); // 降順

// Template
// template <class T>
// T foomax(T x, T y){
//   if (x > y){
//     return x;
//   }else{
//     return y;
//   }
// }

// string を int に変換 stoi("1010")
// int を string に変換 to_string(1010)


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

int main() {
  long x,y;cin>>x>>y;
  long l = y/x;

  int cnt=0;
  while (l >= 1) {
    cnt++;
    l /= 2;
  }
  cout << cnt;
}


Measured memory_bytes: 256