akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <random>

using namespace std;

void pass(){
	return;
}

#define prev _prev
#define hash _hash;
#define rand() rand()<<15+rand()
typedef long long ll;
typedef unsigned long long ull;

mt19937 rnd(rand());
const int MOD = 1e9 + 7;
const ll BIG_MOD = 1e18 + 7;
const int MAXN = 1e5 + 7;


signed main(){
	cout.tie(NULL);
	cout.precision(20);
	//freopen("input.txt", "r", stdin);
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i += 2){
		cout << s[i];
	}

	return 0;
}

Measured memory_bytes: 592
/*
 _     _                             
| |__ | |__   __ _  __ _ _   _  __ _ 
| '_ \| '_ \ / _` |/ _` | | | |/ _` |
| |_) | | | | (_| | (_| | |_| | (_| |
|_.__/|_| |_|\__,_|\__, |\__, |\__,_|
                   |___/ |___/       
*/
#include<bits/stdc++.h>

#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;

#define N  100005

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{
		ll int a,b,m;
		cin>>a>>b>>m;
		ll int arr[a+1];
		ll int brr[b+1];
		for(ll int i=1;i<=a;i++) cin>>arr[i];
		for(ll int i=1;i<=b;i++) cin>>brr[i];
		ll int mini=1e18;
		for(ll int i=1;i<=m;i++)
		{
			ll int x,y,c;
			cin>>x>>y>>c;
			mini=min(mini,arr[x]+brr[y]-c);
		}	
		sort(arr+1,arr+1+a);
		sort(brr+1,brr+1+b);
		mini=min(mini,arr[1]+arr[1]);
		cout<<mini;
	}
	return 0;
}

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

int main() {
    int N,K;
    int sum=0,pos=0;
    int min,max;
    cin >> N >> K;
    vector<int> price(N);
    for(int i=0;i<N;i++){
        if(i==0){
            max = price.at(0);
        }
        cin >> price.at(i);
        if(price.at(i)>max){
            max = price.at(i);
        }
    }
    while(K>0){
        min = max;
        for(int i=0;i<N;i++){
            if(price.at(i)<=min && price.at(i)!=0){
                min = price.at(i);
                pos = i;
            }
        }
        sum += min;
        price.at(pos) = 0;
        K--;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, m: usize, a: [usize; m]);

    let sum = a.iter().sum::<usize>();
    let ans = if n < sum { -1 } else { (n - sum) as i64 };
    println!("{}", ans);
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    cout << a[n / 2] - a[n / 2 - 1];
    return 0;
}


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

long int gcd(long int x, long int y) {
  if (x < y) {
    return gcd(x, y - x);
  } else if (x > y) {
    return gcd(x - y, y);
  } else {
    return x;
  }
}

long int lcm(long int x, long int y) {
  return (x * y) / gcd(x, y);
}

int main() {
  long int a, b, c, d;
  cin >> a >> b >> c >> d;
  long int ans = b - a + 1;
  ans -= b / c - (a - 1) / c;
  ans -= b / d - (a - 1) / d;
  ans += b / lcm(c, d) - (a - 1) / lcm(c, d);
  cout << ans << endl;
}


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

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();
        int m = cin.nextInt();

        var unionFind = new UnionFindTree(n);

        for (int i = 0; i < m; ++i)
        {
            int x = cin.nextInt();
            int y = cin.nextInt();
            int z = cin.nextInt();

            unionFind.Unite(x, y);
        }

        int[] foundRoot = new int[n + 1];
        int count = 0;

        for (int i = 1; i <= n; ++i)
        {
            int root = unionFind.Root(i);

            if (foundRoot[root] == 0)
            {
                foundRoot[root] = 1;
                ++count;
            }
        }

        Console.WriteLine(count);
    }
}

class UnionFindTree
{
    int[] parent;

    public UnionFindTree(int n)
    {
        parent = new int[n + 1];

        for (int i = 0; i <= n; ++i)
        {
            parent[i] = i;
        }
    }

    public int Root(int x)
    {
        // これ、再帰で回してスタックオーバーフロー出ない？（デフォルトで１MB）
        // （↑子供それぞれの親の値は、このRoot関数を呼んだときに総親の値に書き換えられるので、絶対大丈夫）
        if (parent[x] == x) { return x; }
        return parent[x] = Root(parent[x]);
    }

    public void Unite(int x, int y)
    {
        int rootX = Root(x);
        int rootY = Root(y);
        if (rootX != rootY)
        {
            parent[rootX] = rootY;
        }
    }

    public bool Same(int x, int y)
    {
        return Root(x) == Root(y);
    }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 17280
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    int N;
    cin >> N;
    vector<int> h(N);
    REP(i, N) cin >> h[i];
    int ans = 0;
    for (int cur = 1; cur <= 100; ++cur)
    {  
        int numgroup = 0;
        bool chain = false;
        bool ok = false;
        REP(i, N)
        {
            if (h[i] >= cur)
            {
                ok = true;
                if (!chain)
                {
                    chain = true;
                    ++numgroup;
                }
            }
            else
            {
                if (chain)
                {
                    chain = false;
                }
            }
        }
        if (!ok) break;
        ans += numgroup;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <stdio.h>
#include <limits.h>

int main(int argc, char **argv)
{
    int n;
    scanf("%d", &n);

    int max = 0;
    int min = INT_MAX;
    for (int i = 0; i < n; ++i) {
        int a;
        scanf("%d ", &a);
        if (a > max) {
            max = a;
        }
        if (a < min) {
            min = a;
        }
    }
    int dist = max - min;
    printf("%d", dist);
    return 0;
}

Measured memory_bytes: 128
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
A = readInts()
m = max(A)
nya = m
mid = m/2
for i in range(n):
    if abs(A[i] - mid) <= nya:
        nya = abs(A[i]-mid)
        k = A[i]
print(m,k)


Measured memory_bytes: 21556
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(int argc, const char * argv[]) {
    int n, s;
    cin >> n >> s;
    
    int ans=0;
    for(int x=0; x<=n; x++){
        for(int y=0; y<=n; y++){
            int z=s-(x+y);
            
            if(0<=z && z<=n){
                ans++;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator sl
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
    FAST;
    LL n,m,i,j,k,p,q,o,l,s,t,z;
    string a,b;
    cin>>a>>b;
    for(i=0;b[i];i++)
    {
        cout<<a[i]<<b[i];
    }
    if(a.SZ>b.SZ)
    {
        cout<<a[i];
    }
    cout<<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X;
    vector<int> cd;
    cin >> X;
    int x=sqrt(X);
    int size=2*x+1;
    long long n[size];
    n[0]=0;
    for(int i=-x+1; i<=x; i++){
        n[i+x] = n[i+x-1]+5*i*i*i*i+10*i*i*i+10*i*i+5*i+1;
    }
    long long target;
    int from,to;
    int ans1,ans2,ansflag=0;
    for(int i=0; i<size; i++){
        target=n[i]+X;
        from=i;
        to=size-1;
        while(1){
            if(n[(to+from)/2]<target){
                if(from>=to) break;
                from=(to+from)/2+1;
            }else if(n[(to+from)/2]>target){
                if(from>=to) break;
                to=(to+from)/2-1;
            }else{
                ansflag=1;
                ans2=i-x+1;
                ans1=(to+from)/2-x+1;
                break;
            }
        }
        if(ansflag) break;
    }
    cout << ans1 << " " << ans2;
    return 0;
}


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

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

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

    int n;
    cin >> n;
    map<int, int> mp;

    roop(i, n-1){
        int x; cin >> x;
        mp[x-1]++;
    }

    roop(i, n){
        cout << mp[i] << endl;
    }

    return 0;
}

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


int main()
{
    int n,x,y;
    cin >> n;
    cin >> x;
    int ct =0;
    int res =0;
    for(int i = 1; i < n; ++i)
    {
        cin >> y;
        if(y <= x)
            ct++;
        else
        {
            res = max(res,ct);
            ct=0;
        }
        x= y;
    }
    res = max(res, ct);
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(x-a>0 && x-b>0 && x-a>x-b) cout<<"B\n";
    else if(x-a>0 && x-b>0 && x-a<x-b) cout<<"A\n";
    else if(x-a<0 && x-b>0 && a-x<x-b) cout<<"A\n";
    else if(x-a<0 && x-b>0 && a-x>x-b) cout<<"B\n";
    else if(x-a<0 && x-b<0 && a-x>b-x) cout<<"B\n";
    else if(x-a<0 && x-b<0 && a-x<b-x) cout<<"A\n";
    else if(x-a>0 && x-b<0 && x-a<b-x) cout<<"A\n";
    else if(x-a>0 && x-b<0 && x-a>b-x) cout<<"B\n";
    return 0;


}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
long long Read() {
    long long x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9') {
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
int main(){
	int a=Read(),b=Read(),c=Read(),d=Read();
	if(a+b==c+d) cout<<"Balanced"<<endl;
	if(a+b>c+d) cout<<"Left"<<endl;
	if(a+b<c+d) cout<<"Right"<<endl;
	return 0;
}

Measured memory_bytes: 256
s=input()

if s=='RRR':
    print(3)
if s=='RRS':
    print(2)
if s=='RSR':
    print(1)
if s=='SRR':
    print(2)
if s=='RSS':
    print(1)
if s=='SSS':
    print(0)
if s=='SRS':
    print(1)
if s=='SSR':
    print(1)


Measured memory_bytes: 9052
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
  vector<int> v;
  int n,r;
  int p,c;
  while(true) {
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    v.clear();
    for(int i = 0; i < n; i++)
      v.push_back(i + 1);
    for(int i = 0; i < r; i++) {
      cin >> p >> c;
      p -= 1;
      rotate(v.rbegin(), v.rbegin() + p, v.rbegin() + p + c);
    }
    cout << v.back() << endl;
  }
  return 0;
}

Measured memory_bytes: 2992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int h,w;
int fie[11][11];
int data[11][11];
int sum[11][11];

int C(int y1,int y2,int x1,int x2,int xx){
	for(int i=x1;i<=x2;i++){
		if(data[y1][i]==1)return 0;
		if(data[y2][i]==1)return 0;
	}
	for(int i=y1;i<=y2;i++){
		if(data[i][x1]==1)return 0;
		if(data[i][x2]==1)return 0;
	}
	int res=0;
	for(int i=y1+1;i<y2;i++){
		for(int j=x1+1;j<x2;j++){
			if(data[i][j]==0)return 0;
			res+=xx-fie[i][j];
		}
	}
	return res;
}

int solve(){
	int res=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			data[i][j]=1;
		}
	}
	for(int cc=9;cc>=1;cc--){
		for(int j=0;j<h;j++){
			for(int k=0;k<w;k++){
				data[j][k]=(fie[j][k]<cc);
			}
		}
		for(int i=0;i<h;i++){
			for(int j=i+2;j<h;j++){
				for(int k=0;k<w;k++){
					for(int l=k+2;l<w;l++){
						res=max(res,C(i,j,k,l,cc));
					}
				}
			}
		}
	}
	return res;
}

int main(void){
	while(1){
		scanf("%d%d",&h,&w);
		if(h==0 && w==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf("%d",&fie[i][j]);
			}
		}
		printf("%d\n",solve());
	}
	return 0;
}

Measured memory_bytes: 3212
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools

import queue
from collections import deque



def main():
    num = int(input())
    s = list(input())
    ans = 0
    for i in range(1, num)[::-1]:
        if s[i] == s[i - 1]:
            ans += 1

    print(len(s) - ans)






if __name__ == '__main__':
    main()


Measured memory_bytes: 50156
import itertools

n, m, x = list(map(int, input().split()))
all_list = []
for i in range(n):
    tmp = list(map(int, input().split()))
    all_list.append(tmp)

ok = False
cur_price = (10 ** 5) * n + 1
for i in range(1, n + 1):
    answers = list(itertools.combinations(range(n), i))
    # print(answers)
    for ans_list in answers:
        sum_list = [0] * (m + 1)
        # print(sum_list)
        for ans in ans_list:
            # print(all_list[int(ans[0])])
            sum_list = [a + b for a, b in zip(sum_list, all_list[int(ans)])]
        # print(sum_list)
        if min(sum_list[1:]) >= x:
            if sum_list[0] < cur_price:
                cur_price = sum_list[0]
                ok = True

if ok:
    print(cur_price)
else:
    print(-1)


Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}




int main() {
  ll a;
  string b;
  cin >> a >> b;
  ll b2=(b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
  cout << (a*b2)/100 << endl;
    
}

Measured memory_bytes: 3604
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }

#define INF 1 << 30
int t[8], t2, c;
int main() {
	int N, v;
	cin >> N;
	rep(i, 0, N) {
		cin >> v;
		if (v < 3200)t[v / 400]++;
		else t2++;
	}
	rep(i, 0, 8)if (t[i])c++;
	printf("%d %d\n", max(c, 1),(c + t2));
	return 0;
}


Measured memory_bytes: 256
mod = (1e9 + 7).to_i
n = gets.chomp.to_i
arr = gets.chomp.split(' ').map(&:to_i)
sum = arr.inject(:+)
res = 0
n.times do |i|
  sum -= arr[i]
  res += arr[i] * sum
  res %= mod
end
puts res.to_i


Measured memory_bytes: 36064
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmax(T &a, T b) { if (a < b) a = b; return; }
template<typename T> inline void chmin(T &a, T b) { if (a > b) a = b; return; }

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

  int n, m; cin >> n >> m;
  vector<int64> a(n), b(m), c(m);
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < m; ++i) cin >> b[i] >> c[i];

  sort(a.begin(), a.end());
  //rep(i,n)debug(a[i]);
    
  vector<pll> v;
  for (int i = 0; i < m; ++i) v.emplace_back(c[i], b[i]);
  sort(v.rbegin(), v.rend());

  vector<int64> t;
  int pos = 0;

  while (pos < m && (int) t.size() < n) {
    for (int i = 0; i < v[pos].second; ++i) {
      t.push_back(v[pos].first);
    }
    ++pos;
  }

  if ((int) t.size() < n) {
    for (int i = 0; i < n - (int) t.size(); ++i) {
      t.push_back(0);
    }
  } else {
    //sort(rall(t));
    t.resize(n);
  }
  //sort(rall(t));
  //rep(i, n)debug(t[i]);
  for (int i = 1; i < n; ++i) {
    a[i] += a[i - 1];
    t[i] += t[i - 1];
  }

  int64 ans = a[n - 1];

  for (int i = 0; i < n; ++i) {
    chmax(ans, a[n - 1] - a[i] + t[i]);
  }

  print(ans);

  return 0;
}

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

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C, X, Y;
            string[] str = Console.ReadLine().Split(' ');
            A = int.Parse(str[0]);
            B = int.Parse(str[1]);
            C = int.Parse(str[2]);
            X = int.Parse(str[3]);
            Y = int.Parse(str[4]);

            int totalPlice = 0;

            // 組み換えがやすい場合
            if (A + B > C * 2)
            {
                // 少ないピザを生成
                int minPizzaNumber = (X > Y) ? Y : X;
                totalPlice += minPizzaNumber * C * 2;
                // 残ったピザを生成
                totalPlice += (A < C * 2) ? (X - minPizzaNumber) * A : (X - minPizzaNumber) * C * 2;
                totalPlice += (B < C * 2) ? (Y - minPizzaNumber) * B : (Y - minPizzaNumber) * C * 2;
            }
            else
            {
                // A
                totalPlice += A * X;
                // B
                totalPlice += B * Y;
            }
            Console.WriteLine(totalPlice);
        }
    }
}


Measured memory_bytes: 11092
A, B = map(int, input().split())

def f(c, i):
    if c == 0: return 0
    if i == 1:
        tmp = (c + 1) // 2
    else:
        tmp = max(0, (c + 1) % (2 ** i) - 2 ** i // 2)
    # print(c, i, tmp)
    return tmp % 2

ret = ""

for i in range(1, 45 + 1):
    # interval -> 2 ** (i + 1)
    val = (f(B, i) - f(max(0, A - 1), i)) % 2
    ret += str(val)

ret = list(map(str, ret))
ret.reverse()
ret = "".join(ret)
# print(ret)
print(int(ret, 2))

Measured memory_bytes: 38740
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int inf =1e6+9;
int n,a[inf];

bitset<inf> bs;
vector <int > primes;
int sieve_size,g;
void sieves()
{
    sieve_size=1e3;
    bs.set();
    bs[0]=bs[1]=0;
    for(int i=2; i<=sieve_size; i++)
    {
        if(bs[i])
        {
            for(int j=i*i; j<=sieve_size; j+=i)
                bs[j]=0;
            primes.push_back((int )i);
        }
    }
}

bool valid[inf];

void check(int x){
     if(valid[x] )
            {
                if(g==1)
                    puts("setwise coprime"),exit(0);
                else
                    puts("not coprime"),exit(0);
            }
            valid[x]  = 1;
}

int main()
{
    sieves();
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",a+i);
     g = a[1];
    for(int i=2; i<=n; i++)
        g = __gcd(g,a[i]);

    for(int i=1; i<=n; i++){

        for(auto o:primes){
            if(o > a[i] || a[i] % o )
                continue;
            check(o);
            while( (a[i]%o) == 0 )
                a[i] /= o;
        }
        if(a[i] != 1)
            check(a[i]);
    }
    puts("pairwise coprime");
}


Measured memory_bytes: 7668
#include<iostream>
using namespace std;
int main()
{
   int n,l1,r1,s=0;
   cin>>n;
   for(int i=0;i<n;i++)
   {
          cin>>l1>>r1;
          s+=r1-l1+1;
   }
   cout<<s;

   return 0;
}


Measured memory_bytes: 256
n,k = map(int, input().split())
x = list(map(int, input().split()))

ans = float("inf")
for i in range(n-k+1):
  l = abs(x[i]) + abs(x[i]-x[i+k-1])
  r = abs(x[n-1-i]) + (x[n-1-i]-x[n-k-i])
  ans = min(ans,l,r)
print(ans)

Measured memory_bytes: 20048
h, w = map(int, input().split())
a = [input() for _ in range(h)]

b = []
for i in range(h):
    if "#" in a[i]:
        b.append(a[i])


c = [list(x) for x in zip(*b)]
ans = []
for i in range(len(c)):
    if "#" in c[i]:
        ans.append(c[i])
        
ans = [list(x) for x in zip(*ans)]
for v in ans:
    print("".join(v))

Measured memory_bytes: 64056
#include<iostream>
#include<algorithm>
using namespace std;
int n,w[101],v[101],ww,dp[101][10001];;
int dps(){
    for(int i=0;i<=ww;i++){
        if(i<w[0])dp[0][i]=0;
        else dp[0][i]=v[0];
    }
    for(int i=1;i<n;i++){
        for(int j=0;j<=ww;j++){
            if(j<w[i])dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],v[i]+dp[i-1][j-w[i]]);
        }
    }
    return dp[n-1][ww];
}
int main(){
    cin>>n>>ww;
    for(int i=0;i<n;i++){
        cin>>v[i]>>w[i];
    }
    dps();
    cout<<dp[n-1][ww]<<endl;
}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using P = pair<ll,ll>;
//Write From this Line

int main()
{
	ll n;
	cin >> n;
	vector<ll> a(n+1);
	rep(i, n+1)cin>>a[i];
	vector<P> mp(100010);
	ll child;
	for(ll i = n; i >= 0; i--){
		if(i == n) mp[i] = {a[i],a[i]};
		else {
			mp[i] = {(mp[i+1].first+1)/2 + a[i], mp[i+1].second + a[i]};
		}
	}
	if(mp[0].first != 1) {
		cout << -1 << endl;
		return 0;
	}
	ll ans = 1;
	ll now = 1;
	for(ll i = 1; i <= n;i++){
		ll plu = min(mp[i].second, 2 * now);
		ans += plu;
		now = plu - a[i];
	}
	cout << ans << endl;
}


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

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

int main(void){

    int N;
    cin >> N;
    N %= 10;

    if(N == 3){
        cout << "bon\n";
    } else if(N == 0 || N == 1 || N == 6 || N == 8){
        cout << "pon\n";
    } else {
        cout << "hon\n";
    }

    return 0;
}

Measured memory_bytes: 3620
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    k,n=map(int,input().split())
    A=[int(_) for _ in input().split()]
    max_len=(k-A[-1])+A[0]
    for i in range(n-1):
        max_len=max(max_len,A[i+1]-A[i])
    print(k-max_len)

if __name__=='__main__':
    main()

Measured memory_bytes: 26444
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;

int main() {
  ll n;
  cin >> n;
  vector<ll> vec;

  ll a = 2;
  while (n!=1) {
    if (n/a < a) {
      if (a <= n)
        vec.push_back(n);
      break;
    }
    else if (n / a * a == n) {
      vec.push_back(a);
      n /= a;
    }
    else
      ++a;
  }

  ll s = 1;
  ll ans = 0;
  ll c = 0;
  ll t = 0;
  for (auto &v : vec) {
    if (s != v) {
      s = v;
      ans += 1;
      c = 0;
      t = 2;
    }
    else {
      c += 1;
      if (c == t) {
        ans += 1;
        c = 0;
        t += 1;
      }
    }
  }

  cout << ans << endl;
}

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

using namespace std;

const int mod = 1e9 + 7;

class BinomialCoefficients{
  int max;
  int mod;
  long long *factorial;
  long long *factorial_inverse;
  long long *inverse;

public:
  int get(int n, int k){
    if(n < 0 || k < 0 || k > n) return 0;
    else return factorial[n] * (factorial_inverse[k] * factorial_inverse[n - k] % mod) % mod;
  }

  BinomialCoefficients(int max = 3000000, int mod = 1000000007) : max(max), mod(mod){
    factorial = new long long[max + 1];
    factorial_inverse = new long long[max + 1];
    inverse = new long long[max + 1];

    factorial[0] = factorial[1] = 1;
    factorial_inverse[0] = factorial_inverse[1] = 1;
    inverse[1] = 1;

    for(int k = 2; k <= max; k++){
      factorial[k] = factorial[k - 1] * k % mod;
      inverse[k] = mod - inverse[mod % k] * (mod / k) % mod;
      factorial_inverse[k] = factorial_inverse[k - 1] * inverse[k] % mod;
    }
  }

  ~BinomialCoefficients(){
    delete [] factorial;
    delete [] factorial_inverse;
    delete [] inverse;
  }
};

constexpr long long power(long long b, long long e, long long mod){
  long long ret = 1;
  while(e){
    if(e & 1){
      ret *= b;
      ret %= mod;
    }

    b *= b;
    b %= mod;
    e >>= 1;
  }

  return ret;
}

constexpr long long power(long long b, long long e){
  return power(b, e, mod);
}

int main(){
  int K;
  cin >> K;
  
  string S;
  cin >> S;
  
  int n = S.size();
  
  BinomialCoefficients binom;
  
  long long ans = 0;
  for(int k = 0; k <= K; k++){
    ans += binom.get(n + k - 1, k) * power(25, k) % mod * power(26, K - k) % mod;
    ans %= mod;
  }
  
  if(ans < 0) ans += mod;
  
  cout << ans << endl;
  
  return 0;
}

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

int find_sumation_individual_digits(int n){
    int sum = 0;
    while(n > 0){
        sum = sum + (n % 10);
        n = n / 10;
    }
    return sum;
}

int main() {
    int N,A ,B;
    cin >> N >> A >> B ;
    int sumation=0;
    for(int i=1; i<=N;i++){
        int dig_sum = find_sumation_individual_digits(i) ;
        if( (A <= dig_sum)&&( dig_sum <= B)){
            sumation = sumation + i;
        }
    }
    cout << sumation << endl;
}

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

int main() {
  long long N;
  cin >> N;
  vector<long long> divisor;
  for (long long i = 1; i * i <= N; i++) {
    if (N % i == 0) {
      divisor.push_back(i);
      if (i * i != N) {
        divisor.push_back(N / i);
      }
    }
  }
  long long temp;
  long long ans = 0;
  for (unsigned long long i = 0; i < divisor.size(); i++) {
    temp = divisor[i] - 1;
    if (temp != 0 && N % temp == N / temp) ans += temp;
  }
  cout << ans;
}

Measured memory_bytes: 384
import math

x, y = map(int, input().split())

def cmb(n, r, p):
    if r < 0 or n < r:
        return 0
    r = min(r, n - r)
    return (fact[n] * factinv[r] * factinv[n-r]) % p

p = 10 ** 9 + 7
N = 10 ** 6
fact = [ 1, 1]
factinv = [1, 1]
inv = [0, 1]

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
    
a = (2*y-x)/3
b = (2*x-y)/3
if a != int(a) or b != int(b) or a < 0 or b < 0 or (a == 0 and b == 0):
    print(0)
else:
    print(cmb(int(a+b), int(a), p))

Measured memory_bytes: 121836
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n;
  m=0;
  vector<int64_t>a(n);
  for (int i=0;i<n;i++) {
    cin >> a.at(i); 
  }
  for (int i=0;i<n;i++) {
    for (int j=0;j<n;j++) {
      for (int k=0;k<n;k++) {
        if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i] && a[i]!=a[j] && a[i]!=a[k] && a[k]!=a[j]){
          m++;
        }
      } 
    }
  }
  cout << m/6 << endl;
}

Measured memory_bytes: 3636
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+10,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

ll n;
ll f(ll x) {ll y=x; x*=x; x*=x; return y*x;}

map<ll,int> s;

int main() {
	qr(n);
	ll t=min(n,(ll)1e8);
	s[0]=0;
	for(register ll i=1;i<=t;i++) {
		if(s.count(f(i)-n)) pr1(i),pr2(s[f(i)-n]),exit(0);
		s[f(i)]=i;
		s[f(-i)]=-i; 
	}
	for(register ll i=1;i<=t;i++) 
		if(s.count(f(-i)-n)) pr1(-i),pr2(s[f(-i)-n]),exit(0);
	return 0;
}



Measured memory_bytes: 3660
import itertools

n, m, q = map(int, input().split())
l = []
ans = 0
ref = 0

for i in range(q):
    abcd = list(map(int, input().split()))
    l.append(abcd)

for i in itertools.combinations_with_replacement(range(1, m + 1), n):
    for j in range(q):
        if i[l[j][1] - 1] - i[l[j][0] - 1] == l[j][2]:
            ref += l[j][3]
    ans = max(ans, ref)    
    ref = 0

print(ans)

Measured memory_bytes: 9212
import java.util.*;
public class Main {
    public static class Pair{
        int coor;
        long h;
        public Pair(int x,int y) {
            this.coor=x;
            this.h=y;
        }
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int a = sc.nextInt();
        Pair[] pairs=new Pair[n];
        for (int i = 0; i < n; i++) {
            int x=sc.nextInt();
            int y=sc.nextInt();
            pairs[i]=new Pair(x,y);
        }
        long res=0;
        Arrays.sort(pairs,(b,c)->  (b.coor-c.coor));
        int[] diff=new int[n+1];
       for(int i=0;i<n;i++)
        {
            int j=bs(pairs,i,d);
            long need=Math.max((pairs[i].h+a-1-diff[i]*a)/a,0);
            res+=need;
            diff[i]+=need;
            diff[j]-=need;
            diff[i+1]+=diff[i];
        }
        System.out.println(res);
    }
    public static int bs(Pair[] pairs, int start, int d)
    {
        int end=pairs.length;
        int left=0;
        while(left<end){
            int mid=left+(end-left)/2;
            if(pairs[mid].coor-pairs[start].coor<=2*d)
            {
                left=mid+1;
            }
            else
            {
                end=mid;
            }
        }
        return left;
    }
}

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

int main(void) {
  long long N, K;
  cin >> N >> K;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  vector<long long> dist(N, -1);
  long long ans = 0;
  dist[0] = 0;
  while (K > 0) {
    K--;
    if (dist[A[ans]] != -1) {
      K %= dist[ans] - dist[A[ans]] + 1;
      ans = A[ans];
      break;
    } else {
      dist[A[ans]] = dist[ans] + 1;
      ans = A[ans];
    }
  }

  for (int i = 0; i < K; i++) {
    ans = A[ans];
  }
  cout << ans + 1 << endl;
  return 0;
}

Measured memory_bytes: 6400
#include <iostream>

using namespace std;

int const NMAX = 100;
int const WMAX = 1e5;

int n, weight;
int w[1 + NMAX], val[1 + NMAX];

long long dp[1 + NMAX][1 + WMAX];

int main() {
    cin >> n >> weight;
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> val[i];
    }

    dp[1][w[1]] = val[1];
    for(int i=2; i<=n; i++) {
        for(int j=0; j<=weight; j++) {
            dp[i][j] = dp[i-1][j];
        }
        for(int j=w[i]; j<=weight; j++) {
            dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + val[i]);
        }
    }
    long long maxVal = 0;
    for(int i=0; i<=weight; i++) {
        if(maxVal < dp[n][i]) {
            maxVal = dp[n][i];
        }
    }
    cout << maxVal;
    return 0;
}


Measured memory_bytes: 77568
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    string s;
    while(cin>>s){
        ll ans=0;  
        n=s.size();
        for(int i=0; i<n; ++i){
            if(s[i]!=s[n-i-1]){
                ++ans;
            }
        }
        ans/=2;
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 256
n = int(input())
i = 0
buf = 0
while 26**i+buf<=n:
    buf += 26**i
    i += 1
ans = ''
for j in range(i):
    ans += chr(ord('a')+(n//(26**j)-1)%26)
    n -= 26**j
print(ans[::-1])


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
main()
{
  
  long long n;
  cin>>n;
  vector<long long> b(n-1);
  for(int i=0;i<n-1;i++)cin>>b[i];
  vector<long long> a(n);
  a[0]=b[0];
  a[n-1]=b[n-2];
  for(int i=1;i<n-1;i++)
      {
        a[i]=min(b[i-1],b[i]);
        
      }
  long long ans=0;
  for(auto x:a)
    ans+=x;
  cout<<ans<<"\n";
    
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

ll a[MAXN],b[MAXN];

int main(void)
{
	int d,n;
	scanf("%d%d",&d,&n);
	for(int i=1; i<=n; ++i) scanf("%lld",&a[i]);
	
	for(int i=1; i<n; ++i)
		b[i] = a[i+1]-a[i];
	b[n] = d-a[n]+a[1];
	
	ll sum=0, mx=0;
	for(int i=1; i<=n; ++i)
	{
		sum += b[i];
		if(b[i]>mx) mx=b[i];
	}
	printf("%lld",sum-mx);
	return 0;
}

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

using namespace std;

const int MAXN = 2e5 + 5;

int n ;
string s ;

map<int , int> mp;

int main()
{
    cin>>n;
    int sol = 1;
    for(int i = 0;i<n;i++)
    {
        int t;
        cin>>t;
        if(mp[t]++)
            sol = 0;
    }
    cout<<(sol?"YES":"NO");
    return 0;
}


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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  int n, k;
  cin >> n >> k;
  ll ans = 0;
  while(n){
    n = n / k;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<pair<int, int>> p;
	long long as = 0, bs = 0, ans = 0;
	for(int i = 0; i < n; i++){
		int a, b;
		cin >> a >> b;
		p.push_back({a, i});
		p.push_back({b, i});
		as += a;
		bs += b;
	}
	ans = min(as, bs);
	sort(p.begin(), p.end());
	vector<int> e(n);
	for(int i = 0; i < n; i++){
		e[p[i].second] = 1;
	}
	if(find(e.begin(), e.end(), 0) == e.end()){
		int q1, q2, q3, q4, d1, d2;
		if(p[n - 1].second != p[n].second){
			q1 = n - 1, q2 = n;
		}else{
			q1 = n - 1, q2 = n + 1;
		}
		if(p[n - 2].second != p[n].second){
			q3 = n - 2, q4 = n;
		} else{
			q3 = n - 2, q4 = n + 1;
		}
		d1 = p[q2].first - p[q1].first;
		d2 = p[q4].first - p[q3].first;
		if(d1 <= d2) swap(p[q1], p[q2]);
		else swap(p[q3], p[q4]);
	}
	long long sum = 0;
	for(int i = 0; i < n; i++){
		sum += p[i].first;
	}
	ans = min(ans, sum);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2420
# Counterを使わずに
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
rod1 = 0
rod2 = 0
A = sorted(A)[::-1]
for i in range(len(A)-2):
    if rod1:
        i += 1
    #print(A[i],A[i+1])
    if A[i] == A[i+1]:
        if rod1:
            rod2 = A[i]
        else:
            rod1 = A[i]
    if rod1 and rod2:
        break

if (not rod1) and (not rod2):
    print(0)
else:
    print(rod1*rod2)

Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
#include <climits>
#define LIM 1000000007
#define ll long long
using namespace std;
int main() {
  string s;
  ll kk = 0;
  ll ii = 0;
  cin >> s;
  for (ll i = 0; i < s.size(); i++) {
    if (s[i] == 'A') {
      ii = i;
      break;
    }
  }
  for (ll i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'Z') {
      kk = i;
      break;
    }
  }
  cout << kk - ii + 1 << endl;
  return 0;
}



Measured memory_bytes: 640
#include <iostream>
using namespace std;
string s;
int visit[100001],cnt;
int sol(string x)
{
	for(int i=0; i<s.size(); i++)
	{
		string w;
		for(int j=0; j<x.size(); j++)
		{
			if(!visit[i+j])
			w+=s[i+j];
			else
			break;
		}	
		if(w==x)
		{
			for(int j=0; j<x.size(); j++)
			{
				visit[i+j]=1;
			}
		}
	}
}
int main()
{
	cin >> s;
	sol("eraser");
	sol("erase");
	sol("dreamer");
	sol("dream");
	
	for(int i=0; i<s.size(); i++)
	{
		if(visit[i])
		cnt++;
	}
	if(cnt==s.size())
	cout << "YES\n";
	else
	cout << "NO\n";
}

Measured memory_bytes: 896
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
struct edge { int to, dist, cost; };
bool operator<(const edge& e1, const edge& e2) { return e1.cost < e2.cost; }
int N, M, L, a1, a2, a3, a4;
int main() {
	while (cin >> N >> M >> L, N | M | L) {
		vector<vector<edge> > G(N);
		for (int i = 0; i < M; i++) {
			cin >> a1 >> a2 >> a3 >> a4; a1--, a2--;
			G[a1].push_back(edge{ a2, a3, a4 });
			G[a2].push_back(edge{ a1, a3, a4 });
		}
		vector<vector<int> > d(N, vector<int>(L + 1, 999999999)); d[0][L] = 0;
		priority_queue<edge> que; que.push(edge{ 0, L, 0 });
		while (!que.empty()) {
			edge u = que.top(); que.pop();
			for (edge e : G[u.to]) {
				if (u.dist >= e.dist) {
					int dist1 = u.dist - e.dist;
					int cost1 = -u.cost;
					if (d[e.to][dist1] > cost1) {
						d[e.to][dist1] = cost1;
						que.push(edge{ e.to, dist1, -cost1 });
					}
				}
				int dist2 = u.dist;
				int cost2 = -u.cost + e.cost;
				if (d[e.to][dist2] > cost2) {
					d[e.to][dist2] = cost2;
					que.push(edge{ e.to, dist2, -cost2 });
				}
			}
		}
		int ret = *min_element(d[N - 1].begin(), d[N - 1].end());
		cout << ret << endl;
	}
	return 0;
}

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
    int a, b, ans = 0;
    cin >> a >> b;

    REP(i,2){
        if(a > b){
            ans += a;
            a--;
        }else{
            ans += b;
            b--;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int a = sc.nextInt();
		if(a % 2 == 0) {
			System.out.println(a);
		} else {
			System.out.println(a * 2);
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 998244353;

struct mint {
    lint v;
    lint _mod;
    mint() : v(0) {}
    mint(signed v, lint _mod = mod) : v(v), _mod(_mod) {}
    mint(lint t, lint _mod = mod) : _mod(_mod) {
        v = t % _mod;
        if (v < 0)
            v += _mod;
    }

    mint pow(lint k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }
    mint inv() { return pow(_mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += _mod - a.v;
        if (v >= _mod)
            v -= _mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = v * a.v % _mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(_mod - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};
ostream &operator<<(ostream &os, mint m) { return os << m.v; }

struct Combination {
    vector<lint> fac, finv, inv;
    Combination(lint maxN) : fac(maxN + 100), finv(maxN + 100), inv(maxN + 100) {
        maxN += 100; // for safety
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1]            = 1;
        for (lint i = 2; i <= maxN; ++i) {
            fac[i]  = fac[i - 1] * i % mod;
            inv[i]  = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }
    lint operator()(lint n, lint k) {
        if (n < k)
            return 0;
        if (n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
    }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m, k;
    cin >> n >> m >> k;
    Combination nCk(400000);
    mint ret = 0;
    for (lint i = 0; i <= k; ++i) {
        mint t = nCk(n - 1, i);
        t *= mint(m - 1).pow(n - 1 - i);
        ret += t;
    }
    ret *= m;
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 12688
n = int(input())
  
l = []
s = {}
for i in range(n):
    c, m = input().split()
    if c[0] == 'i':
        s[m] = 0
    elif c[0] == 'f':
        if m in s:
            l.append('yes')
        else:
            l.append('no')
print(*l,sep='\n')

Measured memory_bytes: 47776
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define MAX 100005
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int x,a,b;
  cin>>x>>a>>b;
  cout<<(abs(a-x)<abs(b-x)?"A":"B")<<endl;
  return 0;
}


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

int main(void){
    map<ll, ll> number;
    ll n;
    cin >> n;

    rep(i, n){
        ll tmp;
        cin >> tmp;
        number[tmp]++;
    }

    ll count = 0;
    for(auto num: number){
        if(num.second % 2 != 0)
            count++;
    }

    cout << count << endl;
    return 0;
}


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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,k;
    cin>>n>>k;
    if(n==k)
    {
        cout<<0<<'\n';
        return 0;
    }
    if(n>k)
    {
        long long int ans = n%k;
        ans = min(ans,abs(k-ans));
        cout<<ans<<"\n";
    }
    else
    {
        long long int ans = min(n,abs(k-n));
        cout<<ans<<"\n";
        return 0;
    }
    
}

Measured memory_bytes: 3592
S = input()
words = ['dreameraser','dreamerase','dreamer','dream','eraser','erase']
i = 0
while i < len(S):
    update = False
    for w in words:
        if S[i:].startswith(w):
            i += len(w)
            update =True
            break
    if not update:
        break
print('YES' if i == len(S) else 'NO')

Measured memory_bytes: 9088