akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int m = scanner.nextInt();
        ArrayList<int[]> tasks = new ArrayList<>(n);
        for (int i = 0; i < n; ++i) {
            int a = scanner.nextInt();
            int b = scanner.nextInt();
            tasks.add(new int[]{a, b});
        }
        tasks.sort(Comparator.comparingInt(o -> o[0]));
        PriorityQueue<Integer> available = new PriorityQueue<>(n, Comparator.reverseOrder());
        int ans = 0;
        for (int day = 1, i = 0; day <= m; ++day) {
            while (i < n && tasks.get(i)[0] <= day) {
                available.add(tasks.get(i)[1]);
                ++i;
            }
            if (!available.isEmpty())
                ans += available.poll();
        }
        writer.println(ans);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.valueOf(next());
        }

        private long nextLong() {
            return Long.valueOf(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 48640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	ll n, W;
	cin >> n >> W;
	ll w[n+1], v[n+1];
	rep(i, 1, n+1){
		cin >> w[i] >> v[i];
	}
	ll maxn = 100008;
	ll dp[maxn];
	rep(i, 1, maxn){dp[i] = INF;}
	dp[0] = 0;
	
	rep(i, 1, n+1){
		rrep(j, maxn-1, 0){
			if(j+v[i] < maxn){
				dp[j+v[i]] = min(dp[j]+w[i], dp[j+v[i]]);
			}
		}
	}
	ll ans = 0;
	rep(i, 0, maxn){
		if(dp[i] <= W){
			ans = max(i, ans);
		}
	}
	print(ans)
	//printa(dp, 0, 12)
	return 0;
}

Measured memory_bytes: 1024
//                             In The Name Of Allah
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 
 
const int N = 1e5 + 100, OO = 1e6 + 1000, T = 10, M = 998244353, P = 6151, SQ = 300, lg = 44;
typedef pair <int, int> pii;

int32_t main() {
	use_fast;
	string s;
	cin >> s;
	if((int)s.size() % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	for(int i = 0; i < (int)s.size(); i += 2) {
		if(s[i] == 'h' && s[i + 1] == 'i')
			continue;
		else {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0; 
} 
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- ... 
*/

Measured memory_bytes: 256
n = gets.to_i
a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)

satisfaction = 0


n.times do |i|
  satisfaction += b[a[i].to_i - 1].to_i

  if i > 0 && a[i].to_i - a[i-1].to_i == 1
    satisfaction += c[a[i-1].to_i - 1].to_i
  end
end


p satisfaction

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ret = 0;
    if (a[0] != 0) {
        cout << -1 << "\n";
        return 0;
    }
    a.push_back(-1);
    for (int i = 1; i < n; ++i) {
        if (a[i] > a[i - 1] + 1) {
            cout << -1 << "\n";
            return 0;
        }
        if (a[i] == a[i + 1] - 1) {
            continue;
        } else {
            ret += a[i];
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  string tarou,hanako;
  int T=0,H=0;
  int i,n;


  cin >>n;

  for(i=0;i<n;i++){
    cin >>tarou >>hanako;
    if(tarou>hanako) T=T+3; 
    else if(tarou<hanako) H=H+3;
    else{++T;++H;}
  }

  cout <<T <<" " <<H <<endl;

  return 0;
}

Measured memory_bytes: 1208
n = int(input())
total = 0
a = list(map(int,input().split()))
table = [0 for i in range(100000+1)]
for i in a:
    total+=i
    table[i]+=1

q = int(input())

for _ in range(q):
    a,b = map(int,input().split())
    total -= table[a]*a
    table[b] += table[a]
    total += table[a]*b
    table[a]= 0
    print(total)


Measured memory_bytes: 91004
#include <bits/stdc++.h>
#define sz              size()
#define pb              push_back
#define Fr              first
#define Sc              second
#define Log2(x)         (31^__builtin_clz(x))
#define endl            "\n"
#define int             ll
using namespace std;
typedef long long ll;
int n, k, c;
string s;
int dpL[200200];
int dpR[200200];
int recL(int i) {
    if(i >= s.sz) return 0;
    if(dpL[i] != -1) return dpL[i];
    int p = 0, l = 0;
    if(s[i] == 'x') p += recL(i + 1);
    else {
        p += recL(i + c + 1) + 1;
        l += recL(i + 1);
    }
    return dpL[i] = max(p, l);
}
int recR(int i) {
    if(i < 0) return 0;
    if(dpR[i] != -1) return dpR[i];
    int p = 0, l = 0;
    if(s[i] == 'x') p += recR(i - 1);
    else {
        p += recR(i - c - 1) + 1;
        l += recR(i - 1);
    }
    return dpR[i] = max(p, l);
}
int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n >> k >> c;
    cin >> s;
    memset(dpL, -1, sizeof dpL);
    memset(dpR, -1, sizeof dpR);
    recL(0);
    recR(s.sz - 1);
    if(dpL[1] < k) cout << 1 << endl;
    for(int i = 1 ; i < s.sz - 1 ; i++) {
        if(s[i] == 'o' && dpL[i + 1] + dpR[i - 1] < k)
            cout << i + 1 << endl;
    }
    if(dpR[s.sz - 2] < k && s.sz > 1) cout << s.sz << endl;
}


Measured memory_bytes: 11156
n,m,r,t,i,j,k,a[100][100],b[100][100];
main(){
    long c;
    scanf("%d%d%d",&n,&m,&r);
    for(i=0;i<n;i++)
        for(j=0;j<m;j++)
            scanf("%d",&a[i][j]);
    for(i=0;i<m;i++)
        for(j=0;j<r;j++)
            scanf("%d",&b[i][j]);
    for(i=0;i<n;i++)
        for(j=0;j<r;j++){
            for(k=c=0;k<m;k++){
                c+=a[i][k]*b[k][j];
            }
            printf("%ld%s",c,j==r-1?"\n":" ");
        }
}

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

using namespace std;
typedef long long ll;

const char W = '.';
const char B = '#';

int main(){
    ll a, b;
    cin >> a >> b;

    const ll na = 2 * (a - 1 + 49) / 50;
    const ll nb = 2 * (b - 1 + 49) / 50;

    vector<vector<char>> map(na + nb, vector<char>(100, W));
    for(int i = 0; i < na; ++i){
        fill(map.at(i).begin(), map.at(i).end(), B);
    }
    a--; b--;
    for(int i = 0; a > 0; i += 2){
        for(int j = 0; j < map.at(i).size() && a > 0; j += 2){
            map.at(i).at(j) = W;
            a--;
        }
    }
    for(int i = na + 1; b > 0; i += 2){
        for(int j = 0; j < map.at(i).size() && b > 0; j += 2){
            map.at(i).at(j) = B;
            b--;
        }
    }

    cout << map.size() << ' ' << map.at(0).size() << endl;
    for(int i = 0; i < map.size(); ++i){
        for(int j = 0; j < map.at(i).size(); ++j){
            cout << map.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}


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

#define INF 1000000007;

int N, K;
int h[100005];
long long dp[100005];

int main() {
    cin >> N >> K;
    for (int i = 1; i <= N; ++i) {
        cin >> h[i];
    }

    dp[1] = 0LL;
    for (int i = 2; i <= N; ++i) {
        dp[i] = INF;
        for (int kk = 1; kk <= K; ++kk) {
            if (i - kk >= 1) {
                dp[i] = min(dp[i], dp[i - kk] + abs(h[i] - h[i -kk]));
            }
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX=2e5+7,MOD=2019;
int main (){
    string s;
    cin>>s;
    int n = s.size();
    vector<int>digits(n);
    for(int i=0;i<n;i++) digits[i]=s[i]-'0';
    reverse(digits.begin(),digits.end());

    map<int,int>cnt;
    cnt[0]=1;
    int res=0;
    ll curr = 0;
    ll power=1;

    for(auto x:digits){
        curr = (curr)%MOD + (x*power)%MOD;
        curr%=MOD;
        res+=cnt[curr];
        cnt[curr]++;
        power*=10;
        power%=MOD;
    }

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


Measured memory_bytes: 4444
import java.util.Scanner;

/**
 * Created by zzt on 17-1-16.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();

        s = s.replaceAll("eraser", "");
        s = s.replaceAll("erase", "");
        s = s.replaceAll("dreamer", "");
        s = s.replaceAll("dream", "");

        System.out.println(s.length()>0?"NO":"YES");
    }
}

Measured memory_bytes: 16188
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cstdlib>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>
#include <cstring>

using namespace std;

#define ll long long

#ifndef ONLINE_JUDGE
#define debug(format, ...) fprintf(stderr, \
    "%s:%d: " format "\n", __func__, __LINE__,##__VA_ARGS__)
#else
#define debug(format, ...)
#define NDEBUG
#endif

int n;
pair<int, int> seq[5005];

bool cmp(pair<int, int> a, pair<int, int> b)
{
    return a.first + a.second < b.first + b.second;
}

ll f[5005][5005]; /* min blk cnt */

ll inf = 1000000000000000000LL;

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &(seq[i].first), &(seq[i].second));
    }
    sort(seq + 1, seq + n + 1, cmp);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i+1; j++) {
            f[i+1][j] = inf;
        }
        for (int j = 0; j <= i; j++) {
            f[i+1][j] = min(f[i+1][j], f[i][j]);
            if (seq[i+1].first >= f[i][j]) {
                f[i+1][j+1] = min(f[i+1][j+1], f[i][j] + seq[i+1].second);
            }
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; i++) {
        if (f[n][i] != inf) ans = i;
    }
    printf("%d", ans);
    return 0;
}


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

typedef long long ll;

const int Maxn = 100005;
const int Inf = 1000000007;

int X, Y, A, B, C;
int a[Maxn], b[Maxn], c[Maxn];
int pnta, pntb, pntc;
ll res;

int main()
{
    scanf("%d %d %d %d %d", &X, &Y, &A, &B, &C);
    for (int i = 0; i < A; i++)
        scanf("%d", &a[i]);
    sort(a, a + A);
    for (int i = 0; i < B; i++)
        scanf("%d", &b[i]);
    sort(b, b + B);
    for (int i = 0; i < C; i++)
        scanf("%d", &c[i]);
    sort(c, c + C);
    pnta = A - X;
    pntb = B - Y;
    for (int i = 0; i < C; i++) {
        int mn = Inf;
        if (pnta < A) mn = min(mn, a[pnta]);
        if (pntb < B) mn = min(mn, b[pntb]);
        if (pntc < C) mn = min(mn, c[pntc]);
        if (pnta < A && mn == a[pnta]) { pnta++; continue; }
        if (pntb < B && mn == b[pntb]) { pntb++; continue; }
        pntc++;
    }
    for (int i = pnta; i < A; i++)
        res += a[i];
    for (int i = pntb; i < B; i++)
        res += b[i];
    for (int i = pntc; i < C; i++)
        res += c[i];
    cout << res << endl;
    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ZERO(a) memset(a,0,sizeof(a))
#define AND(x,y) (int)((x)&(y))

const int M = 1024;
int a,b,c,n;
int state[334];
int X[M],Y[M],Z[M];

void init(void) {
    ZERO(state);ZERO(X);ZERO(Y);ZERO(Z);
}

int count1(int i) {
    return (AND(state[X[i]],1) + AND(state[Y[i]],1) + AND(state[Z[i]],1));
}

int main() {
    while(cin>>a>>b>>c && a) {
        init();
        cin >> n;
        rep(i,n) {
            int x,y,z,w; cin>>x>>y>>z>>w;
            if(w == 1) state[x]=state[y]=state[z]=1;
            X[i]=x;Y[i]=y;Z[i]=z;
        }

        rep(i,n) {
            if(count1(i) == 3) continue; // w == 1

            if(count1(i) == 2) {
                if(AND(state[X[i]],1) != 1) state[X[i]] = 2;
                if(AND(state[Y[i]],1) != 1) state[Y[i]] = 2;
                if(AND(state[Z[i]],1) != 1) state[Z[i]] = 2;
            }
        }

        for(int i = 1; i <= a+b+c; i++) {
            if(state[i] == 0) cout<<2<<"\n";
            if(state[i] == 1) cout<<1<<"\n";
            if(state[i] == 2) cout<<0<<"\n";
        }
    }


    return 0;
}

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

const int INF = 1001001001;
int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s, 1<<n){
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i & 1) {
	cost += c[i];
	rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3640
import sys,bisect
input = sys.stdin.readline

n,k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9+7

fact = [1]
fact_inv = [1]
for i in range(10**5+5):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))


def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

a.sort()

mi = 0
for i in range(n-k+1):
    mi = (mi + a[i]*mod_comb_k(n-i-1,k-1,mod)%mod)%mod

a = a[::-1]
ma = 0
for i in range(n-k+1):
    ma = (ma + a[i]*mod_comb_k(n-i-1,k-1,mod)%mod)%mod


print((ma-mi)%mod)

Measured memory_bytes: 66984
N, x = map(int, input().split())

n = 2 * N - 1
if x == 1 or x == n:
    print('No')
    exit()
elif N == 2:
    print('Yes')
    print('\n'.join(map(str, [1, 2, 3])))
    exit()

n = n // 2 + 1
N *= 2
answer = [0] * N

if x == N - 2:
    answer[n] = x
    answer[n + 1] = x + 1
    answer[n + 2] = x - 1
    answer[n - 1] = x - 2

    numbers = list(range(1, x - 2)) + list(range(x + 2, N))
else:
    answer[n] = x
    answer[n + 1] = x - 1
    answer[n + 2] = x + 2
    answer[n - 1] = x + 1

    numbers = list(range(1, x - 1)) + list(range(x + 3, N))

for i in range(1, N):
    if answer[i] == 0:
        answer[i] = numbers.pop()

print('Yes')
print('\n'.join(map(str, answer[1:])))


Measured memory_bytes: 26684
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

// input
uint64_t getZ() {
  uint64_t v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 50;
int v[MAXN];

int main() {
  std::cout << std::setprecision(10) << std::fixed;
  int N = getZ();
  for(int i = 0; i < N; ++i) v[i] = getZ();
  std::sort(v, v+N);
  double ans = 0.5*(v[0]+v[1]);
  for(int i = 2; i < N; ++i) (ans += v[i]) *= 0.5;
  fin(ans);
  return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second

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

int main ()
{
    fastio
    char a , b ; 
  cin >> a >> b ;
  cout << (a=='H' ? b : (b== 'H' ? 'D' : 'H'));

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
    int n;
    cin >> n;
    int h[30];
    for (int i = 0; i < n; i++) cin >> h[i];
    int count = 0;
    for (int i = 0; i < n; i++){
        int count2 = 0;
        for (int j = 0; j < i; j++){
            if (h[j] <= h[i]) count2++;
        }
        if (count2 == i) count++;
    }
    cout << count << endl;
  return 0;
}


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

int main(){
	int r;
	while(cin>>r){
		if(r<1200){
			cout<<"ABC"<<endl;
		}
		if(r>=1200&&r<2800){
			cout<<"ARC"<<endl;
		}
		if(r>=2800){
			cout<<"AGC"<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if (n == m) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;
    return 0;
}


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

int main(void) {
    int n, x, a[100000];
    long long ans;
    cin >> n >> x;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        int temp = max(a[i] + a[i + 1] - x, 0);
        a[i + 1] -= temp;
        a[i] -= max(0 - a[i + 1], 0);
        a[i + 1] = max(a[i + 1], 0);
        ans += temp;
    }
    cout << ans << endl;
}


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

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

    // X * 1.08 = N
    double X = N / 1.08;
    int ans = (int)X;
    bool found = false;
    for(int i=ans-1; i<ans+2; i++) {
        if((int)(i * 1.08) == N) {
            cout << i << endl;
            found = true;
            return 0;
        }
    }
    if(!found){
        cout << ":(" << endl;
    }
}

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

int main() {
    int N, M, C, a, ans = 0, sum = 0;
    cin >> N >> M >> C;
    vector<int> B(M);
    for (int i = 0; i < M; i++) {
        cin >> B.at(i);
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            cin >> a;
            sum += a * B.at(j);
        }
        if (sum + C > 0) {
            ans++;
        }
        sum = 0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	String n = s.next();
    	if(n.charAt(0)>=65 && n.charAt(0)<=90)System.out.println("A");
    	else System.out.println("a");
    	
    	
    	
    }	
}


Measured memory_bytes: 32632
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vvl a(n, vl(n));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    vl scores(1 << n);
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = 0; j < n; ++j) {
            for (int k = j + 1; k < n; ++k) {
                if ((i & (1 << j)) && (i & (1 << k)))
                    scores[i] += a[j][k];
            }
        }
    }
    vl dp(1 << n, 0);
    for (int i = 0; i < (1 << n); ++i) {
        for (int j = i; j > 0; j = (j - 1) & i) {
            chmax(dp[i], dp[i - j] + scores[j]);
        }
    }
    cout << dp[(1 << n) - 1] << "\n";
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n,m; cin >> n >> m;
  bool ans = true;
  vector<int> a(n,-1);
  rep(i,m){
    int s,c; cin >> s >> c;
    if(a[s-1]==-1) a[s-1]=c;
    else if(a[s-1]!=c) ans = false;
  }

  if(n!=1&&a[0]==0) ans = false;

  if(ans){
    for(int i=0;i<n;i++){
      if(a[i]==-1){
        if(i==0&&n>=2) a[i]=1;
        else a[i]=0;
      }
      cout << a[i];
    }
    cout << endl;
  }else{
    puts("-1");
  }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) FOR(i, 0, a)
#define ROF(i, a, b) for (int i = (b); i >= (a); i--)
#define R0F(i, a) ROF(i, 0, a-1)
#define trav(x, a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty;

    swap(sx, sy); swap(tx, ty);

    int dx = abs(sx-tx), dy = abs(sy-ty);

    string res = string(dx, 'U')+string(dy, 'R')+string(dx, 'D')+string(dy, 'L')+"L"+string(dx+1, 'U')+string(dy+1, 'R')+"DR"+string(dx+1, 'D')+string(dy+1, 'L')+"U";

    cout << res << "\n";

}


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

using namespace std;

int ipow(int a, int b) {
    int temp = 1;

    for (int i = 0; i < b; i++) {
        temp *= a;
    }
    return temp;
}

int main() {
    int n;
    vector<int> a;

    cin >> n;

    int temp;

    for (int i = 0; i < n; i++) {
        cin >> temp;
        a.push_back(temp);
    }

    sort(a.begin(), a.end(), std::greater<int>());

    long long int ans = 0;
    int ii = 0;

    for (int i = 0; i < n; i++) {
        ans += a[ii];
        if (i % 2 == 1)ii++;
    }

    cout << ans - a[0];

    return 0;
}

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

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n; string s;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
			ans++;
		}
	}
	cout << ans << endl;
}

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

signed main()
{
    int H,W; cin>>H>>W;
    vector<string> s(H);
    for(int i=0;i<H;i++){
      cin>>s[i];
    }

    int ans=0;
    for(int i=0;i<H*W;i++){
      for(int j=0;j<H*W;j++){
        int y1=i/W, x1=i%W;
        int y2=j/W, x2=j%W;
        if(s[y1][x1]=='B' and s[y2][x2]=='B'){
          ans=max(ans,abs(y1-y2)+abs(x1-x2));
        }
      }
    }
    cout<<ans<<endl;
}




Measured memory_bytes: 3244
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;

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

    for (int j = n-1; j>=0;--j) {
        cout<<a[j];
        if(j==0)cout<<endl;
        else cout<<' ';
    }


    return 0;

}


Measured memory_bytes: 3020
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,unsafe-math-optimizations")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
#include "bits/stdc++.h"
#include <assert.h>
#include <immintrin.h>
#include <emmintrin.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
const int MOD=1000000007;
#define endl "\n"
#define fst first
#define snd second
const int UNDEF = -1;
const int INF=1<<30;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<ll,ll> pll;typedef vector<ll> vll;typedef pair<int,int> pii;typedef vector<int> vi;typedef vector<vi> vvi;
#ifdef ONLINE_JUDGE
#define assert(...) /* nothing */
#endif
#define DEBUG_CAT
#ifdef DEBUG_CAT
#define dbg(...)   printf( __VA_ARGS__ )
#else 
#define dbg(...)   /****nothing****/
#endif
const int mn=1e6+4;
int a[mn];

int n,k;
int f(int x) {
  int den=k-1;
  return (x+den-1)/den;
}
int main()
{
  cin>>n>>k;
  int one;
  for (int i=0;i<n;i++) {
    int x; cin>>x; if (x==1) one=i;
  }
  int ans=f(one)+f(n-1-one);
  for (int b=-k;b<=k;b++) {
    int L=one+b;
    int R=n-1-one-b;
    if (L>=0&&R>=0) {
      //if (b<0) ++R;
      //if (b>0) ++L;
      int cand=f(L)+f(R);
      //printf("b:%d L:%d R:%d cand:%d. %d %d\n",b,L,R,cand,f(L),f(R));
      chkmin(ans, cand);
    }
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
int main(void){
  int a,b,i;
  scanf("%d %d",&a,&b);

  if(a>b){
   for(i=0;i<a;i++){
     printf("%d",b);
   }
  }
  if(b>a){
    for(i=0;i<b;i++){
     printf("%d",a);
   }
  }
  if(a==b){
    for(i=0;i<a;i++){
     printf("%d",b);
   }
  }
  return 0;
}

Measured memory_bytes: 1724
/*input
AAAAABBBBAAABBBBAAAA
BBBBAAABBBBBBAAAAABB
10
2 15 2 13
2 13 6 16
1 13 2 20
4 20 3 20
1 18 9 19
2 14 1 11
3 20 3 15
6 16 1 17
4 18 8 20
7 20 3 14
*/
#include <bits/stdc++.h>
using namespace std;

string s1,s2;
long cak,q;
long c1[100005],c2[100005];
long a,b,c,d;

int main(){
	cin >> s1 >> s2 ;
	cak=0;
	for(int i=0;i<s1.length();i++){
		if(s1[i]=='A') cak++;
		if(s1[i]=='B') cak+=2;
		c1[i+1]=cak;
	}
	cak=0;
	for(int i=0;i<s2.length();i++){
		if(s2[i]=='A') cak++;
		if(s2[i]=='B') cak+=2;
		c2[i+1]=cak;
	}
	cin >> q ;
	while(q--){
		cin >> a >> b >> c >> d ;
		if((c1[b]-c1[a-1]-c2[d]+c2[c-1])%3==0) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 2432
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		int e = sc.nextInt();

		int result =0;
		int minTime =10;

		int aResult = result(a);
		int bResult = result(b);
		int cResult = result(c);
		int dResult = result(d);
		int eResult = result(e);

		minTime = Math.min(minTime, a%10==0?10:a%10);
		// System.out.println(minTime);
		minTime = Math.min(minTime, b%10==0?10:b%10);
		// System.out.println(minTime);
		minTime = Math.min(minTime, c%10==0?10:c%10);
		// System.out.println(minTime);
		minTime = Math.min(minTime, d%10==0?10:d%10);
		// System.out.println(minTime);
		minTime = Math.min(minTime, e%10==0?10:e%10);
		// System.out.println(minTime);
		if(minTime==10){
			minTime=10;
		}

		result += aResult;
		// System.out.println(result);
		result += bResult;
		// System.out.println(result);
		result += cResult;
		// System.out.println(result);
		result += dResult;
		// System.out.println(result);
		result += eResult;
		// System.out.println(result);
		result += minTime-10;
		System.out.println(result);

	}

	private static int result(int a) {
	if(a%10!=0){
		return a/10 *10 +10;
	}
	return a;
	}
}



Measured memory_bytes: 22996
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //b
  int a, b;
  cin >> a >> b;
  string s, t;
  for (int i = 0; i < a; i++) s += b + '0';
  for (int i = 0; i < b; i++) t += a + '0';
  cout << min(s, t) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int small = 1000000001;
  int result = 0;
  for(int i=0; i != n; ++i){
    int temp;
    cin >> temp;
    if(temp%2 == 1){
      small = 0;
      cout << small <<endl;
      return 0;
    }
    result = 0;
    while(temp%2 == 0){
      temp /= 2;
      result++;
    }
    if(result < small) small = result;
  }


  
  cout << small <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
int maxl=128,L,cnt;
using namespace std;
vector<char> alp;
vector<string> S;
int que;
int query(string s){
	cout<<"? "<<s<<endl<<flush;cin>>que;return que;
}
string str,x,y,xy,as;
bool cmp(string a,string b){return a.size()>b.size();}
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	for(int i='a';i<='z';i++) alp.push_back(i);
	for(int i='A';i<='Z';i++) alp.push_back(i);
	for(int i='0';i<='9';i++) alp.push_back(i);
	for(int i=0;i<62;i++){
		str="";
		for(int j=0;j<maxl;j++) str+=alp[i];
		cnt=query(str);
		cnt=maxl-cnt;
		L+=cnt;
		str="";
		for(int j=0;j<cnt;j++) str+=alp[i];
		S.push_back(str);
	}
	while(S.size()>=2){
		sort(S.begin(),S.end(),cmp);
		if(S.back().size()==0){
			S.pop_back();
			continue;
		}
		x=S.back();S.pop_back();
		y=S.back();S.pop_back();
		xy="";
		while(x.size()&&y.size()){
			as=xy+y[0]+x;
			cnt=query(as);
			if(cnt+as.size()==L){
				xy+=y[0];
				y.erase(y.begin());
			}
			else{
				xy+=x[0];
				x.erase(x.begin());
			}
		}
		xy+=x;xy+=y;
		S.push_back(xy);
	}
	cout<<"! "<<S[0]<<endl;
	return 0;
}


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

#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define ll long long
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9;
ll INF = 2e18;
const int mod = 1e9+7;
const int N = 22;
int n;

vvi dp(N,vi(1<<N,-1));
vvi a(N,vi(N));
int solve(int r,int mask){
	if(r==n){
		return mask==0;
	}
	if(dp[r][mask] == -1){
		dp[r][mask] = 0;
		for(int i=0;i<n;++i){
			if(a[r][n-1-i]==1 && mask&(1<<i)){
				dp[r][mask] += solve(r+1,mask^(1<<i));
				dp[r][mask] %= mod;
			}
		}
	}
	return dp[r][mask];
}

int main(){
	cin >> n;
	rep(i,n){
		rep(j,n){
			cin >> a[i][j];
		}
	}
	cout<<solve(0,(1<<n)-1)<<endl;
	return 0;
}

Measured memory_bytes: 377216
import sys
input=sys.stdin.readline
n,x=map(int,input().split())
BLU=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    b,l,u=BLU[i]
    BLU[i].append(l*b+u*(x-b))
BLU.sort(key=lambda x: -x[3])
acc=0
Acc=[0]*(n+1)
for i in range(n):
    acc+=BLU[i][3]
    Acc[i+1]=acc
s=sum(-BLU[i][1]*BLU[i][0] for i in range(n))

def judge(k):
    q=k//x; r=k%x
    t=0
    if r==0:
        if Acc[q]+s>=0:
            return True
        return False
    for i in range(n):
        t=score(i,q,r)
        if t+s>=0:
            return True
    return False

def score(a,q,r):
    b,l,u,f=BLU[a]
    if r<=b:
        t=l*r
    else:
        t=l*b+u*(r-b)
    if a<=q-1:
        t+=Acc[q+1]-f
    else:
        t+=Acc[q]
    return t

l=0; r=n*x
if judge(0):
    r=0
while l+1<r:
    k=(l+r)//2
    if judge(k):
        r=k
    else:
        l=k
print(r)

Measured memory_bytes: 64360
n = int(input())
s = list(input())
ABC = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ABC2 = ABC*3
answer = []
for i in s:
    k = ABC.index(i)
    answer.append(ABC2[k+n])

print("".join(answer))

Measured memory_bytes: 39792
# AtCoder
N = int(input())
A = list(map(int, input().split()))

ans = 0
s = 0
m = float('inf')

for i in A:
    i = abs(i)
    s += i
    m = min(m, i)

minus_num = len(list(filter(lambda x: x < 0, A)))

if minus_num % 2 == 0:
    print(s)
else:
    print(s-2*m)


Measured memory_bytes: 14224
#include <stdio.h>

int main(void)
{
	long N, M;
	long ans = 0;

	scanf("%ld %ld", &N, &M);

	if ((2 * N) >= M)
	{
		ans = M / 2;
		N = N - M / 2;

	}

	else
	{
		ans = N;
		M = M - 2 * N;
		ans = ans + M / 4;
	}

	printf("%ld", ans);

	return 0;

}



Measured memory_bytes: 128
#include <string>
#include<iostream>
#include <algorithm>
#include<sstream>
#include<list>
#include<math.h>
//#include <cstdio>
//#include <stdio.h>
using namespace std;                      


int cost(int x,int y){

    return pow((x-y),2);
}



int main ()
{
int N;

cin>>N;

int a[N];

for(int i =0;i<N;i++){
    cin>>a[i];
    
}

int ans=100000000;
for (int i=-100;i<=100;i++){
        int sum=0;
        for(int j=0;j<N;j++){
      sum=sum+cost(a[j],i);
        
        }


        if(ans>=sum ){
            ans=sum;
        }
}

cout<<ans;


return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
mod=10**9+7
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
n,a,b,c=map(int,input().split())
ans=0
aa,bb=a*pow(a+b,mod-2,mod),b*pow(a+b,mod-2,mod)
an,bn=pow(aa,n,mod),pow(bb,n,mod)
for i in range(n):
  ans+=(n+i)*(an*pow(bb,i,mod)+pow(aa,i,mod)*bn)*comb(n+i-1,i)
  ans%=mod
print((ans*100*pow(100-c,mod-2,mod))%mod)

Measured memory_bytes: 20812
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
 
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

/*bool operator<(const data &d)const{
	return hoge;
}*/
 
const int dx[]={0,1,1,-1,-1,0};
const int dy[]={1,1,0,0,-1,-1};
set<char>vowel={'a','i','u','e','o'};

int marume(int x){
	if(x>255)return 255;
	if(x<=0)return 0;
	return x;
}

int H;
vector<vector<int>>getJfen(string s){
	int W = 0;
	H = 0;
	rep(i,0,s.size()){
		if(s[i]=='/')break;
		if(s[i]=='b')W++;
		else W+=s[i]-'0';
	}
	rep(i,0,s.size())if(s[i]=='/')H++;
	vector<vector<int>>mat(H+1,vector<int>(W,0));
	int tate = 0,yoko = 0;
	rep(i,0,s.size()){
		if(s[i]=='b')mat[tate][yoko++] = 1;
		else if(s[i]=='/'){
			yoko=0;
			tate++;
		}else{
			yoko+=s[i]-'0';
		}
	}
	return mat;
}
 
signed main(){
	IOS();
	vector<string>ans;
	while(1){
		string s;
		cin>>s;
		if(s=="#")break;
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		auto banmen = getJfen(s);
		banmen[a-1][b-1]=0;banmen[c-1][d-1]=1;
		string t="";
		int spase;
		rep(i,0,H+1){
			spase = 0;
			rep(j,0,banmen[i].size()){
				if(banmen[i][j]==1){
					if(spase)t+=spase+'0';
					t+='b';
					spase = 0;
				}else spase++;
			}
			if(spase)t+=spase+'0';
			if(i!=H)t+='/';
		}
		ans.push_back(t);
	}
	for(auto e:ans){
		cout<<e<<endl;
	}
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    string c1, c2;
    cin >> c1 >> c2;
    reverse(c1.begin(), c1.end());
    if(c1 == c2)
    {
        cout << "YES" << endl;
    } else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>//C++のライブラリすべてinclude
#include<stdio.h>
#include<string>
#include<iostream>
#include<algorithm>
#include<queue>
#include<tuple>
#include<map>//map<char,char> a["a"]="a"
#include<limits>//ex numeric_limits<int>::max()
#include<math.h>
#define llong long long
#define INF 999999999
#define vvi vector< vector<int>>
//=vvi(sz, vector<int>(N, 0))= vector<vector<int>>(20, vector<int>(10, 0));
#define vvvi vector<vector<vector<int>>>
//= vector<vector<vector<int>>>(30, vector<vector<int>>(20, vector<int>(10, 0)));
using namespace std;

// int dp[][];

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

    int N,K;
    cin >> N >> K;
    vector<int> x(N);
    for (int i = 0; i < N; ++i)
    {
        cin >> x[i];
    }
    int mdis=INF;
    for (int i = 0; i <= N-K; ++i)
    {
        int u,d;
        u=x[i];d=x[i+K-1];
        int dis;
        if(u<=0 && 0<d){
            dis=min(abs(u), d)*2+max(abs(u),d);
        }else if(u<0){
            dis=abs(u);
        }else{
            dis=d;
        }
        mdis=min(mdis,dis);
    }
    cout << mdis<<endl;
}


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


void solve(long long A, long long B, long long H, long long M){
    double x1 = A * cos((H / 12.0 + M / 60.0 / 12) * 2 * M_PI);
    double y1 = A * sin((H / 12.0 + M / 60.0 / 12) * 2 * M_PI);
    double x2 = B * cos(M / 60.0 * 2 * M_PI);
    double y2 = B * sin(M / 60.0 * 2 * M_PI);
    // printf("%f %f %f %f\n", x1, y1, x2, y2);
    double ans = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    cout << std::fixed << std::setprecision(9) << ans << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long H;
    scanf("%lld",&H);
    long long M;
    scanf("%lld",&M);
    solve(A, B, H, M);
    return 0;
}


Measured memory_bytes: 4228
kingaku, n = input().split()
no_num = input().split()
ok_num = [str(i) for i in range(10) if not str(i) in no_num]
result = []
 
for i in kingaku:
    for j in ok_num:
        if i == j:
            result.append(j)
            break
        elif i < j:
            result.append(j)
            print("".join(result).ljust(len(kingaku), ok_num[0]))
            exit()
            break
    else:
        n = 1 if ok_num[0] == '0' else 0
        print(ok_num[n].ljust(len(kingaku)+1, ok_num[0]))
        exit()
 
print(''.join(result))

Measured memory_bytes: 9044
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        a: i32,
        b: i32,
        c: i32,
    }
    if b / a >= c {
        println!("{}", c);
    } else {
        println!("{}", b / a);
    }
}


Measured memory_bytes: 4352
a = [int(input())]
seen = {a[0]}
f = lambda n: 3 * n + 1 if n & 1 else n // 2
for i in range(2, 1000001):
    next = f(a[-1])
    if next in seen:
        print(i)
        exit()
    a.append(next)
    seen.add(next)
raise Exception('Something went wrong...')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define lg length()
#define pb push_back
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005

int n,a[20005],b[20005],p[20005],x;

int main(){
    cin >> n;
    for(int i=1;i<=n;i++) cin >> x,p[x]=i;
    for(int i=1;i<=n;i++){
        cout << 500000000+i*n+p[i] << ' ';
    }
    cout << '\n';
    for(int i=1;i<=n;i++){
        cout << 500000000-i*n << ' ';
    }
}


Measured memory_bytes: 768