akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

const int MAXN = 200000;
const int MOD = int(1E9) + 7;
const int INF = (1<<30);

int pow_mod(int b, int p) {
	int ret = 1;
	for(int i=p;i;i>>=1,b=1LL*b*b%MOD)
		if( i & 1 ) ret = 1LL*ret*b%MOD;
	return ret;
}

int fct[MAXN + 5], ifct[MAXN + 5];
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*i*fct[i-1]%MOD;
	ifct[MAXN] = pow_mod(fct[MAXN], MOD - 2);
	for(int i=MAXN-1;i>=0;i--)
		ifct[i] = 1LL*ifct[i+1]*(i+1)%MOD;
}

int c[MAXN + 5], w[MAXN + 5], N, X, Y;
int mn[MAXN + 5], cnt[MAXN + 5];

int main() {
	init(), scanf("%d%d%d", &N, &X, &Y);
	for(int i=1;i<=N;i++) mn[i] = INF;
	for(int i=1;i<=N;i++) {
		scanf("%d%d", &c[i], &w[i]);
		mn[c[i]] = min(mn[c[i]], w[i]);
	}
	for(int i=1;i<=N;i++)
		if( mn[c[i]] + w[i] <= X )
			w[i] = mn[c[i]];
	int fmn = -1, smn = -1;
	for(int i=1;i<=N;i++)
		if( mn[i] != INF ) {
			if( fmn == -1 || mn[fmn] > mn[i] )
				smn = fmn, fmn = i;
			else if( smn == -1 || mn[smn] > mn[i] )
				smn = i;
		}
	int tot = 0;
	for(int i=1;i<=N;i++) {
		if( c[i] == fmn ) {
			if( smn != -1 && w[i] + mn[smn] <= Y )
				cnt[c[i]]++, tot++;
		}
		else {
			if( w[i] + mn[fmn] <= Y )
				cnt[c[i]]++, tot++;
		}
	}
	int ans = fct[tot];
	for(int i=1;i<=N;i++)
		ans = 1LL*ans*ifct[cnt[i]]%MOD;
	printf("%d\n", ans);
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
using namespace std;
typedef long long ll;
bool is_integer( double x ){
  return std::floor(x)==x;
}
int main(){
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < d; j++) {
      cin >> x.at(i).at(j);
    }
  }
  int cnt=0;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      double val=0;
      for(int k=0; k<d;k++){
        //cout << x.at(i).at(k) << ' ' << x.at(j).at(k) << endl;
        val+= pow((x.at(i).at(k) - x.at(j).at(k)),2);
      }
      //cout << val << endl;
      val=pow(val,0.5);
      //cout << val << endl;
      //cout << is_integer(val)<<endl;
      if(is_integer(val)) cnt+=1;
    }
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
def LI(): return list(map(int,input().split()))
N,M = LI()
ks = [LI() for _ in range(M)]
p = LI()
ans = 0
for i in range(2**N):
    bit = [i>>j & 1 for j in range(N)]
    for k,x in enumerate(ks):
        _,*s = x
        if p[k] != sum([bit[y-1] for y in s])%2:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%MOD;
        }
        x = (x*x)%MOD;
        n >>= 1;
    }
    return ret;
}

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

    vector<pair<ll,ll>>  vec;

    for(int i = 0; i < n; i++){
        ll a,b;
        cin >> a >> b;
        vec.push_back(make_pair(b,a));
    }

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

    ll t = 0;

    for(int i = 0; i < n; i++){
        t += vec[i].second;
        if(t > vec[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 6512
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
signed main()
{
  string n; cin >> n;
  if((n[0]==n[1] && n[1]==n[2])||(n[1]==n[2]&&n[2]==n[3])) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
template<class T>bool maxi(T &a,const T &b){if(a<b){ a=b; return 1;} return 0;}
template<class T>bool mini(T &a,const T &b){if(b<a){ a=b; return 1;} return 0;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF2 4000000000000000037
#define INF 1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;

void Main(){

  int c[3][3];
  int sum=0;
  rep(i,3){
    rep(j,3){
      cin>>c[i][j];
      sum+=c[i][j];
    }
  }

  if(sum%3!=0){
    cout<< "No"<<"\n";
    return;
  }

  rep(a0,101){
    rep(a1,101){
      rep(a2,101){
        int b0=c[0][0]-a0;
        int b1=c[0][1]-a0;
        int b2=c[0][2]-a0;
        if(b0<0 or b1<0 or b2<0) continue;
        if(c[1][0] != a1+b0) continue;
        if(c[1][1] != a1+b1) continue;
        if(c[1][2] != a1+b2) continue;
        if(c[2][0] != a2+b0) continue;
        if(c[2][1] != a2+b1) continue;
        if(c[2][2] != a2+b2) continue;

        cout<< "Yes"<<"\n";
        return;
      }
    }
  }


  cout<< "No"<<"\n";
}


//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	unsigned int p,n,s=0,i=0,j;
	for(j=0;;j++)
	{
		if(scanf("%d,%d",&p,&n)==EOF)
			break;
		s+=p*n;
		i+=n;
	}
	printf("%d\n%.0f\n",s,((double)i/j)+0.00001);
	return 0;
}

Measured memory_bytes: 632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;
    N=S.size();
    char now=S[0];
    ll ans=0;
    rep(i,N){
        if(now!=S[i]){
            ans++;
        }
        now=S[i];
    }
    
    cout << ans << endl;


    return 0;
    

}

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

int N;
std::string S;

int main()
{
	std::cin >> N >> S;
	using vi = std::vector<int>;
	using vvi = std::vector<vi>;
	vvi table(N + 2, vi(10, N + 1));
	for (int i{N - 1}; i >= 0; i--)
	{
		table[i] = table[i + 1];
		table[i][S[i] - '0'] = i + 1;
	}
	int count{};
	for (int i{}; i < 1000; i++)
	{
		int now{};
		for (int j{}, i_cpy{i}; j < 3; j++, i_cpy /= 10)
			now = table[now][i_cpy % 10];
		if (now != N + 1)
			count++;
	}
	printf("%d\n", count);


	return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

#define MOD 1000000009
typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{

    int x;
    cin>>x;
    cout<<!x<<endl;
 return 0;
}


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

int SIZE=100001;

int main(void){
	char S [SIZE];
	int Q;
	char Qs[200001];
	int sizeQs=0;
	char Qb[200001];
	int sizeQb=0;
	bool X=true;//true 正順

	int T,F;
	char C;
	scanf("%s",S);
	scanf("%d",&Q);
	for(int k=0;k<Q;k++){
		scanf("%d",&T);
		if(X){
			if(T==1){
				X=false;
			}else{
				//T==2
				scanf("%d %c",&F,&C);
				if(F==1){
					Qs[sizeQs]=C;
					sizeQs++;
				}else{
					Qb[sizeQb]=C;
					sizeQb++;
				}
			}
		}else{
			if(T==1){
				X=true;
			}else{
				//T==2
				scanf("%d %c",&F,&C);
				if(F==2){
					Qs[sizeQs]=C;
					sizeQs++;
				}else{
					Qb[sizeQb]=C;
					sizeQb++;
				}
			}
		}
	}
	//出力
	if(X){
		for(int w=0;w<sizeQs;w++)printf("%c",Qs[sizeQs-1-w]);
		printf("%s",S);
		for(int w=0;w<sizeQb;w++)printf("%c",Qb[w]);
	}else{
		for(int w=0;w<sizeQb;w++){
			printf("%c",Qb[sizeQb-1-w]);
			}
		int m=strlen(S);
		for(int w=0;w<m;w++)printf("%c",S[m-w-1]);
		for(int w=0;w<sizeQs;w++)printf("%c",Qs[w]);
	}
}

Measured memory_bytes: 768
import sys
from fractions import gcd


def main():
    n, x = map(int, input().split())
    xs = list(map(int, input().split()))

    ans = 0

    for i in range(n):
        xs[i] -= x
        if xs[i] < 0:
            xs[i] *= -1
        ans = gcd(ans, xs[i])

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16280
import numpy as np
import math
import itertools
N = int(input())
data = [list(map(int,input().split())) for _ in range(N)]
length_list = []
arr = np.arange(1,N+1)
list_arr = arr.tolist()
for v in itertools.permutations(list_arr,N):
    S = 0
    for i in range(N-1):
        S += np.sqrt((data[v[i]-1][0]-data[v[i+1]-1][0])**2+(data[v[i]-1][1]-data[v[i+1]-1][1])**2)
    length_list.append(S)
ave = sum(length_list)/math.factorial(N)
print(ave)

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

using namespace std;

int getMaxScore (vector <vector <int>> & scores) {
    if (scores.empty()) {
        return 0;
    }
    int n = scores.size();
    vector <int> curr(3), prev = scores[0];

    for (int i = 1; i < n; ++i) {
        curr[0] = max(prev[1] + scores[i][0], prev[2] + scores[i][0]);
        curr[1] = max(prev[0] + scores[i][1], prev[2] + scores[i][1]);
        curr[2] = max(prev[0] + scores[i][2], prev[1] + scores[i][2]);
        prev = curr;
    }
    return *max_element(prev.begin(), prev.end());
}

int  main () {
    int n = 0;
    scanf("%d", &n);
    vector <vector <int>> scores(n, vector <int>(3));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            scanf("%d", &scores[i][j]);
        }
    }
    printf("%d", getMaxScore(scores));
    return 0;
}

Measured memory_bytes: 5760
import math
import sys
import queue
from collections import Counter
from itertools import accumulate
from fractions import gcd
from functools import reduce


def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

if __name__ == "__main__":
    n= int(sys.stdin.readline())
    v= list(map(int, sys.stdin.readline().split()))
    v.sort()
    if n ==2:
        print((v[1]+v[0])/2)
    else:
        tmp=v[0]
        for i in range(n-2):
            tmp = (tmp+v[i+1])/2
        ans = (tmp+v[n-1])/2
        print(ans)

Measured memory_bytes: 5612
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;

using ll = long long;
using Bint = mp::cpp_int;
ll mod = 1000000007;

int main() {
    // input
    ll x, a, b;
    cin >> x >> a >> b;

    // calculate
    ll temp = x - a;
    cout << temp % b << endl;
    return 0;
}



Measured memory_bytes: 256
n=int(input())
A=[int(i) for i in input().split()]
mod=10**9+7
import collections

P=collections.defaultdict(int)
ans=0
for a in A:
  ans=(ans+pow(a,mod-2,mod))%mod
  pf={}
  for i in range(2,int(a**0.5)+1):
    while a%i==0:
      pf[i]=pf.get(i,0)+1
      a//=i
  if a>1:
    pf[a]=1
  for p in pf.keys():
    P[p]=max(P[p],pf[p])

for p in P.keys():
  ans=(ans*pow(p,P[p],mod))%mod

print(ans)

Measured memory_bytes: 46300
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int h = sc.nextInt();

		int[] a = new int[n+1];
		int[] b = new int[n+1];
a[0]=0;
b[0]=0;
		for(int i = 1 ; i <= n ; i++){
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

int ata=0;

		Arrays.sort(a);
		Arrays.sort(b);
for(int i=n;i>=1;i--){
if(b[i]>a[n]){
	h=h-b[i];
ata++;
}
if(h<=0){
	break;
}
}


if(h<=0){
System.out.println(ata);
}else{
	if(h%a[n]==0){
System.out.println(ata+h/a[n]);}else{
	System.out.println(1+ata+h/a[n]);
}



}


	}}

Measured memory_bytes: 73680
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const ll inf=1e18+10;
const int maxn=405;

ll dp[maxn][maxn],a[maxn],sum[maxn];
int n;

ll dfs(int l,int r){
	if(dp[l][r]!=inf) return dp[l][r];
	for(int i=l;i<=r-1;i++){
		dp[l][r]=min(dfs(l,i)+dfs(i+1,r),dp[l][r]);
	}
	dp[l][r]+=sum[r+1]-sum[l];
	return dp[l][r];
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	for(int i=0;i<maxn;i++) for(int j=0;j<maxn;j++) dp[i][j]=inf;
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i-1];
	for(int i=0;i<n;i++) dp[i][i]=0;
	printf("%lld\n",dfs(0,n-1));
	return 0;
}


Measured memory_bytes: 1536
import java.util.*;
//import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		long n = parseLong(sc.next());
		long k = parseLong(sc.next());
		sc.close();
		long a1 = n / k;
		long a2 = 0;
		if(k%2==0) {
			a2 = (n + k /2) / k; 
		}
		out.println(a1*a1*a1+a2*a2*a2);
	}
}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define dalao 1000000007
#define inf 0x7fffffff
#define N 200010
using namespace std;
typedef long long ll;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(a>c)swap(a,c),swap(b,d);
	if(b<c)puts("0");
	else if(b>=d)printf("%d",min(abs(a-b),abs(c-d)));
	else printf("%d",b-c);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
using namespace std;
typedef long long int ll;

int main()
{
    int N;
    cin>>N;
     vector<ll> p;
    while(N--)
    {

    int n;
    cin>>n;
    switch(n)
    {
        case 0:int num;
        cin>>num;
        p.push_back(num);
        break;
        case 1: int num1;
        cin>>num1;
        cout<<p[num1]<<endl;
        break;
        case 2:
            p.pop_back();
            default: break;
    }

    }
}



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

int main(){
    int d,n,k = 1;
    cin >> d >> n;

    for (int i = 0; i < d; i++)
    {
        k *= 100;
    }

    if ( n== 100 ) cout << k*(n + 1) << endl;
    else cout << k * n << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  1000000007;
int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
     signed main(){
     
    int n,k;
    cin>>n>>k;
    int ans[k+1]={};
    for(int i=k;i>=1;i--){
         ans[i]=modpow(k/i,n,MOD);
         for(int j=2;j*i<=k;j++)ans[i]=(ans[i]+MOD-ans[j*i])%MOD;
    }
    int ans2=0;
     for(int i=1;i<=k;i++)ans2=(ans2+i*ans[i]%MOD)%MOD;
     cout<<ans2<<endl;
      }

        


Measured memory_bytes: 4412
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())

using namespace std;
using ll = int64_t;

constexpr int N = 3 * 1e5;
constexpr int MOD = 1e9 + 7;

ll factorials[N + 1];
pair<ll, ll> P[N + 1];

ll rev(ll x) {
  ll p = MOD - 2;
  ll ans = 1;
  while (p) {
    if (p & 1)
      ans = (ans * x) % MOD;
    x = (x * x) % MOD;
    p >>= 1;
  }
  return ans;
}

pair<ll, ll> C(ll n, ll k) {
  return {factorials[n], factorials[k] * factorials[n - k] % MOD};
}

pair<ll, ll> M(pair<ll, ll> lhs, pair<ll, ll> rhs) {
  return {lhs.fi * rhs.fi % MOD, lhs.se * rhs.se % MOD};
}

ll A(pair<ll, ll> p) {
  return p.fi * rev(p.se) % MOD;
}

pair<ll, ll> NEG(pair<ll, ll> p) {
  return {(MOD - p.fi) % MOD, p.se};
}

pair<ll, ll> PLUS(pair<ll, ll> lhs, pair<ll, ll> rhs) {
  return {(lhs.fi * rhs.se + rhs.fi * lhs.se) % MOD, (lhs.se * rhs.se) % MOD};
}

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

  factorials[0] = factorials[1] = 1;
  for (int i = 2; i <= N; i++)
    factorials[i] = (factorials[i - 1] * i) % MOD;

  P[0] = {1, 1};
  for (int i = 1; i <= N; i++) {
    P[i] = M(P[i - 1], {1, 2});
  }

  int B, W;
  cin >> B >> W;

  pair<ll, ll> onlyBlackSum = {0, 1};
  pair<ll, ll> onlyWhiteSum = {0, 1};

  for (int i = 0; i < B + W; i++) {
    if (B <= i) {
      onlyWhiteSum = PLUS(onlyWhiteSum, M(M(C((i - 1), B - 1), M(P[B - 1], P[(i - 1) - (B - 1)])), {1, 2}));
    }
    if (W <= i) {
      onlyBlackSum = PLUS(onlyBlackSum, M(M(C((i - 1), W - 1), M(P[W - 1], P[(i - 1) - (W - 1)])), {1, 2}));
    }

    // cout << "sums: " << A(onlyWhiteSum) << " " << A(onlyBlackSum) << endl;

    ll ans = A(PLUS(M(PLUS(PLUS({1, 1}, NEG(onlyWhiteSum)), NEG(onlyBlackSum)), {1, 2}), onlyBlackSum));

    cout << ans << "\n";
  }

  return 0;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define INF 100000007
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = inx(x, y)
#define print(x) cout << x << "\n"
#define print2(x, y) cout << x << " " << y << "\n"
#define printv(vec) rep(i, vec.size()) cout << vec[i] << " "; print("");
#define ALL(v) v.begin(), v.end()
#define SUM(v) accumulate(ALL(v), 0)
#define MAX(v) *max_element(ALL(v))
#define MIN(v) *min_element(ALL(v))
#define SORT(v) sort(ALL(v))
#define REV(v) reverse(ALL(v))
typedef long long ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;

ll f(ll x){

	if(x % 4 == 0) return 0 ^ x;
	if(x % 4 == 1) return 1;
	if(x % 4 == 2) return 1 ^ x;
	if(x % 4 == 3) return 0;
	
}		

void solve(){
	
	ll A, B;
	cin >> A >> B;
	ll ans = f(B) ^ f(A - 1);
	print(ans);
		
}

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





Measured memory_bytes: 3644
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;

int main(){
    int n,k;
    cin >> n>> k;
    rep(i,n){
        int p;
        cin >> p;
        pq.push(-p);
    }
    int ans=0;
    rep(i,k){
        int q=pq.top();
        pq.pop();
        ans+=-q;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a) for(ll i=0;i<a;i++)
#define jkl ll debug = 0;
#define RREP(i,a) for(ll i=a-1;i>=0;i--)
#define rrep(i,a,b) for(ll i=a-1;i>=b;i--)
#define printall(n,array) {for(ll i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> Pi;
typedef pair<ll, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7


int main(){
    ll n, k, T, D;
    priority_queue<Pi> pq;
    cin >> n >> k;
    REP(i, n){
        cin >> T >> D;
        pq.push(make_pair(D, T));
    }
    ll type = 0;    //number of types
    ll fund = 0;    //fund point of delicious
    VE number(n+1, 0); //count type number
    priority_queue<Pi, vector<Pi>, greater<Pi> > smalls;
    REP(i, k){
        auto top = pq.top();
        pq.pop();
        ll td = top.first;
        ll tt = top.second;
        fund += td;
        if(number[tt]){
            number[tt]++;
            smalls.push(make_pair(td, tt));
        }else{
            number[tt]++;
            type++;
        }
    }
    ll ans = fund + type * type;
    rep(i, type+1, k+1){
        while(!smalls.empty()){
            auto stop = smalls.top();
            smalls.pop();
            ll sd = stop.first;
            ll st = stop.second;
            if(number[st] <= 1)continue;
            number[st]--;
            fund -= sd;
            break;
        }
        while(!pq.empty()){
            auto btop = pq.top();
            pq.pop();
            ll bd = btop.first;
            ll bt = btop.second;
            if(number[bt])continue;
            number[bt]++;
            fund += bd;
            type++;
            break;
        }
        ans = max(ans, fund + type * type);
    }
    print(ans);
}



Measured memory_bytes: 4208
from collections import Counter
from functools import reduce
import bisect
import copy
import fractions
import math
# import statistics
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def P(x): return print(x)
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))


n, a = II(), LI()
left = [0] * (n+1)
right = [0] * (n+1)

for i in range(1, n+1):
    left[i] = fractions.gcd(left[i-1], a[i-1])

for i in range(n-1, -1, -1):
    right[i] = fractions.gcd(right[i+1], a[i]) 

# print(left)
# print(right)

maxi = -INF

for i in range(n):
    maxi = max(maxi, fractions.gcd(left[i],right[i+1]))

print(maxi)



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

// definitions
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define high(x) __builtin_popcountll(x)
#define pb push_back
#define pf push_front
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256
#define pi 3.1415926535897932384



using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dql;
typedef deque <char> dqc;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

ll INF=1e18;



// prevent collisions in unordered_map
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);
    }
};

template <class T>
void read(T arr[],ll n) {rep(i,0,n) cin>> arr[i];}

typedef unordered_map <long long, long long, custom_hash> umap;


// standard functions
ll mystoi(string str)
{
    stringstream ss(str);
    ll ans=0;
    ss >> ans;

    return ans;
}

ll exp(ll x, ll ex, ll p) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%p;
        ex >>= 1ll;
        x = (x * x)%p;
    }
    return ans;
}

bool sort_cond(const pair<ll,ll> &a, const pair <ll,ll> &b)
{
    return ((a.f-a.s)>(b.f-b.s));
}
  

// code beigns in main
int main()
{

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    while(t--)
    {
        string s;
        cin >> s;

        ll cnt=0;
        rep(i,0,s.length())
        {
            if(s[i]=='?') s[i]='D';
        }

        cout << s << endl;
    }
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>                          
using namespace std;
int a,b,c,x,y;
long long ans;
int main(){
	cin>>a>>b>>c>>x>>y;
	if(c*2<a+b)
	{
		ans+=min(x,y)*c*2;
		if(x>y) ans+=(x-y)*a;
		else ans+=(y-x)*b;
	}
	else ans=x*a+y*b;
	if(c*2*max(x,y)<ans) ans=c*2*max(x,y);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $n, $x);
$l = explode(" ", trim(fgets(STDIN)));
$sum = 0;
$ans = 1;
for ($i = 0; $i < $n; $i++) {
  $sum += $l[$i];
  if ($sum <= $x) $ans++;
}
echo $ans;
?>

Measured memory_bytes: 4604
#!/usr/bin/env python3
import sys

def sum_xor(X: int):
    untilb = 0
    if X%4==3:
        untilb = 0
    elif X%4==1:
        untilb = 1
    else:
        if (X+1)%4==3:
            untilb = 0^(X+1)
        elif (X+1)%4==1:
            untilb = 1^(X+1)

    return untilb

def solve(A: int, B: int):
    print(sum_xor(B)^sum_xor(A-1))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

#define all(v) (v).begin(), (v).end()
#define fi first
#define se second
#define eb emplace_back
#define pb push_back
#define mp make_pair

template <typename T>
bool uax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template <typename T>
bool uin(T& a, T b) { if (b < a) { a = b; return true; } return false; }

using namespace std;

typedef pair<int, int> pii;
typedef vector<pii> vpi;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef list<int> li;
typedef vector<li> vli;
typedef vector<vpi> vvpi;
typedef long long i64;

const int inf = 1e9;

void solve_b() {
  int n; cin >> n;
  const int M = 20;
  vi a(n); forn(i, n) cin >> a[i];
  array<int, M> b;
  forn(i, M) b[i] = n;
  vi c(n + 1, n);
  i64 ans = 0;
  ford(i, n) {
    int r = c[i + 1];
    forn(j, M) if ((a[i] >> j) & 1) {
      uin(r, b[j]);
      b[j] = i;
    }
    ans += (c[i] = r) - i;
  }
  cout << ans << endl;
}

void solve_a() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  pii a(0, 0);
  for (char c: s) if (c == 'W') a.se += 1; else a.fi += 1;
  pii b(0, 0);
  int ans = n;
  for (char c: s) {
    if (c == 'W') a.se -= 1; else a.fi -= 1;
    uin(ans, a.fi + b.se);
    if (c == 'W') b.se += 1; else b.fi += 1;
  }
  cout << ans << endl;
}

int main() {
#ifdef HOME
  freopen("../input.txt", "rt", stdin);
#endif
  solve_b();
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <algorithm>
using namespace std;
int k,t,i,a[105],s;
int main()
{
    cin>>k>>t;
    for(i=1;i<=t;i++)
        cin>>a[i];
    sort(a+1, a+t+1);
    for(i=1;i<t;i++)
        s+=a[i];
    cout<<max(0,a[t]-s-1);
    return 0;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, i321) => {
        read_value!($next, i32) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

//
// # Examples
//
// # integers
// input! { n: i32, m: i32, ... }
//
// # array
// input! { n: i32, v: [i32; n], }
//
// # matrix
// input! { n: i32, m: i32, mat: [[]] }
//
// # string
// input! { s: chars }
//
// 3 4
// ####
// #..#
// .#.#
//
// input!{
//     h: i32,
//     w: i32,
//     board: [chars; h],
// }

// https://practice.contest.atcoder.jp/tasks/practice_1
//fn main() {
//    input!{
//        a: i32, b: i32, c: i32,
//        foo: chars,
//    }
//    let s: String = foo.into_iter().collect();
//    println!("{} {}", a+b+c, s);
//}
fn main() {
    input! { a: f32, b: f32 }
    println!("{}", ((a+b)/2.0).ceil());
}

Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,ans=0; cin>>n;
    map<ll,ll> cnt;
    vector<ll> A(n,0);
    rep(i,n){
        int a; cin>>a;
        A[i]=a;
        if(cnt.count(a)) cnt[a]++;
        else cnt[a]=1;
    }
    for(auto q : cnt){
        ans+=q.second*(q.second-1)/2;
    }
    rep(i,n){
        printf("%lld\n",ans-(cnt[A[i]]-1));
    }
}

Measured memory_bytes: 11008
#include<bits/stdc++.h>
using namespace std;
string s;
int a[111111],ans;
int main()
{
	cin>>s;
	a[1]=s[0]-'0';
	for(int i=1;i<s.size();i++) 
	{
		a[i+1]=s[i]-'0';
		if(a[i+1]==a[i])
		{
			a[i+1]^=1;
			ans++; 
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
N,K = map(int,input().split())
MOD = 10**9 + 7

def sum_lr(l,r):
    return (l + r)*(r-l+1)//2


ans = 0
for i in range(K,N+2):
    a = sum_lr(N-(i-1),N)
    b = sum_lr(0,i-1)
    temp = a - b + 1
    # print('i',i)
    # print(a)
    # print(b)
    # print(temp)
    ans += temp
    ans %= MOD
print(ans)

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<29;

int main(){
  int N; cin >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  ll res = 0;
  ll now = 0;
  for(int i = 0; i < N; ++i){
    if (a[i] == now + 1){
      now++;
    }else{
      res++;
    }
  }
  if (res != N) cout << res << endl;
  else cout << -1 << endl;
}


Measured memory_bytes: 1024
n = int(input())
j = 0
t = 10
for i in range(n):
    if j < i:
        print("no")
        break
    d = int(input())
    j += d // 10
    if d < t:
        t += 10
    elif d >= t:
        t = 10
else:
    if t == 10:
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5608
#include<stdio.h>

int main(){
	long k,i,j;
	scanf("%ld",&k);
	
	long long int a[k],b[k],c[k];
	long long int max,min;
	
	for(i=0;i<k;i++){
		scanf("%lld",&a[i]);
	}
	
	if(a[k-1]!=2){
		printf("-1\n");
		return 0;
	}
	
	b[k-1]=1;
	c[k-1]=1;
	
	for(i=k-2;i>=0;i--){
		max = a[i+1]*(c[i+1]+1)-1; 
		min = a[i+1]*b[i+1];
		if(min - (min%a[i]) + a[i] > max && min%a[i] != 0){
			printf("-1");
			return 0;
		}
		b[i]=min/a[i];
		if(min%a[i]>0){
			b[i]++;
		}
		c[i]=max/a[i];
	}
	printf("%lld %lld\n",a[0]*b[0],a[0]*(c[0]+1)-1);
	return 0;
}

Measured memory_bytes: 2560
from collections import defaultdict

n=int(input())
v=list(map(int,input().split()))

o=defaultdict(int)						#初期化を忘れずに
e=defaultdict(int)

for i in range(0,n,2):
	e[v[i]]+=1

for i in range(1,n,2):
	o[v[i]]+=1

es=sorted(e.items(),key=lambda x:x[1],reverse=True)							#辞書のソート
os=sorted(o.items(),key=lambda x:x[1],reverse=True)

if es[0][0]==os[0][0]:
	if len(es)==1 and len(os)==1:
		print(n-max(es[0][1],os[0][1]))
	elif len(es)==1:
		print(n-es[0][1]-os[1][1])
	elif len(os)==1:
		print(n-es[1][1]-os[0][1])
	else:
		print(n-max(es[0][1]+os[1][1],es[1][1]+os[0][1]))
else:
	print(n-es[0][1]-os[0][1])		

Measured memory_bytes: 23008
//
// Created by kashi on 26-06-2020.
//
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define ll long long
#define ff first
#define ss second
#define Endl endl
#define int long long
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
bool cmps(pair<int,int>p1,pair<int,int>p2) {
    return p1.ss<p2.ss;
}
const int MAXN = 2e5+ 10;

int32_t main() {
    int a;
    cin>>a;
    cout<<a+pow(a,2)+pow(a,3)<<endl;
    return 0;
}

Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> arr;
typedef vector<arr> matrix;
typedef vector<ll> longarr;
typedef vector<longarr> longmat;
typedef map<int, arr> graph;
typedef vector<char> chararr;
typedef vector<chararr> charmat;
typedef pair<int, int> fraction;
ll MOD = 1000000007;
int n;
struct segmenttree {
	vector<ll> st;
	int n;

	void init(int _n) {
		n = _n;
		st.clear();
		st.resize(4 * _n);
	}

	void update(int l, int r, int indup, ll val, int node) {
		if (l == r) {
			st[node] = val;
			return;
		}
		else {
			int mid = (l + r) / 2;
			if (indup >= l && indup <= mid) {
				update(l, mid, indup, val, node * 2 + 1);
			}
			else {
				update(mid + 1, r, indup, val, node * 2 + 2);
			}
			st[node] = max(st[2 * node + 1], st[2 * node + 2]);
		}
	}

	ll query(int si, int se, int l, int r, int node) {
		if (se < l || si > r || l > r) {
			return 0;
		}
		if (si >= l && se <= r) {
			return st[node];
		}
		int mid = (si + se) / 2;
		ll q1 = query(si, mid, l, r, node * 2 + 1);
		ll q2 = query(mid + 1, se, l, r, node * 2 + 2);
		return max(q1, q2);
	}
	ll query(int l, int r) {
		return query(0, n - 1, l, r, 0);
	}
	void update(int index, ll val) {
		update(0, n - 1, index, val, 0);
	}
};

int main() {

	segmenttree tree;
	cin >> n;
	vector<pair<int, int> >v;
	vector<ll> b(n, 0);
	int x;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		v.push_back({x, i});
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	sort(v.begin(), v.end());
    ll ans=0;
    tree.init(n);
	for (auto p : v) {
        ll val=tree.query(0, p.second - 1) + b[p.second];
		ans = max(ans, val);
		tree.update(p.second, val);
	}

	cout << ans;
}


Measured memory_bytes: 12716
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        OutputWriter out = new OutputWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int N = in.nextInt(), displayed = in.nextInt();
            if (N >= 10) {
                out.printLine(displayed);
            } else {
                out.printLine(displayed + 100 * (10 - N));
            }
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tokenizer = null;

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
        }

        public String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(in.readLine());
                }
                return tokenizer.nextToken();
            } catch (IOException e) {
                return null;
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }

    static class OutputWriter {
        PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void print(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
        }

        public void printLine(Object... objects) {
            print(objects);
            writer.println();
        }

        public void close() {
            writer.close();
        }

    }
}



Measured memory_bytes: 23380
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 4005;

int n;
ll p[MAXN], dp[MAXN][MAXN], x;
priority_queue <pii> q;

int main() {
  scanf("%d %lld",&n,&x);
  REP(i, n) scanf("%lld",&p[i]);
  REP(i, n) p[i + n] = p[i];

  ll sol = (1LL << 60);

  REP(i, n) {
    ll tmp = x * i;
    while (!q.empty()) q.pop();
    for (int j = n - 1, k = -1; j > 0; j--, k--) q.push({-p[j], k});
    REP(j, n) {
      while (!q.empty() && j - q.top().sec > i) q.pop();
      q.push({-p[j], j});
      tmp -= q.top().fi;
    }
    sol = min(sol, tmp);
  }

  printf("%lld\n",sol);
  return 0;
}


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

using ll = long long;
using ull = unsigned long long;

const double PI = acos(-1);
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;

#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)

int main (void) {
    pair<int,int> p1,p2,p3,p4;
    cin>>p1.fi>>p1.se>>p2.fi>>p2.se;
    int d1 = p2.fi - p1.fi;
    int d2 = p2.se - p1.se;
    p3 = make_pair(p2.fi-d2,p2.se+d1);
    p4 = make_pair(p3.fi-d1,p3.se-d2);
    cout<<p3.fi<<" "<<p3.se<<" "<<p4.fi<<" "<<p4.se<<endl; 
    return 0;
}

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

static int
str2cmp (
  const char  * s1,
  const char  * s2,
  const char  * d
  )
{
  const char *a, *b, *y;
  int carry = 0;

  for ( a = s1; isdigit ( *a ); ++a );
  for ( b = s2; isdigit ( *b ); ++b );
  for ( y = d ; isdigit ( *y ); ++y );

  for ( ; ; )
  {
    int sum = carry;

    if ( a != s1 ) sum += *( --a ) - '0';
    if ( b != s2 ) sum += *( --b ) - '0';
    carry = sum / 10;
    sum   = sum % 10;

    if ( a == s1 && b == s2 && y == d
      && carry == 0 ) break ;
    if ( y == d || sum != *( --y ) - '0' )  return ( 0 );
  }

  return ( 1 );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( ; ; )
  {
    char s1[ 128 ], s2[ 128 ]
       , d[ 128 ];
    char *  cv[ 128 ];
    int     cv_count = 0;
    char *  t;

    if ( scanf ( " %[X0-9]+%[X0-9]=%[X0-9]", s1, s2, d )
          != 3 ) break ;

    for ( t = s1; *t != '\0'; ++t )
    {
      if ( *t == 'X' )  cv[ cv_count++ ] = t;
    }
    for ( t = s2; *t != '\0'; ++t )
    {
      if ( *t == 'X' )  cv[ cv_count++ ] = t;
    }
    for ( t = d;  *t != '\0'; ++t )
    {
      if ( *t == 'X' )  cv[ cv_count++ ] = t;
    }

    for ( i = 0; i <= 9; ++i )
    {
      if ( i == 0
        && ( ( s1[ 0 ] == 'X' && s1[ 1 ] != '\0' )
          || ( s2[ 0 ] == 'X' && s2[ 1 ] != '\0' )
          || (  d[ 0 ] == 'X' &&  d[ 1 ] != '\0' ) ) ) continue ;

      for ( j = 0; j < cv_count; ++j )
      {
        *cv[ j ] = i + '0';
      }

      if ( str2cmp ( s1, s2, d ) )  break ;
    }
    if ( i <= 9 ) printf ( "%d\n", i );
    else          printf ( "NA\n" );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())
i = 1
num = [0] * 13

while True:
    cnt = 0
    for j in range(1, i+1):
        if i % j == 0:
            cnt += 1

    if cnt > 12:
        i += 1
        continue

    if num[cnt] == 0:
        num[cnt] = i

    if num[n] > 0:
        ans = num[n]
        break

    i += 1

print(ans)

Measured memory_bytes: 7640
n, x, m = map(int, input().split())
s = 0
R = [-1]*m
R[x] = 0
T = [x]
for i in range(1, m+1):
    x = (x**2)%m
    T.append(x)
    if R[x] != -1:
        r = R[x]
        q = i-R[x]
        break
    else:
        R[x] = i
#print(R)
#print(r)
#print(q)

c = 0
for i in range(q):
    c += T[r+1+i]

X = [-1]*m
for i, e in enumerate(R):
    if e == -1:
        continue
    else:
        X[e] = i

n -= 1
if n <= r:
    ans = 0
    for i in range(n+1):
        ans += X[i]
else:
    ans = 0
    for i in range(r+1):
        ans += X[i]
    n -= r
    s, t = divmod(n, q)
    for i in range(t):
        ans += T[r+1+i]
    ans += c*s
print(ans)


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

int main(){
  int n;
  cin >> n;
  vector<long int> a(3 * n);
  for(int i = 0; i < 3 * n; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  long int out = 0;
  for(int i = 0; i < n; i++){
    out += a.at(i * 2 + n);
  }
  cout << out;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#define N 100005

typedef struct pp{
  char name[100];
  int l;
}P;

P A[N+1];
int max,mini,n;

void en(P);
P de(void);
int mi(int,int);

int main()
{
    int flag=0, c;
  int i,k;
  P r;
  scanf("%d %d", &n, &k);

  for ( i = 1; i <= n; i++){
    scanf("%s", A[i].name);
    scanf("%d", &A[i].l);
  }
max=1;
mini=n+1;

while(max!=mini)
{
r=de();
c=mi(k,r.l);
  r.l-=c;
flag+=c;
if(r.l>0)en(r);
else
{
printf("%s %d\n",r.name,flag);
 }
 }
  return 0;
}

void en(P x)
{
  A[mini]=x;
  mini=(mini+1)% N;
}
 
P de()
{
  P x=A[max];
  max=(max+1)%N;
  return x;
}

int mi(int a,int b)
{
  return a<b?a:b;
}



Measured memory_bytes: 11924
#include<iostream>
#include<math.h>

int main()
{
	int d;
	int ans = 0;
	while( std::cin >> d ){
	 	for( int i = 1; i < 600 / d; i++ ){
			ans += (int)pow( i * d, 2 ) * d;
		}
		std::cout << ans << std::endl;
		ans = 0;
	}

 	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

ll memo[100];

ll solve(ll n)
{
  if(memo[n] != 0)return memo[n];
  if(n == 0) return 2;
  if(n == 1) return 1;

  return memo[n] = solve(n-1)+solve(n-2);
}

int main()
{
  ll n; cin >> n;
  memset(memo, 0, sizeof memo);
  cout << solve(n) << endl;
  system("pause");
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, ans = 0, x;
  cin >> n;
  map<ll, ll> mp;
  for (int i = 1; i <= n; ++i) cin >> x, ans += mp[i - x], mp[i + x]++;
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;

int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    REP(i, H) cin >> a[i];

    vector<int> I, J;
    REP(i, H) {
        bool has_black = false;
        REP(j, W) {
            if (a[i][j] == '#') {
                has_black = true;
                break;
            }
        }
        if (has_black) {
            I.push_back(i);
        }
    }
    REP(j, W) {
        bool has_black = false;
        REP(i, H) {
            if (a[i][j] == '#') {
                has_black = true;
                break;
            }
        }
        if (has_black) {
            J.push_back(j);
        }
    }

    for (int i: I) {
        for (int j: J) {
            cout << a[i][j];
        }
        cout << '\n';
    }
    cout << flush;

    return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>
int main ()
{
    int N,L,a=0,b=0,c=0;
    scanf("%d%d",&N,&L);
    if(L<=0 & L+N-1>=0){
        for(int i=1;i<=N;i++){
            a+=(L+i-1);
        }
        printf("%d",a);
    }else if(L>0){
        for(int i=2;i<=N;i++){
            b+=(L+i-1);
        }
        printf("%d",b);
    }else if(L<0 & L+N-1<0){
        for(int i=1;i<=N-1;i++){
            c+=(L+i-1);
        }
        printf("%d",c);
    }

    
    return 0;
}

Measured memory_bytes: 128