akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#define f first
#define s second
#define mp make_pair
#define mt make_tuple

int n, m, s;
pair<int,int> graph[55][55];
int C[55];
int D[55];
int dist[55][5555];
void solve()
{
    cin>>n>>m>>s;
    memset(graph, 0x3F, sizeof graph);
    memset(dist, 0x3F, sizeof dist);
    forn(_, m)
    {
        int x, y, a, b; cin>>x>>y>>a>>b;
        --x,--y;
        graph[x][y] = mp(a, b);
        graph[y][x] = mp(a, b);
    }
    forn(i, n)
    {
        cin>>C[i]>>D[i];
    }
    s = min(s, 5000LL);
    dist[0][s] = 0;
    priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>> >pq;
    pq.push(mt(0,0,s));
    while(sz(pq))
    {
        int tm, nw, sv; tie(tm, nw, sv) = pq.top(); pq.pop();
        if (dist[nw][sv] != tm) continue;
        for (int nxt = 0; nxt<50;++nxt)
        {
            if (graph[nw][nxt].first > sv) continue;
            int nt = tm + graph[nw][nxt].second;
            if (nt < dist[nxt][sv - graph[nw][nxt].first])
            {
                dist[nxt][sv - graph[nw][nxt].first] = nt;
                pq.push(mt(dist[nxt][sv - graph[nw][nxt].first], nxt, sv - graph[nw][nxt].first));
            }
        }
        int nt = tm + D[nw];
        int ns = min(5000LL, sv + C[nw]);
        if (dist[nw][ns] > nt)
        {
            dist[nw][ns] = nt;
            pq.push(mt(dist[nw][ns], nw, ns));
        }
    }
    for(int i=1;i<n;++i)
    {
        int ans = 1e18;
        for(int j = 0; j <=5000;++j)
        {
            ans = min(ans, dist[i][j]);
        }
        cout << ans << '\n';
    }

}


signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 11916
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define SIZE 200001
int N;
ll K;
void func()
{
    cin >> N >> K;
    int town[SIZE], point(1);
    ll count(0);
    rep(i, 0, N) cin >> town[i + 1];
    vector<int> ans(1, 1);
    bool v[SIZE] = {};
    while (v[point] == false && count++ < K)
    {
        v[point] = true;
        point = town[point];
        ans.push_back(point);
    }
    if (count < K)
    {
        ans.push_back(town[point]);
        rep(i, 0, ans.size() - 1)
        {
            if (ans[i] == ans[ans.size() - 1])
            {
                int x = ans.size() - i - 1;
                // cout << i << ' ' << x << endl;
                point = ans[i + ((K - i) % x)];
            }
        }
    }
    cout << point << endl;
}
int main()
{
    func();
}

Measured memory_bytes: 5184
//by rko27
//One more....
//---------------------------------------------------------------------------------------------------------------------------------------------------

#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int  long long 
#define ll  long long 
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define nl "\n"
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define god ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

//----------------------------------------------------------------------------------------------------------------------------------------------------


int mod=1000000000+7;
int modu=998244353;

//----------------------------------------------------------------------------------------------------------------------------------------------------

ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll powe(ll x, ll y){ x = x%mod, y=y%(mod-1);ll ans = 1;while(y>0){if (y&1){ans = (1ll * x * ans)%mod;}y>>=1;x = (1ll * x * x)%mod;}return ans;}
void fun()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	//786
}
bool isPrime(int n){for(int i=2;i*i<=n;i++)if(n%i==0) return false;return true;}
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}

//-------------------------------------------------------------------------------------------------------------------------------------------------------

std::vector<pair<int,int > > v;

//--------------------------------------------------------------------------------------------------------------------------------------------------------


//--------------------------------------------------------------------------------------------------------------------------------------------------------
signed main() 
{
	god;
	//rko;
	fun();
	int tt=1; //cin>>tt;
	while(tt--)
	{
		int n,k; cin>>n>>k;
		int h[n+1]; h[0]=0;
		for(int i=1;i<=n;i++) cin>>h[i];
		int dp[n+1];
		memset(dp,mod,sizeof(dp));
		dp[1]=0; dp[2]=abs(h[1]-h[2]);
		for(int i=3;i<=n;i++)
		{
			for(int j=1;j<=k;j++)
			{
				if(j<j) continue;
				dp[i]=min(dp[i-j]+abs(h[i]-h[i-j]), dp[i]);
			}
		}
		cout<<max(0ll,dp[n]);
	}
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
int l[105],n;
int main()
{
	cin >> n;
	int ans=0;
	for(int i=0; i<n; i++) cin >> l[i];
	sort(l,l+n);
	for(int i=0; i<n-2; i++)
		for(int j=i+1; j<n-1; j++)
			for(int k=j+1; k<n; k++)
				if(l[i]!=l[j]&&l[j]!=l[k]&&l[i]!=l[k]&&l[i]+l[j]>l[k]) ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3640
import sys
n = sys.stdin.readline().rstrip()[-1]
d = {
  '0': 'pon',
  '1': 'pon',
  '2': 'hon',
  '3': 'bon',
  '4': 'hon',
  '5': 'hon',
  '6': 'pon',
  '7': 'hon',
  '8': 'pon',
  '9': 'hon',
}
print(d[n])


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

import math

if __name__ == '__main__':
    l = list(map(int, input().split()))
    X = int(l[0])
    K = int(l[1])
    D = int(l[2])
    
    if D*K <= abs(X):
        minVal=abs(X) - D*K
    else:
        n=math.floor(abs(X)/D)+1
        # while abs(X) - D*n > 0:
        #    n=n+1
        
        if (K-n)%2==0:
            minVal = abs(abs(X) - D*n)
        else:
            minVal = abs(abs(X) - D*(n-1))
        
    print(minVal)

Measured memory_bytes: 9148
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
int mod=1000000007;
typedef long long ll;
using namespace std;
 
int main(){
	int n;
	ll a,b;
	cin>>n>>a>>b;
	lol(i,n-1){
		ll p,q;
		cin>>p>>q;
		ll tmp=a/p+(a%p>0);
		tmp=max(tmp,b/q+(b%q>0));
		a=p*tmp;
		b=q*tmp;
	}
	cout<<a+b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define rALL(x) x.rbegin(), x.rend()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<vector<char>> g;
int main(){
    ll n, k;    cin >> n >> k;
    vector<ll> s, t, a(n);
    REP(i, n){
        ll x;   cin >> x;
        if(0<x) s.push_back(x);
        else t.push_back(x);
        a[i] = x;
    }
    ll S=s.size(), T=t.size();
    bool ok=false;
    if(S>0){
        if(n==k) ok = !(T%2);
        else ok = true;
    }else   ok = !(k%2);
    ll res=1;
    if(!ok){
        sort(ALL(a), [](ll x, ll y){
            return abs(x) < abs(y);
        });
        REP(i, k) res = (res*abs(a[i]))%MOD;
        res = (MOD-res)%MOD;
    }else{
        sort(ALL(s));  //降順ソート
        sort(rALL(t));
        if(k%2){
            res = (res*s.back())%MOD;
            s.pop_back();
        }
        vector<ll> p;
        while(2<=s.size()){
            ll x=s.back();  s.pop_back();
            x *= s.back();  s.pop_back();
            p.push_back(x);
        }
        while(2<=t.size()){
            ll x=t.back();  t.pop_back();
            x *= t.back();  t.pop_back();
            p.push_back(x);
        }
        sort(rALL(p));
        REP(i, k/2) res = (p[i]%MOD*res)%MOD;
    }
    cout << res << endl;
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

typedef struct {
    Int y, x;
} p_t;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Int n;
    cin >> n;
    if (n % 2 == 0) {
        Int f = 0;
        Int x = 10;
        for (Int i = 0; x <= n; i++) {
            f += n / x;
            x *= 5;
        }
         x = 2;
        Int t = 0;
        for (Int i = 0; x <= n; i++) {
            t += n / x;
            x *= 2;
        }
        dump(min(f, t));
    }
    else {
        dump(0);
    }

    return 0;
}

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

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, d, x, y;

	cin >> n >> d;

	ll ans = 0;


	while (n--) {

		cin >> x >> y;

		if (x * x + y * y <= d * d) {
			ans++;
		}
	}

	cout << ans << endl;



	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
    int a[5];
    int S = 0;
    int min = 10;
    for(int i = 0;i < 5;i++){
        cin >> a[i];
        if(a[i] % 10 != 0){
            min = std::min(min, a[i] % 10);
            a[i] -= a[i] % 10;
            a[i] += 10;
        }
        S += a[i];
    }
    S -= 10;
    cout << S + min << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <iomanip>
#include <math.h>
#include <algorithm>
#define oo 1000000007
#define maxN 207
using namespace std;

int f[2][207][207];
int a[207][207];
int b[1007];

int main() {

    long long a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max({a*c, a*d, b*c, b*d}) << endl;
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main()
{
    //int t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,cnt=0,sum=0;
        cin>>n;
        ll arr[n];
        map <ll,ll> mp;
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
            mp[arr[i]]++;
            sum+=arr[i];
        }
        cin>>k;
        for(i=0;i<k;i++)
        {
            cin>>a>>b;

            sum-=a*mp[a];
            sum+=b*mp[a];
            mp[b]+=mp[a];
            mp[a]=0;
            cout<<sum<<endl;
        }



    }
}



Measured memory_bytes: 10284
#include <bits/stdc++.h>
using namespace std;
 
 
int main(void){
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            sum += v[i];
        } else {
            sum -= v[i];
        }
    }
    vector<int> v2(N);
    v2[0] = sum;
    for (int i = 1; i < N; i++) {
        v2[i] = (v[i - 1] - v2[i - 1] / 2) * 2; 
    }
    for (int i = 0; i < N - 1; i++) {
        cout << v2[i] << " ";
    }
    cout << v2[N - 1] << endl;
    
    
    return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int h, w;
  cin >> h >> w;

  int cnt = 0;
  char s[10][10];
  rep(i, h) {
    rep(j, w) {
      cin >> s[i][j];
      if (s[i][j] == '#') ++cnt;
    }
  }

  int T = h + w - 1;
  cout << (cnt == T ? "Possible" : "Impossible") << "\n";

  return 0;
}

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

ll gcd(ll x,ll y){
    if (x<y) swap(x,y);
    if (y==0) return x;
    else return gcd(y,x%y);
}

int main(){
    int N;
    cin >> N;
    vector<ll> T(N);
    for (int i=0;i<N;i++){
        cin >> T[i];
    }
    vector<ll> c_sum_lcm(N+1,1);
    for (int i=1;i<=N;i++){
        c_sum_lcm[i] = T[i-1] / gcd(T[i-1],c_sum_lcm[i-1]) * c_sum_lcm[i-1];
    }
    cout << c_sum_lcm[c_sum_lcm.size()-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	int k,a,b;
	cin>>k>>a>>b;
	int t=ceil((double)a/k);
	if(t*k<=b && t*k>=a){
		cout<<"OK\n";
	}
	else{
		cout<<"NG\n";
	}
}


Measured memory_bytes: 3652
import math
n, k = map(int, input().split())
if k > n:
    prob = 0
else:
    prob = (n-k+1)/n
for i in range(1,min(n+1,k)):
    x = math.ceil(math.log2(k/i))
    if k>n:
        prob += (1/n)*0.5**x
    else:
        prob += (1/n)*0.5**x
print(prob)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l, r, d, ans = 0;
  cin >> l >> r >> d;
  for (int i = l; i <= r; i++)
  {
    if (i%d == 0)
    {
      ans++;
    }
    
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 3620
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=5e5+5,M=2e6+5,MOD=1e9+7,OO=1e9;
struct X
{
	int a,b,c;
};
int n;
int memo[55][401][401];
int ma,mb;
X wa[55];
int solve(int indx,int a,int b){
	if(indx==n){
		if(a && b && (a%ma == 0) && (b%mb ==0 ) && ((a/ma) == (b/mb)))return 0;
		if(a && b && (ma%a == 0) && (mb%b ==0 ) && ((ma/a) == (mb/b)))return 0;
		return 1e9;
	}
	int &ret = memo[indx][a][b];
	if(~ret)return ret;
	ret = min(solve(indx+1,a+wa[indx].a,b+wa[indx].b)+wa[indx].c,
		solve(indx+1,a,b));
	return ret;
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();	
	
	scanf("%d %d %d",&n,&ma,&mb);

	for(int i=0;i<n;i++)scanf("%d %d %d",&wa[i].a,&wa[i].b,&wa[i].c);

	memset(memo,-1,sizeof(memo));

	if(solve(0,0,0)>=1e9)printf("-1\n");
	else	printf("%d\n",solve(0,0,0));
}		


Measured memory_bytes: 34816
<?php
fscanf(STDIN, '%d %d', $len, $k);
fscanf(STDIN, '%s', $line);
$org = str_split($line);
$map = [];
$now = 1;
$cnt = 0;
for ($i=0; $i < $len; $i++) { 
    if ($org[$i] == $now) {
        $cnt++;
    } else {
        $map[] = $cnt;
        $now = 1 - $now;
        $cnt = 1;
    }
}

if ($cnt) {
    $map[] = $cnt;
}

if (count($map) % 2 == 0) {
    $map[] = 0;
}

$mapLen = count($map);
$tmpArr = array_fill(0, $mapLen + 1, 0);
for ($i=0; $i < $mapLen; $i++) { 
    $tmpArr[$i + 1] = $tmpArr[$i] + $map[$i];
}

$max = 0;
for($i = 0; $i < $mapLen; $i+=2){
    $left = $i;
    $right = min($i + 2 * $k + 1, $mapLen);
    $tmp = $tmpArr[$right] - $tmpArr[$left];

    $max = max($max, $tmp);
}
echo $max;

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

using ll = long long;

// 繰り返し自乗法(x^nをmで割った余り) O(logn)
ll power(ll x, ll n, ll m) {
  ll res = 1;
  if (n > 0) {
    res = power(x, n / 2, m);
    if (n % 2 == 0) res = (res * res) % m;
    else res = (((res * res) % m) * x) % m;
  }
  return res;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  vector<ll> x(s.size());
  map<ll, ll> mp;
  ll keep = 0, ans = 0;
  mp[0]++;
  for (int i = s.size() - 1; i >= 0; i--) {
    keep += (s.at(i) - '0') * power(10, s.size() - i - 1, 2019);
    keep %= 2019;
    x.at(i) = keep;
  }
  
  for (int i = 0; i < s.size(); i++) {
    if (i >= 4) mp[x.at(i - 4)]++;
    ans += mp[x.at(i)];
  }
  
  cout << ans << '\n';
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,H;cin>>N>>H;
  vector<pair<int,int>>A(N*2);
  for(int i=0;i<N;i++){
    int a,b;cin>>a>>b;
    A[i*2]=pair(a,1);
    A[i*2+1]=pair(b,2);
  }
  sort(A.rbegin(),A.rend());
  long long count=0;
  for(int i=0;i<N*2;i++){
    if(A[i].second==1){
      cout<<i+(H-count+A[i].first-1)/A[i].first<<endl;
      return 0;
    }
    count+=A[i].first;
    if(count>=H){cout<<i+1<<endl;return 0;}
  }
}

Measured memory_bytes: 4824
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
 }
int main(){
  int64_t n, ans=0;
  cin >> n;
  map<int64_t, int> m = prime_factor(n);
  for (const auto& [key, value]:m){
    ans+=(int)((sqrt(1+8*value)-1)*0.5);
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
void make_v(vector<int> &v, int a, int b, int c) {
    for (int i = 0; i < a; i++) v.push_back(3);
    for (int i = 0; i < b; i++) v.push_back(5);
    for (int i = 0; i < c; i++) v.push_back(7);
}
int main() {
    int n;
    cin >> n;
    vector<int> nums;
    for (int i = 3; i < 10; i++) {
        for (int a = 1; a <= i - 2; a++) {
            for (int b = 1; a + b <= i - 1; b++) {
                int c = i - a - b;
                vector<int> v;
                make_v(v, a, b, c);
                do {
                    int n = 0;
                    for (auto u: v) n = n * 10 + u;
                    nums.push_back(n); 
                } while (next_permutation(v.begin(), v.end()));
            }
        }
    }
    // dfs({3, 5, 7});
    sort(nums.begin(), nums.end());
    int ans = 0;
    for (auto x: nums) {
        if (x > n) break;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3720
import collections
import sys
S = input()[::-1]
    
MOD=2019
X = [0]
for i, s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
    
c = collections.Counter(X)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 16608
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int intAns = 0;
		
		for (int i = 1; i < 10; i++) {
			
			n -= 111;
			
			if (n <= 0) {
				intAns = i;
				break;
			}
		}
		
		String ans = String.valueOf(intAns);
		
		System.out.println(ans + ans + ans);
	}
}

Measured memory_bytes: 23124
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define psvi pair<string,vi>
#define psi pair<string,int>
#define pss pair<string,string>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
#define vvi vector<vi>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
/****************************/
int cf(int n)
{
	int ans=1;
	rep(i,n)
	{
		ans*=10;
	}
	return ans;
}
int s[10],c[10];
int main()
{
	int n,m;
	cin>>n>>m;
	rep(i,m)
	{
		cin>>s[i]>>c[i];
	}
	rep3(i,cf(n-1),cf(n))
	{
		if(i==1)
		{
			i--;
			bool can=true;
			rep(j,m)
			{
				if(!(i%cf(n-s[j]+1)/cf(n-s[j])==c[j]))
				{
					can=0;
					break;
				}
			}
			if(can)
			{
				cout<<i;
				return 0;
			}
			i++;
		}
		bool can=true;
		rep(j,m)
		{
			if(!(i%cf(n-s[j]+1)/cf(n-s[j])==c[j]))
			{
				can=0;
				break;
			}
		}
		if(can)
		{
			cout<<i;
			return 0;
		}
	}
	cout<<"-1";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a>=0 && b>=0 && c>=0 && a<=100 && b<=100 && c<=100)
  {
    if(a<b && b<c)printf("Yes\n");
    else printf("No\n");
  }
  return 0;
}

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

ll ks(ll weight[],ll value[],int N,int W) {
    ll dp[N+1][W+1] = {0};
    for(int i=0; i<=N; i++) {
        for(int w=0; w<=W; w++) {
            if(w == 0 || i == 0) {
                dp[i][w] = 0;
            }
            else {
                ll x=0,y=0;
                if(weight[i] <= w) {
                    x = value[i] + dp[i-1][w-weight[i]];
                }     
                y = dp[i-1][w];
                dp[i][w] = max(x,y);
            }
        }
    }
    return dp[N][W];
}

int main() {
    int N,W;
    cin>>N>>W;
    ll value[N+1]={0},weight[N+1]={0};
    for(int i=1; i<=N; i++) {
        cin>>weight[i]>>value[i];
    }
    cout<<ks(weight,value,N,W);
    return 0;
}

Measured memory_bytes: 82392
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int N;
int main(){
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);
    rep(i,N)cin >> A[i];
    rep(i,N)cin >> B[i];
    rep(i,N)cin >> C[i];
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());
    long long ans = 0;
    for(ll i=0;i<N;++i){
        ll k = upper_bound(C.begin(),C.end(),B[i])-C.begin();
        k = N-k;
        ll l = lower_bound(A.begin(),A.end(),B[i])-A.begin();
        ans += k*l;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  if(B == 0 || B == 1)
    cout << 0;
  else{
    for(int i = 0;i < 20;++i)
      if(A + (A - 1) * i >= B){
        cout << i + 1;
        break;
      }
    }
}

Measured memory_bytes: 764
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		
		while (true) {
			int x = Integer.parseInt(scan.next());
			int y = Integer.parseInt(scan.next());
			
			if (x == 0 && y == 0) {
				break;
			}
			
			if (x > y) {
				int tmp = x;
				x = y;
				y = tmp;
			}
			
			System.out.println(x + " " + y);
		}
	}
}

Measured memory_bytes: 35888
# -*- coding: utf-8 -*-
N = int(input())
items = [list(map(int, input().split())) for i in range(N)]
items = sorted(items, key=lambda x:x[0]+x[1])
res = 0
bf =  -10**9
for x, l in items:
    if bf <= x - l:
        res += 1
        bf = x + l
print(res)


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

int main() {
    int a = 0, b = 0;
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); ++i) {
        if(s[i] == '0') a++;
        else b++;
    }
    cout << min(a, b)*2 << '\n';
    
    return 0;
}


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

int main( ) {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

const int mod = 1e9 + 7;

int N;
string S[50];
int dp[55][55][55][55];

int rec(int top, int bottom, int col, int alpha)
{
  if(alpha >= 27 || col > 20) return (0);
  if(top == bottom && col == 20) return (1);
  if(~dp[top][bottom][col][alpha]) return(dp[top][bottom][col][alpha]);
  int ret = rec(top, bottom, col, alpha + 1);
  for(int i = top; i <= bottom; i++) {
    if(S[i][col] == (alpha == 0 ? '~' : alpha - 1 + 'a') || (alpha && S[i][col] == '?')) {
      (ret += 1LL * rec(top, i, col + 1, 0) * (i == bottom ? 1 : rec(i + 1, bottom, col, alpha + 1)) % mod) %= mod;
    } else {
      break;
    }
  }
  return(dp[top][bottom][col][alpha] = ret);
}

int main()
{
  memset(dp, -1, sizeof(dp));
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> S[i];
    while(S[i].size() < 20) S[i].push_back('~');
  }
  cout << rec(0, N - 1, 0, 0) << endl;
}

Measured memory_bytes: 39020
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int N = inputintArray[0];
		int R = inputintArray[1];

		if(N >= 10)
		{
			Console.WriteLine(R);
		}
		else
		{
			Console.WriteLine(R + (100 * (10 - N)));
		}
	}
}

//string s = Console.ReadLine();
//int[] inputintArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = inputintArray[0];
//int W = inputintArray[1];
//int N = int.Parse(Console.ReadLine());
//int[] a = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

//Console.WriteLine(ans);
//Console.ReadKey();

Measured memory_bytes: 11220
#include <iostream>
#include <stdlib.h>
#include <vector> //vector
#include <algorithm> //sort()
#include <numeric>

#define rep(i, n) for(int i=0; i<(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) cout << "debug (" #a "):" << endl << (a) << endl;

typedef uint64_t ulint;
typedef int64_t lint;

using namespace std;

template<class T> inline bool chmin(T& a, T b);
template<class T> inline bool chmax(T& a, T b);
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v);

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);

//uint64_t a, b, c, d;
//uint64_t i, j;
lint n, m;

int main(){
//////////////////////////////////////////////////////

    cin >> n;

    vector<lint> w( n );

    for ( lint i = 0 ; i < n ; i ++)
    {
        cin >> w[i];
    }

    lint sum=0;

    for ( lint i = 0 ; i < n ; i ++)
    {
        sum += w[i];
    }

    lint min=999999;
    lint fw=0;

    for ( lint i = 0 ; i < n ; i ++)
    {
        fw += w[i];
        if(abs(sum-2*fw)<min)
        {
            min=abs(sum-2*fw);
        }
        else
        {
            break;
        }
        

    }

    cout << min << endl;

    

   

    // sort(input.begin() , input.end());

    // uint64_t max = numeric_limits<uint64_t>::max();


    //////////////////////////////////////////////////////
    // DP

//     // 無限大の値
//     const uint64_t INF = (uint64_t)1 << 60;
//     //const int64_t NINF = -1 * ((int64_t)1 << 60 );
 
//     // DP テーブル
//     uint64_t dp[100010];

//     //DPテーブル初期化（最小化用）
//     for (int i = 0; i < 100010; ++i)
//     {
//         //dp[i] = INF;
//         dp[i] = 0;
//     } 

//     // 初期条件
//     dp[0] = 0;

//     // ループ
//     for (int i = 1; i <= n; ++i) {
//         //chmin( dp[i], dp[i - 1] + abs( input[i] - input[i - 1] ));
//         //if (i < 2)continue;
//         //chmin( dp[i], dp[i - 2] + abs( input[i] - input[i - 2] ));



//         // chmax ( dp [i] , dp[i - 1]);
//         // chmax ( dp [i] , dp[i - 1] + input[i]);
//         // cout << "dp[" << i <<"] = " << dp[i] << endl;

//     }



// //////////////////////////////////////////////////////

//     cout << dp[n] << endl;

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


//最小化用関数
template<class T> inline bool chmin(T& a, T b)
{
    if (a > b) 
    {
        a = b;
        return true;
    }
    return false;
}

//最大化関数
template<class T> inline bool chmax(T& a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}


// vectorprint用
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	int len = v.size();
	for (int i = 0; i < len; ++i) {
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}

// //合計
// template<class T> lint sum(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0);
// }


// //平均
// template<class T> double ave(vector<T> a)
// {
//     return std::accumulate(a.begin(), a.end(), 0.0) / a.size();
// }


Measured memory_bytes: 256
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
#[allow(unused_imports)]
use std::io::{stdout, stdin, BufWriter, Write};

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
    }

    let mut ans = 0;
    for i in 0..n+1 {
        if i >= 1 && i < 10 {
            ans += 1;
        }
        if i >= 100 && i < 1000 {
            ans += 1;
        }
        if i >= 10000 && i < 100000 {
            ans += 1;
        }
    }
    puts!("{}\n", ans);
}


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

void solve() {
  int x;
  cin >> x;
  int maxN = x / 100;
  int moddd = x % 100;
  if (moddd <= 5 * maxN) cout << 1 << endl;
  else cout << 0 << endl;
}

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


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph emplace
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n,  anss;
string S[MAXN],sad;
deque<ll> front,back;
deque<ll>legit;
string ans;
bool unlegit[MAXN];
int main()
{
	FAST
	cin>>n;
	FOR(i,0,n)cin>>S[i];
	FOR(i,0,n){//compress
		FOR(j,1,S[i].size()){
			if(S[i][j-1]=='A'&&S[i][j]=='B') anss++;
		}
		string s = "";
		s+=S[i][0];
		s+='Z';
		s+=S[i].back();
		S[i]=s;
		if(S[i][0]!='B'&&S[i][2]=='A')front.pb(i);
		else if(S[i][0]=='B'&&S[i][2]!='A')back.pb(i);
		else if(S[i][0]=='B'&&S[i][2]=='A')legit.pb(i);
		else unlegit[i]=1;
	}
	if(siz(back)&&siz(front)&&siz(legit)) {
		legit.push_front(front[0]);
		front.pop_front();
		legit.pb(back[0]);
		back.pop_front();
	}
	if(siz(back)>siz(front)) {
		for(auto i:legit)ans+=S[i];
		ans+=S[back.back()];
		back.pop_back();
		while(min(siz(back),siz(front))>0){
			ans+=S[front.back()];
			ans+=S[back.back()];
			front.pop_back();
			back.pop_back();
		}
	} else if(siz(back)<siz(front)) {
		ll x = front.back();
		front.pop_back();
		while(min(siz(back),siz(front))>0){
			ans+=S[front.back()];
			ans+=S[back.back()];
			front.pop_back();
			back.pop_back();
		}
		ans+=S[x];
		for(auto i:legit)ans+=S[i];
	} else {
		while(min(siz(back),siz(front))>0){
			ans+=S[front.back()];
			ans+=S[back.back()];
			front.pop_back();
			back.pop_back();
		}
		for(auto i:legit)ans+=S[i];
	}
	FOR(i,0,n)if(unlegit[i])ans+=S[i];
	FOR(j,1,siz(ans)) if(ans[j-1] == 'A' && ans[j]=='B') anss++;
	cout<<anss;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll K;
  cin >> K;
  string s;
  cin >> s;
  if (s.length() <= K) {
    cout << s << endl;
  } else {
    s.resize(K);
    s += "...";
    cout << s << endl;
  }
  

}


Measured memory_bytes: 3600
import sys
import math
i=int(input())
  #insu bunkai site hairetu de kaesu
k=[]
num=i
j=2
while j*j<=num:
  if i%j==0:
    i//=j
    k.append(j)
  else:
    j+=1
if i!=1:
  k.append(i)

print(str(num)+": "+(' '.join(map(str, k))))


Measured memory_bytes: 5656
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define P pair<int,int>
#define F first
#define S second
#define int long long
#define mod 1000000007
#define mmod 998244353
#define all(v) v.begin(), v.end()
#define INF LLONG_MAX/3
#define PI 3.14159265359
using namespace std;
int mypow(int fa, int fb, int fc) {
	if (fb == 0)return 1;
	if (fb % 2)return mypow(fa, fb - 1, fc)*fa%fc;
	int z = mypow(fa, fb / 2, fc);
	return z * z%fc;
}
int k(int fa) {
	int x = 0;
	while (fa) {
		x++;
		fa /= 10;
	}
	return x;
}
int gcd(int fa, int fb) {
	if (fb == 0)return fa;
	return gcd(fb, fa%fb);
}
signed main() {
	int a;
	cin >> a;
	f(i, a) {
		int b;
		cin >> b;
		if (b % 2 == 0 && b % 3 && b % 5) {
			puts("DENIED");
			return 0;
		}
	}
	puts("APPROVED");
}

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

int main()
{
  int m,n;
  cin>>m>>n;
  vector<int> be[m];
  for(int i=0;i<m;i++)
    {
      //tama
      if(i!=1)
        be[1].push_back(i);
    }

  for(int i=0;i<n;i++)
    {
      int x,y;
      cin>>x>>y;
      x--;y--;
      be[y].push_back(x);
    }
  int cnt=m;
  while(cnt>0)
    {
      vector<int> del;

      for(int i=0;i<m;i++)
        {
          if(be[i].size()<=0)
            {
              cout<<i+1<<endl;
              cnt--;
              del.push_back(i);
	      be[i].push_back(-1);
            }
        }
      for(int i=0;i<m;i++)
        {
          for(int j=0;j<del.size();j++)
            be[i].erase(remove(be[i].begin(),be[i].end(),del[j]),be[i].end());
	}
    }


}

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

int main(){
  int a;
  cin >>a;
  if(a==4||a==2||a==1){
    cout << 4<< endl;
    return 0;
  }
  int i=1;
  while(true){
    i++;
    if(a%2==0) a=a/2;
    else a=3*a+1;
    if(a==4){
      cout << i+3<< endl;
      return 0;
    }
  }
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String[] suit = {"S","H","C","D"};
		String[] rank = {"1","2","3","4","5","6","7","8","9","10","11","12","13"};
		int n = sc.nextInt();
		String[][] card = new String[4][13];
		for (int i = 0; i < n; i ++ ){
			String s = sc.next();
			String r = sc.next();
			int sIdx = Arrays.asList(suit).indexOf(s);
			int rIdx = Arrays.asList(rank).indexOf(r);
//			System.out.println(sIdx + " " + rIdx);
			card[sIdx][rIdx] = "ok";
		}
		for (int i = 0; i < 4; i ++ ){
			for (int k = 0; k < 13; k ++ ){
				if (card[i][k] == null){
					System.out.println(suit[i] + " " + rank[k]);
				}
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 26224
# AOJ 0631: Point Card
# Python3 2018.7.2 bal4u

n, m = map(int, input().split())
ans, mi = 0, n*2
for i in range(m):
	a, b = map(int, input().split())
	if a < n:
		ans += n-a
		mi = min(mi, a)
print(ans if ans <= 0 else ans-(n-mi));



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

int main(){
  int N;
  cin >>N;
  for(int i=1;i<10;i++)
    for(int j=1;j<10;j++)
      if(N==i*j){
        cout << "Yes"<<endl;
        return 0;
      }

  cout<<"No"<<endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Buffer([]byte{}, math.MaxInt64)
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	k, n := scanInt(), scanInt()
	a := scanInts(n)
	a = append(a, a...)

	for i := 0; i < n; i++ {
		a[n+i] += k
	}

	ans := int(1e9)
	for i := n - 1; i < 2*n-1; i++ {
		if ans > a[i]-a[i-(n-1)] {
			ans = a[i] - a[i-(n-1)]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 8960
N,M=map(int, input().split())
from collections import defaultdict
A=list(map(int, input().split()))
B=[]
import math
def lcm(x, y):
    return (x * y) // math.gcd(x, y)
# a 偶数
twos=0
D=defaultdict(int)
for i in range(N):
    B.append(A[i]//2)
    a=A[i]
    now=0
    while a%2==0:
        a//=2
        now+=1
    D[now]+=1
    twos=max(twos, now)
if len(set(D.values()))!=1:
    print(0)
    exit()
now=1
for i in range(N):
    now=lcm(now, B[i])

# 1.5 * 3 2*5
from math import ceil
ans=M//(now*pow(2,twos))+1
#res=now+now%(2**twos)
ans=ceil(M//now/2)
#if M-res>0:
#    ans-=int((M-res)//now/(2**twos))

print(ans)

Measured memory_bytes: 95108
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <fstream> //ofstream
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int n,m,qno,wact,answa=0,ansct=0;
string result;
std::vector<int> wactv(pow(10,5),0);
std::vector<int> flag(pow(10,5),0);
void solve(){

}

int main(){
        cin>>n>>m;
        rep(i,m){
                cin>>qno;
                cin>>result;
                if(result=="WA") {
                        wactv.at(qno)++;
                }else if(flag.at(qno)==0) {
                        flag.at(qno)=1;
                        ansct++;
                        answa+=wactv.at(qno);
                }
        }
        cout<<ansct<<" "<<answa<<endl;



        return 0;
}


Measured memory_bytes: 1024
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail) { cin >> head; in(move(tail)...); }
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

vector<ll> p;
vector<ll> IsPrime;
void sieve(ll max)
{
    if (max+1 > IsPrime.size())
        IsPrime.resize(max+1,0);
    std::iota(IsPrime.begin(), IsPrime.end(), 0);
    for (ll i=2; i*i<=max; ++i)
        if (IsPrime[i] >= i) {
            p.push_back(i);
            for (ll j=i*i; j<=max; j += i)
                if (IsPrime[j] == j) IsPrime[j] = i;
        }
}

void solve()
{
    sieve(10000000);
    IN(n);
    ll res = 0;
    rep(i, n+1) {
        ll k = i;
        ll f = 0;
        ll c = 0;
        ll r = 1;
        while (k > 1) {
            ll m = IsPrime[k];
            k /= m;
            if (f != m) {
                r *= c + 1;
                c = 0;
                f = m;
            }
            ++c;
        }
        r *= c + 1;
        res += i * r;
    }
    cout << res << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 81252
def main():
	N = int(input())
	X = list(map(int, input().split()))
	P = [p for p in range(min(X),max(X)+1)]
	m_list = [sum([(x-p)**2 for x in X]) for p in P] 
	print(min(m_list))
  
if __name__=="__main__":
	main()

Measured memory_bytes: 64340
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll h,w;
  ll vx[]={0,1,0,-1,-1,-1,1,1},vy[]={1,0,-1,0,1,-1,1,-1};
  cin >> h >> w;
  string s[h];
  for(int i=0;i<h;i++){
    cin >> s[i];
  }
  for(int x=0;x<h;x++){
    for(int y=0;y<w;y++){
      ll cnt = 0;
      for(int i=0;i<8;i++){
        ll nx = x + vx[i];
        ll ny = y + vy[i];
        if(nx>=0&&ny>=0&&nx<h&&ny<w&&s[nx][ny]=='#'){
          cnt++;
        }
      }
      if(s[x][y]=='#')cout<<'#';
      else cout<<cnt;
    }
    cout <<endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	private static List<Node> T = new ArrayList<Main.Node>();

	private static class Node {
		public int key;
		public Node left;
		public Node right;
	}

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

		int n = Integer.parseInt(br.readLine());
		for (int i = 0; i < n; i++) {
			String command = br.readLine().trim();

			if (command.equals("print")) {
				print();
			} else if (command.startsWith("insert")) {
				Node node = new Node();
				node.key = Integer.parseInt(command.split(" ")[1]);
				insert(node);
			} else if (command.startsWith("find")) {
				find(Integer.parseInt(command.split(" ")[1]));
			}
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}

	private static void print() {
		Node root = T.size() == 0 ? null : T.get(0);

		List<Integer> tmp = new ArrayList<Integer>();
		inorder(root, tmp);
		for (int i : tmp) {
			System.out.print(" " + i);
		}
		System.out.println();

		tmp = new ArrayList<Integer>();
		preorder(root, tmp);
		for (int i : tmp) {
			System.out.print(" " + i);
		}
		System.out.println();
	}

	private static void inorder(Node node, List<Integer> ret) {
		if (node == null) {
			return;
		}

		inorder(node.left, ret);
		ret.add(node.key);
		inorder(node.right, ret);
	}

	private static void preorder(Node node, List<Integer> ret) {
		if (node == null) {
			return;
		}

		ret.add(node.key);
		preorder(node.left, ret);
		preorder(node.right, ret);
	}

	private static void insert(Node z) {
		Node y = null;
		Node x = T.size() == 0 ? null : T.get(0);
		while (x != null) {
			y = x;
			if (z.key < x.key) {
				x = x.left;
			} else {
				x = x.right;
			}
		}
		if (y == null) {
			T.add(z);
		} else if (z.key < y.key) {
			y.left = z;
		} else {
			y.right = z;
		}
	}

	private static void find(int key) {
		Node root = T.size() == 0 ? null : T.get(0);
		System.out.println(find(root, key) ? "yes" : "no");
	}

	private static boolean find(Node node, int key) {
		if (node == null) {
			return false;
		}

		if (node.key == key) {
			return true;
		} else if (node.key > key) {
			return find(node.left, key);
		} else {
			return find(node.right, key);
		}
	}
}

Measured memory_bytes: 215084
n = int(input())
*A, = map(int, input().split())
S = [0]
for i in range(n):
    S.append(S[-1]+A[i])
DP = [[None for j in range(n+1)] for i in range(n)]
def dp(i, j):
    if j <= i+1:
        return 0
    if DP[i][j] != None:
        return DP[i][j]
    DP[i][j] = S[j]-S[i]+min([dp(i, k)+dp(k, j) for k in range(i+1, j)])
    return DP[i][j]
print(dp(0, n))


Measured memory_bytes: 48604
n = int(input())
d = {k:v for k,v in zip(range(26),'abcdefghijklmnopqrstuvwxyz')}
i = 1
while n > 26**i:
    n -= 26**i
    i += 1
res = ''
n -= 1
for j in range(i-1,-1,-1):
    jn, n = divmod(n, 26**j)
    res += d[jn]
print(res)

Measured memory_bytes: 9172