akhauriyash/Code-Regression huggingface dataset:
X, K, D = input().split()
X, K, D = int(X), int(K), int(D)
count = 0
if X < 0:
  X = -X
  L = X
else:
  L = X
if K < L // D:
  L = L - K * D
  K = 0
elif K == L // D:
#  print("koko")
  L = L % D
  K = 0
else:
#  print("C")
  temp = L
  L = L % D - D
  K = K - temp // D - 1
if L == 0:
  if K % 2 == 0:
    print(0)
    exit()
  else:
    print(D)
    exit()
if K == 0:
  print(abs(L))
  exit()
if abs(L) >= L + D:
  goal = L + D
  if K % 2 != 0:
    print(goal)
    exit()
  else:
    print(abs(L))
    exit()
elif abs(L) < L + D:
  goal = abs(L)
  if K % 2 == 0:
    print(abs(L))
    exit()
  else:
    print(L + D)
    exit()

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

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------


//def function
//------------------------------------------

//main
//------------------------------------------

signed main(){
  int N;
  VI city(5);
  cin >> N;
  REP(i, 5){
    cin >> city.at(i);
  }

  int ans=0;
  int mini=city.at(0);
  REP(i, 5){
    mini = min(mini, city.at(i));
  }
  ans = N/mini + 4;
  (N%mini!=0)?ans+=1:ans+=0;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# Problem: https://atcoder.jp/contests/abc051/tasks/abc051_b
# Python 1st Try
# CalcTime O^2 Edition

import sys
# from collections import defaultdict
# import heapq,copy
# from collections import deque
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(K, S):
    result = 0
    # algorithm
    for x in range(0, K+1):
        for y in range(0, K+1):
            z = S - x - y
            if ((0 <= z) and ( z <= K)):
                result = result + 1
    return result


if __name__ == "__main__":
    K, S = MI()
#    print("K={} S={}".format(K, S))
    print("{}".format(solver(K, S)))


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

using namespace std;

int main()
{
	string s;
	cin >> s;
	
	stack<int> stk1;
	stack<pair<int, int> > stk2;
	stack<pair<int,int> > stk3;
	int x, temp, area = 0;
	
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == '\\')
			stk1.push(i);
		else if(s[i] == '/' && stk1.size() > 0)
		{
			x = stk1.top();
			stk1.pop();
			temp = i - x;
			area += temp;
			
			while((stk2.size() > 0) && (stk2.top().first > x))
			{
				temp += stk2.top().second;
				stk2.pop();
			}
			stk2.push(make_pair(x, temp));
		}
	}
	
	for(int i = stk2.size(); i > 0; i--)
	{
		stk3.push(stk2.top());
		stk2.pop();
	}
	
	printf("%d\n%d", area, stk3.size());
	for(int i = stk3.size(); i > 0; i--)
	{
		printf(" %d", stk3.top().second);
		stk3.pop();
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 3380
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    int A[] = new int[100];
    int X,N,C=0;

    N = scanner.nextInt();

    for(int i=0;i<N;i++){
      A[i] = scanner.nextInt();
    }

    for(int k=0;k<N;k++){
      for(int i=N-1;i>=1;i--){
        if(A[i]<A[i-1]){
          X = A[i];
          A[i] = A[i-1];
          A[i-1] = X;
          C++;
        }
      }
    }

    for(int i=0;i<N;i++){
      System.out.print(A[i]);
      if(i!=N-1){
        System.out.print(" ");
      }
    }
    System.out.print("\n" + C + "\n");
  }
}



Measured memory_bytes: 26392
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub


import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
buff_readline = sys.stdin.readline
readline = sys.stdin.readline

INF = 2**62-1


def read_int():
    return int(buff_readline())


def read_int_n():
    return list(map(int, buff_readline().split()))


def read_float():
    return float(buff_readline())


def read_float_n():
    return list(map(float, buff_readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()

def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, K, P):
    P.sort()
    return sum(P[:K])


def main():
    N, K = read_int_n()
    P = read_int_n()
    print(slv(N, K, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 10448
#include <iostream>
#include <string>
using namespace std;
int d[256];
int main( void )
{
  ios::sync_with_stdio(false);
  string w;
  cin >> w;
  for( int i=0; i<w.size(); i++ ){
    d[w[i]]++;
  }
  string ret = "Yes";
  for( int i='a'; i<='z'; i++ ){
    if( d[i] & 1 ){
      ret = "No";
      break;
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<vector>
#include<set>
#include<map>
#define int long long int
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    multiset<int> s;
    int n,m;
    cin>>n>>m;
    int j;
    for(j=0;j<n;j++)
    {
		int x;
		cin>>x;
		s.insert(x);
	}
	while(m!=0)
	{
		auto it=s.end();
		it--;
		int p=(*it)/2;
		s.erase(it);
		s.insert(p);
		m--;
	}
	int answer=0;
	for(int x:s)
	  answer+=x;
	cout<<answer<<endl;
}	



Measured memory_bytes: 4992
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<cmath>

using namespace std;

int main(){
  int D;
  cin>>D;
  while(D--){
    int N;
    cin>>N;
    vector<int> B{-(1<<29),0};
    vector<int> H{50,50};
    while(N--){
      int b,h;
      cin>>b>>h;
      B.push_back(b);
      H.push_back(h);
    }
    B.insert(end(B),{100,1<<29});
    H.insert(end(H),{50,50});
    int M;
    cin>>M;
    vector<int> F(M),A(M);
    for(int i=0;i<M;i++){
      cin>>F[i]>>A[i];
    }
    int L;
    cin>>L;
    vector<tuple<int,int,int,double> > PT;
    for(int i=0;i<L;i++){
      int p,t;
      cin>>p>>t;
      PT.emplace_back(t,p,i,0);
    }
    sort(begin(PT),end(PT));
    int ct=0;
    vector<double> h(B.size()-1);
    for(auto &e:PT){
      int dt=get<0>(e)-ct;
      for(int i=0;i<M;i++){
	int x=lower_bound(begin(B),end(B),F[i])-begin(B)-1;
	double ra=dt*A[i];
	for(;;){
	  bool rltl=(H[x]>H[x+1]);
	  int lx=x+rltl;
	  double dh=H[lx]-h[x];
	  if(dh<1e-9){
	    int sx=x+(rltl?1:-1);
	    if(fabs(h[x]-h[sx])>1e-9){
	      x=sx;
	    }else{
	      int hx=max(x,sx);
	      B.erase(begin(B)+hx);
	      H.erase(begin(H)+hx);
	      h.erase(begin(h)+hx);
	      x=min(x,sx);
	    }
	  }else{
	    long long a=(B[x+1]-B[x])*30LL;
	    double cap=a*dh;
	    if(ra<cap){
	      h[x]+=ra/a;
	      break;
	    }else{
	      h[x]=H[lx];
	      ra-=cap;
	    }
	  }
	}
      }
      ct=get<0>(e);
      int ax=lower_bound(begin(B),end(B),get<1>(e))-begin(B)-1;
      get<3>(e)=h[ax];
    }
    for(int i=0;i<L;i++){
      for(auto e:PT){
	if(get<2>(e)==i){
	  cout<<fixed<<get<3>(e)<<endl;
	}
      }
    }
  }
}

    

Measured memory_bytes: 1280
def main():
    a, b, c, d = [int(a) for a in input()]

    plus = lambda a, b: a + b
    minus = lambda a, b: a - b
    ops = [plus, minus]
    for op1 in ops:
        for op2 in ops:
            for op3 in ops:
                t = op1(a, b)
                t = op2(t, c)
                t = op3(t, d)
                if t == 7:
                    s1 = "+" if op1 is plus else "-"
                    s2 = "+" if op2 is plus else "-"
                    s3 = "+" if op3 is plus else "-"
                    print("{}{}{}{}{}{}{}=7".format(a, s1, b, s2, c, s3, d))
                    return


if __name__ == '__main__':
    main()


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

using namespace std;

#define print(s) cout << (s) << endl;
#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n) 
#define all(a) a.begin(), (a).end()
#define inf = 9876543210
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<string>w(n);
    REP(i,n)cin>>w[i];
    int ans = 1;
    REP(i,n-1){
        for(int j = i+1; j<n; j++){
            if(w[i] == w[j]){
                ans = 0;
            }  
        }
    }
    REP(i,n-1){
        if(w[i].back()!= w[i+1].front()){
            ans = 0;
        }
    }

    if(ans == 0){
        cout<<"No"<<endl;
    } else if (ans == 1){
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

vector<ll> ans(2*1e5+10,0);

ll bin_pow(ll a,ll n,ll mod){
    ll ans=1;
    while(n>0){
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans%mod;
}

ll f(ll i)
{
  ll cnt=0;
  while(i!=0)
  {
    i%=__builtin_popcount(i);
    cnt++;
  }
  return cnt;
}

int main()
{
  for (int i = 0; i < ans.size()-5; ++i)
  {
    ans[i]=f(i);
  }

  int n;
  cin>>n;
  string x;
  cin>>x;
  if(n==1&&x=="1")
  {
    cout<<0<<endl;
    return 0;
  }

  ll pop=0;
  for (int i = 0; i < x.size(); ++i)
  {
    if(x[i]=='1') pop++;
  }
  ll pop_plus=pop+1;
  ll pop_minus=pop-1;
  bool judge=false;
  if(pop_minus==0) 
  {
    pop_minus=1;
    judge=true;
  }
  string rev_x=x;
  reverse(rev_x.begin(), rev_x.end());
  ll plus=0,minus=0;
  for (ll i = 0; i < rev_x.size(); ++i)
  {
    if(rev_x[i]=='1')
    {
      plus+=bin_pow(2,i,pop_plus);
      minus+=bin_pow(2,i,pop_minus);
      plus%=pop_plus;
      minus%=pop_minus;
    }
  }

  for (int i = 0; i < x.size(); ++i)
  {
    if(x[i]=='1')
    {
      // cout<<"i: "<<i<<endl;
      // cout<<minus<<" "
      // <<pop_minus<<" "
      // <<bin_pow(2,n-1-i,pop_minus)<<" "<<endl;
      int idx=(minus+2*pop_minus
        -bin_pow(2,n-1-i,pop_minus))%pop_minus;
      if(judge) cout<<0<<endl;
      else cout<<1+ans[idx]<<endl;
    }
    else
    {
      // cout<<"i: "<<i<<endl;
      // cout<<plus<<" "
      // <<pop_plus<<" "
      // <<bin_pow(2,n-1-i,pop_plus)<<" "<<endl;
      int idx=(plus+2*pop_plus
        +bin_pow(2,n-1-i,pop_plus))%pop_plus;
      cout<<1+ans[idx]<<endl;
    }
  }
}

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

int main()
{
  string s;
  ll k;
  cin >> s >> k;
  int n = s.size();
  
  vector<int> cnt = {1};
  for(int i = 1; i < n; i++)
  {
    if(s[i] == s[i - 1])
    {
      cnt.back()++;
    }
    else
    {
      cnt.emplace_back(1);
    }
  }
  //for(auto x : cnt) cout << x << " "; cout << endl;
  
  if((int)cnt.size() == 1)
  {
    k *=  cnt[0];
    cout << k / 2 << endl;
    return 0;
  }
  
  if(s[0] != s[n - 1] || k == 1)
  {
    ll a = 0;
    for(auto x : cnt)
    {
      a += x / 2;
    }
    cout << k * a << endl;
  }
  else
  {
    ll a = 0, ans = 0;
    
    //prefixとsuffix
    for(int i = 0; i < cnt.size(); i++)
    {
      ans += cnt[i] / 2;
    }
    
    //あいだの部分
    cnt[0] += cnt.back();
    for(int i = 0; i + 1 < cnt.size(); i++)
    {
      a += cnt[i] / 2;
    }
    ans += (k - 1) * a;
    cout << ans << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define plll pair<pll,ll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

ll matrice[101][101];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
        
    ll n,k;
    cin>>n>>k;
    vpll edges;
    for(ll i=1;i<n;i++)
    {
        edges.push_back(make_pair(i,n));
    }
    ll ans=((n-2)*(n-1))/2;
    k=ans-k;
    if(k<0)
    {
        cout<<"-1";
        exit(0);
    }
    ll val=n-1,store;
    while(k!=0)
    {
        store=min(val-1,k);
        k-=store;
        for(ll i=1;i<=store;i++)
        {
            edges.push_back(make_pair(i,val));
        }
        val--;
    }
    ll size=edges.size();
    cout<<size<<endl;
    for(ll i=0;i<size;i++)
    {
        cout<<edges[i].first<<" "<<edges[i].second<<endl;
    }
    return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int main(){
	int N,T;
	cin >> N >> T;
	int A[N];
	FOR(i,0,N) cin >> A[i];
	int maxA[N];
	int max = A[N-1];
	for (int i = N-1; i >= 0;i--){
		if (A[i] > max) max = A[i];
		maxA[i] = max;
	}
	int merit[N];
	merit[N-1] = 0;
	max = 0;
	FOR(i,0,N-1){
		merit[i] = maxA[i+1] - A[i];
		if (max < merit[i]) max = merit[i];
	}
	int ret = 0;
	FOR(i,0,N-1){
		if (merit[i] == max) ret++;
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1408
from itertools import accumulate
from operator import mul

# 入力
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9 + 7


# n + 1 個の整数からk個選ぶ組合せから重複する部分列の個数を差し引いて解を求める
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(
                pow(self.x, other.x, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    def __radd__(self, other):
        return ModInt(other + self.x)

    def __rsub__(self, other):
        return ModInt(other - self.x)

    def __rmul__(self, other):
        return ModInt(other * self.x)

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))


f = [ModInt(1)] + list(
    accumulate(
        map(ModInt, range(1, n + 2)),
        mul
    )
)


def c(n, k):
    return (
        0 if n < k else
        f[n] / (f[n - k] * f[k])
    )


w = sum(a) - n * (n + 1) // 2
m = a.index(w) + a[::-1].index(w)
ans = '\n'.join(
    str(c(n + 1, k) - c(m, k - 1))
    for k in range(1, n + 2)
)

# 出力
print(ans)


Measured memory_bytes: 35716
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def mark(b, check, la):
    for i in range(3):
        for j in range(3):
            if la[i][j] == b:
                check[i][j] = True

def ok(check):
    for i in range(3):
        if check[i][0] and check[i][1] and check[i][2]:
            return True
        if check[0][i] and check[1][i] and check[2][i]:
            return True
    if check[0][0] and check[1][1] and check[2][2]:
        return True
    if check[2][0] and check[1][1] and check[0][2]:
        return True
    return False


def main():
    check = [[False for _ in range(3)] for _ in range(3)]
    la = []
    for i in range(3):
        l = rli()
        la.append(l)
    n = ri()
    for i in range(n):
        b = ri()
        mark(b, check, la)
    if ok(check):
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <stdio.h>

#define N 10000
#define Q 500


int linearSearch(int,int *,int);

int main(){
  int a=0,S[10000],b,T[500],i,j,k=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&b);
  for(j=0;j<b;j++){
    scanf("%d",&T[j]);
    if(linearSearch(a,S,T[j])==1)
      k++;
    else if(linearSearch(a,S,T[j])==0)
      continue;
  }
  printf("%d\n",k);
  return 0;
}
int linearSearch(int n,int *A,int key){
  int i=0;
  A[n] = key;
  while(A[i]!=key){
    i++;
    if(i==n)
      return 0;
  }
  return 1;
  
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll n,k; cin >> n >> k;
  vector<P<ll,ll>> v(n);
  vector<ll> vm(100001);
  for(auto&e:v)cin >> e.second >> e.first;
  sort(v.rbegin(), v.rend());
  ll ans = 0;
  ll cnt = 0;
  for(ll i = 0; i < k; ++i){
    ans += v[i].first;
    vm[v[i].second]++;
    if(vm[v[i].second] == 1)cnt++;
  }  
  ll idx = k - 1;
  ll fans = ans + cnt*cnt;
  for(ll i = k; i < n; ++i){
    if(vm[v[i].second] > 0)continue;
    while(idx >= 0 && vm[v[idx].second] == 1)idx--;    
    if(idx < 0)break;
    ans -= v[idx].first;
    ans += v[i].first;
    vm[v[i].second]++;
    vm[v[idx].second]--;
    cnt++;
    ChangeMax(fans,ans + cnt*cnt);
    idx--;
  }
  cout << fans << endl;
  return 0;
}


Measured memory_bytes: 5632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

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

    string s, t;
    cin >> s >> t;
    vector<int> x(s.size() + 1), y(t.size() + 1);
    rep(i, 0, s.size()) {
        x[i + 1] = x[i] + (s[i] - 'A' + 1);
        x[i + 1] %= 3;
    }
    rep(i, 0, t.size()) {
        y[i + 1] = y[i] + (t[i] - 'A' + 1);
        y[i + 1] %= 3;
    }
    int q;
    cin >> q;
    while (q--) {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int i = (x[b] - x[a - 1] + 3) % 3;
        int j = (y[d] - y[c - 1] + 3) % 3;
        if (i == j)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 1744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
    static FastScanner sc = new FastScanner();
    public static void main(String[] args) {
       int n=sc.nextInt();
      int d=sc.nextInt();
        int count=0;
      while (n-->=1){
          long x=sc.nextLong();
          long y=sc.nextLong();
//          Math.abs(x);
//          Math.abs(y);
          double dist=Math.sqrt((x*x)+(y*y));
//          System.out.println(dist);

          if (dist<=d){
              count++;
          }
      }
        System.out.println(count);


    }

        static void sortint(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sort(long[] a) {
        ArrayList<Integer> l = new ArrayList<>();
        for (long i : a) l.add((int) i);
        Collections.sort(l);
        for (int i = 0; i < a.length; i++) a[i] = l.get(i);
    }

    static class FastScanner {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");

        String next() {
            while (!st.hasMoreTokens())
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

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

        int[] readArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }

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





Measured memory_bytes: 54896
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

X, Y = LI()

for i in range(X + 1):
    if 2 * i + 4 * (X - i) == Y:
        print("Yes")
        sys.exit()

print("No")   

Measured memory_bytes: 9216
n = int(input())
h = list(map(int, input().split()))

a = [0]*n

for i in range(n):
  if i == 0:
    a[i] = 0
  elif i == 1:
    a[i] =  a[i-1] + abs(h[i] - h[i-1])
  else:
    a[i] = min(a[i-1] + abs(h[i] - h[i-1]),  a[i-2] + abs(h[i] - h[i-2]))

print(a[-1])

Measured memory_bytes: 13980
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_C&lang=jp
#include <bits/stdc++.h>
using namespace std;

struct WarshallFloyd {
  WarshallFloyd() {};
  WarshallFloyd(int n) : n(n) { init(); };

  const long long inf = 1001001001010001001ll;
  int n;
  bool NC = false;
  vector<vector<long long>> d;

  void init() {
    d = vector<vector<long long>>(n, vector<long long>(n, inf));
    for (int i = 0; i < n; ++i) d[i][i] = 0;
  }

  void add_edge(int u, int v, long long c) {
    d[u][v] = c;
  }

  bool build() {
    for (int k = 0; k < n; ++k) {
      for (int i = 0; i < n; ++i) {
        if (d[i][k] == inf) continue;
        for (int j = 0; j < n; ++j) {
          if (d[k][j] == inf) continue;
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }

    bool f = false;
    for (int i = 0; i < n; ++i) {
      if (d[i][i] < 0) f = true;
    }

    return NC = f;
  }

  long long shortestPath(int u, int v) {
    return d[u][v];
  }
};

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

  WarshallFloyd wf(n);
  for (int i = 0; i < m; ++i) {
    int u, v, c;
    cin >> u >> v >> c;

    wf.add_edge(u, v, c);
  }

  if (wf.build()) {
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      if (wf.shortestPath(i, j) == wf.inf) {
        cout << "INF";
      } else {
        cout << wf.shortestPath(i, j);
      }
      cout << (j + 1 == n ? "\n" : " ");
    }
  }
}

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

int count(int n) {
	int sum = 0;
	for (auto i = 1; i <= n; ++i) {
		if (n % i == 0)
			++sum;
	}
	return sum;
}
int main() {
	int n;
	std::cin >> n;
	int res = 0;
	for (auto i = 1; i <= n; i += 2) {
		if (count(i) == 8) ++res;
	}
	std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdint>

template <template <class> class Container> class eratosthenes {
	using uint64 = ::std::uint_fast64_t;

public:
	using container_type = Container<uint64>;
	using size_type = typename container_type::size_type;

protected:
	container_type c;
	size_type s;

public:
	eratosthenes() : c(), s(0) {}
	explicit eratosthenes(const size_type size)
		: c((size >> 6) + 1, ~static_cast<uint64>(0)), s(size) {
		c[0] ^= 3;
		for (size_type i = 2; i * i < size; ++i)
			if (c[i >> 6] >> (i & 0x3F) & 1)
				for (size_type j = i * i; j < size; j += i)
					c[j >> 6] &= ~(static_cast<uint64>(1) << (j & 0x3F));
	}

	bool empty() const { return !s; }
	size_type size() const { return s; }

	bool test(const size_type i) const {
		assert(i < size());
		return c[i >> 6] >> (i & 0x3F) & 1;
	}
	bool operator[](const size_type i) const {
		assert(i < size());
		return c[i >> 6] >> (i & 0x3F) & 1;
	}
};

#include <cstdio>
#include <vector>

template <class T> using vec_alias = ::std::vector<T>;

int main() {
	using uint = unsigned int;

	constexpr uint N = 100000001;

	eratosthenes<vec_alias> pri(N);

	uint n;
	scanf("%u", &n);

	uint cnt = 0, x;
	while (n--) {
		scanf("%u", &x);
		cnt += pri[x];
	}

	printf("%u\n", cnt);

	return 0;
}



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

using namespace std;
//using namespace __gnu_pbds;

#define ll    long long
#define PR    pair<ll, ll>

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int a[N], vis[N];
vector<int> path;
deque<int> dq;

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n; ll k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vis[1] = 1;
    int start = 1, now = 1;
    dq.push_back(1);
    while (true) {
        now = a[now];
        if (vis[now]) {
            break;
        }
        dq.push_back(now);
        vis[now] = 1;
    }
    if (dq.size() == 1) {
        cout << 1 << '\n';
        return 0;
    }
    if (k <= dq.size() - 1) {
        dq.pop_front();
        int ans = 1;
        while (k--) {
            ans = dq.front();
            dq.pop_front();
        }
        cout << ans << '\n';
        return 0;
    }
    k -= (ll)(dq.size() - 1);
    while (dq.front() != now) {
        dq.pop_front();
    }
    while (!dq.empty()) {
        path.push_back(dq.front());
        dq.pop_front();
    }
//    for (auto i : path) {
//        cout << i << " -> ";
//    }
//    cout << endl;
    int r = k % (ll)path.size();
    if (r == 0) {
        r = path.size() - 1;
    } else {
        r -= 1;
    }
//    cout << r << endl;
    cout << path[r] << '\n';
    return 0;
}


Measured memory_bytes: 6352
import collections
n = int(input())
s = [input() for i in range(n)]

ans = [100] * 26
for i in range(26):
    for j in range(n):
        sub = 97 + i
        ans[i] = min(ans[i], s[j].count(chr(sub)))

for i in range(26):
    for j in range(ans[i]):
        print(chr(97 + i), end="")


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

using namespace std;
typedef long long int lli;
#define fast                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
typedef pair<lli, lli> pii;
#define ff first
#define ss second
#define MOD 1000000007
#define pb push_back
#define EPS 1e-6
const lli MAX = 1e9 + 7;

int main()
{
    fast;
    int t = 1;
    while (t--)
    {
        lli d, t, s;
        cin >> d >> t >> s;
        if (d  <= s*t)
            cout << "Yes\n";
        else
            cout << "No\n";
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> cnt(5);
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') cnt[0]++;
        else if (s[0] == 'A') cnt[1]++;
        else if (s[0] == 'R') cnt[2]++;
        else if (s[0] == 'C') cnt[3]++;
        else if (s[0] == 'H') cnt[4]++;
    }
    vector<bool> v{true, true, true, false, false};

    long long res = 0;
    do {
        long long t = 1;
        for (int i = 0; i < 5; i++) {
            if (v[i]) {
                t *= cnt[i];
            }
        }
        res += t;
    } while (prev_permutation(v.begin(), v.end()));

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))


int main(void){
	bool ok=true;
	vector<int> inp;
	int a;

	rep(i,6){
		cin >> a;
		inp.push_back(a);
	}
	cout<<(inp[4]-inp[0]<=inp[5]?"Yay!":":(")<<endl;
	return 0;
}


Measured memory_bytes: 764
#pragma region Header
#define _CRT_SECURE_NO_WARNINGS
#define FOR(i,s, e) for(int i = s; i<e; ++i)
#define rFOR(i,s, e) for(int i=s-1; i>=e; --i)
#define loop(len) for(int i=0; i<len; ++i)
#define rloop(len) for(int i=len-1; i>=0; --i)
#define iPair pair<int,int>
#define LPair pair<ll,ll>
#define vecP(t,t2) vector<pair<t,t2>>
#define uoMP(t, t2) unordered_map<t, t2>
#define pb push_back
#define pp pop_back
#define beg_end(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define MrN ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long  ll;
typedef long double  ld;
#include<bits/stdc++.h>
using namespace std;
#pragma endregion

int n;
vector<int> v[3];
const int SIZE = 1e5 + 5;
int DP[3][SIZE];

int solve(int i, int type){

	int cost = v[type][i];

	if(i == n-1) return DP[type][i] = cost;

	if(DP[type][i] != -1)
		return DP[type][i];

	switch(type){
		case 0: return DP[type][i] = cost + max(solve(i+1, 1), solve(i+1, 2));

		case 1: return DP[type][i] = cost + max(solve(i+1, 0), solve(i+1, 2));

		case 2: return DP[type][i] = cost + max(solve(i+1, 0), solve(i+1, 1));
	}

}

int main() {
	MrN;
	//freopen("input.txt", "r", stdin);
	cin >> n;

	loop(n){
		FOR(t, 0, 3){
			int a;
			cin >> a;
			v[t].pb(a);
			DP[t][i] = -1;
		}
	}

	cout << max(solve(0, 0), max(solve(0, 1), solve(0, 2))) << '\n';
	
	return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n,x; cin >> n >> x;
  vector<int> m(n); rep(i,n) cin >> m[i];

  sort(m.begin(),m.end());
  int ans = n;
  rep(i,n) x-=m[i];
  
  ans += x/m[0];

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


Measured memory_bytes: 3560
#include<cstdio>
#include<algorithm>
using namespace std;
int n,u,v,ans,dp[110000][33];
int edgenum,vet[210000],Next[210000],Head[110000];
void addedge(int u,int v){
	vet[++edgenum]=v;
	Next[edgenum]=Head[u];
	Head[u]=edgenum;
}
void dfs(int u,int fa){
	int v;
	for (int e=Head[u];e;e=Next[e]){
		v=vet[e];
		if (v!=fa){
			dfs(v,u);
			for (int i=0;i<=30;i++) dp[u][i]+=dp[v][i];
		}
	}
	v=0;
	for (int i=0;i<=30;i++)
		if (dp[u][i]>1) v=i+1;
	while (dp[u][v]) v++;
	ans=max(ans,v); dp[u][v]=1;
	for (int i=0;i<v;i++) dp[u][i]=0;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		scanf("%d%d",&u,&v);
		addedge(u,v); addedge(v,u);
	}
	dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 20736
h,w,a,b =map(int,input().split())
mod = 10**9+7

#階乗を求める
fact_l = [1 for i in range(h+w+1)]
for i in range(1,len(fact_l)):
    fact_l[i] *= (fact_l[i-1]*i)%mod

#逆元
factinv_l = [1 for i in range(h+w+1)]
for i in range(1,len(fact_l)):
    factinv_l[i] = pow(fact_l[i],mod-2,mod)
    
#必ず通るポイントまでの組み合わせ
point1 = [1 for i in range(w-b)]
for i in  range(len(point1)):
    yoko = b+i 
    tate = h-a-1
    n = yoko+tate
    r = yoko
    point1[i] = fact_l[n]*factinv_l[r]*factinv_l[n-r]%mod

#point1からの経路
out = 0
for i in range(len(point1)):
    yoko = w-b-i-1
    tate = a-1
    n = yoko+tate
    r = yoko
    case = fact_l[n]*factinv_l[r]*factinv_l[n-r]%mod
    out += (point1[i]*case)%mod
print(out%mod)

Measured memory_bytes: 22768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    int card[4][4];
    int i, j;
    FOR0(i, 3) FOR0(j, 3) cin>>card[i][j];
    int n;
    cin>>n;
    FOR0(i, n)
    {
        int temp;
        cin>>temp;
        int x, y;
        FOR0(x, 3) FOR0(y, 3)
        {
            if(card[x][y] == temp) card[x][y] = 0;
        }
    }
    bool is = false;
    // rows
    FOR0(i, 3)
    {
        FOR0(j, 3) if(card[i][j]) break;
        if(j == 3) is = true;
    }

    // col
    FOR0(j, 3)
    {
        FOR0(i, 3) if(card[i][j]) break;
        if(i == 3) is = true;
    }

    // main diag
    FOR0(i, 3) if(card[i][i]) break;
    if( i == 3) is = true;

    // other diag
    FOR0(i, 3) if(card[i][2-i]) break;
    if( i == 3) is = true;
    if(is) cout<<"Yes\n";
    else cout<<"No\n";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;


public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int[] list = new int[N];
        for(int i=0;i<N;i++){
            list[i] = Integer.parseInt(sc.next());
        }
        int[] listA = new int[N];
        int[] listB = new int[N];
        listA[0] = list[0];
        listB[N-1] = list[N-1];
        for(int i=1;i<N;i++){
            listA[i] = gcd(listA[i-1],list[i]);
            listB[N-1-i] = gcd(listB[N-i], list[N-i-1]); 
        }
        int ans = 0;
        for(int i=0;i<N;i++){
            if(i==0){
                ans= Math.max(ans,listB[i+1]);
            }else if(i==N-1){
                ans= Math.max(ans,listA[i-1]);
            }else{
                ans= Math.max(ans,gcd(listA[i-1],listB[i+1]));
            }
        }
        System.out.println(ans);
    }
    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
}



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

typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

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

vvi t;
int W,H;

void dfs(int x,int y){
    t[x][y]='0';
    for(int i=0;i<8;i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(nx>=0 && nx<H && ny>=0 && ny<W && t[nx][ny]==1) dfs(nx,ny);
    }
    return;
}

int main(){
    while(cin>>W>>H){
        if(W==0&&H==0) return 0;

        t.resize(H);
        for(int i=0;i<H;i++) t[i].resize(W);

        for(int i=0;i<H;i++) for(int j=0;j<W;j++) cin>>t[i][j];

        int cnt=0;

        for(int i=0;i<H;i++) for(int j=0;j<W;j++) if(t[i][j]==1){
            cnt++;
            dfs(i,j);
        }
        cout << cnt << endl;
    }
}

Measured memory_bytes: 3256
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>
void Search_path(int **,int*,int,int*);
int main(){
  int i,j,k,n,m,dast;
  int **array,*flag,*distant;
  scanf("%d",&n);
  flag = malloc(sizeof(int *)*n);
  distant = malloc(sizeof(int)*n);
  for(i=0;i<n;i++){
    flag[i]=0;
    distant[i]=INT_MAX;
  }
  array = malloc(sizeof(int *)*n);
  for(i=0;i<n;i++)array[i] = malloc(sizeof(int)*n);
  for(i=0;i<n;i++)for(j=0;j<n;j++)array[i][j]=0;

  for(i=0;i<n;i++){
    scanf("%d %d",&dast,&m);
    for(j=0;j<m;j++){
      scanf("%d",&k);
      scanf("%d",&array[i][k]);
    }
  } 
  //
    Search_path(array,flag,n,distant);
    
  for(i=0;i<n;i++)printf("%d %d\n",i,distant[i]);
  //
 
  for(i=0;i<n;i++)free(array[i]);
  free(array);
  free(flag);
  free(distant);

  return 0;
}

void Search_path(int **array,int *flag,int n,int *distant){
  int index,num,i,j,min=INT_MAX,sum=0;
  int passed[n],pass_count=1,Candidate[n],Candidate_count=0;//passed[]:既に通ったnode
  index=0;
  flag[index] = 1;
  passed[0]=index;
  distant[0]=0;
  while(1){
    num = -1;
    min = INT_MAX;
    for(j=0;j<pass_count;j++){//使用済edge以外から最小costのedgeを探す
      index=passed[j];
      for(i=0;i<n;i++){
	if(distant[i] > distant[index] + array[index][i] &&  array[index][i] > 0 )distant[i] = distant[index] + array[index][i];
	if(flag[i] == 0 && min > array[index][i] && array[index][i] > 0){//接続先のnodeがまだ通ってないかつ、一番costが少ない所を選ぶ
	  min = array[index][i];
	  num = i;
	}
      }
    }
    if(num == -1)break;
    flag[num]=1;
    passed[pass_count++]=num;//通ったnodeを記録
    sum +=min;//最小コストを全て足す
  }
}
      
  
    
  
    
			



Measured memory_bytes: 2112
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    string s; cin >> s;
    vector<pair<char, char>> tds(q); cin >> tds;
    auto calc = [&](){ 
        int in = -1, out = n;
        while(in + 1 < out){
            int piv = (in + out) / 2;
            int pos = piv;
            bool done = false;
            for(auto& td : tds){
                if(td.first == s[pos]){
                    pos += (td.second == 'L' ? -1 : 1);
                }
                if(pos == -1){
                    in = piv;
                    done = true;
                    break;
                }else if(pos == n){
                    break;
                }
            }
            if(!done){
                out = piv;
            }
        }
        printde(in + 1);
        return in + 1;
    };
    int ans = 0;
    printde(tds, s);
    ans += calc();
    reverse(s.begin(), s.end());
    for(auto& td : tds){
        td.second = td.second == 'L' ? 'R' : 'L';
    }
    printde(tds, s);
    ans += calc();
    cout << n - ans << '\n';
}


Measured memory_bytes: 1020
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n;
    cin >> n;
    ll sum = 0;
    bool ok = false;
    ll cnt = 0;
    rep(i, n+1){
        sum+=i;
        cnt = i;
        if(sum==n)ok=true;
        if(sum>=n)break;
    }
    if(ok){
        cout << "Yes\n" << cnt+1 << endl;
        ll back = 1;
        ll ans[cnt+1][cnt];
        rep(i, cnt)ans[0][i]=back++;
        rep(i, cnt){
            rep(j, cnt){
                if(j<i+1)ans[i+1][j]=ans[j][i];
                else ans[i+1][j]=back++;
            }
        }
        rep(i, cnt+1){
            cout << cnt << " ";
            rep(j, cnt)cout << ans[i][j] << " ";
            cout << endl;
        }
    }
    else {
        cout << "No\n";
    }
}

Measured memory_bytes: 2944
#include <iostream>
//#include <algorithm>
//#include <vector>
//#include <unordered_map>
//#include <map>
//#include <queue>
//#include <cstring>

//#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


#define MOD		1000000007
#define ll		long long int
#define pll		pair<ll, ll>
#define pb		push_back
#define endl	"\n"
#define f 		first
#define s 		second
#define fastio 	ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v)  (v).begin(), (v).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

ll power(ll x, ll y) { ll ans = 1; x %= MOD; while (y) {if (y & 1)ans = (x * ans) % MOD; x = (x * x) % MOD; y >>= 1;} return ans;}
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};



void solve() {
    string s;
    cin >> s;
    if(s[s.size() - 1] == 's') {
        s += "es";
    } else {
        s += "s";
    }

    cout << s << endl;
}

int main() {
    fastio;
    solve();

}


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


int main()
{
	vector<int> stack;
	string s;
	while( cin >> s )
	{
		int a, b;
		switch( s[0] )
		{
			case '+':
			case '-':
			case '*':
				b = stack.back();
				stack.pop_back();
				a = stack.back();
				stack.pop_back();
				stack.push_back(	( s[0] == '+' ) ?	a + b :
									( s[0] == '-' ) ?	a - b :
														a * b
				);
				break;
			default:
				stack.push_back( stoi( s ) );
		}

		if( getchar() == '\n' ) break;
	}

	cout << stack[0] << endl;

	return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;i++)
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define fst first
#define snd second
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)(a).size())

int main() {FIN;
    string s;
    cin>>s;
    ll b=0,res=0;
    for(char c:s) {
        if(c=='W')res+=b;
        else if (c=='B')b++;
    }
    cout<<res<<endl;
}//sdasd

Measured memory_bytes: 720
/// Zhamshitos
/// Rinat
/// Rahatosich
/// 8 "A";
///
#include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  string h, t;
  int sum = 0;
  for( int i = 0; i < n; i ++ )
    {
      if( s[i] == '(' )
            sum ++;
      else sum--;
    if(sum < 0){
      h += "(";
      sum ++;
    }
  }
  while(sum){
    t += ")";
    sum --;
  }
  cout << h << s << t << endl;
  return 0;
}


Measured memory_bytes: 256
var
	N,M,S,cnt,i:Longint;
	A:Array[1..100]of Longint;
begin
	read(N,M);
	for i:=1 to N do begin
		read(A[i]);
		inc(S,A[i]);
	end;
	for i:=1 to N do if A[i]*4*M>=S then inc(cnt);
	if cnt>=M then writeln('Yes')else writeln('No');
end.


Measured memory_bytes: 128
/*
AizuOnline A0022
Maximum Sum Sequence
*/
#include <stdio.h>
#define XSIZ 10
#define YSIZ 10
int paper[XSIZ][YSIZ];


draw_ink(int x,int y,int siz)
{
  switch(siz){
  case 3:
    if(x>1)             paper[x-2][y]++;
    if(x<XSIZ-2)        paper[x+2][y]++;
    if(y>1)             paper[x][y-2]++;
    if(y<XSIZ-2)        paper[x][y+2]++;
  case 2:
    if((x>0)     &&(y>0))           paper[x-1][y-1]++;
    if((x<XSIZ-1)&&(y>0))           paper[x+1][y-1]++;
    if((x>0)     &&(y < YSIZ-1))    paper[x-1][y+1]++;
    if((x<XSIZ-1)&&(y < YSIZ-1))    paper[x+1][y+1]++;
  default:
    paper[x][y]++;
    if(x > 0)           paper[x-1][y]++;
    if(x < XSIZ-1)      paper[x+1][y]++;
    if(y > 0)           paper[x][y-1]++;
    if(y < YSIZ-1)      paper[x][y+1]++;
  }
}
int max_ink()
{   int ret = 0;
    int i,j;
    for(i=0;i<XSIZ;i++)
      for(j=0;j<XSIZ;j++)
        if(ret < paper[i][j])
          ret=paper[i][j];
  return ret;
}

int colorless()
{   int ret = 0;
    int i,j;
    for(i=0;i<XSIZ;i++)
      for(j=0;j<XSIZ;j++)
        if(0 == paper[i][j])
          ret++;
  return(ret);
}
main()
{

  int x,y,siz;
  int i,j;

  for(i=0;i<XSIZ;i++)
    for(j=0;j<XSIZ;j++)
      paper[i][j]=0;
  
  
  while(EOF != scanf("%d,%d,%d",&x,&y,&siz))
    draw_ink(x,y,siz);

  printf("%d\n%d\n",colorless(),max_ink());

  
return(0);
}

Measured memory_bytes: 0
n, m, x = map(int, input().split())
c = []
algo = []
for _ in range(n):
    l = list(map(int, input().split()))
    c.append(l[0])
    algo.append(l[1:])

cost = []
for i in range(2**n):
    c_sum = 0
    u_sum = [0]*m
    for j in range(n):
        if (i>>j) & 1:
            c_sum += c[j]
            for k in range(m):
                u_sum[k] += algo[j][k]
    if all(s >= x for s in u_sum):
        cost.append(c_sum)
if cost:
    print(min(cost))
else:
    print(-1)


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

int main() {
  int N;
  cin >> N;
  int temp = N%100;
  if(temp >10){
    temp %= 10;
  }
  if(temp == 3)
    cout << "bon" << endl;
  else if(temp == 0 || temp == 1 || temp == 6 || temp == 8)
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
  
  return 0;

}

Measured memory_bytes: 3636