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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

bool ok(int w,const vi& xs,int sp)
{
	int n=xs.size();
	vi sum(n+1);
	rep(i,n) sum[i+1]=sum[i]+xs[i];
	
	vi dp(n+1); dp[0]=1;
	int l=0,r=0,cnt=0;
	rep(i,n){
		for(;l<i;cnt-=!!dp[l++]) if(sum[i+1]-sum[l]+(i-l)<=w) break;
		for(;r<i;cnt+=!!dp[r++]) if(sum[i+1]-sum[r]+(i-r)*sp<w) break;
		dp[i+1]=!!cnt;
	}
	
	int res=dp[n];
	for(int i=n;i--;){
		if(sum[n]-sum[i]+(n-i-1)>w) break;
		res|=dp[i];
	}
	return res;
}

int main()
{
	for(int w,n;~scanf("%d%d",&w,&n) && w|n;){
		vi xs(n);
		rep(i,n) scanf("%d",&xs[i]);
		
		int lo=1,hi=w;
		while(lo<hi){
			int mi=(lo+hi)/2;
			if(ok(w,xs,mi))
				hi=mi;
			else
				lo=mi+1;
		}
		printf("%d\n",lo);
	}
}

Measured memory_bytes: 1736
import java.util.*;
import java.io.*;

class Main {
  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st;
    
    int n = Integer.parseInt(br.readLine());
    st = new StringTokenizer(br.readLine());
    int a[] = new int[n];
    for(int i=0 ; i<n ; i++) {
      a[i] = Integer.parseInt(st.nextToken());
    }
    
    long lcmans = a[0];
    for(int i=1 ; i<n ; i++) {
      lcmans = lcm(lcmans, a[i]);
    }
    
    long sum = 0;
    for(int i=0 ; i<n ; i++) {
      sum += lcmans/a[i];
    }
    
    System.out.println((double)lcmans/sum);
  }
  
  static long gcd(long a, long b) {
    return (b==0) ? a : gcd(b,a%b);
  }
  
  static long lcm(long a, long b) {
    return (a*b)/gcd(a,b);
  }
}


Measured memory_bytes: 20948
def bubble(A):
    #标记是否需要继续冒泡
    flag =True;
    n=len(A)
    i=0
    while flag:
        flag=False
        for j in range(n-1,i,-1):
           if A[j][1]<A[j-1][1]:
               A[j],A[j-1]=A[j-1],A[j]
               flag=True
        i+=1


#选择排序法
def selection(A):
    n=len(A)
    for i in range(n):
        minj=i
        for j in range(i,n):
            if A[j][1]<A[minj][1]:
                minj=j
        if i!=minj:
            A[i],A[minj]=A[minj],A[i]
            
  
          
n=int(input())
ss=[x for x in input().split()]     
ss2=ss.copy()


bubble(ss)
for i in range(len(ss)-1):
    print(ss[i],end=' ')
print(ss[-1])
print('Stable')
   

selection(ss2)
for i in range(len(ss2)-1):
    print(ss2[i],end=' ')
print(ss2[-1])
if ss==ss2:
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5616
package main

import "fmt"

func main() {
	var N, Y int
	fmt.Scan(&N, &Y)
	for i := 0; i <= N; i++ {
		for j := 0; j <= N; j++ {
			k := Y/1000 - 10*i - 5*j
			if 0 <= k && (i+j+k) == N {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"Yes":"N1010o"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    int n = gi, y = gi;
    ZeroToN(i1, n) {
        ZeroToN(i2, n-i1) {
            int i3 = (n-i1-i2);
            if (i1 * 10000 + i2 * 5000 + i3 * 1000 == y) {
                vec<int> res = {i1,i2,i3};
                print(res);
                return;
            }
        }
    }
    print("-1 -1 -1");
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include<bits/stdc++.h>

using namespace std;
 
#define  GODSPEED       ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(15);
#define  f              first                 
#define  s              second
#define  newl           cout<<"\n";
#define  pb             push_back  
#define  mset(a,x)      memset(a,x,sizeof(a))
#define  debv(a)        for(auto it: a)cout<<it<<" ";newl;
#define  deb1(a)        cout<<a<<"\n";
#define  deb2(a,b)      cout<<a<<" "<<b<<"\n";
#define  deb3(a,b,c)    cout<<a<<" "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)  cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
#define  uniq(a)        a.resize(unique(a.begin(), a.end()) - a.begin());
#define  all(a)         a.begin(),a.end()           
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;

const ll   N     =  3e5+5;
const ll   mod   =  1e9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   LEVEL =  log2(N)+1;

ll test = 1, n, x, t;

void solve(){
	cin >> n >> x >> t;
	deb1((ll)ceil((ld)n/x)*t)
}

int main(){
	GODSPEED;
	//cin>>test;
	for(int i = 1; i <= test; i++){
		solve();
	}
	#ifndef ONLINE_JUDGE
	cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
	#endif
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

#define MAX_N (100000)
#define INF (1000000000 + 1)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int n, as[MAX_N];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &as[i]);
  }

  // sort
  sort(as, as + n);

  // solve
  const int i = n - 1, a_i = as[n - 1];
  const int k_max0 = a_i / 2, k_max1 = (a_i + 1) / 2;
  const int k_max2 = a_i - k_max0, k_max3 = a_i - k_max1;
  int d_max = INF, a_j_max = -1;
  for (int j = 0; j < n; j++) {
    const int a_j = as[j];
    const int d =
        min(abs(a_j - k_max0),
            min(abs(a_j - k_max1), min(abs(a_j - k_max2), abs(a_j - k_max3))));
    if (d < d_max) {
      a_j_max = a_j;
      d_max = d;
    }
  }
  printf("%d %d\n", a_i, a_j_max);

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    auto calc = [&](int x) {
        int ret = 0;
        int n = s.size();
        rep(i, n) {
            int k = s[i] - '0';
            if(((i+x)&1) != k) ++ret;
        }
        return ret;
    };
    cout << min(calc(0), calc(1)) << endl;
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define LL long long
#define db long double

using namespace std;
const int N=(1<<20)+10;
int rd()
{
    int x=0,w=1;char ch=0;
    while(ch<'0'||ch>'9'){if(ch=='-') w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+(ch^48);ch=getchar();}
    return x*w;
}
int n,f1[N],f2[N],z1[N],z2[N],an[N];
vector<int> e1[N],e2[N],ee[N];
bool vs[N];
int d1(int x)
{
    int nn=e1[x].size(),an=!z1[x]?x:0;
    for(int i=0;i<nn;++i)
    {
	int y=e1[x][i],w=d1(y);
	if(!an||!w) an|=w;
	else
	{
	    ee[an].push_back(w),ee[w].push_back(an);
	    an=0;
	}
    }
    return an;
}
int d2(int x)
{
    int nn=e2[x].size(),an=!z2[x]?x:0;
    for(int i=0;i<nn;++i)
    {
	int y=e2[x][i],w=d2(y);
	if(!an||!w) an|=w;
	else
	{
	    ee[an].push_back(w),ee[w].push_back(an);
	    an=0;
	}
    }
    return an;
}

int main()
{
///////
    n=rd();
    for(int i=1;i<=n;++i)
    {
	f1[i]=rd();
	if(~f1[i]) e1[f1[i]].push_back(i),z1[f1[i]]^=1;
    }
    for(int i=1;i<=n;++i)
    {
	f2[i]=rd();
	if(~f2[i]) e2[f2[i]].push_back(i),z2[f2[i]]^=1;
    }
    for(int i=1;i<=n;++i)
	if(z1[i]^z2[i]){puts("IMPOSSIBLE");return 0;}
    puts("POSSIBLE");
    for(int i=1;i<=n;++i)
	if(f1[i]<0){d1(i);break;}
    for(int i=1;i<=n;++i)
	if(f2[i]<0){d2(i);break;}
    queue<int> q;
    for(int i=1;i<=n;++i)
	if(!z1[i]&&!vs[i])
	{
	    an[i]=-1,vs[i]=1,q.push(i);
	    while(!q.empty())
	    {
		int x=q.front();
		q.pop();
		int nn=ee[x].size();
		for(int j=0;j<nn;++j)
		{
		    int y=ee[x][j];
		    if(!vs[y]) vs[y]=1,an[y]=-an[x],q.push(y);
		}
	    }
	}
    for(int i=1;i<=n;++i) printf("%d ",an[i]);
    return 0;
}
 


Measured memory_bytes: 90368
#include<bits/stdc++.h>
#define up(j,k,i) for(ll i=j;i<k;i++)
#define down(j,k,i) for(ll i=j;i>k;i--)
#define M 1000000007
#define pp(n) printf("%lld\n",ll(n))
#define ps(n) printf("%lld ",ll(n))
#define pd(x,y) printf("%lld %lld\n",ll(x),ll(y))
#define is(n) scanf("%lld",&n)
#define inf LLONG_MAX
#define id(n,m) scanf("%lld%lld",&n,&m)
#define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define ss(s) scanf("%s",s)
#define cool 0
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll> 
#define db cout<<"######\n"
#define null(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,255,sizeof(a))
typedef long double ld;
typedef long long int ll;
using namespace std;
ll i,j,k,z,t,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag;
map<set<ll>,bool> b;
int main()
{
	it(x,y,z);
	
	while(1)
	{
		set<ll> s;
		
		s.insert(x);
		s.insert(y);
		s.insert(z);
		
		if(b[s])
		{
			pp(-1);
			return 0;
		}
		else
		b[s]=true;
		
		if(x%2 or y%2 or z%2)
		{
			pp(ans);
			return 0;
		}
		
		
		ll tx=x,ty=y,tz=z;
		
		x=ty/2+tz/2;
		y=tx/2+tz/2;
		z=tx/2+ty/2;
		ans++;
		
	}
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  int n, i;
  cin >> n;
  vi x(n);
  double sum = 0;

  REP(i, 0, n){
      cin >> x[i];
      sum += x[i];
  }

  sum /= n;
  int ans = 0;
  int ans2 = 0;

  REP(i, 0, n) {
   	ans += (ceil(sum) - x[i]) * (ceil(sum) - x[i]);
    ans2 += (floor(sum) - x[i]) * (floor(sum) - x[i]);
  }

  cout << (int)min(ans, ans2) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(All(a));
    int res=0;
    for(int i=0;i<(n-2)/2;i++)res-=2*a[i];
    for(int i=(n-2)/2+2;i<n;i++)res+=2*a[i];
    res-=a[(n-2)/2];
    n%2?res-=a[(n-2)/2+1]:res+=a[(n-2)/2+1];
    if(n%2){
        int p=0,m=0;
        for(int i=0;i<n/2;i++)m+=2*a[i];
        for(int i=n/2+2;i<n;i++)p+=2*a[i];
        p+=a[n/2]+a[n/2+1];
        res=max(res,p-m);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
sx, sy, tx, ty = list(map(int, input().split()))

ans = 'R'
x = tx - sx
y = ty - sy
for _ in range(x-1):
    ans += 'R'
for _ in range(y):
    ans += 'U'
for _ in range(x):
    ans += 'L'
for _ in range(y):
    ans += 'D'
ans += 'LU'
for _ in range(y):
    ans += 'U'
for _ in range(x):
    ans += 'R'
ans += 'RD'
ans += 'RD'
for _ in range(y):
    ans += 'D'
for _ in range(x):
    ans += 'L'
ans += 'LU'

print(ans)


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

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[], int n, int g) {
  for (int i = g; i < n; i ++) {
    int v = A[i];
    int j = i - g;
    while (j >= 0 && A[j] > v) {
      A[j + g] = A[j];
      j -= g;
      cnt ++;
    }
    A[j+g] = v;
  }
}

void shellSort(int A[], int n) {
  for (int h = 1; ; ) {
    if (h > n) break;
    G.push_back(h);
    h = 3 * h + 1;
  }

  for (int i = G.size()-1; i >= 0; i --) {
    insertionSort(A, n, G[i]);
  }
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i ++) scanf("%d", &A[i]);
  cnt = 0;

  shellSort(A, n);

  cout << G.size() << endl;
  for (int i = G.size() - 1; i >= 0; i --) {
    printf("%d", G[i]);
    if (i) printf(" ");
  }
  printf("\n");
  printf("%d\n", cnt);
  for (int i = 0; i < n; i ++) printf("%d\n", A[i]);
}



Measured memory_bytes: 7056
//ｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwｺｹｯwwwｺｹｯｺｯwwwｺｯwwｺｯwwｺｹｯwwwｺｯwwwｺｹｯwwwｺｹｯｺｯwwwｺｹｰｰｰｰｯ!!!wwwwwｺｹｯｺｯｯｺｰｰｰｰ!!!!!!wwwwwwwwwww
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[m];
        for(int i = 0 ; i < n ; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0 ; i < m ; i++){
            b[i] = sc.nextInt();
        }
        sc.close();
        Arrays.sort(a);
        Arrays.sort(b);
        if(a[n - 1] > b[0]){
            System.out.println("War");
        }else{
            boolean ebishu = true;
            for(int i = a[n - 1] + 1 ; i <= b[0] && ebishu ; i++){
                if(x < i && i <= y){
                    System.out.println("No War");
                    ebishu = false;
                }
            }
            if(ebishu)System.out.println("War");
        }
    }
}

Measured memory_bytes: 36140
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

ll ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
	while(z[++Z]=x%10+48,x/=10);
	while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}
ll a[200200];
int main()
{
	int n,k;
	read(n);read(k);
	for (int i=1;i<=k;i++) a[i]=n/k;
	for (int i=1;i<=n%k;i++) a[i]++;
	ans=a[k]*a[k]*a[k];
	if (k%2==0)
		ans+=a[k/2]*a[k/2]*a[k/2];
	cout<<ans;
	return 0;
}









Measured memory_bytes: 3840
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))

count = 0

for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        b[i] -= a[i]
        a[i] = 0
    else:
        count += b[i]
        a[i] -= b[i]
        b[i] = 0
    if a[i+1] < b[i]:
        count += a[i+1]
        b[i] -= a[i+1]
        a[i+1] = 0
    else:
        count += b[i]
        a[i+1] -= b[i]
        b[i] = 0

print(count)


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

using namespace std;

long long gcd(long long x,long long y){
	if(x==0) return y;
    return gcd(y%x, x);
}

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

	long long t;
	long long a,b,c,d;

	cin >> t;

	for (int i = 0;i < t;i++){
		cin >> a >> b >> c >> d;
		if(b > a){cout << "No" << endl;continue;}
		else if(b > d){cout << "No" << endl;continue;}
		else if(c >= b){cout << "Yes" << endl;continue;}
		long long g = gcd(b,d);
		if(b-g+a%g > c){cout << "No" << endl;continue;}
		else {cout << "Yes" << endl;continue;}
	}	

	return 0;

}

Measured memory_bytes: 256
S = input()
#print(S)

mae = int(S[:2])
ato = int(S[2:])
#print(mae, ato)

if (mae >= 13 or mae == 0) and (ato <= 12 and ato != 0):
    print('YYMM')
elif (mae <= 12 and mae != 0) and (ato >= 13 or ato == 0):
    print('MMYY')
elif (mae <= 12 and ato <= 12) and (mae != 0 or ato != 0):
    print('AMBIGUOUS')
else:
    print('NA')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
using namespace std;
typedef long long int ll;
const int k_mod = 1e9 + 7;

int main(void){
	int n;
	cin >> n;
	int* array = new int[n];
	rep(i,0,n){
		cin >> array[i];
	}
	int* dp = new int[n];
	dp[0] = 0;
	dp[1] = abs(array[0]-array[1]);
	rep(i,2,n){
		dp[i] = min(dp[i-2] + abs(array[i] - array[i-2]), dp[i-1] + abs(array[i] - array[i-1]));
	}
	printf("%d\n", dp[n-1]);
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VL xs(N);
  REP(i,N) cin >> xs[i];
  SORT(xs);

  VL acc(N+1);
  REP(i,N) acc[i+1] = acc[i] + xs[i];

  int ans = 1;
  for(int i=N-2;i>=0;--i){
	if(acc[i+1]*2 >= xs[i+1])
	  ++ans;
	else break;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1792
//Heaplax
//别让自己后悔
#include<bits/stdc++.h>
#define N 200005
#define LL long long
#define LOG(x) cerr<<#x<<" = "<<x<<endl
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;
}
using namespace std;
int n,k;
char s[N];
deque<int> que;
int main()
{
	re(n),re(k);
	scanf("%s",s+1);
	for(int i=1;i<=n;++i)
		if(s[i]=='A')que.push_back(0);
		else que.push_back(1);
	int tag=0;
	for(int i=1;i<=min(k,2*n+10);++i)
	{
		if(tag^que.front())
		{
			que.pop_front();
			tag^=1;
			que.push_back(tag);
		}
		else que.front()^=1;
	}
	if(k<=2*n+10)
	{
		while(!que.empty())
			putchar(tag^que.front()?'B':'A'),que.pop_front();
	}
	else
	{
		k-=2*n+10;
		if(n%2==0)
		{
			for(int i=1;i<=n;++i)
				putchar(i&1?'B':'A');
		}
		else
		{
			if((tag^que.front())==0)k^=1;
			if(k&1)
				for(int i=1;i<=n;++i)
					putchar(i&1?'A':'B');
			else
			{
				putchar('B');
				for(int i=2;i<=n;++i)
					putchar(i&1?'A':'B');
			}
		}
	}
}
/*
BAB
BAA
BBA
ABA
BBA
ABA
*/


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
int main() {
  string s;
  cin >> s;
  rep(i,1<<(3)){
    ll ans=s[0]-'0';
    rep(j,3){
      if((i>>j)%2==1){
        ans+=s[j+1]-'0';
      }
      else{
        ans-=s[j+1]-'0';
      }
    }
    if(ans==7){
      rep(j,3){
        cout << s[j];
        if((i>>j)%2==1){
          cout << "+";
        }
        else{
          cout << "-";
        }
      }
      cout << s[3] << "=7" << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a;
  if(n<10){
    cout<<n;
  }else if(n<100){
    cout<<9;
  }else if(n<1000){
    a=n-99;
    cout<<(9+a);
  }else if(n<10000){
    cout<<909;
  }else if(n<100000){
    a=n-9999;
    cout<<(909+a);
  }else{
    cout<<90909;
  }
}

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

signed main(void)
{
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k)
		cout << s << endl;
	else
		cout << s.substr(0, k) << "..." << endl;
	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <string>

using namespace std;

struct Node
{
	int key;
	Node* parent;
	Node* left;
	Node* right;
};

Node* root;
Node* NIL;

Node* treeMinimum(Node* x)
{
	while (x->left != NIL)
	{
		x = x->left;
	}
	return(x);
}

Node* find(Node* u, int k)
{
	while (u != NIL && k != u->key)
	{
		if (k < u->key)
		{
			u = u->left;
		}
		else
		{
			u = u->right;
		}
	}
	return(u);
}

Node* treeSuccessor(Node* x)
{
	while (x->right != NIL)
	{
		return(treeMinimum(x->right));
	}
	Node* y = x->parent;
	while (y != NIL && x == y->right)
	{
		x = y;
		y = y->parent;
	}
	return(y);
}

void treeDelete(Node* z)
{
	Node* y;
	Node* x;

	if (z->left == NIL || z->right == NIL)
	{
		y = z;
	}
	else
	{
		y = treeSuccessor(z);
	}
	if (y->left != NIL)
	{
		x = y->left;
	}
	else
	{
		x = y->right;
	}
	if (x != NIL)
	{
		x->parent = y->parent;
	}

	if (y->parent == NIL)
	{
		root = x;
	}
	else
	{
		if (y == y->parent->left)
		{
			y->parent->left = x;
		}
		else
		{
			y->parent->right = x;
		}
	}
	if (y != z)
	{
		z->key = y->key;
	}
	delete(y);
}

void insert(int key)
{
	Node* y = NIL;
	Node* x = root;
	Node* z;

	z = new Node;
	z->key = key;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL)
	{
		y = x;
		if (z->key < x->key)
		{
			x = x->left;
		}
		else
		{
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL)
	{
		root = z;
	}
	else
	{
		if (z->key < y->key)
		{
			y->left = z;
		}
		else
		{
			y->right = z;
		}
	}
}

void inOrder(Node* u)
{
	if (u == NIL)
	{
		return;
	}
	inOrder(u->left);
	cout << " " << u->key;
	inOrder(u->right);
}

void preOrder(Node* u)
{
	if (u == NIL)
	{
		return;
	}
	cout << " " << u->key;
	preOrder(u->left);
	preOrder(u->right);
}

void solve()
{
	int m;
	cin >> m;
	for (int i = 0; i < m; ++i)
	{
		string command;
		cin >> command;
		if (command == "insert")
		{
			int key;
			cin >> key;
			insert(key);
		}
		else if (command == "print")
		{
			inOrder(root);
			cout << endl;
			preOrder(root);
			cout << endl;
		}
		else if (command == "find")
		{
			int key;
			cin >> key;
			Node* t = find(root, key);
			if (t != NIL)
			{
				cout << "yes" << endl;
			}
			else
			{
				cout << "no" << endl;
			}
		}
		else if (command == "delete")
		{
			int key;
			cin >> key;
			treeDelete(find(root, key));
		}
	}
}

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

Measured memory_bytes: 19964
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
#ifndef ONLINE_JUDGE
    scanf("%lld", &a);
#else
    scanf("%I64d", &a);
#endif
    return a;
}

int main() {
    char a[4];
    scanf("%s", a);
    if (strlen(a) == 3) {
        char b = a[0];
        a[0] = a[2];
        a[2] = b;
    }

    printf("%s\n", a);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int a,b,c,ans;
    cin>>a>>b>>c;
    if(a>=c) ans=0;
    else if(a+b>=c) ans=c-a;
    else{
        cout<<"NA"<<endl;
        return 0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include<string>
#include<stdio.h>
#include<bitset>

using namespace std;

int main()
{
	int n; cin >> n;
	bool num[40000] = {false}; num[0] = true; int a,max=0;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		for (int d = max;  d >=0;  d--)
		{
			if (num[d])num[d + a] = true;
		}
		max += a;
	}
	int s,z; cin >> s;
	for (int i = 0; i < s; i++)
	{
		cin >> z;
		cout << (num[z] ?  "yes" : "no" )<< endl;
	}
	return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
using namespace std;
int main(void)
{
    int x, y;
    int i, st, large, small;

    for(i = 1; i <= 3000; i++){
        scanf("%d", &x); scanf("%d", &y);
        small = x;
            large = y;
            if(y < small){
                small = y;
                large = x;
            }
        if(x == 0 && y == 0) break;
        else printf("%d %d\n", small, large);
    }
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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


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

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e7
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
using namespace std;

void solve(void)
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    string ans = "No";
    rep(i, k)
    {
        if (b > a && c > b)
        {
            ans = "Yes";
            break;
        }
        else if (b <= a)

            b *= 2;
        else if (c <= b)
            c *= 2;
    }
    if (b > a && c > b)
        ans = "Yes";
    cout << ans << endl;
}
int main(void)
{
    solve();
}

Measured memory_bytes: 3596
n=int(input())
y=lambda:[*map(int,input().split())]
a,b=y(),y()[::-1]
c=0
for i in range(n):
  if a[i]==b[i]:c=a[i]
if c<1:print("Yes");print(' '.join(map(str,b)));quit()
al,bl,ah,bh=[-1]*4
ea=eb=0
for i in range(n):
  if al<0 and a[i]==c:al=i
  if bl<0 and b[i]==c:bl=i
  if al<0:ea+=1
  if bl<0:eb+=1
  if ah<0 and al>=0 and a[i]!=c:ah=i
  if bh<0 and bl>=0 and b[i]!=c:bh=i
if ah<0:ah=n
if bh<0:bh=n
t=ah+bh-al-bl
if ah+bh-al-bl>n:print("No");quit()
o1=min(bh-bl,ea,ea-eb+ah-al)
print("Yes")
print(' '.join(map(str,[c]*o1+b[:eb]+b[eb+bh-bl:]+[c]*(bh-bl-o1))))

Measured memory_bytes: 41524
$h, $w = gets.chomp.split(' ').map(&:to_i)

$map = []

$count_sharp = 0

$h.times do
  line = gets.chomp.split('')
  $count_sharp += line.count { |s| s == '#' }
  $map << line
end

$queue = [[0, 0, 1]]

until $queue.empty?
  i, j, dist = $queue.shift

  if i == $h - 1 && j == $w - 1
    puts $h * $w - dist - $count_sharp
    exit(0)
  end
  next if $map[i][j] == '#'
  $map[i][j] = '#'

  $queue << [i + 1, j, dist + 1] if i + 1 < $h
  $queue << [i - 1, j, dist + 1] if i - 1 >= 0
  $queue << [i, j + 1, dist + 1] if j + 1 < $w
  $queue << [i, j - 1, dist + 1] if j - 1 >= 0
end

puts '-1'


Measured memory_bytes: 3836
from  collections import  deque
H , W = map(int, input().split())
mp = []
for i in range(H):
    mp.append(list(input()))


class node():
    def __init__(self):
        self.wall = 0
        self.reaf = []
        self.tansaku = 0
        self.cost = 0


nodelist = [node() for i in range(H * W)]
count = 0
for i in range(len(mp)):
    for j in range(len(mp[i])):
        if mp[i][j] == "#":
            nodelist[count].wall = 1
        count += 1
count2 = 0
for i in range(len(nodelist)):

    if count2 != 0:
        if nodelist[i-1].wall == 0:
            nodelist[i].reaf.append(i-1)
    if count2 != W-1:
        if nodelist[i+1].wall == 0:
            nodelist[i].reaf.append(i+1)
    if i+W < len(nodelist):
        if nodelist[i+W].wall == 0:
            nodelist[i].reaf.append(i+W)
    if i-W >= 0:
        if nodelist[i-W].wall == 0:
            nodelist[i].reaf.append(i-W)

    count2 += 1
    if count2 == W:
        count2 = 0

def tansaku(nodelist,que):
    data = que.popleft()
    for j in nodelist[data].reaf:
        if nodelist[j].tansaku == 0:
            que.append(j)
            nodelist[j].tansaku = 1
            nodelist[j].cost = nodelist[data].cost + 1
    if len(que) != 0:
        tansaku(nodelist, que)


def nodereset(nodelist):
    for i in range(len(nodelist)):
        nodelist[i].tansaku = 0
        nodelist[i].cost = 0
    return nodelist

maxnum = 0

for i in range(len(nodelist)):
    if nodelist[i].wall == 0:
        nodelist = nodereset(nodelist)
        que = deque()
        que.append(i)
        nodelist[i].tansaku = 1
        tansaku(nodelist, que)
        for j in range(len(nodelist)):
            if nodelist[j].cost > maxnum:

                maxnum = nodelist[j].cost
print(maxnum)


Measured memory_bytes: 61404
from bisect import bisect_left
n,m = map(int,input().split( ))
s = input()
l= len(s)
s_id = []
sm = 0
for i in range(l):
    if not int(s[i]):
        s_id.append(i)

ans = []
now = n
while now>0:
    #print(now)
    nxt = now-m
    j = bisect_left(s_id,nxt)
    if s_id[j] <now-m:
        j+=1
    if s_id[j]==now:
        print(-1)
        exit()
    ans.append(now-s_id[j])
    now = s_id[j]
ans.reverse()
print(*ans)

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

int main() {
  int n, m;
  while (cin >> n >> m) {
    if (!n && !m) break;

    vector<int> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i];

    int goods1 = 0, goods2 = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        if (a[i] + a[j] > goods1 + goods2 && a[i] + a[j] <= m) {
          goods1 = a[i];
          goods2 = a[j];
        }
      }
    }

    if (goods1 + goods2) cout << goods1 + goods2 << endl;
    else cout << "NONE" << endl;
  }

  return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int Q;
    cin >> Q;

    int MAX = 10e6;

    vector<int> prime(MAX, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i * i < MAX; i++)
    {
        if (prime[i])
        {
            for (int j = 2; j * i < MAX; j++)
            {
                prime[i * j] = 0;
            }
        }
    }

    vector<int> N(MAX, 0);
    for (int i = 0; i < MAX; i++)
    {
        if (prime[i] && prime[(i + 1) / 2])
        {
            N[i] = 1;
        }
    }

    vector<int> a(MAX + 1, 0);
    for (int i = 0; i < MAX; i++)
    {
        a[i + 1] = a[i] + N[i];
    }

    for (int i = 0; i < Q; i++)
    {
        int r, l;
        cin >> l >> r;
        cout << a[++r] - a[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 120424
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define LL_MAX LLONG_MAX
#define ULL_MAX ULLONG_MAX
#define ull unsigned long long
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define mk make_pair
#define endl '\n'

bool fun(pair<int,int> a, pair<int,int> b)
{
    return (a.first-a.second > b.first-b.second);
}
int main()
{
    IOS;
    int n;
    cin>>n;
    vector<pair<int,int>> a;
    int clostart=0,opstart=0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin>>s;
        stack<char> q;
        for (int j = 0; j < (int)s.size(); j++)
        {
            if(q.empty()==0)
            {
                if(q.top()=='(' && s[j]==')')
                {
                    q.pop();
                    continue;
                }
            }
            q.push(s[j]);
        }
        int close=0,open=0;
        while(!q.empty())
        {
            if(q.top()=='(')
            {
                close++;
            }
            else
            {
                open++;
            }
            q.pop();
        }
        if(open==0)
        {
            clostart+=close;
        }
        else if(close==0)
        {
            opstart+=open;
        }
        else
        {
            a.eb(mk(close,open));
        }
    }
    sort(a.begin(),a.end(),fun);
    int value=clostart;
    for (int i = 0; i < (int)a.size(); i++)
    {
        value-=a[i].second;
        if(value<0)
        {
            cout<<"No";
            return 0;
        }
        value+=a[i].first;
    }
    value-=opstart;
    if(value==0)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
}


Measured memory_bytes: 5256
/*input
2 0
1 2
*/
#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;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
vector<int> v[maxn];
int dist[maxn];
int bfs(int u,int t){
	queue<int> q;
	q.push(u);
	
	memset(dist,-1,sizeof(dist));
	dist[u]=0;
	while(!q.empty()){
		int z=q.front();
		q.pop();
		for(auto x:v[z]){
			if(dist[x]==-1){
				q.push(x);
				dist[x]=dist[z]+1;
			}
		}
	}
	if(dist[t]==-1) return -1;
	return dist[t]/3;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	REP(i,m){
		int a,b;
		cin>>a>>b;
		--a;
		--b;
		v[a].pb(b+n);
		v[a+n].pb(b+2*n);
		v[a+2*n].pb(b);
	}
	int s,t;
	cin>>s>>t;
	--s;
	--t;
	cout<<bfs(s,t);
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

ll s2ll(string s) {
  ll res = 0;
  for (int i = 0; i < s.size(); i++) {
    res = res * 10 + (s[i] - '0');
  }
  return res;
}

ll dfs(string &s, int p, int w, ll sum) {
  if (p + w == s.size()) return sum + s2ll(s.substr(p, w));
  return dfs(s, p + w, 1, sum + s2ll(s.substr(p, w))) + dfs(s, p, w + 1, sum);
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  string s;
  cin >> s;
  cout << dfs(s, 0, 1, 0) << endl;

  return 0;
}

Measured memory_bytes: 256
#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 watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const int MAXN = 200005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	int a[n];
	forn(i,0,n){
		cin>>a[i];
	}
	
	int cur=1;
	forn(i,0,n){
		if(a[i]==cur) cur++;
	}
	
	if(cur==1) cout<<-1<<'\n';
	
	else cout<<n-(cur-1)<<'\n';
	
	return 0;
}


Measured memory_bytes: 4396
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rrep(i,n) for(ll i##_len=(n) ,i=i##_len-1;i>=0;--i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define printd(val) std::cout<< #val" = " <<val<<"\n";
#include<bits/stdc++.h>
using ll = long long;
using pii = std::pair<ll,ll>;
using namespace std;
template<class T>T chmin(T a,T b){if(a>b){a^=b;b^=a;a^=b;return 1;}return 0;}
template<class T>T chmax(T b,T a){if(a<b){a^=b;b^=a;a^=b;return 1;}return 0;}

ll n;
vector<ll> a;
vector<ll> b;
void input(){
    cin>>n;
    a.resize(n+1);
    b.resize(n);
    for(int i = 0; i < n+1; ++i) {
        cin>>a[i];
    }
    for(int i = 0; i < n; ++i) {
        cin>>b[i];
    }
}
void src(){
    ll count=0;
    for(int i = 0; i < n; ++i) {
        ll win = min(a[i],b[i]);
        count+= win;
        b[i] -= win;
        a[i] -= win;
        ll win2 = min(a[i+1],b[i]);
        count  += win2;
        b[i]   -= win2;
        a[i+1] -= win2;
    }
    cout<<count;
}

int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 1792
#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 n, x, in;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n){
        cin >> in;
        a.at(i) = abs(x - in);
    }
    int ans = a.at(0);
    rep(i, n-1){
        ans = __gcd(ans, a.at(i+1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <cassert>
#include <algorithm>
using namespace std;

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  int L, R, d;
  cin >> L >> R >> d;

  int cnt = 0;
  for(int i = L; i <= R; i++) {
    if(i % d == 0) cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3664
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        List<int> x = Console.ReadLine().Split().Select(int.Parse).ToList();
        x.Add(x.Min());
        x.Sort();
        Console.WriteLine(solve(s[0], s[1], x));
    }
    static int solve(int n, int m, List<int> x) {
        int[] l = new int[m];
        for(int i = 0; i < m; i ++) {
            l[i] = Math.Abs(x[i+1]-x[i]);
        }
        Array.Sort(l);
        Array.Reverse(l);
        for(int i = 0; i < n-1; i ++) {
            l[i] = 0;
            if(i == m-1) break;
        }
        return l.Sum();
    }
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

int dy[]={0, 0, 1, -1, 1, -1, -1, 1};
int dx[]={1, -1, 0, 0, 1, 1, -1, -1};


int main() {
    cout<<fixed<<setprecision(10);

    ll w,h; cin>>w>>h;
    using T = tuple<ll,ll,ll>;
    vector<T> vec;

    rep(i,w){
        ll p; cin>>p;
        vec.emplace_back(p, i, 0);
    }
    rep(j,h){
        ll q; cin>>q;
        vec.emplace_back(q, j, 1);
    }

    sort(ALL(vec));

    ll ans = 0;
    vint cnt(2,0);
    vint num = {w+1, h+1};

    for(auto e:vec){
        ll cost, cur, t;
        tie(cost, cur, t) = e;
        ans += cost*(num[t^1] - cnt[t^1]);
        cnt[t]++;
    }
    cout<<ans<<endl;



    return 0;

}

Measured memory_bytes: 8560
#include<stdio.h>
int main(){
	int n,k,a[1001],b[1001],i,j,s[1001]={0};
	scanf("%d%d",&n,&k);
	for(i=0;i<n;i++)scanf("%d",&a[i]);
	for(i=0;i<k;i++)scanf("%d",&b[i]);
	for(i=0;i<k;i++){
		for(j=0;j<n;j++){
			if(a[j]<=b[i]){
				++s[j];
				break;
			}
		}
	}
	j=0;
	for(i=0;i<n;i++)if(j<s[i])k=i+1,j=s[i];
	printf("%d\n",k);
	return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#define f cin
#define NMAX 200010
using namespace std;

//ifstream f("date.in");

int n, m;
vector <int> a[NMAX];
int interior[NMAX], exterior[NMAX];
int nr, top_sort[NMAX];
int dp[NMAX];
int vis[NMAX];


void dfs(int x) {
    vis[x] = 1;
    for (int i = 0; i < a[x].size(); ++i) {
        if (vis[a[x][i]] == 0) {
            dfs(a[x][i]);
        }
    }
    top_sort[nr++] = x;
}

int main() {

    f >> n >> m;
    for (int i = 0; i < m; ++i) {
        int x, y;
        f >> x >> y;
        x --;
        y --;
        a[x].push_back(y);
        interior[y] ++;
        exterior[x] ++;
    }

    for (int i = 0; i < n; ++i) {
        if (interior[i] == 0) {
            dfs(i);
        }
    }

    int longest_path = 0;


    for (int i = 0; i < nr; ++i) {
        //cout << top_sort[i] << " ";
        int v_max = 0;
        int current_element = top_sort[i];
        for (int j = 0; j < a[current_element].size(); ++j) {
            int current_neig = a[current_element][j];
            v_max = max(v_max, dp[current_neig]);
        }
        dp[current_element] = v_max + 1;
        longest_path = max(longest_path, dp[current_element]);
    }

    cout << longest_path - 1;

    return 0;
}


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

int K;
double P, E, T;

double solve(int night, double L, double R)
{
  double Td = (L + R) / 2.0;
  if (night == K) {
    if (abs(T-Td) < E)
      return 1.0;
    else
      return 0.0;
  }

  if (T - L <= E && R - T <= E)
    return 1.0;
  if (T + E < L || T - E > R)
    return 0.0;

  if (Td <= T)
    return (1.0-P)*solve(night+1, Td, R) + P*solve(night+1, L, Td);
  else
    return (1.0-P)*solve(night+1, L, Td) + P*solve(night+1, Td, R);
}

int main()
{
  int R, L;
  while (cin >> K >> R >> L) {
    cin >> P >> E >> T;
    printf("%.6f\n", solve(0, R, L));
  }
  return 0;
}

Measured memory_bytes: 0