akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;


int query(int a, int b, int c, int d) {
  cout << "? " << a << " " << b << " " << c << " " << d << "\n";
  int r;
  cin >> r;
  return r;
}

const int H = 50;
int board[H][H];

int main(void){
  ios::sync_with_stdio(false);
  int h, w, n;
  ll k;
  cin >> h >> w >> n >> k;
  int seen = 0;
  REP(i, 0, h / 2) {
    REP(j, 0, w / 2) {
      int res = i == h / 2 - 1 && j == w / 2 - 1 ?
	n - seen :
	query(2 * i, 2 * j, 2 * i + 1, 2 * j + 1);
      seen += res;
      if (res == 4) {
	REP(a, 0, 2) REP(b, 0, 2) { board[2 * i + a][2 * j + b] = 1; }
      } else {
	REP(a, 0, 2) {
	  REP(b, 0, 2) {
	    int loc = 0;
	    if (res > 0) {
	      loc = query(2 * i + a, 2 * j + b, 2 * i + a, 2 * j + b);
	    }
	    board[2 * i + a][2 * j + b] = loc;
	    res -= loc;
	  }
	}
      }
    }
  }

  
  ll sum = 0;
  ll cur = 1;
  REP(i, 0, h) {
    REP(j, 0, w) {
      int res = board[i][j];
      sum = (sum + res * cur) % k;
      cur = cur * 2 % k;
    }
  }
  cout << "! " << sum << "\n";
}


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


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

	if (D == 25) cout << "Christmas" << endl;
	else if (D == 24) cout << "Christmas Eve" << endl;
	else if (D == 23) cout << "Christmas Eve Eve" << endl;
	else cout << "Christmas Eve Eve Eve" << endl;

	return 0;
}


Measured memory_bytes: 256
using System;

public class Hello{
    public static void Main(){
        int n = int.Parse(Console.ReadLine());
        string[] hs = Console.ReadLine().Split(' ');
        long[] h = Array.ConvertAll(hs, x => long.Parse(x));
        bool flag = true;
        long start = 0;
        
        for(int i = 0; i < n - 1; i++){
            if(start == h[i]){
                if(h[i] > h[i + 1]){
                    flag = false;
                }
            }else if(start > h[i]){
                flag = false;
            }else{
                h[i]--;
                if(h[i] > h[i + 1]){
                    flag = false;
                }
            }
            
            if(flag == false){
                break;
            }else{
                start = h[i];
            }
        }
        
        Console.WriteLine(flag ? "Yes" : "No");
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  vector<int> q(n);
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin >> p.at(i);
  for(int i=0;i<n;i++)
    cin >> q.at(i);
  for(int i=0;i<n;i++)
    a.at(i)=i+1;
  
  int x,y;
  int l=0;
  
  do{
    int k=0;
    for(int i=0;i<n;i++){
      if(a.at(i)!=p.at(i))
        k++;
    }
    l++;
    if(k==0)
      x=l;
  }while(next_permutation(a.begin(),a.end()));
    
  l=0;
  for(int i=0;i<n;i++)
    a.at(i)=i+1;
  
  do{
    int k=0;
    for(int i=0;i<n;i++){
      if(a.at(i)!=q.at(i))
        k++;
    }
    l++;
    if(k==0)
      y=l;
  }while(next_permutation(a.begin(),a.end()));
  
  cout << max(x-y,y-x) << endl;
    
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main{
    static int[][] ary=new int[3][3];
    static boolean[][] bingo=new boolean[3][3];
    public static void main(String[] args)throws Exception{
        Scanner sc=new Scanner(System.in);
        for(int i=0;i<3;i++){
            Arrays.fill(bingo[i],false);
            for(int j=0;j<3;j++){
                ary[i][j]=sc.nextInt();
            }
        }
        int n=sc.nextInt();
        for(int i=0;i<n;i++){
            int b=sc.nextInt();
            boolean flag=false;
            for(int j=0;j<3;j++){
                for(int k=0;k<3;k++){
                    if(ary[j][k]==b){
                        bingo[j][k]=true;
                        flag=true;
                    }
                }
                if(flag){
                    break;
                }
            }
        }
        for(int i=0;i<3;i++){
            if(bingo[i][0]&&bingo[i][1]&&bingo[i][2]){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        for(int i=0;i<3;i++){
            if(bingo[0][i]&&bingo[1][i]&&bingo[2][i]){
                System.out.println("Yes");
                System.exit(0);
            }
        }
        if(bingo[0][0]&&bingo[1][1]&&bingo[2][2]){
            System.out.println("Yes");
            System.exit(0);
        }
        if(bingo[0][2]&&bingo[1][1]&&bingo[2][0]){
            System.out.println("Yes");
            System.exit(0);
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 21716
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int n = sc.nextInt();
                sc.close();
                boolean ebishu = true;
                while(n >= 0){
                        if(n % 7 == 0){
                                ebishu = false;
                        }
                        n -= 4;
                }
                if(!ebishu) System.out.println("Yes");
                else System.out.println("No");
        }
}

Measured memory_bytes: 35856
#include <stdio.h>

int parent[10000];

int root(int x){
    if(parent[x] == x)
        return x;
    
    return parent[x] = root(parent[x]);
}

void unite(int x, int y){
    int x2 = root(x);
    int y2 = root(y);
    parent[x2] = y2;
}

int main(void){
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i=0; i<n; i++)
        parent[i] = i;
    while(q--){
        int cmd, x, y;
        scanf("%d%d%d", &cmd, &x, &y);
        if(cmd){
            puts(root(x) == root(y) ? "1" : "0");
        }else{
            unite(x, y);
        }
    }
}


Measured memory_bytes: 2112
#include <stdio.h>
#include <unistd.h>


const int mod = 1000000007;

char s[100001];

int dp[2][13];

int main(){
  int i, j, k, r, b, d, l, t;
  t = 0;
 
  for(t=0;(k=read(STDIN_FILENO, s+t, sizeof(s)-t)) > 0;t+=k);

  for(l = 0; s[l] >= '0'; l++) ;

  r = 5;
  dp[0][0] = 1;
  b = 0;
  d = 1;
  for(i = l - 1; i >= 0; i--, d = d * 10 % 13){
    if(s[i] != '?'){
      r -= (s[i] - '0') * d;
      continue;
    }
    for(k = 0; k < 13; k++){
      for(j = 0; j < 10; j++){
        dp[b^1][(j * d + k) % 13] += dp[b][k];
        if(dp[b^1][(j * d + k) % 13] >= mod) dp[b^1][(j * d + k) % 13] -= mod;
      }
      dp[b][k] = 0;
    }
    b ^= 1;
  }

  r %= 13;
  if(r < 0) r += 13;

  printf("%d\n", dp[b][r]);
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

string s;

int main(){
	cin >> s;
	if((int)s.size() % 2 != 0){
		cout << "No\n"; return 0;
	}
	for(int i = 0;i < (int)s.size();i++){
		if(i % 2 == 0 && s[i] != 'h'){
			cout << "No\n"; return 0;			
		}
		if(i % 2 == 1 && s[i] != 'i'){
			cout << "No\n"; return 0;			
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 256
n,q = map(int,input().split())
s = input()
I = [list(map(int,input().split())) for i in range(q)]
AC = []
ac = 0
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac += 1
        AC += [ac]
    else:
        AC += [ac]
AC = [0] + AC + [ac]
for i in range(q):
    ac_q =  AC[I[i][1]-1]-AC[I[i][0]-1]
    print(ac_q)

Measured memory_bytes: 31504
#include<iostream>
using namespace std;
int main()
{
    long long A, B; cin >> A >> B;
    long long C, D, E;   cin >> C >> D;
    long long cc, dd, rem;
    long long ansa, ansb, ansc, ans;
    if(C > D){
        E = D;
        D = C;
        C = E;
    }
    rem = D%C;
    cc = C;
    dd = D;
    while(rem != 0){
        E = rem;
        dd = cc;
        cc = E;
        rem = dd % cc;
    }
    E = C*D/cc;
    ansa = B/C - A/C;
    ansb = B/D - A/D;
    ansc = B/E - A/E;
    if(A%C == 0)
        ansa++;
    if(A%D == 0)
        ansb++;
    if(A%E == 0)
        ansc++;
    ans = B - A + 1 - ansa - ansb + ansc;
    cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
string a;
int main(){
    long long ans=0;
    cin>>a;
    for(int i=1;i<a.length();i++){
        if(a[i-1]!=a[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
import math
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
l.sort(key=lambda x: math.atan2(x[1],x[0]))
l += l
ans = 0
for i in range(n):
    x = y = 0
    for j in range(n):
        nx,ny = l[i+j]
        x += nx
        y += ny
        ans = max(ans,(x**2+y**2)**0.5)
print(ans)

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

int ruijo(int n, int ans){
    if(n == 1){
        return ans + 1;
    }
    return ruijo(n - 1, ans + n);
}

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

    int ans = 0;
    if (n != 1 && n != 0) ans += ruijo(n - 1, 0);
    if (m != 1 && m != 0) ans += ruijo(m - 1, 0);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
k,n = map(int, input().split())
A = list(map(int, input().split()))
x = []
for a in A:
    x.append(a%k)
x.sort()
t = 0
for i in range(len(x)-1):
    t = max(t, x[i+1]-x[i])
t = max(t, k-x[-1]+x[0])
print(k-t)


Measured memory_bytes: 87372
s=input()
n=len(s)

def kaibun(s):
    if s==s[::-1]:
        return True
    else:
        return False

if kaibun(s) and kaibun(s[:(n-1)//2]) and kaibun(s[(n+1)//2:])==True:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
template <typename T> bool chmax(T &u, const T z) { if (u < z) {u = z; return true;} else return false; }
template <typename T> bool chmin(T &u, const T z) { if (u > z) {u = z; return true;} else return false; }
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long 
//typedef pair<ll, ll> P;
//const ll INF=1LL<<60;
ll gcd(ll x,ll y){return y? gcd(y,x%y) :x;}

template<typename T>
T prim(vector<vector<pair<ll, T>>> &g){
    ll n = (ll)g.size();
    T ret = 0;
    vector<bool> used(n, false);
    using P = pair<T, ll>;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(0,0);
    while(!que.empty()){
        auto p = que.top();
        que.pop();
        if(used[p.second]) continue;
        used[p.second] = true;
        ret += p.first;
        for(auto &e : g[p.second]){
          que.emplace(e.second,e.first);
        }
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
	vector<pair<ll,int>>x,y;
    vector<vector<pair<ll, ll>>> g(n);
    rep(i,n){
        ll a,b;
		cin>>a>>b;
		x.emplace_back(a,i);
		y.emplace_back(b,i);
	}
	sort(x.begin(),x.end());
	for(int i=1;i<n;i++){
		ll kyori=abs(x[i].first-x[i-1].first);
		g[x[i].second].emplace_back(x[i-1].second,kyori);
		g[x[i-1].second].emplace_back(x[i].second,kyori);
	}
	sort(y.begin(),y.end());
	for(int i=1;i<n;i++){
		ll kyori=abs(y[i].first-y[i-1].first);
		g[y[i].second].emplace_back(y[i-1].second,kyori);
		g[y[i-1].second].emplace_back(y[i].second,kyori);
	}
	ll ans=prim<ll>(g);
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 21924
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 0;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    sum += s[i];
  }
  sort(s.begin(), s.end());
  for (int i = 0; i < n; i++) {
    if (sum % 10 != 0) {
      break;
    }
    if (s[i] % 10 != 0) {
      sum -= s[i];
    }
  }
  if (sum % 10 == 0) {
    cout << 0 << endl;
  } else {
    cout << sum << endl;
  }
  return 0;
}

Measured memory_bytes: 3576
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

int main() {
  i64 n;
  cin >> n;
  i64 x = 1, y = 1;
  while (n--) {
    i64 t, a;
    cin >> t >> a;
    i64 k = max((x + t - 1) / t, (y + a - 1) / a);
    x = k * t;
    y = k * a;
  }
  cout << x + y << endl;
  return 0;
}


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

#define pb   push_back
#define endl "\n"
#define ll   long long

#define W(t)          while(t--)
#define rep(i,n)      for(i = 0; i < n; i++)
#define IOS ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

int main()
{
	IOS
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n, m, i, j, q;
	cin >> n >> m >> q;
	ll row[n + 1] = {}, col[m + 1] = {};
	pair<ll, ll> dir[q + 1];

	for (i = 1; i <= q; i++)
	{
		cin >> dir[i].first >> dir[i].second;
		row[dir[i].first]++;
		col[dir[i].second]++;
	}
	ll r = *max_element(row, row + n + 1);
	ll c = *max_element(col, col + m + 1);

	ll cnt = 0;
	set<ll> mr, mc;
	for (i = 1; i <= n; i++)
		if (r == row[i])
			mr.insert(i);
	for (i = 1; i <= m; i++)
		if (c == col[i])
			mc.insert(i);
	for (i = 1; i <= q; i++)
		if (mr.count(dir[i].first) && mc.count(dir[i].second))
			cnt++;
	ll ans = r + c;
	if ((ll)mr.size() * (ll)mc.size() == cnt)
		ans--;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 41084
import sys, math
from functools import lru_cache
import numpy as np
import heapq
from collections import defaultdict
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def lcm(a, b):
    return a*b//math.gcd(a, b)


def main():
    N = list(mi())
    N.sort()
    if N == [1,4,7,9]:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()


Measured memory_bytes: 27176
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long N = lread();
    long[] D;
    foreach (_; 0 .. N)
        D ~= lread();
    D.sort().uniq.count.writeln();
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n;
  cin >> n;

  int count = 0;
  for(int i = 1; i <= n; i += 2){
    int c = 0;
    for(int j = 1; j <= i; j++){
      if(i % j == 0) ++c;
    }
    if(c == 8) ++count;
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
# 最大公約数
def gcd(a,b):
    while b != 0:
        a,b = b, a%b
    return a

n,x = map(int,input().split())
X = list(map(int, input().split()))
a = []
dist = []
if len(X) == 1:
    print(abs(X[0]-x))
    exit()
for i in range(len(X)):
    a.append(abs(X[i]-x))
ans = 0
for d in a:
    ans = gcd(ans,d)
print(ans)

Measured memory_bytes: 15020
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	int A, B, C, D;
	cin >> A >> B >> C >> D;

	if (D == 1) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int s, w;
	cin >> s >> w;
	if (w >= s) {
		cout << "unsafe";
	}
	else {
		cout << "safe";
	}
	return 0;
}

Measured memory_bytes: 3624
N=int(input())
l=list(map(int,input().split()))
ans=0
for i in range(N-2):
    for j in range(i+1,N-1):
        for k in range(j+1,N):
            if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i] and l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[k]+l[j]>l[i]:
                ans+=1
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
using namespace std;

int puzzle[9][9];
bool ast[9][9];

void check() {
    for (int i=0; i<9; ++i) {
        for (int j=0; j<9; ++j) {
            for (int k=0; k<9; ++k) {
                if (i != k && puzzle[i][j] == puzzle[k][j]) {
                    ast[i][j] = true;
                    break;
                }
                if (j != k && puzzle[i][j] == puzzle[i][k]) {
                    ast[i][j] = true;
                    break;
                }
            }
            for (int k=(i/3)*3; k<(i/3)*3+3; ++k) {
                for (int l=(j/3)*3; l<(j/3)*3+3; ++l) {
                    if ((i != k || j != l) && puzzle[i][j] == puzzle[k][l]) {
                        ast[i][j] = true;
                        break;
                    }
                }
            }
        }
    }
}

int main() {
    int n;
    bool lf = false;
    cin >> n;
    for (int k=0; k<n; ++k) {
        if (lf) {
            cout << endl;
        }
        memset(ast, false, sizeof ast);
        for (int i=0; i<9; ++i) {
            for (int j=0; j<9; ++j) {
                cin >> puzzle[i][j];
            }
        }
        check();
        for (int i=0; i<9; ++i) {
            for (int j=0; j<9; ++j) {
                cout << (ast[i][j] ? "*" : " ") << puzzle[i][j];
            }
            cout << endl;
        }
        lf = true;
    }
    return 0;
}

Measured memory_bytes: 1160
import os, sys, re, math

S = input()
T = input()

table = {}
flg = True
for i in range(len(S)):
	if S[i] in table.keys():
		if T[i] != table[S[i]]:
			flg = False
	else:
		if T[i] in table.values():
			flg = False
		else:
			table[S[i]] = T[i]
	if not flg:
		break

if flg:
	print('Yes')
else:
	print('No')


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

int main() {
  long n, k, s;
  cin >> n >> k >> s;
  for(long i = 0; i < k; i++) {
    cout << s << " ";
  }
  for(long i = 0; i < (n - k); i++) {
    if (s == 1e9) {
      cout << (999999999) << " ";
    }
    else {
      cout << (s + 1) << " ";
    }
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<int> top(N);
  vector<int> middle(N);
  vector<int> bottom(N);
  for(int i=0; i<N; i++){
    cin >> top.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> middle.at(i);
  }
  for(int i=0; i<N; i++){
    cin >> bottom.at(i);
  }
  sort(top.begin(), top.end());
  sort(bottom.begin(), bottom.end());

  int64_t ans= 0;
  for(int i=0; i<N; i++){
    auto itr_t= lower_bound(top.begin(), top.end(), middle.at(i));
    auto itr_b= upper_bound(bottom.begin(), bottom.end(), middle.at(i));
    int64_t N_t= distance(top.begin(), itr_t);
    int64_t N_b= distance(itr_b, bottom.end());

    ans+= N_t* N_b;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
typedef long long ll;
bool aaa[11111111];
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
 
 
int main() {
  int n,c,aan,m,Q,memo=0,sx=0,sy=1,ans=0,gx,gy;
  string ka,ss;
  bool flag=true,flag1=false;
  cin>>n; 
  
	  
  cout<<n+n*n+n*n*n<<endl;
}

Measured memory_bytes: 3620
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;


// vector<int> dp(10);

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    // dp.assign(10,1000);

    int h,w;
    cin >> h >> w;
    int c[10][10];
    rep(i,10){
        rep(j,10){
            cin >> c[i][j];
        }
    }
    
    rep(i,10){
        rep(j,10){
            rep(l,10){
                if(c[j][l]>c[j][i]+c[i][l]){
                    c[j][l]=c[j][i]+c[i][l];
                }
            }
        }
    }

    int ans=0;

    rep(i,h){
        rep(j,w){
            int q;
            cin >> q;
            if(q==-1){
                continue;
            }
            else {
                ans+=c[q][1];
            }
        }
    } 

    cout << ans;

    return 0;
}

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

using namespace std;

#define inputInt(a) scanf("%d", &a)
#define inputStr(a) getline(cin, a)
#define clr(a) memset(a, 0, sizeof(a))
#define print(a) cout<<a<<endl

int main()
{
    char s[60];
    char t[60];
    int lens, lent, pos,cnt,k;
    bool flag = false;

    scanf("%s", s);
    scanf("%s", t);

    lens = strlen(s);
    lent = strlen(t);

    for(int i = lens-1; i>=0; i--)
    {
       if(s[i]==t[lent-1] || s[i] == '?')
       {
           k=i;
           cnt = 0;
           for(int j=lent-1; j>=0;j--)
           {
               if(s[k]=='?' || s[k] == t[j])
               {
                   cnt++;
               }
               else
                    break;
               k--;
           }
           if(cnt == lent)
           {
               k = i;
               for(int j=lent-1; j>=0; j--)
               {
                   s[k] = t[j];
                   k--;
               }

            flag = true;
            pos = i-lent;
            break;
           }
           else
               continue;
       }
    }


    char ch = 'a';
    if(flag == true)
    {
        for(int i = 0; i<lens;i++)
            if(s[i]=='?') s[i]=ch;

    }

    if(flag == true)
        print(s);
    else
        print("UNRESTORABLE");

   return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

// パスカルの三角形を使った実装
ll C[51][51]; // C[n][k] -> nCk

void comb_table(int N){
    for(int i=0; i<=N; i++){
        for(int j=0; j<=i; j++){
            if(j==0 || j==i) C[i][j] = 1LL;
            else C[i][j] = (C[i-1][j-1]+C[i-1][j]);
        }
    }
}

int main(){
    int N, A, B; cin >> N >> A >> B;
    vector<double> v(N);
    for(int i=0; i<N; i++) cin >> v[i];
    sort(v.begin(), v.end(), greater<ll>());

    double MAX = 0.0;
    for(int i=0; i<A; i++) MAX += v[i];

    MAX /= A;

    comb_table(50);
    
    if(MAX == v[0]){
        ll ans = 0;
        int cnt = 0;
        for(int i=0; i<N; i++) if(v[i] == v[0]) cnt++;
        for(int i=A; i<=min(cnt, B); i++) ans += C[cnt][i];
        printf("%.8lf\n", MAX);
        cout << ans << endl;

    }
    else{
        int n1 = 0, n2 = 0;
        for(int i=0; i<N; i++){
            if(v[i] == v[A-1] && i<=A-1) n1++, n2++;
            if(v[i] == v[A-1] && i>=A) n1++;
        }
        printf("%.8lf\n", MAX);
        cout << C[n1][n2] << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>

using namespace std;
/*
int find(int x, vector<int> &p) {
if (p[x] == x)return x;
return p[x] = find(p[x], p);
}

void uni(int x, int y, vector<int> &p) {
x = find(x, p);
y = find(y, p);
p[x] = y;
}

int same(int x, int y, vector<int> p) {
if (find(x, p) == find(y, p))return 1;
return 0;
}
*/

//long long a[1002];

int R, G, B;
long long ans = 0;
const int MAX_N = 3001;

int memo[MAX_N][3];

int fn(int n, int mark) {
	if (n == 0) {
		return 1;
	}
	if (mark != 0 && memo[n][mark-1] != -1) return memo[n][mark-1];
	int tmp1 = 0, tmp2 = 0, tmp3 = 0;
	if (n - R >= 0 && mark < 2) tmp1 = memo[n - R][0] = fn(n - R, 1);
	if (n - G >= 0 && mark < 3) tmp2 = memo[n - G][1] = fn(n - G, 2);
	if (n - B >= 0 && mark < 4) tmp3 = memo[n - B][2] = fn(n - B, 3);
	if (n - R < 0 && n - G < 0 && n - B < 0) return 0;
	//return memo[n - R][0] + memo[n - G][1] + memo[n - B][2];
	return tmp1 + tmp2 + tmp3;
}

int main()
{
	for (int i = 0; i < MAX_N; ++i) {
		for (int j = 0; j < 3; j++) {
			memo[i][j] = -1;
		}
	}
	long long N, K, cnt = 0, tmp;
	cin >> R >> G >> B >> N;
	cout << fn(N, 0) << endl;
	for (int j = 0; j < 3; j++) {
		for (int i = 0; i < N; i++) {
			//cout << memo[i][j] << endl;
		}
		//cout << endl;
	}
	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s = "ACL";
  int k;
  cin >> k;
  rep(i, k)
    cout << s;
  cout << endl;
  return 0;
}

Measured memory_bytes: 3556
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,a;
int main(){
    cin >> N;
    set<int> st;
    rep(i,N){
        cin >> a;
        if(st.find(a) == st.end()) st.insert(a);
        else st.erase(a);
    }
    pr(sz(st));
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  char str[11];
  cin >> str;
  char a[11];
  int x = 0;
  for(int i=0; i<11; i++){
    if(str[i]=='1'){
      a[x] = '1';
      x++;
    }else if(str[i]=='0'){
      a[x] = '0';
      x++;
    }else if(str[i]=='B'){
      if(!x==0){
        x--;
      }
    }
  }
  for(int i=0; i<x; i++){
    cout << a[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
d, g = map(int, input().split())
pc = [list(map(int, input().split())) for _ in range(d)]

ans = 1000
for i in range(1 << d):
	score = 0
	num = 0
	rest = 0
	for j in range(d):
		if ((i >> j) & 1) == 1:
			score += pc[j][0]*100*(j+1) + pc[j][1]
			num += pc[j][0]
		else:
			rest = j
	if score < g:
		need = (g-score-1)//(100*(rest+1)) + 1
		if need > pc[rest][0]-1:
			continue
		else:
			num += need
	ans = min(ans, num)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main(int argc, const char * argv[]) {
    
    int x,y,n,xxx;
    scanf("%d %d",&x,&y);
    
    if(x<y){
        xxx=x;
        x=y;
        y=xxx;
    }
    
    while(1){
        
        if(x%y==0){
            printf("%d\n",x);
            break;
        }
        
        n=x%y;
        
        if(x%n==0 && y%n==0){
            printf("%d\n",n);
            break;
        }
        
        x=n;
        
        xxx=x;
        x=y;
        y=xxx;

    }
    
    return 0;
}

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

int main(){
  
  int N, M;
  cin >> N >> M;
  priority_queue<int> A;
  long tmp;
  
  for(int i = 0; i < N; i++) {
    cin >> tmp;
    A.push(tmp);
  }
  
  for(int i = 0; i < M; i++){
    tmp = A.top();
    A.pop();
    A.push(tmp/2);
  }
  
  long long sum = 0;
  for(int i = 0; i < N; i++) {
    sum += A.top();
    A.pop();
  }
  //sum = accumulate(A.begin(), A.end(), 0LL);
  cout << sum;
  
  return 0;
}

Measured memory_bytes: 892
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

template <class T> struct cord{
  T x,y;
};

template <class T> double dist(cord<T> a, cord<T> b){
  T dx=a.x-b.x;
  T dy=a.y-b.y;
  return sqrt(dx*dx+dy*dy);
}

int main()
{

  //cout << fixed << setprecision(10);
  
  int n,a; cin >> n >> a;
  if (n%500<=a){cout << "Yes";}
  else {cout << "No";}

  return 0;
}


Measured memory_bytes: 256
use std::io;

fn main(){
  println!("{}", readInt32().pow(3));
}

fn readLine() -> String {
    let mut line = String::new();

    io::stdin().read_line(&mut line)
        .expect("failed to read line");
        
    line
}

fn readInt32() -> i32 {
   readLine().trim().parse().expect("Please type a number!")
}


Measured memory_bytes: 5032
w, h, x, y = map(int, input().split(' '))

max_area = 0
square_area = w * h
multiple_ans = 1 if 2 * x == w and 2 * y == h else 0

print('{max_area} {multiple_ans}'.format(max_area=str(square_area / 2), multiple_ans=str(multiple_ans)))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = int_fast64_t;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(nullptr)
#define digit(N) cout << fixed << setprecision((N))
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

int main()
{
	ll K;
	int N;
	cin >> N >> K;
	vector<int> a(N);

	int sz = 60;
	vector<vector<int>> next(sz + 1, vector<int>(N, -1));
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		a[i]--;
		next[0][i] = a[i];
	}

	for (int k = 0; k < sz; k++)
	{
		for (int i = 0; i < N; i++)
		{
			if (next[k][i] == -1)
				continue;
			next[k + 1][i] = next[k][next[k][i]];
		}
	}

	int ans = 0;

	for (int k = sz - 1; k >= 0; k--)
	{
		if ((K >> k) & 1)
			ans = next[k][ans];
	}

	cout << ans + 1 << "\n";
}

Measured memory_bytes: 52628
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
  		
  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  
        int count=0;
  
       count+=(n-1)/(k-1);
       if((n-1)%(k-1)!=0){
       count++;
       }
       
  
    	System.out.println(count);
    }
}


Measured memory_bytes: 59268
using System;
using System.Numerics;

namespace CodingForces
{
    static class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            BigInteger power = 1;
            long mod = (long)Math.Pow(10, 9) + 7;
            for (var i = 1; i <= n; i++)
            {
                power = (power * i) % mod;
            }
            Console.WriteLine(power);
            //Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13524
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
  int N;
  int p[210][3];
  
  cin >> N;

  for(int i = 0 ; i < N ; i++){
    cin >> p[i][0] >> p[i][1] >> p[i][2];
  }
  
  vector<int> point;
  
  for(int i = 0 ; i < N ; i++){
    int tmp = 0;
    for(int k = 0 ; k < 3 ; k++){
      bool f = true;
      for(int j = 0 ; j < N ; j++){
	if(i == j) continue;
	if(p[i][k] == p[j][k]) f = false;
      }
      if(f) tmp += p[i][k];
    }
    point.push_back(tmp);
  }
  
  for(int i = 0 ; i < N ; i++){
    cout << point[i] << endl;
  }
  return 0;
}
  

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

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 20001;

int a[MX], b[MX], N, ord[MX];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N;
    FOR(i,1,N+1) a[i] = i*40000;
    FOR(i,1,N+1) {
        int x; cin >> x;
        ord[x] = i;
    }
    FOR(i,1,N+1) b[i] = (20005-i)*40000+ord[i];
    FOR(i,1,N+1) cout << a[i] << " ";
    cout << "\n";
    FOR(i,1,N+1) cout << b[i] << " ";
    cout << "\n";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

Measured memory_bytes: 896
#include <iostream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,N) for(int i=0;i<((int)N);i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int main(void){
  int N; cin>>N;
  char abc[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','\0'};
  char str[N][51];
  for(int i=0;i<N;i++){
      cin>>str[i];
  }
  int check[N][26];
  for(int i=0;i<N;i++){
      for(int j=0;j<26;j++){
          check[i][j]=0;
      }
  }
  for(int i=0;i<N;i++){
      int len=strlen(str[i]);
      for(int j=0;j<len;j++){
          int alpha=str[i][j]-'a';
          check[i][alpha]++;
      }
  }
  int ans[26];
  for(int i=0;i<26;i++){ int min=100;
     for(int j=0;j<N;j++){
        if(check[j][i]<min) min=check[j][i];
         
     }
     ans[i]=min;
  }
  for(int i=0;i<26;i++){
    for(int j=0;j<=ans[i];j++){
        if(j!=0){cout<<abc[i];}
    }
  }
  return 0;
}


Measured memory_bytes: 256
a, b = map(int,input().split())

x = 0
for i in range(0,b):
    x+=a*(10**i)

x = str(x)
y = 0
for j in range(0,a):
    y+=b*(10**j)
y = str(y)
if x>=y:
    print(y)

else:
    print(x)


Measured memory_bytes: 3060
#include<iostream>
	using namespace std;
	#define fo(i,n) for(int i=0;i<n;i++)
	#define pb push_back
	#define mp map<int,int>
	#define ump unordered_map<int,int>
	#define vi vector<int>
	#define M INT_MAX
	#define MI INT_MIN
	#define ll long long int
	#define pii pair<int,int>
	#define F first
	#define S second
	#define fall(i,a,b) for(int i=a;i<b;i++)
	#define pi 3.1415926535
	void solve()
	{
			int r;
			cin>>r;
			cout<<(2*pi*r)<<endl;
	}
	int main()
	{
		solve();
	}

Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    string s,t;cin >> s >> t;
    // s -> t
    int ans = INF;
    for(int i=0;i<s.size() - t.size() + 1;++i){
        int dif = 0;
        for(int j=0;j<t.size();++j){
            dif += s[i+j] != t[j];
        }
        chmin(ans, dif);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

#define ANS(f) if(f) cout << "YES" << endl; else cout << "NO" << endl;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
void debug(mat m){REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl; }}



signed main(){

    int N; cin >> N;
    vec A(N); readv(A);
    vec r(N + 1), l(N + 1);


    r[0] = 0;
    vec vr;
    REP(i, N){
        r[i + 1] = r[i] + 1;
        if(i >= 1){
            int a = A[i - 1], b = A[i];
            if(a >= b){
                while(a >= b * 4){
                    b *= 4;
                    vr.push_back(i);
                }
            }else{
                while(a < b){
                    a *= 4;
                    if(vr.size() == 0) r[i + 1] += 2 * i;
                    else{
                        int i0 = vr[vr.size() - 1]; vr.pop_back();
                        r[i + 1] += 2 * (i - i0);
                    }
                }
            }
        }
    }
    l[N] = 0;
    vec vl;
    IREP(i, N){
        l[i] = l[i + 1];
        if(i < N - 1){
            int a = A[i], b = A[i + 1];
            if(a <= b){
                while(a * 4 <= b){
                    a *= 4;
                    vl.push_back(i);
                }
            }else{
                while(a > b){
                    b *= 4;
                    if(vl.size() == 0) l[i] += 2 * (N - 1 - i);
                    else{
                        int i0 = vl[vl.size() - 1]; vl.pop_back();
                        l[i] += 2 * (i0 - i);
                    }
                }
            }
        }
    }
    int ans = INF;
    REP(i, N + 1) ans = min(ans, r[i] + l[i]);
    cout << ans;
    
    return 0;
}

Measured memory_bytes: 5504
def f():
  n, m = map(int, input().split())
  num = [set() for i in range(n)]
  for i in range(m):
    s, c = map(int, input().split())
    num[s-1].add(c)
  s = []
  for i in num:
    if len(i) > 1:
      print(-1)
      return
    if len(i) == 1:
      for x in i:
        s.append(x)
        break
    else:
      s.append(0)
  if s[0] == 0 and n != 1:
    if len(num[0]) > 0:
      print(-1)
      return
    else:
      s[0] = 1
  print(''.join(str(x) for x in s))
f()

Measured memory_bytes: 9136
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 5005
#define M 10005
#define ll long long
#define mod 1000000007
void Read(int &p)
{
	p = 0;
	char c = getchar();
	for (; c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; c = getchar())p = p * 10 + c - '0';
}
int n, tar[M], nex[M], fir[N], cnt;
int siz[N];
int dp[N][N], f[N], g[N];
void Add(int a, int b)
{
	++cnt;
	tar[cnt] = b;
	nex[cnt] = fir[a];
	fir[a] = cnt;
}
void Dfs(int r, int fa)
{
	siz[r] = 1;
	dp[r][1] = 1;
	for (int i = fir[r]; i; i = nex[i])
	{
		int v = tar[i];
		if (v != fa)
		{
			Dfs(v, r);
		    for (int j = 0; j <= siz[r]; j++)
			{
				g[j] = dp[r][j];
				dp[r][j] = 0;
			}
			for (int j = 0; j <= siz[r]; j++)
				for (int k = 0; k <= siz[v]; k++)
					dp[r][j + k] = (dp[r][j + k] + (ll)g[j] * dp[v][k]) % mod;
			siz[r] += siz[v];
		}
	}
	for (int i = 0; i <= siz[r]; i++)
		dp[r][0] = (dp[r][0] - (ll)dp[r][i] * f[i]) % mod;
}
int main()
{
	Read(n);
	for (int i = 1; i < n; i++)
	{
		int u, v;
		Read(u), Read(v);
		Add(u, v), Add(v, u);
	}
	f[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		if (i & 1)continue;
		f[i] = (ll)f[i - 2] * (i - 1) % mod;
	}
	Dfs(1, 0);
	int ans = -dp[1][0];
	if (ans < 0)
		ans += mod;
	printf("%d\n", ans);
}
//

Measured memory_bytes: 97152
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int k,s,ooo,ans=0;
    scanf("%d%d",&k,&s);
    for(int i=0;i<=k;i++)
    {
        for(int j=0;j<=k;j++)
        {
            int ooo=s-i-j;
            if(ooo<=k&&ooo>=0)
			  ans++;
		}
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int variety, num, sum = 0;
	int price[1000] = { 0 };

	scanf("%d %d", &variety, &num);
	for (int i = 0; i < variety; i++) {
		scanf("%d", &price[i]);
	}

	int min = price[0];
	for (int i = 0; i < variety - 1; i++) {
		for (int j = variety - 1; j > i; j--) {
			if (price[j-1] > price[j]) {
				int temp = price[j];
				price[j] = price[j - 1];
				price[j - 1] = temp;

			}
		}
	}

	for (int i = 0; i < num; i++) {
		sum += price[i];
	}

	printf("%d", sum);

	return 0;
}

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

int main(){
    ll x,b=100;
    cin >>x;
    int ans=1;
    while(b<x){
        b=1.01*b;
        ans++;
    }
    
    
    cout << ans-1 <<endl;
    return 0;
}

Measured memory_bytes: 3624
import sys
import itertools
if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    

N=int(input())
h=list(map(int,input().split()))
dp=[float("inf") for _ in range(N)]
dp[0]=0
dp[1]=abs(h[1]-h[0])
for i in range(N-2):
	dp[i+2]=min(dp[i]+abs(h[i]-h[i+2]),dp[i+1]+abs(h[i+1]-h[i+2]))
print(dp[N-1])

Measured memory_bytes: 14132
#include <bits/stdc++.h>
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprrev(i, a, b) for (int i = b - 1; i >= a; i--) // [a, b)
#define reprev(i, n) reprrev(i, 0, n)
#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
const ll mod = 1e9 + 7;
void chmod(ll &M)
{
  if (M >= mod)
    M %= mod;
  else if (M < 0)
  {
    M += (abs(M) / mod + 1) * mod;
    M %= mod;
  }
}
ll modpow(ll x, ll n)
{
  if (n == 0)
    return 1;
  ll res = modpow(x, n / 2);
  if (n % 2 == 0)
    return res * res % mod;
  else
    return res * res % mod * x % mod;
}

int getl(int i, int N) { return i == 0 ? N - 1 : i - 1; };
int getr(int i, int N) { return i == N - 1 ? 0 : i + 1; };
long long GCD(long long a, long long b)
{
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}

using namespace std;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main() {
  long long N;
  cin >> N;
  long long count = 0;
  for(int i = 1; i <= N; i++) {
    if((i%2!=0) and (divisor(i).size()==8)) count++;
    	
  }
  cout << count << "\n";
}

Measured memory_bytes: 3596
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public final class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int rem = n%10;
		if(rem == 2 || rem == 4 || rem == 7 || rem == 9 || rem ==5){
			System.out.println("hon");
		}
		else if(rem == 0 || rem == 1 || rem == 6 || rem == 8){
			System.out.println("pon");
		}
		else{
			System.out.println("bon");
		}
	}
}

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

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  if (a != 0) {
    cout << b / x - (a - 1) / x << endl;
  } else {
    cout << 1 + b / x << endl;
  }
}

Measured memory_bytes: 256