akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end());
#define VREV(v) reverse(v.begin(), v.end());
using namespace std;
using ll = long long;
using pll = pair<ll,ll>;
using vll = vector<ll>;
using vdouble = vector<double>;
using vstr = vector<string>;
typedef pair<int,int> P;
int dx[4] = {1, 0, -1, 0},dy[4] = {0, 1, 0, -1};

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

int main(){
    ll N;
	cin>>N;
	vll P(N),Q(N);
	REP(i,N) cin>>P[i];
	REP(i,N) cin>>Q[i];
	
	vll a(N);
	REP(i,N) a[i]= i+1;
  
    map<vll, ll> mp;
	do{
		mp[a] = mp.size();
	}while(next_permutation(a.begin(), a.end()));
	
	ll ans = abs(mp[P] - mp[Q]);
	cout << ans <<endl;
	return 0;
}

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

long long solve(long long N){
    if(N % 2 == 1) return 0;
    
    long long ans = 0;
    N /= 2;
    while(N){
        ans += N/5;
        N /= 5;
    }
    return ans;
}



int main(void){
    long long N; cin >> N;
    cout << solve(N) << endl;
}


Measured memory_bytes: 3564
#include<iostream>
#include<map>
#include<unordered_map>
#include<set>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long double ld;
#define mp make_pair
#define pb push_back

#define rep(i, N) for(ll i = 0; i < N; i++)
#define repa(i, a, N) for(ll i = a; i < N; i++)
#define repr(i, N) for(ll i = N-1; i >= 0; i--)

#define drep(i, N, j, M) rep(i, N) rep(j, M)
#define trep(i, N, j, M, k, L) rep(i, N) rep(j, M) rep(k, L)

#define all(A) A.begin(), A.end()

const double PI = 3.141592653589793;

// const ll mod = 1e9 + 7;
const ll mod = 998244353;

const ll LLMAX = numeric_limits<long long>::max();

void No() {
	cout << "No" << endl;
}

void Yes() {
	cout << "Yes" << endl;
}

ll id(char c) {
	return c - 'a';
}

bool isOK(vi& a, ll k, ll index) {
	return a[index] < k * (index + 1);
}

ll binary_search(vi& a, ll k) {
	ll left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	ll right = (ll)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()

	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		ll mid = left + (right - left) / 2;

		if (isOK(a, k, mid))
			right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}

template<class t, class u>
ostream& operator<<(ostream& os, const pair<t, u>& p) {
	return os << "{" << p.first << "," << p.second << "}";
}

template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
	os << "{";
	for (auto e : v)os << e << ",";
	return os << "}";
}

int main() {

	double a, b, x;
	cin >> a >> b >> x;

	double a2 = a * a;
	double L = a2 * b;

	double h;
	double angle;

	if (x >= L / 2.0) {
		h = 2.0 * (L - x) / a2;
		angle = atan(a / h);
	}
	else {
		h = 2.0 * x / b / a;
		angle = atan(h / b);
	}

	printf("%.10f", 90.0 - angle * 180.0 / PI);

	cout << 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;
using ll = long long;
using P =pair<int,int>;

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a!=c){
        cout<<1<<endl;
    }else{
        cout<<0<<endl;
    }
return 0;}
/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
def main():
    A, B, K = map(int, input().split())

    ans = set()
    n = min(A + K, B)
    for i in range(A, n):
        ans.add(i)

    n = max(B - K + 1, A)
    for i in range(n, B + 1):
        ans.add(i)

    for i in sorted(ans):
        print(i)

main()


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
K=[tuple(map(int,input().split())) for i in range(K)]
mod=998244353

DP=[0]*(4*10**5+100)
DP[1]=1
DP[2]=-1

for i in range(1,N+1):
    DP[i]+=DP[i-1]
    DP[i]%=mod
    
    for l,r in K:
        DP[i+l]+=DP[i]
        DP[i+l]%=mod
        DP[i+r+1]-=DP[i]
        DP[i+r+1]%=mod
        

    #print(DP[:10])

print(DP[N])
    


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

const int maxn=1e5+5;

int n,k;
vector<int>g[maxn];
int w[maxn];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >q;
int vis[maxn];
int flag;

void check(int x,int f)
{
	if(flag)return ;
	for(int i=0;i<(int)g[x].size();i++)
	{
		int to=g[x][i];
		if(to==f)continue;
		if(abs(w[x]-w[to])!=1)flag=1;
		check(to,x);
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++)
	{
		int a,b;scanf("%d%d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
	{
		int p,val;scanf("%d%d",&p,&val);
		w[p]=val;vis[p]=1;
		q.push(make_pair(val,p));
	}
	while(!q.empty())
	{
		int p=q.top().second,val=q.top().first;q.pop();
		for(int i=0;i<(int)g[p].size();i++)
		{
			int to=g[p][i];
			if(vis[to])continue;
			w[to]=val+1;vis[to]=1;q.push(make_pair(w[to],to));
		}
	}
	
	check(1,0);
	if(flag)
	{
		puts("No");
	}
	else
	{
		puts("Yes");
		for(int i=1;i<=n;i++)
		{
			printf("%d\n",w[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 12156
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int Xmax, Ymax, n;
    cin >> Xmax >> Ymax >> n;
    int Xmin = 0;
    int Ymin = 0;

    int x[n], y[n], a[n];
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> a[i];
    }

    for(int i = 0; i < n; i++){
        if(a[i]==1 && Xmin<x[i]){
            Xmin = x[i];
        }
        else if(a[i]==2 && Xmax>x[i]){
            Xmax = x[i];
        }
        else if(a[i]==3 && Ymin<y[i]){
            Ymin = y[i];
        }
        else if(a[i]==4 && Ymax>y[i]){
            Ymax = y[i];
        }

        //cout << "Xmin: " << Xmin  << ", Xmax:" << Xmax << ", Ymin:" << Ymin << ", Ymax" << Ymax << endl;
    }

    int ans = (Xmax-Xmin) * (Ymax-Ymin);
    if((Xmax-Xmin)>0 && (Ymax-Ymin)>0) cout << (Xmax-Xmin) * (Ymax-Ymin) << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double a, b, c;
  cin >> a  >> b >> c;
  if (a + b + 2 * (long double)sqrt(a*b) < c) {
    cout << "Yes" << '\n';
  } else {
    cout << "No" << '\n';
  }
}


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

struct Query{
 int l,r; UL d;
} Q[4000];

int R[2000][4];
int* listX[4000];
int* listY[4000];
LL dX[4000];
LL dY[4000];
UL G[4000]={};
LL ans=0;

bool PtrCmp(int* l, int* r) {return *l<*r;}

int main() {
 UL N; scanf("%u",&N);
 rep(i,N)rep(j,4) scanf("%d",&R[i][j]);
 rep(i,N){
  listX[i*2]=&R[i][0];
  listY[i*2]=&R[i][1];
  listX[i*2+1]=&R[i][2];
  listY[i*2+1]=&R[i][3];
 }
 sort(listX,listX+N+N,PtrCmp);
 sort(listY,listY+N+N,PtrCmp);
 rep(i,N*2-1) dX[i]= *listX[i+1] - *listX[i];
 rep(i,N*2-1) dY[i]= *listY[i+1] - *listY[i];
 rep(i,2*N) *listX[i] = *listY[i] = i;
 rep(i,N){
  Q[R[i][1]] = { R[i][0],R[i][2],1 };
  Q[R[i][3]] = { R[i][0],R[i][2],(UL)-1 };
 }
 rep(y,N*2-1){
  for(UL x=Q[y].l; x<Q[y].r; x++)
   G[x]+=Q[y].d;
  rep(x,N*2) if(G[x]) ans+=dX[x]*dY[y];
 }
 printf("%lld\n",ans);
 return 0;
}



Measured memory_bytes: 3492
//11-1 惑星探査
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<time.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#define LL long long
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
#define ROOP() while(true)

//二次元累積輪
int M,N,K;
int mp[1000][1000];//y,x
int dp_J[1000][1000];
int dp_O[1000][1000];
int main(){
	cin >> M >> N >> K;
	for(int i=0; i<M; i++){
		string tmp;
		cin >> tmp;
		for(int j=0; j<N; j++){
			if(tmp[j]=='J'){
				mp[i][j] = 0;
			}
			else if(tmp[j]=='O'){
				mp[i][j] = 1;
			}
			else mp[i][j] = 2;
		}
	}
	
	for(int i=0; i<M; i++){
		for(int j=0; j<N; j++){
			if(i!=0 && j!=0){
				dp_J[i][j] = dp_J[i][j-1] + dp_J[i-1][j] - dp_J[i-1][j-1];
			}
			else if(i!=0 && j==0){
				dp_J[i][j] = dp_J[i-1][j];
			}
			else if(i==0 && j!=0){
				dp_J[i][j] = dp_J[i][j-1];
			}
			else if(i==0 && j==0){
				dp_J[i][j] = 0;
			}
			if(mp[i][j]==0) dp_J[i][j]++;
		}
	}
	
	/*
	for(int i = 0;i < M;++i){
		for(int q = 0;q < N;++q){
			if(mp[i][q] == 0) dp_J[i][q] = 1;
		}
	}
	for(int i = 0;i < M;++i){
		for(int q = 1;q < N;++q){
			dp_J[i][q] += dp_J[i][q-1];
		}
	}
	for(int i = 1;i < M;++i){
		for(int q = 0;q < N;++q){
			dp_J[i][q] += dp_J[i-1][q];
		}
	}*/
	for(int i=0; i<M; i++){
		for(int j=0; j<N; j++){
			if(i!=0 && j!=0){
				dp_O[i][j] = dp_O[i][j-1] + dp_O[i-1][j] - dp_O[i-1][j-1];
			}
			else if(i!=0 && j==0){
				dp_O[i][j] = dp_O[i-1][j];
			}
			else if(i==0 && j!=0){
				dp_O[i][j] = dp_O[i][j-1];
			}
			else if(i==0 && j==0){
				dp_O[i][j] = 0;
			}
			if(mp[i][j]==1) dp_O[i][j]++;
		}
	}

	for(int i=0; i<K; i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		a--;
		b--;
		c--;
		d--;
		if(a!=0 && b!=0){
			int j = dp_J[c][d] - dp_J[c][b-1] - dp_J[a-1][d] + dp_J[a-1][b-1];
			int o = dp_O[c][d] - dp_O[c][b-1] - dp_O[a-1][d] + dp_O[a-1][b-1];
			int ii = (c-a+1)*(d-b+1) - j - o;
			cout << j << " " << o << " " << ii << endl;
		}
		else if(a!=0 && b==0){
			int j = dp_J[c][d] - dp_J[a-1][d];
			int o = dp_O[c][d] - dp_O[a-1][d];
			int ii = (c-a+1)*(d-b+1) - j - o;
			cout << j << " " << o << " " << ii << endl;
		}
		else if(a==0 && b!=0){
			int j = dp_J[c][d] - dp_J[c][b-1];
			int o = dp_O[c][d] - dp_O[c][b-1];
			int ii = (c-a+1)*(d-b+1) - j - o;
			cout << j << " " << o << " " << ii << endl;
		}
		else if(a==0 && b==0){
			int j = dp_J[c][d];
			int o = dp_O[c][d];
			int ii = (c-a+1)*(d-b+1) - j - o;
			cout << j << " " << o << " " << ii << endl;
		}
	}


	return 0;
}


Measured memory_bytes: 14756
#include<iostream>
using namespace std;
int main() {
    int H=1, W=1;
    while (true) {
        cin >> H >> W;
        if (H == 0 && W == 0)break;
        for (int i = 0; i < H; i++) {
            cout << "#";
            for (int j = 0; j < W-2; j++) {
                if(i==0||i==H-1)cout << "#";
                else { 
                    cout <<"."; 
                }
            }
            cout << "#";
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

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

int Emonth[12] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 };

long long daycount(int year , int month , int day)
{
	long long total = 0;
	total += year * 365;		//year??´1???1??\?????§?????\??°

	total += Emonth[month-1];			//1???1??\???month???1??\?????§?????\??°(???????????´??????????????????)
	
	total += year / 4;
	total -= year / 100;
	total += year / 400;		//???????????´????????°

	if (((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)) && (month < 3))
	{
		total--;		//???????????´??????2???29??\??????????????????????????§?????????????????????
	}

	total += day;		//1??\???day??\?????§?????\??°

	return total;
}


int main()
{
	int y1, y2, m1, m2, d1, d2;
	while (1)
	{
		long long total1 = 0, total2 = 0;
		cin >> y1 >> m1 >> d1 >> y2 >> m2 >> d2;
		if (y1 < 0 || m1 < 0 || d1 < 0 || y2 < 0 || m2 < 0 || d2< 0) break;

		total1 = daycount(y1, m1, d1);
		total2 = daycount(y2, m2, d2);

		cout << total2 - total1 << endl;

	}


	return 0;
}

Measured memory_bytes: 1156
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = 99999999;
const ll linf = 999999999999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

///////////////////////////////////////////////////////////////////////////
int a[2000005] = {};
vector<int> b;

int main(){
    int n;
    cin >> n;
    rep(i,0,n){
        cin >> a[i];

        if(i%2 == 0){
            b.pb(a[i]);
        }else{
            auto it = b.begin();      
            it = b.insert(it,a[i]); 
        }
    }
    

    if(n%2 == 0)rep(i,0,n)cout << b[i] << " ";
    else rep(i,0,n)cout << b[n-1-i] << " ";
    cout << endl;
    
	return  0;
}

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

using namespace std;

int M, N, K;
vector<string> MapData;
int DpJTotal[1001][1001];
int DpOTotal[1001][1001];
int DpITotal[1001][1001];

void solve() {
	
	for (int i = 1; i <= M; ++i) {
		for (int j = 1; j <= N; ++j) {
			DpJTotal[i][j] += DpJTotal[i][j - 1];
			DpOTotal[i][j] += DpOTotal[i][j - 1];
			DpITotal[i][j] += DpITotal[i][j - 1];
		}
	}

	for (int j = 1; j <= N; ++j) {
		for (int i = 1; i <= M; ++i) {
			DpJTotal[i][j] += DpJTotal[i - 1][j];
			DpOTotal[i][j] += DpOTotal[i - 1][j];
			DpITotal[i][j] += DpITotal[i - 1][j];
		}
	}

}

int main() {
	int a, b, c, d;
	string str;

	memset(DpJTotal, 0, sizeof(DpJTotal));
	memset(DpOTotal, 0, sizeof(DpOTotal));
	memset(DpITotal, 0, sizeof(DpITotal));
	cin >> M >> N >> K;
	for (int i = 0; i < M; ++i) {
		cin >> str;
		MapData.push_back(str);
		for (int j = 1; j <= N; ++j) {
			if (MapData[i][j - 1] == 'J') {
				++DpJTotal[i + 1][j];
			}
			else if (MapData[i][j - 1] == 'O') {
				++DpOTotal[i + 1][j];
			}
			else if (MapData[i][j - 1] == 'I') {
				++DpITotal[i + 1][j];
			}
		}
	}
	/*for (int i = 0; i < M; ++i) {
		cout << MapData[i] << endl;
	}*/
	solve();
	for (int i = 0; i < K; ++i) {
		cin >> a >> b >> c >> d;
		cout << DpJTotal[c][d] - DpJTotal[c][b - 1] - DpJTotal[a - 1][d] + DpJTotal[a - 1][b - 1] << " ";
		cout << DpOTotal[c][d] - DpOTotal[c][b - 1] - DpOTotal[a - 1][d] + DpOTotal[a - 1][b - 1] << " ";
		cout << DpITotal[c][d] - DpITotal[c][b - 1] - DpITotal[a - 1][d] + DpITotal[a - 1][b - 1] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 15608
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {

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

    int count = Integer.parseInt(reader.readLine());
    for (int i = 0; i < count; i++) {
      BigInteger l = new BigInteger(reader.readLine());
      BigInteger r = new BigInteger(reader.readLine());
      if (l.toString().length() > 80 || r.toString().length() > 80) {
        System.out.println("overflow");
        continue;
      }
      BigInteger result = l.add(r);
      if (result.toString().length() > 80) {
        System.out.println("overflow");
        continue;
      }
      System.out.println(result.toString());
    }
  }

}

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

ll N,M;
int main(){
	cin >> N >> M;
	if(N == M){
		if(N == 1)cout << 1 << endl;
		else cout << (N-2)*(N-2) << endl;
	}
	else if(min(N,M) == 1) {
		cout << max(N,M)-2 << endl;
	}else{
		cout << (M-2)*(N-2) << endl;
	}
	return 0;
}


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

#define FIND(c, e) ((c).find(e) != (c).end())
#define NFIND(c, e) ((c).find(e) == (c).end())
#define ALL(t) (t).begin(), (t).end()
#define ALLR(t) (t).rbegin(), (t).rend()
#define MP make_pair

const int N = int( 2e5 ) + 10;
const int M = int( 1e6 ) + 1;
const int MOD = int( 1e9 ) + 7;
const double PI = acos(-1.0);
const double eps = 1e-6;
template<class T> T gcd(T a,T b){while(b){T r=a%b;a=b;b=r;}return a;}
template<class T> T lcm(T a,T b){return (a*b)/gcd(a,b);}
template<class T> T max(T a,T b,T c){return max(max(a,b),c);}
template<class T> T min(T a,T b,T c){return min(min(a,b),c);}

void __answer()
{
    int n, a;
    cin >> n;
    unordered_set<int> s;
    while(n--) {
        cin >> a;
        if(FIND(s, a)) {
            s.erase(a);
        } else s.insert(a);
    }
    cout << s.size() << endl;
}
int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cout << setprecision(11) << fixed;
    #ifdef LOCAL
        freopen("TEST.txt", "r", stdin);
    #endif
    __answer();
    return 0;
}


Measured memory_bytes: 4388
import sys #追加
sys.setrecursionlimit(500*500)

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return int(x)

N = int(input())
A = list(map(int, input().split()))

LCM = lcm(A)

ans = 0
for a in A:
    ans += LCM//a

ans %= 1000000007

print(ans)

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

int n, m;
ll a[MAX];

int main()
{
    cin >> m >> n;
    for(int i = 1; i <= n; i++){
        scanf("%lld", &a[i]);
    }
    ll ans = 0;
    for(int i = 2; i <= n; i++){
        ans = max(ans, a[i]-a[i-1]);
    }
    ans = max(ans, a[1]+m-a[n]);
    cout << m-ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<cctype>
#include<cstdlib>
#include<cstring>
#include<utility>
#include<algorithm>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define For(i,x,y) for(int i=((int)x);i<=((int)y);i++)
#define Dep(i,y,x) for(int i=((int)y);i>=((int)x);i--)
#define Rep(i,x) for (int y,i=head[x];i;i=E[i].nxt)
using namespace std;

const int inf=1000000009;

typedef double db;
typedef long long ll;
typedef unsigned int uint;
typedef pair<int,int> pii;

int rd() {
	char c=getchar(); int t=0,f=1;
	while (!isdigit(c)) f=(c=='-')?-1:1,c=getchar();
	while (isdigit(c)) t=t*10+c-48,c=getchar(); return t*f;
}
void wt(int x) {
	if (x<0) putchar('-'),wt(-x);
	else { if (x>9) wt(x/10); putchar(x%10+48); }
}

const int N=1e6+5;

ll n,m,A[N],sum,ans=1e18,c[N],B[N];

int main() {
	n=rd(),m=rd();
	For (i,1,n) {
		c[i]=rd();
		if (i==1) continue;
		int l=c[i-1],r=c[i];
		if (l<r) A[l+1]++,A[r+1]--,B[r+1]-=r-l;
		else {
			A[l+1]++,A[1]++,A[r+1]--;
			B[1]+=m-l,B[r+1]-=r+m-l;
		}
	}
	For (i,1,m) A[i]+=A[i-1],sum+=A[i];
	For (i,1,m) {
		B[i]=B[i]+B[i-1]+A[i];
		ans=min(ans,sum-B[i]+A[i]);
	}
	printf("%lld\n",ans);
	return 0;
}






Measured memory_bytes: 9088
//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef unsigned long long ull;
typedef long long  ll;
#define MOD 1000000007
#define MX 1000000000
#define NMAX 100005
#define MXL 1000000000000000000
#define PI 3.14159265
#define pb push_back
using namespace std;
#define sc second
#define endl '\n'
#define fr first
//read contraints to make sure its not brute force

int main()
{
    string s;
    cin >> s;
    if(s[s.size()-1] == 's')
    {
        cout << s << "es";
    }
    else
    {
        cout << s << "s";
    }
}



Measured memory_bytes: 3624
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

ll d[205][205];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, m, r;
	cin >> n >> m >> r;
	vi t(r);
	rep(i, r) cin >> t[i], t[i]--;
	rep(i, 205) rep(j, 205) d[i][j] = 1e18;
	rep(i, 205) d[i][i] = 0;
	rep(i, m){
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--, b--;
		d[a][b] = c;
		d[b][a] = c;
	}
	rep(k, n) rep(i, n) rep(j, n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	ll ans = 1e18;
	sort(all(t));
	do{
		ll cur = 0;
		repn(i, 1, r) cur += d[t[i]][t[i - 1]];
		ans = min(ans, cur);
	} while(next_permutation(all(t)));
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Precision
// << std::fixed << std::setprecision(7)

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}


void solve(){
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++)
    if(s[i] == '7'){
      cout << "Yes" << endl;
      return;
    }
  cout << "No" << endl;
}

int main(){
  // FastIO
  //ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 3592
N , M = map(int , input().split(' '))
A, B = [], []
hit = 0
for i in range(M):
    tmp = input().split(' ')
    A.append(int(tmp[0]))
    B.append(int(tmp[1]))

hit_card = 0
for i in range(M):
    if A[i] >= N:
        hit_card += 1

sorted_A = sorted(A, reverse=True)
need_money = 0

if hit_card < (M - 1):
    need_hit = (M - 1) - hit_card

    for i in range(need_hit):
        need_money += N - sorted_A[i + hit_card]

print(need_money)

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

using namespace std;

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  char d = 'A' - 'a';
  printf("%c%c%c\n", a[0] + d, b[0] + d, c[0] + d);
  return 0;
}


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

int main()
{
	string S;

	cin >> S;

	int correctCount = 0;
	int size = S.size();
	for (int i = 0; i < size; ++i)
	{
		if (i % 2 == 0)
		{
			if (S[i] == '0')
				++correctCount;
		}
		else
		{
			if (S[i] == '1')
				++correctCount;
		}
	}

	int ret = (correctCount > size - correctCount) ? size - correctCount : correctCount;
	cout << ret << endl;

	return 0;
}

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

string s;
int p[100001];
int dp[100001][2] , was[100001][2];

int _find(int pos , int t){
    if (was[pos][t]) return dp[pos][t];
    was[pos][t] = 1;
    if (s[pos] == 'L' && s[pos - 1] == 'R' && !t) return dp[pos][t] = pos;
    if (s[pos] == 'R' && s[pos + 1] == 'L' && !t) return dp[pos][t] = pos;
    if (s[pos] == 'R') return dp[pos][t] = _find(pos + 1 , t ^ 1);
    if (s[pos] == 'L') return dp[pos][t] = _find(pos - 1 , t ^ 1);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    for (int i = 0; i < s.size(); i++) p[_find(i , 0)]++;
    for (int i = 0; i < s.size(); i++) cout << p[i] << " ";
}


Measured memory_bytes: 6892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    string n;
    cin >> n;
    for (int i = 0; i < n.length(); ++i) {
        if (n[i] == '1') n[i] = '9';
        else if (n[i] == '9') n[i] = '1';
    }
    cout << n << endl;
}

Measured memory_bytes: 764
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vvi = vector<vector<int>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	string s, t; cin >> s >> t;
	int ans = 0;
	rep(i, 3) ans += s[i] == t[i];
	cout << ans << endl;
}

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

int cmpnum(const void * n1, const void * n2)
{
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void){

  long n;
  scanf("%ld", &n);
  long a[n];
  long sort[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
    sort[i] = a[i];
  }

  qsort(sort, n, sizeof(long), cmpnum);
  long first = sort[0];
  int first_count = 1;
  long second;
  if (sort[1] == first) {
    first_count++;
  } else {
    second = sort[1];
  }

  for (long i = 0; i < n; i++) {
    if (a[i] != first) {
      printf("%ld\n", first);
    } else {
      if (first_count != 1) {
        printf("%ld\n", first);
      } else {
        printf("%ld\n", second);
      }
    }
  }

  return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end());
  cout << A.back() - A.front();

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
  	static int mod = 1000000007;
  static int size = 200001;
	static long[] fac = new long[size];
	static long[] finv = new long[size];
	static long[] inv = new long[size];
	static int INF = Integer.MAX_VALUE;
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	// 整数の入力
	int N = sc.nextInt();
  int K = sc.nextInt();
  int[] h =new int[N];
  int count=0;
  for(int i=0;i<N;i++){
    h[i] = sc.nextInt();
    if(h[i]>=K){
     count++; 
    }
  }
    System.out.println(count);



} 

 //fac, inv, finvテーブルの初期化、これ使う場合はinitComb()で初期化必要
	public static  void initComb(){
		fac[0] = finv[0] = inv[0] = fac[1] = finv[1] = inv[1] = 1;
		for (int i = 2; i < size; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - (mod / i) * inv[(int) (mod % i)] % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}
 
	//nCk % mod
	public static long comb(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
		return fac[n] * finv[k] % mod * finv[n - k] % mod;
	}
 
	//n! % mod
	public static long fact(int n){
		return fac[n];
	}
 
	//(n!)^-1 with % mod
	public static long finv(int n){
		return finv[n];
	}
  
}

Measured memory_bytes: 66528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main(){
    ll n;
    cin >> n;
    ll sum = 0;
    rep(i,n)rep(j,n)rep(k,n){
        ll t = gcd(i+1,j+1);
        ll a = gcd(t,k+1);
        sum += a;
    }
    cout << sum << endl;
}

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

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define rep(i,n) for(int i=0; i<(int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

//constexpr ll mod = 998244353;
constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

// greatest common divisor
long long gcd(long long a, long long b) {
  long long r = 1;
  while (r != 0) {
    r = a%b; a = b; b = r;
  }
  return a;
}

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


ll count(ll a, ll c, ll d) {
  ll s = a/c;
  ll t = a/d;
  ll r = a/lcm(c,d);
  return a-(s+t-r);
}


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

  ll a, b, c, d; cin >> a >> b >> c >> d;
  cout << count(b, c, d)-count(a-1, c, d) << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

int main() {
	int n;
	while (cin >> n, n) {
		pair<int, int> p[n];
		int i = 0;
		
		p[i] = pair<int, int>(0, 0);
		i++;
		
		int maxX = 0, minX = 0;
		int maxY = 0, minY = 0;
		for (;i < n; i++) {
			int c, d;
			cin >> c >> d;
			int x = p[c].first + dx[d], y = p[c].second + dy[d];
			p[i] = pair<int, int>(x, y);
			minX = min(minX, x);
			maxX = max(maxX, x);
			minY = min(minY, y);
			maxY = max(maxY, y);
		}
		cout << (maxX + 1 - minX) << " " << (maxY + 1 - minY) << endl;
	}
}

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

#define pb(a) push_back(a)
#define INF 1145141919810364364
#define mod 1000000007

typedef long long ll;

const int dsize = 1e5+5;
int dx[] = {-1,0,1,0},dy[] = {0,1,0,-1};
vector<ll> prime;

ll inv[dsize],fac[dsize];

template <class T = ll> T in(){T x;cin >> x;return (x);}
inline ll GCD(ll a,ll b){ll c;while(b!=0){c=a%b;a=b;b=c;}return a;}
inline ll LCM(ll a,ll b){return a*b/GCD(a,b);}
inline ll POW(ll a,ll b){ll c=1;while(b>0){if(b&1){c=a*c%mod;}a=a*a%mod;b>>=1;}return c;}
inline void _nCr(){fac[0]=1;for(int i=1;i<dsize;i++){fac[i]=fac[i-1]*i%mod;}for(int i=0;i<dsize;i++){inv[i]=POW(fac[i],mod-2);}}
inline ll nCr(ll n,ll r){return (fac[n]*inv[r]%mod)*inv[n-r]%mod;}
inline void PRI(ll n){bool a[n+1];for(int i=0;i<n+1;i++){a[i]=1;}for(int i=2;i<n+1;i++){if(a[i]){prime.pb(i);ll b=i;while(b<=n){a[b]=0;b+=i;}}}}

int main() {
	int n=in();
	int cal[n];
	set<int> c;
	for (int i=0;i<n;i++) {
		cin>>cal[i];
		c.insert(cal[i]);
	}
	if (c.size()==1){
		if (cal[0]==n-1){
			cout<<"Yes"<<endl;
			return 0;
		} else {
			if (cal[0]<=n/2) {
				cout<<"Yes"<<endl;
				return 0;
			} else {
				cout<<"No"<<endl;
				return 0;
			}
		}
	} else if (c.size()==2) {
		int x=0,y=0;
		int a=*c.begin();
		auto itr=c.begin();itr++;
		if (a+1!=*itr) {
			cout<<"No"<<endl;
			return 0;
		}
		for (int i=0;i<n;i++) {
			if (cal[i]==a) x++;
			else y++;
		}
		if (x<=a&&a<=x-1+y/2) {
			cout<<"Yes"<<endl;
		} else {
			cout<<"No"<<endl;
		}
		return 0;
	} else {
		cout<<"No"<<endl;
	}
	return 0;
}

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

int main() {
  string n;
  cin >> n;
  int total = 0;
  for (int i = 0; i < (int)n.size(); i++) {
    total += (int)(n[i] - '0');
    total %= 9;
  }

  if (total == 0) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 3748
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt(), m = sc.nextInt(), a = sc.nextInt();
            if(n==0 && m==0 && a==0) break;

            int[][] amida = new int[1001][n+1];

            for(int i=0; i<m; i++){
                int h = sc.nextInt(), p = sc.nextInt(), q = sc.nextInt();
                amida[h][p] = q;
                amida[h][q] = p;
            }

            int idx = a;
            for(int i=1000; i>0; i--){
                if(amida[i][idx]!=0) idx = amida[i][idx];
            }
            
            System.out.println(idx);
        }
    }

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

Measured memory_bytes: 70780
#include<stdio.h>
#include<string.h>

main(){
	
	int i;
	char s[100]="",p[100]="", copy_s[200];
	char *x;
	
	scanf("%s%s",&s,&p);
	
	strcpy(copy_s,s);
	
	strcat(copy_s,s);
	
	x=copy_s;
	
	x=strstr(x,p);
	
	if(x){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	
	return 0;
}

Measured memory_bytes: 540
import static java.lang.System.out;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main extends BaseExe {

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

    @Override
    protected void execute() throws Exception {
        List<Integer> nums = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
        nums.forEach(x -> nums.forEach(y -> out.println(x + "x" + y + "=" + x * y)));
    }

    public void recursionQQ() {
        recursionQQ(1);
    }

    public void recursionQQ(int i) {
        if (i > 9)
            return;
        recursionQ(i, 1);
        recursionQQ(++i);
    }

    public void recursionQ(int i, int j) {
        if (j > 9)
            return;
        out.println(i + "x" + j + "=" + i * j);
        recursionQ(i, ++j);
    }

}

abstract class BaseExe {

    private Scanner scan;

    private String inData;

    public void exeSysIn() {
        try (Scanner scan = new Scanner(System.in)) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void exeFileIn(String inDataPath) {
        try (Scanner scan = new Scanner(new File(inDataPath))) {
            exeCtrl(scan);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void exeCtrl(Scanner scan) throws Exception {
        this.scan = scan;
        execute();
    }

    protected abstract void execute() throws Exception;

    protected String nextLine() {
        return scan.nextLine();
    }

    protected boolean judgeInData() {
        return hasNextLine() && isNotEmptyInData();
    }

    protected boolean hasNextLine() {
        return scan.hasNextLine();
    }

    protected boolean isNotEmptyInData() {
        inData = nextLine();
        return !inData.isEmpty();
    }

    protected String getInData() throws Exception {
        if (inData.isEmpty())
            throw new Exception("inData is Empty.");
        return inData;
    }
}

Measured memory_bytes: 31148
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

int main() {
  int n, ma, mb;
  cin >> n >> ma >> mb;
  struct chemical{
    int a;
    int b;
    int c;
  };
  vector<chemical> chemis(n);
  for(int i = 0; i < n; i++)
  {
    int a, b, c;
    cin >> a >> b >> c;
    chemis[i] = {a, b, c};
  }
  ///半分全列挙を行う
  auto half_search = [&](uint range, uint offset, vector<vector<int>> &result)
  {
    for(uint i = 0; i < range; i++)
    {
      int a, b, c;
      a = b = c = 0;
      uint index = 0;
      for(uint j = 1; j <= i; j = j << 1)
      {
        if(j & i)
        {
          //そこのビットに1が立っている
          a += chemis[index + offset].a;
          b += chemis[index + offset].b;
          c += chemis[index + offset].c;
        }
        index++;
      }
      result[a][b] = min(result[a][b], c);
    }
  };
  uint offset = (uint)(n / 2);
  const int max_num = 40 * 10 + 1;
  const int max_cost = 100 * 40 * 2 + 1;
  vector<vector<int>> result_before(max_num, vector<int>(max_num, max_cost));
  vector<vector<int>> result_after(max_num, vector<int>(max_num, max_cost));
  half_search((uint)(pow(2, offset)), 0, result_before);
  half_search((uint)(pow(2, n - offset)), offset, result_after);

  ///正しい比率を列挙
  vector<pair<int, int>> correct_rate;
  for(int i = 1; i <= max_num; i++)
  {
    int tempa = ma * i;
    int temob = mb * i;
    if(tempa <= max_num && temob <= max_num)
    {
      correct_rate.push_back({tempa, temob});
    }
  }
  ///結果をマージ
  int result = max_cost;
  for(int i = 0; i < max_num; i++)
  {
    for(int j = 0; j < max_num; j++)
    {
      for(auto e : correct_rate)
      {
        if(e.first - i < 0 || e.second - j < 0) continue;
        if(e.first - i >= max_num || e.second >= max_num) continue;
        result =  min(result, result_before[i][j] + result_after[e.first - i][e.second - j]);
      }
    }
  }
  if(result == max_cost)
  {
    cout << -1 << endl;
  }else{
    cout << result << endl;
  }
  return 0;
}


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

# define REP(i,n) for (int i=0;i<(n);++i)
# define rep(i,a,b) for(int i=a;i<(b);++i)
# define p(s) std::cout << s ;
# define pl(s)  std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
# define yes(j) std::cout << (j ? "yes" : "no") << endl;
# define all(v) v.begin(),v.end()
# define showVector(v) REP(i,v.size()){p(v[i]);p(" ")} pl("")
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;}
typedef long long int ll;
typedef pair<ll,ll> P_ii;
typedef pair<double,double> P_dd;

template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}

template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}


const int MOD = 1000000007;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;

void addM(long long &a, long long b) {
    a += b;
    if (a >= MOD) a -= MOD;
}

void mulM(long long &a, long long b) {
    a = ((a%MOD)*(b%MOD))%MOD ;
}

// テーブルを作る前処理
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
	int n;
	cin>>n;
	vector<ll> a(n+1);

	rep(i,1,n+1){
		int x;
		cin>>x;
		a[x]=i;
	}

	set<ll> st;
	st.insert(0);
	st.insert(n+1);

	ll ans=0;
	rep(i,1,n+1){
		auto itr=st.lower_bound(a[i]);
		ll  up=*itr;
		--itr;
		ll down = *itr;

		ans+=1LL*i*(a[i]-down)*(up-a[i]);
		st.insert(a[i]);
	}
	pl(ans);
	return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    int N;
    cin>>N;
    vi A(N);
    vector<pii> P(N);
    vector<pii> M(N);

    for(int i=0;i<N;i++){
        cin>>A[i];
        P[i]=make_pair(A[i]+i,i);
        M[i]=make_pair(i-A[i],i);

    }
    //sort(ALL(P));
    sort(ALL(M));
    vi Mf(N);
    vi Ms(N);
    for(int i=0;i<N;i++){
        Mf[i]=M[i].first;
        Ms[i]=M[i].second;
    }

    ll ans=0;
    for(int i=0;i<N;i++){
        int val=P[i].first;
        int start=lower_bound(ALL(Mf),val)-Mf.begin();
        int end=upper_bound(ALL(Mf),val)-Mf.begin();
        int ans_i=(upper_bound(Ms.begin()+start,Ms.begin()+end,P[i].second)-Ms.begin())-start;
        ans+=(end-start)-ans_i;
        // for(int j=start;j<end;j++){
        //     if(P[i].second<Ms[j])ans++;
        // }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8804
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> ii;
/////////////////////////////////////////////////////////////////////
# define M_PI 3.14159265358979323846 
int main()
{
  int r;
  scanf("%d", &r);
  r *= 2;
  double circ = M_PI * r;
  cout << circ << endl;
  return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
#define MOD 1e9+7
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll gcd(ll n, ll m){
    if(m==0)return n;
    return gcd(m, n % m);
}

ll lcm(ll n, ll m){
    return m / gcd(n, m) * n;
}

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

    int A,B;
    cin >> A>>B;
    cout << 6-A-B<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <functional>
#include <map>
#include <math.h>



using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long int x; cin >> x;

	long long int a, b;


	for (int i = -118; i <= 119; i++) {
		a = pow(i, 5);
		for (int j = -119; j <= 118; j++) {
			b = pow(j, 5);
				if (a - b == x) {
					cout << i << " " << j << endl;
					return 0;
				}

		}
	}

	return 0;
}


Measured memory_bytes: 4060
t = list(map(int, input().split())); n, k = t[0], t[1];
stripe = str(input()); groups = 0
for i in range(len(stripe)-1):
    if stripe[i] != stripe[i+1]:
        groups += 1
groups += 1
if k >= groups//2:
    print(n-1)
else:
    groups = groups - 2 * k
    print(n - groups)

Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#define X 1000000007
using namespace std;


int main(){
        int N,M,i;
        cin >> N >> M;
        long long ans=1;
        if(N==M) {
                for(i=1; i<=N; i++) {
                        ans*=i;
                        ans%=X;
                }
                for(i=1; i<=M; i++) {
                        ans*=i;
                        ans%=X;
                }
                ans= (ans*2)%X;
        }else if(N-M==1||M-N==1) {
                for(i=1; i<=N; i++) {
                        ans*=i;
                        ans%=X;
                }
                for(i=1; i<=M; i++) {
                        ans*=i;
                        ans%=X;
                }

        }else{
                ans = 0;
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256