akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
int n,m,i,j,k,x[100005],y[100005],book[405][405],flag[405],sum;
int main(){
	n=read();m=read();
	for(i=1;i<=m;i++){
		x[i]=read();
		y[i]=read();
	}
	for(i=1;i<=n;i++){
		book[i][i]=1;
		for(j=m;j>=1;j--){
			if(book[i][x[j]]==1&&book[i][y[j]]==1){
				flag[i]=1;
				break;
			}
			if(book[i][x[j]]==1||book[i][y[j]]==1){
				book[i][x[j]]=1;
				book[i][y[j]]=1;
			}
		}
	}
	for(i=1;i<=n;i++)
		if(flag[i]==0)
			for(j=i+1;j<=n;j++)
				if(flag[j]==0){
					for(k=1;k<=n;k++)
						if(book[i][k]==1&&book[j][k]==1)
							break;
					if(k==n+1)
						sum++;
				}
	pus(sum,2);
	return 0;
}

Measured memory_bytes: 1664
# ABC159 B

def main():
    s = input()
    
    n = len(s)
    m = (n-1)//2
    o = (n+3)//2
    p = s[:m]
    q = s[o-1:]

    if s == s[::-1]:
        if p == p[::-1]:
            if q == q[::-1]:
                print("Yes")
            else:
                print("No")
        else:
            print("No")
    else:
        print("No")

if __name__ == '__main__':
    main()

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cout <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cout <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}
#define jeb() fflush(stdout);

using namespace std;
const int max_n = 1e6 + 5;

int gcd(int a, int b) {
    return a == 0 ? b : gcd(b%a, a);
}

int mod = 1e9 + 7;
int n, m;
VI v, w;

int g1[1234567], g2[1234567];

int main() {
	read2(n, m);
	readv(v, n);
	readv(w, m);
	FOR(i,1,n*m+1) g1[i] = g2[i] = -1;
	FOR(i,0,n) g1[v[i]] = i;
	FOR(j,0,m) g2[w[j]] = j;
	int ans = 1;
	int wier = 0, kol = 0, zakryte = 0;
	FORD(i,n*m, 1) {
		if (g1[i] != -1 && g2[i] != -1) {
			zakryte += wier + kol;
			wier++;
			kol++;
		} else if (g1[i] == -1 && g2[i] == -1) {
			ans = (ans * 1LL * zakryte) % mod;
			zakryte--;
		} else if (g1[i] == -1) {
			ans = (ans * 1LL * wier) % mod;
			zakryte += wier - 1;
			kol++;
		} else if (g2[i] == -1) {
			ans = (ans * 1LL * kol) % mod;
			zakryte += kol - 1;
			wier++;
		}
	}
	printf("%d\n", ans);
}





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

int N, M, Q;
int A[50], B[50], C[50], D[50];

int dfs(vector<int> As, int lower){
    if(As.size() == N){
        long long point =0;
        for(int i=0; i<Q; i++){
            if(As[B[i]-1] - As[A[i]-1] == C[i]){
                point += D[i];
            }
        }
        //for(auto a: As){
        //    std::cout << a;
        //}
        //cout << " : " << point << endl;
        return point;
    }
    vector<int> result;
    for(int a=lower; a<=M; a++){
        vector<int> tmpAs = As;
        tmpAs.push_back(a);
        result.push_back(dfs(tmpAs, a));
    }
    int maxpoint = 0;
    for(auto x : result){
        maxpoint = max(maxpoint, x);
    }
    return maxpoint;
}

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> N >> M >> Q;
    for(int i=0; i<Q; i++){
        cin >> A[i] >> B[i] >> C[i] >> D[i];
    }

    vector<int> As;
    cout << dfs(As,1) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<algorithm>
#include <iomanip>
#include <cmath>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <vector>
#include <bitset>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>

constexpr int INF = 1050000000;
constexpr int MOD = 1000000007;
constexpr int LONGINF = 1005000000000000000;
using namespace std;

using ll = long long;


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

	int x = 1;

	while (x*2 <= n) {
		x *= 2;
	}

	cout << x << endl;






}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		int h[] = new int[n];
		int a[] = new int[m];
		int b[] = new int[m];

		for (int i=0; i<n; i++){
			h[i] = sc.nextInt();
		}

		for (int i=0; i<m; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
		}

		HashMap<Integer, HashSet<Integer>>map = new HashMap<Integer, HashSet<Integer>>();

		for (int i=1; i<=n; i++){
			map.put(i, new HashSet<Integer>());
		}

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

			HashSet<Integer> set = map.get(a[i]);
			set.add(b[i]);
			map.put(a[i], set);

			set = map.get(b[i]);
			set.add(a[i]);
			map.put(b[i], set);
		}

		int ans = 0;
		for (int i=0; i<n; i++){
			int fromH = h[i];
			HashSet<Integer> set = map.get(i+1);
			boolean bool= true;
			for (int to :set) {
				if (fromH <= h[to-1]){
					bool = false;
					break;
				}
			}
			if (bool){
				ans++;
			}
		}
		System.out.println(ans);
	}


}

Measured memory_bytes: 91764
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a,i;
  cin>>n;
  vector<int> d(n);
  for (i=0;i<n;i++) cin>>d.at(i);
  sort(d.begin(),d.end());
  a=1;
  for (i=1;i<n;i++) if (d.at(i-1)<d.at(i)) a++;
  cout<<a<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
#define endl "\n";
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
 
ll const inf = 1e18;
ll const maxn = 1e6+5;
ll const mod = 998244353;
 
// code begins here

int main(){
    fast;
    
    string s,t;
    cin>>s>>t;
    
    ll cnt = 0, n = s.length();
    
    for(ll i=0;i<n;i++)
        if(s[i]!=t[i])
            cnt++;
            
    cout<<cnt<<endl;
    
    return 0;
}

Measured memory_bytes: 3796
/*input
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define pb push_back
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define mpr make_pair
#define MX 1000000007
#define ui unsigned int
#define ll long long
#define ld long double
#define fi first
#define se second
#define testcases int testcases;cin>>testcases;while(testcases--)
#define printvector(v) for(int i=0;i<v.size();i++) cout<<v[i]<<" ";  cout<<endl
#define printarray(v,n)  for(int i=0;i<n;i++) cout<<v[i]<<" ";  cout<<endl
#define inputarray(v,n)  for(int i=0;i<n;i++)cin>>v[i]
#define debug(i) cout<<"debug: "<<i<<endl
#define pr(i) cout<<i<<endl
#define timetaken cerr<<clock()/double(CLOCKS_PER_SEC)<<endl
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define toDigit(a) (a-'0')
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

ll cal(int n, vector<pair<int,ll>>& a, ll w, int sum){
    vector<vector<ll>>dp(n+1,vector<ll>(sum+1));
    
    for(int i=1;i<=sum;++i) dp[0][i] = MX;
    
    dp[1][a[0].se] = a[0].fi;
    
    dp[1][0] = 0;
    
    for(int i=1;i<=n;++i){
        for(int j=0;j<=sum;++j){

            dp[i][j] = dp[(i-1)][j];
            
            if(a[i-1].se <= j){
                dp[i][j] = min(dp[i][j], dp[(i-1)][j-a[i-1].se] + a[i-1].fi);
            }
        }
    }
    //return dp[n%2][sum];
    ll ans;
    
    // while(lo <= hi){
    //     ll mid = (lo+hi)>>1;
    //     if(dp[n%2][mid] <= w){
    //         ans = mid;
    //         lo = mid+1;
    //     } 
    //     else hi = mid-1;
    // }

    for(int i=0;i<=sum;++i){
        if(dp[n][i] <= w)
            ans = i;
    }
    return ans;
}

int main() {
    fast_io;
    ll n,w;
    cin>>n>>w;
    
    vector<pair<int,ll>>a(n);
    int sum = 0;
    for(int i=0;i<n;++i){
        cin>>a[i].fi>>a[i].se;
        sum += a[i].se;
    }
    
    pr(cal(n,a,w,sum));
    return 0;
}

Measured memory_bytes: 80384
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int i,p[10000001],d[10000001];
 
int32_t main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     int t,n,ans=0,k,j;
     cin>>n;
      for(i=1;i<=n;i++)d[i]=1;
      for(i=2;i<=n;i++){if(p[i])continue;
          for(j=i;j<=n;j+=i){
              p[j]=1;
              k=1;t=j;
              while(t%i==0){
                  k++;
                t/=i;  
              }
              d[j]*=k;
          }
      }
      for(i=1;i<=n;i++){ans+=i*d[i];}
      cout<<ans;
    return 0;
}

Measured memory_bytes: 159920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadInts();
            var ans = 0;
            var list = new List<int>();
            list.Add(input[0] + input[1]);
            list.Add(input[1] + input[2]);
            list.Add(input[2] + input[0]);
            WriteLine(list.Min());
        }

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


Measured memory_bytes: 13268
#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;


const long long int mod = 1000000007;
const long long int INF = 99999999999999999;



long long int N,M,K,H,W,A[35]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
long long int a,b,c;
int main()
{
    cout << fixed << setprecision(18);
    cin>>a>>b>>c;
    IFYes(c>a+b&&4*a*b<(c-a-b)*(c-a-b));
    
}


Measured memory_bytes: 256
import Control.Monad
import Data.Set hiding (map)

main :: IO ()
main = do
  l1 <- getLine
  let [n, k] = map read $ words l1 :: [Int]
  lk <- replicateM k $ getLine *> getLine
  let ak = map (map read . words) lk :: [[Int]]
      holder = unions $ map fromList ak

  print $ n - size holder


Measured memory_bytes: 6160
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  if (b % a == 0)
    Cout(a + b);
  else
    Cout(b - a);
  return 0;
}

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

int main() {

  int a,b,c,sum ; cin >> a >> b >> c >> sum ; 
  int ans = 0 ; 
   
  for ( int i = 0 ; i <= a ; i++ ){
     for ( int j = 0 ; j <= b ; j++ ){
     	int goukei = sum - (500*i + 100*j) ;
        if ( goukei%50 == 0 and (0 <= goukei/50 and goukei/50 <= c) ) ans ++ ;
        }
     }
   cout << ans ; 
}

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

const int N=1e5+9;

int first[N], nxt[N<<1], v[N<<1], w[N<<1];

int tot=0;
inline void add(int f, int t, int c) {
	++tot;
	v[tot]=t;
	nxt[tot]=first[f];
	first[f]=tot;
	w[tot]=c;
}
	
int n;
unsigned long long dis[N];
void dfs(int k, int fa) {
//	debug(k);
//	debug(fa);
	for (int j=first[k]; j; j=nxt[j]) {
		if (v[j]==fa) {
			continue;
		}
		dis[v[j]]=dis[k]+w[j];
		dfs(v[j], k);
	}
}

int main(void) {
	scanf("%d", &n);
	int f, t, w;
	for (int i=1; i<n; i++) {
		scanf("%d%d%d", &f, &t, &w);
		add(f, t, w);
		add(t, f, w);
	}
	int q, k;
	scanf("%d%d", &q, &k);
	dis[k]=dis[0]=0;
	dfs(k, -1);
	//for (int i=1; i<=n; i++) {
	//	cout<<dis[i]<<'\n';
	//}
	while (q--) {
		scanf("%d%d", &f, &t);
		printf("%lld\n", dis[f]+dis[t]);
	}
	return 0;
	
}

Measured memory_bytes: 9984
N, W = map(int,input().split())
ws = []
vs = []
for _ in range(N):
   w,v = map(int,input().split())
   ws.append(w)
   vs.append(v)
# i番目の重みws[i], 価値vs[i]
def solve(N, W, ws, vs):
    # V = 全ての品物の価値の総和
    V = sum(vs)

    # 初期値は価値0以外の重さを上限より大きく
    dp = [W+1] * (V + 1)
    dp[0] = 0
    for i in range(N):
        # 価値v, 重さw
        v = vs[i]; w = ws[i]
        for j in range(V, v-1, -1):
            dp[j] = min(dp[j-v] + w, dp[j])

    # 重さが上限以下の価値のうち、最大の価値が解
    return max(i for i in range(V+1) if dp[i] <= W)

print(solve(N,W,ws,vs))

Measured memory_bytes: 40940
#!/usr/bin/env python3
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools


def input_int_list():
    return list(map(int, input().split()))


def input_int_list_with_length(length=None):
    if length == None:
        length = int(input())
    return list(map(int, input().split()))[:length]


def list_uniq_count(l):
    return len(set(l))


def solve(N: int, K: int):
    l = []
    for _ in range(K):
        l += input_int_list_with_length()
    print(N-list_uniq_count(l))


def main():
    solve(*input_int_list())


if __name__ == '__main__':
    main()


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

int main() {
  int a,c=0;
  cin>>a;
  vector<int> p(a);
  for(int i=0;i<a;i++)
    cin>>p[i];
  for(int i=1;i<a-1;i++){
    if(p[i-1]<p[i]&&p[i]<p[i+1])
      c++;
    else if(p[i+1]<p[i]&&p[i]<p[i-1])
      c++;
  }
  cout<<c;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long //记得longlong！！
using namespace std;
int n,a[200003],fsum[200003],bsum[200003],ans=-2e18,sum,su; //fsum[i]代表的是与i奇偶性相同的数的前缀和，bsum[i]代表的是与i奇偶性相同的数的后缀和
signed main()
{
	scanf("%lld",&n);
	for(int i=1; i<=n; i++)
		scanf("%lld",&a[i]);
	fsum[1]=a[1],fsum[2]=a[2],bsum[n]=a[n],bsum[n-1]=a[n-1];
	for(int i=3; i<=n; i++)
		fsum[i]=fsum[i-2]+a[i];
	for(int i=n-2; i>=1; i--)
		bsum[i]=bsum[i+2]+a[i];
	sum=fsum[n];
	if(n%2==0)
	{
		ans=max(fsum[n-1],fsum[n]);
		for(int i=1; i<=n; i+=2)
			ans=max(ans,fsum[i]+bsum[i+3]);
		cout<<ans;
		return 0;
	}
	for(int i=1; i<=n; i++)
		if(i%2==0)
			su+=a[i];
		else
			su=max(su-a[i],-a[i]),ans=max(ans,sum+su); //最大子段和
	cout<<ans;
	return 0;
}

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

#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define lg long long
#define db double
#define lb(x) ((x)&-(x))
#define ft first
#define sd second

#define HII cerr<<"HI"<<endl
#define LLLINE cerr<<"@@@@@@@@@@@@@@@@@@@@"<<endl

template <class _T_>
void read(_T_& d){
	d=0;int f=1;char c=getchar();
	for(;c<'0'||c>'9';c=getchar())if(c=='-')f*=-1;
	for(;c>='0'&&c<='9';c=getchar())d=d*10+c-'0';
	d*=f;
}

/************************************************/
#define MN 300005
#define Md 1000000007
#define _A(x,y) (x)=((x)+(y))%Md
#define _S(x,y) (x)=((x)-(y)+Md)%Md
int n;
char c[MN];
int dp[3][3][MN];
int main(){
	scanf("%s",c+1);
	n=strlen(c+1);
	dp[0][0][0]=1;
	int res=1;
	for(int i=1;i<=n;++i){
		if(c[i]=='?')_A(res,res);
		if(c[i]=='0'||c[i]=='?'){
			_A(dp[0][1][i],dp[0][2][i-1]);
			_A(dp[0][1][i],dp[0][0][i-1]);
			_A(dp[0][2][i],dp[0][1][i-1]);
			_A(dp[1][1][i],dp[1][2][i-1]);
			_A(dp[1][1][i],dp[1][0][i-1]);
			_A(dp[1][2][i],dp[1][1][i-1]);
			_A(dp[2][1][i],dp[2][2][i-1]);
			_A(dp[2][1][i],dp[2][0][i-1]);
			_A(dp[2][2][i],dp[2][1][i-1]);
		}
		if(c[i]=='1'||c[i]=='?'){
			_A(dp[0][0][i],dp[0][1][i-1]);
			_A(dp[0][1][i],dp[0][2][i-1]);
			_A(dp[1][0][i],dp[0][0][i-1]);
			_A(dp[1][0][i],dp[1][1][i-1]);
			_A(dp[1][1][i],dp[1][2][i-1]);
			_A(dp[2][0][i],dp[1][0][i-1]);
			_A(dp[2][0][i],dp[2][1][i-1]);
			_A(dp[2][1][i],dp[2][2][i-1]);
		}
	}
	_S(res,dp[0][1][n]);
	_S(res,dp[1][2][n]);
	cout<<res;
	return 0;
}


Measured memory_bytes: 11136
import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
graph = [list() for _ in range(n**2)]

id_index = [[i+j*n for i in range(n)] for j in range(n)]
index_list = []

def toId(p, o):
    if p > o:
        index = id_index[o][p]
        index_list.append(index)
        return index
    else: return id_index[p][o]

v_len = [-1 for _ in range(n)] * n
finished = [False for _ in range(n)] * n

def dfs(id):
    next_list = graph[id]

    if v_len[id] != -1:
        if not finished[id]:
            print(-1)
            sys.exit()
        return v_len[id]

    v_len[id] = 1

    for next in next_list:
        v_len[id] = max(v_len[id], dfs(next)+1)

    finished[id] = True
    return v_len[id]

for p in range(n):
    a = [toId(p, int(x)-1) for x in input().split()]
    for i in range(n-2):
        graph[a[i]].append(a[i+1])
    
ans = 0

for id in index_list:
    ans = max(dfs(id), ans)

print(ans)

Measured memory_bytes: 222692
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a=1;
  int i;
  for(i=1;i<=n;i++) {
    a*=i;
    a=a%1000000007;
  } 
  cout << a << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

ll frac[100100];

ll comb(ll a, ll b) {
  ll ue = frac[a];
  ll sh1, sh2;
  ll h=mod-2;
  ll two;
  while(h>0) {
    two = 1;
    sh1 = frac[b];
    sh2 = frac[a-b];
    while(2*two<h) {
      two *= 2;
      sh1 *= sh1;
      sh1 %= mod;
      sh2 *= sh2;
      sh2 %= mod;
    }
    h -= two;
    ue *= sh1;
    ue %= mod;
    ue *= sh2;
    ue %= mod;
  }
  return ue;
}

int main() {
  frac[0] = 1;
  for(ll i=1;i<100100;++i) frac[i] = frac[i-1]*i%mod;
  ll N, M;
  cin>>N>>M;
  vector<ll> prime;
  map<ll, ll> amap;
  for(ll i=2;i*i<=M;++i) {
    if(M%i==0) prime.push_back(i);
    while(M%i==0) {
      amap[i]++;
      M /= i;
    }
  }
  if(M>1) prime.push_back(M);
  amap[M]++;
  ll ans = 1;
  for(int i=0;i<prime.size();++i) {
    ans *= comb(amap[prime[i]]+N-1, N-1);
    ans %= mod;
  }
  cout<<ans<<endl;
}



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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec)
        is >> x;
    return is;
}

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int w, h, x, y;
    cin >> w >> h >> x >> y;

    double dw = w;
    double dh = h;
    cout << (dw * dh / (double)2.0) << " ";

    if(x == 0 or y == 0)
        cout << 0 << endl;
    else if(w / x == 2 and w % x == 0 and h / y == 2 and h % y == 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>

int main(void){
    int h,w,count;
    scanf("%d%d",&h,&w);
    char a[h][w+2];
    for (int i=0; i<h; i++){
        scanf("%s",a[i]);
    }
    for (int i=0; i<h; i++){
        count=0;
        for (int j=0; j<w; j++){
            if (a[i][j]=='.'){
                count++;
            }
        }
        if (count==w){
            for (int j=i; j<h; j++){
                strcpy(a[j],a[j+1]);
            }
            i--;
            h--;
        }
    }
    
    for (int i=0; i<w; i++){
        count=0;
        for (int j=0; j<h; j++){
            if(a[j][i]=='.'){
                count++;
            }
        }
        if(count==h){
            for (int j=0; j<h; j++){
                for (int k=i; k<w; k++){
                    a[j][k]=a[j][k+1];
                }
            }
            i--;
            w--;
        }
    }
    for (int i=0; i<h; i++){
        for (int j=0; j<w; j++){
        printf("%c",a[i][j]);
        }
        printf("\n");
    }
    
    
    
	return 0 ;
}

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

int main(void) {
	int p,i,l;
	char s[128];
	while(scanf("%s",s) , s[0] != '#'){
		l = strlen(s);
		p = 1;
		for(i = 0;i < l;i++){
			if(p == 1){//A city
				if(s[i] == '0'){p=2;}else{p=3;}
			}
			else if(p == 2){//X city
				if(s[i] == '0'){p=114514;}else{p=4;}
			}
			else if(p == 3){//Y city
				if(s[i] == '0'){p=2;}else{p=114514;}
			}
			else if(p == 4){//Z city
				if(s[i] == '0'){p=5;}else{p=6;}
			}
			else if(p == 5){//W city
				if(s[i] == '0'){p=6;}else{p=3;}
			}
			else if(p == 6){//B city
				if(s[i] == '0'){p=3;}else{p=2;}
			}
			if(p == 114514){break;}
		}
		if(p == 6){printf("Yes\n");}else{printf("No\n");}
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back

const int N = 1e5;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
int jum[N + 5];
int main(){
  string s, ss = "";
  cin >> s;
  for(int i = 0;i < s.length(); ++i){
    if(s[i] != 'x'){
      ss += s[i];
    }
  }
  string sss = ss;
  reverse(sss.begin(), sss.end());
  if(ss != sss){
    puts("-1");
    return 0;
  }
  else if(ss == ""){
    puts("0");
    return 0;
  }
  else{    
    int len = (int) ss.length();
    int tengah = (int) ss.length() / 2;
    int before = 0, after = 0;
    int poi = 0;
    for(int i = 0;i < s.length(); ++i){
      if(s[i] == 'x'){
        if(poi == 0) before++;
        else if(poi == len) after++;
        else{
          if(poi > tengah){
            if(len & 1){
              jum[poi - tengah - 1]--;
            }
            else{
              jum[poi - tengah]--;
            }
          }
          else{
            jum[tengah - poi]++;
          }
        }
      }
      else poi++;
    }

    int ans = abs(after - before);
    for(int i = 1;i <= tengah; ++i){
      ans += abs(jum[i]);
    }
    if(len & 1) ans += abs(jum[0]);
    cout << ans << endl; 
  }
  return 0;
}


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

int main(){
    int n,m;
    cin>>n;
    map<string,int> mp;
    string s,t;
    rep(i,n){
        cin >>s;
        mp[s]++;
    }
    cin>>m;
    rep(i,m){
        cin >>t;
        mp[t]--;
    }
    int ans = 0;
    for(auto x:mp){
        ans = max(ans,x.second);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int a,b;
    while (1){
        cin >> a >> b;
        if ( a == 0 && b == 0 ) break;
        if ( a <= b ){
            cout << a << " " << b << endl;
        }else {
            cout << b << " " << a << endl;
        }
    }
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    int ans1 = 0;
    int ans2 = 0;
    int ans3 = 0;
    int tempX = X;
    int tempY = Y;
    // if (A + B > C * 2)
    while (tempX > 0 && tempY > 0)
    {
        ans1 += C * 2;
        tempX--;
        tempY--;
    }
    while (tempX > 0)
    {
        ans1 += A;
        tempX--;
    }
    while (tempY > 0)
    {
        ans1 += B;
        tempY--;
    }

    tempX = X;
    tempY = Y;
    while (tempX > 0 || tempY > 0)
    {
        ans2 += C * 2;
        tempX--;
        tempY--;
    }

    // else
    tempX = X;
    tempY = Y;
    while (tempX > 0)
    {
        ans3 += A;
        tempX--;
    }
    while (tempY > 0)
    {
        ans3 += B;
        tempY--;
    }
    // printf("ans1 = %d, ans2 = %d, ans3 = %d\n", ans1, ans2, ans3);
    int ans = min(ans1, min(ans2, ans3));
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.InputMismatchException;


public class Main {

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

		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int[][] a = new int[n][m];
		int[] b = new int[m];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				a[i][j] = sc.nextInt();
			}
		}
		for (int j = 0; j < m; j++) {
			b[j] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			int c = 0;
			for (int j = 0; j < m; j++) {
				c += a[i][j] * b[j];
			}
			System.out.println(c);
		}

		sc.close();
	}

	@SuppressWarnings("unused")
	private static class Scanner {
		InputStreamReader isr;
		BufferedReader br;
		StreamTokenizer st;

		private Scanner() {
		}

		Scanner (InputStream in) {
			isr = new InputStreamReader(in);
			br = new BufferedReader(isr);
			st = new StreamTokenizer(br);
		}

		String next() throws RuntimeException  {
			try {
				if (st.nextToken() != StreamTokenizer.TT_WORD) {
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return st.sval;
		}

		int nextInt() throws RuntimeException {
			try {
				if (st.nextToken() != StreamTokenizer.TT_NUMBER) {
					throw new InputMismatchException();
				}
			} catch (IOException e) {
				throw new IllegalStateException();
			}

			return (int)st.nval;
		}

		void close() {
		}
	}
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int niz[1000005];
const int MOD = 1000000007;

int main(){
    ios_base::sync_with_stdio(false);
	cout.precision(10);
	cout << fixed;

    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
    }
    sort(niz+1, niz+1+n);
    if(n%2){
        for(int i=1; i<=n; i+=2){
            if(niz[i] != i-1 || niz[i-1] != i-1){
                cout << 0;
                return 0;
            }
        }
        int res = 1;
        for(int i=1; i<=n/2; i++) res = (2*res)%MOD;
        cout << res;
        return 0;
    }
    for(int i=1; i<=n; i+=2){
        if(niz[i] != i || niz[i+1] != i){
            cout << 0;
            return 0;
        }
    }
    int res = 1;
    for(int i=1; i<=n/2; i++) res = (2*res)%MOD;
    cout << res;
    return 0;
}


Measured memory_bytes: 640
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 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:
                ans += 1
                
print(ans)

Measured memory_bytes: 3060
import Control.Monad
main = do
    [n,a,b] <- map read . words <$> getLine
--    h <- map read <$> (sequence $ replicate n getLine)
    h <- map read . words <$> getContents
    print $ solve h a b

inf :: Integer
inf = 10^9+1

solve ::[Integer] -> Integer -> Integer -> Integer
solve h a b = binalySearch inf 0 (f h a b)
  where binalySearch ::Integral a => a -> a -> (a -> Bool) -> a
        binalySearch ok ng f
          | abs (ok-ng) <= 1 = ng + 1
          | f mid = binalySearch mid ng f
          | otherwise = binalySearch ok mid f
            where mid = (ok + ng) `div` 2
        f ::[Integer] -> Integer -> Integer -> Integer -> Bool
        f h a b c = s <= c
          where list = [max 0 (hi - b*c + a - b - 1) `div` (a-b) | hi <- h]
                s = sum list

Measured memory_bytes: 17068
#include <iostream>

using namespace std;

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    x = x + d/a[i];
    if(d%a[i]!=0)x++;
  }
  
  cout << x <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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() {
  int N;
  cin >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  vector<ll> b(N);
  rep(i, N) cin >> b[i];

  ll sumA = 0;
  ll sumB = 0;
  rep(i, N) {
    sumA += a[i];
    sumB += b[i];
  }

  if (sumB < sumA) {
    cout << "No" << endl;
    return 0;
  }

  ll ope = sumB - sumA;
  ll opeA = 0;
  ll opeB = 0;
  rep(i, N) {
    if (a[i] > b[i]) {
      ll diff = a[i] - b[i];
      opeB += diff;
    } else if (a[i] < b[i]) {
      ll diff = b[i] - a[i];
      if (diff % 2 == 0) {
        opeA += diff / 2;
      } else {
        opeA += (diff + 1) / 2;
        opeB++;
      }
    }
  }

  if (opeA > ope || opeB > ope) {
    cout << "No" << endl;
    return 0;
  }

  ll resA = ope - opeA;
  ll resB = ope - opeB;

  if (resA * 2 != resB) {
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int N, M;
	cin >> N >> M;

	vector<pair<int, int>>A(N);
	vector<pair<int, int>>C(M);

	rep(i, N)
		cin >> A[i].first >> A[i].second;
	rep(i, M)
		cin >> C[i].first >> C[i].second;

	rep(i, N) {
		int ans = 0;
		int mind = INF;

		rep(j, M)
			if (abs(A[i].first - C[j].first) + abs(A[i].second - C[j].second) < mind)
				mind = abs(A[i].first - C[j].first) + abs(A[i].second - C[j].second), ans = j + 1;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
#define N 6
#define eps 0.00001
#define REP(i,b,n) for(int i=(int)b;i<(int)n;i++)
#define rep(i,n)  REP(i,0,n)
int gcd(int w,int m){
  return m == 0?w:gcd(m,w%m);
}

/*
double tw=weight[i][k]+weight[k+1][j];
double tmpr = max(weight[i][k]/tw+rcost[k+1][j],rcost[i][k]-weight[k+1][j]/tw);
double tmpl = max(weight[k+1][j]/tw+lcost[i][k],lcost[k+1][j]-weight[i][k]/tw );
double tmp = tmpr+tmpl;
if ( tmp <lim+eps && tmp >cost[i][j]){
*/

double ans = -1;


void solve(int n,int now,bool *used,double *rc,double *lc,double lim,double c,int *weight){
  if ( n-1 == now){
    ans = max(ans,c);
    return;
  }
  
  //left i , right j
  rep(i,n){
    if ( used[i] == true)continue;
    rep(j,n){
      if (i == j)continue;
      if ( used[j] == true)continue;
      double w = weight[i]+weight[j];
      double tmpr=max(weight[i]/w+rc[j],-weight[j]/w+rc[i]);
      double tmpl=max(weight[j]/w+lc[i],-weight[i]/w+lc[j]);

      if ( tmpr+tmpl >lim+eps){continue;}
      double tr=rc[i],tl=lc[i];int tw=weight[i];
      used[j]=true;
      rc[i]=tmpr;
      lc[i]=tmpl;
      weight[i]=weight[i]+weight[j];
      solve(n,now+1,used,rc,lc,lim,tmpr+tmpl,weight);
      rc[i]=tr;
      lc[i]=tl;
      weight[i]=tw;
      used[j]=false;
    }
  }
  
}

main(){
 int te;
 cin>>te;
 while(te--){
   int n;
   double r;
   cin>>r>>n;
   int inp[n];
   rep(i,n)cin>>inp[i];

   double rc[n],lc[n];
   bool used[n];
   rep(i,n)rc[i]=lc[i]=0,used[i]=false;
   ans=-1;

   solve(n,0,used,rc,lc,r,0,inp);
   if ( ans == -1)puts("-1");
   else printf("%.9lf\n",ans);
 }
}

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

  int main() {
    int N;
    cin >> N ;
    vector<int> H(N);
    vector<int> count(N);
    int upd=0;
    int j=0;

    for (int i=0; i<N; i++)
      cin >> H.at(i);

    for (int i=0; i<N-1; i++){
      if(H.at(i)>=H.at(i+1)){
        count.at(j)++ ;
        if(upd<count.at(j))
          upd=count.at(j);
        }
      else
        j++;
      
      }
    
    cout << upd << endl;
      
      
      
  }

    

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long 
#define ld long double
using namespace std;
const ll INF = 1e18;
const ll MOD = 998244353;

vector<string> vec_splitter(string s) {
		s += ',';
		vector<string> res;
		while(!s.empty()) {
				res.push_back(s.substr(0, s.find(',')));
				s = s.substr(s.find(',') + 1);
		}
		return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
		if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
		stringstream ss; ss << H;
		cerr << args[idx] << " = " << ss.str();
		debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define deb(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define deb(...) 42
#endif

ll func(vector<pair<int, ll>> vec, int m) {
	int n = vec.size();
	sort(vec.begin(), vec.end());
	ll ans = 0;
	set<pair<ll, int>> st;
	int cur = 0;
	for(int sz = 0; sz <= m; sz++) {
		deb(cur, sz);
		while(cur < n and vec[cur].first == sz) {
			if(vec[cur].second > 0)	st.insert({vec[cur].second, cur}), ans += vec[cur].second;
			if(st.size() > sz)	ans -= st.begin()->first, st.erase(st.begin());
			deb(vec[cur].first, vec[cur].second, sz);
			cur++;
		}
	}
	return max(ans, 0ll);
}

int32_t main() {
	ios::sync_with_stdio(!cin.tie(NULL));
		
	int t;
	cin >> t;
	while(t--){
		vector<pair<int, ll>> le, ri;
		int n;
		ll sum = 0;
		cin >> n;
		ll l, r, k;
		for(int i = 0; i < n; i++) {
			cin >> k >> l >> r;
			sum += min(l, r);
			if(l > r)	le.push_back({k, l - r});
			else	ri.push_back({n - k, r - l});
		}
		deb(sum);
		cout << func(ri, n) + func(le, n) + sum << "\n";
	}
}





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

int main() {
    int n,k;
    cin >> n >> k;
    
    vector<int> p(n);
    for (int i = 0; i < n; i++){
        cin >> p.at(i);
    }

    vector<int> p_sum(n-k+1,0);
    for (int i = 0; i < k; i++){
        p_sum[0]=p_sum[0]+p[i];
    }
    for (int i = 1; i < n-k+1; i++){
        p_sum[i]=p_sum[i-1]-p[i-1]+p[i-1+k];
    }

    int maxp_sum=0;
    for (int i = 0; i < n-k+1; i++){
        maxp_sum=max(maxp_sum,p_sum[i]);
    }
    double ans=0.5*(double)k+(double)maxp_sum/2.0;

    cout << fixed << setprecision(13) << ans << endl;
}

Measured memory_bytes: 4712
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn even(x: u64) -> bool {
    x % 2 == 0
}

fn odd(x: u64) -> bool {
    x % 2 == 1
}

fn main() {
    let v = read_vec::<u64>();
    let a = v[0];
    let b = v[1];

    if a == 0 && b == 0 {
        println!("0"); return;
    } else if a == b {
        println!("{}", a); return;
    }

    let mut ans = 0;
    if odd(a) && odd(b) {
        ans = a ^ (((b - a) / 2) % 2);
    } else if odd(a) && even(b) {
        ans = a ^ b ^ (((b - a - 1) / 2) % 2);
    } else if even(a) && odd(b) {
        ans = ((b - a + 1) / 2) % 2;
    } else if even(a) && even(b) {
        ans = b ^ (((b - a) / 2) % 2);
    }
    println!("{}", ans);

    /*
    let mut base = 1;
    let mut base_i = 0;
    let mut be = vec![0u64; 2];
    for i in 0.. {
        for (j, &n) in (vec![a, b]).iter().enumerate() {
            if n < base && be[j] == 0 {
                be[j] = base / 2;
            }
        }

        if be[0] > 0 && be[1] > 0 {
            break;
        }

        base *= 2;
        base_i += 1;
    }
    */

    /*
    let mut ans = a;
    for i in a+1..b+1 {
        ans = ans ^ i;
    }

    println!("{}", ans);
    */
}


Measured memory_bytes: 4352
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
using namespace std;
long long p[100000100],q[100000010],s[100000010],o;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m,a;
    cin>>n>>m;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>p[i];
        o+=p[i];
    }
    for(i=1;i<=m;i++)
    {
        cin>>q[i];
        o+=q[i];
    }
    sort(q,q+m+1);
    for(i=1;i<=m;i++)
        s[i]=s[i-1]+q[i];
    int l,r,mi,an;
    for(i=0;i<n;i++)
    {
        l=0;
        r=m;
        an=0;
        while(l<=r)
        {
            mi=(l+r)>>1;
            if(q[mi]<p[i])
            {
                l=mi+1;
                an=mi;
            }
            else r=mi-1;
        }
        o+=s[an]+p[i]*(m-an);
    }
    cout<<o<<'\n';
}


Measured memory_bytes: 2560
def 解():
    iN = int(input())
    aA = [int(_) for _ in input().split()]
    aDiff  = [0]*(iN-1)
    iD = sum(aA)
    iF = 0
    for i in range(iN-1):
        iF += aA[i]
        aDiff[i] = abs(iD - 2*iF)
    print(min(aDiff))
解()


Measured memory_bytes: 23784
n = int(input())
alphabet_histgram = [[0 for _ in range(n)] for _ in range(26)]
ord_a = ord("a")

for i in range(n):
    S = input()
    for c in S:
        alphabet_histgram[ord(c) - ord_a][i] += 1

ret = ""
for i, hist_c in enumerate(alphabet_histgram):
    ret += chr(ord_a + i) * min(hist_c)

print(ret)


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

int main() {
	char c[3][3];
	int i,j;
	for(i=0;i<3;i++){
		for(j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	for(i=0;i<3;i++){
		cout<<c[i][i];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#rest...使用数の残り
#n...今見る数字
#acc...今までの合計
#to...目的の値

def counter(rest, n, acc, to):
  #残り使用数が0なら...acc == to -> 1,  acc != to -> 0
  if rest == 0:
    return acc == to

  #nが使える数(9)を超えたら終了
  if n == 10:
    return 0
  
  #nを使った場合と使わなかった場合の合計の数を出力
  return counter(rest - 1, n + 1, acc + n , to) + counter(rest, n + 1, acc, to)

while True:
  n, s = map(int, input().split())

  if not n:
    break

  print(counter(n, 0, 0, s))


Measured memory_bytes: 5596
/*
 * ex7-1
 * kamecha
 */
#include<stdio.h>

typedef struct point{
    int x_elem;
    int y_elem;
}point;

//構造体の足し算
point add(point a, point b){
    point tmp = {0, 0};
    tmp.x_elem = a.x_elem + b.x_elem;
    tmp.y_elem = a.y_elem + b.y_elem;
    return tmp;
}

point dec(point a, point b){
    point tmp = {0, 0};
    tmp.x_elem = a.x_elem - b.x_elem;
    tmp.y_elem = a.y_elem - b.y_elem;
    return tmp;
}

//頂点を原点から90度反時計回りに(正方形の形に沿って)シフト
point shift_point(point ptr){
    point vec = {-ptr.y_elem, ptr.x_elem};
    return add(vec, ptr);
}

int main(void){
    point p1, p2, p3, p4;
    scanf("%d", &p1.x_elem);
    scanf("%d", &p1.y_elem);
    scanf("%d", &p2.x_elem);
    scanf("%d", &p2.y_elem);
    p3 = add(p1, shift_point(dec(p2, p1)));
    p4 = add(p2, shift_point(dec(p3, p2)));
    printf("%d %d %d %d\n", p3.x_elem, p3.y_elem, p4.x_elem, p4.y_elem);
    return 0;
}


Measured memory_bytes: 1680
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)

using namespace std;

#define X real()
#define Y imag()

typedef double D;
D EPS = 1e-8;

typedef complex<D> P;
struct L{
    P a, b;
    P vec(){ return b - a; }
};
typedef vector<P> Pol;

int sig(D a) { return a < -EPS ? -1 : a > EPS ? 1 : 0; }
D dot(P a, P b){ return a.X * b.X + a.Y * b.Y; }
D cross(P a, P b){ return a.X * b.Y - a.Y * b.X; }

D area(Pol pol) {
    int n = pol.size();
    D res = 0;
    REP(i, n) {
        res += cross(pol[i], pol[ (i + 1) % n ]);
    }
    return abs(res) / 2.0;
}

int main(){
    int n;
    int t = 0;
    while(cin >> n && n > 0) {
        Pol pol(n);
        REP(i, n) {
            double x, y;
            cin >> x >> y;
            pol[i] = P(x, y);
        }
        printf("%d %.1f\n", ++t, area(pol));
    }
    return 0;
}

Measured memory_bytes: 1244
H=int(input())+1
A=[0]+list(map(int,input().split()))
def h(i):
 l=2*i;r=l+1
 if l<H and A[i]<A[l]:g=l
 else:g=i
 if r<H and A[g]<A[r]:g=r
 if g>i:A[i],A[g]=A[g],A[i];h(g)
for i in range(H//2,0,-1):h(i)
print(' '+' '.join(map(str,A[1:])))


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
  }
  double avg = (double)sum / n;
  double mindf = 100.0;
  for(int i = 0; i < n; i++){
    double dif = abs(a[i] - avg);
    mindf = min(mindf, dif);
  }
  for(int i = 0; i < n; i++){
    if(abs(a[i]-avg)==mindf){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n1,m1,n2,m2,k,h1,h2,h3;
	cin>>n1>>m1>>n2>>m2>>k;
	if(n2-n1<0)
	{
		h1=n2-n1+24;
	}
	else
	{
		h1=n2-n1;
	}
	if(m2-m2<0)
	{
		h2=m2-m1+60;
		h1--;
	}
	else
	{
		h2=m2-m1;
	}
	h3=h1*60+h2;
	if(h3-k>=0)
	cout<<h3-k;
	else
	cout<<0;
} 

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    while(true){
        cin >> n >> x;
        if(n==0 && x==0)break;
    int ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(i+j+k == x)ans++;
            }
        }
    }
    cout << ans << endl;
    }
    
}


Measured memory_bytes: 3096