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

#define ran 2022

int n, x, y;
int s[ran];

int main() {
	scanf("%d%d%d", &n, &x, &y);
	
	for(int i=1;i<=n;i++)
	for(int j=i+1;j<=n;j++) {
		int len;
		if(i<=x) {
			if(j<=x) len = j-i;
			else
			if(j<=y) len = min(j-i, (x-i) + 1 + (y-j));
			else
					 len = (x-i) + 1 + (j-y);
		} else
		if(i<=y) {
			if(j<=y) len = min(j-i, (i-x) + 1 + (y-j));
			else
					 len = min(i-x+1, y-i) + (j-y);
		} else len = j-i;
		//printf("%d %d %d\n", i, j, len);
		s[len]++;
	}
	for(int i=1;i<n;i++)
		printf("%d\n", s[i]);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
template<class T> inline bool chmax(T& a, T b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b){ if(a>b){ a=b; return 1; } return 0; }


signed main()
{   
    int N; cin>>N; 
    vector<double> p(N);
    for(int i=0;i<N;i++){
        cin>>p[i];
    }

    vector<vector<double> > dp(N+1,vector<double>(N+1));
    dp[0][0]=1;

    for(int i=0;i<N;i++){
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]+=dp[i][j]*p[i];
            dp[i+1][j]+=dp[i][j]*(1-p[i]);
        }
    }

    double ans=0;
    for(int i=(N+1)/2;i<=N;i++){
        ans+=dp[N][i];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;

int main(){
  string s;
  cin >> s;
  int res = 0;
  rep(i,sz(s)-1) if (s[i] != s[i+1]) res++;
  cout << res << endl;
  return 0;
} 

Measured memory_bytes: 512
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())
    if a+b>=10:
        print('error')
    else:
        print(a+b)
    
if __name__ == '__main__':
    main()


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

using namespace std;
long long n,a,mmin=100,k;
int main()
{
 cin>>n;
 for(int i=0;i<n;i++)
 {
    cin>>a;
    k=0;
    while(a%2==0)
    {
    a/=2;
    k++;
    }
    mmin=min(k,mmin);
 }
 cout<<mmin<<endl;
 return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]
        
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())
    
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
        
# uf = UnionFind(6)
# print(uf.parents)
# # [-1, -1, -1, -1, -1, -1]

# print(uf)

# print(uf.group_count())

n, m = map(int, input().split())

uf = UnionFind(n)

# print(n, m)
for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    # print(a, b)
    uf.union(a, b)
    
# print(uf.group_count())
print(uf.group_count() - 1)

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

int main() {
	int n;
	while (cin >> n, n) {
		int ia[1000], p[1000], q[1000], r[1000];
		for (int j = 0;j < n;j++) {
			cin >> ia[j] >> p[j] >> q[j] >> r[j];
		}
		int mp, mq, mr, mc;
		cin >> mp >> mq >> mr >> mc;

		int flg = 0;
		for (int i = 0;i < n;i++) {
			int kc = p[i] * 4 + (q[i] * 9) + (r[i] * 4);
			if (p[i] <= mp && q[i] <= mq&& r[i] <= mr && kc <= mc) {
				flg = 1;
				cout << ia[i] << endl;
			}
		}
		if (flg == 0)cout << "NA" << endl;
	}
	return 0;
}

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

// 解説を読んだ
// 各ポッキーが1 1 1 ... 1となった状態が負けなので、
// 全てのポッキーの長さを1減じたものに対するNimを考えればよい
// 長さxのポッキーに対するgrundy数は、観察を行うと
// (x-1)%(d+1)であることがわかる(実際に書き出せば明らか)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int nim = 0;
    while(n-- > 0){
        int x;  cin >> x;
        nim ^= (x-1)%(d+1);
    }
    cout << (nim==0 ? "Second" : "First") << endl;
    return 0;
}


Measured memory_bytes: 3180
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n;
    cin >> n;

    vector<ll> A(n);
    REP(i, n) cin >> A[i];

    ll cur = 1;
    ll ans = 0;
    REP(i, n) {
        if (A[i] > cur) {
            ll cnt = A[i] / cur;
            if (A[i] % cur == 0) cnt -= 1;
            ans += cnt;
            A[i] = 1;
        }
        cur = max(cur, A[i] + 1);
    }

    print(ans);
}


Measured memory_bytes: 4000
def solve():
    # making a list of prime numbers
    primes = [2, 3]
    for n in range(5, 10000, 2):
        l = n ** 0.5
        for p in primes:
            if n % p == 0:
                break
            if l < p:
                primes.append(n)
                break
    
    primes = [0] + primes
    
    from itertools import accumulate
    ac_primes = list(accumulate(primes))
    
    from bisect import bisect_left, bisect_right
    from sys import stdin
    file_input = stdin
    for line in file_input:
        n = int(line)
        if n == 0:
            break
        
        low = bisect_left(ac_primes, n)
        high = bisect_right(primes, n)
        
        ans = 0
        
        for x in ac_primes[low:high]:
            t = x - n
            if t == ac_primes[bisect_left(ac_primes, t)]:
                ans += 1
        
        print(ans)

solve()


Measured memory_bytes: 5832
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MX = 610;

int was[MX][MX];
int cl1[MX][MX];
int cl2[MX][MX];
vector<pair<int, int> > v1, v2;
int n;
int d1, d2;

void dfs1(int x, int y, int c, const vector<pair<int, int>> &vv, int cl[MX][MX]) {
	was[x][y] = 1;
	cl[x][y] = c;
	for (auto p: vv) {
		int nx = x + p.first;
		int ny = y + p.second;
		if (nx >= 0 && nx < 2 * n && ny >= 0 && ny < 2 * n) {
			if (!was[nx][ny]) {
				dfs1(nx, ny, c ^ 1, vv, cl);
			}
			else {
				assert(cl[nx][ny] != cl[x][y]);
			}
		}
	}
}

vector<pair<int, int> > gg[4];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	cin >> n >> d1 >> d2;
	for (int i = -2 * n; i <= 2 * n; ++i)
		for (int j = -2 * n; j <= 2 * n; ++j) {
			if (i * i + j * j == d1)
				v1.emplace_back(i, j);
			if (i * i + j * j == d2)
				v2.emplace_back(i, j);
		}
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 2 * n; ++j) {
			if (!was[i][j])
				dfs1(i, j, 0, v1, cl1);
		}
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 2 * n; ++j) {
			was[i][j] = 0;
		}
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 2 * n; ++j) {
			if (!was[i][j])
				dfs1(i, j, 0, v2, cl2);
		}
	for (int i = 0; i < 2 * n; ++i)
		for (int j = 0; j < 2 * n; ++j) {
			gg[cl1[i][j] * 2 + cl2[i][j]].emplace_back(i, j);
		}
	for (int i = 0; i < 4; ++i) {
		if (gg[i].size() >= n * n) {
			gg[i].resize(n * n);
			for (auto p: gg[i]) {
				cout << p.first << " " << p.second << "\n";
			}
			return 0;
		}
	}
	return 0;
}




Measured memory_bytes: 21976
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
#include <random>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<bool> vbool;
typedef vector<string> vstr;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
template <typename _Ty> istream& operator >> (istream& istr, vector<_Ty>& v) { for (size_t i = 0; i < v.size(); i++) cin >> v[i]; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
template <typename _Ty> _Ty ipow(_Ty x, _Ty n) { _Ty ret = _Ty(1); for (_Ty i = _Ty(0); i < n; i++) ret *= x; return ret; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false




int main()
{
	//clock_t start, end;
	//start = clock();

	string W, S;
	cin >> W;
	for (int i = 0; i < W.size(); i++) {
		if (isupper(W[i])) W[i] = tolower(W[i]);
	}

	int ans = 0;
	while (true) {
		cin >> S;
		if (S == "END_OF_TEXT") break;

		for (int i = 0; i < S.size(); i++) {
			if (isupper(S[i])) S[i] = tolower(S[i]);
		}
		
		if (W == S) ans++;
	}
	cout << ans << endl;

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}



Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int H, W;
	cin >> H >> W;
	vector<vector<int>> a(H, vector<int>(W));
	for (auto i = 0; i < H; ++i)
	{
		for (auto j = 0; j < W; ++j)
		{
			int temp;
			cin >> temp;
			a[i][j] = temp % 2;
		}
	}

	int offset[4][2] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1} };
	vector<vector<bool>> used(H, vector<bool>(W));
	auto x = -1;
	auto y = 0;
	auto index = 0;
	vector<tuple<int, int, int, int>> list;
	bool flag = false;
	for (auto i = 0; i < H * W; ++i)
	{
		auto nx = x;
		auto ny = y;
		for (auto j = 0; j < 2; ++j)
		{
			auto ofs = offset[index];
			nx = x + ofs[0];
			ny = y + ofs[1];
			if (nx < 0 || nx >= W || ny < 0 || ny >= H || used[ny][nx])
			{
				index = (index + 1) % 4;
			}
			else
			{
				break;
			}
		}

		used[ny][nx] = true;

		if (flag)
		{
			list.push_back(make_tuple( y + 1, x + 1, ny + 1, nx + 1 ));
		}

		if (a[ny][nx] == 1)
		{
			flag = !flag;
		}

		x = nx;
		y = ny;
	}

	cout << list.size() << endl;
	for (auto& t : list)
	{
		cout << get<0>(t) << " " << get<1>(t) << " " << get<2>(t) << " " << get<3>(t) << endl;
	}

	return 0;
}

Measured memory_bytes: 5232
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
const int INF=1e9+10;
char s[666];
int fa[500010],a[222][222],d[500010],f[222][222],n,ans;
int getf(int x){
	if (fa[x]==x) return x;
	int t=fa[x];
	fa[t]=getf(t);
	d[x]^=d[t];
	fa[x]=fa[t];
	return fa[x];
}
int main(){
	cin>>n;
	FOR(i,1,n){
		scanf("%s",s+1);
		FOR(j,1,n) a[i][j]=s[j]-'0';
	}
	FOR(i,1,n) fa[i]=i,d[i]=0;
	FOR(i,1,n)
		FOR(j,i+1,n) if (a[i][j]){
				int X=getf(i),Y=getf(j);
				if (X==Y){
					if (d[i]==d[j]) return puts("-1"),0;
				}
				else{
					fa[X]=Y;
					d[X]=d[i]^d[j]^1;
				}
			}
	FOR(i,1,n)
		FOR(j,1,n){
			if (i==j){f[i][j]=0;continue;}
			f[i][j]=(a[i][j]?1:INF);
		}
	FOR(j,1,n)
		FOR(i,1,n)
			FOR(k,1,n)
				f[i][k]=min(f[i][k],f[i][j]+f[j][k]);
	FOR(i,1,n)
		FOR(j,1,n)
			ans=max(ans,f[i][j]+1);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2432
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> H >> W;
	vector< string > grid(H);
	rep(i, H) cin >> grid[i];
	queue< pii > q;
	vector< vector< int > > d(H, vector< int >(W, INF));
	q.push(pii(0, 0));
	d[0][0] = 0;
	bool f = false;
	while (!q.empty()) {
		pii p = q.front();
		q.pop();
		if (p == pii(H - 1, W - 1)) {
			f = true;
			break;
		}
		rep(k, 4) {
			int ni = p.first + di[k];
			int nj = p.second + dj[k];
			if (0 <= ni && ni < H && 0 <= nj && nj < W && grid[ni][nj] == '.' && d[ni][nj] > d[p.first][p.second] + 1) {
				d[ni][nj] = d[p.first][p.second] + 1;
				q.push(pii(ni, nj));
			}
		}
	}
	if (!f) {
		cout << -1 << endl;
		return 0;
	}
	int c = 0;
	rep(i, H) rep(j, W) if (grid[i][j] == '.') c++;
	int ans = c - d[H - 1][W - 1] - 1;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <utility>
#include <algorithm>
#include<vector>

using namespace std;

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

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

    vector<pair<int, int> > p;
    int a,b;
    pair<int, int> pa;
    for(int i = 0; i < N; i++){
        cin >> a >> b;
        pa.first = a;
        pa.second = b;
        p.push_back(pa);
    }

    sort(p.begin(), p.end(),compare_by_b);

    int cou = 0;
    int frag = 0;
    for(int i = 0; i < N; i++){
        cou += p[i].first;
        if(cou > p[i].second){
            frag = 1;
            break;
        }
    }

    if(frag == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 2420
#include<iostream>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>

#define rep(i,start,n) for(int i=start ; i<n ; i++)

using namespace std;

int main(){

int n=0;
double p1=0,p2=0,p3=0,infinity[1000],inf=0;

cin >> n;                                                 //n?¬????????????????????????¨???

vector<double> V(n);                                    //???????¢????
vector<double> W(n);                                    //???????¢????

rep(i,0,n){
cin >> V[i];                                           //n?¬???????x??????????????\???
}

rep(i,0,n){
  cin >> W[i];                                           //n?¬???????y????????????
}

rep(i,0,n){
p1 += fabs(V[i]-W[i]);                                     //??????????????????????????¢
}

rep(i,0,n){
p2 += fabs(V[i]-W[i])*fabs(V[i]-W[i]);                       //???????????????????????¢
}

rep(i,0,n){
  p3 += fabs(V[i]-W[i])*fabs(V[i]-W[i])*fabs(V[i]-W[i]);           //????????¢
}

inf = 0;
rep(i,0,n){
  infinity[i] = fabs(V[i]-W[i]);
if(infinity[i]>inf){
  inf = infinity[i];                                                //???????????????????????¢
}
}

cout << fixed << setprecision(8) << p1 << endl;                          //??¨???
cout << fixed << setprecision(8) << sqrt(p2) << endl;
cout << fixed << setprecision(8) << pow(p3,1.0/3.0) << endl;
cout << fixed << setprecision(8) << inf << endl;

return 0;

}

Measured memory_bytes: 1328
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  long long k, a, b;
  cin >> k >> a >> b;

  long long ans = 0;
  if (b - a >= 2) {
    long long tmp = k - a + 1;
    ans += (b - a) * (long long)(tmp / 2) + tmp % 2 + a;
  } else {
    ans += k + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
tmp = input()
tmp_s = [int(x.strip()) for x in tmp.split(' ')]
N = tmp_s[0] #person number 1-N(0-N-1)
K = tmp_s[1] #K points
Q = tmp_s[2] #num of right
A = []
num_of_win = [0]*N
point = []
lost_point = [0]*N
for i in range(0, Q):
    A.append(int(input()))
    num_of_win[A[i]-1] += 1
S = sum(num_of_win)
for i in range(0, N):
    lost_point[i] = S - num_of_win[i]
    point.append(K-lost_point[i])
    if point[i] <= 0:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 16608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int w,h,n,cnt=0;
  int x[100],y[100],a[100],b[100][100]={};
  cin>>w>>h>>n;
  rep(i,0,n)cin>>x[i]>>y[i]>>a[i];

  rep(i,0,n){
    if(a[i]==1){
      for(int j=0;j<h;j++){
        for(int k=0;k<x[i];k++){
          b[j][k]=1;
        }
      }    
    }else if(a[i]==2){
      for(int j=0;j<h;j++){
        for(int k=x[i];k<w;k++){
          b[j][k]=1;
        }
      } 
    }else if(a[i]==3){
      for(int j=0;j<y[i];j++){
        for(int k=0;k<w;k++){
          b[j][k]=1;
        }
      } 
    }else if(a[i]==4){
      for(int j=y[i];j<h;j++){
        for(int k=0;k<w;k++){
          b[j][k]=1;
        }
      } 
    }
  }
  rep(i,0,h){
    rep(j,0,w){
      if(b[i][j]==0)cnt++;
    }
  }
  cout<<cnt<<endl;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long

int main(){
    int x;
    cin>>x;
    int a,b;
    a=x/100;
    b=x%100;
    if(0<b && b<13){
        if(0<a && a<13) cout<<"AMBIGUOUS"<<endl;
        else cout<<"YYMM"<<endl;
    }
    else{
        if(0<a && a<13) cout<<"MMYY"<<endl;
        else cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace AizuOnlineJudge
{
    class Program
    {
        static void Main(string[] args)
        {
            int d, i = 0;
            while((d = int.Parse(Console.ReadLine())) != 0)
            {
                Console.WriteLine($"Case {++i}: {d}");
            }
        }
    }
}



Measured memory_bytes: 17932
package main

import (
  "bufio"
  "container/list"
  "fmt"
  "os"
  "strconv"
  "strings"
)

func main() {
  io := IO{bufio.NewReaderSize(os.Stdin,100),bufio.NewWriterSize(os.Stdout,100)}
  n,k := io.NextInts()
  a := io.NextIntArray()
  s := make([]int,n+1)
  for i:=1;i<n+1;i++ { s[i] = (s[i-1]+a[i-1]-1)%k }
  m := map[int]int64{}
  q := list.New()
  x := int64(0)
  for i:=0;i<n+1;i++ {
    x += m[s[i]]
    m[s[i]]++
    q.PushBack(s[i])
    if q.Len() == k {
      t,_ := q.Remove(q.Front()).(int)
      m[t]--
    }
  }
  fmt.Println(x)
}

type IO struct {
  reader *bufio.Reader
  writer *bufio.Writer
}
func(io *IO) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := io.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(io *IO) Println(a ...interface{}) (int,error) {
  return fmt.Fprintln(io.writer,a...)
}
func(io *IO) Flush() error {
  return io.writer.Flush()
}
func(io *IO) NextInts() (int,int) {
  s := strings.Fields(io.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}
func(io *IO) NextIntArray() []int {
  s := strings.Fields(io.NextLine())
  a := make([]int,len(s))
  for i:=0;i<len(s);i++ { a[i],_ = strconv.Atoi(s[i]) }
  return a
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
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(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n;
  cin >> n;
  vector<ll> b(n-1);
  cin >> b;
  vector<ll> a(n, inf);
  rep(i, n){
    if(i < n - 1)a[i] = min(a[i], b[i]);
    if(i > 0)a[i] = min(a[i], b[i-1]);
  }
  ll res = 0;
  rep(i, n)res += a[i];
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
public static void main(String[] args){
	Scanner scanner = new Scanner(System.in);
  	String i = scanner.next();
  	char[] chars = i.toCharArray();
  	int sum = 0;
  	for(char c : chars){
    	sum += Integer.valueOf(c+"");
    }
  	String res = sum % 9 == 0 ? "Yes" : "No";
  System.out.println(res);
}
}

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

typedef long long LL;

#define FOR(i, a, b) for (int i = (a), i##_END_ = (b); i <= i##_END_; i++)
#define DNF(i, a, b) for (int i = (a), i##_END_ = (b); i >= i##_END_; i--)

template <typename Tp> void in(Tp &x) {
	char ch = getchar(), f = 1; x = 0;
	while (ch != '-' && (ch < '0' || ch > '9')) ch = getchar();
	if (ch == '-') f = -1, ch = getchar();
	while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= f;
}

template <typename Tp> Tp chkmax(Tp &x, Tp y) {return x > y ? x : x=y;}
template <typename Tp> Tp chkmin(Tp &x, Tp y) {return x < y ? x : x=y;}
template <typename Tp> Tp Max(Tp x, Tp y) {return x > y ? x : y;}
template <typename Tp> Tp Min(Tp x, Tp y) {return x < y ? x : y;}

char str[200010];

int num[30], sum;

int main()
{
	scanf("%s", str + 1); int l = strlen(str + 1);

	FOR(i, 1, l) num[str[i] - 'a']++;

	sum = l;

	LL ans = 1;
	
	FOR(i, 1, l) {
		num[str[i] - 'a']--;
		sum--;
		ans += sum - num[str[i] - 'a'];
	}

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


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll x, y;
	cin >> x >> y;

	FOR(c,0,1000) FOR(t,0,1000) {
		if (c+t == x && 2*c+4*t == y) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
}



Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<cctype>
#include<vector>
//vector<int> w(3);
using namespace std;
int main(){
        char ch;
        int ans=0;
        while(1){
                scanf("%c",&ch);
                if(ch!='\n'){
                    int c=ch-'0';
                    ans+=c;
                }else{
                        if(ans!=0){
                            printf("%d\n",ans);
                            ans=0;
                        }else{
                                break;
                        }
                }
        }
        return 0;
}

Measured memory_bytes: 1120
def func(n):
    c=0
    k=n
    while(n):
        n//=10
        c+=1
    if c%2==1:
        return True
    else:
        return False
N=int(input())
ans=0
for i in range(N):
    if func(i+1):
        ans+=1
print(ans)


Measured memory_bytes: 41708
from collections import deque


def next_turn(char):
    if char == 'a':
        return 0
    elif char == 'b':
        return 1
    elif char == 'c':
        return 2


def solve():
    sa = deque(list(input()))
    sb = deque(list(input()))
    sc = deque(list(input()))
    s = (sa, sb, sc)
    
    player = ['A', 'B', 'C']
    turn = 0
    while 1:
        card = s[turn].popleft()
        turn = next_turn(card)
        if not s[turn]:
            print(player[turn])
            exit()


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3316
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
    n, k = MAP()
    p = LIST()
    ans = 0
    tmp = 0
    if n == k:
        k = list(accumulate(range(max(p)+1)))
        for x in p:
            ans += k[x]/x
        
        print(ans)
        sys.exit()

    p_ = list(accumulate(p))
    #print(p_)


    for i in range(n-k):
        #print(i,p_[i+k]-p_[i])
        if tmp <= p_[i+k]-p_[i]:
            l = p[i+1:i+k+1]
            tmp = p_[i+k]-p_[i]

    #print('l:',l)
    k = list(accumulate(range(max(l)+1)))

    for x in l:
        ans += k[x]/x
        
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 26628
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string n;
    cin >> n;
    int64 res = 0;
    for(int i=0; i<n.size(); i++) {
        res += n[i] - '0';
        res %= 9;
    }
    string ans = res % 9 == 0 ? "Yes" : "No";
    cout << ans << endl;

}

Measured memory_bytes: 3372
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
ans = 10**10
for bit in range(1<<n):
  l = a[:]
  rev = [0]*n
  for i in range(n):
    if bit & 1<<i:
      rev[i] = 1
      l[i] = b[i]
  if sum(rev) % 2:
    continue
  odd = list()
  even = list()
  for i in range(n):
    if rev[i]^(i&1):
      even.append((l[i],i))
    else:
      odd.append((l[i],i))
  if len(even) != n//2:
    continue
  odd.sort()
  even.sort()
  l = list()
  for x,y in zip(odd,even):
    l.append(x)
    l.append(y)
  if n&1: l.append(odd[-1])
  fl = 0
  for x,y in zip(l,l[1:]):
    if x[0] > y[0]:
      fl = 1
      break
  if fl: continue
  f = [x[1] for x in l]
  # print('ok', bit, even, odd)
  cnt = 0
  g = [0]*n
  for x in f:
    cnt += sum(g[x:])
    g[x] = 1
  if ans > cnt:
    ans = cnt
if ans > 10**9:
  ans = -1
print(ans)

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

def get_name(N):

    alphabets = [chr(i) for i in range(97, 97+26)]
    length = len(alphabets)

    shou = (N - 1) // length
    amari = N % length

    if N <= 26:
        return alphabets[amari-1]
    else:
        return get_name(shou) + get_name(amari)

print(get_name(N))

Measured memory_bytes: 9048
arr = []
temp = int(input())
su =0
for i in range(2, int(-(-temp**0.5//1))+1):
  if temp%i==0:
    cnt=0
    while temp%i==0:
      cnt+=1
      temp //= i
    arr.append(cnt)
    
     
     
      

if temp!=1:
  arr.append(1)
  
 
if arr==[] and temp !=1:
  arr.append(1)
  su =1


for t in range(len(arr)):
  cnt =1
  while arr[t] -cnt>=0:
    arr[t] -=cnt
    su +=1
    cnt +=1
    
   
print(su)

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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin >> n;
	long long ans = 0;
	vector<bool> is_prime(1000001, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 3; i * i <= 1000000; i += 2) {
		if (!is_prime[i]) continue;
		for (int j = i * i; j <= 1000000; j += i) {
			is_prime[j] = false;
		}
	}
	vector<int> prime(1, 2);
	for (int i = 3; i <= 1000000; i += 2) {
		if (is_prime[i]) {
			prime.push_back(i);
		}
	}
	for (auto&& i : prime) {
		int cnt = 1;
		bool add = true;
		if (n % i) continue;
		if (n < i * i) break;
		while (add) {
			for (int j = 0; j < cnt; j++) {
				if (n % i) {
					add = false;
					break;
				}
				n /= i;
			}
			ans += add;
			cnt++;
		}
		if (n < i * i) break;
	}
	cout << ans + (n != 1) << "\n";
}

Measured memory_bytes: 4004
#include<stdio.h>
#define N 100000
#define NILL -1

typedef struct{
  int p;
  int l;
  int r;
}Node;
  
Node A[N];
int n,B[N];

  
int rec(int x,int y){
  B[x] = y;
  if(A[x].r != NILL) rec(A[x].r,y);
  if(A[x].l != NILL) rec(A[x].l,y + 1);
}


int main(){
  int i,j,d,v,c,l,r,n,op;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = A[i].l = A[i].r = NILL;
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) A[v].l=c;
      else A[l].r = c;
      l=c;
      A[c].p = v;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == -1) r=i;
  }

  rec(r,0);

  for(i=0;i<n;i++){
   
    printf("node %d: parent = %d, depth = %d,",i,A[i].p,B[i]);
    if(A[i].p == -1) printf(" root,");
    else if(A[i].l == -1 ) printf(" leaf,");
    else printf(" internal node,");
    printf(" [");
    for(j=0,op=A[i].l;op != -1;j++,op = A[op].r){
      if(j != 0) printf(", ");
      printf("%d",op);
    }
    printf("]\n");  
  }

  return 0;
}



Measured memory_bytes: 6468
import sys

def div(n):
    count = 0
    for i in range(1, n+1):
        count += 1 if n%i==0 else 0
    return count

ans = 0
for i in range(1, int(input())+1):
    ans += 1 if i%2==1 and div(i) == 8 else 0
print(ans)

Measured memory_bytes: 9036
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>


using namespace std;


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

int n;
int must_win;

vector<vector<int>> result;
vector<int> win_count;

int dfs(int i, int j) {
  int count = 0;

  if (win_count[i] > must_win) {
    return 0;
  }

  if (i == j) {
    int i_ = i;
    int j_ = j + 1;
    if (j_ == n) {
      if (win_count[i] < must_win) {
        return 0;
      }
      i_++;
      j_ = 0;
    }
    return dfs(i_, j_);
  }

  if (i == n && j == 0) {
    for (int i = 0; i < n; i++) {
      if (win_count[i] != must_win) {
        return 0;
      }
    } 
    return 1;
  }



  if (result[i][j] != 0) {
    int i_ = i;
    int j_ = j + 1;
    if (j_ == n) {
      if (win_count[i] < must_win) {
        return 0;
      }
      i_++;
      j_ = 0;
    }

    return dfs(i_, j_);
  }

  if (win_count[i] < must_win) {
    // If win
    result[i][j] = 1;
    result[j][i] = -1;
    win_count[i]++;

    count += dfs(i, j);

    // Undo
    result[i][j] = 0;
    result[j][i] = 0; 
    win_count[i]--;
  }

  if (win_count[j] <= must_win) {
    // If Lose
    result[i][j] = -1;
    result[j][i] = 1;
    win_count[j]++;

    count += dfs(i, j);

    result[i][j] = 0;
    result[j][i] = 0;
    win_count[j]--;
  }

  return count;
}


int main() {
  while (true) {
    cin >> n;
    if (n == 0) {
      break;
    }
    int m;
    cin >> m;

    result.clear();
    result.resize(n);
    for (int i = 0; i < n; i++) {
      result[i] = vector<int>(n);
    }
    win_count.clear();
    win_count.resize(n);

    for (int i = 0; i < m; i++) {
      int x, y;
      cin >> x >> y;
      x--; y--;

      result[x][y] = 1;
      result[y][x] = -1;
      win_count[x]++;
    }
    
    must_win = n / 2;

    int ans = dfs(0, 0);
    
    cout << ans << endl;

  }
  return 0;
}


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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int L; cin >> L;
	vector<pair<int,int>> V;
	while((1<<18) <= L){
		L -= (1<<18);
		V.push_back(make_pair(2,L));
	}
	repm(i,17,-1) if((1<<i) <= L){
		L -= (1<<i);
		V.push_back(make_pair(20-i,L));
	}
	cout << 20 << ' ' << V.size()+36 << endl;
	for(auto u : V) cout << 1 << ' ' << u.first << ' ' << u.second << endl;
	repp(i,2,20){
		cout << i << ' ' << i+1 << ' ' << (1<<(19-i)) << endl;
		cout << i << ' ' << i+1 << ' ' << 0 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
c = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[c - 1])


Measured memory_bytes: 2940
#include<cstdio>

int main(){
    int x,y;
    for(int i = 0;; i++){
        scanf("%d %d",&x,&y);
        if(x == 0 && y == 0){
            break;
        }
        if(x > y){
            int z = x;
            x = y;
            y = z;
        }
        else{
            x = x;
            y = y;
        }
        printf("%d %d\n",x,y);
    }
    return 0;
}


Measured memory_bytes: 2620
class UnionFind
        def initialize(n)
                @parent = (0..n).to_a
        end

        def unite(x,y)
                rx, ry = x, y
                while @parent[rx] != @parent[ry] do
                        if @parent[rx] > @parent[ry] then
                                rx,ry = ry,rx
                        end
                        if rx == @parent[rx] then
                                @parent[rx] = @parent[ry]
                                break
                        end
                        @parent[rx], rx = @parent[@parent[ry]], @parent[rx]
                end
        end

        def root(x)
                while x != @parent[x] do
                        x = @parent[@parent[x]]
                end
                return x
        end

        def same?(x,y)
                root(x) == root(y)
        end
end

ab = $<.map { |x| x.split.map(&:to_i) }
N, M = ab.shift


res = M.times.map do |j|
	uf = UnionFind.new(N)
	M.times.map do |i|
		next if j == i
		uf.unite(ab[i][0], ab[i][1])
	end
	true if	(1..N).map { |k| uf.root(k) }.uniq.size == 1
end

p res.count(&:nil?)


Measured memory_bytes: 1916
#include<iostream>
using namespace std;
int main(){
  int n,m,max=0;
  while(1){
    max=0;
    bool flag=false;
    cin>>n>>m;
    if(n==0&&m==0){
      break;
    }
    int a[n];
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
  
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++){
	  if(max<a[j]+a[k] && a[j]+a[k]<=m&&j!=k){
	    max=a[j]+a[k];
	    flag=true;
	  }
      }
    }
    if(flag==false){
      cout<<"NONE"<<endl;
    }else{
      cout<<max<<endl;
    }
  }
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 set<string> s;
 ll n;
 cin>>n;
 for(ll i=0;i<n;i++){
  string t;
  cin>>t;
  s.insert(t);
 }
 cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 19136
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    vi data(N); F0R(i, N) cin >> data[i];
    int ans = 10000000;
    FOR(p, 1, 101) {
        int val = 0;
        F0R(i, N) val += (data[i] - p) * (data[i] - p);
        ans = min(ans, val);
    }
    cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 256
s = int(input())

import numpy as np
import itertools
candess = []
cnt = 0

for i in range(3, 10):
    candes = list((itertools.product([3,5,7], repeat=i)))
    for cande in candes:
        if (3 in cande) and (5 in cande) and (7 in cande) and \
        (int(''.join(map(str, cande)))) <= s:
            cnt += 1
print(cnt)

Measured memory_bytes: 15592
""" 解答AC """

N,x = map(int,input().split())
a = list(map(int,input().split()))

ans = float("inf")

# b[i]: 色iを飼うために「捕まえる」操作時間の最小値
b = a.copy()

# 魔法をちょうどk回唱える場合
for k in range(N):
    for i in range(N):
        b[i] = min(b[i], a[(i-k) % N])

    ans = min(ans, k * x + sum(b))

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define pii             pair<LL , LL >
#define inf             1111111111
#define in(a)           scanf("%d", &a)
#define ins(a)          scanf("%s", a)
#define in2(a, b)       scanf("%d%d", &a, &b)
#define in3(a, b, c)    scanf("%d%d%d", &a, &b, &c)
#define pn              printf("\n")
#define pr(a)           printf("%d\n", a)
#define prs(a)          printf("%d ", a)
#define pr2(a, b)       printf("%d %d\n", a, b)
#define pr3(a, b, c)    printf("%d %d %d\n", a, b, c)
#define pcs(a)          printf("Case %d: ", a)
#define mp              make_pair
#define vi              vector<LL >
#define _ceil(n, a)     ((n)%(a)==0?((n)/(a)):((n)/(a)+1))
#define cl              clear()
#define sz              size()
#define pb              push_back
#define mem(a, b)       memset((a), (b), sizeof(a))
#define all(X)          (X).begin(), (X).end ()
#define iter(it, X)     for (__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#define ext(a)          {printf("%s\n", a); return 0;}
#define oka(x, y)       ((x)>=0&&(x)<row&&(y)>=0&&(y)<col)
#define x               first
#define y               second
#define lc              (2*i)
#define rc              (2*i+1)

typedef long long LL;
typedef unsigned long long ULL;
//LL  dx[]={1,0,-1,0};LL dy[]={0,1,0,-1}; //4 Direction
//LL  dx[]={1,1,0,-1,-1,-1,0,1,0};LL dy[]={0,1,1,1,0,-1,-1,-1,0};//8 direction
//LL  dx[]={2,1,-1,-2,-2,-1,1,2};LL dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//bool check(LL n, LL pos) {return (n & (1<<pos))>>pos;} //typecast 1 in case of int
//LL  on(LL n, LL pos) {return n | (1<<pos);} //typecast 1 in case of int
//LL  off(LL n, LL pos) {return n & ~(1<<pos);} //typecast 1 in case of int
//bool operator < (const data &d) const{return cost<d.cost;} //reverse in priority queue

const LL M=4010;
const LL mod = 1000000007;

string a, b;
LL acnt[30], bcnt[30];
ULL p[M];

bool ispossible(LL len)
{
    LL i, j, k;

    unordered_map<ULL, bool>mep;
    mem(acnt, 0);
    mem(bcnt, 0);

    for (i=0; i<len; i++) acnt[a[i]-'a']++;
    ULL hval = 0;
    for (i=0; i<26; i++) hval = (hval + (acnt[i] * p[i])  ) ;
    mep[hval] = 1;

    for (i=0, j=len; j < a.size(); i++, j++)
    {
        hval = ((hval - p[a[i]-'a'])) ;
        hval = (hval + p[a[j]-'a']) ;
        mep[hval] = 1;
    }

    for (i=0; i<len; i++) bcnt[b[i]-'a']++;
    hval = 0;
    for (i=0; i<26; i++) hval = (hval + (bcnt[i] * p[i])  ) ;

    if (mep[hval]) return true;

    for (i=0, j=len; j < b.size(); i++, j++)
    {
        hval = ((hval - p[b[i]-'a'])) ;
        hval = (hval + p[b[j]-'a']) ;
        if (mep[hval]) return true;
    }

    return false;
}

int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("C:\\Users\\Dell\\Desktop\\in.txt", "r", stdin);
////    freopen("C:\\Users\\Dell\\Desktop\\in.txt", "w", stdout);
//#endif
  //  ios_base::sync_with_stdio(false);

    LL i, j, k, len;
    p[0] = 1;
    for (i=1; i<M; i++) p[i] = (p[i-1] * 31) ;

    cin>>a>>b;
    for (len=min(a.size(), b.size()); len>0; len--)
    {
        if (ispossible(len)) break;
    }

    cout<<len<<endl;


return 0;
}

Measured memory_bytes: 3496