akhauriyash/Code-Regression huggingface dataset:
/*
 * a.cpp
 *
 *  Created on: 2019/06/08
 *      Author: MEIP-users
 */




#include <bits/stdc++.h>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1e9+10)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main() {
	ll a, b, c, k;
	ll ans = 0;
	cin >> a >> b >> c >> k;
	for (ll i = 0; i < k; i++){
		if(i < a){
			ans ++;
		}else if(i>a+b-1){
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3676
import numpy as np


def solve():
    tv = np.sum(a)
    min_votes = np.ceil(tv * 1/4 / m)
    cnt = np.sum(a >= min_votes)
    if cnt>=m:
        print("Yes")
    else:
        print("No")
    return


#s = input()

n, m = [int(i) for i in input().split(" ")]
a = [int(i) for i in input().split(" ")]
solve()

Measured memory_bytes: 13376
#include<stdio.h>
int main()
{
    int x=1 , y=2 ,z=3 ,A,B;
    scanf("%d%d",&A,&B);
    if(A==x  &&  B==y)
    {
        printf("%d\n",z);
    }
    else if(A==x  &&  B==z)
    {
        printf("%d\n",y);
    }
    else if(A==y && B==z)
    {
        printf("%d\n",x);
    }
    else if(A==z && B==x)
    {
        printf("%d\n",y);
    }
    else if(A==y && B==x)
    {
        printf("%d\n",z);
    }
    else
    {
        printf("%d\n",x);
    }
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int n;
	vector<int>a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a_temp;
		cin >> a_temp;
		a.push_back(a_temp);
	}
	sort(a.begin(), a.end(), greater<int>());
	int sum = 0;
	for (int i = 1; i < n; i++) {
		sum += a[i];
	}
	if (a[0] < sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<functional>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

template<typename T, int MAXNN>
struct seg_tree {
  typedef std::function<T(T,T)> OP;
  T data_[MAXNN*2-1], e_;
  int NN;
  OP& op_;

  seg_tree(int N, OP& op, T e) : e_(e), op_(op) {
    NN = 1;
    while(NN < N) NN *= 2;
    std::fill_n(data_, NN*2-1, e);
  }
  void update(int k, T v) {
    k += NN-1;
    data_[k] = v;
    while(k > 0) {
      k = (k-1)/2;
      data_[k] = op_(data_[k*2+1], data_[k*2+2]);
    }
  }
  int query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return e_;
    if(a <= l && r <= b) return data_[k];
    int m = (l+r)/2;
    int vl = query(a, b, k*2+1, l, m);
    int vr = query(a, b, k*2+2, m, r);
    return op_(vl, vr);
  }
  int query(int a, int b){ return query(a, b, 0, 0, NN); }
};


using seg2k = seg_tree<int, 2048>;
seg2k::OP min_op = [](int x, int y){ return std::min(x, y); };
seg2k::OP max_op = [](int x, int y){ return std::max(x, y); };

int const INF = 1e9+5;

int main() {
  int N; std::cin >> N;
  std::vector<int> a(N+2);
  for(int i = 0; i < N+2; ++i) std::cin >> a[i];
  
  std::vector<seg2k> yx_max(N+1, seg2k(N+1, max_op, -INF));
  std::vector<seg2k> xy_min(N+1, seg2k(N+1, min_op,  INF));
  for(int y = N; y >= 1; --y) {
    for(int x = N; x > y; --x) { // play for Y
      int res = std::abs(a[N+1] - a[x]);
      res = std::min(res, xy_min[x].query(x+1, N+1));
      yx_max[y].update(x, res);
    }
    for(int x = y-1; x >= 0; --x) { // play for X
      int res = std::abs(a[N+1] - a[y]);
      res = std::max(res, yx_max[y].query(y+1, N+1));
      if(y==1 && x==0) fin(res);
      xy_min[x].update(y, res);
    }
  }
  return 0;
}


Measured memory_bytes: 64384
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		
		int a[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		int ans = x;
		
		
		for (int i = 0; i < n; i++) {
			ans += (d - 1)/ a[i] + 1;
		}
		
		System.out.println(ans);
	}
}

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,lessl<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define f(i,l,r) for(int i=l;i<=r;i++)
#define rf(i,r,l) for(int i=r;i>=l;i--)

#define bp __builtin_popcountll
#define inf 1e18

const int N=5e3+5;
const int M=1e9+7;
int dp[N][N];
int len[N];
int a[N],c[N];
void dfs(int x)
{
	int curr=0;
	int oo=x;
	for(int i=1;i<N;i++)
	{
		curr+=c[x];
		dp[oo][i]=curr;
		x=a[x];
		if(x==oo && len[x]==0)
		{
			len[x]=i;
		}
	}
}
void solve()
{
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	for(int i=1;i<=n;i++)
	cin>>c[i];
	for(int i=1;i<=n;i++)
	{
		dfs(i);
	}
	int ans=-inf;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<N;j++)
		{
			if(j<=k)
			{
				ans=max(ans,dp[i][j]+((k-j)/len[i])*dp[i][len[i]]);
				ans=max(ans,dp[i][j]);
			}
		}
	}
	cout<<ans<<endl;
	
}



signed main()
{
	FAST
    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
    	// cout<<"Case #"<<tc<<": ";
    	solve();
    }
}


Measured memory_bytes: 199264
"""
author : halo2halo
date : 31, Jan, 2020
"""

import sys
import itertools

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

S = readline().decode('utf8')
print(-S.find('A') + S.rfind('Z') + 1)


Measured memory_bytes: 3516
import sys
input = sys.stdin.readline

n, k, l = map(int, input().split())
road = []
train = []
for i in range(k):
    road.append(list(map(int, input().split())))
for i in range(l):
    train.append(list(map(int, input().split())))

class Union_Find():
    def __init__(self, num):
        self.par = [-1]*(num+1)
        self.siz = [1]*(num+1)

    def same_checker(self, x, y):
        return self.find(x) == self.find(y)

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            x = self.par[x]
            return self.find(x)

    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] < self.par[ry]:
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
            elif self.par[rx] > self.par[ry]:
                self.par[rx] = ry
                self.siz[ry] += self.siz[rx]
            else:
                self.par[rx] -= 1
                self.par[ry] = rx
                self.siz[rx] += self.siz[ry]
        return

    def size(self, x):
        return self.siz[self.find(x)]

road_root = Union_Find(n)
train_root = Union_Find(n)
for i in range(k):
    road_root.union(road[i][0], road[i][1])
for i in range(l):
    train_root.union(train[i][0], train[i][1])

road = []
train = []
for i in range(n):
    road.append(road_root.find(i+1))
    train.append(train_root.find(i+1))

road
train

pair = []
for i in range(n):
    pair.append((road[i], train[i]))

d = dict()
for i in range(n):
    if pair[i] not in d:
        d[pair[i]] = 1
    else:
        d[pair[i]] += 1

ans = []
for i in range(n):
    ans.append(d[pair[i]])

print(" ".join(map(str, ans)))


Measured memory_bytes: 76520
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        char[] s = nsToChars();
        for (int i = 0; i < 3; i++) {
            if (s[i] == s[i+1]) {
                so.println("Bad");
                return;
            }
        }
        so.println("Good");
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int offset) {
        long[] a = new long[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = nl();
        return a;
    }
}


Measured memory_bytes: 21716
N = raw_input()
A_list = map(int, raw_input().split())
B_list = map(int, raw_input().split())
if sum(A_list) < sum(B_list):
    print(-1)
else:
    import numpy as np
    diff = [x - y for (x, y) in zip(A_list, B_list)]
    neg_list = [i for i in diff if i < 0]
    neg_sum = sum(neg_list)
    pos_list = [i for i in diff if i > 0]
    pos_list.sort(reverse=True)
    pos_list = np.cumsum(pos_list).tolist()
    for j,k in enumerate(pos_list):
        if len(neg_list) == 0:
            print(0)
            break
        elif neg_sum + k >= 0:
            print(j+1+len(neg_list))
            break 
        else:
            continue

Measured memory_bytes: 31992
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int m,d;
  cin>>m>>d;
  int ans=0;
  repi(i,1,m+1){
    repi(j,1,d+1){
      int a=j%10;
      int b=j/10;
      //cout<<a<<" "<<b<<endl;
      if(a<=1 || b<=1) continue;
      if(a*b==i) ans++;
    }
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>  

int main() 
{     
	int i,k;     
	int a,b;    
	while(1)
	{         
		scanf("%d %d", &a, &b);         
		if(a==0&&b==0)
		{            
			break;        
		}         
		for(i=0; i<a; i++)
		{             
			for(k=0; k<b; k++)
			{                 
				printf("#");             
			}           
			printf("\n");        
		}         
		printf("\n");    
	}    
	return 0; 
}

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


int main() {
    char a;
    cin>>a;

    if(a=='A') cout<<'T'<<endl;
    else if(a=='T') cout<<'A'<<endl;
    else if(a=='G') cout<<'C'<<endl;
    else if(a=='C') cout<<'G'<<endl;

    return 0;
}


Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define rall(x) x.rbegin() , x.rend()
#define all(x) x.begin() , x.end()
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <int , int>;
void in(int &x);
const int N = 1e5 + 10;
#define singleCase
// #define multipleCase
int n,c,k,t[N];

void work() {
   in(n); in(c); in(k);
   for (int i = 0 ; i < n ; i++) {
      in(t[i]);
   }
   sort(t , t + n);
   int sol = 0;
   for (int i = 0 ; i < n ; ) {
      int j = i + 1;
      while (j < n) {
         if (j - i >= c) break;
         if (t[j] - t[i] > k) break;
         j++;
      }
      i = j, sol++;
   }
   printf("%d\n" , sol);
   return;
}

int main() {
   #ifdef multipleCase
      int nQ; in(nQ);
      while (nQ--)
         work();
   #endif
   #ifdef singleCase
      work();
   #endif
   return 0;
}

void in(int &x) {
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-') {
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	  x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 4120
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<tuple<string, int, int>> a(n);
    rep(i, n) {
        string s;
        int p;
        cin >> s >> p;
        a[i] = make_tuple(s, -p, i+1);
    }
    sort(a.begin(), a.end());
    for (auto b: a) {
        cout << get<2>(b) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);
    
    ll x; cin >> x;

    ll t = 100;

    int ans = 0;
    while (t < x) {
        t += (double(t) * 0.01) / 1;
        ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = 100000000+7;
const ll MAX_N = 1000;

ll n,m;
string s,t;
ll a,b;

int main(){
  cin>>n>>a>>b;
  cin>>s;
  ll total=0;
  ll ab_num=0;
  for(int i=0;i<s.size();i++){
    //cout<<"total= "<<total<<" ab_num= "<<ab_num<<endl;
    if(s[i]=='a'){
      if(total<a+b){
        cout<<"Yes"<<endl;
        total++;
      }
      else cout<<"No"<<endl;
    }else if(s[i]=='b'){
      if(total<a+b && ab_num<b){
        cout<<"Yes"<<endl;
        total++;
        ab_num++;
      }
      else cout<<"No"<<endl;
    }else if(s[i]=='c'){
      cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 896
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#include<cstdlib>
#include<cctype>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll maxn = 1e5 + 5;
const ll maxm = 1e3 + 5;
template<class T>
inline T qread(T &IEE){
	register T x = 0, f = 1;
	register char ch = getchar();
	while(!isdigit(ch)){
		if(ch == '-'){
			f = -f;
		}
		ch = getchar();
	}
	while(isdigit(ch)){
		x = (x << 1) + (x << 3) + (ch ^ 48);
		ch = getchar();
	}
	return IEE = x * f;
}
template<class T>
inline void qwrite(T a){
	if(!a){
		putchar('0');
		return ;
	}
 	if(a < 0){
		putchar('-');
		a = -a;
	}
	if(a > 9) qwrite(a / 10);
	putchar(a % 10 + 48);
	return ;
}
template<class T>
inline T ab(T a){
	return (a > 0) ? a : -a;
}
template<class T>
inline void swa(T &a, T &b){
	a ^= b ^= a ^= b;
	return ;
}
string s;
int main(){
//	freopen("1.in", "r", stdin);
//	freopen("1.out", "w", stdout);
	cin >> s;
	cout << s[0] << (int)(s.size()) - 2 << s[(int)(s.size()) - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

#define repr(i, n) for(int i = n; i >= 0; i--)
#define reprl(i, n) for(ll i = n; i >= 0; i--)
#define all(v) v.begin(), v.end()

const ll mod=1000000007;

int countBits(int in){
  int res=0;
  for(int i=0;i<10;i++){
    int msk=1<<i;
    if((in&msk)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}
const string outputYesNo(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s,t;cin>>s>>t;
  t.resize(s.size());
  cout<<outputYesNo(s==t)<<endl;
  return 0;
}


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

ll dp[1010][1010][3] = {0};

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

    string s;
    cin >> s;
    int n = s.size();

    vector<int> a(n + 2);
    s = 'X' + s + 'X';
    int i = 0, j = 0;

    while (i <= n) {
        i++;
        if (s[i] != s[i + 1]) {
            int k = i - j;
            if (s[i] == 'R') {
                a[i + 1] += k / 2;
                a[i] += k - k / 2;
            } else {
                a[j] += k / 2;
                a[j + 1] += k - k / 2;
            }
            j = i;
        }
    }
    rep(i, 1, n + 1) cout << a[i] << ' ';
    cout << endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
T = [int(i) for i in input().split()]
m = int(input())
P = []
X = []
for i in range(m):
    p, x = map(int, input().split())
    P.append(p)
    X.append(x)

sum_t = sum(T)
for i in range(m):
    print(sum_t - T[P[i]-1] + X[i])

Measured memory_bytes: 3064
nk = input().split()
n = int(nk[0])
k = int(nk[1])

a = list(map(lambda x:int(x), input().split()))

visited_i = [-1]*n

i = 0
visited_i[0] = 0

loops = -1
loopn = -1

nowp = 0
while i < k:
  i += 1
  nowp = a[nowp]-1
  #print(nowp)
  
  if visited_i[nowp] != -1 and loops == -1:
    loops = nowp
    loopn = i-visited_i[nowp]
    
    #print("loopn = "+str(loopn), end = " ")
    #print(nowp)
    
    k = (k-i)% loopn
    i = 0
    #print("k = "+str(k))
  else:
  	visited_i[nowp] = i

#print(visited_i)
print(nowp+1)

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

int main() {
    string N;
    cin >> N;
    char c = N[N.length()-1];
    string ans;
    if(c=='3') ans="bon";
    else if(c=='0'||c=='1'||c=='6'||c=='8') ans = "pon";
    else ans = "hon";

    cout << ans << endl;
}

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



int main() {
	int n,t;
	int a;
	int minValue = 1e9 + 1;
	int point = 0;
	int pointCount = 0;

	cin >> n >> t;

	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a < minValue) {
			minValue = a;
			continue;
		}

		int tmpPoint = a - minValue;
		if (point > tmpPoint) {
			continue;
		} 
		if (point == tmpPoint) {
			pointCount++;
			continue;
		}
		pointCount = 1;
		point = tmpPoint;
	}

	cout << pointCount << endl;

	return 0;
}

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

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


  if(A > B){
  	if(A > C){
    	cout << (10*A)+B+C << endl;
    }else{

    	cout << (10*C)+A+B << endl;
    }

  }else{

  	if(B > C){
    	cout << (10*B)+A+C << endl;
    }else{
    	cout << (10*C)+A+B << endl;
    }
  }
}


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;
const int M=1e9 + 7;

string inttos(int num)
{
    return to_string(num);
}

int stoint(string sss)
{
    return stoi(sss);
}

int32_t main()
{
	IOS;
	//memset(dp,-1,sizeof(dp));	
	int T;
	T=1;
	while(T--)
	{
		int k,n;
		cin >> k >> n;
		int a[n+5];
		int ans = 0;
		rep(i,1,n)
		{
			cin >> a[i];
		}
		ans = a[n] - a[1];
		rep(i,2,n)
		{
			ans = min(ans,k - (a[i]-a[i-1]));
		}
		ans = min(ans, k - (k-a[n] + a[1]));
		cout << ans << endl;
	}
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'
//END OF TEMPLATE

ll t[3], n;

ll ways(int pos, ll rem){
	if(pos==2) return rem%t[pos]==0;
	ll ret=0;
	for(ll i=0; i*t[pos]<=rem; i++){
		ret+=ways(pos+1, rem-i*t[pos]);
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	FOR(i, 0, 2) cin>>t[i];
	cin>>n;
	cout<<ways(0, n)<<ent;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,h;
    cin >> h >> a;
    int count = 0;
    while(h>0){
        count ++;
        h -= a;
    }
    cout << count << endl;
    return 0;
 
}

Measured memory_bytes: 256
n = int(input())
As = list(map(int, input().split()))

MOD = 1_000_000_007

csum = [0] * (n + 1)
for i in range(n):
    csum[i + 1] = csum[i] + As[i]

ans = 0
for i in range(n - 1):
    ans += As[i] * (csum[n] - csum[i + 1]) % MOD

print(ans % MOD)


Measured memory_bytes: 31444
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := readInt()
	p := make([]int, n)
	for i := range p {
		p[i] = readInt()
	}
	ans := 0
	for i := 0; i < n; i++ {
		if p[i] == i+1 {
			ans++
			if i+1 < n && p[i+1] == i+2 {
				i++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1920
from collections import deque

H, W = [int(x) for x in input().split()]
board = []
for _ in range(H):
    board.append(input())

white = sum([board[h].count('.') for h in range(H)])

dist = {(x, y):white + 1 for x in range(W) for y in range(H)}
q = deque([(0, 0)])
dist[(0, 0)] = 1
while q:
    x, y = q.popleft()
    for d in range(4):
        nx, ny = x + int(((1j)**d).real), y + int(((1j)**d).imag)
        if nx < 0 or W <= nx or ny < 0 or H <= ny:
            continue
        if board[ny][nx] == '#':
            continue
        if dist[(nx, ny)] <= white:
            continue
        dist[(nx, ny)] = dist[(x, y)] + 1
        q.append((nx, ny))

lenofpath = dist[(W - 1, H - 1)]
ans = white - lenofpath
print(ans)

Measured memory_bytes: 9496
def cmb(n, r, mod):#コンビネーションの高速計算　
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] * g2[n-r])%mod

mod = 10**18+7 #出力の制限
N = 50
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,K,T,S=map(int,input().split())
a=list(map(int,input().split()))

must0=[i for i in range(18) if S>>i &1==0]
must1=[i for i in range(18) if T>>i &1==1]

A=[]
for val in a:
    check=True
    for j in must0:
        check=check&(val>>j &1==0)
    for j in must1:
        check=check&(val>>j &1==1)
    if check:
        A.append(val)

if not A:
    print(0)
    exit()

bit=[]
for i in range(18):
    if i not in must0 and i not in must1:
        bit.append(i)

for i in range(len(A)):
    temp=0
    for j in range(len(bit)):
        temp+=(A[i]>>bit[j] &1==1)*2**j
    A[i]=temp

ans=0
n=len(bit)
for i in range(2**n):
    dic={}
    for a in A:
        val=a&i
        if val not in dic:
            dic[val]=0
        dic[val]+=1
    temp=0
    for val in dic:
        for j in range(1,min(K,dic[val])+1):
            temp+=cmb(dic[val],j,mod)
    popcount=0
    for j in range(n):
        popcount+=(i>>j &1)
    ans+=temp*(-1)**popcount

print(ans%mod)

Measured memory_bytes: 70856
#include <iostream>
#include <cmath>
#include <string>
#include <string.h>
typedef long long ll;
using namespace std;

#define repr(i, from, to) for (int i = (int)from; i < (int)to; i++)
#define rep(i, N) repr(i, 0, N)

#define MAX_H 6
#define MAX_W 6

ll h, w, k;
string c[MAX_H];

void solve()
{
    ll result = 0;
    rep(i, 1 << h) rep(j, 1 << w)
    {
        ll count = 0;
        rep(s, h) rep(t, w)
        {
            if ((i & (1 << s)) && (j & (1 << t)) && c[s][t] == '#')
                count++;
        }
        if (count == k)
            result++;
    }
    cout << result << endl;
}

int main()
{
    cin >> h >> w >> k;
    rep(i, h) cin >> c[i];

    solve();
}


Measured memory_bytes: 3644
n, m, x = [int(i) for i in input().split()]
a = []
c = []
for i in range(n):
    inp = [int(i) for i in input().split()]
    c.append(inp[0])
    a.append(inp[1:])

ok = False
ans = float('inf')
for bit in range(1 << n):
    o = [0] * m
    tot = 0
    for i in range(n):
        if bit >> i & 1:
            tot += c[i]
            for j in range(m):
                o[j] += a[i][j]

    allOk = True
    for i in o:
        if i < x:
            allOk = False
            break
    if allOk:
        ok = True
        ans = min(ans, tot)

if ok:
    print(ans)
else:
    print(-1)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    int ans = 1000- n%1000;
    ans = ans%1000;
    cout << ans << endl;

    
    return 0;
}


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

typedef long long ll;
ll n;

int main()
{
    cin >> n;

    vector<tuple<string, int, int>> v;
    for (int i = 1; i <= n; i++)
    {
        string s;
        int p;
        cin >> s >> p;
        v.push_back(make_tuple(s, -p, i));
    }
    sort(v.begin(), v.end());

    for (auto &&i : v)
    {
        cout << get<2>(i) << endl;
    }
    
}

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

string S, T, U;
int A, B;

int main(){
    cin >> S >> T >> A >> B >> U;
    if(S==U)A--;
    else if(T==U) B--;
    cout << A << " " << B << endl;
    return 0;
}

Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    vector <ll> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];

    vector <ll> fac(n + 1), inv(n + 1), inv_sum(n + 1);
    fac[0] = inv[0] = fac[1] = inv[1] = 1;
    inv_sum[0] = 0;
    inv_sum[1] = 1;
    for (ll i = 2; i <= n; i++) {
        fac[i] = fac[i - 1] * i % MOD; // n!
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD; // n^-1
        inv_sum[i] = (inv_sum[i - 1] + inv[i]) % MOD;
    }

    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans = (ans + (x[i + 1] - x[i]) * inv_sum[i + 1] % MOD) % MOD;
    }

    cout << ans * fac[n - 1] % MOD << "\n";
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>

using namespace std;

int n, x, y;

void solve() {
  vector<int> cnt(n+1);
  for (int i=1;i<n;i++) {
    for (int j=i+1;j<=n;j++) {
      int dist = min(j - i, min(abs(x - i) + abs(y - j), abs(x - j) + abs(y - i)) + 1);
      cnt[dist]++;
    }
  }
  for (int i=1;i<n;i++) {
    cout << cnt[i] << endl;
  }
}

int main() {
  cin >> n >> x >> y;
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
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; }
const ll INF = 1e10;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    if (b/a > c) PRINT(c);
    else PRINT(b/a);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a[11];
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<n;i++)	
		cin>>a[i];
	int ans=1e9;
	for(int mask=0;mask<(1<<(n-1));mask++){
		int cnt=__builtin_popcount(mask);;
		int tot=cnt;
		vector<int> cur(cnt+1,0);
		for(int j=0;j<m;j++){
			int p=0;
			for(int i=0;i<n;i++){
				cur[p]+=(a[i][j]=='1');
				if(mask>>i&1)
					p++;
			}
			bool bad=false;
			for(int i=0;i<cur.size();i++)
				if(cur[i]>k)
					bad=true;
			if(bad){
				tot++;
				fill(cur.begin(),cur.end(),0);
				int p=0;
				for(int i=0;i<n;i++){
					cur[p]+=(a[i][j]=='1');
					if(mask>>i&1)
						p++; 
				}
				bool flag=false;
				for(int i=0;i<cur.size();i++)
					if(cur[i]>k)
						flag=true;
				if(flag)
					tot=1e9;
			}
		}
		ans=min(tot,ans);
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    ll h,w,n;
    cin >> h >> w >> n;
    map<pair<ll,ll>,ll> mp;
    for(int i = 0;i < n;i ++){
        ll a,b;
        cin >> a >> b;
        a --;b --;
        for(int i = -1;i < 2;i ++){
            for(int j = -1;j < 2;j ++){
                ll y=a+i,x=b+j;
                if((y-1)*(h-2-y)>=0&&(x-1)*(w-2-x)>=0) mp[make_pair(y,x)] ++;
            }
        }
    }
    for(int i = 0;i < 10;i ++){
        ll ans=0;
        for(auto ite = mp.begin();ite != mp.end();++ite){
            if(ite->second==i) ans ++;
        }
        if(!i) cout << (h-2)*(w-2)-mp.size() << endl;
        else cout << ans << endl;
    }
    return 0;
}

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

int main(){
	while(1){
		int n,r;
		cin>>n>>r;
		if(n==0&&r==0)break;
		vector<int> a(n);
		for(int i = 0;i<n;i++){
			a[i]=n-i-1;
		}
		for(int i = 0;i<r;i++){
			int p,c;
			cin>>p>>c;
			for(int j=0;j<n;j++){
				if(a[j]<p-1){
					a[j]+=c;
				}else if(a[j]<p-1+c){
					a[j]-=(p-1);
				}
			}
			//cout<<i<<endl;
		}
		//cout<<"a"<<endl;
		for(int i=0;i<n;i++){
			if(a[i]==0)cout<<i+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 2984
import java.util.Scanner;

public class Main {
  public static void main(String[] args ) throws Exception {
    Scanner sc = new Scanner(System.in);
    double N = Double.parseDouble(sc.next());
	long takahashi = 100L;
    int count = 0;

    while(true) {
    	if(takahashi>=N) {
    		System.out.println(count);
    		break;
    	}
    	takahashi =  (long) (takahashi * 1.01);
    	count++;
    }
  }
}

Measured memory_bytes: 27076
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, D;
  cin >> N >> D;
  if(N %(2*D + 1) == 0){
  cout << N /(2*D + 1) << endl;
  }
  else{
     cout << N /(2*D + 1) + 1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n;
V<int> e[N];
int dfs(int a, int p){
  int r = 0;
  for(int b:e[a]) if(b!=p) r ^= dfs(b, a)+1;
  return r;
}
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  FOR(i, 1, n){
    int x, y;
    cin >> x >> y;
    x--; y--;
    e[x].pb(y);
    e[y].pb(x);
  }
  cout << (dfs(0, -1) ? "Alice" : "Bob") << endl;
}

Measured memory_bytes: 10368
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i, s, n) for(int i=(s); i<=(n); ++i)
#define outl(x) cout<< (x) << '\n'
using namespace std;

class UnionFind {
private:
   int *par;
   int *rank;
   const size_t N;

public:
   UnionFind(size_t n): N(++n), par(new int[N]), rank(new int[N]) {
      reps(i,0,N) par[i] = i, rank[i] = 0;
   }
   ~UnionFind() {
      delete[] par;
      delete[] rank;
   }
   int root(const int x) {
      if(par[x] != x) par[x] = root( par[x] );
      return (par[x]);
   }

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

   //success: 1   failed: 0
   bool unite(int x, int y) {
      x = root(x), y = root(y);
      if(x == y)return (false);
      link(x, y);
      return (true);
   }

   void link(const int x, const int y) {
      (rank[x] > rank[y]) ? par[y] = x : par[x] = y;
      if( rank[x] == rank[y] ) ++rank[y];
   }
};

signed main()
{
   cin.tie(0), ios::sync_with_stdio(false);
   int N, Q;
   cin >> N >> Q;
   UnionFind S(N);

   while(Q--) {
      int x, y;
      bool com;
      cin >> com >> x >> y;
      if(com == 1)outl( S.same(x,y) );
      else S.unite(x,y);
   }
}




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

int main(){
  int N;
  cin >> N;
  double f=0;
  
  vector<double> A(N);
  for(int i=0; i < N; i++){
    cin >> A.at(i);
  }
  
  for(int i=0; i < N; i++){
    f += (1 / A.at(i));
  }
  
  cout << fixed;
  cout << setprecision(15) << 1 / f << endl;
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main ()
{
long long a,b,c,x,y,ans;
cin>>a>>b>>c>>x>>y;

if (a+b<=2*c) {
	ans=a*x+b*y;
	}
else {
	if (x>=y) {
		if (a>2*c) {
			ans=2*c*y+(x-y)*2*c;
		}
		else {
			ans=2*c*y+(x-y)*a;
		}
	}
	else {
		if (b>2*c) {
			ans=2*x*c+2*(y-x)*c;
		}
		else {
			ans=2*x*c+b*(y-x);
		}
	}
}

cout<<ans;

return 0;
}

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

int main() {
  string s;
  int k;
  vector<string>data(0);
  cin >> s >> k;
  rep(i,s.size()){
    string sub = {s[i]};
    data.push_back(sub);
    for(int j = 1;j < k;j++){
      if(i+j >= s.size()) break;
      sub = sub+s[i+j];
      data.push_back(sub);
    }
  }
  sort(data.begin(),data.end());
  unique(data.begin(),data.end());
  cout << data[k-1] << endl;
}

Measured memory_bytes: 1660
import itertools

N = input()
N_len = len(N)
N_int = int(N)
ans = 0
for i in range(3, 10):
    target = list(itertools.product([3, 5, 7], repeat=i))
    for t in target:
        s = ''.join(map(str, t))
        a = int(s)
        if a <= N_int and s.count('3') and s.count('5') and s.count('7'):
            ans += 1
print(ans)


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

ll readLL(){
	ll i;
	scanf("%lld",&i);
	return i;
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

int main(){
	int k=read(),t=read();
	vi a(t);
	REP(i,t)
		a[i]=read();
	int mx=*max_element(a.begin(),a.end());
	int rem=k-mx;
	int ans=max(0,mx-(rem+1));
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,a[100010],b[100010],c[100010];
int d[100010];
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	rep(i,n)cin>>c[i];
	sort(a,a+n);
	sort(c,c+n);
	rep(i,n){
		d[i]=lower_bound(a,a+n,b[i])-a;
	}
	int ans=0;
	rep(i,n){
		ans+=d[i]*(c+n-upper_bound(c,c+n,b[i]));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::cout << (N + 1) / 2 << std::endl;

  return 0;
}


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

int main(void)
{
    int a, b, C;
    double x, S, L, h;
    scanf("%d %d %d", &a, &b, &C);

    double rad;
    double PI = acos(-1);
    rad = C * PI / 180;

    double sinC = sin(rad);
    h = b * sinC;
    S = a * h / 2;
    x = sqrt(a * a + b * b - 2 * a * b * cos(rad));
    L = a + b + x;

    printf("%lf\n%lf\n%lf\n", S, L, h);

    return 0;
}



Measured memory_bytes: 2072
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

int main(){

    int x;
    cin >> x;

    int tmp = x % 100;
    int cnt = tmp / 5;
    int r =0;
    if(tmp % 5 >0){
        r = 1;
    }
    cnt += r;

    if(x > 100*cnt){
        cout << 1 << endl;
    }
    else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int n,k,p;
  

  scanf("%d",&n);
    
  while(n-->0){
    scanf("%d%d",&k,&p);
    
    if(k%p==0){
      printf("%d\n",p);

    }else if(k>p){
      printf("%d\n",k%p);

    }else if(k<p){
      printf("%d\n",k); 
    }}
    
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<double> p(n);
  for(int i=0;i<n;i++)
    cin>>p.at(i);
  vector<vector<double>> dp(n+1,vector<double>(n+1,0));
  dp[0][0]=1;
  for(int j=1;j<=n;j++)
    dp[0][j]=dp[0][j-1]*(1-p.at(j-1));
  for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
      dp[i][j]=dp[i-1][j-1]*p.at(j-1)+dp[i][j-1]*(1-p.at(j-1));
  double s=0;
  for(int i=n/2+1;i<=n;i++)
    s+=dp[i][n];
  cout<<fixed<<setprecision(10)<<s<<endl;
}

Measured memory_bytes: 70656
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#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 rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define ts to_string
#define all(v) (v).begin(), (v).end()
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector <string>
#define vvs vector <vector<string>>
#define pq  priority_queue<int>
using ll = long long;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 2000000000;
const int MINF=-2000000000;
constexpr ll mod = 1e9 + 7;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */
/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }
    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
ll kind(vi SYURUI) {//vector<int>型の配列の要素の種類数
    int size = SYURUI.size();
    sort(all(SYURUI));
    int cnt = 1;
    rep(i, size-1) {
        if (SYURUI[i] != SYURUI[i + 1])cnt++;
    }
    return cnt;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int A, B, C; cin >> A >> B >> C;
    cout << max(C - (A - B), 0LL) << endl;
}




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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  bool kihbr = false;
  int p = 0;
  bool a = false;
  bool result = true;
  REP(i, SZ(s)) {
    switch(p) {
    case 0:
      if(s[i] == 'K') {
        a = false;
        p = 1;
      } else if(s[i] == 'A') {
        if(a) result = false;
        else  a = true;
      } else {
        result = false;
      }
      break;
    case 1:
      if(s[i] == 'I') p = 2;
      else result = false;
      break;
    case 2:
      if(s[i] == 'H') p = 3;
      else result = false;
      break;
    case 3:
      if(s[i] == 'B') {
        a = false;
        p = 4;
      } else if(s[i] == 'A') {
        if(a) result = false;
        else a = true;
      } else {
        result = false;
      }
      break;
    case 4:
      if(s[i] == 'R') {
        kihbr = true;
        a = false;
        p = 5;
      } else if(s[i] == 'A') {
        if(a) result = false;
        else a = true;
      } else {
        result = false;
      }
      break;
    case 5:
      if(s[i] == 'A') {
        if(a) result = false;
        else a = true;
      } else {
        result = false;
      }
      break;
    }
  }
  if(result && kihbr) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int ans;
signed main(){
	int n;
	cin>>n;
	vector<int>vec(n/2),vek(n/2);
	pair<int,int>k[100005],g[100005];
	for(int i=0;i<100005;i++){
		k[i].second=i;
		g[i].second=i;
	}
	for(int i=0;i<n;i++){
		if(i%2==0){
			cin>>vec[i/2];
			k[vec[i/2]].first++;
		}
		else{
			cin>>vek[i/2];
			g[vek[i/2]].first++;
		}
	}
	sort(k,k+100005);
	reverse(k,k+100005);
	sort(g,g+100005);
	reverse(g,g+100005);
	ans+=n/2-(max(k[0].first,g[0].first));
	if(k[0].second!=g[0].second){
		ans+=n/2-(min(k[0].first,g[0].first));
	}	
	else{
		ans+=n/2-(max(k[1].first,g[1].first));
	}
	for(int i=0;i<2;i++){
		//cout<<k[i].first<<" "<<k[i].second<<"  "<<g[i].first<<" "<<g[i].second<<endl;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4096