akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

//拡張ユークリッドの互除法
//ax+by=gcd(a, b)の特殊解を計算
//返り値はgcd(a, b)
ll extgcd(ll a, ll b, ll& x, ll& y) {
	if (b == 0) {
		x = (a >= 0) ? 1 : -1;
		y = 0;
		return abs(a);
	}
	else {
		ll res = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
		return res;
	}
}


//xとmは互いに素であるとする
//法mにおけるaの逆元とはab%m=1なる唯一のb<m
//逆元（拡張ユークリッド）
//ax+my=1なる(x, y)が求まればax%m=(1-my)%m=1よりb=x
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

//順列
//nPk mod MODを返す
//f[i]はi!（階乗）mod MODを指す
const ll N = 200005;
vector<ll> f(N);

ll P(ll n, ll k) {
	if (n < k) return 0;
	return (f[n] * mod_inverse(f[n - k], MOD)) % MOD;
}


//組合せ
//nCk mod MODを返す
ll C(ll n, ll k) {
	if (n < 0) return 0;
	return (P(n, k) * mod_inverse(f[k], MOD)) % MOD;
}

signed main() {
	ll h, w, a, b;

	cin >> h >> w >> a >> b;

	f[0] = 1;

	FOR(i, 1, N) {
		f[i] = (f[i - 1] * i) % MOD;
	}

	ll nowh = h - a;
	ll noww = b + 1;
	ll ans = 0;

	while (nowh > 0 && noww < w + 1) {
		ans += C(nowh + noww - 2, nowh - 1) * C(h - nowh + w - noww, h - nowh);
		ans %= MOD;
		nowh--;
		noww++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+50;
int gi(){
    char ch=getchar(); int x=0,q=0;
    while(ch<'0'||ch>'9') q=ch=='-'?1:q,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return q?-x:x;
}
int a[N]; ll b[N];
int main(){
    int n=gi();
    for (int i=1; i<=n; ++i) a[i]=gi();
    sort(a+1,a+n+1);
    for (int i=1; i<=n; ++i) b[i]=b[i-1]+a[i];
    int las=0;
    for (int i=1; i<=n; ++i)
	if (b[i-1]*2<a[i])
	    las=i;
    cout<<n-las+1;
    return 0;
}


Measured memory_bytes: 1408
while true
  n = gets.chomp.to_i
  break if n == 0

  ci = gets.chomp.split(" ").map{|s| s.to_i}
  k = 0

  while true
    prev_ci = ci
    cmap = {}
    cmap.default = 0

    prev_ci.each{|i| cmap[i] = cmap[i] + 1}
    ci = prev_ci.map{|i| cmap[i]}

    break if prev_ci == ci

    k += 1
  end

  puts k
  puts ci.join(" ")
end

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


int N, M, s, c;
bool exist = true;
vector<int> s_c(4, -1);  //s_c[i]=(左からi桁目の数)


int main(){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> s >> c;
        if(s_c[s] >= 0 && s_c[s] != c){ exist = false; break; }
        if(s == 1 && c == 0){  //最上位桁が0
            if(N == 1) s_c[s] = 0;
            else { exist = false; break; }
        }
        s_c[s] = c;  //s_c[s] = -1 || s_c[s] == c
    }


    if(exist){
        for(int i = 1; i <= N; i++){
            if(s_c[i] < 0){            //最小となるように決定
                if(i == 1){    //最上位桁が決まっていない
                    if(N == 1) cout << 0;  
                    else cout << 1;
                }
                else cout << 0;        //最上位桁以外は0にすれば最小に
            }
            else cout << s_c[i];       //existかつもう決定している
        }  
        cout << endl;
    }
    
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 3572
#include<algorithm>
#include<cstdio>
#include<cmath>
#define mxn 1000010
#define ldb long double
using namespace std;
const double PI=acos(-1.0);
int n,L,sl,fh,t[mxn];
double d,ansx,ansy;
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
int main()
{
	n=rd();L=rd();
	for(int i=1;i<=n;++i) t[i]=rd();
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j)
		{
			d=1.0*(t[i]+t[j])/L/2;
			ansx+=cos(2*PI*d)*(i-1+n-j)+cos(2*PI*d+PI)*(j-i-1);
			ansy+=sin(2*PI*d)*(i-1+n-j)+sin(2*PI*d+PI)*(j-i-1);
		}
	printf("%.10lf %.10lf\n",ansx*6/n/(n-1)/(n-2),ansy*6/n/(n-1)/(n-2));
	return 0;
}

Measured memory_bytes: 384
H, W, A, B = map(int, input().split())

ans = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(A):
    ans[i][j] = 1

for i in range(B):
  for j in range(W):
    ans[i][j] ^= 1

for i in range(H):
  for j in range(W):
    print(ans[i][j], end = "")
  print()

Measured memory_bytes: 14196
#include <bits/stdc++.h>
using namespace std;
const string NAME = "z";
const int N = 111;
#define ll long long
const ll inf = 1e9 + 7;
ll t, K, dp[N][5];
string L, R;
vector<int> dg;

ll sol(int pos, int num, int dabe)
{
    if (num > K)
        return 0;
    if (pos == -1)
        return num == K;
    if (dabe && dp[pos][num] > -1)
        return dp[pos][num];
    ll cnt = 0;
    for (int i = 0; i <= max(dg[pos], dabe * 9); i++)
        cnt += sol(pos - 1, num + (i > 0), dabe | (i < dg[pos]));
    if (dabe)
        dp[pos][num] = cnt;
    //cout << pos << " " << num << " " << dp[pos][num] << "\n";
    return cnt;
}

ll cal(string u)
{
    dg.clear();
    for (auto x : u)
        dg.insert(dg.begin(), x - 48);
    return sol(dg.size() - 1, 0, 0);
}

int main()
{
    //freopen((NAME + ".inp").c_str(), "r", stdin);
    //freopen((NAME + ".out").c_str(), "w", stdout);
    ios::sync_with_stdio(0);
    memset(dp, -1, sizeof(dp));
    cin >> L >> K;
    cout << cal(L) << "\n";
    return 0;
}

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

int main (){
	int N;cin>>N;
	vector<long long> A(N);
	for(int i=0;i<N;++i){
		cin>>A[i];
	}
	sort(A.begin(),A.end(),greater<int>());
	long long tate=0,yoko=0;
	bool istate=false;
	for(int i=1;i<N;++i){
		if(istate&&A[i]==A[i-1]){
			yoko=A[i];
			break;
		}
		if(A[i]==A[i-1]){
			tate=A[i];
			istate=true;
			i++;
		}
		
	}
	cout<<tate*yoko<<endl;
    return 0;
}

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

int main(){
    int n,p;
    ll ans = 0;
    cin >> n >> p;
    map<int,ll> mp;
    for(int i = 0;i < n;i ++){
        int a;
        cin >> a;
        mp[a%2] ++;
    }
    ll C[101][101];
    C[0][0] = 1;
    for(int a = 1;a < 101;a ++){
        C[a][0] = 1;
        for(int b = 1;b < 101;b ++){
            C[a][b] = C[a-1][b] + C[a-1][b-1];
        }
    }
    if(p){
        for(int i = 1;i <= mp[1];i+=2){
            ans += C[mp[1]][i]*pow(2,mp[0]);
        }
    }else{
        for(int i = 0;i <= mp[1];i+=2){
            ans += C[mp[1]][i]*pow(2,mp[0]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
int i,v;std::string s;
int P() {
  i++;
  if(s[i]=='T')return 1;
  if(s[i]=='F')return 0;
  if(isalpha(s[i]))return v>>(s[i]-'a')&1;
  if(s[i]=='-')return !P();
  int l=P();
  i++;int o=s[i];if(o=='-')i++;
  int r=P();i++;
  if(o=='*')return l&r;
  if(o=='+')return l|r;
  if(o=='-')return l<=r;
}
int main() {
  while(std::cin>>s){
    if(s=="#")break;
    int k=1;
    for(v=0;v<(1<<11);v++) {
      i=-1;int l=P();
      i++;
      if(l!=P()){k=0;break;}
    }
    std::cout<<(k?"YES\n":"NO\n");
  }
  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vvi = vector<vector<int>> ;

struct unionfind{
    vector<int> r;

    unionfind(int n){
        r = vector<int>(n,-1); //r.at(i) iの根
    }

    int root(int x){
        if(r.at(x) < 0) return x;
        else return r.at(x) = root(r.at(x)); //xの根を返す
    }
    bool unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return false; //xとyの根が同じとき何もしない
        r.at(x) = ry;        //xの根にyの根を追加
        return true;
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<set<int>> r(n);
    for(int ix=0;ix<m;ix++){
        int a,b; cin >> a >> b;
        a--; b--;
        r.at(a).insert(b);
        r.at(b).insert(a);
    }
    bool can = false;
    for(int ix=0;ix<n;ix++){
        if(r.at(ix).count(0) == true && r.at(n-1).count(ix) == true) can = true;
    }
    cout << (can == true ? "POSSIBLE" : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 31480
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long int li;


int main(void){
    ll ans=0;
    int n;
    cin >> n;
    int h[n+1];
    for(int i=1;i<=n;i++)cin >> h[i];
    int x=1000;
  int xpre=0;
    for(int q=1;q<=10000;q++){
        int now=1;
        for(int i=1;i<=n;i++){
            if(i==2&&h[1]==0)xpre=0; else xpre=x;
            x=min(x,h[i]);
            if(h[i]==0){
              if(i==1){now=2;x=1000;continue;}
              for(int j=now;j<=i-1;j++){h[j]=h[j]-xpre;}
              if(xpre!=1000)ans+=xpre;
			  x=1000;
              xpre=0;
              now=i+1;
            }else   if(i==n){
              for(int j=now;j<=i;j++){h[j]=h[j]-x;}
              if(x!=1000)ans+=x;
              x=1000;
              xpre=0;
              now=i+1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <iterator>

using namespace std;

long long int const LL_MAX = 10000000000000000; // 10^16

long long int DP[3][100001];

long long int total(int N, string str){
	
	DP[0][0] = 0;
	DP[1][0] = 0;
	DP[2][0] = 0;
	
	str = " " + str;
	
	for(int i = 1; i <= N; i++){
		if(str[i] == 'J'){
			DP[0][i] = DP[0][i - 1] + 1;
		}else{
			DP[0][i] = DP[0][i - 1];
		}
	}
	for(int i = 1; i <= N; i++){
		if(str[i] == 'O'){
			DP[1][i] = DP[1][i - 1] + DP[0][i - 1];
		}else{
			DP[1][i] = DP[1][i - 1];
		}
	}
	for(int i = 1; i <= N; i++){
		if(str[i] == 'I'){
			DP[2][i] = DP[2][i - 1] + DP[1][i - 1];
		}else{
			DP[2][i] = DP[2][i - 1];
		}
	}
	return DP[2][N];
}

int main(){
	
	string str;
	int N;
	
	cin >> N;
	cin >> str;
	
	string str1, str3;
	
	str1 = "J" + str;
	str3 = str + "I";
	
	long long int I_sum = 0;
	
	for(int i = 0; i < N; i++){
		if(str[i] == 'I'){
			I_sum++;
		}
	}
	
	long long int J_count = 0;
	long long int O_max = 0;
	
	for(int i = 0; i < N; i++){
		if(str[i] == 'J'){
			J_count++;
		}else if(str[i] == 'I'){
			I_sum--;
		}
		if(J_count * I_sum > O_max){
			O_max = J_count * I_sum;
		}
	}
	
	long long int ans = max(max(total(N + 1, str1), total(N + 1, str3)), total(N, str) + O_max);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 6024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1e5;
int main(){
  int N; scanf("%d", &N);
  vector<vector<int>> to(N,vector<int>(N,0));
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      char c; cin >> c; int d = c-'0'; 
      if( d == 0 ){ d = INF;} 
      if( i == j ){ d = 0;}
      to[i][j] = d;}}
  
  vector<int> color(N,0); //0が未到達、1が白、２が黒
  
  queue<int> Q; Q.push(0); color[0] = 1;
  bool flag = true;
  while(!Q.empty()){
    int p = Q.front(); Q.pop();
    for(int i = 0; i < N; i++){ 
      if( to[p][i] == 1 ){ //隣接しているところに進む
        if( color[i] == 0){ 
          if(color[p] == 1){ color[i] = 2;}
          else{ color[i] = 1;}
          
          Q.push(i);
        }
        else{
          if( color[i] == color[p]){ //二部じゃない
            flag = false; break;}
        }
      }
    }
      if(!flag){ break;}
  }
    
  if(!flag){ cout << -1 << endl; return 0;}
  
  for(int k = 0; k < N; k++){
    for(int i = 0; i < N; i++){
      for(int j = 0; j < N; j++){
        to[i][j] = min(to[i][j], to[i][k]+to[k][j]);
      }
    }
  }
  
  int ans = 0;
  
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      ans = max(ans, to[i][j]);
    }
  }
  
  printf("%d\n", ans+1); return 0;
}
  
  

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define INF ( 1 << 28 )
using namespace std;
int N,x,y,b,p;
int solve(int n,int p){
  if(n > 6 || p > 6) return INF;
  if(n > 4 && p > 1 ) return (x*n + y*p) * 0.8;
  return min( x*n + y*p, min(solve(n+1,p),solve(n,p+1)));
}
int main(){
  cin >> N;
  while(N--){
    cin >> x >> y >> b >> p;
    cout << solve(b,p) << endl;
  }
}

Measured memory_bytes: 1164
import sys

stdin = sys.stdin

na = lambda: list(map(int, ns().split()))
ns = lambda: stdin.readline()

N, Y = na()

ans="-1 -1 -1"
for i in range(N+1):
    if (i * 10000) > Y:
        continue
    for j in range(N+1-i):
        k = N - i - j
        if ((i * 10000) + (j * 5000)) > Y:
            continue
        if (i*10000) + (j*5000) + (k*1000) == Y:
            ans = str(i) + " " + str(j) + " " + str(k)
            break
    else:
        continue
    break

print(ans)


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

int main(){
    ll n, a,b,ab,ans;
    cin >> n >> a >> b;

    ab = a+b;
    ll abw = n/ab, abm = n%ab;

    ans = abw * a;
    if(abm >= a){
        ans += a;
    }else{
        ans += abm;
    }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
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)
int MOD=998244353;
int n,a,b,k;
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
bool judge(int i){
    bool flag=false;
    int buf=k-a*i;
    if(buf>=0){
        //cout<<"K"<<endl;
        if(buf<=n*b){
            //cout<<"KK"<<endl;
            if((k-a*i)%b==0){
                flag=true;
                int num=(k-a*i)/b;
                if(num>n)flag=false;
                //cout<<"KKK"<<endl;
            }
        }
    }
    return flag;
}
int comv(vector<int> const& kaijo,int N,int kk){
    int res=kaijo[N];
    res*=modinv(kaijo[kk],MOD);
    res%=MOD;
    res*=modinv(kaijo[N-kk],MOD);
    res%=MOD;
    return res;
}
int solve(vector<int> const& kaijo,int i){
    int res=0;
    int r,bb;
    r=i;bb=(k-a*i)/b;
    if(bb<0)return 0;
    int buf=comv(kaijo,n,r);
    buf*=comv(kaijo,n,bb);
    buf%=MOD;res=buf;
    //printf("i=%lld, res=%lld\n",i,res);
    //printf("R=%lld, B=%lld\n",r,bb);
    return res;
}
signed main(){
    cin>>n>>a>>b>>k;
    int res=0;
    vector<int> kaijo(n+1,1);
    rep1(i,n){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=MOD;
    }
    rep(i,n+1){
        if(judge(i)){
            res+=solve(kaijo,i);
            res%=MOD;
            //cout<<i<<endl;
        }
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2560
import java.util.*;
public class Main{
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int A=sc.nextInt();
int B=sc.nextInt();
if(A<=5){
System.out.println("0");
}else if(A>=6&&A<=12){
System.out.println(B/2);
}else{
System.out.println(B);
}
}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define int long long
#define fi first
#define sc second
#define pii pair<int,int>
#define vi vector<int>
#define msi map<string,int>
#define si set<int>
#define all(v) v.begin(),v.end()
#define sz(v)  int((v).size())
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define isinarr(i,n) ((i>=0)?((i<n)?1:0):0)
#define fastio  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ppb pop_back
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mp make_pair
#define	endl '\n'

using namespace std;
void solve()
{
	int n;
	cin>>n;
	int a[n];
	map<int,int> m;
	m[0]=0;
	rep(i,0,n)
	{
		cin>>a[i];
		if(i>1)
		{
			m[i]=min(m[i-1]+abs(a[i]-a[i-1]),m[i-2]+abs(a[i]-a[i-2]));
		}
		if(i==1)
		{
			m[i]=abs(a[i]-a[i-1]);
		}
	}
	cout<<m[n-1];
}



signed main()
{
    fastio
    int t=1;
    //cin>>t;
    while(t--)
    	solve();
    return 0;
}

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

int main(){
    int n; cin >> n;
    vector<int> A1(n),A2(n);
    for (int i=0;i<n;i++){cin >> A1[i];}
    for (int i=0;i<n;i++){cin >> A2[i];}
    vector<int> B1(n),B2(n);
    for (int i=0;i<n;i++){
        if(i==0) B1[0] = A1[0];
        else{B1[i] = B1[i-1] + A1[i];}
    }
    for (int i=0;i<n;i++){
        if(i==0) B2[0] = A2[0];
        else{B2[i] = B2[i-1] + A2[i];}
    }
    int res = max(B1[n-1]+A2[n-1],A1[0]+B2[n-1]);
    for(int i=1;i<n-1;i++){
        if(B1[i]-B2[i-1]+B2[n-1]>res){
            res = B1[i]-B2[i-1]+B2[n-1];
        }
    }
    cout << res << endl;
    return 0;

}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        for (int i = 0; i < n; i++)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var k = int.Parse(line[0]);
            var p = int.Parse(line[1]);
            var win = k % p;
            if (win == 0) win = p;
            Console.WriteLine(win);
        }
    }
}

Measured memory_bytes: 9196
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
    int xy[3000][2];
    int n;

    for(int i = 0; ; i++) {
        scanf("%d %d", &xy[i][0], &xy[i][1]);
        if(xy[i][0] == 0 && xy[i][1] == 0) {
            n = i;
            break;
        }
    }

    for(int i = 0; i < n; i++) {
        int x = min(xy[i][0], xy[i][1]);
        int y = max(xy[i][0], xy[i][1]);
        printf("%d %d\n", x, y);
    }

    return 0;
}


Measured memory_bytes: 2604
#include<stdio.h>
#define N 1200

int main(void){
	char ny,alp=0;
	int i=0;
	int su[26]={0};
	
	while(scanf("%c",&ny)!=EOF){
		for(i=0;i<26;i++){
			if((ny==('a'+i))||(ny==('A'+i))){
				su[i]=su[i]+1;
			}
		}
	}
	for(i=0;i<26;i++){
		alp=0;
		alp='a'+i;
		printf("%c : %d\n",alp,su[i]);
	}
	return 0;
}


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

#define ROUND_UP(a, b) ((a) + (b)-1)/(b)

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

	int num = ROUND_UP(a+b, 2);

	cout << num << endl;

	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bitset>
using namespace std;
int n;
int a[2005];
bitset<4000005>M(0);
int main()
{
	scanf("%d",&n);
	M[0]=1;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		M|=M<<a[i];
	}
	int cnt=0,cnt1=0;
	for(int i=1;i<=4000000;i++)cnt+=M[i];
	for(int i=1;i<=4000000;i++)
	{
		cnt1+=M[i];
		if(cnt1==(cnt+1)/2)
		{
			printf("%d",i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1664
using System;
using System.Linq;
using System.Collections.Generic;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var dist = ab[1] - ab[0];

            var list = new List<int>();
            list.Add(1);
            for (int i = 2; i < 1000; i++) list.Add(i + list.Last());

            var ans = list[dist-1] - ab[1];
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i,n) for (int i=1;i<=(n);i++)
using namespace std;
typedef long long ll;
int gcd(int x, int y,int z) {
  int temp=0;
  temp = __gcd(x, y);
  return __gcd(temp,z);
}
int main(){
  int n;
  int ans=0;
  cin >> n;
  rep(i,n){
    rep(j,n){
      rep(k,n){
        ans+= gcd(i,j,k);
      }
    }
  }
  cout << ans <<endl;
  return 0;
}

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

int main(){
  	int X;
  	cin >> X;
  	int count = 0;
  	for (int i = 1; i <= 360; i++){
      	if (X * i % 360 == 0) {
          	count = i;
          	break;
        }
    }
  
  	cout << count << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
int main()
{
    double d,x,y;
    ll n;
    sl(n);
    ll sum=0;
    scanf("%lf",&d);
    for(ll i=0;i<n;i++)
    {
        scanf("%lf %lf",&x,&y);
        //cout<<x<<" "<<y<<endl;
        double s=x*x+y*y;
        s=sqrt(s);
        if(s<=d)
            sum++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3852
/***********************************************************************************
*           Falling down is an accident, Staying down is a choice.                 *
***********************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ios std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) //Fast IO
#define _USE_MATH_DEFINES
#define PI acos(-1.0) //3.14159265358
#define EPS 1e-9 //epsilon, 10^-9, checking for equality 
#define pb push_back
#define fi first
#define se second
#define isort(x) sort(x.begin(),x.end())
#define dsort(x) sort(x.rbegin(),x.rend())
const int inf=1e9+7; //10^9 +7
const int modc=998244353;
typedef long long int ll;
void solve();int main(){ios;solve();return 0;}
/***********************************************************************************/
void solve()
{
	int n;cin>>n;
	vector<int> a(n),b(n);
	ll ans=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<n;i++)
	{
		cin>>b[i];
		ans+=b[i];
	}
	map<int,int> c;
	for(int i=0;i<n-1;i++)
	{
		int temp;cin>>temp;
		c[i]=temp;
	}
	for(int i=1;i<n;i++)
	{
		if(a[i]==a[i-1]+1)
		{
			ans+=c[a[i-1]-1];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

//----------------------------------------------------------------
signed main(){
   
    int n;
	cin >> n;
	vll l(n);
	rep(i,n)cin >> l[i];
	l.pb(-1);
	l.pb(INF);
	SORT(l);

	int ans = 0;

	for(int i = 1;i <= n-2;i++){
		for(int j = i+1;j <= n-1;j++){
			int mini = abs(l[i]-l[j]);
			int maxi = l[i]+l[j];
			int L,R;
			ll ok = n+1;  //解が存在する値
			ll ng = 0;  //解が存在しない値 

			while(abs(ok-ng)>1){
				ll mid = (ok+ng)/2;
				if(mini < l[mid]){
					ok = mid;
				}else{
					ng = mid;
				}
			}
			L = ok;

			ok = 0;  //解が存在する値
			ng = n+1;  //解が存在しない値 

			while(abs(ok-ng)>1){
				ll mid = (ok+ng)/2;
				if(l[mid] < maxi){
					ok = mid;
				}else{
					ng = mid;
				}
			}
			R = ok;
			// cerr << i << " " << j << " " <<  L << " " << R << endl;
			L = max(L,j+1);
			if(R == n+1 || L == 0 || L > R)continue;
			else ans += R-L+1;
		}
	}
	cout << ans << endl;
	return 0;
}

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

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://nikkei2019-2-qual.contest.atcoder.jp/tasks/nikkei2019_2_qual_b
// rm -r -f test;oj dl https://abc143.contest.atcoder.jp/tasks/abc143_a

Measured memory_bytes: 256
_ = gets
a = gets.split.map(&:to_i)

def selection_sort(a)
  cnt = 0
  0.upto(a.size - 1) do | i |
    min_j = i
    i.upto(a.size - 1) do | j |
      if a[j] < a[min_j]
        min_j = j
      end
    end
    if min_j != i
      cnt += 1
      a[min_j], a[i] = a[i], a[min_j]
    end
  end
  return a, cnt
end

a, cnt = selection_sort(a)
puts a.join(' ')
puts cnt



Measured memory_bytes: 6872
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cstring>
#include<cstdlib>
#include <ctime>
#include <math.h>
using namespace std;
int main(void)
{
	int n,m,i,s[100001],f[100001],ans,x,y;
	cin >> n >> m;
	for(i=1;i<=n;i++){
		s[i]=1;
		f[i]=0;
	}
	f[1]=1;
	for(i=1;i<=m;i++){
		cin >> x >> y;
		if(f[x]==1) f[y]=1;
		if(s[x]-1==0) f[x]=0;
		s[x]--;
		s[y]++;
	}
	ans=0;
	for(i=1;i<=n;i++){
		if(f[i]==1) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
    int H,N;
    scanf("%d %d",&H,&N);
    int a[N],sum=0;
    for(int i=0;i<N;i++){
        scanf("%d",&a[i]);
    }
    for(int i=0;i<N;i++){
        sum = sum + a[i];
    }
    if(sum>=H){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string.h>
using namespace std;
string x,y;
int main()
{ 
  cin >> x;
  cin >> y; 
  if(x[0]==y[2] && x[1]==y[1] && x[2]==y[0]){
    printf("YES");
  }else{printf("NO");
       }
}

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

if N <= 11:
	answer = 11
elif N <= 22:
	answer = 22
elif N <= 33:
	answer = 33
elif N <= 44:
	answer = 44
elif N <= 55:
	answer = 55
elif N <= 66:
	answer = 66
elif N <= 77:
	answer = 77
elif N <= 88:
	answer = 88
elif N <= 99:
	answer = 99
elif N <= 111:
	answer = 111
elif N <= 222:
	answer = 222
elif N <= 333:
	answer = 333
elif N <= 444:
	answer = 444
elif N <= 555:
	answer = 555
elif N <= 666:
	answer = 666
elif N <= 777:
	answer = 777
elif N <= 888:
	answer = 888
elif N <= 999:
	answer = 999

print(answer)











Measured memory_bytes: 3064
import math
a,b,C=map(int,input().split())
C_rad=math.pi*C/180
S=(1/2)*a*b*math.sin(C_rad)
L=a+b+math.sqrt(a**2+b**2-2*a*b*math.cos(C_rad))
h=2*S/a
print("{0:.8f}".format(S))
print("{0:.8f}".format(L))
print("{0:.8f}".format(h))

Measured memory_bytes: 7840
#include<iostream>
#include<unordered_map>
#include<vector>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  unordered_map <string,int> m;
  vector<string> v(n);
  int i=0;
  bool f=true;
  while(n--){
    string s;
    cin>>s;
    if(m.count(s)==1){
      cout<<"No"<<endl;
      f=false;
      break;
    }
    m[s]=1;
    v[i]=s;
    if(i==0){i++;
      continue;
      
    }
   else{ int x=v[i-1].size();
    string p=v[i-1];
    if(p[x-1]!=s[0]){
      cout<<"No"<<endl;
      f=false;
      break;
    }
    i++;}
  }
  if(f){
    cout<<"Yes"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
int gcd(int x,int y){
	return y?gcd(y,x%y):x;
}
const int N=50005*6;
int n,m,q,mod,g,z;
struct Edge{
	int a,b,c;
}e[N];
int fa[N];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
int Hash(int x,int p,int q){
	return (x-1)*6+p*3+q;
}
void Merge(int x,int y){
	fa[getf(y)]=getf(x);
}
int check(int x,int y){
	return getf(x)==getf(y);
}
int pw2[2][1000005];
void Solve(int s,int t,int r){
	swap(s,t);
	r=(r+z)%mod;
	For(p,0,1)
		For(q,0,2)
			if (check(Hash(s,0,0),Hash(t,p,q))&&pw2[p][(r+(3-q)*g)%mod])
				return (void)puts("YES");
	puts("NO");
}
int main(){
	n=read(),m=read(),q=read(),mod=read();
	For(i,1,m)
		e[i].a=read(),e[i].b=read(),e[i].c=read();
	g=0;
	For(i,2,m)
		g=gcd(g,abs(e[i].c-e[1].c));
	if (!g)
		g=mod;
	z=e[1].c%g;
//	outval(g);outval(z);
	mod=gcd(mod,g*3);
	For(i,0,n*6-1)
		fa[i]=i;
	For(i,1,m){
		int a=e[i].a,b=e[i].b,c=(e[i].c-z)/g%3;
		For(p,0,1)
			For(q,0,2){
				Merge(Hash(a,p,q),Hash(b,p^1,(q*2+c)%3));
				Merge(Hash(b,p,q),Hash(a,p^1,(q*2+c)%3));
			}
	}
	clr(pw2);
	int tmp=z;
	For(i,0,mod*2)
		pw2[i&1][tmp]|=1,tmp=tmp*2%mod;
	while (q--){
		int s=read(),t=read(),r=read();
		Solve(s,t,r);
	}
	return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define double long double
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define debug(x) cerr<<#x<<": "<<x<<endl;
#define all(a) a.begin(),a.end()
#define sort(a) sort(all(a))
#define rsort(a) sort(all(a),greater<>())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
template<class T> inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
typedef long long ll;
typedef pair<int,int> P;
const long long MOD=1000000007;
clock_t time_ini = clock();
double time_diff(){
  ll time_tmp = clock();
  const double time = static_cast<double>(time_tmp - time_ini) / CLOCKS_PER_SEC * 1000.0;
  return time;
}
#define saiaku if(time_diff() > 1990)
vector <ll> dp;


void solve(long long N, long long K, std::string S){
  ll cnt=0;
  for (ll i = 0; i < N-1; i++)
  {
    cnt += S[i]==S[i+1];
  }
  cout << min(cnt+2*K, N-1) << "\n";
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(N, K, S);
    return 0;
}


Measured memory_bytes: 512
#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>
#include <bitset>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

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

int main() {

	lint N, K;
	cin >> N >> K;

	vector<lint> A(N), B(N);
	for (int i = 0; i < N; i++) cin >> A[i] >> B[i];

	vector<lint> Kr{ K };
	int now = 0;
	for (int i = 30; i >= 0; i--) {
		if (K >> i & 1) {
			Kr.emplace_back(now + (1 << i) - 1);
			bitset<32> tmp(Kr.back());
			DMP(tmp);
			now += 1 << i;
		}
	}

	lint ans = 0;
	for (const auto& k : Kr) {
		lint sum = 0;
		for (int i = 0; i < N; i++) {
			if ((A[i] | k) == k) sum += B[i];
		}
		chmax(ans, sum);
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4752
import java.util.*;
import java.util.regex.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    scanner.nextLine();
    for (int ii = 0; ii < n; ii++) {
      String str = scanner.nextLine();
      Pattern pa = Pattern.compile("^>'(=+)#\\1~$");
      Pattern pb = Pattern.compile("^>\\^(?:Q=)+~~$");
      Matcher ma = pa.matcher(str);
      Matcher mb = pb.matcher(str);
      if (ma.find()) {
        System.out.println("A");
      } else if (mb.find()) {
        System.out.println("B");
      } else {
        System.out.println("NA");
      }
    }
  }
}

Measured memory_bytes: 31248
a,b,c,x,y = map(int,input().split())
ans = 10**19
ans = min(ans,a*x+b*y)
ans = min(ans,c*max(x,y)*2)
if x <= y:
    ans = min(ans,c*x*2+(y-x)*b)
else:
    ans = min(ans,c*y*2+(x-y)*a)
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  int N;
  cin >> N;
  int a = N / 200;
  cout << 10 -a << endl;

}

Measured memory_bytes: 3616
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    int tmp = 0;
    for(int i = 0; i< n; i++){
        cin >> a[i];
        tmp ^= a[i];
    }
    vector<int> ans(n);
    for(int i =0; i< n; i++){
        ans[i] = a[i]^tmp;
    }
    for(int i = 0; i<n; i++){
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 4732
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, j, n) for (int i = j; i < (int)(n); i++)
#define brep(i, n) for (int i = n; i > 0; i--)
#define BREP(i, j, n) for(int i = n; i > j; i--)
#define TEST cout << "PASS" << endl
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9 + 1e6 + 1e3 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
    int n;
    cin >> n;
    ll a[200000];
    rep(i, n) cin >> a[i];
    ll ans = 0;
    ll m = a[0];
    for(int i = 1; i < n; i++){
        if(a[i] <= m){
            ans += m - a[i];
        }
        m = max(m, a[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m;i>n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(20) << S << endl
#define Vecpr(K,L1,L2,N) vector<pair<L1,L2>> K(N)
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,R) vector<vector<L>> K(N, vector<L>(M,R))
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
   lli A,B,C,L,R,N,M,K,sum=0,num=0,flag=1;
   string S,T;
   cin >> N >> S >> T;
   rep(i,0,N){
      string SS=S.substr(N-1-i,i+1);
      string TT=T.substr(0,i+1);
      if(SS==TT)sum=i+1;
   }
   Out(2*N-sum);
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define mp(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
	os << "[";
	for (const auto &v : vec) {
		os << v << ",";
	}
	os << "]";
	return os;
}

void Solve(){
	int n,m;
	string s;
	while(true){
		cin >> n >> m >> s;
		if(!n) break;
		
		vector<int> cnt(m);
		
		for(int i=m-3; i>=0; --i){
			if(s[i]=='I'&&s[i+1]=='O'&&s[i+2]=='I') cnt[i]=cnt[i+2]+1;
		}
	
		int ans=0;
		rep(i,0,m){
			if(cnt[i]>=n) ++ans;
		}
	
		cout << ans << endl;
	}
}

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

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    int mn = a[0], ans = 1;
    for(int right = 1; right < n; right++){
        if(a[right] <= mn){
            mn = a[right];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<string>
#include<algorithm>
#include<iostream>
#include<math.h>
using namespace std;
int main(void)
{
    int i,j,k,n,m;
    int x,y;
    scanf("%d%d%d%d",&n,&m,&x,&y);
    if(n<=m)
    {
        if(x<=y)
            printf("%d\n",n+x);
        else
            printf("%d\n",n+y);
    }
    else
    {
        if(x<=y)
            printf("%d\n",m+x);
        else
            printf("%d\n",m+y);
    }
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n = I()
    b = LI()
    a = [inf] * n
    for i in range(n-1):
        a[i+1] = b[i]
        if b[i] < a[i]:
            a[i] = b[i]

    return sum(a)


print(main())



Measured memory_bytes: 5716
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N, M);

    priority_queue<i64> pq;
    rep(i, 0, N) {
        var(i64, x);
        pq.push(x);
    }

    rep(i, 0, M) {
        const i64 x = pq.top();
        pq.pop();
        pq.push(x / 2);
    }

    i64 ans = 0;
    rep(i, 0, N) {
        ans += pq.top();
        pq.pop();
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1400
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class T> inline int Digit_L(T n){
  int res=0;
  while(n){
    res++;
    n /= 10;
  }
  return res;
}
int N;
int main(){
  int N, i, res=0;
  rd(N);
  for(i=(1);i<(N+1);i++){
    res +=Digit_L(i)%2;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190822-2
 
// --- original code ---
// int N;
// {
//   int N, res = 0;
//   rd(N);
//   rep(i,1,N+1) res += Digit(i)%2;
//   wt(res);
// }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
int x[25],maxi=-1;
int ans=0;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		cin>>x[i];
	for(int i=1;i<=n;i++) {
		if(x[i]>=maxi) ans++;
		maxi=max(maxi,x[i]);
	}
	cout<<ans;
	return 0;
}


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

int main() {
	string last_str;
	string current_str;
	int n;
	cin >> n;
	cin >> last_str;
	vector<string> words;
	bool flag = true;
	words.push_back(last_str);
	for (int i = 1; i < n; ++i) {
		cin >> current_str;
		if (current_str[0] != last_str[last_str.length() - 1]) {
			flag = false;
		}
		for (auto val : words) {
			if (val == current_str) {
				flag = false;
			}
		}
		last_str = current_str;
		words.push_back(last_str);
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
std::vector < int > E[2001];
int N, K, q[2001], fa[2001], f[2001][2001], O = 1000000000;
int main()
{
	scanf("%d%d", &N, &K);
	for (int i = 1, u, v; i < N; i++)
	{
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	int H = 0, T = 1;
	q[1] = 1;
	while (H < T)
	{
		int u = q[++H];
		for (int v : E[u])
			if (v != fa[u])
				fa[q[++T] = v] = u;
	}
	for (int i = N; i; i--)
	{
		int u = q[i];
		f[u][0] = 1;
		for (int v : E[u])
			if (v != fa[u])
				f[u][0] += f[v][0];
		for (int j = 0; j <= K; j++)
		{
			int small = std::min(K - j, j), big = j, M = 0;
			for (int v : E[u])
				if (v != fa[u])
				{
					f[u][j + 1] += f[v][small];
					M = std::min(M, f[v][big] - f[v][small]);
				}
			f[u][j + 1] += M;
		}
		for (int j = 1; j <= K + 1; j++)
			f[u][j] = std::min(f[u][j], f[u][j - 1]);
		O = std::min(O, N - f[u][0] + f[u][K + 1]);
	}
	printf("%d\n", O);
	return 0;
}


Measured memory_bytes: 16000
#include<iostream>
#include<cstdio>
using namespace std;
int a[201000];long long ans=0;
int main()
{
	int n;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	if(a[1]!=0)return 0*puts("-1");
	int now=0;
	for(int i=n;i>=2;i--)
	{
		if(a[i]<now)return 0*puts("-1");
		else if(a[i]==now){if(a[i]!=0)now--;}
		else now=a[i]-1,ans+=a[i];
	}
	if(now!=0)return 0*puts("-1");
	printf("%lld",ans);return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool visit(const vector<vector<int>>& g, int v, vector<int>& order, vector<int>& color) {
    color[v] = 1;
    for (int u : g[v]) {
        if (color[u]==2) continue;
        if (color[u]==1) return false;
        if (!visit(g, u, order, color)) return false;
    }
    order.push_back(v); color[v] = 2;
    return true;
}

// トポロジカルソートする
// 返り値が true の時のみ意味を持つ(false の場合は閉路)
bool TopologicalSort(const vector<vector<int>>& g, vector<int>& order) {
    int n = g.size();
    vector<int> color(n);
    for (int u = 0; u < n; u++) if (!color[u] && !visit(g, u, order, color)) return false;
    reverse(order.begin(), order.end());
    return true;
}

int getIndex(const int a, const int b, const int N) {
    const int p1 = min(a, b);
    const int p2 = max(a, b);
    return p1 * N + p2;
}

int main() {
    int N;
    cin >> N;
    vector<vector<int> > G(N*N);
    for (int i = 0; i < N; i++) {
        vector<int> A(N-1);
        for (int j = 0; j < N-1; j++) {
            cin >> A[j]; --A[j];
        }
        for (int j = 0; j < N-2; j++) {
            const int v1 = getIndex(i, A[j], N);
            const int v2 = getIndex(i, A[j+1], N);
            G[v1].push_back(v2);
        }
    }
    vector<int> order;
    if (!TopologicalSort(G, order)) {
        cout << -1 << endl;
        return 0;
    }
    vector<int> dp(N*N);
    for (const int el : order) {
        for (const int child : G[el]) {
            dp[child] = max(dp[child], dp[el] + 1);
        }
    }
    cout << *max_element(dp.begin(), dp.end()) + 1 << endl;
    return 0;
}

Measured memory_bytes: 48376
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)
 
using namespace std;
 
typedef long long ll;


int main(){
    int N;
    vector<int> a;
    set<int> p;
    map<int,int> index;
    cin>>N;
    rp(i,0,N){int A;cin>>A;a.push_back(A);index[A]=i;}

    ll ans=0;
    p.insert(N);
    p.insert(-1);
    for(int i=1;i<N+1;i++){
        //cout<<"ind"<<index[i]<<endl;
        auto l=--p.lower_bound(index[i]),r=p.upper_bound(index[i]);
        //cout<<endl;
        //cout<<*l<<*r<<endl;
        ans+=((ll)(index[i]-*l)*(ll)(*r-index[i]))*ll(i);
        p.insert(index[i]);
        


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


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

int main(){
  int N, M, T = 0;
  cin >> N;
  
  int time[N];
  for(int i = 0; i < N; i++){
    cin >> time[i];
    T += time[i];
  }
  
  int cnt = T;

  cin >> M;
  int juice[M][2];
  
  for(int i = 0; i < M; i++){
    for(int j = 0; j < 2; j++){
      cin >> juice[i][j];
    }
  }
  
  for(int i = 0; i < M; i++){
    T = cnt;
    T = T + juice[i][1] - time[juice[i][0] - 1];
    cout << T << endl;
  }
}    
 
  
  
  

Measured memory_bytes: 256