akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 1000000007
#define md 998244353
#define trace(...)
#define ll long long int
#define ld long double
#define fi first
#define se second
#define fr(i,a,b) for(ll i=a;i<=b;i++)
#define frr(i,b,a) for(ll i=b;i>=a;i--)
#define mem(a) memset(a, 0, sizeof(a))
#define vpi std::vector<pair<int,int>>
#define pii pair<int,int>
#define pb push_back
#define sall(v) sort(v.begin(),v.end())
#define all(v) (v.begin(),v.end())
#define minf -10000000
#define vi vector<int>
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
    uniform_int_distribution<int> uid(0,lim-1);
    return uid(rang);
}
ll power(ll x, ll y,ll p) { 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {  
        if (y & 1) // If y is odd, multiply x with result
            res = (res*x) % p;  
        y = y>>1; // y = y/2 // y must be even now
        x = (x*x) % p;   
    } 
    return res; 
}
ll power(ll x, ll y) { 
    ll res = 1;      // Initialize result 
    while (y > 0) {    
        if (y & 1)// If y is odd, multiply x with result 
            res = (res*x) ;  
        y = y>>1; // y = y/2 // y must be even now 
        x = (x*x);   
    } 
    return res; 
}
 
ll max3(ll a,ll b,ll c){
    return max(a,max(b,c));
}
ll min3(ll a,ll b,ll c){
    return min(a,min(b,c));
}
bool isPrime(ll n) { // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}

double calc(pair<double,double> p1,pair<double,double>p2){
    double x1=p1.first,x2=p2.first,y1=p1.second,y2=p2.second;
    double ans=(x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
    return sqrt(ans);
}

void solve() {
    int n;cin>>n;
    vector<pair<double,double>> v(n);fr(i,0,n-1)cin>>v[i].first>>v[i].second;
    double arr[n][n];
    fr(i,0,n-1){
        fr(j,0,n-1){
            arr[i][j]=calc(v[i],v[j]);
        }
    }
    double ans=0;
    fr(i,0,n-1){
        fr(j,i+1,n-1)ans+=arr[i][j];
    }
    cout<<(ans*2)/(double)(n)<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    int t;
    // cin>>t;
    t=1;
    while(t--){
        solve();
    }
    #ifndef ONLINE_JUDGE
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif
    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    cout<<n*n<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
const int N=1e6+5;
char s[N];
int main()
{
	int n=read(),a=read(),b=read(),c=read(),d=read();
	cin>>s+1;
	if(a>b)
	{
		swap(a,b);
		swap(c,d);
	}
	if(s[a]=='#'||s[b]=='#'||s[c]=='#'||s[d]=='#')
	{
		puts("No");
		return 0;
	}
	if(c<d)
	{
		int gs=0;
		for(int i=b;i<=d;i++)
		{
			if(s[i]=='#')gs++;
			else gs=0;
			if(gs==2){puts("No");return 0;}
		}
		for(int i=a;i<=c;i++)
		{
			if(s[i]=='#')gs++;
			else gs=0;
			if(gs==2){puts("No");return 0;}
		}
		puts("Yes");
	}
	else{
		int gs=0;
		for(int i=a;i<=c;i++)
		{
			if(s[i]=='#')gs++;
			else gs=0;
			if(gs==2){puts("No");return 0;}
		}
		gs=0;
		for(int i=b-1;i>=b-1;i--)
			if(s[i]=='.')gs++;
			else break;
		for(int i=b;i<=d;i++)
		{
			if(s[i]=='.')gs++;
			else gs=0;
			if(gs>2){puts("Yes");return 0;}
		}
		gs=0;
		s[d]='#';
		for(int i=a;i<=c;i++)
		{
			if(s[i]=='#')gs++;
			else gs=0;
			if(gs==2){puts("No");return 0;}
		}
		puts("Yes");
	}
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 50;
const int mod = 1e9 + 7;
ll a[maxn], sum[maxn];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1; i <= n;i++){
        cin >> a[i];
        sum[i] = sum[i - 1] + a[i];
        sum[i] %= mod;
    }
    ll ans = 0;

    for(int i = 1;i <= n;i++){
        ans += a[i] % mod * sum[i - 1] % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define me memset
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;
using namespace std;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;

inline int read()
{
	int X=0; bool flag=1; char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') flag=0; ch=getchar();}
	while(ch>='0'&&ch<='9') {X=(X<<1)+(X<<3)+ch-'0'; ch=getchar();}
	if(flag) return X;
	return ~(X-1);
}

int n,x,t;

int main() {
    //ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	n=read();
	x=read();
	t=read();

	printf("%d\n",((n-1)/x+1)*t);

    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif

template<class Ty> Ty randint(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c, neg = 0; while(isspace(c = getchar_unlocked()));
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar_unlocked())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int f[MAXN];

int main() {
	int n; rd(n);
	vector<int> a(n);

	ll sum = 0;
	for (int& i : a) {
		rd(i);
		sum += i;
		f[i]++;
	}

	int q; rd(q);
	while(q--) {
		int b, c; rd(b, c);
		sum -= 1ll * f[b] * b;
		sum += 1ll * f[b] * c;
		f[c] += f[b];
		f[b] = 0;
		printf("%lld\n", sum);
	}

}

Measured memory_bytes: 4112
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
const int N=1e6+5;
int n,m,s,t,dis[N];
vector<int>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
int main()
{
	n=read();m=read();
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		g[x].push_back(y+n);
		g[x+n].push_back(y+2*n);
		g[x+2*n].push_back(y);
	}
	s=read(),t=read();
	memset(dis,0x3f,sizeof(dis));
	dis[s]=0;
	queue<int>q;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();q.pop();
		for(int i=0;i<g[u].size();i++)
		{
			int v=g[u][i];
			if(dis[v]>dis[u]+1)
			{
				dis[v]=dis[u]+1;
				q.push(v);
			}
		}
	}
	if(dis[t]==0x3f3f3f3f)cout<<-1;
	else cout<<dis[t]/3;
}

Measured memory_bytes: 36992
import java.util.*;

class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int bit = 0;
    for (int i=0; i<N; i++){
      bit |= sc.nextInt();
    }
    System.out.println(Integer.numberOfTrailingZeros(bit));
  }
}

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

using lint = long long;

int main() {
    int n;
    std::cin >> n;

    std::vector<lint> ss(n);
    for (auto& s : ss) std::cin >> s;

    lint ans = 0;
    for (int k = 1; k < n; ++k) {
        int l = 0, r = n - 1;
        lint sum = 0;

        while (r > k && (r > l || r % k != 0)) {
            sum += ss[l] + ss[r];
            ans = std::max(ans, sum);
            l += k;
            r -= k;
        }
    }

    std::cout << ans << std::endl;
    return 0;
}


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

int main(){
	long long int   K;
	string S;
	cin >> K >> S;
  
  if (K >= S.size()) cout << S << endl;
  else {
  	while (S.size() > K) S.pop_back();
    S += "...";
    cout << S << endl;
  }
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<int,int>:: iterator it;
set<int>st;
set<int>::iterator it1;

int main()
{
    long long  i,j,n,t,a;
    cin>>t;
    cout<<t+(t*t)+(t*t*t)<<"\n";

return 0;
}



Measured memory_bytes: 3560
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <utility> // pair make_pair
#include <algorithm> // next_permutation

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))

using namespace std;
using Graph = vector<set<int> >;

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

  Graph G(N);
  
  for (int i = 0; i < M; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    G[a].insert(b);
    G[b].insert(a);
  }

  int A[N];
  for (int i = 1; i < N; i++) {
    A[i] = i;
  }
  int cnt = 0;
  do {
    bool path = 1;
    for (int i = 1; i < N; i++) {
      if (i == 1) {
        if (!G[0].count(A[i])) {
          // cout << "0: " << A[i] << endl;
          path = 0;
          break;
        }
      } else if (!G[A[i-1]].count(A[i])) {
        // cout << A[i-1] << ": " << A[i] << endl;
        path = 0;
        break;
      }
    }
    if (path) cnt++;
  } while (next_permutation(A + 1, A + N));

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	int n,p;
	vector<int> P;
	cin>>n;
	P.push_back(-1);
	rep(i,n){
		cin>>p;
		P.push_back(p);
	}
	P.push_back(-1);
	int ans=0;
	reps(i,n){
		if(i == P[i]){
			P[i+1] = P[i];
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 892
import numpy as np

def getNearestIndex(list, num):
    """
    概要: リストからある値に最も近い値を返却する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx
def main():
    n = int(input())
    T, A = map(int, input().split())
    lst = list(map(int, input().split()))
    temper = [T-l*0.006 for l in lst]
    ind = getNearestIndex(temper, A)
    print(ind + 1)

if __name__ == '__main__':
    main()

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

using namespace std;

const int oo = (int) (1e9);
const int dirI[] = {-1, 0, 1, 0};
const int dirJ[] = {0, 1, 0, -1};

struct coord
{
    int i, j;
} q[401];

int h, w, m[23][23], ma;

void border()
{
    ma = -oo;
    for(int i = 0; i <= h + 1; i++)
        m[i][0] = m[i][w + 1] = -1;
    for(int i = 0; i <= w + 1; i++)
        m[0][i] = m[h + 1][i] = -1;

}

void read()
{
    char temp;
    cin>>h>>w;
    for(int i = 1; i <= h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            cin>>temp;
            if(temp == '#')
                m[i][j] = -1;
        }
    }
}

void lee(coord start)
{
    int st, dp;
    st = dp = 0;
    q[0] = start;
    m[start.i][start.j] = 1;
    coord p;
    while(st <= dp)
    {
        p = q[st++];
        for(int k = 0; k < 4; k++)
        {
            coord v;
            v.i = p.i + dirI[k];
            v.j = p.j + dirJ[k];
            if(m[v.i][v.j] == 0)
            {
                m[v.i][v.j] = m[p.i][p.j] + 1;
                if(m[v.i][v.j] > ma)
                    ma = m[v.i][v.j];
                q[++dp] = v;
            }
        }
    }
    for(int i = 0; i <= h + 1; i++)
    {
        for(int j = 0; j <= w + 1; j++)
            if(m[i][j] != -1)
                m[i][j] = 0;
    }
}

void solve()
{
    coord st;
    for(int i = 1; i <=h; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            if(m[i][j] == 0)
            {

                st.i = i;
                st.j = j;
                lee(st);
            }
        }
    }
}

void print()
{
    cout<<ma-1;
}

int main()
{
    read();
    border();
    solve();
    print();
    return 0;
}


Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as V
--import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array (Array, listArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Control.Monad (forM_)
import Control.Monad.ST (ST, runST)
import Control.Monad.Trans.State (StateT(..))
import qualified Control.Monad.Cont as C
import qualified Data.ByteString.Char8 as B

import Debug.Trace (trace)

-- utility functions

--tr x = trace (show x) x
tr = id

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

--readIntsA :: Int -> B.ByteString -> UArray Int Int
--readIntsA n bs = runSTUArray $ do
--  arr <- newArray_ (0,n-1)
--  go arr 0 bs
--  return arr
--  where
--    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
--    go arr i bs
--      | i==n = return ()
--      | otherwise = do
--        let Just (x,bs') = readInt bs
--        writeArray arr i x
--        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

amount = [1,6,36,216,1296,7776,46656,9,81,729,6561,59049]

solv n = runST $ do
  dp <- newArray_ (0,n) :: ST s (STUArray s Int Int)
  forM_ [0..n] $ go dp
  readArray dp n
  where
  go dp 0 = writeArray dp 0 0
  go dp i = do
    m <- minimum <$> sequence [readArray dp j|a<-amount, let j=i-a, j>=0]
    writeArray dp i (m+1)

main = do
  n <- read <$> getLine
  print $ solv n


Measured memory_bytes: 1788
import math
N, M = map(int,input().split())
b = 0

P = [1]
for k in range(2,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)

P = sorted(P)
for e in P:
    if e >= N:
        print(M//e)
        exit(0)
print(1)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	string s,t;
	bool f=false;
	vector<char> S;
	vector<char> T;
	cin >> s >> t;
	
	for(int i=0;i<s.size();i++){
		S.push_back(s[i]);
		T.push_back(t[i]);
	}

	for(int i=0;i<S.size();i++){
		for(int j=0;j<S.size();j++){
			if(S[j]!=T[j]){break;}
			if(j==S.size()-1){f=1;}
		}
		char tt=*(S.end()-1);
		S.pop_back();
		S.insert(S.begin(),tt);
	}

	if(!f){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
const int maxn=2000222;
int a[maxn],id[maxn];
bool vis[maxn];
LL k,n,cur,ru;
int dfs(int de,int now)
{
	if(vis[now])
	{
		ru=id[now];
		return de-id[now];
	}
	vis[now]=1;
	id[now]=de;
	return dfs(de+1,a[now]);
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;++i)scanf("%lld",&a[i]);
	vis[1]=1;cur=1;id[1]=0;
	LL len=dfs(1,a[1]),ste;
	if(k<=ru)
	{
		for(int i=1;i<=k;++i)cur=a[cur];
		printf("%lld\n",cur);
		return 0;
	}
	for(int i=1;i<=ru;++i)cur=a[cur];
	k-=ru;
	ste=k%len;
	for(int i=1;i<=ste;++i)cur=a[cur];
	printf("%lld\n",cur);
}

Measured memory_bytes: 5516
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=3.14159265359;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
void SRAND(){auto duration = std::chrono::system_clock::now().time_since_epoch();auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();srand(millis);}

ll n,a[N],x,c[N],ans,cnt[N];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	REP1(i,n)cin>>a[i];
	REP1(i,n)cin>>x,ans+=x;
	REP1(i,n-1)cin>>c[i];
	for(ll i=n-1;i>=1;i--){
		if(a[i+1]==a[i]+1)ans+=c[a[i]];
	}
	cout<<ans<<"\n";
	return 0;
}



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

int N;
ll a[200010];
ll b[200010];

int main() {
    cin >> N;
    for (auto i = 0; i < N; i++) cin >> a[i];
    for (auto i = 0; i < N; i++) cin >> b[i];
    
    ll ret = 0;
    ll c = 1 << 29;
    for (auto i = 29; i >= 0; i--) {
        for (auto j = 0; j < N; j++) {
            a[j] &= ~(1 << (i + 1));
            b[j] &= ~(1 << (i + 1));
        }
        sort(b, b + N);
        
        ll now = 0;
        for (auto j = 0; j < N; j++) {
            now += lower_bound(b, b + N, 2 * c - a[j]) - lower_bound(b, b + N, 1 * c - a[j]);
            now += lower_bound(b, b + N, 4 * c - a[j]) - lower_bound(b, b + N, 3 * c - a[j]);
        }
        ret *= 2;
        ret += now % 2;
        c >>= 1;
    }
    cout << ret;   
}

Measured memory_bytes: 3328
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define sz(x) (int)(x).size();
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	
	int H=in();int W=in();
	int h=in();int w=in();
	cout<<(H-h)*(W-w);
}

Measured memory_bytes: 3664
import java.util.Random;
import java.util.Scanner;

public class Main {
    static void cut(int[] v, int p, int c) {
        int[] tmp = new int[p + c];
        for (int i = 0, j = p - 1; i < c; ++i, ++j) {
            tmp[i] = v[j];
        }

        for (int i = c, j = 0; j < p - 1; ++i, ++j) {
            tmp[i] = v[j];
        }

        for (int i = 0; i < p + c - 1; i++) {
            v[i] = tmp[i];
        }
    }

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

        while (true) {
            int n = scanner.nextInt(), r = scanner.nextInt();
            if (n == 0 && r == 0) break;

            int[] v = new int[n];

            for (int i = n - 1; i >= 0; --i) v[i] = n - i;

            for (int i = 0; i < r; ++i) {
                int p = scanner.nextInt(), c = scanner.nextInt();
                cut(v, p, c);
            }
            System.out.println(v[0]);
        }
    }
}


Measured memory_bytes: 36860
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    string S,T;cin>>S>>T;
    map<string,int>memo;
    int N=S.size();
    if(N<T.size())cout<<"UNRESTORABLE"<<endl;
    else{
        for(int i=0;i+T.size()<=N;i++){
            bool ok=true;
            for(int j=0;j<T.size();j++){
                if((S[i+j]!=T[j])&&(S[i+j]!='?')){
                    ok=false;
                    break;
                }
            }
            if(ok){
                string ans="";
                REP(j,i){
                    if(S[j]=='?')ans+='a';
                    else ans+=S[j];
                }
                REP(j,T.size())ans+=T[j];
                if(i+T.size()<N){
                    REP(j,N-i-T.size()){
                        int d=i+T.size()+j;
                        if(S[d]=='?')ans+='a';
                        else ans+=S[d];
                    }
                }
            	memo[ans]++;
            }
        }  
        if(memo.empty())cout<<"UNRESTORABLE"<<endl;
        else{
            auto it=memo.begin();
            cout<<it->first<<endl;
        }
    }
}

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

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
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<<30;
//const ll INF = (ll)1e18 + 1;

const int MAX = 510000; //nCrのr
//const ll INF = (ll)1e18 + 1;

long long fac[MAX], finv[MAX], inv[MAX], facn[MAX];
class mint {
public:
    long long x;
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    //mint operator-() const{ return mint(-x);}
    mint operator-() const {
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

};

struct combination {
    vector<mint> fact, ifact;
    combination(long long n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(long long n, long long k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//素因数分解
vector<P> prime_factorize(ll N){
  vector<P> res;
  for (ll a = 2; a * a <= N; ++a){
    if (N % a != 0) continue;
    ll ex = 0; //指数
    while (N % a == 0){
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}

int main(){
  int N, M; cin >> N >> M;
  vector<P> prime = prime_factorize(M);
  combination C(200010);
  mint ans = 1;
  rep(i, (int)prime.size()){
    int k = prime[i].second;
    /*
    cout << prime[i].first << " " << prime[i].second << endl;
    cout << C(N+k-1, k).x << endl;*/
    ans *= C(N + k - 1, k);
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 3456
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int n, A, B, C, D;
bool p[200001];
char c;
int main() {
	scanf("%d%d%d%d%d", &n, &A, &B, &C, &D);
	for (c = getchar(); c != '#'&&c != '.'; c = getchar());
	for (int i = 1; i <= n; i++, c = getchar())
		if (c == '.') p[i] = true;
	for (int i = A; i < C; i++)
		if (!p[i] && !p[i + 1]) {
			puts("No");
			return 0;
		}
	for (int i = B; i < D; i++)
		if (!p[i] && !p[i + 1]) {
			puts("No");
			return 0;
		}
	if (C < B || C < D) {
		puts("Yes");
		return 0;
	}
	for (int i = max(A, B); i <= D; i++)
		if (p[i] && p[i - 1] && p[i + 1]) {
			puts("Yes");
			return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main() {

    int n;
    cin >> n;
    int arr[n];

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

    dp[1] = abs(arr[1]- arr[0]);

    for(int i=2;i<n;i++){

        dp[i] = min(abs(arr[i]- arr[i-1])+dp[i-1] , abs(arr[i]- arr[i-2]) + dp[i-2]);
    }

    // dp[2] = 20 ;
    // dp[3] =
 // 30 10 60 10 60 50
 // 0  20 (30) 20
        cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 4384
H,W=input().split()
h=int(H)
w=int(W)
if h==1 or w==1:
  print(1)
elif h%2!=0 and w%2!=0:
  print(int((h*w/2)+1))
elif h%2==0 or w%2==0:
  print(int(h*w/2))

Measured memory_bytes: 3060
# coding:utf-8

N, W = (int(x) for x in input().split())
w = [0 for x in range(N)]
v = [0 for x in range(N)]
for i in range(N):
	w[i], v[i] = (int(x) for x in input().split())

V = sum(v)

inf = 10000000000000
dp = [[inf for x in range(V+1)] for y in range(N+1)]

dp[0][0] = 0

for i in range(1, N+1):
	for j in range(V+1):
		# 品物を選ばない
		dp[i][j] = min(dp[i][j], dp[i-1][j])
		# 品物を選ぶ
		if j - v[i-1] >= 0:
			dp[i][j] = min(dp[i][j], dp[i-1][j-v[i-1]] + w[i-1])

# for i in range(N+1):
# 	for j in range(V+1):
# 		if dp[i][j] == inf:
# 			print(" inf", end="")
# 		else:
# 			print("{0:>4}".format(str(dp[i][j])), end="")
# 	print("")

max_v = 0
for i in range(N+1):
	for j in range(V+1):
		if dp[i][j] <= W:
			max_v = max(max_v, j)

print(max_v)

Measured memory_bytes: 171372
#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug { 
    ($($a: expr),*) => { 
        println!(concat!($(stringify!($a)," = {:?}, "),*), $($a),*);
    } 
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

fn solve() {
    let s = get!(String);
    let mut map = BTreeMap::new();
    for (i, c) in s.chars().enumerate() {
        if let Some(v) = map.insert(c, i) {
            if i-v <= 2 {
                println!("{} {}",  v+1, i+1);
                return;
            }
        }
    }
    println!("-1 -1");
}


Measured memory_bytes: 8572
#include <iostream>
#include <stdlib.h>
#include <utility>
#include <math.h>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <stdio.h>
#define   FOR(i,n) for(int i=0;i<n;i++)

using namespace std;
int int_sort(const void*a,const void *b) {
	return *(  int *) b - *(int *) a;
	//qsort(b, a, sizeof(long long int), int_sort);
}

int main() {

	int c1=0,c2=0,c3=0,c4=0,tmp;
	FOR(i,3){
		FOR(m,2){
			cin>>tmp;
			if(tmp==1)
				c1++;
			else if(tmp==2)
				c2++;
			else if(tmp==3)
				c3++;
			else if(tmp==4)
				c4++;
		}
	}

	if(  c1==3 ||c2==3||c3==3||c4==3){
		cout<<"NO";
		return 0;
	}
	if(  c1==0 ||c2==0||c3==0||c4==0){
		cout<<"NO";
		return 0;
	}

	else{
		cout<<"YES";
		return 0;
}



}


Measured memory_bytes: 256
n = int(input())
a = [[0]*37 for _ in range(37)]
b = 0
for _ in range(n):
    A = round(float(input())*10**9)
    for i in range(37):
        if A%2 == 0:
            A //= 2
        else:
            x = i
            break
    for i in range(37):
        if A%5 == 0:
            A //= 5
        else:
            y = i
            break
    a[x][y] += 1
for i in range(37):
    for j in range(37):
        for k in range(i+1, 37):
            for l in range(37):
                if i+k >= 18 and j+l >= 18:
                    b += a[i][j]*a[k][l]
for i in range(37):
    for j in range(37):
        for k in range(j, 37):
            if j == k and i >= 9 and j >= 9:
                b += a[i][j]*(a[i][j]-1)//2
            elif j != k and i >= 9 and j+k >= 18:
                b += a[i][j]*a[i][k]
print(b)

Measured memory_bytes: 9264
#include<bits/stdc++.h>
using namespace std;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
void work() {
    int A=gi(),B=gi(),C=gi(),D=gi(),l=1,r=A+B,k=(max(A,B)-1)/(min(A,B)+1)+1;
    while(l<=r) {
        int mid=(l+r)>>1;
        int a=A-mid/(k+1)*k-mid%(k+1),b=B-mid/(k+1);
        if(mid%(k+1)) ++a;
        if(1ll*a*k>=b) l=mid+1;
        else r=mid-1;
    }
    int a=A-r/(k+1)*k-r%(k+1),b=B-r/(k+1);
    if(r%(k+1)||!r) ++a;
    l=r+b-1ll*a*k;
    for(int i=C;i<=min(r,D);i++) putchar(i%(k+1)?'A':'B');
    for(int i=max(C,r+1);i<=D;i++) putchar((i-l)%(k+1)?'B':'A');
    puts("");
}
int main() {
    int T=gi();
    while(T--) work();
    return 0;
}


Measured memory_bytes: 384
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
S = gets.chomp

r = 0
g = 0
b = 0
S.split('').each do |c|
  if c == 'R'
    r += 1
  elsif c == 'G'
    g += 1
  else
    b += 1
  end
end

sum = r * g * b

0.step(N-3) do |i|
  j = i + 1
  while 2 * j - i < N
    sum -= 1 if S[i] != S[j] && S[i] != S[2 * j - i] && S[j] != S[2 * j - i]
    j += 1
  end
end

puts sum


Measured memory_bytes: 14796
#include<iostream>
#include <cstdio>
 
using namespace std;
 
void trace(int A[],int N){
    int i;
    for (i = 0; i < N; i++) {
        if (i > 0) printf(" ");
        printf("%d", A[i]);
    }
    putchar('\n');
}
 
void insertionSort(int A[], int N) {
     
    int i, j, v;
 
    for (i = 1; i < N; i++) {
        v = A[i];
        j = i - 1;
        while (j >= 0 & A[j] > v) {
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        trace(A, N);
    }
}
 
int main(){
 
    int N, i, j;
    int A[100];
    cin >> N;
    for (i = 0; i < N; i++) cin >> A[i];
 
    trace(A, N);
    insertionSort(A, N);
 
    return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
#include <iomanip>
#include <iostream>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll max(ll a, ll b){
    if(a > b) return a;
    else return b;
}
 
ll min(ll a, ll b){
    if(a < b) return a;
    else return b;
}

int main(void){
    int N; cin >> N;
    vector<ll> H(N,0); for(int i = 0; i < N; i++) cin >> H[i];
    
    for(int i = 0; i < N - 1; i++){
        if((H[i+1]-H[i]) > 0) H[i+1]--;
    }
    
    bool OK = true;
    for(int i = 0; i < N - 1; i++){
        if(H[i] > H[i+1]) OK = false;
    }
    
    if(OK) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1024
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
#include <deque>
#include <queue>
#include <tuple>

using namespace std;

namespace myLib {

#define prec(i) cout << fixed << setprecision(i)

	void output_yn(bool isYes) {
		if (isYes)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}

	const long long MOD = 1000000007;

	long long fact(long long k) {
		long long sum = 1;
		for (long long i = 2; i <= k; i++)
			sum *= i;

		return sum;
	}

	long long fact_mod(long long k) {
		long long sum = 1;
		for (long long i = 2; i <= k; i++)
			sum = (sum * i) % MOD;

		return sum;
	}

	int ctoi(char c) {
		if (c >= '0' && c <= '9')
			return c - '0';
		else
			return -1;
	}

	long long pow_mod(int a, int b) {
		long long ans = 1;
		for (int i = 0; i < b; i++)
			ans = (ans * a) % MOD;

		return ans;
	}

	long long powll(long long a, long long  b) {
		long long ans = 1;
		for (long long i = 0; i < b; i++)
			ans = ans * a;

		return ans;
	}

	long long modinv(long long a) {

		long long b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= MOD;
		if (u < 0) u += MOD;

		return u;
	}

	long long _gcd(long long a, long long b)
	{
		if (a < b)
			swap(a, b);

		if (a % b == 0)
			return b;
		else
			return _gcd(b, a % b);
	}

	long long _lcm(long long a, long long b)
	{
		return (((a * b) % MOD) * modinv(_gcd(a, b))) % MOD;
	}

	long long ncr(long long n, long long r) {
		long long sum = 1;
		for (long long i = r + 1; i <= n; i++)
			sum *= i;

		return sum;
	}

	vector<vector<int>> graph;
	vector<bool> seen;
	vector<int> grpCnt;

	void dfs(const vector<vector<int>> graph, int v, int group) {
		seen[v] = true;
		grpCnt[group]++;
		for (auto next_v : graph[v]) {
			if (seen[next_v])
				continue;
			dfs(graph, next_v, group);
		}
	}
}

using namespace myLib;


int main()
{
	
	long long a, b, c, d, max;
	cin >> a >> b >> c >> d;

	max = a * c;
	if (max < a * d)
		max = a * d;
	if (max < b * c)
		max = b * c;
	if (max < b * d)
		max = b * d;

	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <stdio.h> 

int main() {
    
  int x,i,n;

  scanf("%d",&n);
  
  for(i=1; i<=n; i++) {
    x = i;
    
    if(x %3 == 0) {
      printf(" %d",i);
    } else if(x % 10 == 3) {
      printf(" %d",i);
    } else { 
      while(x != 0) {
	x /=10;
	if(x % 10 == 3) {
	  printf(" %d",i);
	  break;
	}
      }
    }
    
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2108
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
graph = [0] + [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    graph[u].append((v, w))
    graph[v].append((u, w))

def dfs(graph, queue, color):
    is_bigraph = True
    while queue:
        current = queue.pop()
        current_color = color[current]

        for _next, dist in graph[current]:
            if color[_next] != - 1:
                if color[_next] != (color[current] + dist) % 2:
                    is_bigraph = False
            else:
                color[_next] = (color[current] + dist) % 2
                queue.append(_next)

    return is_bigraph

queue = [1]
color = [-1] + [-1] * n
color[1] = 0
if not dfs(graph, queue, color):
    print('Something wrong')
    sys.exit(1)

for c in color[1:]:
    print(c)


Measured memory_bytes: 94016
# -*- coding: utf-8 -*-


class FactMod():
    '''
    modの値が素数の時のfactと組み合わせを求める
    フェルマーの小定理を用いているため、modが素数以外の時は使えない
    '''

    def __init__(self, n, mod):
        '''
        コンストラクタ
        f:nまでの i!の値を　配列に入れる
        inv: (i!)^-1　の値を配列に入れる
        '''
        self.mod = mod
        self.f = [1]*(n+1)
        for i in range(1, n+1):
            self.f[i] = self.f[i-1]*i % mod

        self.inv = [pow(self.f[-1], mod-2, mod)]
        for i in range(1, n+1)[::-1]:
            self.inv.append(self.inv[-1]*i % mod)
        self.inv.reverse()

    def fact(self, n):
        '''
        n!の値を返す
        '''
        return self.f[n]

    def comb(self, n, r):
        '''
        nCrの値を返す
        '''
        ret = self.f[n] * self.inv[n-r]*self.inv[r]
        ret %= self.mod
        return ret

    def perm(self, n, r):
        """
        nPrの値を返す
        """
        ret = self.f[n] * self.inv[n-r]
        ret %= self.mod
        return ret

N,A,B,K = map(int,input().split())
ans=0
MOD=998244353

F=FactMod(N+1,MOD)

for a in range(N+1):
    Ascore = a*A
    Bscore=K-Ascore
    if Bscore%B==0:
        b=Bscore//B
        if 0<=b<=N:
            ans+=(F.comb(N,a)*F.comb(N,b))%MOD
            ans%=MOD
print(ans)





Measured memory_bytes: 99880
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int maxn = 2000;
LL a[maxn], b[maxn];
int main(){
    ios::sync_with_stdio(false);
    LL N, x;
    cin >> N >> x;
    for(int i = 0; i < N; i += 1) cin >> a[i];
    LL ans = 0;
    for(int i = 0; i < N; i += 1) ans += b[i] = a[i];
    for(int k = 1; k < N; k += 1){
        LL pans = k * x;
        for(int i = 0; i < N; i += 1) pans += b[i] = min(b[i], a[(i + N - k) % N]);
        ans = min(ans, pans);
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
#include <time.h>
int main(){
    char s[100]={},t[250]={};
    scanf("%s %s",s,t);
    strcat(t,s);
    printf("%s",t);
    return 0;
}

Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60)-1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    //---------------------------------------------
    
    int n;
    cin>>n;
    for(int i=1;i<=50000;i++){
        int x=i*1.08;
        if(x==n){
            cout<<i<<endl;
            break;
        }
        if(i==50000){
            cout<<":("<<endl;
        }
    }
}

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

using namespace std;

/*-------------------------------*/
#define FOR(i, a, b) for(int i = (a); i < (b); i++)  //a~(b - 1)?????§
#define print(i) cout << i << endl //?°??????????Python?????????
#define all(i) (i).begin(),(i).end() //??¨??????(sort??¨???)
#define mp make_pair //mp(OO, OO)??¨???:::pint??¨???

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<long long> llv;
typedef vector<pint> vpint;
/*-------------------------------*/

int main(void)
{
  int a[101] = {};
  int mx = 0;
  int x;

  while (cin >> x){
    a[x]++;
    if (mx < a[x]) mx = a[x];
  }
  FOR(i, 1, 101){
    if (a[i] == mx){
      cout << i << endl;
    }
  }
  return 0; 
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);


using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using mint = map<int, int>;

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

const char sp = ' ';
const char cmm = ',';
const int MOD = 1e9+7;
const int INF = 1e9;
const ll LINF = 1e18;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powmod(ll b, ll e){ll r=1;while(e>0){if(e&1)r=(r%MOD)*(b%MOD)%MOD;b=(b%MOD)*(b%MOD)%MOD;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

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; }
template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    int len = v.size();
    s << '[';
    for (int i = 0; i < len; ++i) {
        s << v[i]; if (i < len-1) s << ", ";
    }
    s << ']';
    return s;
}

struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    };
}fastio;

int main(){

    ll n;
    cin >> n;

    ll s = 0;
    ll m = n;
    while(n > 0){
        s += n%10;
        n /= 10;
    }
    Judge(m%s==0);

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n1;
		int n2;
		int n3;
		int date;

		Scanner scan = new Scanner(System.in);

		date = scan.nextInt();

		for(int i = 0 ; i < date ;i++){
			n1 = scan.nextInt();
			n2 = scan.nextInt();
			n3 = scan.nextInt();

			if(n3 * n3 == n2*n2+n1*n1){
				System.out.println("YES");

			}else if(n2 * n2 == n3 * n3 + n1 * n1){
				System.out.println("YES");

			}else if(n1 * n1 == n3 * n3 + n2 * n2){
				System.out.println("YES");

			}else{
				System.out.println("NO");
			}
		}

	}

}

Measured memory_bytes: 32740
import sys
sys.setrecursionlimit(10000)

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

ans = 0
def dfs(l,r):
    global ans
    tmp = H[l:r]
    if len(tmp) == 0: return
    if len(tmp) == 1:
        ans += tmp[0]
        H[l] = 0
        return
    sub = min(tmp)
    ans += sub
    for i in range(l,r):
        H[i] -= sub
    tmp = H[l:r]
    if 0 in tmp:
        izero = l + tmp.index(0)
        if izero != l: dfs(l,izero)
        if izero != r: dfs(izero+1,r)

dfs(0,N)
print(ans)

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

int main() {
  long int n,k,mode;//nは要素数 modeは最頻値
  cin>>n>>k;
  vector<long int> a(n);//最頻値を求める配列
  for(long int i=0;i<n;i++)cin>>a[i];
  
  //最頻値を求める
  vector<long int> aa(n);
  vector<pair<long int,long int>> mode_(n);
  long int count=1;
  long int x=0;
  for(long int i=0;i<n;i++)aa[i]=a[i];
  sort(aa.begin(),aa.end());
  
  for(long int i=0;i<n-1;i++){
    if(aa[i]==aa[i+1]){
      count++;
      mode_[x].first=count;
      mode_[x].second=aa[i];
    }
    else{
      mode_[x].first=count;
      mode_[x].second=aa[i];
      count=1;
      x++;
    }
  }
  sort(mode_.begin(),mode_.end());
  reverse(mode_.begin(),mode_.end());
  
  /*mode[n].second n+1番目に多く出る数
  その数の個数はmode[n].first*/
  
  for(long int i=0;i<k;i++){
    n-=mode_[i].first;
    if(n==0)break;
  }
  cout<<n<<endl;
}


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

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

	vector<int> cnt(1000000);
	for (int x = 1; x <= 100; x++) {
		for (int y = 1; y <= 100; y++) {
			for (int z = 1; z <= 100; z++) {
				cnt[x*x + y*y + z*z + x*y + y*z + z*x]++;
			}
		}
	}

	int n; cin >> n;
	for (int i = 1; i <= n; i++) cout << cnt[i] << '\n';

	return 0;
}


Measured memory_bytes: 7080
from itertools import product

while True:
    co = 0
    n, x = map(int, input().split())
    
    if n == x == 0:
        break

    for a, b, c in product(range(1, n + 1), range(1, n + 1), range(1, n + 1)):
        co += a + b + c == x and a != b != c != a
    print(co // 6)




Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
long long a,b;
string s1,s2,s3;
int main()
{
	cin>>s1>>s2;
	cin>>a>>b;
	cin>>s3;
	if (s3==s1)
	{
		cout<<a-1<<" "<<b<<endl;
	}
	else
	{
		cout<<a<<" "<<b-1<<endl;
	}
}
    

Measured memory_bytes: 256