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

int main(){
    int n;
    ll k;
    ll a[100005];
    cin>>n>>k;
    for(int i=0;i<n;i++) cin>>a[i];
    ll zero[70];
    ll one[70];
    int keta=0;//0,1は0桁
    ll dketame[70]={0};
    while(k>0){
        dketame[keta]=k%2;
        k/=2;
        if(k>0) keta++;
    }
    for(int i=0;i<51;i++){
        for(int j=0;j<n;j++){
            
            if(a[j]%2==0) zero[i]++;
            else one[i]++;
            a[j]/=2;
        }
    }
    ll res=0;
    for(int d=40;d>=-1;d--){
        if(d!=-1 && dketame[d]==0) continue;
        
        ll tmp=0;
        
        for(int i=0;i<40;i++){
            ll mask=1LL<<i;
            if(i<d){
                tmp+=max(zero[i],one[i])*pow(2,i);
            }
            else if(i==d){
                tmp+=one[i]*pow(2,i);
            }
            else{
                if(dketame[i]==1) tmp+=zero[i]*mask;
                else tmp+=one[i]*(1LL<<i);
            }
        }
        res=max(res,tmp);
    }
    cout<<res<<endl;
    return 0;
}


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

using namespace std;

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

  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    x -= a[i];
    if (x < 0) {
      break;
    }
    if (i == n - 1) {
      if (x != 0) {
        break;
      }
    }
    ++cnt;
  }

  cout << cnt << '\n';

  return 0;
}


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

const int mod = 1e9 + 7;

class Combination{
public:
  typedef long long ll;
  ll N;
  ll mod;
  vector<ll> fac;
  vector<ll> finv;
  vector<ll> inv;
  
  
  Combination(ll N = 1e6,ll mod = 1e9 + 7): N(N), mod(mod), fac(N+1), finv(N+1), inv(N+1){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i <= N; i++){
      fac[i] = fac[i-1] * i % mod;
      inv[i] = mod - inv[mod%i] * (mod / i) % mod;
      finv[i] = finv[i-1] * inv[i] % mod;
    }
  }

  function<ll(ll,ll)> get = [&](ll n,ll r){
    if( n < r ) return 0LL;
    if( n < 0 || r < 0) return 0LL;
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod;
  };

};

auto nCr = (new Combination())->get;  

int N, M, K, A[1000000];
int dp[600005];

signed main(){
  
  A[0] = 1;
  
  for(int i=1;i<1000000;i++) A[i] = A[i-1] * 3 % mod;
  
  cin>>N>>M>>K;
  
  dp[0] = 1;
  
  for(int i=0;i<M+K;i++){
    
    dp[i+1] = dp[i] * 2;
    
    dp[i+1] -= nCr( i, M );
    
    dp[i+1] -= nCr( i, K );
    
    dp[i+1] += mod * 2;
    
    dp[i+1] %= mod;
    
  }
  
  int ans = 0;
  
  for(int i=N;i<=N+M+K;i++){
    
    ans += ( dp[i-N] * nCr( i - 1, N - 1 ) % mod ) * A[(N+M+K)-i] % mod;
    
    ans %= mod;
    
  }
  
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 36224
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}

void solve()
{
  //code begins from here//
  ll n;
  cin>>n;
  map <string,ll> m;
  m["AC"]=0;
  m["WA"]=0;
  m["TLE"]=0;
  m["RE"]=0;
  lop(i,n)
  {
    string s;
    cin>>s;
    m[s]++;
  }
  cout<<"AC x "<<m["AC"]<<endl;
   cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
     cout<<"RE x "<<m["RE"]<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
	int x,y,m,kaisuu,caunt;
	int noboru,oriru,kioku;
	int dansa[100];
	scanf("%d",&m);
	for(x=0; x<m; x++)
	{
		noboru=0;
		oriru=0;
		scanf("%d",&kaisuu);
		for(caunt=0; caunt<kaisuu; caunt++)
			scanf("%d",&dansa[caunt]);
		for(y=0; y<kaisuu-1; y++)
		{
			if(dansa[y]<dansa[y+1]);
			{
				kioku=dansa[y+1]-dansa[y];
				if(noboru<kioku)
					noboru=kioku;
			}
			if(dansa[y]>dansa[y+1])
			{
				kioku=dansa[y]-dansa[y+1];
				if(oriru<kioku)
					oriru=kioku;
			}
		}
		printf("%d %d\n",noboru,oriru);
	}
	return 0;
}

Measured memory_bytes: 596
import sys
sys.setrecursionlimit(20000)

n = int(input())
h_L = list(map(int,input().split()))

counter = 0


def devzero(l,moji=0):
    return_L,tmp = [],[]
    for val in l:
        if val != moji:
            tmp.append(val)
            #print(tmp)
        elif val == moji:
            return_L.append(tmp)
            tmp = []
    return_L.append(tmp)

    return return_L

def rec(L):
    global counter

    if L == []:
        return
    if 0 not in L:
        L = [i-1 for i in L]
        counter += 1
    L = devzero(L,moji=0)
    for val in L:
        rec(val)

if __name__=="__main__":
    rec(h_L)
    print(counter)


Measured memory_bytes: 41200
//dumsdafh
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int main(){
    int t; scanf("%d", &t);
    while(t--){
        int n,d; scanf("%d %d", &n, &d);
        if(n%2 == 1){
            printf("%d\n", (n-1)*127 + d);
        } else {
            printf("%d\n", n*127 - d);
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>

using namespace std;

const int mod = 1000000007;

long long qpow(long long base,int tms)
{
	long long tmp = 1;
	while(tms)
	{
		if(tms & 1) tmp = tmp * base % mod;
		base = base * base % mod;
		tms >>= 1;
	}
	return tmp;
}

long long inv2 = qpow(2,mod - 2);
long long dp[3050][3050];
int N,Q;
int seq[3050];

int main()
{
	scanf("%d%d",&N,&Q);
	for(int i = 1;i <= N; ++ i)
		scanf("%d",&seq[i]);
	for(int i = 1;i <= N; ++ i)
		for(int j = 1;j <= N; ++ j)
			dp[i][j] = seq[i] > seq[j];
	long long make_me_burn = qpow(2,Q);
	while(Q --)
	{
		int x,y; scanf("%d%d",&x,&y);
		dp[x][y] = dp[y][x] = (dp[x][y] + dp[y][x]) * inv2 % mod;
		for(int i = 1;i <= N; ++ i)
			if(i != x && i != y)
				dp[i][x] = dp[i][y] = (dp[i][x] + dp[i][y]) * inv2 % mod,
				dp[x][i] = dp[y][i] = (dp[x][i] + dp[y][i]) * inv2 % mod;
	}
	long long ans = 0;
	for(int i = 1;i <= N; ++ i)
		for(int j = i + 1;j <= N; ++ j)
			ans = ans + dp[i][j] * make_me_burn % mod,ans %= mod;
	printf("%lld\n",ans);
}

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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif

int main(){
    IOS;
    int n;
    cin >> n;
    vi a(n);
    set<int> x;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        x.insert(a[i]);
    }

    cout << (x.size() == a.size() ? "YES" : "NO") << endl;

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}




Measured memory_bytes: 10368
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>

typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n;
	ll ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		if (!(i % 3 == 0) && !(i % 5 == 0)) {
			ans += i;
		}
	}
	cout << ans << endl;
	
	return 0;
}


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

int main(void){
  char s[6];
  for(int i=0;i<6;i++){
    cin>>s[i];
  }
  int count=0;
  if(s[2]==s[3]) count++;
  if(s[4]==s[5]) count++;
  if(count==2) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int INF = 1e9;
const int maxK = 1000 + 9;

int n, k;
ll psum[2 * maxK][2 * maxK];

void read(){
  cin >> n >> k;
  for(int i = 0; i < n; i++){
    int x, y; char c;
    cin >> x >> y >> c;
    if(c == 'W')
      x += k;

    x %= (2 * k);
    y %= (2 * k);

//    cerr << x + 1 << ' ' << y + 1 << '\n';
    psum[x + 1][y + 1]++;
  }
}

bool inside(int x, int y){
  return (1 <= x && x <= 2 * k) && (1 <= y && y <= 2 * k);
}

ll rangeSum(int x, int y, int u, int v){
  if(x > u || y > v || !inside(x, y) || !inside(u, v))
    return 0;

  return psum[u][v] - psum[x - 1][v] - psum[u][y - 1] + psum[x - 1][y - 1];
}

void solv(){
//  for(int i = 1; i <= 2 * k; i++){
//    for(int j = 1; j <= 2 * k; j++)
//      cerr << psum[i][j] << ' ';
//    cerr << '\n';
//  }

  for(int i = 1; i <= 2 * k; i++)
    for(int j = 1; j <= 2 * k; j++)
      psum[i][j] += psum[i][j - 1];

  for(int i = 1; i <= 2 * k; i++)
    for(int j = 1; j <= 2 * k; j++)
      psum[i][j] += psum[i - 1][j];

  ll mx = 0;
  for(int i = 1; i <= 2 * k; i++){
    for(int j = 1; j <= 2 * k; j++){
      ll cnt = 0;
      if(!inside(i + k - 1, j + k - 1))
        continue;
//      cerr << i << ' ' << j << ' ' << "--> " << rangeSum(i, j, i + k - 1, j + k - 1) << '\n';
//      cerr << i + k << ' ' << j + k << " ---> " << rangeSum(i + k, j + k, 2 * k, 2 * k) << '\n';
//      cerr << i + k << ' ' << 1 << " ---> " << rangeSum(i + k, 1, 2 * k, j - 1) << '\n';
//      cerr << 1 << ' ' << 1 << " ---> " << rangeSum(1, 1, j - 1, j - 1) << '\n';
//      cerr << 1 << ' ' << j + k << " ---> " << rangeSum(1, j + k, i - 1, 2 * k) << '\n';
      cnt += rangeSum(i, j, i + k - 1, j + k - 1);
      cnt += rangeSum(i + k, j + k, 2 * k, 2 * k);
      cnt += rangeSum(i + k, 1, 2 * k, j - 1);
      cnt += rangeSum(1, 1, i - 1, j - 1);
      cnt += rangeSum(1, j + k, i - 1, 2 * k);
//      cerr << "cnt = " << cnt << '\n';
//      cerr << "---------------------\n";

      mx = max(mx, cnt);
      mx = max(mx, n - cnt);
    }
  }

  cout << mx << '\n';
}

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

  read();
  solv();

  return 0;
}


Measured memory_bytes: 31744
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define check system("pause")
#define all(x) (x).begin(),(x).end()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
const ll mod = 1e9+7;
const int N = 51;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p,b) memset(p,b,sizeof(p))
#define sz(x) int(x.size())
int a[N],b[N],c[N],d[N],A[N],ans=0,n,m,q;
void dfs(int p,int x){
	if(p==n+1){
		int sum=0;
		rep(i,1,q){
			if(A[b[i]]-A[a[i]]==c[i]) sum+=d[i];
			
			
		}
		ans=max(ans,sum);
		return ;
	}
	rep(i,x,m){
		A[p]=i;
		dfs(p+1,i);
	}
}
int main()
{
  	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m>>q;
	rep(i,1,q){
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	dfs(1,1);
	cout<<ans;
  	return 0;
}



Measured memory_bytes: 3652
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include <bits/stdc++.h>

using namespace std;

const int kMaxNumNodes = (1 << 20);

struct AlphaNode {
	int next[26];
	int count[26];
};

int num_nodes;
int root;
AlphaNode nodes[kMaxNumNodes];

int calc(const string& s) {
	int current = root;
	for (int i = 0; i < s.length() - 1; ++i) {
		int c = s[i] - 'a';
		current = nodes[current].next[c];
		if (current == 0) {
			return 0;
		}
	}
	return nodes[current].count[s.back() - 'a'];
}

void add(const string& s) {
	vector<int> num_chars(26);
	for (char c : s) {
		++num_chars[c - 'a'];
	}
	int current = root;
	for (int i = 0; i < s.length(); ++i) {
		for (int j = 0; j < 26; ++j) {
			if (num_chars[j] > 0) {
				++nodes[current].count[j];
			}
		}
		int c = s[i] - 'a';
		--num_chars[c];
		if (nodes[current].next[c] == 0) {
			nodes[current].next[c] = (++num_nodes);
		}
		current = nodes[current].next[c];
	}
}

int main()
{
#ifdef _MSC_VER
	freopen("b.in", "r", stdin);
#endif
	std::ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	vector<int> s_sort_by_length(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		reverse(s[i].begin(), s[i].end());
		s_sort_by_length[i] = i;
	}
	sort(s_sort_by_length.begin(), s_sort_by_length.end(), [&](int a, int b) { return s[a].length() > s[b].length(); });
	memset(nodes, 0, sizeof(nodes));
	num_nodes = 0;
	root = (++num_nodes);
	long long ret = 0;
	for (int i = 0; i < n; i++) {
		const string& a = s[s_sort_by_length[i]];
		ret += calc(a);
		add(a);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 223280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    ll n, k;
    cin >> n >> k;
    int a[n];
    repi(i, n, 0)
    {
        cin >> a[i];
        a[i]--;
    }
    bool town[n] = {false};
    ll index = 0;
    while (k > 0)
    {
        if (!town[index])
        {
            town[index] = true;
        }
        else
        {
            break;
        }
        index = a[index];
        k--;
    }
    if (k == 0)
    {
        cout << index + 1 << endl;
    }
    else
    {
        vector<ll> loop;
        fill(town,town + n,false);
        while (true)
        {
            if (!town[index])
            {
                town[index] = true;
                loop.push_back(index);
                index = a[index];
            }
            else
            {
                break;
            }
        }
        k %= loop.size();
        cout << loop[k] + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 5116
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 100000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=200005;

int a[26], n, s[N], last[26], p[N], visit[N];
char str[N];


void add(int x){
    while(x<N) s[x]++,x+=x&-x;
}
int get(int x){
    int ans=0;
    while(x) ans+=s[x],x-=x&-x;
    return ans;
}

int main()
{
    scanf("%s",str+1);
    n=strlen(str+1);
    int i,k,t;
    FOR(i,1,n)
    {
        k=str[i]-'a';
        a[k]++;
        p[i]=last[k];
        last[k]=i;
    }
    k=0;
    FOR(i,0,25) k+=(a[i]&1);
    if(k>n%2) {
        puts("-1");
        return 0;
    }
    LL ans=0, len=n, preNum=0;
    FOR(i,1,n) if(!visit[i]) {
        t=str[i]-'a';
        k=last[t];
        if(i>=k) {
            len--;
            ans+=len/2;
        }
        else {
            ans+=len-(k-preNum-get(k));
            visit[k]=1;
            add(k);
            len-=2;
            last[t]=p[k];
        }
        preNum++;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 2048
cards = [[False for i in range(13)] for j in range(4)]
pattern = ["S","H","C","D"]
n = int(input())
for i in range(n):
    ch,rank = input().split()
    rank = int(rank)
    cards[pattern.index(ch)][rank-1] = True
for i in range(4):
    for j in range(13):
        if cards[i][j] == False:
            print(pattern[i], j+1)


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    ll n,k;
    cin >> n >> k;
    ll a[n];
    for (ll i=0;i<n;i++)cin >> a[i];
    n-=k;
    if (n%(k-1)==0){
        cout << n/(k-1)+1 << endl;
    }else{
        cout << n/(k-1)+2 << endl;
    }
    return 0;
}




Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad

data YesNo = Yes | No deriving(Show)

solver :: String -> String -> Int -> YesNo
solver s t n
    | n == 0    = No
    | s == t    = Yes
    | otherwise = solver (tail s ++ [head s]) t (n-1)

main :: IO ()
main = do
    s <- getLine
    t <- getLine
    print $ solver s t (length t)


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


dic = {}
for i in range(N):
    s = input()

    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1


print('AC x {}'.format(dic.get('AC', 0)))
print('WA x {}'.format(dic.get('WA', 0)))
print('TLE x {}'.format(dic.get('TLE', 0)))
print('RE x {}'.format(dic.get('RE', 0)))



Measured memory_bytes: 9196
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int calc(int n,int *d,int m,int *dp){
  if(dp[n]>=0) return dp[n];
  int res=n;
  int i;
  for(i=0;i<m;i++){
    if(n-d[i]>=0){
      res=MIN(res,calc(n-d[i],d,m,dp)+1);
    }
  }
  dp[n]=res;
  return res;
}

void run(void){
  int n,m;
  scanf("%d%d",&n,&m);
  int d[20];
  int i;
  for(i=0;i<m;i++) scanf("%d",d+i);
  int *dp=(int *)malloc(sizeof(int)*(n+1));
  for(i=0;i<=n;i++) dp[i]=-1;
  dp[0]=0;
  int ans=calc(n,d,m,dp);
  printf("%d\n",ans);
  free(dp);
  return;
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 5744
n = int(input())
x = [int(i) for i in input().split()]
y = sorted(x)
m1 = y[int(n/2-1)]
m2 = y[int(n/2)]
if m1==m2:
  for i in x:
    print(m1)
else:
  for i in x:
    if m2 > i:
      print(m2)
    elif i > m1:
      print(m1)

Measured memory_bytes: 26016
from heapq import heappush, heappop
inf = float('inf')

# (始点,隣接リスト)
def dijkstra(start,ad):
    global dist
    dist = [inf]*len(ad)
    dist[start] = 0
    pq = [(start,0)]
    while pq:
        v = heappop(pq)[0]
        for nv,nw in ad[v]:
            if dist[nv] > dist[v] + nw:
                dist[nv] = dist[v] + nw
                heappush(pq,(nv,dist[nv]))

N = int(input())
ad = [[] for _ in range(N)]
for _ in range(N-1):
    a,b,c = map(int,input().split())
    a -= 1; b -= 1
    ad[a].append((b,c))
    ad[b].append((a,c))
Q,K = map(int,input().split())
K -= 1
query = [[int(e)-1 for e in input().split()] for _ in range(Q)]

dijkstra(K,ad)

for x, y in query:
    ans = dist[x] + dist[y]
    print(ans)

Measured memory_bytes: 64380
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
ans = 0
pre = -1
for i in range(n):
    ans += b[a[i] - 1]
    if pre == a[i] - 1:
        ans += c[pre - 1]
    pre = a[i]
print(ans)

Measured memory_bytes: 38384
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    [x,y] <- getIntList
    print $ if x `mod` y == 0 then -1 else x

Measured memory_bytes: 380
N = int(input())
T, A = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]

dif = float('inf')
num = 0

for i in range(N):
    dif_i = abs(T - H[i] * 0.006 - A)
    if dif > dif_i:
        dif = dif_i
        num = i + 1

print(num)

Measured memory_bytes: 3188
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int N;
    private int[] S;
    public void Solve()
    {
        N = int.Parse(Console.ReadLine());
        S = new int[N];
        for (int i = 0; i < N; i++)
        {
            S[i] = int.Parse(Console.ReadLine());
        }
        int max = 10000;
        bool[] array = new bool[max + 1];
        array[0] = true;
        foreach(int i in S)
        {
            for(int j = max; j >= 0; j--)
            {
                if (array[j])
                {
                    array[j + i] = true;
                }
            }
        }
        for(int i = max; i >= 0; i--)
        {
            if(i % 10 == 0)
            {
                continue;
            }
            if (array[i])
            {
                Console.WriteLine(i);
                return;
            }
        }
        Console.WriteLine(0);
    }
}



Measured memory_bytes: 11072
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    long long sum=0;
    long long a[n];
    long long b[n];
    int i,j;
    for(i=0;i<n;i++){
        cin >> a[i];
    }
    b[n-1]=a[n-1];
    for(i=n-2;i>=0;i--){
        b[i]=(a[i]+b[i+1])% (1000000007);
    }
    for(i=0;i<n-1;i++){
        sum =(sum + a[i]*b[i+1])% (1000000007);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 6772
M, K = map(int, input().split())

if K == 0:
    ans = list(range(1 << M)[:: -1]) + list(range(1 << M))
    print(*ans)
    exit()

A = []
B = []

used = [False] * (1 << M)
for d in range(M):
    if ((1 << d) & K) != 0:
        A.append(1 << d)
        used[1 << d] = True

for i in range(1 << M):
    if used[i]:
        continue
    else:
        B.append(i)

xorA = 0
for a in A:
    xorA ^= a

xorB = 0
for b in B:
    xorB ^= b

if xorA != K or xorB != K:
    print(-1)
    exit()

A.sort()
B.sort()
ans = A + B + A[:: -1] + B[:: -1]
print(*ans)


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MAX = 10000000;
ll _sieve_size;
bitset<10000010> bs;
vi primes;

void sieve(ll upperbound){
	_sieve_size = upperbound+1;
	bs.set();
	bs[0] = bs[1] = 0;
	for(ll i = 2; i <= _sieve_size; i++){
		if(bs[i]){
			for(ll j = i*i; j <= _sieve_size; j += i) bs[j] = 0;
			primes.push_back(i);
		}
	}
} 
bool isPrime(ll n){
	if(n <= _sieve_size) return bs[n];
	for(int i = 0; i < (int)primes.size(); i++)
		if(n%primes[i] == 0) return false;
	return true;
} //only work for N <= (last prime in vi "primes")^2

map<ll,int> primeFactors(ll n){
	map<ll,int> factors;
	ll pf_idx = 0, pf = primes[pf_idx];
	int ans = 0;
	while(pf*pf <= n){
		while(n%pf == 0){ n /= pf; ans++;
			factors[pf]++;
		}
		pf = primes[++pf_idx];
	}
	if(n != 1){
		factors[n]++;
		ans++;
	}
	//return ans Number of prime factors of n
	return factors;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	sieve(10000000);
	ll N; cin >> N;
	map<ll,int> p = primeFactors(N);
	ll res = 0;
	for(auto &x : p){
		//cout << x.fi << ' ' << x.se << ":D\n";
		ll cnt = 1;
		ll act = 1;
		while(1){
			if(cnt*(cnt+1)/2 > x.se){
				break;
			}
			act = cnt;
			cnt++;
		}
		res += act;
	}
	cout << res << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


Measured memory_bytes: 8580
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

//vector string deque break continue
#define forn(i, s, f) for (int i = (int)s; i < (int)f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pf push_front
#define pb push_back
#define pop_f pop_front
#define pop_b pop_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

template <typename T> istream& operator>>(istream& in, vector <T>& a) {for (auto& i : a) in >> i; return in;}
template <typename T> ostream& operator<<(ostream& out, vector <T>& a)  {for (auto& i : a) out << i << " "; return out;}
template <typename T, typename U> void chkmin(T& a, U b) {if (a > b) a = b;}
template <typename T, typename U> void chkmax(T& a, U b) {if (a < b) a = b;}

const int MOD = 2019;

int add(int x, int y) {
    x += y;
    if (x >= MOD)
        return x - MOD;
    return x;
}

int sub(int x, int y) {
    x -= y;
    if (x < 0)
        return x + MOD;
    return x;
}

int mul(int x, int y) {
    return (1LL * x * y) % MOD;
}

int bin_pow(int a, int p) {
    if (!p)
        return 1;
    if (p % 2)
        return (1LL * bin_pow(a, p - 1) * a) % MOD;
    int t = bin_pow(a, p / 2);
    return (1LL * t * t) % MOD;
}

int inv(int x) {
    return bin_pow(x, MOD - 2);
}


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    int n = sz(s);
    forn (i, 0, n)
        s[i] -= '0';
    map <int, int> cnt;
    int sf = 0, p = 1;
    long long ans = 0;
    cnt[0] = 1;
    for (int i = n - 1; i >= 0; --i) {
        sf = add(sf, mul(s[i], p));
        p = mul(p, 10);
        //cout << sf << "\n";
        ans += cnt[sf];
        cnt[sf]++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3748
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: u32 = read();
    let first_number: i64 = read();
    let mut min: i64 = first_number;
    let mut max: i64 = first_number;
    let mut sum: i64 = first_number;

    for _ in 0..(n - 1) {
        let number: i64 = read();
        if number < min {
            min = number;
        } else if number > max {
            max = number;
        }
        sum += number;
    }
    println!("{} {} {}", min, max, sum);
}



Measured memory_bytes: 5048
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    print((n%2 + n // 2) / n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
// Digits in Multiplication
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;

int findLengthOfDigits(long int x) {
    int length = 0;
    while(x > 0) {
        x /= 10;
        length++;
    }
    return length;
}

int main() {
    long int N;
    cin >> N;
    int mi = 1 << 30;
    for (int i = 1; i <= sqrt(N); i++) {
        // 整数（割り切れてるものだけ）を抽出
        if (N / i * i == N) {
            mi = min(mi, max(findLengthOfDigits(i), findLengthOfDigits(N / i)));
        }
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<climits>
#include<cassert>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<bitset>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9
 
using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    string s;
    int k, kk = 0;
    cin >> s >> k;

    int n = (int)s.length();
    vector<string> v;
    map<string, bool> mp;
    rep(n){
        string t = "";
        reppp(j, 1, min(k, n-i)+1){
            t += s[i+j-1];
            if(!mp[t]) v.push_back(t);
            mp[t] = true;
        }
    }
    sort(all(v));
    cout << v[k-1] << endl;

    return 0;
}
   


Measured memory_bytes: 2048
n = int(input())
ss = [input() for i in range(n)]
ans = 0
a,b,ab = 0,0,0
for s in ss:
    ans += s.count('AB')
    if s[0] is 'B' and s[-1] is 'A':
        ab += 1
    elif s[0] is 'B':
        a += 1
    elif s[-1] is 'A':
        b += 1
m = min(a,b)
if ab != 0:
    if a+b>0:
        print(ans+ab+m)
    else:
        print(ans+ab-1)
else:
    print(ans+m)


Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    string s; cin >> s;
    int n = (int)s.size();
    bool isc = false;

    rep(i, n){
        if(i == 0 && s[0] != 'A'){
            cout << "WA" << endl;
            return 0;
        }
        if(i != 0){
            if(i > 1 && i < n-1 && s[i] == 'C'){
                if(isc){
                    cout << "WA" << endl;
                    return 0;
                }
                else{
                    isc = true;
                    continue;
                }
            }
            int p = s[i] - 'A';
            if(0 <= p && p <= 25){
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    if(!isc){
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
}

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

const int INF=1010101010;

int main() {
  int h,n; cin>>h>>n;
  vector<int> a(n),b(n);
  rep(i, n) cin>>a[i]>>b[i];
  vector<vector<int>> dp(n+1, vector<int>(h+10101));
  rep(i, n+1) rep(j, h+10101) dp[i][j]=INF;

  dp[0][0]=0;
  rep(i, n) {
    rep(j, h+10101) {
      if (j-a[i]>=0) dp[i+1][j]=min(dp[i][j], dp[i+1][j-a[i]]+b[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  int res=INF;
  for (int i=h; i<h+10101; i++) res=min(dp[n][i], res);
  cout<<res<<endl;
}

Measured memory_bytes: 78976
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  
  // hill climbing
  int lm = 0;
  int sc[26];
  for(;;) {
    if((xor64()>>25)&1) {
      int d = xor64()%D;
      int pi = t[d];
      last[pi].erase(d);
      for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
      int mi = std::max_element(sc, sc+26) - sc;
      t[d] = mi;
      last[mi].insert(d);
      if(mi != pi) lm = 0; else ++lm;
    } else {
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-16 || d2 < d1-16 || t[d1] == t[d2]) {
        d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
        ++lm;
      }
    }
    if(lm >= 100) break;
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3704
def comb(n,r,m):
	if r == 0: return 1
	return memf[n]*pow(memf[r],m-2,m)*pow(memf[n-r],m-2,m)
def memfact(a):
	temp = 1
	yield temp
	for i in range(1,a+1):
		temp = temp * i % 1000000007
		yield temp

K = int(input())
S = input()
s = len(S)
ans = 0
m = 1000000007
memf = []
for x in memfact(s+K-1):
	memf.append(x)
for i in range(K+1):
	ans = (ans+comb(s+K-i-1,K-i,m)*pow(25,K-i,m)*pow(26,i,m)) % m
print(ans)

Measured memory_bytes: 134344
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt(),f=0;
    int[] d1=new int[n],d2=new int[n];
    for(int i=0;i<n;i++){
      d1[i]=sc.nextInt();
      d2[i]=sc.nextInt();
      if(d1[i]==d2[i]){
        f++;
        if(f==3){
          System.out.println("Yes");
          break;
        }
      }else{
        f=0;
      }
    }
    if(f<3){
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 35964
#include<iostream>
#include<math.h>
using namespace std;
int n,m,ans=2019*2019;
int main()
{
	cin>>n>>m;
	if(m-n>=2019)
		cout<<0<<endl;
	else
	{
		 for(int i=n;i<m;i++)
			for(int o=i+1;o<=m;o++)
				ans=min(ans,((i%2019)*(o%2019)%2019));
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int e;
	bool first = true;
	while(cin >> e, e){
		int a, b, c, d; cin >> d >> c >> b >> a;
		if(!first) cout << endl;
		first = false;
		int itr[4];
		int res[4];
		int v[4] = {500, 100, 50, 10};
		int minVal = 10000;
		for(itr[0]=0;itr[0]<=a;itr[0]++){
			for(itr[1]=0;itr[1]<=b;itr[1]++){
				for(itr[2]=0;itr[2]<=c;itr[2]++){
					for(itr[3]=0;itr[3]<=d;itr[3]++){
						int sum = 0;
						for(int i=0;i<4;i++) sum += v[i] * itr[i];
						if(sum < e) continue;
						int lest = sum - e;
						int cnt = 0;
						bool ok = true;
						for(int i=0;i<4;i++){
							int add = lest/v[i];
							if(itr[i] > 0 && add > 0) ok = false;
							cnt += add;
							lest %= v[i];
						}
						cnt += a - itr[0];
						cnt += b - itr[1];
						cnt += c - itr[2];
						cnt += d - itr[3];
						if(ok && cnt < minVal){
							minVal = cnt;
							for(int i=0;i<4;i++) res[i] = itr[i];
						}
					}
				}
			}
		}
		for(int i=3;i>=0;i--){
			if(res[i] > 0) cout << v[i] << " " << res[i] << endl;
		}
	}
}

Measured memory_bytes: 1164
#pragma region header
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int, int> P;
using Graph = vector<vector<int> >;
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const double PI = acos(-1.0);
#pragma endregion
// cout << fixed << setprecision(14);

int main() {
    int K;
    cin >> K;
    rep(i, K) { cout << "ACL"; }
    cout << endl;
}

Measured memory_bytes: 3604
#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>;
using G = vector<vector<int>>;
    
int main(){
    string s;
    cin >> s;
    bool a = s[0]=='R' && s[1]=='R' && s[2]=='R';
    bool b = s[0]=='R' && s[1]=='R';
    bool c = s[1]=='R' && s[2]=='R';
    bool d = s[0]=='S' && s[1]=='S' && s[2]=='S';
    int ans = 1;
    if(a) ans = 3;
    else if(b || c) ans = 2;
    else if(d) ans = 0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
import numpy as np


def main():
    length = int(input())
    sequence = list(map(int, input().split()))
    answer = 0
    for i in range(3 ** length):
        ternary_i = np.base_repr(i, 3).zfill(length)
        now_product = 1
        for j in range(length):
            if ternary_i[j] == "0":
                now_product *= sequence[j]
            elif ternary_i[j] == "1":
                now_product *= sequence[j] + 1
            else:
                now_product *= sequence[j] - 1
        if now_product % 2 == 0:
            answer += 1
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 21148
n=int(input())
p=list(map(int,input().split()))
c=[0]*n
for i in range(n):
  if p[i]==i+1:c[i]=1
ans=0
for i in range(n-1):
  if c[i]*c[i+1]:
    ans+=1
    c[i],c[i+1]=0,0
print(ans+sum(c))

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

int main(){
	int n,a,b; cin>>n>>a>>b;
	int dis=b-a-1;
	if(dis%2==0) cout<<"Borys"<<endl;
	else cout<<"Alice"<<endl;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-
h, w = map(int, input().split())

if h == 1 or w == 1:
    print(1)
    exit()

if h % 2 == 0 and w % 2 == 0:
    print(h * w // 2)
    exit()

if h % 2 == 0 and w % 2 == 1:
    tmp = (h * (w - 1) // 2)
    print(tmp + (h // 2))
    exit()

if h % 2 == 1 and w % 2 == 0:
    tmp = ((h - 1) * w // 2)
    print(tmp + (w // 2))
    exit()

if h % 2 == 1 and w % 2 == 1:
    tmp = ((h - 1) * (w - 1) // 2)
    print(tmp + (h // 2) + (w // 2) + 1)
    exit()


Measured memory_bytes: 3064
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}
fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let K: usize = sc.get();
    let v = vec![1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
    println!("{}", v[K-1]);
}


Measured memory_bytes: 4352
#!/usr/bin/env python3

def main():
    N = int(input())
    gsba = list(map(int, input().split()))
    gsbb = list(map(int, input().split()))
    
    # ナップザック問題として解く
    w = gsba
    v = [gsbb[i]-gsba[i] for i in range(3)]
    dp = [0]*(N+1)

    for i in range(3):
        for j in range(N+1):
            if j >= w[i]:
                dp[j] = max(dp[j],dp[j-w[i]]+v[i])

    M = dp[-1] + N
    w = gsbb
    v = [gsba[i]-gsbb[i] for i in range(3)]
    dp = [0]*(M+1)

    for i in range(3):
        for j in range(M+1):
            if j >= w[i]:
                dp[j] = max(dp[j],dp[j-w[i]]+v[i])

    print(dp[-1] + M)

if __name__ == "__main__":
    main()

Measured memory_bytes: 261976
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
typedef long long LL;
typedef long double Lf;
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
#define rep(i,n)Rep(i,0,n)
#define Ma(x,y) ((x)>(y)?(x):(y))
#define mi(x,y) ((x)<(y)?(x):(y))
#define MOD 1000000007
int acs(const void* a, const void* b) { return *(int*)a - *(int*)b; } // 1,2,3,4
int des(const void* a, const void* b) { return *(int*)b - *(int*)a; } // 8,7,6,5
int cmp_char(const void* a, const void* b) { return *(char*)a - *(char*)b; } // a,b,c,d
int cmp_str(const void* a, const void* b) { return strcmp(*(const char**)a, *(const char**)b); } // aaa,aab
//temmie_のsnippet

#define N 200009

int main() {
	LL n, m, k, a, b, sa[N] = { 0 }, sb[N]={0};
	scanf("%lld%lld%lld", &n, &m, &k);
	rep(i, n) {
		scanf("%lld", &a);
		sa[i+1]=a+sa[i];
	}
	rep(i, m) {
		scanf("%lld", &b);
		sb[i + 1] = b + sb[i];
	}
	int ans = 0;
	rep(i, n+1) {//aの冊数固定
		if (sa[i] > k)break;
		LL p = k - sa[i];
		int q=0,r=m/2,s=m;
		while (s - q > 1) {
			r = (q + s) / 2;
			if (sb[r] <= p)q = r;
			else s = r;
		}
		if (sb[q] <= p)ans = Ma(ans, q+i);
		if (sb[r] <= p)ans = Ma(ans, r+i);
		if (sb[s] <= p)ans = Ma(ans, s+i);
	}

	printf("%d", ans);
}

Measured memory_bytes: 4832