akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
  int n,m,a,h,hmax,p,q,i,j,c;
  int x[1001][101];

  while(1){
    for(i=1;i<=1000;i++){
      for(j=1;j<=100;j++){
	x[i][j]=0;
      }
    }
    hmax=0;
    c=1;
    scanf("%d %d %d",&n,&m,&a);
    if(n==0&&m==0&&a==0)break;
    if(m!=0){
      for(i=0;i<m;i++){
	scanf("%d %d %d",&h,&p,&q);
	if(h>hmax)hmax=h;
	x[h][p]=c;
	x[h][q]=c;
	c++;
      }
    }
    for(i=hmax;i>0;i--){
      if(x[i][a]!=0){
	if(a==1&&x[i][a+1]==x[i][a])a++;
	else if(a==n&&x[i][a-1]==x[i][a])a--;
	else if(x[i][a-1]==x[i][a])a--;
	else if(x[i][a+1]==x[i][a])a++;
      }
    }
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 1424
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;


ll x;
ll ans;

int main(){
  cin >> x;
  ans = x / 11 * 2;
  if(x % 11 >= 7) ans+=2;
  else if(x%11 != 0) ans++;
  cout<<ans <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
    int n;
    char s[101];
    int ans=0;

    scanf("%d",&n);

    int i;
    for(i=0;i<n;i++){
        scanf("%c",&s[i]);
      	//printf("%c\n",s[i]);
        if(s[i]=='Y'){
            ans++;
            break;
        }
    }

    if(ans>0){
        puts("Four");
    }else{
        puts("Three");
    }
    return 0;
}

Measured memory_bytes: 128
k = int(input())


def dfs(d, val, all):
    all.append(val)
    if d == 10:
        return
    for j in [-1, 0, 1]:
        add = (val) % 10 + j
        if 0 <= add <= 9:
            dfs(d+1, val*10+add, all)


all = []
for v in range(1, 10):
    dfs(1, v, all)
all.sort()
print(all[k-1])

Measured memory_bytes: 12304
import sys
input = sys.stdin.readline


def main():
    N, K = map(int, input().split())

    if N == K:
        print(0)
    else:
        amari = N % K
        if amari == 0:
            print(0)
        elif abs(amari - K) > amari:
            print(amari)
        else:
            print(abs(amari - K))

if __name__ == "__main__":
    main()

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

int a,b,c;
int cnt1=0,cnt2=0;
int num[100][100];

int main (){
    scanf("%d %d %d",&a,&b,&c);
    puts(a+b>=c?"Yes":"No");
    return 0;
}


Measured memory_bytes: 256
object Main extends App {
	
	override def main(args:Array[String]) = {
		val sc = new java.util.Scanner(System.in)
		
		Iterator.continually(new DataSet(sc.nextInt,sc.nextInt)).
		takeWhile(_.isContinue).foreach(d => println(d.solve))
	}
	
	case class DataSet(val n:Int, val x:Int){
		val isContinue = !( n == 0 && x == 0)

		def solve = {
			var sum:Int = 0
			// i < j < k ??§????????????????????????
			// i ??? x / 3 ????¶??????????
			
			// ??\???(i , j , k) = x ???????????????i????????°??¨?????????
			for(i <- ( 1 to x / 3)){
				 
				// k ?????¨??????????????§?????? k = x - i - j ??§
				// j = i ??¨????????? k = x - i - i - 1???
				// ????????§??¶?´??????¶??¨?????? k ??? n????¶??????????
				val max_k = math.min(x - i*2 - 1, n) 
				
				// j ???????°???¨????????????k????????§????????§
				val min_j = x - i - max_k
				
				if(max_k > min_j){
					// (i , min_j , max_k)
					// (i , min_j + 1 , max_k - 1)
					// (i , min_j + 2 , max_k - 2)
					// ?????????
					// (i , min_j + z , max_k - z)
					// z = (max_k - min_j) / 2
					val z = (max_k - min_j + 1) / 2
					val pattern_jk = z 
					sum += pattern_jk
				}
			}
			sum
		}
	}
}

Measured memory_bytes: 44980
/*************************************************************************
> File Name: test.cpp
> Author: Akira 
> Mail: qaq.febr2.qaq@gmail.com 
************************************************************************/

#include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
#define MST(a,b) memset(a,b,sizeof(a))
#define CLR(a) MST(a,0)
#define Sqr(a) ((a)*(a))
#define ALL(a) a.begin(), a.end()
#define mp make_pair
#define pb push_back
using namespace std;

#define MaxN 200005
#define MaxM MaxN*10
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626
const int mod = 1E9+7;
const double eps = 1e-6;
#define bug cout<<88888888<<endl;
#define debug(x) cout << #x" = " << x << endl;
template<typename T> T abs(T val){return val>0?val:-val;}
inline int max2(int a, int b) {return ((a > b)? a : b);}
inline int min2(int a, int b) {return ((a < b)? a : b);}
inline int max3(int a, int b, int c) {return max2(a, max2(b, c));}
inline int min3(int a, int b, int c) {return min2(a, min2(b, c));}
template <class T> inline void read(T &ret) {char c; ret=0;while((c=getchar())<'0'||c>'9');while(c>='0'&&c<='9') ret=ret*10+(c-'0'),c=getchar();}
template <class T> inline void out(T x) {if(x>9) out(x/10);putchar(x%10+'0');}

char str[MaxN];
int loc[MaxN][26], to[26], cost[MaxN];
void solve()
{
	int len = strlen(str);
	for(int i=0;i<26;i++) to[i] = len+1;
	for(int i=len;i>=0;i--)
	{
		memcpy(loc[i], to, sizeof(to));
		to[str[i-1]-'a'] = i;
	}
	for(int i=len;i>=0;i--)
	{
		cost[i] = len+1;
		for(int j=0;j<26;j++)
		{
			cost[i] = min(cost[i], cost[loc[i][j]]+1);
		}
	}
	int u = 0,v;
	while(u!=len+1)
	{
		for(v=0;v<26;v++)
		{
			if(cost[u]==cost[loc[u][v]]+1) break;
		}
		printf("%c", v+'a');
		u = loc[u][v];
	}
	puts("");
}
int main()
{
	while(~scanf("%s", &str))
		solve();
}


Measured memory_bytes: 21504
N = int(input())
c = 0
Y = 0
for _ in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        c += 1
        if c == 3:
            Y = 1
    else:
        c = 0
if Y:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9172
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int Q = Integer.parseInt(sc.next());

        Map<Integer, List<Integer>> map = new HashMap<>();
        for (int i = 0; i < N - 1; i++) {
            int a = Integer.parseInt(sc.next());
            int b = Integer.parseInt(sc.next());
            List<Integer> l1 = map.getOrDefault(a, new ArrayList<>());
            l1.add(b);
            map.put(a, l1);
            List<Integer> l2 = map.getOrDefault(b, new ArrayList<>());
            l2.add(a);
            map.put(b, l2);
        }

        int[] p = new int[N + 1];
        for (int i = 0; i < Q; i++) {
            int v = Integer.parseInt(sc.next());
            int x = Integer.parseInt(sc.next());
            p[v] += x;
        }

        int[] t = new int[N + 1];
        int parent = 1;
        t[parent] = p[parent];
        Deque<Data> dq = new ArrayDeque<>();
        Data d = new Data();
        d.parent = parent;
        d.children = map.get(parent);
        dq.addLast(d);

        Set<Integer> visited = new HashSet<>();
        visited.add(parent);
        while (!dq.isEmpty()) {
            Data data = dq.pollFirst();
            for (int i : data.children) {
                if (visited.contains(i)) {
                    continue;
                }
                visited.add(i);
                t[i] = t[data.parent] + p[i];
                if (map.containsKey(i)) {
                    Data tmp = new Data();
                    tmp.parent = i;
                    tmp.children = map.get(i);
                    dq.addLast(tmp);
                }
            }
        }

        System.out.println(Arrays.stream(t).skip(1).mapToObj(String::valueOf).collect(Collectors.joining(" ")));

    }

    public static class Data {
        int parent;
        List<Integer> children;
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,k;
	cin>>n>>k;
    int a[n];
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
   
    int dp[n];
    dp[0]=0;
    for(int i=1;i<n;i++)
      dp[i]=INT_MAX;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
            dp[j]=min(dp[j], abs(a[j]-a[i]) + dp[i]);
        }

    }
    cout<<dp[n-1]<<"\n";
    
}

Measured memory_bytes: 4404
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;
 
const double EPS = 1e-9;
const double PI = 3.14159265359;
 
typedef complex<double> P;

typedef long long int li;

int main(){
	int n;

	while(cin >> n, n){
		vector<li> sales(4001);
		queue<int> in;
		int num;
		li tanka, kazu;
		for(int i = 0; i < n; i++){
			cin >> num >> tanka >> kazu;
			if(!sales[num]){
				in.push(num);
			}
			sales[num] += tanka*kazu;
		}

		bool NA = true;
		while(in.size()){
			if(sales[in.front()] >= 1000000){
				cout << in.front() << endl;
				NA = false;
			}
			in.pop();
		}
		if(NA){
			cout << "NA" << endl;
		}
	}

    return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
using namespace std;
//lets try ideone -_-
int n , a , dp[1000100],ans;
int main() {
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		scanf("%d",&a);
		dp[a]=dp[a-1]+1;
	}
	for(int i = 0 ; i < (n<<1) ; i++)ans=max(ans,dp[i]);
	cout << n-ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#import<cstdio>
int main(){int K,i=scanf("%d",&K)-2,n=(K+3)/4*2,j,k;for(printf("%d\n",n);++i<n;puts(""))for(j=-1;++j<n;)printf("%d ",((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1);}

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

#define ll long long

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define alll(it,A) for(it=A.begin();it!=A.end();it++)

#define err1(a) cout<<a<<endl
#define err2(a,b) cout<<a<<" "<<b<<endl
#define err3(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>

const ll N=100005;
const ll M = 1000000007;

ll dp[N];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,w;
    cin>>n>>w;
    rep(i,0,n){
    	ll a,b;
    	cin>>a>>b;
    	repb(j,w,a){
    		dp[j]=max(dp[j],dp[j-a]+b);
    	}
    }
    ll ans=0;
    rep(i,0,w+1)	ans=max(ans,dp[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main()
{
    string s;
    cin >> s;
    int q;
    cin >> q;
    int rev = 0;
    string endd = "";
    string starts = "";
    while(q--)
    {
        int t, f;
        cin >> t;
        if(t == 1)
        {
            rev = 1 - rev;
        }
        else
        {
            char ch;
            cin >> f >> ch;
            if(f == 1)
            {
                if(rev == 0)
                {
                    // s = ch + s;
                    starts = ch + starts;
                }
                else
                {
                    // s = s + ch;
                    endd = endd + ch;
                }
            }
            else
            {
                if(rev == 0)
                {
                    endd = endd + ch;
                    // s = s + ch;
                }
                else
                {
                    starts = ch + starts;
                    // s = ch + s;
                }
            }
        }
    }
    s = starts + s + endd;
    if(rev)
    {
        reverse(s.begin(), s.end());
        cout << s << endl;
    }
    else
    {
        cout << s << endl;
    }
    return 0;
}


Measured memory_bytes: 1512
danmen = input()

down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] < left:
                break
            edge.pop()
            area += pool.pop()

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Measured memory_bytes: 8116
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] suki = new int[m + 1];
		for (int i = 0; i < n; i++) {
			int k = sc.nextInt();
			for (int j = 0; j < k; j++) {
				suki[sc.nextInt()]++;
			}
		}
		int count = 0;
		for (int i = 1; i <= m; i++) {
			if (suki[i] == n) {
				count++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 22356
from math import *
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))

print(sum([abs(x[i]-y[i]) for i in range(n)]))
print(sqrt(sum([(x[i]-y[i])**2 for i in range(n)])))
print(sum([abs(x[i]-y[i])**3 for i in range(n)]) ** (1/3))
print(max([abs(x[i]-y[i]) for i in range(n)]))



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

ll w[100005];
ll v[100005];
ll dp[105][100005];
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, W;
  cin >> n >> W;
  rep(i, n) { cin >> w[i+1] >> v[i+1]; }
  
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= W; ++j) {
      dp[i][j] = dp[i-1][j];
      if (j >= w[i]) {
        dp[i][j] = max(dp[i][j], dp[i-1][j - w[i]] + v[i]);
      }
    }
  }
  cout << dp[n][W] << endl;
  return 0;
}


Measured memory_bytes: 79360
#include <iostream>
#include <string>
#include <cstring>

using namespace std;
int main() {
    string p,s;
    cin >> s;
    cin >> p;
    s+=s;
    for(int i=0;i<s.size();i++){
        if(s.find(p)!=string::npos){
            cout <<"Yes" <<endl;
            break;
        }
        else
            cout << "No" << endl;
        break;
    }
}


Measured memory_bytes: 3164
#include<iostream>
using namespace std;
char evaluate(int,int,int);

int main(){
    int m,f,r;

    cin >> m >> f >> r;

    while ( m > -1 || f > -1 || r > -1 ){
        cout << evaluate(m,f,r) << endl;
        cin >> m >> f >> r;
    }
}

char evaluate(int m,int f,int r){
    char rank;
    int avg;
    avg = (m+f);
    
    if (avg >= 80 ){
        rank= 'A';
    } else if (avg >= 65){
        rank= 'B';
    } else if (avg >= 50){
        rank='C';
    } else if (avg >= 30){
        if(r >= 50){
            rank = 'C';
        } else{
            rank = 'D';
        }
    } else {
        rank = 'F';
    }

    if (m == -1 || f ==-1 ){
        rank = 'F';
    }
    return rank;
}


Measured memory_bytes: 3088
s=list(input())
t=list(input())
ls=len(s)
lt=len(t)
if ls<lt:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt,-1,-1):
  for j in range(i,i+lt):
    if s[j]==t[j-i] or s[j]=="?":
      continue
    else:
      break
  else:
    for k in range(i,i+lt):
      s[k]=t[k-i]
    for l in range(ls):
      if s[l]=="?":
        s[l]="a"
    print(*s,sep="")
    exit()
else:
  print("UNRESTORABLE")


Measured memory_bytes: 3064
import Data.List
import Data.Maybe

readInt :: String -> Int
readInt = read

main = do
 s <- map readInt.words<$>getContents
 putStrLn.unlines.map show $ solve s

solve::[Int]->[Int]
solve (n:s)
 | any (< 0) (shibaku n s) = [0-1]
 | any (<= 0) (create n s) = [0-1]
 | otherwise = reverse $ create n s

create :: Int -> [Int] -> [Int]
create 0 _ = []
create n s = [(maxIndex n s) + 1] ++ create (n-1) (delIx (maxIndex n s) s)

maxIndex::Int->[Int]->Int
maxIndex n s = if null ic then (0-2) else maximum ic where
 ic = findIndices (==0) (shibaku n s)

delIx:: Int->[Int]->[Int]
delIx n s = take n s ++ drop (n+1) s

shibaku n s = zipWith (-) [1..n] s


Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char& ch) {
	string s = "";
	s += ch;
	return "'" + s + "', ";
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cout << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL_DEFINE
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
   
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
typedef pair<int, int> pii;
const int mod = (int) 1000000007; // 998244353;
const int inf = (int) 2e18;

 
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(9);
	#ifdef LOCAL_DEFINE
		freopen("in.txt", "rt", stdin);
	#endif
	
	int n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << '\n';
	
	return 0;
}
 
 
 
 

Measured memory_bytes: 3572
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

int main() {

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

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

	cout << min(N*A, B) << "\n";

	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int,input().split()))
h.append(101)
ans = 0
start = 0
i = 0
while sum(h[:n])!=0:
    if h[i]!=0:
        h[i] -= 1
    if h[i]==0:
        start = i+1    
    if h[i]>=h[i+1] or i==n-1:
        ans += 1
        i = start
        continue
    i += 1
print(ans)

Measured memory_bytes: 9200
from sys import stdin

def main():

    input = stdin.readline

    A,B,M = map(int,input().split())

    a = [0] * A
    b = [0] * B

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

    min_price = min(a) + min(b)

    for _ in range(M):
        ticket = list(map(int,input().split()))
        price = a[ticket[0]-1] + b[ticket[1]-1] - ticket[2]

        min_price = min(min_price,price)

    print(min_price)


if __name__ == "__main__":
    main()

Measured memory_bytes: 19368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

ll a[222222];
ll pref[222222];
ll suf[222222];

void fix(deque<ii> &dq)
{
	while(dq.size()>=2&&dq[0].fi==0&&dq[1].fi==0)
	{
		dq[1].se+=dq[0].se;
		dq.pop_front();
	}
}

ll sub(deque<ii> &dq)
{
	if(dq.empty()) return 0;
	if(dq[0].fi>0)
	{
		dq[0].fi--;
		fix(dq); return 1;
	}
	ll ans = dq[0].se;
	if(dq.size()>=2)
	{
		dq[1].fi--; ans++;
	}
	fix(dq);
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll x = ll(1e18);
	deque<ii> dq;
	for(int i=0;i<n;i++)
	{
		if(i>0) pref[i]=pref[i-1];
		pref[i]++;
		ll curx = a[i];
		ll miny = 0;
		if(curx<=x)
		{
			while(curx*4<=x)
			{
				curx*=4; miny++;
			}
			if(i==0) miny=ll(1e9);
			dq.push_front(mp(miny,1));
			fix(dq);
		}
		else
		{
			ll tmpx=x;
			while(curx>tmpx)
			{
				tmpx*=4; miny++;
			}
			ll cnt=0;
			for(int z=0;z<miny;z++)
			{
				cnt+=sub(dq);
			}
			dq.push_front(mp(0,1));
			fix(dq);
			pref[i]+=cnt*2;
		}
		/*
		for(ii z:dq)
		{
			cerr<<z.fi<<','<<z.se<<' ';
		}
		cerr<<'\n';
		*/
		x=a[i];
	}
	x=ll(1e18); dq.clear();
	for(int i=n-1;i>=0;i--)
	{
		if(i<n-1) suf[i]=suf[i+1];
		ll curx = a[i];
		ll miny = 0;
		if(curx<=x)
		{
			while(curx*4<=x)
			{
				curx*=4; miny++;
			}
			if(i==n-1) miny=ll(1e9);
			dq.push_front(mp(miny,1));
			fix(dq);
		}
		else
		{
			ll tmpx=x;
			while(curx>tmpx)
			{
				tmpx*=4; miny++;
			}
			ll cnt=0;
			for(int z=0;z<miny;z++)
			{
				cnt+=sub(dq);
			}
			dq.push_front(mp(0,1));
			fix(dq);
			suf[i]+=cnt*2;
		}
		x=a[i];
	}
	suf[n]=0;
	ll ans=suf[0];
	for(int i=0;i<n;i++)
	{
		ans=min(ans,pref[i]+suf[i+1]);
	}
	cout<<ans<<'\n';
}


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

using namespace std;
const int nn = 2e5 + 5;

int main() {
	int A, B, T;
	scanf("%d %d %d", & A, & B, & T);
	int ans = 0, awal = A;
	while (awal <= T) {
		ans += B;
		awal += A;
	}	
	printf("%d\n", ans);
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline

N,Q = map(int,readline().split())

G = [[] for i in range(N)]
for i in range(N - 1):
  a,b = map(int,readline().split())
  G[a - 1].append(b - 1)
  G[b - 1].append(a - 1)

P = [0] * N
for i in range(Q):
  p,x = map(int,readline().split())
  P[p - 1] += x
  
ans = [0] * N

stack = []
# 頂点, 親, そこまでの点数
stack.append([0, -1, 0])
while stack:
  v,parent,point = stack.pop()
  point += P[v]
  ans[v] = point
  for child in G[v]:
    if child == parent:
      continue
    stack.append([child, v, point])
  
print(*ans)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const ll MOD = (ll)(1e9 + 7);

/////////////////////////////////////////////////////////////
class ModuloOperator {
 public:
  ll modulo;

  ModuloOperator(ll modulo) { this->modulo = modulo; }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0)
      ret += modulo;
    else
      ret %= modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= modulo;
    return ret;
  }

  ll div(ll a, ll b) { return mul(a, pow(b, modulo - 2)); }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

ll n, k;

ModuloOperator mo(MOD);

int main(void) {
  // Here your code !
  scanf("%lld %lld", &n, &k);

  vector<pair<ll, ll>> s;

  for (ll i = 1; i * i <= n; ++i) {
    s.emplace_back(i, 0LL);
    s.emplace_back(n / i, 0LL);
  }

  sort(s.begin(), s.end());

  s.erase(unique(s.begin(), s.end()), s.end());

  for (int i = 0; i < s.size() - 1; ++i) {
    ll left = n / s[i + 1].first;
    ll right = n / s[i].first;
    s[i].second = right - left;
  }
  s.back().second = 1;

  int m = s.size();

  map<ll, int> factor2ind;
  for (int i = 0; i < m; ++i) {
    factor2ind[s[i].first] = i;
  }

  vector<vector<ll>> dp(k + 1, vector<ll>(m));

  dp[0][factor2ind[n]] = 1LL;

  for (int i = 0; i < k; ++i) {
    for (int j = m - 2; j >= 0; --j) dp[i][j] = mo.add(dp[i][j], dp[i][j + 1]);
    for (int j = 0; j < m; ++j) {
      int coj = factor2ind[n / s[j].first];
      dp[i + 1][j] = mo.add(dp[i + 1][j], mo.mul(dp[i][coj], s[j].second));
    }
  }

  ll ans = 0LL;

  for (int i = 0; i < m; ++i) {
    ans = mo.add(ans, dp[k][i]);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 58668
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::iter::FromIterator;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let k = scan.read::<i64>();
    let h = scan.readn::<i64>(n);
    println!("{}", h.iter().filter(|&&x| x >= k).count());
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int n;
    cin>>n;
    long long sum = 0;
    int maxv = -1000001;
    int minv = 1000001;

    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        sum = sum + a;
        if(a>maxv){
            maxv=a;
        }
        if(a<minv){
            minv=a;
        }
        
    }
    
    cout<<minv<<" "<<maxv<<" "<<sum<<endl;
    
    return 0;
}




Measured memory_bytes: 3116
import itertools

n=int(input())
listposi= []
order = []
for i in range(n):
    tmp = [int(j) for j in input().split()]
    listposi.append(tmp)
    order.append(i)
    
#print(listposi)
olist = list(itertools.permutations(order))
#print(olist)

dist = 0
for test in olist:
    for i in range(n-1):
        sta = test[i]
        gol = test[i+1]
        stax = listposi[sta][0]
        stay = listposi[sta][1]
        golx = listposi[gol][0]
        goly = listposi[gol][1]
        dist += ((stax-golx)**2+(stay-goly)**2)**0.5
print(dist/len(olist))

Measured memory_bytes: 47980
#include <iostream>
#include <vector>
#include <cstring>

int main(void) {
  int N;
  std::cin >> N;

  // 入力の受け取り
  std::vector<int> a(N), b(N), c(N);
  for (int i = 1; i <= N; i++) { // 1-indexで入れる
    std::cin >> a[i] >> b[i] >> c[i];
  }

  // DP
  int dp[100002][3]; // dp[i][j] := i日目にjを選んだ時の幸福度最大値
  memset(dp, 0, sizeof(dp)); // 0で初期化しておく
  
  // 1日目は先に埋めておく
  dp[1][0] = a[1];
  dp[1][1] = b[1];
  dp[1][2] = c[1];

  // DP更新
  for (int i = 2; i <= N; i++) {
    // i日目に0(A)を選んだ時の幸福度最大値
    //  = 前日にB,Cを選んだ時の最大値のmax + i日目にAを選ぶ最大値
    dp[i][0] = std::max(dp[i - 1][1], dp[i - 1][2]) + a[i];

    // i日目に1(B)を選んだ時の幸福度最大値
    dp[i][1] = std::max(dp[i - 1][0], dp[i - 1][2]) + b[i];

    // i日目に2(C)を選んだ時の幸福度最大値
    dp[i][2] = std::max(dp[i - 1][0], dp[i - 1][1]) + c[i];
  }

  // N日目にA,B,Cを選んだ時の最大値の最大値を取る
  int result = std::max(dp[N][0], std::max(dp[N][1], dp[N][2]));
  std::cout << result << std::endl;

  return 0;
}

Measured memory_bytes: 5616
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using tiii = tuple<int,int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
const ll DIV =1e9+7;
//const double PI = M_PI;
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}
#define chmax(a,b) a=max(a,b)

/*Coding Space*/
int main(){
  int n,t; cin >> n >> t;
  int ans = INF;
  rep(i,n){
    int c,tt; cin >> c >> tt;
    if(t >= tt)  ans = min(ans, c);
  }
  if(ans == INF)
    cout << "TLE" << endl;
  else
    cout << ans << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 110
#define MAXW 100001

ll gcd(ll a, ll b) {
    if(a < b) swap(a, b);
    if (b==0) return a;
    return gcd(b, a%b);
}

ll n, W;
ll w[MAXN], v[MAXN];
ll dp[MAXN][MAXW];

int main() {
    cin >> n >> W;
    for(int i=0; i<n; i++) {
        cin >> w[i] >> v[i];
    }

    for(int i=0; i<W; i++) dp[0][i] = 0;

    for(int i=0; i<n; i++) {
        for(int k=0; k<=W; k++) {
            if (k >= w[i]) {
                dp[i+1][k] = max(dp[i][k-w[i]] + v[i], dp[i][k]);
            } else {
                dp[i+1][k] = dp[i][k];
            }
        }
    }

    cout << dp[n][W] << endl;
}


Measured memory_bytes: 80128
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N, M, H, W;
int ans;
string s;

int main() {
    int A, B;
    cin >> A >> B;
    
    int ans = 0;
    chmax(ans, A + A - 1);
    chmax(ans, A + B);
    chmax(ans, B + B - 1);
    write(ans);
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int sign(int x) { return (x > 0) - (x < 0); }
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 cdiv(int a, int b) { return (a - 1 + b) / b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

signed main() {
    int D, T, S;
    cin >> D >> T >> S;
    if (D <= S * T) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
}


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

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

int main()
{
    int n; cin >> n;
    vector<int> a(n), groups;
    rep(i, n) cin >> a[i];

    groups.push_back(a[0]);
    rep(i, n-1){
        int ng = -1, ok = groups.size();
        while(ok - ng > 1){
            int mid = (ng + ok) / 2;
            if(groups[mid] < a[i + 1])
                ok = mid;
            else
                ng = mid;
        }
        if(ok == groups.size())
            groups.push_back(a[i + 1]);
        else
            groups[ok] = a[i + 1];
    }

    cout << groups.size() << endl;
    return 0;
}

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

using namespace std;

int main() {
		string S, T;
		cin >> S >> T;

		vector<int> d1(26, 0);
		for (int i = 0; i < S.size(); i++) {
				if (d1[S[i] - 'a'] == 0) {
						d1[S[i] - 'a'] = T[i];
				} else if (d1[S[i] - 'a'] != T[i]) {
						cout << "No" << endl;
						return 0;
				}
		}

		vector<int> d2(26, 0);
		for (int i = 0; i < T.size(); i++) {
				if (d2[T[i] - 'a'] == 0) {
						d2[T[i] - 'a'] = S[i];
				} else if (d2[T[i] - 'a'] != S[i]) {
						cout << "No" << endl;
						return 0;
				}
		}

		cout << "Yes" << endl;
		return 0;
}


Measured memory_bytes: 776
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);
//aryread!string();
//auto PS = new Tuple!(long,string)[](M);
//x[]=1;でlong[]全要素1に初期化
void main()
{
    auto n = lread();
    string ans = "";
    // writeln(ans);
    // writeln(cast(char)('a' + 25));
    // writeln(cast(char)('a' + n % 26));
    while (n > 0)
    {
        n -= 1;
        ans ~= cast(char)('a' + n % 26);
        n /= 26;
    }
    // writeln(ans);
    foreach_reverse (e; 0 .. (ans.length))
    {
        write(ans[e]);
    }
    writeln();

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}

void arywrite(T)(T a)
{
    a.map!text.join(' ').writeln;
}


Measured memory_bytes: 3680
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,a[20],x[20][20],y[20][20];
  int ch[20],q[20],cnt=0,max=0,fl;
  cin>>n;
  for(int i=0; i<n; i++){
    cin>>a[i];
    for(int j=0; j<a[i]; j++){
      cin>>x[i][j]>>y[i][j];
    }
  }
  
  for(int i=0; i<(1<<n); i++){
    cnt=0;
    for(int j=0; j<n; j++){
      ch[j]=0;
      q[j]=-1;
    }
    for(int j=0; j<n; j++){
      if((i>>j)&1){
	ch[j]=1;
	q[j+1]=1;
      }else{
	q[j+1]=0;
      }
    }
  
    for(int j=0; j<n; j++){
      fl=0;
      if(ch[j]){
	for(int k=0; k<a[j]; k++){
	  if(q[x[j][k]]==1 && y[j][k]==0)fl=1;
	  else if(q[x[j][k]]==0 && y[j][k]==1)fl=1;
	}
	if(fl==0){
	  cnt++;
	}else{
	  cnt=0;
	  break;
	}
      }

    }
    if(cnt>max){
      max=cnt;
    }
  }
  
  cout<<max<<'\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long gcd(long long x, long long y) {
  while (y != 0) {
    long long r = x % y;
    x = y;
    y = r;
  }
  return x;
}

long long lcm(long long x, long long y) {
  return x/gcd(x, y)*y;
}

int main() {
  long long a, b; cin >> a >> b;
  cout << lcm(a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())

S = []
for _ in range(n):
    s = list(input())
    s.sort()
    S.append("".join(s))
S.sort()

C = []
c = 1
for i in range(n - 1):
    if S[i] == S[i + 1]:
        c += 1
    else:
        C.append(c)
        c = 1
C.append(c)

ans = 0
for c in C:
    ans += c * (c - 1) // 2

print(ans)


Measured memory_bytes: 11252
n,k,x = map(int,input().split())
ll = [list(map(int,input().split())) for _ in [0]*n]
costl = []
for i in range(2**n):
  fmt = '0'+str(n)+'b'
  s = format(i, fmt)
  suml = [0]*len(ll[0])
  for i in range(n):
    if s[i] == '1':
      for j in range(len(suml)):
        suml[j] += ll[i][j]
  if x<= min(suml[1:]):
    costl.append(suml[0])
print(min(costl) if len(costl)>0 else -1)

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


int main() {
	
	int N;
	cin >> N;
	int i=0;
	while(1){
		if(N < pow(2,i)) break;
		i++;
	}
	cout << pow(2,i-1) << endl;
	
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
const int MOD=1e9+7;
struct mint{int x;mint(int x=0):x(x){}};
inline mint operator+  (mint a,mint b){return a.x+b.x<MOD?a.x+b.x:a.x+b.x-MOD;}
inline mint operator-  (mint a){return MOD-a.x;}
inline mint operator-  (mint a,mint b){return a+-b;}
inline mint operator*  (mint a,mint b){return 1LL*a.x*b.x%MOD;}
inline mint operator<< (mint x,int y){mint r=1;for(;y;y>>=1,x=x*x)if(y&1)r=r*x;return r;}
inline mint operator~  (mint x){return x<<MOD-2;}
inline mint operator/  (mint a,mint b){return a*~b;}
inline mint&operator+= (mint&a,mint b){return a=a+b;}
inline mint&operator-= (mint&a,mint b){return a=a-b;}
inline mint&operator*= (mint&a,mint b){return a=a*b;}
inline mint&operator<<=(mint&x,int y){return x=x<<y;}
inline mint&operator/= (mint&a,mint b){return a=a/b;}
#define MN 141
char s[MN+5];
mint F[MN+5],R[MN+5],ans;
int n,a[MN+5],an,b[MN+5],bn,c[MN+5],u[MN+5],p[MN+5];
inline mint C(int n,int m){return F[n]*R[m]*R[n-m];}
void dfs(int x,int y,int z,int s0)
{
	int i,j,k;
	memset(u,0,sizeof(u));
	for(i=j=1;i<z;u[a[i++]]=1)if(p[z-i])
	{
		while(j<=bn&&b[j]<a[i])++j;
		if(j>bn)break;
		u[c[i]=b[j++]]=1;
	}
	if(i==z)for(i=j=1;i<z;++i)
	{
		for(k=1;k<p[z-i];++k)
		{
			while(s[j]&&(j<c[i]||u[j]))++j;
			if(!s[j++])break;
		}
		if(k<p[z-i])break;
	}
	if(i==z)
	{
		mint s=F[z-1];
		for(i=1;i<z;s*=R[j-i],i=j)for(j=i;j<z&&p[i]==p[j];++j);
		ans+=s*C(n+2*(z-1-s0),2*(z-1+x));
	}
	if(z<=an)for(;x+y<=an+bn-z&&x+y+s0+!y<=n/2;++y)dfs(x+y,p[z]=y,z+1,s0+!y);
}
int main()
{
	int m,i;
	scanf("%d%d%s",&n,&m,s+1);++n;
	for(F[0]=i=1;i<=MN;++i)F[i]=F[i-1]*i;
	for(R[i=MN]=~F[MN];i--;)R[i]=R[i+1]*(i+1);
	for(i=1;i<=m;++i)(s[i]=='r'?a[++an]:b[++bn])=i;
	dfs(0,0,1,0);
	printf("%d",ans);
}

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

using namespace std;

typedef long long ll;
const int INF = numeric_limits<int>::max()/2;
const int MOD = 1e9+7;

// a^b
ll mypow(ll a, ll b) {
    if (b == 0) return 1;
    ll tmp = mypow(a, b / 2);
    if (b % 2) return (((tmp*tmp) % MOD)*a) % MOD;
    else return (tmp*tmp) % MOD;
}

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

    ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
    // dp[i][j] := i 人以下のグループのみで j 人使う
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    dp[0][0]=1;
    vector<ll> fact(n+1), inv(n+1);
    fact[0]=1;
    inv[0] =1;
    for(ll i=1;i<=n;i++){
        fact[i]=fact[i-1]*i;
        fact[i] %= MOD;
        inv[i] = mypow(fact[i],MOD-2);
    }
    vector<vector<ll>> p(n+1,vector<ll>(n+1));
    for(ll i=1;i<=n;i++){
        p[i][1]=i;
        for(ll j=2;j<=i;j++){
            p[i][j] = p[i][j-1] * (i-j+1);
            p[i][j] %= MOD;
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            dp[i][j] += dp[i-1][j];
            dp[i][j] %= MOD;
            if(i<a || b<i) continue;
            for(int k=c;k<=d;k++){
                if(j-i*k<0) break;
                ll tmp = dp[i-1][j-i*k];
                tmp *= p[n-j+i*k][i*k]; tmp %= MOD;
                tmp *= inv[k]; tmp %= MOD;
                tmp *= mypow(mypow(fact[i],k),MOD-2); tmp %= MOD;
                dp[i][j] += tmp; dp[i][j] %= MOD;
            }
        }
    }
    cout<<dp[b][n]<<endl;
    return 0;
}

Measured memory_bytes: 18048
#include <stdio.h>
#include <string>
#include <iostream>

using namespace std;


int main (void)
{
	string A;
	
	int N,K;
	
	scanf("%d%d",&N,&K);
	cin>>A;
	
	K-=1;
	if(A[K]=='A')
	{
		A[K]='a';
	}
	else if(A[K]=='B')
	{
		A[K]='b';
	}
	else if(A[K]=='C')
	{
		A[K]='c';
	}

	cout<<A<<endl;




return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long p(long n,long x){
    if(n==0&&x==1) return 1;
    if(x==1) return 0;
    if(2<=x&&x<=pow(2,n+1)-2) return p(n-1,x-1);
    if(x==pow(2,n+1)-1) return pow(2,n);
    if(pow(2,n+1)<=x&&x<=pow(2,n+2)-4) return pow(2,n)+p(n-1,x-pow(2,n+1)+1);
    if(x==pow(2,n+2)-3) return pow(2,n+1)-1;
}
int main(){
  long n,x;
  cin >> n >> x;
  cout << p(n,x) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,L;
  cin>>N>>L;
  if(0<=L)
    cout<<L*N+N*(N-1)/2-L<<endl;
    else{
    if(0<=L+N-1)
      cout<<L*N+N*(N-1)/2<<endl;
      
      else
      cout<<L*N+N*(N-1)/2-L+1-N<<endl;
    }
return 0;
}

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

const int mod = 1e9+7;
struct mint {
    ll x;
    mint(ll x = 0) : x(x % mod){}
    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint &operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint &operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint &operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
};

mint c[4005][4005];
void init() {
    c[0][0] = 1;
    for (int i = 0; i <= 4000; i++) {
        for (int j = 0; j <= i; j++) {
            c[i+1][j] += c[i][j];
            c[i+1][j+1] += c[i][j];
        }
    }
}
mint comb(int n, int k) {
    return c[n][k];
}

int main() {
    init();
    int n, k;
    cin >> n >> k;
    rep(i,k) {
        mint red = comb(k-1,i);
        mint blue = comb(n-k+1,i+1);
        mint ans = red.x * blue.x;
        printf("%lld\n",ans.x);
    }
    return 0;
}

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

#define REP(i,n) for(int i=0,_n=(int)(n); i < _n; i++)

typedef long long ll;
const ll MOD = 1000000007;

int nextInt() {
  int x; scanf("%d", &x); return x;
}

int main2() {
  ll A = nextInt();
  ll B = nextInt();
  ll C = nextInt();

  const int LIMIT = 1000;
  int ans = 0;
  for (; ans < LIMIT; ++ans) {
    if (A % 2 == 1) break;
    if (B % 2 == 1) break;
    if (C % 2 == 1) break;
    ll a = (B + C) / 2;
    ll b = (C + A) / 2;
    ll c = (A + B) / 2;
    A = a;
    B = b;
    C = c;
  }
  if (ans >= LIMIT) ans = -1;
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> a(N);
    for(int i=0; i<N; i++) cin >> a[i];

    int cnt = 0;
    bool flg = true;
    while(true){
        for(int i=0; i<N; i++){
            if(a[i]%2 == 0){
                cnt++;
                a[i] /= 2;
            }
            else{
                flg = false;
                break;
            }
        }
        if(!flg) break;
    }

    cout << cnt/N << endl;
}

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

using namespace std;

long long mask = 0;

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

    int n; cin >> n;
    long long arr[n]; for(auto &i : arr) cin >> i;
    for(auto i : arr) mask ^= i; mask = ~mask;
    sort(arr, arr + n, [](long long x, long long y){return (x&mask) > (y&mask);});

    vector<long long> root;
    for(auto i : arr)
    {
        for(auto j : root)
            if((i&mask) > ((i^j)&mask)) i = i^j;
        if(i&mask) root.push_back(i);
    }

    long long ans = 0;
    for(auto i : root)
    {
        if((ans&mask) < ((ans^i)&mask))
            ans = ans^i;
    }

    cout << ans + (~mask ^ ans);
    return 0;
}


Measured memory_bytes: 1152
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main()
{
    ll n;
    cin >> n;
    vector<vector<ll>> a(n,vector<ll>(n));
    vector<ll> bitcnt((1LL<<n));
    rep(i,n){
        rep(j,n){
            cin >> a[i][j];
        }
    }
    vector<ll> dp((1LL<<n));
    dp[0]=1;
    for(ll s=1;s<(1LL<<n);s++){
        bitcnt[s]=bitcnt[s/2]+s%2;
        for(ll l=0;l<n;l++){
            if((s>>l)%2==1LL){
                dp[s]+=dp[s&~(1LL<<l)]*a[bitcnt[s]-1][l];
                dp[s]%=mod;
            }
        }
    }
    cout << dp[(1LL<<n)-1] << endl;
    return 0;
} 

Measured memory_bytes: 33024