akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

int main(){

    int n;
    cin>>n;
    bool flag=false;
    int tmp;
    REP(i,n){
        cin>>tmp;
        if(tmp%2==0){
            if(tmp%3&&tmp%5){
                flag=true;
            }
        }
    }    
    if(flag==false){
        cout<<"APPROVED"<<endl;
    }else{
        cout<<"DENIED"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 2e5;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =    1e9+7;

int main()
{  fast
int n,m;
cin>>n>>m;
if(m>=n)
puts("unsafe");
else
puts("safe");
}


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

int main(){
    int X,cnt,ans=1;
    cin >> X;
    for(int i=2;i<32;i++){
        cnt=i*i;
        if(cnt<=X)
        ans=max(ans,cnt);
        while(cnt<X){
            cnt*=i;
            if(cnt<=X)
            ans=max(ans,cnt);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
I = lambda : list(map(int,input().split()))

n,=I();a=[];b=[]
for i in range(n):
  x,y=I()
  a.append(x);b.append(y)
a.sort();b.sort()
if n%2:
  print(b[n//2]-a[n//2]+1)
else:
  x=(a[n//2-1]+a[n//2]);y=(b[n//2-1]+b[n//2])
  print(y-x+1)

Measured memory_bytes: 25388
package main

import "fmt"

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if (a + b) > (c + d) {
		fmt.Println("Left")
	} else if (a + b) == (c + d) {
		fmt.Println("Balanced")
	} else {
		fmt.Println("Right")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
const ll mod = 1e9 + 7;
vector<int>g[maxn];
int n;

ll dp[maxn][2];

void dfs(int node, int p) {
	dp[node][0] = dp[node][1] = 1LL;

	for(int i:g[node]) {
		if(i == p) continue;

		dfs(i, node);

		dp[node][1] *= 1LL * (dp[i][0] + dp[i][1]);
		dp[node][1] %= mod;

		dp[node][0] *= dp[i][1];
		dp[node][0] %= mod;
	}
}

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

	dfs(1, -1);
	cout<<(dp[1][0] + dp[1][1])%mod<<"\n";
}

Measured memory_bytes: 14208
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int k,s;cin >> k >> s;

    int res=0;
    for(int x=0 ; x<=k ; x++){
        for(int y=0 ; y<=k ; y++){
            if(x+y<=s && x+y+k>=s) res++;
        }
    }
    p(res)
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  
  cout << a[n/2] - a[n/2-1] << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
const ll MOD = 1e9+7;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second


const int INF = 1e9;
const ll LLINF = 1e16;

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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}
 
template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
 
template<typename T>
T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T>
T ngcd(vector<T> a){
    T res;
    res = a[0];
    for(int i = 1; i < a.size() && res != 1; i++) {
        res = gcd(a[i], res);
    }
    return res;
}
 
template<typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

template<typename T>
T nlcm(vector<T> numbers) {
    T res;
    res = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
        res = lcm(res, numbers[i]);
    }
    return res;
}


// 素数判定
template<typename T>
bool isPrime(T x){
    T i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
};

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}



// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}


using pint = pair<int, int>;
using pll = pair<ll, ll>;

int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    int x,y;
    cin >> x >> y;
    print(x + y / 2);
}


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

int main()
{
    mt19937_64 mt;

    static unsigned long long H[1000000][26];
    for (int i=0; i<1000000; i++)
        for (int j=0; j<26; j++)
            H[i][j] = mt();

    int N;
    cin>>N;
    vector<string> S(N);
    for (string &s: S)
        cin>>s;

    for (string &s: S)
        reverse(s.begin(), s.end());
    sort(S.begin(), S.end(), [&](const string &a, const string &b){return a.size()<b.size();});

    map<unsigned long long, vector<long long>> M;
    long long ans = 0;
    for (string s: S)
    {
        int C[26] = {};
        for (int i=0; i<(int)s.size(); i++)
            C[s[i]-'a']++;
        unsigned long long h = 0;
        for (int i=0; i<(int)s.size(); i++)
        {
            if (M.count(h)>0)
                for (int j=0; j<26; j++)
                    if (C[j]>0)
                        ans += M[h][j];
            h ^= H[i][s[i]-'a'];
            C[s[i]-'a']--;
        }

        h = 0;
        for (int i=0; i<(int)s.size()-1; i++)
            h ^= H[i][s[i]-'a'];
        if (M.count(h)==0)
            M[h] = vector<long long>(26);
        M[h][s.back()-'a']++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 251840
s = input()
t = input()

s_list = [c for c in s]
t_list = [c for c in t]

s_list.sort()
t_list.sort()

sd = "".join(s_list)
td = "".join(t_list[::-1])

if sd < td:
    print("Yes")
else:
    print("No")



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

using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
//printf("%.12lf\n",mid);
// __builtin_popcount(int) count 1's in binary
int mod = 1000000007;

int mymod(int num){
  if (num< 0){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}

double eps = .0000000001;

int main ()
{
  prep ();
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> thiss = {a, b, c};
  sort(thiss.begin(), thiss.end());
  cout << thiss[0]+thiss[1];
  
  return 0;
}
// in dp problems think: up until here, intervals, or "what if there's 1, 2, 3..."
// in math problems write out equations
// also in math problems to change multiplication/division to addition/subtraction use logs, add/subtract something to make the multiplication easier (like if it's 3*f(x)+2, change it to 3*(f(x)+1)-1)
// if printint pow function, put an (int) or (long long) next to it
// if checked everything check for bugs (like sorting wrong way or not putting a break in a loop)
// if n is 10^7 try brute force if the operations are simple
// if can't do dp do brute force/greedy
// to save time don't copy maps/vectors into variables if it already exists
// only use long long if need to
// if wrong on decimal problem, check if program rounds or if you can round to a certain amt of decimals
// if decimals too, if can subtract instead of divide
// in grid traversal problems check if doing sideways or not
// if TLE try to take away loop
// in recursion looking math problems look at things from the point of view of both sides (the start and the end sections of the recursion)
// think about how many possible answers there are to the problem
// try to set the answer to the problem and see if it's possible (like w/ binary search)
// if it makes it easier use +1 indexing
// think twice when writing things down that you're going to use later
// for conversions think if you can compute them w/ only one conversion 
// if the problem involves two things moving at the same time, see if you can generalise it to just one thing moving (590/B) (1117/C)
// if nt think primes
// see if you can do a pattern of steps to achieve something (1148/C) (1119/C)
// for problems where you're searching for like a pair that requires something, if it's a yes/no prob, don't focus on individual elements if it's too long (593/B)
// if sub-interval requirements, try to reduce problem into prefix array problem (pairwise numbers) (1174/D)
// think from the end of the problem (if this is the result, what is an attribute of it?)
// if repeating action, if good for debugging use function
// if you know you can do bin search to make it easier but can also solve it shorter way, just do bin search

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

int main(){
  string s;
  int count = 0;
  cin >> s;
  int l = (int)s.length();
  for(int i=0; i<(l+1)/2; i++){
    if(s.substr(i, 1) != s.substr(l-i-1, 1)){
      count ++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int n = N % 10;
    if(n == 2 ||n == 4 || n == 5 || n == 7 || n == 9)cout << "hon";
    else if(n == 3)cout << "bon";
    else cout << "pon";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
    ll g = gcd(A, B);
    if(K%g==0) {
        ll s, ca=B/g, cb=A/g;
        ll oa=min(N, K/A), ob=min(N, K/B);
        int i, j;
        for (i=0, j=ob; i<=oa; i++) {
            while ((s=i*A+j*B)>K) j--;
            if (s==K) break;
        }
        while(i<=N && j>=0) {
            ans += fact.comb(N,i)*fact.comb(N,j);
            if(ans > MOD) ans %= MOD;
            i += ca; j -= cb;
        }
    }
    cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<stack>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	char a[100000];
	scanf("%s",a);
	int m;
	m=strlen(a);
	for(int i=0;i<m;i++)
	{
		if(a[i]+n<='Z')
		printf("%c",a[i]+n);
		else
		printf("%c",a[i]+n-26); 
	}
	
 } 

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

int main(){
    int N, i, MIN;
    int sum = 0;
    int div = 0;
    int s[110];
    cin >> N;

    for (i = 1; i <= N; i++){
      cin >> s[i];
      sum += s[i];
      div = div + s[i] % 10;
      if (s[i] % 10 != 0)MIN = min(MIN, s[i]);
    }

    if (div == 0){
      cout << 0 << endl;
    } else if (sum % 10 != 0){
      cout << sum << endl;
    } else {
      cout << sum - MIN << endl;
    }
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N, M := ReadInt(), ReadInt()
	A := ReadInts(N)
	s := make([]int, N+1)
	for i := 0; i < N; i++ {
		s[i+1] = s[i] + A[i]
	}
	m := make(map[int]int)
	for i := 1; i < N+1; i++ {
		m[s[i]%M]++
	}
	ans := 0
	for _, v := range m {
		ans += (v * (v - 1)) / 2
	}
	ans += m[0]
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 9472
#include <stdio.h>
  
int main(){
    int n,k;scanf("%d %d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
    }
    if((n-1)%(k-1)==0) printf("%d",(n-1)/(k-1));
    else printf("%d",(n-1)/(k-1)+1);
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys


input = sys.stdin.readline
def IS(cb): return cb(input().strip())
def IL(cb): return [cb(s) for s in input().strip().split()]
def IR(cb, rows): return [IS(cb) for _ in range(rows)]
def ILL(cb, rows): return [IL(cb) for _ in range(rows)]


def solve():
    K = IS(int)
    S = IS(str)
    if len(S) <= K:
        print(S)
    else:
        print(S[:K] + '...')


solve()


Measured memory_bytes: 9216
// 世界は変わらない
#include <bits/stdc++.h>
#define int long long int
#define eb emplace_back
#define vi vector <int>
#define pii pair <int, int>
#define ff first
#define ss second

using namespace std;

void solve()
{
    int n, d, cnt = 0;
    cin >> n >> d;
    while(n--)  {
        int x, y;
        cin >> x >> y;
        cnt += (sqrt(x*x + y*y) <= d);
    }
    cout << cnt;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MOD 998244353
#define pb push_back
#define ll long long int
#define con 1000000007
using namespace std;


int main()
{    
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     ll i,j,k,n,m;
     ll t;
     string s,s1;
     cin>>s>>s1;
     if(s1.size()>0)
     {
         s1=s1.substr(0,(ll)s1.size()-1);
     }
     else
     {
          cout<<"No";
         return 0;
     }
     if(s1==s)
         cout<<"Yes";
    else
        cout<<"No";
}

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

void fnInput(vector<string>& rvsStrX, vector<string>& rvsStrY)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvsStrX.resize(nMaxSiz);
  rvsStrY.resize(nMaxSiz);

  for (int i = 0; i < nMaxSiz; ++i)
  {
    cin >> rvsStrX[i] >> rvsStrY[i];
    rvsStrX[i] = ' ' + rvsStrX[i];
    rvsStrY[i] = ' ' + rvsStrY[i];
  }
}

int fnLngCmnSubseq(const vector<string>& cnrvsStrX, const vector<string>& cnrvsStrY)
{
  vector<vector<int>> vvnLcsDP;
  for (int i = 0; i < cnrvsStrX.size(); ++i)
  {
    const int nMAXNX = cnrvsStrX[i].size();
    const int nMAXNY = cnrvsStrY[i].size();

    vvnLcsDP.clear();
    vvnLcsDP.resize(nMAXNX, vector<int>(nMAXNY, 0));

    for (int nx = 1; nx < nMAXNX; ++nx)
      for (int ny = 1; ny < nMAXNY; ++ny)
        if (cnrvsStrX[i][nx] == cnrvsStrY[i][ny])
          vvnLcsDP[nx][ny] = vvnLcsDP[nx - 1][ny - 1] + 1;
        else
          vvnLcsDP[nx][ny] = max(vvnLcsDP[nx - 1][ny], vvnLcsDP[nx][ny - 1]);

    cout << vvnLcsDP[nMAXNX - 1][nMAXNY - 1] << endl;
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<string> vsStrX, vsStrY;

  fnInput(vsStrX, vsStrY);
  fnLngCmnSubseq(vsStrX, vsStrY);
  return 0;
}

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

int main(){
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int price = 0;
  int count = 0;
  for(int i = 0; i < A+1; i++){
    for(int j = 0; j < B+1; j++){
      for(int k = 0; k < C+1; k++){
        price = i * 500 + j * 100 + k * 50;
        if(price == X) count++;
      }
    }
  }
  cout << count << endl;
}
  

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


int main()
{
    long long i,j,n,x,y,d,c=0;

    cin >> n >> d ;
    double a[n+1];
    for(i=0;i<n;i++)
    {
        cin >> x >> y;
        a[i]= sqrt((x*x)+(y*y));
    }
    for(i=0;i<n;i++)
    {
        if(a[i]<=d)
            c++;
        
    }
    cout << c << endl;

}

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

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
template<typename T> void read_vec(vector<T>& v);
void write();
template<typename First, typename... Rest> void write(First& first, Rest&... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    ll N, K;
    read(N, K);
    vector<ll> h(N);
    read_vec(h);
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(h[i] >= K) ans++;
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列として入力を受け取る
template<typename T>
void read_vec(vector<T>& v){
    for(size_t i = 0; i < v.size(); i++){
        cin >> v[i];
    }
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First& first, Rest&... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

Measured memory_bytes: 1024
// 解き直し.
// AtcoderRegularContest解説
// https://img.atcoder.jp/arc098/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
LL A[200002], CUM[200002], XOR[200002];

int main(){

    // 1. 入力情報取得.
    int N;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++){
        scanf("%lld", &A[i]);
        CUM[i] = CUM[i - 1] + A[i];
        XOR[i] = XOR[i - 1] ^ A[i];
    }
    
    // 2. 解説通り.
    // 条件を満たす 整数の組(l, r) の 個数 を計算(※尺取り法っぽいロジックを使えるとのこと).
    LL ans = 0;
    int l = 1, r = 1;
    int counter = 0;
    while(l <= N){
        while(r <= N){
            // 2-1. 整数の組(l, r) に 対応する和, 排他的論理和を取得.
            LL Add = CUM[r] - CUM[l - 1];
            LL Xor = XOR[r] ^ XOR[l - 1]; // 変数名: xor だと, Compile error となった.
            
            // 2-2. 条件を満たすか確認.
            if(Add == Xor) ans += (r - l + 1);
            else           break;
            
            // 2-3. r を increment.
            r++;
            
            // 2-4. debug用.
            counter++;
            if(counter > 200002) break;
            
        }
        
        // 2-6. l を increment.
        l++;
        
    }
    
    // 3. 出力 ～ 後処理.
    printf("%lld\n", ans);
    return 0;

}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,ans=0;
	cin >> n;
	for(int i=1;i<=n;i+=2){
		int temp=0;
		for(int j=1;j*j<=i;j++){
			if(i%j == 0) temp+=2;
		}
		if(temp == 8) ans++;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 384
/*Author : Kartik Bansal
 *Date : 02/08/19
 *Time : 17:46 */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
#define tc int t ;cin>>t ;while(t--)
#define pb push_back
#define FOR(i,n) for(int i =0;i<n;i++)
#define Sort(v) sort(v.begin() ,v.end())
#define vi  vector<int>
int32_t main()
{
  ios::sync_with_stdio(0) ;
  cin.tie(0) ; cout.tie(0) ;
  int n ;
  cin>>n ;
  vi v(n+1) ;
  v[0] = 0 ;
  for(int i=1 ;i<=n;i++)
    cin>>v[i] ;
      vi dp(n+1) ;
  dp[0]= 0 ;
  dp[1] = 0 ;
  dp[2] = abs(v[2]-v[1]) ;
  // cout<<dp[1]  ;
  for (int i =3 ; i<=n;i++)
  {
    // for(int j = 1 ;j<=2 ;j++)
    // {
      dp[i] = min(dp[i-1]+abs(v[i] - v[i-1]) , dp[i-2]+ abs(v[i] - v[i-2])   ) ;
    // }
  }
  cout<<dp[n] ;

}


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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HI;
typedef priority_queue<int, vector<int>, greater<int> > HDI;

const int N = 100010, M = 1010;

int n, m;
int a[N];

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i ++ ) cin >> a[i];
	
	int res = 0;
	for (int l = 0; l <= min(n, m); l ++ )
		for (int r = 0; r <= min(n - l, m - l); r ++ )
		{
			int t = m - l - r, sum = 0;
			HDI heap;
			for (int i = 0; i < l; i ++ )
			{
				heap.push(a[i]);
				sum += a[i];
			}
			for (int i = n - 1; i >= n - r; i -- )
			{
				heap.push(a[i]);
				sum += a[i];
			}
			while (t > 0 && heap.size() && heap.top() < 0)
			{
				sum -= heap.top();
				heap.pop();
				t -- ;
			}
			res = max(res, sum);
		}
		
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	//static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	
	
	//for(int i=0;i<N;i++) {}
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		int N=sc.nextInt();
		int A=sc.nextInt();
		int B=sc.nextInt();
		p(Math.min(N*A, B));
		
		
	}
	

	
	
	
	

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21972
n = int(input())
a = [int(i) - 1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
sum = 0
prev = 100
for i in range(n):
    sum += b[a[i]]
    if a[i] - 1 == prev:
        sum += c[prev]
    prev = a[i]
print(sum)


Measured memory_bytes: 3060
class Dice
    def initialize(array)
        @ary = array
    end

    def move(dir)
        case
        when dir == "N"
            @ary = [@ary[1], @ary[5], @ary[2], @ary[3], @ary[0], @ary[4]]
        when dir == "S"
            @ary = [@ary[4], @ary[0], @ary[2], @ary[3], @ary[5], @ary[1]]
        when dir == "W"
            @ary = [@ary[2], @ary[1], @ary[5], @ary[0], @ary[4], @ary[3]]
        when dir == "E"
            @ary = [@ary[3], @ary[1], @ary[0], @ary[5], @ary[4], @ary[2]]
        end
    end

    def ret
        p @ary[0]
    end
end
array = gets.split.map(&:to_i)
directions = gets.split("").map(&:to_s)

dice = Dice.new(array)
directions.size.times do |i|
    dice.move(directions[i])
end
dice.ret


Measured memory_bytes: 6876
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        boolean[] field = new boolean[h * w];
        ArrayDeque<Integer> deq = new ArrayDeque<>();
        for (int i = 0; i < h; i++) {
            char[] arr = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                if (arr[j] == '#') {
                    field[i * w + j] = true;
                    deq.add(i * w + j);
                }
            }
        }
        ArrayDeque<Integer> next = new ArrayDeque<>();
        int count = 0;
        while (deq.size() > 0) {
            count++;
            while (deq.size() > 0) {
                int x = deq.poll();
                if (x - w >= 0) {
                    if (!field[x - w]) {
                        next.add(x - w);
                        field[x - w] = true;
                    }
                }
                if (x + w < h * w) {
                    if (!field[x + w]) {
                        next.add(x + w);
                        field[x + w] = true;
                    }
                }
                if (x % w > 0) {
                    if (!field[x - 1]) {
                        next.add(x - 1);
                        field[x - 1] = true;
                    }
                }
                if (x % w < w - 1) {
                    if (!field[x + 1]) {
                        next.add(x + 1);
                        field[x + 1] = true;
                    }
                }
            }
            ArrayDeque<Integer> tmp = next;
            next = deq;
            deq = tmp;
        }
        System.out.println(count - 1);
   }
}

Measured memory_bytes: 76264
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
using i64 = long long;

int main()
{
  i64 a, n, m;
  cin >> a >> n >> m;
  i64 ans = 0;
  for (i64 i = 1; i <= sqrt(m); i++)
  {
    i64 p = 1;
    for (i64 j = 0; j < n; j++)
      p *= i;
    if (m < p)
      break;
    string s = to_string(p);
    i64 sum = 0;
    for (i64 j = 0; j < s.size(); j++)
      sum += s[j] - '0';
    if (sum + a == i)
      ans++;
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3224
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
int main()
{
	long long int i,n,p=0,j;
	map<string,long long int>cnt;
	map<string, long long int>::iterator itr;
	cin>>n;
	//string s[n];
//	for(i=0;i<n;i++)
//		cin>>s[i];
	for(i=0;i<n;i++)
		{
			int sum=0;
			string s;
			cin>>s;
			sort(s.begin(), s.end());
		//	for(j=0;j<10;j++)
		//		sum+=s[j]-'a';
			cnt[s]++;	
		}
		for(itr=cnt.begin();itr!=cnt.end();itr++)
			{
				p+=itr->second*(itr->second-1)/2;
			}
	cout<<p<<endl;
}

Measured memory_bytes: 11420
/// input macro from https://qiita.com/tanakh/items/1ba42c7ca36cd29d0ac8
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 : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
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 ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ 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 ) * } } ; }

fn manhattan(a: (usize, usize), b: (usize, usize)) -> usize {
    let x_dist = a.0.max(b.0) - a.0.min(b.0);
    let y_dist = a.1.max(b.1) - a.1.min(b.1);

    return x_dist + y_dist;
}

fn solve() {
    input!(n: usize, xy: [(i64, i64); n]);

    let z_max = {
        let (x, y) = xy
            .iter()
            .max_by(|&a, &b| (a.0 + a.1).cmp(&(b.0 + b.1)))
            .unwrap();
        x + y
    };
    let z_min = {
        let (x, y) = xy
            .iter()
            .min_by(|&a, &b| (a.0 + a.1).cmp(&(b.0 + b.1)))
            .unwrap();
        x + y
    };

    let w_max = {
        let (x, y) = xy
            .iter()
            .max_by(|&a, &b| (a.0 - a.1).cmp(&(b.0 - b.1)))
            .unwrap();
        x - y
    };
    let w_min = {
        let (x, y) = xy
            .iter()
            .min_by(|&a, &b| (a.0 - a.1).cmp(&(b.0 - b.1)))
            .unwrap();
        x - y
    };

    let z = z_max - z_min;
    let w = w_max - w_min;

    println!("{}", z.max(w));
}
fn main() {
    std::thread::Builder::new()
        .name("solve".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}


Measured memory_bytes: 3988
#include<stdio.h>

int main(){
    int N,i,count=0;
    int a[100001];
    scanf("%d",&N);
    for(i=1;i<=N;i++){
        scanf("%d",&a[i]);
    }

    for(i=1;count<100001;){
        if(i==2) break;
        i=a[i];
        count++;        
    }
    if(count==100001) printf("-1\n");
    else printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
#define MOD 1000000007

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int r, g, b; cin >> r >> g >> b;
	if ((100*r + 10*g + b) % 4 == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i = a; i<n; i++)
#define per(i,a,n) for (int i = n-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define all(now) (now).begin(),(now).end()
#define fi first
#define se second
#define SZ(now) ((int)(now).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod = 1000000007;
inline int read(int &n){char c=getchar();int x=0,f=1;while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}return n = x*f;}
ll powmod(ll a,ll b,ll mod) {ll res = 1; a%=mod; assert(b>=0); for(;b; b>>=1){if(b&1)res = res*a%mod; a = a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N = 1e5+7;
int T,n,m;
int a[N];
int main()
{
    //ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    while(~scanf("%d%d",&n,&m))
    {
        rep(i, 1, n + 1) scanf("%d", a + i);
        int ans = (n - 1) / (m - 1);
        if((n-1)%(m-1)!=0) ans++;
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 640
mod = 10 ** 9 + 7
s = input()
n = len(s)
dp = [[0] * 13 for _ in range(n + 1)]
dp[0][0] = 1

numbers = list(range(10))
for i in range(n):
    next_nums = numbers if s[i] == '?' else [int(s[i])]
    for j in range(13):
        for k in next_nums:
            jj = (10 * j + k) % 13
            dp[i + 1][jj] = (dp[i + 1][jj] + dp[i][j]) % mod
print(dp[n][5])



Measured memory_bytes: 95424
#include <bits/stdc++.h>
using namespace std ;
int main()
{
    string x,dw[8]{"","SAT","FRI", "THU" , "WED" , "TUE" , "MON" , "SUN"} ;
    cin >> dw[0] ;
         if(dw[0] == dw[1])
        cout << 1 ;
    else if(dw[0] == dw[2])
        cout << 2 ;
    else if(dw[0] == dw[3])
        cout << 3 ;
    else if(dw[0] == dw[4])
        cout << 4 ;
    else if(dw[0] == dw[5])
        cout << 5 ;
    else if(dw[0] == dw[6])
        cout << 6 ;
    else if(dw[0] == dw[7])
        cout << 7 ;

    return 0 ;
}


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

int main(void){
    int n, m, x, cnt = 0;
    cin >> n >> m >> x;
    vector<int> costs(m);
    for (int i=0; i<m; i++) cin >> costs[i];
    for (int i=0; i<m; i++){
        if (costs[i] < x) cnt++;
        else break;
    }
    cout << min(cnt, m-cnt) << endl;
    return 0;
}

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

int main(){
  int i,j,cnt;
  ll n;
  cin>>n;
  for(i=(int)sqrt(n)+1;i>=1;i--){
    if(n%i==0){
      cout<<i+n/i-2;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>
#include <tuple>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int h,w;cin>>h>>w,h|w;){
		vs grid(h);
		rep(i,h) cin>>grid[i];
		string p; cin>>p;
		
		vvi t(h,vi(w,INFTY));
		queue<tuple<int,int,int>> q;
		rep(i,h) rep(j,w) if(grid[i][j]=='A')
			q.emplace(i,j,0);
		while(!q.empty()){
			auto cur=q.front(); q.pop();
			int ci=get<0>(cur),cj=get<1>(cur),ct=get<2>(cur);
			if(ci<0 || h<=ci || cj<0 || w<=cj || grid[ci][cj]=='#' || t[ci][cj]!=INFTY)
				continue;
			t[ci][cj]=ct;
			rep(i,4) q.emplace(ci+"\xff\x1\0\0"[i],cj+"\0\0\xff\x1"[i],ct+1);
		}
		
		int ci=-1,cj=-1;
		rep(i,h) rep(j,w) if(grid[i][j]=='B')
			ci=i,cj=j;
		int res=INFTY;
		pii pos;
		for(int ct=0,i=0;ct<1e6;ct++,i=(i+1)%p.size()){
			if(ct>=t[ci][cj]){
				res=ct;
				pos=mp(ci,cj);
				break;
			}
			int ni=ci,nj=cj;
			if(p[i]=='8') ni--;
			if(p[i]=='2') ni++;
			if(p[i]=='4') nj--;
			if(p[i]=='6') nj++;
			if(0<=ni && ni<h && 0<=nj && nj<w)
				ci=ni,cj=nj;
		}
		
		if(res==INFTY)
			cout<<"impossible"<<endl;
		else
			cout<<res<<' '<<pos.first<<' '<<pos.second<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007 //S(vector).size()
using namespace std;
typedef long long ll;

int dp[50];

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

	dp[0] = 1;
	dp[1] = 1;
	for(int i = 2; i <= n; i++)	dp[i] = dp[i - 1] + dp[i - 2];
	
	cout << dp[n] << endl;
	return 0;
}



Measured memory_bytes: 3092
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============
using PQ = priority_queue<pii>;

ll solveLeftSide(
    const vector<vector<ll>>& klr,
    PQ pqL
) {
    const int N = klr.size();
    ll res = 0;
    set<int> seat;
    rep(i, N) seat.insert(i);
    while (!pqL.empty()) {
        auto idx = pqL.top().second; pqL.pop();
        auto K = klr[idx][0];
        auto itr = seat.upper_bound(K);
        if (itr == seat.begin()) {
            res += klr[idx][2];
        }
        else {
            res += klr[idx][1];
            --itr;
            seat.erase(itr);
        }
    }
    return res;
}

ll solveRightSide(
    const vector<vector<ll>>& klr,
    PQ pqR
) {
    const int N = klr.size();
    ll res = 0;
    set<int> seat;
    rep(i, N)seat.insert(i);
    while (!pqR.empty()) {
        auto idx = pqR.top().second; pqR.pop();
        auto K = klr[idx][0] + 1;
        auto itr = seat.lower_bound(K);
        if (itr == seat.end()) {
            res += klr[idx][1];
        }
        else {
            res += klr[idx][2];
            seat.erase(itr);
        }
    }
    return res;
}

int main()
{
    int T;
    cin >> T;
    rep(t, T) {
        int N;
        cin >> N;
        vector<vector<ll>> klr(N);
        rep(i, N) {
            ll k, l, r;
            cin >> k >> l >> r;
            k--;
            klr[i] = { k,l,r };
        }

        PQ pqL, pqR;
        rep(i, N) {
            auto diff = klr[i][1] - klr[i][2];
            if (diff >= 0) pqL.push({ diff, i });
            else pqR.push({ -diff,i });
        }
        ll res = solveLeftSide(klr, pqL) + solveRightSide(klr, pqR);
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 26684
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string input[3];
	int S[3];
	int i[3];
	i[0] = i[1] = i[2] = 0;
	int n, m;
	n = m = 0;
	cin >> input[0] >> input[1] >> input[2];
	S[0] = input[0].size();
	S[1] = input[1].size();
	S[2] = input[2].size();

	while (S[0] > 0 && S[1] > 0 && S[2] > 0)
	{
		switch (input[n][m])
		{
		case 'a':
			S[n]--;
			i[n]++;
			n = 0;
			m = i[0];
			break;
		case 'b':
			S[n]--;
			i[n]++;
			n = 1;
			m = i[1];
			break;
		case 'c':
			S[n]--;
			i[n]++;
			n = 2;
			m = i[2];
			break;
		}

		for(int j = 0;j < 3;j++)
			if (S[j] <= 0)
			{
				cout << char('A' + j) << endl;
				break;
			}
	}

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,i,j,k;
  
  scanf("%d",&N);
  
  for(i = 0;i <= N;i+=7){
    j = N - i;
    if(j % 4 == 0){
      puts("Yes");
      return 0;
    }
  }
  puts("No");
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> z(3);
  int x,i;
  cin>>z.at(0)>>z.at(1)>>z.at(2)>>x;
  sort(z.begin(),z.end());
  for(i=0;i<x;i++) z.at(2)*=2;
  cout<<z.at(0)+z.at(1)+z.at(2)<<endl;
}

Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque

# 右端のアルファベット：左端にもっていくとしてよい

S = [None] + [int(x) - ord('a') for x in read().rstrip()]

class BinaryIndexedTree():
    def __init__(self, seq):
        self.size = len(seq)
        self.depth = self.size.bit_length()
        self.build(seq)
        
    def build(self,seq):
        data = seq
        size = self.size
        for i,x in enumerate(data):
            j = i+(i&(-i))
            if j < size:
                data[j] += data[i]
        self.data = data
        
    def __repr__(self):
        return self.data.__repr__()
        
    def get_sum(self,i):
        data = self.data
        s = 0
        while i:
            s += data[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        data = self.data
        size = self.size
        while i < size:
            data[i] += x
            i += i & -i
    
    def find_kth_element(self,k):
        data = self.data; size = self.size
        x,sx = 0,0
        dx = 1 << (self.depth)
        for i in range(self.depth - 1, -1, -1):
            dx = (1 << i)
            if x + dx >= size:
                continue
            y = x + dx
            sy = sx + data[y]
            if sy < k:
                x,sx = y,sy
        return x + 1

N = len(S) - 1
close = [False] * (N+1)

x_to_I = [deque() for _ in range(26)]
for i,x in enumerate(S[1:],1):
    x_to_I[x].append(i)

counter = [len(I) for I in x_to_I]
odd_cnt = sum(x&1 for x in counter)
if odd_cnt >= 2:
    print(-1)
    exit()

find_center = False
bit = BinaryIndexedTree([0] * (N+1))

answer = 0
for r in range(N,0,-1):
    x = S[r]
    bl = close[r]
    if bl:
        continue
    l = x_to_I[x][0]
    if l == r:
        find_center = True
        continue
    x_to_I[x].pop()
    x_to_I[x].popleft()
    costR = 1 if find_center else 0
    costL = l - 1 - bit.get_sum(l)
    bit.add(l,1)
    bit.add(r,1)
    close[l] = True
    answer += costL + costR

print(answer)

Measured memory_bytes: 17616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

template <class T>
inline bool chmax(T& a, T b) {
    return a = (a < b) ? b : a;
}
template <class T>
inline bool chmin(T& a, T b) {
    return a = (a > b) ? b : a;
}

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

struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}

    mint operator-() const { return mint(-x); }

    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(MOD - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;

        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    // 順列の計算
    mint p(int n, int k) { return fact[n] * ifact[n - k]; }
};

int main() {
    INIT;

    ll X, Y;
    cin >> X >> Y;

    combination comb(1000005);

    if (2 * X - Y < 0 || 2 * Y - X < 0) {
        cout << 0 << endl;
        return 0;
    }

    if (!((2 * X - Y) % 3 == 0 && (2 * Y - X) % 3 == 0)) {
        cout << 0 << endl;
        return 0;
    }

    ll a = (2 * Y - X) / 3;
    ll b = (2 * X - Y) / 3;
    ;
    cout << comb(a + b, a) << endl;

    return 0;
}

Measured memory_bytes: 18768