akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    vector<ll> v(4);
    rep(i, 4) v[i] = s[i] - '0';
    rep(op1, 2) {
        rep(op2, 2) {
            rep(op3, 2) {
                ll tmp = v[0];
                if (op1 == 0) tmp += v[1];
                else tmp -= v[1];
                if (op2 == 0) tmp += v[2];
                else tmp -= v[2];
                if (op3 == 0) tmp += v[3];
                else tmp -= v[3];
                if (tmp == 7) {
                    string ans = "";
                    ans += to_string(v[0]) + ((op1 == 0) ? "+" : "-");
                    ans += to_string(v[1]) + ((op2 == 0) ? "+" : "-");
                    ans += to_string(v[2]) + ((op3 == 0) ? "+" : "-");
                    ans += to_string(v[3]) + "=7";
                    cout << ans << endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include <math.h>
#include<algorithm>
#include<vector>
using namespace std;

int main() {
	long long h;
	cin >> h;

	long long count = 0;
	int i = 0;
	while (h > 0) {
		count = count + pow(2,i);
		h = h / 2;
		i++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <cstdio>
const int MAXS = 3;
char S[MAXS + 5];
char T[MAXS + 5];

int main() {
  scanf(" %s%s", S, T);
  int ret = 0;
  for (int i = 0; i < MAXS; ++i) {
    if (S[i] == T[i]) ++ret;
  }
  printf("%d\n", ret);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#pragma warning(disable:4996)

using namespace std;


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

	long long n, i, j, k, ans = 0;
	cin >> n;
	for (i = 1; i <= n; i++) {
		if (i % 3 == 0) continue;
		if (i % 5 == 0) continue;
		ans += i;
	}
	cout << ans << "\n";

	return 0;
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<class T> struct Zip{
    vector<T> val;
    unordered_map<T, int> idx;

    void add(const T v){ val.emplace_back(v); }

    void zip(){
        sort(val.begin(), val.end());
        val.erase(unique(val.begin(), val.end()), val.end());
        for(int i = 0;i < val.size();i++) idx[val[i]] = i;
    }

    int operator[] (const T v) { return idx[v]; }
    T operator() (const int i) { return val[i]; }
    int size() { return val.size(); }
};

struct Box{
	bool left;
	bool right;
	bool top;
	bool down;
	bool v;

	Box(){
		left = right = top = down = true;
		v = false;
	}
};

Box mas[4000][4000];

struct Num{
	int a, b, c, d, e, f;
};

Zip<int> tate, yoko;
int dfs(int i, int j){
	queue<pair<int, int>> que;
	que.push({i, j});
	int ans = 0;
	while(!que.empty()){
		i = que.front().first;
		j = que.front().second;
		que.pop();
		if(mas[i][j].v) continue;
		if(i == 0 || i == tate.size()-1 || j == 0 || j == yoko.size()-1){
			cout << "INF" << endl;
			exit(0);
		}
		mas[i][j].v = true;
		ans += (tate(i)-tate(i-1)) * (yoko(j)-yoko(j-1));
		if(mas[i][j].left) que.push({i, j-1});
		if(mas[i][j].right) que.push({i, j+1});
		if(mas[i][j].top) que.push({i+1, j});
		if(mas[i][j].down) que.push({i-1, j});
	}
	return ans;
}

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

	Num t[1010], y[1010];
	
	for(int i = 0;i < n;i++){
		cin >> t[i].a >> t[i].b >> t[i].c;
		tate.add(t[i].a);
		tate.add(t[i].b);
		yoko.add(t[i].c);
	}

	for(int i = 0;i < m;i++){
		cin >> y[i].d >> y[i].e >> y[i].f;
		tate.add(y[i].d);
		yoko.add(y[i].e);
		yoko.add(y[i].f);
	}

	tate.add(INT_MIN);
	yoko.add(INT_MIN);
	tate.add(INT_MAX);
	yoko.add(INT_MAX);

	tate.add(0);
	yoko.add(0);
	tate.zip();
	yoko.zip();

	for(int i = 0;i < n;i++){
		int idx = yoko[t[i].c];
		int l = tate[t[i].a];
		int r = tate[t[i].b];
		for(int j = l+1;j <= r;j++){
			mas[j][idx].right = false;
			mas[j][idx+1].left = false;
		}
	}

	for(int i = 0;i < m;i++){
		int idx = tate[y[i].d];
		int l = yoko[y[i].e];
		int r = yoko[y[i].f];
		for(int j = l+1;j <= r;j++){
			mas[idx][j].top = false;
			mas[idx+1][j].down = false;
		}
	}

	int ans = dfs(tate[0], yoko[0]);

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


Measured memory_bytes: 82160
a,b,c=map(int,input().split())
temp=[]
temp.append(a%b)
i=2
while True:
  temp.append(a*i%b)
  if temp[i-1]==temp[0]:
    break
  i=i+1
count=0
for i in range(0,len(temp)):
  if temp[i]==c:
    count=1
if count==1:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,m,k = map(int,ipt().split())
    a = [int(i) for i in ipt().split()]
    b = [int(i) for i in ipt().split()]
    an = n
    bn = m
    sm = 0
    for i,ai in enumerate(a):
        if sm+ai > k:
            an = i
            break
        sm += ai
    for i,bi in enumerate(b):
        if sm+bi > k:
            bn = i
            break
        sm += bi
    ma = an+bn
    for i in range(an):
        ai = a[an-1-i]
        sm -= ai
        for j in range(bn,m):
            if sm+b[j] > k:
                bn = j
                break
            elif j == m-1:
                bn = m
            sm += b[j]
        if ma < an-i-1+bn:
            ma = an-i-1+bn
        if bn == m:
            print(ma)
            exit()
    print(ma)


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 112808
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
 
#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
typedef long long ll;
using namespace std;

int n,m,mem;
bool ab[100000];

int main(){
	cin>>n>>m;
	lp(n)
		ab[i]=false;
	lp(2*m){
		cin>>mem;
		ab[mem-1]=!ab[mem-1];
	}
	lp(n)
		if(ab[i]){
			cout<<"NO"<<endl;
			return 0;
		}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(0); cin.tie(); cout.tie()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define len(a) (int)a.size()
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

using namespace std;

typedef long long ll;
typedef long double ld;

auto rnd = bind(uniform_int_distribution<int>(1, 10000), mt19937(time(0)));

bool is_prime (int n, int p) {
    for (int i = 2; i <= sqrt(n) && i <= p; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

ll binpow (ll a, ll n) {
	if (n == 0)
		return 1;
	if (n % 2 == 1)
		return binpow(a, n - 1) * a;
	else {
		ll b = binpow (a, n / 2);
		return b * b;
	}
}

int main()
{
    boost;
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);
    ll moves = min(x / d, k);
    x -= moves * d;
    k -= moves;
    if (k % 2 == 0) {
        cout << x;
    }
    else {
        cout << d - x;
    }
    return 0;
}



Measured memory_bytes: 3700
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] f = new int[n];
		int sz = 0;
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			if (sz == 0) {
				f[sz] = a[0];
				++sz;
			} else {

				int ok = -1;
				int ng = sz;
				while (ng - ok > 1) {
					int middle = (ok + ng) / 2;
					if (f[middle] < a[i]) {
						ok = middle;
					} else {
						ng = middle;
					}
				}

				f[ok + 1] = a[i];
				if (ok + 1 == sz)
					++sz;
			}
		}
		
		System.out.println(sz);

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

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

typedef long long ll;
typedef double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    int n; ll k;
    cin >> n >> k;

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

    int cnt[41] = {0};

    for (int i = 0; i < n; i++)
        for (int j = 0; j < 41; j++)
            if (a[i] & (1ll << j))
                cnt[j]++;

    ll ans = 0, at = 0;

    for (int i = 41 - 1; i >= 0; i--) {
        int ns = cnt[i], nus = n - cnt[i];
        ll co = ns;

        if (co < nus and (at ^ (1ll << i)) <= k) {
            co = nus;
            at ^= (1ll << i);
        }

        ans += (1ll << i)*co;
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <malloc.h>
typedef struct node
{
	int ai;
	int time;
	struct node*left;
	struct node*right;
}tree;
tree* create(int now)
{
	tree*r=(tree*)malloc(sizeof(tree));
	r->ai=now;
	r->time=1;
	r->left=NULL;
	r->right=NULL;
	return r;
}
void add(tree*root,int now)
{
	if(root->ai==now)
	{
		root->time++;
		return;
	}
	if(root->ai<now)
	{
		if(root->right!=NULL)
		{
			add(root->right,now);
			return;
		}
		else
		{
			root->right=create(now);
			return;
		}
	}
	else
	{
		if(root->left!=NULL)
		{
			add(root->left,now);
			return;
		}
		else
		{
			root->left=create(now);
			return;
		}
	}
}
int allxian=0;
void searchall(tree*root)
{
	if(root==NULL)
		return;
	searchall(root->left);
	searchall(root->right);
	if(root->time%2!=0)
	{
		allxian++;
	}
}
int main()
{
	int alla[100001];
	int allcount=0;
	int i,j;
	int now;
	tree*root;
	scanf("%d",&allcount);
	scanf("%d",&now);
	root=create(now);
	for(i=0;i<allcount-1;i++)
	{
		scanf("%d",&now);
		add(root,now);
	}
	searchall(root);
	printf("%d",allxian);
	return 0;
} 

Measured memory_bytes: 3328
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1e5 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int n,k;
int w[MAXN];

bool is_judge(int x){
    int cnt=0,cur=0;
    int p=1;
    while(p<=n){
        while(p<=n){
            if(cur+w[p]>x) break;
            cur+=w[p++];
        }
        cur=0;
        cnt++;
    }
    return cnt<=k;
}

void work(){
    scanf("%d%d",&n,&k);
    int L=1,R=1000000000;
    for(int i=1;i<=n;i++){
        scanf("%d",&w[i]);
        L=max(L,w[i]);
    }
    int ans=0;
    while(L<=R){
        int mid=(L+R)>>1;
        if(is_judge(mid)){
            R=mid-1;
            ans=mid;
        }
        else{
            L=mid+1;
        }
    }
    printf("%d\n",ans);
}

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





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

using namespace std;

long long P_is_not_2_5(long long N, long long P, const string& S) {
    map<long long, long long> residual;
    residual.insert(make_pair(0LL, 1LL));
    long long pow10 = 1;
    long long curr = 0LL;
    for (long long i = N - 1; i >= 0; --i) {
        //int s = atoi(S.substr(i, 1).c_str());
        //int m = (s * pow10 + curr) % P;
        //if (residual.count(m) == 0) {
        //    residual.insert(make_pair(m, 0LL));
        //}
        //residual[m] += 1;
        //curr = m;
        long long x = (curr + pow10 * (long long)atoi(S.substr(i, 1).c_str())) % P;
        if (residual.count(x) == 0) {
            residual.insert(make_pair(x, 1LL));
        }
        else {
            residual[x] += 1;
        }
        curr = x;
        pow10 *= 10;
        pow10 %= P;
    }
    long long ans = 0;
    for (auto it : residual) {
        long long n = it.second;
        if (n >= 2) {
            ans += n * (n - 1) / 2;
        }
    }
    return ans;
}

long long P_is_2_or_5(long long N, long long P, const string& S) {
    long long ans = 0LL;
    for (long long i = 0; i < N; ++i) {
        long long c = (long long)atoi(S.substr(i, 1).c_str());
        if (c % P == 0) {
            ans += i + 1;
        }
    }
    return ans;
}

void Main() {
    long long N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    long long ans = 0LL;
    if (P == 2LL || P == 5LL) {
        ans = P_is_2_or_5(N, P, S);
    }
    else {
        ans = P_is_not_2_5(N, P, S);
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);



signed main(){

    int N, M;
    cin >> N >> M;

    int ans;

    if(N >= 2 && M >= 2){
        ans = (N - 2) * (M - 2);
    }else if(N == 1 && M >= 2){
        ans = M - 2;
    }else if(N >= 2 && M == 1){
        ans = N - 2;
    }else{
        ans = 1;
    }

    cout << ans;

    
    return 0;
}








void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<double> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  double sum = 0;
  for (int i = 0; i < n; i++) sum += a[i];

  int count = 0;
  double border = sum / (4 * m);
  for (int i = 0; i < n; i++){
    if (a[i] >= border) count++;
  }
  if (count >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N, M = map(int, readline().split())
    A = []
    B = []
    for _ in range(N):
        A.append(readline().decode('utf-8').strip())
    for _ in range(M):
        B.append(readline().decode('utf-8').strip())
    AH = N
    AW = len(A[0])
    BH = M
    BW = len(B[0])
    ans = 'No'
    for i in range(AH-BH+1):
        for j in range(AW-BW+1):
            if A[i][j:j+BW] == B[0]:
                for h in range(BH):
                    if A[i+h][j:j+BW] == B[h]:
                        continue
                    else:
                        break
                else:
                    ans = 'Yes'
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  int H, W;
  cin >> H >> W;
   for (int i = 0; i < H; i++) {
     vector<char> vec(W);
      for (int j = 0; j < W; j++) {
     cin >> vec.at(j);
      }
      for (int k = 0; k < W; k++) {
        cout << vec.at(k);
      }
     cout << endl;
      for (int k = 0; k < W; k++) {
        cout << vec.at(k);
      }
     cout << endl;
   }
}

Measured memory_bytes: 3596
n = int(input())
lst = [int(i) for i in input().split()]
rate = [0] * 8
num = 0

for i in range(n):
    k = lst[i] // 400
    if k < 8 and rate[k] == 0:
        rate[k] += 1
    elif k >= 8:
        num += 1


c = rate.count(1)
y = num+c
if c == 0:
    x = 1
else:
    x = c

print(x,y)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod =  1e9 + 7;
const int maxn = 10'000 + 5;
const int maxv = 1'000'000 + 5;
int arr[maxn], pf[maxv];
ll modpow(ll base, ll power) {
    ll res = 1;
    while (power) {
        if (power & 1)
            res = res * base % mod;
        base = base * base % mod;
        power >>= 1;
    }
    return res;
}
void fac(int num) {
    int cnt = 0;
    if (num % 2 == 0) {
        while (num % 2 == 0) {
            ++cnt;
            num /= 2;
        }
        pf[2] = max(pf[2], cnt);
    }
    for (int i = 3; i <= sqrt(num); i += 2) {
        if (num % i == 0) {
            cnt = 0;
            while (num % i == 0) {
                ++cnt;
                num /= i;
            }
            pf[i] = max(pf[i], cnt);
        }
    }
    if (num > 2)
        pf[num] = max(pf[num], 1);
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> arr[i];
        fac(arr[i]);
    }
    ll lcm = 1;
    for (int i = 2; i < maxv; ++i)
        lcm = lcm * modpow(i, pf[i]) % mod;
    ll res = 0;
    for (int i = 0; i < n; ++i)
        res = (res + lcm * modpow(arr[i], mod - 2) % mod) % mod;
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 2816
n = gets.to_i
qs = n.times.map{gets.split}
s = 0
qs.each do |q|
    if q[1] == "("
        s += q[2].to_i
    else
        s -= q[2].to_i
    end
    puts s == 0 ? "Yes" : "No"
end

Measured memory_bytes: 9744
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,d;
	cin >> n >> d;
	int ans = 0;
	for(int i = 0; i < n;++i){
		ll x,y;
		cin >> x >> y;
		double dist = sqrt(x*x+y*y);
		if(dist<= d)
			++ans;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3688
n, m, r = gets.split.map(&:to_i)
rr = gets.split.map{|e| e.to_i - 1}

d = Array.new(n) {Array.new(n, 1 << 30)}
n.times {|i| d[i][i] = 0}

m.times do
    a, b, c = gets.split.map{|e| e.to_i - 1}
    d[a][b] = d[b][a] = c + 1
end

n.times do |k|
    n.times do |s|
        next if s == k
        (s+1).upto(n-1) do |f|
            d[f][s] = d[s][f] = [d[s][f], d[s][k] + d[k][f]].min
        end
    end
end

p rr.permutation.map {|e| e.each_cons(2).inject(0){|r,(i,j)| r + d[i][j]}}.min

Measured memory_bytes: 15344
#include <stdio.h>

int main() {
	int x,y;
	while(1){
		scanf("%d %d",&x,&y);
		if ( x == 0 && y == 0 ) {
			break;
		}
			if ( x < y ) {
				printf("%d %d\n",x,y);
			} else {
				printf("%d %d\n",y,x);
		}
	}
	return 0;
}



Measured memory_bytes: 2024
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll k, n;
    cin >> k >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = LONG_LONG_MAX;
    rep(i, n) {
        ll tmp = 0;
        if (i == (n - 1)) {
            tmp = k - ((k - a[n - 1]) + a[0]);
            // printf("i=%lld, v=%lld, %lld\n", i, k - a[n - 1], a[i]);
        }
        else {
            tmp = k - (a[i + 1] - a[i]);
        }
        ans = min(ans, tmp);
        // printf("i=%lld, tmp=%lld\n", i, tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<vector>
#include<iostream>
#include<string>
#include<algorithm> 
using namespace std;
int main(){
	string s,t="AKIHABARA",pt="KIHBR";
	cin>>s;
	int pre=0;
	for(int i=0;s[i];i++){
		if(s[i]==pt[pre]){
			pre++;
		}
	}
	if(pre!=5){
		cout<<"NO"<<endl;
		return 0;
	}
	int i=0,j=0,k=0;
	while(s[i]){
		if(!t[j]){
			cout<<"NO"<<endl;
			return 0;
		}
		if(s[i]==t[j]){
			i++;
			j++;
			k=0;
		}else{
			j++;
			k++;
			if(k==2){
				cout<<"NO"<<endl;
				return 0;
			}
		}
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const int mod=1000000007;
const LL inf=0x3f3f3f3f3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

priority_queue<LL, vector<int>, greater<int> > l;   //最小值优先
priority_queue<LL> r;
LL lv[maxn], rv[maxn], data[maxn];
int n;

int main()
{
    while(~scanf("%d", &n)){
        while(!l.empty())l.pop();
        while(!r.empty())r.pop();
        LL x, ans, lsum=0, rsum=0;
        for(int i=0;i<2*n;i++){
            scanf("%lld", &x);
            data[i]=x;
            lsum+=x;
            l.push(x);
            if(i>=n-1){
                if(i>n-1){
                    lsum-=l.top();
                    l.pop();
                }
                lv[i-n+1]=lsum;
            }
        }
        for(int i=0;i<n;i++){
            scanf("%lld", &x);
            rsum+=x;
            r.push(x);
        }
        for(int i=2*n-1;i>=n-1;i--){
            rv[i-n+1]=rsum;
            r.push(data[i]);
            rsum+=data[i];
            rsum-=r.top();
            r.pop();
        }
        ans=-inf;
        for(int i=0;i<=n;i++){
            ans=max(ans, lv[i]-rv[i]);
        }
        printf("%lld\n", ans);
    }
    return 0;
}



Measured memory_bytes: 4216
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 1E6+7;

vector<int> adj[N];
int h[N];
int n,m,cnt;

bool check_good(int u)
{
    for (int i = 0;i < (int)adj[u].size();++i)
    {
        int tmp = adj[u][i];
        if (h[u] <= h[tmp]) return false;
    }
return true;
}

int main()
{
    fastIO
    cin>>n>>m;
    
    for (int i = 1;i <= n;++i) cin>>h[i];
    
    for (int i = 1;i <= m;++i)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    } 
    
    for (int i = 1;i <= n;++i)
        if (adj[i].size() >= 1)
        {
            if (check_good(i) == true) { ++cnt; }
        }
        else if (adj[i].size() == 0) { ++cnt; }
    
    cout<<cnt;
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ans = 0;
    int f_num = abs(x - y);
    if (a + b <= 2 * c)
        ans += (a + b) * (min(x , y));
    else
        ans += 2 * c * min(x , y);

    if (f_num != 0) {
        int value = (x > y)? a : b;
        if (value * f_num <= c * 2 * f_num)
            ans += value * f_num;
        else
            ans += c * 2 * f_num;
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 256
#include <stdio.h>

int h, w;

int main(void) {
    int row, col;
    
    while (1) {
        scanf("%d%d", &h, &w);
        if (h == 0 && w == 0) break;
        
        for (row = 1; row <= h; ++row) {
            for (col = 1; col <= w; ++col) {
                printf("#");
            }
            
            printf("\n");
        }
        
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 572
#include <stdio.h>

int main()
{
    int w, n, a, b, t, s[30];

    scanf("%d %d", &w, &n);
    for (int i = 0; i < w; i++)
        s[i] = i + 1;

    for (int i = 0; i < n; i++)
    {
        scanf("%d,%d", &a, &b);
        t = s[a - 1];
        s[a - 1] = s[b - 1];
        s[b - 1] = t;
    }

    for (int i = 0; i < w; i++)
        printf("%d\n", s[i]);

    return 0;
}



Measured memory_bytes: 2584
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <string.h>
#include <bits/stdc++.h>
#include <math.h>

#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;


int main(){
    //std::ifstream in("resource/input.txt");
    //std::cin.rdbuf(in.rdbuf());

	double a[4];
	REP(i,4)
	{
		cin >> a[i];
	}

	double x = a[0] - a[2];
	double y = a[1] - a[3];

	double res;

	res = x*x + y*y;
	//平方根
	//sqrt(res)

	res = sqrt(res);

    cout << fixed << setprecision(5) << res << " ";
	//std::printf("%.5f¥n", res);
	
	return 0;
}




Measured memory_bytes: 3292
#C
n = int(input())
a = [int(i) for i in input().split()]

diameter = max(a)
mini     = min(a)

dic = dict()
for v in a:
    if v in dic:
        dic[v] += 1
    else:
        dic[v] = 1
#print(dic)
        
        
for i in range(diameter+1):
    v = max(i, diameter - i)
    #print(v)
    if (v not in dic) or dic[v]==0:
        print("Impossible")
        #print(v)
        break
    else:
        dic[v] -= 1
else:
    threshold = (diameter+1)//2 #girigiri out
    if threshold < mini: #somosomo tiisaike-su
        print("Impossible")
    elif dic[mini]>0:
        print("Impossible")
    else:
        print("Possible")
        
        
    

        


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

bool solve() {
    int n;
    std::cin >> n;
    if (n == 0) return false;

    std::vector<int> nxts(1 << 10, 0);
    {
        int b = 0;
        while (n--) {
            char c;
            std::cin >> c;
            if (c == 'u') {
                b = 0;
            } else {
                int d = c - '0';
                nxts[b] |= (1 << d);
                b |= (1 << d);
            }
        }
    }

    for (int a = 0; a < (1 << 10); ++a) {
        for (int b = 0; b < (1 << 10); ++b) {
            if (a & b) continue;
            if (nxts[a] & b) {
                nxts[a | b] |= nxts[b];
            }
        }
    }

    for (int b = 0; b < (1 << 10); ++b) {
        if (nxts[b] & b) {
            std::cout << "UNSAFE" << std::endl;
            return true;
        }
    }

    std::cout << "SAFE" << std::endl;
    return true;
}

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

    while (solve()) {}

    return 0;
}



Measured memory_bytes: 3160
#include<cstdio>
int main(){
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if (x+r>W||x-r<0||y+r>H||y-r<0){
		printf("No\n");
	}else {
		printf("Yes\n");
	}
}


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

int N, X, Y, ans[1 << 18], dist[1 << 18];
vector<int> G[1 << 12];

int main() {
	cin >> N >> X >> Y;
	G[X].push_back(Y);
	G[Y].push_back(X);
	for (int i = 1; i <= N - 1; i++) {
		G[i].push_back(i + 1);
		G[i + 1].push_back(i);
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) dist[j] = (1 << 30);
		dist[i] = 0; queue<int>Q; Q.push(i);
		while (!Q.empty()) {
			int pos = Q.front(); Q.pop();
			for (int j : G[pos]) {
				if (dist[j] != (1 << 30)) continue;
				dist[j] = dist[pos] + 1;
				Q.push(j);
			}
		}
		for (int j = i + 1; j <= N; j++) ans[dist[j]]++;
	}
	for (int i = 1; i <= N - 1; i++) cout << ans[i] << endl;
	return 0;
}

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

using namespace std;

const int INF = 1 << 30;

int W, H, S[1000][1000];
int ei1333[1000][1001];
int beet[1000][1001];
int dp[1001][1001];

int rec(int x, int y, bool which)
{
  if(x == W && y == H) return (0);
  if(~dp[x][y]) return (dp[x][y]);

  int ret = -INF;
  if(!which) {
    int get = 0;
    if(y + 1 <= H) {
      get += (ei1333[y][W] - ei1333[y][x]);
      ret = max(ret, get - rec(x, y + 1, 1));
      get = 0;
    }
    if(x + 1 <= W) {
      get -= (beet[x][H] - beet[x][y]);
      ret = max(ret, get - rec(x + 1, y, 1));
    }
  } else {
    int get = 0;
    if(y + 1 <= H) {
      get -= (ei1333[y][W] - ei1333[y][x]);
      ret = max(ret, get - rec(x, y + 1, 0));
    }
    if(x + 1 <= W) {
      get = 0;
      get += (beet[x][H] - beet[x][y]);
      ret = max(ret, get - rec(x + 1, y, 0));
    }
  }

  return (dp[x][y] = ret);
}

int main()
{
  scanf("%d %d", &W, &H);
  for(int i = 0; i < H; i++) {
    for(int j = 0; j < W; j++) scanf("%d", &S[i][j]);
  }

  for(int i = 0; i < H; i++) {
    ei1333[i][0] = 0;
    for(int j = 1; j <= W; j++) ei1333[i][j] += ei1333[i][j - 1] + S[i][j - 1];
  }
  for(int i = 0; i < W; i++) {
    beet[i][0] = 0;
    for(int j = 1; j <= H; j++) beet[i][j] += beet[i][j - 1] + S[j - 1][i];
  }

  memset(dp, -1, sizeof(dp));
  cout << abs(rec(0, 0, 0)) << endl;
}

Measured memory_bytes: 18872
#include <stdio.h>

void Draw(int h,int w){
	int i,j;
	for(i = 0;i < h;i++){
		if(i == 0 || i == h - 1){
			for(j = 0;j < w;j++){
				printf("#");
			}
		}else{
			for(j = 0;j < w;j++){
				if(j == 0 || j == w - 1){
					printf("#");
				}else{
					printf(".");
				}
			}
		}
		printf("\n");
	}

	printf("\n");

	return;
}

int main(void){
	int H,W;

	while(1){
		scanf("%d %d", &H, &W);

		if(H == 0 && W == 0){
			break;
		}else if(H <= 300 && W <= 300){
			Draw( H, W);
		}
	}

	return 0;
}

Measured memory_bytes: 572
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>

#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;

signed main()
{
	char S[100];
	cin >> S;
	int len = strlen(S);
	S[len - 8] = '\0';
	cout << S << endl;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int A[202020];
int B[202020];
int T[202020],F[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		B[A[i]]=i+1;
	}
	
	T[N]=0;
	F[N]=N;
	for(i=N-1;i>=1;i--) {
		if(T[i+1]==0) {
			if(B[i]<B[i+1]) {
				T[i]=0;
				F[i]=i;
			}
			else {
				T[i]=1;
				F[i]=i+1;
			}
		}
		else {
			if((B[F[i+1]]<B[i] && B[i]<B[i+1]) || (B[i]<B[i+1] &&  B[i+1]<B[F[i+1]]) || (B[i+1]<B[F[i+1]] && B[F[i+1]]<B[i])) {
				T[i]=T[i+1];
				F[i]=F[i+1];
			}
			else {
				T[i]=T[i+1]+1;
				F[i]=i+1;
			}
		}
	}
	cout<<T[1]<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	ll arr[n + 1] = {0};
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; i * j <= n; j++)
			arr[i * j]++;
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++)
	{
		ll ans1 = i * arr[i];
		ans += ans1;
	}
	cout << ans;
	return 0;

}


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

typedef pair<int, int> pii;

int H, W;
vector<vector<char> > G;
vector<vector<int> > Gp, dp;
stack<int> st;

int solve() {
    int ret = 0;
    for(int i = 0; i < H; i++) {
        while(!st.empty()) st.pop();
        for(int j = 0; j <= W; j++) {
            while(!st.empty() && dp[i][ st.top() ] > (j == W? 0 : dp[i][j])) {
                int t = st.top(); st.pop();
                int d = st.empty()? -1 : st.top();
                ret = max(ret, (j - d) * (dp[i][t] + 1));
            }
            st.push(j);
        }
    }
    return ret;
}

int main() {
    scanf("%d %d", &H, &W);
    G = vector<vector<char> >(H, vector<char>(W));
    for(int i = 0; i < H; i++) {
        scanf("\n");
        for(int j = 0; j < W; j++) {
            scanf("%c", &G[i][j]);
        }
    }
    H--;
    W--;
    Gp = vector<vector<int> >(H, vector<int>(W));
    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            Gp[i][j] = ((G[i][j] != G[i][j + 1]) != (G[i + 1][j] != G[i + 1][j + 1]));
        }
    }

    dp = vector<vector<int> >(H, vector<int>(W));
    for(int i = H - 1; i >= 0; i--) {
        for(int j = 0; j < W; j++) {
            if(i != H - 1 && Gp[i][j] == 0) dp[i][j] = 1 + dp[i + 1][j];
            else dp[i][j] = (Gp[i][j] == 0);
        }
    }

    cout << max(max(H + 1, W + 1), solve());
}


Measured memory_bytes: 35584
#include <stdio.h>
#include <stdlib.h>

int main(void) {
    char str[3][512];
    char *p[3];
    int i,next;
    
    for(i=0;i<3;i++){
        p[i] = fgets(str[i], 512, stdin);
    }
    

    i = 0;
    while(((*(p[i]) >= 'a') && (*(p[i]) <= 'c'))) {
        p[i]++;
        i = p[i][-1] - 'a';
    }
    printf("%c\n", 'A'+i);

    return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define MAX 10000

int prime(int) ;

int main(){
  int n,i,a=0,A[MAX];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    a += prime(A[i]);
  }
  printf("%d\n",a);
  return 0;
}

int prime(int n){
  int i;
  if(n==2)return 1;
  for(i=2;i*i<=n;i++){
    if(n%i==0)return 0;
  }
  return 1;
}



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

int main() {
  string S;
  cin >> S;

  int sum = 700;
  if(S[0] == 'o') sum += 100;
  if(S[1] == 'o') sum += 100;
  if(S[2] == 'o') sum += 100;

  cout << sum << endl;
  }

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

int main(){
	int r,c,i,j;
	cin >> r >> c;
	int a[r+1][c+1];
	for(i=0;i<r+1;i++){
		for(j=0;j<c+1;j++){
			a[i][j]=0;
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			cin >> a[i][j];
		}
	}
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			a[i][c]+=a[i][j];
		}
	}
	for(i=0;i<c;i++){
		for(j=0;j<r;j++){
			a[r][i]+=a[j][i];
		}
	}
	for(i=0;i<r;i++){
			a[r][c]+=a[i][c];
	}
	
	for(i=0;i<r+1;i++){
		for(j=0;j<c+1;j++){
			cout << a[i][j] ;
			if(j!=c) cout <<" ";
		}
		cout << endl;
	}
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ll long long int
#define fi first
#define se second
#define opti ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const ll N = 1e5+6;
ll t,i,j,k,n,m,q;

int main()
{
    opti
    bool prime[N];
    memset(prime, true, sizeof(prime));
 
    for (ll p=2; p*p<N; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*2; i<N; i += p)
                prime[i] = false;
        }
    }
    prime[0] = false;
    prime[1] = false;
    ll ans[N];
    memset(ans,0,sizeof(ans));
    for(i=1;i<N;i++)
    {
        if(i%2)
        {
            if(prime[i]&&prime[(i+1)/2])
            {
                ans[i]=1;
            }
        }
    }
    for(i=2;i<N;i++)
    {
        ans[i] = ans[i] + ans[i-1];
    }
    cin>>q;
    while(q--)
    {
        ll left,right;
        cin>>left>>right;
        cout<<ans[right] - ans[left-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long x = in.nextLong(), y = in.nextLong();

            int cnt = 0;
            long cur = x;
            while (cur <= y) {
                ++cnt;
                cur <<= 1;
            }

            out.println(cnt);
        }

    }
}



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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;

int main() {
  ll x;
  scanf("%lld", &x);

  ll ans = 0;
  ll n1 = x / 500;

  ans += n1 * 1000;

  x -= n1 * 500;

  ll n2 = x / 5;

  ans += n2 * 5;

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
using namespace std;
int setmax(int num, int len,int m) {
	int tmp;
	tmp = (num < len ? num : len);
	return (m > tmp ? m : tmp);
}
int main()
{
	string s;
	int n;
	cin >>n>>s;
	int len,left,m=0;
	for (len = 1; len <n; len++) {
		int num = 0;
		for (left = 0; left <= n - len; left++) {
			if (left == n - len|| s[left] != s[left + len]) {
				m = setmax(num, len, m);
				num = 0;
			}
			else
				num++;
		}
	}
	cout << m;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int a,b; cin >> a >> b;
  int ans = 0;
  if (a>=13) ans = b;
  else if(a>=6) ans = b/2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::{self, BufRead};

fn main() {
  let stdin = io::stdin();
  let mut lines = stdin.lock().lines();
  let n: usize = lines.next().unwrap().unwrap().parse().unwrap();
  let mut honest: Vec<Vec<usize>> = vec![Vec::new(); n];
  let mut dishonest: Vec<Vec<usize>> = vec![Vec::new(); n];
  for i in 0..n {
    let a: usize = lines.next().unwrap().unwrap().parse().unwrap();
    for _ in 0..a {
      let xs: Vec<usize> = lines.next().unwrap().unwrap().split(' ').map(|x| x.parse().unwrap()).collect();
      let (x, y) = (xs[0] - 1, xs[1]);
      if y == 0 {
        dishonest[i].push(x);
      } else {
        honest[i].push(x);
      }
    }
  }
  let mut ans = 0;
  for i in 0..((2 as u32).pow(n as u32)) {
    let mut ok = true;
    for j in 0..n {
      if i & (1 << j) != 0 {
        let p1 = honest[j].iter().all(|h| i & (1 << *h) != 0);
        let p2 = dishonest[j].iter().all(|d| i & (1 << *d) == 0);
        if !p1 || !p2 {
          ok = false;
          break;
        }
      }
    }
    if ok {
      let temp = (0..n).filter(|k| i & (1 << *k) != 0).count();
      if ans < temp {
        ans = temp;
      }
    }
  }
  println!("{}", ans);
}

Measured memory_bytes: 4352
import java.util.*;

public class Main{
	public static void main( String[] args ){
		
		//Make a instance of Scanner
		Scanner scan = new Scanner(System.in);
		
		//size of matrix
		int size = 3;
		int matrix[][] = new int[size][size];
		
		// input each values in the matrix
		for(int i = 0; i < matrix.length ; i++){
			for(int j = 0 ; j < matrix[i].length ; j++ ){
				matrix[i][j] = scan.nextInt();
			}
		}
		
		// input numbers to be inspected
		int n = scan.nextInt();
		int num[] = new int[n];
		for(int i = 0; i< num.length ; i++){
			num[i] = scan.nextInt();
		}
		
		// second matrix to show if each elements in matrix[][] matchs any elements in num[]
		boolean isCoincide[][] = new boolean[size][size];
		
		// initialize all isCoincide[][] elements with 'true'
		for(int i = 0 ; i< matrix.length ; i++){
			for(int j = 0 ; j < matrix[i].length ; j++){
				for(int k = 0 ; k < num.length ; k++){
					if(matrix[i][j] == num[k]){
						isCoincide[i][j] = true;
					}
				}
			}
		}
		
		
		// isBingo[0] shows if each row is judged as bingo
		// isBingo[1] shows if each line is judged as bingo
		// isBingo[2][0] shows diagonal line (top-left to bottom-right) is judged as bingo
		// isBingo[2][1] shows diagonal line (top-right to bottom-left) is judged as bingo
		boolean isBingo[][] = new boolean[3][];
		
		// set elements by initializing isBingo[][]
		isBingo[0] = new boolean[] {true,true,true};
		isBingo[1] = new boolean[] {true,true,true};
		isBingo[2] = new boolean[] {true,true};
		
		
		// inspect all elements in isCoincide[][] and judge bingo
		for(int i = 0 ; i < matrix.length ; i++){
			for(int j = 0 ; j < matrix[i].length ; j++){
				
				// for this 'if' statement, i means line , and j means row
				if(isCoincide[i][j] != true){
					isBingo[0][j] = false;
					isBingo[1][i] = false;
					if(i == j){
						isBingo[2][0] = false;
					}
					if(2-i == j){
						isBingo[2][1] = false;
					}
				}
			}
		}
		
		// boolean variable showing there is a bingo in matrix[][]
		boolean bingo = false;
		
		for(int i = 0 ; i < isBingo.length ; i++){
			for(int j = 0 ; j < isBingo[i].length ; j++){
				if(isBingo[i][j] == true){
					bingo = true;
				}
			}
		}
		
		if(bingo){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int maxn=100000+10;
struct node
{
	int to,next,w;
}edge[maxn];
int k=1,head[maxn],ind[maxn],n,m,dp[maxn];
void add(int u,int v,int w)
{
	edge[++k].to=v;edge[k].next=head[u];head[u]=k;edge[k].w=w;
}
void Topsort()
{
	queue<int>q;
	for(int i=1;i<=n;i++)
		if(!ind[i])
			q.push(i);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=head[x];i;i=edge[i].next)
		{
			dp[edge[i].to]=max(dp[edge[i].to],dp[x]+edge[i].w);
			ind[edge[i].to]--;
			if(!ind[edge[i].to])
				q.push(edge[i].to);
		}
	}
}
int  main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v;
		cin>>u>>v;
		add(u,v,1);
		ind[v]++;
	}
	Topsort();
	int ans=0;
	for(int i=1;i<=n;i++)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
	return 0;
}
//Phoenix-ZH

Measured memory_bytes: 6104
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a=0, b = 0,c,d, n, k;
string s, t;

int kaizyo (int x)
{
	if (x % 2 == 1)
		return 0;
	else
		return 1 + kaizyo(x / 2);
}

int main()
{
	cin >> a >> b;
	if (a < 9 && b < 9)
		cout << "Yay!" << endl;
	else
		cout << ":("<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100001];
int main()
{
	int n,k,i,j,min_1=INT_MAX;
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=1;i<=n-k+1;i++)
	{
		min_1=min(a[i+k-1]-a[i],min_1);
		//printf("%d %d %d %d\n",i+k,a[i+k],i,a[i]);
	}
	printf("%d",min_1);
	return 0;	
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int main(){
  int res=1;
  rd(N);
  while(2*res <= N){
    res *= 2;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N;
// {
//   int res = 1;
//   rd(N);
//   while(2res <= N) res *= 2;
//   wt(res);
// }


Measured memory_bytes: 256