akhauriyash/Code-Regression huggingface dataset:
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
 
signed main() {
string ans = "No";
int N;
cin >>N;
REP(i,3){
if(N%10 == 7){
    ans = "Yes";
    answer(ans);
    return 0;
}
N = (N-(N%10))/10;
}
answer(ans);

}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

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

    ll ans = 0;
    int now = x[0];

    for(int i = 1; i < n; i++){
        ll cost = (x[i]-now)*a;
        now = x[i];
        if(cost > b) ans += b;
        else ans += cost;
    }

    cout << ans << endl;


    return 0;
}

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

int main() {
	int n;  cin >> n;
	vector<ll> x(n), y(n), h(n); rep(i, 0, n) cin >> x[i] >> y[i] >> h[i];

	rep(X, 0, 101) {
		ll H = 0;
		rep(Y, 0, 101) {
			rep(i, 0, n) {
				if (h[i] != 0) {
					H = h[i] + abs(X - x[i]) + abs(Y - y[i]);
					break;
				}
			}
			bool f = true;
			rep(i, 0, n) {
				ll hi = H - abs(X - x[i]) - abs(Y - y[i]);
				hi = max(hi, 0LL);
				if (h[i] != hi) {
					f = false;
					break;
				}
			}
			if (f) {
				cout << X << " " << Y << " " << H << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
struct hoge{int from,to,sa;};
signed main(){
    int n,t;cin >> n >> t;
    int a[n];
    rep(i,n)cin >> a[i];
    int mini = a[0];
    int mx = 0;
    

    for(int i = 1;i < n ;i++){
        mx = max(mx,a[i] - mini);

        mini = min(mini,a[i]);
    
    }
    mini = a[0];
    int ans = 0;
    for(int i = 1;i < n ;i++){
        if(a[i] - mini == mx){
            ans++;
        }
        mini = min(mini,a[i]);
    }
    cout << ans << endl;

    
    

    
        

    
    

    


    


    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

int n, h[100005];
/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();

    cin >> n;
    int ans = 0;
    int cur = 0;
    REP (i, n) {
        cin >> h[i];
    }

    for (int i=n-2; i>=0; i--) {
        if (h[i] >= h[i+1]) {
            cur++;
        } else {
            cur = 0;
        }
        debug(cur);
        ans = max(ans, cur);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <iomanip>
#include <valarray>
#include <vector>


int main(int argc, char *argv[])
{
    int num;
    std::cin >> num;
    std::string input;
    std::valarray<double> values(0.0, num);

    for(int i = 0; i < num; ++i){
        int val;
        std::cin >> val;
        values[i] = val;
    }

    std::cout << std::fixed << std::setprecision(0) <<  values.min() << " " << values.max() << " " << values.sum() << std::endl;

    return 0;
}

Measured memory_bytes: 3292
require 'pp'

n = gets.chomp!
a_n = gets.chomp!.split(" ").map(&:to_i)
b_n = gets.chomp!.split(" ").map(&:to_i)
c_n = gets.chomp!.split(" ").map(&:to_i)

sum = 0
before = -1000
a_n.each do |a|
    sum += b_n[a-1]
    if before + 1 == a
        sum += c_n[before - 1]
    end

    before = a
end

puts sum


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

using namespace std;

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif

    int a, b, c; cin >> a >> b >> c;
    int ans = min(b/a, c);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
	char s[10];
  	char t[10];
  	char u[10];
  	int a=0;
  	int b=0;
  	
  	scanf("%s%s",s,t);
  	scanf("%d%d",&a,&b);
  	scanf("%s",u);
  
  	if( strcmp(s,u)==0 ){
    	a-=1;
    }else{
    	b-=1;
    }
  	
  	printf("%d %d\n",a,b);
  	
  	return 0;
}

Measured memory_bytes: 128
H, W = [int(item) for item in input().split()]

l = []
for i in range(H):
  line = input()
  if "#" in line: 
    l.append(line)
  else:
    H -= 1

to_be_deleted = []
for i in range(W):
  white = True
  for line in l:
    if line[i] == "#":
      white = False
      break
  if white:
    to_be_deleted.append(i)
    
for i in to_be_deleted[::-1]:
  for j in range(H):
    if i < W-1:
      l[j] = l[j][:i] + l[j][i+1:]
    else:
      l[j] = l[j][:i]
      
for item in l:
  print(item)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#define SIZE 300005

using namespace std;
typedef long long int ll;

int sz[SIZE];

int main()
{
	int n,a,b;
	scanf("%d %d %d",&n,&a,&b);
	if((ll) a*(ll) b<(ll) n||a+b>n+1)
	{
		puts("-1");
	}
	else
	{
		int zan=n;
		for(int i=0;i<a;i++)
		{
			sz[i]=1;
			zan--;
		}
		for(int i=0;i<a;i++)
		{
			sz[i]+=zan;
			zan=max(0,sz[i]-b);
			sz[i]=min(sz[i],b);
		}
		int start=0;
		for(int i=0;i<a;i++)
		{
			for(int j=sz[i]-1;j>=0;j--) printf("%d ",start+j+1);
			start+=sz[i];
		}
		puts("");
	}
	return 0;
}


Measured memory_bytes: 2944
/*  ***  In The Name of God ... ***  */ 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define int long long
#define all(v) v.begin() , v.end()
#define pb push_back
#define endl '\n' 
template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}


int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n , y ;
	cin >> n >> y ;
	for ( int i = 0 ; i <= n ; i++ ) {
		for ( int j = 0 ; j + i <= n ; j++ ) {
			int k = n - i - j ;
			if ( k < 0 )
				continue ;
			if ( i * 10000 + j * 5000 + k * 1000 == y )
				return cout << i << ' ' << j << ' ' << k << endl , 0 ; 
		}
	}
	cout << "-1 -1 -1 " << endl  ;
	return 0 ; 
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    char N[4];
    scanf("%s", N);

    int i = 0;
    for (i = 0; i < 3; i++) {
        if (N[i] == '7') {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}

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

int checkSquare( char *data, int x0, int y0, int n ){
	int d=1;
	while( (x0+d)<=n && (y0+d)<=n ){
		for( int y=y0; y<(y0+d); y++ ){
			for( int x=x0; x<(x0+d); x++ ){
				if( data[y*n+x] == '*' ){
					return d-1;
				}
			}
		}
		d++;
	}
	return d-1;
}

int main(){
	int n;
	char *data;
	string line;
	while(1){
		int max = 0;
		getline( cin, line );
		sscanf( line.c_str(), "%d", &n );
		if( n == 0 )	break;
		data = new char[n*n+1];
		for( int i=0; i<n; i++ ){
			getline( cin, line );
			for( int j=0; j<n; j++ ){
				data[i*n+j] = line[j];
			}
		}
		for( int y=0; y<n; y++ ){
			for( int x=0; x<n; x++ ){
				if( data[y*n+x] == '.' ){
					int l = checkSquare(data,x,y,n);
					max = (max<l) ? l : max;
				}
			}
		}
		cout << max << endl;
		delete[] data;
		data = 0;
	}
	return 0;
}

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

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

	int n, a, b, c;
	cin >> n >> a >> b >> c;

	vector<int> topping(n);
	for(int i = 0; i < n; ++i) {
		cin >> topping[i];
	}

	int price = a;
	int cal = c;
	sort(topping.rbegin(), topping.rend());

	for(int i = 0; i < n; ++i) {
		if(cal * b < topping[i] * price) {
			price += b;
			cal += topping[i];
		}
	}

	cout << cal / price << endl;

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1200
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	int num = 0;

	string s, c = "CODEFESTIVAL2016";

	cin >> s;

	for (int k = 0; k < 16; k++) {
		if (s.at(k) != c.at(k)) {
			num++;
		}
	}

	cout << num << "\n";
	

	return 0;
}

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

using namespace std;

const int maxn = 2e5 + 5;

vector <int> g[maxn];
bool vis[maxn];

void dfs(int u , int &t) {
	vis[u] = 1;
	t++;
	for(int i = 0 ; i < g[u].size() ; i++) {
		int v = g[u][i];
		if(!vis[v]) {
			dfs(v , t);
		}
	}
}

int main() {
	int n , m;
	ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++) {
		int u , v;
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u); 
	}
	int ans = 0;
	for(int i = 1 ; i <= n ; i++) {
		int cnt = 0;
		if(!vis[i]) {
			dfs(i , cnt);
			ans = max(cnt , ans);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 24080
#include<algorithm>
#include<iostream>
#include<math.h>
#include<queue>
#include<stdio.h>
#include<stdlib.h>
#include<stack>
#include<string>
#include<vector>

#define ll long long
#define ull unsigned long long

using namespace std;
int main(void) {
	ll A = 0,B = 0;

	scanf("%lld%lld", &A, &B);

	printf("%lld\n", max(max(A + B, A - B), A * B));

	return 0;
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int M; cin >> M;
    ll ans = 0;
    vector<ll> digits;
    rep(i, M){
        ll d, c; cin >> d >> c;
        ll m;
        m = (d*c-1) / 9; 
        ans += c-1+m;
        digits.push_back(d*c-9*m);
    }

    
    rep(i, digits.size()-1){
        ll val = digits[i] + digits[i+1];
        if(val >= 10){
            digits[i] = 1;
            digits[i+1] = val % 10;
            i--;
        }
        else digits[i+1] = val;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista

def zrob_listy_sadziedztwa(lista): 
    listy_sasiedzitwa = {}
    for x, y in lista: 
        listy_sasiedzitwa[x] = []
        listy_sasiedzitwa[y] = []
    for x, y in lista: 
        listy_sasiedzitwa[y].append(x)
    return listy_sasiedzitwa

def wyjscie_do_szkoly_bfs(lista_zasad): 
    zasady = {}
    ile_niespelnionych = {}
    for rzecz1,rzecz2 in lista_zasad: 
        zasady[rzecz1] = [] 
        zasady[rzecz2] = []
        ile_niespelnionych[rzecz1] = 0 
        ile_niespelnionych[rzecz2] = 0
    for rzecz1, rzecz2 in lista_zasad: 
        zasady[rzecz1].append(rzecz2)
        ile_niespelnionych[rzecz2] += 1
    kolejnosc_ubioru = [rzecz for rzecz in zasady if ile_niespelnionych[rzecz] == 0]
    nr_przegladnanego = 0
    while nr_przegladnanego < len(kolejnosc_ubioru): 
        for ubranie in zasady[kolejnosc_ubioru[nr_przegladnanego]]: 
            ile_niespelnionych[ubranie] -= 1
            if ile_niespelnionych [ubranie] == 0:
                kolejnosc_ubioru.append(ubranie)
        nr_przegladnanego += 1
    if len(kolejnosc_ubioru) != len(zasady): 
        raise Exception('Nie można się ubrać Skurwysynu')
    return kolejnosc_ubioru 

def longest_patch(): 
    N, M = wczytaj_liste()
    lista_krawedzi = []
    for i in range(M): 
        x, y = wczytaj_liste()
        lista_krawedzi.append((x,y))
    listy_krawedzi = zrob_listy_sadziedztwa(lista_krawedzi)
    kolejnosc = wyjscie_do_szkoly_bfs(lista_krawedzi)
    najdluzsze_drogi = {}
    for wierzcholek in kolejnosc: 
        if len(listy_krawedzi[wierzcholek]) == 0: 
            najdluzsze_drogi[wierzcholek] = 0
        else: 
            maksimum = 0 
            for x in listy_krawedzi[wierzcholek]: 
                if najdluzsze_drogi[x]> maksimum:
                      maksimum = najdluzsze_drogi[x]
            najdluzsze_drogi[wierzcholek] = maksimum + 1
    najdluzsza = 0 
    for a_chuj_wie_co in najdluzsze_drogi: 
        if najdluzsze_drogi[a_chuj_wie_co] > najdluzsza:
            najdluzsza = najdluzsze_drogi[a_chuj_wie_co]
    print (najdluzsza)

longest_patch()  

Measured memory_bytes: 112212
H, W = map(int, input().split())
S = [input() for _ in range(H)]

A = [''] * H

di = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            A[h] += '#'
        else:
            c = 0
            for d in di:
                h1 = h + d[0]
                w1 = w + d[1]
                if 0 <= h1 < H and 0 <= w1 < W:
                    if S[h1][w1] == '#':
                        c += 1
            A[h] += str(c)

for i in range(H):
    print(A[i])



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


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

    int K;
    cin >> K;

    if (K % 2 == 0 or K % 5 == 0) {
        cout << -1 << endl;
    }
    else {
        int L = 0;
        if (K % 7 == 0) {
            L = 9 * K / 7;
        }
        else {
            L = 9 * K;
        }
        int s = 10;
        for (int i = 1; i <= L; i++) {
            if (s % L == 1) {
                cout << i << endl;
                break;
            }
            s = (s % L) * 10;
        }
    }
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int cnt1,cnt2;
string a;
int main()
{
    cin>>a;
    for(int i=0;i<a.length();i++)
    {
        if(a[i]=='0')cnt1++;
        else cnt2++;
    }
    cout<<min(cnt1,cnt2)*2;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};


int main()
{
    long long N;
    cin >> N;
    unsigned long long count = 0;
    if(N % 2 == 0)
    {
        for(int i = 1;pow(5,i) * 2<= N;i++)
        {
            count += (long long)(N / ((long long)pow(5,i) * 2));
        }
    }
    cout << count << '\n'; 
}


Measured memory_bytes: 256
a,b,c = sorted(map(int,input().split()))
count = 0
count += (c-a) // 2
count += (c-b) // 2
ca = (c-a) % 2
cb = (c-b) % 2
if ca and cb:
  count += 1
elif ca or cb:
  count += 2
print(count)

Measured memory_bytes: 3060
import numpy as np

n, k = map(int, input().split())
e = 0
for i in range(1, n + 1):
    if i < k:
        if (np.log2(k) - np.log2(i)) == int(np.log2(k) - np.log2(i)):
            sh = int(np.log2(k) - np.log2(i))  # 何回コインを投げるか
        else:
            sh = int(np.log2(k) - np.log2(i) + 1)
        e += (1 / n) * 0.5 ** sh
    else:
        e += (1 / n)
print(e)

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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int count = 0;
			// a == b
			if (Integer.parseInt(line) % 2 == 0) {
				count++;
			}
			// a != b
			for (int j = 1; j < line.length(); j++) {
				if (line.charAt(j) != '0') {
					int l = Integer.parseInt(line.substring(0, j));
					int r = Integer.parseInt(line.substring(j));
					if (l <= r && (r - l) % 2 == 0) {
						count++;
					}
				}
			}
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 17060
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  string s;
  cin>>s;
  ll k;
  cin>>k;
  int n=s.size();
  char old = '$';
  int last = -1;
  vecint nums;
  for(auto&& i:irange(0,n)) {
    if (s[i] != old) {
      if (last >= 0) nums.push_back(i-last);
      old = s[i];
      last = i;
    }
  }
  if (!nums.empty()) {
    nums.push_back(n-last);
    if (s.front() == s.back()) {
      ll sum = 0;
      int p = nums.size();
      for(auto&& i:irange(1,p-1)) sum += nums[i]/2;
      ll ans = sum * k + nums.front()/2 + nums.back()/2 + (nums.front() + nums.back())/2 * (k-1);
      cout<<ans<<endl;
    } else {
      ll sum = 0;
      for(auto&& e:nums) sum += e/2;
      cout<<sum*k<<endl;
    }
  } else {
    ll total = n*k;
    cout<<total/2<<endl;
  }
  return 0;
}


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

int main() 
{
    int n;
    while (scanf("%d", &n)&&n!=0) {
        long long int a[n];
        for (int i=0; i<n; i++) scanf("%lld", &a[i]);
        long long int dp[n];
        dp[0] = a[0];
        long long int res = dp[0];
        for (int i=1; i<n; i++) {
            dp[i] = max(a[i], dp[i-1]+a[i]);
            res = max(res, dp[i]);
        }
        printf("%lld\n", res);
    }
}

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

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

using namespace std;
using ll = long long;
using P = pair<int,int>;



int main(){
	
	int N, X, T;
	
	cin >> N >> X >> T;
	
	if( N % X == 0 ){
		cout << (T * (N / X));
	}
	else{
		cout << (T * (N / X + 1));
	}
	
	return 0;
	
}


Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner std = new Scanner(System.in);
        String s = std.next();
        String[] cubes = s.split("");
        int redCube = 0;
        int blueCube = 0;
        for (int i = 0; i < cubes.length; i++) {
            if (cubes[i].equals("0")) {
                redCube++;
            } else {
                blueCube++;
            }
        }

        System.out.println(Math.min(redCube, blueCube) * 2);
    }
}


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

int main(){
    long long a,b,c,x,y,z,counter=0;
    cin>>a>>b>>c;
    if(a==b && b==c && !(a%2))cout<<-1,exit(0);
    while(!(a%2) && !(b%2) && !(c%2)){
        x=y=z=0;
        x=b/2 + c/2;
        y=a/2 + c/2;
        z=a/2 + b/2;
        a=x;
        b=y;
        c=z;
        counter++;
    }
    cout<<counter<<endl;
return 0;
}


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

int main(){

	int set;

	cin >> set;

	int num[set][3];

	for(int i=0;i<set;i++){
		cin >> num[i][0] >> num[i][1] >> num[i][2];
	}

	for(int i=0;i<set;i++){
		int a=num[i][0]*num[i][0];
		int b=num[i][1]*num[i][1];
		int c=num[i][2]*num[i][2];
		if(a+b==c||b+c==a||c+a==b) cout << "YES\n";
		else cout << "NO\n";
	}

    return 0;
}


Measured memory_bytes: 2964
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>

using namespace std;

int H,W,K;

int test(int key, int* org);

int main(){
    cin >> H >> W >> K;
    int org[H][W];
    for(int r=0;r<H;r++){
        for(int c=0;c<W;c++){
            char tmp;
            cin >> tmp;
            if(tmp == '.'){org[r][c]=0;}else{org[r][c]=1;}
        }
    }

    int ans=0;
    for(int k=0;k<pow(2,H+W);k++){
        if(test(k, &org[0][0]) == K)
            ans++;
    }
    cout << ans;
    return 0;
}

int test(int key, int* org){
    int tst[H][W];
    for(int r=0;r<H;r++){
        for(int c=0;c<W;c++){
            tst[r][c] = org[r*W+c];
        }
    }

    for(int rn=0;rn<H;rn++){
        if(((key >> rn) & 0x01) == 1){
            for(int c=0;c<W;c++)
                tst[rn][c]=0;
        }
    }
    for(int cn=0;cn<W;cn++){
        if(((key >> (H+cn)) & 0x01) == 1){
            for(int r=0;r<H;r++)
                tst[r][cn]=0;
        }
    }
    int sum=0;
    for(int r=0;r<H;r++){
        for(int c=0;c<W;c++){
            sum += tst[r][c];
        }
    }
    return sum;
}

Measured memory_bytes: 4032
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int mas[100005];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    ll sum = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int a, b;
        cin >> a >> b;
        mas[i] = a + b;
        sum -= (ll) b;
    }
    sort(mas + 1, mas + n + 1);
    for (int i = n; i > 0; i -= 2) sum += (ll) mas[i];
    cout << sum;
    return 0;
}



Measured memory_bytes: 640
import sys

n,k=map(int,input().split())

if k==0:
    print(n*n)
    sys.exit()
    
icnt=0
for ki in range(k+1,n+1):
    qki=n//ki
    icnt+=qki*(ki-k)+max(n%ki-(k-1),0)

print(icnt)    
    

Measured memory_bytes: 9120
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner a= new Scanner(System.in);
    int j = a.nextInt();
    long ans = 0;
    for(int i = 1; i <= j; i++){
      if(i%3==0 || i%5 == 0)
        continue;
      else
        ans+=i;
    }
    System.out.println(ans);
  }
}

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

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int x, y;
    cin >> x >> y;
    if ((x+y)%3) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x+y)/3;
    x -= n; y -= n;
    if (x < 0 || y < 0) {
        cout << 0 << endl;
        return 0;
    }
    combination c(x+y);
    mint ans = c(x+y,x);
    cout << ans.x << endl;
    return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define sz(x) (int)(x).size()
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

struct int_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

struct pair_hash {
    size_t operator()(pii x) const {
        return int_hash{}(x.first) ^ (int_hash{}(x.second) << 16);
    }
};

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<cd> vcd;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pii>> vvpii;
typedef vector<vector<pll>> vvpll;
typedef unordered_map<int, int, int_hash> umpii;
typedef unordered_map<ll, ll, int_hash> umpll;
typedef unordered_set<int, int_hash> usi;
typedef unordered_set<ll, int_hash> usll;
typedef unordered_set<pii, pair_hash> uspii;
typedef queue<int> qi;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = numeric_limits<int>::max();
const int MX = 100001; //check the limits, dummy

bool check(vector<int> &a, int pos, ll m, int p, int v) {
    if(a[pos] + m < a[p - 1]) return false;
    ll can = 0, n = a.size();
    for(int i = p - 1; i < pos; i++) {
        can += a[pos] + m - a[i];
    }
    can += (p - 1 + n - pos) * m;
    return can >= m * v;
}

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

    int n, m, v, p;
    cin >> n >> m >> v >> p;

    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(rbegin(a), rend(a));

    int lo = p, hi = n - 1;
    if(!check(a, lo, m, p, v)) {
        cout << p << endl;
    }
    else if(check(a, hi, m, p, v)) {
        cout << n << endl;
    }
    else {
        while(hi - lo > 1) {
            int mid = (hi - lo) / 2 + lo;
            if(check(a, mid, m, p, v)) lo = mid;
            else hi = mid;
        }
        cout << lo + 1 << endl;
    }
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
#define ll          long long int
#define ld          long double
#define pb          push_back
#define mp          make_pair
#define ff          first
#define se          second
#define endl        '\n'
#define fd(n)       fixed<<setprecision(n)
#define MAX         100000000000000000
#define MAXN        1000050
#define mod         1000000007  
#define pi          3.1415926535897932384626433
 
ll fun(ll x,ll y){
    ll ans=1;
    while(y>0){
        if(y%2==1){
            ans=ans*1ll*x;
            ans=ans%mod;
        }
        y=y/2;
        x=(x*1ll*x)%mod;
    }
    return ans;
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,flag=0,j,x;
    ll prime[MAXN],prime1[MAXN];
    memset(prime,0,sizeof(prime));
    memset(prime1,0,sizeof(prime1));
    for(i=2;i<MAXN;i++){
        if(prime[i]==0){
            for(j=i+i;j<MAXN;j+=i){
                prime[j]=1;
            }
        }
    }
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
        prime1[a[i]]++;
    }
    x=a[0];
    for(i=1;i<n;i++){
        x=__gcd(x,a[i]);
    }
    if(x>=2){
        cout<<"not coprime";
    }
    else{
        ll count=0;
        for(i=2;i<MAXN;i++){
            count=0;
            for(j=i;j<MAXN;j+=i){
                count+=prime1[j];
            } 
            if(count>1){
                flag=1;
            }
        }
        if(flag==0){
            cout<<"pairwise coprime";
        }
        else{
            cout<<"setwise coprime";
        }
    }
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++)
    {
        cin >> vec.at(i);
    }
    int ans = 0;
    int n = 1;
    for (int i = 0; i < N; i++)
    {
        if (vec.at(i) == n)
        {
            n++;
            continue;
        }
        else
        {
            ans++;
        }
    }

    if (ans == N)
    {
        ans = -1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


int main(int argc, char* argv[])
{
    int n;
    scanf("%d", &n);

    vector<int> a(n);
    int i,j;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a.begin(), a.end());

    ll sum=0;
    for(i=0; i<n; i++) {
        for(j=i+1; j<n; j++) {
            int tmp=a[i]+a[j];
            int k = lower_bound(a.begin(), a.end(), tmp)-a.begin();
            sum += k-(j+1);
        }
    }
    printf("%lld\n", sum);

    return 0;
}



Measured memory_bytes: 256
n,k = map(int,input().split())
w = [int(input()) for i in range(n)]

def binarySearch(left,right):
    mid = 0
    while right > left:
        mid = int(left + (right - left)//2)
        if check(mid,w,k):
            right = mid
        else:
            left = mid + 1
    return left

def check(p,w,k):
    k_tmp = 1
    w_tmp = 0
    for w_i in w:
        w_tmp += w_i
        if w_tmp > p:
            w_tmp = w_i
            k_tmp += 1
            if k_tmp > k:
                return False
    return True

print(binarySearch(max(w),sum(w)))

Measured memory_bytes: 11588
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string>
#include<string.h>

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

#define _CRT_SECURE_NO_WARNINGS
int N;
char s[8010];
vector<int> x,y;
bool dpx[8010][3000] = {};
bool dpy[8010][3000] = {};

int gx, gy;

int main() {
	scanf("%s",s);
	N = strlen(s);
	scanf("%d %d",&gx,&gy);
	int now = 0;
	for (; s[now] == 'F'; now++) {}	
	gx = abs(gx-now);
	gy = abs(gy);

	bool isX = true; int c = 0;
	while (1) {	
		if (s[now] == 'F') {
			c++;
		}
		else {
			if (isX) {
				if (c != 0) {
					x.push_back(c);
				}
				isX = false;
			}else {
				if (c!=0) {
					y.push_back(c);
				}
				isX = true;
			}
			if (s[now] == '\0') {
				break;
			}
			c = 0;
		}
		now++;
	}

	bool xFlag=false, yFlag=false;

	if (x.size()==0) {
		xFlag = (gx == 0);
	}
	else {
		dpx[x[0]][0] = true;
		for (int i = 1; i < x.size(); i++) {
			for (int j = 0; j <= N; j++) {
				if (j+x[i]<=N) {
					dpx[j][i] |= dpx[j + x[i]][i - 1];
				}
				if (j-x[i]>=0) {
					dpx[j][i] |= dpx[j - x[i]][i - 1];
				}
			}
		}
		xFlag = dpx[gx][x.size() - 1];
	}

	if (y.size() == 0) {
		yFlag = (gy == 0);
	}
	else {
		dpy[y[0]][0]= true;
		for (int i = 1; i < y.size(); i++) {
			for (int j = 0; j <= N; j++) {
				if (j + y[i] <= N) {
					dpy[j][i] |= dpy[j + y[i]][i - 1];
				}
				if (j - y[i] >= 0) {
					dpy[j][i] |= dpy[j - y[i]][i - 1];
				}
			}
		}
		yFlag = dpy[gy][y.size() - 1];
	}
	

	if(xFlag&&yFlag){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 47232
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
typedef pair<int,int> ii;
const double pi=3.141592653589793238462643383279;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,k;
	cin>>n>>k;
	int lol[n+1];
	memset(lol,0,sizeof lol);
	for(int i=0;i<k;i++)
	{
		int xx;
		cin>>xx;
		for(int j=0;j<xx;j++)
		{
			int yy;
			cin>>yy;
			lol[yy]++;
		}
	}
	int c=0;
	for(int i=1;i<=n;i++)
	{
		if(lol[i]==0)c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 3660
H,N = map(int,input().split())
MAXH = H+1
DP = [float("inf")]*MAXH
DP[0] = 0
a = [0]*N
b = [0]*N
for i in range(N):
  a[i],b[i] = map(int,input().split())
for i in range(MAXH):
  if DP[i] == float("inf"):
    continue    
  for j in range(N):
        DP[min(i+a[j],H)] = min(DP[min(i+a[j],H)],DP[i]+b[j])
print(DP[H])


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

int main() {
  int a, b, c;
  cin >> a >> b;
  if ((a + b) % 2 == 0) {
    c = (a + b) / 2;
  }
  else {
    c = (a + b) / 2 + 1;
  }
  cout << c << endl;
}


Measured memory_bytes: 256
import sys
s = input()
s = s[:len(s)-1]
while 1:
    if len(s) %2 == 1:
        s = s[:len(s)-1]
        continue

    if s[:len(s) // 2] == s[len(s) // 2:]:
        print(len(s))
        sys.exit()
    else:
        s = s[:len(s)-1]

Measured memory_bytes: 3060
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
ans=0
d=[]
if n>=m:
  print(0)
else:
  for i in range(1,m):
    y=x[i]-x[i-1]
    d.append(y)
  
  d.sort(reverse=True)
  for j in range(n-1):
    ans+=d[j]
    
  print(x[m-1]-x[0]-ans)    
    
  

Measured memory_bytes: 13968
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define int long long
set < ll> primes;
 
int n,m;

bool isvalid(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
int dx[]={0,0,1,-1,-1,1,1,-1};
int dy[]={1,-1,0,0,-1,1,-1,1};
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

 
 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    
   int n,k;
    cin>>n>>k;
    int a[n];
    int ans=0;
    
    int a1,a2;
    for(int i=0;i<k;i++){
        cin>>a[i];
        
        
    }
    int diff=0;
    
    int b;
    for(int i=0;i<k;i++){
        if(!i){
            b=a[k-1]-a[0];
            b=n-b;
            
            diff=max(diff,b);
        }
        b=a[i]-a[i-1];
        diff=max(diff,b);
    }

    ans=n-diff;
    cout<<ans;
    
  
}

Measured memory_bytes: 3840
#include<iostream>
#include<map>
#include<sstream>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

string compute(int n,bool &flag){
  string ret ="";
  while(n>0){
    if (n%2 == 1)ret+="1";
    else ret+="0";
    n/=2;
  }
  if (ret.size() > 8){
    flag=false;
    return "";
  }
  flag=true;
  while(ret.size() != 8)ret+="0";
  reverse(ret.begin(),ret.end());
  return ret;
}

void makeall(map<string,string> &M){
  const int aho[4]={5000,2500,1250,625};
  rep(i,(1<<4)){
    int val=0;
    rep(j,4){
      if ( (i&(1<<j)) != 0)val+=aho[j];
    }
    stringstream sin;
    sin<<val;
    string key;
    sin>>key;
    while(key.size() != 4)key="0"+key;
    string ret="";
    rep(j,4){
      if ( (i&(1<<j)) != 0)ret+="1";
      else ret+="0";
    }
    //    cout << key <<" " << ret << endl;
    M[key]=ret;
 }
}
/*
string compute2(int m,bool &flag){
  const int aho[4]={5000,2500,1250,625};
  rep(i,(1<<4)){
    //cout << i << endl;
    int val=0;
    rep(j,4){
      if ( (i&(1<<j)) != 0)val+=aho[j];
    }
    cout << val << endl;
    if (val == m){
      string ret="";
      rep(j,4){
	if ( (i&(1<<j)) != 0)ret+="1";
	else ret+="0";
      }
      flag=true;
      return ret;
    }
  }
  flag=false;
  return "";
}
*/

main(){
  int n,m;
  char dummy;
  string in;
  map<string,string> M;
  makeall(M);
  while(getline(cin,in)){
    if (in.size() == 0)continue;
  bool isper=false;
    int m=0;
    int cnt=0;
    string ahoge="";
    rep(i,in.size()){
      if (in[i] == '.'){
	isper=true;
	in[i]=' ';
      }else if (isper){
	ahoge+=in[i];
      }
    }
    while(ahoge.size() != 4)ahoge+="0";
    
    stringstream sin(in);
    sin>>n;
    if (n < 0)break;


    
    bool flag;
    string a=compute(n,flag);
    if (!flag){
      cout << "NA" << endl;
      continue;
    }
    //    cout << ahoge << endl;
    if (M.find(ahoge) != M.end())cout << a << "." << M[ahoge] << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	char buf[5] = {};
	cin >> buf[0] >> buf[1] >> buf[2] >> buf[3];
	sort(buf, buf + 4);
	dbg(buf);
	cout << (strcmp("1479", buf) ? "NO" : "YES") << endl;
	
	return 0;
}

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

int n,A[20],q;
bool solve(int i,int m){
    if(i>=n&&m>0)return false;
    if(A[i]==m)return true;
    if(m>A[i]&&solve(i+1,m-A[i]))return true;
    return solve(i+1,m);
}


int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin >> A[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        int m;
        cin>>m;
        if(solve(0,m))cout<<"yes";
        else cout<<"no";
        cout <<endl;
    }
    return 0;
    
}


Measured memory_bytes: 3100
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

const MOD: u64 = 998244353;
fn main() {
    input! {
        n: usize,
        d: [usize; n],
    }
    if d[0] != 0 {
        return println!("0")
    }
    let mut counts:Vec<u64> = vec![0; n+1];
    for i in 0..n {
        counts[d[i]] += 1;
    }
    if counts[0] != 1 {
        return println!("0")
    }

    let mut res = 1u64;
    for i in 1..n+1 {
        for j in 0..counts[i] as usize {
            res *= counts[i-1];
            res %= MOD;
        }
    }
    println!("{}", res%MOD)
}



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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    int h, w;
    cin >> h >> w;
    int c[10][10];
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
        }
    }
    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    int ans = 0;
    rep(i, h){
        rep(j, w){
            int a;
            cin >> a;
            if(a >= 0){
                ans += c[a][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>


int main(void){
    int a,b,c,d;
    std::cin >> a >> b >> c >> d;
    while(a > 0 && c > 0){
        c -= b;
        if(c <= 0){
            std::cout << "Yes" << std::endl; 
            return 0;
        }
        a -= d;
        if(a <= 0){
            std::cout << "No" << std::endl; 
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3628