akhauriyash/Code-Regression huggingface dataset:
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    char s[100];
    scanf("%s", s);
    if (strlen(s) % 2 == 1) {
        printf("No\n");
    } else {
        bool ok = true;
        for (int i = 0; i < strlen(s); i += 2) {
            if (s[i] != 'h' || s[i+1] != 'i') {
                ok = false;
            }
        }
        if (ok) {
            printf("Yes\n");
        } else {
            printf("No\n");
        }
    }
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 or i % 5 == 0) continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve() {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int a=sc.nextInt();
		System.out.println(n*n-a);
	}
}

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

using namespace std;

#define ll long long

#define DEBUG (0)

int main()
{
  int H = 0,A=0;
  cin >> H >> A;

  if(H%A == 0){
    cout << H/A << "\n";
  }else{
    cout << H/A + 1 << "\n";
  }
}

Measured memory_bytes: 256
A,B,M = map(int,input().split())

a = list(map(int,input().split()))
b = list(map(int,input().split()))

ticket = []

while M>0:
    ticket.append(tuple(map(int, input().split())))
    M -= 1

lowest = min(a)+min(b)

for ele in ticket:
    t = a[ele[0]-1] + b[ele[1]-1] - ele[2]
    if t < lowest:
        lowest = t
print(lowest)

Measured memory_bytes: 29468
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#define pb push_back
using namespace std;
vector<int>a,b,p;
int N;
 
int main(void){
  int i,j,k,t,tmp;
  int c,c2;
  a.clear(); b.clear(); p.clear();
  cin>>N;
  a.pb(-1); b.pb(-1); p.pb(-1);
  for(i=1;i<=N;i++){
    cin>>tmp;
    p.pb(tmp);
    a.pb(i*N);
    b.pb((N-i+1)*N);
  }
 
  for(i=1;i<=N;i++){
    b[p[i]]+=i;
  }
 
  for(i=1;i<=N;i++){
    cout<<a[i]<<" ";
  }
  cout<<endl;
 
  for(i=1;i<=N;i++){
    cout<<b[i]<<" ";
  }
  cout<<endl;
 
  return 0;
}

Measured memory_bytes: 1024
use std::io::Read;

fn main() {
    let mut buf = String::new();

    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let result = buf.chars().filter(|c| *c == '1').count();
    println!("{}", result);
}


Measured memory_bytes: 4352
def get_min_idx_val(A, N):
    min_val = A[0]
    min_idx = 0
    for i in range(N):
        if min_val > A[i]:
            min_val = A[i]
            min_idx = i
            
    return min_idx, min_val

def get_max_idx_val(A, N):
    max_val = A[0]
    max_idx = 0
    for i in range(N):
        if max_val < A[i]:
            max_val = A[i]
            max_idx = i
            
    return max_idx, max_val

def solve():
    N = int(input())
    A = list(map(int, input().split()))
    min_idx, min_A = get_min_idx_val(A, N)
    max_idx, max_A = get_max_idx_val(A, N)
    sign = 0
    if abs(min_A) <= abs(max_A):
        sign = 1
    else:
        sign = -1
            
    ret = 0
    query = []
    # print('sign:',sign)
    additive_idx = max_idx if sign > 0 else min_idx
    additive_val = max_A if sign > 0 else min_A 
    # print(min_idx, max_idx, additive_idx, additive_val)
    for i in range(N):
        if A[i]*sign < 0:
            ret += 1
            query.append('{0} {1}'.format(additive_idx+1, i+1))
            A[i] += additive_val
    
    if sign > 0:
        for i in range(1,N):
            first = i-1
            second = i
            if A[first] > A[second]:
                # if A[second] >= 0:
                ret += 1
                query.append('{0} {1}'.format(first+1, second+1))
                A[second] += A[first]
    elif sign < 0:
        for i in range(0,N-1)[::-1]:
            first = i
            second = i+1
            # print(first, second, A[first], A[second])
            if A[first] > A[second]:
                # if A[first] <= 0:
                ret += 1
                query.append('{0} {1}'.format(second+1, first+1))
                A[first] += A[second]
    
    # print(A)
    output = """{0}
{1}""".format(ret, '\n'.join(query))
    print(output)
    
solve()

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
int main(){
    int n;
    cin >> n;
    vector <char> s(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> s[i];
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    if(s.size() == 3) cout << "Three" << endl;
    else cout << "Four" << endl;
    
    return 0;
}

Measured memory_bytes: 256
// 3_abc133_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll l, r;
    cin >> l >> r;
    vector<int> v(2019);
    rep(i, 2019) v[i] = 0;

    for(int i = l ; i <= r && i < l + 2019; i++){
        v[i % 2019] = 1;
    }

    ll ans = INF;
    for(int i = 0; i < 2018; i++){
        if(v[i] == 0) continue;
        for(int j = i + 1; j < 2019; j++){
            if(v[j] == 0) continue;
            if(ans > i * j % 2019) ans = i * j % 2019;
        }
    }

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


Measured memory_bytes: 256
/////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && x<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

signed main(){

  Arithmetic Exception;

  int a;
  string s;
  cin>>a>>s;

  cout<<(a<3200?"red":s)<<endl;

  return 0;

}


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

typedef long long ll;

int main() {
	ll K,A,B;cin>>K>>A>>B;

	ll bis = 1;

	if (K+1 >= A)
	{
		bis = A;
	}
	else bis += K;
	K-=A-1;

	if (K <= 0)
	{
		cout<<bis<<endl;
	}

	if (B > A + 2)
	{
		if (K % 2)
		{
			bis += (K-1)/2*(B-A);
			bis++;
		}
		else
		{
			bis += K/2*(B - A);
		}
	}
	else
	{
		bis += K;
	}

	cout<<bis<<endl;
	
	return 0;
}

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

using namespace std;

int n;
int arr[100005][3];

int dp[100005][3];

long long calc(int i,int prev)
{
	if(i == n)	return 0;

//	cout <<"calc"<<i<<","<<prev<<endl;
	long long option1 = 0, option2 = 0, option3 = 0;

	if(dp[i][prev] != 0)	return dp[i][prev];

	if(prev != 0)
		option1 = arr[i][0] + calc(i+1,0);
	if(prev != 1)
		option2 = arr[i][1] + calc(i+1,1);
	if(prev != 2)
		option3 = arr[i][2] + calc(i+1,2);


	dp[i][prev] = max(option1, max(option2, option3));

	return dp[i][prev];
}

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);	cout.tie(0);
	
	int k;
	cin >> n ;
	
	for(int i=0; i<n;i++)
		for(int j=0;j<3; j++)
			cin >> arr[i][j];			

	long long ans = calc(-1,0);
		
	cout <<ans<<endl;
		
	return 0;
}


Measured memory_bytes: 8832
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
m = readl()

a = 1
b = 1

for i in m:
    a *= 3
    if i % 2 == 0:
        b *= 2
ans = a - b
print(ans)

Measured memory_bytes: 6480
n = int(input())
a = list(map(int,input().split()))
mod = 10**9+7
ans = 0
for i in range(60):
  keta=1<<i
  cnt=0
  for j in a:
    if keta & j:
      cnt+=1
  ans+=((keta%mod)*cnt*(n-cnt))%mod


print(ans%mod)


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

const int S=(1<<20)+5;
char buf[S],*H,*T;
inline char Get()
{
    if(H==T) T=(H=buf)+fread(buf,1,S,stdin);
    if(H==T) return -1;return *H++;
}
inline int read()
{
    int x=0;char c=Get();
    while(!isdigit(c)) c=Get();
    while(isdigit(c)) x=x*10+c-'0',c=Get();
    return x;
}

const int N=410;
int n,h,in[N],out[N];
int fa[N];
bool ok[N];

int find(const int &x){return fa[x]==x?x:fa[x]=find(fa[x]);}

int main()
{
    n=read();h=read();
    for(int i=1;i<=(h<<1);i++) fa[i]=i;
    for(int i=1;i<=n;i++)
    {
        int A=read(),B=read(),C=read(),D=read();
        int x=C?C+h:A,y=D?D:B+h;
        out[x]++;in[y]++;
        x=find(x);y=find(y);
        if(x!=y) fa[x]=y;
    }
    for(int i=1;i<=h;i++) if(in[i]>out[i]) return !puts("NO");
    for(int i=h+1;i<=(h<<1);i++) if(in[i]<out[i]) return !puts("NO");
    for(int i=1;i<=(h<<1);i++) if(in[i]!=out[i]||!in[i]&&!out[i]) ok[find(i)]=1;
    for(int i=1;i<=(h<<1);i++) if(fa[i]==i&&!ok[i]) return !puts("NO");
    return !puts("YES");
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
        cout<<(a-k)<<" "<<b<<endl;
    else
    {
        cout<<"0 ";
        k-=a;
        if(b>k)
            cout<<b-k<<endl;
        else
            cout<<"0"<<endl;
    }
}


Measured memory_bytes: 3596
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    ArrayList<HashSet<Integer>> a = new ArrayList<HashSet<Integer>>();
    boolean[] b = new boolean[n];

    for (int i=0;i<n;i++){
      HashSet<Integer> f = new HashSet<Integer>();
      a.add(f);
      b[i] = false;
    }

    for (int i=0;i<m;i++){
      int b1 = scan.nextInt();
      int c = scan.nextInt();
      HashSet<Integer> a1 = a.get(b1-1);
      a1.add(c);
      HashSet<Integer> a2 = a.get(c-1);
      a2.add(b1);
    }

    ArrayList<String> q = new ArrayList<String>();
    int max = 0;

    for (int i=0;i<n;i++){
      if (b[i] == false){
        int sum = 1;
        HashSet<Integer> check = a.get(i);
        b[i] = true;
        for (int kk : check){
          if (b[kk-1] == false){
              b[kk-1] = true;
              q.add(kk+"");
          }
        }

        while (q.size() > 0){
          sum += 1;
          int aa = Integer.parseInt(q.get(0));
          q.remove(0);
          HashSet<Integer> check1 = a.get(aa-1);
          for (int kkk : check1){
            if (b[kkk-1] == false){
                b[kkk-1] = true;
                q.add(kkk+"");
            }
          }
        }
        max = Math.max(max,sum);
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 128948
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

#define F first
#define S second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    string a, b, c;
    cin >> a >> b >> c;
    if (a[a.length()-1] == b[0] && b[b.length()-1] == c[0]) {
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int a, b;
    cin >> a >> b;
    if(a>b)swap(a,b);
    int ans;
    if(a==1 && b==2) ans=3;
    if(a==2 && b==3) ans=1;
    if(a==1 && b==3) ans=2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}


vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  set<int> ok;

  auto div1 = divisor(N - 1);
  for (auto elem : div1) {
    if (elem == 1)
      continue;
    ok.insert(elem);
  }

  auto div2 = divisor(N);
  for (auto k : div2) {
    if (k == 1)
      continue;
    int N_cp = N;
    while (N_cp % k == 0)
      N_cp /= k;
    if (N_cp % k == 1)
      ok.insert(k);
  }

  int ans = len(ok);
  cout << ans << endl;
}

Measured memory_bytes: 384
import math

n,d = list(map(int,input().split()))

# x = []
# y = []
cnt = 0
for i in range(0,n):
    x,y = list(map(int,input().split()))
    # x.append(a)
    # y.append(b)
    k = math.sqrt(x**2 + y**2)
    if k <= d :
        cnt += 1

print(cnt)

Measured memory_bytes: 9200
h, w, _ = gets.split.map(&:to_i)
s = Array.new(h){gets.chomp.chars}
a = Array.new(h){Array.new(w, 0)}
k = 0
h.times do |i|
  k += 1
  x = 0
  f = true
  w.times do |j|
    if s[i][j] == '#' && f
      f = false
      x.upto(j) do |y|
        a[i][y] = k
      end
      x = j + 1
    elsif s[i][j] == '#' && f == false
      k += 1
      a[i][j] = k
      x = j + 1
    else
      k += 1 if f == false
      f = true
    end
  end
  if s[i][-1] == '.'
    k -= 1
    x.upto(w - 1) do |y|
      a[i][y] = k
    end
  end
end
y = 0
f = true
h.times do |i|
  if s[i].all?{|x| x == '.'} && f
    y = i
    f = false
  elsif s[i].any?{|x| x =='#'} && f == false
    y.upto(i.pred) do |z|
      a[z] = a[i]
    end
    f = true
  end
end
y = 0
f = true
h.pred.downto(0) do |i|
  if s[i].all?{|x| x == '.'} && f
    y = i
    f = false
  elsif s[i].any?{|x| x == '#'} && f == false
    y.downto(i) do |z|
      a[z] = a[i]
    end
    f = true
  end
end
h.times do |i|
  puts a[i].join(' ')
end

Measured memory_bytes: 11004
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    int n; cin>>n;
    vector<ll> x(n);
    vector<ll> x2(n);
    rep(i,0,n){
        cin>>x[i];
        x2[i] = x[i];
    }
    sort(all(x2));
    ll right=x2[n/2];
    ll left=x2[n/2 -1];
    rep(i,0,n){
        if(x[i]<=left) cout<<right<<endl;
        else cout<<left<<endl;
    }

}

Measured memory_bytes: 5376
n, m = gets.strip.split.map(&:to_i)
nab = n.times.map{ gets.strip.split.map(&:to_i) }
mcd = m.times.map{ gets.strip.split.map(&:to_i) }

nab.each do |xi|
    distance = -1
    indexNumber = 0
    mcd.each_with_index do |var, index|
        temDistance = (var[0] - xi[0]).abs + (var[1] - xi[1]).abs
        if  distance == -1 || temDistance < distance then
            indexNumber = index
            distance = temDistance
        end
    end
    puts indexNumber.succ
end

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


//TEMPLATE
#define pb              push_back
#define mp              make_pair
#define ll              long long
#define ld              long double
//#define pi              3.1415926536
#define pi              acos(-1)
#define newline         printf("\n")
#define printminusone   printf("-1\n")
#define scl1(n)         scanf("%lld", &n)
#define scl2(a, b)      scanf("%lld %lld", &a, &b)
#define scl3(a, b, c)   scanf("%lld %lld %lld", &a, &b, &c)
#define printl(n)       printf("%lld\n", n)
#define ssl1(str)       scanf(" %[^\n]", str)
#define scd1(n)         scanf("%lf", &n)
#define scd2(a, b)      scanf("%lf %lf", &a, &b)
#define printd(n)       printf("%lf\n", n)
#define printld(n)      printf("%Lf\n", n)
#define printcase       printf("Case %lld: ", i)
#define reversed(s)     reverse(s.begin(), s.end())
#define asort(s)        sort(s.begin(), s.end())
#define dsort(s)        sort(s.rbegin(), s.rend())
#define for0(i, n)      for (i = 0; i < n; i++)
#define for1(i, n)      for (i = 1; i <= n; i++)
#define fori(itt, stt)  for(auto itt = stt.begin(); itt != stt.end(); itt++)
#define pii             pair <ll, ll>
#define piii            pair <ll, pii>
#define F               first
#define S               second
#define FR              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ms(arr, x)      memset(arr, x, sizeof arr)
#define bitcount(n)     __builtin_popcountll(n)
#define all(s)          s.begin(), s.end()

const ll INF = LLONG_MAX;
const ll SZ = 2e5+5;
const ll mod = 998244353;


ll c1, c2;
ll ex_euclid(ll a, ll b) {
    if(b == 0) {
        c1 = 1;
        c2 = 0;
        return a;
    }

    ll g = ex_euclid(b, a%b);

    ll x1 = c1;
    c1 = c2;
    c2 = x1 - c2 * (a/b);

    return g;
}

ll mod_inverse(ll a, ll m) {
    ll g = ex_euclid(a, m);

    return ((c1%m) + m) % m;
}

ll ft[SZ], invf[SZ];
void cal_fact() {
    ll i;
    ft[0] = 1;
    invf[0] = mod_inverse(ft[0], mod);

    for(i = 1; i < SZ; i++) {
        ft[i] = (ft[i-1]%mod * i%mod) % mod;
        invf[i] = mod_inverse(ft[i], mod);
    }
}

ll ncr_mod(ll x, ll y) {
    ll r1 = (ft[x]%mod * invf[y]%mod) % mod;
    ll res = (r1%mod * invf[x-y]%mod) % mod;
    return res;
}

ll bigmod(ll x, ll y) {
    if(y == 0) return 1;

    ll res = bigmod(x, y/2);
    res = (res * res) % mod;
    if(y%2 == 1) res = (res * x) % mod;

    return res;
}

int main() {
    cal_fact();
    ll t = 0, n, m, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0;
    string s, s1, s2;

    scl3(n, m, k);

    if(m == 1) {
        if(k == n-1) puts("1");
        else puts("0");
        return 0;
    }

    for1(p, n) {
        if(n-p > k) continue;

        x = ncr_mod(n-1, p-1);
        y = (m * bigmod(m-1, p-1)) % mod;
        z = (x * y) % mod;
        ans = (ans + z) % mod;
    }

    printl(ans);

    return 0;
}



Measured memory_bytes: 6896
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=1e6+5;
const int mod=1e9+7;
long long f[N]={0},s[N]={0},ans=0LL,n;;
int main()
{
	scanf("%lld",&n);
	f[0]=1ll;s[0]=1ll;
	f[1]=1ll;s[1]=2;
	f[2]=1ll;s[2]=3;
	for(int i=3;i<=n;i++)
	{
		f[i]=(f[i-1]+s[i-3])%mod;
		s[i]=(s[i-1]+f[i])%mod;
	}
	for(int i=0;i<=n-2;i++) 
	  ans+=f[i]*((n-1)*(n-1)%mod+i+1)%mod;
	ans=(ans+(n-1)*f[n-1]%mod)%mod;
	ans=(ans+f[n])%mod;
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;

void solve()
{
    int n;
    cin >> n;
    vector <int> k(n + 1), l(n + 1), r(n + 1);
    vector <int> f, s;
    for (int i = 1; i <= n; i++)
    {
        cin >> k[i] >> l[i] >> r[i];
        if (l[i] >= r[i])
            f.push_back(i);
        else
            s.push_back(i);
    }
    long long ans = 0;
    set < pair <int, int> > st;
    sort(f.begin(), f.end(), [&](int x, int y)
        {
            return k[x] < k[y];
        });
    for (int i = 0; i < f.size(); i++)
    {
        int id = f[i];
        if (st.size() < k[id])
        {
            st.insert({ l[id] - r[id], id });
        }
        else {
            if (st.empty())
            {
                ans += r[id];
                continue;
            }
            pair <int, int> p = *st.begin();
            if (l[p.second] - r[p.second] < l[id] - r[id])
            {
                ans += r[p.second];
                st.erase(st.begin());
                st.insert({ l[id] - r[id], id });
            }
            else {
                ans += r[id];
            }
        }
    }
    while (!st.empty())
    {
        pair <int, int> p = *st.begin();
        ans += l[p.second];
        st.erase(st.begin());
    }
    sort(s.begin(), s.end(), [&](int x, int y)
        {
            return k[x] > k[y];
        });
    for (int i = 0; i < s.size(); i++)
    {
        int id = s[i];
        if (st.size() < (n - k[id]))
        {
            st.insert({ r[id] - l[id], id });
        }
        else {
            if (st.empty())
            {
                ans += l[id];
                continue;
            }
            pair <int, int> p = *st.begin();
            if (r[p.second] - l[p.second] < r[id] - l[id])
            {
                ans += l[p.second];
                st.erase(st.begin());
                st.insert({ r[id] - l[id], id });
            }
            else {
                ans += l[id];
            }
        }
    }
    while (!st.empty())
    {
        pair <int, int> p = *st.begin();
        st.erase(st.begin());
        ans += r[p.second];
    }
    cout << ans << endl;
}

int main()
{
    int tt;
    cin >> tt;
    while (tt--) solve();
}

Measured memory_bytes: 11160
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()() {
		return 0;
	}
};

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

	for(;;)
	{
		int n;
		cin >> n;
		if(cin.fail()) break;

		vi a(n);
		for(auto&m:a) cin >> m;

		int full_xor=0;
		for(auto m:a) full_xor^=m;

		vi ans(n);
		for(int i=0;i<n;i++) ans[i]=full_xor^a[i];

		for(int i=0;i<n-1;i++) cout << ans[i] << " ";
		cout << ans[n-1] << "\n";
	}
	return 0;
}


Measured memory_bytes: 4712
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

// DAG - directed acyclic graph

const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) {
	assert(!visited[a]);
	visited[a] = true;
	for (int b : edges[a]) {
		dist[b] = max(dist[b], dist[a] + 1);
		--in_degree[b];
		if (in_degree[b] == 0) {
			dfs(b);
		}
	}
}

int main() {
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, m;
	scanf("%d%d", &n, &m);
	while (m--) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		++in_degree[b];
	}
	ll ctr = 0;
	for (int i = 1; i <= n; ++i) {

		if (!visited[i] && in_degree[i] == 0) {
			ctr++;
			dfs(i);
		}
	}
	int answer = 0;
	for (int i = 1; i <= n; ++i) {
		answer = max(answer, dist[i]);
	}
	printf("%d\n", answer);
}

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

typedef unsigned long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;

#define INF (int)(1e9)

#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,start,end) for(int i=(start);i<=(end);i++)
#define all(n) begin(n),end(n)

#define DEBUG

int main()
{
	const string abc = "abc";
	string s;
	cin >> s;
	sort(s.begin(),s.end());

	bool ans = true;
	rep(i,3)
	{
		if(abc[i] != s[i]) ans = false;
	}

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

Measured memory_bytes: 256
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


def main():
    num, time_lim = map(int, input().split())
    data = list(map(int, input().split()))

    ans = 0
    next_time = 0
    for i in range(num):
        now_time = data[i]
        if now_time >= next_time:
            next_time = now_time + time_lim
            ans += time_lim
        else:
            ans += now_time + time_lim - next_time
            next_time = now_time + time_lim
        # print(ans, now_time)
    print(ans)

if __name__ == '__main__':
    main()



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

int main() {
  int a, b;
  string s;
  cin >> a >> b >> s;
  string ans = "Yes";
  int n = a + b + 1;
  for(int i=0; i<n; i++) {
    if(i==a) {
      if(s.at(i) != '-') {
        ans = "No";
        break;
      }
    } else {
      if(s.at(i) == '-') {
        ans = "No";
        break;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int N , K;
  cin >> N >> K ;
  int i = 0 , j = 1 , m = 0 , l = 0 ;
  
  for ( i ; i < N ; i ++ )
  {
    m = j * 2 ;
    l = j + K ;
    if ( m <= l )
      j = m ;
    else 
      j = l ;
  }
  cout << j << endl ;
}


Measured memory_bytes: 256
import copy
H,W = map(int, input().split())

l = []
l.append(["."]*(W+2))
for h in range(H):
  l.append(["."] + list(input()) + ["."])
l.append(["."]*(W+2))

ans = [[0 for w in range(W+2)] for h in range(H+2)]

for h in range(1,H+1):
  for w in range(1,W+1):
    if l[h][w] == "#":
      ans[h+1][w] += 1
      ans[h-1][w] += 1
      ans[h][w+1] += 1
      ans[h][w-1] += 1
      ans[h+1][w+1] += 1
      ans[h-1][w-1] += 1
      ans[h+1][w-1] += 1
      ans[h-1][w+1] += 1
      
for h in range(1,H+1):
  a = []
  for w in range(1,W+1):
    if l[h][w] == "#":
      a.append("#")
    else:
      a.append(str(ans[h][w]))
  print("".join(a))

Measured memory_bytes: 40432
MOD = 10 ** 9 + 7
M = 10 ** 3 + 7

N, A, B, C, D = map(int, input().split())

fact = [1] * M
inv = [1] * M
def mod_inv():
    for i in range(2, M):
        fact[i] = i * fact[i-1] % MOD
    inv[M-1] = pow(fact[M-1], MOD - 2, MOD)
    for i in range(M-1, 0, -1):
        inv[i-1] = i * inv[i] % MOD
mod_inv()

def nCr(n, r):
    if r > n // 2:
        r = n - r
    return fact[n] * inv[n-r] * inv[r] % MOD

dp = [[0] * M for _ in range(B+2)]
dp[A][0] = 1

for i in range(A, B+1):
    for j in range(N+1):
        p = 1
        l = (N - j) // i
        for k in range(min(D, l) + 1):
            if k == 0 or C <= k:
                dp[i+1][j+i*k] += p * dp[i][j] * inv[k]
                dp[i+1][j+i*k] %= MOD
            p *= nCr(N-i*k-j, i)
            p %= MOD
print(dp[B+1][N])

Measured memory_bytes: 123740
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N,K,Q;
  cin >> N >> K >> Q;
  vint ans(N,K-Q);
  REP(i,Q){
    int a;
    cin >> a;
    a--;
    ans[a]++;
  }
  
  for(auto a : ans){
    if(0 < a){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  
  
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

char s[100010];
ll cnt[30];
ll ans,n;
int main(){
	scanf("%lld %s",&n,s);
	rep(i,0,n){
		int c=s[i]-'a';
		ll ss=1;
		rep(j,0,26)if(j!=c)ss=ss*(cnt[j]+1)%MOD;
		ans=(ans+ss)%MOD;
		cnt[c]++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 256
S = list(input())



sum = 0

for i in range(2**(len(S)-1)):


    op_list = ["+"]*(len(S)-1)
    for j in range(len(S)-1):
        if (i>>j) & 1:
            op_list[j] = ""
    s = ""
    for k in range(len(S)-1):
        s = s + S[k] + op_list[k]

    s = s + S[len(S)-1]

    sum = sum + eval(s)


print(sum)

    


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

using namespace std;

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

    string s;
    cin >> s;

    auto mid = s.length() - 1;
    long long total = 0;
    for (unsigned long i = 0; i < 1 << mid; ++i) {
        unsigned long pre = 0;
        long long sub_total = 0;
        for (unsigned long j = 0; j < mid; j++) {
            if ((i >> j) % 2 == 1) {
                sub_total += stoll(s.substr(pre, j + 1 - pre));
                pre = j + 1;
            }
        }
        sub_total += stoll(s.substr(pre));
        total += sub_total;
    }

    cout << total << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int n;
  char suits[52];
  int ranks[52];
  int i, j;
 
  int cards[4][14] = {{}};
 
  scanf("%d ", &n);
  for(i = 0; i < n; ++i) {
    scanf("%c %d ", &suits[i], &ranks[i]);
 
    if(suits[i] == 'S') {
      cards[0][ranks[i]] = 1;
    } else if(suits[i] == 'H') {
      cards[1][ranks[i]] = 1;
    } else if(suits[i] == 'C') {
      cards[2][ranks[i]] = 1;
    } else if(suits[i] == 'D') {
      cards[3][ranks[i]] = 1;
    }
  }
 
  for(i = 0; i < 4; ++i) {
    for(j = 1; j <= 13; ++j) {
      if(cards[i][j] == 0) {
    if(i == 0) printf("S ");
    else if(i == 1) printf("H ");
    else if(i == 2) printf("C ");
    else if(i == 3) printf("D ");
    printf("%d\n", j);
      }
    }
  }
 
  return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
typedef long long ll;
#define sz(x) int(x.size())
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define MOD 1000000007
using namespace std;
 
 
int main(){
    int N; cin >> N;
    int A[N][3]; rep(i,N) cin >> A[i][0] >> A[i][1] >> A[i][2];
    int dp[100001][3]; 
    rep(i,100001){
        rep(j,3) dp[i][j] = 0;
    }
    dp[0][0] = A[0][0]; dp[0][1] = A[0][1]; dp[0][2] = A[0][2];
    for (int i = 0; i < N-1; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            dp[i+1][j] = max(dp[i][(j+1)%3],dp[i][(j+2)%3]) + A[i+1][j];
        }
        
    }
    
    cout << max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2])) << endl;
}

Measured memory_bytes: 2560
sx, sy, tx, ty = map(int, input().split())

ans = ""
for i in range(ty - sy):
    ans += "U"
for i in range(tx - sx):
    ans += "R"
for i in range(ty - sy):
    ans += "D"
for i in range(tx - sx + 1):
    ans += "L"
for i in range(ty - sy + 1):
    ans += "U"
for i in range(tx - sx + 1):
    ans += "R"
ans += "D"
ans += "R"
for i in range(ty - sy + 1):
    ans += "D"
for i in range(tx - sx + 1):
    ans += "L"
ans += "U"

print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public Hello(){}
    public static void Main(){
       new Hello().Calc();
    }
    void Calc(){
        var inputs = InputValues;
        foreach(var i in inputs){
            Console.WriteLine(i);
        }
    }
    
    List<string> InputValues{
        get{
            var inputs = new List<string>();
            
            while(true){
                var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                var m = a[0];
                var f = a[1];
                var r = a[2];
                
                var sum = m + f;
                if(m == -1 && f == -1 && r == -1){
                    break;
                }
                if(m == -1 || f == -1){
                    inputs.Add("F");
                }else if(sum >= 80){
                    inputs.Add("A");
                }else if(sum >= 65){
                    inputs.Add("B");
                }else if(sum >= 50){
                    inputs.Add("C");
                }else if(sum >= 30){
                    if(r >= 50){
                        inputs.Add("C");
                    }else{
                        inputs.Add("D");
                    }
                }else{
                    inputs.Add("F");
                }
                
            }
            return inputs;
        }
    }
}



Measured memory_bytes: 8264
#include <algorithm> //STLͨ���㷨
#include <cmath> //������ѧ����
#include <cstdio> //��������/�������
#include <iostream> //����������/���
#include <cstring> //�ַ�������
#include <string> //�ַ�����
#include <ctime> //�������ʱ��ĺ���
#define itn int
#define fro for
#define ll long long
#define reg register
#define inf 1234567890
#define rep(i,a,b,c) for (int i=a;i<=b;i+=c)
/*#include <bitset> //STLλ������
#include <cstype> //�ַ�����
#include <cerrno> //���������
#include <complex> //������
#include <clocale> //���屾�ػ�����
#include <cstdlib> //������������ڴ���亯��
#include <deque> //STL˫�˶�������
#include <exception> //�쳣������
#include <fstream> //�ļ�����/���
#include <functional> //STL�������㺯��(���������)
#include <limits> //�����������������ֵ����
#include <list> //STL�����б�����
#include <map> //STLӳ������
#include <iomanip> //����������/���
#include <ios> //��������/���֧��
#include <iosfwd> //����/���ϵͳʹ�õ�ǰ������
#include <istream> //����������
#include <ostream> //���������
#include <queue> //STL��������
#include <set> //STL��������
#include <sstream> //�����ַ�������
#include <stack> //STL��ջ����
#include <stdexcept> //��׼�쳣��
#include <streambuf> //�ײ�����/���֧��
#include <utility> //STLͨ��ģ����
#include <vector> //STL��̬��������
#include <cwchar.h>//���ַ�����������/���
#include <cwctype.h> //���ַ�����*/

using namespace std;

ll ans;

int max(int x,int y){return x>y?x:y;}

int min(int x,int y){return x<y?x:y;}

int abs(int x){return x>0?x:-x;}

int gcd(int x,int y){return (!y)?x:gcd(y,x%y);}

void exgcd(int a,int b,int &d,int &x,int &y){if (!b){d=a,x=1,y=0;}else{exgcd(b,a%b,d,y,x);y-=x*(a/b);}}

int quick_power(ll a,int b){ll r=1;for (;b;b>>=1,a=a*a)if (b&1) r=r*a;return r;}

inline char read() {
	static const int IN_LEN = 1000000;
	static char buf[IN_LEN], *s, *t;
	return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);
}
template<class T>
inline void read(T &x) {
	static bool iosig;
	static char c;
	for (iosig = false, c = read(); !isdigit(c); c = read()) {
		if (c == '-') iosig = true;
		if (c == -1) return;
	}
	for (x = 0; isdigit(c); c = read()) x = x * 10 + (c ^ '0');
	if (iosig) x = -x;
}

char sr[10000000],z[20];int C=-1,Z=0;
void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(int x){
	if (x<0) sr[++C]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
//int find(int x){return fa[x]=fa[x]==x?x:find(fa[x]);}

//void add(int x,int y,int z){to[++cnt]=y;v[cnt]=z;Next[cnt]=head[x];head[x]=cnt;}

const int mod=1e9+7;
char s[200200];

int tmp,lsh;

int main()
{
	int n;
	cin>>n;
	ans=1;
	for (int i=1;i<=n;i++) ans*=i,ans%=mod;
	scanf("%s",s+1);
	for (int i=1;i<=n*2;i++)
	{
		if ((tmp%2)^(s[i]=='B')) tmp++;
		else (ans*=tmp)%=mod,tmp--,lsh++;
	}
	cout<<ans*(lsh==n);
	return 0;
}









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

#define Inv(x) QPow(x,Mod-2);

const int maxN=2005;
const int maxM=maxN*maxN;
const int Mod=1e9+7;

int n,K;
int Fc[maxM],Ifc[maxM];
int F[maxN][maxN];

int QPow(int x,int cnt);
int C(int n,int m);
int main(){
    Fc[0]=Ifc[0]=1;for (int i=1;i<maxM;i++) Fc[i]=1ll*Fc[i-1]*i%Mod;
    Ifc[maxM-1]=Inv(Fc[maxM-1]);for (int i=maxM-2;i>=1;i--) Ifc[i]=1ll*Ifc[i+1]*(i+1)%Mod;
    
    scanf("%d%d",&n,&K);
    if (K==1){
	puts("1");return 0;
    }

    F[0][0]=1;
    for (int i=1;i<=n;i++)
	for (int j=n;j>=0;j--){
	    if (j<=i&&j>=0) F[i][j]=1ll*F[i-1][j-1]*C(i*K-j-1,K-2)%Mod;
	    F[i][j]=(F[i][j]+F[i][j+1])%Mod;
	}
    /*
    for (int i=0;i<=n;i++){
	for (int j=0;j<=n;j++) cout<<F[i][j]<<" ";
	cout<<endl;
    }//*/
    int Ans=1ll*F[n][0]*Fc[n]%Mod;
    printf("%d\n",Ans);return 0;
}
int QPow(int x,int cnt){
    int ret=1;
    while (cnt){
	if (cnt&1) ret=1ll*ret*x%Mod;
	x=1ll*x*x%Mod;cnt>>=1;
    }
    return ret;
}
int C(int n,int m){
    if (n<0||m<0||n<m) return 0;
    return 1ll*Fc[n]*Ifc[m]%Mod*Ifc[n-m]%Mod;
}


Measured memory_bytes: 47360
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <list>
#include <cmath>
#include <stack>
#include <queue>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

int main()
{
	long n;
	cin >> n;
	while (!IsPrime(n))
	{
		n++;
	}
	cout << n;
}


Measured memory_bytes: 31488
import sys
from bisect import bisect_right

def main():
  input = sys.stdin.readline
  N, M, X = map(int, input().split())
  A = list(map(int, input().split()))
  x = bisect_right(A, X)
  print(min(x, M-x))


if __name__ == '__main__':
  main()

Measured memory_bytes: 2940
#include<iostream>
#include<iomanip>
#include<cassert>
#include<math.h>
#include<complex>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
ll A[100];
bool over[100];
int main(){
    cin>>N;
    for(ll i=0;i<N;i++)cin>>A[i];
    for(ll i=0;i<N;i++){
        for(ll j=i+1;j<N;j++){
            over[i]=true;
            if(A[i]==A[j])continue;
            if(A[i]<A[j])over[i]=true;
            else over[i]=false;
            break;
        }
    }
    ll nowM=1000;
    ll nowK=0;
    for(ll i=0;i<N;i++){
        if(over[i]){
            nowK+=nowM/A[i];
            nowM-=nowM/A[i]*A[i];
        }else{
            nowM+=nowK*A[i];
            nowK=0;
        }
    }
    cout<<nowM<<endl;
    
    return 0;
}

Measured memory_bytes: 3632
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

ll ans(ll a , ll b){
    if(a < b)return a;
    else if(a % b == 0)return ans(a/b,b);
    else return ans(a%b,b);
}

set < ll > dvs;
void dv(ll v){
    for(ll i = 1; i<=sqrt(v)+1; i++){
        if(v % i == 0){
            dvs.insert(i);
            dvs.insert(v/i);
        }
    }
}

int main()
{
    ll n; cin >> n;
    dv(n);
    dv(n-1);
    set < ll > an;
    dvs.erase(1);
    for(auto v : dvs){
        if(ans(n,v) == 1)an.insert(v);
    }
    cout << an.size() << endl;
    return 0;
}
/*

for(int i = 1; i<=1000000; i++){
        if(i > n)break;
        if(n%i == 0){
            divisor.insert(n/i);
            divisor.insert(i);
        }
    }
    for(int i = 1; i<=1000000; i++){
        if(i > (n-1)){
            break;
        }
        if((n-1)%i == 0){
            divisor.insert(n/i);
            divisor.insert(i);
        }
    }
    set < ll > an;
    for(auto v : divisor){
        if(ans(v,n)==1)an.insert(v);
    }
    cout << an.size() << endl;

*/


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

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

    while(n>0){
        int t = n%10;
        if(t == 7){
            cout<<"Yes";
            return 0;
        }
        n/=10;
    }
    cout<<"No";
}


Measured memory_bytes: 3636