akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<char> vc;
typedef vector<string> vs;
const ll mod = 1e9+7;
const ll inf = 1e17;
const int INF = 1e9;
const double PI = acos(-1);
#define fo(i, a, b) for(int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(s) s.begin(), s.end()
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
int main()
{
  int x;
  cin >> x;

  int m = 0;
  fo(i, 1, floor(sqrt(x))+1) {
    fo(j, 2, 10) {
      if(x >= pow(i, j)) {
        m = max(m, (int)pow(i, j));
      } else continue;
    }
  }
  cout << m << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
X=input().split()
LONG=int(X[0])
HOUSE=int(X[1])
X=input().split()
PLACE=[0]*LONG
for _ in range(HOUSE):
    place=int(X[_])
    PLACE[place]=1

i=0
while(PLACE[i]==0):
    i+=1
START=i
i=LONG-1
while(PLACE[i]==0):
    i-=1
END=i
"""
一番前にいるやつ: START
一番後ろにいるやつ: END
"""
s_g_long=LONG+START-END
MOST_LONG=s_g_long
"""
s_g_long: STARTとENDの間の距離
MOST_LONG: 最長の間隔
"""
where=START
for _ in range(HOUSE-1):
    """
    全ての間隔の長さをはかり、最長のものを通らないような道のりが最短
    """
    i_idash_long=0
    while(PLACE[where+1]==0):
        where+=1
        i_idash_long+=1
    where+=1
    i_idash_long+=1
    if MOST_LONG<i_idash_long:
        MOST_LONG=i_idash_long

print(LONG-MOST_LONG)

Measured memory_bytes: 26164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {

	int n, t, a; cin >> n >> t >> a;
	
	int ans;
	double x = 1000000000000000;
	for (int i = 0; i < n; i++) {
		int h; cin >> h;
		double tmp = (double)(t - h * 0.006);
		tmp = abs(tmp - a);
		if (chmin(x, tmp)) {
			ans = i + 1;
		}
	}

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

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){

    int a,b;
    long long x;
    char c[10];
    scanf("%d",&a);
    scanf("%s",c);
    scanf("%d",&b);
    if(strcmp(c,"+")==0){
        x=a+b;
    }
    else{
        x=a-b;
    }
    printf("%lld\n",x);

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#include <random>
#include <chrono>
#define INF 1000000000
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  ll t[n];
  REP(i, n) cin >> t[i];
  ll ans = 0;
  REP(i, n-1){
    ans += min(b, a*(t[i+1] - t[i]));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, d;
  cin >> n >> d;
  vector<vector<int>> x(n, vector<int>(d));
  rep(i,n) {
    rep(j,d) cin >> x[i][j];
  }
  int ans = 0;
  rep(i,n)rep(j,i) {
    int sq = 0;
    rep(k,d) {
      int s = x[i][k] - x[j][k];
      sq += s*s;
    }
    int s = sqrt(sq)+0.5; // 1.999999...
    if (s*s == sq) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var n = long.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(e => UInt64.Parse(e)).ToArray();
        if (a.Any(item => item == 0))
        {
            Console.WriteLine("0");
            return;
        }
        UInt64 b = 1;
        for (int i = 0; i < a.Length; i++)
        {
            if (a[i] <= 1000000000000000000 / b)
            {
                b *= a[i];
            }
            else
            {
                Console.WriteLine("-1");
                return;
            }
        }
        Console.WriteLine(b);
    }
}


Measured memory_bytes: 41532
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

int a,b,ans=0; 

inline int read(){
	int s=0,t=1;
	char c=getchar();
	while((c>'9'||c<'0')&&c!='-')c=getchar();
   	if(c=='-')t=-1,c=getchar();
   	while(c>='0'&&c<='9')s=s*10+c-'0',c=getchar();
   	return s*t;
}

int main(void){
	scanf("%d %d",&a,&b);
	ans=a+b;
	ans=max(ans,a-b);
	ans=max(ans,a*b);
	printf("%d",ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std ;
int read() {
  int x = 0 , f = 1 ;
  char c = getchar() ;
  while(c < 48 || c > 57) {
    if(c == '-') f = -1 ;
    c = getchar() ;
  }
  while(c > 47 && c < 58) {
    x = (x << 1) + (x << 3) + (c & 15) ;
    c = getchar() ;
  }
  return x * f ;
}
void print(int x) {
  if(x < 0) x = -x , putchar('-') ;
  if(! x) { putchar('0') ; }
  static char st[30] ; int stp = 0 ;
  while(x) { st[++ stp] = x % 10 ^ 48 ; x /= 10 ;}
  while(stp) { putchar(st[stp --]) ; }
  putchar('\n') ;
}
signed main() {
  int sum = read() + read() + read() ;
  if(sum < 22) puts("win") ;
  else puts("bust") ;
  return 0 ;
}

Measured memory_bytes: 256
// #pragma GCC optimize("O3")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace ::std;
// clang-format off
template<typename T> T nxt() {T res; cin >> res; return res;}
#define tests() for (int _ = nxt<int>(); _ >= 0; _--)
#define nxt1(t,n) t (n); cin >> n
#define nxt2(t,n,m) t (n),(m); cin >> n >> m
#define nxt3(t,n,m,k) t (n),(m),(k); cin >> n >> m >> k
#define rep(i, A) for (int i = 0 ; i < A ; i++)
#define ll long long
typedef pair<int,int> pii;typedef pair<ll, ll> pll;typedef vector<int> vi;typedef vector<vi> vvi;typedef vector<ll> vl;typedef vector<vl> vvl;
#define dbg(vari) cerr<<#vari<<" = "<<(vari)<<endl;
template<typename T,typename TT> ostream& operator<<(ostream &s,pair<T,TT> t) {return s<<"("<<t.first<<","<<t.second<<")";}
template<typename T> ostream& operator<<(ostream &s,vector<T> t){for(T ti : t)s<<ti<<" ";return s; }
#define all(x) (x).begin(), (x).end()
#define last(vec) vec[vec.size()-1]
#define has(c,x) ((c).find(x) != (c).end())
// clang-format on

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

    nxt2(int, N, K);
    vi a(N);
    generate(all(a), nxt<int>);

    vi dp(K + 1);

    for (int i = 1; i <= K; i++) {
        for (int j = 0; j < N; j++) {
            if (i - a[j] >= 0 && dp[i - a[j]] == 0) {
                dp[i] = 1;
            }
        }
    }
    // cout << dp << endl;

    cout << (dp[K] ? "First" : "Second") << endl;

    return 0;
}


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

vector<ll> to[11];

int main(){
    ll N;cin>>N;
    double x[60],y[60];
    rep(i,0,N)cin>>x[i]>>y[i];
    map<pair<ll,ll>,ll> m;
    ll cn,MAX=0;
    rep(i,0,N){
        rep(j,0,N){
            cn=1;
            if(i==j)continue;
            rep(k,0,N){
                rep(l,0,N){
                    if(k==l||(i==k&&j==l))continue;
                    if((y[j]-y[i])==(y[l]-y[k])&&(x[j]-x[i])==(x[l]-x[k]))cn++;
                    MAX=max(MAX,cn);
                }
            }
        }
    }
    
    cout<<N-MAX<<endl;

}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//using Graph = vector<vector<int>>;
//using P =pair<int,int>;
//int dy[4] = {-1,0,1,0};
//int dx[4] = {0,-1,0,1};

int main()
{
    int N;
    cin >> N;
    
    vector<int> data(N);
    for(int i=0;i<N-1;i++)
    {
        int a;
        cin >> a;
        a--;
        data[a]++;
        
    }
    
    for(int i=0;i<N;i++)
    {
        cout << data[i] << endl;
    }
    
    return 0;
    
}

Measured memory_bytes: 4048
N, M = map(int, input().split())

A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])

B=[]
for i in range(M):
    c, d = map(int, input().split())
    B.append([c, d])

for i in range(N):
    saitei = float("inf")
    ans = 0
    for j in range(M):
        if abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1]) < saitei:
            saitei = abs(A[i][0]-B[j][0]) + abs(A[i][1]-B[j][1])
            ans = j+1   
    print(ans) 

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

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

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    int A, B;
    cin >> A >> B;

    cout << max(A - 2*B, 0) << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import * as fs from 'fs';

export class Reader {
    lines: string[];
    currentLine: number;

    constructor() {
        this.lines = fs.readFileSync("/dev/stdin", "utf8").trim().split("\n");
        this.currentLine = 0;
    }

    readLine(): string {
        return this.lines[this.currentLine++];
    }

    readInt(): number {
        return Number(this.readLine());
    }

    readInts(): number[] {
        return this.readLine().split(" ").map(Number);
    }
}

function solve(): void {
	let reader = new Reader();
	let N = reader.readInt();
	let K = 0;
	let found = false;
	for(K=0; K<2*N+1; K++) {
		if (K*(K-1) == 2*N) {
			found = true;
			break;
		}
	}
	if (!found) {
		console.log('No');
		return;
	}
	console.log('Yes');
	console.log(K);
	let S: number[][] = new Array(K).fill(null).map(() => []);
	let numberToAdd = 1;
	for(let i=0; i<K-1; i++) {
		for(let l=i+1; l<K; l++) {
			S[i].push(numberToAdd);
			S[l].push(numberToAdd);
			numberToAdd += 1;
		}
	}
	for(let i=0; i<S.length; i++) {
		console.log(`${K-1} ${S[i].map((num) => num.toString()).join(" ")}`);
	}
}

solve();


Measured memory_bytes: 45588
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <tuple>
#include <cstring>
#include <map>
#include <iomanip>
#include <ctime>
#include <complex>
#include <cassert>
#include <climits>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define len(X) (X).size()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>

int n, k;
vector<int> G[2020];
vector<int> depth;
vector<bool> vis;

void search(int at, int dep) {
    vis[at] = 1;
    depth[dep]++;
    for (auto &i : G[at]) {
        if (!vis[i]) search(i, dep + 1);
    }
}

int val(int r) {
    for (int i = 0; i < n; i++) depth[i] = vis[i] = 0;
    search(r, 0);
    int res = 0;
    for (int i = k / 2 + 1; i < n; i++) res += depth[i];
    /*
    for (int i = 0; i < n; i++) {
        cerr << depth[i] << " ";
    }
    cerr << endl;*/
    return res;
}

int valodd(int p, int q) {
    for (int i = 0; i < n; i++) depth[i] = vis[i] = 0;
    vis[q] = 1;
    search(p, 0);
    vis[q] = 0;
    search(q, 0);
    int res = 0;
    for (int i = k / 2 + 1; i < n; i++) res += depth[i];
    /*
    for (int i = 0; i < n; i++) {
        cerr << depth[i] << " ";
    }
    cerr << endl;*/
    return res;
}

int main() {
    cin >> n >> k;
    vector<int> a(n - 1), b(n - 1);
    depth.resize(n);
    vis.resize(n);
    for (int i = 0; i < n - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;  b[i]--;
        G[a[i]].push_back(b[i]);
        G[b[i]].push_back(a[i]);
    }

    int ans = 1e9;
    if (k % 2 == 0) {
        for (int i = 0; i < n; i++) {
            ans = min(ans, val(i));
            //cout << i _ val(i) << endl;
        }
    }
    else {
        for (int i = 0; i < n - 1; i++) {
            ans = min(ans, valodd(a[i], b[i]));
            //cout << i _ val(i) << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
def resolve():
    # 整数 1 つ
    n = int(input())
    # 整数複数個
    # a, b, c = list(map(int, input().split()))
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    # A = [list(map(int, input().split())) for i in range(H)]

    max7 = n // 7
    max4 = n // 4

    re = "No"
    for i in range(max7 + 1):
        for j in range(max4 + 1):
            if 7 *i + 4 *j == n:
                re = "Yes"

    print(re)


resolve()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int n,a,b;
    cin >> n >> a >> b;
    cout << min(a, b) << " " << max(0, a + b - n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    ll n, a;
    cin >> n >> a;
    vector<ll> sup;
    vector<ll> inf;
    ll eq = 0;
    rep(i, 0, n)
    {
        ll x; cin >> x;
        if (x < a)
            inf.push_back(a-x);
        else if (x > a)
            sup.push_back(x-a);
        else 
            eq++;
    }
    if (inf.size() == 0 || sup.size() == 0)
        return cout << (1LL << eq) - 1, 0;
    ll res = (1LL << eq) - 1;
    bool go1[inf.size()][5000];
    ll dp1[inf.size()][5000];
    go1[0][inf[0]] = true;
    dp1[0][inf[0]]++;
    rep(i, 1, inf.size())
    {
        go1[i][inf[i]] = true;
        dp1[i][inf[i]]++;
        rep(j, 1, 2501)
        {
            if (go1[i-1][j] == true)
            {
                go1[i][j] = true;
                dp1[i][j] += dp1[i-1][j];
                go1[i][j + inf[i]] = true;
                dp1[i][j + inf[i]] += dp1[i-1][j];
            }
        }
    }
    bool go2[sup.size()][5000];
    ll dp2[sup.size()][5000];
    go2[0][sup[0]] = true;
    dp2[0][sup[0]]++;
    rep(i, 1, sup.size())
    {
        go2[i][sup[i]] = true;
        dp2[i][sup[i]]++;
        rep(j, 1, 2501)
        {
            if (go2[i-1][j] == true)
            {
                go2[i][j] = true;
                dp2[i][j] += dp2[i-1][j];
                go2[i][j + sup[i]] = true;
                dp2[i][j + sup[i]] += dp2[i-1][j];
            }
        }
    }
    cout << endl;
    ll x = inf.size() - 1;
    ll y = sup.size() - 1;
    rep(j, 1, 2501)
        res += dp1[x][j] * dp2[y][j] * (1LL << eq);
    cout << res;
    return 0;
}

Measured memory_bytes: 768
def func(n, a, x):
    # NX
    # x.sort()
    x = [i - a for i in x]
    minus = 0
    plus = 0
    for _x in x:
        if _x > 0:
            plus += _x
        else:
            minus += _x
    # print("x:{}".format(x))
    dp = [[0] * (plus - minus + 1) for j in range(n + 1)]
    # 平均がAとは,x[i]-Aの和が0となること
    # dp[j][t] = "xからj枚以上選んで和が「t-(負のxの和)」の場合の数"
    # 0 <= j <= N
    # 0 <= t <= (正のx[i]-Aを全て選ぶ) - (負のx[i]-Aを全て選ぶ)
    # dp[j][t] = dp[j-1][t-x[j]] + dp[j-1][t]
    # dp[0][-(負のxの和)] = 1 #初期シード,1つも選ばない場合は1通り
    # dp[0][-(負のxの和)でない] = 0
    dp[0][-minus] = 1
    for j in range(1, len(dp)):
        for t in range(len(dp[0])):
            # print("j:{} dp({},{})".format(j, len(dp), len(dp[0])))
            dp[j][t] = dp[j - 1][t]
            # print("t:{} x[{}]:{}".format(t, j-1, x[j-1]))
            if len(dp[0]) > t - x[j-1] >= 0:
                # print(t - x[j-1])
                dp[j][t] += \
                    dp[j - 1][t - x[j-1]]
    return dp[n][-minus] - 1


n, a = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]
print(func(n, a, x))
"""
print(func(4, 8, [7, 8, 9, 9]) == 5)  # 合計33
print(func(3, 8, [6, 6, 9]) == 0)  # 合計21
print(func(8, 5, [3, 6, 2, 8, 7, 6, 5, 9]) == 19)  # 合計46
print(func(33, 3,
           [3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3])
      == 8589934591)  # 合計46
"""


Measured memory_bytes: 3956
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String ans = "";
    char[] ss = s.toCharArray();
    for (int i=0; i<s.length(); i += 2) {
      System.out.print(ss[i]);
    }
  }
}

Measured memory_bytes: 33192
#include <iostream>
#include <algorithm>

using namespace std;

int pow(int a, int b){
	if((long long)a*a > 1e12) return 1000000000;
	if(b==0) return 1;
	int res = pow(a, b/2);
	res = res*res;
	if(b%2) res *= a;
	return res;
}

int main(){
	int N;
	int A[100];
	while(cin >> N){
		for(int i=0;i<N;i++) cin >> A[i];
		sort(A, A+N);
		int idx = 0;
		int zero = 0, one = 0;
		while(idx<N&&A[idx]<2){
			if(A[idx]==0) zero++;
			if(A[idx]==1) one++;
			idx++;
		}
		int g = -1;
		if(zero%2==1&&one==0&&idx<N) g = A[idx++];
		if(N-2>=idx&&A[N-1]==3&&A[N-2]==2) swap(A[N-1], A[N-2]);
		for(int i=idx;i<N;i++) cout << A[i] << endl;
		if(zero%2==1){
			if(zero==1&&one==0){
				if(g!=-1)
					cout << g << endl << 0 << endl;
				else
					cout << 0 << endl;
			}
			else {
				for(int i=0;i<zero/2*2;i++) cout << 0 << endl;
				if(g!=-1) cout << g << endl;
				if(one > 0) cout << 1 << endl;
				cout << 0 << endl;
				for(int i=0;i<one-1;i++) cout << 1 << endl;
			}
		} else {
			for(int i=0;i<zero;i++) cout << 0 << endl;
			for(int i=0;i<one;i++) cout << 1 << endl;
		}
	}
}

Measured memory_bytes: 0
/*
author : seryu
title : ABC173B_"Judge Status Summary"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define mreps(i,j,n) for(int i = j; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

void solve()
{
	vector<string> judge = {"AC", "WA", "TLE", "RE"};
	vector<int> ans(4, 0);
	int n;
	cin >> n;
	rep(i, n)
	{
		string s;
		cin >> s;
		rep(j, 4)if(s == judge[j])ans[j]++;
	}
	rep(j, 4)cout << judge[j] << " x " << ans[j] << endl;
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 3640
MOD=10**9+7
n,k=map(int,input().split())
def modpow(a, p, mod=MOD):
    # return a**p (mod MOD) O(log p)
    if p==0: return 1
    if p%2==0:
        half = modpow(a, p//2, mod)
        return half*half % mod
    else:
        return a * modpow(a, p-1, mod) % mod

ret=modpow(2,n)
class ModInt:
    def __init__(self, x):
        self.x = x % MOD

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

    __repr__ = __str__

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

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

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

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

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

    __radd__ = __add__

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

    __rmul__ = __mul__

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

    def __rpow__(self, other):
        return (
            ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
            ModInt(pow(other, self.x, MOD))
        )
def comb(x,n):
    divd=1
    for i in range(n):
        divd*=ModInt(x-i)
    for i in range(n):
        divd/=ModInt(i+1)
    return divd
if k<n-1:
    combl_1=[1]*n
    combl_2=[1]*(n+1)
    combl_1[1]=n-1
    combl_2[1]=n
    for i in range(2,n):
        combl_1[i]=ModInt(n-i)*combl_1[i-1]/ModInt(i)
        combl_2[i]=ModInt(n-i+1)*combl_2[i-1]/ModInt(i)
    ans=0
    for i in range(k+1):
        ans+=combl_1[i]*combl_2[i]
    print(ans)
if k>=n-1:
    print(comb(2*n-1,n-1))

Measured memory_bytes: 82064
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e6+3)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;

int main()
{
	ll n;
	cin>>n;
    ll k = 26;
    ll cnt = 1;
    while(n - k > 0)
    {
		n-=k;
		k*=26;
		cnt++;
	}
	k/=26;
	string ans;
	while(cnt--)
	{
		int c = 0;
		while(n-k > 0){
			n-=k;
			c++;
		}
		ans+=c+'a';
		k/=26;
	}
	cout<<ans;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;

ll powmod(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * powmod(a, n - 1, p)) % p;
	long long t = powmod(a, n / 2, p);
	return (t * t) % p;

}
int main() {
	ll n,ans=0;
	cin >> n;
	ans = powmod(10, n, mod) + powmod(8, n, mod) - (powmod(9, n, mod) * 2LL);
	ans %= mod;
	ans = (ans + mod) %mod;
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3604
N = int(input())

ans = [0]*(N+1)

for i in range(1, int(N**0.5)+1):
    for j in range(1, int(N**0.5)+2):
       for k in range(1, int(N**0.5)+2):
            f = i*i + j*j + k*k +i*j + j*k + k*i
            if f <= N:
                ans[f] += 1
print(*ans[1:], sep='\n')


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

int main(){
	int A;
	int B;
	int C;
	int D;
	int mint,minb;
	
	cin>>A;
	cin>>B;
	cin>>C;
	cin>>D;
	
	if(A<B){
		mint=A;
	}else{
		mint=B;
	}
	
	if(C<D){
		minb=C;
	}else{
		minb=D;
	}
	
	cout<<mint+minb<<"\n";
	
	return 0;
	
	
}

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

double heron(double a, double b, double c) {
    double z = (a + b + c) / 2.0;
    return sqrt(z * (z - a) * (z - b) * (z - c));
}

double dist(double x1, double y1, double x2, double y2) {
    return sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
}

int main() {
    vector<double> x, y;
    double tx, ty;
    char c;
    while (cin >> tx >> c >> ty) {
        x.push_back(tx);
        y.push_back(ty);
    }
    double area = 0;
    for (int i=1; i+1<(int)x.size(); ++i) {
        double a = dist(x[0], y[0], x[i], y[i]);
        double b = dist(x[0], y[0], x[i+1], y[i+1]);
        double c = dist(x[i], y[i], x[i+1], y[i+1]);
        area += heron(a, b, c);
    }
    cout.width(6);
    cout << fixed;
    cout << area << endl;
    return 0;
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second

const char kan[][3] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "ld", "mb", "mp", "nc", "nd", "ng", "nt", "nw", "ps", "qu", "cw", "ts"};

int main(){
  int count[40][40] = {};
  int n;
  scanf("%d ", &n);
  REP(i, n){
    char str[1123];
    int conv[1123];
    int len;
    fgets(str, sizeof str, stdin);
    for(int j = 0, k = 0;;){
      if(str[j] == 'l' && str[j + 1] == 'd'){
        conv[k] = 26;
        ++k;
        j += 2;
      }else if(str[j] == 'm' && str[j + 1] == 'b'){
        conv[k] = 27;
        ++k;
        j += 2;
      }else if(str[j] == 'm' && str[j + 1] == 'p'){
        conv[k] = 28;
        ++k;
        j += 2;
      }else if(str[j] == 'n' && str[j + 1] == 'c'){
        conv[k] = 29;
        ++k;
        j += 2;
      }else if(str[j] == 'n' && str[j + 1] == 'd'){
        conv[k] = 30;
        ++k;
        j += 2;
      }else if(str[j] == 'n' && str[j + 1] == 'g'){
        conv[k] = 31;
        ++k;
        j += 2;
      }else if(str[j] == 'n' && str[j + 1] == 't'){
        conv[k] = 32;
        ++k;
        j += 2;
      }else if(str[j] == 'n' && str[j + 1] == 'w'){
        conv[k] = 33;
        ++k;
        j += 2;
      }else if(str[j] == 'p' && str[j + 1] == 's'){
        conv[k] = 34;
        ++k;
        j += 2;
      }else if(str[j] == 'q' && str[j + 1] == 'u'){
        conv[k] = 35;
        ++k;
        j += 2;
      }else if(str[j] == 'c' && str[j + 1] == 'w'){
        conv[k] = 36;
        ++k;
        j += 2;
      }else if(str[j] == 't' && str[j + 1] == 's'){
        conv[k] = 37;
        ++k;
        j += 2;
      }else if(str[j] == '\n'){
        len = k;
        break;
      }else if(str[j] == ' '){
        conv[k] = -1;
        ++k;
        ++j;
      }else{
        conv[k] = str[j] - 'a';
        ++k;
        ++j;
      }
    }
    // REP(j, len) printf("%s ", kan[conv[j]]);
    REP(j, len - 1){
      if(conv[j] != -1 && conv[j + 1] != -1){
        ++count[conv[j]][conv[j + 1]];
      }
    }
  }

  REP(i, 38){
    int index;
    int mx = 0;
    REP(j, 38){
      if(mx < count[i][j]){
        index = j;
        mx = count[i][j];
      }
    }
    if(mx) printf("%s %s %d\n", kan[i], kan[index], mx);
    else printf("%s a 0\n", kan[i]);
  }

  return 0;
}



Measured memory_bytes: 3204
#include<stdio.h>
int main(){
 int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a<=b&&b<=c){
  printf("%d %d %d\n",a,b,c);
}else if(a<=c&&c<=b){
 printf("%d %d %d\n",a,c,b);
}else if(b<=a&&a<=c){
 printf("%d %d %d\n",b,a,c);
}else if(b<=c&&c<=a){
 printf("%d %d %d\n",b,c,a);
}else if(c<=a&&a<=b){
 printf("%d %d %d\n",c,a,b);
}else if(c<=b&&b<=a){ 
 printf("%d %d %d\n",c,b,a);
}
return 0;
}


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

typedef long long ll;

const int MOD = 1e9 + 7 ;
const double PI = 2 * acos(0.0);


int main()
{
  ll n, time, ans = 0 ;
  string s ;
  cin >> n ;
  stack<pair<string, ll> > st ;
  for(int i = 0; i < n; i++) {
    cin >> s >> time ;
    st.push({s, time}) ;
  }
  cin >> s ;
  while(!st.empty()) {
    if(st.top().first == s) break ;
    else {
      ans += st.top().second ;
      st.pop() ;
    }
  }

  cout << ans << endl ;

}


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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T> struct range_add {
  static constexpr T inf = numeric_limits<T>::max() / 2;
  struct node { T delta = 0, min = inf, max = -inf, len = 0, sum = 0; };
  static node op(const node& l, const node& r) {
    return {
      l.delta + r.delta,
      std::min(l.min, l.delta + r.min), std::max(l.max, l.delta + r.max),
      l.len + r.len, l.sum + l.delta * r.len + r.sum
    };
  }
  static node make_node(T a) { return {a, a, a, 1, a}; }
  const int n;
  vector<node> t;
  range_add(const vector<T>& v) : n(v.size() + 1), t(2 * n) {
    for (int i = n - 1; i--; ) t[n + i] = make_node(v[i] - (i ? v[i - 1] : 0));
    for (int i = n; i-- > 1; ) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
  node fold(int l, int r) const {
    node a, b;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) a = op(a, t[l++]);
      if (r & 1) b = op(t[--r], b);
    }
    return op(a, b);
  }
  T get(int i) const { return fold(0, i + 1).delta; }
  T min(int l, int r) const { return get(l - 1) + fold(l, r).min; }
  T max(int l, int r) const { return get(l - 1) + fold(l, r).max; }
  T sum(int l, int r) const { return get(l - 1) * (r - l) + fold(l, r).sum; }
  void set(int i, const node& a) {
    t[i += n] = a;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
  void add(int l, int r, T a) {
    set(l, make_node(t[n + l].delta + a));
    set(r, make_node(t[n + r].delta - a));
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<int> h(n + 1);
  set<int> se;
  for (int i = 0; i < n; ++i) {
    h[i + 1] = h[i];
    if (s[i] == '(') {
      ++h[i + 1];
    } else {
      --h[i + 1];
      se.insert(i);
    }
  }
  range_add<int> ra(h);
  while (q--) {
    int i;
    cin >> i;
    --i;
    if (s[i] == '(') {
      s[i] = ')';
      se.insert(i);
      int j = *begin(se);
      cout << j + 1 << '\n';
      se.erase(j);
      s[j] = '(';
      ra.add(j + 1, i + 1, 2);
    } else {
      if (ra.get(i) == 1) {
        cout << i + 1 << '\n';
        continue;
      }
      se.erase(i);
      s[i] = '(';
      int ng = 0, ok = i;
      while (ok - ng > 1) {
        int mid = (ng + ok) / 2;
        (ra.min(mid, i) > 1 ? ok : ng) = mid;
      }
      int j = ng;
      cout << j + 1 << '\n';
      s[j] = ')';
      se.insert(j);
      ra.add(j + 1, i + 1, -2);
    }
  }
}



Measured memory_bytes: 23152
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define uint unsigned long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) {
    return a / gcd(a, b) * b;
}
int sigma(int n){
    int sum=0;
    for (int i=1; i<=(n); i++){
        sum+=i;
    }
    return sum;
}
int distance(int yo,int xo,int yi,int xi){
    return (yo-yi)*(yo-yi)+(xo-xi)*(xo-xi);
}
signed main(){
    int X;
    cin >> X;
    int i, j;
    int flg ;
    for(i=X;i<X*4;i++){
        flg = 0;
        for(j=2;j<i;j++){
            if(i%j==0){
                flg = 1;
            }
        }
        if(flg==0){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      String S = sc.nextLine();
      if(S.equals("RRS") || S.equals("SRR"))
        System.out.println(2);
      else if(S.equals("RRR"))
        System.out.println(3);
      else if(S.equals("SSS"))
        System.out.println(0);
      else
          System.out.println(1);
              
    }
}

Measured memory_bytes: 35772
import java.util.Scanner

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val k = scn.nextInt()
	val n = scn.nextInt()
	val a0 = scn.nextInt()
	var bef = a0
	var max = 0
	for (i in 2..n){
		val a = scn.nextInt()
		max = (a - bef).coerceAtLeast(max)
		bef = a
	}
	max = (k+a0-bef).coerceAtLeast(max)
	println(k-max)
}

Measured memory_bytes: 71016
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
          ll a,b;
           cin>>a>>b;
           ll cnt[42];
           rep(i,0,42){
             cnt[i]=0;
           }
           if(a%4==2||a%4==3){
             if(b%4==0||b%4==3)cnt[0]++;
           }
           else if(a%4==0||a%4==1){
             if(b%4==1||b%4==2)cnt[0]++;
           }
           rep(i,1,42){//下からi桁目
             if((a/(ll(pow(2,i))))%2){
               cnt[i]+=a% ll(pow(2,i));
               cnt[i]%=2;
               //if(i==0)cout<<cnt[i]<<endl;
             }
           }
                rep(i,1,42){//下からi桁目
             if((b/(ll(pow(2,i))))%2){
               cnt[i]+=b% ll(pow(2,i)) +1;
               cnt[i]%=2;
               if(i==0)cout<<cnt[i]<<endl;
             }
           }
           ll ans=0;
                rep(i,0,42){
                 if(cnt[i])ans+=pow(2,i); 
                }
           cout<<ans<<endl;
}

Measured memory_bytes: 3964
#include <cstdio>
#include <algorithm>

#define N 500
int main(){
    int n;
    std::scanf("%d", &n);

    float p[N + 1];
    float q[N + 1];
    p[0] = 0.f;
    for(int i = 1; i <= n; ++i){
        std::scanf("%f", &p[i]);
    }
    for(int i = 0; i <= n; ++i){
        std::scanf("%f", &q[i]);
    }
    float a[N + 2][N + 2];
    float c[N + 2][N + 2];
    a[1][0] = q[0];
    c[1][0] = q[0];
    for(int i = 1; i <= n; ++i){
        a[i+1][i] = q[i];
        c[i+1][i] = q[i];
        a[i][i] = p[i] + q[i-1] + q[i];
        c[i][i] = p[i] + 2 * (q[i-1] + q[i]);
    }

    for(int l = 2; l <= n; ++l){
        for(int i = 1; i <= n - l + 1; ++i){
            int j = i + l - 1;
            a[i][j] = a[i][j-1] + a[i+1][j] - a[i+1][j-1];
            c[i][j] = 1000.f;
            for(int k = i; k <= j; ++k){
                c[i][j] = std::min(c[i][j], c[i][k-1] + a[i][k-1] + c[k+1][j] + a[k+1][j] + p[k]);
            }
        }
    }

    std::printf("%f\n", c[1][n]);
}



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

int main() {
  ll n;
  cin>>n;
  vector<int> h(n);
  rep(i,n)cin>>h[i];
  string ans="Yes";
  ll cnt=0;
  rep(i,n){
    ll now=h[i];
    if (now>cnt){
      now--;cnt=now;
    }
    else if (now==cnt)continue;
    else if (now<cnt){
      ans="No";break;
    }
    }
    cout<<ans;
  }


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

using namespace std;
#define int long long 
#define N 666666
int arr[N],a[N],b[N];
#define pi 6.28318530717958623200
vector<int> v[N];
signed main(){
	int n;
	cin>>n;
	for(int i=2;i<=n;i++){
		cin>>a[i];
		v[a[i]].push_back(i);
	} 
	for(int i=1;i<=n;i++) cout<<v[i].size()<<'\n';
	return 0;
}



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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define PB push_back

const int INF = (1LL<<30);

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

const int maxh = 35, maxw = 35;
int csum[maxh][maxw];
void init(VVI vec) {
  assert(vec.size());
  REP(i, vec.size()) REP(j, vec[0].size()) {
    if(!i && !j) csum[i][j] = vec[i][j];
    else if(!i) csum[i][j] = csum[i][j-1] + vec[i][j];
    else if(!j) csum[i][j] = csum[i-1][j] + vec[i][j];
    else csum[i][j] = csum[i-1][j] + csum[i][j-1] - csum[i-1][j-1] + vec[i][j];
  }
}
// 閉区間, 0-indexedで矩形範囲の合計
int cumsum(int sx, int sy, int gx, int gy) {
  if(!sx && !sy) return csum[gy][gx];
  if(!sx) return csum[gy][gx] - csum[sy-1][gx];
  if(!sy) return csum[gy][gx] - csum[gy][sx-1];
  return csum[gy][gx] - csum[gy][sx-1] - csum[sy-1][gx] + csum[sy-1][sx-1];
}

int h, w, s;
PII dp[35][35][35][35];
PII func(int sx, int sy, int gx, int gy) {
  if(dp[sx][sy][gx][gy] != PII{-1, -1}) return dp[sx][sy][gx][gy];
  // 分割しなかったとしても条件を満たさない
  if(cumsum(0, 0, w-1, h-1) - cumsum(sx, sy, gx, gy) > s) return {-1, -1};
  // 分割しない
  int group = 1, ret = cumsum(sx, sy, gx, gy);
  // 縦で割る
  FOR(i, sx, gx) {
    PII vl = func(sx, sy, i, gy);
    PII vr = func(i+1, sy, gx, gy);
    if(group < vl.first + vr.first || (group == vl.first+vr.first && ret < min(vl.second, vr.second))) {
      group = vl.first + vr.first;
      ret = min(vl.second, vr.second);
    }
  }
  // 横で割る
  FOR(i, sy, gy) {
    PII vl = func(sx, sy, gx, i);
    PII vr = func(sx, i+1, gx, gy);
    if(group < vl.first + vr.first || (group == vl.first+vr.first && ret < min(vl.second, vr.second))) {
      group = vl.first + vr.first;
      ret = min(vl.second, vr.second);
    }
  }
  return dp[sx][sy][gx][gy] = {group, ret};
}

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

  while(true) {
    cin >> h >> w >> s;
    if(!h) break;
    VVI vec(h, VI(w));
    REP(i, h) REP(j, w) cin >> vec[i][j];

    // 累積和,dp配列の初期化
    init(vec);
    REP(i1, 35) REP(i2, 35) REP(i3, 35) REP(i4, 35) dp[i1][i2][i3][i4] = {-1, -1};

    PII ret = func(0, 0, w-1, h-1);
    cout << ret.first << " " << s - cumsum(0,0,w-1,h-1) + ret.second << endl;
  }

  return 0;
}



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

using namespace std;

int main()
{
    int N;
    cin >> N;
    string s[2];
    for (int i = 0; i < 2; i++) {
        cin >> s[i];
    }

    constexpr int MOD = ((1e9) + 7);
    using ll = long long;

    int i = 0;
    ll ans = 0;
    vector<int> vec; 
    if (s[0][0] == s[1][0]) {
        ans = 3;
        i = 1;
        vec.emplace_back(1);
    } else {
        ans = 6;
        i = 2;
        vec.emplace_back(2);
    }

    for (; i < N; ) {
        if (s[0][i] == s[1][i]) {
            vec.emplace_back(1);
            i++;
        } else {
            vec.emplace_back(2);
            i += 2;
        }
    }

    for (int j = 1; j < (int)vec.size(); j++) {
        if (vec[j - 1] == 1) {
            if (vec[j] == 1) {
                ans *= 2;
            } else {
                ans *= 2;
            }
        } else {
            if (vec[j] == 1) {
                ans *= 1;
            } else {
                ans *= 3;
            }
        }
        ans %= MOD;
    }

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


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

#define ll long long
#define sq(a) (a)*(a)
#define caset int t; cin >> t; while(t--)
#define get1(a) ll int a; cin>>a;

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define line '\n'

#define vi(v)	vector < int > v;
#define	all(v)	v.begin(), v.end()


//#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)   #ifndef ONLINE_JUDGE   freopen("input.txt","r",stdin);		freopen("output.txt","w",stdout); 	#endif


int main() {
//	fast;
    long long int val,mx=0,n,a,b;
    cin>>a>>b>>n;
    if(b<=n)
        cout<<floor(a*(b-1)/b);
    else
    {
        cout<<floor(a*n/b);
    }



return 0;
}



Measured memory_bytes: 3780
#include <iostream>
#include <set>
using namespace std;
int main(){
  int n;cin>>n;
  set<int> ans;
  for(int i = 0; n > i; i++){
    int a;cin>>a;
    if(ans.find(a) == ans.end()){
      ans.insert(a);
    }else{
      ans.erase(a);
    }
  }
  cout << ans.size() << endl;
}

Measured memory_bytes: 4864
#include<stdio.h>
int main(void)
{
	int a[10],i,t,j;
	for(i=0;i<10;i++)
	{
		scanf("%d",&a[i]);
	}
	for(i=0;i<10;i++)
	{
		for(j=i+1;j<10;j++)
		{
			if(a[i]<a[j])
			{
				t=a[i];
				a[i]=a[j];
				a[j]=t;
			}
		}
	}
	for(i=0;i<3;i++){
	printf("%d\n",a[i]);
	}
	return 0;
}

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

using namespace std;

class DisjointSet {
private:
	vector<int> rank, p;
public:
	DisjointSet() {}
	DisjointSet(int n) {
		rank.assign(n, 0);
		p.assign(n, 0);
		for (int i = 0; i < n; i++) p[i] = i;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] > rank[y]) {
			p[y] = x;
		} else {
			p[x] = y;
			if (rank[x] == rank[y]) rank[y]++;
		}
	}

	int root(int x) {
		return p[x]==x?x:p[x]=root(p[x]);
	}
};

int main() {
	int n,k,l; cin >> n >> k >> l;
	DisjointSet dj1(n),dj2(n);
	while(k--) {
		int p,q; cin >> p >> q;
		dj1.unite(p-1,q-1);
	}
	while(l--) {
		int r,s; cin >> r >> s;
		dj2.unite(r-1,s-1);
	}
	map<pair<int,int>,int > cnt;
	for(int i=0;i<n;++i) ++cnt[make_pair(dj1.root(i),dj2.root(i))];
	for(int i=0;i<n;++i) {
		if(i) cout << " ";
		cout << cnt[make_pair(dj1.root(i),dj2.root(i))];
	}
	cout << endl;
	
	return 0;
}

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

int main()
{
	string s;
	int N;
	
	cin >> s;
	N=s.size();
	
	int ans=0;
	int psum=0;
	int gsum=0;
	s='_'+s;
	for(int i=1;i<=N;i++)
	{
		if(psum<i/2)
		{
			psum++;
			if(s[i]=='g')
				ans++;
		}
		else
		{
			gsum++;
			if(s[i]=='p')
				ans--;
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())
graph = [[] for i in range(3 * N)]
for i in range(M):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    graph[u].append(v+N)
    graph[u+N].append(v+2*N)
    graph[u+2*N].append(v)
S, T = map(int,input().split())
S, T = S-1, T-1
visit = [False for i in range(3 * N)]
length = [0 for i in range(3 * N)]
def bfs(v):
    Q = []
    Q.append(v)
    visit[v] = True
    while Q:
        v = Q.pop(0)
        for u in graph[v]:
            if not visit[u]:
                visit[u] = True
                length[u] = length[v] + 1
                Q.append(u)
                #print(u, length[u])
bfs(S)
#print(length)
if visit[T]:
    print(int(length[T] //3))
else:
    print(-1)


Measured memory_bytes: 62304
#include <bits/stdc++.h>
using namespace std;
int main(){
  int M, N, X, Y;
  cin >> M >> N >> X>> Y;
  vector<int> Xs(M);
  vector<int> Ys(N);

  for(int i = 0 ; i < M; i++){
    cin >> Xs.at(i);
  }
  for(int i = 0 ; i < N; i++){
    cin >> Ys.at(i);
  }
  
  sort(Xs.begin(), Xs.end());
  sort(Ys.begin(), Ys.end());
  
  for(int Z = X + 1; Z <= Y; Z++){
    if(Xs.at(M-1) < Z && Z <= Ys.at(0)){
      cout << "No War" << endl;
      return 0;
    }
  }
  
  cout << "War" << endl;
  return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
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);
        Jfen solver = new Jfen();
        try {
            int testNumber = 1;
            while (true)
                solver.solve(testNumber++, in, out);
        } catch (UnknownError e) {
            out.close();
        }
    }

    static class Jfen {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String S = in.next();
            if (S.equals("#")) throw new UnknownError();
            int a, b, c, d;
            a = in.nextInt() - 1;
            b = in.nextInt() - 1;
            c = in.nextInt() - 1;
            d = in.nextInt() - 1;
            String[] Ss = S.split("/");
            StringBuilder[] board = new StringBuilder[Ss.length];
            for (int i = 0; i < Ss.length; i++) {
                board[i] = new StringBuilder();
                for (int j = 0; j < Ss[i].length(); j++) {
                    final char C = Ss[i].charAt(j);
                    if (Character.isDigit(C)) {
                        for (int k = 0; k < C - '0'; k++) {
                            board[i].append('.');
                        }
                    } else {
                        board[i].append(C);
                    }
                }
            }
            final char cbuf = board[a].charAt(b);
            board[a].setCharAt(b, board[c].charAt(d));
            board[c].setCharAt(d, cbuf);
            StringBuilder ans = new StringBuilder();
            for (int i = 0; i < board.length; i++) {
                int cnt = 0;
                for (int j = 0; j < board[i].length(); j++) {
                    if (board[i].charAt(j) == 'b') {
                        if (cnt != 0) {
                            ans.append(cnt);
                        }
                        cnt = 0;
                        ans.append('b');
                    } else {
                        cnt++;
                        if (j + 1 == board[i].length()) {
                            ans.append(cnt);
                            cnt = 0;
                        }
                    }
                    if (i + 1 != board.length && j + 1 == board[i].length()) {
                        ans.append('/');
                    }
                }
            }
            out.println(ans);
        }

    }
}

Measured memory_bytes: 26480
<?php
  $n = trim(fgets(STDIN));
  $min = 9999999999999999999;
  for($i=1; $i<=10**6; $i++){
    if(is_float($n/$i)){
      continue;
    }
    $j = $n/$i;
    $min = min($min,($i-1)+($j-1));
  }
  echo $min."\n";

Measured memory_bytes: 4604
#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(){
    ll n;
    cin >> n;
    priority_queue<double, vector<double>, greater<double>> que;
    rep(i, 0, n){
        double v; cin >> v;
        que.push(v);
    }
    while(true){
        auto p = que.top();
        que.pop();
        auto q = que.top();
        que.pop();
        if(que.empty()){
            cout << (p+q) / 2.0 << endl;
            break;
        }
        que.push((p+q)/2.0);
    }
    return 0;
}

Measured memory_bytes: 3812
#include <stdio.h>
 
int main(void){

	int n = 0 ;
	int m = 0 ;

	int i = 0 ;
	int j = 0 ;

	scanf("%d %d", &n, &m);

	int A[n][m];
	int b[m];
	int c[n];

	for( i = 0 ; i < n ; i++){
		c[i] = 0 ;
	}

	for( i = 0 ; i < n ; i++){
		for( j = 0 ; j < m ; j++){
			scanf("%d", &A[i][j]);
		}
	}

	for( j = 0 ; j < m ; j++){
		scanf("%d", &b[j]);
	}

	for( i = 0 ; i < n ; i++){
		for( j = 0 ; j < m ; j++){
			c[i] += A[i][j] * b[j];
		}
		printf("%d\n" ,c[i]);
	}

	return 0;
}

Measured memory_bytes: 640