akhauriyash/Code-Regression huggingface dataset:
// #include C {
#include<cstring>
#include<cassert>
#include<cstdio>
#include<cctype>
#include<cmath>
// }

// #include C++ {
#include<functional>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<map>
#include<set>
// }

using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 100005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
int p[MAX_N];
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
//  WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);
	vector <PII> V;
	while (N--) {
		int a, b;
		scanf("%d %d", &a, &b);
		V.emplace_back(a, b);
	}
	sort(ALL(V));
	int left = NONE, right = NONE;
	int res = 0;
	for (PII p : V) {
		if (p.X <= right + 1) {
			right = p.Y;
		}
		else {
			if(left != NONE)
				res += right - left + 1;
			left = p.X;
			right = p.Y;				
		}
	}
	res += right - left + 1;
	printf("%d\n", res);
}

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

// 許容誤差
const double EPS = 1e-10;
bool equals(double a, double b) {
    return fabs(a - b) < EPS;
}

// 点とベクトル
class Point {
 public:
    double x, y;
    explicit Point(double x = 0, double y = 0): x(x), y(y) {}
    Point operator+(const Point p) const {
        return Point(x + p.x, y + p.y);
    }
    Point operator-(const Point p) const {
        return Point(x - p.x, y - p.y);
    }
    Point operator*(double a) const {
        return Point(a * x, a * y);
    }
    Point operator/(double a) const {
        return Point (x / a, y / a);
    }
    double norm() {
        return x * x + y * y;
    }
    double abs() {
        return sqrt(norm());
    }
    bool operator<(const Point &p) const {
        return x != p.x ? x < p.x : y < p.y;
    }
    bool operator==(const Point &p) const {
        return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
    }
    bool operator!=(const Point &p) const {
        return !(fabs(x - p.x) < EPS && fabs(y - p.y) < EPS);
    }
    Point rotate(double deg) {
        double th = M_PI * (deg / 180.0);
        return Point(x * cos(th) - y * sin(th), x * sin(th) + y * cos(th));
    }
};

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

    int N;
    cin >> N;
    vector<Point> V;
    for (int i = 0; i < N; i++) {
        Point p;
        cin >> p.x >> p.y;
        V.push_back(p);
    }
    int64_t k = 1;
    for (int i = 2; i <= N - 1; i++) k *= i;
    double avg = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            avg += (V[i] - V[j]).abs() * k * 2;
        }
    }
    double ret = avg / (k * N);
    cout << fixed << setprecision(10) << ret << endl;

    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0

for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if i*500+j*100+k*50 == x:
        count += 1
        
print(count)
      

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MIN2(x,y)	((x)<(y)?(x):(y))
#define ABS(x)		((x)<0 ? -(x):(x))


int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(){
    int     x, n, xi, flag1=0, flag2=0, flag3=0, min=999;   //min:現状最も小さい差分
    int     p[100+1] = { 0};
    int     min_p[2] = {-1}; //複数存在するのは、プラス側かマイナス側かの二択

    scanf("%d %d", &x, &n);
    if( n==0 ){ printf("%d", x); return 0; }

    //取得とソート
    for(int i=0; i<n; i++){ scanf("%d", &p[i]); }
    qsort( p, n, sizeof(int), compare_int );

    //x自身の場合（数列にxがない）
    for(int i=0; i<n; i++){
        if( p[i] == x ){ flag1=1; break; }
    }
    if( flag1==0 ){ printf("%d\n", x); return 0; }

    //その他（数列にxがいる）
    for(int j=1; j<100; j++){
        flag2=0;
        flag3=0;
        for(int k=0; k<n; k++){
            if( p[k] == x-j ){ flag2=1; }   //マイナス方向に同じ値がいた
            if( p[k] == x+j ){ flag3=1; }   // プラス方向に同じ値がいた
        }
        //2つ存在したので小さい方を
        if     ( flag2==0 && flag3==0 ){ printf("%d\n", x-j); return 0; }
        else if( flag2==0             ){ printf("%d\n", x-j); return 0; }
        else if( flag3==0             ){ printf("%d\n", x+j); return 0; }
    }
    return 0;
}

Measured memory_bytes: 1704
class Node():
    def __init__(self, parent = -1, left = -1, right = -1):
        self.parent = parent
        self.left = left
        self.right = right

def preorder(ns, i):
    print(" " + str(i), end ="")
    if ns[i].left != -1:
        preorder(ns, ns[i].left)
    if ns[i].right != -1:
        preorder(ns, ns[i].right)

def inorder(ns, i):
    if ns[i].left != -1:
        inorder(ns, ns[i].left)
    print(" " + str(i), end ="")
    if ns[i].right != -1:
        inorder(ns, ns[i].right)

def postorder(ns, i):
    if ns[i].left != -1:
        postorder(ns, ns[i].left)
    if ns[i].right != -1:
        postorder(ns, ns[i].right)
    print(" " + str(i), end ="")
    
    
n = int(input())
ns = [Node() for i in range(n)]
for i in range(n):
    p, l, r = map(int, input().split())
    if l != -1:
        ns[p].left = l
        ns[l].parent = p
    if r != -1:
        ns[p].right = r
        ns[r].parent = p

for i in range(n):
    if ns[i].parent == -1:
        print("Preorder")
        preorder(ns, i)
        print()
        print("Inorder")
        inorder(ns, i)
        print()
        print("Postorder")
        postorder(ns, i)
        print()


Measured memory_bytes: 5612
#pragma GCC optimize(2)
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define PI atan(1.0)*4
#define E 2.718281828
#define rp(i,s,t) for (register int i = (s); i <= (t); i++)
#define RP(i,t,s) for (register int i = (t); i >= (s); i--)
#define ll long long
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define debug printf("ac\n");
using namespace std;
inline int read()
{
    int a=0,b=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
            b=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        a=(a<<3)+(a<<1)+c-'0';
        c=getchar();
    }
    return a*b;
}
const int INF = 0x3f3f3f3f;
const int N = 2e5+7;
int a[N];
int main(){
    int n=read();
    rp(i,1,n) a[i]=read();
    ll ans=0;
    for(int l=1,r=0,now=0;l<=n;){
        while(r<=n&&(now^a[r])==now+a[r]) now+=a[r++];
        ans+=r-l;
        now^=a[l++];
    }
    cout<<ans<<endl;
    return 0;
}
/*
1 1
1 2
2 2
2 3
2 4
3 3
3 4
4 4
4 5
4 6
4 7
5 5
5 6
5 7
6 6
6 7
6 8
7 7
7 8
8 8
9 9
10 10
10 11
10 12
11 11
11 12
12 12
13 13
14 14
14 15
14 16
15 15
15 16
16 16
17 17
18 18
19 19
37
*/

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

typedef long long int ll;
#define int ll

ll N, S, W, Q;
vector<int> A;

void solve(){
    vector<int> S(N+1);
    int k = 1;
    for(int i=N-1; i>=0; i--){
        S[i] = (k*A[i] + S[i+1]) % Q;
        k = k*10LL % Q;
    }
    
    int ans = 0;
    if(Q != 2 && Q != 5){
        map<int, int> mp;
        for(int i=0; i<=N; i++){
            ans += mp[S[i]];
            if(A[i]) mp[S[i]]++;
        }
//        for(int i=0;i<N;i++){
//            if( A[i] ) mp[S[i]]++;
//            ans += mp[ S[i+1] ];
//        }
    }else{
        int cnt = 0;
        for(int i=0; i<N; i++){
            if(A[i]) cnt++;
            if(A[i] % Q == 0)
                ans += cnt;
        }
    }
    cout << ans << endl;
}

signed main(){
    while (cin >>N>>S>>W>>Q, N|S|W|Q) {
        A.clear(); A.resize(N);
        int g = S;
        for(int i=0; i<N; i++) {
            A[i] = (g/7) % 10;
            if( g%2 == 0 ) { g = (g/2); }
            else           { g = (g/2) ^ W; }
        }
        solve();
    }
    
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

const int maxn = 1e5+10;
const int mod = 1e9+7;

using namespace std;

void solve(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans = n/(a+b)*a;
    ans = ans + min(a,n%(a+b));
    cout<<ans<<endl;
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3624
line = input().split()
import fractions
lcm = (int(line[2])*int(line[3]) //fractions.gcd(int(line[2]),int(line[3])))
 
pos_c = int(line[1])//int(line[2]) 
pos_d = int(line[1])//int(line[3])
pos_lcm = int(line[1])//lcm
 
pos_c1 = (int(line[0])-1)//int(line[2])
pos_d1 = (int(line[0])-1)//int(line[3])
pos_lcm1 = (int(line[0])-1)//lcm
 
b = int(line[1]) - pos_c - pos_d + pos_lcm
a = int(line[0]) - 1 - pos_c1 - pos_d1 + pos_lcm1
 
print(b-a)

Measured memory_bytes: 5104
/*  ex3_2
    potter0723sw  */

#include <stdio.h>

int main(void) {
	int number,poo;
	scanf("%d", &number);
	poo = number % 10; //pooはplace of oneの略
	if(poo == 2 || poo == 4 || poo == 5 || poo == 7 || poo == 9){//１の位を参照するために%10をした
		printf("hon\n");
	}else if(poo == 0 || poo == 1 || poo == 6 || poo == 8){
		printf("pon\n");
	}else printf("bon\n");
	return 0;
}


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

int main(){
  int A,B;
  int N = 0;
  cin >> A >> B;
  while(A <= B){
    if(A%10 == A/10000 && (A%100-A%10)/10 == (A/1000-(A/10000)*10)){
      N++;
    }
    A += 1;
  }
  cout << N << endl;
}

Measured memory_bytes: 256
class Segmenttree_max():
    def __init__(self, number):
        n = 1
        while n < number:
            n *= 2
        self.n = n
        self.list = [0] * (2 * n - 1)

    def add(self, i, x):  # 0indexed ith add x
        i += self.n - 1
        self.list[i] = x
        while i > 0:
            i = (i - 1) // 2
            self.list[i] = max(self.list[2 * i + 1], self.list[2 * i + 2])

    def search(self, a, b, k, l, r):  # call as search(a,b,0,0,self.n) maximum in [a,b)
        if r <= a or b <= l:
            return 0
        elif a <= l and r <= b:
            return self.list[k]
        else:
            vl = self.search(a, b, 2 * k + 1, l, (l + r) // 2)
            vr = self.search(a, b, 2 * k + 2, (l + r) // 2, r)
            return max(vl, vr)


N = int(input())
H = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
tree = Segmenttree_max(N)
dp = [0] * (N + 1)
for i in range(1, N + 1):
    dp[i] = tree.search(0, H[i - 1] - 1, 0, 0, tree.n) + A[i - 1]
    tree.add(H[i - 1] - 1, dp[i])
ans=0
for i in range(N+1):
    ans=max(ans,dp[i])
print(ans)

Measured memory_bytes: 122960
#include <bits/stdc++.h>
#define eps 1e-8
using namespace std;
const int maxn = 100;
int V,n,X,Y;
double vx,vy;
double g=9.8;
int L[maxn],B[maxn],R[maxn],T[maxn];
double calc(double t)
{
    return vy*t-g*t*t/2;
}
int cmp(double l,double h,double x)
{
    return x<l+eps?-1:x>h-eps?1:0;
}
bool f(double qx,double qy)
{
    double a=g*g/4,b=g*qy-V*V,c=qx*qx+qy*qy;
    double d=b*b-4*a*c;
    if(d<0 && d>-eps) d=0;
    if(d<0) return false;
    for(int tmp=-1; tmp<=1; tmp+=2)
    {
        double t=(-b+tmp*sqrt(d))/(2*a);
        if(t<=0) continue;
        t=sqrt(t);
        vx=qx/t;if(fabs(vx)<eps) vx=eps;
        vy=(qy+g*t*t/2)/t;
        double temp=X/vx;
        double qyy=calc(X/vx);

        if(qyy<Y-eps)
        {
            continue;
        }
        bool ok=true;
        for(int i=0; i<n; i++)
        {
            if(L[i]>=X) continue;
            if(R[i]==X && Y<=T[i] && B[i]<=qyy) ok=false;
            int yl=cmp(B[i],T[i],calc(L[i]/vx));
            int yr=cmp(B[i],T[i],calc(R[i]/vx));
            int xh=cmp(L[i],R[i],vx*vy/g);
            int yh=cmp(B[i],T[i],calc(vy/g));

            if(xh==0 && yh>=0 && yl<0) ok=false;
            if(yl*yr<=0) ok=false;
        }
        if(ok) return true;
    }
    return false;
}
int main()
{
    cin>>n>>V>>X>>Y;
    for(int i=0; i<n; i++) cin>>L[i]>>B[i]>>R[i]>>T[i];
    for(int i=0;i<n;i++) R[i]=min(R[i],X);
    bool ans = f(X,Y);

    for(int i=0; i<n; i++)
    {
        ans |=f(L[i],T[i]);
        ans |=f(R[i],T[i]);
    }
    puts(ans?"Yes":"No");
    return 0;
}
/*
0 7 3 1

1 7 3 1
1 1 2 2

1 7 2 2
0 1 1 2
1 1 2 2


*/



Measured memory_bytes: 3100
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    long long n, a, b, x1, x2;
    scanf("%lld%lld%lld", &n, &a, &b);
    x1=a;x2=b;
    for(int i=0;i<n-1;i++)
    {
        scanf("%lld%lld", &a, &b);
        long long temp=x1/a;
        if(x1%a!=0)
            temp++;
        long long temp2=x2/b;
        if(x2%b!=0)
            temp2++;
        long long m=max(temp, temp2);
        x1=a*m;x2=b*m;
    }
    printf("%lld\n", x1+x2);
    return 0;
} 


Measured memory_bytes: 128
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl //[l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<endl;out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

string s,t;
map<char,char> src,tgt;

signed main(){
    io();

    in(s,t);
    int cnt=0;
    rep(i,s.size()){
        //show(i,s[i],src[s[i]]);
        if(src[s[i]]){
            s[i]=src[s[i]];
        }else{
            src[s[i]]='a'+cnt;
            s[i]='a'+cnt;
            cnt++;
        }
    }
    //show(s);
    cnt=0;
    rep(i,t.size()){
        //show(i,t[i],tgt[t[i]]);
        if(tgt[t[i]]){
            t[i]=tgt[t[i]];
        }else{
            tgt[t[i]]='a'+cnt;
            t[i]='a'+cnt;
            cnt++;
        }
    }
    //show(s,t);
    if(s==t){
        yes;
    }else{
        no;
    }

    return 0;
}


Measured memory_bytes: 1020
/**
 *    author:  tourist
 *    created: 21.12.2019 18:02:47       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> cc(3, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    ++cc[x - 1];
  }
  vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(n + 1, vector<double>(n + 1)));
  for (int c = 0; c <= n; c++) {
    for (int b = 0; b + c <= n; b++) {
      for (int a = 0; a + b + c <= n; a++) {
        int d = n - a - b - c;
        if (d == n) {
          dp[c][b][a] = 0;
          continue;
        }
        if (c > 0) dp[c][b][a] += dp[c - 1][b + 1][a] * c / n;
        if (b > 0) dp[c][b][a] += dp[c][b - 1][a + 1] * b / n;
        if (a > 0) dp[c][b][a] += dp[c][b][a - 1] * a / n;
        dp[c][b][a] = (dp[c][b][a] + 1) * n / (n - d);
      }
    }
  }
  cout << fixed << setprecision(17) << dp[cc[2]][cc[1]][cc[0]] << '\n';
  return 0;
}


Measured memory_bytes: 216832
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define repk(i,m,n) for(int i=m;i<n;i++)
#define OKawaiiKoto ios::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD1=1e9+7;
const int MOD2=998244353;
const ll INF=2*1e18;
const ld PI=3.14159265358979323846;
ll a[200005];
int main()
{
    OKawaiiKoto
    ll n,cur=0;
    cin>>n;
    rep(i,n)
    {
        cin>>a[i];
        cur^=a[i];
    }
    rep(i,n) cout<<(cur^a[i])<<" ";
}


Measured memory_bytes: 5124
#include <bits/stdc++.h>
using namespace std;
#define N 300010
int n,m,tot=0,root[N],ans[N];
struct node{int x,y;}a[N];
struct seg{int l,r,x;}t[N*100];
inline char gc(){
	static char *S,*T,buf[1<<16];
	if(T==S){T=(S=buf)+fread(buf,1,1<<16,stdin);if(T==S) return EOF;}
	return *S++;
}
inline int read(){
	int x=0,f=1;char ch=gc();
	while(ch<'0' || ch>'9'){if(ch=='-') f=-1;ch=gc();}
	while('0'<=ch && ch<='9') x=x*10+ch-'0',ch=gc();
	return x*f;
}
inline bool cmp(node x,node y){
	return x.x<y.x;
}
inline void ins(int &v,int l,int r,int x){
	t[++tot]=t[v];v=tot;t[v].x++;
	if(l==r) return;
	int mid=l+r>>1;
	if(x<=mid) ins(t[v].l,l,mid,x);
	else ins(t[v].r,mid+1,r,x);
}
inline int query(int v1,int v2,int l,int r,int x,int y){
	if(x<=l && r<=y) return t[v2].x-t[v1].x;
	int mid=l+r>>1,s=0;
	if(x<=mid) s+=query(t[v1].l,t[v2].l,l,mid,x,y);
	if(mid<y) s+=query(t[v1].r,t[v2].r,mid+1,r,x,y);
	return s;
}
int main(){
	n=read();m=read();
	for(int i=1;i<=n;++i){
		a[i].x=read(),a[i].y=read();
	}
	sort(a+1,a+n+1,cmp);
	for(int i=1,j=1;i<=m;++i){
		root[i]=root[i-1];
		while(j<=n && a[j].x==i) ins(root[i],1,m,a[j].y),++j;
	}
//	printf("%d\n",tot); 
//	for(int i=1;i<=m;++i) printf("%d ",root[i]);puts("");
//	for(int i=1;i<=tot;++i) printf("%d %d %d %d\n",i,t[i].l,t[i].r,t[i].x);
	printf("%d\n",n);
	for(int i=2;i<=m;++i){
		for(int j=i;j<=m;j+=i){
			ans[i]+=query(root[j-i],root[j],1,m,j,m);
		}
		printf("%d\n",ans[i]);
	}
	return 0;
}

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

int main(){
  int N,Y,x,y,d;

  cin>>N>>Y;

  d=0;
  for(x=0;x<=N;x++){
    for(y=0;y<=N;y++){
      if((Y==10000*x+5000*y+1000*(N-x-y))&&N-x-y>=0){
        cout<<x<<" "<<y<<" "<<N-x-y<<endl;
        d=1;
        break;
      }
    }
    if(d==1)
    break;
  }

  if(d==0)
  cout<<"-1 -1 -1"<<endl;
}


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

using namespace std;

int main(){
  long long i,j,n=0,num=0,m;
  string s;
  cin >> s;
  for(i=0;i<s.size();i++){
    num += s[i] - '0';
    m=1;
    for(j=0;j<s.size()-i-1;j++){
      m*=10;
    }
    n += (s[i] - '0')*m;
  }
  if(n%num == 0){
    cout << "Yes" << endl;
    //cout << n << num << endl;

  }else{
    cout << "No" << endl;
    //cout << n << num << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char str[50];

int main(int argc, char** argv) {
	cin>>str;
	if(str[0] == 'Y' && str[1] == 'A' && str[2] == 'K' && str[3] == 'I')
		puts("Yes");
	else puts("No");	
	return 0;
}

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

uint64_t pow2(uint64_t x) {
  return static_cast<uint64_t>(1) << x;
}

uint64_t calc(uint64_t x) {
  uint64_t p = std::ceil(std::log2(x + 1));
  return pow2(p);
}

int main() {
  uint64_t n;
  std::cin >> n;
  std::multiset<uint64_t, std::greater<uint64_t>> a;
  for (uint64_t i = 0; i < n; i++) {
    uint64_t t;
    std::cin >> t;
    a.insert(t);
  }

  uint64_t count = 0;

  while (!a.empty()) {
    const auto b = a.begin();
    const auto val = *b;
    const auto pair = calc(val) - val;
    if (val < pair) {
      a.erase(val);
    } else if (val == pair) {
      const auto co = a.count(val);
      if (2 <= co) {
        count += co / 2;
        a.erase(val);
      } else {
        a.erase(val);
      }
    } else {
      const auto cov = a.count(val);
      const auto cop = a.count(pair);
      if (cop != 0) {
        count += std::min(cov, cop);
        a.erase(val);
        a.erase(a.find(pair), std::next(a.find(pair), std::min(cov, cop)));
      } else {
        a.erase(val);
      }
    }
  }

  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 9728
import math
n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]


def get_1_index(a):
    for i,j in enumerate(a):
        if j==1:
            return i


index=get_1_index(a)

mae=index
usiro=n-index-1

# print(math.ceil(mae/(k-1))+math.ceil(usiro/(k-1)))
print(math.ceil((n-1)/(k-1)))

Measured memory_bytes: 20464
from collections import Counter

S = input()
MOD = 2019
redisuals = [0]


for i in range(len(S)):
    s = int(S[-i - 1])
    redisuals.append((redisuals[-1] + s * pow(10, i, MOD)) % MOD)

c = Counter(redisuals)

ans = 0
for k, v in c.items():
    ans += v * (v - 1)

ans //= 2
print(ans)

Measured memory_bytes: 16452
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

int a[N];

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    int c = 0;
    for(int i = 0; i < n; i++){
        if(a[i] == c + 1) c++;
    }
    if(c == 0) cout << -1;
    else cout << n - c;

    return 0;
}


Measured memory_bytes: 4428
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int sum = 0;
  for(int i=0;i<s.length();i++){
    sum += s[i]-'0';
  }
  if(sum%9 == 0)cout<<"Yes\n";
  else cout<<"No\n";
}

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

#define endl putchar('\n')

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

    int a[n], b[n], c[n], p[n];
    c[0]=1;

    for(i=0; i<n; i++)
    {
        scanf("%d", &p[i]);
        if(i>0) c[i]=c[i-1]+n;
    }

    for(i=0; i<n; i++)
    {
        b[i]=c[i];
        a[i]=c[n-1-i];
    }

    for(i=0; i<n; i++) a[p[i]-1]+=i;

    for(i=0; i<n; i++) printf("%d ", b[i]);
    endl;
    for(i=0; i<n; i++) printf("%d ", a[i]);
    return 0;
}


Measured memory_bytes: 2028
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

ll N, M;

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

    priority_queue<
        ll,
        vector<ll>,
        less<ll> >
        que;

    ll a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        que.push(a);
    }

    for (ll i = 0; i < M; i++) {
        ll maxa = que.top();
        que.pop();
        que.push(floor(maxa / 2));
    }

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        ans += que.top();
        que.pop();
    }

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


Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0; i<n; i++)
int main()
{
	int N;
	cin >> N;
	vector<ll> L(N);
	rep(i,N){
		cin >> L[i];
	}

	ll ans = 0;

	sort(L.begin(),L.end());

	for(int i = 0; i<=N-3; i++){
		for(int j = i+1; j<=N-2; j++){
			if(L[i] != L[j]){
				for(int k = j+1; k<=N-1; k++){
					if(L[i]+L[j]<= L[k])
						break;
					if(L[j] != L[k])	
						ans++;
				}
			}
		}
	}

	cout << ans;

	cin >> N;
	
	return 0;	
}


Measured memory_bytes: 3528
N, M = gets.split.map(&:to_i)
E = M.times.map{ gets.split.map(&:to_i) }

G = Array.new(N + 1){ [] }
E.each do |a,b|
  G[a] << b
  G[b] << a
end

P = Array.new(N + 1, 0)
used = Array.new(N + 1)
q = [1]
used[1] = true
until q.empty?
  u = q.shift
  G[u].each do |v|
    next if used[v]
    P[v] = u
    used[v] = true
    q << v
  end
end
puts "Yes"
puts P[2,N - 1]

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<vector<bool>> G(n, vector<bool>(n, false));
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        G.at(a-1).at(b-1) = true;
        G.at(b-1).at(a-1) = true;
    }
    vector<int> v(n-1);
    for (int i=0; i<n-1; ++i) v.at(i) = i+1;
    int res = 0;
    do {
        bool ok = true;
        if (!G.at(0).at(v.at(0))) ok = false;
        for (int i=0; i<n-2; ++i) {
            if (!G.at(v.at(i)).at(v.at(i+1))) {
                ok = false;
                break;
            }
        }
        if (ok) ++res;
    } while (next_permutation(v.begin(), v.end()));
    cout << res << '\n';
}

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

    solve();

    return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
    int n;
    std::cin >> n;
    std::map<std::string, int> verdicts;
    for (size_t i = 0; i < n; i++) {
        std::string inp;
        std::cin >> inp;
        verdicts[inp]++;
    }
    printf("AC x %d\n", verdicts["AC"]);
    printf("WA x %d\n", verdicts["WA"]);
    printf("TLE x %d\n", verdicts["TLE"]);
    printf("RE x %d\n", verdicts["RE"]);
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
int n,k,i,j;
int main()
{   cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
        cin>>a[i];
    vector<long long> dp(n,LONG_MAX);
    dp[0]=0;
    for(i=1;i<n;i++)
    {
        for(j=i-1;j>=0 && abs(j-i)<=k;j--)
            dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


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


int main(){


    int r, d, x, i;


    cin >> r >> d >> x;


    for( i = 0 ; i < 10 ; i = i + 1 ){

         x = r * x - d;

         cout << x << endl;

         }


    return 0;

    }


Measured memory_bytes: 256
// Problem : A - Rainy Season
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*

WINNERS NEVER QUIT AND QUITTERS NEVER WIN!!

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef unordered_map<ll,ll> umll;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF LLONG_MAX/2

int main()
{
    io;
    string s;
    cin>>s;
    ll ans=0,final=0;
    bool prev=false;
    FOR(i,0,3)
    {
    	if(s[i]=='R')
    	{
    		if(prev){ans++;}
    		else{prev=true; ans++;}
    		final=max(final,ans);
    	}
    	else
    	{
    		final=max(final,ans);
    		ans=0;
    		prev=false;
    	}
    }
    final=max(final,ans);
    cout<<final;
    return 0;
}



Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rep(i,N) for(ll i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1


ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n, m, s, g1, g2;
ll dp[200][200];

int main() {
	while (cin >> n >> m >> s >> g1 >> g2&&n + m + s + g1 + g2) {
		s--; g1--; g2--;
		rep(i, n)rep(j, n) {
			if (i != j)dp[i][j] = INF;
		}
		rep(i, m) {
			int b1, b2, c;
			cin >> b1 >> b2 >> c;
			b1--; b2--;
			dp[b1][b2] = c;
		}
		rep(k, n) {
			rep(i, n) {
				rep(j, n) {
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
				}
			}
		}
		ll ans = INF;
		rep(i, n) {
			if (i == s)ans = min(ans, dp[i][g1] + dp[i][g2]);
			else ans = min(ans, dp[s][i] + dp[i][g1] + dp[i][g2]);
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 3132
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    string S; cin >> S;
    int N = (int)S.size();
    vector<ll> R(N+1);
    vector<ll> L(N+1);
    for(int i=0; i<N; i++){
        if(S[i]=='R') R[i+1] = R[i] + 1;
        else R[i+1] = 0;
    }
    
    for(int i=N-1; i>=0; i--){
        if(S[i]=='L') L[i] = L[i+1] + 1;
        else L[i] = 0;
    }
    
    
    vector<ll> ans(N);
    for(int i=0; i<N-1; i++){
        if(S[i]=='R' && S[i+1]=='L'){
            
            if((R[i+1] + L[i+1])%2==0){
                ans[i] = (R[i+1] + L[i+1]) / 2;
                ans[i+1] = (R[i+1] + L[i+1]) / 2;
            }else{
                if((R[i+1]>L[i+1] && (R[i+1]-1)%2==0) || (R[i+1]<L[i+1] && (L[i+1]-1)%2==1)){
                    ans[i] = (R[i+1] + L[i+1] + 1) / 2;
                    ans[i+1] = (R[i+1] + L[i+1]) / 2;
                }else{
                    ans[i] = (R[i+1] + L[i+1]) / 2;
                    ans[i+1] = (R[i+1] + L[i+1] + 1) / 2;
                }
                
            }
        }
    }
    for(int i=0; i<N; i++){
        cout << ans[i] << " ";
    }
    
    cout << endl;

    
    
    return 0;
}





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

int main() {
    int n, m;
    while(cin >> n >> m, n) {
        vector<pair<int, int>> v(m);
        for(int i=1; i<=m; ++i) {
            v[i-1].second = -i;
        }
        for(int i=0; i<n; ++i) {
            for(int j=0; j<m; ++j) {
                int k; cin >> k;
                v[j].first += k;
            }
        }
        stable_sort(v.rbegin(), v.rend());
        for(int i=0; i<m; ++i) {
            cout << -v[i].second << " \n"[i == m-1];
        }
        cout << flush;
    }
}


Measured memory_bytes: 3052
#include<bits/stdc++.h>
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pq priority_queue
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define elif else if

using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using pll=pair<ll,ll>;
using pss=pair<string,string>;
using pdd=pair<ld,ld>;
using graph=vector<vector<int>>;
using wgraph=vector<vector<pll>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ex[8]={1,1,0,-1,-1,-1,0,1};
const int ey[8]={0,1,1,1,0,-1,-1,-1};
const ld E=1e-9;

template<class T> void chmin(T &a, T b){a=min(a, b);}
template<class T> void chmax(T &a, T b){a=max(a, b);}

ll abs1(ll a){if(a>=0)return a;else return -a;}
ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1)ret*=a;a*=a;
    if(a>=p)a%=p;if(ret>=p)ret%=p;
    b=b>>1;
  }
  return ret;
}
int digit(ll a,ll b=10){int i=0;while(a!=0){a/=b;i++;}return i;}
ll gcd1(ll a,ll b){
  if(a==0 || b==0)return 0;
  ll n;while(a%b!=0){n=a%b;a=b;b=n;}return b;
}
ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];a[0]=n;b[0]=m;int i=1;
  while(b[i-1]!=0){a[i]=b[i-1];b[i]=a[i-1]%b[i-1];i++;}
  n=i;if(c%a[n-1]!=0)return 0;
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){ll cnt=x;x=y;y=cnt-(a[n-i-1]/b[n-i-1])*y;}
  return x;
}
ll modRev(ll a,ll p=MOD){
  a%=p;ll n=solveLinear(a,p,1);
  n%=p;if(n<0)return n+p;
  return n;
}
ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  ll ret=1;for(int i=1;i<=n;i++){ret=ret*i;if(ret>=p)ret%=p;}
  return ret;
}
ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  ll ret=1;rep(i,k){ret=ret*(n-i);if(ret>=p)ret%=p;}
  return ret;
}
ll binom(ll n,ll k,ll p=MOD){
  return (perm(n,k,p)*modRev(fact(k)))%p;
}
int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}

int main(){
  ll i,j,cnt=0;
  ll n;
  cin>>n;
  vector<ll> c(n);
  for(i=0;i<n;i++)cin>>c[i];
  sort(all(c),greater<ll>());
  ll ans=c[0];
  for(i=1;i<n;i++){
      ans=(((pow1(2,i-1,MOD)*(i+2))%MOD*c[i])%MOD+2*ans)%MOD;
  }
  cout<<(pow1(2,n,MOD)*ans)%MOD<<endl;
}


Measured memory_bytes: 1792
s = input()

search = []
search.append(s)
found = False

while len(search) > 0:
    se = search[0]
    # print(se, search)
    search = search[1:]
    if se in ("dream", "dreamer", "erase", "eraser"):
        print("YES")
        found = True
        break
    if len(se) < 5:
        continue
    if se[0:5] in ("dream", "erase"):
        search.append(se[5:])
    if se[0:6] in ("eraser"):
        search.append(se[6:])
    if se[0:7] in ("dreamer"):
        search.append(se[7:])

if not found:
    print("NO")


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    cout<<fixed<<setprecision(5);
    float pi=3.14159f;
    int r;
    cin>>r;
    float ans=2.0*pi*r;
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


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

int main() {
  int A , B , C;
  cin >> A;
  
  B = A / 10;
  C = A % 1000;
  
  if (((B % 111) == 0) || ((C % 111) == 0)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

ll calc(vp p) {
  int n = p.size();
  rep(i, n) p[i].first = min(p[i].first, n);
  vector<vector<int>> s(n+1);
  rep(i, n) s[p[i].first].push_back(p[i].second);
 
  ll res = 0;
  priority_queue<int> q;
  for (int i = n; i >= 1; --i) {
    for (int x : s[i]) q.push(x);
    if (q.size() > 0) {
      res += q.top();
      q.pop();
    }
  }
  return res;
}

void solve() {
  int n;
  cin >> n;
  vp pl, pr;
  ll ans = 0;
  rep(i, n) {
    int k, l, r;
    cin >> k >> l >> r;
    if (l > r) {
      ans += r;
      pl.emplace_back(k, l - r);
    } else {
      ans += l;
      pr.emplace_back(n - k, r - l);
    }
  }
  ans += calc(pl);
  ans += calc(pr);
  cout << ans << endl;
}

int main() {
  int t;
  cin >> t;
  while(t--) solve();
  return 0;
}

Measured memory_bytes: 10440
using System;

class Program
{
    static void Main(string[] args)
    {
        string S = Console.ReadLine();
        long A = long.Parse(S.Split()[0]);
        long V = long.Parse(S.Split()[1]);
        S = Console.ReadLine();
        long B = long.Parse(S.Split()[0]);
        long W = long.Parse(S.Split()[1]);
        long T = long.Parse(Console.ReadLine());

        long av = V * T;
        long bv = W * T;
        if (av >= bv + Math.Abs(A - B))
        {
            Console.WriteLine("YES");
            return;
        }
        Console.WriteLine("NO");
    }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, M, C; cin >> N >> M >> C;
    vector<ll> B(M);
    ll A[N][M];
    rep(i, M){cin >> B.at(i);}
    rep(i, N){rep(j, M){
        cin >> A[i][j];
    }}
    ll ans = 0;
    rep(i, N){
        ll tmp = C;
        rep(j, M){tmp += A[i][j] * B[j];}
        if (tmp > 0){ans++;}
    }
    cout << ans << endl;
}

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


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

struct UnionFind {
    vector<int> par;

    //正の場合、親を表す
    //負の場合、根で数値は連結成分のサイズ
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) {
            return x;
        } else {
            return par[x] = root(par[x]); //経路圧縮
        }
    }

    bool unite(int x, int y) {
        x = root(x); y = root(y);

        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); //小さい方を大きい方にくっつけるため

        par[x] += par[y];
        par[y] = x;

        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return -par[root(x)];
    }
};

int main() {

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

    UnionFind uf(n);

    vector<vector<int>> fre(n);
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        --a; --b;

        fre[a].push_back(b);
        fre[b].push_back(a);

        uf.unite(a, b);
    }

    vector<vector<int>> blo(n);
    for (int i = 0; i < k; ++i) {
        int c, d; cin >> c >> d;
        --c; --d;

        blo[c].push_back(d);
        blo[d].push_back(c);
    }

    for (int i = 0; i < n; ++i) {
        int res = uf.size(i) - 1; //自分自身を引く

        for (auto t : fre[i]) {
            if (uf.same(i, t)) --res;
        }

        for (auto t : blo[i]) {
            if (uf.same(i, t)) --res;
        }

        cout << res << ' ';
    }

    cout << endl;
}

Measured memory_bytes: 13304
fn main() {
    proconio::input! {
        n: usize,
        x: String,
    }
    let x=x.as_bytes();
    let b=x.iter().filter(|&&c|c!=b'0').count();
    let mut d=[0;2];
    let mut r=vec![vec![0;n];2];
    for i in 0..2 {
        if i==0 && b<2 {
            continue;
        }
        let b=b+i*2-1;
        let mut v=0;
        for &x in x {
            v=(v*2+(if x==b'0' {0} else {1}))%b;
        }
        d[i]=v;
        r[i][0]=1;
        for k in 1..n {
            r[i][k]=r[i][k-1]*2%b;
        }
        r[i].reverse();
    }
    for (i,&x) in x.iter().enumerate() {
        let v=if x==b'0' {0} else {1};
        let b=if v==0 {b+1} else {b-1};
        if b==0 {
            println!("0");
            continue;
        }
        let mut a=if v==0 {
            (d[1]+r[1][i])%b
        }
        else {
            (d[0]+b-r[0][i])%b
        };
        let mut c=1;
        while a>0 {
            a%=a.count_ones()as usize;
            c+=1;
        }
        println!("{}",c);
    }
}

Measured memory_bytes: 5540
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    string S;
    cin >> S;
    int i;
    if(S[2] == S[3] & S[4] == S[5]){cout << "Yes" << endl; return 0;}
    else{cout << "No" << endl; return 0;}

    return 0;
}


Measured memory_bytes: 3064
import java.util.Scanner;

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

		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n - 1];

		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		for (int i = 0; i < n; i++) {
			b[i] = Integer.parseInt(sc.next());
		}

		for (int i = 0; i < n - 1; i++) {
			c[i] = Integer.parseInt(sc.next());
		}

		int cnt = 0;

		for (int i = 0; i < n; i++) {

			cnt += b[a[i]-1];
			if (i > 0) {
				if (a[i] - a[i - 1] == 1) {
					cnt += c[a[i - 1]-1];
				}
			}
		}

		System.out.println(cnt);
		sc.close();
	}
}

Measured memory_bytes: 21588
#include <iostream>
using namespace std;
 
    
    
int main(){
     
     int H,N;
     cin>>H>>N;
     int ary[N];

     for(int i=0;i<N;i++)
     {
         cin>>ary[i];
     }
     int A=0;
     for(int j=0;j<N;j++)
     {
         A=A+ary[j];
     }

     if(A<H)
     {
         cout<<"No"<<endl;
     }
    else
    {
    cout<<"Yes"<<endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include <algorithm>
int a[300000],b[300000];
using namespace std;
int main(void){
    string s;
    int n;
    cin>>n;
    cin>>s;
    for(int i=1;i<s.length();i++){
        a[i]+=a[i-1]+(s[i-1]=='W');
    }
    for(int i=s.length()-1;i>=0;i--){
        b[i]+=b[i+1]+(s[i+1]=='E');
    }
    int Min=300001;
    for(int i=0;i<s.length();i++){
        Min=min(Min,a[i]+b[i]);
    }
    cout<<Min<<endl;
    return 0;
}


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

int main(){
    long long n, a, b, c, d;

    cin >> n >> a >> b >> c >> d;

    long long sa = 2*c;

    long long haba = d-c;
    for(int i = 0;i < n-2;i++){
        sa -= (d - c);
        haba += (d - c);
        if(sa <= 0){
            sa = 0;
            break;
        }
    }

    long long ma = d*(n-1)+a;
    for(int i = 0;i < n;i++){
        if(ma-haba <= b && b <= ma){
            cout <<"YES" << endl;
            return 0;
        }
        ma -= haba+sa;
    }

    cout << "NO" << endl;
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)

using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> rows;
    for(int i = 0; i < h; i++){
        if(i == 0){
            string rs(w + 2, '.');
            rows.push_back(rs);
        }
        string s;
        cin >> s;
        s = "." + s + ".";
        rows.push_back(s);
        if(i == h - 1){
            string rend(w + 2, '.');
            rows.push_back(rend);
        }
    }
    
    bool ans = true;
    
    for(int i = 1; i < h + 1; i++){
        for(int j = 1; j < w + 1; j++){
            if(rows[i][j] == '#'){
                if(!(rows[i][j+1] == '#' || rows[i][j-1] == '#' || rows[i+1][j] == '#' || rows[i-1][j] == '#')){
                    ans = false;
                    break;
                }
            }
        }
    }
    if(ans){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		for(int n;(n=sc.nextInt())!=0;){
			int[][] a=new int[n][n];
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					a[i][j]=sc.nextInt();
			
			int[][] b=new int[n][n];
			for(int i=0;i<n;i++){
				int min=-1;
				for(int j=0;j<n;j++)
					if(min==-1 || a[i][j]<min)
						min=a[i][j];
				for(int j=0;j<n;j++)
					if(a[i][j]==min)
						b[i][j]++;
			}
			for(int j=0;j<n;j++){
				int max=-1;
				for(int i=0;i<n;i++)
					if(max==-1 || a[i][j]>max)
						max=a[i][j];
				for(int i=0;i<n;i++)
					if(a[i][j]==max)
						b[i][j]++;
			}
			
			int res=0;
			for(int i=0;i<n;i++)
				for(int j=0;j<n;j++)
					if(b[i][j]==2)
						res=a[i][j];
			
			System.out.println(res);
		}
	}
}

Measured memory_bytes: 12000