akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector <int> vi;
const int MOD = 1e9 + 7;

void solve(){
    ll n, t;
    ll ans = 0;
    cin >> n >> t;
    ll last = 0, prev = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(last > x){
            ans -= last - x;
        }
        prev = x;
        last = x + t;
        ans += last - prev;
    }
    cout << ans;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


string s,p;

bool check(int x){
  // s[x]移行がpに一致するか否か
  int n = s.size();
  int m = p.size();
  if (x + m > n) return false;
  for (int i=0; i<m; i++){
    if (s[x+i] != p[i]) return false;
  }
  return true;
}

int main() {
  cin >>s >>p;
  s = s + s;
  bool ok = true;
  int n = s.size();
  int m = p.size();
  for (int i=0; i<n; i++){
    if (check(i)){
      cout <<"Yes" <<endl;
      return 0;
    }
  }
  cout <<"No" <<endl;
}



Measured memory_bytes: 3196
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
#include <chrono>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef tuple<ll,ll,ll> tll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
//↓Union-Find Tree
struct UnionFind {
  vector<long long> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  long long root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  long long size(int x) {
    return -data[root(x)];
  }
};
//↑Union-Find Tree
int main() {
	ll N,M;
	cin>>N>>M;
	vint A,B;
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		A.pb(a);
		B.pb(b);
	}
	reverse(A.begin(),A.end());
	reverse(B.begin(),B.end());
	vll ans;
	ll usa=N*(N-1)/2;
	UnionFind U(N+1);
	for(int i=0;i<M;i++){
		ans.pb(usa);
		if(U.root(A[i])!=U.root(B[i])){
			usa-=U.size(A[i])*U.size(B[i]);
			U.unionSet(A[i],B[i]);
		}
	}
	reverse(ans.begin(),ans.end());
	for(ll L:ans)
		cout<<L<<endl;
    return 0;
}

Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      int A = Integer.parseInt(sc.next());
      int B = Integer.parseInt(sc.next());
       String result = A <= 8 && B <= 8 ? "Yay!" : ":(";

      System.out.println(result);
    }
  }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
    	
        int[] x = new int[12];
        int[] y = new int[12];
        int tp;
        
        while(sc.hasNext()) {

            String[] s = sc.next().split(",");
            tp=0;
            
            for(int i=0; i<12; i++) {
            	x[i]= Integer.parseInt(s[i]);
            	y[i]=tp+x[i];
            	tp+=x[i];
            }
            
            double d, t, v;
			int ans=0;

            d=y[9];
            v=x[10]+x[11];
            t=d/v;
            
            d=t*x[10];
            for(int i=0; i<10 && d>y[i]; i++) ans =i+2;
            
//            System.out.println(t); スレ違いの時間
//           System.out.println(d);　　スレ違いの位置
            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 12000
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;
const int MaxN = 105;
const double eps = 1e-6;
const double PI = acos(-1.0);

int n;
struct Point {
    int x, y;
}PP[MaxN + 5];

double slope[MaxN + 5];

int main()
{
    //printf("%lf\n", atan2(0, 1));
    while(scanf("%d", &n) != EOF) 
    {
        for(int i = 1; i <= n; i++) scanf("%d %d", &PP[i].x, &PP[i].y);
        for(int i = 1; i <= n; i++) {
            int tot = 0;
            for(int j = 1; j <= n; j++)
                if(i != j)
                    slope[++tot] = atan2(PP[j].y - PP[i].y, PP[j].x - PP[i].x);
            sort(slope + 1, slope + tot + 1);
            double ans = 0.0;
            ans = max(ans, PI - (slope[tot] - slope[1]));
            for(int j = 2; j <= tot; j++) 
                ans = max(ans, (slope[j] - slope[j - 1]) - PI);
            printf("%.10lf\n", ans / (2 * PI));
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;

int main(){
	int b1,b2,b3;
	
	scanf("%d %d %d",&b1,&b2,&b3);
	if(b1==0){
		if(b2==0){
			if(b3==0)
			printf("Close\n");
			else
			printf("Open\n");
		}
		else
		printf("Close\n");
	}
	else{
		if(b2==0)
		printf("Close\n");
		else
		printf("Open\n");
	}
}


Measured memory_bytes: 3128
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int H,W;
  cin>>H>>W;
  vector<vector<int>> A(H,vector<int>(W));
  for(int i=0;i<H;i++)
    for(int &j:A[i])
      cin>>j;
  vector<vector<int>> B(0);
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++){
      if(A[i][j]%2){
        A[i][j+1]++;
        B.push_back({i+1,j+1,i+1,j+2});
      }
    }
    if(H-1!=i && A[i][W-1]%2){
      A[i+1][W-1]++;
      B.push_back({i+1,W,i+2,W});
    }
  }
  cout<<B.size()<<endl;
  for(vector<int> &v:B)
    cout<<v[0]<<' '<<v[1]<<' '<<v[2]<<' '<<v[3]<<endl;
}

Measured memory_bytes: 13972
import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val k = sc.nextInt()
  val ds = Vector.fill(k)(sc.next())

  @tailrec
  def calc(i: Int): Int = {
    if (!ds.exists(d => s"$i".contains(d))) i else calc(i + 1)
  }

  println(s"${calc(n)}")
}


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

using namespace std;

const int maxn = 1e2+10;
const int maxw = 1e5+100;

long long n, w, cost[maxn], weight[maxn], dp[maxn][maxw];

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

    cin >> n >> w;

    for(int i=1; i<=n; i++)cin >> weight[i] >> cost[i];

    for(int i=1; i<=n; i++){
        for(int j=1; j<=w; j++){
            if(weight[i]<=j){
                dp[i][j]=max(dp[i-1][j], cost[i] + dp[i-1][j-weight[i]]);
            }
            else dp[i][j]=dp[i-1][j];
        }
    }
    cout << dp[n][w] << endl;
}


Measured memory_bytes: 79360
#include <stdio.h>
#define MAX 200000

int main(){
  int i,j,n,max=-1000000001,min=1000000001,A;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A);
    if(A - min > max && i)
      max = A-min;
    if(min > A){
      min = A;
    }
  }
  printf("%d\n",max);
  return 0;
  
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define rip(a,b,c) for(int (a)=(c);(a)<(b);(a)++)
const long long INF= 1LL << 60;
int main(){
    //入力始まり
    int N;
    int Y;
    cin >> N >> Y;
    //入力終わり

    for(int x=0;x<2001;x++){
        if(x>N){
            continue;
        }
        for(int y=0;y<2001;y++){
            if(N<x+y){
                continue;
            }
            int z=N-x-y;
            if(10000*x+5000*y+1000*z==Y){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
            
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}



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

using namespace std;
typedef long long ll;

char c[1001][1001];
int a[1001][1001];
int h, w;
queue<int> pos, pos_next;

void dfs(int x, int y){
    if(y + 1 <= w && c[x][y + 1] == '.' && (a[x][y + 1] == 0 || a[x][y + 1] > a[x][y])){
        a[x][y + 1] = a[x][y];
        pos.push(x * 1001 + y + 1);
        dfs(x, y + 1);
    }
    if(y - 1 >= 1 && c[x][y - 1] == '.' && (a[x][y - 1] == 0 || a[x][y - 1] > a[x][y])){
        a[x][y - 1] = a[x][y];
        pos.push(x * 1001 + y - 1);
        dfs(x, y - 1);
    }
    if(x + 1 <= h && c[x + 1][y] == '.' && (a[x + 1][y] == 0 || a[x + 1][y] > a[x][y])){
        a[x + 1][y] = a[x][y];
        pos.push(x * 1001 + 1001 + y);
        dfs(x + 1, y);
    }
    if(x - 1 >= 1 && c[x - 1][y] == '.' && (a[x - 1][y] == 0 || a[x - 1][y] > a[x][y])){
        a[x - 1][y] = a[x][y];
        pos.push(x * 1001 - 1001 + y);
        dfs(x - 1, y);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> h >> w;
    int ch, cw, dh, dw;
    cin >> ch >> cw >> dh >> dw;
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j)
            cin >> c[i][j];
    }

    pos.push(ch * 1001 + cw);
    a[ch][cw] = 1;
    int px, py;
    while(!pos.empty()){
        px = pos.front();
        pos.pop();
        py = px % 1001;
        px = px / 1001;
        if(px == dh && py == dw){
            break;
        }
        dfs(px, py);
        for(int i = (px - 2 >= 1 ? px - 2 : 1); i <= (px + 2 <= h ? px + 2 : h); ++i)
            for(int j = (py - 2 >= 1 ? py - 2 : 1); j <= (py + 2 <= w ? py + 2 : w); ++j){
                if(c[i][j] == '.' && (a[i][j] == 0 || a[i][j] > a[px][py] + 1)){
                    a[i][j] = a[px][py] + 1;
                    pos_next.push(i * 1001 + j);
                }
            }
        if(pos.empty()){
            swap(pos, pos_next);
        }
    }
    cout << a[dh][dw] - 1 << "\n";
    return 0;
}


Measured memory_bytes: 8564
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    string s;
    cin >> s;
    REP(i,s.size()) {
        if (i%2 == 0) cout << s[i];
    }
    cout << endl;
}


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

using namespace std;

typedef pair<int,int> P;
typedef long long ll; 

#define int ll

const ll mod = 1e9 + 7;

main(){
	int n;
	cin >> n;
	int x[100];
	for(int i=0;i<n;i++) cin >> x[i];

	int min = 1000000;
	for(int p=0;p<=100;p++){
		int tmp = 0;
		for(int i=0;i<n;i++){
			tmp += (x[i]-p)*(x[i]-p);
		}
		if(min > tmp) min = tmp;
	}

	cout << min << endl;

	return 0;
}


Measured memory_bytes: 3568
import math
N,M = map(int, input().split())
L = []
 
for i in range(1,math.floor(math.sqrt(M))+1):
    if M % i == 0:
        L.append(i)
        L.append(int(M / i))
L1 = [i for i in L if M / i >= N]
print(max(L1))

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

const int MAX = 2e5;
bool f[MAX + 1];
set<int> st;

int it = 0;
vector<int> G[MAX];

void get(int size, int v) {
	assert(1 <= size);
	--size;
	while (size >= 1) {
		int ns = *prev(st.upper_bound(size));
		if (ns >= 1) {
			int t = it++;
			G[v].push_back(t);
			G[t].push_back(v);
			get(ns, t);
		}
		size -= ns;
	}
}

int main()
{
	string s;
	cin >> s;
	int n = s.size();
	if (s.front() != '1' || s.back() == '1') {
		cout << -1 << endl;
		return 0;
	}
	f[0] = true;
	for (int i = 1; i < n; i++) {
		if (s[i - 1] == '1') f[i] = true, st.insert(i);
		if (s[i - 1] != s[n - i - 1]) {
			cout << -1 << endl;
			return 0;
		}
	}
	get(n, it++);
	assert(it == n);
	for (int i = 0; i < n; i++) {
		for (auto to : G[i]) if (to > i) {
			cout << i + 1 << ' ' << to + 1 << endl;
		}
	}
	return 0;
}


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

int a[4];
int x, y;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	for(int i=0; i<4; ++i)
		cin >> a[i];
	cout << a[2]-a[3]+a[1] << " " << a[3]+a[2]-a[0] << " " << a[0]-a[3]+a[1] << " " << a[1]+a[2]-a[0] << "\n";
}

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

struct P{
int mon[11];
int maru[11];
int pe,x;
int t;
int N;
};

int main(){

struct P Q[52];

int T,P,R;
while(1){
cin>>T>>P>>R;if(T==0&&P==0&&R==0)break;

for(int i=0;i<51;i++)
	{Q[i].x=0;Q[i].t=0;
	for(int j=0;j<11;j++)
	{Q[i].mon[j]=0;Q[i].maru[j]=0;}
}
for(int i=0;i<R;i++){
string str;int ti,pi,tr;

cin>>ti>>pi>>tr;
cin>>str;
if(str=="CORRECT"){
Q[ti].maru[pi]=1;
Q[ti].t+=Q[ti].mon[pi]+tr;
Q[ti].x++;
}

if(str=="WRONG"){
Q[ti].maru[pi]=0;
Q[ti].mon[pi]+=1200;
Q[ti].pe++;
}
}
int jun[51]={};
for(int i=0;i<51;i++)
{jun[i]=i;Q[i].N=i;} 

for(int i=1;i<=T;i++)
for(int j=T;j>i;j--)
{if(Q[jun[j]].x>Q[jun[j-1]].x){int t=jun[j];jun[j]=jun[j-1];jun[j-1]=t;}}


for(int i=1;i<=T;i++)
for(int j=T;j>i;j--)
if(Q[jun[j]].x==Q[jun[j-1]].x&&Q[jun[j-1]].t>Q[jun[j]].t){
int t=jun[j];jun[j]=jun[j-1];jun[j-1]=t;}

for(int i=1;i<=T;i++)
for(int j=T;j>i;j--)
if(Q[jun[j]].x==Q[jun[j-1]].x&&Q[jun[j]].t==Q[jun[j-1]].t&&jun[j]<jun[j-1]){
int t=jun[j];jun[j]=jun[j-1];jun[j-1]=t;}

for(int i=1;i<=T;i++)
{cout<<jun[i]<<" "<<Q[jun[i]].x<<" "<<Q[jun[i]].t<<endl;
}
}
return 0;
}

Measured memory_bytes: 1220
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<queue>
#include<set>
#include<sstream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200000+10;
int sz[N];
struct P{
    int a,b;
    friend bool operator<(const P &p1,const P &p2){
        return p1.b>p2.b;
    }
};
int main()
{

    int n,k,x;
    while(~scanf("%d%d",&n,&k)){
        memset(sz,0,sizeof(sz));
        set<int>se;
        for(int i=0;i<n;i++){
            scanf("%d",&x);
            se.insert(x);
            sz[x]++;
        }
        if(se.size()<=k) printf("0\n");
        else {
            P now;
            priority_queue<P>q;
            for(set<int>::iterator it=se.begin();it!=se.end();it++){
                now.a=*it;
                now.b=sz[*it];
                q.push(now);
            }
            int sum=0;
            for(int i=0;i<se.size()-k;i++){
                sum+=(q.top()).b;
                q.pop();
            }
            printf("%d\n",sum);
        }
    }
    return 0;
}




Measured memory_bytes: 12536
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
ll INF = LLONG_MAX / 3;
double EPS = 1e-10;

void dfs(int u, vector<vector<edge> >& G, vector<ll>& a) {
	for (int i = 0; i < G[u].size(); i++) {
		edge e = G[u][i];
		if (a[e.v] != -1) continue;
		a[e.v] = a[u] ^ e.w;
		dfs(e.v, G, a);
	}
}

int main() {
	int N, M, Q; cin >> N >> M >> Q;
	vector<vector<edge> > G(N);
	while (M--) {
		int x, y; ll w; scanf("%d%d%lld", &x, &y, &w);
		edge e = {y, w};
		G[x].push_back(e);
		edge _e = {x, w};
		G[y].push_back(_e);
	}
	vector<ll> a(N, -1);
	a[0] = 0;
	dfs(0, G, a);
	vector<ll> b;
	for (int u = 0; u < N; u++)
		for (int i = 0; i < G[u].size(); i++) {
			edge e = G[u][i];
			b.push_back(a[u] ^ a[e.v] ^ e.w);
		}
	int n = b.size(), k = 0;
	for (ll x = 1LL<<60; x; x >>= 1)
		for (int i = k; i < n; i++)
			if (b[i] & x) {
				swap(b[k], b[i]);
				for (int i = k + 1; i < n; i++)
					if (b[i] & x)
						b[i] ^= b[k];
				k++;
				break;
			}
	while (Q--) {
		int x, y; scanf("%d%d", &x, &y);
		ll z = a[x] ^ a[y];
		for (int i = 0; i < k; i++)
			if (z < (z ^ b[i]))
				z ^= b[i];
		printf("%lld\n", z);
	}
}

Measured memory_bytes: 18488
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var M = one[0];
	var K = one[1];
	if(K >= 0 && K < Math.pow(2,M)){
		if(M == 1){
			if(K == 0){
				myout("0 0 1 1");
			}else{
				myout(-1);
			}
			return;
		}
		if(K == 0){
			var output = new Array(Math.pow(2,M + 1));
			for(var i = 0; i < Math.pow(2,M); i++){
				output[i * 2] = i;
				output[i * 2 + 1] = i;
			}
			myout(myconv(output, 8));
		}else{
			var output = [K,0];
			for(var i = 1; i <= Math.pow(2,M) - 1; i++){
				if(i != K){
					output.push(i);
				}
			}
			output.push(K);
			for(var i = Math.pow(2,M) - 1; i > 0; i--){
				if(i != K){
					output.push(i);
				}
			}
			output.push(0);
			myout(myconv(output, 8));
		}
	}else{
		myout(-1);
	}
}


Measured memory_bytes: 50840
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  char A[51][51],B[51][51];
  int N,M;
  cin >> N >> M;
  REP(i,N)cin >> A[i];
  REP(i,M)cin >> B[i];
  for(int p=0;p<=N-M;p++){
    for(int q=0;q<=N-M;q++){
      for(int i=0;i<M;i++){
        for(int j=0;j<M;j++){
          if(A[i+p][j+q] != B[i][j]){
            i=M;j=M;
            break;
          }
          if(i == M-1 && j==M-1){
            cout << "Yes" << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << "No" << endl;
  return 0;  
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

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

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;

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

        int n = sc.nextInt();
        ArrayList<Integer> a = new ArrayList<>();

        for(int i=0; i<n; i++) {
            a.add(sc.nextInt());
        }
        sc.close();

        Collections.reverse(a);
        for(int i=0; i<a.size(); i++) {
            if(i == a.size()-1) {
                System.out.println(a.get(i));
            } else {
                System.out.print(a.get(i) + " ");
            }
        }
    }
}



Measured memory_bytes: 26220
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;


int main (int argc, char const *argv[])
{
    int A,B,C;
    cin>>A>>B>>C;
    
    int ans=max({
        10*A+B+C,
        A+10*B+C,
        A+B+10*C,
    });
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


ll dp[102][N];

void test_case() {

    ll n;
    cin>>n;

    ll wm;
    cin>>wm;

    vecl w(n), v(n);

    rep(i,n) {
        cin>>w[i]>>v[i];
    }

    for(ll i=1; i<=n; i++) {
        for(ll j=1; j<=wm; j++) {
            if(j - w[i-1] < 0) {
                dp[i][j] = dp[i-1][j];
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
            }
        }
    }

    cout<<dp[n][wm]<<endl;


}


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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
    //cin >> t;
    while(t--)
    {   
        test_case();
    }
}


Measured memory_bytes: 81788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

int MAX = 1e6+2;
int main(){
	int k, i;
	cin >>k;
	string arr, result;
	cin >> arr;
	result = arr;
	if(arr.length()>k){
		result = string(arr.begin(), arr.begin()+k)+"...";
	}
	cout << result << endl;
}

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

int main() {
    int x,t;
    cin >> x >> t;
    cout << max(0,x-t) << endl;
}

Measured memory_bytes: 256
# Your code here!


# スペース区切りの整数の入力
a,b,c=gets.chomp.split(" ").map(&:to_i);

d = (a - b).abs
e = (a - c).abs
f = (b - c).abs

arr = [d,e,f]
arr.sort!
    
    
# 出力
puts arr[0] + arr[1]

Measured memory_bytes: 1788
#include <iostream>

using namespace std;

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

    int n;
    cin >> n;

    for (int i = 1; i <= 9; i++)
        for (int j = 1; j <= 9; j++)
            if (i * j == n)
            {
                cout << "Yes\n";
                return 0;
            }
    
    cout << "No\n";

    return 0;
}


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

int main(){
	int n, x[100], y[100];
	cin >> n;
	for(int i = 0; i < n; i++)cin >> x[i];
	for(int i = 0; i < n; i++)cin >> y[i];

	double d[4];
	for(int i = 0;i < 4;i++ )d[i] = 0.0;

	for(int p = 1;p <= 3; p++){
		for(int i = 0; i < n; i++){
			d[p] += pow(fabs(x[i] - y[i]),p);
		}
		d[p] = pow(d[p], 1.0/p);
	}

	for(int i = 0; i < n; i++){
		d[0] = (d[0] < fabs(x[i] - y[i])?fabs(x[i] - y[i]):d[0]);
	}

	printf("%lf\n", d[1]);
	printf("%lf\n", d[2]);	
	printf("%lf\n", d[3]);
	printf("%lf\n", d[0]);

	return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll n, a, b; cin >> n >> a >> b;

	ll d = abs(a - b);
	if (d & 1)
		std::cout << min(a-1, n-b) + 1 + (d - 1) / 2 << std::endl;
	else
		std::cout << d/2 << std::endl;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            int m = cin.ReadInt;

            int max = (int)Math.Ceiling(m / (double)n);
            long ans = 0;

            for (long i = 1; i <= max; i++)
            {
                if (m % i == 0)
                {
                    long div = m / i;

                    if (div % n == 0)
                    {
                        i *= div / n;
                    }
                    ans = i;
                }
            }

            Console.WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long
#define MAX_N 800001

using namespace std;

long long MOD = 1000000007;

struct segment_tree{
    ll tree[MAX_N];
    int size;

    segment_tree(int N){
        int n=1;
        while(N>n){
            n<<=1;
        }
        size=2*n;
        
        for(int i=0; i<size; i++){
            tree[i]=MOD*MOD;
        }
    }

    void update(int k, ll x){
        k+=(int)(size>>1)-1;
        tree[k]=x;

        while(k>0){
            k=(k-1)/2;
            tree[k]=min(tree[2*k+1],tree[2*k+2]);
        }
    }

    ll query(int a, int b){
        return query(a,b,0,0,(size>>1));
    }

    ll query(int a, int b, int k, int l, int r){
        if(b<=l || r<=a){
            return MOD*MOD;
        }else if(a<=l && r<=b){
            return tree[k];
        }else{
            ll ret=MOD*MOD;
            ret=min(ret,query(a,b,2*k+1,l,(l+r)/2));
            ret=min(ret,query(a,b,2*k+2,(l+r)/2,r));
            return ret;
        }
    }
};

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int N;
vector<int> pos(200001);
ll partition_(ll l, ll r, segment_tree &st){
    if(r-l==1){
        return st.query(l, r);
    }else if(r-l==0){
        return 0;
    }

    ll ret=0;
    ll min_=st.query(l,r);
    ret+=min_*(pos[min_]-l+1)*(r-pos[min_]);
    ret+=partition_(l, pos[min_],st);
    ret+=partition_(pos[min_]+1, r, st);
    return ret;
}

int main(){
    cin >> N;
    segment_tree st(N);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        st.update(i, a);
        pos[a]=i;
    }

    cout << partition_(0,N,st) << endl;
}

Measured memory_bytes: 67312
#include<stdio.h>
    #include <string.h>
    int main(void){
        int b=0,c=0;
        char a[10],d;
        scanf(" %s",a);
        for(int i=0;i<strlen(a);i++){
            if(isupper(a[i])==0) b++;
            if(i>1&&i<strlen(a)-1&&a[i]=='C') c++;
        }
        if(strlen(a)<4||10<strlen(a)) printf("WA\n");
        else if(a[0]!='A'||c!=1) printf("WA\n");
        else if(strlen(a)-2==b&&c==1) printf("AC\n");
        else if(strlen(a)-2!=b) printf("WA\n");
        return 0;
    }


Measured memory_bytes: 128
#include<cstdio> 
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
#define fir first
#define sec second
#define mp make_pair
using namespace std;

namespace flyinthesky {

	int n, p[200000 + 5];
	char s[200000 + 5];
	
	bool cmp(int x, int y) {return s[x] == s[y] ? x < y : s[x] > s[y];}

	LL abss(LL x) {return x > 0 ? x : -x;}

    void clean() {
    }
    int solve() {
    	
    	clean();
    	scanf("%s", s);
    	n = strlen(s);
    	for (int i = 0; i < n; ++i) p[i] = i;
    	sort(p, p + n, cmp);
    	LL ans = 0;
    	for (int i = 0; i < n; ++i) {
    		if (s[p[i]] != 'B')
    			ans += abss(i - p[i]);
    		else 
    			break ;
		}
    	cout << ans;
    	
        return 0;
    }  
}
int main() {
    flyinthesky::solve();
    return 0;
}

Measured memory_bytes: 1280
from collections import defaultdict
n, a = map(int, input().split())
x = list(map(int, input().split()))

dp = [defaultdict(int) for _ in range(n+1)]
dp[0][a] += 1

for i, x_i in enumerate(x):
    for p in dp[i].keys():
        # 入れる場合
        pk = p + a - x_i
        dp[i+1][pk] += dp[i][p]
        # 入れない場合
        dp[i+1][p] += dp[i][p]

print(dp[n][a] - 1)

Measured memory_bytes: 5492
#include <stdio.h>

int main()
{
  int i,j,n,x,r,p;
  int A[100000],temp,temp2;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
  p=0;
  r=n-1;
  //partition(A, p, r)
  //for(i=0;i<20;i++){   
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      temp=A[i];
      A[i]=A[j];
      A[j]=temp;
    }
  }
  temp2=A[i+1];
  A[i+1]=A[r];
  A[r]=temp2;
  //}

  for(j=0;j<i+1;j++) printf("%d ",A[j]);
  printf("[%d]",A[i+1]);
  for(j=i+2;j<n;j++) printf(" %d",A[j]);
  printf("\n");
  
  return 0;
}

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

int main() {
  int64_t a,b,c,S,T;
  cin >> a >> b >> c;
  S=2*(a*b+b*c+c*a);
  T=a*a+b*b+c*c;
  if(S<T&&c>a+b){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
while True:
 n,x = map(int,input().split())
 if n == 0 and x == 0: break
 ans = 0
 for i in range(1,n+1):
    for j in range(i+1,n+1):
       for k in range(j+1,n+1):
          if i+j+k == x: ans += 1
 print(ans)


Measured memory_bytes: 5596
def count_combinations(max_, sum_):
    """return the number of combinations of three numbers
    (in 1..max_) which sum to sum_
    """
    result = 0 
    for i in range(1, max_-1):
        for j in range(i+1, max_):
            if j < (sum_ - (i + j)) <= max_:
                result += 1

    return result


def run():
    while True:
        (n, x) = [int(v) for v in input().split()]
        if n == 0 and x == 0:
            break
        else:
            print(count_combinations(n, x))


run()


Measured memory_bytes: 5608
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		long[] H = new long[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextLong();
		}
		boolean[] isGood = new boolean[N];
		Arrays.fill(isGood, true);
		for (int i = 0; i < M; i++) {
			int from = sc.nextInt() - 1;
			int to = sc.nextInt() - 1;
			if (H[from] < H[to]) {
				isGood[from] = false;
			} else if (H[from] > H[to]) {
				isGood[to] = false;
			} else {
				isGood[from] = false;
				isGood[to] = false;
			}
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N; i++) {
			if (isGood[i]) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 60408
N,M = map(int,input().split())
A = [input() for i in range(N)]
B = [input() for j in range(M)]
ans = "No"
for i in range(N-M+1):
    for j in range(N-M+1):
        count = 0
        for k in range(M):
            for l in range(M):
                if B[k][l] == A[i+k][j+l]:
                    count += 1
        if count == M*M:
            ans = "Yes"
            break
    else:
        continue
    break
print(ans)

Measured memory_bytes: 3064
from collections import deque
k = int(input())
 
q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for _ in range(k):
    x = q.popleft()
    mod = x % 10
    if mod != 0:
        q.append(x * 10 + mod - 1)
    q.append(x * 10 + mod)
    if mod != 9:
        q.append(x * 10 + mod + 1)
 
print(x)

Measured memory_bytes: 11956
#include <cstdio>
#include <vector>
#include <map>

/*
A1 ... An
B1 ... Bn
Ai Bi
min_{A1B1 = ... = AnBn} B_1+ ... +Bn
lcm
lcm/A1 + lcm/A2 + ... lcm/An

sum_i lcm/Ai
sum_i lcm/prod

*/

constexpr int mod = 1000000007;

std::map<int, int> factors;

int n;
int A[10000];
int B[10000];

int modpow(int x, int n){
  int r = 1;
  for(; n; n>>=1){
    if(n&1) r = (long long) r * x % mod;
    x = (long long) x * x % mod;
  }
  return r;
}

constexpr int maxi = 1000000;

bool sieve[maxi+1];
std::vector<int> primes;
int minv[maxi+1];
int f2;

int main(){
  for(int i = 3; i < maxi; i+=2){
    if(sieve[i]) continue;
    for(int j = 2*i; j <= maxi; j+=i) sieve[j] = true;
    primes.push_back(i);
  }

  minv[1] = 1;
  for(int i = 2; i <= maxi; i++) minv[i] = mod - (long long) minv[mod % i] * (mod / i) % mod;

  scanf("%d", &n);
  for(int i = 0; i < n; i++) scanf("%d", A+i), B[i] = A[i];

  for(int i = 0; i < n; i++){
    int ff2 = __builtin_ctz(B[i]);
    f2 = std::max(f2, ff2);
    B[i] >>= ff2;
    if(!sieve[B[i]]){
      if(factors[B[i]] == 0) factors[B[i]] = 1;
      continue;
    }
    for(int p: primes){
      if(p > B[i]) break;
      if(B[i] % p) continue;
      int np = 0;
      do { B[i]/=p; np++; } while(B[i] % p == 0);
      factors[p] = std::max(factors[p], np);
    }
  }

  int lcm = 1 << f2;
  for(auto &x: factors){
    lcm = (long long) lcm * modpow(x.first, x.second) % mod;
  }

  long long int ans = 0;
  for(int i = 0; i < n; i++) ans += minv[A[i]];
  ans %= mod;


  printf("%d\n", (int) ((long long)lcm*ans%mod));

  return 0;
}


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int n = x+y+z;
  vector<long> a(n), b(n), c(n);
  vector<int> vi(n);
  long sc = 0;
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
    vi[i]=i;
    sc += c[i];
    a[i] -= c[i];
    b[i] -= c[i];
  }

  sort(all(vi),[&](int l, int r){
    return a[l]-b[l] < a[r]-b[r];
  });
  // a[l]+b[r] < a[r]+b[l]

  vector<long> vl(n+1, 0), vr(n+1, 0);

  {
    priority_queue<long, vector<long>, greater<long> > pq;
    // 左からL個の中からy個b
    long tmp = 0;
    rep(i,y){
      int id = vi[i];
      pq.push(b[id]);
      tmp += b[id];
    }
    vl[y-1] = tmp;
    repl(i,y,n){
      int id = vi[i];
      tmp += b[id];
      long t = pq.top(); pq.pop();
      long u = b[id];
      pq.push(max(t, u));
      tmp -= min(t, u);
      vl[i] = tmp;
    }
  }

  {
    priority_queue<long, vector<long>, greater<long> > pq;
    // 右からR個の中からx個のa
    long tmp = 0;
    for(int i=n-1; i>=n-x; i--){
      int id = vi[i];
      pq.push(a[id]);
      tmp += a[id];
    }
    vr[n-x] = tmp;
    for(int i=n-x-1; i>=0; i--){
      int id = vi[i];
      tmp += a[id];
      long t = pq.top(); pq.pop();
      long u = a[id];
      pq.push(max(t, u));
      tmp -= min(t, u);
      vr[i] = tmp;
    }
  }

  long ans = -1e+15;
  for(int i=y-1; i+x<n; i++){
    ans = max(ans, vl[i] + vr[i+1]);
  }

  cout << sc + ans << endl;

  return 0;
}


Measured memory_bytes: 5752
#include<iostream>
using namespace std;
long int a[123456];
int main()
{
    long int n,i,odd=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]%2)
            odd++;
    }
    if(odd%2)
        cout<<"NO\n";
    else
        cout<<"YES\n";
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pl;
const int MAXN = 3000;
const ll MOD = 2019;
ll l, r, ans;
int m;
bool visit[MAXN];
vector<ll> v;

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

	ans = 1e7;
	
	cin >> l >> r;

	for (ll i = l; i <= r; i++) {
		ll val = i % MOD;
		if (visit[val]) {
			break;
		}
		visit[val] = true;
	
		v.push_back(val);
	}

	m = v.size();

	for (int i = 0; i < m; i++) {
		for (int j = i+1; j < m; j++) {
			ll cur = (v[i] * v[j]) % MOD;
			ans = min(ans, cur);
		}
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,i,j,c,p[5],a,x=0,z[5],flg;
	while(1){
		scanf("%d",&n);
		if(n==0000) break;
		flg=0;
		c=0;
		while(1){
			if(n==6174) break;
			for(i=0;i<4;i++){
				p[i]=n%10;
				a=n/10;
				n=a;
			}
			if(p[0]==p[1]&&p[0]==p[2]&&p[0]==p[3]){
				flg=1;
				printf("NA\n");
				break;
			}
			c++;
			for(i=0;i<4;i++) z[i]=p[i];
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(z[i]<z[j]){
						x=z[i];
						z[i]=z[j];
						z[j]=x;
					}
				}
			}
			for(i=0;i<3;i++){
				for(j=i+1;j<4;j++){
					if(p[i]>p[j]){
						x=p[i];
						p[i]=p[j];
						p[j]=x;
					}
				}
			}
			n=(z[0]*1000+z[1]*100+z[2]*10+z[3])-(p[0]*1000+p[1]*100+p[2]*10+p[3]);
		}
		if(flg!=1) printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 2600
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    n, k = i_map()
    num_list = i_list()

    num_list.sort()

    count = 0

    for i in range(k):
        count += num_list[i]

    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 77096
#include<limits.h>
#include<math.h>
#include <iostream>
#include<algorithm>
using namespace std;

int minc(int *h,int n,int k)
  {
      int res[n];
      res[n-1]=0;
      for(int i=n-2;i>=0;i--)
       {
           int mi=INT_MAX;
           for(int j=1;j<=k && (i+j)<n;j++)
            {
                mi=min(res[i+j]+abs(h[i+j]-h[i]),mi);
            }
           res[i]=mi;    
       }
      return res[0]; 
  }

int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
	   cin>>h[i];
	cout<<minc(h,n,k);   
	return 0;
}


Measured memory_bytes: 1024
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/*Used path compression technique*/
/*-------------------------------------*/
//ll finds(ll a)
//{
//    vector<ll>vec;
//    while(parent[a]>0){
//        vec.pb(a);
//        a=parent[a];
//    }
//    for(int i=0;i<vec.size();i++)parent[vec[i]]=a;
//    return a;
//}
//void unions(ll a,ll b)
//{
//    parent[a]+=parent[b];
//    parent[b]=a;
//}
/*------------------------------*/
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
ll arr[200];
void Dufaux()
{
    ll n,ans=1;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>arr[i];
    for(int i=1;i<=n;i++)ans=lcm(ans,arr[i]);
    cout<<ans<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
int a[100010];
int d[100010];
int cnt=1,n;
int fun(int i)
{
    int j,k,m,n;
    if(a[i]==2)
    {
        cout<<cnt<<endl;
    }
    else
    {
        cnt++;
        d[i]=0;
        if(d[a[i]])
            fun(a[i]);
        else
            return 1;
    }
}
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int i,j,k,m,n;
    int cnt=0;
    for(i=1; i<=100000; i++)
        d[i]=1;
    cin>>n;
    for(i=1; i<=n; i++)
        cin>>a[i];
    if(fun(1)==1)
        cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1024