akhauriyash/Code-Regression huggingface dataset:
n_all,leg_all=map(int, input().split())

for i in range(n_all+1):
    leg_kame=2*(n_all-i)
    leg_turu=4*i
    if leg_kame+leg_turu==leg_all:
        print('Yes')
        break
    else:
        continue
else:(print('No'))


Measured memory_bytes: 9156
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni();
        long c = in.nl(), k = in.nl();
        long[] t = in.nl(n);
        Arrays.sort(t);
        int ans = 0, last = 0;
        for (int i = 1; i < n; i++) {
            if(t[i]>t[last]+k||i-last+1>c){
                ans++;
                last = i;
            }
        }
        ans++;
        out.println(ans);
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 37080
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
		string[] line = Console.ReadLine().Trim().Split(' ');
		var n = int.Parse(line[0]);
		var k = int.Parse(line[1]);
		var ans = 0d;
		for (int i = 1; i <= n; i++)
		{
			if (i <= k - 1)
			{
				var w = (int)(Log10(k / i) / Log10(2)) + 1d;
				if (i * (int)Pow(2d, w - 1) == k) w -= 1d;
				ans += (1 / Pow(2d, w));
			}
			else ans += 1d;
		}
		Console.WriteLine(ans /n );
	}
}

Measured memory_bytes: 11092
# ABC060b
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

a, b, c = map(int, input().split())

for i in range(a, a * b+a, a):
    if (i % b == c):
        #print(i, b, i % b, c)
        print('YES')
        exit()
print('NO')

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

int x, y, z;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> x >> y >> z;
    if(x != y && x != z) cout << x << endl;
    if(y != x && y != z) cout << y << endl;
    if(z != x && z != y) cout << z << endl;
    return 0;
}


Measured memory_bytes: 256
//noob
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int(x.size()))
typedef vector<int> vi;
typedef pair<int,int> PI;
const int N = (int)1e6 + 7;

void solve()
{
	string s,t;cin>>s>>t;
	int min=10001;
	for(int i=0;i<=sz(s)-sz(t);i++){
		int count=0;
		for(int j=0;j<sz(t);j++){
			if(t[j]!=s[i+j]) count++;
			
		}
		if(count<min) min=count;
	}
		if(min==10001) cout<<"0"<<endl;
		else cout<<min<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	
solve();
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fir first
#define sec second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
    int n, m;
    cin >> n >> m;
    ll ans = 0;
    vector<int> A(n);
    vector<P> B;
    rep(i,n)cin>>A[i];
    A.pb(INF);
    rep(i,m){
        int b,c;
        cin >> b >> c;
        B.pb(make_pair(c,b));
    }
    sort(all(A));
    sort(rall(B));
    int id = 0;
    bool flag = false;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < B[i].sec; j++) {
            if(A[id] < B[i].fir)A[id] = B[i].fir;
            else{
                flag = true;
                break;
            }
            id++;
        }
        if(flag) break;
    }
    rep(i,n)ans += A[i];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2184
n=int(input())
mul=1
limit=1000000000000000000
x=input().split()
for i in range (n):
    p=int(x[i])
    if(p==0):
        mul=0
        break
if(mul==0):
    print(mul)
else:
    for i in range (n):
        p=int(x[i])
        mul*=p
        if(mul>limit):
            break
    if(mul>limit):
      print(-1)
    else:
      print(mul)

Measured memory_bytes: 19516
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.numeric;

void main() {
    int n;
    scan(n);
    
    long ans = 1;

    foreach (i ; 0 .. n) {
        long t;
        scan(t);
        ans = lcm(ans, t);
    }

    writeln(ans);
}

long lcm(long a, long b) {
    return a / gcd(a, b) * b;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

int score(int d, vector<int> &c, vector<vector<int>> &s, vector<int> &lt, int t, int sc) {
  int score = sc;
  score += s[d][t];
  lt[t] = d;
  rep(j, 26) score -= c[j]*(d-lt[j]);
  return score;
}

signed main() {
  int D; cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];
  vector<int> t(D, 1);

  
  int sc = 0;
  vector<int> lt(26, -1);
  rep(i, D) {
    int nextsc = score(i, c, s, lt, 0, sc);
    rep(tmp, 26) {
      if(nextsc < score(i, c, s, lt, tmp, sc)) {
        t[i] = tmp+1;
        nextsc = score(i, c, s, lt, tmp, sc);
      }
    }
    sc = nextsc;
  }
  rep(i, D) cout << t[i] << endl;
    

}

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

int foo(const int N, const int K, char* S)
{
  int ct=0;
  for(int i=0; i<N-1; i++){
    ct+= S[i]==S[i+1];
  }
 
  //cout<< min(ct+2*K,N-1)<<"\n";
  return min(ct+2*K,N-1);
}

int main()
{ 
  int N,K;
  cin >> N>>K;
 
  char S[N+2];
  cin>>S;
  cout << foo(N, K, S) << endl;

  return 0;
}


Measured memory_bytes: 384
def main():
    a, b = map(int, input().split(" "))
    for i in range(1,1010):
        ta = i*8//100
        tb = i*10//100
        if ta == a and tb == b:
            print(i)
            return
    print(-1)
    

if __name__ == "__main__":
    main()

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    string s,t,ss="",tt="";
    cin>>s>>t;
    //cerr<<s<<" "<<t<<endl;
    ss=s,tt=t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<ll>());
    if(s<t)
      Yes
    else
      No


}
return 0;
}

Measured memory_bytes: 256
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;

signed main() {
int N , M , sum=0,rere=-1;
cin >> N >> M;
vector<int> A(M);
REP(i,M){
    cin >> A[i];
    sum = sum + A[i];
}
if(N < sum) cout << rere << endl;
else cout << N - sum <<endl;

}

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

int main() {
  string s;
  lint k;
  cin >> s >> k;
  for (int i = 0; i < s.size() && i < k; i++) {
    if (s[i] != '1') {
      cout << s[i] << endl;
      return 0;
    }
  }
  cout << "1" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>

using namespace std;

int n, a, b, c, x, y, z;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b >> c;

		int u = x, v = y, w = z;
		x = max(v, w) + a;
		y = max(u, w) + b;
		z = max(u, v) + c;
	}
	
	int ans = max(x, max(y, z));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

vector<vector<int>> G;
vector<int> color;
void dfs(int v, int pv, int c) {
    color[v] = c;
    for (auto nv : G[v]) {
        if (nv==pv) continue;
        dfs(nv,v,1-c);
    }
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    G.resize(N);
    rep(i,N-1) {
        int a,b; cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    color.resize(N);
    dfs(0,-1,0);
    int b = 0, w = 0;
    rep(i,N) {
        if (color[i]) b++;
        else w++;
    }
    queue<int> que1,que2,que3;
    for (int i = 1; i <= N; ++i) {
        if (i%3==0) que3.emplace(i);
        if (i%3==1) que1.emplace(i);
        if (i%3==2) que2.emplace(i);
    }
    vector<int> ans(N);
    if (b <= N/3) {
        rep(i,N) {
            if (color[i]) {
                ans[i] = que3.front(); que3.pop();
            } else {
                if (!que1.empty()) {
                    ans[i] = que1.front(); que1.pop();
                } else if (!que2.empty()) {
                    ans[i] = que2.front(); que2.pop();
                } else {
                    ans[i] = que3.front(); que3.pop();
                }
            }
        }
    } else if (w <= N/3) {
        rep(i,N) {
            if (!color[i]) {
                ans[i] = que3.front(); que3.pop();
            } else {
                if (!que1.empty()) {
                    ans[i] = que1.front(); que1.pop();
                } else if (!que2.empty()) {
                    ans[i] = que2.front(); que2.pop();
                } else {
                    ans[i] = que3.front(); que3.pop();
                }
            }
        }
    } else {
        rep(i,N) {
            if (color[i]) {
                if (!que1.empty()) {
                    ans[i] = que1.front(); que1.pop();
                } else {
                    ans[i] = que3.front(); que3.pop();
                }
            } else {
                if (!que2.empty()) {
                    ans[i] = que2.front(); que2.pop();
                } else {
                    ans[i] = que3.front(); que3.pop();
                }
            }
        }
    }
    
    rep(i,N) cout << ans[i] << " ";
    cout << ln;
}

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

// macros
#define overload_rep(_1, _2 ,_3 ,name, ...) name
#define re_p(i, n) for(int i = 0; i < (n); ++i)
#define r_ep(i, x, y) for(int i = (x); i <= (y); ++i)
#define rep(...) overload_rep(__VA_ARGS__, r_ep, re_p)(__VA_ARGS__)
#define all(a) a.begin(), a.end()
#ifndef STOP_DEBUG
#define debug(...)\
    do { cerr << boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_cerr(__VA_ARGS__); cerr << noboolalpha; } while (0)
#else
#define debug(...)
#endif

// functions
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; }
void debug_cerr(){ cerr << '\n'; }
template<class Head, class... Tail>
void debug_cerr(Head head, Tail... tail){
    cerr << ' ' << head;
    debug_cerr(tail...);
}
template<typename T>
vector<T> make_v(size_t a, T b){ return vector<T>(a, b); }
template<typename... Ts>
auto make_v(size_t a, Ts... ts){
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

// cin/cout setup
struct IoSetup{
    IoSetup(){
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} iosetup;

// Let's get AC!

typedef long long lint;
constexpr int mx = 200000;
constexpr lint inf = 1ll << 60;
int L;
lint A[mx];
lint dp[mx + 1][5];

int main(){

    cin >> L;
    rep(i, L)cin >> A[i];
    
    rep(i, 0, L)rep(j, 5)dp[i][j] = inf;
    dp[0][0] = 0;

    auto calc = [&](int i, int j){
        if(j & 1){
            if(A[i] > 0)return A[i] % 2;
            else return 2ll;
        }
        if(j == 2)return (A[i] + 1) % 2;
        else return A[i];
    };

    rep(i, L){
        rep(j, 5)rep(nj, j, 4){
            chmin<lint>(dp[i + 1][nj], dp[i][j] + calc(i, nj));
        }
    }

    // rep(j, 5){
    //     rep(i, 0, L){
    //         if(dp[i][j] == inf)cout << " inf";
    //         else cout << setw(4) << dp[i][j];
    //     }
    //     cout << endl;
    // }

    lint ans = inf;
    rep(j, 5)chmin(ans, dp[L][j]);
    cout << ans << '\n';
    return 0;

}

Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int bubble_sort(int a[],int n){
    int c=0;
    for(int i=0;i<n;i++){
        for(int i=1;i<n;i++){
            if(a[i-1]>a[i]){
                c++;
                swap(a[i-1],a[i]);
            }
        }
    }
    return c;
}

int main(){
    int n,a[100];
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int change = bubble_sort(a,n);
    for(int i=0;i<n-1;i++){
        cout << a[i] << ' ';
    }
    cout << a[n-1] << endl;
    cout << change << endl;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int k;
    int[] h;
    long dp[];

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }
        sc.close();

        // 解答処理
        solve();
    }
    
    private void solve() {
        dp = new long[n];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 1; i < n; i++) {
            dp(i);            
        }
        System.out.println(dp[n-1]);
    }
    
    private void dp(int cur) {
        int i=0;
        if (cur <= k) {
            i = 0;
        } else {
            i = cur - k;
        }
        for(; i < cur; i++){
            dp[cur] = Math.min(dp[i] + Math.abs(h[i] - h[cur]), dp[cur]);
        }
    }
}

Measured memory_bytes: 50388
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<cstdlib>
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
#define regsiter register
#define CL fclose(stdin),fclose(stdout)
namespace io
{
	int F()
	{
		int n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
	long long G()
	{
		long long n=0,F=1;
		char ch;
		while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		ch=='-'?F=0:n=ch-'0';
		while((ch=getchar())>='0'&&ch<='9')n=(n<<1)+(n<<3)+ch-'0';
		return F?n:-n;
	}
}
#include<set>
int a[211111];
int v[211111];
std::multiset<int> pos,neg;
long long sp;
int main()
{
	int n=io::F()<<1,Q=io::F();
	long long ans=0;
	for(register int i=1;i<=n;++i)ans+=a[i]=io::F();
	io::F();
	for(register int i=2;i<n;++i)v[i]=io::F()-a[i];
	io::F();
	for(register int i=2;i<n;++i)v[i]>=0?sp+=v[i],pos.insert(v[i]):neg.insert(v[i]);
	for(register int i=1;i<=Q;++i)
	{
		int p=io::F(),x=io::F(),y=io::F();
		ans-=a[p];
		ans+=a[p]=x;
		if(p==1||p==n)goto skip;
		v[p]>=0?sp-=v[p],pos.erase(pos.find(v[p])):neg.erase(neg.find(v[p]));
		v[p]=y-x;
		//for(std::multiset<int>::iterator it=pos.begin();it!=pos.end();++it)printf("%d\n",*it);
		v[p]>=0?sp+=v[p],pos.insert(v[p]):neg.insert(v[p]);
		skip:;
		if(pos.size()&1)
		{
			if(*pos.begin()>-*neg.rbegin())printf("%lld\n",ans+sp+*neg.rbegin());
				else printf("%lld\n",ans+sp-*pos.begin());
		}
		else printf("%lld\n",ans+sp);
	}
	return 0;
}




Measured memory_bytes: 12672
#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define pb push_back
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define all(m) m.begin(), m.end()
#define uid uniform_int_distribution
#define init(m, x) memset(m, x, sizeof(m));
#define FILE ifstream in("input.txt");ofstream out("output.txt");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    fast;
    str t; cin>>t;
    int o = 0;
    for(char c : t) o += c-'0';
    cout<<(o%9 ? "No" : "Yes");
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
multiset<double> s; 
int main() {
	int n;
	cin>>n;
	double x;
	for (int i=0,y; i<n;i++) {cin>>y; s.insert(y); }
	while (s.size()>1) {
		set<double>::iterator it=s.begin();
		double u=*it;
		s.erase(it);
		it=s.begin();
		double v=*it;
		s.erase(it);
		s.insert((u+v)/2.0);
	} 
	printf("%lf\n", *s.begin());
	return 0;
}

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

//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
//using namespace __gnu_pbds;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> dct;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair

bool compare(pair<ll,pii> a, pair<ll,pii> b)
{return a.second.second*b.second.first < b.second.second*a.second.first;
}

const int mod = 1e9 + 7;
const ll inf = ll(1e18);


int main() {
    //clock_t tm = clock();
    fastio;
    string s;ll k,n;
    cin>>s;n=s.length();
    cin>>k;
    ll ans=0;int flag=0;
    map<char,int>fq;
    fr(i,s)fq[i]++;
    if(fq.size()==1){
        ll x = n*k;
        cout<<x/2<<endl;
    }
    else {
        ll end=n-2,start=0;
        while(s[end]==s[n-1])end--;
        while(s[start]==s[n-1])start++;
        f(i, start, end+1) {
            if (s[i] == s[i - 1]) {
                ans++;
                if (i < end and s[i + 1] == s[i])i++;
            }
        }
        ans *= k;
        ll rep = start + n-1-end;
        ans += (k-1)*(rep/2);
        ans += start/2;
        ans += (n-1-end)/2;
        cout << ans << endl;
    }
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

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

	int a[n];
	for(i=0; i<n; i++)
		scanf("%d", &a[i]);

	for(i=n-1; i>=0; i--){
		printf("%d", a[i]);
		if(i!=0)
			printf(" ");
	}
	printf("\n");

	return 0;
}

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



int seeIndex(int num1, int max1){
    int count1 = 0;
    while(num1 < max1 ){
        num1 = num1 * 2;
        count1++;
    }
    return count1;
}

double seeAnswer(int count, double num){
    double probability = 1 / num;
    for (int counts = count; counts > 0; counts--){
        probability= probability / 2;  
    }
    return probability;
}

int main (){
    double n; 
  	int k;
    cin >> n >> k;
    double answer = 0;
    for (int i = 1; i <= n; i++){
        answer = answer + seeAnswer(seeIndex(i, k), n);
    }
    std::cout << std::setprecision(13) << answer << endl;
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define w(t) int t;cin>>t;while(t--)
#define pb push_back
#define mk make_pair
#define ascSort(v) sort(v.begin(), v.end())
#define descSort(v) sort(v.begin(), v.end(), greater<int>())
#define ff first
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define umapi unordered_map<int,int>

const int m=998244353;
using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>PBDS;

void FIO(){
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);	
}



int32_t main(){
	
	//FIO();
	int h,w;cin>>h>>w;
	vi row(h,0),col(w,0);
	int m;cin>>m;
	set<pi> s;
	for(int i=0; i<m; i++){
		int x,y;cin>>x>>y;
		x--;y--;
		s.insert({x,y});
		row[x]++;col[y]++;
	}

	int mxr=row[0],mxc=col[0];
	for(auto x:row)
		mxr=max(mxr,x);
	for(auto x:col)
		mxc=max(mxc,x);
	vi ansr,ansc;	
	for(int i=0; i<h ;i++){
		if(row[i]==mxr)
			ansr.pb(i);
	}
	for(int i=0; i<w ;i++){
		if(col[i]==mxc)
			ansc.pb(i);
	}
	int x=ansr.size(),y=ansc.size();
	if(x*y>(int)3*100000){
		cout<<mxr+mxc<<"\n";
		return 0;
	}
	else{
		for(int i=0; i<(int)ansr.size(); i++){
			for(int j=0; j<(int)ansc.size(); j++){
				if(s.find({ansr[i],ansc[j]})==s.end()){
					cout<<mxr+mxc;
					return 0;
				}
				//return 0;
			}
		}
	}		
	cout<<mxr+mxc-1;
		
	
	

	return 0;
	
		
}




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

int main(void)
{
    string s, t;
    cin >> s >> t;
    int answer = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) answer = 1;
    }   
    if (answer) cout << "No" << endl;
    else cout << "Yes" << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;
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+B)%2==0){
            System.out.println((A+B)/2);
        }else{
            System.out.println("IMPOSSIBLE");
        }

    }
}

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

int N;
int A[2][100];
int dp[2][100];

int main(){
  cin>>N;
  for(int i=0;i<2;i++)
    for(int j=0;j<N;j++)
      cin>>A[i][j];
  
  dp[0][0]=A[0][0];
  for(int i=0;i<2;i++){
    for(int j=0;j<N;j++){
      if(j+1<N){
        dp[i][j+1]=max(dp[i][j+1],dp[i][j]+A[i][j+1]);
      }
      if(i+1<2){
        dp[i+1][j]=max(dp[i+1][j],dp[i][j]+A[i+1][j]);
      }
    }
  }
  cout<<dp[1][N-1]<<endl;
  return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;



int main() {
    ll t1, t2, a1, a2, b1, b2;
    cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

    if (a1 < b1) {
        swap(a1, b1);
        swap(a2, b2);
    }

    ll p = (a1 - b1) * t1;
    ll q = (a2 - b2) * t2;

    if (p + q > 0) {
        cout << 0 << endl;
    } else if (p + q == 0) {
        cout << "infinity" << endl;
    } else {
        ll s = (-p) / (p + q);
        ll t = (-p) % (p + q);
        if (t == 0) {
            cout << s * 2 << endl;
        } else {
            cout << s * 2 + 1 << endl;
        }
    }


}

Measured memory_bytes: 3620
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a>=3200){
    cout << s << endl;
  }
  else{
    cout << "red" << endl;
  }
  return 0;
}

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

int main() {
  int k,x;
  cin >> k >> x;
  int l=max(-1000000,x-k+1);
  int r=min(1000000,x+k-1);
  for(int i=l; i<=r; i++) {
    cout << i << " ";
  }
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007

int main()
{
  ll n, m;
  cin >> n >> m;
  vector<ll> hs = {};
  ll h;

  hs.push_back(0); // dummy;

  for (auto i = 0; i < n; i++)
  {
    cin >> h;
    hs.push_back(h);
  }

  vector<ll> around(n + 1, 0);
  vector<set<ll>> roads(n + 1, set<ll>{});

  for (auto i = 0; i < m; i++)
  {
    ll a, b;
    cin >> a >> b;
    around[a] = max(around[a], hs[b]);
    around[b] = max(around[b], hs[a]);
  }

  ll cnt = 0;
  for (auto i = 1; i <= n; i++)
  {
    if (hs[i] > around[i])
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 9504
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    H, W, K = [int(x) for x in input().split()]
    S = [list(input().strip()) for _ in range(H)]

    ans = float("inf")

    for n in range(2 ** (H - 1)):
        tmp = 0
        wn = [0] * 10
        wi = [set() for _ in range(10)]

        ni = 0
        for i in range(H):
            wi[ni].add(i)
            if n >> i & 1:
                ni += 1
                tmp += 1

        for i in range(W):
            f = False
            for j in range(H):
                for wii in range(ni + 1):
                    if j in wi[wii]:
                        if wn[wii] + int(S[j][i]) > K:
                            tmp += 1
                            f = True
                        else:
                            wn[wii] += int(S[j][i])
                        break
                if f:
                    break
            if f:
                for wii in range(ni + 1):
                    wn[wii] = 0
                for j in range(H):
                    for wii in range(ni + 1):
                        if j in wi[wii]:
                            wn[wii] += int(S[j][i])
                            break
                for wii in range(ni + 1):
                    if wn[wii] > K:
                        tmp = float("inf")

        ans = min(ans, tmp)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52060
#include <iostream>
#include <map>
#include <cstring>
#include <climits>
#include <cstdlib>
using namespace std;

typedef pair<int,int> P;

int n, m;
map<string,P> hensu;
string t[102];
bool op[102], h[102], d[102];

bool dp[102][102][256];

bool solve(){
  memset(dp, 0, sizeof(dp));

  int size = 0;

  for(int i = 0; i < m; i++){
    if(d[i]){
      int x = atoi(t[i].c_str());

      dp[i + 1][size][x] = true;
      size++;

      for(int j = 0; j < size - 1; j++){
        for(int k = 0; k < 256; k++){
          dp[i + 1][j][k] = dp[i][j][k];
        }
      }
    }
    else if(h[i]){
      int from = hensu[t[i]].first;
      int to = hensu[t[i]].second;

      for(int j = from; j <= to; j++){
        dp[i + 1][size][j] = true;
      }

      size++;

      for(int j = 0; j < size - 1; j++){
        for(int k = 0; k < 256; k++){
          dp[i + 1][j][k] = dp[i][j][k];
        }
      }
    }
    else{
      size--;

      int cal;

      for(int j = 0; j < 256; j++){ //ue
        for(int k = 0; k < 256; k++){ //shita
          if(!dp[i][size][j] || !dp[i][size - 1][k]) continue;

          if(t[i] == "+"){
            cal = (k + j) % 256;
          }
          else if(t[i] == "-"){
            cal = (k - j + 256) % 256;
          }
          else if(t[i] == "*"){
            cal = (k * j) % 256;
          }
          else{
            if(j == 0){
              return false;
            }

            cal = (k / j) % 256;
          }

          dp[i + 1][size - 1][cal] = true;
        }
      }

      for(int j = 0; j < size - 1; j++){
        for(int k = 0; k < 256; k++){
          dp[i + 1][j][k] = dp[i][j][k];
        }
      }
    }
  }

  /*
  for(int i = 0; i <= m; i++){
    for(int j = 0; j < 3; j++){
      for(int k = 0; k <= 20; k++){
        printf("%d ", dp[i][j][k]);
      }
      cout<<endl;
    }
    cout<<endl;
  }
  */

  return true;
}

int main(){
  while(cin >> n){
    for(int i = 0; i < n; i++){
      string name;
      P p;
      cin >> name >> p.first >> p.second;
      hensu[name] = p;
    }

    memset(op, 0, sizeof(op));
    memset(h, 0, sizeof(h));
    memset(d, 0, sizeof(d));

    cin >> m;

    for(int i = 0; i < m; i++){
      cin >> t[i];

      if(t[i][0] == '+' || t[i][0] == '-' || t[i][0] == '/' || t[i][0] == '*'){
        op[i] = true;
      }
      else if(isdigit(t[i][0])){
        d[i] = true;
      }
      else{
        h[i] = true;
      }
    }

    if(solve()) cout << "correct\n";
    else        cout << "error\n";
  }
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<=(b);++i)
#define ROF(i,a,b) for (int i=(a);i>=(b);--i)
typedef long long ll;
inline int read() {
	int x=0,s=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') s=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return s*x;
}

const int MAXN=400005,Mo=1000000007;
int n,m,q,a[MAXN],b[MAXN];
ll work(int x,int y){
	ll ret=1e18;
	FOR(i,1,x-1) {
		ll S0=1ll*i*y;
		int X=x-i;
		ll S1,S2;
		if ((X&1)&&X>1) {
			S1=1ll*(X/2)*y; S2=1ll*(X/2+1)*y;
			ret=min(ret,max({S0,S1,S2})-min({S0,S1,S2}));
		}
		if (!(X&1)) {
			S1=S2=1ll*(X/2)*y;
			ret=min(ret,max({S0,S1,S2})-min({S0,S1,S2}));
		}
		if ((y&1)&&y>1) {
			S1=1ll*(y/2)*X; S2=1ll*(y/2+1)*X;
			ret=min(ret,max({S0,S1,S2})-min({S0,S1,S2}));
		}
		if (!(y&1)) {
			S1=S2=1ll*(y/2)*X;
			ret=min(ret,max({S0,S1,S2})-min({S0,S1,S2}));
		}
	}
	return ret;
}
int main(){
	n=read(); m=read();
	printf("%lld\n",min(work(n,m),work(m,n)));
	
	return 0;
}

/*
*/


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

string b = "aeiou";

int main(){
  string s; cin >> s;
  for (int i = 0; i < 5; i++) {
    if (s[0] == b[i]) {
      cout << "vowel" << endl;
      return 0;
    }
  }
  cout << "consonant" << endl;
  return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vint v(n);
    REP(i,n){
        v[i] = i+1;
    }
    vint p(n),q(n);
    REP(i,n) cin >> p[i];
    REP(i,n) cin >> q[i];
    int a=0,b=0;
    int now = 1;
    while(true){
        if(v==p){
            a=now;
        }
        if(v==q){
            b=now;
        }
        if(a>0&&b>0){
            break;
        }
        now++;
        next_permutation(v.begin(), v.end());
    }
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  t += s;
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

pair<int, int> val(const string& s)
{
	if (s == "AB") return { 0, 1 };
	if (s == "BC") return { 1, 2 };
	if (s == "AC") return { 2, 0 };

	return { -1, -1 };
}

int rem(const pair<int, int>& p) {
	return 3 - (p.first + p.second);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;

	int64_t vs[3]; cin >> vs[0] >> vs[1] >> vs[2];

	vector<string> ss(n); for (auto& s : ss) cin >> s;

	vector<int> ans(n);
	FOR_LT(i, 0, n) {
		string s = ss[i];
		pair<int, int> v = val(s);

		if (vs[v.first] == 0 && vs[v.second] == 0) {
			cout << "No" << endl;
			return 0;
		}
		if (vs[v.first] == 0) {
			ans[i] = v.first;
			vs[v.first]++;
			vs[v.second]--;
			continue;
		}
		if (vs[v.second] == 0) {
			ans[i] = v.second;
			vs[v.first]--;
			vs[v.second]++;
			continue;
		}
		if (vs[v.first] == 1 && vs[v.second] == 1) {
			if (i == n - 1) {
				ans[i] = v.first;
				vs[v.first]++;
				vs[v.second]--;
				continue;
			}

			string ns = ss[i + 1];
			int nr = rem(val(ns));
			if (nr == v.first) {
				ans[i] = v.second;
				vs[v.first]--;
				vs[v.second]++;
				continue;
			}
			if (nr == v.second) {
				ans[i] = v.first;
				vs[v.first]++;
				vs[v.second]--;
				continue;
			}

			ans[i] = v.first;
			vs[v.first]++;
			vs[v.second]--;
			continue;
		}

		if (vs[v.first] < vs[v.second]) {
			ans[i] = v.first;
			vs[v.first]++;
			vs[v.second]--;
			continue;
		}
		ans[i] = v.second;
		vs[v.first]--;
		vs[v.second]++;
	}

	cout << "Yes" << endl;
	FOR_LT(i, 0, n) {
		char c = 'A' + ans[i];
		cout << c << endl;
	}


	return 0;
}


Measured memory_bytes: 6600
#include "bits/stdc++.h"
using namespace std;

long long numOfPairs(const vector<int> &cards){
    long long num=0LL;
    int remain=0;
    for(int cnt : cards){
        num+=min(remain, cnt)*1LL;
        cnt-=min(remain, cnt);
        num+=cnt/2;
        remain=cnt%2;
    }
    return num;
}

int main(){
    int n;
    while(scanf("%d", &n)!=EOF){
        vector<int> cards;
        for(int i=0; i<n; i++){
            int cnt;
            scanf("%d", &cnt);
            cards.push_back(cnt);
        }
        printf("%lld\n", numOfPairs(cards));
    }
    return 0;
}


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

struct SieveOfEratosthenes {
    vector<int> primes;
    vector<bool> isPrime;
    void build(ll n) {
        primes.clear();
        isPrime.assign(n + 1, true);
        isPrime[0] = isPrime[1] = false;
        ll k = 2;
        for (; k * k <= n; ++k) {
            if (!isPrime[k]) continue;
            primes.push_back(k);
            for (int m = k * 2; m <= n; m += k) isPrime[m] = false;
        }
        for (; k <= n; ++k) if (isPrime[k]) primes.push_back(k);
    }
    int operator [](int i) const { return primes[i]; }
    int size() const { return primes.size(); }
};

int main() {
    int n;
    SieveOfEratosthenes soe;
    while (~scanf("%d", &n)) {
        soe.build(n);
        printf("%d\n", soe.size());
    }
}


Measured memory_bytes: 3452
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int r, D, x; cin >> r >> D >> x;
	loop(10) {
		x = r * x - D;
		cout << x << endl;
	}

	return 0;
}


Measured memory_bytes: 256
import sys
import itertools
input = sys.stdin.readline
sys.setrecursionlimit(100000)


def read_values():
    return map(int, input().split())


def read_index():
    return map(lambda x: x - 1, map(int, input().split()))


def read_list():
    return list(read_values())


def read_lists(N):
    return [read_list() for n in range(N)]


def main():
    N = int(input())
    X = read_list()
    res = 10 ** 10
    for y in range(1, 101):
        res = min(res, sum((x - y) ** 2 for x in X))
    print(res)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n), vis(n);
    vector<P> v;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v.push_back(P(a[i], i));
    }
    sort(all(v));
    reverse(all(v));
    set<int> st;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        int id = v[i].second;
        vis[id] = 1;
        if (i == 0) {
            st.insert(id);
            continue;
        }
        auto itr = st.lower_bound(id);
        if (itr != st.end()) {
            ll r = (*itr);
            auto it = st.upper_bound(r);
            ll rr;
            if (it == st.end()) {
                rr = n - 1;
            } else {
                rr = (*it) - 1;
            }
            ll l;
            auto itl = st.lower_bound(id);
            if (itl == st.begin()) {
                l = 0;
            } else {
                itl--;
                l = (*itl) + 1;
            }
            ans += a[id] * (id - l + 1LL) * (rr - r + 1LL);
        }
        if (itr != st.begin()) {
            itr--;
            ll l = (*itr);
            auto it = st.lower_bound(l);
            ll l2;
            if (it == st.begin()) {
                l2 = 0;
            } else {
                --it;
                l2 = (*it) + 1;
            }
            ll r;
            it = st.upper_bound(id);
            if (it == st.end()) {
                r = n - 1;
            } else {
                r = (*it) - 1;
            }
            ans += a[id] * (l - l2 + 1LL) * (r - id + 1LL);
        }
        st.insert(id);
    }
    cout << ans << endl;
}


Measured memory_bytes: 8048
S = list(input())
N = len(S)

la = 0
ra = 0
ans = 0

for i in range(N-1):
    if S[i] == "<":
        la += 1
    else:
        ra += 1

    if S[i] == ">" and S[i+1] == "<":
        m = min(la,ra) - 1
        M = max(la,ra)
        ans += M*(M+1)//2 + m*(m+1)//2
        la = 0 
        ra = 0

if S[-1] == "<":
        la += 1
else:
    ra += 1

m = min(la,ra) - 1
M = max(la,ra)
ans += M*(M+1)//2 + m*(m+1)//2

print(ans)

Measured memory_bytes: 7836