akhauriyash/Code-Regression huggingface dataset:
// Problem : D - 2017-like Number
// Contest : AtCoder - AtCoder Beginner Contest 084
// URL : https://atcoder.jp/contests/abc084/tasks/abc084_d
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}
vi prime,spf;
void sieve(int n)
{
	incd(prime,n+1);
	incd(spf,n+1);
	for(int i=0;i<=n;i++)
	spf[i]=i;
	prime[0]=1;
	prime[1]=1;
	for(int i=2;i*i<=n;i++)
	if(!prime[i])
	for(int j=i*i;j<=n;j+=i)
	{
		prime[j]=1;
		if(spf[j]==j)
		spf[j]=i;
	}
}
void solve()
{
	int q;cin>>q;
	sieve(100001);
	int pre[100002]={0};
	for(int i=1;i<=100000;i++)
	{
		pre[i]=pre[i-1];
		if(prime[i]==0 and prime[(i+1)/2]==0)
		pre[i]++;
	}
	while(q--)
	{
		int l,r;cin>>l>>r;
		cout<<pre[r]-pre[l-1]<<"\n";
	}
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

ll f(ll x) {
  ll res = 0;
  while (x % 2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}

signed main() {
  init();
  ll N, M;
  cin >> N >> M;
  vll A(N);
  rep(i, N) {
    cin >> A[i];
    A[i] /= 2;
  }

  ll t = f(A[0]);
  rep(i, N) {
    if (f(A[i]) != t) {
      COUT(0);
      return 0;
    }
    A[i] >>= t;
  }
  M >>= t;

  ll l = 1;
  rep(i, N) {
    l = lcm(l, A[i]);
    if (l > M) {
      COUT(0);
      return 0;
    }
  }
  M /= l;
  ll ans = (M + 1) / 2;
  ANS;
  return 0;
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
typedef  long long 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;}

template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main(){
    string s;
    cin>>s;
    string b;
    rep(i,s.size()){
       if(b.empty()&&s.at(i)=='B')continue;
       if(s.at(i)=='B')b.erase(b.size()-1);
       else {
           if(s.at(i)=='1')b+="1";
           if(s.at(i)=='0')b+="0";
       }
    }
    cout<<b<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
    string s;
    cin >> s;
    set<char> st;
    for (const auto c : s)
        st.insert(c);
    for (char c = 'a'; c <= 'z'; ++c) {
        if (!st.count(c)) {
            cout << s << c << '\n';
            return 0;
        }
    }
    string t = s;
    if (next_permutation(s.begin(), s.end())) {
        for (int i = 0; i < s.size(); ++i) {
            if (s.substr(0, i) > t) {
                cout << s.substr(0, i) << '\n';
                return 0;
            }
        }
    } else
        cout << -1 << '\n';
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
  int N;
  ll A[MAX_N];
  std::cin >> N;
  rep(i, N) std::cin >> A[i];

  int ans = 1;
  char inc = '=';
  rep(i, N - 1) {
    char new_inc;
    if(A[i + 1] == A[i]) new_inc = '=';
    if(A[i + 1] > A[i]) new_inc = '+';
    if(A[i + 1] < A[i]) new_inc = '-';

    if(inc != '=' and new_inc != '=' and inc != new_inc) {
      ++ans;
      inc = '=';
    } else {
      if(new_inc != '=') inc = new_inc;
    }
  }
  std::cout << ans << '\n';
}


Measured memory_bytes: 1024
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: usize,
        mut bb: [usize; n],
    }

    let mut ans = vec![];

    for i in 0..n {
        let mut index = None;
        for j in 0..n-i {
            if bb[j] == j+1 {
                index = Some(j);
            }
        }
        if let Some(index) = index {
            ans.push(index+1);
            bb.remove(index);
        } else {
            println!("-1");
            return;
        }
    }

    for x in ans.into_iter().rev() {
        println!("{}", x);
    }
}


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

vector<int> uf;

int find(int u) {
    return uf[u] < 0 ? u : uf[u] = find(uf[u]);
}

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

    int n, m;
    cin >> n >> m;
    uf.assign(n, -1);
    vector<pii> edges(m);
    for (auto &ed : edges) {
        cin >> ed.first >> ed.second;
    }
    ll curr = 1LL*n*(n-1)/2;
    vector<ll> ans(m);
    for (int i = m-1; i >= 0; --i) {
        ans[i] = curr;
        int u = edges[i].first-1, v = edges[i].second-1;
        int pu = find(u), pv = find(v);
        if (pu != pv) {
            curr -= 1LL*-uf[pu]*-uf[pv];
            uf[pu] += uf[pv], uf[pv] = pu;
        }
    }
    for (int i = 0; i < m; ++i) {
        cout << ans[i] << "\n";
    }
}

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

bool is_palindrome(string s)
{
	size_t n = s.length();
	if (n == 1)
	{
		return true;
	}
	else if (n == 2)
	{
		return s[0] == s[1];
	}

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

	return true;
}

bool is_strong_palindrome(string s)
{
	if (s.length() == 3)
	{
		if (s[0] == s[2]) return true;
		else return false;
	}

	if (!is_palindrome(s)) return false;
	string left = s.substr(0, s.length() / 2);
	if (!is_palindrome(left)) return false;
	string right = s.substr((s.length() + 1) / 2, s.length() / 2);
	if (!is_palindrome(right)) return false;

	return true;
}

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

	if (is_strong_palindrome(s)) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define pi acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
ll a[N];
int main()
{
	int n,m,q,k;
	cin>>n;
	__int128 now=1;
	for(int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
	if(a[1]==0){
		cout<<0;
		return 0;
	}
	for(int i=1;i<=n;i++){
		now*=a[i];
		if(now>1000000000000000000){
			cout<<-1;
			return 0;
		}
	}
	ll ans=now;
	cout<<ans;
}


Measured memory_bytes: 4420
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;
typedef pair<ll,ll> l_l;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back


ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

int main(){
    ll n,m;cin>>n>>m;
    string s;cin>>s;
    reverse(s.begin(),s.end());
    ll iti=0;
    ll ans=0;
    ll a[1000000];
    ll cc=0;
    bool b=true;
    while(iti<n){
        ans++;
        b=false;
        for(ll i=m;i>=1;i--){
            if(iti+i<=n){
                if(s[iti+i]=='0'){
                    iti=iti+i;
                    a[cc]=i;
                    cc++;
                    b=true;
                    break;
                }
            }
        }
        if(b==false){
            break;
        }
    }
    if(b==false){
        cout<<-1<<endl;
    }else{
        cout<<a[ans-1];
        for(ll i=ans-2;i>=0;i--){
            cout<<' '<<a[i];
        }
        cout<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 2816
#include <iostream>
#include <vector>


using namespace std;

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    
    vector<int> A(N), A_sort(N);
    for (int i=0; i<N; ++i)
    {
        cin >> A[i];
    }
    
    copy(A.begin(), A.end(), A_sort.begin());
    sort(A_sort.begin(),A_sort.end(),greater<int>());
    
    for (int i=0; i<N; ++i)
    {
        cout << (A[i] == A_sort[0] ? A_sort[1] : A_sort[0]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <string>
#include <cctype>
#include <cstdio>
#include <math.h>
using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
const int AMAX = 100000; 
using namespace std;
#define rep(i, n) for (i64 i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (i64 i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REVE(x) reverse(x.begin(), x.end())
#define all(x) (x).begin(), (x).end()
#define fst first
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define sw swap
#define UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define down(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
using LL = long long;
using ULL = unsigned long long;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

int main()
{
    int n,ans;
    cin >> n;  
    vector<int> a;
    rep(i,n){
      int b;
      cin >> b;
        a.pb(b);
        if(a[i]%2!=0){
            cout << 0;
            return 0;
        }
    }
  rep(i,n){
  while(a[i]>1&&a[i]%2==0){
     a[i]/=2;
    ans++;
  }
   a[i]=ans;
   ans=0;
  }
    SORT(a);
    cout << a[0];
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 1
/*------------------------------------------------------------*/

int main(){
	int n;
	in(n);
	int k1=0,ans1=0;
	FOR(i,1,n){
		int c1,c2;
		in2(c1,c2);
		if(c1>k1){
			k1=c1;
			ans1=c2;
		}
	}
	out(k1+ans1);
}

Measured memory_bytes: 256
n = input()

a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
c_list = list(map(int, input().split()))



before_num = 0
sum = 0
for a in a_list:
    sum += b_list[a-1]
    if before_num > 0 and (before_num == (a-1)):
        sum += c_list[before_num-1]
    before_num = a

print(sum)

Measured memory_bytes: 3064
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i%2==0 and j%2==0:
                print("#",end="")
            elif i%2==0 and j%2==1:
                print(".",end="")
            elif i%2==1 and j%2==0:
                print(".",end="")
            elif i%2==1 and j%2==1:
                print("#",end="")
        print()
    print()


Measured memory_bytes: 7004
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			foreach (var c in s) {
				if (c == '1') {
					Console.Write("9");
				} else {
					Console.Write("1");
				}
			}
			Console.WriteLine();


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		ll k,a,b;
		bool flag=false;
		cin>>k>>a>>b;
		if(a%k==0||b%k==0)
			flag=true;
		if(a/k!=b/k)
			flag=true;
		if(flag)
			cout<<"OK";
		else
			cout<<"NG";
	}
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(ll i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

constexpr int MOD = 1000000007;

// + - * / ^
int mod(int a)
{
	int res = a % MOD;
	if(res < 0) {
		return res + MOD;
	}
	return res;
}
int mul_mod(int a, int b)
{
	ll res = ((ll)a * (ll)b) % MOD;
	return mod((int)res);
}
int pow_mod(int a, int b)
{
	ll res = 1;
	while (b > 0) {
		if(b & 1) {
			res = res * (ll)a % (ll)MOD;
		}
		a = mul_mod(a, a);
		b >>= 1;
	}
	return (int)res;
}
int inv_mod(int a)
{
	return pow_mod(a, MOD - 2);
}
int div_mod(int a, int b)
{
	return mul_mod(a, inv_mod(b));
}

// ! C
constexpr int FAC_MAX = 100000;
ll fac[FAC_MAX], finv[FAC_MAX], inv[FAC_MAX];
void com_init()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < FAC_MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
ll com_mod(int a, int b){
	if (a < b) return 0;
	if (a < 0 || b < 0) return 0;
	return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> t(n), a(n);
	rep (i, n) cin >> t[i];
	rep (i, n) cin >> a[i];
	vector<bool> amb(n);
	vector<int> h(n);
	bool valid = true;

	// takahashi
	rep (i, n) {
		if (i == 0) {
			amb[0] = false;
		} else {
			amb[i] = (t[i] == t[i - 1]);
		}
		h[i] = t[i];
	}

	// aoki
	reprev (i, n) {
		bool now;
		if (i == n - 1) {
			now = false;
		} else {
			now = (a[i] == a[i + 1]);
		}
		if (now && amb[i]) chmin(h[i], a[i]);
		else if (now) valid &= (a[i] >= h[i]);
		else if (amb[i]) {
			amb[i] = false;
			valid &= (h[i] >= a[i]);
			h[i] = a[i];
		}
		else valid &= (a[i] == h[i]);
	}
	if (!valid) cout << "0\n";
	else {
		ll ans = 1;
		rep (i, n) {
			if (amb[i]) ans = mul_mod(ans, h[i]);
		}
		cout << ans << "\n";
	}
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

struct Unionfind {
	vector<int> par;
  vector<int> size;

	Unionfind(int n) {
		par.resize(n);
    size.resize(n);
		for (int i = 0;i < n;i++) {
			par[i] = i;
      size[i] = 1;
		}
	}

	int root(int a) {
		if (par[a] == a)return a;
		return par[a] = root(par[a]);
	}

	bool same(int a, int b) {
		return root(a) == root(b);
	}

	void unite(int a, int b) {
		int A = root(a);
		int B = root(b);
		if (A == B)return;

    if(size[A]>size[B])swap(A,B);
    size[B] += size[A];
		par[A] = B;
	}

  int getSize(int a){
    return size[root(a)];
  }
};

int main(void){
  int n, m, k, i;
  int a, b, c, d;

  vector<int> ans;
  vector<int> f;

  cin >> n >> m >> k;
  
  Unionfind tree(n);
  ans.resize(n);
  f.resize(n,0);

  for(i=0;i<m;i++){
    cin >> a >> b;
    a--;
    b--;
    f[a]++;
    f[b]++;
    tree.unite(a,b);
  }

  for(i=0;i<n;i++){
    ans[i] = tree.getSize(i) - f[i] - 1;
  }

  for(i=0;i<k;i++){
    cin >> c >> d;
    c--;
    d--;
    if(tree.same(c,d)){
      ans[c]--;
      ans[d]--;
    }
  }

  for(i=0;i<n;i++){
    cout << ans[i] << " ";
  }
  cout << endl;

  return 0;
}


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

typedef pair<ll, ll>Pll;
int main()
{
    ll n, K;
    ll ans = -1ll;
    Pll p[55];

    cin >> n >> K;
    for (ll i = 0; i < n; i++) {
        cin >> p[i].first >> p[i].second;
    }

    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < n; j++) {
            for (ll k = 0; k < n; k++) {
                for (ll l = 0; l < n; l++) {
                    ll maxx = max(p[i].first, max(p[j].first, max(p[k].first, p[l].first)));
                    ll minx = min(p[i].first, min(p[j].first, min(p[k].first, p[l].first)));
                    ll maxy = max(p[i].second, max(p[j].second, max(p[k].second, p[l].second)));
                    ll miny = min(p[i].second, min(p[j].second, min(p[k].second, p[l].second)));

                    ll sum = 0;
                    for (ll m = 0; m < n; m++) {
                        if (minx <= p[m].first && p[m].first <= maxx &&
                            miny <= p[m].second && p[m].second <= maxy) {
                            sum++;
                        }
                    }

                    if (sum >= K) {
                        ans = (ans == -1 ? (maxx - minx) * (maxy - miny) :
                               min(ans, (maxx - minx) * (maxy - miny)));
                    }
                    
                }
            }
        }
    }
   
    cout << ans << endl;

    return 0;

}


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

int main(){
  int n,k;long long s;cin>>n>>k>>s;
  REP(i,n){
    if(s!=1e9){
      if(i<k) cout<<s;
      else cout<<1000000000;
    }else{
      if(i<k) cout<<s;
      else cout<<999999999;    
    }
    if(i<n-1) cout<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;



int main() {
    int n, m; cin >> n >> m;
    priority_queue<ll> a;
    rep(i, n) {
        ll num; cin >> num;
        a.push(num);
    }

    while (m > 0) {
        ll k = a.top();
        a.pop();
        k >>= 1; 
        --m;
        a.push(k);
    }

    ll ans = 0;
    while (!a.empty()) {
        ans += a.top();
        a.pop();
    }

    cout << ans << endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <set>
#include <iostream>

const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

const int MAXSIZE = 1000;
char field[MAXSIZE + 1][MAXSIZE + 1];

const int MAXN = 10;
int locationsX[MAXN];
int locationsY[MAXN];
 
int H, W, N;

int get_shortest_distance(int current_HP)
{
	int sx = locationsX[current_HP-1];
	int sy = locationsY[current_HP-1];
	int ex = locationsX[current_HP];
	int ey = locationsY[current_HP];

	bool is_visit[MAXSIZE + 1][MAXSIZE + 1];
	for(int i=0;i<MAXSIZE;i++)
		for(int j=0;j<MAXSIZE;j++)
			is_visit[i][j]=false;
	std::set<std::pair<int,int>> frontier;
	frontier.insert(std::pair<int,int>{sx,sy});
	for(int step=0;step<100000000;step++)
	{
		for(auto p:frontier)
		{
			if(p.first==ex && p.second==ey)	return step;
			is_visit[p.first][p.second] = true;
		}
		std::set<std::pair<int,int>> next_frontier;
		for(auto p:frontier)
		{
			for(int i=0;i<STEP_NUM;i++)
			{
				int nx = p.first+STEP[i][0];
				int ny = p.second+STEP[i][1];
				if(nx<0 || H<=nx) continue;
				if(ny<0 || W<=ny) continue;
				if(field[nx][ny]=='X') continue;
				if(is_visit[nx][ny]) continue;
				next_frontier.insert(std::pair<int,int>{nx,ny});
			}
		}
		frontier = next_frontier;
	}
	return -1;
}

int solve()
{
	int total_step = 0;
	for(int i=1;i<N+1;i++)
		total_step += get_shortest_distance(i);
	return total_step;
}

int main()
{
	scanf("%d %d %d", &H, &W, &N);
	for(int i=0; i<H; i++)
		scanf("%s", field[i]);
	for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			int HP=-1;
			if(field[i][j]=='S')	HP=0;
			if(field[i][j]=='1')	HP=1;
			if(field[i][j]=='2')	HP=2;
			if(field[i][j]=='3')	HP=3;
			if(field[i][j]=='4')	HP=4;
			if(field[i][j]=='5')	HP=5;
			if(field[i][j]=='6')	HP=6;
			if(field[i][j]=='7')	HP=7;
			if(field[i][j]=='8')	HP=8;
			if(field[i][j]=='9')	HP=9;
			if(HP!=-1)
			{
				locationsX[HP]=i;
				locationsY[HP]=j;
			}
		}
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 5096
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		int B = scanner.nextInt();
		int C = scanner.nextInt();
		int K = scanner.nextInt();

		int x1 = 0;
		while (B <= A) {
			B = B * 2;
			x1++;
		}
		int x2 = 0;
		while (C <= B) {
			C = C * 2;
			x2++;
		}
		if( x1 + x2  > K){
			System.out.println("No");
		}
		else{
			System.out.println("Yes");
		}
		scanner.close();
	}
}

Measured memory_bytes: 35736
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    int x, a, b;
    void solve()
    {
        x = cin.nextint;
        a = Math.Abs(x - cin.nextint);
        b = Math.Abs(x - cin.nextint);
        WriteLine((a < b) ? "A" : "B");
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main() {
    string a, b;
    cin >> a >> b;
    string c=a+b;
    int num = atoi(c.c_str());
    int x = num;
    string z ="No";
    for(int i=0; i<x; i++){
        if(i*i==x){
            z ="Yes";
        }
    }
    cout << z << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

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

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

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


main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n % 2 == 1) {
        cout << "0\n";
        rr;
    }
    ll ans = 0;
    for (int st = 10; st <= n; st *= 5) {
        ans += n / st;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3660
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var a = NextInt();
        var b = NextInt();
        var c = NextInt();
        var k = long.Parse(NextString());

        var ans = a - b;
        if (k % 2 != 0) {
            ans *= -1;
        }
        WriteLine(ans);
    }

    static int NextInt() {
        return int.Parse(NextString());
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13268
n, z, w = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

if n == 1
  p (w - a[0]).abs
  exit
end

# ref: http://drken1215.hatenablog.com/entry/2019/05/11/133400
# dp[山札からとった枚数][後手かどうか] := その状態からスタートしたときの、最終的なカードの数値の差の最適値（先手なら最大値、後手なら最小値）
dp = Array.new(n + 1) { Array.new(2, 0) }
(n - 1).downto(0) do |i|
  # 先手
  y = i == 0 ? w : a[i - 1]
  dp[i][0] = (y - a[n - 1]).abs # のこりすべてとる
  (i + 1).upto(n - 1) do |j|
    dp[i][0] = [dp[i][0], dp[j][1]].max
  end

  # 後手
  x = i == 0 ? z : a[i - 1]
  dp[i][1] = (x - a[n - 1]).abs
  (i + 1).upto(n - 1) do |j|
    dp[i][1] = [dp[i][1], dp[j][0]].min
  end
end

p dp[0][0]


Measured memory_bytes: 2172
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for( ll i = (a); i < (ll)(b); i++ )
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort( (x).begin(),(x).end() )
#define REVERSE(x) reverse( (x).begin(),(x).end() )
#define UNIQUE(x) (x).erase( unique( ALL( (x) ) ) , (x).end() )
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())
#define SHOW(x) cout << #x << " = " << x << endl
#define SHOWA(x,n) for( int yui = 0; yui < n; yui++ ){ cout << x[yui] << " "; } cout << endl

#define pb emplace_back
#define fi first
#define se second

using namespace std;

typedef long double ld;
typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vpl> gr;
typedef vector<vl> ml;
typedef vector<vd> md;
typedef vector<vi> mi;
     
const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ld EPS = 1e-12;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> inline T sq( T a ){ return a * a; }

ll in(){ long long int x; scanf( "%lld" , &x ); return x; }
char yuyushiki[1000010]; string stin(){ scanf( "%s" , yuyushiki ); return yuyushiki; }

// head

int n;
ll a[100010];
ll b[100010];

ll x, sum;

int main(){

  n = in();
  REP( i , n ){
    a[i] = in();
    sum += a[i];
    x += i+1;
  }
  if( sum % x != 0 ){
    puts( "NO" );
    return 0;
  }
  ll y = sum / x;
  ll cnt = 0;
  REP( i , n ){
    b[i] = -( a[(i+1)%n] - a[i] - y );
    if( b[i] < 0 or b[i] % n != 0 ){
      puts( "NO" );
      return 0;
    }
    cnt += b[i] / n;
  }

  if( cnt != y ){
    puts( "NO" );
  } else {
    puts( "YES" );
  }
  

  return 0;
}


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

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	
	int dp[100][100];
	bool s[100][100];

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			char c; cin >> c;
			s[i][j] = (c == '.');
		}
	}
	
	dp[0][0] = (s[0][0] ? 0 : 1);

	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(i == 0 && j == 0)
				continue;

			int u = (i == 0) ? INT_MAX : dp[i-1][j];
			int l = (j == 0) ? INT_MAX : dp[i][j-1];
			if(s[i][j]){ // white
				dp[i][j] = min(u,l);
			} else { //black
				if(i > 0){
					if(j > 0){
						dp[i][j] = min(	(s[i-1][j] ? 1 : 0) + u,
										(s[i][j-1] ? 1 : 0) + l);
					} else {
						dp[i][j] = (s[i-1][j] ? 1 : 0) + u;
					}
				} else {
					dp[i][j] = (s[i][j-1] ? 1 : 0) + l;
				}
			}
		}
	}

	cout << dp[h-1][w-1];

	return 0;
}


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

int main() {
  int A,B;
  cin>>A>>B;
  
  int ans=A*B;
  cout<<ans<<endl;

}

Measured memory_bytes: 3636
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
//#include <utility>
#include <set>
#include <iostream>
//#include <memory>
#include <string>
#include <vector>
#include <algorithm>
//#include <functional>
#include <sstream>
//#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
//#include <cctype>
#include <cstring>
//#include <ctime>
#include <iterator>
#include <bitset>
//#include <numeric>
//#include <list>
//#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


namespace{
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}


#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;
int calc(pii a,pii b){
	return abs(a.F-b.F)+abs(a.S-b.S);
}
void mainmain(){
	int h,w;
	while(cin>>w>>h,h||w){
		vector<vector<pii>> vv(5);
		pii S,G;
		rep(i,h){
			rep(j,w){
				char t;
				cin>>t;
				if(t=='S'){
					S=mkp(i,j);
				}
				else if(t=='G'){
					G=mkp(i,j);
				}
				else if(t=='.'){
					continue;
				}
				else{
					vv[t-'0'-1].PB(mkp(i,j));
				}
			}
		}
		vector<pii> ans;
		vvint tmp(5);
		rep(j,5){
			rep(k,vv[j].size()){
				tmp[j].PB(INT_MAX);
			}
		}
		rep(i,5){
			bool f=true;
			rep(j,4){
				if(vv[(i+j+1)%5].size()==0) f=false;
			}
			if(!f) continue;
			vvint tt=tmp;
			int st=(i+1)%5;
			rep(j,tt[st].size()){
				tt[st][j]=calc(S,vv[st][j]);
			}
			rep(j,3){
				int pa2=(i+j+2)%5;
				int pa1=(i+j+1)%5;
				rep(k,vv[pa1].size()){
					rep(l,vv[pa2].size()){
						tt[pa2][l]=min(tt[pa2][l],tt[pa1][k]+calc(vv[pa1][k],vv[pa2][l]));
					}
				}
			}
			int t1=INF;
			int t2=(i+4)%5;
			rep(j,tt[t2].size()){
				t1=min(t1,tt[t2][j]+calc(vv[t2][j],G));
			}
			ans.PB(mkp(t1,i));
		}
		if(ans.size()==0){
			puts("NA");
		}
		else{
			sort(ALL(ans));
			// rep(i,ans.size()){
				// cout<<ans[i].S+1<<" "<<ans[i].F<<endl;
			// }
			// cout<<(int)ans.size()<<endl;
			cout<<ans[0].S+1<<" "<<ans[0].F<<endl;
		}
	}
}



}
main() try{
    mainmain();
}
catch(...){
}

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

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif

    string s;
    cin >> s;
    bool a = false;
    int len = 0;
    int count = 0;
    for(int i = 0; i < (int) s.size(); ++i) {
        if(s[0] == 'A') {
            a = true;
        }
        if(i > 1 && i < s.size() - 1) {
            if(s[i] == 'C') {
                count++;
            }
        }
        if(s[i] >= 'a' && s[i] <= 'z') {
            len++;
        }
    }
    if(a == true && count == 1 && len + count + 1 == s.size()) {
        cout << "AC" << endl;
    }
    else {
        cout << "WA" << endl;
    }
    return 0;
}


Measured memory_bytes: 3660
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    cnt = 0
    for i in range(N):
        if i % 2 == 0 and A[i] % 2 == 1:
            cnt += 1
    print(cnt)
 
if __name__ == '__main__':
    main()

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

int main() {
  int N;
  cin >> N;
  
  vector<string> vec(N);

  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  int ab = 0;
  int la = 0;
  int fb = 0;
  int bot = 0;
  bool flag1 = false;
  bool flag2 = false;
  
  for (int i = 0; i < N; i++) {
      for (int j =0; j < vec.at(i).size() - 1; j++){
          if (vec.at(i).at(j) == 'A' && vec.at(i).at(j+1) == 'B'){
              ab++;
          }
          if (vec.at(i).at(j) == 'B' && j == 0){
              fb++;
              flag1 = true;
          }
          if (vec.at(i).at(j+1) == 'A' && j+1 == vec.at(i).size() - 1){
              la++;
              flag2 = true;
          }
      }
      
      if (flag1 == true && flag2 == true){
          bot++;
      }
      
      flag1 = false;
      flag2 = false;
      
  }
  
  int ans = 0;
  
  if (max(la, fb) - min(la, fb) == 0 && bot != 0 && bot == min(la, fb)) {
  ans = ab + min(la, fb) - 1;
  }
  else {
  ans = ab + min(la, fb);
  }
  
  cout << ans << endl;
  
}


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

template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int N;

int find(long now, bool is_3, bool is_5, bool is_7){
    if(now > N){
        return 0;
    }
    int ans = is_3 && is_5 && is_7;
    ans += find(now * 10 + 3, true, is_5, is_7);
    ans += find(now * 10 + 5, is_3, true, is_7);
    ans += find(now * 10 + 7, is_3, is_5, true);
    return ans;
}

int main(){
    cin >> N;
    cout << find(0, false, false, false) << endl;
}


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

using namespace std;

int main(void){
    int x,a,b;
    cin >> x >> a >> b;
    
    int dist1 = abs(x - a);
    int dist2 = abs(x - b);
    
    if (dist1 < dist2){
        cout << 'A' << endl;
        return 0;
    }
    else{
        cout << 'B' <<endl;
        return 0;
    }
}


Measured memory_bytes: 3584
#include<cstdio>
#include<vector>
#include<algorithm>
#include<utility>
#include<numeric>
#include<iostream>
#include<array>
#define _USE_MATH_DEFINES

#include<math.h>
#include<unordered_map>

#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)>(b)?(a):(b)

using namespace std;

int main()
{
	int n, m, l;
	long long int a[100][100], b[100][100];

	scanf("%d %d %d", &n, &m, &l);

	for (int i = 0; i < n; i++)for (int j = 0; j < m; j++)
	{
		scanf("%lld", &a[i][j]);
	}

	for (int i = 0; i < m; i++)for (int j = 0; j < l; j++)
	{
		scanf("%lld", &b[i][j]);
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < l; j++)
		{
			long long int ans = 0;
			for (int k = 0; k < m; k++)
			{
				ans += a[i][k] * b[k][j];
			}
			printf("%lld", ans);
			if (j < (l - 1))
			{
				printf(" ");
			}
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#define RI register int

using namespace std;

int Notprime[10000005], Prime[10000005], tot;
void Euler(int MAX) {
  Notprime[1] = 1;
  for (RI i = 2; i <= MAX; ++i) {
    if (!Notprime[i]) Prime[++tot] = i;
    for (RI j = 1; j <= tot && Prime[j] * i <= MAX; ++j) {
      Notprime[i * Prime[j]] = 1;
      if (i % Prime[j] == 0) break;
    }
  }
}

int const MAXN = 505;
struct Edges {
  int to, next;
} e[MAXN * MAXN];
int a[MAXN], odd[MAXN], even[MAXN], cnt1, cnt2;
int vis[MAXN], fa[MAXN], head[MAXN], ttott;

inline void Add(int k) { k & 1 ? odd[++cnt1] = k : even[++cnt2] = k; }
inline void addedge(int from, int to) {
  e[++ttott] = (Edges){to, head[from]};
  head[from] = ttott;
}

bool xyl(int k) {
  if (vis[k]) return 0;
  vis[k] = 1;
  for (RI i = head[k]; i; i = e[i].next)
    if (!fa[e[i].to] || xyl(fa[e[i].to])) {
      fa[e[i].to] = k;
      return 1;
    }
  return 0;
}

int main() {
//  freopen("prime.in", "r", stdin);
//  freopen("prime.out", "w", stdout);
  Euler(1e7);
  int n; scanf("%d", &n);
  for (RI i = 1; i <= n; ++i) scanf("%d", &a[i]);
  sort(a + 1, a + 1 + n);
  int last = a[1];
  for (RI i = 2; i <= n; ++i)
    if (a[i] != a[i - 1] + 1)
      Add(last), Add(a[i - 1] + 1), last = a[i];
  Add(last), Add(a[n] + 1);
  for (RI i = 1; i <= cnt1; ++i)
    for (RI j = 1; j <= cnt2; ++j)
      if (!Notprime[abs(odd[i] - even[j])])
        addedge(i, j);
  int Sucs = 0;
  for (RI i = 1; i <= cnt1; ++i, memset(vis, 0, sizeof(vis)))
    if (xyl(i)) ++Sucs;
  int ans = Sucs; cnt1 -= Sucs, cnt2 -= Sucs;
  ans += cnt1 + cnt2;
  ans += cnt1 & 1;
  printf("%d\n", ans);
  return 0;
}

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

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

	return gcd(y, x % y);
}


int main() {
	int K;
	cin >> K;

	ll sum = 0;
	for(int a = 1; a <= K; a++) {
		for(int b = 1; b <= K; b++) {
			for(int c = 1; c <= K; c++) {
				sum += gcd(gcd(a, b), c);
			}
		}
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3596