akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
void cscan(void);
void clear(void);

int n,sa=0,sb=0;

int main(){

  int end=1;

  while(end){

  scanf("%d",&n);

  if(n==0){
    break;
  }

  cscan();

  printf("%d %d\n",sa,sb);

  clear();

}

  return 0;
}

void cscan(){

  int i,j;
  int a,b;

  for(i=0;i<n;i++){

    scanf("%d %d",&a,&b);

    if(a==b){
      sa+=a;
      sb+=b;
    }
    else if(a>b){
      sa+=a+b;
    }
    else if(a<b){
      sb+=a+b;
    }

  }
}

void clear(){

  sa=sb=0;

}

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

using namespace std;

int n;
char a[1000010];
int b[1000010];

int main(){
	scanf("%s",a);
	n = strlen(a);
	for(int i=n;i>=1;i--){
		b[i]=a[i-1]-'0';
	}
	b[0]=0;

	int ans = 0;
	for(int i=n;i>=0;i--){
		if(b[i]>9){
			b[i] -= 10;
			b[i-1]++;
		}
		if(b[i]<=4)
			ans += b[i];
		else if (b[i]>=6){
			ans += 10-b[i];
			b[i-1]++;
		}else{
			if(b[i-1]<5)ans += b[i];
			else {b[i-1]++;ans += b[i];}
		}
//		printf("%d %d\n",i,ans);
	}
	printf("%d\n",ans);
}

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

int main()
{
    string S;
    cin >> S;
    int len = S.length() - 1;

    if (S[len] == '2' || S[len] == '4' || S[len] == '5' || S[len] == '7' || S[len] == '9')
    {
        cout << "hon" << endl;
    }
    else if (S[len] == '0' || S[len] == '1' || S[len] == '6' || S[len] == '8')
    {
        cout << "pon" << endl;
    }
    else if (S[len] == '3')
    {
        cout << "bon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] arr = str.toCharArray();
        for (int i = str.length() - 1; i >= 0; i--){
            System.out.print(arr[i]);
        }
        System.out.println();
    }
}



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

class Program
{    

    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());

        string input = Console.ReadLine();
        string[] str = input.Split(' ');

        int[] data = new int[n];

        for(int i = 0; i < n; i++)
        {
            data[i] = int.Parse(str[i]);
        }

        for(int i = 0; i < n; i++)
        {
            int j = i - 1;
            int v = data[i];
            while(j >= 0 && data[j] > v)
            {
                data[j + 1] = data[j];
                j--;
            }

            data[j + 1] = v;

            Console.WriteLine(String.Join(" ", data));
            
        }
       
    }
}


Measured memory_bytes: 17988
from collections import deque

h, w = map(int, input().split())
a = ''.join(input() + '#' for _ in range(h))
n = len(a)
b = ['#'] * w
q = deque()
r = 0
for i in range(n):
  if a[i] == '.':
    b[:-w] = a
    b[i] = 0
    q.append(i)
    while(q):
      i = q.popleft()
      r = max(r, b[i])
      for j in (i - 1, i + 1, i - w - 1, i + w + 1):
        if b[j] == '.':
          b[j] = b[i] + 1
          q.append(j)
print(r)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
void OUT(bool b){cout<<(b?"YES":"NO")<<endl;}
void Out(bool b){cout<<(b?"Yes":"No")<<endl;}
void out(bool b){cout<<(b?"yes":"no")<<endl;}
int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}

/*他のライブラリを入れる場所*/

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s,s!="#"){
		int y,m,d; cin>>y>>m>>d;
		if(y<=30 or (y==31 and m<=4)){
			cout<<s<<" "<<y<<" "<<m<<" "<<d<<endl;
		}else{
			cout<<"? "<<y-30<<" "<<m<<" "<<d<<endl;
		}
	}
	return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> T(N+1);
  int sum=0;
  for(int i=0;i<N;i++){
    cin >> T.at(i);
    sum+=T.at(i);
  }
  int M;
  cin >> M;
  for(int i=0;i<M;i++){
    int p,x;
    cin >> p >> x;
    cout << sum-T.at(p-1)+x << endl;
  }
  return 0;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N; cin >> N;
    ll A[N]; rep(i, N) cin >> A[i];
    //abs(A[i]-A[j]) = abs(i-j)
    map<ll, ll> mp1;
    map<ll, ll> mp2;
    rep(i, N){
        mp1[i-A[i]]++;
        mp2[i+A[i]]++;
    }
    ll ans = 0;
    for(auto p: mp1){
        ll n = p.first, cnt = p.second;
        ll x = mp2[n];
        ans += cnt*x;
    }
    for(auto p: mp2){
        ll n = p.first, cnt = p.second;
        ll x = mp1[n];
        ans += cnt*x;
    }
    cout << ans/2 << endl;
    return 0;  
}

Measured memory_bytes: 50560
// In the name of God

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int n;
	cin >> n;
	long double sum = 0;
	for(int i=0;i<n;i++) {
		long double x;
		cin >> x;
		sum += 1.0/x;
	}
	cout << setprecision(9);
	cout << (1.0/sum);
	return 0;
}


Measured memory_bytes: 256
/**	epsileer 12 January 2020  17:28:13  **/	
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

void solve(){
	char ch; cin>>ch;
	cout<<(char)(ch+1);
}	

signed main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); TEST; return 0;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
s = list(input())
s_0_1 = [1]*(k+int(s[0]))
s_1_0 = []
for i in range(n-1):
    if s[i] == "0" and s[i+1] == "1":
        s_0_1.append(i+2)
    elif s[i] == "1" and s[i+1] == "0":
        s_1_0.append(i+1)
s_1_0.extend([n]*(k+int(s[-1])))
ans = 0
for i in range(len(s_0_1)):
    ans = max(ans, s_1_0[i]-s_0_1[i]+1)
print(ans)




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

struct union_find_tree{

    vector<ll> par;

    union_find_tree(ll n) {
        par.resize(n);
        for(ll i=0;i<n;i++) {
            par[i] = i;
        }
    }

    ll find(ll a) {
        if(par[a] == a)return a;
        return par[a] = find(par[a]);
    }

    void unite(ll a,ll b) {
        par[find(a)] = find(b);
    }

    bool same(ll a,ll b) {
        return find(a) == find(b);
    }

};

int main() {
    ll n,q;
    cin >> n >> q;
    union_find_tree uni(n);
    for(ll i=0;i<q;i++) {
        ll c,x,y;
        cin>>c>>x>>y;
        if(c==0) {
            uni.unite(x,y);
        }else {
            if(uni.same(x,y)) {
                cout << 1 << endl;
            }else {
                cout << 0 << endl;
            }
        }
    }
}



Measured memory_bytes: 3196
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric> 
#include <math.h>

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

int main()
{
    int h, w;
    cin >> h >> w;
    char a[h+2][w+2];
    REP(i, h+2){
        REP(j, w+2) {
            a[i][j] = '.';
        }
    }
    REP(i, h){
        REP(j, w) {
            cin >> a[i+1][j+1];
        }
    }
    bool flag = true;
    REP(i, h){
        REP(j, w) {
            if(a[i+1][j+1] == '#') {
                if(a[i+2][j+1] == '.' && a[i][j+1] == '.' && a[i+1][j+2] == '.' && a[i+1][j] == '.'){
                    flag = false;
                }
            }
        }
    }
    if(flag) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long int max(long long int n, double tmp[], long long int *num, double *M) {
	double max_memo = tmp[0];
	long long int max_num = 0;
	for (int i = 1; i < n; i++) {
		if (max_memo < tmp[i]) {
			max_memo = tmp[i];
			max_num = i;
		}
	}
	*num = max_num;
	*M = max_memo;
	return 0;
}

main() {
	int a,b,c,d,e,f;
	long long int k=0;
	int water[35];
	int sugar[3500];
	double s[300000] = {};
	double m;
  int check=0;
	long long int num,num2;
	scanf("%d%d%d%d%d%d", &a, &b,&c,&d,&e,&f);
  if(100*a==f){printf("%d 0",f);return 0;}
	for (int i = 0; i <= 30; i++) {
		for (int j = 0; j <= 30; j++) {
			if (a*i + b * j <= 30) {
				water[a*i + b * j]++;
			}
		}
	}

	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (c*i + d * j <= 3000) {
				sugar[c*i + d * j]++;
			}
		}
	}

	for (int i = 1; i <= 30; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (i*100+j<=f&&water[i]!=0&&sugar[j]!=0&&j<=e*i) {
				s[k] = (double)j / i;
              if(j!=0){check++;}
			}
			k++;
		}
	}
  if(check==0){printf("%d 0",100*a);return 0;}
	max(k, s, &num, &m);
	num2 = num % 3001;
	num /= 3001;
  num++;
	printf("%lld %lld", num*100+num2, num2);
}


Measured memory_bytes: 2560
use std::cmp::max;
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let h: Vec<i32> = (0..n).map(|_| read()).collect();

    let mut max_i = 0;
    let mut count = 0;
    for h in h.windows(2) {
        if h[0] >= h[1] {
            count += 1;
        } else {
            max_i = max(max_i, count);
            count = 0;
        }
    }
    max_i = max(count, max_i);

    println!("{}", max_i);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(A: int, B: int, C: int):
    ans = YES if A == B == C else NO
    print(ans)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    solve(A, B, C)

if __name__ == '__main__':
    main()


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

int main() {
	int n, p, q=0, i, j, k,
	box1[100][100] = {},
	box2[100] = {};
	cin >> n >> p;
	for (i = 0; i < n; i++) {
		for (j = 0; j < p; j++) {
			cin >> box1[i][j];
		}
	}
	for (k = 0; k < p; k++) {
		cin >> box2[k];
	}
	for (i = 0; i < n; i++) {
		for (j = 0; j < p; j++) {
			q += box1[i][j] * box2[j];
		}
		cout << q << "\n";
		q = 0;
	}
	
	return 0;
}


Measured memory_bytes: 3152
N, K, Q = map(int, input().split())
Ap = [0] * (N+1)
for q in range(Q):
    Ai = int(input())
    Ap[Ai] += 1
QmK = Q - K
for a in Ap[1:]:
    if a > QmK:
        print('Yes')
    else:
        print('No')


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

int main() {
  int N, K;
  cin >> N >> K;
  int R = 1; 
  for (int i = 0; i < N; i++) {
    if (R * 2 <= R + K) {
      R *= 2;
    }
    else {
      R += K;
    }
  }
  cout << R << endl;
}


Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    vi a(N), b(N), c(N);
    REP(i, N)
    {
        cin >> a[i] >> b[i] >> c[i];
    }
    vvi dp(N + 1, vi(3));
    REP(i, N)
    {
        dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i];
        dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i];
        dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i];
    }
    OUT(*max_element(ALL(dp[N])));
}

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

#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
int counter[4];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin >> s;
	forn(i,0,s.size()){
		if(s[i] == 'S')counter[0] = 1;
		else if(s[i] == 'N')counter[1] = 1;
		else if(s[i] == 'W')counter[2] = 1;
		else counter[3] = 1;
	}
	if(counter[0]+counter[1] == 1){
		cout << "No\n";
		return 0;
	}
	if(counter[2]+counter[3] == 1){
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
function main(input) {
  input = input.split('\n');
  var tmp = input[0].split(' ');

  var N = Number(tmp[0]);
  var A = Number(tmp[1]);

  var x = [0];
  x = x.concat(input[1].split(' ').map(Number));

  var dp = new Array(N + 1);
  for (var i = 0; i <= N; ++i) {
    dp[i] = new Array(N + 1);
    for (var j = 0; j <= N; ++j) {
      dp[i][j] = new Array(A * N + 1).fill(0);
    }
  }

  for (var i = 0; i < N; ++i) dp[i][0][0] = 1;

  for (var i = 1; i <= N; ++i) {
    for (var j = 1; j <= i; ++j) {
      for (var k = 1; k <= A * N; ++k) {
        if (k < x[i]) {
          dp[i][j][k] = dp[i - 1][j][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i]];
        }
      }
    }
  }

  var ans = 0;
  for (var j = 1; j <= N; ++j) {
    ans += dp[N][j][j * A];
  }

  console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 98352
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
struct UnionFind {
  UnionFind(int sz) : data(sz, -1) {}

  int root(int ver) { return data[ver] < 0 ? ver : data[ver] = root(data[ver]); }

  void unite(int ver1, int ver2) {
    ver1 = root(ver1);
    ver2 = root(ver2);
    if (ver1 != ver2) {
      if (data[ver1] < data[ver2]) {
        data[ver1] += data[ver2];
        data[ver2] = ver1;
      } else {
        data[ver2] += data[ver1];
        data[ver1] = ver2;
      }
    }
  }

  bool same(int ver1, int ver2) { return root(ver1) == root(ver2); }

  int size(int ver) { return -data[root(ver)]; }

private:
  vector<int> data;
};

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n, k, l; cin >> n >> k >> l;
  UnionFind load(n);
  REP(i, k) {
    int p, q; cin >> p >> q;
    --p;
    --q;
    load.unite(p, q);
  }
  UnionFind rail(n);
  REP(i, l) {
    int r, s; cin >> r >> s;
    --r;
    --s;
    rail.unite(r, s);
  }
  vector<pair<pair<int, int>, int>> ro(n);
  REP(i, n) ro[i] = {{load.root(i), rail.root(i)}, i};
  sort(ALL(ro));
  vector<int> ans(n);
  int sum = 1;
  vector<int> vec(1, ro[0].second);
  auto now = ro[0].first;
  FOR(i, 1, n) {
    if (now == ro[i].first) {
      ++sum;
      vec.push_back(ro[i].second);
    } else {
      for (int v : vec) ans[v] = sum;
      now = ro[i].first;
      sum = 1;
      vec.resize(0);
      vec.push_back(ro[i].second);
    }
    if (i == n-1) {
      for (int v : vec) ans[v] = sum;
    }
  }
  REP(i, n) {
    cout << ans[i];
    if (i == n-1) cout << '\n';
    else cout << ' ';
  }
  return 0;
}


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



int main() {
    int N;

    bool isPrime[10001];
    for (int i = 0; i < 10001; i++) isPrime[i] = 1;
    isPrime[0] = isPrime[1] = 0;
    for (int i = 0; i < 10001; i++) {
        if (!isPrime[i]) continue;
        for (int j = 2; j * i < 10001; j++) {
            isPrime[i*j] = 0;
        }
    }

    vector<int> prime;
    prime.push_back(0);
    for (int i = 0; i < 10001; i++) if (isPrime[i]) prime.push_back(i);
    for (int i = 1; i < prime.size(); i++) prime[i] += prime[i-1];
    
    while (cin >> N, N) {
        int ans = 0;
        int i = 0, j = 0;
        while (i < prime.size() && j < prime.size()) {
            int sub = prime[j] - prime[i];
            if (sub < N) j++;
            else if (sub >= N) {
                i++;
                if (sub == N) ans++;
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

int main()
{
    string s,t,u;
    cin>>s>>t;
    ll a,b;
    cin>>a>>b;
    cin>>u;
    if(u==s) --a;
    else --b;
    cout<<a<<" "<<b<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=200010;
typedef long long LL;
map<LL,LL>ans;
LL n;

LL dfs(LL x){
	if(x==1)return 1;
	if(ans[x])return ans[x];
	ans[x]=1+2*dfs(x/2);
	return ans[x];
}

int main(){
#ifdef WK
	//freopen("in.txt","r",stdin);
#endif
	scanf("%lld",&n);
	printf("%lld\n",dfs(n));
    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

struct MaxSegmentTree{
  int size_;
  int length_;
  vector<ll> data_;
  umap<int, int> par_info_;
  umap<int, pair<int, int>> chil_info_;
  
  MaxSegmentTree(int size)
    :size_(CalcSize(size)), length_((size_+1)/2), data_(size_, 0)
  { Init(); }
  
  int CalcSize(int size)
  { int n = 1; while(n < size)n *= 2; return 2 * n - 1; }
  void Init(){
    for(int i = (size_/2)-1; i >= 0; --i){
      int l = i*2 + 1, r = i*2 + 2;
      par_info_[l] = i;
      par_info_[r] = i;
      chil_info_[i] = {l,r};
    }
  }
  
  void Set(int idx, ll x){
    int pos = (size_/2)+idx;
    data_[pos] = x;
    while(pos != 0){
      pos = par_info_[pos];
      ll l, r;tie(l, r) = chil_info_[pos];
      data_[pos] = data_[l]|data_[r];
    }
  }
  
  ll GetMax(int target_l, int target_r, int idx = 0,
	    int range_l = 0, int range_r = -1){
    if(range_r == -1){
      range_r = length_;
      if(target_l > target_r || target_l < 0 || target_r > length_){
	cerr << "SegmentTree GetMin target index error\n";
	cerr << "target_l:" << target_l << " target_r:" << target_r << endl;
	return -(1e+18);
      }
    }
    
    if(target_r <= range_l || target_l >= range_r) return 0;
    if(target_r >= range_r && target_l <= range_l) return data_[idx];
    
    int l, r; tie(l, r) = chil_info_[idx];
    int mid = (range_l + range_r)/2;
    
    ll val_l = GetMax(target_l, target_r, l, range_l, mid);
    ll val_r = GetMax(target_l, target_r, r, mid, range_r);
    
    return val_l|val_r;
  }  
};

int main(){
  int n; cin >> n;
  string s; cin >> s;
  int q; cin >> q;
  MaxSegmentTree seg(n);
  for(int i = 0; i < n; ++i){
    seg.Set(i,1<<(s[i]-'a'));    
  }

  // cerr << endl;
  // for(int i = 0; i < seg.size_; ++i){
  //   cerr << i << ' ' << bitset<32>(seg.data_[i]) << endl;
  // }
  
  for(int i = 0; i < q; ++i){
    int a,b; cin >> a >> b;
    if(a == 1){
      char c; cin >> c;
      seg.Set(b-1,1<<(c-'a'));
    }
    else{      
      int c; cin >> c;
      b--;
      // debug(seg.GetMax(b,c));
      cout << bitset<64>(seg.GetMax(b, c)).count() << endl;
      // cout << __builtin_popcount(seg.GetMax(b, c)) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 78320
import java.util.Scanner;

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

		int n = kb.nextInt();
		int i = 1;
		do {
			int x=i;
			
			if( 0 == x%3 ) {
				System.out.print( " "+i );
			} else {
				do {
					if( 3 == x%10 ) {
						System.out.print( " "+i );
						break;
					}
					x /= 10;
				} while( 0!=x );
			}
			
		} while ( ++i <= n );
		
		System.out.print( "\n" );
	}
}

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

int main(){
  string s;
  cin >> s;
  bool a = s[0] == 'R';
  bool b = s[1] == 'R';
  bool c = s[2] == 'R';
  if(a and b and c){
    cout << 3;
  }
  else if((a and b) or (b and c)){
    cout << 2;
  }
  else if(a or b or c){
cout << 1;
  }
  else{
cout << 0;
  }
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
    詰まった時に、別の分野の問題として考え直す（これdpでは？、グラフとしてみればいいのでは？）
    多くの問題はパターンマッチだが、パターンに落とし込むまでが難しく、そのための訓練としてわからない問題をあれこれ色々な角度から考察してみるのではないか
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;

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

    int n,k; cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; ++i) cin >> a[i];

    // dp[i] := 石の個数がi個で手番が回ってきたら勝てる？
    vector<bool> dp(200005, false);
    for(int i=1; i<=k; ++i){
        for(int j=0; j<n; ++j) if(i-a[j]>=0 && dp[i-a[j]] == 0) dp[i]=1;
    }

    if(dp[k] == true) cout << "First" << endl;
    else cout << "Second" << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
ABC = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[-1, -1, -1] for _ in range(N)]
dp[0] = ABC[0]
i = 1
for a, b, c in ABC[1:]:
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a 
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + b 
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c 
    i += 1
print(max(dp[N-1]))


Measured memory_bytes: 79320
#include<iostream>
using namespace std;
int main() {
	int l[110], n; cin >> n;
	for (int i = 0; i < n; i++){
		cin >> l[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++){
		int minj = i;
		for (int j = i; j < n; j++) {
			if (l[j] < l[minj])minj = j;
		}
		if (i != minj){
			int tmp = l[i];
			l[i] = l[minj];
			l[minj] = tmp;
			sum++;
		}
	}
	for (int i = 0; i < n; i++){
		cout << l[i];
		if (i != n - 1)cout << ' ';
		else cout << endl << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
using namespace std;

int main(void) {
    int n;
    cin >> n;
    // string s;
    for (int i = 0; i < n; i++)
    {   
        string s;
        cin >> s;
        if (s == "Y") {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin>>n>>s;
  int count=0;
  for(int i=0;i<n-2;i++){
    if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
        count++;
    }
  }
  cout<<count<<endl;
  
}

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

const int N = 100001;
const long long Pmax = 10000 * N;
int w[N];
int n, k;

int check(int mid) {
    int tmp = 0, cnt = 1;
    for (int i = 0; i < n; i++) {
        if (tmp + w[i] > mid) {
            tmp = w[i];
            cnt++;
        } else {
            tmp += w[i];
        }
    }
    return cnt;
}
int binaryP (int Max) {
    int left = Max;
    int right = Pmax;
    int mid;
    int a = (left + right) / 2, b = right, c = left;
    while (right - left > 0) {
        a = mid;
        mid = (left + right) / 2;
        int v = check(mid); //最大積載量P = mid のとき何台
        //cout<< "v = " << v << endl;
        b = right; c = left;
        if (v <= k) right = mid;
        else left = mid;
        //cout << left << " " << mid << " " << right << endl;
        //cout << c << " " << a << " " << b << endl;
        if (a == mid && b == right && c == left) break;
    }
    return right;
}
int main() {
    cin >> n >> k;
    int Max = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        Max = (w[i] > Max) ? w[i] : Max;
    }
    cout << binaryP(Max) << endl;
    return 0;
}



Measured memory_bytes: 3488
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    ll n = s.size();
    REP(i, n) cout << "x";
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

def input():
    return sys.stdin.readline()[:-1]

def main():
    n,m = map(int,input().split())
    k = []
    s = []
    ans = 0
    
    for _ in range(m):
        tmp = [int(i) for i in input().split()]
        k.append(tmp.pop(0))
        s.append(tmp)

    p = [int(i) for i in input().split()]

    for i in range(2**n):
        tentou=[0]*m
        b = bin(i)[2:].zfill(n)
        for i2 in range(len(s)):
            for i3 in s[i2]:
                if b[i3-1] == "1":
                    tentou[i2]+=1
        tentou = [z % 2 for z in tentou]
        if tentou == p:
            ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 42092
num_of_switch,num_of_denkyu = map(int,input().split())
denkyu_switch = []
for denkyu in range(num_of_denkyu):
    denkyu_switch.append(list(map(lambda x:int(x)-1,input().split())))
    del denkyu_switch[denkyu][0]
surplus = list(map(int,input().split()))


ans=0
for i in range(2**num_of_switch):
    denkyu_on_off=[False for _ in range(num_of_denkyu)]
    switch_on_off = list(map(int,list(str(bin(i)).replace("0b","").zfill(num_of_switch))))


    for denkyu in range(len(denkyu_switch)):
        count=0
        for switch in range(len(denkyu_switch[denkyu])):
            
            if switch_on_off[denkyu_switch[denkyu][switch]]==1:
                count += 1
        
        if count%2 == surplus[denkyu]:
            denkyu_on_off[denkyu]=True
        else:break

    if False not in denkyu_on_off:
        ans+=1
print(ans)

"""
5 3
1 3
2 1 2
1 3
0 0 1
"""

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll a, b, c;
    cin >> a >> b >> c;

    if(4 * a * b < powk(c - a - b) && c - a - b > 0){
        cout << "Yes";
    }
    else{
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

a = list(input())


al = set()

dp = [[[0 for k in range(10)] for i in range(10)] for j in range(10)]


kkk = [[0 for j in range(10)]for i in range(n)]
count = 0
for i in range(n):
    k = int(a[i])
    if i == 0:
        kkk[i][k] += 1
    else:
        for j in range(10):
            if k == j:
                kkk[i][j] += kkk[i-1][j] + 1
            else:
                kkk[i][j] += kkk[i-1][j]

for i in range(1,n-1):
    e = int(a[i])
    ae = []
    for pl in range(10):
        if kkk[i-1][pl] > 0:
            ae.append(pl)
    for pl in range(10):
        if kkk[-1][pl] - kkk[i][pl] > 0:
            for pp in ae:
                if not dp[pp][e][pl]:
                    count += 1
                    dp[pp][e][pl] += 1
                    


print(count)


Measured memory_bytes: 56540
N = int(input()) # 数字を変数に格納
List = list(map(int,input().split())) # 複数の数字をリストに格納

total = 1
sum = 0

for i in range(N):
    total = total * List[i]

l = []
for i in range(N):
    l.append(total / List[i])
    
for i in range(N):
    sum = sum + l[i]
    
result = total / sum

print(result)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

template<typename T> void chmax(T &a, T b) { a = std::max(a, b); }
template<typename T> void chmin(T &a, T b) { a = std::min(a, b); }
template<typename T> void chadd(T &a, T b) { a = a + b; }

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n - 1);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n - 1) cin >> c[i];

	int ans = 0;

	rep(i, n) {
		ans += b[i];
	}
	rep(i, n - 1) {
		if (a[i] == a[i + 1] - 1) {
			ans += c[a[i] - 1];
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
#define all(in) in.begin(),in.end()
using namespace std;
int main(){
int n,m;
while(cin>>n>>m,n||m){
vector<int>a,b;
int tmp;
int suma=0,sumb=0;
rep(i,n){
cin>>tmp;
pb(a,tmp);
suma+=tmp;
}
rep(i,m){
cin>>tmp;
pb(b,tmp);
sumb+=tmp;
}

int min=9999,mini[2]={0};
rep(i,n){
rep(j,m){
if(suma-a[i]+b[j]==sumb+a[i]-b[j]&&min>suma-a[i]+b[j]){
min=suma-a[i]+b[j];
mini[0]=a[i];
mini[1]=b[j];
}
}
}
if(min!=9999)cout<<mini[0]<<" "<<mini[1]<<endl;
else cout<<-1<<endl;
}
}

Measured memory_bytes: 1220
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((caph (read))
         (capw (read))
         (h (read))
         (w (read)))
    (println (+ (- (* caph capw)
                   (* h capw)
                   (* w caph))
                (* h w)))))

#-swank(main)



Measured memory_bytes: 15076
#define __USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

struct Point {
    double x, y;
};

void print(Point a) {
    cout << fixed << setprecision(8) << a.x << " " << a.y << endl;
}

void koch(int n, Point a, Point b) {
    if (n == 0) return;

    Point s, t, u;
    double r = 60.0 / 180.0 * M_PI;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = s.x + (t.x - s.x) * cos(r) - (t.y - s.y) * sin(r);
    u.y = s.y + (t.x - s.x) * sin(r) + (t.y - s.y) * cos(r);

    koch(n - 1, a, s);
    print(s);
    koch(n - 1, s, u);
    print(u);
    koch(n - 1, u, t);
    print(t);
    koch(n - 1, t, b);
}

int main() {
    Point a, b;
    int n;
    cin >> n;

    a.x = 0.0;
    a.y = 0.0;
    b.x = 100.0;
    b.y = 0.0;

    print(a);
    koch(n, a, b);
    print(b);

    return 0;
}


Measured memory_bytes: 3220
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val a, b = sc.nextInt()
    val aS = a.toString * b
    val bS = b.toString * a
    println(if (aS < bS) aS else bS)
  }

}


Measured memory_bytes: 26040
#include<bits/stdc++.h> 
using namespace std;
#define X first
#define Y second
#define pii pair<int,int>
#define rep(i,a,b) for (int i=a;i<=b;++i)
int n,res,l[1005],vis[1005];char d[1005];
vector<pii>V;
int main()
{
	scanf("%d",&n);
	rep(i,0,n-1)
	{
		scanf("\n%c %d",&d[i],&l[i]);
		if(d[i]=='y')V.push_back(make_pair(l[i],i));
	}
	sort(V.begin(),V.end());
	for(auto v:V)
	{
		if(vis[v.Y])continue;
		vis[v.Y]=1;res++;
		for(int i=v.Y-1;i>=0;i--)
		{
			if(d[i]=='n'&&v.X<=l[i])break;
			vis[i]=1;
		}
		for(int i=v.Y+1;i<n;i++)
		{
			if(d[i]=='n'&&v.X<=l[i])break;
			vis[i]=1;
		}
	}
	printf("%d\n",res);
	return 0;
}


Measured memory_bytes: 3244
#include <cstdio>


int main() {
    char buf[20];
    char cf[] = "CODEFESTIVAL2016";
    int ans = 0;
    scanf("%s", buf);
    for (int i = 0; i < 16; ++i) {
        if (buf[i] != cf[i]) ++ans;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
    int R;
    while (cin >> R){
        if(R < 1200)  cout << "ABC" << endl;
        else if(R < 2800)   cout << "ARC" << endl;
        else  cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
m=1
a=[]
while n>26:
  n,mod=divmod(n,26)
  if mod==0:
    mod==26
    n-=1
  a.append(mod)
  m+=1
a.append(n)
s="abcdefghijklmnopqrstuvwxyz"
ans=""
for i in range(m-1,-1,-1):
  ans+=s[a[i]-1]
print(ans)

Measured memory_bytes: 9128
oni_x, oni_speed = map(int, input().split())
chi_x, chi_speed = map(int, input().split())
time = int(input())
ans = False


if oni_speed > chi_speed:
    sa = abs(oni_x - chi_x)
    sa_speed = oni_speed - chi_speed
    if sa_speed*time >= sa:
        ans = True

if ans:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9184
#include <iostream>
#include <string>
#include <stack>
#include <algorithm>

using namespace std;

int main() {
  string str;
  cin >> str;

  stack<char> ans;

  for (int i = 0; i < str.size(); i++) {
    switch (str[i]) {
    case 'B': {
      if (!ans.empty()) {
        ans.pop();
      }
      break;
    }
    case '0': {
      ans.push('0');
      break;
    }
    case '1': {
      ans.push('1');
      break;
    }
    }
  }

  string an;
  while (!ans.empty()) {
    an += ans.top(); ans.pop();
  }
  reverse(an.begin(), an.end());
  cout << an << endl;
  return 0;
}


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

int main(){
	int n, m;
	while(std::cin >> n >> m){
		//n及びmが0ならば終了
		if(n == 0 && m == 0){
			return 0;
		}
		
		std::vector<int> p(n);
		for(int i = 0; i < n; ++i){
			std::cin >> p[i];
		}
		
		std::sort(p.begin(), p.end(), std::greater<int>());
		//(mの倍数) 個目の商品が無料
		for(int i = m; i <= n; i += m){
			p[i-1] = 0;
		}
		
		std::cout << std::accumulate(p.begin(), p.end(), 0) << std::endl;
	}
	
	return 0;
}

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

int maxHappiness(vector<vector<int>> &happiness,vector<vector<int>> &dp, int days, int activity){
   if(dp[days][activity] !=-1){
      return dp[days][activity];
   }
    if(days == 0){
        dp[days][activity] = happiness[0][activity];
        return happiness[0][activity];
    }
    int maxPast = INT_MIN;
    for(int i=0;i <3; i++){
        if(i != activity){
            maxPast = max(maxHappiness(happiness,dp,days -1, i), maxPast);
        }
    }
    dp[days][activity] = happiness[days][activity] + maxPast;
    return dp[days][activity];
}
int main(){
    int n;
    cin>>n;
    vector<vector<int>> happiness(n, vector<int>(3));
    vector<vector<int>> dp(n, vector<int>(3, -1));
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++){
            cin>>happiness[i][j];
}
    }
    
    int ans = INT_MIN;
    for(int i=0; i<3; i++){
        int x = maxHappiness(happiness, dp, n-1, i);
        ans = max(ans, x);
}
cout<<ans<<endl;
return 0;
}







Measured memory_bytes: 21884
import numpy as np
def main():
    h, w = map(int, input().split())
    s = np.array([list(input()) for _ in range(h)])
    t = np.zeros((h+2, w+2))
    t[1:-1, 1:-1][s == "."] = 1
    row = np.zeros((h+2, w+2))
    col = np.zeros((w+2, h+2))
    for i in range(1, h+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        row[i, idx[:-1]+1] += dif-1
        row[i, idx[1:]] -= dif-1
        row[i] = np.cumsum(row[i])
    t = t.T
    for i in range(1, w+1):
        idx = np.where(t[i] == 0)[0]
        dif = np.diff(idx)
        col[i, idx[:-1]] += dif-2
        col[i, idx[1:]] -= dif-2
        col[i] = np.cumsum(col[i])
    col = col.T
    cost = np.add(row, col)
    print(int(np.max(cost)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 176196
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() { int a, b, c,d;
  cin >> a >> b >> c >> d;
  while (b <= a) {
    b *= 2;
    d--;
  }
  while (c <= b) {
    c *= 2;
    d--;
  }
  if (d < 0) {
    cout << "No";
  } else {
    cout << "Yes";
  }
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の
string型配列と同じような感じ） map<int, string> mp; for (auto itr =mp.begin();
itr != mp.end(); itr++) {
    //順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3608
N,Y=map(int,input().split())
x,y,z=-1,-1,-1
for i in range(N+1):
    for j in range(N+1-i):
        k=N-i-j
        if Y==i*10000+5000*j+1000*k:
            print(i," ",j," ",k)
            quit()
print(x," ",y," ",z)


Measured memory_bytes: 41324
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define um unordered_map
#define fi first
#define se second

int main()
{   
   fast;
    
    ll n; cin>>n;
    ll arr[n], dp[n];
    
    for(ll i=0; i<n; i++)
    {
        cin>>arr[i];
        
        if(i==0)
            dp[i]=0;
        else if(i==1)
            dp[i]=abs(arr[i]-arr[i-1]);
        else
            dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
    }
    
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 5112
#include<iostream>
using namespace std;
int main() {
	int a = 1;
	cin >> a;
	for (int i = 1; i <= 10000; i++)
	{
		if (a==0)
		{
			return 0;
		}
		else
		{
			cout << "Case" << " " << i << ":" << " " << a << endl;
			cin >> a;
		}
	}
	return 0;
}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }

    int ans = numeric_limits<int>::max();
    for (int i = 0; i < N; i++) {
        int mi = A[i];
        

        priority_queue<int, vector<int>, greater<int>> Que;

        int pre_j = -1;
        for (int j = 0; j < N; j++) {
            if (A[j] < mi) {
                if (j - pre_j != 1) {
                    int l = j - pre_j - 1;
                    priority_queue<int, vector<int>, greater<int>> temp;
                    for(int k = pre_j + 1; k < j; k++) {
                        temp.push(A[k]);
                    }
                    for (int k = 0; k < l - K + 1; k++) {
                        Que.push(temp.top()); temp.pop();
                    }
                }
                pre_j = j;
            }
        }
        if (N - pre_j != 1) {
            int l = N - pre_j - 1;
            priority_queue<int, vector<int>, greater<int>> temp;
            for(int k = pre_j + 1; k < N; k++) {
                temp.push(A[k]);
            }
            for (int k = 0; k < l - K + 1; k++) {
                Que.push(temp.top()); temp.pop();
            }
        }

        if (Que.size() < Q) continue;
        if (Que.top() != mi) continue;
        for (int i = 0; i < Q - 1; i++) {
            Que.pop();
        }
        int ma = Que.top(); Que.pop();
        ans = min(ans, ma - mi);
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

    int ttc = c/b;
    if (c%b) {ttc++;}

    int atc = a/d;
    if (a%d) {atc++;}

    if (ttc <= atc)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 3592