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

#define ll long long

// 繰り返しに情報によって，累乗a^b (mod m)を計算する
ll mpow(ll a, ll b, ll m) {
  if (b == 1) return a;
  // b奇数のとき
  if (b % 2) return (a * mpow(a, b-1, m)) %m;
  // b偶数のとき
  ll t = mpow(a, b/2, m) %m;
  return (t * t) % m;
}


int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  const ll M = 1000000007;
  //全体 2^n
  ll ans = mpow(2, n, M) -1;
  
  
  
  // a,b本からなる花の数を引く(nCa, nCbを引く)
  ll x = 1;
  for (ll i = n; i >= n-a+1; i--) {
    x *= i;
    x %= M;
  } 
    
  for (ll i = 1; i <= a; i++) {
    x *=  mpow(i, M-2, M);
    x %= M;
  }
  ans -= x % M;
  
  
  x = 1;
  for (ll i = n; i >= n-b+1; i--) {
    x *= i;
    x %= M;
  } 
  for (ll i = 1; i <= b; i++) {
    x *= mpow(i, M-2, M);
    x %= M;
  }
  ans -= x % M;
  
  cout << (ans + 2 * M) % M << endl;
}




Measured memory_bytes: 256
using Primes
function divide(n)
    ans = 0
    temp = n
    for m in 1:n
        temp -= m
        temp < 0 && break
        ans += 1
    end
    return ans
end
function DivGame()
    N = parse(Int, readline())
    data = [c.second for c in collect(factor(N))]
    return println(sum(divide.(data)))
end
DivGame()

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

int main() {
  int X, Y, Z; cin >> X >> Y >> Z;

  int Ans = 0;
  int temp = Z;
  while(true) {
    temp += Y+Z;
    if ( temp<X )  {Ans++;}
    if ( temp==X ) {Ans++; break;}
    if ( temp>X )  {break;}
  }

  cout << Ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<algorithm>
using std::cout;
using std::cin;
using std::endl;

int main(void){
    int N;
    long long top[5]={};
    long long answer=0;
    std::string str;

    cin>>N;
    for(int i=0;i<N;i++){
        cin>>str;
        if(str[0]=='M'){
            top[0]++;
        }
        else if(str[0]=='A'){
            top[1]++;
        }
        else if(str[0]=='R'){
            top[2]++;
        }
        else if(str[0]=='C'){
            top[3]++;
        }else if(str[0]=='H'){
            top[4]++;
        }

    }

    for(int i=0;i<=2;i++){
        for(int j=i+1;j<=3;j++){
            for(int k=j+1;k<=4;k++){
                answer+=top[i]*top[j]*top[k];
            }
        }
    }
    cout<<answer<<endl;
	
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h, w;
    cin >> h >> w;
    char data[101][101];
    for(int i=1; i<=h; i++){
        for(int j=1; j<=w; j++){
            cin >> data[i][j];
        }
    }
    for(int i=1; i<=2*h; i++){
        for(int j=1; j<=w; j++){
            cout << data[(i+1)/2][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define mk make_pair
#define pb push_back
#define INF (ll)1e18
#define pii pair<ll,ll>
#define mod 1000000007 //998244353
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fb(i,a,b) for(ll i=a;i>b;i--)
#define ff first
#define ss second
#define PI 3.141592653589793238
#define pq priority_queue<ll>
#define pqr priority_queue<ll,vector<ll>,greater<ll>()>
using namespace std;
ll pow_mod(ll a,ll b)
{
	ll res=1;
	while(b!=0)
	{
		if(b&1)
		{
			res=(res*a)%mod;
		}
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}
void solve()
{
  string s;
  cin>>s;
  
  ll mx=0;
  
  for(ll i=0;i<3;i++){
      ll cntr=0;
      ll j=i;
      
      while(j<3&&s[j]=='R')
      j++,cntr++;
      
      mx=max(mx,cntr);
  }
  
  cout<<mx<<endl;
}
int32_t main()
{    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     cout.tie(NULL);
     
//Start from Here.

  ll t;
  t=1;
 // cin>>t;
  while(t--)
  solve();
  
//Good Bye!
    return 0;
}

Measured memory_bytes: 3652
#include<iostream>
#include<vector>
#include<set>
using namespace std;
// Problem https://atcoder.jp/contests/abc085/tasks/abc085_b

int solver(int allRice,vector<int> dia){
    int result=0;
//    for(int j=0;j<allRice;j++){
//        cout << dia.at(j) << " ";
//    }
//    cout << endl;
    set<int> dias;
    for(int j=0;j<allRice;j++){
        dias.insert(dia.at(j));
    }
    result = dias.size();
    return result;
}

int main(void){
    int answer;
    int N;
    cin >> N;
    vector<int> d(N);
    for(int j=0;j<N;j++){
        cin >> d.at(j);
    }
    answer = solver(N,d);
    cout << answer << endl;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
constexpr int INF = 1 << 29;
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

ll N, K;
ll bit[1000010];

void bitadd(int a, ll w) {
	for(int x = a; x <= N + 1; x += x & -x) bit[x] += w;
}
ll bitsum(int a) {
	ll ret = 0;
	for(int x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}

vector<int> compress(vector<ll> &A) {
	vector<ll> C = A;
	sort(C.begin(), C.end());
	C.erase(unique(C.begin(), C.end()), C.end());

	vector<int> ret(A.size());
	for (int i = 0; i < A.size(); i++) {
		ret[i] = lower_bound(C.begin(), C.end(), A[i]) - C.begin();
	}
	return ret;
}

int main() {
	vector<ll> B;
	cin >> N >> K;
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		B.push_back(sum - i * K);
		sum += a;
	}
	B.push_back(sum - N * K);
	vector<int> C = compress(B);

	ll ans = 0;
	for (int i = 0; i < C.size(); i++) {
		ans += bitsum(C[i] + 1);
		bitadd(C[i] + 1, 1);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4208
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl;
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
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;}
const string YES = "Yes";
const string NO = "No";
// clang-format on

void solve(long long A, long long B, long long C, long long D) {
  ll a = C / B, t = A / D;
  if (C % B == 0)
    a--;
  if (A % D == 0)
    t--;
  ANS((t >= a ? YES : NO));
}

// clang-format off
int main() {
  long long A;
  scanf("%lld",&A);
  long long B;
  scanf("%lld",&B);
  long long C;
  scanf("%lld",&C);
  long long D;
  scanf("%lld",&D);
  solve(A, B, C, D);
  return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

using namespace std;



int main()
{
	int n,k;
	int min=1;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		if (min*2 <= min+k) {
			min *= 2;
		}
		else {
			min += k;
		}
	}
	cout << min << endl;

	return 0;
}


Measured memory_bytes: 256
n,m,X,Y=map(int,input().split())
x=list(map(int, input().split()))
y=list(map(int, input().split()))
if min(y)>max(x):
    sec=list(range(max(x)+1,min(y)+1))
    for i in range(X+1,Y+1):
        if i in sec:
            print('No War')
            break
    else:
        print('War')
else:
    print('War')

Measured memory_bytes: 3064
#include <iostream>

int main()
{
  int N = 0;
  int n =0;
  int count = 0;
  std::cin >> N;

  if( N >= 10000 )
  {
    if(N >99999)
      N = 99999;
    count = 9 + 900;
    n = N - 10000 + 1;

  }
  else if( N >= 100)
  {
    if(N >999)
      N = 999;
    count = 9 ;
    n = N - 100 + 1;
  }
  else if( N >= 1 )
  {
    if(N > 9)
      N = 9;
    n = N;
  }



  count += n;

  std::cout << count << std::endl;



  return 0;
}


Measured memory_bytes: 256
n = STDIN.gets.chomp.to_i
x = Array.new(0)
u = Array.new(0)
for i in 1..n
  a, b = STDIN.gets.chomp.split(" ")
  x.push(a.to_f)
  u.push(b)
end

result = 0.0
for i in 0..(n-1)
  if u[i] == "JPY" then
    result += x[i]
  else
    result += x[i] * 380000.0
  end
end

puts result 


Measured memory_bytes: 1788
#include <iostream>
using namespace std;
int main()
{
    long long n, k;
    cin >> n >> k;
    bool flag = false;
    if (k % 2 == 0) {
        flag = true;
    }   
    if (flag) {
        long long j = k / 2;

        cout << (n / k) * (n / k) * (n / k) + (((n / j) + 1) / 2) * (((n / j) + 1) / 2) * (((n / j) + 1) / 2) 
             << endl;

    } else {
        cout << (n / k) * (n / k) * (n / k) << endl;
    }   
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
using namespace std;
const int N=210;
int f[2][N][N][N],g[2][N][N][N];
int n,m,sum[N][N];
bool full(int xa,int ya,int xb,int yb){
	int all=(xb-xa+1)*(yb-ya+1),s=sum[xb][yb]+sum[xa-1][ya-1]-sum[xa-1][yb]-sum[xb][ya-1];
	return !s||all==s;	
}
char s[N];
int main(){
	//freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){scanf("%s",s+1);
		for(int j=1;j<=m;j++)sum[i][j]=(s[j]=='#'),sum[i][j]+=sum[i][j-1];
	}
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)sum[i][j]+=sum[i-1][j];
	int cur=0;
	for(int i=1;i<=n;i++)for(int j=i;j<=n;j++)for(int c=1;c<=m;c++){
		int t=f[0][i][j][c-1];
		if(t<c&&full(i,c,j,c)) t=c;
		if(t>=c)while(t<m&&full(i,c,j,t+1))t++;else t=c-1;
		f[0][i][j][c]=t;
	}
	for(int i=1;i<=m;i++)for(int j=i;j<=m;j++)for(int c=1;c<=n;c++){
		int t=g[0][i][j][c-1];
		if(t<c&&full(c,i,c,j)) t=c;
		if(t>=c)while(t<n&&full(c,i,t+1,j)) t++;else t=c-1;
		g[0][i][j][c]=t;
	}
	for(int ans=0;ans<=20;ans++){
		if(f[cur][1][n][1]>=m){printf("%d\n",ans);return 0;}
		cur^=1;memset(g[cur],0,sizeof(g[cur]));
		memset(f[cur],0,sizeof(f[cur]));
		for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)for(int c=1;c<=m;c++){
			int t=f[cur^1][i][j][c];if(t>=m){f[cur][i][j][c]=m;continue;}
			t=f[cur^1][i][j][t+1];
			while(t<m){
				int d=g[cur^1][c][t+1][i];
				d=g[cur^1][c][t+1][d+1];
				if(d>=j)t++;else break;
			}f[cur][i][j][c]=t;
		}
		for(int i=1;i<=m;i++)for(int j=i;j<=m;j++)for(int c=1;c<=n;c++){
			int t=g[cur^1][i][j][c];if(t>=n){g[cur][i][j][c]=n;continue;}
			t=g[cur^1][i][j][t+1];
			while(t<n){
				int d=f[cur^1][c][t+1][i];
				d=f[cur^1][c][t+1][d+1];
				if(d>=j)t++;else break;
			}g[cur][i][j][c]=t;
		}
	}
}

Measured memory_bytes: 145152
#import <stdio.h>
int main() {
    int n,m;
    int T[200] = {0};
    int P[200] = {0};
    int X[200] = {0};
    scanf("%d", &n);
    for(int i=0;i<n;i++) {
        int t;
        scanf("%d", &t);
        T[i] = t;
    }
    scanf("%d", &m);
    for(int j=0;j<m;j++) {
        int p, x;
        scanf("%d %d", &p,&x);
        P[j] = p;
        X[j] = x;
    }
    for(int j=0;j<m;j++) {
        int count = 0;
        for(int i=0;i<n;i++) {
            count += i==P[j]-1 ? X[j] : T[i];
        }
        printf("%d\n", count);
    }
}


Measured memory_bytes: 4152
while True:
    a, op, b = input().split()
    if op == '?':
        break
    a = int(a)
    b = int(b)
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    else:
        print(a//b)

Measured memory_bytes: 7652
main :: IO ()                                                                                                              
main = do                                                                                                                  
  [a,b] <- map read . words <$> getLine :: IO [Int]                                                                        
  let ns = map show [a..b]                                                                                                 
      ms = map reverse ns                                                                                                  
  print $ length . filter id $ zipWith (==) ns ms

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

int main() {
  long long int q,h,s,d,n;
  cin >> q >> h >> s >> d >> n;
  h = min(h, 2*q);
  s = min(s, 2*h);
  if (2*s<=d) {
    cout << n*s << endl;
  }
  else {
    if (n%2==0) 
      cout << n/2 * d << endl;
    else
      cout << n/2 * d + s << endl;
  }
  return 0;
}
      

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

using namespace std;

#define long long long


int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    
    for (int i = 0; i < n; i++) cin >> a[i];
    
    long ans = 0;
    
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans += a[i] * a[j];
        }
    }
    
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
def main():
    d, n = map(int, input().split())
    answer = 100 ** d
    if 0 < d:
        while 0 < n:
            if answer % (100 ** d) == 0 and answer % (100 ** (d + 1)) > 0:
                n -= 1
            answer += 100 ** d
        answer -= 100 ** d
    else:
        answer = n if n < 100 else 101
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D;
  cin>>N>>A>>B>>C>>D;
  string s;
  cin>>s;
  int t = 0;
  int p = 0;
  bool k = 0;
  bool m = 0;
  for(int i = A-1;i<C;i++){
    if(s.at(i) == '#'){
      t++;
    }
    else{
      t = 0;
    }
    if(t>=2){
      k = 1;
    }
  }
  t = 0;
  for(int i = B-1;i<D;i++){
    if(s.at(i) == '#'){
      t++;
    }
    else{
      t = 0;
    }
    if(t>=2){
      k = 1;
    }
  }
  if(C>D){
    m = 1;
    for(int i = B-2;i<D+1;i++){
      if(s.at(i) == '.'){
        p++;
      }
      else{
        p = 0;
      }
      if(p>=3){
        m = 0;
      }
    }
  }
  if(m == 0 && k == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int a,b,c,d;
vector<int> v;
int aa[4]={1,4,7,9};

int main(){
  cin>>a>>b>>c>>d;
  v.push_back(a);
  v.push_back(b);
  v.push_back(c);
  v.push_back(d);
  sort(v.begin(),v.end());
  REP(i,4){
    if(v[i]!=aa[i]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<string,int> P;

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

    int sl = s.size();
    int tl = t.size();

    char sch[sl], tch[tl];
    for(int i=0;i<sl;i++){
        sch[i] = s[i];
    }
    sort(sch, sch+sl);

    string s_prime = "";
    for(int i=0;i<sl;i++){
        s_prime += sch[i];
    }

    for(int i=0;i<tl;i++){
        tch[i] = t[i];
    }
    sort(tch, tch+tl);

    string t_prime = "";
    for(int i=0;i<tl;i++){
        t_prime += tch[tl - 1 - i];
    }
    

    if(s_prime < t_prime) cout << "Yes" <<endl;
    else cout << "No" <<endl;




    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    string s;
    cin >> s;
    rep(i, 0, 3)
    {
        if (s[i] == s[i + 1])
        {
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(cont) cont.begin(), cont.end()
#define pb push_back
#define fi first
#define se second
#define DEBUG(x) cerr << (#x) << ": " << (x) << '\n'

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

template<class T> bool uin(T &a, T b) {return (a < b ? false : (a = b, true));}
template<class T> bool uax(T &a, T b) {return (a > b ? false : (a = b, true));}

//ifstream f(".in");
//ofstream g(".out");

const int MOD = 1e9 + 7;
const int NMAX = 2e5 + 5;

int fact[NMAX];
int tcaf[NMAX];

int mul(int a, int b) {
  return (1LL * a * b) % MOD;
}

void sub(int &a, int b) {
  a -= b;
  if (a < 0) {
    a += MOD;
  }
}

int lgPow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) {
      ret = mul(ret, b);
    }
    b = mul(b, b);
    e >>= 1;
  }
  return ret;
}

void precalc(int n) {
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) {
    fact[i] = mul(fact[i - 1], i);
  }
  tcaf[n] = lgPow(fact[n], -1);
  for (int i = n - 1; i >= 0; --i) {
    tcaf[i] = mul(tcaf[i + 1], i + 1);
  }
}

int choose(int n, int k) {
  return mul(fact[n], mul(tcaf[k], tcaf[n - k]));
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL_DEFINE
  freopen(".in", "r", stdin);
#endif

  int h, w, n;
  cin >> h >> w >> n;
  precalc(h + w);
  vector<pair<int, int>> cell(n + 3);
  for (int i = 1; i <= n; ++i) {
    int x, y;
    cin >> x >> y;
    cell[i] = {x, y};
  }
  cell[++n] = {h, w};

  sort(cell.begin() + 1, cell.begin() + n + 1);

  vector<int> dp(n + 2);
  for (int i = 1; i <= n; ++i) {
    int x, y;
    tie(x, y) = cell[i];
    dp[i] = choose(x + y - 2, x - 1);
    for (int j = 1; j <= i - 1; ++j) {
      if (x >= cell[j].fi && y >= cell[j].se) {
        sub(dp[i], mul(dp[j],
                       choose(x - cell[j].fi + y - cell[j].se, x - cell[j].fi)));
      }
    }
  }

  cout << dp[n] << '\n';

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


Measured memory_bytes: 1920
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
#define N 2000005 //命令の数の最大量
int A[N],j=0;
 
int Parent(int i){ //親のアドレス値
  return i/2;
}
int Left(int i){ //左の子のアドレス値
  return 2*i;
}
int Right(int i){ //右の子のアドレス値
  return 2*i+1;
}
 
void heapIncreaseKey(int i,int key){
	int tmp;
  if(key<A[i])  return; //例外エラー処理
  A[i]=key; //挿入
  while(i>1 && A[Parent(i)]<A[i]){ //今回挿入した子が、その親より大きい場合は入れ替える、そして親＞子の関係になるまで繰り返す
    tmp=A[i];
    A[i]=A[Parent(i)];
    A[Parent(i)]=tmp;
    i=Parent(i);
  }
}
 
void maxHeapInsert(int key){ //A[j]にkeyをインサートします
  j++;
  A[j]=-1; //小さい値を入れます（keyの最小値が０なので、ここではー１）
  heapIncreaseKey(j,key); //ここで挿入
}
 
void maxHeapify(int i){ //最大値削除に伴う辻褄合わせ。末端の値が木の一番上に来たので、それ（i）を親＞子の関係が成立するまで下げていく
  int tmp,l=Left(i),r=Right(i),largest;
 
  if(l<=j && A[l]>A[i]) largest=l;
  else largest=i;
 
  if(r<=j && A[r]>A[largest])largest=r;
 
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(largest);
  }
}
 
int heapExtractMax(){ //最大値のリターン、削除
  int max;
  if (j<1) return 0; //例外エラー処理
  max=A[1]; //maxに木の一番上の値を入れる
  A[1]=A[j]; //木の一番上に木の末端の値を入れる
  j--; //末端のアドレス値を一つ消す
  maxHeapify(1);
  return max;
}
 
main(){
  char str[20];
  int key;
   
  while(1){ //無限ループ回しましょうか
    scanf("%s",str); //まずは文字の読み込み
    if(strcmp(str,"end")==0) break; //文字列がendでループ抜ける
 
    if(str[0]=='i') { //文字列がinsertでkeyをinsert
      scanf("%d",&key);
      maxHeapInsert(key);
    }
    else printf("%d\n",heapExtractMax()); //文字列がextractで最大値を出力、および木から最大値の削除
  }
  return 0;
}

Measured memory_bytes: 4696
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvl vector<vll>
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define vpii vector<pii >
#define vpll vector<pll >
#define ff first
#define ss second
#define PI 3.14159265358979323846
#define fastio ios_base::sync_with_stdio(false) , cin.tie(NULL) ,cout.tie(NULL) 

using namespace std;

ll dp[101][100001];
ll knapsack(int a[],int b[],int n,int w)
{
	 if(n==0||w==0)
	 return 0;
	 
	 if(dp[n][w]!=-1)
	 return dp[n][w];
	 
	 if(a[n-1]<=w)
	 {
	 	return dp[n][w]=max(b[n-1]+knapsack(a,b,n-1,w-a[n-1]),knapsack(a,b,n-1,w));
	 }
	 else
	 return dp[n][w]=knapsack(a,b,n-1,w);
}

int main(){
    fastio;
    int n,w;
    cin>>n>>w;
    int wt[n+1],val[n+1];
    for(int i=0;i<n;i++) cin>>wt[i]>>val[i];
    memset(dp,-1,sizeof(dp));
    cout<<knapsack(wt,val,n,w);
    return 0;
}


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

int n,P,Q,R,C,flag;
struct DATA{
int name,p,f,c,cal,sum,flag;
};
DATA data[1001];

int main(){
	while(1){
		flag=0;
		for(int i=0;i<n;i++){data[i].flag=0;}
		cin>>n;
		if(n==0){break;}
		for(int i=0;i<n;i++){
			cin>>data[i].name>>data[i].p>>data[i].f>>data[i].c;
			data[i].cal=data[i].p*4+data[i].f*9+data[i].c*4;
		}
		cin>>P>>Q>>R>>C;
		for(int i=0;i<n;i++){
			if(data[i].p<=P && data[i].f<=Q && data[i].c<=R && data[i].cal<=C){
				data[i].flag=1;
			}
		}
		for(int i=0;i<n;i++){
			if(data[i].flag==1){
				cout<<data[i].name<<endl;
				flag++;
			}
		}
		if(flag==0){cout<<"NA"<<endl;}
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<n; i++)
#define SORT(x) sort(x.begin(), x.end(), greater<ll>())
using namespace std;
typedef long long ll;

int main() {
    ll X, Y, Z;
    ll K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X), B(Y), C(Z);
    vector<ll> ans;
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    SORT(A); SORT(B); SORT(C);
    rep(x, X){
        rep(y, Y){
            rep(z, Z){
                if((x+1)*(y+1)*(z+1) <= K) ans.push_back(A[x] + B[y] + C[z]);
                else break;
            }
        }
    }
    SORT(ans);
    rep(i, K) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

int g[15][15]; // グラフとして受け取る

int main() {
    int n;
    cin >> n;
    rep(i,n)rep(j,n) g[i][j] = -1;
    rep(i,n) {
        int m;
        cin >> m;
        rep(j,m) {
            int a, x;
            cin >> a >> x;
            --a;
            g[i][a] = x;
        }
    }

    int ans = 0;
    rep(i,1<<n) {
        vector<int> d(n);
        rep(j,n) if (i>>j&1) { // i の j ビット目が立っているかどうか
            d[j] = 1;
        }
        bool ok = true;
        rep(j,n) {
            if (d[j]) {
                rep(k,n) {
                    if (g[j][k] == -1) continue;
                    if (g[j][k] != d[k]) ok = false;
                }
            }
        }

        if (ok) ans = max(ans, __builtin_popcount(i));
    }

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

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  char str[222];
  scanf("%s", str);
  int n = strlen(str);
  for(int i = n-2; i; i-=2) {
    if(strncmp(str, str+i/2, i/2) ==0) {
      printf("%d\n", i);
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k; cin >> n >> k;
    if(n <= k){
        cout << min(n,k-n) << endl;
    }else{
        cout << min((n%k),k-(n%k)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
#include <climits>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
        // setw(6) << setfill('0')
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << "(" << v.first << ", " << v.second << ")";
    return ostr;
}

int64 powmod(int64 n, int64 count, int64 mod) {
    if (count == 0) return 1;
    if (count % 2 == 0) {
        int64 t = powmod(n, count / 2, mod);
        return t * t % mod;
    }
    return n * powmod(n, count - 1, mod) % mod;
}

int64 ncr(int64 n, int64 r, int64 mod) {
    int64 a;
    if (n < r) a = min(n, r - n);
    else a = min(n - r, r);

    int64 res = 1;
    rep(i, a) {
        res = res * (n - i) % mod;
        res = res * powmod(i + 1, mod - 2, mod) % mod;
    }

    return res;
}

int main() {
    int64 a, b;
    cin >> a >> b;

    if (a == 1 && b == 1) {
        cout << 1 << endl;
    } else if (a == 2 || b == 2) {
        cout << 0 << endl;
    } else if  (a == 1 || b == 1) {
        cout << max(a, b) - 2 << endl;
    } else {
        cout << (a - 2) * (b - 2) << endl;
    }

    // vector<vector<char>> v(a, vector<char>(b, '0'));

    // rep(i, a) {
    //     rep(j, b) {
    //         reps(-1, x, 2) reps(-1, y, 2) {
    //             if (i + x >= 0 && i + x < a && j + y >= 0 && j + y < b) {
    //                 if (v[i+x][j+y] == '0') {
    //                     v[i+x][j+y] = '1';
    //                 } else {
    //                     v[i+x][j+y] = '0';
    //                 }
    //             }
    //         }
    //     }
    // }

    // rep(i, a) {
    //     cout << v[i] << endl;
    // }
}


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

namespace jm
{
	const int N=52,MOD=1000000007;
	inline void inc(int a,int &b){b+=a;if(b>=MOD)b-=MOD;}
	int f[N][N*2][N*2],s[N*2];
	int n;
	void initialize()
	{
		scanf("%d",&n);
		for(int i=1;i<=n*2-1;i++)
			scanf("%d",s+i);
		std::sort(s+1,s+n*2);
	}
	void dp()
	{
		f[n][1][1]=1;
		for(int i=n;i>1;i--)
		{
			int ad=(s[i]!=s[i-1]),au=(s[n*2-i]!=s[n*2-i+1]);
			for(int j=1;j<=n*2-1;j++)
				for(int k=1;k<=j;k++)
				{
					int v=f[i][j][k],oj,ok;
					if(!v)continue;
					
//					printf("f[%d][%d][%d] = %d\n",i,j,k,v);

					oj=j+ad+au,ok=k+ad;
					for(int l=1;l<=ok;l++)inc(v,f[i-1][l+oj-ok+(l!=ok)][l]);
					for(int l=ok+1;l<=oj;l++)inc(v,f[i-1][ok+oj-l+1][ok+1]);
				}
		}
	}
	void solve()
	{
		initialize();
		dp();
		int ans=0;
		for(int i=1;i<=n*2-1;i++)
			for(int j=1;j<=n*2-1;j++)
				inc(f[1][i][j],ans);
		printf("%d\n",ans);
	}
}

int main()
{
//	freopen("F.in","r",stdin);
//	freopen("F.out","w",stdout);
	jm::solve();
	return 0;
}


Measured memory_bytes: 1408
from collections import deque

#
# N = 3
# ARR = [[[2],[3]], [[3],[1]], [[1],[2]]]

# N = 3
# ARR = [[[2],[]],[[1],[]],[[],[2]]]


# N = 2
# ARR = [[[], [2]], [[], [1]]]

N = int(input())
ARR = []

for i in range(N):
    A = int(input())
    X = []
    Y = []
    for j in range(A):
        x, t = map(int, input().split())
        if t == 1:
            X.append(x)
        else:
            Y.append(x)
    ARR.append([X,Y])

def calculate(n, arr):
    result = []
    for i in range(2 ** n):
        q = deque()
        possibilities = []
        teacherGoods = set()
        teacherBads = set()
        for j in range(n):
            identity = (i >> j & 1) == 1
            if identity:
                q.append(j)
                possibilities.append(identity)
                teacherGoods.add(j + 1)
            else:
                teacherBads.add(j + 1)
            # j 第几号人
            # i >> j & 1 第几号人是好人还是坏人
        res = judge(q, arr, teacherGoods, teacherBads)
        if res == True:
            result.append(sum(possibilities))

    print(max(result))


def judge(possibilities, arr, teacherGoods, teacherBads):
    goodMans = set()
    badMans = set()
    trueStatus = {}
    result = True
    while len(possibilities) > 0:

        trueIndex = possibilities.popleft()
        if trueStatus.get(trueIndex) == True:
            continue
        trueStatus.__setitem__(trueIndex, True)
        for g in arr[trueIndex][0]:
            goodMans.add(g)
            possibilities.append(g - 1)
        for b in arr[trueIndex][1]:
            badMans.add(b)

        if len(list(goodMans & teacherBads)) > 0:
            result = False
            break

        if len(list(badMans & teacherGoods)) > 0:
            result = False
            break
    return result


calculate(N, ARR)


Measured memory_bytes: 3700
#include<stdio.h>
#include<math.h>
int main()
{
    long long int N,X,i,sum,count,ara[10000];
    scanf("%lld %lld",&N,&X);
    for(i=0;i<N;i++)
    {
        scanf("%lld",&ara[i]);
    }
    sum=0;
    count=1;
    for(i=0;i<N;i++)
    {
        sum+=ara[i];
        if(sum<=X)
        {
            count++;
        }
        else
        {
            break;
        }
    }
    printf("%lld\n",count);
    return 0;
}

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

bool palindrome(string s){
	if (s == string(s.rbegin(), s.rend())){
		return true;
	} else {
		return false;
	}
}


int main() { 
	string m;
	cin >> m;
	int n = m.length();
	string gh = m.substr(0, (n-1)/2);
	string kk = m.substr((n+3)/2 - 1, n - (n+3)/2 + 1);
	if (palindrome(gh) && palindrome(kk) && palindrome(m)){
		cout << "Yes";
	} else {
		cout << "No";
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>

#define ll long long
#define db double
#define inf 0x7fffffff
#define rg register int

using namespace std;

int n,m;
string a[503],b[503],c[503];


inline int qr(){
	char ch;
	while((ch=getchar())<'0'||ch>'9');
	int res=ch^48;
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+(ch^48);
	return res;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=qr(),m=qr();
	for(rg i=0;i<n;++i){
		getline(cin,a[i]);
		b[i]=c[i]=a[i];
	}
	for(rg i=1;i<n-1;i+=2)
		for(rg j=0;j<m-1;++j)
			b[i][j]='#';
	for(rg i=0;i<n;++i)
		b[i][0]='#';
	for(rg i=2;i<n-1;i+=2)
		for(rg j=1;j<m;++j)
			c[i][j]='#';
	for(rg i=0;i<n;++i)
		c[i][m-1]='#';
	for(rg i=0;i<n;++i)
		cout<<b[i]<<endl;
	puts("");
	for(rg i=0;i<n;++i)
		cout<<c[i]<<endl;
	return 0;
}


Measured memory_bytes: 1536
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        String arr01[] = mylist.get(0).split(" ");

        int l = Integer.valueOf(arr01[0]);
        int r = Integer.valueOf(arr01[1]);

        //        int l = 2022;
        //        int r = l + 2019;
        int mindata = 9999;

        int cnt = 0;
        int num = Math.min(2019, r - l - 1);

        for (int i = l; i <= r; i++) {
            for (int j = i + 1; j <= r; j++) {

                int amari1 = i % 2019;
                int amari2 = j % 2019;
                int amari3 = (amari1 * amari2) % 2019;
                mindata = Math.min(mindata, amari3);

                //                System.out.println(i + " " + j + " " + amari3 + " " + mindata);
                if (mindata == 0) {
                    System.out.println(mindata);
                    return;
                }

            }
        }
        System.out.println(mindata);

    }

}


Measured memory_bytes: 23124
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (long long int)1e18

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    while (1) {
        int n;
        int m;
        cin >> n >> m;
        if (n == 0 && m == 0) {
            break;
        }
        Vec<int> c(m);
        Vec<int> x(n + 1);
        for (int i = 0; i < m; i++) {
            cin >> c[i];
        }
        for (int j = 1; j <= n; j++) {
            cin >> x[j];
        }
        
        Vec<Vec<long long int> > dp(n + 1, Vec<long long int>(256));
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j < 256; j++) {
                dp[i][j] = INF;
            }
        }
        dp[0][128] = 0;

        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < 256; j++) {
                for (int k = 0; k < m; k++) {
                    long long int div = j + c[k];
                    if (div > 255) {
                        div = 255;
                    } else if (div < 0) {
                        div = 0;
                    }
                    long long int cost = (x[i] - div) * (x[i] - div);
                    dp[i][div] = min(dp[i][div], dp[i - 1][j] + cost);
                }
            }
        }
        long long int ans = dp[n][0];
        for (int j = 1; j < 256; j++) {
            ans = min(ans, dp[n][j]);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 43812
N=int(input())
A=list(map(int,input().split()))
flag=False
ans=0
while True:
    for i,j in enumerate(A):
        if j%2!=0:
            print(ans)
            flag=True
            break
        else:
            A[i]=j/2
    ans+=1 
    if flag:
        break

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

using namespace std; 
 
#define int long long
#define M 1000000007
 
signed main(){
	
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
	int x;
	cin >> x;
	cout << 1-x << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

void cout_vec(vector<int> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> A(N,0);
    vector<int> B(M,0);
    
    vector<int> row(N*M+2,0);
    vector<int> column(N*M+2,0);
    
    for(int i=0; i<N; i++){
        cin >> A[i];
        row[A[i]]+=1;
        if(row[A[i]]==2){
            cout << 0 << endl;
            return 0;
        }
    }
    for(int i=0; i<M; i++){
        cin >> B[i];
        column[B[i]]+=1;
        if(column[B[i]]==2){
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i=N*M; i>0; i--){
        row[i-1]+=row[i];
        column[i-1]+=column[i];
    }
    //cout_vec(row);
    //cout_vec(column);
    long long ans=1;
    for(int i=N*M; i>0; i--){
        long long r= row[i];
        long long c= column[i];
        if(r-row[i+1]==0 && c-column[i+1]==0){
            ans*=r*c-(N*M-i);
        }else if(r-row[i+1]==1 && c-column[i+1]==0){
            ans*=c;
        }else if(r-row[i+1]==0 && c-column[i+1]==1){
            ans*=r;
        }
        ans%=MOD;
        //cout << i << ' ' << ans << endl;
        if(ans <= 0){
            cout << 0 << endl;
            return 0;
        }
    }

    cout << ans << endl;

}

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

int main() {
  string S;
  char c;
  int ans = 0;

  cin >> S;
  c = S.at(0);

  for(int i=1;i<S.size();++i){
    if(S.at(i) == c){
      if(S.at(i) == '1'){
        S.at(i) = '0';
        ans++;
      }else{
        S.at(i) = '1';
        ans++;
      }
    }
    c = S.at(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3700
#include<iostream>
using namespace std;
int main(){
  string s; cin >> s;
  int a[30]={0};
  for(char c:s){
    a[c-'a']++;
  }
  for(int i=0;i<26;i++){
    if(a[i]>=2){
      cout << "no" << endl;
      return 0;
    }
  }
  cout << "yes" << endl;
  return 0;
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    string s;
    cin >> s;
    
    int cnt = 0;
    for (int i = 1; i < n; i++){
        if (s[i] == s[i - 1])
            cnt += 1;
    }

    cout << min(n - 1, cnt + k * 2) << '\n';

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    string s, p;
    cin >> s >> p;
    s += s;
    if(s.find(p)!=string::npos) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1192
#include<vector>
#include <iostream>
#include<string>
#include <complex>
#include <algorithm>
#include<string>

using namespace std;

int main(){
    int x, y;
    cin >> x;
    cin >> y;

    int flag = 0;

    for(int i = 0;i <= x; i++){
        int n = y - 2*i;
        int z = x-i;
        if(n - z*4 == 0){
            flag = 1;
        }
    }


    if(flag == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }

}

Measured memory_bytes: 3636
{-# LANGUAGE CPP #-}
module Main where

import qualified Data.Vector.Unboxed as V 
import qualified Data.Map.Strict as M
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.Char
import qualified Data.List as L

dump :: (Show a) => a -> IO()
#if __GLASGOW_HASKELL__ >= 800
dump x = print x
#else
dump _ = pure ()
#endif

-- "101010" -> [1,0,1,0,1,0]
readToList :: String -> [Int]
readToList [] = []
readToList (x:xs) = read [x] : readToList xs

 
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getList :: IO [Int]
getList = (fmap (read . BS.unpack) . BS.words) <$> BS.getLine

-- "10 10 10" -> [10, 10, 10]
getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readmat :: Int -> IO [[Int]]
readmat rows = replicateM rows getList

newtype UF a = UF (M.Map a a) deriving (Show) -- Map node parent

makeuf :: Int -> UF Int
makeuf n = let m = M.fromList $ zip [0..n] [0..n]
                in UF m

unionUF :: (Eq a, Ord a) => a -> a -> UF a -> UF a
unionUF l r uf@(UF m) = let lp = findUF l uf
                            rp = findUF r uf
                        in if lp == rp
                           then uf
                           else if size l uf < size r uf
                                then UF $ M.update (const $ Just rp) lp m
                                else UF $ M.update (const $ Just lp) rp m

findUF :: (Eq a, Ord a) => a -> UF a -> a
findUF x uf@(UF m) = let px = m M.! x
                      in if px == x
                         then px
                         else findUF px uf -- TODO 貼り直し

size :: (Eq a, Ord a) => a -> UF a -> Int
size x (UF m) = M.size $ M.filter (\par -> par==x) m

genbit :: Int -> [[Int]]
genbit 0 = []
genbit 1 = [[0],[1]]
genbit len = do
  x <- [0,1]
  map (x:) $ genbit (len-1)

base :: Int
base = 10 ^ 9 + 7

forn :: (Num a, Enum a, Monad m) => a -> (a -> m b) -> m [b]
forn x = forM [0..(x-1)]

count :: (Eq a) => a -> [a] -> Int
count y = length . filter (== y)

main :: IO()
main = do
  n <- getInt
  s <- getLine
  let f i c = chr $ (ord c + i - ord 'A') `mod` 26 + ord 'A'
  dump $ f 3 'a'
  putStrLn $ map (f n) s


Measured memory_bytes: 1404
#include<bits/stdc++.h>
#define MAX 100010
#define inf 1<<30
#define linf 1e16
#define eps (1e-8)
#define mod 1000000007
#define pi acos(-1)
#define phi (1.0+sqrt(5))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};
 
int v,e,r;
vector<pii> g[MAX];
 
void dijkstra(){
  int d[MAX];
  priority_queue<pii,vector<pii>,greater<pii> > pq;
  fill(d,d+MAX,inf);
  d[r]=0;
  pq.push(mp(0,r));
 
  while(pq.size()){
    pii u=pq.top();
    pq.pop();
    if(d[u.s]<u.f)continue;
 
    FOR(i,0,g[u.s].size()){
      int next=g[u.s][i].f;
      int cost=d[u.s]+g[u.s][i].s;
      if(cost<d[next]){
        d[next]=cost;
        pq.push(mp(cost,next));
      }
    }
  }
  FOR(i,0,v){
    if(d[i]==inf)printf("INF\n");
    else printf("%d\n",d[i]);
  }
  return;
}
 
int main()
{
  scanf("%d%d%d",&v,&e,&r);
  FOR(i,0,e){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    g[a].pb(mp(b,c));
  }
  dijkstra();
  return 0;
}


Measured memory_bytes: 13064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main () {
	int N;
	vector < pair <int, int> > v;
	cin >> N;
	for (int i=1; i<=N; i++) {
		int tmp;
		cin >> tmp;
		v.push_back (make_pair (tmp, i));
	}
	sort (v.begin (), v.end ());
	for (int i=0; i<N; i++)
		cout << v.at (i).second<< " ";
	cout << endl;
	return 0;
}

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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll inf = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/


int main(){
    fIO

    ll a, b;
    cin >> a >> b;

    vector<ll> divs;
    ll g = __gcd(a, b), curr = g;
    int ans = 0;
    for(ll i = 2; i * i <= g; i++){
        if(curr % i == 0){
            while(curr % i == 0) curr /= i;
            ans++;
        }
    }
    if(curr > 1) ans++;

    cout << ans + 1;



}








Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(S: str):
    print(min(S.count("0"), S.count("1")) * 2)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
const int N=1e6;
int f[N+10][2],g[N+10],a[N+10];
int n;
void Update(int *g,int *f) {
    if (f[0]>g[0]) {
        g[1]=g[0];
        g[0]=f[0];
        g[1]=max(g[1],f[1]);
    }
    else if (f[0]>g[1]) g[1]=f[0];
}
void work() {
    for (int i=0;i<(1<<n);i++) {
        f[i][0]=a[i];
        f[i][1]=-1e9;
    }
    for (int i=0;i<n;i++)
        for (int j=(1<<n)-1;j>=0;j--) {
            if (j&(1<<i)) continue;
            Update(f[j|(1<<i)],f[j]);
        }
}
int main() {
    scanf("%d",&n);
    for (int i=0;i<(1<<n);i++)
        scanf("%d",&a[i]);
    work();
    for (int i=0;i<(1<<n);i++) {
        g[i]=f[i][0]+f[i][1];
        if (i) {
            g[i]=max(g[i-1],g[i]);
            printf("%d\n",g[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 12288