akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(a, b) printf(a, b);
#define c(s) cout << (s) << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define cyn(c) cout << (c ? "Yes" : "No") << endl;
#define cYN(c) cout << (c ? "YES" : "NO") << endl;
#define pyn(c) printf("%s\n", c ? "Yes" : "No");
#define pYN(c) printf("%s\n", c ? "YES" : "NO");
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<LL, LL> P;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int al[26] = {};
int mod = 1e9 + 7;

int main() {
    int N; string S; cin>>N>>S;
    ULL ans = 1;
    rep(i,S.size()){
        al[S[i]-'a']++;
    }
    rep(i,26){
        ans = ((ans%mod) * ((al[i]+1)%mod)) % mod;
    }
    cout<<ans-1<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
	using namespace std;
	typedef long long int ll;
	double dp[3002][3002];
	int main()
	{
		ll n;
		cin>>n;
		double a[n+1];
		for (ll i=1;i<=n;i++)
			cin>>a[i];
		dp[1][1]=a[1];
		dp[1][0]=1-a[1];
		for (ll i=2;i<=n;i++)
		{
			for (ll j=0;j<=i;j++)
			{
				if (j==0)
					dp[i][j]=dp[i-1][j]*(1-a[i]);
				else
					dp[i][j]=dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
			}
		}
		double ans=0;
		for (ll i=n/2+1;i<=n;i++)
			ans+=dp[n][i];
		printf("%0.10lf\n",ans);
	}

Measured memory_bytes: 68992
package main

import "fmt"

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	ans := "No"
	for i := 0; i < len(S); i++ {
		if S == T {
			ans = "Yes"
			break
		}
		S = S[len(S)-1:] + S[0:len(S)-1]
	}
	fmt.Println(ans)
}


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

int main(){
	int N,P,R,P2,P3[100],A;
	R=0;
	while(true){
		cin>>N>>P;
		P2=P;
		A=0;
		memset(P3,0,sizeof(P3));
		if(N==0 && P==0){
			break;
		}
		while(true){
			for(int i=0;i<N;i++){
				if(P3[i]==P){
					R=i;
					goto Exit;
				}
			}
			if(P2==0){
				P2=P3[A%N];
				P3[A%N]=0;
			}
			else{
				P2 -= 1;
				P3[A%N] += 1;
			}
			A++;
		}
		Exit:
		cout<<R<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
N, M = gets.split.map{|i|i.to_i}
students = Array.new(N){gets.split.map{|i|i.to_i}}
checkpoints = Array.new(M){gets.split.map{|i|i.to_i}}
students.each{|s|
    min = 10 ** 9
    cp = nil
    checkpoints.size.times{|c|
        d = (s[0] - checkpoints[c][0]).abs + (s[1] - checkpoints[c][1]).abs
        if d < min
            min = d
            cp = c + 1
        end
    }
    puts cp
}


Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
#define VEC vector
#define V VEC<ll>
signed main(){
  ll N,M,G,i,ans=-1;string S,T;
  cin>>N>>M>>S>>T;G=__gcd(N,M);
  bool x=true;N/=G;M/=G;
  REP(i,G)if(S[i*N]!=T[i*M])x=false;
  if(x)ans=M*N*G;
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

#define DIM 200009
#define INF 1e11+9
#define amen exit(0)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define pairll pair<long long,long long>
#define fi first
#define se second

long long i,j,k,l,n,m;

vector<long long>a[DIM],from[DIM];

long long dp[DIM],vis[DIM];

void dfs(long long v){
    vis[v]=1;
    dp[v]=0;
    for(auto to:from[v]){
        if(vis[to]==0)dfs(to);
        dp[v]=max(dp[v],dp[to]+1);
    }
}

int main()
{
    cin>>n>>m;
    for(i=1;i<=m;i++){
        cin>>k>>l;
        a[k].push_back(l);
        from[l].push_back(k);
    }

    for(i=1;i<=n;i++){
        if(vis[i]==0)dfs(i);
    }

    long long res=-INF;

    for(i=1;i<=n;i++)res=max(res,dp[i]);

    cout<<res<<endl;

    return 0;
}


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

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

    int stick[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    set<int> se;
    vector<int> A(M);
    for (int& x : A) {
        cin >> x;
        int t = stick[x];
        se.insert(t);
    }

    vector<int> dp(N * 2 + 10, -1e9);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        if (dp[i] < 0) continue;
        for (int x : se) {
            if (dp[i] + 1 > dp[i + x]) {
                dp[i + x] = dp[i] + 1;
            }
        }
    }

    string ans;
    int remain = dp[N];
    int match = N;
    sort(A.rbegin(), A.rend());
    while (match > 0) {
        for (int i = 0; i < M; i++) {
            int t = match - stick[A[i]];
            if (t < 0) continue;
            if (dp[t] == remain - 1) {
                ans += char(A[i] + '0');
                match -= stick[A[i]];
                remain--;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
  char c;
  cin >> c;
  if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o' )
  cout << "vowel";
  else 
  cout << "consonant";
}

Measured memory_bytes: 384
// abc158_c
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int A, B;
    cin >> A >> B;

    REPN(n, 1, 1001){
        int x = (int)(n * 0.08);
        int y = (int)(n * 0.1);
        if (x == A && y == B){
            print(n);
            return 0;
        }
    }
    print(-1);

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int x = saori.saori_hayami();
		int ans = 0;
		int num = 0;
		for(int i = 0;i < n;i++){
			num += saori.saori_hayami();
			if(num <= x){
				ans++;
			}
		}
		System.out.println(ans+1);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21076
# 2:50
a, b = map(int, input().split())
if b == 1:
    print(0)
    exit()

if a >= b:
    print(1)
else:
    b -= a
    cnt = 1
    while (b > 0):
        b -= (a - 1)
        cnt += 1
    print(cnt)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define rrep(i,n) for(int i=(n);i>=0;--i)
#define ssort(n) sort((n).begin(),(n).end())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define INF 100000
 
int main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    rep(i,N)cin >> a[i];
 
    int s=0;
    rep(i,N)s^=a[i];
    rep(i,N)a[i]^=s;
    rep(i,N){
        cout << a[i] << endl;
    }
}

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

int main(){
  int S=0;
  int D;
  cin >> D;
  vector<int>c(27);
  for(int i=1;i<27;i++){
    cin >> c[i];
  }
  vector<vector<int>>s(D+1,vector<int>(27,0));
  for(int i=1;i<=D;i++){
    for(int j=1;j<27;j++){
      cin >> s[i][j];
    }
  }
  vector<int>t(D);
  for(int i=1;i<=D;i++){
    cin >> t[i];
  }
  vector<int>lastDi(27);
  for(int i=1;i<=D;i++){
    for(int j=1;j<27;j++){
      if(t[i]==j){
        lastDi[j]=i;
        S+=s[i][j];
      }
      S-=c[j]*(i-lastDi[j]);
    }
    cout << S << endl;
  }
}

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

int main(){
  int N, K;
  cin >> N >> K;
  int A[N];
  int loca = 0;
  for(int i=0;i<N;i++){
  	cin >> A[i];
    if(A[i] == 1) loca = i;
  }
  int M = loca;
  int L = N-M-1;
  int mini = 1000000;
    for(int j=0; j<K; j++){
    double a = (L-K+j+1);
    double b = (M-j);
      int res = ceil(b/(K-1))+ceil(a/(K-1));
      mini = min(mini, res);
    }
  
  cout << mini + 1 << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------


void _main() {
	string S;
	cin >> S;
	string ans = "Good";
	rep(i, 0, S.length() - 1) {
		if (S[i] == S[i + 1]) {
			ans = "Bad";
		}
	}
	cout << ans << endl;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

ll f(ll x, ll y){
    if(x == 0){
        return 0;
    }
    return x / y + f(x / y, y);
}

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

  ll N;
  std::cin >> N;

  if(N % 2 == 1){
      std::cout << 0 << std::endl;
      return 0;
  }

  ll res = std::min(N / 2 + f(N / 2, 2), f(N / 2, 5));
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
S = input()
K = int(input())

if len(set(S)) == 1:
    print(len(S) * K // 2)
    exit()


def count(s):
    res = 0
    cnt = 1
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            cnt += 1
        else:
            res += cnt // 2
            cnt = 1
    res += cnt // 2
    return res


a = count(S)
b = count(S + S)
print(a + (K - 1) * (b - a))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<string>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
using ll = long long;
using lli = long long int;
ll MM = 1000000000;
ll mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
int main(){
    ll q, h, s, d; cin >> q >> h >> s >> d;
    ll ans = 0;
    ll n; cin >> n;
    ll a = min(2*q, h);
    ll b = min(2*a, s);
    if(b*2 <= d) ans = b* n;
    else {
        if(n % 2 == 0){
            ans += (n/2)*d;
        }
        else {
            ans += (n/2)*d;
            ans += b;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#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 INF (1 << 30 - 1)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N >> M;
    vi a(M);
    cin >> a;
    int sum = accumulate(ALL(a), 0);
    dump(sum);
    if (sum > N) {
        cout << -1 << endl;
    } else {
        cout << N - sum << endl;
    }
}

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

int main() {
  int N, K;
  string S;
  cin >> N;
  cin >> S;
  cin >> K;

  char kth = S[K-1];

  for(int i=0; i<N; i++){
    if(kth != S[i]){
        cout << "*";
    }
    else{
        cout << S[i];
    }
  }

  cout << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll ans=0;
    rep(i,1,n+1){
        ll res=1;
        rep(j,0,6){
            if(res>i){
                if(j%2==1) ans++;
                break;
            }
            res*=10;
        }
    }
    cout <<ans<<"\n";
}

Measured memory_bytes: 256
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <algorithm>
#define ii pair<int, int>
#define iii pair<ii, int>
#define pq priority_queue

using namespace std;

vector<vector<int>> precalc(vector<vector<char>> grid, int dir, int h, int w) {
    if (dir == 0) {
        //left
        vector<vector<int>> ans(h, vector<int>(w));
        for (int i = 0; i < h; i++) {
            ans[i][0] = grid[i][0] == '.' ? 1 : 0;
            for (int j = 1; j < w; j++) {
                if (grid[i][j] == '.') {
                    ans[i][j] = ans[i][j - 1] + 1;
                }
                else {
                    ans[i][j] = 0;
                }
            }
        }
        return ans;
    }
    else if (dir == 1) {
        //right
        vector<vector<int>> ans(h, vector<int>(w));
        for (int i = 0; i < h; i++) {
            ans[i][w - 1] = grid[i][w - 1] == '.' ? 1 : 0;
            for (int j = w - 2; j >= 0; j--) {
                if (grid[i][j] == '.') {
                    ans[i][j] = ans[i][j + 1] + 1;
                }
                else {
                    ans[i][j] = 0;
                }
            }
        }
        return ans;
    }
    else if (dir == 2) {
        //up
        vector<vector<int>> ans(h, vector<int>(w));
        for (int i = 0; i < w; i++) {
            ans[0][i] = grid[0][i] == '.' ? 1 : 0;
            for (int j = 1; j < h; j++) {
                if (grid[j][i] == '.') {
                    ans[j][i] = ans[j - 1][i] + 1;
                }
                else {
                    ans[j][i] = 0;
                }
            }
        }
        return ans;
    }
    else if (dir == 3) {
        //down
        vector<vector<int>> ans(h, vector<int>(w));
        for (int i = 0; i < w; i++) {
            ans[h - 1][i] = grid[h - 1][i] == '.' ? 1 : 0;
            for (int j = h - 2; j >= 0; j--) {
                if (grid[j][i] == '.') {
                    ans[j][i] = ans[j + 1][i] + 1;
                }
                else {
                    ans[j][i] = 0;
                }
            }
        }
        return ans;
    }
}

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

    int h, w;
    cin >> h >> w;
    vector<vector<char>> graph(h, vector<char>(w));
    cin.get();
    ii start;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin.get(graph[i][j]);
        }
        cin.get(); //get \n character
    }

    vector<vector<int>> l = precalc(graph, 0, h, w);
    vector<vector<int>> r = precalc(graph, 1, h, w);
    vector<vector<int>> u = precalc(graph, 2, h, w);
    vector<vector<int>> d = precalc(graph, 3, h, w);
    int max_illuminate = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (graph[i][j] == '.') {
                max_illuminate = max(max_illuminate, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
            }
        }
    }
    cout << max_illuminate;
}

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

int main() {
  string S;
  cin >> S;
  if(S.at(2)==S.at(3)&&S.at(4)==S.at(5)){ cout << "Yes" << endl; }
  else { cout << "No" << endl; }
  return 0 ;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, t = LI()
    print(b * (t // a))
    return

#B
def B():
    n = II()
    v = LI()
    c = LI()
    ans = 0
    for i in range(n):
        if v[i] > c[i]:
            ans += v[i] - c[i]
    print(ans)
    return

#C
def C():
    def gcd(a, b):
        if b > a: a, b = b, a
        while b:
            a, b = b, a % b
        return a
    n = II()
    a = LI()
    dp1 = [None] * (n - 1)
    dp1[0] = a[0]
    dp2 = [None] * (n - 1)
    dp2[-1] = a[-1]
    for i in range(1, n - 1):
        dp1[i] = gcd(dp1[i - 1], a[i])
        dp2[-i - 1] = gcd(dp2[-i], a[-i - 1])
    ans = 0
    dp1.insert(0, dp2[0])
    dp2.append(dp1[-1])
    for i in range(n):
        ans = max(ans, gcd(dp1[i], dp2[i]))
    print(ans)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, D;
int A[305][305];
ll X[305*305], Y[305*305];
ll Sum[305*305];

ll Dist(int i, int j){
  return abs(X[i] - X[j]) + abs(Y[i] - Y[j]);
}

int main(){
  cin >> H >> W >> D;
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      cin >> A[i][j];
      X[A[i][j]] = i; Y[A[i][j]] = j;
    }
  }

  for (int i = D + 1; i <= H * W; i++){
    Sum[i] = Sum[i - D] + Dist(i, i - D);
  }

  int Q; cin >> Q;
  for (int i = 0; i < Q; i++){
    int L, R; cin >> L >> R;
    cout << Sum[R] - Sum[L] << endl;
  }

  return 0;
}


Measured memory_bytes: 6088
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, m;
	cin >> n >> m;

	vector<vector<int>> s(m);
	for (auto &vec : s) {
		int k;
		cin >> k;

		vec.resize(k);
		for (auto &v : vec) {
			cin >> v;
			v--;
		}
	}

	vector<int> p(m);
	for (auto &v : p) {
		cin >> v;
	}

	int ans = 0;
	for (int mask = 0; mask < (1 << n); mask++) {
		bool isLight = true;
		for (int i = 0; i < m; i++) {
			int score = 0;
			for (auto v : s[i]) {
				if (mask & (1 << v)) {
					score++;
				}
			}

			if (score % 2 != p[i]) {
				isLight = false;
				break;
			}
		}

		if (isLight) {
			ans++;
		}
	}

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


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

int main() {
    int n;
    cin >> n;
    
    for(int i = 0;i < (1 << n);++i){
        cout << i << ":";
        for(int j = 0;j < n;++j){
            if(i & (1 << j)){
                cout << " " << j;
            }
        }
        cout << endl;
    }
}



Measured memory_bytes: 3100
#include<stdio.h>
int main(void){
    int a,b,c,d,x;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if(a <= c){
        if(b<=c)
            puts("0");
        else{
            if(b<=d){
                printf("%d\n",b-c);
            }
            else{
                printf("%d\n",d-c);
            }
        }
    }
    else{
        x = a;
        a = c;
        c = x;

        x = b;
        b = d;
        d = x;
        if(b<=c)
            puts("0");
        else{
            if(b<=d){
                printf("%d\n",b-c);
            }
            else{
                printf("%d\n",d-c);
            }
        }
    }
    
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

constexpr ll INF = 1e16;
constexpr ll MOD = 1000000007;

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

ll max(ll a, ll b) {return a < b ? b : a; }
ll min(ll a, ll b) {return a > b ? b : a; }
double maxf(double a, double b) { return a < b ? b : a; }

template<typename T> inline string toString(const T &a) {
  ostringstream oss; oss << a; return oss.str();
}

ll dp[61][2];

/* 二進数のbitsetに変換する */
//MSBが先頭に来る
int make_bitset(bitset<60>& bs, ll val) {
  /*int bit_digits = 0;
  int tval = val;
  while(tval) {
    tval /= 2;
    ++bit_digits;
  }*/
  int bit_digits = 60;
  
  int i = 1;
  while(true) {
    bs.set(bit_digits - i, val % 2);
    val /= 2;
    if(val == 0) break;
    ++i;
  }
  
  return bit_digits;
}

int main() {
  int N;
  ll K;
  
  cin >> N >> K;
  
  bitset<60> Kb;
  vector<bitset<60>> Ab(N);
  
  rep(i, 60) {
    dp[i][0] = -1;
    dp[i][1] = -1;
  }
  
  make_bitset(Kb, K);
  
  rep(i, N) {
    ll A;
    cin >> A;
    make_bitset(Ab[i], A);
  }
  
  // int bit_digits = 0;
  // ll tval = K;
  // while(tval) {
  //   tval /= 2;
  //   ++bit_digits;
  // }
  int bit_digits = 60;
  
  vector<int> bitcounts;
  
  rep(j, 60) {
    int ct = 0;
    rep(i, N) {
      if(Ab[i][j]) ++ct;
    }
    bitcounts.push_back(ct);
  }
  
  dp[60 - bit_digits][0] = 0;
  
  for(int i=60 - bit_digits; i<60; ++i) {
    rep(j, 2) {
      if(dp[i][j] >= 0) {
        rep(d, (j ? 1 : Kb[i]) + 1) {
          int i_n = i + 1;
          int j_n = j || d < Kb[i];
          ll n_v = dp[i][j] + (d == 0 ? ((ll)bitcounts[i] << (60-i-1)) : ((ll)(N - bitcounts[i]) << (60-i-1)));
          dp[i_n][j_n] = max(dp[i_n][j_n], n_v);
        }
      }
    }
  }
  
  cout << max(dp[60][0], dp[60][1]) << endl;
}


Measured memory_bytes: 1024
a = input().split()
tg = a[0]
ok_nums = set(["1","2","3","4","5","6","7","8","9","0"])
ng_nums = set(input().split())
ok_nums = ok_nums - ng_nums
rt = 0
i = int(tg)
while True:
  if ok_nums >= set(d for d in str(i)):
    print(i)
    break
  else:
    i+=1

Measured memory_bytes: 9184
mod = 998244353
n, k = map(int, input().split())
index_list = []
for _ in range(k):
    l, r = map(int, input().split())
    index_list.append([l, r])

dp = [0 for _ in range(n)]
dpsum = [0 for _ in range(n)]
dp[0] = 1
dpsum[0] = 1
for i in range(1, n):
    for l, r in index_list:
        l_index = max(i - r - 1, -1)
        r_index = i - l
        if r_index >= 0:
            dp[i] += dpsum[r_index]
            if (r_index > l_index) & (l_index >= 0):
                dp[i] -= dpsum[l_index]
    dp[i] = dp[i] % mod
    dpsum[i] = (dp[i] + dpsum[i - 1]) % mod
print(dp[-1])

Measured memory_bytes: 24772
import sys
from collections import deque
from itertools import *


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


def S(): return sys.stdin.readline().rstrip()


def LS(): return list(sys.stdin.readline().rstrip().split())


def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]


N = I()
ans_list = []
divi_list = make_divisors(N)

for i in range(len(divi_list)):
    for q in range(len(divi_list)):
        if divi_list[i] * divi_list[q] == N:
            ans_list.append(
                max(len(str(divi_list[i])), len(str(divi_list[q]))))
print(min(ans_list))


Measured memory_bytes: 41484
# coding: utf-8
# Your code here!
l=[]
for i in range(3):
   l.append(input()) 
k=[]
for j in l:
    k.append(list(j))
ans=0    
next=k[0][0]
k[0]=k[0][1:]
if len(k[0])==0:
    print("A")
    ans+=1

while ans==0:
    if next=="a":
        if len(k[0])==0:
            print("A")
            ans+=1
        else:
            next=k[0][0]
            k[0]=k[0][1:]
        
    if next=="b":
        if len(k[1])==0:
            print("B")
            ans+=1
        else:
            next=k[1][0]
            k[1]=k[1][1:]
    if next=="c":
        if len(k[2])==0:
            print("C")
            ans+=1
        else:
            next=k[2][0]
            k[2]=k[2][1:]      

Measured memory_bytes: 3064
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = (l);x<=(u);x++)
#define RREP(x,l,u) for(ll x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 100010;
const int mod = 1e9+7;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

ll N;

deque<ll> Ans;

int A[100],cnt;

void Work(){
	while(N){
		A[++cnt]=N&1;
		N>>=1;
	}
	int tot=0;
	RREP(i,cnt-1,1){
		Ans.PB(++tot);
		if(A[i])Ans.push_front(++tot);
	}
	iout(tot*2);
	for(auto i:Ans)printf("%d ",i);REP(i,1,tot)printf("%d ",i);
}

void Init(){
	read(N);N++;
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 256
def last_alert(list_):
    iter_ = iter(list_)
    n = next(iter_)
    for i in iter_:
        yield n, False
        n = i
    yield n, True


N, X = map(int, input().split())
ans = 0
for i, is_last in last_alert(sorted(map(int, input().split()))):
    if is_last and X != i:
        break
    elif X < i:
        break
    X -= i
    ans += 1
print(ans)


Measured memory_bytes: 3060
n = int(input())
if n < 105:
  print(0)
elif 105 <= n < 135:
  print(1)
elif 135 <= n < 165:
  print(2)
elif 165 <= n < 189:
  print(3)
elif 189 <= n < 195:
  print(4)
else:
  print(5)

Measured memory_bytes: 3060
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return(a)

N, K = map( int, input().split())
X = list( map( int, input().split()))
now = abs( K - X[0])
for x in X:
    now = gcd(now, abs(x-K))
print(now)


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

int main()
{
    int n, m, answer = 0;
    cin >> n >> m;
    bool flag = 0;
    int start_point;
    vector<int> shop_gap(n + 1, 0);
    for (int i = 0; i < m; i++)
    {
        int c, d;
        cin >> c >> d;
        for (int j = c; j < d; j++)
        {
            shop_gap.at(j)++;
        }
    }
    for (int i = 0; i < n + 1; i++)
    {
        if (shop_gap.at(i) != 0 && flag == 0)
        {
            flag = 1;
            start_point = i;
        }
        else if (shop_gap.at(i) == 0 && flag == 1)
        {
            flag = 0;
            answer += 2 * (i - start_point);
        }
    }
    answer += n + 1;
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
#include <stdlib.h>

int main (void) {
    int n, ans;

    scanf("%d", &n);

    ans = n;
    while ( ans%10 != (ans%100)/10 ||   /* 1の位と10の位 */
            (ans%100)/10 != ans/100 )   /* 10の位と100の位 */
        ans++;

    printf("%d\n", ans);
    return EXIT_SUCCESS;
}


Measured memory_bytes: 128
x = int(input())
max_num = 0
max_count = 0

for i in range(1, x+1):
    count = 0
    flag =1
    num = i
    while flag==1:
        if num%2 == 0:
            count = count+1
            num = num/2
            continue
        else:
            flag=0
            if count>=max_count:
                max_num = i
                max_count = count
                break
            else:
                break

print(max_num)
    



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
typedef pair<long double, long double> p;
#define X first
#define Y second

p transition(p p0, p p1, p p2){
  p t;
  double theta = atan2(p1.Y-p0.Y,p1.X-p0.X);
  t.X = (cos(theta)*(p2.X-p0.X)+sin(theta)*(p2.Y-p0.Y))*cos(theta)+p0.X;
  t.Y = (cos(theta)*(p2.X-p0.X)+sin(theta)*(p2.Y-p0.Y))*sin(theta)+p0.Y;
  return t;
}

int main(){ _;
  p p0,p1,p2,t;
  int q;
  cin>>p0.X>>p0.Y>>p1.X>>p1.Y>>q;
  REP(i,q){
    cin>>p2.X>>p2.Y;
    t = transition(p0,p1,p2);
    printf("%.10Lf %.10Lf\n", t.X, t.Y);
  }
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <unordered_map>

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

using namespace std;

int main()
{
  int n[4];
  REP(i, 4)
  {
    cin >> n[i];
  }

  sort(n, n + 4);
  if (n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9)
  {
    cout << "YES" << endl;
  }
  else
  {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 888
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int M = sc.nextInt();
    int X = sc.nextInt();

    int[] A = new int[N];

    for (int i = 0; i < M; i++) {
      A[i] = sc.nextInt();
    }

    sc.close();

    int count = 0;

    for (int i = 0; i < M; i++) {

      if (A[i] < X) {
        count++;
      }

    }

    if (count < M/2) {
      System.out.println(count);
    } else {
      System.out.println(M - count);
    }

  }

}

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

int main(){

    string s;
    cin >> s;

    rep(i,s.size()){
        cout << "x";
    }cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

const ll INF=1e18;

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

  ll ans=INF;
  for(ll i=1;i*i<=N;i++){
    if(N%i==0){
      ans=min(ans,i-1+(N/i)-1);
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>	// 入出力
#include<stdio.h>	// printf()が使える小数は%fで
#include<math.h>	// 数学の関数
#include<vector>	// 配列
#include<string>	// 文字列
#include<map>		// 連想配列
#include<stack>		// スタック
#include<queue>		// キュー
#include<algorithm> // ソートとか

long long int ll1 = 1;

using namespace std;

int main()
{
	int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;

	long long int sub = (D - C)*(N - 1);

	long long int ans = B - A;

	for (int i = 0; i < N; ++i)
	{
		long long int cell = ll1*C*i - ll1*D*(N - 1 - i);

		if (ans >= cell&&ans <= cell + sub)
		{
			cout << "YES" << endl;
			return 0;
		}
	}

	cout << "NO" << endl;

	return 0;
}

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

int main(){
  int n,m;
  cin >> n >> m;
  cout << (n-1)*(m-1) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int k = Integer.parseInt(sc.next());
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    for (int i = a; i <= b; i++) {
      if (i % k == 0) {
        pw.println("OK");
        return;
      }
    }
    pw.println("NG");
  }
}


Measured memory_bytes: 35768
import sys; input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
from collections import defaultdict
mod = 10 ** 9 + 7; INF = float("inf")

def getlist():
	return list(map(int, input().split()))

class lazySegTree(object):
	def __init__(self, N):
		self.N = N
		self.LV = (N - 1).bit_length()
		self.N0 = 2 ** self.LV
		self.data = [N - 1] * (2 * self.N0)
		self.lazy = [INF] * (2 * self.N0)

	# 遅延伝播を行うindexを生成
	def gindex(self, l, r):
		L = (l + self.N0) >> 1; R = (r + self.N0) >> 1
		lc = 0 if l & 1 else (L & -L).bit_length()
		rc = 0 if r & 1 else (R & -R).bit_length()
		for i in range(self.LV):
			if rc <= i:
				yield R
			if L < R and lc <= i:
				yield L
			L >>= 1; R >>= 1

	# 遅延伝搬処理
	def propagates(self, *ids):
		for i in reversed(ids):
			v = self.lazy[i - 1]
			if v == INF:
				continue
			self.lazy[2 * i - 1] = min(self.lazy[2 * i - 1], v)
			self.lazy[2 * i] = min(self.lazy[2 * i], v)
			self.data[2 * i - 1] = min(self.data[2 * i - 1], v)
			self.data[2 * i] = min(self.data[2 * i], v)
			self.lazy[i - 1] = INF

	def update(self, l, r, x):
		*ids, = self.gindex(l, r + 1)
		self.propagates(*ids)

		L = self.N0 + l; R = self.N0 + r + 1
		while L < R:
			if R & 1:
				R -= 1
				self.lazy[R - 1] = min(self.lazy[R - 1], x)
				self.data[R - 1] = min(self.data[R - 1], x)
			if L & 1:
				self.lazy[L - 1] = min(self.lazy[L - 1], x)
				self.data[L - 1] = min(self.data[L - 1], x)
				L += 1
			L >>= 1; R >>= 1
		for i in ids:
			self.data[i - 1] = min(self.data[2 * i - 1], self.data[2 * i])

	# k番目の値を取得
	def pointQuery(self, k):
		*ids, = self.gindex(k, k + 1)
		self.propagates(*ids)
		return self.data[k + self.N0 - 1]

	# デバッグ用
	def debug(self):
		ids = [i for i in range(self.N0, 0, -1)]
		self.propagates(*ids)
		print(self.data[self.N0 - 1:])

def main():
	N, Q = getlist()
	lSeg_low = lazySegTree(N + 1)
	lSeg_col = lazySegTree(N + 1)
	ans = (N - 2) ** 2
	for i in range(Q):
		n, x = getlist()
		if n == 1:
			itr = lSeg_col.pointQuery(x)
			ans -= itr - 2
			lSeg_low.update(2, itr - 1, x)
		else:
			itr = lSeg_low.pointQuery(x)
			ans -= itr - 2
			lSeg_col.update(2, itr - 1, x)
		# lSeg_low.debug()
		# lSeg_col.debug()
		# print(2, itr, x)
	print(ans)
	# print((N - 2) ** 2 - ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 93732
#include <utility>
#include <algorithm>
#include <iostream>
#include <queue>

using namespace std;

int N;
int D[100+10] = {};
int U = 0;
int K[100+10] = {0};
int V = -1;
int G[100+10][100+10] = {0};



void bfs(int src){
  //cerr << "bfs root = " << src << endl;
  queue<int> Q;
  Q.push(src);
  D[src] = 0;
  while (! Q.empty()){
    int cur = Q.front();
    Q.pop();
    //cerr << "visiting " << cur << " " << D[cur] << endl;
    for(int dst=1;dst<=N;++dst){
      if(D[dst] == -1 && G[cur][dst] == 1){
	D[dst] = D[cur]+1;
	Q.push(dst);
      }
    }
  }
}

int main(){
  cin >> N;
  for(int i=0;i<101;++i){
    D[i] = -1;//?????????
  }

  for(int i=0;i<N;++i){
    cin >> U;
    cin >> K[U];
    for(int j=0;j<K[U];++j){
      cin >> V;
      G[U][V] = 1;
    }
  }
  /*
  for(int j=1;j<=N;++j){
    for(int i=1;i<=N;++i){
      cout << G[i][j] << " ";
    }
    cout << endl;
   }
*/

  bfs(1);
  
  for(int i=1;i<=N;++i){
    cout << i << " " << D[i] << endl;
  }

}

Measured memory_bytes: 3116
#include<iostream>
using namespace std;
int N,a,b,c;
main()
{
  cin>>N;
  for(int i=0;i<N;i++)
  {
    int A;cin>>A;
    if(A%2)a++;
    else if(A%4)b++;
    else c++;
  }
  a+=b>0;
  cout<<(c+1<a?"No":"Yes")<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(){

  int a, b;
  string s;

  cin>>a>>b;
  cin>>s;

  for(int i=0;i<s.size();i++){
    if(i<a){
      if(!('0'<=s[i]&&s[i]<='9')){
        cout<<"No"<<endl;
        return 0;
      }
    }else if(i==a){
      if(s[i]!='-'){
        cout<<"No"<<endl;
        return 0;
      }
    }else{
      if(!('0'<=s[i]&&s[i]<='9')){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }

  cout<<"Yes"<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
 
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define F first
#define S second
#define MP make_pair
#define PB push_back
 
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)
int main(){
	ll n,k,x,y,ans;
	cin>>n>>k>>x>>y;
	if(n>k)
		ans=k*x;
	else
		ans=n*x;
	if(n-k>0)
		ans+=(n-k)*y;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 int main(void){
  int i,x;
    int tm[4];
  for(x=0,i=0;i<4;i++){
    scanf("%d",&tm[i]);
    x+=tm[i];
  }
  printf("%d\n%d\n", x/60,x%60);
  return 0;
}

Measured memory_bytes: 596
import itertools

dx = (0, 0, 0, 1,-1, 1, 1,-1,-1,-2, 2, 0, 0)
dy = (0, 1,-1, 0, 0, 1,-1, 1,-1, 0, 0,-2, 2)
dd = (5, 9, 13)

def drop(fab, start, used, size_list):
    for xy in range(start, 100):
        y = xy%10
        x = xy//10
        size = size_list[used]
        for i in range(size):
            if not fab[y + dy[i] + 2][x + dx[i] + 2]:
                break
        else:
            for i in range(size):
                fab[y + dy[i] + 2][x + dx[i] + 2] -= 1
            if sum(map(sum, fab)):
                if size == size_list[used + 1]:
                    result = drop(fab, xy, used + 1, size_list)
                else:
                    result = drop(fab, 0, used + 1, size_list)
                if result:
                    result.append([x, y, dd.index(size) + 1])
                    return result
                for i in range(size):
                    fab[y + dy[i] + 2][x + dx[i] + 2] += 1
            else:
                return [[x, y, dd.index(size) + 1]]
    return False

fab = [[0 for i in range(14)] for j in range(14)]

n = int(input())

for i in range(10):
    fab[i + 2][2:12] = list(map(int, input().split()))

s = sum(map(sum, fab))
d_all = list(itertools.combinations_with_replacement([5,9,13], n))
d_list = [l for l in d_all if sum(l) == s]

ans = [0 for i in range(n)]
for d in d_list:
    d_tmp = sorted(d)[::-1]
    ans = drop(fab, 0, 0, d_tmp)
    if ans:
        for a in ans:
            print(*a)
        break



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

int main() {
    int t;
    cin >> t;
    while (t--) {
        int nums[9];
        char colors[10];
        for (int i = 0; i < 9; i++) {
            cin >> nums[i];
        }
        for (int i = 0; i < 9; i++) {
            cin >> colors[i];
        }
        int cards[3][9] = {};
        int colorNum[3] = {};
        for (int i = 0; i < 9; i++) {
            int color;
            switch (colors[i]) {
            case 'R':
                color = 0;
                colorNum[0]++;
                break;
            case 'G':
                color = 1;
                colorNum[1]++;
                break;
            case 'B':
                color = 2;
                colorNum[2]++;
                break;
            default:
                break;
            }
            cards[color][nums[i]]++;
        }
        if (colorNum[0] % 3 != 0 || colorNum[1] % 3 != 0 || colorNum[2] % 3 != 0) {
            cout << 0 << endl;
            continue;
        }
        int result = 1;
        for (int i = 0; i < 3; i++) {
            int c, n;
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 9; k++) {
                    if (cards[j][k] > 0) {
                        c = j;
                        n = k;
                        goto endSearch;
                    }
                }
            }
        endSearch:
            if (cards[c][n] >= 3) {
                cards[c][n] -= 3;
                break;
            }
            if (n > 7
                || cards[c][n] <= 0 || cards[c][n + 1] <= 0 || cards[c][n + 2] <= 0) {
                result = 0;
                break;
            }
            for (int j = 0; j < 3; j++) {
                cards[c][n + j]--;
            }
        }
        cout << result << endl;
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  string x;
  string zero = "0";
  int sum;
  while (true) {
    sum = 0;
    cin >> x;
    if (x == zero) break;
    sum = accumulate(x.begin(), x.end(), 0,
                     [](int acc, char i) { return acc + (i - '0'); });
    cout << sum << endl;
  }
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
inline long long read(){
	register long long x=0;
	register bool f=0;
	register char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<3)+(x<<1)+c-48;
		c=getchar();
	}
	return f?-x:x;
}
char cr[200];int tt;
inline void print(register long long x,register char k='\n') {
    if(!x) putchar('0');
    if(x < 0) putchar('-'),x=-x;
    while(x) cr[++tt]=x%10+'0',x/=10;
    while(tt) putchar(cr[tt--]);
    putchar(k);
}
const int maxn=233333;
int n;
int k,c,f[maxn],g[maxn];
char s[maxn];
bool v1[maxn],v2[maxn];
int main(){
	n=read();k=read();c=read();
	gets(s+1);
	for(int i=1;i<=n;i++){
		f[i]=s[i]=='o'?i:f[i-1];
	}
	g[n+1]=n+1;
	for(int i=n;i>=1;i--){
		g[i]=s[i]=='o'?i:g[i+1];
	}
	int mx1=0,mx2=0,t=1;
	while(1<=t&&t<=n){
		t=g[t];
		if(1<=t&&t<=n){
			v1[t]=true;
			t+=c+1;
			mx1++;
		}
	}
	t=n;
	while(1<=t&&t<=n){
		t=f[t];
		if(1<=t&&t<=n){
			v2[t]=true;
			t-=c+1;
			mx2++;
		}
	}
	if(max(mx1,mx2)>k) return 0;
	for(int i=1;i<=n;i++) if(v1[i]&&v2[i]) print(i);
	return 0;
}

Measured memory_bytes: 3712
#include <cstdio>
#include <algorithm>
#include <string>

using namespace std;

int N;
const char x[4][2][2] = {{"." , "."} , {"." , "#"} , {"#" , "."} , {"#" , "#"}};
string s[2];
char c[7];
bool b = 1;

int main(){
	scanf("%d" , &N);
	for(int i = 0 ; i < 4 ; ++i){
		printf("%s\n%s\n" , x[i][0] , x[i][1]);
		fflush(stdout);
		scanf(" %s" , c);
		if(c[0] == 'e') return 0;
		if(c[0] == 'T'){
			s[0] += x[i][0];
			s[1] += x[i][1];
			break;
		}
	}
	while(1){
		for(int j = 0 ; j < 4 ; ++j){
			if(b){
				printf("%s%s\n%s%s\n" , s[0].c_str() , x[j][0] , s[1].c_str() , x[j][1]);
				fflush(stdout);
				scanf(" %s" , c);
				if(c[0] == 'e') return 0;
				if(c[0] == 'T'){
					s[0] += x[j][0];
					s[1] += x[j][1];
					break;
				}
			} else {
				printf("%s%s\n%s%s\n" , x[j][0] , s[0].c_str() , x[j][1] , s[1].c_str());
				fflush(stdout);
				scanf(" %s" , c);
				if(c[0] == 'e') return 0;
				if(c[0] == 'T'){
					s[0].insert(0 , x[j][0]);
					s[1].insert(0 , x[j][1]);
					break;
				}
			}
			if(j == 3){
				b = 0;
				j = -1;
				continue;
			}
		}
	}
}


Measured memory_bytes: 596