akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
using ll = long long;

using Weight = int;
using Capacity = int;
struct Edge {
    int src, dst; Weight weight;
    Edge(int s, int d, int w) : src(s), dst(d), weight(w) {}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

struct UndirectionalCompare {
    bool operator() (const Edge& e, const Edge& f) const {
        if (min(e.src,e.dst) != min(f.src,f.dst))
            return min(e.src,e.dst) < min(f.src,f.dst);
        return max(e.src,e.dst) < max(f.src,f.dst);
    }
};
typedef set<Edge, UndirectionalCompare> Edgeset;
void visit(const Graph &g, int v, int u,
           vector<int>& art, vector<Edgeset>& bcomp,
           stack<Edge>& S, vector<int>& num, vector<int>& low, int& time) {
    low[v] = num[v] = ++time;
    for(auto &e : g[v]){
        int w = e.dst;
        if (num[w] < num[v]) S.emplace(e);              // for bcomps
        if (num[w] == 0) {
            visit(g, w, v, art, bcomp, S, num, low, time);
            low[v] = min(low[v], low[w]);
            if ((num[v] == 1 && num[w] != 2) ||         // for arts
                (num[v] != 1 && low[w] >= num[v])) art.push_back(v);
            if (low[w] >= num[v]) {                     // for bcomps
                bcomp.push_back(Edgeset());
                while (1) {
                    Edge f = S.top(); S.pop();
                    bcomp.back().insert(f);
                    if (f.src == v && f.dst == w) break;
                }
            }
        } else low[v] = min(low[v], num[w]);
    }
}
void articulationPoint(const Graph& g,
                       vector<int>& art, vector<Edgeset>& bcomp) {
    const int n = g.size();
    vector<int> low(n), num(n);
    stack<Edge> S;
    for(int u = 0; u < n; u++){
        if (num[u] == 0) {
            int time = 0;
            visit(g, u, -1, art, bcomp, S, num, low, time);
        }
    }
}

int main(){
    int n,m;
    while(cin >> n >> m){
        Graph g(n);
        rep(i,m){
            int a,b;
            cin >> a >> b;
            g[a].emplace_back(a,b,0);
            g[b].emplace_back(b,a,0);
        }
        vector<int> arts;
        vector<Edgeset> es;
        articulationPoint(g,arts,es);
        sort(all(arts));
        auto last = unique(all(arts));
        for(auto it = arts.begin(); it != last; ++it) cout << *it << '\n';
    }
}

Measured memory_bytes: 9576
class Dice:
    def __init__(self):
        self.number = [i for i in range(6)]

    def set_number(self, d0, d1, d2, d3, d4, d5):
        self.number[0] = d0
        self.number[1] = d1
        self.number[2] = d2
        self.number[3] = d3
        self.number[4] = d4
        self.number[5] = d5

    def roll(self, command):
        if   command == "E":
            self.set_number(self.number[3],self.number[1],self.number[0],self.number[5],self.number[4],self.number[2])
        elif command == "N":
            self.set_number(self.number[1],self.number[5],self.number[2],self.number[3],self.number[0],self.number[4])
        elif command == "S":
            self.set_number(self.number[4],self.number[0],self.number[2],self.number[3],self.number[5],self.number[1])
        elif command == "W":
            self.set_number(self.number[2],self.number[1],self.number[5],self.number[0],self.number[4],self.number[3])
        else:
            raise

    def get_top(self):
        return self.number[0]




list_face = list(map(int, input().split()))
commands = input()

dice = Dice()
dice.set_number(list_face[0], list_face[1], list_face[2], list_face[3], list_face[4], list_face[5])

for command in commands:
    dice.roll(command)

print(dice.get_top())




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

int main(){
  int k;
  char str[100], copy[100]={0};
  scanf("%d",&k);
  scanf("%s",str);
  if(strlen(str)>k){
    printf("%s...\n",memcpy(copy,str,k));
  }else {
    printf("%s\n",str);
  }
  return 0;
}

Measured memory_bytes: 1728
#include <stdio.h>

int main(void) {
  int i, a;

  while (scanf("%d", &a) != EOF) {
    i = 1;
    while (1) {
      a--;
      if (a == 0) break;
      i++;
      if (i == 40) i = 1;
    }
    printf("3C%02d\n", i);
  }

  return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
using graph = vector<vector<ll>>;


int main() {
	string s, t,ans="Yes";
	cin >> s;
	cin >> t;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			ans = "No";
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <list>

#include <cmath>
#include <algorithm>
#include <cassert>
#include <bitset>
#include <complex>
#include <climits>
#include <functional>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> l4;
typedef pair<double, double> dd;
#define mp make_pair
#define pb push_back

#define debug(x) cerr << #x << " = " << x << " "




int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  puts((n+1)/2 >= k ? "YES" : "NO");
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void) {

	int input[3];
	int a, b, c;
	int num5=0, num7=0;
	int i;

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

	input[0] = a;
	input[1] = b;
	input[2] = c;

	for (i = 0; i < 3; i++) {
		
		if (input[i] == 5) {
			num5++;
		}
		else if (input[i] == 7) {
			num7++;
		}
		else {

		}
	}
		
	if (num5 == 2 && num7 == 1) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 100001

using namespace std;

long long MOD = 1000000007;

struct edge
{
    ll cost;
    int to;
};


void dfs(int x, ll cost, vector<vector<edge>> &edges, vector<ll> &dist){
    if(dist[x]!=MOD*MOD){
        return;
    }
    dist[x]=cost;
    for(auto &e:edges[x]){
        dfs(e.to,cost+e.cost,edges,dist);
    }
}

int main(){
    int N;
    cin >> N;

    vector<vector<edge>> edges(N,vector<edge>(0));
    for(int i=0; i<N-1; i++){
        int u,v,w;
        cin >> u >> v >> w;
        u--;v--;
        edges[u].push_back({w,v});
        edges[v].push_back({w,u});
    }

    vector<ll> dist(N,MOD*MOD);
    dfs(0,0,edges,dist);
    for(int i=0; i<N; i++){
        if(dist[i]%2==0){
            cout << 0 << '\n';
        }else{
            cout << 1 << '\n';
        }
    }
}

Measured memory_bytes: 12576
/*
Author: Arham_doshi
@quote "Code like there's no tommorow!"
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007



using namespace std;

int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
int ceil(int n,int k){if(k%n==0){return k/n;}else return (k/n)+1;}
int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}
int a[3005],dp[3005][3005];

int dequ(int l,int r){
    if(dp[l][r]!=-1)return dp[l][r];
    else if(l==r){
        dp[l][r]=a[l];
        return dp[l][r];
    }
    else{
        dp[l][r]=max(a[l]-dequ(l+1,r),a[r]-dequ(l,r-1));
        return dp[l][r];
    }
    
}


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,t,n,k;
    cin>>n;
    _init(a);
    _init(dp);
    
    fo(i,0,n){
        cin>>x;
        a[i]=x;
    }
    
    cout<<dequ(0,n-1);
    
    
    return 0;
}

Measured memory_bytes: 70912
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=n-1;i>=a;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pair<ll,ll>>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=2e4+10,oo=0x3f3f3f3f,MOD=998244353;
const double PI = acos(-1);

void solve(){
    char c;
    cin>>c;
    if(c>='a')
        cout<<'a'<<endl;
    else
        cout<<'A'<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();
}


Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<functional>
#include<iomanip>

#define LLI long long int

using namespace std;

int main(){
	int A,B;cin>>A>>B;
	int ans;
	if(A>=13)
		ans=B;
	else if(A>=6)
		ans=B/2;
	else
		ans=0;
	cout<<ans<<endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	class UnionFind{
		int [] par, rank;
		int num;
		public UnionFind(int n) {
			par = new int[n];
			rank = new int[n];
			for(int i = 0 ; i < n; i++){
				par[i] = i;
				//rank[i] = 0;
			}
			num = n;
		}
		int find(int x){
			if(par[x] == x)return x;
			else return par[x] = find(par[x]);
		}
		void unite(int x, int y){
			x = find(x);
			y = find(y);
			if(x == y) return ;
			if(rank[x] < rank[y]) par[x] = y;
			else{
				par[y] = x;
				if(rank[x] == rank[y]) rank[x]++;
			}
			num--;
		}
		boolean same(int x, int y){
			return find(x) == find(y);
		}
	}
	
	private void doit(){
		
		Scanner sc = new Scanner(System.in);
		long mod = 1000000007;
		while(sc.hasNext()){
			int N = 100000 * 2;
			
			int n = sc.nextInt();
			int k = sc.nextInt();
			int m = sc.nextInt();
			UnionFind uf = new UnionFind(n);
			for(int i = 0; i < k; i++){
				
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				uf.unite(a, b);
			}
			UnionFind uf2 = new UnionFind(n);
			for(int j = 0; j < m; j++){
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				uf2.unite(a,b);
			}
			
			TreeMap<Long, Integer> count = new TreeMap<>();
			for(int i=0;i< n;i++){
				long res = (long) uf.find(i) * N + uf2.find(i);
				if(! count.containsKey(res)){
					count.put(res, 1);
				}
				else{
					count.put(res, count.get(res) + 1);
				}
			}
			
			StringBuilder ans = new StringBuilder();
			for(int i =0;i<n;i++){
				int res = count.get((long) uf.find(i) * N + uf2.find(i));
				ans.append(" " + res);
			}
			System.out.println(ans.substring(1));
			
		}

	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


Measured memory_bytes: 106924
N,Y=map(int,input().split())
flag=False
for i in range(N+1):
    if flag==True:
        break
    else:
        pass
    for j in range(N+1-i):
        k=N-i-j
        if 10000*i+5000*j+1000*k==Y:
            print(i, j, k)
            flag=True
            break
        else:
            continue
if flag==False:
    print("-1 -1 -1")
else:
    pass

Measured memory_bytes: 3060
'use strict'

function main(input) {
    
        input = input.split(/\n|\s/).map(v => ~~v)
        const q = input[1]
        const tmp = input.slice(2, -1)
        const recipe = tmp.sort((a, b) => a - b)

        const sum = recipe.reduce((v, x) => v + x)

        const ans = Math.floor((q - sum) / recipe[0]) + recipe.length
        

        console.log(ans)



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


Measured memory_bytes: 7500
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,YL=1e9+7,M=N-5,inv2=YL+1>>1;
inline int MO(const int &x){return x>=YL?x-YL:x;}
inline int ksm(int a,int k){int r=1;while(k){if(k&1)r=1ll*r*a%YL;a=1ll*a*a%YL,k>>=1;}return r;}
int fac[N],fnv[N];
typedef std::pair<int,int> P;
#define mk make_pair
inline int C(int x,int y){return y>x?0:1ll*fac[x]*fnv[y]%YL*fnv[x-y]%YL;}
int main()
{
	ios::sync_with_stdio(0);fac[0]=1;
	for(int i=1;i<=M;++i)fac[i]=1ll*fac[i-1]*i%YL;fnv[M]=ksm(fac[M],YL-2);
	for(int i=M;i>=1;--i)fnv[i-1]=1ll*fnv[i]*i%YL;
	int n,m,ws=0,bs=0;cin>>n>>m;
	for(int i=1;i<=n+m;++i)
	{
		int ans=(ws+1ll*MO(MO(YL-ws)+MO(YL-bs)+1)*inv2)%YL;
		printf("%d\n",ans);
		ws=(1ll*C(i-1,m-1)*ksm(inv2,i)+ws)%YL;
		bs=(1ll*C(i-1,n-1)*ksm(inv2,i)+bs)%YL;
	}
	return 0;
}


Measured memory_bytes: 3840
object Main extends App {
  val N = io.StdIn.readLine.toInt

  def div(n: Int): Boolean = {
    if (n % 4 == 0 || n % 7 == 0 || n == 0) return true
    else if (n != 4 && n <= 6) return false
    else return div(n - 7) || div(n - 4)
  }

  val out = if (div(N)) "Yes" else "No"

  println(out)
}


Measured memory_bytes: 25424
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+10;
struct node{
	int x,id;
};
int L[N],R[N];
struct cmp{
	bool operator()(int a,int b){return R[a]<R[b];}
};
node l[N],r[N];
int n;
int get(int l,int r){return r>=l?r-l+1:0;}
bool cmp1(node x,node y){return x.x<y.x;}
int main(){
	scanf("%d",&n);
	set<int,cmp>s;
	for (int i=1;i<=n;i++) scanf("%d%d",&l[i].x,&r[i].x);
	for (int i=1;i<=n;i++) L[i]=l[i].x,R[i]=r[i].x;
	for (int i=1;i<=n;i++) l[i].id=i,r[i].id=i;
	sort(l+1,l+n+1,cmp1); sort(r+1,r+n+1,cmp1);
	for (int i=1;i<=n;i++) if (r[1].id!=i) s.insert(i);
	int ans=0,x=L[r[1].id];
	for (int i=1;i<n;i++){
		if (l[i].id!=r[1].id) s.erase(l[i].id);
		ans=max(ans,get(max(l[i].x,x),r[1].x)+get(l[n].x,R[*s.begin()]));
	}
	for (int i=1;i<=n;i++) if (i!=r[1].id&&i!=l[n].id) ans=max(ans,get(L[i],R[i])+get(l[n].x,r[1].x));
	printf("%d\n",ans); 
}

Measured memory_bytes: 7296
<?php

fscanf(STDIN, "%d %d", $n, $m);

$s_arr = [];
$c_arr = [];
for ($i = 0; $i < $m; ++$i) {
    $inputs = explode(' ', trim(fgets(STDIN)));

    $s_arr[] = $inputs[0];
    $c_arr[] = $inputs[1];
}

for ($i = 0; $i < 1000; ++$i) {
    if (strlen($i) != $n) {
        continue;
    }

    $arr = str_split($i);

    $res = true;
    for ($j = 0; $j < $m; ++$j) {
        // keta
        if ($arr[$s_arr[$j] - 1] !== $c_arr[$j]) {
            $res = false;
            break;
        }
    }

    if ($res) {
        echo $i;
        return;
    }
}

echo -1;


Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <cstdlib>  // abs() for integer
#include <algorithm>
#include <fstream>
using namespace std;

int main(){
    // あとで消す
    //std::ifstream in("bin3.txt");
    //std::cin.rdbuf(in.rdbuf());

    int N;
    cin >> N ;

    vector<int> arr(N);

    //int tmp,maxv;//,minsub,before,ii;
    //cout << "ok" << N << endl;

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

    for(int i=1;i<N;i++){
        arr[i] = arr[i]+arr[i-1];
    }

    int maxv = arr[N-1];
    int ii = N-1;


    for(int i=0;i<N;i++){
        if(maxv-arr[i]-arr[i]<0){
            ii = i;
            break;
        }
    }


    int compA,compB;
    compA = maxv-arr[ii]-arr[ii];
    if(compA<0)compA = -compA;
    compB = maxv-arr[ii-1]-arr[ii-1];

    //cout << ii << endl;
    //cout << compA << compB << endl;

    if(compB>compA){
        cout << compA << endl;
    }else{
        cout << compB << endl;
    }


    return 0;
}


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

struct node{
    int key;
    struct node *next;
    struct node *prev;
};
typedef struct node * NodePointer;
NodePointer nil;
void init(){
    nil = malloc(sizeof(struct node));
    nil->next = nil;
    nil->prev = nil;
}
NodePointer search(int key){
  NodePointer x;
  if(key == -1){
    return nil->prev;
  }
  else{
  x = nil->next;
  while(x != nil && x->key != key)
    x = x->next;
  return x;
  }
}
void insert(int key){
    NodePointer x;
    x = malloc(sizeof(struct node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

void delete(int key){
  NodePointer x;
  x = search(key);
  if(x == nil) return;
  else{
  x->prev->next = x->next;
  x->next->prev = x->prev;
  }
  free(x);
  return;
}

void printList(){
    NodePointer cur = nil->next;
    int isf = 1;
    while(1){
	if ( cur == nil ) break;
        if ( isf == 0)  printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
        isf = 0;
    }
    printf("\n");
}

int main(){
    int i, n, key;
    char s[20];
    init();
    scanf("%d",&n);
    for(i = 0; i < n; i++){
        scanf("%s",s);
        if(s[0] == 'i'){
            scanf("%d",&key);
            insert(key);
        }
        else if(s[0] == 'd'){
            if(s[6] == 'F')
                delete(nil->next->key);
            else if(s[6] == 'L')
                delete(-1);
            else{
                scanf("%d",&key);
                delete(key);
            }
        }

    }
    printList();
    free(nil);
    return 0;
}

Measured memory_bytes: 31788
#include <iostream>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll dp[2010][2010];
int main(){
    int i,j,s; cin >> s;
    for(i=3;i<=s;i++) dp[0][i] = i - 2;
    for(i=1;i<=s;i++){
        for(j=3;j<=s;j++){
            dp[i][j] = (dp[i][j - 1] + dp[i - 1][j - 3])%mod; 
        }
    }
    ll ans = 0;
    for(i=0;i<=s;i++){
        (ans += dp[i][s] + mod - dp[i][s - 1]) %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 35052
from bisect import bisect_left as bisect

def main():
    n, m, *ab = map(int, open(0).read().split())

    rate = []
    for a, b in zip(*[iter(ab)] * 2):
        if a > m:
            continue
        rate.append([a, b])

    rate = sorted(rate, key=lambda x: -x[1])

    day = list(range(1, m + 1))
    day_len = m
    ans = 0
    for term, money in rate:
        work_day = bisect(day, term)
        if work_day == day_len:
            continue
        else:
            del day[work_day]
            day_len -= 1
            ans += money

    print(ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 26692
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	int p=0,q=0,ans=0;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		if(s[i]=='g')
		{
			if(q>p)
			{
				ans++;
				p++;
			}
			else
			{
				q++;
			}
		} 
		else
		{
			if(q>p)
			{
				p++;
			}
			else
			{
				ans--;
				q++;
			}
		}
	} 
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
int a,b;
cin >> n;
if(n==1) {
  cout << "Hello World" << endl;
} else {
  cin >> a >> b;
  cout << a+b << endl;
}
return 0;
}


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

int main() {
  string s,b,c;
  cin >> s;
  bool flag = true;
  string a = s;
  reverse(a.begin(),a.end());
  if(s != a) flag = false;
  int n = s.size();
  int j = (n-1)/2;
  a.erase(j);
  b = a;
  reverse(b.begin(),b.end());
  if(a != b) flag = false;
  a = s;
  int k = (n+3)/2;
  a.erase(0,k-1);
  c = a;
  reverse(c.begin(),c.end());
  if(a != c) flag = false;
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.io.*;
class Main
{
public static void main(String args[])throws IOException
{
BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
while(true)
{
String str=input.readLine();
String str_ary[]=str.split(" ");
if(str_ary[0].equals("0") && str_ary[1].equals("0"))break;
int x,y,big,small,count=0;
x=Integer.parseInt(str_ary[0]);
y=Integer.parseInt(str_ary[1]);
if(x>y)
{
big=x;
small=y;
}
else 
{
big=y;
small=x;
}
while(true)
{

if((big%small)==0)
{
count++;
break;
}
int tmp=big%small;
big=small;
small=tmp;
count++;
}
System.out.println(small+" "+count);
}
}
}

Measured memory_bytes: 24132
#include <iostream>
#include <string>
#include <cmath>
#include <set>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <cstring>

using namespace std;

constexpr long long mod = 1000000007;
constexpr double eps = 0.0000000001;

typedef long long ll;
typedef long long unsigned ull;

int main() {
    ll h,c = 1,r = 0;
    cin >> h;
    while(h > 1) {
        r += c;
        c *= 2;
        h /= 2;
    }
    cout << c + r << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,X1,X2,X3;
    scanf("%d %d",&A,&B);
    X1=A+B;
    X2=A-B;
    X3=A*B;
    if(X1>=X2 && X1>=X3)
    {
        printf("%d\n",X1);
    }
   else if(X2>=X1 && X2>=X3)
    {
        printf("%d\n",X2);
    }
   else 
    {
        printf("%d\n",X3);


    }
    return 0;


}


Measured memory_bytes: 128
n = int(raw_input())
a = map(int, raw_input().split())

i = 0
j = 1
res = a[i]
total = n

while i < n and j < n:
  if res & a[j] == 0:
    res += a[j]
    j += 1
  else:
    res -= a[i]
    i += 1
    total += j - i
    if j == i:
      j += 1
      res = a[i]

if j == n:
  if i < n-1:
    for k in range(i+1, n):
      total += j-k

print(total)


Measured memory_bytes: 19996
#include <queue>
#include <vector>
#include <iostream>
#pragma warning(disable : 4996)
//FILE *in = freopen("input.txt", "r", stdin);
using namespace std;
int n, p[100007], vis[100007], can[100007], d[100007]; vector<int> v;
void rec(int pos, int cur) {
	vis[pos] = cur;
	while (true) {
		if (p[pos] == 0) break;
		v.push_back(pos);
		pos += p[pos];
		if (vis[pos] == cur || !can[pos]) {
			for (int i = 0; i < v.size(); i++) can[v[i]] = 0;
			break;
		}
		vis[pos] = cur;
	}
	v.clear();
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> p[i], can[i] = 1;
	for (int i = 0; i < n; i++) {
		if (!vis[i] && p[i]) rec(i, i + 1);
	}
	fill(d + 1, d + n, -1);
	queue<int> que; que.push(0);
	while (!que.empty()) {
		int u = que.front(); que.pop();
		for (int i = 1; i <= 6 && u + i < n; i++) {
			int cur = u + i;
			if (can[cur] && d[cur] == -1) {
				while (p[cur]) cur += p[cur];
				if(d[cur] == -1) d[cur] = d[u] + 1, que.push(cur);
			}
		}
	}
	cout << d[n - 1] << endl;
	return 0;
}

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

#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)

int di[] = {1,-1,0,0};
int dj[] = {0,0,1,-1};
char t[12][7];

void printMap(void){
	rep(i,12){cout<<t[i]<<endl;}
}

void fallPuyo(void){
	for(int i=10;i>=0;i--){
		rep(j,6){
			if(t[i][j] != '.'){
				int k;
				for(k=i+1;k<12 && t[k][j]=='.';k++);
				k--;
				if(t[k][j] == '.'){
					t[k][j] = t[i][j];
					t[i][j] = '.';
				}
			}
		}
	}
}

void deletePuyo(int ti,int tj,char c){
	t[ti][tj] = '.';
	rep(i,4){
		int ni = ti + di[i];
		int nj = tj + dj[i];

		if(ni>=0 && ni<12 && nj>=0 && nj<6){
			if(t[ni][nj] == 'O') t[ni][nj] = '.';
			else if(t[ni][nj] == c) deletePuyo(ni,nj,c);
		}
	}
}

int countPuyo(int ti,int tj,char c){
	int res = 0;

	t[ti][tj] = '.';
	rep(i,4){
		int ni = ti + di[i];
		int nj = tj + dj[i];

		if(ni>=0 && ni<12 && nj>=0 && nj<6 && t[ni][nj]==c) res += countPuyo(ni,nj,c);
	}
	t[ti][tj] = c;

	return res + 1;
}

int main(void){
	int n;
	cin>>n;

	while(n--){
		rep(i,12)cin>>t[i];

		int rensa = 0;
		bool finishFlg = false;

		while(!finishFlg){
			finishFlg = true;

			rep(i,12)rep(j,6){
				if(t[i][j] != 'O' && t[i][j] != '.'){
					if(countPuyo(i,j,t[i][j]) >= 4){
						deletePuyo(i,j,t[i][j]);
						if(finishFlg){
							finishFlg = false;
							rensa++;
						}
					}
				}
			}
			fallPuyo();
		}

		cout<<rensa<<endl;
	}

	return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
 
def main(S):
    for i in range(1 << len(S)):
        st = str(S[0])
        num = int(S[0])
        for j in range(len(S)-1):
            if((i >> j) & 1):
                st = st + "+" + str(S[j+1])
                num += int(S[j+1])
            else:
                st = st + "-" + str(S[j+1])
                num -= int(S[j+1])
        if(num == 7):
            print(st + "=7")
            break
    
if(__name__ == "__main__"):
    S = list(input())
    
    main(S)

Measured memory_bytes: 3188
// A_B_Problem.c
// ２つの整数 a と b を読み込んで、以下の値を計算するプログラムを作成して下さい
// ・a ÷ b ： d (整数)
// ・a ÷ b の余り ： r (整数)
// ・a ÷ b ： f (浮動小数点数)
// 【入力】
// 1行に２つの整数 a, b が与えられます。
// 【出力】
// d, r, f を１つの空白で区切って１行に出力して下さい。
// fについては、0.00001以下の誤差があってもよいものとします。
// 【制約】
// 1 ≤ a, b ≤ 10^9
// 【例】
// 入力：3 2、出力：1 1 1.50000
#include<stdio.h>

int main( void) {
  int a, b;
  int d, r;
  double f;

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

  d = a / b;
  r = a % b;
  f = (double)a / b;

  printf( "%d %d %.8lf\n", d, r, f);

  return 0;
}



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

int main() {
  int N, K; cin >> N >> K;
  vector<int> V(N);
  for (int i = 0; i < N; i++) cin >> V.at(i);
  int ans = 0;
  // 合計 i 個取り出す
  for (int i = 1; i <= min(N, K); i++) {
    // 前からは j 個
    for (int j = 0; j <= i; j++) {
      vector<int> v;
      for (int k = 0; k < j; k++) v.push_back(V.at(k));
      for (int l = 0; l < i-j; l++) v.push_back(V.at(N-1-l));
      sort(v.begin(), v.end());
      int sum = 0;
      for (int m = 0; m < v.size(); m++) sum += v.at(m);
      // 残り K-i 回は負の数を捨てる操作に使う
      for (int n = 0; n < min((int)v.size(), K-i); n++) {
        if (v.at(n) < 0) sum -= v.at(n);
      }
      ans = max(ans, sum);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pi = pair<int, int>;
using vi = vector<int>;
using vii = vector<pi>;
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(0); cin.tie(NULL);
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x)sz(a))
#define present(t, x) (t.find(x) != t.end())
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define forall(it, a) for(decltype((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define what_is(x) cerr << #x << " is " << (x) << endl;
#define db(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) \
	for(long blockTime=(long)NULL;(blockTime==(long)NULL?(blockTime=clock())!=(long)NULL:false); \
	debug("%s:%.4fs\n",(d),(double)(clock()-blockTime)/CLOCKS_PER_SEC))
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1); // pi
const ld EPS = 1e-9; // epsilon
#define eb emplace_back
#define ef emplace_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int imin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int imax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}

//time__("program time")

void solve(){

}

int main(){

	fast_io;
	//solve();
	int n;
	cin >> n;

	vector<int>a(n);
	rep(i,0,n){

		cin >> a[i];
	}

	int ans = *max_element(all(a)) - *min_element(all(a));

	cout << ans << "\n";

return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<(int)N;i++)
int main()
{
  int N,K,D,x,count=0;
  cin>>N>>K;
  vector<int> A(N,0);
  rep(i,K){cin>>D;rep(j,D){cin>>x;A.at(x-1)++;}}
  for(auto a:A)if(a==0)count++;
  return cout<<count<<endl,0;
}

Measured memory_bytes: 3600
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define swap(p,q) r=(p);(p)=(q);(q)=r
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007//10^9+7
#define PI acos(-1)

using namespace std;

ll int mod_inverse(int a,int M){
	int x=M-2;
	ll int temp=a;
	ll int ret=1;
	//a^(MOD-1)==1(mod MOD)を利用
	//a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める

	while(x!=0){
		if(x%2==1){
			ret=(ret*temp)%M;
		}
		temp=(temp*temp)%M;
		x=x/2;
	}
	return ret;
}

int main(void)
{
	//変数の宣言
	int n,a,b,c,d;
	static ll int dp[1010][1010];
	static ll int factorial[1010];
	static ll int ifp[1010][1010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	ll int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int ok,ng;



	//データの読み込み


	scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
//	scanf_s("%d %d %d %d %d",&n,&a,&b,&c,&d);


/*	for(i=0;i<m;i++){
//		scanf("%d %d %d",&u,&v,&s);
		scanf_s("%d %d %d",&u,&v,&s);
	}*/

	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

	factorial[0]=1;
	for(i=1;i<=n;i++){
		factorial[i]=factorial[i-1]*i%MOD;
	}

	for(i=0;i<=n;i++){
		temp1=factorial[i];
		temp=1;
		for(j=0;j<=n;j++){
			ifp[i][j]=mod_inverse(temp,MOD);
			temp=(temp*temp1)%MOD;
		}
	}


	for(i=0;i<1010;i++){
		for(j=0;j<1010;j++){
			dp[i][j]=0;
		}
	}

	dp[a-1][0]=1;
	for(i=a;i<=b;i++){
		for(j=0;j<=n;j++){
			k=0;
			while(j>=i*k&&(k==0||(c<=k&&k<=d))){
				temp=(dp[i-1][j-i*k]*factorial[n-j+i*k])%MOD;
				temp=(temp*ifp[n-j][1])%MOD;
				temp=(temp*ifp[i][k])%MOD;
				temp=(temp*ifp[k][1])%MOD;
				dp[i][j]=(dp[i][j]+temp)%MOD;
				if(k==0){
					k=c;
				}else{
					k++;
				}
			}
		}
	}


	//	printf("計算部分終了\n");

	//出力
	
/*	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			printf("dp[%d][%d]=%d ",i,j,dp[i][j]);
		}
		printf("\n");
	}*/


	printf("%lld",dp[b][n]);
	

	//	printf("結果の出力終了\n");


	return 0;
}



Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = (int)s.size();
    cout << s.substr(0,n-8) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	char s[100001];
	int a = scanf("%s", s);
	
	int cnt = 0;
	int zero_cnt = 0;
	int one_cnt = 0;
	while(1){
		if(s[cnt]=='0')
			if(cnt%2 == 0){
				one_cnt+= 1;
			}
			else{
				zero_cnt+=1;
			}
		else if(s[cnt]=='1'){
			if(cnt%2 == 0){
				zero_cnt+= 1;
			}
			else{
				one_cnt+=1;
			}
		}
		else{
			break;
		}
		cnt += 1;
	}
	
	int min = zero_cnt>=one_cnt?one_cnt:zero_cnt;
	//min = 0;
	printf("%d", min);
	return 0;
}

Measured memory_bytes: 256
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 2e3 + 10;

int h, w;
char grid[N][N];
vector < int > row[N], col[N];

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			cin >> grid[i][j];
			if (grid[i][j] == '#') {
				row[i].eb(j);
				col[j].eb(i);
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		row[i].eb(-1);
		row[i].eb(w);
		sort(all(row[i]));
	}
	for (int i = 0; i < w; ++i) {
		col[i].eb(-1);
		col[i].eb(h);
		sort(all(col[i]));
	}
	int res = 0;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (grid[i][j] == '#') {
				continue;
			}
			int curr = 0;
			{
				int hi = lower_bound(all(row[i]), j) - row[i].begin();
				int lo = hi - 1;
				curr += row[i][hi] - row[i][lo] - 1;
			}
			{
				int hi = lower_bound(all(col[j]), i) - col[j].begin();
				int lo = hi - 1;
				curr += col[j][hi] - col[j][lo] - 1;
			}
			res = max(res, curr - 1);
		}
	}
	cout << res << "\n";
}

Measured memory_bytes: 38272
str = gets.chomp.split("")
str.map! {|item| item.ord }

num = Array.new

i = 97 
26.times{
    
    num.push(str.count(i)%2) 
    
    i += 1
    }

if num.include?(1)
    puts "No"
else 
    puts "Yes"
end 


Measured memory_bytes: 1788
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

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

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = Array(3) { sc.next().toCharArray() }
        pw.println("${A[0][0]}${A[1][1]}${A[2][2]}")
    }
}


Measured memory_bytes: 31268
#include<iostream>
#include<cstdio>
#include<algorithm>
#define f first
#define s second
using namespace std;

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

bool PC(P& f,P& s){return f.s.s<s.s.s;}

int main()
{
	int n,m,p,y;
	P a[100010];
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		cin>>p>>y;
		a[i].f.f=p;
		a[i].f.s=y;
		a[i].s.f=0;
		a[i].s.s=i;
	}
	sort(a,a+m);
	p=a[0].f.f;
	y=0;
	for(int i=0;i<m;i++)
	{
		if(p!=a[i].f.f)p=a[i].f.f,y=0;
		a[i].s.f=++y;
	}
	sort(a,a+m,PC);
	for(int i=0;i<m;i++)printf("%012ld\n",(long)(a[i].f.f*1e6+a[i].s.f));
	return 0;
}

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

int A[] = { 1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049, 0 };

int main()
{
int i;
int j;
int a;
int N;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> N;

vector<int> X( N + 1, 0 );

	for( j = 0; A[ j ] > 0; j++ )
	{
		if( A[ j ] > N ) continue;
		if( A[ j ] == N )
		{
			cout << 1 << endl;

			return 0;
		}

		X[ A[ j ] ] = 1;
	}

	for( i = 1; i < N; i++ )
	{
		for( j = 0; A[ j ] > 0; j++ )
		{
			a = i + A[ j ];
			if( a > N ) continue;

			if( X[ a ] == 0 || X[ a ] > X[ i ] + 1 )
				X[ a ] = X[ i ] + 1;
		}
	}

	cout << X[ N ] << endl;

	return 0;
}


Measured memory_bytes: 640
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hope the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 5010;

int mod;

inline int Mod(int x) { return x >= mod ? x - mod : x; }
inline void Add(int &x, int y) { x += y, x -= x >= mod ? mod : 0; }

int f[MAXN][MAXN];
int g[MAXN][MAXN];
int S[MAXN * 2];

int main() {
	int n = ri; mod = ri;
	int N = (n + 1) / 2;

	f[0][0] = 1;
	for(int i = 1; i <= N; i++)
		for(int j = 0; j <= n; j++)
			for(int k = j; k <= n; k += i)
				Add(f[i][k], f[i - 1][j]);

	g[0][0] = 1;
	for(int i = N - 1; i >= 1; i--) {
		for(int j = 0; j <= n; j++) {
			if(i * j >= n) break;
			for(int k = i * j; i + k <= n; k++)
				if(i + k <= n)
					Add(g[j + 1][k + i], g[j][k]);
		}
	}

	for(int i = 0; i <= n; i++)
		for(int j = 1; j <= n; j++)
			Add(g[i][j], g[i][j - 1]);
	for(int i = 1; i <= n; i++)
		for(int j = 0; j <= n; j++)
			Add(g[i][j], g[i - 1][j]);

	int n1 = N, n2 = N - 1;
	int res = 0;
	if(!(n & 1)) {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1][i] * g[n - x][x - i - 1]) % mod;
	} else {
		for(int x = 1; x <= n; x++)
			for(int i = 0; i < x; i++)
				res = (res + 1LL * f[n1 - 1][i] * g[n - x][x - i - 1]) % mod;
	}
/*
	for(int i = 0; i <= n; i++) printf("%d\n", S[i]);

	for(int i = 1; i <= n; i++) Add(S[i], S[i - 1]);

	int res = 0;
	for(int i = 0; i < n; i++) Add(res, S[i]);
*/
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 147712
import sys
input = sys.stdin.buffer.readline

n, k = map(int, input().split())
TD = [[0, 0] for _ in range(n)]
for i in range(n):
    t, d = map(int, input().split())
    TD[i][0], TD[i][1] = d, t

TD.sort(reverse=True)
S = set()
f = 0
h = []
import heapq
heapq.heapify(h)
for i in range(k):
    d, t = TD[i]
    if t in S:
        heapq.heappush(h, d)
    else:
        S.add(t)
    f += d

INF = 10**18
F = [-INF]*(k+1)
cur = len(S)
F[cur] = f

for i in range(k, n):
    d, t = TD[i]
    if t in S:
        continue
    else:
        if h:
            x = heapq.heappop(h)
            f += d-x
            S.add(t)
            cur += 1
            F[cur] = f

for i in range(0, k+1):
    F[i] += i*i

print(max(F))


Measured memory_bytes: 59184
//https://atcoder.jp/contests/code-festival-2017-qualb/tasks/code_festival_2017_qualb_a
//A - XXFESTIVAL
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int main() {
    string S; cin>>S;    
    REP(i,8){
        S.pop_back();
    }
    cout<<S<<endl;
    return 0;
}

Measured memory_bytes: 764
#include<cstdio>
#include<iostream>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0,f=0;re char v=getchar();
	while(v<'0')f|=(v=='-'),v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return f?-t:t;
}
int n,a,b,c,d,e;
signed main(){
	a=read();b=read();c=read();d=read();e=read();
	if(a>c)swap(a,c);
	a+=b*e;c+=d*e;
	if(a>=c)puts("YES");
	else puts("NO");
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e4+100;
int sum[maxn];
int n,a,b;

int f(int n)
{
    if (n==0) return 0;
    return n%10+f(n/10);
}

void _init()
{
    memset(sum,0,sizeof(sum));
    for (int i=1;i<maxn;i++)
        sum[i]=f(i);
}

int main()
{
    //freopen("1.txt","r",stdin);
    _init();
    while (scanf("%d%d%d",&n,&a,&b)!=EOF)
    {
        long long ans=0;
        for (int i=1;i<=n;i++)
            if (sum[i]<=b && sum[i]>=a)
                ans+=i;

        printf("%lld\n",ans);
    }
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
int main(){
  int a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  int cnt=0;
  while(a%2==0&&b%2==0&&c%2==0){
    int aa=b/2+c/2,bb=a/2+c/2,cc=a/2+b/2;
    a=aa;b=bb;c=cc;cnt++;
    if(cnt>100000000){
      printf("-1\n");return 0;
    }
  }
  printf("%d\n",cnt);
  return 0;
}


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

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> x(m);
  rep(i,m) cin >> x[i];
  
  if(n>=m){
    cout << 0 << endl;
    return(0);
  }
  
  sort(x.begin(),x.end());
  
  ll ans=x[m-1]-x[0];
  
  vector<ll> y(m-1);
  rep(i,m) y[i] = x[i+1]-x[i];
  sort(y.begin(),y.end());
  reverse(y.begin(),y.end());
  
  rep(i,n-1){
    ans -= y[i];
  }
  
  cout << ans << endl;
  
  return(0);
}

Measured memory_bytes: 4676
#include<iostream>
using namespace std;
int main( )
{
    bool prime[10001];
    int a[10001];
    int i,j,k;
    for(i=0; i<=10000; ++i)
    {
        prime[i]=true;
        a[i]=0;
    }
    prime[0]=false;
    prime[1]=false;
    for(i=2; i<=5000; ++i)
        for(j=2; j*i<=10000; ++j)
        {
            if(prime[i]==true)
                prime[j*i]=false;
        }
    for(i=1;i<=10000;++i)
    {
        for(k=1;k<=i;++k)
        {
            if(prime[k]==1&&prime[i-k+1]==1)
            ++a[i];
        }
    }
    int n;
    while(cin>>n)
    {
        cout<<a[n]<<endl;
    }
    return 0;
}

Measured memory_bytes: 912
import java.util.Scanner;

//Factorization of Quadratic Formula
public class Main{

	long gcd(long a, long b){
		return b==0?a:gcd(b, a%b);
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if((a|b|c)==0)break;
			double D = b*b-4*a*c;
			if(D<0)System.out.println("Impossible");
			else if(D==0){
				int A = 2*a;
				int B = -b;
				long g = gcd(Math.abs(A), Math.abs(B));
				A/=g;
				B/=g;
				System.out.println(A+" "+(-B)+" "+A+" "+(-B));
			}
			else{
				int k = 1;
				while(k*k<=D){
					if(k*k==D)break;
					k++;
				}
				if(k*k>D){
					System.out.println("Impossible");continue;
				}
				int P = 2*a;
				int Q = -b+k;
				int R = 2*a;
				int S = -b-k;
				long g = gcd(Math.abs(P), Math.abs(Q));
				P/=g;
				Q/=g;
				g = gcd(Math.abs(R), Math.abs(S));
				R/=g;
				S/=g;
				Q=-Q;
				S=-S;
				if(P>R||(P==R&&Q>S))System.out.println(P+" "+Q+" "+R+" "+S);
				else System.out.println(R+" "+S+" "+P+" "+Q);
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000