akhauriyash/Code-Regression huggingface dataset:
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;

#define MaxN 100005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}


int main()
{
    //std::ios::sync_with_stdio(false);
    int A,B,C,D;
    read(A);read(B);read(C);read(D);
    int s = max(A,C);
    int e = min(B,D);
    int ans = max(0,e-s);
    out(ans);puts("");
    //system("pause");
    //printf("%lld\n", ((x)%mod+mod)%mod );
    //printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
}


Measured memory_bytes: 256
n = int(input())
a = [int(item) for item in input().split()]

rank_num = [0] *  9
for item in a:
    item_rank = -1 
    if item < 400:
        item_rank = 0
    elif item < 800:
        item_rank = 1
    elif item < 1200:
        item_rank = 2
    elif item < 1600:
        item_rank = 3
    elif item < 2000:
        item_rank = 4
    elif item < 2400:
        item_rank = 5
    elif item < 2800:
        item_rank = 6
    elif item < 3200:
        item_rank = 7
    else:
        item_rank = 8
    rank_num[item_rank] += 1

ans_min = max(8 - rank_num[:-1].count(0), 1)
ans_max = 8 - rank_num[:-1].count(0) + rank_num[-1]
print(ans_min, ans_max)

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


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

    int n = s.size();
    int a = 0, b = 0, c = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'a') a++;
        if(s[i] == 'b') b++;
        if(s[i] == 'c') c++;
    }

    for(int i = 0; i < n / 3; i++){
        if(0 < a && 0 < b && 0 < c) {
            a--;
            b--;
            c--;
        } else {
            break;
        }
    }

    if(a == 0 && b == 0 && c == 0) {
        cout << "YES" << endl;
        return 0;
    }

    if(a <= 1 && b <= 1 && c == 0) {
        cout << "YES" << endl;
        return 0;
    }

    if(a == 0 && b <= 1 && c <= 1) {
        cout << "YES" << endl;
        return 0;
    }

    if(a <= 1 && b == 0 && c <= 1) {
        cout << "YES" << endl;
        return 0;
    }

    cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3712
h, n = map(int, input().split())
A = []
B = []
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
inf=float('inf')
dp = [[inf] * (h + 1) for i in range(n + 1)]
dp[0][0]=0
for i in range(n):
    for j in range(h + 1):
        if j < A[i]:
            dp[i + 1][j] = min(dp[i][j], B[i])
        else:
            dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - A[i]] + B[i])
print(dp[n][h])

Measured memory_bytes: 285320
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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; }

typedef long long ll;

using namespace std;



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,s;cin>>n>>s;
  vector<ll>kouho;
  if(n<s){
    cout<<-1<<endl;
    return 0;
  }
  if(n==s){
    cout<<n+1<<endl;
    return 0;
  }
  kouho.push_back(n-s);
  for(ll pri=1;pri<(ll)sqrt(n-s)+1;pri++){
    //ll pri=tp.first;
    if((n-s)%pri!=0)continue;
    kouho.push_back((n-s)/pri);
    ll tn=n,ts=0;
    //cout<<pri<<endl;
    while(tn>0){
      ts+=tn%(pri+1);
      tn/=pri+1;
    }
    //cout<<ts<<" "<<s<<endl;
    if(ts==s){
      cout<<pri+1<<endl;
      return 0;
    }
  }
  sort(all(kouho));
  for(auto pri:kouho){
    ll tn=n,ts=0;
    while(tn>0){
      ts+=tn%(pri+1);
      tn/=pri+1;
    }
    //cout<<pri<<endl;
    if(ts==s){
      cout<<pri+1<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;


  return 0;

}


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

int main(){
  ll N,v[200000],cnt=0,max=pow(10,9);
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> v[i];
    if(v[i]<max){
      max=v[i];
      cnt++;
    }
  }
  cout << cnt <<endl;
}
  

Measured memory_bytes: 1792
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int[][][] f = new int[n][5][2];
		for(int i = 0; i < n ; i++){
		    for(int j = 0; j < 5 ; j++){
		        f[i][j][0] = sc.nextInt();
		        f[i][j][1] = sc.nextInt();
		    }
		}
		long[][] p = new long[n][11];
		for(int i = 0; i < n ; i++){
		    for(int j = 0; j < 11 ; j++){
		        p[i][j] = sc.nextLong();
		    }
		}
		
		// 計算
		long result = Long.MIN_VALUE;
		for(int i = 1; i < 1<<10 ; i++){
		    int[] cnt = new int[n];
		    for(int j = 0; j < 10; j++){
		        int youbi = j/2;
		        int ampm = j%2;
		        if((i>>j & 1) == 1){
		            for(int k = 0; k < n; k++){
		                if(f[k][youbi][ampm] == 1) cnt[k]++;
		            }
		        }
		    }
		    long temp = 0;
		    for(int l = 0; l < n; l++){
		        temp += p[l][cnt[l]];
		    }
		    result = max(result, temp);
		}
		
		// 出力
		System.out.println(result);
	}
}


Measured memory_bytes: 27008
MOD=998244353
A,B,C,D=map(int,input().split())

dp=[[1]*(D+1) for _ in range(C+1)]

powA=1
for i in range(A+1,C+1):
  powA*=B
  powA%=MOD
  dp[i][B]=powA
  
powB=1
for i in range(B+1,D+1):
  powB*=A
  powB%=MOD
  dp[A][i]=powB
#print(dp)

for i in range(A+1,C+1):
  for j in range(B+1,D+1):
    dp[i][j]=dp[i-1][j]*j+dp[i][j-1]*i
    dp[i][j]-=(i-1)*(j-1)*dp[i-1][j-1]
    dp[i][j]%=MOD
    
#print(dp)
print(dp[C][D])

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans1=10*a+b+c;
    int ans2=a+10*b+c;
    int ans3=a+b+10*c;
    cout << max(max(ans1,ans2),ans3) << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int a = in.nextInt();
			int b = in.nextInt();
			int c = in.nextInt();
			int d = in.nextInt();

			out.println(Math.min(a, b) + Math.min(c, d));

		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 21588
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb push_back
#define boost ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pii pair<ll,ll>
#define forn(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
int main()
{
      boost;
      int n,q,sum=0;
      cin>>n;
      int arr[n];
      forn(i,n)
      {
            cin>>arr[i];
            sum+=arr[i];
      }
      cin>>q;
      while(q--)
      {
            int x,y;
            cin>>x>>y;
            x--;
            int D=sum-arr[x]+y;
            cout<<D<<endl;
      }
}

Measured memory_bytes: 256
#include<stdio.h>

int main () {
	int i, j, k, n, x;
	int count;
	while(1){
		count = 0;
		scanf("%d %d", &n, &x);
		
		if ( n == 0 && x == 0 ) {
			break;
		}
		
		for ( i = 1; i <= n - 2; i++ ) {
			for ( j = i + 1; j <= n - 1; j++ ) {
				for ( k = j + 1; k <= n; k++ ) {
					if ( i + j + k == x ) {
						count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}


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

int main()
{
    int n,i;
    double a[105],s=0;

    cin>>n;

    for(i=0;i<n;i++){
        cin>>a[i];
        s=s+(1/a[i]);
    }
    cout<<1/s<<endl;

    return 0;
}



Measured memory_bytes: 256
package main

import "fmt"

func main() {


	var n int
	fmt.Scan(&n)


	f := true

	for i := 1; i < 10; i++ {
		if f {

			for j := 1; j < 10; j++ {
				if n == ( i * j) {
					fmt.Println("Yes")
					f = false
					break
				}
			}
		}
	}

	if (f) {
		fmt.Println("No")
	}

}

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


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

    sort(a,a+3);
    if(abs(a[0]-a[1])==abs(a[1]-a[2]))
    {
                cout<<"YES";
                return 0;
    }
    cout<<"NO";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iomanip>
#include <map>
#include <set>
#include <tuple>
#include <unordered_map>
#include <iterator>
#include <string>
#include <limits>
 
using namespace std;
 
using i64 = int64_t;
using P = pair<i64, i64>;
i64 mod = 1000000007;
int int_max = 2147483647;
int max_n = 1e5;
 
 
int main(int argc, char **argv) {
    double r;
    cin >> r;
 
    cout<< setprecision(10) << r*2.* M_PI <<endl;
 
    return 0;
}

Measured memory_bytes: 3780
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int main(){
  int N,M,K;
  cin >> N >> M >> K;
  for(int i = 0;i <= N;i++){
    for(int j = 0;j <= M;j++){
      if((N - i) * j + (M - j) * i == K){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" <<endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		Map<Integer,Boolean> map = new HashMap<>();
		int count = 0;
		for (int i = 0; i < N; i++) {
			int num = sc.nextInt();
			if (map.containsKey(num)) {
				if (map.get(num)) {
					map.replace(num, false);
					count--;
				} else {
					map.replace(num, true);
					count++;
				}
			} else {
				map.put(num, true);
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 62800
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 10000007ll
#define pb push_back
#define vl vector<ll>
#define pll pair<ll,ll>
#define mp make_pair
using namespace std;
#define pi (long double)3.14159265358979323846 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 struct sch{
	ll s,e,t;
};
bool sortinrev(const struct sch &a, const struct sch &b) 
{ 
    return (a.s < b.s); 
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 
int main()
{
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a)
	{
		cout<<k<<endl;
	}
	else
	{
		if(k<=a+b)
		{
			cout<<a<<endl;
		}
		else
		{
			cout<<a-(k-a-b)<<endl;
		}
	}
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int H, W;
ll DP[1001][1001];
char a;

int main() {
	cin >> H >> W;
	DP[1][1] = 1;
	for (int i = 1; i != H + 1; ++i) {
		for (int j = 1; j != W + 1; ++j) {
			cin >> a;
			if (a == '.') {
				DP[i][j] += (DP[i - 1][j] + DP[i][j - 1]) % mod;
			}
		}
	}
	cout << DP[H][W] << endl;
	return 0;
}

Measured memory_bytes: 8064
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

l = p[:x] + q[:y]
l.sort()

i = 0
while i < len(l) and i < len(r):
  if l[i] < r[i]:
    l[i] = r[i]
    i += 1
  else:
    break

print(sum(l))

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

using namespace std;
typedef unsigned long long ull;
#define DBG(v) cerr << #v << " = " << (v) << endl;

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

    int n, X;
    cin >> n >> X;
    vector<int> a(n);
    for (int &x:a)
        cin >> x;
    partial_sum(a.begin(), a.end(), a.begin());
    auto it = upper_bound(a.begin(), a.end(), X);
    cout << it - a.begin() + 1;
    return 0;
}

Measured memory_bytes: 256
M=10**9+7
n,k=map(int,input().split())
l=[0]*(k+1)
a=0
for i in range(k,0,-1):
  l[i]=pow(k//i,n,M)-sum(l[j] for j in range(i*2,k+1,i))
  a+=i*l[i]
print(a%M)

Measured memory_bytes: 70876
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const ll mod = 1e9+7;


void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


/* 注意 

    1LL<<60 * N とかのオーバーフローに気を付けろ
    制約がヒントになる、ちゃんと全ての制約を見ろ

*/


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

    int N, W; cin >> N >> W;
    vector<int> v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];

    vector<vector<int>> dp(N+5, vector<int>(W+5, 0));
    rep(i, N) rep(j, W+1) {
        chmax(dp[i+1][j], dp[i][j]);
        if (j-w[i]>=0) chmax(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
    }

    cout << dp[N][W] << endl;
    
    return 0;
}



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

using namespace std;

#define pii pair<int,int>
#define ll long long
#define s second
#define f first



int main(){
  ll a,b;
  cin >> a >> b;
  if(a>=13){
    cout << b;
    return 0;
  }else if(a>=6){
    cout << b/2;
    return 0;
  }
  cout << 0;
  return 0;
}


Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var map = new char[n, n];
        var map2 = new char[m, m];
        for (int i = 0; i < n; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < n; j++) map[i, j] = s[j];
        }
        for (int i = 0; i < m; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < m; j++) map2[i, j] = s[j];
        }
        Console.WriteLine(checkMap(map, map2) ? "Yes" : "No");
    }
    public static bool checkMap(char[,] map, char[,] map2)
    {
        var n = map.GetLength(0); var m = map2.GetLength(0);
        for (int i = 0; i <= n - m; i++)
            for (int j = 0; j <= n - m; j++)
                if (checkMap2(map, map2, i, j)) return true;
        return false;
    }
    public static bool checkMap2(char[,] map, char[,] map2, int x, int y)
    {
        var m = map2.GetLength(0);
        for (int i = 0; i < m; i++)
            for (int j = 0; j < m; j++)
            {
                var nx = x + i;
                var ny = y + j;
                if (map[nx, ny] != map2[i, j]) return false;
            }
        return true;
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
  ll n, a, b; cin >> n >> a >> b;
  ll ans = (n / (a + b)) * a;
  ll left = n % (a + b);
  ans += min(left, a);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, X, Y = map(int, input().split())
result = [0]*N
for i in range(1, N+1):
    for j in range(i+1, N+1):
        result[min([j-i,abs(X-i)+1+abs(j-Y),abs(Y-i)+1+abs(j-X)])-1]+=1
s = '\n'.join(map(str, result[:-1]))
print(s)

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

int main(){
  ll n;
  cin>>n;
  ll big=n/500,small=(n%500)/5;
  cout<<big*1000+small*5<<endl;
  
  
  }

Measured memory_bytes: 256
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define INT_MAX 2147483647
#define LLINT_MAX 9223372036854775807
#define mod 1000000007
#define ll long long int
using namespace std;

ll t, a, b, c, d;

ll gcd(ll a, ll b)
{
	ll c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}
int main() {
	cin >> t;
	lp(t) {
		cin >> a >> b >> c >> d;
		if (a < b)cout << "No" << endl;
		else if (d < b)cout << "No" << endl;
		else if (c >= b)cout << "Yes" << endl;
		else {
			if (b + a%gcd(b, d) - gcd(b, d) <= c) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
	}
	return 0;
}

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

struct Data {
    int x, y;
    int mx, my;
};

const int N = (int)1e5;
const int ITERATION = 500;
const double EPS = (double)1e-9;
const double INF = (double)1e18;

Data dat[N+5];

double solve(int n, double timee) {
    pair<double, double> range_x = make_pair(INF, -INF);
    pair<double, double> range_y = make_pair(INF, -INF);

    for (int i=1; i<=n; i++) {
        double x = (double)dat[i].x + (double)dat[i].mx * timee;
        range_x.first = min(range_x.first, x);
        range_x.second = max(range_x.second, x);

        double y = (double)dat[i].y + (double)dat[i].my * timee;
        range_y.first = min(range_y.first, y);
        range_y.second = max(range_y.second, y);
    }

    double dx = range_x.second - range_x.first;
    double dy = range_y.second - range_y.first;
    return dx * dy;
}

int main() {
    int n; scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        char dir[5]; scanf("%d %d %s", &dat[i].x, &dat[i].y, dir);
        if (dir[0] == 'R') {
            dat[i].mx = 1;
            dat[i].my = 0;
        } else if (dir[0] == 'L') {
            dat[i].mx = -1;
            dat[i].my = 0;
        } else if (dir[0] == 'U') {
            dat[i].mx = 0;
            dat[i].my = 1;
        } else if (dir[0] == 'D') {
            dat[i].mx = 0;
            dat[i].my = -1;
        }
    }

    double lo = (double)0.0, hi = (double)1e10;
    for (int xxx=0; xxx<ITERATION; xxx++) {
        double mid_a = ((double)2.0 * lo + hi) / (double)3.0;
        double mid_b = (lo + (double)2.0 * hi) / (double)3.0;
        double ret_a = solve(n, mid_a);
        double ret_b = solve(n, mid_b);

        if (ret_a - ret_b > -EPS) {
            lo = mid_a;
        }
        if (ret_a - ret_b < EPS) {
            hi = mid_b;
        }
    }

    double res = solve(n, (lo + hi) / (double)2.0);
    printf("%.10lf\n", res);
    return 0;
}


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

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

    long long n, k;
    cin >> n >> k;
    vector <long long> arr(n);
    for(int i=0;i<n;i++)
        cin >> arr[i];

    long long cost = LONG_LONG_MAX;
    for(int i=0;i<=n-k;i++){
        if(arr[i] < 0 && arr[i+k-1] <= 0){
            cost = min(cost, abs(arr[i]));
        }
        else if( arr[i]>=0 && arr[i+k-1] > 0){
            cost = min(cost, arr[i+k-1]);
        }
        else{
            cost= min(cost, min(abs(arr[i])*2+arr[i+k-1], abs(arr[i])+arr[i+k-1]*2));
        }
    }
    cout << cost << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long
#define met(a) memset(a,0,sizeof(a))
#define inf 0x3f3f3f3f
using namespace std;
const int mod=1e9+7;
const int N=1e5+10;
ll a[N],b[N],c[N];
int main()
{
    ll i,j=0,k=0,m,n;
    ll ans=0;
    cin>>n;
    for(i=1; i<=n; i++)
        cin>>a[i];
    for(i=1; i<=n; i++)
        cin>>b[i];
    for(i=1; i<=n; i++)
        cin>>c[i];
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    sort(c+1,c+1+n);
    for(i=1;i<=n;i++)
    {
        while(a[j+1]<b[i]&&j+1<=n)
            j++;
        while(c[k+1]<=b[i]&&k+1<=n)
            k++;
        ans+=j*(n-k);
    }
    cout<<ans<<endl;
    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  string str;cin>>str;
  if(str=="AKIHABARA"||str=="AKIHBARA"||str=="AKIHABRA"||str=="AKIHABAR"||str=="KIHABARA"||str=="KIHBARA"||str=="KIHABRA"||str=="KIHABAR"||str=="AKIHBRA"||str=="AKIHBAR"||str=="AKIHABR"||str=="KIHBRA"||str=="KIHBAR"||str=="AKIHBR"||str=="KIHBR"||str=="KIHABR")cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
n = int(input())
a = list(map(int,input().split()))
a_sum = sum(a)
aa = np.array(np.cumsum(a),dtype="object")
all_a = sum(a)

mod = 1000000007

ans = 0
for i in range(n-1):
    ans += (a[i]%mod * (all_a - aa[i])%mod)

print(ans%mod)

Measured memory_bytes: 50036
n,m,x = [int(x) for x in input().split()]

cost = []
data = []

for _ in range(n):
    tmp = [int(x) for x in input().split()]
    cost.append(tmp[0])
    data.append(tmp[1:])

ans = 1200010

for i in range(1<<n):
    tmpcost = 0
    xarr = [0]*m
    for j in range(12):
        if (i&(1<<j)):
            tmpcost+=cost[j]            
            for k in range(m):
                xarr[k] += data[j][k]

    xarr = [val >= x for val in xarr]
    if all(xarr):ans = min(ans,tmpcost)



if ans == 1200010:print(-1)
else:print(ans)

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

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

    int U[h + 2][w + 2];
    int D[h + 2][w + 2];
    int L[h + 2][w + 2];
    int R[h + 2][w + 2];
    for (int i = 0; i < h + 2; i++){
        for (int j = 0; j < w + 2; j++){
            U[i][j] = 0;
            D[i][j] = 0;
            L[i][j] = 0;
            R[i][j] = 0;
        }
    }
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (s[i][j] == '.'){
                U[i + 1][j + 1] = U[i][j + 1] + 1;
                L[i + 1][j + 1] = L[i + 1][j] + 1;
            }
            if (s[h - i - 1][w - j - 1] == '.'){
                D[h - i][w - j] = D[h - i + 1][w - j] + 1;
                R[h - i][w - j] = R[h - i][w - j + 1] + 1;
            }
        }
    }
    int ans = 0;
    for (int i = 1; i < h + 1; i++){
        for (int j = 1; j < w + 1; j++){
            ans = fmax(ans, U[i][j] + D[i][j] + L[i][j] + R[i][j]);
        }
    }
    cout << ans - 3 << endl;
}


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

void solve() {
    int n; cin>>n;
    int a = 0, b=0, c=0, d=0;
    rep(i, 0, n) {
        string s; cin>>s;
        if(s == "AC")
            a++;
        else if (s == "WA")
            b++;
        else if (s == "TLE")
            c++;
        else
            d++;
    }
    cout << "AC x " << a << "\n";  
    cout << "WA x " << b << "\n";  
    cout << "TLE x " << c << "\n";  
    cout << "RE x " << d << "\n";  

}

int main() {
    int t = 1; //scanf("%d", &t);
    while(t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3624
//is there any case of -1 or any special corner cases ?
#include<bits/stdc++.h>
using namespace std;
#define int long long int 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pi pair<int,int>
#define all(v) v.begin(),v.end()
#define zeros(arr) memset(arr,0,sizeof(arr));
#define precise(num)  cout<<fixed; cout << std::setprecision(num)
#define nl cout<<"\n";
#define test int t;cin>>t;while(t--) 
int check(int num ){
    
    int num1 = pow(num , 0.2);
    
    int ans = num1;
    
    num1 = pow(num1,5);
    
    if(num1 == num){
        return ans;
    }
    
    return 0;
}
int32_t main(){
    int n;
    cin>>n;
    int a[n+1];
    map<int,int>cn;
    
    for(int i   = 0 ; i < n ; i ++ ){
        cin>>a[i];
        cn[i-a[i]]++;
    }
    int res =0 ;
    for(int i  = 0 ; i < n ; i ++ ){
        res+=cn[i+a[i]];
    }
    cout<<res<<endl;
    
}

Measured memory_bytes: 27880
def get_next(sw_prev2,sw_prev1,ox_prev1):
    
    rev_ox = {"o":"x", "x":"o"}
    rev_sw = {"S":"W", "W":"S"}
    
    sw = sw_prev2
    if sw_prev1 == "W": ox_prev1 = rev_ox[ox_prev1]
    if ox_prev1 == "x": sw = rev_sw[sw]
    
    return sw

n = int(input())
ox = input()

for sw0,sw1 in [("S","S"),("S","W"),("W","S"),("W","W")]:
    ans = ""
    ans = sw0+sw1
    for i,oxi in enumerate(ox[1:]+ox[0],1):
        ans += get_next(ans[i-1],ans[i],oxi)
    
    if ans[0] == ans[-2] and ans[1] == ans[-1]:
        ans = ans[:-2]
        break
else:
    ans = -1

print(ans)

Measured memory_bytes: 3436
import fractions
A, B, C, D = map(int, input().split())

def lcm(C, D):
    return (C * D) // fractions.gcd(C, D)

def function(X):
    return X - X//C - X//D + X//lcm(C, D)

print(function(B) - function(A - 1))

Measured memory_bytes: 5048
#include <stdio.h>

int main() {
  int n,a[101],i,j,m;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&a[i]);
  int cnt=0;
  for(i=0; i<n; i++) {
    m=i;
    for(j=i+1; j<n; j++) {
      if(a[j]<a[m]) m=j;
    }
    if(a[i]>a[m]) {
      int tmp=a[i];
      a[i]=a[m];
      a[m]=tmp;
      cnt++;
    }
  }
  for(i=0; i<n; i++) {
    if(i) printf(" ");
    printf("%d",a[i]);
  }
  printf("\n%d\n",cnt);
  return 0;
}



Measured memory_bytes: 2056
//ITP1_6_B:   Finding Missing Cards
#include <stdio.h>
#include <stdbool.h>
int main(){
    int maisu, i, n;
    char ch;
    char marks[]={'S', 'H', 'C', 'D'};
    int aruka[4][13];
    int a,b;
    for (a=0;a<4;++a)
        for (b=0;b<14;++b)
            aruka[a][b] = 0;
    scanf("%d", &maisu);
    for (i=1; i<=maisu; i++){
        scanf("%c", &ch);
        scanf("%c %d", &ch, &n);
        n-=1;
        if     (ch=='S')aruka[0][n]=1;
        else if(ch=='H')aruka[1][n]=1;
        else if(ch=='C')aruka[2][n]=1;
        else if(ch=='D')aruka[3][n]=1;
    }
    for (a=1;a<=4;a++){
        for (b=1;b<=13;b++){
            if (aruka[a-1][b-1]!=1){
                printf("%c %d\n", marks[a-1], b);
            }
        }
    }
}



Measured memory_bytes: 1904
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main()
{
	string S, T;

	cin >> S >> T;

	map<char, char> dic_s;
	for (int ci = 0; ci < S.size(); ci++) {
		if (dic_s.count(S[ci]) == 0) {
			dic_s[S[ci]] = T[ci];
		}
		else {
			if (dic_s[S[ci]] != T[ci]) {
				cout << "No";
				return 0;
			}
		}
	}

	map<char, char> dic_t;
	for (int ci = 0; ci < T.size(); ci++) {
		if (dic_t.count(T[ci]) == 0) {
			dic_t[T[ci]] = S[ci];
		}
		else {
			if (dic_t[T[ci]] != S[ci]) {
				cout << "No";
				return 0;
			}
		}
	}


	cout << "Yes";

	return 0;
}



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

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

    string S;
    cin >> S;

    vector<int> v;
    char c_state = S.front();
    if(c_state == '0') v.emplace_back(0);
    int cnt = 0;
    for(int i = 0; i < S.size(); ++i){
        if(S[i] == c_state){
            ++cnt;
        }else{
            v.emplace_back(cnt);

            cnt = 1;
            c_state = S[i];
        }
    }
    v.emplace_back(cnt);

    if(S.back() == '0') v.emplace_back(0);

    int ans = accumulate(begin(v), begin(v)+min(2*K+1, static_cast<int>(v.size())), 0);
    int sum = ans;
    const auto max_iter = static_cast<int>(v.size())-2*K-1;
    for(int i = 2; i <= max_iter; i += 2){
        sum += v[i+2*K]+v[i+2*K-1]-v[i-1]-v[i-2];
        ans = max(sum, ans);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
  
  int N;
  cin >> N;
  
  long long ans = 0;
  
  for(int i=0; i<N; i++)
  {
    ans += i;
//    cout << ans << endl;
  }
  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    if(s[a-1] == '#' || s[b-1] == '#' || s[c-1] == '#' || s[d-1] == '#')
    {
        cout << "No";
        return 0;
    }
    else
    {
        int co = 0;
        FOR(i,min(a-1,b-1),max(c,d))
        {
            if(s[i] == '#' && s[i+1] == '#' && (c-1 > i || d-1 > i))
            {
                cout << "No";
                return 0;
            }
        }
        bool t = d < c;
        // cout << "t: " << t << endl;
        // cout << "a b c d: " << a << " " << b << " " << c << " " << d << endl;
        deque<int> ind;
        if(t)
        {
            FOR(i,min(a-1,b-1),max(c-2,d-2))
            {
                if(s[i] == '#')
                    co++;
                if(s[i+1] == '#')
                    co++;
                if(s[i+2] == '#')
                    co++;
                if(co == 0)
                {
                    ind.pb(i);
                }
                co = 0;
                // cout << "co = " << co << endl;
            }
            // cout << "made it here..." << endl;
            if(ind.size()==0)
            {
                cout << "No";
                return 0;
            }
            // cout << "made it here too..." << endl;
            // cout << ind << endl;
            F0R(i,ind.size())
            {
                if(!((d < c) && (d-1 < ind[i]+1 || b-1 > ind[i]+1)))
                {
                    cout << "Yes";
                    return 0;
                }
            }
            cout << "No";
            return 0;
        }
        cout << "Yes";
    }

    return 0;
}


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

void trace(int A[],int N) {
  for (int i=0; i<N; i++) {
    cout << ((i==0)?"":" ") << A[i] << flush;
  }
  cout << endl;
}
void insertionSort(int A[],int N) {
  for (int i=1; i<N; i++) {
    int v=A[i];
    int j=i-1;
    while (j>=0 && A[j]>v) {
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    trace(A,N);
  }
}
int main() {
  int N;
  cin >> N;
  int A[N];
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }
  trace(A,N);
  insertionSort(A,N);
  return 0;
}



Measured memory_bytes: 3084
#####segfunc######
def segfunc(a,b):
    while b:
        a, b = b, a % b
    return a

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2])

def update(k,x):
    k += num-1
    seg[k] = x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])

def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0

n = int(input())
a = list(map(int,input().split()))
#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num
init(a)

ans = -1
for i in range(n):
    ans = max(ans, segfunc(query(0,i), query(i+1, n)))
print(ans)



Measured memory_bytes: 64484
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;
 
template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)
 
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;
  
 
int main() {
    int D;
    ll G;
    cin >> D >> G;
    int P[10], C[10];
    rep(i,D) cin >> P[i] >> C[i];
 
    int res = INF;
    rep(bit, pow(2,D)) {
        int cnt = 0;
        int n = -1;
        ll score = 0;
        rep(i,D) {
            if (bit & (1<<i)) {
                score += 100*(i+1) * P[i] + C[i];
                cnt += P[i];
            }
            else {
                n = i;
            }
        }
 
        if (score < G) {
            ll s = 100*(n+1);
            int m = (G - score + s - 1) / s;
            if (m >= P[n]) continue;
            score += s * m;
            cnt += m;
        }
 
        res = min(res, cnt);
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 512
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x=s0()

ans=0
c=0
for s in x:
    if s=="T":
        if c==0:
            ans+=1
        else:
            c-=1
    else:
        c+=1
print(ans*2)

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

namespace ABC110B___1_Dimensional_World_s_Tale
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
            int n = line[0];
            int m = line[1];
            int x = line[2];
            int y = line[3];
            int[] lineX = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);
            int[] lineY = Array.ConvertAll(Console.ReadLine().Trim().Split(' '), int.Parse);

            for(int z = x + 1; z <= y; z++)
            {
                if (isNoWar(z, lineX, lineY))
                {
                    Console.WriteLine("No War");
                    return;
                }
            }

            Console.WriteLine("War");

        }

        static bool isNoWar(int z,int[] lineX, int[] lineY)
        {
            for (int i = 0; i < lineX.Count(); i++)
            {
                if (lineX[i] >= z){return false;}
            }

            for (int i = 0; i < lineY.Count(); i++)
            {
                if (lineY[i] < z) { return false;}

            }
            return true;
        }
    }

}


Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N; cin >> N;
    vector<ll> a(N); for(auto& in:a) cin >> in;
    ll two = 0,four = 0;
    for(int i = 0; i < N;i++){
        if(a[i]%4 == 0){
            four++;
            continue;
        }
        if(a[i]%2 == 0){
            two++;
            continue;
        }
    }
    if(four*2 + 1 >= N) return "Yes";
    if(four*2 + two >= N) return "Yes";
    return "No";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<ll>;
using vll = vector<vector<ll>>;
using pii = pair<int,int>;
#define FOR(i,a,b) for(ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1000000007;
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
int main(){
  string str;
  int a;
  priority_queue<int> q;
  while (cin >> str,str != "end") {
    if (str == "insert") {
      cin >> a;
      q.push(a);
    } else {
      cout << q.top() << endl;
      q.pop();
    }
  }
}


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

int main()
{
    int i,j,brk=0;
    string s;
    cin>>s;

    int a,b,c,l;
    l = s.size();
    a = (l-1)/2;
    a;
    b = (l+3)/2;
    b;
    if(l%2==0)
        cout<<"No\n";
    else
    {

        for(i = 0,j=l-1; i < l,j>=0; i++,j--)
        {
            if(s[i]!=s[j])
            {
                brk=1;
                break;
            }
        }
        if(brk==1)
            cout<<"No\n";
        else
        {
            for(i = 0,j=a-1; i < a,j>=0; i++,j--)
            {
                if(s[i]!=s[j])
                {
                    brk=1;
                    break;
                }
            }
            if(brk==1)
                cout<<"No\n";
            else
            {
                for(i = b-1,j=l-1; i<l,j>=b-1; i++,j--)
                {
                    if(s[i]!=s[j])
                    {
                        brk=1;
                        break;
                    }
                }
                if(brk==1)
                    cout<<"No\n";
                else
                    cout<<"Yes\n";
            }
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
int tot=0;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		tot+=s[i]-'0';
	}
	if(tot%9==0)
	{
		printf("Yes");
	}
	else
	{
		printf("No");
	}
}

Measured memory_bytes: 3760
from collections import Counter,defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

k,n = inpl()
a = inpl()
a.sort()
print(max(0, a[-1]*2 - k - 1))

Measured memory_bytes: 64876
N,M=map(int,input().split())
A=[]
B=[]
C=[]
D=[]
for i in range(N):
	x,y=map(int,input().split())
	A.append(x)
	B.append(y)
for i in range(M):
	x,y=map(int,input().split())
	C.append(x)
	D.append(y)
for i in range(N):
	ans=[]
	for j in range(M):
		tmp=abs(A[i]-C[j])+abs(B[i]-D[j])
		ans.append(tmp)
	T=len(ans)
	for k in range(T):
		if ans[k]==min(ans):
			print(k+1)
			break
	

Measured memory_bytes: 9252
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll sum=0;
	int n;
	cin>>n;
	vector<int> a;
	for(int i=0;i<n+1;i++)
	{
		int q;
		cin>>q;
		a.push_back(q);
	}
	vector<int> b;
	for(int i=0;i<n;i++)
	{
		int q;
		cin>>q;
		b.push_back(q);
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]>=b[i])
		{
			sum+=b[i];
			b[i]=0;
		}
		else
		{
			sum+=a[i];
			b[i]-=a[i];
			a[i]=0;
		}
		if(b[i]>0)
		{
			if(a[i+1]>=b[i])
			{
				sum+=b[i];
				a[i+1]-=b[i];
				b[i]=0;
			}
			else
			{
				sum+=a[i+1];
				b[i]-=a[i];
				a[i+1]=0;
			}
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1400
#include <stdio.h>

int main(){
    int d;

    scanf("%d", &d);

    switch(d){
        case 22:
            printf("Christmas Eve Eve Eve\n");
            break;

        case 23:
            printf("Christmas Eve Eve\n");
            break;
        
        case 24:
            printf("Christmas Eve\n");
            break;

        default:
            printf("Christmas\n");
    }

    return 0;
}

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

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

    int N; cin >> N;
    ll m; ll pa; ll pb;
    for(int i=0;i<N;i++){
        int a,b; cin >> a >> b;
        if(i==0) m = a+b;
        else{
            ll k = (m+pa+pb-1)/(pa+pb);
            ll l = max((pa*k+a-1)/a,(pb*k+b-1)/b);
            m = l*(a+b);
        }
        pa = a; pb = b;
    }
    cout << m;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    vi a(n);
    rep(i,0,n) cin >> a[i];
    int j=0;
    rep(i,1,n) if(a[i]<a[j]) j = i;
    int best=n;
    for(int i=max(0,j-k+1); i<=j; ++i) {
        int num=1+((i+k-2)/(k-1))+(n-(i+k)+k-2)/(k-1);
        best=min(best,num);
    }
    cout << best << "\n";
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>


int main(void){

    int X = 0;
    int d_X = 0.0;
    int flag = 0;
    int i = 0;

    scanf("%d", &X);

    while (flag == 0){

        d_X = sqrt((double)X);

        if (X == 2){
            flag = 1;

        } else {

            if (X % 2 == 0){
                X++;

            } else {

                for (i = 3; i <= (int)d_X; i = i + 2){
                    //printf("%d\n", i);
                    //printf("%d\n", X);
                    //printf("%d\n", X % i);


                    if (X % i == 0){
                        X++;
                        break;

                    } 
                }
                if (i >= (int)d_X){
                    flag = 1;
                }   
            }
        }
    }
    printf("%d", X);

    return 0;
}

Measured memory_bytes: 128