akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

const int NILL = -1;

typedef long int lint;

typedef struct node
{
  lint key;
  struct node* parent;
  struct node* left;
  struct node* right;
  
}TREE;

TREE* root = NULL;//initial condition

void insert(TREE* t)
{
  TREE* x;
  TREE* y;

  y = NULL;
  x = root;

  while(x != NULL)//if not node* x is NULL, search where to insert node t  
  {
    y = x;
    if(t->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  t->parent = y; //<=抜け忘れ注意
  
  //if parent of node x is NULL
  if(y == NULL) root = t;
  else if(t->key < y->key){
    y->left = t;
  }
  else{
    y->right = t;
  }
}

TREE* find(lint key)
{
  TREE* p = root;//start to search node from root
  
  while(p != NULL && p->key != key){
    if(p->key > key){
      p = p->left;
    }
    else{
      p = p->right;
    }
  }
  //p->keyだとsegmentation faultになるので注意
  if(p == NULL) return NULL;
  else return p;
}

TREE* getMin(TREE* u)
{
  if(u->left == NULL) return u;
  else getMin(u->left);
}

TREE* getSuccessor(TREE* u)
{
  if(u->right != NULL) return getMin(u->right);

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

void delete(TREE* u)
{
  TREE* delnode;
  TREE* delchild;
  
  //if(u->left == NULL && u->right == NULL) free(u);
  if(u->left == NULL || u->right == NULL) delnode = u;
  else delnode = getSuccessor(u);

  if(delnode->left != NULL) delchild = delnode->left;
  else delchild = delnode->right;

  if(delchild != NULL){
    delchild->parent = delnode->parent;
  }
  
  if(delnode->parent == NULL) root = delchild; //ex.insert2回目など
  else{
    if(delnode == delnode->parent->left){
      delnode->parent->left = delchild;
    }
    else{
      delnode->parent->right = delchild;
    }
  }

  if(delnode != u) u->key = delnode->key;

  free(delnode);
}

void PreOrder(TREE* n)
{
  if(n == NULL) return;
  printf(" %ld",n->key);
  PreOrder(n->left);
  PreOrder(n->right);
}

void InOrder(TREE* n)
{
  if(n == NULL) return;
  InOrder(n->left);
  printf(" %ld",n->key);
  InOrder(n->right);
}

void print()
{
  InOrder(root);
  printf("\n");
  PreOrder(root);
  printf("\n");
}

int main()
{
  int m;
  int i;
  char order[20];
  lint key;
  
  scanf("%d",&m);

  for(i = 0; i < m;i++){
    scanf("%s",order);
    
    if(order[0] == 'i'){
      scanf("%ld", &key);

      TREE* t = (TREE *)malloc(sizeof(TREE));
      t->right = t->left = NULL;
      t->key = key;
      
      insert(t);
    }
    else if(order[0] == 'd'){
      scanf("%ld", &key);

      TREE* u = find(key);
      if(u != NULL) delete(u);
    }
    else if(order[0] == 'f'){
      scanf("%ld",&key);
      
      if(find(key) != NULL) printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(order,"print") == 0){
      print();
    }
  }
  return 0;
}


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

signed main(){
  string s; cin >> s;
  lint N = s.size();
  vector<lint> left(N), right(N);
  lint start = 0;
  for(lint i = 0; i < N; i++){
    if(s[i] == 'R'){
      start = i;
    }
    left[i] = start;
  }
  start = N - 1;
  for(lint i = N - 1; i >= 0; i--){
    if(s[i] == 'L'){
      start = i;
    }
    right[i] = start;
  }
  vector<lint> ans(N);
  for(lint i = 0; i < N; i++){
    if(s[i] == 'R'){
      if(abs(i - right[i]) % 2 == 0) ans[right[i]]++;
      else ans[right[i] - 1]++;
    }
    if(s[i] == 'L'){
      if(abs(i - left[i]) % 2 == 0) ans[left[i]]++;
      else ans[left[i] + 1]++;
    }
  }
  for(lint i = 0; i < N; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 3072
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;



signed main(){
	int x;
	cin >> x;
	out(x ^ 1);
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;

int main(){
    ll A,B;cin>>A>>B;
    double s=A/0.08,t=B/0.1;
    for(ll i=(ll)(min(s,t)-1);i<=max(s,t)+1;i++){
        ll u=i*0.08,v=i*0.1;
        if(u==A&&v==B){cout<<i<<endl;return 0;}
    }
    cout<<-1<<endl;
}
      

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.rbegin(), a.rend());
	priority_queue<P> pq;
	pq.push(P(a[0], a[0]));
	ll ans = 0;
	for(int i = 1; i < n; ++i){
		P p = pq.top();
		pq.pop();
		ans += p.first;
		pq.push(P(a[i], p.first));
		pq.push(P(a[i], p.second));
	}
	std::cout << ans << endl;
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);

    int n, x;
    while(true) {
        cin >> n >> x;
        if(n == 0 && x == 0) break;
        int ans = 0;
        FOR(i, 1, n + 1) FOR(j, i + 1, n + 1) {
            if( j + 1 <= x - i - j && x - i - j <= n) ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3124
# collections.deque is implemented using doubly linked list at C level..
from collections import deque

linkedlist = deque()

for _ in range(int(input())):
    input_command = input()
    if input_command == 'deleteFirst':
        linkedlist.popleft()

    elif input_command == 'deleteLast':
        linkedlist.pop()
    
    else:
        com, num = input_command.split()
        if com == 'insert':
            linkedlist.appendleft(num)

        elif com == 'delete':
            try:
                linkedlist.remove(num)
            except:
                pass
            

print(' '.join(linkedlist))


Measured memory_bytes: 69740
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func stringLineScan() string {
	sc.Scan()
	return sc.Text()
}

var searched []bool
var count int

func main() {
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	m, _ := strconv.Atoi(stringLineScan())
	k, _ := strconv.Atoi(stringLineScan())
	f := make(map[int][]int)
	block := make(map[int][]int)
	ab := make(map[string]struct{})
	for i := 0; i < m; i++ {
		a, _ := strconv.Atoi(stringLineScan())
		b, _ := strconv.Atoi(stringLineScan())
		a--
		b--
		if _, ok := f[a]; ok == false {
			x := make([]int, 0)
			f[a] = x
		}
		if _, ok := f[b]; ok == false {
			x := make([]int, 0)
			f[b] = x
		}
		f[a] = append(f[a], b)
		f[b] = append(f[b], a)
		ab[fmt.Sprint(b, a)] = struct{}{}
		ab[fmt.Sprint(a, b)] = struct{}{}
	}
	for i := 0; i < n; i++ {
		searched = append(searched, false)
	}
	for i := 0; i < k; i++ {
		c, _ := strconv.Atoi(stringLineScan())
		d, _ := strconv.Atoi(stringLineScan())
		c--
		d--
		if _, ok := block[c]; ok == false {
			x := make([]int, 0)
			block[c] = x
		}
		if _, ok := block[d]; ok == false {
			x := make([]int, 0)
			block[d] = x
		}
		block[c] = append(block[c], d)
		block[d] = append(block[d], c)
		ab[fmt.Sprint(c, d)] = struct{}{}
		ab[fmt.Sprint(d, c)] = struct{}{}
	}
	group := make([]int, n)
	ans := make([]int, n)
	init := 0
	for i := 0; i < n; i++ {
		for j := init; j < n; j++ {
			if !searched[j] {
				searched[j] = true
				init = j
				count++
				break
			}
		}
		result := make([]int, 1)
		result[0] = init
		result = splitter(init, f[init], f, result)
		l := len(result) - 1
		for _, j := range result {
			ans[j] = l
			group[j] = init
		}
		if count == n {
			break
		}
	}
	for k, list := range f {
		for _, v := range list {
			if _, ok := ab[fmt.Sprint(k, v)]; group[k] == group[v] && ok {
				ans[k]--
			}
		}
	}
	for k, list := range block {
		for _, v := range list {
			if _, ok := ab[fmt.Sprint(k, v)]; group[k] == group[v] && ok {
				ans[k]--
			}
		}
	}
	fmt.Println(strings.Trim(fmt.Sprint(ans), "[]"))
}
func splitter(init int, list []int, f map[int][]int, result []int) []int {
	for _, i := range list {
		if !searched[i] {
			searched[i] = true
			count++
			result = append(result, i)
			result = splitter(i, f[i], f, result)
		}
	}
	return result
}


Measured memory_bytes: 67348
#include<bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/detail/standard_policies.hpp>
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>ordered_set;
/////////////////// TYPES & MACROS ///////////////////////////////
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define vv vector
#define exist(e,s) (s.find(e)!=s.end())
#define ll long long int 
#define dd double
#define pii pair<int,int>
#define pll pair<ll,ll>
// #define int ll
typedef vector<int> vi;
ll INFLL=(ll)2e18, MOD=1e9+7;
const int INF=0x6f6f6f6f;
///////////*//////// DEBUG /////////////////////////////////////////
#ifdef DEBUG
#define D(x) cerr<<#x<<" is: "<<x<<'\n';
#define DD(x,y) cerr<<'('<<#x<<','<<#y<<") are: "<<x<<' '<<y<<'\n';
#define DDD(x,y,z) cerr<<'('<<#x<<','<<#y<<','<<#z<<") are: "<<x<<' '<<y<<' '<<z<<'\n';
auto tStart = chrono::system_clock::now(); //freopen("op.txt","w",stdout);
#else 
#define D(x) ;
#define DD(x,y) ;
#define DDD(x,y,z) ;
#endif
/////////////////// VARIABLES & FUNCTIONS//////////////////////////
vv<vv<pll>> adj; vi vis;
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1},dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};
inline ll mexp(ll x,ll n,ll m){ll res=1;while(n){if(n&1)res=(res*x)%m;n>>=1;x=((x%m)*(x%m))%m;}return res;}
inline bool ispow2(ll x){ return x && (!(x&(x-1)));}
inline ll gcd(ll x, ll y){ pll p{x,y}; while(p.ss) p={p.ss,p.ff%p.ss}; return p.ff;}

struct elem{
  ll x,y,h;
};
/////////////////// MAIN STARTS //////////////////////////////////
int32_t main(void){
ios_base::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
cout<<fixed;cerr<<fixed; cout<<setprecision(10); cerr<<setprecision(3);
mt19937 genr(chrono::high_resolution_clock::now().time_since_epoch().count());

int n,m; cin>>n>>m;
for(int i=m/n;i>0;--i){
  int rem=m-i*n;
  if(rem%i==0) {cout<< i <<'\n'; break;}
}

#ifdef DEBUG
auto diff=chrono::system_clock::now()-tStart;
cerr<<"\nExecution time: "<<chrono::duration<dd,milli>(diff).count()<<" ms.\n";
#endif
return 0;
}

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

#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define fill(a, z) memset(a, z, sizeof(a))
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << z << ' '
#define cnl(z) cout << z << '\n'
#define printclock cerr<<"Time : "<<1000*(double)clock()/(double)CLOCKS_PER_SEC<<"ms\n";
#define M 1000000007
#define M2 998244353
#define MAXN 300005
#define INF 1000000000000
#define endl "\n"
#define iip(t) \
	int t;     \
	cin >> t;
#define iip2(a, b) \
	int a, b;      \
	cin >> a >> b;
#define dip(a) \
	double a;  \
	cin >> a;
#define dip2(a, b) \
	double a, b;   \
	cin >> a >> b;
#define garr(ip)       \
	for (auto &x : ip) \
		cin >> x;
#define parr(ip)          \
	for (auto &x : ip)    \
		cout << x << " "; \
	cout << endl;
#define test   \
	int _t;    \
	cin >> _t; \
	while (_t--)

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

int modExp(int base, int exponent, int MOD = M)
{
	if (exponent == 0)
		return 1;
	int curr = modExp(base, exponent >> 1);
	curr = (curr * curr) % MOD;
	if (exponent & 1)
		curr = (curr * base) % MOD;
	return curr;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int r;
	cin >> r;
	double ans = 6.28318530717958623200 * r;
	cout << setprecision(9) << fixed << ans << endl;
}

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

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}


int main(){
    int n;
    cin >> n;
    vector<ll>a(n),s(n);
    rep(i,n){
        cin >> a[i];
        s[i] += a[i];
        if(i!=0)s[i] += s[i-1];
    }
    ll ans = 1LL<<60;
    for(int i=1;i<n-1;i++){
        vector<ll> p;
        ll tmp1,tmp2;
        ll x = s[i];
        ll tx = (x+1)/2;
        ll ind = lower_bound(s.begin(),s.end(),tx)-s.begin();
        ll pp,qq;
        if(ind==0){
            pp = s[0];
            qq = s[i]-s[0];
        }else{
            pp = s[ind-1];
            qq = s[i]-s[ind-1];
            if(abs(pp-qq)>abs(s[ind]-(s[i]-s[ind]))){
                pp = s[ind];
                qq = s[i]-s[ind];
            }
        }
        //cerr << pp << " " << qq << " ";
        p.PB(pp);p.PB(qq);
        ll y = s[n-1]-s[i];
        ll ty = s[i] +  (y+1)/2;
        ind = lower_bound(s.begin(),s.end(),ty)-s.begin();
        if(ind==i+1){
            pp = s[i+1]-s[i];
            qq = s[n-1]-s[i+1];
        }else{
            pp = s[ind-1]-s[i];
            qq = s[n-1]-s[ind-1];
            if(abs(pp-qq)>abs(s[ind]-s[i]-(s[n-1]-s[ind]))){
                pp = s[ind]-s[i];
                qq = s[n-1]-s[ind];
            }
        }

       // cerr << pp << " " << qq << endl;
        p.PB(pp);p.PB(qq);
        sort(p.begin(),p.end());
        ans = min(ans,p[3]-p[0]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <list>
#include <algorithm>
using namespace std;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >> n;
    list<int> li;

    for (int i=0; i<n; ++i) {
        string op; cin >> op;
        if (op[0] == 'i') {
            int key; cin >> key;
            li.push_front(key);
        } else if (op.size() > 6 && op[6] == 'F') {
            li.pop_front();
        } else if (op.size() > 6 && op[6] == 'L') {
            li.pop_back();
        } else {
            int key; cin >> key;
            list<int>::iterator pos = find(li.begin(), li.end(), key);
            if (pos != li.end()) {
                li.erase(pos);
            }
        }
    }

    for (list<int>::iterator it = li.begin(); it != li.end(); ++it) {
        cout << ((it == li.begin()) ? "" : " ") << *it;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 32472
#include <iostream>
#include <algorithm>
#include <iterator>

using namespace std;

//print the number of divisors of c between a and b
int main()
{
    int a, b, c, s = 0;

    cin >> a >> b >> c;
    
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
            s++;
    }

    cout << s << endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  if (m%n==0){
      cout << m/n << endl;
  } else {
      for(int i = m/n; i>0; i--){
          if(m%i==0){
              cout << i << endl;
              break;
          }
      }
  }
}

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

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //-----------------------------------------
    string S;
    cin >> S;

    rep(i, S.length())
    {
        cout << 'x';
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);

	int D;
	cin >> D;

	vector<int> c(26);

	REP(i, 26)
	{
		cin >> c[i];
	}

	vector<vector<int>> s(D, vector<int>(26));

	REP(d, D)
	{
		REP(j, 26)
		{
			cin >> s[d][j];
		}
	}


	vector<int> last(26, 0);
	int sat = 0;

	REP(d, D)
	{
		//int mi = 0;
		//REP(i, 26)
		//{
		//	if (s[d][mi] < s[d][i])mi = i;
		//}
		//last[mi] = d;

		int t;
		cin >> t;
		t--;
		last[t] = d + 1;



		sat += s[d][t];
		REP(i, 26)
		{
			sat -= c[i] * (d + 1 - last[i]);
		}
		cout << sat << endl;
	}
	return 0;
}

Measured memory_bytes: 3648
eval"N,A,*X="+`dd`.split*?,;d=[0]*2e4;d[N*=A]=1;p=[0]*2e4;X.map{|x|(0..2*N).map{|j|p[j]=d[j]+d[j-x+A]};d,p=p,d};p d[N]-1

Measured memory_bytes: 4356
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000
 
int main(){
  int *A,*B;
 
  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);
 
  A=malloc(sizeof(int)*n+1);
  B=malloc(sizeof(int)*n+1);
 
  for(i=0;i<=VMAX;i++) C[i]=0;
 
  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }
 
  for(i=1;i<=VMAX;i++) C[i]+=C[i-1];
 
  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
 
 
  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 16276
#include <algorithm>
#include <array>
#include <atomic>
#include <bitset>
#include <chrono>
#include <complex>
#include <condition_variable>
#include <deque>
#include <exception>
#include <forward_list>
#include <fstream>
#include <functional>
#include <future>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <mutex>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <typeinfo>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
#include <cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
//constexpr int INF = 1<<30;
//constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
int N;

int main(int argc, char** argv) {
  cin >> N;
  vll A(N);
  for (int i=0; i<N; i++) {
    cin >> A[i];
  }

  ll a = A[0];
  for (int i=1; i<N; i++) {
    a += A[i]*(i%2==0 ? 1 : -1);
  }
  vll ret(N);
  ret[0] = a/2;
  for (int i=1; i<N; i++) {
    ret[i] = A[i-1]-ret[i-1];
  }
  for (int i=0; i<N; i++) {
    cout << ret[i]*2;
    if (i<N-1) cout << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 2944
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18


int main() {

	string s; cin >> s;

	vector<int> cnt(3);

	for (char c : s) {
		++cnt[c - 'a'];
	}

	sort(cnt.begin(), cnt.end());

	int d = abs(cnt[0] - cnt[2]);

	if (d == 0 || d == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 512
# coding: utf-8


def solve(*args: str) -> str:
    n, x, m = map(int, args[0].split())

    a = x
    ret = 0
    D = [-1]*(m+1)
    for i in range(n):
        if 0 <= D[a]:
            j = a
            L = []
            while D[j] != a:
                L.append(j)
                j = D[j]
            L.append(j)
            d, r = divmod(n-i-1, len(L))
            ret += d*sum(L)+sum(L[:r+1])
            break
        ret += a
        p = a
        a = pow(a, 2, m)
        D[p] = a

    return str(ret)


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


Measured memory_bytes: 11656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 int main(){
     double a,b,c;
     double rc;
     double S,L,h,cr;
     double PI = acos(-1);
    /*
    ラジアンについて
        ラジアンの求め方
        ラジアン = Θ*π/180
    三角関数・逆三角関数について
        sin x = yのときarcsin y = xである
    */
    /*
        degree=度
        radian=ラジアン
    */
    /*
        cos(PI)=-1
        なら
        acos(-1)=PI
    */
   //tan c / a = d
    scanf("%lf %lf %lf",&a,&b,&c);
    //printf("a=%lf\n",a);//d
    //printf("b=%lf\n",b);//d
    //printf("c=%lf\n",c);//d
    rc = c*PI/180;
    S = (a*b*sin(rc))/2;
    L = a+b+sqrt(pow(a,2) + pow(b,2) - 2*a*b*cos(rc));
    h = (S*2)/a;
    printf("%lf\n%lf\n%lf\n",S,L,h);
    return 0;
 }



Measured memory_bytes: 2144
#include <stdio.h>

int main(void){
	int i;
	int n, a[101];
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &a[i]);
	}
	for(i=n-1;i>=0;i--){
		printf("%d", a[i]);
		if(i==0) break;
		else printf(" ");
	}
	printf("\n");
	return 0;
}



Measured memory_bytes: 2732
S,T=[0],[0]
for k,c in enumerate(input()):S+=[S[-1]+(c=='A')]
for k,c in enumerate(input()):T+=[T[-1]+(c=='A')]
for _ in[0]*int(input()):
    a,b,c,d=map(int,input().split())
    print(['YES','NO'][(2*(b-a-d+c)+T[d]-T[c-1]-S[b]+S[a-1])%3>0])

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

void solve(long long N, std::vector<long long> a) {
    vector<vector<ll>> ans(N, vector<ll>(10));
    ll xortmp = 0;
    rep(i, N) { xortmp ^= a[i]; }
    rep(i, N) {
        ll tmp = xortmp ^ a[i];
        cout << tmp << " ";
    }
    cout << endl;
}

int main() {
    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const ll LINF = 1e18 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int N, M;

struct Edge {
  Edge(int _from, int _to, ll _cost)
    : from(_from), to(_to), cost(_cost) {}
  int from;
  int to;
  ll cost;
};

vector< Edge > e;
ll d[MAX_N];
// bool state[MAX_N];

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

  fill_n(d, MAX_N, LINF);

  cin >> N >> M;
  vector< int > a(M);
  vector< int > b(M);
  vector< ll > c(M);
  REP(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--; b[i]--;
    e.emplace_back(Edge(a[i], b[i], -1ll * c[i]));
  }

  d[0] = 0ll;
  // state[0] = true;
  
  REP(i, N) {
    
    EACH(ei, e) {
      // if (!state[ei.from]) continue;
      if (d[ei.from] != LINF && d[ei.to] > d[ei.from] + ei.cost) {
	d[ei.to] = d[ei.from] + ei.cost;
	// state[ei.to] = true;
	
	if (i == N - 1 && ei.to == N - 1) {
	  cout << "inf" << endl;
	  return 0;
	}
      }
    }
  }

  
  ll ans = -1ll * d[N - 1];
  cout << ans << endl;

  /*
  REP(i, N) {
    debug(d[i]);
  }
  */
  
  return 0;
}



Measured memory_bytes: 1152
#include <bits/stdc++.h>
using i64 = int_fast64_t;
#define repeat(i, a, b) for(int i = (a); (i) < (b); ++(i))
#define rep(i, n) repeat(i, 0, n)

int a[210000];

void solve() {
    int n;
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    auto calc = [&](int b) {
        i64 ret = 0;
        rep(i, n) {
            ret += abs(a[i] - (b + i));
        }
        return ret;
    };
    int left = -1e9, right = 1e9;
    int cnt = 0;
    while(cnt < 1000) {
        int l = left + (right - left) / 3;
        int r = right - (right - left) / 3;
        if(calc(l) < calc(r)) {
            right = r;
        } else {
            left = l;
        }
        cnt++;
    }
    i64 ans = std::numeric_limits<i64>::max();
    repeat(i, left, right + 1) {
        ans = std::min<i64>(ans, calc(i));
    }
    printf("%lld\n", ans);
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    solve();
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9
#define MOD 1000000007

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int ans;
    if(n%111 == 0) ans = n/111*111;
    else ans = (n/111+1)*111;

    cout << ans << endl;
}


Measured memory_bytes: 256
console.log((args=>{
  const [[N,K],A] = args.trim().split('\n').map( r=>r.split(' ').map(v=>v|0) );
  const MOD = BigInt(1e9+7), mul = (a,b) => (BigInt(a)*BigInt(b)%MOD+MOD)%MOD;
  if ( K === N ) return `${A.reduce(mul,1)}`;
  let Am = [], Ap = [], zero = 0;
  for ( let i = 0; i < N; i++ ) {
    if ( A[i] > 0 ) Ap.push(A[i]);
    if ( A[i] < 0 ) Am.push(A[i]);
    if ( A[i] === 0 ) zero++;
  }
  if ( K+zero > N ) return '0';
  Am.sort((a,b)=>a-b);
  Ap.sort((a,b)=>b-a);
  if ( Ap.length === 0 && K&1 ) return zero?'0':`${ Am.slice(-K).reduce(mul,1) }`;
  let om = 0, op = 0, ap = [], am = [];
  for ( let i = 0; i < K; i++ ) {
    if ( (Ap[op]|0) > -(Am[om]|0) ) {
      ap.push(Ap[op]); op++;
    } else {
      am.push(Am[om]); om++;
    }
  }
  if ( am.length&1 ) {
    if ( am.length === Am.length 
      || BigInt(Ap[op]|0)*BigInt(Ap[op-1]|0) > BigInt(Am[om-1]|0)*BigInt(Am[om]|0)
      || am.length === K ) {
      am.pop();
      ap.push(Ap[op]);
    }
    else {
      ap.pop();
      am.push(Am[om]);
    }
  }
  return `${mul(ap.reduce(mul,1),am.reduce(mul,1))}`;
})(require('fs').readFileSync('/dev/stdin', 'utf8')));


Measured memory_bytes: 72976
#include <stdio.h>

int main(){
  int x,y,temp;
  while(1){
    scanf("%d %d",&x,&y);
    if(x!=0||y!=0){
      if(x>y){
        temp=x;
        x=y;
        y=temp;
      }
      printf("%d %d\n",x,y);
    }else{
      break;
    }
  }
  return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> a;
	for (int i = 1; i < 10; ++i) {
		for (int j = 1; j < 10; ++j) a.push_back(i * j);
	}
	if (a.end() == find(a.begin(), a.end(), N)) cout << "No";
	else cout << "Yes";
}

Measured memory_bytes: 256
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
#define MOD 1000000007
using namespace std;
signed main() {
  int N, M;
  cin >> N;
  vector<string> U(N);
  for (int i = 0; i < N; i++) {
    cin >> U[i];
  }

  cin >> M;
  int state = 0; // 0:locked, 1:unlocked
  for (int i = 0; i < M; i++) {
    string s; cin >> s;
    int unknown = 1;
    for (int j = 0; j < N; j++) {
      if (s == U[j]) {
        if (state == 0) {
          state = 1;
          cout << "Opened by ";
        } else {
          state = 0;
          cout << "Closed by ";
        }
        cout << s << endl;
        unknown = 0;
        break;
      }
    }
    if (unknown) {
      cout << "Unknown " << s << endl;
    }
  }
}




Measured memory_bytes: 3232
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <functional>
#include <bitset>

using namespace std;

int main()
{
	long N, X;
	cin >> N >> X;

	vector<unsigned long> vec_i(N);
	for (int ic = 0; ic < N; ic++) {
		long buf;
		cin >> buf;
		vec_i[ic] = buf;
	}

	long Buf = 0;
	//long Output = 0;
	int count = 0;

	if(X != 0){
		count = 1;

		for (int ic = 0; ic < N; ic++) {
			Buf += vec_i[ic];
			if (Buf > X) {
				break;
			}
			count++;
		}

	}

	std::cout << count;


	return 0;
}


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

double dp[301][301][301];

int main() {
  int n;
  int hist[3] = {0, 0, 0};
  cin >> n;
  rep(i, n+1)rep(j, n+1)rep(k, n+1){
    dp[i][j][k] = 0;
  }
  rep(i,n+1) rep(j,n+1) rep(k,n+1) {
    double e = 0, ijk = i+j+k;
    if (i+j+k > 0) e += double(n)/ijk;
    if (k > 0) e += dp[i][j][k-1]*(double(k)/ijk);
    if (j > 0) e += dp[i][j-1][k+1]*(double(j)/ijk);
    if (i > 0) e += dp[i-1][j+1][k]*(double(i)/ijk);
    dp[i][j][k] = e;
  }
  int h;
  rep(i, n) {cin >> h; hist[h-1]++;}
//  rep(i, n+1) {rep(j, n+1) {rep(k, n+1) cout << dp[i][j][k]; cout << endl;} cout << endl;}
  cout << setprecision(20) << dp[hist[2]][hist[1]][hist[0]] << endl;
}


Measured memory_bytes: 213248
#include <bits/stdc++.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;

int main() {
	
	string s;
	cin >> s;
	printf("%c%d%c\n", s[0], (int) s.size()-2, s[s.size()-1]);
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
	vector<string>v(2);
	cin>>v[0]>>v[1];
	for(int i=0;i<2;i++){
		int cur=i,z=0;
		vector<int>idx(2);
		for(;z<v[0].size();z++,cur^=1){
			for(;idx[cur]<v[cur].size()&&v[cur][idx[cur]]!=v[0][z];idx[cur]++);
			if(v[cur][idx[cur]]!=v[0][z])break;
			idx[cur]++;
		}
		if(z==v[0].size()){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

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

using namespace std;

using llint = long long;

const int MAXN = 200100;

int n;
llint arr[MAXN];
llint sum[MAXN];
llint pref[MAXN];
llint suff[MAXN];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int i, j;
	llint sol = 1ll<<60;
	
	cin>>n;
	
	for (i = 0; i < n; ++i)
	{
		cin>>arr[i];
		sum[i + 1] = sum[i] + arr[i];
	}
	
	for (j = 1, i = 2; i <= n; ++i)
	{
		while (j + 1 < i && abs(sum[i] - 2 * sum[j + 1]) < abs(sum[i] - 2 * sum[j]))
			++j;
		
		pref[i] = abs(sum[i] - 2 * sum[j]); 
	}
	
	for (j = n - 1, i = n - 2; i >= 0; --i)
	{
		while (j - 1 > i && abs(sum[n] - sum[i] - 2 * (sum[n] - sum[j - 1])) < abs(sum[n] - sum[i] - 2 * (sum[n] - sum[j])))
			--j;
		
		suff[i] = abs(sum[n] - sum[i] - 2 * (sum[n] - sum[j]));
	}
	
	for (i = 2; i <= n - 2; ++i)
	{
//		cout<<i<<": "<<(sum[i] + pref[i]) / 2<<' '<<(sum[i] - pref[i]) / 2<<", "<<(sum[n] - sum[i] + suff[i]) / 2<<' '<<(sum[n] - sum[i] - suff[i]) / 2<<endl;
		sol = min(sol, max((sum[i] + pref[i]) / 2, (sum[n] - sum[i] + suff[i]) / 2) - min((sum[i] - pref[i]) / 2, (sum[n] - sum[i] - suff[i]) / 2));
	}
	
	cout<<sol<<'\n';
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int A[3], B[3] = {1, 0, -1};
int K;

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

  for(int i=0;i<3;++i){
      std::cin >> A[i];
  }

  std::cin >> K;

  int res = 0;

  for(int i=0;i<3;++i){
      int n = std::min(A[i], K);
      res += n * B[i];
      K -= n;
  }

  std::cout << res << std::endl;
}


Measured memory_bytes: 3652
#include <iostream>
#define STA 123456
using namespace std;

int Prime[STA*2+1]={0};
void P_num(){
    Prime[0] = Prime[1] = 1;
    for(int i=2;i<=STA;i++){
        for(int j=2;i*j<=STA*2;j++) Prime[i*j] = 1;
    }
}

int main(){
    P_num();
    int n;
    while(cin >>n,n){
        int ans = 0;
        for(int i=n+1;i<=2*n;i++){
            if(Prime[i] == 0) ans++;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 2124
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
using namespace std;
map<vector<int>,int>memo;

int M,N;
vector<string>*vp;
int dfs(vector<int> &t){
	if(t.size()==1)return 0;
	if(memo.find(t)!=memo.end())return memo[t];
	int r=1<<30;
	for(int j=0;j<M;j++){
		vector<int>a,b;
		for(auto &e:t)(vp->at(e)[j]=='0'?a:b).push_back(e);
		if(a.size()&&b.size())r=min(r,max(dfs(a),dfs(b))+1);
	}
	return memo[t]=r;
}

int main(){
	for(;cin>>M>>N,M;){
		vector<string>v(N);
		vp=&v;
		for(int i=0;i<N;i++)cin>>v[i];
		vector<int>t(N);
		iota(t.begin(),t.end(),0);
		memo.clear();
		printf("%d\n",dfs(t));
	}
}

Measured memory_bytes: 3372
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args ) {
    Scanner sc = new Scanner(System.in);
    int hiki = sc.nextInt();
    int asi = sc.nextInt();
    
    if (asi%2==1 || hiki*4<asi || hiki*2>asi) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    } 
  }
}



Measured memory_bytes: 27076
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
m=-1
s=0
s+=sum(p[0:k])
for i in range(len(p)-k):
    s+=p[i+k]
    s-=p[i]
    if m < s:
        m=s
print((m+k)/2)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
constexpr int IINF = INT_MAX;

int n, a[105], b[105], dp[105][105];

int rec(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(r==l) return 0;

    int res = IINF;
    for(int i=l;i<r;i++){
        res = min(res, rec(l,i)+rec(i+1,r)+a[l]*b[i]*a[i+1]*b[r]);
    }
    return dp[l][r] = res;
}

int main() {
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    for(int i=0;i<n;i++) fill(dp[i], dp[i]+n, -1);
    cout << rec(0,n-1) << endl;
    return 0;
}


Measured memory_bytes: 3068
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
k=int(input())
s=input()
a=[]
p=""
if len(s)<=k:
    print(s)
else:
    for i in range(k):
        a.append(s[i])
    a.append("...")
    print(p.join(a))
    
    
        
        
    
    
    
            
            
            
    
    
    
    
        
        
    
    
        
            
    
    
    
    
    
    
            
            
            
    

    

Measured memory_bytes: 61928
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] A = new int[N];
    for (int i = 0; i < N; i++) {
      A[i] = sc.nextInt();
    }
    Arrays.sort(A);
    long[] S = new long[N];
    S[0] = A[0];
    for (int i = 1; i < N;i++) {
      S[i] = S[i-1]+A[i];
    }
    int ngIdx = -1;
    for (int i = 0; i < N-1; i++) {
      if (S[i]*2 < A[i+1]) {
        ngIdx = i;
      }
    }

    System.out.println(N-ngIdx-1);
  }
}

Measured memory_bytes: 51012
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll dp[100010];
ll a[305][305];
ll l[100010];
ll r[100010];
P p[100010];


int main(){
    int h, w, d;
    cin >> h >> w >> d;
    rep(i, h) rep(j, w){
        ll t;
        cin >> t;
        t--;
        p[t] = make_pair(i,j);
    }




    int q;
    cin >> q;
    rep(i, q) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    rep(i, d){
        for(int j = i; j < h*w-d; j += d){
            dp[j+d] = dp[j] + abs(p[j].first - p[j+d].first) +  abs(p[j].second - p[j+d].second);
        }
    }

    rep(i, q){
        cout << dp[r[i]] - dp[l[i]] << endl;
    }

    return 0;
}

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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)

#define X first
#define Y second

template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

signed main() {
	int a, c; char b;
	cin >> a >> b >> c;
	if (b == '+') cout << a + c << endl;
	if (b == '-') cout << a - c << endl;
	system("pause");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define rep(i, a, b) for(int i = a; i < b; i++)
#define repr(i, a, b) for(int i = a - 1; i >= b; i--)
#define iter(m) for(auto it = m.begin(); it != m.end(); it++)
#define iterr(m) for(auto it = m.rbegin(); it != m.rend(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int mod = (int)1e9 + 7;
signed main(){
    int n; cin >> n;
    int sum = 0;
    int ans = 0;
    vi v(n);
    rep(i, 0, n) {
        cin >> v[i];
        sum += v[i];
    } 
    rep(i, 0, n) {
        ans += (((sum - v[i]) % mod ) * v[i]) % mod; 
        sum -= v[i];
        ans %= mod;
    }
    cout << ans;

}

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


int main() {
    int n, t;
    cin >> n >> t;
    int min_cost = INT_MAX;
    for (int i = 0; i < n; i++) {
        int c, _t;
        cin >> c >> _t;
        if (_t <= t && c < min_cost) {
            min_cost = c;
        }
    }
    if (min_cost == INT_MAX) cout << "TLE" << endl;
    else cout << min_cost << endl;
    return 0;
}


Measured memory_bytes: 256
from math import ceil
n = int(input())
pf = []
t = n
if n == 1:
    print(0)
    exit()
for i in range(2, ceil(n ** 0.5) + 1):
    c = 0
    while t % i == 0:
        c += 1
        t //= i
    if c > 0: pf.append(c)
if t != 1: pf.append(1)

ans = 0
for i in pf:
    tmp = i
    j = 1
    while j <= tmp:
        tmp -= j
        ans += 1
        j += 1
print(ans)

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

int main(){
	//cin.tie(0),ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<int>a(n);
	map<int,int>m;
	for(auto&i:a){
		cin>>i;
		++m[i];
	}
	int64_t ans=0,tmp,tmp2;
	for(auto&i:m)ans+=(int64_t)i.second*(i.second-1)/2;
	for(auto&i:a){
		tmp=m.at(i);
		tmp=tmp*(tmp-1)/2;
		tmp2=m.at(i)-1;
		tmp2=tmp2*(tmp2-1)/2;
		cout<<ans-tmp+tmp2<<"\n"s;
	}
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());

    int cnt = 1, u = v.at(N - 1);
    for (int i = N - 2; i >= 0; i--)
    {
        if (v.at(i) == u)
        {
            continue;
        }
        cnt++;
        u = v.at(i);
    }
    cout << cnt;
}


Measured memory_bytes: 3664
/** 
 * THIS IS MOOONI'S CODE !
 * HACK IT IF YOU CAN !
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> x(a), y(b);
  for (int i = 0; i < a; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < b; i++) {
    cin >> y[i];
  }
  int ans = *min_element(x.begin(), x.end()) + *min_element(y.begin(), y.end());
  for (int i = 0; i < m; i++) {
    int id1, id2, dis;
    cin >> id1 >> id2 >> dis;
    --id1; --id2;
    ans = min(ans, x[id1] + y[id2] - dis);
  }
  cout << ans << '\n';
  return 0;
}

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


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

    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    for(int i=0;i<k;i++){
        if(c <= b){
            c *=2;
        }
        else if(a >= b){
            b *=2;
        }
    }
    if(a<b && b<c){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


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

int main(){

	int a, b, c;

	while(cin >> a >> b)
	{
		if(a+b<10){
			c=1;
		}

		else if(a+b<100){
			c=2;
		}

		else if(a+b<1000){
			c=3;
		}

		else if(a+b<10000){
			c=4;
		}

		else if(a+b<100000){
			c=5;
		}

		else if(a+b<1000000){
			c=6;
		}

		else{
			c=7;
		}

		cout<<c<<endl;
		
	}

	return 0;
}

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


int main(int argc, char const *argv[])
{
  int n;
  cin >> n;
  int sum = 0;
  while(n--){
    int l, r;
    cin >> l >> r;

    sum += (r-l+1);
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>

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

typedef long long ll;

ll coef[MAX];

int main()
{
  coef[0] = 0;
  coef[1] = 1;
  coef[2] = 4;
  REP(i,3,40)coef[i] = coef[i-1]*3+1;

  int n;
  while(cin >> n)
    {
      ll total = 0;
      ll ans = n;
      rep(i,(int)floor(n/2))
	{
	  total += 2*coef[i];
	}
      total *= 2;
      if(n%2 != 0)total += 2*coef[(int)ceil(n/2)];

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

Measured memory_bytes: 1156
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int k,a,b;cin >> k >> a >> b;
	a = (a+k-1)/k;
	b = b/k;
	int dif = b-a;
	cout << (dif >= 0 ? "OK\n" : "NG\n");
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);

		String str = sc.next();

		int total = 0;

		if (str.charAt(0) == '1') total++;
		if (str.charAt(1) == '1') total++;
		if (str.charAt(2) == '1') total++;
		
		System.out.println(total);
	}
}

Measured memory_bytes: 21840
#include <bits/stdc++.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;


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

  d = a/b;
  r = a%b;
  f = (double)a/(double)b;
  cout << d << " " << r << " " <<fixed << setprecision(6) << f << endl;
  return 0;
}



Measured memory_bytes: 3284