akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
using namespace std;

int main()
{
    int n,q,i;
    string s;
    cin >> n >> q >> s;
    vector<int> list;
    for(i = 0;i < n-1;++i){
        if(s.at(i) == 'A' && s.at(i+1) == 'C'){
            list.push_back(i+1);
        }
    }
    int l,r,low,high;
    for(i = 0;i < q;++i){
        cin >> l >> r;
        if(list.size() == 0){
            cout << 0 << endl;
        }else{
            low =  lower_bound(list.begin(),list.end(),l)-list.begin();
            high = lower_bound(list.begin(),list.end(),r-1)-list.begin();
            if(high == list.size()){
                --high;
            }
            if(list.at(high) <= r-1){
                ++high;
            }
            cout << high-low << endl;
        }
        
    }
    return 0;
}

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

int main(){
  int a,b;cin>>a>>b;
  int S=0,T=0;
  string X,Y;
  for(int i=0;i<b;i++) S+=a*pow(10,i);
  for(int j=0;j<a;j++) T+=b*pow(10,j);
  X=to_string(S);Y=to_string(T);
  if(X<=Y) cout<<X<<endl;
  else cout<<Y<<endl;
}

Measured memory_bytes: 4068
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int dp[100010];

int main(){
  string s,t; cin >> s >> t;
  int sl=s.size();
  map<char,set<int> > mp;
  rep(i,sl){
    mp[s[i]].insert(i+1);
    mp[s[i]].insert(sl+1);
  }
  int tl=t.size();
  if(mp[t[0]].size()==0){
    cout << -1 << endl;
    return 0;
  }
  dp[0]=*begin(mp[t[0]]);
  rep(i,tl-1){
    if(mp[t[i+1]].size()==0){
      cout << -1 << endl;
      return 0;
    }
    dp[i+1]=*mp[t[i+1]].upper_bound(dp[i]);
    if(dp[i+1]==sl+1) dp[i+1]=*begin(mp[t[i+1]]);
  }
  ll cnt=0;
  rep(i,tl-1){
    if(dp[i]>=dp[i+1]) cnt++;
  }
  ll ans=sl*cnt+dp[tl-1];
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;

static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;

#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, d[10000001];

int main(int argc, char **argv) {
	CLEAR(d);
	cin >> n;
	ll res = 1;
	FOR(i, 2, n+1) {
		res += i * (d[i] + 2);
		for (ll j = i*2; j <= n; j += i) ++d[j];
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 81760
#include <iostream>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <vector>
#include <queue>

using namespace std;

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

  string ans = "No";
  for (int i = 0; i < s.length() - 1; i++)  {
    if (s[i] == 'A' && s[i+1] == 'B') ans = "Yes";
    if (s[i] == 'B' && s[i+1] == 'A') ans = "Yes";
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
4
3 4 3 2

      23
    345
  4567
678

*/
int main(){
  ll K; cin>>K;
  vector<ll> A(K,0),DP1(K,-1),DP2(K,-1);
  for(ll i=0; i<K; i++) cin>>A[i];
  if(A[K-1]>2){
    cout<<-1<<endl;
    return 0;
  }
  DP1[K-1]=2;
  DP2[K-1]=3;  
  //DP1
  for(ll i=K-2; i>=0; i--){
    ll n=DP1[i+1]/A[i];
    if(DP1[i+1]%A[i]>0) n++;
    DP1[i]=n*A[i];
  }
  //DP2
  for(ll i=K-2; i>=0; i--){
    ll n=DP2[i+1]/A[i];
    DP2[i]=(n+1)*A[i]-1;
  }
//for(ll i=0; i<K; i++)cout<<DP2[i]<<" ";  
  if(DP1[0]>DP2[0]){
    cout<<-1<<endl;
    return 0;
  }
  cout<<DP1[0]<<" "<<DP2[0]<<endl;
}

Measured memory_bytes: 2560
# ???????????¢??¶?????????
end_panels = []
3.times do |i|
  end_panels << STDIN.gets.chomp.split(' ').map(&:to_i)
end
end_panels.flatten!

start_panels = [1, 2, 3, 4, 5, 6, 7, 8, 0]
width = 3
height = 3
$queue = [[true, []], [false, []]]
forward_cache = {}
backward_cache = {}

def add_queue(is_forward, dicts, dict)
  dicts2 = dicts.dup
  dicts2 << dict
  $queue << [is_forward, dicts2]
end

while true do
  # ?§????
  q = $queue.shift
  is_forward, dicts = q[0], q[1]
  if is_forward
    panels = start_panels.dup
  else
    panels = end_panels.dup
  end
  z = panels.index(0)
  dicts.each do |d|
    case d
    when :u then panels[z], panels[z-3] = panels[z-3], panels[z]
    when :d then panels[z], panels[z+3] = panels[z+3], panels[z]
    when :l then panels[z], panels[z-1] = panels[z-1], panels[z]
    when :r then panels[z], panels[z+1] = panels[z+1], panels[z]
    end
    z = panels.index(0)
  end
#pp dicts
  # ??????????????????
  if is_forward && backward_cache.key?(panels)
    puts dicts.size + backward_cache[panels].size
    break
  elsif !is_forward && forward_cache.key?(panels)
    puts dicts.size + forward_cache[panels].size
    break
  end
  if is_forward
    if !forward_cache.key?(panels) || forward_cache[panels].size > dicts.size
      forward_cache[panels] = dicts
    end
  else
    if !backward_cache.key?(panels) || backward_cache[panels].size > dicts.size
      backward_cache[panels] = dicts
    end
  end

  # ?¬??????¢?´¢?????????
  if z / width != 0 \
     && dicts[-1] != :d
     # && dicts[-3, 3] != [:l, :d, :r] \
     # && dicts[-3, 3] != [:r, :d, :l]
    add_queue(is_forward, dicts, :u)
  end
  if z / width != height - 1 \
     && dicts[-1] != :u
     # && dicts[-3, 3] != [:l, :u, :r] \
     # && dicts[-3, 3] != [:r, :u, :l]
    add_queue(is_forward, dicts, :d)
  end
  if z % width != 0 \
     && dicts[-1] != :r
     # && dicts[-3, 3] != [:u, :r, :d] \
     # && dicts[-3, 3] != [:d, :r, :u]
    add_queue(is_forward, dicts, :l)
  end
  if z % width != width - 1 \
     && dicts[-1] != :l
     # && dicts[-3, 3] != [:u, :l, :d] \
     # && dicts[-3, 3] != [:d, :l, :u]
    add_queue(is_forward, dicts, :r)
  end
end

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
pint A[111111];
int ans=0;

void solve(int l,int r){
    ans++;
    for(int i=l;i<r;i++){
        A[i].fi/=2;
        A[i].se=(A[i].se+1)/2;
    }

    int cur=l;
    vpint lis;
    while(cur<r){
        if(A[cur].se==1){
            cur++;
            continue;
        }
        if(A[cur].fi==1){
            if(cur>l&&A[cur-1].fi>1){
                cur++;
                continue;
            }
            if(cur+1<r&&A[cur+1].fi>1){
                cur++;
                continue;
            }
            if(cur+1<r&&A[cur+1].se==2){
                ans++;
                cur+=2;
                continue;
            }
            ans++;
            cur++;
            continue;
        }
        int nex=cur;
        while(nex<r&&A[nex].fi>1)nex++;
        lis.pb({cur,nex});
        cur=nex;
    }

    rep(i,lis.size())solve(lis[i].fi,lis[i].se);
}

signed main(){
    cin>>N;
    rep(i,N){
        int a;cin>>a;
        A[i]={a,a};
    }

    int cur=0;
    vpint lis;
    while(cur<N){
        if(A[cur].fi==1){
            cur++;
            continue;
        }
        int nex=cur;
        while(nex<N&&A[nex].fi!=1)nex++;
        solve(cur,nex);
        cur=nex;
    }

    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
def resolve():
  n = int(input())
  ans = 1
  num = 0
  for i in range(1, n+1):
    tmp = 0
    x = i
    while x >= 2 and x % 2 == 0:
      if x % 2 == 0:
        tmp += 1
        x /= 2
        if tmp >= num:
          ans = i
          num = tmp
      else:
        continue

  print(ans)
  return

if __name__ == "__main__":
  resolve()


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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define pi pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
#define vl vector<ll>
#define vii vector<pair<int,int> >
#define vll vector<pair<long long,long long> >
#define pb push_back
#define mp make_pair3

const ll mod=1e9+7;
#define MAX 100000

int modulo = 420047;

ll binexpo(ll a,ll b,ll c){

    if(b==0) return 1;
    else if(b%2==0) return binexpo(((a%c)*(a%c))%c,b/2,c)%c;
    else return ((a%c)*(binexpo(((a%c)*(a%c))%c,b/2,c)%c))%c;
}

int main(){

    int n,w;
    cin>>n>>w;

    ll dp[n+1][w+1];
    memset(dp,0,sizeof(dp));

    ll wt[n],val[n];
    FOR(i,0,n) cin>>wt[i]>>val[i];

    FOR(i,1,n+1){
        FOR(j,1,w+1){
            dp[i][j] = dp[i-1][j];
            if(wt[i-1]<=j) dp[i][j] = max(dp[i][j],dp[i-1][j-wt[i-1]] + val[i-1]);
        }
    }

    cout<<dp[n][w];

    return 0;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 1e5+7;

ll N, A, B;
ll X[MAX_N];

void input() {
	cin >> N >> A >> B;
	for(int i=0;i<N;i++) {
		cin >> X[i];
	}
}

void solve() {
	ll ans = 0;
	for(int i=1;i<N;i++) {
		ll cost;
		if((X[i]-X[i-1])*A < B) cost = (X[i]-X[i-1])*A;
		else cost = B;
		ans += cost;
	}
	cout << ans << endl;
}

int main() {
	input();
	solve();
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

long long power(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a ;
        a = a * a ;
        b >>= 1;
    }
    return res;
}


signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   

#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif  

    string s,t;
    cin>>s>>t;
    int n=s.length();
    int x=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
            x++;
    }
    cout<<x;

} 
    


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

int main(){
  long long n,a[200010];
  cin>>n;
  for(int i=0;i<n;++i)cin>>a[i];
  for(int i=1;i<n;++i)a[i]+=a[i-1];

  long long ans=2e9;
  for(int i=0;i<n-1;++i){
    ans=min(ans,abs(a[i]*2-a[n-1]));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,d,a;cin >> n >> d >> a;
  vector<pair<ll,ll>> p(n);
  for(int i=0;i<n;i++){
    ll x,h;cin >> x >> h;
    p[i]={x,(h+a-1)/a};
  }
  sort(p.begin(),p.end());
  vector<ll> x(n),y(n),c(n+1);
  for(int i=0;i<n;i++){
    x[i]=p[i].first;
    y[i]=p[i].second;
  }
  ll sum=0,ans=0;
  for(int i=0;i<n;i++){
    int itr=upper_bound(x.begin(),x.end(),x[i]+2*d)-x.begin();
    sum+=c[i];
    ll r=max(0LL,y[i]-sum);
    ans+=r;
    c[i+1]+=r;
    c[itr]-=r;
  }
  cout << ans << endl;
}

Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
int len;
char s[100005],s1[100005];
bool ok=1;
int main()
{
    cin>>s;
    len=strlen(s);
    for(register int i=0;i<len;i++)
    {
        s1[i]=s[len-i-1];
        if(s1[i]=='b')
        	s1[i]='d';
        else if(s1[i]=='d')
        	s1[i]='b';
        else if(s1[i]=='p')
        	s1[i]='q';
        else
        	s1[i]='p';
    }
    for(register int i=0;i<len;i++)
    {
    	if(s[i]!=s1[i])
    	{
    		ok=0;
    		break;
        }
    }
    if(ok)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
ans = 'DENIED'
 
for i in range(n):
  if a[i]%2 == 1:
    continue
  else:
    if a[i]%3==0 or a[i]%5==0:
      continue
    else:
      break
else:
  ans = 'APPROVED'
 
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 2);
    a[0] = inf;
    rep3(i, 1, n + 1) cin >> a[i];
    a[n + 1] = -inf;
    
    a.erase(unique(all(a)), a.end());
    // cerr << a << endl;
    
    vector<int> v;
    int key = 0;
    rep3(i, 1, sz(a) - 1) {
        if (key == 0) {
            if (a[i - 1] > a[i] && a[i] < a[i + 1]) {
                key ^= 1;
                v.eb(a[i]);
            }
        } else {
            if (a[i - 1] < a[i] && a[i] > a[i + 1]) {
                key ^= 1;
                v.eb(a[i]);
            }
        }
    }
    // cerr << v << endl;
    if (sz(v) % 2) v.pop_back();
    
    ll x = 1000, y = 0;
    rep(i, sz(v)) {
        if (i % 2 == 0) {
            y += x / v[i];
            x -= x / v[i] * v[i];
        } else {
            x += y * v[i];
            y = 0;
        }
    }
    cout << x << endl;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORd(i, a, b) for (int i = (a) - 1; i >= (b); --i)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int FFTMOD = 119 << 23 | 1;
const int INF = (int) 1e9 + 23111992;
const ll LINF = (ll) 1e18 + 23111992;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
template<class T> inline int chkmin(T& a, const T& val) {return val < a ? a = val, 1 : 0;}
template<class T> inline int chkmax(T& a, const T& val) {return a < val ? a = val, 1 : 0;}
inline ull isqrt(ull k) {ull r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int sign(ld x) {return x < -EPS ? -1 : x > +EPS;}
inline int sign(ld x, ld y) {return sign(x - y);}
mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int mrand() {return abs((int) mt());}
#define db(x) cerr << "[" << #x << ": " << (x) << "] ";
#define endln cerr << "\n";

void chemthan() {
    string s; cin >> s;
    if (sz(s) & 1) {
        cout << "No\n";
        return;
    }
    string t = "hi";
    FOR(i, 0, sz(s)) {
        if (s[i] != t[i & 1]) {
            cout << "No\n";
            return;
        }
    }
    cout << "Yes\n";
}

int main(int argc, char* argv[]) {
    ios_base::sync_with_stdio(0), cin.tie(0);
    if (argc > 1) {
        assert(freopen(argv[1], "r", stdin));
    }
    if (argc > 2) {
        assert(freopen(argv[2], "wb", stdout));
    }
    chemthan();
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
/*

*/
int main()
{
    int N,M;
    int a[10000];
    int sum=0;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> a[i];
    }
    //ぜんぶの合計がNより小さければいいんでしょう
    for (int i = 0; i < M; i++){
        sum += a[i];
    }   
    if(sum > N){
        cout << -1 << endl;
    }else{
        cout << N-sum << endl;
    }
        return 0;
    }

Measured memory_bytes: 3184
import math
import collections
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n = int(input())
    maxv = n*(n-1)//2
    a = [list(map(int, input().split())) for i in range(n)]
    for i in range(n):
        for j in range(n-1):
            a[i][j] -= 1

    # 試合を頂点とする(ex 1-2,2-4 : i < j)
    v = 0  # 頂点数
    # 頂点にIDをふる
    Id = [[-1 for i in range(n)] for j in range(n)]
    for i in range(n):
        for j in range(n):
            if i < j:  # 3-1はダメ
                Id[i][j] = v
                Id[j][i] = v
                v += 1


    e = [[] for i in range(maxv)]
    for i in range(n):
        for j in range(n - 1):
            # a[i][j]にIDを代入する Id[1][3]=1 => a[1][3] = a[3][1] = 1
            # x = i
            # y = a[i][j]
            # if x > y:
            #     x, y = y, x
            # a[i][j] = Id[x][y]  # toId(i, a[i][j])
            a[i][j] = Id[i][a[i][j]]
        for j in range(n - 2):
            e[a[i][j + 1]].append(a[i][j])


    calculated = [False for i in range(maxv)]
    dp = [-1 for i in range(maxv)]

    def dfs(v):
        if dp[v] != -1:  # サイクル検知
            if not calculated[v]:
                return -1
            return dp[v]
        dp[v] = 1
        for u in e[v]:
            ret = dfs(u)
            if ret == -1:
                return -1
            dp[v] = max(dp[v], ret + 1)
        calculated[v] = True
        return dp[v]

    ans = 0
    for i in range(v):
        ret = dfs(i)
        if ret == -1:  # detected cycle
            print(-1)
            exit()
        ans = max(ans, ret)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 221240
S=input()
mae=S[:2]
ato=S[2:]
mon_list=("01","02","03","04","05","06","07","08","09","10","11","12")
test=0
if mae in mon_list:
  test=test+1
if ato in mon_list:
  test=test+3

if test==0:
  print("NA")
if test==1:
  print("MMYY")
if test==3:
  print("YYMM")
if test==4:
  print("AMBIGUOUS")

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

int main() {
  int n;
  cin >> n;
  vector<int> yakusu(201, 0);
  for (int i = 1; i <= 200; i++) {
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) yakusu[i]++;
    }
  }

  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    if (yakusu[i] == 8) ans++;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  int n, m, a;
  cin >> n >> m;
  for (int i=0; i<m; i++) {
    cin >> a;
    n -= a;
  }
  if (n>=0) cout << n << endl;
  else cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int main() {
	char ch[250] = { 0 };
	char a[250] = { 0 };
	int h;
	int i, j, k, l, n, m;

	while (1) {
		i = 0;
		while (1) {
			scanf("%c", &ch[i]);
			if (ch[i] == '\n') {
				break;
			}
			i++;
		}
		if (i == 1 && ch[0] == '-') break;

		scanf("%d", &m);

		for (j = 0; j<m; j++) {
			scanf("%d", &h);
			for (k = 0; k<i - h; k++) {
				a[k] = ch[h + k];
			}
			for (k = 0; k<h; k++) {
				a[i - h + k] = ch[k];
			}
			for (k = 0; k<i; k++) {
				ch[k] = a[k];
			}
		}
		for (k = 0; k<i; k++) {
			printf("%c", ch[k]);
		}
		printf("\n");
		scanf("%c", &ch[0]);
	}

	return 0;
}


Measured memory_bytes: 2068
let ( +^ ) x y = (x + y) mod 1000000007

let denote_amida amida k =
  if 0 < amida land (1 lsl k) then k + 1
  else if 0 <= k && 0 < amida land (1 lsl (k - 1)) then k - 1
  else k

let () = Scanf.scanf "%d %d %d" @@ fun h w k ->
  let valid_amidas =
    List.filter (fun amida -> amida land (amida lsl 1) = 0) @@
    Array.to_list @@
    Array.init (1 lsl (w - 1)) @@ fun admida -> admida in
  let dp = Array.make_matrix (h + 1) w 0 in
  dp.(0).(0) <- 1;
  for i = 1 to h do
    for j = 0 to w - 1 do
      List.iter (fun amida ->
        dp.(i).(denote_amida amida j) <- dp.(i - 1).(j) +^ dp.(i).(denote_amida amida j)) valid_amidas
    done
  done;
  Printf.printf "%d\n" dp.(h).(k - 1)

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

using namespace std;

using ll = long long;

int main(void) {
    ll n, ans = 0;
    cin >> n;

	unordered_map<string, ll> m;
	for (int i = 0; i < n; i++) {
        string s;
		cin >> s;
		sort(s.begin(), s.end());
        
		m[s]++;
		
	}

	for(auto x:m) {
        ans += x.second * (x.second - 1) / 2;
    }

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10660
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

count = 0
b = [0] * 200000

for a in A:
    b[a] += 1

b.sort()

for i in range(len(b)):
    if b[i] == 0:
        count += 1

del b[:count]

ans = 0
kind = len(b)
for i in range(len(b)):
    if K < kind:
        ans += b[i]
        kind -= 1
    else:
        print(ans)
        break

Measured memory_bytes: 25748
#include <bits/stdc++.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#define int long long
using namespace std;

#define fin(i,n) for (int i = 0; i < n; i++)
#define fin2(i,a,b) for (int i = a; i < b; i++)
#define ford(i,n) for (int i = n-1; i >= 0; i--)
#define ford2(i,a,b) for (int i = a-1; i >= b; i--)
 
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define mod 1000000007
#define PI 3.1415926535897932384626
#define EXP1 2.718281828459045
#define BIG 1000000000000000000

#define sl(n) scanf("%lld", &n)
#define sll(n,m) scanf("%lld %lld", &n, &m)
#define slll(n,m,k) scanf("%lld %lld %lld", &n, &m, &k)
#define sllll(n,m,k,o) scanf("%lld %lld %lld %lld", &n, &m, &k, &o)
#define sd(n) scanf("%lf", &n)
#define sdd(n,m) scanf("%lf %lf", &n, &m)
#define sddd(n,m,k) scanf("%lf %lf %lf", &n, &m, &k)
#define sc(c) scanf(" %c", &c)
#define ss(s) scanf("%s", s)
#define sal(t,n) fin(iz,n) { scanf("%lld", &t[iz]); }
#define sad(t,n) fin(iz,n) { scanf("%lf", &t[iz]); }
#define gl(t) scanf(" %[^\n]", t);

#define pc(n) printf("%c\n", n)
#define ps(s) printf("%s\n", s)
#define pss(s) printf("%s\n", s.c_str())
#define pl(n) printf("%lld\n", n)
#define pll(n,m) printf("%lld %lld\n", n, m)
#define plll(n,m,k) printf("%lld %lld %lld\n", n, m, k)
#define pd(n) printf("%lf\n", n)
#define pdd(n,m) printf("%lf %lf\n", n, m)
#define pal(t,n) fin(rz,n) { printf("%lld ", t[rz]); } printf("\n")
#define pad(t,n) fin(rz,n) { printf("%lf ", t[rz]); } printf("\n")

#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
 
#define OK ps("OK")
#define OK1 ps("OK1")
#define OK2 ps("OK2")

#define ll int
#define vl vector<ll>
#define vvl vector<vl>
#define vvvl vector<vvl>

#define dll pair<ll, ll>
#define vdll vector<dll>
#define vvdll vector<vdll>

#define vb vector<bool>
#define vvb vector<vb>
#define vd vector<double>
#define vvd vector<vd>
#define vc vector<char>
#define vvc vector<vc>

#define all(v) v.begin(), v.end()
#define vlen(v) (int)(v.size())
#define pb push_back
#define fi first
#define se second

const int b1 = 52;
const int b2 = 61;
int dp[b2][b1][b1];
int ss[b2][b1];
int n, nbc;

signed main()
{
    sll(n, nbc);
    fin(i, n) fin(j, n) {
        sl(dp[0][i][j]);
    }
    if (n%1) {
        fin(i, n) fin(j, n) {
            ss[0][i] += dp[0][i][j];
            ss[0][i] %= mod;
        }
    }
    else fin(i, n) fin(j, n) ss[0][i] = 1;

    fin2(e, 1, b2) fin(i, n) {
        bool con = (nbc & (1LL << (e-1))) > 0;
        fin(j, n) fin(k, n) {
            dp[e][i][j] += dp[e-1][i][k] * dp[e-1][k][j];
            dp[e][i][j] %= mod;
            if (con && k == 0) {
                ss[e][i] += dp[e-1][i][j] * ss[e-1][j];
                ss[e][i] %= mod;
            }
        }
        if (! con) { ss[e][i] = ss[e-1][i]; }
    }
    int ans = 0;
    fin(i, n) ans = (ans + ss[b2-1][i]) % mod;
    pl(ans);
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
const int maxn = 200200;
int dp[maxn],a[maxn],b[maxn];
void solve()
{
    int h,n;
    cin >> h >> n;
    memset(dp,200200,maxn);
    dp[0] = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        for (int j = 0; j < h; j++){
            dp[min(j + a[i],h)] = min(dp[min(j + a[i],h)], dp[j] + b[i]);
        }
    }
    cout << dp[h] << endl;
}

// 7 3 3 1 1

int main()
{
    int t;
    solve();
    return (0);
}





Measured memory_bytes: 512
# coding: utf-8
# Your code here!
S=input()
L=len(S)+1

ascii_lowercase=[chr(i) for i in range(97,97+26)]
#print(ascii_lowercase)

flag=0

S=S+'A'
for i in range(L):
    for letter in ascii_lowercase:
  #      print(S[:L-i-1],S[L-i-1],letter)
        if (letter not in S[:L-i-1]) and letter > S[L-i-1]:
            flag = 1
            answer = S[:L-i-1]+letter
            break
    if flag==1:
        break

if flag==1:
    print(answer)
else:
    print('-1')





Measured memory_bytes: 3060
use std::io;
fn main() {
    let mut s = String::new();
    io::stdin().read_line(&mut s)
        .expect("Failed to read line");
    let v: Vec<&str> = s.split(' ').collect();
    let (a, b) = (v[0], v[1]);
    let a: i32 = a.trim().parse().expect("cannot parse");
    let b: i32 = b.trim().parse().expect("cannot parse");
    println!("{} {}", a * b, 2 * (a + b));
}



Measured memory_bytes: 5024
n, u, v = map(int, input().split())
u, v = u-1, v-1
edges = [[] for i in range(n)]
for i in range(n-1):
    ai, bi = map(int, input().split())
    ai, bi = ai-1, bi-1
    edges[ai].append(bi)
    edges[bi].append(ai)

depth = 0
already = [0 for i in range(n)]
already[v] = 1
nodes = [v]
while nodes != []:
    depth += 1
    next_nodes = []
    for node in nodes:
        children = edges[node]
        for child in children:
            if already[child] == 0:
                already[child] = depth
                next_nodes.append(child)
    nodes = next_nodes
already[v] = 0

depth = 0
already_u = [0 for i in range(n)]
already_u[u] = 1
nodes = [u]
while nodes != []:
    depth += 1
    next_nodes = []
    for node in nodes:
        children = edges[node]
        for child in children:
            if already_u[child] == 0:
                already_u[child] = depth
                next_nodes.append(child)
    nodes = next_nodes
already_u[u] = 0

maxi = 0
for i in range(n):
    if already_u[i] < already[i]:
        maxi = max(maxi, already[i])

print(maxi-1)

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

int n;
main(){
	int y,m,d,sum,n,k;
	int pre = 196470;
	cin >> n;
	while(n--){
		sum = 0;
		cin >> y >> m >> d;
		sum += ((y-1) * 200) - ((y-1)-(y-1)/3)*5;
		sum += 20 * (m-1);
		if(y % 3) sum -= ((m-1)/2);
		sum += d;
		cout << pre - sum + 1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
n = gets.to_i
flowers = gets.split.map(&:to_i)
ans = 0
until flowers.max == 0
  ans += 1
  from = flowers.find_index { |n| n > 0 }
  to = flowers.find_index.with_index { |n, i| n == 0 && i > from } || n
  (from...to).each do |i|
    flowers[i] -= 1
  end
end
puts ans


Measured memory_bytes: 1788
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <numeric>
#include <type_traits>
#include <limits>
#include <random>
#include <iomanip>

using namespace std;

using ll = long long;

typedef pair<int, int> P;

#define rep(i,N) for(long long i = 0;i < (long long)N; ++i)

static int mod = 1000000007;
static int large = 1000000000;

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

int N, W;
ll v[101], w[101];

ll dp[101][100001];


//i番目までの品物でj以下の重さの価値の最大値
ll  f(ll i, ll j) {
	if (i == -1) return 0;
	if (dp[i][j] != -1) return dp[i][j];
	ll sec = 0;
	if (j < w[i]) {
		sec = f(i - 1, j);
	}
	else {
		sec = max(f(i - 1, j), f(i - 1, j - w[i]) + v[i]);
	}
	return dp[i][j] = sec;
}

int main() {
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	rep(i, 101) {
		rep(j, 100001) {
			dp[i][j] = -1;
		}
	}
	cout << f(N - 1, W) << endl;
	return 0;
}



Measured memory_bytes: 79104
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int A = scan.nextInt();
        int B = scan.nextInt();
        if (B < A) {
            int T = A;
            A = B;
            B = T;
        }
        if ((B-A) % 2 == 1) {
            System.out.println("IMPOSSIBLE");
        } else {
            System.out.println(A + (B-A)/2);
        }
    }
}


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

int main() {
    size_t constexpr x = 100;
    size_t D, N;
    cin >> D >> N;
    size_t ans = N;


    if (0 == D) {
        cout << ((N < x) ? N : (x + 1)) << endl;
        return 0;
    } 
    

    size_t min = 1;
    for (size_t i = 1; i <= D; i++) {
        min *= x;   
    }

    cout << min *   ((N < x) ? N : (x + 1))  << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	S := next()
	T := next()
	ans := 0
	for i := 0; i < 3; i++ {
		if S[i] == T[i] {
			ans++
		}
	}
	fmt.Fprintln(out, ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
{-# LANGUAGE ScopedTypeVariables #-}

import Data.Array
import Data.List
import Control.Monad

solve arr h w
    | null res = "Yes"
    | otherwise = "No"
    where
        res = [() | i <- [1..h], j <- [1..w], step arr i j]
        step arr i j = curr && ns
            where
                curr = arr ! (i,j) == '#'
                ns = null $ (filter (\p -> arr ! p == '#') $ filter (\(a,b) -> a > 0 && a <= h && b > 0 && b <= w) [(i+1,j),(i-1,j),(i,j+1),(i,j-1)])


main = do
    [h, w] <- map read . words <$> getLine :: IO [Int]
    str <- concat <$> replicateM h getLine :: IO String
    let (grid :: Array (Int,Int) Char) = listArray ((1,1),(h,w)) str
    putStrLn $ solve grid h w

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
int n, a[234567][25], b[25], p = 0; bool bl = 1;
signed main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; k; j++){
			a[i][j] = k % 2;
			k /= 2;
			p = max(p, j);
		}
	}
	int r = 0, l = 0, ans = 1;
	for (int i = 0; i <= 20; i++)b[i] = a[0][i];
	while (1) {
		l++; if (l >= n)break;
		for (int i = 0; i <= p; i++) {
			b[i] += a[l][i];
			if (b[i] > 1)bl = 0;
		}
		while (!bl) {
			bool b00l = 1;
			for (int i = 0; i <= p; i++) {
				b[i] -= a[r][i];
				if (b[i] > 1)b00l = 0;
			}
			r++;
			bl = b00l;
		}
		ans += l - r + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 41216
#include <stdio.h>
int main()
{ 
	long long n;
	scanf("%lld", &n);
	for(long long i=-1003; i<=1003; i++)
		for(long long j=-1003; j<=1003; j++)
			if(i * i * i * i * i - j * j * j * j * j == n)
			{
				printf("%lld %lld", i, j);
				return 0;
			}
    return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

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

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

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {

	ll sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	ll x = tx-sx;
	ll y = ty - sy;

	rep(i, x)cout << 'R';
	rep(i, y)cout << 'U';
	rep(i, x)cout << 'L';
	rep(i, y)cout << 'D';
	cout << 'D';
	rep(i, x + 1)cout << 'R';
	rep(i, y + 1)cout << 'U';
	cout << 'L';
	cout << 'U';
	rep(i, x + 1)cout << 'L';
	rep(i, y + 1)cout << 'D';
	cout << 'R';
	

	system("PAUSE");
}


Measured memory_bytes: 504
from sys import stdin
def f(n):
    if n%4==0:
        return n
    elif n%4==2:
        return 1^n
    elif n%4==1:
        return 1
    else:
        return 0

def main():
    #入力
    readline=stdin.readline
    A,B=map(int,readline().split())
    if A==0 and B==0:
        print(0)
    elif A==0:
        print(f(B))
    else:
        print(f(B)^f(A-1))

if __name__=="__main__":
    main()

Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    long X = sc.nextLong();
    long answer = 0;
    
    for(long i=X;i<100000000;i++){
      int count = 0;
      for(long j=2;j*j<=i;j++){
        if(i%j==0){
          count++;
          break;
        }
      }
      if(count==0){
        answer = i;
        break;
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;
int a[52][30];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n;
	cin>>n;
	REP(i,n){
		string s;
		cin>>s;
		REP(j,s.size()){
			a[i][s[j] - 'a']++;
		}
	}
	REP(alp,29){
		int ct = INF;
		REP(i,n){
			ct = min(ct,a[i][alp]);
		}
		while(ct--)cout << (char)('a' + alp);
	}
	cout << endl;
  return 0;
}


Measured memory_bytes: 256
from collections import deque

while True:
    W, H = map(int, input().split())
    if W | H == 0:
        break
    tiles = [input() for i in range(H)]
    first = ()
    for h in range(H):
        index = tiles[h].find("@")
        if index != -1:
            first = (index, h)
            break
    memo = {first: 0}
    que = deque([first])
    count = 1
    while len(que) > 0:
        x, y = que.popleft()
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            if (x + dx, y + dy) not in memo:
                if (0 <= x + dx < W) and (0 <= y + dy < H) and tiles[y + dy][x + dx] == ".":
                    count += 1
                    memo[(x + dx, y + dy)] = 1
                    que.append((x + dx, y + dy))
    print(count)


Measured memory_bytes: 6036
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>

using namespace std;

int main(){	
	int N;
	//cin>>N;
	scanf("%d",&N);
	long long a;
	long long t;
	for(int i=1;i<=N;++i){
		long long A;
		long long T;
		//cin>>T>>A;
		scanf("%lld%lld",&T,&A);
		if(i==1){
			a=A;
			t=T;
		}
		else{
			long long gain1=0;
			if(A<a){
				gain1=a/A;
				if(a%A){
					++gain1;
				}
			}
			long long gain2=0;
			if(T<t){
				gain2=t/T;
				if(t%T){
					++gain2;
				}
			}
			gain1=max(gain1,gain2);
			if(!gain1){
				gain1++;
			}
			a=A*gain1;
			t=T*gain1;
		}
	}
	//cout<<a+t<<endl;
	printf("%lld\n",a+t);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	long K;
	int N;
	long[] a;

	Main(BufferedReader in) throws IOException {
		K = Long.parseLong(in.readLine());
		N = 50;
		a = new long[N];
	}

	void eval() {
		int index = -1;
		long max = -1;
		for (int i = 0; i < N; ++i) {
			if (max < a[i]) {
				index = i;
				max = a[i];
			}
		}
		a[index] -= (long) N;
		for (int i = 0; i < N; ++i) {
			if (i != index) {
				a[i]++;
			}
		}
	}

	void calc() {
		if (K % 50 == 0) {
			a[0] = K / 50L;
			for (int i = 1; i < N; ++i) {
				a[i] = 49L + K / 50L;
			}
		} else {
			a[0] = K / 50L + 1L;
			for (int i = 1; i < N; ++i) {
				a[i] = 49L + K / 50L + 1L;
			}
			for (int i = 0; i < (50L - K % 50L); ++i) {
				eval();
			}
		}
	}

	void showResult() {
		System.out.println(N);
		System.out.print(a[0]);
		for (int i = 1; i < N; ++i) {
			System.out.print(" " + a[i]);
		}
		System.out.println("");
	}
}

Measured memory_bytes: 25336
#include <stdio.h>

int solve(int, int);

int i, m, n, q;
int seq[20];

main(){
 

  scanf("%d", &n);

  for( i = 0; i < n; i++){
    scanf("%d", &seq[i]);
  }

  scanf("%d", &q);

  while( q != 0 ){
    i = 0;
    scanf("%d", &m);
    if( solve(i,m) == 1 ) printf("yes\n");
    else printf("no\n");
    q--;
  }

}

int solve(int i, int m){
  int res;

  if( m == 0 ) return 1;
  if( i >= n ) return 0;

  res = solve(i+1, m) || solve(i+1, m-seq[i]);

  return res;

}

Measured memory_bytes: 580
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main()
{
	int N,M,C;
	int sum=0,cnt=0;
	cin >> N >> M >> C;
	int a[100],b[100];
	
	for(int i=0;i<M;i++){
		cin >> b[i];
	}
	
	for(int i=0;i<N;i++){
		for(int j=0;j<M;j++){
			cin >> a[j];
			sum=sum+(a[j]*b[j]);
		}
		if(sum + C > 0)cnt++;
		sum=0;
	}
	
	cout << cnt << endl;
	
	
	return 0;
}

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

if n == 1:
    print(0)
    exit()

def is_prime(n):
    if n <= 1: return False
    for i in range(2, int(n**0.5) + 1):
        if n%i == 0: return False
    return True

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i!=n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors
 
ans = []
cnt = 0
X = make_divisors(n)[1:]
for x in X:
    if is_prime(x):
        ans.append(x)
        n //= x
        cnt += 1
        e = 2
        while x**e < n:
            ans.append(x**e)
            e += 1
    elif x in ans:
        if n%x == 0:
            n //= x
            cnt += 1
print(cnt)

Measured memory_bytes: 9396
#include <bits/stdc++.h>
#include <string>
using namespace std;
int intinput() {
	int x;
	cin >> x;
	return x;
}
vector<int> forintinput(int n) {
	vector<int> x(100000);
	for(int i = 0;i < n;i++) cin >> x[i];
	return x;
}
int main(){
	int a,b;
	a = intinput();
	char c;
	b = intinput();
	if(a + b >= 10){
		cout << "error" << endl;
	}else{
		cout << a+b << endl;
	}
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <queue>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;



int main(){

    int n;
    vector<pair<string,string>> v;
    int result;
    while(cin>>n,n){
        v.resize(n);
        REP(i,n){
            cin>>v[i].first>>v[i].second;
        }

        sort(v.begin(),v.end());
   
        priority_queue< string,std::vector<string>,greater<string>> pq;
        pq.push(v[0].second);
        result = 1;

        /*
        REP(i,n){
            cout << v[i].first << " " << v[i].second << endl;
        }*/

        FOR(i,1,n){
            if(pq.top().compare(v[i].first)<=0){
                pq.pop();
                
            }else{
                result++;
           
            }
            pq.push(v[i].second);
        }
        cout << result << endl;
    }
    

    return 0;
}



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

int main(){
  string s;
  cin >> s;
  string prev;
  int i = 0, cnt = 0;
  while ( i < s.length()){
    if ( i == s.length() - 2 && s[i] == s[i+1]){
      i = i+2;
    }
    if ( prev.length() == 1 && prev[0] == s[i]){
      prev = s[i];
      prev = prev + s[i+1];
      i = i+2;
    } else {
      prev = s[i];
      i++;
    }
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}

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

using namespace std;

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

	if ((N % 500) <= A)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include<iostream>
using namespace std;
void insertsionSort(int a[], int n)
{
	int v,j;
	for(int i=1; i<n; i++)
	{
		v = a[i];
		j=i-1;
		
		while((j >= 0)&&(a[j] > v))
		{
			a[j+1] = a[j];
			j--;
		}
		
		a[j+1] = v;
		
		for(int i=0; i<n; i++)
		{
			if(i != 0)
			cout << " ";
			cout << a[i];
		}
		cout << endl; 
	}
}
int main()
{
	int n;
	
	
	cin >> n;
	
	int a[n] = {0};
	
	for(int i=0; i<n; i++)
	{
		cin >> a[i];
	}
	
	for(int i=0; i<n; i++)
	{
		if(i != 0)
		cout << " ";
		cout << a[i];
	}
	cout << endl;
	
	insertsionSort(a,n);
	
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>
#include <iomanip>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

const ll INF = 1LL<<60;
const ll MOD = 1000000007;

//cout << fixed << setprecision(10);
ll N,M;
ll S,T;
//vector<vector<vector<Pll>>> G;
vector<vector<ll>> G;
vector<vector<ll>> dist;


void bfs(ll from,ll d, ll state){
    queue<Pll> que;
    que.push(Pll(from,state));

    while(!que.empty()){
        ll from = que.front().first;
        ll state = que.front().second;
        que.pop();
        for(auto e : G[from]){
            if(dist[e][(state+1)%3]!=INF) continue;
            dist[e][(state+1)%3]=dist[from][state]+1;
            que.push(Pll(e,(state+1)%3));
        }
    }
}

int main() {
    cin >> N >> M;
    G.assign(N,vector<ll>());
    dist.assign(N,vector<ll>(3,INF));
    for(int i=0;i<M;i++){
        ll w,v;
        cin >> w >> v;
        w--;v--;
        G[w].push_back(v);
    }
    cin >> S >> T;
    S--;T--;
    dist[S][0]=0;
    bfs(S,0,0);
    ll ans=(dist[T][0]==INF?-1:dist[T][0]/3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11392
#include <stdio.h>
int main (void){
   
	int x,y,i=1;

	while(i>0)
	{
	
	scanf("%d %d",&x,&y);
	
	if(x==0 && y==0)
	{
		i=-100;
	}
	
	else
	{
		if(x<=y)
		{
			printf("%d %d\n",x,y);
		}
		else
		{
			printf("%d %d\n",y,x);
		}

		i++;
	}
	
	}
	 
     return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

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

	if (N % 2 == 0) {
		cout << N / 2 << endl;
	}
	else {
		cout << N / 2 + 1 << endl;
	}

}






Measured memory_bytes: 3564