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

using namespace std;

int main() {
    int N, K, R, S, P;
    string t;

    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> t;

    int total_point = 0;
    for (int diff_k=0; diff_k<K; diff_k++) {
        int r_cnt = 0, s_cnt = 0, p_cnt = 0;

        char prev_win = false;
        for (int i=N-1-diff_k; i>=0; i-=K) {

            char hand = t[i];
            int next_index = i + K;
            // 後ろのindexが必ず最善の手をとるようにする。k個前が同じ手が最善でも必ず最善を取る。

            if (hand == 'r') {
                if (prev_win && (next_index < N && t[next_index] == 'r')) {
                    prev_win = false;
                } else {
                    r_cnt++;
                    prev_win = true;
                }
            } else if (hand == 'p') {
                if (prev_win && (next_index < N && t[next_index] == 'p')) {
                    prev_win = false;
                } else {
                    p_cnt++;
                    prev_win = true;
                }
            } else if (hand == 's') {
                if (prev_win && (next_index < N && t[next_index] == 's')) {
                    prev_win = false;
                } else {
                    s_cnt++;
                    prev_win = true;
                }
            }
        }

        total_point += r_cnt * P;
        total_point += p_cnt * S;
        total_point += s_cnt * R;
    }

    cout << total_point << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <climits>
#include <cstring>
#include <utility>
#include <cmath>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define F first
#define S second 
#define pb push_back
#define all(x) x.begin(),x.end()
#define endl "\n"


void print() { cout << endl; }

template <typename T, typename... Types>
void print(T arg, Types... args) {
    cout << arg << " ";
    print(args...);
}

typedef long long ll;
typedef long double ld;
typedef pair< int, int > pii;
typedef vector < int > vi;

const int mod = 1e9 + 7;
const int N = 2e5 + 7;


ll gcdExtended(ll a, ll b, ll *x, ll *y){
    if (a == 0){
        *x = 0, *y = 1;
        return b;
    }
    ll x1, y1;
    ll gcd = gcdExtended(b%a, a, &x1, &y1);
    *x = y1 - (b/a) * x1;
    *y = x1;
    return gcd;
}

ll modInv(ll a, ll m){
    ll x, y;
    ll g = gcdExtended(a, m, &x, &y);
    ll res = (x%m + m) % m;
    return res;
}
 
 
ll mpower(ll x, ll y, ll p){
    ll res = 1;
    x = x % p;
    while(y > 0){
        if(y & 1) res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
 
ll power(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}
 
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}



int main()
{
    IOS;
    ll n, k;
    cin >> n >> k;
    ll a = n % k;
    cout << min(a, k-a) << endl;
    return 0;
}


Measured memory_bytes: 256
object ABC051B {

  import Competitive._

  val K, S = nextInt
  println(Range.inclusive(0, Math.min(K, S)).map(x => S - x).map(r => Math.max(Math.min(r, K) - Math.max(r - K, 0) + 1, 0)).sum)
}
object Main extends App{
  ABC051B
}

object Competitive{
  import scala.io.StdIn.readLine

  implicit class ForInt(val self: Int) {
    @inline def fori(from: Int)(body: Int => Unit): Unit = {
      var i = from
      while (i < self) {
        body(i)
        i += 1
      }
    }

    @inline def fori()(body: Int => Unit): Unit = fori(0)(body)

    @inline def times(body: => Unit): Unit = fori(0){_ => body}
  }

  private var tokenizerBack = readLine().split(" ").iterator
  def tokenizer: Iterator[String] = {
    tokenizerBack = if (tokenizerBack.hasNext) tokenizerBack else readLine().split(" ").iterator
    tokenizerBack
  }

  def next: String = tokenizer.next
  def nextInt: Int = next.toInt
  def nextLong: Long = next.toLong
  def nextIntArray(n: Int): Array[Int] = Array.fill(n)(nextInt)
  def nextLongArray(n: Int): Array[Long] = Array.fill(n)(nextLong)
  def nextArray(n: Int): Array[String] = Array.fill(n)(next)
}

Measured memory_bytes: 25412
#include <bits/stdc++.h> 
#include<string> 
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<char> vc;

typedef map<long long,long long> mpi;
#define llu unsigned long long 
#define vbi vector<bool> 
#define mod 1000000007
#define all(v) (v).begin(), (v).end()
#define alr(x) x.rbegin(),x.rend()
#define mp make_pair
#define pb push_back
#define sd second
#define ft first
#define endl '\n'
#define cnl cout<<endl;
#define frr(i,b) for(ll i=0; i<b;i++)
#define fb(i,b) for(ll i=b-1; i>=0; i--)
#define ms(x,v) memset(x,v, sizeof(x))
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define print_vec(v) for(ll i=0;i<(int)v.size();i++) cout<<v[i]<<" ";
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
const int N = 2e5 + 5;
using pi = pair<ll, ll>;
ll i,j,k;
void solve(){
  ll n;cin>>n;
  string s; cin>>s;
  
   ll ans=0;
   for(i=0;i<n-2;i++){
    string r="";
     for(j=i;j<i+3;j++){
       r.pb(s[j]);
     }
     if(r=="ABC") ans++;
   }
   cout<<ans<<endl;
  

return ;
}
signed main(){
    
    //CASET
    solve () ;
  
 
 
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iostream>
using namespace std;
int n;
int a[1000000];
int yu[1000000];

int main(){
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
a[i]--;
}
int res=0;

for(int i=0;i<n;i++){
if(a[a[i]]==i && yu[i]==0 && yu[a[i]]==0){
res++;
yu[i]=yu[a[i]]=1;
}
}

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

return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


typedef pair<int, int> p;
int main() { 
    int x1, y1; cin >> x1 >> y1;
    int x2, y2; cin >> x2 >> y2;
    int x3, y3, x4, y4;

    int dx = x2 - x1;
    int dy = y2 - y1;

    x3 = x2 - dy;
    y3 = y2 + dx;
    x4 = x1 - dy;
    y4 = y1 + dx;
    
    print(x3, y3, x4, y4);
    
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# DPL_1_D: Combinatorial - Longest Increasing Subsequence


class SegmentTree:
    def __init__(self, n):
        size = 2**n.bit_length()
        self.size = 2*size - 1
        self.data = [0] * self.size

    def max(self, lo, hi):
        def _max(r, i, j):
            if j < lo or i > hi:
                return 0
            elif lo <= i and j <= hi:
                return self.data[r]
            else:
                mid = (i + j) // 2
                return max(_max(r*2+1, i, mid), _max(r*2+2, mid+1, j))

        return _max(0, 0, self.size//2)

    def set(self, i, v):
        r = self.size//2 + i
        self.data[r] = v
        while r > 0:
            r = (r-1) // 2
            self.data[r] = max(self.data[r*2 + 1], self.data[r*2 + 2])


def longest_increasing_subseq(vs):
    index = {v: i for i, v in enumerate(sorted(set(vs)))}
    seg = SegmentTree(len(index))
    c = 1

    for i in range(len(vs)):
        j = index[vs[i]]
        _c = seg.max(0, j-1)+1
        if _c > c:
            c = _c
        seg.set(j, _c)

    return c


def run():
    n = int(input())
    vs = []

    for _ in range(n):
        vs.append(int(input()))

    print(longest_increasing_subseq(vs))


if __name__ == '__main__':
    run()



Measured memory_bytes: 26900
import java.util.*;


class Main{
    public static void main(String[] args){
    	Scanner sc= new Scanner(System.in);
    String s=sc.nextLine(),p=sc.nextLine();
    char[] l1 = s.toCharArray();
    char[] l2 = p.toCharArray();

   int flag=0;
   for(int i=0;i<s.length();i++){
	   if(flag>=p.length()) break; 	
	if(l1[i]==l2[0]) {
		int temp=i;
	      for(int j=0;j<p.length();j++){ 
			if(temp==s.length())temp=0;
			if(l2[j]!=l1[temp]){
				flag=0;
				break; 
			}
			temp++;flag++;
			}
	    }
	   }
   if(flag==0){System.out.println("No");
   }
   else System.out.println("Yes");
	  }
 }
    

Measured memory_bytes: 26252
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, m;
vector<int> a, b, u, v;

vector<long long> dp;
int d2i(int edg, int ok){
    return edg * (1<<m) + ok;
}

vector< vector<int> > dst;

long long f(int edg, int ok){
    if(edg == n-1) return (ok == (1<<m)-1);
    int id = d2i(edg, ok);
    if(dp[id] != -1) return dp[id];
    long long res = f(edg+1, ok);
    for(int i=0;i<m;i++){
        if(dst[u[i]][v[i]] < dst[u[i]][a[edg]] + dst[a[edg]][v[i]]) continue;
        if(dst[u[i]][v[i]] < dst[u[i]][b[edg]] + dst[b[edg]][v[i]]) continue;
        ok |= (1<<i);
    }
    res += f(edg+1, ok);
    return dp[id] = res;
}

int main(void){
    cin >> n;
    a.assign(n-1, 0);
    b.assign(n-1, 0);
    for(int i=0;i<n-1;i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    cin >> m;
    u.assign(m, 0);
    v.assign(m, 0);
    for(int i=0;i<m;i++){
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
    }


    dst.assign(n, vector<int>(n, n));
    for(int i=0;i<n;i++){
        dst[i][i] = 0;
    }
    for(int i=0;i<n-1;i++){
        dst[a[i]][b[i]] = dst[b[i]][a[i]] = 1;
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dst[i][j] = min(dst[i][j], dst[i][k] + dst[k][j]);
            }
        }
    }

    dp.assign(n*(1<<m), -1);

    long long ans = f(0, 0);
    cout << ans << endl;

}


Measured memory_bytes: 409856
#include <iostream>

int
main(void)
{
  int n, i, x, y, data[4][14];
  char ch;

  for (y = 0; y < 4; y++) {
    for (x = 0; x < 14; x++) {
      data[y][x] = 0;
    }
  }

  std::cin >> n;
  for (i = 0; i < n; i++) {
    std::cin >> ch >> x;
    switch (ch) {
    case 'S':
      y = 0;
      break;
    case 'H':
      y = 1;
      break;
    case 'C':
      y = 2;
      break;
    case 'D':
      y = 3;
      break;
    }
    data[y][x] = 1;
  }

  for (y = 0; y < 4; y++) {
    for (x = 1; x <= 13; x++) {
      if (data[y][x] != 1) {
        if (y == 0) {
          ch = 'S';
        } else if (y == 1) {
          ch = 'H';
        } else if (y == 2) {
          ch = 'C';
        } else if (y == 3) {
          ch = 'D';
        }
        std::cout << ch << ' ' << x << std::endl;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  cin>>N>>K;
  long S;
  cin>>S;
  vector<long>A(N);
  for(int i=0;i<K;i++)A[i]=S;
  if(S==1000000000){
	for(int i=K;i<N;i++)A[i]=1;
  }else for(int i=K;i<N;i++)A[i]=S+1;
  for(int i=0;i<N-1;i++)cout<<A[i]<<" ";
  cout<<A[N-1]<<endl;
}

Measured memory_bytes: 2048
def main():
    mod = 10**9 + 7
    n = int(input())

    # store last 3 characters
    # 'A':0, 'C':1, 'G':2, 'T':3
    dp = [[[0] * 4 for _ in range(4)] for _ in range(4)]
    dp[3][3][3] = 1
    for i in range(n):
        new_dp = [[[0] * 4 for _ in range(4)] for _ in range(4)]
        for i in range(4):
            for j in range(4):
                for k in range(4):
                    num = dp[i][j][k]

                    # add all
                    for l in range(4):
                        new_dp[j][k][l] += num

                    # delete
                    # AG?C or ?AGC or A?GC or ?GAC
                    if (i == 0 and j == 2) or (j == 0 and k == 2) or (i == 0 and k == 2) or (j == 2 and k == 0):
                        new_dp[j][k][1] -= num
                    # ?ACG
                    if j == 0 and k == 1:
                        new_dp[j][k][2] -= num

        for i in range(4):
            for j in range(4):
                for k in range(4):
                    dp[i][j][k] %= mod

        dp = new_dp

    for i in range(4):
        for j in range(4):
            dp[i][j] = sum(dp[i][j]) % mod
    for i in range(4):
        dp[i] = sum(dp[i]) % mod
    print(sum(dp) % mod)

main()

Measured memory_bytes: 74616
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc int t;cin>>t;while(t--)
#define otc int t=1;while(t--)
#define ll long long int
#define ld long double
#define pb push_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define ull unsigned long long int
#define memset(arr) memset(arr, 0, sizeof(arr));
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b)
{return (a.fi > b.fi);}

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

	int s,w;
	cin>>s>>w;
	if(w>=s)
		puts("unsafe");
	else
		puts("safe");
	return 0;

}

Measured memory_bytes: 3592
n,k = map(int,input().split());
i = 0;
if n == k:
    print(0);
elif n < k:
    print(min(n,k-n));
else:
    v = (n - k)%k;
    if v*2 >= k:
        print(k-v);
    else:
        print(v);

Measured memory_bytes: 9160
#include <stdio.h>
#include <math.h>
 
main(void) {
  double r, s, l, pai = acos(-1.0);
 
  scanf("%lf", &r);
 
  s = r * r *  pai;
  l = 2 * pai * r;
 
  printf("%f %f\n", s, l);
 
  return 0;
}

Measured memory_bytes: 648
object Main extends App{                                                             
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt

  for(i <- 0 until N) {
    val tmp = new Array[Int](3)
    for(j <- 0 until 3) tmp(j) = sc.nextInt

    val max = tmp.max
    val min1 = if(tmp(0) == tmp.max) tmp(1) else tmp(0)
    val min2 = if(tmp(2) == tmp.max) tmp(1) else tmp(2)

    val min1_pow = Math.pow(min1, 2)
    val min2_pow = Math.pow(min2, 2)
    val min = Math.sqrt(min1_pow + min2_pow)

    val check = if(max == min) "YES" else "NO"
    println(check)
  }

}

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

int main() {
    ll a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if(v<=w){
        cout << "NO" << endl;
        return 0;
    }
    ll dis = abs(a-b);
    if((dis/(double)t + w)<=v){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
#define L_MAX 1e18
using ll = long long;
using ld = long double;
using ii = pair<ll,ll>;
using iii = tuple<ll,ll,ll>;
using matrix = vector<vector<ll>>;
using arr = vector<ll>;
using vs = vector<string>;
using pv = vector<ii>;
using umap = unordered_map<ll,ll>;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
void showArr(arr a){
    for(auto i : a) cout<<i<<" ";
    cout<<endl;
}
ll dx[]={-1,1,-1,1,0,0,-1,1};
ll dy[]={-1,1,0,0,-1,1,1,-1};
int main(){
    fast;
    ll n,m,sum=0;
    cin>>n>>m;
   // n++;
    for(int i=0;i<m;i++){
        ll x;
        cin>>x;
        sum+=x;
    }
    if(n-sum<0){
        cout<<-1<<endl;
    }else{
        cout<<n-sum<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main() {
    long s;
    cin>>s;
	long long dp[s+1]={0};
	dp[0]=1;
	for(int i=1;i<=s;i++)
        for(int j=3;j<=s;j++)
    {
        if(j<=i)
            dp[i]=(dp[i]+dp[i-j])%mod;

    }
    cout<<dp[s];
}


Measured memory_bytes: 3588
#!/usr/bin/env python3

#import
import math
#import numpy as np
N = int(input())
L = list(map(int, input().split()))

L.sort()

def is_ok(arg, cmin, cmax):
    return L[arg] > cmin and L[arg] < cmax

def meguru_bisect(ok, ng, cmin, cmax):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid, cmin, cmax):
            ok = mid
        else:
            ng = mid
    return ok

ans = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        a = L[i]
        b = L[j]
        cmin = b - a
        cmax = a + b
        t = meguru_bisect(j, N, cmin, cmax)
        ans += t - j

print(ans)

Measured memory_bytes: 69332
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
int main(){
    map<char,int> m;
    string s;
    cin >> s;
    for(int i=0;i<s.size();i++){
        m[s[i]]++;
        if(m[s[i]]>1){
            cout << "no\n";
            return 0;
        }
    }
    cout << "yes\n";
    return 0;
}

Measured memory_bytes: 256
N, M, X = map(int, input().split(' '))
price, exp = [], [0] * N
for i in range(N):
    ls = list(map(int, input().split(' ')))
    price.append(ls[0])
    exp[i] = ls[1:]
rst = -1
for i in range(1 << N):
    price_combi, exp_combi, exp_sum, cnt = [], [], [0] * M, []
    for j in range(N):
        if i >> j & 1:
            price_combi.append(price[j])
            exp_combi.append(exp[j])
    for s in range(len(exp_combi)):
        for t in range(M):
            exp_sum[t] += exp_combi[s][t]
    [ cnt.append(i) for i in exp_sum if i >= X ]
    if len(cnt) == M:
        if rst == -1:
            rst = sum(price_combi)
        else:
            rst = min(rst, sum(price_combi))
print(rst)

Measured memory_bytes: 9024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ma=0;int mi=1000000000;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        ma=max(a,ma);
        mi=min(a,mi);
    }
    cout<<ma-mi<<endl;
}
        


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

typedef long long ll;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int N, X;
    cin >> N >> X;
    int L[N];
    rep(i, N) cin >> L[i];
    int D[N + 1];
    D[0] = 0;
    int count = 1;
    for(int i = 1; i < N + 1; i++){
        D[i] = D[i - 1] + L[i - 1];
        if(D[i] <= X) count++;
        else break;
    }
    cout << count << endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String s = scanner.next();
			int a = Integer.parseInt(s.substring(0, 2)), b = Integer.parseInt(s.substring(2));
			if (isMonth(a)) {
				if (isMonth(b)) {
					System.out.println("AMBIGUOUS");
				} else {
					System.out.println("MMYY");
				}
			} else {
				if (isMonth(b)) {
					System.out.println("YYMM");
				} else {
					System.out.println("NA");
				}
			}
		}
	}

	/**
	 * nが月の数になれるかを返す
	 * 
	 * @param n
	 * @return nが月の数になれるか
	 */
	private static boolean isMonth(int n) {
		return (n >= 1) && (n <= 12);
	}
}


Measured memory_bytes: 35780
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
set<P> T;
const ll MOD=1000000007;

int main()
{
	ll N,M;
	cin>>N>>M;
	string R="IMPOSSIBLE";
	for(int i=0;i<M;i++)
	{
		int a,b;
		cin>>a>>b;
		T.insert(make_pair(a,b));
		T.insert(make_pair(b,a));
		if(T.count(make_pair(1,a))&&T.count(make_pair(a,N)))R="POSSIBLE";
		if(T.count(make_pair(1,b))&&T.count(make_pair(b,N)))R="POSSIBLE";
	}
	cout<<R<<endl;
}


Measured memory_bytes: 18944
#include <iostream>
#include <vector>
#include <chrono>
#include <random>

std::mt19937 rng((int) std::chrono::steady_clock::now().time_since_epoch().count());

int main() {
	std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
	int n;
	std::string str;
	std::cin >> n >> str;
	int open = 0;
	int ans = 1;
	const int MOD = 1e9 + 7;
	for(int i = 1; i <= n; i++) {
		ans = (long long) ans * i % MOD;
	}
	for(auto c : str) {
		int v = c == 'B' ? 1 : 0;
		if((v+open)%2 == 1) {
			//std::cout << "first case\n";
			open++;
		} else if(open > 0) {
			//std::cout << "second case\n";
			ans = (long long) ans * open % MOD;
			open--;
		} else {
			ans = 0;
		}
	}
	if(open != 0) {
		ans = 0;
	}
	std::cout << ans << std::endl;
}

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

#define f(x, y, z) for (int x = (y), __ = (z); x < __; ++x)
#define _rep(i, a, b) for (int i = (a); i <= (b); ++i)

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9 + 7;

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

int main() {
  int N;
  scanf("%d", &N);
  vector<vector<int>> a(N);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int v;
      scanf("%d", &v);
      if (v == 1) a[i].push_back(j);
    }
  }

  int size = 1 << N;
  vector<int> dp(size);
  dp[size - 1] = 1;
  for (int mask = size - 2; mask >= 0; mask--) {
    int x = __builtin_popcount(mask);
    int ans = 0;
    for (int j : a[x]) {
      if ((mask & (1 << j)) == 0) {
        ans = (ans + dp[mask | (1 << j)]) % MOD;
      }
    }
    dp[mask] = ans;
  }

  printf("%d\n", dp[0]);
}


Measured memory_bytes: 8448
#include <stdlib.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll=long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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;
}
const long long INF=1LL << 60;
long long a,b;
long long dp[100200][110];
long long w[110],v[110];


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    bool flag=false;
    for(int i=b;i<=c;i++){
        if(i%a==0){
            flag=true;
        }
    }
    if(flag){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
}



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

int main(){
  int a,b;
  cin>>a>>b;
  string g=to_string(a);
  string h=to_string(b);
  string M;
  string N;
  for(int i=0;i<b;i++){
    M+=g;
  }
  for(int j=0;j<a;j++){
    N+=h;
  }
  vector<string>gun(2);
  gun.at(0)=M;
  gun.at(1)=N;
  sort(gun.begin(),gun.end());
  cout<<gun.at(0)<<endl;
}


Measured memory_bytes: 256
main=interact$f.map read.words
f[n,x]=if x<2 || m<=x then "No" else unlines$"Yes":map show(a++[x-1..x+1]++b) where
  m=2*n-1
  (a,b)=splitAt((m-3)`div`2)$[1..x-2]++[x+2..m]

Measured memory_bytes: 3708
N,M=map(int,input().split())
AB=[[0,0] for _ in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=map(int,input().split())
AB.sort(key=lambda x:x[0])
ans=0
drink_num=0
for i in range(N):
    if (AB[i][1]+drink_num)>=M:
        ans+=(M-drink_num)*AB[i][0]
        drink_num=M
    else:
        ans+=AB[i][1]*AB[i][0]
        drink_num+=AB[i][1]
    if drink_num==M:
        break
print(ans)

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

int main() {
    int x;
    cin >> x;
    if (x < 1200){
        cout << "ABC" << endl;
    }
    else{
        cout << "ARC" << endl;
    }
}


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

#define rep(i,begin,end) for(int i=begin;i<=end;i++)
#define repi(i,end,begin) for(int i=end;i>=begin;i--)
#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;

#define MAXN 100001

int n;
int h[MAXN], dp[MAXN];

int sol(int pos){
	if(dp[pos] != -1) return dp[pos];

	if(pos == 1) return dp[pos] = 0;
	if(pos == 2) return dp[pos] = abs(h[pos] - h[pos-1]);

	return dp[pos] = min(sol(pos-1) + abs(h[pos] - h[pos-1]), sol(pos-2) + abs(h[pos] - h[pos-2]));
}

int main(){
fio

cin >> n;

memset(dp,-1,sizeof(dp));

rep(i,1,n) cin >> h[i];

cout << sol(n) << endl;

return 0;
}

Measured memory_bytes: 2560
/* Highway Toll */
import java.io.*;

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public static int[][] table = new int[][]{
		{  0, 300, 500, 600, 700, 1350, 1650},
		{  6,   0, 350, 450, 600, 1150, 1500},
		{ 13,   7,   0, 250, 400, 1000, 1350},
		{ 18,  12,   5,   0, 250,  850, 1300},
		{ 23,  17,  10,   5,   0,  600, 1150},
		{ 43,  37,  30,  25,  20,    0,  500},
		{ 58,  52,  45,  40,  35,   15,    0}
	};
	
	public final int start = 17*60 + 30;
	public final int end   = 19*60 + 30;
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] tmp;
		
		while( true ){
			line = in.readLine();
			int entra = Integer.parseInt(line);
			if(entra==0) break;
			line = in.readLine();
			tmp = line.split(" ");
			int h = Integer.parseInt(tmp[0]);
			int m = Integer.parseInt(tmp[1]);
			int en_time = h*60 + m;
			
			line = in.readLine();
			int extra = Integer.parseInt(line);
			line = in.readLine();
			tmp = line.split(" ");
			h = Integer.parseInt(tmp[0]);
			m = Integer.parseInt(tmp[1]);
			int ex_time = h*60 + m;
			
			int a, b;
			if(entra > extra){
				a = entra-1;
				b = extra-1;
			}
			else{
				a = extra-1;
				b = entra-1;
			}
			
			int dist = table[a][b];
			int fee  = table[b][a];
			
			if(((en_time>=start && en_time <=end) || (ex_time>=start && ex_time<=end)) && dist <= 40){
				fee /= 2;
			}
			
			if(fee%50 != 0){
				fee = 50 * (fee/50 + 1);
			}
			
			System.out.println(fee);
		}
	}
}

Measured memory_bytes: 9752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int N,K;
vector<int> V;
//num個取るときの最大値
ll solve(int num){
    //cout << ":" << num << endl;
    ll maxi = 0;
    rep(i,0,num+1){
        //cout << i << endl;
        priority_queue<int,vector<int>, greater<int>> que;
        //cout << "hoge" << endl;
        rep(j,0,i){
            //cout << j << endl;
            //cout << V[j] << " \n"[j==i-1];
            que.push(V[j]);
        }
        rep(j,0,num-i){
            //cout << N-i-j << endl;
            //cout << V[N-1-j] << " \n"[j==num-i-1];
            que.push(V[N-1-j]);
        }
        ll sum = 0;
        rep(j,0,K-num){
            if(que.size() && que.top() < 0){
                que.pop();
            }
        }
        while(!que.empty()){
            sum += que.top();
            que.pop();
        }
        //cout << sum << endl << endl;
        maxi = max(maxi, sum);
    }
    return maxi;
}
main(){
    cin >> N >> K;
    V.resize(N);
    rep(i,0,N)cin >> V[i];
    ll maxi = 0;
    rep(i,0,K+1){
        maxi = max(maxi, solve(min(i, N)) );
        //cout << solve(min(i, N)) << endl;
    }
    cout << maxi << endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}

main :: IO ()
main = do
  n <- readLn
  k <- readLn
  print $ solve n k

solve :: Int -> Int -> Int
solve n k = foldr operate 1 [1 .. n] where
  operate _ x = min (x * 2) (x + k)


Measured memory_bytes: 508
using System;

namespace abc101_a
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int ret = 0;
            for (int i = 0; i < 4; i++) ret += s[i] == '+' ? 1 : -1;
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 11092
S=input()
N=len(S)
i=1
X=[S[0]]
while(i<N):
    if i==N-2 and S[i]==S[i+1]:
        X.append(S[i]+S[i+1])
        i+=2
    elif S[i]==X[-1]:
        X.append(S[i]+S[i+1])
        i+=2
    else:
        X.append(S[i])
        i+=1
print(len(X))


Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s,t;
	int a,b;
	cin>>s>>t;
	cin>>a>>b;
	string h;
	cin>>h;
	if(h==s&&a>0)
	a--;
	else if(h==t&&b>0)
	b--;
	cout<<a<<" "<<b;
} 

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

int main() {
  long long A,B;
  cin>>A>>B;
  int K;
  cin>>K;
  long long Q=A;
  long long P=B;
  if(A+K-1>=B-K+1){
    for(long long i=0;i<B-A+1;i++){
      cout<<Q<< endl;
      Q++;
    }
    return 0;
  }
  for(long long i=0;i<K;i++){
    cout<<Q<< endl;
    Q++;
  }
  for(long long i=0;i<K;i++){
    cout<<B-K+1<< endl;
    B++;
  }
}
  
  

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

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

const int INF = 1e9;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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


int main(void){
  ios::sync_with_stdio(false);

  string S;
  cin >> S;
  int N = S.size() + 1;
  vector<ll> a(N);

  for(int i = N-2; i>=0; --i){
    if (S[i] == '>'){
      a[i] = a[i+1] + 1;
    }
  }

  REP(i, N-1){
    if (S[i] == '<'){
      a[i+1] = max(a[i]+1, a[i+1]);
    }
  }

  ll ans = 0;
  REP(i, N){ans += a[i];}

 
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 4764
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;

import javax.swing.JTabbedPane;
public class Main{
	static class FastScanner{//用于快速读入大量数据
		BufferedReader br;
		StringTokenizer st;
		public FastScanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(in),16384);
			eat("");
		}
		public void eat(String s) {
			st = new StringTokenizer(s);
		}
		public String nextLine() {
			try {
				return br.readLine();
			} catch (IOException e) {
				return null;
			}
		}
		public boolean hasNext() {
			while(!st.hasMoreTokens()) {
				String s = nextLine();
				if(s==null) return false;
				eat(s);
			}
			return true;
		}
		public String next() {
			hasNext();
			return st.nextToken();
		}
	    
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
	static FastScanner cin = new FastScanner(System.in);//快读
	static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));//快速输出
    static int mod=1000000007;

   


   static  String str;
    public static void main(String[] args) {
       int n;
       n=cin.nextInt();
       str=cin.next();
       int len=str.length();
       int ans=0;
       Queue<Integer>vec=new LinkedList<Integer>();
       for(int i=len-1;i>=0;i--) {
    	   if(str.charAt(i)=='R') {
    		   vec.add(i);
    	   }
       } 
       int cc=0;
       for(int i=0;i<len;i++) {
    	   if(str.charAt(i)=='W') {
    		   if(!vec.isEmpty()&&vec.peek()>i) {
    			   vec.poll();
    			   ans++;
    		   }
    	   }
       }
       out.println(ans);
       out.flush();
       return ;
	}
 
}


Measured memory_bytes: 44548
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e6;
const double PI = acos(-1.0);
#define Test ll tesnum;tesnum = read();while(tesnum--)
ll read();
ll a[N];
int main()
{
    int n;
    cin>>n;
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        cin>>a[i];
        ans^=a[i];
    }
    for(int i = 1; i <= n; i++){
        cout<<(ans^a[i])<<" ";
    }cout<<endl;
    return "BT7274", NULL;
}

inline ll read() {
    ll hcy = 0, dia = 1;char boluo = getchar();
    while (!isdigit(boluo)) {if (boluo == '-')dia = -1;boluo = getchar();}
    while (isdigit(boluo)) {hcy = hcy * 10 + boluo - '0';boluo = getchar();}
    return hcy * dia;
}

Measured memory_bytes: 5080
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> orderedMultiset;
int solve()
{
	int n,d;
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}




Measured memory_bytes: 3648
q=int(input())
for i in range(q):
    L=input().split( )
    x0=int(L[0])
    y0=int(L[1])
    x1=int(L[2])
    y1=int(L[3])
    x2=int(L[4])
    y2=int(L[5])
    x3=int(L[6])
    y3=int(L[7])
    vx1=x0-x1
    vy1=y0-y1
    vx2=x2-x3
    vy2=y2-y3
    if vx1*vy2-vx2*vy1==0:
        print(2)
    elif vx1*vx2+vy1*vy2==0:
        print(1)
    else:
        print(0)



Measured memory_bytes: 5616
import java.util.*;
public class Main {

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

}



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

using namespace std;
#define INF (1<<28)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

vector<int> g[8];
vector<pair<int,int> > outa;
int vr;
void makeg(int n){
    int a[7]={128,64,32,16,8,4,2};
    int num=1;
    lp(i,7){
      int x=0;
      lp(j,num){
        for(int k=x;k<a[i]+x;k++){
          g[i].push_back(k+1);
        }
        if(i!=0)x+=a[i-1];
      }
      num*=2;
    }
  lp(i,7){
    if(n<a[i]){
      vr=i+1;
      continue;
    }
    lp(j,g[i].size()){
      if(g[i][j]>n) break;
      outa.push_back(make_pair(i+1,g[i][j]));
    }
  }
    return;
}

void outp(int n){
  if(n<=10){
    cout<<0<<endl;
    return;
  } 
  cout<<outa.size()<<endl;
  lp(i,outa.size()){
    cout<<outa[i].first<<" "<<outa[i].second<<endl;
  }

  //if(outa.size()>n*(n-1)/2)cout<<"error!"<<endl;
}

signed main(){
  int n,k;
  cin>>n>>k;
  makeg(n);
  /*lp(i,7) cout<<g[i].size()<<endl;
  return 0;*/
  outp(n);
  lp(zzz,k){
    if(n<=10){
      lp(i,11){
        if(i==0) continue;
        cout<<i<<endl;
        string s;
        cin>>s;
        if(s=="Yes") break;
      }
      continue;
    }
    int ans=1;
    int add=128;
    int st=0;
    lp(i,8){
      if(i==0) continue;
      cout<<i<<endl;
      string s;
      cin>>s;
      if(s=="Yes"){
        st=1;
        break;
      }
      if(s=="No"&&vr<i){
        ans+=add;
      }
      add/=2;
    }
    if(st==1) continue;
    while(1){
      cout<<ans<<endl;
      string s;
      cin>>s;
      if(s=="Yes") break;
      else ans++;
    }
  }
  return 0;
}


Measured memory_bytes: 3340
local l, r = io.read("*n", "*n")
if 2020 < r - l then
  print(0)
else
  local ret = 2018
  local mmi = math.min
  for i = l, r - 1 do
    for j = i + 1, r do
      ret = mmi(ret, (i * j) % 2019)
    end
  end
  print(ret)
end


Measured memory_bytes: 2696
#include <iostream>
#include <string>
#include <regex>

int main (void){
  std::string S; std::cin >> S;

  if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
  else std::cout << "NO" << std::endl;

  return 0;
}

Measured memory_bytes: 39808
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pii pair<int, int>
#define pll pair<long long , long long>
#define pb push_back
#define ll long long
#define ld long double
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
ll power(ll x,ll y,ll m){ll r=1;for(;y;y>>=1){if(y&1)r=r*x%m;x=x*x%m;}return r;}
const ll mod = 1e9 + 7;
const ld pi = 3.14159265358979;
    
int run_test(){
      int a, b, c;
      cin >> a >> b >> c;
      if(a == b && b!=c){
            cout << "Yes\n";
            return 0;
      }
      if(b == c && c != a){
            cout << "Yes\n";
            return 0;
      }
      if(c == a && a != b){
            cout << "Yes\n";
            return 0;
      }
      cout << "No\n";
      return 0;
}
    
int main(){
   FAST;
    ll t;
    t = 1;
     
    while(t--){
        run_test();
    }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B;
	cin >> A >> B;



	co((A * 3 + B) / 2);

	Would you please return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  
  vector<string> A(N), B(M);
  for (int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  for (int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  
  for (int i = 0; i <= N - M; i++){
    for (int j = 0; j <= N - M; j++){
      int test = 0;
      while (A.at(i + test).substr(j, M) == B.at(test)){
        test++;
        if (test == M){
          cout << "Yes" << endl;
          exit(0);
        }
      }
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
ll dp1[1000005];
ll dp2[1000005];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(ll i = 1; i <= 1000000; i++) {
        dp1[i] = INF;
        dp2[i] = INF;
    }
    ll tmp = 0;
    while(true) {
        tmp++;
        ll now = tmp * (tmp + 1) * (tmp + 2) / 6;
        //cerr << tmp << " " << now << endl;
        if(now > 1000000) break;
        for(ll after = now; after <= 1000000; after++) {
            dp1[after] = min(dp1[after], dp1[after-now] + 1);
        }
        if(now % 2 == 0) continue;
        for(ll after = now; after <= 1000000; after++) {
            dp2[after] = min(dp2[after], dp2[after-now] + 1);
        }
    }
        while(true) {
            int n;
            cin >> n;
            if(n == 0) break;
            cout << dp1[n] << " " << dp2[n] << endl;
        }
    return 0;
}


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


int main() {
	
	string s;
	cin >> s;
	set<char> g;
	for(auto i : s) g.insert(i);
	if (g.size()==s.length()) cout << "yes" << endl;
	else cout << "no" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::string;

int main(int argc, char* argv[]) {
  int n, k, q;
  cin >> n >> k >> q;

  std::vector<int> a(q);
  for (int i = 0; i < q; ++i) {
    cin >> a[i];
  }

  std::vector<int> offset(n, -q);
  for (int i = 0; i < q; ++i) {
    ++offset[a[i] - 1];
  }

  for (int i = 0; i < n; ++i) {
    cout << ((k + offset[i] > 0) ? "Yes" : "No") << std::endl;
  }

  return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<iostream>
#include<map>
using namespace std;
map<int,int> flag;
int main()
{
	int m,n,x;
	scanf("%d",&m);
	for(int i=0;i<m;++i)
	{
		scanf("%d",&x);
		if(flag.count(x)) ++flag[x];
		else flag.insert(pair<int,int>(x,1));
	}
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	{
		scanf("%d",&x);
		if(flag.count(x))
		{
			if(flag[x]==0) {printf("NO");return 0;}
			--flag[x];
		}
		else {printf("NO");return 0;}
	}
	printf("YES");
	return 0;
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
    int N;
    long T;
    scanf("%d%ld",&N,&T);

    //A[0]~A[N-1]に格納する
    long* A;
    NEW(A,N);
    for(int i=0;i<N;i++){
        scanf("%ld",&A[i]);
    }

    long* min;
    NEW(min,N);
    min[0]=A[0];
    for(int i=1;i<N;i++){
        if(A[i]<min[i-1]) min[i]=A[i];
        else min[i]=min[i-1];
    }

    long B=A[0]-min[0];
    for(int i=1;i<N;i++) B=MAX(B,A[i]-min[i]);

    int ans=0;
    for(int i=0;i<N;i++){
        if(A[i]-min[i]==B) ans++;
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen(".in.txt", "r", stdin);
	freopen(".out.txt", "w", stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n; cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	ll ans = a[n - 1];
	n -= 2;
	for(int i = n; n; i--)
	{
		ans += a[i] + (n > 1) * a[i];
		n = max(n - 2, 0);
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 4720
import Data.List
import Data.Maybe
import Control.Monad
import qualified Data.ByteString.Char8 as C

readInt' = fst.fromJust.C.readInt
readLnInt = map readInt'.C.words<$>C.getLine
readCsInt n = concat<$>replicateM n readLnInt

x ? (a,b) = if x then a else b
half = flip div 2
aliq = ((0==).).mod

main = do
 [n] <- readLnInt
 inputs <- replicateM 3 readLnInt
 print $ solve inputs

solve [a,b,c] = sum(b ++ [c!!ix|ix <- pick a])

pick (a:b:x)
 | a == b-1 = [a-1] ++ (null x)?([],pick(b:x))
 | otherwise = (null x)?([],pick(b:x))


Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;
/*--------------------------------------------*/

int main(){
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a,b,c;
    cin >> a >> b >> c;

    if(c - a - b < 0){
        cout << "No" << endl;
        return 0;
    }

    cout << (4 * a * b < (c-a-b) * (c-a-b)?"Yes":"No") << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		// 文字列の入力
		if((a + b) % 3 != 0){
			System.out.println(0);
		}else if(a > b * 2 || b > a * 2){
        	System.out.println(0);
        }
      else{
			int c = ((a + b) / 3 - (a - b)) / 2;
			int d = ((a + b) / 3 + (a - b)) / 2;
			int MAX = c + d + 1;
          long e;
int MOD = 1000000007;

long[] fac = new long[MAX];
long[] finv = new long[MAX];
long[] inv = new long[MAX];;


    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

// 二項係数計算
    e = fac[c + d] * (finv[c] * finv[d] % MOD) % MOD;


System.out.println(e);
		}
		
		
		
	}
}

Measured memory_bytes: 57976