akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
typedef pair<int, int > Pii;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
#define pb push_back
#define rs resize 
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define repll(i, a, b) for(ll i=(a); i<(b); i++)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define COUT(a) cout << a << endl
#define ALL(a) (a).begin(),(a).end()
const long long int mod = 1e9 + 7;

ll gcd(ll x, ll y){
  if(x < y) swap(x,y);
  if(y == 0) return x;
  return gcd(x%y,y);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    ll A,B,C,res=1;
    cin >> A >> B;
    C = gcd(A,B);
    for(ll i=2; i*i<=C; i++){
        if(C%i==0){
            while(C%i==0) C = C/i;
            res++;
        }
    }
    if(C>1) res++;
    COUT(res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    int cnt = 0;
    for(int i = 1; i<=n;i++)
    {
        cin>>a[i];
         if((i%2!=0)&&(a[i]%2!=0))
         {
             cnt++;
         }

    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 3620
import java.io.*
import java.util.*

const val YES = "Yes"
const val NO = "No"
fun solve(S: String){
    if (S.toList().sorted() == "abc".toList()){
        println(YES)
    }else println(NO)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val S = sc.next()
    solve(S)
}



Measured memory_bytes: 35884
N, M, C = map(int, input().split())
B = [int(i) for i in input().split()]
ans = 0
for _ in range(N):
    a = [int(i) for i in input().split()]
    s = 0
    for m in range(M):
        s += a[m] * B[m]
    s += C
    if s > 0:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)

	
int main(){
	string S;
	cin >> S;
	
	int count=0;
	For(i,0,S.size()){
		if(S[i]=='o') count++;
	}
	if(count+15-S.size()>=8) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;

int main(void) {
    lint n;
    cin >> n;
    lint ans = 1e9;
    while (n > 100) {
        if (n < 100) break;
        lint m = n % 1000;
        ans = min(ans, abs(m - 753));
        n /= 10;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int x;
  cin>>x;
  int ans=0;
  rep(i,2,10){
    int j=1;
    while(true){
      if(pow(j,i)>x) break;
      ans=max(ans,(int)pow(j,i));
      j++;
    }
  }
  cout<<ans<<endl;
}

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



int main() {
    string s;
    cin >> s;
    
    int cnt, mx;
    cnt = mx = 0;
    rep(i,3) {
        if(s[i] == 'R')
            cnt++;
        else {
            mx = max(cnt,mx);
            cnt = 0;
        }
    }
    mx = max(cnt,mx);
    
    cout << mx << endl;
    
    
    return 0;
}




Measured memory_bytes: 3588
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t
#include <math.h>

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

int get_int3(int64_t *a1, int64_t *a2, int64_t *a3) {
  return scanf("%lld %lld %lld", a1, a2, a3);
}

int main(void) {
    int64_t a, b, limit;
    get_int3(&a, &b, &limit);

    int64_t x = min(limit, b-1);
    int64_t ans = floor(a*x/b) - a * floor(x/b);
    printf("%lld\n", ans);
    return 0;
}

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

int main(){
    int d,g;
    cin>>d>>g;
    vector<int>p(d),c(d);
    rep(i,d)cin>>p[i]>>c[i];
    int ans=1e9;
    for(int bit=0; bit<(1<<d); ++bit){
        int mn=0,cnt=0;
        vector<bool>a(d,false);
        rep(i,d){
            if(bit&(1<<i)){
                mn+=p[i];
                cnt+=(i+1)*100*p[i]+c[i];
                a[i]=true;
            }
        }
        if(cnt>=g){
            ans=min(ans,mn);
        }
        else{
            for(int i=d-1; i>=0; --i){
                if(a[i])continue;
                for(int j=0; j<p[i]; ++j){
                    cnt+=(i+1)*100;
                    mn++;
                    if(cnt>=g){
                        ans=min(ans,mn);
                        break;
                    }
                }
                if(cnt>=g)break;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,n2,m,ans,ab,a[27000];
ll power(ll x,ll y){
	ll z=1;
	for(int i=0;i<y;i++)
		z*=x;
	return z;
}
void dfs(ll x,ll y){
	if(x>m)return ;
	if(x>=3){
		ll g=y;
		bool b,c,d;
		b=c=d=false;
		for(int i=0;i<x;i++){
			ll z=power(10,x-i-1);
			if(y/z==3)b=true;
			if(y/z==5)c=true;
			if(y/z==7)d=true;
			y%=z;
		}
		if(b==true and c==true and d==true)a[ab++]=g;
		y=g;
	}
	y*=10;
	dfs(x+1,y+3);
	dfs(x+1,y+5);
	dfs(x+1,y+7);
}
int main(){
    ios::sync_with_stdio(false);
    cin >> n;
    n2=n;
    while(n>0)n/=10,m++;
    n=n2;
    dfs(0,0);
    for(int i=0;i<ab;i++)
    	if(a[i]<=n)ans++;
    cout << ans;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;
int main(){
        int A,B,C,D,E,F;
        cin>>A>>B>>C>>D>>E>>F;
        pair<int,int> ans = make_pair(100*A,0);
        double par = 0;
        for (int a = 0; 100*A*a <= F; a++) {
                for (int b = 0; 100*A*a + 100*B*b <= F; b++) {
                        int W = (A*a+B*b)*100;
                        int SMax = (A*a+B*b)*E;
                        for (int c = 0; W + C*c <= F; c++) {
                                for (int d = 0; W + C*c+D*d <= F; d++) {
                                        int S = C*c+D*d;
                                        if(W+S == 0) continue;
                                        if (W + S <= F && S<=SMax) {
                                                if(par < (double)S/(W+S)) {
                                                        ans = make_pair(W+S,S);
                                                        par = (double)S/(W+S);
                                                }
                                        }
                                }
                        }
                }
        }
        cout << ans.first << " " << ans.second << endl;

        return 0;
}


Measured memory_bytes: 256
/// referenced: https://beta.atcoder.jp/contests/abc065/submissions/2326784
#include <bits/stdc++.h>
using namespace std;

vector<int> parent;

int getRoot(int v) {
  if (parent[v] == v) return v;
  return parent[v] = getRoot(parent[v]);
}

bool isSame(int v0, int v1) {
  return getRoot(v0) == getRoot(v1);
}

void unite(int v0, int v1) {
  int root0 = getRoot(v0);
  int root1 = getRoot(v1);
  if (root0 != root1) parent[root0] = root1;
}

int main(){
  int N;
  cin >> N;
  parent.resize(N);
  vector<pair<int, int>> x(N);
  vector<pair<int, int>> y(N);
  for (int i = 0; i < N; ++i) {  // For each vertex.
    int x_tmp, y_tmp;
    cin >> x_tmp >> y_tmp;
    x[i] = make_pair(x_tmp, i);
    y[i] = make_pair(y_tmp, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  vector<pair<int, pair<int, int>>> edges;
  for (int i = 1; i < N; ++i) {
    auto index_x = make_pair(x[i].second, x[i - 1].second);
    auto value_x = abs(x[i].first - x[i - 1].first);
    auto pair_x = make_pair(value_x, index_x);
    edges.push_back(pair_x);
    auto index_y = make_pair(y[i].second, y[i - 1].second);
    auto value_y = abs(y[i].first - y[i - 1].first);
    auto pair_y = make_pair(value_y, index_y);
    edges.push_back(pair_y);
  }
  sort(edges.begin(), edges.end());  // ascending edge length.
  for (int i = 0; i < N; ++i) parent[i] = i;  // no edges.
  int distance = 0;
  for (int i = 0; i < edges.size(); ++i) {
    auto e = edges[i];
    auto next = e.second.first;
    auto prev = e.second.second;
    if (!isSame(next, prev)) {  // Connects components if not connected.
      unite(next, prev);
      distance += e.first;
    }
  }
  cout << distance << endl;
}


Measured memory_bytes: 6900
#include<stdio.h>

int n,A[50];

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-A[i]);
	return res;
}

int main()
{
	int q,M,i;
	scanf("%d",&n);
	for(i=0;i<n;i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i=0;i<q;i++)
	{
		scanf("%d",&M);
		if(solve(0,M)) printf("yes\n");
		else printf("no\n");
	}
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getdiff(const T &a,const T &b,T &c) {
  set_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> T deg2rad(T deg) {return deg*2*M_PI/360;}
template<class T> T rad2deg(T rad) {return rad*360/(2*M_PI);}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const ll MAX=5e6;


int main() {
  // 先頭i文字の部分列か
  // tの全ての文字がsになければout
  map<char,vector<int>> mp;
  string s,t;cin>>s>>t;
  REP(i,siz(s)) mp[s[i]].push_back(i);
 
  // 全ての文字があるか
  REP(i,siz(t)) {
    if (siz(mp[t[i]])==0) {
      OUT(-1);
      return 0;
    }
  }
 
  ll ans = 0;
  int tmp = 0;
  REP(i,siz(t)) {
    auto it = lower_bound(ALL(mp[t[i]]),tmp);
    if (it==mp[t[i]].end()) {
      auto it2 = lower_bound(ALL(mp[t[i]]),0);
      int plus = (siz(s)-tmp)+(*it2+1);
      ans += plus;
      tmp = (tmp+plus)%siz(s);
    } else {
      ans += *it-tmp+1;
      tmp = (tmp+*it-tmp+1)%siz(s);
    }
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;}
template<class T, class U> inline void mul_self(T &a, U b){a *= b;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int n;
    while(cin>>n){
        vd prob(n);
        forn(i,n) cin>>prob[i];

        vvd dp(n+1, vd(n+1));
        dp[0][0] = 1;
        // prob till ith toss, of having of j heads
        fore(coins,1,n+1){
            double pr_head = prob[coins-1];
            forn(heads,n+1){
                dp[coins][heads] = (heads ? dp[coins-1][heads-1] : 0) * pr_head + dp[coins-1][heads]*(1-pr_head);
            }
        }
    
        // print_vv(dp);
        double ans = 0;
        for(int heads=n; heads> n/2; --heads){
            add_self(ans, dp[n][heads]);
        }
        printf("%.11lf\n",ans);
    }
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
using Int = long long int;
template<typename T> void swap(T *t1, T *t2){ T* tmp=t1; t1=t2; t2=tmp;}


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

    Int n, p, cnt=0, tmp = 0;
    cin >> n;
    for(Int i=0; i<n; i++){
        cin >> p;
        if(p != i+1){
            cnt++;
        }
    }
    if(cnt <= 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

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

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

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

ll x[510][510];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,m,q;
    cin>>n>>m>>q;
    
    vec<ll> a(q),b(q);
    rep(i,m){
        ll l,r;
        cin>>l>>r;
        x[l][r]++;
    }
    rrep(i,n){
        rrep(j,n){
            x[i][j]+=x[i][j-1];
        }
    }
    rrep(i,q){
        ll p,q,sum=0;
        cin>>p>>q;
        for(ll j=p;j<=q;j++) sum+=x[j][q]-x[j][p-1];
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 4480
import java.util.Scanner;
 
//Greatest Common Divisor: Euclidean Algorithm
public class Main{
 
    static long gcd(long a, long b){
        c = 0;
        if(a < b){
            long tmp = a;
            a = b;
            b = tmp;
        }
        while(b!=0){
            long r = a%b;
            a = b;
            b = r;
            c++;
        }
        return a;
    }
 
    static int c;
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if((a|b)==0)break;
            System.out.println(gcd(a,b)+" "+c);
        }
    }
}


Measured memory_bytes: 32464
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
primes = prime_factorize(int(input()))
prime_set = set(primes)
count = 0
for p in prime_set:
    cnt = primes.count(p)
    count += 1
    i = 2
    while cnt>i:
        cnt -= i
        count += 1
        i = i + 1
print(count)


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

using namespace std;


char a[111111];
int main(){
    int n, flag = 0;
    scanf("%d", &n);
    for(int i = 0; i < n; i++){
        scanf("%s", a);
        if(a[0] == 'Y'){
            flag = 1;
        }
    }
    if(flag) printf("Four\n");
    else printf("Three\n");
}

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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int numone(int x)
{
    int ret = 0;
    while (x)
    {
        ret += x & 1;
        x >>= 1;
    }
    return ret;
}

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

    int N, M;
    vs32 vec;
    vs32 p;
    cin >> N >> M;

    vec.resize(M, 0);
    p.resize(M, 0);
    int s, k;
    rep (i, M)
    {
        cin >> k;
        rep (j, k)
        {
            cin >> s;
            vec[i] |= (1 << (s - 1));
        }
    }

    rep (i, M) cin >> p[i];

    int ans = 0;
    for (int i = 0; i < (1 << N); ++i)
    {
        bool find = true;
        rep (j, M)
        {
            if (numone(vec[j] & i) % 2 != p[j]) find = false;
        }
        if (find) ++ans;
    }

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
<?php
  
while ($line = fgets(STDIN)) {
   $stdin[] = trim($line);
}
#$v2 = str_split($stdin[0]);
#$v2 = explode(" ", $stdin[0]);

$v = explode(" ", $stdin[0]);

$count = 0;
$loop = 1;

while(true){
  // 1週目は全ポート使える
  if($loop == 1){
    $count = $v[0];
  }else{
    $count = $count + $v[0] - 1;
  }
  
  if($count >= $v[1]){
    break;
  }
  
  $loop++;
}

if($v[1] == 1){ $loop = 0;} 

echo $loop . PHP_EOL;







Measured memory_bytes: 3956
#include<algorithm>
#include<cmath>
#include<deque>
#include<iomanip>
#include<iostream>
#include<list>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<string>
#include<vector>

#include<map>
#include<set>
#define rep0_n(i,n) for(int i=0; i<n; i++)
#define rep1_n(i, n) for(int i=1; i<n+1; i++)
#define reps_n(i, s, n) for(int i=s; i<n; i++)
typedef long long ll;
using namespace std;

int main(){
  int a,x,y;
  cin >> x >> y;
  a = max(x+y,x-y);
  cout << max(a,x*y);
  return 0;
}


Measured memory_bytes: 256
n= int(input())
a = list(map(int, input().split()))
a.append(0)
ans=1000
b = 0
for i in range(1,n+1):
  if a[i] < a[i-1]:
    if i-1-b>0:
      ans = ans//a[b]*a[i-1]+ans%a[b]
    b = i
print(ans)

Measured memory_bytes: 61736
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    n,k = LI()
    r = []
    for i in range(2,n+1):
        r.append((1,i))

    t = (n-1) * (n-2) // 2
    if t < k:
        return -1

    for i in range(2,n+1):
        if t == k:
            break
        for j in range(i+1,n+1):
            t -= 1
            r.append((i,j))
            if t == k:
                break

    if t == k:
        return '{}\n{}'.format(len(r), JAA(r,'\n',' '))

    return -1


print(main())



Measured memory_bytes: 5724
from sys import stdin


def readline_from_stdin() -> str:
    return stdin.readline().rstrip


if __name__ == '__main__':
    pass
    # N = input()
    # X, Y, Z = input().split()
    # A = [int(i) for i in input().split()]
    X = [int(i) for i in input().split()]
    for idx, v in enumerate(X):
        if v == 0:
            print(idx+1)
            exit(0)


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll r,d,x;
  cin >> r >> d >> x;
  REP(i,10){
    ll n = r*x - d;
    cout << n << endl;
    x = n;
  }
  return 0;
}


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

int main()
{
  int n;
  cin >> n;
  ll a = 0, ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> a;
    ans += (a - 1);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;

int dp[100010];
bool isbroken[100010];
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m; cin >> n >> m;
	VE a(m); rep(i, m)cin >> a[i];
	rep(i, m)isbroken[a[i]-1] = true;
	if (!isbroken[0])dp[0] = 1;
	if (!isbroken[1])dp[1] = dp[0] + 1;
	rep(i, n) {
		if (i == 0 || i == 1)continue;
		if(!isbroken[i])dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

template<typename M>
struct segment_tree{
	typedef function<M(M, M)> F;
	int size;//2冪
	vector<M> val;//1-indexed
	F f;//結合関数
	M e;//単位元

	segment_tree(int N, vector<M> &data, F f, M e) : f(f), e(e){
		size = 1;
		while(size < N) size *= 2;
		val.assign(2 * size, e);
		for(int i = 0; i < N; i++) val[size + i] = data[i];
		for(int i = N; i < size; i++) val[size + i] = e;
		for(int i = size - 1; i > 0; i--) val[i] = f(val[2 * i], val[2 * i + 1]);
	}

	//k番目の要素をxに変更する
	void update(int k, M x){
		k += size;
		val[k] = x;
		while(k /= 2) val[k] = f(val[2 * k], val[2 * k + 1]);
	}

	//[l, r)の演算の結果を返す
	M query(int l, int r){
		M L = e, R = e;
		for(l += size, r += size; l < r; l /= 2, r /= 2){
			if(l & 1) L = f(L, val[l++]);
			if(r & 1) R = f(val[--r], R);
		}
		return f(L, R);
	}
};

//(int, my_min, inf)
#define inf (int)(1e9)

int my_min(int x, int y){
	return x < y ? x : y;
}


int main(){
	int N, M, i, j;
	scanf("%d%d", &N, &M);
	string S;
	cin >> S;
	vector<int> A(N + 1, inf);
	A[N] = 0;
	segment_tree<int> t(N + 1, A, my_min, inf);
	for(i = N - 1; i >= 0; i--){
//		printf("i = %d\n", i);
		if(S[i] == '0'){
			A[i] = t.query(i + 1, i + M + 1) + 1;
//			printf("A[i] = %d\n", A[i]);
			t.update(i, A[i]);
		}
	}
/*	for(i = 0; i <= N; i++){
		printf("A[%d] = %d\n", i, A[i]);
	}
*/	if(A[0] >= inf){
		printf("-1\n");
		return 0;
	}
	for(i = 0; i < N; i += j){
		for(j = 1; A[i + j] >= A[i]; j++);
		printf("%d ", j);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
  int s;
  double w,h;
  while(scanf("%d,%lf,%lf",&s,&w,&h)!=EOF){
    double bmi = w/(h*h);
    if(bmi>=25.0) printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 3192
package main

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

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

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`

				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	n := nextInt()
	d := nextInts(n)
	m := nextInt()
	t := nextInts(m)

	if n < m {
		fmt.Fprintln(out, "NO")
		return
	}

	// マップ
	a := map[int]int{}
	for i := 0; i < n; i++ {
		if val, ok := a[d[i]]; ok {
			a[d[i]] = val + 1
		} else {
			a[d[i]] = 1
		}
	}
	ans := "YES"
	for i := 0; i < m; i++ {
		if val, ok := a[t[i]]; ok {
			if val == 0 {
				ans = "NO"
				break
			} else {
				a[t[i]] = val - 1
			}
		} else {
			ans = "NO"
			break
		}
	}

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

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
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}


Measured memory_bytes: 17152
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int q;
    scanf("%d", &q);
    auto f = [](string s, char c){
        int K = s.size();
        string t;
        if(c == 'J') t = s[K-1] + s.substr(0, K-1);
        if(c == 'C') t = s.substr(1) + s[0];
        if(c == 'E'){
            if(K%2 == 0) t = s.substr(K/2) + s.substr(0, K/2);
            else t = s.substr((K+1)/2) + s[K/2] + s.substr(0, K/2);
        }
        if(c == 'A'){
            reverse(s.begin(), s.end());
            t = s;
        }
        if(c == 'P'){
            t = s;
            for(auto &i: t)if(isdigit(i)) i = (i-48-1+10)%10 + 48;
        }
        if(c == 'M'){
            t = s;
            for(auto &i: t)if(isdigit(i)) i = (i-48+1)%10 + 48;
        }
        return t;
    };
    while(q--){
        string t, s;
        cin >> t >> s;
        reverse(t.begin(), t.end());
        for(auto c: t) s = f(s, c);
        cout << s << "\n";
    }
}


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

#define _p(...) (void)printf(__VA_ARGS__)
#define forr(x,arr) for(auto&& x:arr)
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) _rep3(i,0,n)
#define _rep3(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2,)(__VA_ARGS__)
#define _rrep2(i,n) _rrep3(i,0,n)
#define _rrep3(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2,)(__VA_ARGS__)
#define ALL(x) (x).begin(), (x).end()
#define BIT(n) (1LL<<(n))
#define SZ(x) ((int)(x).size())
#define fst first
#define snd second
using ll=long long;using pii=pair<int,int>;using vb=vector<bool>;
using vi=vector<int>;using vvi=vector<vi>;using vvvi=vector<vvi>;
using vl=vector<ll>;using vvl=vector<vl>;using vvvl=vector<vvl>;
using vd=vector<double>;using vvd=vector<vd>;using vvvd=vector<vvd>;
using vpii=vector<pii>;using vvpii=vector<vpii>;using vvvpii=vector<vvpii>;
int ni() { int i; scanf("%d", &i); return i;}
int nl() { ll l; scanf("%lld", &l); return l;}
vi nia(int n) {vi ret(n); rep(i, n) scanf("%d", &ret[i]); return ret;}
vl nla(int n) {vl ret(n); rep(i, n) scanf("%lld", &ret[i]); return ret;}

void Main() {
  string c = "CODEFESTIVAL2016";
  string s;
  cin >> s;
  int ans = 0;
  rep(i, SZ(c)) {
    if (c[i] != s[i]) ans++;
  }
  cout << ans << endl;
}
int main() { cin.tie(0); ios::sync_with_stdio(false); Main(); return 0; }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
template<class T> inline T gcd(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}


int main(){
  int n;
  cin >> n;
  int a[1000000];
  FOR(i,n){
    cin >> a[i];
  }

  if(n%2==0){
    FOR(i,n/2){
      cout << a[n-1-2*i] << " ";
    }
    FOR(i,n/2){
      cout << a[i*2] << " ";
    }
  }else{
    FOR(i,n/2+1){
      cout << a[n-1-2*i] << " ";
    }
    FOR(i,n/2){
      cout << a[i*2+1] << " ";
    }
  }

  cout << endl;
  
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  ll n,a[200010];
  cin>>n;
  ll sum=0;
  rep(i,n){
    cin>>a[i];
    sum+=a[i];
  }

  // cout<<sum<<endl;
  ll div=0,min=1e15;
  rep(i,n-1){
    sum-=a[i];
    div+=a[i];
    if(abs(sum-div)<min)min=abs(sum-div);
  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 5148
#include <iostream>

using namespace std;

int main()
{
  int a = 0;
  char s[5];

  cin >> s;

  for(int i = 0;i < 4;i++){
    if(s[i] == '+')
      a++;
    else
      a--;
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
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 main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> v(M);
    for (auto &&i : v) {
        int a, b;
        cin >> a >> b;
        i = {a, b};
    }

    sort(ALL(v), [](pair<int, int> a, pair<int, int> b) {
        return a.second < b.second;
    });
    int ans = 0, end = 0;
    for (auto &&i : v) {
        if (end <= i.first) {
            end = i.second;
            ans++;
        }
    }
    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=(a) ; i<=(b) ; ++i)
#define mp make_pair
#define pii pair<int, int>
#define PB push_back
#define F first
#define S second
#define Task ""
using namespace std;
long long a, b;
int c[41], cnt[41];

long long calc(long long n) {
    if(n<=0) return 0;
    if(n==1) return 1;
    int last=-1;
    memset(c, 0, sizeof c);
    for(int i=39 ; i>=0 ; --i) {
        if((n>>i)&1) {
            ++c[i];
            if(last==-1) last=i;
        }
    }
    rep(i, 1, last) c[i]+=c[i-1];
    long long ans=0;
    memset(cnt, 0, sizeof cnt);

    if(last==1) cnt[0]=1;
    if(c[0]) cnt[0]^=1;
    for(int i=last-1 ; i ; --i) {
        if(c[i]-c[i-1]==0) continue;
        cnt[0]=(0ll+cnt[0]+(1ll<<(i-1)))%2;
    }

    rep(i, 1, last) {
        if(c[i]-c[i-1]==0) {
            int L=c[last]-c[i]-1;
            int R=i;
            long long xx=(1ll<<L)-1;
            xx%=2;
            xx*=(1ll<<R);
            xx%=2;
            cnt[i]=(cnt[i]+xx)%2;
        } else {
            cnt[i]=1;
            int xx=0;
            for(int j=last-1 ; j>i ; --j) {
                if(c[j]-c[j-1]==0) continue;
                xx=(0ll+xx+(1ll<<(j-1)))%2;
            }
            for(int j=i-1 ; j>=0 ; --j) {
                if(c[j]-c[j-1]==0) continue;
                xx=(0ll+xx+(1ll<<j))%2;
            }
            if(xx) cnt[i]=0;
        }
    }
    rep(i, 0, last) {
        if(cnt[i]&1) ans+=(1ll<<i);
    }
    return ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen(Task".inp", "r", stdin);
    //freopen(Task".out", "w", stdout);
    cin >> a >> b;
    long long ans=(calc(b)^calc(a-1));
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = Integer.parseInt(sc.next());
			int t[] = new int[n + 1];
			int x[] = new int[n + 1];
			int y[] = new int[n + 1];
			for (int i = 1; i <= n; i++) {
				t[i] = Integer.parseInt(sc.next());
				x[i] = Integer.parseInt(sc.next());
				y[i] = Integer.parseInt(sc.next());
			}
			for (int i = 0; i < n; i++) {
				int diff = Math.abs(x[i] - x[i + 1]) + Math.abs(y[i] - y[i + 1]);
				int time = t[i + 1] - t[i];
				if (diff > time || (diff - time) % 2 != 0) {
					System.out.println("No");
					return;
				}
			}
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 59560
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt();
		int w = scanner.nextInt();

		int[][] map = new int[h][w];


		for (int i=0; i<h; i++){
			char[] as = scanner.next().toCharArray();
			for (int j=0; j<w; j++){
				boolean isB = (as[j]=='#');
				if(isB){
					for (int k=1; k<=j && map[i][j-k]>k; k++){
						map[i][j-k]=k;
						for(int l=1; l<=i && map[i-l][j-k]>k+l; l++){
							map[i-l][j-k]=k+l;
						}
					}
					for (int k=1; k<=i && map[i-k][j]>k; k++){
						map[i-k][j]=k;
						for (int l=1; j+l<w && map[i-k][j+l]>k+l; l++){
							map[i-k][j+l]=k+l;
						}
					}
				}else if (i==0 && j==0) map[i][j] = Integer.MAX_VALUE;
				else if (map[0][0]==Integer.MAX_VALUE) map[i][j] = Integer.MAX_VALUE;
				else if (i==0) map[i][j] = map[i][j-1]+1;
				else if (j==0) map[i][j] = map[i-1][j]+1;
				else map[i][j] = Math.min(map[i][j-1], map[i-1][j])+1;
			}
		}

		int ans = 0;

		for (int i=0; i<h; i++) for (int j=0; j<w; j++) {
			ans = Math.max(ans, map[i][j]);
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 35028
/*
* Filename:    aoj0558.cpp
* Desciption:  BFS
* Created:     2016-03-05
* Author:      JIngwei Xu [mail:xu_jingwei@outlook.com]
*
*/
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<queue>
#define INT_MAX 1<<30
using namespace std;
const int INF=100000;
char s[1111];
int maze[1111][1111];
int N,H,W;
int sx,sy,ans,aim;
int d[1111][1111];
int dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
typedef pair<int,int> P;

void bfs(int x,int y){
	memset(d,-1,sizeof(d));
	queue<P> que;
	que.push(P(x,y));
	d[x][y]=0;
	int kx,ky;
	while (!que.empty())
	{
		P pp=que.front();que.pop();
		kx=pp.first;
		ky=pp.second;
		
		if(maze[kx][ky]==aim)break;
		int px,py;
		for (int i = 0; i < 4; i += 1)
		{
			px=kx+dx[i],py=ky+dy[i];
			if(px<0||py<0||px>=H||py>=W)continue;
			if(maze[px][py]==-1)continue;
			if(d[px][py]==-1){
				d[px][py]=d[kx][ky]+1;
				que.push(P(px,py));
			}
		}
	}
	sx=kx;sy=ky;
	ans+=d[kx][ky];
}
int main()
{
	scanf("%d%d%d",&H,&W,&N);
	for (int i = 0; i < H; i += 1)
	{
		scanf("%s",s);
		for (int j = 0; j < W; j += 1)
		{
			if(s[j]=='S'){
				sx=i;sy=j;
				maze[i][j]=0;
			}else if(s[j]=='.'){
				maze[i][j]=0;
			}else if(s[j]=='X'){
				maze[i][j]=-1;
			}else{
				maze[i][j]=s[j]-'0';
			}
		}
	}
	ans=0;
	aim=0;
	while (aim<N)
	{
		aim++;
		bfs(sx,sy);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10404
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String b = sc.nextLine();

		if (b.equals("A")) {
			System.out.println("T");

		}else if (b.equals("C")) {
			System.out.println("G");

		}else if (b.equals("G")) {
			System.out.println("C");

		} else {
			System.out.println("A");
		}

	}

}


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

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; a++) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ex++;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main (void){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> res;
    res = prime_factorize(n);
    int sum=0;
    for (pair<ll, ll> a : res) {
        int i = 1, count = 0;
        while (a.second >= i) {
            a.second -= i;
            count++;
            i++;
        }
        sum += count;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};



//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!

class rest {
public:
	string S;
	int P;
	int Num;
public:
	rest(string s, int p, int num) {
		S = s;
		P = p;
		Num = num;
	}
	bool operator<(const rest &another) const
	{
		if( S != another.S)return S < another.S;
		return P > another.P;

	};
};

int imos[1000000];

signed main() {
	map<int, int> ma;
	int N;
	cin >> N;
	vector<rest> v;

	rep(i, N) {
		string S;
		int P;
		cin >> S >> P;
		v.push_back(rest(S, P, i + 1));
	}
	sort(v.begin(), v.end());
	for (auto r : v) {
		cout << r.Num << endl;
	}



	return 0;
}

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

int main(){
	string ar[] = {"MON","TUE","WED","THU","FRI","SAT","SUN"};
	string s;
	cin>>s;
	if(s=="SUN"){
		cout<<"7";
		return 0;
	}
	else {
		cout<<6-(find(ar,ar+7,s)-ar);
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,k;
int main()
{
	scanf("%lld%lld%lld",&a,&b,&k);
	if(a>k)
		printf("%lld %lld",a-k,b);
	else 
		printf("%lld %lld",0,max((long long)0,a+b-k));
	
	return 0; 
} 

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n][3];
    for(int i=0; i<n; i++){
        for(int j=0; j<3; j++)
            cin>>a[i][j];
    }
    int dp[3]={a[0][0],a[0][1],a[0][2]};
    for(int i=1; i<n; i++){
        int temp[3];
        for(int j=0; j<3; j++){
            temp[j]=a[i][j]+max(dp[(j+1)%3],dp[(j+2)%3]);
        }
        for(int j=0; j<3; j++)dp[j]=temp[j];
    }
    cout<<max(dp[0],max(dp[1],dp[2]));
}


Measured memory_bytes: 4764
#include<iostream>
#include<vector>
#define MAX_N 100000
#define MOD (1000000007)
#define int long long
using namespace std;
vector<int> g[MAX_N];
int n,k,a,b;
int P(int n,int r){
  int tmp=1;
  for(int i=0;i<r;i++){
    tmp*=(n-i);
    tmp%=MOD;
  }
  return tmp%MOD;
}
int dfs(int now,int from){
  int next_val,result=1,K;
  if(from==-1){
    K=P(k-1,g[now].size());
  }else{
    K=P(k-2,g[now].size()-1);
  }
  for(int i=0;i<g[now].size();i++){
    if(g[now][i]==from) continue;
    else{
      result *=dfs(g[now][i],now);
      result %= MOD;
    }
  }
  return (K*result)%MOD;
}
signed main(){
  int ans=1;
  cin >> n >> k;
  for(int i=0;i<n-1;i++){
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  cout <<(dfs(0,-1)*k)%MOD<<endl;
}


Measured memory_bytes: 11520