akhauriyash/Code-Regression huggingface dataset:
import sys
from math import ceil, floor
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def main():
    n,m = map(int, input().split())
    p = 1 / 2**(m)
    t = 100*(n-m) + 1900*m
    ans = 0    
    
    # 正解する確率: p
    # i回目に正解する確率: (p-1)^(i-1) * p
    print(int( (-1) * ((p-1)*t) / ((1-p)*p)))
    return

if __name__ == '__main__':
    main()

Measured memory_bytes: 5052
#include<stdio.h>

int main(){
    int N,i;
    int a_max=0;
    int a_max_next=0;
    scanf("%d",&N);
    int A[N];

    for(i=0;i<N;i++){
        scanf("%d",&A[i]);
        if(A[i]>a_max){
            a_max=A[i];
        }else if(A[i]>=a_max_next){
            a_max_next=A[i];
        }
    }

    for(i=0;i<N;i++){
        if(A[i]==a_max){
            printf("%d\n",a_max_next);
        }else{
            printf("%d\n",a_max);
        }
    }
    
    return 0;
}

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

using namespace std;
 
#define PB	push_back
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP	make_pair
 
#define debug(_x)		cerr << #_x << '=' << (_x) << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << (_x) << ' ' << #_y << '=' << (_y) << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << (_x) << ' '; cerr << endl;

#define HERE debug(__LINE__);

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef pair<pair<int, int>, int> iii;
typedef vector<int> vi;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;

const int INF = LONG_LONG_MAX>>1;
const int NINF = LONG_LONG_MIN/2;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	int a[n], b[n], c[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}
	
	vvi dp(n+1, vi(3));
	
	for (int i = 1; i <= n; i++) {
		dp[i][0] = max(a[i-1] + dp[i-1][1], a[i-1] + dp[i-1][2]);
		dp[i][1] = max(b[i-1] + dp[i-1][0], b[i-1] + dp[i-1][2]);
		dp[i][2] = max(c[i-1] + dp[i-1][0], c[i-1] + dp[i-1][1]);
	}
	
	cout << max(dp[n][0], max(dp[n][1], dp[n][2])) << endl;
}

// g++ -Wall -Wextra -Wshadow -fsanitize=undefined


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

vector<vector<int>> bitExplore(int n)
{
  vector<vector<int>> ret;
  for (int bit = 0; bit < (1 << n); ++bit)
  {
    vector<int> S;
    for (int i = 0; i < n; ++i)
    {
      if (bit & (1 << i))
      {
        S.push_back(i);
      }
    }

    ret.push_back(S);
  }
  return ret;
}


int blacks(vector<string> graph)
{
  int cnt = 0;
  for (auto && a : graph) 
  for (auto && b : a)
  {
    if (b == '#') cnt++;
  }
  return cnt;   
}

int main(){
  int h,w,k;cin>>h>>w>>k;
  vector<string> g(h);
  for (auto && a : g) {
    cin >> a;
  }
  ll ans = 0;
  auto choseH = bitExplore(h);
  auto choseW = bitExplore(w);
  
  for (auto && i : choseH)
  for (auto && j : choseW)
  {
    auto newg = g;
    for (auto && a : i)
    {
      for (int tmp = 0; tmp < w; tmp++) {
        newg.at(a).at(tmp) = '.';
      }
    }
    for (auto && a : j)
    {
      for (int tmp = 0; tmp < h; tmp++) {
        newg.at(tmp).at(a) = '.';
      }
    }
    if(blacks(newg) == k) ans++;

      
  }
    
    
  cout << ans << endl;
}

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N);
  while (cin >> N) a.at(N - 1)++;
  for (M = 0; M < a.size(); M++) cout << a.at(M) << endl;
}

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

using namespace std;

const int N = 1e5+5;
int parent[N],sz[N];

void make_set(int v) {
    parent[v] = v;
    sz[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (sz[a] < sz[b])
            swap(a, b);
        parent[b] = a;
        sz[a] += sz[b];
    }
}

int main(){
    int n;
    scanf("%d",&n);
    vector<pair<int,int>> xvec,yvec;
    vector<pair<int,pair<int,int>>> evec;
    for(int i = 0; i<n; i++){
        int x,y;
        scanf("%d%d",&x,&y);
        xvec.push_back({x,i});
        yvec.push_back({y,i});
    }
    sort(xvec.begin(),xvec.end());
    sort(yvec.begin(),yvec.end());
    for(int i = 0; i<n-1; i++){
        evec.push_back({xvec[i+1].first-xvec[i].first,{xvec[i].second,xvec[i+1].second}});
        evec.push_back({yvec[i+1].first-yvec[i].first,{yvec[i].second,yvec[i+1].second}});
    }
    for(int i = 0; i<n; i++)
        make_set(i);
    sort(evec.begin(),evec.end());
    long long ans = 0;
    for(auto it:evec){
        int a,b;
        tie(a,b)=it.second;
        if(find_set(a)!=find_set(b)){
            union_sets(a,b);
            ans += it.first;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 8888
#include <stdio.h>
#define N 10000
#define NIL -1

typedef struct node{
    int p,l,r;
}Node;

Node T[N];
int n;

void preP(int u){
    if(u==NIL) return;
    printf(" %d",u);
    preP(T[u].l);
    preP(T[u].r);
}

void inP(int u){
    if(u==NIL) return;
    inP(T[u].l);
    printf(" %d",u);
    inP(T[u].r);
}

void postP(int u){
    if(u == NIL) return;
    postP(T[u].l);
    postP(T[u].r);
    printf(" %d",u);
}
int main(void){
    int i,v,l,r,root;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        T[i].p=NIL;
      }
    for(i=0; i<n; i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l != NIL)
            T[l].p=v;
        if(r != NIL)
            T[r].p=v;
    }
    for(i=0; i<n; i++){
        if(T[i].p == NIL){
            root=i;
          }
        }
    puts("Preorder");

    preP(root);

    puts("");
    puts("Inorder");

    inP(root);

    puts("");
    puts("Postorder");

    postP(root);
    puts("");

    return 0;
}



Measured memory_bytes: 2036
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
//#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define FOR(i,n)  for(ll i=0;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define rev(p) reverse(p.begin(),p.end());
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define popcount(x) __builtin_popcountll(x)
#define sz(x) ((ll)x.size())
const ll M=1000000007;
const ll MM=998244353;
int begtime = clock();
#define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";

 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

template<typename T,typename F>
void chmax( T &a,F b){
  if(b>a)a=b;
}

template<typename T,typename F>
void chmin( T &a,F b){
  if(b<a)a=b;
}




const ll N=1e5+5;

ll sp[N];

void sieve(){
  for(int i=1;i<N;i++)sp[i]=i;

    for(int i=2;i<N;i++){
      if(sp[i]==i){
        for(int j=i*i;j<N;j+=i){
          if(sp[j]==j)sp[j]=i;
        }
      }
    }
}

  

int main()
{ 

IOS;

ll n,k;
cin>>n>>k;

vl a(n+1);

FOR(i,n)cin>>a[i+1];

queue<ll>q;

for(int i=k+1;i<=n;i++){
  if(a[i]>a[i-k])q.push(1);
  else q.push(-1);
}

for(int i=k+1;i<=n;i++){
  ll x=q.front();
  q.pop();
  if(x==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
 // if(a[i]>a[i-1])q.push(1);
  //else q.push(-1);
}



//end_routine();

return 0;
 
}


Measured memory_bytes: 6336
fn b() {
    input! {
        n: usize,
    }

    let mut ans: Vec<u32> = vec![0; 4];

    for _ in 0..n {
        input! {
            sv: String
        }
        if sv == "AC" {
            ans[0] += 1;
        }
        else if sv == "WA" {
            ans[1] += 1;
        }
        else if sv == "TLE" {
            ans[2] += 1;
        }
        else {
            ans[3] += 1;
        }
    }
    println!("AC x {}", ans[0]);
    println!("WA x {}", ans[1]);
    println!("TLE x {}", ans[2]);
    println!("RE x {}", ans[3]);
}

use proconio::input;

fn main() {
    b();
}

Measured memory_bytes: 2552
tmp = list(range(1,int(input())+1))

#tmp = copy.copy(N)
res = 0
for i in range(len(tmp)):
    if tmp[i] % 3 != 0 and tmp[i] % 5 != 0 and tmp[i] % 15 != 0:
        res += tmp[i]

print(res)

Measured memory_bytes: 48368
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    REP(i, N) cin >> a[i];
    llint ans = 0;
    REP(i, N-1){
        if(a[i]+a[i+1] > x){
            // cout << a[i+1] << " " << a[i]+a[i+1]-x << "\n";
            ans += min(a[i+1], a[i]+a[i+1]-x);
            a[i+1] -= min(a[i+1], a[i]+a[i+1]-x);
            if(a[i] - x > 0){
                ans += (a[i] - x);
                a[i] -= (a[i] - x);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  as <- getIntList

  let calcUppers [] !m !ups = ups
      calcUppers (a:as) !m !ups = let nleaf = a
                                      nparen = m - a
                                      m' = if nparen < maxBound `div` 2 then nparen * 2 else maxBound
                                  in calcUppers as m' (m:ups)

      ups :: [Int]
      ups = calcUppers as 1 []

      va = V.fromList as

      solve i []     nleaf maxpar res = res
      solve i (x:xs) nleaf maxpar res = let minpar = (maxpar + 1) `div` 2
                                            c = min x (nleaf + maxpar)
                                            res' = c + res
                                            i' = i - 1
                                            nleaf' = va V.! i'
                                        in if x < (nleaf + minpar)
                                           then -1
                                           else solve i' xs nleaf' c res'
--  print ups
  print $ solve n ups (va V.! n) 0 0



Measured memory_bytes: 24568
function Main(input) {
  input = input.split(" ");

  var N = ~~input[0];
  var A = ~~input[1];
  var B = ~~input[2];

  var Problem = function(){
    this.N = N;
    this.A = A;
    this.B = B;
  }

  Problem.prototype = {
    procedure: function(){
      var count = 0;
      for(var i=1; i<=N; i++){ // 1, 2, 3, 4, 5....1234,1235,1236...
        var numArray = String(i).split("").map(x => ~~x); //1234 => [1,2,3,4]
        var sum=0;
        for(eachNum of numArray){
          sum = sum+eachNum; // 1+2+3+4
        }
        if(this.A <= sum && sum <= this.B){
          //console.log(sum);
          count=count+i; // count=0+1234;
        }
      }
      return count;
    }
  }

  var problem = new Problem();
  console.log(problem.procedure());

  // console.log('%d %d',N,Q);
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 11636
/*数组有没有开小
有没有开long long
会不会爆long long
初始化（多组数据，一定要记得把数组清零！！！）
时刻小心数组/容器是否为空
最后容器中剩余是否需要加入答案 
位运算结果的数组，要开2倍。位运算时注意结果的范围可能大于两个数的范围
要考虑边界情况(n=0?n=1?n=最大值?) 
注意变量名(尤其注意:n,n2 i,j)
开bool时注意取值不能为0~2
*/
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1e5+5;
int n,m,q[N],f[N],g[N],ans[N];
char s[N];

int main()
{
	n=read();m=read();
	scanf("%s",s);
	ri l=1,r=1;
	rep(i,1,n){
		if(s[i]=='1'){
			f[i]=n+n;continue;
		}
		while(l<=r&&i-q[l]>m)++l;
		if(l<=r)f[i]=f[q[l]]+1,g[i]=q[l];
		else f[i]=n+n,g[i]=0;
		while(l<=r&&f[i]<f[q[r]])--r;
		q[++r]=i;
	}
	//rep(i,1,9) cout<<i<<":"<<f[i]<<' '<<g[i]<<endl;
	if(f[n]>n){
		cout<<-1;return 0;
	}
	ri x=n,y=f[n];
	while(x){
		ans[y]=x-g[x];--y;
		x=g[x];
	}
	rep(i,1,f[n])printf("%d ",ans[i]);
	return 0; 
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N, A; scanf("%d %d", &N, &A);
  vector<int> X(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &X[i]);
    X[i] -= A;
  }

  int T = N * 50;
  vector<vector<ll>> dp(N + 5, vector<ll>(2 * T + 5, 0));
  dp[0][T] = 1;
  for (int i = 1; i <= N; ++i) {
    for (int j = 0; j <= 2 * T; ++j) {
      dp[i][j] = dp[i - 1][j];
      if (j - X[i - 1] >= 0 and j - X[i - 1] <= 2 * T) {
        dp[i][j] += dp[i - 1][j - X[i - 1]];
      }
    }
  }

  ll ans = dp[N][T] - 1;
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2432
import heapq as hp
def solution():
    n, m = map(int, input().split())
    a = [int(aa) * -1 for aa in input().split()]
    hp.heapify(a)
    for i in range(m):
        hp.heappush(a, (hp.heappop(a)*-1 // 2) * -1)
    print(abs(sum(a)))

solution()


Measured memory_bytes: 14180
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

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

	while (n != 0 || m != 0) {
		int *taro = new int[ n ];
		int *hana = new int[ m ];
		int sum = 0;
		int sum_t = 0;
		int sum_h = 0;

		for (int i = 0; i < n; i++) {
			cin >> taro[i];
			sum += taro[i];
			sum_t += taro[i];
		}
		for (int i = 0; i < m; i++) {
			cin >> hana[i];
			sum += hana[i];
			sum_h += hana[i];
		}
		if (sum % 2 != 0){
			cout << -1 << endl;
		}else{
			int swap_t,swap_h;
			bool find = false;
			sum = sum / 2;
			for (int i = 0; i < n && !find; i++) {
				for (int j = 0; j < m && !find; j++) {
					if (sum_t-taro[i]+hana[j] == sum) {
						if (sum_h-hana[j]+taro[i] == sum) {
							find = true;
							swap_t = taro[i];
							swap_h = hana[j];
						}
					}
				}
			}
			if (!find) {
				cout << -1 << endl;
			}else{
				cout << swap_t << " " << swap_h << endl;
				find = false;
			}	
		}
		delete[] taro;
		delete[] hana;

		cin >> n;
		cin >> m;
	}
	return 0;
}

Measured memory_bytes: 3012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N;
vector<int> d;

int main() {
  cin >> N;
  d.resize(N);
  rep(i, N) cin >> d[i];

  int ans = 0;
  rep(i, N) for (int j = i + 1; j < N; ++j) { ans += d[i] * d[j]; }

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


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

using namespace std;

const int N=1e5+5;
typedef long long ll;
int a[N],f[N];
int qu(int x)
{
    if(a[x]==x) return x;
    return qu(a[x]);
}
vector <int> b[N];
int main()
{
    int n,m,p[N];
    cin >> n >> m;
    for(int i=1;i<=n;i++)
    {
        cin >> p[i];
        a[i]=i;
        b[i].push_back(i);
    }
    while(m--)
    {
        int x,y,c;
        cin >> x >> y;
        a[max(qu(x),qu(y))]=min(qu(x),qu(y));
    }
    for(int i=1;i<=n;i++)
    {
        a[i]=qu(a[i]);
        if(a[i]!=i)
        {
            b[i].clear();
            b[a[i]].push_back(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(!b[i].empty())
        {
            for(int j=0;j<b[i].size();j++)
            {
                f[p[b[i][j]]]=i;
            }
            for(int j=0;j<b[i].size();j++)
            {
                if(f[b[i][j]]==i) ans++;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 7416
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include<stdio.h>
#include<algorithm>
#define PI 3.14159265
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define SZ(x) ((int)(x).size())

using namespace std;

double sessen(double a,double b,double c,double t) {
	double x;
	x = ((100 - a * t - b * sin(PI*c*t)) / (a + PI * b*c*cos(PI*c*t))) + t;
	return x;
}


int main(){
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) {
		cout << a-b << endl;
	}
	else {
		cout << b - a << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

void solve() {

	int n;
	cin >> n;

	priority_queue<pair<lint, pair<lint, lint>>> LK;
	priority_queue<pair<lint, pair<lint, lint>>, vector<pair<lint, pair<lint, lint>>>, greater<>> RK;
	lint ans = 0;
	for (int i = 0; i < n; i++) {
		lint k, l, r;
		cin >> k >> l >> r;
		k--;
		if (l > r) LK.emplace(k, make_pair(l, r));
		else RK.emplace(k, make_pair(r, l));
	}

	int cnt = 0;
	priority_queue<lint> L;
	for (int i = n; i >= 0; i--) {

		while (!LK.empty()) {
			const auto& [k, p] = LK.top();
			if (i > k) break;
			
			const auto& [l, r] = p;
			L.emplace(l - r);
			ans += l;
			LK.pop();
		}

		if (!L.empty()) {
			L.pop();
			cnt++;
		}

	}

	while (!L.empty()) {
		ans -= L.top();
		L.pop();
	}

	priority_queue<lint> R;
	for (int i = 0; i < n; i++) {

		while (!RK.empty()) {
			const auto& [k, p] = RK.top();
			if (i <= k) break;

			const auto& [r, l] = p;
			R.emplace(r - l);
			ans += r;
			RK.pop();
		}

		if (!R.empty()) {
			R.pop();
		}

	}

	while (!R.empty()) {
		ans -= R.top();
		R.pop();
	}

	while (!RK.empty()) {
		ans += RK.top().second.second;
		RK.pop();
	}

	cout << ans << "\n";

};

int main() {

	int T;
	cin >> T;

	for (int i = 0; i < T; i++) {
		solve();
	}

	return 0;
}



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

int main(){
	int n;
	cin >> n;
	vector<ll> a(n), csum(n);
	rep(i,n){
		cin >> a[i];
		if(i == 0) csum[i] = a[i];
		else csum[i] = csum[i-1] + a[i];
	}
	if(n==4){
		cout << max({a[0],a[1],a[2],a[3]}) - min({a[0],a[1],a[2],a[3]}) << endl;
		return 0;
	}
	ll P,Q,R,S;
	int l=0,r=2;
	ll ans = pow(10,15);
	for(int i(1);i<n-2;++i){
		
		while(l < i-1){
			ll prev = abs(csum[i]-2*csum[l]);
			ll next = abs(csum[i]-2*csum[l+1]);
			if(prev > next) l++;
			else break;
		}
		while(r < n-2){
			ll prev = abs(csum[n-1]-2*csum[r]+csum[i]);
			ll next = abs(csum[n-1]-2*csum[r+1]+csum[i]);
			if(prev > next) r++;
			else break;
		}
		P = csum[l];
		Q = csum[i] - csum[l];
		R = csum[r] - csum[i];
		S = csum[n-1] - csum[r];
		ans = min(ans, max({P,Q,R,S}) - min({P,Q,R,S}));
	}
	
	cout << ans << endl;
	return 0;
}

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

int main(){
	int n, a, b, c;
	cin >> n >> a >> b >> c;
	vector<int> li(n);
	rep(i, n) cin >> li.at(i);
	vector<int> ar(n);
	rep(i, n) ar.at(i) = i;
	int min = 1000000000;
	do{
		for(int i=0; i<n-2; i++){
			for(int j=i+1; j<n-1; j++){
				for(int l=j+1; l<n; l++){
					vector<int> l0(3);
					rep(i, 3) l0.at(i) = 0;
					int sum = 0;
					sum += (l-j-1)*10;
					sum += (j-i-1)*10;
					sum += i*10;
					rep(ii, n){
						if(ii <= i){
							l0.at(0) += li.at(ar.at(ii));
						}else if(ii <= j){
							l0.at(1) += li.at(ar.at(ii));
						}else if(ii <= l){
							l0.at(2) += li.at(ar.at(ii));
						}else{
							break;
						}
					}
					sort(l0.begin(), l0.end());
					sum += abs(l0.at(0) - c);
					sum += abs(l0.at(1) - b);
					sum += abs(l0.at(2) - a);
					if(sum < min) min = sum;
				}
			}
		}
	}while(next_permutation(ar.begin(), ar.end()));
	cout  << min << endl;
	return 0;
}

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

int main() {
  vector<int> p(3);
  for (int i = 0; i < 3; i = i + 1) {
    cin >> p.at(i);
  }
  int min = p.at(2) + p.at(0);
  for (int i = 0; i < 2; i = i + 1) {
    if (min > p.at(i) + p.at(i + 1)) {
      min = p.at(i) + p.at(i + 1);
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
// http://codeforces.com/gym/100126/attachments/download/1321/20122013-tryenirovka-spbgu-b-15-heshi-ru.pdf
// Problem A
#include <bits/stdc++.h>
using namespace std;
typedef long long int lint;

const lint p = 311;
const lint M = lint(1e9) + 7;

vector<lint> mem_pow; // it makes sense to store only F(l) = (p^(M-2)*p^l)%M

string str;
vector<lint> phashes;
void computePHash() {
    phashes.resize(str.length()+1, 0);
    lint p_cur = 1;
    for (int l = 1; l <= str.length(); ++l) {
        phashes[l] = (phashes[l-1] + str[l-1]*p_cur)%M;
        p_cur = (p_cur*p)%M;
    }
}

lint powmod(lint x, lint y) {
    if (y == 0)
        return 1;
    lint prev = powmod(x, y/2);
    return ((prev * prev)%M * (y%2 ? x : 1) )%M;
}
// returns hash for [l, r) substring
lint h(int l, int r) {
    lint dif = phashes[r] - phashes[l];
    while (dif < 0)
        dif += M;
    lint res = (dif *mem_pow[l])%M;
    return res;
}

int main(int, char**) {
    std::ios::sync_with_stdio(false);

    // fillin pow_mem
    mem_pow.resize(5001, 1);
    mem_pow[1] = powmod(p, M-2);
    for (int i = 2; i < 5001; ++i)
        mem_pow[i] = (mem_pow[i-1]*mem_pow[1])%M;    

    cin >> str;
    size_t K;
    cin >> K;
    // compute prefix hash
    computePHash();
    
    unordered_map<lint, pair<int, int> > s;
    for (int i = 0; i < str.length(); ++i) {
        for (int l = 1; l <= min(K, str.length() - i) ; ++l) {
            auto ch = h(i, i+l);
//cout << str.substr(i, l) << " " << ch << endl;
            s.emplace(ch, make_pair(i, l));     
        }
    }

    vector<string> ss;
    for (auto v = s.begin(); v != s.end(); ++v) {
        ss.push_back( str.substr(v->second.first, v->second.second));
    }
    sort(ss.begin(), ss.end());
    cout << ss[K-1] << endl;

    return 0;
}



Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
# C - Digits in Multiplication
# モジュールのインポート
import math

# 標準入力の取得
N = int(input())

# 求解処理
# F(A, B)を定義
def F(A:int, B:int) -> int:
    digits_A = len(str(A))
    digits_B = len(str(B))
    return max(digits_A, digits_B)

# 全探索を行い、F(A, B)の最小値を求める
# a <= bとして、sqrt(N)まで探索を行うことで、時間を節約する
result = len(str(N)) # 初期値として、Nの桁数を入力
for a in range(1, int(math.sqrt(N))+1):
    # bが整数でない場合、何もしない
    if N % a != 0:
        continue

    # bが整数である場合、a, bのうち桁数が大きい方を求める
    b = int(N / a)
    result = min(result, F(a, b))

# 結果出力
print(result)

Measured memory_bytes: 3064
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush
from fractions import gcd
from copy import deepcopy
import math
import queue
#import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline-------------------------------------------
    N = int(input())
    A = list(map(int,input().split()))
    p = []
    for i in range(N):
        p.append([i+1,A[i]])
    p.sort(key = lambda x:x[1])
    ans = [p[i][0] for i in range(N)]
    print(*ans,sep = " ")
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 25632
#include <stdio.h>

int dsum( int *digits, int n ){
	int i, sum=0;

	for( i=0; i<n; i++ ){
		sum += digits[i];
	}
	return sum;
}

/*For Debug
void printdsum( int *digits, int n ){
	int i;

	for( i=0; i<n-1; i++ ){
		printf("%d+", digits[i]);
	}
	printf("%d=%d\n", digits[i], dsum( digits, n ) );
}
*/

int main(){
	int n, s;
	int d[10];
	int sp;
	int cnt;
	int i;
	int t;

	for(;;){
		
	NEXT_SET:
		
		scanf("%d %d", &n, &s);
		if( n==0 && s==0 )
			break;

		cnt = sp = 0;

		//make minimum case
		for( i=0; i<n; i++ ){
			d[sp] = i;
			sp++;
		}

		for(;;){
			//printdsum( d, sp );//for debug
			if( dsum(d, sp) == s )
				cnt++;
			sp--;
			if( d[sp] != 9 ){
				d[sp]++;
				sp++;
			}else{
				for( t=0; d[sp] >= 9-t; t++ ){
					sp--;
					if( sp <= -1 ){
						printf("%d\n", cnt);
						goto NEXT_SET;
					}
				}
				d[sp]++;
				sp++;
				while( sp < n ){
					d[sp] = d[sp-1]+1;
					sp++;
				}	
			}
		}
	}

	return 0;
}
		

Measured memory_bytes: 600
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 c = sc.nextInt();
        int[] b = new int[m];
        for (int i = 0 ; i < m ; i++) {
            b[i] = sc.nextInt();
        }
        int[][] a = new int[n][m];
        int count = 0;
        for (int i = 0 ; i < n ; i++) {
            int ans = 0;
            for (int j = 0 ; j < m ;j++) {
                a[i][j] = sc.nextInt();
                ans += a[i][j] * b[j];
            }
            if (ans + c > 0) {
                count++;
            }

        }

        System.out.println(count);


    }

}


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


int main() {
    string s;
    cin >> s;
    map<char,int> d;
    rep(i,s.length()){
        d[s[i]]++;
    }
    for(char c = 'a';c <= 'z';c++){
        if(d[c] == 0){
            cout << c << endl;
            return 0;
        }
    }
    cout << "None\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

//桁数
ll GetDigit(ll num)
{
  return log10(num) + 1;
}

//約数全列挙
vector<ll> enum_div(ll n)
{
  vector<ll> ret;
  for (ll i = 1; i * i <= n; ++i)
  {
    if (n % i == 0)
    {
      ret.push_back(i);
      if (i * i != n)
      {
        ret.push_back(n / i);
      }
    }
  }
  sort(begin(ret), end(ret));
  return ret;
}

//累乗(xのn乗%mod)
ll modpow(ll x, ll n, ll mod = MAX)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

//階乗
ll factorial(ll n)
{
  if (n > 0)
    return n * factorial(n - 1);
  else
    return 1;
}

ll modinv(ll a, ll mod)
{
  ll b = mod, u = 1, v = 0;
  while (b)
  {
    ll t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0)
    u += mod;
  return u;
}

void Main()
{
  str s; cin >> s;
  char flag = s[0];
  ll ans = 0;
  rep(i, s.size())
  {
    if(s[i] != flag)
    {
      ans++;
      flag = s[i];
    }
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}

Measured memory_bytes: 512
n, m = map(int, input().split())
x = list(map(int, input().split()))
dist = []

x.sort()
for i in range(1, m):
    dist.append(x[i] - x[i-1])
dist.sort()
if m > n:
    print(sum(dist[:m-n]))
else:
    print('0')


Measured memory_bytes: 56744
n=int(input())
x = [int(x) for x in input().split()]

heikin=(sum(x)/n)

if abs(int(heikin)-heikin)<abs(int(heikin+1)-heikin):
    kaisai=int(heikin)
else:
    kaisai=int(heikin+1)

ans=0

for i in x:
    ans+=(i-kaisai)**2

print(ans)

Measured memory_bytes: 62036
n=int(input())
l=[]
for i in range(n):
  m=int(input())
  l.append(m)
l=sorted(l)
c=0
d=1
e=l[0]
for i in range(1,n):
  if l[i]!=e:
    if d%2==1:
      c+=1
    e=l[i]
    d=1
  else:
    d+=1
if d%2==1:
  c+=1
print(c)


Measured memory_bytes: 8284
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		System.out.println((sc.nextInt() + sc.nextInt() / 2));
	}
}

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

#define endl '\n'

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

    int a,b,c,d; cin >> a >> b >> c >> d;

    int i=1;
    while(a > 0 && c > 0){
        if (i & 1){
            c -= b;
        } else{
            a -= d;
        }
        i++;
    }
    if (a <= 0) cout << "No\n";
    else cout << "Yes\n";
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;



signed main(){
    IOS;
    int k;
    cin >> k;
    int a, b;
    cin >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) return cout << "OK", 0;
    }
    cout << "NG";
    return 0;
}

Measured memory_bytes: 3612
def gcd(a,b):
  if b>a:
    a,b=b,a
  while b:
    a,b=b,a%b
  return a
n = int(input())
a = list(map(int,input().split()))
left = list(range(n-1))
right = list(range(n-1))
left[0]=a[0]
right[0]=a[n-1]
for i in range(1,n-1):
  left[i]=gcd(left[i-1],a[i])
  right[i]=gcd(right[i-1],a[n-i-1])
m=0
for i in range(n):
  if i == 0:
    m=right[n-2]
  elif i == n-1:
    m=max(m,left[n-2])
  else:
    m=max(m,gcd(left[i-1],right[n-i-2]))
print(m)

Measured memory_bytes: 15588
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#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 >> m;
    vector<pair<bool,int>> ans(n);
    if(n!=1) ans[0].second=1;
    for(int i=0;i<m;i++){
        int s,c;
        cin >> s >> c;
        s--;
        if(!ans[s].first){
            ans[s].first=true;
            ans[s].second=c;
        }else if(ans[s].second==c) continue;
        else{
            cout << -1 << endl;
            return 0;
        }
    }
    if(ans[0].second==0&&n!=1){
        cout << -1 << endl;
        return 0;
    }
    for(int i=0;i<n;i++){
        cout << ans[i].second;
    }
    cout << endl;
}

Measured memory_bytes: 256
def expression(ss, i, c_level):
    s = ss[i]
    code = s[-1]
    if code == "+":
        return plus(ss, i+1, c_level+1)
    elif code == "*":
        return product(ss, i+1, c_level+1)
    return int(s[c_level:])

def plus(ss, i, c_level):
    num = 0
    while i < len(ss):
        s = ss[i]
        level = len(s)-1
        if level < c_level:
            break
        if c_level < level:
            i += 1
            continue
        num += expression(ss, i, c_level)
        i += 1
    return num

def product(ss, i, c_level):
    num = 1
    while i < len(ss):
        s = ss[i]
        level = len(s)-1
        if level < c_level:
            break
        if c_level < level:
            i += 1
            continue
        num *= expression(ss, i, c_level)
        i += 1
    return num

while 1:
    n = input()
    if n == 0:
        break
    ss = [raw_input() for i in xrange(n)]
    print expression(ss, 0, 0)

Measured memory_bytes: 6420
import sys
from heapq import heappush,heappop
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    X,Y,Z,K=map(int,input().split())
    A=list(map(int,input().split()))
    B=list(map(int,input().split()))
    C=list(map(int,input().split()))
    A.sort(reverse=True); B.sort(reverse=True); C.sort(reverse=True)
    h=[]
    s=set()
    heappush(h,(-(A[0]+B[0]+C[0]),0,0,0))
    s.add((0,0,0))
    for _ in range(K):
        c=heappop(h)
        print(-c[0])
        for k in range(3):
            if (c[1]+(k==0)<X and c[2]+(k==1)<Y and c[3]+(k==2)<Z) and not (c[1]+(k==0),c[2]+(k==1),c[3]+(k==2)) in s:
                heappush(h,(-(A[c[1]+(k==0)]+B[c[2]+(k==1)]+C[c[3]+(k==2)]),c[1]+(k==0),c[2]+(k==1),c[3]+(k==2)))
                s.add((c[1]+(k==0),c[2]+(k==1),c[3]+(k==2)))
                

if __name__ == '__main__':
    main()


Measured memory_bytes: 55400
# include <stdio.h>
int main(){
	char a[26],b[26]={0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
	int c,d=0;
	scanf("%s",a);
	for(c=0;c<26;c++){
		if(a[c]=='a')b[0]++;
		if(a[c]=='b')b[1]++;
		if(a[c]=='c')b[2]++;
		if(a[c]=='d')b[3]++;
		if(a[c]=='e')b[4]++;

		if(a[c]=='f')b[5]++;
		if(a[c]=='g')b[6]++;
		if(a[c]=='h')b[7]++;
		if(a[c]=='i')b[8]++;
		if(a[c]=='j')b[9]++;

		if(a[c]=='k')b[10]++;
		if(a[c]=='l')b[11]++;
		if(a[c]=='m')b[12]++;
		if(a[c]=='n')b[13]++;
		if(a[c]=='o')b[14]++;

		if(a[c]=='p')b[15]++;
		if(a[c]=='q')b[16]++;
		if(a[c]=='r')b[17]++;
		if(a[c]=='s')b[18]++;
		if(a[c]=='t')b[19]++;

		if(a[c]=='u')b[20]++;
		if(a[c]=='v')b[21]++;
		if(a[c]=='w')b[22]++;
		if(a[c]=='x')b[23]++;
		if(a[c]=='y')b[24]++;

		if(a[c]=='z')b[25]++;
	}
	for(c=0;c<26;c++)if(b[c]>1)d++;
	if(d>0)printf("no");
	else printf("yes");
	return 0;
}

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

static const int N=100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>p[i-1]>>p[i];
    }
    
    for(int i=1;i<=n;i++)m[i][i]=0;
    for(int l=2;l<=n;l++){
        for(int i=1;i<=n-l+1;i++){
            int j=i+l-1;
            m[i][j]=(1<<21);
            for(int k=i;k<=j-1;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout<<m[1][n]<<endl;
    
    return 0;
}


Measured memory_bytes: 3112
#include<cstdio>

int main(){
	int f[1000001] = {};
	int n;

	for(int i = 2; i < 500001; i++){
		f[i * 2] = 1;
	}

	for(int i = 3; i <= 1000; i += 2){
		for(int j = 3; j * i <= 1000000; j += 2){
			f[i * j] = 1;
		}		
	}

	int sum;

	while(scanf("%d", &n) + 1){
		int sum = n - 1;
		for(int i = 2; i <= n; i++){
			sum -= f[i];
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 4940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i, N) cin >> A[i];
  

  int flag = 0;
  int flag3 = 0;
  int cnt = 0;
  REP(i,N-1){
    if(A.at(i)<A.at(i+1)){
      if(flag3 == 0){
        flag=1;
        flag3=1;
      }else if(flag!=1&&flag3!=0){
        cnt++;
        flag3 = 0;
      }
    }else if(A.at(i)>A.at(i+1)){
      if(flag3==0){
        flag = -1;
        flag3 = 1;
      }else if(flag!=-1&&flag3!=0){
        cnt++;
        flag3 = 0;
      }
    }
  }  
  
  cout << cnt+1 << endl;
}

Measured memory_bytes: 640
a = int(input())
ar = list(map(int,input().split()))
k = 0
g = 0
f = 0
for r in ar:
    if r % 4 == 0:
        f += 1
    elif r % 2 == 0:
        g += 1
    else:
        k += 1
if f == 0:
    if k == 0:
        print("Yes")
    else:
        print("No")
elif g == 0:
    if k - f <= 1:
        print("Yes")
    else:
        print("No")
elif k == 0:
    print("Yes")
else:
    if f >= k:
        print("Yes")
    else:
        print("No")
    
    

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
	static int A;
	static int B;
	static int C;
	static int K;
	static int x;
	public static void main(String[]args) {
		Scanner sc= new Scanner(System.in);
		A=sc.nextInt();
		B=sc.nextInt();
		C=sc.nextInt();
		K=sc.nextInt();
		if(K-A>=0) {
			for(int n=0;n<A;n++) {
				x++;
			}
			if(K>=A+B) {
				for(int n=0;n<K-A-B;n++) {
					x--;
				}
			}
		}
		else {
			for(int n=0;n<K;n++) {
				x++;
			}
		}
		System.out.println(x);
	}
}

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

int main(void){
    int n,k;
    cin>>n>>k;
    ll res = k;
    rep(i,n-1){
        res *= k-1;
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
#include<set>
using namespace std;

int main()
{
    set<int>seto;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(seto.count(x))
            seto.erase(x);
        else
            seto.insert(x);
    }
    cout<<seto.size()<<endl;
    return 0;

}

Measured memory_bytes: 4992
import java.io.*;
import java.util.*;
import java.util.stream.*;

class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		boolean flg = false;
		for(int i = 0;i < 3;i++){
			if(s[i].equals("7")){
				flg = true;
			}
		}
		if(flg){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

int main(){
  string S;
  cin >>S;
  int N=0;
  N=S.length();
  if(N==7){
    if (S=="keyence"){
      cout<<"YES"<<endl;
      return 0;
    }
    else cout<<"NO"<<endl;
    return 0;
  }
  for (int i=0;i<N;i++){
    string P=S;
    int C=N-7;
    if(P.erase(i,C)=="keyence"){
      cout<<"YES"<<endl;
        return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}

    

  
      


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{     int n,i,j,s;
    char a[4];
             while(~scanf("%s",a))
			 {  s=0;
			 	if(a[0]==a[3]&&a[1]==a[2]&&a[0]!=a[1])
			 	s=1;
			 	if(a[0]==a[1]&&a[2]==a[3]&&a[0]!=a[2])
			 	s=1;
			 	if(a[0]==a[2]&&a[1]==a[3]&&a[0]!=a[1])
			 	s=1;
			 	
			 	if(s==1)
			 	printf("Yes\n");
			 	else
			 	printf("No\n");
			  } 
  
}


Measured memory_bytes: 256
card = {}
bingo = {1:False,2:False,3:False,4:False,5:False,6:False,7:False,8:False,9:False}
for i in range(3):
    row = list(map(int, input().split()))
    card[i * 3 + 1] = row[0]
    card[i * 3 + 2] = row[1]
    card[i * 3 + 3] = row[2]

n = int(input())
for i in range(n):
    num = int(input())
    keys = [k for k, v in card.items() if v == num]
    if len(keys) > 0:
        bingo[keys[0]] = True

hit_keys = [k for k, v in bingo.items() if v]
if len(hit_keys) >= 3 and ((1 in hit_keys and 2 in hit_keys and 3 in hit_keys) or \
    (4 in hit_keys and 5 in hit_keys and 6 in hit_keys) or\
    (7 in hit_keys and 8 in hit_keys and 9 in hit_keys) or\
    (1 in hit_keys and 4 in hit_keys and 7 in hit_keys) or\
    (2 in hit_keys and 5 in hit_keys and 8 in hit_keys) or\
    (3 in hit_keys and 6 in hit_keys and 9 in hit_keys) or\
    (1 in hit_keys and 5 in hit_keys and 9 in hit_keys) or\
    (3 in hit_keys and 5 in hit_keys and 7 in hit_keys)):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
#define _name3(_1,_2,_3,name,...) name
#define _rep1(n) for(ll i=0;i<(n);++i)
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _name3(__VA_ARGS__,_rep3,_rep2,_rep1)(__VA_ARGS__)
#define rrep(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define each(i,a) for(auto &i:a)
#define sum(a) accumulate(range(a),0LL)
#define range(i) (i).begin(),(i).end()
template<class T> inline constexpr bool chmin(T &mn,const T &cnt){if(mn>cnt){mn=cnt;return 1;}else return 0;}
template<class T> inline constexpr bool chmax(T &mx,const T &cnt){if(mx<cnt){mx=cnt;return 1;}else return 0;}

int main() {
    int n;
    cin>>n;
    vector<int> a(n);
    rep(n)cin>>a[i];
    bool dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    rep(n)rep(j,i+1,n){
        if(a[i]!=a[j])break;
        dp[i][j+1]=1;
    }
    rep(siz,4,n+1)rep(i,n+1-siz){
        int j=i+siz;
        rep(k,i+2,j-1)if(dp[i][k]&&dp[k][j]){
            dp[i][j]=1;
            break;
        }
        if(!dp[i][j]&&a[i]==a[j-1]){
            if(chmax(dp[i][j],dp[i+1][j-1]))continue;
            if(a[i]==a[j-2]){
                if(chmax(dp[i][j],dp[i+1][j-2]))continue;
            }
            if(a[i+1]==a[j-1]){
                if(chmax(dp[i][j],dp[i+2][j-1]))continue;
            }
            rep(k,i+2,j-2)if(a[i]==a[k]&&dp[i+1][k]&&dp[k+1][j-1]){
                dp[i][j]=1;
                break;
            }
        }
    }
    cout<<(dp[0][n]?"yes":"no")<<endl;
}



Measured memory_bytes: 3096