akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

int main(void)
{
    int a[4], b[4];
    while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
        int sum1 = 0, sum2 = 0;
        for (int i = 0; i < 4; ++i)
            if (a[i] == b[i])
                ++sum1;
        for (int i = 0; i < 4; ++i)
            for (int j = 0; j < 4; ++j)
                if (i != j && a[i] == b[j])
                    ++sum2;
        cout << sum1 << " " << sum2 << endl;
    }

    return 0;
}



Measured memory_bytes: 2984
import math
N, M = map(int, input().split())
mm = math.floor(math.sqrt(M)) + 1
ans = 0
for a in range(mm, 0, -1):
  if M % a == 0:
    b = M // a
    if a >= N:
      ans = max(ans, b)
    elif b >= N:
      ans = max(ans, a)
print(ans)

Measured memory_bytes: 39152
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n,m=map(int,input().split())
    if n == 1:
        print(1)
        return
    aa=[]
    for _ in range(m):
        aa.append(int(input()))
    for i in range(m-1):
        if aa[i]+1==aa[i+1]:
            print(0)
            return
    cc = [0] * n
    i = 0
    j = 2 
    cc[0] = 1
    if m < 1 or aa[0] > 1:
        cc[1] = 1
    else:
        cc[1] = 0
        i += 1
    while j < n:
        if i < m and aa[i] == j:
            i+=1
        else:
            cc[j]=cc[j-1]+cc[j-2]
        j+=1
    print((cc[n-1]+cc[n-2])%1000000007)

main()

Measured memory_bytes: 460020
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

s = sum(ril())
if s > 21:
    print('bust')
else:
    print('win')










Measured memory_bytes: 3064
#include "stdio.h"
#include "string.h"

#define SIZE_OF_ARRAY(a) (sizeof(a)/sizeof(a[0]))

int sum_of_keta(int num)
{
	int num_keta[6];
	int temp_num = 1;
	int sum = 0;

	memset(num_keta, 0, sizeof(num_keta));

	for(int i=0;i<SIZE_OF_ARRAY(num_keta);i++){
		num_keta[i] = num%(temp_num*10)/temp_num;
		temp_num *= 10;
	}

	for(int j=0;j<SIZE_OF_ARRAY(num_keta);++j){
		sum += num_keta[j];
	}
	return sum;
}

int main(void){
	int N, A, B;
	int i;
	int sum_of_fugo = 0;
	int sum;

	scanf("%d%d%d", &N, &A, &B);

	for(i=1;i<=N;++i){
		sum = sum_of_keta(i);
		if(A<=sum&&sum<=B){
			sum_of_fugo += i;
		}
	}

	printf("%d\n", sum_of_fugo);
	return 0;
}

Measured memory_bytes: 128
odd  = []
even = []

inp= int(input())

for i in range(1,inp+1):
    if i%2 == 0:
        even.append(i)
 #       print("even append!")
    else:
        odd.append(i)
#      print("odd apprnd!")
    
print(len(odd)/(len(odd)+len(even)))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main() {
	string c1, c2, c3;
	cin >> c1 >> c2 >> c3;
	transform(c1.begin(), c1.end(), c1.begin(), ::toupper);
	transform(c2.begin(), c2.end(), c2.begin(), ::toupper);
	transform(c3.begin(), c3.end(), c3.begin(), ::toupper);
	cout << c1.at(0) << c2.at(0) << c3.at(0) << endl;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

dp = [0, abs(h[1]-h[0])]

for i in range(2, n):
    dp.append(min(dp[i-1] + abs(h[i-1]-h[i]), dp[i-2] + abs(h[i-2]-h[i])))

print(dp[-1])

Measured memory_bytes: 20672
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define pp pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define F first 
#define S second 
#define lc "\n"
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;} 
ll MAX=1e18 , MIN=-1e18 , MOD=1000000007;
void YJ()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
}
int main() 
{
    YJ(); fastio
    int n; cin>>n;
    if(n>=400&&n<600) cout<<8;
    if(n>=600&&n<800) cout<<7;
    if(n>=800&&n<1000) cout<<6;
    if(n>=1000&&n<1200) cout<<5;
    if(n>=1200&&n<1400) cout<<4;
    if(n>=1400&&n<1600) cout<<3;
    if(n>=1600&&n<1800) cout<<2;
    if(n>=1800&&n<2000) cout<<1;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int H,W,D;
	cin>>H>>W>>D;
	
	vector<pair<int,int>> P(H*W);
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int A;
			cin>>A;
			A--;
			P[A]=make_pair(i,j);
		}
	}
	
	vector<vector<int>> dis(D,vector<int>(1,0));
	
	for(int i=0;i<D;i++){
		for(int j=1;true;j++){
			int t = i+j*D;
			if(t>H*W)break;
			int d = abs(P[t].first-P[t-D].first)+abs(P[t].second-P[t-D].second);
			dis[i].push_back(d+dis[i].back());
		}
	}
	
	int Q;
	cin>>Q;
	
	for(int i=0;i<Q;i++){
		int l,r;
		cin>>l>>r;
		l--;r--;
		if(l==r){
			cout<<0<<endl;
			continue;
		}
		cout<<dis[l%D][r/D]-dis[l%D][l/D]<<endl;
	}
		
    return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair



bool solve(int N){
    switch(N){
        case 7: case 5: case 3:
            return true;
        default:
            return false;
    }
}

int main() {
    int N; cin >> N;
    cout << (solve(N) ? "YES":"NO") << endl;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
import scala.math._

object Main extends App with StdInHelper {
  val x = readLong
  val s = x / 11L
  val m = x % 11L

  println(s * 2 + (if (m == 0) 0 else if (m <= 6) 1 else 2))
}

trait StdInHelper {
  def readInts = readLine.split(" ").map(_.toInt)
  def readLongs = readLine.split(" ").map(_.toLong)
}


Measured memory_bytes: 25548
local mfl = math.floor

local function get_ary_from_idx(idx, n)
  idx = idx - 1
  local box = {}
  for i = 1, n do box[i] = true end
  local rettbl = {}
  for i = n, 1, -1 do
    local pos = idx % i + 1
    idx = mfl(idx / i)
    local cnt = 0
    for j = 1, n do
      if box[j] then
        cnt = cnt + 1
        if cnt == pos then
          box[j] = false
          table.insert(rettbl, j)
          break
        end
      end
    end
  end
  return rettbl
end

local function get_idx_from_ary(ary)
  local retidx = 0
  local n = #ary
  local cpy = {}
  for i = 1, n do cpy[i] = ary[i] end
  for i = 1, n - 1 do
    for j = i + 1, n do
      if cpy[i] < cpy[j] then cpy[j] = cpy[j] - 1 end
    end
  end
  for i = n, 1, -1 do
    retidx = retidx * (n + 1 - i) + cpy[i] - 1
  end
  return retidx + 1
end

local n = io.read("*n")
local x, y = {}, {}
for i = 1, n do
  x[i], y[i] = io.read("*n", "*n")
end

local allpat = 1
for i = 1, n do
  allpat = allpat * i
end

local msq = math.sqrt
local function getlen(p, q)
  return msq((x[p] - x[q]) * (x[p] - x[q]) + (y[p] - y[q]) * (y[p] - y[q]))
end
local len = 0
for i = 1, allpat do
  local a = get_ary_from_idx(i, n)
  for j = 1, #a - 1 do
    len = len + getlen(a[j], a[j + 1])
  end
end
print(string.format("%.10f", len / allpat))


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define VEC(TYPE, A, NAME, INIT) vector<TYPE> NAME(A, INIT)
#define VEC2(TYPE, A, B, NAME, INIT) vector<vector<TYPE>> NAME(A, vector<TYPE>(B, (INIT)))

int main()
{
    ull l;
    int n;
    cin >> l >> n;
    VEC(ull, n + 2, x, -1);
    x[0] = 0;
    x[n + 1] = l;
    REP(i, n) cin >> x[i + 1];

    VEC(ull, n + 2, sum0, 0);
    VEC(ull, n + 2, sumN, 0);
    REP( i, n + 1 ) sum0[i+1] = sum0[i] + x[i+1];
    REP( i, n + 1 ) sumN[n-i] = sumN[n-i+1] + x[n+1] - x[n-i];

    ull ans = 0;
    REP(i, n + 1)
    {
        if (i == 0)
        {
            ans = max(ans, x[n+1] - x[1]);
            continue;
        }
        if( i == n )
        {
            ans = max(ans, x[n]);
            continue;
        }

        int start = i;
        int end = i + 1;
        ull sum;
        if( i * 2 == n )
        {
            sum = sumN[end] + sum0[start];
            sum *= 2;
            ans = max(ans, sum - x[start]);
            ans = max(ans, sum - (x[n + 1] - x[end]));
        }
        else if( i * 2 < n )
        {
            sum = sumN[end] - sumN[end + i] + sum0[start];
            sum *= 2;
            ans = max(ans, sum - x[start]);
            sum = sumN[end] - sumN[end + i + 1] + sum0[start];
            sum *= 2;
            ans = max(ans, sum -( x[n+1] - x[end] ) );
        }
        else
        {
            int j = n + 1 - end;
            sum = sumN[end] + sum0[start] - sum0[start-j];
            sum *= 2;
            ans = max(ans, sum - (x[n + 1] - x[end]));
            sum = sumN[end] + sum0[start] - sum0[start-j-1];
            sum *= 2;
            ans = max(ans, sum - x[start]);
        }
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
N = int(input())
l = [int(input()) for i in range(5)]
tmp = 0
for i in range(5):
  if l[i] > N:
    tmp += 1

if tmp == 5:
  print(5)
else:
    ans = 0
    if N%min(l) == 0:
      ans+=5+N//min(l)-1
    else:
      ans+=5+N//min(l)
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL (1LL<<62) // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

long long modPow(long long x, long long n, long long mod = MODV){
    if(n == 0) return 1;
    if(n%2 == 0) return modPow(x*x%mod, n/2, mod)%mod;
    return x%mod * modPow(x%mod, n-1, mod)%mod;
}

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

    // 包除原理(全ての組み合わせ - 0が無い - 9が無い + 0と9が無い)
    // 全ての組み合わせ; 10^n
    // 0が1つ以上存在しない; 9^n
    // 9が1つ以上存在しない; 9^n
    // 0と9が1つ以上存在しない; 8^n
    ll ans = modPow(10, n);
    ans -= 2*modPow(9, n);
    ans += modPow(8, n);
    cout << (ans%MODV+MODV)%MODV << endl;
}

Measured memory_bytes: 3612
MOD = 10**9 +7

def main():
    l=input()
    n=len(l)

    dp=[[0]*2 for _ in range(n)]
    dp[0][0] = 2
    dp[0][1] = 1 

    for i in range(1,n):
        if l[i]=='0':
            dp[i][0] = dp[i-1][0]
            dp[i][1] = 3*dp[i-1][1]
            dp[i][1] %= MOD
        else:
            dp[i][0] = 2*dp[i-1][0]
            dp[i][0] %= MOD
            dp[i][1] = dp[i-1][0] + 3*dp[i-1][1]
            dp[i][1] %= MOD
    
    print(sum(dp[-1])%MOD)
if __name__=='__main__':
    main()

Measured memory_bytes: 19700
#N,Lを入力より取得する
n,l = map(int, input().split())

#リストに[s1,s2,...,sn]形式で取得
slist = []
for i in range(n):
    slist.append(input())
"""
if 'a' < 'd':
    print('1')
else:
    print('0')

"""
#リストの要素を辞書早い順にソートする
for i in range(n):
    j = i + 1
    for j in range(n):
        for k in range(l):
            if slist[i][k] < slist[j][k]:
                slist[i], slist[j] = slist[j],slist[i]
                break
            elif slist[i][k] > slist[j][k]:
                break

out = ''            
for i in slist:
    out = out + i

#最終結果を出力
print(out)

Measured memory_bytes: 3064
#include <algorithm>　　　 //STL通用算法
#include <bitset>　　　　　//STL位集容器
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>　　　　 //复数类
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>　　　　　 //STL双端队列容器
#include <exception>　　　 //异常处理类
#include <fstream>
#include <functional>　　　//STL定义运算函数（代替运算符）
#include <limits>
#include <list>　　　　　　//STL线性列表容器
#include <map>　　　　　　 //STL 映射容器
#include <iomanip>
#include <ios>　　　　　　//基本输入／输出支持
#include<iosfwd>　　　　　//输入／输出系统使用的前置声明
#include <iostream>
#include <istream>　　　　 //基本输入流
#include <ostream>　　　　 //基本输出流
#include <queue>　　　　　 //STL队列容器
#include <set>　　　　　　 //STL 集合容器
#include <sstream>　　　　//基于字符串的流
#include <stack>　　　　　 //STL堆栈容器　　　　
#include <stdexcept>　　　 //标准异常类
#include <streambuf>　　　//底层输入／输出支持
#include <string>　　　　　//字符串类
#include <utility>　　　　 //STL通用模板类
#include <vector>　　　　　//STL动态数组容器
#include <cwchar>
#include <cwctype>
#define ll long long
using namespace std;
//priority_queue<int,vector<int>,less<int> >q;
int dx[]= {-1,1,0,0,-1,-1,1,1};
int dy[]= {0,0,-1,1,-1,1,1,-1};
const int maxn = 1000+66;
const ll mod=1e9+7;
const ll inf=0x3f3f3f3f3f3f3f3fLL;
int n,m;
double a[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    double ans=0.0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lf",&a[i]);
        //cout<<a[i]<<endl;
        ans+=1.0/a[i];
    }
    //cout<<ans<<endl;
    ans=1.0/ans;
    printf("%.7f",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int a[n];
        int sum = 0;
        for (int i = 0; i < n; ++i)
        {
            cin >> a[i];
            sum += a[i];
        }

        if (n == 1)
        {
            cout << 0 << "\n";
            return 0;
        }
        sort(a, a + n);
        if (n == 2)
        {
            cout << a[n - 1] << "\n";
            return 0;
        }
        int nn = n - 2;
        int ans = a[n - 1];
        int i = 0;
        for (i = n - 2; i >= 0; --i)
        {
            ans += 2 * a[i];
            nn = nn - 2;
            if (nn <= 0)
                break;
        }
        //cout << i << "ee\n";
        if (n % 2)
        {
            cout << ans - a[i] << "\n";
        }
        else
            cout << ans << "\n";
    }
}

Measured memory_bytes: 5172
def bubble_sort(cards, n):
    for i in range(n):
        for j in range(n-1, i, -1):
            if cards[j][1] < cards[j-1][1]:
                cards[j], cards[j-1] = cards[j-1], cards[j]

    return cards

def selection_sort(cards, n):
    for i in range(n):
        minj = i

        for j in range(i, n):
            if cards[j][1] < cards[minj][1]:
                minj = j

        if i != minj:
            cards[i], cards[minj] = cards[minj], cards[i]

    return cards

def is_stable(cards, sorted_cards):
    hashed = {}

    for m, v in cards:
        if v not in hashed:
            hashed[v] = []

        hashed[v].append((m, v))

    for sm, sv in sorted_cards:
        if hashed[sv][0] != (sm, sv):
            return False

        hashed[sv] = hashed[sv][1:]

    return True

def print_cards(cards, sorted_cards):
    print(' '.join([card[0]+str(card[1]) for card in sorted_cards]))

    if is_stable(cards, sorted_cards):
        print('Stable')
    else:
        print('Not stable')

def main():
    n = int(input())
    cards = [(card[0], int(card[1])) for card in input().split()]

    sorted_cards = bubble_sort(cards[:], n)
    print_cards(cards, sorted_cards)

    sorted_cards = selection_sort(cards[:], n)
    print_cards(cards, sorted_cards)

if __name__ == '__main__':
    main()



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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  for (int i = 0; i < n; i += 2) {
    cnt += a[i] % 2 == 1;
  }
  cout << cnt << '\n';
}


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

int main(){
  int n;
  cin >> n;
  int i,ans=0;
  for(i=1;i<=n;i++){
    int s,j;
    s=0;
    j=i;
    while(j>0){
      j /= 10;
      s++;
    }
    if(s%2==1){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var mochi = new List<int>();
            for (int i = 0; i < N; i++)
            {
                var d = int.Parse(Console.ReadLine());
                if (!mochi.Contains(d)) mochi.Add(d);
            }

            Console.WriteLine(mochi.Count);
        }
    }
}

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

int main(){
	int n, a;
	cin >> n >> a;
	if(n%500 <= a)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long c[200001],n;
long long h[200001],a[200001];
int lowbit(int x)
{
    return x&-x;
}
void update(int index,long long max_value)
{
    while(index<=n)
    {
        c[index]=max(c[index],max_value);
        index+=lowbit(index);
    }
}
long long maxrange(int index)
{
    long long maxx=0;
    while(index)
    {
        maxx=max(maxx,c[index]);
        index-=lowbit(index);
    }
    return maxx;
}
int main()
{
    long long maxx=0,t,i;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
        scanf("%lld",&h[i]);
    for(i=1;i<=n;i++)
        scanf("%lld",&a[i]);
    for(i=1;i<=n;i++)
    {
        t=maxrange(h[i]-1);
        maxx=max(maxx,t+a[i]);
        update(h[i],t+a[i]);
    }
    printf("%lld",maxx);
    return 0;
}

Measured memory_bytes: 4992
a=input()
import sys
if len(a)%2==0:
    print('No')
    sys.exit()
d=(len(a)-1)//2

b=a[0:int(d)]
e=(len(a)+3)/2-1
c=a[int(e):int(len(a))]
r=['']*len(b)
w=['']*len(c)
for i in range(len(b)):
    r[i]+=b[i]
for i in range(len(c)):
    w[i]+=c[i]

b1=r
b1.reverse()
c1=w
c1.reverse()

if b1==r and c1==w and r==w:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;
static const int INF = (int)1e8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) for (int i=0; i<(int)(n); ++i)
#define FOREQ(i,k,n) for (int i=(k); i<=(int)(n); ++i)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FIND(m,w) ((m).find(w)!=(m).end())

int main(void){
  string up,left; //red-up green-left
  string down;
  while(cin>>up){
    if(up=="-") break;
    cin>>left>>down;
    queue<char> queup,quelf;
    REP(i,up.size())queup.push(up[i]);
    REP(i,left.size())quelf.push(left[i]);
    char stk;
    string ans;
    stk = quelf.front(); quelf.pop();
    int idx = 0;
    while(!quelf.empty()||!queup.empty()){
      if(idx>=down.size()||down[idx]!=stk){
        ans += stk;
        stk = quelf.front(); quelf.pop();
      }else{
        idx++;
        stk = queup.front(); queup.pop();
      }
    }
    ans += stk;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
N = gets.to_i
RATIOS = readlines.map{|l| l.split.map(&:to_i)}

prev_x = min_t = min_a = 0
RATIOS.each do |t, a|
  x = nil
  y = [
    1,
    prev_x / (t+a),
    min_t / t,
    min_a / a,
  ].max
  while true
    x = (t+a)*y
    break if x >= prev_x && t*y >= min_t && a*y >= min_a
    y += 1
  end
  prev_x = x
  min_t = t * y
  min_a = a * y
end
p prev_x


Measured memory_bytes: 1916
while True:
    a,op,b = input().split()
    a=int(a)
    b=int(b)
    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == "*":
        print(a*b)
    elif op == "/":
        print(int(a/b))
    elif op == "?":
        break


Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define all(in) in.begin(), in.end()
constexpr int INF = (numeric_limits<int>::max() == INT_MAX ? (int)1e9 : (long long)1e18);
constexpr long double eps = 1e-6;
const string el = "\n";
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
using ld  = long double;using pii = pair<int,int>;using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
void fast_io(){ios::sync_with_stdio(false); cin.tie(nullptr);}
template<class T> T gcd(T a,  T b) {return b ? gcd(b, a % b) : a;}
template<class U> U lcm( U m, U n ){if((0 == m )||( 0 == n ))return 0; return ((m / gcd(m, n)) * n); }
signed main(){
    fast_io();
    int H,W,D; cin >> H >> W >> D;
    vector<pii>pos(H * W  + 1);
    vector<vector<int>>grid(H,vector<int>(W));
    for(int i = 0; i < H; ++i){
        for(int j = 0; j < W; ++j){
            int num; cin >> num;
            pos[num] = pii(i,j);
            grid[i][j] = num;
        }
    }
    vector<int>memo(H * W  + 1, 0LL);
    for(int i = 0; i <= H * W; ++i){
        if(memo[i] != 0) continue;
        int t = i;
        while(t + D < memo.size()){
            pii p = pos[t  + D];
            pii lpos = pos[t];
            memo[t + D] = memo[t] + abs(p.first - lpos.first) + abs(p.second - lpos.second);
            t += D;
        }
    }
    int Q; cin >> Q;
    rep(_,Q){
        int l,r; cin >> l >> r;
        cout << memo[r] - memo[l] <<  el;
    }
}


Measured memory_bytes: 3968
n = int(input())


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


print(num2alpha(n).lower())


Measured memory_bytes: 79732
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        w: usize,
        mut weval: [(usize, usize); n],
    };

    weval.insert(0, (0, 0));
    let mut dp = vec![vec![0; w+1]; n+1];

    for i in 1..=n {
        for j in 0..=w {
            if weval[i].0 <= j {
                dp[i][j] = dp[i-1][j].max(dp[i-1][j-weval[i].0] + weval[i].1);
            } else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    println!("{}", dp[n][w]);
}


Measured memory_bytes: 81040
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]

ab = sorted(ab, key=lambda x: x[1], reverse=True)

lefttime = ab[0][1]
for a, b in ab:
    lefttime = min(lefttime, b)
    lefttime -= a
    
    if lefttime < 0:
        print("No")
        exit()

print("Yes")

Measured memory_bytes: 89944
#include<iostream>
#include<cmath>
#include<vector>
#include<numeric>
#include<limits>
using namespace std;
int main() {
  int k;
  cin >> k;
  int ans = 0;
  for (int i = 1;i <= k; i++){
    for(int j = 1; j <= k; j++){
      for (int x = 1; x <= k; x++){
        int tmp = std::gcd(i, j);
        ans += std::gcd(tmp, x);
      }
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 3624
#include <cstdio>
#include <iostream> 
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
 
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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



int main()
{
	int h, w;
	cin >> h >> w;

	map<char, int> m;
	REP(i, h){
		string a;
		cin >> a;

		REP(j, w){
			m[a[j]]++;
		}
	}

	int c[4] = {};
	for(auto x : m){
		c[((x.second % 4) + 3) % 4]++;
	}

	if(h % 2 == 0 && w % 2 == 0){
		if(!(c[0] | c[1] | c[2])){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	else if(h % 2 == 1 && w % 2 == 1){
		if(c[0]){
			c[0]--;
		}
		else if(c[2]){
			c[2]--;
			c[1]++;
		}
		else{
			cout << "No" << endl;
			return 0;
		}

		if(c[1] > h / 2 + w / 2 || c[0] || c[2]){
			cout << "No" << endl;
		}
		else{
			cout << "Yes" << endl;
		}
	}
	else{
		if(h & 1){
			if(w % 4 == 0){
				if(!(c[1] % 2 == 0 && c[1] <= w / 2)){
					cout << "No" << endl;
					return 0;
				}
			}
			else{
				if(!(c[1] & 1 && c[1] <= w / 2)){
					cout << "No" << endl;
					return 0;
				}
			}
		}
		else{
			if(h % 4 == 0){
				if(!(c[1] % 2 == 0 && c[1] <= h / 2)){
					cout << "No" << endl;
					return 0;
				}
			}
			else{
				if(!(c[1] & 1 && c[1] <= h / 2)){
					cout << "No" << endl;
					return 0;
				}
			}
		}

		if(c[0] | c[2]){
			cout << "No" << endl;
		}
		else{
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
const int N=300005;
int n,m,x[N],t[N];
int l[N],r[N];
int ans,cnt,rev;
int main(){
	scanf("%d%d",&n,&m);
	m*=2; ans=1;
	For(i,1,n) scanf("%d",&x[i]);
	For(i,1,n) scanf("%d",&t[i]);
	For(i,1,n){
		int v=t[i]%m;
		ans+=t[i]/m+(v!=0);
		l[i]=(v&&v<=2*x[i]);
		r[i]=(v&&v<=m-2*x[i]);
		//printf("%d %d\n",l[i],r[i]);
	}
	For(i,1,n-1){
		if (r[i]&&cnt){
			if (l[i]) ++rev;
			--ans; --cnt;
		}
		else if (l[i]) ++cnt;
		else if (r[i]&&rev)
			--rev,++cnt;
	}
	if (r[n]) --ans;
	printf("%lld\n",1ll*ans*m);
} 

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#include <bitset>
#include <complex>
#define ll long long
#define INF 1000000000000000001
#define MOD 1000000007
using namespace std;


int main(){
    int N;
    cin >> N;
    int A[15];
    int x[15][15];
    int y[15][15];
    for(int i=0; i<N; i++){
        cin >> A[i];
        for(int j=0; j<A[i]; j++){
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }


    int ans=0;
    for(int i=0; i<(1<<N); i++){
        int shoujiki[15];
        int temp=i;
        for(int k=0; k<N; k++){
            shoujiki[k] = temp%2;
            temp/=2;
        }

        int num = 0;
        for(int i=0; i<N; i++){
            num += shoujiki[i];
        }

        int ok = 1;
        int status[15]={};
        for(int i2=0; i2<N; i2++){
            status[i2] = shoujiki[i2];
        }

        for(int i2=0; i2<N; i2++){  // i2 番目の人の証言
            if(shoujiki[i2]==1){
                for(int j=0; j<A[i2]; j++){
                    if(status[x[i2][j]]==-1){
                        status[x[i2][j]]=y[i2][j];
                    }else if(status[x[i2][j]]!=y[i2][j]){
                        ok=0;
                    }
                }
            }
        }

        if(ok==1){
            ans = max(ans,num);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
k, x = gets.chomp.split(' ').map(&:to_i)
if x - k + 1 < -1000000
    k.times do |i|
        print i-1000000
        print" "
    end
else
    (x-k+1).upto(x+k-1) do |i|
        if i > 1000000
            break
        else
            print i
            print" "
        end
    end
end

Measured memory_bytes: 1788
package main

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

var goods = []int{100, 101, 102, 103, 104, 105}

func solve() {
	x := getInt()

	dp := make([]bool, x+1)
	dp[0] = true

	for i := range dp {
		for _, g := range goods {
			if i-g < 0 {
				continue
			}

			dp[i] = dp[i] || dp[i-g]
		}
	}

	ans := 0
	if dp[x] {
		ans = 1
	}
	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long tmp1 = 0;
        long tmp2 = 0;
        long ans = 0;

        for (int i = 0; i < n; i++) {
            tmp1 = tmp2;
            tmp2 = sc.nextInt();
            long x = tmp1 - tmp2;
            if (x > 0) {
                ans += x;
                tmp2 += x;
            }
        }
        System.out.println(ans);
    }
}


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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    int diffA = abs(x - a);
    int diffB = abs(x - b);

    if(diffA < diffB)
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "B" << endl;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>
#include <iterator>
#include <regex>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template <class T, template <class, class> class C, class charT = char>
void vdump(const C<T, allocator<T>> &v, const charT* delimiter = ", ",
           ostream &stream = cout) {
  copy(v.begin(), v.end(), ostream_iterator<T>(stream, delimiter));
  stream << endl;
}

int main() {
  ios::sync_with_stdio(false);
  ll x, y;
  cin >> x >> y;
  ll ans = 0;
  while(x <= y) {
    x *= 2;
    ans++;
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    char s[n+1];
    scanf("%s", s);
    string t = "abcdefghijklmnopqrstuvwxyz";
    int a[n];
    fill(a,a+n,0);
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 26; j++){
            if(s[i] == t[j]){
                a[i] = j;
                break;
            }
        }
    }

    int dup_max = 0;
    for(int i = 0; i < n-1; i++){
        int b[26];
        fill(b,b+26,0);
        int dup = 0;
        for(int j = 0; j <= i ; j++){
            b[a[j]] = 1;
        }
        for(int j = i+1; j < n ; j++){
            if(b[a[j]] == 1){
                dup++;
                b[a[j]] = 2;
            }
        }
        if(dup > dup_max){
            dup_max = dup;
        }
        
    }
    
    printf("%d\n", dup_max);
    // for(int i = 0; i < n; i++){
    //     printf("%d ", a[i]);
    // }
    // puts("");

}

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

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

    vector<vector<int>> s(n,vector<int>(27));

    for(int i=0;i<n;i++){
    	string x;
    	cin>>x;
    	for (int j=0;j<(int)x.length();j++) s[i][x[j]-'a']++;
    }

	
	string res;
	for(int i=0;i<27;i++){
		int f = 1;
		int mn = INT_MAX;
		for(int st = 0;st<n;st++){
			if(s[st][i]){
				mn = min(mn,s[st][i]);
			} else f = 0;
		}
		if(f){
			for(int ab = 0;ab<mn;ab++) res+=(i+'a');
		}
	}

	cout<<res;

}

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

using namespace std;

int main(void) {
	int lim = 1000000;
	int dp[lim],odp[lim];
	for (int i = 0; i < lim; ++i) {
		dp[i] = i;
		odp[i] = i;
	}

	int num = 4;
	for (int now = 2; num < lim; ++now) {
		for (int i = num; i < lim; ++i) {
			dp[i] = min(dp[i],dp[i-num]+1);
		}
		if (num%2 == 1) {
			for (int i = num; i < lim; ++i) {
				odp[i] = min(odp[i],odp[i-num]+1);
			}
		}
		num = ((now+1)*(now+2)*(now+3))/6;
	}

	int n;
	while (cin >> n, n) {
		cout << dp[n] << " " << odp[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 10876
import java.util.Scanner;

class Main{
	
	
	public static void main(String[] args) {
		new Main().Kei();
	}
	
	void Kei() {
		Scanner sc=new Scanner(System.in);
		int a=Integer.parseInt(sc.next());
		int b=Integer.parseInt(sc.next());
		StringBuilder sb=new StringBuilder();
		sb.append(a);
		sb.append(b);
		double g=Math.sqrt(Integer.parseInt(sb.toString()));
		if(g==(int)g)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
	
}




Measured memory_bytes: 21460
#include <iostream>
#include <algorithm>
using namespace std ;
struct dd{
	int c;
	int t;
}a[105];
int cmp(dd x,dd y){
	return x.c<y.c;
}
int main()
{
	int n,T; cin >> n >>T ;
	for(int i=0;i<n;i++)	cin >>a[i].c >>a[i].t ;
	sort(a,a+n,cmp) ;
	int f=0;
	for(int i=0;i<n;i++){
		if(a[i].t<=T) {
		f=1;cout <<a[i].c;break;}
	}
	if(f==0) cout <<"TLE" ;
    return 0;
}




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

using ll = long long;
#define int ll

int N;
const int nax = 305;
double dp[nax][nax][nax];
vector<int> st(4);

double dfs(int a, int b, int c)
{
	if(a + b + c == 0) return 0.0;
	if(dp[a][b][c] > -1) return dp[a][b][c];
	double ks = (double)N/(a + b + c);
	double ret = 0.0;
	
	if(a)
	{
		ret += (dfs(a-1,b,c) + ks) * a/(a + b + c);
	}
	if(b)
	{
		ret += (dfs(a+1,b-1,c) + ks) * b/(a + b + c);
	}
	if(c)
	{
		ret += (dfs(a,b+1,c-1) + ks) * c/(a + b + c);
	}
	return dp[a][b][c] = ret;
}

int32_t main()
{
	scanf("%lld",&N);
	for(int i=0;i<N;i++)
	{
		int x;
		scanf("%lld",&x);
		st[x]++;
	}
	for(int i=0;i<=N;i++) for(int j=0;j<=N;j++) for(int k=0;k<=N;k++)
	dp[i][j][k] = -1;
	double ret = dfs(st[1],st[2],st[3]);
	printf("%.12lf\n",ret);
	return 0;
}

Measured memory_bytes: 219392
import java.util.Scanner;

public class Main {
  static long a, b, x;

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

    a = sc.nextLong(); b = sc.nextLong();
    x = sc.nextLong();

    long ans = b / x - a / x;
    if(a % x == 0){
      ++ans;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 9808
S = input()
ls = list(S)
N = len(S)

if ls == list(reversed(ls)) and ls[:(N-1)//2] == list(reversed(ls[:(N-1)//2])) and ls[(N+3)//2-1:] == list(reversed(ls[(N+3)//2-1:])):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38256
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// Queue
type Queue<'a> = Queue of ('a list * 'a list)

[<RequireQualifiedAccess>]
[<CompilationRepresentation(CompilationRepresentationFlags.ModuleSuffix)>]
module Queue =
  let empty = Queue([], [])
  let ofList l = Queue(l, [])
  let singleton x = Queue([x], [])
  let private check (Queue(f, r)) =
    match (f, r) with
    | ([], _) -> Queue(List.rev r, [])
    | _ -> Queue(f, r)
  let snoc x (Queue(f, r)) = Queue(f, x::r) |> check
  let head (Queue(f, _)) = List.head f
  let tryHead (Queue(f, _)) = List.tryHead f
  let tail (Queue(f, r)) =
    match f with
    | [] -> failwith "queue is empty"
    | _::f -> Queue(f, r) |> check
  let tryUncons (Queue(f, r)) =
    match f with
    | [] -> None
    | x::f -> Some(x, Queue(f, r) |> check)
  let (|Cons|Nil|) q =
    match tryUncons q with
    | Some(h,t) -> Cons(h, t)
    | None -> Nil
// Queue

// start
let (N,M) = readPair int int ()
let g = Array.init N (fun _ -> ResizeArray<int>())
for _ in 1..M do
  let (A,B) = readPair int int ()
  g.[A-1].Add (B-1)
  g.[B-1].Add (A-1)

let route =
  let r = Array.create N (-1)
  let rec bfs = function
    | Queue.Nil -> ()
    | Queue.Cons (x, que) ->
      g.[x]
      |> Seq.fold (
        fun q y ->
          if r.[y]>=0 then q
          else
            r.[y]<-x
            q |> Queue.snoc y
      ) que
      |> bfs
  bfs (Queue.singleton 0)
  r

printfn "Yes"
for i in 1..(N-1) do
  printfn "%d" (1+route.[i])

Measured memory_bytes: 55924
#pragma GCC optimize "-O3"
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pip pair<int, pii >
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;
const int N = 505;

using namespace std;

int n, p[N*N];
int d[N][N], o[N][N];

stack<pip > q;
void upd(){
	while(!q.empty()){
		pip c = q.top();
		q.pop();
		c.F = -c.F;
		int i = c.S.F, j = c.S.S;
		if(d[i][j] < c.F) continue;
		d[i][j] = c.F;
		if(d[i][j]+o[i-1][j] < d[i-1][j]) q.push({-d[i][j]-o[i-1][j], {i-1, j}});
		if(d[i][j]+o[i+1][j] < d[i+1][j]) q.push({-d[i][j]-o[i+1][j], {i+1, j}});
		if(d[i][j]+o[i][j-1] < d[i][j-1]) q.push({-d[i][j]-o[i][j-1], {i, j-1}});
		if(d[i][j]+o[i][j+1] < d[i][j+1]) q.push({-d[i][j]-o[i][j+1], {i, j+1}});
	}
}

int main(){

	cin.tie(0);
	ios_base::sync_with_stdio(0);

	cin >> n;
	for(int i=0; i<n*n; i++) cin >> p[i];
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			o[i][j] = 1;
			d[i][j] = min(min(i, n-i+1), min(j, n-j+1));
		}
	}

	int ans = 0;

	for(int k=0; k<n*n; k++){
		int i = 1+(p[k]-1)/n, j = 1+(p[k]-1)%n;
		ans += d[i][j]-1;
		o[i][j] = 0;
		q.push({-(d[i][j]-1), {i, j}});
		upd();
	}

	cout << ans << endl;

	return 0;
}


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

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

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

typedef long long ll;

void solve(std::string S)
{
    if (S == "SUN")
    {
        cout << "7" << endl;
    }
    if (S == "MON")
    {
        cout << "6" << endl;
    }
    if (S == "TUE")
    {
        cout << "5" << endl;
    }
    if (S == "WED")
    {
        cout << "4" << endl;
    }
    if (S == "THU")
    {
        cout << "3" << endl;
    }
    if (S == "FRI")
    {
        cout << "2" << endl;
    }
    if (S == "SAT")
    {
        cout << "1" << endl;
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
x, y = gets.split(" ").map(&:to_i)

a = x*2 - y/2
b = x - a

if b >= 0 && a >= 0 && (b * 2) % 2 == 0 && (b * 2) % 2 == 0 && y % 2 == 0
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 14352
// template
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<long long, long long> LP;
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define REP_AB(i, a, b) for (ll i = ll(a); i <= ll(b); ++i)
#define ALL(v) v.begin(), v.end()
#define SORT(v) sort(ALL(v))
#define UNIQUE(v) sort(ALL(v));v.erase(unique(ALL(v)), v.end());
#define SIZE(x) ((ll)(x).size())
#define REVERSE(v) reverse(ALL(v))
// true / false
#define BIN_SEARCH(v, a) binary_search(ALL(v), a)
// index
#define BIN_LEFT(v, a) (lower_bound(ALL(v), a) - v.begin())
#define BIN_RIGHT(v, a) (upper_bound(ALL(v), a) - v.begin())
#define BIN_INSERT(v, a) (v.insert(v.begin() + BIN_LEFT(v, a), a))
#define DEL(v, i) v.erase(v.begin() + i)
#define INSERT(v, i, a) v.insert(v.begin() + i, a)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a / gcd(a, b)) * b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define out cout
#define in cin
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
// template end
 
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll N;
    in >> N;

    if(N<10){
        out << N << endl;
    }else if(N<100 || N==10){
        out << 9 << endl;
    }else if(N<200){
        out << 9 + N -((N/100) * 100) + 1 << endl;
    }else if(N<1000){
        out << 9 + N - 100 + 1 << endl;
    }else if(N<10000 || N==1000){
        out << 909 << endl;
    }else if(N<2000){
        out << 9 + 900 + N-((N/10000) * 10000) + 1 << endl;
    }else if(N<100000){
        out << 9 + 900 + N - 10000 + 1 << endl;
    }else if(N==100000){
        out << 9 + 900 + 90000 << endl;
    }
 

 

}

Measured memory_bytes: 256
from collections import defaultdict
N, M = map(int, input().split())
heights = list(map(int, input().split()))
d = defaultdict(list)
for i in range(M):
    A, B = map(int, input().split())
    d[A].append(B)
    d[B].append(A)
ans_cnt = 0
for i in range(1, N + 1):
    if d[i] == []:
        ans_cnt += 1
    else:
        my_height = heights[i - 1]
        flag = True
        for j in d[i]:
            if heights[j - 1] >= my_height:
                flag = False
                break
        if flag:
            ans_cnt += 1
print(ans_cnt)


Measured memory_bytes: 36796
#include <bits/stdc++.h>
#define int long long
using namespace std;

long long K;
int N;
int A[200005];
int dist[200005];

int32_t main() {
  scanf("%lld %lld", &N, &K);
  for(int i = 1; i <= N; i++) {
    scanf("%lld", &A[i]);
  }
  int now = 1;
  dist[1] = 1;
  while(1) {
    if(dist[A[now]] != 0) {
      if(K <= dist[A[now]] - 1) {
        now = 1;
        break;
      }
      K -= dist[A[now]] - 1;
      K %= dist[now] + 1 - dist[A[now]];
      now = A[now];
      break;
    }
    dist[A[now]] = dist[now] + 1;
    now = A[now];
  }
  while(K--) {
    now = A[now];
  }
  printf("%lld\n", now);
}

Measured memory_bytes: 6888
/*
 * ALDS1_11_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>

using namespace std;

int d[101];
int f[101];
int nowTime;

void dfsRec(vector<int>* a, int n, int v) {
	if(d[v] > 0) return;
	nowTime++;
	d[v] = nowTime;
	for(int &x:a[v]) {
		dfsRec(a, n, x);
	}
	nowTime++;
	f[v] = nowTime;
}

int main() {
	int n;
	vector<int> adj[101];

	cin >> n;
	for(int i=0; i<n; i++) {
		int v;
		int k;
		cin >> v >> k;
		for(int j=0; j<k; j++) {
			int u;
			cin >> u;
			adj[v].push_back(u);
		}
	}

	for(int i=1; i<=n; i++) {
		if(d[i] ==0) dfsRec(adj, n, i);
	}

	for(int i=1; i<=n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
}





Measured memory_bytes: 3084
fun main(args: Array<String>) {
    val (M, D) = listOfInt()
    fun check(m: Int, dd: Int): Boolean {
        val (d10, d1) = listOf(dd / 10, dd % 10)
        if (d10 < 2 || d1 < 2) return false
        return m == d1 * d10
    }
    var ans = 0
    for (m in 1..M) {
        for (d in 1..D) {
            if (check(m, d)) {
                ans++
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }


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

int main(){
    int n;
    int w[100];
    cin >> n;
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> w[i];
        sum += w[i];
    }
    int ans=1000000;
    int now=0;
    for(int i=0;i<n;i++){
        now += w[i];
        ans=min(ans,abs(sum-now-now));
        // if(abs(sum-2*now)<=ans){
        //     ans = abs(sum-2*now);
        // }
    }
    cout << ans;
    return 0;
}
//今回の学び 
// １．絶対値にする関数abc()は引数が１つのみ。
// 
// 
// 
// 
// 
//

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(0, c - (a - b)) << endl;
}

Measured memory_bytes: 3644
import sys
import math
#n = int(input())
a, b, c = map(int, input().split())
#s = input()
#p = list(map(int, input().split()))

if a == b:
  if a == c:
    print("No")
  else:
    print("Yes")

else:
  if a == c:
    print("Yes")
  else:
    if b == c:
      print("Yes")
    else:
      print("No")



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

using namespace std;

int const maxn = 1005;
int a[maxn], b[maxn];
int dp[11005];
int inf = 1e9;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int h, n;
    cin >> h >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    for (int i = 1; i <= 11000; ++i) {
        dp[i] = inf;
        for (int j = 1; j <= n; ++j) {
            if (i - a[j] >= 0) dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
        }
    }
    int ans = inf;
    for (int i = h; i <= 11000; ++i) ans = min(ans, dp[i]);
    cout << ans;
    return 0;
}



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

using namespace std;
using ll = long long;

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back

int main()
{
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N), v(N);
    REP(i,0,N) cin >> w[i] >> v[i];

    vector<vector<ll>> dp(N+1, vector<ll>(W+1, 0));

    REP(i,0,N) {
        REP(j,0,W+1) {
            if (j - w[i] >= 0) dp[i+1][j] = MAX(dp[i+1][j],dp[i][j-w[i]]+v[i]);
            dp[i+1][j] = MAX(dp[i+1][j],dp[i][j]);
        }
    }

    _PR(dp[N][W]);

    return 0;
}

/*



*/

Measured memory_bytes: 80256
import itertools
n=int(input())
lst=[list(map(int,input().split())) for i in range(n)]
per=[i for i in itertools.permutations(range(n))]
ans=0
for i in per:
  for j in range(n-1):
    ans+=pow((lst[i[j]][0]-lst[i[j+1]][0])**2+(lst[i[j]][1]-lst[i[j+1]][1])**2,0.5)
print(ans/len(per))


Measured memory_bytes: 81000