akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define gcd(a,b)		__gcd(a,b)
#define lcm(a,b)		(a*b)/gcd(a,b)
#define ff              first
#define ss              second
#define int             long long
#define pb              emplace_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             INT64_MAX
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define all(x)			x.begin(),x.end()
#define digits(x)		floor(log10(x))+1
#define FIO				ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

class dsu {
private:
	int *id;
	int* sz;

	int root(int i) {
		while (i != id[i]) {
			id[i] = id[id[i]];
			i = id[i];
		}
		return i;
	}
public:
	int n;
	dsu(int v) {
		n = v;
		id = new int[n];
		sz = new int[n];

		for (int i = 0; i < n; i++) {
			id[i] = i;
			sz[i] = 0;
		}
	}

	bool find(int p , int q) {
		return root(p) == root(q);
	}

	void join(int p , int q) {
		int i = root(p);
		int j = root(q);
		if (i == j) {
			return;
		}
		if (sz[i] < sz[j]) {
			id[i] = j ;
			sz[j] += sz[i];
		}
		else {
			id[j] = i;
			sz[i] += sz[j];
		}
	}
};

class BIT {
private:
	int* FT;
	int n;
public:
	void updateBIT(int index , int val) {
		index += 1;
		while (index <= n) {
			FT[index] += val;
			index += (index & (-index));
		}
	}

	int getSum(int index) {
		index += 1;
		int sum = 0 ;
		while (index > 0) {
			sum += FT[index];
			index -= (index & (-index));
		}
		return sum;
	}


	BIT(int* a , int v) {
		n = v ;
		FT = new int[n + 1];
		for (int i = 1 ; i <= n ; i++) {
			FT[i] = 0 ;
		}
		for (int i = 0 ; i < n ; i++) {
			updateBIT(i, a[i]);
		}
	}
};

int nCr(int n , int r ) {
	int p = 1, k = 1;

	if (n - r < r ) {
		r = n - r;
	}
	if (r != 0) {
		while (r != 0) {
			p *= n ;
			k *= r ;
			int m = __gcd(p, k);
			p /= m;
			k /= m;
			n--;
			r--;
		}
	}
	else {
		p = 1;
	}
	return p ;
}

int modPower(int x, int y , int p) {
	//Used to calculate (x^y)%p
	int res = 1;
	if (y == 0) {
		return 1;
	}

	x = x % p;
	if (x == 0) {
		return 0  ;
	}

	while (y > 0) {
		if (y & 1) {
			res = (res * x) % p;
		}

		y >>= 1;
		x = (x * x) % p;
	}
	return res ;

}

int32_t main() {
	FIO;


	int r ;
	cin >> r;

	if (r < 1200) {
		cout << "ABC";
	}
	else if (r < 2800) {
		cout << "ARC";
	}
	else {
		cout << "AGC";
	}





	return 0;
}


Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
	int x,y,i;
	for(i=1;i<=3000;i++){
		cin>>x>>y;
		if(x==0 && y==0)break;
		if(x>y){
			cout<<y<<" "<<x<<endl;
		}else{
			cout<<x<<" "<<y<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3088
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


double f(double x1, double y1, double x2, double y2, double x3, double y3){
	x2 -= x1;
	x3 -= x1;
	y2 -= y1;
	y3 -= y1;
	return abs(x2*y3-y2*x3)/2;
}

bool solve(){
	vector<double> x(4),y(4);
	while(cin>>x[0]){
		cin>> y[0];
		for(int i=1;i<4;i++){
			cin>> x[i]>> y[i];
		}
		double s[4];
		for(int i=0;i<4;i++){
			s[i] = f(x[i],y[i],x[(i+1)%4],y[(i+1)%4],x[(i+2)%4],y[(i+2)%4]);
		}
		if(s[0] == s[1]+s[2]+s[3]){
			cout<< "YES"<< endl;
		}else{
			cout<< "NO"<< endl;
		}
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1216
//リハビリ(7/22)
#include <bits/stdc++.h>
using namespace std;

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

int main(){
    const long long INF = 1LL << 60;
    long long h[100010];
    long long dp[100010];
    int N;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> h[i]; dp[i] = INF;
    }

    dp[0] = 0;

    for(int i = 1;i<N;i++){
        chmin(dp[i],dp[i-1]+ abs(h[i-1] - h[i]));
        if(i>1) chmin(dp[i], dp[i-2]+ abs(h[i] - h[i-2]));
    }

    cout << dp[N-1] << endl;

}

Measured memory_bytes: 1792
#include <iostream>

int main()
{
	int X;
	std::cin >> X;

	switch ( X )
	{
	case 3: case 5: case 7:
		std::cout << "YES" << std::endl;
		break;
	default:
		std::cout << "NO" << std::endl;
	}

	return ( 0 );
}


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

using namespace std;

using PA = pair<int, int>;

vector<int> E[102400];
int D[102400];
bool V[102400];
int P[102400];

int main() {
  int N, M;
  cin >> N >> M;

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    E[a-1].push_back(b-1);
    E[b-1].push_back(a-1);
  }

  for (int i = 0; i < N; i++) {
    D[i] = 1000000;
    V[i] = false;
    P[i] = -1;
  }

  D[0] = 0;
  P[0] = 1;

  priority_queue<PA, vector<PA>, greater<PA>> que;
  que.push(PA(0, 0));
  
  while(!que.empty()){
    PA p = que.top();
    int ic = p.second;
    que.pop();

    for_each(E[ic].begin(), E[ic].end(), [&](int &hi) {
      if (D[hi] > D[ic] + 1) {
        D[hi] = D[ic] + 1;
        P[hi] = ic;
        que.push(PA(D[ic] + 1, hi));
      }
    });

    V[ic] = true;
  }

  bool f = true;
  for (int i = 1; i < N; i++) f &= P[i] != -1;

  if (f) {
    cout << "Yes" << endl;
    for (int i = 1; i < N; i++) {
      cout << P[i] + 1 << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 10912
#include <cstdio>
#include <algorithm>
using namespace std;
#define MAX_H 200
#define MAX_W 200
#define INF 100000000

int main(int argc, const char * argv[]) {
    int H, W, c[10][10], A[MAX_H][MAX_W];
    scanf("%d%d", &H, &W);
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < 10; j++) {
            scanf("%d", &c[i][j]);
        }
    }
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    // d[i][k] : iをk回以内の変換で1に変えるときの最小コスト
    int d[10][100];
    for (int k = 0; k < 100; k++) {
        for (int i = 0; i < 10; i++) {
            if (i == 1) {
                d[i][k] = 0;
            } else if (k == 0) {
                d[i][k] = INF;
            } else {
                int cost = INF;
                for (int j = 0; j < 10; j++) {
                    cost = min(cost, c[i][j] + d[j][k - 1]);
                }
                d[i][k] = cost;
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] != -1) {
                int a = A[i][j];
                ans += d[a][99];
            }
        }
    }
    printf("%d\n", ans);
    
    return 0;
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

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

int A, B;

signed main()
{
	cin >> A >> B;
	int cnt = 1;
	int ans = 0;
	while (true)
	{
		if (cnt >= B)
			break;
		cnt += A - 1;
		ans++;
	}
	cout << ans << endl;
}




Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- 整数の入力
    n <- readLn
    -- 出力
    putStrLn . show $ sum [1..n]


Measured memory_bytes: 508
N,M = map(int,input().split(" "))
Min = 1
Max = N

for _ in range(M):
    L,R = map(int,input().split(" "))
    if L>Min:
        Min=L
    if R<Max:
        Max=R
if Max-Min>=0:
    print(Max-Min+1)
else:
    print(0)

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

int main(){
    string s, t;
    cin >> s >> t;
    int ans = INF;
    for (int i=0; i+sz(t)<=sz(s); ++i) {
        int cnt = 0;
        rep(j, sz(t)) if (t[j] != s[i+j]) ++cnt;
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
days = int(input())
clast = list(map(int,input().split()))

allpref = [] #allpref[day][contest]
for i in range(days):
    allpref.append(list(map(int,input().split())))
donelist = [0]*26
contestlist = []
for i in range(days):
    max = -10**10
    result = 0
    contest = False
    for held in range(26):
        tempdonelist = donelist[:]
        tempdonelist[held] = i+1
        zanen = sum([clast[j]*((i+1)-tempdonelist[j]) for j in range(26)])
        result += allpref[i][held] - zanen
        if result >= max:
            max = result;contest = held


    donelist[contest] = i+1
    contestlist.append(contest+1)

for num in contestlist:
    print(num)


Measured memory_bytes: 9408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

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

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll n,m;
  cin >> n >> m;
  if (n < m) swap(n,m);
  if (n - m != 0 && n - m != 1) {
    cout << 0 << endl;
    return 0;
  }
  //n! * (n+1)Cm * m!
  mint ans(n), mf(m);
  for (ll i = n-1; i >= 2; --i) {
    ans *= i;
    if (i < m) mf *= i;
  }
  debug(ans.x, mf.x);
  ll temp;
  if (n == m) temp = 2;
  else temp = 1;
  ans *= temp;
  ans *= mf;
  cout << ans.x << endl;
  return 0;
}

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

int main(){
int N,L;
cin >> N >> L;
vector<string> vec(N);
for(int i=0; i<N; i++){
    cin >> vec.at(i);
}
sort(vec.begin(),vec.end());
string S;
for(int i=0; i<N; i++){
    S += vec.at(i);
}
cout << S <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Int int32_t
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define bitcnt(n) __builtin_popcountll(n)
#define setpre(n) cout << fixed << setprecision(n)
#define tr(c) for(const auto& x : c )cout << x << " "; cout << "\n";
#define ol(c, s, e) for(int pos=s; pos<e; pos++)cout << c[pos] << " ";cout <<"\n";
#define PI acos(-1LL)

const int M = 1000000007;
const int N = 2e5 + 5;
const long long INF = 1e9 + 12;

string a,b;
int dp[3005][3005];
int fun(int i, int j){
    if(i<0 || j<0)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(a[i] == b[j]){
        return dp[i][j] =  1 + fun(i-1, j-1);
    }
    else{
        return dp[i][j] = max(fun(i-1,j), fun(i, j-1));
    }
}
string ans;
void path(int i, int j){
    if(i<0 || j<0)
        return;
    if(a[i] == b[j]){
        ans+=a[i];
        path(i-1,j-1);
    }else{
        if(fun(i,j) == fun(i-1,j))
            path(i-1,j);
        else
            path(i,j-1);
    }
}
void solve(){
    cin >> a >> b;
    memset(dp, -1, sizeof dp);
    fun(a.size()-1,b.size()-1);
    path(a.size()-1,b.size()-1);
    reverse(all(ans));
    cout << ans;
}

signed main(){
    FAST
    int tc = 1;
//    TODO: check for tc
//    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        solve();
    }
}


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

int main() {
char aa;
  cin >> aa;
vector<char> moji{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  for(int i = 0; i < 26; i++){
  	if(aa == moji[i]){
    	cout << moji[i+1] << endl;
    }
  }
}

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

int main() {
	long int A, B, C;
	cin >> A >> B >> C;
	if(A%2==0 || B%2==0 || C%2==0){
		cout << 0 << endl;
		return 0;
	}
	else{
		vector<long int> vec (3);
		vec.at(0) = A;
		vec.at(1) = B;
		vec.at(2) = C;
		sort(vec.begin(),vec.end());
		cout << vec.at(0) * vec.at(1) << endl;
		return 0;
	}
}

Measured memory_bytes: 256
//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin, output: process.stdout
});
var obj; var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  return {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw "ArrayIndexOutOfBoundsException ‚There is no more input";}}
  };
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
  var N = nextInt();
  var output = [];
  var list = "abcdefghijk";
  dfs([0]);
  output.sort();
  myout(myconv(output, 9));
  function dfs(used){
    if(used.length == N){
      var s = "";
      for(var i = 0; i < N; i++){
        s += list[used[i]];
      }
      output.push(s);
      return;
    }
    var max = Math.max.apply(null,used) + 1;
    for(var i = 0; i <= max; i++){
      var tmp = makeClone(used);
      tmp.push(i);
      dfs(tmp);
    }
  }
}


Measured memory_bytes: 62264
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,ans=0;
vll v[100005];
int dp[100005][2];
void dfs(int node , int p){
	dp[node][0] = dp[node][1] = 1;
	for(auto j:v[node]){
		if(j!=p){
			dfs(j,node);
			dp[node][0]=(dp[j][1]*dp[node][0])%hell;
			dp[node][1]=(((dp[j][0]+dp[j][1])%hell)*dp[node][1])%hell; 
		}
	}
}
void solve(){
    cin>>n;
    for(int i=0;i<n-1;i++){
    	cin>>j>>k;
    	v[j].pb(k);
    	v[k].pb(j);
    }
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%hell<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}


Measured memory_bytes: 14208
#include<stdio.h>

long long int min(long long int x,long long int y){
  if(x<y) return x;
  else return y;
}

long long int max(long long int x,long long int y){
  if(x>y) return x;
  else return y;
}

int main(){
  int n,k,i,j,l,m,o,cnt=0;
  long long int x[50],y[50],xmin,xmax,ymin,ymax,s;
  s=4000000000000000000;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++){
    scanf("%ld %ld",&x[i],&y[i]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(i!=j){
        xmin=min(x[i],x[j]);
        xmax=max(x[i],x[j]);
        for(l=0;l<n;l++){
          for(m=0;m<n;m++){
            if(l!=m){
              cnt=0;
              ymin=min(y[l],y[m]);
              ymax=max(y[l],y[m]);
              for(o=0;o<n;o++){
                if(x[o]>=xmin&&x[o]<=xmax&&y[o]<=ymax&&y[o]>=ymin)
                  cnt++;
              }
              if(cnt>=k) s=min(s,(xmax-xmin)*(ymax-ymin));
            }
          }
        }
      }
    }
  }
  printf("%ld\n",s);
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

//sum(floor((a*i+b)/m))) for i=0,...,n-1
/*
0 <= n <= 1e9
1 <= m <= 1e9
0 <= a,b < m
*/
ll floor_sum(ll n,ll m,ll a,ll b){
    ll ans=0;
    if(a>=m){
        ans+=n*(n-1)*(a/m)/2;
        a%=m;
    }
    if(b>=m){
        ans+=n*(b/m);
        b%=m;
    }

    ll y_max=(a*n+b)/m,x_max=(y_max*m-b);
    if(y_max==0) return ans;
    ans+=(n-(x_max+a-1)/a)*y_max;
    ans+=floor_sum(y_max,a,m,(a-x_max%a)%a);
    return ans;
}

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

  int T;
  cin>>T;
  rep(q,T){
      ll N,M,A,B;
      cin>>N>>M>>A>>B;
      cout<<floor_sum(N,M,A,B)<<"\n";
  }

  return 0;
}


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

const ll M = 1000000007;
int n, m;
ll t, B, xs, ys;

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++){
		scanf("%lld", &t);
		xs = (xs + (i - 1) * t - B) % M;
		B += t;
	}
	B = 0;
	for(int i = 1; i <= m; i++){
		scanf("%lld", &t);
		ys = (ys + (i - 1) * t - B) % M;
		B += t;
	}
	printf("%lld\n", xs * ys % M);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int m,k;
    cin >> m >> k;
    if(k >= 1<<m){
        cout << -1 << el;
    } else {
        if(k==0){
            for(int i=0;i<(1<<m);i++){
                cout << i << " ";
            }
            for(int i=(1<<m)-1;i>=0;i--){
                cout << i << " ";
            }
            return 0;
        }
        int g = 0;
        for(int i=1;i<1<<m;i++){
            if(i!=k){
                g ^= i;
            }
        }
        if(g==k){
            int y = (1<<m)-1;
            for(int i=0;i<=y;i++){
                if(i!=k){
                    cout << i << " ";
                }
            }
            cout << k << " ";
            for(int i=y;i>=0;i--){
                if(i!=k){
                    cout << i << " ";
                }
            }
            cout << k << el;
        } else {
            cout << -1 << el;
        }
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 	string s,t,u;cin>>s>>t;
  	u=s;
  	for(int j=0;j<s.size();j++){
        u.at(0)=s.at(s.size()-1);
  		for(int i=0;i<s.size()-1;i++){
    		u.at(i+1)=s.at(i);
    	}
  		if(u==t){
    		cout<<"Yes"<<endl;
      		return 0;
    	}
        s=u;
    }
    		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int n;
    int count = 0,ans = 0;;
    for(;;){
        scanf("%d",&n);
        if(n == 0)break;
        ans = 1000-n;
        for(;;){
        if(ans == 0){
            printf("%d\n",count);
            break;
        }
        else if(ans >= 500){
            ans-=500;
            count++;
        }
        else if(ans >= 100){
            ans-=100;
            count++;
        }
        else if(ans >= 50){
            ans-=50;
            count++;
        }
        else if(ans >= 10){
            ans-=10;
            count++;
        }
        else if(ans >= 5){
            ans-=5;
            count++;
        }
        else {
            ans-=1;
            count++;
        }
        }
        count = 0;
    }
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<algorithm>

int main(){
	long long int n;
	std::cin>>n;

	std::vector<long long int> v(n);
	for (long long int& x : v) {
		std::cin >> x;
	}

	std::sort(v.begin(), v.end());

	for (int i = 0; i < n-1; i++) {
		if (v[i] == v[i + 1]) {
			std::cout << "NO" << std::endl;
			exit(0);
		}
	}

	std::cout<<"YES"<<std::endl;
	return 0;
}

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

ll lcm(ll a, ll b)
{
    ll t = __gcd(a, b);
    return t ? (a / t * b) : 0;
}

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

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

  ll num = b - a + 1;
  ll cd = lcm(c,d);
  ll res = num - (b / c + b / d) + ((a-1) / c + (a-1)/d) + b / cd -  (a-1) / cd;

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  int n, a, b; cin >> n >> a >> b;
  cout << min(a*n, b) << endl;
  system("pause");
}

Measured memory_bytes: 504
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Iterator;
import java.util.Collections;
import java.util.Comparator;
import java.util.Random;

class Main{
        public static void main(String args[]){
                Scanner sc = new Scanner(System.in);
                int N = sc.nextInt();
                int Y = sc.nextInt();

                int x,y,z;
                boolean ch=false;
                for(x=0; x<=N; x++){
                        for(y=0; y<=N-x; y++){
                                z = N - x - y;
                                ch = 10000 * x + 5000 * y + 1000 * z == Y;
                                if(ch){
                                        System.out.print(x+" "+y+" "+z);
                                        break;
                                }
                        }
                        if(ch)break;
                }
                if(!ch)System.out.print("-1 -1 -1");
        }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;
const int N = 100005;
const long long mod = 1000000007ll;
int n, now = 0, seq[N << 1];
char str[N << 1];
long long ans = 1ll;
int main () {
    scanf("%d", &n);
    scanf("%s", str);
    for (int i = 1; i <= (n << 1); i++) seq[i] = (str[i - 1] == 'B') ? 1 : 0;
    seq[0] = seq[(n << 1) + 1] = 0;
    for (int i = (n << 1) + 1; i >= 1; i--) seq[i] ^= (seq[i - 1] ^ 1);
    for (int i = 1; i <= (n << 1); i++) {
        if (seq[i]) {
            seq[i + 1] ^= 1;
            ans = ans * now % mod, now--;
        }
        else now++;
    }
    for (int i = 1; i <= n; i++) ans = ans * i % mod;
    if (now) printf("%lld\n", 0ll);
    else printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1280
import math
N=int(input())
ans=[0]*(N+1)
tempn=0
xmax=int(math.sqrt(N)+1)
for x in range(1,xmax+1):
    ymax=xmax-x
    for y in range(1,xmax+1):    
        zmax=ymax-y
        for z in range(1,xmax+1):
            tempn=((x+y+z)**2-(x*y+y*z+z*x))
            if tempn <= N:
                ans[tempn]+=1
for i in range(1,(N+1)):
    print(ans[i])


Measured memory_bytes: 69316
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const hs = input[1].split(" ").map(a => Number(a));
  let prevH = 0;
  let result = "Yes";
  for (let i = 0; i < n-1; i++) {
    const h = hs[i];
    const nextH = hs[i+1];
    if (1 < h - nextH) {
      result = "No";
      break;
    } else if (h - nextH === 1) {
      if (i !== 0 && nextH < prevH) {
        result = "No";
        break;
      }
      prevH = nextH;
    } else {
      prevH = prevH < h ? h-1 : h;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17816
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<cmath>

using namespace std;

int main(){
    int N, X, T;
    cin >> N >> X >> T;
    int ans = N/X + ((N%X > 0)? 1:0);
    cout << ans*T;


    return 0;
}


Measured memory_bytes: 3628
N = int(input())
Sa = []
Sb = []
Sba = []
ans = 0
for _ in range(N):
    s = input()
    if s[0] == 'B' and s[-1] == 'A':
        Sba.append(s)
    elif s[0] == 'B':
        Sb.append(s)
    elif s[-1] == 'A':
        Sa.append(s)
    ans += s.count('AB')
lsa = len(Sa)
lsb = len(Sb)
lsba = len(Sba)
if len(Sba) >= 1:
    ans += len(Sba)-1
    if lsa:
        ans += 1
        lsa -= 1
    if lsb:
        ans += 1
        lsb -= 1
ans += min(lsa, lsb)
print(ans)

Measured memory_bytes: 3700
#include<iostream>
#include<set>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<iterator>
#include<cmath>
#include<functional>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector< vector<int> > F(N, vector<int>(10));
    for(int i=0; i<N; i++){
        for(int j=0; j<10; j++){
            cin >> F.at(i).at(j);
        }
    }
    vector< vector<long> > P(N, vector<long>(11));
    for(int i=0; i<N; i++){
        for(int j=0; j<11; j++){
            cin >> P.at(i).at(j);
        }
    }

    long m = -10000000000;
    for(int i=1; i<1024; i++){
        long r = 0;
        for(int j=0; j<N; j++){
            int t = i;
            int c = 0;
            for (int k=0; k<10; k++){
                if(t % 2 == 1 && F.at(j).at(k) == 1){
                    c++;
                }
                t = t >> 1;
            }
            r += P.at(j).at(c);
        }
        m = max(m, r);
    }
    cout << m << endl;
}


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);

		int d = sc.nextInt();
		int t = sc.nextInt();
		int s = sc.nextInt();

		if(d <= t*s) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 35732
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <list>
#define rep(i,n) for(int i=0; i<n; ++i)
using namespace std;

int main() {
    int n, count = 0;
    cin >> n;
    int l[n];
    rep(i,n) cin >> l[i];
    sort(l, l+n, greater<>());
    
    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[k]) ++count;
        else break;
    }
    cout << count << endl;
    return 0;
}



Measured memory_bytes: 256
import time
_s = time.time()

import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

from numba import njit


def getInputs():
    D = int(readline())
    CS = np.array(read().split(), np.int32)
    C = CS[:26]
    S = CS[26:].reshape((-1, 26))
    return D, C, S


@njit('(i8, i4[:], i4[:, :], i4[:], )', cache=True)
def _compute_score1(D, C, S, out):
    score = 0
    last = np.zeros(26, np.int32)
    for d in range(len(out)):
        i = out[d]
        score += S[d, i]
        last[i] = d + 1
        score -= np.sum(C * (d + 1 - last))
    return last, score


def _update_score():
    pass

@njit('(i8, i4[:], i4[:, :], i4[:], i8, )', cache=True)
def _random_update(D, C, S, out, score):
    d = np.random.randint(0, D)
    q = np.random.randint(0, 26)
    p = out[d]

    if p == q:
        return out, score

    out[d] = q
    _, new_score = _compute_score1(D, C, S, out)
    if score < new_score:
        score = new_score
    else:
        out[d] = p

    return out, score


@njit('(i8, i4[:], i4[:, :], i4[:], i8, i8, )', cache=True)
def _random_swap(D, C, S, out, score, delta):
    d1 = np.random.randint(0, D)
    d2 = np.random.randint(max(0, d1 - delta), min(D, d1 + delta))
    #p, q = out[[d1, d2]]
    p = out[d1]
    q = out[d2]

    if d1 == d2 or p == q:
        return out, score

    #out[[d1, d2]] = (q, p)
    out[d1] = q
    out[d2] = p
    _, new_score = _compute_score1(D, C, S, out)
    if score < new_score:
        score = new_score
    else:
        #out[[d1, d2]] = (p, q)
        out[d1] = p
        out[d2] = q

    return out, score



def step1(D, C, S):
    out = []
    LAST = 0
    for d in range(D):
        max_score = -10000000
        best_i = 0
        
        for i in range(26):
            out.append(i)
            last, score = _compute_score1(D, C, S, np.array(out, np.int32))
            if max_score < score:
                max_score = score
                LAST = last
                best_i = i
            out.pop()

        out.append(best_i)

    return np.array(out), LAST, max_score


def step2(D, C, S, out, score):
    while time.time() - _s <= 1.9:
        flag = np.random.rand() >= 0.5
        out = out.astype(np.int32)

        if flag:
            out, score = _random_update(D, C, S, out, score)
        else:
            out, score = _random_swap(D, C, S, out, score, 13)

    return out, score


def output(out):
    out += 1
    print('\n'.join(out.astype(str).tolist()))


D, C, S = getInputs()
out, _, score = step1(D, C, S)
#print(score)
out, score = step2(D, C, S, out, score)
output(out)
#print(score)

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

using namespace std;



int main(){
    
    int N;
    cin >> N;
    vector<int> h(N+1);
    h[N] = 0;
    int hh = 0;
    
    for (int i = 0; i < N; i++) {
        cin >> h[i];
        if (hh < h[i]) {
            hh = h[i];
        }
    }
    
    int ans = 0;
    
    for (int i = 1; i <= hh; i++) {
        
        for (int j = 0; j <= N; j++) {
            if (h[j] >= i && h[j+1] < i) {
                ans += 1;
            }
            
        }  
    }
    
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#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>;
const int INF=1000000007;

int main() {
  ll n;
  cin >> n;
  ll ans = 2*(n/11);
  if(n%11!=0&&n%11<=6) ans++;
  else if(n%11>6) ans+=2;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio> 
#include<algorithm>
using namespace std;
long long a[100000],b[100000];
long long dp=0;
int main()
{
	int n;
	long long h;
	cin>>n>>h;
	
	for(int i=0;i<n;i++)
	{
		cin>>a[i]>>b[i];
	}
	sort(a,a+n);
	sort(b,b+n);
	long long j=n;
	while(h>0)
	{	if(j<1)
		{
		if(h%a[n-1]==0)
			dp+=h/a[n-1];
			else dp+=h/a[n-1]+1;
			h=0;
			} 
		if(a[n-1]>=b[j-1])
		{
			if(h%a[n-1]==0)
			dp+=h/a[n-1];
			else dp+=h/a[n-1]+1;
			h=0;
		}
		else
		{
			h-=b[--j];
			dp++;
		}
			
	}
	cout<<dp<<endl;
	return 0; 
} 

Measured memory_bytes: 1792
n = int(input())
h_list = list(map(int, input().split()))

count = 0
max_count = 0

for i in range(n-1):
    if h_list[i] >= h_list[i+1]:
        count += 1
        if count > max_count:
            max_count = count
    else:
        count = 0
print(max_count)

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

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

    ll n,k; cin>>n>>k;
    vector<ll> a(100005);
    for(int i=0; i<n; i++) {
        int x,y; cin>>x>>y;
        a[x] += y;
    }
    ll c=0;
    for(int i=0; i<100005; i++) {
        c += a[i];
        if(c>=k) {
            cout<<i;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
# coding: utf-8


def main(N):
    a, b = N.split()
    a = int(a)
    b = int(b)
    if a > 9 or a < 1:
        return -1
    if b > 9 or b < 1:
        return -1
    return a*b

if __name__ == "__main__":
    N = input()
    my_ans = main(N)
    print(my_ans)


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

int a[10][2];
int main() {
  int D,G;
  cin>>D>>G;
  rep(i,D){
    cin>>a[i][0]>>a[i][1];
  }
  long long mins=INF;
  rep(bit,1<<D){
    long long mons=0;
    long long tens=0;
    rep(i,D){
      if(bit>>i&1){
        mons+=a[i][0];
        tens+=a[i][1]+100*(i+1)*a[i][0];
      }
    }
    if(tens>=G){
      mins=min(mins,mons);
    }
      rep(j,D){
        long long mons1=mons;
        long long tens1=tens;
        if(!(bit>>(D-j-1)&1)){
          rep(i,a[D-j-1][0]){
            if(tens1>=G){
              mins=min(mins,mons1);
              break;
            }
            mons1++;
            tens1+=100*(D-j);
          }
          break;
        }
      }
    }
  cout<<mins<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

/**
 * https://abc113.contest.atcoder.jp/tasks/abc113_c
 */
public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int N = in.nextInt();
        int M = in.nextInt();
        List<Data> data = new ArrayList<>(M);
        for (int i = 0; i < M; i++) {
            data.add(i, new Data(in.nextInt(), in.nextInt(), 1, i));
        }
        Collections.sort(data, Data.BY_Y);
        Collections.sort(data, Data.BY_P);
        for (int i = 1; i < M; i++) {
            if (data.get(i).p == data.get(i - 1).p) {
                data.get(i).id = data.get(i - 1).id + 1;
            }
        }
        Collections.sort(data, Data.BY_ORIG);
        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < M; i++) {
            // System.out.println(data.get(i).getAns()); TLE
            ans.append(data.get(i).getAns()).append("\n");
        }
        System.out.println(ans);
    }

    private static class Data {
        private int p, y, id, orig;
        private static final Comparator<Data> BY_P = (o1, o2) -> Integer.compare(o1.p, o2.p);
        private static final Comparator<Data> BY_Y = (o1, o2) -> Integer.compare(o1.y, o2.y);
        private static final Comparator<Data> BY_ORIG = (o1, o2) -> Integer.compare(o1.orig, o2.orig);

        private Data(int p, int y, int id, int orig) {
            this.p = p;
            this.y = y;
            this.id = id;
            this.orig = orig;
        }

        private String getAns() {
            return String.format("%06d%06d", p, id);
        }
    }
}


Measured memory_bytes: 153688
#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(){
 string s;
  cin >> s;
  if(s.at(1) == 'B') cout << "ARC" << endl;
  else cout << "ABC" << endl;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>

using namespace std;

const int N = 111111;

int a[N];
long long pre[N];
long long suf[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    pre[i] = pre[i - 1] + abs(a[i - 1] - a[i]);
  }
  for (int i = n; i > 0; --i) {
    suf[i] = suf[i + 1] + abs(a[i + 1] - a[i]);
  }
  for (int i = 1; i <= n; ++i) {
    printf("%lld\n", pre[i - 1] + abs(a[i - 1] - a[i + 1]) + suf[i + 1]);
  }
  return 0; 
}

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

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    // take one tasty antidote + one tasty poison = +2 each
    int D = min(B,C);
    int sum = 0;
    sum += 2*D;
    B -= D;
    C -= D;
    //printf("%d %d %d. %d tasty cookies\n", A,B,C,sum);
    // take one untasty antidote + one tasty poison = +1 each
    int E = min(A,C);
    sum += E;
    A -= E;
    C -= E;
    //printf("%d %d %d. %d tasty cookies\n", A,B,C,sum);
    // can you still take one tasty poison?
    if (C>0) {
        C--;
        sum++;
    }
    // take the rest of the untasty antidotes & tasty antidotes, if no more poison
    sum += B;
    A = 0;
    B = 0;
    //printf("%d %d %d. %d tasty cookies\n", A,B,C,sum);
    cout << sum << '\n';
}


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

int main(){
    ll l,r;
    cin>>l>>r;
    
    ll a = r/M - (l-1)/M;
    
   if(a>0){
        cout<<0;
        return 0;
    }
    
   ll ans  = M;
   for(int i = l; i <= r ; i++)
       for(int j = i+1; j <=r ; j++){
           ll t= i%M * j%M;
            ans = min(ans,t%M);
       }
   
   cout<<ans;
}


Measured memory_bytes: 256
def perfect_swap():
    global n, a, b, cost
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            ai, aj = a[i], a[j]
            if ai == b[j] and aj == b[i]:
                a[i], a[j] = aj, ai
                cost += ai + aj


def lowest_swap():
    global n, a, b, cost
    for i in range(n - 1):
        bi, tmp_cost, count = b[i], 0, 0
        while a[i] != bi:
            si = a.index(bi)
            bsi = b[si]
            sj = a.index(bsi)
            a[si], a[sj] = bsi, bi
            tmp_cost += bi + bsi
            count += 1
        if count:
            if i:
                b0 = b[0]
                cost += min(tmp_cost, (bi + b0) * 2 + tmp_cost - (bi - b0) * count)
            else:
                cost += tmp_cost


n, a, cost = int(input()), list(map(int, input().split())), 0
b = sorted(a)
perfect_swap()
lowest_swap()
print(cost)

Measured memory_bytes: 7832
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<int,vector<int>,greater<int>> que;


llint k,n;

void solve(){
	cin >> k >> n;
	llint a[n];
	llint ans=0;
	for(int i=0;i<n;i++)cin >> a[i];
	llint x=0;
	for(int i=0;i<n-1;i++)x=max(a[i+1]-a[i],x);
	x=max(x,a[0]+k-a[n-1]);
	cout << k-x << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		if(T[0] * A[0] + T[1] * A[1] == T[0] * B[0] + T[1] * B[1]){
			Console.WriteLine("infinity");
			return;
		}
		if(A[0] > B[0] && A[1] > B[1]){
			Console.WriteLine(0);
			return;
		}
		if(A[0] < B[0] && A[1] < B[1]){
			Console.WriteLine(0);
			return;
		}
		if(A[0] > B[0]){
			var t = A; A = B; B = t;
		}
		
		
		long U = A[0] * T[0] + A[1] * T[1] - (B[0] * T[0] + B[1] * T[1]);
		if(U < 0){
			Console.WriteLine(0);
			return;
		}
		
		long tot = 0;
		long t1 = (B[0] * T[0] - A[0] * T[0]) / U + 1; 
		long t2 = (B[0] * T[0] - A[0] * T[0]) / U; 
		tot += t1 + t2;
		if((B[0] * T[0] - A[0] * T[0]) % U == 0) tot--;
		Console.WriteLine(tot);
		
	}
	long[] T,A,B;
	public Sol(){
		T = rla();
		A = rla();
		B = rla();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

int main(){
    string s;
    cin >> s;
    for(int i=0;i<(s.size()+1)/2;++i){
        if(s[i] != s[s.size()-i-1]){
            cout << "No" << endl;
             return 0;
        } 
    }
    for(int i=0;i<(s.size()-1)/2;++i){
        if(s[i] != s[(s.size()-1)/2 -1-i]){
             cout << "No" << endl;
             return 0;
        }
    }
    for(int i=0;i<(s.size()-1)/2;++i){
        if(s[i + (s.size()+3)/2 -1] != s[s.size()-i-1]){
             cout << "No" << endl;
             return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
h=LI()
count=0
counter=[]
for i in range(n-1):
    if h[i]>=h[i+1]:
        count+=1
    else:
        counter.append(count)
        count=0
counter.append(count)
#print(counter)
print(sorted(counter)[-1])

Measured memory_bytes: 14636
//DEEPANSHU RAWAT
//BTECH/10530/18
//INFORMATION TECHNOLOGY

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
 */
/*************************************************************************************************************************/
#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi LLONG_MAX
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define e endl
#define mod 1000000007
#define modd 20000
using namespace std ;
/**************************************************************************************************************************/

/**************************************************************************************************************************/
int main()
    {
        ios_base::sync_with_stdio(false);//FOR FAST INPUT OUTPUT METHOD
        cin.tie(NULL);
        cout.tie(NULL);
       
        lld n,m;
        cin>>n>>m;
        cout<<((n)*(n-1))/2 + ((m)*(m-1))/2;
}
       
/**************************************************************************************************************************/                            

Measured memory_bytes: 256
n,m=map(int,input().split())
h=list(map(int,input().split()))
k=[0]*n

for i in range(m):
    a,b=map(int,input().split())
    if h[a-1]==h[b-1]:
        k[a-1]=1
        k[b-1]=1
    else:
        if h[b-1]>h[a-1]:
            k[a-1]=1
        else:
            k[b-1]=1

print(k.count(0))

Measured memory_bytes: 19964
A = list(str(input()))
B = list(str(input()))
C = list(str(input()))
a_len = len(A)
b_len = len(B)
c_len = len(C)
next = "a"

while a_len>=0 and b_len>=0 and c_len>=0:
    if next=="a":
        if a_len>=1:
            next = A[0]
            del A[0]
        a_len -= 1
    elif next=="b":
        if b_len>=1:
            next = B[0]
            del B[0]
        b_len -= 1
    else:
        if c_len>=1:
            next = C[0]
            del C[0]
        c_len -= 1
print(next.upper())

Measured memory_bytes: 3064