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

int main() {
    int n;
    cin>>n;
    vector<long long> v;
    long long k;
    for (int i = 0; i < n; i++) {
        cin>>k;
        if (k % 2 == 0) v.push_back(k);
    }
    sort(v.begin(), v.end());
    int ans = 0;
    int nextIndex = 0;
    while (true) {
        bool evenUsed = false;
        for (int i = nextIndex; i < v.size(); i++) {
            if (v[i] % 2 == 0 && !evenUsed) {
                v[i] /= 2;
                if (v[i] % 2 == 1) nextIndex++;
                evenUsed = true;
            } else {
                v[i] *= 3;
            }
        }
        if (evenUsed == false) break;
        ans++;
    }
    cout<<ans<<endl;
}

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

void block(int n,vector<int> P,int s){
	int a;
	P.push_back(n);
	if(s==0){
		for(a=0;a<P.size();a++){
			printf("%d",P[a]);
			if(P.size()==1)printf("\n");
			else if(a<=P.size()-2)printf(" ");
			else printf("\n");
		}
	}else{
		for(a=s;a>0;a--){
			if(a<=n)block(a,P,s-a);
		}
	}
}

int main(void){
	int a;
	int n;
	vector<int> none;
	while(1){
		cin >> n;
		if(n==0)break;
		for(a=0;a<n;a++){
			block(n-a,none,a);
		}
	}
	return 0;
}

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

pair<ll ,ll> dp[3001][3001];
int main(){

string s , t ; cin >> s >> t ;
ll sl , tl ; sl = s.size(); tl = t.size();
dp[0][0].first = 0;dp[0][0].second = 0;
 dp[1][0].first= 0;dp[1][0].second= 0;
  dp[0][1].first= 0; dp[0][1].second= 0; ll ans = 0; pair<ll,ll> ind ;
for(ll i=0; i<=sl ; i++){
    for(ll j=0 ; j<=tl; j++){
    if(i==0 || j==0){ dp[i][j].first= 0; dp[i][j].second =0;}
    else {
 ll maxi = 0;  maxi = max(dp[i-1][j].first , dp[i][j-1].first);
   ll flag =0;
  if( s[i-1]== t[j-1]){ flag = 1;
      maxi= max(maxi , dp[i-1][j-1].first+ 1); }
     dp[i][j].first = maxi; ll sec ;
     if(maxi== dp[i-1][j-1].first+ 1 && flag){ sec =1  ;}
     else if(maxi==dp[i-1][j].first){sec = 2;}
     else { sec = 3;}  
       ans = max(ans, maxi); if(ans==maxi){ ind = make_pair(i,j); }
        dp[i][j].second = sec;
    }
}}

 string ret = ""; ll count =0;
  // backtracking to get the answer  
    while(count< ans){
           if(dp[ind.first][ind.second].second==1){ ret= ret+ s[ind.first-1]; ind.first--; ind.second--; count++;}
           else if(dp[ind.first][ind.second].second==2){ind.first--;}
           else { ind.second--;}
    }
   ll d = ret.size();

   for(ll i= d-1; i>=0; i--){ cout << ret[i];} cout << endl;

}

Measured memory_bytes: 144380
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		long d = long.Parse(Console.ReadLine());//long.Parseはstringをlongに変換。
    if(d == 22) Console.WriteLine("Christmas Eve Eve Eve");
    if(d == 23) Console.WriteLine("Christmas Eve Eve");
    if(d == 24) Console.WriteLine("Christmas Eve");
    if(d == 25) Console.WriteLine("Christmas");
	}
}

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

const int MOD = 1e9+7;
int fac(int x) {
    return x == 0 ? 1 : (1LL*x*fac(x-1)) % MOD;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, M;
    cin >> N >> M;
    if (N < M) swap(N,M);
    if (N == M) {
        cout << ((1LL*2*fac(M)*fac(N)) % MOD) << '\n';
    }
    else if (M == N-1) {
        cout << ((1LL*fac(M)*fac(N))%MOD) << '\n';
    }
    else {
        cout << 0 << '\n';
    }

}



Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> dp(n + 10, INF);
  vector<int> h(n);
  rep(i, n) cin >> h[i];
  dp[0] = 0;
  rep(i, n) {
    if(i + 2 < n) dp[i + 2] = min(dp[i] + abs(h[i + 2] - h[i]), dp[i + 2]);
    if(i + 1 < n) dp[i + 1] = min(dp[i] + abs(h[i + 1] - h[i]), dp[i + 1]);
    
  }

  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
N=int(input())

str_list = input().split(' ')
A_list = [int(x) for x in str_list]

import numpy as np
A = np.array(A_list)

arg = np.argsort(A)
arg += 1

for ii in range(N):
    if ii < N-1:
        print('%s ' % arg[ii], end='')
    else:
        print(arg[ii])


Measured memory_bytes: 25100
#include <iostream>

int main(){
   int A[3];
   for(int i=0; i<3; ++i)
      std::cin >> A[i];

   int max = A[0];
   if(max<A[1]) max = A[1];
   if(max<A[2]) max = A[2];

   int min = A[0];
   if(min>A[1]) min = A[1];
   if(min>A[2]) min = A[2];

   std::cout << max - min << std::endl;

   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, ans, temp;
  cin >> N;
  ans = 0;
  temp = 0;
  vector<double> vect(N);
  for (int i = 0; i < N; i++){
    cin >> vect.at(i);
  }
  for (int i = 0; i < N - 1; i++){
    if (vect.at(i) >= vect.at(i+1)) {
      temp++;
    }
    else {
      temp = 0;
    }  
    if (ans < temp) {
      ans = temp;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define MAXN 100000

int table[MAXN+5];

int main(int argc, char const *argv[])
{
	#ifdef DBG
	freopen("D.in", "r", stdin);
	freopen("D.out", "w", stdout);
	#endif

	int cut,num,ans;
	vector <int> after;

	while( ~scanf("%d %d",&cut,&num) ){

		for(int i = 0 ; i < num ; i++ )
			scanf("%d",&table[i]);
		sort(&table[0],&table[num]);

		if( cut > num ){
			printf("0\n");
			continue;
		}

		after.clear();
		for(int i = 1 ; i < num ; i++ )
			after.push_back(table[i]-table[i-1]);
		sort(after.begin(), after.end());

		ans = 0;
		for(int i = 0 ; i < num-(cut-1)-1 ; i++ )
			ans += after[i];
	
		printf("%d\n", ans);
	}

	return 0;
}

Measured memory_bytes: 1276
void main() {
	auto N = ri;
	auto S = rs;
	ulong res = ulong.max;
	auto A = new int[](N);

	// i番目含め左から今までのWの個数
	A[0] = S[0] == 'W';
	foreach(i; 1..N) A[i] = S[i] == 'W' ? A[i-1]+1 : A[i-1];

	// i番目含め左から今までのEの個数
	// C[i] = (i+1) - A[i];
	// 下二行はどちらも同じ結果をもつ

	auto C = iota(1, N+1).map!(a => a - A[a-1]).array;
	// auto C = iota(N).map!(a => (a+1) - A[a]).array;

	foreach(i; 0..N) {
		ulong tmp;
		tmp += C[$-1] - C[i]; // リーダーより右でEを向いている人の数
		tmp += i < 1 ? 0 : A[i-1]; // リーダーより左でWを向いている人の数
		res = min(res, tmp);
	}
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 4436
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) _OUTPUT_IMPL_(__VA_ARGS__)

int main() {
	in(int, a, b);
	out((a + b) % 24);
}

Measured memory_bytes: 256
#include <stdio.h>

int n, s[20];

int solve(int i, int m) {
	if (m == 0) {
		return 1;
	}
	if (i >= n) {
		return 0;
	}
	int res = solve(i + 1, m) || solve(i + 1, m - s[i]);
	return res;
}

int main(void)
{
	int t;
	int q;
	int i;
	int solve(int i, int m);

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &s[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &t);
		if (solve(0, t)) {
			printf("yes\n");
		}
		else {
			printf("no\n");
		}
	}

	return 0;
}




Measured memory_bytes: 1996
#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;


int main(){
    int N,D,X,A;
    cin>>N;
    cin>>D>>X;
    REP(i,N){
        cin>>A;
        //debug(i);
        for(int j=0;j*A+1<=D;j++){
          //  debug(j*A+1);
            X++;
        }

    }
    cout<<X<<endl;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
 {
   //freopen("in.txt","r",stdin);
   //freopen("out.txt","w",stdout);
   int a,b;
   cin>>a>>b;
   if(a>0&&a<10&&b>0&&b<10)
     cout<<a*b<<endl;
    else
    {
        cout<<"-1"<<endl;
    }
    
 }

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline

from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

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

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

n,m = myinput()
ab = [ list(myinput()) for _ in range(m) ]
# print(ab)

ab_sorted = mysort(ab,1)
# print(ab_sorted)

count = 0
e = 0
for i in range(m):
    ns = ab_sorted[i][0]
    ne = ab_sorted[i][1]
    if ns>=e:
        count += 1
        e = ne
    else:
        pass
print(count)

Measured memory_bytes: 64600
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define mp make_pair
#define vvll vector <vll>
#define vsi vector <si>
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    int n;
    cin>>n;
    n%=10;
    if (n==3)
        cout<<"bon";
    else
    {
        if (n==2||n==4||n==5||n==7||n==9)
            cout<<"hon";
        else
            cout<<"pon";
    }

}

Measured memory_bytes: 3648
N = int(input())
H = [int(_) for _ in input().split()] 

flag = True

ushiro = H[-1]
for i in H[::-1]:
   hitotsumae = i
   if hitotsumae > ushiro:
           if hitotsumae - 1 == ushiro:
                   ushiro = i -1
           else:
                   flag = False
   else:
           ushiro = i


    

if flag:
        print("Yes")
else:
        print("No")


Measured memory_bytes: 63984
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.stream.Stream;

public class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
    String s = br.readLine();
    String[] sa = s.split(" ");
    int[] na = Stream.of(sa).mapToInt(Integer::parseInt).toArray();
    int total = 0;
    for (int i = 1; i <= na[0]; i++) {
      int sum = sumDigits(i);
      if (sum >= na[1] && sum <= na[2]) {
        total += i;
      }
    }

    out.println(total);
    out.close();
  }

  public static int sumDigits(int n) {
    int sum = 0;
    while (n > 0) {
      sum += n % 10;
      n /= 10;
    }
    return sum;
  }
}

Measured memory_bytes: 34516
#include <stdio.h>

int main(){
    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);
    int a[n][m], b[m][l];
    long long c[n][l];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%d", &a[i][j]);
        }
    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < l; j++)
        {
            scanf("%d", &b[i][j]);
        }
    }
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < l; j++)
        {
            c[i][j]=0;
            for (int k = 0; k < m; k++)
            {
                c[i][j]+=a[i][k]*b[k][j];
            }
            if(j!=l-1)printf("%lld ", c[i][j]);
        }
        printf("%lld\n", c[i][l-1]);
    }
}


Measured memory_bytes: 2100
import collections
import math
import operator as op
from functools import reduce
from collections import Counter
import numpy as np
import math
import bisect
import heapq


MOD = 1000000007


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


def get_inputs(cast_func=None):
    if cast_func is None:
        return input().split()
    else:
        return list(map(cast_func, input().split()))


def get_input(cast_func=None):
    if cast_func is None:
        return input()
    else:
        return cast_func(input())


def is_prime(n):
    if n == 1:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True


def main():
    N = get_input(int)
    # if "7" in N:
    #     print("Yes")
    # else:
    #     print("No")


    ans = 0
    for i in range(1, N+1):
        if i % 3 != 0 and i % 5 != 0:
            ans += i

    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 27096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

  ll n; cin>>n; 
  vector<ll> a(n); rep(i,n){cin>>a.at(i);}
  
  ll min=a.at(0); ll ans=0;
  rep(i,n){
    if(min>a.at(i)){
      ans+=min-a.at(i); 
    }
  
    else{min=a.at(i);}
  
  }
  
  cout<<ans<<endl;
  
  
  
  
  
}


Measured memory_bytes: 4840
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		// for (; solver.hasNext();) {
		// solver.readBody(in.readLine());
		// }
		// solverS.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		// N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		int a = Integer.parseInt(strArr[0]);
		int b = Integer.parseInt(strArr[1]);
		int c = Integer.parseInt(strArr[2]);
		int d = Integer.parseInt(strArr[3]);
		if (Math.abs(c - a) <= d) {
			System.out.println("Yes");
		} else if ((Math.abs(a - b) <= d) && (Math.abs(c - b) <= d)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
	}

	public void solve() {

	}
}


Measured memory_bytes: 22612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

map<ll, ll> prime;
void factorize(int n) {
    for(int i = 2; i * i <= n; i++) {
        while(n % i == 0) {
            prime[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        prime[n] = 1;
    }
}

int main(void) {

    int x;
    cin>>x;
    for(int i=x;i>=1;i--){
        prime.clear();
        factorize(i);
        bool ch=true;
        // irep(j,prime){
        //     cout<<j->first<<" "<<j->second<<endl;
        // }
        irep(j,prime){
            if(j->second>1&&j->second==prime.begin()->second)continue;
            ch=false;
        }
        if(ch){
            fin(i);
            return 0;
        }
        // if(prime.size()==1&&prime.begin()->second>1&&prime.begin()->first>0){
        //     fin(i);
        //     irep(j,prime){
        //         cout<<j->first<<" "<<j->second<<endl;
        //     }
        //     return 0;
        // }
    }
    fin(1);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
typedef long long ll;
typedef int64_t in;

using namespace std;

ll n;
vector<pair<ll, ll>> a(300000);

int main(){
    cin >> n;
    rep(i,n){
        cin >> a[i].first >> a[i].second;
        ll temp = a[i].first;
        a[i].first = a[i].second;
        a[i].second = temp;
    }
    
    sort(a.begin(), a.begin()+n);
    
    ll sum=0;
    bool flag = true;
    rep(i,n){
        sum += a[i].second;
        if(sum > a[i].first){
            //cout << sum;
            flag = false;
            break;
        }
    }
    if(flag) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}


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

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

    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i=0; i<N; ++i) cin >> A[i];

    cout << 1 + (max(0, (N-K))+K-2) / (K-1) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
vector<int> v[1005];
int n,q,a,b,c;
int main(){
	cin>>n>>q;
	while(q--){
		cin>>a;
		if(a==0){
			cin>>b>>c;
			v[b].push_back(c);
		}else if(a==1){
			cin>>b;
			for(int i=0;i<v[b].size();i++)
				i>=1&&putchar(' '),cout<<v[b][i];
			cout<<"\n";
		}else
			cin>>b,v[b].clear();			
	}
	return 0;
}


Measured memory_bytes: 5920
#pragma GCC optimize (2)
#pragma G++ optimize (2)
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 924844033
#define MAX 200005
using namespace std;
//char nc()
//{
//	static char buf[100000],*p1=buf,*p2=buf;
//	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
char nc(){return getchar();}
int read()
{
	int x=0,y=1;
	char c=nc();
	while(!isdigit(c))
	{
		if(c=='-')y=-1;
		c=nc();
	}
	while(isdigit(c))
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=nc();
	}
	return x*y;
}
int n,head[MAX],cnt=0;
struct edge{
	int next,to;
}a[MAX<<1];
void add(int x,int y)
{
	a[++cnt].next=head[x];
	a[cnt].to=y;
	head[x]=cnt;
}
int sz[MAX];
long long A[MAX<<2],B[MAX<<2],fac[MAX],facinv[MAX];
void dfs(int x,int f)
{
	sz[x]=1;
	for(int i=head[x];i;i=a[i].next)
	{
		int t=a[i].to;
		if(t==f) continue;
		dfs(t,x);
		sz[x]+=sz[t];
	}
	if(x!=1) A[sz[x]]++;
	A[n-sz[x]]++;
}
long long mo(long long x)
{
	return x<mod?x:x-mod;
}
long long C(int down,int up)
{
	return fac[down]*facinv[down-up]%mod*facinv[up]%mod;
}
long long quick_pow(long long x,long long y)
{
	long long re=1;
	while(y)
	{
		if(y&1) re=re*x%mod;
		x=x*x%mod;
		y>>=1;
	}
	return re;
}
int rev[MAX<<2];
long long wi[MAX<<2];
const long long g=5;
int make(int n)
{
	int l=log2(n)+1;n=1<<l;
	for(int i=0;i<n;i++)
		rev[i]=((rev[i>>1]>>1)|((i&1)<<(l-1)));
	return n;
}
void dft(long long a[],int n,long long flag)
{
	for(int i=0;i<n;i++)
		if(rev[i]<i) swap(a[i],a[rev[i]]);
	for(int i=1;i<n;i<<=1)
	{
		long long wn=quick_pow(g,mod-1+flag*(mod-1)/(i<<1));
		wi[0]=1;
		for(int j=1;j<i;j++)
			wi[j]=wi[j-1]*wn%mod;
		for(int j=0;j<n;j+=i<<1)
			for(int k=0;k<i;k++)
			{
				long long x=a[j+k],y=a[j+k+i]*wi[k]%mod;
				a[j+k]=mo(x+y);a[j+k+i]=mo(x-y+mod);
			}
	}
	if(flag==-1)
	{
		long long inv=quick_pow(n,mod-2);
		for(int i=0;i<n;i++)
			a[i]=a[i]*inv%mod;
	}
}
int main()
{
	n=read();
	int x,y;
	for(int i=1;i<n;i++)
		x=read(),y=read(),add(x,y),add(y,x);
	dfs(1,0);
	fac[0]=1;
	for(int i=1;i<=n;i++)
		fac[i]=fac[i-1]*i%mod;
	facinv[n]=quick_pow(fac[n],mod-2);
	for(int i=n;i;i--)
		facinv[i-1]=facinv[i]*i%mod;
	for(int i=0;i<=n;i++)
		A[i]=A[i]*fac[i]%mod,B[i]=facinv[n-i];
	int ln=make(n*2);
	dft(A,ln,1);dft(B,ln,1);
	for(int i=0;i<ln;i++)
		A[i]=A[i]*B[i]%mod;
	dft(A,ln,-1);
	for(int i=1;i<=n;i++)
		printf("%lld\n",mo(1ll*n*C(n,i)%mod-1ll*facinv[i]*A[i+n]%mod+mod));
	return 0;
}


Measured memory_bytes: 37192
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans=LINF,a[ohara],b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n;
    rep(i,n)cin>>a[i];
    rrep(i,-100,101){
        ll cost=0;
        rep(j,n){
            cost+=abs(a[j]-i)*abs(a[j]-i);
        }
        ans=min(ans,cost);
    }
    Cout(ans);
    return 0;
}


Measured memory_bytes: 256
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
    

a, b, c = map(int, input().split())


if c % gcd(max(a, b), min(a, b)) == 0:
    ans = 'YES'
else:
    ans = 'NO'
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
double dis(pair<int,int>p,pair<int,int>q){
    double d=((p.first-q.first)*(p.first-q.first))+((p.second-q.second)*(p.second-q.second));
    return sqrt(d);
}
int main()
{
    
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2) cout<<"No"<<endl;
    else{
        if(s.substr(0,n/2)==s.substr(n/2,n-1))
        cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    //cout<<s.substr(n/2,n-1);

} 

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

int N,M;
int D[100010] = {0};

int main()
{
    scanf("%d%d",&N,&M);
    for(int i = 0; i < M; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        D[a]++;D[b]++;
    }
    for(int i = 1; i < N + 1; i++)
    {
        printf("%d\n",D[i]);
    }
    return 0;
}


Measured memory_bytes: 256
check='abcdefghijklmnopqrstuvwxyz'
s=input()
l=len(s)
if l<=25:
  for i in range(25):
    if check[i] not in s:
      print(s+check[i])
      break
else:
  s2=''.join(map(str,sorted(s,reverse=True)))
  if s==s2:
    print(-1)
  else:
    for i in range(25):
      if s[-(i+1)]>s[-(i+2)]:
        tmp1=s[:-(i+2)]
        tmp2=s[-(i+2):]
        break
    base=tmp2[0]
    minc=10**9
    for i in range(1,len(tmp2)):
      tmpv=ord(tmp2[i])-ord(base)
      if tmpv>0 and tmpv<minc:
        minc=tmpv
    print(tmp1+chr(ord(base)+minc))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> p;
long long N, A, B, C;
long long INF = 1e18;
vector<long long> l;
long long dfs(int i){
    long long ans = INF;
    if(i == N){
        long long res = 0;
        if(p[0].size() >= 1 && p[1].size() >= 1 && p[2].size() >= 1){
            res += (p[0].size() + p[1].size() + p[2].size() - 3) * 10;
            for(int j = 0; j < 3; j++){
                long long temp = 0;
                for(int k = 0; k < p[j].size(); k++){
                    temp += p[j][k];
                }
                if(j == 0) res += abs(temp - A);
                else if(j == 1) res += abs(temp - B);
                else if(j == 2) res += abs(temp - C);
            }
            return res;
        }
        else return INF;
    }
    for(int j = 0; j < 3; j++){
        p[j].push_back(l[i]);
        ans = min(dfs(i + 1), ans);
        p[j].pop_back();
    }
    ans = min(ans, dfs(i + 1));
    return ans;
}
int main(){
    cin >> N >> A >> B >> C;
    p.resize(3);//0がA1がB2がC
    l.resize(N);
    for(int i = 0; i < N; i++) cin >> l[i];
    cout << dfs(0) << endl;
}

Measured memory_bytes: 256
program Project1;
             
{$APPTYPE CONSOLE}
         
uses
  SysUtils,math;
var
  g,l,r,a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k,t,z:Integer;
  //l:array of Integer;
  s,s123,s1,s2,s3:string;
  tf:Boolean;
  //nyu:TStringList;
  xc,yc,space:char;
begin
  try
    { TODO -oUser -cConsole Main : ここにコードを記述してください }
    Read(x);
    Read(y);
    Readln(z);
    Writeln((x-z) div (y+z));
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

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

using namespace std;
struct node {
    long long a, b;
} e[1000000];

bool cmp(node a, node b) {
    return a.a < b.a;
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%lld %lld", &e[i].a, &e[i].b);
    }
    sort(e + 1, e + 1 + n, cmp);
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (m >= e[i].b) {
            ans += e[i].a * e[i].b;
            m -= e[i].b;
        } else {
            ans += e[i].a * m;
            m = 0;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
	int n;scanf("%d",&n);
	int ss=0;
	for(int i=1;i<=n;i++)
	{
		int x,k;scanf("%d%d",&x,&k);
		while(x%k!=0)
		{
			int dx=x/k+1;
			x=x-(x%k+dx-1)/dx*dx;
		}
		ss^=x/k;
	}
	printf(ss?"Takahashi\n":"Aoki\n");
	return 0;
}

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

#define ll long long int


int main()
{
	ll n;
	cin>>n;
	ll h[n+1];
	for(int i=1; i<=n; i++) cin>>h[i];
	ll dp[n+1];
// dp [i] denotes the cost to reach step i.
	dp[1] = 0;
	dp[2] = abs(h[2]-h[1]);
	dp[3] = min (abs(h[3]-h[2])+dp[2],abs(h[3]-h[1]));

	for(int i=4; i<=n; i++)
	{
		dp[i] = min (abs(h[i]-h[i-1])+dp[i-1],abs(h[i]-h[i-2])+dp[i-2]);
	}

	cout<<dp[n];

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[100000];
long long ans = 1;
bool k = 1;
int main(){
    int n;
    cin>>n;
    for(int i = 0; i<n; i++)
        cin>>a[i];
    sort(a,a+n);

    if(n%2==0){
        for(int i = 0; i<n; i++){
            if(i%2==0){
                if(a[i]==a[i+1]){
                    ans*=2;
                    ans%=1000000007;
                }
                else{
                    k = 0;
                }
            }
        }
    }
    else{
        if(a[0]!=0)
            k = 0;
        for(int i = 1; i<n; i++){
            if(i%2==1){
                if(a[i]==a[i+1]){
                    ans*=2;
                    ans%=1000000007;
                }
                else{
                    k = 0;
                }
            }
        }

    }
    if(k)
        cout<<ans<<endl;
    else
        cout<<0<<endl;


}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

char mp[100][100];

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	rep(i, 100) {
		if (i < 50) {
			rep(j, 100) mp[i][j] = '.';
		}
		else {
			rep(j, 100) mp[i][j] = '#';
		}
	}
	a--; b--;
	for (int i = 0; i < 50; i += 2) {
		if (b == 0) break;
		for (int j = 0; j < 100; j += 2) {
			mp[i][j] = '#';
			b--;
			if (b == 0) break;
		}
	}
	for (int i = 51; i < 100; i += 2) {
		if (a == 0) break;
		for (int j = 0; j < 100; j += 2) {
			mp[i][j] = '.';
			a--;
			if (a == 0) break;
		}
	}
	cout << 100 << ' ' << 100 << endl;
	rep(i, 100) {
		rep(j, 100) cout << mp[i][j];
		cout << endl;
	}
 	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;
int main ()
{
	string s;
	cin>>s;
	if(s=="Sunny")
	{
		printf("Cloudy");
		return 0;
	}
	else if(s=="Cloudy")
	{
		printf("Rainy");
		return 0;
	}
	else if(s=="Rainy")
	{
		printf("Sunny");
	}
	return 0;
}


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

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

    int sum = 0;
    rep(i, N) {
        int l, r;
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int answers = sc.nextInt();
        int kinds = sc.nextInt();

        int[] likeCounts = new int[kinds + 1];
        Arrays.fill(likeCounts, 0);

        for (int i = 0; i < answers; i++) {
            int ansCount = sc.nextInt();
            for (int j = 0; j < ansCount; j++) {
                likeCounts[sc.nextInt()]++;
            }
        }

        System.out.println(IntStream.of(likeCounts).filter(i -> i == answers).count());

    }
}

Measured memory_bytes: 28116
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w, h;
		for(;;) {
			h = sc.nextInt();
			w = sc.nextInt();
			
			if(h == 0 && w == 0) {
				break;
			}
			for(int j = 0; j < h; j++) {
				for(int i = 0; i < w; i++) {
					System.out.print("#");
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}


Measured memory_bytes: 35492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    //          int N = int.Parse(Console.ReadLine());
    //          string S = Console.ReadLine();
    Dictionary<string, long> choice = new Dictionary<string, long>();

    public static void Main()
    {
        int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(Math.Min(sp[0]*sp[1],sp[2]));

    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
#include<bitset>
#include<random>
#include<time.h>

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;
const ll INF = 1LL << 60;

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



// Main Code


int main()
{
  int t, a, b;
  cin>>t>>a>>b;
  cout<<min((a*t), b)<<endl;
}


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

int main() {

    int n;
    scanf("%d", &n);
    char s[4];

    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    for (int i = 0; i < n; i++) {

        scanf("%s", s);
        
        if (strcmp(s, "AC") == 0) {
            ac++;
        } else if (strcmp(s, "WA") == 0) {
            wa++;
        } else if (strcmp(s, "TLE") == 0) {
            tle++;
        } else if (strcmp(s, "RE") == 0) {
            re++;
        }

    }

    printf("AC x %d\n", ac);
    printf("WA x %d\n", wa);
    printf("TLE x %d\n", tle);
    printf("RE x %d\n", re);


    return 0;
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N;
	cin >> N;
	string S;
	rep(i,N) S+="a";
	int a[15];
	rep(i,N) a[i]=0;
	int num=N-1;
	while(!a[0]){
		string ans=S;
		rep(i,N) ans[i]+=a[i];
		cout << ans << endl;
		for(int j=N-1; j>=num; j--){
			int M=0;
			rep(k,j) M=max(M,a[k]);
			if(a[j]<=M){
				a[j]++;
				for(int k=j+1; k<=N-1; k++) a[k]=0;
				break;
			}
			if(j==num){
				for(int k=num; k<=N-1; k++) a[k]=0;
				a[j-1]=1;
				num--;
				break;
			}
		}
	}

	return 0;
}

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

int main(void){

    int N,Y; cin>>N>>Y;

    for (int Yukichi = 0; Yukichi <= N; ++Yukichi) {
        int mansatu = Yukichi*10000;
        for (int Higuchi = 0; Higuchi <= N-Yukichi; ++Higuchi) {
            int gosenensatu = Higuchi * 5000;
            int Noguchi = N - (Yukichi + Higuchi);
            int senensatu = Noguchi * 1000;

            if (mansatu + gosenensatu + senensatu == Y) {
                cout << Yukichi << " " << Higuchi << " " << Noguchi << endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int a,b;
	cin>>a>>b;
	vint v(b);
	rep(i,b) cin>>v[i];
	sort(ALL(v));
	if(b==1){
		cout<<a-1<<endl;
		return;
	}
	if(v.back()-1<=a-v.back()) {
		cout<<0<<endl;
	}
	else{
		cout<<v.back()-1-a+v.back()<<endl;
	}
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
import sys

readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

N = int(readline().rstrip())
H = list(map(int, readline().split()))

LIM = 10 ** 9
dp = [LIM] * N
dp[0] = 0
for i in range(N):
    if i+1 < N:
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i] - H[i+1]))
    if i+2 < N:
        dp[i+2] = min(dp[i+2], dp[i] + abs(H[i] - H[i+2]))

ans = dp[-1]
print(ans)

Measured memory_bytes: 12328
S=int(input())

def comb(n,k,p):
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p
  
x = S//3
y = 1000000007
ans = 0
for i in range(x):
  ans = ans + comb(S-2*i-3,i,y)
  
if S >= 3:
    x = S//3
    y = 1000000007
    ans = 0
    for i in range(x):
        ans = ans + comb(S-2*i-3,i,y)
    print(ans%y)
else:
    print(0)

Measured memory_bytes: 9268
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define cyes cout << "YES" << endl
#define cno cout << "NO" << endl
#define f(i, a, n) for(int i = a; i < n; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mod 1000000007
int gcd(int a, int b) { if (!b) return a; return gcd(b, a % b); }  
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
using namespace std;

int32_t main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
  int x,y;

  

  cin >> x >> y;

  if(y%2 !=0)
    {cout << "No";
    return 0;}

  if(y >= 2*x && y<= 4*x)
    cout << "Yes";
    else
      cout << "No";

  
  
  return 0;
}

Measured memory_bytes: 3648
N,W = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]

dp = [{} for i in range(N+1)]
dp[0][0] = 0
for i in range(1,N+1):
    w,v = src[i-1]
    for w0,v0 in dp[i-1].items():
        if w0 in dp[i]:
            dp[i][w0] = max(dp[i][w0], v0)
        else:
            dp[i][w0] = v0
        if w0+w > W: continue
        if w0+w in dp[i]:
            dp[i][w0+w] = max(dp[i][w0+w], v0+v)
        else:
            dp[i][w0+w] = v0+v
print(max(dp[-1].values()))

Measured memory_bytes: 654960
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include <algorithm>
#include<initializer_list>
#include<map>
#include<set>
using namespace std;

int main() {
	string s;
	cin >> s;
	for (int i = 0; i < s.length()-1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}





Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            label:
            int n = Parse(ReadLine());
            var list = new List<string>();
            if (n % 2 == 0)
            {
                for (int i = 1; i < n; ++i)
                {
                    for (int j = i + 1; j <= n; ++j)
                    {
                        if (i + j != n + 1)
                        {
                            list.Add($"{i} {j}");
                        }
                    }
                }
            }
            else
            {
                for (int i = 1; i < n; ++i)
                {
                    for (int j = i + 1; j <= n; ++j)
                    {
                        if (i + j != n)
                        {
                            list.Add($"{i} {j}");
                        }
                    }
                }
            }
            WriteLine(list.Count);
            foreach (var s in list) WriteLine(s);
            //goto label;
        }
    }
}


Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, s: "List[str]", t: "List[int]", X: str):
    idx = 0
    for i,r in enumerate(s):
        if r == X:
            idx = i

    print(sum(t[idx+1:]))
    return
    

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [str()] * (N)  # type: "List[str]"
    t = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        s[i] = next(tokens)
        t[i] = int(next(tokens))
    X = next(tokens)  # type: str
    solve(N, s, t, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rs(a, b) ((a) >> (b))
#define ls(a, b) ((a) << (b))
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

bool cmp(ii a, ii b) { return a.F > b.F; }

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    int arr[n];
    ii a[n];
    for (int i = 0; i < n; i++)
        cin >> arr[i], a[i].F = arr[i], a[i].S = i;

    sort(a, a + n, cmp);

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (a[j].S != i) {
                cout << a[j].F << "\n";
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3968
a=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k=int(input())
print(a[k-1])

Measured memory_bytes: 2940