akhauriyash/Code-Regression huggingface dataset:
/* be name khoda */

// #define stream_enable
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 200010;

ll n, k;
ll S[maxn];

void MAIN() {

    cin >> n >> k;
    fori (i, n) {
        char c; cin >> c;
        S[i] = c == 'A';
    }
    ll I = 0, R = 0;
    fori (i, min(k, n * 2)) {
        if (S[R] ^ I) S[R] ^= 1;
        else I ^= 1, R = (R + 1) % n;
    }
    if (k > n * 2 && n % 2) S[R] ^= k & 1;
    fori (i, n) cout << ((S[(i + R) % n] ^ I) ? 'A' : 'B');
    cout << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(
5 2
ABAAA
    )";
    MAIN();
    return 0;
}


Measured memory_bytes: 1280
def get_str_from_org
    gets.chomp
end

def get_num_from_arg
    get_str_from_org.to_i
end

blue = {}
red = {}

get_num_from_arg.times do 
    s = get_str_from_org
    if blue.include?(s) then
        blue[s] += 1
    else
        blue[s] = 1
    end
end

get_num_from_arg.times do
    s = get_str_from_org
    if red.include?(s) then
        red[s] += 1
    else
        red[s] = 1
    end
end

ans = 0
blue.each do |k,v|
    v -= red[k] if red.include?(k)
    ans = v if v > ans
end

puts ans

Measured memory_bytes: 3836
import sys
sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

H,W = map(int,input().split(' '))
MAP = [None]*H
for i in range(H):
    MAP[i] = list(input())

ANS = 0

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

import queue
q = queue.Queue()

for i in range(H):
    for j in range(W):
        st = MAP[i][j]
        if st=='#': continue
        dist = [[0]*W for i in range(H)]
        visited = [[0]*W for i in range(H)]
        visited[i][j] = 1
        q.put([i,j])
        while not q.empty():
            y,x = q.get()
            for dy,dx in dxy:
                ny,nx = y+dy,x+dx
                if not (0<=nx<W): continue
                if not (0<=ny<H): continue
                if visited[ny][nx]: continue
                if MAP[ny][nx] == '#': continue
                visited[ny][nx] = 1
                dist[ny][nx] = dist[y][x] + 1
                q.put([ny,nx])
        ANS = max(ANS, max(max(row) for row in dist))
print(ANS)

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

ll a[100010], b[100010];

int main() {
    int n;
    cin >> n;
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if (i+1 == a[i]) {
            b[i] = 1;
        }
    }

    ll a1=0, a2=0;
    rep(i, n-1) {
        if (b[i] and b[i] == b[i+1]) a2++;
        else if (b[i] > 0) {
            if (a2>0) { a2++; a1 += (a2/2)+bool(a2%2); }
            else a1++;
            a2 = 0;
        }
    }

    if (b[n-1] > 0) {
        if (a2>0){ a2++; a1 += (a2/2)+bool(a2%2); }
        else a1++;
    }

    cout << a1 << endl;

}


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

int main(void){
  while(1){
    int stone[50];
    for(int k = 0 ; k < 50 ; k++){stone[k] = 0;}

    int bowl;
    int n, p;  // n：候補者人数，p：小石の総数
    cin >> n;
    cin >> p;

    if(n == 0 && p == 0){return 0;}

    bowl = p;

    bool flg = true;
    int ans;

    for(int i = 0 ; flg ; i = (i+1) % n){

      if(bowl == 0){
        bowl = bowl + stone[i];
        stone[i] = 0;
      }else{
        stone[i]++;
        bowl--;
        if(bowl == 0 && stone[i] == p){ans = i; flg = false;}
      }
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 3024
isp = [True for _ in range(10005)]
isp[0] = isp[1] = False
for p in range(10005):
    if not isp[p]:
        continue
    for i in range(2, 10000):
        if p * i > 10000:
            break
        isp[p*i] = False
primes = list(filter(lambda x: isp[x], range(10000)))
# print(primes)
_, *N = map(int, open(0).read().split())
ans = 0
for n in N:
    if n > 10000:
        ans += 1
        for p in primes:
            if n % p == 0:
                ans -= 1
                break
    else:
        ans += isp[n]
print(ans) 


Measured memory_bytes: 6712
#include<stdio.h>
int main(void){
  int A;
  int B;
  scanf("%d",&A);
  scanf("%d",&B);
  if(A>=13){
    printf("%d",B);
  }
  if((A<=12)&&(6<=A)){
    printf("%d",B/2);
  }
  if(A<=5){
    printf("%d",0);
  }
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
  vector<int> a(4),b(4);
  while(cin>>a[0]>>a[1]>>a[2]>>a[3]
           >>b[0]>>b[1]>>b[2]>>b[3]){
    int hit=0,blow=0;
    for(int i=0;i<4;i++){
      if(a[i]==b[i]){
        hit++;
        a[i]=b[i]=0;
      }
    }
    for(int i=0;i<4;i++){
      for(int j=0;j<4;j++){
        if(a[i]==0)continue;
        if(a[i]==b[j]){
          blow++;
          break;
        }
      }
    }
    cout<<hit<<" "<<blow<<endl;
  }

}

Measured memory_bytes: 1192
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int N,co[100002]={},maxi=0;

int main(){
    cin>>N;
    int a[N];
    rep(i,N){
        cin>>a[i];
        co[a[i]]+=1;
        co[a[i]+1]+=1;
        co[a[i]+2]+=1;
    }
    rep(i,100002){
        maxi=max(maxi,co[i]);
    }
    out(maxi);
}

Measured memory_bytes: 1024
//
//  main.c
//  ProgrammingContest_C
//
//  Created by ?????? ?????? on 2016/01/03.
//  Copyright ?? 2016??´ Jiiko corp. All rights reserved.
//

#include <stdio.h>


int gcd(int x, int y){
    int tmp;
    
    if(y == 0) return x;
    
    if(x < y){
        tmp = y;
        y = x;
        x = tmp;
    }
    
    return gcd(y, x%y);
    
}


int main(int argc, const char * argv[]) {
    //Input
    int a,b;
    
    scanf("%d", &a);
    scanf("%d", &b);
    
    printf("%d\n", gcd(a,b));
    
    return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
#define f(i,a,b) for(ll i=a;i<b;i++)
 

int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
ll n,m;
cin>>n>>m;
ll a[n+1];
ll sum=0;
for(int i=0;i<n;i++){
cin>>a[i];
sum+=a[i];}
float d=1;
float b=4*m;
float c=d/b;
ll cnt=0;
float ans=(float)sum*c;
for(int i=0;i<n;i++){
	if(a[i]>=ans)
	cnt++;
	
}
if(cnt>=m)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

}


Measured memory_bytes: 256
S = input()
F = int(S[:2])
B = int(S[2:])

if 1 <= F <= 12:
    if 1 <= B <= 12:
        ans = "AMBIGUOUS"
    else:
        ans = "MMYY"
else:
    if 1 <= B <= 12:
        ans = "YYMM"
    else:
        ans = "NA"
        
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};

signed main() {
  int n;cin>>n;
  int dp[100001];
  dp[0] = 0;
  repd(i,1,n+1){
    dp[i] = dp[i-1]+1;
    int a = 6;
    while(a <= i){
      dp[i] = min(dp[i], dp[i-a] + 1);
      a *= 6;
    }
    a = 9;
    while(a <= i){
      dp[i] = min(dp[i], dp[i-a]+1);
      a *= 9;
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 640
import heapq

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

ab = []

for i in range(n):
    a, b = list(map(int, input().split()))
    ab.append([a, b])

ab.sort()

d = 1

w = []
heapq.heapify(w)

p = 0
d = 1
i = 0
while d <= m:
    while i < n and ab[i][0] == d:
        a, b = ab[i]
        heapq.heappush(w, -b)
        i += 1
    #print(w)
        #d日前にやる仕事をきめる
    if len(w) > 0:
        p -= heapq.heappop(w)

    d += 1


print(p)


Measured memory_bytes: 92752
#include<iostream>
using namespace std;
int main(){
    long long x,ans;
    cin >> x;
    ans = x / 11LL * 2LL + (x % 11LL > 6LL ? 2LL : (x % 11LL == 0 ? 0 : 1LL));
    cout << ans << endl;
}

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

bool v[200];

int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;++i){
        int d;
        cin>>d;
        for(int j=0;j<d;++j){
            int a;
            cin>>a;
            v[a-1]=1;
        }
    }
    int ans=0;
    for(int i=0;i<n;++i){
        if(v[i]==0)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define here(x) cout << #x << " = " << x << endl;
#define show(x) {for( auto i : x) cout << i << '\t'; cout << endl;}
#define shop(n, x) {for(int i = 0; i < n; i++) cout << x << setw(4); cout << endl;}
#define ff first
#define ss second
#define endl '\n'
#define en " "
#define pb push_back
#define mpair make_pair
ll mod = 1000000007;
ll inf = LLONG_MAX;
long double pi = 3.1415926536;
ll len[100010], vis[100010];
ll dfs(ll node, ll par, vector < ll > v[])
{
	vis[node] = 1;
	ll m = 0, sub = 0;
	for(auto ch : v[node])
	{
		if(ch == par)	continue;
		if(vis[ch] == 0)
			sub = dfs(ch, node, v);

		else if(vis[ch] == 1)
			return mod + 2;

		else if(vis[ch] == 2)
			sub = len[ch];

		m = max(m, sub);
	}
	vis[node] = 2;

	return len[node] = m + 1;
}
int main()
{
	fastio();
	int tt = 1;
	//cin >> tt;
	while(tt--)
	{
		// 		j NOT i 		check		//		CHECK -> if()   else if()
		ll n, x = 0, m = 0, y = 0, k = inf;
		cin >> n >> m;
		vector < ll > v[n + 1];
		for(ll i = 0; i < m; i++)
		{
			cin >> x >> y;
			v[x].pb(y);
		}
		ll f = 1;
		m = 1;

		for(ll i = 0; i < n; i++)
		{
			if(vis[i + 1])	continue;

			x = dfs(i + 1, 0, v);
			if(x >= mod)
				f = 0;
			else
				m = max(x, m);
		}
		if(f)
			cout << m - 1 << endl;
		else
			cout << -1 << endl;
	}
}

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

int H, W;
int board[501][501];
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

int opcnt = 0;
int operation[260000][4];


void nextorder(int i, int j, int * ni, int * nj){
    if(i % 2 == 0){
        if(1 < j){
            *ni = i;
            *nj = j-1;
            return;
        }else{
            *ni = i+1;
            *nj = j;
            if(*ni > H) {*ni = 0; *nj = 0;}
            return;
        }
    }else{
        if (j < W){
            *ni = i;
            *nj = j+1;
            return;
        }else{
            *ni = i+1;
            *nj = j;
            if(*ni > H) { *ni = 0; *nj = 0;}
            return;
        }
    }
}
int main(void){
    scanf("%d %d",&H,&W);
    
    int tmp;
    int start_i = 0, start_j = 0;;
    
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            scanf("%d",&tmp);
            board[i][j] = tmp;
        }
    }

    

    int i = 1;
    int j = 1;

    int ni,nj;
    nextorder(i,j,&ni,&nj);
    //printf("%d %d\n",ni,nj);
    while(ni != 0 & nj != 0){
        //printf("board[%d][%d]=%d,board[%d][%d]=%d\n",i,j,board[i][j],ni,nj,board[ni][nj]);
        if(board[i][j]%2 == 1){
            operation[opcnt][0]=i;
            operation[opcnt][1]=j;
            operation[opcnt][2]=ni;
            operation[opcnt][3]=nj;
            opcnt++;
        }
        board[ni][nj] += board[i][j]%2;
        //board[i][j] -= board[i][j]%2;
        //printf("board[%d][%d]=%d\n",ni,nj,board[ni][nj]);
        i = ni;
        j = nj;
        nextorder(i,j,&ni,&nj);
        //printf("%d %d\n",ni,nj);
    }
    
    printf("%d\n",opcnt);
    for(int o = 0; o < opcnt; o++){
        printf("%d %d %d %d\n",operation[o][0],
                               operation[o][1],
                               operation[o][2],
                               operation[o][3]);
    }
}


Measured memory_bytes: 7040
import sys
class Lazysegtree:
    #RAQ
    def __init__(self, A, intv, initialize = True, segf = min):
        #区間は 1-indexed で管理
        self.N = len(A)
        self.N0 = 2**(self.N-1).bit_length()
        self.intv = intv
        self.segf = segf
        self.lazy = [0]*(2*self.N0)
        if initialize:
            self.data = [intv]*self.N0 + A + [intv]*(self.N0 - self.N)
            for i in range(self.N0-1, 0, -1):
                self.data[i] = self.segf(self.data[2*i], self.data[2*i+1]) 
        else:
            self.data = [intv]*(2*self.N0)

    def _ascend(self, k):
        k = k >> 1
        c = k.bit_length()
        for j in range(c):
            idx = k >> j
            self.data[idx] = self.segf(self.data[2*idx], self.data[2*idx+1]) \
            + self.lazy[idx]
            
    def _descend(self, k):
        k = k >> 1
        idx = 1
        c = k.bit_length()
        for j in range(1, c+1):
            idx = k >> (c - j)
            ax = self.lazy[idx]
            if not ax:
                continue
            self.lazy[idx] = 0
            self.data[2*idx] += ax
            self.data[2*idx+1] += ax
            self.lazy[2*idx] += ax
            self.lazy[2*idx+1] += ax
    
    def update(self, k, x):
        k = k + self.N0
        self.data[k] = x
        self._ascend(k)
    
    def query(self, l, r):
        L = l+self.N0
        R = r+self.N0
        Li = L//(L & -L)
        Ri = R//(R & -R)
        self._descend(Li)
        self._descend(Ri - 1)
        
        s = self.intv                                                              
        while L < R:
            if R & 1:
                R -= 1
                s = self.segf(s, self.data[R])
            if L & 1:
                s = self.segf(s, self.data[L])
                L += 1
            L >>= 1
            R >>= 1
        return s
    
    def add(self, l, r, x):
        L = l+self.N0
        R = r+self.N0

        Li = L//(L & -L)
        Ri = R//(R & -R)
        
        while L < R :
            if R & 1:
                R -= 1
                self.data[R] += x
                self.lazy[R] += x
            if L & 1:
                self.data[L] += x
                self.lazy[L] += x
                L += 1
            L >>= 1
            R >>= 1
        
        self._ascend(Li)
        self._ascend(Ri-1)
N, M = map(int, input().split())
LA = [[] for _ in range(N)]
for _ in range(M):
    l, r, a = map(int, sys.stdin.readline().split())
    LA[r-1].append((l-1, a))

dp = Lazysegtree([0]*(N+1), -10**16, True, max)

for i in range(N):
    res = 0
    t = dp.data[1]
    for l, a in LA[i]:
        res += a
        dp.add(l, i, a)
    dp.add(i,i+1, res + t)
print(dp.data[1])


Measured memory_bytes: 108372
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;
list<long long int> Prime(int M) {
	list<long long int>P;
	P.push_back(2);
	P.push_back(3);
	for (int i = 5; i <= M; i += 6) {
		bool flag = true;
		for (auto j : P) {
			if (i%j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i);
		flag = true;
		for (auto j : P) {
			if ((i + 2) % j == 0) {
				flag = false;
				break;
			}
		}
		if (flag)P.push_back(i + 2);
	}
	return P;
}

long long int N, M, K, Q, W, H;
long long int ans;


int main() {
	ios::sync_with_stdio(false);
	int num[3];
	cin >> num[0] >> num[1] >> num[2];
	sort(num, num + 3);
	if (num[0] == 5 && num[1] == 5 && num[2] == 7)cout << "YES\n";
	else cout << "NO\n";
	return 0;
}

Measured memory_bytes: 256
# ABC052D - Walk and Teleport (ARC067D)
def main():
    N, A, B = tuple(map(int, input().split()))
    X = tuple(map(int, input().split()))
    D = [j - i for i, j in zip(X, X[1:])]  # distance
    ans = sum(min(A * d, B) for d in D)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14352
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B, C);

// ===

fn main() {
    let (n, m, x): (usize, usize, usize) = read();
    let mut cost: Vec<i32> = vec![0; n+1];
    let a: Vec<usize> = readnc();
    for p in a {
        cost[p] = 1;
    }
    let mut left = 0;
    let mut right = 0;
    for i in 0..x {
        left += cost[i];
    }
    for i in x+1..n+1 {
        right += cost[i];
    }
    println!("{}", min(left, right));
}


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

int main() {
  string S;
  cin >> S;
  
  int red = 0;
  int blue = 0;
  
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) == '0'){
      red++;
    } else {
      blue++;
    }
  }
    
  cout << 2*min(red,blue) << endl;  
}
    
    

Measured memory_bytes: 512
// プリム法 最小全域木 Minimum Spanning Tree
#include <iostream>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <vector>
using namespace std;
static const int MAX = 100;
static const int INF = (1<<21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

const int nmax = 8;
bool graph[nmax][nmax];

int dfs(int v, int N, bool visited[nmax]) {

    bool all_visited = true;

    for(int i = 0; i < N; i++) {
        if (visited[i] == false) {
            all_visited = false;
        }
    }

    if (all_visited) {
        return 1;
    }

    int ret = 0;

    for(int i = 0; i < N; i++) {
        if (graph[v][i] == false) continue;
        if (visited[i]) continue;

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

int main() {

    int n ,m;
    cin >> n >> m;

    int a, b;
    for(int i = 0; i < m; i++) {
        cin >> a >> b;
        graph[a-1][b-1] = graph[b-1][a-1] = true;
    }

    bool visited[nmax];
    for(int i = 0; i < n; i++) {
        visited[i] = false;
    }

    visited[0] = true;
    cout << dfs(0, n, visited) << endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

A, B =  map(int, sys.stdin.readline().split())
if A <= 8 and B <= 8:
    print("Yay!")
else:
    print(":(")


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

int main(){
  int s;
  cin >>s;
  int num[1001001] = {0};
  num[s]++;
  int M = 0;
  for(int i = 2;;i++){
    if(s%2 == 0) s /= 2;
    else s = 3*s+1;
    if(num[s]) {
      M = i;
      break;
    }
    num[s]++;
  }
  cout << M << endl;
  return 0;
}

Measured memory_bytes: 4096
program main

  implicit none

  integer :: L, R, i, j, ans, ans_tmp
  integer, allocatable, dimension ( : ) :: a

  read ( unit = *, fmt = * ) L, R

  if ( R-L+1 >= 2019 ) then

     print '(i0)', 0

     stop

  end if
  
  allocate ( a ( 1:R-L+1 ) )

  do i = 1, R-L+1
     
     a ( i ) = mod ( L + i - 1, 2019 )

  end do

  ans = 2019
  
  do i = 1, R-L+1

     do j = 1, R-L+1

        if ( i == j ) then

           cycle

        end if

        ans_tmp = mod ( a ( i ) *  a ( j ), 2019 )

        if ( ans_tmp < ans ) ans = ans_tmp

        if ( ans == 0 ) then
           
           print '(i0)', 0

           stop

        end if
        

     end do

  end do

  print '(i0)', ans
  
  
end program main


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
typedef long long ll;
typedef double db;
const int MX=200000;
ll T[4*MX+50];
ll a[MX+5],b[MX+5];
void UP(int p, int l, int h, int x, ll v)
{
    if(l==h)
    {
        T[p]=v;
        return;
    }
    int m=(l+h)/2;
    if(x<=m)UP(2*p,l,m,x,v);
    else UP(2*p+1,m+1,h,x,v);
    T[p]=max(T[2*p],T[2*p+1]);
}
ll Q(int p, int l, int h, int x, int y)
{
    if(l>y||h<x)return 0;
    if(l>=x&&h<=y)return T[p];
    int m=(l+h)/2;
    return max(Q(2*p,l,m,x,y),Q(2*p+1,m+1,h,x,y));
}
int main()
{
    FasterIO;
    ll n,x,y;
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    for(int i=1;i<=n;i++)
    {
        x=Q(1,1,n,1,a[i]);
        UP(1,1,n,a[i],x+b[i]);
    }
    cout<<Q(1,1,n,1,n)<<endl;
    return 0;
}


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

int main() {
  string S,T;
  cin >> S >> T;
  int x=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)!=T.at(i)){
      x++;
    }
  }
  cout << x << endl;
}

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

using namespace std;

int rec(int a,int b, int c,int k)
{
	if(k==0)
	return 0;
//	cout<<a<<"  "<<b<<"  "<<c<<"   \n";
	
	if(a<b && b<c)
	return 1;
	
	return rec(  a,2*b,c,k-1  )  +rec(a,b,c*2,k-1) ;
	
	
	
	
	
	
}
int main()
{
	int t;
	t=1;
	while(t--)
	{
		int n;
		
		
		int a,b,c,k;
	
	  cin>>a>>b>>c>>k;
	  
	  
	   if(rec(a,b,c,k+1)) 
	   cout<<"Yes\n";
	   
	   else
	   cout<<"No\n";
	
	
	}



}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222





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


  vll v(3);
  rep(i, 3) cin >> v[i];
  sort(all(v));
  cout << v[0] * v[1] / 2 << endl;



  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

long long fac[510000],finv[510000],inv[510000];
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<510000;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;
  }
}
long long COM(int n,int k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
long long facdiv(lint n,lint k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return (fac[n]*finv[k])%MOD;
}


int main(void){
    COMinit();
    lint N,K;
    cin >> N >> K;
    lint A[N];
    rep(i,N) cin >> A[i];
    sort(A,A+N);
    lint sum[N+1]={};
    rep(i,N) sum[i+1]=sum[i]+A[i];
    lint ans=0;
    int count=0;
    lint minus=0;
    for(int i=N;i>=K;i--){
        lint add=((A[N-1]-A[0])*(count+1)-minus)%MOD;
        minus=minus+(A[count+1]-A[0])+(A[N-1]-A[N-count-2]);
        minus%=MOD;
        add=(add*COM(N-2-count,K-2))%MOD;
        ans=(ans+add)%MOD;
        count++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 13824
import java.util.*

fun main(args: Array<String>) = p56()

fun p56() {
    val (v, e, r) = readLine()!!.split(' ').map { it.toInt() }

    data class Vertex(val index: Int, val neighbor: MutableSet<Pair<Int, Int>> = mutableSetOf())

    val vertexes = Array(v) { Vertex(it) }

    repeat(e) {
        val (s, t, d) = readLine()!!.split(' ').map { it.toInt() }
        vertexes[s].neighbor.add(t to d)
    }

    val queue = PriorityQueue<Pair<Vertex, Long>>(Comparator { o1, o2 -> o1.second.compareTo(o2.second) })
    queue.add(vertexes[r] to 0L)
    val inf = Long.MAX_VALUE / 10
    val distances = LongArray(v) { inf }
    distances[r] = 0

    while (queue.isNotEmpty()) {
        val (vertex, dist) = queue.poll()
        val (index, neighbor) = vertex
        if (dist > distances[index]) continue

        neighbor.forEach { (to, d) ->
            if (d + dist < distances[to]) {
                distances[to] = d + dist
                queue.add(vertexes[to] to d + dist)
            }
        }
    }

    val answer = distances.joinToString(System.lineSeparator()) { if (it != inf) it.toString() else "INF" }

    println(answer)
}



Measured memory_bytes: 224564
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <array>


typedef long long int llint;
const llint LARGE = 1L<<60;
typedef std::array<int, 3> w_edge;
typedef std::pair<int, int> edge;

int main(void){
  int n, m, p;
  std::cin >> n >> m >> p;

  std::vector<w_edge> edges(m);
  for(int i=0; i<m; i++){
    std::cin >> edges[i][0] >> edges[i][1] >> edges[i][2];
    edges[i][0]--;
    edges[i][1]--;
    edges[i][2] = p - edges[i][2];
  }

  std::vector<llint> dists(n, LARGE);
  std::vector<llint> temp_dists(n, LARGE);
  dists[0] = 0;
  temp_dists[0] = 0;

  for(int i=0; i<n; i++){
    for(const auto& elem: edges){
      auto src = elem[0];
      auto dst = elem[1];
      auto weight = elem[2];
      temp_dists[dst] = temp_dists[dst]>dists[src]+weight ? dists[src]+weight : temp_dists[dst];
      //std::cout << dst << " " << temp_dists[dst] << std::endl;
    }
    for(int i=0; i<n; i++){
      dists[i] = temp_dists[i];
    }

    //for(int i=0; i<n; i++){
    //  std::cout << dists[i] << " ";//std::endl;
    //}
    //std::cout << std::endl;
  }
  llint temporal_result = dists[n-1];
  for(int i=0; i<n; i++){
    for(const auto& elem: edges){
      auto src = elem[0];
      auto dst = elem[1];
      auto weight = elem[2];
      temp_dists[dst] = temp_dists[dst]>dists[src]+weight ? dists[src]+weight : temp_dists[dst];
      //std::cout << dst << " " << temp_dists[dst] << std::endl;
    }
    for(int i=0; i<n; i++){
      dists[i] = temp_dists[i];
    }

    //for(int i=0; i<n; i++){
    //  std::cout << dists[i] << " ";//std::endl;
    //}
    //std::cout << std::endl;
  }
  
  if(temporal_result != dists[n-1]){
    std::cout << -1 << std::endl;
  }else{
    std::cout << (temporal_result > 0 ? 0 : -temporal_result) << std::endl;
  }
  return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.1415926535
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 3e6;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    set <int> pos;
    for (int i = 0; i < n; ++i)
        if (s[i] == 'o')
            pos.emplace(i);
    map <int, int> early, later;
    {
        int i = *pos.begin();
        for (int j = 0; j < k; ++j)
        {
            early[i] = j;
            i += c + 1;
            if (pos.lower_bound(i) == pos.end())
                break;
            i = *pos.lower_bound(i);
        }
    }
    {
        int i = *pos.rbegin();
        for (int j = 0; j < k; ++j)
        {
            later[i] = k - j - 1;
            i -= c;
            if (pos.lower_bound(i) == pos.begin())
                break;
            i = *(--pos.lower_bound(i));
        }
    }
    for (auto &x : early)
        if (later.count(x.first))
            if (later[x.first] == x.second)
                cout << x.first + 1 << endl;
    return 0;
}




Measured memory_bytes: 36116
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
long long int mod = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
//////////////////////////////////

int main(){
    int a, b; cin >> a >> b;
    cout << max({a+b, a-b, a*b}) << endl;
    
    return 0;
}

// EOF



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

using namespace std;

typedef long long ll;
ll mod = 1000000007, oo = 1000000009;

void Emsawy() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

#define clr(v,d)     memset(v, d, sizeof(v))
#define sz(v)	     ((int)((v).size()))
#define all(v)	     ((v).begin()), ((v).end())
#define allr(v)	     ((v).rbegin()), ((v).rend())
#define V	         vector
#define MP	         make_pair
#define bug(n)           cout<< #n <<" = "<< n << endl;
int dx[] = { 1, -1, 0, 0, 1, -1, 1, -1 };
int dy[] = { 0, 0, 1, -1, 1, -1, -1, 1 };

V<V<int> > adj;
const ll N = 100000 + 5;
int n, m, k, w;

int main() {

	//Emsawy();
	int a, b; 
	while (cin >> a >> b) {
		if (a <= 8 && b <= 8) cout << "Yay!" << endl;
		else cout << ":(" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/perl

my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @a = map { $_ - 0 } split(/\s+/,<STDIN>);

my $res = 'YES';
my %m = ();
foreach my $a (@a){
  if( $m{$a} ){
    $res = 'NO';
    last;
  }
  $m{$a} = 1;
}
print "$res\n";



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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

u64 lcm(u64 a, u64 b) { return (a / gcd(a, b)) * b; }

int main() {
  string S;
  cin >> S;
  for (u32 i = 0; i < S.size(); ++i) {
    cout << 'x';
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, f, n) for (ll i = (f); i < (ll)(n); i++)
#define repe(i, f, n) for (ll i = (f); i <= (ll)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using GraphC = vector<vector<char>>;
using pint = pair<int, int>;

int main() {
  int N;
  cin >> N;
  vector<int> V(N), C(V);
  rep(i, 0, N) cin >> V[i];
  rep(i, 0, N) cin >> C[i];

  int ans = 0;
  rep(bit, 0, 1 << N) {
    int x = 0;
    int y = 0;
    rep(i, 0, N) {
      if (bit >> i & 1) {
        x += V[i];
        y += C[i];
      }
    }

    ans = max(ans, x - y);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
/*
*/

#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <string>
#include <complex>
#include <math.h>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <stdio.h>
#include <stack>
#include <algorithm>
#include <list>
#include <ctime>

#include <memory.h>
#include <assert.h>

#define y0 sdkfaslhagaklsldk

#define y1 aasdfasdfasdf
#define yn askfhwqriuperikldjk
#define j1 assdgsdgasghsf
#define tm sdfjahlfasfh
#define lr asgasgash
#define norm asdfasdgasdgsd
#define have adsgagshdshfhds

#define eps 1e-11
#define M_PI 3.141592653589793
#define bs 1000000007
#define bsize 337

using namespace std;

const int INF = 1e9;
const int N = 500031;

int n, m;
string st;
int l[N], r[N];
int s1[N], s2[N];

int dp[3050][3050];

string solve(string st, int flag)
{
	for (int i = 1; i <=m; i++)
	{
		int a, b;
		a = l[i] - 1;
		b = r[i];
		sort(st.begin() + a, st.begin() + b);
		if (flag)
			reverse(st.begin() + a, st.begin() + b);
	}
	return st;
}

int main(){
	//freopen("tree.in","r",stdin);
	//freopen("tree.out","w",stdout);
	//	freopen("F:/input.txt", "r", stdin);
	//	freopen("F:/output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n >> m;
	cin >> st;
	
	for (int i = 1; i <= m; i++)
	{
		cin >> l[i] >> r[i];
	}

	string st1 = solve(st,0);
	string st2 = solve(st,1);
	
	for (int i = 0; i < st1.size(); i++)
	{
		s1[i + 1] = s1[i] + st1[i] - 48;
		s2[i + 1] = s2[i] + st2[i] - 48;
	}

	//cout << st1 << " " << st2 << endl;
	
	dp[0][0] = 1;
	for (int i = 0; i < st.size(); i++)
	{
		for (int j = 0; j <= i; j++)
		{
			for (int ad = 0; ad <= 1; ad++)
			{
				if (j + ad<s1[i + 1] || j + ad>s2[i + 1])
					continue;
				dp[i + 1][j + ad] += dp[i][j];
				dp[i + 1][j + ad] %= bs;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i <= st.size(); i++)
	{
		ans = ans + dp[st.size()][i];
		ans %= bs;
	}
	cout << ans << endl;

	cin.get(); cin.get();
	return 0;
}

Measured memory_bytes: 12672
A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[int(input())-1])


Measured memory_bytes: 2940
def gcd(a, b)
  a, b = b, a if a < b

  loop do
    r = a%b
    break if r == 0
    a, b = b, r
  end
  return b
end

def lcm(a, b)
  return a*b/gcd(a, b)
end

while gets do
  a, b = $_.split(' ').map(&:to_i)
  puts "#{gcd(a, b)} #{lcm(a, b)}"
end

Measured memory_bytes: 6100
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int array_size = sc.nextInt();

		long[] array = new long[array_size];

		for (int counta = 0; counta < array.length; counta++) {
			array[counta] = sc.nextLong();
		}

		sc.close();

		long min = array[0];
		long max = array[0];
		long sum = 0;

		for (int counta = 0; counta < array.length; counta++) {
			if (min > array[counta]) min = array[counta];
			if (max < array[counta]) max = array[counta];
			sum = sum + array[counta];
		}

		System.out.printf("%d %d %d\n", min, max, sum);
	}

}



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

int main() {
  int n,d,x,a[100];
  cin>>n>>d>>x;
  for (int i(0);i<n;i++) cin>>a[i];
  for (int i(0);i<n;i++){
    int now(1);
    while (now<=d){
      x++;
      now+=a[i];
    }
  }
  cout << x << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+9;
char a[109][109];
int main()
{
    FASTINOUT;
    int r,c;
    cin>>r>>c;
    r--,c--;
    char l='.';
    for (int i=1;i<=100;i++){
            if (i==50)
            l='#';
        for (int j=1;j<=100;j++)
            a[i][j]=l;
    }
    for (int i=1;i<=49&&c;i+=2){
        for (int j=1;j<=100&&c;j++){
            if (a[i][j-1]!='#'&&a[i-1][j]!='#'){
            a[i][j]='#';
            c--;
            }

        }
    }
    for (int i=52;i<=100&&r;i+=2){
        for (int j=1;j<=100&&r;j++){
            if (a[i][j-1]!='.'&&a[i-1][j]!='.'){
            a[i][j]='.';
            r--;
            }
        }
    }
    cout<<100<<" "<<100<<endl;
    for (int i=1;i<=100;i++){
        for (int j=1;j<=100;j++){
            cout<<a[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    let s = input[0].split("");
    const QN = parseInt(input[1]);
    let front = []
    let back = []
    let isReverse = false
    for(let i = 2; i<2+QN; i++){
        let q = input[i].split(" ")
        if(q[0] == 1){
            isReverse = !isReverse
        } else {
            if(q[1] == 1){
                if(isReverse) back.push(q[2])
                else front.push(q[2])
            } else {
                if(isReverse) front.push(q[2])
                else back.push(q[2])
            }
        }
    }
    if(isReverse){
        s.reverse()
        back.reverse()
        console.log(back.join("") + s.join("") + front.join(""))
    }else{
        front.reverse()
        console.log(front.join("")+s.join("")+back.join(""))
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 36660
l = list(input())
n = len(l)
mod = pow(10, 9) + 7
m = pow(10, 5) + 5
p2 = [1] * m
p3 = [1] * m
for i in range(1, m):
    p2[i] = (p2[i - 1] * 2) % mod
    p3[i] = (p3[i - 1] * 3) % mod
cnt = 0
ans = 0
for i in range(n):
    if l[i] == "1":
        ans += ((p3[n - i - 1] * p2[cnt]) % mod)
        ans %= mod
        cnt += 1
ans += p2[cnt]
ans %= mod
print(ans)

Measured memory_bytes: 17524
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

bool ok(string s) {
  return s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H';
}

void solve() {
  int n; cin >> n;
  map<char, ll> map;
  rep(i, n) {
    string s; cin >> s;
    if (!ok(s)) continue;
    if (map.find(s[0]) == map.end()) map.insert(make_pair(s[0], 1));
    else map[s[0]]++;
  }
  if (map.size() == 0) {
    outl(0);
  } else {
    ll sum = 0;
    vector<char> v = {'M', 'A', 'R', 'C', 'H'};
    for (int vi : v) {
      if (map.find(vi) == map.end()) map.insert(make_pair(vi, 0));
    }
    for (int i = 0; i < 5; i++) {
      for (int j = i+1; j < 5; j++) {
        for (int k = j+1; k < 5; k++) {
          // debug3(i, j, k);
          // debug3(v[i], v[j], v[k]);
          // debug3(map[v[i]], map[v[j]], map[v[k]]);
          sum += map[v[i]] * map[v[j]] * map[v[k]];
        }
      }
    }
    outl(sum);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


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

int main(){
  int dice[7], temp;
  string order;

  cin
    >> dice[1]
    >> dice[2]
    >> dice[3]
    >> dice[4]
    >> dice[5]
    >> dice[6];

  cin >> order;

  for(int i = 0; i < 101; i++){
    if(order[i] == '\0') break;
    else if(order[i] == 'N'){
      temp = dice[5];
      dice[5] = dice[1];
      dice[1] = dice[2];
      dice[2] = dice[6];
      dice[6] = temp;
    }
    else if(order[i] == 'S'){
      temp = dice[2];
      dice[2] = dice[1];
      dice[1] = dice[5];
      dice[5] = dice[6];
      dice[6] = temp;
    }
    else if(order[i] == 'W'){
      temp = dice[1];
      dice[1] = dice[3];
      dice[3] = dice[6];
      dice[6] = dice[4];
      dice[4] = temp;
    }
    else if(order[i] == 'E'){
      temp = dice[1];
      dice[1] = dice[4];
      dice[4] = dice[6];
      dice[6] = dice[3];
      dice[3] = temp;
    }
  }

  cout << dice[1] << endl;

  return 0;
}

Measured memory_bytes: 1204
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B;
    scan(A, B);
    long n = A + B;
    writeln((n < 10) ? n.text : "error");
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }
 
int main() {
  std::cout << std::fixed << std::setprecision(10);
  ull n;
  cin >> n;

  vector<ull> v;
  each(i, n) {
    ull tmp;
    cin >> tmp;
    v.push(tmp);
  }

  sort_asc(v);
  double res = 0.0;
  each(i, n) {
    if (i == 0) {
      res = v[i];
      continue;
    }

    res = (double)((double)res + (double)v[i]) / 2.0;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256