akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define FOR(i,k,n) for(int(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define debug(x) std::cerr<<#x<<": "<<x<<"\n"
#define debug2(x,y) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<"\n"
#define debug3(x,y,z) std::cerr<<#x<<": "<<x<<", "<<#y<<": "<<y<<", "<<#z<<": "<<z<<"\n"

using ll=long long;
using vi=std::vector<int>;
using vvi=std::vector<vi>;
using vll=std::vector<ll>;
using vvll=std::vector<vll>;
template<typename T> using vvec=std::vector<std::vector<T>>;
template<typename T>
auto make_v(size_t sz){return std::vector<T>(sz);}
template<typename T,typename... Ts>
auto make_v(size_t sz,Ts...ts){return std::vector<decltype(make_v<T>(ts...))>(sz,make_v<T>(ts...));}
template<typename T>
void fill_v(T&var,const T&x){var=x;}
template<typename V,typename T>
void fill_v(V&v,const T&x){for(auto&& w:v){fill_v(w,x);}}

template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::vector<std::vector<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<T>&v){
  int sz=v.size();s<<"\n";rep(i,sz){s<<v[i];if(i<sz-1){s<<"\t";}}s<<"\n";return s;}
template<typename T> std::ostream& operator<<(std::ostream&s,const std::deque<std::deque<T>>&v){
  for(auto&& w:v){s<<w;}return s;}
template<typename T> std::ostream& operator<<(std::ostream&s, const std::set<T>&v){
  s<<"\n";for(auto&& elm:v){s<<elm<<"\t";}s<<"\n";return s;}

inline void scan(int&a){scanf("%d",&a);}
inline void scan(ll&a){scanf("%lld",&a);}
inline void scan(char&a){scanf(" %c",&a);}
inline void scan(double&a){scanf("%lf",&a);}
inline void scan(std::string&s){char BUF[3000000];scanf(" %s",BUF);s=std::string(BUF);}
template<typename T>
inline void scan(std::vector<T>&v){for(auto&& sv:v){scan(sv);}}
template<typename First,typename...Args>
inline void scan(First&f,Args&...args){scan(f);scan(args...);}
inline void print(int a){printf("%d\n",a);}
inline void print(ll a){printf("%lld\n",a);}
inline void print(double a){printf("%.12f\n",a);}
inline void print(std::string s){std::cout<<s<<"\n";}

using namespace std;

int mod = 1000000007;
int main() {
  int n; scan(n);
  string s; scan(s);
  vi cnt(26, 0);
  rep (i, n) {
    cnt[s[i] - 'a'] += 1;
  }
  ll ans = 1;
  rep (i, 26) {
    ans = ans * (cnt[i] + 1) % mod;
  }
  ans = (ans + mod - 1) % mod;
  print(ans);
  return 0;
}


Measured memory_bytes: 1016
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    int n;
    cin >> n;
    bool ans = true;
    for (int i = 0; i < n; ++i) {
        int a;
        cin >> a;
        if (a % 2) continue;
        if (!(a % 3 == 0 || a % 5 == 0)) ans = false;
    }
    cout << (ans ? "APPROVED" : "DENIED") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;cin>>H>>W;
  vector<string>M(H);
  for(int i=0;i<H;i++){
    cin>>M.at(i);
  }
  for(int i=0;i<H;i++){
    cout<<M.at(i)<<endl;
    cout<<M.at(i)<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<cmath>
#include<queue>
#include<limits>
#include<cassert>
#include<set>
#include<tuple>
#include<map>
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
typedef long long ll;
using namespace std;

int main() {
	int a,b,c; cin >> a >> b >> c;
	if (a == b) cout << c;
	if (a == c) cout << b;
	if (b == c) cout << a;

}


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

int main()
{
    int n;
    cin >> n;
    vector<pair<int,int> > p(n);
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        p[i]=make_pair(a[i],i);
    }
    sort(p.begin(),p.end());
    reverse(p.begin(),p.end());
    for(int i=0;i<n;i++){
        if(i!=p[0].second){
            cout <<p[0].first<< endl;
        }
        else{
            cout << p[1].first<< endl;
        }
    }

    return 0;

}


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

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

using ll = long long;
#define INF 1e9

int N, M;
vector<int> A, B;

int main(){
  cin >> N >> M;
  A.resize(N), B.resize(N);
  vector<vector<int>> p(100001);
  priority_queue<int> que;
  REP(i, N){
    cin >> A[i] >> B[i];
    p[A[i]-1].push_back(B[i]);
  }
  ll ans = 0;
  REP(i, M){
    REP(j, p[i].size()){
      que.push(p[i][j]);
    }
    if(!que.empty()){
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll ans=10000000000000000;
  vector<ll> v(n,0),s(n,0);
  r(i,n){
    cin >> v[i];
    if(!i)s[i]=v[i];
    else s[i]=s[i-1]+v[i];
  }
  r(i,n-1){
    ans=min(ans,abs(s[n-1]-s[i]*2));
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
//#include <boost/foreach.hpp>
#include <vector>
#include <algorithm>
using ll = long long ;
using namespace std;
int main(){
    int n,h;
    cin >> n >> h;
    vector<pair<int,int>> vec(2*n+100);
    for(int i=0;i<n;i++){
        int a,b;
        cin >> a >> b;
        vec[i*2]=pair<int,int> (a,0);
        vec[i*2+1]=pair<int,int> (b,1);
    }
    sort(vec.begin(),vec.end(),greater<pair<int,int>>());
    int j=0;
    long long c=0;
    while(h>0){
        if(vec[j].second==0){
            while(h>0){
                c++;
                h -= vec[j].first;
                
            }
        }else{
            c++;
            h -= vec[j].first;
            j++;
            
        }
    }
    cout<<c<<endl;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, ans;
    string str;
    char prev;
    scanf("%lld", &N);
    cin >> str;
    ans = 1;
    prev = str.at(0);
    REP(int, i, 1, N){
        if ( prev == str.at(i) ){
            continue;
        }
        else{
            prev = str.at(i);
            ans++;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int N,cnt=0;
int main(){
	cin>>N;
	if((N/100)>=1 && (N/100)<=12) cnt+=1;
	if((N%100)>=1 && (N%100)<=12) cnt+=2;
	if(cnt==0) cout<<"NA"<<endl;
	if(cnt==1) cout<<"MMYY"<<endl;
	if(cnt==2) cout<<"YYMM"<<endl;
	if(cnt==3) cout<<"AMBIGUOUS"<<endl;
}

Measured memory_bytes: 256
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))


N,M = map(int,input().split())
A = list(map(int,input().split()))
BC = [list(map(int,input().split())) for _ in range(M)]

A = sorted(A,key=lambda x:x*(-1))
BC = sorted(BC,key=lambda x:x[1]*(-1))
li = []

cnt = 0
j = 0
while(cnt<N and j<M):
    if BC[j][0]>0:
        BC[j][0] -= 1
        li.append(BC[j][1])
        cnt += 1
    else:
        j+=1
    

ans = 0
ai = 0
bi = 0
cnt2 = 0
while(cnt2<N):
    if bi<len(li) and ai<N:
        if li[bi]>A[ai]:
            ans += li[bi]
            bi += 1
        else:
            ans += A[ai]
            ai += 1
    
    elif bi<len(li):
        ans += li[bi]
        bi += 1

    else:
        ans += A[ai]
        ai += 1
    cnt2 += 1

print(ans)


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


class Program
{
    static void Main(string[] args)
    {
        string[] NM = Console.ReadLine().Split(' ');
        int N = int.Parse(NM[0]);
        int M = int.Parse(NM[1]);

        string[] Astr = Console.ReadLine().Split(' ');
        int[] A = new int[N];
        float total = 0;
        for(int i=0; i<N; i++){
            A[i] = int.Parse(Astr[i]);
            total += A[i];
        }

        int popular = 0;
        for(int i=0; i<N; i++){
            if(!(A[i] < total/(4*M))){
                popular += 1;
            }
        }

        if(popular >= M){
            Console.WriteLine("Yes");
        }else{
            Console.WriteLine("No");
        }

    }
}

Measured memory_bytes: 11092
n = int(input())
l = list(map(int,input().split()))
if n <= 2:
    print(0)
    quit()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            a = sorted([l[i],l[j],l[k]])
            if len(set(a)) != 3:
                continue
            if a[0]+a[1] > a[2]:
                ans += 1
print(ans)

Measured memory_bytes: 9140
main = getLine >>=putStrLn.calc.map (read::String->Int).words
		where
		calc :: [Int]->String
		calc1 [a,b,c]=if a<b
			then [a,b,c]
			else [b,a,c]
		calc2 [a,b,c]=if b<c
			then [a,b,c]
			else [a,c,b]
		calc=unwords.map show.calc1.calc2.calc1

Measured memory_bytes: 3624
#include<iostream>
int main()
{
	const int MAX=1000;
	using namespace std;
	int n,i,j,temp,count,A[MAX];
	count=0;
	cin>>n;
	for(i=0;i<n;i++)
		cin>>A[i];
	for(i=1;i<=n-1;i++)
		for(j=n-1;j>=i;j--)
			if(A[j-1]>A[j])
			{
				{
					temp=A[j-1];
					A[j-1]=A[j];
					A[j]=temp;
				}
				count++;
			}
	for(i=0;i<n;i++)
		if(i<n-1)
			cout<<A[i]<<' ';
		else
			cout<<A[i];
	cout<<endl<<count<<endl;
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
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;}

string s;
string t;
vector<string> vec;

bool match(int k){
  rep(i,t.size()){
    if(s[i+k] != t[i] && s[i+k] != '?'){
      return false;
    }
  }
  return true;
}

string key(int k){
  string ans = s;
  
  rep(i,t.size()){
    ans[i+k] = t[i];
  }
  
  rep(i,s.size()){
    if(ans[i] == '?'){
      ans[i] = 'a';
    }
  }
  
  return ans;
  
}

int main(){
  cin >> s >> t;
  
  rep(i,s.size() - t.size() + 1){
    if(match(i)){
      string ans = key(i);
      vec.push_back(ans);
    }
  }
  
  sort(vec.begin(),vec.end());
  
  if(vec.size() > 0){
    cout << vec[0];
  }else{
    cout << "UNRESTORABLE";
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B, C, D;
	int L, R;
	int Decision;
	
	scanf("%d %d %d %d", &A, &B, &C, &D);

	L = A + B;
	R = C + D;

	Decision = L - R;

	if (Decision < 0) printf("Right");
	else if(Decision == 0) printf("Balanced");
	else printf("Left");

	return 0;
}

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

template <typename T>
struct segtree {
	int n;
	vector<T> tree;
	T def = numeric_limits<T>::max(), none = numeric_limits<T>::max();
	
	segtree(int n_) {
		for (n = 1; n < n_; n *= 2) {
			
		}
		tree.assign(2 * n, def);
	}
	
	T get(int index) {
		assert(0 <= index && index < n);
		return tree[n + index];
	}
	
	T merge(T a, T b) {
		return min(a, b);
	}
	
	void update(int index, T x) {
		assert(0 <= index && index < n);
		tree[index += n] = x;
		for (index /= 2; index; index /= 2) {
			tree[index] = merge(tree[2 * index], tree[2 * index + 1]);
		}
	}
	
	T query(int a, int b, int index, int l, int r) {
		assert(0 <= a && a < b && b <= n);
		assert(0 <= l && l < r && r <= n);
		if (r <= a || b <= l) {
			return none;
		}
		if (a <= l && r <= b) {
			return tree[index];
		}
		T puni = query(a, b, 2 * index, l, (l + r) / 2);
		T muni = query(a, b, 2 * index + 1, (l + r) / 2, r);
		return merge(puni, muni);
	}
	
	T query(int l, int r) {
		assert(0 <= l && l < r && r <= n);
		return query(l, r, 1, 0, n);
	}
};

int main() {
	int n, q;
	cin >> n >> q;
	segtree<int> seg(n);
	for (int i = 0; i < q; i++) {
		bool f;
		int x, y;
		cin >> f >> x >> y;
		if (f) {
			cout << seg.query(x, y + 1) << endl;
		} else {
			seg.update(x, y);
		}
	}
	return 0;
}

Measured memory_bytes: 3896
#include <stdio.h>
int main(void){
    
    int n,m,i,j;
    scanf( "%d %d" , &n , &m );
    int a[n][m];
    int b[m];
    int c = 0;

    for( i = 0; i < n ; i++ ){
        for( j = 0 ; j < m ; j++ ){
            scanf("%d" , &a[i][j] );
        }
    }

    for( i = 0; i < m ; i++ ){
            scanf("%d" , &b[i] );
    }


    for( i = 0; i < n ; i++ ){
        for( j = 0 ; j < m ; j++ ){
            c += a[i][j] * b[j];
        }
        printf( "%d\n" , c );
        c = 0;
    }
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <variant>
#include <atcoder/all>
#define FOR(i,k,n) for(ll i=(k);i<(ll)(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) begin(x),end(x)
 
using namespace std;
using namespace std::string_literals;
using namespace atcoder;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

// ax+by=gcd(a,b)
// |x|+|y| -> min
// x <= y
ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll g = a; x = 1; y = 0;
  if (b) g = extgcd(b, a%b, y, x), y -= (a / b) * x;
  return g;
}

constexpr ll INF = 1e16;

ll calc(ll a, ll b) {
  ll x,y;
  ll g = extgcd(a, b, x, y);
  if (g != 1) return INF;
  if (x < 0) {
    ll tmp = -x * a;
    if (x+b >= 0) {
      tmp = min(tmp, b*(a-y));
    }
    return tmp;
  } else {
    ll tmp = -y * b;
    if (y+a >= 0) {
      tmp = min(tmp, a*(b-x));
    }
    return tmp;
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n;
  cin>>n;
  ll mn = max(1l, n-1);
  ll div = 2*n;
  for (ll i = 2; i*i <= div; ++i) {
    if (div % i == 0) {
      ll j = div / i;
      mn = min(mn, calc(j, i));
    }
  }
  cout << mn << endl;
  return 0;
}


Measured memory_bytes: 3688
while True:
    middle,semester,additional = map(int,raw_input().split())
    if middle == -1 and semester == -1 and additional == -1:
        break
    else:
        if middle == -1 or semester == -1 or middle + semester < 30:
            print("F")
        elif middle + semester >= 80:
            print("A")
        elif middle + semester >= 65:
            print("B")
        elif middle + semester >= 50:
            print("C")
        else:
            if additional >= 50:
                print("C")
            else:
                print("D")
                

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

int main() {
  int n;
  double xa,ya,ra;
  double xb,yb,rb;
  
  cin>>n;

  for(int i=0; i<n; i++) {
    cin>>xa>>ya>>ra>>xb>>yb>>rb;
    
    double d = sqrt( (xb-xa)*(xb-xa) + (yb-ya)*(yb-ya) );
    int res;
    
    if(ra+rb<d) res=0;
    else if( d<ra-rb ) res=2;
    else if( d<rb-ra ) res=-2;
    else res=1;
    
    cout << res << endl;
  }
    
  return 0;
}

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

int main(){
 int x;
 cin >> x;
 int c500 = x / 500;
 x -= c500 * 500;
 int c5 = x / 5;
 int ans = c500 * 1000 + c5 * 5;
 cout << ans << endl;
}


Measured memory_bytes: 256
S = input()
if len(set(S)) == 1:
    print(0)
    exit()
ans = len(S)
for i in range(26):
    seq = [s for s in S]
    p = chr(ord('a')+i)
    for j in range(len(S)-1):
        for k in range(len(S)-j-1):
            if seq[k+1] == p:
                seq[k] = seq[k+1]
        for k in range(len(S)-j-1):
            if seq[k] != p:
                break
        else:
            ans = min(ans, j+1)
            break
print(ans)

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

ll gcd(ll x,ll y)
{
	return x%y?gcd(y,x%y):y;
}

int main()
{
    ll a,b;
    while(cin>>a>>b)
    {
        ll ans;
        ans=a*b/gcd(a,b);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
def cmb(a,b,c):
    b = min(b,a-b)
    num = 1
    for i in range(b):
        num = num*(n-i) % c
    den = 1
    for i in range(b):
        den = den*(i+1) % c
    return num*pow(den,c-2,c) % c
mod = 10**9+7
n,a,b = map(int,input().split())
ans  = (pow(2,n,mod)-cmb(n,a,mod)-cmb(n,b,mod)-1) % mod
if ans < 0:
    ans = ans + mod
print(ans)

Measured memory_bytes: 63632
times = int(input())
numbers = list(map(int, input().split()))
count = 0
minj = 0

for i in range(times):
    minj = i
    for j in range(i, times, 1):
        if numbers[j] < numbers[minj]:
            minj = j

    if i != minj:
        numbers[i], numbers[minj] = numbers[minj], numbers[i]
        count += 1

print(' '.join(map(str, numbers)))
print(count)



Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007
using namespace std;

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

	cout<<a*b/2<<endl;
	
	return 0;
}


Measured memory_bytes: 256
s = 3.times.map{gets.chomp}
t = ["A","B","C"]
i = 0
j = 0
loop do
  case s[i].chr
  when "a"
    i = 0
  when "b"
    i = 1
  when "c"
    i = 2
  end
  if s[i].size == 0
    puts t[i]
    break
  else
    s[j].slice!(0)
    j = i
  end
end

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

K = int(input())

fueru = [[(x + i - 1) for x in range(3) if 0 <= x + i - 1 <= 9]
         for i in range(10)]

if K <= 9:
    ans = K
    print(ans)
    exit()

last_lst = [i + 1 for i in range(9)]
count = len(last_lst)
for idx in range(10):
    new_lst = []
    for l in last_lst:
        for c in fueru[int(str(l)[-1])]:
            new_lst.append(str(l) + str(c))

    if K <= count + len(new_lst):
        ans = new_lst[K - count - 1]
        print(ans)
        exit()

    count += len(new_lst)
    last_lst = new_lst


Measured memory_bytes: 57180
#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>


typedef long long ll;
typedef long double ld;
using namespace std;
using namespace __gnu_pbds;


#define endl "\n"
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
const int N=1e5+5, mxN=(1<<20)+5;
int mod=1e9+7;
int arr[N];
int main()
{
    FIO
   int n,k;
   cin>>n>>k;
   for(int i=0;i<n;i++)
    cin>>arr[i];
   sort(arr,arr+n);
   ll ans=1e18;
   for(int i=0;i<n;i++)
   {
       if(i+k-1<n)
       {
           int j=i+k-1;
           ll co=abs(arr[i])+abs(arr[j]-arr[i]);
           ll co2=abs(arr[j])+abs(arr[i]-arr[j]);
           ans=min(ans,min(co,co2));

       }
       else
        break;
   }

   cout<<ans;
     return 0;

}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int cnt = 0;
        if(i % 2 == 1)
        {
            for(int j = 1; j <= i; j++)
            {
                if(i % j == 0)
                {
                    cnt++;
                }
            }
            
            if(cnt == 8)
            {
                ans++;
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  int L,R;
  
  cin >> A >> B >> C >>D;
  L = A + B;
  R = C + D;
  
  if ( L > R ) {
    
    cout << "Left" << endl;
    
  } else if ( L < R ){
    
    cout << "Right" << endl;
  } else {
    
    cout << "Balanced" << endl;
  }
}
    

Measured memory_bytes: 3628
#include<stdio.h>
int main() {
  int n, i, j, m, h;
  scanf("%d", &n);
  int u[n], k[n], A[n][n];
  for(i = 0; i < n; i++) {
    scanf("%d%d", &u[i], &k[i]);
    if(k[i] != 0) {
      for(j = 0; j < k[i]; j++) {
	scanf("%d", &A[i][j]);
      }
    }
  }
  for(i = 0; i < n; i++) {
    for(j = 0; j < n; j++) {
      if(k[i] != 0) {
	for(m = 0; m < k[i]; m++) {
	  h = 0;
	  if(j == (A[i][m]-1)) {
	    h = 1;
	    break;
	  }
	}
	if(h == 1) printf("1");
	else printf("0");
      }
      else printf("0");
      if(j != n-1) printf(" ");
    }
    printf("\n");
  }
  return 0;
}

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

int main() {
int n;
cin>>n;
string s;
cin>>s;
int i=0;
int j= n/2;
if(n<2 || n%2!=0){
    cout<<"No"; return 0;
}

while(s[i]==s[j] && j<n){
    i++;
    j++;
}

if(j==n){
    cout<<"Yes";
}
else{
    cout<<"No";
}
return 0;
}

Measured memory_bytes: 256
import math
import numpy as np

def findnext(l, mx):
    for i in range(1, mx+1):
        if i not in l:
            return i
    return -1

def solve():
    n, k = map(int, input().split())
    prob = np.float64(0.0)
    for i in range(1, n+1):
        #i:出目
        #L:必要なコイン投げ回数
        if k > i:
            L = math.ceil(math.log2(float(k)/float(i)))
            prob += np.power(np.float64(0.5), L)
        else:
            prob += np.float64(1.0)

    prob = prob / np.float64(n)
    print(prob.astype(str))

solve()

Measured memory_bytes: 12484
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;

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

void solve(){
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	A += B;
	C += D;
	if(A>C){
		cout << "Left";
	}else if(A<C){
		cout << "Right";
	}else{
		cout << "Balanced";
	}
	cout << endl;
}

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

Measured memory_bytes: 256
#include<iostream>
int main()
{
	int n;
	int q;
	int s[10000]={0};
	int t[500]={0};
	int cnt=0;
	int i,j;
	
	std::cin>>n;
	for(i=0;i<n;i++){
		std::cin>>s[i];
	}
	
	std::cin>>q;
	for(i=0;i<q;i++){
		std::cin>>t[i];
	}

	for(i=0;i<q;i++){
		for(j=0;j<n;j++){
			if(s[j]==t[i]){
				cnt++;
				break;
			}
		}
	}
	std::cout<<cnt<<'\n';
	return 0;
}


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

namespace AtCoder
{
    class ABC
    {
        static void Main(string[] args)
        {
            int[][] N = new int[3][];
            for (int i = 0; i < 3; i++)
            {
                N[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            bool j = true;
            if (N[0][0] + N[1][1] + N[2][2] != N[2][0] + N[1][1] + N[0][2]) j = false;
            if (N[0][0] + N[1][2] + N[2][1] != N[0][2] + N[1][0] + N[2][1]) j = false;
            if (N[0][1] + N[1][0] + N[2][2] != N[0][1] + N[1][2] + N[2][0]) j = false;

            int sum = 0;
            for(int i = 0; i < 3; i++)
            {
                for(int k = 0; k < 3; k++)
                {
                    sum += N[i][k];
                }
            }

            if (sum / 3 != N[0][0] + N[1][1] + N[2][2]) j = false;
            if (sum / 3 != N[0][0] + N[1][2] + N[2][1]) j = false;
            if (sum / 3 != N[0][1] + N[1][0] + N[2][2]) j = false;

            Console.WriteLine(j ? "Yes" : "No");
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>

using namespace std;


int main(void) {
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;

    int table[401][401];
    for(int i=0; i<=400; i++) {
        for(int j=0; j<=400; j++) {
            table[i][j] = 1000000;
        }
    }
    table[0][0] = 0;

    while(N--) {
        int a, b, c;
        cin >> a >> b >> c;
        for(int i=400-a; i>=0; i--) {
            for(int j=400-b; j>=0; j--) {
                table[i+a][j+b] = min(table[i+a][j+b], table[i][j] + c);
            }
        }
    }

    int ans = 1000000;
    for(int i=1; i<=400; i++) {
        for(int j=1; j<=400; j++) {
            if(Ma*j == Mb*i) {
                ans = min(ans, table[i][j]);
            }
        }
    }

    if(ans == 1000000) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a+b==15){
    cout << '+' << endl;
  }
  else if(a*b==15){
    cout << '*' << endl;
  }
  else{
    cout << 'x' << endl;
  }
  return 0;
}

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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int N;
    cin >> N;
    cout << 800 * N - 200 * (N / 15) << endl;

    return 0;
}


Measured memory_bytes: 888
from math import ceil
from fractions import gcd


def lcm(x, y):
    return (x * y) // gcd(x, y)


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

A = max(b // c - ceil(a / c) + 1, 0)
B = max(b // d - ceil(a / d) + 1, 0)
C = max(b // lcm(c, d) - ceil(a / lcm(c, d)) + 1, 0)
print(max(b-a+1-(A+B-C), 0))


Measured memory_bytes: 5044
#include<stdio.h>
int main(){
    int a,op,b;
 
    while(1){
        scanf("%d %c %d",&a,&op,&b);
        switch(op){
        case'?':
            break;
        case'+':
            printf("%d\n",a+b);
            break;
        case'-':
            printf("%d\n",a-b);
            break;
        case'*':
            printf("%d\n",a*b);
            break;
        case'/':
            printf("%d\n",a/b);
            break;
        }
        if(op=='?') break;
 
    }
 
    return 0;
}




Measured memory_bytes: 2080
#include <iostream>
#include <vector>
#include <map>

#define ALP 26

using namespace std;

struct Day_data{
    int penalty;
    int satis[ALP];
    int lasts[ALP];
    int selected;
};

struct Solution_data{
    int days;

    int penalties[ALP];
    vector<Day_data> day_data;
    int satis_sum;
    int penal_sum;

    Solution_data(int d);
    int get_score();
    void solve_greedily();
};

Solution_data::Solution_data(int d): days(d), day_data(d)
{
    satis_sum = 0;
    penal_sum = 0;

    for(int i = 0; i < d; i++){
        for(int j = 0; j < ALP; j++){
            day_data[i].lasts[j] = -1;
        }
    }
}

int Solution_data::get_score()
{
    return satis_sum - penal_sum;
}

void Solution_data::solve_greedily()
{
    for(int i = 0; i < days; i++){
        pair<int, int> max = make_pair(0, day_data[i].satis[0] + penalties[0]);
        for(int j = 1; j < ALP; j++){
            int day_score = day_data[i].satis[j] + penalties[j];
            if(max.second < day_score){
                max.first = j;
                max.second = day_score;
            }
        }

        day_data[i].selected = max.first;
        for(int j = i; j < days; j++){
            day_data[i].lasts[max.first] = i;
        }
        satis_sum += day_data[i].satis[max.first];

        for(int j = 0; j < ALP; j++){
            penal_sum += (i - day_data[i].lasts[j]) * penalties[j];
        }
    }
}

int main(void)
{
    int days;
    cin >> days;

    Solution_data sol(days);

    for(int i = 0; i < ALP; i++){
        int p;
        cin >> p;
        sol.penalties[i] = p;
    }

    for(int i = 0; i < days; i++){
        for(int j = 0; j < ALP; j++){
            int s;
            cin >> s;
            sol.day_data[i].satis[j] = s;
        }
    }

    for(int i = 0; i < days; i++){
        for(int j = 0; j < ALP; j++){
            sol.day_data[i].lasts[j] = -1;
        }
    }

    sol.solve_greedily();

    for(int i = 0; i < days; i++){
        cout << sol.day_data[i].selected + 1 << endl;
    }
}

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

int main(){
	ll N; cin>>N;
    ll ans=0;
    vector<ll> A(N);
    rep(i,N) cin>>A[i];
  	sort(A.begin(),A.end());
  	ll mcnt=0;
  	rep(i,N){
    	if(A[i]<0) mcnt++;
    }
  	if(mcnt%2==0){
    	rep(i,N){
        	if(A[i]<0) ans-=A[i];
          	else ans+=A[i];
        }
      	printf("%lld",ans);
      	return 0;
    }
  	else if(mcnt==N){
      	A[N-1]*=-1;
    	rep(i,N) ans-=A[i];
     	printf("%lld",ans);
      	return 0;
    }
  	else{
    	rep(i,mcnt-1){
        	ans-=A[i];
        }
      
      	if(abs(A[mcnt-1])>A[mcnt]){
        	ans=ans-A[mcnt-1]-A[mcnt];
        }
      	else{
        	ans=ans+A[mcnt-1]+A[mcnt];
        }
      
      	for(int i=mcnt+1;i<N;i++){
        	ans+=A[i];
        }
      	printf("%lld",ans);
      	return 0;
    }
}

Measured memory_bytes: 1024
#include<cstdio>
int n,cntr,cnte;
char c;
int main(){
	scanf("%d\n",&n);
	for(register int i=1;i<=n;i++){
		scanf("%c",&c);
		if(c=='R')cntr++;
		else cnte++;
	}
	if(cntr>cnte)puts("Yes");
	else puts("No");
}

Measured memory_bytes: 128
N, C = [int(_) for _ in input().split()]
D = [[int(_) for _ in input().split()] for i in range(C)]
c = [[int(_) - 1 for _ in input().split()] for i in range(N)]

from collections import defaultdict
from itertools import permutations

xs = [defaultdict(int) for _ in range(3)]

for i, row in enumerate(c):
    for j, x in enumerate(row):
        xs[(i + j) % 3][x] += 1

cs = [[sum(D[x][j] * num for x, num in xs[i].items()) for j in range(C)] for i in range(3)]

result = min(
    cs[0][c1] + cs[1][c2] + cs[2][c3]
    for c1, c2, c3
    in permutations(range(C), 3)
)
    
print(result)

Measured memory_bytes: 5748
#!/usr/bin/env python3
import sys
import collections as cs

def solve(N: int, A: "List[int]"):
    if len(set(A))==len(A):
        for i in range(N):
            print(0)
        exit()
    q=0
    p=cs.Counter(A)
    for o in p.values():
        q+=o*(o-1)//2
    for i in range(N):
        print(q-p[A[i]]+1)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()


Measured memory_bytes: 83148
def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret

def main():
    global n
    n=int(input())
    print(dfs('0'))

if __name__ == "__main__":
    main()

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

string s1, s2, s3;

int main(){
    cin >> s1 >> s2 >> s3;
    cout << char(s1[0]-0x20) << char(s2[0]-0x20) << char(s3[0]-0x20);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int N;
  std::cin >> N;
  switch (N%10) {
    case 0:
    case 1:
    case 6:
    case 8:
      std::cout << "pon" << std::endl;
      break;
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      std::cout << "hon" << std::endl;
      break;
    case 3:
      std::cout << "bon" << std::endl;
      break;
  }
  return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[200010],b[200010]={};
    vll v;
    cin >> n;
    rep2(i,1,n+1){
        cin>>a[i];
    }
    for(ll i=n;i>0;i--){
        ll sum=0;
        for(ll j=i;j<=n;j+=i){
            sum+=b[j];
        }
        if(sum%2!=a[i]){
            v.pb(i);
            b[i]=1;
        }
    }
    cout<<v.size()<<endl;
    rep(i,(ll)v.size()){
        cout<<v[i];
        if(i!=(ll)v.size()-1){
            cout<<" ";
        }
    }
    if(v.size())cout<<endl;
    return 0;
}

Measured memory_bytes: 5236
/*Remember: The Struggle is Important*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

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

#define     int          long long int
#define     fast()       ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)       x.begin(),x.end()
#define     mem(a,b)     memset(a,b,sizeof(a))
#define     gcd(a,b)     __gcd((a),(b))
#define     lcm(a,b)     ((a)*(b))/gcd((a),(b))
#define     pb           push_back
#define     ins          insert
#define     F            first
#define     S            second

const int inf=1e18,MOD=1e9+7;

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

 vector<int> v(n+5,0);

 int a,b;
 for(int i=0;i<m;++i)
 {
  cin>>a>>b;
  ++v[a];
  --v[b+1];
 }

 int sum=0,ans=0;
 for(int i=1;i<=n;++i)
 {
  sum+=v[i];
  v[i]=sum;

  if(sum==m)
  ++ans;
 }

 cout<<ans;
}

int32_t main()
{
 fast();

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

 return 0;
}



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

int count(long long n){
    int cnt=0;
    while(n>0){
        n/=10;
        cnt++;
    }
    return cnt;
}

int main(){
    long long n;
  	long long b;
    int cur=0;
  	int ans=100000;
    cin>>n;
    for(long long i=1;i*i<=n;i++){
       if(n%i==0){
       b=n/i;
       cur=max(count(i),count(b));
       if(ans>cur)ans=cur;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    int l = 0, r = S.size()-1;
    int res = 0;
    while(l <= r) {
        if(S[l] == S[r]) { ++l, --r; continue; }
        if(S[l] == 'x') { ++l, ++res; continue; }
        if(S[r] == 'x') { --r, ++res; continue; }
        cout << -1 << endl; return 0;
    }
    cout << res << endl;
    return 0;
}

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

typedef long long ll;

const int MAXV = 1e5 + 10;
const int MAXN = 1e3 + 10;
const ll INF = 1e13;

ll dp[MAXV];
int N,W,V,wi[MAXN],vi[MAXN];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++) dp[i] = INF;
	dp[0] = 0;

	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}


Measured memory_bytes: 1024
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String x = sc.next();
      String y = sc.next();
      if(x.compareTo(y) > 0)System.out.println(">");
      else if(x.compareTo(y) == 0)System.out.println("=");
      else System.out.println("<");
    }
}

Measured memory_bytes: 21844
S = input()
n = len(S)
ans = 0
for i in range(2**(n-1)) :
    c = 0
    for j in range(n-1) :
        if (i>>j)&1 :
            ans += int(S[c:j+1])
            c = j + 1
    else :
        ans += int(S[c:])
print(ans)

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

#define rep(i, j, n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define Puts(x) puts(x? "Yes":"No")
const int mod = 1e9 + 7;

typedef long long i64;
typedef pair<int, int> pi;

template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;

i64 gcd(int n, int m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(int n, int m) {return (n / gcd(n, m) * m);}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};

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

  int n, t, a;
  cin >> n >> t >> a;

  double tmp = DBL_MAX;
  int num = 0;
  rep(i, 0, n) {
    int h;
    cin >> h;

    double d = t - h * 0.006;
    if(tmp > abs(a - d)) {
      num = i + 1;
      tmp = abs(a - d);
    }
  }
  cout << num << endl;
}


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

//typedef
//------------------------------------------
typedef int64_t LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define rwhole(f,x,...) ([&](decltype((x)) whole) { return (f)(rbegin(whole), rend(whole), ## __VA_ARGS__); })(x)
#define EACH(i,c) for(decltype((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) whole(sort, c)
#define RSORT(c) rwhole(sort, c)

//constant
//--------------------------------------------
constexpr double EPS = 1e-10;
constexpr double PI  = M_PI;
constexpr int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

template<class T,class U> void chmax(T&a,U b){if(a<b)a=b;}
template<class T,class U> void chmin(T&a,U b){if(b<a)a=b;}
LL gcd(LL a, LL b) { return b?gcd(b,a%b):a;}
LL lcm(LL a, LL b) { return a/gcd(a,b)*b;}

//main code

int main(int argc, char *argv[])
{
	int a,b,h;
	cin >> a >> b >> h;
	cout <<((a+b)*h)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

void solve() {
  int c, n;
  cin >> c >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int mx = a[0] + c - a[n - 1];
  for (int i = 1; i < n; ++i) { mx = max(mx, a[i] - a[i - 1]); }
  cout << c - mx << "\n";
}

int main(int argc, char *argv[]) {
  int o_o = 1;
  if (!o_o) cin >> o_o;
  for (; o_o; --o_o) solve();
  return 0;
}


Measured memory_bytes: 1024
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<int> vsize;
    UnionFind(int size) : par(size), rank(size), vsize(size) {
        REP(i, size) {
            par[i] = i;
            rank[i] = 0;
            vsize[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }
    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
        vsize[x] += vsize[y];
        vsize[y] = vsize[x];
    }
    bool same(int x, int y) { return find(x) == find(y); }
    int getSize(int x) { return vsize[find(x)]; }
};

typedef pair<int, int> P;

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

    int N, K, L;
    cin >> N >> K >> L;

    UnionFind uf1(N + 1);
    REP(i, K) {
        int p, q;
        cin >> p >> q;
        p--;
        q--;
        uf1.unite(p, q);
    }

    UnionFind uf2(N + 1);
    REP(i, L) {
        int r, s;
        cin >> r >> s;
        r--;
        s--;
        uf2.unite(r, s);
    }

    map<P, int> cnt;
    REP(i, N) {
        cnt[{uf1.find(i), uf2.find(i)}]++;
    }
    REP(i, N) {
        cout << cnt[{uf1.find(i), uf2.find(i)}] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 21120
#include <stdio.h>

int main(){
    int m, f, r;
    while(1){
        scanf("%d%d%d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1) break;
        if(m == -1 || f == -1) printf("F\n");
        else if(m+f >= 80) printf("A\n");
        else if(m+f >= 65) printf("B\n");
        else if(m+f >= 50) printf("C\n");
        else if(m+f >= 30){
            if(r >= 50) printf("C\n");
            else printf("D\n");
        }
        else printf("F\n");
    }
    return 0;
}


Measured memory_bytes: 2044
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

int main() {
  int n;
  cin >> n;
  int dx[] = {0,1,0,-1};
  int dy[] = {-1,0,1,0};
  while(n--) {
    int h,w;
    cin >> h >> w;
    char ba[w][h];
    int nx, ny, d;
    REP(i,h)
      REP(j,w) {
      cin >> ba[j][i];
      if (ba[j][i]=='^') {
        nx = j;
        ny = i;
        d = 0;
      } else if  (ba[j][i]=='>') {
        nx = j;
        ny = i;
        d = 1;
      } else if  (ba[j][i]=='v') {
        nx = j;
        ny = i;
        d = 2;
      } else if  (ba[j][i]=='<') {
        nx = j;
        ny = i;
        d = 3;
      }
    }
    ba[nx][ny] = '.';
    int m;
    cin >> m;
    REP(i,m) {
      char c;
      cin >> c;
      if (c=='S') {
        int sx=nx, sy=ny;
        while(1) {
          sx+=dx[d];
          sy+=dy[d];

          if (sx<0||sx>=w||sy<0||sy>=h) break;
          if (ba[sx][sy]=='*') {
            ba[sx][sy] = '.';
            break;
          } else if (ba[sx][sy] == '#') break;
        }
      } else {
        if (c=='U') {
          d = 0;
        }else if (c=='D')
          d=2;
        else if (c=='L')
          d = 3;
        else
          d=1;
        int nnx = nx+dx[d];
        int nny = ny+dy[d];
        if (nnx>=0&&nnx<w&&nny>=0&&nny<h && ba[nx+dx[d]][ny+dy[d]] == '.') {
          nx += dx[d];
          ny += dy[d];
        }
      }
    }
    string hoge="^>v<";
    ba[nx][ny] = hoge[d];
    REP(y,h) {
      REP(x,w)
        cout << ba[x][y];
      cout << endl;
    }
    if (n)cout << endl;
  }
}

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

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

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  
  int sum = 0;
  rep(i, N)
  {
    int tmp = calc_sum(i);
    
    if ((A <= tmp) && (B >= tmp))
    {
      sum += i;
    }
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 10005

const int INF = 1e9+7;

string s;
int now = 0;

int solve(){

    if(isdigit(s[now])){
        int num = 0;
        while(now < s.size() && isdigit(s[now])){
            num = num * 10 + s[now] - '0';
            now++;
        }
        return (num + 1)/2;
    }else{

        vector<int> vec;
        int cnt = 0;
        while(s[now] == '['){
            now++;
            vec.push_back(solve());
            now++;
        }
        sort(vec.begin(),vec.end());
        for(int i = 0;i < (vec.size() + 1)/2;i++){
            cnt += vec[i];
        }
        return cnt;
    }
}


int main(){

    int q;
    cin >> q;
    for(int i = 0;i < q;i++){
        now = 0;
        cin >> s;
        cout << solve() << endl;
    }
}


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

int main(){
    char s[3];
    char t[3];
    int i, count=0;
    cin >> s;
    cin >> t;
    
    for (i=0; i < 3; i++) {
        if (s[i]==t[i]) {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<iomanip>
#include<cstdlib>
#include<cmath>
#include<cstdio>
using namespace std;

int main()
{
	int n, a = 100000;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int b = a * 5 / 100;
		a += b;
		if (a % 1000)a = (a / 1000 + 1) * 1000;
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 1160