akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>){
    val inputs = readLine()!!.split(" ").map { it.toLong() }
    val a = inputs[0]
    val b = inputs[1]
    val k = inputs[2]
    println(Math.max(a - k, 0).toString() + " " + Math.max(Math.min(b - (k - a), b), 0).toString())
}


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

using namespace std;

int main(){
    int n, k;
    cin>>n>>k;
    int arr[n];
    for(int i= 0;i< n;i++){
        cin>>arr[i];
    }
    int dp[n];
    memset(dp,0, sizeof(dp));
    dp[0] = 0;
    // dp[1] = abs(arr[1] - arr[0] );
    for(int i=0;i< n;i++){
        if(i < k){
            dp[i] = abs(arr[i] - arr[0]);
            for(int j=0;j< i;j++){
                dp[i] = min(dp[j] + abs(arr[j]-arr[i]), dp[i]);
            }
            continue;
        }
        dp[i] = abs(arr[i] - arr[i-k]) +dp[i-k]; 
        for(int j = 1;j< k;j++){
            dp[i] = min(abs(arr[i] - arr[i-j]) + dp[i-j],dp[i]);
        }
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
s=int(input())
a=list(map(int,input().split()))
b=int(input())
s=[]
for i in range(b):
    c,d=map(int,input().split())
    s.append(sum(a[:c-1])+sum(a[c:])+d)   
for i in range(b):
    print(s[i])

Measured memory_bytes: 3060
dict = {}
q = int(input())

for i in range(q):
    a = list(input().split())
    ki = a[1]
    if a[0] == '0':
        dict[ki] = int(a[2])
    elif a[0] == '1':
        print(dict[ki] if ki in dict else 0)
    else:
        if ki in dict:
            dict[ki] = 0


Measured memory_bytes: 37504
l=input()
list=list(l)
list_2=[]
length=len(list)
for k in range(length):
  if list[k]=="0":
    list_2.append("0")
  elif list[k]=="1":
    list_2.append("1")
  else:
    if len(list_2)==0:
      continue
    else:
      del list_2[-1]
mojiretsu="".join(list_2)
print(mojiretsu)


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

ll n,m,x[100005],y[100005],r1,r2,rez;

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

    cin>>n>>m;
    for(ll i=1;i<=n;i++)
        cin>>x[i];
    for(ll i=1;i<=m;i++)
        cin>>y[i];
    sort(x+1,x+1+n);
    sort(y+1,y+1+m);

    for(ll i=1;i<=n;i++)
    {
        r1+=x[i]*(i-1-(n-i));
        r1%=1000000007;
    }
    for(ll i=1;i<=m;i++)
    {
        r2+=y[i]*(i-1-(m-i));
        r2%=1000000007;
    }
    rez=r1*r2;
    rez%=1000000007;

    cout<<rez<<endl;

    return 0;
}


Measured memory_bytes: 5092
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
l = []
c = []
ls = []
for i in range(N):
    l.append(i + 1)
    c.append(0)

# 重複なしのあらゆる並び
l = list(map(list, itertools.permutations(l)))
print(abs(l.index(P) - l.index(Q)))


Measured memory_bytes: 10356
using System;
using System.Linq;

namespace Poisonous_Cookies
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            var canEat = 0;

            // Cを何枚食べられるか
            var b = input.ElementAt(1);
            var gedoku = input.ElementAt(0) + b;
            var doku = input.ElementAt(2);
            if (gedoku >= doku)
            {
                canEat += doku;
            }
            else
            {
                canEat += gedoku + 1;
            }

            canEat += b;
            Console.WriteLine(canEat);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define xmod int(1e9+7)
#define hmod 1223334444555553LL
using namespace std;

int n;
char s[1005];
int main(){
	scanf("%d\n%s",&n,s);
	if (n < 3200)
	printf("red\n");
	else
	printf("%s\n",s);
	return 0;
} 

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T & arr, const U & v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR & arr, const U & v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int32_t N;
int32_t pos[100][2];

bool used[100];
void dfs(int i, int dx, int dy) {
	if (used[i]) { return; }
	used[i] = true;
	for (int32_t j = 0; j < N; j++)
	{
		int xxx = (pos[i][0] - pos[j][0]);
		int yyy = (pos[i][1] - pos[j][1]);
		if ((xxx == dx && yyy == dy) || (xxx == -dx && yyy == -dy)) {
			dfs(j, dx, dy);
		}
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> pos[i][0] >> pos[i][1];
	}

	int32_t min = N;
	for (size_t i = 0; i < N; i++)
	{
		for (size_t j = 0; j < N; j++)
		{
			if (i == j) { continue; }
			fill_all(used, false);

			int count = 0;
			for (size_t k = 0; k < N; k++)
			{
				if (!used[k]) {
					++count;
					dfs(k, (pos[i][0] - pos[j][0]), (pos[i][1] - pos[j][1]));
				}
			}
			min = std::min(min, count);
		}
	}
	std::cout << min << endl;

	return 0;
}
#endif


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF (1<<29)
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int p){
	for(int i=2;i<=sqrt(p);i++){
		if(!p%i)return false;
	}
	return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a%MOD;
    if(b%2)return modpow(a,b-1)*a%MOD;
    else return modpow(a,b/2)*modpow(a,b/2)%MOD;
}
int comb(int a,int b){
    if(b==0||a==b)return 1;
    if(b==1)return a%MOD;
    return (comb(a-1,b-1)+comb(a-1,b))%MOD;
}
string s;
int c[26],ma=0,sp,ans=1000;
vector<char>v;
signed main(){
    cin>>s;
    int n=s.size();
    rep(i,n)c[s[i]-'a']++;
    rep(i,26){
        sp=-1;
        ma=0;
        rep(j,n){
            if(s[j]==(char)(i+'a')){
                ma=max(j-sp-1,ma);
                sp=j;
            }
        }
        ma=max(n-1-sp,ma);
        ans=min(ma,ans);
    }
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var S string
	fmt.Scan(&S)
	c1 := S[0]
	var c2 uint8
	var i1, i2 int
	sset := false
	for i := range S {
		if S[i] == c1 {
			i1++
		} else {
			if !sset {
				sset = true
				c2 = S[i]
				i2++
			} else if S[i] == c2 {
				i2++
			}
		}
	}
	if i1 == 2 && i2 == 2{
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

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

int main(){
    int a;
    cin >> a;
    if(a%1000==0){
        cout << 0 << endl;
    }else{
        cout << (a / 1000 + 1) * 1000 - a << endl;
    }
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void){
	int array[100];
	int n;
	int i,j,flag,tmp,ex=0;
	scanf("%d",&n);
	for(i=0;i<n;++i){
		scanf("%d",&array[i]);
	}
	flag = 1;
	i=0;
	while(flag){
		flag = 0;
		for(j=n-1;j>=i+1;--j){
			if(array[j]<array[j-1]){
				tmp = array[j];
				array[j] = array[j-1];
				array[j-1] = tmp;
				flag=1;
				ex++;
			}
		}
		i++;
	}
	for(i=0;i<n;++i){
		if(i)printf(" ");
		printf("%d",array[i]);
	}
	printf("\n%d\n",ex);
	return 0;
}

Measured memory_bytes: 604
#include <iostream>

using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if(b == c){
        cout << a << endl;
    }else if(a == c){
        cout << b << endl;
    }else {
        cout << c << endl;
    }

    return 0;
}



Measured memory_bytes: 256
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, K = gets_i_list
total = 0.0

(1..N).each do |n|
  if n <= K-1
    count = (Math::log(K.to_f/n,2)).ceil
    total += (1.0/N) * ((0.5) ** count)
  else
    total += 1.0/N
  end
end
puts total


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

int main() {
  int A, B;
  cin >> A >> B;
  vector<int> vec = {A, B};
  
  sort(vec.begin(), vec.end());
  int answer = 0;
  answer += vec.at(1);
  vec.at(1)--;
  sort(vec.begin(), vec.end());
  answer += vec.at(1);
  cout << answer << endl;
  }
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;

int main() {
    ll N; cin >> N;
    string u, l; cin >> u >> l;

    int k = 0;
    ll ans = 1;
    for (int i = 0; i < N; i++)
    {
        if(u[i]==l[i]){
            if(k==0) ans *= 3;
            else if(k==1) ans *= 1;
            else ans *= 2;
            ans %= mod;
            k = 2;  
        } else {
            i++;
            if(k==0) ans *= 6;
            else if(k==1) ans *= 3;
            else ans *= 2;
            ans %= mod;
            k = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
    int A,B,C,K,Max, Bandeira = 0;
    int i;

    scanf("%d %d %d", &A, &B, &C);
    scanf("%d", &K);

    Max = A;
    Bandeira = 1;
    if(Max < B){
        Max = B;
        Bandeira = 2;
    }
    if(Max < C){
        Max = C;
        Bandeira = 3;
    }
    for(i = 0; i < K;i++){
        Max = Max * 2;
    }
    if(Bandeira == 1){
        Max = Max + B + C;
    }else if(Bandeira == 2){
        Max = A + Max + C;
    }else if(Bandeira == 3){
        Max = A + B + Max;
    }
    printf("%d", Max);

    return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
bool visited[1000001]={false};
int dist[1000001];
void dfs(int src,unordered_map<int,list<int> >&graph,int inDegree[])
{
    visited[src]=true;
    for(auto j:graph[src])
    {
        dist[j]=max(dist[j],dist[src]+1);
        inDegree[j]--;
        if(inDegree[j]==0) dfs(j,graph,inDegree);
    }
}
int main()
{
    int v,e,t1,t2,ans=0; cin>>v>>e;
    unordered_map<int,list<int> >graph;
    int inDegree[v+1]={0};
    for(int i=0;i<e;i++)
    {
        cin>>t1>>t2;
        graph[t1].push_back(t2);
        inDegree[t2]++;
    }
    for(int i=1;i<=v;i++)
    {
        if(!visited[i] and inDegree[i]==0)
        dfs(i,graph,inDegree);
    }
    for(int i=1;i<=v;i++)
    {
        ans=max(ans,dist[i]);
    }
    cout<<ans;
}

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

int n, k, t, t2;

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++){
		if(i % k == k / 2)
			t++;
		if(i % k == 0)
			t2++;
	}
	long long ans = t;
	if(t >= 1)
		ans += (1LL * t * (t - 1) * 3);
	if(t >= 2)
		ans += (1LL * t * (t - 1) * (t - 2));
	if(k % 2 == 1)	
		ans = 0;
	ans += t2;
	if(t2 >= 1)
		ans += (1LL * t2 * (t2 - 1) * 3);
	if(t2 >= 2)
		ans += (1LL * t2 * (t2 - 1) * (t2 - 2));
	cout << ans;
	return 0;
}

Measured memory_bytes: 384
from itertools import *

h, w, k = map(int, input().split())
c = []
ans = 0

for i in range(h):
    c.append(input())

count = 0

for i in range(h+1):
    conbI = list(combinations(list(range(h)), i))

    for j in range(w+1):
        conbJ = list(combinations(list(range(w)), j))

        for tupleI in conbI:
            for tupleJ in conbJ:
                temp = 0
                for x in range(h):
                    for y in range(w):
                        if x in tupleI or y in tupleJ:
                            continue
                        else:
                            if c[x][y] == '#':
                                temp += 1

                if temp == k:
                    ans += 1


print(ans)

Measured memory_bytes: 73540
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort(reverse=True)
sm = sum(s)
ans = 0
while (sm - ans)%10==0 and s:
    now = s.pop()
    ans += now
    if(sm - now)%10!=0:
        ans = now
        break

print(sm - ans)



Measured memory_bytes: 8980
import bisect

N = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))

sorted_a = sorted(a)
sorted_c = sorted(c)
ans = 0
for each_b in b:
    ai = bisect.bisect_left(sorted_a, each_b)
    ci = bisect.bisect_right(sorted_c, each_b)
    ans += ai * (len(c)-ci)
print(ans)


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

using namespace std;
using ll = long long;

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

	vector<vector<ll>> cnt(62, vector<ll>(62, 0));
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (find(s.begin(), s.end(), '.') == s.end()) s.push_back('.');
		int pos = 0;
		while (s[pos] != '.') pos++;
		s += string(10 - s.size() + pos, '0');
		ll y = 0;
		for (auto c : s) {
			if (isdigit(c)) y = y * 10 + c - '0';
		}
//		cout << "y = " << y << '\n';
		int p2 = 0, p5 = 0;
		for (; y % 2 == 0; y /= 2, p2++);
		for (; y % 5 == 0; y /= 5, p5++);
		cnt[p2][p5]++;
//		cout << '(' << p2 << ' ' << p5 << ")\n";
	}
	ll ans = 0;
	for (int p2 = 0; p2 < 62; p2++) {
		for (int p5 = 0; p5 < 62; p5++) {
			for (int pp2 = 0; pp2 < 62; pp2++) {
				for (int pp5 = 0; pp5 < 62; pp5++)
					ans += cnt[p2][p5] * cnt[pp2][pp5] * (min(p2 + pp2, p5 + pp5) >= 18) *
						   (pair<int, int>{p2, p5} != pair<int, int>{pp2, pp5});
			}
		}
	}
	for (int p2 = 0; p2 < 62; p2++) {
		for (int p5 = 0; p5 < 62; p5++) ans += cnt[p2][p5] * (cnt[p2][p5] - 1) * (min(p2, p5) * 2 >= 18);
	}
	cout << ans / 2 << '\n';
}


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

int main() {
  string S, T, U; cin >> S >> T >> U;
  char s = S.at(0) + 'A' - 'a';
  char t = T.at(0) + 'A' - 'a';
  char u = U.at(0) + 'A' - 'a';
  string ans = "";
  ans = ans + s + t + u;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
char s[1010];
int realans=1e9,len,last[110],ans[110];
int cmin(int a,int b){return a<b?a:b;}
int cmax(int a,int b){return a>b?a:b;}
int main()
{
	scanf("%s",s+1),len=strlen(s+1);
	f(i,1,len)
	{
		ans[s[i]-'a']=cmax(ans[s[i]-'a'],i-last[s[i]-'a']-1);
		last[s[i]-'a']=i;
	}
	f(i,0,25)if(last[i])realans=cmin(ans[i]=cmax(ans[i],len-last[i]),realans);
	return printf("%d\n",realans),0;
}

Measured memory_bytes: 128
#include<iostream>
#include<set>
using namespace std;
int main(){
    int n;
    cin>>n;
    set<int>ST;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        ST.insert(x);
    }
    cout<<ST.size()<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int N, K;
    string S;
    cin >> N;
    cin >> S;
    cin >> K;
    char c = S[K-1];
    REP(i, S.length()) {
        if(S[i] != c) S[i] = '*';
    }
    cout << S << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[1024];
    int q;
    int i;

    scanf("%s", s);
    scanf("%d", &q);
    while (q--){
        char query[16];
        int a, b;

        scanf("%s %d %d", query, &a, &b);
        if (!strcmp(query, "print")){
            for (i = a; i <= b; ++i) putchar(s[i]);
            puts("");
        }
        else if (!strcmp(query, "reverse")){
            for (i = 0; i <= (b - a) / 2; ++i){
                char tmp = s[a + i];
                s[a + i] = s[b - i];
                s[b - i] = tmp;
            }
        }
        else {
            char p[1024];

            scanf("%s", p);
            strncpy(s + a, p, b - a + 1);
        }
    }

    return 0;
}


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

int main() {
    char s;
    char back = NULL;
    int c = 0;

    while(cin.get(s)) {
        if (s == '\n')
            break;

        if (s == back) {
            back = (s == '1') ? '0' : '1';
            c++;
        } else {
            back = s;
        }
    }
    cout << c << endl;
    return 0;

} 

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

int main() {
    string s;
    cin >> s;
    vector<int> v(3, 0);
    v[0] = count(s.begin(), s.end(), 'a');
    v[1] = count(s.begin(), s.end(), 'b');
    v[2] = count(s.begin(), s.end(), 'c');

    bool flag = false;
    if (abs(v[0] - v[1]) > 1 || abs(v[0] - v[2]) > 1 || abs(v[1] - v[2]) > 1) {
        flag = true;
    }
    int rest = (v[0] + v[1] + v[2]) % 3;
    if (rest > 2) {
        flag = true;
    }
    if (s.size() > 2 && (v[0] == 0 || v[1] == 0 || v[2] == 0)) {
        flag = true;
    }
    cout << (flag ? "NO" : "YES") << endl;
}

Measured memory_bytes: 512
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int A,B,C;
    R(A,B,C);
    if((A==B||B==C||C==A) &&
     !(A==B&&B==C))W("Yes");
    else W("No");
    return 0;
}


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

int main(){
    string s;
    cin >> s;
    int Q;
    cin >> Q;
    string t;
    rep(qi, Q){
        int ty;
        cin >> ty;
        if(ty == 1){
            swap(s, t);
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                t += c;
            }else{
                s += c;
            }
        }
    }
    reverse(t.begin(), t.end());
    t += s;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 1128
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------
vector<int> Z_algorithm(string S) {
    int c = 0, n = S.length();
    vector<int> Z(n, 0);
    for (int i = 1; i < n; i++) {
        int l = i - c;
        if (i + Z[l] < c + Z[c]) {
            Z[i] = Z[l];
        }
        else {
            int j = max(0, c + Z[c] - i);
            while (i + j < n && S[j] == S[i + j])j++;
            Z[i] = j;
            c = i;
        }
    }
 
    Z[0] = n;
    return Z;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int n;string s;
    cin>>n>>s;
    int ans=0;
    
    int abc=0;
    for (int beg = 0; beg < n- 1; beg++) {
        string tmp = s.substr(beg);
        auto ret = Z_algorithm(tmp);
        for (int j = 1; j < ret.size(); j++) {
            if (ret[j] <= j)ans = max(ans, ret[j]);
        }
    }
    cout << ans << endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main() {
 
	int N, A;
	cin >> N >> A;
 
	int x;
	x = N / 500;
 
	if ((N - 500 * x) <= A) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll n,m,i,j,k,l,t;
int main()
{
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
            m+=i;
    }
    printf("%lld\n",m);
    return 0;
}


Measured memory_bytes: 3824
//#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;

int main() {
	
	int ky[1000] = {};
	int ny[1000] = {};
	string s;
	while (getline(cin,s)) {
		if (s.empty())break;

		int it=1;
		for (int i = 0;i<s.size();i++) {
			if (s[i] == ',') {
				it = i;
				break;
			}
		}

		string a;
		a = s.substr(0, it);
		int c = stoi(a);
		ky[c - 1]++;

	}

	string sa;
	while (getline(cin,sa)) {
		int it;
		for (int i = 0;i<sa.size();i++) {
			if (sa[i] == ',') {
				it = i;
				break;
			}
		}

		string a;
		a = sa.substr(0, it);
		int c = stoi(a);

		ny[c - 1]++;
	}

	for (int i = 0;i<1000;i++) {
		if (ky[i] != 0 && ny[i] != 0)cout << i + 1 << ' ' << ky[i] + ny[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 2992
#include <iostream>

long long gcd(long long a, long long b){
    long long denom = std::min(a, b), num = std::max(a, b) % denom, buf;
    while(0 != denom){
        buf = denom;
        denom = num % denom;
        num = buf;
    }

    return buf;
}

long long lcm(long long a, long long b){
    return a * b / gcd(a, b);
}

int main(){
    long long a, b, c, d;
    std::cin >> a >> b >> c >> d;
    --a;

//    std::cout << "gcd: " << gcd(c, d) << std::endl;
//    std::cout << "lcm: " << lcm(c, d) << std::endl;
    std::cout << b - (b / c + b / d) + b / lcm(c, d) - (a - (a / c + a / d) + a / lcm(c, d)) << std::endl;

    return 0;
}

Measured memory_bytes: 256
S=input()
flg=True
if S[0]!="A":
  flg=False
if S[2:-1].count("C")!=1:
  flg=False
for i in range(1,len(S)):
  if S[i]=="C" and i!=len(S)-1:
    continue
  if S[i].isupper():
    flg=False
print("AC" if flg else "WA")  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+b,(a).begin()+c // コンテナ a の 要素 b から c へのイテレータ
#define MOD 1000000007
#define INF 1000000000
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

// まずは全探索，次にDP
// 偶奇，逆から，ソート，出現回数，出現位置，DP
// 余事象，包除
// データ構造
// 問題の特徴量
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 小数のときは，精度の設定する．
int main() {
cin.tie(0);
ios::sync_with_stdio(false);

int64_t N; cin >> N;
VI A(N+1), B(N);
rep(i, 0, N+1) cin >> A[i];
rep(i, 0, N) cin >> B[i];

// なるべくBを使い切っていく．貪欲．
int64_t num = 0;
rep(i, 0, N){
    if (A[i] <= B[i]) {
        num += A[i];
        B[i] -= A[i];
        A[i] = 0;
    }
    else {
        num += B[i];
        A[i] -= B[i];
        B[i] = 0;
    }
    if (A[i+1] <= B[i]){
            num += A[i+1];
            A[i+1] = 0;
        }
    else {
        num += B[i];
        A[i+1] -= B[i];
    }
}

cout << num << "\n";

}

// 境界，出力文字列 チェック



Measured memory_bytes: 1792
x,y,z=map(int,input().split())
if x<=y<=z:print(x,y,z)
elif y<=x<=z:print(y,x,z)
elif x<=z<=y:print(x,z,y)
elif z<=y<=x:print(z,y,x)
elif y<=z<=x:print(y,z,x)
elif z<=x<=y:print(z,x,y)



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

int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main() {
	int a, b;
	int num = 1;
	int cnt = 0;
	cin >> a >> b;
	while(num < b){
		cnt++;
		num = num + a - 1;
	}
	if(a == b) cnt = 1;
	if(b < 1) cnt = 0;
	cout << cnt << endl;
}

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

int main()
{
	int h, w;

	while (true)
	{
		cin >> h >> w;
		if ((h == 0) && (w == 0)) break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 3104
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });

            var cin = GetIntArray().OrderBy(o=>o).ToArray();
            var ans = cin[0] + cin[1];

            Console.WriteLine(ans);


            Console.Out.Flush();
            Console.ReadKey();
        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public char GetChar() { return Console.ReadLine().Trim()[0]; }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public Double[] GetDoubleArray() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V,W>(out T a, out U b, out V c, out W d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);
        }
        static void Multi<T, U, V, W,X>(out T a, out U b, out V c, out W d,out X e)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]);e = cv<X>(ar[4]);
        }
    }
}

Measured memory_bytes: 13396
//*
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <functional>
#define MOD 1000000007
#define MAX 0x3f3f3f3f
#define MAX2 0x3f3f3f3f3f3f3f3fll
#define ERR 1e-10
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#pragma warning(disable:4996)
using namespace std;

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

char a[200000];
int n;

int main()
{
	int i, j, k, l;
	scanf("%s", a);
	n=strlen(a);
	int ans=0;
	for(i=0;i<n-1;i++) if(a[i] != a[i+1]) ans++;
	cout<<ans<<endl;
	return 0;
}
//*/

Measured memory_bytes: 384
// Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string S;
		cin >> S;

		if(S=="0")
			break;

		if(S[1]>='0'&&S[1]<='7'){
			if(S[3]>='0'&&S[3]<='7'){
				if(S[5]>='0'&&S[5]<='7'){
					cout << "black" << '\n';
				}
				else{
					cout << "blue" << '\n';
				}
			}
			else{
				if(S[5]>='0'&&S[5]<='7'){
					cout << "lime" << '\n';
				}
				else{
					cout << "aqua" << '\n';
				}
			}
		}
		else{
			if(S[3]>='0'&&S[3]<='7'){
				if(S[5]>='0'&&S[5]<='7'){
					cout << "red" << '\n';
				}
				else{
					cout << "fuchsia" << '\n';
				}
			}
			else{
				if(S[5]>='0'&&S[5]<='7'){
					cout << "yellow" << '\n';
				}
				else{
					cout << "white" << '\n';
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  double a, b, x; cin >> a >> b >> x;

  auto f = [&](double mid){
    if(tan(mid) < b/a){
      double y = a * tan(mid);
      return a*a*(b-y) + a*a*y/2;
    }else {
      double y = b / tan(mid);
      return y*a*b/2;
    }
  };

  double left = 0,right = M_PI/2;
  while(right - left > 1e-9){
    double mid = (left + right) / 2;
    if(f(mid) <= x) right = mid;
    else left = mid;
  }
  printf("%.6f\n", right / M_PI * 180);

  return 0;
}


Measured memory_bytes: 384
def op(u,v):
    return (complex.conjugate(u)*v).imag

f = []
while True:
    try:
        st = input().strip().split(',')
        x,y = list(map(float,st ))
        f.append(x + y*1j)
    except EOFError:
        break

s = 0.0
fo = f[0]
for j in range(2,len(f)):
    i = j - 1
    s += op(f[i]-fo,f[j]-fo)/2.0
print("%.6f" % abs(s))

Measured memory_bytes: 7484
//template code, C343, 2019
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		int count = 0;
		for(LinkedList<Integer> i: adjList)
		{
			for(int j: i)
			{
				adjMatrix[count][j] = 1;
			}
			count++;
		}
		
		for(int i = 0; i < totalVertex; i++)
		{
			for(int j = 0; j < totalVertex - 1; j++)
			{
				if(adjMatrix[i][j] == null)
				{
					System.out.print("0 ");
				}else
				{
					System.out.print("1 ");
				}
			}
			if(adjMatrix[i][totalVertex - 1] == null)
			{
				System.out.println("0");
			}else
			{
				System.out.println("1");
			}
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main{
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}













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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li l[1010];

int main() {
	li n;
	cin >> n;
	cout << n*(n + 1) / 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
using index_t = std::size_t;

namespace lib
{
	using graph_t = std::vector<std::set<index_t>>;
	template<class T>using weighted_graph_t = std::vector<std::map<index_t, T>>;

	struct max_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::max(lhs, rhs);
		}
	};
	struct min_t
	{
		template<class T>constexpr T operator()(T const& lhs, T const& rhs)const
		{
			return std::min(lhs, rhs);
		}
	};

	constexpr max_t max;
	constexpr min_t min;

	template<class T>auto order_by(T func)
	{
		return [=](auto&& lhs, auto&& rhs)
		{
			return func(lhs) < func(rhs);
		};
	}

	template<class T>constexpr auto max_v = std::numeric_limits<T>::max();
	template<class T>constexpr auto min_v = std::numeric_limits<T>::min();

	template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;
}

void Main()
{
	int result = -1;
	for (int i : boost::irange(1, 6))
	{
		int v;
		std::cin >> v;
		if (v == 0)
		{
			result = i;
		}
	}
	std::cout << result << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

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

int main(){
  string S;
  cin>>S;
  if(S[0]==S[1] &&S[2]!=S[1] &&S[2]==S[3]){
    cout<<"Yes"<<endl;
  }
  else if(S[0]==S[3] &&S[2]!=S[3] &&S[2]==S[1]){
    cout<<"Yes"<<endl;
  }
  else if(S[0]==S[2] &&S[2]!=S[1] &&S[1]==S[3]){
    cout<<"Yes"<<endl;
    
  }
  else{
    cout<<"No"<<endl;
  }
}


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

int main(int argc, char const *argv[]) {
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> order;
    vector<vector<int>> data(n + 1);
    for (int i = 0; i < m; ++i) {
        int p, y;
        cin >> p >> y;
        data[p].push_back(y);
        order.push_back(make_pair(p, y));
    }
    for (int i = 0; i < n + 1; ++i) {
        sort(data[i].begin(), data[i].end());
    }
    for (auto py : order) {
        int p = get<0>(py);
        int y = get<1>(py);
        auto l = lower_bound(data[p].begin(), data[p].end(), y);
        int index = distance(data[p].begin(), l);
        printf("%06d%06d\n", p, index + 1);
    }

    return 0;
}


Measured memory_bytes: 7796
/*****************************************************/
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <cstdlib>
#include <iostream>
#include <algorithm>

using namespace std;

#define   offcin        ios::sync_with_stdio(false)
#define   DEBUG         freopen("#.txt", "r", stdin)
#define   sigma_size    26
#define   lson          l,m,v<<1
#define   rson          m+1,r,v<<1|1
#define   slch          v<<1
#define   srch          v<<1|1
#define   ll            long long
#define   ull           unsigned long long
#define   lowbit(x)     (x&-x)

const int    INF    = 0x3f3f3f3f;
const ll     INFF   = 1e18;
const double pi     = acos(-1.0);
const double inf    = 1e18;
const double eps    = 1e-9;
const ll     mod    = 1e9+7;
const int    maxmat = 10;
const ull    BASE   = 133333331;

/*****************************************************/
inline void RI(int &x) {
      char c;
      while((c=getchar())<'0' || c>'9');
      x=c-'0';
      while((c=getchar())>='0' && c<='9') x=(x<<3)+(x<<1)+c-'0';
}
inline ll bits(ll x) {
      return !x ? x : bits(x - lowbit(x)) + 1;
}
/*****************************************************/

int main(int argc, char const *argv[]) {
    int W, a, c;
    cin>>W>>a>>c;
    int b = a + W, d = c + W;
    if (b < c) cout<<c - b<<endl;
    else if (d < a) cout<<a - d<<endl;
    else cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  // s(Sピースの数),c(cピースの数),ans(作成できるSccの数)
  long long s, c, ans;
  // 「Sピース」と「cピース」の個数を入力
  cin >> s >> c;
  // 「Sピース」が多くて 「cピース」が足りなくなってしまう場合
  // c/2 → 「Scc」を完成させる為には「cピース」が2つ必要なため
  if(s>c/2){
    ans += c/2;
  // それ以外
  }else{
    // 「Sピース」全て使いっても「Scc」が作れるので、まずは「Sピースの個数分 ans に保持
    ans += s;
    // 「Sピース」を使って「Scc」を作った分の「cピース」を c から引く
    // 「Scc」を作るのに「cピース」を2つ使うので「Sピースの個数」×「cピース」×2
    c -= s*2;
    // 「cピース」を2つ使うことで「Sピース」が作れる
    // つまり「cピース」4つで「Scc」が作成可能
    // 残りの「cピース」で作った「Scc」を ans に 加算
    ans += c/4;
  }
  // ans を出力(表示)
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

string s, t;

int main(void){
    cin >> s >> t;
    lli m = s.size();
    lli n = t.size();
    vector<vector<lli>> dp(m+1, vector<lli>(n+1));
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            lli x = 0;
            if(s[i-1] == t[j-1]) x = 1;
            dp[i][j] = max({dp[i-1][j-1]+x, dp[i-1][j], dp[i][j-1]});
        }
    }
    // rep(i, m+1){
    //     rep(j, n+1){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    //cout << dp[m][n] << endl;

    stack<char> st;
    lli i = m;
    lli j = n;
    while(i > 0 && j > 0){
        lli c = dp[i][j];
        if(dp[i-1][j] == c){
            i--;
        }else if(dp[i][j-1] == c){
            j--;
        }else{
            i--;
            j--;
            st.push(s[i]);
        }
    }
    while(!st.empty()){
        cout << st.top();
        st.pop();
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 73724
#include <iostream>
#include <queue>

using namespace std;

struct sort_pred {
    bool operator()(const std::pair<int,int> &left, const std::pair<int,int> &right) {
        return left.second > right.second;
    }
};

int main() {
    int N, M; cin >> N >> M;
    priority_queue<int> p;
    // vector<pair<int,int>> v;
    pair<int, int> v[100000];

    // O(10 ** 5)
    for(int i = 0; i < N; i++) {
        int A; cin >> A;
        p.push(A);
    }

    // O(10 ** 5)
    for(int i = 0; i < M; i++) {
        int B, C; cin >> B >> C;
        v[i] = make_pair(B, C);
    }

    // O(10 ** 5 log 10 ** 5)
    int size = sizeof(v)/sizeof(v[0]);
    sort(v, v+size, sort_pred());

    int n = N;
    for(int i = 0; i < M; i++) {
        auto pair = v[i];
        if(n > pair.first) {
            for(int i = 0; i < pair.first; i++) {
                p.push(pair.second);
            }
            n -= pair.first;
        } else {
            for(int i = 0; i < n; i++) {
                p.push(pair.second);
            }
            break;
        }
    }

    // O(10**5 log 10**5)
    long long sum = 0;
    for(int i = 0; i < N; i++) {
        // cout << p.top() << endl;
        sum += p.top(); p.pop();
    }

    cout << sum << endl;
}


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

//import java.io.*;

//class Main{
//    public static void main(String[] args) throws Exception{
//        int x, ans;
//     
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        x = Integer.parseInt(br.readLine());
//         
//        ans = x*x*x;
//        System.out.println(ans);
//    }
//}

//class Main {
//    public static void main(String[] arg)throws IOException{
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String str = br.readLine();
//        String[] div = str.split(" ");
//        int s =  Integer.parseInt(div[0]);
//        int l =  Integer.parseInt(div[1]);
//        System.out.println(s*l + " "+ 2*(s+l));
//    }   
//}

//import java.io.BufferedReader;
//import java.io.InputStreamReader;
//   
//public class Main{
//    public static void main(String args[])throws java.lang.Exception{
//        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//        String line = br.readLine();
//        //変数に配列を代入
//        int s =Integer.parseInt(line);
//        int h = s / 3600;
//        int m = (s % 3600) / 60;
//        s = s % 60;
//        System.out.println(h+":"+m+":"+s);
//         
//    }
//}

//import java.io.*;
//
//public class Main
//{
//	public static void main(String[] args) throws Exception
//	{
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		String str = br.readLine();
//		String[] div = str.split(" ");
//		int a = Integer.parseInt(div[0]);
//		int b = Integer.parseInt(div[1]);
//		if (a > b)
//		{
//			System.out.println("a > b");
//		} else if (a == b) {
//			System.out.println("a == b");
//		} else {
//			System.out.println("a < b");
//		}
//	}
//}

//public class Main
//{
//	public static void main(String[] args) throws IOException {
//		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
//		String str = br.readLine();
//		String[] div = str.split(" ");
//		int a = Integer.parseInt(div[0]);
//		int b = Integer.parseInt(div[1]);
//		int c = Integer.parseInt(div[2]);
//		if (a < b && b < c)
//		{
//			System.out.println("Yes");
//		}else{
//			System.out.println("No");
//		}
//	}
//}

//public class Main {
//	public static void main(String[] args) {
//		for (int i = 0; i < 1000; i++) {
//			System.out.println("Hello World");
//		}
//	}
//}

public class Main {
    public static void main(String args[]) throws IOException{
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder builder = new StringBuilder();
        int i=1;
        while(true){
            int data= Integer.parseInt(reader.readLine());
            if(data==0)
                break;
             
            builder.append("Case ").append(Integer.toString(i++)).append(": ").append(Integer.toString(data)).append("\n");
        }
        System.out.print(builder);
    }
}

Measured memory_bytes: 30992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

const int maxn = 100100;
struct E {
  ll b, l, u;

  ll delta(ll x) const {
    return calc(x) - calc(0);
  }

  ll calc(ll a) const {
    return (a >= b ? u : l) * (a - b);
  }
};
E a[maxn];
ll prx[maxn];
ll pr0[maxn];
ll x;
int n;
  
bool operator<(const E& e1, const E& e2) {
  return e1.delta(x) > e2.delta(x);
}

ll calc_except(int l, int r, int id, ll* pr) {
  ll res = pr[r] - pr[l];
  if (l <= id && id < r) {
    res -= pr[id + 1] - pr[id];
  }
  return res;
}

ll calc(int id, ll C) {
  ll cnt = C / x;
  ll rem = C % x;
  int bd = id >= cnt ? cnt : cnt + 1;
  ll score = calc_except(0, bd, id, prx) + calc_except(bd, n, id, pr0) + a[id].calc(rem);
  return score;
}

signed main() {
#ifdef LOCAL
  assert(freopen("c.in", "r", stdin));
#endif
  cin >> n >> x;
  for (int i = 0; i < n; ++i) {
    cin >> a[i].b >> a[i].l >> a[i].u;
  }
  sort(a, a + n);
  for (int i = 0; i < n; ++i) {
    prx[i + 1] = prx[i] + a[i].calc(x);
    pr0[i + 1] = pr0[i] + a[i].calc(0);
  }
  ll L = -1, R = x * n;
  while (L + 1 < R) {
    ll C = (L + R) / 2;
    bool ok = false;
    for (int i = 0; i < n; ++i) {
      if (calc(i, C) >= 0) {
        ok = true;
        break;
      }
    }
    if (ok) {
      R = C;
    } else {
      L = C;
    }
  }
  cout << R << '\n';
}


Measured memory_bytes: 4096