akhauriyash/Code-Regression huggingface dataset:
/* ex3_4 melo */
#include <stdio.h>
int main(void){
    int Num, Result, N1, N2;//４つの整数の箱を作る
    int TorF=0;//Numが1以上9以下の2つの整数の積として表すことができるれば1、できなければ0を返す整数の箱を作り0を代入する
    scanf("%d",&Num);//Numに整数を代入する
        for(N1=1;N1<10;N1++){//九九を行う
            for(N2=1;N2<10;N2++){
                Result=N1*N2;//九九の結果を代入
                if(Num==Result){//九九の結果の中にNumと一致する値があれば
                    TorF=1;//1以上9以下の2つの整数の積として表すことができる
                }
            }
        }
        if(TorF==1){//1以上9以下の2つの整数の積として表すことができる
            printf("Yes\n");
        }else{//1以上9以下の2つの整数の積として表すことができない
            printf("No\n");
        }

        return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    int i=1;
    while(i<=k)
    {
        cout<<s<<" ";
        i++;
    }
    i=1;
    if(n-k>=1)
    {
        while(i<=n-k)
        {
            if(s==1000000000){
                cout<<s-1<<" ";
            }
            else{
            cout<<s+1<<" ";
            }
            i++;
        }
        
    }
        
}

Measured memory_bytes: 1280
import sys
sys.setrecursionlimit(100000000)

INF = 10**10
def solve(h, n, a, b):
    ab = sorted(zip(a, b), key=lambda _:(_[0]/_[1], -_[0]), reverse=True)
    dp = [-1] * h
    def f(h):
        best = INF
        for x, y in ab:
            if h-x <= 0:
                score = y
            else:
                if dp[h-x] == -1:
                    dp[h-x] = f(h-x)
                score = y + dp[h-x]
            if score < best:
                best = score
            else:
                break
        return best
    return f(h)

h, n = map(int, input().split())
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(h, n, a, b))

Measured memory_bytes: 14956
def main():
  N = int(input())
  t = input().split(" ")
  a = [int(i) for i in t]
  b = sorted(a)
  sm = b[N//2-1]
  bm = b[N//2]
  
  for i in a:
    if i <= sm:
      print(bm)
    else:
      print(sm)
main()


Measured memory_bytes: 29976
import numpy as np

H,W=map(int,input().split(' '))
# 回数の最大値はH+W
max_value = H+W
values =[]

# マス目に回数を入れる。黒なら0、白なら最大値を入れておく
for i in range(H):
    values.append([0 if i == '#' else max_value for i in list(input())])
# numpy配列に
values = np.array(values)

# 右のセルと比較して、
for x in range(W-1):
    values[:,x+1] = np.minimum(values[:,x]+1,values[:,x+1])
for x in range(W-1,0,-1):
    values[:,x-1] = np.minimum(values[:,x-1],values[:,x]+1)
for x in range(H-1):
    values[x+1,:] = np.minimum(values[x,:]+1,values[x+1,:])
for x in range(H-1,0,-1):
    values[x-1,:] = np.minimum(values[x,:]+1,values[x-1,:])
print(np.max(values))


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

#define int long long

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



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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int A, B; cin >> A >> B;
  if(B % A == 0) cout << A + B << endl;
  else cout << B - A << endl;
}


Measured memory_bytes: 3632
x = list(map(int, input().split()))

if x[0] == 0:
  print(1)
elif x[1] == 0:
  print(2)
elif x[2] == 0:
  print(3)
elif x[3] == 0:
  print(4)
elif x[4] == 0:
  print(5)

Measured memory_bytes: 9148
#include<iostream>
#define MAX_V 16
#define INF 100000000
using namespace std;
int n,s,t,l,m;
int dp[1<<MAX_V][MAX_V];
int d[MAX_V][MAX_V];
int solve(int S,int v){
  if(dp[S][v]>=0){
    return dp[S][v];
  }
  if(S==(1<<n)-1 && v==0){
    return dp[S][v]=0;
  }
  int res = INF;
  for(int u=0;u<n;u++){
    if(!(S>>u&1)){
      res = min(res,solve(S | 1<<u, u)+d[v][u]);
    }
  }
  return dp[S][v] = res;
}
int main(){
  cin >> n>>m;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      d[i][j]=INF;
    }
  }
  for(int i=0;i<1<<n;i++){
    for(int j=0;j<n;j++){
      dp[i][j]=-1;
    }
  }
  for(int i=0;i<m;i++){
    cin >> s >> t;
    cin >>d[s][t];
  }
  int tmp=solve(0,0);
  if(tmp==INF){
    cout << "-1\n";
  }else{
    cout << tmp<<endl;
  }
  
}



Measured memory_bytes: 5132
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n;
  cin >> n;
  vector<ll> a(n),b(n);
  ll ans = 0;
  ll bmin = longinf;
  rep(i,n){
    cin >> a[i] >> b[i];
    ans += a[i];
    if(a[i]>b[i]){
      bmin = min(bmin, b[i]);
    }
  }
  if(a==b){cout<<0<<endl; return 0;}
  cout << ans-bmin << endl;
  return 0;
}

Measured memory_bytes: 512
import math

n = int(input())
#a = int(input())
#a,b = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
#ls = list(map(int,input().split(" ")))
#a,b = list(input().split())
#string = input()
ls = [int(input()) for i in range(n)]
ls = set(ls)

print(len(ls))

Measured memory_bytes: 2940
#include<stdio.h>

int A[110];
int main(){
  int N,M,i,j,t;
  scanf("%d%d",&N,&M);
  for(i=0;i<N;i++) scanf("%d",A+i);
  for(i=1;i<=M;i++){
    for(j=0;j<N-1;j++){
      if(A[j]%i>A[j+1]%i){
	t=A[j];
	A[j]=A[j+1];
	A[j+1]=t;
      }
    }
  }
  for(i=0;i<N;i++) printf("%d\n",A[i]);
  return 0;
}


Measured memory_bytes: 1968
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+9,MAX_N=2e5+10;

int N;
int a[MAX_N];
vector<int> G[MAX_N];
int ans[MAX_N];
vector<int> dp;

void dfs(int v,int p){
    int nxt=lower_bound(dp.begin(),dp.end(),a[v])-dp.begin();
    int tmp=dp[nxt];
    dp[nxt]=a[v];
    ans[v]=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();
    for (int u:G[v]){
        if (u==p) continue;
        dfs(u,v);
    }
    dp[nxt]=tmp;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for (int i=0;i<N;++i) cin >> a[i];
    for (int i=0;i<N-1;++i){
        int u,v; cin >> u >> v; --u,--v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    for (int i=0;i<N;++i) dp.emplace_back(INF);
    dfs(0,-1);
    for (int i=0;i<N;++i) cout << ans[i] << '\n';
}

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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18

void solve(){
  int n ,k;cin>>n>>k;
  vector<bool> dp(k+1);
  vi a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=1;i<=k;i++){
    bool f=0;
    for(int x:a){
      if(x>i)break;
      if(!dp[i-x]||i==x){f=1;break;}
    }
    dp[i]=f;
  }
  if(dp[k])cout<<"First";
  else cout<<"Second";
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = 102;
typedef pair<int, int> pii;

struct TFlow {
    struct TEdge {
        int u, v, cf;
        TEdge() {u = v = cf = 0;}
        TEdge(int u, int v, int cf): u(u), v(v), cf(cf) {}
    };
    int s, t, n, FlowVal;
    vector<TEdge> e;
    vector<vector<int>> a;
    vector<int> trace;
    TFlow() {}
    TFlow(int s, int t, int n): s(s), t(t), n(n) {
         e.clear(); a.resize(n + 1); trace.resize(n + 1);
    }
    void AddEdge(int u, int v, int cf) {
        a[u].pb(e.size()); e.pb(u, v, cf);
        a[v].pb(e.size()); e.pb(v, u, 0);
    }
    bool BFS() {
        fill(trace.begin(), trace.end(), -1);
        trace[s] = -2; queue<int> q; q.push(s);
        while(q.size()) {
            int u = q.front(); q.pop();
            for(int i: a[u]) {
                int v = e[i].v;
                if(e[i].cf > 0 && trace[v] == -1) {
                    q.push(v), trace[v] = i;
                    if(v == t) return 1;
                }
            }
        }
        return 0;
    }
    int GetMaxFlow() {
        int delta, u, i;
        FlowVal = 0;
        while(BFS()) {
           delta = int(1e9 + 7);
           for(u = t; (i = trace[u]) >= 0; u = e[i].u)
               delta = min(delta, e[i].cf);
           for(u = t; (i = trace[u]) >= 0; u = e[i].u)
               e[i].cf -= delta, e[i ^ 1].cf += delta;
           FlowVal += delta;
        }
        return FlowVal;
    }
};

int n, m;
string s;
pii S, T;

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n >> m;
    TFlow Flow = TFlow(0, n + m + 1, n + m + 2);
    ///s = 0, t = n + m + 1, n row(1 -> n), m col(n + 1 -> n + m)
    for(int i = 1; i <= n; ++i) {
        cin >> s; s = ' ' + s;
        for(int j = 1; j <= m; ++j) {
            if(s[j] == '.') continue;
            if(s[j] == 'S') {
                Flow.AddEdge(0, i, int(1e9 + 7));
                Flow.AddEdge(0, j + n, int(1e9 + 7));
                S = mp(i, j);
            } else if(s[j] == 'T') {
                Flow.AddEdge(j + n, n + m + 1, int(1e9 + 7));
                Flow.AddEdge(i, n + m + 1, int(1e9 + 7));
                T = mp(i, j);
            }
            Flow.AddEdge(i, j + n, 1);
            Flow.AddEdge(j + n, i, 1);
        }
    }
    if(S.fi == T.fi || S.se == T.se) return cout << -1, 0;
    else cout << Flow.GetMaxFlow();
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n;
    cin >> n;

    int64_t ans = 0;
    vector f(n + 1, 0L);
    for (auto k : irange(1L, n + 1)) {
        for (int64_t m = k; m <= n; m += k) {
            ++f[m];
        }

        ans += k * f[k];
    }

    cout << ans << endl;
}

Measured memory_bytes: 81400
#include <iostream>
#include <algorithm>
using namespace std;
using ll = long long;
#define MXN 101
#define MXK 100010
#define mod 1000000007
ll dp[MXN][MXK], a[MXN], pre_sum[MXN][MXK];

ll fast_sum(ll i, ll j)
{
	ll lw = max(0ll, j-a[i]);
	if(!lw) return pre_sum[i-1][j]%mod;
	ll ret = pre_sum[i-1][j]%mod-pre_sum[i-1][lw-1]%mod;
	if(ret<0ll) ret+=mod;
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll N; cin>>N;
	ll K; cin>>K;
	for(ll i=1; i<=N; i++) cin>>a[i];

	dp[0][0] = 1ll;
	pre_sum[0][0] = 1ll;
	for(ll j=1; j<=K; j++) pre_sum[0][j] = pre_sum[0][j-1];
	for(ll i=1; i<=N; i++) pre_sum[i][0] = 1ll;

	for(ll i=1; i<=N; i++)
	{
		for(ll j=0; j<=K; j++)
		{
			dp[i][j] = fast_sum(i, j);
			if(j>0) pre_sum[i][j] = pre_sum[i][j-1]%mod+dp[i][j], pre_sum[i][j]%=mod;
			/*for(ll k=0; k<=a[i]; k++)
				if(j>=k) dp[i][j]+=dp[i-1][j-k];*/
		}
	}
	cout << dp[N][K]%mod << '\n';
	return 0;
}

Measured memory_bytes: 158080
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A, B, C, D, E; //もともとの肉の温度 ,目的の温度 ,凍った肉を 1 ℃温めるのにかかる時間 ,凍った肉を解凍するのにかかる時間,凍っていない肉を 1 ℃温めるのにかかる時間
    cin >> A >> B >> C >> D >> E;
    int x;
    if(A < 0){
        x = (0 - A) * C + D + B * E;
    }
    else if (A > 0){
        x = (B - A) * E;
    }
    else{
        x = D + B * E;
    }
    cout << x << endl;
}



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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
//定数　
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define INTINF 1000000000
#define MOD 10000007 //10^9+7:合同式の法
#define MAXR 100000  //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

#define N_MAX 100000
#define h_MAX 10000

int main()
{
    int N;
    int K;
    int a[N_MAX + 1];
    int b[N_MAX + 1];
    int c[N_MAX + 1];

    long dp[N_MAX + 1][3];
    long ans;

    memset(dp, 0, sizeof(dp));
    memset(a, 0, sizeof(a));
    memset(b, 0, sizeof(b));
    memset(c, 0, sizeof(c));

    cin >> N;
    REP(i, N)
    {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];

    for (int i = 1; i < N; i++)
    {
        dp[i][0] = max(dp[i - 1][1] + a[i], dp[i - 1][2] + a[i]);
        dp[i][1] = max(dp[i - 1][0] + b[i], dp[i - 1][2] + b[i]);
        dp[i][2] = max(dp[i - 1][0] + c[i], dp[i - 1][1] + c[i]);
    }

    ans = max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2]));
    cout << ans;
}

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

int main()
{
  string n;
  cin >> n;
  if((n.at(0) == n.at(1) && n.at(1) == n.at(2)) || (n.at(1) == n.at(2) && n.at(2) == n.at(3)))
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 764
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  vvll as(n, vll(n));
  rep(i, n) rep(j, n) cin >> as[i][j];

  vll pts(1 << n);
  rep(s, 1 << n) {
    rep(i, n) repLRE(j, i + 1, n - 1) {
      if ((s >> i) & (s >> j) & 1) pts[s] += as[i][j];
    }
  }

  vll dp(1 << n, 0);
  rep(s, 1 << n) {
    chmax(dp[s], pts[s]);
    for (ll t = s; t > 0; --t &= s) {
      chmax(dp[s], dp[s & t] + dp[s & ~t]);
    }
  }

  cout << dp[(1 << n) - 1] << endl;

  return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6;
int pr[N], f = 1;
bool vis[N] = {0};
void era(){
	for(int i = 2; i < N; i++)
		if(!vis[i]){
			for(int j = i * 2; j < N; j += i)
				vis[j] = true;
		}
	for(int i = 2; i < N; i++)
		if(!vis[i]){
			pr[f++] = i;
//			printf("%d\n",i);
	}
}

int main(){
	era();
	int x;
	while(cin >> x){
		for(int i = 1; i < f; i++)
			if(pr[i] >= x){				
				printf("%d\n",pr[i]);
				break;
			}
	}
	return 0;
}

Measured memory_bytes: 1536
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int i = 0; i < 3; i++) ans += s[i] == t[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i=0; i< (int)(n); i++)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> V(N, -1);
    vector<vector<int>> to(N), cost(N);
    int ui, vi, wi;
    rep(i,N-1) {
        cin >> ui >> vi >> wi;
        ui--;
        vi--;
        wi %= 2;
        to[ui].push_back(vi);
        to[vi].push_back(ui);
        cost[ui].push_back(wi);
        cost[vi].push_back(wi);
    }
    queue<int> q;
    V[0] = 0;
    q.push(0);
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        rep(i, to[v].size()) {
            int u = to[v][i];
            int w = cost[v][i];
            if (V[u] != -1) continue;
            V[u] = (V[v] + w) % 2;
            q.push(u);
        }
    }

    rep(i,N) {
        cout << V[i] << endl;
    }
}

Measured memory_bytes: 14460
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;


void solve(){
	char ch ;
	cin >> ch ;
	for(char i = 'a' ; i <= 'z' ; i++){
		if(ch == i){
			cout << 'a' << endl ;
			return ;
		}
	}
	cout << 'A' << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
}


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

int N, K, C;
string S;
int L[200100], R[200100];

signed main() {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K >> C >> S;
    int now = 0;
    rep(i, K) {
        while (S[now]=='x') now++;
        L[i] = now;
        now += C+1;
    }
    now = N-1;
    for (int i=K-1; i>=0; i--) {
        while (S[now]=='x') now--;
        R[i] = now;
        now -= C+1;
    }
    rep(i, K) if (L[i]==R[i]) cout << L[i]+1 << endl;
}

Measured memory_bytes: 6824
def root(v):
    if v == par[v]:
        return v
    par[v] = root(par[v])
    return par[v]

def unite(u, v):
    u = root(u)
    v = root(v)
    if u == v:
        return
    if size[u] < size[v]:
        par[u] = v
        size[v] += size[u]
    else:
        par[v] = u
        size[u] += size[v]

N, M = map(int, input().split())
E = []
par = list(range(N))
size = [1] * N
for i in range(M):
    a, b = map(int, input().split())
    E.append((a, b))

ans = [0] * M
ans[-1] = N * (N - 1) // 2
for i in range(M-1, 0, -1):
    a, b = E[i]
    c = root(a-1)
    d = root(b-1)
    if c == d:
        ans[i-1] = ans[i]
    else:
        ans[i-1] = ans[i] - size[c] * size[d]
    unite(a-1, b-1)

print(*ans, sep="\n")

Measured memory_bytes: 26176
class binary_tree():
    def __init__(self,value,left=None,right=None):
        self.value=value
        self.left=left
        self.right=right

def find_corres_bra(s,fr,to):
    count=0 
    x=-1
    for i in range(len(s)):
        if s[i]==fr:
            count += 1
        elif s[i]==to:
            if count==1:
                x=i
                break
            else:
                count-=1
    return x
    

def make_tree(s):
    if s=='':
        return None
    x0=0
    x1=find_corres_bra(s,'(',')')+1
    x2=x1+find_corres_bra(s[x1:],'[',']')+1
    tree=binary_tree(int(s[x1+1:x2-1]),make_tree(s[x0+1:x1-1]),make_tree(s[x2+1:-1]))
    return tree

def synthe_trees(t1,t2):
    tree=binary_tree(value=t1.value+t2.value)
    if t1.left!=None and t2.left !=None:
        tree.left=synthe_trees(t1.left,t2.left)
    if t1.right!=None and t2.right !=None:
        tree.right=synthe_trees(t1.right,t2.right)
    return tree

def tree_to_str(tree):
    if tree==None:
        return ''
    ans='('+ tree_to_str(tree.left)+')'+'['+str(tree.value)+']'+'('+ tree_to_str(tree.right)+')'
    return ans

t1=make_tree(input())
t2=make_tree(input())
tree=synthe_trees(t1,t2)
print(tree_to_str(tree))
        


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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

v<pair<ll, int>> factorize(ll n) {
    v<pair<ll, int>> res;
    for (ll i = 2; i * i <= n; ++i) {
       if (n%i) continue;
       res.emplace_back(i,0);
       while(n%i == 0) {
           n /= i;
           res.back().second++;
       }
    }
    if (n != 1) res.emplace_back(n,1);
    return res;
}

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

    ll a, b; cin >> a >> b;
    ll g = gcd(a,b);
    auto f = factorize(g);
    int ans = f.size() +1;
    cout << ans << endl;
    return 0;
}


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


def main():
    A,B,C=map(int, input().split())
    ans = 0
    while 1:
        if A%2==1 or B%2==1 or C%2==1:
            break
        if A==B==C:
            print(-1)
            return
        tA = A
        tB = B
        A = (B+C)//2
        B = (tA+C)//2
        C = (tB+tA)//2
        ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

signed main(){
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    int sum=0,Ans=1145141919810;
    for(int i=0;i<=max(x,y);i++){
        sum=0;//ABを2i枚買う
        sum+=2*i*c;
        sum+=a*max((int)0,x-i);
        sum+=b*max((int)0,y-i);
        Ans=min(Ans,sum);
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <utility>
#include <cmath>
#include <queue>
#include <stack>

using namespace std;

#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define MOD 998244353
#define MAX_N 1111

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef pair<ll,ll> pll;

int main() {
  int n, h, w;
  scanf("%d %d %d", &n, &h, &w);
  int a, b;
  int ans = 0;
  for(int i = 0; i < n; ++i) {
    scanf("%d %d", &a, &b);
    if(a >= h && b >= w) ++ans;
  }
  printf("%d\n", ans);
  return 0;
}


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

int Palindromic(int a, int b){
  int sum = 0;
  for(int i = a; i < b + 1; i++){
    int s = i % 10, t = i / 10 % 10; //1の位と10の位
    int u = i / 1000 % 10, v = i / 10000 % 10; //千の位と一万の位

    if(s == v && t == u){
      sum++;
    }
  }
  return sum;
}



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

  cout << Palindromic(a, b) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int pref[300010];
int suff[300010];
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    for(int i=1; i<n; i++)
    {
        if(s[i-1]=='W')pref[i] = pref[i-1] + 1;
        else pref[i] = pref[i-1];
    }
    for(int i=n-2; i>=0; i--)
    {
        if(s[i+1]=='E')suff[i] = suff[i+1]+1;
        else suff[i] = suff[i+1];
    }
    int mn = INT_MAX;

    for(int i=0; i<n; i++)
    {
        mn = min(mn,suff[i]+pref[i]);
    }
    cout << mn << endl;
}


Measured memory_bytes: 6112
#define M_PI 3.14159265359
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
class P{
public:
	double x,y;
	P(){}
	P(double xx,double yy){
		x=xx;
		y=yy;
	}
	P operator +(P p){
		return P(x+p.x,y+p.y);
	}
	P operator -(P p){
		return P(x-p.x,y-p.y);
	}
	P operator /(double d){
		return P(x/d,y/d);
	}
};

int n;
P p[301];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%lf%lf",&p[i].x,&p[i].y);
		}
		int res=1;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				P np=p[j]-p[i];
				//printf("%lf %lf\n",np.x,np.y);
				double blen=np.x*np.x/4.0+np.y*np.y/4.0;
				if(blen>1.0)continue;
				double len=sqrt(1-blen);
				double dir=atan2(np.y,np.x);
				P cp=(p[i]+p[j])/2+P(len*cos(dir+M_PI/2),len*sin(dir+M_PI/2));
				int cnt=0;
				for(int k=0;k<n;k++){
					double len2=sqrt((cp.x-p[k].x)*(cp.x-p[k].x)+(cp.y-p[k].y)*(cp.y-p[k].y));
					if(len2<=1.0001)cnt++;
				}
				res=max(res,cnt);
				cp=(p[i]+p[j])/2+P(len*cos(dir-M_PI/2),len*sin(dir-M_PI/2));
				cnt=0;
				for(int k=0;k<n;k++){
					double len2=sqrt((cp.x-p[k].x)*(cp.x-p[k].x)+(cp.y-p[k].y)*(cp.y-p[k].y));
					if(len2<=1.0001)cnt++;
				}
				res=max(res,cnt);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1160
n = gets.to_i
p = gets.split.map(&:to_i)
res = 0
[*1..(n-2)].each do |i|
    s = [p[i-1], p[i], p[i+1]]
    res += 1 if p[i] != s.min && p[i] != s.max
end
puts res

Measured memory_bytes: 1788
from collections import Counter

N, K = map(int, input().split(' '))
A = tuple(map(int, input().split(' ')))

counter = Counter()

i = 1
while True:
    if counter[i] >= 2:
        break
    counter[i] += 1
    i = A[i - 1]

loop = len([0 for v in counter.values() if v == 2])
to_loop = len([0 for v in counter.values() if v == 1])

if K > to_loop:
    K = to_loop + (K - to_loop) % loop

i = 1
for _ in range(K):
    i = A[i - 1]

print(i)


Measured memory_bytes: 37336
// I WILL FLY ONEDAY //1

#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define pb push_back
#define vx vector<ll> x
#define vy  vector<ll> y
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  f   first
#define  s   second
#define mod 1000000007
using namespace std;

/*
check for corner cases(for n==1)
 check for int overflow
 run on some sample cases before submitting
*/

/*FERMAT THEOREM

       pow(x,m-1)%m=1 (x and m are co-prime)
*/
/*MODULAR INVERSE

        pow(x,-1)=pow(x,m-2) (x and m are co-prime)
*/

/*
ll  mode(ll x,ll n,ll mod)
{
    if(n==0)return 1%mod;

    ll u=mode(x,n/2,mod);
    u=(u*u)%mod;
    if(n & 1)u=(u*x)%mod;
}
*/

int main()
{
   fast;
      ll a,b;
      cin>>a>>b;

      ll z= max(a+b,max(a-b,a*b));
      cout<<z<<endl;
}











































































Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<typename T> using Graph = vector<vector<T>>;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define endl '\n'

ll N, P, Q;
ll A[500005];
ll sum;

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

  cin >> N >> P >> Q;
  rep(i, N) {
    ll C;
    cin >> C;
    sum += C;
    A[i] = C - (Q - i)*P;
  };

  sort(A, A + N);
  ll ans = sum;
  rep(i, N) {
    sum += 2*P*i - A[i];
    ans = max(ans, sum);
  }
  
  cout << ans << endl;

  return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.size();
    int ans = 0;
    for (int i=0;i<n;i++){
        if (s[i] != s[n-1-i]){
            ans++;
        }
    }

    cout << ans/2 << endl;

}

Measured memory_bytes: 256
from pprint import pprint
import sys

N, W = map(int, sys.stdin.readline().strip().split(" "))

w = []
for _ in range(N):
    w_i, v_i = map(int, sys.stdin.readline().strip().split(" "))
    w.append((w_i, v_i))

dp = []
for _ in range(N+1):
    dp.append([0] * (W+1))


for i in range(N):
    for j in range(W+1):
        if j - w[i][0] >= 0:
            dp[i+1][j] = max(dp[i][j - w[i][0]] + w[i][1], dp[i+1][j])
        dp[i+1][j] = max(dp[i][j], dp[i+1][j])
# pprint(dp)
print(dp[N][W]) 

Measured memory_bytes: 120684
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        a: String,
        b: String
    };
    let arr = ["H", "D", "H"];
    let rs = arr[((a == "H") as usize + (b == "H") as usize)];
    println!("{}", rs);
}


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

const double PI = 3.14159265358979;

class Point {
public:
    double x, y;
    Point(double x = 0.0, double y = 0.0) :x(x), y(y) {}
};

class Wind {
public:
    double w, a;
};

bool include(double angle, double low, double high) {
    if(low < 0.0 && 2.0 * PI + low <= angle) return true;
    if(high >= 2.0 * PI && angle <= high - 2.0 * PI) return true;
    return low <= angle && angle <= high;
}

bool savor(const Point &home, const Wind &wind, const vector<Point> &blossom, double d) {
    d /= 2.0;
    for(const auto &b: blossom) {
        Point dif(home.x - b.x, home.y - b.y);
        double angle = atan2(dif.y, dif.x);
        double dist = hypot(dif.y, dif.x);
        if(angle < 0.0) angle = 2.0 * PI + angle;
        if(dist <= wind.a && include(angle, wind.w - d, wind.w + d)) return true;
    }
    return false;
}

double toRadian(double d) {
    return d * PI / 180.0;
}

int main() {
    int H, R;
    while(cin >> H >> R, H | R) {
        vector<Point> home(H);
        for(auto &i: home) cin >> i.x >> i.y;

        int U, M, S;
        double du, dm, ds;
        cin >> U >> M >> S >> du >> dm >> ds;

        du = toRadian(du);
        dm = toRadian(dm);
        ds = toRadian(ds);

        vector<Point> plum(U), peach(M), cherry(S);
        for(auto &i: plum) cin >> i.x >> i.y;
        for(auto &i: peach) cin >> i.x >> i.y;
        for(auto &i: cherry) cin >> i.x >> i.y;

        vector<Wind> wind(R);
        for(auto &i: wind) cin >> i.w >> i.a;
        for(auto &i: wind) i.w = toRadian(i.w);

        // solve
        vector<int> number(H, 0);
        int maxNumber = 0;

        for(int i = 0; i < H; ++i) {
            for(int day = 0; day < R; ++day) {
                bool ok = savor(home[i], wind[day], {Point(0.0, 0.0)}, du);
                bool ng = false;
                ng |= savor(home[i], wind[day], plum, du);
                ng |= savor(home[i], wind[day], peach, dm);
                ng |= savor(home[i], wind[day], cherry, ds);

                if(!ok || ng) continue;

                ++number[i];
                maxNumber = max(maxNumber, number[i]);
            }
        }

        if(maxNumber) {
            bool first = true;
            for(int i = 0; i < H; ++i) if(number[i] == maxNumber) {
                if(!first) cout << " ";
                first = false;
                cout << i + 1;
            }
            cout << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) x * x

// 型エイリアス //
using lint = long long;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
int gcd(int a, int b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

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

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint comb(int n, int m) {
    return perm(n) / (perm(n - m) * perm(m));
}

// End of Template //



int main() {

    lint a, b, c;
    cin >> a >> b >> c;
    
    if (c - a - b < 0) {
        n();
    }
    else {
        if (x2((c - a - b)) > 4 * a * b) {
            y();
        }
        else {
            n();
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  
  cin >> s;
  
  if(s =="Sunny") cout << "Cloudy" << endl;
  if(s =="Cloudy") cout << "Rainy" << endl;
  if(s =="Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    private static int n;
    private static int q;
    private static int[] p;
    private static int[] rank;
 
    private static boolean same(int x, int y) {
        return findSet(x) == findSet(y);
    }
 
    private static void unite(int x, int y) {
        int i = findSet(x);
        int j = findSet(y);
 
        if (i == j) return;

        if (rank[i] > rank[j]){
            p[j] = p[i];
            rank[i] += rank[j];
            rank[j] = 0;
        }
        else {
            p[i] = p[j];
            rank[j] += rank[i];
            rank[i] = 0;
        }	
    }
 
    private static int findSet(int i) {
        while (i != p[i]){
            p[i] = p[p[i]];
            i = p[i];
        }
        return i;
    }
 
    private static void DisjointSet() {
        p = new int[n];
        rank = new int[n];
 
        for (int i = 0; i < n; i++) {
            p[i] = i;
            rank[i] = 1;
        }
    }
 
 
    public static void main (String[] args){
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        q = scanner.nextInt();
 
        DisjointSet();
        for (int i = 0; i < q; i++) {
            int com = scanner.nextInt();
            int x = scanner.nextInt();
            int y = scanner.nextInt();
 
            if (com == 0){
                unite(x, y);
            }
            if (com == 1){
                if (same(x, y)){
                    System.out.println(1);
                }else{
                    System.out.println(0);
		}
            }
        }
    }
}

Measured memory_bytes: 101180
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

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

    ll ans = N * (N-1) / 2;
    vector<ll> A(M), B(M);
    for(int i=0; i<M; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }

    UnionFind uni(N);

    vector<ll> vec(M-1);
    for(int i=0; i<M-1; i++){
        ll a = A[M-1-i], b = B[M-1-i];
        if(uni.root(a) == uni.root(b)) vec[i] = ans;
        else{
            ans -= uni.size(a) * uni.size(b);
            uni.connect(a, b);
            vec[i] = ans;
        }
        
    }

    for(int i=0; i<M-1; i++) cout << vec[M-2-i] << endl;
    cout << N*(N-1)/2 << endl;


}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define PI 3.14159265359
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;
    cin >> n;

    vector<pair<int,pair<int,int>>> tf;
    FOR(i,0,n-1){
      int a; cin >> a;
      FOR(j,0,a-1){
        int b,c;
        cin >> b >> c;
        tf.PB(MP(i+1,MP(b,c)));
      }
    }

    int output = 0;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<n); ++bit) {
        map<int,int> m;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { // i が bit に入るかどうか
                ++m[i];
            }
        }

        vector<int> assign(n+1,-1);
        
        FOR(i,0,n-1){
            for(auto x : tf){
              if(x.first!=i+1) continue;
              
              if(m[i]){
                if(assign[x.second.first-1]==-1 || assign[x.second.first-1]==x.second.second){
                  assign[x.second.first-1] = x.second.second;
                }
                else{
                  assign[n] = 9;
                }
              }
            }
        }

        bool allcheck = true;

        FOR(i,0,n-1){
          if(assign[i]==-1) continue;

          if(assign[i]!=m[i]) allcheck = false;
        }

        int ans = 0;

        if(allcheck && assign[n]!=9){
          FOR(i,0,n-1){
            if(m[i]!=0) ++ans;
          }
        }

          // FOR(i,0,n-1){
          //   cout << assign[i] << "";
          // }
          // cout << endl;
          // FOR(i,0,n-1){
          //   cout << m[i] << "";
          // }
          // cout << endl;

          // cout << "---" << endl;

        chmax(output,ans);
    }

    cout << output << endl;


}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int A,B,C,D,k;
bool pd(int x){
	if(x==0) return 1;
	if(x%(k+1)==0) x--;
	int cntB=x/(k+1),cntA=x-cntB;
	if((A-cntA+1)*(long long)k>=B-cntB)
		return 1;
	return 0;
}
int main(){
//	freopen("D.in","r",stdin);
	int T;
	scanf("%d",&T);
	while(T--){
		scanf("%d%d%d%d",&A,&B,&C,&D);
		if(A>B) k=(A-1)/(B+1)+1;
		else k=(B-1)/(A+1)+1;
		int l=0,r=A+B,mid;
		while(r-l>1){
			mid=(l+r)>>1;
			if(pd(mid)) l=mid;
			else r=mid;
		}
		if(pd(r)) l=r;
		for(int i=C;i<=D;i++){
			if(i<=l){
				if(i%(k+1)==0) printf("B");
				else printf("A");
			}
			else{
				if((A+B+1-i)%(k+1)==0) printf("A");
				else printf("B");
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 384
import unittest
import math


class TestD(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(2), 3)

    def test_2(self):
        self.assertEqual(think(4), 7)

    def test_3(self):
        self.assertEqual(think(1000000000000), 1099511627775)


def solve():
    h = read()
    result = think(h)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(h):
    rank = math.floor(math.log(h) / math.log(2)) + 1
    return 2 ** rank - 1


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51056
#include <stdio.h>

int main()
{
	int c[3][3], i, j;
	char *ans;

	for(i=0; i<3; i++){
		for(j=0; j<3; j++){
			scanf("%d", &c[i][j]);
		}
	}

	if(c[0][0]+c[1][1]==c[0][1]+c[1][0] && c[0][1]+c[1][2]==c[0][2]+c[1][1] && c[1][0]+c[2][1]==c[1][1]+c[2][0] && c[1][1]+c[2][2]==c[1][2]+c[2][1]){
		ans="Yes";
	}else{
		ans="No";
	}
	printf("%s\n", ans);

	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int S = sc.nextInt();
        int count = 0;
        for(int x = 0; x <= K; x++){
            for(int y = 0; y <= K; y++){
                int total = x + y;
                if(!(total > S) && (total + K) >= S){
                    count++;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 35352
import itertools

def combination(d):
    dd = [i for i in range(d)]
    return [itertools.combinations(dd, i) for i in range(d + 1)]

def all_green(d, g, ps, cs):
    # tood use int max value or other constant value
    min_count = 1000000
    for cc in combination(d):
        for c in cc:
            v = 0
            count = 0
            for ccc in c:
                v += cs[ccc]
                v += (ccc + 1) * 100 * ps[ccc]
                count += ps[ccc]
            if v >= g:
                if count < min_count:
                    min_count = count
                continue
            if count >= min_count:
                continue

            dd = [i if i not in c else None for i in range(d)]
            dd = list(filter(lambda x: x is not None, dd))
            for vvv in reversed(dd):
                for _ in range(ps[vvv]):
                    v += 100 * (vvv + 1)
                    count += 1
                    if v >= g:
                        if count < min_count:
                            min_count = count
                        break
                if count >= min_count:
                    break
    return min_count

d, g = map(int, input().split())
ps = []
cs = []
for _ in range(d):
    p, c = map(int, input().split())
    ps += [p]
    cs += [c]
print(all_green(d, g, ps, cs))


Measured memory_bytes: 3188
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cctype>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#include<sstream>
#include<vector>
#include<cstdlib>
#include<ctime>
#include<list>
#include<deque>
#include<bitset>
#include<fstream>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
#define int ll
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=2e5+5;
int inf=2e18;
int n,dp[N][5];
//
inline void up(int &x,int y){
    if(y>x)x=y;
}
int min(int x,int y,int z){
    return min(x,min(y,z));
}
signed main(){
    n=getint();
    rep(i,5)dp[0][i]=inf;
    dp[0][0]=0;
    for(int i=1;i<=n;i++){
        int x=getint();
        dp[i][0]=dp[i-1][0]+x;
        dp[i][1]=min(dp[i-1][0],dp[i-1][1])+(x%2==1);
        dp[i][2]=min(dp[i-1][0],dp[i-1][1],dp[i-1][2])+(x%2==0);
        dp[i][3]=min(dp[i-1][2],dp[i-1][3])+(x%2==1);
        if(!x)dp[i][1]+=2,dp[i][3]+=2;
        for(int j=1;j<=3;j++)if(dp[i][j]>inf)dp[i][j]=inf;
        dp[i][4]=min(dp[i-1][1],dp[i-1][4],min(dp[i-1][2],dp[i-1][3]))+x;
    }
    int res=inf;
    rep(i,5)res=min(res,dp[n][i]);
    printf("%lld\n",res);
   	return 0;
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#define maxn 200005
#define Mod 1000000007
#define ll long long
#define Mod 1000000007
using namespace std;
inline int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;
}
int n,a[maxn],f[maxn],ans;
int main(){
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();ans=1;
	for(int i=1;i<=n;i++)if(a[i]!=a[i-1])ans=f[a[i]]=(ans+f[a[i]])%Mod;
	printf("%d\n",ans); 
}

Measured memory_bytes: 1792