akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
const int MN=5000+5;
const int P=924844033;
using namespace std;
typedef long long ll;
template<typename T>inline T&IN(T&in){
	in=0;char c=getchar();int f=1;
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c))in=in*10+c-'0',c=getchar();
	return in*=f;
}
int n,k;ll ans;
ll g[MN],fac[MN];
int eg[MN],f[MN][MN][2],vis[MN][2];
void input(){
	IN(n),IN(k);fac[0]=1;
	for(int i=1;i<=n;++i)for(int j=0;j<2;++j)if(!vis[i][j]){
		for(int x=i,y=j;x<=n;x+=k,y^=1)vis[x][y]=1,++eg[0];
		eg[eg[0]]=1;
	}
	f[1][0][0]=1;
	for(int i=1;i<=2*n;++i)for(int j=0;j<=n;++j){
		f[i+1][j][0]=(f[i][j][0]+f[i][j][1])%P;
		if(!eg[i])f[i+1][j+1][1]=f[i][j][0];
	}
	for(int i=0;i<=n;++i)g[i]=(f[2*n][i][0]+f[2*n][i][1])%P;
	for(int i=1;i<=n;++i)fac[i]=fac[i-1]*i%P;
	for(int i=0,j=-1;i<=n;++i,j=-j)ans=(ans+g[i]*j*fac[n-i]%P)%P;
	printf("%lld\n",(P-ans)%P);
}
int main(){
	input();
	return 0;
}

Measured memory_bytes: 156928
#include <bits/stdc++.h> 
     
    using namespace std; 
    #define ll long long
    #define ld long double
   ll gcd(ll a,ll b)
   {
    if(b==0)
        return a;
    return gcd(b,a%b);
   }
    int main()
    {
        ll k;
        cin >> k;
        ll mod=9*k;
        if(k%2 == 0 || k%5 == 0)
            cout << "-1\n";
        else
        {
            ll init=70;
            init=init%mod;
            ll cnt=1;
            while(init!=7)
            {
                //cout << init << "\n";
                cnt++;
                init=(init*10)%mod;
            }
            cout << cnt << "\n";
        }
    }
    

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 50;
pair<string, int> x[N];
char in[101];

int main(){
	int n, an = 0;
	scanf("%d", &n);
	f(i, 0, n){
		scanf("%s%d", in, &x[i].second);
		x[i].first = in;
		an += x[i].second;
	}
	scanf("%s", in);
	f(i, 0, n){
		an -= x[i].second;
		if (x[i].first == in)break;
	}
	printf("%d\n", an);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,K;
    cin>>N>>K;

    int ans=0;
    for(int i=K+1;i<=N;i++){
        int x=N/i;
        int y=i-K;
        int z=max(0LL,N%i-K+1);
        ans+=x*y+z;
    }
    cout << min(ans,N*N) << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;
int main()
{
	int n, t[100010], m, p, x, sum = 0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> t[i], sum += t[i];
	cin >> m;
	for (int i = 0; i < m; i++) {
		cin >> p >> x;
		p--;
		sum += x - t[p];
		cout << sum << endl;
		sum += t[p] - x;
	}
	return 0;
}


Measured memory_bytes: 256
X, N = map(int, input().split())
if N == 0:
    print(X)
else:
    P = list(map(int, input().split()))
    P = set(P)
    ans = 0
    i = 0
    while ans == 0:
        Xa = X-i
        Xb = X+i
        if Xa not in P:
            ans = Xa
            break
        if Xb not in P:
            ans = Xb
        i += 1
    print(ans)        


Measured memory_bytes: 9184
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll N,M;
    cin >> N >> M;
    string S,T;
    cin >> S >> T;
    ll L = N*M/__gcd(N,M);
    ll stepN,stepM;
    stepN = L/N;
    stepM = L/M;
    for(int i=0; i<M; i++){
        if(0 == (i*stepM)%stepN){
            int idxN = (i*stepM)/stepN;
            if(idxN >= N){
                break;
            }
            if(S[idxN] != T[i]){
                L = -1;
                break;
            }
        }
    }
    cout << L << endl;
}

Measured memory_bytes: 3760
import sys
H, W, K = map(int, input().split())
HW = [list(map(int, list(str(input())))) for _ in range(H)]

def blocks(hw):
    score = 0
    ret = 1
    delcnt = 0
    while ret:
        ret = check(delcnt, hw)
        score += ret
        delcnt += 1
    return score

def check(delcnt, hw):
    s = 0
    blank = -1
    for h in range(H):
        cnt = 1
        old = hw[h][:]
        for w in range(1, W):
            if hw[h][w-1]==hw[h][w]:
                cnt+=1
                flg = True
            else:
                if cnt>=K:
                    s += cnt*hw[h][w-1]
                    for k in range(1, cnt+1):
                        hw[h][w-k] = blank
                        blank -= 1
                cnt = 1
        if cnt>=K:
            s += cnt*hw[h][W-1]
            for k in range(1, cnt+1):
                hw[h][W-k] = blank
                blank -= 1
    for w in range(W):
        cnt = 1
        for h in range(H-1, -1, -1):
            item = hw[h][w]
            hw[h][w] = blank
            blank -= 1
            if item>0:
                hw[H-cnt][w] = item
                cnt += 1
    return 2**delcnt*s

import copy
ans = []
if K>=4:
    print(0)
else:
    for h in range(1, H):
        for w in range(W):
            hw = copy.deepcopy(HW)
            for i in range(H-h, 0, -1):
                hw[i][w] = hw[i-1][w]
            hw[0][w] = 0
            ans.append(blocks(hw))
print(max(ans))

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

typedef long long ll;

ll N;
int p;
vector<int> ans;

int main() {
    cin>>N;
    for(p = 42; p >= 0; p--) {
        if(N >= (1LL << p) - 1) break;
    }
    for(int i = 1; i <= p; i++) ans.push_back(i);
    N -= (1LL << p) - 1;
    int v = ++p;
    for(int i = p; i >= 0; i--) {
        if(N < (1LL << i)) continue;
        ans.push_back(v++);
        for(int j = ans.size() - 1; j >= i + 1; j--) {
            int tmp = ans[j];
            ans[j] = ans[j - 1];
            ans[j - 1] = tmp;
        }
        N -= (1LL << i);
    }
    for(int i = 1; i <= 100; i++) ans.push_back(i);
    printf("%d\n", ans.size());
    for(int i = 0; i < ans.size(); i++) {
        printf("%d ", ans[i]);
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        for(int k=0;;k++){
            String s1 = sc.next();
            if(s1.equals("-")) break;
            int m = sc.nextInt();
            for(int i=0;i<m;i++){
                int h = sc.nextInt();
                String s2 = s1.substring(h,s1.length());
                s2 += s1.substring(0,h);
                s1 = s2;
            }
            System.out.println(s1);
        }
    }
}



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

using namespace std;
typedef long long ll;
#define DBG(v) cerr << #v << " = " << (v) << endl;

struct DS {
    int c0 = 0;
    int c1 = 0;
    ll cnt = 0;

    void ins0() {
        cnt += c1;
        c0++;
    };

    void ins1() {
        c1++;
    }

    ll f() {
        ll res = cnt;
        c0 = c1 = cnt = 0;
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);

    string s;
    cin >> s;


    const int n = (int)s.size();

    s += "XXX";

    DS ds;
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if(s[i] == 'A')
            ds.ins1();
        else if(s[i] == 'B' && s[i+1] == 'C') {
            ds.ins0();
            i++;
        } else {
            ans += ds.f();
        }
    }

    ans += ds.f();
    cout << ans;

    return 0;
}

Measured memory_bytes: 848
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int N, A[200000], L[200000], R[200000];

int main() {
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	L[0] = A[0];
	for (int i = 1; i < N; ++i) {
		L[i] = max(L[i - 1], A[i]);
	}
	R[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; --i) {
		R[i] = max(A[i], R[i + 1]);
	}
	cout << R[1] << endl;
	for (int i = 1; i < N - 1; ++i) {
		cout << max(L[i - 1], R[i + 1]) << endl;
	}
	cout << L[N - 2] << endl;
}

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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
//#define sum(start, end) accumulate(start, end, 0)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define pb push_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

using namespace std;
template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

int choose (int a, int b, int c, int k) {
    if(k == 0)
        return a+b+c;

    return max(choose(a*2, b, c, k-1),
        max(choose(a, b*2, c, k-1), choose(a, b, c*2, k-1)));
}

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

    int ABC[3];
    rep(i, 3)
        ABC[i] = in<int>();
    int K=in<int>();

    // 再帰
    int res = choose(ABC[0], ABC[1], ABC[2], K);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
n = int(input())
a = [int(x) for x in stdin.readline().rstrip().split()]
for i in range(n-1):
  if a[n-1-i] < a[n-1-i-1] :
    a[n-1-i-1] -= 1 
  if a[n-1-i] < a[n-1-i-1] :
    #print("{} {}".format(i, a[i]))
    print("No")
    exit()
  """
  if i > 0:
    if a[i] < a[i-1]:
      print("No")
      exit()
  """
        
print("Yes")

Measured memory_bytes: 14308
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	int a;
	cin>>a;
	map<string,int> m;
	while(a--)
	{
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<'\n';
	cout<<"WA x "<<m["WA"]<<'\n';
	cout<<"TLE x "<<m["TLE"]<<'\n';
	cout<<"RE x "<<m["RE"]<<'\n';
	
	return 0; 	
}

Measured memory_bytes: 3676
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
#define INF 1000000000
typedef long long ll;

int G[310][310], N;

bool warshallFloyd(int n){
    
    rep1(k,n){
        rep1(i,n){
            rep1(j,n){
                if( G[i][j] > G[i][k]+G[k][j]){
                    return false;
                }
            }
        }
    }
    return true;
}

int main() {
    cin >> N;
    
    mem(G,0);
    
    rep1(i,N)rep1(j,N) cin >> G[i][j];
    
    ll ans=0;
    if( warshallFloyd(N) ){
        ll cnt=0;
        rep1(i,N){
            for(int j=i+1; j<=N;j++){
                bool redundant = false;
                rep1(k,N){
                    if( i!=k && j!=k && G[i][j]==G[i][k]+G[k][j]){
                        redundant = true;
                        break;
                    }
                }
                if(!redundant) cnt += G[i][j];
            }
        }
        ans = cnt;
    }else {
        ans = -1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 888
N, W = [int(x) for x in input().split()]
WV = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
for i in range(N):
    for w in range(W+1):
        if (w - WV[i][0] >= 0):
            dp[i+1][w] = max(dp[i+1][w], dp[i][w-WV[i][0]]+WV[i][1])
        dp[i+1][w] = max(dp[i+1][w], dp[i][w])
print(dp[N][W])


Measured memory_bytes: 171836
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (line == "-")
                {
                    break;
                }

                int m = int.Parse(Console.ReadLine());
                for(int i=0;i<m;i++)
                {
                    int h = int.Parse(Console.ReadLine());
                    line = line.Substring(h) + line.Substring(0, h);
                }

                Console.WriteLine(line);
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 8868
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

a, b = map(int, input().split())
d = []
for i in range(a):
    x, y = map(int, input().split())
    d.append((x, y))
d.sort()
count = 0
for i in range(a):
    if b <= d[i][1]:
        count += b * d[i][0]
        break
    else:
        b -= d[i][1]
        count += d[i][0] * d[i][1]
print(count)

Measured memory_bytes: 19448
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

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

  vector<ll> a(n, 0), b(n, 0);
  for (int i=0; i<n; i++) 
    cin>>a[i]>>b[i];
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());

  if (n % 2) {
    ll start = a[(n+1)/2 - 1];
    ll end = b[(n+1)/2 - 1];
    cout<<end-start + 1<<endl;
  }
  else {
    ll start = a[n/2 - 1] + a[n/2+1 - 1];
    ll end = b[n/2 - 1] + b[n/2+1 - 1];
    cout<<end-start + 1<<endl;
  }
}

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

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}

Measured memory_bytes: 6372
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[2];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;
set<ll> st;

ll gcdt(ll tara,ll tarb){ //最大公約数
    ll am=1;
    while(am){
        am=tara%tarb;
        tara=tarb;
        tarb=am;
    }
    return tara;
}

ll lcmt(ll tara,ll tarb){ //最小公倍数
    return tarb/gcdt(tara,tarb)*tara;
}

ll multMod(ll a,ll b,ll m){
    ll res = 0;
    a %= m;
    while (b){
        if (b & 1){
        res = (res + a) % m;
        }
        a = (a * 2) % m;
        b = b / 2;
    }
    return res;
}

bool isPrime(ll num){
    ll bd=floor(sqrt(double(num)));
    if(num==1)return 0;
    if(num==2)return 1;
    for (ll i = 2; i <= bd; ++i) {
        if (num % i == 0)
            return 0;
    }
    return 1;
}

ll pollard(ll num,ll c=1){
    ll x,y,p;
    if(num%2==0)return 2;
    if(isPrime(num))return num;
    x = p = 1LL;
    ll next = 2,i=1;
    while (p == 1){
        ++i;
        if (i == next){
        y = x;
        next *= 2;
        }
        x = (multMod(x,x,num) + c) % num;
        if (y == x) return pollard(num,c+1);
        p = gcdt(num,llabs(x-y));
    }
    return pollard(p);
}

template<typename MAIN>
ostream & operator<<(ostream & osys,vector<MAIN> vtar){
    osys<<"[";
    for(ll i=0;i<vtar.size();i++)osys<<vtar[i]<<(i==vtar.size()-1 ? "":",");
    osys<<"]";
    return osys;
}

int main(){
    //cin>>n>>m;
    //st=PollardRho(gcdt(n,m),1);
    //C st.size()+1 E;
    cin>>n>>m;
    //C isPrime(n) E;
    n=gcdt(n,m);
    while(n>1){
        a=pollard(n);
        n/=a;
        st.insert(a);
    }
    C st.size()+1 E;
    
    
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
vector<int> X;
vector<int> Y;
vector<int> DX;
vector<int> DY;
int N;
double solve(double a) {

	double mxx = -1e18;
	double mnx = 1e18;
	double mxy = -1e18;
	double mny = 1e18;


	for (int i = 0; i < N; i++) {
		double x = X[i] + a * DX[i];
		double y = Y[i] + a * DY[i];

		mxx = max(mxx, x);
		mnx = min(mnx, x);

		mxy = max(mxy, y);
		mny = min(mny, y);
	}

	return (mxx - mnx) * (mxy - mny);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	X.resize(N);
	Y.resize(N);
	DX.resize(N, 0);
	DY.resize(N, 0);
	char dd;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> dd;

		if (dd == 'U') {
			DY[i] = 1;
		}
		else if (dd == 'D') {
			DY[i] = -1;
		}
		else if (dd == 'R') {
			DX[i] = 1;
		}
		else if (dd == 'L') {
			DX[i] = -1;
		}
	}
	double res = 1e18;

	double u = 1e9;
	double d = 0;

	for (int t = 0; t < 200; t++) {

		double uu = (u * 2 + d) / 3;
		double dd = (u + d * 2) / 3;

		double uv = solve(uu);
		double dv = solve(dd);
		res = min(res, uv);
		res = min(res, dv);
		if (dv < uv) {
			u = uu;
		}
		else {
			d = dd;
		}

	}


	cout << fixed << setprecision(15) << res << endl;
}

Measured memory_bytes: 3456
#pragma GCC optimize("O3")   //
#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, b, a) for(int i = b - 1; i >= a; i--)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef unsigned long long ull;

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
std::mt19937 eng(seed);

uniform_int_distribution<> DD(0, (1ll << 31));

ll random2(){
    return (ll(DD(eng))*(1ll << 31) + ll(DD(eng))) & ((1ll << 62ll)-1);
}

ll n,m,k,q,T;

const ll big = 1000000007;
const ll big2 = 1000000009;
const ll mod =  998244353;

const int MAXN = 300001;


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

    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d,e;

    cin >> n >> m >> k;
    vl CSA(n+1);
    vl CSB(m+1);
    CSA[0] = 0;
    CSB[0] = 0;
    rep(c1,0,n){
        cin >> a;
        CSA[c1+1] = a+CSA[c1];
    }
    rep(c1,0,m){
        cin >> a;
        CSB[c1+1] = a+CSB[c1];
    }

    ll r = m;
    ll ans = -1;

    rep(l,0,n+1){
        if(CSA[l] > k)break;
        while(CSA[l] + CSB[r] > k){
            r--;
        }
         ans = max(ans, l+r);
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 6376
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 1e5;

int main()
{
	lld n,a[MAXN] = {0};

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

	lld four = 0,not_four = 0,two = 0;;

	for(int i = 0; i < n; i++)
	{
		if (a[i] % 4 == 0)
		{
			four++;
		}else
		{
			if (a[i] % 2 == 0)
			{
				two++;
			}else
			{
				not_four++;
			}
		}
	}

	if (two >= 1)
	{
		not_four++;
	}

	if (four - not_four >= -1)
	{
		cout << "Yes" << endl;
	}else
	{
		cout << "No" << endl;
	}



	return 0;
}

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

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define ull unsigned long long
#define ld long double

#define mod 1000000007
#define EULER 2.7182818284
#define INF 1000000000

#define pb push_back
#define ins insert
#define IT iterator
#define PQ priority_queue
#define    nl           "\n"
#define fi first
#define se second
#define maxe max_element
#define mine min_element
#define er erase
#define lb lower_bound
#define ub upper_bound

#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define pi pair<int,int>
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mpi map<int,int>
#define mpl map<ll,ll>
#define umpi unordered_map<int,int>
#define umpl unordered_map<ll,ll>
#define si set<int>
#define sl set<ll>
#define msi multi_set<int>
#define msl multi_set<ll>

#define mem(v,i) memset(v,i,sizeof(v)) // v is array. To set all elements to 0 or -1 only. mem(arr,0);


#define repab(i,a,b) for(int i=(a);i<=(b);i++)
#define reprab(i,a,b) for(int i=(a);i>=(b);i--)
#define repll(i,a,b) for(ll i=(a);i<=(b);i++)
#define rep(i,n) for(int i=(0);i<(n);i++)
#define repr(i,n) for(int i=(n);i>=0;i--)
#define bs bitset
#define bpc(a) __builtin_popcount(a)
#define tc int t;cin>>t;while(t--)
template<typename T> void TIME(T start, T end)
{
#ifndef ONLINE_JUDGE
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count();
    time_taken *= 1e-9;
    cout << "\nExecuted in: " << fixed
         << time_taken << setprecision(9);
    cout << " sec";
#endif
}

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

ll max(ll a,ll b)
{
    if(a>b)return a;return b;
}
ll min(ll a,ll b)
{
    if(a<b)return a;return b;
}

ll mypow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if(b==0)
    return a;
    return gcd(b,a%b);
}
//..............................!!!!!!Get ready to fight!!!!!!............................


int main()
{   
     auto start = chrono::high_resolution_clock::now();
    fast
    string s;
    cin>>s;
    int i,n=s.length(),cnt0=0,cnt1=0;
    for(i=0;i<n;i++){
        if(s[i]=='0')
        cnt0++;
        else
        cnt1++;
    }
    cout<<2*min(cnt1,cnt0);
    auto end = chrono::high_resolution_clock::now();
    TIME(start, end);
    return 0;
}

Measured memory_bytes: 3732
// D - String Equivalence
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vector<string> s(1,"a");
	while(--N){
		vector<string>t; swap(s,t);
		rp(i, 0, t.size()){
			char mx='a'; rp(j, 1, t[i].size()) mx = max(mx, t[i][j]); mx++;
			rp(c, 'a', mx+1) s.push_back(t[i] + char(c));

		}
	}
	rp(i, 0, s.size()) cout<< s[i] <<endl;
}

Measured memory_bytes: 10956
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	vll v;
	rep(i,1,n+1){
		if(n%i==0){
			v.pb(i);
		}
	}
	bool f=0;
	rep(i,0,sz(v)){
		if(v[i]<=9 and (n/v[i])<=9)f=1;
	}
	if(f)cout<<"Yes";
	else cout<<"No";
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
 
int main(){
    string s;
    cin >> s;
    string ans;
    rep(i,s.length()){
        if(s[i]=='B'){
            if(!ans.empty()){
                ans.pop_back();
            }
        }else{
            ans.push_back(s[i]);
        }
    }
    cout << ans << endl;
    
    return 0;
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int calc(const int bit,int *p,int *c,int g,int d){
  int score=0;
  int res=0;
  int i;
  for(i=0;i<=d;i++){
    if((bit>>i)&0x01){
      score+=p[i]*i*100+c[i];
      res+=p[i];
    }
  }
  i=d;
  while(score<g && i>0){
    if(((bit>>i)&0x01)==0){
      int k=(g-score)/(i*100);
      if(k>p[i]) k=p[i];
      score+=k*i*100;
      res+=k;
    }
    i--;
  }
  return score>=g?res:10*100+1;
}

void run(void){
  int d,g;
  scanf("%d%d",&d,&g);
  int p[11];
  int c[11];
  p[0]=c[0]=0;
  int i;
  for(i=1;i<=d;i++) scanf("%d%d",p+i,c+i);

  int min=100*10+1;
  for(i=0;i<(1<<d);i++){
    int t=calc(i<<1,p,c,g,d);
    if(t<min) min=t;
  }
  printf("%d\n",min);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
using namespace std;

using ll = long long;

constexpr ll mod = 100055128505716009ll;

vector<pair<ll, ll>> make_hashes(string str){
    vector<pair<ll, ll>> v;
    v.emplace_back(0, 0);

    for(auto ch : str){
        const int sz = v.size();
        for(int i = 0; i < sz; ++i){
            ll x, y;
            tie(x, y) = v[i];
            v[i] = make_pair((29ll * x + ch - 'a' + 1)%mod, y);
            v.emplace_back(x, (29ll * y + ch - 'a' + 1)%mod); } }

    return  v; }

int main(){
    int n;
    cin >> n;
    string str;
    cin >> str;

    string left, right;

    for(int i = 0; i < n; ++i){
        left.push_back(str[i]);
        right.push_back(str[2 * n - i - 1]); }

    auto h1 = make_hashes(left), h2 = make_hashes(right);

    sort(begin(h1), end(h1));

    long long rez = 0;

    for(auto x : h2)
        rez += upper_bound(begin(h1), end(h1), x) - lower_bound(begin(h1), end(h1), x);

    cout << rez << endl;
    return 0; }


Measured memory_bytes: 12140
#include <stdio.h>
#include <math.h>

double PI;

double deg2rad(double deg){
    return (deg / 360) * 2 * PI;
}

int main(){
    int a, b, c;
    double cr;
    
    PI = acos(-1);
    
    scanf("%d %d %d", &a, &b, &c);
    
    cr = deg2rad(c);
    
    printf("%f\n", (a * b * sin(cr)) / 2); // (1/2)(a b sin c)
    printf("%f\n", a + b + sqrt(a * a + b * b - 2 * a * b * cos(cr))); // 余弦定理
    printf("%f\n", b * sin(cr));
    
    return 0;
}


Measured memory_bytes: 2052
N,M = map(int,input().split())
ans = 1
if abs(N-M) >= 2:
  print(0)
elif abs(N-M) == 1:
  for i in range(1,min(N,M)+1):
    ans *= i
    ans = ans % (10**9 + 7)
  ans = ans**2 * max(N,M)
  ans = ans % (10**9 + 7)
  print(ans)
elif abs(N-M) == 0:
  for i in range(1,N+1):
    ans *= i
    ans = ans % (10**9 + 7)
  ans = ans**2
  ans *= 2
  ans = ans % (10**9 + 7)
  print(ans)

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

const int INF = 1e9 + 1;

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];
  rep(i, N) A[i] -= i + 1;

  sort(A.begin(), A.end());

  int b = A[N / 2];

  ll ans = 0;
  rep(i, N) ans += abs(A[i] - b);

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;

int main() {
    string s, t;
    cin >> s >> t;
    int mn = 1001001;
    rep(i, s.size() - t.size() + 1) {
        int now = 0;
        rep(j, t.size()) {
            if (s[i + j] != t[j]) now++;
        }
        mn = min(mn, now);
    }
    cout << mn << endl;
    return 0;
}
/*
g++ -std=c++17 -Wall -Wextra -g -O0 -fsanitize=undefined,address main.cpp && oj t
*/

Measured memory_bytes: 3596
#include<stdio.h>
int main(){
  int a[10],b,i=0,j=0,t[100]={0};
  while(scanf("%d",&b)!=EOF){
    if(b!=0){
      i++;
      a[i]=b;
    }
  
    else{
     
      t[j]=a[i];
      i--;
      j++;
    } 
  }
  for(i=0;t[i]!=0;i++){
    printf("%d\n",t[i]);
  }
  return 0;
}
    

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

using namespace std;
using ll = long long;
using vec = vector<int>;

#define rep(i, n)  for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define Sort(a)    sort(a.begin(), a.end())
#define gSort(a)   sort(a.begin(), a.end(), greater<int>())
#define pout(n, a) cout << fixed << setprecision(n) << (a)
#define Cast(dig, n) static_cast<std::bitset<(dig)>>(n)

const int INF = 2147483647;
const ll  MOD = 1000000007;

int main() {
    ll x; cin >> x;

    for(ll a = -1000; a <= 1000; ++a) {
        for(ll b = -1000; b <= 1000; ++b) {
            if(((a*a*a*a*a) - (b*b*b*b*b)) == x) {
                cout << a << " " << b;
                return 0;
            }
        }
    }
}

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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());

    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                if(a[i]==a[j]||a[j]==a[k]) continue;
                if(a[i]+a[j]>a[k]) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>

int main()
{
    int n, k, q;
    int attacker;

    std::cin >> n >> k >> q;
    int *score = new int[n + 1];
    int *correct = new int[q + 1];
    int *diff = new int[n + 1];
    
    for (int i = 1; i <= q; ++i) {
        std::cin >> correct[i];
    }
    for (int i = 1; i <= n; ++i) {
        score[i] = k;
    }

    for (int i = 1; i <= n; ++i) {
        diff[i] = 0;
    }
    for (int i = 1; i <= q; ++i) {
        diff[correct[i]]++;
    }

    for (int i = 1; i <= n; ++i) {
        score[i] = score[i] - q + diff[i];
    }

    for (int i = 1; i <= n; ++i) {
        if (score[i] > 0) {
            std::cout << "Yes" << std::endl;
        } else {
            std::cout << "No" << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, d, a, i, j;
	int m[200000][2];
	scanf("%d%d%d", &n, &d, &a);
	for(i=0; i<n; i++){
		scanf("%d%d", &m[i][0], &m[i][1]);
	}
	qsort(m, n, sizeof(int)*2, comp);
	int k[200000][2];
	int l=0, r=0, s=0;
	long h=0;
	long ans = 0;
	for(i=0; i<n; i++){
		while(s>0 && k[l][0]<m[i][0]){
			h-=k[l][1];
			l++, s--;
		}
		if(s==0){
			int N = (m[i][1]+a-1)/a;
			ans+=N;
			k[r][0] = m[i][0]+d*2;
			k[r][1] = N*a;
			h+=k[r][1];
			r++, s++;
		}else if(m[i][1] > h){
			m[i][1] -= h;
			int N = (m[i][1]+a-1)/a;
			ans+=N;
			k[r][0] = m[i][0]+d*2;
			k[r][1] = N*a;
			h+=k[r][1];
			r++, s++;
		}
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 4732
n,m=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort()
d=[]
for i in range(0,m-1):
    d.append(l[i+1] - l[i])
d.sort()
for i in range(0,n-1):
    ld = len(d)
    if ld == 0:
        print(0)
        import sys
        sys.exit()
    d.pop(ld-1)
print(sum(d))

Measured memory_bytes: 13968
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	ll n;
	cin>>n;
	map<ll,ll> m;
	rep(i,n){
		ll a;
		cin>>a;
		m[a]++;
	}
	ll ans=0;
	foreach(itr,m){
		if(itr->fi==itr->se){
			continue;
		}
		else{
			if(itr->fi>itr->se){
				ans+=itr->se;
			}
			else{
				ans+=min(itr->se,itr->se-itr->fi);
			}
		}
	}
	cout<<ans;
	re 0;
}

Measured memory_bytes: 6272
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
from collections import defaultdict #d = defaultdict(int) d[key] += value
import itertools #list(accumulate(A))

S = input()
K = ii()
N = len(S)

'''
alphabets = list('abcdefghijklmnopqrstuvwxyz')
l = []

for alpha in alphabets:
    for i, m in enumerate(S):
        if m == alpha:
            flag = 1
            for j in range(1, min(K+1, N-i+1)):
                l.append(S[i:i+j])

    l = sorted(set(l))
    if len(l) >= K:
        print(l[K-1])
        exit()
'''
l = []
for i in range(N):
    for j in range(1, K+1):
        if i+j-1 < N:
            l.append(S[i:i+j])

print(sorted(set(l))[K-1])

Measured memory_bytes: 5340
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int a;
	int b;
	int area;
	int length;

	scanf("%d %d", &a, &b);

	if ((a < 1 || 100 < a) ||
		(b < 1 || 100 < b)) {
		fprintf(stderr, "illegal input\n");
		exit(1);
	}

	area = a * b;
	length = 2 * (a + b);

	printf("%d %d\n", area, length);

	return 0;
}



Measured memory_bytes: 2100
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    answer = ""

    for i in range(1, 99):
        if N <= 26 ** i:
            N -= 1
            for j in range(i):
                answer += chr(ord("a") + N % 26)
                N //= 26
            break
        else:
            N -= 26 ** i

    print(answer[::-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 9104
N=(int)(input())
t_=0
x_=0
y_=0
for i in range(N):
    st,sx,sy = input().split()
    t=(int)(st)
    x=(int)(sx)
    y=(int)(sy)
    dt = t-t_
    dx = x-x_
    dy = y-y_
    if dx+dy>dt or (dx+dy)%2!=dt%2:
        print("No")
        exit(0)
    
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
 
 
int main()
{
 
    lint n,ans=0;
    cin >> n;
    lint a[n];
    REP(i, n) { cin >> a[i]; }
 
    FOR(i, 0, n)
    {
        ans ^= a[i];
    }
 
    if (ans==0){
        cout << "Yes"<< "\n";
    }
    else{
        cout << "No" << "\n";
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	vector<ll> v,v1;
	for(ll i=0;i<n;i++)
	{
		ll a,b;
		cin>>a>>b;
		v.push_back(a);
		v1.push_back(b);
	}
	sort(v.begin(),v.end());
	sort(v1.begin(),v1.end());
	reverse(v.begin(),v.end());
	if(n%2)
	{
		cout<<v1[n/2]-v[n/2]+1;
	}
	else
	{
		cout<<v1[n/2]+v1[(n/2)-1]-(v[n/2]+v[(n/2)-1])+1;
	}
	
}

Measured memory_bytes: 6692
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//(1,1)から(i,j)に移動するときの移動回数はi-1 + j -1である
//N=i*jと2数の積で表した時、(i,j)の和が最小となるペアを求める
int main() {
 ll N;
 cin >>N;
 int k = sqrt(N);
 ll ans = 5000000000000;
 for(int i = 1;i<=k;i++){
	 ll j = N/i;
	 if(N%i == 0){
		 ans = min(ans,i+j-2);
	 }
 }
 cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

template <typename X>
struct SegTree {
    using FX = function<X(X, X)>;
    int n;
    FX fx;
    const X ex;
    vector<X> dat;
    SegTree(int n_, FX fx_, X ex_) : n(), fx(fx_), ex(ex_), dat(n_ * 4, ex_) {
        int x = 1;
        while (n_ > x) {
            x *= 2;
        }
        n = x;
    }

    void set(int i, X x) { dat[i + n - 1] = x; }
    void build() {
        for (int k = n - 2; k >= 0; k--) dat[k] = fx(dat[2 * k + 1], dat[2 * k + 2]);
    }

    void update(int i, X x) {
        i += n - 1;
        dat[i] = x;
        while (i > 0) {
            i = (i - 1) / 2;  // parent
            dat[i] = fx(dat[i * 2 + 1], dat[i * 2 + 2]);
        }
    }

    // the minimum element of [a,b)
    X query(int a, int b) { return query_sub(a, b, 0, 0, n); }
    X query_sub(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l) {
            return ex;
        } else if (a <= l && r <= b) {
            return dat[k];
        } else {
            X vl = query_sub(a, b, k * 2 + 1, l, (l + r) / 2);
            X vr = query_sub(a, b, k * 2 + 2, (l + r) / 2, r);
            return fx(vl, vr);
        }
    }
    /* debug */
    inline X operator[](int a) { return query(a, a + 1); }
    void print() {
        for (int i = 0; i < 2 * n - 1; ++i) {
            cout << (*this)[i];
            if (i != n) cout << ",";
        }
        cout << endl;
    }
};

int main(){
  int n;ll x;
  cin >> n >> x;
  auto fx = [](ll x1, ll x2) -> ll { return min(x1, x2); };
  ll ex = numeric_limits<ll>::max();
  SegTree<ll> rmq(2*n, fx, ex);

  vector<ll> a(n);
  rep(i,n)cin >> a[i];
  rep(i,n)rmq.update(i,a[i]);
  rep(i,n)rmq.update(i+n,a[i]);
  
  ll res = LINF;
  rep(k,n){
    ll t = 0;
    rep(i,n){
      t += rmq.query(i,i+k+1);
    }
    chmin(res,t+x*k);
  }
  cout << res << endl;
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 1000000

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a, b, c;
	cin >> a >> b >> c;
	ll ans = 0;
	for (int i = a; i <= b; i++) {
		if (c % i == 0) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
typedef long long ll;
ll n, k, c, lst;
bool flag;
string s;
ll cnt;
bool vis[200010];
stack<int> stk;
int main() {
    cin >> n >> k >> c;
    cin >> s;
    lst = -1;
    for (int i = 0; i < (int)(s.length()); i++) {
        if (s[i] == 'x' || lst >= i) continue;
        if (cnt >= k) {
            flag = 1;
            break;
        }
        lst = i + c;
        vis[i] = 1;
        cnt++;
    }
    if (flag) {
        return 0;
    }
    lst = s.length();
    for (int i = (int)s.length() - 1; i >= 0; i--) {
        if (s[i] == 'x' || lst <= i) continue;
        lst = i - c;
        if (vis[i]) {
            stk.push(i);
        }
    }
    while (!stk.empty()) {
        cout << stk.top() + 1 << endl;;
        stk.pop();
    }
    return 0;
} 

Measured memory_bytes: 2464
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
from operator import itemgetter
 
N,M = map(int,readline().split())
a = list(map(int,readline().split()))
m = map(int,read().split())
bc = list(zip(m,m))


#[n,m]=[int(x) for x in input().split()]
#a=[int(x) for x in input().split()]
#bc=[[int(x) for x in input().split()] for _ in range(m)]

bc.sort(key = itemgetter(1),reverse=True)
bc.append((N,-1))
change=[]
for b,c in bc:
    change += [c] * b
    if len(change) > N:
        break
 
a += change
a.sort()
answer = sum(a[-N:])
print(answer)

Measured memory_bytes: 31520
a = list(map(int,input().split()))
cnt_5=0
cnt_7=0
for i in range(3):
  if a[i]==5:
    cnt_5=cnt_5+1
  elif a[i]==7:
    cnt_7=cnt_7+1
 
if cnt_5 == 2 and cnt_7 == 1:
  print('YES')
else:
  print('NO')

Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

struct Point{
  double x;
  double y;
};

void koch(int n, struct Point a, struct Point b){
  struct Point s, t, u;
  double th;

  if(n == 0) return;

  th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1, t, b);
}

int main() {
  struct Point a, b;
  int n;

  scanf("%d", &n);

  a.x = 0;
  a.y = 0;
  b.x = 100;
  b.y = 0;

   printf("%.8f %.8f\n", a.x, a.y);
   koch(n, a, b);
   printf("%.8f %.8f\n", b.x, b.y);
   
  return 0;
}



Measured memory_bytes: 2096
N = int(input())

status = [[] for _ in range(N)]
for i in range(N):
    A = int(input())
    for _ in range(A):
        x, y = list(map(int, input().split()))
        status[i].append((x-1,y))

honest = 0

# bit全探索
for i in range(2 ** N):
    flag = True
    for j in range(N):
        if ((i >> j) & 1) == 1:
            # bitが立っている箇所に対して処理。つまり,人jが正直者だとしたとき、
            # その人の発言と、矛盾していないか判定
            for x, y in status[j]: # 人jの証言            
                if ((i >> x) & 1) != y:
                    flag = False
                    break
    if flag:
        honest = max(honest, bin(i)[2:].count('1'))  # 0bが先頭につくため

print(honest)

Measured memory_bytes: 43372
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b+c<22)
        printf("win\n");
    else
        printf("bust\n");
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> Pre, In, Post;
int pos;

void reconstruction(int l, int r){
    if(l>=r) return;    //葉が来るまで
    int root = Pre[pos++];  //次の節点
    int m = distance(In.begin(), find(In.begin(), In.end(), root));
    reconstruction(l, m);
    reconstruction(m+1, r);
    Post.push_back(root);
}

void solve(){
    pos = 0;
    reconstruction(0, Pre.size());
    for(int i=0, size = Pre.size(); i<size; i++){
        if(i) printf(" ");
        printf("%d", Post[i]);
    }
    printf("\n");
}

int main(){

    int n;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        int k;
        scanf("%d", &k);
        Pre.push_back(k);
    }
    for(int i=0; i<n; i++){
        int k;
        scanf("%d", &k);
        In.push_back(k);
    }

    solve();

    return 0;
}


Measured memory_bytes: 2792
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
	_typer init = 0;
	char ch = getchar(), k = 0;
	for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
	for ( ; isdigit(ch); ch = getchar())
		init = (init << 3) + (init << 1) + (ch ^ 48);
	return k ? -init : init;
}
const ll N = 0, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int n, a, b;

int main() {
	cin >> n >> a >> b;
	cout << min(n * a, b) << endl;
	return 0;
}



Measured memory_bytes: 256
def divisors(n):
    divisors_list = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors_list.append((i,n//i))
            divisors_list.append((n//i,i))
    divisors_list.sort()
    return divisors_list

n, m = [ int(v) for v in input().split() ]
divisors_list = divisors(m)

ans = 1
for i in divisors_list:
    if i[1] >= n:
        ans = i[0]
print(ans)


Measured memory_bytes: 38640
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

int main()
{
	ll x, k, d;
	cin >> x >> k >> d;
	ll min_dist = abs(x);
	ll div = abs(x) / d;
	if (div <= k)
	{
		if ((k - div) % 2 == 0)
			min_dist = abs(abs(x) - (div * d));
		else
			min_dist = abs(abs(x) - (div * d + d));
	}
	else
		min_dist = abs(abs(x) - k * d);
	cout << min_dist << endl;
	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int a,b,x;
  
  cin >> a >> b;
  
  x = (a * b) % 2;
  
  if (x == 0) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256