akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 1000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*4
#define REP(a,b) for(long long a = 0;a < b;++a)
int grid[2000][2000];
int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for (int i = 0; i < b; ++i) {
		for (int q = 0; q < w; ++q) {
			grid[i][q] += 1;
			grid[i][q] %= 2;
		}
	}
	for (int i = 0; i < a; ++i) {
		for (int q = 0; q < h; ++q) {
			grid[q][i] += 1;
			grid[q][i] %= 2;
		}
	}
	for (int i = 0; i < h; ++i) {
		int cnt[2] = {};
		REP(q, w) {
			cnt[grid[i][q]]++;
		}
		if (min(cnt[0], cnt[1]) != a) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = 0; i < w; ++i) {
		int cnt[2] = {};
		REP(q, h) {
			cnt[grid[q][i]]++;
		}
		if (min(cnt[0], cnt[1]) != b) {
			cout << "No" << endl;
			return 0;
		}
	}
	REP(i, h) {
		REP(q, w) {
			cout << grid[i][q];
		}
		cout << endl;
	}
}

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

int main(){
int h1,h2,k1,k2,a,b,c,d;
cin>>h1>>h2>>k1>>k2>>a>>b>>c>>d;

int A = h1/10;
int B = h2/20;
int C = k1/10;
int D = k2/20;

if(h1*a+h2*b+A*c+B*d > k1*a+k2*b+C*c+D*d) cout<<"hiroshi"<<endl;
if(h1*a+h2*b+A*c+B*d < k1*a+k2*b+C*c+D*d) cout<<"kenjiro"<<endl;
if(h1*a+h2*b+A*c+B*d == k1*a+k2*b+C*c+D*d) cout<<"even"<<endl;

return 0;
}



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

#define rep(i, j) FOR(i, 0, j)
#define rep2(i, k) for(int i = 1; i <= k; ++i)
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define INF (1 << 30)

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

int field[105][105], use[105][105];
int h, w, sx, sy, gx, gy, n;
int scol;

void make_map(int x,int y,int chk,int color){
  if(chk == 0){
    for(int i=y;i<y+2;i++){
      for(int j=x;j<x+4;j++) field[i][j] = color;
    }
  }
  else {
    for(int i=y;i<y+4;i++){
      for(int j=x;j<x+2;j++) field[i][j] = color;
    }
  }
}

bool dfs(int x,int y){
  use[y][x] = true;
  if(x == gx && y == gy) return true;
  for(int i=0;i<4;i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(nx >= 0 && nx < w && ny >= 0 && ny < h && field[ny][nx] == field[sy][sx] && !use[ny][nx]) dfs(nx,ny);
  }
  return use[gy][gx];
}

int main() {
	while(cin >> w >> h, w) {
		memset(field, 0, sizeof(field));
		memset(use, false, sizeof(use));
		int scol = 0;
		cin >> sx >> sy >> gx >> gy;
		--sx; --sy; --gx; --gy;
		cin >> n;
		while(n--){
     		int c,d,x,y; cin >> c >> d >> x >> y; --x; --y;
      		make_map(x,y,d,c);
    	}
		if(dfs(sx, sy)) cout << "OK" << endl;
		else cout << "NG" << endl; 
	}
	return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}

int main()
{

	vector<int> a(3);
	cin >> a[0] >> a[1] >> a[2];

	sort(a.begin(), a.end());

	if (a[0] == a[1] && a[1] != a[2]) {
		cout << "Yes" << endl;
	}
	else if (a[0] != a[1] && a[1] == a[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	







	return 0;



}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define TEN(x) ((ll)1e##x)
const ll mod = TEN(9) + 7;
int main() {
	ll n; scanf("%lld", &n);
	ll sum = 1, num = 0;
	while (n--) {
		ll a; scanf("%lld", &a);
		num++;
		if (a / 2 + a % 2 < num) {
			sum = sum * num % mod;
			num--;
		}
	}
	while (num--) sum = sum * (num + 1) % mod;
	printf("%lld\n", sum);
}

Measured memory_bytes: 256
import fractions

def lcm(a, b):
  return (a * b) / fractions.gcd(a, b)

N = int(input())
A = list(map(int, input().split()))

g = []
for index, a in enumerate(A):
  if index == len(A) - 1:
    break
  g.append(fractions.gcd(a, A[index+1]))
  
  
print(min(g))

Measured memory_bytes: 16280
N, Y = map(int, input().split())
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if 0 <= z <= 2000 and 10000*x + 5000*y + 1000*z == Y:
            print(x, y, z)
            exit()
print(-1, -1, -1)

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>

#define rep_ui(k,n)      for(ui  i = (k); i < (n); ++i)
#define rep_si(k,n)      for(int i = (k); i < (n); ++i)
#define rep_ul(k,n)      for(ul  i = (k); i < (n); ++i)
#define rep_sl(k,n)      for(ll  i = (k); i < (n); ++i)
#define rep_ui_down(k,n) for(ui  i = (k); i > (n); --i)
#define rep_si_down(k,n) for(int i = (k); i > (n); --i)
#define rep_ul_down(k,n) for(ul  i = (k); i > (n); --i)
#define rep_sl_down(k,n) for(ll  i = (k); i > (n); --i)

#define rep_uj(k,n)      for(ui  j = (k); j < (n); ++j)
#define rep_sj(k,n)      for(int j = (k); j < (n); ++j)
#define rep_uj_down(k,n) for(ui  j = (k); j > (n); --j)
#define rep_sj_down(k,n) for(int j = (k); j > (n); --j)

#define rep(k,n)         rep_ui(k,n)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

template<class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vc)
{
  for (auto it = vc.begin(); it != vc.end(); ++it)
  {
    if (std::next(it) == vc.end())
      os << *it;
    else
      os << *it << ' ';
  }
  return os;
}

template<class T1, class T2>
inline
std::ostream & operator<<(std::ostream & os, const std::pair<T1, T2> & p)
{
  return os << p.first << ' ' << p.second;
}

void solve(void)
{
  using std::string;
  using std::vector;
  using std::map;
  using std::pair;
  using std::cin;
  using std::cout;
  ui N{}, K{}; std::cin >> N >> K;
  vector<ll> v(N);
  rep(0, N) cin >> v[i];
  auto it = boost::lower_bound(v, 0);
  ui num = std::distance(v.begin(), it);

  auto cmp = [](ll a, ll b){
    return (a < 0 && b < 0) || (a >= 0 && b >= 0);
  };
  vector<ll> res;
  res.reserve(K);
  rep(0, K + 1)
  {
    if(num < i) break;
    ui it = num - i;
    ui max = it + K - 1;
    if(max >= N) continue;
    ll x = v[it];
    ll y = v[max];
    ll ux = std::abs(x);
    ll uy = std::abs(y);
    if(cmp(x, y))
    {
      res.push_back(std::max(ux, uy));
    }
    else
    {
      auto r0 = ux*2 + uy;
      auto r1 = ux + uy*2;
      res.push_back(std::min(r0, r1));
    }
  }

  auto ans = *boost::min_element(res);
  cout << ans << '\n';
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 1408
#include<cctype>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
const int N=524288,P=924844033;
int n,lim,fac[N],ifac[N],rev[N],w[N],f[N],g[N];std::vector<int>e[N];
int read(){int x=0,c=getchar();while(isspace(c))c=getchar();while(isdigit(c))(x*=10)+=c&15,c=getchar();return x;}
void inc(int&a,int b){a+=b-P,a+=a>>31&P;}
int sub(int a,int b){return a-=b,a+=a>>31&P;}
int mul(int a,int b){return 1ll*a*b%P;}
int pow(int a,int k){int r=1;for(;k;k>>=1,a=mul(a,a))if(k&1)r=mul(a,r);return r;}
int C(int n,int m){return 1ll*fac[n]*ifac[m]%P*ifac[n-m]%P;}
void init()
{
    int p=(lim=1<<(33-__builtin_clz(n)))>>1,g=pow(5,(P-1)/lim);
    w[p]=fac[0]=1;
    for(int i=1;i<lim;++i) rev[i]=(rev[i>>1]>>1)|(i&1? p:0);
    for(int i=p+1;i<lim;++i) w[i]=mul(w[i-1],g);
    for(int i=p-1;i;--i) w[i]=w[i<<1];
    for(int i=1;i<=n;++i) fac[i]=mul(fac[i-1],i);
    ifac[n]=pow(fac[n],P-2);
    for(int i=n;i;--i) ifac[i-1]=mul(ifac[i],i);
}
int dfs(int u,int fa)
{
    int size=1,x;
    for(int v:e[u]) if(v^fa) ++f[x=dfs(v,u)],size+=x;
    return ++f[n-size],size;
}
void NTT(int*a,int f)
{
    if(!~f) std::reverse(a+1,a+lim);
    for(int i=1;i<lim;++i) if(i<rev[i]) std::swap(a[i],a[rev[i]]);
    for(int i=1;i<lim;i<<=1) for(int j=0,d=i<<1;j<lim;j+=d) for(int k=0,x;k<i;++k) x=mul(a[i+j+k],w[i+k]),a[i+j+k]=sub(a[j+k],x),inc(a[j+k],x);
    if(!~f) for(int i=0,x=P-(P-1)/lim;i<lim;++i) a[i]=mul(a[i],x);
}
int main()
{
    n=read(),init();
    for(int i=1,u,v;i<n;++i) u=read(),v=read(),e[u].push_back(v),e[v].push_back(u);
    dfs(1,0),f[0]=0;
    for(int i=1;i<=n;++i) f[i]=mul(f[i],fac[i]);
    std::reverse(f,f+n+1),memcpy(g,ifac,(n+1)<<2),NTT(f,1),NTT(g,1);
    for(int i=0;i<lim;++i) f[i]=mul(f[i],g[i]);
    NTT(f,-1),std::reverse(f,f+n+1);
    for(int i=1;i<=n;++i) printf("%d\n",sub(mul(n,C(n,i)),mul(f[i],ifac[i])));
}


Measured memory_bytes: 40960
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
using System.Diagnostics;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    private long NextLong()
    {
        return long.Parse(Next());
    }
}

class Magatro
{
    private int N, K;
    private int[] X, Y;
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        X = new int[N];
        Y = new int[N];
        for (int i = 0; i < N; i++)
        {
            X[i] = sc.NextInt();
            Y[i] = sc.NextInt();
        }
    }

    private long Ans(int i, int j, int k, int l)
    {
        int MaxX = Math.Max(X[i], Math.Max(X[j], Math.Max(X[k], X[l])));
        int MinX = Math.Min(X[i], Math.Min(X[j], Math.Min(X[k], X[l])));
        int MaxY = Math.Max(Y[i], Math.Max(Y[j], Math.Max(Y[k], Y[l])));
        int MinY = Math.Min(Y[i], Math.Min(Y[j], Math.Min(Y[k], Y[l])));
        int cnt = 0;
        for (int n = 0; n < N; n++)
        {
            bool a = MinX <= X[n] && X[n] <= MaxX;
            bool b = MinY <= Y[n] && Y[n] <= MaxY;
            if (a && b)
            {
                cnt++;
            }
        }
        if (cnt >= K)
        {
            return (long)(MaxX - MinX) * (MaxY - MinY);
        }
        return long.MaxValue;
    }




    public void Solve()
    {
        Scan();

        long ans = long.MaxValue;
        for (int i = 0; i < N; i++)
        {
            for (int j = i; j < N; j++)
            {
                for (int k = j; k < N; k++)
                {
                    for (int l = k; l < N; l++)
                    {
                        ans = Math.Min(ans, Ans(i, j, k, l));
                    }
                }
            }
        }
        Console.WriteLine(ans);
    }

    static public void Main()
    {
        new Magatro().Solve();

    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 1000010
using namespace std;

int main(){
  string s;
  int k;
  cin >> s >> k;
  int dp[110][10][2] = {0};
  int n = s.size();
  
  dp[0][0][0] = 1;
  REP(i,n) {
    REP(j,k+1) {
      if(s[i] == '0') {
        dp[i+1][j][0] = dp[i][j][0];
      } else {
        dp[i+1][j+1][0] += dp[i][j][0];
        dp[i+1][j][1] += dp[i][j][0];
        dp[i+1][j+1][1] += (ll)(s[i]-'1') * dp[i][j][0]; 
      }
      
      dp[i+1][j][1] += dp[i][j][1];
      dp[i+1][j+1][1] += dp[i][j][1] * 9;
    }
  }
  
  cout << dp[n][k][0] + dp[n][k][1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[3][3],n;
    for(int i=0;3>i;++i){
        for(int j=0;3>j;++j)
        scanf("%d",&a[i][j]);
    }
    scanf("%d",&n);
    int b[n];
    for(int i=0;n>i;++i)
    scanf("%d",&b[i]);
    for(int i=0;3>i;++i){
        for(int j=0;3>j;++j){
            for(int k=0;n>k;++k){
                if(b[k]==a[i][j])
                a[i][j]=0;
            }
        }
    }
    if((a[0][0]==a[0][1]&&a[0][1]==a[0][2])||(a[1][0]==a[1][1]&&a[1][1]==a[1][2])||(a[2][0]==a[2][1]&&a[2][1]==a[2][2])||(a[0][0]==a[1][0]&&a[1][0]==a[2][0])||(a[0][1]==a[1][1]&&a[1][1]==a[2][1])||(a[0][2]==a[1][2]&&a[1][2]==a[2][2])||(a[0][0]==a[1][1]&&a[1][1]==a[2][2])||(a[0][2]==a[1][1]&&a[1][1]==a[2][0]))
    printf("Yes");
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──████AJ████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/

#include<bits/stdc++.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long

int N;
const int maxN = 401;
// ll dp[maxN][maxN];
ll a[maxN];

// ll getMax(int start, int end) {
// 	if (start == end) return 0;
// 	if (dp[start][end] != -1) return dp[start][end];

// 	ll result = LLONG_MAX;
// 	ll sum = 0;
// 	for (int i = start; i <= end; i++) {
// 		sum += a[i];
// 	}
// 	for (int i = start; i < end; i++) {
// 		ll r1 = getMax(start, i);
// 		ll r2 = getMax(i + 1, end);
// 		result = min(result, r1 + r2 + sum);
// 	}

// 	return dp[start][end] = result;
// }

ll bottomUp() {
	ll dp[N][N];
	for (int i = 0; i < N; i++) {
		dp[i][i] = 0;
	}

	for (int L = 2; L <= N; L++) {
		for (int start = 0; start <= N - L; start++) {
			int end = start + L - 1;
			dp[start][end] = LLONG_MAX;
			ll sum = 0;
			for (int i = start; i <= end; i++) {
				sum += a[i];
			}
			for (int k = start; k < end; k++) {
				dp[start][end] = min(dp[start][end], dp[start][k] + dp[k + 1][end] + sum);
			}
		}
	}
	// for (int i = 0; i < N; i++) {
	// 	for (int j = 0; j < N; j++) {
	// 		cout << dp[i][j] << " ";
	// 	}
	// 	cout << endl;
	// }

	return dp[0][N - 1];
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	// memset(dp, -1, sizeof(dp));
	// ll res = getMax(0, N - 1);
	ll res = bottomUp();
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr int MOD = 998244353;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(n); return n < 0 ? 0 : I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

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

int main() {
    int N, M, K; cin >> N >> M >> K;
    mint ans = 0;
    for (int i = 0; i <= K; i++) {
        ans += C(N - 1, i) * modpow(M - 1, N - 1 - i) * M;
    }
    cout << ans << endl;
}

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

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

using namespace std;

int main(){
  int N, x;
  cin >> N >> x;
  int a[N];
  rep(i, N)
    cin >> a[i];
  //入力終了

  //a[i]が小さい子供から処理
  sort(a, a+N);

  int ans = 0;
  rep(i, N-1){
    //a[i]よりも多くお菓子を持っていれば，丁度配れば良い
    if(a[i] <= x){
      ans++;
      x -= a[i];
    }
  }

  //ちょうどa[i]個貰わなければならないことに注意する
  if(a[N-1] == x)
    ans++;

  //解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3568
#include<stdio.h>
#define MAX 100
#define INFTY (1<<21)
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n,M[MAX][MAX];

void dijkstra(){
  int i,v,minv;
  int d[MAX],color[MAX];

  for(i = 0; i< n ; i++){
    d[i] = INFTY;
    color[i] = WHITE;
  }

  d[0] = 0;
  color[0] = GRAY;
  while(1){
    minv = INFTY;
    int u = -1;
    for(i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;
    for(v = 0; v<n ; v++){
      if(color[v] != BLACK && M[u][v] !=INFTY){
	if(d[v] > d[u] + M[u][v]){
	  d[v] = d[u]+M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  for(i = 0; i<n; i++){
    printf("%d %d\n",i,(d[i] == INFTY?-1:d[i]));
  }
}


int main(){
  int i,j;
  scanf("%d",&n);
  for(i = 0; i<n; i++){
    for(j = 0; j<n; j++){
      M[i][j] = INFTY;
    }
  }

  int k,c,u,v;
  for(i = 0; i<n; i++){
    scanf("%d%d",&u,&k);
    for(j = 0; j < k; j++){
      scanf("%d%d",&v,&c);
      M[u][v] = c;
    }
  }
  dijkstra();

  return 0;
}



Measured memory_bytes: 2112
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#include <cctype>
#include <locale>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ

signed main(){
    ll a,b,c; cin >> a >> b >> c;
    ll res=0;
    rep(i,1001001){
        res+=a;
        if(res%b==c){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
}




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

int main() {
  
  int a,b,c;
  int N;
  cin >> N;
    a = N / 100;
    N = N % 100;
    b = N / 10;
    N = N % 10;
    c = N;
  cout << a + b + c << endl; 
}



Measured memory_bytes: 256
package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}

func Solve() {
  N := NextLine()
  DP := make([][]int, len(N) + 1)
  for i := range DP {
    DP[i] = make([]int, 2)
  }
  DP[0][1] = 1
  for i, n := range N {
    c := int(n) - int('0')
    DP[i + 1][0] = MinInt(DP[i][0] + c, DP[i][1] + 10 - c)
    DP[i + 1][1] = MinInt(DP[i][0] + c + 1, DP[i][1] + 9 - c)
  }
  Write(DP[len(N)][0])
  return
}

func main() {
  Solve()
  Output()
}

Measured memory_bytes: 44312
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define Rep(i,n) for (int i = (int)(n); i >= 0; i--)
#define all(vec) vec.begin(),vec.end()
#define rever(vec) reverse(all(vec));
#define cend cout << endl;
#define prique(T) priority_queue<T, vector<T>, greater<T>>
struct edge { int to, cost; };
typedef pair<int, int> P;
const int mod = 1e9 + 7, inf = 1e16;
 
int modpow(int x, int n) {
	if (n == 0) return 1;
	if (n & 1) return (x * modpow(x * x % mod, n / 2) % mod + mod) % mod;
	return (modpow(x * x % mod, n / 2) + mod) % mod;
}
 
int fact(int n) {
	int ans = 1;
	rep(i, n) {
		ans *= (i + 1);
		ans %= mod;
	}
	return (ans + mod) % mod;
}
 
int comb(int n, int r) {
	if (n < r) swap(n, r);
	if (n - r < r) r = n - r;
	return fact(n) * modpow(fact(n - r), mod - 2) % mod * modpow(fact(r), mod - 2) % mod;
}
 
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
 
int lcm(int a, int b) {
	return a * b / gcd(a, b);
}
 
bool pri(int p) {
	for (int i = 2; i * i <= p; i++) if (p % i == 0) return false;
	return p > 1;
}

int n, k, ans;
signed main() {
	cin >> n >> k;
	ans = pow(n / k, 3);
	if((k & 1) == 0) {
		ans += pow((n + k / 2) / k, 3);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
ll = list(map(int, input().split()))


def bubble_sort(a, n):
    flag = True
    count = 0
    while flag:
        flag = False
        for i in range(n-2, -1, -1):
            if a[i] > a[i+1]:
                a[i], a[i+1] = a[i+1], a[i]
                flag = True
                count += 1
    print(" ".join(map(str, a)))
    print(count)


bubble_sort(ll, n)


Measured memory_bytes: 5600
/**
 * Heaps - Complete Binary Tree
 */

#include <iostream>

using namespace std;

int main() {

    int H, A[502];

    cin >> H;

    for (int i = 1; i <= H; i++) {
        cin >> A[i];
    }

    for (int i = 1; i <= H; i++) {
        int parent, left, right;
        parent = i / 2;
        left = i * 2;
        right = i * 2 + 1;
        printf("node %d: key = %d, ", i, A[i]);
        if (parent) printf("parent key = %d, ", A[parent]);
        if (left <= H) printf("left key = %d, ", A[left]);
        if (right <= H) printf("right key = %d, ", A[right]);
        cout << endl;
    }
}


Measured memory_bytes: 3128
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        String s = in.next();
        String t = in.next();
        int a = in.nextInt();
        int b = in.nextInt();
        String u = in.next();

        if (s.equals(u)) {
            a--;
        } else {
            b--;
        }

        out.println(a + " " + b);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<bitset>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+8
#define EPS 1e-8
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = (j); i < (k); i++)
int rules[12];
int ans;
int stage[12][10001];

int simulate(int R,int C){
	int res  = 0;
	rep(i,R){
		if( rules[i] == 1){
			rep(j,C)stage[i][j] = 1-stage[i][j];
		}
	}
	rep(j,C){
		int sum = 0;
		rep(i,R){
			sum += stage[i][j];
		}
		res += max(sum,R-sum);
	}
	rep(i,R){
		if( rules[i] == 1){
			rep(j,C)stage[i][j] = 1-stage[i][j];
		}
	}
	return res;
}
void pattern(int dep,int R,int C){
	if(dep == R){
		ans = max(ans,simulate(R,C));
		return ;
	}
	rules[dep] = 1;
	pattern(dep+1,R,C);
	rules[dep] = 0;
	pattern(dep+1,R,C);
}
int main(){
	int R,C;
	while(scanf("%d%d",&R,&C),R){
		memset(stage,0,sizeof(stage));
		memset(rules,0,sizeof(rules));
		ans = 0;
		rep(i,R){
			rep(j,C){
				int tmp;
				scanf("%d",&tmp);
				stage[i][j] = tmp;
			}
		}
		pattern(0,R,C);
		printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
    int n, l[3];
    scanf("%d", &n);
    while(n--) {
        scanf("%d %d %d", &l[0], &l[1], &l[2]);
        sort(l, l + 3);
        if (l[0]*l[0] + l[1]*l[1] == l[2] * l[2]) {
            puts("YES");
        } else {
            puts("NO");
        }
    }
    return 0;
}


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

const int maxn = 1e5+7;
const int inf = 1e9+7;

int n, k;
int h[maxn];
int dp[maxn];

int main(int argc, char *argv[]) {  
	std::cin >> n >> k;
	for (int i = 0; i < n; i++) {
		std::cin >> h[i];
	}
	std::fill(dp, dp+maxn, inf);
	dp[0] = 0;
	dp[1] = std::abs(h[1] - h[0]);
	for (int i = 2; i < n; i++) {
		for (int j = 1; j <= k && j <= i; j++) {
			dp[i] = std::min(dp[i-j] + std::abs(h[i]-h[i-j]), dp[i]);
		}
	}
	std::cout << dp[n-1] << '\n';
}

Measured memory_bytes: 1024
#![allow(non_snake_case)]
use proconio::{input, fastout};
use std::cmp::max;

#[fastout]
fn main() {
    input!{
        n:usize, k:i64,
        a: [i64; n]
    }
    let mut cnt = vec![0i64; 60];
    for &x in &a {
        for i in 0..60 {
            if (x >> i) & 1 > 0 {
                cnt[i] += 1;
            }
        }
    }
    let n = n as i64;
    let mut dp = vec![vec![-1, 0]; 61];
    for i in (0..60).rev() {
        if dp[i+1][0] >= 0 {
            dp[i][0] = dp[i+1][0] + (max(cnt[i], n - cnt[i]) << i);
        }
        if (k >> i) & 1 > 0 {
            dp[i][0] = max(dp[i][0], dp[i+1][1] + (cnt[i] << i));
            dp[i][1] = dp[i+1][1] + ((n - cnt[i]) << i);
        } else {
            dp[i][1] = dp[i+1][1] + (cnt[i] << i);
        }
    }
    println!("{}", max(dp[0][0], dp[0][1]))
}


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

int main(){
  int X;
  bool ans[1001];
  for(int i=0;i<1001;i++) ans[i] = false;
  ans[1] == true;
  for(int p=2;p<10;p++){
    for(int b=1;(int)pow(b,p)<1001;b++){
      ans[(int)pow(b,p)] = true;
    }
  }
  cin >> X;
  while(true){
    if(ans[X]){
      cout << X << endl;
      break;
    }
    X--;
  } 
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,t;
    cin>>n>>x>>t;
    for(int i=1;i>0;i++)
    {
        if(i*x>=n)
        {
            cout<<i*t;
            break;
        }
    }
	return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define in freopen("in.txt","r",stdin)
//#define out freopen("out.txt","w",stdout) 
ll n,m,k,t,l,r;
ll b,c,d;
char A,B,C,X,Y,Z;
ll ans,MAX,MIN=40,sum;
ll a[200050],f[200050];
//ll dp1[1000][1000],dp2[1000][1000];
char str[200050],bx[200050];


int main()
{
    ll i,s,j;
    t=1;
    //scanf("%lld",&t);
    while(t--)
    {
		cin>>n;
		ll x,y,z;
		for(i=1;i<=n;i++)
		{
			ll num=0;
			for(x=1;x<=150;x++)
			{
				for(y=1;y<=150;y++)
				{
					for(z=1;z<=150;z++)
					{
						sum=(x+y)*(x+y)+(y+z)*(y+z)+(x+z)*(x+z);
						if(sum==2*i) num++;
						if(sum>2*i) break;
					}
				}
			}
			printf("%lld\n",num);
		}
	}
	return 0;
}

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

int main() {
  int max = 0,c = 0;
  string s;
  cin >> s;
  s += 'E';
  for(int i = 0;i < s.size();i++){
    if((s.at(i) == 'A'||s.at(i) == 'C')||(s.at(i) == 'G'||s.at(i) == 'T')){
      c++;
    }
    else{
      if(c >= max){
        max = c;
      }
      c = 0;
    }
  }
  cout << max << endl;
}


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


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct solve
{
	solve(){}
	ll operator()(int n, string s) {
		int r=0, w=0;

		for(int i=0;i<n;i++)
		{
			if(s[i]=='R') r++;
			else w++;
		}

		int ans=min(r, w);

		int f=0, b=n-1, a=0;
		for(;;)
		{
			for(;s[f]=='R' && f<n;f++)
				;
			for(;s[b]=='W' && b>=0;b--)
				;
			if(f>b) break;
			f++;
			b--;
			a++;
		}
		min_u(ans, a);

		return ans;
	}
};

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

	for(;;)
	{
		int n;
		string s;
		cin >> n >> s;
		if(cin.fail()) break;


		cout << solve()(n, s) << "\n";
	}
	return 0;
}


Measured memory_bytes: 3876
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
#include <set>
#include <list>
#include <map>
#include <algorithm>
#include <typeinfo>
#define _USE_MATH_DEFINES
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

int n, q;
vector<int> A(2000);

int solve(int i, int v){
    if(v==0){
        return 1;
    }
    if(i>=n){
        return 0;
    }
    int res;
    if(A[i]<=v){
        res = solve(i+1, v) || solve(i+1, v-A[i]);
    }else{
        res = solve(i+1, v);
    }
    return res;
}

int main(){

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> A[i];
    }

    cin >> q;
    for(int i=0; i<q; i++){
        int M;
        cin >> M;
        if(solve(0, M)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }

    return 0;
}



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

int main() {
    int a;
    int t[100010], x[100010], y[100010];
    cin >> a;
    t[0] = x[0] = y[0] = 0;  
    for (int i = 0; i < a; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  

    bool can = true;
    for (int i = 0; i < a; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false;
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define ll long long

using namespace std;

const int N = (int)2e5 + 7;

int k, n;
int a[N];

main() {
  scanf("%d %d", &k, &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int ans = min(a[n - 1] - a[0], a[0] + k - a[1]);
  for (int i = 1; i + 1 < n; i++) {
    int res = min(k - a[i] + a[i - 1], a[i] + k - a[i + 1]);
    ans = min(ans, res);
  }
  int res = min(a[n - 1] - a[0], k - a[n - 1] + a[n - 2]);
  ans = min(ans, res);
  cout << ans;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind z(n);
    vector<vector<int>> br(n);
    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        z.merge(x - 1, y - 1);
        br.at(x - 1).push_back(y - 1);
        br.at(y - 1).push_back(x - 1);
    }

    for (int i = 0; i < k; i++) {
        int x, y;
        cin >> x >> y;
        br.at(x - 1).push_back(y - 1);
        br.at(y - 1).push_back(x - 1);
    }
    for (int i = 0; i < n; i++) {
        int t = z.size(i);
        int p = br.at(i).size();
        for (int j = 0; j < p; j++) {
            int l = br.at(i).at(j);
            if (z.issame(i, l))t--;
        }
        cout << t-1;
        if (i == n - 1)break;
        cout << " ";

    }
    cout << endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int n,m;cin>>n>>m;
    vector<vector<int>> x(114514);
    rep(i,n) {
        int a,b;cin>>a>>b;
        x[a].push_back(b);
    }

    priority_queue<ll> pq;
    ll ans = 0;

    for (int i = 1; i <= m; ++i) {
        for (auto &&e: x[i]) pq.push(e);
        if (!pq.empty()) ans += pq.top(), pq.pop();
    }

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


Measured memory_bytes: 6016
N = int(input())
A = list(map(int, input().split()))

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

tmp = judge(tmp_one, tmp_two)
print(tmp)


Measured memory_bytes: 14484
n, q = gets.chomp.split.map(&:to_i)
stack = Array.new(n){[]}
q.times{
    query = gets.chomp.split.map(&:to_i)
    case query[0]
    when 0
        stack[query[1]].push query[2]
    when 1
        puts stack[query[1]].last unless stack[query[1]].empty?
    when 2
        stack[query[1]].pop
    end
}



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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<unordered_set<int>> honests(N);
  vector<unordered_set<int>> liers(N);

  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    for (int j = 0; j < A; j++) {
      int x, y;
      cin >> x >> y;
      x--;
      if (y == 1) {
        honests[i].insert(x);
      } else {
        liers[i].insert(x);
      }
    }
  }

  int answer = 0;
  for (int i = 0; i < (1 << N); i++) {
    unordered_set<int> current_honests;
    unordered_set<int> current_liers;
    for (int j = 0; j < N; j++) {
      if (i & (1 << j)) {
        current_honests.insert(j);
        for (int h : honests[j]) current_honests.insert(h);
        for (int l : liers[j]) current_liers.insert(l);
      } else {
        current_liers.insert(j);
      }
    }

    bool ok = true;
    for (int h : current_honests) {
      if (current_liers.count(h)) {
        ok = false;
        break;
      }
    }

    for (int l : current_liers) {
      if (current_honests.count(l)) {
	ok = false;
	break;
      }
    }

    if (ok) {
      answer = max(answer, __builtin_popcount(i));
    }
  }
  cout << answer << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>
 
int main() {
    char str[1002];
    int i, sum;
    while (fgets(str, 1002, stdin) && str[0] != '0') {
        sum = 0;
        for (i = 0; str[i] != '\n'; i++) {
            sum += str[i] - 48;
        }
        printf("%d\n", sum);
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
const ll mod = 1e9+7;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

ll pow_mod(ll a,ll b) {
    ll ret;
    if (b < 0) ret = pow_mod(a,mod+b-1);
    else if (b == 0) ret = 1;
    else if (b == 1) ret = a;
    else {
        ll c = pow_mod(a,b/2);
        if (b%2) ret = (c*c)%mod*a%mod;
        else ret = c*c%mod;
    }
    return ret;
}

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> s(n),t(m);
    for (int i = 0;i < n;++i) cin >> s[i];
    for (int i = 0;i < m;++i) cin >> t[i];
    vector<vector<ll>> dp(n+1,vector<ll>(m+1,0));
    for (int i = 0;i < n+1;++i) dp[i][0] = 1;
    for (int i = 0;i < m+1;++i) dp[0][i] = 1;
    // dp[0][0] = 1;
    for (int i = 0;i < n;++i) {
        for (int j = 0;j < m;++j) {
            if (s[i] == t[j]) {
                dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j])%mod;
            } else {
                dp[i+1][j+1] = (dp[i][j+1]+dp[i+1][j]-dp[i][j])%mod;
            }
        }
    }
    
   /*
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) {
        if (s[i] == t[j]) dp[i+1][j+1] = max(max(dp[i][j+1],dp[i+1][j]),dp[i][j]+1);
        else dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
    }
    ll ans = 0;
    for (int i = 0;i < n;++i) for (int j = 0;j < m;++j) if (s[i] == t[j]) {
        (ans += (pow_mod(2,dp[i+1][j+1]-1))) %= mod;
    }*/
    // cout << ans << endl;
    // for (int i = 0;i < n+1;++i) p_ary(dp[i],0,m+1,j);
    cout << (dp[n][m]+mod)%mod << endl;
    return 0;
}

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

static const int MAX_N = 200000;

struct Relay_List {

	Relay_List *next;
	Relay_List *prev;
	bool live;

};

Relay_List RL[MAX_N];

int main()
{

	int N, M, Q, a, q;

	cin >> N >> M >> Q;
	for( int i = 0; i < N; i++ ) {

		RL[i].next = &RL[i == N - 1 ? 0		: i + 1];
		RL[i].prev = &RL[i == 0		? N - 1 : i - 1];
		RL[i].live = true;

	}

	Relay_List *checkRL1, *checkRL2;

	checkRL1 = &RL[0];
	checkRL2 = checkRL1;

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

		cin >> a;
		if( !( a % 2 ) ) {
			for( int j = 0; j < a; j++ ) checkRL1 = checkRL1->next;
			checkRL2 = checkRL1->prev;
		}
		else {
			for( int j = 0; j < a; j++ ) checkRL1 = checkRL1->prev;
			checkRL2 = checkRL1->prev;
		}

		checkRL1->live = false;
		checkRL1 = checkRL1->next;

		checkRL1->prev = checkRL2;
		checkRL2->next = checkRL1;

	}

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

		cin >> q;
		cout << ( RL[q].live ? 1 : 0 ) << endl;

	}

	return 0;

}

Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    string s;
    cin>>s;

    if(s[0]==s[1]||s[1]==s[2]||s[2]==s[3])cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct point{
	int x;
	int y;
	int step;
};
const int MAX=1e9;
char mp[801][801];
int cnt[801][801];
bool visit[801][801];
int h,w,k;
bool ifok;
int step;
int dirx[4]={0,1,0,-1};
int diry[4]={1,0,-1,0};
void bfs(int sx,int sy)
{
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cnt[i][j]=MAX;
		}
	}
	queue<point> q;
	cnt[sx][sy]=0;
	point start;
	start.x=sx;
	start.y=sy;
	start.step=0;
	visit[sx][sy]=0;
	q.push(start);
	while(!q.empty())
	{
		point now=q.front();
		q.pop();
		step=max(step,now.step);
		for(int i=0;i<4;i++)
		{
			int dx=dirx[i]+now.x;
			int dy=diry[i]+now.y;
			if(dx>=1&&dx<=h&&dy>=1&&dy<=w)
			{
				if(visit[dx][dy]&&mp[dx][dy]!='#')
				{
//					cout<<dx<<" "<<dy<<endl;
					point next;
					next.step=now.step+1;
					next.x=dx;
					next.y=dy;
					visit[dx][dy]=0;
					cnt[dx][dy]=next.step;
					q.push(next);
				}
			}
		}
//		cout<<q.size()<<endl;
//		system("PAUSE");
	}
}
int main()
{
//	freopen("cin.txt","r",stdin);
	cin>>h>>w>>k;
	int sx,sy;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin>>mp[i][j];
			if(mp[i][j]=='S')
			{
				sx=i;
				sy=j;
			}
		}
	}
/*	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cout<<mp[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<h<<" "<<w<<endl;
	cout<<sx<<" "<<sy<<endl;*/
	if(sx==1||sx==h||sy==1||sy==w)
	{
		cout<<0<<endl;
		return 0;
	}
	memset(visit,1,sizeof(visit));
	bfs(sx,sy);
/*	cout<<step<<endl;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cout<<cnt[i][j]<<" ";
		}
		cout<<endl;
	}*/
/*	if(ifok)
	{
		cout<<(step+k-1)/k<<endl;
		return 0;
	}
	else*/
	int ans=1<<30;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			if(cnt[i][j]<=k)
			{
				int least=min(min(i-1,j-1),min(h-i,w-j));
				int times=(least+k-1)/k;
				ans=min(ans,times+1); 
			}
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3968
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b = sc.nextInt();
		int c=sc.nextInt();
		if(a+b>=c)
			System.out.print("Yes");
		else
			System.out.print("No");
	}

}


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

int main()
{
	int n,s[100],max,min,nmax,nmin,ret;
	while (cin >> n, n) {
		for(int i = 0;i < n;i++) {
			cin >> s[i];
		}
		min = 1000;
		max = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] > max){
				max = s[i];
				nmax = i;
			}
			if (s[i] < min) {
				min = s[i];
				nmin = i;
			}
		}
		s[nmax] = s[nmin] = 0;
		ret = 0;
		for (int i = 0; i < n; i++) {
			ret += s[i];
		}
		cout << ret / (n - 2) << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Main {
    /**
     * Iterate through each line of input.
     */
    int[] array;
    String answer = "";

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run(){
        Scanner sc = new Scanner(System.in);
        char[] input = sc.next().toCharArray();
        array = new int[input.length];

        for(int i=0; i<input.length; i++){
            array[i] = Character.getNumericValue(input[i]);
        }

        dfs(0, array[0], String.valueOf(array[0]));
        System.out.println(answer);
    }

    void dfs(int x, int sum, String ans){
        if(x == 3){
            if(sum == 7){
                for(int i=x; i<array.length-1; i++){
                    ans += "+0";
                }
                answer = ans + "=7";
                return;
            }
        } else {
            dfs(x+1, sum + array[x+1], ans + "+" + array[x+1]);
            dfs(x+1, sum - array[x+1], ans + "-" + array[x+1]);
        }
    }
}


Measured memory_bytes: 21844