akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;


int nRow, nCol;
struct P {
  int x, y;
};
bool operator<(const P& p1, const P& p2) {
  if(p1.y != p2.y) return p1.y < p2.y;
  return p1.x < p2.x;
}

char buf[700];
vector<P> ps;

const int OFFSET = 299;
int hcs[610][610]; // hcs[OFFSET+Y][X]: Y座標Yでの、左からの累積和
int vcs[610][610]; // vcs[X][OFFSET+Y]: X座標Xでの、下からの累積和
bool bs[610][610]; // bs[X][OFFSET+Y]: 点があるか無いか

int main(void) {
  scanf("%d%d", &nRow, &nCol);
  REP(i, nRow) {
    scanf("%s", buf);
    REP(j, nCol) {
      if(buf[j] == '#') {
        P p;
        p.x = j+i;
        p.y = j-i;
        ps.push_back(p);
      }
    }
  }
  //sort(ps.begin(), ps.end());
  REP(i, ps.size()) {
    int x = ps[i].x;
    int y = ps[i].y;
    bs[x][OFFSET+y] = true;
    hcs[OFFSET+y][x+1] = 1;
    vcs[x][OFFSET+y+1] = 1;
    // cerr << "(" << x << ", " << y << ") from [" << (x-y)/2+1 << "][" << (x+y)/2+1 << "]" << endl;
  }
  REP(y, 601) {
    REP(x, 601) {
      hcs[y][x+1] += hcs[y][x];
    }
  }
  REP(x, 601) {
    REP(y, 601) {
      vcs[x][y+1] += vcs[x][y];
    }
  }
  // REP(i, 10) {
  //   REP(j, 10) {
  //     cerr << (bs[i][OFFSET+j-5] ? '#': '.');
  //   }
  //   cerr << endl;
  // }

  // 3点のやつ
  ll res = 0;
  REP(i, ps.size()) {
    int px = ps[i].x;
    int py = ps[i].y;
    REP(x, px) {
      if(bs[x][OFFSET+py]) {
        int d = px-x;
        if(OFFSET+py-d >= 0) {
          if(bs[x][OFFSET+py-d]) ++res;
          if(bs[px][OFFSET+py-d]) ++res;
        }
        if(OFFSET+py+d < 610) {
          if(bs[x][OFFSET+py+d]) ++res;
          if(bs[px][OFFSET+py+d]) ++res;
        }
      }
    }
  }
  // cerr << "> " << res << endl;
  // 2点+辺
  REP(i, ps.size()) {
    int px = ps[i].x;
    int py = ps[i].y;
    REP(x, px) {
      if(bs[x][OFFSET+py]) {
        int d = px-x;
        if(OFFSET+py-d >= 0) {
          res += hcs[OFFSET+py-d][px] - hcs[OFFSET+py-d][x+1];
        }
        if(OFFSET+py+d < 610) {
          res += hcs[OFFSET+py+d][px] - hcs[OFFSET+py+d][x+1];
        }
      }
    }
  }
  
  // cerr << "> " << res << endl;
  REP(i, ps.size()) {
    int px = ps[i].x;
    int py = ps[i].y;
    for(int y = -299; y < py; ++y) {
      if(bs[px][OFFSET+y]) {
        int d = py-y;
        if(px-d >= 0) {
          res += vcs[px-d][OFFSET+py] - vcs[px-d][OFFSET+y+1];
        }
        if(px+d < 610) {
          res += vcs[px+d][OFFSET+py] - vcs[px+d][OFFSET+y+1];
          // cerr << px << " " << y << " " << px << " " << py << endl;
        }
      }
    }
  }


  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  vector<int>ans(N);
  vector<pair<long long,long long>>S(N);
  vector<pair<long long,long long>>C(M);
  for(int i=0;i<N;i++){
    long long a,b;cin>>a>>b;
    S.at(i)=make_pair(a,b);
  }
  for(int j=0;j<M;j++){
    long long a,b;cin>>a>>b;
    C.at(j)=make_pair(a,b);
  }
  for(int i=0;i<N;i++){
    int mark=-1;
    long long min=1000000007;
    for(int j=0;j<M;j++){
      if(abs(S.at(i).first-C.at(j).first)+abs(S.at(i).second-C.at(j).second)<min){
        mark=j;
        min=abs(S.at(i).first-C.at(j).first)+abs(S.at(i).second-C.at(j).second);
      }
    }
    ans.at(i)=mark+1;
  }
  for(int i=0;i<N;i++){
    cout<<ans.at(i)<<endl;
  } 
}

Measured memory_bytes: 256
s = input()
dic_ = str.maketrans({'T':'1','A':'1','C':'1','G':'1'})
s = s.translate(dic_)
count = 0
result = 0
pre_i = ''

for i in s:
  if pre_i == '1' and i == '1':
    count += 1
    
  elif pre_i =='1':
    if count > result:
      result = count
    count = 0
    pre_i = ''
  
  elif i == '1':
    count += 1
    pre_i = '1'
if result < count:
  result = count
print(result)

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

#define LINE_BUF_SIZE 100

int main(){

    int i,j,k;
    int max = 0;
    int count = 0;
    int M,N,v;
    int D,X;
    char line[LINE_BUF_SIZE];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d", &N);

    int A[N+1];

    fgets(line,sizeof(line),stdin);
    sscanf(line,"%d %d", &D,&X);

//    printf("n,d,x=%d %d %d\n",N,D,X);

    for(i=1;i<=N;i++){

        fgets(line,sizeof(line),stdin);
        sscanf(line,"%d", &v);
        //printf("v=%d\n",v);
        A[i] = v;
    }

    int num = 0;
    count = 0;

    for(j=1;j<=N;j++){
        for(i=1;i<=D;i++){
            if(i == count*A[j]+1){
                num += 1;
                count += 1;
            }
            //count = 0;
        //printf("num=%d\n",num);
        }
        count = 0;
    }

    printf("%d",X+num);

    return 0;

}


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


int main() {
	string a,b,c;

	cin >> a ;
	cin >> b;
	cin >>c;

	if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0])
		cout << "YES\n";
	else
		cout << "NO\n";
	  

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	bool ans = true;
	for (int i = n - 1; i >= 1; i--) {
		if (h[i - 1] - h[i] == 1) {
			h[i - 1]--;
		}
		else if (h[i - 1] - h[i] >= 2) {
			ans = false;
		}
	}
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)

template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;

void solve(){
  int n, m; cin >> n >> m;
  priority_queue<ll> a;  
  FOR(i,0,n) {ll b; cin >> b; a.push(b);}
  while(m>0){
    ll tmp = a.top();
    a.pop();
    tmp /= 2;
    --m;
    a.push(tmp);
  }
  ll ans = 0;
  FOR(i,0,n) {ans += a.top(); a.pop();}
  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int main(void)
{
	string S;
	cin >> S;
	int a[3] = {};
	for (char c : S) {
		a[c - 'a']++;
	}
	if (abs(a[0] - a[1]) < 2 && abs(a[1] - a[2]) < 2 && abs(a[2] - a[0]) < 2) {
		cout << "YES\n";
	}
	else {
		cout << "NO\n";
	}
	return 0;
}


Measured memory_bytes: 512
import java.util.HashSet;
import java.util.Scanner;


// 137_b
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        HashSet<Long> hs = new HashSet<>();

        for (int i = 0; i < n; i++) {
            hs.add(sc.nextLong());
        }

        String ans = hs.size() == n ? "YES" : "NO";

        out(ans);

    }

    /*
     * 以下メソッド集
     */

    static long gcd(long a, long b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static int gcd(int a, int b) {

        return (b == 0) ? a : gcd(b, a % b);
    }

    static void out(String info) {

        System.out.println(info);
    }

    static void out(int info) {

        System.out.println(info);
    }

    static void out(double info) {

        System.out.println(info);
    }

    static void out(long info) {

        System.out.println(info);
    }

}


Measured memory_bytes: 101960
N, M = map(int, input().split())
A = list(map(int, input().split()))
num = []
for a in A:
  num += [[a,1]]
for i in range(M):
  b, c = map(int, input().split())
  num += [[c,b]]
  
num.sort(reverse = 1)
ans = 0
use = 0

for pair in num:
  #上限達成する場合
  if use + pair[1] >= N:
    ans += (N - use)* pair[0]
    use = N
    break
  else:#達成しない
    use += pair[1]
    ans += pair[1] * pair[0]
    
print(ans)

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m;
	cin >> n >> m;
	vector<int>day[100010];
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		day[a].push_back(b);
	}
	int ans = 0;
	priority_queue<int>pq;
	for (int i = 1; i <= m; i++) {
		for (auto it : day[i]) {
			pq.push(it);
		}
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 5632
S = input()
if len(S) % 2 == 1:
	print("No")
	exit()
for i in range(len(S)):
	if i % 2 == 1:
		if S[i] != 'i':
			print("No")
			exit()
	if i % 2 == 0:
		if S[i] != 'h':
			print("No")
			exit()
print("Yes")

Measured memory_bytes: 3060
#pragma G++ optimize(2)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
using namespace std;
#define REG register
#define REP(i,x,y) for(REG int i=x;i<=y;i++)
#define UP(i,x,y) for(REG int i=x;i>=y;i--)
#define IN inline
#define ll long long 
#define inf 0x3f3f3f3f

const int maxn=200010;
int f[maxn],pos[maxn][30],n;
char s[maxn];
int main(){
    scanf("%s",s);
    n=strlen(s);
    for(int i=0;i<26;i++)pos[n][i]=n;
    f[n]=1;f[n+1]=0;//即使没有后缀仍然需要长度为1，f[n]=1；如果没有相同字符的话就f[n+1]+1，所以f[n+1]=0。 
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<26;j++)pos[i][j]=pos[i+1][j];
        pos[i][s[i]-'a']=i;
        f[i]=n+1;
        for(int j=0;j<26;j++)f[i]=min(f[i],f[pos[i][j]+1]+1);
    }
    int T=f[0],p=0;
    while(T--){
        for(int j=0;j<26;j++)if(f[pos[p][j]+1]+1==f[p]){
            putchar('a'+j);
            p=pos[p][j]+1;
            break;
        }
    }
    return 0;
}

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

using namespace std;



int main(){


	int n; cin >> n;

	vector <int> b(n, 1e5), a(n, 1e9);


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

	for(int i = 0; i < n - 1; i++){
		a[i] = min(a[i], b[i]);
		a[i + 1] = min(a[i + 1], b[i]);
	}


	int ans = 0;

	for(int i = 0; i < n; i++){
		ans = max(ans, a[i]);
	}


	cout << accumulate(a.begin(), a.end(), 0) << endl;






	return 0;
}

Measured memory_bytes: 256
N=int(input())
sp = []
for i in range(N):
  s,p=input().split()
  p=int(p)
  sp.append((i+1,s,p))

sp = sorted(sp,key=lambda x:x[2],reverse=True)
sp = sorted(sp,key=lambda x:x[1])

for i in range(N):
  print(sp[i][0])

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

int main() {
	long long N, A, B;
	cin >> N >> A >> B;
	if (N == 1 && A != B)	cout << 0;
	else if (A > B) 	cout << 0;
	else {
		cout << (B - A) *(N - 2) + 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    long long r,g,h;
    r=1ll*a*b;
    g=a+b;
    h=a-b;
    cout<<max(r,max(g,h))<<endl;
}


Measured memory_bytes: 256
import copy

def gen_mono_inc_seqs(N, M, cur_list, cur_len):
    if cur_len == N:
        return cur_list

    result = []
    for l in cur_list:
        last_val = l[len(l)-1]
        for i in range(last_val, M+1):
            tmp = copy.copy(l)
            tmp.append(i)
            result.append(tmp)

    return gen_mono_inc_seqs(N, M, result, cur_len+1)


def mono_inc_seqs(N, M):
    l = [ [i] for i in range(1, M+1) ]
    return gen_mono_inc_seqs(N, M, l, 1)

N, M, Q = map(int, input().split())

a, b, c, d = [0] * Q, [0] * Q, [0] * Q, [0] * Q
for i in range(Q):
    a_, b_, c_, d_ = map(int, input().split())
    a[i], b[i], c[i], d[i] = a_, b_, c_, d_

max_result = -1
seqs = mono_inc_seqs(N, M)
for seq in seqs:
    tmp = 0
    for i in range(Q):
        if seq[b[i]-1] - seq[a[i]-1] == c[i]:
            tmp += d[i]
    max_result = max(max_result, tmp)

print(max_result)





Measured memory_bytes: 110072
#include <bits/stdc++.h>
#define ll long long int
#define fr(i, a, b) for (ll i = a; i < b; i++)
#define pb(v, a) v.push_back(a)
#define Sort(v) sort(v.begin(), v.end())
#define For(m) for (auto it = m.begin(); it != m.end(); it++)
#define mod 1000000007
using namespace std;



int main()
{
  
 ll n;
 cin >> n;
 ll a[n];
 ll b[n];
 ll sum2=0;
 fr(i,0,n)
 cin>>a[i],sum2+=a[i];
 ll sum1=0;
 fr(i,0,n)
 cin >>b[i],sum1+=b[i];
 if(sum1>sum2)
 {
     cout << -1;
     return 0;
 }
 ll c[n];
 ll tot=0;
 ll sum3=0;
 fr(i,0,n)
 {
     if(a[i]>=b[i])
     {
         c[i]=a[i];
     }
     else
     {
         tot++;
         c[i]=b[i];
         
     }
     sum3+=c[i];
 }
  ll arr[n];
  fr(i,0,n)
  {
      arr[i]=(a[i]-b[i]);
  }
  sort(arr,arr+n,greater<int>());
  ll in=0;
  while(sum3!=sum2)
  {
      sum3-=arr[in];
      in++;
      if(sum3<=sum2)break;
  }
  cout << tot+in;


  return 0;
}


Measured memory_bytes: 3328
S = input()
s = list(S)
p = -1
q = -1
a = [s[0],s[1]]
b = [s[2],s[3]]
if 1 <= int(''.join(a)) <= 12:
    p = 1
else:
    p = 0
if 1 <= int(''.join(b)) <= 12:
    q = 1
else:
    q = 0
if p == 1 and q == 1:
    print('AMBIGUOUS')
elif p == 0 and q == 1:
    print('YYMM')
elif p == 1 and q == 0:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 38384
N,M=map(x->parse(Int,x),split(readline()))
X=sort(map(x->parse(Int,x),split(readline())))
L=Array{Int}(0)
for i=2:M
	push!(L,X[i]-X[i-1])
end
sort!(L)
ans=X[end]-X[1]
for i=1:N-1
	if i<=length(L)
		ans-=L[end-i+1]
	end
end
println(ans)


Measured memory_bytes: 146816
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
int main(){
    cin.tie(0);
    cout.sync_with_stdio(false);
    long long N;
    cin >> N;
    if(N%2) {
        cout << 0 << endl;
        return 0;
    }
    ll res = 0;
    ll d = 10;
    while(N >= d){
        res += N / d;
        d *= 5;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
Np1 = N+1
ans = 0
for b in range(1, Np1):
    r = b - K
    if r <= 0:
        continue
    for a in range(max(1,K), Np1, b):
        ans += min(a+r, Np1) - a
print(ans)

Measured memory_bytes: 73560
n=int(input())
childs=[0]*n

for i in range(n):
    node=list(map(int,input().split()))
    childs[node[0]] = node[1:]

class BisectTree:
    def __init__(self,childs):
        self.n=len(childs) 
        self.left_child=[0]*self.n
        self.right_child=[0]*self.n
        self.parent=[-1]*self.n
        for i in range(self.n):
            self.left_child[i]=childs[i][0]
            self.right_child[i]=childs[i][1]
            if childs[i][0] != -1:
                self.parent[childs[i][0]]=i
            if childs[i][1] != -1:
                self.parent[childs[i][1]]=i
        self.root=self.parent.index(-1)

tree=BisectTree(childs)

def preorder(tree,node,ans):
    ans.append(node)
    left=tree.left_child[node]
    right=tree.right_child[node]
    if left != -1:
        preorder(tree,left,ans)
    if right != -1:
        preorder(tree,right,ans)

def inorder(tree,node,ans):
    left=tree.left_child[node]
    right=tree.right_child[node]
    if left != -1:
        inorder(tree,left,ans)
    ans.append(node)
    if right != -1:
        inorder(tree,right,ans)

def postorder(tree,node,ans):
    left=tree.left_child[node]
    right=tree.right_child[node]
    if left != -1:
        postorder(tree,left,ans)
    if right != -1:
        postorder(tree,right,ans)
    ans.append(node)
    

preorder_ans=[]
preorder(tree,tree.root,preorder_ans)
print("Preorder\n ",end="")
print(*preorder_ans)

inorder_ans=[]
inorder(tree,tree.root,inorder_ans)
print("Inorder\n ",end="")
print(*inorder_ans)

postorder_ans=[]
postorder(tree,tree.root,postorder_ans)
print("Postorder\n ",end="")
print(*postorder_ans)





Measured memory_bytes: 5624
import sys
input = sys.stdin.readline

N = int(input())
H = list(map(int, input().split()))
ans = 0
l = 0
for i in range(1, N):
    if H[i-1] >= H[i]:
        l += 1
    else:
        ans = max(ans, l)
        l = 0
ans = max(ans, l)
print(ans)

Measured memory_bytes: 84768
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;
constexpr ll  MOD = (1e9+7);
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int lcm(int a, int b) { return a / gcd(a, b) * b; }

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
ll factorial(ll n, ll m=2) {
    // calculate n!
    m = max(2LL, m);
    ll rtn = 1;
    for (ll i=m; i<=n; i++) {
        rtn = (rtn * i) % MOD;
    }
    return rtn;
}
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll modpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n, m; cin >> n >> m;
    vector<vector<ll>> stu(n, vector<ll>(2)), che(m, vector<ll>(2));
    rep(i, n) cin >> stu[i][0] >> stu[i][1];
    rep(i, m) cin >> che[i][0] >> che[i][1];
    rep(i, n) {
        ll dist = INF;
        ll ans = -1;
        rep(j, m) {
            ll tmp = abs(stu[i][0] - che[j][0]) + abs(stu[i][1] - che[j][1]);
            if (dist > tmp)
                ans = j+1;
            chmin(dist, tmp);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
def f(n):
    l, r = 0, 1 << 20
    while r - l > 1:
        m = (l + r) // 2
        if m ** 5 <= n:
            l = m
        else:
            r = m
    return l if l ** 5 == n else 0

X = int(input())
for i in range(1 << 20):
    a = f(X + i ** 5)
    if a:
        print(a, i)
        break
    a = f(X - i ** 5)
    if a:
        print(a, -i)
        break


Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(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--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int x[n], tmp[n];

	rep(i, 0, n) {
		cin >> x[i];
		tmp[i] = x[i];
	}

	sort(x, x + n);

	rep(i, 0, n) {
		int med = x[(n + 1) / 2];
		int med_1 = x[(n + 1) / 2 - 1];
		if(tmp[i] >= med) {
			cout << med_1 << endl;
		} else {
			cout << med << endl;
		}
	}
}


Measured memory_bytes: 3712
import numpy as np
import math as m

def main(**kwargs):
    q = n // (a + b) 
    r = n % (a + b)

    if r < a:
        res = q * a + r

    else:
        res = q * a + a
        
    return res

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, a, b, *_ = cin

    cout = main(n=n, a=a, b=b)
    print(cout)

Measured memory_bytes: 21788
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<string>
//#include<queue>
//#include<cmath>
//#include<algorithm>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<ll,ll>
typedef long long ll;
const int maxn=3e4+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=max(n,m);i++)printf("%d",min(n,m));
	puts("");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace __gnu_cxx;
#define dprint(v) cout << #v"=" << v << endl //;)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define forall(it,v) for(auto it=v.begin();it!=v.end();++it)
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define INF (ll)1e16
#define endl '\n'
#define isin(x,y) ((y).find(x)!=(y).end())
#define forr(i,a,b) for(int i=(a); i<(b); i++)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

typedef pair<int,int> ii;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
        cin>>s;
        ll n=sz(s);
        string a(sz(s),'0');
        for(ll i=1;i<n;i+=2)a[i]='1';
        string b(sz(s),'1');
        for(ll i=1;i<n;i+=2)b[i]='0';
        ll ans1=0,ans2=0;
        forn(i,n)if(s[i]!=a[i])++ans1;
        forn(i,n)if(s[i]!=b[i])++ans2;
        cout<<min(ans1,ans2)<<endl;
	return 0;
}


Measured memory_bytes: 592
#selection_sort
n = int(input())
a = list(map(int, input().split()))
cnt = 0
for i in range(n):
    minj = i
    for j in range(i, n):
        if a[j] < a[minj]:
            minj = j
    if i != minj:
        a[i], a[minj] = a[minj], a[i]
        cnt += 1
    
    
print(*a)
print(cnt)


Measured memory_bytes: 5600
def get_input():
    N,K = map(int,input().split())
    A = map(int,input().split())
    return N,K,A

def solve(N,K,A):
    sum_per_digit_list = sum_digit(A)
    K_b = to_2digit(K+1)
    cand = []
    for i in range(40):
        if K_b[i] ==1:
            cand.append(calc_opt(i,K_b,sum_per_digit_list,N))
    return max(cand)

def calc_opt(i,K_b,sum_per_digit_list,N):
    opt = 0
    for j in range(40):
        if j < i :
            opt+= max(N-sum_per_digit_list[j], sum_per_digit_list[j]) * 2**j
        elif j==i:
            opt+= sum_per_digit_list[j] * 2**j

        else:
            if K_b[j] == 1:
                opt+= (N - sum_per_digit_list[j]) * 2**j
            else:
                opt+= sum_per_digit_list[j] * 2**j
    return opt



def sum_digit(A):
    sum_per_digit_list = []
    numbers = list(A)
    for i in range(40):
        sum_per_digit_list.append(sum([number %2 for number in numbers]))
        numbers = [number //2 for number in numbers]
    return sum_per_digit_list
    
def to_2digit(number):
    digits = []
    for i in range(40):
        digits.append(number %2)
        number = number //2 
    return digits


if __name__ == "__main__":
    N,K,A = get_input()
    print(solve(N,K,A))

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

using namespace std;

// MACROS

#define ll long long
#define ull unsigned long long
#define ld long double

#define vi vector<int>
#define vll vector<ll>
#define vld vector<ld>
#define u_s unordered_set

#define pii pair<int,int>
#define pll pair<ll,ll>

#define FOR(i, n) for (ll (i) = 0; i < n; i++)
#define FORN(i, a, b) for (ll (i) = a; i < b; i++)
#define FORE(i, l) for (auto (i) : l)

#define pb push_back
#define pob pop_back
#define emp emplace

#define in(n) cin >> (n);
#define debug(n) cout << #n << ": " << n << '\n';

// FUNCTIONS

template< typename T >
inline T gcd(T a, T b) { if (b) return gcd(b, a % b); return a; }

template< typename T >
inline T ext_gcd(T a, T b, T & x, T & y) { if (a == 0) { x = 0; y = 1; return b; } T x1, y1; T g = ext_gcd(b % a, a, x1, y1); x = y1 - (b / a) * x1; y = x1; return g; }

double dis(pll f, pll s)
{
    return sqrt(pow(s.first - f.first, 2) + pow(s.second - f.second, 2));
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    ll n;        
    cin >> n;
    vll nums(n);
    FOR(i, n) nums[i] = i + 1;
    vector<pll> coords;
    FOR(i, n)
    {
        ll x, y;
        cin >> x >> y;
        coords.pb(make_pair(x, y));
    }
    ld sum = 0;
    ll fact = 1;
    FOR(i, n) fact *= (i + 1);
    do
    {
        FOR(i, n - 1)
        {
            sum += dis(coords[nums[i] - 1], coords[nums[i + 1] - 1]);
        }
    } while (next_permutation(nums.begin(), nums.end()));
    cout << setprecision(15) << sum / fact << '\n';
}



Measured memory_bytes: 256
#!python3

from time import perf_counter
tick = perf_counter() + 1.92

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect

def resolve():
    G = 26
    it = map(int, sys.stdin.read().split())
    D = next(it)
    C = [next(it) for i in range(G)]
    S = [[next(it) for i in range(G)] for i in range(D)]
    L = [[-1] for i in range(G)]
    T = [0] * D

    def update(di, qi):

        score = 0
        t0 = T[di]
        score += S[di][qi]-S[di][t0]

        a1 = li = L[t0][:]
        ii = li.index(di)
        la = D if len(li)-1 == ii else li[ii+1]
        score -= C[t0] * (di-li[ii-1])*(la-di)
        li.pop(ii)

        a2 = li = L[qi][:]
        ii = bisect(li, di)
        li.insert(ii, di)
        la = D if len(li)-1 == ii else li[ii+1]
        score += C[qi] * (di-li[ii-1])*(la-di)

        return score, (a1, a2)

    U = 10
    def calc(i, j):
        score = S[i][j]
        for k in range(G):
            u = k - L[k][-1]
            score -= C[k] * (u + u + U) * U // 2
        score += C[k] * U * (i-L[j][-1])
        return score

    for di in range(D):
        i, score = 0, calc(di, 0)
        for qi in range(1, G):
            x = calc(di, qi)
            if x > score:
                i, score = qi, x
        T[di] = i
        L[i].append(di)

    while perf_counter() < tick:
        di, qi = randrange(0, D), randrange(0, G)
        diff, swap = update(di, qi)
        if diff > 0:
            score += diff
            q0, T[di] = T[di], qi
            L[q0], L[qi] = swap

    print(*(i+1 for i in T), sep="\n")

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 91220
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
vector<int> doit (const string& s) {
  int n = (int) s.size();
  vector<int> res(n + 1);
  for (int i = 0; i < n; i++) {
    res[i + 1] = res[i] + s[i] - 'A' + 1;
  }
  return res;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  auto ss = doit(s);
  auto ts = doit(t);
  int q;
  cin >> q;
  while (q--) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if ((ss[b] - ss[a - 1]) % 3 == (ts[d] - ts[c - 1]) % 3) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
  return 0;
}

Measured memory_bytes: 1744
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
using namespace std;

int min(int a, int b) {
    if (a < b) return a;
    else return b;
}

double calc(int r, int n) {
    const int hsize = r * 2 + 1;
    const int psize = hsize - 2;
    vector<int> heights(hsize, 0);
    vector<int> points(psize, -1);
    
    for (int i = 0; i < n; i++) {
        int xl, xr, h;
        cin >> xl >> xr >> h;
        for (int j = xl; j < xr; j++) {
            if (j < -r || r < j) continue;
            if (heights[r + j] < h) heights[r + j] = h;
        }
    }

    for (int i = 0; i < psize; i++) {
        points[i] = min(heights[i], heights[i + 1]);
    }

    double min = 100.0;
    double rad = (double)r;
    for (int i = 0; i < psize; i++) {
        double x = (double)(i - r + 1);
        double y = sqrt(rad * rad - x * x);
        double m = (double)(points[i]) - y + rad;
        if (min > m) min = m;
    }
    return ((double)((int)(min * 10000.0))) / 10000.0;
}

int main() {
    int r, n;
    while (true) {
        cin >> r >> n;
        if (r == 0 && n == 0) return 0;
        cout << fixed << setprecision(4) << calc(r, n) << endl;
    }
}


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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    string s;
    std::cin >> s;
    int n=s.size();
    std::vector<int> a(3,0);
    rep(i,n){
        a[s[i]-'a']++;
    }
    sort(all(a));
    if(a[2]-a[0]<=1)std::cout << YES << std::endl;
    else std::cout << NO << std::endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,X[111];
ll i, j, k;
int main(){
    scanf("%lld", &N);
    
    fornum(i,0,N){
        scanf("%lld", &X[i]);
    }
    j = 1e18;
    fornum(i,0,101){
        ll a = 0;
        fornum(k,0,N){
            ll b = (X[k] - i);
            a += b * b;
        }
        j = min(a, j);
    }
    printf("%lld", j);
    return 0;
}

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

class UnionFind{
    public:
    //親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> par;
 
	//作るときはparの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N){
		par = vector<int>(N, -1);
	}
 
	//Aがどのグループに属しているか調べる
	int find(int A){
		if(par[A] < 0) return A;
		return par[A] = find(par[A]);
	}
 
	//自分のいるグループの頂点数を調べる
	int size(int A){
		return -par[find(A)];//親をとってきたい
	}
 
	//AとBをくっ付ける
	bool unite(int A, int B){
		//AとBを直接つなぐのではなく、find(A)にfind(B)をくっつける
		A = find(A);
		B = find(B);
		if(A == B){
			//すでにくっついてるからくっ付けない
			return false;
		}
 
		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう
		if(size(A) < size(B)) swap(A, B);
 
		//Aのサイズを更新する
		par[A] += par[B];
		//Bの親をAに変更する
		par[B] = A;
 
		return true;
	}

    bool is_same(int A, int B){
        return find(A) == find(B);
    }
};

int main(){
    int n,m; cin >> n >> m;
    vector<int> a(m),b(m);
    rep(i,m){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }
    vector<ll> ans(m);
    ans[m-1] = (ll)n * (n-1) / 2;

    UnionFind uni(n);
    for(int i = m-1; i >= 1; i--){
        ans[i-1] = ans[i];
        if(!uni.is_same(a[i],b[i])){
            ans[i-1] -= (ll)uni.size(a[i])*uni.size(b[i]);
            uni.unite(a[i],b[i]);
        }
    }
    rep(i,m) cout << ans[i] << endl;
}



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

int main(){
  ll n;
  cin >> n;
  ll money = 1000;
  ll s;//start
  cin >> s;
  ll k = 0;//kabu
  rep(i,n){
    if (i < n-1){
      ll a;
      cin >> a;
      if(s <= a){
        k += money/s;
        money %= s;
      }else{
        money += k*s;
        k = 0;
      }
      s = a;
    }
    if (i == n-1){
      money += k*s;
      k = 0;
    }
  }
  cout << money << endl;
}

Measured memory_bytes: 3584
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String count = br.readLine();
            System.out.println("ABC" + count);
        } catch (IOException e) {
            e.printStackTrace();
           }
    }
}

Measured memory_bytes: 22612
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


# 処理内容
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()

    dp = [True] * (max(A) + 1)
    tmp = 0
    for a in A:
        if a == tmp:
            dp[a] = False
            continue
        tmp = a
        i = 2
        while a*i < len(dp):
            dp[a*i] = False
            i += 1
    
    ans = 0
    for a in A:
        if dp[a] == True:
            ans += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 101400
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;
 
//vector<ll> G[550010];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}

 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k;
ll ans;
ll x[500005], y[500005], z[200005];
char s[500005], t[500005];
string table[100];
bool used[500005];
 
int main(){
    
    c3_init();
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> n;
    for(ll i=0;i<n;i++){
        cin >> x[i];
    }
    for(ll i=0;i<n-1;i++){
        y[i] = x[i+1] - x[i];
        y[i] %= mod;
    }
    n --;
    ll all = fact[n];
    all %= mod;
    for(ll i=0;i<n;i++){
        ans += y[i] * all;
        ans %= mod;
        ll tmp = fact[n] * rui((i + 2), mod - 2);
        tmp %= mod;
        all += tmp;
        all %= mod;
    }
    p(ans);

    return 0;
}













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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a, b;
    cin >> a >> b;

    if (a < b)
    {
        cout << "a < b" << endl;
    }
    else if (a > b)
    {
        cout << "a > b" << endl;
    }
    else
    {
        cout << "a == b" << endl;
    }

    return 0;
}



Measured memory_bytes: 3164
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

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

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n, Y; cin >> n >> Y;
  for(ll x = 0;x <= n;x++)
  {
    for(ll y = 0;y <= n;y++)
    {
      if(x * 10000 + y * 5000 + (n - x - y) * 1000 == Y&&(n - x - y) >= 0)
      {
        cout << x << " " << y << " " << n - x - y << endl;
        exit(0);
      }
    }
  }
  cout << "-1 -1 -1\n";
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

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

int main() {
  int N, K;
  cin >> N >> K;
  if (N == 0) {
    cout << 1 << endl;
    return 0;
  }
  int i = 0;
  int j = 1;
  while(j <= N) {
    i++;
    j *= K;
  }
  cout << i << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
inline int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')c=getchar(),k=-1;
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return kk*k;
}using namespace std;
void write(int x){if (x<0)putchar('-'),x=-x;if (x/10)write(x/10);putchar(x%10+'0');}
void writeln(int x){write(x);puts("");}
int n,a[1000010],ans;
signed main(){
	n=read();for (int i=1;i<=n;i++){
		a[i]=read();if (a[i]==a[i-1])a[i]=0,ans++;
	}writeln(ans);
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
    string s;
    cin >> s;
    int c, f;
    f = -1; c = 1000;
    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'C') {
            if (c == 1000) c = i;
        }
        else if (s[i] == 'F') {
            f = i;
        }
    }
    if (c < f) {
        puts("Yes");
    }
    else {
        puts("No");
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(a) int((a).size())
#define pb push_back
#define allc c.begin(),c.end()
#define tr(c,i) for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) (c.find(x) != c.end())
#define cpresent(c,x) (find(allc,x) != c.end())
#define ll long long
using namespace std;

int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	if((s[2]==s[3])&&(s[4]==s[5]))
        cout<<"Yes";
    else
        cout<<"No";
}


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

int gcd(int a, int b) {
	if (b == 0) return a;
	else return gcd(b, a%b);
}

int calc(int N,int K) {
	vector<int> x;
	for (int i = 1; i <= sqrt(N); i++) {
		if (0 == N % i) {
			x.push_back(i);
			if (N != i * i) {
				x.push_back(N / i);
			}
		}
	}
	sort(x.begin(),x.end());
	return x[x.size()-K];
}


int main() {
	int A, B, K;
	cin >> A >> B >> K;
	int g = gcd(A, B);
	int ans = calc(g, K);
	cout << ans << endl;

}

Measured memory_bytes: 3736
$n, $k = readlines.map(&:to_i)
def dnf(operations, results)
  if operations.size == $n
    point = 1
    operations.each do |operation|
      point *= 2 if operation == 'A'
      point += $k if operation == 'B'
    end
    results << point
    return
  end

  dnf(operations + ['A'], results)
  dnf(operations + ['B'], results)

  if operations.empty?
    return results.min
  end
end
puts dnf([], [])


Measured memory_bytes: 1916
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi p(n);
  rep(i,n){
    cin >> p[i];
  }
  ll ans = 0;
  int cnt = 0;
  rep(i,n){
    int id = i+1;
    if(p[i] == id){
      if(cnt){
        cnt=0;
      }else{
        ans++;
        cnt = 1;
      }
    }else{
      cnt=0;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

vector<ll> ps;
vector<ll> as;

ll f(ll n, ll x) {
  if(n == 0) {
    return x <= 0 ? 0 : 1;
  } else if(x <= 1 + as[n - 1]) {
    return f(n - 1, x - 1);
  } else {
    return ps[n - 1] + 1 + f(n - 1, x - 2 - as[n - 1]);
  }
}

int main() {
  ll N, X;
  cin >> N >> X;
  ps = vector<ll>(N + 1); // パティの枚数の配列
  ps[0] = 1;
  as = vector<ll>(N + 1); // 枚数の配列
  as[0] = 1;
  for(ll i = 1; i <= N; ++i) {
    ps[i] = 2 * ps[i - 1] + 1;
    as[i] = 2 * as[i - 1] + 3;
  }
  cout << f(N, X) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int n, a;
int x[55];

int y[55];
int X;
ll dp[55][2555*2] = {0};

int main () {
  cin >> n >> a;
  rep(i,n) cin >> x[i];

  X = max(*max_element(x,x+n),a);
  rep(i,n) y[i] = x[i] - a;

  dp[0][n*X] = 1;
  rep(j,55) {
    rep(s,2555*2) {
      if (j >= 1 && !(0<=s-y[j-1] && s-y[j-1]<=2*n*X)) {
        dp[j][s] = dp[j-1][s];
      }
      if (j >= 1 && (0<=s-y[j-1] && s-y[j-1]<=2*n*X)) {
        dp[j][s] = dp[j-1][s] + dp[j-1][s-y[j-1]];
      }
    }
  }

  cout << dp[n][n*X]-1 << endl;
}

Measured memory_bytes: 2432
#include <iostream>

#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::min;

static int
solve(int A, int B, int C, int X, int Y)
{
  if (A + B <= C * 2)
  {
    return A * X + B * Y;
  }
  int xy = min(X, Y);
  return min(C * 2, A) * (X - xy) + min(C * 2, B) * (Y - xy) + C * xy * 2;
}

int
main()
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  cout << solve(A, B, C, X, Y) << endl;
  return 0;
}


Measured memory_bytes: 256