akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    string s;
    sf(s);
    if (s[2] == s[3] && s[4] == s[5]) {
        puts("Yes");
    }else puts("No");
    return 0;
}

Measured memory_bytes: 256
def nCr(n, r):
    import math
    return math.factorial(n) // ((math.factorial(n - r) * math.factorial(r)))
MOD = 1000000007

n, k = map(int, input().split())
b, r = k, n-k
for i in range(0, k):
    x = nCr(b - 1,  i) # 青いブロックの分け方
    if r - i < 0:
        print(0)
    else:
        y = nCr(r + 1, r - i)
        print(x * y % MOD)


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long long n, a, b, i, j, k, ans, aa, bb;
	cin >> n >> a >> b;
	if (a > b) ans = 0;
	else if (n == 2) ans = 1;
	else if (n == 1) {
		if (a != b) ans = 0;
		else ans = 1;
	}
	else {
		aa = a * (n - 1) + b;
		bb = b * (n - 1) + a;
		ans = bb + 1 - aa;
	}
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>

int ans(int n){
	for (int i=0; i <= 25; i++){
		if ((n-4*i>=0) and (n-4*i)%7==0) return 1;
	}
	return 0;
}

int main(){
	int n, a, b;
	std::cin >> n;
	if (ans(n)) std::cout << "Yes\n";
	else std::cout << "No\n";
	return 0;
}


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

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;

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

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

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

const i64t MOD = 1000000007;

vector< vector<int> > edg;

int main() {
    int N;
    cin >> N;

    edg = vector< vector<int> >(N+1);
    for (int i = 0; i < N+1; ++i) {
        edg[i] = vector<int>(N+1, -1);
    }

    // set_level(1, 1, 0, N);

    int xor_ij;
    for (int i = 1; i <= N-1; ++i) {
        for (int j = i+1; j <= N; ++j ) {
            xor_ij = i ^ j;
            // printf("DEBUG : %d %d %x\n", i, j, xor_ij);
            for (int k = 1; k < 500; ++k) {
                // printf("DEBUG2 : %d %d\n", xor_ij, xor_ij & (1 << (k-1)));
                if (xor_ij & (1 << (k-1))) {
                    printf("%d", k);
                    break;
                }
            }
            // printf("%d", edg[i][j]);
            if (j != N) { printf(" "); }
        }
        printf("\n");
    }
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
      int p, j, count=0,i,k;
      scanf("%d", &p);
      int ara1[p],ara2[p];
      for(i=0;i<p;i++)
      {
          scanf("%d",&ara1[i]);
          ara2[i]=i+1;

      }
      for(j=0;j<p;j++)
      {
          if(ara1[j]!=ara2[j])
          {
              count++;
          }
          if(count>2)
          {
              printf("NO");
              break;
          }

      }
      if(count==2 || count==0)
      {
          printf("YES");

      }
      return 0;
}


Measured memory_bytes: 1732
#include <iostream>
using namespace std;
 
int main (){
	int P,Q,R,ans = 1,M = 0;
    	cin >> P >> Q >> R;
        if(ans<=P){
          M = 1;
          ans = P;
        }
  		if(ans<=Q){
          M = 2;
          ans = Q;
        }
  		if(ans<=R){
          M = 3;
          ans = R;
        }
  		if(M == 1)
          cout << Q + R;
  		if(M == 2)
          cout << P + R;
  		if(M == 3)
          cout << Q + P;
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> list(2*n);
	for(int i = 0; i < 2 * n; i++){
		cin >> list[i];
	}
	sort(list.begin(), list.end() );
	int ans = 0;
	for(int i =0; i < 2 * n; i+=2){
		ans += list[i];
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
	
typedef long long ll;
typedef unsigned long long ull;
typedef long double db;
	
#define MOD 1000000007
#define mini 18446744073709551615
#define ff first
#define ss second
#define pb push_back
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
	//cin>>T;
	while(T--)
	{
		string s;
		cin>>s;
		int n=s.size();
		if(s[n-1]=='s')
			cout<<s<<"es";
		else
			cout<<s<<"s";
	}
	return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <numeric>
using namespace std;
#define MAX_N 200000

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; }
const long long INF = 1LL << 60;

// Input
int K, N;
int A[MAX_N];

int main() {
  cin >> K >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) cin >> vec.at(i);

  int tmp = vec.at(N-1);
  for (int i = N-1; i > 0; i--) {
    vec.at(i) -= vec.at(i-1);
  }
  vec.at(0) = vec.at(0) + K - tmp;
  sort(vec.begin(), vec.end());
  cout << K - vec.at(N-1) << endl;
}


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

const int N = 200000;
char s[N+5];

int main(){
    int n;
    scanf("%d", &n);
    scanf("%s", s+1);
    int l = 1, r = n, cnt = 0;
    while (l < r){
        while (l <= n && s[l] == 'R') ++l;
        while (r >= 1 && s[r] == 'W') --r;
        if (l < r && l <= n && s[l] == 'W' && r >= 1 && s[r] == 'R'){
            ++l; --r; ++cnt;
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 3940
#include<cstdio>
int n,m;long long f[100005];
long long max(long long a,long long b){return a>b?a:b;}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1,w,v;i<=n;i++)
	{
		scanf("%d%d",&w,&v);
		for(int i=m;i>=w;i--)f[i]=max(f[i],f[i-w]+v);
	}printf("%lld\n",f[m]);
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N, 0);
  for(auto& a : A){
    cin >> a;
  }
  while(M>0){
    sort(A.begin(), A.end());
    int s = lower_bound(A.begin(), A.end(), A.back()/2) - A.begin();
    s = max(s, N-M);
    for(int ii=s; ii<N; ii++){
      A[ii] /= 2;
      M--;
    }
  }
  long long int ans=0;
  for(auto& a : A){
    ans += a;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for(int i = 0; i < n; i++) {
        cin >> y[i];
    }
    auto d1 = 0;
    auto var = 0;
    long a = 0;
    auto d4 = -1;
    for(int i = 0; i < n; i++) {
        d1 += abs(x[i] - y[i]);
        var += pow(abs(x[i] - y[i]),2);
        a += pow(abs(x[i] - y[i]),3);        
        d4 = max(d4, abs(x[i] - y[i]));
    }
    auto d2 = sqrt(var);
    auto d3 = cbrt(a);
    // cout << "a " << a << endl; 

    cout << setprecision(20) << d1 << endl;
    cout << setprecision(20) << d2 << endl;
    cout << setprecision(20) << d3 << endl;
    cout << setprecision(20) << d4 << endl;
    return 0;
}


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

const double PI = acos(-1);

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define MOD 1000000007
#define INF 1000000000

void solve_abc_c() {
	ll n, m;
	ll x;
	ll a;
	string s;
	string s_ans;
	ll l_ans = 0;
	double d_ans = 0;
	
	cin >> s;

	reverse(ALL(s));

	n = s.size() - 1;
	ll d;
	rep(i, pow(2, n)) {
		x = 1;
		d = s[0] - '0';
		l_ans += d;
		rep(j, n) {
			d = s[j + 1] - '0';
			if (((i >> j) & 1) == 1) {
				l_ans += d;
				x = 1;
			}
			else {
				x *= 10;
				l_ans += d * x;
			}
		}
	}

	cout << l_ans << "\n";
}

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

	solve_abc_c();

	return 0;
}


Measured memory_bytes: 4056
a=list(map(int,input().split()))
n=4*int(input())
for i in range(4):
    a[i]=a[i]*(2**(3-i))
h=a[:]
h.sort()
c=0
for i in range(4):
    p=a.index(h[i])
    s=h[i]//(2**(3-p))
    d=n//(8//(2**(3-p)))
    c+=s*d
    n-=d*int(8//(2**(3-p)))
print(c)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,m,c=0;
    cin>>n>>m;
    int d[50]={0};
    rep(i,n){
        int k;
        cin>>k;
        vector<int> a(k);
        rep(j,k){
            cin>>a[j];
            d[a[j]]++;
        }
    }
    rep(i,m+1) if(d[i]==n) c++;
    cout<<c<<endl;
    return 0;
}

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

int n;
vector<vector<int>> tree;
int dp[200005];
int a[200005];
int ans[200005];
int curans;

void doit(int v, int p) {
    int low = 0, high = n + 1;
    int mid;
    while (low + 1 < high) {
        mid = (low + high) / 2;
        if (dp[mid] < a[v]) {
            low = mid;
        } else {
            high = mid;
        }
    }
    low++;
    int orig = dp[low];
    dp[low] = a[v];
    int prevans = curans;
    if (orig == 1 << 30) {
        curans = low;
    }
    ans[v] = curans;
    for (int i = 0; i < tree[v].size(); i++) {
        int u = tree[v][i];
        if (u == p) continue;
        doit(u, v);
    }
    dp[low] = orig;
    curans = prevans;
}

int main() {
    cin >> n;
    tree = vector<vector<int>>(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        tree[u].push_back(v);
        tree[v].push_back(u);
    }
    for (int i = 1; i < 200005; i++) {
        dp[i] = 1 << 30;
    }
    doit(0, -1);
    for (int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int main() {
    //ifstream cin("b.in");

    int n; cin >> n;

    vector<vector<int>> d(n, vector<int> (n, 0));

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            cin >> d[i][j];

    vector<vector<int>> a = d;

    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j)
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);

    if(a != d) {
        cout << "-1\n";
        return 0;
    }
    
    vector<vector<int>> has(n, vector<int> (n, 1));
    
    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) {
                if(k != i and k != j and d[i][k] + d[k][j] == d[i][j]) {
                    has[i][j] = 0;
                }
            }

    long long ans = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < n; ++j)
            ans += d[i][j] * has[i][j];

    cout << ans / 2 << "\n";
}

Measured memory_bytes: 1280
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String[] arr = S.split("");
		
		int count = 1;
		
		for(String s : arr) {
			if (count % 2 == 0) {
				if (s.equals("L") || s.equals("U") || s.equals("D")) {
					
				} else {
					System.out.println("No");
					break;
				}
			} else {
				if (s.equals("R") || s.equals("U") || s.equals("D")) {
					
				} else {
					System.out.println("No");
					break;
				}
			}
			
			if (count == arr.length) {
				System.out.println("Yes");
			}
			count++;
			
		}
		
	}

}


Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;

int main()
{
  int n;
  cin >> n;
  string s = to_string(n);
  int count = 0;
  for(int i = 0; i < s.size(); i++)
  {
    if(s[i] == '2')
    {
      count++;
    }
  }
  cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

const MAX = 10000

func main() {
	var N, T int
	fmt.Scan(&N, &T)

	minCost := MAX
	var c, t int
	for i := 0; i < N; i++ {
		fmt.Scan(&c, &t)
		if t <= T && c < minCost {
			minCost = c
		}
	}

	if minCost == MAX {
		fmt.Println("TLE")
	} else {
		fmt.Println(minCost)
	}
}


Measured memory_bytes: 512
#include<stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;

for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2512
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
 
typedef vector<int> vi;;
typedef vector<ll> vll;

#define l() length()
#define sz() size()
 
#define b() begin()
#define e() end()
#define all(x) x.begin(), x.end()
 
#define pb(i) push_back(i)
#define PB() pop_back()
 
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
#define mp make_pair
#define Fi first
#define Se second
 
const int maxx=1e6+9;
 
// Happy Coding!


void solve(){

    int n;
    cin>>n;
    vi arr(n,0);
    for(int i=1;i<=n;i++){
        cin>>arr[i];
        if(i==1){
            arr[0]=arr[1];
        }
    }
    // sz of array=n+1;
    int sum=arr[n-1];
    for(int i=0;i<n-1;i++){
        arr[i]=min(arr[i],arr[i+1]);
        sum+=arr[i];
    }
    // for(int x:arr){cout<<x<<" ";}cout<<endl;
    cout<<sum<<endl;
}




int main() {
    faster;
    int t=1;
    // cin>>t;
    while(t-->0){
        solve();
    }
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	vector<int> arrmv;
	for(int i=0;i<n;i++){
		int t;cin>>t;
		arrmv.push_back(t);
		}
	int poi=1;
	int ans=0;
	for(int i=0;i<n;i++){
		if(arrmv[i]==poi){
			poi++;
			ans++;
		}
	
	}
	if(ans==0)cout<<-1<<endl;
	else cout<<n-ans<<endl;
	return 0;
}

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

const ll mod = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  list<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (i % 2) {
      a.push_back(x);
    } else {
      a.push_front(x);
    }
  }
  if (n % 2) {
    for (auto i = a.begin(); i != a.end(); i++) {
      cout << *i << " ";
    }
  } else {
    for (auto i = a.rbegin(); i != a.rend(); i++) {
      cout << *i << " ";
    }
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 9848
#include <stdio.h>

int main (void)


{


int a,b,c,i,x;


x=0;


scanf("%d %d %d",&a,&b,&c);


for(i=a;i<=b;i++)


{


if(c%i==0)


{


x=x+1;


}


}


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


return 0;


}

Measured memory_bytes: 596
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define		CH		ch=(getchar())
#define		I64		long long

inline		int		IN(){
	int x=0,f=1;char ch;
	for (CH;ch>'9'||ch<'0';CH) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';CH) (x*=10)+=ch-'0';
	return x*f;
}

int i,j,k,l,n,m,a[1000005],t;
I64 ans;

int main(){
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	ans=1;
	for (i=n;i;i--) if (t==4) break;
		else if (t%2==0) t++;
		else if (a[i]==a[i+1]){
			t++;
			ans*=(I64)a[i];
		}
	if  (t==4){
		printf("%lld",ans);
		return 0;
	}
	puts("0");
}

Measured memory_bytes: 512
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

int main()
{
    init_comb();

    int h, w, a, b;
    std::cin >> h >> w >> a >> b;

    long long ans = 0;
    for (int i = b; i < w; i++) {
        ans += comb(i + (h - 1 - a), i) * comb((w - 1 - i) + (a - 1), a - 1) % mod;
        ans %= mod;
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 12288
#include <stdio.h>
#include <stdint.h>
#define OK 0
#define NG 1
#define MOD 1000000007
  
static char A[100002];
static int64_t memo[100002];

int main(void) {
  int N, M;
  scanf("%d%d", &N, &M);
  for(int i = 0; i < M; i++) {
    int a;
    scanf("%d", &a);
    A[a] = NG;
  }

  memo[0] = 1;
  if(A[1] == OK)
    memo[1] = 1;
  for(int i = 2; i <= N; i++) {
    if(A[i] == NG) {
      memo[i] = 0;
      continue;
    }
    memo[i] = (memo[i-1] + memo[i-2]) % MOD;
  }
  
  printf("%ld\n", memo[N]);
  return 0;
}


Measured memory_bytes: 1024
//AOJ-GRL-1-B
#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;

#define MAX_E 10000
#define MAX_V 10000

//頂点fromから頂点toへのコストcostの辺
struct edge { int from, to, cost; };

edge es[MAX_E];//辺の張り型 : es[i] = edge{from, to, cost}

int dist[MAX_V];//最短距離
int V, E;//Vは頂点数、Eは変数

//s番目の頂点から各頂点への最短距離を求める。また、trueならsからたどりつける負の閉路が存在する。
bool bellman_ford(int s){
    for(int i = 0; i < V; i++) dist[i] = INF;
    int cnt = 0;
    dist[s] = 0;
    while(cnt < V){
        bool update = false;
        for(int i = 0; i < E; i++){
            edge e = es[i];
            if(dist[e.from] != INF && dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                update = true;
            }
        }
        if(!update) break;
        cnt++;
    }
    return (cnt == V);
}

//trueなら負の閉路が存在する
bool find_negative_loop(){
    memset(dist, 0, sizeof(dist));

    for(int i = 0; i < V; i++){
        for(int j = 0; j < E; j++){
            edge e = es[j];
            if(dist[e.to] > dist[e.from] + e.cost){
                dist[e.to] = dist[e.from] + e.cost;
                if(i == V - 1) return true;
            }
        }
    }
    return false;
}

signed main(){
    int r;
    cin >> V >> E >> r;
    int s,t,d;
    REP(i,E){
        cin >> s >> t >> d;
        es[i] = edge{s, t, d};
    }
    if(bellman_ford(r)){
        cout << "NEGATIVE CYCLE" << endl;
    }else{
        REP(i,V){
            if(dist[i] == INF){
                cout << "INF" << endl;
            }else{
                cout << dist[i] << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3128
import sys
# 許容する再帰処理の回数を変更
sys.setrecursionlimit(10**5+10)
# input処理を高速化する
input = sys.stdin.readline
def chmax(a, b):
    """ 最大値を返す関数 """
    if a >= b:
        return a
    else:
        return b
def main():  
    # 入力
    N, M = map(int, input().split())
    # 隣接関係は隣接リストで管理する
    lst_edge = [[] for _ in range(N)]
    for _ in range(M):
        x, y = map(int, input().split())
        # 最初のindexをゼロにする
        lst_edge[x-1].append(y-1)
    # dp[v] := ノードvを始点とした時の有向パスの長さの最大値
    # -1 未訪問で初期化。
    dp = [-1] * N
    # メモ化再帰
    def rec(v):
        # 既に更新済み
        if dp[v] != -1:
            return dp[v]
        ans = 0
        lst_nv = lst_edge[v]
        for nv in lst_nv:
            ans = chmax(ans, rec(nv) + 1)
        dp[v] = ans
        return dp[v]
    
    # 全ての点に対して更新する
    ans = 0
    for v in range(N):
        ans = chmax(ans, rec(v))
    
    print(ans)
main()

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}

void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );

  int s;
  cin>>s;
  vi v(100000,0);
  v[s]=1;
  int ans=0;
  int before=s;
  for(int i=2;;i++){
    int a;
    if(before%2==0)a=before/2;
    else a=3*before+1;
    if(v[a]==1){
      ans=i;
      break;
    }
    v[a]=1;
    before=a;
  }
  
  cout(ans);

  return 0;
}

Measured memory_bytes: 125952
number = int(input())
data = list(map(int, input().split()))
ans = 0

def change(left, right):
    global data, ans
    hiku = min(data[left:right])
    for i in range(left, right):
        data[i] -= hiku
    ans += hiku

def main():
    global data, ans, number
    while 1:
        flg = 0
        if data.count(0) == number:
            break
        for i in range(number):
            if data[i] == 0:
                continue
            for j in range(i, number):
                if data[j] == 0:
                    flg = 1
                    change(i, j)
                    break
                elif j == number -1:
                    flg = 1
                    change(i, j+1)
                    break
            if flg:
                break
    print(ans)

if __name__ == '__main__':
    # a = [1,2,3,4]
    # b = min(a[3:4])
    # print(a[3]-b)
    main()

Measured memory_bytes: 3064
object Main extends App {
  
  val sc = new java.util.Scanner(System.in)
  val s = sc.next()
  var ans = 0
  for ((a, i) <- s.zipWithIndex) {
    if (a == 'R' && (i ==  0 || ans == 0 || s(i - 1) == 'R')) {
      ans += 1
    }
  }
  println(ans)
}

Measured memory_bytes: 55540
def main():
    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    res = 0
    for i in range(0, n):
        r = 0
        for j in range(0, i + 1):
            r += a[j]
        for j in range(i, n):
            r += b[j]
        res = max(res, r)
    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

bool myf(string S){
    if(S.size()%2==1)return false;
    REP(i,S.size()/2){
        if(S[i]!=S[S.size()/2+i])return false;
    }
    return true;
}

signed main(){
    string S;cin>>S;
  	S=S.substr(0,S.size()-1);
    int N=S.size();
    REP(i,N){
        if(myf(S)){
            cout<<S.size()<<endl;
            break;
        }
        S=S.substr(0,S.size()-1);
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  long long money=1000;
  long long result;
  long long l=0;
  long long k=0;
  cin>>N;
  vector<long long> vec(N);
  for(long long i=0;i<N;i++){
    cin>>vec.at(i);
  }
  for(long long i=0;i<N-1;i++){
    
    if(vec.at(i)<vec.at(1+i)){
      
      k+=money/vec.at(i);
      l=money/vec.at(i);
      
      
      money-=l*vec.at(i);
     
      
      
    }
    if(vec.at(i)>vec.at(1+i)){
      money=money+k*vec.at(i);
      result=money;
      k=0;
      
    }
    
  }
  money+=vec.at(N-1)*k;
  if(money<result){
    cout<<result<<endl;
  }
  else{
    cout<<money<<endl;
  }
  
}
    
    
    


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

int main(){
    int n;
    cin >> n ;
    vector <string> s(n);
    rep(i,n) cin >> s[i];
    int m;
    m=0;

    map<string,int> zi;
    rep(i,n){
        zi[s[i]]+=1;
        if (zi[s[i]]>m){
            m=zi[s[i]];
        }
    }


    
    for(auto p:zi){
        if (p.second==m){
            cout << p.first << endl;
        }  
    }

    

    

    return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

#define N 100010

//1-indexed! 1-indexed!
vl bit(N + 1);
int n;

ll sum(int i) {
	ll s = 0;
	while (i > 0) {
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(int i, ll x) {
	while (i <= n) {
		bit[i] += x;
		i += i & -i;
	}
}


int main() {
	string s;
	cin >> s;
	n = s.size();
	int i, j;
	bit.resize(n + 1);
	vi num(26);
	for (i = 0; i < n; i++) {
		num[s[i] - 'a']++;
	}
	int ki = -1;
	for (i = 0; i < 26; i++) {
		if (num[i] % 2) {
			if (ki == -1) {
				ki = i;
			}
			else {
				cout << -1 << endl;
				return 0;
			}
		}
	}
	vi p(n, -1);
	vi cnt(26);
	vi place(n);
	for (i = 0; i < n; i++) {
		int alpha = s[i] - 'a';
		cnt[alpha]++;
		if (alpha == ki) {
			if (cnt[alpha] <= num[alpha] / 2) {
				place[i] = 0;
			}
			else if (cnt[alpha] == num[alpha] / 2 + 1) {
				place[i] = 1;
			}
			else {
				place[i] = 2;
			}
		}
		else {
			if (cnt[alpha] <= num[alpha] / 2) {
				place[i] = 0;
			}
			else {
				place[i] = 2;
			}
		}
	}
	j = 0;
	for (i = 0; i < n; i++) {
		if (place[i] == 0) {
			p[j++] = i;
		}
		else if (place[i] == 1) {
			p[n / 2] = i;
		}
	}
	vi right(26);
	for (i = 0; i < n; i++) {
		right[s[i] - 'a'] = i;
	}
	for (i = 0; i < n / 2; i++) {
		int alpha = s[p[i]] - 'a';
		p[n - 1 - i] = right[alpha];
		for (j = right[alpha] - 1; j >= 0; j--) {
			if (s[j] - 'a' == alpha) {
				right[alpha] = j;
				break;
			}
		}
	}
	for (i = 0; i < n; i++) {
		p[i]++;
	}
	ll ans = 0;
	for (j = 0; j < n; j++) {
		ans += (j - sum(p[j]));
		add(p[j], 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <functional>
#include <utility>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <cassert>

using namespace std;
#define for0(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define forA(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define forD(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define deb(x) cout<< #x << "=" << x <<endl
#define all(a) a.begin(),a.end()
#define re(x) cin>>x
#define readarr(a,n) for0(i,n) cin>>a[i]
#define mod 1000000007
#define INF 1000000000000000003
#define ff first
#define ss second
#define pb push_back 
#define pob pop_back
#define mp make_pair
#define endl "\n"

typedef long long int            ll;
typedef vector<int>              vi;
typedef pair<int, int>           pi;
typedef unordered_map<int, int>  mii;
typedef unordered_map<char, int> mci;
typedef unordered_set<int>       usi;

int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}

void solve(){
	int x,y,z;
	re(x),re(y),re(z);
	swap(x,y);
	swap(x,z);
	cout<<x<<" "<<y<<" "<<z;
}

int main(){

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1; 
    // cin>>t;
    while(t--){
      solve();
    }
    return 0;
}

Measured memory_bytes: 3656
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    k=n-m-1 # merge する回数
    if(k==0):
        print(0)
        return
    if(n<2*k):
        print("Impossible")
        return

    # cost の小さい方から使いたい
    A=[[a,i] for i,a in enumerate(map(int,input().split()))]
    A.sort()
    E=[[] for _ in range(n)]
    for _ in range(m):
        x,y=map(int,input().split())
        E[x].append(y)
        E[y].append(x)

    cnt=0
    col=[None]*n # 連結成分に分解
    def dfs(v)->bool:
        if(col[v] is not None): return False
        col[v]=cnt
        Q=[v]
        while(Q):
            v=Q.pop()
            for nv in E[v]:
                if(col[nv] is not None): continue
                col[nv]=cnt
                Q.append(nv)
        return True

    for v in range(n):
        cnt+=dfs(v)

    # 各連結成分(n-m 個)から1個ずつ選ぶ
    ans=0
    used=[0]*cnt
    for i in range(n):
        a,v=A[i]
        if(not used[col[v]]):
            ans+=a
            used[col[v]]=1
            A[i][0]=INF

    # 残りの頂点から 2k-(n-m) 個選ぶ
    A.sort()
    for a,v in A[:2*k-(n-m)]:
        ans+=a

    print(ans)
resolve()

Measured memory_bytes: 79872
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

void solve() {
	int n;
	cin >> n;
	
	int mn = inf;
	vi p(n);
	for(int i = 0; i < n; i++) cin >> p[i];
	
	int ans = 0;
	for(int i = 0; i < n; i++) {
		mn = min(mn, p[i]);
		if(p[i] == mn) ans++;
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

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

int main(int argc, char const *argv[]) {
  int rooms[4][3][10];
  int n, b, f, r, v;

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        rooms[i][j][k] = 0;
      }
    }
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> b >> f >> r >> v;
    rooms[b - 1][f - 1][r - 1] += v;
  }

  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < 10; k++) {
        cout << " " << rooms[i][j][k];
      }
      cout << "\n";
    }
    if (i != 3)cout << "####################\n";
  }

  return 0;
}

Measured memory_bytes: 3084
/*Huyyt*/
#include<bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll LLmaxn = 2e18;
string a;
int K;
string str[10000000];
int pop = 0;
map<string, int> mp;
int main()
{
        cin >> a;
        cin >> K;
        for (int i = 0; i <= 25 && pop < K; i++)
        {
                for (int j = 0; j < a.size(); j++)
                {
                        if (a[j] == 'a' + i)
                        {
                                string now = "";
                                for (int k = j; k < min((int)a.size(), j + K); k++)
                                {
                                        now += a[k];
                                        if (!mp[now])
                                        {
                                                str[++pop] = now;
                                                //cout<<now<<endl;
                                                mp[now]++;
                                        }
                                }
                        }
                }
        }
        sort(str + 1, str + pop + 1);
        cout << str[K] << endl;
        return 0;
}


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

const int MOD = 1000000007;
const int MAX =200000;

int main() {
  string s;
  string head = "";
  string tail = "";
  int flip = 0;
  int q;
  int t;
  int f;
  string c;
  cin >> s >> q;
  rep(i, q) {
    cin >> t;
    if(t == 1) {
      flip ^= 1;
    } else {
      cin >> f >> c;
      f--;
      if (f ^ flip == 0){
        head += c;
      } else {
        tail += c;
      }
    }
  }
  if(flip){
    swap(head, tail);
    reverse(s.begin(), s.end());
  }
  reverse(head.begin(), head.end());

  cout << (head + s + tail) << endl;
}

Measured memory_bytes: 1348
#include<iostream>
using namespace std;
int main(){
	int a,b,c,x,y;
	cin>>a>>b>>c>>x>>y;
	int a1=min(x*a+y*b,max(x,y)*c*2);
	if(x<y)
		a1=min(a1,x*c*2+(y-x)*b);
	if(x>y)
		a1=min(a1,y*c*2+(x-y)*a);
	cout<<a1<<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);
        ABC128_a solver = new ABC128_a();
        solver.solve(1, in, out);
        out.close();
    }

    static class ABC128_a {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int A = in.nextInt();
            int P = in.nextInt();

            out.println((int) Math.floor(((A * 3) + P) / 2));

        }

    }
}



Measured memory_bytes: 22612
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	auto sz = [](int lev) { return (1LL << (lev + 2)) - 3; };
	auto pt = [](int lev) { return (1LL << (lev + 1)) - 1; };

	auto dfs = [&](auto &&f, int lev, lint i) -> lint {
		
		if (lev == 0) return i >= 1 ? 1 : 0;
		else if (i <= sz(lev - 1) + 1) return f(f, lev - 1, i - 1);
		else return pt(lev - 1) + 1 + f(f, lev - 1, i - (sz(lev - 1) + 2));

	};

	lint N, X;
	cin >> N >> X;

	cout << dfs(dfs, N, X) << "\n";

	return 0;
}

Measured memory_bytes: 256
require 'set'

# ??????: ???????????¢?´¢

# ??£
NB = [
  [2],
  [5, 2],
  [0, 1, 3, 6],
  [2, 7],
  [5],
  [1, 4, 6, 9],
  [2, 5, 7, 10],
  [3, 6, 8, 11],
  [7],
  [5, 10],
  [6, 9, 11, 12],
  [10, 7],
  [10]
]

Y = [0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4]
X = [2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2]

def solve(field)
  queue = []
  queue << [field, 0]
  used = Set.new
  dist = -1
  prev_dist = -1
  until queue.empty?
    f, dist = queue.shift
    return dist if f == [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0]
    d = dist
    13.times do |i|
      next if f[i] == 0
      d += (X[f[i]] - X[i]).abs + (Y[f[i]] - Y[i]).abs
    end
    next if d > 20
    13.times do |i|
      next if f[i] != 0
      NB[i].each do |t|
        f[i], f[t] = f[t], f[i]
        unless used.include? f
          nf = f.clone
          used.add(nf)
          queue << [nf, dist + 1]
        end
        f[i], f[t] = f[t], f[i]
      end
    end
    # p "N: #{prev_dist = dist}" if prev_dist < dist
  end
  return -1 if queue.empty?
  dist
end

loop do
  v = gets.to_i
  break if v == -1
  field = (1..4).map { gets.split(" ").map(&:to_i) }
  res = solve(([[v]] + field).flatten)
  puts (res == -1) ? "NA" : res
end

Measured memory_bytes: 12748
#include <iostream>

using namespace std;

#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int main() {
  string S; cin >> S;
  int counter[2][2] = {{0}};
  int index = 0;
  for (const auto& e : S) {
    ++counter[index][e-'0'];
    ++index;
    index%=2;
  }
  OUT(S.length()-max(counter[0][0] + counter[1][1], counter[0][1] + counter[1][0]));

  return 0;
}


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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int b[M];
  for (int i = 0; i < M; i++) cin >> b[i];

  int a;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < M; j++) {
      cin >> a;
      sum += a * b[j];
    }
    ans += (sum + C > 0);
  }

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


Measured memory_bytes: 256
#include<vector>
#include<list>
#include<algorithm>
#include<numeric>
#include<iostream>
std::vector<std::vector<int>> graph;
std::vector<bool> used;
std::vector<int> order;
std::vector<int> group;
std::vector<std::vector<int>> t;
std::vector<std::vector<int>> rev_graph(graph.size());
void dfs(int i){
    if(used[i]==true){
        return;
    }
    used[i]=true;
    for (auto &&to : graph[i])
    {
        dfs(to);
    }
    order.push_back(i);
}
void rdfs(int idx,int g){
    if(group[idx]!=-1)return;
    group[idx]=g;
    for (auto &&to : rev_graph[idx])
    {
        rdfs(to,g);
    }
    
}
std::vector<std::vector<int>> strongly_connected(){
    used.resize(graph.size());
    fill(used.begin(),used.end(),false);
    group.resize(graph.size());
    rev_graph.resize(graph.size());
    for(int i=0;i<graph.size();i++){
        if(used[i]==false){
            dfs(i);
        }
    }
    for (int i=0;i<graph.size();i++)
    {
        for (auto &&j : graph[i])
        {
            rev_graph[j].push_back(i);
        }
    }
    std::fill(group.begin(),group.end(),-1);
    int g=0;
    reverse(order.begin(),order.end());
    for (auto &&i : order)
    {
        if(group[i]!=-1)continue;
        rdfs(i,g++);
    }
    t.resize(g);
    for(long long i = 0; i < group.size(); i++){
        t[group[i]].push_back(i);        
    }
    return t;
}
int V,E;

int main(){
    std::cin>>V>>E;
    graph.resize(V);
    for(long long i = 0; i < E; i++){
        int tmp1,tmp2;
        std::cin>>tmp1>>tmp2;
        graph[tmp1].push_back(tmp2);
    }
    strongly_connected();
    int Q;
    std::cin>>Q;
    for(long long i = 0; i < Q; i++){
        int tmp1,tmp2;
        std::cin>>tmp1>>tmp2;
        std::cout<<(group[tmp1]==group[tmp2])<<std::endl;
    }
}


Measured memory_bytes: 4652
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    bool chk=false;
    string S,T;
    cin >> S >> T;
    char tmp;
    for(int i=0; i<S.size(); i++)
    {
        if(S==T)
        {
            chk=true;
            break;
        }
        for (int j=0; j<S.size(); j++)
        {
            if(j==0) 
            {
                tmp=T.at(0);
            }
            if(j==S.size()-1)
            {
                T.at(j)=tmp;
                continue;
            }
            T.at(j)=T.at(j+1);            
        }
    }
    if(chk)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3608
N,T = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
ans = 10**10
for c,t in src:
    if t <= T:
        ans = min(ans,c)
if ans == 10**10:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 3316
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>

using namespace std;

typedef long long ll;
typedef pair<double,int> P;

static const double eps = 10e-9;

bool isA(string str){
	if(str.size() >= 1 && str[0] != '>') return false;
	if(str.size() >= 2 && str[1] != '\'') return false;

	int hist[] = {0,0};
	for(int i=2,j=0;i<str.size()-1;i++){
		if(str[i] == '='){
			hist[j]++;
		}
		else if(str[i] == '#') j++;
		else return false;
	}

	if(hist[0] != hist[1]) return false;
	if(hist[0] == 0 || hist[1] == 0) return false;
	if(str[str.size()-1] != '~') return false;

	return true;

}

bool isB(string str){
	if(str.size() >= 1 && str[0] != '>') return false;
	if(str.size() >= 2 && str[1] != '^') return false;

	if(str.size() <= 3) return false;

	string rear = str.substr(2,str.size()-2);

	bool isok=false;
	int i;
	for(i=0;i+1<rear.size();){
		if(rear.substr(i,2) == "Q="){
			isok=true;
			i+=2;
		}
		else break;
	}

	return (i+2 == rear.size() && isok && rear.substr(i,2) == "~~");
}

int main(){
	int n;
	while(~scanf("%d",&n)){
		for(int i=0;i<n;i++){
			string str;
			cin >> str;

			if(isA(str)) cout << "A" << endl;
			else if(isB(str)) cout << "B" << endl;
			else cout << "NA" << endl;
		}
	}
	
}

Measured memory_bytes: 3220
<?php
$X = trim(fgets(STDIN));
//list($m2,$d2) =  explode(" ",trim(fgets(STDIN)));
//$A =  explode(" ",trim(fgets(STDIN)));

$amari = $X % 100;
$syo     = intdiv($X , 100);
$syo = $syo * 5;
if ($amari <= $syo) {
  printf("1\n");
}
else {
  printf("0\n");
}


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


template <typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v){
    if(!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

template <typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &p) {
    out << "[" << p.first << ", " << p.second << "]";
    return out;
}
//---------

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

    ll k;
    ll cur;
    cin >> s >> k;
    rep(i, 0, s.size()){
        if(k <= 0) break;
        cur = 'z' - s[i]+1;
        if(k - cur >= 0 && cur != 26){
            s[i] = 'a';
            k -= cur;
        }
        //cout << "k = " << k << endl;
    }

    k %= 26;
    //cout << s << endl;
    //cout << (char)(s[s.size()-1] + k) << endl;
    if(k > 0)  s[s.size()-1] = (char)(s[s.size()-1] + k);
    cout << s << endl;
}

Measured memory_bytes: 640