akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define mp(i,j) make_pair(i,j)
#define debug_v(v,N) for(int i=0;i<N;i++) { cout << v[i] << " "; } cout << endl;
#define debug_vv(v,H,W) for(int i=0;i<H;i++) { for(int j=0;j<W;j++) { cout << v[i][j] << " "; } cout << endl; }

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

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

int A[100010];

void Main()
{
	int N, K; cin >> N >> K;
	rep(i,N) cin >> A[i];
	N -= K;
	int res = 1;
	res += (N + (K - 1) - 1) / (K - 1);
	cout << res << endl;
}

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


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	string S;
	int Q;
	cin >> S >> Q;
	deque<char> T;
	fx(S.size()) {
		T.push_back(S[x]);
	}
	bool flag = true;
	fx(Q) {
		int a;
		cin >> a;
		if (a==1) {
			flag = !flag;
		}
		else {
			int f;
			char c;
			cin >> f >> c;
			if (f==1) {
				if (flag) {
					T.push_front(c);
				}
				else {
					T.push_back(c);
				}

			}
			else {
				if (flag) {
					 T.push_back(c);
				}
				else {
					T.push_front(c);
				}
			}
		}
	}
	int t = T.size();
	fx(t) {
		if(flag)
		cout << T[x];
		else
			cout << T[t-x-1];
	}
	cout << endl;
    return 0;
}



Measured memory_bytes: 896
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;

#define int ll
#define LOCAL 0
#define dbg(x) cout << #x << " is " << x << "\n"
#define gll(x) scanf("%d",&x)
#define gll2(x,y) scanf("%d%d",&x,&y)
#define gll3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define gllarr(arr,n) f(i,n) gll(arr[i]);
#define sz(x) ((int)x.size())
#define s(x) sort(x.begin(),x.end())
#define all(v) v.begin(),v.end()
#define rs(v) { s(v) ; r(v) ; }
#define r(v) {reverse(all(v));}
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define fr(i,n) for(int i=n-1;i>=0;i--)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)

const ll mod = (ll)1e9 + 7;
const ll inf = (ll)1e16;
const ld eps = 1e-12;
const ll N = (int)2e5 + 5;
const ll LOGN = 19;
const ld PI = 3.14159265358979323846;
inline ll mul(ll a, ll b, ll m = mod) { return (ll)(a * b) % m;}
inline ll add(ll a, ll b, ll m = mod) { a += b; if(a >= m) a -= m; if(a < 0) a += m; return a;}
inline ll power(ll a, ll b, ll m = mod) { if(b == 0) return 1; if(b == 1) return (a % m); ll x = power(a, b / 2, m); x = mul(x, x, m); if(b % 2) x = mul(x, a, m); return x;}

void solve() {
    int n;
    cin>>n;
    cout<<n + n * n + n * n * n<<endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    if (LOCAL) {
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\input.txt", "r", stdin);
        freopen("C:\\Users\\Dishant\\Desktop\\Collection-DEV c++\\output.txt", "w", stdout);
    }
    int t = 1;
    //cin>>t;
    for(int test = 1; test <= t; test++) {
        //cout<<"Case #"<<test<<": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <complex>
using namespace std;

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

#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp make_pair
#define ERASE(v,i) (v).erase(remove(all(v),i),(v).end())
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(c,it) for(typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define debug(x) cerr<<#x<<" = "<<(x)<<endl;
#define LINE cerr<<"LINE: "<<__LINE__<<endl;

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T> void preview(T a,T b){for(T it=a;it!=b;++it)cerr<<*it<<" ";cerr<<endl;}

const int INF = 100000000;
const double PI = acos(-1.0), EPS = 1e-10;

int main() {
	for(double d; cin >> d;) {
		string s;
		if(d <= 48.00) s = "light fly";
		else if(d <= 51.00) s = "fly";
		else if(d <= 54.00) s = "bantam";
		else if(d <= 57.00) s = "feather";
		else if(d <= 60.00) s = "light";
		else if(d <= 64.00) s = "light welter";
		else if(d <= 69.00) s = "welter";
		else if(d <= 75.00) s = "light middle";
		else if(d <= 81.00) s = "middle";
		else if(d <= 91.00) s = "light heavy";
		else s = "heavy";
		cout << s << endl;
	}
	return 0;
}

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

int main() {
    string s,t;
    cin >> s;
    cin >> t;

    string u = t.substr(0,s.size());

    if (s == u) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N; scanf("%d", &N);
  vector<int> primep(56000, 1);
  primep[0] = 0;
  int upper = 55555;
  for (int i = 2; i * i <= upper; ++i) {
    if (not primep[i]) { continue; }
    for (int j = i * i; j <= upper; j += i) {
      primep[j] = 0;
    }
  }
  vector<int> ans(N);
  int ix = 0;
  for (int i = 2; i <= upper; ++i) {
    if (not primep[i]) { continue; }
    if (i % 5 == 2) {
      ans[ix] = i;
      if (++ix == N) { break; }
    }
  }
  printf("%d", ans[0]);
  for (int i = 1; i < N; ++i) {
    printf(" %d", ans[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 512
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const ll mod = 1e9 + 7;
const int N = 2e3 + 10, M = 2e3 + 10;
const ll INF = 5e18;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;

#define pi acos(-1)

int dp[N][N]; //长度为i，和为j的方案数
set<pii> s;

int main()
{

    int n;
    scanf("%d", &n);
    dp[0][0] = 1;
    int ans = 0;
    for (int i = 1; i <= n / 3; i++)
    {
        for (int k = 0; k + 3 <= n; k++)
        {
            dp[i][k + 3] += dp[i - 1][k];
        }
        for (int k = 3; k <= n; k++)
        {
            dp[i][k] = (dp[i][k] + dp[i][k - 1]) % mod;
        }
        ans += dp[i][n];
        ans %= mod;
    }
    cout << ans << endl;
    // for (auto i : s)
    //     cout << i.first << ' ' << i.second << endl;
    return 0;
}
/*
1477863787
*/

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

int main(){
  ll N, A, B;
  cin>>N>>A>>B;
  ll n,l;
  n=N/(A+B);
  l=N%(A+B);
  
  if(l>=A){
    cout<<A+A*n<<endl;
  }
  else{
    cout<<A*n+l<<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int q[501][501];
int n,m;
int ans;
struct data{
	int i,j;
	int x,y;
}qwq[1000010];
signed main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	  for(int j=1;j<=m;j++)
	    scanf("%d",&q[i][j]);
	for(int i=1;i<n;i++)
	  for(int j=1;j<=m;j++)
	  	if(q[i][j]&1) q[i+1][j]++,qwq[++ans].i=i,qwq[ans].j=j,qwq[ans].x=i+1,qwq[ans].y=j;
	for(int j=1;j<m;j++) if(q[n][j]&1) q[n][j+1]++,qwq[++ans].i=n,qwq[ans].j=j,qwq[ans].x=n,qwq[ans].y=j+1;
	printf("%d\n",ans);
	for(int i=1;i<=ans;i++) printf("%d %d %d %d\n",qwq[i].i,qwq[i].j,qwq[i].x,qwq[i].y); 	
}


Measured memory_bytes: 6272
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, i := nextInt(), nextInt()

	fmt.Println(N - i + 1)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	int c;
	while(cin>>a>>b>>c){
		int sum=0;
		a%=b;
		rep(i,c){
			a*=10;
			sum+=a/b;
			a%=b;
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
 
typedef long long int ll;
typedef pair<ll,ll> P;
 
int A[3][4001];
int ss[4001];
 
int main(){
    int n;
    string s;
    cin>>n>>s;
    int col[3]={0,0,0};
    for(int i=0;i<n;i++){
        switch(s[i]){
            case 'R':
                col[0]++;ss[i]=0;break;
            case 'G':
                col[1]++;ss[i]=1;break;
            case 'B':
                col[2]++;ss[i]=2;break;
        }
        A[0][i]=col[0];A[1][i]=col[1];A[2][i]=col[2];
    }
    ll sum=0;
    for(int sta=0;sta<n;sta++){
        for(int x=1;sta+x+1<n;x++){
            if(ss[sta]==ss[sta+x]){continue;}
            int tmp=3-ss[sta]-ss[sta+x];
            sum+=A[tmp][n-1]-A[tmp][sta+x];
            if(sta+x+x<n){
                sum-=(A[tmp][sta+x+x]-A[tmp][sta+x+x-1]);
            }
        }
    }
    cout<<sum;
 
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include<bits/stdc++.h>
const int N=1e5+5;
const int M=1e7;
using namespace std;

int main()
{
    long long t,x,y,n,m,i,j,a,b;
    cin>>n>>a>>b;
    x=(b-a)/2;
    t=b-a;
    if(t%2==0) cout<<x;
    else{
        x=b-1;
        y=n-a;
        if(x>y) cout<<y-(t-1)/2;
        else cout<<x-(t-1)/2;
    }
    return 0;
}


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

int main(){
  stack<int> t;
  string s;
  int a,b,c;
  while(cin>>s){
    if('0'<=s[0]&&s[0]<='9'){
      if(s.size()>=2){
	a=s.size();
	b=1;
	for(int i=0;i<a-1;i++)b*=10;
	c=0;
	for(int i=0;i<a;i++){
	  c+=(s[i]-'0')*b;b/=10;	  
	}
	t.push(c);
      }
      else t.push(s[0]-'0');
    }
    else if(s=="+"){
      a=t.top();t.pop();
      b=t.top();t.pop();
      t.push(a+b);
    }
    else if(s=="-"){
      a=t.top();t.pop();
      b=t.top();t.pop();
      t.push(b-a);
    }
    else if(s=="*"){
      a=t.top();t.pop();
      b=t.top();t.pop();
      t.push(a*b);     
    }
  }
  cout <<t.top()<<endl;
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
int a[N];

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, m, l, r;
	cin >> n >> m;

	for(int i = 0; i < m; i++){
		cin >> l >> r;
		a[l] += 1;
		if(r + 1 <= n) a[r+1] -= 1;
	}

	int ans = 0;
	for(int i = 1; i <= n; i++){
		a[i] += a[i-1];
		if(a[i] == m) ans++;
	}
	cout << ans;
}	

Measured memory_bytes: 640
from itertools import combinations
n,d=map(int,input().split())
x=[list(map(int,input().split())) for i in range(n)]
ans=0
for i,j in combinations(x,2):
    l=0
    for k in range(d):
        l+=(i[k]-j[k])**2
    if int(l**0.5)**2==l:
        ans+=1
print(ans)

Measured memory_bytes: 3188
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<set>
#include<map>
using namespace std;


int main() {
    string s;
    cin >> s;
    int r = 0;
    for(int i = 0; i < 4; i++){
        if(s[i] == '+'){
            r++;
        }
        else{
            r--;
        }
    }
    cout << r;
    cout << endl;
}


Measured memory_bytes: 256
A, B = list(map(int, input().split()))
M = max(A, B)
if M == 1:
    print(1, 2)
    print("#.")

else:
    D = 2 * (M - 1) if M <= 50 else 100
    if A == 1:
        h = ((B-2)//50 + 2) * 2  + 1
    elif B == 1:
        h = ((A-2)//50 + 2) * 2  + 1 
    else:
        h = ((A-2)//50 + (B-2)//50 + 2) * 2  + 1 

    print(h, D)
    
    def gene(N, flag):
        global h
        N -= 1
        p, q = [".", "#"] if flag == "A" else ["#", "."]
        pq = p + q
        count = (N-1)//50 + 1
        while count > 1:
            print(pq * 50)
            print(q * 100)
            count -= 1
            N -= 50
            
        print(pq * N + q * (D - 2*N))
        print(q * D)
    
    gene(A, "A")
    print("." * D)
    gene(B, "B")
    


Measured memory_bytes: 3064
n=int(input())
B=[int(i) for i in input().split()]
A=[]
A.append(B[0])
for i in range(n-1):
	A.append(B[i])
	if A[i]>B[i]:
		A[i]=B[i]
	if A[i+1]>B[i]:
		A[i+1]=B[i]
		print(A)
	else:
		continue
print(sum(A))

Measured memory_bytes: 3064
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, M, X = map(int, input().split())
a = list(map(int, input().split()))
l = [0]*(N+1)
for i in a:
    l[i] += 1
print(min(sum(l[0:X]), sum(l[X+1: N+1])))


Measured memory_bytes: 3060
#include<cstdio>
long long a,b;
int main() {
	scanf("%lld%lld",&a,&b);
	long long ans;
	if (a%2==0) ans=(a/2)*b; else if (b%2==0) ans=(b/2)*a; else ans=((a-1)/2)*b+(b/2)+1;
	if (a==1||b==1) ans=1;
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;


public class Main {
	

	
	
	public static void main(String[] args) {

		
		Scanner s = new Scanner(System.in);
		
		int n = s.nextInt();
		
		System.out.println(2*Math.PI*n);
		
	}
}

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

using namespace std;

#define FOR(i,s,e) for((i)=(s);(i)<(int)(e);(i)++)
#define REP(i,e) FOR(i,0,e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

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

const double EPS = 1e-10;

const int H = 10;
const int W = 5;
int h;
int c[H][W];

int main() {
  int i, j, k, l;
  int res;

  while (1) {
    scanf("%d ", &h); 
    if (!h) break;

    for (i=0; i<h; i++)
      for (j=0; j<W; j++)
        scanf("%d ", &(c[i][j]));

    res = 0;
    bool update = true;
    while (update) {
      update = false;
      for (i=h-1; i>=0; i--) {
        for (j=0; j<3; j++) {
          k = 1;
          while (c[i][j]!=0 && j+k<W && c[i][j+k]==c[i][j]) k++;
          if (k >= 3) {
            res += k * c[i][j];
            for (l=j; l<j+k; l++) c[i][l] = 0;
            update = true;
            break;
          }
        }
      }

      for (i=h-2; i>=0; i--)
        for (j=0; j<W; j++) {
          int d = i;
          while (d+1<h && c[d+1][j]==0) d++;
          if (i!=d) {
            c[d][j] = c[i][j];
            c[i][j] = 0;
          }
        }
    }

    printf("%d\n", res);
  }

  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  while(1){
    long long a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if(!a&&!b&&!c&&!d&&!e)break;
    long long na,nb,nc;
    cin>>na>>nb>>nc;
    long long ans=0;
    if(d<=nc)ans=(nc*e)+nb*b+na*a;
    else {
      ans=min(nc*c+nb*b+na*a,d*e+nb*b+na*a);
      long long tmp=ans;
      nb=nb-(d-nc);
      if(nb<0) na+=nb,nb=0;
      if(na<0) tmp=min(tmp,d*e);
      else tmp=min(tmp,d*e+nb*b+na*a);
      ans=min(ans,tmp);
    }
    cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100];
ll d[100];

ll f(ll n, ll x){
	if(d[n]==x&&dp[n]!=-1)return dp[n];
	ll ret = 0;
	if(n==0){
		return 1;
	}
	if(x<=1){
		return 0;
	}
	else if(x<=1+d[n-1]){
		ret = f(n-1,x-1);
	}
	else if(x<=1+d[n-1]+1){
		ret = f(n-1,d[n-1])+1;
	}
	else if(x<=1+d[n-1]+1+d[n-1]){
		ret = f(n-1,d[n-1])+1+f(n-1,x-d[n-1]-2);
	}
	else{
		ret = f(n-1,d[n-1])+1+f(n-1,d[n-1]);
	}
	if(d[n]==x){
		dp[n] = ret;
	}
	return ret;
}

int main(){
	clr(dp,-1);
	ll ans = 0;
	ll n,x;
	cin>>n>>x;
	d[0] = 1;
	rep(i,1,100){
		d[i] = d[i-1]*2+3;
	}
	ans = f(n,x);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
d=dict()
while n>0:
    s=input()
    if d.get(s)==None:
        d[s]=1
    else:
        d[s]+=1
    n-=1
d2=sorted(d.items(),key=lambda x:x[1],reverse=True)
arr=[]
for i in d2:
    if i[1]==d2[0][1]:
        arr.append(i[0])
    else:
        break

for i in sorted(arr):
    print(i)


Measured memory_bytes: 47324
-- https://github.com/minoki/my-atcoder-solutions
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
import Data.Char (isSpace)
import Data.List (unfoldr, sort)
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Ord
import Data.Coerce

sortDown :: forall a. Ord a => [a] -> [a]
sortDown = coerce (sort :: [Down a] -> [Down a])

exchangeOne :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Int
exchangeOne !gA !sA !bA !gB !sB !bB !n =
  let dg = gB - gA
      ds = sB - sA
      db = bB - bA
      l = sortDown $ filter (\(d,x) -> d > 0) [(dg, gA), (ds, sA), (db, bA)]
  in case l of
       [] -> n
       [(!dx,!xA)] -> let (qx,rx) = n `quotRem` xA
                          -- A で qx * gA 個のどんぐりを売却し、金 qx グラムを得る。
                          -- B で金 qx グラムを売却し、 qx * gB 個のどんぐりを得る。
                      in n + qx * dx
       [(!dx,!xA),(!dy,!yA)] -> n + maximum [ x * dx + y * dy
                                            | x <- [0..n `quot` xA]
                                            , let y = (n - x * xA) `quot` yA
                                            ]
       [(!dx,!xA),(!dy,!yA),(!dz,!zA)] -> n + maximum [ x * dx + y * dy + z * dz
                                                      | x <- [0..n `quot` xA]
                                                      , y <- [0..(n - x * xA) `quot` yA]
                                                      , let z = (n - x * xA - y * yA) `quot` zA
                                                      ]

main = do
  n <- readLn
  [gA,sA,bA] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  [gB,sB,bB] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ exchangeOne gB sB bB gA sA bA $ exchangeOne gA sA bA gB sB bB n


Measured memory_bytes: 2428
import sys,queue,math,copy,itertools,bisect,collections,heapq
LI = lambda : [int(x) for x in sys.stdin.readline().split()]

N,M = LI()
A = itertools.accumulate(LI())

d = {0:1}
for x in A:
    m = x % M
    if m in d: d[m] += 1
    else: d[m] = 1

ans = 0
for x in d.values():
    ans += x * (x-1) // 2
print (ans)

Measured memory_bytes: 60700
// -----------------------------------
// Author     : MatsuTaku
// Country    : Japan
// Created    : 05/02/20 20:07:37
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int k,a,b; cin>>k>>a>>b;
  bool ans = (a/k > 0 and a%k==0) or (a/k<b/k);
  cout << (ans ? "OK" : "NG") << endl;

  return 0;
}


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

using namespace std;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << static_cast<char>(s1[0] - 'a' + 'A')
            << static_cast<char>(s2[0] - 'a' + 'A')
            << static_cast<char>(s3[0] - 'a' + 'A') << endl;
}


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

int main() {
    int K , X ;
    cin >> K >> X ; // 1 ≤ K ≤ 100, 1 ≤ X ≤ 10^5
    int T = K * 500;
    if(T < X) cout << "No"<< endl;
    else cout << "Yes" <<endl;
	return 0;
}

Measured memory_bytes: 3528
#include <bits/stdc++.h>
using namespace std;
int main(){
	int x,y;
	cin>>x>>y;
	int a[7]={1,3,5,7,8,10,12};
	int b[4]={4,6,9,11};
	int c=2;
	int p=0,q=0;
	for(int i=0;i<7;i++){
		if(a[i]==x) p=1;
		if(a[i]==y) q=1;
	}
	for(int i=0;i<4;i++){
		if(b[i]==x) p=2;
		if(b[i]==y) q=2;
	}
	if(c==x) p=3;
	if(c==y) q=3;
	if(p==q){
		cout<<"Yes";
	}
	else
		cout<<"No";
}

Measured memory_bytes: 256
n, q = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
q.times do
  l, r = gets.split.map(&:to_i)
  i = (0..n-1).bsearch {|i| l <= a[i] } || n
  j = (0..n-1).bsearch {|j| r <  a[j] } || n
  p j - i
end


Measured memory_bytes: 15048
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
using namespace std;
struct ST
{
    int x;
    int deep;
    string s;
};
int mx[4] = {1, -1, 4, -4};
int a[10][10];
int ans =0;
map<string, int> vis;
//int ans = 0;
void bfs()
{
    ST star;
    star.x = 0;
    star.deep = 0;
    star.s = "01234567";
    queue<ST> q;
    q.push(star);
    vis[star.s] = 0;
    while(!q.empty())
    {
        ST u = q.front();
        q.pop();
        for(int i = 0; i < 4; i++)
        {
            if(i == 0 && u.x == 3)
                continue;
            if(i == 1 && u.x == 4)
                continue;
            ST v;
            v.x = u.x + mx[i];
            v.s = u.s;
            if(v.x >=0 && v.x < 8)
            {

                swap(v.s[u.x], v.s[v.x]);
                if(!vis[v.s]){
                    vis[v.s] = u.deep + 1;
                    v.deep = u.deep + 1;
                    q.push(v);
                }
            }
        }
    }
}
int main()
{
    bfs();
    ios::sync_with_stdio(false);
    string s;
    while(getline(cin, s))
    {
        string t = "";
        int L = s.size();
        for(int i = 0;i < L; i = i + 2)
        {
            t += s[i];
        }
        cout << vis[t] << endl;

    }
    return 0;
}



Measured memory_bytes: 5276
#include <iostream>

using namespace std;

struct point {
	int x, y;
};

int main() {
	point A, B;

	cin >> A.x >> A.y >> B.x >> B.y;

	cout << B.x + A.y - B.y << " " << -A.x + B.x + B.y << " " <<
		A.x + A.y - B.y << " " << -A.x + B.x + A.y << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
using namespace std;

string head[20]={"yotta","zetta","exa","peta","tera","giga","mega","kilo","hecto","deca","deci","centi","milli","micro","nano","pico","femto","ato","zepto","yocto"};
int m[21]={24,21,18,15,12,9,6,3,2,1,-1,-2,-3,-6,-9,-12,-15,-18,-21,-24,0};

int main(){
	int n;
	string S;
	cin>>n;
	getline(cin,S);
	for(int h=0;h<n;h++){
	int c=0,e=0,f=0,D,cur=0;
		string s[3]={"","",""};
		getline(cin,S);
		while(cur<S.size()){
			if(S[cur]==' ')c++;
			else s[c]+=S[cur];
			cur++;
		}
	if(s[0][0]=='0'){
		int d=2;
		while(s[0][d]=='0'){d++;}
		if(s[0].size()==d+1)cout<<s[0][d];
		else cout<<s[0][d]<<"."<<s[0].substr(d+1);
		D=1-d;
	}
	else {
		int d=1;
		if(s[0].size()==1)cout<<s[0];
		else {
			while(s[0][d]!='.'){d++; if(d==s[0].size()){e=1;break;}}
			if(e==0)cout<<s[0][0]<<"."<<s[0].substr(1,d-1)<<s[0].substr(d+1);
			else cout<<s[0][0]<<"."<<s[0].substr(1);
		}
		D=d-1;
	}
	if(c==2)while(s[1]!=head[f])f++;
	else f=20;
	cout<<" * 10^"<<D+m[f]<<" "<<s[c]<<endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X,Y;
    cin >> X >> Y;
    ll ans = 0;
    while(X <= Y){
        X *= 2;
        ans++;
    }
    print(ans);


}


Measured memory_bytes: 256
n = int(input())
L = []
i = 0
while i < n:
    s,p = map(str,input().split(' '))
    p = -1*int(p)
    L.append((s,p,i))
    i += 1
L.sort()
ans = ''
for l in L:
    ans += str(l[2]+1)+'\n'
print(ans[:-1])

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
  int nows = 1;
  long long int n = 2;
  long long int m = 1;
  int cc;
  cin >> cc;
  while(true){
    if(cc == 1){
      cout << 1 << endl;
      break;
    }
    n = n + m;
    nows++;
    if(cc == nows){
      cout << n << endl;
      break;
    }
    m = n + m;
    nows++;
    if(cc == nows) {
      cout << m << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long ;
using P = pair<ll, ll>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fs first
#define sc second
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	ll a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;

	vector<bool> water(31, false);
	water[0] = true;
	repn(i, f/100){
		if(i >= a && water[i-a]) water[i] = true;
		else if (i >= b && water[i-b]) water[i] = true;
	}

	vector<bool> suger(f+1);
	suger[0] = true;
	repn(i, f){
		if(i >= c && suger[i-c]) suger[i] = true;
		else if(i >= d && suger[i-d]) suger[i] = true;
	}

	ll ansW = 0, ansS = 0;
	double ansP = 0;
	repn(i, f/100){
		if(water[i]){
			ll s = i*e;
			repr(j, s){
				if(suger[j] && i*100+j <= f){
					if((double)j/(i*100+j) >= ansP){
						ansW = i, ansS = j, ansP = (double)j/(i*100+j);
					}
					break;
				}
			}
		}
	}

	cosp(ansW*100+ansS); co(ansS);

	return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  for(int i = 0; i < 8; i++) {
    if(N >= pow(2, i) && N < pow(2,i+1)) {
    cout << pow(2, i) << endl;
    break;
    }
  }
}

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

const int MOD = 1000000007;
const int INF = 1e9;

int main(){
  char a;
  cin >> a;

  string ans;
  if(a <= 90) ans = "A";
  else ans = "a";

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <set>

using namespace std;
typedef long long lli;

int main() {
  string str; cin >> str;
  int k; cin >> k;
  set<string> memo;
  int windowSize = min(k + 5, (int)str.size());
  for (int i = 0; i < str.size(); i++) {
    string tmp = "";
    for (int j = 0; j + i < str.size() && j < windowSize; j++) {
      tmp += str[j + i];
      memo.insert(tmp);
    }
  }
  string ans = "";
  int cnt = 1;
  for (auto it = memo.begin(); it != memo.end(); it++) {
    if (cnt == k) {
      ans = *it;
      break;
    }
    cnt++;
  }
   cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> vec(M*2);
    
    for (int i = 0; i < M*2; i++){
        int a;
        cin >> a;
        vec.at(i) = a;
    }
    
    vector<int> ans(N);
    
    for (int i = 1; i < N+1; i++){
        int times = 0;
        
        for (int j = 0; j < M*2; j++){
            if (vec.at(j) == i){
                times++;
            }
        }
        
        ans.at(i-1) = times;
    }
    
    for (int i =0; i < N; i++){
        cout << ans.at(i) << endl;
    }
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int N = int.Parse(input[0]);
        int D = int.Parse(input[1]);

        List<List<int>> X = new List<List<int>>();

        for(int i = 0; i < N; i++) {
            string[] strPoint = Console.ReadLine().Split(' ');
            List<int> y = new List<int>();

            foreach(string item in strPoint) {
                y.Add(int.Parse(item));
            }

            X.Add(y);
        }

        int count = 0;

        for(int i = 0; i < N; i++) {

            for(int j = i + 1; j < N; j++) {
                double sum = 0;

                for(int k = 0; k < D; k++) {
                    sum += Math.Pow((double)(X[i][k] - X[j][k]), 2);
                }

                double sqrt = Math.Sqrt(sum);

                if((int)sqrt == sqrt) {
                    count++;
                }

            }

        }

        Console.WriteLine(count);

    }
}

Measured memory_bytes: 13268
#!/usr/bin/env python3
import sys
import numpy as np
from itertools import *


def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    l = [i for i in range(1,M+1)]
    ans = 0
    for v in combinations_with_replacement(l, N):
        score = 0
        for j in range(Q):
            #print(a[j],b[j],c[j],d[j],A[i][b[j]-1]-A[i][a[j]-1], c[j], d[j])
            #print(A[i][b[j]-1]-A[i][a[j]-1], c[j])
            if (v[b[j]-1]-v[a[j]-1])==c[j]:
                score += d[j]
        #print(ans[i])
        ans = max(ans, score)
    #print(ans)
    print(ans)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()


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

const int maxn=300000+10;
long long n,a[maxn],ans=0;

int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=3*n;i++) scanf("%lld",&a[i]);
	sort(a+1,a+1+3*n);
	long long mid=n;
	for(int i=(3*n)-1;i>=mid+1;i-=2) ans+=a[i];
	printf("%lld\n",ans);
}

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

using namespace std;

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

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long llint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double pi = 3.14159265358979323846;

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  string s;
  cin >> s;
  int n = s.size();
  bool ok = true;
  for (int i = 0; i < n / 2; i++) {
    if (s[i] != s[n - i - 1]) ok = false;
  }
  for (int i = 0; i < n; i++) {
    if (i >= (n - 1) / 2 - i - 1) break;
    if (s[i] != s[(n - 1) / 2 - i - 1]) ok = false;
  }

  for (int i = (n + 3) / 2 - 1; i < n; i++) {
    if (i >= (n - 3) / 2 - i - 1) break;
    if (s[i] != s[(n - 3) / 2 - i - 1]) ok = false;
  }

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

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int SX, SY, TX, TY;

void solve() {
    string ans;
    int dx = TX - SX, dy = TY - SY;

    ans += string(dx, 'R');
    ans += string(dy, 'U');
    ans += string(dx, 'L');
    ans += string(dy, 'D');

    ans += 'D';
    ans += string(dx + 1,'R');
    ans += string(dy + 1, 'U');
    ans += 'L';
    
    ans += 'U';
    ans += string(dx + 1, 'L');
    ans += string(dy + 1, 'D');
    ans += 'R';

    cout << ans << endl;
}

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

    while(cin >> SX >> SY >> TX >> TY) {
        solve();
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <queue>
#include <algorithm>

using namespace std;

struct block {
    int size;
    int count;
    
    block(int size, int count) : size(size), count(count) {}
};

int a[200000];
long long right[200001];
long long left[200001];

int main() {
    int n, i;
    long long ans = 1e18;
    deque <block> d;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    
    d.push_back(block(1, 0));
    
    for (i = n - 2; i >= 0; i--) {
        long long x = a[i], y = a[i + 1];
        
        right[i] = right[i + 1];
        
        while (x > y) {
            y *= 4;
            right[i] += d[0].size * 2;
            d[0].count--;
            
            if (d.size() > 1 && d[0].count == 0) {
                d[1].size += d[0].size;
                d.pop_front();
            }
        }
        
        if (x * 4 > y) {
            d[0].size++;
        } else {
            int count = 0;
            
            while (x * 4 <= y) {
                x *= 4;
                count++;
            }
            
            d.push_front(block(1, count));
        }
    }
    
    d.clear();
    d.push_back(block(1, 0));
    
    for (i = 1; i < n; i++) {
        long long x = a[i - 1], y = a[i];
        
        left[i + 1] = left[i];
        
        while (x < y) {
            x *= 4;
            left[i + 1] += d[0].size * 2;
            d[0].count--;
            
            if (d.size() > 1 && d[0].count == 0) {
                d[1].size += d[0].size;
                d.pop_front();
            }
        }
        
        if (y * 4 > x) {
            d[0].size++;
        } else {
            int count = 0;
            
            while (y * 4 <= x) {
                y *= 4;
                count++;
            }
            
            d.push_front(block(1, count));
        }
    }
    
    for (i = 0; i <= n; i++) ans = min(ans, left[i] + right[i] + i);
    
    printf("%lld\n", ans);
    
    return 0;
}


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

int main() {
  int N,A;
  cin >> N >> A;
  
  N = N % 500;
  
  if ( A >= N ) {
     cout << "Yes" << endl;
  }
  
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
r, c = map(int, input().split())

table = []
for _ in range(r):
    table.append(list(map(int, input().split())))

for i in range(r):
    print(' '.join(map(str, table[i])), end='')
    print(' {}'.format(sum(table[i])))

total = 0
for j in range(c):
    column_sum = 0
    column_sum = sum([row[j] for row in table])
    print('{} '.format(column_sum), end='')
    total += column_sum
print(total)

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

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

    sort(a, a + N, greater<int>());
    int Alice = 0, Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) Alice += a[i];
        else Bob += a[i];
    }

    cout << Alice - Bob << endl;

    return 0;
}

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

int main(){
    int n, m, i, j, r, t;
    cin >> n >> m;
    int a[n][2], b[m][2];
    for(i=0; i<n; i++){
        cin >> a[i][0] >> a[i][1];
    }
    for(i=0; i<m; i++){
        cin >> b[i][0] >> b[i][1];
    }
    for(i=0; i<n; i++){
        r = 1000000000;
        t = 0;
        for(j=0; j<m; j++){
            if(r > abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1])){
                r = abs(a[i][0]-b[j][0])+abs(a[i][1]-b[j][1]);
                t = j+1;
            }
        }
        cout << t << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;

class UnionFind {
public:
	vector<int>par, rank, node;
	UnionFind(int n) :par(n), rank(n, 0),node(n,1) {
		for (int i = 0;i < n;i++)par[i] = i;
	}
	void init(int n) {
		for (int i = 0;i < n;i++) {
			par[i] = i;
			rank[i] = 0;
			node[i] = 1;
		}
	}

	int find(int x) {
		return par[x] == x ? x : par[x] = find(par[x]);
	}

	bool same(int x, int y) {
		return find(x) == find(y);
	}

	void unite_tree(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y])rank[x]++;
		}
	}
	int root_size(int x){
		return rank[find(x)];
	}

	int size(int x) {
		return node[find(x)];
	}

	void unite_node(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y)return;
		if (size(x) < size(y))swap(x, y);
		node[x] += node[y];
		par[y] = par[x];
	}
};
int main(void){
    ll n,m;
    cin>>n>>m;
    UnionFind uf = UnionFind(n+1);
    vector<ll>p(n);
    for(ll i=0;i<n;i++)cin>>p[i];
    for(ll i=0;i<m;i++){
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        uf.unite_tree(p[x],p[y]);
    }
    ll ans = 0;
    for(ll i=1;i<=n;i++){
        if(uf.same(i,p[i-1]))ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2176
def f(n, k):
    # dp[ 上からの桁数 ][ N 未満フラグ ][ 0でない数の個数 ] := このパターンの総数
    # dp[i][smaller][j]
    # smaller = 0 のときNに一致
    # smaller = 1 のときN未満
    n = str(n)
    L = len(n)

    dp = [[[0]*(k+2) for i in range(2)] for j in range(L+1)]
    dp[0][0][0] = 1

    for i in range(L):
        D = int(n[i])
        for smaller in range(2):
            for j in range(k+1):
                for d in range((9 if smaller else D)+1):
                    dp[i+1][smaller or (d < D)][j + (d != 0)] += dp[i][smaller][j]

    return dp[L][0][k] + dp[L][1][k]


def main():
    N = int(input())
    K = int(input())

    print(f(N, K))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{
	scanf("%d",&n);
	if(n&1)
	{
		printf("%d\n",(n-1)*(n-1)>>1);
		for(register int i=1;i<n;i++)
			for(register int j=i+1;j<=n;j++)
				if(i+j!=n)
					printf("%d %d\n",i,j);
	}
	else
	{
		printf("%d\n",n*(n-2)>>1);
		for(register int i=1;i<n;i++)
			for(register int j=i+1;j<=n;j++)
				if(i+j!=n+1)
					printf("%d %d\n",i,j);
	}
	return 0;
}

Measured memory_bytes: 256
import sys
import  math
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = input()
ct = 1
l = n[0]
r = n[-1]
print("Yes" if n[:3].count(l) == 3 or n[1:].count(r) == 3 else 'No')

Measured memory_bytes: 5084
import java.util.*;

public class Main{
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int Q = scan.nextInt();

    UF uf = new UF(N);
    
    StringBuilder sb = new StringBuilder();
    for(int i=0;i<Q;i++) {
        int t = scan.nextInt();
        int u = scan.nextInt();
        int v = scan.nextInt();
        if (t == 0) {
            uf.unite(u,v);
        } else {
            int ret = uf.same(u,v) ? 1 : 0;
            sb.append(String.valueOf(ret) + "\n");
        }
    }
    scan.close();

    System.out.print(sb);
}

    private static class UF {
        int []par;
        private UF(int n) {
            par = new int[n];
            for(int i=0;i<n;i++) {  
                par[i] = i;
            }
        }
        public boolean same(int i, int j) {
            int ri = root(i); 
            int rj = root(j); 
            return ri == rj;
        }

        public void unite(int i, int j) {
            int ri = root(i);
            int rj = root(j);
            if (ri == rj) return;
            par[ri] = rj;
        }
        public int root(int x) {
            if (par[x] == x) return x;
            return par[x] = root(par[x]);
        }
    }
}


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

int main(){
    cin >> n;
    pair<string,int> p("a",1);
    vector<pair<string,int>>  a = {p};
    vector<string> A = {"a","b","c","d","e","f","g","h","i","j"};
    
    int s = 0;
    for (int i = 0; i < n; i++)
    {
        if(i == n-1){
            for (int j = 0; j < a.size(); j++)
            {
                string s = a[j].first;
                printf("%s\n", s.c_str());
            }
        }
        else{
            int ss = a.size();
            for (int j = 0; j < ss; j++)
            {
                for (int k = 0; k < a[j].second+1; k++)
                {
                    string str = a[j].first + A[k];
                    if(k == a[j].second) a.push_back(make_pair(str,a[j].second+1));
                    else a.push_back(make_pair(str,a[j].second));
                }
                
            }
            a.erase(a.begin(),a.begin()+ss);
        }
    }
    
}


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

using namespace std;

int rec(vector<string> &s,int c){
    int ret;
    bool op=(s[0][c-1]=='+')?true:false;
    if(op)ret=0;
    else ret=1;
    for (int i = 1; i < s.size(); ++i) {
        if(s[i][c]=='+'||s[i][c]=='*'){
            vector<string> tv;
            tv.emplace_back(s[i]);
            ++i;
            while(i<s.size()&&s[i].size()!=c+1){
                tv.emplace_back(s[i]);
                ++i;
            }
            --i;
            int t=rec(tv,c+1);
            if(op)ret+=t;
            else ret=ret*t;
        }
        else{
            if(op)ret+=s[i][c]-'0';
            else ret=ret*(s[i][c]-'0');
        }
    }
    return ret;
}

int main(){
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<string> s(n);
        for (int i = 0; i < n; ++i) {
            cin>>s[i];
        }
        if(n==1)cout<<s[0][0]-'0'<<endl;
        else cout<<rec(s,1)<<endl;
    }
    return 0;
}


Measured memory_bytes: 3200