akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>
#include <cctype>
#include <stdio.h>
#include <cstdlib>
#include <algorithm>

using namespace std;
int n;
string t[1000];
string h[1000];
int T;
int H;

bool comp(string s, string t) {
	if (s.front() - t.front() < 0) return true;
	else if (s.front() - t.front() > 0) return false;
	else {
		s.erase(s.begin());
		t.erase(t.begin());
		return comp(s, t);
	}
}

int main() {
	T = 0; H = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> t[i] >> h[i];
	}
	for (int i = 0; i < n; i++) {
		if (t[i] == h[i]) {
			T++;
			H++;
		}
		else {
			if (comp(t[i], h[i])) H += 3;
			else T += 3;
		}
	}
	cout << T << ' ' << H << endl;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
//const int MOD = (int) 1e9 + 7;
const int MOD = 119 << 23 | 1;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-6;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
inline int mrand(int k) {return abs((int) mt()) % k;}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    int n, m; cin >> n >> m;
    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << "\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
using namespace std;
ll mod = 1000000007;
ll INF = 1000000000000000000;
ll n, k;
ll a[101];
ll v[101];
ll w[101];
ll dp[101][100001];
ll lim;

ll foo(ll idx, ll val)
{

	if (idx == n)
	{
		if (val >= lim) return 0;
		return INF;
	}

	if (dp[idx][val] != -1) return dp[idx][val];

	ll res = 0;
	ll v1 = w[idx] + foo(idx + 1, val + v[idx]);
	ll v2 = foo(idx + 1, val);
	res = min(v1, v2);
	return dp[idx][val] = res;
}


void solve(int t)
{
	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> w[i] >> v[i];
	}
	ll s = 0;
	for (int i = 0; i < n; i++) s += v[i];

	ll lo = 0;
	ll hi = s;
	ll ans;
	ll mid;

	//lim = 140;
	//cout << foo(0, 0) << endl;
	while (lo <= hi)
	{
		mid = (lo + hi) / 2;
		lim = mid;

		memset(dp, -1, sizeof(dp));
		if (foo(0, 0) <= k)
		{
			ans = mid;
			lo = mid + 1;
		}
		else
		{
			hi = mid - 1;
		}
	}

	cout << ans << endl;

}

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




	int t = 1;
	//cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
}


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

int main() {
    ll n;
    cin >> n;
    vector<int> vec;
    while(true){
        vec.push_back(n%26);
        n=(n-1)/26;
        if(n==0) break;        
    }
    rep(i,vec.size()){
        int a=vec[vec.size()-i-1];
        if(a==0) a=26;
        char c='a'-1+a;

        cout << c;
    }

}

Measured memory_bytes: 3564
/*
    Problem 3
    https://atcoder.jp/contests/abc106/tasks/abc106_b
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
/* global variables */
vector<char> C = {'A', 'C', 'T', 'G'};
/* function */
/* main */
int main(){
    string S;
    cin >> S;

    int ans = 0;
    int l = 0, r = 0;
    while (r < S.size()) {
        r++;
        if (count(C.begin(), C.end(), S[r - 1]))
            ans = max(ans, r - l);
        else
            l = r;
    }

    cout << ans << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  int ans=100005;

  int c=0;
  string ss;
  ss=s;
  if(s[0]!='0'){
    c++;
    ss[0]='0';
  }
  rep(i,ss.size()-1){
    if(ss[i]==ss[i+1]){
      c++;
      if(ss[i]=='0')
      ss[i+1]='1';
      else
      ss[i+1]='0';
    }
  }

  ans=min(ans,c);
  c=0;

  ss=s;
  if(s[0]!='1'){
    c++;
    ss[0]='1';
  }
  rep(i,ss.size()-1){
    if(ss[i]==ss[i+1]){
      c++;
      if(ss[i]=='0')
      ss[i+1]='1';
      else
      ss[i+1]='0';
    }
  }
  ans=min(ans,c);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 512
a = []
for x in range(3):
    a.append(list(map(int, input().split())))
row = [0] * 3
col = [0] * 3
sli = [0] * 2

c = [[False] * 3 for _ in range(3)]
n = int(input())
for _ in range(n):
    b = int(input())
    for x in range(3):
        for y in range(3):
            if a[x][y] == b:
                c[x][y] = True
flag = False
for i in range(3):
    if c[i].count(True) == 3:
        flag = True
    if c[0][i] == c[1][i] == c[2][i] == True:
        flag = True
if c[0][0] == c[1][1] == c[2][2] == True:
    flag = True
if c[0][2] == c[1][1] == c[2][0] == True:
    flag = True

print("Yes" if flag else "No")


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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 100000;
const int K = 100000;
int n, k;
int w[N], t[K];

bool check(int limit) {
  int i, j;
  
  for (i=0; i<n; i++)
    if (limit < w[i]) return false;

  memset(t, 0, sizeof(t));
  i = j = 0;
  while (i<n && j<k) {
    if (t[j] + w[i] < limit) 
      t[j] += w[i++];
    else if (t[j] + w[i] == limit)
      t[j++] += w[i++];
    else
      j++;
  }

  return (i==n) ? true : false;
}

int main() {
  int i;
  scanf("%d%d ", &n, &k);
  for (i=0; i<n; i++)
    scanf("%d ", w+i);

  int l = 0, u = 0;
  for (i=0; i<n; i++) u += w[i];
  while (u-l > 1) {
    int m = (l+u)/2;
    if (check(m))
      u = m;
    else
      l = m;
  }
  printf("%d\n", u);
  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	char c; cin >> c;
	if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') cout << "vowel\n";
	else cout << "consonant" << endl;
	return 0;
}


Measured memory_bytes: 3648
#include<iostream>
using namespace std;
int main(void){
    int w,h,x,y,r;
    int i,j;
    cin>>w>>h>>x>>y>>r;
    if(x-r<0||x+r>w||y-r<0||y+r>h){
        cout<<"No"<<endl;
    }else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)

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

//------------------------------------------------
int main(){
  int n;
  double a[110];
  double b[110];
  double ans;
  ans=0;
  cin>>n;
  rep(i,0,n){
  cin>>a[i];
  b[i]=1/a[i];
  ans+=b[i];
}
  cout<<1/ans<<endl;
}


Measured memory_bytes: 256
def main():
    n,k = map(int,input().split())
    A = list(map(int,input().split()))

    left = 0
    right = max(A)

    while abs(right-left)>1:
        cent = (right+left)//2
        
        ct = 0
        for a in A:
            ct+=a//cent
            if a%cent==0:
                ct-=1
        
        if ct <= k:
            right=cent
        else:
            left=cent
    
    print(right)
main()


Measured memory_bytes: 30668
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int H, W, A, B; std::cin >> H >> W >> A >> B;
	rep(i, H){
		rep(j, W) {
			if (i <= H - B - 1) {
				if (j <= W - A - 1)std::cout << 0;
				else std::cout << 1;
			}
			else {
				if (j <= W - A - 1)std::cout << 1;
				else std::cout << 0;
			}
		}
		std::cout << "\n";
	}

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 1280
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  int n;
  cin >> n;
  vvi graph(n,vi(n,0));
  REP(i,n){
    int k;
    cin >> k >> k;
    REP(j,k){
      int tmp;
      cin >> tmp;
      graph[i][tmp-1]++;
    }
  }
  REP(i,n){
    cout << graph[i][0];
    FOR(j,1,n){
      cout << " " << graph[i][j];
    }
    cout << endl;
  }
}



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

typedef pair<int, char> Pair;

int n;
set<Pair, greater<Pair> > order;
map<char, int> num;

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) return 0;

    order.clear();
    num.clear();
    for (int i=0; i<26; i++) {
      order.insert(Pair(0, 'A'+i));
      num['A'+i] = 0;
    }

    bool yet = true;
    int ans;
    for (int i=1; i<=n; i++) {
      char c;
      scanf(" %c", &c);

      if (yet) {
        order.erase(Pair(num[c], c));
        num[c] += 1;
        order.insert(Pair(num[c], c));
        auto itr = order.begin();
        int m = itr->first;
        itr++;
        int g = itr->first;
        if (m > g+n-i) {
          ans = i;
          yet = false;
        }
      }
    }

    if (yet) puts("TIE");
    else printf("%c %d\n", order.begin()->second, ans);
  }
}

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

const int limit = 1e6;
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    vector<bool> ng(limit+1, false);
    sort(a.begin(), a.end());
    for(int i=0; i<n-1; i++){
        if(a[i] == a[i+1]){
            ng[a[i]] = true;
        }
    }
    a.erase(unique(a.begin(), a.end()), a.end());
    
    int ans = 0;
    for(int i: a){
        if(!ng[i]) ans++;
        for(int j=i; j<=limit; j+=i){
            ng[j] = true;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4312
'''
.append(要素) リストに要素を追加 
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul

print('x'*len(stdin.readline().rstrip()))


Measured memory_bytes: 38384
N = int(input())
A = set(map(int, input().split()))

while len(A) > 1:
    minA = min(A)
    tempA = set()
    tempA.add(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.add(mod)
    A = tempA

print(list(A)[0])

Measured memory_bytes: 20012
from itertools import product
import numpy as np
N, M, X = map(int, input().split())
CA = np.array([input().split() for _ in range(N)], dtype=np.int64)
C = CA[:, 0]
A = CA[:, 1:]

inf = 10**18
ans = inf
for p in product(range(2), repeat=N):
    p = np.array(p)
    ok = (p[:, None] * A).sum(axis=0)
    if (ok >= X).all():
        cost = (p * C).sum()
        ans = min(ans, cost)

if ans >= inf:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 27320
#include <iostream>

using namespace std;

int main()
{
    string s ,t;
    cin >>s >>t;
    int x = stoi (s + t);
    for ( int i =1; i <=1000; i ++){
        if ( i*i == x ){
            puts ("Yes");
            return 0;
        }
    }
    puts ("No");
}


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

const int MOD = 1e9 + 7;

main() {
  int n, m; cin >> n >> m;
  ll xsum = 0;
  rep(i, n) {
    ll x; cin >> x;
    xsum = (xsum + (2 * (i + 1) - n - 1) * x % MOD) % MOD;
  }
  ll ysum = 0;
  rep(i, m) {
    ll y; cin >> y;
    ysum = (ysum + (2 * (i + 1) - m - 1) * y % MOD) % MOD;
  }
  cout << xsum * ysum % MOD << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int ans = 0;
		for (int x = 0; x <= K; ++x) {
			for (int y = 0; y <= K; ++y) {
				int z = S - x - y;
				if (z < 0 || z > K)
					continue;
				++ans;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 9800
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            for (int b =0;b<a;b++)
            {
                int[] sss = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if (sss[0] * sss[0] + sss[1] * sss[1] == sss[2] * sss[2] || sss[0] * sss[0] + sss[2] * sss[2] == sss[1] * sss[1] || sss[1] * sss[1] + sss[2] * sss[2] == sss[0] * sss[0])
                    Console.WriteLine("YES");
                else
                    Console.WriteLine("NO");
            }

        }
    }
}

    

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

int n;


int main(){
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		for (int j = i + 1; j <= n; j++){
			int x = i ^ j;
			x = x & -x;
			int y = 0;
			while (x){
				y++; x /= 2;
			} 
			printf("%d ", y);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int N;
  cin >> N;
  bool p = false , w = false , g = false , y = false;
  for(int i=0;i<N;i++){
    char s;
    cin >> s;
    if(s == 'P') p = true;
    if(s == 'W') w = true;
    if(s == 'G') g = true;
    if(s == 'Y') y = true;
  }

  int cnt = 0;
  if(p) cnt++;
  if(w) cnt++;
  if(g) cnt++;
  if(y) cnt++;

  if(cnt == 3) cout << "Three" << endl;
  if(cnt == 4) cout << "Four" << endl;
  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(M)]
for i in range(0, 1000):
  i = str(i)
  flag = True
  if len(i) != N:
    continue
  for s, c in sc:
    #print(i, s, len(i))
    if len(list(i)) < s:
      flag = False
      break
    if i[s-1] != str(c):
      flag = False
      break
  if flag:
    print(i)
    exit()

print(-1)
    


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

using namespace std;

typedef long long int ll;
typedef long long int lli;
typedef unsigned long long int ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define fin(ans) cout << (ans) << endl;
//３つ以上の値をセットに(3より多いときはカッコ内を増やす)\
sort -> p -> q -> r
#define mt(p, q, r) make_tuple(p, q, r)
#define all(a) a.begin(), a.end()

template <typename T>
void V(T &n)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i];
  }
}

template <typename T, typename U>
void V2(T &n, U &m)
{
  for (ll i = 0; i < n.size(); i++)
  {
    cin >> n[i] >> m[i];
  }
}

template <typename T>
void Sort(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b));
  }
}

template <typename T>
void Down(T &n, ll a = 0, ll b = 0)
{
  if (b == 0)
  {
    return (sort(n.begin() + a, n.end(), greater<ll>()));
  }
  else
  {
    return (sort(n.begin() + a, n.begin() + b, greater<ll>()));
  }
}

void Main()
{
  ll n; cin >> n;
  vs s(n);vll p(n); V2(s, p);
  vector<tuple<str, ll, ll>> ans(n);
  rep(i, n)
  {
    p[i] = 100 - p[i];
  }
  rep(i, n)
  {
    ans[i] = mt(s[i], p[i], i + 1);
  }
  sort(all(ans));
  rep(i, n)
  {
    fin(get<2>(ans[i]))
  }
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}

Measured memory_bytes: 256
<?php

$tiles = str_split(trim(fgets(STDIN)));
$len = count($tiles);
$halflen = 0;

if ($len % 2 == 1) {
    $halflen = intval(floor($len / 2));
} else {
    $halflen = $len / 2;
}

$n01 = [];
$n10 = [];

for ( $i = 0; $i < $halflen ; $i++ ) {
    $n01[] = 0;
    $n01[] = 1;
    $n10[] = 1;
    $n10[] = 0;
}

if ($len % 2 == 1) {
    $n01[] = 0;
    $n10[] = 1;
}

$n01_count = 0;
$n10_count = 0;

for ($i = 0; $i < $len ; $i++) {
    if($tiles[$i] != $n01[$i]) {
        $n01_count++;
    }
    if($tiles[$i] != $n10[$i]) {
        $n10_count++;
    }
}

echo $n01_count < $n10_count ? $n01_count : $n10_count;
echo "\n";


Measured memory_bytes: 18936
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::{BufWriter, Write};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn greed(a: i32, b: i32, mut c: i32) -> i32 {
    let mut ans = 0;
    let mut tmp = c / b;
    ans += tmp;
    c -= b * tmp;

    let tmp = c / a;
    ans += tmp;
    c -= a * tmp;

    ans + c
}

fn opt(a: i32, b: i32, mut c: i32) -> i32 {
    let mut ans = c / a + c % a;
    let mut tmp = 0;

    while c >= b {
        c -= b;
        tmp += 1;
        ans = min(ans, tmp + c / a + c % a);
    }
    ans
}

fn f(a: i32, b: i32) -> i32 {
    for i in 2..a*b+100 {
        let g = greed(a, b, i);
        let o = opt(a, b, i);
        if g != o {
            return i;
        }
    }
    -1
}

fn hoge(a: i64, b: i64) -> i64 {
    for i in 2..a+1 {
        if a - i <= 0 {
            break;
        }
        let l = (i-1) * a + 1;
        let r = l + a - i;
        if l <= b && b <= r {
            return a as i64 * i as i64;
        }
    }
    -1
}

fn solve() {
    input!(
        a: i64,
        b: i64,
    );

    println!("{}", hoge(a, b));
}

fn main() {
    let stack_size = 1 << 28;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}



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

using namespace std;

int n, m;
vector<vector<int> > out, in;
vector<int> dep;

int dfs(int curr) {
  if(dep[curr] != -1) return dep[curr];

  int ret = 0;
  for(int i = 0; i<out[curr].size(); ++i) {
    int v = out[curr][i];
    ret = max(ret, 1+dfs(v));
  }

  dep[curr] = ret;
  return ret;
}

int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);

  cin >> n >> m;
  out.resize(n);
  in.resize(n);
  dep.assign(n, -1);
  for(int i = 0; i<m; ++i) {
    int u, v; cin >> u >> v;
    u--; v--;
    out[u].push_back(v);
    in[v].push_back(u);
  }


  int ret = 0;
  for(int i = 0; i<n; ++i) {
    if(in[i].size() == 0) {
      ret = max(ret, dfs(i));
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
	int N;
	string str;
	cin>>N>>str;
	vector<bool> s(N+1),a(N+2);
	rep(i,N) s[i] = str[i]=='o';
	s[N] = s[0];
	rep(k,4){
		a[0]=k&1, a[1]=k>>1;
		rep(i,N) a[i+2] = a[i]==(a[i+1]==s[i+1]);
		if(a[0]==a[N] && a[1]==a[N+1]){
			rep(i,N)cout<<"WS"[a[i]];
			cout<<endl;
			return 0;			
		}
	}
	cout<<-1<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>

#define D_MAX 1000000000
#define N_MAX 100000
#define M_MAX 10000
#define min(x,y) (((x)<(y))?(x):(y))

int d;
int n;
int m;

int ad[N_MAX+1];
int ak[M_MAX+1];

void MergeSort(int array[],int left,int right){
  int awork[N_MAX+1];
  int mid;
  int i;
  int j;
  int x;
  int y;
  
  if( left >= right ){
    return;
  }
  
  mid = (left + right) / 2;
  MergeSort( array, left, mid);
  MergeSort( array, mid+1, right);
  
  for( i=left; i<=mid; i++){
    awork[i] = array[i];
  }
  
  j = right;
  for( i=mid+1; i<=right; i++){
    awork[i] = array[j];
    j--;
  }
  
  x = left;
  y = right;
  
  for( i=left; i<=right; i++){
    if(awork[x] <= awork[y]){
      array[i] = awork[x];
      x++;
    }else{
      array[i] = awork[y];
      y--;
    }
  }
}

int calcDist(void){
  int i;
  int j;
  int minDist;
  int sum = 0;

  j = 1;
  for( i=1; i<=m; i++){
    while(ad[j] < ak[i]){
      j++;
    }
    minDist = min( ak[i]-ad[j-1],ad[j]-ak[i] );
    sum += minDist;
  }
  return sum;
}


void input(void){
  int i;
  scanf("%d",&d);
  if( d != 0){
    scanf("%d",&n);
    scanf("%d",&m);
    ad[0] = 0;
    for( i=1; i<=n-1; i++){
      scanf("%d",&ad[i]);
    }
    ad[n] = d;
    for( i=1; i<=m; i++){
      scanf("%d",&ak[i]);
    }
  }
}

int main(void){
  int i;
  int sumDist;
  while( 1 ){
    input();
    if( d == 0 ){
      break;
    }
    MergeSort( ad, 0, n);
    MergeSort( ak, 1, m);
    sumDist = calcDist();
    printf("%d\n",sumDist);
  }
}




Measured memory_bytes: 8784
#include <stdio.h>

int main(void)
{
	int prime[110000], i, j, s, sum;
	
	for (i = 0; i < 110000; i++){
		prime[i] = 1;
	}
	
	prime[0] = prime[1] = 0;
	
	for (i = 2; i * i <= 110000; i++){
		if (prime[i] == 1){
			for (j = i * i; j <= 110000; j += i){
				prime[j] = 0;
			}
		}
	}
	
	while (scanf("%d", &s), s != 0){
		sum = 0;
		
		i = 0;
		j = 0;
		while (i < s){
			if (prime[j] == 1){
				sum += j;
				i++;
			}
			j++;
		}
		
		printf("%d\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0); cin.sync_with_stdio(false);
  int h, w, n;
  cin >> h >> w >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<pair<int, int>> trf;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      trf.emplace_back(i, i & 1 ? w - 1 - j : j);
    }
  }
  vector<vector<int>> ret(h, vector<int>(w));
  auto it = trf.begin();
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < a[i]; j++) {
      ret[it->first][it->second] = i + 1;
      it++;
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cout << ret[i][j] << (j < w - 1 ? " " : "");
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 512
package main

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

func main() {
	var n int
	fmt.Scan(&n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = scanInt(scanner)
	}

	count := 0
	for true {
		for i := 0; i < n; i++ {
			if a[i]%2 == 0 && a[i] != 0 {
				a[i] /= 2
			} else {
				fmt.Println(count)
				return
			}
		}
		count++
	}
}

func scanInt(s *bufio.Scanner) (int, error) {
	s.Scan()
	str := s.Text()
	return strconv.Atoi(str)
}

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

ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
ll cnt;
ll visit[55][55];
ll c[55][55];
ll h,w;

bool in(ll y, ll x){
    return 0 <= y && y < h && 0 <= x && x < w;
}

void dfs(ll y, ll x){
    if(c[y][x]==0) return;
    if(visit[y][x]>0) return;
    visit[y][x] = cnt;
    rep(i,8){
        ll ny = y+dy[i];
        ll nx = x+dx[i];
        if(!in(ny, nx)) continue;
        else{
            dfs(ny,nx);
        }
    }
}

int main(){
    while(1){
        cin >> w >> h;
        if(w==0 && h==0) break;
        cnt = 0;
        rep(i,h) rep(j,w) cin >> c[i][j];
        rep(i,h) rep(j,w) visit[i][j] = 0;
        rep(i,h){
            rep(j,w){
                if(c[i][j]==0) continue;
                else{
                    if(visit[i][j] > 0) continue;
                    else{
                        cnt++;
                        dfs(i,j);
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}



Measured memory_bytes: 3120
import sys
input = sys.stdin.readline

def calc(ban_s, ban_t):
    dp2 = [0]*N
    dp2[N-1] = 0
    
    for v in range(N-2, -1, -1):
        cnt = 0
        
        for nv in G[v]:
            if v==ban_s and nv==ban_t:
                continue
            
            dp2[v] += dp2[nv]+1
            cnt += 1
        
        if cnt==0:
            dp2[v] = 100000
        else:
            dp2[v] /= cnt
        
    return dp2[0]
    
N, M = map(int, input().split())
G = [[] for _ in range(N)]

for _ in range(M):
    s, t = map(int, input().split())
    G[s-1].append(t-1)

dp = [0]*N
dp[N-1] = 0

for v in range(N-2, -1, -1):
    for nv in G[v]:
        dp[v] += dp[nv]+1
    
    dp[v] /= len(G[v])

ans = dp[0]

for v in range(N):
    M = 0
    mark = -1
    
    for nv in G[v]:
        if dp[nv]>M:
            M = dp[nv]
            mark = nv
    
    ans = min(ans, calc(v, mark))

print(ans)

Measured memory_bytes: 57820
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long LL;
vector<int> q;
int a[1000000];
int main(){
	int n,L,fg=0;
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;++i)scanf("%d",&a[i]);
	for(int i=1;i<n;++i){
		if(a[i]+a[i+1]>=L)fg=i;
	}
	if(fg==0){puts("Impossible");return 0;}
	puts("Possible");
	for(int i=1;i<=fg-1;++i)printf("%d\n",i);
	for(int i=n-1;i>=fg;--i)printf("%d\n",i);
	return 0;
}

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

int main() {
	string s;
	cin>>s;
	char f,l;
	f=s[0],l=s[s.size()-1];
	int rest;
	if(f==l){
		rest=3;
	}else{
		rest=0;
		char t=l;
		for(int i=0;i<s.size();i++){
			if(t==l){
				if(s[i]==f){
					rest++;
					t=f;
				}
			}else{
				if(s[i]==l){
					rest++;
					t=l;
				}
			}
		}
	}
	if(((int)s.size()-rest)%2==0){
		cout << "Second" << endl;
	}else{
		cout << "First" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 512
# A - Station and Bus
s = input()

cntA = 0
cntB = 0

for i in s:
    if i == 'A':
        cntA += 1

    else:
        cntB += 1

if cntA == 3 or cntB == 3:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 2940
from itertools import product

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def _num(arr):
    out = 1
    for item in arr:
        out *= (item[1]+1)
    return out

n_orig = int(input())
arr = factorization(n_orig)
arr1 = factorization(n_orig - 1)

if n_orig==2:
    print(1)
elif len(arr)==1 and arr[0][1]==1:
    print(_num(arr1))
else:
    tmp = _num(arr1)-1
    
    for nums in product(*[range(item[1]+1) for item in arr]):
        n = n_orig
        kk = 1
        for num, base in zip(nums, arr):
            base = base[0]
            kk *= base**num
        if (kk==1):
            continue
        while n%kk==0:
            n /= kk
        if ((n - 1) % kk == 0):
            tmp += 1
    print(tmp)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <set>
#include <queue>
#include <stack>
#include <map>

using namespace std;
typedef long long LL;
const int INF = int(1e9);

int N,K;
int min1 = INF;

void DFS(int sum,int n)
{
    if(n==N)
    {
        if(sum<min1)
            min1=sum;
        return;
    }
    DFS(sum*2,n+1);
    DFS(sum+K,n+1);
}

int main()
{
    cin>>N>>K;
    DFS(1,0);
    cout<<min1<<endl;


   return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BCakesAndDonuts solver = new BCakesAndDonuts();
        solver.solve(1, in, out);
        out.close();
    }

    static class BCakesAndDonuts {
        private static final String[] ANSWER = {"Yes", "No", "No", "No", "Yes", "No", "No", "Yes", "Yes", "No", "No", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "No", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes", "Yes"};

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            out.println(ANSWER[in.nextInt()]);
        }

    }
}



Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MOD (ll) (1e9+7)
int main()
{
	ll n;
    cin>>n;
    string x;
    map<string,int> ma;
    for(int i=0;i<n;i++)
    {
      cin>>x;
      ma[x]++;
    }
  cout<<ma.size()<<"\n";
}

Measured memory_bytes: 18992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define _GLIBCXX_DEBUG

void print(vector<int> l) {
  for (int i : l) {
    cout << i;
  }
  cout << endl;
}

int main() {
  int T;
  cin >> T;
  for (int n = 0; n < T; n++) {
    bool ans = true;
    vector<int> a, b, c;
    vector<int> cardN(9);
    for (int i = 0; i < 9; i++)
      cin >> cardN[i];
    for (int i = 0; i < 9; i++) {
      string cardC;
      cin >> cardC;
      if (cardC == "R")
        a.push_back(cardN[i]);
      if (cardC == "G")
        b.push_back(cardN[i]);
      if (cardC == "B")
        c.push_back(cardN[i]);
    }

    if ((a.size() % 3) || (b.size() % 3) || (c.size() % 3)) {
			cout<<0<<endl;//最初はans=falseにしてた
      continue;
    }

    for (vector<int> nv : {a, b, c}) {
      sort(nv.begin(), nv.end());
      while (nv.size() != 0) {
        if ((nv[0] == nv[1]) && (nv[1] == nv[2]))
          nv.erase(nv.begin(), nv.begin() + 3);
				//eraseの２つめの引数は削除したい範囲の次を指す
        else {
          auto p2 = find(nv.begin(), nv.end(), nv[0] + 1);
          auto p3 = find(nv.begin(), nv.end(), nv[0] + 2);
          if ((p2 != end(nv)) && (p3 != end(nv))) {
            nv.erase(p3);
            nv.erase(p2);
						nv.erase(nv.begin());//最初忘れてた
						/*nv.erase(nv.begin());
            nv.erase(p2);
            nv.erase(p3);//ミス
						*/
          } else {
            ans = false;
            break;
          }
        }
      }
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int 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 fi first
#define se second
#define debug(...) cerr<<__LINE__<<" ["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec)
{ for (auto v : vec) os << v << ' '; os << '\n'; return os; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa)
{ os << '(' << pa.first << ',' << pa.second << ')'; return os; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T)
{ cerr << " " << H; debug_out(T...); }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    vector<int> H(n);
    rep(i, n) cin >> H[i];
    for(int i = n - 2; i >= 0; i--) {
        if (H[i] - 1 > H[i + 1]) {
            cout << "No" << endl;
            return;
        } else if (H[i] - 1 == H[i + 1]){
            H[i]--;
        } else {
            continue;
        }
    }
    cout << "Yes" << endl;
}

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


Measured memory_bytes: 3712
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


void rec(int lm,vi& a,vl& ans){
    int sz=a.size();
    if(sz==lm){
        LL num=0;
        FOR(i,0,sz){
            num*=10;
            num+=a[i];
        }
        ans.PB(num);
        //cerr<<num<<endl;
        return;
    }
    FOR(i,-1,2){
        int nx=a[sz-1]+i;
        if(nx>=0&&nx<10){
            a.PB(nx);
            rec(lm,a,ans);
            a.pop_back();
        }
    }

}

int main(){
	int k;
    cin>>k;
    vl ans;
    FOR(i,1,11){
        FOR(j,1,10){
            auto a=vi(1,j);
            rec(i,a,ans);
        }
    }
    sort(ans.begin(),ans.end());
    //cerr<<ans.size()<<endl;
    cout<<ans[k-1]<<endl;

}


Measured memory_bytes: 2548
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
// 素数かどうか判定
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s, t; cin >> s >> t;
	int n = sz(s);
	int m = sz(t);
	vector<vector<int>>is(26);
	rep(i, n) {
		is[s[i] - 'a'].push_back(i);
	}
	rep(i, n) {
		is[s[i] - 'a'].push_back(i + n);
	}
	int ans = 0;
	int p = 0;
	rep(i, m) {
		int c = t[i] - 'a';
		if(sz(is[c])==0){
			puts("-1");
			return 0;
		}
		p = *lower_bound(is[c].begin(), is[c].end(), p) + 1;
		if (p >= n) {
			p -= n; ans += n;
		}
	}
	ans += p;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2756
#include <iostream>                                              
#include <string>   
using namespace std;
                    
string S;           
                    
int solve(){        
  string copy1 = S; 
  int ans = 100100100;
  for(int i = 0; i < 26; i++){
    int kaisuu = 0; 
    copy1 = S;      
    while(1){       
      string copy2; 
      bool flag = true;
      for(int j = 0; j < copy1.size(); j++)
        if(copy1[j] != 'a'+i){
          flag = false;
          break;    
        }           
      if(flag) break;
      for(int j = 1; j < copy1.size(); j++){
        if(copy1[j-1] != 'a'+i && copy1[j] != 'a'+i)
          copy2 += copy1[j];
        else copy2 += 'a'+i;
      }             
      kaisuu++;     
      copy1 = copy2;
    }               
    ans = min(ans, kaisuu);
  }                 
  return ans;       
}
int main(){
  cin >> S;
  cout << solve() << endl;
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; i++) {
    ll res = (N/i) * (i + (i * (N/i)));
    res /= 2;
    ans += res;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
N = int(input())
A = [0, 0, 0, 0, 0]
for i in range(N):
  s = input()
  if s[0] == "M":
    A[0] += 1
  elif s[0] == "A":
    A[1] += 1
  elif s[0] == "R":
    A[2] += 1
  elif s[0] == "C":
    A[3] += 1
  elif s[0] == "H":
    A[4] += 1
ans = 0
for i in range(3):
  for j in range(i+1, 4):
    for k in range(j+1, 5):
      ans += A[i] * A[j] * A[k]
print(ans)

Measured memory_bytes: 74880
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let _n = read::<i32>();
    let mut an = read_vec::<i32>();

    an.sort();

    let mut alice = 0;
    let mut bob = 0;
    let mut ord = 0; // 0: alice, 1: bob
    loop {
        match an.pop() {
            Some(i) => {
                match ord {
                    0 => alice += i,
                    _ => bob += i,
                }
            }
            None => break,
        }
        if ord == 0 { ord = 1 } else { ord = 0 }
    }
    println!("{}", alice - bob);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int str[30];
int main()
{
	int n,ans=0;
	cin>>n;
	string a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		memset(str,0,sizeof(str));
		str[a[i]-'a']++;
		str[b[i]-'a']++;
		str[c[i]-'a']++;
		int temp=0;
		for(int j=0;j<26;j++)
		{
			temp=max(temp,str[j]);
		}
	//	cout<<temp<<endl;
		ans+=3-temp;
	}
	cout<<ans<<endl;
	return 0;
} 

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

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

    string S;
    int P;
    map<string, vector<pair<int, int>>> m;
    for (int i = 1; i <= N; i++)
    {
        cin >> S;
        cin >> P;
        m[S].push_back(make_pair(-P, i));
    }

    for (auto x : m)
    {
        sort(x.second.begin(), x.second.end());
        for (auto a : x.second)
        {
            cout << a.second << endl;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;
typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef map<int, int> M;
typedef pair<int, int> P;

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

    int n;
    cin >> n;
    if (n % 2) cout << n * 2 << endl;
    else cout << n << endl;
    
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); i++)

using namespace std;
using lint = long long;

int main(void)
{
    string S1, S2;
    int N;
    cin >> N;
    cin >> S1 >> S2;
    for(int i = 0; i < S1.size(); i++){
        cout << S1[i] << S2[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static long gcd(long a, long b){
        long x;
        long y;
        if(b > a){
            x = b;
            y = a;
        }else{
            x = a;
            y = b;
        }
        long lm;
        while((lm = x%y) != 0){
            x = y;
            y = lm;
        }
        return y;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long sum = 0;
        for(long a = 1; a <= N; a++){
            for(long b = 1; b <= N; b++){
                for(long c = 1; c <= N; c++){
                    sum = sum + gcd(a, gcd(b, c));
                }
            }
        }
        System.out.println(sum);
    }
} 

Measured memory_bytes: 35832
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <unordered_set>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
int INF = INT_MAX / 10;
double EPS = 1e-10;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

bool solve(vector<int> a) {
	int N = a.size();
	ll sum = 0;
	rep(i, N) sum += a[i] - 1;
	if (sum == 0) return false;
	if (sum % 2) return true;
	int odd = 0;
	rep(i, N) if (a[i] % 2) odd++;
	if (odd >= 2) return false;
	int i0;
	rep(i, N) if (a[i] % 2) i0 = i;
	if (a[i0] == 1) return false;
	a[i0]--;
	int d = 0;
	rep(i, N) d = gcd(d, a[i]);
	rep(i, N) a[i] /= d;
	return !solve(a);
}

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N) scanf("%d", &a[i]);
	cout << (solve(a) ? "First" : "Second") << endl;
}


Measured memory_bytes: 9984
n = int(input())
a = [0] * n
b = [0] * n
for i in range(n):
  p, q = [int(j) for j in input().split(' ')]
  a[i] = p+q
  b[i] = p-q

a.sort()
b.sort()
print(max(a[-1] - a[0], b[-1] - b[0]))

Measured memory_bytes: 80996