akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n, m, s, t;
long long init = 1e15;
vector<long long> dijkstra(vector<vector<pair<int, long long>>> graph, int start){
  vector<long long> ret(n,1e18);
  priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> que;
  que.push({0, start});
  ret[start] = 0;
  while(!que.empty()){
    auto p = que.top();
    que.pop();
    for(auto to: graph[p.second]){
      if(ret[to.first] > p.first + to.second){
        ret[to.first] = p.first + to.second;
        que.push({ret[to.first], to.first});
      }
    }
  }
  return ret;
}
int main(){
  cin >> n >> m >> s >> t;
  s--;
  t--;
  vector<vector<pair<int, long long>>> yen(n), snuuk(n);
  for(int i=0; i<m; i++){
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--;
    v--;
    yen[u].push_back({v, a});
    yen[v].push_back({u, a});
    snuuk[u].push_back({v, b});
    snuuk[v].push_back({u, b});
  }
  auto ycost = dijkstra(yen, s);
  auto scost = dijkstra(snuuk, t);
  vector<long long> cost(n);
  for(int i=0; i<n; i++) cost[i] = ycost[i] + scost[i];
  vector<long long> ans(n+1,0);
  for(int i=n-1; i>-1; i--)  ans[i] = max(ans[i+1], init - cost[i]);
  for(int i=0; i<n; i++) cout << ans[i] << endl;
}

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

int dp[5001][5001];
// a - b

int main()
{
    string a, b;
    cin >> a >> b;
    for(int i = 1; i <= a.size(); i++){
        for(int j = 1; j <= b.size(); j++){
            if(a[i-1]==b[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }
    
    int i = a.size(), j = b.size();
    string ans;
    while((i>0)&&(j>0)){
        if(a[i-1]==b[j-1]){
            ans = a[i-1] + ans;
            i--;
            j--;
        }
        else if(dp[i][j-1]<dp[i-1][j]) i--;
        else j--;
    }
    
    cout << ans;
    return 0;
}


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

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

    for(int i=1; i<=n; i++){
        if(i%3==0){
            printf(" %d", i);
        }
        else{
            int it = i;
            while(1){
                if(it <= 0){
                    break;
                }
                else{
                    if(it%10 == 3){
                        printf(" %d", i);
                        break;
                    }
                    it = it / 10;
                }
            }
        }
    }

    printf("\n");

    return 0;
}


Measured memory_bytes: 2084
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int main() {
	int x; cin >> x;
	string s = "ai1333";
	rep(i, x / 100) {
		s.push_back('3');
	}
	cout << s <<endl;
	//stop
	return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pii;
typedef pair<pii,pii> piiii;
typedef vector<pii> vii;
typedef vector<ll> vi;
typedef queue<ll> qi;
typedef queue<char> qc;
typedef queue<string> qs;
typedef vector<char> vc;
typedef vector<string> vs;
typedef map<char,ll> mpci;
typedef map<ll,ll> mpii;
typedef map<string,ll> mpsi;
typedef set<ll> sei;
typedef set<char> sec;
typedef set<string> ses;
typedef stack<ll> si;
typedef stack<char> sc;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pll> vpll;
typedef vector<pdd> vdd;
typedef unsigned int uint;
typedef long double ld;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vii> vvii;
/*=====================================================================*/
#define pb push_back
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define sz(a) (int)(a.size())
#define len(a) (int)(a.length())
#define all(s) (s).begin(),(s).end()
#define fi first
#define se second
#define be begin
#define en end
#define m_p make_pair
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define forn(i,p,n) for(int i=p;i<=n;i++)
#define ford(i,p,n) for(int i=n-1;i>=p;i--)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();++i)
#define zero(a) memset(a,0,sizeof(a))
#define number(a,num) memeset(a,num,sizeof(a))

/*=====================================================================*/

inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
/*======================================================================*/
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
/*======================================================================*/
const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};
/*======================================================================*/
int main()
{
  /*
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
  */
  /*====================================================================*/
  int n;
  read(n);
  int x=n/100;
  int mod=n%100;
  if(mod>x*5)
    cout<<0<<endl;
  else
    cout<<1<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

int N;

int gcd(int a,int b){
  if(b==0) return a;
  return gcd(b,a%b);
}

int main(int argc, char const *argv[]) {
  cin >> N;
  vector<int> A(N);
  for (size_t i = 0; i < A.size(); i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end());
  int before =*(A.end()-1);
  for(int i=A.size()-1;i>0;i--){
    before=gcd(A[i-1],before);
  }
  cout << before << endl;
}


Measured memory_bytes: 640
#include<iostream>

using namespace std;
// 插入排序思路：
// 1. 将第i个位置的元素的值保存，即v = a[i]；
// 2. 从第i-1个元素开始依次向前挪动一位,给即将插入的元素腾出位置，即a[i] = a[i-1]; i--;
// 3. 直到插入位置j，挪动停止，即a[j] = v;
// 4. 重复以上三步，直到最后一个元素归位


/*输出函数*/
void trace(int a[], int n){
    for (int i = 0; i < n; i++){
        if (i != n-1){
            printf("%d ", a[i]);
        }else{
            printf("%d\n", a[i]);
        }
    }
}


/*插入排序函数*/
void insertionSort(int a[], int n){
    int j , v;
    // 题目要求，未排序时也要输出一次
    trace(a, n);
    for (int i = 1; i < n; i++){
        v = a[i];
        j = i-1;
        while(j >= 0&& a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        // 题目要求，每归位一个输出一次
        trace(a, n);
    }
}

int main(){
    int n, i;
    int a[100];
    scanf("%d", &n);
    for (int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }
    insertionSort(a, n);
    return 0;
}


Measured memory_bytes: 3140
//50000 for aizu0056
//1000000 for aizu0185
#define M 32769
p[M+1];


int main(i,j,n){
  p[1]=1;
  for(;i<=M;i++)
    if(!p[i])
      for(j=i*2;j<=M;j+=i)
        p[j]=1;
  for(;scanf("%d",&n),n;){
    int i=2,s=0;
    for(;i<=n/2;i++){
      if(p[i])continue;
      if(!p[n-i]){
        s++;
      }
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 0
class RangeMinimumQuery:
    nmemb = 1
    size  = 1
    data  = []
    def __init__(self, n):
        self.nmemb = n
        while self.size < n: self.size *= 2
        self.data = [0] * (self.size * 2)
        
    def __find(self, start, end, id, left, right):
        if end <= left or right <= start:
            return 2 ** 31 - 1
        elif start <= left and right <= end:
            return self.data[id]
        else:
            mid = (left + right) / 2
            vl = self.__find(start, end, id * 2 + 1, left, mid)
            vr = self.__find(start, end, id * 2 + 2, mid, right)
            return min(vl, vr)
            
    def find(self, start, end):
        return self.__find(start, end, 0, 0, self.size)
        
    def update(self, pos, value):
        pos += self.size - 1
        self.data[pos] = value
        
        while(pos > 0):
            pos = (pos - 1) / 2
            vl = self.data[pos * 2 + 1]
            vr = self.data[pos * 2 + 2]
            self.data[pos] = min(vl, vr)
            
if __name__ == "__main__":
    n, q = map(int, raw_input().split())
    rmq = RangeMinimumQuery(n)

    for i in range(n):
        rmq.update(i, 2 ** 31 - 1)
        assert(rmq.find(i, i + 1) == 2 ** 31 - 1)
        
    for i in range(q):
        com, x, y = map(int, raw_input().split())
        if com == 0:
            rmq.update(x, y)
        else:
            print(rmq.find(x, y + 1))
    
            
            
        
            

Measured memory_bytes: 10336
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int h[3], m[3], s[3];
	int ah[3], am[3], as[3];
	int hflag = 0;
	int mflag = 0;
	int hour[3];
	int minute[3];
	int second[3];
	int i;
	
	
	for (i = 0; i < 3; i++){
		scanf("%d %d %d %d %d %d", &h[i], &m[i], &s[i], &ah[i], &am[i], &as[i]);
	
		if (as[i] - s[i] < 0){
			second[i] = 60 + (as[i] - s[i]);
			mflag++;
		}
		else {
			second[i] = as[i] - s[i];
		}
	
		if (am[i] - m[i] - mflag < 0){
			minute[i] = 60 + (am[i] - m[i] - mflag);
			hflag++;
		}
		else {
			minute[i] = am[i] - m[i] - mflag;
		}
	
		hour[i] = ah[i] - h[i] - hflag;
	
		mflag = 0;
		hflag = 0;
	}
	
	for (i = 0; i < 3; i++){
		cout << hour[i] <<" "<< minute[i] <<" "<<second[i]<< endl;
	}
	
	return (0);
}

Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define lol long long
signed main(){
  int n,m;
  cin >>n>>m;
  vector<int> a(m),key(m);
  for(int i=0;i<m;i++){
    int b;cin >>a[i]>>b;
    for(int j=0;j<b;j++){
      int c;
      cin >>c;
      key[i]|=1<<(c-1);
    }
  }
  vector<vector<int>> dp(m+2,vector<int>(1<<n,1e9));
  dp[0][0]=0;
  for(int i=0;i<m;i++){
    for(int bit=0;bit<(1<<n);bit++){
      dp[i+1][bit]=min(dp[i+1][bit],dp[i][bit]);
      dp[i+1][bit|key[i]]=min(dp[i+1][bit|key[i]],dp[i][bit]+a[i]);
    }
  }
  if(dp[m][(1<<n)-1]!=1e9) cout <<dp[m][(1<<n)-1]<<'\n';
  else cout <<"-1\n";
  return(0);
}

Measured memory_bytes: 19196
#include <algorithm>
#include <array>
#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::string s;

  std::cin >> s;

  int size = s.size(), acc[111111];

  acc[0] = 0;

  for (int i = 0; i < size; i ++)
    acc[i + 1] = acc[i] + (s[i] - '0');

  int l, r;

  for (l = 0, r = size; l < r; l ++, r --) {
    int c = acc[r] - acc[l];
    
    if (c == 0 || c == r - l) {
      std::cout << r << std::endl;

      return 0;
    }
  }

  assert(l == (size + 1) / 2);

  std::cout << l << std::endl;

  return 0;
}


Measured memory_bytes: 832
import sys, math
from functools import lru_cache
from collections import defaultdict
from decimal import Decimal
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N, P = mi()
    A = list(mi())

    if all(a%2==0 for a in A):
        print(0 if P else pow(2, N))
    else:
        print(pow(2, N-1))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10008
import * as fs from 'fs';

const input = fs.readFileSync("/dev/stdin", "utf8");
const [colors, nums, u] = input.split("\n")
const [s, t] = colors.split(" ")
let [a, b] = nums.split(" ").map(x => +x)

if (u === s) a--
if (u === t) b--

console.log(a, b)


Measured memory_bytes: 7372
import java.util.*;
import java.lang.*;

class Mod{
    static final long MOD = 1000_000_007;
    static final long[] fact = makeFactorialArray(1000000);
    static final long[] factInv = makeInversedArray(fact);

    public static long add(long a, long b){
        long tmp = (a+b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long adds(long... ar){
        long ans=0;
        for(long x:ar) ans = Mod.add(ans, x);
        return ans;
    }
    public static long sub(long a, long b){
        return add(a,-b);
    }
    public static long mult(long a, long b){
        long tmp = (a*b)%MOD;
        return tmp>=0 ? tmp : tmp+MOD;
    }
    public static long mults(long... ar){
        long ans=1;
        for(long x:ar) ans = Mod.mult(ans, x);
        return ans;
    }
    public static long power(long a, long x){ //calculate a^x
        if(x<0)return 0;
        if(x==0)return 1;
        if(x%2==0) {
            long half = power(a,x/2);
            return mult(half,half);
        }
        return (a*power(a,x-1)) % MOD;
    }
    public static long inverse(long a){
        return power(a,MOD-2);
    }
    public static long div(long a, long b){
        return mult(a, inverse(b));
    }
    public static long[] makeFactorialArray(int size){
        long[] array = new long[size];
        array[0]=1;
        for(int i=1;i<size;i++){
            array[i]=mult(array[i-1],i);
        }
        return array;
    }
    public static long[] makeInversedArray(long[] original){
        long[] array = new long[original.length];
        for(int i=0;i<original.length;i++){
            array[i] = inverse(original[i]);
        }
        return array;
    }
    public static long combination(int n, int r){
        if(n<0 || r<0 || n<r) return 0;
        return mult(fact[n], mult(factInv[r],factInv[n-r]));
    }

}

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        System.out.println(Mod.power(N,3));
    }
}


Measured memory_bytes: 39508
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 200001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, m, cnt[MAX_N];
bool ac[MAX_N];

signed main(){
    cin >> n >> m;
    REP(i, m){
        string s;
        ll p;
        cin >> p >> s;
        if(s == "WA" && !ac[p-1]) cnt[p-1]++;
        else if(s == "AC") ac[p-1] |= true;
    }
    ll cnt_ac = 0, cnt_wa = 0;
    REP(i, n){
        if(ac[i]){
            cnt_ac++;
            cnt_wa += cnt[i];
        }
    }
    cout << cnt_ac << " " << cnt_wa << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main(){
    int x,n,u;
    cin>>x>>n;
    set<int>s;
    for(int i=0;i<n;++i){
        cin>>u;
        s.insert(u);
    }
    int t=0;
    while(1){
        if(s.count(x-t)==0){
            cout<<x-t<<endl;
            break;
        }else if(s.count(x+t)==0){
            cout<<x+t<<endl;
            break;
        }
        ++t;
    }
}


Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long
#define MOD 1000000007

using namespace std;

int main(){
    string S;
    cin >> S;
    vector<int> a;
    vector<int> z;
    for(int i=0;i<S.size();i++){
        if(S[i]=='A'){
            a.push_back(i);
        }
        if(S[i]=='Z'){
            z.push_back(i);
        }
    }
    cout << z[z.size()-1]-a[0]+1 << endl;
    return 0;
}


Measured memory_bytes: 1364
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int ans=0,tmp=0;
    for(int i=0;i<n-1;i++){
        if(a[i]>=a[i+1])tmp++;
        else{
            ans=max(ans,tmp);
            tmp=0;
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4004
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int []a = new int [n];
		
		for(int i = 0 ; i < n ;i++) {
			a[i] = sc.nextInt();
		}
		
		Arrays.sort(a);
		int min = 1000000;
		for(int i = a[0] ; i <= a[n-1] ;i++) {
			int temp = 0;
			for(int j = 0 ; j < n ; j++) {
				temp +=(int)Math.pow(Math.abs(i - a[j]), 2);
			}
			//System.out.println(temp);
			
			min = Math.min(min, temp);
		}
		System.out.println(min);
	}

}


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

void input()
{ 
    #ifndef ONLINE_JUDGE 
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) ll a[n]; rep(i,0,n) cin>>a[i];
#define vector(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a,n) rep(i,0,n) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
class Graph
{
	map<int,vector<int>>adjList;
	int nodes;
	map<int,int>dp;
	public:
		Graph(int node)
		{
			nodes=node;
		}
		void addEdge(int u,int v)
		{
			adjList[u].pb(v);
		}
		void print()
		{
			for(auto j:adjList)
			{
				cout<<j.ff<<" ->";
				for(auto i:j.ss)
				{
					cout<<i<<"-";
				}
				cout<<endl;
			}


		}
		int dfshelper(int u)
		{
			if(dp.count(u))return dp[u];

			int max1=0;
			for(auto j:adjList[u])
			{
				//cout<<j<<" "<<curr<<endl;
				max1=max(max1,dfshelper(j)+1);

			}
			//cout<<"Returend From"<<u<<" value->"<<curr<<endl;
			return dp[u]=max1;
		}
		int dfs()
		{
			int max1=INT_MIN;
			rep(i,1,nodes+1)
			{
				max1=max(max1,dfshelper(i));
				//cout<<max1<<endl;
			}
			return max1;
		}

};
int main()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
   	//input();
   	int n,m;
   	cin>>n>>m;
   	Graph g(n);
   	rep(i,0,m)
   	{
   		int u,v;
   		cin>>u>>v;
   		g.addEdge(u,v);
   	}
   	cout<<g.dfs()<<endl;
}

 

Measured memory_bytes: 17792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(void){
    ll a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(a<b){
        if(a+t*v>=b+t*w){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }else{
        if(a-t*v<=b-t*w){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }

}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define rrep(i,n) for(int i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
#define yes "Yes"
#define no "No"
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int N,M;
int main(){
    cin >> N >> M;
    vector<int> divs;
    rep1(i,sqrt(M)) if(M % i == 0) divs.pb(i),divs.pb(M/i);
    int ans = 0;
    rep(i,sz(divs)) if(M/divs[i] >= N) ans = max(ans,divs[i]);
    pr(ans);
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int d, t, s; cin >> d >> t >> s;
  if(t * s >= d) cout << "Yes" << endl;
  else cout << "No" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string p,q,m;
    char c;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>c;
        p+=c;
        m+=(char)(i+49);
    }
    for(int i=0;i<n;i++){
        cin>>c;
        q+=c;
    }
    int r=1,a=0,b=0;
    do{
        if(m==p){
            a=r;
        }
        if(m==q){
            b=r;
        }
        r++;
    }while(next_permutation(m.begin(),m.end()));
    cout<<abs(a-b);
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void solve(long long N){
    int ans = 0;
    REP(i, N + 1) {
        if (i == 0) continue ;
        ans += i;
    }
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    string s;
    cin>>s;
    string ans;
    REP(i,s.size()) {
        if (i%2 == 0) ans.pb(s[i]);
    }
    cout<<ans<<endl;
    return 0;
}

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

int d[110][110];
int n, m, a[1010], b[1010], c[1010], r;
bool used[1010];

void warshall_floyd(int n){
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            for (int k = 0; k < n; k++){
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}

int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            d[i][j] = (i == j ? 0 : 1e9 + 7);
        }
    }
    for (int i = 0; i < m; i++){
        scanf("%d%d%d", &a[i], &b[i], &c[i]);
        a[i]--, b[i]--, d[a[i]][b[i]] = c[i], d[b[i]][a[i]] = c[i];
    }
    warshall_floyd(n);
    for (int i = 0; i < n; i++){
        for (int k = 0; k < m; k++){
            used[k] = used[k] || d[i][a[k]] + c[k] == d[i][b[k]] || d[i][a[k]] + c[k] == d[i][b[k]];
        }
    }
    for (int i = 0; i < m; i++)r += !used[i];
    printf("%d\n", r);
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007LL
#define MAX 100000
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

ll fact[MAX*10], rfact[MAX+10];

ll comb(ll n, ll r){
    if(n < r) return 0;
    else return (((fact[n] * rfact[r]) % MOD) * rfact[n-r]) % MOD;
}

ll subtractmod(ll x, ll y){
    return (x+MOD-y) % MOD;
}

signed main(){
    int n, d1, d2, tmp;
    scanf("%d", &n);
    vector<int> use(n+1, -1);
    rep(n+1){
        scanf("%d", &tmp);
        if(use[tmp] != -1){
            d2 = i;
            d1 = use[tmp];
            break;
        }else{
            use[tmp] = i;
        }
    }

    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    reppp(i, 2, n+1){
        fact[i] = (fact[i-1] * (ll)i) % MOD;
        rfact[i] = 1;
        ll k = MOD-2;
        ll a = fact[i];
        while(k > 0){
            if(k & 1){
                rfact[i] *= a;
                rfact[i] %= MOD;
            }
            a *= a;
            a %= MOD;
            k  >>= 1;
        }
    }
    reppp(i, 1, n+1){
        ll ans = subtractmod(comb((ll)n+1, (ll)i), comb((ll)(d1+n-d2), (ll)(i-1)));
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 3200
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define pli pair<long long , int>
#define pil pair<int ,long long>
#define pi acos(-1)
#define pb push_back
#define mkp make_pair
#define all(a) a.begin(), a.end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;




int main(){
    IOS
    //freopen("output.txt","w",stdout);
    string s;
    string t;
    cin>>s>>t;
    int n=s.length();
    int m= t.length();
    int dp[n+1][m+1];
    for(int i=0;i<n+1;i++){
        for(int j=0;j<m+1;j++){
            if(i==0 || j==0){
                dp[i][j]=0;

            }
            else if(s[i-1]==t[j-1]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }

        }
    }
    int i=n;
    int j=m;
    string ans = "";
    while(i>0 && j>0){
        if(dp[i-1][j]==dp[i][j]){
            i--;
        }
        else if(dp[i][j-1]==dp[i][j]){
            j--;
        }
        else{
            ans+=s[i-1];
            i--;
            j--;
        }
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}


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

using namespace std;

const long long INF = 1e18;

int a[200005];
long long dp[200005][3];

int main() {
	int n;
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	int k = 1 + n % 2;
	
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= k; j++) {
			dp[i][j] = -INF;
		}
	}
	
	dp[0][0] = 0LL;
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			if (dp[i][j] == -INF) continue;
			// skip
			if (j + 1 <= k) {
				dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j]);
			}
			
			// no skip
			if ((i + j) % 2 == 0) {
				// pick
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + a[i + 1]);
			}
			else {
				// no pick
				dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
			}
		}
	}
	
	printf("%lld\n", dp[n][k]);
}


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

MAX = int(1e9)
def main():
    S = int(input())
    x2 = int(1e9)
    if S%x2 != 0:
        y3 = (S // x2) + 1
        x3 = x2 - (S % x2)
    else:
        y3 = S // x2
        x3 = 0
    print(0, 0, x2, 1, x3, y3)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
N, K = list(map(int, input().split()))
snack = []
for i in range(K):
    number = int(input())
    s = list(map(int, input().split()))
    for j in range(len(s)):
        snack.append(s[j])

answer = 0
for i in range(1, N+1):
    if i not in snack:
        answer += 1

print(answer)

Measured memory_bytes: 9152
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int maxn = 110;
const int maxsize = 10100;

ll f[maxn][maxsize];
int a[maxn];

int main()
{
	//freopen("A.in","r",stdin);
	int n,p;
	scanf("%d%d",&n,&p);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	f[0][0] = 1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<maxsize;j++)
		{
			f[i][j] = f[i-1][j];
			if (j >= a[i]) f[i][j] += f[i-1][j-a[i]];
		}
	}
	ll ans = 0;
	for (int i=0;i<maxsize;i++)
		if (i % 2 == p) ans += f[n][i];
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 4224
import java.util.Arrays;
import java.util.Scanner;

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

        char SPACE = '.';
        char BOMB = '#';

        int h = sc.nextInt();
        int w = sc.nextInt();
        char s[][] = new char[h+2][w+2];

        for (int i = 0; i <= h+1; i++) {
            Arrays.fill(s[i], '.');
        }

        sc.nextLine();

        for (int i = 1; i <= h; i++) {
            String line = sc.nextLine();
            for (int j = 1; j <= w; j++) {
                s[i][j] = line.charAt(j-1);
            }
        }

        for (int i = 1; i <= h; i++) {
            for (int j = 1; j <= w; j++) {
                int count = 0;
                if (s[i][j] == '#') {
                    System.out.print('#');
                    continue;
                }

                if (s[i-1][j-1] == '#') count++;
                if (s[i][j-1] == '#') count++;
                if (s[i+1][j-1] == '#') count++;
                if (s[i-1][j] == '#') count++;
                if (s[i+1][j] == '#') count++;
                if (s[i-1][j+1] == '#') count++;
                if (s[i][j+1] == '#') count++;
                if (s[i+1][j+1] == '#') count++;
                System.out.print(count);
            }
            System.out.println();
        }

    }


}


Measured memory_bytes: 22484
N = int(input())
R = [int(input()) for _ in range(N)]
min_num = R[0]
now_profit = R[1] - R[0]
for i in range(1,N):
    now_profit = max(R[i]-min_num, now_profit)
    if min_num > R[i]:
        min_num = R[i]
print(now_profit)


Measured memory_bytes: 13596
import heapq

N = int(input())
An = [int(e) for e in input().split()]

def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr

    ref = sum([e for e in arr]) / len(arr)

    for e in arr:
        if e < ref:
            left.append(e)
        else:
            right.append(e)

    if len(left) == 0:
        return right

    left = quick_sort(left)
    right = quick_sort(right)

    return left + right

p = quick_sort(An)
v0 = p.pop()

q = [-v0]
heapq.heapify(q)

s = 0

while p:
    v = heapq.heappop(q)
    newv = p.pop()
    heapq.heappush(q, -newv)
    heapq.heappush(q, -newv)
    s -= v

print(s)





Measured memory_bytes: 152064
import _heapq as heapq
n, m = [int(i) for i in input().split()]
ab = []
for _ in range(n):
    a, b = [int(i) for i in input().split()]
    ab.append([a, -b])
ab.sort()
j = 0
ans=0
h = []
for i in range(1, m + 1):
    while j<n and ab[j][0] <= i:
        heapq.heappush(h, ab[j][1])
        j += 1
    if h:
        ans += heapq.heappop(h)
print(-ans)


Measured memory_bytes: 20712
#include <bits/stdc++.h>
using namespace std;
long long N,M;

int main(){
  cin >> N >> M;
  if(N%2 == 1){
    for(int i = 1; i <= M; i++){
      cout << i << " " << 2*M+1-i << endl;
    }
  }else{
    for(int i = 1; i <= M; i++){
      if(i <= N/4){
        cout << i << " " << N+1-i << endl;
      }else{
        cout << i << " " << N-i << endl;
      }
    }
  }
}

Measured memory_bytes: 3600
from sys import stdin
N, K = [int(_) for _ in stdin.readline().rstrip().split()]
D = []
A = []
for i in range(K):
  d = int(stdin.readline().rstrip())
  D.append(d)
  a = [int(_) for _ in stdin.readline().rstrip().split()]
  for _a in a:
    A.append(_a)
A = set(A)
print(N-len(list(A)))

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

using namespace std;
using   ll=long long;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

#define endl        	"\n"
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define int             long long int
#define pll				pair<int , int>

#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007
#define hell            998244353 

ll mod_pow(ll a,ll b,ll m) 
{
    ll res = 1;
    while(b)	
    {
        if(b&1) 	
        {
        	res=(res*a) % m;
        }
        a=(a*a) % m;
        b>>=1;
    }
    return res;
}

ll mod_inverse(ll a) 
{
	return mod_pow(a , mod-2 , mod);
}

void solve()
{
	int a , b , c;
	
	cin >> a >> b >> c;
	
	if(a+b+c >= 22) {
		cout << "bust";
	}
	else {
		cout << "win";
	}
}

signed main() {
    fast;
    
    int t = 1;
    
	//cin >> t;
    
    while(t--) {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;

int main(){
	string S;
	cin>>S;
	if(S[0]=='7'||S[1]=='7'||S[2]=='7'){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

const long long MOD = 1000000007;
typedef vector<long long> vec;
typedef vector<vec> mat;

mat make_mat(int n, int m) {
  return mat(n, vec(m));
}

mat mat_mul(const mat &a, const mat &b) {
  mat r = mat(a.size(), vec(b[0].size()));
  for (int i = 0; i < (int)a.size(); i++) {
    for (int k = 0; k < (int)a[i].size(); k++) {
      for (int j = 0; j < (int)b[k].size(); j++)
        r[i][j] = (r[i][j] + a[i][k] * b[k][j]) % MOD;
    }
  }
  return r;
}

mat mat_pow(mat a, ll b) {
  mat r = mat(a.size(), vec(a[0].size()));
  for (int i = 0; i < (int)a.size(); i++)
    r[i][i] = 1;
  while (b > 0) {
    if (b&1) r = mat_mul(r,a);
    a = mat_mul(a,a);
    b >>= 1;
  }
  return r;
}

void print_mat(mat &a) {
  putchar('\n');
  for (int i = 0; i < (int)a.size(); i++)
    for (int j = 0; j < (int)a[i].size(); j++)
      printf("%lld%c",a[i][j]," \n"[j+1==(int)a[i].size()]);
  putchar('\n');
}

int n;
ll k;

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  cin >> n >> k;

  mat a = make_mat(n,n);

  forn(i,n) forn(j,n) cin >> a[i][j];

  mat ak = mat_pow(a,k);

  ll res = 0;
  forn(i,n) forn(j,n) {
    res = (res + ak[i][j]) % MOD;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 384
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r,g=l+1,[i,l][l<H and A[i]<A[l]]
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


Measured memory_bytes: 64180
z=input().split(' ')

a=int(z[0])
b=int(z[1])
c=int(z[2])
d=int(z[3])

count=0
if d-a>0:
    count+=a
else:
    count=d

x=d-a
#print(count)
#print(x)

if x-b>0:
    y=x-b
    #print(y)
    if y-c>0:
        count-=c
    else:
        count-=y
else:
    pass

print(count)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
void solve()
{
	vector<int> v(3);
	int k;
	REP(i,3)
		cin>>v[i];
	cin>>k;
	sort(all(v));
	int sum = v[0]+v[1];
	while(k)
	{
		v[2]*=2;
		k--;
	}
	sum+=v[2];
	cout<<sum<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int K, T; cin >> K >> T;
	vi arr (T);
	int hi = 0;
	F0R(i, T) {
		cin >> arr[i];
		hi = max(hi, arr[i]);
	}

	print(max(2*hi - 1 - K, 0));
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;

 int f(int W, int n, vector <int>& w, vector <int>& p){
    
    vector < vector <int> > dp(n+1, vector <int> (W+1));
    
    for(int i=1 ; i<=n ; i++){
       for(int j=1 ; j<=W ; j++){
          
          int a,b;
          b = dp[i-1][j];
          a = p[i-1] + dp[i-1][j-w[i-1]];
          
          if(j>=w[i-1]) dp[i][j] = max(a,b);
          else dp[i][j] = b;
       }
    }
        return dp[n][W];
 }
 
  int32_t main() {
     int n,W; cin>>n>>W; 
     vector <int> w(n),p(n);
     for(int i=0 ; i<n ; i++) cin>>w[i]>>p[i];
     cout<<f(W,n,w,p);
}

Measured memory_bytes: 80256
#if __has_include("debug.h")
    #include "debug.h"
#else  
#include <bits/stdc++.h>
using namespace std;
#define d(...) 2;
#endif

#define int long long int

#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"      

#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ff first
#define ss second
#define eps 1e-10

#define gcd(a,b)            __gcd((a),(b))
#define lcm(a,b)            ((a*b)/gcd(a,b))

void solve();

char a[10][10];
char b[10][10];

int n,m,k;

void copy()
{
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			b[i][j]=a[i][j];
		}
	}
	
}

bool check()
{
	int black=0,i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(b[i][j]=='#')
			{
				black++;
			}
		}
	}
	return (black==k);
}

void color(int i,int j)
{
	for(int x=0;x<n;x++)
	{
		if(i&(1<<x))
		{
			for(int y=0;y<m;y++)
			{
				b[x][y]='R';
			}
		}
	}

	for(int x=0;x<m;x++)
	{
		if(j&(1<<x))
		{
			for(int y=0;y<n;y++)
			{
				b[y][x]='R';
			}
		}
	}

}



int32_t main()
{
    #ifdef DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
    #endif 

    fast
    
    int t = 1;
	// cin>>t;
	
	while(t--)
	    solve();
	return 0;  
}

void solve()
{
	int i,j;
	cin>>n>>m>>k;






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

	int cnt=0;

	for(i=0;i<(1LL<<n);i++)
	{
		for(j=0;j<(1LL<<m);j++)
		{
			copy();
			color(i,j);

			if(check())
			{
				d(i,j);
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;

}

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

//int sieve[9999999];

int main()
{
    ///BISMILLAHIR RAHMANIR RAHIM
   int a[5];
   for(int i=0;i<5;i++){
    cin>>a[i];
    if(a[i]==0){
        cout<<i+1<<" ";
    }
   }
   cout<<endl;
    /// A L H A M D U L I L L A H
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector")
typedef long double ld;
typedef long long ll;

struct Point {
    ll x, y, x1 = 0, y1 = 0;
    
    Point() {}
    
    Point(ll _x, ll _y, char c) {
        x = _x;
        y = _y;
        if (c == 'U') {
            y1 = 1;
        } else if (c == 'D') {
            y1 = -1;
        } else if (c == 'R') {
            x1 = 1;
        } else {
            x1 = -1;
        }
    }
};

vector<Point> vc;

ld dist(ld t) {
    ld max_x = -1e9, max_y = -1e9, min_x = 1e9, min_y = 1e9;
    for (auto p : vc) {
        ld xx = p.x + p.x1 * t;
        ld yy = p.y + p.y1 * t;
        max_x = max(max_x, xx);
        max_y = max(max_y, yy);
        min_x = min(min_x, xx);
        min_y = min(min_y, yy);
    }
    return (max_x - min_x) * (max_y - min_y);
}

int main() {
#ifdef LOCAL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(20);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        ll x, y;
        char c;
        cin >> x >> y >> c;
        vc.push_back(Point(x, y, c));
    }
    ld l = 0, r = 1e11;
    for (int i = 0; i < 700; ++i) {
        ld m1 = (r - l) / 3 + l;
        ld m2 = r - (r - l) / 3;
        ld a1 = dist(m1);
        ld a2 = dist(m2);
        if (a1 > a2) {
            l = m1;
        } else {
            r = m2;
        }
    }
    cout << fixed << min(dist(l), dist(r));
    return 0;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define all(v) ((v).begin()),((v).end())
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
double const EPS = 1e-12, PI = acos(-1);
const int N = 6e5 + 9, M = 1e3 + 9, OO = 1e9 + 7, MOD = 1e9 + 7, MOD2 = 998244353;
const ll inf = 1e18;

int main() {
    fastIO;
    int n, k, a;
    cin >> n >> k;
    map<int, int> mp;
    for(int i = 0; i < n; ++i) {
        cin >> a;
        mp[a]++;
    }
    vector<int> vv;
    for(auto it: mp) {
        vv.push_back(it.second);
    }
    sort(all(vv));
    int req = int(vv.size()) - k;
    ll total = 0;
    for (int i = 0; i < req; ++i) {
        total += vv[i];
    }
    cout << total;

    return 0;
}


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

using pii = pair<int, int>;
using vi = vector<int>;
using ll = long long;

constexpr int mod = 100000;

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> a(N), dice(M);
        for(int i = 0; i < N; ++i) {
            cin >> a[i];
        }
        for(int i = 0; i < M; ++i) {
            cin >> dice[i];
        }
        int now = 0, ans = 0;
        while(now < N - 1) {
            now += dice[ans++];
            if(now <= N - 1) {
                now += a[now];
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3028
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;

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

int main(){
    ll n,k; cin >> n >> k;
    ll g = n % k;
    chmin(g, k - g);
    cout << g << endl;
}

Measured memory_bytes: 256