akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
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) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    if(n % 2 == 0) cout << n / 2 << endl;
    else cout << n / 2 + 1 << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0]*n
res = 0
tmp = 0
zero = False
for i in range(n):
    s = int(input())
    a[i] = s
    if s==0:
        zero = True
if not zero:
    print(sum(a)//2)
    exit()

for i in range(n):
    if a[i]!=0:
        tmp+=a[i]
    else:
        res+=tmp//2
        tmp = 0
    if i==n-1 and tmp>1:
        res+=tmp//2
print(res)


Measured memory_bytes: 6900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int n,q;
    string s;
    cin >> n >> q >> s;
    vector<pair<char,char>> v(q);//呪文を格納
    int l=-1,r=s.size(),lb=l,rb=r;//lbは左に落ちるゴレムのうち最も右にあるやつ(left border)
    for(int i=0;i < v.size();i++){
        cin >> v.at(i).first >> v.at(i).second;
    }

    reverse(v.begin(),v.end());//逆から実行して、どこまで行くか調べればok(追い越さないので)

    //何回も書くvの要素は置換しておく

    for(int j=0;j < v.size();j++){
        
        if(v.at(j).second == 'R'){
            if(r-1 >= 0 && v.at(j).first==s.at(r-1)){
                r--;
            }
            if(l>=0 && v.at(j).first==s.at(l)){
                l--;//すでにいなかったら一つ戻る
            }
        }else{//Lの時
            if(r < s.size() && v.at(j).first==s.at(r)){
                r++;//既にいない場合
            }
            if(l+1<s.size() && v.at(j).first==s.at(l+1)){
                l++;
            }   
        }
    }
    
        cout << r-l-1 << endl;
}


Measured memory_bytes: 1028
/*
** 二叉搜索树的插入
** 中序和前序输出
*/

# include <cstdio>
# include <cstdlib>
# include <cstddef>

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root;

void inorder(Node *u) {
    if (u == NULL)
        return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}

void preorder(Node *u) {
    if (u == NULL)
        return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

void insertNode(int k) {
    Node *y = NULL;
    Node *x = root;

    Node *z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NULL;
    z->right = NULL;

    while (x != NULL) {
        y = x;
        if (z->key < x->key)
            x = x->left;
        else
            x = x->right;
    }

    z->parent = y;

    if (y == NULL)
        root = z;
    else if (z->key < y->key)
        y->left = z;
    else
        y->right = z;
}

bool findNode(int k) {
    Node *x = root;
    while (x != NULL) {
        if (k == x->key)
            return true;
        if (k < x->key)
            x = x->left;
        else
            x = x->right;
    }
    return false;
}

Node * findKey(int key) {
    Node *u = root;
    while (u != NULL && key != u->key) {
        if (key < u->key) {
            u = u->left;
        }
        else {
            u = u->right;
        }
    }
    return u;
}

Node * getMinimum(Node *u) {
    while (u->left != NULL) {
        u = u->left;
    }
    return u;
}

Node * getSuccessor(Node *u) {
    if (u->right != NULL)
        return getMinimum(u->right);

    Node *y = u->parent;
    while (y != NULL && u == y->right) {
        u = y;
        y = y->parent;
    }
    return y;
}

void deleteNode(Node *u) {
    Node *y = NULL;
    Node *x = NULL;

    if (u->left == NULL || u->right == NULL) {
        y = u;
    }
    else {
        y = getSuccessor(u);
    }

    if (y->left != NULL) {
        x = y->left;
    }
    else
    {
        x = y->right;
    }

    if (x != NULL) {
        x->parent = y->parent;
    }

    if (y->parent == NULL) {
        root = x;
    }
    else if (y == (y->parent)->left) {
        (y->parent)->left = x;
    }
    else {
        (y->parent)->right = x;
    }

    if (y != u) {
        u->key = y->key;
    }

    free(y);
}

void solve() {
    int n, x;
    char com[10];

    root = NULL;

    scanf("%d", &n);    
    for (int i = 0; i < n; i++) {
        scanf("%s", com);
        if (com[0] == 'i') {
            scanf("%d", &x);
            insertNode(x);
        }
        else if (com[0] == 'f') {
            scanf("%d", &x);
            if (findNode(x))
                printf("yes\n");
            else
                printf("no\n");
        }
        else if (com[0] == 'd') {
            scanf("%d", &x);
            deleteNode(findKey(x));
        }
        else {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);
    solve();
    return 0;
}


Measured memory_bytes: 21332
#include<bits/stdc++.h>
using namespace std;
int main(){
int A,B,C,D;
cin >> A >> B>> C >> D;
  if(A+B>C+D){
  cout << "Left" << endl;
  }else if(A+B == C+D){
  cout << "Balanced" <<endl;
  }else{
  cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)
k = int(stdin.readline().rstrip())
a,b = map(int,stdin.readline().rstrip().split())

for i in range(a,b+1):
    if i%k == 0:
        print("OK")
        exit()
print("NG")

Measured memory_bytes: 9176
// Problem : B - ... (Triple Dots)
// Contest : AtCoder - AtCoder Beginner Contest 168
// URL : https://atcoder.jp/contests/abc168/tasks/abc168_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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



Measured memory_bytes: 3624
//by Top1
#include <bits/stdc++.h>
          
#define f first
#define s second
#define int long long
#define ld long double
#define ull unsigned long long
#define pii pair <int, int>
#define pll pair <long, long>
#define mp make_pair
#define pb push_back
#define pf push_front
#define pp pop_back
#define cerr cout
#define rev reverse
#define all(s) s.begin(), s.end()
#define sz(s) (int)s.size()
#define forn(i, a, b) for (int i = a; i <= b; i++)
#define boost ios_base::sync_with_stdio(false); cin.tie(0),cout.tie(0);
#define nxtp next_permutation
#define pvtp prev_permutation
#define KZ return 
#define x1 x21212121
#define y1 y21212121
#define sqr(x) x * x 
      
const int inf = (1e18) + 1;
const int mod = 1e9 + 7;
const int maxn = 5e5 + 111;
        
using namespace std;          

int n, k, ans, a[maxn];
bool was[maxn];

int binpow(int x, int y){
	if (y == 0)
		return 1;
	if (y % 2 == 1)
		return binpow(x, y - 1) * x % mod;
	else{
		int z = binpow(x, y / 2) % mod;
		return (z * z) % mod;
	}
}

void solve(){
	cin >> n >> k;
      
	for (int i = k; i >= 1; i--){
		int x = binpow(k / i, n) % mod;
		a[i] = x;
		for (int j = 2; j * i <= k; j++){
			a[i] = (a[i] % mod - a[j * i] % mod + mod) % mod;
		}
	}

	for (int i = 1; i <= k; i++){
		ans = ans + a[i] * i;
		ans %= mod;
	}

	cout << ans;
}                              
      
main(){
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

    boost;
    
    int q = 1;
 
    //cin >> q;
    
    while (q--){
        solve();
    }
}

Measured memory_bytes: 4424
import java.io.*;
import java.util.*;

class FastReader 
{ 
    BufferedReader br; 
    StringTokenizer st; 
    
    public FastReader() 
    { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    
    String next() 
    { 
        while (st == null || !st.hasMoreElements()) 
        { 
            try
            { 
                st = new StringTokenizer(br.readLine()); 
            } 
            catch (IOException  e) 
            { 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    
    int nextInt() 
    { 
        return Integer.parseInt(next()); 
    } 
    
    long nextLong() 
    { 
        return Long.parseLong(next()); 
    } 
    
    double nextDouble() 
    { 
        return Double.parseDouble(next()); 
    } 
    
    String nextLine() 
    { 
          String str = ""; 
        try
        { 
            str = br.readLine(); 
        } 
        catch (IOException e) 
        { 
            e.printStackTrace(); 
        } 
        return str; 
    } 
} 

class Solution
{
    void solve()
    {
        FastReader sc = new FastReader();

        String S = sc.next();

        if(S.equals("MON"))
            System.out.println(6);

        if(S.equals("TUE"))
            System.out.println(5);

        if(S.equals("WED"))
            System.out.println(4);

        if(S.equals("THU"))
            System.out.println(3);

        if(S.equals("FRI"))
            System.out.println(2);

        if(S.equals("SAT"))
            System.out.println(1);

        if(S.equals("SUN"))
            System.out.println(7);
    }
}
  
public class Main 
{ 
    public static void main(String[] args) 
    { 
        Solution ob = new Solution();

        ob.solve();
    } 
} 

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

template <typename T>
struct Dijkstra {
  struct Edge {
    int to;
    T cost;
  };
  vector<int> prev;
  vector<vector<Edge>> g;
  Dijkstra(int n) : prev(n, -1), g(n) {}

  void addEdge(int u, int v, T w) {
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  vector<T> build(int s) {
    vector<T> dist(g.size(), -1);
    using Node = pair<T, int>;
    priority_queue<Node, vector<Node>, greater<Node>> pq;
    pq.push({dist[s] = 0, s});

    while (!pq.empty()) {
      auto d = pq.top().first;
      auto u = pq.top().second;
      pq.pop();
      if (dist[u] < d) continue;
      for (auto&& v : g[u]) {
        if (dist[v.to] < 0 || dist[v.to] > dist[u] + v.cost) {
          dist[v.to] = dist[u] + v.cost;
          prev[v.to] = u;
          pq.push({dist[v.to], v.to});
        }
      }
    }
    return dist;
  }
  vector<int> getPath(int t) {
    vector<int> path;
    for (; t != -1; t = prev[t]) path.push_back(t);
    reverse(begin(path), end(path));
    return path;
  }
};

int main() {
  int xs, ys, xt, yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  vector<int> x(n + 2), y(n + 2), r(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> x[i] >> y[i] >> r[i];
  }
  int s = n;
  x[s] = xs;
  y[s] = ys;
  r[s] = 0;
  int t = n + 1;
  x[t] = xt;
  y[t] = yt;
  r[t] = 0;
  Dijkstra<double> g(n + 2);
  for (int i = 0; i < n + 2; i++) {
    for (int j = i + 1; j < n + 2; j++) {
      double d = hypot(abs(x[i] - x[j]), abs(y[i] - y[j])) - (r[i] + r[j]);
      if (d < 0) d = 0;
      g.addEdge(i, j, d);
    }
  }
  auto ans = g.build(s);
  cout << setprecision(10) << fixed;
  cout << ans[t] << endl;
}


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

const int MAXN = 3003;
double ans[MAXN][MAXN];
double p[MAXN];

int main () {
	// input
	int n;
	cin >> n;
	for (int i = 0; i < n; i ++)
		cin >> p[i];
	// starting points
	ans[0][0] = 1 - p[0]; // avali mishe element, dovomi mishe tedad
	ans[0][1] = p[0];
	// calculation
	for (int i = 1; i < n; i ++) // tossing each coin
		for (int j = 0; j <= i + 1; j ++) { // in wich line it will endup
			ans[i][j] += (1 - p[i]) * ans[i - 1][j];
			if (j > 0)
				ans[i][j] += p[i] * ans[i - 1][j - 1];
		}
	int start = n / 2 + 1;
	double answer = 0;
	for (int i = start; i <= n; i ++)
		answer += ans[n - 1][i];
	if (n >= 5) {
		cout << setprecision(10) << fixed << answer << endl;
		return 0;
	}
	cout << answer << endl;
	return 0; 
}


Measured memory_bytes: 49868
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m;cin>>n>>m;
  vector<int> city(n+1);
  int temp=0;
  for(int i=0;i<2*m;i++){
  	cin>>temp;
    city[temp]++;
  }
  for(int i=0;i<n;i++){
  	cout<<city[i+1]<<endl;
  }
  
}


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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

int main()
{
    _fastio
    ll n,k,mx;
    cin>>n>>k;
    ll ar[200005];
    for1(i,n)
        cin>>ar[i];
    /*ll sm=1;
    for(ll i=1;i<=k;i++)
    {
        sm*=ar[i];
    }
    mx=sm;*/
    for(ll i=2;i<=(n-k+1);i++)
    {
        /*sm=mx;
        sm/=ar[i-1];
        sm*=ar[i+k-1];
        //cout<<sm<<en;*/
        if(ar[i-1]<ar[i+k-1])
        {
            //mx=sm;
            cout<<"Yes"<<en;
        }
        else
        {
            //mx=sm;
            cout<<"No"<<en;
        }
    }
}


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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D; 

  if (A + B > C + D) {
    cout << "Left" << endl;
  }  
  else if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()

  println(abc068b(n))
}

private fun abc068b(n: Int): Int {
  var tmp = 1
  while (tmp <= n) {
    tmp *= 2
  }

  return tmp / 2
}


Measured memory_bytes: 31392
#include <algorithm>
#include <iostream> //標準入出力
#include <fstream>  //ファイルでの入出力
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <utility> //pair
#include <cmath>  //sqrt 
#include <iomanip> //setprecision
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define MAX 1000000
#define pair(a) pair<a,a>

int bfs(vector<string>& field,int fb){
    int h=field.size(),w=field[0].size();
    vector<vector<int>> dfroms(h,vector<int>(w,-1));
    queue<pair(int)> later;
    const int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0}; //東西南北の順

    later.push({0,0});
    dfroms[0][0] = 1;

    while(!later.empty()){
        pair(int) now = later.front();
        int x = now.first, y = now.second;
        later.pop();
        rep(i,4){
            pair(int) next = {x+dx[i],y+dy[i]};
            int nx = next.first,ny = next.second;
            if(nx<0||nx>=h||ny<0||ny>w) continue;
            if(field[nx][ny]=='#') continue;
            if(dfroms[nx][ny]!=-1) continue;
            dfroms[nx][ny] = dfroms[x][y] + 1;
            later.push(next);
        }
    }
    int out = h*w - dfroms[h-1][w-1] - fb;
    if(dfroms[h-1][w-1] == -1) return -1;
    else return out;
}

void _main(){
    int h,w;
    cin >> h >> w;
    vector<string> field; 
    field.resize(h);
    rep(i,h) cin >> field[i];
    int firstblack = 0;
    rep(i,h) rep(j,w) if(field[i][j]=='#') firstblack++;
    cout << bfs(field,firstblack) << endl;
    
    return;
}
int main() {
    cout << fixed << setprecision(10);
    _main();
    return 0;
}
    

Measured memory_bytes: 3200
def main():
    n, a, b = map(int, raw_input().split())
    if a < b:
        a, b = b, a
    if (a - b) % 2 == 0:
        print (a - b) / 2
        return
    print min(b - 1, n - a) + (a - b - 1) / 2 + 1

main()


Measured memory_bytes: 27884
def solve():
    H,N = map(int,input().split())
    attack = []
    mp = []
    for i in range(N):
        a,b = map(int,input().split())
        attack.append(a)
        mp.append(b)
    
    max_attack = max(attack)
    dp = [[float('inf')] * (H+max_attack) for _ in range(N+1)]

    for i in range(N+1):
        dp[i][0] = 0
    
    for i in range(N):
        for j in range(H+max_attack):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if j - attack[i] >= 0:
                dp[i+1][j] = min(dp[i+1][j], dp[i][j-attack[i]]+mp[i], dp[i+1][j-attack[i]]+mp[i])
    
    ans = float('inf')
    for i in range(N+1):
        for j in range(H,H+max_attack):
            ans = min(ans, dp[i][j])
    
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 384024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<numeric>

using namespace std;

typedef long long LL;

struct edge {
	int to;
	int cost;
};

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

int main(void) {
	int n;
	cin >> n;
	vector<LL>c(n), s(n), f(n);
	for (int i = 1; i < n; i++)cin >> c[i] >> s[i] >> f[i];
	for (int i = 1; i < n; i++) {
		for (int j = i; j < n-1; j++) {
			s[i] += c[j];
			if (s[i] >= s[j + 1]) {
				if (s[i] % f[j + 1] == 0) {
					continue;
				}
				else {
					s[i] += (f[j + 1] - (s[i] % f[j + 1]));
				}
			}
			else {
				s[i] = s[j + 1];
			}
		}
		s[i] += c[n - 1];
		cout << s[i] << endl;
	}
	cout << 0;
	return 0;
}

Measured memory_bytes: 256
#line 1 "test/algebra/gcd.test.cpp"
#define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_C"

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

#line 1 "test/algebra/../../library/algebra/gcd.cpp"
// greatest common divisor and least common multiple
// gcd is calculated by Euclidean Algorithm
// lcm = m * n / gcd(m,n)
template <typename T = int>
T gcd(T a, T b) {
    if (a < b)
        return gcd(b, a);
    if (b == 0)
        return a;
    T r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

template <typename T = int>
T lcm(T m, T n) {
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}
#line 8 "test/algebra/gcd.test.cpp"

int main() {
    lint n;
    cin >> n;
    vector<lint> a(n);
    lint ret = 1;
    for (int i = 0; i < n; ++i) {
        lint a;
        cin >> a;
        ret = lcm(ret, a);
    }
    cout << ret << "\n";
    return 0;
}



Measured memory_bytes: 3100
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define io ios_base::sync_with_stdio(false); cin.tie(0);

#define fs first
#define sc second
#define mp make_pair
#define mt make_tuple
#define pb push_back

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef long double ld;

const ll LINF = 1e18;
const int INF = 1e9;
const ld EPS = 1e-9;
const int MOD = 1e9+7;

/// Scanf para ler char array separados por espacos -> scanf(" %[^\n]", texto);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){

	io;
    string strs[105];
    int n, l;
    cin >> n >> l;
    rep(i, 0, n){
    	cin >> strs[i];
    }
    sort(strs, strs+n);
    rep(i, 0, n){
    	cout << strs[i];
    }
    cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline int read()
{
    int x = 0;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x;
}
int n, m, mx;
int a[500005], nxt[500005], t[500005];
int p[1000005];
struct qer
{
    int l, r, id, ans;
} q[500005];
bool cmp1(qer a, qer b)
{
    return a.l == b.l ? a.r < b.r : a.l < b.l;
}
bool cmp2(qer a, qer b)
{
    return a.id < b.id;
}
int lowbit(int x) { return x & (-x); }
void update(int x, int v)
{
    for (int i = x; i <= n; i += lowbit(i))
        t[i] += v;
}
int ask(int x)
{
    int tmp = 0;
    for (int i = x; i > 0; i -= lowbit(i))
        tmp += t[i];
    return tmp;
}
int main()
{
    n = read();
    m = read();
    for (int i = 1; i <= n; i++)
        a[i] = read(), mx = max(mx, a[i]);
    for (int i = n; i > 0; i--)
        nxt[i] = p[a[i]], p[a[i]] = i;
    for (int i = 1; i <= mx; i++)
        if (p[i])
            update(p[i], 1);
    for (int i = 1; i <= m; i++)
        q[i].l = read(), q[i].r = read(), q[i].id = i;
    sort(q + 1, q + m + 1, cmp1);
    int l = 1;
    for (int i = 1; i <= m; i++)
    {
        while (l < q[i].l)
        {
            if (nxt[l])
                update(nxt[l], 1);
            l++;
        }
        q[i].ans = ask(q[i].r) - ask(q[i].l - 1);
    }
    sort(q + 1, q + m + 1, cmp2);
    for (int i = 1; i <= m; i++)
        printf("%d\n", q[i].ans);
    return 0;
}

Measured memory_bytes: 19388
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    A, B, C, D = map(int, readline().split())

    if A + B > C + D:
        print('Left')
    elif A + B < C + D:
        print('Right')
    else:
        print('Balanced')

    return


if __name__ == '__main__':
    main()


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

int N;
int bills[2][100];
bool used[2][100][1000];

int rec(int bill, int floor, int t){
    if(floor == N-1 && bills[bill][floor] != 2){return t;}
    if(t >= 1000){return INF;}
    if(used[bill][floor][t]){return INF;}

    used[bill][floor][t] = true;

    int res = INF;
    if(bills[bill][floor] == 0){
        res = std::min(rec(!bill, floor, t+1), rec(!bill, floor+1, t+1));
        if(floor+2 < N){res = std::min(res, rec(!bill, floor+2, t+1));}
    }else if(bills[bill][floor] == 1){
        int nextFloor = floor;
        while(true){
            if(nextFloor + 1 == N || bills[bill][nextFloor+1] != 1){
                break;
            }else{
                nextFloor += 1;
            }
        }

        if(nextFloor == N-1){return t;}
        res = rec(!bill, nextFloor, t+1);
        res = std::min(res, rec(!bill, nextFloor+1, t+1));
        if(nextFloor+2 < N){res = std::min(res, rec(!bill, nextFloor+2, t+1));}
    }else{
        int nextFloor = floor;
        while(bills[bill][nextFloor] == 2){
            nextFloor -= 1;
        }

        // if(nextFloor+1 < N && !bill == 1 && nextFloor+1 == 4){printf("%d, %d, %d\n", bill, floor, t);}
        res = rec(!bill, nextFloor, t+1);
        if(nextFloor+1 < N){res = std::min(res, rec(!bill, nextFloor+1, t+1));}
        if(nextFloor+2 < N){res = std::min(res, rec(!bill, nextFloor+2, t+1));}
    }
    return res;
}

int main(){
    while(std::cin >> N, N){
        REP(i, 2){
            REP(j, N){
                std::cin >> bills[i][j];
            }
        }

        memset(used, 0, sizeof(used));
        int res = rec(1, 0, 0);
        memset(used, 0, sizeof(used));
        res = std::min(res, rec(0, 0, 0));

        if(res != INF){
            std::cout << res << std::endl;
        }else{
            std::cout << "NA" << std::endl;
        }
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=2e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n,m,k;
void input()
{
	n=read<int>(),m=read<int>();k=read<int>();
}
int ans,dp[N<<1][N],sum[N<<1][N];
const int mo=1e9+7;
void work()
{
	dp[0][0]=1;
	For(i,0,m)sum[0][i]=1;
	For(i,1,n+m)For(j,0,m)
	{
		dp[i][j]=(j?sum[i-1][j-1]:0)-(j-k>=0?sum[i-1][j-k]:0);
		dp[i][j]=(dp[i][j]+mo)%mo;
		if(j%(k-1)==m%(k-1)&&i*(k-1)-j<=n-1&&(i*(k-1)-j)%(k-1)==(n-1)%(k-1))ans=(ans+dp[i][j])%mo;
		dp[i][j]=(dp[i][j]+dp[i-1][j])%mo;
		sum[i][j]=((j?sum[i][j-1]:0)+dp[i][j])%mo;
	}
	write(ans,'\n');
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 62976
# coding: utf-8


def solve(*args: str) -> str:
    a1, a2, a3 = map(int, args[0].split())
    return 'win' if a1 + a2 + a3 < 22 else 'bust'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long long Q,H,S,D,N,ans,k;
int main()
{
    cin>>Q>>H>>S>>D>>N;
    k=min(Q*4,min(H*2,S));
    if(k*2<=D)
    {
        cout<<k*N<<endl;
    }
    else
    {
        cout<<((N%2)*k)+N/2*D<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, ans = 0;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e;
    for (ll i = 1; i < n; i++)
        if (a[i] < a[i - 1])
            ans += a[i - 1] - a[i], a[i] = a[i - 1];
    cout << ans;
}

Measured memory_bytes: 4776
import sys
 
while True:
    line = sys.stdin.readline()
    if line is '':
        break
     
    (a, b, e, c, d, f) = map(float, line.split())
     
    D = a * d - b * c
    x = (d * e - b * f) / D
    y = (a * f - c * e) / D
     
    if abs(x) < 1e-4:
        x = 0.0
    if abs(y) < 1e-4:
        y = 0.0
     
    print("{0:.3f} {1:.3f}".format(x, y))


Measured memory_bytes: 5580
def solve(bfo2, bfo1):
    ans = [bfo2, bfo1]
    for i in s:
        if ((bfo1 == 'S' and i == 'o')
                or (bfo1 == 'W' and i == 'x')):
            ans.append(bfo2)
        else:
            ans.append('S' if bfo2 == 'W' else 'W')
        bfo1, bfo2 = ans[-1], bfo1
    if ans[:2] == ans[-2:]:
        print(*ans[1:-1], sep='')
        exit()


n, s = int(input()), input()

for i in ['S', 'W']:
    for j in ['S', 'W']:
        solve(i, j)
print(-1)


Measured memory_bytes: 93040
S = input()
Answer = 0
for i in range(len(S)):
    counter = 0
    for j in range(len(S)-i):
        if S[j] in ['A','C', 'G','T']:
            counter += 1
            if Answer < counter:
                Answer = counter
            j = i + 1
        else:
            counter = 0
print(Answer)

Measured memory_bytes: 3060
S = input()
S = list(S)
MOD = 1000000007
l = [[0 for j in range(10)] for i in range(6)]
for i in range(6):
    for j in range(10):
        l[i][j] = j * 10**i % 13

dp = [[0 for i in range(13)] for i in range(len(S)+1)]
dp[0][0] = 1

for i in range(len(S)-1, -1, -1):
    ir = len(S)-1 - i
    if S[i] == "?":
        c = -1
    else:
        c = int(S[i])
    
    for j in range(10):
        if c != -1 and c != j:
            continue
        for k in range(13):
            dp[ir+1][(k + l[ir%6][j]) % 13] += dp[ir][k]
    for k in range(13):
        dp[ir+1][k] %= MOD

print(dp[len(S)][5])

Measured memory_bytes: 70536
//#include<bits/stdc++.h> using namespace std;
#include<iostream>
using namespace std;
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<stack>
#include<queue> //priority_queue inside queue
#include<deque>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define nl '\n'
typedef long long ll;
typedef unsigned long long ull;
#define f(i,start,end) for(i=start;i<=end;i++)
#define min_heap priority_queue<int, vector<int>, greater<int> >
#define max_heap priority_queue<int>
#define eb emplace_back

bool isPrime(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        if(n%i==0) return false;
    }
    return true;
} //returns true if prime!


int main()
{
    fast;
//int t=0,tc=0; cin >> tc; f(t,1,tc) //testcases
    {
        int n,m,q;
        cin >> n >> m >> q;
        int i,j;
        int a[60],b[60],c[60],d[60];
        
        f(i, 0, q-1)
        {
            cin >> a[i] >> b[i] >> c[i] >> d[i];
            a[i]--;
            b[i]--;
        }
        
        vector<int> x(n+m-1, 1);
        f(i,0, m-2) x[i]=0;
        
        int ans = 0;
        
        do
        {
            int cnt = 1;
            vector<int> y;
            f(i, 0, x.size()-1)
            {
                if(x[i]==1) y.eb(cnt);
                else cnt++;
            }
            //for(auto it: y) cout << it; cout << nl;
            int sums = 0;
            f(i, 0, q-1)
            {
                if(y[b[i]]-y[a[i]]==c[i]) sums += d[i];
            }
            ans = max(ans, sums);
        }
        while(next_permutation(x.begin(), x.end()));
        cout << ans << nl;
    }
    return 0;
}
    

Measured memory_bytes: 3608
#include<stdio.h>
#include<math.h>
#include<queue>
#include<stack>
#include<string.h>
#include<algorithm>
#include<cctype>
#include<map>
#include<set>
typedef long long ll;
using namespace std;
char a[1000],b[1000];
int main()
{
	int n;
	scanf("%d",&n);
	getchar();scanf("%s",a);scanf("%s",b);
	for(int i=1;i<=n;i++){
		printf("%c%c",a[i-1],b[i-1]);
	}printf("\n");
}

Measured memory_bytes: 128
N,M=map(int,input().split())
L=[(1,a) for a in map(int,input().split())]
for _ in range(M):
  L.append(tuple(map(int,input().split())))
L=sorted(L,key=lambda x: x[1],reverse=True)
ans,k=0,0
for n,a in L:
  if n+k>=N:
    ans+=a*(N-k)
    break
  else:
    ans+=a*n
    k+=n
print(ans)

Measured memory_bytes: 39060
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<char,int>ma;
  string s;
  cin>>s;
  rep(i,s.length())ma[s[i]]++;
  int l=s.length();
  cout<<(l/2-ma['p'])<<endl;

  return 0;

}


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

int main(){
    int a,b,c,x,y;
    int ans = 0;
    cin >> a >> b >> c >> x >> y;
    int z = max(x,y);
    int w = min(x,y);
    if(a+b>=2*c){
        if(x>y){
            ans = min(c*2*x,c*y*2 + (x-y)*a);
        }
        else{
            ans = min(c*2*y,c*x*2 + (y-x)*b);
        }
    }
    else{
        ans = a*x + b*y;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int gcd(int x, int y){
  if(x%y==0) return y;
  return gcd(y, x%y);
}

int main()
{
  int N;
  int a[110000];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i];

  res = a[0];
  FOR(i,1,N-1){
    res = gcd(res, a[i]);
  }

  cout << res << endl;
}


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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define INF INT_MAX
#define NINF INT_MIN
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << "\n";
    err(++it, args...);
}

const int MAX_D = 3000+10;

int n;
long double p[MAX_D];
long double dp[MAX_D][MAX_D];

int main() {

	cout << fixed << setprecision(10);
	cin >> n;

	tik(i,1,n+1)
		cin >> p[i];

	dp[0][0] = 1.0;

	tik(i,1,n+1) {
		tik(j,0,n+1) {
			if(j > 0)
				dp[i][j] = dp[i-1][j]*(1-p[i]) + dp[i-1][j-1]*p[i];
			else
				dp[i][j] = dp[i-1][j]*(1-p[i]);
		}
	}

	long double res = 0;

	tik(i,n/2+1,n+1) {
		res += dp[n][i];
	}

	cout << res;
}

Measured memory_bytes: 141568
#include <iostream>
#include <utility>
#include <string>
#include <vector>

struct Dice
{
  int numbers[6];

  Dice (int n1, int n2, int n3, int n4, int n5, int n6) {
    numbers[0] = n1;
    numbers[1] = n2;
    numbers[2] = n3;
    numbers[3] = n4;
    numbers[4] = n5;
    numbers[5] = n6;
  }

  void move(char dir){
    if (dir == 'N') {
      setNum(numbers[1], numbers[0], numbers[2], numbers[5], numbers[3], numbers[4]);
    }
    if (dir == 'S') {
      setNum(numbers[4], numbers[5], numbers[2], numbers[0], numbers[3], numbers[1]);
    }
    if (dir == 'W') {
      setNum(numbers[2], numbers[4], numbers[5], numbers[1], numbers[0], numbers[3]);
    }
    if (dir == 'E') {
      setNum(numbers[3], numbers[4], numbers[0], numbers[1], numbers[5], numbers[2]);
    }
  }

  void roll(std::string dir){
    if (dir == "vertical") {
      setNum(numbers[1], numbers[0], numbers[2], numbers[5], numbers[3], numbers[4]);
    }
    if (dir == "horizontal") {
      setNum(numbers[0], numbers[2], numbers[1], numbers[3], numbers[4], numbers[5]);
    }
  }

  void setNum(int top, int north, int east, int south, int west, int bottom) {
    numbers[0] = top;
    numbers[4] = north;
    numbers[2] = east;
    numbers[1] = south;
    numbers[3] = west;
    numbers[5] = bottom;
  }

  void printDice() {
    std::cout << numbers[0] << " " << numbers[1] << " " << numbers[2] << " " << numbers[3] << " " << numbers[4] << " " << numbers[5] << "\n";
  }

  bool isSameDice(Dice dice) {
    for (int i = 0; i < 4; i++)
    {
      for (int j = 0; j < 4; j++)
      {
        if (dice.numbers[0] == numbers[0]
            && dice.numbers[1] == numbers[1]
            && dice.numbers[2] == numbers[2]
            && dice.numbers[3] == numbers[3]
            && dice.numbers[4] == numbers[4]
            && dice.numbers[5] == numbers[5]) {
              return true;
        }
        dice.roll("horizontal");
      }
      dice.roll("vertical");
    }
    move('E');
    for (int i = 0; i < 4; i++)
    {
      for (int j = 0; j < 4; j++)
      {
        if (dice.numbers[0] == numbers[0]
            && dice.numbers[1] == numbers[1]
            && dice.numbers[2] == numbers[2]
            && dice.numbers[3] == numbers[3]
            && dice.numbers[4] == numbers[4]
            && dice.numbers[5] == numbers[5]) {
              return true;
        }
        dice.roll("horizontal");
      }
      dice.roll("vertical");
    }
    return false;
  }
};

int main() {
  int n;
  std::cin >> n;
  std::vector<Dice> dices;
  int n1, n2, n3, n4, n5, n6;
  while (n--) {
    std::cin >> n1 >> n2 >> n3 >> n4 >> n5 >> n6;
    Dice dice(n1, n2, n3, n4, n5, n6);
    dices.push_back(dice);
  }
  bool isAllDiff = true;
  for (int i = 0; i < dices.size(); i++)
  {
    for (int j = 0; j < dices.size(); j++)
    {
      if (i == j) {
        continue;
      }
      if (dices[i].isSameDice(dices[j])) {
        isAllDiff = false;
      }
    }
  }
  if (isAllDiff) {
    std::cout << "Yes" << "\n";
  } else {
    std::cout << "No" << "\n";
  }
}


Measured memory_bytes: 3164
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
        int count = 1;
	int min = sc.nextInt();
	int P = 0;
	for(int i=2;i<=N;i++){
	    P = sc.nextInt();
	    if(P <= min){
		count++;
		min = P;
	    }
	}
	System.out.print(count);
    }
}

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

using namespace std;

int main() {

   string sa,sb,sc;

   cin >> sa >> sb >> sc;

   int a = -1;
   int b = -1;
   int c = -1;

   char now = 'a';
   char ans;

   while(1){
       if(now == 'a'){    
           a++;
           if(a == sa.length()) break;
           now = sa[a];
       }else if(now == 'b'){    
           b++;
           if(b == sb.length()) break;
           now = sb[b];
       }else if(now == 'c'){    
           c++;
           if(c == sc.length()) break;
           now = sc[c];
       }
   }

   if(now == 'a') ans = 'A';
   else if(now == 'b') ans = 'B';
   else ans = 'C';
   
   cout << ans << endl;

   return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n, m;
	cin >> n >> m;
	VI s(n+2);
	REP(i,m){
		int c, d;
		cin >> c >> d;
		s[c]++;
		s[d]--;
	}
	REP(i,n+1) s[i+1] += s[i];
	int x = 0;
	REP(i,n+2) if (s[i] > 0) x++;
	cout << n + 1 + 2*x << endl;

    return 0;
}

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

int f(int n) {
  if(n % 2 == 0)
    return n / 2;
  else
    return 3 * n + 1;
}

int main() {
  int s;
  cin >> s;
  
  vector<int> a(1000000);
  a.at(0) = s;
  
  int ans = 0;
  int x = 0;
  int number = 0;
  for (int i = 1; i < 1000000; i++) {
    a.at(i) = f(a.at(i-1));
    x = a.at(i);
    number = i;
    for(int j = 0; j < i; j++) {
      if(x == a.at(j)) {
        ans = number + 1;
        break;
      }
    }
    if(ans != 0)
      break;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4096
#include<iostream>
#include<algorithm>
#include<vector>
#include<bitset>
using namespace std;
int N, K;
vector<int> line;
bool search(int);
int main() {
	cin >> N >> K;
	line.resize(N);
	for (int i = 0; i < N; ++i) {
		cin >> line[i];
	}
	sort(line.begin(), line.end());
	int fp = 0, bp = N;
	while (fp < bp) {
		int dp = (fp + bp) / 2;
		if (search(dp)) {
			fp = dp + 1;
		}
		else {
			bp = dp;
		}
	}
	cout << fp << endl;
	return 0;
}

bool search(int po) {
	if (K <= line[po])return false;
	bitset<5000> set;
	set[0] = true;
	for (int i = 0; i < N; ++i) {
		if (i != po) {
			set |= set << line[i];
		}
	}
	for (int i = K - 1; i >= K - line[po]; --i) {
		if (set[i])return false;
	}
	return true;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <map>
#include <cstdlib>
using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    vector< vector<int> > A(2, vector<int>(N));
    for(int i=0; i<2; i++){
        for(int j=0; j<N; j++){
            cin >> A[i][j];
        }
    }
    ll ans=0;
    for(int to_under=0; to_under<N; to_under++){
        ll tmp=0;
        for(int i=0; i<=to_under; i++){
            tmp+=A[0][i];
        }
        for(int j=to_under; j<N; j++){
            tmp+=A[1][j];
        }
        ans=max(tmp, ans);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
from math import floor
while(True):
  e = int(input())
  if e == 0:
    quit()
  ans = e
  for i in range(0,e):
      if i ** 3 > e:
          break
      j = floor((e - i ** 3)**0.5)
      k = e - i ** 3 - j ** 2 + i + j
      if k < ans:
          ans = k
  print(ans)



Measured memory_bytes: 5772
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;


int main(){
    string s;
    cin>>s;
    int a,z;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i=a;i<s.size();i++){
        if(s[i]=='Z'){
            z=i;
        }
    }
    cout<<z-a+1<<endl;
}


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

typedef pair<int,int> P;

int main() {
  int n;
  while(cin >> n && n) {
    P a[n];
    for(int i=0; i<n; i++) cin >> a[i].second >> a[i].first;
    sort(a,a+n);
    bool ck=true;
    int sum=0;
    for(int i=0; i<n; i++) {
      sum+=a[i].second;
      if(sum>a[i].first) {
	ck=false;
	break;
      }
    }
    if(ck) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 1156
#include <stdio.h>
int main(void){
	int n,a,b,i,f[100004]={},ans;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&a,&b);
		f[a]++;
		f[b+1]--;
	}
	for(i=1;i<100004;i++){
		f[i]+=f[i-1];
		if(f[i]+1>=i)
			ans=i-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 996
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String s = sc.next();
			int[] a = new int[10];
			for(int i = 0; i < 10; i++) {
				a[i] = s.charAt(i) - '0';
			}
			System.out.println(rec(a));
		}
		sc.close();
	}
	static int rec(int[] a) {
		if(a.length == 1) {
			return a[0];
		}
		int[] b = new int[a.length - 1];
		for(int i = 0; i < b.length; i++) {
			b[i] = (a[i] + a[i + 1]) % 10;
		}
		return rec(b);
	}
}



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

using namespace std;

int main()
{
    int N, M, K;
    cin >> N >> M >> K;
    for(int i = 0; i <= N; i++) {
        for(int j = 0; j <= M; j++) {
            if(i * (M - j) + (N - i) * j == K) {
                printf("Yes\n");
                return 0;
            }
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #define Mod 1000000007
    #define INF 1e9
    #define INFL 9e18
    #define EPS 1e-9
    #define pb push_back
    #define mp make_pair
    #define SET(a) memset(a,-1,sizeof(a))
    #define CLR(a) memset(a,0,sizeof(a))
    #define CPY(a,b) memcpy(a,b,sizeof(a))
    #define all(a) (a).begin(),(a).end()
    #define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define N 100005
    #define fs first
    #define sc second
    using namespace std;

    typedef  long long int ll;
    typedef pair<ll,ll> ii;
    typedef vector <ii> vii;
    typedef vector <ll> vi;


    int main()
    {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios;

ll x,a,b;
cin>>x>>a>>b;
x-=a;
ll pp=x/b;
cout<<x-pp*b;
  
    









    return 0;


    }

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a+b == 15) cout << '+' << endl;
    else if(a*b == 15) cout << '*' << endl;
    else cout << 'x' << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
const int mapSize=1e6+5,mod=1e9+7;
int fac[mapSize*2],inv[mapSize*2];
void Init(){
    fac[1]=inv[1]=1;
    for(int i=2;i<=(int)2e6+1;++i) {
        fac[i]=1ll*fac[i-1]*i%mod;
        int res=mod%i,div=mod/i;
        inv[i]=1ll*inv[res]*(mod-div)%mod;
    }
    for(int i=2;i<=(int)2e6+1;++i)
        inv[i]=1ll*inv[i]*inv[i-1]%mod;
    fac[0]=inv[0]=1;
}
int C(int down, int up) {
    return 1ll*fac[down]*inv[up]%mod*inv[down-up]%mod;
}
int rowSum(int rowId, int colL, int colR) {
    int tmp1,tmp2,ret=((tmp1=(C(rowId+1+colR,colR)) - (tmp2=C(rowId+colL,colL-1)))%mod+mod)%mod;
    return ret;
}
int main() {
    Init();
    int r1,c1,r2,c2;
    scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
    int ans = 0;
    for (int rowId = r1; rowId <= r2; ++rowId)
        ans = (ans + rowSum(rowId, c1, c2)) % mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repr(i,a,n) for(int i=a;i>=n;i--)
#define INF 999999999
#define INF_M 2147483647
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
 
int main() {
 	int n;
 	while(cin >> n) {
 		if(n == 0) break;
 		int ret = 0;
 		while(n/=5) ret += n;
 		cout << ret << endl;
 	}
    return 0;
}

Measured memory_bytes: 1160