akhauriyash/Code-Regression huggingface dataset:
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op=='?':
        break
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(a*b)
    elif op=='/':
        print(a//b)


Measured memory_bytes: 5592
#include <iostream>
#include <set>
#include <queue>
#include <utility>
#include <bits/stdc++.h>
typedef long long ll;
typedef std::pair<int,int> ii;
using namespace std;

int main() {
    map<char, int>mp;
    string s; cin >> s;
    string ans = "Yes";
    for(auto c : s){
        mp[c]++;
    }
    int target = s.size()/2;
    if(mp.size() != 2) ans = "No"; 
    for(auto it = mp.begin(); it != mp.end(); ++it){
       if(it->first != 'h' && it->first != 'i'){
           ans = "No";
           break;
       }
       if(it->second != target){
           ans = "No";
           break;
       }
    }
    for(int i = 0 ; i < s.size(); i++){
        if(i % 2 == 0 && s[i] != 'h') ans = "No";
        if(i % 2 != 0 && s[i] != 'i') ans = "No";
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
s = gets.chomp.split("").map(&:to_i)
length = s.length
sum = []

(0..length-3).each do |number|
  sum.push(s.slice(number,3).join.to_i)
end

answer = (sum.first - 753).abs

sum.each do |min|
  answer = (min - 753).abs if answer >= (min - 753).abs
end

puts answer

Measured memory_bytes: 1788
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>


int main(){
  long long int N, tmp1, tmp2;
  std::vector<long long int> X, L;

  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    X.push_back(tmp1);
    L.push_back(tmp2);
  }

  // solve problem
  std::vector<std::pair<long long int, long long int> > max_min;
  for(long long int i = 0; i < N; i++){
    max_min.push_back(std::make_pair(X[i]+L[i], X[i]-L[i]+1));
  }
  std::sort(max_min.begin(), max_min.end());

  long long int ans = 0;
  long long int tmp_max = -1e10;

  for(long long int i = 0; i < N; i++){
    if(max_min[i].second > tmp_max){
      ans++;
      tmp_max = max_min[i].first;
    }
  }

  std::cerr << "Answer:" << std::endl;
  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 3948
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	b = readline() |> split |> parseMap
	k = b[1]
	for i in 1:n-2
		k += min(b[i],b[i+1])
	end
	k += b[n-1]
	println(k)
end

main()

Measured memory_bytes: 110956
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
ll nCr(ll n, ll r){
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
  ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
  return ret;
}

int main(void){
  string s,t;cin>>s>>t;
  int ans = 0;
  rep(i,3){
    ans += s[i]==t[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t % mod;
    } else {
        return modpow(m, n - 1) * m % mod;
    }
}
long long power(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}

long long moddiv(long long a, long long b) { return (a * modpow(b, mod - 2)) % mod; }

const ll INF = 1LL << 60;

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}

ll nCkmod(ll n, ll k) {
    ll denomi = 1;
    for (int i = n; i > n - k; i--) {
        denomi *= i;
        denomi %= mod;
    }
    ll numera = 1;
    REP(i, k) {
        numera *= (i + 1);
        numera %= mod;
    }
    return moddiv(denomi, numera);
}
vector<vector<ll>> graph;
vector<ll> as;
map<P, ll> number;
ll n;
ll memo[3001][3001];
ll func(ll first, ll length) {
    if (length == 0) {
        return 0;
    }
    if (memo[first][length] != INF) {
        return memo[first][length];
    }
    ll a, b;
    a = func(first, length - 1);
    b = func(first + 1, length - 1);
    memo[first][length] = max(-a + as[length - 1 + first], -b + as[first]);
    return memo[first][length];
}
int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i, 1, n + 1) { ans += i * (((n / i) * (n / i + 1) / 2)); }
    cout << ans << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
typedef long long ll;
const ll mod=1000000007;
const ll inf=2147483647;
const int N=200005;
const int M=3000005;
int head[N],to[M],nxt[M];
int c[N],pos[N],cc[N],cnt;
ll w[N],fac[N],divide[N],minn[N];
bool vis[N];
ll pow(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1)ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
ll cal(ll n,ll k){
    return(((fac[n]*divide[n-k])%mod)*divide[k])%mod;
}
void dfs(int x){
    vis[x]=true;
    for(int i=head[x];i;i=nxt[i])if(!vis[to[i]])dfs(to[i]);
}
void add(int u,int v){
    to[++cnt]=v;
    nxt[cnt]=head[u];
    head[u]=cnt;
}
int n,i,a,b;
ll x,y,min1,min2,tot,ans;
int main(){
    scanf("%d %lld %lld",&n,&x,&y);
    fac[0]=1;
    for(i=1;i<=n;i++){
        scanf("%d %lld",&c[i],&w[i]);
        fac[i]=(i*fac[i-1])%mod;
        minn[i]=inf;
    }
    divide[n]=pow(fac[n],mod-2);
    for(i=n;i>0;i--)divide[i-1]=(i*divide[i])%mod;
    for(i=1;i<=n;i++){
        if(w[i]<minn[c[i]]){
            minn[c[i]]=w[i];
            pos[c[i]]=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i!=pos[c[i]]&&w[i]+minn[c[i]]<=x){
            add(i,pos[c[i]]);
            add(pos[c[i]],i);
        }
    }
    min1=min2=inf;
    for(i=1;i<=n;i++){
        if(w[i]<min1){
            min1=w[i];
            a=i;
        }
    }
    for(i=1;i<=n;i++){
        if(w[i]<=min2&&c[i]!=c[a]){
            min2=w[i];
            b=i;
        }
    }
    for(i=1;i<=n;i++){
        if(i==a)continue;
        if(c[i]!=c[a]&&w[i]+w[a]<=y){
            add(i,a);
            add(a,i);
        }
        if(b&&c[i]!=c[b]&&w[i]+w[b]<=y){
            add(i,b);
            add(b,i);
        }
    }
    dfs(a);
    tot=0;
    for(i=1;i<=n;i++){
        if(vis[i]){
            tot++;
            cc[c[i]]++;
        }
    }
    ans=1;
    for(i=1;i<=n;i++){
        if(cc[i]){
            ans=(ans*cal(tot,cc[i]))%mod;
            tot-=cc[i];
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 18944
MOD = 10**9 + 7
H, W = map(int, input().split())
grid = [input() for _ in range(H)]
dp = [[0]*(W) for _ in range(H)]
dp[0][0] = 1
for i in range(H):
    for k in range(W):
        if i+1 < H and grid[i+1][k] != '#':
            dp[i+1][k] += dp[i][k]
        if k+1 < W and grid[i][k+1] != '#':
            dp[i][k+1] += dp[i][k]
        dp[i][k] %= MOD
print(dp[H-1][W-1]%MOD)

Measured memory_bytes: 43856
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
#import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
#from collections import deque
#from collections import defaultdict
# from collections import Counter
#from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	
	ans=":("
	
	for i in range(50000):
		if (i*1.08)//1==n:
			ans=i
	
	print(ans)
	
	
	
	
if __name__ == "__main__":
		main()


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

using namespace std;
int main(){
    int a,b,c,t7=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a==7) t7++;
    if(b==7) t7++;
    if(c==7) t7++;
    if(t7==1) printf("YES");
    else printf("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using ull = unsigned long long;
//#define int ll
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<V<T>>;
#define fi first
#define se second
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(ll i = (ll)(b)-1;i >= a;--i)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1), EPS = 1e-10;
const ll MOD = 1e9+7;
template<class T> istream& operator>>(istream &is,vector<T> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> istream& operator>>(istream &is,vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i) is >> st[i];
  return is;
}
template<class T> ostream& operator<<(ostream &os, const vector<T> &st){
  for(size_t i=0;i<st.size();++i){
    if(i==st.size()-1) os << st[i];
    else os << st[i] << " ";
  }
  return os;
}
template<class T> ostream& operator<<(ostream &os, const vector<vector<T>> &st){
  for(size_t i=0;i<st.size();++i){
    os << st[i];
    if(i!=st.size()-1) os << endl;
  }
  return os;
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,l;
  cin >> n >> l;
  int sum = 0;
  REP(i,n){
    sum += l+i;
  }
  int mn = INT_MAX;
  int id = -1;
  REP(i,n){
    if(abs(sum-sum-l-i)<mn){
      mn = abs(sum-sum-l-i);
      id = i;
    }
  }
  cout << sum-l-id << endl;
}


Measured memory_bytes: 256
# ABC138D - Ki
from collections import deque


def main():
    N, Q, *X = map(int, open(0).read().split())
    AB, PX = X[: 2 * (N - 1)], X[2 * (N - 1) :]

    tree, cnt = [[] for _ in range(N + 1)], [0] * (N + 1)
    for a, b in zip(*[iter(AB)] * 2):
        tree[a].append(b), tree[b].append(a)
    for p, x in zip(*[iter(PX)] * 2):
        cnt[p] += x

    queue = deque([1])
    is_searched = [False] * (N + 1)
    is_searched[1] = True
    while queue:
        u = queue.popleft()
        cur_cnt = cnt[u]
        is_searched[u] = True
        for v in tree[u]:
            if is_searched[v]:
                continue
            cnt[v] += cur_cnt
            queue.append(v)

    print(" ".join(map(str, cnt[1:])))


if __name__ == "__main__":
    main()


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


int main(){
    string S;
    cin >> S;
    int N = (int)S.size();
    bool checkS = true;
    bool checkR = true;
    int i=0;
    int j=0;
    while(checkR){
        if(S.at(j)!=S.at(N-1-j)){
            cout << "No" << endl;
            checkS = false;
            break;
        }
        j++;
        if(j==N-1-j){
            checkR = false;
        }
    }
    
    while(checkS){
        if(i+1==(N-1)/2){
            cout << "Yes" << endl;
            break;
        }
        if(S.at(i)!=S.at(((N-1)/2-1)-i)){
            cout << "No" << endl;
            break;
        }
        if(S.at((N+3)/2-1+i)!=S.at(N-1-i)){
            cout << "No" << endl;
            break;
        }
        if(i+2==(N-1)/2){
            cout << "Yes" << endl;
            break;
        }
        i++;
        
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> p;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define srep(i, from, to) for(int i = from; i < (int)(to); i++)
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
template <class T> bool chmax(T &a, const T &b) {
  if(a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if(b < a) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(m);
  rep(i, m) cin >> a[i];

  int ansn = 0;
  for(int i = x; i <= n; i++) {
    rep(j, m) {
      if(i == a[j]) ansn++;
    }
  }

  int ans0 = 0;
  for(int i = x; i >= 0; i--) {
    rep(j, m) {
      if(i == a[j]) ans0++;
    }
  }
  int ans = min(ansn, ans0);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n, k, q = gets.chomp.split(" ").map(&:to_i);

ps = Array.new(n, k - q)
q.times do 
  a = gets.chomp.to_i
  ps[a-1] += 1
end

ps.each do |p|
  if p > 0
          puts "Yes"
  else
          puts "No"
  end
end

Measured memory_bytes: 3196
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long xsum = 0;
		long ysum = 0;
		long p = 1000000007;

		for(int i=0; i<n; i++){
			xsum += sc.nextLong() * (2*i - n + 1);
		}
		xsum %= p;

		for(int i=0; i<m; i++){
			ysum += sc.nextLong() * (2*i - m + 1);
		}
		ysum %= p;

		System.out.println((xsum*ysum)%p);
	}
}

Measured memory_bytes: 65028
local DBG = false
function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

function dbgpr_t(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in ipairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

function dbgpr_tp(tbl)
    if DBG then
        dbgpr(tbl)
        io.write("[dbg]")
        for i,v in pairs(tbl) do
            io.write(i)
            io.write(":")
            io.write(tostring(v))
            io.write(" ")
        end
        print("")
    end
end

------------------------------------
local MOD = 1000000007
local AA, ZZ = 97, 122
local alpha_count = {}
for i=AA,ZZ,1 do
    alpha_count[i] = 0
end
local N = io.read("n", "l")
local S = io.read("l")
local s_tbl = {string.byte(S, 1, #S)}
for _,v in ipairs(s_tbl) do
    alpha_count[v] = alpha_count[v] + 1
end
dbgpr_tp(alpha_count)

local answer = 1
for i=AA,ZZ,1 do
    local place_cnt = alpha_count[i]
    if place_cnt == 0 then
    elseif place_cnt == 1 then
        answer = (answer * 2) % MOD
    else
        -- place_cnt >= 2
        local alphai_combs = 1 + place_cnt
        answer = (answer * alphai_combs) % MOD
    end
end
answer = (answer - 1) % MOD
print(answer)

Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
 
int main(){
    int n,a,b;
 
    while(cin >> n ,n){
	vector<int> v[n];
	for(int i = 0 ; i < n ; i++){
	    cin >> a;
	    for(int j = 0 ; j < a ; j++){
		cin >> b;
		v[i].push_back(b);
	    }
	}
	int check[101] = {0};
	int cnt[101] = {0};
	int ans;
 
	cin >> a;
	for(int i = 0 ; i < a ; i++){
	    cin >> check[i];
	}
	int t = 0;
	while(true){
	    if(t == n) break;
       
	    for(int i = 0 ; i < a ; i++){
		vector<int>::iterator pos;
		pos = find(v[t].begin(),v[t].end(),check[i]);
		if(pos == v[t].end()){
		    break;
		}
		else{
		    cnt[t]++;
		}
	    }
	    t++; 
	}
 
	int cnt1 = 0;
	for(int i = 0 ; i < n ; i++){
	    if(cnt[i] == a){
		ans = i+1;
		cnt1++;
	    }
 
	}
	if(cnt1 == 1) cout << ans << endl;
	else cout << "-1" << endl;   
    }
    return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
 
 
 
ll gcd(ll a,ll b){
    if(a==0){
        return b;
    }                     
    return gcd(b%a,a);
}
ll power(ll x,ll y){            
    ll res=1;
    while(y>0){
        if(y%2==1){
            res=(res*x);
        }
        x=(x*x);
        y=y/2;
    }
    return res;
}
 


int main(){
 
 /*#ifndef ONLINE_JUDGE
    
   freopen("input.txt", "r", stdin);
   
   freopen("output.txt", "w", stdout);
   #endif*/
  ll n,i,j;
  sfl(n);
  ll a[n];
  f(i,0,n)sfl(a[i]);

  sort(a,a+n);
ll x,y,z,ans=0;
  f(i,0,n){
   f(j,i+1,n){
    x=lower_bound(a,a+n,a[i]+a[j])-a;
    x-=2;
    y=upper_bound(a,a+n,a[j]-a[i])-a;
    if(a[i]<=(a[j]-a[i]))y-=1;

  ans+=x-y;

  //cout<<a[i]<<" "<<a[j]<<" "<<x<<" "<<y<<"\n";




   }

  }
  cout<<ans/3;;












   return 0;
 }

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    int a,b; cin >> a >> b;
    for(int i = 1; i < 100000; ++i) {
        if(i*8/100 == a && i/10 == b) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';


    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}


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

using namespace std;

int main() {
    
    vector<int> a(5, 0);
    int k, count=0;

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

    cin >> k;

    if (a[4] - a[0] > k) {
        cout << ":(";
   }
    else {
        cout << "Yay!";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  while(n){
    ans++;
    n/=k;
  }
  COUT(ans);
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 507

int main (void) {
  int n, m, k, l, r, p, q, a[N][N], b[N][N];

  scanf("%d %d %d", &n, &m, &k);

  for (int i = 0; i < m; i++)  {
    scanf("%d %d", &l, &r);
    a[l][r]++;
  }

  for (int i = 0; i < N; i++)
    b[i][0] = b[0][i] = 0;

  for (int i = 1; i < N; i++)
    for (int j = 1; j < N; j++)
      b[i][j] = b[i-1][j] + b[i][j-1] - b[i-1][j-1] + a[i][j];
  
  for (int i = 0; i < k; i++) {
    scanf("%d %d", &p, &q);
    printf("%d\n", b[q][q] - b[p-1][q] - b[q][p-1] + b[p-1][p-1]);
  }

  return 0;
}

Measured memory_bytes: 2816
n, m = map(int, input().split())
lst = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0

for i in range(2**n):
    bulb = [0] * m
    for j in range(n):
        if i>>j & 1:
            for k in range(m):
                if j+1 in lst[k][1:]:
                    bulb[k] += 1

    all_lightup = True
    for l in range(m):
        if bulb[l] % 2 != p[l]:
          all_lightup = False
          break
    if all_lightup:
        ans += 1

print (ans)




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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 108 A / Link: http://abc108.contest.atcoder.jp/tasks/abc108_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL ans = 0LL;

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

	LL N; 
	
	cin >> N;
	
	ans = (N / 2)*((N + 1) / 2);
	
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    string S; cin >> S;
    int cnt = 0;
    REP(i, SZ(S)) if(S[i] == 'o') cnt++;
    cnt += 15 - SZ(S);
    Ans(cnt >= 8, "YES", "NO");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <math.h>

int main() {

    char a[105], b[105], c[105];

    int len_a, len_b, len_c;

    scanf("%s %s %s", a, b, c);

    len_a = strlen(a);

    len_b = strlen(b);

    //len_c = strlen(c);

    if ((a[len_a - 1] == b[0]) && b[len_b - 1] == c[0])

        puts("YES");

    else

        puts("NO");

    return 0;

}

Measured memory_bytes: 128
from collections import defaultdict
n, c = map(int, input().split())
org = defaultdict(list)
for _ in range(n):
    s, t, ch = map(int, input().split())
    org[ch].append((s, t))


all = []
for ch in range(1, c+1):
    org[ch].sort()
    m = len(org[ch])
    for i in range(m):
        s, t = org[ch][i]
        
        if i == 0:
            pre_s, pre_t = s, t
        else:
            if pre_t == s:
                pre_t = t
            else:
                all.append((2*pre_s-1, 2*pre_t))
                pre_s, pre_t = s, t
            
        if i == m-1:
            all.append((2*pre_s-1, 2*pre_t))


time = [0]*(2*10**5+2)
for l, r in all:
    time[l] += 1
    time[r+1] -= 1
for i in range(2*10**5+1):
    time[i+1] += time[i]

print(max(time))


Measured memory_bytes: 66520
import kotlin.math.floor
import kotlin.math.min

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val (a, b, n) = readLongList()
    val f = { x: Long ->
        floor(a * x.toDouble() / b).toLong() - (a * floor(x.toDouble() / b)).toLong()
    }
    println(f(min(b-1, n)))
}

Measured memory_bytes: 36392
#include <stdio.h>

int main(void)
{
	int i;
	long long tak,nak,hik,K,Un=10000000000000000000;
	scanf("%lld %lld %lld %lld",&tak,&nak,&hik,&K);
	if(tak-nak>=Un&&Un-(tak-nak)<=0){
		if(K%2==0){
			printf("%lld\n",tak-nak);
		}else if(K%2==1){
			printf("%lld\n",nak-tak);
		}
	}else{
		printf("Unfair\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;

#define PI 3.14159265358979323846264338327950L

int res;

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

    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    res = -1;
    int cnt = 0;
    int tmp = A[0];
    while (cnt < N + 1)
    {
        cnt++;
        if (tmp == 2)
        {
            res = cnt;
            break;
        }
        tmp = A[tmp-1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3716
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let a:i32 = read();
    let b:i32 = read();
    let c:i32 = read();
    println!("{} {} {}",c,a,b);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  int c=0;
  
  for (int i = A; i < B+1; i++) {
    if (i/10000 == i%10 && i%10000/1000 == i%100/10) {
	    c++;
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	
	int n;
	cin >> n;
	vector<string> s;
	string a;
	FOR(i,n){
		cin >> a;
		sort(all(a));
		s.push_back(a);
	}

	sort(all(s));

	ll cnt=1;
	ll ans=0;
	FOR(i,n-1){
		if(s[i]==s[i+1]){
			cnt++;
		}else{
			ans+=cnt*(cnt-1)/2;
			cnt=1;
		}
	}
	ans+=cnt*(cnt-1)/2;
	cout << ans << endl;
}

Measured memory_bytes: 5748
n = int(input())
b = list(map(int, input().split()))

a =[0]*n
a[0] = b[0]

if n == 2:
    a[1] =b[0]
    print(sum(a))

else:

    for i in range(n-2):
        if b[i+1] >= b[i]:
            a[i+1] = b[i]
            a[i+2] = b[i+1]

        else:
            a[i+1] = b[i+1]
            a[i+2] = b[i+1]

    print(sum(a))


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

const string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
    string s;
    int k=0;
    int count[27]={0};
    cin >> s;
    for (int i=0;i<4;i++){
        for (int j=0;j<26;j++){
            if(s[i]==alpha[j]){
                count[j]++;
            }
        }
    }
    for(int i=0;i<27;i++){
        if(count[i]==2){
            k++;
        }else if(count[i]!=0){
            cout <<"No";
            return 0;
        }
    }
    if(k==2){
        cout << "Yes";
    }else{
        cout <<"No";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,Y;
  int x,y,z;
  cin>>n>>Y;
  int k=0;
  for(int i=0;i<=n;i++)
  {
    int t=Y-(9000*i)-(1000*n);
    if(t>=0 && t%4000==0 && (n-i-(t/4000))>=0)
    {
      x=i;
      y=t/4000;
      z=n-i-y;
      k=1;
      break;
    }
  }
  if(k)cout<<x<<' '<<y<<' '<<z<<endl;
  else cout<<-1<<' '<<-1<<' '<<-1<<endl;
  return 0;
}
   

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> a;
    int tmp;
    for(int i=0;i<n;i++){
        cin >> tmp;
        a.push(tmp);
    }

    for(int i=0;i<m;i++){
        tmp = a.top();
        a.pop();
        tmp /= 2;
        a.push(tmp);
    }

    long long sum = 0;
    for(int i=0;i<n;i++){
        tmp = a.top();
        a.pop();
        sum += tmp;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        while(true){
            
            int a = sc.nextInt();
            String op = sc.next();
            int b = sc.nextInt();
            
            if(op.equals("?"))break;
            
            int ans = 0;
            
            switch(op){
            case "+":
                ans = a+b;
                break;
            case "-":
                ans = a-b;
                break;
            case "*":
                ans = a*b;
                break;
            case "/":
                ans = a/b;
                break;
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 26364
def main():
    S = list(input())
    rev_S = S[::-1]

    split = len(S) // 2

    S = S[:split]
    rev_S = rev_S[:split]

    count = 0

    for i in range(len(S)):
        if S[i] != rev_S[i]:
            count += 1

    print(count)

if __name__ == "__main__":
    main()


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

int main() {
  int d;
  cin >> d;
  vector<int> c(26), last(26);
  for (int i = 0; i < 26; i++) {
    cin >> c.at(i);
  }
  vector s(d, vector(26, 0));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  int v = 0;
  for (int i = 0; i < d; i++) {
    int dmax = -1e9, tmax = 0;
    for (int t = 0; t < 26; t++) {
      int d = 0;
      last.at(t) = i + 1;
      d += s.at(i).at(t);
      for (int j = 0; j < 26; j++) {
        d -= c.at(j) * (i + 1 - last.at(j));
      }
      if (d > dmax) {
        dmax = d;
        tmax = t;
      }
    }
    cout << tmax + 1 << endl;
  }
}


Measured memory_bytes: 3680
V, E = map(int, input().split())
INF = 10**20
cost = [[INF if x != y else 0 for x in range(V)] for y in range(V)]

for i in range(E) :
    a, b, c = map(int, input().split())
    cost[a][b] = c
    
for k in range(V) :
    for i in range(V) :
        for j in range(V) :
            if cost[i][k] != INF and cost[k][j] != INF :
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j])
            
negative_cycle = False 
for i in range(V) :
    if cost[i][i] < 0 :
        negative_cycle = True
        
if negative_cycle == True :
    print("NEGATIVE CYCLE")
else :
    for i in cost :
        i_str = list(map(str, i))
        print(" ".join([x if x != str(INF) else "INF" for x in i_str]))


Measured memory_bytes: 6008
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    s = [input() for _ in range(N)]
    
    ans = 0
    cnt_a, cnt_b, cnt_ab = 0, 0, 0
    for si in s:
        ans += si.count('AB')
        if si[-1] == 'A' and si[0] == 'B':
            cnt_ab += 1
        elif si[-1] == 'A':
            cnt_a += 1
        elif si[0] == 'B':
            cnt_b += 1
    
    if cnt_ab == 0:
        ans += min(cnt_a, cnt_b)
    else:
        if 0 < cnt_a + cnt_b:
            ans += cnt_ab + min(cnt_a, cnt_b)
        else:
            ans += cnt_ab - 1
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int MOD = 1e9+7;
int dsu[200005];
int getParent(int num){
    if(dsu[num]==num)return num;
    return dsu[num]=getParent(dsu[num]);
}
void makeParent(int a , int b){
    a =getParent(a);
    b = getParent(b );
    dsu[a]=b;
}
int main() {
    IO;
    int n , m ;
    cin>>n>>m ;
    for(int i = 0 ; i<= n ;i ++){
        dsu[i]=i;
    }
    for(int i = 0 ; i<m ; i++){
        int a , b ;
        cin>>a>>b;
        makeParent(a,b);
    }
    map<int, int> dd ;
    int ans = 0;
    for(int i = 0 ; i<=n ; i++){
        dd[getParent(i)]++;
        ans = max(ans,  dd[getParent(i)]);
    }
    cout<<ans<<endl;
}

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

int main(){
	int p[5];
	while(1){
	int t[3]={0};
		for(int i=0;i<5;i++){
			cin >> p[i];
			if(!p[i])return(0);
			t[p[i]-1]++;
		}
		if(t[0]&&t[1]&&!t[2])
			for(int i=0;i<5;i++)
				if(p[i]==1)p[i]=1;
				else p[i]=2;
		else if(t[0]&&!t[1]&&t[2])
			for(int i=0;i<5;i++)
				if(p[i]==1)p[i]=2;
				else p[i]=1;
		else if(!t[0]&&t[1]&&t[2])
			for(int i=0;i<5;i++)
				if(p[i]==2)p[i]=1;
				else p[i]=2;
		else
			for(int i=0;i<5;i++)p[i]=3;
		
		for(int i=0;i<5;i++)cout<<p[i]<<endl;
	}
}

Measured memory_bytes: 0
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<bitset>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
#define MAXN 1005
int rd()
{
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
int n,l,x;
int main()
{
	n=rd(),x=rd();
	int now=0,cnt=1;
	for(int i=1;i<=n;i++)
	{
		l=rd();
		now+=l;
		if(now>x) break;
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int g=0;
		int ans=0;
		for(int i=0; i<s.length(); i++){
			if(s.charAt(i)=='g' && g>0){
				g--;
				ans++;
			}else if(s.charAt(i)=='p'){
				if(g>0){
					g--;
				}else{
					ans--;
					g++;
				}
			}else{
				g++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 25316
def gcd(x, y):
    a = max(x, y)
    b = min(x, y)
    if b == 0:
        return a
    remainder = a % b
    if remainder == 0:
        return b
    return gcd(b, remainder)


N = int(input())
integers = [int(x) for x in input().split()]

left = [0]
right = [0]

for i in range(N):
    left.append(gcd(left[-1], integers[i]))
    right.append(gcd(right[-1], integers[-i-1]))

# right.reverse()

lr = []
for i in range(N):
    lr.append(gcd(left[i], right[-i-2]))

print(max(lr))


Measured memory_bytes: 14436
#include<iostream>
#include<vector>
#include <string>

using namespace std;

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

	int Sum = 0;

	while (N >= 500) {

		N = N - 500;
		Sum += 1000;

	}

	while (N >= 5) {

		N = N - 5;
		Sum += 5;

	}

	cout << Sum;

}

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

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int a = sc.nextInt();
    int b = sc.nextInt();

    int res = 0;
    int count = 1;
    while (count < b) {
      res++;
      count += a - 1;
    }
    os.println(res);
  }
}

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

class TETORIS {
public:
    int N;
    vector<vector<int> > bd;
    TETORIS() : N(0) {}
    void put(int len, int pos) {
        int k;
        for (k=bd.size()-1; k>=0; --k) {
            for (int i=0; i<len; ++i) {
                if (bd[k][pos+i]) goto brk;
            }
        } brk:;
        ++k;
        if ((int)bd.size() == k) bd.push_back(vector<int>(5, 0));
        for (int i=0; i<len; ++i) {
            bd[k][pos+i] = 1;
        }
        N += len;
    }
    void update() {
        for (int i=bd.size()-1; i>=0; --i) {
            if (bd[i][0] && bd[i][1] && bd[i][2] && bd[i][3] && bd[i][4]) {
                bd.erase(bd.begin()+i);
                N -= 5;
            }
        }
    }
};

int main() {
    int n;
    while (cin >> n, n) {
        TETORIS tet;
        int d, p, q;
        for (int i=0; i<n; ++i) {
            cin >> d >> p >> q;
            --q;
            if (d == 1) {
                tet.put(p, q);
                tet.update();
            } else {
                for (int j=0; j<p; ++j) tet.put(1, q);
                tet.update();
            }
        }
        cout << tet.N << endl;
    }
    return 0;
}

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	LL a[n+1],b[n];
	for(int i=0;i<n+1;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	LL ans = 0;
	// keisan
	for(int i=0;i<n;i++){
		if(b[i] < a[i]){
			ans += b[i];
		}else{
			ans += a[i];
			b[i] -= a[i];
			if(b[i] > 0){
				if(b[i] < a[i+1]){
					a[i+1] -= b[i];
					ans += b[i];
				}else{
					ans += a[i+1];
					a[i+1] = 0;
				}
			}
		}
	}
	// syutsuryoku
	cout << ans;
}

Measured memory_bytes: 5116
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  9 16:34:45 2018

@author: Narita
"""
import collections
import itertools

def main():
    N = int(input())
    S = []
    for i in range(N):
        S.append(input())
#    print(S)
    
    result = 0
    match_str = "MARCH"
    combi_str = list(itertools.combinations(list(match_str), 3))
#    print(combi_str)
    initial_char = []
    for i in range(N):
#        print(S[i][0])
#        print(S[i][0] in match_str)
        if(S[i][0] in match_str):
            initial_char.append(S[i][0])
#    print(initial_char)
    c = collections.Counter(initial_char)
#    print(c)
    for li in combi_str:
        result += c[li[0]] * c[li[1]] * c[li[2]]
    print(result)
    
if __name__=="__main__":
    main()


Measured memory_bytes: 10880
#include<iostream>
#include<math.h>
using namespace std;
int main(){

    int n;
    int d;
    cin>>n>>d;
    int cnt=0;
    int x,y;
    double distance;
    for(int i=0;i<n;i++){

        cin>>x>>y;
        distance=sqrt(pow(x,2)+pow(y,2));
        if(distance<=d)cnt++;
        //cout<<distance<<endl;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3648
import bisect
n=int(input()) 
L=list(map(int, input().split())) 
L.sort()

count = 0        
for i in range(n-2):
  a = L[i]
  for k in range(i+1,n-1):
    b = L[k]

    count += bisect.bisect_left(L, a + b) - k -1
print(count)

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

int main() {
    long long A, B, C;
    cin >> A >> B >> C;
    if (A % 2 && B % 2 && C % 2) {
        long long ans = 2e18;
        ans = min(ans, A * B);
        ans = min(ans, B * C);
        ans = min(ans, C * A);
        cout << ans << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as BS
main=do
 [n,k]<-map read.words<$>getLine
 ab<-replicateM n (map(read.BS.unpack).BS.words<$>BS.getLine)
 print(f (sort ab) k)
  where f ([a,b]:ab) k = if b<k then (f ab (k-b)) else a

Measured memory_bytes: 68988
n = gets.to_i
k = gets.to_i

arr = gets.split(' ').map!(&:to_i)

ans = 0
arr.each do |e|
  dis_a = e - 0
  dis_b = (e - k).abs

  if dis_a > dis_b
    ans += dis_b * 2
  else
    ans += dis_a * 2
  end
end

puts ans


Measured memory_bytes: 1788
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn filter(a: &Vec<u64>, m: &u64) {
    let mut sum = 0;
    let mut result = 0;
    for item in a {
        sum = sum + item;
    }

    let judge: f64 = sum as f64 / 4.0 / *m as f64;

    for item in a {
        if (*item as f64) >= judge {
            result = result + 1;
        }
    }

    if result < *m {
        println!("No");
    } else {
        println!("Yes");
    }
}

fn main() {
    let n: u32 = read();
    let m: u64 = read();
    let a: Vec<u64> = (0..n).map(|_| read()).collect();
    filter(&a, &m);
}


Measured memory_bytes: 4352
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key = lambda x:x[0])
ans = 0
for a, b in ab:
    ans += a * min(b, m)
    m -= b
    if m <= 0:
        break
print(ans)

Measured memory_bytes: 28404
N = int(input())
S = list(input())

cnt_right = S[1:].count('E')
cnt_left = 0
ans = cnt_right + cnt_left

for ichi in range(len(S)-1):
    if S[ichi] == 'W':
        cnt_left += 1
    if S[ichi+1] == 'E':
        cnt_right -= 1
    ans = min(ans, cnt_right + cnt_left)
    
print(ans)

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

int main(){
  int n;
  cin >> n;
  
  vector<double> v(n);
  for(int i=0;i<v.size();i++){
  	cin >> v.at(i);
  }
  
  while(v.size()>1){
    sort(v.begin(), v.end(), std::greater<double>());
    double v1 = v.back();
    v.pop_back();
    double v2 = v.back();
    v.pop_back();
    v.push_back((v1+v2)/2);
  }
  cout << v.at(0);
  return 0;
}

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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        while (true){
            final int times = Integer.parseInt(br.readLine());
            if (times == 0) { break; }
            
            Map<String, Long> data = new LinkedHashMap<>();
            for (int i=1; i <= times; i++) {
                String[] e = br.readLine().split(" ");
                data.merge(e[0], Long.parseLong(e[1]) * Long.parseLong(e[2]), Long::sum);
            }
            
            long count = data.entrySet().stream()
                .filter(e -> e.getValue() >= 1_000_000)
                .peek(e -> System.out.println(e.getKey()))
                .count();
            if (count == 0) { System.out.println("NA"); }
        }
    }
}

Measured memory_bytes: 32148