akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
typedef pair <int,PP> PPP;

static const double eps = 1e-8;

struct DICE{
	int top;
	int bottom;
	int lhs;
	int rhs;
	int front;
	int rear;
};

int main(){
	
	int n;
	while(~scanf("%d",&n)){
		if(n==0) break;
		int sum=1;
		DICE dice = {1,6,4,3,2,5};
		for(int i=0;i<n;i++){
			char buf[32];
			scanf("%s",buf);
			switch(buf[0]){
			case 'N':{
				//bot2fro
				//fro2top
				//top2rear
				//rear2bot
				int bottom = dice.bottom;
				int front = dice.front;
				int top = dice.top;
				int rear = dice.rear;
				dice.bottom = rear;
				dice.front = bottom;
				dice.top = front;
				dice.rear = top;
				sum += dice.top;
				break;
					 }
			case 'S':{
				int bottom = dice.bottom;
				int front = dice.front;
				int top = dice.top;
				int rear = dice.rear;
				dice.bottom = front;
				dice.front = top;
				dice.top = rear;
				dice.rear = bottom;
				sum += dice.top;
				break;
					 }
			case 'W':{
				int bottom = dice.bottom;
				int top = dice.top;
				int lhs = dice.lhs;
				int rhs = dice.rhs;
				dice.bottom = lhs;
				dice.top = rhs;
				dice.lhs = top;
				dice.rhs = bottom;
				sum += dice.top;
				break;
					 }
			case 'E':{
				int bottom = dice.bottom;
				int top = dice.top;
				int lhs = dice.lhs;
				int rhs = dice.rhs;
				dice.bottom = rhs;
				dice.top = lhs;
				dice.lhs = bottom;
				dice.rhs = top;
				sum += dice.top;
				break;
					 }
			case 'R':{
				int lhs = dice.lhs;
				int rhs = dice.rhs;
				int front = dice.front;
				int rear = dice.rear;
				dice.lhs = front;
				dice.rhs = rear;
				dice.front = rhs;
				dice.rear = lhs;
				sum += dice.top;
				break;
					 }
			case 'L':{
				int lhs = dice.lhs;
				int rhs = dice.rhs;
				int front = dice.front;
				int rear = dice.rear;
				dice.lhs = rear;
				dice.rhs = front;
				dice.front = lhs;
				dice.rear = rhs;
				sum += dice.top;
				break;
					 }
			default:
				break;
			}
		}
		printf("%d\n",sum);
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;
const int L = 8;

bool check(string &a, string &b){
  REP(i, L) if(a[i] != '*' && a[i] != b[i]) return false;
  return true;
}

int main() {
  int N, M;
  while(cin >>N >>M && N){
    vector<string> s(N);
    vector<int> m(N);
    int ans = 0;
    REP(i, N) cin >>s[i] >>m[i];
    REP(i, M){
      string ss; cin >>ss;
      int tmp = 0;
      REP(j, N) if(check(s[j], ss)) tmp = m[j];
      ans += tmp;
    }
    cout <<ans <<endl;
  }
  return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <unordered_set>
#include <queue>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

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

int main(){
  ll N, M;
  cin >> N >> M;
  priority_queue<ll> A;
  ll tmp;
  rep(i, N){
    cin >> tmp;
    A.push(tmp);
  }
  
  //sort(A.begin(), A.end());
  
  ll esc;
  rep(i,M){
    esc = A.top()/2;
    //auto Iter1 = lower_bound(A.begin(), A.end(), esc);
    A.push(esc);
    A.pop();
  }
  
  //rep(i,N) cout << A[i] << endl;
  
  ll sum=0;
  rep(i,N){
    sum+=A.top();
    A.pop();
  }
  cout << sum << endl;
  
}

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

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << ” = ” << (x) << ” (L” << __LINE__ << “)” << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
       return l.first<r.first || (l.first==r.first && l.second > r.second);
       });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main() {
    int n;
    cin>>n;
    if(n%4==0 || n%7==0){
        cout<<"Yes"<<endl;
        return 0;
    }
    n-=7;
    while(n>0){
        if(n%4==0){
            cout<<"Yes"<<endl;
            return 0;
        }
        n-=7;
    }
    cout<<"No"<<endl;

   return 0;
}

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

int main(void) {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; ++i) cin >> S[i];

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      int num = 0;
      for (int m = -1; m <= +1; ++m) {
        for (int n = -1; n <= +1; ++n) {
          int ny = i + m;
          int nx = j + n;
          if (ny < 0 || H <= ny || nx < 0 || W <= nx) continue;
          if (S[ny][nx] == '#') ++num;
        }
      }
      if (S[i][j] == '#')
        cout << "#";
      else
        cout << num;
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n, k = map(int, readline().split())
xy = []
xx = []
yy = []
for _ in range(n):
    x, y = map(int, readline().split())
    xx.append(x)
    yy.append(y)
    xy.append((x, y))
xx.sort()
yy.sort()
ans = float('inf')
for i, ix in enumerate(xx):
    for jx in xx[i + 1:]:
        for j, iy in enumerate(yy):
            for jy in yy[j + 1:]:
                cnt = 0
                for x, y in xy:
                    if ix <= x <= jx and iy <= y <= jy:
                        cnt += 1
                if cnt >= k:
                    ans = min(ans, (jx - ix) * (jy - iy))
print(ans)


Measured memory_bytes: 47708
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll p[51],a[51];

void build()
{
	p[0]=1;
	a[0]=1;
	for(int i=1;i<=50;i++)
	{
		p[i]=p[i-1]*2+1;
		a[i]=a[i-1]*2+3;
	}
}

ll eat(ll lvl,ll &rem)
{
	if(rem<=0) return 0;
	if(rem>=a[lvl])
	{
		rem-=a[lvl];
		return p[lvl];
	}
	rem--;
	ll n=eat(lvl-1,rem);
	if(rem==0) return n;
	rem--; n++;
	n+=eat(lvl-1,rem);
	if(rem>0) rem--;
	return n;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	build();
	ll l,r; cin>>l>>r;
	cout<<eat(l,r)<<"\n";
	return 0;
}

Measured memory_bytes: 256
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::min();
const int minimum  = numeric_limits<int>::max();
// const int N = 1e5 + 5 ;
const ll mod = 1e9 + 7 ;

ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}

ll gcd (ll a, ll b) {
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}






int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// int t ;
	// cin >> t ;
	// while (t--) {
	int n ;
	cin >> n ;
	string s ;
	cin >> s ;
	int cntW = count(s.begin(), s.end() , 'W') ;
	int cntR = count(s.begin(), s.end(), 'R') ;
	if (cntW == 0 || cntR == 0) {
		cout << 0 << "\n";
	} else {
		int ans = 0 ;
		int lo = 0 , hi = n - 1 ;
		while (lo < hi) {
			if (s[lo] == 'W' ) {
				if (s[hi] == 'R') {
					ans++ ;
					lo++ ;
					hi-- ;
				} else {
					hi-- ;
					// lo++ ;
					// ans++ ;
				}
			} else {
				lo++ ;
			}
		}
		cout << ans << "\n";
	}
	// for (int i = 0 ; i < n ; i++) {
	// 	if (s[i] == '')
	// 	}



	// }







	return 0 ;

}



Measured memory_bytes: 3684
def aaa(O, X):
    if O == 3:
        print 'o'
        return True
    elif X == 3:
        print 'x'
        return True

while True:
    try:
        line = raw_input()
        ttt = []
        while line:
            lis = []
            for i in range(3):
                lis.append(line[i])
            else:
                ttt.append(lis)
            line = line[3:]
            
        flag = False
        for y in range(3):
            O = 0
            X = 0
            for x in range(3):
                if ttt[y][x] == 'o':
                    O += 1
                elif ttt[y][x] == 'x':
                    X += 1
            else:
                if aaa(O, X): flag = True
            if flag == True: break
        if flag == True: continue
        
        for x in range(3):
            O = 0
            X = 0
            for y in range(3):
                if ttt[y][x] == 'o':
                    O += 1
                elif ttt[y][x] == 'x':
                    X += 1
            else:
                if aaa(O, X): flag = True
            if flag == True: break
        if flag == True: continue
                
        O = 0
        X = 0
        for i in range(3):
            if ttt[i][i] == 'o':
                O += 1
            elif ttt[i][i] == 'x':
                X += 1
        else:
            if aaa(O, X): flag = True
        if flag == True: continue
            
        O = 0
        X = 0
        for i in range(3):
            if ttt[i][2-i] == 'o':
                O += 1
            elif ttt[i][2-i] == 'x':
                X += 1
        else:
            if aaa(O, X): flag = True
        if flag == True:
            continue
        else:
            print 'd'
    except EOFError:
        break

Measured memory_bytes: 4340
#include<stdio.h>
#include<stdlib.h>

typedef struct node{
  int key;
  int priority;
  struct node *left;
  struct node *right;
}node;


node * Delete(node **,int);
node * _delete(node **,int);

int find(node *p,int x){

  while(p!=NULL){
    if(p->key == x)return 1;
    else if(p->key > x)p=p->left;
    else p=p->right;
  }

  return 0;

}

void inorder(node *p){

  if(p->left!=NULL)inorder(p->left);

  printf(" %d",p->key);

  if(p->right!=NULL)inorder(p->right);

  return;

}

void preorder(node *p){

  printf(" %d",p->key);

  if(p->left!=NULL)preorder(p->left);

  if(p->right!=NULL)preorder(p->right);

  return;

}

void print(node *p){

  inorder(p);
  printf("\n");

  preorder(p);
  printf("\n");

  return;

}

node * makenode(int x,int y){
  node *new=malloc(sizeof(node));
  new->key=x;
  new->priority=y;
  new->left=NULL;
  new->right=NULL;
  return new;
}

node *rightRotate(node *p){
  node *q=p->left;
  p->left=q->right;
  q->right=p;
  return q;
}

node *leftRotate(node *p){
  node *q=p->right;
  p->right=q->left;
  q->left=p;
  return q;
}


node* insert(node **t,int key,int priority){
  node *new;

  if((*t)==NULL)
  return new=makenode(key,priority);
  if ((*t)->key==key)
  return *t;

  if(key < (*t)->key){
    (*t)->left=insert(&(*t)->left,key,priority);
    if((*t)->priority < (*t)->left->priority)
    (*t)=rightRotate((*t));
  }
  else {
    (*t)->right=insert(&(*t)->right,key,priority);
    if((*t)->priority < (*t)->right->priority)
    (*t)=leftRotate((*t));
  }

  return *t;
}


node * Delete(node **t,int key){
  if((*t)==NULL)
  return NULL;

  if(key < (*t)->key)
  (*t)->left=Delete(&((*t)->left),key);

  else if(key > (*t)->key)
  (*t)->right=Delete(&((*t)->right),key);

  else return _delete(t,key);

  return *t;
}

node * _delete(node **t,int key){
  if((*t)->left==NULL && (*t)->right==NULL)
  return NULL;
  else if((*t)->left==NULL)
  (*t)=leftRotate(*t);
  else if((*t)->right==NULL)
  (*t)=rightRotate(*t);
  else {
    if((*t)->left->priority > (*t)->right->priority)
    (*t)=rightRotate(*t);
    else
    (*t)=leftRotate(*t);
  }
  return Delete(t,key);
}


int main(){
  int n,x,y;
  char com[8];
  node *root=NULL;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%s",com);

    switch(com[0]){

      case 'i':scanf("%d %d",&x,&y);
      root=insert(&root,x,y);
      break;

      case 'd':scanf("%d",&x);
      root=Delete(&root,x);
      break;


      case 'f':scanf("%d",&x);
      if(find(root,x))printf("yes\n");
      else printf("no\n");
      break;

      case 'p':print(root);
      break;

    }

  }

  return 0;

}



Measured memory_bytes: 7964
# https://atcoder.jp/contests/agc014/tasks/agc014_b

from collections import defaultdict

n, m = map(int, input().split())
counter = defaultdict(int)
for _ in range(m):
    ai, bi = map(int, input().split())
    counter[ai] += 1
    counter[bi] += 1


for key in counter:
    if counter[key] % 2 != 0:
        print("NO")
        exit()
else:
    print("YES")

Measured memory_bytes: 53524
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int x, a;
    cin >> x >> a;
    if (x < a) cout << 0;
    else
        cout << 10;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, list(input().split())))
cnt = 0
for i in range(len(a)-1):
  if a[i] >= a[i+1]:
    cnt += a[i] - a[i+1]
    a[i+1] += a[i] - a[i+1]
print(cnt)

Measured memory_bytes: 32412
#include<bits/stdc++.h>
using namespace std;
 
int main()
{	
  cout.precision(7);
  	int n, k;
  	cin >> n >> k;
  	int a, c = 0;
  for(int i = 0; i < n; ++i)
  { 
    cin >> a;
  	if(a >= k)
      c++;
  }
  cout << c << "\n";
  return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x, n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair< int, int > P;
typedef pair< int, P > PP;

//------------------------------------------------

const int MOD = 10000;
int n, k;
int taste[105];

int DP(int snd, int fst) {
	int dp[n][4][4] = {};
	dp[1][snd][fst] = 1;
	FOR(i, 2, n) {
		FOR(j, 1, 4) {
			FOR(k, 1, 4) {
				if (taste[i]) {
					if (j == k && k == taste[i]) continue;
					(dp[i][taste[i]][k] += dp[i - 1][k][j]) %= MOD;
				}
				else {
					FOR(l, 1, 4) {
						if (j == k && k == l) continue;
						(dp[i][l][k] += dp[i - 1][k][j]) %= MOD;
					}
				}
			}
		}
	}
	int res = 0;
	FOR(i, 1, 4) FOR(j, 1, 4) (res += dp[n - 1][i][j]) %= MOD;
	//cout << "(fst, snd, res) = " << fst << "," << snd << "," << res << endl;
	return res;
}

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

	cin >> n >> k;
    REP(i, k) {
		int a, b;
		cin >> a >> b;
		taste[a - 1] = b;
	}
	int ans = 0;
	if (taste[0]) {
		if (taste[1]) {
			ans = DP(taste[1], taste[0]);
		}
		else {
			REP(i, 3) {
				ans += DP(i + 1, taste[0]);
			}
		}
	}
	else {
		REP(i, 3) {
			if (taste[1]) {
				ans += DP(taste[1], i + 1);
			}
			else {
				REP(j, 3) {
					ans += DP(j + 1, i + 1);
				}
			}
		}
	}
	cout << ans % MOD << endl;

	return 0;
}




Measured memory_bytes: 3196
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 1000005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int n,m,x;
int c[15];
int a[15][15];
int getcost(int mask){
	int cur[15]={0};
	int cost=0;
	for(int i=0;i<n;i++){
		if(!(mask&(1<<i)))continue;
		cost+=c[i];
		for(int j=0;j<m;j++)cur[j]+=a[i][j];
	}
	for(int i=0;i<m;i++)if(cur[i]<x)cost=1e9;
	return cost;
}
void solve(){
	int ans=1e9;
	cin>>n>>m>>x;
	rep(i,n){
		cin>>c[i];
		rep(j,m)cin>>a[i][j];
	}
	for(int i=0;i<(1<<n);i++)ans=min(ans,getcost(i));
	if(ans>=1e9)ans=-1;
	cout<<ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 3644
N, W = map(int, input().split())
vl = []
wl= []
for _ in range(N):
  v, w = map(int, input().split())
  vl.append(v)
  wl.append(w)
  
dp = [[0 for _ in range(W+1)] for _ in range(N+1)]

for i in range(N):
  for w in range(1, W+1):
    if w - wl[i] < 0:
      dp[i+1][w] = dp[i][w]
    else:
      dp[i+1][w] = max(dp[i][w], dp[i+1][w-wl[i]] + vl[i])
      
print(dp[N][W])


Measured memory_bytes: 16128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define ll long long
int dp[12][2001];
int book[11][2001];
int kind[11] = { 0 };
int acc[11][2001];
int main() {
	int N, K;
	int c, g;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> c >> g;
		book[g - 1][kind[g - 1]++] = c;
	}
	for (int i = 0; i < 11; i++) {
		sort(book[i], book[i] + kind[i]);
		reverse(book[i], book[i] + kind[i]);
	}
	for (int i = 0; i < 11; i++) {
		acc[i][0] = 0;
		for (int j = 1; j <= kind[i]; j++) {
			acc[i][j] = acc[i][j - 1] + book[i][j - 1] + 2 * (j - 1);
		}
	}
	for (int i = 0; i <= K; i++) {
		if (0 < i&&i <= kind[0])dp[0][i] = acc[0][i];
		else dp[0][i] = 0;
	}

	for (int i = 1; i <= 11; i++) {
		for (int j = 0; j <= K; j++) {
			dp[i][j] = 0;
			for (int k = 0; k <= min(j, kind[i]); k++) {
				dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + acc[i][k]);
			}
		}
	}
	cout << dp[11][K] << endl;
	return 0;
}


Measured memory_bytes: 3336
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)
	result := "No"
	sa := s[:(len(s)-1)/2]
	sb := s[((len(s)+3)/2)-1:]
	if s == reverse(s) && sa == reverse(sa) && sb == reverse(sb) {
		result = "Yes"
	}
	fmt.Println(result)
}

func reverse(s string) string {
	rs := []rune(s)
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		rs[i], rs[j] = rs[j], rs[i]
	}
	return string(rs)
}


Measured memory_bytes: 512
def main():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    non_negative = len(list(filter(lambda x: x >= 0, a)))
    negative = n - non_negative
    if non_negative == 0:
        negative = n - 1
        non_negative = 1
    elif negative == 0:
        negative = 1
        non_negative = n - 1
    neg_num = a[:negative]
    non_neg_num = a[-non_negative:]
    ope = []
    for nnn in non_neg_num[:-1]:
        ope.append([neg_num[0], nnn])
        neg_num[0] -= nnn
    for nn in neg_num:
        ope.append([non_neg_num[-1], nn])
        non_neg_num[-1] -= nn
    print(non_neg_num[-1])
    for i, j in ope:
        print(i, j)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26320
while true
	a, op, b = gets.split( " " )
	case op
	when "+"
		puts( a.to_i+b.to_i )
	when "-"
		puts( a.to_i-b.to_i )
	when "*"
		puts( a.to_i*b.to_i )
	when "/"
		puts( a.to_i/b.to_i )
	else
		break
	end
end

Measured memory_bytes: 6100
#include<bits/stdc++.h>
#include <atcoder/all>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
using namespace atcoder;
typedef pair<int,int> P;
typedef long long ll;
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;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) { 
      if (d[x] < 0) return x;
      return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
      x = find(x); y = find(y);
      if (x == y) return false;
      if (d[x] > d[y]) swap(x,y);
      d[x] += d[y];
      d[y] = x;
      return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int main() {
    int n,m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m) {
        int a,b;
        cin >> a >> b;
        a--;b--;
        uf.unite(a,b);
    }
    set<int>se;
    rep(i,n) se.insert(uf.find(i));
    int ans = se.size()-1;
    cout << ans << endl;
}

Measured memory_bytes: 7576
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<char> = s.trim().chars().collect();
    let mut x: usize = 0;
    let mut y: usize = 0;
    for i in 0..v.len() {
        if v[i] == 'A' {x = i; break;}
    }
    for i in (0..v.len()).rev() {
        if v[i] == 'Z' {y = i; break;}
    }
    println!("{}", y - x + 1);
}



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

int main()
{
	int L;
	int A, B;
	int C, D;

	std::cin >> L >> A >> B >> C >> D;

	std::cout << (int)(L - std::max( ceil( (double)A / C ), ceil( (double)B / D ) )) << std::endl;

	return 0;
}

Measured memory_bytes: 1164
N=int(input())
a=list(map(int,input().split()))
s=sum(a)
b=[]
for ai in a:
    if not b:
        b.append(ai)
    elif len(b)==N-1:
        break
    else:
        b.append(b[-1]+ai)
c=[abs(2*x-s) for x in b]
print(min(c))

Measured memory_bytes: 88620
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, ans;
int di[4] = {0, -1, 0, 1}, dj[4] = {1, 0, -1, 0};
char S[25][25];

int Dist[25][25];
int Solve(int I, int J){
  fill((int*)Dist, (int*)(Dist + H), -1);

  queue <Pii> que; que.push({I, J});
  Dist[I][J] = 0;

  while (!que.empty()){
    Pii Q = que.front(); que.pop();

    for (int k = 0; k < 4; k++){
      int i = Q.fi + di[k];
      int j = Q.se + dj[k];

      if (0 <= i && i < H && 0 <= j && j < W){
        if (Dist[i][j] == -1 && S[i][j] == '.'){
          que.push({i, j});
          Dist[i][j] = Dist[Q.fi][Q.se] + 1;
          ans = max(ans, Dist[i][j]);
        }
      }
    }
  }
  return 0;
}

int main(){
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; i++) scanf("%s", S+i);

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (S[i][j] == '#') continue;
      Solve(i, j);
    }
  }
  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 3788
import java.util.Scanner;
import java.util.Arrays;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int[] num = new int[n];
			for(int i = 0;i < n;i++){
				num[i] = scan.nextInt();
			}
			Arrays.sort(num);
			System.out.println(1);
			int j = 0;
			for(int i = 2;i <= num[0];i++){
				for(j = 0;j < n;j++){
					if(num[j]%i != 0){
						break;
					}
				}
				if(j == n){
					System.out.println(i);
				}
			}
		}
	}
}

Measured memory_bytes: 19480
m1,d1=(int(x) for x in input().split())
m2,d2=(int(x) for x in input().split())
math1 = [1,3,5,7,8,10,12]
math2 = [4,6,9,11]
math3 = [2]
a = 0
if m1 in math1:
    if d1 == 31:
        a += 1
elif m1 in math2:
    if d1 == 30:
        a += 1
elif m1 in math3:
    if d1 == 28:
        a += 1
else:
    pass

print(a)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if (A == B && B == C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main (void){
  int W;  //????????¢????¨?
  int H;  //????????¢??????
  int x;  //??????x??§?¨?
  int y;  //??????y??§?¨?
  int r;  //??????

  scanf("%d",&W);
  scanf("%d",&H);
  scanf("%d",&x);
  scanf("%d",&y);
  scanf("%d",&r);

  if( x<r || x>W-r || y<r || y>H-r)
    printf("No\n");
  else
    printf("Yes\n");

  return 0;
}

Measured memory_bytes: 584
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;


public class C
{
	public static void Main()
	{
		int N = Int32.Parse(Console.ReadLine());
		List<long> A = new List<long>(N);
		string[] args = Console.ReadLine().Split(' ');
		for(int i = 0; i < N; i++)
			A.Add(Int32.Parse(args[i]));
		A.Sort();
		A.Reverse();

		long edge1 = 0;
		long edge2 = 0;
		for(int i = 0; i < N-1; i++)
		{
			if(A[i] != A[i+1])
				continue;
			if(edge1 == 0)
			{
				edge1 = A[i];
				i++;  // total: i += 2
			}
			else
			{
				edge2 = A[i];
				break;
			}
		}
		
		Console.WriteLine(edge1 * edge2);
	}
}





Measured memory_bytes: 19040
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x[300005],y[300005],i,j;
    int h,w,m;
    set<pair<int,int>> s;
    pair<int,int>p;
    cin>>h>>w>>m;
    for(i=0;i<m;i++)
    {
        int xx,yy;
        cin>>xx>>yy;
        x[xx]++;
        y[yy]++;
        p.first=xx;
        p.second=yy;
        s.insert(p);
    }
    int mx=*max_element(x,x+300005);
    int my=*max_element(y,y+300005);
    int mxa[300005],mya[300005],count1=0,count2=0;
    for(i=0;i<300005;i++)
    if(x[i]==mx)
    mxa[count1++]=i;
    for(i=0;i<300005;i++)
    if(y[i]==my)
    mya[count2++]=i;
    int ansfound=0;
    for(i=0;i<count1;i++)
    {
    for(j=0;j<count2;j++)
    {
        p.first=mxa[i];
        p.second=mya[j];
        if(s.find(p)==s.end())
        {
            ansfound=1;
            break;
        }
    }
    if(ansfound==1)
    break;
    }
    if(ansfound==1)
    cout<<x[p.first]+y[p.second];
    else
    cout<<x[p.first]+y[p.second]-1;
    
    
}

Measured memory_bytes: 22348
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  ll n;
  R n;
  ll ans=0;
  ll a[n];
  rep(i,n) R a[i];
  rep(i,n) {
    REP(j,i+1,n) ans+=a[i]*a[j];
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

using namespace std;
using ll = long long int;
using ull = unsigned long long int;
#define vll vector<ll>

#define FOR(i, b, e) for(int i = (b); i < (e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define REV(v) reverse((v).begin(), (v).end())
#define IN(v) cin >> (v);
#define VIN(v, n) REP(i, n) cin >> v[i];
#define OUT(v) cout << (v) << endl;
#define YN(b) OUT((b) ? "YES" : "NO")
#define Yn(b) OUT((b) ? "Yes" : "No")
#define yn(b) OUT((b) ? "yes" : "no")

const ll MOD = 1000000007;

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

  long double a, b;
  cin >> a >> b;

  ll r = a * b;

  cout << r << endl;

  return 0;
}

Measured memory_bytes: 3832
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 100000
#define pie 3.141592653589793238462643383279
#define P std::pair<int,int>
#define prique priority_queue
using namespace std;
int n,h[110];
signed main(){
	cin>>n;
	rep(i,n)cin>>h[i];
	int ans=0;
	rep(i,n){
		while(h[i]){
			int cnt=n;
			for(int j=i;j<n;j++){
				if(!h[j]){
					cnt=j;
					break;
				}
			}
			for(int j=i;j<cnt;j++)h[j]--;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define REP(A, H) for(int A = 0; A < H; A++)
#define RREP(A, B, H, W) for(int A = 0; A < H; A++) for (int B = 0; B < W; B++)
#define MAX(A, B) (A = std::max(A, B))
#define MIN(A, B) (A = std::min(A, B))

typedef long long ll;

struct POINT {
  int x; int y;
  POINT(int x, int y) : x(x), y(y) {}
};

POINT operator +(const POINT& a, const POINT& b) {
  return POINT(a.x + b.x, a.y + b.y);
}

POINT operator -(const POINT& a, const POINT& b) {
  return POINT(a.x - b.x, a.y - b.y);
}

/* std::cout << ;*/
/* std::cout << << std::endl; */

const int MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long c(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll memo[4001];

ll h(ll n, ll r) {
  return c(n + r - 1, r);
}

int main(void) {
  int n, k; std::cin >> n >> k;
  
  COMinit();

  REP(i, 4001) memo[i] = -1;

  REP(i, k + 1) {
    if (i == 0) continue;
    //std::cout << "here" << i << std::endl;
    if (n - k + 1 < i) {
      std::cout << 0 << std::endl; continue;
    }
    //std::cout << "i : " << i << std::endl; 
    //std::cout << "k - i : " << k - i << ", n - k - (i - 1) : " << n - k - (i - 1) << std::endl;
    std::cout << (h(i, k - i) * h(i + 1, n - k - (i - 1))) % MOD << std::endl;
  }

  return 0;
}

Measured memory_bytes: 12288
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sca=new Scanner(System.in);
int a =sca.nextInt();
double sum=0;
for (int i=0;i<a;i++) {
	double b=sca.nextDouble();
	String c=sca.next();
	if(c.equals("JPY")) {
		sum+=b;
	}
	else {
		sum+=b*380000.0;
	}
}
System.out.print(sum);

	}

}


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

int main() {
	
	int a, b, t;
	cin >> a >> b >> t;
	cout << t / a * b << endl;
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static int[] print_num = 
		{0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
	public static int[] print_num2 = 
		{0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		for(int i = 0; i < n; i++){
			int from = sc.nextInt();
			int to = sc.nextInt();
			
			if(from > to){
				if(from <= 5){
					from = 15 - from;
					to = 15 - to;
				}else if(to <= 5){
					to = 15 - to;
				}else{
					to += 15;
				}
			}
			
			boolean first = true;
			for(int j = from; j <= to; j++){
				
				System.out.print((first ? "" : " ") + print_num2[j]);
				
				if(first){
					first = false;
				}
			}
			System.out.println();
		}
		
	}
	
}

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

using namespace std; 

int n, m, col[1005]; 
bool can[1005][1005], only[1005][1005]; 
int vis[1005]; 
vector <int> G[1010]; 

void dfs1(int u, int x) {
    can[x][u] = 1; 
    vis[u] = 1; 
    for (auto v : G[u]) {
        if (!vis[v]) {
            dfs1(v, x);
        }
    }
}

void dfs2(int u, int x, int t, int op) {
    // cout << u << '\n'; 
    if (op == 1) {
        only[x][u] = col[u] != t; 
    }
    else {
        col[u] = t; 
    }
    vis[u] = 1; 
    for (auto v : G[u]) {
        if (!vis[v]) {
            dfs2(v, x, t, op); 
        }
    }
}

int U[1010100], V[1010100]; 

int main() {
    scanf("%d %d", &n, &m); 
    for (int i = 1; i <= m; i++) {
        int u, v; 
        scanf("%d %d", &u, &v);
        U[i] = u, V[i] = v; 
        G[u].push_back(v);  
    }
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis)); 
        vis[i] = 1; 
        dfs1(i, i); 
    }
    for (int i = 1; i <= n; i++) {
        memset(vis, 0, sizeof(vis)); 
        vis[i] = 1;
        memset(col, 0, sizeof(col));  
        for (int j = 0; j < G[i].size(); j++) {
            int v = G[i][j]; 
            if (!vis[v])
                dfs2(v, i, j + 1, 0); 
        }
        memset(vis, 0, sizeof(vis)); 
        vis[i] = 1; 
        for (int j = G[i].size() - 1; j >= 0; j--) {
            int v = G[i][j]; 
            if (!vis[v])
                dfs2(v, i, j + 1, 1); 
        }
    }
    for (int i = 1; i <= m; i++) {
        if (can[V[i]][U[i]] ^ only[U[i]][V[i]]) puts("diff"); 
        else puts("same"); 
    }
    return 0; 
}

Measured memory_bytes: 11392
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;
int main(){
    int n;
    long long a[100005],sum1=0,sum2=0,cnt1=0,cnt2=0;
    bool f1=0,f2=1;//0正数，1负数 
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
    	scanf("%lld",&a[i]);
    	//按照奇数为正，偶数为负的规律改变 
		if(f1==0){//说明当前这个应该为正 
			if(sum1+a[i]<=0){//当前这个不是正 
				cnt1+=1-sum1-a[i];//把sum1改变为最小的正数1需要a[i]改变1-sum1-a[i]个 
				sum1=1; 
			}
			else{
				sum1+=a[i];//如果当前是正那么就不管 
			} 
			f1=1;//下一个应该为负数 
		}
		else{//当前应该为负数 
			if(sum1+a[i]>=0){//当前这个不是正 
				cnt1+=a[i]-(-1-sum1);//把sum1改变为最小的负正-1需要a[i]改变a[i]-(-1-sum1)个 
				sum1=-1; 
			}
			else{
				sum1+=a[i];//如果当前是负数那么就不管 
			} 
			f1=0;//下一个应该为正数数 
		} 
		//按照奇数为负数，偶数为正数的规律改变 
		
		if(f2==0){//说明当前这个应该为正 
			if(sum2+a[i]<=0){//当前这个不是正 
				cnt2+=1-sum2-a[i];//把sum1改变为最小的正数1需要a[i]改变1-sum1-a[i]个 
				sum2=1; 
			}
			else{
				sum2+=a[i];//如果当前是正那么就不管 
			} 
			f2=1;//下一个应该为负数 
		}
		else{//当前应该为负数 
			if(sum2+a[i]>=0){//当前这个不是正 
				cnt2+=a[i]-(-1-sum2);//把sum1改变为最小的负正-1需要a[i]改变a[i]-(-1-sum1)个 
				sum2=-1; 
			}
			else{
				sum2+=a[i];//如果当前是负数那么就不管 
			} 
			f2=0;//下一个应该为正数数 
		} 
	}
	printf("%lld",min(cnt1,cnt2)); 
    return 0 ;
}

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

using namespace std;
typedef long long ll;
//ループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//コンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

//2値の最大公約数(順序関係なし・0はダメ)
int gcd(int a, int b){
    return b ? gcd(b, a%b) :a;
}

//n個の最大公約数
int ngcd(vector<int>& a){
    int res;
    res = a.at(0);
    for(int i = 1; i< a.size() && res != 1; i++){
        res = gcd(a.at(i), res);
    }
    return res;
}

//2値の最小公倍数
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}

//n個の最小公倍数
int nlcm(vector<int> numbers){
    int res;
    res = numbers.at(0);
    for(int i = 0; i< numbers.size();i++){
        res = lcm(res, numbers[i]);
    }
    return res;
}

//素数判定O(√N)
bool isPrime(int x){
    if(x<2) return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(int i = 3; i*i <= x; i+=2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(int n){
    int res = 0;
    while(n>0){
        res += n%10;
        n /= 10;
    }
    return res;
}

//約数全列挙
vector<int> enum_div(int n){
    vector<int> ret;
    for(int i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

//繰り返し自乗法
long long int mod_pow(long long int x, long long int n, long long int mod){
    long long int res = 1;
    while(n > 0){
        if(n & 1) res = res*x%mod;
        x = x*x%mod;
        n >>= 1;
    }
    return res;
}

//文字列の中で何回文字が出てきたのかを数える
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c); //覚える
}

int main(){
    ll N; cin >> N;
    ll buf;
    multiset<ll> A;
    REP(i,N){
        cin >> buf;
        A.insert(buf);
    }

    ll cmft = *rbegin(A);
    auto itr = ++rbegin(A);

    for(ll i=3;i<N+1;i++){
        cmft += *itr;
        if(i%2==0) ++itr;
    }

    cout << cmft << endl;
}

Measured memory_bytes: 13004
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    string s;
    int q;
    cin>>s>>q;
    vector<char> fro(0),bac(0);
    int t,f;
    char c;
    int n=s.size();
    bool flag=0;
    rep(i,q){
        cin>>t;
        if(t==1){ flag=(!flag);continue;}
        cin>>f>>c;
        if(!flag && f==1) fro.push_back(c);
        else if(!flag && f==2) bac.push_back(c);
        else if(flag && f==1) bac.push_back(c);
        else fro.push_back(c);
    }
    if(!flag){
        rep(i,fro.size()) cout<<fro[fro.size()-i-1];
        rep(i,n) cout<<s[i];
        rep(i,bac.size()) cout<<bac[i];
    }
    else{
        rep(i,bac.size()) cout<<bac[bac.size()-i-1];
        rep(i,n) cout<<s[n-i-1];
        rep(i,fro.size()) cout<<fro[i];
    }
    cout<<endl;
}

Measured memory_bytes: 1104
//Nayeem Shahriar Joy ,Applied Physics And Electronic Engineering , University of Rajshahi.

 #include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;


   int main(){
    int m, d, w;
    int days[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    string weekName[7] = {"Sunday", "Monday", "Tuesday", "Wednesday",
                         "Thursday", "Friday", "Saturday"};
    while(1){
        cin >> m >> d;
        if(!(m || d)){
            return 0;
        }
        w = 3;
        for(int i = 1; i < m; i++){
            w += days[i - 1];
        }
        w += d;
        cout << weekName[w % 7] << endl;
    }
}

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

int main(){
  int x,y;
  cin>>x>>y;
  if(x==2||y==2) cout<<"No";
  else if(x==4||x==6||x==9||x==11){
    if(y==4||y==6||y==9||y==11) cout<<"Yes";
    else cout<<"No";
  }else{
    if(y==4||y==6||y==9||y==11) cout<<"No";
    else cout<<"Yes";
  }
}

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

int main() {
  int K, X;
  cin >> K >> X;

  int l = max(X - (K - 1), -1000000);
  int r = min(X + (K - 1), 1000000);
  for (int i = l; i <= r; i++) {
    cout << i;
    if (i != r) cout << " ";
  }
  cout << endl;
}


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

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

using namespace std;

int main(){
	int n; scanf("%d",&n);

	set<int> A;
	rep(i,n){ int a; scanf("%d",&a); A.emplace(a); }
	puts(A.size()==n?"YES":"NO");

	return 0;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
#endif
	int n; cin>>n;
	unordered_map<string,int> mp;
	string s;
	vector<string> v;
	int maxi=-1;
	for(int i=0;i<n;i++){
		cin>>s;
		mp[s]++;
	}
	for(auto x: mp)
		maxi=max(maxi,x.second);
	for(auto x: mp){
		if(x.second==maxi)
			v.push_back(x.first);
	}
	sort(v.begin(),v.end());
	for(string ss: v){
		cout<<ss<<endl;
	}
	return 0;
}

Measured memory_bytes: 25284
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int i = c-(a-b);
    if(i<0){
      System.out.println(0);
    }else{
      System.out.println(i);
    }
    
  } 
}

Measured memory_bytes: 23252
//This Code was made by Chinese_zjc_.
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<bitset>
#include<cmath>
#include<queue>
#include<stack>
#include<string>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<time.h>
// #include<windows.h>
#define int long long
#define PI 3.14159265358979323
#define INF 0x3fffffffffffffff
using namespace std;
int ans,len;
string s;
signed main()
{
    ios::sync_with_stdio(false);
    cin>>s;
    s=' '+s;
    for(int i=1;i<=3;++i)
    {
        if(s[i]=='S')
        {
            len=0;
        }
        else
        {
            ++len;
            ans=max(ans,len);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3624
/**
*    author:  yamako
*    created: 05.08.2020 22:38:08
**/

#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

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

Node *root, *NIL;

void insert(int k) {
    Node *y = NIL;
    Node *x = root;
    Node *z;

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

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

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

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

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

int main() {
    int n, i, x;
    string com;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        cin >> com;
        if (com == "insert") {
            scanf("%d", &x);
            insert(x);
        } else if (com == "print") {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }

    return 0;
}


Measured memory_bytes: 26744
#pragma GCC optimize ("O3")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int A, B, C, K;
	cin >> A >> B >> C >> K;

	int kotae = 0;
	if (K > 0) {
		int k = min(K, A);
		kotae += k;
		K -= k;
	}
	if (K > 0) {
		int k = min(K, B);
		K -= k;
	}
	if (K > 0) {
		int k = min(K, C);
		kotae -= k;
		K -= k;
	}

	co(kotae);


	Would you please return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner i = new Scanner(System.in);
		int x=i.nextInt();
		int s=x%60;
		x=x-s;
		int m=x%3600/60;
		x=x-m;
		int h=x/3600;
		System.out.println(h+":"+m+":"+s);
	}
}

Measured memory_bytes: 17340
#include <bits/stdc++.h>
#define us unordered_set
#define f first
#define s second
#define pb push_back
#define MOD 1000000007
#define MOD2 1000000009
#define BASE 29
#define BASE2 31
#define eps 1e-9
#define INF 1000000002
#define PI 3.14159265359

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<int, pii> piii;
typedef pair<pii,pii> piiii;
const int N = 200002;
const int BIT = 30;
int n;
ll a[N], f[N], k;

bool can(ll mid) {
    int i =0, j = n-1;
    ll currK = k;
    while(i<n) {
        ll target = mid / f[j];
        currK -= max(0LL, a[i] - target);
        i++, j--;
    }
    return currK >= 0;
}

int main() {
    scanf("%d%lld",&n,&k);
    for(int i =0;i<n;i++)
        scanf("%lld",&a[i]);
    for(int i =0;i<n;i++)
        scanf("%lld",&f[i]);
    ll l = 0, r = 1e12, ans = r;
    sort(a, a+n);
    sort(f, f+n);
    while(l<=r) {
        ll mid = (l+r)>>1;
        if(can(mid)) {
            ans = mid;
            r = mid-1;
        } else {
            l = mid+1;
        }
    }
    printf("%lld", ans);
    return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int i,n,k,a[55],ans=0;
  cin >> n >> k;
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a,a+n,greater<int>());
  for(i=0;i<k;i++){
    ans=ans+a[i];
  }
  cout << ans << endl;
  return 0;
  }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dp[100010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<100010;i++){
		dp[i]=i;
	}
	int a[12]={1,6,36,216,1296,1296*6,1296*36,9,81,729,729*9,729*81};
	sort(a,a+10);
	for(int i=0;i<100010;i++){
		for(int j=0;j<12;j++){
			if(i>=a[j]){
				dp[i]=min(dp[i],dp[i-a[j]]+1);
			}
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 640