akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int N, K;
	cin >> N >> K;
	K--;
	cout << N - K << endl;
	return 0;
}


Measured memory_bytes: 256
import java.io.*;

public class Main {
    static Character[] toCharacterArray (String s) {
        if (s == null) {
            return null;
        }
        int len = s.length();
        Character[] array = new Character[len];
        for (int i = 0; i < len; i++) {
            array[i] = new Character (s.charAt (i));
        }
        return array;
    }
    public static void main (String[] args) throws Exception {
        BufferedReader reader =
            new BufferedReader (new InputStreamReader (System.in));
        Character[] S = toCharacterArray (reader.readLine());
        boolean flg = S[2].equals (S[3]) && S[4].equals (S[5]);
        System.out.println (flg ? "Yes" : "No");
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const i64 MOD = 1e9 + 7;

int main()
{
  i64 n;
  cin >> n;
  vector<i64> a(n);
  for (i64 i = 0; i < n; i++)
    cin >> a[i];
  i64 ans = 0, bit = 1;
  for (i64 i = 0; i < 60; i++)
  {
    i64 cnt[2] = {};
    for (i64 j = 0; j < n; j++)
      if (a[j] & (1LL << i))
        cnt[1]++;
      else
        cnt[0]++;
    (ans += (cnt[0] * cnt[1]) % MOD * bit % MOD) %= MOD;
    (bit *= 2) %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
   
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

const int INF=1e9+7;
 
struct edge{
    int to, cap, cost, rev;
};

int n;
int V;
vector<edge> g[202];
int h[202];
int dist[202];
int prevv[202], preve[202];
 
void add_edge(int from, int to, int cap, int cost){
    edge e;
    e.to=to, e.cap=cap, e.cost=cost, e.rev=g[to].size();
    g[from].push_back(e);
    e.to=from, e.cap=0, e.cost=-cost, e.rev=g[from].size()-1;
    g[to].push_back(e);
}
 
int min_cost_flow(int s, int t, int f){
    int res=0;
    fill(h, h+V, 0);
    while(f>0){
        priority_queue<P, vector<P>, greater<P>> que;
        fill(dist, dist+V, INF);
        dist[s]=0;
        que.push(P(0, s));
        while(!que.empty()){
            P p=que.top(); que.pop();
            int v=p.second;
            if(dist[v]<p.first) continue;
            for(int i=0; i<g[v].size(); i++){
                edge &e=g[v][i];
                if(e.cap>0 && dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
                    dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
                    prevv[e.to]=v;
                    preve[e.to]=i;
                    que.push(P(dist[e.to], e.to));
                }
            }
        }
        for(int v=0; v<V; v++) h[v]+=dist[v];
        if(dist[t]==INF) return -1;
        int d=f;
        for(int v=t; v!=s; v=prevv[v]){
            d=min(d, g[prevv[v]][preve[v]].cap);
        }
		f-=d;
        res+=d*h[t];
        for(int v=t; v!=s; v=prevv[v]){
            edge &e=g[prevv[v]][preve[v]];
            e.cap-=d;
            g[v][e.rev].cap+=d;
        }
    }
    return res;
}

int main()
{
	cin>>n;
	int w[100][100], e[100][100];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>w[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>e[i][j];
		}
	}
	string f[100];
	for(int i=0; i<n; i++) cin>>f[i];
	V=2*n+2;
	int ans=0;
	for(int i=0; i<n; i++) add_edge(V-2, i, 1, 0);
	for(int j=0; j<n; j++) add_edge(j+n, V-1, 1, 0);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(f[i][j]=='.'){
				add_edge(i, j+n, 1, w[i][j]);
			}else{
				add_edge(i, j+n, 1, -e[i][j]);
				ans+=e[i][j];
			}
		}
	}
	ans+=min_cost_flow(V-2, V-1, n);
	cout<<ans<<endl;
	vector<int> r, c, op;
	for(int i=0; i<n; i++){
		for(int j=0; j<g[i].size(); j++){
			if(g[i][j].to>=2*n) continue;
			if((g[i][j].cap==0 && f[i][g[i][j].to-n]=='.') || (g[i][j].cap>0 && f[i][g[i][j].to-n]=='o')){
				r.push_back(i+1);
				c.push_back(g[i][j].to-n+1);
				if(f[i][g[i][j].to-n]=='.') op.push_back(1);
				else op.push_back(0);
			}
		}
	}
	cout<<r.size()<<endl;
	for(int i=0; i<r.size(); i++){
		if(op[i]) cout<<r[i]<<" "<<c[i]<<" write"<<endl;
		else cout<<r[i]<<" "<<c[i]<<" erase"<<endl;
	}
    return 0;
}


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

using namespace std;

#define fore(i, s, e) for(ll i = s; i < (ll)e; i++)
#define pb push_back

typedef long long ll;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x, y, z, K; cin >> x >> y >> z >> K;
    ll a[x], b[y], c[z];
    fore(i, 0, x) cin >> a[i]; 
    fore(i, 0, y) cin >> b[i]; 
    fore(i, 0, z) cin >> c[i];
    sort(a, a + x);
    sort(b, b + y);
    sort(c, c + z);
    reverse(a, a + x);
    reverse(b, b + y);
    reverse(c, c + z);
    vector<ll> res;
    fore(i, 0, x) {
        fore(j, 0, y) {
            fore(k, 0, z) {
                if((i + 1) * (j + 1) * (k + 1) <= K) res.pb(a[i] + b[j] + c[k]);
                else break;
            }
        }
    }
    sort(res.begin(), res.end(), greater<ll>());
    fore(i, 0, K) {
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n;
	cin>>n;
	if(n==1)
	cout<<"0"<<endl;
	else
	cout<<"1"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    string s;

    cin >> s;

    if(s=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
int main(void)
{
	int i, n, a[100];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	for(i=n-1; i>=0; i--){
		printf("%d", a[i]);
		if(i!=0){
			printf(" ");
		}
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 600
N = int(input())
S = []
for i in range(N):
    S.append(input())
print('AC x ' + str(S.count('AC')))
print('WA x ' + str(S.count('WA')))
print('TLE x ' + str(S.count('TLE')))
print('RE x ' + str(S.count('RE')))



Measured memory_bytes: 16272
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;

static class MainClass
{
    public static void Main(string[] args)
    {
        var N = Console.ReadLine().ToInt32();
        var K = Console.ReadLine().ToInt32();

        var X = Console.ReadLine().ToInt32();
        var Y = Console.ReadLine().ToInt32();
        if (N - K >= 0)
            Console.WriteLine(K * X + (N - K) * Y);
        else
            Console.WriteLine(N * X);

        Console.ReadLine();
    }

    #region ライブラリ
    public static long ToInt64(this string str) => long.Parse(str);
    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();
    public static List<long> SplittedStringToInt64List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => long.Parse(x)).ToList();
    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    public const int INF = int.MaxValue / 2;
    public const long LONGINF = long.MaxValue / 2;

  
  

    public static void PrintArray(int[,] array)
    {
        for (int i = 0; i < array.GetLength(0); i++)
        {
            var sb = new StringBuilder();
            for (int j = 0; j < array.GetLength(1); j++)
            {
                sb.Append(array[i, j]).Append(" ");
            }
            Console.WriteLine(sb.ToString());
        }
    }

    #endregion
}



Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <vector>
#include <set>
#include <stack>
#include <queue>

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


using namespace std;
const int MAXN = 1000005;
const int INF = 0x7f7f7f7f;
typedef long long ll;


int main() {
#ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    //freopen("../output.txt", "w", stdout);
#endif
    ll n;
    cin >> n;
    vector<char> v;
    while (n) {
        string al = "zabcdefghijklmnopqrstuvwxy";
        v.push_back(al[n % 26]);
        if (!(n % 26)) --n;
        n = n / 26;
    }
    for (int i = v.size(); i > 0; --i) {
        cout << v[i - 1];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
   int n;cin>>n;
   cout<<"ABC"<<n;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <limits>
#include <cstdlib>
#include <regex>
using namespace std;

double inf = numeric_limits<double>::infinity();

#define REP(i,n) for(int i=0;i<n;i++)
using LL = long long int;
LL GCD(LL a,LL b){ if(a<b) return GCD(b,a); else if(a%b==0) return b; else return GCD(b,a%b); }
LL LCM(LL a,LL b){ return (a/GCD(a,b))*b; }


LL getHoge(LL k) {
    LL hoge = 1;
    while (k != 0) {
        k = k >> 1;
        hoge = hoge << 1;
    }
    hoge = hoge >> 1;
    return hoge - 1;
}

int main() {
    int n;
    LL k;
    
    cin >> n >> k;
    
    LL ans1 = 0, ans2 = 0;
    vector<LL> as, bs;
    
    REP(i,n) {
        LL a, b;
        cin >> a >> b;
        as.push_back(a);
        bs.push_back(b);
    }
    
    if (k == 0) {
        LL ans4 = 0;
        REP(i,n) {
            if (as[i] == 0) {
                ans4 += bs[i];
            }
        }
        cout << ans4 << endl;
        return 0;
    }
    
    
    LL hoge = getHoge(k);
    REP(i,n) {
        if (as[i] <= hoge) {
            ans1 += bs[i];
        }
    }
    
    LL fuga = k - (hoge + 1);
    LL piyo = getHoge(fuga);
    
    
    REP(i,n) {
        if ((as[i] | k) <= k) {
            ans2 += bs[i];
        }
    }
    
    fuga = getHoge(k) + 1;
    piyo = k - fuga;
    while (piyo != 0) {
        LL ans2_tmp = 0;
        LL nyan = getHoge(piyo);
        nyan += fuga;
        
        REP(i,n) {
            if ((nyan | as[i]) <= nyan) {
                ans2_tmp += bs[i];
            }
        }
        ans2 = max(ans2, ans2_tmp);
        fuga += getHoge(piyo) + 1;
        piyo = k - fuga;
    }
    
    cout << max(ans1, ans2) << endl;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    cout << (b - a) * (b - a + 1) / 2 - b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n;
    std::string s;
    std::cin>>n>>s;

    std::vector<int> v;
    v.push_back(0);
    for(int i = 0;i < s.size();i++){
        if(s[i] == 'I'){
            v.push_back(1);
        }else{
            v.push_back(-1);
        }
    }
    std::partial_sum(v.begin(), v.end(), v.begin());
    std::cout<<*std::max_element(v.begin(), v.end())
        <<std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<boost/multiprecision/cpp_ll.hpp>
//using boost::multiprecision::cpp_ll; // use cpp_ll as data type for large numbers 
using namespace std;

#define int ll
#define ll long long
#define pb push_back
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL); 
#define mod 1000000007
#define mp make_pair
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<long long>
#define log2(X) (63ll - __builtin_clzll(X))
#define test ll t; cin>>t; while(t--)
#define modInv(n) po(n,mod-2)%mod
#define ncr(n,r) (((fact[n]*modInv(fact[r]))%mod)*modInv(fact[n-r]))%mod

ll po(ll a, ll b)
{
    ll res=1;
    while(b)
    {
        if(b&1)
        {
            res=(res*a)%mod;
        }
        a=(a*a)%mod;
        b=b/2;
    }
    return res%mod;
}

signed main() 
{
    fast()
    //test
    {
        int n; cin>>n;
        int a[n],b[n],c[n];
        ll dp[n+5][2]={0};
        for(int i=0; i<n; i++)
        {
            cin>>a[i]>>b[i]>>c[i];
        }
        dp[0][0]=a[0]; dp[0][1]=b[0]; dp[0][2]=c[0];
        for(int i=1; i<n; i++)
        {
           dp[i][1]=max(dp[i-1][0]+b[i],dp[i-1][2]+b[i]);
           dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
           dp[i][2]=max(dp[i-1][1]+c[i],dp[i-1][0]+c[i]);
        }
        int ans=max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
        cout<<ans<<"\n";
    }   
}


Measured memory_bytes: 7556
import java.util.Scanner;
 
 
public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		Scanner sc = new Scanner(System.in);
	
		char[] X = sc.next().toCharArray();
		char[] Y = sc.next().toCharArray();
		int X_len = X.length;
		int Y_len = Y.length;
		int[][] dp = new int[X_len+1][Y_len+1];
		//init
		for(int i=0; i<=X_len;i++){
			dp[i][0] = i;
		}
		for(int j=0 ;j<=Y_len; j++){
			dp[0][j] = j;
		}
		
		for(int i=0; i<X_len; i++){
			for(int j=0; j<Y_len; j++){
				
				if(X[i] == Y[j]){
					dp[i+1][j+1] = dp[i][j];
				}else{
					dp[i+1][j+1] = Math.min(Math.min(dp[i+1][j], dp[i][j+1]), dp[i][j])+1;
				}
				
			}
		}
		
		System.out.println(dp[X_len][Y_len]);
		
		sc.close();
	}
	
	
	
}


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

using namespace std;

int a[105];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	long long ans = 1e18;
	for (int i = -100; i <= 100; i++) {
		long long rem = 0;	
		for (int j = 0; j < n; j++) {
			rem += (abs(i - a[j])) * (abs(i - a[j]));
		}
		ans = min(ans, rem);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  int max_cnt = 0;
  rep(i, n) {
    int cnt = 0;
    int ch_num = i + 1;
    while (!(ch_num & 1)) {
      cnt++;
      ch_num >>= 1;
    }
    if (max_cnt < cnt) {
      ans = i + 1;
      max_cnt = cnt;
    }
  }
  cout << ((n == 1) ? 1 : ans) << endl;
}


Measured memory_bytes: 256
# +1/-1の折れ線で表したとき
# 「0で終わる」かつ「途中で0未満にならない」を満たせば良い

# あとは貪欲を上手い事使う


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = []
    b = []
    for _ in range(n):
        s = input().rstrip()
        # 最終的に上がる量/最下点
        up, down = 0, 0
        for i in s:
            if i == ')':
                up -= 1
                if down > up:
                    down = up
            else:
                up += 1
        if up >= 0:
            a.append((down, up))
        else:
            b.append((up-down, down, up))

    a.sort(reverse=True)
    b.sort(key=lambda a: a[0],reverse=True)

    c = 0

    for d, u in a:
        if c+d < 0:
            print('No')
            break
        else:
            c += u
    else:
        for _, d, u in b:
            if c+d < 0:
                print('No')
                break
            else:
                c += u
        else:
            if c == 0:
                print('Yes')
            else:
                print('No')
    
if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i).first >> A.at(i).second;
  }  
  sort(A.begin(), A.end());
  cout << A.at(N-1).first+A.at(N-1).second << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-7;

int n, k;
double d[210], t, u, v, l;
double dp[210][210];

int main(){
	cin >> n >> k >> t >> u >> v >> l;
	rep(i, n) cin >> d[i];
	d[n++] = l;
	
	rep(i, n) rep(j, n) dp[i][j] = INF;
	dp[0][1] = d[0] / u;
	
	double res = INF;
	rep(i, n) rep(j, k + 1) if(dp[i][j] < INF){
		int ni = i + 1, nj = j;
		double dist = d[i], next = dp[i][j];
		
		dp[ni][nj] = min(dp[ni][nj], next + (d[ni] - dist) / u);
		
		while(ni < n){
			while(nj > 0 && dist + EPS < d[ni]){
				nj--;
				dist += t * v;
				next += t;
			}
			if(dist + EPS > d[n - 1]){
				res = min(res, next - (dist - d[n - 1]) / v);
			}
			if(dist + EPS < d[ni]){
				nj++;
				dp[ni][nj] = min(dp[ni][nj], next + (d[ni] - dist) / u);
				break;
			}
			
			if(nj == k){
				next = next - (dist - d[ni]) / v + t;
				dist = d[ni] + t * v;
			}
			ni++;
			nj = min(nj + 1, k);
		}
	}
	rep(i, k + 1) res = min(res, dp[n - 1][i]);
	printf("%.9f\n", res);
	
	return 0;
}

Measured memory_bytes: 1580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define tl t<<1
#define tr t<<1|1
#define mid ((r + l) >> 1)
const int maxn = 2e5 + 5;
const int mod = 998244353;
ll sum[maxn << 2] , mu[maxn] , lazy[maxn << 2] , all[11][maxn];
void PushUp(int t , int l , int r)
{
    ll len = (r - mid) % mod;
    sum[t] = (sum[tl] * mu[len] % mod + sum[tr] ) % mod;
}
void D (int t , int l , int r , int c)
{
    sum[t] = all[c][r - l + 1];
    lazy[t] = c;
}
void pushdown (int t , int l , int r)
{
    if (lazy[t]){
        D(tl , l , mid , lazy[t]);
        D(tr , mid + 1 , r , lazy[t]);
        lazy[t] = 0;
    }
}
void Build(int l,int r,int t)
{
    if(l == r)
    {
        sum[t] = 1;
        return ;
    }
    Build(l , mid , tl);
    Build(mid + 1 , r , tr);
    PushUp(t , l , r);
}
void Update(int L,int R,int l,int r,int t,ll c)
{
    if(L <= l && r <= R)
    {
        sum[t] = all[c][r - l + 1];
        lazy[t] = c;
        return ;
    }
    pushdown(t , l , r);
    if(L <= mid)
        Update(L,R,l,mid,tl,c);
    if(R > mid)
        Update(L,R,mid+1,r,tr,c);

    PushUp(t , l , r);
}
void solve (){
    mu[0] = 1;
    for (ll i = 1 ; i < maxn ; i++)
        mu[i] = mu[i - 1] * 10ll % mod;
    for (ll i = 1 ; i < maxn ; i++)
        for (ll j = 1 ; j <= 9 ; j++)
            all[j][i] = (all[j][i - 1] * 10ll %mod + j) % mod;
}
int main()
{
    solve();
    ios::sync_with_stdio(false);
    int n , q; cin >> n >> q;
    Build(1 , n , 1);
    while (q--){
        int c , l , r; cin >> l >> r >> c;
        Update(l , r , 1 , n , 1 , c);
        cout << sum[1] << endl;
    }
    return 0;
}

Measured memory_bytes: 27448
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
#define double long double
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-6;
const int MOD=1000000007;

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

signed main(){
	int n,dp[200010][2] = {};
	string s;
	cin >> s;
	dp[0][1] = 1;
	for(int i = 0;i < s.length();i++){
		if(s[i] == '1'){
			dp[i + 1][0] = (dp[i + 1][0] + dp[i][0] * 3 + dp[i][1]) % MOD;
			dp[i + 1][1] = (dp[i + 1][1] + dp[i][1] * 2) % MOD;
		}
		else{
			dp[i + 1][0] = (dp[i + 1][0] + dp[i][0] * 3) % MOD;
			dp[i + 1][1] = (dp[i + 1][1] + dp[i][1]) % MOD;
		}
	}
	cout << (dp[s.length()][0] + dp[s.length()][1]) % MOD << endl;
}


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

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

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se secondO
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n,s;
	while(1){
		cin>>n>>s;
		if(n+s==0) break;
		vi r(n);
		rep(i,0,n) cin>>r[i];
		sort(all(r));
		int ans=0;
		rep(i,0,n){
			int id=max(i+1,(int)(upper_bound(all(r),s-r[i])-r.begin()));
			ans+=n-id;
		}
		o(ans);
	}
}

Measured memory_bytes: 1288
import sys
import os


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b = map(str, sys.stdin.readline().split())

    if a == "H" and b == "H":
        ret = "H"
    elif a == "H" and b == "D":
        ret = "D"
    elif a == "D" and b == "H":
        ret = "D"
    elif a == "D" and b == "D":
        ret = "H"

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename T> ll min(ll a, const T&& b) { return a < b ? a : b; }
template<typename T> ll min(const T&& a, ll b) { return a < b ? a : b; }
template<typename T> ll max(ll a, const T&& b) { return a > b ? a : b; }
template<typename T> ll max(const T&& a, ll b) { return a > b ? a : b; }
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll x, y;
  while (cin >> x >> y, x || y) {
    if (x > y) swap(x, y);
    cout << x << " " << y << endl;
  }
}



Measured memory_bytes: 3192
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
ll n;
//ld ;
//string s, t;
 
int main() {
  cin >> n;
  vector<pair<ll,ll>> p(n);
  ll length[n][2];
  ll canWith[n][n];
  for(ll i=0;i<n;i++){
    ll x;
    ll l;
    cin >> x;
    cin >> l;
    p[i] = make_pair(x+l,x-l);
  }
  sort(p.begin(),p.end());
  ll max;
  ll count = 0;
  for(ll j=0;j<n;j++){
    if(j==0 || max <= p[j].second){
      max = p[j].first;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

typedef long long int64;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

int main() {
  int N;
  std::cin >> N;
  if ((N % 1000) == 0) {
    std::cout << 0 << std::endl;
  } else {
    std::cout << 1000 - (N % 1000) << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3604
S = list(input())
n = len(S)
odd = ['R', 'U', 'D']
even = ['L', 'U', 'D']
ans = "Yes"

for i in range(1, n+1):
    if i % 2 == 0:
        if not S[i-1] in even:
            ans = "No"
            break
        else:
            continue
    else:
        if not S[i-1] in odd:
            ans = "No"
            break
        else:
            continue

print(ans)


Measured memory_bytes: 38256
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

ans = list()
for i in range(X):
    for j in range(Y):
        if (i+1)*(j+1) > K:
            break
        else:
            for k in range(Z):
                if (i+1)*(j+1)*(k+1) > K:
                    break
                else:
                    ans.append(A[i]+B[j]+C[k])

ans.sort(reverse=True)
for i in range(K):
    print(ans[i])

Measured memory_bytes: 8724
#!/usr/bin/env python3
import sys
#sys.setrecursionlimit(150000)

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int):
    ans=NO
    for i in range(1,10):
        if N%i==0 and N//i<10:
            ans=YES
            break
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <cstdio>
#include <cstring>

#define ll long long

// 処理内容
int main() {

    ll k; scanf("%lld", &k);
    ll dp[100000];
    memset(dp, 0x7F, sizeof(unsigned ll) * k);
    dp[1] = 1;

    // deque
    ll qv[100000] = {1};
    ll qbeg = 0, qend = 1;

    while (qbeg != qend) {

        ll v = qv[qbeg];
        ll c = dp[v];
        qbeg++; if (qbeg == k) qbeg = 0; // pop_front

        ll n1 = -~v; if (n1 == k) n1 = 0;
        ll n2 = v * 10; while (n2 >= k) n2 -= k;
        if (dp[n1] > -~c) {
            dp[n1] = -~c;
            // push_back
            qv[qend] = n1;
            qend++; if (qend == k) qend = 0;
        }
        if (dp[n2] > c) {
            dp[n2] = c;
            // push_front
            qbeg--; if (qbeg == -1) qbeg = ~-k;
            qv[qbeg] = n2;
        }
        
    }

    printf("%llu", dp[0]);
    
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
const int INF = 1000000007;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    set<int> sugar, water;
    for(int i = 0; i <= F/C; i++){
        for(int j = 0; j <= F/D; j++){
            int tmp = i * C + j * D;
            if(tmp <= F) sugar.insert(tmp); 
        }
    }

    for(int i = 0; i <= F/A; i++){
        for(int j = 0; j <= F/B; j++){
            int tmp = (i * A + j * B) * 100;
            if(tmp <= F && tmp >= 100) water.insert(tmp); 
        }
    }

    int ans_water = 0, ans_sugar = 0;
    double ans_c = -1;
    for(int w : water){
        for(int s : sugar){
            double tmp_c = (double)(s) / (double)(s + w);
            if(w + s <= F && s <= w / 100 * E && tmp_c > ans_c){
                ans_sugar = s;
                ans_water = w;
                ans_c = (double)(ans_sugar) / (double)(ans_water + ans_sugar);
            }
        }
    }

    cout << ans_sugar + ans_water << ' ' << ans_sugar << endl;
}

Measured memory_bytes: 384
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
#include <utility>
//#include <set>
//#include <map>
#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
ll INF = 1e15 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,m,s ;
	cin >> n >> m >> s ;
	vector<vector<pair<ll,pll>>> g(n) ;
	for(int i=0;i<m;i++){
		ll u,v,a,b ;
		cin >> u >> v >> a >> b ;
		u-- ; v-- ;
		g.at(u).emplace_back(v,make_pair(a,b)) ;
		g.at(v).emplace_back(u,make_pair(a,b)) ;
	}
	vector<pll> chg(n) ;
	for(int i=0;i<n;i++) cin >> chg.at(i).first >> chg.at(i).second ;
	vvll d(n,vll(2501,INF)) ;
	priority_queue<pair<ll,pll>> pq ;
	pq.emplace(0,make_pair(0,min(s,2500ll))) ;
	while(!pq.empty()){
		ll cost = -pq.top().first ;
		ll p = pq.top().second.first ;
		ll mny = pq.top().second.second ;
		pq.pop() ;
		if(d.at(p).at(mny)!=INF) continue ;
		d.at(p).at(mny) = cost ;
//		if(mny<15) cout << p << " " << mny << " " << cost << endl ;
		if(d.at(p).at(min(mny+chg.at(p).first,2500ll))==INF) pq.emplace(-cost-chg.at(p).second,make_pair(p,min(mny+chg.at(p).first,2500ll))) ;
		for(int i=0;i<g.at(p).size();i++){
			if(mny<g.at(p).at(i).second.first) continue ;
			if(d.at(g.at(p).at(i).first).at(mny-g.at(p).at(i).second.first)!=INF) continue ;
			pq.emplace(-cost-g.at(p).at(i).second.second,make_pair(g.at(p).at(i).first,mny-g.at(p).at(i).second.first)) ;
		}
	}
	for(int i=1;i<n;i++){
		ll ans = INF ;
		for(int j=0;j<=2500;j++) ans = min(ans,d.at(i).at(j)) ;
		cout << ans << endl ;
	}
//	for(int i=0;i<n;i++){
//		for(int j=0;j<15;j++) cout << d.at(i).at(j) << (j==14?"\n":" ") ;
//	}
}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
  ll n, c=0, b;
  cin >> n;
  vecll a(n + 1);
  forll(i, 0, n+1)
	cin >> a[i];
  forll(i, 0, n){
	cin >> b;
	if (a[i] < b){
	  c += min(b, a[i] + a[i + 1]);
	  a[i + 1] = max((ll)0, a[i + 1] + a[i] - b);
	}else
	  c += b;
  }
  cout << c << endl;
}

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

int a[3], mx;
int main(){
	rep(i,3)scanf("%d", &a[i]);
	rep(i,3)mx = max(mx, a[i]);
	int ans = 0;
	rep(i,3)ans += mx-a[i];
	if(ans%2 == 0){
		printf("%d\n", ans/2);
	}else{
		ans = ans/2;
		ans += 2;
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
		int max = 0;
		for(int i = 0; i < n; i++){
		    String s = sc.next();
		    int cnt = tm.getOrDefault(s, 0) + 1;
		    tm.put(s, cnt);
		    max = max(max, cnt);
		}
		
		// 計算
		//String result = "Yes";
		for(String key : tm.keySet()){
		    //System.out.println(max);
		    if(tm.get(key).equals(max)) System.out.println(key);
		}
		
		// 出力
		//System.out.println(result);
	}
}


Measured memory_bytes: 78968
#include <iostream>
#include <vector>
using namespace std;
bool separate(int* A, int i, vector<int>& vB, vector<int>& vC)
{
	if (i == 10)
		return true;
	
	{
		vector<int> vTmpB(vB);
		if (vTmpB.empty() || (!vTmpB.empty() && (vTmpB.back() < A[i]))){
			vTmpB.push_back(A[i]);
			if (separate(A, i + 1, vTmpB, vC))
				return true;
		}
	}

	{
		vector<int> vTmpC(vC);
		if (vTmpC.empty() || (!vTmpC.empty() && (vTmpC.back() < A[i]))){
			vTmpC.push_back(A[i]);
			if (separate(A, i + 1, vB, vTmpC))
				return true;
		}
	}

	return false;
}
int main()
{
	int n;
	cin >> n;
	int A[10] = {};
	while(n--){
		for (int j = 0; j < 10; ++j)
			cin >> A[j];
		vector<int> vB, vC;
		if (separate(A, 0, vB, vC)) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}

Measured memory_bytes: 1176
#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 a, b, c, loopcount;
int giveA, giveB, giveC;

int main() {
  cin >> a >> b >> c;
  loopcount = 0;
  while (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    giveA = a / 2;
    giveB = b / 2;
    giveC = c / 2;
    a = giveB + giveC;
    b = giveC + giveA;
    c = giveA + giveB;
    loopcount++;
    if (loopcount > 100000000) break;
  }
  if (loopcount > 100000000) {
    cout << -1 << endl;
  }else{
    cout << loopcount << endl;
  }
  return 0;
}


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

int d;

int choco(int a){
    int eatChoco=(d-1)/a+1;
    return eatChoco;
}

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

    int ans=x;
    for(int i=0;i<n;i++){
        ans+=choco(a[i]);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long int ll;

ll dp[200100][4];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	ll r,s,p; cin >> r >> s >> p;
	string ss; cin >> ss;
	for(int i=0;i<n;i++){
		for(int j=0;j<4;j++){
			for(int pp=0;pp<3;pp++){
				if(pp==j)continue;
				if(pp==0)dp[i+k][pp]=max(dp[i+k][pp],dp[i][j]+(ss[i]=='s'?r:0));
				if(pp==1)dp[i+k][pp]=max(dp[i+k][pp],dp[i][j]+(ss[i]=='p'?s:0));
				if(pp==2)dp[i+k][pp]=max(dp[i+k][pp],dp[i][j]+(ss[i]=='r'?p:0));
			}
		}
	}
	ll ans=0;
	for(int i=n-1;i>n-1-k;i--){
		ll ma=0;
		for(int pp=0;pp<4;pp++){
			ma=max(ma,dp[i+k][pp]);
		}
		ans+=ma;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int a1,a2,a3,b1,b2,b3,c1,c2,c3;
	cin>>a1>>a2>>a3>>b1>>b2>>b3>>c1>>c2>>c3;
	if(a1+b2+c3==a1+b3+c2&&a1+b3+c2==a2+b1+c3&&a2+b1+c3==a2+b3+c1&&a2+b3+c1==a3+b1+c2&&a3+b1+c2==a3+b2+c1)puts("Yes");
	else puts("No");
}

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

typedef vector< pair< int,pair<int,int> > > vpp;

void rm(vpp &v,const int d){
  int i=0;
  for(;i<v.size();i++)
    if(v[i].first==d)
      {v.erase(v.begin()+i);break;}
}

void add(vpp &v,const int d,const int w){
  int i=0;
  for(;~v[i].first;i++){
    if(v[i+1].second.first-v[i].second.second>=w){
      v.insert(v.begin()+i+1,make_pair(d,make_pair(v[i].second.second,v[i].second.second+w)));
      printf("%d\n",v[i].second.second);break;
    }
  }
  if(v[i].first==-1)puts("impossible");
}

int main(){
  int W,Q,d,w;
  char s[2];
  for(;scanf("%d%d",&W,&Q),W;){
    vpp v;
    v.push_back(make_pair(-2,make_pair(0,0)));
    v.push_back(make_pair(-1,make_pair(W,0)));
    for(;Q;Q--){
      scanf("%s",s);
      if(*s=='w')scanf("%d",&d),rm(v,d);
      else scanf("%d%d",&d,&w),add(v,d,w);
    }
    puts("END");
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE 100100
#define NIL -1
#define MAX_N 100100

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string a, b, c;

int main() {
	cin >> a >> b >> c;
	if (a.back() == b[0] && b.back() == c[0])cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;

public class Main {

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

		while(true){
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			if(x1==0 && y1==0) break;
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();
			int x3 = sc.nextInt();
			int y3 = sc.nextInt();
			int x4 = sc.nextInt();
			int y4 = sc.nextInt();
			double maxx = Math.max(Math.max(x1,x2), x3);
			double maxy = Math.max(Math.max(y1,y2), y3);
			double minx = Math.min(Math.min(x1,x2), x3);
			double miny = Math.min(Math.min(y1,y2), y3);			
			Point2D.Double p1 = new Point2D.Double(x1,y1);
			Point2D.Double p2 = new Point2D.Double(x2,y2);
			Point2D.Double p3 = new Point2D.Double(x3,y3);
			Point2D.Double p4 = new Point2D.Double(x4,y4);
			Line2D.Double a = new Line2D.Double(p2,p3);
			Line2D.Double b = new Line2D.Double(p3,p1);
			Line2D.Double c = new Line2D.Double(p1,p2);
			double r = sc.nextDouble();

			if(p4.distance(p1)<=r && p4.distance(p2)<=r && p4.distance(p3)<=r){
				System.out.println("b");
			}else if(a.ptSegDist(p4)>=r && b.ptSegDist(p4)>=r && c.ptSegDist(p4)>=r){
				Line2D.Double da = new Line2D.Double(p1,p4);
				Line2D.Double db = new Line2D.Double(p2,p4);
				Line2D.Double dc = new Line2D.Double(p3,p4);
				if(minx<x4 && x4<maxx && miny<y4 && y4<maxy && a.intersectsLine(da)==false
						&& b.intersectsLine(db)==false && c.intersectsLine(dc)==false){
					System.out.println("a");
				}else{
					if(a.ptSegDist(p4)==r || b.ptSegDist(p4)==r || c.ptSegDist(p4)==r){
						System.out.println("c");
					}else{
						System.out.println("d");
					}
				}
			}else{
				System.out.println("c");
			}
		}
	}
}

Measured memory_bytes: 23224
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	mc := newModcom(m + 1)
	max := mc.choose(m, n).mul(mc.facs[n])
	horobiyo := max
	for i := 1; i < n+1; i++ {
		if i&1 == 1 {
			horobiyo.subAs(mc.choose(n, i).mul(mc.choose(m-i, n-i).mul(mc.facs[n-i])))
			continue
		}
		horobiyo.addAs(mc.choose(n, i).mul(mc.choose(m-i, n-i).mul(mc.facs[n-i])))
	}
	ans := max.mul(horobiyo)
	fmt.Fprintln(writer, ans)
}

type mint int64

func (mt mint) mod() mint {
	m := mint(1e9 + 7)
	mt %= m
	if mt < 0 {
		return mt + m
	}
	return mt
}
func (mt mint) inv() mint {
	return mt.pow(mint(0).sub(2))
}
func (mt mint) pow(n mint) mint {
	p := mint(1)
	for n > 0 {
		if n&1 == 1 {
			p.mulAs(mt)
		}
		mt.mulAs(mt)
		n >>= 1
	}
	return p
}
func (mt mint) add(x mint) mint {
	return (mt + x).mod()
}
func (mt mint) sub(x mint) mint {
	return (mt - x).mod()
}
func (mt mint) mul(x mint) mint {
	return (mt * x).mod()
}
func (mt mint) div(x mint) mint {
	return mt.mul(x.inv())
}
func (mt *mint) addAs(x mint) *mint {
	*mt = mt.add(x)
	return mt
}
func (mt *mint) subAs(x mint) *mint {
	*mt = mt.sub(x)
	return mt
}
func (mt *mint) mulAs(x mint) *mint {
	*mt = mt.mul(x)
	return mt
}
func (mt *mint) divAs(x mint) *mint {
	*mt = mt.div(x)
	return mt
}

type modcom struct {
	facs, invs []mint
}

func newModcom(n int) modcom {
	facs := make([]mint, n+1)
	invs := make([]mint, n+1)
	facs[0] = 1
	for i := 0; i < n; i++ {
		facs[i+1] = facs[i].mul(mint(i + 1))
	}
	invs[n] = facs[n].inv()
	for i := n - 1; i >= 0; i-- {
		invs[i] = invs[i+1].mul(mint(i + 1))
	}
	return modcom{
		facs: facs,
		invs: invs,
	}
}
func (mc *modcom) choose(n, k int) mint {
	return mc.facs[n].mul(mc.invs[k]).mul(mc.invs[n-k])
}


Measured memory_bytes: 9960