akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();

        System.out.println(solve(N));

        sc.close();
    }

    static String solve(int N) {
        return (N <= 999) ? "ABC" : "ABD";
    }
}

Measured memory_bytes: 21844
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

a, b = na()

def f(x):
    if x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    elif x % 4 == 1:
        return x^(x-1)
    elif x % 4 == 2:
        return x^(x-1)^(x-2)

print(f(b) ^ f(a-1))


Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
from functools import reduce
import sys
import math
import bisect
import random
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return list(map(float, sys.stdin.readline().split()))
def LS():return sys.stdin.readline().split()
def SR(n): return [list(sys.stdin.readline())[:-1] for i in range(n)]
def IR(n): return [int(sys.stdin.readline()) for i in range(n)]
def LIR(n): return [list(map(int, sys.stdin.readline().split())) for i in range(n)]
def LSR(n): return [list(map(list, sys.stdin.readline().split())) for i in range(n)]
_gcd = lambda x, y: _gcd(y, x%y) if (x%y) else y
_lcm = lambda x, y: x*y // _gcd(x, y)
def gcd(*numbers):
    return reduce(_gcd, numbers)
def lcm(*numbers):
    return reduce(_lcm, numbers)
sys.setrecursionlimit(1000000)
INF = float('inf')
mod = 1000000007
dire4 = [(1,0), (0,1), (-1,0), (0,-1)]
dire8 = [(1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)]

N, D = LI()

print(N//(2*D+1)+(1 if N%(2*D+1) else 0))

Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin>>S.at(i);
  }
  for(int i=0;i<W+2;i++){
    cout<<'#';
  }
  cout<<endl;
  for(int i=0;i<H;i++){
    cout<<'#'<<S.at(i)<<'#'<<endl;
  }
      for(int i=0;i<W+2;i++){
    cout<<'#';
  }
      cout<<endl;
      }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;
ll dp[101][256][101];
ll a[101];
ll fact[101];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, x;
	cin>>n>>x;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	fact[0] = 1;
	for(int i = 1; i <= n; i++)
	{
		fact[i] = (ll(fact[i-1])*i)%MOD;
	}
	dp[0][0][0] = 1;
	dp[0][a[0]][1] = 1;
	for(int i = 1; i < n; i++)
	{
		for(int j = 0; j <= 255; j++)
		{
			dp[i][0][0] = 1;
			for(int k = 1; k <= n; k++)
			{
				dp[i][j][k] = (dp[i-1][j][k]+dp[i-1][(j^a[i])][k-1])%MOD;
			}
		}
	}	
	ll ans = 0;
	for(int i = 1; i <= n; i++)
	{
		ans = (ans + (fact[i]*dp[n-1][x][i])%MOD)%MOD;
	}	
	cout<<ans<<'\n';
}


Measured memory_bytes: 20352
n=int(input())
a=[]
ans=0
for i in range(n):
    a.append(int(input()))
    if(i>0 and a[-2]==1 and a[-1]>0):
        ans+=1
        a[-2]-=1
        a[-1]-=1
    ans+=a[-1]//2
    a[-1]=a[-1]%2
    if(i>0 and a[-2]==1 and a[-1]==1):
        ans+=1
        a[-2]-=1
        a[-1]-=1

print(ans)


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

int main() {
    ll X, Y;
    cin >> X >> Y;
    ll ans = 0;
    if (X == 1) {
        ans += 300000;
    } else if (X == 2) {
        ans += 200000;
    } else if (X == 3) {
        ans += 100000;
    }
    if (Y == 1) {
        ans += 300000;
    } else if (Y == 2) {
        ans += 200000;
    } else if (Y == 3) {
        ans += 100000;
    }
    if ((Y == 1) && (X == 1)) {
        ans += 400000;
    }
    cout << ans << endl;
    return 0;
}


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

A=list(list(map(int,input().split())) for _ in range(N))

v=100000*100000
flag=1
for i in range(1<<N):
  price=0
  P=[0 for _ in range(M)]
  for j in range(N):
    if (i>>j)&1==1:
      for k in range(M):
        P[k]+=A[j][k+1]
      price+=A[j][0]
  judge=True      
  for l in range(M):
    if X>P[l]:
      judge=False
      break
  if judge:
    flag=0
    v=min(v,price)

if flag:
  v=-1

print(v)
      

      

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

template<typename integer>
integer __lcm(integer a, integer b) {
  return (a * b) / __gcd(a, b);
}

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

  vector<int> a(n);
  rep (i, n) cin >> a[i];
  vector<int> b = a;
  sort(b.begin(), b.end());

  int mid = (n / 2) - 1;

  rep (i, n) {
    if (a[i] <= b[mid]) cout << b[mid+1] << endl;
    else cout << b[mid] << endl;
  }

  return 0;
}



Measured memory_bytes: 3712
k,n=map(int,input().split())
point=list(map(int,input().split()))
long=0
dist=0
for i in range(n-1):
  dist=point[i+1]-point[i]
  if dist>=long:
    long=dist
dist=k-point[n-1]+point[0]
if dist>=long:
  long=dist
print(k-long)

Measured memory_bytes: 26060
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

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

int main(void) {
	string s;
	cin >> s;
	for (int i = 1; s[i] != '\0'; ++i) {
		if (s[i] == s[i - 1]) {
			cout << "Bad" << endl;
			return 0;
		}
	}
	cout << "Good" << endl;
	return 0;
}

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

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> vec;
  int biggest = 0;
  rep(i, n){
    int num;
    cin >> num;
    biggest = max(biggest, num);
    vec.push_back(num);
  }
  int gcdNum = vec[0];
  for(int i=1; i<n; i++){
    gcdNum = gcd(gcdNum, vec[i]);
  }
  if(k % gcdNum == 0 && k <= biggest) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
  return 0;
}
  
  

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
template<typename T>inline T read(){
	T f=0,x=0;char c=getchar();
	while(!isdigit(c)) f=c=='-',c=getchar();
	while(isdigit(c)) x=x*10+c-48,c=getchar();
	return f?-x:x;
}
#define int long long
namespace run{
	const int N=131079;
	int head[N],nex[N],to[N],w[N],cnt;
	inline void add(int u,int v,int c){
		nex[++cnt]=head[u];
		head[u]=cnt,to[cnt]=v,w[cnt]=c;
	}

	typedef pair<int,int> P;
	typedef vector<P> Vec;
	inline Vec dfs(int u,int mid){
		if(!head[u]){
			Vec tmp;tmp.resize(1);tmp[0]=P(0,0);
			return tmp;
		}
		Vec L,R;
		for(int i=head[u],tot=0;i;i=nex[i],tot++)
			if(!tot){
				L=dfs(to[i],mid);
				for(int j=0;j<L.size();j++) L[j].first+=w[i],L[j].second+=w[i];
			}else{
				R=dfs(to[i],mid);
				for(int j=0;j<R.size();j++) R[j].first+=w[i],R[j].second+=w[i];
			}

		Vec retL,retR;
		for(int l=0,r=0;l<L.size() && r<R.size();l++){
			while(r+1<R.size() && L[l].second+R[r+1].first<=mid) r++;
			if(L[l].second+R[r].first<=mid) retL.push_back(P(L[l].first,R[r].second)),r++;
		}
		for(int r=0,l=0;r<R.size() && l<L.size();r++){
			while(l+1<L.size() && R[r].second+L[l+1].first<=mid) l++;
			if(R[r].second+L[l].first<=mid) retR.push_back(P(R[r].first,L[l].second)),l++;
		}

		Vec ret;
		for(int l=0,r=0;l<retL.size() || r<retR.size();){
			if(l<retL.size() && (r>=retR.size() || retL[l].first<retR[r].first)){
				if(!ret.size() || retL[l].second<ret[ret.size()-1].second) ret.push_back(retL[l]);
				l++;
			}else{
				if(!ret.size() || retR[r].second<ret[ret.size()-1].second) ret.push_back(retR[r]);
				r++;
			}
		}
		return ret;
	}

	int n;
	int main(){
		n=read<int>();
		int sum=0;
		for(int i=2;i<=n;i++){
			int fa=read<int>(),c=read<int>();
			add(fa,i,c),sum+=c;
		}
		int l=0,r=sum,ret;
		while(l<=r){
			int mid=(l+r)>>1;
			if(dfs(1,mid).size()>0) r=mid-1,ret=mid;
			else l=mid+1;
		}
		printf("%lld\n",ret);
		return 0;
	}
}
#undef int
int main(){
#ifdef my
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	return run::main();
}

Measured memory_bytes: 26096
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int n,x;
int main(void) 
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x%2==0)
		{
			if(x%3==0||x%5==0)
				continue;
			else
			{
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
    return 0;
}

Measured memory_bytes: 256
/*
日本でよく使われる紙幣は、10000 円札、5000 円札、1000 円札です。以下、「お札」とはこれらのみを指します。
青橋くんが言うには、彼が祖父から受け取ったお年玉袋にはお札が N 枚入っていて、合計で Y 円だったそうですが、嘘かもしれません。
このような状況がありうるか判定し、ありうる場合はお年玉袋の中身の候補を一つ見つけてください。
なお、彼の祖父は十分裕福であり、お年玉袋は十分大きかったものとします。
*/

#include <stdio.h>
#include <string.h>
#include <math.h>

#define LINE_BUF_SIZE 1024

int main(){

    int i,j,k;
    int length,first;
    long int N,Y;
    char line[LINE_BUF_SIZE];
    int count = 0;

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%ld %ld",&N,&Y);

    length = strlen(line);
    
    if(line[length-2] != '0' || line[length-3] != '0' || line[length-4] != '0'){    /*下3桁が0以外であったら終了*/
        printf("-1 -1 -1");
        return 0;
    }

    for(i=0;i<=N;i++){
        for(j=0;j<=N-i;j++){                /*i,jによって残りのkも決定されるため*/
            //for(k=0;k<=N-(i+j);k++){

                //printf("%d %d %d\n",i,j,k);

                if(10000*i+5000*j+1000*(N-i-j) == Y){
                    printf("%d %d %d",i,j,N-i-j);
                    return 0;
                }

            //}
        }
    }

    printf("-1 -1 -1");

    return 0;
}

Measured memory_bytes: 128
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <cstdlib>
#include <functional>

using namespace std;

int main(int argc, char* argv[]){
    long int N, A;
    cin >> N >> A;
    cout << N*N - A << endl;

    return 0;
}


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

constexpr char NL = '\n';
constexpr int MOD = 1e9 + 7;

struct safe_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

void solve()
{
    string n; cin >> n;
    int val = 0;
    for (char c : n) {
        val += c - '0';
    }
    cout << (val % 9 == 0 ? "Yes" : "No") << NL;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

typedef long long ll;

using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = a + b + c - max(a, max(b, c));

    cout << ans << endl;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 0;
  rep(i,n) {
    int h;
    cin >> h;
    if(h >= k){
      ans ++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
s = input()

d = defaultdict(int)

for i in s:
  d[i] += 1

if len(s) == 1:
  print ('YES')
  exit()
if len(d) == 1:
  print ('NO')
  exit()
if len(d) == 2:
  if len(s) == 2:
    print ('YES')
    exit()
  else:
    print ('NO')
    exit()


a = list(d.values())
if max(a) - min(a) < 2:
  print ('YES')
else:
  print ('NO')


Measured memory_bytes: 9280
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
	public static void main(String args[])throws IOException{
		Path2D.Double path = new Path2D.Double();;
		Point2D.Double[] p = new Point2D.Double[20];
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] splitLine = new String[2];
		int count=0;
		double a,b,c,z;
		double sum=0;
		
		for(int i=0;i<20;i++){
			p[i] = new Point2D.Double();
		}
		
		while(true){
			line = br.readLine();
			if(line == null || line.isEmpty())
				break;
			splitLine = line.split(",");
			p[count].setLocation(Double.parseDouble(splitLine[0]),Double.parseDouble(splitLine[1]));
			count++;
		}
		
		for(int i=0;i<count-2;i++){
			a=p[0].distance(p[i+1]);
			b=p[i+1].distance(p[i+2]);
			c=p[i+2].distance(p[0]);
			z=(a+b+c)/2;
			sum+=Math.sqrt(z*((z-a)*(z-b)*(z-c)));
		}
		
		System.out.printf("%.6f\n",sum);
	}
}

Measured memory_bytes: 16928
#include <iostream>

using namespace std;

int main()
{
    int n,v[1001],i,s=0;

   cin>>n;
   for (int i=1;i<=n;i++)
    {cin>>v[i];s+=v[i];}

   for (int i=1;i<=n;i++)
    for (int j=i+1;j<=n;j++)
      if (v[i]>v[j]) swap (v[i],v[j]);


    int smax=0,sref=0,j=1,x=0,ok=1;

    if (s%10) smax=s;
    else
      {

       if (s%10==0)
           for (int k=1;k<=n;k++)
           if (v[k]%10) {x=v[k]; ok=0;break;}
   if (!ok)
    smax=s-x;
    else
        smax=0;
      }
    cout<<smax<<endl;

    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
ws = []
n.times do
  ws << gets.chomp
end

def shiritori(n,ws)
  (n-1).times.with_index do |i|
    return false if ws[i].[](-1) != ws[i+1].[](0)
  end
  true
end

def duplicate_check(ws)
  return true if ws.length == ws.uniq.length
  false
end

if shiritori(n,ws)  && duplicate_check(ws)
  puts 'Yes'
else
  puts 'No'
end


Measured memory_bytes: 1788
#include <cstdio>
const int N = 2005, mod = 924844033;
int n = 0, k = 0;
int a[N], fac[N];
long long f[N][N][2][2];
bool vis[N];
int main() {
	scanf("%d%d", &n, &k);
	fac[0] = 1;
	for (int i = 1; i <= n; ++i)
		fac[i] = 1LL * fac[i - 1] * i % mod;
	int tot = 0;
	a[0] = -0x7fffffff;
	for (int i = 1; i <= n; ++i)
		if (!vis[i])
			for (int j = i; j <= n; j += k)
				vis[j] = 1, a[++tot] = j;
	f[0][0][0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		f[i][0][0][0] = 1;
		for (int j = 1; j <= i; ++j) {
			f[i][j][0][0] = (f[i - 1][j][1][0] + f[i - 1][j][0][0] + (a[i] - a[i - 1] == k) * f[i - 1][j - 1][0][0]) % mod;
			f[i][j][0][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][1][0] + f[i - 1][j - 1][0][0]) % mod;
			f[i][j][1][0] = (f[i - 1][j][0][1] + f[i - 1][j][1][1] + (a[i] - a[i - 1] == k) * f[i - 1][j - 1][0][1]) % mod;
			f[i][j][1][1] = (a[i + 1] - a[i] == k) * (f[i - 1][j - 1][0][1] + f[i - 1][j - 1][1][1]) % mod;
		}
	}
	int ans = 0;
	for (int i = 0; i <= n; ++i) {
		int sum = (f[n][i][0][0] + f[n][i][0][1] + f[n][i][1][0] + f[n][i][1][1]) % mod;
		if (i & 1)
			(ans += mod - (long long)sum * fac[n - i] % mod) %= mod;
		else
			(ans += (long long)sum * fac[n - i] % mod) %= mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 73448
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+9;
int n;
int a[maxn];
int init(){
    cin>>n;
    for(int i=0;i<n;++i)cin>>a[i];
}
int solve(){
    multiset <int> s;
    #define itr multiset <int> :: iterator
    int c=0;
    for(int i=0;i<n;++i){
        int x=a[i];
        itr p=s.lower_bound(x);
        if(p==s.begin()){
            c++;
            s.insert(x);
        }else{
            --p;
            s.insert(p,x);
            s.erase(p);
        }
    }
    return c;
}
int main(){
	init();
	cout<<solve()<<endl;
    return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vvl G(101010);
vl dp(101010,-1);

ll dfs(ll u){
    if(dp[u] != -1) return dp[u];
    vl res;
    for(auto v : G[u]){
        res.push_back(dfs(v));
    }
    if(res.empty()) return dp[u] = 0;
    else{
        sort(rall(res));
        rep(i,res.size()) res[i] += i+1;
        return dp[u] = *max_element(all(res));
    }
}

int main(){
    ll n; cin >> n;
    rep(i,n-1){
        ll a; cin >> a; a--;
        G[a].push_back(i+1);
    }
    cout << dfs(0) << endl;
}

Measured memory_bytes: 19072
#include <stdio.h>
 
void cut(int* cards,int n,int k) {	//	カット処理
    int result[200];
    int i;
    for(i=0;i<k;i++) {
        result[2*n-k+i]=cards[i];
    }
    for(i=k;i<2*n;i++) {
        result[i-k]=cards[i];
    }
    for(i=0;i<n*2;i++) {
        cards[i]=result[i];
    }
}
 
void rf(int* cards,int n) {//リフルシャッフル
    int result[200];
    int i;
    for(i=0;i<n;i++) {
        result[i*2]=cards[i];
        result[i*2+1]=cards[i+n];
    }
    for(i=0;i<n*2;i++) {
        cards[i]=result[i];
    }
}
 
int main(void) {
    int cards[200];
    int i,n,m,k;
    scanf("%d",&n);
    scanf("%d",&m);
    for(i=0;i<n*2;i++)cards[i]=i+1;
    for(i=0;i<m;i++) {
        scanf("%d",&k);
        if(k==0)rf(cards,n);
        else cut(cards,n,k);
    }
    for(i=0;i<n*2;i++)printf("%d\n",cards[i]);
    return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[20];
int main()
{
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(len<3) puts("No");
	else
	{
		if(s[1]=='Y'&&s[2]=='A'&&s[3]=='K'&&s[4]=='I') puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1000000007;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n);
  map<ll, ll> M;
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    M[a[i]] = 1;
  }
  vector<ll> dp(n + 2);
  dp[0] = 0;
  dp[1] = 1;

  if (M[1] == 1 && M[2] == 1) {
    cout << 0 << endl;
    return 0;
  }

  for (int i = 2; i <= n + 1; i++) {
    if (M[i - 1]) {
      dp[i] = 0;
      continue;
    }
    if (dp[i - 1] == 0 && dp[i - 2] == 0) {
      cout << 0 << endl;
      return 0;
    }
    // if (i - 1 != 3) { dp[i] += dp[i - 1]; }
    // if (i - 2 != 3) { dp[i] += dp[i - 2]; }
    dp[i] = (dp[i - 1]) % MOD + dp[i - 2] % MOD;
  }
  cout << dp[n + 1] % MOD << endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;

  vll sum(N);

  ll count = 0;
  rep(i, N) {
    if (i == 0) {
      sum[0] = 0;
    }
    if (S[i - 1] == 'A' && S[i] == 'C') {
      count++;
    }
    sum[i] = count;
  }

  rep(i, Q) {
    ll l, r;
    cin >> l >> r;
    l--;
    r--;
    COUT(sum[r] - sum[l]);
  }

  return 0;
}

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

ll lcm(ll a, ll b)
{
    ll t = __gcd(a, b);
    return t ? (a / t * b) : 0;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  int n;cin>>n;
  ll res=0;
  for(int i=0;i<n;i++){
    ll t;cin>>t;
    if(i==0){
      res=t;
    }else{
      res=lcm(res, t);
    }
  }
  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
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: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
	ll n; cin >> n;
	ll ans = 1e9;
	for(ll i = 0; i < n; ++i){
		ll a; cin >> a;
		ll tmp = 0;
		while(!(a & 1)){
			a /= 2;
			tmp++;
		}
		ans = min(tmp, ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
def num2alpha(num):
    if num <= 26:
        return chr(96+num)
    elif num % 26 == 0:
        return num2alpha(num//26-1)+chr(90)
    else:
        return num2alpha(num//26)+chr(96+num % 26)


n = int(input())
ans = num2alpha(n)
print(ans.lower())


Measured memory_bytes: 9092
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		while(true){
			int x = in.nextInt();
			int h = in.nextInt();
			if(x + h == 0)break;
			double x2 = x;
			double h2 = h;
			double S = x2*x2 +2*x2*Math.sqrt((x2*x2)/4+h2*h2);
			System.out.println(S);
		}
	}
}

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

using namespace std;

typedef long long ll;

const ll INF = 1e18;
const int N = 3005;

ll a[N], dp[N][N];

ll fun(int L, int R) {
  if (L > R) return 0;
  if (L == R) return a[L];
  ll &ret = dp[L][R];
  if (ret != -INF) return ret;
  ret = max(ret, a[L] - fun(L + 1, R));
  ret = max(ret, a[R] - fun(L, R - 1));
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dp[i][j] = -INF;
    }
  }
  cout << fun(0, n - 1) << endl;
  return 0;
}


Measured memory_bytes: 70912
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
inline void _read(int &x)
{
	x = 0;
	char t = getchar();
	while (!isdigit(t)) t = getchar();
	while (isdigit(t))
	{
		x = x * 10 + t - '0';
		t = getchar();
	}
}
 
const int MAXN = 1e5 + 10;
int n, ans;
pair <int, int> in[MAXN];
 
int main()
{
	_read(n);
	for (register int i = 0; i < n; i++)
	{
		_read(in[i].first);
		in[i].second = i;
	}
	sort(in, in + n);
	for (register int i = 0; i < n; i += 2)
	{
		if(in[i].second & 1 != i & 1)
			ans++;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  cout << n << ':';
  for (int i = 2; i * i <= n; i++){
    if (n % i == 0){
      while (n % i == 0){
        cout << ' ' << i;
        n /= i;
      }
    }
  }
  if (n != 1){
    cout << ' ' << n;
  }
  cout << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vi a;

int main(){
	cin>>n;
	a=vi(n);
	for(auto &i:a) cin>>i;
	int res=0,I=0;
	for(int i=1;i<n;i++) if(a[i-1]<a[i]){
		res=max(res,i-I);
		I=i;
	}
	res=max(res,n-I);
	cout<<res-1<<endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int d1, d2; cin >> d1 >> d2;
    if (d1 == d2) ++cnt;
    else          cnt = 0;

    if (cnt >= 3) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vi> dp(n+2, vi(m+2));
    rep(i, n+1) rep(j, m+1) {
        // cout << i << " " << j << endl;
        if(i >= n) {
            chmax(dp[i][j+1], dp[i][j]);
        }
        else if(j >= m) {
            chmax(dp[i+1][j], dp[i][j]);
        }
        else if(s[i] == t[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
        else {
            chmax(dp[i+1][j], dp[i][j]);
            chmax(dp[i][j+1], dp[i][j]);
        }
    }
    cout << dp[n][m] << '\n';
    // rep(i, n+2) {
    //     rep(j, m+2) {
    //         cout << " " << dp[i][j];
    //     }
    //     cout << endl;
    // }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i, n) solve();
    return 0;
}


Measured memory_bytes: 6868
#include <utility>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <numeric>
#include <limits>
#include <queue>
#include <cstdint>
#include<iomanip>
#define ll long long int
#define rep(i,rept) for (int (i) = 0; (i) < rept; (i)++)
#define rept(i,n,rept) for (int (i) = n; (i) < rept; (i)++)
#define Yes(b) std::cout<< (b ? "Yes" : "No")<<std::endl
#define YES(b) std::cout<< (b ? "YES" : "NO")<<std::endl
#define fr first
#define se second
#define lolo 92233720368547757
#define susu 1000000007
typedef std::pair<int, int> pp;
typedef std::pair<ll, ll> llpp;
using namespace std;
int main() {
	int k;
	map<string, bool> m = {};
	vector<string> v = {};
	string  s,str;
	cin >> s >> k;
	rep(i, s.size()) {
		rep(j, 5) {
			if (i + j + 1 <= s.size()) {
				str = s.substr(i, j + 1);
				if (!m[str]) {
					v.emplace_back(str);
					m[str] = true;
				}

			}
			else {
				break;
			}
		}
	}
	sort(v.begin(), v.end());
	cout << v[k-1];
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 1000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio	
	int n;
	cin >> n;
	int a[n];
	std::vector<int> v;
	for(int i=0; i<n; i++){
		cin >> a[i];
		v.push_back(a[i]);
	}
	sort(v.begin(),v.end());
	for(int i=0; i<n; i++){
		if(a[i]==v[n-1])cout << v[n-2] << endl;
		else
			cout << v[n-1] << endl;
	}
	return 0;
}








Measured memory_bytes: 5076
import numpy as np

#l,rまでの配列に+1する関数
def give_water(flower, lr):
    flower_with_water = [x+1 if i>=lr[0] and i<=lr[1] else x for i,x in enumerate(flower)]
    return flower_with_water

def TF_list(flower, h):
    h = np.array(h)
    TF_list_0 = []
    for i in range(len(flower)):
        TF_list_0.append(flower[i] < h[i])
    return TF_list_0

#Trueが連続しているindexの範囲を[(0, 1), (2,4)]みたいな形で出力
def list_tuple_True(flower, h, N):
    TF_list = (flower < h)
    TF_list = np.insert(TF_list, N, False)
    True_range = []
    #FLAGは一つ前のTFを表す。初期値はFalse
    FLAG = False
    for i, TF in enumerate(TF_list):
        if TF:
            if FLAG:
                #Trueが連続している場合
                pass
            else:
                #FalseからTrueに切り替わった場合
                start = i
        else:
            if FLAG:
                #TrueからFalseも切り替わった場合
                end = i-1
                True_range.append((start, end))
            else:
                #Falseが連続している場合
                pass
        FLAG = TF
    return True_range
            
N = int(input())
h = list(map(int, input().split()))

h = np.array(h)
flower = np.zeros(N)

count = 0
while not((h == flower).all()):
    water_range = list_tuple_True(flower, h, N)
    count += len(water_range)
    for lr in water_range:
        flower = give_water(flower, lr)
        
print(count)
        


Measured memory_bytes: 21056
import scala.io.Source
import scala.collection.mutable.Map

object Main {
  def main(args: Array[String]) = {
    val lines = Source.stdin.getLines.toStream
    val inSeq = lines.drop(1).head.split(' ').map(_.toLong)

    println(dp(inSeq))
  }

  def dp(input: Array[Long]): Long = {
    val memo = Array.ofDim[Long](input.length + 1, input.length + 1, 2)

    (1 to input.length).foreach { n =>
      memo(n-1)(n)(0) = input(n-1)
      memo(n-1)(n)(1) = 0
    }

    (2 to input.length).foreach { area =>
      (2 to area).foreach { tgLen =>
        var locMin = Long.MaxValue
        var cost = 0L
        ((area - tgLen + 1) to (area - 1)).reverse.foreach { split =>
          var cand = memo(area - tgLen)(split)(1) + memo(split)(area)(1)
          if (cand <= locMin) {
            locMin = cand
            cost = memo(area - tgLen)(split)(0) + memo(split)(area)(0)
          }
        }
        memo(area - tgLen)(area)(0) = cost
        memo(area - tgLen)(area)(1) = locMin + cost
      }
    }
    memo(0)(input.length)(1)
  }
}


Measured memory_bytes: 45284
from sys import stdin

N = int(stdin.readline().rstrip())
A = [0] * 100

for n in range(1, N + 1):
    i = 2
    while n > 1:
        if n % i == 0:
            n //= i
            A[i] += 1
        else:
            i += 1

x = len([x for x in A if x >= 4])
y = len([x for x in A if x >= 2])
z = len([x for x in A if x >= 14])
w = len([x for x in A if x >= 4])
a = len([x for x in A if x >= 24])
b = len([x for x in A if x >= 2])

print(((x * (x - 1)) // 2) * (y - 2) + z * (w - 1) + a * (b - 1) + len([x for x in A if x >= 74]))


Measured memory_bytes: 38512
#include <stdio.h>

int main(){
  int A,B;
  scanf("%d %d",&A,&B);
  A=(A+11)%13;
  B=(B+11)%13;
  if(A>B) printf("Alice\n");
  else if(A<B) printf("Bob\n");
  else printf("Draw\n");
  return 0;
}

Measured memory_bytes: 1660
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <fstream>
using namespace std;
double pie=3.14159265358979;
long long mod=1000000007;
//

int main(){
	int d;
	int c[26];
	cin>>d;
	for(int i=0;i<26;i++){
		cin>>c[i];
	}
	int s[365][26];
	for(int i=0;i<d;i++){
		for(int j=0;j<26;j++){
			cin>>s[i][j];
		}
	}
	int t[365];
	int con[26][366]={};
	long long ans=0;
	for(int i=0;i<d;i++){
		cin>>t[i];
		t[i]--;
		con[t[i]][i]=1;
		ans+=s[i][t[i]];
	}
	for(int i=0;i<26;i++){
		con[i][d]=1;
	}
	int me=-1;
	for(int i=0;i<26;i++){
		me=-1;
		for(int j=0;j<=d;j++){
			if(con[i][j]==1){
				if(me==-1){
					me=j;
					ans-=c[i]*j*(j+1)/2;
				}else{
					me++;
					ans-=c[i]*(j-me)*(j-me+1)/2;
					me=j;
				}
			}
		}
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++){
		int dd,qq;
		cin>>dd>>qq;
		dd--;
		qq--;
		ans-=s[dd][t[dd]];
		ans+=s[dd][qq];
		me=-1;
		for(int j=0;j<=d;j++){
			if(con[t[dd]][j]==1){
				if(me==-1){
					me=j;
					ans+=c[t[dd]]*j*(j+1)/2;
				}else{
					me++;
					ans+=c[t[dd]]*(j-me)*(j-me+1)/2;
					me=j;
				}
			}
		}
		me=-1;
		con[t[dd]][dd]=0;
		for(int j=0;j<=d;j++){
			if(con[t[dd]][j]==1){
				if(me==-1){
					me=j;
					ans-=c[t[dd]]*j*(j+1)/2;
				}else{
					me++;
					ans-=c[t[dd]]*(j-me)*(j-me+1)/2;
					me=j;
				}
			}
		}
		me=-1;
		t[dd]=qq;
		for(int j=0;j<=d;j++){
			if(con[t[dd]][j]==1){
				if(me==-1){
					me=j;
					ans+=c[t[dd]]*j*(j+1)/2;
				}else{
					me++;
					ans+=c[t[dd]]*(j-me)*(j-me+1)/2;
					me=j;
				}
			}
		}
		me=-1;
		con[t[dd]][dd]=1;
		for(int j=0;j<=d;j++){
			if(con[t[dd]][j]==1){
				if(me==-1){
					me=j;
					ans-=c[t[dd]]*j*(j+1)/2;
				}else{
					me++;
					ans-=c[t[dd]]*(j-me)*(j-me+1)/2;
					me=j;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;
typedef long long ll;

int main(){
  string o, e;
  cin>>o>>e;
  if(o.size()==e.size()){
    for(int i=0; i<o.size(); ++i){
      cout<<o[i]<<e[i];
    }
  }else{
    for(int i=0; i<e.size(); ++i){
      cout<<o[i]<<e[i];
    }
    cout<<o[o.size()-1];
  }
  cout<<endl;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    ll X; cin >> X;
    ll money = 100;
    int year = 0;
    while(true){
        money = money + money/100;
        year++;
        if(money >= X){
            cout << year << endl;
            break;
        }
    }
}

Measured memory_bytes: 3636
import java.util.LinkedList;	//ArrayListだと間に合わない
import java.util.ListIterator;
import java.util.Scanner;

class Main {
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) {

		LinkedList<Integer> list = new LinkedList<>();
		ListIterator<Integer> ite = list.listIterator();

		int n = scan.nextInt();

		for(int i=0; i<n; i++) {
			int query = scan.nextInt();

			switch(query) {

			case 0:
				int a = scan.nextInt();

				ite.add(a);
				ite.previous();
				break;

			case 1:
				int b = scan.nextInt();
				if(0 <= b) {
					for(int j=0; j<b; j++) {
						ite.next();
					}
				}else {
					for(int j=0; j>b; j--) {
						ite.previous();
					}
				}
				break;

			case 2:
				ite.next();
				ite.remove();
				break;
			}
		}

		for(Integer a : list) {
			System.out.println(a);
		}
	}
}


Measured memory_bytes: 309968
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            for(int k = 1; k <= n; ++k){
                int foo = gcd(i, j);
                foo = gcd(foo, k);
                ans += foo;
            }
        }
    }
    cout << ans << endl;
}

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

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, k;
    cin >> n >> k;
    vector<mint> p(k);
    mint ans = 0;
    rep1r(i, k) {
        mint t = k / i;
        t = t.pow(n);
        for (int j=i*2; j<=k; j+=i) t -= p[j-1];
        ans += t * i;
        p[i-1] = t;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4056
#include<stdio.h>

int main(void) {

	/*Aさんの点数*/
	int A1,A2,A3,A4;
	/*Bさんの点数*/
	int B1,B2,B3,B4;

	int S,T;
	S = 0;
	T = 0;

	scanf("%d %d %d %d",&A1,&A2,&A3,&A4);
	scanf("%d %d %d %d",&B1,&B2,&B3,&B4);

	/*合計を計算する*/
	S = A1 + A2 + A3 + A4;
	T = B1 + B2 + B3 + B4;

	if(T < S) {
		printf("%d\n",S);
	}
	else {
		printf("%d\n",T);
	}
	return 0;
}

Measured memory_bytes: 592
#include <iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(b >= c){
		cout << "delicious" << endl;
	}
	else{
		if(a+b >= c){
			cout << "safe" << endl;
		}
		else{
			cout << "dangerous" << endl;
		}
	}
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int sets = scan.nextInt(), queries = scan.nextInt();
        UnionFind uf = new UnionFind(sets);
        for(int i = 0; i < queries; i++){
            if(scan.nextInt() == 0) uf.union(scan.nextInt(), scan.nextInt());
            else System.out.println(uf.same(scan.nextInt(), scan.nextInt()) ? 1 : 0);
        }
    }
}

class UnionFind{
    int ufarr[];
    UnionFind(int sets){
        ufarr = new int[sets];
        for(int i = 0; i < sets; i++) ufarr[i] = i;
    }

    int find(int x){
        while(ufarr[x] != x) x = ufarr[x];
        return x;
    }

    int union(int x, int y){
        int x_ = find(x), y_ = find(y);
        if(x_ != y_){
            ufarr[x_] = y_;
            return 0;
        }
        return 1;
    }

    boolean same(int x, int y){
        return find(x) == find(y);
    }
}

Measured memory_bytes: 76864
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    sort(all(A));
    int low = -1, high = N - 1;
    while (high - low > 1) {
        int mid = (low + high) / 2;

        bool b = true;
        ll s = A[mid];
        for (int i = 0; i < N; ++i) {
            if (i == mid) continue;

            if (s * 2 >= A[i]) {
                s += A[i];
            }
            else {
                b = false;
                break;
            }
        }

        if (b) high = mid;
        else low = mid;
    }

    write(N - high);
}

Measured memory_bytes: 640
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;
typedef pair<char,int> P;
int N,Q;
int mark[100001];
int tree[100001];
P query[100001];
 
int get(int i){
  if(mark[i])return i;
  return tree[i]=get(tree[i]);
}
 
int main() {
  while(scanf("%d%d",&N,&Q),N|Q){
    memset(mark,0,sizeof(mark));
    mark[0]=1;
    for(int i=1;i<N;i++){
      scanf("%d",tree+i);
      tree[i]--;
    }
    for(int i=0;i<Q;i++){
      scanf(" %c%d",&query[i].first,&query[i].second);
      query[i].second--;
    }
    for(int i=0;i<Q;i++){
      if(query[i].first=='M'){
        mark[query[i].second]+=1;
      }
    }
 
    long long c=0;
    for(int i=Q-1;i>=0;i--){
      if(query[i].first=='M'){
        mark[query[i].second]-=1;
      }else{
        c+=get(query[i].second)+1;
      }
    }
    printf("%lld\n",c);
  }
}

Measured memory_bytes: 2748
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int N;
  cin>>N;
  string s;
  cin>>s;
  int ans = 0;
  for(int i = 0;i<N-1;i++){
    if(s.at(i) != s.at(i+1)){
      ans++;
    }
  }
  cout << ans+1 << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
int mod;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { for (auto &vi: vec) os << vi << " "; return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T >inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

    int T;
    // cin >> T;
    T = 1;

    while (T--) {
        solve();
    }
}

template<typename T>
vector<T> lis(vector<T> a) {
  vector<T> b;
  b.eb(a[0]);
  rep3(i, 1, sz(a)) {
    int it = lb(b, a[i]);
    if (it == sz(b)) {
      b.eb(a[i]);
    } else {
      b[it] = a[i];
    }
  }
  return b;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  
  rep(i, n) rep3(j, i, n) {
    vector<int> b = a;
    swap(b[i], b[j]);
    auto v = lis(b);
    if (sz(v) == n) { cout << "YES" << endl; return; }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256