akhauriyash/Code-Regression huggingface dataset:
S = input()

d = [0, 0, 0, 1]

max_ans = 10**9 + 7

for c in reversed(S):
    # print(c, d)
    m = [c == "A", c == "B", c == "C", c == "?"]
    if(m[3] is True):
        tmp = 3
    else:
        tmp = 1

    for j in range(3):
        d[j] = (tmp * d[j] + int(m[j] or m[3]) * d[j + 1]) % max_ans
    d[3] = (tmp * d[3]) % max_ans

print(d[0])

Measured memory_bytes: 3188
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
  static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
  
	public static void main (String[] args) throws IOException {    
    String[] first = br.readLine().split(" ");
    long L = Long.parseLong(first[0]);
    long R = Long.parseLong(first[1]);
    
    long Aminus1 = F(L-1);
    long B = F(R);
    
    // System.out.println(Aminus1 + " " + B);
    
    long ans = Aminus1 ^ B;
    
    bw.write(ans + "");
    
    bw.close();
	}
  
  public static long F(long X) {
    if(X <= 0) return 0;
    
    long ans = 0;
    
    if(X % 2 == 0) {
      if((X / 2) % 2 == 0) {
        ans = ans ^ 0;
      }
      else {
        ans = ans ^ 1;
      }
      
      ans = ans ^ X;
    }
    else {
      if((X / 2) % 2 == 0) {
        ans = ans ^ 1;
      }
      else {
        ans = ans ^ 0;
      }
    }
    
    return ans;
  }
}


Measured memory_bytes: 23252
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

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

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
a = LI()

asort = sorted(a)

d = defaultdict(int)
for i in range(N):
    d[a[i]] += 1
keys = sorted(list(d.keys()))

ans = [0]*N
max_ = 0
place = 0
for i in range(N):
    if a[i] > max_:
        diff = a[i]-max_
        num = N-bisect_left(asort,a[i])
        ans[i] = num*diff
        for j in range(place,len(keys)):
            if keys[j] <= max_:
                continue
            elif keys[j] >= a[i]:
                place = j
                break
            else:
                ans[i] += (keys[j]-max_)*d[keys[j]]
        max_ = a[i]

ans[0] = sum(a)-sum(ans[1:])

for i in range(N):
    print(ans[i])

Measured memory_bytes: 74048
#include<cstdio>
#include<vector>
#include<algorithm>

#define	pb			push_back
#define	rep(i,n)	for(int i=0;i<n;i++)

using namespace std;

typedef	vector<int>	vi;

struct Rect{
	int l,r,t,b;
};

int main(){
	int t;	scanf("%d",&t);
	while(t--){
		int h,w;	scanf("%d%d",&h,&w);
		static char bag[50][51];
		rep(i,h)	scanf("%s",bag[i]);

		int n=0;	// number of goods
		vector<char> goods;
		int ginv[128];
		rep(i,128)	ginv[i]=-1;
		rep(i,h)rep(j,w){
			char c=bag[i][j];
			if(c!='.' && ginv[c]==-1){
				goods.pb(c);
				ginv[c]=n++;
			}
		}

		Rect rc[7];
		rep(i,n){
			rc[i].l=rc[i].t=100;
			rc[i].r=rc[i].b=0;
		}
		rep(i,h)rep(j,w){
			char c=bag[i][j];
			int id=ginv[c];
			if(c!='.'){
				rc[id].l=min(rc[id].l,j);
				rc[id].r=max(rc[id].r,j);
				rc[id].t=min(rc[id].t,i);
				rc[id].b=max(rc[id].b,i);
			}
		}

		bool safe=false,badshape=false;
		vi ongoods[7];
		rep(k,n){
			for(int i=rc[k].t;i<=rc[k].b;i++)for(int j=rc[k].l;j<=rc[k].r;j++){
				char c=bag[i][j];
				if(c=='.'){ badshape=true; goto BADSHAPE; }
				if(c!=goods[k])	ongoods[k].pb(ginv[c]);
			}
			sort(ongoods[k].begin(),ongoods[k].end());
			ongoods[k].erase(unique(ongoods[k].begin(),ongoods[k].end()),ongoods[k].end()	);
		}
		BADSHAPE:

		if(!badshape){
			int ord[]={0,1,2,3,4,5,6};
			do{
				bool ok=true;
				rep(i,n){
					rep(j,ongoods[i].size()){
						int front,back;
						rep(k,n){
							if(ord[k]==i)				back=k;
							if(ord[k]==ongoods[i][j])	front=k;
						}
						if(front>back){ ok=false; goto BADORDER; }
					}
				}
				BADORDER:
				if(ok){ safe=true; break; }
			}while(next_permutation(ord,ord+n));
		}

		puts(safe?"SAFE":"SUSPICIOUS");
	}

	return 0;
}

Measured memory_bytes: 808
#include <stdio.h>

void swap(int *a, int *b)
{
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int gcd(int a, int b)
{
  int r;
  if (a < b) {
    swap(&a, &b);
  }

  while ((r = a % b) != 0) {
    a = b;
    b = r;
  }
  return b;
}

int lcd(int a, int b)
{
  //return (a * b) / gcd(a, b);
  return (a / gcd(a, b)) * b;
}

int main(void)
{
  int a, b;

  while (scanf("%d %d", &a, &b) != EOF) {
    printf("%d %d\n", gcd(a, b), lcd(a, b));
  }

  return 0;
}

Measured memory_bytes: 596
#include <cstdio> 
#include <cstdlib> 
#include <cmath> 
#include <cstring> 
#include <climits> 
#include <cfloat> 
#include <map> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <numeric>
#include <cassert>

#define FOR(i, min, max) for (int i = (min); i < (max); ++i) 
#define FORE(i, min, max) for (int i = (min); i <= (max); ++i) 
#define REP(i, n) for (int i = 0; i < (n); ++i) 
#define REPV(vec, i) for (int i = 0; i < (int)(vec.size()); ++i) 
#define FOR_EACH(vec, it) for (typeof((vec).begin()) it = (vec).begin(); it != (vec).end(); ++it)

using namespace std; 
static const double EPS = 1e-12; 
typedef long long ll; 

template<typename T>
vector<T> getVector(int N) {
    vector<T> v(N);
    REP(i, N) cin >> v[i];
    return v;
}

int main(void)
{
    int N;
    cin >> N;
    set<string> w;
    REP(i, N) {
        string s;
        cin >> s;
        w.insert(s);
    }
    cout << w.size() << endl;
    return 0;
}


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

int ans;
int n;
char s[510][510];

int judge() {
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		bool flag = true;
		for (int j = 1; j <= n; j++)
			if (s[i][j] == '.') flag = false;
		if (flag) cnt++;
	}
	return cnt;
}

int JUDGE() {
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		bool flag = true;
		for (int j = 1; j <= n; j++)
			if (s[j][i] == '.') flag = false;
		if (flag) cnt++;
	}
	return cnt;
}

void solve(int u) {
	bool flag = false;
	for (int i = 1; i <= n; i++) {
		if (s[i][u] == '#') flag = true;
	}
	int cnt = 0;
	if (!flag) cnt = 1;
	//int cnt = 0;
	for (int i = 1; i <= n; i++)
		if (s[u][i] == '.') cnt++;
	ans = min(ans, cnt + n - JUDGE());
}

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%s",s[i] + 1);
	bool flag = false;
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			if (s[i][j] == '#') flag = true;
	if (!flag) { printf("-1\n"); return 0; }
	if (judge()) {
		printf("%d\n",n - JUDGE());
		return 0;
	} else {
		ans = 100000;
		for (int i = 1; i <= n; i++)
			solve(i);
		printf("%d\n",ans);
	}
	return 0;
}

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void input() {

    }

    void solve() {
        input();
        int n, k;
        cin >> n >> k;
        int tapi = (n + 1) / 2;

        if (tapi >= k) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    int ans = 0;
    ans = x + y / 2;

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int cnt1[100005];

int main(){
	string s; cin >> s;
	int n=s.size();
	bool R=true;
	bool L=false;
	int cntR=-1; int cntL=-1;
	int cntr=0; int cntl=0;
	for(int i=0;i<n;i++){
		if(R){
			cntr=0;
			while(s[i]=='R'){
				i++;
				cntr++;
			}
			i--;
			cntR=i;
			R=false;
			L=true;
		}
		else if(L){
			cntl=0;
			while(s[i]=='L'){
				i++;
				cntl++;
			}
			i--;
			cntL=i;
			cnt1[cntR]=cntl/2+cntr/2+cntr%2;
			cnt1[cntR+1]=cntr/2+cntl/2+cntl%2;
			R=true;
			L=false;
		}
	}
	for(int i=0;i<n;i++){
		cout << cnt1[i] << " " ;
	}
	cout << endl;
}

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





int main(){
  int x,y;
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  x=(a+b+c+d)/60;
  y=(a+b+c+d)%60;
  cout<<x<<endl<<y<<endl;
  
  
  return 0;
}



Measured memory_bytes: 3028
fun main(args: Array<String>) {
    val set = mutableSetOf<Int>()
    (1..9).forEach { a ->
        (1..9).forEach { b -> 
            set.add(a * b)
        }
    }
    val n = readLine()!!.toInt()
    if (set.contains(n)) {
        print("Yes")
    } else {
        print("No")
    }
}


Measured memory_bytes: 33956
#include<cstdio>
#include<algorithm>
#define INF 1000000000
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

ll a[100001];
ll memo[100001];//i???????????§?¶?????????????????¨?(i???????????????)
int main(){
	int n, k;
	while (scanf("%d%d", &n, &k), n){
		rep(i, n)
			scanf("%lld", &a[i]);
		ll sum = 0;
		rep(i, n + 1){
			memo[i] = sum;
			sum += a[i];
		}
		ll Max = -INF;
		rep(i, n - k + 1){
			sum = memo[i + k] - memo[i];
			Max = max(Max, sum);
		}
		printf("%lld\n", Max);
	}
	return 0;
}

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

int main() {
	long long  a, b, r, x, tmp;
	cin >> a >> b;
	x = a * b;


	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}


	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	cout << x / b << endl;
	return 0;
}


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

#define show(x) cerr << #x << " = " << x << endl ;
#define input_from_file freopen("input.txt","r",stdin)
#define output_to_file freopen("output.txt" , "w",stdout)
#define output_to_error freopen("error.txt" , "w" ,stderr)
#define fastio ios_base::sync_with_stdio(0)
#define endl '\n'

const int H = 1e4+1 , N = 1e3+1;
int dp[H][N];
int ai[N] , bi[N] , minn[H];
int main()
{
    #ifdef LOCAL
        input_from_file;
        output_to_file;
        output_to_error;
    #endif
    fastio;cin.tie(0);cout.tie(0);
    int h , n ; cin >> h >> n ;
    for(int i = 1 ; i <= n ; ++i)
        cin >> ai[i] >> bi[i];
    for(int i = 1 ; i <= h ; ++i)
        for(int j = 1 ; j <= n ; ++j)
            dp[i][j] = INT_MAX;
    for(int i = 1 ; i <= h ; ++i)
        minn[i] = INT_MAX;
    for(int i = 1 ; i <= h ; ++i)
    {
        for(int j = 1 ; j <= n ; ++j)
            {
                if(i >= ai[j])
                    dp[i][j] = min(dp[i][j] , bi[j] + minn[i-ai[j]]);
                else dp[i][j] = min(dp[i][j] , bi[j]);
                minn[i] = min(minn[i] , dp[i][j]);
            }
    }
    int ans = INT_MAX;
    for(int i = 1 ; i <= n ; ++i)
        ans = min(ans , dp[h][i]);
    cout << ans;
    return 0;
}


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

int main(){
    string s, t;
    cin >> s >> t;
    ll n = s.size();
    rep(i, 0, n){
        bool f = true;
        rep(j, 0, n){
            if(s[j] != t[(i+j) % n]) f = false;
        }
        if(f){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  map<char, ll> mp;
  for (ll i = 0; i < N; i++) {
    string s; cin >> s;
    mp[s.at(0)]++;
  }
  string march = "MARCH";
  ll cnt = 0;
  for (ll i = 0; i < 5; i++) {
    for (ll j = i + 1; j < 5; j++) {
      for (ll k = j + 1 ; k < 5; k++) {
	cnt += mp[march.at(i)] * mp[march.at(j)] * mp[march.at(k)];
      }
    }
  }
  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n;
	int c;
	
	while (1){
		scanf("%d", &n);
		c = 0;
		
		if (n == 0){
			break;
		}
		
		while (n != 1){
			if (n % 2 == 0){
				n /= 2;
			}
			else if (n % 2 != 0){
				n *= 3;
				n += 1;
			}
			c++;
		}
		printf("%d\n", c);
		
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 500010, inf = 1e9 + 233, mod = 1e9 + 7;
int n, X;
int a[maxn], f[210][maxn];

template<typename T>
inline void read(T &k)
{
    int f = 1; k = 0; char c = getchar();
    while (c < '0' || c > '9') c == '-' && (f = -1), c = getchar();
    while (c <= '9' && c >= '0') k = k * 10 + c - '0', c = getchar();
    k *= f;
}

int main()
{
    read(n); read(X);
    for (int i = 1; i <= n; i++) read(a[i]);

    sort(a + 1, a + 1 + n, greater<int>());

    int ans = 0;
    f[0][X] = 1;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= X; j++)
        {
            if (j >= a[i])
            {
                f[i][j] = (f[i][j] + 1ll * f[i - 1][j] * (n - i)) % mod;
                f[i][j % a[i]] = (f[i][j % a[i]] + f[i - 1][j]) % mod;
            }
            else f[i][j] = (f[i][j] + 1ll * f[i - 1][j] * (n - i + 1)) % mod;
            // printf("i:%d j:%d f:%d\n", i, j, f[i][j]);
        }

        if (i == n) 
            for (int j = 0; j <= X; j++)
            ans = (ans + 1ll * j * f[i][j]) % mod;
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 391552
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
AA = A.copy()
count = sum(A)
ans = 0
for i in range(N-1,-1,-1):
    if A[i+1] + A[i] <= B[i]:
        ans += A[i+1] + A[i]
        A[i+1] = 0
        A[i] = 0
    else:
        now = A[i+1] - B[i]
        A[i+1] = max(now, 0)
        A[i] = A[i] - (max(-now, 0))
        ans += B[i]
    #print(A)
print(ans)

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++) cin >> H[i];
  
  int cnt=0;
  for(int i=N; i>=0; i--){
    bool T=true;
    for(int j=i-1; j>=0; j--){
      if(!(H[i]>=H[j])) T=false;
    }
    if(T) cnt++;
  }

  cout << cnt << endl;
  return 0;
}

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

int main()
{
    int n;
    bool flag = true;
    std::vector<int> h;
    std::cin>>n;
    h.resize(n);
    for(int i=0;i<n;i++)std::cin>>h[i];

    for(int i=n-2;i>=0;i--){
        if(h[i]>h[i+1]){
            if(h[i]==h[i+1]+1)h[i]--;
            else flag = false;
        }
    }
    std::string ans;
    if(flag)ans = "Yes";
    else ans = "No";
    std::cout<<ans<<std::endl;
}

Measured memory_bytes: 640
from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
import math

def bin1(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=k**mid
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin1(mid+1,r,k,t,b,val,ans)
		else:
			return bin1(l,mid-1,k,t,b,val,ans)
		
def bin2(l,r,k,t,b,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		v=t*(k**mid)+b*(mid)
		if(v==val):
			return v
		elif(v>val):
			ans=mid
			return bin2(l,mid-1,k,t,b,val,ans)
		else:
			return bin2(mid+1,r,k,t,b,val,ans)

def SieveOfEratosthenes(n): 
      
    # Create a boolean array "prime[0..n]" and initialize 
    #  all entries it as true. A value in prime[i] will 
    # finally be false if i is Not a prime, else true. 
    prime = [True for i in range(n+1)] 
    p = 2
    while (p * p <= n): 
          
        # If prime[p] is not changed, then it is a prime 
        if (prime[p] == True): 
              
            # Update all multiples of p 
            for i in range(p * p, n+1, p): 
                prime[i] = False
        p += 1
    l=[]
    for i in range(2,n+1):
    	if(prime[i]):
    		l.append(i)
    return l
def bin(l,r,ll,val):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		if(val>=ll[mid][0] and val<=ll[mid][1]):
			return mid
		elif(val<ll[mid][0]):
			return bin(l,mid-1,ll,val)
		else:
			return bin(mid+1,r,ll,val)
def deci(n):
	s=""
	while(n!=0):
		if(n%2==0):
			n=n//2
			s="0"+s
		else:
			n=n//2
			s="1"+s
	return s
def diff(s1,s2):
	if(len(s1)<len(s2)):
		v=len(s1)
		while(v!=len(s2)):
			s1="0"+s1
			v=v+1
	else:
		v=len(s2)
		while(v!=len(s1)):
			s2="0"+s2
			v=v+1
	c=0
	for i in range(len(s1)):
		if(s1[i:i+1]!=s2[i:i+1]):
			c=c+1
	return c
from sys import stdin, stdout 
def fac(a,b):
	v=a
	while(a!=b):
		v*=a-1
		a=a-1
	return v
def bino(l,r,n):
	if(l>r):
		return -1
	else:
		mid=(l+r)//2
		val1=math.log((n/mid)+1,2)
		val2=int(val1)
		if(val1==val2):
			return val1
		elif(val1<1.0):
			return bino(l,mid-1,n)
		else:
			return bino(mid+1,r,n)

def binary(l,r,ll,val,ans):
	if(l>r):
		return ans
	else:
		mid=(l+r)//2
		if(val%ll[mid]==0):
			ans=ll[mid]
			return binary(l,mid-1,ll,val,ans)
		else:
			return binary(l,mid-1,ll,val,ans)
def odd(n,ans,s):
	if(n%2!=0 or n in s):
		return ans
	else:
		s.add(n)
		return odd(n//2,ans+1,s)

if __name__ == '__main__':
	s,w=map(int,input().split(" "))
	if(w>s-1):
		print("unsafe")
	else:
		print("safe")

Measured memory_bytes: 76784
import java.io.*;

public class Main{
	public static void main(String[] args){
		try{
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String s;
			while((s=reader.readLine()) !=null){
				String[] t=s.split(" ");
				int[] r=new int[t.length];
				for(int i=0;i<t.length;i++){
					r[i]=Integer.parseInt(t[i]);
				}
				int c =r[0]+r[1];
				System.out.println(c);
			}
		}catch(IOException e){
			System.exit(0);
		}
	}
}

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

int main() {
    long long n, k, ans=0, cnt;
    cin >> n >> k;
    vector<long long> s(n+1);
    for(int i=1; i<=n+1; i++) {
        if(i==1) {
            s[i-1]=n+1;
        }
        else {
            s[i-1]=s[i-2]+n-2*i+2;
        }
        s[i]%=1000000007;
    }
    for(int i=k; i<=n+1; i++) {
        ans+=s[i-1];
        ans%=1000000007;
    }
    cout << ans;
}

Measured memory_bytes: 4644
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: i64 = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };

    const INF: i64 = 1_000_000_000_000_000;
    let M = (N as f64).sqrt() as i64;
    let ans = (1..(M + 1))
        .map(|i| if N % i == 0 { i + N / i - 2 } else { INF })
        .min()
        .unwrap();

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
 
const int size = 100001;
 
int dp[size];
int stone[size];
 
int frog(int n){
    if(n <= 0)
        return 0;
    if(dp[n] != -1)
        return dp[n];
  	if(n - 2 >= 0)
    	return dp[n] = min(frog(n - 1) + abs(stone[n] - stone[n - 1]), frog(n - 2) + abs(stone[n] - stone[n - 2]));
	else if(n - 1 >= 0)
      	return dp[n] = frog(n - 1) + abs(stone[n] - stone[n -1]);
}
 
int main(){
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> stone[i];
    for(int i = 0; i < n; i++)
        dp[i] = -1;
    cout << frog(n - 1) << endl;
 
}


Measured memory_bytes: 2560
def solve():
    N = input()
    n = int(N)

    if N[1:].count('9') == len(N) - 1:
        ans = int(N[0]) + 9 * (len(N) - 1)
    else:
        ans = int(N[0]) - 1 + 9 * (len(N) - 1)
    print(ans)

solve()

Measured memory_bytes: 2940
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ n, m ] <- readInts
	[ ps, ss ] <- transpose . map words . ( ++ [ "1 WA" ] ) <$> replicateM m getLine
	uncurry ( printf "%d %d\n" ) $ solve n ( map ( pred . read ) ps ) ss

solve n ps ss = runST $ do
	let
		m = length ps
	acs <- newArray ( 0, n - 1 ) 0 :: ST s ( STUArray s Int Int )
	was <- newArray ( 0, n - 1 ) 0 :: ST s ( STUArray s Int Int )
	res_ac <- newSTRef 0
	res_wa <- newSTRef 0
	forM_ ( zip ps ss ) $ \( p, s ) -> do
		ac <- readArray acs p
		wa <- readArray was p
		if s == "AC" && ac == 0
			then do
				writeArray acs p 1
				modifySTRef res_ac succ
				modifySTRef res_wa ( + wa )
			else modifyArray was p succ
				-- s == "WA" && ac == 1 case will be discarded 
	res_ac' <- readSTRef res_ac
	res_wa' <- readSTRef res_wa
	return ( res_ac' :: Int, res_wa' )

Measured memory_bytes: 78204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGreenBin solver = new CGreenBin();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGreenBin {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();
            String[] s = new String[n];
            for (int i = 0; i < n; i++) {
                char[] c = in.next().toCharArray();
                Arrays.sort(c);
                s[i] = new String(c);
            }
            Arrays.sort(s);
            long res = 0;
            long cnt = 0;
            for (int i = 1; i < n; i++)
                res += s[i].equals(s[i - 1]) ? ++cnt : (cnt = 0);

            out.println(res);

        }

    }
}



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

int main(){
  long long q, h, s, d, n;
  cin >> q >> h >> s >> d >> n;
  if ( 4 * q < s ) s = 4 * q;
  if ( 2 * h < s ) s = 2 * h;
  if ( 2 * s < d ) d = 2 * s;
  cout << n / 2 * d + (n & 1) * s << endl;
  return 0;
}


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

int main() {
  int w, h, x, y, r;
  std::cin >> w >> h >> x >> y >> r;
  if (x - r < 0 || x + r > w || y - r < 0 || y + r > h) {
    std::cout << "No" << std::endl;
  } else {
    std::cout << "Yes" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            boolean a[] = new boolean[3];
            a[in.nextInt() - 1] = true;
            a[in.nextInt() - 1] = true;
            for (int i = 0; i < 3; i++) {
                if (!a[i]) out.println(i + 1);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 23252
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
int main(){
    string s;
    while(cin >> s){
        vector<int> in;
        int t = 0;
        for(int i = 0; i < s.size(); i++){
            if(s[i] == ','){
                in.push_back(t);
                t = 0;
                continue;
            }
            t *= 10;
            t += s[i] - '0';
        }
        in.push_back(t);
        sort(in.begin(),in.end());

        if(in[0] == in[3] || in[1] == in[4]){
            cout << "four card" << endl;
            continue;
        }
        int card[15] = {};
        for(int i = 0; i < 5; i++)card[in[i]]++;
        sort(card, card+15);
        if(card[12] == 0){
            cout << "full house" << endl;
            continue;
        }
        if(card[14] == 1 &&(in[4] - in[0] == 4 || (in[0] == 1 && in[1] == 10 && in[4] == 13))){
            cout << "straight" << endl;
            continue;
        }
        if(card[14] == 3){
            cout << "three card" << endl;
            continue;
        }
        if(card[14] == 2 && card[13] == 2){
            cout << "two pair" << endl;
            continue;
        }
        if(card[14] == 2){
            cout << "one pair" << endl;
            continue;
        }
        cout << "null" << endl;
    }
}



Measured memory_bytes: 3128
#include <iostream>
#include <stdio.h>
using namespace std;

int main(void){
  char s[100];
  scanf("%s",s);
  int count = 0;
  int i=0;
  for(i=0;s[i]!='\0';i++);
  for(int j=0;j<(i+1)/2;j++){
    if(s[j]!=s[i-1-j]) count++;
  }
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

ll pw(ll x, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n % 2 == 1) {
            res *= x;
            res %= mod;
            n--;
        } else {
            x *= x;
            x %= mod;
            n /= 2;
        }
    }
    return res;
}

ll inv(int n) {
    return pw(n, mod - 2);
}

const int N = 2e5 + 7;

vector <ll> fact(2e5 + 7, 1);

int C(ll n, ll k) {
    ll ver = 1;
    for (int i = n; i >= n - k + 1; i--) {
        ver *= i;
        ver %= mod;
    }
    ll dv = fact[k];
    dv = inv(dv);
    ver *= dv;
    ver %= mod;
    return ver;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    ll ans = pw(2, n);
    ans--;
    if (ans < 0) ans += mod;
    for (int i = 2; i < N; i++) {
        fact[i] = fact[i - 1] * i;
        fact[i] %= mod;
    }
    ans -= C(n, a);
    if (ans < 0) ans += mod;
    ans -= C(n, b);
    if (ans < 0) ans += mod;
    cout << ans << '\n';
    return 0;
}

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

#define GYOU_MAX 256


int main(void)
{
	int R, G, B, N;
	scanf("%d%d%d%d", &R, &G, &B, &N);

	int count = 0;
	double x;
	for (int i = 0;;i++) {
		if (R*i > N) {
			break;
		}

		for (int j = 0;;j++) {

			x=(double)(N-( R * i + G * j))/B;

			//printf("%d %d %f\n", i, j, x);
			if ((ceil(x) == floor(x))&&x >= 0) {
				count++;
				//printf("[%d %d %d]\n", i, j,(int) x);
			}
			if (R*i + G * j > N) {
				break;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 128
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;
using ll = long long;

const ll MOD = 1000000007;
const ll INF = 1e18;
const double pi = acos(-1);
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1,1,0,-1,-1,-1,0,1};
const int dy8[8] = {0,1,1,1,0,-1,-1,-1};


#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()


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; }



void solve(){
    
    // remove the bottom 3 lines when you submit this code.
    std::ifstream in("sample.txt");
    std::cin.rdbuf(in.rdbuf());

    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s; cin >> s;
    bool isseven = false;
    rep(i,s.size()){
        if(s[i]=='7') isseven = true;
    }
    cout << ((isseven)?"Yes":"No") << endl;
}



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



Measured memory_bytes: 3656
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& o) {
    out << "(" << o.first << "," << o.second << ")";
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<T>& V) {
    for (int i = 0; i < V.size(); i++) {
        out << V[i];
        if (i != V.size() - 1) out << " ";
    }
    return out;
}
template <class T>
ostream& operator<<(ostream& out, const vector<vector<T> >& Mat) {
    for (int i = 0; i < Mat.size(); i++) {
        if (i != 0) out << endl;
        out << Mat[i];
    }
    return out;
}
template <class S, class T>
ostream& operator<<(ostream& out, const map<S, T>& mp) {
    out << "{ ";
    for (auto it = mp.begin(); it != mp.end(); it++) {
        out << it->first << ":" << it->second;
        if (mp.size() - 1 != distance(mp.begin(), it)) out << ", ";
    }
    out << " }";
    return out;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

const ll MOD = 1e9 + 7;
template <class Type>
Type solve(Type res = Type()) {
    string S;
    cin >> S;

    int SL = (int)S.length();

    auto dp = make_v<ll>(SL + 1, 13);
    dp[0][0] = 1;
    for (int i = 0; i < SL; i++) {
        int l = 0, r = 9;

        if (S[i] != '?') {
            l = r = S[i] - '0';
        }

        for (int j = 0; j < 13; j++) {
            if (dp[i][j] == 0) continue;
            for (int m = l; m <= r; m++) {
                dp[i+1][(j*10+m)%13] += dp[i][j];
                dp[i+1][(j*10+m)%13] %= MOD;
            }
        }
    }

    res = dp[SL][5];
    return res;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // solve<ll>(0);
    cout << fixed << setprecision(12) << solve<ll>() << endl;
    return 0;
}

Measured memory_bytes: 16664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
  using P = pair<int, int>;
  int n;
  vector<int> f, primes; //f.at(x)はxの最小素因数
  Sieve(int n=1):n(n), f(n+1) {
  f[0] = f[1] = -1;
  for (ll i = 2; i <= n; ++i) {
    if (f[i]) continue; //ここでf[i]==0なら素数
    primes.push_back(i);
    f[i] = i;
    for (ll j = i*i; j <= n; j += i) {
  if (!f[j]) f[j] = i;
    }
  }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) { //xの素因数を小さい順に列挙
  vector<int> res;
  while (x != 1) {
    res.push_back(f[x]);
    x /= f[x];
  }
  return res;
  }
  vector<P> factor(int x) {
  vector<int> fl = factorList(x);
  if (fl.size() == 0) return {};
  vector<P> res(1, P(fl[0], 0));
  for (int p : fl) { //ここでランレングス圧縮
    if (res.back().first == p) {
  res.back().second++;
    } else {
  res.emplace_back(p, 1);
    }
  }
  return res;
  }
  ll divs(ll x){
    ll r = 1;
    for(auto y : factor(x)){
      r *= y.second+1;
    }
    return r;
  }
};
// Sieve sieve(N);でN以下の各自然数の最小素因数を調べ上げる
// sieve.factor(M)でMの素因数分解

int main()
{
  ll N;
  cin >> N;
  Sieve sieve(N);
  ll ans = 0;
  rep(i, N){
    ans += (i+1) * sieve.divs(i+1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 46500
N = int(input())
A = list(map(int, input().split()))
A_re = []

for i in range(N):
  num = A[i]
  A_re.append([num, i+1])
  
A_re.sort()

Ans = []
for j in range(N):
  ans = A_re[j][1]
  Ans.append(str(ans))
  
Ans = ' '.join(Ans)
print(Ans)

Measured memory_bytes: 27648
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = list(input().strip())
    if n[-1] in ['2','4','5','7','9']:
        print('hon')
    elif n[-1] in ['0','1','6','8']:
        print('pon')
    else:
        print('bon')


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 61672
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
#include<limits.h>
using namespace std;

int main() {
    long long n,ans,a=0,b,f=INT_MAX;

    cin>>n;
    for(int i=sqrt(n);i>=1;i--){
        if(n%i==0){
            ans=i+n/i-2;
          break;
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef long double ld;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
#define VV(T) vector<vector<T>>
#define sz(x) int(x.size())
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i,n) for (ll i=(ll)n-1;i>=0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX6 1001001//6
#define MAX7 10010010//7
#define SENTINEL 2000000000//9
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define CLR(mat) memset(mat, 0, sizeof(mat))
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}//最大公約数
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}//最小公倍数
template<class T> bool contain(const std::string& s, const T& v) {
   return s.find(v) != std::string::npos;
}
const int MOD = 1000000007;

inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;
x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}

ll nCr(ll n,ll k,ll MOD_=1000000007){
    //assert(n>=0&&k>=0&&MOD_>=2);
    ll size=k;
    ll ans=1;
    vector<ll>fact_inv,inv;
    fact_inv.resize(size+5);
    inv.resize(size+5);
    fact_inv[0]=fact_inv[1]=1;
    inv[1]=1;
    for(int i=2;i<size+5;i++){
        inv[i]=MOD_-inv[MOD_%i]*(MOD_/i)%MOD_;
        fact_inv[i]=fact_inv[i-1]*inv[i]%MOD_;
    }
    for(int i=n;i>=n-k+1;i--){
        ans*=i;ans%=MOD_;
    }
    return ans*fact_inv[k]%MOD_;
}

//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// vector型から重複を削除 list.erase(unique(ALL(list)),list.end());
// g++ -o a a.cpp -Wall -lm -std=c++17
//push_back -> emplace_back
int main(){
   int S;cin>>S;
   int a=S/3;
   ll ans=0;
   for(int i=1;i<=a;i++){
       if(i==1){ans+=1;continue;}
       int amari=S-3*i;
       ans=(ans+nCr(amari+i-1,i-1))%MOD;
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <math.h>
#include <map>
#include <stack>
using namespace std;
static const int INF = 1e9+7;
// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i =a; i < b; i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define PI 3.14159265359

int main(){
    int a; cin >> a;
    int b; cin >> b;
    int c; cin >> c;
    int x; cin >> x;

    int cnt = 0;
    repr(i, 0, a+1){
        repr(j, 0, b+1){
            repr(k, 0, c+1){
                if(500*i + 100*j + 50*k == x) cnt++;
            }
        }
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		int MAX = 1000000;
		boolean[] prime = new boolean[MAX + 1];
		for (int i = 2; i <= MAX; i++) {
			if (!prime[i]) {
				for (int j = i * 2; j <= MAX; j += i) {
					prime[j] = true;
				}
			}
		}
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] a = new int[n];
			int min = Integer.MAX_VALUE;
			boolean[] f = new boolean[m + 1];
			for (int i = 0; i < n; i++) {
				int s = scanner.nextInt();
				min = Math.min(s, min);
				a[i] = s;
				for (int j = s; j <= m; j += s) {
					f[j] = true;
				}
			}
			int max = 0;
			for (int i = min; i <= m; i++) {
				if (!f[i])
					for (int j = 0; j < n; j++) {
						if (i - a[j] >= 0 && f[i - a[j]]) {
							f[i] = true;
							break;
						}
					}
				if (f[i] && !prime[i])
					max = i;
			}
			System.out.println(max == 0 ? "NA" : max);

		}

	}
}

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

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

  int m = n;
  set<int> st;
  for (int t = 0; t < 2; t++) {
    for (int i = 2; i * i <= n; i++) {
      if(n % i == 0) {
        st.insert(i);
        st.insert(n/i);
      }
    }
    st.insert(n);
    n--;
  }

  st.erase(1);

  int answer = 0;
  for (auto & k : st) {
    int x = m;
    while (true) {
      if(x % k == 0) x /= k;
      else if(x % k == 1) {
        answer++;
        break;
      } else {
        break;
      }
    }
  }
  cout << answer << '\n';
}


Measured memory_bytes: 3908
import java.util.Scanner;

public class Main {

	static Scanner scanner;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    String o=gs();
	    String e=gs();
	    
	    StringBuilder sb=new StringBuilder();
	    for (int i=0; i<e.length();i++) {
	    	sb.append(o.charAt(i));
	    	sb.append(e.charAt(i));
	    }
	    
	    

	    if (o.length() != e.length()) {
	    	sb.append(o.charAt(o.length()-1));
	    }

        System.out.println(sb.toString());
//        if (a<b) {
//        	System.out.print(Math.max(b-a-w, 0));
//        }else {
//        	System.out.print(Math.max(a-b-w, 0));
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35768
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

#define all(x) begin(x),end(x)

using namespace std;
using ll = long long;

void print_ans(const vector<int> &);

int main()
{
	vector<int> v;
	int n; cin >> n;
	if (n == 0) {
		cout << 0 << endl;
		return 0;
	}

	while (n != 0) {
		int r = n % -2;
		n /= -2;

		if (r == -1) {
			r = 1;
			n += 1;
		}

		v.push_back(r);
	}

	reverse(v.begin(), v.end());
	for (auto i : v) cout << i;
	cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, k; cin >> n >> k;
  string s; cin >> s;
  int cnt = 0;
  int diff = 0;
  for(int i=1;i<n;++i) {
    if(s[i-1] == s[i]) {
      cnt++;
    } else {
      diff++;
    }
  }
  cout << cnt + min(diff, k * 2) << endl;
}


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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) a.begin(), a.end()
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

void solve() {	
	ll N;
	cin >> N;

	char lets[5] = {'M','A','R','C','H'};
	map<char,ll> mp;
	for (int i = 0; i < N; ++i) {
		string s;
		cin >> s;
		mp[s[0]]++;
	}
	ll ans = 0;
	for (int mask = 0; mask < (1<<5); ++mask) {
		ll add = 1;
		ll cnt = 0;
		for (int i = 0; i < 5; ++i) {
			if (mask&(1<<i)) {
				++cnt;
				add *= mp[lets[i]];
			}
		}
		if (cnt==3) ans += add;
	}

	cout << ans << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256