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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int N;
vll H;

int main(int argc, char** argv) {
  cin >> N;
  H.resize(N);

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

  int ret = 0;
  int count = 0;
  for (int i=0; i<N-1; i++) {
    if (H[i] >= H[i+1]) {
      count++;
    } else {
      ret = max({ret, count});
      count = 0;
    }
  }

  ret = max({ret, count});
  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
    // 変数宣言
    char s[6];
    int comp3_4 = 0;
    int comp5_6 = 0;
    char result[4] = "No";
    char *p_result = result;
    int i;

    for( i = 0; i < 6 ; i++ ){
        s[i] = 0;
    }

    // 入力処理
    scanf( "%s", s );

    // 3文字目・4文字目の比較
    if( s[2] == s[3] ){
        comp3_4 = 1;
    }

    // 5文字目・6文字目の比較
    if( s[4] == s[5] ){
        comp5_6 = 1;
    }

    // 結果判定
    if( comp3_4 == 1 && comp5_6 == 1 ){
        p_result = "Yes";
    }

    // 出力
    printf( "%s\n", p_result );

    return 0;
}

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

#pragma GCC optimize ("-O2")
#define ll long long
#define tr(container, it) for(auto it = container.begin(); it != container.end(); it++)
#define testcase(t) int t;cin>>t;while(t--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define what_is(x)  cerr << #x << " is " << x << endl;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))

const int LIM=1e5+5,MOD=1e9+7;

int main(){

	IOS;

	ll n;
	cin>>n;
	ll ans=0;

	ans+=(n/500 * 1000);
	n%=500;
	ans+=(n/5 * 5);
	cout<<ans<<endl;

	






	return 0;
}
 










Measured memory_bytes: 256
def d(u):
 global t
 C[u]=0;D[u]=t;t+=1
 for v in M[u]:
  v=int(v)-1
  if C[v]:d(v)
 F[u]=t;t+=1
N=int(input());R=range(N)
M=[input().split()[2:]for _ in R]
C,D,F=[1]*N,[0]*N,[0]*N
t=1
for i in R:
 if C[i]:d(i)
for i in R:print(i+1,D[i],F[i])


Measured memory_bytes: 5720
#include<iostream>
#include "algorithm"
#include "bits/stdc++.h"
#define ll long long
using namespace std ;
int m[1000000];
int main(){
    int n;
    cin>>n;
    for(int a=1;a<=105;a++){
        for(int b=1;b<=105;b++){
            for(int c=1;c<=105;c++){
                int sum=a*a+b*b+c*c+a*b+b*c+a*c;
                if(sum<=10000)
                m[sum]++;
            }
        }
    }
    for(int i=1;i<=n;i++)
        cout<<m[i]<<endl;
    return 0;
}

Measured memory_bytes: 3556
l = list(map(int, input().split()))

x = max(l)

y = min(l)
z = x%y

if z == 0:
  z = x

else:
  while x%y > 0:
    z = x%y
    if y > z :
      x = y
      y = z
    else:
      x = z

print(z)


Measured memory_bytes: 5592
from collections import deque
import sys


x, y, a, b, c = map(int, input().split())
pa = list(map(int, input().split())) + [-1]
pb = list(map(int, input().split())) + [-1]
r = list(map(int, input().split())) + [-1]

pa = [(pa[i], 0) for i in range(a)]
pb = [(pb[i], 1) for i in range(b)]
r = [(r[i], 2) for i in range(c)]
q = sorted(pa + pb + r)
cnt0 = 0
cnt1 = 0

ans = 0
cnt = 0
for i in range(len(q))[::-1]:
    if cnt == x + y:
        break
    num, col = q[i]
    if col == 0:
        if cnt0 < x:
            cnt0 += 1
            ans += num
            cnt += 1
    elif col == 1:
        if cnt1 < y:
            cnt1 += 1
            ans += num
            cnt += 1
    else:
        ans += num
        cnt += 1
print(ans)

Measured memory_bytes: 121452
#include <iostream>
#include <string>

void solve() {
    int n;
    std::cin >> n;

    std::string s(n, '0');
    for (auto& c : s) {
        int a, b;
        std::cin >> a >> b;
        if (a == b) c = '1';
    }

    for (int i = 0; i + 3 <= n; ++i) {
        if (s.substr(i, 3) == "111") {
            std::cout << "Yes\n";
            return;
        }
    }

    std::cout << "No\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;

struct Dise
{
    public int D1 { set; get; }
    public int D2 { set; get; }
    public int D3 { set; get; }
    public int D4 { set; get; }
    public int D5 { set; get; }
    public int D6 { set; get; }
    public char[] Order { set; get; }
}


class Program
{
    static void Main(string[] args)
    {
        int n = 1;  //サイコロの個数、今回は1つだが次はこの個数を任意にする
        var dise = new Dise[n];   //サイコロの情報を持Aつ変数
        for (int i = 0; i < n; i++)
        {
            string[] input = Console.ReadLine().Split(' ');  //サイコロの目
            string orderstr = Console.ReadLine();
            char[] order = orderstr.ToCharArray();   //オーダーの入った配列

            dise[i].D1 = int.Parse(input[0]);
            dise[i].D2 = int.Parse(input[1]);
            dise[i].D3 = int.Parse(input[2]);
            dise[i].D4 = int.Parse(input[3]);
            dise[i].D5 = int.Parse(input[4]);
            dise[i].D6 = int.Parse(input[5]);
            dise[i].Order = order;
        }

        for (int i = 0; i < n; i++)
        {
            for (int k = 0; k < dise[i].Order.Length; k++)
            {
                int a, b;              
                switch (dise[i].Order[k])
                {
                    case 'N':
                        a = dise[i].D1;
                        b = dise[i].D6;
                        dise[i].D1 = dise[i].D2;
                        dise[i].D2 = b;
                        dise[i].D6 = dise[i].D5;
                        dise[i].D5 = a;
                        break;
                    case 'E':
                        a = dise[i].D1;
                        b = dise[i].D6;
                        dise[i].D6 = dise[i].D3;
                        dise[i].D1 = dise[i].D4;
                        dise[i].D3 = a;
                        dise[i].D4 = b;
                        break;
                    case 'S':
                        a = dise[i].D1;
                        dise[i].D1 = dise[i].D5;
                        dise[i].D5 = dise[i].D6;
                        dise[i].D6 = dise[i].D2;
                        dise[i].D2 = a;
                        break;
                    case 'W':
                        a = dise[i].D4;
                        b = dise[i].D3;
                        dise[i].D4 = dise[i].D1;                      
                        dise[i].D3 = dise[i].D6;
                        dise[i].D6 = a;
                        dise[i].D1 = b;
                        break;
                }
            }

        }
      
        foreach (var s in dise)
        {
            Console.WriteLine(s.D1);
        }
    }
}


Measured memory_bytes: 19980
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	private static final FastIn in = new FastIn();
	private static final PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		Solver sol = new Solver();
		sol.solve();
		out.close();
	}
	private static final class Solver {
		public void solve() {
			char[] s = in.next().toCharArray();
			int n = s.length;
			for (int i = 0; i < n - 1; ++i) {
				if (s[i] == s[i + 1]) {
					out.println((i + 1) + " " + (i + 2));
					return;
				}
			}
			for (int i = 0; i < n - 2; ++i) {
				if (s[i] == s[i + 2]) {
					out.println((i + 1) + " " + (i + 3));
					return;
				}
			}
			out.println("-1 -1");
		}
	}
	private static final class FastIn {
		private BufferedReader br;
		private StringTokenizer st;
		public FastIn() {
			br = new BufferedReader(new InputStreamReader(System.in), 1 << 20);
			st = null;
		}
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


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

int main(void){
    int ans=0,i,j,p,q,s[10000],t[500];
    cin>>p;
    for(i=0;i<p;i++)cin>>s[i];
    cin>>q;
    for(i=0;i<q;i++)cin>>t[i];
    
    for(i=0;i<q;i++){
        for(j=0;j<p;j++){
            if(t[i]==s[j]){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define mod 1000000007
#define MN 405
long long f[MN][MN],pw[MN][MN],qz[MN][MN];
int n,c,a[MN],b[MN];
void add(long long &x,long long y){x+=y;if(x>mod)x-=mod;}
long long Abs(long long x){if(x<0) x+=mod;return x;}
int main(){
	register int i,j,k;
	for(i=1;i<=400;i++) pw[i][0]=1;
	
	for(i=1;i<=400;i++)for(j=1;j<=400;j++) pw[i][j]=(pw[i][j-1]*i)%mod;
	for(i=1;i<=400;i++)for(j=0;j<=400;j++) qz[i][j]=(qz[i-1][j]+pw[i][j])%mod;
	
	n=read(),c=read();
	for(i=1;i<=n;i++) a[i]=read();
	for(i=1;i<=n;i++) b[i]=read();
	
	f[0][0]=1;
	
	for(i=1;i<=n;i++)for(j=0;j<=c;j++)for(k=j;k>=0;k--){
		add(f[i][j],f[i-1][k]*Abs(qz[b[i]][j-k]-qz[a[i]-1][j-k])%mod);
	}
	printf("%lld\n",f[n][c]);
	return 0;
}

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

namespace ConsoleApplication46
{
    class Program
    {
        static bool PrimeNumbers(int a)
        {
            for (int b = 3; ; b++)
            {
                if (a % b == 0) return false;
                if ((b + 1) * (b + 1) > a) return true;
            }
        }
        static void Main()
        {
            while (true)
            {
                int a = int.Parse(Console.ReadLine()), l = 5;
                if (a == 1) { l = 2;goto k; }
                if (a == 2) { l = 5;goto k; }
                if (a == 0) break;int s = 2;
                for(int b = 5; a >s;b+=2)
                {
                    if (PrimeNumbers(b)) { s++;l += b; }
                   
                }
            k:;    Console.WriteLine(l);
            }
        }
    }
}

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

int main(){
    int a,b;
    char op;
    
    while(1){
        cin>>a>>op>>b;
        if(op=='?')break;
        
        if(op=='+')cout<<a+b<<endl;
        else if(op=='-')cout<<a-b<<endl;
        else if(op=='*')cout<<a*b<<endl;
        else if(op=='/')cout<<a/b<<endl;
    }
    return 0;
}


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

#define int long long

#define pb push_back
#define mp make_pair
#define st first
#define nd second
typedef pair < int , int > pp;
const int mod = 1e9 + 7;
const int N   = 5e3 + 3;

vector < int > V[N];

int sz[N],Cen,T[N],t,M[N],MM[N],C[N][N],fa[N],n,x,y,i,j,k,s,ans;

void f(int x){
    sz[x] = 1;
    int h=1;
    for(int y, i=0; i<V[x].size(); i++)
        if(!sz[ y = V[x][i] ]){
            f(y);
            sz[x] += sz[y];
            if(sz[y] > n/2) h=0;
        }
    if(h && n-sz[x] <= n/2) Cen = x;
}

void g(){
    memset(M , 0 , sizeof M);
    M[0] = 1;
    s = 0;
    for(i=1;i<=t;i++){
        memset(MM , 0 , sizeof MM);
        for(j=0;j<=T[i];j++)
            for(k=0;k<=s;k++)
                MM[j+k] = (MM[j+k] + C[ T[i] ][j] * C[ T[i] ][j] % mod * fa[j] % mod * M[k]) % mod;
    
        s += T[i];
        for(j=0;j<=s;j++) M[j] = MM[j];
    }
    
    for(i=0;i<=s;i++) 
        ans = (ans + (i&1 ? -1 : 1) * fa[s-i] * M[i]) % mod;
}

signed main(){
    cin >> n;
    for(fa[0]=C[0][0]=i=1;i<=n;i++){
        fa[i] = fa[i-1] * i % mod; 
        for(C[i][0]=j=1;j<=i;j++)
            C[i][j] = (C[i-1][j-1] + C[i-1][j]) % mod;
    }
    for(i=2;i<=n;i++){
        cin >> x >> y;
        V[x].pb(y); V[y].pb(x);
    }
    f(1);
    x = Cen;
    for(i=0;i<V[x].size();i++){
        if(sz[x] < sz[ y = V[x][i] ]) T[++t] = n - sz[x];
        else T[++t] = sz[y];
    }
    
    g();
    T[++t] = 1;
    g();
    cout << (ans + mod) % mod;
    return 0;
}

Measured memory_bytes: 194560
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列



#define REP(i,m,n) for(int i = (int) (m);i < (int) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//提出コード↓

string s;
string ans = "Yes";



int main() {
	cin >> s;
	rep(i, s.size()) {
		
		if (s.size() % 2 == 1) {
			ans = "No";
			break;
		}



		if (i % 2 == 0) {
			if(s[i] == 'h'){}
			else {
				ans = "No";
				break;
			}
		}
		else {
			if(s[i] == 'i'){}
			else {
				ans = "No";
				break;
			}
		}
	}
	cout << ans << endl;



	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main()
{
  char  o[51], e[51], m[102];
  int  i, j;

  scanf("%s", o);
  scanf("%s", e);

  for(i=0; i<51; i++){
    m[i*2] = o[i];
    m[i*2+1] = e[i];
  }
  
  printf("%s\n", m);

  return 0;
}

Measured memory_bytes: 128
#import pysnooper
#import os,re,sys,operator,math,heapq,string
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)
input=stdin.readline

n,x=map(int,input().rstrip().split())
a=list(map(int,input().split()))
ans=0
if a[0]>x:
    ans+=a[0]-x
    a[0]=x
for i in range(0,n-1):
    if a[i]+a[i+1]>x:
        ans+=a[i]+a[i+1]-x
        a[i+1]-=a[i+1]+a[i]-x
print(ans)

Measured memory_bytes: 14516
#include <iostream>
#include <map>

using namespace std;
long long n,k,x,maxi;
long long s[200005];
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(int i=k;i<=n;i++)
    {
        maxi=max(maxi, s[i]-s[i-k]);
    }
    double ans=(double)(maxi+k)/2;
    cout.precision(12);
    cout<<fixed<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<ll> vl;
typedef queue<int> qi;
typedef queue<ll> ql;
typedef pair<ll,ll> pll;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
#define rep(i,n) for (int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define pf push_front
#define F first
#define S second
#define INF 2000000009

int main()
{
    ios::sync_with_stdio(false);
    int n,m,k;
    cin>>n>>m>>k;
    for (int i=0;i<=n;i++){
    	for (int j=0;j<=m;j++){
    		if (i*m+j*n-i*j*2==k){
    			cout<<"Yes";
    			return 0;
    		}
    	}
    }
    cout<<"No";
    return 0;
}

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

#define ll long long

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  
  vector<ll> X(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i];
  }
  
  ll ans = 0;
  
  for (int i = 0; i < N-1; i++) {
    if ((X[i+1] - X[i]) * A < B) {
      ans += (X[i+1] - X[i]) * A;
    } else {
      ans += B;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define ts cout<<"ok"<<endl
#define oo (1e18)
#define ll long long
#define LL unsigned long long
#define hh puts("")
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
using namespace std;
bitset<4000005> bt;
int n,sum;
inline int read(){
    int ret=0,ff=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-') ff=-1;ch=getchar();}
    while(isdigit(ch)){ret=(ret<<3)+(ret<<1)+(ch^48);ch=getchar();}
    return ret*ff;
}
signed main(){
	n=read();
	bt[0]=1;//bt[i]表示i能否被构造 
	for(int i=1;i<=n;i++){
		int x=read();
		bt|=bt<<x;//整体转移 
		sum+=x;
	}
	//对于一个值x能被构造,那么s-x也能被构造,所以这个序列左右对称
	//因此扫描答案从中间开始 
	for(int i=(sum+1)>>1;i<=sum;i++)
		if(bt[i]){
			printf("%d",i);
			break;
		}
    return 0;
}

Measured memory_bytes: 1664
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int d = 0;
  for (int n = a; n <= b; ++n) {
    if (c % n == 0)
      d++;
  }
  cout << d << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  long long x,y,cnt=2;
  int ans=1;
  cin>>x>>y;
  while (x*cnt<=y) {
    cnt*=2;
    ans+=1;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200001
ll t1[N << 2], t2[N << 2];
vector<pair<int, int> > a[N];
void up(int x, int L, int R, int l, int r, ll c) {
    if (l <= L && R <= r) return (void)(t1[x] += c, t2[x] += c);
    int mid = (L + R) >> 1;
    if (l <= mid) up(x << 1, L, mid, l, r, c);
    if (r > mid) up(x << 1 | 1, mid + 1, R, l, r, c);
    t1[x] = max(t1[x << 1], t1[x << 1 | 1]) + t2[x];
}
int n, m;
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1, x, y, z; i <= m; i++) {
        scanf("%d%d%d", &x, &y, &z);
        a[y].push_back(make_pair(x, z));
    }
    for (int i = 1; i <= n; i++) {
        up(1, 1, n, i, i, t1[1]);
        for (auto &it : a[i]) up(1, 1, n, it.first, i, it.second);
    }
    printf("%lld\n", max(t1[1], 0ll));
    return 0;
}

Measured memory_bytes: 22912
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s,t,u;
	int a,b;
	cin>>s>>t>>a>>b>>u;

	if (s==u)
	{
		cout<<a-1<<" "<<b;
	}else{
		cout<<a<<" "<<b-1;
	}
	
}

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

#define sc(x) scanf("%d",&x);
#define rep(x ,n) for(int x=0; x<n; x++)
#define ll long long
#define finish(x) return cout << x << endl,0;
#define scarr(a,n) for(int x=0; x<n; x++)scanf("%d",&a[x]);

int l ,r;
int cnt[2019];

int main()
{
    cin >> l >> r;
    for(int i=l; i<=min(l+5000 ,r); i++)
        cnt[i%2019]++;

    int ans = 1e9;
    for(int i=0; i<2019; i++)
    for(int j=0; j<2019; j++){
        if(i == j && cnt[i] >= 2)
            ans = min(ans ,i*j%2019);
        if(i!=j && cnt[i] && cnt[j])
            ans = min(ans ,i*j%2019);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#require 'pp'

n = gets.chomp!.to_i
x_n = gets.chomp!.split(" ").map(&:to_i)
y_n = x_n.sort

left = y_n[y_n.length / 2 - 1]
right = y_n[y_n.length / 2]

x_n.each do |x|
    if x <= left
        puts right
    else
        puts left
    end
end


Measured memory_bytes: 23752
n=int(input())
a=list(map(int,input().split()))
lst=[0]*8
num=0
for i in range(n):
  if 3200<=a[i]:
    num+=1
  for j in range(8):
    if 400*j<=a[i]<400*(j+1):
      if lst[j]==0:
        lst[j]+=1

print(*[max(1,sum(lst)),sum(lst)+num])
      
    


Measured memory_bytes: 38256
def c_divide_the_problems(N, D):
    D.sort()
    abc_max, arc_min = D[N // 2 - 1], D[N // 2]  # [abc_max + 1, arc_min] が整数の区間
    return arc_min - abc_max if arc_min > abc_max else 0

N = int(input())
D = [int(i) for i in input().split()]
print(c_divide_the_problems(N, D))

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

using namespace std;

int main() {
    long long int N, W;
    cin>>N>>W;
    vector<long long int> val, wei;
    for(long long int i=0;i<N;i++) {
        long long int w, v;
        cin>>w>>v;
        val.push_back(v);
        wei.push_back(w);
    }

    long long int t[N+1][W+1];
    memset(t, 0 ,sizeof(t));

    // val, wei, W

    for(long long int i=0;i<=N;i++) {
        for(long long int w=0;w<=W;w++) {
            if(i==0 || w==0) t[i][w]=0;
            else if(wei[i-1]<=w) {
                t[i][w] = max(t[i-1][w], t[i-1][w-wei[i-1]]+val[i-1]);
            }
            else 
                t[i][w] = t[i-1][w];
        }
    }

    cout<< t[N][W];
}

Measured memory_bytes: 82336
for i in range(100):
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    #print(h*w)
    #print(h)
    #print(w)
    else:
        for j in range(1,2):
            for k in range(1,w):
                print('#',end='')
            print('#')
        for l in range(2,h):
            print('#',end='')
            for n in range(2,w):
                print('.',end='')
            print('#')
        for m in range(h,h+1):
            for n in range(1,w):
                print('#',end='')
            print('#')
    print('')




Measured memory_bytes: 7000
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int n;cin>>n;
	int k;cin>>k;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	{
	    cin>>h[i];
	}
	vector<long long int> dp(n,INT_MAX);
	dp[0]=0;
	for(int i=1;i<n;i++)
	{
	    int j=max(0,i-k);
	    while(j<i)
	    {
	        dp[i]=min(dp[i],dp[j]+(long long int)abs(h[i]-h[j]));
	        j++;
	    } 
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=998244353;
const int mod=998244353;
int main(){
    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    cout<<min((n-1)/a*b+b,(n-1)/c*d+d)<<endl;
}


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

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

	int S,W;
	cin>>S>>W;

	if(W>=S)
		cout<<"unsafe"<<endl;
	else
		cout<<"safe"<<endl;

	return 0;
}

Measured memory_bytes: 3640
import math
N = int(input())
ARR = list(map(int,input().split()))

def calculate(n, arr):

    a1 = math.floor(sum(arr)/n)
    a2 = math.ceil(sum(arr)/n)

    result1 = 0
    result2 = 0
    for i in range(n):
        result1 += pow(arr[i] - a1,2)
        result2 += pow(arr[i] - a2,2)

    print(min(result1,result2))


calculate(N, ARR)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  string s; cin >> s;
  int n = s.size();

  V<> prv(n);
  for (int i = 0; i < n; ++i) {
    prv[i] = s[i] == 'R' ? i : prv[i - 1];
  }
  V<> nxt(n);
  for (int i = n - 1; i >= 0; --i) {
    nxt[i] = s[i] == 'L' ? i : nxt[i + 1];
  }

  V<> res(n);
  for (int i = 0; i < n; ++i) {
    if (s[i] == 'R') {
      ++res[nxt[i] - (nxt[i] - i & 1)];
    } else {
      ++res[prv[i] + (i - prv[i] & 1)];
    }
  }

  for (int i = 0; i < n; ++i) {
    cout << res[i] << " \n"[!(n + ~i)];
  }
}

Measured memory_bytes: 1872
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    string S;
    if (n == 0) {cout << 0 << endl; return 0;}
    int cnt = 0;
    while(n != 0) {
        if(cnt % 2 == 0) {
            if((n + INF) % 2 == 1) S = "1" + S;
            else S = "0" + S;
            n -= (n + INF) % 2;
            n /= 2;
        } else {
            if((n + INF) % 2 == 1) S = "1" + S;
            else S = "0" + S;
            n += (n + INF) % 2;
            n /= 2;
        }
        cnt++;
        //cout << S << " " << cnt << endl;
    }
    cout << S << endl;



    return 0;
}
// -1
// 

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

using i64 = int64_t;

const double EPS = 1e-9;

using Point = complex<double>;

double dot(const Point &a, const Point &b) { return real(conj(a) * b); }

double calc(Point a, Point b, Point c){
    double theta = acos(dot(a-b, c-b) / (abs(a-b)*abs(c-b)));
    double phi = acos(dot(a-c, b-c) / (abs(a-c)*abs(b-c)));
    return (tan(theta/2)*tan(phi/2)*abs(c-b))/(2*tan(theta/2)*tan(phi/2)+tan(theta/2)+tan(phi/2));
}

int main(){
    double x1, y1, x2, y2, x3, y3;
    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
    Point a(x1, y1), b(x2, y2), c(x3,y3);
    double ans = max({calc(a,b,c), calc(c,a,b), calc(b,c,a)});
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 768
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 200005;
const int MAXM = 1000005;
const int MOD = 1000000007;
const int MAMOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
#define endl "\n"
#define de(x) cout<<#x<<"="<<x<<endl

int main()
{
    ll x, ret = 0;
    cin >> x;
    ret += x / 500 * 1000;
    x %= 500;
    ret += x / 5 * 5;
    x %= 5;
    cout << ret << endl;
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int table[10][10] = {};
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        table[a][b] = 1;
        table[b][a] = 1;
    }

    vector<int> path(n);
    for (int i = 0; i < n; ++i) {
        path[i] = i+1;
    }
    int ans = 0;
    do {
        bool flag = true;
        for (int i = 0; i < n-1; ++i) {
            if (table[path[i]][path[i + 1]] == 0) flag = false;
        }
        if (flag) ans++;
    } while(next_permutation(path.begin()+1, path.end()));

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import heapq
from decimal import Decimal

input = sys.stdin.readline
a, b, c = map(str, input().split())

root_a = Decimal(a)**Decimal('0.5')
root_b = Decimal(b)**Decimal('0.5')
root_c = Decimal(c)**Decimal('0.5')


if root_a + root_b < root_c:
    print("Yes")
else:
    print("No")

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

int main(){
  ll h, w, k;
  cin>>h>>w>>k;
  char g[h][w];
  for(ll i=0; i<h; i++){
    for(ll j=0; j<w; j++){
      cin>>g[i][j];
    }
  }
  ll ans =0;
  ll black;
  for(ll mr=0; mr< (1<<h); mr++){ //maskR mr
    for(ll mc=0; mc< (1<<w); mc++){ // maskC mc
      black=0;
      for(ll i=0; i<h; i++){
        for(ll j=0; j<w; j++){
          if(( (mr&(1<<i)) == 0) && ( (mc&(1<<j)) == 0) ){
            if(g[i][j]=='#'){
              black++;
            }
          }
        }
      }
      if(black ==k)ans++;
    }
  }
  cout<<ans<<"\n";

  return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,c,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>a>>b>>c;

    mx = max(a,max(b,c));

    for(int i=mx;;i++){
        cur = ((i-a)&1)+((i-b)&1)+((i-c)&1);
        if(cur&1)continue;
        cout<<((i*3-(a+b+c))>>1)<<"\n";
        break;
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b){
if(a<b){return gcd(b,a);}
else if(a%b){return gcd(b,a%b);}
else{return b;}
}
int main(){
  ll N;
  cin>>N;
  if(N<=999)
  cout<<"ABC"<<endl;
  if(N>=1000)
  cout<<"ABD"<<endl;
    }
  
  
  
  

  
  

 


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>

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

int main()
{
    int n;
    vi ans;

    cin >> n;
    if (n == 0)
    {
        cout << 0 << endl;
        return 0;
    }
    while (1)
    {
        if (n == 0)
            break;
        int r = n % -2;
        n /= -2;
        ans.push_back(abs(r));
        if (r == -1)
            n++;
    }
    for (int i = ans.size() - 1; i >= 0; i--)
    {
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;

int main() {
    int n, total=0;
    cin >> n;
    for (int i=1; i<=n; i++) {
        if ((int(log10(i))+1) % 2) {
            total++;
        }
    }
    cout << total;
}

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

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

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

    P h[M];
    for(int i=0; i<M; i++){
        int a, b;
        cin >> a >> b;
        h[i] = make_pair(b, a);
    }

    sort(h, h+M);

    int ans = 0;
    int pos = -1;
    for(int i=0; i<M; i++){
        int l = h[i].second;
        int r = h[i].first;
        if(!(pos>l && pos<=r)){
            ans++;
            pos = r;
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
  char deck[200 + 1];
  char tmp[2][200 + 1];
  int len;
  int m, h, i;

  while (1) {
    scanf("%s", deck);
    if (!strcmp(deck, "-")) break;
    len = strlen(deck);

    scanf("%d", &m);

    for (i = 0; i < m; i++) {
      scanf("%d", &h);
      
      strncpy(tmp[0], deck, h);
      tmp[0][h] = '\0';
      strcpy(tmp[1], &deck[h]);
      
      strcpy(deck, tmp[1]);
      strcpy(&deck[len - h], tmp[0]);
    }
    printf("%s\n", deck);
  }

  return 0;
}

Measured memory_bytes: 596
#![allow(non_snake_case, unused_mut)]
#![allow(unused_imports)]
use proconio::{fastout, input, marker::*};
//use petgraph::unionfind::UnionFind;
use std::collections::*;

const MOD: i64 = 1_000_000_000 + 7;

#[fastout()]
fn main() {
    input! {
        n:usize,k:usize
    }
    // n-1 <=k のように、kが十分大きければ、全パターン。
    // すなわち n人と仕切りn-1で組み合わせなので、2n-1 choose n-1
    let mut fact = vec![1i64; n + 1];
    let mut ifact = vec![1i64; n + 1];
    for i in 1..=n as usize {
        fact[i] = fact[i - 1] * (i as i64) % MOD;
        ifact[i] = modInv(fact[i]);
    }
    let choose = |n, r| fact[n] * ifact[n - r] % MOD * ifact[r] % MOD;
    //if n - 1 <= k {
    //    let ans: i64 = choose(2 * n - 1, n - 1);
    //    println!("{}", ans);
    //    return;
    //}
    // k < n-1 の時は、0人の部屋の数を i とすると、0の位置がchoose(n,i)
    // i人がn-i個の部屋に分散したと考えるとその分け方は、H(n-i,i) =　choose(n-i+i-1,n-i-1)
    let mut ans = 0;
    for i in 0..=std::cmp::min(k, n - 1) {
        let tmp = choose(n, i) * choose(n - 1, n - i - 1) % MOD;
        //println!("i={}, choose={}", i, tmp);
        ans = (ans + tmp) % MOD;
    }
    println!("{}", ans);
}

fn modPow(x: i64, a: i64) -> i64 {
    if a == 0 {
        1
    } else {
        if a % 2 != 0 {
            modPow(x, a - 1) * x % MOD
        } else {
            let y = modPow(x, a / 2);
            y * y % MOD
        }
    }
}
fn modInv(x: i64) -> i64 {
    modPow(x, MOD - 2) % MOD
}


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

using namespace std;

#define ll long long
#define fi first
#define se second

void test_case(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	vector<ll> arr(n);
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	sort(arr.rbegin(),arr.rend());
	ll res=0,cnt=0;
	for(int i=0;i<n;i++){
		if(cnt>=k){
			res+=arr[i];
		}
		else
			cnt++;
	}
	printf("%lld",res);

}

int main(){
	int t=1;
	//scanf("%d",&t);
	
	while(t--)
		test_case();

}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll prime=1e9+7;
int main(){
  ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h,w;
    cin>>h>>w;
    int mat[h+1][w+1];
    for(int i=0;i<h+1;i++){
    for(int j=0;j<w+1;j++){
    mat[i][j]=0;}}
    for(int i=0;i<h;i++){
    string s;
    cin>>s;
    for(int j=0;j<w;j++){
    if(s[j]=='.')
    mat[i][j]=1;

    }

    }
    mat[h-1][w-1]=1;
for(int i=h-1;i>=0;i--){
for(int j=w-1;j>=0;j--){
if(i==(h-1) && (j==(w-1)))
continue;
if(!mat[i][j])
continue;
ll ab=mat[i+1][j];
ab+=mat[i][j+1];
ab%=prime;
mat[i][j]=ab;
}

}
cout<<mat[0][0];
    return 0;}


Measured memory_bytes: 7528
#include<iostream>
using namespace std;
int main(){
  int t,n,h[101],up[101],down[101],dammy;
  cin >> t;
  
      for(int i=0;i<t;i++){
	cin >> n;
	up[i]=0;
	down[i]=0;
	for(int j=0;j<n;j++){
	  cin >>h[j];}
	for(int k=1;k<n;k++)
	    if(h[k-1]<h[k]){
	      dammy=h[k]-h[k-1];
	      if(dammy>up[i]){
		up[i]=h[k]-h[k-1];}}

	    
	    else if(h[k-1]>h[k]){
	      dammy=h[k-1]-h[k];
	      if(dammy>down[i]){
		down[i]=h[k-1]-h[k];}}
	  
     
      }
	

	  for(int i=0;i<t;i++){
	    cout << up[i] << " " << down[i] << endl;
	  }

	  return 0;

}	

    

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

int main(){
  int n;
  double sum1=1,sum2=0;
  cin >> n;
  vector<double> v(n,0);
  r(i,n)cin >> v.at(i);
  r(i,n)sum1*=v.at(i);
  r(i,n)sum2+=sum1/v.at(i);
  printf("%.8lf\n",sum1/sum2);
}

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

int main() {
  string s, key = "keyence";
  cin >> s;

  int n = s.size(), i = 0, j = n - 1, now = 0, back = 6;

  while (s[i] == key[now]) {
    if (now == 6) {
      cout << "YES" << endl;
      return 0;
    } else {
      i++;
      now++;
    }
  }

  if (s.substr(n - 7 + i) == key.substr(now))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	a, b := scanInt(sc), scanInt(sc)
	mi, ma := min(a, b), max(a, b)
	fmt.Println(strings.Repeat(fmt.Sprintf("%d", mi), ma))
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


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

const ULL M = 998244353;

int main() {
    int N, K; cin >> N >> K;
    int I[10][2]; rep(i, K) rep(j, 2) cin >> I[i][j];
    ULL dp[400001] = {}; dp[0] = 1; dp[1] = M - 1;
    rep(i, N - 1) {
        rep(k, K) {
            dp[i + I[k][0]] += dp[i];
            dp[i + I[k][1] + 1] += M - dp[i];
        }
        dp[i + 1] += dp[i];
        dp[i + 1] %= M;
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 6748
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define reps(i,a,b) for(int i=a;i<b;++i)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    rep(i, t) cin >> a[i];
    int mx = *max_element(all(a));
    int sum = accumulate(all(a), 0) - mx;
    cout << max(0, mx - sum - 1) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

int main(int argc, char const *argv[])
{
    int use[26] = {};
    string s;
    cin >> s;
    
    int ans = INT_MAX;
    int cnt;
    int num;

    for (int i = 0; i < 26; i++)
    {
        char ch = i + 'a';
        num = 0;
        cnt = 0;
        for (int j = 0; j < s.size(); j++)
        {
            if (s[j] == ch)
            {
                num = max(num, cnt);
                cnt = 0;
            }else
            {
                cnt++;
            }
            
        }
        num = max(num, cnt);
        ans = min(ans, num);
        
    }
    

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>

#define ll long long
#define uint unsigned int
#define ull unsigned ll


using namespace std;
const ll MAXN = 2e9+2;
const ll SIZE = 2e5+10;


int main(){
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		int x; cin >> x;
		if(x >= k)
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}
// 1 | 2 3 | 4
// 1 2 | 3 4 | 5 6
// 1 2 3 | 4 5 6 7 | 8 9 10
// A B C   D E F G   H J K

Measured memory_bytes: 256
def main():
    t = int(input())
    for _ in range(t):
        n, a, s, m = int(input()), list(map(int, input().split())), input(), []
        for i in range(n-1, -1, -1):
            ans = a[i]
            for j in m:
                ans = min(ans, ans ^ j)
            if s[i] == "0":
                if ans:
                    m.append(ans)
            else:
                if ans:
                    print(1)
                    break
        else:
            print(0)


main()

Measured memory_bytes: 9240
# -*- coding: utf-8 -*-
"""
Set - Set: Search
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_7_A&lang=jp

"""
s = set()
for _ in range(int(input())):
    q, x = input().split()
    if q == '0':
        s.add(x)
        print(len(s))
    else:
        print(int(x in s))



Measured memory_bytes: 27460
//# define FLAG
///delet....................................
# include   <bits/stdc++.h>
using namespace std;
# define    VI                      vector<int>
# define    pb                      push_back
# define    mp                      make_pair
# define    IOS                     ios::sync_with_stdio(false)
# define    mem(a,b)                memset(a,b,sizeof(a))
# define    FO(i,n,a)               for(int i=n; i>=a; --i)
# define    FOR(i,a,n)              for(int i=a; i<=n; ++i)
# define    pi                      acos(-1.0)
# define    MAX                     0x7fffffffffffff
# define    INF                     0x3f3f3f3f
# define    MOD                     1000000007
# define    eps                     0.00000001
# define    hr                      putchar('\n')
# define    bug                     puts("H")
# pragma    comment(linker,"/STACK:1024000000,1024000000")
typedef     unsigned long long      ULL;
typedef     long long               LL;
inline char gtc() {
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
# define    Template                int
inline Template read() {
    int flag=1;
    char ch=gtc();
    if(ch==EOF)return EOF;   ///EOFµÄÖµÊÇ-1
    Template sum=0;
    while(!((ch>='0'&&ch<='9')||ch=='-'))ch=gtc();
    if(ch=='-')flag=-1,ch=gtc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return sum*flag;
}
inline void out(Template x) {
    if(x<0)putchar('-'),x=-x;
    if(x>9)out(x/10);
    putchar(x%10+'0');
}
///coding...................................

int main() {
    IOS;
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    int n;
    cin>>n;
    if(n%10==9||n/10==9)puts("Yes");
    else puts("No");
    return 0;
}











///delete FLAG..............................




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] w = new int[N];
        int[] v = new int[N];

        for (int i = 0; i < N; i++) {
            w[i] = sc.nextInt();
            v[i] = sc.nextInt();
        }

        int vMax = 1000 * 100;
        long INF = Long.MAX_VALUE - 1000000000;
        long[][] dp = new long[N + 1][vMax + 1];

        for (int i = 0; i < N + 1; i++) {
            for (int j = 0; j < vMax + 1; j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][0] = 0;

        for (int i = 0; i < N; i++) {
            for (int j = 0; j <= vMax; j++) {
                if (j >= v[i]) {
                    dp[i + 1][j] = Math.min(dp[i][j - v[i]] + w[i], dp[i][j]);
                } else {
                    dp[i + 1][j] = dp[i][j];
                }
            }
        }

        int result = 0;
        for (int i = 0; i <= vMax; i++) {
            if (dp[N][i] <= W) {
                result = i;
            }
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 128984
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int s = (a/2);
            int v = (a/2)+1;
            if(a%2==0){
              System.out.println(s*s);
            } else {
              System.out.println(s*v);
            }
            }
}

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

int main() {
  int N,K;
  int x;
  int ch;
  int sum = 0;
  cin >> N >> K;
  
  for(int i = 0;i < N;i++){
    cin >> x ;
    ch = K - x;
    if( ch <= x ){
      sum += 2 * ch;
    }
    else{
      sum += 2 * x;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int L,R,d;
  cin>>L>>R>>d;
  int ans=0;
  FOR(i,L,R+1)if(i%d==0)ans++;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007

ll n, e[3], s[8], g[8], ans = INF;

void dfs(ll a, ll b) {
	g[a] = b;
	if (a == n - 1) {
		ll hon[4] = {}, cost[4] = {}, na = 0;
		bool ok = true;
		REP(i, n) {
			hon[g[i]]++;
			cost[g[i]] += s[i];
		}
		REP(i, 3) if (hon[i] == 0)ok = false;
		if (ok) {
			REP(i, 3) na += abs(e[i] - cost[i]) + (hon[i] - 1) * 10;
			ans = min(ans, na);
		}
	}
	else REP(i, 4)dfs(a + 1, i);
}

int main() {
	cin >> n;
	REP(i, 3)cin >> e[i];
	REP(i, n)cin >> s[i];
	REP(i, 4)dfs(0, i);
	cout << ans << endl;
}




Measured memory_bytes: 256