akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -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 (a>b) { a=b; return 1; } return 0; }



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

  cout << z << " " << x << " " << y << endl;



  
  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define fi first
#define se second 

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

// End of template code!
int main() 
{
    buff();
    int n, k, c;
    cin >> n >> k >> c;
    string S;
    cin >> S;
    vector<int> suff_work(n, 0);
    vector<int> pref_work(n, 0);
    for(int i = n - 1; i >= 0; --i) {
        int nxt = i + c + 1;
        int add = (nxt < n ? suff_work[nxt] : 0);
        if(i < n - 1) suff_work[i] = suff_work[i + 1];
        if( S[i] == 'o' ) suff_work[i] = max(suff_work[i], add + 1);
    }
    
    for(int i = 0; i < n; ++i) {
        int prv = i - c - 1;
        int add = (prv >= 0 ? pref_work[prv] : 0);
        if(i > 0) pref_work[i] = pref_work[i - 1];
        if(S[i] == 'o') pref_work[i] = max(pref_work[i], add + 1);
    }

    // quero testar cada dia pra ver se ele eh necessario
    for(int i = 0; i < n; ++i) 
    {
        int prv = i - 1;
        int nxt = i + 1;
        int before = ( prv >= 0 ? pref_work[prv] : 0);
        int after  = ( nxt < n ? suff_work[nxt] : 0);
        if(after + before < k) cout << i + 1<< '\n';
    }

    return 0;
}



Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5,mod=1e9+7;
ll fct[N],inv[N],invfct[N];
ll power(ll n,ll p){
    ll ans=1;
    while(p){
        if(p&1)ans*=n,ans%=mod;
        p>>=1;
        n*=n;
        n%=mod;
    }
    return ans;
}
inline void init(){
    fct[0]=fct[1]=1;
	inv[1]=1;
	invfct[0]=invfct[1]=1;
	for(ll i=2;i<N;i++){
		fct[i]=i*fct[i-1]%mod;
		inv[i]=ll(mod-inv[mod%i])*(mod/i)%mod;
		invfct[i]=ll(inv[i])*invfct[i-1]%mod;
	}
}
ll n,sz[N],dp[N],ans[N];
vector<ll> adj[N];
void dfs(ll node,ll pr){
    sz[node]=1;
    ll num=1,dem=1;
    for(auto &ele:adj[node]){
        if(ele==pr)continue;
        dfs(ele,node);
        dem*=invfct[sz[ele]];
        dem%=mod;
        num*=dp[ele];
        num%=mod;
        sz[node]+=sz[ele];
    }
    dp[node]=num*dem;
    dp[node]%=mod;
    dp[node]*=fct[sz[node]-1];
    dp[node]%=mod;
}
void dfs2(ll node,ll pr,ll s1,ll v1){
    if(node!=pr){
        ans[node]=dp[node]*invfct[sz[node]-1]%mod;
        ans[node]=ans[node]*fct[n-1]%mod;
        ans[node]=ans[node]*invfct[s1]%mod;
        ans[node]=ans[node]*v1%mod;
    }
    else ans[node]=dp[node];
    ll prod=ans[node],org=ans[node];
    for(auto &ele:adj[node]){
        if(ele==pr)continue;
        prod = prod*power(dp[ele],mod-2)%mod;
        prod = prod*fct[sz[ele]]%mod;
        prod = prod*invfct[n-1]%mod;
        prod = prod*fct[n-1-sz[ele]]%mod;
        dfs2(ele,node,n-sz[ele],prod);
        prod=org;
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    init();
    cin>>n;
    for(ll i=1;i<n;i++){
        ll u,v;cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1,1);
    dfs2(1,1,0,0);
    for(ll i=1;i<=n;i++)cout<<ans[i]<<"\n";
}


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

int main(){
  int n, q;
  cin >> n >> q;

  bool memo[300010] = {};
  int mn[300010] = {};

  int c;
  for(int i = 0;i < n;i++){
    cin >> c;
    memo[c] = true;
  }


  for(int i = 1;i <= 300000;i++){
    if(memo[i]) mn[i] = i;
    else mn[i] = mn[i-1];
  }

  int qq;
  for(int p = 0;p < q;p++){
    cin >> qq;
    int ans = mn[300000] % qq;
    for(int i = qq;i <= 300000;i += qq){
      ans = max(ans, mn[i-1] % qq);
    }
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 4572
#include <iostream>

int main(void){
  int a,b,r,num;

  std::cin >> a;
  std::cin >> b;

  r = b-1;
  num=0;
  while(r>0){
    r -= a-1;
    num++;
  }
  std::cout << num;
  
  return 0;
}


Measured memory_bytes: 256
def zeros(n):
    ret = 0
    while n != 0:
        if n % 2 == 0:
            ret += 1
            n //= 2
        else:
            break
    return ret

N = int(input())
for i in range(1,N):
    a = []
    for j in range(i+1,N+1):
        d = j - i
        z = zeros(d)
        a.append(z+1)
    print(' '.join(map(str, a)))

Measured memory_bytes: 43356
'use strict'

const main = (input) => {
    const A = parseInt(input.split(' ')[0])
    const B = parseInt(input.split(' ')[1])

    if(A * B % 2 !== 0){
        console.log('Yes')
    } else {
        console.log('No')
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 7372
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int n;
char t[1001];
string s;
int p[1000];

int dp[1000][8][3];
int ans;

int main(){
	scanf("%d", &n);
	scanf("%s", t);
	s = t;
	for(int i=0; i<n; i++){
		if(s[i] == 'J') p[i] = 0;
		else if(s[i] == 'O') p[i] = 1;
		else p[i] = 2;
	}

	for(int i=0; i<8; i++){
		if((i & 1) == 1 && (i >> p[0] & 1) == 1){
			for(int j=0; j<3; j++){
				if((i >> j & 1) == 1){
					dp[0][i][j] = 1;
				}
			}
		}
	}

	for(int i=1; i<n; i++){
		for(int j=0; j<8; j++){
			if((j >> p[i] & 1) == 1){
				for(int k=0; k<3; k++){
					if((j >> k & 1) == 1){
						for(int l=0; l<8; l++){
							int ma = 0;
							for(int m=0; m<3; m++){
								if((j >> m & 1) == 1){
									ma = max(ma, dp[i-1][l][m]);
								}
							}
							dp[i][j][k] += ma;
							dp[i][j][k] %= 10007;
						}
					}
				}
			}
		}
	}
/*
	for(int i=0; i<n; i++){
		for(int j=0; j<8; j++){
			printf("%d\t", dp[i][j][0] + dp[i][j][1] + dp[i][j][2]);
		}
		printf("\n");
	}
*/
	for(int i=0; i<8; i++){
		int ma = 0;
		for(int j=0; j<3; j++){
			ma = max(ma, dp[n-1][i][j]);
		}
		ans += ma;
		ans %= 10007;
	}
	printf("%d\n", ans);
	return 0;
}

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

#define sswap(x, y) { x+=y; y=x-y; x-=y; }
#define LSOne(S) ((S) & (-S))

#define EPS 1e-6
#define MOD 1000000007

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
	int n, q;
	string s;
	cin >> n >> q >> s;
	int v[n+12];
	v[0] = 0;
	for (int i = 1; i < n; i++)
		v[i] = v[i-1] + ((s[i] == 'C') && (s[i-1] == 'A') ? 1 : 0);
	while (q--) {
		int l, r;
		cin >> l >> r;
		cout << v[r-1] - v[l-1] << ende;
	}
  return 0;
}


Measured memory_bytes: 1488
#include <iostream>

using namespace std;

int N;
int *A;

int Partition()
{
  int r = N - 1;
  int x = A[r];
  int i = 0;

  for(int j = 0; j < r; ++j)
  {
    if(A[j] <= x)
    {
      int tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;

      ++i;
    }
  }

  int tmp = A[r];
  A[r] = A[i];
  A[i] = tmp;

  return i;
}

int main()
{
  cin >> N;

  A = new int[N];

  for(int i = 0; i < N; ++i)
    cin >> A[i];

  int rIndex = Partition();

  for(int i = 0; i < N; ++i)
  {
    cout << (i == 0 ? "" : " ");
    if(i == rIndex)
      cout << "[" << A[i] << "]";
    else 
      cout << A[i];
  }
  cout << endl;

  delete [] A;

  return 0;
}


Measured memory_bytes: 3160
N = int(input())
A = list(map(int, input().split()))

def calc(center):
    ret = 0
    for a in A:
        ret += (a - center)**2
    return ret

ans = 10**10
for c in range(min(A), max(A) + 1):
    ans = min(ans, calc(c))

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cctype>
using namespace std;

int main(){
	string str;
	getline(cin, str);
	for(int i = 0; i < str.size(); i++){
		if(str[i] >= 'a' && str[i] <= 'z'){
			str[i] = toupper(str[i]);
		}
	}
	cout << str << endl;
}

Measured memory_bytes: 1180
import sys, math
def input(): return sys.stdin.readline().strip()


def main():
    N = int(input())
    A = [0] + list(map(int, input().split()))
    """
    dp[i][j] = (1からi番目の数のうちどの２個も連続しないようにj個選んだ時の和の最大)
    と置くらしい。何故その発想になるんだ？？
    最初は左右で分けて尺取りみたいなことをすれば行けると思ったが、左右の分け目を１つずらしたら
    最適解がガラッと変わって困った　→　じゃあDP、って感じなのかなあ

    このままだとO(N^2)なので状態数を減らす。
    １．j個は連続しないようにとるので、j <= (1 + i) // 2は確定。(iは1-indexedなことに注意)
    ２．残った(N - i)から連続しないように(N // 2 - j)個選ぶには、(N // 2 - j) <= (1 + N - i) // 2、
    　　すなわち(i - 3) // 2 <= jが必要。
    　　（j = 0,1,とか考えてもいいが、最終的にdp[N][N // 2]を求めるのにこれらは寄与しない）
    以上より、(i - 3) // 2 <= j <= (i + 1) // 2の範囲のみでdpすれば十分。

    肝心の遷移だが、A = [3, 1, 4, 1, 5, 9, 2]を例にとると
            i\j|  0  1  2   3   4       dp[5][1] = max(A[5], dp[4][1])
            ----------------------      dp[5][2] = max(A[5] + dp[3][1], dp[4][2])
              1|  0  3                  dp[5][3] = A[5] + dp[3][2]
              2|  0  3
              3|  0  4  7               dp[6][2] = max(A[6] + dp[4][1], dp[5][2])
              4|     4  7               dp[6][3] = max(A[6] + dp[4][2], dp[5][3])
              5|     5  9  12
              6|        9  12           のように、最後の数をとるか取らないかで場合分けすればよい。
              7|        9  12  14       ただしiが奇数の場合、dp[i][(i + 1) // 2]は必ずA[i]を
                                        加えざるを得ないため場合分けは起きないことに注意。
    """

    # iの偶奇でdp[i]をeven, oddに分割してメモリ削減
    odd = [0, A[1], 0]
    even = [0, max(A[1], A[2])]
    for i in range(3, N + 1):
        if i % 2 == 0:
            even[0] = max(A[i] + even[0], odd[1])
            even[1] = max(A[i] + even[1], odd[2])
        elif i > 3:
            odd[0] = max(A[i] + odd[0], even[0])
            odd[1] = max(A[i] + odd[1], even[1])
            odd[2] = A[i] + odd[2]
        else:
            odd[1] = max(A[1:4])
            odd[2] = A[1] + A[3]
    if N % 2 == 0:
        print(even[1])
    else:
        print(odd[1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 105480
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1LL << 30;

//初めて素因数分解を書いたため苦戦
//forでint iとしていたが、ll iとする必要があった

int main(){
  ll A, B;
  cin >> A >> B;
  ll C = __gcd(A, B);
  ll counter = 1; //1をカウント
  for(ll i = 2; i*i <= C; i++){
    if(C%i) continue;
    counter++;
    while(C%i==0) C /= i;
  }
  if(C != 1) counter++;
  cout << counter << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n;cin>>n;
	double a[n+1];
	for(ll i=0;i<n;i++)cin>>a[i];
	sort(a,a+n);
	double res=a[0];
	for(ll i=1;i<n;i++)res=(res+a[i])/2;
	cout<<fixed<<setprecision(16)<<res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0;
  cin>>n;
  int l[n*2+1];
  for(int i=0;i<n*2;i++)cin>>l[i];
  sort(l,l+n*2);
  reverse(l,l+n*2);
  for(int i=0;i<n*2;i++){
    if(i%2==1)ans+=l[i];
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <assert.h>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 2019

ll dp[2][2019];

int main(){
  string s;
  cin>>s;
  ll ans = 0;
  ll now = 0;
  ll nex = 1;
  rep(i,0,s.sz){
    ll a = s[i]-'0';
    dp[nex][a]++;
    rep(j,0,2019){
      dp[nex][(10*j+a)%2019]+=dp[now][j];
    }
    clr(dp[now],0);
    now=1-now;
    nex=1-nex;
    ans += dp[now][0];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
template<class T> inline bool chmin(T& a, T b) {if(a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if(a < b) {a = b; return true;} return false;}

int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  vector<int>on(n);
  on[0]=1;
  int tmp;
  int cnt=0;
  rep(i,n){cin>>tmp;tmp--;a[i]=tmp;}
  tmp=a[0];
  rep(i,n){
    if(tmp==1)break;
    else if(on[tmp]==0){
      cnt++;
      on[tmp]=1;
      tmp=a[tmp];
    }
    else{
      cout<<-1<<endl;return 0;
    }
  }
  cnt++;
  cout<<cnt<<endl;
  
  
    
    
  return 0;
}


Measured memory_bytes: 3988
#D問題
N,K = map(int,input().split())
V = list(map(int,input().split()))

R = min(N,K)


MAX = 0
for a in range(R+1):
    G = []
    for i in range(a):
        G.append(V[i])
    for b in range(R+1-a):
        H = G[:]
        for j in range(min(b,N-a)):
            H.append(V[N-j-1])
        H.sort()
        kari = sum(H)
        for k in range(K-(a+b)):
            if k >= a+b:
                break
            else:
                if H[k] >= 0:
                    break
                else:
                    kari+=(-H[k])
        MAX = max(MAX,kari)
        
print(MAX)

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
    int a;
    int b;

    do{
        scanf("%d", &a);

    }while(a<0 || a>100);

    do{
        scanf("%d", &b);

    }while(b<0 || b>100);


    int result = a * b;
    printf("%d\n", result);

    return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

// コンビネーションを計算する関数
ll modpow(ll a, ll n, ll mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N;
    string X;
    cin >> N;
    cin >> X;

    // 10進数→2進数-----------------------------------
    vector<ll> Binary(N);
    ll count = 0;
    REP(i, N){
        Binary[i] = X[N-i-1]-'0';
        if(Binary[i] == 1){
            count++;
        }
    }

    vector<ll> P(N, 0);
    vector<ll> M(N, 0);
    REP(i, N){
        P[i] = modpow(2, i, count+1);
        if(count-1 == 0){
            M[i] = 0;
        }
        else{
            M[i] = modpow(2, i, count-1);
        }
    }

    ll ptotal = 0;
    ll mtotal = 0;
    REP(i, N){
        // cout << "P:" << P[i] << " M:" << M[i] << endl;
        if(Binary[i] == 1){
            ptotal += P[i];
            mtotal += M[i];
        }
    }

    // N以下の数が来たときの計算を事前にやっておく
    vector<ll> A(N+1, 0);
    for(ll i=1; i<=N; i++){
        ll temp = i;
        // cout << "temp:" << temp << endl;
        ll num = 0;
        while(temp>0){
            // vector<ll> Binary;
            ll bina = temp;
            ll one = 0;
            for (int j = 0; bina>0 ; j++){
                // Binary.push_back(bina%2);
                if(bina%2 == 1) one++;
                bina = bina/2;
            }
            temp = temp % one;
            num++;
        }
        // cout << "i:" << i << " num:" << num << endl;
        A[i] = num;
    }

    // for(ll i=1; i<=N; i++){
    //     cout << i << " : " << A[i] << endl;
    // }

    for(ll i=N-1; i>=0; i--){
        if(Binary[i] == 1){
            if(count-1 == 0){
                cout << 0 << endl;
                continue;
            }
            ll m = (mtotal - M[i] + (count-1)) % (count-1);
            // cout << "m:" << m << " " << A[m]+1 << endl;
            cout << A[m]+1 << endl;
        }
        else{
            ll p = (ptotal + P[i] + (count+1)) % (count+1);
            // cout << "p:" << p << " " <<A[p]+1 << endl;
            cout << A[p]+1 << endl;
        }
    }

    return 0;
}

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

int main()
{
	int n,x,y;
	cin>>n>>x>>y;
	if(x > y) swap(x, y);
	int ans = n - x + 1;
	cout<<ans * (n - y + 1)<<endl;
	return 0;
}


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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int dp[100100][4] = {0};

signed main(){
    
    int x = 1000000007;
    string s;
    cin >> s;

    dp[0][0] = 1;
    REP(i,s.size()){
        if(s[s.size()-i-1] == '?') dp[i+1][0] = 3*dp[i][0]%x;
        else dp[i+1][0] = dp[i][0];
    }
    REP(i,s.size()){
        int a1=1,a2=1,a3=1,b1=0,b2=0,b3=0;
        if(s[s.size()-1-i] == '?'){
            a1 = a2 = a3 =3;
            b1=b2 = b3 = 1;
        }else if(s[s.size()-1-i] == 'A'){
            b3=1;
        }else if(s[s.size()-1-i] == 'B'){
            b2=1;
        }else if(s[s.size()-1-i] == 'C'){
            b1=1;
        }

        dp[i+1][1] = b1*dp[i][0]%x + a1*dp[i][1]%x;
        dp[i+1][2] = b2*dp[i][1]%x + a2*dp[i][2]%x;
        dp[i+1][3] = b3*dp[i][2]%x + a3*dp[i][3]%x;
        dp[i+1][1] %= x;
        dp[i+1][2] %= x;
        dp[i+1][3] %= x;
    }
    


    cout << dp[s.size()][3] << endl;
    REP(i,4){
        REP(j,s.size()+1){
          //  cerr << dp[j][i] << " ";
        }
        //cerr << endl;
    }
    
    return 0;
}
//g++ -std=c++14 code1.cpp


Measured memory_bytes: 3584
def main():
    n, k = [int(i) for i in input().split()]
    s = [int(i) for i in list(input())]
    table = []
    now = 1
    cnt = 0
    for i in range(n):
        if s[i] == now:
            cnt += 1
        else:
            table.append(cnt)
            cnt = 1
            now ^= 1 # 0　と 1 の切り替え
    if cnt != 0:
        table.append(cnt)
    if len(table)%2 == 0:
        # 奇数で終わらせれば、1 で終わったことになる
        table.append(0)
    ans = 0
    l = 0
    d = min(len(table), 2*k+1)
    r = l + d
    tmp = sum(table[l:r])
    while r <= len(table):
        ans = max(ans, tmp)
        if l < len(table):
            tmp -= table[l]
        l += 1
        if l < len(table):
            tmp -= table[l]
        l += 1
        r += 1
        if r <= len(table):
            tmp += table[r-1]
        r += 1
        if r <= len(table):
            tmp += table[r-1]
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5060
def main():
  K = int(input())
  ans = False
  if K % 2 == 0:
    print(-1)
    exit()
  cnt = 7 % K
  for i in range(1, K+1):
    if cnt == 0:
      ans = True
      print(i)
      exit()
    cnt = (10 * cnt + 7) % K
  if ans == False:
    print(-1)
    exit()
main()

Measured memory_bytes: 9036
import java.util.*;
import java.util.Map.Entry;



public class Main{

	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 Map<Long,Integer> map=new HashMap<Long,Integer>();
	 for(int i=0;i<N;i++) {
		 long temp=sc.nextLong();
		 if(map.containsKey(temp)) {
			 map.put(temp,map.get(temp)+1);
		 }else {
			 map.put(temp,1);
		 }
	 }
	 
	 List<Entry<Long,Integer>> list_entries = new ArrayList<Entry<Long,Integer>>(map.entrySet());
     
    
     Collections.sort(list_entries, new Comparator<Entry<Long,Integer>>() {
         public int compare(Entry<Long,Integer> obj1, Entry<Long,Integer> obj2) {
           
             return obj1.getValue().compareTo(obj2.getValue());
         }
     });
	 
     long result=0;
     
     for(Entry<Long, Integer> entry : list_entries) {
    	 if(entry.getKey()>entry.getValue()) {
    		 result+=entry.getValue();
    	 }else if(entry.getKey()<entry.getValue()) {
    		 result+=(entry.getValue()-entry.getKey());
    	 }
         //System.out.println(entry.getKey() + " : " + entry.getValue());
     }
     
     System.out.println(result);
	 
 }
	


}



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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> city(n, 0);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    city.at(a - 1)++;
    city.at(b - 1)++;
  }
  for (int i = 0; i < n; i++) {
    cout << city.at(i) << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
int main(){

  int n,q;
  cin>>n>>q;
  priority_queue <int> a[n];

  for(int i=0;i<q;i++){
    int n,t;
    cin>>n>>t;
    if(!n){
      int x;
      cin>>x;
      a[t].push(x);
    }
    else if(n==1 && !a[t].empty()) cout<<a[t].top()<<endl;
    else if(!a[t].empty()) a[t].pop();
  }

  return 0;

}



Measured memory_bytes: 4096
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<functional>
using namespace std;
typedef long long LL;
inline LL read()
{
	LL kk=0,f=1;
	char cc=getchar();
	while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
	while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
	return kk*f;
}
const int maxn=1020;
LL a[maxn*2];
LL qpow(LL a,LL b)
{
	LL kk=1;
	while(b)
	{
		if(b&1)kk=(kk*a);
		a=(a*a);
		b>>=1;
	}
	return (kk);
};
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
map<LL,pii>M;
void init()
{
	for(LL i=1;i<=maxn;++i)a[i]=qpow(i,5ll);
	for(LL i=0;i<=maxn;++i)
	{
		for(LL j=0;j<=i;++j)
		{
			LL now=a[i]+a[j];
			if(!M.count(now))M[now]=mp(i,-j);
			now=a[i]-a[j];
			if(!M.count(now))M[now]=mp(i,j);
		}
	}
}
int main()
{
	init();
	LL x=read();
	pii k=M[x];
	printf("%d %d\n",k.first,k.second);
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
	int H, W;
	vector<vector<int>> A, B, diff;

	cin >> H >> W;
	A.resize(H, vector<int>(W));
	B.resize(H, vector<int>(W));
	diff.resize(H, vector<int>(W));
	for (auto &h: A) {
		for (auto &w: h) {
			cin >> w;
		}
	}
	for (auto &h: B) {
		for (auto &w: h) {
			cin >> w;
		}
	}

	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			diff[h][w] = abs(A[h][w] - B[h][w]);
		}
	}

	vector<vector<bitset<160*160+1>>> res(H, vector<bitset<160*160+1>>(W));
	res[0][0].set(diff[0][0] + 160*80);
	res[0][0].set(-diff[0][0] + 160*80);
	for (int h = 0; h < H; ++h) {
		for (int w = 0; w < W; ++w) {
			if (h > 0) {
				res[h][w] |= res[h-1][w] << diff[h][w];
				res[h][w] |= res[h-1][w] >> diff[h][w];
			}
			if (w > 0) {
				res[h][w] |= res[h][w-1] << diff[h][w];
				res[h][w] |= res[h][w-1] >> diff[h][w];
			}
		}
	}

	int ans = inf<int>;
	for (int i = 0; i <= 160*80; ++i) {
		if (res[H-1][W-1].test(i)) {
			ans = min(ans, (int)abs(i - 160*80));
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 20736
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

struct segtree {
    int n;
    vi node;
    segtree(int n):n(n),node(2*n-1,inf) {}
    void update(int l,int r,int ne,int d,int dl,int dr) {
        if(r <= dl || dr <= l) return;
        if(l <= dl && dr <= r) {
            chmin(node[d],ne);
            return;
        }
        update(l,r,ne,2*d+1,dl,(dl+dr)/2);
        update(l,r,ne,2*d+2,(dl+dr)/2,dr);
    }
    int get_min(int i) {
        int now = n-1+i;
        int ret = node[now];
        while(now > 0) {
            now = (now-1)/2;
            chmin(ret,node[now]);
        }
        return ret;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,q;
    cin >> n >> q;
    vvi s(n,vi(3));
    rep(i,n) cin >> s[i][0] >> s[i][1] >> s[i][2];
    rep(i,n) {
        s[i][0] -= s[i][2];
        s[i][1] -= s[i][2];
    }
    vector<int> d(q);
    rep(i,q) cin >> d[i];
    vi ans(q);
    int nq = 2;
    while(nq < q) nq *= 2;
    segtree st(nq);
    rep(i,n) {
        int ns=s[i][0],nt=s[i][1],nx=s[i][2];
        auto it = lower_bound(all(d),ns);
        if(it == d.end()) continue;
        auto eit = lower_bound(all(d),nt);
        if(eit == d.begin()) continue;
        if(it == eit) continue;
        st.update(it-d.begin(),eit-d.begin(),nx,0,0,nq);
    }
    rep(i,q) {
        int now = st.get_min(i);
        ans[i] = (now == inf ? -1 : now);
    }
    rep(i,q) cout << ans[i] << endl;
}


Measured memory_bytes: 16512
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;


int main() {
	long long int a, b;
	char c;
	cin >> a >> c >> b;
	if (c == '+')a += b;
	else a -= b;
	cout << a << endl;
	

	return 0;

}




Measured memory_bytes: 384
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    if (n % 2 == 0 && s.substr(0, n/2) == s.substr(n/2, n/2)) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

int main(){
    int A, B, C, N, M ,K;
    int sum = 0;
    int t = 0;
    string s, s1;
    cin >> A >> B;
    for(int i = 0; i < 2; i++){
        if(A>B){
            sum += A;
            A--;
        }
        else{
            sum += B;
            B--;
        }
    }
//    vector<int> X();

//    for(int i = 0; i < ; i++){}
//    for(int j = 0; j < ; j++){}

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
vector<ll> getNums(ll N) {
    vector<ll> num(N);
    REP(i, N) {
        cin >> num[i];
    }
    return num;
}
int main() {
    ll N, P;
    cin >> N >> P;

    unordered_map<ll, ll> values;
    {
        ll n = P;
        for (ll i = 2; i * i <= n; ++i) {
            while ((n % i) == 0) {
                n /= i;
                values[i]++;
            }
        }
        if (n != 1) {
            values[n]++;
        }
    }

    ll ans = 1;
    for (const auto& v : values) {
        ll c = v.second / N;
        if (c >= 1) {
            ans *= pow(v.first, c);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4052
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
#define MAX_N 52
#define INF 1e18
ll d[MAX_N][MAX_N*MAX_N];
struct edge{ll to,cost,coin;};
vector<edge> G[MAX_N];
vector<ll> c(MAX_N),di(MAX_N);
void dij(ll s){
  priority_queue<TP,vector<TP>,greater<TP>> que;
  fill(d[0],d[MAX_N],INF);
  s = min(s,MAX_N*MAX_N-1ll);
  d[0][s] = 0;
  que.push(TP(0,s,0));
  while(!que.empty()){
    auto [dis,coin,v]=que.top();
    que.pop();
    coin = min(coin,MAX_N*(MAX_N-1ll));
    if(d[v][coin]<dis) continue;
    ll n_d = dis + di[v];
    ll n_coin = min(coin+c[v],MAX_N*(MAX_N-1ll));
    if(d[v][n_coin]>n_d){
      que.push(TP(n_d,n_coin,v));
      d[v][n_coin] = n_d;
    }
    for(ll i=0;i<(ll)G[v].size();i++){
      edge e=G[v][i];
      n_coin = coin - e.coin;
      if(n_coin>=0 && d[e.to][n_coin]>dis+e.cost){
        d[e.to][n_coin] = dis+e.cost;
        que.push(TP(d[e.to][n_coin],n_coin,e.to));
      }
    }
  }
}
ll min_d[MAX_N][MAX_N];
signed main(){
  init_io();
  ll n,m,s;
  cin >> n >> m >> s;
  vector<ll> u(m),v(m),a(m),b(m);
  for(int i=0;i<m;i++){
    cin >> u[i] >> v[i] >> a[i] >> b[i];
    u[i]--;
    v[i]--;
    G[u[i]].push_back({v[i],b[i],a[i]});
    G[v[i]].push_back({u[i],b[i],a[i]});
  }
  for(int i=0;i<n;i++){
    cin >>c[i] >> di[i];
  }
    dij(s);
  for(int i=1;i<n;i++){
    ll ans = INF;
    for(int j=0;j<MAX_N*MAX_N;j++){
      ans = min(d[i][j],ans);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define ffor(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rfor(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) ffor(i, 0, j, 1)
#define rrep(i, j) rfor(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp make_pair
#define pb push_back
//#define f first
//#define s second
#define inf (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define trace1(x)                     cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)        cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
const double pi=acos(-1.0);
typedef pair<long long int,long long int> pii;
typedef long long ll;
typedef vector<long long int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<long long int,long long int> mpii;
typedef set<long long int> sei;
typedef multiset<long long int> msei;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,n,m;
    cin>>n;
    ll a[n+1][3];
    ll dp[n+1][3];
    memset(dp,0,sizeof(dp));
    for(i=1;i<=n;i++)
    cin>>a[i][0]>>a[i][1]>>a[i][2];
    for(i=1;i<=n;i++)
    {
        for(j=0;j<3;j++)
        {
            for(ll l=0;l<3;l++)
            {
                if(l!=j)
                {
                    dp[i][j]=max(dp[i][j],dp[i-1][l]+a[i][j]);
                }
            }
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
    return 0;
}

Measured memory_bytes: 4992
//#include "pch.h"
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
#include <numeric>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
const double PI = 3.14159265359;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

int n;
vector<string>slist;
vector<vector<int>>list(100000,vector<int>(0));


signed main() {
	
	cin >> n;
	vector<int>v;
	vector<int>v2;
	vector<int>v3;



	for (int i = 1; i <= n; i++) {
		int num;
		cin >> num;
		v2.push_back(num);
	}

	for (int i = 1; i <= n; i++) {
		int num;
		cin >> num;
		v3.push_back(num);
	}

	int index = 0, index1 = 0,index2 = 0;
	bool flag1b = false, flag2b = false;

	for (int i = 1; i <= n; i++) {
		v.push_back(i);
	}

	do {
		bool flag1 = false, flag2 = false;

		for (int i = 0; i < v.size() && flag1b == false; i++) {
			if (v[i] != v2[i]) {
				flag1 = true;
				//index1 = index;
				break;
			}
		}

		if (flag1 == false && flag1b==false) {
			flag1b = true;
			index1 = index;
		}

		for (int i = 0; i < v.size() && flag2b == false; i++) {
			if (v[i] != v3[i]) {
				flag2 = true;
				//index2 = index;
				break;
			}
		}

		if (flag2 == false && flag2b == false) {
			flag2b = true;
			index2 = index;
		}

		index++;
		list.push_back(v);

		/*for (int i = 0; i < v.size(); i++) {
			cout << v[i];
		}
		cout << endl;*/

	} while (next_permutation(v.begin(), v.end()));

	//cout << "index1->" << index1 << " index2->" << index2 << endl;
	cout << abs(index1 - index2) << endl;


	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

int c2d(char c) {
	return c - '0';
}

bool is_month(int n) {
	return n > 0 && n <= 12;
}

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

	char s[8];
	scanf("%s", s);
	int x = c2d(s[0]) * 10 + c2d(s[1]);
	int y = c2d(s[2]) * 10 + c2d(s[3]);
	if (is_month(x) && is_month(y))
		puts("AMBIGUOUS");
	else if (is_month(x))
		puts("MMYY");
	else if (is_month(y))
		puts("YYMM");
	else
		puts("NA");
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll a[MAX*10];

ll f(ll n) {
    if(n%2==0) return n/2;
    else return 3*n+1;
}

int main(void) {
    ll s;
    cin >> s;
    ll i;
    Map mp;
    
    a[0]=s;
    mp[a[0]]++;
    for(i=1; i<MAX*10; i++) {
        a[i]=f(a[i-1]);
        mp[a[i]]++;
        if(mp[a[i]]>1) {
            pt(i+1);
            return 0;
        }
        
    }
    
    
}






Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	ll N, M;
	cin >> N >> M;

	if (2 * N < M) {
		cout << N + (M-2*N)/ 4 << endl;
	}
	else {
		cout << M / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define REP(i, n) for (int i=0; i<n; ++i)
#define print(x) cout << x << endl;

using namespace std;

void solve() {
    
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    int cnt = 0;
    for (int i=0; i<N-1; ++i) {
        if (S[i] == S[i+1]) ++cnt;
    }

    int ans = min(N-1, cnt + 2*K);
    print(ans);
}

int main() {

    solve();
    return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int a = ni();
    int b = ni();
    
    int[] p = na(n);
    
    int[] cnt = new int[3];
    for (int i = 0; i < n; i ++) {
      if (p[i] <= a) {
        cnt[0] ++;
      } else if (p[i] <= b) {
        cnt[1] ++;
      } else {
        cnt[2] ++;
      }
    }
    System.out.println(Arrays.stream(cnt).min().getAsInt());
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 28500
N = int(input())
A = [int(i) for i in input().split()]

for i in range(N):
    if A[i]==0:
        print(0)
        exit()

ans=1
for i in range(N):
    ans*=A[i]
    if ans>10**18:
        print(-1)
        exit()
print(ans)


Measured memory_bytes: 88088
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main() {
  int N = readln.chomp.to!(int);
  int[] C, S, F;
  for (int i = 0; i < N - 1; i++) {
    int[] buf = readln.chomp.split.to!(int[]);
    C ~= buf[0];
    S ~= buf[1];
    F ~= buf[2];
  }

  for (int i = 0; i < N - 1; i++) {
    int x = S[i] + C[i];
    for (int j = i + 1; j < N - 1; j++) {
      if (x > S[j]) {
        int t = (x - S[j]) % F[j];
        if (t) {
          x += F[j] - t;
        }
      }
      else {
        x += S[j] - x;
      }
      x += C[j];
    }
    writeln(x);
  }
  writeln(0);
}


Measured memory_bytes: 380
import bisect
import heapq
import numpy as np
N, K = map(int,input().split())
s = input()
res = 0
if s[0] == 'R' and s[1] == 'R':
    res += 1
for i in range(1,N-1):
    if s[i-1] == 'R' and s[i] == 'L':
        continue
    elif s[i+1] == 'L' and s[i] == 'R':
        continue
    res += 1
if s[N-1] == 'L' and s[N-2] == 'L':
    res += 1
res = min([N-1, res+2*K])
print(res)


Measured memory_bytes: 12456
#include <stdio.h>
#include <iostream>
#include <cmath>

#define int long long

using namespace std;

const int N=123456;

int Abs(int a) {
    return a>=0?a:-a;
}

signed main() {
	int x,y;
	scanf("%lld %lld",&x,&y);
	if(x>=0 && y>=0) {
		if(x<=y) {
			printf("%lld\n",y-x);
		} else {
			printf("%lld\n",min(x-y+2,y+x+1));
		}
	} else if(x>=0 && y<=0) {
		if(Abs(x)<=Abs(y)) {
			printf("%lld\n",Abs(y)-Abs(x)+1);
		} else {
			printf("%lld\n",Abs(x)-Abs(y)+1);
		}
	} else if(x<=0 && y>=0) {
		if(Abs(x)>=Abs(y)) {
			printf("%lld\n",min(Abs(x)-Abs(y)+1,Abs(x)+Abs(y)));
		} else {
			printf("%lld\n",min(Abs(y)+Abs(x),Abs(y)-Abs(x)+1));
		}
	} else {
		if(Abs(x)>=Abs(y)) {
			printf("%lld\n",Abs(x)-Abs(y));
		} else {
			printf("%lld\n",Abs(y)-Abs(x)+2);
		}
	}
	return 0;
}


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

bool palin(string s)
{
    int n=s.length();
    for(int i=0;i<=n/2;i++)
    {
        if(s[i]!=s[n-i-1])
        return false;
        
    }
    return true;
}

int main() {
	// your code goes here
	double l;
	cin>>l;
	double side=l/3;
	cout<<fixed<<setprecision(9)<<side*side*side;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
long long int n,L,d[10],v[10],G,f[10];

long long int gcd(long long int x,long long int y) {
  if(y==0) return x;
  return gcd(y ,x%y);
}

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

int main() {
  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> d[i] >> v[i];
      long long int a = gcd(d[i],v[i]); //yakubun
      d[i] /= a;
      v[i] /= a;
    }

    G = gcd(d[0],d[1]);
    L = lcm(d[0],d[1]);
    for(int i=2;i<n;i++) {
      G = gcd(G,d[i]);
      L = lcm(L,d[i]);
    }
    for(int i=0;i<n;i++) {
      f[i] = L * v[i] / d[i];
    }
    long long int F = gcd(f[0],f[1]);
    for(int i=2;i<n;i++) {
      F = gcd(F,f[i]);
    }
    for(int i=0;i<n;i++) {
      cout << f[i]/F << endl;
    }
  }
}

Measured memory_bytes: 0