akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,m,a,b,i;
    cin>>n>>m;
    set<pair<int,int>> edge;
    for (i=0;i<m;i++)
    {
        cin>>a>>b;
        if (a>b)
            swap(a,b);
        edge.insert(mp(a,b));
    }
    bool flag=false;
    for (i=2;i<n;i++)
    {
        if (edge.find(mp(1,i))!=edge.end() && edge.find(mp(i,n))!=edge.end())
        {
            flag=1;
            break;
        }
    }
    if (flag)
        cout<<"POSSIBLE\n";
    else
        cout<<"IMPOSSIBLE\n";
}

Measured memory_bytes: 9600
#include <cstdio>
#include <algorithm>
using namespace std;

double growth[200][200];
double dp[200][200];

int main()
{
	int n, m;
	
	while (scanf("%d %d", &n, &m), n + m){
		for (int i = 0; i < 200; i++){
			dp[0][i] = 1.0;
			for (int j = 1; j < 200; j++){
				dp[j][i] = 0.0;
			}	
		}
		
		for (int i = 0; i < n; i++){
			for (int j = 0; j < n; j++){
				scanf("%lf", &growth[i][j]);
			}
		}
		
		for (int i = 0; i < m - 1; i++){
//			printf("%d\n", i);
			for (int j = 0; j < n; j++){
				for (int k = 0; k < n; k++){
//					printf("%lf\n", dp[i][j] * growth[k][j]);
					dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] * growth[k][j]);
				}
//				printf("%d %lf\n", j, dp[i + 1][j]);
			}
		}
		
		double maxi = 0.0;
		for (int i = 0; i < n; i++){
			maxi = max(maxi, dp[m - 1][i]);
		}
		
		printf("%.2lf\n", maxi);
	}
	
	return 0;
}

Measured memory_bytes: 1560
// #pragma GCC optimize "trapv"

#include<bits/stdc++.h>
using namespace std;
#define vi vector<int> 
#define vll vector<ll> 
#define vpll vector<pair<ll ,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define map map<ll ,ll>
#define umap unordered_map<ll , ll>
#define endl "\n"
#define set set<ll> 
#define setC set<char>
#define all(x) x.begin() , x.end()
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define fastcout ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcases int tt = 1 ; cin >> tt ; for(int i = 1 ; i <= tt ; ++i)
#define codejam cout << "Case #"<<i <<": "; 
#define FOR(i,a,n) for(int i = a ; i <= n ; ++i)
#define FORback(i,a,n) for(int i = n ; i >= a ; --i)
#define ll long long int
const ll INF = 1e13+7;
const ll mod = 1e9+7;


vvll dp;

ll doSome(vll&arr , int i , int j){


    if(i == j){
        return dp[i][j] = arr[i];
    }
    if(j == i+1){
        return dp[i][j] = max(arr[i] , arr[j]);
    }

    if(dp[i][j] != -1)
        return dp[i][j];
    // 1 2 3

    ll a = arr[i] + min(doSome(arr , i+2 , j) , doSome(arr , i+1 , j-1));
    ll b = arr[j] + min(doSome(arr , i+1 , j-1 ) , doSome(arr , i , j-2));

    return dp[i][j] = max(a , b);
}


void solv(){
    ll n;
    cin >> n ;
    vll arr(n);

    FOR(i , 0 , n-1){
        cin >> arr[i];
    }
    dp.assign(n+1 , vll(n+1 , -1));
    ll sum= accumulate(all(arr) , 0LL);
    ll val = doSome(arr , 0 , n-1);

    cout << 2*val - sum << endl;
}

int main(){
    fast ;    
    // testcases{
        // codejam ;
        solv();
    // } 
}




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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

pair<ll, int> pp[MAXN];
int sz[MAXN];
int par[MAXN];

int get_par(int v) {
	return par[v] == v ? v : par[v] = get_par(par[v]);
}

vi g[MAXN];

ll sum_dis[MAXN];
int cnt[MAXN];
int used[MAXN];

void dfs(int s) {
	used[s] = 1;
	cnt[s] = 1;
	REP(i, 0, SZ(g[s])) {
		int to = g[s][i];
		if (!used[to]) {
			dfs(to);
			cnt[s] += cnt[to];
			sum_dis[s] += sum_dis[to] + cnt[to];
		}
	}
}

void solve(){
	int n;
	scanf("%d", &n);
	REPN(i, 1, n) {
		scanf("%lld", &pp[i]._1);
		pp[i]._2 = i;
		sz[i] = 1;
		par[i] = i;
	}
	sort(pp + 1, pp + n + 1);
	int r = n;
	//int bads = 0;
	for(; r > 1; r--) {
		int a = pp[r]._2;
		ll val = pp[r]._1 - (n - 2 * sz[a]);
		int ind = lower_bound(pp + 1, pp + n + 1, mp(val, -1)) - pp;
		if (ind == n + 1 || pp[ind]._1 != val) {
			printf("-1\n");
			return;
		}
		int a1 = get_par(a);
		int b = pp[ind]._2;
		int b1 = get_par(b);
		if (a == b) {
			// Let's assume
			printf("-1\n");
			return;
		}
		par[a1] = b1;
		sz[b] += sz[a];
		g[a].pb(b);
		g[b].pb(a);
	}
	
	int s = pp[1]._2;
	dfs(s);
	if (sum_dis[s] != pp[1]._1) {
		// Let's assume
		printf("-1\n");
		return;
	}
	
	REPN(i, 1, n) {
		REP(j, 0, SZ(g[i])) {
			int to = g[i][j];
			if (to > i) {
				printf("%d %d\n", i, to);
			}
		}
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}


int main() {
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  cout<<15-(x1+x2+x3+x4+x5)<<endl;
  return 0;
}

Measured memory_bytes: 3568
#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>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

template<class T> class segtree {
	int n;
	vector<T> data;
	T id;
	function<T(T, T)> operation;
	function<T(T, T)> update;
public:
	segtree(size_t _n, T _id, function<T(T, T)> _operation, function<T(T, T)> _update)
		:id(_id), operation(_operation), update(_update) {
		n = 1;
		while (n < _n + 2) {
			n *= 2;
		}
		data = vector<T>(2 * n, id);
	}
	void change(int a, int b, int x) {
		a += n; b += n;
		while (a < b) {
			if (a & 1) data[a] = update(data[a], x);
			if (b & 1) data[b - 1] = update(data[b - 1], x);
			a++; a >>= 1; b >>= 1;
		}
	}
	T get(int i) {
		T ret = id;
		i += n;
		while (i > 0) {
			ret = operation(ret, data[i]);
			i >>= 1;
		}
		return ret;
	}
	//T operator[](int i) { return data[i + n]; }
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);

	int n, m;
	cin >> n >> m;
	vector<int> l(n), r(n);
	vector<P> p(n);
	rep(i, n) {
		cin >> l[i] >> r[i];
		l[i]--; r[i]--;
		p[i].first = r[i] - l[i] + 1;
		p[i].second = l[i];
	}
	sort(all(p));
	vector<int> ans(m + 2);
	rep(i, n) ans[p[i].first]++;
	for (int i = m - 1; i >= 1; i--) ans[i] += ans[i + 1];
	segtree<int> seg(m, 0, [](int a, int b) {return a + b; }, [](int a, int b) {return a + b; });
	int idx = 0;
	for (int i = 1; i <= m; i++) {
		while (idx < n && p[idx].first == i - 1) {
			seg.change(p[idx].second, p[idx].first + p[idx].second, 1);
			idx++;
		}
		for (int j = i; j <= m; j += i) ans[i] += seg.get(j - 1);
	}
	rep(i, m) cout << ans[i + 1] << endl;
}

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

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define clr(ar, val) memset(ar, val, sizeof(ar))
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
using namespace std;

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

int main(void)
{
	int n, b[100];
	cin >> n;
	rep(i, n - 1) cin >> b[i];
	int ans = b[0] + b[n - 2];
	rep(i, n - 2) {
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int G[100][100];
int d[100];
int f[100];
int c[100];
int time1,n;

void visit(int);
void dfs(void);

void visit(int u)
{
  int i;

  c[u] = 1;
  d[u] = ++time1;

  for(i=0;i<n;i++){
    if(!G[u][i]) continue;
    if(!c[i]) visit(i);
  }

  c[u] = 2;
  f[u] = ++time1;
}

void dfs()
{
  int i;

  for(i=0;i<n;i++){
    c[i] = 0;
  }

  time1 = 0;

  for(i=0;i<n;i++){
    if(!c[i]) visit(i);
  }

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
}

int main()
{
  int i,j,u,v,k;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&v);
    for(j=0;j<v;j++){
      scanf("%d",&k);
      G[u-1][k-1] = 1;
    }
  }

  dfs();

  return 0;
}


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

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cur = 0;
    int ans = 0;
    while (cur < n)
    {
        cur++;
        set<char> st;
        rep(i, cur) st.insert(s[i]);
        int cnt = 0;
        map<char, int> mp;
        for (int i = cur; i < n; i++)
        {
            if (st.count(s[i]) && !mp.count(s[i]))
            {
                cnt++;
                mp[s[i]]++;
            }
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
--http://www.nct9.ne.jp/m_hiroi/light/lua07.html
Stack = {}

function Stack.new()
  local obj = { buff = {} }
  return setmetatable(obj, {__index = Stack})
end

function Stack:push(x)
  table.insert(self.buff, x)
end

function Stack:pop()
  return table.remove(self.buff)
end

function Stack:top()
  return self.buff[#self.buff]
end

function Stack:isEmpty()
  return #self.buff == 0
end

--------------------------------------------------------

local n,k=io.read("*n","*n")
local edge={}
for i=1,n do
    edge[i]={}
end
for i=1,n-1 do
    local a,b=io.read("*n","*n")
    edge[a][b]=false
    edge[b][a]=false
end

local pattern=k
local stack=Stack.new()
stack:push(1)

while not stack:isEmpty() do
    local a=stack:pop()
    local available_colors
    if a==1 then
        available_colors=k-1
    else
        available_colors=k-2
    end
    for b,_ in pairs(edge[a]) do
        if not edge[a][b] then
            edge[a][b]=true
            edge[b][a]=true
            stack:push(b)
            pattern=pattern*available_colors%1000000007
            available_colors=available_colors-1
        end
    end
end
print(pattern)

Measured memory_bytes: 12976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;typedef vector<ll> vll;
#define fill(a) memset(a, 0, sizeof (a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0; i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define each(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define unq(v) sort(all(v)),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define getpos(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define sz(x) (int)x.size()

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int maxn = 2000100;

int main(){
        _ios;
        int a,b,c;
        cin>>a>>b>>c;
        set<int>s;
        s.insert(a);
        s.insert(b);
        s.insert(c);
        if(s.size()==2)puts("Yes");
        else puts("No");




return 0;
}






Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include <string>
#include<cstdio>
#include<stack>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
using namespace std;
typedef long long ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}

//------------------変数-----------------------//
ll n,a=1,b=1;
//-------------------関数----------------------//

int main() {
	cin >> n;
	REP(i, n) {
		ll aa, bb;
		cin >> aa >> bb;	ll cnt = 1;
		if (a%aa == 0) {
			cnt = a / aa;
		}
		else {
			cnt = a / aa + 1;
		}
		if (b%bb == 0) {
			cnt = max(cnt, b / bb);
		}
		else {
			cnt = max(cnt, b / bb+ 1);
		}
		a = aa*cnt; b = bb*cnt;
	}
	cout << a + b << endl;
}

Measured memory_bytes: 256
from heapq import heappush, heappop
import collections
import math
import heapq
from collections import defaultdict
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    n, m = map(int, input().split())
    e = [[]for i in range(n)]
    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        e[a].append(b)

    dp = [-1 for i in range(n)]
    vis = [False for i in range(n)]

    def f(i):
        if vis[i]:
            return dp[i]
        ret = 0
        for v in e[i]:
            ret = max(ret, f(v) + 1)
        vis[i] = True
        dp[i] = ret
        return dp[i]

    ans = 0
    for i in range(n):
        ans = max(f(i), ans)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 68536
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const long long MOD = 1000000007;

typedef int Weight;
struct Edge{
    int from, to;
    Weight weight;
    int rev;     // 無向グラフの対の辺
    Edge(int from, int to, Weight weight) :
            from(from), to(to), weight(weight) { }
    Edge(int from, int to, Weight weight, int rev) :
            from(from), to(to), weight(weight), rev(rev){ }
};
bool operator < (const Edge &a, const Edge &b){
    if(a.weight != b.weight) return a.weight > b.weight;
    if(a.from != b.from) return a.from > b.from;
    return  a.to > b.to;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;

typedef long long ll;

// O(n)での逆元配列計算
vector<ll> calcinvs(ll n, ll mod){
    vector<ll> inv(n);
    inv[1] = 1;
    for(ll i=2;i<n;++i)
        inv[i] = inv[mod % i] * (mod - mod / i) % mod;
    return inv;
}

void addFlowEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, g[b].size()));
    g[b].push_back(Edge(b, a, 0, g[a].size() - 1));
}
void addUndirectedEdge(Graph &g, int a, int b, Weight c){
    g[a].push_back(Edge(a, b, c, 0));
    g[b].push_back(Edge(b, a, c, 0));
}

int perm(int n, int m, const vector<int> &fact, const vector<int> &invfact) {
    if (m > n) {
        return 0;
    }

    return (fact[n] * invfact[n - m]) % MOD;
}

int dfs(const Graph &g, int v, int prev, int K, const vector<int> &fact, const vector<int> &invfact) {
    int r = 1;
    for(auto e: g[v]) if (e.to != prev) {
        r = (r * dfs(g, e.to, v, K, fact, invfact)) % MOD;
    }

    if (prev == -1) {
        r = (r * perm(K, g[v].size() + 1, fact, invfact)) % MOD;
    } else {
        r = (r * perm(K - 2, g[v].size() - 1, fact, invfact)) % MOD;
    }


    return r;
}

void solve(long long N, long long K, std::vector<long long> a, std::vector<long long> b){
    vector<int> fact(100010);
    fact[0] = 1;

    for(int i = 1; i < 100010; ++i) {
        fact[i] = (fact[i - 1] * i) % MOD;
    }
    vector<int> invfact = calcinvs(100010, MOD);
    invfact[0] = 1;
    for(int i = 1; i < 100010; ++i) {
        invfact[i] = (invfact[i] * invfact[i - 1]) % MOD;
    }

    ++N;
    Graph g(N);
    for (int i = 0; i < a.size(); ++i) {
        addUndirectedEdge(g, a[i], b[i], 0);
    }

    cout << dfs(g, 1, -1, K, fact, invfact) << endl;
}

signed main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
    }
    solve(N, K, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 21376
#include<stdio.h>

int main(void){
        while(1){
                int a, b;
                scanf("%d %d", &a, &b);
                if(a+b==0) break;
                if(a>b) printf("%d %d\n", b, a);
                else printf("%d %d\n", a, b);
        }
        return 0;
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

int N, M;
vector<int> S[10];
int P[10];

bool f(int l, int sw) {
    int tmp = 0;
    for (int s:S[l]) {
        if ((sw >> s) & 1)++tmp;
    }
    return tmp % 2 == P[l];
}

signed main() {
    cin >> N >> M;
    rep(i, M) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            --s;
            S[i].push_back(s);
        }
    }
    rep(i, M)cin >> P[i];
    int ans = 0;
    rep(i, 1 << N) {
        bool flag = true;
        rep(j, M) {
            flag &= f(j, i);
        }
        ans += flag;
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	char c;
	cin >> c;
	switch (c) {
		case 'A':
			cout<<"T"<<endl;
			break;
		case 'C':
			cout<<"G"<<endl;
			break;
		case 'T':
			cout<<"A"<<endl;
			break;
		case 'G':
			cout<<"C"<<endl;
			break;		
	}
	
	return 0;
}

Measured memory_bytes: 256
from sys import stdin


def main():
    S = stdin.readline()
    T = stdin.readline()

    sum_ = 0

    if S[0] == T[0]:
        sum_ += 1

    if S[1] == T[1]:
        sum_ += 1

    if S[2] == T[2]:
        sum_ += 1

    print(sum_)


if __name__ == "__main__":
    main()


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

int main(){
    int N;
    int flag =0;
    cin >> N;
    for(int i =0;i<N;i++){
        for(int k=0;k<N;k++){
            if(4*k + 7*i ==N){
//                cout << k << i;
                flag=1;
                break;
            }
        }
//        if(flag == 1) break;
    }
    if(flag == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
import itertools
##print(ord("A"))
#n = int(input())
#n,k = map(int,input().split())
#h = list(map(int,input().split()))	
s = input()
weat = ["Sunny", "Cloudy", "Rainy","Sunny"]
for i in range(3):
    if s == weat[i]:
        break

print(weat[i+1])


Measured memory_bytes: 3060
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		int n = Integer.parseInt(a + b);
		
		for(int i = 1; i * i <= 10000000; ++i){
			if(i * i == n){
				System.out.println("Yes");
				break;
			}
			if(i * i > n){
				System.out.println("No");
				break;
			}
		}
	}
}

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);	
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll ,ll> 			pll;
typedef pair<ld,ld> 			pld;
typedef unordered_map<ll,ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5+7;
const ll 	MAX7 	= 	1e+7+7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9+7;
const ll 	N 		= 	2*1e6;

vll adj[N];ll visit[N]={};
int dx8[]={0,1,1,1,0,-1,-1,-1}, dy8[]={1,1,0,-1,-1,-1,0,1};
int dx4[]={0,1,0,-1}, dy4[]={1,0,-1,0};

// <------------- Declare Variables Here ------------> //

ll T=1;
ll n,x,y,m,k;
string s,t;
vll a,b,p,ans;
// <------------- Implement Functions Here ----------> //


// <------------- Start of main() -------------------> //

void MAIN() {
	cin >>n>>m;
	ll x= (m%n==0)?(m+n):(m-n);
	cout<<x;
}

int main() {
	fastio;randomINT;
	//cin>>T;
	while(T--) {
		MAIN();
	}
	return 0;
}



Measured memory_bytes: 50500
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pl;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;
int main(){
    int a,b;
    string s,t;
    int n;
    cin>>n;
    cin>>s>>t;
    rep(i,n*2){
        if(i%2 == 0)cout<<s[i/2];
        else cout<<t[i/2];
    }
    cout<<endl;

}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,ans;

signed main() {
    cin >> n;
    if (n%2) {
        cout << 0 << endl;
        return 0;
    }
    while(n) ans += n/5/2, n /= 5;
    cout << ans << endl;
}


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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  int answer;
  
  if (op == "+") {
    answer = A + B;
  }
  else{
    answer = A - B;
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 256
/*
1
T1 H1
T1T2 T1H2+H1T2 H1H2
T1T2T3 T1T2H3+T1H2T3+H1T2T3 T1H2H3+H1T2H3+T1H2H3 H1H2H3
...

simulate from left to right when trying to find the proper DP state

dp[row][0] = dp[row-1][0] * tail
dp[row][col] = dp[row-1][col-1] * head + dp[row-1][col] * tail
dp[row][N] = dp[row-1][N-1] * head

answer = sum of top half of dp[N]
*/
#include <bits/stdc++.h>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  vector<double> dp(n + 1);
	dp[0] = 1;
	for(int i = 0; i < n; ++i) {
    double p;
    scanf("%lf", &p);

    vector<double> ndp(n + 1);
		for(int j = 0; j <= i; ++j) {
			ndp[j] += dp[j] * (1 - p);
			ndp[j + 1] += dp[j] * p;
		}
    dp = ndp;
  }

  double ans = 0;
	for(int i = (n + 1) / 2; i <= n; ++i) ans += dp[i];

  printf("%.12lf\n", ans);

  return 0;
}

Measured memory_bytes: 3840
import java.util.Scanner;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    System.out.print(a/b + " ");
    System.out.print(a%b + " ");
    String str = String.format("%.5f",(double)a/b);
    System.out.println(str);
  }
}

Measured memory_bytes: 26284
#include <stdio.h>

int main(void)
{
	int a, b;
	int first = 0;
	
	scanf("%d %d", &a, &b);
	while (a != 0 || b != 0){
		int i;
		int flag = 0;
		
		if (first == 1){
			puts("");
		}
		for (i = a; i <= b; i++){
			if (i % 4 == 0){
				if (i % 100 != 0 || i % 400 == 0){
					printf("%d\n", i);
					flag = 1;
				}
			}
		}
		if (flag == 0){
			puts("NA");
		}
		
		first = 1;
		scanf("%d %d", &a, &b);
	}
	
	return 0;
}

Measured memory_bytes: 612
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

import heapq
n, m = lr()
a = list(map(lambda x: - int(x), input().split()))
heapq.heapify(a)
for i in range(m):
    b = heapq.heappop(a) * (-1)
    b //= 2
    heapq.heappush(a, -b)
print(-sum(a))


Measured memory_bytes: 14180
#include<bits/stdc++.h>
using namespace std;
string s;
char ch[100005];
bool simulate()
{
    int n=s.length();
    for(int i=1;i<=n;i++)
    {
        if(ch[i]=='S')
        {
            if(s[i]=='o')ch[i+1]=ch[i-1];
            else
            {
                if(ch[i-1]=='S')ch[i+1]='W';
                else ch[i+1]='S';
            }
        }
        else
        {
            if(s[i]=='x')ch[i+1]=ch[i-1];
            else
            {
                if(ch[i-1]=='S')ch[i+1]='W';
                else ch[i+1]='S';
            }
        }
    }
    if(ch[n]!=ch[0])return false;
    if(ch[0]=='S')
    {
        if(s[0]=='o')
        {
            if(ch[n-1]!=ch[1])return 0;
        }
        else
            if(ch[n-1]==ch[1])return 0;
    }
    else
    {
        if(s[0]=='x')
        {
            if(ch[n-1]!=ch[1])return 0;
        }
        else
            if(ch[n-1]==ch[1])return 0;
    }

    return true;
}
void print(int n)
{
    for(int i=0;i<n;i++)cout<<ch[i];
    cout<<endl;
}
int main()
{
    int n;cin>>n;
    cin>>s;
    ch[0]='S';
    ch[1]='S';
    bool f=simulate();
    if(f){
        print(n);
        return 0;
    }
    ch[0]='S',ch[1]='W';
    f=simulate();
    if(f){
        print(n);
        return 0;
    }
    ch[0]='W',ch[1]='W';
    f=simulate();
    if(f){
        print(n);
        return 0;
    }
    ch[0]='W';
    ch[1]='S';
    f=simulate();
    if(f)
    {
        print(n);
        return 0;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define debug(vec) for (auto v : vec) cout << v << " "; cout << endl; 
using namespace std;

typedef long long int llint;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  
  //debug(a)

  llint ans1 = 0;
  vector<llint> sums(n); 
  
  //+-+-...
  if (a[0] <= 0) {
    ans1 -= a[0] - 1; 
    sums[0] = 1;
  }
  else sums[0] = a[0];
  
  rep(i,n-1){
    if (i % 2 == 0){
      if (sums[i] + a[i+1] >= 0)  {
	ans1 += sums[i] + a[i+1] + 1;
	sums[i+1] = -1;
      }
      else sums[i+1] = sums[i] + a[i+1];
    }
    else {
      if (sums[i] + a[i+1] <= 0)  {
	ans1 -= sums[i] + a[i+1] - 1;
	sums[i+1] = 1;
      }
      else sums[i+1] = sums[i] + a[i+1];
    }
  }

//debug(sums)
  llint ans2 = 0;

  //-+-+...
  if (a[0] >= 0) {
    ans2 += a[0] + 1; 
    sums[0] = -1;
  }
  else sums[0] = a[0];
  
  rep(i,n-1){
    if (i % 2 == 0){
      if (sums[i] + a[i+1] <= 0)  {
    	ans2 -= sums[i] + a[i+1] - 1;
    	sums[i+1] = 1;
      }
      else sums[i+1] = sums[i] + a[i+1];
    }
    else {
      if (sums[i] + a[i+1] >= 0)  {
	    ans2 += sums[i] + a[i+1] + 1;
	    sums[i+1] = -1;
      }
      else sums[i+1] = sums[i] + a[i+1];
    }
  }
  //debug(sums)
  //cout << ans1 << " " << ans2 << endl;
  cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
#include <iomanip>
#include <sstream>
#include <unordered_map>

using namespace std;
typedef long long ll;


ll ans, mx, mn, flag, sum=1, cnt;


int main(){
	ll x,a;
	cin>>x>>a;
	if(x<a) cout<<"0";
	else cout<<10;
}


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

using namespace std;

using ll = long long;
using T = tuple<double, double, double>;

//1-indexであることに注意
struct BIT {
    int n;
    vector<int> data;

    BIT(int n) : n(n), data(n + 1, 0) {}

    int sum(int i) {
        int s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

    void add(int i, int x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }
};

int inv(vector<int>& a) {
    int res = 0;
    BIT b(a.size());
    for (int i = 0; i < a.size(); i++) {
        res += i - b.sum(a[i] + 1);
        b.add(a[i] + 1, 1);
    }
    return res;
}

double solve(vector<T>& p, int lim) {
    double ok = 1e9, ng = -1e9 - 1;
    vector<int> idx(p.size());
    for (int i = 0; i < p.size(); i++) {
        idx[i] = i;
    }
    for (int loop = 0; loop < 100; loop++) {
        double mid = (ok + ng) / 2;
        auto comp = [&](const int& i1, const int& i2) {
            double a1, b1, c1, a2, b2, c2;
            tie(a1, b1, c1) = p[i1];
            tie(a2, b2, c2) = p[i2];
            double y1 = (-a1 * mid + c1) / b1;
            double y2 = (-a2 * mid + c2) / b2;
            return y1 < y2;
        };
        sort(idx.rbegin(), idx.rend(), comp);
        if (inv(idx) >= lim) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int lim = (n * (n - 1) + 3) / 4;
    vector<T> p(n);
    for (int i = 0; i < n; i++) {
        cin >> get<0>(p[i]) >> get<1>(p[i]) >> get<2>(p[i]);
    }
    sort(p.begin(), p.end(), [](const T& t1, const T& t2){return -get<0>(t1) / get<1>(t1) < -get<0>(t2) / get<1>(t2);});
    double ansx = solve(p, lim);
    for (int i = 0; i < n; i++) {
        swap(get<0>(p[i]), get<1>(p[i]));
    }
    sort(p.begin(), p.end(), [](const T& t1, const T& t2){return -get<0>(t1) / get<1>(t1) < -get<0>(t2) / get<1>(t2);});
    double ansy = solve(p, lim);
    cout << fixed << setprecision(10) << ansx << " " << ansy << endl;
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
const ll ZERO=0;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N);
    rep(i,N){
        cin>>A.at(i);
    }
    ll W=50;
    rep(j,min(K,W)){
        vector<ll> B(N);
        rep(i,N){
            ll l=max(ZERO,i-A.at(i));
            ll r=min(N-1,i+A.at(i));
            B.at(l)++;
            if(r+1<N)B.at(r+1)--;
        }
        rep(i,N-1)B.at(i+1)+=B.at(i);
        rep(i,N)A.at(i)=B.at(i);
    }
    rep(i,N){
        cout<<A.at(i)<<" ";
    }
    cout<<endl;
}

Measured memory_bytes: 6360
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define M 1000010

int main(){
	IOS;
	ll n;cin>>n;
	vll v;
	ll val=1;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			val=i;
		}
	}
	ll ans=val+(n/val)-2;
	cout<<ans;
	
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    int n=0, x=0;
    cin >> n >> x;
    int m[n]; 
    for(int i=0; i<n; ++i) cin >> m[i];
    
    int sum=0;
    for(int i=0; i<n;i++) sum += m[i];
    int rest = x - sum;
    sort(m,m+n);
    int min = m[0];
    n += rest / min;
    cout << n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1000000000
#define  pow(x) pow(10,(x)) 
typedef long long int LL;

int main(){
    string S; cin >> S;
    string OK = "Good";
    rep(i,S.size()){
        if(i == 0)continue;
        if(S[i] == S[i-1])OK = "Bad";
    }
    cout << OK << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  int n, ans;
  cin >> n;
  ans = n * n;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
int main()
{
  int n,tmp;
  cin>>n;
  vector<int> all;
  for(int i = 0;i<n;i++)
  {
    cin>>tmp;
    all.push_back(tmp);
  }
  for(int i = n-1; i>0;i--)
  {
    if( (all.at(i-1)-all.at(i)) >1)
    {
      cout<<"No"<<endl;
      return 0;
    }
    else if((all.at(i-1)-all.at(i)) == 1)
    {
      all.at(i-1)--;
      /*if(i!=1)
      {
        if( (all.at(i-1)-all.at(i-2))<0 )
        {
           cout<<"No"<<endl;
      		return 0;
        }
      }*/
    }
    else
    {
      continue;
    }
  }
  cout<<"Yes"<<endl;
 return 0; 
}

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

string s[12], input[12];
int h, w;
bool ans = 0;

bool check() {
	int cnt = 0;
	bool b[12] = {};
	for (int i = 0; i < h; ++i) {
		if (!b[i]) {
			string t = s[i];
			reverse(t.begin(), t.end());
			for (int j = i + 1; j < h; ++j) {
				if (!b[j] && t == s[j]) {
					b[i] = 1;
					b[j] = 1;
					cnt += 2;
					break;
				}
			}
		}
	}

	if (h & 1) {
		if (cnt == h - 1) {
			for (int i = 0; i < h; ++i) {
				if (!b[i]) {
					string t = s[i];
					reverse(t.begin(), t.end());
					if (s[i] == t) return 1;
					else return 0;
				}
			}
		}
		else return 0;
	}
	else {
		if (cnt == h) return 1;
		else return 0;
	}
}

void copy(int a, int b) {
	for (int i = 0; i < h; ++i) {
		s[i][b] = input[i][a];
	}
}


bool mask[12];
void rec(int rem) {
	if (rem == 0) {
		if (check()) ans = 1;
	}
	else {
		if (rem & 1) {
			for (int i = 0; i < w; ++i) {
				if (!mask[i]) {
					copy(i, w / 2);
					mask[i] = 1;
					rec(rem - 1);
					mask[i] = 0;
					break;
				}
			}
			if (rem == 1) return;
		}
		int t;
		for (int i = 0; i < w; ++i) {
			if (!mask[i]) {
				copy(i, w / 2 - rem / 2);
				mask[i] = 1;
				t = i;
				break;
			}
		}
		for (int i = 0; i < rem - 1; ++i) {
			int cnt = 0;
			for (int j = 0; j < w; ++j) {
				if (!mask[j]) {
					if (cnt == i) {
						mask[j] = 1;
						copy(j, w - 1 - w / 2 + rem / 2);
						rec(rem - 2);
						mask[j] = 0;
						break;
					}
					else cnt++;
				}
			}
		}
		mask[t] = 0;
	}
}


int main() {
	cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		cin >> input[i];
		s[i] = input[i];
	}

	rec(w);

	if (ans) cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)
flg = 0

kinds = a.uniq.count
if kinds <= k
  puts 0
  flg = 1
end

group = a.group_by {|v| v }.map {|k, v|
  [k, v.count]
}.sort {|a, b|
  a.last <=> b.last
}[0..(kinds - k - 1)]
puts group.map(&:last).reduce(:+) if flg == 0

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

void solve()
{
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        ll x, y;
        cin >> x >> y;
        if (x * x + y * y <= d * d) {
            ++ans;
        }
    }
    cout << ans << endl;
}

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

    /* int T; */
    /* cin >> T; */
    /* for (int t = 0; t < T; ++t) { */
        solve();
    /* } */
    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
int **matrix, *visit, *queue;
void bfs(int, int);
main()
{
        int i, j, n, u, k, v;
        scanf("%d", &n);
        matrix = (int**)malloc(sizeof(int*) * n);
        visit = (int*)malloc(sizeof(int) * n);
    queue = (int*)malloc(sizeof(int) * n);
        for (i = 0; i < n; i++) {
                matrix[i] = (int*)malloc(sizeof(int) * n);
                visit[i] = 0;
                for (j = 0; j < n; j++) {
                        matrix[i][j] = 0;
                }
                scanf("%d%d", &u, &k);
                for (j = 0; j < k; j++) {
                        scanf("%d", &v);
                        matrix[u - 1][v - 1] = 1;
                }
        }
        bfs(1, n);
        for (i = 0; i < n; i++) {
                printf("%d %d\n", i + 1, visit[i] - 1);
                free(matrix[i]);
        }
        free(matrix);
        free(visit);
        free(queue);
}
void bfs(int p, int size)
{
        int i, pos, head = 0, tail = 0;
        queue[tail++] = p;
        visit[p - 1] = 1;
        do {
                pos = queue[head++];
                for (i = 0; i < size; i++) {
                        if (matrix[pos - 1][i] && !visit[i]) {
                                visit[i] = visit[pos - 1] + 1;
                                queue[tail++] = i + 1;
                        }
                }
        } while (head != tail);
}


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

typedef long long ll;
const int mod = 1000000007;

// 0:Tor未定, 1:C, 2:G, 3:A
// dp[i][j][k][l]   i桁目まで決めたとき、i桁目がkで、(i-1)桁目がjで、(i-2)桁目がlである場合の数
// 条件を満たさない場合は、0
ll dp[105][4][4][4];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    
    // 場合の数を考えるときのdpテーブルの初期化
    dp[0][0][0][0] = 1;
    
    // dpテーブルを埋める
    for(int i = 0; i < n; ++i){
        // (i+1)桁目をTにする
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                for(int l = 0; l < 4; ++l){
                    dp[i+1][0][j][k] = (dp[i+1][0][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をCにする(Cを入れられないのは、直前の並びが(AG, GA, AxG, AGx)のとき)
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                // AG or GA
                if((j == 2 && k == 3) || (j == 3 && k == 2))    continue;
                for(int l = 0; l < 4; ++l){
                    // AxG or AGx
                    if((k == 2 && l == 3) || (j == 2 && l == 3))    continue;
                    dp[i+1][1][j][k] = (dp[i+1][1][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をGにする(Gを入れられないのは、直前の並びが(AC)のとき)
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                if(j == 1 && k == 3)    continue;
                for(int l = 0; l < 4; ++l){
                    dp[i+1][2][j][k] = (dp[i+1][2][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
        
        // (i+1)桁目をAにする
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                for(int l = 0; l < 4; ++l){
                    dp[i+1][3][j][k] = (dp[i+1][3][j][k] + dp[i][j][k][l]) % mod;
                }
            }
        }
    }

    ll res = 0;
    for(int i = 0; i < 4; ++i){
        for(int j = 0; j < 4; ++j){
            for(int k = 0; k < 4; ++k){
                res = (res + dp[n][i][j][k]) % mod;
            }
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################


N, Q = map(int, input().split())
S = input().rstrip()

# Sの累積和
rui = [0] * N
for i in range(1, N):
    rui[i] = rui[i-1]
    if S[i-1] == 'A' and S[i] == 'C':
        rui[i] = rui[i-1] + 1

for i in range(Q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1

    print( rui[r] -rui[l] )


Measured memory_bytes: 6332
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
//#define uint __int128_t
 
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define low(a,b) lower_bound(all(a),(b))-(a).begin()
#define upp(a,b) upper_bound(all(a),(b))-(a).begin()
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<vint> vvint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
typedef pair<pint,pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007;
const ll INF=1e18;

int N;
vint v[100010];
int dp[100010];
bool used[100010];

int dfs(int d){
    if(used[d])return dp[d];
    used[d]=true;
    vint tmp;
    for(auto e:v[d])tmp.pb(dfs(e));
    sort(all(tmp),greater<int>());
    rep(i,0,(int)tmp.size())dp[d]=max(dp[d],1+i+tmp[i]);
    return dp[d];
}

signed main() {
    IOS();
    //(1ll<<N)シフト演算のオーバーフローに気をつける
    cin>>N;
    rep(i,1,N){
        int a;cin>>a;
        a--;
        v[a].pb(i);
    }
    
    
    cout<<dfs(0)<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    return 0;
}

Measured memory_bytes: 16000
//Atcoder 177A
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main(){
	int d,t,s;
	cin >> d >> t >> s;
	double time=double(d)/double(s);
	if(time<=double(t)){
		cout << "Yes";
	}
	else cout << "No";
	return 0;
}


Measured memory_bytes: 3608
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int x; cin>>x;
    vector<int> c = {100, 101, 102, 103, 104, 105};

    vector<int> dp(x+1, inf);

    dp[0] = 0;
    for(int i=0; i<6; i++){
        for(int j=0; j + c[i] <= x; j++){
            chmin(dp[j + c[i]], dp[j] + 1); 
        }
    }

    if(dp[x] == inf) cout << 0 << endl;
    else cout << 1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  ll N,W;
  cin>>N>>W;
  vector<ll> w(N),v(N);
  for(int i=0;i<N;i++){
    cin>>w[i]>>v[i];
  }
  ll p=1010*N;
  ll dp[N+1][p];dp[0][0]=0;
  for(int i=1;i<p;i++)dp[0][i]=W+1;
  dp[0][v[0]]=w[0];
  for(int i=1;i<N;i++){
    for(int j=0;j<p;j++){
      if(j<v[i]){
        dp[i][j]=dp[i-1][j];
      }else{
        dp[i][j]=(dp[i-1][j-v[i]]+w[i]>W?dp[i-1][j]:min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]));
      }
    }
  }
  ll m=0;
  for(int i=0;i<p;i++){
    if(dp[N-1][i]<=W)m=i;
  }
  cout<<m;
}

Measured memory_bytes: 79872
#include<bits/stdc++.h>
using namespace std;
#define eps (1>>25)
#define INF (1<<25)
#define MOD 1000000007

int main(){
  cout<<fixed<<setprecision(12);
  int n,w;
  pair<double,pair<int,int> > a[100000];
  double ans;
  cin>>n>>w;
  for(int i=0;i<n;i++){
    cin>>a[i].second.first>>a[i].second.second;
    a[i].first=(double)a[i].second.first/(double)a[i].second.second;
  }
  sort(a,a+n);
  for(int i=n;i>=0;i--){
    if(a[i].second.second>=w){
      ans+=(double)w*a[i].first;
      break;
    }else{
      ans+=a[i].second.first;
      w-=a[i].second.second;
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4824
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>

using namespace std;

typedef long long ll;

int main() {
    string S;
    cin >> S;
    
    int len = S.size();
    int ans = 0;
    
    if (len % 2 == 0) {
        ans = len / 2;
        char body = S[len / 2];
        for (int i = 1; i <= len / 2; ++i) {
            if (S[len / 2 - i] == body && S[len / 2 + i - 1] == body)
                ++ans;
            else
                break;
        }
    } else {
        ans = (len + 1) / 2;
        char body = S[(len - 1) / 2];
        for (int i = 1; i <= (len + 1) / 2; ++i) {
            if (S[(len - 1) / 2 - i] == body && S[(len - 1) / 2 + i] == body)
                ++ans;
            else
                break;
        }
    }
    
    printf("%d\n", ans);
    
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;


int main()
{
    int n;
    cin >> n;
    
    if (n % 1000 == 0)
        cout << 0 << endl;
    else
        cout << ((n / 1000) + 1) * 1000 - n << endl;
}

Measured memory_bytes: 3628