akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
#define rept(i,L,R) for(int i=(L);i<(R);i++)
#define isc(n) scanf("%d",&n)
#define llsc(n) scanf("%lld",&n)
#define dsc(n) scanf("%lf",&n)
#define enl cout<<endl
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define xx first
#define yy second
typedef long long ll;
typedef pair<int,int>PI;
typedef pair<pair<int,int>,int>PII;

const int mx=1e5+10;
ll vis[mx];
vector<PI>adj[mx];

int main()
{
	int n,m,l,r,w;
	isc(n);isc(m);
	rept(i,0,m)
	{
		isc(l);isc(r);isc(w);
		adj[l].PB(MP(r,w));
		adj[r].PB(MP(l,-w));
	}
	rept(i,0,mx)vis[i]=-2e9;
	int flag=1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]!=-2e9)continue;
		vis[i]=0;
		queue<int>temp;
		temp.push(i);
		while(!temp.empty())
		{
			int kp=temp.front();
			temp.pop();
			//cout<<"=== "<<kp<<" ==="<<endl;
			for(PI p:adj[kp])
			{
				if(vis[p.xx]!=-2e9)
				{
					//cout<<kp<<" "<<p.xx<<" "<<p.yy<<endl;
					//cout<<vis[p.xx]<<" "<<vis[kp]<<endl;
					if(vis[p.xx]-vis[kp]!=p.yy)
					{
						flag=0;
						break;
					}
				}
				else
				{
					vis[p.xx]=vis[kp]+p.yy;
					temp.push(p.xx);
				}
			}
			if(!flag)break;
		}
		if(!flag)break;
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 9728
#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>;

vector<int> to[100005];
int n;

vector<int> dist;
void dfs(int v, int d=0, int p=-1){
  dist[v] = d;
  for(int u: to[v]){
    if(u==p) continue;
    dfs(u, d+1, v);
  }
}
vector<int> calcDist(int s){
  dist = vector<int> (n);
  dfs(s);
  return dist;
}

int main() {
  int s, t;
  cin >> n >> s >> t;
  --s; --t;
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  vector<int> distS = calcDist(s);
  vector<int> distT = calcDist(t);
  int mx = 0;
  rep(i, n){
    if(distS[i] < distT[i]){
      mx = max(mx, distT[i]);
    }
  }
  int ans = mx-1;
  cout << ans << endl;
  return 0;
}


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


int main(){
  ll N,ans=0;
  cin >> N;
  vector<ll> L(N);
  rep(i,0,N) cin >> L[i];
  sort(L.begin(), L.end());
  rep(i,0,N){
    rep(j,i+1,N){
      rep(k,j+1,N){
        if(L[k]<L[j]+L[i] && L[k]!=L[j] && L[i]!=L[j] && L[i]!=L[k])ans++;
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3628
import copy
N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0,0)
dist = 0
for j in range(N+1):
    dist += abs(A[j]-A[j+1])
for j in range(N):
    res = dist + abs(A[j+2]-A[j]) - abs(A[j+1]-A[j]) - abs(A[j+2]-A[j+1])
    print(res)


Measured memory_bytes: 14816
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, a, b, c, total;
  cin >> N;
  total = 0;
  
  for(int i = 1;i <= N;i++){
    for(int j = 1;j <= N;j++){
      for(int k = 1;k <= N;k++){
      a = i; b = j; c = k; 
        while(1) {
          if(a < b) swap(a, b);
          if(!b) break;
          a %= b;
       }
        while(1) {
          if(a < c) swap(a, c);
          if(!c) break;
          a %= c;
       }
      total = total + a;        
      }
    }
  }
  cout << total << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>

using namespace std;

const int MAXN = 1000000 + 1000;
const int MOD = 998244353;

int n, m;

int fac[MAXN], ifac[MAXN];

int fpow(int x, int p)
{
	int ret = 1;
	for(; p; p >>= 1, x = (long long)x * x % MOD)
		if(p & 1)
			ret = (long long)ret * x % MOD;
	return ret;
}

int inv(int x)
{
	return fpow(x, MOD - 2);
}

int get_c(int n, int m)
{
	if(n < 0 || m < 0 || n < m)
		return 0;
	return (long long)fac[n] * ifac[m] % MOD * ifac[n - m] % MOD;
}

void init()
{
	fac[0] = 1;
	for(int i = 1; i < MAXN; i++)
		fac[i] = (long long)fac[i - 1] * i % MOD;
	ifac[MAXN - 1] = inv(fac[MAXN - 1]);
	for(int i = MAXN - 2; i >= 0; i--)
		ifac[i] = (long long)ifac[i + 1] * (i + 1) % MOD;
}

int main()
{
	ios::sync_with_stdio(false);
	// freopen("1.in", "r", stdin);
	// freopen("1.out", "w", stdout);

	cin >> n >> m;
	init();
	if(n > m)
		swap(n, m);
	int ans = 0;
	for(int i = 1; i <= n; i++)
		ans = (ans + (long long)get_c(n + m - 2 * i, n - i) * get_c(2 * i, i)) % MOD;
	ans = (long long)ans * inv(2) % MOD;
	ans = (long long)ans * inv(get_c(n + m, n)) % MOD;
	ans = (ans + m) % MOD;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8192
import std.stdio;
import std.string;
import std.conv;
import std.bigint;
import std.typecons;
import std.algorithm;
import std.array;
import std.math;
 
void main() {
    auto N = readln.chomp.to!real;
    writeln(cast(ulong)(floor(sqrt(N)) ^^2));
}


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

#define debug(x) cerr << x << " = "(x) << endl;
#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int n,k;
    cin >> n >> k;
    bool snk[n] = {};
    rep(i,0,k){
        int d; cin >> d;
        rep(j,0,d){
            int tmp;
            cin >> tmp;
            tmp--;
            snk[tmp] = true;
        }
    }
    int ans = 0;
    rep(i,0,n){
        if(!snk[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
int main()
{
    long a,b;
	while(scanf("%ld%ld",&a,&b)!=EOF){
		long sum=a+b;
		int count=0;
		while(sum>0){
			sum=sum/10;
			count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define REPS(i, m, n) for (int i = (m); i <= (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define rreps(i, x) for (int i = (int)(x); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { fill( (T*)array, (T*)(array+N), val ); }
template <class T1, class T2, class Pred = std::less<T2> >
struct sort_pair_second {
    bool operator()(const std::pair<T1,T2>&left, const std::pair<T1,T2>&right) {
        Pred p;
        return p(left.second, right.second);
    }
};

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

    int h, m, h2, m2, k;
    cin >> h >> m >> h2 >> m2 >> k;
    int time = h * 60 + m;
    int time2 = h2 * 60 + m2;
    int ans = time2 - time - k;
    cout << ans << endl;
    return 0;
}

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

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 998244353
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 200005;
const int MAX_M = 200005;

int N, M;
struct Input {
  int l,r,x;
};

using II = pair<int, int>;

Input inputs[MAX_M];
vector<int> add[MAX_N];
vector<II> del[MAX_N];

#define MAX_SEG (2 << 20)

struct Node{
  int sum;
  int delay;
  bool delayFlag;
  Node(){
    sum = delay = delayFlag = 0;
  }
};

int n;
Node seg[2*MAX_SEG];

//セグメントツリーの要素数の設定
void Init(int _n){
  n = 1;
  while(_n > n)
    n *= 2;
}

//遅延値の評価
inline void DelayEvaluate(int k, int a, int b){

  //遅延評価フラグが立っていないなら遅延評価を行わない
  if(!seg[k].delayFlag)
    return;

  //現在の値を遅延値に基づいて更新
  seg[k].sum += seg[k].delay;
  
  //今見ているノードに子がある場合
  if(k < n-1){
    //遅延値を子に伝播させる
    seg[2*k+1].delay += seg[k].delay;
    seg[2*k+2].delay += seg[k].delay;
    //遅延評価フラグを立てる
    seg[2*k+1].delayFlag = seg[2*k+2].delayFlag = true;
  }

  //遅延評価を行ったので自分の遅延値等は初期化しておく
  seg[k].delay = seg[k].delayFlag = 0;

}

//ノードkの値の計算
//子の値が計算終了していることが前提
inline void UpdateNode(int k){
  seg[k].sum = max(seg[2*k+1].sum, seg[2*k+2].sum);
}

//[l,r)の範囲一様にvを加算する
void UpdateRange(int l, int r, int v, int k = 0, int a = 0, int b = n){

  //とりあえず遅延計算
  DelayEvaluate(k,a,b);
  
  //見ているノードが[l,r)と全く被っていない場合
  if(b <= l || r <= a){
    return;
  }
  //完全に被っている場合
  else if(l <= a && b <= r){
    seg[k].delay += v;
    seg[k].delayFlag = true;
    DelayEvaluate(k,a,b);
    return;
  }
  //ちょい被りの場合
  else{
    int mid = (a+b)/2;
    UpdateRange(l,r,v,2*k+1,a,mid);
    UpdateRange(l,r,v,2*k+2,mid,b);
    UpdateNode(k);
    return;
  }

}

//[l,r)の値の合計を出力する
int Query(int l, int r, int k = 0, int a = 0, int b = n){

  //とりあえず遅延計算
  DelayEvaluate(k,a,b);

  //今見ているノードが[l,r)と全く被っていない場合
  if(b <= l || r <= a)
    return -1145141919810;
  //完全に被っている場合
  else if(l <= a && b <= r){
    return seg[k].sum;
  }
  //ちょい被りの場合
  else{
    int vl,vr;
    int mid = (a+b)/2;
    vl = Query(l,r,2*k+1,a,mid);
    vr = Query(l,r,2*k+2,mid,b);
    return max(vl,vr);
  }

}


signed main()
{
  cin >> N >> M;
  Init(N);
  REP(m,M) {
    Input& n = inputs[m];
    cin >> n.l >> n.r >> n.x;
    add[n.l].emplace_back(n.x);
    del[n.r].emplace_back(II(n.l, n.x));
  }

  int ans = 0;
  FOR(n,1,N+1) {
    for(int x : add[n]) {
      UpdateRange(0,n,x);
    }
    int ma = Query(0,n);
    ans = max(ans, ma);
    UpdateRange(n,n+1,ma);
    for(auto p : del[n]) {
      UpdateRange(0,p.first,-p.second);
    }
    // cerr << n << ": " << ma << endl;
    // REP(nn,N+1) {
    //   cerr << Query(nn,nn+1) << " ";
    // }
    // cerr << endl;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 125056
#include <iostream>
#include <cmath>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <cstring>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair < int, int >
#define pll pair < long long, long long>
#define ull unsigned long long
#define vi vector < int >
#define vll vector < long long >
#define sz(a) (int)a.size()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x))
#define fname "searching"

const int inf = (int)1e9;
const ll INF = (ll)1e18;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int mod = (int)1e9 + 7;

int n, k;
int a[200200];
vector<pii> v;

int solve(){
    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> a[i];
    sort(a, a + n);
    int cnt = 1;
    for(int i = 1; i <= n; ++i){
        if(a[i - 1] == a[i]) cnt++;
        else{
            v.pb(mp(cnt, a[i - 1]));
            cnt = 1;
        }
    }
    sort(all(v));
    // for(int i = 0; i < sz(v); ++i){
    //     cout << v[i].f << " " << v[i].s << "\n";
    // }
    if(sz(v) <= k) return 0;
    int sum = 0;
    for(int i = 0; i < sz(v); ++i){
        sum += v[i].f;
        if(sz(v) - i - 1 <= k) break;
    }
    return sum;
}

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

    cout << solve() << "\n";
    
    return 0;
}

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{
    int k,a,b;
    int f = 0;
    // 整数の入力
    scanf("%d", &k);
    // スペース区切りの整数の入力
    scanf("%d %d",&a,&b);
  	
  	int i;
  	for(i=1; k*i <= b; i++){
    	if(a <= k*i && k*i <= b){
        	f = 1;
          	break;
        }
    }
  
  	if(f){
    	puts("OK");
    }else{
    	puts("NG");
    }
  	
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll A,B,C,ans;
  cin >> A>>B>>C;
  ans = min(C,B/A);
  cout << ans<< endl;
  return 0;
}

Measured memory_bytes: 764
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
int main()
{
	string s;
	cin >> s;
	int f[26] = {};
	for (int i = 0; i < s.size(); ++i)
		++f[s[i] - 'a'];
	ll res = s.size()*(ll)(s.size() - 1) / 2 + 1;
	for(int i=0;i<26;++i)
		res -= f[i] * (ll)(f[i] - 1) / 2;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.ArrayList;
import java.util.Scanner;
class Main{


	static final int MOD = 1000000007;


	static int ans = 0;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();

		int[] b = new int[n];
		
		for(int i= 0;i < n-1;i++){
			b[i] = sc.nextInt();
		}
		if(n == 2){
			System.out.println(2*b[0]);
			return;
		}
		int[] a = new int[n];

			a[0] = b[0];
		

		int ans = a[0];
		for(int i = 0;i < n-1;i++){
			if(b[i] < b[i+1]){
				a[i+1] = b[i];
				ans += b[i];
			}else{
				a[i+1] = b[i+1];
				ans += b[i+1];
			}
			
		}
		ans += b[n-2];

		

		System.out.println(ans);









	}
	
	
	static void sieve(ArrayList<Long> list){
		int n = 50000000;
		boolean[] is_prime = new boolean[n+1];
		int[] prime = new int[n];
		for(int i= 0;i <=n;i++){
			is_prime[i] = true;
		}
		list.add((long) 1);
		for(int i = 2;i <= n;i++){
			if(is_prime[i]){
				list.add((long)i);
				for(int j = 2*i;j <= n;j+=i){
					is_prime[j] = false;
				}
			}
		}



	}




	static int upperbond(int k,int min,int[] data){		//kより小さい最大の値をdataの中から探し、返す二分探索
		int max = data.length;
		//		if(min == data.length-1){
		//			if(data[min] > k){
		//				return min;
		//			}
		//		}

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}

		return max;
	}

	static int lowerbond(int k,int min,int[] data){		//kより大きい最小の値をdataの中から探し、返す二分探索
		int max = data.length;

		while(max-min > 1){
			int mid = (max+min)/2;
			if(data[mid] >= k){
				max = mid;
			}else{
				min = mid;
			}
		}
		return min;
	}



	static int gcd(int a,int b){				//最大公約数を返す
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}
	static long gcd(long a,long b){
		if(b == 0){
			return a;
		}else{
			return gcd(b, a%b);
		}
	}



	static long lcm (long a, long b) {
		long g = gcd(a,b);
		return a/g*b;
	}




}

class Town{
	int index;
	int x ;
	int y;
	public Town(int index,int x,int y) {
		this.index = index;
		this.x = x;
		this.y = y;
		// TODO 自動生成されたコンストラクター・スタブ
	}


}


class Edge extends ArrayList<P>{

}

class P{
	int to;
	long cost;
	P(int to,long cost){
		this.to = to;
		this.cost = cost;
	}
}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return   from- otherpair.from;
	}








}






Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include<cstdlib>
using namespace std;
int main(){
  vector<int>S={1,2,3,4,5,6,7,8,9,10,12,14,16,18,15,21,24,27,32,28,36,20,25,30,35,40,45,36,42,48,54,49,56,63,64,72,81} ;
  	int N; cin>>N;
  int K=0;
  for(int i=0; i<S.size(); i++){
    if(N==S.at(i))
      K++;
    else continue;
  }
  if(K!=0)
    cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

int main(){

    int n; cin >> n;

    int ans = 0;
    for(int x = 1; x <= n; x++){

        //約数の個数
        int cnt = 0;
        for(int i = 1; i <= x; i++){
            //割り切れたらインクリメント
            if(x % i == 0) cnt++; 
        }

        //約数の個数が丁度 8 なら ans をインクリメント
        if(cnt == 8 && x % 2 == 1) ans++;
    }

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

Measured memory_bytes: 256
N = int(input())
xv = []
for i in range(N):
  x,v = input().split()
  if v == "BTC":
    x=float(x)
  else:
    x=int(x)
  xv.append([x,v])
dama=0
for i in range(N):
    if xv[i][1] == "JPY":
        dama+=xv[i][0]
    else:
        dama+=xv[i][0]*380000.0
print(dama)

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()

int main() {
    int a, b;
    cin >> a >> b;
    int d = b - a;
    cout << (d + 1)*d/2 - b << endl;
    return 0;
}


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

const int MAXN = 100100;
long long int n, k;
long long int h[MAXN];
long long int dp[MAXN];


int main() {

  cin >> n >> k ;
  for (int i = 0; i < n; i++) {
    scanf("%d", &h[i]);
  }

  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);

  for (int i = 2; i < n; i++) {
    dp[i] = (1LL << 60);
    for (int j = 1; j <=k; j++) {
      if (j > i) continue;
      dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }

  }
  cout << dp[n - 1];

}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define dd double
#define MOD1 1000000007
#define MOD2 998244353
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<ll,ll> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m,ll MOD){if(m==0)return 1;ll t=mpowe(n,m/2,MOD);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;if(n==0) return -1;return logtwo(n/2)+1;}
int main()
{
    fastio();
   
    ll n;
    cin>>n;
    std::vector<pair<int,int>> v(n);
    int f=0;
    for(int i=0;i<n;i++)
    {
        cin>>v[i].ff>>v[i].ss;
    }
    for(int i=2;i<n;i++)
    {
        if(v[i].ff==v[i].ss && v[i-1].ff==v[i-1].ss && v[i-2].ff==v[i-2].ss)
            f=1;
    }
    if(f==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    
}

Measured memory_bytes: 3640
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Diagnostics;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{
    
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N, Y;
        
        
        public static void Input()
        {
            var cin = new Solve();

            var input = cin.SplitReader();
            N = input[0];
            Y = input[1];
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            
            for(var i = 0; i <= N; i++)
            {
                for(var j = 0; j <= N - i; j++)
                {
                    int res = Y - 10000 * i - 5000 * j;
                    if (res >= 0 && res % 1000 == 0 && res / 1000 == N - i - j)
                    {

                        Console.WriteLine($"{i} {j} {N - i - j}");
                        
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");

            //Console.Out.Flush();
        }

        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    
}



Measured memory_bytes: 13268
N = int(input())
ST = list()
for _ in range(N):
  ST.append(list(input().split()))

X = input()
time = 0
play = 0
for i in range(N):
  if play==0:
    if play==0 and ST[i][0] == X:
      play = 1
    continue
  time += int(ST[i][1])
  
print(time)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int dp[100005];
int n;
int a[100005];
int cal(int k){
    if(dp[k]!=-1)
        return dp[k];

    for(int i=0;i<n;i++){
        if(a[i]<=k){
            if(cal(k-a[i])==2) {
                dp[k] = 1;
                return dp[k];
            }
        }

    }
    dp[k]=2;
    return dp[k];
}
void solve(){
    int k;
    cin>>n>>k;

    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    dp[0]=2;
    dp[k]=cal(k);
    if(dp[k]==1)
        cout<<"First"<<endl;
    else cout<<"Second"<<endl;

}
int main(){

    solve();
}


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

int main(){
  int a,b,c,x,ans;
  ans=0;
  cin>>a>>b>>c>>x;
  for(int i=0;i<=a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(i*500 + j*100 + k*50 == x) ans++;
      }
    }
  }
  cout << ans << endl;
}

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

#define ll long long int
#define endl '\n'
ll const mod = 1e9 + 7;


int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin>>n;
    
    ll s=0;
    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            s+=i;
    }
    
    cout<<s;
    
	// your code goes here
	return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	double ans=0.0;
	cin >>n;
	vector<pair<int,int>>xy(n);
	int patten = 1;
	rep(i,n){
		cin>>xy[i].F>>xy[i].S;
		patten*=(i+1);
	}
	sort(all(xy));
	pair<int,int>at;
	do{
		at=mp(0,0);
		for(auto itr=xy.begin();itr!=xy.end();itr++){
			if(itr!=xy.begin()){
				ans+=hypot(at.F-(itr->F),at.S-(itr->S));
			}
			at=(*itr);
		}	
	}while(next_permutation(all(xy)));

	printf("%.9lf\n",ans/patten);
}

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

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int a, b, k;
   set<int> vc;
   cin >> a >> b >> k;
   for(int i = a;i<=b;i++) {
      if(a+k>i||b-k<i) {
         vc.insert(i);
      }
   }
   // sort(vc.begin(), vc.end());
    for(auto itr = vc.begin(); itr != vc.end(); ++itr) {
        cout << *itr << "\n";      
    }
   
   return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int a[105];
int main()
{
    int n,sum3,sum=0;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    sum3=sum;
    sum/=2;
    int ans,x=66666;
    int sum1=0,sum2,c;
    for(int i=1; i<=n; i++)
    {
        sum1+=a[i];
        c=abs(sum-sum1);
        if(x>c)
        {
            x=c;
            sum2=sum1;
        }

    }

 printf("%d\n",abs(sum2-(sum3-sum2)));




    return 0;
}


Measured memory_bytes: 128
n=int(input())
h=list(map(int, input().split()))
dp=[0]*n
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 13928
#include <bits/stdc++.h>
#include <algorithm>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>
#include <math.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> pbds;
#define vll vector<ll> 
#define nl cout << endl
#define fr(a,b) for(auto i=a;i<b;i++)
#define pll pair<ll,ll>
#define f first
#define s second
#define vpll vector<pll>
#define ump unordered_map
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define IN(a,b) ((a).find(b)!=(a).end())
#define pb push_back
#define mkp make_pair
#define PI M_PI
#define INF 1e18
#define deb(x) if(ON) cout << #x <<" : " << x << endl
#define fast ios_base::sync_with_stdio(false)
#define io cin.tie(NULL),cout.tie(NULL)
#define ON !false
ll dx[]={0,-1,0,1};
ll dy[]={1,0,-1,0};
const ll mod=1e9+7;
ll i,j;
ll add(ll a,ll b){
    return  ((a%mod)+(b%mod)+mod)%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod)+mod)%mod;
}
void pause(ll id){
    cout << "Waiting " << id << endl;
    cin >> id;
}

const int mxn=1e5+10;
ll n,t;


signed main(){
    fast;
    io;
    if(!true){
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    }
    ll n;
    cin >> n;
    ll arr[n+1][3];
    ll i,j;
    for(i=0;i<=n;i++){
        for(j=0;j<3;j++){
            arr[i][j]=0;
        }
    }
    ll a,b,c;
    ll mx=-INF;
    for(i=1;i<=n;i++){
        for(j=0;j<3;j++){
            cin >> arr[i][j];
            mx=max((arr[i-1][(j+1)%3]),(arr[i-1][(j+2)%3]));
            arr[i][j]+=mx;
        }
    }
    mx=max(arr[n][0],max(arr[n][1],arr[n][2]));
    cout << mx << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x));i>=0;i--)
#define ALL(x) (x).begin(),(x).end()


void solve(long long N, std::vector<long long> a){
  long long count = 0;
  long long cur = 1;
  REP(i, N){
    if(a[i] != cur) {
      count++;
    }
    else {
      cur++;
    }

  }

  cout << ((count == N) ? -1 : count) << endl;
  return;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  std::vector<long long> a(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&a[i]);
  }
    solve(N, std::move(a));
    return 0;
}


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

namespace AtCoder.Abc
{
    class A_125_BiscuitGenerator
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long result = array[2] / array[0] * array[1];

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 28196
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<functional>
#include<string.h>
#include<vector>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<queue>
#include<deque>
#include<string>
#include<random>
#include<stack>
#include<limits.h>
using namespace std;

signed main() {
	string a; cin >> a;
	string b;
	for (char c : a) {
		if (c != 'x')b += c;
	}
	for (int i = 0; i < b.length() / 2; i++) {
		if (b[i] != b[b.length() - i - 1]) { puts("-1"); return 0; }
	}
	int sum = 0;
	vector<int>V;
	for (char i : a) {
		if (i == 'x')sum++;
		else {
			V.push_back(sum); sum = 0;
		}
	}
	V.push_back(sum);
	int ans = 0;
	for (int i = 0; i < V.size() / 2; i++) {
		ans += abs(V[i]-V[V.size() - i - 1]);
	}
	cout << ans << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c;
  cin >> a >> b >> c;
  if ((a <= c && c <= b) || (b <= c && c <= a))
    cout << "Yes" << '\n';
  else
    cout << "No" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <cassert>

#define INFLL 2000000000000000000
#define INF 2000000000
#define MOD 1000000007
#define PI acos(-1.0)

typedef std::pair <int, int> pii;
typedef long long ll;
typedef std::vector <ll> vll;

using namespace std;


int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);	
	int n;
	cin >> n;
	int arr[10];
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}
	ll ans = 0; 
	for (int i = 1; i < (1 << n); i++) {
		ll odd = 1, even = 1;
		for (int j = 0; j < n; j++) {
			if (i & (1 << j)) {
				if (arr[j] % 2 == 1) 
					even *= 2;	
			} else {
				if (arr[j] % 2 == 0) odd *= 2;
			}
		}
		ans += odd * even;
	}
	cout << ans << endl;
	return 0;
}

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

int main () {
    int A, B, C; cin >> A >> B >> C;
    bool can = true;
	
    int cnt = 0;
    
    int a = A;
    int b = B;
    int c = C;
    if (A % 2 != 0 || B % 2 != 0 || C % 2 != 0) cnt = 0;
    else {
      while (1) {

        int na = (b+c) / 2;
        int nb = (a+c) / 2;
        int nc = (a+b) / 2;
        if (na == A && nb == B && nc == C) {
            can = false;
            break;
        }
        if (a % 2 != 0 || b % 2 != 0 || c % 2 != 0) break;
        cnt++;
        a = na;
        b = nb;
        c = nc;
        cerr << cnt << endl;
      }
    }
    if (can) cout << cnt << endl;
    else cout << -1 << endl;
}

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

int main() {
	string s; cin >> s;
	deque<char>st;
	for (char c : s) {
		if (c == 'A') {
			if (st.empty() || st.back() == 'Z')st.push_back(c);
		}
		if (c == 'Z') {
			if (!st.empty() && st.back() == 'A')st.push_back(c);
		}
	}
	if (!st.empty() && st.back() == 'A')st.pop_back();
	if (st.empty())printf("-1");
	for (char c : st)cout << c;
	cout << endl;
}

Measured memory_bytes: 3336
local n = io.read("*n")
local a = {}
for i = 1, n do a[i] = io.read("*n") end
local ret = 1000000007 * 1000000007
for flag = -1, 1, 2 do
  local cur = 0
  local cnt = 0
  for i = 1, n do
    cur = cur + a[i]
    if flag < 0 then
      if 0 <= cur then
        cnt = cnt + cur + 1
        cur = -1
      end
    else
      if cur <= 0 then
        cnt = cnt - cur + 1
        cur = 1
      end
    end
    flag = flag * -1
  end
  ret = math.min(ret, cnt)
end
print(ret)


Measured memory_bytes: 2424
#include <bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define e "\n"
#define MaRiaMa { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
#define fix(n) cout << fixed << setprecision(n);
using namespace std;
int main()
{
	MaRiaMa;
	int n,i=1;
	cin >> n;
	while (pow(2, i) <= n)
	{
		i++;
	}
	cout << pow(2, i - 1);
}

Measured memory_bytes: 4296
import sys
from collections import deque

input = sys.stdin.readline
N, u, v= map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N-1)]

g = [[] for _ in range(N+1)]
for a, b in AB:
    g[a].append(b)
    g[b].append(a)

parent = [-1] * (N + 1)
children = [[] for _ in range(N+1)]
degree = [0] * (N + 1)
q = deque([v])
while len(q) > 0:
    node = q.popleft()
    node_d = degree[node]
    for i in g[node]:
        if i == parent[node]:
            continue
        parent[i] = node
        degree[i] = node_d + 1
        children[node].append(i)
        q.append(i)

ans = 0
# uができるとこまで登
tmp = (degree[u] - 1) // 2
for _ in range(tmp):
    u = parent[u]
max_deg = 0
q = deque([u])
while len(q) > 0:
    node = q.popleft()
    max_deg = max(max_deg, degree[node])
    for i in children[node]:
        q.append(i)
print(max_deg-1)


Measured memory_bytes: 110584
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);
LL n, m, x[1000000][2] = {}, ans = 0;
struct edge { int cost, to; };
int  par[100000];  // リーダーの値を格納 
int find(int x) { if (par[x] == x)return x; par[x] = find(par[x]); return par[x]; }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; par[x] = y; }
bool same(int x, int y) { return find(x) == find(y); }
vector<edge>vec[10000];
string str[2];
int main() {
	cin >> str[0] >> str[1];
	for (LL i = 0; i < str[0].size(); i++) {
		if (i > 0)
			x[i][0] = x[i - 1][0];
		x[i][0] += (str[0][i] == 'A' ? 1 : 2);
	}
	for (LL i = 0; i < str[1].size(); i++) {
		if (i > 0)
			x[i][1] = x[i - 1][1];
		x[i][1] += (str[1][i] == 'A' ? 1 : 2);
	}
	cin >> n;
	for (LL A = 0; A < n; A++) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		if ((x[b - 1][0] - (a>1 ? x[a - 2][0] : 0)) % 3 == (x[d - 1][1] - (c>1?x[c - 2][1]:0)) % 3)
			cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

bool comp(int a, int b){
    return (a<b);
}
 
int main(){
    int n; cin >> n;
    long long ans = 0;
    for(int i=1; i<=n; i++){
        if(i%3!=0 && i%5!=0) ans+=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
x, n = map(int, input().split())
p = list(map(int, input().split()))

alpha = x
if not p:
  print(x)
  exit()

for i in range(n+1):
  if alpha in p:
    alpha += (i+1)*(-1)**(i+1)
    continue
  else:
    print(alpha)
    exit()


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

int main() {
  
  vector<int> N(3);
  for(int i=0; i<3; i++){ cin >> N.at(i); }
  sort(N.begin(), N.end(), greater<int>());
  
  cout << N.at(0)*10 + N.at(1)+N.at(2) << endl;
  
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
  	Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    
    int result = 700;
    
    char[] unko = s.toCharArray();
    
    for(int i=0;i<unko.length;i++){
      if(unko[i]=='o'){
        result += 100;
      }
    }
    
    System.out.println(result);
  
  }
  
}


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

int main() {
  
  string S;
  cin >> S;
  
  if (S == "SSS") {
    cout << 0 <<endl;
  }
  else if (S == "RRR") {
    cout << 3 <<endl;
  }
  else if (S == "RRS" || S == "SRR") {
    cout << 2 <<endl;
  }
  else {
    cout << 1 <<endl;
  }

return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define f(i,n) for(int i=0; i<n; ++i)
#define fi(i,st,n) for(int i=st; i<=n; ++i)
#define veci vector<int>
#define vecp vector<pair<int,int> >
#define vecl vector<ll>
int prime[100000+10];

ll lcm(ll a, ll b) {
	return a*b/__gcd(a,b);
}

ll power(ll a, ll n, ll mod) {
	ll res = 1;
	while(n > 0) {
		if(n&1) {
			res = (res*a)%mod;
		}
		a = (a*a)%mod;
		n = n/2;
	}
	return res;
}

ll sum(int arr[], int n) {
	ll res = 0;
	f(i,n) {
		res += arr[i];
	}
	return res;
}

void seive() {
	prime[1] = 0;
	for(int i=2; i<=100000; i++) {
		prime[i] = 1;
	}
	for(ll i=2; i<=100000; i++) {
		if(prime[i]) {
			for(ll j=i*i; j<=100000; j+=i) {
				prime[j] = 0;
			}
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--){
		int n;
		cin>>n;
		ll arr[n];
		f(i,n) cin>>arr[i];
		ll curr = 1000; 
		for(int i=1; i<n; i++) {
			if(arr[i] > arr[i-1]) {
				ll temp = curr/arr[i-1];
				curr = curr%arr[i-1];
				curr += arr[i]*temp;
			}
		}
		cout<<curr<<"\n";
 	}
 	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<string>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstring>
#include<stack>
#include<functional>
using namespace std;

int main(){
	int dn[13] = {-1,31,28,31,30,31,30,31,31,30,31,30,31};
	int y1,m1,d1,y2,m2,d2;
	while(cin>>y1>>m1>>d1>>y2>>m2>>d2){
		if(y1<0 || m1<0 || d1<0 || y2<0 || m2<0 || d2<0) break;
		int ans = 0;
		for(int y=y1,m=m1,d=d1;;y++){
			if(y%4==0 && (y%100!=0 || y%400==0)) dn[2] = 29;
			else dn[2] = 28;
			for(;;){
				for(;;){
					if(y==y2 && m==m2 && d==d2) goto OUT;
					ans++;
					if(++d>dn[m]){
						d = 1; break;
					}
				}
				if(++m>12){
					m = 1; break;
				}
			}
		}
		OUT:
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1144
k, n = map(int, input().split())
a = list(map(int, input().split()))
a1 = sorted(a)
temp = list()
x = len(a)-1
for i in range(x):
    temp.append(a1[i+1]-a1[i])
temp.append(min(max(a)-min(a),k-max(a)+min(a)))
ans = k-max(temp)
print(ans)


Measured memory_bytes: 32288
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime> 
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>
#include <iomanip>
#define y1 y11
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define skip continue
#define all(x) x.begin(), x.end()
#define NAME "code"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef pair<pii, ll> piii;

const ld pi = 2 * acos(0.0);
const ll prime = 31;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 11;
const ll dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const ll dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

ll n, m, d[2][maxn], f[2][maxn], s[2], ans, cnt;

vector<pii> g[maxn];

priority_queue<pii> q;

void dijkstra(bool x){
	for(int i = 1; i <= n; ++i)
		d[x][i] = inf;

	d[x][s[x]] = 0;
	f[x][s[x]] = 1;
	q.push({0, s[x]});
	while(!q.empty()){
		ll v = q.top().sc, dist = -q.top().fr;
		q.pop();
		if(dist != d[x][v]) skip;
		for(pii to : g[v]){
			if(d[x][v] + to.sc < d[x][to.fr]){
				d[x][to.fr] = d[x][v] + to.sc;
				f[x][to.fr] = 0;
				q.push({-d[x][to.fr], to.fr});
			}
			if(d[x][to.fr] == d[x][v] + to.sc)
				f[x][to.fr] = (f[x][to.fr] + f[x][v]) % mod;
		}
	}
}

int main(){

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

cin >> n >> m >> s[0] >> s[1];

for(int i = 0, v[2], cost; i < m; ++i){
	cin >> v[0] >> v[1] >> cost;
	g[v[0]].pb({v[1], cost});
	g[v[1]].pb({v[0], cost});	
}

dijkstra(0);
dijkstra(1);

ans = (f[0][s[1]] * f[1][s[0]]) % mod;
cnt = d[0][s[1]];

for(int i = 1; i <= n; ++i){
	if(d[0][i] + d[1][i] == cnt && d[1][i] == d[0][i])
		ans = (ans - ((((f[0][i] * f[1][i]) % mod) * ((f[0][i] * f[1][i]) % mod)) % mod) + mod) % mod;
	for(pii to : g[i]){
		if(d[0][i] + d[1][to.fr] + to.sc == cnt && d[0][i] * 2 < cnt && d[1][to.fr] * 2 < cnt)
			ans = (ans - ((((f[0][i] * f[1][to.fr]) % mod) * ((f[0][i] * f[1][to.fr]) % mod)) % mod) + mod) % mod;
	}
}

cout << ans;

return 0;
}

Measured memory_bytes: 23024
#include<bits/stdc++.h>
#define int long long
using namespace std;
priority_queue<int> q;
priority_queue<int,vector<int>,greater<int> >q2;
int n,dlt,ans1,ans2,siz,rs;
signed main() {
	int opt,x,y;
	scanf("%lld",&n);
	for(register int i=1; i<=n; i++) {
		scanf("%lld",&opt);
		if(opt==1) {
			scanf("%lld%lld",&x,&y);
			dlt+=y;
			rs++;
			siz=(rs+1)/2;
			while(q.size()<siz&&q2.size()) {
				ans1+=q2.top();
				q.push(q2.top());
				ans2-=q2.top();
				q2.pop();
			}
			if(q.size()<siz) {
				q.push(x);
				ans1+=x;
				//cout<<'*';
			} else if(x<q.top()) {
				q2.push(q.top());
				ans2+=q.top();
				ans1-=q.top();
				q.pop();
				q.push(x);
				ans1+=x;
			} else {
				q2.push(x);
				ans2+=x;
			}
		} else {
			printf("%lld %lld\n",q.top(),q.top()*q.size()-ans1+ans2-q.top()*q2.size()+dlt);
		}
	}
}

Measured memory_bytes: 4920
#include<stdio.h>
#include<math.h>
int main()
{
  long int a,b,t,min,n;
  scanf("%ld",&n);
  min=n-1;
  for(a=2; a<=(sqrt(n)); a++){
    if(n%a==0){
      b=n/a;
      t=a+b-2;
      if(min>t)
        min=t;
    }
  }
  printf("%ld",min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds;
using namespace std;

typedef long long int lli;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> OrderedSet;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(auto &i : c)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define fill(a)  memset(a, 0, sizeof (a))
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }
int mul(int a, int b, int c){lli res=(lli)a*b;return (int)(res>=c?res%c:res);}
template<typename T>T power(T e, T n, T m){T x=1,p=e;while(n){if(n&1)x=mul(x,p,m);p=mul(p,p,m);n>>=1;}return x;}
int mod_neg(int a, int b, int c){int res;if(abs(a-b)<c)res=a-b;else res=(a-b)%c;return(res<0?res+c:res);}
template<typename T>T extended_euclid(T a, T b, T &x, T &y){T xx=0,yy=1;y=0;x=1;while(b){T q=a/b,t=b;b=a%b;a=t;\
t=xx;xx=x-q*xx;x=t;t=yy;yy=y-q*yy;y=t;}return a;}
template<typename T>T mod_inverse(T a, T n){T x,y,z=0;T d=extended_euclid(a,n,x,y);return(d>1?-1:mod_neg(x,z,n));}
template <class T>  inline void smax(T &x,T y){ x = max((x), (y));}
template <class T>  inline void smin(T &x,T y){ x = min((x), (y));}


int main(){
    #ifndef ONLINE_JUDGE
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    int pow, K;
    cin >> pow >> K;

    lli dp[K + 1];
    dp[K] = 1;
    lli ans = K;
    repD(i, K - 1, 1){
        int dv = (K / i);
        dp[i] = power(dv, pow, MOD);
        for(int j = i * 2; j <= K; j += i){
            dp[i] += MOD - dp[j];
            if(dp[i] > MOD){
                dp[i] -= MOD;
            }
        }
        dp[i] %= MOD;
        ans += (lli) i * dp[i];
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4392
import math

A, B, C, X, Y = map(int, input().split())
lowest = A*X + B*Y

for a in range(0, X+1):
  c = (X-a)*2
  if Y - 0.5*c < 0:
    b = 0
  else:
    b = math.ceil(Y - 0.5*c)
  if A*a + B*b + C*c < lowest:
    lowest = A*a + B*b + C*c
    
for b in range(0, Y+1):
  c = (Y-b)*2
  if X - 0.5*c < 0:
    a = 0
  else:
    a = math.ceil(X - 0.5*c)
  if A*a + B*b + C*c < lowest:
    lowest = A*a + B*b + C*c

print(lowest)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
#define dmp(x) cerr << __LINE__ << " " << #x << " " << x << endl;
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;}
template<class t,class u>
ostream& operator << (ostream& os,pair<t,u> p){
	return os << p.fi << ',' << p.sec;
}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
void fastio(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
}
int a,b,c;
int main(){
	cin >> a >> b >> c;
	if((a-c)*(b-c)<=0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int scanner1 = scanner.nextInt();
		int scanner2 = scanner.nextInt();
		int area = scanner1 * scanner2;
		int Surroundings = 2 * scanner1 + 2 * scanner2;
		System.out.println(area + " " + Surroundings);
	}
}

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define fastio ios::sync_with_stdio(false); cin.tie(0)

int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.in", "r", stdin);
    //     freopen("output.out", "w", stdout);
    // #endif
	int a, p;
	cin >> a >> p;
	cout << (a*3+p)/2 << 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++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n,m;cin >> n >> m;
    int x[m];
    rep(i,m)cin >> x[i];
    if(n >= m){
        cout << 0 << endl;
        return 0;
    }
 
    vector<int> res;
    sort(x,x+m);
    int ans = 0;
    rep(i,m-1){
        ans += x[i+1] - x[i];
        res.push_back(x[i+1] - x[i]);
    }
    sort(res.rbegin(),res.rend());
    rep(i,n-1)ans -= res[i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2168
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <list>
#include <tuple>
using namespace std;

int main() {
	char S[100000 + 1];
	int dummy, ans = 0;
	dummy = scanf("%s", S);

	char now = S[0];
	int len = strlen(S);
	for (int i = 1; i < len; i++) {
		if (now != S[i]) {
			now = S[i];
			ans++;
		}
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256