akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    vector<int> num(26, 100000);
    int n; cin >> n;
    REP(i, n){
        string s; cin >> s;
        vector<int> cnt(26, 0);
        REP(j, s.length()){
            ++cnt[s[j] - 'a'];
        }
        REP(j, 26) num[j] = min(num[j], cnt[j]);
    }
    
    REP(i, 26){
        REP(j, num[i]) cout << char('a' + i);
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int par[100010];
int r[100010];

struct memo{
  int x,y,num;
};

struct route{
  int from,to,cost;
};

bool cmp_x(const memo& a, const memo& b){
  return a.x < b.x;
}

bool cmp_y(const memo& a, const memo& b){
  return a.y < b.y;
}

bool cmp(const route& a, const route& b){
  return a.cost < b.cost;
}

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;
    r[i]=0;
  }
}

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

void unite(int x,int y){
  int rx=root(x), ry=root(y);
  if(rx==ry) return;
  if(r[rx]<r[ry]) par[rx]=ry;
  else{
    par[ry]=rx;
    if(r[rx]==r[ry]) r[rx]++;
  }
  return;
}

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

int main() {
  int n;
  cin>>n;
  memo p[n];
  for(int i=0;i<n;i++){
    memo m;
    int x,y;
    cin>>x>>y;
    m.x=x,m.y=y,m.num=i;
    p[i]=m;
  }
  route ans[2*(n-1)];
  sort(p,p+n,cmp_x);
  for(int i=0;i<n-1;i++){
    route r1;
    r1.from=p[i].num,r1.to=p[i+1].num,r1.cost=abs(p[i+1].x-p[i].x);
    ans[i]=r1;
  }
  sort(p,p+n,cmp_y);
  for(int i=0;i<n-1;i++){
    route r1;
    r1.from=p[i].num,r1.to=p[i+1].num,r1.cost=abs(p[i+1].y-p[i].y);
    ans[n-1+i]=r1;
  }
  sort(ans,ans+2*(n-1),cmp);
  ll res=0;
  init(n);
  for(int i=0;i<2*(n-1);i++){
    route e=ans[i];
    if(!same(e.from,e.to)){
      unite(e.from,e.to);
      res+=e.cost;
    }
  }
  cout<<res<<endl;
  return 0;
}


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

int main(){

int N, K;
  cin >> N >> K;
int ichi, ans;

    if((N - 1) % (K - 1) == 0) ans += (N - 1) / (K - 1);
    else ans += (N - 1) / (K - 1) + 1;
    
cout << ans << 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 ll = long long;
using P = pair<int,int>;
using namespace std;

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

    double res = ((a+1) / 2) / (double)a;

    cout << res << endl;
    return 0;
}


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

int main() {
  int N;
  scanf("%d", &N);

  int res=1, sub=1;
  for (int i=0; i<N; ++i) {
    int a;
    scanf("%d", &a);
    res *= 3;
    if ((a & 1) == 0) {
      sub *= 2;
    }
  }

  printf("%d\n", res-sub);
  return 0;
}


Measured memory_bytes: 128
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from math import gcd
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gcd
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]

mod=10**9+7

s=I()
A=[0]*(s+1)
acc=[0]*(s+1)
for i in range(1,s+1):
    if i<=3:
        A[i]=0
    else:
        A[i]=acc[i-3]
    if i>=3:
        A[i]+=1
    A[i]%=mod
    acc[i]=acc[i-1]+A[i]
    acc[i]%=mod

print(A[s])







Measured memory_bytes: 77016
#include<iostream>
#include<unordered_map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
using namespace std;
bool so(pair<pair<string, int>, int> a, pair<pair<string, int>, int> b){
  if(a.first.first != b.first.first){
    return a.first.first < b.first.first;
  }
  return a.first.second > b.first.second;
}
int main(){
  int N;
  cin >> N;
  
  vector<pair<pair<string, int>, int>> SP;
  
  string s;
  int p;
  for(int i = 0; i < N; i++){
    cin >> s >> p;
    SP.push_back( make_pair(make_pair(s, p), i+1));
  }
  sort(SP.begin(), SP.end(), so);
  
  for(auto sp: SP){
  cout << sp.second << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll
#define INF 1e16
#define mod 1000000007
int main(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a!=c) cout<<1<<endl;
    else cout<<0<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include<iostream>
#define LL long long 
int N;
LL mod = 1e9 + 7;
int ap[100010];
LL kai[100010];
LL dis[100010];
int l, r;

LL fermat(LL x, int y) {
	if (y == 0)return 1;
	if (y == 1)return x;
	LL F = fermat(x, y / 2);
	F *= F;
	F %= mod;
	if (y % 2)return(F*x) % mod;
	else return F;
}


int main() {
	std::cin >> N;
	N++;
	kai[0] = 1;
	for (int i = 1; i <= N; i++) {
		kai[i] = (kai[i - 1] * i) % mod;
	}
	dis[N] = fermat(kai[N], mod - 2);
	for (int i = N; i >= 1; i--) {
		dis[i - 1] = (dis[i] * i) % mod;
	}
	for (int i = 1; i <= N; i++) {
		int tmp;
		std::cin >> tmp;
		if (ap[tmp]) {
			l = ap[tmp] -1;
			r = N - i;
		}
		else {
			ap[tmp] = i;
		}
	}
	for (int i = 1; i <= N; i++) {
		LL ans = kai[N] * dis[i];
		ans %= mod;
		ans *= dis[N - i];
		ans %= mod;
		if (l + r - i + 1 >= 0) {
			LL M = (kai[l + r] * dis[l + r - i + 1]) % mod;
			M *= dis[i - 1];
			M %= mod;
			ans -= M;
		}
		if (ans < 0)ans += mod;
		std::cout << ans<< std::endl;
	}
}

Measured memory_bytes: 3200
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]


def dfs(cur, a, b, c):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30
        else:
            return float("inf")

    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + L[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + L[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + L[cur]) + 10

    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        label:
        WriteLine(hoge() ? "Yes" : "No");
        //goto label;
    }
    static bool hoge()
    {
        SortedList<char, List<int>> list1 = new SortedList<char, List<int>>(), list2 = new SortedList<char, List<int>>();
        var line = ReadLine();
        for (int i = 0; i < line.Length; ++i)
        {
            char c = line[i];
            if (!list1.ContainsKey(c)) list1.Add(c, new List<int>());
            list1[c].Add(i);
        }
        line = ReadLine();
        for (int i = 0; i < line.Length; ++i)
        {
            char c = line[i];
            if (!list2.ContainsKey(c)) list2.Add(c, new List<int>());
            list2[c].Add(i);
        }
        if (list1.Count != list2.Count) return false;
        var val1 = list1.Values.ToList();
        var val2 = list2.Values.ToList();
        return val1.TrueForAll(li1 => val2.Exists(li2 => piyo(li1, li2)));
    }

    static bool piyo(List<int> lhs, List<int> rhs)
    {
        if (lhs.Count != rhs.Count) return false;
        for (int i = 0; i < lhs.Count; ++i)
        {
            if (lhs[i] != rhs[i]) return false;
        }
        return true;
    }
}


Measured memory_bytes: 19808
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

int a[10],k,ans;

int main() {
	scanf("%d %d %d %d",&a[0],&a[1],&a[2],&k);
	sort(a,a+3);
	ans=pow(2,k)*a[2]+a[0]+a[1];
	printf("%d\n",ans);
}

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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;

int lenA;
ll cnt[N];
ll ans;

string A;

main () {
        cin >> A;

        lenA = (int) A.size();

        ans = (lenA - 1) * 1ll * lenA / 2 + 1;

        for (int i = 0; i < lenA; i ++) {
                cnt[A[i] - 'a'] ++;
        }

        for (int i = 0; i <= 25; i ++) {
                ans -= (cnt[i] * 1ll * (cnt[i] - 1)) / 2;
        }

        printf("%lld", ans);
}


Measured memory_bytes: 640
//khodaya khodet komak kon
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")


using namespace std;

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

const int N = 2000 + 10;
const ll MOD = 924844033;
const ll INF = 1000000010;
const ll LOG = 25;

int n, K, a[N], DP[N][N][4], dp[N][N], fac[N];
vi M[N];

int add(int a, int b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int mul(int a, int b){
	return (a * 1ll * b % MOD);
}

int minu(int a, int b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}

int32_t main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> K;
	for (int i = 0; i < N; i++) fac[i] = (i == 0?1:mul(fac[i - 1], i));
//	cout << fac[n] << '\n';
	for (int i = 1; i <= n; i++){
		M[i % K].pb(i);
	}
	DP[0][0][0] = 1;
	for (int i = 0; i < N - 1; i++)for (int j = 0; j <= i; j++) for( int l = 0; l < 4; l++){
		if (i != 0){
			if ((l & (1 << 1)) == 0){
				DP[i + 1][j + 1][(l & 1) << 1] = add(DP[i + 1][j + 1][(l & 1) << 1], DP[i][j][l]);
			} 
		}
		DP[i + 1][j + 1][((l & 1) << 1) | 1] = add(DP[i + 1][j + 1][((l & 1) << 1) | 1], DP[i][j][l]);
		DP[i + 1][j][(l & 1) << 1] = add(DP[i + 1][j][(l & 1) << 1], DP[i][j][l]);
//		cout << i << ' ' << j << ' ' << l << ' ' << DP[i][j][l] << '\n'; 
	}
	int sz = 0;
	dp[0][0] = 1;
	for (int i = 1; i <= K; i++){
		for (int j = 0; j <= sz; j++)for (int k = 0; k <= M[i - 1].size(); k++){
			dp[i][j + k] = add(dp[i][j + k], mul(dp[i - 1][j], add(DP[M[i - 1].size()][k][0], DP[M[i - 1].size()][k][2])));
		}
		sz += M[i - 1].size();
//		cout << sz << '\n';
	} 
	int ans = 0;
	for (int i = 0; i <= n; i++){
		if (i % 2 == 0){
			ans = add(ans, mul(fac[n - i], dp[K][i]));
		}else ans = minu(ans, mul(fac[n - i], dp[K][i]));
	}	
	cout << ans;









	return 0;
}


Measured memory_bytes: 56568
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <chrono>
 
using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T>inline bool chmax(T &a, T b){return (a < b ? a = b, true : false);}
template<typename T>inline bool chmin(T &a, T b){return (a > b ? a = b, true : false);}
 
const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;
const long double EPS = 1e-6;
 
const int MAX = 55;
LL N, A, B;
LL v[MAX];
 
LL comb(LL n,LL r){LL res = 1;RREP(i,r){res*=(n-i);res/=(r-i);}return res;}
 
int main() {
	scanf("%lld%lld%lld", &N, &A, &B);
	REP(i, N) {
		scanf("%lld", v + i);
	}
	sort(v, v + N);
	reverse(v, v + N);
	LL sum = 0;
	long double maave = 0;
	VI idxs;
	REP(i, B) {
		sum += v[i];
		if (i + 1 >= A) {
			maave = (long double)sum / (i + 1);
			break;
		}
	}
	sum = 0;
	REP(i, B) {
		sum += v[i];
		if (i + 1 >= A) {
			if (maave == ((long double)sum / (i + 1))) {
				idxs.EB(i + 1);
			}
		}
	}
	cout << fixed << setprecision(10) << maave << endl;
	LL ans = 0;
	FORE(e, idxs) {
		assert(A <= e && e <= B);
		map<LL, int> mp, mp2;
		REP(i, e) {
			mp[v[i]]++;
		}
		FOR(i, e, N) {
			mp2[v[i]]++;
		}
		LL pre = 1;
		FORE(e, mp2) {
			pre *= comb(e.second + mp[e.first], mp[e.first]);
		}
		ans += pre;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  def modPow(x: Long, n: Long, mod: Long): Long = {
    if(n == 0){
      1
    } else {
     val r = modPow(x * x % mod, n / 2, mod)
      if(n % 2 != 0){
        r * x % mod
      } else {
        r
      }
    }
  }

  val a = StdIn.readLine().split(' ').map(_.toInt)

  println(modPow(a(0), a(1), 1000000007))

}


Measured memory_bytes: 43996
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> vec1(3);
  vector<int> vec2(3);
  vector<int> vec3(3);
  
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> vec1.at(i);
  }
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> vec2.at(i);
  }
  for ( int i = 0 ; i < 3 ; i++ ) {
    cin >> vec3.at(i);
  }
  
  int n;
  cin >> n;
  vector<int> num(n);
  for ( int i = 0 ; i < n ; i++ ) {
    cin >> num.at(i);
  }
  
  for (int i = 0 ; i < n ; i++ ) {
    for ( int j = 0 ; j < 3 ; j++ ) {
      if (vec1.at(j) == num.at(i) ) {
        vec1.at(j) = 0;
      }
      if (vec2.at(j) == num.at(i) ) {
        vec2.at(j) = 0;
      }
      if (vec3.at(j) == num.at(i) ) {
        vec3.at(j) = 0;
      }
    }
  }
  
  if ( vec1.at(0) == 0 && vec1.at(1) == 0 && vec1.at(2) == 0 ) {
    cout << "Yes" << endl;
  }
  else if ( vec2.at(0) == 0 && vec2.at(1) == 0 && vec2.at(2) == 0 ) {
    cout << "Yes" << endl;
  }
  else if ( vec3.at(0) == 0 && vec3.at(1) == 0 && vec3.at(2) == 0 ) {
    cout << "Yes" << endl;
  }
  else if ( vec1.at(0)==0 && vec2.at(0) ==0 && vec3.at(0)==0  ){
    cout << "Yes" << endl;
  }
  else if ( vec1.at(1)==0 && vec2.at(1) ==0 && vec3.at(1)==0  ){
    cout << "Yes" << endl;
  }
  else if ( vec1.at(2)==0 && vec2.at(2) ==0 && vec3.at(2)==0  ){
    cout << "Yes" << endl;
  }
  else if ( vec1.at(0)==0 && vec2.at(1) ==0 && vec3.at(2)==0  ){
    cout << "Yes" << endl;
  }
  else if ( vec1.at(2)==0 && vec2.at(1) ==0 && vec3.at(0)==0  ){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
 }

Measured memory_bytes: 256
import           Control.Monad
import           Data.List

main :: IO ()
main = do
    [h, _] <- fmap (map read . words) getLine :: IO [Int]
    ass    <- replicateM h $ getLine :: IO [String]
    printgrid $ transpose . del . transpose . del $ ass

del :: [String] -> [String]
del = filter (\s -> not . all (== '.') $ s)

printgrid :: [String] -> IO ()
printgrid []       = return ()
printgrid (s : ss) = do
    putStrLn s
    printgrid ss


Measured memory_bytes: 1788
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7
def modinv(a, mod=10**9+7):
    return pow(a, mod-2, mod)

fac = [0]*(N+1)
fac[0] = 1
fac[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1] * i % mod

def combi(n,r,mod=10**9+7):
    return( ( fac[n] * modinv(fac[r]) )%mod * modinv(fac[n-r]) % mod)

A.sort()
ans = 0
for i in range(1, N-K+2):
    ans += combi(N-i, K-1)*A[N-i] % mod
    ans += mod
    ans -= combi(N-i, K-1)*A[i-1] % mod

print(ans%mod)

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

typedef signed long long ll;
const int MX = 1e3 + 5;

int main() {
    int a, b, c;
    cin >> a >> b;
    c = a + b;
    (c >= 10) ? cout << "error\n" : cout << c << "\n";
    return 0;
}

Measured memory_bytes: 256
n=int(input())
s = []
for _ in range(n):
        s.append(int(input()))

sm=0
for num in s:
        sm+=num

if sm %10 != 0:
        print(sm)
        exit()

s.sort()
for num in s:
        if num%10!=0:
                print(sm-num)
                exit()
print(0)

Measured memory_bytes: 3060
(* 本当に辛い *)
let array_map2 f a b =
    let l = Array.length a in
    if l = 0 then [||] else begin
        let r = Array.make l (f (Array.unsafe_get a 0) (Array.unsafe_get b 0)) in
        for i = 0 to l - 1 do
            Array.unsafe_set r i (f (Array.unsafe_get a i) (Array.unsafe_get b i))
        done;
        r
    end

let () = Scanf.scanf "%d %d %d\n" @@ fun n m c ->
    let b = Array.init m (fun _ ->
        Scanf.scanf " %d" (fun b -> b)) in
    Array.init n (fun _ ->
        Scanf.scanf "\n" (fun _ -> ()) 0;
        let a = Array.init m (fun _ ->
            Scanf.scanf " %d" (fun a -> a)) in
        let t = array_map2 (fun a b -> a * b) a b
        |> Array.fold_left (+) 0 in
        if t + c > 0
        then 1
        else 0)
    |> Array.fold_left (+) 0
    |> Printf.printf "%d"


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>

int a[50];

int main()
{
	int N, P;
	int a0 = 0, a1 = 0;
	scanf("%d%d", &N, &P);
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
		if (a[i] % 2 == 0) {
			a0++;
		} else {
			a1++;
		}
	}
	unsigned long long res = 0;
	res = 1ULL<<a0;
	unsigned long long res2 = 0;
	unsigned long long cur = 1;
	for (int i = 0; i <= a1; i++) {
		if (i%2 == P) {
			res2 += cur;
		}
		cur = cur * (a1 - i) / (i + 1);
	}
	res *= res2;
	printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 128
h, w = [int(i) for i in input().split()]
s = [[0 for i in range(w)] for j in range(h)]
s2 = [['.' for i in range(w + 2)] for j in range(h + 2)]

for i in range(1, h + 1):
    input_str = input()
    for j in range(1, w + 1):
        s2[i][j] = input_str[j - 1]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s2[i][j] == "#":
            if s2[i - 1][j] == "." and s2[i + 1][j] == "." and s2[i][j - 1] == "." and s2[i][j + 1] == ".":
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n, max_w = map(int, input().split())

dp = [-1 for _ in range(max_w + 1)]
dp[0] = 0

for i in range(n):
    w, v = map(int, input().split())
    queue = list()
    for i in range(max_w, w - 1, -1):
        dp[i] = max(dp[i], dp[i - w] + v)

print(max(dp))

Measured memory_bytes: 44912
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

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

int main() {
  string S, T;
  cin >> S >> T;
  int result = 0;
  REP(i, S.size()) {
    if (S[i] != T[i]) {
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3924
#include<iostream>
#include<climits>
#define MAX 500001
using namespace std;
void merge(int*, int, int, int);
void mergeSort(int*, int, int);
int cnt = 0;
int main() {
	int n, A[MAX];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}
		mergeSort(A, 0, n);
	for (int i = 0; i < n; i++) {
		cout << A[i];
		if (i != n - 1) {
			cout << " ";
		}
		else {
			cout << endl;
		}
	}
	cout << cnt << endl;
}

void merge(int *A, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	int L[MAX], R[MAX];
		for (int i = 0; i < n1; i++) {
		L[i] = A[left + i];
			}
		for (int i = 0; i < n2; i++) {
		R[i] = A[mid + i];
			}
		L[n1] = INT_MAX;
	R[n2] = INT_MAX;
	int i = 0, j = 0;
	for (int k = left; k < right; k++) {
		cnt++;
		if (L[i] <= R[j]) {
			A[k] = L[i];
			i++;
		}
		else {
			A[k] = R[j];
			j++;
		}
	}
}


void mergeSort(int *A, int left, int right) {
	if (left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

Measured memory_bytes: 6920
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		long K = in.nextLong();
		int[][] ab = new int[N][2];
		for (int i = 0; i < N; i++) {
			ab[i][0] = in.nextInt();
			ab[i][1] = in.nextInt();
		}
		Arrays.sort(ab, (x, y) -> Integer.compare(x[0], y[0]));
		int index = 0;
		while (K > 0) {
			K -= ab[index][1];
			index++;
		}
		System.out.println(ab[index - 1][0]);
		in.close();
	}
}

Measured memory_bytes: 94752
from __future__ import print_function

from functools import reduce
from operator import mul
from collections import Counter
from collections import deque
from itertools import accumulate
from queue import Queue
from queue import PriorityQueue as pq
from heapq import heapreplace
from heapq import heapify
from heapq import heappushpop
from heapq import heappop
from heapq import heappush
import heapq
import time
import random
import bisect
import itertools
import collections
from fractions import Fraction
import fractions
import string
import math
import operator
import functools
import copy
import array
import re
import sys
sys.setrecursionlimit(500000)


input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    l = int(input().strip())
    print(l**3 / 27)


if __name__ == '__main__':
    main()


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

void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0); 
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}

int main() {
  ll n;
  string s;
  cin >> n >> s;
  if (s.length() <= n) {
    cout << s;
  } else {
    cout << s.substr(0, n) + "...";
  }
  return 0;
}

Measured memory_bytes: 3632
/*
 * ARC092_C.cpp
 *
 *  Created on: May 19, 2018
 *      Author: 13743
 */
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<cstring>
using namespace std;
typedef long long lng;
typedef unsigned long long ulng;

#define pb push_back
#define SZ(a) int((a).size())
#define ALL(a) (a).begin(), (a).end
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

lng power(lng b, lng e) {lng sol=1; while(e>0) {if(e&1) {sol=sol*b;} e>>=1; b*= b;} return sol;}

void quickSort(int l, int r, int* a, int* b) {
	if(l >= r) return;
	int piv = a[r];
	int i = l - 1;
	for(int j=l; j<r; j++) {
		if(a[j] <= piv) {
			i++;
			swap(a[i], a[j]);
			swap(b[i], b[j]);
		}
	}
	swap(a[i+1], a[r]);
	swap(b[i+1], b[r]);
	quickSort(l, i, a, b);
	quickSort(i+2, r, a, b);
}

int rx[101];
int ry[101];
int bx[101];
int by[101];

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

	int N;
	cin>> N;
	REP(i, N) {
		cin >> rx[i] >> ry[i];
	}
	REP(i, N) {
		cin >> bx[i] >> by[i];
	}
	rx[100] = ry[100] = -1;

	int ans = 0;
	quickSort(0, N-1, bx, by);
	REP(i, N) {
		int red = 100;
		REP(j, N) {
			if(rx[j] < bx[i] && ry[j] < by[i] && ry[j] > ry[red]) {
				red = j;
			}
		}
		if(red != 100) {
			++ans;
			rx[red] = ry[red] = -1;
		}
	}

	cout << ans << endl;
}






Measured memory_bytes: 256
use proconio::input;
use proconio::marker::{Bytes, Chars, Isize1, Usize1};

fn main() {
    input! {
        d: usize,
        t: usize,
        s: usize
    }

    if s*t >= d {
        println!("Yes")
    } else {
        println!("No")
    }
}

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

int main(){

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

    map<int, int> dict;
    for (int i=0; i<k; i++){
        int l, r;
        l = a+i;
        r = b-i;
        if (l <= b && r >= a){
            dict[l];
            dict[r];
        }
    }

    for (auto p: dict){
        auto key = p.first;
        cout << key << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
struct station{
	double x,y,z,r;
};
double dist(station &a,station &b){
	return pow(pow(a.x-b.x,2)+pow(a.y-b.y,2)+pow(a.z-b.z,2),0.5)-a.r-b.r;
}
int uft[100];
void init(){
	for(int i = 0; i < 100; ++i) uft[i] = i;
}
int find(int v){
	if(uft[v] == v) return v;
	else return uft[v] = find(uft[v]);
}
void uni(int v,int w){
	uft[find(w)] = find(v);
}
typedef pair<double,pair<int,int> > P;
int main(){
	int n;
	while(cin >> n,n){
		init();
		station s[100];
		for(int i = 0; i < n; ++i){
			cin >> s[i].x >> s[i].y >> s[i].z >> s[i].r;
		}
		P p[10000];
		int m = 0;
		for(int i = 0; i < n; ++i)for(int j = 0; j < n; ++j){
			double d = dist(s[i],s[j]);
			if(d > 0) p[m++] = P(d,pair<int,int>(i,j));
			else uni(i,j);
		}
		sort(p,p+m);
		double sum = 0;
		for(int i = 0; i < m; ++i){
			if(find(p[i].second.first) != find(p[i].second.second)){
				sum += p[i].first;
				uni(p[i].second.first,p[i].second.second);
			}
		}
		printf("%.3f\n",sum);
	}
}

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

#define fr(i,n) for(int i = 0; i<n; i++)
#define sz(v) (int)(v.size())
#define prin(a) cout << #a << " = " << a << endl
#define all(v) (v).begin(),(v).end()

const int N = 2e3+10;
int cnt[N];

int vis[N];
int dist[N];
vector<int> g[N];

void bfs(int o){
	queue<pair<int,int>> q;
	memset(vis,0,sizeof(vis));
	vis[o] = 1;
	q.emplace(0,o);
	
	while(!q.empty()){
		int d, no; tie(d,no) = q.front(); q.pop();
		dist[no] = d;
		for(auto &it : g[no]){
			if(!vis[it]){
				vis[it] = 1;
				q.emplace(d+1,it);
			}
		}
	}
}

int main(){
	int n, x, y; cin >> n >> x >> y;
	x--,y--;
	
	fr(i,n-1) g[i].push_back(i+1), g[i+1].push_back(i);
	g[x].push_back(y);
	g[y].push_back(x);
	
	fr(i,n){
		bfs(i);
		for(int j = i+1; j<n; j++) cnt[dist[j]]++;		
	}
	
	fr(i,n-1) printf("%d\n", cnt[i+1]);
}

Measured memory_bytes: 384
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n, m; readV(n, m);
  int[] l, r; readC(m, l, r);

  writeln(max(0, r.reduce!min - l.reduce!max + 1));
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
typedef  unsigned long long ull;
const double EPS= (1e-9);
using namespace std;
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void SP(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
map<string ,int> mb;
string st;
vector< pair<int,int> > v;
int par[100009];
void I()
{
    for(int i=1;i<=100001;i++)
    {
        par[i]=i;
    }
}
int get_par(int n)
{
    if(par[n]==n)
        return n;
    return par[n]=get_par(par[n]);
}
void lnk(int a,int b)
{
    par[a]=b;
}
int main()
{
    SP();
    I();
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.pb(mp(b,-a));
    }
    sort(allr(v));
    int cur=m;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        int n1=-v[i].second;
        if(n1>m)
            continue;
        int n2=get_par(n1);
        if(n2==m+1)
            continue;
        ans+=v[i].first;
        lnk(n2,n2+1);
    }
    cout<<ans<<endl;

}



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

void solve() {
    ll X;
    cin >> X;
    for (int a = -118; a <= 119; ++a) {
        for (int b = -119; b <= 118; ++b) {
            if (a*a*a*a*a - b*b*b*b*b == X) {
                printf("%d %d\n", a, b);
                return;
            }
        }
    }
}

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


Measured memory_bytes: 3752
/*
[abc126] E - 1 or 2
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 1e5;
const int MAX_M = 1e5;

int N, M;
vector<int> g[MAX_N];
bool visited[MAX_M];

void dfs(int v) {
    if (visited[v]) {
        return;
    }
    visited[v] = true;
    for (int to : g[v]) {
        dfs(to);
    }
}

ll solve() {
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (!visited[i]) {
            ans++;
            dfs(i);
        }
    }
    return ans;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    cout << solve() << endl;

    return 0;
}


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

typedef long long ll;

#define pb push_back
#define mkp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define clr(a, b) memset(a, b, sizeof(a))
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1e5 + 5;
int a[N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int n;
    cin >> n;
    forn(i, n) cin >> a[i];
    map<int, int> mp;
    vector<pair<int, int>> v1, v2;
    forn(i, n) {
        ++mp[a[i]];
        ++i;
    }
    FOR(it, mp) {
        v1.pb({it->second, it->first});
    }
    mp.clear();
    forab(i, 1, n-1) {
        ++mp[a[i]];
        ++i;
    }
    FOR(it, mp) {
        v2.pb({it->second, it->first});
    }
    sort(all(v1));
    sort(all(v2));
    if(v2.back().second != v1.back().second) {
        cout << n - (v1.back().first + v2.back().first);
    } else {
        int nn = v1.size(), mn = v2.size();
        if(nn >= 2 && mn >= 2) {
            cout << n - max(v1[nn-1].first + v2[mn-2].first, v1[nn-2].first + v2[mn-1].first);
        } else if(v2.size() >= 2) {
            cout << n - v2[mn-2].first + v1[nn-1].first << "\n";
        } else if(v1.size() >= 2) {
            cout << n - v1[nn-2].first + v2[mn-1].first << "\n";
        } else 
            cout << n/2 << "\n";
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

namespace Contest
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Array.ConvertAll(Console.ReadLine().Split(), Convert.ToInt32);
            int a = ab[0], b = ab[1];
            Console.WriteLine(Math.Max(a + b, Math.Max(a - b, a * b)));

        }
    }
}

Measured memory_bytes: 11220
import java.util.Scanner;

public class Main{
  static int n;
  static boolean[] pat;

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

    n = sc.nextInt();
    pat = new boolean[n];
    String line = sc.next();
    for(int i = 0; i < line.length(); i++){
      pat[i] = (line.charAt(i) == 'o');
    }

    boolean[] ans = null;

    boolean[] ss = search(true, true);
    if(ss != null){
      System.out.println(toAnswer(ss));
      return;
    }

    boolean[] sw = search(true, false);
    if(sw != null){
      System.out.println(toAnswer(sw));
      return;
    }

    boolean[] ws = search(false, true);
    if(ws != null){
      System.out.println(toAnswer(ws));
      return;
    }

    boolean[] ww = search(false, false);
    if(ww != null){
      System.out.println(toAnswer(ww));
      return;
    }

    System.out.println(-1);
  }

  private static boolean[] search(boolean s0, boolean s1){
    boolean[] s = new boolean[n];
    s[0] = s0;  s[1] = s1;

    for(int i = 1; i < n - 1; i++){
      if(pat[i]){
        s[(i + 1) % n] = s[(i - 1 + n) % n];
      }
      else{
        s[(i + 1) % n] = !s[(i - 1 + n) % n];
      }
      if(!s[i]){
        s[(i + 1) % n] = !s[(i + 1) % n];
      }
    }

    if(pat[0]){
      if(s[0]){
        if(s[n - 1] != s[1]){
          return null;
        }
      }
      else{
        if(s[n - 1] == s[1]){
          return null;
        }
      }
    }
    else{
      if(s[0]){
        if(s[n - 1] == s[1]){
          return null;
        }
      }
      else{
        if(s[n - 1] != s[1]){
          return null;
        }
      }
    }

    if(pat[n - 1]){
      if(s[n - 1]){
        if(s[n - 2] != s[0]){
          return null;
        }
      }
      else{
        if(s[n - 2] == s[0]){
          return null;
        }
      }
    }
    else{
      if(s[n - 1]){
        if(s[n - 2] == s[0]){
          return null;
        }
      }
      else{
        if(s[n - 2] != s[0]){
          return null;
        }
      }
    }

    return s;
  }

  private static String toAnswer(boolean[] a){
    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < a.length; i++){
      if(a[i]){
        sb.append("S");
      }
      else{
        sb.append("W");
      }
    }
    return sb.toString();
  }
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

int main(){
  double A,B,H,M;
  cin >> A >> B>>H>>M;


  H += (M/60);
  double rad = abs(2*acos(-1)*H/12 - 2*acos(-1)*M/60);


  double a2 = A*A + B*B -2*A*B*cos(rad);
  //cout << rad*360/(2*acos(-1)) <<endl;
  //cout << A*A + B*B + 2*A*B*cos(rad)<< endl;

  cout << fixed << setprecision(12) << sqrt(a2) ;
}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std;
const long long maxn=1005;
const long long inf=0x3f3f3f3f;
long long dp[maxn][maxn]; 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	long long k;
	cin>>k;
	for(long long i=0;i<=9;i++)
		dp[1][i]=1;
	for(long long i=2;i<=10;i++)
		for(long long j=0;j<=9;j++)
			dp[i][j]=dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j+1];
	long long l,r,flag=0;
	for(long long i=1;i<=10;i++)
	{
		for(long long j=1;j<=9;j++)
		{
			if(k<=dp[i][j])
			{
				l=i;
				r=j;
				flag=1;
				break;
			}
			k-=dp[i][j];
		}
		if(flag==1)
			break;
	}
	queue<long long> q;
	q.push(r);
	for(int i=l-1;i>=1;i--)
	{
		if(k<=dp[i][r-1])
		{
			r--;
			q.push(r);
		}
		else
		{
			k-=dp[i][r-1];
			if(k<=dp[i][r])
				q.push(r);
			else
			{
				k-=dp[i][r];
				r++;
				q.push(r);
			}
		}
	}
	while(!q.empty())
	{
		cout<<q.front();
		q.pop();
	}
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    for (ll i = 1; i <= n; i++) ans += i * (i + 1) / 2;
    for (ll i = 1; i < n; i++) {
        ll a, b, c, d;
        cin >> c >> d;
        a = min(c, d);
        b = max(c, d);
        ans -= a * (n - b + 1);
    }
    cout << ans;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main() {

    string S;
    cin >> S;

    reverse(S.begin(), S.end());

    rep(i, 4) reverse(divide[i].begin(), divide[i].end());

    bool can = true;
    for(int i = 0; i < S.size();) {
        bool can2 = false;
        rep(j, 4) {
            string d = divide[j];
            if (S.substr(i, d.size()) == d) {
                can2 = true;
                i += d.size();
            }
        }

        if (!can2) {
            can = false;
            break;
        }
    }

    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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

int main(){
  int N;cin>>N;
  vector<string> W(N);
  for(int i=0;i<N;i++) cin>>W.at(i);
  bool shirit=true;
  for(int i=0;i<N;i++){
    if(shirit){
      for(int j=i+1;j<N;j++){
        if(W.at(i)==W.at(j)){
          shirit=false;
          break;
        }
      }
    }
  }
  if(shirit){
    for(int i=0;i<N-1;i++){
      int l=W.at(i).size();
      if(W.at(i).at(l-1)!=W.at(i+1).at(0)){
        shirit=false;
        break;
      }
    }
  }
  if(shirit) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
    

Measured memory_bytes: 3632
// problem: "https://atcoder.jp/contests/abc150/tasks/abc150_c"

#include<bits/stdc++.h>

using namespace std;

int numPerm(vector<int>&P,vector<int>&Q)
{
    int n = P.size();
    int i,j,c,m;
    c = 0;

    while(P != Q)
    {
        vector<int>temp;
        i = n-1;
        while(P[i-1] > P[i])
        {
            temp.push_back(P[i]);
            i--;
        }

        temp.push_back(P[i]);

        j = 0;
        while(j < temp.size() && temp[j] < P[i-1])
            j++;

        swap(temp[j],P[i-1]);
        j = 0;
        while(i < n)
        {
            P[i] = temp[j];
            i++;
            j++;
        }

        c++;
    }

    return c;
}

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

    int i,x;
    vector<int>P,Q;

    for(i=0;i!=n;i++)
    {
        cin>>x;
        P.push_back(x);
    }

    for(i=0;i!=n;i++)
    {
        cin>>x;
        Q.push_back(x);
    }

    for(i=0;i!=n;i++)
    {
        if(P[i] == Q[i])
            continue;

        else if(P[i] < Q[i])
            cout<<numPerm(P,Q);     // define

        else
            cout<<numPerm(Q,P);     // define

        break;
    }

    if(i == n)
        cout<<0;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

typedef pair<long long, long long> P;

int main(){
  int N,M;
  cin >> N >> M;
  vector<long long> Kard(N);
  long long answer = 0;
  //cout << "GUIY" << endl;
  for(int i = 0;i < N;i++){
    cin >> Kard.at(i);
    answer += Kard.at(i);
  }
  sort(Kard.begin(),Kard.end());

  vector<P> data(M);
  //cout << "GUIsY" << endl;
  for(int i = 0;i < M;i++){
    cin >> data.at(i).second >> data.at(i).first;
  }
  sort(data.begin(),data.end(),greater<P>());

  /*for(int i = 0;i < M;i++){
    cout << data.at(i).first <<" " << data.at(i).second << endl;
  }*/

  int now = 0,sum = 0;
  for(int i = 0;i < N;i++){
    //cout << i << now << sum << endl;
    if(now < M){
    if(data.at(now).first > Kard.at(i)){
      answer += (data.at(now).first - Kard.at(i));
      sum++;
    }
    if(sum == data.at(now).second){
      sum = 0;
      now++;
    }
  }
}
  cout << answer << endl;
}

/*int main(){
  int N,M;
  cin >> N >> M;
  long long answer = 0;
  vector<long long> Kard(N);
  for(int i = 0;i < N;i++){
    cin >> Kard.at(i);
    answer += Kard.at(i);
  }
  sort(Kard.begin(),Kard.end());

  priority_queue<int> data;
  int b,c;
  for(int i = 0;i < M;i++){
    cin >> b >> c;
    for(int j = 0;j < b;j++){
      data.push(c);
    }
  }
  if(data.size() < N){
    int x = N - data.size();
    for(int i = 0;i < x;i++){
      data.push(0);
    }
  }
  for(int i = 0;i < N;i++){
    if(Kard.at(i) < data.top()){
      answer += (data.top() - Kard.at(i));
    }
    data.pop();
  }
  cout << answer << endl;
  return 0;
}*/

/*int main(){
  int N,M;
  cin >> N >> M;
  vector<long long> Kard(N);
  for(int i = 0;i < N;i++){
    Kard.at(i) = 0;
  }
  for(int i = 0;i < N;i++){
    cin >> Kard.at(i);
  }
  sort(Kard.begin(),Kard.end());
  int b,c;
  for(int i = 0;i < M;i++){
    cin >> b >> c;
    for(int j = 0;j < b;j++){
      if(Kard.at(j) < c){
        Kard.at(j) = c;
      }else{
        break;
      }
    }
    sort(Kard.begin(),Kard.end());
  }
  long long count = 0;
  for(int i = 0;i < N;i++){
    count += Kard.at(i);
  }
  cout << count << endl;
}*/


Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 300000
vector<int> v[N];
int n, q, tot, d[N], l[N], r[N], s[N];

void dfs(int x, int fa) {
    d[x] = ++tot, l[x] = r[x] = tot;
    for(int i = 0; i < v[x].size(); i++) {
        if (v[x][i] == fa) continue;
        dfs(v[x][i], x);
        l[x] = min(l[x], l[v[x][i]]);
        r[x] = max(r[x], r[v[x][i]]);
    }
}

int main() {
    //freopen("sample.in", "r", stdin);
    cin >> n >> q;
    for(int i = 1; i < n; i++) {
        int x, y; scanf("%d%d", &x, &y);
        v[x].pb(y), v[y].pb(x);
    }
    dfs(1, 0);
    for(int i = 1; i <= q; i++) {
        int p, x; scanf("%d%d", &p, &x);
        s[l[p]] += x, s[r[p] + 1] -= x;
    }
    for(int i = 1; i <= n; i++) s[i] = s[i] + s[i - 1];
    for(int i = 1; i <= n; i++) printf("%d ", s[d[i]]);
}

Measured memory_bytes: 35456
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 200010;

struct Vec {
  ll x, y;

  Vec(ll x = 0, ll y = 0) : x(x), y(y) {}

  Vec operator+(const Vec& rhs) const { return Vec(x + rhs.x, y + rhs.y); }

  Vec operator-() const { return Vec(-x, -y); }

  Vec operator-(const Vec& rhs) const { return *this + -rhs; }

  ll operator*(const Vec& rhs) const { return x * rhs.y - y * rhs.x; }

  ll operator^(const Vec& rhs) const { return x * rhs.x + y * rhs.y; }
};

int n, cnt, top;
int h[N];
ll dp[N];
Vec stk[N];

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  ll c;
  scanf("%d%lld", &n, &c);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &h[i]);

  stk[++cnt] = Vec(h[1], h[1] * (ll)h[1]);
  top = 1;
  for (int i = 2; i <= n; ++i) {
    Vec jud(h[i] * -2, 1);
    while (top < cnt && (stk[top + 1] ^ jud) < (stk[top] ^ jud))
      ++top;
    dp[i] = (stk[top] ^ jud) + c + h[i] * (ll)h[i];
    Vec ins(h[i], dp[i] + h[i] * (ll)h[i]);
    while (cnt > 1 && (stk[cnt] - stk[cnt - 1]) * (ins - stk[cnt]) <= 0)
      --cnt;
    stk[++cnt] = ins;
    top = min(top - 1, cnt);
    if (top < 1)
      top = 1;
    //LOG("%d: %lld\n", i, dp[i]);
  }
  printf("%lld\n", dp[n]);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 5760
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)
 
N, K = map(int, input().split())
if K!=10:
  N = Base_10_to_n(N, K)
print( len(str(N)) )

Measured memory_bytes: 3060
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

using ll = long long int;


int main() {
	int n;
	double total = 0;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			total += 2;
		}else if(a % 2 == 0){
			total += 1;
		}
		else {

		}
	}


	if (n % 2 == 1) {
		if ((total / (n - 1)) >= 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		if ((total / n) >= 1) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}



Measured memory_bytes: 256
from collections import deque
n = int(input())
a = list(map(int, input().split()))
b = deque([])

for i in range(n):
    if i%2==0:
        b.append(a[i])
    else:
        b.appendleft(a[i])
if n%2==1:
    b = list(b)[::-1]
print(' '.join(list(map(str, b))))


Measured memory_bytes: 39284
#include "bits/stdc++.h"

using namespace std;
using ll = long long int;

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

    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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; }
int d(ll a){
    ll j;
    rep(i, 27){
        j = 27-i;
        if(a %(1<<j) == 0){
            return j;
        }
    }
    return 0;
}
int main()
{
    int n;
    cin >> n;
    vll a(n);
    ll tot = 0;
    rep(i, n){
        ll x;
        cin >>x;
        a[i] = d(x);
        tot += a[i];       
    }
    sort(ALL(a));
    vi b;
    rep(i, n/2){
        b.eb(a[i]);
        b.eb(a[n-1-i]);
    }
    if(n%2 != 0) b.eb(a[n/2]);
    rep(i, n-1){
        if((b[i]+b[i+1])>=2){
            continue;
        }
        cout << "No" << endl;return 0;
    }
    // int c = n-1;
    // rep(i, n){
    //     if((a[i]+a[i+1])>=2){
    //         continue;
    //     }else{
    //        if(i+1 > n/2)  continue;
    //        swap(a[i+1], a[c--]);
    //        if((a[i]+a[i+1])<2){
    //            cout << "No" << endl;return 0;
    //        }
    //     }
    // }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 4716