akhauriyash/Code-Regression huggingface dataset:
// clang-format off
	#define BADSEED random_device{}()
	#include <bits/stdc++.h>
	using namespace std;
	using ll = long long;
	using uint = unsigned int;
	ostream &operator<<(ostream &os, int8_t c) { return os << short(c); }
	istream &operator>>(istream &is, int8_t &c) { short x; is >> x; c = x; return is; }
	#define TM_(...) template <class __VA_ARGS__>
	namespace narut {
	TM_(T) using TupSz = tuple_size<decay_t<T>>;
	TM_(T) constexpr auto spc(T const &t, int) -> decltype((cout << t), 'a') { return ' '; }
	constexpr auto spc(string const &s, int) { return '\n'; }
	TM_(T) constexpr auto spc(T const &t, char) { return '\n'; }
	struct IO {
		TM_(T) static auto out_(ostream &os, T const &t, int) -> decltype(void(os << t)) { os << t; }
		TM_(T, class OS) static auto out_(OS &os, T const &t, int) -> decltype(void(begin(t))) {
			auto it = begin(t), e = end(t);
			if (it != e) out_(os, *it++, 0);
			for (; it != e; out_(os, *it++, 0)) os << spc(*it, 0);
		}
		TM_(T, size_t... Is) static void out_tup(ostream &os, T const &t, index_sequence<Is...>) { (void)initializer_list<int>{0, ((Is == 0) ? 0 : ((os << ' '), 0), (os << get<Is>(t)), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) out_(ostream &os, T const &t, char) { out_tup(os, t, make_index_sequence<TupSz<T>::value>{}); }
		TM_(Sep, class F, class... Ts) static ostream &print(ostream &os, Sep sep, F const &f, Ts const &... ts) { return void(initializer_list<int>{(out_(os, f, 0), 0), (out_(os << sep, ts, 0), 0)...}), os; }
		TM_(T) static auto in_(istream &is, T &t, int) -> decltype(void(is >> t)) { is >> t; }
		TM_(T, class IS) static auto in_(IS &is, T &t, int) -> decltype(void(begin(t))) { for (auto &x : t) in_(is, x, 0); }
		TM_(T, size_t... Is) static void in_tup(istream &is, T &t, index_sequence<Is...>) { (void)initializer_list<int>{0, (in_(is, get<Is>(t), 0), 0)...}; }
		TM_(T) static decltype(void(TupSz<T>{})) in_(istream &is, T &t, char) { in_tup(is, t, make_index_sequence<TupSz<T>::value>{}); }
	};
	} // namespace narut
	#define Cout(...) narut::IO::print(cout, ' ', __VA_ARGS__) << '\n'
	#ifdef NARUT_LOCAL
	#define Debug(...) narut::IO::print(cerr << "\033[0;31m", ", ", __VA_ARGS__) << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] struct Cin { 
		template <class T> Cin const &operator>>(T &t) const { return narut::IO::in_(cin, t, 0), *this; }
		template <class T> operator T() const { T t; return *this >> t, t;  }	
	} Cin;
	TM_(T) auto operator%(T &t, size_t n) -> decltype(t.resize(n), t)& { return t.resize(n), t; }
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)

// clang-format on





auto Main() {
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;

	auto period = h2*60+m2 - (h1*60+m1);
	cout << period - k;
	
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


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

#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define maxs(x,y) (x=max(x,y))
#define mins(x,y) (x=min(x,y))
#define FIX <<fixed<<setprecision(10)<<
using namespace std;

using ll = long long; using ull = unsigned long long;
using vb = vector<bool>; using vvb = vector<vb>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
using pii = pair<int,int>; using pll = pair<ll,ll>;

const ll MOD = 1e9+7;

bool isNotStable(int N,vector<string> origin,vector<string> comp){
REP(i,N){
    if(origin[i]!=comp[i])return true;
}
return false;
}

int main(){
int N,min,count=0;
string st="Stable";
cin>>N;
vector<string> B(N),C(N);
REP(i,N)cin>>B[i];
REP(i,N)C[i]=B[i];
REP(i,N){
    min=i;
    FOR(j,i,N){
        if(C[j][1]<C[min][1])min=j;
    }
    swap(C[min],C[i]);
}
REP(i,N){
    for(int j=N-1;j>i;j--){
    if(B[j-1][1]>B[j][1])swap(B[j-1],B[j]);
}
}
REP(i,N-1)cout<<B[i]<<" ";
cout<<B[N-1]<<endl<<"Stable"<<endl;
if(isNotStable(N,B,C))st="Not stable";
REP(i,N-1)cout<<C[i]<<" ";
cout<<C[N-1]<<endl<<st<<endl;;
}


Measured memory_bytes: 3204
#include<stdio.h>
const int N = 105;
int main()
{
	int n,a[N] = {0};
	scanf("%d",&n);
	for(int i =0;i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i =n-1;i >= 0; i--)
	{
		if(i)
		{
			printf("%d ",a[i]);
		}
		else
		{
			printf("%d\n",a[i]);
		}
	
	}
	
	return 0;
} 


Measured memory_bytes: 2680
#define _GLIBCXX_DEBUG

#include"bits/stdc++.h"
using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define AToB(i,a,b) for(int i=a;i<(ll)(b+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//bitsearch
#define BITSEARCH(bit, n) for (int bit = 0; bit < (1<<n); ++bit)
#define isOne(bit, i) bit & (1<<i)


//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

template<typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n)
{
    auto first = v.cbegin() + m;
    auto last = v.cbegin() + n + 1;

    std::vector<T> vec(first, last);
    return vec;
}

#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

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

//pair
#define fir first
#define sec second
#define mp make_pair

//types
#define ll long long
#define vec vector
#define cord2d pair<int,int>
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(long long a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(char a){ cout << a << endl; }
void print(double a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T = int>
void print(vec<T> v){ cout << v << endl; }

template <class T = int>
void print2dVec(vec<vec<T>> v2d){for(vec<T> v: v2d) {print(v);}}

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

//maths
int factorial(int k){ int sum = 1; for (int i = 1; i <= k; ++i) { sum *= i; } return sum; }

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

void Main() {
    //code here
    int a = gi, b = gi, c = gi;
    YesNo1(c >= a && c <= b);
}


signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int s;
	scanf("%d", &s);
	int s1, s2;
	s1 = s / 100;
	s2 = s % 100;
	int answer = 0;

	if (s1 != 0 && s1 <= 12) {
		answer += 1;
	}
	if (s2 != 0 & s2 <= 12) {
		answer += 2;
	}
	switch (answer) {
	case 0:
		printf("NA\n");
		break;
	case 1:
		printf("MMYY\n");
		break;
	case 2:
		printf("YYMM\n");
		break;
	case 3:
		printf("AMBIGUOUS\n");
		break;
	}
	//while (1);
}

Measured memory_bytes: 128
#!/usr/bin/env perl

use strict;
use warnings;

my $S = <STDIN>;
chomp($S);

my $n = length($S);
my $s = reverse($S);

my $a = substr($S,0,($n-1)/2);
my $b = substr($S,($n+1)/2,($n-1)/2);
my $c = reverse($a);
my $d = reverse($b);

if($s eq $S && $a eq $c && $b eq $d){print 'Yes';}
else{print 'No';}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int cmpstr(const void *a, const void *b) {
	return strcmp((char *)a, (char *)b);
}
int main() {
	int n, cnt = 1;
	char s[200000][11];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s", s[i]);
	}
	qsort(s, n, sizeof(s[0]), cmpstr);
	for (int i = 0; i < n - 1; i++) {
		if (strcmp(s[i], s[i + 1]) != 0) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 5740
DANCE = ['L', 'R', 'U', 'D']
EVEN_GOOD = ['L', 'U', 'D']
ODD_GOOD = ['R', 'U', 'D']

even = list()
odd = list()

S = input()
S = list(S)

for i, s in enumerate(S):
    if (i+1) % 2 == 0:
        even.append(s)
    else:
        odd.append(s)

flag = True

for e in even:
    if e in EVEN_GOOD:
        pass
    else:
        flag = False

for o in odd:
    if o in ODD_GOOD:
        pass
    else:
        flag = False

if flag:
    print('Yes', end='')
else:
    print('No', end='')


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

int n;
int a[55];

int main() {
	scanf("%d", &n);
	for(int i=0;i<n;i++) scanf("%d", &a[i]);
	sort(a, a+n);
	
	double x = a[0];
	for(int i=1;i<n;i++)
		x = (x+a[i])/2;
	printf("%.10lf\n", x);
	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(9);
  A.at(8) = N/100000000;
  A.at(7) = N/10000000;
  A.at(6) = N/1000000;
  A.at(5) = N/100000;
  A.at(4) = N/10000;
  A.at(3) = N/1000;
  A.at(2) = N/100;
  A.at(1) = N/10;
  A.at(0) = N;
  
  for(int i=0;i<8;i++){
    A.at(i) = A.at(i) - A.at(i+1)*10;
  }
  
  int f = 0;
  
  for(int i=0;i<9;i++){
    f = f + A.at(i);
  }
  
  int b = N%f;
  
  if(b == 0){
    cout << "Yes" << endl;
  }
  else if(b > 0){
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    int k;
    cin>>k;
    int a,b;
    cin>>a>>b;
    for(int i = a;i<=b;i++){
        if(i%k == 0){
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
#define PI acos(-1)
#define oo LLONG_MAX
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
/*

*/
vector<vector<ll>> G;
vector<bool> seen;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar(ll n, ll set){//親はset=根
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=set;
      mkpar(next_n, set);
    }
  }

  void mkpar2(ll n){//親は1個上、引数1個
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n] = true;
      par[next_n] = n;
      mkpar2(next_n);
    }
  }

  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};

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

  ll N, M; cin >> N >> M;
  G.assign(N+1, vector<ll>());
  seen.assign(N+1,false);
  for(int i=0; i<M; i++){
    ll a,b; cin>>a>>b;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
  }
  UnionFind tree(N);
  seen[1] = true;
  for(int i=1; i<=N; i++) tree.mkpar(i,i);
  vector<ll> usize(200010, 0);
  for(int i=1; i<=N; i++)
    usize[tree.par[i]]++;
  ll ans = 0;
  for(int i=1; i<=200000; i++)
    chmax(ans, usize[i]);
  cout << ans << endl;
}



Measured memory_bytes: 31332
H, W, K = map(int, input().split())
A = [[0]*W for i in range(H+1)]
A[0][0] = 1
MOD = 10**9+7
for i in range(H):
  for j in range(W):
    for k in range(1<<(W-1)):
      for l in range(W-1):
        if (k>>l)&1 and (k>>(l+1))&1:
          break
      else:
        if j>0 and (k>>(j-1))&1:
          A[i+1][j-1] += A[i][j]
          A[i+1][j-1] %= MOD
        elif j<W-1 and (k>>j)&1:
          A[i+1][j+1] += A[i][j]
          A[i+1][j+1] %= MOD
        else:
          A[i+1][j] += A[i][j]
          A[i+1][j] %= MOD

print(A[H][K-1])

Measured memory_bytes: 3064
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
LL max(LL a, LL b){
  if (a > b) {
    return a;
  }else return b;
}

int main(void)
{
  char s[13];
  char t[13];
  char c;
  LL ans = 0;
  scanf("%s", &s);
  scanf("%s", &t);

  if (strlen(t) - strlen(s) != 1) {
    printf("No\n");
    return 0;
  }

  if (strlen(s) == 1) {
    if (s[0] == t[0]) {
      printf("Yes\n" );
    }else{
      printf("No\n" );
    }
    return 0;
  }

  for (size_t i = 0; i < strlen(s)-1; i++) {
    if (s[i] != t[i]) {
      printf("No\n" );
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 1656
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.make 1000001 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      as_.(a) <- 1 + as_.(a)
  done;
  let dp = Array.make 1000001 1 in
  for a = 0 to 1000000 do
    if as_.(a) <> 1 then dp.(a) <- 0;
    if 0 < as_.(a) then
      let rec mark i =
        if i <= 1000000 then
          (as_.(i) <- 0; mark (i + a)) in
      mark (2 * a)
  done;
  Printf.printf "%d\n" @@
  Array.fold_left ( + ) 0 dp


Measured memory_bytes: 21804
#include<stdio.h>      
long long gcd(long long a,long long b)
{  
    if(a==0) return b;  
    else return gcd(b%a,a);  
}  
int main(){  
    long long n;  
    long long arr[110];  
    scanf("%d",&n);  
    for(int i=0;i<n;i++) scanf("%lld",&arr[i]);  
    long long t=arr[0];  
    for(int i=1;i<n;i++){  
        long long x=gcd(t,arr[i]);  
        t*=(arr[i]/x);  
    }  
    printf("%lld",t);
	return 0; 
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys

N = int(input().strip())
#-----

if N <= 104:
    print(0)
    sys.exit()
elif N == 105:
    print(1)
    sys.exit()
else:
    ans_list=[105]
    for i in range(107,N+1,2):
        cnt=0
        for j in range(1,N+1):
            if i % j == 0:
                cnt += 1
        
        if cnt == 8:
            ans_list.append(i)

print(len(ans_list))


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


//できない理由は2通り
//1. 枚数が足りない
//2. 選ぶときに数字がかぶる

// MAX_N 3 * 10^5 なので　N^2はできない

//大量にかぶっているカードがあっても、毎回使えば、食べれる
int main(){
    int A,B;
    cin >> A >> B;

    int res;

    if(A <= 9 && B <= 9)
    {
      res = A * B;
    }
    else
    {
      res = -1;
    }

    cout << res << endl;

    return 0;    
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

void solve(){
  int n,m;
  cin>>n>>m;
  cout<<(n*(n-1))/2+(m*(m-1))/2;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    char c = getchar();
    string ans = "consonant";
    if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') ans = "vowel";
    cout << ans << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
const ll INF = 1LL << 60;
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll dp[110][100100];

void solve(long long N, long long W, std::vector<long long> w, std::vector<long long> v)
{
    for (int i = 0; i < 110; i++)
    {
        for (int j = 0; j < 100100; j++)
        {
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j <= 100100; j++)
        {
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if (j - v[i] >= 0)
            {
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 100100; i++)
    {
        if (dp[N][i] <= W)
        {
            ans = i;
        }
    }

    cout << ans << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long W;
    scanf("%lld", &W);
    std::vector<long long> w(N);
    std::vector<long long> v(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &w[i]);
        scanf("%lld", &v[i]);
    }
    solve(N, W, std::move(w), std::move(v));
    return 0;
}


Measured memory_bytes: 86400
#include<bits/stdc++.h>
using namespace std;
long long n,t,cnt=0,a,kmp;
int main()
{
	scanf("%lld%lld",&n,&t);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		if(a>=kmp)
		{
			cnt+=t;
			kmp=a+t;
		}else
		{
			cnt+=(a+t-kmp);
			kmp=a+t;
		}
	}
	printf("%lld\n",cnt);
}

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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define EACH(itr,v) for(auto itr:v)
#define pb(s) push_back(s)

typedef long long ll;

int main()
{
std:
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin>>N;
    if(N==1)
    {
        cout<<0;
        return 0;
    }
    vector<int> vi;
    REP(i,N){
        int x;
        cin>>x;
        vi.pb(x);
    }
    int small=1e9;
    FOR(i,-100,101){
        int sum=0;
        REP(j,N){
            sum+=(vi[j]-i)*(vi[j]-i);
        }
        small=min(small,sum);
    }
    cout<<small;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
ll a[200006];
ll n;
int main(){
     cin>>n;
    ll min=11;
    for(ll i=1;i<=sqrt(n);i++){
        if(n%i==0){
        ll x=i;
        ll y=n/i;
        string s1=to_string(x);
        string s2 = to_string(y);
        ll z=max((ll)s1.length(),(ll)s2.length());
        if(z<min)
            min=z;
        }
    }
    cout<<min;
    
    return 0;
}


Measured memory_bytes: 256
def s():
 import sys
 r=sys.stdin.readline
 I=float('inf')
 for e in iter(r,'0 0\n'):
  n,k=map(int,e.split())
  F=[[I]*-~n for _ in[0]*-~n]
  for i in range(1,n+1):F[i][i]=0
  for _ in[0]*k:
   f=r();g=map(int,f[2:].split())
   if'0'==f[0]:a,b=g;A=F[a][b];print([A,-1][A==I])
   else:
    c,d,e=g
    if e<F[c][d]:
     for i in range(2,n+1):
      for j in range(1,i):
       F[i][j]=F[j][i]=min(F[i][j],F[i][c]+e+F[d][j],F[i][d]+e+F[c][j])
if'__main__'==__name__:s()


Measured memory_bytes: 6240
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
struct fenw{
  VI fw;
  in n;
  void ini(in pn){
    n=pn;
    fw.clear();
    fw.resize(n,0);
  }
  void ad(in l, in x){
    while(l<n){
      fw[l]+=x;
      l|=(l+1);
    }
  }
  in sm(in l){
    in r=0;
    while(l>=0){
      r+=fw[l];
      l&=(l+1);
      --l;
    }
    return r;
  }
};
fenw fw;
in n;
vector<pair<in,in> > psm;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in k;
  cin>>n>>k;
  in ssf=0;
  psm.PB(MP(0,0));
  in a;
  forn(z,n){
    cin>>a;
    a-=k;
    ssf+=a;
    psm.PB(MP(ssf,z+1));
  }
  sort(all(psm));
  fw.ini(n+9);
  in sm=0;
  forv(i,psm){
    sm+=fw.sm(psm[i].second);
    fw.ad(psm[i].second,1);
  }
  cout<<sm<<endl;
  return 0;
}


Measured memory_bytes: 6384
// Interative Deepening
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

//?§???¨??????
static const int dx[4]={0,-1,0,1};
static const int dy[4]={1,0,-1,0};

//????????????
static const char dir[4]={'r','u','l','d'};

//?????????????????¨
int MDT[N2][N2];

//Puzzle{?????????????????????????????????}
struct Puzzle { int f[N2], space, MD; };

//?????????puzzle
Puzzle state;

//??±????????¶
int limit;

//??????
int path[LIMIT];

//?????°????????????????????????
int getAllMD(Puzzle pz)
{
	int sum = 0;
	for(int i=0;i<N2;i++)
	{
		if(pz.f[i]==N2)continue;//???16???0????°±??????
		sum+=MDT[i][pz.f[i]-1];
	}
	return sum;
}

bool dfs(int depth, int prev)
{
	//??????????????????0?????´??????????????°??????
	if(state.MD==0)return true;
	
	//??????????????±????????????????¶????????????¶??????????????????
	if(depth+state.MD>limit)return false;
	
	//??????????????????(sx,sy)
	int sx=state.space/N;
	int sy=state.space%N;
	
	Puzzle tmp;
	
	for(int r=0;r<4;r++)
	{
		//(tx,ty)?????????????????????????§???¨???????????????
		int tx=sx+dx[r];
		int ty=sy+dy[r];
		
		//?????????????¶????
		if(tx<0||ty<0||tx>=N||ty>=N)continue;
		
		
		if(max(prev,r)-min(prev,r)==2)continue;
		
		tmp=state;
		
		//??????????????????????????????????????¶?????¢?????????
		state.MD-=MDT[tx*N+ty][state.f[tx*N+ty]-1];//????§???¨???????????????????????????????????????
		state.MD+=MDT[sx*N+sy][state.f[tx*N+ty]-1];//???????§???¨????????????????????????
		swap(state.f[tx*N+ty],state.f[sx*N+sy]);//?????¢
		
		state.space=tx*N+ty;
		if(dfs(depth+1,r))
		{
			path[depth]=r;
			return true;
		}
		state=tmp;
	}
	return false;
}
//?????£?????±
string iterative_deeping(Puzzle in)
{
	in.MD=getAllMD(in);//????§???¶?????????????????????
	for(limit=in.MD;limit<=LIMIT;limit++)
	{
		state=in;
		if(dfs(0,-100))
		{
			string ans="";
			for(int i=0;i<limit;i++)
			ans+=dir[path[i]];
			return ans;
		}
	}
	return "unsolvable";
}

int main()
{
	for(int i=0;i<N2;i++)
		for(int j=0;j<N2;j++)
			MDT[i][j]=abs(i/N-j/N)+abs(i%N-j%N);
			
	/*for(int i=0;i<N2;i++)
	{
		for(int j=0;j<N2;j++)
		cout<<MDT[i][j]<<" ";
		cout<<endl;
	}
	cout<<endl;*/
	
	Puzzle in;
	
	for(int i=0;i<N2;i++)
	{
		cin>>in.f[i];
		if(in.f[i]==0)
		{
			in.f[i]=N2;
			in.space=i;
			//???0??????16????????????????¢???????0?°±?????????16
		}
	}
	string ans=iterative_deeping(in);
	cout<<ans.size()<<endl;
	//cout<<ans;
}

/*
MDT???????????????
0 1 2 3 1 2 3 4 2 3 4 5 3 4 5 6 
1 0 1 2 2 1 2 3 3 2 3 4 4 3 4 5 
2 1 0 1 3 2 1 2 4 3 2 3 5 4 3 4 
3 2 1 0 4 3 2 1 5 4 3 2 6 5 4 3 
1 2 3 4 0 1 2 3 1 2 3 4 2 3 4 5 
2 1 2 3 1 0 1 2 2 1 2 3 3 2 3 4 
3 2 1 2 2 1 0 1 3 2 1 2 4 3 2 3 
4 3 2 1 3 2 1 0 4 3 2 1 5 4 3 2 
2 3 4 5 1 2 3 4 0 1 2 3 1 2 3 4 
3 2 3 4 2 1 2 3 1 0 1 2 2 1 2 3 
4 3 2 3 3 2 1 2 2 1 0 1 3 2 1 2 
5 4 3 2 4 3 2 1 3 2 1 0 4 3 2 1 
3 4 5 6 2 3 4 5 1 2 3 4 0 1 2 3 
4 3 4 5 3 2 3 4 2 1 2 3 1 0 1 2 
5 4 3 4 4 3 2 3 3 2 1 2 2 1 0 1 
6 5 4 3 5 4 3 2 4 3 2 1 3 2 1 0 
*/

Measured memory_bytes: 3204
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    string S; cin >> S;
    int N = S.size();
    int l = 0; int r = N-1;
    int ans = 0;
    while(l < r) {
        //cout << l << " " << r << endl;
        if(S[l] == S[r]) {
            l++; r--;
        } else {
            if(S[l] == 'x') {
                l++; ans++;
            } else if(S[r] == 'x') {
                r--;
                ans++;
            } else {
                //cout << S[l] << " " << S[r] << endl;
                cout << -1 << endl;
                return 0;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REP(i,b) FOR(i,0,b)
#define RFOR(i,a,b) for (int i = a-1; i >= b; i--)
#define RREP(i,a) RFOR(i,a,0)
#define REPALL(i,x) for (int i = 0; i < x.size(); i++)
#define RREPALL(i,x) for (int i = x.size()-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define MIN_ELEMENT(x) min_element(ALL(x))
#define MAX_ELEMENT(x) max_element(ALL(x))
#define COUNT(x,num) count(ALL(x), num)
#define MEMSET(x,val) memset(x, val, sizeof(x))
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
void YES(bool flag) {cout<<(flag ? "YES" : "NO")<<endl;}
void Yes(bool flag) {cout<<(flag ? "Yes" : "No")<<endl;}
void yes(bool flag) {cout<<(flag ? "yes" : "no")<<endl;}
#define fst first
#define scd second
#define nextline putchar('\n')
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<ll> VLL;
typedef vector<vector<ll>> VVLL;
const int INF = 1e7;
const ll MOD = 1e9 + 7;

int h, n;
ll ans = MOD;
VLL dp(22222, MOD), a, b;
int main()
{
    cin>>h>>n;
    a.resize(n);
    b.resize(n);
    REP(i,n) {
        cin>>a[i]>>b[i];
    }

    dp[0] = 0;
    REP(i,h) {
        REP(j,n) {
            MIN(dp[i+a[j]], dp[i] + b[j]);
            if (i+a[j] >= h) {
                MIN(ans, dp[i+a[j]]);
            }
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
using System;
class Program
{
	static void Main(string[] args)
	{
      string[] input = Console.ReadLine().Split(' ');
      int a = int.Parse(input[0]);
      int b = int.Parse(input[1]);
      int c = int.Parse(input[2]);
      int d = int.Parse(input[3]);
      double takatt = Math.Ceiling((double)c/b);
      double aokatt = Math.Ceiling((double)a/d);
      Console.WriteLine(takatt <= aokatt ? "Yes" : "No");

      
	}
}

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

// #include<cstdio>

int main(){
  int m, f, r;
  while(1){
    cin >> m >> f >> r;
    if (m==-1 && f==-1 && r==-1) break;
    if (m==-1 || f==-1) cout << "F\n";
    else
      if (m+f>=80) cout << "A\n";
      else
	if (m+f>=65) cout << "B\n";
	else
	  if (m+f>=50) cout << "C\n";
	  else
	    if (m+f>=30 && r>=50) cout << "C\n";
	    else
	      if (m+f>=30) cout << "D\n";
	      else
		cout << "F\n";
  }

  return 0;
}

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

long long MOD = 1000000007; //prime

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

 	long long ModUniverse = 1;
 	for (long i = 0; i < N; i++)
 		ModUniverse = (ModUniverse * 10) % MOD;

	long long Bar2 = 2;
	for (long i = 0; i < N; i++)
		Bar2 = (Bar2 * 9) % MOD;
	
	long long BarBar = 1;
	for (long i = 0; i < N; i++)
		BarBar = (BarBar * 8) % MOD;
		
	long long tmp = ModUniverse;
	tmp = (tmp + BarBar) % MOD;
	
	tmp = ((tmp - Bar2) + MOD) % MOD;
	
	cout << tmp << endl;

	return 0;
}

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

using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ((a + b) > (c + d)) {
        cout << "Left" << endl;
    } else if ((a + b) < (c + d)) {
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }

    return 0;
}


Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
	class Program
	{
		public static void Main(string[] args)
		{
			var in1 = ReadInts().ToArray();
			var k = in1[0];
			var t = in1[1];
			var a = ReadInts().ToArray();
			Console.WriteLine(Math.Max(a.Max() - 1 - (k - a.Max()), 0));
		}

		private static IEnumerable<int> ReadInts() => Console.ReadLine().Split(' ').Select(int.Parse);
	}
}

Measured memory_bytes: 2904
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <math.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)

#define PI 3.14
typedef long long ll;


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

int main() {
  int n, m;
  cin >> n >> m;

  int homeworks[m];
  rep(i, m) {
      cin >> homeworks[i];
      n -= homeworks[i];
  }
  int ans = (n < 0) ? -1 : n;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int A,B,C;
  cin >> A >> B >> C;
  int a[B];
  FOR(i,0,B) a[i] = A*(i+1);
  FOR(i,0,B) {
    if ((a[i] % B) == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  
  return 0;
  
}




Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int a[maxn];
int dp[maxn];
int main()
{
	#ifdef TEST
		freopen("input.txt","r",stdin);
    #endif
	int n,m,T;
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) dp[i]=1e9+7;
	dp[1]=0;
	for(int i=1;i<=n;i++)
	{
		for(int k=1;k<=m;k++)
		dp[i+k]=min(dp[i]+abs(a[i]-a[i+k]),dp[i+k]);
	}
	cout<<dp[n]<<endl;
	
}



Measured memory_bytes: 1024
if __name__ == '__main__':
    n, m = tuple(map(int, input().split()))
    heights = list(map(int, input().split()))
    heights = [0] + heights
    roads = {}
    count = 0
    for i in range(0, m):
        a, b = tuple(map(int, input().split()))
        if not (a in roads.keys()):
            roads[a] = {heights[b], }
        else:
            roads[a].add(heights[b])
        if not (b in roads.keys()):
            roads[b] = {heights[a], }
        else:
            roads[b].add(heights[a])
    for each in roads.items():
        if heights[each[0]] > max(each[1]):
            count += 1
    count +=  n - len(roads.keys())
    print(count)


Measured memory_bytes: 41948
class Combi
    def initialize(max_n, mod = 10**9+7)
        @mod = mod
        @max_n = max_n

        @fac = Array.new(@max_n+1)
        @inv = Array.new(@max_n+1)
        @finv = Array.new(@max_n+1)

        @fac[0] = @fac[1] = 1
        @finv[0] = @finv[1] = 1
        @inv[1] = 1
        2.upto(@max_n) do |i|
            @fac[i] = @fac[i-1] * i % @mod
            @inv[i] = @mod - @inv[@mod%i] * (@mod/i) % @mod
            @finv[i] = @finv[i-1] * @inv[i] % @mod
        end
    end

    def nCk(n,k)
        @fac[n] * @finv[n - k] * @finv[k] % @mod
    end
end

combi = Combi.new(50)

N,P=gets.chomp.split.map(&:to_i)

even = 0
odd = 0

A=gets.chomp.split.map(&:to_i)

A.each do |v|
    if v % 2 == 0
        even += 1
    else
        odd += 1
    end
end

ans = 0
if P == 0
    0.step(odd,2) do |i|
        ans += combi.nCk(odd,i)
    end    
else
    1.step(odd,2) do |i|
        ans += combi.nCk(odd,i)
    end    
end
puts ans * (1<<even)

Measured memory_bytes: 1916
#include <iostream> 
#include <sstream> 
#include <iomanip> 
#include <algorithm> 
#include <cmath> 
#include <string> 
#include <vector> 
#include <list> 
#include <queue> 
#include <stack> 
#include <set> 
#include <map> 
#include <bitset> 
#include <numeric> 
#include <climits> 
#include <cfloat> 
using namespace std; 

class Dice
{
public:
    vector<char> pip; // ì¼kãºÌÚ
    Dice(){
        pip.assign(6, -1);
    }
    void roll(int d){ // ì¼kE¶Éñ]
        int dir[][4] = {{4,2,5,0},{4,3,5,1},{4,0,5,2},{4,1,5,3},{0,3,2,1},{0,1,2,3}};
        char tmp = pip[dir[d][0]];
        for(int i=0; i<3; ++i)
            pip[dir[d][i]] = pip[dir[d][i+1]];
        pip[dir[d][3]] = tmp;
    }
    bool operator==(const Dice& d) const{
        return pip == d.pip;
    }
};

bool same(Dice& dice1, Dice& dice2)
{
    for(int i=0; i<6; ++i){
        if(i < 4)
            dice1.roll(0);
        else{
            dice1.roll(1);
            if(i == 5)
                dice1.roll(1);
        }
        for(int j=0; j<4; ++j){
            dice1.roll(4);
            if(dice1 == dice2)
                return true;
        }
    }
    return false;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<Dice> dice(n);
        for(int i=0; i<n; ++i){
            vector<string> s(6);
            for(int j=0; j<6; ++j)
                cin >> s[j];

            dice[i].pip[4] = s[0][0];
            dice[i].pip[0] = s[1][0];
            dice[i].pip[1] = s[2][0];
            dice[i].pip[3] = s[3][0];
            dice[i].pip[2] = s[4][0];
            dice[i].pip[5] = s[5][0];
        }

        int ret = 0;
        for(int i=0; i<n; ++i){
            for(int j=i+1; j<n; ++j){
                if(same(dice[i], dice[j])){
                    ++ ret;
                    break;
                }
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
def main():
    n, d = map(int, input().split())
    dis = d**2
    ans = 0
    for _ in range(n):
        x, y = map(int, input().split())
        if x**2 + y**2 <= dis:
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  int count_grid[50][50];
  string bomb[50];
  
  cin >> H >> W;
  
  for ( int i = 0; i < H; i++ )  {
    cin >> bomb[i];
  }
  
  for ( int i = 0; i < H; i++ )  {
    for ( int j = 0; j < W; j++ ) {
      count_grid[i][j] = 0;
      
      for ( int k = -1; k < 2; k++ ) {
        for ( int l = -1; l < 2; l++ ) {
          if ( i+k >= 0 && i+k < H &&
               j+l >= 0 && j+l < W ) {
            if ( bomb[i+k].at(j+l) == '#' ) {
              count_grid[i][j]++;
            }
          }
        }
      }
    }
  }
  
  for ( int i = 0; i < H; i++ )  {
    for ( int j = 0; j < W; j++ ) {
      if ( bomb[i].at(j) == '#' ) {
        cout << '#';
      }
      else {
        cout << count_grid[i][j];
      }
    }
    cout << endl;
  }
}

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

using namespace std;

int main(){
  int k, n, a[200009];
  cin >> k >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  sort(a, a+n);
  int mx=a[0]+k - a[n-1];
  for(int i=0;i<n-1;i++){
    mx = max(a[i+1] - a[i], mx);
  }
  cout << k - mx << endl;
}



Measured memory_bytes: 1024
unittest
{
	assert( [ "3", "1 3", "2 3" ].solve == 7 );
	assert( [ "2", "1 2" ].solve == 3 );
	assert( [ "10", "5 3", "5 7", "8 9", "1 9", "9 10", "8 4", "7 4", "6 10", "7 2" ].solve == 113 );
}



import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto uvs = new long[ 2 ][ n - 1 ];
	foreach( ref uv; uvs )
	{
		input.popFront;
		uv = input.front.split.to!( long[] );
		uv[] -= 1;
	}
	
	// 全パターンの頂点数を合計
	auto ans = 0L;
	foreach( i; 0L .. n )
	{
		ans += ( i + 1 ) * ( n - i );
	}
	
	// 頂点数合計 - 辺数合計 = 連結成分数
	foreach( uv; uvs )
	{
		if( uv[ 0 ] < uv[ 1 ] ) ans -= ( uv[ 0 ] + 1 ) * ( n - uv[ 1 ] );
		else                    ans -= ( uv[ 1 ] + 1 ) * ( n - uv[ 0 ] );
	}
	return ans;
}


Measured memory_bytes: 6900
#include<bits/stdc++.h>
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_multiset tree<long long , null_type,less_equal<long long >, rb_tree_tag,tree_order_statistics_node_update>
#define ordered_set tree<long long , null_type,less<long long >, rb_tree_tag,tree_order_statistics_node_update>
*/
using namespace std;
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld     long double 
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define en cout<<"\n";
#define ull unsigned long long int
#define o(x) cout<<x<<"\n";
#define o1(x) cout<<x<<" ";
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define pre(n) cout<<fixed<<setprecision(n);
#define      gcd(a,b)    __gcd(a,b)
#define bs            binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define pi 3.14159265358979323846
#define all(x) x.begin(),x.end()
#define re return 0;
// *#######################################################################################*

/*
bool isp(ll n)
{
    ll i;
    for(i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            return false;
        }
        
    }
}
  */
  
  ll powerm(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;    
  
    x = x % p; 
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % p;  
   
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
  long long lcm(long long a, long long b){//?????????
   return a * b / gcd(a, b);
}

/*
ll po(ll z,ll z1)
{
    ll rer=0;
    rer=     ((z*(z-1))/2+(z1*(z1-1))/2);
    return rer;

}
*/
/*
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
*/
/*
bool is_prime(ll n){
    for(ll i = 2;i*i<=n;i++){
        if(n%i == 0) return false;
    }
    return true;
}
*/
int inv(int a){
    return powerm(a,mod-2,mod);
}

ll const N=1e5;
ll fact[N], invfact[N];
 
void precompute(){
    fact[0] = 1;
    for(int i=1;i<N;i++) fact[i] = (fact[i-1]*i)%mod;
    invfact[N-1] = inv(fact[N-1])%mod;
    for(int i=N-2;i>=0;i--) invfact[i] = (invfact[i+1]*(i+1))%mod;
}
 
ll ncr(ll n, ll r){
    if(n<r) return 0;
    return (((fact[n]*invfact[r])%mod)*invfact[n-r])%mod;
}


//*88888*********5555555555555555******88888888$$$$$$$$$$******!!!!!!!!!!
//%%%%%%%%%%%%%%55
//%%%%%%%%%%%%%%%%%%%
//55555555555555555555//\
//55555555555555

       int main()
       {
           //????????
    fast

    double d,t,s;
    cin>>d>>t>>s;
    if((d/s)*1.0<=t)
    {
        Yes
    }
   else
   {
       No
   }












//?????????
re}

Measured memory_bytes: 3744
import numpy as np

D = int(input())
c = np.array(list(map(int, input().split())))
s = np.array([list(map(int, input().split())) for _ in range(D)])


def s7(c, s, last_date, di, i, mul):
    score = s[di - 1][i]
    score += mul * c[i] * (di - last_date[i])
    return score


def f8(D, c, s):
    last_date = np.zeros(26)

    t = []
    for di in range(1, D + 1):
        mul = np.mean(s[di - 1]) / np.mean(c)
        score_list = []
        for i in range(26):
            score_list.append(s7(c, s, last_date, di, i, mul))

        select_index = score_list.index(max(score_list))
        t.append(select_index)
        last_date[select_index] = di

    return t


for ti in f8(D, c, s):
    print(ti + 1)

Measured memory_bytes: 27436
/* ***********************************************
Author        :Winmer
Created Time  :2018年04月20日 星期五 21时58分44秒
File Name     :vj_lbq_sjjg_a.cpp
************************************************ */

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
string s,t;
int main(){
    while(cin>>s>>t){
        sort(s.begin(),s.end());sort(t.begin(),t.end());
        for(int i=0;i<t.size()/2;i++){swap(t[i],t[t.size()-i-1]);}
        if(s<t)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int n, A[20];

int solve (int i, int m) {

    int res;

    if (m == 0) {

        return 1;

    }

    if (i >= n) {

        return 0;

    }

    res = solve (i + 1, m) || solve (i + 1, m - A[i]);

    return res;

}

int main () {

    int q, m[200], i;

    cin >> n;
    for (i = 0; i < n; i++) {

        cin >> A[i];

    }

    cin >> q;
    for (i = 0; i < q; i++) {

        cin >> m[i];

    }

    for (i = 0; i < q; i++) {

        if (solve (0, m[i])) {

            cout << "yes" << endl;

        } else {

            cout << "no" << endl;

        }

    }

    return 0;

}

Measured memory_bytes: 3100
#include<iostream>
using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    for (ll n = 1; n <= 3500; n++) {
        for (ll w = 1; w <= 3500; w++) {
            ll c1 = 4 * n * w;
            ll c2 = N * (w + n);
            ll c3 = N * n * w;
            if (c1 == c2) continue;
            if (c3 % (c1 - c2) == 0 && c3 / (c1 - c2) > 0) {
                cout << n << ' ' << w << ' ' << c3 / (c1 - c2) << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int a, b;
    cin >> a >> b;
    if(a<=b){
        for(int i=0; i<b; i++){
            cout << a ;
        }
    }
    else{
        for(int i=0; i<a; i++){
            cout << b ;
        }
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[200005];
map<int,long long> dp[200005];
long long solve(int idx,int cnt)
{
	if (idx>=n)
	{
		if (cnt==n/2)
		return 0;
		return -1e18;
	}
	if (dp[idx].count(cnt))
	return dp[idx][cnt];
	if (cnt+(n-idx+1)/2<n/2)
	return -1e18;
	return dp[idx][cnt]=max(solve(idx+1,cnt),solve(idx+2,cnt+1)+a[idx]);
}
int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++)
	scanf("%d",&a[i]);
	printf("%lld",solve(0,0));
}

Measured memory_bytes: 41932
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

import sys, os

def main():
    ans = "Yes"
    steps = list(input())
    for i, st in enumerate(steps):
        if (i%2 == 1):
            if st == "R":
                ans = "No"
        else:
            if st == "L":
                ans = "No"
    print(ans)    
if __name__ == "__main__" :
    main()



Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		//????????£????????????
		Scanner sc =  new Scanner(System.in);
		int sum =0;
		String Evaluation ="a";
		while(true){
			//???????????????m
			int m = sc.nextInt();
			//??????????????????
			int f =sc.nextInt();
			//???????¨? ???
			int r = sc.nextInt();
			//??¨????????????-1?????£????????????
			if(m ==-1&& f==-1 &&r ==-1){
				break;
			}
			//????¨????
			sum = m + f;
			//???????????????????¬?????????? F
			if(m ==-1 ||f ==-1){
				System.out.println("F");
			//??????????????¶???
			}else if(sum>= 80){
				System.out.println("A");
			}else if(80>sum && sum>=65){
				System.out.println("B");
			}else if(65> sum&& sum>= 50){
				System.out.println("C");
			}else if(50>sum&& sum >=30){
				if(r>=50){
					System.out.println("C");
				}else{
					System.out.println("D");
				}
			}else {
				System.out.println("F");
			}
		}
	}
}

Measured memory_bytes: 26040
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <utility>
#include <map>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <cstdlib>
#include <set>
#include <chrono> 

#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define repf(i,st,end,inc) for(int i = st; i < end; i += inc)
#define repb(i,st,end,dec) for(int i = st; i >= end; i -= dec) 

#define MOD 1000000007

#define trace1(a) cout << a << endl;
#define trace2(a,b) cout << a << " | " << b << endl;
#define trace3(a,b,c) cout << a << " | " << b << " | " << c << endl;
#define trace4(a,b,c,d) cout << a << " | " << b << " | " << c << " | "<< d << endl;

using namespace std;
using namespace std::chrono;


int main(){
	fast;
	auto start = high_resolution_clock::now(); 

	int a, b;
	cin >> a >> b;
	if(b%a == 0)
		cout << a+b;
	else
		cout << b - a;

	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start);	
	// cout << endl;
	// cout << double(duration.count()) / 1000000 << endl; 

	return 0;
}


Measured memory_bytes: 256