akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  int S;
  cin>>S;
  int p=S/100;
  int q=S%100;
   if(1<=p && p<=12){
     if(1<=q && q<=12)
       cout<<"AMBIGUOUS"<<endl;
     else
       cout<<"MMYY"<<endl;
   }
  else if(1<=q && q<=12)
    cout<<"YYMM"<<endl;
  else
    cout<<"NA"<<endl;
}

Measured memory_bytes: 256
from functools import lru_cache

H, W, K = map(int, input().split())

MOD = 10**9 + 7


class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(
                pow(self.x, other.x, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    def __radd__(self, other):
        return ModInt(other + self.x)

    def __rsub__(self, other):
        return ModInt(other - self.x)

    def __rmul__(self, other):
        return ModInt(other * self.x)

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))


# 長さiの横幅に対して、隣り合わないように横線を引くパターン数
@lru_cache(maxsize=None)
def f(i):
    return (
        ModInt(1) if i <= 0 else
        ModInt(2) if i == 1 else
        f(i - 1) + f(i - 2)
    )


# 動的計画法により解を求める
@lru_cache(maxsize=None)
def g(i, j):
    return (
        ModInt(0) if i == 0 and j >= 2 or j == 0 or j == W + 1 else
        ModInt(1) if i == 0 and j == 1 else
        (
            g(i - 1, j - 1) * f(j - 3) * f(W - j - 1) +
            g(i - 1, j) * f(j - 2) * f(W - j - 1) +
            g(i - 1, j + 1) * f(j - 2) * f(W - j - 2)
        )
    )


ans = g(H, K)

print(ans)


Measured memory_bytes: 4188
#include <iostream>
#include<cstdio>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<cstring>
#include<stack>

using namespace std;

int main()
{
	int a,b,n;
	cin>>n>>a>>b;
	int x,y;
	x=min(a,b);
	y=max(0,a+b-n);
	cout<<x<<" "<<y<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;
    int x;
    cin >> x;

    int count = 0;
    REP(i, a + 1) REP(j, b + 1) REP(k, c + 1) {
        if ((500 * i + 100 * j + 50 * k) == x)
            count++;
    }

    cout << count << '\n';
    return 0;
}

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

const int MAX = 100000;
const int INF = 1073741823; // 10^30-1、使わない辺とかに用いる

int main() {
	int N, K, x[MAX];
	cin >> N >> K;
	for (int i = 0;i < N;++ i) cin >> x[i];
	
	int m = 0; // x[m-1]は0未満、x[m]は0以上
	for (int i = 1;i < N;++ i) if (x[i - 1] < 0 && x[i] >= 0) m = i;
	if (x[N - 1] < 0) m = N;
	
	int ans = INF;
	for (int i = 0;i < N;++ i) { // このiの位置で引き返す
		int first = abs(x[i] * 2); // 最初に移動する距離
		int on = i < m ? m - i : i - m + 1; // 現時点で付けた蝋燭の数
		if (on + (i < m && x[m] == 0 ? 1 : 0) >= K) { // 既に付け切った
			ans = min(ans, first / 2);
		} else {
			int next = i < m ? m + K - on - 1 : m - K + on; // 移動先
			if (next < 0 || next >= N) continue;
			int second = abs(x[next]); // 残りの移動距離
			ans = min(ans, first + second);
		}
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

移動経路は次の2つしかあり得ない
1. まず左へ行き、途中で引き返して右へ行く
2. まず右へ行き、途中で引き返して左へ行く
どの蝋燭の地点で引き返したか求めれば答えになる

*/

Measured memory_bytes: 640
#include <stdio.h>
#define MAX 100000
typedef struct{
  int parent,right,left;
}Node;

Node T[MAX];

int x,h[MAX],d[MAX];

void depth(int,int);
int height(int);
int sibling(int);
void print(int);

int main(){
  int n,i,id,left,right,root=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].parent = -1;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&id,&left,&right);
    T[id].left = left;
    T[id].right = right;
    if(left != -1) T[left].parent = id;
    if(right != -1) T[right].parent = id;
  }
    for(i=0;i<n;i++){
      if(T[i].parent == -1) root = i;
    }
    
    depth(root,0);
    height(root);

    for(i=0;i<n;i++){
      print(i);
    }

    return 0;
}
void print(int x){
  int degree=0;
      printf("node %d: parent = %d,",x,T[x].parent);
      printf(" sibling = %d,",sibling(x));
      if(T[x].left != -1) degree++;
      if(T[x].right != -1) degree++;

      printf(" degree = %d,",degree);
      printf(" depth = %d, height = %d, ",d[x],h[x]);
      
      if(T[x].parent == -1) printf("root\n");
      else if(T[x].left == -1 && T[x].right == -1) printf("leaf\n");
      else printf("internal node\n");
}

int height(int x){
  int left=0,right=0;
  if(T[x].right != -1)  right = height(T[x].right)+1;
  if(T[x].left != -1) left = height(T[x].left) +1;
  if(T[x].right == -1 && T[x].left == -1) return 0;
  if(left > right) return h[x] = left;
  else return h[x] = right;
}

int sibling(int x){
  if(T[x].parent == -1) return -1;
  if(T[T[x].parent].left != x && T[T[x].parent].left != -1) return T[T[x].parent].left;
  if(T[T[x].parent].right  != x && T[T[x].parent].right != -1) return T[T[x].parent].right;

  return -1;
}

void depth(int x, int y){
  if(x == -1) return;
  d[x] = y;
  depth(T[x].left, y+1);
  depth(T[x].right, y+1);
}



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

#define int long long
#define pb push_back
#define ff first
#define ss second

int mod = 998244353;


int power(int x, int y, int p)  
{  
    int res = 1;      
  
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  


main(){
	int n,s;
	cin>>n>>s;
	int arr[n+1],i,j,k;
	for(i=1;i<=n;i++){
		cin>>arr[i];
	}
	int dp[n+1][s+1];
	for(i=0;i<n+1;i++){
		for(j=0;j<s+1;j++){
			dp[i][j]=0;
		}
	}
	dp[0][0]=1;
	
	int count=0;
	for(i=1;i<=n;i++){
		for(j=0;j<=s;j++){
			dp[i][j] = dp[i-1][j]*2;
			dp[i][j] = dp[i][j]%mod;
			if(arr[i]<=j){
				dp[i][j] += dp[i-1][j-arr[i]];
				dp[i][j] = dp[i][j]%mod;
			}
		}
	}
	// for(i=0;i<=n;i++){
	// 	for(j=0;j<=s;j++){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	cout<<dp[n][s]<<endl;
	return 0;
}

Measured memory_bytes: 73920
import numpy as np
import sys


def solve(H):
    a = 1
    prev = 0
    for c in H:
        if c > prev:
            if a == 0:
                a = 1
        elif c - a < prev:
            if a == 0:
                return 0
            elif a == 1:
                a = 0
                if c < prev:
                    return 0
        prev = c - a
    return 1


nin = np.fromstring(sys.stdin.buffer.read(), dtype=np.int64, sep=' ')
N = nin[0]
H = nin[1:N + 1]
result = solve(H)
if result:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 14520
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

const int mod = 1e6 + 3;
inline int add(int u, int v) {
  return u + v >= mod ? u + v - mod : u + v;
}
inline int mul(int u, int v) {
  return u * 1ll * v % mod;
}
int pwr(int a, int n) {
  int r = 1;
  for (; n > 0; n >>= 1) {
    if (n & 1) r = mul(r, a);
    a = mul(a, a);
  }
  return r;
}
inline int inv(int a) {
  return pwr(a, mod - 2);
}

int fact[mod];

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  fact[0] = 1;
  for (int i = 1; i < mod; i++) {
    fact[i] = mul(fact[i - 1], i);
  }

  int q; cin >> q;
  while (q--) {
    int x, d, n; cin >> x >> d >> n;
    int ans = 0;
    if (d == 0) {
      ans = pwr(x, n);
    } else {
      int y = mul(x, inv(d));
      if (y + n - 1 < mod) {
        ans = mul(pwr(d, n), mul(fact[y + n - 1], inv(fact[y - 1])));
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 7556
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

int k,a,b;

int main(){
	scanf("%d%d%d",&k,&a,&b);
	if (b<a+2 || k<a){ printf("%d\n",k+1); return 0; }
	k-=a-1; cout<<a+1ll*k/2*(b-a)+(k&1)<<endl;
	return 0;
}

Measured memory_bytes: 256
S = input()

for i in range(ord('a'), ord('z')+1):
    if chr(i) not in S:
        print(S + chr(i))
        exit()
else:
    for i in range(len(S)-1, -1, -1):
        for j in range(ord('a'), ord('z')+1):
            if S[i] < chr(j) and chr(j) not in S[:i]:
                print(S[:i] + chr(j))
                exit()
    else:
        print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional>
using namespace __gnu_pbds;  
using namespace std;



typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
    
    
    
//defines
typedef long long ll;
typedef long double ld;

ll n,m,k,a,b,c,t=1;
void solve()
{
    ll cnt=0;
    cin>>n;
    vector<ll>v(n);
    for(ll i=0;i<n;i++)
    {
        cin>>v[i];
        if(i%2==0 and v[i]%2!=0)cnt++;
    }
    cout<<cnt;
 //cout<<"\n";
}

int32_t main()
{
#ifdef ONPC
    freopen("input.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

 // cin>>t;
    while(t--)
    {
        solve();
    }
  //cout<<sum;
        
    return 0;
}

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

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b;
    d = a*b*a;
    if(d%2==0)
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	a, b, c, k = rli()
	ans = 0
	for add, cnt in [(1, a), (0, b), (-1, c)]:
		score = min(k, cnt)
		ans += add*score
		k -= score
		if k == 0:
			break
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 64328
n = int(input())
ans = 1
l = [int(x) for x in input().split()]
limit = 10**18
if(0 in l):
    print(0)
    exit()

for x in l:
    x = int(x)
    ans *= x

    if(ans > limit):
        print(-1)
        exit()    

print(ans)


Measured memory_bytes: 21644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

const int MAX_A = 55555;
const int MAX_N = 55;

int n;
bool pf[MAX_A + 1];
vector<int> prime;

void create_prime() {
    rep(i, MAX_A + 1) pf[i] = true;
    pf[0] = pf[1] = false;
    
    for(int i = 2; (i * i) <= MAX_A; i++) {
        if (!pf[i]) {
            continue;
        }
        
        for (int ii = 2; (i * ii) <= MAX_A; ii++) {
            pf[i * ii] = false;
        }
    }
    
    for (int i = 0; i <= MAX_A; i++) {
        if (pf[i]) {
            prime.push_back(i);
        }
    }
}

bool is_prime(int n) {
    return pf[n];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    create_prime();
    int cnt = 0;
    
    rep(i, n) {
        while(!pf[++cnt * 5 + 1]);
        printf("%d%s", cnt * 5 + 1, (i == (n - 1)) ? "\n" : " ");
    }
    
    return 0;
}

Measured memory_bytes: 384
using System;

class Program {
    static void Main (string[] args) {
        var inp = Console.ReadLine().Split(' ');
        int a = int.Parse(inp[0]);
        int b = int.Parse(inp[1]);

        int c = int.Parse(inp[2]);
        int d = int.Parse(inp[3]);

        while(true) {
            c -= b;
            if(c <= 0) {
                Console.WriteLine("Yes");
                break;
            }

            a -= d;
            if(a <= 0) {
                Console.WriteLine("No");
                break;
            }
        }
    }
}

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

d = {}
m = 0
for x in s:
    if x in d:
        d[x] += 1
        m = max(m, d[x])
    else:
        d[x] = 0

for x in sorted({k:v for k, v in d.items() if v == m}.keys()):
    print(x)

Measured memory_bytes: 53520
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL unsigned long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL A[100000];

LL ans = 0;

void solve(){
	multiset<LL> arrays;
	arrays.insert(A[0]);
	for(int i=1;i<N;i++){
		auto iter = arrays.lower_bound(A[i]);
		if(iter==arrays.begin()) arrays.insert(A[i]);
		else{
			iter--;
			arrays.erase(iter);
			arrays.insert(A[i]);
		}
	}
	ans = arrays.size();
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> A[i];

    solve();

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

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EPS 1e-10
#define setNil(x) memset((x),0,sizeof(x))
#define setINF(x) memset((x),63,sizeof(x))
#define setNegINF(x) memset((x),192,sizeof(x)) //NegINF=-INF-1
#define setNeg1(x) memset((x),255,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
string s;
int d;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>s>>d;
	for(int i=0;i<s.size();i+=d)cout<<s[i];
	return 0;
}

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

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

	int ac[5000], bc[5000];
	for (int i = 0;i < a;i++)cin >> ac[i];
	for (int j = 0;j < b;j++)cin >> bc[j];

	int ans = 0;
	for (int i = 0;i < b;i++) {
		int itr = 0;
		int st = i;
		for (int j = 0;j < a;j++) {
			if (bc[itr + st] == ac[j]) {
				itr ++ ;
			}
		}
		ans = max(ans, itr);
	}
	cout << ans << endl;
	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N;string s;cin>>N>>s;
    string ans="";
    rep(i,s.size()){
        if(s.at(i)+N<='Z'){
            ans+=s.at(i)+N;
        }else{
            ans+=s.at(i)+N-'Z'+'A'-1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <cstdio>

using namespace std;

int n, h[22];

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", h+i);
  int ma = 0, res = 0;
  for (int i = 0; i < n; i++) {
    res += (ma <= h[i] ? 1 : 0);
    if (ma < h[i]) ma = h[i];
  }
  printf("%d\n", res);
  return 0;
}


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

class Fib {
public:
    Fib() : _f1(1), _f2(1) {}
    int operator()(int n) {
        if (n == 0) {
            return _f1;
        }
        if (n == 1) {
            return _f2;
        }
        else {
            for (int i = 2; i <=n; ++i) {
                double x = _f1 + _f2;
                _f1 = _f2;
                _f2 = x;
            }
            return _f2;
        }
    }

private:
    int _f1;
    int _f2;
    int _x;
};

int main() {
    int n;
    cin >> n;
    Fib f;
    cout << f(n) << endl;
}


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

#define ll              long long
#define ull             unsigned long long
int str_to_int(string s)
{
    stringstream ss(s);
    int n;
    ss>>n;
    return n;
}
int main()
{
    //freopen("A.txt","r",stdin);
    //freopen("A.txt","w",stdout);
    ios_base::sync_with_stdio(0);

    string s1,s2;
    cin>>s1;
    cin>>s2;
    string p=s1+s2;

    int m=str_to_int(p);
    int n=sqrt(m);

    if(n*n==m)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  double a, b, c;
  cin >> a >> b >> c;
  printf("%.8f\n", a * b * sin(c*M_PI/180) / 2);
  printf("%.8f\n", a + b + sqrt(pow(a, 2) + pow(b, 2) - 2*a*b*cos(c*M_PI/180)));
  printf("%.8f\n", b * sin(c*M_PI/180));
  return 0;
}



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

int main() {
    int counter[26] = {};
    char ch;

    while (cin >> ch) {
        if (isalpha(ch)) {
            int num = tolower(ch) - 'a';
            counter[num]++;
        }
    }

    for (int i = 0; i < 26; i++) {
        printf("%c : %d\n", i + 'a', counter[i]);
    }

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
	map<char, string> mp;
	mp['2'] = mp['4'] = mp['5'] = mp['7'] = mp['9'] = "hon";
	mp['0'] = mp['1'] = mp['6'] = mp['8'] = "pon";
	mp['3'] = "bon";
	string s; cin >> s;
	cout << mp[s.back()];
}

Measured memory_bytes: 3632
#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>;

int main() {
    string S;
    cin >> S;

   	if(S[S.length()-1]=='s'){
       cout << S << "es" << endl;
    }else{
      cout << S << "s" << endl;
    }
    return 0;
}

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

typedef long long lint; typedef pair<int, int> ii;
const int MOD = 1'000'000'007, MOD2 = 1'000'000'009;
const int INF = 0x3f3f3f3f; const lint BINF = 0x3f3f3f3f3f3f3f3fLL;

int n, dist[100005], par[100005], lst[100005];

template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;

int solve(){
	cin >> n;
	for(int i=0;i<n;i++) dist[i] = INF;
	min_queue<ii> q;
	dist[n] = 0, par[n] = -1, lst[n] = -1, q.push({dist[n], n});
	while(!q.empty()){
		int u = q.top().second; q.pop();
		for(int j=(u>=n);j<10;j++){
			int v = (u * 10 + j) % n;
			int t = dist[u] + j;
			if(t < dist[v]){
				dist[v] = t;
				par[v] = u;
				lst[v] = j;
				q.push({dist[v], v});
			}
		}
	}
	cout << dist[0] << endl;
	// vector<int> out;
	// for(int u=0;u!=-1;u=par[u]) out.push_back(lst[u]);
	// reverse(out.begin(), out.end());
	// for(int x: out) cerr << x;
	// cerr << endl;
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	// int t; cin >> t; while(t--)
	solve();
	// cout << (solve() ? "YES" : "NO") << endl;
	return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define step(i,s,n,c) for(int i=(s);i<(n);i+=(c))
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define each(i,vec) for(auto i:vec)
#define cinv(n,vec) VL vec(n);for(auto&v:vec)cin>>v;
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  int n;
  cin>>n;
  cinv(n,a);

  SORT(a);
  /*if(n<10){
    int ans=0;
    do{
      int res=0;
      rep(i,n-1)res+=abs(a[i]-a[i+1]);
      chmax(ans,res);
      //cout<<res<<":";call(a);
    }while(next_permutation(all(a)));
    out(ans);
    //return 0;
  } */

  VL x(n);
  int idx=n-1;
  step(i,1,n,2)x[i]=a[idx--];
  x[0]=a[idx];
  idx=0;
  step(i,2,n,2)x[i]=a[idx++];
  int res=0;
  rep(i,n-1)res+=abs(x[i]-x[i+1]);

  VL y(n);
  idx=0;
  step(i,1,n,2)y[i]=a[idx++];
  y[0]=a[idx];
  idx=n-1;
  step(i,2,n,2)y[i]=a[idx--];
  int calc=0;
  rep(i,n-1)calc+=abs(y[i]-y[i+1]);
  out(max(res,calc));
  
  
  return 0;
}


Measured memory_bytes: 2560
h, w = map(int, input().split())
a = [input() for _ in range(h)]
blank_h, blank_w = set(), set()
for i in range(h):
    count = 0
    for j in range(w):
        if a[i][j] != '.':
            break
        count += 1
    if count == w:
        blank_h.add(i)
for j in range(w):
    count = 0
    for i in range(h):
        if a[i][j] != '.':
            break
        count += 1
    if count == h:
        blank_w.add(j)
for i in range(h):
    if i in blank_h:
        continue
    for j in range(w):
        if j in blank_w:
            continue
        print(a[i][j], end='')
    print()

Measured memory_bytes: 4468
#include <bits/stdc++.h>
using namespace std;
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl;
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl;
#define dbv(v) cerr << #v << ":"; for (auto i : v) cerr << i << ' '; cerr << endl;
#define dbvp(v) cerr << #v << ":"; for (auto i : v) cerr << "{"  << i.f << ',' << i.s << "} "; cerr << endl;
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl;
#define pb push_back
#define pf push_front
#define oo (ll)1e18
#define inf (int)1e10
#define ll long long 
#define ld long double
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "hi\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
typedef tuple<ll,ll,ll> tl3;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string lts(ll x) {stringstream s; s << x; return s.str(); }
ll stl(string x) {stringstream s(x); ll temp; s >> temp; return temp; }
string cts(char x) {string s(1,x); return s;}
const int MOD = 1e9 + 7;
const int MAXN = 305;
template <typename T> void maxself(T& a, T b) {
    a = max(a, b);
}
template <typename T> void minself(T& a, T b) {
    a = min(a, b);
}

//#define cerr if(0)cout


int main() {
    IAMSPEED
	int a,b,c; cin >> a >> b >> c;
	if (a+b+c >= 22) cout << "bust";
	else cout << "win";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 998244353 
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; }
//(a+b-1)/b

signed main(){
	string s; cin>>s;
	ll n=s.size();
	map<ll,ll> mp;
	mp[0]++;
	reverse(all(s));
	ll cnt=1;
	ll now=0;
	for(ll i=0;i<n;i++){
		ll j=cnt*(s[i]-'0')%2019;
		cnt*=10; cnt%=2019;
		now+=j;
		now%=2019;
		mp[now]++;
	}
	ll ans=0;
	for(auto c:mp){
		//if(c.second>1)cout<<c.first<<" ";
		ll j=c.second*(c.second-1)/2;
		ans+=j;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3728
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;




//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main() {
	int n;
	cin >> n;
	long long int l[100];

	l[0] = 2;
	l[1] = 1;
	FOR(i, 2, 87) {
		l[i] = l[i - 1] + l[i - 2];
	}

	cout << l[n] << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define all(a) (a).begin(),(a).end()
#define double long double
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(all(a));
	vector<int> cnt;
	int s = 1, p = a[0];
	for (int i = 1; i < n; i++) {
		if (a[i] == p) s++;
		else {
			cnt.push_back(s);
			s = 1;
			p = a[i];
		}
	}
	cnt.push_back(s);
	int ns = cnt.size();
	for (int i = 0; i < n - ns; i++) cnt.push_back(0);
	sort(all(cnt));
	reverse(all(cnt));
	vector<int> sum(n);
	for (int i = 0; i < n; i++) sum[0] += cnt[i];
	for (int i = 1; i < n; i++) sum[i] = sum[i - 1] - cnt[i - 1];
	vector<int> res(n + 2);
	vector<double> frac(n + 2);
	for (double i = 0; i < n + 2; i++) {
		frac[i] = (double)(i / (i + 1));
	}
	for (int i = 1; i < n + 2; i++) {
		if (sum[i] != 0) {
			double ch = (double)sum[i] / (double)sum[i - 1] - 0.000000000001;
			int x = lower_bound(all(frac), ch) - frac.begin();
			res[i] = i + x - 1;
		}
		else {
			res[i] = res[i - 1] + 1;
		}
	}
	int t = 1, y = 0;
	for (int i = 0; i < n; i++) {
		while (i >= res[t]) {
			t++;
		}
		cout << sum[t - 1] / (i + 2 - t) << endl;
	}
}

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

int main(){
  int n,i,j;
  int **G;
  int num,k,adj;

  scanf("%d",&n);
  G = malloc(sizeof(int *)*n);
  for(i=0 ; i<n ; i++) G[i] = malloc(sizeof(int )*n);

  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++) G[i][j] = 0;
  }
  
  for(i=0 ; i<n ;i++){
    scanf("%d%d",&num,&k);
    for(j=0 ; j<k ; j++){
      scanf("%d",&adj);
      G[num-1][adj-1] = 1;
    }
  }

  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++){
      if(j == n-1)printf("%d\n",G[i][j]);
      else printf("%d ",G[i][j]);
    }
  }

  return 0;
}

Measured memory_bytes: 632
import java.util.HashMap;
import java.util.Scanner;

public class Main {
    static int N;
    static HashMap<Integer, Integer> a;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new HashMap<>();
        for(int i = 0; i < N; i++) {
            int number = scanner.nextInt();
            if(a.containsKey(number)) {
                Integer c = a.get(number);
                c++;
                a.put(number, c);
            } else {
                a.put(number, 1);
            }
        }

        scanner.close();
    }


    public static void main(String args[]) {
        init();

        int count = 0;
        for(Integer i : a.keySet()) {
            if(a.get(i) < i) {
                count += a.get(i);
            } else if (a.get(i) > i) {
                count += Math.abs(i - a.get(i));
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 61088
#include<iostream>
using namespace std;
int main(){
    int i,n;
    cin>>n;
    int ht[n+1],dp[n+1];
    for(i=1;i<=n;i++)
        cin>>ht[i];
    dp[1] = 0;
    dp[2] = abs(ht[2] - ht[1]);
    for(i=3;i<=n;i++){
        dp[i] = min(abs(ht[i]-ht[i-1]) + dp[i-1], abs(ht[i]-ht[i-2]) + dp[i-2]);
    }
    cout<<dp[n];
    // for(i=1;i<=n;i++)
    //     cout<<dp[i];
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
void ppp(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
}
ll nCr(int n,int k){
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(void){
  int n,m;
  scanf("%d %d",&n,&m);
  if(n<m){
    int t=n;
    n=m;
    m=t;
  }
  FOR(n)printf("%d",m);
  PRS("");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#include <cmath>

typedef long long ll;

using namespace std;

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll i = 2; i * i <= N; i++) {
        if (N % i != 0) continue;
        ll ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % i == 0) {
            ++ex;
            N /= i;
        }
        // その結果を push
        res.push_back({i, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll> > ans = prime_factorize(n);

    ll ans_size = ans.size();
    ll sum = 0;

    for(int i  = 0; i < ans_size; i++){
        ll cnt = 1;
        while(ans[i].second >= cnt){
            sum++;
            ans[i].second -= cnt;
            cnt++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 3640
n=int(input())
cnt=[0,0]
a=input()
for i in range(len(a)):
  if a[i]=='R':
    cnt[0]+=1
  else:
    cnt[1]+=1   
cnt_=[0,0]
for j in range(cnt[0]):
  if a[j]=='R':
    cnt_[0]+=1   
print(cnt[0]-cnt_[0])    

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, cand;
  cin >> N;
  vector<vector<int>> xyh(N, vector<int>(3));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> xyh[i][j];
    }
    if (xyh[i][2] > 0)
      cand = i;
  }
  for (int x = 0; x <= 100; x++) {
    for (int y = 0; y <= 100; y++) {
      int H     = xyh[cand][2] + abs(x - xyh[cand][0]) + abs(y - xyh[cand][1]);
      bool flag = true;
      for (int i = 0; i < N; i++) {
        if (xyh[i][2] != max(H - abs(x - xyh[i][0]) - abs(y - xyh[i][1]), 0)) {
          flag = false;
          break;
        }
      }
      if (flag) {
        cout << x << " " << y << " " << H << '\n';
        return 0;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
def a():
    n=list(map(int, input().split()))
    c=list()
    t = list()
    for i in range(n[0]):
        s = list(map(int, input().split()))
        c.append(s[0])
        t.append(s[1])
    z=list()
    z[len(z):]=t[:len(t)]
    z.sort()
    if z[0]>n[1]:
        print("TLE")
        return 0
    l=0
    for i in range(1,len(c)):
        if (c[i]<=c[l]) & (t[i]<=n[1]):
            l = i
    print(c[l])
    return 0
a()

Measured memory_bytes: 38460
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
j=0
m=sorted(p)
import itertools
for i in itertools.permutations(m):
    j+=1
    if list(i)==p:
        a=j
    if list(i)==q:
        b=j
print(abs(a-b))

Measured memory_bytes: 3064
class Bit:
    def __init__(self, n):
        """
        :param n: 最大の要素数
        """
        self.n = n
        self.tree = [0]*(n+1)
        self.depth = n.bit_length() - 1

    def sum(self, i):
        """ 区間[0,i) の総和を求める """
        s = 0
        i -= 1
        while i >= 0:
            s += self.tree[i]
            i = (i & (i + 1) )- 1
        return s

    def built(self, array):
        """ array を初期値とするBITを構築 """
        for i, a in enumerate(array):
            self.add(i, a)

    def add(self, i, x):
        """ i 番目の要素に x を足す """
        while i < self.n:
            self.tree[i] += x
            i |= i + 1

    def get(self, i, j):
        """ 部分区間和 [i, j) """
        if i == 0:
            return self.sum(j)
        return self.sum(j) - self.sum(i)

    def lower_bound(self, x, equal=False):
        """
        (a0+a1+...+ai < x となる最大の i (存在しない時は -1 ) , その時の a0+a1+...+ai )
        a0+a1+...+ai <= x としたい場合は equal = True
        二分探索であるため、ai>=0 を満たす必要がある
        """
        sum_ = 0
        pos = -1    # 1-indexed の時は pos = 0
        if not equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] < x:  # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        if equal:
            for i in range(self.depth, -1, -1):
                k = pos + (1 << i)
                if k < self.n and sum_ + self.tree[k] <= x: # 1-indexed の時は k <= self.n
                    sum_ += self.tree[k]
                    pos += 1 << i
        return pos, sum_

    def __getitem__(self, i):
        """ [a0, a1, a2, ...] """
        return self.get(i, i+1)

    def __iter__(self):
        """ [a0, a1, a2, ...] """
        for i in range(self.n):
            yield self.get(i, i+1)

    def __str__(self):
        text1 = " ".join(["element:            "] + list(map(str, self)))
        text2 = " ".join(["cumsum(1-indexed):  "] + list(str(self.sum(i)) for i in range(1, self.n + 1)))
        return "\n".join((text1, text2))

###############################################################
def solve(sign):
    B = Bit(N)
    B.built(A)
    res = 0
    for i in range(N):
        tmp = B.sum(i + 1)
        if tmp * sign > 0:
            B.add(i, -1 * sign * (abs(tmp) + 1))
            res += abs(tmp) + 1
        elif tmp == 0:
            B.add(i, -1 * sign)
            res += 1
        sign *= -1
    return res

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
print(min(solve(-1), solve(1)))


Measured memory_bytes: 86196
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cstdlib>
#include <sstream>
#include <bitset>

using namespace std;

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

typedef long long ll;
typedef vector<ll> Vec;
typedef pair<ll, ll> Pair;
#define rep(i, n) for(ll i=0;i<n;i++)

//static const ll MOD = 1000000007;
//static const ll INF = 100000000;
//#define PI 3.14159265359

ll multi5(ll x) {
    return pow(x, 5);
}

int main() {
    // input
    ll X;
    cin >> X;

    // process
    rep(a, 1000) {
        for (ll b = -1000; b < 1000; b++) {
            if (X == pow(a, 5) - pow(b, 5)) {
                cout << a << " " << b;
                return 0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int S = sc.nextInt();

		int h = S / 3600;
		int m = (S % 3600) / 60;
		int s = (S % 3600) % 60;

		System.out.println(h + ":" + m + ":" + s);
	}

}


Measured memory_bytes: 26416
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//234
	int n,k;
	cin>>n>>k;
	int cnt=0;
	while(n--) {
		int val;
		cin>>val;
		if(val>=k)cnt++;
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3652
LL = [int(i) for i in input().split()]
N = LL[0]
K = LL[1]
Q = LL[2]

A = [int(input()) for i in range(Q)]
Anslist = [0 for i in range(N)]

for a in range(Q):
    Anslist[A[a] - 1] += 1

for b in range(N):
    if Anslist[b] - Q + K <= 0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 8652
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>
#include<chrono>
#include<random>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

long double constexpr pi = 3.141592653589793;

template<class T>
constexpr T sigma1(T i, T n){
    return (n - i + 1) * (i + n) / 2;
}

template<class T>
constexpr T sigma2(T i, T n){
    return (i == 1 ? n * (n + 1) * (2 * n + 1) / 6 :
            sigma2(1, n) - sigma2(1, i - 1));
}

template<class T>
constexpr T sigma3(T i, T n){
    if (i == 1) {
        auto temp = sigma1(i, n);
        return temp * temp;
    }
    return sigma2(1, n) - sigma2(1, i - 1);
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


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

    ll s, w;

    cin >> s >> w;

    cout << (s <= w ? "unsafe" : "safe");

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<tuple<string,int,int>>ve(n);
  for(int i=0;i<n;i++){
    cin >> get<0>(ve.at(i)) >> get<1>(ve.at(i));
    get<1>(ve.at(i)) = 100-get<1>(ve.at(i));
    get<2>(ve.at(i)) = i+1;
  }
  sort(ve.begin(),ve.end());
  for(int i=0;i<n;i++)
    cout << get<2>(ve.at(i)) << endl;
}

Measured memory_bytes: 3552
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();
        if(str.length() == 1) {
            System.out.println(str);
            return;
        }
        long num = Long.parseLong(str.substring(1));
        int ans = Integer.parseInt(str.substring(0, 1)) + 9 * (str.length() - 1);
        if(num < Math.pow(10, str.length() - 1) - 1) {
            ans--;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int Cost(int a, int b, int c)
{
    return abs(a-b) + abs(b - c);
}

int main()
{
    int a1, a2, a3;
    int cost = 1000000000;
    cin >> a1 >> a2 >> a3;

    cost = min(cost, Cost(a1, a2, a3));
    cost = min(cost, Cost(a1, a3, a2));
    cost = min(cost, Cost(a2, a1, a3));
    cost = min(cost, Cost(a2, a1, a3));
    cost = min(cost, Cost(a3, a1, a2));
    cost = min(cost, Cost(a3, a2, a1));

    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 888
// //#define M_PI 3.14159265358979323846
// #define _USE_MATH_DEFINES

// //#define _GLIBCXX_DEBUG
// //#define all(x) (x).begin(),(x).end()

// #include <bits/stdc++.h>

// #define TASK ""
// #define sqr(x) ((x)*(x))
// typedef long long ll;
// typedef long double ld;
// typedef unsigned long long ull;
// using namespace std;
// const ll INFLL = numeric_limits<int>::max();
// const ll INFINT = numeric_limits<int>::max();
// const ld EPS = 1e-7;
// const ll MOD = 1000000000;
// const ll MAXN = 123456;

// void run()
// {
//     ll n;
//     cin >> n;
//     vector<ll> mas(n);
//     for (int i = 0; i < n; ++i)
//     {
//         cin >> mas[i];
//     }
//     sort(mas.begin(), mas.end());
//     ll ans = INFLL;
//     for (int i = -101; i < 101; i++)
//     {
//         ll ans2 = 0;
//         for (int j = 0; j < n; j++)
//         {
//             ans2 += sqr(i - mas[j]);
//         }
//         ans = min(ans, ans2);
//     }
//     cout << ans;
// }

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

// #ifdef LOCAL
// //#define STRESS
// #ifdef STRESS
//     freopen("input.txt", "w", stdout);
//     cout << "1000 50\n";
//     for (int i = 0; i < 999; i++)
//     {
//         for (int j = 0; j < 999; j++) cout << ".";
//         cout << "X\n";
//     }
//     for (int j = 0; j < 1000; j++)
//         if (j != 1000 / 50)cout << "X";
//         else cout << ".";
//     return 0;

// #endif
//     if (strcmp(TASK, "-") != 0)
//     {
//         freopen("input.txt", "r", stdin);
//         freopen("output.txt", "w", stdout);
//     }
// #else
//     if (strcmp(TASK, "")   != 0)
//     {
//         freopen(TASK".in", "r", stdin)  ;
//         freopen(TASK".out", "w", stdout)  ;
//     }
// #endif
//     run();

//     return 0;
// }

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define sqr(x) ((x)*(x))
typedef long long ll;

void solve()
{
    ll n;
    cin>>n;
    vector<ll> mas(n);
    for(int i=0;i<n;i++)cin>>mas[i];
    sort(begin(mas),end(mas));
    ll ans=1e9;
    for(int i=-101;i<101;i++)
    {
        ll ans2=0;
        for(int j=0;j<n;j++)
        {
            ans2+=sqr(i-mas[j]);

        }
        ans=min(ans,ans2);
    }
    cout<<ans;
}
main()
{
    solve();
    return 0;
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  while(cin >> s){
    ll j = 0, i = 0;
    rep(k,s.size()-2){
      if(s[k] == 'J' && s[k+1] == 'O' && s[k+2] == 'I'){
        ++j;
      }
      if(s[k] == 'I' && s[k+1] == 'O' && s[k+2] == 'I'){
        ++i;
      }
    }
    cout << j << endl;
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <math.h>
const int MOD = 1000000007;
using namespace std;

int main(){
    int a,b;
    float x;
	cin >> a >> b;

    x = float(a + b)/2;

    // cout << x << endl;

    cout << ceil(x) << endl;
}

Measured memory_bytes: 256
a = list(input())

b =0
for i in a:
    if i == "A":
        del a[0:b]
        break
    else:
      b += 1

c = list(reversed(a))

x = 0
for n in c:
    if n == "Z":
        del c[0:x]
        break
    else:
        x += 1
        
print(len(c))
   

Measured memory_bytes: 6708
object Main extends App {
  import scala.io.StdIn.readLine

  	var winState = readLine.split(" ").map(_.toInt)
    var a = winState(1) + winState(2)
  	var b = winState(2)
    var players = readLine.toString

  for (s <- players) {
      if(s == 'a' && a>0){a -= 1; println("Yes");}
      else if(s == 'b' && a>0 && b>0){a -= 1; b -= 1; println("Yes");}
      else println("No")
  }
}


Measured memory_bytes: 61764