akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._700problems
{
    class AGC025_C
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            long[][] lrs = new long[n][];
            for(int i = 0; i < n; i++)
            {
                lrs[i] = ReadLongs();
            }
            long[] ls = new long[n];
            long[] rs = new long[n];
            for (int i = 0; i < n; i++)
            {
                ls[i] = lrs[i][0] * 2;
                rs[i] = -lrs[i][1] * 2;
            }
            Array.Sort(ls);
            Array.Reverse(ls);
            Array.Sort(rs);
            Array.Reverse(rs);
            long res = 0;
            long lSum = 0;
            long rSum = 0;
            for(int i = 0; i < n; i++)
            {
                lSum += ls[i];
                res = Max(res, lSum + rSum);
                lSum -= ls[i];
                rSum += rs[i];
                res = Max(res, lSum + rSum);
                lSum += ls[i];
                res = Max(res, lSum + rSum);
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 26436
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

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

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);
vector<ll> num;

ll maskcount(ll mask){
    ll ct=0;
    for(auto v : num){
        if((v&mask)==mask) ct++;
    }
    return ct;
}

int main() {
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N);
    for(int i=0;i<N;i++) cin >> A[i];

    for(int i=0;i<N;i++){
        ll tmp=0;
        for(int j=i;j<N;j++){
            tmp+=A[j];
            num.push_back(tmp);
        }
    }
    // sort(num.begin(),num.end());
    // for(auto e : num) cout << e << endl;

    ll mask=0;
    for(int i=40;i>=0;i--){
        if(maskcount(mask|(1LL<<i))>=K) mask|=(1LL<<i);
    }
    cout << mask << endl;

    return 0;
}

Measured memory_bytes: 6260
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>
#include <time.h>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

using namespace std;
using ll = long long;
typedef std::pair<int,int> pii;
typedef std::vector<int> vi;
typedef std::vector<pii> vii;

#define PI 3.14159265358979323846264338327950L
const int mod = 1000000007;


void solve(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        if (i%2 == 0 && a%2 ==1){
            ans++;
        }
    }
    cout << ans;
}

int main(){
    int T;
    T = 1;
    //cin >> T;
    while(T--){
        solve();
        cout << endl;
    }
}






Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
const ll INF = 1LL<<60;
typedef pair<ll, ll> P;

int main() {
    ll X;
    cin>>N>>X;
    int left = 0;
    rep(i,10) if((X>>i)&1) left = i;
    ++left;
    //cout<<left<<endl;
    mat dp(N + 1, vec(1<<left, 0));
    dp[0][0] = 1;
    rep(t, X + 1){
        rep(i, N){
            rep(x, 1<<left){
                (dp[i + 1][x ^ t] += dp[i][x])%=MOD;
            }
        }
    }
    /*rep(i,N + 1){
        rep(j,1<<left) cout<<dp[i][j]<<' ';
        cout<<endl;
    }*/
    cout<<dp[N][X]<<endl;
}


Measured memory_bytes: 4924
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,a[202020];
map<int,int>mp;
vector<int>v;
signed main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	int ans=0;
	for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++)
	{
		int x=it->second;
		if(x==1)
		{
			continue;
		}
		else
		{
			ans+=x*(x-1)/2;
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<ans-mp[a[i]]+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n, ma, mi, cnt = 0;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v.at(i);
	for (int i = 0; i < n-2; i++) {
		ma = max( { v.at(i), v.at(i+1), v.at(i + 2) });
		mi = min( { v.at(i), v.at(i+1), v.at(i + 2) });
		if (v.at(i+1) != ma && v.at(i+1) != mi)
			cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll n,a,b;
    std::cin >> n>>a>>b;
    std::cout << min(a,b)<<" "<<max(a+b-n,(ll)0) << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  vector<int> a(N), b(N), c(N), dpa(N,0), dpb(N,0), dpc(N,0);
  REP(i,N) cin >> a[i] >> b[i] >> c[i];
  dpa[0] = a[0];
  dpb[0] = b[0];
  dpc[0] = c[0];
  REP2(i,1,N){
    dpa[i] = max(dpb[i-1] + a[i], dpc[i-1] + a[i]);
    dpb[i] = max(dpa[i-1] + b[i], dpc[i-1] + b[i]);
    dpc[i] = max(dpb[i-1] + c[i], dpa[i-1] + c[i]);
  }
  int ans = max({dpa[N-1], dpb[N-1], dpc[N-1]});
  cout << ans;
  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
using namespace std;
int main()
{
    // スペース区切りの文字列の入力
    long a, c;
    char b;
    cin >> a >> b >> c;

    if(b == '+'){
        // 出力
        cout << a + c;
    }else if(b == '-'){
        // 出力
        cout << a - c;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		int menseki,syuu;
		
		menseki = a * b;
		syuu = (a + b) * 2;
		
		System.out.println(menseki + " " + syuu);

	}

}

Measured memory_bytes: 26196
#ABC122B
def main():
    import sys
    S = sys.stdin.readline().rstrip()
    #print(S)
    cnt = 0
    ans = 0
    for s in S:
        if s in ['A', 'G', 'C', 'T']:
            cnt +=1
        else:
            ans = max(ans, cnt)
            cnt=0
    
    ans = max(ans, cnt)
    print(ans)   
            
                    
    

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

const int MAX_V = 1<<18;

template<typename T> struct lazy_segment_tree{
    //二項演算
    T f(T a, T b){return a+b;}
    //単位元
    T unit;
    int n;
    T seg[2*MAX_V], lazy[2*MAX_V];
    //要素数N(0-indexed)のxを単位元とする遅延セグメント木を構築
    lazy_segment_tree(int N, T x){
        unit = x;
        n = 1;
        while(n < N) n *= 2;
        fill(seg, seg+2*n-1, unit);
        fill(lazy, lazy+2*n-1, unit);
    }
    //i番目のノードについて、遅延評価(遅延配列の伝搬)をする
    void eval(int i, int l, int r){
        if(lazy[i] != unit){
            seg[i] = f(seg[i], lazy[i]);
            if(r-l > 1){
                lazy[2*i+1] = f(lazy[2*i+1] ,lazy[i]/2);
                lazy[2*i+2] = f(lazy[2*i+2], lazy[i]/2);
            }
            lazy[i] = unit;
        }
    }
    //add(a, b, x)で[a,b)にxを右から演算する
    void add(int a, int b, T x, int k = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        eval(k, l, r);
        if(a >= r || b <= l) return;
        elif(a <= l && r <= b){
            //演算の内容によって右から何を演算するかは異なる
            lazy[k] = f(lazy[k], (r-l)*x);
            eval(k, l, r);
        }
        else{
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            seg[k] = f(seg[2*k+1],seg[2*k+2]);
        }
    }
    //query(a, b)で[a, b)における演算の結果を取得
    T query(int a, int b, int i = 0, int l = 0, int r = -1){
        if(r < 0) r = n;
        if(a >= r || b <= l) return unit;
        eval(i, l, r);
        if(a <= l && r <= b) return seg[i];
        else{
            T vl = query(a, b, 2*i+1, l, (l+r)/2);
            T vr = query(a, b, 2*i+2, (l+r)/2, r);
            return f(vl, vr);
        }
    }
    //初期化する
    void clear(){
        fill(seg, seg+2*n-1, unit);
        fill(lazy, lazy+2*n-1, unit);
    }
};

//n個の山のgrundy数
ll grundy(ll n){
    if(n == 0) return 0;
    ll res = 1;
    while(n%2 == 0){
        n /= 2;
        res *= 2;
    }
    return res;
}

int main(){
    int N;
    ll L;
    cin >> N >> L;
    string s[N];
    rep(i, N) cin >> s[i];
    sort(s, s+N);
    lazy_segment_tree<int> seg(2e5, 0);
    seg.add(0, s[0].size(), 1);
    rep2(i, 1, N-1){
        //s[i-1]とs[i]の上何桁が一致しているか
        int j = 0;
        while(j < min(s[i-1].size(),s[i].size()) && s[i-1][j] == s[i][j]) j++;
        seg.add(j, s[i].size(), 1);
    }
    ll res = 0;
    rep(i, 2e5){
        if(i > L) continue;
        if(seg.query(i, i+1)&1) res ^= grundy(L-i);
    }
    if(res) cout << "Alice" << endl;
    else cout << "Bob" << endl;
}

Measured memory_bytes: 4736
n, s = map(int, input().split())
a  = list(map(int, input().split()))
MOD = 998244353
 
dp = [[0]*(s+1) for _ in range(n+1)]
dp[0][0] = 1
 
for i in range(n):
    for j in range(s+1):
        dp[i+1][j] = dp[i+1][j] + dp[i][j] * 2
        dp[i+1][j] = dp[i+1][j] % MOD
        if j + a[i] <= s:
            dp[i+1][j+a[i]] = dp[i+1][j+a[i]] + dp[i][j]
            dp[i+1][j+a[i]] = dp[i+1][j+a[i]] % MOD
 
print(dp[n][s])

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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    string s;
    cin >> s;

    string ans = "";
    for (int i = 0; i < s.length(); i++) {
        switch (s[i]) {
            case '0':
            ans += "0"; break;
            case '1':
            ans += "1"; break;
            case 'B':
            if (ans.length() != 0) ans.pop_back();
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/////////////////////////   _LeMur_
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 100005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;

int n , q;
int a[N];

long long suf[N];
long long pref[N];

int main(){
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        pref[i] = ((i == 1) ? 0 : pref[i - 2]) + a[i];
    }
    for(int i=n;i>=1;i--){
        suf[i] = suf[i + 1] + a[i];
    }
    while(q--){
        int x;
        scanf("%d",&x);
        int ina = 1 , inb = n , id = n + 1;
        while(ina <= inb){
            int mid = (ina + inb) / 2;
            if(a[mid] >= x){
                id = mid;
                inb = mid - 1;
            }
            else
                ina = mid + 1;
        }
        ina = id;
        inb = n;
        int pos1 = n + 1 , pos2 = n;
        while(ina <= inb){
            int mid = (ina + inb) / 2;
            int delta = a[mid] - x;
            int s = 1 , e = id - 1 , ind = id;
            while(s <= e){
                int m = (s + e) / 2;
                if(x - a[m] <= delta){
                    ind = m;
                    e = m - 1;
                }
                else
                    s = m + 1;
            }
            int cnt = mid - ind;
            if(cnt >= n - mid){
                pos1 = mid;
                pos2 = ind - 2 + cnt - n + mid;
                inb = mid - 1;
            }
            else
                ina = mid + 1;
        }
        printf("%lld\n",suf[pos1] + ((pos2 == -1) ? 0 : pref[pos2]));
    }
    return 0;
}


Measured memory_bytes: 3712
#include <bits/stdc++.h>
#define pb push_back
using namespace std;

const int MAXN = 3005;

int a[MAXN];
int sts[MAXN];
vector <int> g[MAXN];

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

    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i < n-1; i++)
    {
        int u, v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }


    for (int it = 0; it < n; it++)
    {
        for (int i = 1; i <= n; i++)
        {
            if (sts[i] != 0) continue;
            bool win = false;
            int less_cnt = 0;
            int win_cnt = 0;
            for (int j = 0; j < g[i].size(); j++)
            {
                int k = g[i][j];
                if (a[i] > a[k])
                {
                    less_cnt++;
                    if (sts[k] == -1)
                    {
                        win = true;
                        break;
                    }
                    else if (sts[k] == 1)
                    {
                        win_cnt++;
                    }
                }
            }
          //  cout << i << " " << less_cnt << endl;
            if (win) sts[i] = 1;
            if (win_cnt == less_cnt) sts[i] = -1;
        }
    }

    for (int i = 1; i <= n; i++)
    {
        if (sts[i] == 1) cout << i << " ";
       // cout << sts[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 384
//============================================================================
// Name        : d.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include<string>
#include<vector>
using namespace std;

int main() {
	string s;cin>>s;
	int n=s.size();
	vector<int> ans(n,0);
	int sum=1;
	for(int i=0;i<n-1;i++){
		if(s[i]=='L')continue;
		if(s[i+1]=='R'){
			sum++;
			continue;
		}
		ans[i]+=sum/2+sum%2;
		ans[i+1]+=sum/2;
		sum=1;
	}
//	for(int i=0;i<n;i++){
//		cout<<ans[i]<<' ';
//	}cout<<endl;

	for(int i=n-1;i>=1;i--){
		if(s[i]=='R')continue;
		if(s[i-1]=='L'){
			sum++;
			continue;
		}
		ans[i]+=sum/2+sum%2;
		ans[i-1]+=sum/2;
		sum=1;
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<' ';
	}cout<<endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,num[200005],ans;
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++) cin>>num[i];
	for (i=1;i<=n;)
	{
		for (j=i;j<=n;j++) if (num[j]!=j) break;
		if (j==i)
		{
			i++;
		}
		else
		{
			ans+=(j-i+1)/2;
			i=j;
		}
	}
	cout<<ans;
	return 0;
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int N, M, X;
    std::cin >> N >> M >> X;
    std::vector<int> A(N);
    REP(i, M) {
        int m;
        std::cin >> m;
        A[m - 1] = 1;
    }

    std::vector<int> accsum(N + 1, 0);
    REP(acc_i, N) {
        accsum[acc_i + 1] = accsum[acc_i] + A[acc_i];
    }

    auto ans = min(accsum[X], accsum[N] - accsum[X]);
    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int H, W;
	int i, j;
	scanf("%d %d", &H, &W);

	while( H != 0 && W != 0)
	{
		for(i=0; i<H; i++)
		{
			for(j=0; j<W; j++)
			{
				if( 0 == j || W-1 == j || 0 == i || H-1 == i)
					printf("#");
				else
					printf(".");
			}
			printf("\n");
		}
		printf("\n");

		scanf("%d %d", &H, &W);
	}


}


Measured memory_bytes: 2036
n=int(input())
a=[]
b=[]
c=[]
a=list(map(int,input().split()))


for i in range(n):

    if a[i]%2==0:
        b.append(a[i])

    else:pass


for k in range(len(b)):

    if b[k]%3==0 or b[k]%5==0:

        c.append(b[k])

if len(b)==len(c):

    print("APPROVED")

else:
    print("DENIED")


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

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

const long long MOD = 1000000007;

int main(){
  int n,m,l,r;
  int ml=0,mr=1e5;
  
  cin>>n>>m;
  
  rep(i,m){
    cin>>l>>r;
    ml=max(l,ml);
    mr=min(r,mr);
  }
  int ans=mr-ml+1;
  if(ans<0) ans=0;
  
  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = ll(1e9 + 7);
#define endl '\n'


template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char c) {
  return string(1,c);
}

string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef COMPETITIVE_PROGRAMMING_LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) if(0){}
#endif

 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  // cin >> TT;
  ll n;
  cin >> n;
  vector<ll> A(n), B(n);
  for (int i = 0; i < n; ++i) {
    cin >> A[i] >> B[i];
  }
  nth_element(A.begin(), A.begin() + n/2, A.end());
  nth_element(B.begin(), B.begin() + n/2, B.end());
  if (n&1) {
    cout << B[n/2]-A[n/2]+1 << endl;
    return 0;
  }
  ll b1 = B[n/2];
  ll a1 = A[n/2];
  nth_element(A.begin(), A.begin() + (n-1)/2, A.end());
  nth_element(B.begin(), B.begin() + (n-1)/2, B.end());
  ll b2 = B[(n-1)/2];
  ll a2 = A[(n-1)/2];
  cout << (b1+b2)-(a1+a2)+1 << endl;
}


Measured memory_bytes: 6240
X, K, D = map(int,input().split())
X = abs(X)
if X > K*D:
	print(X - K*D)
	exit()
k = X // D
if (K - k) % 2 == 0:
	print(X - k*D)
else:
	print(abs(X - k*D - D))

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

int main() {
	int n, tm, min = 0;
	cin >> n >> tm;
	vector<int> c(n), t(n);
	for (int i = 0; i < n; i++) {
		cin >> c[i] >> t[i];
		if (t[i] <= tm && c[i] < c[min])
			min = i;
	}
	if (min == 0 && t[0] > tm)
		cout << "TLE" << endl;
	else
		cout << c[min] << endl;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> h(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    int cnt = 0;
    while (true) {
        if (*max_element(h.begin(), h.end()) == 0) break;

        int i = 0;
        while (i < n) {
            if (h[i] == 0) ++i;
            else {
                ++cnt;
                while (i < n && h[i] > 0) {
                    --h[i];
                    ++i;
                }
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>

#define lli long long int
#define ld long double
#define endl "\n"

using namespace std;

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

	#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("D:\\My Folder\\Programming\\[code] Competetive Programming\\input.txt", "r", stdin);
	// for writing the output to output.txt
	freopen("D:\\My Folder\\Programming\\[code] Competetive Programming\\output.txt", "w", stdout);
	#endif

	int N;cin>>N;
	pair<int,int> arr[N];
	
	for (int i = 0; i<N; i++){
		cin>>arr[i].first>>arr[i].second;
	}

	int flag = 0;

	for (int i = 0; i<N; i++){
		if ((arr[i].first == arr[i].second) && (arr[i+1].first == arr[i+1].second) && (arr[i+2].first == arr[i+2].second)){
			flag = 1;
			break;
		}
	}

	if (flag == 0) cout<<"No";
	else cout<<"Yes";

	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n;
int a[100001],b[100000];
long long ans=0;
int main()
{
	cin>>n;
	for(int i=0;i<=n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++)
	cin>>b[i];
	ans+=min(a[0],b[0]);
	b[0]-=a[0];
	b[0]=max(b[0],0);
	for(int i=1;i<n;i++)
	{
		ans+=min(b[i-1],a[i]);
		a[i]-=b[i-1];
		a[i]=max(a[i],0);
		ans+=min(a[i],b[i]);
		b[i]-=a[i];
		b[i]=max(b[i],0);
	}
	ans+=min(a[n],b[n-1]);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
import collections

zzz = 1
nn = int(input())
ans = 0

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

for i in range(1,nn):
    zzz = 1
    cc = collections.Counter(prime_factorize(i))
    hoge = cc.values()
    for aaa in hoge:
        zzz *= aaa + 1
    ans += zzz
   
print(ans)

Measured memory_bytes: 69876
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<31-1;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef std::priority_queue<int> IntPrioQueue; //Z->A
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue; //A->Z

void solve(void){
    int N, S;
    cin >> N >> S;
    int ans = 0;
    Rep(N, S, n) {
        if (n/10000==n%10 and (n/1000)%10==(n/10)%10) ans++;
    }
    cout << ans << '\n';
}

int main(void){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<utility>
#include<algorithm>
typedef long long LL;
#define pii pair<LL,LL>
using namespace std;
const LL mod=1e9+7;
LL a,b,c,d,ans=0;
LL nowx,nowy,nowz,disx,disy,disz,prex,prey,prez;
vector<pii> vec;
bool cmp(pii a,pii b){
	return a.first*b.second<a.second*b.first;
}
int main(){
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	for (int i=0;i<=d;i++){
		if (i<a){
			vec.push_back(make_pair(i,a));
			vec.push_back(make_pair(a-i-1,a));
		}
		if (i<b){
			vec.push_back(make_pair(i,b));
			vec.push_back(make_pair(b-i-1,b));
		}
		if (i<c){
			vec.push_back(make_pair(i,c));
			vec.push_back(make_pair(c-i-1,c));
		}
	}
	sort(vec.begin(),vec.end(),cmp);
	for (int i=0;i<vec.size();i++){
		nowx=a*vec[i].first/vec[i].second;
		nowy=b*vec[i].first/vec[i].second;
		nowz=c*vec[i].first/vec[i].second;
		disx=min(a-1,prex+d)-max(0LL,prex-d)+1;
		disy=min(b-1,prey+d)-max(0LL,prey-d)+1;
		disz=min(c-1,prez+d)-max(0LL,prez-d)+1;
		if (nowx+d<a) ans=(ans+(nowx-prex)*disy%mod*disz%mod)%mod;
		if (nowy+d<b) ans=(ans+(nowy-prey)*disx%mod*disz%mod)%mod;
		if (nowz+d<c) ans=(ans+(nowz-prez)*disx%mod*disy%mod)%mod;
		prex=nowx,prey=nowy,prez=nowz;
	}
	ans=(ans+(min(a-1,d)+1)*(min(b-1,d)+1)%mod*(min(c-1,d)+1)%mod)%mod;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 10476
"""
連続する数は動かさず、それ以外を左右に分配していく
⇨並べ替えた後、昇順に連続しているかは、インデックスが昇順になっているかを見る
"""
import sys
input = sys.stdin.readline

n = int(input())
ps = {int(input()):i for i in range(n)}
cnt = 1
prev = 10**10
ans = 0
# 番兵
ps[n+1] = -1
for i in range(1,n+2):
    ind = ps[i]
    if prev < ind:
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 1
    prev = ind
print(n-ans)

Measured memory_bytes: 35424
def main():
    N = int(input())
    S = sorted([int(_) for _ in input().split()])
    Q = int(input())
    T = sorted([int(_) for _ in input().split()])

    ans = 0

    for t in T:
        left = 0
        right = len(S) - 1

        while True:
            mid = (left + right) // 2
            if S[mid] == t:
                ans += 1
                break
            elif S[mid] < t:
                left = mid + 1
            else:
                right = mid - 1

            if left > right:
                break

    print(ans)

main()



Measured memory_bytes: 16900
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;

 const int maxn = 100000;
 struct Point
 {
    double x,y;
    Point() {}
    Point(double _x, double _y) {
        x = _x;
        y = _y;
    }

    Point operator -(const Point &B) const {
        return Point(x-B.x, y-B.y);
    }

 }p[maxn];

 double eps = 1e-10;
 
 int dcmp(double x)
 {
    if(fabs(x) < eps) return 0;
    else return x < 0 ? -1 : 1;
 }
 
 double Cross(Point A, Point B)
 {
    return A.x*B.y - A.y*B.x;
 }
 
 bool isConvex(Point *p, int n)
 {
    p[n] = p[0]; 
    p[n+1] = p[1]; 
    int now = dcmp(Cross(p[1]-p[0], p[2]-p[1]));
    for(int i = 1; i < n; i++)
    {
        int next = dcmp(Cross(p[i+1]-p[i], p[i+2]-p[i+1]));
        if(now*next < 0)
        {
            return false;
        }
        now = next; 
    }
    return true;
 }
 
 int main()
 {
    int n=4;
    char temp,temp2;
    while(cin>>p[0].x>>temp>>p[0].y>>temp2)
    {
        for(int i = 1; i < 3; i++)
        {
            char temp3,temp4;     
            cin>>p[i].x>>temp3>>p[i].y>>temp4;
        }
        char temp5;
        cin>>p[3].x>>temp5>>p[3].y;
        bool flag = isConvex(p,n);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    //while(1);
    return 0;
 }

 

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

int main(){
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }
    sort(s.begin(), s.end());

    rep(i, n){
        cout << s[i];
    }
    cout << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 256
def cmod(n, r, p):
    x,y  = 1, 1
    for i in range(r):
        x = x * (n - i) % p
        y = y * (r - i) % p
    return (x * pow(y, p - 2, p)) % p


n, a, b = map(int, (input().split()))
p = 10 ** 9 + 7
print((pow(2, n, p) - 1 - cmod(n, a, p) - cmod(n, b, p)) % p)

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

int main(){
  int n;
  cin >> n;
  vector<tuple<string,int,int>> a(n);
  rep(i,n){
    string city;
    int score;
    cin >> city >> score;
    a[i]= make_tuple(city,-score,i);
  }
  sort(a.begin(),a.end());
  rep(i,n)cout << get<2>(a[i])+1 << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
//#include "MyMath.h"
//#include "DataStructure.h"
#include <map>
#include <set>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <functional>
#include <math.h>
#include <string.h>
using namespace std;
const int num = 15, num1 = 10000000;
typedef long long int ll;
typedef pair<int, int> p;
const int INF = 20000000;
int dp[1 << num][num], m[num][num];
int n, e;
int solve(int s, int v) {
	if (s == (1 << n) - 1 && v == 0) {
		return dp[s][v] = 0;
	}
	if (dp[s][v] >= 0)
		return dp[s][v];
	int res = INF;
	for (int t = 0; t < n; t++)
		if (!(s >> t & 1))
			res = min(res, m[v][t] + solve(s | 1 << t, t));
	return dp[s][v] = res;
}
int main() {
	cin >> n >> e;
	fill(m[0], m[num], INF);
	fill(dp[0], dp[1 << num], -1);
	for (int i = 0; i < e; i++) {
		int  s, t, u;
		cin >> s >> t >> u;
		m[s][t] = u;
	}
	if (solve(0, 0) >= INF)
		cout << -1 << endl;
	else cout << solve(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 5016
#include <bits/stdc++.h>
 
using namespace std;
 
#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double
 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
#define MX LLONG_MAX
#define MN LLONG_MIN

const ll mod=1e9+7;
const ll N=1e5+5;
 
ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll a[n],sum=0,mn=MX,ans;
    for(ll i=0;i<n;i++)
    {
        a[i] = i+k;
        sum += a[i];
    }
    for(ll i=0;i<n;i++)
    {
        ll tmp = 0;
        for(ll j=0;j<n;j++)
        {
            if(i!=j)
            {
                tmp += a[j];
            }
        }
        if(abs(tmp-sum)<mn)
        {
            mn = abs(tmp-sum);
            ans = tmp;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <memory.h>
using namespace std;
int main()
{
	bool prime[1000010];
	memset(prime,1,1000010);
	prime[0]=prime[1]=0;
	int i,j,n,sum;
	for (i=2;i<1000000;i++)
	{
		if (prime[i])
		{
			for (j=2;i*j<1000000;j++)
			{
				prime[i*j]=false;
			}
		}
	}
	while(cin>>n)
	{
		sum=0;
		for(i=2;i<=n;i++)
		{
			sum+=prime[i];
		}
		cout<<sum<<endl;

	}	
	return 0;
}

Measured memory_bytes: 2140
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)
	prices := scanNums(N)
	max := -100
	total := 0
	for _, p := range prices {
		if max < p {
			max = p
		}
		total += p
	}
	fmt.Printf("%d\n", total-max/2)
}

/**
 * １行に空白区切りで数字を読み込み
 */
func scanNums(len int) (nums []int) {
	nums = make([]int, len)
	for i := 0; i < len; i++ {
		fmt.Scan(&nums[i])
	}
	return
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
int ans=0,i,j,n,m,a[110][110],b[110];
scanf("%d %d\n",&n,&m);
for(i=0;i<n;i++){
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
scanf("\n");
}
for(i=0;i<m;i++){
scanf("%d\n",&b[i]);
}
for(i=0;i<n;i++){
for(j=0;j<m;j++){
ans=ans+a[i][j]*b[j];
}
printf("%d\n",ans);
ans=0;
}
return 0;
}


Measured memory_bytes: 2080
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

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

    std::string S;
    std::cin >> S;

    std::stack<char> stack;

    for (size_t i = 0; i < S.size(); ++i) {
        if (stack.empty()) {
            stack.push(S[i]);
        }
        else {
            auto c = stack.top();
            if (c == '(' && S[i] == ')') {
                stack.pop();
            }
            else {
                stack.push(S[i]);
            }
        }
    }

    int countOpen, countClose;
    countOpen = countClose = 0;
    while (!stack.empty()) {
        auto c = stack.top();
        stack.pop();
        if (c == '(') {
            countOpen++;
        }
        else {
            countClose++;
        }
    }

    std::string result;
    result.append(countClose, '(');
    result.append(S);
    result.append(countOpen, ')');

    std::cout << result << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <numeric>
#include <iomanip>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using namespace std;
//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; }
template<class T> inline bool chmin(T a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;
typedef long long int ll ;


#define INF 2000000000


int main() {
 
    int n,m;
    cin >> n >> m ;
    
    n==m ? (cout << "Yes" << endl ) : (cout << "No" << endl );

   // cout << tmp ;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for (int i = 0; i < S.size()-2; ++i)
    if (S.substr(i,3) == "ABC")
      ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
pts = n.times.map{ gets.split.map(&:to_i) }
pts_0 = pts.select{ |_, _, h| h <= 0 }
pts_1 = pts.select{ |_, _, h| h > 0 }
(0..100).each do |xx|
  (0..100).each do |yy|
    heights = pts_1.map{ |x, y, h| (x - xx).abs + (y - yy).abs + h }
    if heights.uniq.size == 1
      h = heights[0]
      if pts_0.all?{ |x, y, _| h - (x - xx).abs - (y - yy).abs <= 0 }
        puts [xx, yy, h].join(" ")
        break
      end
    end
  end
end


Measured memory_bytes: 3836
#include<bits/stdc++.h>
#define x first
#define y second
#define ll long long
#define pii pair<int, int>
#define maxn 1005
#define dbg(n) cout << n << endl
using namespace std;

inline void read(int &x){
	int f = 1; x = 0; char s = getchar();
    while(s > '9' || s < '0'){
		if(s == '-') f = -1;
		s = getchar();
	}
    while(s <= '9' && s >= '0'){
		x = x * 10 + s - '0';
		s = getchar();
	}
    x = x * f;
}

int k, s;

ll dp[7505][3];

ll df(int n, int t){
	if(t == 0) return (n > k ? 0 : 1);
	else{
		if(dp[n][t] != -1) return dp[n][t];
		ll sum = 0;
		for(int i = 0; i <= min(n, k); ++i)
			sum = sum + df(n - i, t - 1);
		dp[n][t] = sum;
		return sum;
	}
}

int main(){
	read(k); read(s);
	for(int i = 0; i < 7505; ++i){
		dp[i][0] = -1;
		dp[i][1] = -1;
	    dp[i][2] = -1;
	}
	cout << df(s, 2) << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

#define pr_arr(name, a, b) \
  for (int i = (a); i < (b); i++) { \
    for (int j = (a); j < (b); j++) {\
      if (j > (a)) printf(" "); \
      printf("%lld", name[i][j]); \
    }\
    printf("\n");\
  }\

#define YES puts("YES")
#define NO  puts("NO")
#define Yes puts("Yes")
#define No  puts("No")

using namespace std;

typedef long long ll;

int ans;
char S[105], T[105];
int N;

int main(void) {
    scanf("%d", &N);
    scanf("%s", S);
    scanf("%s", T);

    int si = 0, ti = 0;
    for (int i = 0; i < 2 * N; i++) {
        if (i % 2 == 0) {
            printf("%c", S[si++]);
        } else {
            printf("%c", T[ti++]);
        }

    }
   

  
    printf("\n");

	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        a: [i32; 5],
    }
    let mut sum = a.iter()
    .map(|i| i/10*10)
    .sum::<i32>();
    let mut v = a.iter()
    .map(|i| i%10)
    .collect::<Vec<i32>>();
    v.sort();
    let mut flag = false;
    for i in 0..5{
        if (v[i]!=0 && !flag){
            sum += v[i];
            flag = true;
        }
        else{
            sum += (v[i]+9)/10*10;
        }
    }
    println!("{}", sum);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
a,b,c,x,y = map(int,input().split())
res = float('inf')
for numc in range(2*max(x, y)+1):
    numa = max(0, x - numc//2)
    numb = max(0, y - numc//2)
    res = min(res, a*numa + b*numb + c*numc)
print(res)

Measured memory_bytes: 3060
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ini = sum(a)
ans = 0
remain = a[0]

for i in range(n):
    remain = max(0, b[i] - a[i])
    a[i] = max(0, a[i]-b[i])
    a[i+1] = max(0, a[i+1]-remain)

    
fin = sum(a)

print(ini-fin)

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

int main()
{
  int N; cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; ++i) cin >> S[i];

  map<char, ll> cnt;
  for (int i = 0; i < N; ++i) {
    if (S[i][0] == 'M' || S[i][0] == 'A' || S[i][0] == 'R' ||
        S[i][0] == 'C' || S[i][0] == 'H') {
      cnt[S[i][0]]++;
    }
  }

  string P = "MMMMMMAAAR";
  string Q = "AAARRCRRCC";
  string R = "RCHCHHCHHH";

  ll ans = 0;
  for (int i = 0; i < 10; ++i) {
    ans += cnt[P[i]] * cnt[Q[i]] * cnt[R[i]];
  }

  cout << ans << endl;
}

Measured memory_bytes: 6144
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int inf = 1001001001;
int main(){
  int N,M,i,j,k;scanf("%d%d",&N,&M);
  int dp[M+1][1<<N];
  fill(dp[0],dp[0]+(1<<N),inf);dp[0][0] = 0;
  dp[0][0] = 0;
  int a,b,c,plus;
  for(i=0;i<M;i++){
    for(j=0;j<(1<<N);j++) dp[i+1][j] = dp[i][j];
    scanf("%d%d",&a,&b);plus = 0;
    for(k=0;k<b;k++){
      scanf("%d",&c);c--;
      plus += 1<<c;
    }
    for(j=0;j<(1<<N);j++) dp[i+1][j|plus] = min(dp[i+1][j|plus],dp[i][j]+a);
  }
  if(dp[M][(1<<N)-1] == inf) printf("-1\n");
  else printf("%d\n",dp[M][(1<<N)-1]);
}


Measured memory_bytes: 19552
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
   ll n;
   cin>>n;
   ll c=0;
   while (n!=0){
    if (n%10==7){
        c++;
        break;
    }
    n/=10;
   }
   if (c==0) cout<<"No";
   else cout<<"Yes";
return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int X, A;
	
	std::cin >> X >> A;
	
	if (X < A)
		std::cout << "0\n";
	else
		std::cout << "10\n";
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 998244353;

long long int N, M, K, H, W, L, R;

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

	cin >> N;
	vector<int>v(N);
	vector<int>w(N);
	for (auto &i : v)cin >> i;
	bool flag = true;
	L = -1;
	for (int i = N - 1; i >= 0; i--) {
		if (v[i] == 1) {
			if (flag) {
				L = i;
			}
		}
		else {
			if (L != -1)flag = false;
		}
	}
	if (L == -1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		w[i] = v[(i + L) % N];
	}
	vector<int>l(N + 1, -1);
	vector<int>r(N + 1, -1);
	for (int i = 0; i < N; i++) {
		if (r[w[i]] == -1) {
			r[w[i]] = i;
			l[w[i]] = i;
		}
		else if (r[w[i]] == i - 1) {
			r[w[i]] = i;
		}
		else {
			cout << 0 << endl;
			return 0;
		}
	}
	w.push_back(1);
	long long int ans = 1;
	if (r[1] == N - 1) {
		for (int i = 2; i <= N; i++) {
			ans *= i;
			ans %= MOD;
		}
		cout << ans << endl;
		return 0;
	}
	int by = 0;
	for (int i = 2; i <= N; i++) {
		if (l[i] == -1) {
			ans *= by;
			by--;
			ans %= MOD;
		}
		else if (r[i] - l[i] > r[1] - l[1]) {
			cout << 0 << endl;
			return 0;
		}
		else if (w[l[i] - 1] > i&&w[r[i] + 1] > i&&r[i] - l[i] < r[1] - l[1]) {
			cout << 0 << endl;
			return 0;
		}
		else if (r[i] - l[i] <= r[1] - l[1]) {
			if (w[l[i] - 1] < i&&w[r[i] + 1] < i) {
				ans *= r[1] - l[1] - (r[i] - l[i]) + 1;
				by += r[1] - l[1] + 1 + r[i] - l[i] + 1 - 2;
				ans %= MOD;
			}
			else if(!(w[l[i] - 1] > i&&w[r[i] + 1] > i)){
				by += r[i] - l[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <string>
#include <vector>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;

int main(){
 int n;
 long long r=0;
 long long g=0;
 long long b=0;
 long long sum=0;
 string s;

 cin>>n>>s;

 rep(i,n){
     if(s.at(i)=='R'){r++;}
     if(s.at(i)=='G'){g++;}
     if(s.at(i)=='B'){b++;}
     
 }

 sum=r*g*b;

for(int j=1;2*j<=n;j++){
    for(int i=0;i<n-2*j;i++){
        if(s.at(i)!=s.at(i+j)&&s.at(i+j)!=s.at(i+2*j)&&s.at(i+2*j)!=s.at(i)){sum--;}
    }
}



cout<<sum<<endl;


}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = int64_t;

const ll dp_size = 1e4 + 10;
ll dp[dp_size];

int main() {
    ll C, N, M;
    cin >> C >> N >> M;
    for(int input = 0; input < N; input++) {
        ll s, p;
        cin >> s >> p;
        for(ll pre_size = C - s; pre_size >= 0; pre_size--) {
            ll &tmp = dp[pre_size + s];
            tmp = max(tmp, dp[pre_size] + p);
        }
    }

    for(ll k = 1; k <= M; k++) {
        ll d = C / k;
        cout << dp[d] * k << endl;
    }
    return 0;
}



Measured memory_bytes: 3160