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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll X;
    cin >> X;
    ll ans = 1;
    FOR(i, X, 2) {
        FOR(j, X + 1, 2) {
            ll p = pow(i, j);
            if (p > X)
                break;
            ans = std::max(ans, p);
        }
    }
    cout << ans << endl;
    return 0;
}

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

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; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

const int mod=1000000007;


int main(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int ans=0;
    int x=n/r;
    int y=n/g;
    rep(i,x+2){
        rep(j,y+2){
            if(i*r+j*g<=n&&(n-i*r-j*g)%b==0){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
let () =
  let a, b = Scanf.scanf "%d %d\n" (fun a b -> a, b) in

  let arr = Array.make a 0 in
  for i = 1 to a do
    let c = Scanf.scanf "%d\n" (fun c -> c) in
    Array.set arr (i-1) c
  done;

  let lst = Array.to_list arr in
  let sum = List.fold_left (+) 0 lst in
  let cheapest = List.hd (List.sort compare lst) in

  let x = (b - sum) / cheapest in

  print_endline (string_of_int (a + x))


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main()
{
    string s;cin>>s;
    int upper=0;
    if(s[0]=='A'){
    for(int i=0;i<s.size();i++){
        if(s[i]>='A'&&s[i]<='Z'){
            upper+=1;
        }
    }
    if(upper!=2){
        cout<<"WA";
    }
    else{
        for(int i=2;i<s.size()-1;i++){
            if(s[i]==67){
                cout<<"AC";
                return 0;
            }
        }
        cout<<"WA";
    }
    }
    else cout<<"WA";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define MOD 1000000007
#define pii pair<int,int>
#define vp vector<pair<int,int>>
#define RT long
using namespace std;


    
void solve(){
    int n; 
    cin>>n;
    cout<<(int)ceil(n/2.0);
}
    
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1,aa,bb,cc,dd;
    //cin>>t;
    while(t--){
        solve();
        cout<<endl;
    }
    
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FT first
#define SC second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;
const int INF = 1e9;
const double EPS = 1e-9;



int main()
{
  string s, t ;
  cin >> s >> t ;
  int n = s.size() ;
  int m = t.size() ;
  int l = max(n,m) ;
  string ss, tt ;
  
  vector<char> str1(n) ;
  vector<char> str2(m) ;
  REP(i,n){
    str1.at(i) = s.at(i) ;
  }
  REP(i,m){
    str2.at(i) = t.at(i) ;
  }
  sort(ALL(str1)) ;
  sort(ALL(str2)) ;
  reverse(ALL(str2)) ;
  
  REP(i,n){
    ss.push_back(str1.at(i)) ;
  }
  REP(i,m){
    tt.push_back(str2.at(i)) ;
  }
  if(ss<tt){
    cout <<"Yes"<<endl ;
  }
  else{
    cout <<"No"<<endl ;
  }

  return 0 ;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mxn= 2e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    ll arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    sort(arr,arr+3);
    if(arr[2]%2)
    cout<<arr[0]*arr[1];
    else cout<<0;
}

Measured memory_bytes: 3600
// God put a smile upon your face <3

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

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

#define mod 958585860497

#define base 2001487

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);

    while(cin >> n >> m)
    {
		if(m >= n) printf("unsafe\n");
		else printf("safe\n");
    }


}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int c[n - 1], s[n - 1], f[n - 1];
    int t = 0;
    rep(i, n - 1) cin >> c[i] >> s[i] >> f[i];
    rep(i, n - 1) {
        t = 0;
        rep3(j, i, n - 1) {
            if (t < s[j]) t = s[j];
            t += (f[j] - t % f[j]) % f[j];
            // ちょうどf[j]の倍数にするために残り足す
            // f[j]の倍数になったら0にする
            t += c[j];
        }
        out(t);
    }
    out(0);
}



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

int b[100][100];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int A, B;
	cin >> A >> B;
	A--, B--;

	int H = 100, W = 100;
	for(int i = 0; i < H / 2; i++){
		for(int j = 0; j < W; j++){
			b[i][j] = 1;
		}
	}

	for(int i = 0; i < H && A; i += 2){
		for(int j = 0; j < W && A; j++){
			if(j % 2 == 0){
				b[i][j] = 0;
				A--;
			}
		}
	}

	for(int i = H - 1; i >= 0 && B; i -= 2){
		for(int j = 0; j < W && B; j++){
			if(j % 2 == 0){
				b[i][j] = 1;
				B--;
			}
		}
	}

	cout << H << " " << W << endl;
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(b[i][j]) cout << "#";
			else cout << ".";
		}
		cout << endl;
	}
}


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

int main() {
    int n,ans=-1;
    double t,a;
    cin>>n>>t>>a;

    double ans1=100000;
    double h[n],tmp;
    
    for(int i=0;i<n;++i){
    cin>>h[i];
    tmp=abs(a-(t-h[i]*0.006));
    ans1=min(ans1,tmp);
    if(ans1==tmp)ans=i+1;
    }
    
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
R,S,P = map(int, input().split())
T = str(input())

i = 1
A = ['t']*K
mp1 = {'r':'p','s':'r','p':'s'}
mp2 = {'r':'r','s':'s','p':'p'}
mp3 = {'r':R,'s':S,'p':P}
ans = 0
for janken in T:
    tmp = i%K
    if A[tmp] == mp1[janken]:
        A[tmp] = 't'
    else:
        A[tmp] = mp1[janken]
        ans += mp3[mp1[janken]]
    i += 1

print(ans)

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



int main() {
int H, W;
cin >> H >> W;
string pick[200];
for(int i = 1; i <= H; i++) cin >> pick[i];

for(int i = 0; i < H+2; i++){
if(i == 0 || i == H+1){
    for(int j = 0; j < W+2; j++)cout << "#";
}
else{
cout << "#";
cout << pick[i];
cout << "#";
}
cout << endl;

}

}



Measured memory_bytes: 256
#include <stdlib.h> 
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <math.h>

using namespace std; 

int main()
{
   string s;

   cin>>s;

   if(s.substr(0,1) != s.substr(1,1) || s.substr(0,1) != s.substr(2,1) ) cout<<"Yes";
   else cout<<"No";

}



Measured memory_bytes: 3636
#include<iostream>
using namespace std;
struct f{
       int a;
       int b;
       int c;
       };
f aa[100005];
int main(){
    int n;
    cin>>n;
    int m=0;
    for(int i=0;i<n;i++){
            cin>>aa[i].a>>aa[i].b>>aa[i].c;
    }
    for(int i=0;i<n;i++){
            int k=aa[i].b+aa[i].c;
            if(aa[i].a<k){
                          m=1;
                          break;
            }
            if((aa[i].a-k)%2==1){
                                 m=1;
                                 break;
            }
    }
    if(m==1){
             cout<<"No"<<endl;
             }
    else{
         cout<<"Yes"<<endl;
         }
         return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(N + 1));
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= i; j++) {
      if(j == 0 || j == i) mat[i][j] = 1;
      else mat[i][j] = mat[i - 1][j - 1] + mat[i - 1][j];
    }
  }
  return mat;
}
int main(){
  int n,q;
  string s;
  cin >> n >> q >> s;
  vector<int> ac(n-1,0);
  rep(i,n-1)
    if(s.at(i)=='A'&&s.at(i+1)=='C')ac.at(i)++;
  vector<int> sum(n,0);
  rep(i,n-1)
    sum.at(i+1)=sum.at(i)+ac.at(i);
  rep(i,q){
    int l,r;
    cin >> l >> r;
    l--;
    r--;
    cout << sum.at(r)-sum.at(l) <<  endl;
  }
}


Measured memory_bytes: 1920
#include <stdio.h>

int main ()
{
	int a, b, ans;
	char op;
	while(scanf("%d %c %d", &a, &op, &b))
	{
	
		if(op == '?')
		{
			break;
		}
		if(op == '+')
		{
			ans = a + b;
		}
		if(op == '-')
		{
			ans = a - b;
		}
		if(op == '*')
		{
			ans = a*b;
		}
		if(op == '/')
		{
			ans = a / b;
		}
		printf("%d\n", ans);
	}
	
	return 0; 
} 


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

using namespace std;

int main()
{
    long  long n, i, sum = 0;

    cin >> n;

    for(i = 1; i <= n; i++)
    {
        if(i % 3 != 0 && i % 5 != 0)
            sum += i;
    }

    cout << sum << endl;

    return 0;
}


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

int main(void) {
  int N,X,Y;
  cin >> N >> X;
  vector<int> m(N);
  int sum = 0;
  int ans = 0;
  rep(i,N) {
    cin >> m.at(i);
    sum += m.at(i);
    ans++;
  }
  Y = X - sum;
  sort(m.begin(),m.end());
  while ( Y >= m.at(0)) {
    Y -= m.at(0);
    ans++;
 }
 cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        static long power(long a, long b, long modulo)
        {
            long result = 1;
            long buff = a;
            for (long i = 1; i <= b; i *= 2)
            {
                result = result * ((b / i % (2) == 1) ? buff : 1) % modulo;
                buff = (buff * buff) % modulo;
            }
            return result % modulo;
        }
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ')
               .Select(x => int.Parse(x)).ToList();
            var A = vals[0];
            var B = vals[1];
            var C = vals[2];
            var K = vals[3];
            var ans = Math.Min(A, K);
            ans -= Math.Min(C, Math.Max(K - A - B, 0));
            Console.WriteLine(ans);


        }



    }
    class PriorityQueue<T> where T : IComparable<T>
    {
        private List<T> heap = new List<T>();
        private int lastindex = -1;
        private void swap(int n, int m)
        {
            T wait = heap[n];
            heap[n] = heap[m];
            heap[m] = wait;
        }
        public int Count()
        {
            return lastindex + 1;
        }
        public void Enqueue(T data)
        {
            int p;
            if (lastindex + 1 < heap.Count())
            {
                heap[lastindex + 1] = data;
            }
            else
            {
                heap.Add(data);
            }
            lastindex++;
            p = lastindex;

            while (true)
            {
                if (p > 0 && heap[p].CompareTo(heap[(p - 1) / 2]) <= -1)
                {
                    swap(p, (p - 1) / 2);
                    p = (p - 1) / 2;
                }
                else
                {
                    break;
                }
            }
        }
        public T Peek()
        {
            return heap[0];
        }
        public T Dequeue()
        {
            T result = Peek();
            heap[0] = default(T);
            swap(0, lastindex);
            lastindex--;
            int p = 0;
            while (true)
            {
                int np;
                if (2 * p + 1 > lastindex)
                {
                    break;
                }
                else
                {
                    np = ((2 * p + 1 == lastindex) || heap[2 * p + 1].CompareTo(heap[2 * p + 2]) <= -1)
                        ? (2 * p + 1) : (2 * p + 2);
                }
                if (heap[p].CompareTo(heap[np]) >= 1)
                {
                    swap(p, np);
                    p = np;
                }
                else
                {
                    break;
                }
            }

            return result;
        }





    }
}


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> cnt;
    long long s = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        s += a[i];
        cnt[a[i]]++;
    }
    int q;
    cin >> q;
    for (int qi = 0; qi < q; qi++) {
        int from, to;
        cin >> from >> to;
        long long c = cnt[from];
        s = s - c*from + c*to;
        cnt[to] += c;
        cnt[from] = 0;
        cout << s << "\n";
    }
}



Measured memory_bytes: 8240
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

ll N, M, A, G = 1, cnt=1;

int main() {
    fastio();
    cin >> N >> M;
    cin >> A;
    G = A >> 1;
    while(A % 2==0) {
        cnt <<= 1;
        A >>= 1;
    }
    REP(i, N-1) {
        cin >> A;
        if(A % cnt != 0 || (A/cnt)%2 == 0) {
            cout << "0\n";
            return 0;
        }
        A >>= 1;
        G = lcm(A, G);
        if(G > M) {
            cout << "0\n";
            return 0;
        }
    }
    ll ans = M / G;
    ans++;
    ans /= 2;
    cout << ans << "\n";
	return 0;
}

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

int main(){
  ll n,m;cin>>n>>m;
  ll mod=7+1e9;
  ll ans=1;
  if(n<m)swap(n,m);
  if(n-m>1)ans=0;

  rep(i,m)ans=ans*(i+1)%mod*(i+1)%mod;
  rep(i,n-m)ans=ans*(m+i+1)%mod;
  if(n==m)ans=ans*2%mod;
  cout<<ans<<endl;
}


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

int ctoi(const char c){
    if('0'<=c && c<='9') return (c-'0');
    else return -1;
}

int main(){
    int n;
    cin>>n;
    string s;
    s=to_string(n);
    int waru=0;
    rep(i,s.size())waru+=ctoi(s[i]);
    if(n%waru==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

int
main(void)
{
    int h, w, k;
    int hoge, ans = 0;
    string s;
    vector<string> c;
    cin >> h >> w >> k;
    for(int i = 0; i < h; ++i) {
        cin >> s;
        c.push_back(s);
    }
    for(int row = 0; row < (1<<h); ++row) {
        for(int col = 0; col < (1<<w); ++col) {
            hoge = 0;
            for(int i = 0; i < h; ++i) {
                for(int j = 0; j < w; ++j) {
                    if(((row >> i) & 1) == 0 && ((col >> j) & 1) == 0 && c[i][j] == '#')
                        hoge++;
                }
            }
            if(hoge == k) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline int read(){
  int x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
char a[N], b[N];
bool check(int x, int y, int l, int r) {
  int len = r - l + 1;
  for (int i = 0; i < len; ++ i) {
    if (b[x + i] != a[l + i]) {
      return false;
    }
  }
  return true;
}
int main(int argc, char const *argv[]) {
  int n = read();
  scanf("%s", a + 1);
  scanf("%s", b + 1);
  for (int i = n; ~i; -- i) {
    if (check(1, i, n - i + 1, n)) {
      return printf("%d\n", 2 * n - i), 0;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n,m;
    // ll ans=0;
    scanf("%lld%lld",&n,&m);
    // // ll [n];
    // rep(i,0,n){
    //     scanf("%lld",&[i]);
    // }
    if(n%2&&m%2){
        YES;
    }else{
        NO;
    }

    
    // printf("%lld\n");
    return 0;
}


Measured memory_bytes: 128
N = int(input())
S = input()
A_list = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")

S_list = list(S)
ans = ""

for i in range(len(S_list)):
    for j in range(len(A_list)):
        if S_list[i] == A_list[j]:
            if (j + N) > 25:
                ans += A_list[j + N - 26]
            else:
                ans += A_list[j + N]

print(ans)




Measured memory_bytes: 3060
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
const int64_t MOD = 1000000007;
using namespace std;

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> pf;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      pf[i]++;
      n /= i;
    }
  }
  if (n != 1) {
    pf[n] = 1;
  }
  return pf;
}

int64_t modinv(int64_t a, int64_t m) {
  int64_t b = m, u = 1, v = 0;
  while (b) {
    int64_t t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

int main(void) {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int64_t> A(N);
  vector<int64_t> INV(N);
  map<int64_t, int> mp;
  rep(i, N) {
    cin >> A[i];
    map<int64_t, int> mp0 = prime_factor(A[i]);
    for (auto &m : mp0) {
      if (mp[m.first] < m.second) mp[m.first] = m.second;
    }
    INV[i] = modinv(A[i], MOD);
  }
  int64_t LCM = 1;
  for (auto &m : mp) {
    rep(i, m.second) { LCM = (LCM * m.first) % MOD; }
  }

  int64_t answer = 0;
  rep(i, N) { answer = (answer + (LCM * INV[i]) % MOD) % MOD; }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n;
vector<p> xv;
vector<p> sub;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        ll x, y;
        cin >> x >> y;
        xv.push_back(make_pair(x, y));
    }
    if (n == 1)
    {
        cout << 1 << "\n";
        return 0;
    }
    sort(xv.begin(), xv.end());
    for (int i = 0; i < n - 1; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            sub.push_back(make_pair((xv[j].first - xv[i].first), xv[j].second - xv[i].second));
        }
    }
    sort(sub.begin(), sub.end());
    int anssub = 0;
    int count = 0;
    for (int i = 0; i < sub.size() - 1; i++)
    {
        if (sub[i].first == sub[i + 1].first && sub[i].second == sub[i + 1].second)
        {
            count++;
        }
        else
        {
            anssub = max(anssub, count);
            count = 0;
        }
    }
    cout << n - anssub - 1 << "\n";
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

long func_gcd(long x, long y)
{
	long max_cnt;
	long val_gcd;
	long tmp;

	if( y == 0 )
	{
		val_gcd = x;
		return val_gcd;
	}

	if( y >= x )
	{
		tmp = x;
		x = y;
		y = tmp;
	}

	//cout << "func_gcd(" << y << "," << (x%y) << ")" << endl;
	val_gcd = func_gcd( y, (x % y) );

	return val_gcd;
}

int main(void)
{
	long x, y;
	long gcd;
	
	cin >> x >> y;

	gcd = func_gcd(x, y);
	cout << gcd << endl;
	return 0;
}



Measured memory_bytes: 3100
import numpy as np
N, K = map(int, input().split())
A = np.array(input().split(), dtype=np.int64)
F = np.array(input().split(), dtype=np.int64)
A = np.sort(A)
F = np.sort(F)
F = F[::-1]


def C(m):
    need = m // F
    cost = A - need
    cost[cost < 0] = 0
    return cost.sum() <= K


l, r = -1, 10 ** 18 + 10
while r - l > 1:
    m = (r + l) // 2
    if C(m):
        r = m
    else:
        l = m

print(r)


Measured memory_bytes: 37176
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(string b) {
    return [
        "A": "T",
        "T": "A",
        "C": "G",
        "G": "C"
    ][b];
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    string b;
    b = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(b);
    else
        solve(b).writeln;
}


Measured memory_bytes: 256
import heapq
import numpy as np

N, M = map(int, input().split())
A = list(map(int, input().split()))

A = list(-np.array(A))
    
heapq.heapify(A)  # Aをheapに変換
for _ in range(M):
    x = heapq.heappop(A)  # Aの中の最小値を取り出して返す
    heapq.heappush(A, (-x//2)*-1)
    
print(-sum(A))

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


int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  g.resize(n);
  rep(i, m)
  {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> par(n, -1);
  queue<pair<int, int>> q;
  q.emplace(0, 0);
  while (!q.empty())
  {
    auto p = q.front();
    q.pop();
    if (par[p.second] != -1)
      continue;
    par[p.second] = p.first;
    for (int nxt : g[p.second])
      if (par[nxt] == -1)
        q.emplace(p.second, nxt);
  }
  rep(i, n)
    if (i == 0)
      printf("Yes\n");
    else
      printf("%d\n", par[i] + 1);
  return 0;
}

Measured memory_bytes: 10904
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Z, W; cin >> N >> Z >> W;
  int a[N]; FOR(i,0,N) cin >> a[i];
  int ans = 0;
  if(N == 1) ans = abs(W - a[0]);
  else ans = max(abs(a[N-1] - a[N-2]), abs(W - a[N-1]));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int search_pattern(int n, int s, int i, int j, int *sum, int *result);

main()
{
	int n = 0, s = 0, i = 0, j = 0, sum = 0, result = 0;
	while(scanf("%d %d", &n, &s), !((0 == n) && (0 == s)))
	{
		search_pattern(n, s, i, j, &sum, &result);
		//printf("&result = %d result = ", &result);
		printf("%d\n", result);
		//n = 0, s = 0, i = 0, j = 0;
		sum = 0, 
		result = 0;
	}
	return 0;
}

int search_pattern(int n, int s, int i, int j, int *sum, int *result)
{
	for(; (i <= 9) && (j < n); i++)
	{
		*sum += i;
		j++;
		//printf("sum = %d i = %d j = %d\n", *sum, i, j);
		if(i <= 9)
		{
			search_pattern(n, s, i + 1, j, sum, result);
		}
		//printf("sum = %d j = %d\n", *sum, j);
		if((*sum == s) && (j == n))
		{
			*result += 1;
			//printf("*result = %d\n", *result);
		}
		*sum -= i;
		j--;
	}
}

Measured memory_bytes: 600
lst=[list(map(int,input().split())) for _ in range(3)]
n=int(input())
b=[int(input()) for _ in range(n)]
#print(lst,b)

lst_empty=[[0,0,0],[0,0,0],[0,0,0]]

for i in range(3):
    for j in range(3):
        for k in b:
            if lst[i][j]==k:
                lst_empty[i][j]="x"
ans="No"
for i in lst_empty:
    if i[0]==i[1]==i[2]=="x":
        ans="Yes"
for j in list(zip(*lst_empty)):
    if j[0]==j[1]==j[2]=="x":
        ans="Yes"
if lst_empty[0][0]==lst_empty[1][1]==lst_empty[2][2]=="x" or lst_empty[0][2]==lst_empty[1][1]==lst_empty[2][0]=="x":
    ans="Yes"
print(ans)


Measured memory_bytes: 3316
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int N;
vector<ll> A;

ll dp[200010][20];

int lg(ll A, int x, ll B) {
  for (int i = 0; i < x; i++) A *= 4;
  double dB = B;
  // A*4^x <= B*4^y
  for (int y = 0;; y++) {
    if (dB > A + 100 || A <= B) {
      return y;
    }
    dB *= 4;
    B *= 4;
  }
}

ll solve(int i, int x) {
  if (i == N - 1) return 0;
  if (x > 15) {
    return solve(i, 15) + (ll)(N - i - 1) * (x - 15);
  }
  ll& res = dp[i][x];
  if (res != -1) return res;
  int y = lg(A[i], x, A[i + 1]);
  return res = y + solve(i + 1, y);
}

int main() {
  while (cin >> N) {
    A.resize(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<ll> costA(N + 1, 0);
    {
      memset(dp, -1, sizeof(dp));
      for (int i = 0; i < N; i++) costA[i] = solve(i, 0) * 2;
    }
    vector<ll> costB(N + 1, 0);
    {
      reverse(A.begin(), A.end());
      memset(dp, -1, sizeof(dp));
      for (int i = 0; i < N; i++) costB[i] = solve(i, 0) * 2;
    }
    reverse(costB.begin(), costB.end());
    ll res = 1ll << 60;
    for (int i = 0; i <= N; i++) {
      ll cost = i + costA[i] + costB[i];
      res = min(res, cost);
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 54912
N, C, K = map(int, input().split())
T = sorted([int(input()) for _ in range(N)])

bus = 1
lastPassenger = T[0]
waiting = 1
for t in T[1:]:
    if waiting < C and lastPassenger + K >= t:
        waiting += 1
    else:
        waiting = 1
        lastPassenger = t
        bus += 1

print(bus)

Measured memory_bytes: 8276
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
  #define debug(x) cout << #x " => " << (x) << endl
#else
  #define debug(x) 0
#endif
using lint = long long;
constexpr int    INF  = 1 << 29;
constexpr lint   INFL = 1LL << 61;
constexpr int    MOD  = (int)1e9 + 7;
constexpr double EPS  = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int main(void) {
  lint a, b;
  cin >> a >> b;
  lint ans = 0;
  rep (i, 40) {
    lint t = (1LL << i) * 2;
    lint aleft, bleft;
    if (i == 0) {
      aleft = a / 2;
      bleft = (b + 1) / 2;
    } else {
      aleft = max(0LL, (a % t) - t / 2);
      bleft = max(0LL, ((b + 1) % t) - t / 2);
    }
    if ((aleft & 1) ^ (bleft & 1)) ans |= (1LL << i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    if(n<=m)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}





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

int main() {
  int i,j,ans=1001;
  string S,T;
  cin>>S>>T;
  for (i=0;i<=S.size()-T.size();i++) {
    int c=0;
    for (j=0;j<T.size();j++) {
      if (S[i+j]!=T[j]) c++;
    }
    ans = min(ans, c);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
#include <limits>
using namespace std;

inline int f(int n)
{
  return max(0, min(255, n));
}

int main()
{
  int N, M;
  while (cin >> N >> M && N != 0) {
    vector<int> cs(M);
    for (int i = 0; i < M; i++) {
      cin >> cs[i];
    }
    vector<int> xs(N);
    for (int i = 0; i < N; i++) {
      cin >> xs[i];
    }

    vector<vector<int> > dp(N+1, vector<int>(256, 100000000));
    dp[0][128] = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= 255; j++) {
        for (int k = 0; k < M; k++) {
          const int y = f(j+cs[k]);
          dp[i+1][y] = min(dp[i+1][y], dp[i][j] + (xs[i]-y)*(xs[i]-y));
        }
      }
    }
    int ans = numeric_limits<int>::max();
    for (int i = 0; i <= 255; i++) {
      ans = min(ans, dp[N][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 20000
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e16;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

#define int long long

struct SegmentTree{
private:
    int n;
    vector<ll> node;

public:
    // Range Minumum Query
    SegmentTree(vector<ll> v){
        int sz = v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1, INF);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
    }

    void update(int x, ll val){
        x += (n - 1);
        node[x] = val;
        while(0 < x){
            x = (x - 1) / 2;
            node[x] = min(node[2*x+1], node[2*x+2]);
        }
    }

    ll getmin(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return INF;
        if(a <= l && r <= b) return node[k];

        ll vl = getmin(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getmin(a, b, 2*k+2, (l+r)/2, r);
        
        return min(vl, vr);
    }
};

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

    int n, m; cin>>n>>m;
    vector<ll> dist(n, INF);
    dist[0] = 0; 
    SegmentTree seg(dist);
    vector<ll> dist2(n, INF);
    dist2[0] = 0;
    vector<T> v;
    for(int i=0; i<m; i++){
        ll l, r, c; cin>>l>>r>>c;
        v.emplace_back(l, r, c);
    }
    sort(v.begin(), v.end());

    for(int i=0; i<m; i++){
        ll l, r, c;
        tie(l, r, c) = v[i];
        l--, r--;
        ll val = seg.getmin(l, r); // [l, r)
        val += c;
        ll val2 = seg.getmin(min((ll)(n - 1), r + 1), n);
        if(val2 < val) continue;
        if(dist2[r] > val){
            seg.update(r, val);
            dist2[r] = val;
        }
    }

    cout << (dist2[n-1] >= INF ? -1 : dist2[n-1]) << endl;

    return 0;
}

Measured memory_bytes: 8956
#include<bits/stdc++.h>
//#define int long long
#define rep(i, l, r) for(register int i = l; i <= r; ++ i)

inline int read() 
{
	char cc = getchar(); int cn(0), flus(1);
	while(cc < '0' || cc > '9') {if(cc == '-') flus = -flus; cc = getchar();}
	while(cc >= '0' && cc <= '9') {cn = cn * 10 + cc - 48; cc = getchar();}
	return cn * flus;
}

const int MAXN = 1e5 + 10;
const int Mod = 998244353, G = 3;

signed main()
{
	int n = read();
	if(n >= 400 && n <= 599) printf("8\n");
	if(n >= 600 && n <= 799) printf("7\n"); 
	if(n >= 800 && n <= 999) printf("6\n");
	if(n >= 1000 && n <= 1199) printf("5\n");
	if(n >= 1200 && n <= 1399) printf("4\n");
	if(n >= 1400 && n <= 1599) printf("3\n");
	if(n >= 1600 && n <= 1799) printf("2\n");
	if(n >= 1800 && n <= 1999) printf("1\n");
	return 0;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
    int a,b,i,j;
    scanf("%d %d",&a,&b);
    int n[9][9];
    for(i=0;i<9;i++){
        for(j=0;j<9;j++){
            n[i][j]=(i+1)*(j+1);
        }
    }
    if(a>=1 && a<=9 && b>=1 && b<=9){
        for(i=0;i<9;i++){
            for(j=0;j<9;j++){
                if(a*b==n[i][j]){
                    printf("%d\n",a*b); return 0;
                }
            }
        }
        printf("-1\n"); return 0;
    } else {
        printf("-1\n");
        return 0;
    }
}

Measured memory_bytes: 128
from itertools import product

S = input()
N = len(S)
MOD = 10**9 + 7

dp = {i: {j: 0 for j in range(3+1)} for i in range(N+1)}
for i, j in reversed(list(product(range(N+1), range(3+1)))):
    if i < N and j < 3:
        m1 = 3 if S[i] == '?' else 1
        m2 = 1 if S[i] == '?' or S[i] == ['A', 'B', 'C'][j] else 0
        dp[i][j] = m1*dp[i+1][j] + m2*dp[i+1][j+1]
    elif i < N and j == 3:
        dp[i][j] = 3*dp[i+1][j] if S[i] == '?' else dp[i+1][j]
    elif i == N and j == 3:
        dp[i][j] = 1
    dp[i][j] %= MOD
print(dp[0][0])

Measured memory_bytes: 87732
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mo 1000000007
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return(((a-b)%mo+mo)%mo);}


vector<ll>v[100005];


int main() {
	ll n,m;
	cin>>n>>m;
	ll s[n],t[m];
	for(int i=0;i<n;i++)
		cin>>s[i];
	for(int i=0;i<m;i++)
		cin>>t[i];
	//cin>>s>>t;
	ll k,l;
	k=n;
	l=m;
	ll dp[k+1][l+1];
	for(int i=0;i<=k;i++)
		for(int j=0;j<=l;j++)
			dp[i][j]=0;


	for(int i=0;i<=k;i++)
	{
		for(int j=0;j<=l;j++)
		{
			if(i==0||j==0)
				dp[i][j]=1;
			else{
			if(s[i-1]==t[j-1])
				dp[i][j]=madd(dp[i][j],madd(dp[i-1][j],dp[i][j-1]));
			else
				dp[i][j]=msub(madd(dp[i][j-1],dp[i-1][j]),dp[i-1][j-1]);
		}
	}
	}
	cout<<dp[k][l];

}


Measured memory_bytes: 33920
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <functional>
#include <queue>
#include <stack>
#include <string.h>
#include <list>
using namespace std;
typedef long long ll;
#define all(a)  (a).begin(), (a).end()
#define rall(a) (a).rbegin(),(a).rend()
#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 PB push_back
#define MP make_pair
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))


int main() {
    int n;
    cin >> n;
    if(n <= 999) cout << "ABC" << endl;
    else cout << "ABD" << endl;
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  
  bool ans=false;
  
  for(int i=0;i<9;i++){
   for(int j=0;j<9;j++){ 
     if((i+1)*(j+1)==n)ans=true;
   }
  }
  
  if(ans)cout<<"Yes"<<endl;
  else{cout<<"No"<<endl;}
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                emplace_back
#define mp              make_pair
#define sz(a)           a.size()
#define mods(a, m)          ((a % m + m) % m)   
#define md(a)               mods(a, MOD)
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define mem(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i, b, e)     for (int i = b; i < e; i++)
#define forr(i, b, e)     for (int  i = b; i < e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;
typedef long double       ld;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e7 + 7);
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 1230456
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    int h,n;
    cin>>h>>n;
    ll tot=0,valor;
    forr(i,0,n){
        cin>>valor;
        tot+=valor;
    }
    if (tot>=h)
        cout<<"Yes\n";
    else
        cout<<"No\n";

}
// PLUS ULTRA!


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

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


void solve(){
    
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        string str;
        cin>>str;
        cout<<str<<endl<<str<<endl;
    }
}





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

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

int main(void){
  string s; cin>>s;
  bool ym_able=false,my_able=false;
  int date = stoi(s);
  if( date%100 >= 1 && date%100 <= 12) ym_able = true;
  if( date/100 >= 1 && date/100 <= 12) my_able = true;
  if( ym_able){
    if( my_able) cout << "AMBIGUOUS" << endl;
    else cout << "YYMM" << endl;
  }
  else if( my_able) cout << "MMYY" << endl;
  else cout << "NA" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX_N = 50;
int par[MAX_N];
int rn[MAX_N];

int N, M;

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        rn[i] = 0;
    }
}

int find(int x){
    if(par[x] == x) {
        return x;
    } else{
        par[x] = find(par[x]);
        return par[x];
    }
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x==y) return;

    if(rn[x] < rn[y]){
        par[x] = y;
    } else{
        par[y] = x;
        if(rn[x] == rn[y]) rn[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

int main(){
    cin >> N >> M;
    int G[N][N];

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            G[i][j] = 0;
        }
    }

    int A[M], B[M];
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i];
        A[i]--;B[i]--;
        G[A[i]][B[i]] = 1;
        G[B[i]][A[i]] = 1;
    }

    int ans  = 0;
    for(int i=0; i<M; i++){
        if(!G[A[i]][B[i]]) continue;
        G[A[i]][B[i]] = 0;
        G[B[i]][A[i]] = 0;

        init(N);

        for(int j=0; j<N; j++){
            for(int k=0; k<N; k++){
                if(G[j][k]) unite(j, k);
            }
        }

        bool fl = false;
        for(int j=0; j<N; j++){
            if(!same(0, j)) fl = true;
        }

        if(fl) ans++;

        G[A[i]][B[i]] = 1;
        G[B[i]][A[i]] = 1;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x


using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}

int cnt[128];

int main() {
    string s;cin>>s;
    
    rep(i,s.size()){
        cnt[s[i]]++;
    }
    
    if(abs(cnt['a']-cnt['b'])>=2)cout<<"NO"<<endl;
    else if(abs(cnt['a']-cnt['c'])>=2)cout<<"NO"<<endl;
    else if(abs(cnt['c']-cnt['b'])>=2)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}



Measured memory_bytes: 512