akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


//SHORTCUTS

#define ll long long
#define endl '\n'
#define i1(a) cin>>a
#define i2(a,b) cin>>a>>b
#define i3(a,b,c) cin>>a>>b>>c
#define o1(a) cout<<a<<endl
#define o2(a,b) cout<<a<<" "<<b<<endl
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define f(i,a,b) for(int i = a;i<b;i++)
#define fe(i,a,b) for(int i = a;i<=b;i++)
#define fi(i,a,b) for(i=a;i<b;i++)
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair


// DEBUG CODE & FAST OUTPUT

#define printv(a) for (int i = 0; i < a.size(); i++) cout << a[i] << ' ';
#define printvl(a) for (int i = 0; i < a.size(); i++) cout << a[i] << endl;
#define printa(a, n) for (int i = 0; i< n; i++) cout << a[i] << ' ';
#define printal(a, n) for (int i = 0; i < n; i++) cout << a[i] << endl;


//DATA STRUCTURES

#define pq priority_queue
#define ms multiset
// #define y0 _y0_
// #define y1 _y1_
// #define div divi

typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;


//IMP CONSTANT
const int mod = 998244353, inf = 1e9 + 7;
const ll infll = 1e18 + 7;
bool google_contest = false;

//MODULAR OPERATIONS
ll myadd(ll a,ll b){
    ll ans = a+b;
    ans-= ans>=mod ? mod : 0;
    return ans; 
}
ll mysub(ll a, ll b){
    return (a-b+mod)%mod;
}
ll mymul(ll a,ll b){
    return (a*b)%mod;
}
ll mypow(ll a, ll b){
    ll ans = 1;
    while(b>0)
        if(b&1) ans = mymul(ans,a),b--;
        else a = mymul(a,a),b >>= 1;
    return ans;
}
ll nCr(ll n,ll r){
    if(r==0)return 1;
    if(r==1)return n;
    if(n==0)return 0;
    return mymul(n,mymul(nCr(n-1,r-1),mypow(r,mod-2)));
}




const int dx[4] = {1, -1, 0,  0};
const int dy[4] = {0, 0,  1, -1};
//    /\    |  |\  /|                      
//   /__\   |  | \/ |           
//  /    \  |  |    | 



int main(){

ios_base::sync_with_stdio(0);
cin.tie(0); 
cout.tie(0);

int t,tt;
t=1;
// i1(t);
if(google_contest)tt=1;

while(t--){
int a,b,c,d;
i2(a,b);
i2(c,d);

ll dp[c+1][d+1];

f(i,0,c+1){
    f(j,0,d+1)dp[i][j]=0;
}


dp[a][b]=1;

f(i,a+1,c+1)dp[i][b] = mymul(b,dp[i-1][b]);

f(j,b+1,d+1)dp[a][j] = mymul(a,dp[a][j-1]); 


f(i,a+1,c+1){
    f(j,b+1,d+1){
        dp[i][j] = myadd(mymul(dp[i-1][j],(j)),mymul(dp[i][j-1],(i)));
        dp[i][j] = mysub(dp[i][j],mymul((i-1)*(j-1),dp[i-1][j-1]));
    }
}
o1(dp[c][d]);
// f(i,0,c+1){
//     f(j,0,d+1)cout<<dp[i][j]<< " ";
//     cout<<endl;
// }
if(google_contest){
    cout<<"Case "<<tt++<<": ";
}
}

return 0;   
}


//    /\    |  |\  /|                      
//   /__\   |  | \/ |           
//  /    \  |  |    |   OVER!!!!


Measured memory_bytes: 73992
#ABC043-B
s = input()

result = []

for i in s:
    if i == '0':
        result.append('0')
    elif i == '1':
        result.append('1')
    else:
        if len(result) == 0:
            continue
        else:
            result.pop(-1)
            
print("".join(result))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

void rec(int digits, ll value, vector<ll> &all){
   all.push_back(value);

   if(digits == 10) return;

   for(int i = -1; i <= 1; i++){
      int add = (value % 10) + i;
      if(0 <= add && add <= 9) rec(digits + 1, value * 10 + add, all);
   }
}

int main(){
   int k; cin >> k;
   vector<ll> all;
   for(int i = 1; i < 10; i++) rec(1, i, all);

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

   cout << all[k - 1] << endl;
}

Measured memory_bytes: 2420
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>

using namespace std;

#define LL long long

LL n,ans = 1e17,x,y;

int main() {
    scanf("%lld",&n);
    for(int i = 1 ; i <= sqrt(n) ; i++) {
        if(i * (n / i) == n) {
            ans = min(ans,i + (n / i));
        }
    }
    printf("%lld\n",ans - 2);
    //system("pause");
    return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;
int N, M;
vector<int> A;
vector<int> B;
P B_C[100005];

bool compare_P(P a,P b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main() {
  cin >> N >> M;
  int a,b,c;
  rep(i, N) {
    cin >> a;
    A.push_back(a);
  }
  rep(i, M) {
    cin >> b >> c;
    B_C[i] = make_pair(b, c);
  }
  sort(B_C, B_C+M, compare_P);
  /* rep(i, M) cout << B_C[i].first << " : " << B_C[i].second << endl; */
  int use_b=0;
  int b_c_s=0;
  while(use_b<N && b_c_s<M) {
    int b = B_C[b_c_s].first;
    int c = B_C[b_c_s++].second;
    /* cout << "c : " << c << endl; */
    rep(i, min(N-use_b, b)) B.push_back(c);
    use_b += min(N-use_b, b);
  }
  A.insert(A.end(), B.begin(), B.end());
  sort(A.begin(), A.end(), greater<int>());
  /* rep(i, N+M) cout << A[i] << endl; */
  cout << accumulate(A.begin(), A.begin()+N, (ll)0) << endl;
  return 0;
}



Measured memory_bytes: 2808
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <queue>
#include <climits>
using namespace std;
typedef pair<int,int> p;
int d[100003];
vector<p>edge[100002];
int main()
{
    priority_queue<p,vector<p>,greater<p> > que;
    int v,e,r;
    int s,t,d0;
    cin>>v>>e>>r;
    for(int i=0;i<100002;i++){d[i]=INT_MAX;}
    for(int i=0;i<e;i++){
        scanf("%d%d%d",&s,&t,&d0);
        edge[s].push_back(p(t,d0));}
    que.push(p(0,r));
    d[r]=0;
    while(!que.empty()){
        p cur=que.top();
        que.pop();
        if(d[cur.second]<cur.first)continue;
        for(int i=0;i<edge[cur.second].size();i++){
            p to=edge[cur.second][i];
            if(d[to.first]>=d[cur.second]+to.second){
                d[to.first]=d[cur.second]+to.second;
                que.push(p(d[to.first],to.first));}
        }
    }
    for(int i=0;i<v;i++){
        if(d[i]==INT_MAX)cout<<"INF"<<endl;
        else
            cout<<d[i]<<endl; }
    return 0;
}

Measured memory_bytes: 11368
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll arr[100];
ll dp[55][55][105];
ll recur(int l,int r,int rem,ll p,ll n,int cnt,vector<ll>&v)
{
    //  cout<<l<<" "<<r<<" "<<rem<<" "<<p<<" "<<n<<endl;
    if(l>r)
    {
        priority_queue<int>pq;
        int sz=v.size();
        for(int i=0; i<sz; i++)
        {
            if(v[i]<0)
                pq.push(v[i]*-1);
        }
        int ans=p+n,k=rem;
        while(!pq.empty() && k--)
        {

            ans+=pq.top();
            pq.pop();
        }
        return ans;
    }
    if(rem==0)
    {
        // cout<<l<<" "<<r<<" "<<" "<<p<<" "<<n<<" "<<p+n<<endl;
        return p+n;
    }
    ll &ret=dp[l][r][rem];
    if(~ret)
        return ret;
    ret=max(ret,p+n);
    if(cnt>=rem)
    {
        priority_queue<ll>pq;
        int sz=v.size();
        for(int i=0; i<sz; i++)
        {
            if(v[i]<0)
                pq.push(v[i]*-1);
        }
        ll ans=p+n,k=rem;
        while(!pq.empty() && k--)
        {

            ans+=pq.top();
            pq.pop();
        }
        ret=max(ret,ans);
    }
    ll x=0,y=0;
    if(arr[l]<0)
        y=arr[l];
    else
        x=arr[l];
    v.push_back(arr[l]);
    ret=max(ret,recur(l+1,r,rem-1,p+x,n+y,cnt+(arr[l]<0),v));
    x=0,y=0;
    v.pop_back();

    if(arr[r]<0)
        y=arr[r];
    else
        x=arr[r];
    v.push_back(arr[r]);
    ret=max(ret,recur(l,r-1,rem-1,p+x,n+y,cnt+(arr[r]<0),v));
    v.pop_back();
    return ret;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,moves;
    cin>>n>>moves;
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    memset(dp,-1,sizeof(dp));
    vector<ll>v;

    cout<<recur(0,n-1,moves,0,0,0,v)<<endl;


    return 0;
}


Measured memory_bytes: 6096
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N;
  cin>>N; 
  vector<int> a(N);  
  for(int j=0; j<N;j++){
    cin>>a.at(j);
  }
  
  for(int i=N-1; i>=0;i--){
    if(i%2!=N%2){
      cout<<a.at(i)<<" ";
    }
  }
 
  for(int i=0; i<N;i++){
    if(i%2==N%2){
      cout<<a.at(i)<<" ";
    }
  }

}




Measured memory_bytes: 2944
N,M=map(int,input().split())
L=[]
R=[]
for i in range(M):
    l,r=map(int,input().split())
    L.append(l)
    R.append(r)

bottom=1
top=N

for i in range(M):
    if L[i] > bottom:
        bottom = L[i]
    if R[i] < top:
        top = R[i]

if top >= bottom:
    ans = top-bottom+1
else:
    ans = 0
print(ans)


Measured memory_bytes: 10996
def main():
    a, b = map(int, input().split())
    address = input()

    flag = True
    for i in range(len(address)):
        if i == a:
            if address[i] != '-':
                flag = False
                break
            else:
                continue
        try:
            tmp = int(address[i])
        except ValueError:
            flag = False
            break

    if flag:
        print('Yes')
    else:
        print('No')
            

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
char m[182];c;E(p){m[p]-49||--m[p]+E(p-1)+E(p+1)+E(p-13)+E(p+13);}main(i){for(;read(c=0,m+13,157)>155;printf("%d\n",c))for(i=12;++i<168;)m[i]-49||E(i)+c++;exit(0);}

Measured memory_bytes: 0
#include <iostream>
#include <cmath>
using namespace std;
#define EPS 1e-5

//0080
int main(){
	// x^3=qを漸化式でとく
	// X(n+1) = X(n)-( X(n)^3 - q )/( 3*(X(n)^2) )

	int q;
	while(cin >> q, q!=-1){
		double x = (double)q/2.0;
		while(fabs(x*x*x-q) >= q*EPS){
			x = x - (x*x*x-q)/(3*x*x);
		}

		cout.setf(ios::fixed);
		cout.precision(6);
		cout << x << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np

N = int(raw_input())
A = np.array(map(int, raw_input().split()))
# A = map(lambda x: format(x, '060b'), A)
MOD = 10**9 + 7

count = dict()
for i in range(60):
    # zeros = len([a[i] for a in A if a[i] == '0'])
    zeros = np.count_nonzero((A>>i)&1)
    ones = N - zeros
    count[i] = zeros*ones

mod_val = dict()
curr = 1
for i in range(60):
    mod_val[i] = curr % MOD
    curr = (2*curr) % MOD

ans = 0
for i in count:
    ans = (ans + count[i]*mod_val[i]) % MOD

print ans


Measured memory_bytes: 38628
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>

int main(void){
	std::string s;
	std::cin >> s;
	int ans = s.size();
	for(int i=1;i<s.size();i++){
		if(s[i] == s[i-1]){
			i+=2;
			ans--;
		}
	}
	std::cout << ans << std::endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,m;
    cin>>n>>m;
    vl x(n),y(n),z(n);
    rep(i,n)cin>>x[i]>>y[i]>>z[i];
    vvl a(8);
    rep(i,n){
        int cnt=0;
        ll X,Y,Z;
        rep(j,2){
            rep(k,2){
                rep(l,2){
                    if(j==0)X=x[i];
                    else X=-x[i];
                    if(k==0)Y=y[i];
                    else Y=-y[i];
                    if(l==0)Z=z[i];
                    else Z=-z[i];
                    a[cnt].PB(X+Y+Z);
                    cnt++;
                }
            }
        }
    }
    rep(i,8){sort(all(a[i]));reverse(all(a[i]));}
    ll ans=-1e18;
    rep(i,8){
        ll sum=0;
        rep(j,m)sum+=a[i][j];
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}

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

int f(int x, int y) {
	return x <= y ? y - x : x - y + 2;
}

int main()
{
	int x, y;
	cin >> x >> y;
	cout << min(f(x, y), min(f(-x, y) + 1, min(f(x, -y) + 1, f(-x, -y) + 2))) << endl;
	return 0;
}


Measured memory_bytes: 256
(let ((n (read))
      (x (read))
      (a (make-array 0 :element-type 'integer
                       :fill-pointer 0
                       :adjustable t))
      (ans 0)
      (temp 0)
      (flg T))
  (loop repeat n do
        (vector-push-extend (read) a))
  (setf a (sort a #'<))
  (loop for i below n while flg do
        (incf temp (aref a i))
        (if (<= temp x) (incf ans) (setf flg nil))
        (if (and (= i (1- n)) (< temp x)) (decf ans)))
  (princ ans))


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

int main() {
    while (1) {
        string g;
        int y, m, d;
        cin >> g;
        cin >> y >> m >> d;
        if(g == "#")break;
        if(y<31 || y==31 && m<5){
            cout << g << " " << y << " " << m << " " << d << endl;
        }
        else {
            cout << "?" << " " << y-30 << " " << m << " " << d << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3156
use std::io;
//use std::collections::HashMap;
//use std::collections::BinaryHeap;
//use std::collections::HashSet;
//use std::mem; // mem::swap(&mut x,&mut y);
//use std::cmp; // cmp::max,cmp::min

// Rust memo: https://hackmd.io/i0lQY1OKTDW1t66TECOmiw?both

#[allow(dead_code)]
fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
fn read_charvec() -> Vec<char> {
    read_line().chars().collect()
}

#[allow(dead_code)]
fn read_ints() -> Vec<i64> {
    let s = read_line();
    let split: Vec<&str> = s.split(" ").collect();
    split
        .iter()
        .map(|&x| x.to_string().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_int() -> i64 {
    read_ints()[0]
}

#[allow(dead_code)]
fn reverse(s: &String) -> String {
    s.chars().rev().collect::<String>()
}

#[allow(dead_code)]
fn read_lines(n: i64) -> Vec<String> {
    let mut xs = Vec::new();

    for _i in 0..n {
        xs.push(read_line());
    }

    xs
}

#[allow(dead_code)]
fn read_ints2(n: i64) -> Vec<i64> {
    read_lines(n).iter().map(|x| x.parse().unwrap()).collect()
}

#[allow(dead_code)]
fn arange(start: i64, end: i64, step: i64) -> Vec<i64> {
    let mut ret = Vec::new();
    let mut i = start;

    while i < end {
        ret.push(i);
        i += step;
    }

    ret
}

#[allow(dead_code)]
const DXS: [i64; 4] = [0, 0, 1, -1];
#[allow(dead_code)]
const DYS: [i64; 4] = [1, -1, 0, 0];
#[allow(dead_code)]
const INF: i64 = 99999999999;
#[allow(dead_code)]
const N_PRIME: i64 = 1000000007;

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

fn main() {
    let n = read_int() as usize;
    let mut xs = vec![];

    for _i in 0..n {
        let v = read_ints();
        let x = v[0];
        let l = v[1];

        xs.push((x - l, x + l));
    }

    xs.sort_by_key(|x| x.1);

    let mut cnt = 0;
    let mut arm_end = -INF;
    for x in xs {
        if arm_end <= x.0 {
            cnt += 1;
            arm_end = x.1;
        }
    }

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


Measured memory_bytes: 6396
#include<stdio.h>
#define N 100000
 
int n;
void partition(int A[],int p,int r){
  int x,i,j,temp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i += 1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
     }
  }
  for(j=0;j<i+1;j++)printf("%d ",A[j]);
  temp=A[i+1];
  A[i+1]=A[r];
  A[r]=temp;
  printf("[%d] ",A[i+1]);
  for(j=i+2;j<n-1;j++)printf("%d ",A[j]);
   
  printf("%d\n",A[n-1]);
}
 
int main(){
  int i,A[N];
  scanf("%d",&n);
   
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  partition(A,0,n-1);
  return 0;
}

Measured memory_bytes: 988
#include<stdio.h>

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

    char j[n][3];

    int a=0,w=0,t=0,r=0,i;

    for(i = 0; i <=n -1 ;i++){
        scanf("%s",&j[i]);
        if(j[i][0] == 'A'){
            a++;
        }
        if(j[i][0] == 'W'){
            w++;
        }
        if(j[i][0] == 'T'){
            t++;
        }
        if(j[i][0] == 'R'){
            r++;
        }
    }
    printf("AC x %d\n",a);
    printf("WA x %d\n",w);
    printf("TLE x %d\n",t);
    printf("RE x %d\n",r);
    
}

Measured memory_bytes: 1996
#include<bits/stdc++.h>
using namespace std;
char ch[10][10];
int main()
{


    int n,m,a,b,i,j,x,y,t,k,col,row,ans;

    while(scanf("%d %d %d",&n,&m,&k)==3)
    {
        getchar();
        ans = 0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%c",&ch[i][j]);
            }
            getchar();
        }


        for(row=0;row<=(1<<n)-1;row++)
        {
            for(col=0;col<=(1<<m)-1;col++)
            {

                x = 0;

                for(i=0;i<n;i++)
                {
                    for(j=0;j<m;j++)
                    {
                        if((((row>>i)&1)==0)&&(((col>>j)&1)==0)&&ch[i][j]=='#')
                        {
                            x++;
                        }
                    }
                }
                if(x==k)ans++;
            }
        }

        printf("%d\n",ans);




    }












return 0;
}


Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int a[500000];
int main()
{
	for (int i=1;i<=5;i++)
	  cin>>a[i];
	for (int i=1;i<=5;i++)
	  if(a[i]==0) 
	    {
	    	cout<<i<<endl;
	    	return 0;
	    }
	return 0;
} 

Measured memory_bytes: 3616
N = int(input())

def solve(N):
    if 6 >= N:
        return 1
    
    ans = 0
    a = (N // 11) * 2
    b = N % 11

    if b == 0:
        ans = a
    elif 0 < b <= 6:
        ans = a + 1
    else:
        ans = a + 2
    return ans

print(solve(N))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(int i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;

ll res;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    V<> a(n);
    REP(i,n) cin >> a[i];
    sort(rall(a));
    REP(i,n-1) res += a[Roundup_div(i, 2)];
    cout << res << endl;
}


Measured memory_bytes: 4772
N, M = map(int, input().split())

fr = []
to = []

for i in range(M):
    a, b = map(int, input().split())
    if a == 1:
        fr.append(b)
    elif b == 1:
        fr.append(a)
    elif a == N:
        to.append(b)
    elif b == N:
        to.append(a)

fr.sort()
to.sort()

searched = 0
for i in range(len(fr)):
    while searched <= len(to) - 1 and to[searched] <= fr[i]:
        if to[searched] == fr[i]:
            print('POSSIBLE')
            exit()
        searched += 1


print('IMPOSSIBLE')

Measured memory_bytes: 11436
#include<iostream>
using namespace std;
int judge(int n)
{
    int num=0;
    for(int i=1;i*i<n;i++)
    {
        if(n%i==0&&i*i!=n) num+=2;
        if(i*i==n) num++;
    }
    return num;
}
int main()
{
    int n;
    while(cin>>n)
    {
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(i%2==0) continue;
            if(judge(i)==8) ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(x,to) for(int x=0;x<(to);x++)
#define FOR1(x,to) for(int x=1;x<(to);x++)
int main()
{
    int n,j;cin>>n;
    int a[n];
    
    FOR(i,n){
        cin>>a[i];
    }
    
    FOR(i,n){
        if(i>0) cout<<" ";
            cout<<a[i];
        }
    cout<<"\n";
        
    for(int i=1;i<n;i++){
        int v=a[i];
        j=i-1;
        while(j>=0 and a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        FOR(i,n){
            if(i>0) cout<<" ";
            cout<<a[i];
        }
        if(i!=(n)){
        cout<<"\n";
        }
    }
}



Measured memory_bytes: 3088
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <unordered_set>
#include <stack>
#include <iomanip>
using namespace std;

int a[3][3], n;
bool c[3][3];
unordered_set<int> b;

bool check_row(int i) {
    return c[i][0] && c[i][1] && c[i][2];
}

bool check_col(int i) {
    return c[0][i] && c[1][i] && c[2][i];
}

bool check_diag() {
    return (c[0][0] && c[1][1] && c[2][2]) || (c[2][0] && c[1][1] && c[0][2]);
}

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

    for(int i=0; i<3; i++)
        for(int j=0; j<3; j++)  
            cin >> a[i][j];
    cin >> n;
    for(int i=0; i<n; i++) {
        int x;
        cin >> x;
        b.insert(x);
    }
    for(int i=0; i<3; i++)  
        for(int j=0; j<3; j++)
            c[i][j] = b.count(a[i][j]);
    if(check_row(0) || check_row(1) || check_row(2) || check_col(0) || check_col(1) || check_col(2) || check_diag())
        cout << "Yes\n";
    else cout << "No\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
int main(){
	//freopen("in.txt","r",stdin);
	ll ans = 0;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans += (ll)i * (n-i+1);
	}
	
	int _ = n;
	_--;
	while(_--){
		int a,b;
		cin>>a>>b;
		if(a > b) swap(a,b);
		ans -= (ll)a * (n-b+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
using namespace std;

template< typename Monoid >
struct SegmentTree {
  using F = function< Monoid(Monoid, Monoid) >;

  int sz;
  vector< Monoid > seg;

  const F f;
  const Monoid M1;

  SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz, M1);
  }

  void set(int k, const Monoid &x) {
    seg[k + sz] = x;
  }

  void build() {
    for(int k = sz - 1; k > 0; k--) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  void update(int k, const Monoid &x) {
    k += sz;
    seg[k] = x;
    while(k >>= 1) {
      seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
    }
  }

  Monoid query(int a, int b) {
    Monoid L = M1, R = M1;
    for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
      if(a & 1) L = f(L, seg[a++]);
      if(b & 1) R = f(seg[--b], R);
    }
    return f(L, R);
  }

  Monoid operator[](const int &k) const {
    return seg[k + sz];
  }
};

int gcd(int a, int b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

int main()
{
  int N;
  cin>>N;
  SegmentTree< int > seg(N, [](int a, int b) { return gcd(a, b); }, 0);
  for(int i=1;i<=N;i++){
    int a;cin>>a;
    seg.update(i,a);
  }
  int ans=max(seg.query(2,N+1),seg.query(1,N));
  for(int i=2;i<N;i++){
    ans=max(gcd(seg.query(1,i),seg.query(i+1,N+1)),ans);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1280
import java.util.*;
import java.math.*;

public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    // static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    static long[] fact = new long[100];
        public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        long x = sc.nextLong();
        long tmp = a%x;
        a/=x;
        b/=x;
        System.out.println(b-a+(tmp==0?1:0));
    }
    
}


Measured memory_bytes: 23764
N = int(input())
table = [1e100 for i in range(100000 + 10)]
table[0] = 0

for i in range(1, 8):
    if 6 ** i <= 100000 + 10:
        table[6 ** i] = 1

    if 9 ** i <= 100000 + 10:
        table[9 ** i] = 1

for i in range(1, 100000 + 10):
    table[i] = table[i - 1] + 1
    for j in range(1, 8):
        if i - 6 ** j >= 0:
            table[i] = min(table[i], table[i - 6 ** j] + 1)
        if i - 9 ** j >= 0:
            table[i] = min(table[i], table[i - 9 ** j] + 1)

print(table[N])


Measured memory_bytes: 3864
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long int MOD = 1000000007;


int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}



int main()
{
	int cnt = 0;
	string s, t;

	cin >> s >> t;

	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i])
			cnt++;
	}

	cout << cnt << endl;

	return 0;

}

Measured memory_bytes: 256
def ABC141B():
    S = input()

    for i, s in enumerate(S):
        if i % 2 == 0:
            if s == 'L':
                print('No')
                return()
        else:
            if s == 'R':
                print('No')
                return()

    print('Yes')
    return()

ABC141B()    


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define MAX(X,Y) (*max_element(X,Y))
#define MIN(X,Y) (*min_element(X,Y))
#define NP(X,Y) next_permutation(X,Y)

int N;
int A[20010],B[20010],C[20010];

signed main(){
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>C[i];
	}
	for(int i=1;i<=N;i++){
		A[C[i]]+=i;
		B[C[i]]+=i;
	}
	for(int i=2;i<=N;i++){
		A[i]+=A[i-1];
		B[N-i+1]+=B[N-i+2];
	}
	for(int i=1;i<=N;i++){
		if(i!=1)cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	for(int i=1;i<=N;i++){
		if(i!=1)cout<<" ";
		cout<<B[i];
	}
	cout<<endl;
	return 0;
}

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

#define ll long long int
#define mod 1000000007

using namespace std;


int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    int cnt = 0;
    int n = t.length();
    for(int i = 0; i < n; i++){
        if(s[i] != t[i])
            cnt++;
    }
    cout << cnt;
}









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

int main()
{
	while( 1 ) {
		int a, b;
		char op;
		cin >> a >> op >> b;
		if( op == '?' ) {
			break;
		}
		if( op == '+' ) {
			cout << a + b << endl;
		}
		else if( op == '-' ) {
			cout << a - b << endl;
		}
		else if( op == '*' ) {
			cout << a * b << endl;
		}
		else if( op == '/' ) {
			cout << a / b << endl;
		}
	}
}



Measured memory_bytes: 3104
import sys
from collections import defaultdict
range = xrange
input = raw_input

n = int(input())

count = defaultdict(int)
S = sys.stdin.read().split()
for c in S:
    count[c] += 1

best = -1
for s in count:
    best = max(best, count[s])

out = []
for s in count:
    if count[s] == best:
        out.append(s)
out.sort()
print '\n'.join(out)


Measured memory_bytes: 77216
#include<cstdio>
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(void){
	int dp[101][3][3]={0};
	
	int n,m;
	cin>>n>>m;
	
	int plan[101]={0};
	rep(i,101)plan[i]=-1;
	
	rep(i,m){
		int a,b;
		cin>>a>>b;
		plan[a]=b-1;
	}
	
	dp[0][0][0]=1;
	rep(i,n){
		rep(j,3){
			rep(k,3){
				rep(p,3){
					if(i>=2 && j==k && k==p)continue;
					if(plan[i+1]!=-1 && plan[i+1]!=p)continue;
					dp[i+1][p][k] += dp[i][k][j];
					dp[i+1][p][k] %= 10000;
				}
			}
		}
	}
	
	/*
	puts("--0--  --1--  --2-- <<=bef");
	puts("0 1 2  0 1 2  0 1 2 <<=bef bef");
	puts("");
	
	reps(i,1,n+1){
		rep(j,3){
			rep(k,3){
				printf("%d ",dp[i][j][k]);
			}printf(" ");
		}puts("");
	}*/
	
	int ans=0;
	rep(j,3){
		rep(k,3){
			ans += dp[n][j][k];
			ans %= 10000;
		}
	}
	
	printf("%d\n",ans);
}

Measured memory_bytes: 1148
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**4
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

s = int(input())
mod=10**9+7
n = s//3
if n == 0:
  print(0)
  exit()
if n == 1:
  print(1)
  exit()
ans = 1
for i in range(2,n+1):
  a = s-i*3
  ans+=cmb(a+i-1,i-1,mod)
  ans%=mod
print(ans)

Measured memory_bytes: 67912
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		
		// 計算
		long result = 0;
		result = max(a*c, max(a*d, max(b*c, b*d)));
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 25400
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
int p[1010];

int solve() {
    sort(p, p+n);
    int res = 0;
    for (int i = 0; i < k; i++) {
        res += p[i];
    }
    return res;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> p[i];
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 3544
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	string a,b;
	cin>>a>>b;
	if(a[1]==b[1] && a[0] == b[2] && a[2]==b[0]){
		cout<<"YES";
	}
	else{
		cout<<"NO";
	}
	return 0;
}

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

int main(){
  ll n, m;
  cin >> n >> m;
  ll ans;
  ans = n*(n - 1) / 2 + m*(m - 1) / 2;
  cout << ans << "\n";
}

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

int main() {
  int n;
  cin >> n;
  set<string> ans;
  string s;
  rep(i,n) {
    cin >> s;
    ans.insert(s);
  }

  cout << ans.size() << endl;
  return 0;
}


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

int N,Q;
int fid[100010];
bool in[100010];

int main()
{
    scanf("%d%d",&N,&Q);
    in[1] = in[2] = true;
    int now = 1;
    for(int i = 1; i <= N; i++)fid[i] = i;
    for(int i = 0; i < Q; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        swap(fid[a],fid[b]);
        if(now == a)now = b;
        else if(now == b)now = a;
        in[fid[now + 1]] = in[fid[now - 1]] = true;
    }

    int ans = 0;
    for(int i = 1; i <= N; i++)if(in[i])ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7;
ll GCD(ll x, ll y) {if (x % y == 0) return y;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x * y / GCD(x, y);}

int main(){
  ll n,M=-MM,m=MM; cin>>n;
  rep(i,n){
  ll a; cin>>a;
    M=max(M,a); m=min(m,a);
  }
 cout<<M-m<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int h, w, c;
int p[8][8];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void print(int time){
  printf("time %d\n", time);
  REP(y, h){
    REP(x, w) printf("%d ", p[y][x]);
    cout<<endl;
  }
}
int dfs(int time){
  if(time != 5){
    bool equal[8][8] = {};
    queue<int> qx; queue<int> qy;
    qx.push(0); qy.push(0);
    while(!qx.empty()){
      int x = qx.front(); qx.pop();
      int y = qy.front(); qy.pop();
      equal[y][x] = true;
      REP(r, 4){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(nx >= 0 && ny >= 0 && nx < w && ny < h && !equal[ny][nx] && p[y][x] == p[ny][nx]){
          qx.push(nx); qy.push(ny);
          equal[ny][nx] = true;
        }
      }
    }
    int res = 0;
    int tmp[8][8];
    REP(y, h)REP(x, w) tmp[y][x] = p[y][x];
    for(int color = 1; color <= 6; color++){
      REP(y, h)REP(x, w)if(equal[y][x]){
        p[y][x] = color;
      }
      res = max(res, dfs(time + 1));
      REP(y, h)REP(x, w) p[y][x] = tmp[y][x];
    }
    return res;
  }
  else if(time == 5){
    if(p[0][0] != c) return 0;
    bool equal[8][8] = {};
    queue<int> qx; queue<int> qy;
    qx.push(0); qy.push(0);
    while(!qx.empty()){
      int x = qx.front(); qx.pop();
      int y = qy.front(); qy.pop();
      equal[y][x] = true;
      REP(r, 4){
        int nx = x + dx[r];
        int ny = y + dy[r];
        if(nx >= 0 && ny >= 0 && nx < w && ny < h && !equal[ny][nx] && p[y][x] == p[ny][nx]){
          qx.push(nx); qy.push(ny);
          equal[ny][nx] = true;
        }
      }
    }
    int res = 0;
    REP(y, h)REP(x, w) res += equal[y][x];
    return res;
  }
}

int main(){
  while(cin>>h>>w>>c && h){
    REP(y, h)REP(x, w) cin>>p[y][x];
    cout<<dfs(0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 920
import java.util.*;
 
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 X = sc.nextInt();
    int res = 0;
    
    for(int a=0;a<=A;a++){
      for(int b=0;b<=B;b++){
        int c=(X-a*500-b*100)/50;
        if(c>=0&&c<=C){
          res++;
        }
      }
    }
    System.out.println(res);
  }
}

Measured memory_bytes: 21204
N = int(input())
T = list(map(int, input().split()))

for i in range(int(input())):
    P, X = map(int, input().split())
    t = 0
    
    for j in range(N):
        if j+1 == P: t += X
        else: t += T[j]
    
    print(t)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
int k,tot;
void dfs(int x,long long s,int f){
	if(x==1){
		tot++;
		if(tot==k){
			cout<<s;
			exit(0);
		}
		return;
	}
	if(f>0){
		dfs(x-1,s*10+f-1,f-1);
	}
	dfs(x-1,s*10+f,f);
	if(f<9){
		dfs(x-1,s*10+f+1,f+1);
	}
}
int main(){
	cin>>k;
	for(int i=1;i<=10;i++){
		for(long long j=1;j<=9;j++){
			dfs(i,j,j);
		}
	}
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    string s;
    cin >> s;
    deque<char> sq;
    rep(i, s.length()) {
        sq.push_back(s[i]);
    }
    int ans = 0;
    char f, b;
    while(sq.size() > 1) {
        f = sq.front();
        b = sq.back();
        if (f == b) {
            sq.pop_front();            
            sq.pop_back();
        }
        else if (f == 'x') {
            sq.push_back('x');
            ans++;
        }
        else if (b == 'x') {
            sq.push_front('x');
            ans++;
        }
        else {
            puts("-1");
            return 0;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <functional>
#include <time.h>
#include <math.h>

using namespace std;


int main() {

	int n;
	string s,baf,ch;

	cin >> n >> s;

	baf = s.substr(0,s.length()/2);
	ch = baf + baf;
	if (s == ch) {
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

int main() {
	string s;

	cin >> s;

	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


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

int main(){
	int a[N];
	int n;
	cin >>n;
	for(int i=0;i<n;++i){
		cin >>a[i];
	}
	
	int minv=a[0],maxv=-2000000000;
	for(int j=1;j<n;++j){
		maxv = maxv>(a[j]-minv)?maxv:(a[j]-minv);
		minv = minv<a[j]?minv:a[j];
	}
	cout <<maxv <<endl;
	return 0;
}



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

int MIN(int a, int b){return a>b?b:a;}

int compUp(const void* a, const void*b){
    return *(int*)a - *(int*)b;
}

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

int main(void){
    int N, X;
    scanf("%d%d", &N, &X);
    int x[N];
    for(int i = 0; i < N; i++){scanf("%d", &x[i]);}
    qsort(x, N, sizeof(int), compUp);

    int Xidx;
    int flag = 0;
    //Xがxでどこに入るかを見つける
    for(int i = 0; i < N; i++){
        if(x[i] > X){
            Xidx = i;
            flag= 1;
            break;
        }
    }
    if(flag == 0){Xidx = N;}
    //Xとx[n]を新たなy[n+1]にまとめちゃう
    //ここのコード読みにくすぎるのでゴミ
    int y[N+1];
    for(int i = 0; i < Xidx; i++){y[i] = x[i];}
    if(flag == 1){
        y[Xidx] = X;
        for(int i = Xidx+1; i < N+1; i++){
            y[i] = x[i-1];
        }
    }
    else{y[N] = X;}
    
    int d[N];
    for(int i = 0; i < N; i++){d[i] = y[i+1] - y[i];}
    if(N == 1){printf("%d\n", d[0]); return 0;}
    int ans = 1000000001;
    for(int i = 0; i < N-1; i++){
        ans = MIN(gcd(d[i], d[i+1]), ans);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1396
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

int main()
{
	string a, b;
	cin >> a >> b;

	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
		return (0);
	}
	else if (a.size() < b.size()) {
		cout << "LESS" << endl;
		return (0);
	}
	else {
		for (int i = 0; i < a.size(); i++) {
			if (a[i] > b[i]) {
				cout << "GREATER" << endl;
				return (0);
			}
			else if (a[i] < b[i]) {
				cout << "LESS" << endl;
				return (0);
			}
			else {
				continue;
			}
		}
	}
	cout << "EQUAL" << endl;

	return (0);
}

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

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

  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> drink_info_v;
  REP(i, N) {
    int a, b;
    cin >> a >> b;
    drink_info_v.push_back(make_pair(a, b));
  }
  sort(drink_info_v.begin(), drink_info_v.end());

  ll cnt = 0;
  ll ans = 0;
  for(auto drink_info : drink_info_v) {
    ll price = drink_info.first;
    ll num = drink_info.second;
    if(num < M - cnt) {
      ans += price * num;
      cnt += num;
    } else {
      ans += price * (M - cnt);
      break;
    }
  }

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

Measured memory_bytes: 1400
#include <stdio.h>

char map[52][52]; //map[h][w]
int w,h;

void scanmap(){
	int i;
	for(i=0;i<h;i++){
		scanf("%s",map[i]);
	}
}

void wpaint(int a,int b){
	if(a>0 && map[a-1][b] == '.'){
		map[a-1][b] = 'w';
		wpaint(a-1,b);
	}
	if(b>0 && map[a][b-1] == '.'){
		map[a][b-1] = 'w';
		wpaint(a,b-1);
	}
	if(a<h-1 && map[a+1][b] == '.'){
		map[a+1][b] = 'w';
		wpaint(a+1,b);
	}
	if(b<w-1 && map[a][b+1] == '.'){
		map[a][b+1] = 'w';
		wpaint(a,b+1);
	}
}

void bpaint(int a,int b){
	if(a>0){
		if(map[a-1][b] == '.'){
			map[a-1][b] = 'b';
			bpaint(a-1,b);
		}else if(map[a-1][b] == 'w'){
			map[a-1][b] = 'g';
			bpaint(a-1,b);
		}
	}
	if(b>0){
		if(map[a][b-1] == '.'){
			map[a][b-1] = 'b';
			bpaint(a,b-1);
		}else if(map[a][b-1] == 'w'){
			map[a][b-1] = 'g';
			bpaint(a,b-1);
		}
	}
	if(a<h-1){
		if(map[a+1][b] == '.'){
			map[a+1][b] = 'b';
			bpaint(a+1,b);
		}else if(map[a+1][b] == 'w'){
			map[a+1][b] = 'g';
			bpaint(a+1,b);
		}
	}
	if(b<w-1){
		if(map[a][b+1] == '.'){
			map[a][b+1] = 'b';
			bpaint(a,b+1);
		}else if(map[a][b+1] == 'w'){
			map[a][b+1] = 'g';
			bpaint(a,b+1);
		}
	}
}

int bcount(){
	int i,j;
	int count = 0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(map[i][j] == 'b') count++;
		}
	}
	return count;
}

int wcount(){
	int i,j;
	int count = 0;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(map[i][j] == 'w') count++;
		}
	}
	return count;
}

void printmap(){
	int i;
	for(i=0;i<h;i++){
		printf("%s\n",map[i]);
	}
}

void area(){
	scanmap();
	int i,j;
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(map[i][j] == 'W') wpaint(i,j);
		}
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(map[i][j] == 'B') bpaint(i,j);
		}
	}
	printf("%d %d\n",bcount(),wcount());
//	printmap();
}

int main(){
	while(1){
		scanf("%d %d",&w,&h);
		if(w == 0 && h == 0) break;
		area();
	}
	return 0;
}

Measured memory_bytes: 656
#include"bits/stdc++.h"
// #include "prettyprint.hpp"

using namespace std;

typedef long long ll;


#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, n) for(ll i=n; i>=0; i--)
#define reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()

ll split(ll n){
	if(n > 1){
		return 2*split(n/2)+1;
	}

	else return  1;
}


int main(){
	ll H;

	cin >> H;

	cout << split(H) << endl;

	return 0;
}	


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main(){
  int n,k;//a=(0,i),b=(k,i)
  int x[101];
  
  cin >> n >> k;
  for(int i=0;i<n;i++){
    cin >> x[i];
  }
  
  int ans=0;
  for(int i=0;i<n;i++){
    int d=x[i]-k;
    if(d<0)
      d*=-1;
    ans+=min(x[i]*2,d*2);
  }
  
  cout << ans << endl;
}


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

int main() {
	string s; cin >> s;
	string p; cin >> p;
	int i, j;
	for(i=0; i<s.length(); i++) {
		for(j=0; j<p.length() && i+j<s.length(); j++) {
			if(s[i+j] != p[j]) break;
		}
		if(j == p.length()) cout << i << endl;
	}
	return 0;
}


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

int main() {
  int h,w;
  string f;
  cin >> h >> w;
  for (int i; i<w+2; i++) f+='#';
  cout << f << endl;
  for (int i; i<h; i++) {
    string p;
    cout << '#';
    cin >> p;
    cout << p;
    cout << '#' << endl;
  }
  cout << f << endl;
}

Measured memory_bytes: 256