akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

int main(){                                                                                 
  for(int i = 1; i <= 9; ++i){                                                              
    for(int j = 1; j <= 9; ++j){                                                            
      std::cout << i << "x" << j << "=" << i*j << std::endl;                                
    }                                                                                       
  }                                                                                         
  return 0;                                                                                 
}

Measured memory_bytes: 1112
import sys
readline = sys.stdin.readline

# 逆順に見ていく
# A_iの値が小さい順にheapqに追加していく

N,M = map(int,readline().split())
from collections import defaultdict
tasks = defaultdict(list)
for i in range(N):
  a,b = map(int,readline().split())
  tasks[a].append(b)
  
import heapq
q = []
heapq.heapify(q)
ans = 0
for i in range(1,M + 1):
  for task in tasks[i]:
    heapq.heappush(q,-task)
  if q:
    t = heapq.heappop(q)
    ans += (-t)

print(ans)

Measured memory_bytes: 27832
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

/*ソートの時に使う
int sort(const void *a, const void *b){
    return *(int*)a-*(int*)b ;
}
    qsort (data,sizeof(data),sizeof(int),sort); 
*/

int main(void){
    int a,b,c,d,e,f;
    scanf("%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f);
    
    int water[(((f/100)/a)+1)*(((f/100)/b)+1)],countw=0;
    for (int i=0; i<((f/100)/a)+1; i++){
        for (int j=0; j<((f/100)/b)+1; j++){
            if (a*100*i+b*100*j!=0 && a*100*i+b*100*j<=f){
                water[countw]=a*100*i+b*100*j ;
                countw++;
            }
        }
    }
    int suger[((f/c)+1)*((f/d)+1)],counts=0;
    for (int i=0; i<(f/c)+1; i++){
        for (int j=0; j<(f/d)+1; j++){
            if (i*c+j*d<=f){
                suger[counts]=c*i+d*j;    
                counts++;

            }
        }    
    }
    int tmpwater=a*100,tmpsuger=0;
    for (int i=0; i<countw; i++){
        for (int j=0; j<counts; j++){
            if (water[i]+suger[j]<=f && suger[j]*(100+e)<=e*(water[i]+suger[j]) ){
                
                if (tmpsuger*(water[i]+suger[j])<suger[j]*(tmpwater+tmpsuger)){
                    tmpsuger=suger[j];
                    tmpwater=water[i];
                    
                }
            }
        }
    }
    printf("%d %d\n",tmpwater+tmpsuger,tmpsuger);
	return 0 ;
}

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

bool not_equal(int a, int b, int c) {
  return a != b && a != c && b != c;
}

bool make_triangle(int a, int b, int c) {
  return a < b + c && b < c + a && c < a + b;
}

int main() {
  int N;
  cin >> N;
  
  vector<int> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  
  int ans = 0;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      for (int k = 0; k < N; k++) {
        if (not_equal(L.at(i), L.at(j), L.at(k)) && 
            make_triangle(L.at(i), L.at(j), L.at(k))) {
          ans++;
        }
      }
    }
  }
  
  cout << (ans / 6) << endl;
  
  return 0;
}


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

int main() {
  int N, K, a, x;
  cin >> N >> K;
  a = 0;
  for (int i = 0; i < N; i ++){
    cin >> x;
    if (x < K - x) a += x;
    else a += K - x;
  }
  cout << a * 2 << endl;
}


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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

typedef int64_t ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int N = 1e5+1;
const int MOD = 1e9+7;
const ll INF = INT_MAX;
const ll _INF = INT_MIN;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, temp = 1, ans = 0;
	
	cin >> n;
	while(temp <= n) {
		ans += (min(n, temp*10-1)-temp)+1;	
		temp *= 100;
	}	
	
	cout << ans;
}

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

int main(void){
int n;
cin >> n ;
char s[n+1];
int hidaricost[n+2];
int hidarizenbu,migizenbu;
hidarizenbu=migizenbu=0;
hidaricost[0]=0;
int score[n+1];

int i;
for (i=0;i<n;i++){
cin >> s[i] ;
if (s[i]=='E'){
migizenbu++;
hidaricost[i+1]=hidaricost[i];
}
else{
hidarizenbu++;
hidaricost[i+1]=hidaricost[i]+1;
}
}
score[0]=migizenbu-1+hidaricost[1];
int kotae;
kotae=score[0];

for(i=1;i<n;i++){
score[i]=hidaricost[i]+migizenbu-i-1+hidaricost[i+1];
kotae=min(score[i],kotae);
}
cout << kotae << endl;
}





Measured memory_bytes: 2944
import math

s = input()

firstHalf = s[:math.floor(len(s) / 2)]
reversedSecondHalf = s[math.ceil(len(s) / 2):][::-1]

ans = 0
for i in range(len(firstHalf)):
    if (firstHalf[i] != reversedSecondHalf[i]):
        ans += 1

print(ans)


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

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  
  for (int i = 0; i <= N; ++i)
  {
    int sum = findSumOfDigits(i);
    if (A <= sum && sum <= B) total += i;
  }
  
  cout << total << endl;
  return 0;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll n,i,j;
    cin>>n;
    double sum=0.0,cc=0.0;
    for(i=1;i<=n;i++){
        string str;
        double x;
        cin>>x>>str;
        if(str=="JPY")sum+=x*1.0;
        else{
            sum+=(x*380000.0);
        }
        
    }
    cout<<sum<<endl;
return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int N=2e9+2;
const int inf= (int)(1e19+10LL);
int L(int x){
	return x*x*x*x*x;
}
void solve(){
    int x;
    sl(x);
    for(int i=-200;i<=200;i++){
    	for(int j=-200;j<=200;j++){
    		int val1=L(i);
    		int val2=L(j);
    		if((val1-val2)==x){
    			cout<<i<<" "<<j<<endl;
    			return;
    		}
    	
    	}
    }
    

    
    
}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    string x;
    cin>>x;
    int n = x.size();
    if(n % 2 == 1){
        n--;
        x.pop_back();
    }else{
        x.pop_back();
        x.pop_back();
        n-= 2;
    }
    bool is;
    do{
        is = true;
        for(int i = 0 , j = i + n / 2 ; i < n / 2 ; i++ , j++){
            if(x[i] != x[j]){
                is = false;
            }
        }
        if(!is){
            n-= 2;
            x.pop_back();
            x.pop_back();
        }
    }while(!is);
    cout<<x.size()<<endl;

}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l_list = [0]*8
for i in range(N):
    l_list[i] = int(input())
INF = 1e9

target_length = {'A':A, 'B':B, 'C':C}
# print(l_list)
cost_list = []

all_combination = []
base = ['A', 'B', 'C', 'O']

def comb_to_cost(combination):
    cost = 0
    for char in ['A', 'B', 'C']:
        base_length = 0
        for i in range(8):
            c = combination[i]
            if c == char:
                base_length += l_list[i]
                cost += 10
        cost -= 10
        if base_length == 0:
            return INF
        cost += abs(base_length-target_length[char])
    return cost


for char1 in base:
    for char2 in base:
        for char3 in base:
            for char4 in base:
                for char5 in base:
                    for char6 in base:
                        for char7 in base:
                            for char8 in base:
                                all_combination.append(char1+char2+char3+char4+char5+char6+char7+char8)

for comb in all_combination:
    cost_list.append(comb_to_cost(comb))

# print(cost_list)
print(min(cost_list))


Measured memory_bytes: 9820
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 25 18:20:35 2020
"""

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

#N = int(input())
N, K = map(int,input().split())
A = np.array(list(map(int,input().split())))

dp = np.arange(K + A[-1]+1) >= 0
for i in range(K, -1, -1):
    if np.all(dp[A+i]):
        dp[i] = False
#    print(i, dp[i],A+i,dp[A+i])
#print(dp)

if dp[0]:
    ans = 'First'
else:
    ans = 'Second'
print(ans)

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

int main(){
    int n;

    cin >> n;

    int v[n];
    int c[n];
    
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    for(int i=0;i<n;i++){
        cin >> c[i];
    }

    int r = 0;

    for(int i=0; i<n; i++){
        if(v[i]-c[i] > 0){
            r += (v[i]-c[i]);
        }
    }

    cout << r << endl;
}

Measured memory_bytes: 256
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B
main=print.f.map(fst.fromJust.B.readInt).B.words=<<B.getContents
f(_:m:a)=foldr(+)0$map(g.length)$group$sort$scanr(\a s->(a+s)`mod`m)0 a
g i=i*(i-1)`div`2

Measured memory_bytes: 25852
import itertools

n = int(input())
p = tuple(map(int, input().split(" ")))
q = tuple(map(int, input().split(" ")))
l = [i for i in range(n, 0, -1)]

p_i = 0
q_i = 0

for i, v in enumerate(itertools.permutations(l, n)):
  if v == p:
    p_i = i + 1
  if v == q:
    q_i = i + 1

print(abs(p_i - q_i))


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

int main(){
    string s;
    cin>>s;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
int main(){

    int N,M;
    cin>>N>>M;
    vector<int>L(M);
    vector<int>R(M);
    for(int i=0;i<M;i++)
    {cin>>L[i]>>R[i];}
  
    sort(L.begin(),L.end());
    reverse(L.begin(),L.end());
    
    sort(R.begin(),R.end());
    
    if(R[0]-L[0]>=0)
    {cout<<R[0]-L[0]+1<<endl;}
    else{cout<<0<<endl;}
    
    
    
    
    }
    
  
    


Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#define LL long long
using namespace std;
const LL INF = 1e18;
LL a,b,c;
LL k;
int main()
{
    std::ios::sync_with_stdio(false);
    cin>>a>>b>>c>>k;
    bool flag = 0;
    if(abs(b-a) > INF)
        flag = 1;
    if(flag)
        cout<<"Unfair"<<endl;
    else {
        if(k & 1){
            cout<<b-a<<endl;
        }else{
            cout<<a-b<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
 
int main() {
  float A, B;
  cin >> A >> B;
  float Amin = A / 0.08;
  float Amax = (A+1)/ 0.08;
  float Bmin = B / 0.1;
  float Bmax = (B+1) / 0.1;
  
  float Amin_ = ceil(Amin);
  float Bmin_ = ceil(Bmin);
  
  if(Amin_>=Bmax || Bmin_>=Amax) {
    cout << -1;
  } else {
    if(Amin_>Bmin_) {
      cout << Amin_; 
    } else {
      cout << Bmin_;
    }
  }
  
  return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())

bridges = []
for i in range(m):
    bridges.append([int(x) for x in input().split()])
'''
g = list(range(n+1))
ng = [1 for _ in range(n+1)]
gl = [[i] for i in range(n+1)]
ans = []
unconf = n*(n-1)//2
ans.append(unconf)


for x in reversed(bridges):
    a,b = x
    if g[a] != g[b]:
        tmp = ng[g[a]] * ng[g[b]]
        ng[g[a]] = ng[g[a]]+ng[g[b]]
        gl[g[a]] = gl[g[a]] + gl[g[b]]
        for y in gl[g[b]]:
            g[y] = g[a]
        unconf -= tmp
        ans.append(unconf)
    else:
        ans.append(unconf)


ans.reverse()
ans.pop(0)
for x in ans:
    print(x)
'''
def root(par, ifpar, a):
    while ifpar[a] != 1:
       a = par[a]
    return a 

def unite(cnt, par, ifpar, npar, depth, ra, rb):
    if depth[ra] >= depth[rb]:
        npar[ra] = npar[ra] + npar[rb]
        par[rb] = ra
        ifpar[rb] = 0
        if depth[ra] == depth[rb]:
            depth[ra] += 1
    else:
        npar[rb] = npar[rb] + npar[ra]
        par[ra] = rb
        ifpar[ra] = 0

par = list(range(n+1))
ifpar = [1 for _ in range(n+1)]
npar = [1 for _ in range(n+1)]
depth = [1 for _ in range(n+1)]

ans = []
unconf = n*(n-1)//2
ans.append(unconf)
cnt = 0

for x in reversed(bridges):
    a,b = x
    ra = root(par, ifpar, a)
    rb = root(par, ifpar, b)
    if ra != rb:
        tmp = npar[ra] * npar[rb]
        unite(cnt, par, ifpar, npar, depth, ra, rb)
        unconf -= tmp
    ans.append(unconf)
    cnt += 1

ans.reverse()
ans.pop(0)
for x in ans:
    print(x)

Measured memory_bytes: 29536
#include <algorithm>
#include <iostream>
#include <vector>
#include <functional>
using namespace std;

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
    int N; cin >> N;
    vector<int64_t> A(N);
    REP(i, N) cin >> A[i];

    vector<pair<int64_t, int>> indexed(N);
    REP(i, N) indexed[i] = {A[i], i};
    sort(ALL(indexed), greater());

    // dp[L][R] = 左にL人、右にR人配置したときの嬉しさの最大値
    vector dp(N+1, vector(N+1, int64_t()));
    REP(L, N+1) REP(R, N-L+1) {
        if (L == 0 && R == 0) {
            dp[L][R] = 0;
        } else {
            auto [_, k] = indexed[L+R-1];
            int64_t vl = L >= 1 ? dp[L-1][R] + A[k] * abs(k+1 - L)
                                : numeric_limits<int64_t>::min();
            int64_t vr = R >= 1 ? dp[L][R-1] + A[k] * abs(k+1 - (N-R+1))
                                : numeric_limits<int64_t>::min();
            dp[L][R] = max(vl, vr);
        }
    }

    int64_t ans = numeric_limits<int64_t>::min();
    REP(L, N+1) ans = max(ans, dp[L][N-L]);
    cout << ans << '\n';
}


Measured memory_bytes: 34636
import std.stdio, std.string, std.conv, std.range;
import std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N, M;
    scan(N, M);
    auto a = new int[](N);
    a[] = -1;
    foreach (i ; 0 .. M) {
        int si, ci;
        scan(si, ci);
        si--;
        if (a[si] != -1 && a[si] != ci) {
            writeln(-1);
            return;
        }
        a[si] = ci;
    }
    if (a[0] == 0) {
        writeln(N == 1 ? 0 : -1);
        return;
    }
    if (a.all!"a == -1" && N == 1) {
        writeln(0);
        return;
    }
    foreach (i ; 0 .. N) {
        if (a[i] != -1) {
            write(a[i]);
        }
        else {
            write(i == 0 ? 1 : 0);
        }
    }
    writeln;
}




void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
ll n,s,t;
set<ll>o;
int main(void){
    scanf("%lld",&n);
    for(int i=0;i<n;i++){
        ll a;
        scanf("%lld",&a);
        if(o.find(a)==o.end())o.insert(a);
        else{
            if(s<a){
                t=s;
                s=a;
            }else t=max(t,a);
            o.erase(o.find(a));
        }
    }
    printf("%lld\n",s*t);
}

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

/*****All definitions*******/
#define w(t) int t; cin>>t; while(t--)
#define vi vector<int>
#define vs vector<string>
#define mp make_pair
/***************************/

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int s, w;
	cin >> s >> w;
	if (w >= s)	cout << "unsafe";
	else cout << "safe";
	return 0;
}


Measured memory_bytes: 3612
#include<cstdio>

int main(void){

	int paper[10+2+2][10+2+2]={0};
	int x,y,s;
	int max=0,num=0;
	while(scanf("%d,%d,%d",&x,&y,&s)!=EOF){
		if(s>=1){
			paper[2+x][2+y]++;
			paper[2+x][2+y+1]++;
			paper[2+x][2+y-1]++;
			paper[2+x+1][2+y]++;
			paper[2+x-1][2+y]++;
		}
		if(s>=2){
			paper[2+x+1][2+y+1]++;
			paper[2+x-1][2+y+1]++;
			paper[2+x+1][2+y-1]++;
			paper[2+x-1][2+y-1]++;
		}
		if(s>=3){
			paper[2+x][2+y+2]++;
			paper[2+x][2+y-2]++;
			paper[2+x+2][2+y]++;
			paper[2+x-2][2+y]++;
		}
	}
	for(int i=0;i<10;i++){
		for(int j=0;j<10;j++){
			if(max<paper[2+i][2+j]) max=paper[2+i][2+j];
			if(paper[2+i][2+j]==0) num++;
		}
	}
	printf("%d\n%d\n",num,max);
	return 0;
}

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;
    i64 N,A,B,C,D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;

    --A;
    --B;
    --C;
    --D;

    if(C<D){
        while(B<D){
            if(S[B+1]!='#') ++B;
            else if(S[B+1]=='#' and S[B+2]=='.') B+=2;
            else{
                cout << "No" << endl;
                return;
            }
        }
        while(A<C){
            if(S[A+1]!='#') ++A;
            else if(S[A+1]=='#' and S[A+2]=='.') A+=2;
            else{
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }else{
        while(B<D){
            print(B);
            if(0<B-1 and B+1<N and S[B-1]=='.' and S[B+1]=='.') break;
            if(S[B+1]!='#') ++B;
            else if(S[B+1]=='#' and S[B+2]=='.') B+=2;
            else{
                cout << "No" << endl;
                return;
            }
        }
        print(B);
        if(B==D) S[B]='#';
        while(A<C){
            print(A);
            if(S[A+1]!='#') ++A;
            else if(S[A+1]=='#' and S[A+2]=='.') A+=2;
            else{
                cout << "No" << endl;
                return;
            }
        }
        print(A);
        while(B<D){
            print(B);
            if(S[B+1]!='#') ++B;
            else if(S[B+1]=='#' and S[B+2]=='.') B+=2;
            else{
                cout << "No" << endl;
                return;
            }
        }
        cout << "Yes" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<string> str(n);
  int i,j;
  for(i = 0;i < n;++i){
    cin >> str.at(i);
  }
  for(i = 0; i < n-1;++i){
    for(j = i+1;j < n;++j){
      if(str.at(i) == str.at(j)){
        cout << "No" << endl;
        return 0;
      }else{
        continue;
      }
    }
  }
  for(i = 0;i < n-1;++i){
    if(str.at(i).at(str.at(i).size()-1) != str.at(i+1).at(0)){
      cout << "No" << endl;
      return 0;
    }else{
      continue;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s;
long long base=311,MOD=1e9+7,slen;
long long hashs[1005],lt[1005],Pow[1005];
int res1,res2,max1,max2,dau[1005],cuoi[1005],kc[1005],dem;
void nhap()
{
    getline(cin,s);
    s=' '+s;
    slen=s.length()-1;
}
void taohash()
{
    Pow[0]=1;
    for (long long i=1;i<=slen;i++) Pow[i]=(Pow[i-1]*base)%MOD;
    for (long long i=1;i<=slen;i++){
        hashs[i]=(hashs[i-1]*base+s[i])%MOD;
    }
}
long long get(long long i,long long j)
{
    return ((hashs[j]-hashs[i-1]*Pow[j-i+1])+MOD*MOD)%MOD;
}
bool kt(int x,int y)
{
    if (kc[x]!=kc[y]) return false;
    return get(dau[x],cuoi[x])==get(dau[y],cuoi[y]);
}
void push(int u,int v)
{
    dem++;
    dau[dem]=u;
    cuoi[dem]=v;
    kc[dem]=v-u;
}
void khoitao()
{
    int u=1,v;
    for (int i=1;i<=slen;i++){
        if (s[i]==' '||i==slen){
            v=i-1;
            if (i==slen) v=i;
            push(u,v);
            if (kc[dem]>max2){
                res2=dem;
                max2=kc[dem];
            }
            u=i+1;
        }
    }
}
void xuli()
{
    khoitao();
    taohash();
    for (int i=1;i<=dem;i++){
        int kq=0;
        for (int j=1;j<=dem;j++){
            if (j!=i) if (kt(i,j)) kq++;
        }
        if (kq>max1){
            res1=i;
            max1=kq;
        }
    }
    for (int i=dau[res1];i<=cuoi[res1];i++) printf("%c",s[i]);
    printf(" ");
    for (int i=dau[res2];i<=cuoi[res2];i++) printf("%c",s[i]);
    printf("\n");
}
int main()
{
    nhap();
    xuli();
}



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

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

  int h = S / 3600;
  int m = (S % 3600) / 60;
  int s = S % 60;

  cout << h << ":" << m << ":" << s << endl;
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<string> A(2);
    rep(i, 2) cin >> A[i];
    
    ll ret = 1;
    vector<int> B;
    char cur = '0';
    rep(i, N){
        if(cur == A[0][i]) {
            B[B.size() - 1]++;
        }
        else {
            B.pb(1);
        }
        cur = A[0][i];
    }
    
    if(B[0] == 1) ret = 3;
    else ret = 6;
    rep(i, 1, N){
        if(B[i - 1] == 1 && B[i] == 1) ret *= 2;
        if(B[i - 1] == 1 && B[i] == 2) ret *= 2;
        if(B[i - 1] == 2 && B[i] == 1) ret *= 1;
        if(B[i - 1] == 2 && B[i] == 2) ret *= 3;
        ret %= mod;
    }
    
    output(ret);
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 24 21:03:10 2019

@author: Yamazaki Kenichi
"""

S = input()

mm = int(S[5:7])

if mm< 5:
    ans = 'Heisei'
else:
    ans ='TBD'
print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <deque>

using namespace std;

bool f[52][52];
bool visited[52][52][52][52];

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


class state{
public:
    int ax;
    int ay;
    int bx;
    int by;
    int depth;

    state(int a, int b, int c, int d, int e){
        ax = a;
        ay = b;
        bx = c;
        by = d;
        depth = e;
    }
};

int main(){
    int w,h;
    while(cin >> w >> h){
        if((w|h) == 0) break;
        int ax,ay,bx,by,tmp;
        deque<state> q;
        cin >> ax >> ay;
        cin >> bx >> by;
        
        memset(f,false,sizeof(f));
        memset(visited, false, sizeof(visited));

        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin >> tmp;
                f[i][j] = tmp?0:1;
            }
        }

        state s = state(ax,ay,bx,by,0);
        int tmpd;
        bool isok = false;
        q.push_back(s);
        visited[ay][ax][by][bx] = true;
        while(!q.empty()){
            s = q.front();
            ax = s.ax;
            ay = s.ay;
            bx = s.bx;
            by = s.by;
            tmpd = s.depth;
            q.pop_front();
            if((ax == bx) && (ay == by)){
                cout << tmpd << endl;
                isok = true;
                break;
            }
            if(tmpd == 100){
                break;
            }
            int nax, nay, nbx, nby;
            for(int i=0;i<4;i++){
                nax = ax+dx[i];
                nay = ay+dy[i];
                nbx = bx+dx[(i+2)%4];
                nby = by+dy[(i+2)%4];
                if(f[nay][nax] == false){
                    nay = ay;
                    nax = ax;
                }
                if(f[nby][nbx] == false){
                    nby = by;
                    nbx = bx;
                }
                if(f[nay][nax] == true && f[nby][nbx] == true &&
                   visited[nay][nax][nby][nbx] == false){
                    q.push_back(state(nax,nay,nbx,nby,tmpd+1));
                    visited[nay][nax][nby][nbx] = true;
                }
            }
        }
        if(!isok) cout << "NA" << endl;
    }
}

Measured memory_bytes: 8208
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long power=1;
		for(int i=1;i<=n;i++) {
			power *= i;
			power = power % 1000000007;
		}
		System.out.println(power);
	}

}

Measured memory_bytes: 21844
while 1
    n, m = gets.split.map(&:to_i)
    break if n == 0
    min = {}
    max = {}
    (1..n).each {|i| min[i] = max[i] = 0}
    m.times do
        s, k, *cs = gets.split.map(&:to_i)
        min[cs[0]] += s if k == 1
        cs.each do |c|
            max[c] += s
        end
    end
    min_key, second_min_key = min.keys.sort_by {|i| min[i]}[0..1]
    second_max_key, max_key = max.keys.sort_by {|i| max[i]}[-2..-1]
    if min_key != max_key
        p max[max_key] - min[min_key] + 1
    else
        p [max[max_key] - min[second_min_key], max[second_max_key] - min[min_key]].max + 1
    end
end


Measured memory_bytes: 18112
import math
N, K = map(int, input().split())
score = 0

if K <= N:
	ans = (N-K+1)/N
	end = K
else:
	ans = 0
	end = N+1
for i in range(1, end):
	ans += (1/N) * (1/2)**math.ceil(math.log2(K/i))
	
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
using namespace std;

long long gcd(long long a, long long b){
    if(b == 0){
        return a;
    }
    return gcd(b, a%b);
}

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

int main(void){
    int n;
    long long t[1005];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> t[i];
    }
    long long ans = 1;
    for(int i=0;i<n;i++){
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        int N;
        int[] a;
        int[] put;

        int M = 0;
        StringBuilder ans = new StringBuilder();

        void solve(InputReader in, PrintWriter out) {
            N = in.nextInt();
            a = in.nextIntArray(N);
            put = new int[N];
            Arrays.fill(put, 0);

            for (int i = N; i >= 1; --i) {
                int xor = 0;
                for (int j = i*2; j <= N; j += i) {
                    xor ^= put[j - 1];
                }
                if ((xor ^ a[i - 1]) == 1) {
                    put[i - 1] = 1;
                    M++;
                    ans.append(i).append(' ');
                }
            }

            out.println(M);
            if (M > 0) out.println(ans.toString().trim());
        }

    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}

Measured memory_bytes: 42776
#include<stdio.h>
#include<stdlib.h>

int main(void){
  char a[5];
  scanf("%s\n",a);
  if(((a[0] == a[1])&& (a[1] == a[2]))&& (a[2] == a[0])){
    printf("No");
    exit(0);
  }
  printf("Yes" );
  return 0;
}

Measured memory_bytes: 128
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,M=get_i
ab=array(N)
N.times do|i|
    ab[i]=get_i
end
cd=array(M)
M.times do|i|
    cd[i]=get_i
end
N.times do|i|
    dist=INF
    ans=-1
    M.times do|j|
      d=(ab[i][0]-cd[j][0]).abs+(ab[i][1]-cd[j][1]).abs
      if dist>d
        ans=j+1
        dist=d
      end 
    end
    puts ans
end

Measured memory_bytes: 1788
void main() {
	auto arr = 5.iota.map!(i => ri).array;
	
	ulong res = ulong.max;
	do {
		ulong tmp;
		foreach(i, v; arr) {
			if(i == 4) {
				tmp += v;
			} else {
				tmp = ceil((tmp + v) / 10.).to!ulong * 10;
			}
		}
		res = min(res, tmp);
	} while(nextPermutation(arr));
	res.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    long long int T,t;
    cin>>T;
    long long int sum=0;
    long long int start,end;
    for (int i=0;i<n;i++) {
        cin>>t;
        if (i==0) {
            start=t;
            end=T;
        } else {
            if (t<=end) {
                end=t+T;
            } else {
                sum+=end-start;
                start=t;
                end=start+T;
            }
        }
    }
    sum+=end-start;
    cout<<sum<<endl;
}

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

int n;
int d,a;
P p[200005];
ll sum[200005];

int main(void){
	scanf("%d%d%d",&n,&d,&a);
	for(int i=0;i<n;i++){
		scanf("%d%d",&p[i].first,&p[i].second);
	}
	sort(p,p+n);
	ll ans=0;
	for(int i=0;i<n;i++){
		ll rest=p[i].second-sum[i];
		if(rest<=0){
			sum[i+1]+=sum[i];
			continue;
		}
		ll cnt=(rest+a-1LL)/a;
		ans+=cnt;
		sum[i+1]+=sum[i]+cnt*a;
		int pos=lower_bound(p,p+n,P(p[i].first+2LL*d+1LL,0))-p;
		sum[pos]-=cnt*a;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vi a(n+1);
    rep(i, n) {
        int r, c;
        cin >> r >> c;
        if (i == 0) {
            a[i] = r;
            a[i+1] = c;
        } else {
            a[i+1] = c;
        }
    }

    vvi dp(n+1, vi(n+1, INF));
    for (int i = 1; i <= n; ++i) dp[i][i] = 0;
    // kが間隔
    for (int k = 1; k <= n - 1; ++k) {
        // iが始点
        for (int i = 1; i + k <= n; ++i) {
            // jが間の点
            for (int j = i; j <= i + k - 1; ++j) {
                chmin(dp[i][i+k], dp[i][j] + dp[j+1][i+k] + a[i-1]*a[j]*a[i+k]);
            }
        }
    }

    // for (int i = 1; i <= n; ++i) {
    //     for (int j = i+1; j <= n; ++j) {
    //         for (int k = i; k <= j-1; ++k) {
    //             chmin(dp[i][j], dp[i][k] + dp[k+1][j] + a[i-1] * a[k] * a[j]);
    //         }
    //     }
    // }
    // だと更新順がダメ
    
    cout << dp[1][n] << endl;
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>
int main()
{
	char a[11],b[11],c[11];
	int len,len2;
	scanf("%s %s %s",a,b,c);
	len=strlen(a);
	len2=strlen(b);
	if(a[len-1]==b[0]&&b[len2-1]==c[0]) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<int>data(N);
  map<int,int>mp;
  for(int i=0;i<N;i++){
    int tmp;
    cin>>tmp;
    mp[tmp]=i+1;
  }
  for(auto a:mp){
    cout<<a.second<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 5888
/*
Educational DP Contest - F - LCS
https://atcoder.jp/contests/dp/tasks/dp_f
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)
typedef long long ll; 
 
int main()  
{ 
    FAST_INP;
    string s,t;
    cin >> s >> t;
    int m=s.size(), n=t.size();
	// dp[m][n] : length of LCS 
	vector<vector<int>> dp(m+1,vector<int>(n+1,0));
    for(int i=1;i<=m;i++){
    	for(int j=1;j<=n;j++){
    		if(s[i-1]==t[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
    		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	// building LCS
	string ans="";
	int i=m, j=n;
	while(i&&j){
		if(dp[i][j]==dp[i-1][j]) i--;
		else if(dp[i][j]==dp[i][j-1]) j--;
		else {
			ans=s[i-1]+ans;
			i--, j--;	
		}
	}
	cout << ans << endl;
    return 0;
} 


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

using namespace std;
char v[200003];
int n, st, dr, sol;
int main()
{
    ios::sync_with_stdio(false);
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> v[i];

    st = 1;
    dr = n;
    while(true)
    {
        while(v[st] == 'R') ++st;
        while(v[dr] == 'W') --dr;
        if(st >= dr) break;
        ++sol;
        ++st;
        --dr;
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 3768
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int NN = N;
		int fx = 0;
		while (N > 0) {
			fx += N % 10;
			N /= 10;
		}
		System.out.println(NN % fx == 0 ? "Yes" : "No");
	}
}

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

int main(){
  string s,t;
  cin >> s >> t;
  int res = 0;
  for(int i = 0 ; i < s.size() ; i++){
    if(s[i] != t[i])res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3916
# cf17-finalA - AKIBA
def main():
    S = input().rstrip()
    flg = (
        S.replace("A", "") == "KIHBR"
        and "AA" not in S
        and "KA" not in S
        and "IA" not in S
    )
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

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

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

    int N;
    cin >> N;

    vector<pair<long, long>> p(N);
    for (int n = 0; n < N; n++) {
        cin >> p[n].second >> p[n].first;
    }

    sort(p.begin(), p.end());

    bool maniau = true;
    long deadline = 0;
    long time = 0;

    for (int n = 0; n < N; n++) {
        deadline = p[n].first;
        time += p[n].second;
        if (deadline < time) {
            maniau = false;
        }
    }

    if (maniau) {
        cout << "Yes"
             << "\n";
    } else {
        cout << "No"
             << "\n";
    }

    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> x(n),y(n);
    vector<char> d(n);
    map<int,int> xconv, yconv;
    for(int i=0; i<n; i++){
        cin >> x[i] >> y[i] >> d[i];
        xconv[x[i]] = 0;
        yconv[y[i]] = 0;
    }
    
    int idx=0;
    for(auto &p: xconv) p.second = idx++;
    idx = 0;
    for(auto &p: yconv) p.second = idx++;
    
    vector<map<int,char>> xmap(n), ymap(n);
    for(int i=0; i<n; i++){
        xmap[xconv[x[i]]][yconv[y[i]]] = d[i];
        ymap[yconv[y[i]]][xconv[x[i]]] = d[i];
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        auto xx=xmap, yy=ymap;
        int cx=xconv[x[i]], cy=yconv[y[i]];
        int sub=0;
        while(1){
            sub++;
            char dir = xx[cx][cy];
            xx[cx].erase(cy);
            yy[cy].erase(cx);
            if(dir == '>'){
                auto itr = yy[cy].lower_bound(cx);
                if(itr == yy[cy].end()) break;
                cx = itr->first;
            }
            if(dir == '<'){
                auto itr = yy[cy].lower_bound(cx);
                if(itr == yy[cy].begin()) break;
                itr--;
                cx = itr->first;
            }
            if(dir == 'v'){
                auto itr = xx[cx].lower_bound(cy);
                if(itr == xx[cx].end()) break;
                cy = itr->first;
            }
            if(dir == '^'){
                auto itr = xx[cx].lower_bound(cy);
                if(itr == xx[cx].begin()) break;
                itr--;
                cy = itr->first;
            }
        }
        ans = max(ans, sub);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4224
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (int i = 0; i < M; ++i) cin >> X[i];
	sort(X.begin(), X.end());
	vector<int> L;
	for (int i = 1; i < M; ++i) L.push_back(X[i] - X[i - 1]);
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < M - N; ++i) ans += L[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1276
def solve():
    S = input()
    # print(S, len(S))

    S = S[::-1]
    words = ("dream"[::-1], "dreamer"[::-1], "erase"[::-1], "eraser"[::-1])

    i = 0
    while True:
        can = False
        for word in words:
            if S[i:i + len(word)] == word:
                i += len(word)
                can = True

        if i == len(S):
            return True

        if can is False:
            return False


if __name__ == '__main__':
    res = solve()
    if res:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 40432
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define Vl vector<ll>
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using T = ll;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;


int main(){
   int d, t, s;
   cin >> d >> t >> s;
   int res = (d + s - 1) / s;
   cout << (res > t ? "No" : "Yes") << endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k,i,h,j;
  cin >> n >> k;
  double ans=0;
  for(i=1;i<n+1;i++){
    h = 1;
    j = (i+k-1)/i;
    while(j > 1){
      h = h * 2;
      j = (j+1)/2;
    }
    ans += 1/(n * (double)h);
  }
  cout << setprecision(10) << ans << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  rep(i,N) cin >> A[i];
  
  sort(A.begin(),A.end());
  
  int ans = abs(A[0] - A[A.size() - 1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int rn[4], ln[4];

int main(void)
{
	double right, left;
	double EPS;
	int i;
	
	EPS = 1e-8;
	
	while (scanf("%lf %lf", &right, &left) != EOF){
		
		if (right >= 1.1){
			rn[0]++;
		}
		else if (right >= 0.6){
			rn[1]++;
		}
		else if(right >= 0.2){
			rn[2]++;
		}
		else {
			rn[3]++;
		}
		if (left >= 1.1){
			ln[0]++;
		}
		else if (left >= 0.6){
			ln[1]++;
		}
		else if(left >= 0.2){
			ln[2]++;
		}
		else {
			ln[3]++;
		}
	}
	for (i = 0; i < 4; i++){
		printf("%d %d\n", rn[i], ln[i]);
	}
	return (0);
}
			

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


int main() {
  long x;
  cin >> x;
  
  ll ans = x / 500 * 1000;
  ans += (x % 500) / 5 * 5;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define fo(i,n) for(i=0;i<n;i++)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define MAXN 1000002
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
void solve()
{
  map<int,int> um;
  int n;
  cin>>n;
  int c=3*10000;
  for(int i=1;i<=100;i++)
  {
    for(int j=1;j<=100;j++)
    {
      for(int k=1;k<=100;k++)
      {
        int val=(i+j)*(i+j)+(j+k)*(j+k)+(i+k)*(i+k);
        if(val>c)
        continue;
        um[val/2]++;
      }
    }
  }
  for(int i=1;i<=n;i++)
  {
    if(um.find(i)==um.end())
    cout<<0<<" ";
    else
    cout<<um[i]<<" ";
  }
}

int main()
{
  fastio
  solve();
}


Measured memory_bytes: 4280