akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    i64 x = input(), k = input(), d = input();

    x = abs(x);

    i64 t = (x + d - 1) / d;
    if (t > k) {
        cout << x - k * d << endl;
        return;
    }

    x -= t * d;
    k -= t;

    if (k & 1) x += d;
    x = abs(x);

    cout << x << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3656
import java.util.*;
class Main{
public static void main(String args[]){
  Scanner sc=new Scanner(System.in);
  int A[]=new int[5];
  for(int i=0;i<5;i++)A[i]=sc.nextInt();
  for(int i=0;i<5;i++){
    if(A[i]==0){
      System.out.println(i+1);
      break;
    }
    
  }
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define pf push_front
#define rep(i, n) for(int i = 0; i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

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

Measured memory_bytes: 256
r, c = list(map(int, input().split()))
ans = [[0 for j in range(c + 1)] for i in range(r + 1)]
for i in range(r):
    s = list(map(int, input().split()))
    for j in range(len(s)):
        ans[i][j] = s[j]
        ans[i][-1] += s[j]
        ans[-1][j] += s[j]
    ans[-1][-1] += ans[i][-1]

for i in range(len(ans)):
    print(*ans[i])



Measured memory_bytes: 6216
#include <iostream>
#include <string>
#include <map>
using namespace std;
typedef unsigned long long ull;
int main()
{
	string A;
	ull res;
	map<char, ull> mp;
	cin >> A;
	res = A.size();
	for (ull i = 0; i < res; i++)
		mp[A[i]]++;
	
	res = res*(res - 1) / 2;
	for (char c = 'a'; c <= 'z'; c++)
	{
		res -= mp[c] * (mp[c] - 1) / 2;
	}

	cout << res+1 << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>

using namespace std;

int h,w,k,mask;
int dp[50][50][1<<12][4];
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
char mp[51][51];
bool visit[1<<12];

int dfs(int x,int y,int bit,int lk){
    int pt=0,mx=-25000;
    if(dp[x][y][bit][lk]!=-1) return dp[x][y][bit][lk];
    if(x==w-1&&y==h-1&&lk==0) return 0;
    if(!visit[bit]&&mp[y][x]!='.') pt +=mp[y][x]-'0';
    for(int i=0;i<4;++i){
        if(lk==0&&i>1) break;
        int tx=x+dx[i],ty=y+dy[i],nbit=((bit<<2)|i)&mask,uk=i>1?lk-1:lk;
        if(tx>=0&&ty>=0&&tx<w&&ty<h&&mp[ty][tx]!='#') mx=max(mx,dfs(tx,ty,nbit,uk)+pt);
    }
    dp[x][y][bit][lk]=mx;
    return mx;
}

int main(){
    cin>>h>>w>>k;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j) cin>>mp[i][j];
    }
    memset(dp,-1,sizeof(dp));
    mask=(1<<2*2*k)-1;
    for(int i=0;i<=mask;++i){
        int tx=0,ty=0,pre=i;
        for(int j=0;j<2*k;++j){
            tx -=dx[pre&3];ty -=dy[pre&3];
            if(tx==0&&ty==0) visit[i]=true;
            pre >>=2;
        }
    }
    cout<<dfs(0,0,0,k)<<endl;
    return 0;
}

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

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  ll ans = 0;
  if (B - A <= 2) ans = K + 1;
  else ans = A + ((K - (A-1)) / 2) * (B - A) + (K - (A-1)) % 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
using llong = long long;

llong solve(vector<llong>& a, vector<llong>& S, llong signS0=+1) {

    llong op = 0;
    S[0] = a[0];
    if (S[0]*signS0 <= 0) {
        op = abs(S[0]) + 1;
        S[0] = signS0;
    }

    for (size_t i=0; i<a.size()-1; ++i) {
        S[i+1] = S[i] + a[i+1];
        if (S[i+1] == 0) {
            S[i+1] = -(S[i] / abs(S[i]));
            ++op;
        }
        else {
            if(S[i+1]*S[i] > 0) {
                op = op + abs(S[i+1]) + 1;
                // set to +1 or -1.
                S[i+1] = - (S[i+1] / abs(S[i+1]));
            }
        }
    }
    return op;
}

int main() {
    uint n;
    cin >> n;
    vector<llong> a(n, 0);
    vector<llong> S(n, 0);
    for (auto &x: a) cin >> x;

    llong op1 = solve(a, S, +1);
    llong op2 = solve(a, S, -1);
    llong op;
    if (op1 < op2) op = op1;
    else op = op2;
    cout << op << endl;
}


Measured memory_bytes: 4820
n= int(input())
s = str(input())

r=set()
g=set()
b=set()
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
score = len(r)*len(g)*len(b)
for i in r:
    for j in g:
        dist=abs(j-i)
        if (i>j):
            bi = i+dist
            if bi in b:
                score -=1
            bi = j-dist
            if bi in b:
                score -=1
        else:
            bi = j+dist
            if bi in b:
                score-=1
            bi = i-dist
            if bi in b:
                score-=1
        if((i+j)%2==0 and (i+j)/2 in b):
            score-=1
# print(count_)
print(score)

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

using namespace std;

int main(){
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int ans = 0;
    int r,g;
    for(r=0;r<=N;r++){
        for(g=0;g<=N;g++){
            if(N-r*R-g*G >= 0 && (N-r*R-g*G) % B == 0){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
def solve(n, s, t):
    match = 0
    for i in range(n):
        if s[i] == t[0]:
            for j in range(n+1):
                if i+j >= n:
                    match = j
                    break
                elif s[i+j] != t[j]:
                    match = 0
                    break
            if match > 0:
                break
    print("{}".format(n*2-match))


def main():
    n = int(input())
    s = input()
    t = input()
    solve(n, s, t)


if __name__ == "__main__":
    main()


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

#define FOR(i,s,e) for(int i = (s);i <= (e);i++)

const int N_MAX = 100000;

int A[100000];
int B[100000];
int C[100000];

int N;

typedef long long ll;

ll B_cou[100010];
ll C_cou[100010];

int main()
{
	cin >> N;

	FOR(i,0,N - 1)
	{
		cin >> A[i];
	}
	FOR(i,0,N - 1)
	{
		cin >> B[i];
	}

	FOR(i,0,N - 1)
	{
		cin >> C[i];
	}

	sort(A,A + N);
	sort(B,B + N);
	sort(C,C + N);

	int C_step = 0;

	FOR(i,0,N - 1)
	{

		while(C_step < N)
		{
			if(B[i] < C[C_step])
			{
				B_cou[i] += (long long)N - C_step;	
				break;

			}
			C_step++;
		}
	}
	
	for(int i = N - 1;i >= 1;i--)
	{
		B_cou[i - 1] += B_cou[i];
	}

	int B_step = 0;
	ll result = 0;
	FOR(i,0,N - 1)
	{
		while(B_step < N)
		{
			if(A[i] < B[B_step])
			{
				result += B_cou[B_step];
				break;
			}
			B_step++;
		}
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 2176
N = int(input())
A = sorted(list(map(int, input().split())))

m = max(A)+1
dp = [1]*m
for a in A:
  if dp[a-1] == 1:
    dp[a-1] = 2
    for i in range(a*2, m, a):
      dp[i-1] = 0
  elif dp[a-1] == 2:
    dp[a-1] = 0
print(sum([1 for a in A if dp[a-1]]))

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

using namespace std;

int main(){


	long long int a,b,c,aux;

	cin >> a >> b >> c;


	aux = c;
	aux = min(a,c);
	a -= aux;
	c -= aux;
	b -= min(b,c);		

	cout << a << " " << b << endl;



	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d=sc.nextInt();
		if(a*b>=c*d) {
			System.out.println(a*b);
		}else {
			System.out.println(c*d);
		}
	}

}


Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

int n, k;
ll arr[200010];

vector<ll> xp;

int t[200010];
int s(int x){
	int ret=0;
	while(x) ret+=t[x], x&=(x-1);
	return ret;
}

void u(int x){
	while(x<=200000) ++t[x], x+=(x&(-x));
}

int main()
{
	read(n, k);
	for(int i=1; i<=n; ++i) read(arr[i]), arr[i]+=arr[i-1], xp.pb(arr[i]-k*1LL*i);
	xp.pb(0);
	sort(all(xp)); xp.erase(unique(all(xp)), xp.end());
	ll ans=0;
	auto f=[&](ll x){
		return lower_bound(all(xp), x) - xp.begin() + 1;
	};
	u(f(0));
	for(int i=1; i<=n; ++i){
		int p=f(arr[i]-k*1LL*i);
		ans+=s(p); u(p);
	}
	printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 4336
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);

#define debug(x) (#x " : " + to_string(x))
#define debug_cout(x) (cout << #x << " : " <<  to_string(x) << endl)
#define rep(i, n) for(ll i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(ll i=1, i##_len=(n); i<i##_len; i++)
#define rrep(i, n) for(ll i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(ll i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair((a), (b));
using namespace std;
using ll = long long;
//#define int long long
template<class T> bool chmax(T& a, T& b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T& b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = 2e9;

/*****/

int main()
{
	int N;
	cin >> N;
	vector<ll> a(N);
	rep(i, N)	cin >> a[i];

	bool isYes = true;
	int A = 0;
	for (ll i = 0; i < N; i++)
	{
		A ^= a[i];
	}

	if (A == 0)
	{
		isYes = true;
	}
	else
	{
		isYes = false;
	}

	cout << (isYes ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



int main() {
	int n, m,t=0;
	cin >> n >> m;
	vector<int>vec(m);
	vector<int>vec2(m - 1);
	vecin(vec);
	sort(all(vec));
	rep(i, m - 1) {
		vec2[i] = vec[i + 1] - vec[i];
	}
	sort(all(vec2));
	rep(i, m - n) {
		t += vec2[i];
	}
	cout << t << endl;
}


Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	int N, M, X;
	int left = 0, right = 0;

	cin >> N >> M >> X;
	REP(i, M) {
		int A;
		cin >> A;
		if (A < X) left++;
		else right++;
	}
	int ans = min(left, right);
	cout << ans;
	system("pause");
	return 0;
}

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

typedef long long ll;

bool cmp (std::string a, std::string b){
	for(int i = 0; i < std::min(a.size(), b.size()); i++){
		if(a[i] < b[i]){
			return true;
		} else if(a[i] > b[i]){
			return false;
		}
	}

	if(a.size() <= b.size()){
		return true;
	} else {
		return false;
	}
}
int main(){
	std::ios::sync_with_stdio(false);

	std::string s;
	int k;

	std::cin >> s >> k;

	std::vector<std::string> v;
	for(int i = 1; i <= 10; i++){
		for(int j = 0; j + i <= s.size(); j++){
			v.push_back(s.substr(j, i));
		}
	}

	std::sort(v.begin(), v.end());
	v.erase(std::unique(v.begin(), v.end()), v.end());
	std::sort(v.begin(), v.end());

	std::cout << v[k - 1];
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
 
signed main()
{
	
	int n; cin>>n;
	int a[n];
	for(int i=0; i<n; i++) cin>>a[i];
	
	int ans = 0;;
	for(int bit=0; bit<60; bit++)
	{
		int set = 0, unset =0;
		for(int i=0; i<n; i++)
		{
			if(a[i]&1) set++;
			else unset++;
			a[i] >>= 1; 
		}
		ans += ((set * unset % mod) * ((1ll<<bit) % mod) )% mod;
		ans %= mod;
	}
	cout<<ans<<"\n";
	
	
}

Measured memory_bytes: 2560
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

// UnionFind高速
type UnionFind struct {
	d []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.d = make([]int, N)
	for i := 0; i < N; i++ {
		u.d[i] = -1
	}
	return u
}

func (p *UnionFind) root(x int) int {
	if p.d[x] < 0 {
		return x
	}
	p.d[x] = p.root(p.d[x])
	return p.d[x]
}

func (p *UnionFind) unite(x, y int) bool {
	x = p.root(x)
	y = p.root(y)
	if x == y {
		return false
	}
	if p.d[x] > p.d[y] {
		x, y = y, x
	}
	p.d[x] += p.d[y]
	p.d[y] = x
	return true
}

func (p *UnionFind) same(x, y int) bool {
	return p.root(x) == p.root(y)
}

func (p *UnionFind) size(x int) int {
	return -p.d[p.root(x)]
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M := getInt(), getInt()
	u := newUnionFind(N)
	for i := 0; i < M; i++ {
		x, y, _ := getInt()-1, getInt()-1, getInt()
		u.unite(x, y)
	}
	ans := 0
	for i := 0; i < N; i++ {
		if u.root(i) == i {
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 2944
class UnionFind
	def initialize(n)
		@obj_to_node = [nil] * (n+1)
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end
end

n, m = gets.split.map &:to_i

edges = []
cost = (0..n).map{ (0..n).map{ Float::INFINITY} }

(1..m).each do
	i, j, c = gets.split.map &:to_i
	e = [i, j]
	edges << e
	cost[i][j] = cost[j][i] = c
end
edges.sort_by!{|i, j| cost[i][j]}

mst = []
uf = UnionFind.new(n)

history = {}

edges.each do |e|
	i, j = e
	next if uf.same?(i, j)
	history[e] = [Marshal.load(Marshal.dump(uf)), mst.map{|i,j| cost[i][j]}.inject(0, :+)]
	mst << e
	uf.union(i, j)
end

C = mst.map{|i,j| cost[i][j]}.inject(:+)

k = 0
s = 0
mst.each.with_index do |deleted, t0|
	e = nil
	e = edges.shift until e == deleted
	uf, c = history[e]
	t = t0

	edges.each do |e|
		next if e == deleted
		i, j = e
		next if uf.same?(i, j)
		uf.union(i, j)
		c += cost[i][j]
		t += 1
	end

	if c > C || t < n - 1
		k += 1
		s += cost[deleted[0]][deleted[1]]
	end
end

puts [k, s] * ' '

Measured memory_bytes: 40252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct edge {
  int from, to, cost;
  edge() {}
  edge(int from, int to, int cost): from(from), to(to), cost(cost) {}
};

const ll INF = 1LL << 40;
int N, M;
edge es[2010];
ll dis[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--; b--;
    es[i] = edge(a, b, -c);
  }  
  fill_n((ll*)dis, 1010, INF);
  dis[0] = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      edge e = es[j];
      if (dis[e.from] == INF) continue;
      if (dis[e.to] > dis[e.from] + e.cost) {
        dis[e.to] = dis[e.from] + e.cost;
        if (i == N - 1 && e.to == N - 1) {
          cout << "inf" << endl;
          return 0;
        }        
      }
    }
  }
  cout << -dis[N - 1] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元　nCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io

    int n,k;
    cin>>n>>k;
    vector<int> A(n);
    rep(i,n) cin>>A[i];
    int cnt=0;

    if(n==k){
        cout<<1<<endl;
        return 0;
    }
    cnt=(n-2)/(k-1)+1;
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  int T[N], C[N+1][M];
  for(int i = 0; i <= N; ++i) fill(C[i],C[i]+M,0);
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j) C[i+1][j] = C[i][j];
    cin >> T[i];
    --T[i];
    ++C[i+1][T[i]];
  }
  /*
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < M; ++j) cout << C[i][j];
    cout << endl;
  }
  */
  int dp[1<<M], INF = 1000000000;
  fill(dp,dp+(1<<M),INF);
  dp[0] = 0;
  for(int i = 0; i < (1<<M); ++i){
    int t = 0;
    for(int j = 0; j < M; ++j){
      if((i>>j) & 1) t += C[N][j];
    }
    for(int j = 0; j < M; ++j){
      if(!((i>>j) & 1)){
        int c = C[N][j], s = dp[i] + c;
        s -= C[t+c][j];
        //if(t > 0) s += C[t-1][j];
        s += C[t][j];
        //cout << i << " " << j << " " << t << " " << c << endl;
        dp[(i | (1<<j))] = min(dp[(i | (1<<j))], s);
      }
    }
  }
  //for(int i = 0; i < (1<<M); ++i) cout << dp[i] << " ";
  //cout << endl;
  cout << dp[(1<<M)-1] << endl;
  return 0;
}

Measured memory_bytes: 15388
#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int gridDistance, p1loc, p2loc;
    cin >> gridDistance >> p1loc >> p2loc;
    
    if(abs(p1loc-p2loc)%2==0){
        cout << "Alice";
    }else{
        cout << "Borys";
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstdint>

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<intmax_t> X[3];
  for (std::vector<intmax_t> &A: X) {
    A.resize(N);
    for (size_t i=0; i<N; ++i) {
      scanf("%jd", &A[i]);
    }

    std::sort(A.begin(), A.end());
  }

  std::vector<intmax_t> Y[2];
  for (size_t i=0; i<2; ++i) {
    Y[i].assign(N, N);
    for (size_t j=0, k=0; j<N; ++j) {
      while (k < N && X[i][j] >= X[i+1][k]) ++k;
      if (k == N) break;
      Y[i][j] = k;
    }
  }

  for (size_t i=0; i<N; ++i)
    Y[1][i] = N - Y[1][i];

  for (size_t i=N-1; i>0; --i)
    Y[1][i-1] += Y[1][i];

  intmax_t res=0;
  for (size_t i=0; i<N; ++i) {
    size_t j=Y[0][i];
    if (j < N)
      res += Y[1][j];
  }

  printf("%jd\n", res);
  return 0;
}


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

int main() {
    int n, v[60];
    cin >> n;
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v, v+n);
    double ans=(v[0]+v[1])/2.0;
    for (int i = 2; i < n; i++) ans=(ans+v[i])/2.0;
    cout << std::setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
const int mod=998244353;
//const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}

int powm(int a, int b) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}

bool vis[100005];
vi gra[100005];
vi path;
void dfs(int at) {
	vis[at]=1;
	path.pb(at);
	while(gra[at].size()&&vis[gra[at].back()]) {
		gra[at].pop_back();
	}
	if(gra[at].size()) {
		dfs(gra[at].back());
	}
}
void solve() {
	int n,m;
	cin>>n>>m;
	fr(i,1,m) {
		int u,v;
		cin>>u>>v;
		gra[u].pb(v);
		gra[v].pb(u);
	}
	dfs(1);
	vi sta;
	sta.swap(path);
	dfs(1);
	reverse(all(path));
	path.pop_back();
	cout<<path.size()+sta.size()<<endl;
	for(int i:path)
		cout<<i<<" ";
	for(int i:sta)
		cout<<i<<" ";
	cout<<endl;

}

signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	while(t--)
		solve();
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 9844
import sys
sys.setrecursionlimit(1000000)

class Tree:
  C, RL = {}, {}
  R, N, D, S, P = None, None, None, None, None
  def __init__(s, num):
    s.N = num
  def setC(s, a, b):
    if a in s.C: s.C[a].append(b)
    else: s.C[a] = [b]
    if b in s.C: s.C[b].append(a)
    else: s.C[b] = [a]
  def makeRank(s, root):
    s.R = [0] * s.N
    s.R[root] = 1
    s.RL[1] = [root]
    s.S = {}
    s.P = {}
    F = [root]
    s.D = 2
    while F != []:
      Ft = []
      s.RL[s.D] = []
      for i in F:
        for j in s.C[i]:
          if s.R[j] == 0:
            s.R[j] = s.D
            Ft.append(j)
            s.RL[s.D].append(j)
            if i not in s.S:
              s.S[i] = [j]
            else:
              s.S[i].append(j)
            s.P[j] = i

      s.D += 1
      F = Ft
  def getDeep(s, x):
    ans = 0
    if x in s.S:
      for i in s.S[x]:
        ans = max(ans, s.getDeep(i))
      return ans + 1
    else:
      return 0
  def getParent(s, x, n):
    if n == 0:
      return x
    return s.getParent(s.P[x], n - 1)
    

N, u, v = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N - 1)]

T = Tree(N)
for a, b in AB:
  T.setC(a - 1, b - 1)

T.makeRank(v - 1)
t = (T.R[u - 1] // 2) - 1
f = T.R[u - 1] % 2
k = T.getDeep(T.getParent(u - 1, t))
print(t + k + f)



Measured memory_bytes: 153256
#include <bits/stdc++.h>
#define INF 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    s[k-1] -= 'A'-'a';
    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n=3;
  int x=1;
  while(n+x>0){
    cin >>n>>x;
    if(n+x==0)break;
    int count=0;
    int hajime=2;
    for(int i=1;i<101;i++){
      hajime=max(hajime,i+1);
      for(int j=hajime;j<101;j++){
        if(x-i-j<1){
          hajime=i+1;
          break;
        }
        if(x-i-j<n+1&&2*j<x-i){
          count++;
          //cout<<i<<" "<<j<<" "<<x-i-j<<endl;
          //break;
        }
      }
    }
  cout<<count<<endl;
  }
  return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define MAX 200001
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	long long n, ans = 0;
	cin >> n;
	vector<long long>a(n), s(n + 1, 0);
	rep(i, 0, n) {
		cin >> a[i];
		s[i + 1] = s[i] + a[i];
	}
	rep(i, 0, n) {
		long long int x;
		x = s[n] - s[i + 1];
		x %= 1000000007;
		ans += a[i] * x;
		ans %= 1000000007; 
	}
	cout << ans << endl;
}


Measured memory_bytes: 6416
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N = 500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    cin >> n >> m;
    inputv(A, n);
    inputv(B, m);

    ll dp[1001][1001];//dp[i][j]:i日め終了時点でjにいるときの最小疲労度

    rep(i, m+1) {
        rep(j, n+1) {
            dp[i][j] = INF;
            if (i == 0 && j == 0)dp[i][j] = 0;
            if (i > 0)dp[i][j]=dp[i-1][j];
            if (i > 0 && j > 0)dp[i][j] = min(dp[i][j],dp[i-1][j-1] + B[i-1] * A[j- 1]);
        }
    }

    cout << dp[m][n] << endl;
}


Measured memory_bytes: 10940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {

		BufferedReader br =
		        new BufferedReader(new InputStreamReader(System.in));

		  int x  = Integer.parseInt(br.readLine());

		  int h = x/3600;
		  int m = (x%3600)/60;
		  int s = (x%3600)%60;

		  System.out.println(h + ":" + m + ":" + s);

	}

}

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

#ifdef _DEBUG
#define debug(x) cout << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009LL;
static constexpr ll LL7_MOD = 1000000007LL;
static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

ll dp[3010][3010];

int main(int argc, char* argv[]) {
  INFILE;

  ll n;
  cin >> n;

  vector<ll> seq(n);
  scan(seq);
  int sign = n % 2 ? 1 : -1;

  REP(i, 0, n) { dp[i][i] = seq[i] * sign; }

  REP(k, 2, n + 1) {
    sign *= -1;
    REP(i, 0, n + 1 - k) {
      int start = i, end = i + k - 1;
      auto change = sign > 0 ? chmax<ll> : chmin<ll>;

      ll result = sign * seq[start] + dp[start + 1][end];
      change(result, sign * seq[end] + dp[start][end - 1]);
      dp[start][end] = result;
    }
  }

  cout << dp[0][n - 1] << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <map>

#define REP(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

typedef long long ll;

int main()
{

    int n, k;
    cin >> n;
    cin >> k;

    vector<int> a(n);
    REP(i, n)
    cin >> a[i];
    REP(i, n)
    a[i]--;
    vector<int> s(n + 1);
    REP(i, n)
    {
        s[i + 1] = (s[i] + a[i]) % k;
    }

    map<int, int> mp;
    ll ans = 0;
    queue<int> q;
    REP(j, n + 1)
    {
        ans += mp[s[j]];
        mp[s[j]]++;
        q.push(s[j]);
        if (q.size() == k)
        {
            mp[q.front()]--;
            q.pop();
        }
    }

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

Measured memory_bytes: 12032
#include<stdio.h>
int main(){
	double v;
	while(~scanf("%lf",&v)){
		double t,x;
		t=v/9.8;
		x=4.9*t*t;
		for(int n=408;n>=0;n--){
			if(x>(n*5)){
				printf("%d\n",(n+2));
				break;}}}
	return 0;}


Measured memory_bytes: 2612
using System;
namespace ITP1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Split();
            var a = int.Parse(S[0]);
            var b = int.Parse(S[1]);
            var c = int.Parse(S[2]);
            if(a < b && b < c)
            {
                Console.WriteLine("{0} {1} {2}", a, b, c);
            }
            else if(a < c && c < b)
            {
                Console.WriteLine("{0} {1} {2}", a, c, b);
            }
            else if(b < a && a < c)
            {
                Console.WriteLine("{0} {1} {2}", b, a, c);
            }
            else if(b < c && c < a)
            {
                Console.WriteLine("{0} {1} {2}", b, c, a);
            }
            else if(c < a && a < b)
            {
                Console.WriteLine("{0} {1} {2}", c, a, b);
            }
            else if(c < b && b < a)
            {
                Console.WriteLine("{0} {1} {2}", c, b, a);
            }
            else if (c < b && b == a) {
                Console.WriteLine("{0} {1} {2}", c, b, a);
                
            }
            else if (c > b && b == a) 
            {
                Console.WriteLine("{0} {1} {2}", a, b, c);
            }
            else if (c < b && c == a) 
            { 
                Console.WriteLine("{0} {1} {2}", c, a, b); 
            }
            else if (c > b && c == a) 
            { 
                Console.WriteLine("{0} {1} {2}", b, c, a);
            }
            else if (c < a && b == c) 
            { 
                Console.WriteLine("{0} {1} {2}", c, b, a);
            }
            else
            {
                Console.WriteLine("{0} {1} {2}", a, b, c);
            }
        }
    }
}


Measured memory_bytes: 18016
using System;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
          string input1 = Console.ReadLine();
          int var1= int.Parse(input1);
          string input2 = Console.ReadLine();
          string[] var2 = input2.Split(' ');

          int[] var3=new int[var1];
          string output;

            for (int i = 0; i < var2.Length; i++)
          {
             var3[i] =int.Parse(var2[i]);
          }
            Console.WriteLine(input2);
            string[] output1 = new string[var2.Length];

            for (int i = 1; i < var2.Length; i++)
            {
                int key = var3[i];
                int j = i - 1;
                while (j>=0&&var3[j]>key)
                {
                    var3[j + 1] = var3[j];
                    j--;
                    var3[j + 1] = key;
                }
                for (int k = 0; k < var2.Length; k++)
                {
                    output1[k] = var3[k].ToString();
                }
                output = string.Join(" ", output1);
                Console.WriteLine(output);
            }
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int A = a[n-1];

    vector<int> ch(A+1);
    for(int i=0; i<n; i++){
        ch[a[i]]++;
    }
    for(int i=2; i<=A; i++){
        int now = 0;
        for(int j=i; j<=A; j+=i){
            if(ch[j]){
                now += ch[j];
            }
        }
        if(now >= 2){
            int gcd = 0;
            for(int k=0; k<n; k++) gcd = __gcd(gcd,a[k]);
            if(gcd!=1) cout << "not coprime" << endl;
            else cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "pairwise coprime" << endl;
    return 0;
}


Measured memory_bytes: 11032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int N,d;
  string S,ans;
  cin >>N;
  d =0;
  ans = "Three";
  rep(i,N){
    cin >>S;
    if(S=="Y"){
    ans = "Four";
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
cnts = {chr(a):0 for a in range(ord('a'),ord('z')+1)}
for line in sys.stdin:
    alpha_line = [x.lower() for x in list(filter(lambda c: c.isalpha(), list(line)))]
    for a in alpha_line: cnts[a] += 1

for a in range(ord('a'),ord('z')+1): print(chr(a),':',cnts[chr(a)])

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

int main()
{
	int n, t;
	cin >> n >> t;
	int ans = 0, stop = 0;
	for(auto i = 0; i < n; ++i){
		int s;
		cin >> s;
		ans += min(t, max(s + t - stop, 0));
		stop = s + t;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <vector>
#include <iostream>
using namespace std;
#define MOD 1000000007;
const int maxn = 100 + 5;
const char ch[] = {'A', 'C', 'G', 'T'};

int dp[maxn][4][4][4];

bool isValid(int x, int y, int z) {
    string str = "";
    str.push_back(ch[x]);
    str.push_back(ch[y]);
    str.push_back(ch[z]);
        if(str == "AGC")
            return false;
    return true;
}

int solve(int n) {
    memset(dp, 0, sizeof(dp));
    for(int i = 0; i < 4; i++)
        for(int j = 0; j < 4; j++) {
            for(int k = 0; k < 4; k++) {
                if(isValid(i, j, k) && isValid(j, i, k) && isValid(i, k, j)) {
                    dp[3][i][j][k] = 1;
                }
            }
        }

    for(int l = 4; l <= n; l++) {
        for(int i = 0; i < 4; i++) {
            for(int j = 0; j < 4; j++) {
                for(int k = 0; k < 4; k++) {
                    for(int u = 0; u < 4; u++) {
                        if(isValid(i, j, k) && isValid(u, i, k) && isValid(u, j, k) &&  isValid(j, i, k) && isValid(i, k, j)) {
                            dp[l][i][j][k] += dp[l-1][u][i][j] % MOD;
                            dp[l][i][j][k] %= MOD;
                        }
                    }
                }
            }
        }
    }

    int res = 0;
    for(int i = 0; i < 4; i++) {
        for(int j = 0; j < 4; j++) {
            for(int k = 0; k < 4; k++) {
                res += dp[n][i][j][k];
                res %= MOD;
            }
        }
    }
    return res;
}


int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
#endif // LOCAL
    int n;
    while(scanf("%d", &n) == 1) {
        printf("%d\n", solve(n));
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 305
using namespace std;

int n, c;
bool v;
string a[N];
int main()
{
	int i, j, k;
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i], a[i] += a[i];
	for (i = 0; i < n; i++) {
		for (j = v = 0; j < n; j++) {
			for (k = 0; k < n; k++) if (a[j][k + i] != a[k][j + i]) {v = 1; break;}
			if (v) break;
		}
		if (!v) c++;
	}
    cout << c * n << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;
int A[200000];
int main(){
  int N;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A[i];
  }

  map <int, long long> counts;
  for(int i = 0; i < N; i++){
    if(counts.find(A[i]) == counts.end()){
      counts[A[i]] = 1;
    } else {
      counts[A[i]] ++;
    }
  }

  long long whole_ans = 0;
  for(auto it = counts.begin(); it != counts.end(); it++){
    whole_ans += (it->second) * (it->second - 1) / (long long)2;
  }

  for(int i = 0; i < N; i++){
    cout << whole_ans - counts[A[i]] * (counts[A[i]] - 1) / 2 + (counts[A[i]] - 1) * (counts[A[i]] - 2) / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 11008
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

int main() {
	fast_cin();
	ll k, a, b;
	cin >> k >> a >> b;
	if (b - a <= 2) {
		cout << k + 1 << endl;
	} else {
		ll ans = 1;
		ll temp = min(k, a - 1);
		ans += temp;
		k -= temp;
		if (k & 1) {
			++ans;
			--k;
		}
		ans += (k / 2) * (b - a);
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
a = input()  # ssdrtf
b = set(a)  # 重複をなくす

c = 0
for i in b:
    if a.count(i) % 2 == 1:  # もし奇数ならだめ
        c = 1
        break
        
if c == 0:
    print("Yes")
else:
    print("No")


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

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


	for (int i = 0; i < 10; i++) {
		if (111 * i < n && n <= 111 * (i + 1)) {
			cout << 111 * (i + 1) << endl;
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 256
use io::*;
use std::cmp;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let a: i64 = sc.next();
    let b: i64 = sc.next();
    let v: Vec<i64> = sc.next_vec(n);
    let c = a - b;
    let mut l = 0;
    let mut r = 10i64.pow(10);
    while l + 1 < r {
        let m = (l + r) / 2;
        let t: i64 = v.iter().map(|x| (cmp::max(0,x - m * b) + c - 1) / c).sum();
        if t > m {
            l = m;
        } else {
            r = m;
        }
    }
    println!("{}",r);
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 6396
// <------------- Template -----------------------> //


#include<bits/stdc++.h>
using namespace std;

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(0);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	2 * 1e18;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[200];ll visit[300]={};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,q;
string s,t;
ll sum = 0;
// <------------- Implement Functions Here ----------> //

vpll val;

bool comp(pll &a, pll &b) {
	if(a.s == b.s) return a.f > b.f;
	return a.s < b.s;
}

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	for(ll i=0;i<n;i++) {
		cin>>x>>y;
		val.pb({x,y});
	}
	sort(all(val),comp);
	ll cur = 0;
	for(ll i=0;i<n;i++) {
		if(cur + val[i].f > val[i].s) {
			cout<<"No\n";
			return;
		}
		cur+=val[i].f;
	}
	cout<<"Yes\n";
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


Measured memory_bytes: 7468