akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



#ifdef __APPLE__
const int N = 1e2+50;
#else
const int N = 1e6+50;
#endif




int main() {
	ll n,m;
	cin>>n>>m;
	ll ans=1900*m+100*(n-m);
	ans*=qpow(2,m);
	cout<<ans<<endl;
}








Measured memory_bytes: 256
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 L = sc.nextLong();

		final long INF = (long)1e13;
		long[][] d = new long[N][N];
		for(int i=0; i<N; i++) {
			Arrays.fill(d[i], INF);
			d[i][i] = 0;
		}
		for(int i=0; i<M; i++) {
			int A = sc.nextInt()-1;
			int B = sc.nextInt()-1;
			long C = sc.nextLong();
			d[A][B] = d[B][A] = C;
		}
		
		for(int k=0; k<N; k++)
			for(int i=0; i<N; i++)
				for(int j=0; j<N; j++)
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
		
		for(int i=0; i<N; i++)
			for(int j=0; j<N; j++)
				if(0<d[i][j]) {
					if(d[i][j]<=L)
						d[i][j] = 1;
					else
						d[i][j] = INF;
				}
		
		for(int k=0; k<N; k++)
			for(int i=0; i<N; i++)
				for(int j=0; j<N; j++)
					d[i][j] = Math.min(d[i][j], d[i][k] + d[k][j]);
		
		int Q = sc.nextInt();
		for(int i=0; i<Q; i++) {
			int s = sc.nextInt()-1;
			int t = sc.nextInt()-1;
			System.out.println(d[s][t]<INF ? d[s][t]-1 : -1);
		}
		
		sc.close();
	}
}



Measured memory_bytes: 91236
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=10005;
const int mod=1e9+7;
int a[101];
int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    while(cin>>n){
        int s=0;
        for(int i=0;i<n;i++)
            cin>>a[i];
        sort(a,a+n);
        if(a[0]==a[n-1]) cout<<s<<endl;
        else{
            s=1234567;
            int t=0,j;
            for(int i=a[0];i<a[n-1];i++){
                t=0;
                for(j=0;j<n;j++){
                    t+=(i-a[j])*(i-a[j]);
//                    cout<<t<<endl;
                }
                if(t<s) s=t;
            }
            cout<<s<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import copy

Q, H, S, D = map(int,input().split())
N = int(input())
flat = [8*Q, 4*H, 2*S, D]
work = copy.deepcopy(flat)
work.sort()

rank = 1
order = [0, 0, 0, 0]
for i in range(4):
    for j in range(4):
        if work[i] == flat[j]:
            order[j] = rank
            rank += 1
if order[3] == 1: #2リットルが一番効率がいい
    second = 0
    for i in range(4):
        if order[i] == 2:
            second = i
    if N % 2 == 0:
        print(str(D*N//2))
    else:
        if second == 0:
            print(str(D*(N//2) + Q*4))
        elif second == 1:
            print(str(D*(N//2) + H*2))
        else:
            print(str(D*(N//2) + S))
else:
    buy = 0
    for i in range(4):
        if order[i] == 1:
            buy = i
    if buy == 0:
        print(str(Q*4*N))
    elif buy == 1:
        print(str(H*2*N))
    else:
        print(str(S*N))

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

int main(){
    int n,d;
    cin >> n >> d;
    int x[n][d];
    rep(i,n)rep(j,d)cin >> x[i][j];
    int ans = 0;
    double temp = 0;
    rep(i,n){
        for(int k = i+1;k<n;k++){
            rep(j,d){
                temp += pow(x[i][j] - x[k][j],2); 
            }
            // cout << temp << endl;
            temp = pow(temp,0.5);
            // cout << temp <<endl;
            if(temp - int(temp) == 0)ans++;
            temp = 0;
        }
    }
    cout << ans << endl;
}

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

int main() {
	uint64_t n,k;
	cin >> n >> k;
	vector<vector<uint64_t>> nums(n,vector<uint64_t>(2));

	for (int i = 0; i < n; i++) {
		int a, b;
		scanf("%d %d", &a, &b);
		nums.at(i).at(0) = a;
		nums.at(i).at(1) = b;
	}

	sort(nums.begin(), nums.end());

	/*
	cout << "nums" << endl;
	for (int i = 0; i < nums.size(); i++) {
		cout << nums.at(i).at(0) << " " << nums.at(i).at(1) << endl;
	}
	*/

	uint64_t temp = 0;
	uint64_t ans = 0;
	for (int i = 0; i < nums.size(); i++) {	
		if (temp >= k) {
			ans = nums.at(i-1).at(0);
			break;
		}
		temp += nums.at(i).at(1);
		if (i == nums.size() - 1) { ans = nums.at(i).at(0); }
	}
	cout << ans << endl;
}

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

int main() {
  vector<int> a(3);
  for (int i = 0; i < 3; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  cout << a.at(0) << " " << a.at(1) << " " << a.at(2) << endl;
}


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

long long ary[100010];
vector<long long> vec;
int main(){
	long long N;
	cin>>N;
	for(long long i=1;i<=N;i++){
		cin>>ary[i];
	}
	for(long long i=1;i<=N;i++){
		if((ary[i]+1)/2<(i-vec.size())){
			vec.push_back(i-vec.size());
		}
	}
	long long noko=N-vec.size();
	long long res=1;
	for(vector<long long>::iterator it=vec.begin();it!=vec.end();it++){
		res=(res*(*it))%1000000007;
	}
	for(long long i=1;i<=noko;i++){
		res=(res*i)%1000000007;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 1660
//{??????(???)?????????(???)?????????(???)??????, ??????(???)??????}??¨???????§?????????°?????????????????£?????????.
//??????????§??????????????????¶????????????????????????(????????????????????°, ????????´???)???????????§???????????§DP?????§????????????
//?§?????????????????????¶???????????????O(N)?????????????????????O(N^3)???????¨??????§???????§?O(1)?????§???????????§???O(RN^2)???DP????????£????????????????????????
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

void chmin(int &a, int b) {
	a = min(a, b);
}

int INF = 1145141919;
int n, m;
int cost[2][200][200];
int r;
int z[1000];
int dp[1000][200];

void initCost() {
	int i, j, k;
	for (i = 0; i < 2; i++) {
		for (j = 0; j < n; j++) for (k = 0; k < n; k++) cost[i][j][k] = INF;
		for (j = 0; j < n; j++) cost[i][j][j] = 0;
	}
}

void initDp() {
	int i, j;
	for (i = 0; i < r; i++) for (j = 0; j < n; j++) dp[i][j] = INF;
}

signed main() {
	int i, j, k, l;
	
	while (cin >> n >> m) {
		if (!n) break;
		initCost();
		for (i = 0; i < m; i++) {
			int s, d, c; char type;
			cin >> s >> d >> c >> type;
			s--; d--;
			if (type == 'L') {
				cost[0][s][d] = c;
				cost[0][d][s] = c;
			}
			else {
				cost[1][s][d] = c;
				cost[1][d][s] = c;
			}
		}
		
		cin >> r;
		for (i = 0; i < r; i++) { cin >> z[i]; z[i]--; }
		
		for (i = 0; i < 2; i++)
			for (l = 0; l < n; l++)
				for (j = 0; j < n; j++)
					for (k = 0; k < n; k++)
						chmin(cost[i][j][k], cost[i][j][l] + cost[i][l][k]);
		
		initDp();
		dp[0][z[0]] = 0;
		for (i = 0; i < r - 1; i++) {
			for (j = 0; j < n; j++) {
				//???z[i]???(???)???z[i+1]
				chmin(dp[i + 1][j], dp[i][j] + cost[0][z[i]][z[i + 1]]);
				for (k = 0; k < n; k++) {
					//???z[i]???j???(???)???k???z[i+1]
					chmin(dp[i + 1][k], dp[i][j] + cost[0][z[i]][j] + cost[1][j][k] + cost[0][k][z[i + 1]]);
				}
			}
		}
		
		int ans = INF;
		for (i = 0; i < n; i++) chmin(ans, dp[r - 1][i]);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 5248
private fun readIntArray(): List<Int> {
    return readLine()!!.split(" ").map{ it.toInt() }
}

private fun readInt(): Int {
    return readLine()!!.toInt()
}

private fun readTextArray(): List<String> {
    return readLine()!!.split(" ")
}

fun main(args: Array<String>) {
    val (A, B, K) = readIntArray()

    val result = mutableListOf<Int>()

    var temp = A

    while(temp < A + K && temp <= B) {
        result.add(temp)
        temp += 1
    }

    temp = B
    while(temp > B - K && temp >= A) {
        result.add(temp)
        temp -= 1
    }

    val unique = result.distinct().sorted()

    unique.forEach { println(it) }
}

Measured memory_bytes: 38160
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <iterator>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <tuple>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <complex>
#include <bitset>
#include <numeric>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n) ;++(i))
#define REPN(i,a,n) FOR((i),(a),(a)+(n))
#define FOR(i,a,b) for(int (i)=(a); (i)<(b) ;++(i))
#define PB push_back
#define MP make_pair
#define SE second
#define FI first
#define DBG(a) cerr<<(a)<<endl;
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;  typedef pair<LL, LL> PLL; typedef vector<LL> VLL;
const LL LINF=334ll<<53; const int INF=15<<26; const LL MOD=1E9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >>n;
    vector<int> a(n),b(n),p(n+1);
    REP(i,n){
        int tmp; cin >> tmp;
        p[tmp]=i;
    }
    REP(i,n){
        a[i]=50000*i+1;
        b[i]=50000*(n-1-i)+p[i+1]+1;
    }
    REP(i,n)cout << a[i]<< (i==n-1?'\n':' ');
    REP(i,n)cout << b[i]<<(i==n-1?'\n':' ');

    return 0;
}


Measured memory_bytes: 896
// AOJ 2345: Network Reliability
// 2017.10.24 bal4u@uu

#include <stdio.h>

int u[102], v[102];
double dp[16500];

int main()
{
	int n, m, i, j, k, l, lim;
	double p, t;

	scanf("%d%d%lf", &n, &m, &p); p /= 100;
	for (i = 0; i < m; i++) scanf("%d%d", u+i, v+i), u[i]--, v[i]--;
	lim = 1 << n;
	for (i = 1; i < lim; i++) {
		for (l = 1; !(l & i); l<<=1);
		dp[i] = 1;
		for (k = i; k; k = (k - 1) & i) {
			if (k == i || !(k & l)) continue;
			t = dp[k];
			for (j = 0; j < m; j++) {
				if ((i & (1<<u[j])) && (i & (1<<v[j])) && ((k>>u[j]) & 1) != ((k>>v[j]) & 1))
					t *= p;
			}
			dp[i] -= t;
		}
	}
	printf("%.12f\n",dp[lim - 1]);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define 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 VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }



ll N,K;
vector<ll> A;
void input(){
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N >> K;
  A = fetch_vec<ll>(N);
}


int solve(){
  input();
  ll ans=0;
  int M=41;
  for(int j=M;j>=0;j--){
    ll X=0;
    ll ansj=0;
    if(!((K>>j)&1)) continue;
    for(int k=M;k>j;k--) X |= K&(1LL<<k);
    for(int i=(j-1);i>=0;i--){
      int chk=0;
      for(auto a:A) chk += (a>>i)&1;
      if(2*chk >= N) continue;
      else X |= (1LL<<i);
      }
    REP(i,N) ansj += X^A[i];
    ans = max(ans,ansj);
  }
  ll X = K;
  ll ansj=0;
  REP(i,N) ansj += X^A[i];
  ans = max(ans,ansj);

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

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 1024
import bisect

n, m, k = map(int, input().split())
alist = list(map(int, input().split()))
blist = list(map(int, input().split()))

for i in range(len(alist)-1):
    alist[i+1] += alist[i]

for i in range(len(blist)-1):
    blist[i+1] += blist[i]

x = bisect.bisect_right(alist, k)
ans = bisect.bisect_right(blist, k)
for i in range(x):
    d = k - alist[i]
    y = bisect.bisect_right(blist, d) + i + 1
    if ans < y:
        ans = y

print(ans)

Measured memory_bytes: 40416
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         LinkedList<Integer>[] edges = new LinkedList[N+1];
         for(int i=1; i <= N; i++)
            edges[i] = new LinkedList<Integer>();
         for(int i=0; i < M; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            edges[a].add(b);
            edges[b].add(a);
         }
         boolean[] seen = new boolean[N+1];
         int[] par = new int[N+1];
         Queue<Integer> q = new LinkedList<Integer>();
         seen[1] = true;   q.add(1);
         while(q.size() > 0)
         {
            int curr = q.poll();
            for(int next: edges[curr])
               if(!seen[next])
               {
                  par[next] = curr;
                  seen[next] = true;
                  q.add(next);
               }
         }
         for(int i=1; i <= N; i++)
            if(!seen[i])
            {
               System.out.println("No");
               return;
            }
         System.out.println("Yes");
         StringBuilder sb = new StringBuilder();
         for(int i=2; i <= N; i++)
            sb.append(par[i]+"\n");
         System.out.print(sb);
      }
   }

Measured memory_bytes: 79856
#include<bits/stdc++.h>
using namespace std;
int cnt;
void insertionSort(int *A,int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0&&A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}
void shellSort(int *A,int n){
  cnt=0;
  int r=1;
  vector<int> G;
  while(r<=n){
    G.push_back(r);
    r*=2;
  }
  int m=G.size();
  reverse(G.begin(),G.end());
  cout<<m<<endl;
  for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
  for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
  cout<<cnt<<endl;
}
signed main(){
  int n;
  cin>>n;
  int A[n];
  for(int i=0;i<n;i++) cin>>A[i];
  shellSort(A,n);
  for(int k=0;k<n;k++) cout<<A[k]<<endl;
  return 0;
}

Measured memory_bytes: 7044
import numpy as np 
X = int(input())
if 100<=X<=105:
    print(1)
    exit()
# 最低保証回数
Nmax = X//100
# 必ず0がたされるので、先に引いておいてやる
X -= 100*Nmax

x = np.ceil(X/5)
# print(Nmax, x)
if Nmax < x:
    print(0)
else:
    print(1)

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

using namespace std;

int main() {
  string S, T;
  cin >> S >> T;
  int S_length = S.length();
  int T_length = T.length();

  int result = T_length;
  for (int i = 0; i < S_length - T_length + 1; i++) {
    int count = 0;
    for (int j = 0; j < T_length; j++) {
      if (S[i + j] != T[j]) count++;
    }
    if (count < result) result = count;
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
 
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define M 1000000007
#define mp make_pair
#define pb push_back
#define PB pop_back
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define lcase(a) (char)tolower(a)
#define ucase(a) (char)toupper(a)
#define precise(a) fixed<<setprecision(a)<<
#define F first
#define S second
#define I insert
#define pii pair<int,int>
#define trav(a, x) for(auto& a : x)
#define fl(i,n) for(int i = 0;i<n;i++)
#define rfl(n) for(int i = n-1;i>=0;i--)
#define time cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define invect(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.pb(tmp);commands}
#define inset(data,n,commands) for(int i = 0;i<n;i++){int tmp;cin>>tmp;data.I(tmp);commands}
#define display(x) trav(a,x) cout<<a<<" "; cout<<endl;
#define ingrid(data,n,commands) for(int i = 0; i<n; i++){cin>>data[i];commands}
#define section(a,b,w) set_intersection(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define union(a,b,w) set_union(a.begin(), a.end(),b.begin(), b.end(),back_inserter(w));
#define copy(a,w) copy(a.begin(), a.end(),back_inserter(w));
#define all(data) data.begin(), data.end()
#define PI 3.14159265358979323844
#define endl '\n'
#define last(a) a[sz(a)-1]
#define mp make_pair
 
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
 
// Graph DFS
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
 
//primes for hashing 937,991,1013,1409,1741
 
//Returns index of first element not less than key and more than key respectively
#define lb(data,key) lower_bound(all(data),key) - data.begin();
#define up(data,key) upper_bound(all(data),key) - data.begin();
#define fnd(data,key) find(all(data),key) - data.begin();
//Long Long Int
#define int long long int

void solve()
{
    int n;cin>>n;
    std::vector<std::vector<int> > v(n,std::vector<int> (3,0));
    fl(i,n)
    {
        fl(j,3)
        {
            cin>>v[i][j];
        }
    }
    int dp[n][3];
    fl(i,3)
    {
        dp[0][i]=v[0][i];
    }
    for(int i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+v[i][0];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+v[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+v[i][2];
    }
    cout<<max(max(dp[n-1][1],dp[n-1][0]),dp[n-1][2])<<endl;
}
 
signed main()
{
    
    FAST
    
    int t = 1;
    //cin>>t;
    while(t--)
    solve();
    
 
return 0;
}
 
/*6
30 10 60 10 60 50*/

Measured memory_bytes: 8064
ans [[n,d],xs] =
  let v = foldr (\ x a -> if x >= d then a + (x - d) else a) 0 xs
  in
    if v == 0 then "kusoge" else show(v)

main = do
  c <- getContents
  let i = map (map read) $ map words $ lines c :: [[Int]]
      o = ans i
  putStrLn o



Measured memory_bytes: 4320
import java.util.Scanner;
public class Main{
      
    public void solve(){
        Scanner sc = new Scanner(System.in);
        int x;
         
        x = sc.nextInt();
         
        System.out.println(x*x*x);
    }
 
              
    public static void main(String[]args){
        Main obj = new Main();
        obj.solve();
    }
}

Measured memory_bytes: 17152
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{

        ll n;
        cin>>n;
        ll arr[n];
        for(int i=0;i<n;i++)
        {
            cin>>arr[i];
        }
        sort(arr,arr+n);
        ll ch=arr[0];ll ans=0;
        ll bada=arr[n-1];
        ans+=(bada-ch);
       // if(n>2){
        for(int i=1;i<n/2;i++)
        {
            ll x=bada-arr[i];
            ll y=arr[n-i-1]-ch;
            ans+=(x+y);
            bada=arr[n-i-1];
            ch=arr[i];
        }
        if(n%2==1)
        {
            ans=ans+max(abs(arr[(n)/2]-ch),abs(bada-arr[(n)/2]));
        }//}
        cout<<ans<<endl;

    return 0;
}


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

int main() {
  int a;
  cin >> a;
  cout << 3*(a*a) <<endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

int f(int a, int b)
{
    return b?f(b, a%b):a;
}

int gcd(int a, int b, int c)
{
    int ans = a;
    ans = f(a, b);
    ans = f(ans, c); 
    return ans;
}

int main()
{
    int N;
    cin >> N;
    int ans=0;

    for(int a=1;a<=N;++a)
    {
        for(int b=1;b<=N;++b)
        {
            for(int c=1;c<=N;++c)
            {
                ans += gcd(a, b, c);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3620
import java.util.*;

import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		TCase:while(true){
			int a=sc.nextInt(),l=sc.nextInt();
			if(a==0)return;
			List<Integer> alist=new ArrayList<Integer>();
			alist.add(a);
			int c=0;
			while(true){
				c++;
				char[] str=String.format("%0"+l+"d",a).toCharArray();
				Arrays.sort(str);
				int min=0,max=0;
				for(int i=0;i<l;i++){
					min=10*min+ (str[i]-'0');
					max=10*max+(str[l-1-i]-'0');
				}
				a=max-min;
				if(alist.contains(a)){
					int ind=alist.indexOf(a);
					ln(ind+" "+a+" "+(c-ind));
					continue TCase;
				}
				alist.add(a);
			}


		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 23736
#include <vector>
#include <iostream>

using namespace std;

// ref: https://atcoder.jp/contests/dp/submissions/7981121

int main(int argc, char const *argv[]) {
    int MOD = 1000000007;
    int N;
    cin >> N;
    vector<vector<int>> a(N, vector<int>(N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> a[i][j];
        }
    }

    vector<vector<int>> dp(N + 1, vector<int>(1 << N, 0));
    dp[0][0] = 1;
    for (int i = 1; i <= N; i++) {
        for (int mask = 0; mask < (1 << N); mask++) {
            if (__builtin_popcount(mask) != i) {
                continue;
            }
            for (int j = 0; j < N; j++) {
                if (a[i-1][j] && (mask & (1 << j))) {
                    dp[i][mask] += dp[i - 1][mask ^ (1 << j)];
                    if (dp[i][mask] >= MOD) {
                        dp[i][mask] -= MOD;
                    }
                }
            }
        }
    }
    // for (int i = 0; i <= N; i++) {
    //     for (int mask = 0; mask < (1 << N); mask++) {
    //         cout << dp[i][mask] << ", ";
    //     }
    //     cout << endl;
    // }
    cout << dp[N][(1 << N) - 1] << endl;
    return 0;
}


Measured memory_bytes: 188800
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest-
#  Atcoder_Grand_Contest012-A
#  https://atcoder.jp/contests/agc012/tasks/agc012_a

def  maxLevel(memberNumber,orgMemberLevelList):
	maxLevelSortedList = sorted(orgMemberLevelList,reverse=True)
	maxLevelScore = 0
	checkMemberCountRange = range(0,memberNumber,+1)
	for i in checkMemberCountRange:
		maxLevelScore = maxLevelScore+maxLevelSortedList[2*i+1]
	answer = maxLevelScore
	return answer


if __name__ == '__main__':
	N = int(input().strip())
	levelNoSortList = list(map(int,input().strip().split(' ')))
	solution=maxLevel(N,levelNoSortList)
	print("{}".format(solution))

Measured memory_bytes: 39492
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=998244353;

ll MAX=200001;
vector<ll> F(MAX,1);
 
void fact(){
    for(ll i=1;i<MAX;i++){
    F[i]=F[i-1]*i%MOD;
    }
return;
}


// mod. m での a の逆元 a^{-1} を計算する
//ただしmとaが互いにその時のみ
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long comb(long long a, long long b){
    return (((F[a]*modinv(F[b],MOD))%MOD)*modinv(F[a-b],MOD))%MOD;
}

// a^n mod を計算する
//ただしmodとaが互いにその時のみ
long long modpow(long long a, long long n) {
    long long res = 1;ll mod=MOD;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓
//↓↓↓↓↓↓fact()ってちゃんとつける！！！！！！！！！！！↓↓↓↓↓↓


int main(){
    fact();
    ll N;
    cin >> N;
    ll M;
    cin >> M;
    ll K;
    cin >> K;
    ll ans=0;
    for(ll i=0;i<=K;i++){
        ans+=(((comb(N-1,i)*M)%MOD)*modpow(M-1,N-1-i))%MOD;
        ans%=MOD;
    ;}

    cout<<ans<<endl;



    return 0;
}


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

#define MAX(A, B) (((A) > (B)) ? (A) : (B))

int* aclist(char* s, int size) {
  int f=0;
  int count=0;
  int* list = malloc((size + 1) * sizeof(int));
  for (int i=0; i<size; i++) {
  	if (*(s + i) == 'A') {f = 1;}
  	else if ((*(s + i) == 'C') && (f)) {
      count++;
  	  f = 0;
  	}
    else {
      f = 0;
    }
    
    *(list + i) = count;
  }
  *(list + size) = count;
  return list;
}

int ac(int* list, int l, int r) {
  int n;
  n = *(list + r - 1) - *(list + l - 1);
  return n;
}

int main() {
  int N, Q;
  scanf("%d %d", &N, &Q);
  
  char* s = malloc(N * sizeof(char));
  scanf("%s", s);
  int* list = aclist(s, N);
  
  int l, r;
  
  for (int i=0; i<Q; i++) {
    scanf("%d %d", &l, &r);
    
  	printf("%d\n", ac(list, l, r));
  }
  return 0;
}


Measured memory_bytes: 1280
#include<stdio.h>

int main()
{
  char  x[100001];
  int  a[26], i;
  
  scanf("%s", x);
  for(i=0; x[i] != '\0'; i++){
    a[x[i] - 'a'] = 1;
  }
  for(i=0; i < 26; i++){
    if(a[i] == 0)
      break;
  }
  if(i == 26){
    printf("None\n");
  }else{
    printf("%c\n", i + 'a');
  }
  
  return 0;
}

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

int main(){
  int N,K,x;
  cin >> N >> K;
  int A = 0;
  for(int i; i < N; i++){
    cin >> x;
    if(x > K - x){
      A = A + 2*(K - x);
    }
    else{
      A = A + 2 * x;
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int A, B;
    cin >> A >> B;
    cout << A - B + 1 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r)
{
	int x, i, j, t;
	x=A[r];
	i=p-1;
	for(j=p;j<r;j++)
	{
		if(A[j]<=x)
		{
			i++;
			t=A[i];
			A[i]=A[j];
			A[j]=t;
		}
	}
	t=A[i+1];
	A[i+1]=A[r];
	A[r]=t;
	return i+1;
}

int main()
{
	int i, q;
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d", &A[i]);
	}
	q=partition(0, n-1);
	for(i=0;i<n;i++)
	{
		if(i)
			printf(" ");
		if(i==q)
			printf("[");
		printf("%d", A[i]);
		if(i==q)
			printf("]");
		
	}
	printf("\n");
	return 0;
}


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

unordered_map<int,int> memo;
int fib(int n){
    if(n<2) return 1;
    if (not memo.count(n)) memo[n] = fib(n-1)+fib(n-2);
    return memo[n];

}

int main(void){cin.tie(0);ios::sync_with_stdio(false);
    int n; cin>>n;
    cout<<fib(n)<<"\n";
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
const int TMAX = 30000;

pair< vector<int>, vector<int> > eratosthenes(int N){
  vector<int> res;
  vector<int> arr(N);
  for(int i=0; i < N; i++){
    arr[i] = true;
  }
  arr[0] = false;
  arr[1] = false;
  for(int i=2; i*i <= N; i++){
    if(arr[i] == true){
      for(int j=i+i; j < N; j += i){
        arr[j] = false;
      }
    }
  }
  for(int i = 0; i < N; i++){
    if(arr[i] == true) res.push_back(i);
  }
  return pair< vector<int>, vector<int> >(res, arr);
}

bool isTri(int i, int j, int k){
  int a[] = {i, j, k};
  sort(a, a+3);
  if(a[2] < a[1] + a[0]) return true;
  else return false;
}

int main(void){
  int T;
  while(cin >> T, T){
    pair< vector<int>, vector<int> > tmp = eratosthenes(TMAX);
    vector<int> primes = tmp.first;
    vector<int> is_prime = tmp.second;
    int ans = 0;
    for(int i = 0; i < primes.size(); i++){
      for(int j = i; j < primes.size(); j++){
        int k = T - primes[i] - primes[j];
        if(k >= 1 && k >= primes[j] && is_prime[k] == true && isTri(primes[i], primes[j], k)){
          //cout << primes[i] << " " << primes[j] << " " << k << endl;
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3124
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>


#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))
#define FOR(i,n) for (int i = 1; (i) <= (n); ++ (i))
#define dump(x)  cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9+7;
//const lint LINF = 1e18;
const double eps = 0.000000001;//もとの値の10^(-16)まで

using namespace std;

typedef pair<int, int> P;
//priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順
vector<int> edge[200000];
int c[200000];
int f[200000];
int deg[200000];

void dfs(int now,int pa){
  REP(i,edge[now].size()){
    int k = edge[now][i];
    if(k==pa) continue;
    if(f[k]==1){
      if(deg[k]>deg[pa]){
        cout << now << " " << k << endl;
        c[now] ++;
      }
    }
    else{
      f[k] = 1;
      deg[k] = deg[pa]+1;
      dfs(k,now);
    }
  }
  if(c[now]%2==1&&now!=1){
    cout << now << " " << pa << endl;
    c[now]++;
  }
  else if(now!=1){
    cout << pa << " " << now << endl;
    c[pa]++;
  }
}


signed main(){
  int n,m;
  cin >> n >> m;
  if(m%2==1){
    cout << -1 << endl;
    return 0;
  }
  REP(i,m){
    int a1,b1;
    cin >> a1  >> b1;
    edge[a1].pb(b1);
    edge[b1].pb(a1);
  }
  f[1] = 1;
  deg[1] = 1;
  dfs(1,1);
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n, x;
  cin >> n >> x;
  vi32 a(n);
  cin >> a;
  i64 ans = 0;
  rep(i, n - 1) {
    int c = max(0, a[i] + a[i + 1] - x);
    ans += c;
    a[i + 1] = max(0, a[i + 1] - c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define itoc(c)               ((char)(((int)'0')+c))
#define vl                    vector<ll>
#define SZ(x)                 (x).size()
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define sv()                  ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase()               ll t,n; cin>>t;n=t; while(t--)
#define iscn(num)             scanf("%d",&num);
#define scn(num)              scanf("%lld",&num);
#define scn2(num,num2)        scanf("%lld%lld",&num,&num2);
#define dbg(x)                cerr <<"( "<<#x << " = " << x << " )"<<endl
using namespace std;
const ll INF = 2e18 + 99;
typedef pair<ll,ll> Pair;
typedef vector<ll> vec;;
void FAST_IO();
void ara_read(vec &v,ll n);
////////////////////////

int main()
{
	ll n; 
	scanf("%lld",&n);
	vector<vector<ll> >holiday(n,vector<ll>(3,0));
	vector<vector<ll> >dp(2,vector<ll>(3,0));
	for(int i=0; i< n; ++i){
		scanf("%lld%lld%lld",&holiday[i][0],&holiday[i][1], &holiday[i][2]);
		assert(i!=n);
	}
	bool next=1, prev=0;
	for(auto x : {0,1,2}){
		dp[0][x]=holiday[0][x];
	}
	// let's do dp operations...
	for(int i=1 ; i< n; ++i){
		for(int j=0; j< 3 ; ++j){
			for(int x : {0,1,2}){
				if(x==j)
					continue ;
				else {
					dp[next][j]=max(dp[next][j], holiday[i][j]+dp[prev][x]);
				}
			}
		}
		swap(next,prev);
	}
	// printing the ans ...
	printf("%lld\n",max({dp[prev][0] ,dp[prev][1] ,dp[prev][2]}));
    return 0;
}

void FAST_IO()
{
    // ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);

}
void ara_read(vec &v,ll n){
	ll temp;
	for(ll i=0; i<n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
	
}


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

#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

signed main(){
	fastio
	string s;
	cin >> s;
	int ans = 0, tt = -1, t = 0;
	for(int i = 0;i < (int)s.size();i++){
		if(tt){
			if(s[i]=='R') t++;
		}else if(s[i]=='R'){
				t = 1;
				tt = 1;
		}
		if(s[i]=='S'){
			t = 0;
			tt = 0;
		}
		ans = max(t,ans);
	}
	ans = max(t,ans);
	cout << ans << "\n";
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;
public class Main {

public static void main(String[] args) {
		Scanner input= new Scanner(System.in);
		String st=input.next();
		int a = st.length();
		String n ="";
		int i=0;
		while (i < a) {
		n +="x";
		i++;
		
			
		
		}	
		System.out.println(n);
}
}

Measured memory_bytes: 22996
#include "bits/stdc++.h"
using namespace std;
#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 ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    int a=0,b=0,c=0,d,n=0,x=0;
    VI m(3);
    string s,s1,s2;
    cin >> s; 
    if( s[5]== '0' ){
        if ( s[6]== '1' ||s[6]== '2'||s[6]== '3'||s[6]== '4') 
            cout << "Heisei" <<endl;
        else 
            cout << "TBD" <<endl;
    }
    else cout << "TBD" <<endl;
    return 0;
} 

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

#include <iostream>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)

#define N_QUE 100005

struct Process {
  string name;
  int t;
};

class Que {
 private:
  Process que[N_QUE];
  int head = 0, tail = 0;

 public:
  void enque(Process p) {
    que[tail] = p;
    if (tail < N_QUE - 1) {
      tail++;
    } else {
      tail = 0;
    }
  }

  Process deque() {
    Process p = que[head];
    if (head < N_QUE - 1) {
      head++;
    } else {
      head = 0;
    }
    return p;
  }
  bool isEmpty() { return head == tail; }
  bool isFull() { return (tail - head) == N_QUE - 1 || (head - tail == 1); }
};

int main() {
  int n, q, now = 0;
  cin >> n >> q;
  Que que;

  rep(i, n) {
    string name;
    int t;
    cin >> name >> t;
    if (t > q) {
      now += q;
      Process p;
      p.name = name;
      p.t = t - q;
      que.enque(p);
    } else {
      now += t;
      cout << name << " " << now << endl;
    }
  }

  while (!que.isEmpty()) {
    Process p = que.deque();
    if (p.t > q) {
      now += q;
      p.t -= q;
      que.enque(p);
    } else {
      now += p.t;
      cout << p.name << " " << now << endl;
    }
  }
  return 0;
}



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

using namespace std;

typedef long long ll;

const ll INF = - 1e15;
const int MAX_N = 1e2 + 5;
const int MAX_W = 1e5 + 5;

int n, capacity;

ll dp[2][MAX_W];

int p[MAX_N], w[MAX_N];

int main() {
  // dp[n][w] = the maximum profit to get the weight w from the first n objects
  // dp[n][w] = max(dp[n - 1][w] (so i don't chose the object n), dp[n - 1][w - w[i]] + p[i] (i chose it))
  int t;
  cin >> n >> capacity;
  for (int i = 1; i <= n; ++i) {
    cin >> w[i] >> p[i];
  }
  t = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= capacity; ++j) {
      dp[t][j] = dp[1 - t][j];
      if (j - w[i] >= 0) {
        dp[t][j] = max(dp[t][j], dp[1 - t][j - w[i]] + p[i]);
      }
    }
    t = 1 - t;
  }
  cout << dp[1 - t][capacity] << "\n";
  return 0;
}


Measured memory_bytes: 1792
# m-solutions2019D - Maximum Sum of Minimum
def bfs(start: int) -> None:
    q = [start]
    nodes[start] = C.pop()
    while q:
        v = q.pop(0)
        for u in T[v]:
            if not nodes[u]:
                nodes[u] = C.pop()
                q.append(u)


def main():
    # adjacent edges should have close numbers as much as possible -> sort, bfs
    global T, C, nodes
    N, *ABC = map(int, open(0).read().split())
    AB, C = ABC[:-N], ABC[-N:]
    C.sort()
    T = [[] for _ in range(N + 1)]
    for v, u in zip(*[iter(AB)] * 2):
        T[v].append(u), T[u].append(v)
    score, nodes = sum(C) - C[-1], [0] * (N + 1)  # max of C will not be used
    for i, t in enumerate(T[1:], 1):
        if len(t) == 1:
            start = i  # start from any node with degree 1
            break
    bfs(start)
    print(score)
    print(*nodes[1:])


if __name__ == "__main__":
    main()

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

signed main(void)
{
	long long n, sum; cin >> n;
	long long a[n];
	vector<long long> b(n);

	sum = 0;
	rep(i, n) 
	{
		cin >> a[i];
		a[i] -= (i + 1);
		b[i] = a[i];
	}
	sort(b.begin(), b.end());
	rep(i, n)
	{
		sum += abs(a[i] - (b[n / 2]));
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3328
//by xxj
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define ll long long
#define pii pair<int,int>
#define lowbit(x) x&-x
using namespace std;
const int inf=1e9+7;
const double eps=1e-10;
const ll linf=1e18+7;
const ll hh=523;
//const int mod=;
ll dp[(1<<17)];
int a[17][17];
int n;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			scanf("%d",&a[i][j]);
//			cout<<i<<' '<<j<<' '<<a[i][j]<<endl;
		}
	}
	for (int i=0;i<(1<<n);i++){
		for (int j=0;j<n;j++){
			if (!(i & (1<<j))){
				continue;
			}
//			cout<<i<<' '<<j<<endl;
			for (int k=j+1;k<n;k++){
				if (i & (1<<k)){
//					cout<<i<<' '<<j<<' '<<k<<endl;
					dp[i]+=a[j][k];
				}
			}
		}
	}
//	cout<<dp[(1<<n)-1]<<endl;
	for (int i=0;i<(1<<n);i++){
		for (int j=i;j;j=(j-1)&i){
//			cout<<j<<' '<<i<<' '<<j-i<<endl;
			dp[i]=max(dp[i],dp[j]+dp[i^j]);
		}
	}
	printf("%lld\n",dp[(1<<n)-1]);
	return 0;
}
/*
input:
*/

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,m;
    cin>>n>>m;
    long long mx=0;
    for (long long i=1;i*i<=m;i++)
    {
        if (m%i==0)
        {
            if (m/i >= n)
                mx=max(mx,i);
            if (i >= n)
                mx=max(mx,m/i);
        }
    }
    cout<<mx<<endl;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> a){
    sort(ALL(a));
    LL ans = 0;
    int idx = a.size() - 2;
    REP(i, N) {
        ans+=a[idx];
        idx -= 2;
    }

    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(3*N);
    for(int i = 0 ; i < 3*N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

int main(){
  int K,i1,j1,k1,g1,g2;
  long long ans=0;
  cin>>K;
  
  for(int i=1;i<K+1;i++){for(int j=1;j<K+1;j++){for(int k=1;k<K+1;k++){
    i1=i;j1=j;k1=k;

    while(1){
      if(j1<k1){
        g1=j1;
        if(k1%j1==0){break;}
        j1=k1%j1;
        k1=g1;
      }else{
        g1=k1;
        if(j1%k1==0){break;}
        k1=j1%k1;
        j1=g1;
      }
    }

    while(1){
      if(g1<i1){
        g2=g1;
        if(i1%g1==0){ans+=g2;break;}
        g1=i1%g1;
        i1=g2;
      }else{
        g2=i1;
        if(g1%i1==0){ans+=g2;break;}
        i1=g1%i1;
        g1=g2;
      }
    }
      }}}
  cout<<ans;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> uoii;
typedef unordered_map<string,int> uosi;

const int MOD = 1e9+7;

const int INF = 1e10;
int n;
const int MAXT=5e5+10;
int tr[26][MAXT];
string s;

void add(int  *tr,int x,int v){
  //  cout<<"AAA "<<x<<" "<<n<<'\n';
    for(int i=x;i<=n;i+=i&-i){
        tr[i]+=v;
    //    cout<<"TR "<<tr[i]<<" ";
    }
  //  cout<<'\n';
}

int f(int *tr, int x){
    int ans=0;
    for(int i=x;i>0;i-=i&-i){
        //cout<<"IN";
        ans+=tr[i];
    }
    return ans;
}
int get(int *tr, int l , int r){
    //cout<<"GET "<<n<<'\n';
    //cout<<l<<" "<<r<<'\n';
    if(l>r) return 0;
    int x=f(tr,r);
    int y=f(tr,l-1);
    //cout<<x<<" "<<y<<'\n';
/*
    for(int i=0;i<8;i++){
        cout<<tr[i]<<" "<<' ';
    }
    cout<<'\n';*/
    return (x-y)>=1;
}

int32_t main()
{
    
    IOS
    
    cin>>n;
    cin>>s;
    for(int i=1;i<=n;i++){
        int x = s[i-1]-'a';
        add(tr[x],i,1);
        
    }
    int q;
    cin>>q;
    while(q--){
        int a;
        cin>>a;
        if(a==1){
            int l;
            char t;
            cin>>l>>t;
            int x=s[l-1]-'a';
            int y=t-'a';
            add(tr[x],l,-1);
            add(tr[y],l,1);
            s[l-1]=t;
        }else{
            int l,r;
            cin>>l>>r;
            int ans=0;
            for(int i=0;i<26;i++){
             //   cout<<"IND "<<i<<'\n';
                ans+=get(tr[i],l,r);
            }
            cout<<ans<<'\n';
        }
    }
    
    return 0;
}


Measured memory_bytes: 102556