akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn=1e6+10;
#define p 1000000007
int main(){
	fast;
	ll x,k,d; cin>>x>>k>>d;
	x=abs(x);
	ll move=min(x/d,k);
	x-=move*d;
	k-=move;
	if(k%2==0){
		cout<<x<<'\n';
	}
	else
		cout<<d-x<<'\n';
	return 0;
}
//prime func
//subset production
//factorization
//modpow
//modinv ( a^(p-2)=a^(-1) (mod p) )
//sieve
//ncr
//euler totien func (co prime divisiors upto n)
//matrix exponentation
//dsu
//Trees
//Graphs(dfs,bfs,shortes path etc.)
//DP-Recursion

Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100
int main(void){
	int n,m,i,j,z,A[N],B[N],C[1000],tmp,max=0,min=40,cnt=0;
	char s[N],str[N],*line;

	for( ;fgets(str,sizeof(str),stdin)!=NULL; ){
		line=strtok(str," ,");
		sscanf(line,"%d",&m);	
		line=strtok(NULL," ,");	
		sscanf(line,"%d",&n);
		if(m==0 && n==0)
			break;
		A[m]=n;
		B[m]=n;
		if(m>max)
			max=m;
		if(min>m)
			min=m;
		cnt++;
	}
	for(i=min;i<=max;i++){
		for(j=max;j>i;j--){	
			if(B[j] > B[j-1]){
				tmp = B[j-1];
				B[j-1] = B[j];
				B[j] = tmp;
			}
		}
	}
	j=0; B[cnt+1]=40;
	for(i=min;i<=cnt;i++){
		if(B[i]!=B[i+1])
			C[B[i]]=j++;
		else
			C[B[i]]=j;
	}
	for( ;fgets(s,sizeof(str),stdin)!=NULL; ){
		sscanf(s,"%d",&z);	
		printf("%d\n",C[A[z]]+1);
	}
	return 0;
}

Measured memory_bytes: 616
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

int main() {

	int n;
	cin >> n;

	map<char, int64_t> m;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin >> s;
		if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H')
			m[s[0]] += 1;
	}

	if (!m.size())
	{
		cout << "0" << endl;
		return 0;
	}

	string a = "MARCH";
	int64_t count = 0;
	for (int i = 0; i < m.size(); ++i)
		for (int j = i + 1; j < m.size(); ++j)
			for (int k = j + 1; k < m.size(); ++k)
				count += m[a[i]] * m[a[j]] * m[a[k]];

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int sum,i,a;
	char x[1000] = {0};

	scanf("%s", x);

	while(x[0]!='0'){
		sum = 0;
		i = 0;
		while(x[i]!='\0') {
			a= x[i] - '0';
			sum += a;
			i++;
		}

		printf("%d\n", sum);

		scanf("%s", x);
	}
	
	return 0;
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  ll dp[n+1][2];
  int a;
  cin >> a;
  if (a%2==0) {
    dp[0][0] = 1; dp[0][1] = 2;
  } else {
    dp[0][0] = 2; dp[0][1] = 1;
  }
  for (int i=1; i<n; ++i) {
    int a;
    cin >> a;
    if (a%2==0) {
      dp[i][0] = dp[i-1][0] * 3 + dp[i-1][1];
      dp[i][1] = dp[i-1][1] * 2;
    } else {
      dp[i][0] = dp[i-1][0] * 3 + dp[i-1][1] * 2;
      dp[i][1] = dp[i-1][1];
    }
  }
  cout << dp[n-1][0] << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  if(n==1){
    cout << "Hello World" << endl;
  }
  
  else{
    int a,b;
    cin >> a >> b;
    cout << a + b << endl;
  }
}

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

struct Card { char suit, value; };

void bubble(Card A[], int N){
  for (int i = 0; i < N; i++){
    for (int j = N - 1; j >= i + 1; j--){
      if(A[j].value < A[j-1].value) {
	Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
      }
    }
  }
}

void selection(Card A[], int N){
  for (int i = 0; i < N; i++){
    int minj = i;
    for (int j = i; j < N; j++){
      if(A[j].value < A[minj].value) minj = j;
    }
    Card t = A[i]; A[i] = A[minj]; A[minj] = t;
  }
}

void print(Card A[],  int N){
  for(int i = 0; i < N; i++){
    if(i > 0) cout << " ";
    cout << A[i].suit << A[i].value;
  }
  cout <<endl;
}

bool isStable(Card C1[], Card C2[], int N){
  for (int i = 0; i < N; i++) {
    if(C1[i].suit != C2[i].suit) return false;
  }
  return true;
}
int main(){
  Card C1[100], C2[100];
  int N;
  char ch;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> C1[i].suit >> C1[i].value;
  }

  for (int i = 0; i < N; i++) C2[i] = C1[i];

  bubble(C1, N);
  selection(C2, N);

  print(C1, N);
  cout << "Stable" << endl;
  print(C2, N);
  if( isStable(C1, C2, N)) {
    cout << "Stable" << endl;
  } else {
    cout << "Not stable" << endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>

using namespace std;

long long comb2(long long n) {
	return n * (n - 1) / 2;
}

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

	map<char, int> alpha;
	for (char c : s) {
		alpha[c]++;
	}

	long long ans = comb2(s.size()) + 1;
	for (auto p : alpha) {
		// printf("%c %d\n", p.first, p.second);
		if (p.second >= 2) {
			ans -= comb2(p.second);
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n:i64 = read();
    let an = read_vec::<i64>();
    let mut under_color = an.iter().map(|x| x / 400 ).filter(|x| *x < 8).collect::<Vec<_>>();
    under_color.sort();
    under_color.dedup();
    let under = under_color.len();
    let all_color = an.iter().filter(|&x| *x >= 3200).count();
    let max = under + all_color;
    let min = if under == 0{
        1
    } else {
        under
    };
    println!("{} {}",min ,max);
}

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

using namespace std;

const int mod = 998244353;

int add(int x, int y) {
  x += y;
  if(x >= mod) x -= mod;
  if(x < 0) x += mod;
  return x;
}

int sub(int x, int y) {
  x -= y;
  if(x >= mod) x -= mod;
  if(x < 0) x += mod;
  return x;
}

int mult(int x, int y) {
  return 1LL * x * y % mod;
}

int binpow(int x, int y) {
  int ret = 1;
  for(; y > 0; x = mult(x, x), y >>= 1) {
    if(y & 1) ret = mult(ret, x);
  }
  return ret;
}

int inverse_modulo(int x) {
  return binpow(x, mod - 2);
}

template<int N>
struct Combi{
  vector<int> fact, invfact;

  Combi() {
    fact.resize(N); invfact.resize(N);
    fact[0] = 1;
    for(int i = 1; i < N; ++i) fact[i] = mult(fact[i - 1], i);
    invfact[N - 1] = inverse_modulo(fact[N - 1]);
    for(int i = N - 1; i > 0; --i) {
      invfact[i - 1] = mult(invfact[i], i);
    }
  }

  int comb(int n, int k) {
    return mult(mult(fact[n], invfact[k]), invfact[n - k]);
  }
};

Combi <5050> f;

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

  int k, n;

  cin >> k >> n;
  for(int i = 2; i <= k + k; ++i) {
    int pairs = (i - 1) / 2;
    if(i > k) pairs -= i - k - 1;

    int ans = 0;
    for(int t = 0; t <= pairs; ++t) {
      int cand = n - t * 2;
      if(cand < 0) continue;

      if(i % 2 == 0) {
        int all = f.comb(cand + k - 1, k - 1);
        int exc = 0;
        if(cand > 1) exc = f.comb(cand + k - 3, k - 1);
        all = sub(all, exc);

        all = mult(all, f.comb(pairs, t));
        if(t % 2 == 0) ans = add(ans, all);
        else ans = sub(ans, all);
      }
      else {
        /// candies = cand
        /// bars = k
        int calc = f.comb(cand + k - 1, k - 1);

        calc = mult(calc, f.comb(pairs, t));
        if(t % 2 == 0) ans = add(ans, calc);
        else ans = sub(ans, calc);
      }
    }

    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 384
str=input()
str_list=str.split()
a=int(str_list[0])
b=int(str_list[1])
c=int(str_list[2])

if a > b:
    tmp=a
    a=b
    b=tmp
if a > c:
    tmp=a
    a=c
    c=tmp

if b > c:
    tmp=b
    b=c
    c=tmp

print(a,b,c)


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



int main(){
    int n;
    cin>>n;
    ll m;
    cin>>m;
    ll a[100005];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]%=m;
    }
    
    
    map<ll,ll> mod;
    ll sum[100005];
    sum[0]=0;
    mod[0]=1;
    for(int i=0;i<n;i++){
        sum[i+1]=a[i]+sum[i];
        sum[i+1]%=m;
        mod[sum[i+1]]++;
    }
   
    ll ans=0;
    for(auto i : mod){
        ans += (i.second*(i.second - 1)) / 2;
    }
    
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 4992
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12560
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;
ll mpow(ll a, ll b) { ll r = 1; a %= mod; while (b) { r = r * ((b % 2) ? a : 1) % mod, a = a * a % mod, b >>= 1; }return r; }



int main() {
	int n, x; cin >> n >> x;
	vector<int> a(n);
	rep(i, 0, n) cin >> a[i];
	rep(i, 0, n - 1)a[i + 1] += a[i];
	rep(i, 0, n) {
		if (a[i] > x) {
			printf("%d", i + 1);
			return 0;
		}
	}
	printf("%d", n + 1);
	return 0;
}


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

const int maxn = 100005;

vector<int> G[maxn];
int vis[maxn];

void DFS(int x)
{
	vis[x] = 1;
	for(int i = 0;i < G[x].size();++i)
	{
		int v = G[x][i];
		if(vis[v] == 0) DFS(v);
	}
}
int main()
{
	int N,M;
	cin>>N>>M;
	while(M--)
	{
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	int cnt = 0;
	for(int i = 1;i <= N;++i)
	{
		if(vis[i] == 0)
		{
			DFS(i);
			cnt++;
		}
	}
	cout<<cnt-1;
	return 0;
} 

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

int main(){
  int M,T,P,R;
  while(cin >> M >> T >> P >> R){
    if(M==0)break;
    vector<int> times(T,0), solved(T,0);
    vector< vector<int> > WA(T, vector<int>(10,0) );

    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin >> m >> t >> p >> j;
      t--; p--;
      if(j==0){
	solved[t]++;
	times[t] += m + WA[t][p] * 20;
      }else{
	WA[t][p]++;
      }
    }

    vector< vector<int> > rank;
    for(int i=0;i<T;i++){
      vector<int> tmp;
      tmp.push_back(-solved[i]);
      tmp.push_back(times[i]);
      tmp.push_back(-i);
     
      rank.push_back(tmp);
    }

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

    for(int i=0;i<T;i++){
      cout << -rank[i][2]+1;
      if(i+1==T)cout << endl;
      else if(rank[i][0] == rank[i+1][0] && rank[i][1] == rank[i+1][1]){
	cout << "=";
      }else cout << ",";
    }
  }
}

Measured memory_bytes: 1236
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    string abcd;
    cin >> abcd;
    int a, b, c, d;
    a = abcd.at(0) - '0';
    b = abcd.at(1) - '0';
    c = abcd.at(2) - '0';
    d = abcd.at(3) - '0';
    // cout << a << b << c << d << endl;
    vector<char> op(3);
    bool flag = false;
    ll tmp;

    for(size_t i = 0; i < (1 << 3); i++) {
        bitset<3> bi(i);
        // cout << bi << endl;
        tmp = a;
        if(bi.test(0)) {
            op.at(0) = '-';
            tmp -= b;
        } else {
            op.at(0) = '+';
            tmp += b;
            // cout << '+' << tmp;
        }

        if(bi.test(1)) {
            op.at(1) = '-';
            tmp -= c;
        } else {
            op.at(1) = '+';
            tmp += c;
            // cout << '+' << tmp;
        }

        if(bi.test(2)) {
            op.at(2) = '-';
            tmp -= d;
        } else {
            op.at(2) = '+';
            tmp += d;
            // cout << '+' << tmp;
        }
        // cout << tmp << endl;
        if(tmp == 7)
            break;
    }
    op.push_back('=');
    rep(i, 4) { cout << abcd.at(i) << op.at(i); }
    cout << 7;
}

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

using namespace std;

pair <long long, long long> arr[110];
long long DP[110][100010];

int main () {
    long long N,W;
    scanf("%lld%lld",&N,&W);
    for (int i=1;i<=N;i++ ){
        scanf("%lld%lld",&arr[i].first,&arr[i].second);
    }
    sort(arr+1,arr+N+1);
    for (int i=1;i<=N;i++) {
        for (int j=1;j<=W;j++) {
            if (j<arr[i].first) {
                DP[i][j]=DP[i-1][j];
            }
            else {
                DP[i][j]=max(DP[i-1][j],DP[i-1][j-arr[i].first]+arr[i].second);
            }
        }
    }
    cout << DP[N][W];
    return 0;
}



Measured memory_bytes: 79360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){

    int n, m, k;
    cin >> n >> m >> k;
    bool isOk = false;

    for(int i = 0; i <= m; i++)
    {
        for(int j = 0; j <= n; j++)
        {
            long long int black = i * n + j * m - i * j * 2;
            if(black == k){
                isOk = true;
                break;
            }
        }
        if(isOk){
            break;
        }
        
    }

    if(isOk){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    

    return 0;
}

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

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

    int N, X, Y;
    cin>>N>>X>>Y;

    int shortcut = Y-X;

    long long int ans[2000 + 5] = {};
    long long int temp = 0, goshort = 0;
    for(int i = 1; i <= N; i++)
        for(int j = i; j <= N; j++)
        {
            temp = j - i;
            goshort = abs(i - X) + 1 + abs(Y - j);

            // cout<<temp<<" "<<goshort<<endl;
            if(temp > goshort)
                ans[goshort]++;
            else
                ans[temp]++;
        }
    for(int i = 1; i <N; i++)
        cout<<ans[i]<<endl;



    return 0;
}


Measured memory_bytes: 256
import sys

#sys.stdin = open('input2.txt', 'r')
a_c = list(raw_input())
b_c = list(raw_input())
c_c = list(raw_input())
a_i, b_i, c_i = 0,0,0

def is_done(c):
	if c == 'a':
		if (a_i < len(a_c)):
			return False
		else:
			return True
	if c == 'b':
		if (b_i < len(b_c)):
			return False
		else:
			return True
	if c == 'c':
		if (c_i < len(c_c)):
			return False
		else:
			return True

if (len(a_c) == 0):
	print 'A'
	sys.exit()

n_c = a_c[a_i]
a_i = a_i + 1

while True:
	if n_c == 'a':
		if is_done('a'):
			print 'A'
			sys.exit()
		n_c = a_c[a_i]
		a_i = a_i + 1
	elif n_c == 'b':
		if is_done('b'):
			print 'B'
			sys.exit()
		n_c = b_c[b_i]
		b_i = b_i + 1
	else:
		if is_done('c'):
			print 'C'
			sys.exit()
		n_c = c_c[c_i]
		c_i = c_i + 1


Measured memory_bytes: 2696
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    x,a = LI()
    if x < a:
        return 0

    return 10


print(main())



Measured memory_bytes: 5712
s=int(input())

t=int(s**.5)
if t**2>=s:
    t-=1

if t*(t+1)<s:
    x1,y2=t+1,t+1
else:
    x1,y2=t,t+1

x2=x1*y2-s
y1=1

print(0,0,x1,y1,x2,y2)

Measured memory_bytes: 3060
a,b,c,d= gets.split.map(&:to_i)

require "set"
alice = Set.new((a..b).to_a)
bob = Set.new((c..d).to_a)


if  (alice & bob).to_a != []
 ab = (alice & bob).to_a
 puts ab[-1] - ab[0]
else
  puts 0
end

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

long long int n,a[200010],r[2025],ans,i,p[200010];
string s;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>s;n=s.size();
	p[n]=1;for (i=n-1;i>0;i--) p[i]=(p[i+1]*10)%2019;
	a[n+1]=0;
	for (i=n;i>0;i--) a[i]=(a[i+1]+p[i]*(s[i-1]-'0'))%2019;
	for (i=0;i<2019;i++) r[i]=0;
	for (i=1;i<n+2;i++) r[a[i]]++;
	ans=0;
	for (i=0;i<2019;i++) ans=ans+(r[i]*(r[i]-1))/2;
	cout<<ans;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;

vll adj[MAXN];ll visit[MAXN]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x;
string s,t;

// <------------- Implement Functions Here ----------> //



	ll a,b,c,d;

// <------------- Start of main() -------------------> //

void MAIN() {
	cin >> n;
	while(n--) {
		cin >> s;
		if(s == "AC") a++;
		if(s == "WA") b++;
		if(s == "TLE") c++;
		if(s == "RE") d++;
	}
	cout<<"AC x "<<a;newl;
	cout<<"WA x "<<b;newl;
	cout<<"TLE x "<<c;newl;
	cout<<"RE x "<<d;newl;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}


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

a = input().split()
for i in range(len(a)):
    a[i] = int(a[i])
tot = sum(a)
a = sorted(a, reverse=True)
count = 0
for j in range(len(a)):
    max = a[0]
    if max < tot / 4 / m:
        break
    count += 1
    a.pop(0)

if count >= m:
    print('Yes')
else:
    print('No')

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

typedef long long ll;
const ll MOD = 1e9 + 7;

//http://tutuz.hateblo.jp/entry/2018/08/12/014351
int main() {
  int n;
  cin >> n;
  
  string s = "";
  while(n != 0) {
    if (n % 2 != 0) {
      n--;
      s += "1";
    } else {
      s += "0";
    }
    n /= -2;
    // cout << n << endl;
  }
  
  reverse(s.begin(), s.end());
  if (s == "") {
    s = '0';
  }
  
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

struct LowestCommonAncestor{
  ll n,h;
  vector< vector<ll> > G,par;
  vector<ll> dep;
  LowestCommonAncestor(){}
  LowestCommonAncestor(ll n):n(n),G(n),dep(n){
    h=1;
    while((1<<h)<=n) h++;
    par.assign(h,vector<ll>(n,-1));
  }

  void add_edge(ll u,ll v){
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  void dfs(ll v,ll p,ll d){
    par[0][v]=p;
    dep[v]=d;
    for(ll u:G[v])
      if(u!=p) dfs(u,v,d+1);
  }

  void build(ll r=0){
    dfs(r,-1,0);
    for(ll k=0;k+1<h;k++)
      for(ll v=0;v<n;v++)
        if(~par[k][v])
          par[k+1][v]=par[k][par[k][v]];
  }

  ll lca(ll u,ll v){
    if(dep[u]>dep[v]) swap(u,v);
    for(ll k=0;k<h;k++)
      if((dep[v]-dep[u])>>k&1)
        v=par[k][v];

    if(u==v) return u;

    for(ll k=h-1;k>=0;k--)
      if(par[k][u]!=par[k][v])
        u=par[k][u],v=par[k][v];

    return par[0][u];
  }

  ll distance(ll u,ll v){
    return dep[u]+dep[v]-dep[lca(u,v)]*2;
  }
};
 
int main() {
  ll n;
  cin >> n;
  LowestCommonAncestor lca(n);
  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin >> a >> b;
    a--;b--;
    lca.add_edge(a,b);
  }
  lca.build();
  ll f=0;
  ll s=0;
  for(ll i=0;i<n;i++) {
    if(lca.distance(0,i)<=lca.distance(n-1,i)) {
      f++;
    }
    else {
      s++;
    }
  }
  if(f>s) {
    cout << "Fennec" << endl;
  }
  else {
    cout << "Snuke" << endl;
  }
}

Measured memory_bytes: 23536
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;

    vector<int64_t> hs(n);
    for (auto& h : hs)
    {
        cin >> h;
    }

    vector<int64_t> max_hs(n, 0);

    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        max_hs[a] = max(max_hs[a], hs[b]);
        max_hs[b] = max(max_hs[b], hs[a]);
    }

    int count = 0;
    for (int i = 0; i < n; i++)
    {
        if (hs[i] > max_hs[i])
        {
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 4412
n = int(input())
An = [int(x) for x in input().split()]
An.sort(reverse=True)

if 0 in An:
    print(0)
    exit()

j = 10 ** 18
ans = 1
for i in range(n):
    if ans > j:
        print(-1)
        quit()
    ans *= An[i]

if ans > j :
    print(-1)
    
else :
    print(ans)



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

#define mk make_pair
#define pb push_back

typedef long long lld;
typedef pair<lld,lld> pr;
typedef priority_queue <lld> max_heap;
typedef priority_queue <lld, vector<lld>, greater<lld> > min_heap;
lld const mod = 1e9+7;

lld power(lld x, lld y)
{
    lld res = 1;
    while (y > 0) {
        if (y & 1)
            res = res * x;
        y = y >> 1;
        x = x * x;
    }
    return res;
}

lld power_mod(lld base, lld y)
{
    lld t = 1;
    while (y > 0)
    {

        if (y % 2 != 0)
            t = (t * base) % mod;
        base = (base * base) % mod;
        y /= 2;
    }
    return t % mod;
}

lld nCrModp(lld n, lld r, lld p)
{
    if (r > n - r)
        r = n - r;
    lld C[r + 1]={0};
    C[0] = 1;

    for (lld i = 1; i <= n; i++)
    {
      for (lld j = min(i, r); j > 0; j--)
      {
        C[j] = (C[j] + C[j - 1]) % p;

      }
    }
    return C[r];
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  lld t;
  cin>>t;
  if(t>=30)
  {
    cout<<"Yes\n";
  }
  else
  {
    cout<<"No\n";
  }

}


Measured memory_bytes: 3640
#include <stdio.h>


int main (void) {
	int a, b, c, tmp;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if ( a == b && b == c && a == c) {
		printf("%d %d %d\n", a, b, c);
	}
	else {
		tmp = a;
		a = b;
		b = tmp;
		
		tmp = a;
		a = c;
		c =tmp;
		
		printf("%d %d %d\n", a, b, c);
	}
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
 cin>>s;
 if((s.size()%2==0 && s[0]!=s[s.size()-1]) || (s.size()%2!=0 && s[0]==s[s.size()-1]))cout<<"Second"<<endl;
 else cout<<"First"<<endl;
 return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
const int N = 2005;
ll M = 1e9 + 7;
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} }
ll dp[N][N];

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int n; cin>>n;
	vector < pair <ll,ll> > v(n);
	for(int i=1;i<=n;i++)
	{
	    cin>>v[i-1].ff; v[i-1].ss = i;
	}
	sort(v.begin(),v.end());
	reverse(v.begin(),v.end());
	ll ans = -1;
	for(int i=0;i<=n;i++)
	{
	    for(int j=0;j<=n;j++)
	    {
	        if( i+j == n )
	        {
	            ans = max(ans,dp[i][j]);
	            break;
	        }
	        dp[i+1][j] = max(dp[i+1][j],dp[i][j]+abs(v[i+j].ss-i-1)*v[i+j].ff);
	        dp[i][j+1] = max(dp[i][j+1],dp[i][j]+abs(v[i+j].ss-n+j)*v[i+j].ff);
	    }
	}
	cout<<ans;
	
	return 0;
}


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

int N,ans;
int A[100];

void show(){
    rep(i,0,N){
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
}

void selectionSort(){
    rep(i,0,N){
        int minj = i;
        rep(j,i,N){
            if(A[j] < A[minj]) minj = j;
        }
        if(i != minj) {
            swap(A[i], A[minj]);
            ans++;
        }
    }
}

int main() {
    scanf("%d", &N);
    rep(i,0,N) scanf("%d", &A[i]);
    ans=0;
    selectionSort();
    show();
    printf("%d\n",ans);
}


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

public class Main {
	private StringTokenizer st;
	private BufferedReader bf;
	private int n;
	private int m;
	
	Main() {
		readData();
		
		System.out.println((n*m) + " " + (2*n+2*m));
	}
	
	private void readData() {
		try {
			bf = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(bf.readLine());
			n = nextInt();
			m = nextInt();
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private int nextInt() throws IOException {
		return Integer.parseInt(next());
	}
	
	private String next() throws IOException {
		if (st == null || !st.hasMoreTokens())
			st = new StringTokenizer(bf.readLine());
		return st.nextToken();
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Main m = new Main();
	}

}

Measured memory_bytes: 16860
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main() {
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output1.txt", "w", stdout);
    #endif*/
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.size(); int n2=s2.size();
    int dp[n1+1][n2+1];
    for(int j=0;j<=n2;j++){
        dp[n1][j]=0;
    }
    for(int i=0;i<=n1;i++){
        dp[i][n2]=0;
    }
    for(int i=n1-1;i>=0;i--){
        for(int j=n2-1;j>=0;j--){
            if(s1[i]==s2[j]){
                dp[i][j]=1+dp[i+1][j+1];
            }
            else{
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
            }
        }
    }
    string ans="";
    int i=0; int j=0;
    while(i<n1 && j<n2){
        if(s1[i]==s2[j]){
                ans+=s1[i];
                i++; j++;
            }
            else{
                if(dp[i+1][j] >= dp[i][j+1] ? i++ : j++ );
            }
    }
    cout<<ans;
}

Measured memory_bytes: 35456
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 100005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  ll a,b,c;
  cin>>a>>b>>c;
  ll tt = c - a - b;
  if(tt<=0){
    cout<<"No"<<endl;
    return 0;
  }
  ll tmp2 = tt * tt - 4 * a * b;
  if(tmp2>0)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
// const input = fs.readFileSync('./input.txt', 'utf8');

_d(input);

function _d(input: string) {
  const [_NM, ..._AB] = input.split('\n');
  _AB.pop(); // empty line

  const [N, M] = _NM.split(' ').map((s) => parseInt(s));
  const AB = _AB.map(
    (s) => s.split(' ').map((s) => parseInt(s)) as [number, number]
  );

  const directFriends: Set<number>[] = Array.from({ length: N }).map(
    () => new Set<number>()
  ); // a-1 と直接友達な人の添え字 [...b-1]
  for (let i = 0; i < AB.length; i++) {
    const [Ai, Bi] = AB[i];
    directFriends[Ai - 1].add(Bi - 1);
    directFriends[Bi - 1].add(Ai - 1);
  }

  let maxFriendsNum = 0; // 最も大きな「友達関係」の人数
  const searched = new Set<number>(); // 探索済みフラグ

  for (let i = 0; i < N; i++) {
    if (searched.has(i)) continue; // 計算済み（過去に計算された友達関係の中に含まれていた）

    // 友達の数を数える
    const friends = new Set([i]); // 発見された全ての友達の添え字セット
    const pool = [i]; // 探索すべき添え字のリスト

    // 再帰的に探索スタート
    while (pool.length > 0) {
      const target = pool.pop();
      if (target === undefined) continue; // type hint

      if (searched.has(target)) continue; // 探索ずみ
      searched.add(target); // 探索済みをチェックする

      for (const j of Array.from(directFriends[target])) {
        friends.add(j); // 友達に追加
        if (!searched.has(j)) {
          pool.push(j); // 友達の友達をさらに追跡
        }
      }
    }

    maxFriendsNum = Math.max(maxFriendsNum, friends.size); // 最大値を更新
    if (maxFriendsNum >= N / 2) {
      break; // 半数以上の友達関係を見つけた
    }
  }

  console.log(maxFriendsNum); // 最も大きな「友達関係」の人数が、少なくとも必要なグループの数になる
}


Measured memory_bytes: 158072
city = [0, 0, 0, 0]

for _ in range(3):
  a, b = map(lambda x : int(x), input().split())
  city[a-1] += 1
  city[b-1] += 1

two = 0

for i in range(4):
  if city[i] == 2:
    two += 1

if two == 2:
  print("YES")
else:
  print("NO")




Measured memory_bytes: 3060
#include <iostream>
#include <list>
#include <algorithm>

using namespace std;

int main() {
	int n;
	list<int> ans;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;

		if (i % 2 == 0) ans.push_back(tmp);
		else ans.push_front(tmp);
	}

	if (n % 2 == 1) {
		reverse(ans.begin(), ans.end());
	}

	for (auto b : ans) {
		cout << b << " ";
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 8448
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();

    int cou = 0;
    int ans = 0;
    for(int i=1; i<=N; i+=2) {    
    	for(int j=1; j<=N; j++) {
    		if(i%j== 0) {
    			cou++;
    		}
    	}
    	if(cou==8) {
    		ans++;
     }
    	cou = 0;
    }
    	System.out.println(ans);
      }
}



Measured memory_bytes: 35684
#include<bits/stdc++.h>
#define int long long
using namespace std;

int n, q;
int s[1000010];
string q1[1010];
int q2[1010];

int ss[1000010];
set<int> nl;

bool judge(vector<int> *ls, int x, int mid)
{
  int rem = n, pr = 2e9;
  for(int i = 0; i < ls->size(); i++){
    rem -= (upper_bound(ss, ss + n, min(pr - 1, ls->at(i))) - ss)
      - (lower_bound(ss, ss + n, ls->at(i) - mid) - ss);
    pr = ls->at(i) - mid;
  }
  return rem <= x;
}

void solve(int x)
{
  vector<int> ls;
  for(set<int>::iterator p = nl.begin(); p != nl.end(); p++){
    ls.push_back(s[*p]);
  }
  sort(ls.begin(), ls.end(), greater<int>());
  ls.erase(unique(ls.begin(), ls.end()), ls.end());

  if(x == n){
    cout << 0 << endl;
    return;
  }
  if(ls.empty() || n - (upper_bound(ss, ss + n, ls[0]) - ss) > x){
    cout << "NA" << endl;
    return;
  }

  int rs = 0, re = 1e9;

  while(rs < re){
    int mid = (rs + re) / 2;
    if(judge(&ls, x, mid)){
      re = mid;
    }
    else{
      rs = mid + 1;
    }
  }
  
  cout << rs << endl;
  return;
}

signed main()
{
  cin >> n >> q;
  for(int i = 1; i <= n; i++){
    cin >> s[i];
    ss[i - 1] = s[i];
  }
  for(int i = 1; i <= q; i++){
    cin >> q1[i] >> q2[i];
  }

  sort(ss, ss + n);

  for(int i = 1; i <= q; i++){
    if(q1[i] == "ADD"){
      nl.insert(q2[i]);
    }
    else if(q1[i] == "REMOVE"){
      nl.erase(q2[i]);
    }
    else{
      solve(q2[i]);
    }
  }

  return 0;
}

Measured memory_bytes: 16928
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;
using namespace std;

#define mod 1000000007
#define INF 2147483647
#define LLINF 2000000000000000000LL
#define PI 3.141592653589793

#define SIZE 200000


/* RangeMinimumQuery */
//0-index
struct RMQ{
    typedef int Type; //?????¨?????????(???????????\?????°OK)
    int segn2;
    vector<Type> data;
    
    RMQ(int n){
        segn2=1;
        while(segn2<n) segn2*=2;
        
        data.assign(segn2*2,INF);
    }
    
    //????????????????°????????±???????[a,b]
    Type query(int a,int b,int l=0,int r=-1,int k=0){
        
        if(r==-1) r+=segn2;
        
        if(a<=l && r<=b) return data[k];
        if(r<a || b<l) return INF;
        
        return min(query(a,b,l,(l+r)/2,k*2+1),query(a,b,(l+r)/2+1,r,k*2+2));
    }
    
    //k?????????????´????x?????????
    void set(int k,Type x){
        k+=segn2-1;
        data[k]=x;
        
        while(k>0){
            k=(k-1)/2;
            data[k]=min(data[k*2+1],data[k*2+2]);
        }
        
        return;
    }
};


int main(){
    int n,q,a,b,c;
    RMQ rmq(100000);
    
    scanf("%d%d",&n,&q);
    
    for(int i=0;i<q;i++){
        scanf("%d%d%d",&a,&b,&c);
        
        if(a==0){
            rmq.set(b,c);
        }else{
            printf("%d\n",rmq.query(b,c));
        }
    }
    
    
    return 0;
}

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

int count(string S, int K, int N){
    for (int i=0; i<N; i++){
        if (S[i] == 'L')
            K--;
        while (S[i] == 'L'){
            S[i] = 'R';
            i++;
        }
        if (K==0) break;
    }

    int cnt = 0;
    for(int i=0; i<N; i++){
        if(S[i] == 'R' && i+1 < N && S[i+1] == 'R'){
            cnt++;
        }else if(S[i] == 'L' && i-1 >= 0 && S[i-1] == 'L'){
            cnt++;
        }
    }
    return cnt;
}

int main(){
    int N, K;  cin >> N >> K;
    string S;  cin >> S;
    string T;
    for(int i=0; i<N; i++){
        if(S[i]=='R') T += "L";
        if(S[i]=='L') T += "R";
    }

    cout << max(count(S, K, N), count(T, K, N)) << endl;
}

Measured memory_bytes: 640
# coding: utf-8
# Your code here!

while True :
    n = int(input())
    if n == 0 :
        break
    
    cnt = list([0] * 10)
    for i in range(n) :
        cnt[int(input())] += 1
    

    for i in range(10) :
        if cnt[i] > 0 :
            for j in range(cnt[i]) :
                print("*", sep="", end="")
            print()
        else :
            print("-")


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

using namespace std;

struct es{int node,cost; es(int n , int c) { node = n , cost = c; } };

vector <es>graph[100008];

int n , a , b , c ; 

pair<int,int> maxDistance(int node, int parent){
	pair<int,int> best = make_pair(0,node);
	for(es son: graph[node] ) {
		if(son.node!=parent ) {
			pair<int,int> proposal = maxDistance(son.node,node);
			proposal.first+=son.cost;
			best = max(best,proposal);		
		}
	}
	return best;
}

int diameter(int node){
	pair<int,int> farthestFromRoot = maxDistance(0,0);
	return maxDistance(farthestFromRoot.second,farthestFromRoot.second).first;
}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n ; 	
	for(int i = 1 ; i < n ; i ++ ) cin >> a >> b >> c , graph[a].push_back(es(b,c)) , graph[b].push_back(es(a,c));
	cout << diameter(0) << "\n";
	return 0;
}


Measured memory_bytes: 16452
import sys
input = sys.stdin.readline

k, s = map(int, input().split())
cnt = 0
max_v = max(2 * (k + 2), s + 1)
memo = [0] * max_v
for i in range(k + 1):
  for j in range(k + 1):
    v = i + j
    if v > s:
      break
    memo[v] += 1
for i in range(k + 1):
  for j in range(max_v):
    v = i + j
    if v > s:
      break
    elif v == s:
      cnt += memo[j]
print(cnt)


Measured memory_bytes: 41436
import java.util.*;

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

	public Main() {
		new AOj0144().doIt();
	}
	
	class AOj0144{
		int n,d[][];
		
		void print(){
			for(int i=1;i<=n;i++){
				System.out.print(i+": ");for(int s=1;s<=n;s++)System.out.printf("%7d ",d[i][s]);
				System.out.println();
			}
		}
		
		void doIt(){
			n = Integer.parseInt(in.nextLine());			
			d = new int[n+1][n+1];
			for(int i=0;i<=n;i++)Arrays.fill(d[i],100000);
			for(int i=0;i<n;i++)d[i][i] = 0;
			for(int i=0;i<n;i++){
				int num = in.nextInt();
				int w = in.nextInt();
				for(int s=0;s<w;s++)d[num][in.nextInt()] = 1;
			}
			for(int k=1;k<=n;k++)for(int i=1;i<=n;i++)for(int j=1;j<=n;j++){
				d[i][j] = Math.min(d[i][j],d[i][k]+d[k][j]);
			}
			
//			print();
			
			int packet = in.nextInt();
			for(int s=0;s<packet;s++){
				int start = in.nextInt();
				int end = in.nextInt();
				int ttl = in.nextInt();
				if(d[start][end]==100000||d[start][end]>=ttl)System.out.println("NA");
				else System.out.println(d[start][end]+1); 
			}
		}
		
	}
}

Measured memory_bytes: 25872
#!/usr/bin/env python3
import sys

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

def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    for i in range(A - 1, C - 1):
        if S[i:i + 2] == '##':
            ret = NO
            print(ret)
            return
    for i in range(B - 1, D - 1):
        if S[i:i + 2] == '##':
            ret = NO
            print(ret)
            return
    if D < C:
        ret = NO
        for i in range(B - 2, D - 1):
            if S[i:i + 3] == '...':
                ret = YES
                break

    #if '##' in S[A - 1:C] or '##' in S[B - 1:D]:
    #    ret = NO
    #else:
    #    if D < C:
    #        #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
    #        if not '...' in S[B - 2:D + 1]:
    #            ret = NO
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)

if __name__ == '__main__':
    main()


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

int main(){
    ll N,total=0;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);
    rep(i,N+1) cin >> A[i];
    rep(i,N) cin >> B[i];
    
    rep(i,N){
        if(A[i]<=B[i]){
            B[i]=B[i]-A[i];
            total+=A[i];
        }else{
            total+=B[i];
            B[i]=0;
        }
        
        if(A[i+1]<=B[i]){
            total+=A[i+1];
            A[i+1]=0;
        }else{
            A[i+1]=A[i+1]-B[i];
            total+=B[i];
        }
    }
    cout << total << endl;

    return 0;
}

Measured memory_bytes: 1792
// atcoder/abc123/B/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int a, b, c, d, e;
  while (cin >> a >> b >> c >> d >> e) {
    vector<int> v({a, b, c, d, e});
    int mn = 1 << 29;
    sort(v.begin(), v.end());
    do {
      int mx = 0;
      int t = 0;
      each (i, v) {
        t += i;
        setmax(mx, t);
        if (t % 10) t = t + 10 - (t % 10);
      }
      setmin(mn, mx);
    } while (next_permutation(v.begin(), v.end()));
    cout << mn << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <array>
#include <map>
#include <string>
using namespace std;
#define ll long long

int main(void)
{
  int n;
  ll ans=0,a,b;
  cin >> n >> a >> b;
  vector<ll> x(n,0);
  for(int i=0;i<n;i++)
    {
      cin >> x[i];
    }
  for(int i=0;i<n-1;i++)
    {
      ans+=min((x[i+1]-x[i])*a,b);
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000009
#define ll long long
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set0(a) memset ((a), 0 , sizeof(a))
#define set1(a) memset((a),-1,sizeof (a))
#define pi pair<int, int>
#define ps pair<string, string>
#define pl pair<long, long>
#define pll pair<long long, long long>
#define vll vector<long long>
#define vl vector<long>
#define vi vector<int>
#define vs vector<string>
#define vps vector< ps >
#define vpi vector< pi >
#define vpl vector< pl >
#define vpll vector< pll >
#define flash  ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc(t,T) for(long long t=0;t<T;t++)
#define rep(i,s,n,d) for(long long i=s;i<n;i=i+d)

bool sortbysec(const pll &a,
              const pll &b)
{
    return (a.second < b.second);
}
/*bool cxp pair<ll, pll> &a,
              const pair<ll, pll> &b)
{
    return (a.ff < b.ff);
}*/

void func(void)
{
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    else return gcd(b,a%b);
}
void printStack(stack<string> s){
    if(s.empty())return;

    string x=s.top();
    s.pop();
    printStack(s);
    cout<<x;
    s.push(x);

}


ll binaryexp(ll n,ll p){

    if(p==0) return 1;
    if(p%2==0) return binaryexp((n%mod)*(n%mod),p/2);
    else return ((n%mod)*binaryexp(((n%mod)*(n%mod))%mod,(p-1)/2)%mod);

}

#define meax 10000001
vll spf(meax,0);
void siv(){
    spf[1]=1;

   for(ll i=2;i<meax;i++)spf[i]=i;

   for(ll i=4;i<meax;i+=2){
        spf[i]=2;
    }
    for(ll i=3;i*i<meax;i++){
        if(spf[i]==i){
            for(ll j=i*i;j<meax;j+=i){
                if(spf[j]==j){
                    spf[j]=i;
                }
            }
        }
    }
}


int main(){
    string s,t;
    cin>>s>>t;
    map<char,char> m1,m2;
    int flag=0;
    for(int i=0;i<s.size();i++){

        if(m1.find(s[i])==m1.end()){
            m1[s[i]]=t[i];
        }
        else{
            if(m1[s[i]]==t[i])continue;
            else{
                flag=1;
                break;
            }
        }
        if(m2.find(t[i])==m2.end()){
            m2[t[i]]=s[i];
        }
        else{
            if(m2[t[i]]==s[i])continue;
            else{
                flag=1;
                break;
            }
        }

    }


    if(flag==1)cout<<"No\n";
    else cout<<"Yes\n";
}


Measured memory_bytes: 82060
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

using pi = pair<int, int>;

void bit_full_search() {
    int n = 5;
    for (int bit = 0; bit < (1 << n); ++bit) {
        for (int i = 0; i < n; ++i) {
            if (bit & (1 << i)) {
                // implement me
                // ith bit flg is on
            }
        }
    }
}

void Main() {
	int N; cin >> N;
	vector<vector<pi>> As(N, vector<pi>());
	REP(i, N) {
		int a; cin >> a;
		REP(j, a) {
			int x, y; cin >> x >> y;
			--x;
			As[i].push_back(make_pair(x, y));
		}
	}
	int res = 0;
    for (int bit = 0; bit < (1 << N); ++bit) {
		int cnt = 0;
		bool flg = false;
		for (int i = 0; i < N; ++i) {
            if (bit & (1 << i)) {
				cnt++;
				for (auto p : As[i]) {
					bool shojiki = bit & (1 << p.first);
					if ((shojiki && p.second == 0) || (!shojiki && p.second == 1)) {
						flg = true;
					}
				}
            }
        }
		if (!flg) {
			res = max(res, cnt);
		}
	}
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;
long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz");
char s[101][101];
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

int main(void){
  
       cin.tie(0);
    ios::sync_with_stdio(false);
      
      cin>>h>>w;
      rep(i,h)rep(j,w)cin>>s[i][j];
      rep(i,h){
        rep(j,w){
          if(s[i][j]=='.')continue;
          fl=false;
          rep(k,4){
            int nx=j+dx[k],ny=i+dy[k];
            if(nx>=0&&nx<w&&ny>=0&&ny<h&&s[ny][nx]=='#')fl=true;
          }
          if(!fl){
            Cout("No");
            return 0;
          }
        }
      }
    Cout("Yes");
       
return 0;
}


Measured memory_bytes: 256