akhauriyash/Code-Regression huggingface dataset:
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ESecondSum {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n; cin >> n;
      vector<int> p(n);
      vector<int> pos(n+1);
      rep(i, n) {
        cin >> p[i];
        pos[p[i]] = i+1;
      }
      set<int> st;
      st.insert(0);
      st.insert(n+1);
      ll ans = 0;
      for(int i=n; i>=1; i--) {
        int idx = pos[i]; // position of i
        //if (st.empty()) continue;

        auto c = st.lower_bound(idx);
        auto d = c;
        d++;
        if (d == st.end()) {
          d--;
        }
        auto b = c;
        if (b != st.begin()) {
          --b;
        }
        auto a = b;
        if (b != st.begin()) {
          --a;
        }
        debug(*a, *b, idx, *c, *d);

        ll now = 0;
        now += ((*b)-(*a))*((*c)-(idx));
        now += ((*d)-(*c))*(idx-(*b));
        ans += now*i;
        st.insert(idx);
      }
      cout << ans << endl;
    }
};

signed main() {
  ESecondSum solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 5760
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

#define INF ((ll) 1e9)

int n, k, s;

int main() {
	cin >> n >> k >> s;
	for (int i = 0; i < k; i++) {
		cout << s << " ";
	}
	for (int i = k; i < n; i++) {
		if (s > n) {
			cout << "1 ";		
		} else {
			cout << INF << " ";
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
#include <set>
using namespace std;
int main(){
    int n,temp,k;
    set<int> s;
    scanf("%d",&n);
    while(n--){
        scanf("%d%d",&k,&temp);
        if(k==0){
            s.insert(temp);
            printf("%ld\n",s.size());
        }
        else{
            if(s.find(temp)==s.end())printf("0\n");
            else printf("1\n");
        }
    }
}


Measured memory_bytes: 12040
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
pii a[100010];
int b[100010],c[100010];
int main()
{
	int i,j,k,n,m,x,y,h=0;
	scanf("%d%d",&n,&m);
	for(i=0;i<n;i++)
	{
		scanf("%d%d",&a[i].se,&a[i].fi);
	}
	sort(a,a+n);
	reverse(a,a+n);
	ll ans=0,an;
	x=0;
	for(i=0;i<m;i++)
	{
		ans+=1ll*a[i].fi;
		if(b[a[i].se]==0)
		{
			x++;
			b[a[i].se]=1;
		}
		else
		{
			c[h]=i;
			h++;
		}
	}
	ans+=1ll*x*x;
	an=ans;
	for(i=m;i<n;i++)
	{
		if(b[a[i].se]==0)
		{
			if(h==0)
			{
				break;
			}
			b[a[i].se]=1;
			h--;
			x++;
			ans-=1ll*a[c[h]].fi;
			ans+=1ll*a[i].fi;
			ans+=2ll*x-1ll;
			an=max(an,ans);
		}
	}
	printf("%lld",an);
}

Measured memory_bytes: 1536
n = int(raw_input())
a = [0,0,0]
 
for i in range(n):
    a[0],a[1],a[2] = map(int,raw_input().split())
    a.sort()
    if a[0]**2 + a[1]**2 == a[2]**2:
        print("YES")
    else:
        print("NO")

Measured memory_bytes: 6256
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>

#define nl '\n';

using namespace std;

double k;

int main(){

    cin >> k;

    cout << floor((k/2) * (k/2));



}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

// char** arr = new char*[r];
// for(long long i = 0; i < r; i++) arr[i] = new char[c];

Measured memory_bytes: 256
def modpow(a, n, mod):
  res = 1
  while n > 0:
    if n & 1:
      res = res * a % mod
    a = a * a % mod
    n >>= 1
  return res

mod = 10**9 + 7
N = int(input())
print((modpow(10, N, mod) - 2*modpow(9, N, mod) + modpow(8, N, mod)) % mod)

Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        String s = sc.next();
        for (int i = 0; i < n; i++) {
            if (i == k - 1) {
                System.out.print(Character.toLowerCase(s.charAt(i)));
            } else {
                System.out.print(s.charAt(i));
            }
        }
        System.out.println();
    }
}

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

int main(){
    int n;cin >> n;
    vector<LL> v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    LL ans = 0;
    for(int k = 2;k < 50000;k++){
        LL t = 0;
        for(int i = 0 ;i < n;i++){
            if(v[i]%k==0) t += v[i];
        }
        ans = max(t,ans);
    }
    for(int i=0;i<n;i++){
        if(v[i]==1) continue;
        LL t = 0;
        for(int j=0;j<n;j++){
            if(v[j]%v[i]==0) t += v[j];
        }
        ans = max(t,ans);
    }
    cout << ans << endl;
    return 0;
}

            



Measured memory_bytes: 3088
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int q = sc.nextInt();
        long[] a = new long[n];
        long[] x = new long[q];
        for(int i=0; i<n; i++) a[i] = sc.nextLong();
        for(int i=0; i<q; i++) x[i] = sc.nextLong();
        sc.close();

        Arrays.sort(a);
        long[] taket = new long[n];
        taket[0] = Long.MAX_VALUE;
        int apos = 1;
        for(int i=1; i<n; i++){
            for(int j=apos; j<n; j++){
                if(j - i >= i){
                    taket[i] = (a[n-i-1] + a[n-j-1]) / 2;
                    apos = j;
                    break;
                }
            }
        }

        long[] asumr = new long[n];
        long[] asuml = new long[n];
        asumr[0] = a[n-1];
        asuml[0] = n%2==1 ? a[0] : a[1];
        for(int i=1; i<n/2 + n%2; i++){
            asumr[i] = asumr[i-1] + a[n-1-i];
            asuml[i] = asuml[i-1] + a[i*2 + 1 - n%2];
        }

        long[] taketr = new long[n];
        for(int i=0; i<n; i++){
            taketr[n-i-1] = taket[i];
        }

        for(int i=0; i<q; i++){
            int pos = Arrays.binarySearch(taketr, x[i]);
            if(pos < 0) pos = -pos - 1;
            int tr = Math.min(n/2+n%2, n-1-pos);
            int tl = n/2+n%2 - tr - 2;
            long sr = asumr[tr];
            long sl = tl >= 0 ? asuml[tl] : 0;
            System.out.println(sl + sr);
        }

    }
}

Measured memory_bytes: 93164
require 'pp'

def is_i?(string)
  string =~ /^[0-9]+$/
end
class Array
  def product
    self.inject(1) {|sum, elem| sum * elem}
  end
  def sum
    self.inject(0) {|sum, elem| sum + elem}
  end
end

h, w, n = $stdin.gets.chomp.split(" ").map(&:to_i)
cheese_map = h.times.map {[nil] + $stdin.gets.chomp.bytes.to_a.map(&:chr) + [nil]}
cheese_map.insert(h, Array.new(w + 2, nil))
cheese_map.insert(0, Array.new(w + 2, nil))

def bfs_search(map, start)
  directions = [[1, 0], [-1, 0], [0, 1], [0, -1]]
  queue = []
  map[start[:i]][start[:j]] = nil
  goal = start[:item] - 1
  queue.push({:pos => [start[:i], start[:j]], :counter => 0})
  until queue.empty? do
    item = queue.shift
    directions.each do |(i, j)|
      ny = item[:pos][0] + i
      nx = item[:pos][1] + j
      next_item = map[ny][nx]
      if (next_item == goal) then
        return item[:counter] + 1
      elsif (next_item == "." or next_item.is_a?(Numeric)) then
        queue.push({:pos => [ny, nx], :counter => item[:counter] + 1})
        map[ny][nx] = nil
      else next end
    end
  end
end

def deep_copy(object)
  Marshal.load(Marshal.dump(object))
end

cheeses = []

cheese_map.each_with_index do |line, i|
  line.each_with_index do |item, j|
    if is_i?(item) then
      cheeses << {:i => i, :j => j, :item => item.to_i}
      cheese_map[i][j] = item.to_i
    elsif (item == "S") then
      cheese_map[i][j] = 0
    end
  end
end

cheeses = cheeses.sort_by {|elem| elem[:item]}
result = cheeses.map do |cheese|
  bfs_search(deep_copy(cheese_map), cheese)
end.sum

puts result

Measured memory_bytes: 246880
#include "bits/stdc++.h"

#define REP(i,num) for(ll i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=ll>
T in(){T x; cin >> x; return (x);}
template<typename T=ll,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

template<typename T>
bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>
bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);

	ll N=in(),K=in();
	if(!K){
		out(N*N);
		return 0;
	}
	ll S=0;
	ll P=N-K;
	S += (1ll+P)*P/2ll;
	REP(i,N){
		ll V=i+1;
		if(V<=K) continue;
		ll U=N-V,T=V-K;
		S+=(U/V)*T;
		if(U%V>=K) S+=(U%V)-K+1ll;
	}

	out(S);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100100;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& e : a) cin >> e;
    
    int nin = *min_element(a.begin(), a.end());
    int nax = *max_element(a.begin(), a.end());
    
    if (nin + 1 < nax) {
        cout << "No" << endl;
    } else if (nin + 1 == nax) {
        auto f = [&] (int x) { return x == nin; };
        int nini = count_if(a.begin(), a.end(), f);
        int ncc = nax - nini; // 連結成分の個数
        if (n-nini >= ncc*2 && nini <= nin) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    } else {
        if (nin*2 <= n || nin  == n-1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    string s,t,u;
    cin >> s >> t >> u;
    s.at(0) -= 32;
    t.at(0) -= 32;
    u.at(0) -= 32;
    cout << s.at(0);
    cout << t.at(0);
    cout << u.at(0);
    cout << endl;
}

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

int main(){
    int A; cin >> A;
    int B; cin >> B;
    if(A>=13){
        cout << B << endl;
    }
    else if(6<=A && 12>=A){
        cout << B/2 << endl;
    }
    else{
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include <vector>
#include<queue>
#include <random>
using namespace std;



int main() {
	char a[9];
	for (int i = 0; i < 9; i++) {
		cin >> a[i];
	}
	cout << a[0] << a[4] << a[8] << endl;
	return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <stdio.h>
#include <sstream>


using namespace std;
void swap(int &a, int &b);

int main()
{
	// 探索する文字列
	string sAnswer;
	getline(cin, sAnswer);

	string sstr;// = {};
	
	int count = 0;

	//getline(cin, sstr);
	while (true)
	{
		cin >> sstr;
		if (sstr == "END_OF_TEXT")
			break;
		// 大文字を小文字に変換
		for (int i = 0; i < sstr.size(); ++i)
		{
			if (isupper(sstr[i]))
				sstr[i] = tolower(sstr[i]);
		}
		if (sstr == sAnswer)
			count++;

	}
	cout << count << endl;


	return 0;
}





Measured memory_bytes: 3168
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
ls = [0 for _ in range(len(a))]

tmp = 0
for i, v in enumerate(a):
    tmp += v
    ls[i] = tmp

length = ls[-1]
half = length // 2

cand = 2020202020
for l in ls[:-1]:
    cand = min(cand, abs(l * 2 - length))
print(cand)


Measured memory_bytes: 26396
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node{
	int key;
	Node *prev, *next;
};

Node* Nil;

void init(){
	Nil = (Node *)malloc(sizeof(Node));
	Nil->next = Nil;
	Nil->prev = Nil;
}

void insert(int key){
	Node* x = (Node *)malloc(sizeof(Node));
	x-> key = key;
	x->next = Nil->next;
	Nil->next->prev = x;
	Nil->next = x;
	x->prev = Nil;
}

Node* search(int key){
	Node* cur = Nil->next;
	while(cur != Nil && cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void delete_Node(Node* t){
	if(t == Nil) return;
	Node* s = t-> prev;
	Node* p = t-> next;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void delete_key(int key){
	delete_Node(search(key));
}

void delete_first(){
	delete_Node(Nil->next);
}
void delete_last(){
	delete_Node(Nil->prev);
}

void print_list(){
	Node* cur = Nil->next;
	int i=0;
	while(1){
		if(cur == Nil) break;
		if(i > 0) printf(" ");
		printf("%d", cur->key);
		i++;
		cur = cur-> next;
	}
	printf("\n");
}

int main(){
	int i, n, key;
	scanf("%d", &n);
	char s[20];
	init();
	for(i = 0; i < n; i++){
		scanf("%s%d", s, &key);
		if(s[0] == 'i') insert(key);
		if(s[0] == 'd'){
			if(strlen(s) > 6){
				if(s[6] == 'F') delete_first();
				if(s[6] == 'L') delete_last();
			}else{
				delete_key(key);
			}
		}
	}
	print_list();
}



Measured memory_bytes: 33932
main = getLine >>= putStrLn . solve . read

solve :: Int -> String
solve x = let h = x `div` 3600
              m = (x - h * 3600) `div` 60
              s = x - (h * 3600) - (m * 60)
           in (show h) ++ ":" ++ (show m) ++ ":" ++ (show s)


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

using pii = pair<int, int>;
using ll  = long long;
#define rep(i, j) for (int i = 0; i < (int)(j); i++)
#define repeat(i, j, k) for (int i = (j); i < (int)(k); i++)
#define all(v) v.begin(), v.end()
#define debug(x) cerr << #x << " : " << x << endl

template <class T>
bool set_min(T &a, const T &b) {
    return a > b ? a = b, true : false;
}
template <class T>
bool set_max(T &a, const T &b) {
    return a < b ? a = b, true : false;
}
// vector
template <class T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &a : v) is >> a;
    return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &t : v) os << "\t" << t;
    return os << endl;
}
// pair
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &v) {
    return os << "<" << v.first << ", " << v.second << ">";
}

const int INF = 1 << 30;
const ll INFL = 1LL << 60;



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

    int N, X, Y; cin >> N >> X >> Y;
    X--; Y--;
    vector<vector<int>> G(N, vector<int>(N));
    rep(i, N) rep(j, N) {
      if(i == j) G[i][j] = 0;
      else G[i][j] = abs(i - j);
      int a = min(abs(i - X), abs(i - Y));
      int b = min(abs(j - X), abs(j - Y));
      set_min(G[i][j], a + b + 1);
    }
    vector<int> cnt(N + 1);
    rep(i, N) repeat(j, i + 1, N) cnt[G[i][j]]++;
    repeat(k, 1, N) cout << cnt[k] << endl;
      
    
    
    return 0;
}


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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int N;
  cin >> N;
  bool prev = false;
  ll ans = 0;
  rep(i,N){
    ll A;
    cin >> A;
    if(prev == true){
      if(A > 0){
        A--;
        ans ++;
      }
    }

    if(A % 2 == 0){
      prev = false;
      ans += A/2;
    }else{
      prev = true;
      ans += A/2;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
from fractions import gcd
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
lcm = a[0]
for i in range(1,n):
  lcm = lcm*a[i] // gcd(lcm,a[i])
mod=pow(10,9)+7
ans=0
for x in a:
  ans+=lcm//x
print(ans%mod)


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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

ll dp[1100][5000];

void solve(){
    string S; cin >> S;
    int n = S.size();
    vector<int> vec;
    for(int i = 0; i < n-2; ++i){
        int a = (int)(S[i] - '0');
        int b = (int)(S[i+1] - '0');
        int c = (int)(S[i+2] - '0');
        int tmp = 100 * a + 10 * b + c;
        vec.push_back(abs(tmp-753));
    }
    sort(vec.begin(), vec.end());
    cout << vec[0] << endl;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		LinkedList<Integer> pit = new LinkedList<>();
		LinkedList<String> pfm = new LinkedList<>();

		int m = 0;
		int f = 0;
		int r = 0;
		
		//???????????\???
		int cnt = 0;
		while(m != -1 || f != -1 || r != -1) {
			m = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			if(m == -1 && f == -1 && r == -1) {
				break;
			} else {
				pit.add(m);
				pit.add(f);
				pit.add(r);
				cnt+=3;
			}
		}
		
		int k = 0;
		for(int i = 2; i < cnt; i+=3) {
			if(pit.get(i-2) == -1 || pit.get(i-1) == -1) {
				pfm.add("F");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 80) {
				pfm.add("A");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 65) {
				pfm.add("B");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 50) {
				pfm.add("C");
				k++;
			} else if(pit.get(i-2) + pit.get(i-1) >= 30) {
				if(pit.get(i) >= 50) {
					pfm.add("C");
					k++;
				} else {
					pfm.add("D");
					k++;
				}
			} else if(pit.get(i-2) + pit.get(i-1) < 30) {
				pfm.add("F");
				k++;
			}
		}
		
		for(int i = 0; i < k; i++) {
			System.out.println(pfm.get(i));
		}
	}
}

Measured memory_bytes: 26200
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad
import Control.Monad.Fix
import Data.Int
import Data.Foldable
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Set as S
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> VU.Vector Int -> Int
solve !n !an = maximum $ zipWith (+)
                                 (take (n + 1) $ drop n $ reverse calcSumAs)
                                 (take (n + 1) $ drop n $ calcSumBs)
 where
  ain = VU.imap (\(!i) (!a) -> (a, i)) an
  calc an = (\(_, _, !x) -> x) $ VU.foldl'
    (\(!heap, !s, !acc) (!ai, !i) ->
      let heap'        = S.insert (ai, i) heap
          (s', heap'') = if S.size heap' > n
            then
              let Just ((m, _), heap'') = S.minView heap'
              in  (s + ai - m, heap'')
            else (s + ai, heap')
      in  (heap'', s', s' : acc)
    )
    (S.empty, 0, [0])
    an

  calcSumAs = calc ain
  calcSumBs = calc $ VU.map (\(!ai, !i) -> (-ai, i)) $ VU.reverse ain

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n  <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  an <- VU.unfoldrN (3 * n) readInt <$> B.getLine
  print $ solve n an


Measured memory_bytes: 107132
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ph push
#define ptc putchar
#define enter putchar('\n')
#define mod 998244353
using namespace std;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef long long lnt;
inline int read(){
	int x = 0;char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + c - '0' , c = getchar();
	return x;
}
inline void write(int x){
	if (!x){
       ptc('0');
       return;
	}
	int dg[20] , len = 0;
	while (x) dg[len++] = x % 10 , x /= 10;
	while (len--) ptc(dg[len]+'0');
}
inline void writeln(int x){
	write(x);
	ptc('\n');
}
inline int add(int x,int y){
	x += y;if (x >= mod) x -= mod;
	return x;
}
inline int sub(int x,int y){
	x -= y;if (x < 0) x += mod;
	return x;
}
inline int qpow(int x,int y){
	int res = 1;
	while (y){
		if (y & 1) res = 1ll * res * x % mod;
		x = 1ll * x * x % mod;y >>= 1;
	}
	return res;
}
const int N = 1e5 + 10;
int n , m , d;
char s[N] , t[N];
long long answer , Lcm , SmallLcm , cur;

int main(){
	scanf("%d%d",&n,&m);
	scanf("%s%s",s,t);
	Lcm = 1ll * n * m / __gcd(n , m);
	d = __gcd(n , m);
	n /= d;
	m /= d;
	SmallLcm = 1ll * n * m;
	swap(n , m);
	
	answer = Lcm;
	while (cur != Lcm){
		if (s[cur / n] != t[cur / m]) {
//			printf("[%d] %d %d\n",cur,n);
			return puts("-1") ,0;
		}
		cur += SmallLcm;
	}
	cout<<answer;
	return 0;
}

Measured memory_bytes: 384
X = list(map(int,input().split()))
c=100000
b=200000
a=300000
X.sort()
ans=0
cnt=0
for i in X:
    if i==1:
        ans+=a
        cnt+=1
    elif i==2:
        ans+=b
    elif i==3:
        ans+=c
if cnt==2:
    ans += 400000
print(ans)

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

bool cond1 (string s) {

    return (s[0] == 'A');
}

bool cond2 (string s) {

    int c_cnt = 0;

    for (int i = 2; i < s.size() - 1; i++) {
        if (s[i] == 'C') {
            c_cnt++;
        }
    }

    return (c_cnt == 1);
}

bool cond3 (string s) {

    int small_cnt = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] >= 'a' && s[i] <= 'z') {
            small_cnt++;
        }
    }

    return (small_cnt == (s.size() - 2));
}

int main () {

    string S;
    cin >> S;

    if (cond1(S) && cond2(S) && cond3(S)) cout << "AC" << endl;
    else cout << "WA" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <map>
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 3e4 + 5;

int main(){
	int n;
	while(~scanf("%d", &n)){
		int sum = n / 3;
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    int n;
    cin >> n;

    if(n<2) cout << 1 << endl;
    else if(n<4)cout << 2 << endl;
    else if(n<8) cout << 4 << endl;
    else if(n<16) cout << 8 << endl;
    else if(n<32) cout << 16 << endl;
    else if(n<64) cout << 32 << endl;
    else cout << 64 << endl;

    return 0;
}


Measured memory_bytes: 3620
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <algorithm>
 
int main() {
    float A,B;
    scanf("%f %f",&A,&B);
    
    auto min8=ceil(A/.08);
    auto max8=floor((A+1)/.08);
    
    auto min10=ceil(B/.1);
    auto max10=floor((B+1)/.1);

    printf("%d\n",(int)(min8>=max10 || max8<=min10 ? -1 : std::max(min8,min10)));
}

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

int main(void){
    list<int> l;
    int q;
    cin >> q;
    int a, b;
    list<int>::iterator now=l.end();
    for(int i=0; i<q; i++){
        cin >> a;
        if(a==0){
            cin >> b;
            now=l.insert(now, b);
        }
        else if(a==1){
            cin >> b;
            if(b>0){
                for(int j=0; j<b; j++){
                    now++;
                }
            }
            else{
                for(int j=b; j<0; j++){
                    now--;
                }
            }
        }
        else{
            now=l.erase(now);
        }
    }
    for(auto i=l.begin(); i!=l.end(); i++){
        cout << *i << "\n";
    }
    
    return 0;
}



Measured memory_bytes: 18556
#include <stdio.h>

int Binary_Search( int , int, int* );

int main( void ){
	int i, n, q, count;
	
	scanf("%d", &n );
	
	int s[n+1];
	
	for( i = 0; i < n; i++ ){
		scanf("%d", &s[i] );
	}
	
	scanf("%d", &q );
	
	int t[q];
	
	for( i = 0; i < q; i++ ){
		scanf("%d", &t[i] );
	}
	
	count = 0;
	for( i = 0; i < q; i++ ){
		count += Binary_Search( n, t[i], s);
	}
	
	printf("%d\n", count );
	
	return 0;
}
	
int Binary_Search( int n, int key, int* s){
	int left, right, mid;
	
	left = 0;
	right = n;
	
	while( left < right ){
		mid = (left + right)/2;
		
		if( s[mid] == key ){
			return 1;
		}
		else if( key < s[mid] ){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}
	
	return 0;
} 


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

int main()
{
    int N;
    cin>>N;
    vector<int> V(N+1);
    vector<int> W(N+1);
    for (int i=1; i<=N; i++)
        cin>>V[i]>>W[i];

    int Q;
    cin>>Q;
    vector<int> v(Q);
    vector<int> L(Q);
    for (int i=0; i<Q; i++)
        cin>>v[i]>>L[i];

    int D = 0;
    while ((1<<D)-1<N)
        D++;
    int TD = D/2;
    if (TD==0)
        TD = 1;
    vector<vector<int>> T(1<<TD, vector<int>(100001));
    for (int i=W[1]; i<=100000; i++)
        T[1][i] = V[1];
    for (int i=2; i<1<<TD; i++)
        for (int j=0; j<=100000; j++)
        {
            T[i][j] = T[i/2][j];
            if (j>=W[i])
                T[i][j] = max(T[i][j], T[i/2][j-W[i]]+V[i]);
        }

    vector<int> W2;
    vector<int> V2;
    for (int q=0; q<Q; q++)
    {
        int t = v[q];
        W2.clear();
        V2.clear();
        while (t>=1<<TD)
        {
            W2.push_back(W[t]);
            V2.push_back(V[t]);
            t /= 2;
        }
        int ans = 0;
        for (int b=0; b<1<<(int)W2.size(); b++)
        {
            int w = 0;
            int v = 0;
            for (int i=0; i<(int)W2.size(); i++)
                if (b>>i&1)
                {
                    w += W2[i];
                    v += V2[i];
                }
            if (w<=L[q])
                ans = max(ans, v+T[t][L[q]-w]);
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 206692
S = input()
flag_a = False
flag_b = False
if 0 < int(S[:2]) <= 12:
  flag_a = True
if 0 < int(S[2:]) <=12:
  flag_b = True
  
if flag_a and flag_b:
  print("AMBIGUOUS")
else:
  if flag_a:
    print("MMYY")
  elif flag_b:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	mysort(a) ; myrev(a) ;
	ll h,w ;
	h = w = 0 ;
	for(int i=0;i<n-1;i++){
		if(a.at(i)==a.at(i+1)){
			if(h==0){ 
				h = a.at(i) ;
				i++ ;
			}
			else {
				w = a.at(i) ;
				cout << h*w << endl ;
				return 0 ;
			}
		}
	}
	cout << 0 << endl ;
}


Measured memory_bytes: 1024
#include<stdio.h>
//A is array and N is count
int selection_sort(int array[],int size){
  int count=0;
  int min=100000;
  int min_index,tmp;
  int i,j;
  for(i=0;i<size;i++){
    min_index=i;
    for(j=i;j<size;j++){
      if(array[j]<array[min_index]){
        min=array[j];
        min_index=j;
      }
    }
    if(i!=min_index) count++;
    tmp=array[i];
    array[i]=min;
    array[min_index]=tmp;
  }
  return count;
}

int main(void){
  int i,size=0,array[100000],count=0;
  scanf("%d",&size);
  for(i=0;i<size;i++){
    scanf("%d",&array[i]);
  }
  count = selection_sort(array,size);
  for(i=0;i<size;i++){
    if(i>0) printf(" ");
    printf("%d",array[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 1780
#encoding:utf-8 No.0506 2014.11.15
def change_str(str_in)
  str_out = ""
  length = 1
  i = 0
  while str_in[i]
    if str_in[i] == str_in[i+1]
      length += 1
    else
      str_out << length.to_s + str_in[i]
      length = 1
    end
    i += 1
  end
  return str_out
end

while (n = gets.chomp.to_i) != 0
  str = gets.chomp
  n.times do
    str = change_str(str)
  end
  puts str
end

Measured memory_bytes: 6176
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll X, K, D; cin >> X >> K >> D;
	if (X < 0) X = -X;
	ll step = X / D;
	if (K >= step) {
		if ((K - step) % 2 == 0) {
			cout << abs(X - step * D) << '\n';
		}
		else {
			cout << abs(X - step * D - D) << '\n';
		}
	}
	else {
		cout << X - K * D << '\n';
	}
	return 0;
}

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

using namespace std;

const int INF = 1e9 + 1;

int power2(int e){
  if(e == 0) return 1;
  else if(e & 1) return 2 * power2(e - 1);
  else{
    int p = power2(e >> 1);
    return p * p;
  }
}

int main(){
  int N;
  cin >> N;
  int er_N = power2(N);
  priority_queue<int> heaven;
  for(int i = 0; i < er_N; i++){
    int S;
    cin >> S;
    heaven.push(S);
  }
  
  multiset<int> live;
  live.insert(heaven.top());
  heaven.pop();
  
  bool valid = true;
  while(valid && !heaven.empty()){
    multiset<int> unborn;
    multiset<int> born;
    for(auto itr = live.rbegin(); itr != live.rend(); itr++){
      int slime = INF;
      while(!heaven.empty()){
        slime = heaven.top();
        heaven.pop();
        if(slime >= *itr){
          unborn.insert(slime);
        }else break;
      }
      if(slime < *itr){
        born.insert(slime);
      }else{
        valid = false;
        break;
      }
    }
    
    if(valid){
      for(int slime : born){
        live.insert(slime);
      }
      for(int slime : unborn){
        heaven.push(slime);
      }
    }
  }
  
  cout << (valid ? "Yes" : "No") << endl;
  
  return 0;
}

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

int main(){
    int n;
    while(true){
        cin >> n;
        if(n == 0){
            break;
        }
        
        vector< pair<int, int> > train;
        train.push_back(make_pair(0, 0));

        vector< pair<int, int> > time;
        int hs, ms, ss, he, me, se;
        char tmp;
        for(int i=0; i<n; i++){
            cin >> hs >> tmp >> ms >> tmp >> ss;
            cin >> he >> tmp >> me >> tmp >> se;
            time.push_back(make_pair(hs*3600 + ms*60 + ss, he*3600 + me*60 + se));
        }
        sort(time.begin(), time.end());

        int ans = 1;
        for(int i=0; i<n; i++){
            int sz = train.size();
            for(int j=0; j<sz; j++){
                if(train[j].second <= time[i].first){
                    train[j].second = time[i].second;
                    break;
                }
                if(j == sz-1){
                    train.push_back(make_pair(time[i].first, time[i].second));
                    ans++;
                }
            }
        }
        cout << ans << endl;
    }
    
  return 0;
}

Measured memory_bytes: 3228
use std::io;


fn main() {
    let ss = read_one::<String>()
        .split_whitespace()
        .map(|s| s.chars().next().unwrap())
        .fold(String::new(), |t, s| t + s.to_string().as_str())
        .to_uppercase();
    println!("{}", ss);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}
 
inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}
 
inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
template<const LL mod> struct MI{
	LL a;
	MI operator + (const MI & b) {
		MI res{a + b.a};
		if(res.a >= mod) res.a -= mod;
		return res;
	}
	MI operator - (const MI & b) {
		MI res{a - b.a};
		if(res.a <= 0) res.a += mod;
		return res;
	}
	MI operator * (const MI & b) {
		return MI{a * b.a % mod};
	}
	MI operator / (const MI & b) {
		return MI{a * fastpo(b.a, mod - 2, mod) % mod};
	}
};
const int N = 300033;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const LL LIM = 1e18;
int main() {
	LL a;
	double b;
	cin >> a >> b;
	a = a * (int)(b * 100 + 0.5);
	cout << a / 100 << endl;
}


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

using namespace std;

int main()
{
  int n,count=0,l,jud=0;
  string s;
  cin>>s;
  cin>>n;
  l=s.size();
  for(int i=1; i<=n; i++){
    string t;
    cin>>t;
    t+=t;
    int a=0;
    for(int k=0; k<=t.size(); k++){
      if(s[0]==t[k]){
	  for(int b=1; b<=l-1; b++){
	    if(s[b]!=t[k+b]){
	      jud=-1;
	      break;
	     }
	  }
      if(jud==0){
	count++;
	break;
	}
	jud=0;
      }
    }
  }
  cout<<count<<endl;
  return 0;
}

      

Measured memory_bytes: 1208
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		if (n == 1) {
			System.out.println("Hello World");
		} else if (n == 2) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			System.out.println(a + b);
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <vector>
#define mem(a) memset(a, 0, sizeof(a))
using namespace std;
typedef pair<int, int> Pii;
typedef long long LL;
const int MAXN = 1005;
const int inf = 0x3f3f3f3f;
const int Mod = 100000000;
inline int read()
{
    int f=1, x=0;
    char ch = getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-') f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return f*x;
}
char str[MAXN][MAXN];
int main()
{
    int n, m;
    while(~scanf("%d %d", &n, &m))
    {
        for(int i=0;i<n;++i)
            scanf("%s", str[i]);
        for(int i=0;i<=m+1;++i)
        printf("#");
        printf("\n");
        for(int i=0;i<n;++i)
            printf("#%s#\n", str[i]);

        for(int i=0;i<=m+1;++i)
             printf("#");
        printf("\n");
    }
    return 0;
}


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

int main(){
    int a[5];
    ll b=INF,c=-1;
    rep(i,5){
        cin >>  a[i];
        if(a[i]<=b)b=a[i];
        if(a[i]>=c)c=a[i];
    }
    int k;
    cin >> k;
    if(c-b>k)cout << ":(" << endl;
    else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200100
using namespace std;
struct edge
{
	int s,t,vid;
};
vector<edge>edges;
int ma=0;
vector<int>Eg[maxn];
int val[maxn];
void addedges(int a,int b)
{
	edge K;
	K.s=a;
	K.t=b;
	K.vid=1;
	edges.push_back(K);
	Eg[a].push_back(ma);
	Eg[b].push_back(ma);
	ma++;
}

void bfs(int l)
{
	queue<int>o;
	o.push(l);
	while(!o.empty())
	{
		int y=o.front();
		o.pop();
		int L=Eg[y].size();
		for(int i=0;i<L;i++)
		{
			int Q=Eg[y][i];
			if(edges[Q].vid)
			{
				int h;
				if(edges[Q].s==y)
					h=edges[Q].t;
				else
					h=edges[Q].s;
				val[h]+=val[y];
				o.push(h);
				edges[Q].vid=0;
			}
		}
	}
}
int   main()
{
	int n,q,a,b,x,y;
	scanf("%d%d",&n,&q);
	for(int i=1;i<n;i++)
	{
		val[i]=0;
		scanf("%d%d",&a,&b);
		addedges(a,b);
	}
	val[n]=0;
	
	for(int i=0;i<q;i++)
	{
		scanf("%d%d",&x,&y);
		val[x]+=y;
	}
	
	bfs(1);
	for(int i=1;i<n;i++)
		printf("%d ",val[i]);
	printf("%d\n",val[n]);
}
	

Measured memory_bytes: 18224
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
#define ll long long
int main() {
	ll cnt=0,N;
	string S;
	cin >> N>>S;
	for (ll i = 0; i < S.size() - 1; i++) {
		if (S[i] == S[i + 1]) {
			cnt++;
		}
}
	cout << S.size() - cnt << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

int main() {
	string s; cin >> s;

	int i = s.size() - 1;
	while (i >= 0) {
		if (i >= 5 && s.substr(i - 5, 6) == "eraser") i -= 6;
		else if (i >= 4 && s.substr(i - 4, 5) == "erase") i -= 5;
		else if (i >= 6 && s.substr(i - 6, 7) == "dreamer") i -= 7;
		else if (i >= 4 && s.substr(i - 4, 5) == "dream") i -= 5;
		else {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	cin >> S;
	vector<char> ans(S.size(), 'x');
	rep(i, S.size()) {
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N,M;
    cin>>N>>M;
    vint vec;
    rep(i,M){
        int a,b;
        cin>>a>>b;
        vec.pb(max(0ll,N-a));
    }
    sort(all(vec));
    int ans=0;
    rep(i,M-1)ans+=vec[i];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 


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

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N-1);

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

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

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

    LL ans = 0;

    int prev = -100;
    for (int i = 0; i < N; ++i) {
        int curr = A[i];
        ans += B[curr];
        if (prev+1 == curr) {
            ans += C[prev];
        }
        prev = curr;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
struct _IO { _IO() { ios::sync_with_stdio(false); cin.tie(nullptr); } }_io;
typedef long long ll; typedef long double db;

ll exgcd(ll a, ll b, ll& x, ll& y)
{
	if (!b)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll d = exgcd(b, a % b, x, y);
	ll t = x;
	x = y;
	y = t - (a / b) * y;
	return d;
}
ll getInv(ll a, ll mod)
{
	ll x, y;
	return exgcd(a, mod, x, y) == 1 ? (x % mod + mod) % mod : -1;
}

int main()
{
	ll n, cnt = 0;
	bool flag = 0;
	cin >> n;
	while (n--)
	{
		ll a, b;
		cin >> a >> b;
		if (a == b) ++cnt;
		else cnt = 0;
		if (cnt >= 3) flag = 1;
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3648
from bisect import bisect
from bisect import bisect_left
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1, n):
    left = l[j]-l[i]
    right = l[i]+l[j]
    ans += max(0, bisect_left(l, right) - max(j+1, bisect(l,left)))
print(ans)

Measured memory_bytes: 46300
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
const int mod=998244353;
struct point{int x,y;}p[210];
bool vis[210][210];
int multi(point p1,point p2,point p0)
{
	int x1=p1.x-p0.x,y1=p1.y-p0.y;
	int x2=p2.x-p0.x,y2=p2.y-p0.y;
	return x1*y2-x2*y1;
}
int n,bin[210],sta[210],top=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d %d",&p[i].x,&p[i].y);
	bin[0]=1;for(int i=1;i<=n;i++) bin[i]=(bin[i-1]*2)%mod;
	int ans=(bin[n]-n-1)%mod;
	memset(vis,false,sizeof(vis));
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		{
			if(i==j||vis[i][j]) continue;
			top=0;sta[++top]=i;sta[++top]=j;
			for(int k=1;k<=n;k++)
				if(i!=k&&j!=k&&multi(p[i],p[j],p[k])==0) sta[++top]=k;
			for(int k=1;k<=top;k++) for(int u=1;u<=top;u++) vis[sta[k]][sta[u]]=true;
			(ans-=(bin[top]-(top+1)))%=mod;
			//printf("ans:%d %d\n",ans,top);
			//for(int k=1;k<=top;k++) printf("%d ",sta[k]);printf("\n");
		}
	//(ans-=1)%=mod;
	printf("%d",(ans+mod)%mod);
}

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

def puts(n:int, s:str) -> None:
    for _ in range(n):
        print(s, end='')

        
puts(w+2, "#")
print("\n", end='')

for i in range(h):
    print("#", end='')
    print(''.join(a[i]), end='')
    print("#")
puts(w+2, "#")

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef map<string,int> msi;
typedef vector<pii> vpii;

/* global variables */

int n, m, nst;
string sstr, pstr, gstr;
int si, pi, gi;
msi sids;
vpii nbrs[MAX_N];
int dists[MAX_N];

/* subroutines */

int sid(string str) {
  msi::iterator mit = sids.find(str);
  if (mit == sids.end()) return (sids[str] = nst++);
  return mit->second;
}

int mindist(int st, int gl) {
  for (int i = 0; i < n; i++) dists[i] = INF;
  dists[st] = 0;

  priority_queue<pii,vector<pii>,greater<pii> > q;
  q.push(pii(0, st));

  while (! q.empty()) {
    pii u = q.top(); q.pop();
    int ud = u.first;
    int ui = u.second;

    if (ud != dists[ui]) continue;
    if (ui == gl) break;

    vpii nbru = nbrs[ui];
    for (vpii::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int vi = vit->first;
      int vd = ud + vit->second;

      if (dists[vi] > vd) {
	dists[vi] = vd;
	q.push(pii(vd, vi));
      }
    }
  }

  return dists[gl];
}

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    sids.clear();
    for (int i = 0; i < n; i++) nbrs[i].clear();
    
    cin >> sstr >> pstr >> gstr;

    nst = 0;
    si = sid(sstr);
    pi = sid(pstr);
    gi = sid(gstr);

    for (int i = 0; i < m; i++) {
      string astr, bstr;
      int di, ti;
      cin >> astr >> bstr >> di >> ti;

      int ai = sid(astr);
      int bi = sid(bstr);
      int d = di / 40 + ti;
      nbrs[ai].push_back(pii(bi, d));
      nbrs[bi].push_back(pii(ai, d));
    }

    int mind = mindist(si, pi) + mindist(pi, gi);
    cout << mind << endl;
  }

  return 0;
}

Measured memory_bytes: 1512
#include<iostream>
using namespace std;
int main() {
	int n, a, b, c, d, e = 0, f = 0,g=0; cin >> n >> a >> b >> c >> d;
	string s; cin >> s;
	if (c < d) {
		for (int i = a; i < d - 1; i++) {
			if (s[i] == '#' && s[i + 1] == '#') {
				e++;
			}
		}
		if (e == 0) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	else {
		for (int i = b - 2; i < d-1; i++) {
			if (s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.') {
				f++;
			}
		}
		for (int i = a; i < c; i++) {
			if (s[i] == '#' && s[i + 1] == '#') {
				g++;
			}
		}
		if (f != 0 && g==0) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
}


Measured memory_bytes: 640