akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}


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

  rep(i, h) {
    rep(j, w) {
      string s;
      cin >> s;
      if (s == "snuke") {
        cout << (char) ('A' + j) << i + 1 << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 256
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}
const int N=1e5+5;
int dp[105][N];
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int n,k;
    cin>>n>>k;
    int A[n];
    for(int i=0;i<n;i++)cin>>A[i];

    for(int i=0;i<=A[0];i++)
    dp[0][i]=1;
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            int up = j+A[i];
            
            dp[i][j]+=dp[i-1][j];
            dp[i][j]%=M2;
            dp[i][min(up+1,k+1)]-=dp[i-1][j];
            if(dp[i][min(up,k+1)]<0)
            dp[i][min(up,k+1)]+=M2;
        }
        for(int j=1;j<=k;j++)
        {
            dp[i][j]+=dp[i][j-1];
            dp[i][j]%=M2;
        }
    }
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<=k;j++)
        cout<<dp[i][j]<<" ";

        cout<<endl;
    }*/
    cout<<dp[n-1][k];


return 0;
}

Measured memory_bytes: 80128
lines=readlines(open("/dev/fd/0"))
input()=shift!(lines)
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine()=map(intSub,split(input()))
function main()
  w,h,x,y=intLine()
  println(.5w*h,' ',+(.5(w+h)==x+y))
end
main()

Measured memory_bytes: 113040
void main()
{
    string n = rdStr;

    long len = n.length;
    long total;
    foreach (x; n)
    {
        total += x - '0';
    }

    max(total, (n[0]-'1')+9*(len-1)).writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

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

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
int arr[5];
  // taking input
  for (int i = 0; i < 5; i++)
    cin >> arr[i];
// defining a vector
  vector<int> res;
  int summ = 0;
  for (int i = 0; i < 5; i++){
  	int temp = arr[i]%10;
    if(temp != 0) res.push_back(temp);
    summ += arr[i]/10;
  }
  (res.size()!=0)? cout << summ*10 + *min_element(res.begin(), res.end()) + (res.size()-1)*10 << '\n' : cout << summ*10 <<'\n';
	return 0;
}

Measured memory_bytes: 256
import sys

nil = -1

class Node:
    def __init__(self):
        self.parent = nil
        self.sibling = nil
        self.degree = 0
        self.left = nil
        self.right = nil
        self.depth = nil
        self.height = nil
        self.ntype = 'leaf'

def set_depth(v, depth):
    bitree[v].depth = depth

    if bitree[v].left != nil:
        set_depth(bitree[v].left, depth + 1)

    if bitree[v].right != nil:
        set_depth(bitree[v].right, depth + 1)

def set_height(v, height):
    while v != -1:
        if height > bitree[v].height:
            bitree[v].height = height
            v = bitree[v].parent
            height += 1
        else:
            break

n = int(input())
bitree = [Node() for i in range(n)]
leaves = set()

for i in range(n):
    line = [int(j) for j in input().split()]
    t_id = line[0]
    bitree[t_id].left = line[1]
    bitree[t_id].right = line[2]
    bitree[t_id].degree = (line[1] != nil) + (line[2] != nil)

    if bitree[t_id].degree > 0:
        bitree[t_id].ntype = 'internal node'

        if bitree[t_id].left != nil:
            bitree[bitree[t_id].left].parent = t_id

        if bitree[t_id].right != nil:
            bitree[bitree[t_id].right].parent = t_id

        if bitree[t_id].degree == 2:
            bitree[bitree[t_id].left].sibling = bitree[t_id].right
            bitree[bitree[t_id].right].sibling = bitree[t_id].left
    else:
        leaves.add(t_id)

for t_id in range(n):
    if bitree[t_id].parent == nil:
        bitree[t_id].ntype = 'root'
        r = t_id
        break

set_depth(r, 0)

for leaf in leaves:
    set_height(leaf, 0)

for t_id in range(n):

    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
            t_id, bitree[t_id].parent, bitree[t_id].sibling, bitree[t_id].degree,
            bitree[t_id].depth, bitree[t_id].height, bitree[t_id].ntype))

Measured memory_bytes: 7884
#include<bits/stdc++.h>
#define lson l, mid
#define rson mid+1, r
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 2e5+5;

vector<int> ans;
bool visit[N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    while(m--) {
        int u, v;
        scanf("%d%d", &u, &v);
        if(u > v)
            swap(u, v);
        if(u == 1) {
            ans.push_back(v);
        }
        if(v == n) {
            visit[u] = true;
        }
    }
    bool flag = false;
    for(int i=0; i<Size(ans) && !flag; i++) {
        int x = ans[i];
        if(visit[x])
            flag = true;
    }
    if(flag)
        printf("POSSIBLE\n");
    else
        printf("IMPOSSIBLE\n");
}



Measured memory_bytes: 1020
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#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 LL long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define FILL(a,v) memset((void*)a,v,sizeof(a))
#define FILL0(a) FILL(a,0)
#define FILL1(a) FILL(a,-1)
#define ALL(a) (a).begin(),(a).end()
#define Inf 1e9
#define Mod 1000000007
#define foreach(it,x) for(typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define FOR(i,x) for(int i=0;i<x;i++)
#define RFOR(i,x) for(int i=x-1;i>=0;i--)
#define FFOR(i,a,b) for(int i=a;i<b;i++)
#define FRFOR(i,a,b) for(int i=a-1;i>=b;i--)
#define SZ(a) ((int)(a).size())
#define FI first
#define SE second
#define OVER(a) return puts(a),0
using namespace std;
using namespace __gnu_cxx;
typedef pair<int,int> pii;
typedef unsigned long long UINT;
typedef unsigned int Uint;
typedef long long INT;
typedef pair<INT,INT> PII;

int n,a[200007];
vector<int> b,c;

int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if((n-i)%2==0) c.push_back(a[i]);
		else b.push_back(a[i]);
	}
	for(int i=SZ(b)-1;i>=0;i--)
		printf("%d ",b[i]);
	for(int i=0;i<SZ(c);i++)
		printf("%d%c",c[i],i==SZ(c)-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <fstream>
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <numeric>
#include <functional>
#include <string> 
#include <vector>
#include <bitset>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>

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

#define REP(i,n) for(int i = 0; i < int(n); i++)
#define REREP(i,n) for(int i = int(n - 1); i >= 0; i--)
#define FOR(i, m, n) for(int i = int(m);i < int(n);i++)
#define REFOR(i, m, n) for(int i = int(n - 1);i >= int(m);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define fi first 
#define se second

#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VD vector<double>
#define VVD vector<vector<double>>
#define VVVD vector<vector<vector<double>>>
#define VL vector<ll>
#define VVL vector<vector<ll>>
#define VVVL vector<vector<vector<ll>>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define VVVB vector<vector<vector<bool>>>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVVS vector<vector<vector<string>>>

#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<ll,ll>
#define VPII vector<pair<int,int>>
#define VVPII vector<vector<pair<int,int>>>
#define VVVPII vector<vector<vector<pair<int,int>>>>
#define VPLL vector<pair<ll,ll>>
#define VVPLL vector<vector<pair<ll,ll>>>
#define VVVPLL vector<vector<vector<pair<ll,ll>>>>

const ll MOD = (ll)1e9 + 7;
const ll HINF = (ll)1e18;
const ll LINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;


void YN(bool flag) {
	cout << ((flag) ? "YES" : "NO") << endl;
}

void Yn(bool flag) {
	cout << ((flag) ? "Yes" : "No") << endl;
}

void yn(bool flag) {
	cout << ((flag) ? "yes" : "no") << endl;
}

int main() {
	string S; cin >> S;
	VI cnt(3,0);
	REP(i, S.size()) cnt[S[i] - 'a']++;
	YN(*max_element(ALL(cnt)) - *min_element(ALL(cnt)) <= 1);
		
	return 0;
}



Measured memory_bytes: 512
from collections import defaultdict


n = int(input())
jisho = defaultdict(int)
for _ in range(n):
    s = input()
    if int(float(s)) == float(s):
        num = int(float(s))
        cnt2 = 0
        cnt5 = 0
    else:
        a, b = s.split(".")
        keta = len(b)
        cnt2 = -keta
        cnt5 = -keta
        a = int(a)
        b = int(b)
        num = a * pow(10, keta) + b
    while True:
        if num % 5 == 0:
            num //= 5
            cnt5 += 1
        else:
            break
    while True:
        if num % 2 == 0:
            num //= 2
            cnt2 += 1
        else:
            break
    if cnt5 <= -11 or cnt2 <= -11:
        continue
    cnt2 = min(10, cnt2)
    cnt5 = min(10, cnt5)
    jisho[(cnt2, cnt5)] += 1
ans = 0
for i in range(21):
    i -= 10
    for j in range(21):
        j -= 10
        kouho1 = jisho[(i, j)]
        if kouho1 == 0:
            continue
        for k in range(21):
            k -= 10
            for l in range(21):
                l -= 10
                kouho2 = jisho[(k, l)]
                if kouho2 == 0:
                    continue

                if i + k >= 0 and j + l >= 0:
                    if (i, j) == (k, l):
                        ans += kouho1 * (kouho2 - 1)
                    else:
                        ans += kouho1 * kouho2

print(ans // 2)


Measured memory_bytes: 83468
def count(N,K):
    a=0
    while K>N:
        N=N*2
        a=a+1
    return a




N,K=input().split()
N=int(N)
K=int(K)
a=[0]*N
for num in range(0,N):
    a[num]=num+1
ans=0
for num in range(0,N):
    ans=ans+pow(0.5,count(a[num],K))
print(ans/N)

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

int main(){
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    if(A+B < C+D){
        cout << "Right" << endl;
    }
    else if(A+B == C+D){
        cout << "Balanced" << endl;
    }
    else{
        cout << "Left" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

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

    //A[0]~A[N-1]に格納する
    int* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%d",&A[i]);
    }
    qsort(A,N,sizeof(int),asc);

    int* B;
    NEW(B,N);
    int block=0;
    int tmp=1;
    if(N==1){
        block=1;
        B[0]=1;
    }
    else{
        for(int i=1;i<N;i++){
            if(A[i]==A[i-1]) tmp++;
            else{
                B[block]=tmp;
                tmp=1;
                block++;
            }
        }
        B[block]=tmp;
        block++;
    }
    qsort(B,block,sizeof(int),asc);

    int ans=0;
    for(int i=0;i<(block-K);i++){
        ans+=B[i];
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    long N;
    long K;
    long Q;
    cin >> N >> K >> Q;
    long sankasya[N] = {};
    vector<long> A(Q);
    for (long i = 0; i < Q ; i++) {
        std::cin >> A.at(i);
    }
    for (long j = 0; j < Q; j++)
    {
       sankasya[A[j]-1] = sankasya[A[j]-1]+1;
    }
    for (long l = 0; l < N; l++)
    {
        if ((K-Q+sankasya[l]) <= 0)
        {
            cout << "No" <<endl;
        }else{
            cout << "Yes"<<endl;
        }
    }
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N; cin >> N;
  vector<int64_t> dp(N, 1e15), hs(N); dp[0] = 0; for (auto &h : hs) cin >> h;
  for (int i = 0; i < N - 1; ++i)
    {dp[i + 1] = min(dp[i + 1], dp[i] + abs(hs[i] - hs[i + 1]));
    if (i + 2 < N) dp[i + 2] = min(dp[i + 2], dp[i] + abs(hs[i] - hs[i + 2]));}
  cout << dp[N - 1] << endl;}

Measured memory_bytes: 4792
#include <cstdio>

using namespace std;

int main()
{
    int n;
    scanf("%d", &n);
    int sum;
    if(n==0){
        sum=1;
    } else if(n==1){
        sum=1;
    } else{
        int older=1, oldest=1;
        sum=0;
        for(int i=2; i<=n; i++){
            sum=older+oldest;
            oldest=older;
            older=sum;
        }
    }
    printf("%d\n", sum);
    return 0;
}

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

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

const int N = 100000;
const int Q = 50000;
vector<ll> s(N);
vector<ll> t(Q);

// index が条件を満たすかどうか
bool isOK(int index, int key) {
    if (s[index] >= key) return true;
    else return false;
}

// 汎用的な二分探索のテンプレ
int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = (int)s.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

    /* ok と ng のどちらが大きいかわからないことを考慮 */
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;

        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    if (s[ok] != key) {
      ok = -1;
    }
    return ok;
}

int main() {
  ll n, q;
  cin >> n;
  s.resize(n);
  rep(i, n) cin >> s[i];
  cin >> q;
  t.resize(q);
  rep(i, q) cin >> t[i];

  ll ans = 0;

  rep(i, q) {
    if (binary_search(t[i]) != -1) ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3756
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
	int n;
  cin >> n;
  int ans = 1000 * (n / 500);
  n %= 500;
  ans += 5 * (n / 5);
  cout << ans << '\n';
} 

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

int main() {
  int m, d;
  cin >> m >> d;
  
  int ans = 0;
  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= d; j++){
      int k = j, mul = 1;
      bool ok = false;
      if(j < 22) continue;
      while(k > 0){
        int t = k % 10;
        if(t < 2) ok = true;
        mul *= t;
        k /= 10;
      }
      if(ok) continue;
      if(mul == i) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
	int x, y;
	while (1)
	{
		scanf("%d%d", &x, &y);
		if (x == 0 && y == 0) break;
		if (x < y) printf("%d %d\n", x, y);
		else printf("%d %d\n", y, x);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
int main(){
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1){
			puts("F");
		}
		else if(m+f>=80){
			puts("A");
		}
		else if(m+f>=65){
			puts("B");
		}
		else if(m+f>=50||r>=50){
			puts("C");
		}
		else if(m+f>=30){
			puts("D");
		}
		else{
			puts("F");
		}
	}
	return 0;
}


Measured memory_bytes: 2124
#include <stdio.h>
#include <stack>
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int main()
{
    int n;
    int mp[3][105];
    scanf("%d",&n);
    memset(mp,0,sizeof(mp));
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
        scanf("%d",&mp[i][j]);
    }
    for(int i=1;i<=2;i++)
    {
        for(int j=1;j<=n;j++)
            mp[i][j]+=max(mp[i][j-1],mp[i-1][j]);
    }
    printf("%d\n",mp[2][n]);
    return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
ll n, a[200005], now, b[200005], cnt[200005], tow[200005], ans;
bool vis[200005];

ll ef(ll l, ll r, ll v)
{
	if (l == r)
	{
		if (a[l] == v) return l;
		else return 0;
	}
	ll mid = (l + r) / 2;
	if (a[mid] >= v) return ef(l, mid, v);
	else return ef(mid + 1, r, v);
}

int main()
{
	cin >> n;
	for (ll i = 1; i <= n; i++)
	{
		cin >> a[i];
	} 
	sort(a + 1, a + n + 1);
	for (ll i = 1; i <= n; i++)
	{
		if (a[i] != a[i - 1]) b[i] = b[i - 1] + 1;
		else b[i] = b[i - 1];
		cnt[b[i]]++;
		tow[b[i]] = a[i];
		//cout << b[i] << " ";
	}
	now = 1;
	while (now <= a[n]) now *= 2;
	for (ll i = b[n]; i >= 1; i--)
	{
		if (now / 2 > tow[i]) now /= 2;
		ll x = ef(1, n, now - tow[i]);
		x = b[x];
		if (x == 0) continue;
		ll res = min(cnt[i], cnt[x]);
		if (x != i)
		{
			cnt[i] -= res;
			cnt[x] -= res;
		}
		else
		{
			res /= 2;
			cnt[i] -= res;
		}
		//cout << x << " " << tow[x] << " " << tow[i] << " " << res << endl;
		ans += res;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6528
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

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

	bool G[n + 1][n + 1];
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n; ++j)
			G[i][j] = false;
	}

	for (int i = 0; i < n; ++i) {
		int u, k;
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; ++j) {
			int v;
			scanf("%d", &v);
			G[u][v] = true;
		}
	}

	int d[n + 1];
	for (int i = 0; i <= n; ++i)
		d[i] = -1;

	int color[n + 1];
	int WHITE = 0;
	int GRAY = 1;
	int BLACK = 2;
	for (int i = 0; i <= n; ++i)
		color[i] = WHITE;

	queue<int> Q;
	Q.push(1);
	d[1] = 0;
	color[1] = GRAY;

	while (Q.size() != 0) {
		int v = Q.front();
		for (int i = 1; i <= n; ++i) {
			if (G[v][i] && color[i] == WHITE) {
				Q.push(i);
				color[i] = GRAY;
				d[i] = d[v] + 1;
			}
		}
		Q.pop();
		color[v] = BLACK;
	}
	for (int i = 1; i <= n; ++i) {
		cout << i << " " << d[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3120
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        char c = sc.next().charAt(0);
        
        if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
            System.out.println("vowel");
        }else{
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int n;
int d[100000];
int color[100000];
vector<pair<int,int> > adj[100000];
#define WHITE 0
#define BLACK 2
#define GRAY 1
void dijkstra(){
  rep(i,n)d[i]=INT_MAX;
  priority_queue< pair<int,int> > PQ;
  rep(i,n)color[i]=WHITE;
  d[0]=0;
  PQ.push(make_pair(0,0));
  color[0]=GRAY;
  while(!PQ.empty()){
    pair<int,int> f=PQ.top();
    PQ.pop();
    int u=f.second;
    color[u]=BLACK;
    if(d[u]<f.first*(-1))continue;
    rep(j,(int)adj[u].size()){
      int v=adj[u][j].first;
      if(color[v]==BLACK)continue;
      if(d[v]>d[u]+adj[u][j].second){
	d[v]=d[u]+adj[u][j].second;
	PQ.push(make_pair(d[v]*(-1),v));
	color[v]=GRAY;
      }
    }
  }
  rep(i,n)cout<<i<<" "<<(d[i]==INT_MAX?-1:d[i])<<endl;
}


int main(){
  int a,b,c,d;
  cin>>n;
  rep(i,n){
    cin>>a>>b;
    rep(j,b){
      cin>>c>>d;
      adj[a].push_back(make_pair(c,d));
    }
  }
  dijkstra();
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<int> P(N),Q(N),nums(N);
    for(int i=0;i<N;i++){
        cin >> P[i];
    }

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

    for(int i=0;i<N;i++){
        nums[i]=i+1;
    }

    int n=0;
    int n_p,n_q;
    n_p=0;
    n_q=0;
    while (next_permutation(nums.begin(), nums.end())){
        n++;
        for(int i=0;i<N;i++){
            if(nums[i]!=P[i]) break;
            if(i==N-1) n_p=n;
        }

        for(int i=0;i<N;i++){
            if(nums[i]!=Q[i]) break;
            if(i==N-1) n_q=n;
        }

    }

    cout << abs(n_p-n_q) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010

ll f[M],iv[M];
ll ex(ll a,ll b){
	ll ans=1;a%=md;
	while(b){
		if(b&1)ans=(ans*a)%md;
		a=(a*a)%md;b/=2;
	}
	return ans;
}
ll C(ll n,ll r){
	if(n<r)return 0;
	ll ans=(f[n]*iv[r])%md;
	ans=(ans*iv[n-r])%md;
	return ans;
}
int main(){
	IOS;
	f[0]=1,iv[0]=1;
	rep(i,1,M)f[i]=(i*f[i-1])%md;
	iv[M-1]=ex(f[M-1],md-2);
	for(ll i=M-2;i>=0;--i)iv[i]=(iv[i+1]*(i+1))%md;
	ll p=0,m=0;
	ll n,k;cin>>n>>k;
	ll a[n];rep(i,0,n)cin>>a[i];
	sort(a,a+n);
	rep(i,0,n){
		ll left=i,right=n-1-i;
		p=(p+a[i]*C(left,k-1))%md;
		m=(m+a[i]*C(right,k-1))%md;
	}
	ll ans=(p-m+md)%md;
	cout<<ans;
	return 0;
}



Measured memory_bytes: 16640
import java.util.*;
import java.lang.*;

class MathLib{
    public static long divCeil(long a, long b){
        return (a+b-1)/a;
    }

    public static long gcd(long a, long b){
        if(a<b) return gcd(b,a);
        if(b==0) return a;
        if(a%b==0) return b;
        return gcd(b,a%b);
    }
    public static long lcm(long a, long b){
        return (a/gcd(a,b))*b;
    }

    public static LinkedList<Long> divisors(long N){
        LinkedList<Long> ans = new LinkedList<>();
        for(long n = (long)(Math.sqrt(N)+2); n>0; n--){
            if(n*n>N) continue;
            else if(n*n==N) ans.add(n);
            else if(N%n==0){
                ans.addFirst(n);
                ans.addLast(N/n);
            }
        }
        return ans;
    }
}
public class Main {
    static void printArray(int[] array){
        for(int i=0; i<array.length-1; i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[array.length-1]);
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        TreeSet<Integer> gather = new TreeSet<>();
        for(int n=0; n<N-1; n++){
            if(S.charAt(n)=='R' && S.charAt(n+1)=='L') gather.add(n);
        }

        int[] ans = new int[N];
        for(int n=0; n<N; n++){
            int g = (S.charAt(n)=='R') ? gather.tailSet(n).first() : gather.headSet(n).last();
            if(n%2 == g%2) ans[g]++;
            else ans[g+1]++;
        }
       printArray(ans);
    }
}


Measured memory_bytes: 42184
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
fn main(){
    input!{
        n:i64,
        an:[i64;n],
    }
    let map = an.iter().fold(HashMap::new(),|mut map,x|{
        let y = map.get(&x).map(|&i| i +1).unwrap_or(1);
        map.insert(x,y);
        map
    });
    let master = map.iter().filter(|&(k,v)| {
        *v == 2
    }).map(|(k,v)|*v).collect::<Vec<i64>>();
    if master.len() as i64 != n / 2 {println!("0"); return;}
    let mut ans = master.iter().fold(1,|y,x| (y * x) % (1e9 as i64 + 7));
    if n % 2 != 0 && an.iter().filter(|&x| *x == 0).count() != 1 {
        println!("0");
        return;
    }
    println!("{}",ans);
}


Measured memory_bytes: 12540
#include <iostream>
#include <cstdio>
#define ll long long
using namespace std;

inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x=0;char ch=gc();bool positive=1;
	for(;!isdigit(ch);ch=gc())if(ch=='-')positive=0;
	for(;isdigit(ch);ch=gc())x=x*10+ch-'0';
	return positive?x:-x;
}

inline void write(ll x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(ll x){
	write(x);puts("");
}
#include <map>
#define Max 200005
long long n,ans,sum;
map<long long,long long>vis;

int main(){
	n=read();vis[0]=1;
	for(int i=1;i<=n;i++){
		sum+=read();
		ans+=vis[sum];
		vis[sum]++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12800
N = int(input())
H = input().split()
for i in range(0,N):
    H[i] = int(H[i])
H[0] = H[0]-1
s = 0
for i in range(0,N-2):
    if H[i]==H[i+1]:
        if H[i+2]>=H[i+1]:
            continue
        else:
            s = 10
            break
    elif H[i]<H[i+1]:
        if H[i+1]-1<=H[i+2]:
            H[i+1] = H[i+1]-1
            continue
        else:
            s = 10
            break
    else:
        s = 10
        break
if s == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 12012
// Minesweeper
#include <cmath>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;

int main() {
    int h, w;
    cin >> h >> w;
    string board[50];
    for (int i = 0; i < h; ++i) cin >> board[i];

    int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (board[i][j] == '.') {
                int count = 0;
                for (int k = 0; k < 8; ++k){
                    int x = j + dx[k];
                    int y = i + dy[k];
                    if (-1 < x && x < w && -1 < y && y < h && board[y][x] == '#') count++;
                }
                board[i][j] = char(count + '0');
            }
        }
    }
    for (int i = 0; i < h; ++i) {
        cout << board[i] << endl;
    }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi a(n),cnt(n+1);
    rep(i,n){
        cin>>a[i];
        cnt[a[i]]++;
    }
    vi p(n+1);
    REP(i,1,n)p[i]=cnt[i]*(cnt[i]-1)/2;
    int s=accumulate(all(p),0ll);
    rep(i,n){
        cout<<s-p[a[i]]+(cnt[a[i]]-1)*(cnt[a[i]]-2)/2<<endl;
    }
}

Measured memory_bytes: 7296
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	string s; cin >> s;
	char l = s.back();
	if(l == '2' or l == '4' or l == '5' or l == '7' or l == '9') println("hon");
	else if(l == '0' or l == '1' or l == '6' or l == '8') println("pon");
	else println("bon");
}


Measured memory_bytes: 3652
#include <iostream>

int main()
{
    int sec, min, hour;
    std::cin >> min;
    sec = min / 60;
    min %= 60;
    hour = sec / 60;
    sec %= 60;
    std::cout << hour << ":" << sec << ":" << min << std::endl;
    return 0;
}

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

namespace _0267
{
    class Program
    {
        const int LIM = 10000;
        static void Main(string[] args)
        {
            while (true)
            {
                int n = RInt();
                if (n == 0) break;

                int[] blocks = RArInt();
                int res = IsTriNum(blocks.Sum()) ? GetOpeCount(blocks.ToList()) : -1;
                Console.WriteLine(res);
            }
        }

        private static bool IsTriNum(int v)
        {
            double EPS = 10e-9;
            double n = (Math.Sqrt(8 * v + 1) - 1) / 2;
            return Math.Abs(n - Math.Round(n)) < EPS;
        }

        private static int GetOpeCount(List<int> blocks)
        {
            int cnt = 0;
            while (true)
            {
                if (cnt > LIM) return -1;
                if (blocks.Select((x, i) => new { x, i }).All(x => x.x == x.i + 1)) return cnt;

                List<int> nBlocks = new List<int>();
                for (int i = 0; i < blocks.Count(); i++)
                {
                    if (blocks[i] > 1) nBlocks.Add(blocks[i] - 1);
                }
                nBlocks.Add(blocks.Count());
                blocks = nBlocks;
                cnt++;
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RArSt(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RArInt(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RArLong(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RArDouble(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }
}



Measured memory_bytes: 42528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr ll INF = 1e18;
int main(){ 
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());

  if (a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  ll res = 1;
  for (int i = 0; i < n; i++) {
    if (res > INF / a[i]) {
      cout << -1 << endl;
      return 0;
    }
    res *= a[i];
  }
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 4052
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll=long long;
using P=pair<int,int>;
const int INF=1001001001;

int main(){
    int h,w,k; cin>>h>>w>>k;
    vector<string> s(h);
    rep(i,h) cin>>s[i];
    int ans =0;
    for(int is=0;is<(1<<h);is++){
        for(int js=0;js<(1<<w);js++){
            int cnt = 0;
            rep(i,h)rep(j,w){
                //塗りつぶしたとき
                if(is>>i&1) continue;
                if(js>>j&1) continue;
                if(s[i][j] == '#') cnt++;
            }
            if(cnt == k) ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vd(T) vector<vector<T>>
#define v(T) vector<T>
#define mod (ll)(1e9+7)
#define pp(T) pair<T,T>
#define pb push_back
#define mp make_pair
#define NN 100005
#define IO ios_base::sync_with_stdio(NULL),cin.tie(0),cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define DEBUG cout<<"***********DEBUGGING***********"<<endl
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; 
ll power(ll a,ll b){ if(b==0) return 1; ll s=power(a,b/2); s*=s;if(b&1) return s*a; return s;}
ll powermod(ll a,ll b,ll m){ if(b==0) return 1; ll s=power(a,b/2);s*=s; s%=m; if(b&1) return (s*a)%m; return s;}
inline int add(ll a,ll b,ll m=0){
    if(m==0) return a+b;
    return (a%m+b%m)%m;
}

inline int sub(ll a,ll b ,ll m=0){
    if(m==0) return a-b;
    return ((a%m-b%m)%m+m)%m;
}

inline int mul(ll a,ll b,ll m=0){
    if(m==0)return (a*b);
    return ((a%m)*(b%m))%m;
}

inline int div(ll a,ll b,ll m=0){
    if(m==0) return a/b;
    return ((a%m)*(powermod(a,b,m-2)%m))%m;
}

bool isopen(char c){
    return ((c=='(')||(c=='{')||(c=='['));
}

ll longest_balanced_parenthesis(string a,ll n){
    stack<char> s;
    ll start=0;
    ll ans=0,m=0;
    for(ll i=0;i<n;i++){
        if(isopen(a[i])){
            s.push(a[i]);
        }
        else{
            if(isopen(a[i])|| s.empty()){
                m=max(m,ans);
                continue;
            }
            else{
                s.pop();
                ans+=2;
                m=max(ans,m);
            }
        }
    }

    return m;

}

ll setup_k(ll *a,ll k){
  ordered_set x;
  // Now , insert and then check number of integers less than k by just using x.order_of_key(k+1)
}

int main() {

    IO; 

    string s;
    cin>>s;
    ll a=0,b=0;
    for(ll i=0;s[i];i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(ll i=s.length()-1;i>=0;i--){
        if(s[i]=='Z'){
            b=i;
            break;
        }
    }
    cout<<b-a+1<<endl;
}

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

using namespace std;

typedef long long ll;
typedef complex<double> point;
#define mapii map<int, int>
#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define forit(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define forrit(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define maxN 2005
#define MOD 1000
#define oo 1000000007
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int n, a[2*maxN], costB[maxN][maxN], costW[maxN][maxN], dp[maxN][maxN];
char c[2*maxN];

void Calc(int cost[][maxN]) {
    vector<int> cntLess(n+1, 0), posW(n+1, 0), posB(n+1, 0);

    fto(i, 1, 2*n) {
        if (c[i] == 'B') posW[a[i]] = i;
        else posB[a[i]] = i;
    }

    fto(i, 1, n) {
        fto(j, 1, i-1) {
            if (posB[j] < posB[i]) ++cntLess[i];
        }
    }

    fto(j, 0, n-1) cost[0][j] = posB[j+1]-1-cntLess[j+1];
    fto(i, 1, n) {
        fto(j, 0, n-1) {
            cost[i][j] = cost[i-1][j];
            if (posW[i] < posB[j+1]) --cost[i][j];
        }
    }
}

int main () {
    scanf("%d", &n);
    fto(i, 1, 2*n) {
        char s[2];
        scanf("%s%d", s, &a[i]);
        c[i] = s[0];
    }

    Calc(costB);
    fto(i, 1, 2*n) c[i] = 'B'+'W'-c[i];
    Calc(costW);

//    puts("CostB:");
//    fto(i, 0, n) {
//        fto(j, 0, n-1) printf("%d ", costB[i][j]);
//        puts("");
//    }
//    puts("CostW:");
//    fto(i, 0, n) {
//        fto(j, 0, n-1) printf("%d ", costW[i][j]);
//        puts("");
//    }

    fto(i, 0, n) fto(j, 0, n) dp[i][j] = oo;

    dp[0][0] = 0;
    fto(i, 0, n) {
        fto(j, 0, n) {
            if (i < n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+costW[j][i]);
            if (j < n) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+costB[i][j]);
        }
    }

    printf("%d", dp[n][n]);

    return 0;
}


Measured memory_bytes: 47360
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1001

int cc = 0;

int  check(int p){
  return p/500+p%500/100+p%100/50+p%50/10;
}

bool calc(){
  int p;
  int c[4] = {10,50,100,500};
  int k[4],min_c = INF,ans[4] = {};
  
  scanf("%d",&p);
  if(p==0) return false;

  if(cc++>0) printf("\n");

  for(int i=0;i<4;i++) scanf("%d",k+i);


  for(int i=0;i<=k[0];i++){
    for(int j=0;j<=k[1];j++){
      for(int l=0;l<=k[2];l++){
	for(int m=0;m<=k[3];m++){
	  int sum = i*c[0]+j*c[1]+l*c[2]+m*c[3];
	  if(sum < p) continue;
	  int r = check(sum-p)-(i+j+l+m);
	  if(min_c > r){
	    min_c = r;
	    ans[0] = i;
	    ans[1] = j;
	    ans[2] = l;
	    ans[3] = m;
	  }
	}
      }
    }
  }
	
  
  for(int i=0;i<4;i++){
    if(ans[i] > 0){
      printf("%d %d\n",c[i],ans[i]);
    }
  }

  return true;
}
  
int main(){
  
  while(calc());
  
  return 0;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int n,m;
const int maxn=101000;
bool vis[100];
char s[100];
int main()
{
    int x,y;
    cin>>x>>y;
    if(x*500>=y)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}
/*
3
10 3
1 2 3
0 1 2
100 7
3 4 5 6 7 8 9
1 2 3 4 5 6 7
10000 10
1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9
*/



Measured memory_bytes: 384
package main

import (
	"errors"
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	var ret int
	var err error
	ret, err = HolydayYasumi(s)
	if err == nil {
		fmt.Println(ret)
	}
}
func HolydayYasumi(s string) (int, error) {
	week := []string{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
	for idx, day := range week {
		if day == s {
			return 7 - idx, nil
		}
	}
	return -1, errors.New("invalid input")
}


Measured memory_bytes: 512
import math
ini = lambda : int(input())
inm = lambda : map(int,input().split())
inl = lambda : list(map(int,input().split()))
gcd = lambda x,y : gcd(y,x%y) if x%y else y
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
mod = 10**9 + 7

#maincode-------------------------------------------------

x = int(input())
if x:
    print(0)
else:
    print(1)

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string n;
   cin>>n;
   bool pd=false;
   for(int i=0;i<n.size();i++)
   if(n[i]=='7')
   pd=true;
   if(pd)
   cout<<"Yes";
   else
   cout<<"No";
   return 0;	
} 

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back 
const int mod=1e9+7;

int main(){
	int n;
	cin>>n;
	  unordered_map<string,int>m;
	  for(int i=0; i<n; i++){
	     string s;
	       cin>>s;
	       sort(s.begin(),s.end());
	       m[s]++;
	  }
	  ll sum=0;
	  for(auto i: m ){
	      ll k=i.second;
	       sum= sum+ (ll)(k-1)*k/2;
	  }
	  cout<<sum<<endl;
  }
    

// a  A  za  Z  q  Q  !  1 


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

using namespace std;

int main(){
  int N, K;
  cin >> N >> K;
  vector<long> m(K, 0);
  
  for(int i = 1; i <= N; i++){
    m[i%K] += 1;
  }
  
  long ans = 0;
  long tmp;
  for(int i = 1; i <= N; i++){
    tmp = (K - i%K) % K;
    if( (tmp + tmp) % K == 0){
      ans += m[tmp] * m[tmp];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792