akhauriyash/Code-Regression huggingface dataset:
N = int(input())
MOD = 10 ** 9 + 7
memo = [{} for i in range(N + 1)]

def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i], t[i - 1] = t[i - 1], t[i]
        if "".join(t).count("AGC") >= 1:
            return False
    return True

def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in "ACGT":
        if ok(last3 + c):
            ret = ret + dfs(cur + 1, last3[1:] + c)
    memo[cur][last3] = ret
    return ret

print(dfs(0, "TTT") % MOD)

Measured memory_bytes: 3948
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

int main(){
    ll n,m; cin >> n >> m;
    vl a(n),b(m);
    rep(i,n) cin >> a[i];
    rep(i,m) cin >> b[i];
    sort(all(a)); sort(all(b));
    ll ans = 1;
    rep(i,n-1){
        if(a[i+1]==a[i]){
            puts("0");
            return 0;
        }
    }
    rep(i,m-1){
        if(b[i+1]==b[i]){
            puts("0");
            return 0;
        }
    }
    for(ll i=n*m; i>=1; i--){
        ll A = 1; ll B = 1;
        bool aa = binary_search(all(a),i);
        bool bb = binary_search(all(b),i);
        if(!aa) A = a.end() - upper_bound(all(a),i);
        if(!bb) B = b.end() - upper_bound(all(b),i);
        if(aa||bb){
            ans *= A*B;
            ans %= mod;
            continue;
        }
        ans *= max(0LL,A*B-(n*m-i));
        ans %= mod;
    }
    cout << ans << endl;
}

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

using namespace std;
#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__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

const ll MOD = 998244353;

ll dp[3100][3100];


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

  int N, S;
  cin >> N >> S;

  vector<int> A(N);

  rep(i, N)cin>> A[i];

  rep(i, N){
    rep(j, S+1){
      dp[i][j] = 0;
    }
  }

  rep(i, N){
    dp[i][0]++;
    rep(j, S+1){
      // そのまま
      dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;

      if(j + A[i] <= S){
        dp[i+1][j+A[i]] = (dp[i+1][j+A[i]] + dp[i][j]) % MOD;
      }
      
    }
  }

  ll ans = 0;
  for(int i = 0; i <= N; i++){
      ans = (ans + dp[i][S]) % MOD;
  }

  cout << ans << endl;


}


Measured memory_bytes: 73984
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e6+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    string s;
    cin>>n>>s;
    set<int>r,w;
    lp(i,0,n){
        if(s[i]=='R')
            r.insert(i);
        else
            w.insert(i);
    }
    int res=0;
    for(auto i:w){
        if(sz(r)){
            int pos=*prev(r.end());
            if(i<pos)
                swap(s[i],s[pos]),r.erase(pos),res++;
        }
    }
    cout<<res;
}

Measured memory_bytes: 12996
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 H, W;
  cin >> H >> W;
  vector<string> fld(H + 1);
  vector<vector<i64>> dp(H + 1, vector<i64>(W + 1, -1));
  dp[1][1] = 1;
  for(int i = 1;i <= H;i++) {
    cin >> fld[i];
    for(int j = 0;j < W;j++) {
      if(fld[i][j] == '#') dp[i][j + 1] = 0;
    }
  }

  for(int j = 1;j <= W;j++) dp[0][j] = 0;
  for(int j = 1;j <= H;j++) dp[j][0] = 0;

  i64 mod = 1e9 + 7;


  for(int i = 1;i <= H;i++) {
    for(int j = 1;j <= W;j++) {
      if(dp[i][j] == -1) {
        dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
      }
    }
  }
  cout << dp[H][W] << endl;
}


Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main() {
	ll x, y; cin >> x >> y;
	ll ans = 0;
	while(1) {
		x *= 2;
		if(y < x) break;
		ans++;
	}
	printf("%lld\n", ans + 1);
	return 0;
}

Measured memory_bytes: 256
// A - Kth Term
#include <bits/stdc++.h>
using namespace std;
int K;
int V[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main(){
	cin>>K;
	cout<< V[K-1] <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void)
{
    string n;
    cin >> n;
char c = n[n.size()-1];
 
 if(c=='s'){
     cout<<n<<"es";
 }else{
     cout<<n<<"s";
 }
    
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


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

    V<int> a(n);
    int s = 0;
    for(int i = 0; i < n; i++){
        a[i] = l + i;
        s += a[i];
    }

    int x = IINF;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int t = s - a[i];
        if(abs(s - t) < x){
            x = abs(s - t);
            ans = t;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3560
n = int(input())
p = list(map(int,input().split()))
ans = 0
for i in range(1,n-1):
    judge = False
    if p[i-1] < p[i] and p[i] < p[i+1]:
        judge = True
    if p[i+1] < p[i] and p[i] < p[i-1]:
        judge = True
    if judge:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	char blood[4];
	int a, b, ab, o;
	
	a = 0; b = 0; ab = 0; o = 0;
	while (scanf("%d,%s", &n, blood) != EOF){
		if (strcmp(blood, "A") == 0){
			a++;
		}
		if (strcmp(blood, "B") == 0){
			b++;
		}
		if (strcmp(blood, "AB") == 0){
			ab++;
		}
		if (strcmp(blood, "O") == 0){
			o++;
		}
	}
	printf("%d\n%d\n%d\n%d\n", a, b, ab, o);
	
	return (0);
}

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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h.at(i);
    for(int i = n-1;i >= 1;i--){
        if(h.at(i) < h.at(i-1) - 1) {
            cout << "No" << endl;
            return 0;
        }else if(h.at(i) == h.at(i-1) - 1){
            h.at(i-1)--;
        }
    }
    cout << "Yes" << endl;
}

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

int main() {
  int A = 10,B = 11,C = 12,D = 13,E = 14,F = 15;
  char x,y;
  cin >> x >> y;
  if(x > y){
    cout << ">" << endl;
  }
  else if(x == y){
    cout << "=" << endl;
  }
  else{
    cout << "<" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  char str[n+5];
  cin>>str;
  int c=0;
  for(int i=0;i<n-2;i++){
    if(str[i]=='A'&&str[i+1]=='B'&&str[i+2]=='C')
      c++;
  }
    cout<<c;       
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n;
    cin >> n;
    int a[n+5];
    int vis[1000000+5] = {0};
    for(int i = 0; i < n; i++) cin >>a[i];

    sort(a, a+n);
    int mx = a[n-1];
    for(int i = 0; i < n; i++){
        if(vis[a[i]] < 2){
            int it = mx/a[i];
            for(int j = 1; j <= it; j++) vis[a[i]*j]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) if(vis[a[i]] == 1) ans++;
    cout << ans;
}
//new line is printed in the main

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    // int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 8264
#include<iostream>
using namespace std;
#define MAX 101
 
int D[MAX];
 
bool check(){
    if ( D[1]%2 == 0 || D[2]%2 == 0 ) return false;
    for ( int i = 3; i < MAX; i++ ) if ( D[i]%2 ) return false;
    return true;
}
 
main(){
    int a, b;
    while( cin >> a >> b ){
    for ( int i = 1; i <= MAX; i++ ) D[i] = 0;
    D[a]++; D[b]++;
    while(1){
        cin >> a >> b;
        if ( a == 0 && b == 0) break;
        D[a]++; D[b]++;
    }
    cout << (check()?"OK":"NG") << endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define nmax_def 220000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

// ----- UnionFind -----

class UnionFind {
public:
	vi par;
	int N;

	void UnionFind_ini();
	int root(int x);
	void unite(int x, int y);
	bool same(int x, int y);
	int adjnum_func(int x);
	void solve();

private:
	vi adjnum;
};

void UnionFind::UnionFind_ini() {
	adjnum.resize(N);
	par.resize(N);
	rep(i, N) {
		adjnum[i] = 1;
		par[i] = i;
	}
}

int UnionFind::root(int x) {
	if (par[x] == x)
		return x;
	par[x] = root(par[x]);
	return par[x];
}

void UnionFind::unite(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	if (rx == ry)
		return;
	par[rx] = ry;
	adjnum[ry] += adjnum[rx];
	return;
}

bool UnionFind::same(int x, int y) {
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

int UnionFind::adjnum_func(int x) {
	int rx = root(x);
	return adjnum[rx];
}

void UnionFind::solve() {
	int M;
	cin >> N >> M;
	UnionFind_ini();
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		A--;
		B--;
		unite(A, B);
	}
	int ans = 0;
	rep(i, N) {
		ans = max(ans, adjnum_func(i));
	}
	cout << ans << endl;
	return;
}

int main(void) {
	UnionFind graph;
	graph.solve();
	return 0;
}

Measured memory_bytes: 11076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define is(a, b) a == b
#define len(v) ll(v.size())

class UnionFind {
public:
	vector<int> par;//親の番号
    vector<int> rank;//木の深さ
 
	UnionFind(int n){//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
		rep(i,n){
            par.push_back(i);
            rank.push_back(0);
        }
	}
 
	int find(int x) {//木の根を求める
		if(par[x]==x){
            return x;
        }else{
            return par[x]=find(par[x]);
        }
	}
 
	void unite(int x,int y){//xとyの属する集合を併合
        x=find(x);
        y=find(y);
        if(x==y) return;
        if(rank[x]<rank[y]){//木の深さが小さい方を大きい方へ繋げる
            par[x]=y;
        }else{
            par[y]=x;
            if(rank[x]==rank[y]) rank[x]++;
        }
    }

    bool same(int x,int y){//xとyが同じ集合に属するか否か
        return find(x)==find(y);
    }
};
//x以下の要素への最小index, ソートしてから使ってね
template <class T> 
int former(const vector<T> &v, T x){
  return upper_bound(v.begin(), v.end(), x) - v.begin() - 1;
}
//x以上の要素への最小index
template <class T> 
int latter(const vector<T> &v, T x){
  return lower_bound(v.begin(), v.end(), x) - v.begin();
}
//vector書き出し
template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}
//nCk
template <class T>
T comb(T n,T k){
    T ans=1;
    FOR(i,n-k+1,n+1){
        ans*=i;
    }
    FOR(i,1,k+1){
        ans/=i;
    }
    return ans;
}
//a,bの最大公約数
template <class T>
T gcd(T a,T b) {
	if (b == 0) return a;
	else return gcd(b, a % b);
}
//素因数分解
template <class T>
map<T,T> prime_factor(T x){
    map<T,T> ans;
    for(T i=2;i*i<=x;i++){
        while(x%i==0){
            x/=i;
            ans[i]++;
        }
    }
    if (x!=1){
        ans[x]=1;
    }
    return ans;
}
//約数列挙
template <class T>
vector<T> divisor(T x){
    vector<T> res;
    for(T i=1;i*i<=x;i++){
        if(x%i==0){
            res.push_back(i);
            if(i!=x/i){
                res.push_back(x/i);
            }
        }
    }
    return res;
}
//素数判定
template <class T>
bool is_prime(T x){
    for(T i=2;i*i<=x;i++){
        if(x%i==0){
            return false;
        }
    }
    return x!=1;
}

const ll inf=1e9+7;

ll mult(ll n,ll m){//n^m%infを求める
    if(m==1){
        return n%inf;
    }else if(m%2==0){//オーバーフロー防止のためにn^(m/2)*n^(m/2)を考える
        ll t=mult(n,m/2);
        return (t*t)%inf;
    }else{//奇数の時はn^(m-1)*nを考える
        ll t=mult(n,m-1);
        return (t*n)%inf;
    }
}

typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a*b%2==0){
        cout<<"Even"<<endl;
    }else{
        cout<<"Odd"<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, Q, K;
struct edge
{
    int to, cost;
};
vector<edge> G[100005];
int d[100005];
PQG que;

signed main()
{
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        int a, b, c;
        cin >> a >> b >> c;
        G[a].pb({b, c});
        G[b].pb({a, c});
    }
    fill(d, d + N + 1, INFL);
    cin >> Q >> K;
    d[K] = 0;
    que.push(mk(0, K));
    while(!que.empty()){
        int dis = que.top().first;
        int pos = que.top().second;
        que.pop();
        if(d[pos] < dis) continue;
        for(int i = 0; i < (int)G[pos].size(); i++){
            edge e = G[pos][i];
            if(d[e.to] > dis + e.cost){
                d[e.to] = dis + e.cost;
                que.push(mk(d[e.to], e.to));
            }
        }
    }
    for(int i = 0; i < Q; i++){
        int a, b;
        cin >> a >> b;
        cout << d[a] + d[b] << endl;
    }

    return 0;
}
/*


*/


Measured memory_bytes: 11120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // to use min_element

using namespace std;

int main(){
	int a, b, c=0, i, count;
	cin >> a;
	// vector<int> numlst(a);
	for (i =0;i<a;i++){
	count =0;
	cin>> b;
	if (b%2==1){
		c =0; break;
	}else{
		if (c==0) c=b;
		while(b%2==0){
			count++;
			b=b/2;
		}
		if (count <c) c=count;
	}
	}
	cout << c;

return 0;
}

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

const int maxn = 4e3 + 5;

inline int gi()
{
	char c = getchar();
	while (c < '0' || c > '9') c = getchar();
	int sum = 0;
	while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
	return sum;
}

int A, B, n, stk[maxn], ans[maxn], top;
char s[15];
int query(int x, int y) {printf("? %d %d\n",x, y); fflush(stdout); scanf("%s", s); return s[0] == 'Y';}

int main()
{
	A = gi(); B = gi(); n = A + B;
	if (A <= B) return puts("Impossible"), 0;

	for (int i = 0; i < n; ++i)
		if (!top || query(stk[top], i)) stk[++top] = i;
		else --top;
	for (int i = 0; i < n; ++i)	ans[i] = query(stk[top], i);
	printf("! ");
	for (int i = 0; i < n; ++i) printf("%d", ans[i]);
	
	return 0;
}


Measured memory_bytes: 724
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter
 
    #inf = 10**17
    #mod = 10**9 + 7
 
    N = int(input())
    for i in range(10**3):
        if i*(i-1) == N*2:
            res = i
            break
    else:
        print('No')
        exit()
 
    s = [[] for _ in range(res)]
    num = 1
 
    for a,b in combinations(range(res), 2):
        s[a].append(num)
        s[b].append(num)
        num += 1
 
    print('Yes')
    print(res)
    for i in s:
        print('{} {}'.format(res-1, ' '.join(map(str, i))))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 9460
#include <bits/stdc++.h>
using namespace std;
int main(){
  cout << fixed << setprecision(20);
  double A, B;
  double H, M;
  cin >> A >> B >> H >> M;
  double theta1 = 2 * M_PI * ((H + (M / 60))/ 12);
  double theta2 = 2 * M_PI * (M / 60);
  double theta = abs(theta2 - theta1);
  if (theta >= M_PI){
    theta = 2 * M_PI - theta;
  }
  cout << sqrt(max(A * A + B * B - 2 * A * B * cos(theta), (double) 0)) << endl;
}

Measured memory_bytes: 4164
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace AtCoder {
    class Practice {
        static void Main() => CustomMain();

        static void Solve() {
            int a, b, c;
            ReadMulti(out a, out b, out c);

            long ans = 0;
            if (c <= a + b) {
                WriteAnswer(b + c);
            } else {
                WriteAnswer(a + b * 2 + 1);
            }
        }


        static void CustomMain() {
#if DEBUG
            // ファイルからテストケースを読み込む
            global::Common.ChangeStdIn();
            // 時間計測
            var stopwatch = new Stopwatch();
            stopwatch.Start();
#endif
            // 出力高速化
            var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
            Console.SetOut(streamWriter);
            // 回答
            Solve();
#if DEBUG
            stopwatch.Stop();
            Console.WriteLine(stopwatch.Elapsed);
#endif
            Console.Out.Flush();
        }

        static string ReadString() => Console.ReadLine().Trim();
        static int ReadInt() => int.Parse(ReadString());
        static long ReadLong() => long.Parse(ReadString());
        static float ReadFloat() => float.Parse(ReadString());
        static double ReadDouble => double.Parse(ReadString());

        static string[] ReadStringArray() => ReadString().Split(' ');
        static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
        static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
        static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
        static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

        static T TypeConversion<T>(string s) {
            if (typeof(T) == typeof(int)) {
                return (T) Convert.ChangeType(int.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(long)) {
                return (T) Convert.ChangeType(long.Parse(s), typeof(T));
            } else if (typeof(T) == typeof(double)) {
                return (T) Convert.ChangeType(double.Parse(s), typeof(T));
            } else {
                return (T) Convert.ChangeType(s, typeof(T));
            }
        }

        static void ReadMulti<T, U>(out T a, out U b) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
        }

        static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
            var str = ReadStringArray();
            a = TypeConversion<T>(str[0]);
            b = TypeConversion<U>(str[1]);
            c = TypeConversion<V>(str[2]);
        }

        static void WriteAnswer(object ans) => Console.WriteLine(ans);

        static bool IsOdd(long num) {
            return (num & 1) == 1;
        }

        static bool IsEven(long num) {
            return (num & 1) == 0;
        }

        static long GCD(long a, long b) {
            return b != 0 ? GCD(b, a % b) : a;
        }
    }
}

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

#define ll long long
#define rep(i,n) for(int i = 0;i < (n); i++)
#define mod 1000000007

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

	return 0;
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static List<int>[] v;
    static long[] ct;
    
    public static void Main()
    {
	var tmp = ReadIntArray();
	int n = tmp[0], q = tmp[1];
	    
	v = new List<int>[n];
	for (int i = 0; i < n; i++)
	{
	    v[i] = new List<int>();
	}

	for (int i = 0; i < n-1; i++)
	{
	    tmp = ReadIntArray();
	    int a = tmp[0], b = tmp[1];
	    v[a-1].Add(b-1);
	}

	ct = new long[n];
	for (int i = 0; i < q; i++)
	{
	    tmp = ReadIntArray();
	    int p = tmp[0], x = tmp[1];
	    ct[p-1] += x;
	}

	dfs(0, 0);

	for (int i = 0; i < n-1; i++){ Write($"{ct[i]} "); }
	WriteLine(ct[n-1]);
    }

    static void dfs(int node, long x)
    {
	long y = ct[node] + x;
	ct[node] = y;
	foreach (int m in v[node])
	{
	    dfs(m, y);
	}
    }
}


Measured memory_bytes: 62292
#include <stdio.h>
int main(void)
{
	int n,i;
	int array[100];
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&array[i]);
	}
	for (i=n;i>=2;i--){
		printf("%d ",array[i]);
	}
	printf("%d\n",array[1]);
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<math.h>
#include <stdio.h>
using namespace std;

int main(){
    char s[1000];
    scanf("%s", s);
    for(int i=0; i<1000; i++){
        if(s[i] == ' ')
            continue;
        if(s[i] == '\0')
           break;
        if(s[i]<='C')
            s[i] += 26;
        s[i] -= 3;
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 1112
import heapq
N, M = map(int, input().split())
lst = [[] for _ in range(M)]
for i in range(N):
    a, b = map(int, input().split())
    if a-1 < M:
        lst[a-1].append(-b)
        
total = 0
heap = []

for i in range(M):
    for reward in lst[i]:
        heapq.heappush(heap, reward)
    if len(heap) > 0:
        reward = heapq.heappop(heap)
        total += -reward
print(total)

Measured memory_bytes: 17732
def main():
  n=int(input())
  p = list(map(int,input().split()))
  ans=0
  for i in range(0,n-2):
    if max(p[i:i+3])!=p[i+1] and min(p[i:i+3])!=p[i+1]:
      ans+=1
  print(ans)
main()

Measured memory_bytes: 9052
n = int(input())

def wa(n):
  ret = 0
  while n > 0:
    ret += n%10
    n //= 10
  return ret

ans = 10**10
for a in range(1,n):
  b = n-a
  ans = min(ans,wa(a)+wa(b))  
  
print(ans)  

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

class UnionFind {
  vector<int> data;
  
public:
  UnionFind(int size) {
    data.assign(size, -1);
  }
  
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return false;
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
  
  int find(int k) {
    if (data[k] <  0) return k;
    return data[k] = find(data[k]);
  }
  
  int size(int k) {
    return -data[find(k)];
  }
  
  bool same(int x, int y) {
    return find(x) == find(y);
  }
};

int main(void) {
  int n, m, ans = 0;
  vector<int> p;
  
  cin >> n >> m;
  
  UnionFind tree(n);
  
  for (int i = 0; i < n; i++) {
    int in;
    cin >> in;
    in--;
    p.push_back(in);
  }
  
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    
    x--; y--;
    
    tree.unite(p[x], p[y]);
  }
  
  for (int i = 0; i < n; i++)
    if (p[i] == i || tree.same(p[i], i))
      ans++;
  
  cout << ans << endl;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=(n);i<(x);++i)
#define rem(i,n,x) for(int i=(n);i>=(x);--i)
#define pb push_back
#define setp(x) setprecision(x)
using ll = long long;

int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n); rep(i, 0, n) cin >> h[i];

	int ans=0;
	rep(i, 0, n) {
		if (h[i] >= k) ans++;
	}

	cout << ans << endl;

	return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

class LazySegT{
private:
  int NN;
  struct Node{
	int dat;
	int lazy;
  };
  Node segT[2*(1<<19)-1];
public:
  LazySegT(int n){
	NN = 1;
	while(NN < n) NN <<= 1;
	for(int i=0;i<2*NN-1;++i)
	  segT[i].dat = 0, segT[i].lazy = 0;
  }

  void eval(int k, int l, int r){
	if(segT[k].lazy == 0) return;
	
	segT[k].dat += segT[k].lazy * (r-l);
	if(k < NN-1){ // not leaf
	  segT[2*k+1].lazy += segT[k].lazy;
	  segT[2*k+2].lazy += segT[k].lazy;
	}
	segT[k].lazy = 0;
  }

  void update(int a, int b, int c, int k, int l, int r){
	eval(k,l,r);
	if(r <= a || b <= l) return;

	if(a <= l && r <= b){
	  segT[k].lazy += c;
	  eval(k,l,r);
	}
	else{
	  update(a, b, c, k*2+1, l, (l+r)/2);
	  update(a, b, c, k*2+2, (l+r)/2, r);
	  segT[k].dat = segT[k*2+1].dat + segT[k*2+2].dat;
	}
  }
  // dat[idx] += c, a <= idx < b
  void update(int a, int b, int c){
	update(a, b, c, 0, 0, NN);
  }

  int query(int a, int b, int k, int l, int r){
	eval(k,l,r);
	if(r <= a || b <= l) return 0;

	if(a <= l && r <= b) return segT[k].dat;
	else{
	  int vl = query(a, b, k*2+1, l, (l+r)/2);
	  int vr = query(a, b, k*2+2, (l+r)/2, r);
	  segT[k].dat = segT[k*2+1].dat + segT[k*2+2].dat;
	  return vl+vr;
	}
  }
  int query(int a, int b){
	return query(a, b, 0, 0, NN);
  }
};

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

  int N, M;
  cin >> N >> M;
  vector<PII> xs(N);
  REP(i,N){
	cin >> xs[i];
	xs[i].SS++;
  }
  sort(ALL(xs), [](const PII& l, const PII& r){
	  return l.SS - l.FF > r.SS - r.FF;
	});

  LazySegT seg(M+1);
  LL num = N;
  FOR(i,1,M+1){
	while(!xs.empty() && xs.back().SS - xs.back().FF < i){
	  --num;
	  seg.update(xs.back().FF, xs.back().SS, 1);
	  xs.pop_back();
	}

	LL ans = num;
	for(LL d=i;d<=M;d+=i)
	  ans += seg.query(d,d+1);
	cout << ans << endl;
  }

  return 0;
}


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

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

  vector<int> a(n);

  int total = 0;

  rep(i, n) {
    cin >> a[i];
    total += a[i];
  }

  int ans_count = 0;

  rep(i, n) {
    if (total <= a[i] * 4 * m) {
      ans_count++;
    }
  }

  if (m <= ans_count) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode('c${rg!EWj>5WFMt4=bvtLJ2Wdd#F&;Uw9X8eF!=B1}q%gwH=^;|JF%>RK=GhGvnFa**t($AvRIzuma7^uHic@#C$#;J%IR*duwj^R^t(M@iOG_96jF(TRWw3%l$4Ci@&X6V62SLjl``~J`|s9Z);@2nusBC6IrgU;F@VwGS}L^<ZmpfhzrNXfeHs^n%aHS9gnOx%Ya!I8IQtB^otPnW;_xStJD&D1C_TmOx}9|tI(X3I7E;5F#*GC4CIb5=>?P3cm#A>3*ns5JOt=(ZPT^S^`_UPGi0X9L@=`(d9+Fbm$D^X25UGE*foTvZYiBXdUztoqqboRLF6GyWkIOgSs!7CQS7<Tz<Cl^1EF*I5k<8As_j1eAe7O{U{?XToX&<LCbY~zKmp4RKJ96R@I08YB(kqQoxuWL-)@|$h<=CV3Q96R+=%2T;0d0WFo&|kJ;sJsBCd^5TqNtd%HV78uCf%^IZN4G2KliCZOv{2Po;`<%i!q_J59T&C>BMfz|-%G1W~6d=IvIpzT9uw*CiyH??-6q=xd)h%-_MfMNJ?7X!*}PW^LWH@-)({*P#wLuy%KB&UdiO2q`0i{{vzi8j1')))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 14032
import java.util.Scanner;

 public class Main {
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		int d=in.nextInt();
		if((a+b)>(c+d))
			System.out.println("Left");
		if((a+b)<(c+d))
			System.out.println("Right");
		if((a+b)==(c+d))
			System.out.println("Balanced");
		
	}
}


Measured memory_bytes: 23892
# 

def factorize(n):
    '''
    タプルの配列と思ったけど逐次割り算する過程で次数を増やせないじゃん。
    二重配列?
    dictにしよう。
    '''
    if n == 1:
        raise('n >= 2')
    
    factor = {}
    div = 2
    while True:
        if n % div == 0:
            n //= div
            factor[div] = factor.get(div, 0) + 1
            if n == 1:
                return factor
        else:
            div += 1

n = int(input())

if n <= 9:
    print(0)
    exit()

# めんどいから掛けてしまえ。間に合うだろ
import math
product = math.prod(range(1, n+1))
d = factorize(product)
factor = list(d.items())

# print(factor)

ans = 0
for i in range(len(factor)):
    for j in range(i+1, len(factor)):
        for k in range(len(factor)):
            if factor[i][1] >= 4 and factor[j][1] >= 4 and factor[k][1] >= 2 and i!=j and j!=k and k!=i:
                ans += 1

for i in range(len(factor)):
    for j in range(len(factor)):
            if factor[i][1] >= 4 and factor[j][1] >= 14 and i!=j:
                ans += 1

for i in range(len(factor)):
    for j in range(len(factor)):
            if factor[i][1] >= 2 and factor[j][1] >= 24 and i!=j:
                ans += 1

for i in range(len(factor)):
    if factor[i][1] >= 74:
                ans += 1

print(ans)

Measured memory_bytes: 9228
#include <iostream>


using namespace std;


int main()
{unsigned short m{0},d{0};unsigned short count{0};
    cin>>m>>d;
    for(unsigned short j{d};j>0;j--){
        if(j>10){
            unsigned short a=j%10;unsigned short b=(j-a)/10;
            if(a*b<=m&&a*b>0&&a>=2&&b>=2){count++;}
        }
    }
    cout<<count;
}

Measured memory_bytes: 256
import java.util.*;

//update 2019/12/13

public class Main{

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    String s = next();
    String t = next();

    System.out.println(t+s);


  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char aaa){
    return aaa - 48;
  }

  public static int maxInt(int[] a,int lng){
    int max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static int minInt(int[] a,int lng){
    int min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

  public static long maxLong(long[] a,int lng){
    long max=a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }

  public static long minLong(long[] a,int lng){
    long min=a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }

}


Measured memory_bytes: 23124
#include<stdio.h>
int mt(int a,int b)
{
	if(b==0)
	{
		return 1;
	}
	int c=mt(a,b>>1);
	c=(long long)c*c%998244353;
	if(b&1)
	{
		c=(long long)c*a%998244353;
	}
	return c;
}
int n;
int a[262144];
void fwt()
{
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<(1<<n);j++)
		{
			if(j&(1<<i))
			{
				int t=a[j];
				a[j]=a[j-(1<<i)]-t;
				if(a[j]<0)
				{
					a[j]+=998244353;
				}
				a[j-(1<<i)]+=t;
				if(a[j-(1<<i)]>=998244353)
				{
					a[j-(1<<i)]-=998244353;
				}
			}
		}
	}
}
int val[262144];
int tmp[262144];
int main()
{
	scanf("%d",&n);
	int s=0;
	for(int i=0;i<(1<<n);i++)
	{
		scanf("%d",&val[i]);
		s+=val[i];
	}
	s=mt(s,998244351);
	for(int i=0;i<(1<<n);i++)
	{
		val[i]=(long long)val[i]*s%998244353;
	}
	for(int i=0;i<(1<<n);i++)
	{
		a[i]=1;
	}
	a[0]-=(1<<n);
	if(a[0]<0)
	{
		a[0]+=998244353;
	}
	fwt();
	for(int i=0;i<(1<<n);i++)
	{
		tmp[i]=a[i];
		a[i]=-val[i];
		if(a[i]<0)
		{
			a[i]+=998244353;
		}
	}
	a[0]++;
	if(a[0]>=998244353)
	{
		a[0]-=998244353;
	}
	fwt();
	a[0]=0;
	for(int i=1;i<(1<<n);i++)
	{
		a[i]=(long long)tmp[i]*mt(a[i],998244351)%998244353;
		a[0]-=a[i];
		if(a[0]<0)
		{
			a[0]+=998244353;
		}
	}
	fwt();
	int invn=mt(1<<n,998244351);
	for(int i=0;i<(1<<n);i++)
	{
		int answer=(long long)a[i]*invn%998244353;
		printf("%d\n",answer);
	}
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <unordered_map>
#include <cmath>
#include <algorithm>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  ll a, b, asum, bsum;
  cin >> a >> b;
  asum = a;
  bsum = b;
  while (asum != bsum)
  {
    if (asum > bsum) bsum += b;
    else asum += a;
  }

  cout << asum;
}


Measured memory_bytes: 3580
N,M =map(int,input().split())
list_aaa = list(map(int,input().split()))

list_aaa = sorted(list_aaa)
list_aaa_range = []

for i in range(M-1):
    list_aaa_range.append(list_aaa[i+1]-list_aaa[i])

list_aaa_range = sorted(list_aaa_range)

for i in range(1,N):
    if not list_aaa_range :
        list_aaa_range.append(0)
    else:
        list_aaa_range.pop(-1)

print(sum(list_aaa_range))

Measured memory_bytes: 13968
#!/usr/bin/env python

A, B, C = map(int, input().split()) 
res = 10 * A + B + C
if A + 10 * B + C > res:
    res = A + 10 * B + C
if A + B + 10 * C > res:
    res = A + B + 10 * C

print(res)

Measured memory_bytes: 2940
import sys
input = sys.stdin.readline

x = int(input())

s = str(x)

if x<100:
    print(0)
    exit()
elif x>2000:
    print(1)
    exit()
else:
    if x>=1000:
        d = int(s[-4]+s[-3])
        # print(d)
        e = int(s[-2]+s[-1])
        # print(e)
        if d*5 >= e:
            print(1)
            exit()
        else:
            print(0)
            exit()
    else:
        d = int(s[-3])
        # print(d)
        e = int(s[-2]+s[-1])
        # print(e)
        if d*5 >= e:
            print(1)
            exit()
        else:
            print(0)
            exit()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 2005
using namespace std;
const int mo=1e9+7;
int n,m,k,S,f[2*N][N],ans;
void inc(int &x,int y){ x=x+y>=mo ? x+y-mo : x+y;}
void dec(int &x,int y){ x=x-y<0 ? x-y+mo : x-y;}
int main()
{
	int i,j;
	cin>>n>>m>>k;
	f[0][0]=1;
	for(i=1;i<=n+m-1;i++){
		S=0;
		for(j=0;j<=m;j++){
			if(j>=k) dec(S,f[i-1][j-k]);
			if(j%(k-1)==m%(k-1)&&(k-1)*i-j<=n-1&&((k-1)*i-j)%(k-1)==(n-1)%(k-1))
				inc(ans,S);
			inc(S,f[i-1][j]);
			inc(f[i][j],S);
		  }
	  }
	cout<<ans;
	return 0;
}


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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,a,b,c,d;
cin>>n>>a>>b>>c>>d;
a--,b--,c--,d--;
string s;
cin>>s;

vector<bool>dp_snuke(n,false);
vector<bool>dp_hnuke(n,false);
dp_snuke[a]=true;
dp_hnuke[b]=true;
rep(i,n-1){
    if(dp_snuke[i]){
        if(s[i+1]!='#')dp_snuke[i+1]=true;
        if(i+2<n&&s[i+2]!='#')dp_snuke[i+2]=true;
    } 
    if(dp_hnuke[i]){
        if(s[i+1]!='#')dp_hnuke[i+1]=true;
        if(i+2<n&&s[i+2]!='#')dp_hnuke[i+2]=true;
    } 
}    
if(dp_snuke[c]&&dp_hnuke[d]){
    if(c<d){
        cout<<"Yes"<<endl;
    }
    else{
        reps(i,d+1,b){
            if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.'){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
        cout<<"No"<<endl;
    }
}
else{
    cout<<"No"<<endl;
}

return 0;
}

Measured memory_bytes: 3740
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    int A, B;
    cin >> A >> B;

    if(A*B*1%2 == 1 ||A*B*2%2 == 1||A*B*3%2 == 1)cout << "Yes" << endl;
    else cout << "No" << endl;


}



Measured memory_bytes: 3588
#include <stdio.h>

int main(void)
{
	int S, s12, s34, M12=0, M34=0;
	
	scanf("%d", &S);
	s12 = S / 100;
	s34 = S - 100 * s12;

	if (s12 <= 12 && s12 != 0)M12 = 1;
	if (s34 <= 12 && s34 != 0)M34 = 1;

	if (M12 == 0 && M34 == 0) printf("NA");
	else if (M12 == 1 && M34 == 1)printf("AMBIGUOUS");
	else if (M12 == 0)printf("YYMM");
	else printf("MMYY");

	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    int n,a,b,c,five=0,seven=0;
    scanf("%d%d%d",&a,&b,&c);
    if(a==5)five++;
    if(a==7)seven++;
    if(b==5)five++;
    if(b==7)seven++;
    if(c==5)five++;
    if(c==7)seven++;
    if(five==2&&seven==1){
        printf("YES");
    }else printf("NO");
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
using namespace std;
int a,b;
string s;
int main()
{
	cin>>a>>b;
	cin>>s;
	if(s[a]!='-') cout<<"No";
	else{
		for(int i=0;i<=a-1;i++)
		{
			if(s[i]-'0'>=0&&s[i]-'0'<=9) continue;
			else
			{
				cout<<"No";
				return 0;
			}
		}
		for(int i=a+1;i<=a+b;i++)
		{
			if(s[i]-'0'>=0&&s[i]-'0'<=9)  continue;
			else
			{
				cout<<"No";
				return 0;
			}
		} 
		cout<<"Yes";
	}  
	return 0;
}

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

using namespace std;

const int kSize = 25;

struct Node {
    int parent = -1;
    int left, right;
};

Node tree[kSize];

void PreOrder(int root) {
    if (root == -1) {
        return;
    }

    printf(" %d", root);
    PreOrder(tree[root].left);
    PreOrder(tree[root].right);
}

void InOrder(int root) {
    if (root == -1) {
        return;
    }

    InOrder(tree[root].left);
    printf(" %d", root);
    InOrder(tree[root].right);
}

void PostOrder(int root) {
    if (root == -1) {
        return;
    }

    PostOrder(tree[root].left);
    PostOrder(tree[root].right);
    printf(" %d", root);
}

int FindRoot(int n) {
    for (int i = 0; i < n; ++i) {
        if (tree[i].parent == -1) {
            return i;
        }
    }

    return -1;
}

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        tree[id].left = left;
        tree[id].right = right;
        if (left != -1) {
            tree[left].parent = id;
        }
        if (right != -1) {
            tree[right].parent = id;
        }
    }

    int root = FindRoot(n);

    printf("Preorder\n");
    PreOrder(root);
    printf("\n");

    printf("Inorder\n");
    InOrder(root);
    printf("\n");

    printf("Postorder\n");
    PostOrder(root);
    printf("\n");

    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

int main (void)
{
    int n, *a, *b, *c;

    cin >> n;
    a = (int *)malloc(sizeof(int) * n);
    b = (int *)malloc(sizeof(int) * n);
    c = (int *)malloc(sizeof(int) * n);
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    sort(a, a + n);
    sort(c, c + n);

    long ans = 0;
    for (int i = 0; i < n; i++) {
        int *a_lower = lower_bound(a, a + n, b[i]);
        int *c_upper = upper_bound(c, c + n, b[i]);
        /*cout << "b[" << i << "]: " << b[i] << endl;
        cout << "   a_lower: " << *a_lower << ", pos: " << (a_lower - a) << endl;
        cout << "   c_upper: " << *c_upper << ", pos: " << (c_upper - c) << endl;
        cout << (a_lower - a) * (c + n - c_upper) << endl;
        cout << "\n";*/
        ans += (a_lower - a) * (c + n - c_upper);
    }
    cout << ans << endl;

    free(a);
    free(b);
    free(c);

    return 0;
}

Measured memory_bytes: 1408
use itertools::Itertools;
use proconio::input;

const WIDTH: usize = 41;

trait OrdTools: Ord + Clone + Sized {
    fn chmin(&mut self, x: Self) {
        *self = std::cmp::min(self.clone(), x);
    }
    fn chmax(&mut self, x: Self) {
        *self = std::cmp::max(self.clone(), x);
    }
}

impl<T: Ord + Clone + Sized> OrdTools for T {}

fn main() {
    input!(n: usize, orig: [u64; n]);
    let make_seq = |x| (0..WIDTH).map(|i| (x >> i & 1) as usize).collect_vec();
    let a = make_seq(orig[0]);
    let b = make_seq(orig[1]);
    let c = make_seq(orig.iter().skip(2).fold(0, |x, y| x ^ y));
    // eprintln!("{:?}", a);
    // eprintln!("{:?}", b);
    // eprintln!("{:?}", c);

    let mut dp = vec![vec![[std::u64::MAX; 2]; 2]; WIDTH + 1];
    dp[0][0][0] = 0;
    for i in 0..WIDTH {
        let x = a[i];
        let y = b[i];
        let z = c[i];
        // eprintln!("(i, x, y, z) = {:?}", (i, x, y, z));
        // eprintln!("dp[i] = {:?}", dp[i]);
        for ((j, k), l) in (0..2)
            .cartesian_product(0..2)
            .cartesian_product(0..2)
            .filter(|&((j, k), _)| x ^ y ^ z ^ j ^ k == 0)
        {
            let crr = dp[i][j][k];
            if crr != std::u64::MAX {
                let nj = (x < j + l) as usize;
                let nk = (2 <= y + l + k) as usize;
                dp[i + 1][nj][nk].chmin(crr + l as u64 * (1 << i));
            }
        }
    }
    let ans = *dp[WIDTH]
        .iter()
        .map(|v| v.iter().min().unwrap())
        .min()
        .unwrap();
    println!("{}", if orig[0] <= ans { -1 } else { ans as i64 });
}


Measured memory_bytes: 2144
n, m = map(int, input().split())
A = [int(input()) for _ in range(m)]
mod = 10 ** 9 + 7
dp = [0] * (n + 1)
dp[0] = 1
for a in A:
    dp[a] = -1
for i in range(n):
    if dp[i] == -1:
        continue
    if i + 1 <= n:
        if dp[i + 1] >= 0:
            dp[i + 1] += dp[i]
            dp[i + 1] %= mod
    if i + 2 <= n:
        if dp[i + 2] >= 0:
            dp[i + 2] += dp[i]
            dp[i + 2] %= mod
print(dp[n] % mod)


Measured memory_bytes: 7844