akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{


    public static void Main(string[] args)
    {
        var N = LnInt();
        var _ = LnLngs();
        var resu = 1L;
        _ = _.OrderBy(x => x).ToArray();
        foreach(var i in _)
        {
            if (Log10(resu) + Log10(i) > 18) { print(-1);return; }
            resu *= i;
        }
        print(resu>(long)Pow(10,18)?-1:resu);
    }


    public static long SumAtoB(long a, long b) { var length = b - a + 1; return (a + b) * (length / 2) + (length % 2 == 1 ? (a + b) / 2 : 0); }
    public static long PowLite(long n, long p, long mod = (long)1e9 + 7) { long ans = 1; long now = n; for (; p > 0; p >>= 1) { if ((p & 1) == 1) { ans *= now; ans %= mod; } now *= now; now %= mod; } return ans; }
    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
    public static List<T[]> AllPermutation<T>(params T[] array) where T : IComparable { var a = new List<T>(array).ToArray(); var res = new List<T[]>(); res.Add(new List<T>(a).ToArray()); var n = a.Length; var next = true; while (next) { next = false; int i; for (i = n - 2; i >= 0; i--) { if (a[i].CompareTo(a[i + 1]) < 0) break; } if (i < 0) break; var j = n; do { j--; } while (a[i].CompareTo(a[j]) > 0); if (a[i].CompareTo(a[j]) < 0) { var tmp = a[i]; a[i] = a[j]; a[j] = tmp; Array.Reverse(a, i + 1, n - i - 1); res.Add(new List<T>(a).ToArray()); next = true; } } return res; }
}




Measured memory_bytes: 44796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define tsolve int t;cin>>t;while(t--)  solve();
#define f(i,n)   for(int i=0;i<n;i++)
#define ff first
#define all(a) a.begin(),a.end()
#define ss second
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pi>
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,k;
    cin>>n>>k;
    vi a(n);
    f(i,n)  cin>>a[i];
    multiset<ll,greater<ll>> se;
    f(i,n){
        ll su=0;
        for(int j=i;j<n;j++){
            su+=a[j];
            se.insert(su);
        }
    }
    // ll x=*se.begin();
    // auto it=se.begin();
    // it++;
    // k--;
    // while(k--){
    //     x=x&(*it);
    //     it++;
    // }
    // cout<<x;
    vector<ll> v(all(se));
    int m=v.size();
    long long ans=0;
    bool vt[m];
    memset(vt,true,sizeof(vt));
    for(int i=63;i>=0;i--){
        int c=0;
        for(int j=0;j<m;j++)
        {
            if(vt[j])
            {
                if(v[j]&(1ll<<i))
                {
                    c++;
                    }
            }
        }
        if(c<k) {continue;}
        ans=ans|(1ll<<i);
        for(int j=0;j<m;j++)
        {
            if(vt[j] && !(v[j]&(1ll<<i))) vt[j]=false;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 28160
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

// http://techtipshoge.blogspot.com/2013/09/lca.html



enum class Tn{
	black = 0,
	white = 1,
	any
};


int main() {
	int N;
	cin >> N;
	vector<vector<pair<int,int>>>G(N);
	for (int i = 0; i < N-1; i++) {
		int x, y, m;
		cin >> x >> y >> m;
		x--, y--;
		G[x].push_back(make_pair(y, m%2));
		G[y].push_back(make_pair(x, m%2));
	}
	int root = 0;
	vector<int> ans(N,-1);
	queue<pair<int,int>>q;
	for (int i = 0; i < G[root].size(); i++) {
		q.push(G[root][i]);
	}
	ans[root] = 0;
	while (!q.empty()) {
		auto now = q.front();
		q.pop();
		ans[now.first] = now.second % 2;
		for (int i = 0; i < G[now.first].size(); i++) {
			if (ans[G[now.first][i].first] == -1) {
				q.push(make_pair(G[now.first][i].first, ans[now.first] + G[now.first][i].second));
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] << "\n";
	}
	return 0;
}



Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main() {
    int n;
    cin >> n;
    cout << n*n << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
  int n;
  cin>>n;
  vector<vector<int>> a(n+1,vector<int>(n+1,n));
  vector<vector<int>> used(n+1,vector<int>(n,0));
  FOR(i,0,n){
    FOR(j,0,n-1){
      cin>>a[i][j];
      a[i][j]--;
    }
    a[i][n-1]=i;
    a[i][n]=i;
  }
  vector<int> idx(n,0);
  vector<int> bf(n,0);
  vector<int> date(n,0);
  int cnt=0;
  queue<array<int,2>> q;
  queue<array<int,2>> q2;
  priority_queue<array<int,2>> stay;
  FOR(i,0,n){
    int t=a[i][0];
    if(a[t][0]==i&&used[i][t]==0){
      q.push({i,t});
      used[i][t]=used[t][i]=1;
    }else{
      stay.push({-0,i});
    }
  }
  cerr<<q.size()<<endl;
  FOR(d,0,1000010){
    cnt++;
    if(q.empty()){
      q=queue<array<int,2>>(q2);
      q2=queue<array<int,2>>();
    }
    while(q.size()){
      auto pr=q.front();
      q.pop();
      if(date[pr[0]]==cnt||date[pr[1]]==cnt){
        //cerr<<"err:"<<pr[0]<<" "<<pr[1]<<endl;
        q2.push(pr);
      }else{
        //cerr<<cnt<<" pr:"<<pr[0]+1<<" "<<pr[1]+1<<endl;
        idx[pr[0]]++;
        idx[pr[1]]++;
        date[pr[0]]=date[pr[1]]=cnt;
        int t[2]={};
        t[0]=a[pr[0]][idx[pr[0]]];
        t[1]=a[pr[1]][idx[pr[1]]];
        //cerr<<cnt<<" pr:"<<pr[0]+1<<" "<<pr[1]+1<<" "<<t[0]+1<<" "<<t[1]+1<<endl;
        FOR(i,0,2){
          if(t[i]==pr[i]){

          }else{
            if(a[t[i]][idx[t[i]]]==pr[i]&&used[pr[i]][t[i]]==0){
              //cerr<<"nx:"<<pr[i]+1<<" "<<t[i]+1<<endl;
              q2.push({pr[i],t[i]});
              used[pr[i]][t[i]]=used[t[i]][pr[i]]=1;
            }
          }
        }
        //cerr<<cnt<<" pr:"<<pr[0]<<" "<<pr[1]<<endl;

      }
    }

    if(q.size()==0&&q2.size()==0)break;
  }
  FOR(i,0,n){
    if(idx[i]!=n-1){
      cout<<-1<<endl;
      return 0;
    }
  }
  cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
using namespace std;

typedef long long ll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 or b % 3 == 0 or (a + b) % 3 == 0) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
	return 0;
}


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

#define iso ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll int
#define pll pair<ll,ll>
#define mod 1000000007

int main(){
	int h,w,k,i,j,maskr,maskc,black,ans=0;

	cin>>h>>w>>k;
	vector<vector<char>> a(h,vector<char>(w));

	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>a[i][j];
		}
	}

	for(maskr = 0; maskr <= (1<<h)-1 ; maskr++){
		for(maskc = 0;maskc <= (1<<w)-1 ; maskc++){
			black = 0;
			for(i=0;i<h;i++){
				for(j=0;j<w;j++){
					if((maskr&(1<<i))==0 && (maskc&(1<<j))==0 && a[i][j]=='#')
						black++;
				}
			}
			if(black==k)
				ans++;
		}
	}

	cout<<ans<<endl;

}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int a,b,c,d, A[100], B[100], C[100][100], D[100][100][100];
string s, t, r;




int main(){
	cin >> a >> b >> c >> d;
	int e = min(a,b) + min(c,d);
	cout << e << endl;
	return 0;
}

Measured memory_bytes: 256
n=gets.to_i
s=gets.split.map &:to_i
ans=0
for i in 0..n-3
  if [s[i],s[i+1],s[i+2]].min !=s[i+1] && [s[i],s[i+1],s[i+2]].max !=s[i+1]
    ans+=1
  end
end
puts ans


Measured memory_bytes: 14140
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>

using namespace std;

long long MOD = 1e9 + 7;

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

    //int n, k;
    //cin >> n >> k;

    std::string s;
    cin >> s;

    if (s == "Sunny") {
        cout << "Cloudy" << endl;
    }
    if (s == "Cloudy") {
        cout << "Rainy" << endl;
    }

    if (s == "Rainy") {

        cout << "Sunny" << endl;
    }

    
    return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n;
  string s;
  cin >> n >> s;
  int cnt = 0;
  rep(i,n) {
    if(s[i] == ')') {
      if(cnt) cnt--;
      else cout << '(';
    }
    else cnt++;
  }
  cout << s;
  reverse(all(s));
  cnt = 0;
  rep(i,n) {
    if(s[i] == '(') {
      if(cnt) cnt--;
      else cout << ')';
    }
    else cnt++;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
    int cnt = 0;
    int sum = 0;
    int n,m;
    cin >> n >> m;
    int a[n];
    for(int i=0;i<n;i++){cin >> a[i];sum+=a[i];}
    for(int i=0;i<n;i++)if(4*m*a[i]>=sum)cnt++;
    if(cnt>=m)cout << "Yes" << endl;
    if(cnt<m)cout << "No" << endl;
    
    return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  int N;
  if ( a == b && b == c){
    N = 1;
  }
  else if ( a == b && a != c ){
    N = 2;
  }
  else if ( b == c && a != b){
    N = 2;
  }
  else if ( a == c && a != b){
    N = 2;
  }
  else {
    N= 3;
  }
  
  cout << N ;
}


Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
    
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.find(self.par[x])
    
    def same_check(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else: self.par[y] = x
        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1

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

ans = 0
for i in range(M):
    path = UnionFind(N)
    for j in range(M):
        if j != i:
            path.union(a[j], b[j])
    flag = True
    for j in range(N):
        for k in range(j, N):
            if not path.same_check(j, k):
                flag = False
    if not flag:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll X, Y;
    cin >> X >> Y;
    if (abs(X-Y) <= 1) {
        cout << "Brown\n";
    } else {
        cout << "Alice\n";
    }
}

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

int dp[2][(1<<24)];
string s[501];
int n,m;
bool a[501][501];
 
int main(){
  while(cin>>n>>m,n|m){
    for(int i=0;i<n;i++){
      cin>>s[i];
      for(int j=0;j<m;j++){
        a[i][j]=(s[i][j]=='1');
      }
    }
    if(n<=m){
      int ans=0;
      for(int i=0;i<(1<<n);i++){
        if(ans>=__builtin_popcount(i))continue;
        bool ok=1;
        for(int j=0;j<m;j++){
          int cont=0;
          for(int k=0;k<n;k++){
            if(a[k][j] && i&(1<<k))cont++;
          }
          if(cont&1){ok=0;break;}
        }
        if(ok)ans=max(ans,__builtin_popcount(i));
      }
      cout<<ans<<endl;
    }else{
      int list[501];
      fill(list,list+n,0);
      for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
          if(a[i][j]){
            list[i]=list[i]|(1<<j);
          }
        }
      }
      for(int i=0;i<2;i++)for(int j=0;j<(1<<m);j++)dp[i][j]=-1;
      dp[0][0]=0;
      for(int i=0;i<n;i++){
        for(int j=0;j<(1<<m);j++)dp[(i+1)&1][j]=-1;
        for(int j=0;j<(1<<m);j++){
          if(dp[i&1][j]==-1)continue;
          dp[(i+1)&1][j^list[i]]=max(dp[(i+1)&1][j^list[i]],dp[i&1][j]+1);
          dp[(i+1)&1][j]=max(dp[(i+1)&1][j],dp[i&1][j]);
        }
      }
      cout<<dp[n&1][0]<<endl;
    }
  }
}


Measured memory_bytes: 19864
#include <iostream>

using namespace std;
int main(){
        int N,c=0;
        char S[50];
        cin>>N;
        for(int i=0;i<N;i++){
            cin>>S[i];
        }
        for(int i=0;i<N;i++){
            if(S[i]=='A'&& S[i+1]=='B'&& S[i+2]=='C' )
                c+=1;

        }
        cout<<c;

    return 0;
}

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

int a, b, x;
int main()
{
	cin >> a >> b >> x;
	double pi = acos(-1.0);
	if (a * a * b < x * 2) {
		printf("%.9f", atan(2.0 * (a * a * b - x) / (a * a * a)) / pi * 180);
	} else {
		printf("%.9f", 90 - atan(2.0 * x / (b * b * a)) / pi * 180);
	}
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

struct struct_0_ {;;;
    int m_0;;
    int m_1;;
};;;
bool comp_klst_(const struct_0_& a, const struct_0_& b){;;;
    if(a.m_0 != b.m_0){;;;;
        return (a.m_0 < b.m_0);;
    };;;;
    if(a.m_1 != b.m_1){;;;;
        return (a.m_1 < b.m_1);;
    };;;;
    return (1);;
};;;
bool comp_klst_0_(const struct_0_& a, const struct_0_& b){;;;
    return (a.m_0 < b.m_0);;
};;;
bool comp_klst_1_(const struct_0_& a, const struct_0_& b){;;;
    return (a.m_1 < b.m_1);;
};;;
;;

int main(){
  ;;
    int n, m;
    cin >> n >> m;
    ;
    vector<struct_0_> klst;;
    for(int i = 0; i <  m; ++i){;;;
        int a, b;
    cin >> a >> b;
    ;
        klst.push_back({a, b});
    };;;
    sort(klst.begin(), klst.end(), comp_klst_1_);;
    int ans = 0;;
    int i = 0;;
    int cut = klst[0].m_1-1;;
    while(i<klst.size()){;;;
        if(klst[i].m_0<=cut) {;++i; continue;}
        else {;++ans; cut = klst[i].m_1-1;};
    };;;
    cout << (ans+1) << endl;;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
int main() {
	int N;
	cin >> N;
	int two = 0, four = 0, odd = 0;
	rep(i, N) {
		int A;
		cin >> A;
		if (A % 4 == 0) four++;
		else if (A % 2 == 0) two++;
		else odd++;
	}
	if ((two == 0 && four + 1 >= odd) || (two != 0 && four >= odd)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 384
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値

using namespace std;
using ll = long long int;

int main(void){
    int end = 0;
    int N;cin>>N;
    for(int i=0;i<3;i++){
        if(N%10==7){
            end = 1;
        }
        N /= 10;
    }
    if(end==1){
        cout << "Yes" << endl;
    }else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
ll dp[1010][1010];
ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll comb[1010][1010];
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(comb[n][r])return comb[n][r];
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return comb[n][r]=mod_div(ret,tmp);
}

void modadd(ll &a, ll b){
  a+=b;
  a%=MOD;
}


//べき乗 x^n mod M
long long power(long long x, long long n){
	long long res = 1;
	if(n > 0){
		res = power(x, n / 2);
		if(n % 2 == 0) res = (res * res) % MOD;
		else res = (((res * res) % MOD) * x ) % MOD;
	}
	return res;
}

//階乗
long long fact[1005];
long long factorial(long long n, long long r){
	long long res = 1;
	for(int i=r;i<n + 1;i++){
		res*= i;
		res%= MOD;
		fact[i] = res;
	}
	return res;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,a,b,c,d;cin>>n>>a>>b>>c>>d;
  dp[a-1][n]=1;
  factorial(1000,1);
  ll fact_rev[1005];
  for(int i=0;i<1001;i++)fact_rev[i]=power(fact[i],MOD-2);
  for(int i=a-1;i<b;i++){
    for(int j=0;j<=n;j++){
      ll kake=1;
      int cnt=1;
      if(dp[i][j]==0)continue;
      for(int k=j-(i+1);k>=0;k-=(i+1)){
	if(cnt>d)break;
	//cout<<i<<" "<<j<<" "<<k+1+i<<" "<<i+1<<endl;
	if(cnt>=c){
	  dp[i+1][k]+=(dp[i][j]*((combination(k+i+1,i+1)*kake%MOD*fact_rev[cnt])%MOD))%MOD;
	  
	}
	dp[i+1][k]%=MOD;
	kake*=combination(k+1+i,i+1);
	kake%=MOD;
	cnt++;
      }
      dp[i+1][j]+=dp[i][j];
      dp[i+1][j]%=MOD;
    }
  }

  /* for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      //if(dp[i][j]<0)
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
    }*/
  cout<<dp[b][0]<<endl;
  return 0;
}


Measured memory_bytes: 16896
n = int(input())
a = [int(i) for i in input().split()]
c = 0
i = 0
 
while a[i]%2 == 0:
  if a[i]%2 ==0:
    a[i]//=2
  if i==n-1:
    c+=1
    i = 0
  i+=1
print(c)


Measured memory_bytes: 2940
/* abc_168_a */

#include<stdio.h>

int main()
{
  int N,n;
  scanf("%d",&N);
  n=N%10;
  if (n==2 || n==4 || n==5 || n==7 || n==9) printf("hon\n");
  if (n==0 || n==1 || n==6 || n==8) printf ("pon\n");
  if (n==3) printf("bon\n");
  return 0;
}


Measured memory_bytes: 1568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Maximum Sum
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		int n, k, sum = 0, max = 0;
		int[] list;

		while (!(line = br.readLine()).equals("0 0")) {
			n = Integer.parseInt(line.substring(0, line.indexOf(' ')));
			k = Integer.parseInt(line.substring(line.indexOf(' ') + 1));
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(br.readLine());
			}
			max = 0;
			for (int i = 0; i < k; i++) {
				max += list[i];
			}
			sum = max;
			for (int i = k; i < n; i++) {
				sum = sum - list[i - k] + list[i];
				if (sum > max)
					max = sum;
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 29588
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
typedef long long ll;
using namespace std;

int n, x, a[100], cnt;

int main() {
	cin >> n >> x;
	lp(n)
		cin >> a[i];
	cnt = 0;
	sort(a, a + n);
	lp(n) {
		if (x >= a[i]) {
			x -= a[i];
			cnt++;
		}
		else break;
	}
	if (cnt == n&&x != 0)cnt--;
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int w, h, x, y, r;
		// ???????????????int?????§??????????????????
		w = scan.nextInt();// X1
		h = scan.nextInt();// Y2
		x = scan.nextInt();// X1*
		y = scan.nextInt();// Y2*
		r = scan.nextInt();// r*

		// ???????????????????????\??????
		String str;
		str = "No";

		// ??????????????°
		boolean flg;
		flg = false;

		// ??§?¨????????????¢?????????????????????????????????
		if (w > x) {// X??§?¨????????????????????????¢???X??§?¨?????????????X??§?¨????????????£????????????
			if (x <= 0) {// ????????¢????????????????????¨???????????´???
				str = "No";
			} else {
				if (h > y) {// Y??§?¨????????????????????????¢X??§?¨?????????????Y??§?¨????????????£????????????
					if (y <= 0) {// ????????¢????????????????????¨???????????´???
						str = "No";
					} else {
						flg = true;
					}

				} else {
					str = "No";
				}
			}

		} else {
			str = "No";
		}

		// ????????????r?????????????????????
		if (flg) {// ????????°???true?????¨?????????????????????
			if (w >= (x + r)) {// X??§?¨????????????????????????¢X??§?¨???????(??????X??§?¨?+????????????r?????§????????????
				if (w >= (y + r)) {// Y??§?¨????????????????????????¢Y??§?¨???????(??????Y??§?¨?+????????????r?????§????????????
					str = "Yes";
				} else {
					str = "No";
				}
			} else {
				str = "No";
			}
		}
		System.out.println(str);

	}
}

Measured memory_bytes: 26408
w=[]
k=[]
wm=[]
km=[]
for i in range(1,11):
    x=int(input())
    w.append(x)

for i in range(1,4):
    wma=max(w)
    wm.append(wma)
    w.remove(wma)

for i in range(1,11):
    x=int(input())
    k.append(x)

for i in range(1,4):
    kma=max(k)
    km.append(kma)
    k.remove(kma)

print(wm[0]+wm[1]+wm[2],km[0]+km[1]+km[2])


Measured memory_bytes: 5600
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Integer> d = new ArrayList<Integer>();
		for(int i = 0; i < n; i++) {
			d.add(sc.nextInt());
		}
		sc.close();
		Collections.sort(d);
		int ans = d.get(n/2) - d.get(n/2-1);
		System.out.println(ans);
	}

}


Measured memory_bytes: 58660
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let x: usize = iterator.next().unwrap().parse().unwrap();

    let mut a: Vec<usize> = vec![1; n + 1];
    let mut p: Vec<usize> = vec![1; n + 1];
    for i in 1..=n {
        a[i] = 2 * a[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }

    f(n, x, &a, &p).to_string()
}

fn f(n: usize, x: usize , a: &Vec<usize>, p: &Vec<usize>) -> usize {
    if n == 0 {
        return 1;
    }

    if x == 1 {
        return 0;
    }

    if x < a[n - 1] + 2 {
        return f(n - 1, x - 1, a, p);
    }

    if x == a[n - 1] + 2 {
        return p[n - 1] + 1;
    }

    if x < a[n] {
        return p[n - 1] + 1 + f(n - 1, x - (a[n - 1] + 2), a, p);
    }

    return p[n]
}


Measured memory_bytes: 2140
x1,y1,x2,y2 = map(int, input().split())
v12x, v12y = x2-x1, y2-y1
v14x, v14y = v12y*(-1), v12x
x4,y4 = x1+v14x, y1+v14y

x3,y3 = x4+v12x, y4+v12y

print(x3,y3,x4,y4)

Measured memory_bytes: 61216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

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

LL find_closest(int a, int b) {
  LL res = 2018;
  for (int i = a; i < b; i++) {
    for (int j = a+1; j <= b; j++) {
      LL mul = i * j;
      res = min(res, mul % 2019);
      if (res == 0) {
        return res;
      }
    }
  }

  return res;
}

int main(void){
  LL l, r;
  cin >> l >> r;
  LL _min;

  if (r < 2019) {
    cout << (l * (l+1)) % 2019 << endl;
  } else if (l < 2019 && 2019 <= r) {
    cout << 0 << endl;
  } else if (2019 <= l) {
    if ((l / 2019) != (r / 2019)) {
      cout << 0 << endl;
    } else {
      if (l % 2019 == 0) {
        cout << 0 << endl;
      } else {
        cout << find_closest(l % 2019, r%2019) << endl;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MAX=1e17;
bool count(ll y, ll m){
	if(y==0) return 1;
	else if(y>0){
		bool ans=0;
		for(int i=58; i>=0; i--){
			if(m&(1ll<<i)){
				if(!(y&((1ll<<i)-1))){
					ans^=1;
				}
				if(!(y&(1ll<<i))) break;
			}
		}
		if((m|y)==y) ans^=1;
		return ans;
	}else{
		y=-y;
		y--;
		if(y==0){
			return (m+1)&1ll;
		}
		m+=y;
		bool myon=0, ans=0;
		for(int i=58; i>=0; i--){
			if(m&(1ll<<i)) myon=1;
			if(y&(1ll<<i) && !myon){
				return 0;
			}
			if(m&(1ll<<i)){
				if(y&(1ll<<i)) continue;
				if((y&((1ll<<i)-1))==((1ll<<i)-1)) ans^=1;
			}else{
				if(y&(1ll<<i)) break;
			}
		}
		if((m|y)==m) ans^=1;
		return ans;
	}
}
int main()
{
	int n;
	scanf("%d", &n);
	ll x[100010], y[100010];
	for(int i=0; i<n; i++){
		scanf("%lld %lld", &x[i], &y[i]);
		x[i]+=MAX;
	}
	ll l=-1, r=3*MAX;
	while(r-l>1){
		ll m=(l+r)/2;
		bool ok=0;
		for(int i=0; i<n; i++){
			if(x[i]>m) continue;
			ok^=count(y[i], m-x[i]);
		}
		if(ok) r=m;
		else l=m;
	}
	printf("%lld\n", r-MAX);
	return 0;
}


Measured memory_bytes: 1792
"""
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}
"""
n = int(input())
i = 1
while True:
    x = i
    if x % 3 == 0:
        print (f' {i}', end='')
    else:
        while x:
            if x % 10 == 3:
                print(f' {i}', end='')
                break
            x //= 10
    i += 1
    if i > n:
        break
print()


Measured memory_bytes: 5892
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 3e3 + 5;
const int mod = 998244353;
const int inf = 1e9 + 9;
 
int a[N], endat[N][N];

signed main() {
    IOS;
    int n, s;
    cin >> n >> s;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    int ans = 0;
    for(int i = 1; i <= n; i++){
        endat[i][a[i]] = i;
        for(int j = 0; j <= s; j++){
            endat[i][j] += endat[i-1][j];
            if(a[i] <= j)
                endat[i][j] += endat[i-1][j-a[i]];
            endat[i][j] %= mod;
        }
    }
    for(int i = 1; i <= n; i++){
        ans += endat[i][s];
        ans %= mod;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 70784
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}


template <typename T>
void vecOutPadding(vector<T>& vec, string pad = " ") {
	for (const T& elem : vec)
		cout << elem << pad;
}

template <typename T>
void matOut(vector<vector<T>>& mat) {
	for (const auto& row : mat) {
		for (const T& col : row)
			cout << col << " ";
		cout << endl;
	}
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	string s;
	cin >> s;

	bool c, f;
	c = f = false;
	for (auto ss : s) {
		if (ss == 'C') c = true;
		if (c && ss == 'F') f = true;
	}

	yn(f);

	return 0;
}

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

using ll =long long;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    int r,g,b;
    cin >> r >> g >> b;
    if ((10*g+b)%4==0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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; }

int main() {
    ll x, k, d; cin >> x >> k >> d;
    x = abs(x);

    ll t = min(k, x / d);
    k -= t;
    x -= t * d;

    if (k % 2 == 0) {
        cout << x << endl;
    } else {
        cout << d - x << endl;
    }
}


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

// input
int N;
vector<int> A;


void input() {
    cin >> N;
    A = vector<int>(N);
    rep(i, N) cin >> A[i];
}


ll solve(bool p) {
    ll s = 0;
    ll ret = 0;
    rep(i, N) {
        s += A[i];
        if (p) {
            if (s <= 0) {
                ret += 1 - s;
                s += 1 - s;
            }
        } else {
            if (s >= 0) {
                ret += s + 1;
                s -= s + 1;
            }
        }
        p = !p;
    }
    return ret;
}


int main() {
    input();
    ll ans = min(solve(true), solve(false));
    cout << ans << endl;
}


Measured memory_bytes: 3716
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin>>n>>k;
    vector<int>l(n);
    rep(i,n)cin>>l[i];
    sort(ALL(l),greater<int>());
    int sum=0;
    rep(i,k){
        sum+=l[i];
    }
    cout<<sum<<"\n";
}


Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

all_pattern = list(itertools.permutations([i for i in range(1,N+1)]))
#print(all_pattern)

for i, node in enumerate(all_pattern):
  if node == P:
    p = i
  if node ==  Q:
    q = i
    
    
print(abs(p-q))

Measured memory_bytes: 8052
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

var S = readLine()!.toArray()
for _ in 0..<S.count-1 {
    S.removeLast()
    if S.count % 2 > 0 {
        continue
    }
    let firstHalf = (0..<S.count/2).map{S[$0]}
    let secondHalf = (S.count/2..<S.count).map{S[$0]}
    if firstHalf == secondHalf {
        print(S.count)
        break
    }
}


Measured memory_bytes: 1280
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <queue>
#define INF 1<<19
const int MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll n,m,d;
    cin >> n >> m >> d;
    if(d == 0){
        printf("%.10f\n",(double)(n-d)*(m-1)/(n*n));
    }else{
        printf("%.10f\n",(double)2*(n-d)*(m-1)/(n*n));
    }

}

Measured memory_bytes: 256
local n = io.read("*number")
local l = io.read("*number")
local b = io.read("*number")

local sum = 0
if l ~= b and n < 2 then
	print(sum)
 	return sum
end

if l > b then
	print(sum)
	return sum
end

local minx = (n - 1)*l + b
local maxx = (n-1)*b + l

local sum = maxx - minx + 1
print(sum)


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

int main(int argc, char **argv)
{
	int MAX = 100010;
	int n; cin >> n;
	vector<ll> v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];

	vector<int> odd_h(MAX, 0), even_h(MAX, 0);
	for (int i = 0; i < n; ++i)
	{
		if (i & 1) ++odd_h[v[i]];
		else ++even_h[v[i]];
	}

	vector<pint> odd_hist, even_hist;
	odd_hist.reserve(MAX);
	even_hist.reserve(MAX);
	for (int i = 0; i < MAX; ++i)
	{
		odd_hist.push_back(pint(odd_h[i], i));
		even_hist.push_back(pint(even_h[i], i));
	}

	sort(odd_hist.begin(), odd_hist.end(), greater<pint>());
	sort(even_hist.begin(), even_hist.end(), greater<pint>());

	int tmp;
	if (odd_hist[0].second == even_hist[0].second)
	{
		tmp = max(odd_hist[0].first + even_hist[1].first,
				   odd_hist[1].first + even_hist[0].first);
	}
	else
	{
		tmp = odd_hist[0].first + even_hist[0].first;
	}
	std::cout << n - tmp << std::endl;
}


Measured memory_bytes: 3328
import sys

N,K=map(int,input().split())
D=dict()
for i in range(N):
  a,b=map(int,input().split())
  try:
    D[a]+=b
  except:
    D[a]=b

D=sorted(D.items(),key=lambda x:x[0])


for k,v in D:
  K-=v
  if K<=0:
    print(k)
    break

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

bool onlynum(int s, int e, string &str){
    bool ret = true;
    for(int i=s; i<=e; i++){
        if(str[i]=='L' || str[i]=='R' || str[i]=='(' || str[i]==')' || str[i]==','){
            ret = false;
            break;
        }
    }
    return ret;
}
string smax(string s, string t){
    if(s=="invalid") return t;
    if(t=="invalid") return s;
    if(s.length() == t.length()){
        return max(s, t);
    }else if(s.length() < t.length()){
        return t;
    }else{
        return s;
    }
}

int main(){
    string str, str2;
    cin >> str;
    int n = str.length();
    str2 = str;
    for(int i=0; i<n; i++){
        if(str2[i]=='?') str2[i]='9';
    }
    
    vector<vector<string> > dp(n, vector<string>(n, "invalid"));
    for(int j=0; j<n; j++){
        for(int i=0; i+j<n; i++){
            if(onlynum(i, i+j, str) && (j==0 || str[i]!='0')){
                dp[i][i+j] = str2.substr(i, j+1);
            }
            if(j>=5 && (str[i+1]=='(' || str[i+1]=='?') && (str[i+j]==')' || str[i+j]=='?')){
                for(int k=i+3; k<=i+j-2; k++){
                    if(str[k]!=',' && str[k]!='?') continue;
                    if(dp[i+2][k-1]=="invalid" || dp[k+1][i+j-1]=="invalid") continue;
                    if(str[i]=='L' || str[i]=='?'){
                        dp[i][i+j] = smax(dp[i][i+j], dp[i+2][k-1]);
                    }
                    if(str[i]=='R' || str[i]=='?'){
                        dp[i][i+j] = smax(dp[i][i+j], dp[k+1][i+j-1]);
                    }
                }
            }
        }
    }
    cout << dp[0][n-1] << endl;
    return 0;
}



Measured memory_bytes: 3292
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int n;
string s;

int main(){
	cin >> n >> s;
	
	int cnt = 0; n = 0;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'I') cnt++;
		else cnt--;
		n = max(n, cnt);
	}
	cout << n << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
const int INF = 2000000000;

int n, x;
int A[100000];
ll ans = 0;

int main(){
  cin >> n >> x;
  rep(i, n){
    cin >> A[i];
  }
  if(A[0] > x){
    ans += A[0] - x + A[1];
    A[0] = x;
    A[1] = 0;
  }
  rep(i, n-1){
    if(A[i] + A[i+1] > x){
      ans = ans + A[i] + A[i+1] - x;
      A[i+1] = x - A[i];
    }
  }
  cout << ans <<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int common[26];
    rep(i, 0, 26) {
        int mn = 100;
        rep(j, 0, n) {
            int cnt = 0;
            rep(k, 0, (int)s[j].size()) {
                if (s[j][k] == (char)(i + 'a')) {
                    cnt++;
                }
            }
            mn = min(mn, cnt);
        }
        common[i] = mn;
    }

    vector<char> v;
    rep(i, 0, 26) {
        rep(j, 0, common[i]) {
            v.push_back((char)(i + 'a'));
        }
    }
    
    sort(ALL(v));

    rep(i, 0, (int)v.size()) {
        cout << v[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256