akhauriyash/Code-Regression huggingface dataset:
#ifndef _GLIBCXX_DEBUG
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define vrep(v,it) for(auto it = v.begin(); it != v.end(); it++)
#define vrepr(v,it) for(auto it = v.rbegin(); it != v.rend(); it++)
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,...) do { cerr << #v << " = "; array_out(v , __VA_ARGS__ );} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
 
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
/////////////////

void solve(){
  ini(N , M);
  map<int,int> m;
  int cur = 0; m[cur]++;
  rep(i , N){
    ini(x);
    cur = (cur + x) % M;
    m[cur]++;
  }
  ll ans = 0;
  each(v , m){
    ans += 1LL * v.se * (v.se - 1) / 2;
  }
  out(ans);
  
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 1001001001001001001;  // > 10^18
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;

int main () {

    string s; cin >>s;
    
    int count = 0;
    for (int i = 1; i < (int)s.length(); ++i) {
        if (s[i-1] != s[i]) {
            count++;
        } 
    }
    cout << count << endl;
    
    return 0;
}





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

using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<int>a(n);
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        sum+=a[i];
    }
    sort(a.rbegin(),a.rend());
    int c=4*m*a[m-1];
    if(c<sum)puts("No");
    else puts("Yes");
    return 0;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[0].split(" ")[1]);
    
    console.log(A * B);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

using namespace std;
const int MAXN = 100000;

int A[MAXN + 1];
int B[MAXN + 1];
int C[MAXN + 1];
long long can[MAXN + 1];

bool camp(int, int);

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &B[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &C[i]);
	sort(A + 1, A + n + 1, camp);
	sort(B + 1, B + n + 1, camp);
	sort(C + 1, C + n + 1, camp);
	for (int i = 1; i <= n; i++) {
		int left = 0;
		int right = n + 1;
		while (left != right) {
			int mid = (left + right) >> 1;
			if (C[mid] <= B[i]) left = mid + 1;
			else right = mid;
		}
		can[i] = n - left + 1;
//		printf("%d ", n - left + 1);
	}
//	printf("\n");
	for (int i = n - 1; i >= 1; i--) can[i] += can[i + 1];
	long long ans = 0;
	for (int i = 1; i <= n; i++) {
		int left = 0;
		int right = n + 1;
		while (left != right) {
			int mid = (left + right) >> 1;
			if (B[mid] <= A[i]) left = mid + 1;
			else right = mid;
		}
//		for (int j = n; j >= left; j--) ans += can[j];
		ans += can[left];
//		printf("%d ", left);
	}
//	printf("\n");
	printf("%lld\n", ans);
	return 0;
}

bool camp(int a, int b) {
	return a < b;
}

Measured memory_bytes: 2176
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int ans = 0;
        for(int i = 0; i < s.length/2; i++){
            if(s[i] != s[s.length-i-1]){
                ans++;
            }
        }
        System.out.println(ans);
    }
}



Measured memory_bytes: 23124
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <cstdlib>
using namespace std;
using ll = long long int;
using ull = unsigned long long;
int INF = 1e9+7;
ll A[100005];
ll B[100005];
pair<ll,ll> C[100005];

int main() {
    int N;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
        C[i].first = A[i]+B[i];
        C[i].second = i;
    }
    sort(C,C+N);
    reverse(C,C+N);
    ll total = 0;
    for (int i = 0; i < N; i++) {
        if (i%2 == 0)
            total += A[C[i].second];
        else
            total -= B[C[i].second];
    }
    cout << total << endl;
}


Measured memory_bytes: 3328
import heapq
N = int(input())
c = input()
w = []
r = []
for i, s in enumerate(c):
    if s == 'R':
        r.append(-i)
    else:
        w.append(i)
minrw = min(len(r), len(w))
        
heapq.heapify(r)
heapq.heapify(w)
ans = 0
while r and w:
    rq = -heapq.heappop(r)
    wq = heapq.heappop(w)
    if rq < wq: break
    else:
        heapq.heappush(r, -wq)
        heapq.heappush(w, rq)
        ans += 1
        if ans >= minrw:
            ans = minrw
            break

print(ans)

Measured memory_bytes: 17460
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <utility>
using namespace std;

typedef pair<int, int> P;

const int INF = (int)1e9;

int main() {
  int N; scanf("%d", &N);
  // E[from] = [(to, cost)]
  vector<vector<P> > E(N);
  for(int i = 0; i < N - 1; i++) {
    int s, t, c; scanf("%d%d%d", &s, &t, &c);
    E[s].emplace_back(t, c);
    E[t].emplace_back(s, c);
  }
  // (total_distance, to)
  priority_queue<P, vector<P>, greater<P> > Q;
  vector<int> d(N, INF);
  int last = -1;
  Q.emplace(0, 0);
  while(Q.empty() == false) {
    P p = Q.top(); Q.pop();
    if(p.first > d[p.second]) continue;
    d[p.second] = p.first;
    last = p.second;
    for(P e : E[p.second]) {
      if(p.first + e.second < d[e.first]) {
        d[e.first] = p.first + e.second;
        Q.emplace(d[e.first], e.first);
      }
    }
  }

  d.assign(N, INF);
  int last2 = -1;
  Q.emplace(0, last);
  while(Q.empty() == false) {
    P p = Q.top(); Q.pop();
    if(p.first > d[p.second]) continue;
    d[p.second] = p.first;
    last2 = p.second;
    for(P e : E[p.second]) {
      if(p.first + e.second < d[e.first]) {
        d[e.first] = p.first + e.second;
        Q.emplace(d[e.first], e.first);
      }
    }
  }
  printf("%d\n", d[last2]);
}

Measured memory_bytes: 7692
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int dx[]= {0, 0, 1, -1};
int dy[]= {1, -1, 0, 0};
int dist[1001][1001];
bool vis[1001][1001];

void solve() {
        int n, m; cin >> n>> m;
        int sx, sy; cin >> sx>> sy;
        int ex, ey; cin >> ex>> ey;
        sx--, sy--, ex--, ey--;

        vector<string> v(n);

        for (auto& i: v) cin >> i;

        for (int i= 0; i<= n; i++) for (int j= 0; j<= m; j++) dist[i][j]= 2e9;
        for (int i= 0; i<= n; i++) for (int j= 0; j<= m; j++) vis[i][j]= 0;

        deque<pair<pair<int, int>, int>> dq;
        dist[sx][sy]= 0;
        dq.push_back({{sx, sy}, 0});

        while (dq.size()) {
                int x= dq.front().first.first;
                int y= dq.front().first.second;
                int cst= dq.front().second;
                dq.pop_front();

                if (vis[x][y]) continue;
                vis[x][y]= 1;

                for (int i= 0; i< 4; i++) {
                        int tox= x+ dx[i];
                        int toy= y+ dy[i];

                        if (tox< 0|| toy< 0|| tox>= n|| toy>= m|| v[tox][toy]== '#') {
                                continue;
                        }
                        if (dist[tox][toy]> dist[x][y]) {
                                dist[tox][toy]= dist[x][y];
                                dq.push_front({{tox, toy}, cst});
                        }
                }
                for (int j= -2; j<= 2; j++)
                for (int i= -2; i<= 2; i++) {
                        int tox= x+ j;
                        int toy= y+ i;

                        if (tox< 0|| toy< 0|| tox>= n|| toy>= m|| v[tox][toy]== '#') {
                                continue;
                        }

                        if (dist[tox][toy]> dist[x][y]+ 1) {
                                dist[tox][toy]= dist[x][y]+ 1;
                                dq.push_back({{tox, toy}, cst+ 1});
                        }

                }
        }

        cout << (dist[ex][ey]== 2e9? -1: dist[ex][ey])<< "\n";

}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


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

const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};


int main(){
	int h, w, si, sj, gi, gj;
  	cin >> h >> w >> si >> sj >> gi >> gj;
  	si--; sj--; gi--; gj--;
  	vector<string> s(h);
  	rep(i, h) cin >> s[i];
  	const int INF = 1e9;
  
  	vector<vector<int>> dist(h, vector<int>(w, INF));
  	deque<P> q;
  	dist[si][sj] = 0;
  	q.emplace_back(si, sj);
  	while(!q.empty()){
    	int i = q.front().first;
        int j = q.front().second;
      	q.pop_front();
        int d = dist[i][j];
      
      	//歩きの処理
      	rep(v, 4){
        	int ni = i+di[v], nj = j+dj[v];
          	if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          	if(s[ni][nj] == '#') continue;
          	if(dist[ni][nj] <= d) continue;
          	dist[ni][nj] = d;
            q.emplace_front(ni, nj);
        }
         
        //ワープの処理
      	for(int ei = -2; ei <= 2; ei++){
        	for(int ej = -2; ej <= 2; ej++){
            	int ni = i+ei, nj = j+ej;
              	if(ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
          		if(s[ni][nj] == '#') continue;
          		if(dist[ni][nj] <= d+1) continue;
              	dist[ni][nj] = d+1;
              	q.emplace_back(ni, nj);
            }
        }
    }
                     
    int ans = dist[gi][gj];
  	if(ans == INF) ans = -1;
    cout << ans << endl;
}

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e9+9;
 
ll power(ll a, ll b, ll m = mod) {
    ll x = 1;
    while(b) {
        if(b & 1) {
            x = 1ll * x * a % m;
        }
        a = 1ll * a * a % m;
        b /= 2;
    }
    return x;
}
 
const int N = 2e5+9;
// ll a[N];
signed main() {  
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    ll n; cin >> n;
    ll x = n / 100;
    n -= 100 * x;
    if(n <= x * 5) {
        cout << "1\n";
    } else cout << "0\n";






    return 0;
    
}

Measured memory_bytes: 384
'''
INPUT SHORTCUTS
N, K = map(int,input().split())
N ,A,B = map(int,input().split())
string = str(input())
arr = list(map(int,input().split()))
N = int(input())
'''

N = int(input())
arr = list(map(int,input().split()))
ans = 1 
for i in range(N):
	if arr[i]%2==0:
		if(arr[i]%3!=0) and (arr[i]%5!=0):
			ans = 0
if ans:
	print("APPROVED")
else:
	print("DENIED")


Measured memory_bytes: 38416
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>
#include <unordered_set>
#include <unordered_map>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x) do{rep(__i,(x).size()) pri(x,__i);}while(0)
#define pran(x,n) do{rep(__i,n) pri(x,__i);}while(0)
#define pral(x) do{cerr << (#x) << " =";rep(__i,(x).size()) cerr<<" "<<(x[__i]);cerr<<endl;}while(0)
#define prar(x,b,e) do{repr(__i,b,e) pri(x,__i);}while(0)

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

ll MOD = 1000000007;

function<void(int,int)> tensi_no_3p=[&](int v,int d){
};

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	int N = in();
	vint a(N);
	rep(i, N) a[i] = in();
	
	int ans = 0;
	for (int i = 1; i < N; i++) {
		if (a[i] == a[i - 1]) {
			ans++;
			a[i] = -1;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
h, w = gets.split.map(&:to_i)
grid = []
h.times { grid << gets.chomp.split("") }
# 終点のみ、横に照らせるマス目の数をメモする
horizontal_sums = Array.new(h) { Array.new(w) }
# 終点のみ、縦に照らせるマス目の数をメモする
vertical_sums = Array.new(h) { Array.new(w) }

current_vertical = Array.new(w, 0)
current_vertical_sum = vertical_sums[-1]
(0...h).each do |r|
  current_row = grid[r]
  current_horizontal_sum = horizontal_sums[r]
  current_horizontal = 0
  previous_vertical_sum = current_vertical_sum
  current_vertical_sum = vertical_sums[r]
  (0...w).each do |c|
    if current_row[c] == "."
      current_horizontal += 1
      current_vertical[c] += 1
    else
      current_horizontal_sum[c - 1] = current_horizontal
      current_horizontal_sum[c] = 0
      current_horizontal= 0
      previous_vertical_sum[c] = current_vertical[c]
      current_vertical_sum[c] = 0
      current_vertical[c] = 0
    end
  end
  current_horizontal_sum[w - 1] = current_horizontal
end
vertical_sums[h - 1] = current_vertical

max = 0
current_vertical = vertical_sums[h - 1]
(h - 1).downto(0) do |r|
  current_horizontal_sum = horizontal_sums[r]
  current_horizontal = current_horizontal_sum.last
  current_vertical_sum = vertical_sums[r]
  (w - 1).downto(0) do |c|
    count = -1
    if horizontal_tmp = current_horizontal_sum[c]
      current_horizontal = horizontal_tmp
    end
    if vertical_tmp = current_vertical_sum[c]
      current_vertical[c] = vertical_tmp
    end
    count += current_horizontal
    count += current_vertical[c]
    max = count if max < count
  end
end
puts max


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

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        Console.WriteLine(string.Join("\n", Enumerable.Repeat(0, n).Select(_ => Console.ReadLine()).GroupBy(x => x).GroupBy(x => x.Count()).OrderByDescending(x => x.Key).First().Select(x => x.Key).OrderBy(x => x, StringComparer.OrdinalIgnoreCase)));
    }
}


Measured memory_bytes: 60820
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define ces(d) cout<<" "<<endl;
 
 
int main() {
ll N,M;
cin>>N>>M;

if(N*2<=M){
	ce(N+(M-N*2)/4)
}else{
	
	ce(M/2)
	
}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define all(x) x.begin(),x.end()
#define mnx 1000001
#define f(a,b) MP(min(a,b),max(a,b))
#define pr pair<ll,ll>
#define nonod 100005
using namespace std;

void masterstroke(){
	ll n,m;
	cin>>n;
	ll sum=0;
	for(ll i=0;i<n;i++){
		ll x;cin>>x;
		sum^=x;
	}
	if(sum)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	
	
	
}

int main(){
ll t=1;//cin>>t;
for(ll i=0;i<t;i++)masterstroke();
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  if (N == 1) {
    cout << "Hello World" << endl;
    return 0;
  }
  int A, B;
  cin >> A >> B;
  cout << ( A + B ) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int arr[105]={0};
    for(int i=0;i<2;i++){
        int a,b;
        scanf("%d", &a);
        scanf("%d", &b);
        for(int j=a;j<b;j++){
            arr[j]+=1;
        }
    }
    int sum=0;
    for(int i=0;i<105;i++){
        if (arr[i]==2){
            sum+=1;
        }
    }
    printf("%d", sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,int> pli;
typedef pair<int,int> pii;
#define rep(i,a,b) for(ll i=a ; i<b ; i++)
#define qrep(que, ite) for(auto ite=begin(que) ; ite!=end(que) ; ite++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1e17;
const int inf = 1e5;
typedef long double ld;
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 (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return a ? gcd(b%a, a) : b; }
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
ll mo = 998244353;
struct UnionFind {
    vector<int> par;

    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x) {
        return -par[root(x)];
    }
};
struct SegmentTree{
  int N;
  vector<int> node;
  public :
    void intit(vector<int>v){
      int sz = v.size();
      N=1;
      while(N<sz) N*=2;
      node.resize(N);
      for(int i=0 ; i<sz ; i++) node[i+N-1] = v[i];
      for(int i=N-2 ; i>=0 ; i--) node[i] = min(node[i*2+1], node[i*2+2]);
    }
    void update(int x, int val){
      x += N-1;
      node[x+N-1] = val;
      while(x>0){
        x = (x-1)/2;
        node[x] = min(node[x*2+1], node[x*2+2]);
      }
    }
    int getmin(int a, int b, int k, int l, int r){
      if(b<=l || r<=a) return inf;
      else if(a<=l && r<=b) return node[k];
      else{
        int vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        int vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        return min(vl, vr);
      }
    }
};
int main(){
  int x,n;  cin>>x>>n;
  int y=x;
  int z=x;
  vector<int> v(n);
  rep(i,0,n) cin>>v[i];
  sort(all(v));
  map<int,int> ma;
  rep(i,0,n){
    ma[v[i]]++;
  }
  int be=0;
  while(ma[x]!=0){
    x--;
  }
  while(ma[y]!=0){
    y++;
  }
  if(abs(z-x)<abs(z-y)){
    cout<<x<<endl;
  }else if(abs(z-x)==abs(z-y)){
    cout<<min(x,y)<<endl;
  }else{
    cout<<y<<endl;
  }
  return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
#include <string.h>

int main(void){
  char s[1001], order[8], ch[1001];
  int i, j, n, a, b;

  scanf("%s\n%d", s, &n);

  for(i=0;i<n;i++){
    scanf("%s %d %d", order, &a, &b);
    
    if(!strcmp(order, "reverse")){
      for(j=a;j<=b;j++)
        ch[b-j] = s[j];
      for(j=a;j<=b;j++)
        s[j] = ch[j-a];
    }

    if(!strcmp(order, "replace")){
      scanf("%s", ch);
      for(j=0;ch[j]!='\0';j++)
        s[a+j] = ch[j];
    }

    if(!strcmp(order, "print")){
      for(j=a;j<=b;j++)
        printf("%c", s[j]);
      printf("\n");
    }
  }

  return 0;
}





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

const int MAX_M=10010,MAX_T=1300;

int N,M,r,q,t,n,m,s,ts,te;
vector<vector<int>> record(MAX_M,vector<int>(MAX_T));


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	while(cin >> N >> M,N){
		for (int i=0;i<M;++i){
			fill(record[i].begin(),record[i].end(),0);
		}
		cin >> r;
		for (;r--;){
			cin >> t >> n >> m >> s; --m;
			if (s) ++record[m][t];
			else --record[m][t];
		}
		for (int i=0;i<M;++i){
			for (int j=0;j<MAX_T-1;++j) record[i][j+1]+=record[i][j];
			for (int j=0;j<MAX_T;++j) record[i][j]=min(1,record[i][j]);
			for (int j=0;j<MAX_T-1;++j) record[i][j+1]+=record[i][j];
		}
		cin >> q;
		for (;q--;){
			cin >> ts >> te >> m; --m;
			cout << record[m][--te]-record[m][--ts] << '\n';
		}
	}
}


Measured memory_bytes: 54084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int mod = 1e9 + 7;

signed main() {
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    cin >> H;
    int ans = 0;
    sort(H.rbegin(), H.rend());
    for (int i = K; i  < N; i++) {
        ans += H[i];
    }
    cout << ans << endl;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define debug(a) cerr << #a << ": " << (a) << "\n"

typedef long long ll;

const int N = 1e5 + 10;
int n, k, a[N], dp[N];

int main() {
	// freopen("in", "r", stdin);
	// freopen("out", "w", stdout);
	ios::sync_with_stdio(0);cin.tie(0);

	cin >> n >> k;
	for (int i = 1; i <= n; i++) cin >> a[i];
	for (int i = n - 1; i >= 1; i--) {
		dp[i] = INT_MAX;
		for (int j = 1; j <= k; j++) {
			if (i + j <= n) dp[i] = min(dp[i], abs(a[i] - a[i + j]) + dp[i + j]);
		}
	}
	cout << dp[1] << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <iterator>
#include <algorithm>
#include <map>
#include <string.h>
#include <vector>
#include <cmath>
#include <deque>
#include <iomanip>

using namespace std;
#define range(a) a.begin(), a.end()
#define rep(i, c) for(int i = 0; i < (int)c; i++)
typedef long long ll;

const string YES = "Yes";
const string NO = "No";

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

  int a, b; cin >> a >> b;
  if(a < b){
    rep(i, b) cout << a;
  }else{
    rep(i, a) cout << b;
  }




}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
L = 60
MOD = 10**9 + 7
data = [0]*L
for a in A:
    S = reversed(bin(a)[2:])
    for i, s in enumerate(S):
        data[i] += s=="1"
p = 1
res = 0
for i in range(L):
    res += data[i]*(N-data[i])*p
    p *= 2
    p %= MOD
print(res%MOD)

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

#ifdef DEBUG
#include "../.inc/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

struct P {
    int id, x, y;
};

struct Edge {
    int from, to, cost;
};

class UnionFind {
public:
    int n;
    vector<int> par, rank, sz;

    UnionFind(int n) : n(n), par(n), rank(n), sz(n) {
        for (int i=0; i<n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sz[i] = 1;
        }
    }
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x != y) {
            if (rank[x] > rank[y]) swap(x, y);
            par[x] = y;
            sz[y] += sz[x];
            if (rank[x] == rank[y]) ++rank[y];
        }
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int size(int x) {
        return sz[find(x)];
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;
    vector<P> v;
    for (int i=0; i<N; ++i) {
        int x, y;
        cin >> x >> y;
        v.push_back((P){i, x, y});
    }

    vector<Edge> edges;

    sort(v.begin(), v.end(), [](const P &a, const P &b) { return a.x < b.x; });
    for (int i=0; i<N-1; ++i) {
        edges.push_back((Edge){ v[i].id, v[i+1].id, abs(v[i].x-v[i+1].x) });
    }

    sort(v.begin(), v.end(), [](const P &a, const P &b) { return a.y < b.y; });
    for (int i=0; i<N-1; ++i) {
        edges.push_back((Edge){ v[i].id, v[i+1].id, abs(v[i].y-v[i+1].y) });
    }

    sort(edges.begin(), edges.end(), [](const Edge &a, const Edge &b) { return a.cost < b.cost; });

    UnionFind uf(N);
    long long sum = 0;
    for (int i=0; i<(int)edges.size(); ++i) {
        if ( ! uf.same(edges[i].from, edges[i].to)) {
            uf.unite(edges[i].from, edges[i].to);
            sum += edges[i].cost;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define pb push_back
using namespace std;	

const int N=205;
typedef long long int lint;

string a;
int b;

int n;
int t=1,mark[N];
std::vector<int> yol[N],v[N];
void dfs(int k)
{
	if(mark[k]) return ;
	mark[k]=t;
//	printf("t ye k %d %d\n",t,k );
	v[t].pb(k);
	for (auto it : yol[k])
		dfs(it);

}


int bfs(int a)
{
	memset(mark,0,sizeof mark);
	int t=1;
	queue <int> q;
	q.push(a);
	mark[a]=t;
	int fl=1;
//	printf("a %d\n",a);
	while(!q.empty())
	{
		int a=q.front();
		q.pop();
		t=max(t,mark[a]);
//		printf("%d %d\n",a,mark[a]);
		for (auto it : yol[a])
			if(mark[it] && !(mark[it]-1==mark[a] || mark[it]+1==mark[a]))
			{
				fl=0;
				break;
			}
		for (auto it : yol[a])
			if(mark[it]==0)
			{
				mark[it]=mark[a]+1;
				q.push(it);
			}
	}
	return fl ? t : 0; 
}
int main(){
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		cin >> a;
		for (int j = 0; j < a.size(); ++j)
		{
			if(a[j]=='1')
				yol[i].push_back(j);
		}
	}
	for (int i = 0; i < n; ++i)
		if(mark[i]==0)
		{
			dfs(i);
			t++;
		}
//	for (int i = 0; i < n; ++i)
//		printf("%d %d\n",i,mark[i]);
	int ans=0;
//	printf("%d\n",t);
	for (int i = 1; i < t; ++i)
	{
		int mx=0;
		for (int j = 0; j < v[i].size(); ++j)
		{
//			printf("asdas\n");
			mx=max(mx,bfs(v[i][j]));
		}
		if(mx==0)
		{

			cout << "-1" << endl;
			return 0;
		}
		ans+=mx;
	}
	cout << ans;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int N, M, A, a;

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

    int ans = N - A;

    if(ans < 0){
        ans = -1;
    }

    cout << ans << endl;

    return 0;
            
}

Measured memory_bytes: 3656
//Diverse Garland
#include<bits/stdc++.h>

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define N (ll)(1e7+5)
#define mod (ll)(1e9+7)

using namespace std;

int main()
{
    ll t;cin>>t;
    if(t)
        cout<<0<<endl;
    else    
        cout<<1<<endl;
    return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  int ans = 0;
  for (int a = 1; a <= 1000; ++a) {
    for (int b = 1; b <= n / a + 10; ++b) {
      if (a * b < n) {
        ++ans;
        if (b > 1000) ++ans;
      }
    }
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
const int N=200005;
int n,a[N];
int main(){
	//freopen("C:/dasin/aa.in","r",stdin);
  int i,j;
  scanf("%d",&n);
  for(i=1;i<=n;++i)scanf("%d",a+i);
  int low=0;
  ll ans=0;
  for(i=n;i;--i){
    if(a[i]>=i||a[i]<low)return puts("-1"),0;
    if(a[i]>low)ans+=a[i],low=a[i];
    if(low)--low;
  }
  printf("%lld\n",ans);
	return 0;	
}



Measured memory_bytes: 1024
a = input().split()
a = [int(i) for i in a]

b = input().split()
b = [int(i) for i in b]

c = input().split()
c = [int(i) for i in c]

maxb = max(b)
minc = min(c)

if maxb < minc and a[2] < a[3] and maxb < a[3] and minc > a[2]:
	print ('No War')
else:
	print ('War')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repe(i, n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if (a+b > c+d) {
    cout << "Left" << "\n";
  }
  if (a+b == c+d) {
    cout << "Balanced" << "\n";
  }
  if (a+b < c+d) {
    cout << "Right" << "\n";
  }
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		int[][] g = new int[N][N];
		for (int i = 0; i < M; ++i) {
			int a = Integer.parseInt(sc.next()) - 1;
			int b = Integer.parseInt(sc.next()) - 1;
			int l = Integer.parseInt(sc.next()) * 2;
			g[a][b] = g[b][a] = l;
		}
		PriorityQueue<Long> q = new PriorityQueue<Long>();
		for (int i = 0; i < K; ++i) {
			q.add(Long.parseLong(sc.next()) - 1);
		}
		int[] dist = new int[N];
		Arrays.fill(dist, -1);
		int ans = 0;
		while (!q.isEmpty()) {
			long st = q.poll();
			int t = (int) st;
			long d = st >> 32;
			if (dist[t] >= 0) continue;
			dist[t] = (int) d;
			ans = (int) d;
			for (int i = 0; i < N; ++i) {
				if (dist[i] == -1 && g[t][i] > 0) {
					q.add(((d + g[t][i]) << 32) + i);
				}
			}
		}
		for (int i = 0; i < N; ++i) {
			for (int j = i + 1; j < N; ++j) {
				if (g[i][j] == 0) continue;
				ans = Math.max(ans, (dist[i] + dist[j] + g[i][j]) / 2);
			}
		}
		System.out.println((ans + 1) / 2);
	}
}

Measured memory_bytes: 51000
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n, m; cin>>n>>m;
    vector<vector<double>> height(n);
    for(int i=0; i<n; i++){
        int k; cin>>k;
        double hsum=0;
        height[i].eb(0);
        for(int j=0; j<k; j++){
            double s, h; cin>>s>>h;
            for(double l=hsum+1./s; l<=h+hsum+eps; l+=1./s){
                height[i].eb(l);
            }
            
            hsum += h;
        }
    }

    vector<vector<double>> dp(n+10, vector<double>(m+10, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<=m; j++){
            for(int k=0; k+j<=m; k++){
                if(k < height[i].size()) dp[i+1][k+j] = max(dp[i+1][k+j], dp[i][j] + height[i][k]);
            }
        }
    }

    double ans=0;
    for(int i=0; i<=m; i++){
        chmax(ans, dp[n][i]);
    }

    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
string a;
int main()
{
	cin>>a;
	int x=0,y=0,ans=0;
	for(int i=0;i<a.length();++i)
	{
		if(x==y)
		{
			x++;
			if(a[i]=='p')
			ans--;
		}
		else 
		{
			y++;
			if(a[i]=='g')
			ans++;
		}
		
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

int main() {
  int r;
  std::cin >> r;
  if (r < 1200) {
    std::cout << "ABC" << std::endl;
  } else if (r < 2800) {
    std::cout << "ARC" << std::endl;
  } else {
    std::cout << "AGC" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
	"strings"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type inInfo struct {
	in    int
	after int
}

type inInfoSorter []inInfo

func (a inInfoSorter) Len() int      { return len(a) }
func (a inInfoSorter) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a inInfoSorter) Less(i, j int) bool {
	switch {
	case a[i].in > a[j].in:
		return true
	case a[i].in < a[j].in:
		return false
	case a[i].after > a[j].after:
		return true
	default:
		return false
	}
}

func sum(w []int) int {
	s := 0
	for _, v := range w {
		s += v
	}
	return s
}

type ptr []int

func (x ptr) top(i int) int {
	ptrs := []int(x)
	var his []int
	cur := i
	for ; cur >= 0 && ptrs[cur] != cur; cur = ptrs[cur] {
		his = append(his, cur)
	}
	for _, v := range his {
		ptrs[v] = cur - 1
	}
	if cur >= 0 {
		ptrs[cur] = cur - 1
	}
	return cur
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	this.baseScanner = bufio.NewScanner(stdin)
	return &this
}

func (me *ReaderEx) ScanAndSplit() (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	me.words = strings.Fields(me.baseScanner.Text())
	return
}

func (me *ReaderEx) getBytes(i int) []byte {
	return []byte(me.words[i])
}
func (me *ReaderEx) getString(i int) string {
	return me.words[i]
}
func (me *ReaderEx) getInt(i int) int {
	n, err := strconv.Atoi(me.words[i])

	defer func() {
		if err != nil {
			fmt.Fprintln(os.Stderr, "getInt(", n, ")")
		}
	}()
	return n
}

func solve(stdin io.Reader, stdout io.Writer) {
	var n, m int
	var infos []inInfo
	reader := NewScannerEx(stdin)
	reader.ScanAndSplit()
	n = reader.getInt(0)
	m = reader.getInt(1)

	for i := 0; i < n; i++ {
		var info inInfo
		reader.ScanAndSplit()
		info.after = reader.getInt(0)
		info.in = reader.getInt(1)
		infos = append(infos, info)
	}

	sort.Sort(inInfoSorter(infos))

	var ans = make([]int, m)
	var p = make([]int, m)
	for i := range p {
		p[i] = i
	}
	ptrs := ptr(p)

	for _, w := range infos {
		i := ptrs.top(m - w.after)
		if i >= 0 {
			ans[i] = w.in
		}
	}

	fmt.Fprintln(stdout, sum(ans))

}



Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int A = 26;
    int D; cin >> D;
    vector<int> c(D);
    REP(i,A) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(A));
    REP(i,D) REP(j,A) cin >> s[i][j];

    vector<int> last(A,-1);
    REP(i,D) {
        int mx = 0,a = -1;
        REP(j,A) {
            int tmp = (i-last[j])*c[j] + s[i][j];
            if (mx < tmp) {
                mx = tmp;
                a = j;
            }
        }
        OUT(a+1)
        last[a] = i;
    }

    return 0;
}

Measured memory_bytes: 3740
#include <iostream>
#include <stack>
#include <string>

using namespace std;

void catChecker(string str){

	stack<char> cnt;

	for(int i=0;i<str.size();i++){
		char c=str.at(i);
		
		if(c=='m'){
			cnt.push(c);
		}else if(!cnt.empty()){
			if(c=='e' && cnt.top()=='m'){
				cnt.pop();
				cnt.push(c);
			}else if(c=='w' && cnt.top()=='e'){
				cnt.pop();
			}else{
				cout << "Rabbit" << endl;
				return ;
			}
		}else{
			cout << "Rabbit" << endl;
			return ;
		}
	
		
		if(i<str.size()-1 && cnt.empty()){
			cout << "Rabbit" << endl;
			return ;
		}
	}
	if(cnt.empty()){
		cout << "Cat" << endl;
	}else{
		cout << "Rabbit" << endl;
	}
	return ;
}

int main(void){

	string str;

	while(cin>>str)
		catChecker(str);

	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;

#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define FORD(i,a,b) for (int i=(a)-1; i>=(b); --i)

#define pb push_back
#define mp make_pair
#define st first
#define nd second

const int MOD = 1000000007;

int N;
char S[222222];

PII range(int X) {
  PII res(X, X);

  // printf("!!!%d %d\n", res.nd, S[res.nd+2]);
  while (res.nd < N-1) {
    // printf("!!!%d %d\n", res.nd, S[res.nd+2]);
    if (res.nd < N-2 && !S[res.nd+2]) res.nd += 2;
    else if (!S[res.nd+1]) res.nd += 1;
    else break;
  }

  return res;
}

int main() {
  // ios_base::sync_with_stdio(0);

  int A, B, C, D;
  scanf("%d%d%d%d%d%s", &N, &A, &B, &C, &D, S);
  --A, --B, --C, --D;
  REP(i,N) S[i] = S[i] == '#';

  if (A > B) {
    swap(A, B);
    swap(C, D);
  }

  PII A_range = range(A);
  PII B_range = range(B);

  bool ok = A_range.st <= C && C <= A_range.nd && B_range.st <= D && D <= B_range.nd;
  // printf("%d %d %d   %d %d %d\n", A_range.st, A, A_range.nd, B_range.st, B, B_range.nd);
  if (ok && C > D) {
    bool ok2 = false;
    FOR(i,B,D+1) ok2 = ok2 || (!S[i-1] && !S[i] && !S[i+1]);
    ok = ok && ok2;
  }
  printf(ok ? "Yes\n" : "No\n");
}


Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
ok = True
for i in range(n):
    if a[i] % 2 != 0:
        continue
    if a[i] % 3 != 0 and a[i] % 5 != 0:
        ok = False
if ok:
    print('APPROVED')
else:
    print('DENIED')


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

int dp[100005];
bool visited[100005];
vector<int> adj[100005];

void visit(int vertex){
	visited[vertex] = 1;
	dp[vertex] = 0;
	for(int child : adj[vertex]){
		if (!visited[child]){
			visit(child);
		}
		dp[vertex] = max(dp[vertex] , 1 + dp[child]);
	}
}

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

	for(int i = 0 , u , v ; i < m ; i++){
		cin >> u >> v;
		adj[u].push_back(v);
	}

	for(int i = 1 ; i <= n ; i++){
		if (!visited[i]){
			visit(i);
		}
	}

	int ans = 0;
	for(int i = 1 ; i <= n ; i++){
		ans = max(ans , dp[i]);
	}

	cout << ans;

	return 0;
}


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

typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) (in).begin(),(in).end()
#define ALL(in,K) (in),(in)+(K)

#define INF 1e18
#define MOD 1000000007
#define SIZE 10005
#define PI 	3.14159265358979323846

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a, b)*b; } //最小公倍数

char input(){
  char a;
  cin >> a;
  return a;
}

int main(){
  ll n,m;
  cin >> n >> m;
  priority_queue<int> q;
  REP(i,n){
    ll a;
    cin >> a;
    q.push(a);
  }
  while(!q.empty() && m--){
    ll num = q.top();
    q.pop();
    num /= 2;
    if(num)q.push(num);
  }
  ll ans=0;
  while(!q.empty()){
    ans+=q.top();
    q.pop();
  }
  cout << ans << endl;
}

Measured memory_bytes: 892
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
/*----------------------------------------------------------------*/

// int MOD = 998244353;
int MOD = 1000000007;

// int dp[100100][3] = {0};
/*----------------------------------------------------------------*/
signed main(){

	int n;
	string s;
	cin >> n >> s;

	rep(i,s.size()){
		cout << char('A' + (s[i]-'A'+n)%26);
	}
	cout << endl;

	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2020-qual.contest.atcoder.jp/tasks/ddcc2020_qual_b
// rm -r -f test;oj dl https://abc146.contest.atcoder.jp/tasks/abc146_b

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vl;
typedef vector<vector<ll>> vll;
typedef vector<bool> vb;
typedef set<int> si; 
typedef queue<int> qi;
typedef stack<int> sti;
typedef priority_queue<int> pqi;
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
//#define __builtin_popcountll bitCountLL
//#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
mt19937 mt_rand(chrono::high_resolution_clock::now().time_since_epoch().count());
//std::uniform_int_distribution<long long> rg(1,1e18);
#define maxn 100005
#define Mod 1000000007
const int INF = 2e9;
const ll ML = 4e18;
    
void solve() {
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    fori(i,0,s.size()) {
        if(i + t.size() - 1 >= s.size()) break;
        int r = 0;
        fori(j,0,t.size()) {
            if(s[i+j] != t[j]) r++;
        }
        ans = min(ans, r);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
   
    solve();
   
    /*
    clock_t start,finish;
    start = clock();
    
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


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

queue<string> res;
void product(string cand, int repeat) {
  auto now = res.front();
  if (now.size() == repeat) return;
  res.pop();
  for (auto &c : cand) res.push(now + c);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> abc = {0, a, b, c};
  vector<int> l(n);
  for (int i = 0; i < n; i++) cin >> l[i];

  string cand = "0123";
  queue<string> res;
  res.push("");
  while (res.front().size() != n) {
    string now = res.front(); res.pop();
    for (auto &c : cand) res.push(now + c);
  }
  vector<int> ans;
  while (!res.empty()) {
    auto p = res.front(); res.pop();
    vector<vector<int>> group(4);
    for (int i = 0; i < n; i++) {
      group[p[i]-'0'].push_back(l[i]);
    }
    int cost = 0;
    bool flag = true;
    for (int i = 1; i < 4; i++) {
      if (group[i].size() == 0) {flag = false; break;}
      cost += 10 * (group[i].size() - 1);
      int s = accumulate(group[i].begin(), group[i].end(), 0);
      cost += abs(s - abc[i]);
    }
    if (flag) ans.push_back(cost);
  }
  cout << *min_element(ans.begin(), ans.end()) << '\n';
  return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

int main() {
  int n;
  while(cin >> n, n) {
    double t;
    if (n % 3 == 0) t = PI/n;
    else t = PI/3/n;
    
    double s = 1.0/(sqrt(3)+1/tan(t))/6;
    double ans = s*2*n*(n%3?3:1);
    printf("%.10f\n", ans);
  }
}

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

int main() {
	int n; cin >> n; vector<int> vec(3);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> vec[j]; vec[j] = vec[j] * vec[j];
		}
		sort(vec.begin(), vec.end());
		if (vec[0] + vec[1] == vec[2]) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 3112
a=int(input())

s=0
if a<10:
    s=a
elif a<100:
    s=9
elif a<1000:
    s=9+(a-99)
elif a<10000:
    s=909
elif a<100000:
    s=909+(a-9999)
else:
    s=90909

print(s)


Measured memory_bytes: 2940