akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=200005,INF=1<<30;

template<typename T>
struct SegmentTree{
    using F=function<T(T,T)>;
    
    int n;
    vector<T> dat;
    F f;
    T ti;
    
    SegmentTree(int n_ ,F f ,T ti) :f(f),ti(ti){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
    }
    
    SegmentTree(int n_ ,vector<T> &v ,F f,T ti) :f(f),ti(ti){
        n=1;
        while(n<n_) n*=2;
        dat.assign(2*n-1,ti);
        
        for(int i=n-1;i-(n-1)<v.size();i++) dat[i]=v[i-(n-1)];
        
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
    }
    
    void update(int k,T x){
        k+=n-1;
        dat[k]=x;
        
        while(k){
            k=(k-1)/2;
            dat[k]=f(dat[k*2+1],dat[k*2+2]);
        }
    }
    
    void set(int k,T x){
        dat[n-1+k]=x;
    }
    
    void built(){
        for(int i=n-2;i>=0;i--) dat[i]=f(dat[i*2+1],dat[i*2+2]);
    }
    
    T query_(int a,int b,int k,int l,int r){
        if(r<=a||b<=l) return ti;
        if(a<=l&&r<=b) return dat[k];
        else{
            T vl=query_(a,b,2*k+1,l,(l+r)/2);
            T vr=query_(a,b,2*k+2,(l+r)/2,r);
            return f(vl,vr);
        }
    }
    
    T query(int a,int b){
        return query_(a,b,0,0,n);
    }
    
    T get(int k){
        return dat[k+n-1];
    }
    
};

int to[MAX];
ll dp[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<int,int>> S(N);
    for(int i=0;i<N;i++){
        int a,b;cin>>a>>b;
        S[i]={a,a+b};
    }
    sort(all(S));
    
    SegmentTree<int> seg(N,
                         [](int a,int b){return max(a,b);},
                         0);
    
    to[N-1]=N-1;
    seg.update(N-1,N-1);
    
    for(int i=N-2;i>=0;i--){
        auto it=lower_bound(all(S),make_pair(S[i].second,-INF));
        it--;
        int d=it-S.begin();
        
        to[i]=max(i,seg.query(0,d+1));
        seg.update(i,to[i]);
    }
    
    dp[0]=1;
    
    for(int i=0;i<N;i++){
        dp[i+1]+=dp[i];
        dp[to[i]+1]+=dp[i];
        
        dp[i+1]%=mod;
        dp[to[i]+1]%=mod;
    }
    
    cout<<dp[N]<<endl;
}



Measured memory_bytes: 6272
import sys
import itertools
input = sys.stdin.readline

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

S = [list(map(int, input().split())) for i in range(Q)]

ans = 0

for v in itertools.combinations(range(N+M-1), N):
    l = []
    for i in range(N):
        l.append(v[i]-i+1)

    total = 0
    for i in range(Q):
        if l[S[i][1]-1] - l[S[i][0]-1] == S[i][2]:
            total += S[i][3]
    
    ans = max(ans, total)

print(ans)

Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
long long a[105], n, ans=756675478584LL, sol; 
int main (){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n;
for (int i=0; i<n; i++) cin >> a[i];
sort(a, a+n);
for (int i=0; i<=100; i++){
	sol=0;
	for (int j=0; j<n; j++){
		sol+=(a[j]-i)*(a[j]-i);
	}
	ans=min(ans, sol);
}
cout << ans;
return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int min = Integer.MAX_VALUE;
        int count = 0;
        for (int i = 0; i < n; i++) {
            int x = sc.nextInt();
            if (min >= x) {
                count++;
                min = x;
            } 
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 65388
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define MAX 105
#define int long long int
using namespace std;



int32_t main()
{
    string x,y;
    cin >> x >> y;
    int n = x.size();
    int m = y.size();
    
    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    
    for(int i = 1 ; i <= n ; i++)
    {
        for(int j = 1 ; j <= m ; j++)
        {
            if(x[i-1] == y[j-1])
                dp[i][j] = 1+dp[i-1][j-1];
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string ans;
    int i = n,j=m;
    while(i > 0 and j > 0)
    {
        if(x[i-1] == y[j-1])
        {
            ans.pb(x[i-1]);
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j] > dp[i][j-1])
                i--;
            else j--;
        }
    }
    reverse(ALL(ans));
    cout << ans;
    
    return 0;
}


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

int main() {
  int i;
  bool flag=false;
  string s;
  cin >> s;
  for(i=0;i<2;i++){
    if(s[i]!=s[i+1]) break;
    else if(i==1){
    flag = true;
    }
  }
  if(!flag){
      for(i=1;i<3;i++){
   		if(s[i]!=s[i+1]) break;
  		else if(i==2){
    		flag = true;
    	}
  	}
  }
  cout << (flag ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int W,H,x,y;
    cin >> W >> H >> x >> y;
    double S=(double)W*(double)H/2.0;
    cout << S << endl;
    if(W/2.0==x & H/2.0==y) cout << 1 << endl;
    else cout << 0 << endl;
    return 0;
}


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

int main() {

  long long N;
  cin >> N;

  vector<long long> A(100010);
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    A[a]++;
    sum += a;
  }

  long long Q;
  cin >> Q;

  vector<long long> B(Q);
  vector<long long> C(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }

  for (int i = 0; i < Q; i++) {
    sum -= B[i] * A[B[i]];
    sum -= C[i] * A[C[i]];
    A[C[i]] += A[B[i]];
    A[B[i]] = 0;
    sum += C[i] * A[C[i]];
    cout << sum << endl;
  }

  return 0;

}

Measured memory_bytes: 5624
#coding:utf-8
n=[int(i) for i in input().split()]
Ad=0
Au=0
A=[int(i) for i in input().split()]
for i in range(n[1]):
  if(A[i]>n[2]):
    Au+=1
  else:
    Ad+=1
if(Au>=Ad):
  print(Ad)
else:
  print(Au)
  

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    int n; cin >> n;
    for(int i = 0; i < n; i++){
        int x,y,b,p; cin >> x >> y >> b >> p;
        int s = x * b + y * p;
        if(b >= 5 && p >= 2){
            int sum = (x * b + y * p) * 8 / 10;
            cout << sum << endl;
        }else if(b >= 5 && p < 2){
            int t = (x * b + y * 2) * 8 / 10;
            cout << min(s,t) << endl;
        }else if(b < 5 && p >= 2){
            int t = (x * 5 + y * p) * 8 / 10;
            cout << min(s,t) << endl;
        }else{
            int t = (x * 5 + y * 2) * 8 / 10;
            cout << min(s,t) << endl;
        }
    }
}


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

n, q = map(int, input().split())
s = input()
ac_list = [0]

for i in range(1, n):
  if s[i-1:i+1] == 'AC':
    ac_list.append(ac_list[i-1]+1)
  else:
    ac_list.append(ac_list[i-1])

for _ in range(q):
  first, last = map(int, input().split())
  print(ac_list[last-1] - ac_list[first-1])

Measured memory_bytes: 6340
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(void){

  int A, B, C, D;  cin >> A >> B >> C >> D;
  int keep = min(B , D) - max(A, C);
  int ans = (0 < keep)? keep : 0;
  cout << ans << endl;;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

char s[7];

int i;
scanf("%s",&s);

for(i=0;i<7;i++){
  if(s[i]=='\0'){
    break;
  }
}


if(i!=6){
  printf("No");
}else if(s[2]==s[3]&&s[4]==s[5]){
printf("Yes");
}else{
  printf("No");
}

return 0;
}

Measured memory_bytes: 2152
#include<stdio.h>
#include<stdlib.h>
int main(){
    int n,x,t;
    scanf("%d %d %d",&n,&x,&t);
    long long int sum=t;
    while(n>x){
        sum=sum+t;
        n=n-x;
    }
    printf("%lld",sum);
}

Measured memory_bytes: 1732
N, M = map(int, input().split())

if N >= 3 and M >= 3:
    print(N * M - 2 * (N + M) + 4)

if N == 2 or M == 2:
    print(0)

if N == 1:
    if M >= 3:
        print(M - 2)
    elif M == 1:
        print(1)

if M == 1:
    if N >= 3:
        print(N - 2)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>p(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    int ans=0;
    rep(i,n-1){
        if(p[i]==i){
            swap(p[i],p[i+1]);
            ans++;
        }
    }
    if(p[n-1]==(n-1)){
        swap(p[n-1],p[n-2]);
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>

using namespace std;

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

typedef vector<int> vi;

int main()
{
	int field[10][10];
	rep(i, 10)
		fill(field[i], field[i]+10, 0);

	int deepest = 0;
	int ans = 100;
	int x, y, s;
	while(scanf("%d,%d,%d", &x, &y, &s) != EOF){
		reep(i, -2, 3) reep(j, -2, 3){
			int py = i+y, px = j+x;
			if(py<0 || px<0 || 10<=py || 10<=px)
				continue;
			if(abs(i)+abs(j) >= 3)
				continue;
			if(s!=3 && (abs(i)==2 || abs(j)==2))
				continue;
			if(s==1 && abs(i)+abs(j)>=2)
				continue;

			ans -= !field[py][px];
			deepest = max(deepest, ++field[py][px]);
		}
	}
	printf("%d\n%d\n", ans, deepest);

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

template<typename T>
bool is_prime(T n){
  for(T i = 2; i * i < n; i++){
    if(n % i == 0) return false;
  }
  return n != 1;
}

int main(){
  int Q;
  cin >> Q;
  vi l(Q), r(Q);
  for(int i = 0; i < Q; i++){
    cin >> l.at(i) >> r.at(i);
  }
  vi pr(0), num(0);
  vector<bool> prime(110000, true);
  for(int i = 2; i < 110000; i++){
    if(prime.at(i)){
      pr.push_back(i);
      for(int j = i*2; j < 110000; j+=i){
        prime.at(j) = false;
      }
    }
  }
  for(int i = 0; i < pr.size(); i++){
    if(pr.at(i) == 2) continue;
    if(prime.at((pr.at(i)+1)/2)) num.push_back(pr.at(i));
  }
  
  for(int i = 0; i < Q; i++){
    auto itel = lower_bound(ALL(num), l.at(i));
    auto iter = upper_bound(ALL(num), r.at(i));
    cout << iter - itel << endl;
  }

}

Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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

















int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    scanf("%d", &n);
    int cnt[200001] = {};
    for(int i = 0; i < n - 1; i++){
        int a;
        scanf("%d", &a);
        cnt[a]++;
    }
    for(int i = 1; i <= n; i++){
        printf("%d\n", cnt[i]);
    }
}

Measured memory_bytes: 4596
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long a, b, c;
  cin >> a >> b >> c;
  c = min(a + b + 1, c);
  cout << b + c << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(Point p) {return Point(x*p.x-y*p.y,x*p.y+y*p.x);}
    Point operator*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}
    double arg(){return atan2(y,x);}
    double dot(Point p){return x*p.x+y*p.y;}
    double det(Point p){return x*p.y-y*p.x;}
};
int ccw(Point a,Point b,Point c){
    Point t1=b-a,t2=c-a;
    if(t1.det(t2)> eps) return 1;//counter clockwise
    if(t1.det(t2)< -eps) return -1;//clockwise
    if(t1.dot(t2)< -eps) return 2;//c-a-b online
    if(t1.norm()<t2.norm()) return -2;//a-b-c online
    return 0;//a-c-b online
}
bool cmp_x(const Point& p,const Point& q){
  if(p.x!=q.x) return p.x<q.x;
  return p.y<q.y;
}
bool intersectSS(Point a,Point b,Point c,Point d){
    return (ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0);
}
struct Circle{
    double r;
    Point p;
    Circle(){}
    Circle(Point p,double r):p(p),r(r){}
};
bool isIntersectCC(Circle c1,Circle c2){
    return (c1.p-c2.p).abs()<=c1.r+c2.r+eps;
}
pair<Point,Point> CrossPointsCC(Circle c1,Circle c2){
    assert(isIntersectCC(c1,c2));
    double d=(c1.p-c2.p).abs();
    double k=acos((d*d+c1.r*c1.r-c2.r*c2.r)/(c1.r*d*2));
    return make_pair(c1.p+(c2.p-c1.p)*Point(cos(k),sin(k))*(c1.r/d),c1.p+(c2.p-c1.p)*Point(cos(-k),sin(-k))*(c1.r/d));
}
double INF=1000100010;
double d[101][2];
Circle c[101];
Point po[101][2];
bool ck(int l,int r,int idl,int idr){
    Point lp=po[l][idl],rp=po[r][idr];
    FOR(i,l+1,r){
        if(!intersectSS(lp,rp,po[i][0],po[i][1])) return false;
    }
    return true;
}
int main(){
    int n;
    double xi,yi,ri;
    while(cin>>n,n){
        rep(i,n+1) d[i][0]=d[i][1]=INF;
        rep(i,n){
            cin>>xi>>yi>>ri;
            if(i==0) po[i][0]=po[i][1]=Point(xi,yi);
            if(i==n-1) po[n][0]=po[n][1]=Point(xi,yi);
            c[i]=Circle(Point(xi,yi),ri);
        }
        rep(i,n-1){
            pair<Point,Point> pp=CrossPointsCC(c[i],c[i+1]);
            po[i+1][0]=pp.first;po[i+1][1]=pp.second;
        }
        d[0][0]=d[0][1]=0.0;
        rep(i,n)rep(k,2)FOR(j,i+1,n+1)rep(l,2){
            if(ck(i,j,k,l)){
                d[j][l]=min(d[j][l],d[i][k]+(po[i][k]-po[j][l]).abs());
            }
        }
        cout<<fixed<<setprecision(12)<<d[n][0]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int a,b;
  string s;
  cin>>a>>b;
  cin>>s;
  REP(i,a+b+1){
    if(i==a){
      if(s[i]=='-'){
        continue;
      }else{
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      if(0<=s[i]-'0' && s[i]-'0'<=9){
        continue;
      }else{
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
#define mod 1000000007
using namespace std;
signed main() {
	int n, a[123456], b = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 0) {
			b++;
			a[i] *= -1;
		}
	}
	sort(a, a + n);
	b %= 2;
	int ans = 0; if (b)ans -= a[0];
	for (int i = b; i < n; i++)ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 1024
import math
import itertools
import sys
s = input()
t = input()
cnt = len(t)
for i in range(len(s)-len(t)+1):
    tmp = s[i:len(t)+i]
    tcnt = 0
    for j in range(len(tmp)):
        if(tmp[j] != t[j]):
            tcnt += 1
    cnt = min(cnt, tcnt)
print(cnt)


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

int D[10010];

int main(){
    int n,d,s,c=0;
    cin>>n;
    for(int i=0;i<n;i++) cin>>D[i];
    cin>>d;
    for(int i=0;i<d;i++){
        cin>>s;
        for(int j=0;j<n;j++){
            if(D[j]==s){
                c++;
                break;
            }
        }
    }
    cout<<c<<endl;
    return 0;
}



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

int main(){
  int a;
  cin >> a;
  string b[a];
  int c[a];
  int d[a]; //順番
  for(int i = 0;i < a;i++){
    d[i] = i+1;
  }

  for(int i = 0;i < a;i++){
    cin >> b[i];
    cin >> c[i];
  }
  for(int i = a-1;i >= 0;i--){
    for(int j = i-1;j >= 0;j--){
      if(b[i] < b[j]){
        string kari = b[j];
        b[j] = b[i];
        b[i] = kari;

        int karinum = c[j];
        c[j] = c[i];
        c[i] = karinum;

        int karinuma = d[j];
        d[j] = d[i];
        d[i] = karinuma;

      }else if(b[i] == b[j]){
        if(c[i] > c[j]){
          string kari = b[j];
          b[j] = b[i];
          b[i] = kari;

          int karinum = c[j];
          c[j] = c[i];
          c[i] = karinum;

          int karinuma = d[j];
          d[j] = d[i];
          d[i] = karinuma;

        }
      }
    }
  }
  for(int i = 0;i < a;i++){
    cout << d[i] << endl;
  }
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		Set<Integer> set = new HashSet<Integer>();
		
		int s = sc.nextInt();
		set.add(s);
		int before = s;
		
		for(int i = 2;;i++) {
			if(set.contains(f(before))) {
				System.out.println(i);
				break;
			}else {
				before = f(before);
				set.add(before);
			}
		}
	}
	
	static int f(int x) {
		if(x % 2 == 0) {
			return x / 2;
		}else {
			return (x * 3 + 1);
		}
	}
}

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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define output_to_error freopen("error.txt" , "w" ,stderr)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int N = 1e5+1;
int cnt[N];

int main()
{
	#ifdef LOCAL
        input_from_file;
        output_to_file;
        output_to_error;
    #endif
	fastio;cin.tie(0);cout.tie(0);
	int n , m , x ; cin >> n >> m ;
	string s ;int ac = 0 , pe = 0 ;
	for(int i = 1 ; i <= m ; ++i)
	{
		cin >> x >> s ;
		if(s == "AC")
		{
			if(cnt[x] != -1) ac++ , pe += cnt[x] , cnt[x] = -1;
		}
		else if(s == "WA")
		{
			if(cnt[x] != -1) cnt[x]++;
		}
	}
	cout << ac << " " << pe ;

	return 0;
}


Measured memory_bytes: 892
H,W = map(int, input().split())

ans = H * W

# 1つめは縦を1ずつ増やしていく場合
for h in range(1, H):
    a = h * W

    # 残りについて、縦で分割する場合
    b = ((H - h) // 2) * W
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

    # 残りについて、横で分割する場合
    b = (H - h) * (W // 2)
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

# 1つめは横を1ずつ増やしていく場合
for w in range(1, W):
    a = w * H

    # 残りについて、縦で分割する場合
    b = (W - w) * (H//2)
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

    # 残りについて、横で分割する場合
    b = ((W - w) // 2) * H
    c = H * W - a - b
    ans = min(ans, max(a,b,c) - min(a,b,c))
    

print(ans)

Measured memory_bytes: 3064
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#define ll long long
using namespace std;



int main(){
  string S;
  ll N,K;
  cin>>N>>K;
  cin>>S;
  if(S[K-1]=='A') S[K-1]='a';
  if(S[K-1]=='B') S[K-1]='b';
  if(S[K-1]=='C') S[K-1]='c';
  cout<<S<<endl;
  return 0;
}



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

int main()
{
    int numa, numb;
    cin >> numa >> numb;

    numa += 11;
    numb += 11;
    numa %= 13;
    numb %= 13;
    
    if(numa > numb){
        cout << "Alice\n";
    }else if(numa < numb){
        cout << "Bob\n";
    }else{
        cout << "Draw\n";
    }

    return 0;
}


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

int main(){
    ll X,N; cin>>X>>N;
    vector<bool> b(102,true);
    vector<ll> p(N);
    for(ll i=0;i<N;i++){
        cin>>p[i];
        b[p[i]]=false;
    }
    ll d=1000;
    ll ans;
    for (ll i = 0; i < 102; i++){
        if(b[i]&&d>abs(X-i)){
            d=abs(X-i);
            ans=i;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

const int N = 2005;
int a[N], x[N], y[N];

int main() {
	int n;
	cin >> n >> a[0] >> a[1];
	for (int i = 2; i <= n + 1; i++)
		cin >> a[i];
	for (int i = n; i > 0; i--) {
		x[i] = y[i] = abs(a[i] - a[n + 1]);
		for (int j = i + 1; j <= n; j++) {
			if (x[i] < y[j]) {
				x[i] = y[j];
			}
			if (y[i] > x[j]) {
				y[i] = x[j];
			}
		}
	}
	cout << x[1];
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<memory>
#include<algorithm>
#include<cstring>

// 上から順番にパリティを調べていって、対処させ続ける
// 多分一意なのであんまり木にしなくて良い

int main(void)
{
	int N;
	std::cin >> N;
	auto A = std::make_unique<int[]>(N+1);
	auto B = std::make_unique<int[]>(N+1);

	// 入力
	for(auto i = 1; i < N+1; i++)
	{
		int input;
		std::cin >> input;
		A.get()[i] = input;
	}

	memset(&B.get()[0], 0, (N+1) * sizeof(int));


	int ctr = 0;
	// 後ろから計算
	// 答えはBに入れる
	for(auto i = N; i >= 1; i--)
	{
		int mid_good = 0;
		// 自分以上を計算
		for(int j = 2; j <= N; j++)
		{
			int mid_i = i * j;
			if(mid_i > N)
			{
				break;
			}
			else
			{
				mid_good += B.get()[mid_i];
				mid_good %= 2;
			}
			if(i == 1 && false)
			{
				std::cout << "dump: " << mid_good << std::endl;
				std::cout << "j: " << j << std::endl;
			}
		}
		if(i == 1 && false)
		{
			std::cout << "dump: " << mid_good << std::endl;
		}


		B.get()[i] = (A.get()[i] == mid_good) ? 0 : 1;
		if(B.get()[i] == 1)
		{
			ctr++;
		}
	}

	// 出力部
	std::cout << ctr << std::endl;
	if(ctr > 0)
	{
		for(auto i = 1; i <= N; i++)
		{
			if(B.get()[i] == 1)
			{
				std::cout << i << " ";
			}
		}
		std::cout << std::endl;
	}
}

Measured memory_bytes: 2432
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        long[] T = new long[N].Select(x => long.Parse(Console.ReadLine())).ToArray();

        long res = 1;
        List<long> TList = new List<long>();
        for (int i = 0; i < T.Length; i++)
        {
            if (!TList.Contains(T[i]))
            {
                TList.Add(T[i]);
            }
        }
        TList.ForEach(x => res = Lcm(x, res));
        Console.WriteLine(res);
    }

    public static long Lcm(long a, long b)
    {
        return a * (b / Gcd(a, b));
    }
    public static long Gcd(long a, long b)
    {
        if (a < b) return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}

Measured memory_bytes: 13280
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<ld,ld> pdd;

const ll INF=(1LL<<50);
#if __cplusplus<201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif
template<class T>
bool chmax(T& a,const T& b){
  if(a<b){
    a=b;
    return true;
  }
  return false;
}
template<class T>
bool chmin(T& a,const T& b){
  if(a>b){
    a=b;
    return true;
  }
  return false;
}
template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  set<char> s;
  REP(3){
    s.insert(S[i]);
  }
  if(s.size()==2){
    cout<<YES<<endl;
  }else{
    cout<<NO<<endl;
  }
}

int main(){
  cout<<setprecision(1000);
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int h,w,k;
    cin>>h>>w>>k;
    vector<vector<int>> dp(h+1,vector<int>(1<<w));
    dp[0][0] = 1;
    auto check = [&](int mask)->bool {
       for(int j=0;j<w-1;++j)if((mask&(1<<j)) and (mask&(1<<(j+1)))){
                return true;
            }
        return false;
    };
    for(int i=0;i<h;++i){
       for(int j=0;j<w;++j){
        for(int mask = 0;mask<1<<(w-1);++mask){
            if(check(mask))continue;
            if(mask&1<<j)(dp[i+1][j+1] += dp[i][j])%=mo;
            else if(j && mask&1<<(j-1)) (dp[i+1][j-1] += dp[i][j])%=mo;
            else (dp[i+1][j] += dp[i][j])%=mo;
            
        }
       }
    }
    cout << dp[h][k-1] << endl;
    return 0;
}

Measured memory_bytes: 3744
N, K = map(int, input().split())
P = list(map(int, input().split()))

# estP = [-1]
def est(i):
    return 1.0 + (i - 1) * 0.5
# for i in range(1, 1001):
# print(i, sum([j * 1.0 / i for j in range(1, i + 1)]))
# estP.append(sum([j * 1.0 / i for j in range(1, i + 1)]))
# print(i, 1.0 + (i - 1) * 0.5)
# # print(estP)

# 普通に計算する
# - 2x10e5 の2重ループなのでTLE

# m = -1.0
# for i in range(N - K + 1):
#     vi = sum([est(P[j]) for j in range(i, i + K)])
#     m = max(vi, m)
# print(m)


# かしこい計算: 累積和
# WAになってしまった
# sumA = [est(P[0])]
# for i in range(1, N):
#     sumA.append(sumA[-1] + est(P[i]))
# # print([est(P[i]) for i in range(N)])
# # print(sumA)

# m = -1
# for i in range(N - K):
#     # print(i, i + K, sumA[i + K] - sumA[i])
#     m = max(m, sumA[i + K] - sumA[i])
# print(m)

expected = [(P[i] + 1) / 2 for i in range(N)]
# print(expected)
# print(expected[:K])

# 0 ~ K-1 の期待値
ans = sum(expected[:K])
tmp = ans
for i in range(N - K):
    # 新しく追加 (i番目を抜いて，i+K番目を入れる，横に移動)
    tmp = tmp + expected[i + K] - expected[i]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 77448
#include<iostream>

using namespace std;

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

    char ans;
    if(b=='A'){
        ans='T';
    }else if(b=='T'){
        ans='A';
    }else if(b=='C'){
        ans='G';
    }else{
        ans='C';
    }

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

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

const int MAXN = 1e5+5;
const int MAXNN = 1e5+7;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

vector<int> adjList[MAXN];
int dp[MAXN],deg[MAXN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n,m;cin >> n >> m;
    for(int i=0;i<m;++i){
        int c,d;cin >> c >> d;
        adjList[c].pb(d);
        ++deg[d];
    }
    deque<int> dq;
    for(int i=1;i<=n;++i) if(!deg[i]) dq.pb(i);

    while(!dq.empty()){
        int now = dq.front();
        dq.pop_front();
        for(auto u : adjList[now]){
            dp[u] = max(dp[u],dp[now] + 1);
            --deg[u];
        }
        for(auto u : adjList[now]) if(deg[u] == 0) dq.pb(u);

    }
    int maxs=0;
    for(int i=1;i<=n;++i) maxs = max(maxs,dp[i]);
    cout << maxs;

}


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

const int maxn=200005;

inline int read(){
	register int x=0,w=1,ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-48;
	return w*x;
}

int n,N,M,ans;
int a[maxn],b[maxn];

inline int check(int lim){
	for(int i=1;i<=lim;i++)b[i]=a[n-lim+i]-M;
	for(int i=lim+1;i<=n;i++)b[i]=a[i-lim];
	int mx=0;
	for(int i=1;i<=N;i++)
		if(b[i]+b[n-i+1]<0)return 0;
		else mx=max(mx,b[i]+b[n-i+1]);
	ans=min(ans,mx);
	return 1;
}

int main(){
	N=read(),M=read(),n=N*2;
	for(int i=1;i<=n;i++)a[i]=read();
	sort(a+1,a+1+n);
	ans=0x7fffffff;
	int l=0,r=N,mid,res;
	while(l<=r){
		mid=(l+r)>>1;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
    long long int n, k; cin >> n >> k;
    long long ans = k;
    long long t; cin >> t;
    for (int i = 1; i < n; i++) {
        long long x; cin >> x;
        ans += min(k, (x - t));
        t = x;
    }
    cout << ans;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

//m=a1*a2*・・・とするとm-1はどのaでmodをとってもa-1になる
//それが分かっているのでfの最大値は全てのaを足してnを引けば良い
int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    ll sum=0;
    rep(i,n){
        sum += a.at(i);
    }
    cout << sum - n << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
int pwr(int a, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(a, pwr(a, p - 1));
    return pwr(mul(a, a), p / 2);
}
 
int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif
 
  int n, p;
  cin >> n >> p;
  mod = p;
  string s;
  cin >> s;
  vi v(n);
  reverse(all(s));
  for(int i = 0; i < n; i++) {
    v[i] = s[i] - '0';
  }
  if(p == 2 || p == 5) {
    ll res = 0;
    for(int i = 0; i < n; i++) {
      if(v[i] % p == 0) {
        res += n - i;
      } 
    }
    cout << res;
    return 0;
  }
  vi cnt(p);
  int x = 0;
  for(int i = 0; i < n; i++) {
    x = add(x, mul(pwr(10, i), v[i]));
    cnt[x]++;
  }
  ll res = 0;
  cnt[0]++;
  for(int i = 0; i < p; i++) {
    res += 1ll * cnt[i] * (cnt[i] - 1) / 2;
  }
  cout << res;
}


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

string s;

void solve() {
    int n = s.length();
    if(s[n - 1] != 's') cout << s << "s";
    else cout << s << "es";
}

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

    getline(cin,s);
    solve();

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    // input
    lint N;
    map<lint, lint> A;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        lint tmp;
        cin >> tmp;
        ++A[tmp];
        if (A[tmp] >= 2) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 12800
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
	int D,N;
	scanf("%d %d", &D, &N);
	if (N == 100){
	    if(D == 0)
	        printf("%d", 101);
	    if(D == 1)
	        printf("%d", 10100);
	    if(D == 2)
	        printf("%d", 1010000);
	}else {
	    printf("%d", (int)pow(100,D)*N);
	}
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<int> av(n);
	for (auto& a : av) {
		cin >> a;
	}

	for (int i = k; i < n; ++i) {
		if (av[i - k] < av[i]) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4044
import copy
n=int(input())

#a=[int(input() for _ in range(n))]
a = [int(input()) for i in range(n)]

b=[]
b = copy.deepcopy(a)
b.sort(reverse=True)
#print(b)
#print(a)
#print(a[1])
for i in range(n):
    if a[i]==b[0]:
        print(b[1])
    else:
        print(b[0])



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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    if (a < 13) {
        if (a <= 5) {
            cout << 0 << endl;
        } else {
            cout << b / 2 << endl;
        }
        return 0;
    }
    cout << b << endl;
}

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

  //  bool isprime[10000];
  cin>>n;
  if(n==0||n==2) cout<<1<<endl;
  else if(n==1) cout<<2<<endl;
  else cout<<0<<endl;
  /*  for(int i=0;i<10000;i++) isprime[i]=true;
  isprime[0]=isprime[1]=false;
  for(int i=0;i<5000;i++){
    if(!isprime[i]) continue;
    for(int j=i+i;j<10000;j+=i) isprime[j]=false;
  }
  int sum=1;
  for(int i=0;i<n;i++){
    sum*=2;
  }
  int l;
  for(int i=sum+1;i<10000;i++){
    if(isprime[i]){
      l=i;
      break;
    }
  }
  long long s=1;
  for(int i=2;i<l;i++){
    s*=10;
    s++;
  }
  cout<<s<< ' '<<l<<endl;
  cout<<s%l<<endl;*/
  return 0;
}

Measured memory_bytes: 1164
/*****************Bismillahir Rahmanir Rahim***********************/

#include<bits/stdc++.h>
using namespace std;

/************************Start Of Template*************************/

/******** Mahin Shefat - GhOstMan *************/


#define     pb              push_back
#define     popb            pop_back
#define     ll              long long int
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     check           printf("check")
#define     sqr(x)          (x)*(x)
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     Pair            pair<ll,ll>
#define     MAX             1000000000000014
#define     MIN             -1000000000000014
#define     endl            '\n'
#define     Fread           freopen("inputdur.txt","r",stdin)
#define     Fwrite          freopen("output.txt","w",stdout)

/************************End Of Template*************************/
double arr[10005];
int main(){
	
	int n;
	cin >> n;
	ll div = 1;
	for(int i = 1; i <= n; i++){
		div = div * 2LL;
		cin >> arr[i];
	}	
	div /= 2;	
	sort(arr + 1 , arr + n + 1);
	double ans = (arr[1] + arr[2]) / div;
	for(int i = 3; i <= n; i++){
		div /= 2;
		ans += (arr[i] / div);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int leftNum(char c) {
	return 26 - (c - 'a');
}

int main() {
	string s;
	int K;
	cin >> s >> K;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] != 'a') {
			int left = leftNum(s[i]);
			if (left <= K) {
				K -= left;
				s[i] = 'a';
			}
		}
	}
	if (K != 0) {
		K = K % 26;
		int left = leftNum(s[s.length() - 1]);
		if (left < K) {
			s[s.length() - 1] = 'a' + (K - left);
		}
		else {
			s[s.length() - 1] = s[s.length()-1] + K;
		}
	}
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
  int data,i,A[100],check=0,tmp,total=0;
  scanf("%d",&data);
  for(i=0;i<data;i++)scanf("%d",&A[i]);
  while(1){
    for(i=data-1;i>0;--i){
      if(A[i-1] > A[i]){
	tmp = A[i];
	A[i] = A[i-1];
	A[i-1] = tmp;
	check++;
      }
    }
    if(check == 0)break;
    total +=check;
    check = 0;  
  }
  for(i=0;i<data;i++){
    if(i == data-1)printf("%d\n",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d\n",total);
  return 0;
}


Measured memory_bytes: 2104
#!/usr/bin/env python
D,G=map(int, input().split())
PC=[0]+[list(map(int, input().split())) for _ in range(D)]

def function(G,i):
    if i==0:
        return 1e9
    n=min(G//(i*100),PC[i][0])
    s=n*i*100
    if n==PC[i][0]:
        s+=PC[i][1]
    if s<G:
        n+=function(G-s,i-1)
    return min(n,function(G,i-1))
    
print(function(G,D))

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){

  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;

  for(i=0; i<n1; i++){
    L[i] = A[left+i];
  }
  for(i=0; i<n2; i++){
    R[i] = A[mid+i];
  }

  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;

  for(k=left; k<right; k++){
    if(L[i].value <= R[j].value){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
    }
  }

}

void mergeSort(struct Card A[], int n, int left, int right){

  int mid;

  if(left+1 < right){
    mid = (left+right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }

}

int partition(struct Card A[], int n, int p, int r){

  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;

  for(j=p; j<r; j++){
    if(A[j].value <= x.value){
      i++;
      t = A[i];
      A[i] = A[j];
      A[j] = t;
    }
  }

  t = A[i+1];
  A[i+1] = A[r];
  A[r] = t;

  return i+1;

}

void quickSort(struct Card A[], int n, int p, int r){

  int q;

  if(p<r){
    q = partition(A, n , p, r);
    quickSort(A, n, p, q-1);
    quickSort(A, n, q+1, r);
  }

}

int main(){

  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable=1;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s %d", S, &v);
    A[i].suit = B[i].suit = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A, n, 0, n);
  quickSort(B, n, 0, n-1);

  for(i=0; i<n; i++){
    if(A[i].suit != B[i].suit){
      stable = 0;
    }
  }

  if(stable==1){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  for(i=0; i<n; i++){
    printf("%c %d\n", B[i].suit, B[i].value);
  }

  return 0;
}

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

int Dice[6];
void init() {
  for(int i=1;i<=6;i++)
    Dice[i-1] = i;
}
void lotate(int op[]) {
  int Dice_tmp[6];
  for(int i=0;i<6;i++)
    Dice_tmp[i] = Dice[i];
  for(int i=0;i<6;i++)
    Dice[i] = Dice_tmp[op[i]];
}
int main() {
  int north[] = {1,5,2,3,0,4};
  int east[] = {3,1,0,5,4,2};
  int west[]= {2,1,5,0,4,3};
  int sorth[] = {4,0,2,3,5,1};
  int right[] = {0,2,4,1,3,5};
  int left[] = {0,3,1,4,2,5};

  int n,score;
  char s[6];
  while(true) {
    cin >> n;
    if(n == 0) break;
    init();
    score = Dice[0];
    for(int i=0;i<n;i++) {
      cin >> s;
      if(s[0] == 'N') lotate(north);
      if(s[0] == 'E') lotate(east);
      if(s[0] == 'W') lotate(west);
      if(s[0] == 'S') lotate(sorth);
      if(s[0] == 'R') lotate(right);
      if(s[0] == 'L') lotate(left);
      score += Dice[0];
    }
    cout << score << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>

using namespace std;

int main (void)
{
	long long n,a,b,x;

	cin >> n >> a >> b;

	x = 0;

	for (long long i = 0; i < 100000; i++)
	{
		x = ((a + b) * i) + b;

		if (x == n)
		{
			cout << i << endl;
			break;
		}
		else if (x > n)
		{
			cout << i - 1 << endl;
			break;
		}
	}
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{

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

		// String input = sc.nextLine();
	  // String nums[] = input.split(" ");

	  // long A = Long.parseLong(nums[0]);
	  // long B = Long.parseLong(nums[1]);
	  // long sum = Long.parseLong(nums[2]);

		System.out.println((X * X * X));
		// System.out.println(S.toString());

	}
}


Measured memory_bytes: 26204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int d, n;
	cin >> d >> n;
	int a = 1;
	for (int i = 0; i < d; i++) {
		a *= 100;
	}
	if (n != 100)
		cout << n * a << endl;
	else
		cout << 101 * a << endl;
}



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

int main(void) {
	long long A,B;
	char s;
	scanf("%lld %c %lld", &A, &s, &B);
	if (s == '+') {
		printf("%lld", A + B);
	}
	else {
		printf("%lld", A - B);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

#include <vector>

#include <algorithm>

#include <sstream>

#include <string>

#include <cmath>

#include <list>

#include <set>
using namespace std;

int in() {int x; cin >> x; return x;}

template <typename T> class SegTree

{

public:

	int n;

	T T_max;

	vector<T> dat;

	SegTree(int n_, T t_max)

	{

		int n = 1;

		T_max = t_max;

		while (n < n_)n *= 2;

		for (int i = 0; i < 2 * n - 1; i++)dat.push_back(t_max);

	}

	void update(int k, T a)

	{

		k += n - 1;

		dat[k] = a;

		while (k > 0)

		{

			k = (k - 1) / 2;

			dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);

		}

	}



	//[a,b)

	T query(int a, int b)

	{

		return _query(a, b, 0, 0, n);

	}



private:

	T _query(int a, int b, int k, int l, int r)

	{

		if (r <= a || b <= l)return T_max;

		if (a <= l && r <= b)return dat[k];

		else

		{

			T vl = _query(a, b, k * 2 + 1, l, (l + r) / 2);

			T vr = _query(a, b, k * 2 + 2, (l + r) / 2, r);

			return min(vr, vl);

		}

	}

};

int main()
{
	int n;
	bool fis = true;
	while (cin >> n && n)
	{
		if (fis)
		{
			fis = false;
		}
		else
		{
			cout << endl;
		}
		vector< pair <int, string> > a;
		for (int i = 0; i < n; i++)
		{
			int p = 0;
			string name;
			cin >> name;
			p += in() * 3; in();
			p += in();

			a.push_back(pair<int, string>(p, name));
		}

		for (int l = 0; l <= n; l++)
		{
			for (int i = 1; i < a.size(); i++)
			{
				if (a[i].first > a[i - 1].first)swap(a[i], a[i - 1]);
			}
		}

		for (int i = 0; i < n; i++)
		{
			cout << a[i].second << "," << a[i].first << endl;
		}
	}
}

Measured memory_bytes: 1216
use proconio::input;
use proconio::marker::Usize1;
use std::collections::VecDeque;

fn main() {
  input! {
    N: usize,
    M: usize,
    AB: [(Usize1, Usize1);M]
  }
  let mut neighbors: Vec<Vec<usize>> = vec![Vec::with_capacity(N); N];
  let mut result: Vec<usize> = vec![N; N];
  
  for (a, b) in AB {
    neighbors[a].push(b);
    neighbors[b].push(a);
  }

  let mut nexts: VecDeque<usize> = VecDeque::new();
  nexts.push_back(0);
  while let Some(value) = nexts.pop_front() {
    for &nei_val in neighbors[value].iter() {
      if result[nei_val] == N {
          nexts.push_back(nei_val);
            result[nei_val] = value;
        }
    }
  }

  println!("Yes");
  for v in result.iter().skip(1) {
    println!("{}", v + 1);
  }
}

Measured memory_bytes: 16876
#include <stdio.h>

int deleteCube(char *s) {
    int i, one = 0, zero = 0;
    for (i=0; s[i] ;i++) {
        if (s[i] == '1') one++;
        else if (s[i] == '0') zero++;
    }
    return one < zero ? one
         : zero;
}

int main() {
    char s[100001];
    scanf("%s", s);
    printf("%d\n", 2*deleteCube(s));
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c ==  'e' || c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;

  return 0;
}


Measured memory_bytes: 3584
import sys

def main():
    A = int(input())
    B = int(input())

    if(A==1 and B==2 or A==2 and B==1):
        print('3')
    elif(A==1 and B==3 or A==3 and B==1):
        print('2')
    else:    
        print('1')

main()


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

using namespace std;

#define ios         ios_base::sync_with_stdio(false);
#define ll          long long
#define ld          long double
#define db(x)       cout << "[" << #x << ": " << (x) << "]\n"
#define db2(x,y)    cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]\n"
#define db3(x,y,z)  cout << "[" << #x << ": " << (x) << "]  [" << #y << ": " << (y) << "]  [" << #z << ": " << (z) << "]\n"
#define cn          107
#define sn          1007
#define bn          200007
#define M           1000000007
#define inf         LLONG_MAX



int main()
{
        ios;
        ll n; cin >> n;
        string s = to_string(n);
        ll sum = 0;
        for(auto i : s)
        {
                sum += i-'0';
        }
        if(n%sum) cout << "No"; else cout << "Yes";
}



Measured memory_bytes: 3740