akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void){
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b) printf("Draw");
    else if(a>b||a==1) {
      if (b==1) {printf("Bob");}
      else printf("Alice");
    }
    else if(a<b||b==1) {
      if(a==1){printf("Alice");}
      else printf("Bob");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for (int i=0;i<4;i++) {
        cout<<s[i];
    }
    cout<<" ";
    for (int i=4;i<s.size();i++) {
        cout<<s[i];
    }
    cout<<endl;
}

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

int main() {
    char s[100];
    scanf("%s", s);
    for (int i = 0; s[i] != '\0'; i++)  {
        if (i % 2 == 0) {
            switch(s[i]) {
                case 'R':
                case 'U':
                case 'D':
                    break;
                default:
                    printf("No\n");
                    return 0;
            }
        } else {
            switch(s[i]) {
                case 'L':
                case 'U':
                case 'D':
                    break;
                default:
                    printf("No\n");
                    return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int h,w,i;
    cin>>h>>w;
    string s;
    for (i=0;i<h;i++)
    {
        cin>>s;
        cout<<s<<endl;
        cout<<s<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1ll<<60;

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    for(int i=1; i<=9; i++){
        for(int j=1; j<=9; j++){
            if(i*j==n){out("Yes"); return 0;}
        }
    }
    out("No");
    return 0;
}

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

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

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

    int ans = 1;
    int min = P[0];
    int max = P[0];

    for (size_t i = 0; i < N; i++)
    {
        if (P[i] < min)
        {
            min = P[i];
            ans++;
            continue;
        }

        if (P[i] > max)
        {
            max = P[i];
            continue;
        }
    }

    cout << ans << endl;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	string s;
	cin >> s;
	if (s.substr(0, 4) == "YAKI") {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
#define int long long
#define endl "\n"
#define deb(x) cout << #x << " -> " << x << endl;
#define print(x)                         \
    for (auto x_ : x) cout << x_ << " "; \
    cout << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define mod 1000000007  // 1e9 + 7
#define prec(x, y) fixed << setprecision(y) << x
 
void solve() {
    int n;
    cin >> n;
    int sum = 0;
    int prefix[n] = {};
    int a[n];
    for (auto &x : a) cin >> x, sum += x;
    prefix[0] = a[0];
    for (int i = 1; i < n; ++i) prefix[i] = ((prefix[i - 1] + a[i]) % mod);
    int res = 0;
    for (int i = 0; i < n; ++i) {
        int t = (a[i] * (prefix[n - 1] - prefix[i] + mod)) % mod;
        res = (t + res) % mod;
    }
    cout << (res % mod) << endl;
}
 
int32_t main() {
    ios::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
 
    int tc = 1;
    // cin >> tc;
    while (tc--) {
        solve();
    }
}

Measured memory_bytes: 6712
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int root(vector<int> &par, int x) {
  if (par[x] == x) {
    return x;
  }
  else {
    return par[x] = root(par, par[x]);
  }
}

bool same(vector<int> &par, int x, int y) {
  return root(par, x) == root(par, y);
}

void unite(vector<int> &par, vector<int> &cnt, int x, int y) {
  int rootx = root(par, x);
  int rooty = root(par, y);

  if (rootx == rooty) {
    return ;
  }
  else {
    par[rootx] = rooty;
    cnt[rooty] += cnt[rootx];
  }
}

int main() {

  int n, m;
  cin >> n >> m;

  vector<int> par(n, 0);
  rep(i, n) par[i] = i;

  vector<int> cnt(n, 1);

  vector<lli> ans(m, 0);
  vector<vector<int>> bridge(m, vector<int>(2, 0));

  int tmp0, tmp1;
  rep(i, m) {
    cin >> tmp0 >> tmp1;
    bridge[i][0] = tmp0 - 1;
    bridge[i][1] = tmp1 - 1;
  }

  for(int i = m - 1; i >= 0; i -= 1) {
    if (!same(par, bridge[i][0], bridge[i][1])) {
      ans[i] = cnt[par[bridge[i][0]]] * cnt[par[bridge[i][1]]];
      unite(par, cnt, bridge[i][0], bridge[i][1]);
    }
    else ans[i] = 0;
  }
  
  lli cntans = 0;
  rep(i, m) {
    cntans += ans[i];
    cout << cntans << endl;
  }
  
  return 0;
}


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



int main() {
    int n, k;
    cin >> n >> k;
    
    vector<int> h(n);
    rep(i,n) {
        cin >> h[i];
    }
    
    sort(h.rbegin(), h.rend());
    
    long int sum = 0;
    for(int i = k; i < n; i++) {
        sum += h[i];
    }
    
    cout << sum << endl;
    
    
    return 0;
}




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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << 2*M_PI*r << "\n";

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  string ans = "APPROVED";
  for (int i = 0, j; i < N; i++) {
    cin >> j;
    if (j % 2 == 0 && j % 3 != 0 && j % 5 != 0) {
      ans = "DENIED";
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.BufferedInputStream;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner (new BufferedInputStream(System.in));
    long n = sc.nextLong();
    long k = sc.nextLong();
    System.out.println(Math.min(n % k, Math.abs(k - n % k)));
  }
}

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

int main (void) {
	cin.tie(0);
	cin.sync_with_stdio(false);
	int n;
	double result = 0;
	cin >> n;
	while (n --) {
		double value;
		string kind;
		cin >> value >> kind;
		if (kind == "JPY")
			result += value;
		else
			result += value * 380000;
	}
	cout << result << '\n';
	return 0;
}

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

vector<int>to[200005];//辺を入力するための配列を準備
vector<int>ans;//答の配列を準備
void dfs(int v,int p=-1){
  //注目しているのはv、親は第二引数なし、デフォルト引数
  for(int u:to[v]){//辺に沿ってvに入るuを一つ一つチェック
    if (u==p)continue;//逆走させない枝刈り
    ans[u]+=ans[v];//累積和、今がv、次がu
    dfs(u,v);//再帰、uが始点、vが終点
  }
}
int main(){
  int n,q;
  cin>>n>>q;  
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    --a;--b;//ノード番号は1始まりなので0始まりに修正
    to[a].push_back(b);//aに入る辺はbから
    to[b].push_back(a);
  }
  ans.resize(n);//resizeしないとエラー、ノード数の配列が必要
  rep(i,q){
    int p,x;
    cin>>p>>x;
    --p;//ノード番号は1始まりなので0始まりに修正
    ans[p]+=x;//ノードpの大きさにxを加える
  }
  dfs(0);//ゼロから深さ優先探索を開始、親はp=-1（デフォルト引数）
  rep(i,n){//ノード0からの大きさを出力
    cout<<ans[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 23552
object Main extends App {
  val o = io.StdIn.readLine
  val e = io.StdIn.readLine

  def rec(str1: List[Char], str2: List[Char], choose: Int, acc: List[Char]): String = choose match {
    case 1 => str1 match {
      case Nil  => acc.mkString
      case head::tail => rec(tail, str2, 2, acc:+head)
      }
    case 2 => str2 match {
      case Nil  => acc.mkString
      case head::tail => rec(str1, tail, 1, acc:+head)
    }
  }

  val result = rec(o.toList, e.toList, 1, Nil)
  println(result)
}


Measured memory_bytes: 54756
#include <stdio.h>
 
int main(void)
{
	int A[10],a[10];
	int sum=0;
	int max=0;
	
	for(int i=0;i<5;i++){
		scanf("%d",&(A[i]));
	}
			
		for(int i=0;i<5;i++){
			sum=sum+A[i];
		}
		
		for(int i=0;i<5;i++){
			if(A[i]%10==0){
				a[i]=0;
				
			}else{
              a[i]=10-(A[i]%10);				
			}
			
			if(max<a[i]){				
				max=a[i];				
			}
			
			sum=sum+a[i];			
		}		
		printf("%d\n",sum-max);
		
		return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int a, b;
  cin >> a >> b;
  string aa = to_string(a), bb = to_string(b);
  rep(i, b-1) {
    aa += to_string(a);
  }
  
  rep(i, a-1) {
    bb += to_string(b);
  } 

  if(aa <= bb) cout << aa << endl;
  else cout << bb << endl;
  

  return 0;
}

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

uli xgcd(uli a,uli b,uli &x,uli &y){
   if(b==0){
      x=1,y=0;
      return a;
   }
   uli x1,y1;
   uli g=xgcd(b,a%b,x1,y1);
   x=y1;
   y=x1-(a/b)*y1;
   return g;
}
int main(){
   uli n,a,b,x,y;
   while(scanf("%lld %lld %lld",&n,&a,&b)==3){
      if(n==0 && a==0 && b==0)break;
      uli g=xgcd(a,b,x,y);
      uli ans=0;
      for(uli v=g;v<=n;v+=g){
         uli k=v/g;
         uli xx=k*x,yy=k*y;
         uli r=(xx*g)/b;
         if(xx<0 && (-xx*g)%b!=0)r--;
         if(-yy*g<=a*r){
            ans++;
         }
      }
      printf("%lld\n",n-ans);
   }
   return 0;
}

Measured memory_bytes: 1188
/***************************************************************
	File name: E.cpp
	Author: ljfcnyali
	Create time: 2019年07月20日 星期六 20时32分22秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 

const int maxn = 100010;

int a[maxn], len, n, c[maxn];

int main()
{
    scanf("%d", &n);
    REP(i, 1, n) scanf("%d", &c[i]);
    a[0] = 2147483647;
    REP(i, 1, n)
    {
        if ( a[len] >= c[i] ) { a[++ len] = c[i]; continue ; }
        int L = 1, R = len, x = -1;
        while ( L <= R ) 
        {
            int Mid = L + R >> 1;
            if ( a[Mid] < c[i] ) { x = Mid; R = Mid - 1; }
            else L = Mid + 1;
        }
        a[x] = c[i];
    }
    printf("%d\n", len);
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int num,t,ans=0;
int main() {
	scanf("%d", &t);
	for (int i = 1; i <= 31; ++i) {
		for (int j = 2; j <= 9; ++j) {
			num = 1;
			for (int k = 0; k < j; ++k) {
				num *= i;
			}
			if (num <= t && num > ans) {
				ans = num;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
H,W,D = map(int,input().split())
A = [tuple(map(int,input().split())) for i in range(H)]
Q = int(input())
LR = [tuple(map(int,input().split())) for i in range(Q)]

pos = [None] * (H*W)
for i,row in enumerate(A):
    for j,a in enumerate(row):
        pos[a-1] = (i,j)

cums = [0]*D
for (x1,y1),(x2,y2) in zip(pos, pos[D:]):
    d = abs(x1-x2) + abs(y1-y2)
    cums.append(cums[-D] + d)

ans = []
for l,r in LR:
    ans.append(cums[r-1] - cums[l-1])
print(*ans,sep='\n')

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

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

int main() {
  rep(i, 5) {
    int tmp;
    cin >> tmp;
    if (tmp == 0) {
      cout << i + 1;
    }
  }

  return 0;
}


Measured memory_bytes: 3592
m, d = (int(i) for i in input().split())
count = 0
for month in range(2, m+1):
    for day in range(2, d+1):
        d_1 = day % 10
        d_10 = day // 10
        if d_1 >= 2 and d_10 >= 2:
            if d_1 * d_10 == month:
                count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int A[N+1];
int GCD(int a,int b){
	return b==0?a:GCD(b,a%b);
}
int main(){
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
#endif
	int n,tmp,gcd=0;
	cin>>n; 
	for(int i=0;i<n;++i){
		cin>>tmp;
		++A[tmp];
		gcd=GCD(tmp,gcd);
	}
	
	//pairwise
	for(int i=2;i<=N;++i){
		int flag=0;
		for(int j=i;j<=N;j+=i){
			flag+=A[j];
			if(flag>=2) goto setwise;
		}
	}
	cout<<"pairwise coprime"<<endl;
	return 0;
	
	setwise:
	if(gcd==1) cout<<"setwise coprime"<<endl;
	else cout<<"not coprime"<<endl;
	return 0;
}


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

int main(void)
{
  char input[4];
  int i;
  char week[7][4]={ "SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT" };

    char *ptr1;
    char *ptr2;

  scanf("%s",input);



  for(i=0;i<7;i++){
        ptr1=&input[0];
        ptr2=&week[i][0];
      if(strcmp(ptr1,ptr2)==0)
        printf("%d",7-i);
  }
  return 0;
  
}
  


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 100000007

#define writeln(n) cout<<n<<endl

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int inf=100000000;

long long modpow(long long a, long long n, long long mod) //a^n
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

llong gcd(llong a, llong b) {
    return b != 0 ? gcd(b, a % b) : a;
}
//setprecision(10);



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> v(n,0);
    REP(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    double cnt=(double)(v[0]+v[1])/2;

    for(int i=2; i<n; i++)
    {
        cnt=(double)(cnt+v[i])/2;
    }
    cout<<cnt<<endl;
    return  0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	for (int i = 0; i < N; i++) {
		char c;
		cin >> c;
		if (c == 'Y') {
			cout << "Four" << endl;
			return 0;
		}
	}
	cout << "Three" << endl;

}






Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = 0
for i, b in enumerate(B):
    k = min(A[i], b)
    ans += k
    A[i] -= k
    b -= k

    k = min(A[i+1], b)
    ans += k
    A[i+1] -= k
    b -= k

print(ans)

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> P(N);

    REP(i,N) cin >> P[i];

    int ans = 0;

    FOR(i,1,N-1){
        if((P[i+1]-P[i]) * (P[i]-P[i-1]) > 0) ans++;
    }

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

Measured memory_bytes: 3596
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <vector>
#include <stack>

//AOJ0071
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)

using namespace std;
struct stk {
	int y, x;
	stk(int y, int x) : y(y), x(x) { }
};

string bd[10];

void baku(int y, int x){

int ddx[]={-3,-2,-1,1,2,3, 0, 0, 0,0,0,0,0};
int ddy[]={ 0, 0, 0,0,0,0,-3,-2,-1,1,2,3,0};

	stack<stk> qtk;
	qtk.push(stk(y,x));
	while(!qtk.empty()){
		stk cr = qtk.top();
		qtk.pop();
		int yy=cr.y, xx=cr.x;
		if(bd[yy][xx] == '0') continue;
//		printf("\n(%d,%d)",yy,xx);
		bd[yy][xx]='0';
		rep(i,13){
			int dx=xx+ddx[i], dy=yy+ddy[i];
			if( dx >= 8 || dx < 0) continue;
			if( dy >= 8 || dy < 0) continue;
			if(bd[dy][dx] == '1'){
				qtk.push(stk(dy,dx));
//				printf("%d-%d, ",i,qtk.size());
			}
		}
	}

}

int main(void){
string ws,ww;
int n,x,y,cnt=0;
	cin >> n;
	rep(cnt,n){
//		getline(cin,ww);
//		if(ww != "") break;
//		cin.ignore();
		
		rep(i,8) cin >> bd[i];
		cin >> x >> y;

		x--; y--;
		baku(y,x);
		printf("Data %d:\n",cnt+1);
		rep(i,8) cout << bd[i] << endl;
	}
	return 0;
	
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

int m;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> m;
    cout << 48-m;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    
    val red = mutableListOf<Pair<Int, Int>>()
    val blue = mutableListOf<Pair<Int, Int>>()
    
    for (i in 1..N) {
        val (a, b) = readInputLine().split(" ").map {it.toInt()}
        red.add(Pair(a, b))
    }
    for (i in 1..N) {
        val (c, d) = readInputLine().split(" ").map {it.toInt()}
        blue.add(Pair(c, d))
    }
    
    red.sortByDescending { it.second }
    blue.sortBy { it.first }

    val used = mutableSetOf<Pair<Int, Int>>()

    for (bElem in blue) {
        for (rElem in red) {
            if (used.contains(rElem)) {
                continue
            }
            if (rElem.first < bElem.first && rElem.second < bElem.second) {
                used.add(rElem)
                break
            }
        }
    }
    
    println(used.size)
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 37928
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

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

	int n;
	cin >> n;

	string hats;
	cin >> hats;

	int r = 0;
	for (int i = 0; i < (int) hats.size(); ++i) {
		r += (hats[i] == 'R');
	}

	(r > n - r) ? cout << "Yes\n" : cout << "No\n";

	return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD = 1e9+7;
const int larg = 1e5;

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

typedef pair<pair<string, int>, int> City;
City city[100];

int main() {
	int N, point;
	string s;
	cin >> N;
	rep(i, N){
		cin >> s >> point;
		city[i] = make_pair(make_pair(s, -point), i+1);
	}
	sort(city, city+N);
	rep(i, N) cout << city[i].second << endl;
}

Measured memory_bytes: 256
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main(){
  int i=1,x;
  while (cin>>x && x!=0){
    cout<<"Case "<<i<<": "<<x<<endl;
    i++;


  }
  return 0;

}



Measured memory_bytes: 3132
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
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

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

const int mod = 1e9 + 7;
ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}

int P[200001];
ll kotae = 0;
int N;
int to[400001], ne[400001], he[200001];
int dfs(int v, int prev) {
	int kazu = 1;
	for (int u = he[v]; u; u = ne[u]) {
		if (to[u] != prev) {
			int k = dfs(to[u], v);
			kazu += k;
			kotae += P[k] - 1;
		}
	}
	kotae += P[N - kazu];
	return kazu;
}

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


	N = getint();
	int k = 1;
	rep(i, N - 1) {
		int a = getint(), b = getint();
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	P[0] = 1;
	rep1(i, N) P[i] = P[i - 1] * 2 % mod;

	dfs(1, 0);
	kotae = ((ll(P[N - 1]) * N - kotae) % mod + mod) % mod;
	kotae = kotae * modpow(P[N], mod - 2) % mod;

	printf("%lld", kotae);

	Would you please return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>

using namespace std;

template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
const long long INF = 1LL << 60;
using ll = long long;

 
/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
 
 
signed main() {
  ll n;
    cin>>n;
  ll sum=0;
  ll resum=0;
  vector<ll> A(3*n);
  priority_queue<ll> front;
  priority_queue<ll> back;

  for(int i=0;i<3*n;++i){
    cin>>A[i];
    if(i<n){
      front.push(-A[i]);
      sum+=A[i];
    }

    if(2*n-1<i){
      back.push(A[i]);
      resum+=A[i];
    }
  }

  vector<pair<ll,ll>> ans(n+1);
  ans[0].first=sum;
  ans[n].second=resum;
  
  for(int i=n;i<2*n;i++){
    front.push(-A[i]);
    sum+=A[i];

    ll a=front.top();
    sum+=a;
    front.pop();
    ans[i-n+1].first=sum;
  }

  for(int i=(2*n-1);n<=i;i--){
    back.push(A[i]);
    resum+=A[i];

    ll a=back.top();
    resum-=a;
    back.pop();
    ans[i-n].second=resum;
  }

  ll Ans=-INF;
  for(int i=0;i<n+1;i++){
    ll now=ans[i].first-ans[i].second;
    chmax(Ans,now);
  }
  cout<<Ans<<endl;
}

Measured memory_bytes: 5876
local n,k=io.read("n","n","l")
local s=io.read()
local t={1}
for i=2,#s do
    if s:byte(i-1)~=s:byte(i) then
        table.insert(t,i)
    end
end

local max=0
for i=1,#t do
    local x
    if s:byte(t[i])==48 then
        x=(t[i+2*k] or #s+1)-t[i]
    else
        x=(t[i+2*k+1] or #s+1)-t[i]
    end
    max=math.max(x,max)
end
print(max)

Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){

  vt<ll> a(4);
  rep(i,4) {
    cin >> a[i];
  }

  ll ma = max(a[0]*a[2],a[0]*a[3]);
     ma = max({ma,a[1]*a[2],a[1]*a[3]});

  cout << ma << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string a;
  cin >> a;
  if (a == "A") cout << "T" << endl;
  if (a == "T") cout << "A" << endl;
  if (a == "G") cout << "C" << endl;
  if (a == "C") cout << "G" << endl;
  return 0;
}

Measured memory_bytes: 3052
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
struct Card{
  int x;
  int y;
  int c;
};
signed main(){
  int A,B,m;cin>>A>>B>>m;
  vector<int> a(A);
  rep(i,A)cin>>a[i];
  vector<int> b(B);
  rep(i,B)cin>>b[i];
  vector<Card> card(m);
  rep(i,m)cin>>card[i].x>>card[i].y>>card[i].c;
  int res=inf;
  rep(i,m){
    if(res>a[card[i].x-1]+b[card[i].y-1]-card[i].c){
      res=a[card[i].x-1]+b[card[i].y-1]-card[i].c;
    }
  }
  sort(ALL(b));sort(ALL(a));
  if(res>a[0]+b[0])res=a[0]+b[0];
  cout<<res<<endl;
  string s;

  return 0;
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
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; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n, d;
    cin >> n >> d;
    cout << (n-1)/(d*2+1)+1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int x, y, z, a, b, c, t, t2, t3;
    scanf("%d %d %d", &a, &b, &c);
    t=a;
    t2=b;
    t3=c;
    a=b;
    b=t;
    c=a;
    a=t3;
    printf("%d %d %d\n", a, b, c);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, n) cin >> b[i];
    rep(i, 0, n) cin >> c[i];
    int ans = 0;
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    rep(i, 0, n){
        int ia = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        int ic = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        ans += ia * (n - ic);
    }
    cout << ans << endl;
}


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

int n,poz[100010],a,b,x;
long long sol=0,mod=1e9+7,nesto,nesto2,prvi,drugi;

long long pow(int m,int e)
{
	if(e==0) return 1;
	nesto2=pow(m,e/2);
	nesto2=(nesto2*nesto2)%mod;
	if(e%2) return (m*nesto2)%mod;
	else return nesto2;
}
/*
long long f(int k,int l)
{
	if(l<k) return 0;
	nesto=1;
	for(int i=l;i>=l-k+1;i--) nesto=(nesto*i)%mod;
	for(int i=1;i<=k;i++) nesto=(nesto*pow(i,mod-2))%mod;
	return nesto;
}*/

int main()
{
	cin>>n;
	for(int i=1;i<=n+1;i++)
	{
		cin>>x;
		if(poz[x]>0)
		{
			a=poz[x];
			b=i;
		}
		else
			poz[x]=i;
	}
	for(int k=1;k<=n+1;k++)
	{
		if(k==1)
		{
			prvi=n+1;
			drugi=1;
		}
		else
		{
			prvi=(((prvi*pow(k,mod-2))%mod)*(n+2-k))%mod;
			if(n+a-b<k-1) drugi=0; else drugi=(((drugi*pow(k-1,mod-2))%mod)*(n+a-b-k+2))%mod;
		}
		//cout<<prvi<<","<<drugi<<"\n";
		sol=((prvi-drugi)%mod+mod)%mod;		
		cout<<sol<<"\n";
	}
}

Measured memory_bytes: 1536
import java.io.*;

public class Main{
        public static void main(String[] args){
                BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
                String str;
                int checkn = (int)' ';
                String[] s = new String[2];
                int[] a = new int[2];

                try{
                        str = r.readLine();
                        s[0] = str.substring(0,str.indexOf(checkn));
                        s[1] = str.substring(str.indexOf(checkn)+1,str.length());
                }catch(IOException e){
                        System.out.println(e);
                }

                for(int i = 0;i < 2;i++){
                        a[i] = Integer.parseInt(s[i]);
                        if(a[i] == 1){
                                a[i] = 14;
                        }
                }

                if(a[0] > a[1]){
                        System.out.println("Alice");
                }else if(a[0] == a[1]){
                        System.out.println("Draw");
                }else{
                        System.out.println("Bob");
                }
        }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll calc(ll A, ll B, ll x)
{
  return (A * x) / B - A * (x / B);
}

int main()
{
  ll A, B, N;
  cin >>  A >> B >> N;
  ll ans = -100;
  ans = max(ans, calc(A, B, N));
  if (N >= B) {
    ans = max(ans, calc(A, B, B * (N / B) - 1));
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) for (int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
	rep(i, v.size()) { os << v[i] << (i == v.size() - 1 ? "" : " "); }
	return os;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
	for (T& x : v) { is >> x; }
	return is;
}

template <class T>
class CumulativeSum2D {
  public:
	vector<vector<T>> s;
	int h, w;
	CumulativeSum2D(const vector<vector<T>>& a) {
		h = a.size();
		w = a[0].size();
		s = vector<vector<T>>(h + 1, vector<T>(w + 1, 0));
		rep(i, h) rep(j, w) s[i + 1][j + 1] = a[i][j];
		rep(i, h + 1) rep(j, w) s[i][j + 1] += s[i][j];
		rep(i, h) rep(j, w + 1) s[i + 1][j] += s[i][j];
	}

	int sum(int i, int j, int h, int w) {
		return s[i + h][j + w] - s[i][j + w] + s[i][j] - s[i + h][j];
	}

	int maximumSubMatrix() {
		int ret = -1e9;
		rep(i, h + 1) rep(j, w + 1) range(k, 1, h - i + 1)
			range(l, 1, w - j + 1) {
			ret = max(ret, sum(i, j, k, l));
		}
		return ret;
	}
};

signed main() {
	int n, k;
	cin >> n >> k;

	int w = k * 2;
	vector<vector<int>> m(w, vector<int>(w, 0));
	rep(i, n) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		m[y % w][(x + (c == 'W') * k) % w]++;
	}

	// rep(i, 2 * k) {
	//	rep(j, 2 * k) { cout << m[i][j] << ' '; }
	//	cout << endl;
	//}

	CumulativeSum2D<int> csum(m);
	int ans = 0;
	rep(i, k) {
		rep(j, k) {
			int tmp = csum.sum(0, 0, i, j) + csum.sum(i, j, k, k) +
					  csum.sum(i + k, 0, k - i, j) +
					  csum.sum(0, j + k, i, k - j) +
					  csum.sum(i + k, j + k, k - i, k - j);
			ans = max({ans, tmp, n - tmp});
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 62976
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
  	int ANS = 0;
  	int[] A = new int[N];
    int[] B = new int[N];
    int[] C = new int[N-1];
  	for(int i=0;i<N;i++){
      A[i] = sc.nextInt();
    }
  	for(int j=0;j<N;j++){
      B[j] = sc.nextInt();
    }
  	for(int k=0;k<N-1;k++){
      C[k] = sc.nextInt();
    }
  	
  	for(int m=0;m<N;m++){
     	ANS += B[A[m]-1]; 
      	if(m>0){
	      	if(A[m]==A[m-1]+1){
              ANS += C[A[m]-2];
            }
        }
    }
  	
  	System.out.println(ANS);

	}
}

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

int main()
{
	int n,ans=0;
	cin >> n;
	int a[n], b[n], c[n-1];
	for (int i = 0; i < n; ++i) cin >> a[i];
	for (int i = 0; i < n; ++i) cin >> b[i];
	for (int i = 0; i < n-1; ++i) cin >> c[i];
	
	for (int i = 0; i < n; ++i)
	{
		ans += b[a[i]-1];
		if (a[i]+1 == a[i+1] && a[i+1] != 0)
		{
			ans += c[a[i]-1];
		}
	}
	cout << ans << endl;
	
	return 0;
}

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





#define rrep(i,a,b) for(int i=a;i>=b;i--)
int N, K, A[5050];
//-----------------------------------------------------------------------------------
int L[5010][5010], R[5010][5010];
void pre() {
	L[0][0] = 1;
	rep(i, 0, N) rep(j, 0, K) if (L[i][j]) {
		L[i + 1][j] = 1;
		if (j + A[i + 1] < K) L[i + 1][j + A[i + 1]] = 1;
	}

	R[N + 1][0] = 1;
	rrep(i, N, 1) rep(j, 0, K) if (R[i + 1][j]) {
		R[i][j] = 1;
		if (j + A[i] < K) R[i][j + A[i]] = 1;
	}

	// For optimized solution
	rep(i, 0, N + 2) {
		rep(j, 1, K) R[i][j] += R[i][j - 1];
	}
}
//-----------------------------------------------------------------------------------
int main() {
	cin >> N >> K;
	rep(i, 1, N + 1) scanf("%d", &A[i]);

	pre();

	int ans = 0;
	rep(i, 1, N + 1) {
		if (K <= A[i]) continue;

		bool ok = true;
		
		/* // Naive
		rep(j, 0, K) rep(k, 0, K) if (L[i - 1][j] && R[i + 1][k]) {
			if (K <= j + k + A[i] && j + k < K) ok = false;
		} */

		// Optimized
		rep(j, 0, K) if (L[i - 1][j]) {
			int lo = max(K - j - A[i], 0);
			int hi = min(K - 1, K - j - 1);

			int sm = R[i + 1][hi];
			if (0 < lo) sm -= R[i + 1][lo - 1];
			if (sm != 0) ok = false;
		}
		
		if (ok) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 196224
var x = require('fs').readFileSync('/dev/stdin', 'utf8');

var input = x.split("\n");

for (var k = 0 ; k < input.length; k++) {

    var arr = input[k].split(" ").map(Number);
    var H = arr[0];
    var W = arr[1];
 
    if(H === 0 && W === 0) break;
    var result = "";
    for( var i = 0; i < H; i++){
        for( var j = 0; j < W; j++) {
            if (i === 0 || i === H-1 || j === 0 || j === W-1){
                result += "#";
            }
            else {
                result += ".";
            }
            //result = "\n";
        }
        result += "\n";   
    }
        console.log(result);

}




Measured memory_bytes: 17412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
    int m;
    cin >> m;
    cout << 48-m << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
double PI = acos(-1);

void solve()
{	
	int n, m; cin >> n >> m;
	int ans = max(0, n*(n-1)/2)+max(0, m*(m-1)/2);
	cout << ans << endl;
	return;
}

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


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

int main() {
  int N,i=1,sum=0;
  int l,r;
  cin >> N;
  for (i=0;i<N;i++){
    cin >> l >> r;
    sum += r - l + 1;
  }
  
  cout << sum << endl;
}


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

using namespace std;
using ll = long long;

#ifdef LOCAL
  #include "../debug.h"
  #define _GLIBCXX_DEBUG
#else
  #define debug(...) 42
  #define cerr if(0) cout
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int n , m;
  cin >> n >> m;
  vector<ll> ar(n);
  vector<ll> res;
  for(int i = 0; i < n; ++i) {
    cin >> ar[i];
  }
  vector<pair<ll, ll>> w(m);
  for(int i = 0; i < m; ++i) {
    cin >> w[i].second >> w[i].first;
  }
  sort(ar.begin(), ar.end());
  reverse(ar.begin(), ar.end());
  sort(w.begin(), w.end());
  debug(w);
  reverse(w.begin(), w.end());
  debug(w);
  for(int i = 0; i < m; ++i) {
    ll x = w[i].first, t = w[i].second;
    // cerr << x << ' ' << t << ' ' << ar.back() << '\n';
    if(ar.empty() || ar.back() > x) {
      break;
    }
    while(!ar.empty() && ar.back() < x && t) {
      res.push_back(x);
      ar.pop_back();
      t--;
    }
  }
  cout << accumulate(res.begin(), res.end(), 0LL) + accumulate(ar.begin(), ar.end(), 0LL) << '\n';
  return 0;
}


Measured memory_bytes: 3832
#include<stdio.h>
main(){
  long long int m,n,i,j,temp,x1[200],y1[200],x2[1000],y2[1000],count;
  long long int difx,dify;

  while(1){
    
    scanf("%lld",&m);
    
    if(!m) break;

    for(i = 0; i < m; i++){
      scanf("%lld %lld",&x1[i],&y1[i]);
    }
    
    for(i = 0; i < m-1; i++){
      for(j = m-1; j > i; j--){
	if(x1[j] < x1[j-1] || (x1[j] == x1[j-1] && y1[j] < y1[j-1])){
	  temp = x1[j];
	  x1[j] = x1[j-1];
	  x1[j-1] = temp;
	  temp = y1[j];
	  y1[j] = y1[j-1];
	  y1[j-1] = temp;
	}
      }
    }
    
    scanf("%lld",&n);
    
    for(i = 0; i < n; i++){
      scanf("%lld %lld",&x2[i],&y2[i]);
    }
    
    
    for(i = 0; i < n-1; i++){
      for(j = n-1; j > i; j--){
	if(x2[j] < x2[j-1] || (x2[j] == x2[j-1] && y2[j] < y2[j-1])){
	  temp = x2[j];
	  x2[j] = x2[j-1];
	  x2[j-1] = temp;
	  temp = y2[j];
	  y2[j] = y2[j-1];
	  y2[j-1] = temp;
	}
      }
    }
    
    
    for(i = 0; i < n-m; i++){
      difx = x2[i]-x1[0];
      dify = y2[i]-y1[0];
      count = 1;
      for(j = i+1; j < n; j++){
	if(x1[count] + difx == x2[j] && y1[count] + dify == y2[j]) count++;
      }
      if(count == m) break;
    }
    
    printf("%lld %lld\n",difx,dify);
  
  }
  
  return 0;
  
}

Measured memory_bytes: 620
N, X = [int(_) for _ in input().split()]


def calc(n, x, cache = {}):
    #print("calc", n, x)
    key = (n, x)
    if key in cache:
        return cache[key]
    if n == 1:
        if x < 2:
            result = 0
        elif x < 5:
            result = x - 1
        else:
            result = 3
    else:
        plen = 2 * 2 ** n - 3
        if x == 1:
            result = 0
        elif x < 2 + plen:
            result = calc(n - 1, x - 1)
        elif x == 2 + plen:
            result = calc(n - 1, x - 1) + 1
        else:
            result = calc(n - 1, plen) + 1 + calc(n - 1, x - 2 - plen)
    #print("calc", n, x, "=", result)
    cache[key] = result
    return result

result = calc(N, X)

print(result)


Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(aa: Vec<usize>) -> usize {
    let mut c = 0;
    let mut cnt = 0;

    for a in aa {
        if a == c {
            cnt += 1;
            c = 0;
        } else {
            c = a;
        }
    }

    cnt
}

fn main() {
    read_line!();
    let aa = parse_vec!(usize);
    println!("{}", solve(aa));
}

#[test]
fn solve_test() {
    assert_eq!(solve(vec![1,1,2,2,2]), 2);
    assert_eq!(solve(vec![1,2,1]), 0);
    assert_eq!(solve(vec![1,1,1,1,1]), 2);
    assert_eq!(solve(vec![1,2,2,3,3,3,4,4,4,4,1,2,3,4]), 4);
}


Measured memory_bytes: 4352
N,M = map(int,input().split())
a_list=[]
pass_1= []
for i in range(M):
    a = list(map(int,input().split()))
    if(a[0]==1):
        pass_1.append(a[1])
    elif(a[1]==N):
        a_list.append(a[0])
    
if list(set(pass_1) & set(a_list)):
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 111500
#include <bits/stdc++.h>
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) (UB(c,x)-LB(c,x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
template<typename T1, typename T2> using P = pair<T1,T2>;
template<typename T> using V = vector<T>;
struct edge { int from, to; int cost; };
bool operator< (const edge &edge1, const edge &edge2) { return edge1.cost < edge2.cost; };
const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const V<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}


signed main()
{
   int N, M; cin >> N >> M;
   V<int> a(M), b(M);
   REP(i, M) {
      cin >> a[i] >> b[i];
      a[i]--; b[i]--;
   }

   V<set<int>> G(N);
   REP(i, M) {
      G[a[i]].insert(b[i]);
      G[b[i]].insert(a[i]);
   }

   REP(i, N) {
      if (EXIST(G[i], 0) && EXIST(G[i], N-1)) {
         cout << "POSSIBLE" << endl;
         return 0;
      }
   }
   cout << "IMPOSSIBLE" << endl;
   return 0;
}


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

struct Problem {

    void Solve() {
        UL N, M; cin >> N >> M;
        vector<UL> dp(N + 1, -1); dp[0] = 0;
        vector<UL> A(M); rep(i, M) cin >> A[i];
        rep(i, N) {
            for (UL a : A)
                if (i + a <= N) dp[i + a] = min(dp[i + a], dp[i] + 1);
        }
        cout << dp[N] << endl;
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    cout << fixed << setprecision(10);
    p->Solve();
    return 0;
}



Measured memory_bytes: 3128
type t = { mutable x : int; mutable y : int }

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let find_set s x =
  let rec doit x =
    if x <> s.(x).x then s.(x).x <- doit (s.(x).x);
    s.(x).x in
  doit x

let unite s x y =
  let (a, b) = (find_set s x, find_set s y) in
  if s.(a).y > s.(b).y then s.(b).x <- a
  else begin
    s.(a).x <- b;
    if s.(a).y = s.(b).y then s.(b).y <- s.(b).y + 1
  end

let same_p s x y = find_set s x = find_set s y

let solve n q =
  let s = Array.init n (fun i -> { x = i; y = 0}) in
  let rec doit i =
    if i < q then begin
      begin match List.map int_of_string (split (read_line ()) ' ') with
      | 0 :: x :: y :: _ -> unite s x y
      | 1 :: x :: y :: _ -> print_endline (if same_p s x y then "1" else "0")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> solve n q
  | _ -> ()

Measured memory_bytes: 4632
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define mp make_pair
#define f first
#define s second
#define mod 1000*1000*1000+7
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    string ss;cin>>ss;
    if(n&1)
    {
        cout<<"No\n";
    }
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(ss[i]!=ss[n/2+i])
            {
                cout<<"No\n";
                return 0;
            }
        }
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    ll N,i;
    cin >> N;
    vector <double> v;
    double a;
    for(i=0;i<N;i++){
      cin >> a;
      v.push_back(a);
    }
    sort(v.begin(),v.end());
    double ans=v[0];
    for(i=1;i<N;i++){
      ans=(ans+v[i])/2.0;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256