akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;


public class Main {
	
	public static void main(String[] args) {
		new Main().run();
	}
	
	void run() {
		FastScanner sc=new FastScanner();
		int A=sc.nextInt();
		int B=sc.nextInt();
		int C=sc.nextInt();
		int D=sc.nextInt();
		while (true) {
			C-=B;
			if (C<=0) {
				System.out.println("Yes");
				return;
			}
			A-=D;
			if (A<=0) {
				System.out.println("No");
				return;
			}
		}
	}
	
	void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));}
}




class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
    	return (int)nextLong();
    }
}

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

int main(void) {
 int a;
 cin >> a;
 for(int i =1; i <= 9; i++) {
     for(int j = 0; j <=9; j++) {
         if(a == i * j) {
             cout << "Yes" << endl;
             return 0;
         }
     }
 }
 cout << "No" << endl;
  return 0;
}

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

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		mylist ml=new mylist();
		int q=in.nextInt();
		for(int i=0;i<q;i++) {
			int query=Integer.parseInt(in.next());
			switch(query) {
			case 0:
				int x=Integer.parseInt(in.next());
				ml.insert(x);
				break;
				
			case 1:
				int d=Integer.parseInt(in.next());
				ml.move(d);
				break;
				
			case 2:
				ml.delete();
				break;
			}
		}
		ml.printls();
	}

}

class node{
	node next,prev;
	int n;
	boolean END=false;
}

class mylist{
	node END=new node();
	node currentNode;
	int position=0,size=0;
	
	mylist(){
		END=new node();
		END.END=true;
		END.next=END;
		END.prev=END;
		currentNode=END;
	}
	
	void insert(int x) {
		node nn=new node();
		nn.n=x;
		nn.next=currentNode;
		nn.prev=currentNode.prev;
		nn.prev.next=nn;
		nn.next.prev=nn;
		currentNode=nn;
		size++;
	}
	
	void move(int m) {
		for(int i=0;i<Math.abs(m);i++) {
			if(m<0)currentNode=currentNode.prev;
			else currentNode=currentNode.next;
		}
	}
	
	void delete() {
		currentNode.prev.next=currentNode.next;
		currentNode.next.prev=currentNode.prev;
		currentNode=currentNode.next;
		size--;
	}
	
	void printls() {
		node cn=END.next;
		for(int i=0;i<size;i++) {
			System.out.println(cn.n);
			cn=cn.next;
		}
	}
}



Measured memory_bytes: 185260
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

template<class T> void read(T &x){
	int f=0; x=0; char ch=getchar();
	for(;!isdigit(ch);ch=getchar()) f|=(ch=='-');
	for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	if(f) x=-x;
}

const int N=100005,mod=998244353,M=1<<10;
const int bas=int(1000000000000000000ll%mod);
int pw[N],f[N],g[M],dp[M],ndp[M],vis[M];
int n,A,B,a,b,m;
vi e[N];

int main(){
	read(n);
	pw[0]=1;
	rep(i,1,n) pw[i]=(ll)pw[i-1]*bas%mod;
	dp[0]=1;
	REP(t,3){
		rep(i,1,n) e[i].clear();
		read(m);
		rep(i,1,m){
			read(a),read(b);
			if(a>b) swap(a,b);
			e[a].pb(b);
		}
		memset(g,0,sizeof g);
		per(i,n,1){
			f[i]=0;
			for(auto j:e[i]) vis[f[j]]=1;
			while(vis[f[i]]) f[i]++;
			g[f[i]]=(g[f[i]]+pw[i])%mod;
			for(auto j:e[i]) vis[f[j]]=0;
		}
		memset(ndp,0,sizeof ndp);
		REP(i,M) REP(j,M)
			ndp[i^j]=(ndp[i^j]+(ll)dp[i]*g[j])%mod;
		memcpy(dp,ndp,sizeof dp);
	}
	cout<<dp[0]<<endl;
	return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef unsigned long long ULL;
 
#define MP make_pair
#define PB push_back
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)a.size()
#define f first
#define s second
#define FILL(a, b) memset(a, b, sizeof(a))
 
const int MAX = 400*1000+5;
const int INF = 1000*1000*1000 + 7;
const LL LINF = 1LL*INF*INF;
const int MOD = INF;
const double PI = acos(-1.);
const int MAXN = 200007;
 
mt19937 rnd(time(0));
 

int main()
{
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	VI a(n), b(n), c(n);
	FOR(i, 0, n)
	{
		cin >> a[i];
	}
	FOR(i, 0, n)
	{
		cin >> b[i];
	}
	FOR(i, 0, n)
	{
		cin >> c[i];
	}

	sort(ALL(a));
	sort(ALL(b));
	sort(ALL(c));

	LL ans = 0;
	vector<LL> calc(n);
	FOR(i, 0, n)
	{
		int pos = lower_bound(ALL(a), b[i]) - a.begin();
		calc[i] = pos;
		if (i)
		{
			calc[i] += calc[i - 1];
		}
		// cout << calc[i] << " ";
	}

	FOR(i, 0, n)
	{
		int pos = lower_bound(ALL(b), c[i]) - b.begin();
		--pos;
		if (pos < 0)
		{
			continue;
		}
		if (b[pos] < c[i]) 
		{
			ans += calc[pos];
		}
		// cout << pos << " ";
	}
	cout << ans << "\n";

	return 0;	
}
	
	
 

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

using namespace std;

typedef long long LL;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

#define INF 100000000

int main()
{
	int N;
	cin >> N;
	vector<LL> seq(N);
	for (int n = 0; n < N; n++)
	{
		cin >> seq[n];
		seq[n] += (n == 0 ? 0 : seq[n-1]);
	}
	int L = 0, R = 2;
	LL best = INT_MAX;
	for (int M = 1; M < N-1; M++)
	{
		while (abs((seq[M]-seq[L+1]) - seq[L+1]) <= abs((seq[M]-seq[L]) - seq[L]))
			if (L < M-1)
				L++;
			else
				break;
		while (abs((seq[N-1]-seq[R+1]) - (seq[R+1]-seq[M])) <= abs((seq[N-1]-seq[R]) - (seq[R]-seq[M])))
			if (R < N-1)
				R++;
			else
				break;
		LL a = seq[L], b = seq[M] - seq[L], c = seq[R] - seq[M], d = seq[N-1] - seq[R];
		best = min(best, max({ a, b, c, d }) - min({ a, b, c, d }));
	}
	cout << best << endl;
}



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

int main(){
    int n,m;
    cin >>n>>m;
    vector< vector< int > > a(n,vector<int>(m));
    vector<int> b(m);
    vector<int> ans(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i=0;i<m;i++) cin >> b[i];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            ans[i]+=a[i][j]*b[j];
        }
        cout << ans[i] << endl;
    }
    return 0;
}


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

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    vector<int> ans(101);

    for (int i = 1; i <= 100; i++) {
        if (A % i == 0 && B % i == 0) ans.push_back(i);
    }
    sort(ans.begin(), ans.end(), greater<int>());
    cout << ans.at(K - 1) << endl;
}

Measured memory_bytes: 3632
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (n);i++)
using ll = long long;
const ll MOD=1000000007;
const double pi=acos(-1);





int main() 
{
  ll N; cin>>N;
  string S; cin>>S;
  
  
  vector<vector<ll>> vec(N,vector<ll>(3,0));//R,G,B順で
  reverse(S.begin(),S.end());
  rep(i,N)
  {
    if(i==0) {continue;}
    if(S.at(i-1)=='R') {vec.at(i).at(0)++;}
    if(S.at(i-1)=='G') {vec.at(i).at(1)++;}
    if(S.at(i-1)=='B') {vec.at(i).at(2)++;}
    rep(j,3)
    {
      vec.at(i).at(j)+=vec.at(i-1).at(j);
    }
  }
  reverse(S.begin(),S.end());
  reverse(vec.begin(),vec.end());
  //cout<<S<<endl;
  /*
  rep(i,N)
  {
    rep(j,3)
    {
      if(j!=0) {cout<<" ";}
      cout<<vec.at(i).at(j);
    }
    cout<<endl;
  }
  */
  ll ans=0;
  for(ll i=0;i<N;i++)
  {
    for(ll j=i+1;j<N;j++)
    {
      //if(j!=i+1) {cout<<" ";}
      if(S.at(i)==S.at(j)) {/*cout<<ans*/; continue;}
      if(S.at(i)=='R'&&S.at(j)=='G'||S.at(i)=='G'&&S.at(j)=='R') {ans+=vec.at(j).at(2); if(2*j-i<N&&S.at(2*j-i)=='B') {ans--;}}
      if(S.at(i)=='G'&&S.at(j)=='B'||S.at(i)=='B'&&S.at(j)=='G') {ans+=vec.at(j).at(0); if(2*j-i<N&&S.at(2*j-i)=='R') {ans--;}}
      if(S.at(i)=='B'&&S.at(j)=='R'||S.at(i)=='R'&&S.at(j)=='B') {ans+=vec.at(j).at(1); if(2*j-i<N&&S.at(2*j-i)=='G') {ans--;}}
      //cout<<ans;
    }
    //cout<<endl;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3760
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=100010;
struct data{
	int x,y;
}a[N];
int n,m,q,ans;
bool bo[N];
bool cmp(data x,data y)
{
	return x.y>y.y;
}
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int k=1;k<=n;k++)
	{
		int x;
		scanf("%d",&x);
		a[k].x=x;
		a[k].y=x+q;
	}
	sort(a+1,a+1+n,cmp);
	for(int k=1;k<=n;k++)
	{
		ans++;
		int i;
		for(i=1;i<m;i++)
			if(a[k+i].y<a[k].x)
				break;
		k=k+i-1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
int main(){
    string s;
    cin>>s;
    int i,j,k,ans=0,num;
    
    vector<string>ss(4);
    vector<int>si(4);
    for(int i=0;i<s.size()-2;i++){
        for(int j=i+1;j<s.size()-1;j++){
            for(int k=j+1;k<s.size();k++){
                
                ss[0]=s.substr(0,i+1);
                ss[1]=s.substr(i+1,j-i);
                ss[2]=s.substr(j+1,k-j);
                ss[3]=s.substr(k+1);
                

                bool flag=true;
                for(int l=0;l<4;l++){
                    if(ss[l].size()>3||ss[l].size()==0)flag=false;
                    if(ss[l][0]=='0'&&ss[l].size()!=1)flag=false;
                    num=atoi(ss[l].c_str());
                    //cout<<num<<endl;
                    if(!(0<=num&&num<256))flag=false;
                }

                //if(flag)cout<<ss[0]<<" "<<ss[1]<<" "<<ss[2]<<" "<<ss[3]<<endl;
                ans+=flag;
            }

        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD=1e9+7;

int main(void){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> G(n,vector<int>(n,0));
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        G[a][b]=1;
        G[b][a]=1;
    }
    vector<int> X(n);
    rep(i,n) X[i]=i;
    int ans=0;
    do{
        if(X[0]!=0) continue;
        bool ok=true;
        rep(i,n-1){
            if(G[X[i]][X[i+1]]==0) ok=false;
        }
        if(ok) ans++;
    } while(next_permutation(X.begin(),X.end()));
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
N = int(input())
S = input()

b = [0] * (N+1)
w = [0] * (N+1)

for i, s in enumerate(S):
    b[i+1] = b[i]
    w[i+1] = w[i]
    if s == "#":
        b[i+1] += 1
    if s == ".":
        w[i+1] += 1

ans = float('inf')

for i in range(N+1):
    ans = min(ans, b[i] + w[N] - w[i])

print(ans)

Measured memory_bytes: 12776
n = io.read("*n")
dig = 1
flg = 1
if(0 < n) then flg = 0 else n = -n end
t = {}
while(0 < n) do
  rem = n % 2
  if(dig % 2 == flg and rem == 1) then
    n = n + 1
  end
  table.insert(t, 1, rem)
  n = math.floor(n / 2)
  flg = (flg + 1) % 2
end
len = #t
for i = 1, len do
  io.write(string.format("%d", t[i]))
end
if(len == 0) then io.write(0) end
io.write("\n")


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST(N)

lim = 1
ans = 0
for a in A:
    d, m = divmod(a, lim)
    if d == 0 or d == 1 and m == 0:
        lim = max(lim, a+1)
    else:
        ans += d - (m == 0)
        lim = max(lim, 2)
print(ans)


Measured memory_bytes: 7136
#coding:utf-8
n = int(input())
A = list(map(int, input().split()))
def partition(A, p, r):
    x = A[r-1]
    i = p-1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]
    return i
a = partition(A, 0, n)
A[a] = [A[a]]
A = " ".join([str(num) for num in A])
print(A)


Measured memory_bytes: 16396
#include<stdio.h>

int main(void)
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	if(a==b && d==c){
		printf("yes\n");
	}
	else if(a==c && b==d){
		printf("yes\n");
	}
	else if(a==d && b==c){
		printf("yes\n");
	}
	else{
		printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2056
#include<stdio.h>
#include<math.h>
struct shu
{
int from;
int to;
};
shu nCost[31];
void vmake(int nN,int nC);
int main()
{
	int num,nCase,i;

	while(scanf("%d",&num)==1)
	{
      scanf("%d",&nCase);
	  for(i=1;i<=nCase;i++)
	  {
	    scanf("%d,%d",&nCost[i].from,&nCost[i].to);
	  }
	    vmake(num,nCase);
	 }
	return 0;
}

void vmake(int nN,int nC)
 {
  int i,j,To;
  for(i=1;i<=nN;i++)
  {  
     To=i;
     for(j=nC;j>=1;j--)
	 {
       if(To==nCost[j].from)
	         To=nCost[j].to;
	   else
	      if(To==nCost[j].to)
	         To=nCost[j].from;
	 }
	 printf("%d\n",To);
  }
 }

Measured memory_bytes: 1024
///Possibly a duplicate of P2670.
#include <cstdio>

int main(){
    char a[128][128]={0};
    int n,l,N,L;
    const int K=127;
    scanf("%d%d",&n,&l);
    /*input->*/
    for(N=0;N<n;++N){
        for(L=0;L<l;++L){
            scanf("%c",&a[N][L]);
            if(a[N][L]=='\n')
            scanf("%c",&a[N][L]);
        }
    }
    /*process->*/
    for(N=0;N<n;++N){
        for(L=0;L<l;++L){
            if(a[N][L]!='#'){
                a[N][L]=
                (a[(N+1)%128][(L+1)%128]=='#')+
                (a[(N+1)%128][(L+0)%128]=='#')+
                (a[(N+1)%128][(L+K)%128]=='#')+
                (a[(N+0)%128][(L+K)%128]=='#')+
                (a[(N+K)%128][(L+K)%128]=='#')+
                (a[(N+K)%128][(L+0)%128]=='#')+
                (a[(N+K)%128][(L+1)%128]=='#')+
                (a[(N+0)%128][(L+1)%128]=='#')+
                48;
            }
        }
    }
    /*output->*/
    for(N=0;N<n;++N){
        for(L=0;L<l;++L){
            printf("%c",a[N][L]);
        }
        printf("\n");
    }
    return 0;
}

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


using ll = long long int;

using namespace std;




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll A, B, K;
    
    cin >> A >> B >> K;
    
    B = min(B, (B + (A - K)));
    A = max(0LL, (A - K));
    B = max(0LL, B);
    
    cout << A << " " << B;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010


int main(){
  if(df)printf("*** debug mode ***\n");
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int ans=c+b-a;

  printf("%d",ans>0?ans:0);
  return 0;
}


/// confirm df==0 ///

Measured memory_bytes: 128
N, Q = [int(i) for i in input().strip().split()]
S = input().strip()

hit = [0]*(N+1)
for i in range(N):
  hit[i+1] = hit[i] + (1 if S[i:i+2]=='AC' else 0)
  
for _ in range(Q):
  l, r = [int(i) for i in input().strip().split()]
  print(hit[r-1]-hit[l-1])

Measured memory_bytes: 7748
"""
# 標準入力取得
## 文字列
     = sys.stdin.readline().rstrip()
     = list(sys.stdin.readline().rstrip())

## 数値
     = int(sys.stdin.readline())
     = map(int, sys.stdin.readline().split())
     = list(map(int, sys.stdin.readline().split()))
     = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]
"""

import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

mod = 1000000007

if __name__ == "__main__":
     N = int(sys.stdin.readline())
     A = list(map(int, sys.stdin.readline().split()))
     B = list(map(int, sys.stdin.readline().split()))

     cnt = 0
     for i in range(N):
          tmp = B[i] - A[i]
          if tmp > 0:
               cnt += A[i]
               if tmp > A[i + 1]:
                    cnt += A[i + 1]
                    A[i + 1] = 0
               else:
                    cnt += tmp
                    A[i + 1] -= tmp
          else:
               cnt += B[i]

     print(cnt)



Measured memory_bytes: 20664
s = input()

cnt1 = 0
cnt2 = 0

for i in range(len(s)):
	if i % 2 == 0:
		if s[i] == '0':
			cnt1 += 1
		elif s[i] == '1':
			cnt2 += 1
	elif i % 2 == 1:
		if s[i] == '1':
			cnt1 += 1
		elif s[i] == '0':
			cnt2 += 1

print(min(cnt1, cnt2))

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>

using namespace std;

int main()
{
    char S[201];

    if (scanf("%s", S) < 1) return 0;

    int len = strlen(S);
    int num = 1;
    int max = 0;
    while (num <= len / 2)
    {
        for (int i = 0; i < num; i++)
        {
            if (S[i] != S[i + num])
            {
                num++;
                break;
            }

            if (i == num - 1)
            {
                if ((len % 2 == 0) && (num == len / 2))
                {
                    num++;
                    break;
                }
                else
                {
                    max = num;
                    num++;
                    break;
                }
            }
        }
    }


    printf("%d\n", max * 2);
    return 0;
}


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

int a[222222], b[222222];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		scanf("%d", a + i);
	for (int i = 0; i < n; i++)
		scanf("%d", b + i);
	priority_queue<pair<int, int>> q;
	for (int i = 0; i < n; i++) {
		if (b[i] < a[i]) {
			cout << -1 << endl;
			return 0;
		}
		q.emplace(b[i] - a[i], i);
	}
	long c = 0;
	for (;;) {
		auto r = q.top();
		q.pop();
		if (!r.first) break;
		int m = r.second;
		int z = (b[m] - a[m]) / (b[(m + n - 1) % n] + b[(m + 1) % n]);
		c += z;
		if (!z) {
			cout << -1 << endl;
			return 0;
		}
		b[m] -= z * (b[(m + n - 1) % n] + b[(m + 1) % n]);
		q.emplace(b[m] - a[m], m);
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3956
#include <iostream>
#include <cstring>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
struct da
{
    string name;
    int val;
} a[200010];
inline bool comp(da x, da y)
{
    if (x.val > y.val)
        return true;
    if (x.val < y.val)
        return false;
    return x.name < y.name;
}
int main()
{
    ios::sync_with_stdio(false);
    int n, shu = 0, pos = 1;
    string st;
    map<string, int> m;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> st;
        if (m[st] == 0)
        {
            ++shu;
            m[st] = shu;
            a[m[st]].name = st;
            a[m[st]].val = 1;
        }
        else
            ++a[m[st]].val;
    }
    sort(a + 1, a + shu + 1, comp);
    while (a[pos].val == a[pos + 1].val && pos + 1 <= shu)
        ++pos;
    for (int i = 1; i <= pos; ++i)
        cout << a[i].name << endl;
    return 0;
}

Measured memory_bytes: 27008
#include <stdio.h>
int main(void){
    int a, b, c, ans;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    ans = c-(a-b);
    if (ans<0){
        printf("0\n");
    }
    else {
        printf("%d", ans);
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

#define for(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((int)(x).size())
#define inf          1<<25

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

//typedef vector<int> vi;
//typedef vector<long long> vl;
//typedef vector<double> vd;
//typedef pair<int,int> pii;
//typedef pair<long,long> pll;
//typedef long long ll;

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

int main() {
    string s;
    cin >> s;
    
    cout << "2018/01/" + s.substr(8, 2) << endl;
    return 0;
}

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

/* 
 * g++ -std=c++17 main.cpp -o main
 */
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  vector<int> emp(n+1);

  for(int i = 2; i <= n; i++) {
    int a;
    cin>>a;
    emp[a]++;
  }
  for(int i = 1; i<=n; i++)
    cout<<emp[i]<<endl;

}


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

#define ll long long
#define endl "\n"

vector <ll> ad[200006];
vector <ll> vis(200006,0);

ll ans=0, n, m, k;


void add(ll x, ll y){
    ad[x].push_back(y);
    ad[y].push_back(x);
}

ll dfs(ll node){
    vis[node]=1;
    ++ans;
    for(ll i:ad[node]){
        if(!vis[i])
            dfs(i);
    }
    return ans;
}

void solve(){
    ll n, m;
    cin >> n >> m;
    for(ll i=0;i<m;i++){
        ll x,y;
        cin >> x >> y;
        add(x,y);
    }
    k=0;
    for(ll i=1;i<=n;i++)
    {
        ans=0;
        if(!vis[i])
            k=max(k, dfs(i));
    }
    cout << k << endl;
}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 21888
#include"bits/stdc++.h"
using namespace std;

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

  if(N%2 == 0){
    cout << 1.0/2.0 << endl;
  }

  if(N%2 != 0){
    cout << (N+1.0)/(2.0*N) << endl;
  }

  
  return 0;

}


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

int main(){
    int n; cin >> n;
    vector<int> x(n), y(n), h(n);
    int idx;
    for(int i = 0; i < n; i++){
        cin >> x.at(i) >> y.at(i) >> h.at(i);
        if(h.at(i) != 0) idx = i;
    }
    int H;
    bool ok;
    for(int i = 0; i <= 100; i++){
        for(int j = 0; j <= 100; j++){
            ok = true;
            H = abs(i - x.at(idx)) + abs(j - y.at(idx)) + h.at(idx);
            for(int k = 0; k < n; k++){
                if(h.at(k) != max(H - abs(i - x.at(k)) - abs(j - y.at(k)), 0)) ok = false;
            }
            if(ok){
                cout << i << " " << j << " " << H;
                break;
            }
        }
        if(ok) break;
    }
}

Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==
*/

f("a").
f("i").
f("u").
f("e").
f("o").

main :-
    get_string(S),
    f(S) -> writeln("vowel") ; writeln("consonant").


Measured memory_bytes: 8032
#include <cstdio>

#define MAXN 100009

int a[MAXN+1];
bool r[MAXN+1];

int main(){
    int n, m;
    scanf("%d%d", &n, &m);

    for(int i=2; i<=n; i++)
        a[i]=1;
    r[1]=1;
    a[1]=1;

    for(int i=1; i<=m; i++){
        int x, y;
        scanf("%d%d", &x, &y);

        if(r[x]==1)
            r[y]=1;

        a[y]++;

        a[x]--;
        if(a[x]==0)
            r[x]=0;
    }

    int ans=0;
    for(int i=1; i<=n; i++)
        ans+=r[i];

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>
#include <limits>
#include <set>
#include <algorithm>

template <typename F>
auto fix(F&& f) {
	return [f = std::forward<F>(f)](auto&&... args) {
		return f(f, std::forward<decltype(args)>(args)...);
	};
}

int main() {
	int V, E;
	std::cin >> V >> E;

	std::vector<std::vector<int>> edges(V);

	for (int i = 0; i < E; ++i) {
		int s, t;
		std::cin >> s >> t;

		edges[s].push_back(t);
		edges[t].push_back(s);
	}

	std::set<std::pair<int, int>> bridges;

	constexpr int Inf = std::numeric_limits<int>::max();
	std::vector<int> pre(V, Inf), low(V, Inf);

	fix([&](auto dfs, int x, int prev, int count) -> int {
		pre[x] = low[x] = count;
		
		for (auto&& t : edges[x]) {
			if (pre[t] != Inf) {
				if (t != prev)
					low[x] = std::min(low[x], low[t]);
			}
			else {
				count = dfs(dfs, t, x, count + 1);

				low[x] = std::min(low[x], low[t]);

				if (low[t] == pre[t])
					bridges.insert(std::minmax(x, t));
			}
		}

		return count;
	})(0, -1, 0);

	for (auto&& b : bridges)
		std::cout << b.first << " " << b.second << std::endl;
}


Measured memory_bytes: 4476
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <set>
#include <functional>
using namespace std;
using ll = long long;

using pii = pair<int, int>;
int n, q, s[200010], t[200010], x[200010], d[200010];
set<int> block;
priority_queue<pii, vector<pii>, greater<pii>> st, ed;
int main() {
	scanf("%d %d", &n, &q);
	for (int i = 0; i < n; i++) {
		scanf("%d %d %d", s + i, t + i, x + i);
		s[i] -= x[i];
		t[i] -= x[i];
		st.emplace(s[i], i);
	}
	for (int i = 0; i < q; i++)
		scanf("%d", d + i);
	for (int i = 0; i < q; i++) {
		while (!ed.empty() && ed.top().first <= d[i]) {
			block.erase(x[ed.top().second]);
			ed.pop();
		}
		while (!st.empty() && st.top().first <= d[i]) {
			int id = st.top().second;
			if (d[i] < t[id]) {
				block.emplace(x[id]);
				ed.emplace(t[id], id);
			}
			st.pop();
		}
		if (block.empty())
			printf("-1\n");
		else
			printf("%d\n", *block.begin());
	}
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


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

    long long m = 0;
    for(int i = 1; i < 1e+7; ++i){
        m = (10*m+7)%K;
        if(m == 0){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3632
n = int(input())
for i in range(1, n+1):
    x = i

    if x%3 ==0 :
        print(" %d" %(i),end="")
        continue
    else :
        while(True):
            if x%10 ==3 :
                print(" %d" %(i),end="")
                break
            x//=10
            if x == 0:
                break
print("")



Measured memory_bytes: 5868
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string S;
  cin>>S;
  if(S[1]=='R')
  {
  	if(S[0]=='R'&&S[2]=='R')
  	cout<<3<<endl;
  	else if(S[0]=='R'||S[2]=='R')
  	cout<<2<<endl;
  	else
  	cout<<1<<endl;
  }
  else
  {
  	if(S[0]=='R'||S[2]=='R')
  	cout<<1<<endl;
  	else
  	cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 3620
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = input1[0];
            var M = input1[1];

            var a = Enumerable.Repeat(-1, N + 1).ToArray();
            for (int _ = 0; _ < M; _++)
            {
                var input2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
                var s = input2[0];
                var c = input2[1];
                if (a[s] == -1)
                {
                    a[s] = c;
                }
                else
                {
                    if (a[s] != c)
                    {
                        Console.WriteLine(-1);
                        return;
                    }
                }
            }

            if (N == 1)
            {
                Console.WriteLine(a[1] == -1 ? 0 : a[1]);
                return;
            }

            if (a[1] == 0)
            {
                Console.WriteLine(-1);
                return;
            }

            if (a[1] == -1) a[1] = 1;

            var ans = a.Skip(1).Select(s => s == -1 ? 0 : s).Select(s => s.ToString()).Aggregate((s, t) => s += t);
            Console.WriteLine(ans);
        }
    }
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    string str;
    cin >> str;
    int n;
    cin >> n;
    while(n--) {
        string ope;
        cin >> ope;
        if(ope == "print") {
            int a, b;
            cin >> a >> b;
            cout << str.substr(a, b - a + 1) << endl;
            continue;
        }
        if(ope == "reverse") {
            int a, b;
            cin >> a >> b;
            reverse(str.begin() + a, str.begin() + b + 1);
            continue;
        }
        if(ope == "replace") {
            int a, b;
            string x;
            cin >> a >> b >> x;
            for(int i = 0; i < b - a + 1; i++) {
                str[a + i] = x[i];
            }
            continue;
        }
    }
    return 0;
}


Measured memory_bytes: 3184
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

int main(void){
    int n, k;
    std::cin >> n >> k;
    std::set<int> s;
    for(int i = 0; i < n; ++i){
        int tmp;
        std::cin >> tmp;
        s.insert(tmp);
    }
    while(true){
        int tmp = n;
        while(tmp > 0){
            if(s.end() != s.find(tmp % 10)){
                ++n;
                break;
            }
            tmp /= 10;    
        }
        if(0 == tmp) break;
    }
    std::cout << n << std::endl;

    return 0;
}

Measured memory_bytes: 3500
#include <iostream>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <tuple>
using namespace std;

#define MOD 1000000007
#define INF 1e9+7
#define INF_LONG 1e18
#define rep(i, n) for(int i=0; i<n; ++i)
#define rep1(i, n) for(int i=1; i<=n; ++i)
#define rrep(i, m, n) for(int i=m; i<n; ++i)
#define countof(array) (sizeof(array) / sizeof(array[0]))
typedef long long ll;

#define MAX_N 100000
#define MAX_M 100000
#define MAX_V 100
#define MAX_E 100
#define MAX_Q 100000

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

int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};

string ab = {"ABCDEFGHIJKLMNOPQRSTUVWXYZ"};
string as = {"abcdefghijklmnopqrstuvwxyz"};

ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

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

void yes() {
  cout << "Yes" << endl;
}

void no() {
  cout << "No" << endl;
}

void print_array(int array[], int len) {

  for(int i=0; i<len; ++i) {
    cout << array[i] << endl;
  }

}

ll absolute(ll x) {
  return (x<0)? (-1)*x : x;
}

//g++ AtCoder.cpp -o AtCoder
//AtCoder

//--------------------------
//提出するときC++に帰る
//--------------------------

int main() {

  int n, q;
  cin >> n;
  vector<int> s(n);
  rep(i, n) cin >> s[i];
  cin >> q;
  vector<int> t(q);
  rep(i, q) cin >> t[i];

  int ans = 0;
  rep(i, q) {
    if(*lower_bound(s.begin(), s.end(), t[i])==t[i]) ++ans;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 3336
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.stream.Stream;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class BMinesweeper {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int h = in.ints(), w = in.ints();
            String[] s = in.string(h);
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    if (s[i].charAt(j) == '#') {
                        out.print('#');
                        continue;
                    }
                    AtomicInteger ans = new AtomicInteger();
                    GeoWalker.forEach8i(j, i, (x, y) -> {
                        if (0 <= x && x < w && 0 <= y && y < h && s[y].charAt(x) == '#') {
                            ans.getAndIncrement();
                        }
                    });
                    out.print(ans);
                }
                out.println();
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String[] string(int length) {
            return IntStream.range(0, length).mapToObj(x -> string()).toArray(String[]::new);
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }

    static final class GeoWalker {
        private static final int[] DX = {1, 0, -1, 0, 1, 1, -1, -1};
        private static final int[] DY = {0, 1, 0, -1, 1, -1, -1, 1};

        private GeoWalker() {
        }

        public static void forEach8i(int x, int y, BiIntConsumer receiver) {
            for (int i = 0; i < 8; i++) {
                receiver.accept(x + DX[i], y + DY[i]);
            }
        }

    }

    static interface BiIntConsumer {
        void accept(int t, int u);

    }
}



Measured memory_bytes: 27732
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef vector<vector<int> > Graph;
typedef pair<int, int> P; 
// MOD
//const int mod = 1000000007;
typedef long long ll;
long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
//int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
 
mint f(int n) {
  if (n == 0) return 1;
  mint x = f(n/2);
  x *= x;
  if (n%2 == 1) x *= 2;
  return x;
}
 
mint choose(int n, int a) {
  mint x = 1, y = 1;
  rep(i,a) {
    x *= n-i;
    y *= i+1;
  }
  return x / y;
}

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}


struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

P s(int x){
    int a = x%10;
    int b = 0;
    while(x){
        b = x;
        b/=10;
    }
    return P(a, b);
}

int main() {
  int k; cin >> k;
  string s; cin >> s;
  int n = s.size();
  
  if(n<=k) cout << s << endl;
  else{
    rep(i,k) cout<< s[i];
    cout << "..." << endl;
  }
}

Measured memory_bytes: 3140
import sys

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


def solve():
    N = int(rl())
    a = [list(map(int, rl().split())) for _ in range(N)]
    INF = 10 ** 18
    
    dp = [0] * 2 ** N
    searched = [False] * 2 ** N
    searched[0] = True
    c = [0] * 2 ** N
    
    for s in range(2 ** N):
        tmp = 0
        for i in range(N):
            if not s >> i & 1:
                continue
            for j in range(i + 1, N):
                if s >> j & 1:
                    tmp += a[i][j]
        c[s] = tmp
    
    def calc(S):
        if searched[S]:
            return dp[S]
        searched[S] = True
        
        res = -INF
        T = 2 ** N
        while 0 < T:
            T = (T - 1) & S
            res = max(res, c[T] + calc(S ^ T))
        dp[S] = res
        return res
    
    calc(2 ** N - 1)
    print(dp[-1])


if __name__ == '__main__':
    solve()


Measured memory_bytes: 47568
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#pragma GCC optimize("Os")
#pragma GCC target("avx2,fma")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("Os")
*/
 
#include <bits/stdc++.h>
//#include <windows.h>
 
#define ll long long
#define X first
#define Y second
#define MP make_pair
 
using namespace std;
 
    /*
const int MAX_MEM = 1e8;
int mpos=0;
char mem[MAX_MEM];
inline void * operator new(size_t n){
	char *res = mem + mpos;
	mpos += n;
	assert(mpos <= MAX_MEM);
	return (void *)res;
}
 
inline void operator delete(void *){}
    */

const int N = 2e5 + 13;
const ll mod = 1e9 + 7;
    
int n;
ll a[N], m;

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

	cin >> n >> m;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}

	int run = 0;
	for(int i = 1;i < n;i++){
		if(a[i] + a[i + 1] >= m){
			run = i;
			break;
		}
	}

    if(run == 0){
    	cout << "Impossible";
    }     
    else{
    	cout << "Possible\n";
    	for(int i = 1;i < run;i++){
    		cout << i << "\n";
    	}
    	for(int i = n - 1;i > run;i--){
    		cout << i << "\n";
    	}
    	cout << run;
    }

	return 0;
}

Measured memory_bytes: 1664
#include <vector>
#include <stack>
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <typeinfo>
#include <queue>

using namespace std;

typedef long long ll;



void ichi(){
	string s;
	cin >> s;
	int tmp_c = 0;
	int tmp_f = 0;
	for(int i=0;i<s.size();i++){
		if(s[i] == 'C'){
			tmp_c = 1;
		}
		else if(s[i] == 'F'){
			if(tmp_c == 1){
				cout << "Yes" << endl;
				tmp_f = 1;
				break;
			}
		}
	}
	if(tmp_f == 0){
		cout << "No" << endl;
	}

}

void ni(){
	int k,t;
	cin >> k >> t;
	//int num[t];
	std::vector<int> num;
	int tmp;
	for(int i=0;i<t;i++){
		cin >> tmp;
		num.push_back(tmp);
	}
	sort(num.begin(),num.end(),greater<int>());
	/*
	int place = 0;
	for(int i = 0;i<k;i++){
		if(num[place] > 0){
			num[place] = num[place] - 1;
		}
	}
	*/
	int maxnum = num[0];
	int diff = 1;
	for(int i=1;i<t;i++){
		diff = diff + num[i];
	}
	int result = max(0,maxnum - diff);
	cout << result << endl;

	/*
	for(int i=0;i<t;i++){
		cout << num[i] << " ";
	}
	cout << endl;
	*/

}



int main(){
	//ichi();
	ni();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main() {
    int N, T;
    cin >> N >> T;
    
    int ans = 10000;

    for (int i = 0; i < N; ++i) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            ans = min(ans, c);
        }
    }

    if (ans == 10000) {
        cout << "TLE" << endl;
    } else {
        cout << ans << endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B;
	cin >> A >> B;

	if ((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
	else cout << "IMPOSSIBLE" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int number[10001];
    for(int i=1;i<10000;i++)number[i]=i*i;
    while(cin>>n,n){
        vector<int> num;
        for(int i=1;i<n;i++)num.push_back(number[i]%n);
        sort(num.begin(),num.end());
        num.erase(unique(num.begin(),num.end()),num.end());
        int ans[10001]={};
        for(int i=0;i<num.size();i++){
            for(int j=0,k;j<num.size();j++){
                k=num[i]-num[j];
                if(k<0)k+=n;
                if(k>n/2)k=n-k;
                ans[k]++;
            }
        }
        for(int i=1;i<=n/2;i++)cout<<ans[i]<<endl;
    }
}

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;

int main() {
    int n;
    scanf("%d", &n);

    using B = bitset<4242424>;
    B dp;
    dp.set(0);
    int sm = 0;
    for (int i = 0; i < n; i++) {
        int a;
        scanf("%d", &a);
        sm += a;
        dp |= dp<<a;
    }

    for (int i = (sm+1)/2; i <= sm; i++) {
        if (dp[i]) {
            printf("%d\n", i);
            return 0;
        }
    }
    assert(false);
}

Measured memory_bytes: 1792
import sys
import numpy as np

# inputを高速化する。
input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

# dpの配列を作る。
dp = np.zeros(n, dtype=int)
# hの配列を作る。
h = np.array(h)


for i in range(1, n):
    # start は負になることはない。
    start = max(0, i-k)
    # 行列として足し算できるのでforを使う必要がない。
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
#define INF 32767

int main()
{
  int w,h;cin>>w>>h;
  while(w!=0||h!=0)
  {
    vector<vector<int>> s(h,vector<int>(w));
    int i,j,k,l;
    rep(i,h)rep(j,w)cin>>s[i][j];
    vector<int> c(4);
    rep(i,4)cin>>c[i];
    int dp[h][w][4];
    vector<int> dx={1,0,-1,0};
    vector<int> dy={0,1,0,-1};
    rep(i,h)rep(j,w)rep(k,4)
    {
      dp[i][j][k]=INF;
    }
    dp[0][0][0]=0;
    bool update=true;
    while(update)
    {
      update=false;
      rep(i,h)rep(j,w)rep(k,4)rep(l,4)
      {
        int dir;
        if(s[i][j]==4)dir=-1;
        else dir=(l+s[i][j])%4;
        if(i+dy[k]>=0&&i+dy[k]<h&&j+dx[k]>=0&&j+dx[k]<w)
        {
          int base=dp[i+dy[k]][j+dx[k]][k];
          int aft;
          if(dir==k)
          {
            dp[i+dy[k]][j+dx[k]][k]=min(dp[i+dy[k]][j+dx[k]][k],dp[i][j][l]);
            aft=dp[i+dy[k]][j+dx[k]][k];
          }
          else
          {
            dp[i+dy[k]][j+dx[k]][k]=min(dp[i+dy[k]][j+dx[k]][k],dp[i][j][l]+c[(k-l+4)%4]);
            aft=dp[i+dy[k]][j+dx[k]][k];
          }
          if(aft<base)update=true;
        }
      }
    }
    int ans=INF;
    rep(i,4)
    {
      ans=min(ans,dp[h-1][w-1][i]);
    }
    cout<<ans<<endl;
    cin>>w>>h;
  }
}



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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){

  ll a,v,b,w;
  cin >> a >> v >> b >> w;
  ll t;
  cin >> t;


  ll d = abs(a-b);
  if(v <= w){
    cout << "NO" << endl;
  }else{
    if((v-w)*t>=d){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
} 

Measured memory_bytes: 3636