akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#define mod 1000000007
#define mad(a,b) a=(a+b)%mod
#define N 1010
#define X 22
ll h,w,kkk;
char c[N][N];
int di[N][N];
int dist[50][50];
int dp[X][(1<<X)];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>h>>w>>kkk;
    vector<P> v;
    ll sx,sy,gx,gy;
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
	cin>>c[i][j];
	if(c[i][j]=='s')sx=i,sy=j;
	if(c[i][j]=='e')gx=i,gy=j;
    }
    v.push_back(make_pair(sx,sy));
    for(int i=0;i<h;i++)for(int j=0;j<w;j++){
	if('a'==c[i][j])v.push_back(make_pair(i,j));
    }
    v.push_back(make_pair(gx,gy));
    for(int t=0;t<v.size();t++){
	for(int i=0;i<h;i++)for(int j=0;j<w;j++)di[i][j]=1e9;
	di[v[t].first][v[t].second]=0;
	queue<P> Q;
	Q.push(v[t]);
	while(!Q.empty()){
	    ll x=Q.front().first,y=Q.front().second;
	    Q.pop();
	    ll dx[]={0,1,0,-1},dy[]={1,0,-1,0};
	    for(int r=0;r<4;r++){
		ll xx=x+dx[r],yy=y+dy[r];
		if(not(0<=xx&&xx<h&&0<=yy&&yy<w))continue;
		if(c[xx][yy]=='#')continue;
		if(di[xx][yy]==1e9){
		    di[xx][yy]=di[x][y]+1;
		    Q.push(make_pair(xx,yy));
		}
	    }
	}
	for(int s=0;s<v.size();s++){
	    dist[t][s]=di[v[s].first][v[s].second];
	}
    }
    int n=v.size()-1; //cout<<n<<endl;
    /*for(int i=0;i<n;i++){
	for(int j=0;j<n;j++)cout<<dist[i][j]<<" ";
	cout<<endl;
    }*/
    for(int i=0;i<n;i++)for(int j=0;j<(1<<n);j++){
	dp[i][j]=1e9;
    }
    dp[0][1]=0;
    for(int j=0;j<(1<<n);j++)for(int i=0;i<n;i++){
	for(int k=0;k<n;k++){
	    if((j&(1<<k)))continue;
	    chmin(dp[k][j+(1<<k)],dp[i][j]+dist[i][k]);
	}
    }
    int ans=1e9;
    for(int j=0;j<(1<<n);j++){
	ll cnt=0;
	for(int k=0;k<n;k++){
	    if(j&(1<<k))cnt++;
	}
	if(cnt-1>=kkk){
	    for(int i=0;i<n;i++){
		chmin(ans,dp[i][j]+dist[i][n]);
	    }
	}
    }
    if(ans>=1e9)ans=-1;
    cout<<ans<<endl;
}





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

int main() {
  int N,L,count=0;
  cin >> N >> L;
  vector<int> AP(N);
  for(int i=0;i<N;i++){
  	int aa=L+i;
    AP.at(i)=aa;
    count+=aa;
  }
  int min=42332,atai=0;
  for(int i=0;i<N;i++){
  	if(abs(AP.at(i))<min){
      min=abs(AP.at(i));
      atai=i;
    }
  }
  cout << count-AP.at(atai) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long 
#define pb push_back
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define N 10000005
#define INF 10000000000000

using namespace std;

const int mod=1e9+7;



void need_for_speed(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}


int32_t main(){
	need_for_speed();
    int x,n;
    cin>>x>>n;
    set<int> s;
    for(int i=0;i<n;i++){
        int x1;
        cin>>x1;
        s.insert(x1);
    }
    int mn=INT_MAX;
    int ans;
    for(int i=0;i<=1000;i++){
        if(!s.count(i)){
            if(abs(i-x)<mn){
                mn=abs(i-x);
                ans=i;
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}
        
	

		
    

        
        
    
 

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

int main()
{
    long long k;
    string s;
    cin>>k>>s;
    if(s.size()<=k)
    cout<<s<<endl;
    else
    {
        cout<<(s.substr(0,k)+"...")<<endl;
    }
}
  

Measured memory_bytes: 3624
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int q;
    cin >> q;
    vector<int> v;
    int a, b;
	rep(i, q) {
        cin >> a;
        if (a == 2)
            v.pop_back();
        else {
            cin >> b;
            if (a == 0)
                v.push_back(b);
            else
                cout << v[b] << endl;
        }
    }
}


Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,hasil=0,dua=0,x,data[100005]={0},i;
	cin>>n;
	for (i=0; i<n; i++) {
		cin>>x;
		++data[x];
	}
	for (i=0; i<=100000; i++) if (data[i]>0) {
		if (data[i]%2==0) {
			++dua;
		}
		else {
			++hasil;
		}
	}
	hasil+=(dua/2*2);
	cout<<hasil<<endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <string.h>
#define LENGTH 200000

typedef struct A{
  char name[100];
  int time;
}B;

int head, tail, n;
B Q[LENGTH+1];

void enqueue(B);
B dequeue ();
int minimum_judge(int,int);

int main(){
  int elapsedtime = 0,number,i,q;
  B data;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].time);
  }
  tail = n + 1;
  head = 1;
  
  while(head != tail){
    data = dequeue();
    number = minimum_judge(q,data.time);
    data.time -= number;
    elapsedtime += number;
    
    if(data.time > 0){
      enqueue(data);
    }
    else{
      printf("%s %d\n",data.name,elapsedtime);
    }
  }
  
  return 0;
}

void enqueue(B x){
  Q[tail] = x;
  tail++;
}

B dequeue(){
  B x = Q[head];
  head++;
  
  return x;
}

int minimum_judge(int q,int time){
  if(q > time)return time;
  else return q;
}



Measured memory_bytes: 20912
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<map>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e9+7
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;

int main(){

    int n,c;
    cin >> n >> c;
    int grid[c][c];
    int diff[n][n];
    int grid_color_sum[3][30];/*grid_color_sum[i][j]:余りがiになる場所で色がjとなる場所の個数*/
    int ans = INF;

    REP(i,3){
        REP(j,c){
            grid_color_sum[i][j] = 0;/*grid_color_sum[i][j]:余りがiになる場所で色がjとなる場所の個数*/
        }
    }

    REP(i,c){
        REP(j,c){
            cin >> grid[i][j];
        }
    }

    REP(i,n){
        REP(j,n){
            cin >> diff[i][j];
            grid_color_sum[(i+j)%3][diff[i][j]-1]++;/*grid[i][j]-1は配列の添え字に合わせている*/
        }
    }

    for(int i = 0;i < c;i++){
        for(int j = 0;j < c;j++){
            if(i == j){
                continue;
            }
            for(int k = 0;k < c;k++){
                if(k == i || k == j){
                    continue;
                }
                int tmp = 0;
                for(int L = 0;L < c;L++){
                    tmp += grid[L][i] * grid_color_sum[0][L];/*余りが0の場所を全て色Lからiにに塗り替える*/
                }
                for(int L = 0;L < c;L++){
                    tmp += grid[L][j] * grid_color_sum[1][L];/*余りが1の場所を全て色Lからjに塗り替える*/
                }
                for(int L = 0;L < c;L++){
                    tmp += grid[L][k] * grid_color_sum[2][L];/*余りが2の場所を全て色Lからkに塗り替える*/
                }
                ans = min(ans,tmp);
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main() {
	char ss[10];
	int a[10];
	while (cin >> ss) {
		for (int i = 0; i < 10; i++) {
			a[i] = ss[i] - '0';
		}
		int x = a[0] + a[9] + (a[1] + a[8]) * 9 + (a[2] + a[4] + a[5] + a[7]
			) * 6 + (a[3] + a[6]) * 4;
		string sa=to_string(x);
		int f=sa.size();
		cout << sa[f-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            long n = Long.parseLong(br.readLine());
            printFactor(n);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    private static void printFactor(long n) {
        System.out.print(n + ":");
        factorize(n, 3);
    }

    private static void factorize(long n, long r) {
        if (n == 1) {
            System.out.println();
            return;
        }
        System.out.print(" ");
        if (isPrime(n)) {
            System.out.print(n);
            System.out.println();
            return;
        } else if (n % 2 == 0) {
            System.out.print(2);
            n = n / (long) 2;
        } else {
            for (long i = r; i <= n; i += 2) {
                if (n % i == 0) {
                    r = i;
                    System.out.print(i);
                    n = n / i;
                    break;
                }
            }
        }

        factorize(n, r);
    }

    private static boolean isPrime(long n) {
        if (n == 2) {
            return true;
        }
        if (n < 2 || n % 2 == 0) {
            return false;
        }

        int i = 3;
        while (i <= Math.sqrt((double) n)) {
            if (n % i == 0) {
                return false;
            }
            i = i + 2;
        }
        return true;
    }
}

Measured memory_bytes: 24144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#define rep(i, n) for(int i=0;i<(int)(n);++i)
template <typename T> ll gcd(T a, T b) {return b?gcd(b, a%b):a;}
template <typename T> ll lcm(T a, T b) {return a * b / gcd(a, b);};
template <typename T> inline void chmin(T &a, const T& b){if(a>b)a=b;}
template <typename T> inline void chmax(T &a, const T& b){if(a<b)a=b;}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  for (int i = 0; i < (int) s.size(); ++i) {
    cout << "x";
  }
  cout << '\n';
}


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

using namespace std;

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

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

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

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

int main()
{
	for(int w,h;cin>>w>>h && w|h;){
		vvi hex(h+2,vi(w+2));
		rep(i,h) rep(j,w) cin>>hex[i+1][j+1];
		
		queue<pii> q; q.emplace(0,0);
		while(!q.empty()){
			int ci=q.front().first,cj=q.front().second; q.pop();
			if(ci<0 || h+2<=ci || cj<0 || w+2<=cj || hex[ci][cj]) continue;
			hex[ci][cj]=2;
			int di[]={-1,-1,0,0,1,1};
			int dj[]={-1,0,-1,1,-1,0};
			if(ci&1) dj[0]*=-1,dj[4]*=-1;
			rep(k,6) q.emplace(ci+di[k],cj+dj[k]);
		}
		
		int res=0;
		rep(i,h+2) rep(j,w+2) if(hex[i][j]==2){
			int di[]={-1,-1,0,0,1,1};
			int dj[]={-1,0,-1,1,-1,0};
			if(i&1) dj[0]*=-1,dj[4]*=-1;
			rep(k,6){
				int ni=i+di[k],nj=j+dj[k];
				if(0<=ni && ni<h+2 && 0<=nj && nj<w+2 && hex[ni][nj]==1)
					res++;
			}
		}
		
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n];
	int ans=0;
	for(int i=0;i<n;i++)
	cin>>a[i];
	sort(a,a+n);
	if(n%2)
	{
		cout<<0;
		return 0;
	}
	else
	ans=(a[n/2]-a[n/2-1]);
	cout<<ans<<endl;
	return 0;
}

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

int main(){
	map<int, int> m;
	int n;
	cin >> n;
	while(n--){
		int a;
		cin >> a;
		m[a]++;
	}
	int ans = 0;
	for(auto p:m) if(p.second % 2) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

int main() {
	
	int x, a, b;
	cin >> x >> a >> b;

	x -= a;
	cout << x % b << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

class RMQ_segment_tree
{
    using data_type = Pii;

public:

    vector<data_type> dat;
    int N;
    data_type inf;

    RMQ_segment_tree(int n, data_type inf): inf(inf) {
        N = 1;
        while(n > N) N = N << 1;
        dat = vector<data_type>(2 * N - 1, inf);
    }

    //k番目の値をaに更新
    void update(int k, data_type a){
        k += N - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }

    //[a, b)の最小値
    data_type minval(int a, int b){
        return query(a, b, 0, 0, N);
    }

    data_type query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return inf;
        if(a <= l && r <= b) return dat[k];
        else{
            data_type vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            data_type vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return min(vl, vr);
        }
    }
};

int calc_ans(RMQ_segment_tree &t, int i0, int i1){
    if(i0 == i1) return 0;
    Pii p = t.minval(i0, i1);
    int a1 = p.first * (p.second - i0 + 1) * (i1 - p.second);
    return a1 + calc_ans(t, i0, p.second) + calc_ans(t, p.second + 1, i1);
} 

signed main(){

    int N;
    cin >> N;
    vec a(N);
    readvec(a);

    RMQ_segment_tree t(N, Pii(INF, -1));
    REP(i, N) t.update(i, Pii(a[i], i));
    cout << calc_ans(t, 0, N);
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

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

int main(){
  int N; cin >> N;
  int x[100],y[100],h[100];
  int xm,ym,hm=0;
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> h[i];
    if(hm<h[i]){
      xm=x[i]; ym=y[i]; hm=h[i];
    }
  }
  bool check=false;
  int CX,CY,CH; //答えを入れる
  int coef[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
  for(int hp=0; hp<=200; hp++){ //CHの候補　hm+hp
    for(int xp=0; xp<=hp; xp++){ //CXの候補 xx+-xp CYの候補yy+=(hp-xp)
      for(int j=0; j<4; j++){
        //テスト
        int hkou=hm+hp, xkou=xm+xp*coef[j][0],
        ykou=ym+(hp-xp)*coef[j][1];
        bool flag=false;
        for(int i=0; i<N; i++){
          if( max( hkou - abs(x[i]-xkou) - abs(y[i]-ykou) ,0)!=h[i]){
            flag=true; break;
          }
        }
        if(flag==false){
          CX=xkou; CY=ykou; CH=hkou; check=true; break;
        }
      }
      if(check) break;
    }
    if(check) break;
  }
  cout << CX << " " << CY << " " << CH << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define max(a, b) (a>b?a:b)
#define min(a, b) (a<b?a:b)


int n, i, j, k, num[105][105], sum[105][105];

int main(){

    scanf("%d", &n);
    
    for(i = 1;i <= n;i++){
	for(j = 1;j <= n;j++){
	    scanf("%d", &num[i][j]);
	    sum[i][j] = sum[i][j - 1] + num[i][j];
	}
    }
    
    int ans = -(1 << 30);
    
    for(i = 0;i <= n;i++){
	for(j = i + 1;j <= n;j++){
	    int res = -(1 << 30);
	    for(k = 1;k <= n;k++){
		res = max(res + sum[k][j] - sum[k][i], sum[k][j] - sum[k][i]);
		ans = max(res, ans);
	    }
	}
    }
    
    printf("%d\n", ans);
    return 0;
}

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

int main(){
  int x,a,b;
  cin>>x>>a>>b;
  if(abs(x-a)>=abs(x-b)){
    cout<<"B"<<endl;
  }else{
    cout<<"A"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define nn 65536*2
#define lf double

int n,m;
int pa[nn];vector<int> v[nn];
int dep[nn];int ans=0;
void dfs(int x,int p)
{
	dep[x]=1;
	for(int i=0;i<v[x].size();i++) dfs(v[x][i],x);
	if(x==1) return ;
	if(dep[x]>=m and p!=1) ans++,dep[x]=0;//,cout<<x;
	dep[p]=max(dep[p],dep[x]+1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++) 
	{
		scanf("%d",&pa[i]);
		if(i!=1)v[pa[i]].push_back(i);
	}
	if(pa[1]!=1) ans++;
	dfs(1,0);cout<<ans;
	return 0;
} 

Measured memory_bytes: 13568
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 21;
char dn[dm], * di = dn;
inline void putint(ll X) {
	int keta = 0;
	char C[20];
	while (X) {
		*(C + keta) = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--)* di++ = (*(C + i));
	*di++ = '\n';
}

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

	pair<int, int> LR[200000];
	int T = getint();
	rep(t, T) {
		int N = getint();

		ll saishou = 0;
		int k1 = 0, k2 = N;
		rep(i, N) {
			int k = getint(), l = getint(), r = getint();

			if (l < r) {
				LR[--k2] = mp(k + 1, r - l);
				saishou += l;
			}
			else {
				LR[k1++] = mp(k, l - r);
				saishou += r;
			}
		}
		sort(LR, LR + k1);
		sort(LR + k1, LR + N);

		priority_queue<int> PQ;
		int i = k1;
		while (i < N && LR[i].first < k1) {
			PQ.push(LR[i++].second);
		}
		for (int j = k1; j <= N; j++) {
			while (i < N && LR[i].first <= j) {
				PQ.push(LR[i++].second);
			}
			if (PQ.size()) {
				auto q = PQ.top();
				PQ.pop();
				saishou += q;
			}
		}
		PQ = priority_queue<int>();
		i = k1 - 1;
		while (i >= 0 && LR[i].first > k1) {
			PQ.push(LR[i--].second);
		}
		for (int j = k1 - 1; j >= 0; j--) {
			while (i >= 0 && LR[i].first > j) {
				PQ.push(LR[i--].second);
			}
			if (PQ.size()) {
				auto q = PQ.top();
				PQ.pop();
				saishou += q;
			}
		}
		putint(saishou);
	}

	fwrite(dn, 1, di - dn, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5512
#include<stdio.h>
int main()
{
	int x,y,z,i,n;
	while(scanf("%d%d%d",&x,&y,&z)==3)
	{
		n=0;
		for(i=1;i<=10;i++)
			if(i<=20-x-y&&i!=x&&i!=y&&i!=z)
				n++;
		printf((double)n/7>=0.5?"YES\n":"NO\n");
	}
	return 0;
}

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

int main() {
	string a,b,c;
  	cin >> a >> b >> c;
  
  	bool ab = a.at(a.size() - 1) == b.at(0);
  	bool bc = b.at(b.size() - 1) == c.at(0);
  
  	if(ab && bc) {
    	cout << "YES" << endl;
    }else {
    	cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
public class Main {
	public static void main(String[]args) {
		
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		
		if ( a < b ) {
			System.out.println("a < b");
		} else if ( a > b ) {
			System.out.println("a > b");
		} else if ( a == b )
			System.out.println("a == b");
	}
}

Measured memory_bytes: 26284
p = 10**9+7
def pow(x,m):
    if m==0:
        return 1
    if m==1:
        return x
    if m%2==0:
        return (pow(x,m//2)**2)%p
    else:
        return (x*(pow(x,(m-1)//2)**2)%p)%p
A = [1 for _ in range(10000)]
for i in range(2,10000):
    A[i] = (A[i-1]*i)%p
B = [1 for _ in range(10000)]
B[9999] = pow(A[9999],p-2)
for i in range(9998,1,-1):
    B[i] = (B[i+1]*(i+1))%p
def f(n,k):
    return (A[n]*B[k]*B[n-k])%p
S = int(input())
cnt = 0
for n in range(S//3,0,-1):
    k = S-3*n
    cnt = (cnt+f(k+n-1,n-1))%p
print(cnt)

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  ll N, W;
  cin >> N >> W;

  vector<ll> w(N+1);
  vector<ll> v(N+1);
  for (ll i = 0; i < N; ++i) {
    cin >> w[i+1];
    cin >> v[i+1];
  }

  vector<vector<ll>> dp(N+10, vector<ll>(W+10, 0));
  for (ll i = 1; i <= N; ++i) {
    for (ll j = 1; j <= W; ++j) {
      dp[i][j] = dp[i-1][j];
      if (j - w[i] >= 0) {
        dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i <= W; ++i) {
    ans = max(ans, dp[N][i]);
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 87296
let sunday week = 
    if week = "MON" then 6
    else if week = "TUE" then 5
    else if week = "WED" then 4
    else if week = "THU" then 3
    else if week = "FRI" then 2
    else if week = "SAT" then 1
    else 7

let ans = sunday (read_line ())

let () = print_endline @@ string_of_int ans

Measured memory_bytes: 3648
n,x=map(int,input().split()) #n都市xスタート座標
a=list(map(int,input().split()))
import fractions
for i in range(n):
    a[i]=a[i]-x
ans=a[0]
for i in range(1,n):
    ans=fractions.gcd(ans,a[i])
print(abs(ans))

Measured memory_bytes: 14252
#include <algorithm>
#include <array>
#include <iostream>
#include <string>

namespace {
    std::string NBase(long n) {
        static constexpr std::array<char, 26> kChars = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
        static constexpr long kBase = kChars.size();

        std::string name;
        while (n >= kBase) {
            n--;
            name += kChars.at(n % kBase);
            n /= kBase;
        }
        n--;
        if (n >= 0) {
            name += kChars.at(n);
        }

        std::reverse(std::begin(name), std::end(name));
        return name;
    }
}// namespace

int main() {
    long n;
    std::cin >> n;

    std::cout << NBase(n) << std::endl;
}

Measured memory_bytes: 3624
import sys
import collections
input = sys.stdin.readline

mod = 998244353
n = int(input())
d = list(map(int, input().split()))
c = collections.Counter(d)
ans = 1

if d[0] != 0:
    print(0)
    sys.exit()

if c[0] != 1:
    print(0)
    sys.exit()

if max(d)+1 != len(c):
    print(0)
    sys.exit()

try:
    for i in range(1, len(c)-1):
        ans = (ans*c[i]**c[i+1]) % mod
except KeyError:
    print(0)
    sys.exit()

print(ans)


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, W;
	cin >> N >> W;
	vector<ll> w(N), v(N);
	REP(i, N) cin >> w[i] >> v[i];

	ll imax = 101010;
	ll dp[imax][105];
	REP(i, imax)REP(j, 105) dp[i][j] = -1;
	dp[0][0] = 0;
	REP(j, N){
		REP(i, imax){
			if(dp[i][j]==-1) continue;
			dp[i][j+1] = max(dp[i][j], dp[i][j+1]);
			if(i+w[j]<=W) dp[i+w[j]][j+1] = max(dp[i][j]+v[j], dp[i+w[j]][j+1]);
		}
	}
	ll res = -1;
	REP(i, W+1) res = max(res, dp[i][N]);
	cout << res << endl;
    return 0;
}

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

using namespace std;

int main()
{

 int a;
 int b;
 int c;
 string answer;

 cin >> a >> b >> c;

 if (( a < b ) && ( b < c )) {
   answer = "Yes";
 } else {
   answer = "No";
 }
 cout << answer << endl;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define FOR(i, a, b) for(long long i = (a); i <=(b); i++)
using namespace std;

signed main(void)
{
	long long n, k, cnt;
	cin >> n >> k;
	
	cnt = 0;
	FOR(b, 1, n)
	{
		long long p = n / b;
		long long r = n % b;
		cnt += p * max(b - k, (long long)0);
		if (k == 0)
			cnt--;
		cnt += max(r - k + 1, (long long)0);
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>

char s[2222][2222];

int main(void)
{
	bool ans_found = false;
	int h, w, i, j, k, ans = 0;

	scanf("%d %d" ,&h, &w);
	for (i = 1; i <= h; i++)
		scanf("%s" ,&s[i][1]);

	for (i = 1; i <= h && !ans_found; i++)
		for (j = 1; j <= w && !ans_found; j++)
			if (s[i][j] == '.')
			{
				int light = 1;

				for (k = i - 1; k >= 1; k--)
					if (s[k][j] == '#')
						break;
				light += i - k - 1;

				for (k = i + 1; k <= h; k++)
					if (s[k][j] == '#')
						break;
				light += k - i - 1;

				for (k = j - 1; k >= 1; k--)
					if (s[i][k] == '#')
						break;
				light += j - k - 1;

				for (k = j + 1; k <= w; k++)
					if (s[i][k] == '#')
						break;
				light += k - j - 1;

				if (ans < light)
					ans = light;

				if (ans == h + w - 1)
					ans_found = true;
			}

	printf("%d" ,ans);
	return 0;
}

Measured memory_bytes: 4480
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <stdlib.h>
#include <queue>
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const int maxn=2e5+5;

int a[maxn];
priority_queue<int, vector<int>, greater<int> > Q;
int main()
{
    int n, k;
    cin >> n>> k;
    for(int i=0; i<n; i++)
        scanf("%d", &a[i]);
    sort(a, a+n);
    int cnt=1, cnt_num=a[0];
    for(int i=1; i<n; i++)
    {
        if(cnt_num == a[i])
            cnt ++;
        else
        {
            Q.push(cnt);
            cnt = 1;
            cnt_num = a[i];
        }
    }
    Q.push(cnt);
    int sum = 0;
    while(Q.size()>k)
    {
        sum += Q.top();
        Q.pop();
    }
    cout<<sum<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 2168
n = int(input())
tsk = []
for i in range(n):
    a, b = map(int, input().split())
    tsk.append((b, a))
tsk.sort()

t = 0
for i, (b, a) in enumerate(tsk):
    t += a
    if t > b:
        print('No')
        exit()
else:
    print('Yes')

Measured memory_bytes: 35200
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;


int main() {
    int M,D;
    int count=0;
    cin>>M>>D;
    int m;

    for(int i=22;i<D+1;i++){
        int num1 = i/10;
        int num2 = i%10;
        if(num1==1||num2==1)continue;

        m=num1*num2;

        if(m<=M&&m>0){
            count++;
        }

    }

    cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int a=sc.nextInt();
       int b=sc.nextInt();
       int max = Math.max(a+b, a-b);
       max= Math.max(max, a*b);
       System.out.println(max);
    }
}

Measured memory_bytes: 22100
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

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

    if (S.size() == 2) {
        if (S[0] == S[1]) {
            std::cout << "1 2" << std::endl;
        }
        else {
            std::cout << "-1 -1" << std::endl;
        }
        return 0;
    }

    // S >= 3

    for (size_t i = 0; i < S.size() - 2; ++i) {
        if (S[i] == S[i+1]) {
            std:: cout << i+1 << " " << i+2 << std::endl;
            return 0;
        }
        else if (S[i] == S[i+2]) {
            std:: cout << i+1 << " " << i+3 << std::endl;
            return 0;
        }
    }

    if (S[S.size()-2] == S[S.size()-1]) {
        std::cout << S.size() -1 <<" " << S.size() << std::endl;
        return 0;
    }

    std::cout << "-1 -1" << std::endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int res = 700;
    rep(i, 3)
    {
        char s;
        cin >> s;
        if (s == 'o')
            res += 100;
    }
    cout << res << endl;
    // end

    return 0;
}


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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    int n,k,d,s;
    cin>>n>>k;
    si st;
    while(k--){
        cin>>d;
        while(d--){
            cin>>s;
            st.insert(s);
        }
    }
    cout<<n-st.size()<<endl;
}



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


int main() {
  int n;
  cin >> n ;
  n %= 10;
  switch (n) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
  }

  return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i <= n; i++)
template<class T> inline int chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline int chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

ll dp[410][410];

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) dp[i][j] = LINF;
    vector<ll> S(n + 1, 0);
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        S[i + 1] = S[i] + a;
        dp[i][i] = 0;
    }
    for (int w = 1; w < n; w++) {
        for (int i = 0; i < n - w; i++) {
            for (int m = i; m < i + w; m++) {
                chmin(dp[i][i + w], dp[i][m] + dp[m + 1][i + w] + S[i + w + 1] - S[i]);
            }
        }
    }
    cout << dp[0][n - 1] << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int main()
{
  int x;
  int temp;
  vector<int> ans;

  cin >> x;

  for (int j = 2; j < 11; j++) {
    int i = 1;
    while(1) {
      if(pow(i,j) > x) {
        break;
      }
      temp = pow(i, j);
      i++;
    }
    ans.push_back(temp);
    temp = 0;
  }
  cout << *max_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 384
def main():
    a, b = map(int, input().split())
    maxv = int((101 / 0.1) - 1)
    for i in range(maxv+1):
        if (i*8//100 == a) and (i*10//100 == b):
            print(i)
            exit()
    print(-1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9124
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <climits>
#include <cassert>
#include <algorithm>
#include <utility>

using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int a, b,  c;
    cin >> a >> b >> c;
    if (c < a - b) {
        cout << 0 << endl;
    } else {
        cout << c - a + b << endl;
    }
    return 0;
}



Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

bool a[64][64];
bool solve() {
  int H, W; cin>>H>>W;
  REP(h,H) {
    string line; cin>>line;
    REP(w,W) {
      if(line[w] == '#') {
        a[h+1][w+1] = true;
      }
    }
  }
  for(int h = 1; h <= H; h++) {
    for(int w =	1; w <=	W; w++) {
      if(a[h][w] == false) continue;
      if(a[h-1][w] == true) continue;
      if(a[h+1][w] == true) continue;
      if(a[h][w-1] == true) continue;
      if(a[h][w+1] == true) continue;
      return false;
    }
  }
  return true;
}

int main() {
  bool ans = solve();
  cout << ( ans ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
A = []
B = []
N = int(input())
for i in range(N):
    a, b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)

A.sort()
B.sort()

if N%2==1:
    mi = N//2
    lmed = A[mi]
    rmed = B[mi]
    print(rmed-lmed+1)

if N%2==0:
    mir = N//2
    mil = mir-1
    lmed = (A[mir]+A[mil]) / 2
    rmed = (B[mir]+B[mil]) / 2
    print(int(2*(rmed-lmed)+1))

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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define OUT(x) cout<<(x)<<"\n"
#define pb push_back
#define mp make_pair

int main() {
    int a, b;
    string op;
    cin>>a>>op>>b;
    if(op == "+")
        OUT(a+b);
    else
        OUT(a-b);
    return 0;
}


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

#define ll long long
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	long double r;
	cin >> r;
	r = 2 * (22.0/7.0) * r;

	cout << r << "\n";
}

Measured memory_bytes: 3804
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int k; cin>>k;
	ll ans = 0;
	for(int i  =1 ;i<=k ;i++)
		for(int j = 1; j<=k; j++)
			for(int y = 1;y<= k ; y++)
				ans += __gcd(i,__gcd(j,y));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3636
n=int(input())
s=[int(input()) for i in range(n)]
dp=[[-10**9]*10 for i in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
  for j in range(10):
    dp[i][(j+s[i-1])%10]=max(dp[i-1][(j+s[i-1])%10],dp[i-1][j]+s[i-1])
ans=0
for i in range(1,10):
  ans=max(ans,dp[n][i])
print(ans)

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

using namespace std;

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

int n;
vector<int> G[100000];
bool used[100000];
vector<int> pos,ind,c_ind;

void add_edge(int from, int to){
  G[from].push_back(to);
  G[to].push_back(from);
}

int dfs(int v,int r){
  int ret = 0;
  if (r==0){
    pos.clear();
    c_ind.clear();
  }
  used[v] = true;
  pos.push_back(v);
  c_ind.push_back(ind[v]);

  rep(i,G[v].size()){
    if(!used[G[v][i]]) dfs(G[v][i],r+1);
  }
  if(r==0){
    sort(pos.begin(),pos.end());
    sort(c_ind.begin(),c_ind.end());
    int i_ind = 0,p_ind = 0;
    while(i_ind<c_ind.size() && p_ind<pos.size()){
      if(c_ind[i_ind] < pos[p_ind]) i_ind++;
      else if(pos[p_ind] < c_ind[i_ind]) p_ind++;
      else {i_ind++;p_ind++;ret++;}
    }
  }
  return ret;
}

int main(){

  int m,x,y;
  cin >> n >> m;
  vector<int> p(n);
  ind.resize(n);
  rep(i,n) {
    cin >> p[i];
    p[i]--;
    ind[p[i]]=i;
  }
  rep(i,m){
    cin >> x >> y;
    x--; y--;
    add_edge(x,y);
    add_edge(y,x);
  }
  memset(used,0,sizeof(used));
  int sum = 0;
  rep(v,n) if(!used[v]) sum += dfs(v,0);
  cout << sum << endl;

  return 0;
}


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

#define ll long long
int main() {
  int N, M;
  cin >> N >> M;
  
  ll A[N], B[N];
  for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
  
  vector<vector<ll>> G(M+1);
  
  for (int i = 0; i < N; i++){
    if (A[i] <= M) G[A[i]].push_back(B[i]);
  }
  
  ll ans = 0;
 
  priority_queue<ll> pq; 
  for (int i = M-1; i >= 0; i--) { 
    for (ll j : G[M-i]) pq.emplace(j); 
    if (!pq.empty()) {  
      ans += pq.top();
      pq.pop();
    }
  }
  
  cout << ans << endl;
  
}

Measured memory_bytes: 7168
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

int H, N;
vector<int> a, b;

i64 memo[1005][30010];
i64 dp(int i, int dmg) {
    if (i >= N) {
        return (dmg >= H) ? 0 : INF;
    }

    auto &ret = memo[i][dmg];
    if (~ret) return ret;

    ret = INF;
    if (dmg < H) chmin(ret, dp(i, dmg + a[i]) + b[i]);
    chmin(ret, dp(i + 1, dmg));

    return ret;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    read(H, N);
    a.resize(N);
    b.resize(N);
    rep(i, 0, N) { read(a[i], b[i]); }

    memset(memo, -1, sizeof(memo));
    print(dp(0, 0));

    return 0;
}


Measured memory_bytes: 236416
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 long long l,r,i,d,c=0;
 cin>>l>>r>>d;
 for(i=l;i<=r;i++)
 {
   if(i%d==0) c++;
 }
cout<<c<<endl;

}


Measured memory_bytes: 3392
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define rep(N) for (int i = 0; i < N; ++i)
#define Rep(a, b) for (int i = a; i < b; ++i)
#define For(i, N) for (int i = 0; i < N; ++i)
#define all(v) v.begin(), v.end()
#define rev(v) v.rbegin(), v.rend()
#define makei(N) int N; cin >> N;
#define makel(N) ll N; cin >> N;
#define makes(s) string s; cin >> s;
#define maked(d) double d; cin >> d;
#define makev(v, N) vi v(N); rep(N)cin >> v[i];
#define mod 1000000007
#define distance(x1,y1,x2,y2) sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using msi = map<string, int>;

template<typename T>
void say(T s) {
	cout << s << "\n";
}

template<typename T>
void say(vector<T> s) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << " " << *(itr++);
	}
	cout << "\n";
}

template<typename T>
void say(vector<T> s, string t) {
	auto itr = s.begin();
	cout << *(itr++);
	while (itr != s.end()) {
		cout << t << *(itr++);
	}
	cout << "\n";
}

void yn(bool b) {
	if (b)say("yes");
	else say("no");
}

void Yn(bool b) {
	if (b)say("Yes");
	else say("No");
}

void YN(bool b) {
	if (b)say("YES");
	else say("NO");
}

template<typename T>
void maxi(T & a, T b) {
	a = max(a, b);
}

template<typename T>
void mini(T & a, T b) {
	a = min(a, b);
}

void exact_say(double x) {
	cout << setprecision(numeric_limits<double>::max_digits10) << x << endl;
}

template<class T> void getVector(vector<T> & v) {
	for (int i = 0; i < v.size(); ++i)
		cin >> v[i];
}

int main() {
	makei(a);
	makei(b);
	if (a < b)say("a < b");
	else if (a == b)say("a == b");
	else say("a > b");
}


Measured memory_bytes: 3064
N, L = map(int, input().split())

taste_list = [L + i for i in range(N)]
taste_abs_list = [abs(n) for n in taste_list]
abs_min = min(taste_abs_list)
min_idx = taste_abs_list.index(abs_min)
total_sum = sum(taste_list)

ans = total_sum - taste_list[min_idx]
print(ans)

Measured memory_bytes: 3064
def ratecolor(List):
    ratebar = [0]*8
    for r in List:
        if r>=1 and r<400:
            ratebar[0]=1
        elif r>=400 and r<800:
            ratebar[1]=1
        elif r>=800 and r<1200:
            ratebar[2]=1
        elif r>=1200 and r<1600:
            ratebar[3]=1
        elif r>=1600 and r<2000:
            ratebar[4]=1
        elif r>=2000 and r<2400:
            ratebar[5]=1
        elif r>=2400 and r<2800:
            ratebar[6]=1
        else:
            ratebar[7]=1
        
    l = len([i for i in ratebar if i>=1])
    
    return l
    

N = int(input())
A = [int(i) for i in input().split(" ")]
_3200 = [i for i in A if i<3200]
Upper3200 = len([i for i in A if i>=3200])

n = ratecolor(_3200)

if n==0:
    print("{} {}".format(1,Upper3200))
else:
    print("{} {}".format(n,n+Upper3200))

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>


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

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long MOD = 1'000'000'007LL;
const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	ll N, K; scanf("%lld %lld", &N, &K);

	ll l = 0;
	ll r = K + 1;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		ll sum = 0;
		ll now = mid;
		for (ll i = 0; i < N; i++) {
			sum += now;
			now /= 2;
			if (now == 0) break;
		}
		if (sum <= K) l = mid;
		else r = mid;
	}

	cout << l << endl;
	return 0;

}



Measured memory_bytes: 3248