akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
A = [int(x) for x in input().split()]
B_C = [list(map(int, input().split())) for _ in range(M)]
A.sort()
B_C.sort(key=lambda x: x[1], reverse=True)
cur = 0
for i, a in enumerate(A):
    if cur >= M or a > B_C[cur][1]:
        break
    A[i] = B_C[cur][1]
    B_C[cur][0] -= 1
    if B_C[cur][0] <= 0:
        cur += 1
print(sum(A))

Measured memory_bytes: 32888
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    int diff = b - a;
    if (diff <= 0)
        cout << "delicious";
    else if (diff > x)
        cout << "dangerous";
    else if (diff <= x)
        cout << "safe";
    return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pipipii = pair<ll, pair<int, pii>>;

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'000'000'001;
constexpr ll LLINF = 4'000'000'000'000'000'001;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> b(n);
    for(int i = 0; i < n; ++i){
        cin >> b[i];
    }
    vector<int> ans(n);
    for(int i = 0; i < n; ++i){
        for(int j = (int)b.size() - 1; j >= 0; --j){
            if(j+1 == b[j]){
                ans[i] = j+1;
                b.erase(b.begin() + j);
                goto SUCCESS;
            }
        }
        cout << "-1\n";
        return 0;
        SUCCESS:;
    }
    for(int i = n-1; i >= 0; --i){
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
typedef  pair<int, int> iPair; 
//#define mod 1000000007
#define pb push_back
typedef long long ll;
typedef long double ld;
#define FOR(i,n) for(i=0;i<n;i++)
#define FORE(i,n) for(i=0;i<=n;i++)
 
 
ll gcd(ll a , ll b)
{
   if(b==0) return a;
   a%=b;
   return gcd(b,a);
   
}
    
ll maxl(ll a,ll b){
    if(a>b)return a;
    return b;
}
 
ll minl(ll a,ll b){
    if(a>b)return b;
    return a;
}
 
ll mod = 998244353;
 
ll mulmod(ll a, ll b,ll c){ 
    ll res = 0; 
    a = a % c; 
    while (b > 0){ 
        if (b % 2 == 1){ 
            res = (res + a) % c;
        }
        a = (a * 2) % c; 
        b /= 2; 
    } 
    return res % c; 
}
 
int binarySearch(int arr[], int l, int r, int x) 
{ 
    if (r >= l) { 
        int mid = l + (r - l) / 2; 
        if (arr[mid] == x) 
            return mid; 
        if (arr[mid] > x) 
            return binarySearch(arr, l, mid - 1, x); 
        return binarySearch(arr, mid + 1, r, x); 
    } 
    return -1; 
} 
 
int a[100005];
int tree[200005];
 
void build(int st,int low,int high){
    if(low==high){
        tree[st] = a[high]%2;
        return;
    }
    int mid = low+(high-low)/2;
    build(2*st,low,mid);
    build(2*st+1,mid+1,high);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
void update(int st,int start,int end,int ind,int val){
    if(start==end){
        tree[st] = val%2;
        return;
    }
    int mid = start+(end-start)/2;
    if(ind<=mid){
        update(2*st,start,mid,ind,val);
    }
    else update(2*st+1,mid+1,end,ind,val);
    tree[st] = tree[2*st]+tree[2*st+1];
}
 
int query(int st,int start,int end,int low,int high){
    if(start>high || end<low)return 0;
    int mid = start + (end-start)/2;
    if(start==low && end==high){
        return tree[st];
    }
    if(low>mid)return query(2*st+1,mid+1,end,low,high);
    if(high<=mid)return query(2*st,start,mid,low,high);
    return query(2*st,start,mid,low,mid)+query(2*st+1,mid+1,end,mid+1,high);
}

int main()
{
        ios_base::sync_with_stdio(false);
        ll n;
        cin >> n;
        cout << n*n*n << endl;
        return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
  int iLen;
  string s1, s2, s3;
  cin >> iLen;
  cin >> s1;
  cin >> s2;
  cin >> s3;

  if(s1 == s2 && s2 == s3 && s3 == s1)
  {
    cout << "0" << endl;
    return 0;
  }

  int i = 0;
  int iHikaku1 = 0;
  int iHikaku2 = 0;
  int iHikaku3 = 0;
  int iC = 0;
  for(i=0;i<iLen;i++)
  {
    iHikaku1 = 0;
    iHikaku2 = 0;
    iHikaku3 = 0;

    if(s1.at(i) != s2.at(i))
    {
      iHikaku1 = 1;
    }
    if(s2.at(i) != s3.at(i))
    {
      iHikaku2 = 1;
    }
    if(s3.at(i) != s1.at(i))
    {
      iHikaku3 = 1;
    }

    if(iHikaku1 == 1 && iHikaku2 == 1 && iHikaku3 == 1)
    {
      // 全部異なる、1と同じにする
      s2.at(i) == s1.at(i);
      iC++;
      s3.at(i) == s1.at(i);
      iC++;
    }
    else if(iHikaku1 == 1 && iHikaku2 == 1 && iHikaku3 == 0)
    {
      // 1≠2、2≠3、3＝1、2だけ異なる
      s2.at(i) == s1.at(i);
      iC++;
    }
    else if(iHikaku1 == 1 && iHikaku2 == 0 && iHikaku3 == 1)
    {
      // 1≠2、2＝3、3≠1、1だけ異なる
      s1.at(i) == s2.at(i);
      iC++;
    }
    else if(iHikaku1 == 0 && iHikaku2 == 1 && iHikaku3 == 1)
    {
      // 1＝2、2≠3、3≠1、3だけ異なる
      s3.at(i) == s1.at(i);
      iC++;
    }
  }

  cout << iC << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int i,n,count=0,j;
  char a[100];
  scanf("%s",a);
  n=strlen(a);
  for(i=0;i<n;i++){
    if(a[i]!=a[n-i-1]) count=1;
  }
  for(i=0,j=(n-1)/2;i<(n-1)/2;i++,j--){
    if(a[i]!=a[j-1]) count=1;
  }
  for(i=(n+3)/2,j=n-1;i<n;j--,i++){
    if(a[i]!=a[j-1]) count=1;
  }
 if(count==0) printf("Yes");
       else printf("No");
       return 0;
       }

Measured memory_bytes: 128
#include <deque>
#include <iostream>
#include <map>

using namespace std;

#define P (998244353)
#define ll long long int

inline int fast_pow(int x, int n, int mod) {
    long long signed res = 1;
    long long accumulation = x;
    for (int i = 0; n >> i > 0; ++ i) {
        if ((n >> i) % 2) {
            res *= accumulation;
            res %= mod;
        }
        accumulation *= accumulation;
        accumulation %= mod;
    }

    return res;
}

template<int MOD>
class Combination {
public:
    Combination(int n) {
        long long signed accumulation = 1;
        factorials.push_back(1);
        for (int i = 1; i <= n; ++ i) {
            accumulation *= i;
            accumulation %= MOD;
            factorials.push_back(accumulation);
        }

        int n_inv = fast_pow(factorials[n], MOD - 2, MOD);
        invs.push_back(n_inv);
        accumulation = n_inv;
        for (int i = n; i >= 2; --i) {
            accumulation *= i;
            accumulation %= MOD;
            invs.push_front(accumulation);
        }
        invs.push_front(1);
    }

    int calc(int n, int r) {
        long long signed res = 1ll * factorials[n] * invs[r] % MOD;
        return 1ll * res * invs[n - r] % MOD;
    }

    std::deque<int> factorials;
    std::deque<int> invs;
};

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

    Combination<P> comb(n);
    ll ans = 0;
    for (int i = 0; i <= k; ++i) {
        ans += (1ll * m * comb.calc(n - 1, i) % P) * fast_pow(m - 1, n - 1 - i, P);
        ans %= P;
    }
    cout << ans;

    return 0;
}


Measured memory_bytes: 5240
require 'set'
n = gets.to_i
w = gets.chomp
used = Set.new
used << w
ok = true
(n-1).times{
  u = gets.chomp
  if used.include? u
    ok = false
    break
  end
  if w[-1] != u[0]
    ok = false
    break
  end
  w = u
  used << u
}
puts ok ? :Yes : :No


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

#define int            long long int
#define float          long double
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define inf            1e18
#define set_pre(x,y)   fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
using namespace std;
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    int n;
    cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    vector<int>dp(n,INT_MAX);
    dp[0]=0;
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<=2;j++)
        {
            if(i>=j)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import sys
a = list(str(input()))
#print(a)


for i in range(1 << 3):
    op = ['+']*3
    #range 3 because we need to look at all the bits
    for j in range(3):
        if (i >> j)&1:
            #starting from the right
            op[j] = "-"
    op.append('')        
    res = ''
    
    for x,y in zip(a,op):
        res += x+y
        
    if eval(res) == 7:
        print(res+'=7')
        sys.exit()

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

long long solve( long long n, long long x){
  long long r = n % x;
  if( r == 0 ){
    return ( n / x ) * x * 2 - x;
  }
  return (n / x) * x * 2 + solve( x, n % x);
}

int main(){
  long long n, x;
  cin >> n >> x;
  cout << n + solve( n - x , x) << endl;
  return 0;
}


Measured memory_bytes: 256
#define max(a,b)a=a<b?b:a
int n;
long c,x[1<<17],v[1<<17];
main()
{
	scanf("%d%ld",&n,&c);
	long ans=0,L=0,R=0,Rmax=0;
	for(int i=0;i<n;i++)
	{
		scanf("%ld%d",x+i,v+i);
		L+=v[i];
	}
	ans=L-x[n-1];
	for(int i=n;i--;)
	{
		L-=v[i];
		R+=v[i];
		max(Rmax,R-(c-x[i]));
		max(ans,L-(i?x[i-1]*2:0)+Rmax);
	}
	long Lmax=0;
	for(int i=0;i<n;i++)
	{
		L+=v[i];
		R-=v[i];
		max(Lmax,L-x[i]);
		max(ans,R-(i!=n-1?(c-x[i+1])*2:0)+Lmax);
	}
	printf("%ld",ans);
}


Measured memory_bytes: 1792
#include <iostream>
#include <set>
using namespace std;
int main(){
	int n,m;
	while(cin>>n>>m){
		if(n==0&&m==0)break;
		multiset<int> t;
		t.insert(0);
		for(int i=0,a;i<n+m;++i){
			cin>>a;
			t.insert(a);
		}
		int maxd=0;
		multiset<int>::iterator it1=t.begin(),it2=t.begin();
		++it2;
		for(;it2!=t.end();){
			if(*it2-*it1>maxd)maxd=*it2-*it1;
			++it1;
			++it2;
		}
		cout<<maxd<<"\n";
	}
	return 0;
}

Measured memory_bytes: 1364
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		BigDecimal n = new BigDecimal(sc.next());
		BigDecimal k = new BigDecimal(sc.next());

		sc.close();

		BigDecimal a = n.divideToIntegralValue(k);
		BigDecimal b = a.multiply(k);
		BigDecimal c = n.subtract(b);

		BigDecimal d = c.subtract(k).abs();

		if(c.compareTo(d) < 0) {
			System.out.println(c);
		} else {
			System.out.println(d);
		}

	}

}


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

using namespace std;
const int MAXN = 200010;
int _w;

int n, m, a[MAXN], b[MAXN];
map<int,int> mp;

int main() {
	_w = scanf( "%d", &n );
	for( int i = 0; i < n; ++i ) {
		_w = scanf( "%d", a+i );
		++mp[a[i]];
	}
	_w = scanf( "%d", &m );
	for( int i = 0; i < m; ++i ) {
		_w = scanf( "%d", b+i );
		if( mp[b[i]] == 0 )
			return puts("NO"), 0;
		--mp[b[i]];
	}
	return puts("YES"), 0;
}


Measured memory_bytes: 11136
program main
  implicit none
  integer(8) :: n, k, i, m, res
  read (*, *) n, k
  m = 10 ** 9 + 7
  do i = 1, k
    if (n - k - i + 1 < 0) then
      res = 0
    else
      res = combi(k - 1, k - i, m) * combi(n - k + 1, n - k - i + 1, m)
      res = mod(res, m)
    end if
    write (*, "(i0)") res
  end do
  contains

  function combi(n, k, m)
    implicit none
    integer(8), intent(in) :: n, k, m
    integer(8) :: combi, numera, denomi
    numera = perm(n, k, m)
    denomi = mod(fact(k, m), m)
    combi = mod(numera * inv(denomi, m), m)
  end function combi

  function perm(n, k, m)
    integer(8), intent(in) :: n, k, m
    integer(8) :: i, perm
    perm = 1
    do i = n, n - k + 1, -1
      perm = mod(perm * i, m)
    end do
  end function perm

  function fact(n, m)
    implicit none
    integer(8), intent(in) :: n, m
    integer(8) :: i, fact
    fact = 1
    do i = 1, n
      fact = mod(fact * i, m)
    end do
  end function fact

  function inv(n, m)
    implicit none
    integer(8), intent(in) :: n, m
    integer(8) :: inv
    inv = pow(n, m - 2, m)
  end function inv

  recursive function pow(n, p, m) result(res)
    implicit none
    integer(8), intent(in) :: n, p, m
    integer(8) :: res
    if (p == 0) then
      res = 1
    else if (mod(p, 2_8) == 0) then
      res = mod(pow(n, p / 2, m) ** 2, m)
    else
      res = mod(pow(n, p - 1, m) * n, m)
    end if
  end function pow
end program main


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define LLI long long int
#define fst first
#define snd second
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#ifndef M_E
#define M_E 2.71828182845904523536
#endif
#ifdef DEBUG
#include <boost/core/demangle.hpp>
#define dump(x) cerr << "L" << __LINE__ << ": in " << __PRETTY_FUNCTION__ << " \e[32;1m" << boost::core::demangle(typeid(x).name()) << "\e[37m" << " " << (#x) << " = " << (x) << "\e[m" << endl;
#else
#define dump(x)
#endif
#define pln(x) cout << (x) << endl
#define gcd __gcd

using namespace std;
template <class T> constexpr T lcm(T m, T n){return m*n/gcd(m,n);}

template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T, typename U> istream& operator>>(istream &is, pair<T,U> &p){is >> p.first >> p.second; return is;}

template <typename Iter> ostream& out_container(ostream &os, Iter first, Iter last){
  os << "{"; auto itr = first; while(itr != last){if(itr != first) os << ","; os << *itr; ++itr;} os << "}"; return os;
}

template <typename T> ostream& operator<<(ostream &os, const vector<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const deque<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const set<T> &c){return out_container(os,ALL(c));}
template <typename T> ostream& operator<<(ostream &os, const unordered_set<T> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream &os, const unordered_map<T,U> &c){return out_container(os,ALL(c));}
template <typename T, typename U> ostream& operator<<(ostream& os, const pair<T,U> &p){os << "(" << p.first << "," << p.second << ")"; return os;}

template <typename T> T& chmin(T &a, const T &b){return a = min(a,b);}
template <typename T> T& chmax(T &a, const T &b){return a = max(a,b);}

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

  double T,X;
  while(cin >> T >> X){
    cout << setprecision(12) << T/X << endl;
  }
  
  return 0;
}


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

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int T = sc.nextInt();
		int[] c = new int[N];
		int[] t = new int[N];
		int p = 1100;
		for(int i = 0; i < N; i++){
			c[i] = sc.nextInt();
			t[i] = sc.nextInt();
		}
		for(int i = 0; i < N; i++){
			if((t[i] <= T) && (c[i] < p)){
					p = c[i];
				}
			}
		if(p == 1100){
			System.out.println("TLE");
		}else{
			System.out.println(p);
		}
	}
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if ((A < C && C < B) || (A > C && C > B)) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3636
def f(a, b):
    digit_a = digit_b = 0

    while a:
        digit_a += 1
        a //= 10

    while b:
        digit_b += 1
        b //= 10

    return max(digit_a, digit_b)


n = int(input())

ans = n

for i in range(1, int(n ** 0.5) + 1):
    if n % i == 0:
        ans = min(ans, f(i, n // i))

print(ans)



Measured memory_bytes: 3188
N, M = list(map(int, input().split()))

road = [[] for i in range(N)]
for i in range(M):
    a, b = list(map(int, input().split()))
    road[a - 1].append(b)
    road[b - 1].append(a)

for i in range(N):
    print(len(road[i]))


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int
int N, A, B;
bool check(int att, int h[]) {
    int cnt = 0;
    rep(i, N) {
    //    dump(h[i] - B*att);
        if (h[i] - B*att > 0) cnt += (h[i] - B*att + A-B-1)/(A-B);
    }
    //dump(cnt);
    return att >= cnt;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    int h[N];
    rep(i, N) cin >> h[i];
    sort(h, h+N);
    int left = 1, right = h[N-1];
    int middle1 = (left + right)/2;
    int middle0 = 0;
    while(middle1 != middle0) {
        //dump(middle1);
        if(check(middle1, h)) right = middle1;
        else left = middle1+1;
        int tmp = middle1;
        middle1 = (left + right) / 2;
        middle0 = tmp;
    }
    cout << middle1 << endl;
    

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#define int long long
using namespace std;

int grundy(int n) {
	int cnt = 0;
	n++;
	while (n % 2 == 0) { n /= 2; cnt++; }
	return (1LL << cnt);
}

int n, l;
string s;

int vnum = 1;
vector<int> et[100001];
vector<int> ec[100001];
int depth[100001];

int dfs(int v) {
	if (et[v].size() == 0) return 0;
	if (et[v].size() == 1) { return dfs(et[v][0]) ^ grundy(l - depth[v] - 1); }
	return dfs(et[v][0]) ^ dfs(et[v][1]);
}

signed main() {
	int i, j, k;
	
	cin >> n >> l;
	for (i = 0; i < n; i++) {
		cin >> s;
		
		int pos = 0;
		for (j = 0; j < s.length(); j++) {
			for (k = 0; k < ec[pos].size(); k++) {
				if (s[j] - '0' == ec[pos][k]) break;
			}
			if (k == ec[pos].size()) {
				depth[vnum] = j + 1;
				et[pos].push_back(vnum);
				ec[pos].push_back(s[j] - '0');
				pos = vnum;
				vnum++;
			}
			else {
				pos = et[pos][k];
			}
		}
	}
	
	int g = dfs(0);
	if (g == 0) cout << "Bob" << endl;
	else cout << "Alice" << endl;
	return 0;
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

	ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }
	ll lcm(ll x, ll y){ return (x  / gcd(x, y) * y ); }

int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	cin >>n;
	VI a(n), gm, ck(n+1);
	rep(i, n){ cin >>a[i]; a[i]--;}
	ll ans =0;
	int p= 0;
	rep(i, n){
		if(p != a[i]){
			ans++;
		}else p++;
		
	}
	
	cout << (ans != n? ans: -1) <<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n;
vector<pair<double, double> > v;
double ans=0.0;

void dist(int x, int y){
    int x1 = v[x].first;
    int y1 = v[x].second;
    int x2 = v[y].first;
    int y2 = v[y].second;

    ans += sqrt(pow(x2 - x1, 2)+ pow(y2 - y1, 2) * 1.0);

}

void calc(string s){
    for(int i=1; i<n; i++){
        dist(int(s[i])-int('0'), int(s[i-1])-int('0'));
    }

}

int main(){
    std::cout<<std::fixed<<std::showpoint;
    std::cout<<std::setprecision(10);
    cin>>n;
    string s = "";
    char x = '0';
    for(int i=0;i<n;i++){
        s.push_back(x);
        x++;
        double x,y;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }

    //cout<<int('8')-int('0')<<endl;

    calc(s);
    int cnt = 1;

    while(next_permutation(s.begin(), s.end())){
        calc(s);
        cnt++;
    }


    cout<<ans/double(cnt)<<endl;

}


Measured memory_bytes: 256
import sys
s = sys.stdin.readlines()

n, k=map(int, s[0].split())

d=[]
A=[]

for i in s[1:2*k:2]:
    d.append(int(i))

for i in s[2:2*k+1:2]:
    A.append(list(map(int, i.split())))

from collections.abc import Iterable
def flatten(l):
    for el in l:
        if isinstance(el, Iterable) and not isinstance(el, (str, bytes)):
            yield from flatten(el)
        else:
            yield el

A_flat=list(flatten(A))

import collections
c = collections.Counter(A_flat)

print(n-len(list(c.keys())))


Measured memory_bytes: 9480
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int arr[35];
int main()
{  
	memset(arr, 0, sizeof(arr) );
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < n; i++) {
	  int k;
	  cin >> k;
	  for(int j = 0; j < k; j++) {
	  	int tmp;
	  	cin >> tmp;
			arr[tmp]++;
	  }
	}
	int ans = 0;
	for(int i = 1; i <= m; i++) {
		if(arr[i] == n) ans++;
	}
	cout << ans << endl;
  return 0;
}


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

signed main() {
    int k;
    cin >> k;
    int s = 100;
    int c = 0;
    while (true) {
        c++;
        s = (long long)(((double)s) * 1.01);
        if (s >= k) {
            cout << c << endl;
            break;
        }
    }
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int h1 = scn.nextInt();
        int m1 = scn.nextInt();
        int h2 = scn.nextInt();
        int m2 = scn.nextInt();
        int k = scn.nextInt();

        int wakeUpTime = ((h2-h1)*60)+m2-m1;
        int StartStudy = wakeUpTime - k;

        System.out.println(StartStudy);

        scn.close();

    }

}

Measured memory_bytes: 27080
N,X=map(int,input().split())
A=list(map(int,input().split()))
cums=[0]
for i in A:
  cums.append(cums[-1]+i)
ans=float('inf')
for k in range(1,N+1):
  #k回捨てる作業を行うと、k*Xのコストが必要
  tmp=k*X
  #このコスト自体で最低が更新できないなら下の動作は飛ばしてよい
  if tmp >= ans:
    break
  #捨てる回数kがNの半分以上
  #1番目・2番目に拾うゴミはプラスコストは（5×距離）なので
  if 2*k >= N:
    tmp+=5 * cums[-1]
    ans=min(ans, tmp)
    break
  #3番目以降のプラスコストは（2*i番目+1)×距離    
  #k回捨てるのに、1,2番目に拾うのはすべて足して5をかければいい
  tmp+=5*(cums[-1]-cums[-1-2*k])
  #残りの拾うべきもの
  ri=N-2*k
  #3番目に拾うのはコスト7掛け
  m=7
  while True:
    if ri<=k:
      #3番目で拾いきれるなら
      tmp+=m*cums[ri]
      break
    tmp+=m*(cums[ri]-cums[ri - k])
    m+=2
    ri-=k
  ans=min(ans,tmp)

print(ans+N*X)

Measured memory_bytes: 26376
#include<bits/stdc++.h>
using namespace std;
int frog(std::vector<int> v,int n)
{
    int dp[100001] = {0};
    dp[0] = 0;
    dp[1] = abs(v[0]-v[1]);
    int ans1 = abs(v[0]-v[1]) + abs(v[1]-v[2]);
    int ans2 = abs(v[0] - v[2]);
    dp[2] = min(ans1,ans2);

    for(int i=3;i<=n;i++)
    {
        int a1 = dp[i-2] + abs(v[i-2]-v[i-1]) + abs(v[i]-v[i-1]);
        int a2 = dp[i-2] + abs(v[i-2]-v[i]);
        int a3 = min(a1,a2);
        int a4 = dp[i-1] + abs(v[i]-v[i-1]);

        dp[i] = min(a3,a4);
    }

    return dp[n-1];

}
int main()
{
    int n;
    cin>>n;
    std::vector<int> v;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        v.push_back(a);
    }

    int ans = frog(v,n);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4560
#include<stdio.h>

int main(){
  int H, i, key[250];
  scanf("%d", &H);
  for(i = 1 ; i <= H ; i++) scanf("%d", &key[i]);

  for(i = 1 ; i <= H ; i++){
    printf("node %d: key = %d, ", i, key[i]);
    if(i > 1)printf("parent key = %d, ",key[i / 2]);
    if(2 * i <= H) printf("left key = %d, ",key[i * 2]);
    if(2 * i + 1 <= H)printf("right key = %d, ",key[i * 2 + 1]);
    printf("\n");
  }
}



Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  ll N,K;
  cin>>N>>K;

  ll ans=min(N%K,K-N%K);
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T> &p){ cout << "[" << p.first << ", " << p.second << "]"; return os; }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define For1(i, n) for(int i = 1; i <= (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, a, b);
    Cout((b-1 + a-1-1) / (a-1));
}




Measured memory_bytes: 256
import sys
from collections import deque
import bisect
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    v = sorted(list(map(int, input().split())))

    while len(v) > 1:
        v1 = v.pop(0)
        v2 = v.pop(0)
        nv = (v1 + v2) / 2
        if len(v) == 0:
            break
        else:
            i = bisect.bisect_left(v, nv)
            v.insert(i, nv)

    print(nv)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int nax = 202020;
ll sil[nax];
const ll mod = 1000000000 + 7;

ll pot(ll a, int b) {
  ll wyn = 1;
  while (b) {
    if (b&1) {
      wyn = (wyn * a) % mod;
    }
    a = (a * a) % mod;
    b >>= 1;
  }
  return wyn;
}

ll choose(int n, int a) {
  ll licz = 1;
  FOR(i, n - a + 1, n) {
    licz = (licz * i) % mod;
  }
  // printf(" licz: %lld\n", licz);
  ll dziel = pot(sil[a], mod - 2);
  ll res = (licz * dziel) % mod;
  // printf("choose(%d, %d)= %d\n", n,a,res);
  return res;
}

int main() {
	ios_base::sync_with_stdio(false);
  int n, a, b;
  cin >> n >> a >> b;
  ll res = pot(2, n) - 1;
  int c = max(a, b);
  sil[0] = 1;
  FOR(i, 1, c) {
    sil[i] = (sil[i-1] * i) % mod;
  }
  res = (((res - choose(n, a) - choose(n, b)) % mod) + mod ) % mod;
  cout << res << endl;
}

Measured memory_bytes: 1792
import java.util.*;
class Main{
   public static void main(String[] args){
      Scanner in = new Scanner(System.in);
      int a = in.nextInt();
      int b = in.nextInt();
      int h = in.nextInt();
      int area = (a+b)*(h/2);
      System.out.println(area);
   }
}


Measured memory_bytes: 9680
import math
def f(x):
    return math.factorial(x) % (10**9 + 7)

a,b = map(int,input().split())

if abs(a-b) <= 1:
    print((f(a)*f(b)) % (10**9 + 7) if abs(a-b) == 1 else (2*f(a)*f(b)) % (10**9 + 7))
else:
    print(0)

Measured memory_bytes: 46960
n, x = map(int, input().split())
a = list(map(int, input().split()))

last = a[0]
ans = 0
for i in range(1, n):
    if last + a[i] > x:
        num = last + a[i] - x
        ans += num
        last = max(0, a[i] - num)
    else:
        last = a[i]

print(ans)


Measured memory_bytes: 14252
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

    if (a == b) {
        cout << "a == b" << endl;
    } else if (a < b) {
        cout << "a < b" << endl;
    } else {
        cout << "a > b" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> p;


int main()
{
  int n, x;
  cin >> n >> x;
  vector<int> v(n, 0);
  for (int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());

  int res = 0;
  for (int i = 0; i < n; i++){
    if (x < v[i]) {
      cout << res << endl;
      return 0;
    }
    x -= v[i];
    res++;
  }

  res += x / v[0];
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
// Problem Link: 
// Tutorial Link: 

#include<bits/stdc++.h>
 
using namespace std;
 
#define LL long long
#define ll  long long
#define all(v) v.begin(), v.end()
#define pb push_back
#define pLL pair<LL,LL>
#define ff first
#define ss second
#define rep(i,a,b) for(LL i=a;i<b;++i)
#define repb(i,a,b) for(LL i=a;i>b;--i)
#define ld double
#define mp make_pair
#define vLL vector<LL>
#define vpLL vector<pLL>
#define vld vector<ld>
#define pld pair<ld,ld>
#define vpld vector<pld>
#define SLL set<LL>
#define SpLL set<pLL>
#define FIO ios::sync_with_stdio(false)
#define mod 1000000007

string s;

int main()
{
	FIO;
	cin >> s;
	if(s == "RRR") cout << 3 << endl;
	else if(s == "RRS" || s == "SRR") cout << 2 << endl;
	else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3636
def yabai(a):
    al=''
    a2=a
    amarin=a2%4
    if amarin==0 or amarin==3:
        al='00'
    elif amarin%4==2:
        al='11'
    else:
        al='01'
    
    kaisu_a=0
    while a2>0:
        if a2%2==0:
            #pass
            a2=a2/2
            #al='0'+al
        else:
            #pass
            a2=(a2-1)/2
            #al='1'+al
        kaisu_a+=1
    #print(kaisu_a)
    #print('1!')
    for a_i in range(kaisu_a-2):
        amari=a%(2**(a_i+3))
        if amari>=2**(a_i+2) and amari%2==0:
            al='1'+al
        else:
            al='0'+al
    #print(al)
    return al

def main():
    list=input().split(' ')
    a=int(list[0])
    b=int(list[1])
    newa=yabai(a-1)
    #print(newa)
    newb=yabai(b)
    for sa in range(len(newb)-len(newa)):
        newa='0'+newa
    #print(newb)
    answer=0
    #print(newa, newb)
    for i in range(len(newa)):
        if (newa[i]=='0' and newb[i]=='1') or (newa[i]=='1' and newb[i]=='0'):
            answer+=(2**(len(newa)-i-1))
    print(answer)

main()

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

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

    int cnt = 0, win = 0;
    for(int i = 0; i < S.size(); i++){
        if(S[i] == 'o')
            win++;

        cnt++;         
    }
    int pw = 15 - S.size();

    if(pw + win >= 8)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <map>

#define AS(a) (sizeof(a)/sizeof(a[0]))
using namespace std;
long long int MOD = 1000000007;
long long int INF = 10000000000007;




int main() {
  int N,W;
  cin >> N >> W;
  long long int w[N],v[N];
  for(int i = 0; i < N; i++) {
    cin >> w[i] >> v[i];
  }

  long long int dp[N+1][N+1][5 * N + 1];
  for(int i = 0; i < N+1; i++) {
    for(int j = 0; j < N+1; j++) {
      for(int k = 0; k < 5*N + 1; k++) {
        dp[i][j][k] = 0;
      }
    }
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N+1; j++) {
      for(int k = 0; k < 5 * N + 1; k++) {
        dp[i+1][j][k] = max(dp[i+1][j][k],dp[i][j][k]);
        int tmp = w[i] - w[0];
        if(j + 1 >= N+1) continue;
        if(k + tmp >= 5 * N + 1) continue;
        dp[i+1][j + 1][k + tmp] = max(dp[i+1][j + 1][k + tmp],dp[i][j][k] + v[i]);
      }
    }
  }
  long long int ans = 0;
  for(int i = 0; i < N+1; i++) {
    for(int j = 0; j < 5*N+1; j++) {
      if(w[0] * i + j > W) continue;
      ans = max(dp[N][i][j],ans);
    }
  }
  cout << ans << endl;


}


Measured memory_bytes: 40192
s  = input()
q  = int(input())
inv = 1
sfb = [0,"",""]
for i in range(q):
    ls = list(input().split())
    if ls[0] == "1":
        inv *=-1
    else:
        f,c = ls[1:]
        if f == "1":
            sfb[inv] +=c
        else:
            sfb[-inv] +=c

ans = sfb[1][::-1] + s + sfb[-1]
print(ans[::inv])


Measured memory_bytes: 4652
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
using namespace std;

int main() {
  ll k, a, b;
  cin >> k >> a >> b;
  ll ima = 1;
  ll ikkomae = 0;
  ll nikomae = 0;
  for (int i = 1; i <= k; i++) {
    nikomae = ikkomae;
    ikkomae = ima;
    if (i > 1) {
      ll temp = -1;
      if (nikomae >= a) temp = nikomae - a + b;
      ima = max(ikkomae + 1, temp);
    } else {
      ima = ikkomae + 1;
    }
  }
  cout << ima << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;


#define PI			3.14159265
#define OO			1e18
#define SS       	second
#define FF       	first
#define Trace(n)  	cout<< #n <<" = "<< n << endl; 
#define ll			long long
#define endl		"\n"
#define EPS		    1e-9
//#define MOD         1e9 + 7	    
//int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
//int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };

void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}


int main()
{
	//fast();
	int l, r, ans = 0;
	int m;
	cin >> l >> r >> m;
	for (int i = l; i <= r; i++)
		if (i%m == 0)
			ans++;
	cout << ans;


#ifndef ONLINE_JUDGE
	system("pause");
#endif

}

Measured memory_bytes: 3180
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERedAndGreenApples solver = new ERedAndGreenApples();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERedAndGreenApples {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int x = in.nextInt();
            int y = in.nextInt();
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            ArrayList<Integer> red = new ArrayList<>();
            ArrayList<Integer> green = new ArrayList<>();
            ArrayList<Integer> none = new ArrayList<>();

            ArrayList<Integer> eat = new ArrayList<>();
            long sum = 0;

            for (int i = 0; i < a; i++) {
                red.add(in.nextInt());
            }
            for (int i = 0; i < b; i++) {
                green.add(in.nextInt());
            }
            for (int i = 0; i < c; i++) {
                none.add(in.nextInt());
            }

            red.sort(Comparator.reverseOrder());
            green.sort(Comparator.reverseOrder());
            none.sort(Comparator.reverseOrder());
            for (int i = 0; i < x; i++) {
                int r = red.get(i);
                eat.add(r);
                sum += r;
            }
            for (int i = 0; i < y; i++) {
                int g = green.get(i);
                eat.add(g);
                sum += g;
            }
            eat.sort(Comparator.naturalOrder());
            for (int i = 0; i < c; i++) {
                int e = eat.get(i);
                int n = none.get(i);
                if (e < n) {
                    sum = sum - e + n;
                } else {
                    break;
                }
            }
            out.println(sum);

        }

    }
}



Measured memory_bytes: 99648
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int M = 1e9 + 7;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  if (k <= a)
  {
    cout << k ;
  }
  else if (k > a && k <= b)
    cout << a;
  else
    cout << a - (k - a - b);

}

Measured memory_bytes: 3648
import math

def main(*, int=int, input=input):
    N = int(input())

    # スペース区切りでの入力(定数個)
    A = list(map(int, input().split()))

    if 0 in A:
        print(0)
        return
    else:
        Alog = [math.log10(x) for x in A]

    if sum(Alog)>18:
        print(-1)
    else:
        ans = 1
        for a in A:
            ans = ans * a
        if ans > 10**18:
            print(-1)
        else:
            print(ans)
    


if __name__ == "__main__":
    import io, sys
    if "_INPUT" in locals():
        sys.stdin = io.StringIO(_INPUT)
    main()

Measured memory_bytes: 22644
#include<stdio.h>

int main()
{
  int n,i,j,t,A[100],flag=1,count=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  i=0;
  while(flag)
    {
      flag=0;
      for(j=n-1;j>=i+1;j--)
	{
	  if(A[j]<A[j-1])
	    {
	      t=A[j];
	      A[j]=A[j-1];
	      A[j-1]=t;
	      flag=1;
	      count++;
	    }
	}
      i++;
    }
  
  for(i=0;i<n-1;i++)
    {
      printf("%d ",A[i]);
    }
  printf("%d\n",A[i]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
n = int(input())
a = [int(input()) for i in range(n)]
b = [0]*n
b[0] = 1
count = 0
c = a[0]
for i in range(n):
  if b[c-1] == 0:
    b[c-1] = 1
    if c == 2:
      print(count+1)
      break
  else:
    print(-1)
    break
  c = a[c-1]
  count += 1

Measured memory_bytes: 7852
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i =0; i < n ;i++)
using namespace std;
long long a[10];


long long sol(long long i, long long j, long long k, long long a[]){

    return a[i] * a[j] * a[k]; 
    
}

int main()
{
    long long N;
    string s;
    cin >> N;

    rep(i, N){
        cin >> s;
        if(s[0] == 'M') a[0]++;
        else if(s[0] == 'A') a[1]++;
        else if(s[0] == 'R') a[2]++;
        else if(s[0] == 'C') a[3]++;
        else if(s[0] == 'H') a[4]++;
    }
    long long ans = 0;

    ans += sol(0,1,2,a);
    ans += sol(0,1,3,a);
    ans += sol(0,1,4,a);
    ans += sol(0,2,3,a);
    ans += sol(0,2,4,a);
    ans += sol(0,3,4,a);
    ans += sol(1,2,3,a);
    ans += sol(1,2,4,a);
    ans += sol(1,3,4,a);
    ans += sol(2,3,4,a);

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 256
//#pragma 03
//#pragma GCC optimization ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define int long long
#define eb emplace_back
#define ef emplace_front
#define rep(i, x, n) for (int i = x; i < n; ++i)
#define mp make_pair
#define fi first
#define se second
#define ii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vii vector<pair<int, int>>
#define reverse(s) reverse(s.begin(), s.end())
#define ld long double
#define vs vector<string>
#define inf INT_MAX
#define vc vector<char>
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define vb vector<bool>
#define lb(a, x) lower_bound(a.begin(), a.end(), x)
#define ub(a, x) upper_bound(a.begin(), a.end(), x) 
#define vvi vector<vi>
#define mine(a) min_element(a.begin(),a.end())
#define maxe(a) max_element(a.begin(), a.end())
#define iota(a,i) iota(a.begin(),a.end(),i)
#define fileopen(filename) if (fopen(filename".INP", "r")) {freopen(filename".INP", "r", stdin);freopen(filename".OUT", "w", stdout);}
int dp[5009][5009];
signed main() {
    fastio;
    int n;
    string s;
    cin >> n >> s;
    int l = s.length();
    //cout << l << 'a' << endl;
    dp[1][0] = 1;
    dp[0][0] = 1;
    rep(i, 1, n + 1) {
        rep(j, 0, n + 1) {
            if (!dp[i][j]) {
                if (j == 0 && i > 1)
                {
                    dp[i][j] = dp[i - 1][1] * 2 + dp[i - 1][0];
                }
                else {
                    dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j + 1] * 2;
                }
                dp[i][j] %= 1000000007;

            }
        }
    }
    cout << dp[n][l];
}

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

import math
if x >= (a*a*b)/2:
  y = 2*(a*a*b-x)/(a*a*a)
  ans = math.atan(y)
  ans = math.degrees(ans)
else:
  y = 2*x/(a*b)
  ans = math.atan(b/y)
  ans = math.degrees(ans)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
using namespace std;
int main() {
  int N;
  string S;
  cin >> N >> S;
  int cnt = 0;
  for (int i = 0; i < N - 2; i++) {
    if (S[i] == 'A' && S[i + 1] == 'B' && S[i+2] == 'C') {
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

int main(){
  long n;
  int s[100],cnt=0;
  scanf("%ld",&n);
  if(n==0)
    printf("0\n");
  else{
    while(n!=0){
      if(n%2!=0){
        s[cnt]=1;
        n-=1;
      }
      else
        s[cnt]=0;
      cnt++;
      n/=-2;
    }
    for(int i=cnt-1;i>=0;i--)
      printf("%d",s[i]);
    printf("\n");
  }
}

Measured memory_bytes: 128
h,w = gets.split.map(&:to_i)
arr = []
h.times{arr << gets.chomp.split("")}
arr2 =[]
arr.each { |l|
unless l.count(".")== w
arr2 << l
end}

arr3 = arr2.transpose
arr3.map do |i|
  if i.include?("#")
    i
  else
    arr3.delete(i)
  end
end

arr4 = arr3.transpose
arr4.map do |i|
  puts i.join
 end


Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

// int main(){
// 	ll D,G;
// 	cin >> D >>G;
// 	vector<ll> p(D);
// 	vector<ll> c(D);
// 	for(int i = 0; i < D; i++) {
// 		cin >> p[i] >> c[i];
//  	}
	
// 	vector<vector<ll>> dp(11,vector<ll>(1500,0));//dp[i][j]=i*100点までのもんだいで、j問だけ解いたときの最大の点数
// 	int sum = 0;

// 	for(int i = 0; i < D; i++) {
// 		for(int j = 0; j <=1001; j++) {
// 			for(int k = 0; k <= p[i]; k++) {
// 				if (k == p[i]){
// 				dp[i+1][j+k] = max(dp[i+1][j+k],dp[i][j] + (i + 1) * 100 * k + c[i]);
// 				}
// 				else{
// 					dp[i+1][j+k] = max(dp[i+1][j+k],dp[i][j] + (i + 1) * 100 * k);//ボーナスを加算
// 				}
// 			}
// 		}
// 	}

// 	for(int i = 0; i <= 1001; i++) {
// 		if (dp[D][i] >= G){
// 			cout << i << endl;
// 			break;
// 		}
// 	}

// 	return 0;
// }

int main(){
	ll D,G;
	cin >> D >>G;
	vector<ll> p(D);
	vector<ll> c(D);
	for(int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
 	}
	int res =INF;

	for(int i = 0; i < (1 << D) ; i++) {
		int tmp = 0;
		int ans = 0;
		int a = -1;
		for(int j = 0; j < D; j++) {
			if ((i >> j) & 1){//ビットが立っている時
				ans += (j+1) * 100 *p[j] + c[j];
				tmp += p[j];
			}
			else{
				a = j;
			}
		}
		if(ans < G){
            int s1 = 100 * (a + 1);
            int need = (G - ans + s1 - 1) / s1;
            if(need >= p[a]){
                continue;
            }
            tmp += need;
        }
        res = min(res, tmp);
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 764