akhauriyash/Code-Regression huggingface dataset:
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

ll combi(ll n, ll k) {
  static ll c[55][55];
  if(c[0][0] == 0) {
    REP(i, 55) {
      c[i][0] = c[i][i] = 1;
      FOR(j, 1, i) c[i][j] = c[i-1][j] + c[i-1][j-1];
    }
  }
  return c[n][k];
}

pair<double, double> dp[105][55];
int p[105], t[105], v[105];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, L;
  cin >> n >> m >> L;
  REP(i, n) cin >> p[i] >> t[i] >> v[i];

  combi(2, 0);

  REP(i, n) {
    REP(j, m+1) {
      dp[i][j] = {j*t[i] + (double)L/v[i], combi(m, j) * pow(p[i]/100.0, j) * pow((100-p[i])/100.0, m-j)};
      // cout << (double)combi(m, j) << "," << pow(p[i]/100.0, j) << "," << pow((100-p[i])/100.0, m-j) << "," << (100-p[i])/100.0 << " ";
      // cout << dp[i][j] << " ";
    }
    // cout << endl;
  }

  vector<double> ans(n, 0);
  // i人目がj回休んだ時に優勝する確率
  REP(i, n) {
    REP(j, m+1) {
      double prob = dp[i][j].second;
      REP(k, n) {
        if(i==k) continue;
        double sum = 0;
        for(int l=m; l>=0; --l) {
          if(dp[k][l].first <= dp[i][j].first) {
            prob *= sum;
            break;
          }
          sum += dp[k][l].second;
        }
      }
      ans[i] += prob;
    }
  }

  cout << fixed << setprecision(9);
  REP(i, n) cout << ans[i] << endl;

  return 0;
}



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

int main(){
  vector<char> s;
  while(true){
    char x; cin >> x;
    if(cin.eof()) break;
    s.push_back(x);
  }
  
  bool turn = true;
  while(true){
    if(s.size() <= 2){
      cout << (turn ? "Second" : "First") << endl;
      return 0;
    }
    bool flag = false;
    for(int i=1; i<s.size()-1; ++i){
      if(s[i-1] != s[i+1]){
        s.erase(s.begin() + i);
        turn = !(turn);
        flag = true;
        break;
      }
    }
    if(!flag){
      cout << (turn ? "Second" : "First") << endl;
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define st string
#define con continue
#define br break
#define rt return 0
#define fr first
#define sec second
using namespace std;
int main(){
//ll tc; cin>>tc; while(tc--){
ll n,m,i,x,j,mx=0,t,k,b,a,ans=0,c=0; 
 st s,str; char strn;
cin>>n; //a=n; n-=1; 
ll ara[n+1],bra[n+1],taj[n+1];
//memset(taj,0,sizeof(taj));
  map<ll,ll>mp;
for(i=1;i<=n;i++)
    { cin>>ara[i];
      ans+=ara[i];
      mp[ara[i]]++;  
    } 
    
 cin>>k;
  while(k--)
   {
       
       cin>>a>>b;
       c=mp[a];
        ans+=((b-a)*c);
       mp[b]+=c;
       mp[a]-=mp[a];       
      cout<<ans<<endl;
   }      
  
        
     //cout<<a<<endl;
    
 
    rt;
}

Measured memory_bytes: 10188
#include<stdio.h>
    int main(){
      int a,b,c,d=0;
      scanf("%d %d %d",&a,&b,&c);
      for(int i=100; 1<=i; i--){
        if(a%i==0&&b%i==0){
          d++;
        }
        if(d==c){
          printf("%d",i);
          break;
        }
      }
      return 0;}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<string>
#include<sstream>
using namespace std;
int inf = 1000000000;

int main(){

  int a, b;
  cin >> a >> b;
  cout << max(a+b, max(a-b, a*b)) << endl;

  return 0;
}





//


Measured memory_bytes: 256
def main():
    N = int(input())
    M = A = R = C = H = 0
    for i in range(N):
        name = input()
        if name[0] == "M":
            M = M + 1
        elif name[0] == "A":
            A = A + 1
        elif name[0] == "R":
            R = R + 1
        elif name[0] == "C":
            C = C + 1
        elif name[0] == "H":
            H = H + 1

    ans = M*A*R
    ans = ans + M*A*C
    ans = ans + M*A*H
    ans = ans + M*R*C
    ans = ans + M*R*H
    ans = ans + M*C*H
    ans = ans + A*R*C
    ans = ans + A*R*H
    ans = ans + A*C*H
    ans = ans + R*C*H
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <iterator>

using ll = long long;
using namespace std;
#define modmod 1000000007

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,k,n) for(int i=k;i<n;i++)


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

    string words[4];
    words[0] = "dream";
    words[1] = "dreamer";
    words[2] = "erase";
    words[3] = "eraser";

    bool isword = true;

    while(1){
        if(S.length()==0){
            cout << "YES" << endl;
            return 0;
        }

        isword = false;

        for(int i = 0; i < 4; i++){
            if(S.size() < words[i].size()) continue;
            if(S.find(words[i], S.size() - words[i].size()) != std::string::npos){
                S.erase(S.end()-words[i].size(),S.end());
                isword = true;
                break;
            }
        }
        if(isword == false){
            cout << "NO" << endl;
            return 0;
        }
    }



    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  string s;
  cin >> s;
  int n = s.size();
  int ans = INF;
  REP(i, n-2){
    int m = (s[i] - '0')*100 + (s[i+1]-'0')*10 + (s[i+2] - '0');
    chmin(ans, abs(753 - m));
  }
  cout << ans << endl;
  return 0;
}

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

int H, W;
char a[110][110];

int main()
{
    cin >> H >> W;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            cin >> a[h][w];
        }
    }
    vector<int> bh, bw;
    for (int h = 0; h < H; h++) {
        for (int w = 0; w < W; w++) {
            if (a[h][w] == '#') {
                bh.push_back(h);
                break;
            }
        }
    }
    for (int w = 0; w < W; w++) {
        for (int h = 0; h < H; h++) {
            if (a[h][w] == '#') {
                bw.push_back(w);
                break;
            }
        }
    }

    for (auto& eh: bh) {
        for (auto& ew : bw) {
            cout << a[eh][ew];
        }
        cout << endl;
    }
    return 0;
}

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

int main()
{
    int n;
    ld s=0;
    cin>>n;
    ld p[n],dp[n+1];
    dp[0]=1;
    for(int i=1;i<=n;i++)dp[i]=0;
    for(int i=0;i<n;i++){
        cin>>p[i];
        for(int j=i+1;j>=1;j--){
            dp[j]=dp[j-1]*p[i]+dp[j]*(1-p[i]);
        }
        dp[0]*=(1-p[i]);
    }
    for(int i=n/2+1;i<=n;i++)s+=dp[i];
    cout<<fixed<<setprecision(10)<<s;
}


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

using namespace std;

int n;

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

	int qtdOdd = 0;

	for(int i = 1 ; i <= n ; i++)
	{
		int v;
		scanf("%d",&v);

		qtdOdd += v%2;
	}

	if( qtdOdd%2 == 0 ) printf("YES\n");
	else printf("NO\n");
}

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

int p[M+1],a,b,c,n;

void input(void){
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&n);
    n/=50;
}

void process(void){
    int i,j;
    p[0]=1;
    for(i=n;i>=0;i--){
        for(j=1;j<=a && i-j*10>=0;j++){
            p[i]+=p[i-j*10];
        }
    }
    for(i=n;i>=0;i--){
        for(j=1;j<=b && i-j*2>=0;j++){
            p[i]+=p[i-j*2];
        }
    }
    for(i=n;i>=0;i--){
        for(j=1;j<=c && i-j*1>=0;j++){
            p[i]+=p[i-j*1];
        }
    }
    printf("%d\n",p[n]);
}

int main(){
    input();
    process();

    return 0;
}

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

int main()
{
  int n; cin >> n;
  vector<int> num(9, 0);
  for (int i = 0; i < n; ++i)
  {
    int a; cin >> a;
    int index = a/400;
    if (index > 8) index = 8;
    ++num[index];
  }
  
  int min = 0;
  for (auto itr = num.begin(); itr < num.end()-1; ++itr)
    if (*itr) ++min;
  
  if (min) cout << min << " " << min + *(num.end()-1) << endl;
  else cout << 1 << " " << *(num.end()-1) << endl;
}

Measured memory_bytes: 256
// failed to generate code

#include <bits/stdc++.h>
using namespace std;


int a[400];
long long dp[444][444];

long long sum[444];

long long calc(int a,int b){
    return sum[b] - sum[a];
}

int main() {

    int n;
    cin >> n;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    for(int i = 0 ; i < n ; i++) sum[i+1] = sum[i] + a[i];
    for(int i = 0 ; i < 444 ; i++)
        for(int j = 0 ; j < 444 ; j++)
            dp[i][j] = 1e18;

    for(int i = 0 ; i < 444 ; i++){
        dp[i][i+1] = 0;
    }

    for(int w = 2 ; w <= 400 ; w++){
        for(int i = 0 ; i + w <= n ; i++){
            for(int j = i + 1 ; j < i + w ; j++){
                dp[i][i+w] = min(dp[i][i+w], dp[i][j] + dp[j][i+w] + calc(i, i+w) );
            }
        }
    }
    cout << dp[0][n] << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <bitset>
#include <string>
#include <array>
#include <queue>

using namespace std;

int main()
{
    int a, b, c;
    int ans = 0;
    cin >> a >> b >> c;
    ans = (a * b) / 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  l = [int(input()) for _ in range(5)]
  k = int(input())
  if l[-1]-l[0]>k:
    print(':(')
  else:
    print('Yay!')
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5076
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        int[][] a = new int[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                a[i][j] = scan.nextInt();
            }
        }
        int move_count = 0;
        List<String> moves = new ArrayList<>();
        for (int i = 0; i < H; i++) {
            int start = i % 2 == 0 ? 0 : W - 1;
            int increment = i % 2 == 0 ? 1 : -1;
            for (int j = start; j < W && 0 <= j; j = j + increment) {
                if (a[i][j] % 2 == 0) {
                    continue;
                }
                if (i % 2 == 0 && j + 1 < W) {
                    a[i][j] -= 1;
                    a[i][j+1] += 1;
                    move_count += 1;
                    moves.add(String.format("%d %d %d %d", (i+1), (j+1), (i+1), (j+2)));
                    continue;
                }
                if (i % 2 == 1 && 0 <= j - 1) {
                    a[i][j] -= 1;
                    a[i][j-1] += 1;
                    move_count += 1;
                    moves.add(String.format("%d %d %d %d", (i+1), (j+1), (i+1), (j)));
                    continue;
                }
                if (i % 2 == 0 && j == W - 1 && i + 1 < H) {
                    a[i][j] -= 1;
                    a[i+1][j] += 1;
                    move_count += 1;
                    moves.add(String.format("%d %d %d %d", (i+1), (j+1), (i+2), (j+1)));
                    continue;
                }
                if (i % 2 == 1 && j == 0 && i + 1 < H) {
                    a[i][j] -= 1;
                    a[i+1][j] += 1;
                    move_count += 1;
                    moves.add(String.format("%d %d %d %d", (i+1), (j+1), (i+2), (j+1)));
                    continue;
                }
            }
        }
        System.out.println(move_count);
        for (int i = 0; i < move_count; i++) {
            System.out.println(moves.get(i));
        }
    }
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 62;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

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
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= 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
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<P> ans;
  if(n%2==1) {
    for(int i = 1; i <= n; ++i) {
      for(int j = i+1; j <= n; ++j) {
        if(i+j==n) continue;
        ans.emplace_back(i, j);
      }
    }
  }
  else {
    for(int i = 1; i <= n; ++i) {
      for(int j = i+1; j <= n; ++j) {
        if(i+j==n+1) continue;
        ans.emplace_back(i, j);
      }
    }
  }
  cout << ans.size() << endl;
  for(auto x : ans) cout << x.first << " " << x.second << endl;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
	char pattern[8][9];
	int i;
	int j;
	
	for (i = 0; i < 8; i++){
		scanf("%s", pattern[i]);
	}
	
	printf("90\n");
	for (i = 0; i < 8; i++){
		for (j = 7; j >= 0; j--){
			printf("%c",pattern[j][i]);
		}
		printf("\n");
	}
	
	printf("180\n");
	for (i = 7; i >= 0; i--){
		for (j = 7; j >= 0; j--){
			printf("%c",pattern[i][j]);
		}
		printf("\n");
	}
	
	printf("270\n");
	for (i = 7; i >= 0; i--){
		for (j = 0; j < 8; j++){
			printf("%c",pattern[j][i]);
		}
		printf("\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign
 
signed main()
{
    Int(n);
    int r = 0, l = 0;
    rep(i, n) {
        Int(a);
        string s;
        cin >> s;
        Int(b);
        if (s[0] == '(' ) {
            l += b;
        } else {
            r += b;
        }
        if (l == r) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int main(){
    int H[1000],W[1000];
    int tmph,tmpw;
    int i=0;
    cin>>tmph>>tmpw;
    while(tmph!=0||tmpw!=0){
        H[i]=tmph;
        W[i]=tmpw;
        cin>>tmph>>tmpw;
        i++;
    }
    for(int j=0;j<i;++j){
        for(int h=0;h<H[j];++h){
            for(int w=0;w<W[j];++w){
                cout<<'#';
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 212345;
int X[MAX_N];
int Y[MAX_N];

int main2() {
  int N = nextInt();
  REP(i, N) X[i] = nextInt();
  REP(i, N) Y[i] = X[i];

  sort(Y, Y + N);

  int a = Y[(N-1)/2];
  int b = Y[N/2];
  REP(i, N) {
    int ans;
    if (X[i] >= b) ans = a;
    else ans = b;
    printf("%d\n", ans);
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

int main(){
    string s,t,u;
    int a,b;
    cin>>s>>t>>a>>b>>u;
    if (u==s) cout<<a-1<<' '<<b;
    else if (u==t) cout<<a<<' '<<b-1;
    else cout<<a<<' '<<b;
}


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



int main() {
  ll n,m;
  cin >>n >>m;
  ll ans=1;
  if(abs(n-m)>=2){cout << 0 << endl; return 0;}
  for(int i=1;i<=n;i++){
    ans=ans*i%mod;
  }
    for(int i=1;i<=m;i++){
    ans=ans*i%mod;
  }
  if(n==m)ans=ans*2%mod;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int min(int a,int b);
	int a, b;
	scanf("%d %d", &a, &b);
	if(a < b)
	{
		int t = a;
		a = b;
		b = t;
	}
	printf("%d\n", min(a,b));
	
	return 0;
}

int min(int a,int b)
{
	if(a % b == 0)
	{
		return b;
	}
	else
	{
		min(b,a % b);
	}
}


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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {

        int A, B, C, X, Y; cin >> A >> B >> C >> X >> Y;
        int ans = INF;
        {
            int sum = 0;
            int nc = X * 2;
            sum += C * nc;
            if(Y - nc / 2 > 0) sum += B * (Y - nc / 2);
            set_min(ans, sum);
        }
        {
            int sum = 0;
            int nc = Y * 2;
            sum += C * nc;
            if(X - nc / 2 > 0) sum += A * (X - nc / 2);
            set_min(ans, sum);
        }

        set_min(ans, A * X + B * Y);

        cout << ans << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

using namespace std;
typedef long long int ll;

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll,ll>>v(N);
    for(int i = 0; i < N; i++)
    {
        ll x,l;
        cin >> x >> l;
        v[i] = pair(x + l, x - l);
    }
    sort(v.begin(),v.end());
    vector<bool>f(N,false);
    ll now = 0;
    f[now] = true;
    for(ll i = 0; i < N; i++)
    {
        if(v[now].first <= v[i].second) f[i] = true, now = i;
    }
    int ans = 0;
    for(ll i = 0; i < N; i++)
    {
        if(f[i]) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793
#define MOD 1000000007
typedef long long ll;
typedef long double ld;

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

    for(int i = 0; i < N - 1; i++){

        if(x[i] < x[i + 1]){

            if(ans - x[i] >= 0){
                kabu += ans / x[i];
                ans -= kabu * x[i];
            }
        }

        else{
            if(kabu > 0){
                ans += kabu * x[i];
                kabu = 0;
            }
        }

    }
    if(kabu > 0){
        ans += x[N - 1] * kabu;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
 ll n,k;
 cin>>n>>k;
 vector<ll> a(n);
 for(ll i=0;i<n;i++)cin>>a[i];
 //vector<double> la(n);
 //for(ll i=0;i<n;i++) la[i] = log(a[i]);
 //double sum = 0;
 //for(ll i=0;i<k;i++)
 for(ll i=k;i<n;i++){
  if( a[i] > a[i-k] ){
   cout<<"Yes"<<endl;
  }else{
   cout<<"No"<<endl;
  }
 }
    return 0;
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = a; i < n; i++)
#define Repr(i, n, a) for (int i = n; i >= a; i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m, r;
vector<int> v[100010], vv[100010];
int par[100010], cost[100010];

void bfs()
{
    queue<int> que;
    que.push(r);
    while (!que.empty())
    {
        int a = que.front();
        que.pop();
        rep(i, v[a].size())
        {
            if (cost[v[a][i]] == 1)
            {
                par[v[a][i]] = a + 1;
                que.push(v[a][i]);
            }
            else
                cost[v[a][i]]--;
        }
    }
}

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

    cin >> n >> m;
    rep(i, n + m - 1)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        v[a].push_back(b);
        vv[b].push_back(a);
    }
    rep(i, n) if (vv[i].size() == 0) r = i;
    rep(i, n) cost[i] = vv[i].size();
    par[r] = 0;
    bfs();
    rep(i, n) cout << par[i] << endl;
}

Measured memory_bytes: 13440
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  string t;
  
  cin >> s >> t;
  
  int num=0;
  for(int i=0; i<3; i++){
    if(s[i]==t[i]){
      num++;
    }
  }
  
  cout << num << endl;
  
}


Measured memory_bytes: 3628
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	string str;
	cin >> str;
	int size = str.size();
	int Lpos = 0;
	int Rpos = size-1;
	int Len = 0;
	int ans = 0;
	while(Lpos < Rpos){
		if( str[Lpos] == str[Rpos] ){
			Lpos += 1;
			Rpos -= 1;
			Len += 2;
		}else if( str[Lpos] == 'x' ){//かぁぃぃ
			//右にxを入れる
			Lpos += 1;
			Len += 2;
			ans += 1;
		}else if( str[Rpos] == 'x' ){
			Rpos -= 1;
			Len += 2;
			ans += 1;
		}else{
			cout << -1 << endl;
			return;
		}
	}

	//Lpos==Rposならstr[Lpos]はどんな文字でもよい
	cout << ans << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<climits>
#include<stack>

using namespace std;

#define MAX 10000003
#define KMAX 1000000000000003LL

vector<int> vprimes;
bool *isPrime = new bool[MAX];

void MakePrime(){
  for(int i=0;i<MAX;++i)
    isPrime[i]=true;
  isPrime[0]=false;
  isPrime[1]=false;
  for(long long int i=2;i<MAX;++i)
    if(isPrime[i])
      for(long long int j=2;i*j<MAX;++j)
	isPrime[i*j]=false;
  for(int i = 0; i < MAX; ++i)
    if( isPrime[i] )
      vprimes.push_back( i );
}

template<typename Integer>
void Factorization(Integer n, vector< pair<Integer,Integer> > &vp){
  if(n==1){vp.push_back(make_pair(1,1));return ;}
  for(int i = 0; i < vprimes.size(); ++i){
    while(n%vprimes[i]==0){
      n/=vprimes[i];
      if( vp.size()>0 && vp.back().first == vprimes[i] )
	vp.back().second++;
      else
	vp.push_back( make_pair(vprimes[i],1) );
    }
    if(n==1)return ;
  }
  vp.push_back( make_pair(n,1) );  
}

// ®ªÌñ,vvÉ½¢µÄÐÆÂÌªvª èAvÌ®Íå«¢ÉÀÔ
void partitions(int n, int max_n, vector<int>& v, vector<vector<int> >& vv) {
  if(n==0){vv.push_back(v);return;}
  for(int i=min(n,max_n);i>0;i--){v.push_back(i);partitions(n-i,i,v,vv);v.pop_back();}
}

template<typename Integer>
Integer divisorFunction1(Integer n){
  Integer ret=0;
  if(n==1)return 1;
  stack<pair<Integer,Integer> > st;
  vector< pair<Integer,Integer> > facts;
  Factorization(n,facts);
  st.push(make_pair(0,1));
  while(!st.empty()){
    pair<Integer,Integer> nst=st.top();
    st.pop();
    if(nst.first>=facts.size()){ret+=nst.second;continue;}
    Integer r=1;
    for(int i = 0; i < facts[nst.first].second+1; ++i){
      pair<Integer,Integer> nx(nst.first+1,nst.second*r);
      st.push(nx);
      r*=facts[nst.first].first;
    }
  }
  return ret;
}

int main()
{
  map<long long int, double> M;
  MakePrime();
  for(int base=0;base<2;++base){
    for(int n=1;n<21;++n){
      vector<int> v;
      vector< vector<int> > vv;
      //cerr<<n<<endl;
      partitions(n, 13, v, vv);
      for(int i = 0; i < vv.size(); ++i){
	long long int llv=1;
	for(int j = 0; j < vv[i].size(); ++j){
	  for(int k = 0; k < vv[i][j]; ++k){
	    if(llv*vprimes[base+j]>KMAX)break;
	    llv *= vprimes[base+j];
	  }
	  if(llv*vprimes[base+j]>KMAX)break;
	}
	if(llv>0&&llv<KMAX){
	  long long int df=divisorFunction1(llv);
	  M[llv]=max(M[llv],divisorFunction1(llv)/(double)llv);
	}
      }
    }
  }
  //cout << M.size() << endl;
  map<long long int, double> Mans;
  double maxi=0.0;
  for(map<long long int,double>::iterator itm=M.begin(); itm!=M.end(); ++itm){
    maxi=max(maxi,itm->second);
    Mans[itm->first]=maxi;
  }
  while(true){
    long long int k;
    double ans=1;
    cin >> k;
    if(k==0)break;
    map<long long int, double>::iterator itm = Mans.lower_bound(k);
    if( itm->first > k )--itm;
    ans = max(ans,itm->second);
    printf("%.6lf\n",ans);
  }
  return 0;
}

Measured memory_bytes: 13000
# coding=utf-8


N = int(input())
X_list = list(map(int, input().split()))

X_list2 = X_list[:]
X_list2.sort()
smaller = X_list2[N//2 -1]
larger = X_list2[N//2]

for element in X_list:
    if element <= smaller:
        print(larger)
    else:
        print(smaller)


Measured memory_bytes: 25556
import sys
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    A,B=map(int,input().split())
    
    if (A + B) %2 ==0:
        print(int(A/2+B/2))
    else:
        print("IMPOSSIBLE")
    



if __name__ == "__main__":
    main()


Measured memory_bytes: 62068
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

vector<string> board;
int l[2010][2010], r[2010][2010];
int u[2010][2010], d[2010][2010];
 
signed main() {
    int H, W; cin >> H >> W;
    for(int i=0; i<H; i++) {
        string s; cin >> s;
        board.emplace_back(s);
    }

    for(int i=0; i<H; i++) {
        for(int j=1; j<W; j++) {
            if(board[i][j-1] == '.') {
                l[i][j] = l[i][j-1] + 1;
            }
            else {
                l[i][j] = 0;
            }
        }

        for(int j=W-2; j>=0; j--) {
            if(board[i][j+1] == '.') {
                r[i][j] = r[i][j+1] + 1;
            }
            else {
                r[i][j] = 0;
            }
        }
    }

    for(int j=0; j<W; j++) {
        for(int i=1; i<H; i++) {
            if(board[i-1][j] == '.') {
                u[i][j] = u[i-1][j] + 1;
            }
            else {
                u[i][j] = 0;
            }
        }
        for(int i=H-2; i>=0; i--) {
            if(board[i+1][j] == '.') {
                d[i][j] = d[i+1][j] + 1;
            }
            else {
                d[i][j] = 0;
            }
        }
    }

    int ans = 0;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(board[i][j] != '.') continue;
            int cand = l[i][j] + r[i][j] + u[i][j] + d[i][j] + 1;
            ans = max(ans, cand);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 130432
#include<iostream>
long n,k,a,i,j,m=1e9+7,v[9<<9];main(){for(std::cin>>n>>k;i++<n;)for(j=0;j++<n;v[i]>v[j]?(a+=k*(k-1)/2+(i<j)*k)%=m:0)i-1||std::cin>>v[j];std::cout<<a;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    string T;
    cin>>T;
    int N=T.size();
    rep(i,N){
        if(T.at(i)=='?'){
            T.at(i)='D';
        }
    }
    cout<<T<<endl;
}

Measured memory_bytes: 3752
#include<iostream>
#include<vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <iterator>
#include <cstdint>
using namespace std;

int main(void){
    
    string b ;
    cin >> b ;
    size_t n = b.length();
    bool flag[4] ={ false , false , false ,false } ;
    for(int i = 0 ; i < n ; i++ ){
        if(b[i] == 'N'){
            flag[0] = true ;
        }else if(b[i] == 'W'){
            flag[1] = true ;
        }else if(b[i] == 'S'){
            flag[2] = true ;
        }else if(b[i] == 'E'){
            flag[3] = true ;
        }
    }

    if(flag[0] == true && flag[1] == true && flag[2] == true && flag[3] == true){
        cout << "Yes" << endl;
    }else if(flag[0] == true && flag[1] == false && flag[2] == true && flag[3] == false) {
        cout << "Yes" << endl;
    }else if(flag[0] == false && flag[1] == true && flag[2] == false && flag[3] == true) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;

    cin >> a >> b >> c; 

    int count (0);
    for (int i=a; i<=b; i++) 
    {
        if (c % i == 0)
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}



Measured memory_bytes: 3084
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

void initBit(int *bit){
  int n=bit[0];
  for(int i=1;i<=n;i++) bit[i]=0;
}

void inc(int *bit,int x){
  const int n=bit[0];
  for(int i=x;i<=n;i+=i&-i) bit[i]++;
}

int getSum(int *bit,int x){
  int res=0;
  for(int i=x;i>0;i-=i&-i) res+=bit[i];
  return res;
}

int64 count(int m,int *a,int n){
  static int *bit=NULL;
  if(bit==NULL){
    bit=(int *)calloc(2*n+1+1,sizeof(int));
    bit[0]=2*n+1;
  }
  initBit(bit);
  int64 cnt=0;
  int sum=n+1;
  inc(bit,sum);
  for(int i=0;i<n;i++){
    sum+=(a[i]<m?-1:1);
    cnt+=getSum(bit,sum);
    inc(bit,sum);
  }
  return cnt;
}

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int l=1;
  int r=1000000000+1;
  while(r-l>1){
    int m=(l+r)/2;
    int64 cnt=count(m,a,n);
    if(4*cnt>=(int64)n*(n+1)){
      l=m;
    } else {
      r=m;
    }
  }
  printf("%d\n",l);
}

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


Measured memory_bytes: 1280
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
    int x[20][20],y[20][20],a[20],ans = 0;
	    int n; cin >> n;
	    for(int i = 0;i < n;i++){
	        cin >> a[i];
	        for(int j = 0;j < a[i];j++){
	            cin >> x[i][j] >> y[i][j];
	            x[i][j]--;
	        }
	    }

	    for(int tmp = 0;tmp < (1 << n);tmp++){
	        bool ok = true;
	        bitset<15> bit(tmp);
	        for(int i = 0;i < n;i++){
	            if(bit.test(i)){
	                for(int j = 0;j < a[i];j++){
	                    if(y[i][j]){
	                        if(bit.test(x[i][j])) continue;
	                        else ok = false;
	                    }else{
                            if(bit.test(x[i][j])) ok = false;
                            else continue;
                        }
	                }
	            }
	        }
	        if(ok) ans = max(ans,__builtin_popcount(tmp));
	    }
        cout << ans << endl;

}

    


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
	"math"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	d := sc.NextInt()

	arr := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, d)
	}

	for i := 0; i < n; i++ {
		for j := 0; j < d; j++ {
			arr[i][j] = sc.NextInt()
		}
	}
	ans := 0
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			sum := 0
			for k := 0; k < d; k++ {
				sum += (arr[i][k] - arr[j][k]) * (arr[i][k] - arr[j][k])
			}

			tmp := math.Sqrt(float64(sum))
			if tmp == float64(int64(tmp)) {
				ans++
			}
			//			fmt.Printf("%+v\n", math.Sqrt(float64(sum))) // output for debug
		}
	}

	fmt.Printf("%v\n", ans)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

void solve() {
    int N; cin >> N;
    vector<ll> K(N),L(N),R(N);
    rep(i,N) {
        cin >> K[i] >> L[i] >> R[i];
        --K[i];
    }
    vector<int> idx(N);
    iota(all(idx),0);
    sort(all(idx),[&](int i, int j){return K[i] < K[j];});

    ll ans = accumulate(all(R),0LL);
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    priority_queue<pll> rs;
    int cur = 0;
    vector<int> B;
    // rep(i,N) {
    //     while (cur < N and K[idx[cur]] <= i) {
    //         int u = idx[cur];
    //         if (L[u] >= R[u]) {
    //             if (pq.size() <= i) {
    //                 pq.emplace(L[u]-R[u],u);
    //             } else {
    //                 pq.emplace(L[u]-R[u],u);
    //                 //B.emplace_back(pq.top().second);
    //                 pq.pop();
    //             }
    //         } else B.emplace_back(u);
    //         cur++;
    //     }
    // }
    rep(i,N) {
        int u = idx[i];
        if (L[u] >= R[u]) {
            if (pq.size() <= K[u]) {
                pq.emplace(L[u]-R[u],u);
            } else {
                pq.emplace(L[u]-R[u],u);
                pq.pop();
            }
        } else B.emplace_back(u);
    }
    // while (!pq.empty()) {
    //     cout << pq.top().first << ln;
    //     ans += pq.top().first;
    //     pq.pop();
    // }
    //cout << ans << ln;
    int M = B.size();
    //sort(all(B),[&](int i, int j){return K[i] < K[j];});
    for (int i = M-1; i >= 0; i--) {
        int u = B[i];
        if (N-1-K[u] > rs.size()) {
            rs.emplace(L[u]-R[u],u);
        } else {
            rs.emplace(L[u]-R[u],u);
            pq.emplace(rs.top());
            rs.pop();
        }
    }
    while (!pq.empty()) {
        ans += pq.top().first;
        pq.pop();
    }

    cout << ans << ln;
    //cout << ln;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int Q; cin >> Q;
    while (Q--) {
        solve();
    }
}

Measured memory_bytes: 14236
/*
Author : N_o_o_B
Created : December 21 2019 15:35:22 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

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

    string s;
    cin >> s;
    // nc2 - number of palindromic substrings    
    ll n = sz(s);
    ll cnt = n*(n-1)/2;
    vl a(26);
    fori(i,n){
        a[s[i]-'a']++;
    }
    fori(i,26){
        cnt -= (a[i]*(a[i]-1)/2);
    }
    cout << cnt+1 << endl;
    time_taken();
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,c;
  string b;
  cin >> a >> b >> c;
  if(b == "+")cout << a+c << endl;
  else cout << a - c << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
long long tab[30];
long long licz;
int f(char a)
{
    return int(a)-97;
}
void rek(int a,long long war)
{
    if(a==26)
    {
        licz=(licz+war)%mod;
        return;
    }
    rek(a+1,war);
    rek(a+1,(war*tab[a])%mod);
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
    int a;
    string b;
    cin>>a>>b;
    int kon=0;
    for(int x=0;x<a;x++)
        tab[f(b[x])]++;
    rek(0,1);
    cout<<(licz-1+mod)%mod;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    fastcin();
    int n;
    cin >> n;
    vector<string> s(n);
    map<string, int> mp;
    int mx = 0;
    rep(i, n){
        cin >> s[i];
        mp[s[i]]++;
        chmax(mx, mp[s[i]]);
    }
    vector<string> ans;
    repe(i, mp){
        if(i.second == mx) ans.push_back(i.first);
    }
    sort(all(ans));
    repe(i, ans) cout << i << endl;
}

Measured memory_bytes: 27120
#include <iostream>
#include <string>
#include <queue>
#define PAIR pair<int, int>
using namespace std;

int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		int field[8][8];
		for(int j = 0; j < 8; j++){
			string input;
			cin >> input;
			for(int k = 0; k < 8; k++){
				field[j][k] = input[k] - '0';
			}
		}
		int inputx, inputy;
		cin >> inputx >> inputy;

		queue<PAIR> st;
		st.push(PAIR(inputx-1, inputy-1));
		int dx[] = {1, 2, 3, 0, 0, 0,-1,-2,-3, 0, 0 ,0};
		int dy[] = {0, 0, 0, 1, 2, 3, 0, 0, 0,-1,-2,-3};
		while(!st.empty()){
			int x = st.front().first;
			int y = st.front().second;
			field[y][x] = 0;
			//cout << x << y << endl;
			for(int j = 0; j < 12; j++){
				//cout << "ok";
				int nextx = st.front().first + dx[j];
				int nexty = st.front().second + dy[j];
				if(0 <= nextx && nextx < 8 && 0 <= nexty && nexty < 8){
					if(field[nexty][nextx] == 1) st.push(PAIR(nextx, nexty));
				}
			}
			st.pop();
		}

		cout << "Data " << i << ":" << endl;
		for(int j = 0; j < 8; j++){
			for(int k = 0; k < 8; k++){
				cout << field[j][k];
			}
			cout << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 1232