akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int K;
vector<ll>A;
ll check(ll ini){
	for (int i = 0; i < K; i++) {
		ini = ini - ini%A[i];
		if (ini <= 0)return 0;
	}
	return ini;
}

void err() {
	puts(-1);
	exit(0);
}

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

	cin >> K;
	A.resize(K);
	for (int i = 0; i < K; i++)cin >> A[i];
	ll ok1 = 0, ng1 = inf;
	while (ng1 - ok1 > 1) {
		ll mid1 = (ok1 + ng1) / 2LL;
		if (check(mid1) < 2)ok1 = mid1;
		else ng1 = mid1;
	}
	if (check(ng1) != 2)err();


	ll ok2 = 0, ng2 = inf;
	while (ng2 - ok2 > 1) {
		ll mid2 = (ok2 + ng2) / 2LL;
		if (check(mid2) <= 2)ok2 = mid2;
		else ng2 = mid2;
	}
	if (check(ok2) != 2)err();

	cout << ng1 << " " << ok2 << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main()
{
    char c[2]; int n, d, v = 0; bool ok = true;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++)
    {
        scanf("%s%d", c, &d);
        
        v += (c[0] == '(' ? 1 : -1) * d;
        
        if(v < 0) { ok = false; }
    }
    
    printf("%s\n", v == 0 && ok ? "YES" : "NO");
    
    return 0;
}

Measured memory_bytes: 2696
x,y = map(int,input().split())
a = 300000
b = 200000
c = 100000

if x == 1:
    if y==1:
        print(1000000)
    elif y==2:
        print(a+b)
    elif y==3:
        print(a+c)
    else:
        print(a)
if x == 2:
    if y==1:
        print(a+b)
    elif y==2:
        print(b+b)
    elif y==3:
        print(b+c)
    else:
        print(b)
if x == 3:
    if y==1:
        print(a+c)
    elif y==2:
        print(c+b)
    elif y==3:
        print(c+c)
    else:
        print(c)
if x>3 and y>3:
    print(0)
if x>3 and y == 1:
    print(a)
if x>3 and y == 2:
    print(b)
if x>3 and y == 3:
    print(c)


Measured memory_bytes: 3064
import sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,K = LI()
A = [0]+LI()
town = 1
route = [1]
town_set = set([1])
while 1:
    town = A[town]
    route.append(town)
    if town in town_set:
        break
    town_set.add(town)
loopstart_index = route.index(route[-1])
loop_len = (len(route)-1)-loopstart_index
ans_index = loopstart_index+(K-loopstart_index)%(loop_len)
if K<loopstart_index:
    ans_index = K
print(route[ans_index])


Measured memory_bytes: 32588
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define ll long long
#define se second
using namespace std;

int main(){
	// int t;cin>>t;while(t--){
		// ll n;cin>>n;ll s[n+1],c[n+1],f[n+1];
		// for(int i=1;i<=n-1;i++)
		// {
		// 	cin>>c[i]>>s[i]>>f[i];
		// }
	
		// for(int i=1;i<=n-1;i++)
		// {
		// 	ll total=0;
		// 	total+=c[i]+s[i];
		// 	for(int j=i+1;j<=n-1;j++)
		// 	{
		// 		if(total<=s[j])
		// 		total=s[j]+c[j];
		// 		else
		// 		{
		// 			if(total%f[j]==0)
		// 			total=total+c[j];
		// 			else
		// 				total+=(total%f[j])+c[j];
					
		// 		}
				
		// 	}
		// 	cout<<total<<endl;
		// }
		// cout<<"0\n";
		
		
		
		
		ll n,k;cin>>n>>k;
		ll a[n+1];
		vector<ll> pos,neg;
		int f=0;
		for(int i=1;i<=n;i++)
		{
			cin>>a[i];
			if(a[i]==0){f++;continue;}
			if(a[i]<0)neg.push_back(a[i]*-1);
			else pos.push_back(a[i]);
		}
		ll P[n+1]={0},N[n+1]={0};
		P[0]=0,N[0]=0;
		if(f==1)--k;
		if(k==0){cout<<"0\n";}else{
		sort(neg.begin(),neg.end());
		for(int i=0;i<neg.size();i++)
		N[i+1]=N[i]+(neg[i]-N[i]);
		for(int i=0;i<pos.size();i++)
		P[i+1]=P[i]+(pos[i]-P[i]);
		

			ll mi=10000000009;
			for(int i=0;i<neg.size();i++)
			{
			if(k-(i+1)==0){mi=min(mi,N[i+1]);break;}
			if(k-(i+1)>0)
			{
			if(pos.size()>=k-(i+1))
			mi=min(mi,N[i+1]*2+pos[k-(i+1)-1]);
			else continue;
			}}
			
			for(int i=0;i<pos.size();i++)
			{
				
			if(k-(i+1)==0){mi=min(mi,P[i+1]);break;}
			if(k-(i+1)>0)
			{
			if(neg.size()>=k-(i+1))
			mi=min(mi,P[i+1]*2+neg[k-(i+1)-1]);
			else continue;
			}}
			
			cout<<mi<<endl;
			
			
			
		}
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for(int i = 0;i < n;i++) {
    cin >> v[i];
    if(i >= k) cout << (v[i-k] < v[i] ? "Yes" : "No") << endl;
  }
}

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

ll divisor=1e9+7;
int main(){
	ll n,k;
	cin>>n>>k;
	ll ans=1;
	rep(i,n){
		if(i==0)ans*=k;
		else ans*=k-1;
	}
	puts(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
using namespace std;

typedef pair<int, int> P;
int W, H;
char X[20][20];
bool V[20][20];
int DX[4] = {0, -1, 1, 0};
int DY[4] = {-1, 0, 0, 1};

int main() {
  while (cin >> W >> H) {
    if (W == 0 && H == 0) break;
    int sx = -1, sy = -1;
    for (int i=0; i<H; i++) {
      for (int j=0; j<W; j++) {
        cin >> X[j][i];
        V[j][i] = false;
        if (X[j][i] == '@') sx = j, sy = i;
      }
    }

    int c = 0;
    queue<P> q;
    q.push(P(sx, sy));

    while (!q.empty()) {
      int x = q.front().first,
          y = q.front().second; q.pop();
      if (V[x][y]) continue;
      V[x][y] = true;
      c++;

      for (int k=0; k<4; k++) {
        int dx = x + DX[k], dy = y + DY[k];
        if (dx < 0 || dx >= W || dy < 0 || dy >= H) continue;
        if (X[dx][dy] == '.') q.push(P(dx, dy));
      }
    }
    cout << c << "\n";
  }
  return 0;
}

Measured memory_bytes: 3044
n=int(input())
e=[[] for _ in range(n)]
for _ in range(n):
    u,_,*v=map(lambda x:int(x)-1, input().split())
    e[u]=sorted(v)
q=[0]
d=[-1]*n
d[0]=0
while q:
    i=q.pop(0)
    for v in e[i]:
        if d[v]==-1:
            q.append(v)
            d[v]=d[i]+1
for i in range(n):
    print(i+1,d[i])



Measured memory_bytes: 5628
N = int(input())
h = [int(i) for i in input().split()]

count = h[0]

now_min = h[0]
now_max = h[0]
up = True
h.append(0)

for i in h[1:]:
    if up:
        if now_max <= i:
            now_max = i
        else:
            count += now_max - now_min
            now_min = i
            up = False

    else:
        if now_min >= i:
            now_min = i
        else:
            up = True
            now_max = i

print(count)

Measured memory_bytes: 3064
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int M = in.nextInt();
		int[] A = new int[M];
		int total = 0;
		for (int i=0; i<M; i++) {
			A[i] = in.nextInt();
			total = total + A[i];
		}
		
		if (N >= total) {
			System.out.println(N - total);
		} else {
			System.out.println("-1");
		}
		
	}
}


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

int main() {
  int input01;
  int input02;  

  cin >> input01 >> input02;
  if(input01 > input02) {
    cout << "a > b" << endl;
  } else if(input01 < input02) {
    cout << "a < b" << endl;
  } else {
    cout << "a == b" << endl;
  }
  return 0;
} 

Measured memory_bytes: 1156
N, M = map(int, input().split())
edge = []
for i in range(M):
    a,b,c = map(int, input().split())
    edge.append((a-1,b-1, c))
point = [None] * N
point[0] = 0
for i in range((N*4)//3):
    for a,b,c in edge:
        if point[a] is not None:
            if point[b] is None:
                point[b] = point[a] + c
            point[b] = max(point[b], point[a] + c)
current_point = point[N-1]
for i in range(5):
    for a,b,c in edge:
        if point[a] is not None:
            if point[b] is None:
                point[b] = point[a] + c
            point[b] = max(point[b], point[a] + c)
if current_point < point[N-1]:
    print("inf")
else:
    print(current_point)


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

#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 1e6 + 41;
const int mod = 1e9 + 7;
const long long INF = 1e16;
const int inf = 1e9;

int dp[int(2e5) + 5];

int main () {
	boost;
	int n;
	cin >> n;
	for (int i = 1 ; i <= n ; ++ i) {
		int x;
		cin >> x;
		dp[x] = dp[x - 1] + 1;
	}
	cout << n - *max_element (dp, dp + n + 2);
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int H, A, ct=0;
int main()
{
    cin >> H >> A;
   while ((H<1||H>10000)&&(A < 1 || A>10000))
        cin >> H >> A;
   int b = H;
    for (int i = 0; i < b; i++)
    {
        H = H - A;
        ct++;
        if(H<1)
        {
            cout << ct << endl;
            break;
        }
        
    }
    return 0;
}

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

constexpr int INF = 2e9;
int main(){
  int k, n, diff = INF, tmp;
  scanf("%d %d", &n, &k);
  vector<int> h(n);
  for(int i = 0; i < n; i++)
    scanf("%d", &h[i]);
  sort(h.begin(), h.end());
  for(int i = 0; i <= n-k; i++){
    tmp = h[i+k-1] - h[i];
    if(tmp <= diff)
      diff = tmp;
  }
  printf("%d\n", diff);
  return 0;
}


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

typedef long long ll;
const int N=1e6+100;
ll n,Q,k;
char s[N];
ll x[N];

int main(){
	scanf("%lld\n%s\n%lld\n",&n,s,&Q);
	for(ll i=1;i<=Q;i++) scanf("%lld\n",x+i);
	for(ll b=1;b<=Q;b++){
		ll l=x[b]-1;
		queue<ll>q;
		ll cnt=0,ans=0,res=0;
		for(ll i=0;i<n;i++){
			if(s[i]=='D') q.push(cnt);
			if(s[i]=='M') res+=(ll)q.size(),cnt++;
			if(s[i]=='C') ans+=res;
			if(i>=l){
				k=i-l;
				if(s[k]=='D'){
					res-=(cnt-q.front());
					q.pop();
				}
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 11140
import sys,copy
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
inf = float('inf')

N = int(input())
ad = [{} for _ in range(N)]
dis = [inf]*N
near = [-1]*N
player = ["Fennec","Snuke"]

for i in range(N-1):
    a,b = map(int,input().split())
    a -= 1; b -= 1
    ad[a][i] = b
    ad[b][i] = a

back_up = [copy.deepcopy(line) for line in ad]

def dfs(v,start,depth=0):
    if dis[v] > depth:
        dis[v] = depth
        near[v] = start
    if not ad[v]:
        return
    while ad[v]:
        key,nv = ad[v].popitem()
        ad[nv].pop(key)
        dfs(nv,start,depth+1)

dfs(0,0)
ad = back_up
dfs(N-1,N-1)
f = near.count(0)
s = N-f
ans = player[0] if f > s else player[1]
print(ans)

Measured memory_bytes: 180368
def print_frame(h,w):
    if h == 1:
        print("#"*w)
        return
        
    if h == 2:
        print("#"*w)
        print("#"*w)
        return

    print("#"*w)
    for i in range(h-2):
        print("#",end="")
        for j in range(w-2):
           print(".",end="")
        print("#")
    print("#"*w)

while True:
    h,w = map(int,input().split())
    if h == 0 and w == 0:
        break;
    else :
        print_frame(h,w)
        print()

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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define REV(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

//const ll mod = 1e9+7;
//const ll mod = 998244353;
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}
int main()
{
	string s, t;
	cin >> s >> t;

	SORT(s);
	SORT(t); REV(t);
	if(s < t){
		coY();
	} else {
		coN();
	}
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <stack>
using namespace std;

int main()
{
    int n;
    cin >> n;
    stack<int> st;

    while (n != 0) {
        int m = abs(n) % 2;
        st.push(m);
        if (n % -2 != 0) {
            n = (n - 1) / -2;
        } else {
            n /= -2;
        }
    }
    if (st.empty()) {
        cout << 0 << endl;
    } else {
        while (!st.empty()) {
            cout << st.top();
            st.pop();
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/****************************************************************
*	Author: huhao
*	Email: 826538400@qq.com
*	Create time: 2020-02-15 16:50:22
****************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const int N=110;
int n,v[N][N][N];
char a[N][N];
i64 Ans,f[N][N][N];
i64 solve(int l,int r,int m)
{
	if(v[l][r][m]) return f[l][r][m];
	v[l][r][m]=1; i64 &ans=f[l][r][m];
	if(l==r) return ans=1;
	if(l==m||r==m) return ans=0;
	fr(i,l,m-1) fr(I,i,m-1) fd(j,r,m+1) fd(J,j,m+1) if(a[i][j]) ans+=solve(l,I,i)*solve(J,r,j)*solve(I+1,J-1,m);
//	if(l==2&&r==n) printf("%d %d %d  %I64d\n",l,r,m,ans);
	return ans;
}
int main()
{
	n=read()*2;
	fr(i,1,n) scanf("%s",a[i]+1);
	fr(i,1,n) fr(j,1,n) a[i][j]-=48;
//	fr(i,1,n) fr(j,1,n) printf("%d%c",a[i][j],j==n?'\n':' ');
	if(n==2) Ans=a[1][2];
	else fr(i,3,n-1) Ans+=a[1][i]*solve(2,n,i);
	printf("%lld\n",Ans);
	return 0;
}

Measured memory_bytes: 6912
import java.util.*;
public class Main {

	
	public static int computeMax(int[] arr) {
		int profit = -999999999;
		for(int i = 0; i <arr.length; i++) {
			for(int j = i +1 ; j < arr.length ; j++) {
				if(arr[j] - arr[i] > profit) {
					profit = arr[j] - arr[i];
				}
			}
		}
		return profit; 
	}
	
	public static int max(int a, int b) {
		if(a >= b) {
			return a;
		}
		else {
			return b;
		}
	}
	
	public static int computeMaxDP(int[] arr) {
		int[][] memory = new int[arr.length][arr.length];
		int min = arr[0];
		for(int i = 1; i < arr.length; i++ ) {
			for(int j = i; j < arr.length; j++) {
				if(arr[j] < min) {
					min = arr[j];
				}
				memory[i][j] = max(max(memory[i][j-1], arr[j] - min), memory[i-1][j]); 
				//System.out.println(memory[i][j]);
				//System.out.println(min);
				//System.out.println(i + ", " + j);
				
			}
		}
		return memory[arr.length-1][arr.length-1];
	}
	
	public static int computeMaxDPother(int[] arr) {
		int minValue = arr[0];
		int max = Integer.MIN_VALUE;
		for(int i = 1; i < arr.length; i++) {
			if(max < arr[i] - minValue) {
				max = arr[i] - minValue;
			}
			if(arr[i] < minValue) {
				minValue = arr[i];
			}
		}
		return max;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int size = in.nextInt();
		int[] arr = new int[size];
		for(int i = 0;i < size; i++) {
			arr[i] = in.nextInt();
		}
		int profit = computeMaxDPother(arr);
		System.out.println(profit);
	}
}


Measured memory_bytes: 100848
#include <stdio.h>

int m = 0, f = 0, r = 0;
void rank(m, f, r){
  if(m == -1 || f == -1){printf("F\n");}
  else if(m + f >= 80){printf("A\n");}
  else if(m + f >= 65 && m + f < 80){printf("B\n");}
  else if(m + f >= 50 && m + f < 65){printf("C\n");}
  else if((m + f >= 30 && m + f < 50) && (r < 50)){printf("D\n");}
  else if((m + f >= 30 && m + f < 50) && (r >= 50)){printf("C\n");}
  else if(m + f < 30){printf("F\n");}
  else if(r >= 50){printf("C\n");}
};

int main(void){
  while(1){
  scanf(" %d %d %d\n", &m, &f, &r);
  if( m == -1 && f == -1 && r == -1){return 0;}
  else {rank(m, f, r);}
  }
}

Measured memory_bytes: 588
function main()
  
  X = parse(Int, readline())
  
  ans = 0
 
  if X == 1
    ans = 1
  else
  
  	for i in 1:X
    
    	for j in 2:X
    
    		if X < i^j
      		break
            elseif ans < i^j
      		ans = i^j
    		end
      
    	end
    
  	end
    
  end
  
  println(ans)
  
end
 
main()

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    string s; cin >> s;

    for (int i = 0; i < s.size(); ++i) {
        cout << 'x';
    }

    cout << endl;
}

Measured memory_bytes: 256
#include<cstdio>


int main(){
    int n,m,a;
    scanf("%d",&n);
    int x[n+1];
    x[n] = 2020;
    for(int i = 0;i < n;++i) scanf("%d",&x[i]);
    scanf("%d",&m);
    for(int i = 0;i < m;++i){
        scanf("%d",&a);
        if(x[a-1] < x[a]-1) x[a-1]++;
    }
    for(int i = 0;i < n;++i) printf("%d\n",x[i]);
}


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

#define ankit_2305 cerr<<"\nTime taken : "<<(float)(clock()-time_p)/CLOCKS_PER_SEC<<" sec\n";
#define START clock_t
#define TIMER time_p=clock();
#define ll long long

#define MOD 1000000007

using namespace std;

int n, h[100000];
ll dp[100000];

ll solve(int p){
	if(dp[p] != -1)
		return dp[p];
	
	dp[p+1] = solve(p+1);
	dp[p+2] = solve(p+2);
	return min(abs(h[p] - h[p+1]) + dp[p+1] , abs(h[p] - h[p+2]) + dp[p+2]);
}

int main(){
    START TIMER
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int t = 1;
	while(t--){
		cin>>n;
		for(int i=0;i<n;i++){
			cin>>h[i];
			dp[i] = -1;
		}
		dp[n-2] = abs(h[n-1] - h[n-2]);
		dp[n-1] = 0;
		cout<<solve(0);
	}
    ankit_2305
    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
#define rep(i, n)  for (int i = 0; i <  (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const ll INF = ll(1e18)+1;

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

    ll x;
    cin >> x;
    if(x >= 30){
        cout << "Yes";
    }
    else{
        cout << "No";
    }
}

Measured memory_bytes: 3648
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, A, B, C, D;
	string S;
	cin >> N >> A >> B >> C >> D;
	cin >> S;
	if (S.substr(A - 1, C - A + 1).find("##") != string::npos
			|| S.substr(B - 1, D - B + 1).find("##") != string::npos)
	{
		cout << "No" << endl;
	}
	else if (C > D && S.substr(B - 2, D - B + 2).find("...") == string::npos && S[D - 2] == '#')
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
	return 0;
}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    ll N; cin >>N;

    ll limit = sqrt(N);
    ll ans = N-1;

    for (ll i = 2; i <= limit; i++) {
        if (N%i == 0)
            chmin(ans, (i-1)+(N/i-1));
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
# N,M = 10**5,10**5

alb = [[] for i in range(M+1)]

for i in range(N):
  a,b = map(int,input().split())
  # a,b = 1,1
  if a < len(alb):
    alb[a].append(b)

# for i in range(M+1):
#   alb[i] = list(reversed(sorted(alb[i])))
# print(alb)

# cur = 0
# cnt = 0
# for m in range(M+1):
#   for mm in range(max(cur,m),M+1):
#     cur = mm
#     if len(alb[mm])>0:
#       print(m,mm,alb[mm][0],len(alb[mm]))
#       cnt+=alb[mm][0]
#       alb[mm].pop(0)
#       break

q = []

cur = 0
cnt = 0
for m in range(M+1):
  for a in alb[m]:
    heapq.heappush(q,-a)
  if len(q)>0:
    cnt -= heapq.heappop(q)

print(cnt)

Measured memory_bytes: 66464
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        mut a: [i64;n],
    }

    a.sort();
    let max_ = a.pop().unwrap();
    let mut half_ = a.iter().fold(0, |acc, &x| {
        if (x - max_ / 2).abs() <= (acc - max_ / 2).abs() {
            x
        } else {
            acc
        }
    });

    println!("{} {}", max_, half_);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
# define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const int N = 1e6+1;
int a[N],b[N];
int32_t main()
{
	reus;
	ios::sync_with_stdio(0);
	cin.tie(0);

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n,i,j;
    cin>>n;
    for(i=1;i<=n;i++)
    {
    	cin>>a[i];
    	b[a[i]]++;
	}
	for(i=N-1;i>0;i--)
	{
		for(j=2*i;j<N;j+=i)
		{
			b[j]+=b[i];
		}
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
		if(b[a[i]]==1)
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 12944
#include <cstdio>
#include <cstring>
inline int read()
{
	register int c=getchar(),f=1,k=0;
	while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	return k*f;
}
char s[500];
int main()
{
	scanf("%s",s);
	bool flag=1;
	for (int i=1;i<strlen(s);i++)if (s[i-1]=='A'&&s[i]=='C')flag=0;
	if (!flag)printf("Yes\n");else printf("No\n");
} 

Measured memory_bytes: 128
n=int(input())
abc=[]
for i in range(0,n):
    temp=list(map(int,input().split()))
    abc.append(temp)  
dp=[["#"]*3 for i in range(0,n)]

dp[0][0]= abc[0][0]
dp[0][1]= abc[0][1]
dp[0][2]= abc[0][2]

for i in range(1,n):
    dp[i][0]= max( dp[i-1][1], dp[i-1][2] )+ abc[i][0]
    dp[i][1]= max( dp[i-1][0], dp[i-1][2] )+ abc[i][1]
    dp[i][2]= max( dp[i-1][0], dp[i-1][1] )+ abc[i][2]

print(max(dp[n-1][0],dp[n-1][1],dp[n-1][2]))
  


Measured memory_bytes: 47384
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################

signed main(){
    int n;cin >> n;
    string s;cin >> s;
    int q;cin >> q;
    set<int> st[26];
    rep(i,n)st[s[i] - 'a'].insert(i);
    auto change = [&](int i,char c){
        //s[i] をcに
        char past = s[i];
        st[past - 'a'].erase(i);
        st[c - 'a'].insert(i);
        s[i] = c;
    };
    auto get = [&](int l,int r){
        //[l,r)の種類数
        int ret = 0;
        rep(i,26){
            //trace(st[i]);
            auto tmp = st[i].lower_bound(l);
            if(tmp == st[i].end())continue;
            if(*tmp <r)ret++;
        }
        return ret;
    };
    while(q--){
        int t;cin >> t;
        if(t == 1){
            int i;char c;
            cin >> i >> c;
            i--;
            change(i,c);
        }
        else if(t == 2){
            int l,r;cin >> l >> r;
            l--;
            cout << get(l,r) << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 27268
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>

using namespace std;

typedef struct {
	int x = 0;
	int y = 0;
} Point;

typedef vector<Point> PointArray;

// 構造体vectorのソート方法を指定する関数
bool cmp_x_then_y(const Point& left, const Point& right) {
	if (left.x == right.x) return left.y < right.y;
	return left.x < right.x;
}

int main() {

	int N;
	cin >> N;	// ~100
	PointArray redPoints;
	for (int i = 0; i < N; i++) {
		Point tmp;
		cin >> tmp.x >> tmp.y;
		redPoints.push_back(tmp);
	}
	PointArray bluePoints;
	for (int i = 0; i < N; i++) {
		Point tmp;
		cin >> tmp.x >> tmp.y;
		bluePoints.push_back(tmp);
	}
	sort(redPoints.begin(), redPoints.end(), cmp_x_then_y);
	sort(bluePoints.begin(), bluePoints.end(), cmp_x_then_y);

	int count = 0;
	for (int i = 0; i < bluePoints.size(); i++) {
		// 青い点のx座標が小さい側からマッチングする点を探してゆく
		Point &blue = bluePoints[i];
		int match_id = -1;
		int max_y = -1;
		for (int j = 0; j < redPoints.size(); j++) {
			if ((redPoints[j].x < blue.x) && (redPoints[j].y < blue.y)) {
				if (max_y < redPoints[j].y) {
					match_id = j;
					max_y = redPoints[j].y;
				}
			}
			else if(redPoints[j].x >= blue.x) {
				break;
			}
		}
		if (match_id != -1) {
			count++;
			redPoints.erase(redPoints.begin() + match_id, redPoints.begin() + match_id + 1);
		}
	}
	cout << count << endl;

	return 0;

}

/*
5
4 8 *
7 3 **
1 6 ***
2 2
0 0

6 9 *
9 1
8 5 **
3 7 ***
5 4

*/

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:500000000")
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <exception>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <math.h>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <time.h>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;

typedef long long ll;
const double PI = acos(-1.0);
const double EPS = 1e-9;
const ll INF = static_cast<ll>(1e18);

int dp[109][109];

int f(int x, int y) {
	if (dp[x][y] == -1) {
		dp[x][y] = 0;
		for (int i = 1; 2 * i <= x; ++i) {
			if (!f(x - 2 * i, y + i)) {
				dp[x][y] = 1;
				break;
			}
		}
		if (!dp[x][y]) {
			for (int i = 1; 2 * i <= y; ++i) {
				if (!f(x + i, y - 2 * i)) {
					dp[x][y] = 1;
					break;
				}
			}
		}
	}
	return dp[x][y];
}

int main() {
	//freopen("in.txt", "rt", stdin);
	//freopen("out.txt", "wt", stdout);
	
	/*for (int x = 0; x <= 100; ++x) {
		for (int y = 0; y <= 100; ++y) {
			dp[x][y] = -1;
		}
	}
	for (int x = 0; x <= 50; ++x) {
		for (int y = 0; y <= 50; ++y) {
			printf("%d ", f(x, y));
		}
		printf("\n");
	}*/

	ll x, y;
	scanf("%lld %lld", &x, &y);
	if (abs(x - y) <= 1) {
		printf("Brown\n");
	} else {
		printf("Alice\n");
	}
	return 0;
}

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

int main() {
  long long int N, K, MOD, ans;
  cin >> N >> K;
  MOD = 1000000007;
  ans = 0;
  for (long long int i = K; i <= N + 1; i++) {
    ans += (N * i - i * (i - 1) + 1) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;
}


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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  vector<int> N(L);
  for(int i=0; i<L; i++){
    N.at(i)=S.at(i)-'0';
  }
  int Min=1000;
  int x;
  for(int i=0; i<L-2; i++){
    x=N.at(i)*100+N.at(i+1)*10+N.at(i+2);
    Min=min(abs(753-x), Min);
  }
  cout << Min << endl;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 2019
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	cout.tie();
	long long a, b;
	cin >> a >> b;
	long long temp = 2019 * (a % 2019 ? a / 2019 + 1 : a / 2019), ans = 2019;
	if(a <= temp && b >= temp) cout << 0 << '\n';
	else
	{
		for(long long i=a; i<b; i++)
		{
			for(long long j=i+1; j<=b; j++)
			{
				long long temp = (long long)i * j;
				temp = temp % mod;
				if(temp < ans) ans = temp;
			}
			if(ans == 0) break;
		}
		cout << ans << '\n';
	} 
	return 0;
}

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 <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, M;
        cin >> N >> M;
        string S;
        cin >> S;

        vector<int> dp(N + 1);
        vector<int> prev(N + 1, -1);
        queue<pair<int, int>> que;
        que.emplace(0, 0);

        for (int i = 1; i <= N; ++i) {
            if (S[i] == '1') continue;
            while (!que.empty() && i - que.front().second > M) {
                que.pop();
            }

            if (que.empty()) {
                cout << -1 << endl;
                return;
            }

            dp[i] = que.front().first + 1;
            prev[i] = que.front().second;
            que.emplace(dp[i], i);
        }
        if (dp.back() == 0) {
            cout << -1 << endl;
            return;
        }

//        Int dist = dp.back();
//        vector<Int> path(dist + 1, -1);
//        for (int i = 0; i <= N; ++i) {
//            if (path[dp[i]] == -1) {
//                path[dp[i]] = i;
//            }
//        }
//        path[dist] = N;
//        for (int i = 1; i <= dist; ++i) {
//            cout << path[i] - path[i - 1] << " ";
//        }
//        cout << endl;

        vector<Int> path;
        vector<int> ans;
        path.push_back(N);
        while (true) {
            if (path.back() == 0) break;
            path.push_back(prev[path.back()]);
        }
        reverse(all(path));
        for (int i = 1; i < path.size(); ++i) {
            cout << path[i] - path[i - 1] << " ";
        }
        cout << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 2364
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> s(1<<n);
    for(int i=0;i<(1<<n);++i) cin >> s[i];
    sort(s.rbegin(), s.rend());

    vector<bool> used(1<<n, 0);
    used[0] = 1;
    vector<int> parents;
    parents.push_back(s[0]);
    for(int t=0;t<n;++t) {
        int p_cnt = 0;
        for(int i=1;i<(1<<n);++i) {
            if(used[i]) continue;
            if(parents[p_cnt] > s[i]) {
                // cerr << p_cnt << " -> " << i << endl;
                used[i] = 1;
                parents.push_back(s[i]);
                ++p_cnt;
                if(p_cnt == (1 << t)) break;
            }
        }
        if(p_cnt < (1 << t)) {
            cout << "No" << endl;
            return 0;
        }
        sort(parents.rbegin(), parents.rend());
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 2424
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = input()
    s = 0
    for i in range(len(N)):
        s += int(N[i])
    if s%9 == 0:
        print('Yes')
    else:
        print('No')
if __name__ == '__main__':
    main()


Measured memory_bytes: 9204
#include <iostream>
using namespace std;
int n;
long long a[404], b[404], d[404][404];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i], b[i] = b[i - 1] + a[i];
    for (int i = 1; i < n; i++) for (int j = 1; j + i <= n; j++) {
        d[j][j + i] = 1e18;
        for (int k = j; k < j + i; k++) d[j][j + i] = min(d[j][j + i], d[j][k] + d[k + 1][j + i]);
        d[j][j + i] += b[j + i] - b[j - 1];
    }
    cout << d[1][n] << '\n';
}


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

int main(void) {
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (a < b) {
		if (c < b && c > a)
			printf("Yes");
		else
			printf("No");
	} else {
		if (c < a && c > b)
			printf("Yes");
		else
			printf("No");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int arr[5];
int main()
{
    int rot, count, j, div=0, mod=0;
    scanf("%d",&rot);
    div = rot/100;
    mod = rot%100;
    if((div>0 && div<=12) && (mod>0 && mod<=12)) printf("AMBIGUOUS\n");

    else if((div>=0) && (mod>0 && mod<=12)) printf("YYMM\n");

    else if((div>0 && div<=12) && (mod>=0)) printf("MMYY\n");

    else printf("NA\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int ans=0;
		while(true) {
			int n=sc.nextInt();
			int x=sc.nextInt();
			ans=0;
			if(n==0 && x==0) {
				System.exit(0);
			}
			else{
				for(int i=n; i>=3; i--) {
					for(int j=i-1; j>=2; j--) {
						for(int k=j-1; k>=1; k--) {
							if(i+j+k==x) {
								ans++;
							}
						}
					}
				}
				System.out.println(ans);
			}
		}
	}
}


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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007

int main()
{ FAST
    string s; cin >> s;
    if(s == "AAA" || s == "BBB"){
        cout << "No";
    }
    else{
        cout << "Yes";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a, b, i;
	cin>>a>>b;
	int now=b*10, sx=(b+1)*10;
	for(i=now;i<=sx;i++)
	{
		if((int(i*0.08)==a)&&(int(i*0.1)==b))
		{
			break;
		}
	}
	if(i==sx+1)
	{
		cout<<"-1"<<endl;
		return 0;
	}
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  int n, h, w;
  cin >> n >> h >> w;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    if (a >= h && b >= w) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){

    int n, m, x, y; cin >> n >> m >> x >> y;
    vector<int> X;
    vector<int> Y;
    for(int i = 0; i < n; i++){
        int in; cin >> in;
        X.push_back(in);
    }

    X.push_back(x);

    for(int i = 0; i < m; i++){
        int in; cin >> in;
        Y.push_back(in);
    }

    Y.push_back(y);

    if(* max_element ( X.begin () , X.end ()) >= * min_element ( Y.begin () , Y.end ())) cout << "War" << endl;
    else cout << "No War" << endl;
    return 0;
}

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() - 1;
		int[] b = new int[n];

		b[0] = sc.nextInt();
		int tmp = b[0];
		int count = tmp;

		for (int i = 1; i < n; i++) {
			b[i] = sc.nextInt();
			count += Math.min(b[i], tmp);
			tmp = b[i];
		}

		System.out.println(count + b[n - 1]);

	}
}

Measured memory_bytes: 23764
import sys


def input():
    return sys.stdin.readline().strip()


MOD = 998244353


def main():
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    height = [[0] * W for _ in range(H)]
    width = [[0] * W for _ in range(H)]

    for h in range(H):
        cnt = 0
        for w in range(W):
            if S[h][w] == ".":
                cnt += 1
            else:
                width[h][w - cnt : w] = [cnt] * cnt
                cnt = 0
        width[h][W - cnt : W] = [cnt] * cnt
    for w in range(W):
        cnt = 0
        for h in range(H):
            if S[h][w] == ".":
                cnt += 1
            else:
                for i in range(cnt):
                    height[h - cnt + i][w] = cnt
                cnt = 0
        for i in range(cnt):
            height[H - cnt + i][w] = cnt
    answer = 0
    for h in range(H):
        for w in range(W):
            ans = width[h][w] + height[h][w] - 1
            if ans > answer:
                answer = ans
    print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 120540
#include <bits/stdc++.h>
#define loop(n) for (int ngtkana_is_geneous = 0; ngtkana_is_geneous < n; ngtkana_is_geneous++)
#define rep(i, begin, end) for(int i = begin; i < end; i++)

int main()
{
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::string s; std::cin >> n >> s;
  std::cout << (n < 3200 ? "red" : s) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
    map<int, int> a; // ??´???????????¨??£?§£??°????????????
    map<int ,int> m; // ??£?§£??°??¨??????????????????
    int x, y;
    while(~scanf("%d,%d\n", &x, &y)) {
        if(x == 0 && y == 0) break;
        a[x] = y; m[y];
    }

    int j = 1;
    for(auto &s : m) s.second = j++;
        
    int n;
    while(cin >> n) cout << j - m[a[n]] << endl;
    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> s;
  n = s.size();
  vector<int> ans(n);
  rep(ri,2) {
    { // solve R
      int cnt = 0;
      rep(i,n) {
        if (s[i] == 'R') cnt++;
        else {
          ans[i] += cnt/2;
          ans[i-1] += (cnt+1)/2;
          cnt = 0;
        }
      }
    }

    reverse(ans.begin(), ans.end());
    reverse(s.begin(), s.end());
    rep(i,n) {
      if (s[i] == 'L') s[i] = 'R';
      else s[i] = 'L';
    }
  }

  rep(i,n) {
    printf("%d\n", ans[i]);
  }
  return 0;
}


Measured memory_bytes: 1024
#include  <bits/stdc++.h>
using namespace std;
static int fast_io = []() { std::ios::sync_with_stdio(false); cin.tie(nullptr); return 0; }();
 
  
int main(){
  int n,k;
  cin>>n>>k;
  vector<long long int> monsters(n);
  for(auto &x:monsters){
    cin>>x;
  }
  sort(monsters.begin(),monsters.end(),greater<int>());
  long long int ans=0;
  for(int i=k;i<n;i++){
    ans+=monsters[i];
  }
  cout<<ans<<"\n";  
  return 0;
}

Measured memory_bytes: 1792
#include <stdio.h> 
#include <string.h>
#define LEN 100005

typedef struct pp{
 char name[100];
 int t;
 }P;
 P Q[LEN];
 int head,tail,n;
 
void enqueue(P x){
 Q[tail]=x;
 tail=(tail+1)%LEN;
 }
 
 P dequeue(){
 P x=Q[head];
 head=(head+1)%LEN;
 return x;
 }
 
 int min(int a,int b){ return a<b?a:b;}
 
 int main(){
 int elaps=0,c;
 int i,q;
 P u;
 scanf("%d %d",&n,&q);
 
 for(i=1;i<=n;i++){
  scanf("%s",Q[i].name);
  scanf("%d",&Q[i].t);
  }
  head=1;tail=n+1;
  
 while(head != tail){
  u=dequeue();
  c=min(q,u.t);
  u.t-=c;
  elaps+=c;
  if(u.t>0)enqueue(u);
  else{
   printf("%s %d\n",u.name,elaps);
   }
   }
   
   return 0;
 }

Measured memory_bytes: 10756
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=1000000007;
const llint inf=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int i,j,n;cin>>n;
	char c;
	llint aa[21][21]={};
	llint wa[21][21]={};
	llint A=10000000000LL;
	llint ans=0;
	while(n--){
		string s;cin>>s;
		llint gen=0;
		bool ten=false;
		llint AA=A;
		for(auto it:s){
			if(it=='.'){ten=true;}
			else{
				if(!ten){gen*=10;}
				else{AA/=10;}
				gen+=(it-'0')*AA;
			}
		}
		int ni=0,go=0;
		while(gen%2==0){gen/=2;ni++;}
		while(gen%5==0){gen/=5;go++;}
		chmin(ni,20);
		chmin(go,20);
		if(10<=ni&&10<=go){ans--;}
		aa[ni][go]++;
		wa[ni][go]++;
	}
	for(i=20;i>=0;i--){
		for(j=20;j>0;j--){
			wa[i][j-1]+=wa[i][j];
		}
	}
	for(i=20;i>0;i--){
		for(j=20;j>=0;j--){
			wa[i-1][j]+=wa[i][j];
		}
	}
	
	for(i=0;i<=20;i++){
		for(j=0;j<=20;j++){
			ans+=aa[i][j]*wa[20-i][20-j];
		}
	}
	ans/=2;
	cout<<ans<<endl;
}

Measured memory_bytes: 3204
#include <stdio.h>
#include <algorithm>
using namespace std;
struct segment_tree
{
	int seg[262144];
	int query(int id)
	{
		int ret=0;
		for (id+=131072;id;id>>=1)
			(ret+=seg[id])%=1000000007;
		return ret;
	}
	void add(int l,int r,int val)
	{
		for (l+=131072,r+=131072;l<r;l>>=1,r>>=1)
		{
			if (l&1)
				(seg[l++]+=val)%=1000000007;
			if (r&1)
				(seg[--r]+=val)%=1000000007;
		}
	}
};
segment_tree seg1,seg2;
long long s[100001];
int nxt1[100001],nxt2[100001];
int main()
{
	int n;
	long long a,b;
	scanf("%d%lld%lld",&n,&a,&b);
	for (int i=1;i<=n;++i)
		scanf("%lld",s+i);
	nxt1[n]=nxt2[n]=n;
	for (int i=n-1;i>=1;--i)
	{
		nxt1[i]=(s[i+1]-s[i]<a?i:nxt1[i+1]);
		nxt2[i]=(s[i+1]-s[i]<b?i:nxt2[i+1]);
	}
	seg1.add(0,1,1);
	seg2.add(0,1,1);
	for (int i=1;i<=n;++i)
	{
		int val1=seg1.query(i-1),val2=seg2.query(i-1);
		if (val1)
		{
			int nxt=nxt2[i],fir1=(i==1?2:lower_bound(s+i,s+n+1,s[i-1]+a)-s);
			seg2.add(fir1-1,nxt+1,val1);
		}
		if (val2)
		{
			int nxt=nxt1[i],fir2=(i==1?2:lower_bound(s+i,s+n+1,s[i-1]+b)-s);
			seg1.add(fir2-1,nxt+1,val2);
		}
	}
	printf("%d",(seg1.query(n)+seg2.query(n))%1000000007);
	return 0;
}


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

int main(){
	int N; cin >> N;
  	vector<int> A(N);
  	double sum=0.0;
  	for(int i=0; i<N ; i++){
    	cin >> A.at(i);
      	sum+= A.at(i);
    }
  	double ave = sum / N;
  	
  	int i_ave;
  	if(ave >=0){i_ave = (ave + 0.5);}
  	else{i_ave = (ave - 0.5);} 
  	int ans=0;
  	for(int i=0; i< N ;i++){
    	ans+=pow(i_ave-A.at(i),2);
    }
  	cout << ans << endl;
  	
}

Measured memory_bytes: 256