akhauriyash/Code-Regression huggingface dataset:
/*input
10
0 0 1 1 2 3 5 8 13 21 34
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#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 REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e5+1;
int active = 1;
int n;
int a[N];
int x[N];
int y[N];

void solve(){
  	cin >> n;
  	REP(i,n+1)cin >> a[i];
  	int mn = a[n];
  	int mx = a[n];
  	x[n] = a[n];
  	y[n] = a[n];
  	int suma = 0;
  	for(int i = n-1;i >= 0;i--){
  		mn = (mn+1)/2+a[i];
  		mx = mx+a[i];
  		x[i] = mn;
  		y[i] = mx;
  	}
  	if(mn > 1){
  		cout << -1;
  		return;
  	}
  	int cur = 1;
  	int ans = 1;
  	for(int i = 1;i <= n;i++){

  		cur = min(2*(cur-a[i-1]),y[i]);
  		//cout << x[i] << " " << y[i] << " " << cur << endl;
  		ans += cur;
  	}
  	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

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

int n, a;
map<int, int> oc, ec;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (i % 2) oc[a]++;
		else ec[a]++;
	}
    
    int en, em = 0, on, om = 0;
    for (auto& i : ec) {
		if (i.second > em) {
			em = i.second;
			en = i.first;
		}
	}
    for (auto& i : oc) {
		if (i.second > om) {
			om = i.second;
			on = i.first;
		}
	}
	
	int es = 0, os = 0;
    for (auto& i : ec) {
		if (i.second > es && i.first != en) {
			es = i.second;
		}
	}
    for (auto& i : oc) {
		if (i.second > os && i.first != on) {
			os = i.second;
		}
	}
	
	if (en == on) {
		if (em + os > om + es) {
			om = os;
		} else {
			em = es;
		}
	}
	
    cout << n - em - om;
    return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(void){

  int a,b,c,i;

  int count;

scanf("%d %d %d\n",&a,&b,&c);

  for(i = a,count = 0;i <= b;i++){

    if(c%i == 0)count ++;

  }

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

return 0;

}

Measured memory_bytes: 600
# A - Candy Distribution Again
n,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(n):
    if i!=n-1:
        x-=a[i]
        if x>=0:
            ans+=1
        else:
            break
    else:
        if a[i]==x:
            ans+=1

print(ans)

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

const int kN = 100'000 + 5;
vector<int> g[kN];
int pr[kN], ed[kN], st[kN];
bool v[kN], used[kN];

int Dfs(int x, int p, int f) {
    int xv = 0;
    v[x] = true;
    for (int e : g[x]) {
        int u = ed[e] ^ x;
        if (u == p) continue;
        if (used[e]) continue;
        if (!v[u]) {
            int d = Dfs(u, x, e);
            xv ^= d;
        } else {
            used[e] = true;
            st[e] = x;
            xv ^= 1;
        }
    }
    if (xv == 1) {
        if (x == 0) {
            puts("-1");
            exit(0);
        }
        st[f] = x;
        return 0;
    } else {
        if (f != -1) st[f] = p;
        return 1;
    }
}

int main() {
    int n, m; scanf("%d%d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int u, v; scanf("%d%d", &u, &v);
        u--, v--;
        ed[i] = u ^ v;
        g[u].push_back(i);
        g[v].push_back(i);
    }
    Dfs(0, -1, -1);
    for (int i = 0; i < m; ++i) {
        printf("%d %d\n", st[i] + 1, (ed[i] ^ st[i]) + 1);
    }
}


Measured memory_bytes: 13952
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
typedef long long ll;
const int maxn=200000+10,mo=1000000007,inf=1000000005;
int mi[maxn],c[maxn],w[maxn],cnt[maxn],fac[maxn],inv[maxn];
int i,j,k,l,t,n,m,ans,num,x,y;
int qsm(int x,int y){
	if (!y) return 1;
	int t=qsm(x,y/2);
	t=(ll)t*t%mo;
	if (y%2) t=(ll)t*x%mo;
	return t;
}
int C(int n,int m){
	if (n<m||m<0) return 0;
	return (ll)fac[n]*inv[m]%mo*inv[n-m]%mo;
}
int main(){
	scanf("%d%d%d",&n,&x,&y);
	fo(i,1,n) mi[i]=inf;
	fac[0]=1;
	fo(i,1,n) fac[i]=(ll)fac[i-1]*i%mo;
	inv[n]=qsm(fac[n],mo-2);
	fd(i,n-1,0) inv[i]=(ll)inv[i+1]*(i+1)%mo;
	fo(i,1,n){
		scanf("%d%d",&c[i],&w[i]);
		mi[c[i]]=min(mi[c[i]],w[i]);
		cnt[c[i]]++;
	}
	fo(i,1,n) 
		if (mi[i]!=inf){
			if (m==0) m=i;
			else if (mi[i]<mi[m]) m=i;
		}
	t=inf;
	fo(i,1,n)
		if (mi[i]!=inf&&i!=m) t=min(t,mi[i]);
	fo(i,1,n){
		if (w[i]!=mi[c[i]]&&w[i]+mi[c[i]]<=x) continue;
		if (c[i]!=m&&w[i]+mi[m]<=y) continue;
		if (c[i]==m&&w[i]+t<=y) continue;
		cnt[c[i]]--;
	}
	num=cnt[m];
	fo(i,1,n)
		if (mi[i]!=inf&&i!=m)
			if (mi[i]+mi[m]<=y) num+=cnt[i];
	ans=1;
	fo(i,1,n)
		if (mi[i]!=inf&&(i==m||mi[i]+mi[m]<=y)){
			ans=(ll)ans*C(num,cnt[i])%mo;
			num-=cnt[i];
		}
	printf("%d\n",ans);
}

Measured memory_bytes: 4864
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
namespace AtCoder_Beginner_Contest_13
{
    class Program
    {
        //配列にする
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        //Listにする
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
        }
        static void Solve()
        {
            var NK = Sarray();
            var N = NK[0];
            var K = NK[1];
            var Ai = Slist();

            var sum = Ai.Sum();
            var max = Ai.Max();
            var dc = yaku(sum).OrderByDescending(e => e.Key);
            var ans = 0L;
            foreach (var pk in dc)
            {
                Ai.Sort((l, r) => (int)(r % pk.Key - l % pk.Key));
                var pls = new long[N + 1];
                var mns = new long[N + 1];
                for (var i = 1; i < N + 1; ++i)
                {
                    pls[i] = pls[i - 1] + (pk.Key - Ai[i - 1] % pk.Key);
                }
                for (var i = N - 1; 0 <= i; --i)
                {
                    mns[i] = mns[i + 1] + Ai[(int)i] % pk.Key;
                }
                for (var i = 1; i < N ; ++i)
                {
                    if (pls[i] == mns[i] && pls[i] <= K)
                    {
                        ans = Math.Max(ans, pk.Key);
                        break;
                    }
                }
            }
            if (max > 0)
                ans = Math.Max(1, ans);
            WriteLine(ans);
        }
        static Dictionary<long, long> yaku(long n)
        {
            var ret = new Dictionary<long, long>();
            for (long i = 1; i * i <= n; i++)
            {
                if (n % i == 0)
                {
                    ret[i] = 1;
                    ret[n/i] = 1;
                }
            }
            return ret;
        }
    }
}


Measured memory_bytes: 18016
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef long double     ld;
typedef string          str;
#define all(x)			(x).begin(),(x).end()
#define Sort(x)			sort(all(x))
#define A               first
#define B               second
#define sep             ' '
#define endl            '\n'
#define fast_io         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int MAX1 = 5e5 + 7;

ll a, b, c, T, d, e, l, r, x, y, z, mid, cnt, flag, mod = 1e9+7;
pair <ll, ll> num[MAX1];
vector <ll> vec;

int main(){
	cin >> a;
	for (int i = 0; i < a; ++i)	cin >> num[i].A, num[i].B = i+1;
	sort(num, num+a);
	for (int i = 0; i < a; ++i)	cout << num[i].B << sep;
    return 0;
}
/*                          now or never                         */


Measured memory_bytes: 8576
#include<bits/stdc++.h>
#define ll long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define re register
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define per(i,n,m) for(int i=m;i>=n;i--)
#define rrep(i,m,n) for(register int i=m;i<=n;i++)
#define rper(i,n,m) for(register int i=m;i>=n;i--)
#define ull unsigned  long long
using namespace std;
const int INF =1e9+10;
const int N = 5e2 + 10;
int a[N][N];
int ans;
struct node{
    int x,y,x1,y1;
    void output(){
        printf("%d %d %d %d\n",x,y,x1,y1);
    }
};
vector<node> g;
signed main() {
    int h,w;
    si(h);
    si(w);
    rep(i,1,h){
        rep(j,1,w){
            si(a[i][j]);
        }
    }
    rep(i,1,h){
        rep(j,1,w-1){
            if(a[i][j]&1){
                g.push_back({i,j,i,j+1});
                ans++;
                a[i][j+1]++;
            }
        }
    }
    rep(i,1,h-1){
        if(a[i][w]&1){
            ans++;
            g.push_back({i,w,i+1,w});
            a[i+1][w]++;
        }
    }
    printf("%d\n",ans);
    for(auto i:g){
        i.output();
    }
    return 0;
}


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

int main(){
	int n;
	int ans=0;
	std::vector<int> aList;
	std::vector<bool> isSame;

	std::cin>>n;
	aList.resize(n);
	isSame.resize(n, false);

	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	for(int i=0; i<n; i++)
		if(i+1==aList[i])
			isSame[i]=true;

	for(int i=0; i<n; i++){
		if(i==n-1){
			if(isSame[i])
				ans++;
			break;
		}

		if(isSame[i] && !isSame[i+1])
			ans++;

		if(isSame[i] && isSame[i+1])
			ans++, i++;		
	}


	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <vector>
#include <bitset>
#include <queue>
using namespace std;

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(a > c){
        swap(a, c);
        swap(b, d);
    }
    int time = min(b, d)-c;
    if(time < 0){
        cout << 0 << endl;
    }else{
        cout << time << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
int main()
{
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
    ll n;
    cin>>n;
    ll a[n],b[n];
    ll sum1 = 0 ,sum2 = 0;
    ll ans = 0;
    for(ll i=0;i<n;i++)   cin>>a[i] , sum1 += a[i];
    for(ll i=0;i<n;i++)   cin>>b[i] , sum2 += b[i];
    if(sum1<sum2)   return cout<<-1,0;
    vector<ll> extra;
    for(ll i=0;i<n;i++)  if(a[i]>b[i])  extra.pb(a[i]-b[i]);
    sort(extra.rbegin(),extra.rend());
    ll index = 0;
    for(ll i=0;i<n;i++) 
    {
    	if(a[i]<b[i])
    	{
    		ans++;
    		ll need = b[i]-a[i];
    		if(need<extra[index])   extra[index] -= need;
    		else
    		{
    			while(need>extra[index])
    			{
    				need -= extra[index];
    				index++;
    			}
    			extra[index] -= need;
    		}
    	}
    }
    if(ans==0)    index = -1;
    cout<<ans+index+1;
}


Measured memory_bytes: 2428
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int A[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int i = 0;
  int cnt = 0;
  while (i < N) {
    while (i < N - 1 && A[i + 1] == A[i]) {
      ++i;
    }
    if (i >= N - 1) {
      ++cnt;
      printf("%d\n", cnt);
      return 0;
    }
    if (A[i + 1] < A[i]) {
      while (i < N - 1 && A[i + 1] <= A[i]) {
        ++i;
      }
    } else {
      while (i < N - 1 && A[i + 1] >= A[i]) {
        ++i;
      }
    }
    ++cnt;
    ++i;
  }
  printf("%d\n", cnt);
}

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

int main()
{
  int n;
  int ans = 0;
  while(cin >> n){
    for(int a = 0; a <= 9; a++){
      for(int b = 0; b <= 9; b++){
	for(int c = 0; c <= 9; c++){
	  for(int d = 0; d <= 9; d++){
	    if(n == a + b + c + d)
	      ans++;
	  }
	}
      }
    }    
    cout << ans << endl;
    ans = 0;
  }
}

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

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
  long long int a,b,c,d;
  cin>>a>>b>>c>>d;
  long long int ans = max(a*d,max(a*c,max(b*c,b*d)));
  cout<<ans<<endl;
  return 0;

}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define vll vector<long long>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sll set<long long>
#define si set<int>
#define sti stack<int>
#define stkl stack<ll>
#define qi queue<int>
#define pb push_back
#define ff first
#define ss second
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1e9+7;
using namespace std;
int c=0;

void solve(){
	int n;
	cin>>n;

	vector<pii> a(n);

	for(int i=0;i<n;i++){
		cin>>a[i].ff>>a[i].ss;
	}

	for(int i=0;i<n-2;i++){
		int c=0;
		for(int j=0;j<3;j++){
			if(a[i+j].ff!=a[i+j].ss)
				break;
			else
				c++;
		}

		if(c==3){
			cout<<"Yes"<<endl;
			return;
		}
	}

	cout<<"No"<<endl;
}
 
int main(){
    IOS;
    int q=1;
    //cin>>q;
    while(q--){
    	c++;
        solve();
    }
}


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


int main(){
  int N, Y;
  cin >> N, Y;
    int sum = 0;
  Y = N;
 while(N > 0){
sum += N % 10;
   N /= 10;
   
 }
  if(Y % sum == 0){
   cout << "Yes" << endl; 
  }
  
  else{
   cout << "No" << endl; 
  }
  
}


Measured memory_bytes: 256
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[][] edge = new int[2 * M][2];
		for(int i = 0; i < M; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int[] edge1 = {a, b};
			int[] edge2 = {b, a};
			edge[i] = edge1;
			edge[i + M] = edge2;
		}
		
		int ans = 0;
		ArrayList<ArrayList<Integer>> queue = new ArrayList<ArrayList<Integer>>();
		ArrayList<Integer> s = new ArrayList<Integer>();
		s.add(1);
		queue.add(s);
		
		while(queue.size() != 0){
			
			ArrayList<Integer> state = queue.remove(0);
			if(state.size() == N){
				ans++;
				continue;
			}
			int lastNode = state.remove(state.size()-1);
			
			for(int i = 0; i < 2 * M; i++){
				
				if(edge[i][0] == lastNode){
					int nextNode = edge[i][1];
					if(!state.contains(nextNode)){
						ArrayList<Integer> nextState = new ArrayList<Integer>();
						for(Integer node : state) nextState.add(node);
						nextState.add(lastNode);
						nextState.add(nextNode);
						queue.add(nextState);
					}
				}
			}
		}
		
		System.out.println(ans);
	}
}

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

int main(){
    int N; cin >> N;
    set<int> A;
    bool flg = true;

    for(int i=0; i<N; ++i){
        int a; cin >> a;

        // count(値)は0または1を返す
        if(A.count(a)) flg = false;
        A.insert(a);
    }
    if(flg) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  int data[101]={0};
  int rank[101];
  cin>>n;
  for(int i=0;i<n;i++) rank[i]=1;
  int a,b,c,d;
  
  for(int i=0;i<n*(n-1)/2;i++){
    cin>>a>>b>>c>>d;
    a--;b--;
    if(c<d){
      data[b]+=3;
    }else if(c>d){
      data[a]+=3;
    }else if(c==d){
      data[b]++;
      data[a]++;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(data[i]<data[j]){
	rank[i]++;
      }
    }
    cout<<rank[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    int ans = max(c - (a - b), 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%lf",&n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%lf ",n)
#define dprin(n) printf("%lf\n",n)
#define pri(n) printf("%d ",(int)n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x)     x.begin(),x.end()
#define tc   int tt; scf(tt); while(tt--)
#define inf INT_MAX
#define ninf INT_MIN
#define gcd __gcd
#define bitcount(n) __builtin_popcount(n)
typedef double dd;
using namespace std;
const ll mod =1e9+7;
const int N = 1e6+7;
 
void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B) 
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

int main()
{
    ll n;
    lscf(n);
    ll a[n];

    ll max=ninf,maxIndex=0,min=inf,minIndex=0;

    rep(i,0,n){
    lscf(a[i]);
    }

    ll ans=1000;
    ll count=0;
    rep(i,0,n-1)
    {
        if(a[i+1]<a[i])
        {
            ans=ans+(a[i]*count);
            count=0;
        }
        if(a[i+1]>a[i])
        {
            count+=ans/a[i];
            ans%=a[i];
        }
    }
    
    ans=ans+(a[n-1]*count);
    cout<<ans;
return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0), cout.tie(0)
const ll mod = 10e9 + 7;

int main()
{
    fastio;
    float d,s,t;
    cin>>d>>t>>s;
    if(d/s<=t)cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';   
    return 0;
}


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

using namespace std;

int f(long long x, long long y) {
  int keta_x = 0, keta_y = 0;
  while (x != 0) {
    keta_x++;
    x /= 10;
  }
  while (y != 0) {
    keta_y++;
    y /= 10;
  }
  return max(keta_x, keta_y);
}

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

  int ans = 100;
  for (long long a = 1; a * a <= n; a++) {
    if (n % a != 0) {
      continue;
    }
    long long b = n / a;
    ans = min(ans, f(a, b));
  }
  cout << ans << endl;

  return 0;
}

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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  if(a+k-1>=b-k+1){
    for(int i=a;i<=b;i++){
      cout << i << endl;
    }
  }else{
    for(int i=a;i<a+k;i++){
      cout << i << endl;
    }
    for(int i=b-k+1;i<=b;i++){
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextFloat64() (float64, error) {
	return strconv.ParseFloat(nextString(), 64)
}

func main() {
	scanner.Split(bufio.ScanWords)

	n := 5
	array := make([]float64, n)
	for i := 0; i < n; i++ {
		array[i], _ = nextFloat64()
	}

	// fmt.Println(array)
	fmt.Println(int(array[0] - math.Ceil(math.Max(array[1]/array[3], array[2]/array[4]))))
}



Measured memory_bytes: 1104
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(int)(b); i++)
#define FORD(i, a, b) for (int i=a; i>(int)(b); i--)
#define PPC(x) __builtin_popcount(x)
#define MSB(x) (31 - __builtin_clz(x))
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define ithBit(m, i) ((m) >> (i) & 1)
#define ft first
#define sd second
#ifdef DEBUG
#include "debug.h"
#else
#define dbg(...) 0
#endif
using namespace std;

const int maxN = 1 << 17;

bool vis[maxN];
int T[3][3];

bool checkRow(int i)
{
	FOR(j, 0, 3)
		if (!vis[T[i][j]])
			return false;
		return true;
}

bool checkCol(int j)
{
	FOR(i, 0, 3)
		if (!vis[T[i][j]])
			return false;
		return true;
}

void solve()
{
	FOR(i, 0, 3) FOR(j, 0, 3)
		scanf ("%d", &T[i][j]);
	int n;
	scanf ("%d", &n);
	while (n--)
	{
		int a;
		scanf ("%d", &a);
		vis[a]= true;
	}
	
	bool res = false;
	
	FOR(i, 0, 3)
		if (checkRow(i) or checkCol(i))
			res = true;
			
	if (vis[T[1][1]] and ((vis[T[0][0]] and vis[T[2][2]]) or (vis[T[0][2]] and vis[T[2][0]])))
		res = true;
		
	printf("%s\n", res ? "Yes" : "No");
} 
 
int main()
{
    int t;
    t = 1;//scanf ("%d", &t);
    while (t--)
    	solve();
    return 0;    
}




Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

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<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }


int n, p;
long long a, b;
long long tot[10000];

int main() {
    while (cin >> n) {
        if (n == 0) break;
        memset(tot, -1, sizeof(tot));
        vector<int> sya;
        for (int i = 0; i < n; ++i) {
            cin >> p >> a >> b;
            if (tot[p] == -1) {
                sya.PB(p);
                tot[p] = 0;
            }
            tot[p] += a*b;      
        }
        int con = 0;
        for (int i = 0; i < sya.size(); ++i) {
            if ( tot[sya[i]] >= 1000000) {
                cout << sya[i] << endl;
                ++con;
            }
        }
        if (con == 0) puts("NA");
    }
    return 0;
}


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

int main(){
    int n,i,len,j=0,k=0,len2;
    char a[110],b[55],c[55],ch;
    
    scanf("%d",&n);
    scanf("%s",a);
    
    if(n%2!=0){
        printf("No\n");
    }
    
    else{
        len=n/2;
        len2=len+len;
        
        for(i=0;i<len;i++){
            ch=a[i];
            b[j]=ch;
            j++;
        }
        b[j]='\0';
        
        for(i=len;i<len2;i++){
            ch=a[i];
            c[k]=ch;
            k++;
        }
        c[k]='\0';
        
      //  printf("%s %s\n",b,c);
        
        if(strcmp(b,c)==0){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
        
    }
    
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void){
	int x,y;
	scanf("%d %d", &x, &y);
	int a=2*x-1, b=2*y-1, c=x+y;
	if(a>=b && a>=c)printf("%d\n", a);
	else if(b>=a && b>=c)printf("%d\n", b);
	else if(c>=b && c>=a)printf("%d\n", c);
	return 0;


}

Measured memory_bytes: 128
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();

		int num = a.length();
		String c[] = new String[num];
		String d[] = new String[num];

		for(int i=0;i<num;i++) {
			c[i] = a.substring(i, i+1);
			d[i] = b.substring(i, i+1);
		}

		int judge = 0;
		int t = 0;

		for(int i=0;i<num;i++) {
			judge = 1;
			for(int j=0;j<num;j++) {
				t = (j + i)%num;
				if(!c[j].equals(d[t])) {
					judge = 0;
					break;
				}
			}
			if(judge == 1) {
				break;
			}

		}

		if(judge == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}


	}
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<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;}


int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


ll solve(vector<int> A) {
  const int N = A.size();
  sort(ALL(A));
  deque<int> ans;
  int l = 0, r = N-1;
  ans.push_back(A[l]);
  l++;
  while ((int)ans.size() < N) {
    int val = -1;
    int move = 0;
    if (val < abs(ans.back() - A[l])) {
      val = abs(ans.back() - A[l]);
      move = 0;
    }
    if (val < abs(ans.back() - A[r])) {
      val = abs(ans.back() - A[r]);
      move = 1;
    }
    if (val < abs(ans.front() - A[l])) {
      val = abs(ans.front() - A[l]);
      move = 2;
    }
    if (val < abs(ans.front() - A[r])) {
      val = abs(ans.front() - A[r]);
      move = 3;
    }

    if (move == 0) { ans.push_back(A[l]); l++; }
    if (move == 1) { ans.push_back(A[r]); r--; }
    if (move == 2) { ans.push_front(A[l]); l++; }
    if (move == 3) { ans.push_front(A[r]); r--; }
  }

  ll d = 0;
  for (int i = 1; i < N; i++) {
    d += abs(ans[i-1] - ans[i]);
  }
  return d;
}

int main2() {
  int N = nextInt();
  vector<int> A(N);
  REP(i, N) A[i] = nextInt();

  ll ans1 = solve(A);
  REP(i, N) A[i] *= -1;
  sort(ALL(A));
  ll ans2 = solve(A);
  cout << max(ans1, ans2) << endl;

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 1496
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
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;}

set<int>ng={'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};

signed main()
{
	IOS();
	string s;
	vector<int>ans;
	while(1){
		cin>>s;
		if(s=="#")break;
		int flg,cnt = 0;
		rep(i,0,s.size()){
			if(i){
				if(ng.count(s[i])!=flg){
					flg ^= 1;
					cnt++;
				}
			}else flg = ng.count(s[i]);
		}
		ans.push_back(cnt);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}



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

vector<vector<int>> adj;
vector<int> distu;
vector<int> distv;
vector<bool> leaf;
 
void dfs(int v, int p, bool flag)
{
	if(adj[v].size() == 1) leaf[v] = 1;
	for(int i = 0; i < adj[v].size(); i++) if(adj[v][i] != p)
	{
		if(!flag) distu[adj[v][i]] = distu[v] + 1;
		else distv[adj[v][i]] = distv[v] + 1;
		dfs(adj[v][i], v, flag);
	}
}
 
int main()
{
    
    int n, u, v; cin >> n >> u >> v;
    u--; v--;
    adj.resize(n);
    distu.resize(n);
    distv.resize(n);
    leaf.resize(n);
    distu[u] = 0;
    distv[v] = 0;
    for(int i = 0; i < n; i++) leaf[i] = 0;
    for(int i = 0; i < n - 1; i++)
    {
    	int a, b; cin >> a >> b;
    	a--; b--;
    	adj[a].push_back(b);
    	adj[b].push_back(a);
    }
    dfs(u, -1, 0);
    dfs(v, -1, 1);
    int best = 0;
   	for(int i = 0; i < n; i++) if(leaf[i] && (distu[i] < distv[i]))
   		best = max(best, distv[i] - 1);
   	cout << best;
 
    return 0;
}

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

using namespace std;
typedef long long ll;
#define tr(container, it) \
	for (auto it = container.begin(); it != container.end(); it++)
#define scontains(c,x) ((c).find(x) != (c).end())   //O(log n) 
#define contains(c,x) (find((c).begin(),(c).end(),x) != (c).end()) //O(n)
#define Ichar(_x) char _x;scanf("%c",&_x);
#define Iint(_x) int _x;scanf("%d",&_x); 
#define Ill(_x)  ll _x;scanf("%lld",&_x);
#define inc(a,b,x)(x)>a && (x)<b	
#define incE(a,b,x)(x)>=a && (x)<=b	
#define max(a,b) (a)>=(b)? (a) : (b) 
#define fileio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
const double pi = 3.14159265358979323846;

int main()
{
	ll s = 0;
	Iint(a);
	Iint(b);
	Iint(c);
	for (ll i = 0; i < pow(10, 14); )
	{
		i++;
	}
	if(c>=a && c<=a+b)std::cout << "YES";
	else { std::cout << "NO"; }


	
}






Measured memory_bytes: 256
N, K, *P = $<.read.split.map(&:to_i)

pm, n = 0, 2-K
i, Q, min_h, min_t, max_h, max_t = 0, [0]*N, 0, 0, N-1, N-1
until (i+=1) == N
	p = P[i]

#	assert(0 <= min_h <= min_t <= max_t <= max_h < N)
	min_gone = Q[min_h] == i-K
	if p < P[Q[min_h]]
		min_h  = min_t
		min_t -= 1
	else
		min_t -= 1 while p < P[Q[min_t]]
		min_h += 1 if Q[min_h] == i-K
	end
	if P[Q[max_h]] < p
		max_h  = max_t
		max_t += 1
	else
		max_t += 1 while P[Q[max_t]] < p
		max_h -= 1 if Q[max_h] == i-K
	end
	Q[min_t+=1] = Q[max_t-=1] = i
	max_entered = Q[max_h] == i
#	assert(0 <= min_h <= min_t <= max_t <= max_h < N)

	if min_t-min_h+1 == K
		pm = 1
	elsif ! min_gone or ! max_entered
		n += 1
	end
end

p n+pm


Measured memory_bytes: 18428
use std::io::{stdout, Write};
use std::str::FromStr;
use std::thread;

fn run() {
    let stdin = std::io::stdin();
    let mut input = String::new();
    stdin.read_line(&mut input).ok();

    let in_n: i64 = input.trim().parse().unwrap();

    let mut input = String::new();
    stdin.read_line(&mut input).ok();
    let in_x: Vec<u64> = input
        .split_whitespace()
        .map(|s| u64::from_str(s).unwrap())
        .collect();

    let mut y = in_x.clone();
    y.sort();
    let x1 = y[in_n as usize / 2 - 1];
    let x2 = y[in_n as usize / 2];

    let mut out = stdout();
    for x in in_x {
        writeln!(out, "{}", if x <= x1 { x2 } else { x1 }).unwrap();
    }
}

fn main() {
    thread::Builder::new()
        .stack_size(32 * 1024 * 1024) // 32MB
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

/// ローカル環境なら _in.txt から入力を受ける
fn read_input() -> String {
    use std::fs::File;
    use std::io::Read;
    let mut s = String::new();
    match option_env!("LOCAL") {
        Some(_) => File::open("src/_in.txt")
            .expect("File not found")
            .read_to_string(&mut s)
            .unwrap(),
        None => std::io::stdin().read_to_string(&mut s).unwrap(),
    };
    s
}


Measured memory_bytes: 17656
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <iostream>
#include <algorithm>
using namespace std;
long long K, A, B;
int main() {
	cin >> K >> A >> B;
	if (A >= K) cout << 1 << endl;
	else {
		if (A > B) {
			long long p = K - A;
			long long q = A - B;
			cout << (p + q - 1) / q * 2 + 1 << endl;
		}
		else cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll q[200020],h[200020],f[200020],c,n,l,r;
double calc(ll a1,ll b1)
{
	ll dy=f[a1]+h[a1]*h[a1]-f[b1]-h[b1]*h[b1];
	ll dx=h[a1]-h[b1];
	return (double)dy/dx;
}
int main()
{
	cin>>n>>c;
	for(int i=0;i<n;i++)
		cin>>h[i];
	for(int i=1;i<n;i++)
	{
		while(l<r && calc(q[l],q[l+1])<2*h[i])
			l++;
		f[i]=f[q[l]]+(h[q[l]]-h[i])*(h[q[l]]-h[i])+c;
		while(l<r && calc(q[r-1],q[r])>calc(q[r-1],i))
			r--;
		q[++r]=i;
	}
	cout<<f[n-1]<<endl;
	return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define ll long long
#define PI pair<int,int>
#define F first
#define S second
#define all(x) x.begin(),x.end()
using namespace std;
const int MX = 1e5+5;
int a[MX];
int n,m;
struct Job{
    int x,y;
    bool operator<(const Job& j) const{
        if(j.y == y)
            return x < j.x;
        return y < j.y;
    }
};
priority_queue<int> pq;
map<int,vector<int> > mp; 
int main(){
    cin >> n >> m;
    memset(a,0,sizeof(a));
    for(int i=0 ; i<n ; ++i){
        int x,y;
        cin >> x >> y;
        mp[x].push_back(y);
    }
    ll ans = 0;
    for(int i = 1 ; i<=m ; ++i){
        if(mp.count(i)){
            for(auto el : mp[i])
                pq.push(el);
        }
        if(pq.empty())continue;
        ans += 1ll*pq.top();
        pq.pop();
    }
    cout << ans << "\n";
}

Measured memory_bytes: 11264
// 解き直し.
// https://img.atcoder.jp/arc075/editorial.pdf
// C++(GCC 9.2.1)
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)
LL p10[20];

int main(){
    
    // 1. 入力情報.
    LL D;
    scanf("%lld", &D);
    
    // 2. 10 の 冪乗.
    p10[0] = 1;
    rep(i, 19) p10[i + 1] = p10[i] * 10LL;
    // rep(i, 19) printf("%lld\n", p10[i]);
    
    // 3. D の 桁数.
    string strLD = to_string(D);
    int LD = strLD.size();
    
    // 4. L に対応する f(L, d) = D を 計算.
    // d[i] = n[i] - n[L - 1 - i] について, 以下のように解釈を追加する.
    // d[i] の 値 について, n[L - 1] が 0 でないことに注意して, 
    // ① i = 0 の 場合(※ 9 - d[i] 通り).
    // 0 … (1, 1), (2, 2), ..., (9, 9) の 9通り.
    // 1 … (2, 1), (3, 2), ..., (9, 8) の 8通り.
    // ...
    // 8 … (9, 1) の 1通り.
    // 9 … 0通り.
    // 
    // ② i > 0 の 場合(※ 10 - d[i] 通り).
    // 0 … (0, 0), (2, 2), ..., (9, 9) の 10通り.
    // 1 … (1, 0), (2, 1), ..., (9, 8) の 9通り.
    // ...
    // 8 … (9, 1), (8, 0) の 2通り.
    // 9 … (9, 0) の 1通り.
    // d[i] < 0 の 場合も, 絶対値を取って, d[i] > 0 の パターンに帰着.
    function<LL(LL, int, int, int, LL)> f = [&](LL dif, int L, int i, int u, LL ret) {
        // 4-1. 終了条件.
        if(u < i){
            // i の 2倍 が L 未満 の 場合, 10倍する必要があるように見える.
            LL d = (i * 2 < L) ? 10LL : 1LL;
            if(dif == 0) return ret * d;
            else         return 0LL;
        }
        
        // 4-2. 10 の 冪乗.
        LL tP10 = p10[L - 1 - i] - p10[i];
        
        // 4-3. d[i] の 値 を 検討.
        LL q = abs(dif) / tP10;
        // printf("1. L=%d i=%d u=%d tP10=%lld q=%lld dif=%lld\n", L, i, u, tP10, q, dif);
        
        // 4-4. D から 離れすぎている場合.
        if(q > 9){
            // printf("2. Too far away: i=%d u=%d tP10=%lld q=%lld dif=%lld\n", i, u, tP10, q, dif);
            return 0LL;
        }
        
        // 4-5. dif の 正負 で 分岐.
        int sign = (dif >= 0) ? 1 : -1;
        LL dx = (LL)(10 - q - (i == 0)); // dif が 0 以上 か 0未満か.
        LL dif1 = dif - tP10 * q * sign;
        LL dif2 = dif - tP10 * (q + 1) * sign;
        // printf("3. dif >= 0 i=%d dif=%lld dif1=%lld dif2=%lld\n", i, dif, dif1, dif2);
        if(q < 9) return f(dif1, L, i + 1, u, ret * dx) + f(dif2, L, i + 1, u, ret * (dx - 1LL));
        else      return f(dif1, L, i + 1, u, ret * dx);
        return 0LL;
    };
    LL ans = 0LL;
    repx(L, LD, LD * 2 + 1){
        // 上限.
        int uppper = (L / 2) - 1;
        
        // dif = D - Σ((10 の (L - 1 - j)乗 - 10 の j乗) * d[j]) の 計算.
        // ※ 解説上, N - *** と記載されているが, N を D に 読み替えている.
        ans += f(D, L, 0, uppper, 1LL);
    }
    
    // 5. 出力.
    printf("%lld\n", ans);
    return 0;
    
}

Measured memory_bytes: 3792
#include <iostream>
using namespace std;
 
int N, A[10009], sum;
 
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
		while (A[i] % 2 == 0){
			A[i] /= 2; sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
char g1[1000000];
int g2[1000000];
int main() {
	string a;
	cin >> a;
	int ma = 0;
	int s = 0;
	int n = 0;
	while (n < a.length()) {
		int j = n;
		char h = a[n];
		while (a[j] == a[n]) {
			j++;
		}
		g1[s] = h;
		g2[s] = j - n;
		n = j;
		s++;
	}
	for (int i = 1; i < s - 1; i++) {
		if (g1[i] == 'O') {
			if (g1[i - 1] == 'J'&&g1[i + 1] == 'I') {
				if (g2[i] <= g2[i + 1] && g2[i] <= g2[i - 1]) {
					ma = max(ma, g2[i]);
				}
			}
		}
	}
	cout << ma << endl;
}

Measured memory_bytes: 8956
#include <iostream>
#include <math.h>
using namespace std;
int main() {
int n;
int m[n];
int min=1100;
int x;
cin>>n;
cin>>x;
for(int i=0;i<n;i++){
  cin>>m[i];
  x-=m[i];
  if(m[i]<min) min=m[i];
  }
int count;
count=n+(x/min);
cout<<count<<endl;
return 0;
}
 

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
#include<bitset>
using namespace std;

int main() {
	int n; cin >> n;
	int x[n], y[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
		y[i] = x[i];
	}
	sort(y, y + n);
	int middle = y[(n / 2) - 1];//左側
	for (int i = 0; i < n; i++) {
		if (x[i] <= middle)cout << y[n / 2] << endl;
		else cout << middle << endl;
	}
}

Measured memory_bytes: 5096
def solve(n, ps):
    base = list(range(1, n + 1))
    res = 0
    for i in range(n):
        if base[i] == ps[i]:
            if i < n - 1:
                ps[i], ps[i + 1] = ps[i + 1], ps[i]
            else:
                ps[i], ps[i - 1] = ps[i - 1], ps[i]
            res += 1
    return res


def main():
    n = int(input())
    ps = [int(p) for p in input().split()]
    print(solve(n, ps))


if __name__ == '__main__':
    main()


Measured memory_bytes: 13880
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define maxin(v) *max_element(v.begin(), v.end())
#define minin(v) *min_element(v.begin(), v.end())
#define sumall(vect) accumulate(vect.begin(), vect.end(), 0)
#define count(x, vect) count(vect.begin(), vect.end(), x)
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 100000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "------------------------------------\n"
//#define min(a, b, c) min(a, min(b, c))
//#define max(a, b, c) max(a, max(b, c))
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp;
string str;
set<ll> s;
vll v;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a,b;
	cin>>a>>b;
    cout<<(a*b)/__gcd(a,b);
	
	
} 

Measured memory_bytes: 256
#include <stdio.h>

int rot[24][7] = {
	{ 0,1,2,3,4,5,6 },{ 0,1,3,5,2,4,6 },{ 0,1,4,2,5,3,6 },{ 0,1,5,4,3,2,6 },
	{ 0,2,6,3,4,1,5 },{ 0,2,3,1,6,4,5 },{ 0,2,1,4,3,6,5 },{ 0,2,4,6,1,3,5 },
	{ 0,3,1,2,5,6,4 },{ 0,3,2,6,1,5,4 },{ 0,3,5,1,6,2,4 },{ 0,3,6,5,2,1,4 },
	{ 0,4,1,5,2,6,3 },{ 0,4,2,1,6,5,3 },{ 0,4,5,6,1,2,3 },{ 0,4,6,2,5,1,3 },
	{ 0,5,1,3,4,6,2 },{ 0,5,3,6,1,4,2 },{ 0,5,4,1,6,3,2 },{ 0,5,6,4,3,1,2 },
	{ 0,6,2,4,3,5,1 },{ 0,6,3,2,5,4,1 },{ 0,6,5,3,4,2,1 },{ 0,6,4,5,2,3,1 } };
int assign[7];


int main(void)
{
	int i, j, k, l;
    int n;
	int a[1002][7], b[7], dice[7];

    scanf("%d", &n);
	for (k = 0; k < n; k++){
        for (i = 1; i <= 6; i++) scanf("%d", &a[k][i]);
    }

	for (k = 1; k < n; k++){
        for (l = 0; l < k; l++){
            for (j = 0; j < 24; j++) {
                
                for (i = 1; i <= 6; i++) dice[i] = rot[j][i];
                for (i = 1; i <= 6; i++) b[i] = a[l][dice[i]];
                for (i = 1; ; i++) {
                    if (i > 6){ 
                        puts("No");
                        return 0;
                    }    
                    if (a[k][i] != b[i]){
                        break;
                    }
                }

            }
            
        }
    }
	puts("Yes");
	return (0);
}


Measured memory_bytes: 2096
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<(int)n;i++)

using namespace std;


int main()
{
	int w;
	cin>>w;
	while(w!=-1)
	{
		int ans=0;
		
		if(1)
		{
			w-=10;
			ans+=1150;
		}
		
		if(w>0)
		{
			
			ans+=125*min(10,w);
			w-=min(w,10);
		}
		
		if(w>0)
		{
			
			ans+=140*min(10,w);
			w-=min(w,10);
		}
		
		if(w>0)
		{
			ans+=w*160;
		}
		
		cout<<4280-ans<<endl;
		
		
		
		
		cin>>w;
	}
}

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	string s,t; cin>>s>>t;
	int ans=0;
	for(int i=0;i<3;++i)if(s.at(i)==t.at(i))++ans;
	cout<<ans<<"\n"s;
}


Measured memory_bytes: 3556
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 1000005
#define MOD 998244353

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

ll inv[SIZE],fac[SIZE],finv[SIZE];
void make()
{
	fac[0]=fac[1]=1;
	finv[0]=finv[1]=1;
	inv[1]=1;
	for(int i=2;i<SIZE;i++)
	{
		inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
		fac[i]=fac[i-1]*(ll) i%MOD;
		finv[i]=finv[i-1]*inv[i]%MOD;
	}
}
ll C(int a,int b)
{
	if(a<b) return 0;
	return fac[a]*(finv[b]*finv[a-b]%MOD)%MOD;
}
ll mpow(ll m,ll t)
{
	if(t==0) return 1;
	ll ret=mpow(m,t/2);
	ret=ret*ret%MOD;
	if(t%2==1) ret=ret*m%MOD;
	return ret;
}
int main()
{
	make();
	int n,m;
	scanf("%d %d",&n,&m);
	ll ret=0;
	for(int k=0;k<=min(n,m);k++)
	{
		ll sum=mpow(n+1,m-k)*mpow(m+1,n-k)%MOD;
		sum*=C(m,k)*C(n,k)%MOD;
		sum%=MOD;
		sum*=fac[k];
		sum%=MOD;
		if(k%2==0) ret+=sum;
		else ret-=sum;
		ret+=MOD;
		ret%=MOD;
		//printf("%lld\n",sum);
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 23552
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int  n,c; cin >> n >> c;
    int d[c][c];
    rep(i,c)rep(j,c) cin >> d[i][j];
    int col[n][n];
    rep(i,n)rep(j,n) cin >> col[i][j];
    unordered_map<int,int> cc1,cc2,cc3;
    rep(i,n)rep(j,n){
        if((i+j)%3==0) cc1[col[i][j]]++;
        if((i+j)%3==1) cc2[col[i][j]]++;
        if((i+j)%3==2) cc3[col[i][j]]++;
    }
    //cout << cc1[3]+cc2[3]+cc3[3] << endl;

    int ans=INF;
    rep(i,c)rep(j,c)rep(k,c){
        if(i==j || i==k || j==k) continue;
        int tmp=0;
        rep(z,c){
            tmp+=d[z][i]*cc1[z+1];
            tmp+=d[z][j]*cc2[z+1];
            tmp+=d[z][k]*cc3[z+1];
        }
        ans=min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4580
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;


#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

// 二項係数計算
ll 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;
}

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

bool isUru(ll Y){
    if(Y%400==0){ return true;}
    else if(Y%100==0){ return false;}
    else if(Y%4==0){ return true;}
    else{ return false; }
}

pair<ll,ll> dp[50][50];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> vec(n,0);
    rep(i,n){
        ll a;
        cin>>a;
        vec[i]=a;
        rep(j,a){
            cin>>dp[i][j].first>>dp[i][j].second;
            dp[i][j].first--;
        }
    }
    ll res=0;
    for (ll bit=0; bit<(1<<n); ++bit) {
        
        bool check=true;
      for (ll i=0; i < n; ++i) {
       if (bit & (1<<i)) {
        rep(j,vec[i]){
        if(dp[i][j].second == 1 && !(bit & (1 << dp[i][j].first))){
            check=false;
            break;
            }
        if(dp[i][j].second == 0 && (bit & (1 << dp[i][j].first))){
            check=false;
            break;
            }
                }
            }
        }
        if(check){
            ll count=0;
            rep(j,n) if (bit & (1<<j)) count++;
            res=max(res,count);
        }
      }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256