akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int[] G => ReadLine().Split().Select(int.Parse).ToArray();
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int V, Mod;
	List<int>[] es;
	void Solve()
	{
		var I = G;
		V = I[0];
		Mod = I[1];
		es = new List<int>[V];
		for (var u = 0; u < V; u++) es[u] = new List<int>();
		for (var e = 0; e < V - 1; e++)
		{
			I = G;
			es[I[0] - 1].Add(I[1] - 1);
			es[I[1] - 1].Add(I[0] - 1);
		}
		var dp0 = DFS0(0, -1);
		var dp1 = DFS1(0, dp0);
		for (var u = 0; u < V; u++) WriteLine(dp0[u] * (dp1[u] + 1) % Mod);
	}
	long[] DFS0(int u, int p)
	{
		var dp0 = new long[V];
		var st = new Stack<object>();
		st.Push(new A0 { u = u, p = p });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is A0)
			{
				var g = (A0)f;
				es[g.u].Remove(g.p);
				st.Push(new A1 { u = g.u });
				foreach (var v in es[g.u]) st.Push(new A0 { u = v, p = g.u });
			}
			else
			{
				var g = (A1)f;
				dp0[g.u] = 1L;
				foreach (var v in es[g.u]) dp0[g.u] = dp0[g.u] * (dp0[v] + 1) % Mod;
			}
		}
		return dp0;
	}
	long[] DFS1(int u, long[] dp0)
	{
		var dp1 = new long[V];
		var st = new Stack<object>();
		st.Push(new B0 { u = u });
		while (st.Count > 0)
		{
			var f = st.Pop();
			if (f is B0)
			{
				var g = (B0)f;
				var W = es[g.u].Count;
				var x = new long[W + 1];
				var y = new long[W + 1];
				x[0] = y[W] = 1;
				for (var i = 0; i < W; i++) x[i + 1] = x[i] * (dp0[es[g.u][i]] + 1) % Mod;
				for (var i = W - 1; i >= 0; i--) y[i] = y[i + 1] * (dp0[es[g.u][i]] + 1) % Mod;
				for (var i = 0; i < W; i++) dp1[es[g.u][i]] = (dp1[g.u] + 1) * x[i] % Mod * y[i + 1] % Mod;
				x = y = null;
				st.Push(new B1 { u = g.u, i = 0 });
			}
			else
			{
				var g = (B1)f;
				if (g.i < es[g.u].Count)
				{
					st.Push(new B1 { u = g.u, i = g.i + 1 });
					st.Push(new B0 { u = es[g.u][g.i] });
				}
			}
		}
		return dp1;
	}
}
struct A0 { public int u, p; }
struct A1 { public int u; }
struct B0 { public int u; }
struct B1 { public int u, i; }


Measured memory_bytes: 36328
using System;
using System.Collections.Generic;
using System.Linq;
// using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
            // List<long> kl=new List<long>(hs.Keys);
            // kl.Sort();
            // foreach(long k in kl){
            //     s[1]-=hs[k];
            //     if(s[1]<1){Console.WriteLine("{0}",k);break;}
            // }
            char[] c1 = s[0].ToCharArray();
            char[] c2 = s[1].ToCharArray();
            char[] c3 = s[2].ToCharArray();
            Console.WriteLine(c1[c1.Length-1]==c2[0]&&c2[c2.Length-1]==c3[0]?"YES":"NO");
        }
        //最小公倍数
        static long Lcm(long a, long b)
        {
            return a/Gcd(a,b)*b;
        }

        //最大公約数
        static long Gcd(long m, long n)
        {
            if(n==0)return m;
            return Gcd(n,m%n);
        }
    }
}

Measured memory_bytes: 11092
#pragma GCC target("avx2,avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
//#include <atcoder/all>
//using namespace atcoder;
//using mint = modint998244353;
//using mint = modint1000000007;
#include <bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//using i128 = __int128_t;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
constexpr char ln = '\n';
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) {if (a < b) {a = b; return true;} return false;}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) {if (a > b) {a = b; return true;} return false;}
inline int topbit(int x) {return x == 0 ? -1 : 31-__builtin_clz(x);}
inline int topbit(long long x) {return x == 0 ? -1 : 63-__builtin_clzll(x);}
inline int botbit(int x) {return x == 0 ? 32 : __builtin_ctz(x);}
inline int botbit(long long x) {return x == 0 ? 64 : __builtin_ctzll(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
inline int kthbit(long long x, int k) {return (x>>k)&1;}
inline void print() {cout << "\n";}
template<class T>
inline void print(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cout << *itr << " ";
    print();
}
template<class T, class... Args>
inline void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
#ifdef MINATO_LOCAL
#define dump(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
inline void debug() {cerr << endl;}
template<class T>
inline void debug(const vector<T> &v) {
    for (auto itr = v.begin(); itr != v.end(); ++itr) cerr << *itr << " ";
    debug();
}
template<class T, class... Args>
inline void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
#else
#define dump(x) void(0)
inline void debug() {}
template<class T> inline void debug(const vector<T> &v) {}
template<class T, class... Args> inline void debug(const T &x, const Args &... args) {}
#endif
struct Fast_ios {Fast_ios() {cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20);};} fast_ios;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    int N; cin >> N;
    vector<ll> x(N),y(N);
    rep(i,N) cin >> x[i] >> y[i];

    vector<ll> a(N),b(N);
    rep(i,N) a[i] = x[i]+y[i];
    rep(i,N) b[i] = x[i]-y[i];

    sort(all(a)); sort(all(b));
    ll ans = max(a.back()-a[0],b.back()-b[0]);
    cout << ans << ln;
}


Measured memory_bytes: 9528
#include<iostream>
#include<cstring>
using namespace std;
long long a[401];
long long dp[401][401],h[401][401];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	memset(dp,0x3f,sizeof(dp));
	for(int len=1;len<=n;len++)
		for(int i=1;i<=n;i++)
		{
			int j=i+len-1;
			if(j>n)continue;
			if(i==j)dp[i][j]=0;
			h[i][j]=h[i][j-1]+a[j];
			for(int k=i;k<j;k++)
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+h[i][k]+h[k+1][j]);
		}
	cout<<dp[1][n];
	return 0;
}

Measured memory_bytes: 6140
<?php
fscanf(STDIN, "%d", $n);
$a = explode(' ', trim(fgets(STDIN)));
$x = 0;
while (1) {
	for ($i = 0; $i < $n; $i++) {
		if ($a[$i] % 2) exit("$x");
		$a[$i] /= 2;
	}
	$x++;
}

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

ll combi2(ll a) {
	return a*(a - 1)/2;
}

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a.at(i);

	vector<int> b(n, 0);
	for (int i = 0; i < n; i++) {
		b.at(a.at(i) - 1)++;
	}
	ll tot = 0;
	for (int j = 0; j < n; j++) {
		if (b.at(j) - 1) {
			tot += combi2(b.at(j));
		}
	}
	ll ans = tot;
	for (int i = 0; i < n; i++) {
		ans -= combi2(b.at(a.at(i) - 1));
		b.at(a.at(i) - 1)--;
		ans += combi2(b.at(a.at(i) - 1));
		cout << ans << endl;
		ans = tot;
		b.at(a.at(i) - 1)++;
	}
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y);
#define chmin(x,y) x = min(x,y);
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};
const int INF = 1001001001;



int main() {
    int a, b;
    cin >> a >> b;
    if (a%2 != 0 && b%2 != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main(){
  int n;
  cin>>n;
  int cnt=0;
  rep(i,n){
    int d1,d2;
    cin>>d1>>d2;
    if(d1==d2){
      cnt++;
      if(cnt==3){
	puts("Yes");
	return 0;
      }
    }
    else{
      cnt=0;
    }
  }
  puts("No");
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const ll INFL = 1e18+100;
const ll MOD = 1e9+7;
const bool debug = 0;
//-----------------------------------------------//

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || abs(a - b) <= d && abs(c - b) <= d) puts("Yes");
	else puts("No");
	return 0;
}

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

int main() {
  int ans = 0;
  int N;

  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;++i){
    cin >> vec.at(i);
  }

  for(int i=0;i<N-2;++i){
      for(int j=i+1;j<N-1;++j){
        for(int k=j+1;k<N;++k){
          if(vec.at(i) != vec.at(j) && vec.at(i) != vec.at(k) && vec.at(j) != vec.at(k)){
            if(vec.at(i) + vec.at(j) > vec.at(k) && vec.at(i) + vec.at(k) > vec.at(j) && vec.at(k) + vec.at(j) > vec.at(i)){
              ans += 1;
            }
          }
        }
      }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
let list_of_string s =
  let n = String.length s in
  let rec aux acc i =
    if i >= n then List.rev acc else aux (s.[i] :: acc) (i + 1)
  in
  aux [] 0

let () =
  let s = read_line () in
  let n = String.length s in
  let p = (n - 1) / 2 and q = (n + 3) / 2 in
  let ls_u = list_of_string s
  and ls_p = list_of_string (String.sub s 0 p)
  and ls_q = list_of_string (String.sub s (q - 1) (n - q + 1)) in
  if ls_u = List.rev ls_u && ls_p = List.rev ls_p && ls_q = List.rev ls_q then
    print_endline "Yes"
  else print_endline "No"


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

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    bool check = false;
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            if (i*j+(N-i)*(M-j)==K) check = true;
        }
    }
    if (check) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int A=sc.nextInt(), B=sc.nextInt();
		System.out.println(A>B ? (B==1) ? "Bob" : "Alice" : (A==B) ? "Draw" : (A==1) ? "Alice" : "Bob");
		sc.close();			
	}

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

}

Measured memory_bytes: 35692
#line 1 "GRL_1_A_abstract.test.cpp"
#define PROBLEM "https://onlinejudge.u-aizu.ac.jp/problems/GRL_1_A"

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define ALL(v) std::begin(v), std::end(v)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Aug 16 15:46:30 JST 2020
 **/

#define CALL_FROM_TEST
#line 1 "/Users/knshnb/competitive_programming/competitive_library/src/Graph/AbstractDijkstra.hpp"
template <class Dist, class Key, class Delta>  // Delta: Key, (Key, Dist -> void) -> void
std::map<Key, Dist> dijkstra(Key s, Delta delta) {
    std::map<Key, Dist> dist;
    using P = std::pair<Dist, Key>;
    std::priority_queue<P, std::vector<P>, std::greater<P>> q;
    q.push({dist[s] = Dist(), s});
    while (!q.empty()) {
        std::pair<Dist, Key> p = q.top();
        q.pop();
        if (dist[p.second] < p.first) continue;
        delta(p.second, [&](Key to, Dist d) -> void {
            if (dist.count(to) && dist[to] <= p.first + d) return;
            q.push({dist[to] = p.first + d, to});
        });
    }
    return dist;
}
#line 20 "GRL_1_A_abstract.test.cpp"
#undef CALL_FROM_TEST

signed main() {
    Int n, m, r;
    std::cin >> n >> m >> r;
    struct Edge {
        Int to, cost;
    };
    std::vector<std::vector<Edge>> g(n);
    REP(i, m) {
        Int s, t, d;
        std::cin >> s >> t >> d;
        g[s].push_back({t, d});
    }
    auto delta = [&](Int from, auto update) -> void {
        for (Edge& edge : g[from]) {
            update(edge.to, edge.cost);
        }
    };
    auto dist = dijkstra<Int>(r, delta);
    REP(i, n) {
        if (dist.count(i)) {
            std::cout << dist[i] << "\n";
        } else {
            std::cout << "INF\n";
        }
    }
}



Measured memory_bytes: 23560
a=input()
s=input()
s2=0
while s2!=s:
    count=0
    s2=s
    for i in s:
        if i=='(': count+=1
        elif i==')': count-=1
        if count<0: 
            s='('+s
            break
    count=0
    for i in s[::-1]:
        if i==')': count+=1
        elif i=='(': count-=1
        if count<0: 
            s=s+')'
            break
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, T;
    cin >> n >> T;
    int mx = 10000;
    rep(i, n) {
        int c, t;
        cin >> c >> t;
        if (t <= T) chmin(mx, c);
    }
    if (mx == 10000) cout << "TLE" << endl;
    else cout << mx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
template<class T> inline istream& operator >> (istream & c, vector<T> & A) {rep(i, A.size()) c >> A[i];return c;}
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long long n, d;
	cin >> n >> d;
	int ans = 0;
	rep(i, n) {
		long long x, y;
		cin >> x >> y;
		long long tmp = x * x + y * y;
		if (tmp <= d * d) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
str = input().split()
N = int(str[0])
K = int(str[1])

pro = []
q = 1

for i in range(N):
    for j in range(K):
        q = 2**j
        if (i+1)*q >= K:
            break
    pro.append((1/N) * (1/q))
    q = 1

ans = 0
for i in range(N):
    ans = ans + pro[i]

print(ans)

Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using gpp_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T, typename L> using gpp_map = tree<T, L, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T> using gpp_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;*/
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
//#define Add(x, y) x = (x + (y)) % mod
//#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, K; cin >> N >> K;
    string S; cin >> S;
    int d = 0;
    REP(i, N - 1) if(S[i] != S[i + 1]) d++;
    d = max(0LL, d - 2 * K);
    Out(N - 1 - d);

    return 0;
}


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

int t = 0;

typedef struct {
  int t1;
  int t2;
  int *v;
  int d;
  int k;
}DP;

void visit(DP *G, int i){
  int j;
  for(j=0; j<G[i].k; j++){
    if(G[G[i].v[j]-1].d > G[i].d || G[G[i].v[j]-1].d == -1){
      G[G[i].v[j]-1].d = 1 + G[i].d;
      visit(G, G[i].v[j]-1);
    }
  }

  return;
}

int main(){

  int n, i, j, u, k, l[100];
  DP *G;

  scanf("%d", &n);
  G = (DP *)malloc(sizeof(DP)*n);

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

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

  return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<string>
#include<cmath>
#include<cstdlib>
#include<vector>
#include<map>
#include<set>
#include<algorithm>

using namespace std;

int isp[55556];

int main(){
  int n;
  cin>>n;
  isp[0] = 1;
  isp[1] = 1;
  int cnt = 0;
  vector<int> vs;
  for(int i=2;i<55556;i++){
    if(isp[i] == 0){
      for(int j=i+i;j<55556;j+=i){
        isp[j] = 1;
      }
      if(i%5 == 1){
        vs.push_back(i);
      }
    }
  }
  for(int i=0;i<n;i++)cout<<vs[i]<<" ";cout<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
	int i,j,n,r,w,x,y,z;
	while(scanf("%d",&n) , n != 0){
		if(n%1111 == 0){printf("NA\n");continue;}
		r = 0;
		while(n != 6174){
			r++;
			for(i = 1;i <= 3;i++){
				for(j = 1;j <= 100;j*=10){
					x = (n/(j*10))%10;
					y = (n/j)%10;
					if(x < y){n-=(x*j*10+y*j);n+=(x*j+y*j*10);}
				}
			}
			w = (n/1000)%10;
			x = (n/100)%10;
			y = (n/10)%10;
			z = n % 10;
			n = 1000*w+100*x+10*y+z-1000*z-100*y-10*x-w;
		}
		printf("%d\n",r);
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a.at(i);
    map<int, int> mp;
    rep(i, n) {
        for(int j = -1; j <= 1; j++) {
            int k = a.at(i) + j;
            if(mp.count(k)) {
                mp.at(k)++;
            }
            else {
                mp[k] = 1;
            }
        }
    }
    int ans = 0;
    for(P i : mp) {
        ans = max(ans, i.second);
    }
    cout << ans << endl;
    return 0;
}

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

bool cmp(int a,int b){
	return a>b;
}
int main(){
	int n,k,x;
	cin>>n>>k;
	int a[200000+5]={0};
	for(int i=0; i<n; i++){
		cin>>x;
		a[x]++;
	}
	sort(a+1,a+200000+1,cmp);
	int count=0;
	for(int i=k+1; i<=200000; i++){
		count+=a[i];
	}
	cout<<count<<endl;
	
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

string s[51];
const int dx[]={-1,0,1,0},dy[]={0,-1,0,1};
int main(){
    int h,w;
    cin>>h>>w;
    rep(i,h) cin>>s[i];
    rep(i,h)rep(j,w)if(s[i][j]=='#'){
        bool flag=false;
        rep(k,4){
            int tx=j+dx[k],ty=i+dy[k];
            if(tx>=0&&ty>=0&&ty<h&&tx<w){
                if(s[ty][tx]=='#'){
                    flag=true;
                    break;
                }
            }    
        }
        if(!flag){
                cout<<"No"<<endl;
                return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

# N, L = stdin.readline().rstrip()
N, L = map(int, input().split(' '))
# print(N, L)
# N, L = 5, 2
# N, L = 3, -1
# N, L = 30, -50

min_value = L
max_value = L + N - 1

summation = L * N + sum(range(N))

if (min_value < 0) and (0 < max_value):
    pass
elif (min_value > 0):
    summation -= min_value
elif (max_value < 0):
    summation -= max_value
    
print(summation)

Measured memory_bytes: 3060
import numpy as np
N, M = map(int, input().split())
indices = []
for _ in range(M):
    _, *i = map(lambda n: int(n) - 1, input().split())
    indices.append(i)
P = tuple(map(int, input().split()))
print(sum(all(np.array(list(format(n, "0%db" % N)), dtype=np.int8)[indices[m]].sum() & 1 == P[m] for m in range(M)) for n in range(1 << N)))


Measured memory_bytes: 14428
#include <stdio.h>
#include <math.h>

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i,0,n)

typedef long long ll;

#define size (int)1e8+5

int isPrime(int num) {
    if (num == 2)return 1;
    if (num < 2 || num % 2 == 0)return 0;
    for (int i = 3; i * i <= num; i += 2) {
        if (num % i == 0)return 0;
    }
    return 1;
}

void solver() {

    int N;
    int tmp;
    int sum = 0;

    scanf("%d", &N);
    for (int i = 0; i < N; ++i) {
        scanf("%d", &tmp);
        if (isPrime(tmp) == 1) {
            sum++;
        }
    }

    printf("%d\n", sum);
}


int main() {
    solver();
    return 0;
}


Measured memory_bytes: 2036
import itertools
import numpy as np
import math

n, p = map(int, input().split())
if n != 1:
    table = [0] * (int(math.sqrt(p)) + 1)

    pl = []
    ans = 1

    for i in range(2, int(math.sqrt(p)) + 1):
        if table[i] == 0:
            pl.append(i)
            for j in range(i + i, int(math.sqrt(p)) + 1, i):
                table[j] = 1

    a = 0

    for i in range(len(pl)):
        q = p
        while q % pl[i] == 0:
            a += 1
            q = q / pl[i]
        ans = ans * (pl[i] ** (int(a//n)))
        a = 0
else:
    ans = p

print(ans)

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

using namespace std;

#define STREAM_IO ios_base::sync_with_stdio(false)
#define STREAM_IO_BUFFERED cin.tie(0); cout.tie(0)

typedef long long ll;
#define LL (ll)
typedef unsigned int uint;
#define UINT (uint)
typedef unsigned long long ull;
#define ULL (ull)

typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
#define mp make_pair

template <class T1, class T2> inline istream &operator>>(istream &in, pair <T1, T2> &pr) { in >> pr.first >> pr.second;	return in; }
template <class T1, class T2> inline ostream &operator<<(ostream &out, const pair <T1, T2> &pr) { out << pr.first << ' ' << pr.second; return out; }

typedef vector <int> vi;
typedef vector <ll> vl;
#define pb push_back
#define ppb pop_back
#define clr clear

template <class T> inline istream &operator>>(istream &in, vector <T> &v) { for (T &x : v) in >> x; return in; }
template <class T> inline ostream &operator>>(ostream &out, const vector <T> &v) { for (T &x : v) out << x << ' '; return out; }

template <class T> inline istream &operator>>(istream &in, set <T> &v) { T x; in >> x; v.insert(x); return in; }
template <class T> inline ostream &operator>>(ostream &out, set <T> &v) { for (T &x : v) out << x << ' '; return out; }

template <class T> inline istream &operator>>(istream &in, multiset <T> &v) { T x; in >> x; v.insert(x);  return in; }
template <class T> inline ostream &operator>>(ostream &out, multiset <T> &v) { for (T &x : v) out << x << ' '; return out; }

template <class T> void Write(const vector <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; }
template <class T> void Writeln(const vector <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; cout << char(10); }

template <class T> void Write(set <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; }
template <class T> void Writeln(set <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; cout << char(10); }

template <class T> void Write(multiset <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; }
template <class T> void Writeln(multiset <T> &v, char c = ' ') { for (const T &x : v) cout << x << c; cout << char(10); }

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

ll gcd(ll a, ll b) { while (b) { a %= b; swap(a, b); } return a; }
int gcd(int a, int b) { while (b) {	a %= b;	swap(a, b);	} return a; }

#define bitscnt(U) __builtin_popcountll(LL (U))

#define SZ(U) int((U).size())
#define all(U) (U).begin(), (U).end()
#define rall(U) (U).rbegin(), (U).rend()
#define imin(U) (U).begin()
#define gmin(U) (*imin(U))
#define imax(U) (--(U).end())
#define gmax(U) (*imax(U))
#define REV(U) reverse(all(U))
#define SORT(U) sort(all(U))
#define CLR(U) memset(U, 0, sizeof U)
#define ONES(U) memset(U, -1, sizeof U)
#define CPY(FROM, TO) memcpy(TO, FROM, sizeof TO)

void solve()
{
	int n, m, k;
	cin >> n >> m >> k;
	for (int i(0); i <= n; ++i)
		for (int j(0); j <= m; ++j)
			if (i * (m - j) + j * (n - i) == k)
			{
				cout << "Yes\n";
				return;
			}
	cout << "No\n";
	return;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	STREAM_IO;
	STREAM_IO_BUFFERED;
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        Integer[] p = new Integer[n];
        Arrays.setAll(p, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        int p1 = Arrays.stream(p).filter(i -> i <= a).mapToInt(i -> i).toArray().length;
        int p2 = Arrays.stream(p).filter(i -> a < i && i <= b).mapToInt(i -> i).toArray().length;
        int p3 = Arrays.stream(p).filter(i -> b < i).mapToInt(i -> i).toArray().length;
        int result = Math.min(Math.min(p1, p2), p3);

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 27220
#include <iostream>
 
using namespace std;
 
int main() {
  int k;
  int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> k;
  cout << arr[k-1];
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100000
int head,tail;
int Q[MAX];
char QN[MAX][11];
char retname[11];

void initialize(void){
	head=0;
	tail=0;
}

int isEmpty(){
	return head==tail;
}

int isFull(){
	return head==(tail+1)%MAX;
}

void enqueue(char *name, int x){
	if(isFull()){
		exit(1);
	}
	strcpy(QN[tail],name);
	Q[tail]=x;
	if(tail+1==MAX){
		tail=0;
	}else{
		tail++;
	}
}

int dequeue(){
	int x;
	if(isEmpty()){
		exit(1);
	}
	x=Q[head];
	strcpy(retname,QN[head]);
	if(head+1==MAX){
		head=0;
	}else{
		head++;
	}
	return x;
}

int main(void){
	int n,q;
	int alltime=0;
	int i;
	char inputN[11];
	int inputT;
	scanf("%d",&n);
	scanf("%d",&q);
	initialize();
	for(i=0;i<n;i++){
		scanf("%s",inputN);
		scanf("%d",&inputT);
		enqueue(inputN, inputT);
	}
	int useT;
	while(1){
		if(isEmpty()==1) break;
		useT=dequeue();
		if(useT<=q){
			alltime+=useT;
			printf("%s %d\n",retname,alltime);
		}else{
			alltime+=q;
			useT-=q;
			enqueue(retname,useT);
		}
	}
	
	return 0;
}

Measured memory_bytes: 3168
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int N = Integer.parseInt(br.readLine());
		String line = br.readLine();
		String[] A = line.split(" +");
		for (int i = 0; i < N; i++) {
			if (i != 0)
				System.out.print(" ");
			System.out.print(A[i]);
		}
		System.out.println();

		for (int i = 1; i < N; i++) {
			String key = A[i];
			int j = i - 1;
			while (j >= 0 && Integer.parseInt(A[j]) > Integer.parseInt(key)) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = key;
			for (int k = 0; k < N; k++) {
				if (k != 0)
					System.out.print(" ");
				System.out.print(A[k]);
			}
			System.out.println();
		}

		if (br != null) {
			br.close();
			br = null;
		}
	}
}

Measured memory_bytes: 25688
h, w = map(int, input().split())
aList = []
for i in range(h):
    a = input()
    if a.count(".") != w:
        aList.append(a)
h = len(aList)

aLen = w

for j in range(w):
    aSum = sum(aList[i][w - j - 1] == "." for i in range(h))
    if aSum == h:
        for a in range(h):
            aList[a] = aList[a][0:w - j - 1] + aList[a][w - j:aLen]
        aLen -= 1


for i in range(h):
    print(aList[i])


Measured memory_bytes: 3064
var lines = require('fs').readFileSync('/dev/stdin', 'UTF-8');
lines = lines.split("\n")
lines.pop()
lines.pop()

// 0以降を弾く

lines = lines.map((line) => {
  return Number.parseInt(line);
})
for(var i=0;i<lines.length;i++){
  console.log("Case "+(i+1)+": "+lines[i])
}


Measured memory_bytes: 22656
package main

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

var sc = bufio.NewScanner(os.Stdin)
var cnt = 0
const inf = 1 << 32

func nextInt() int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}

func mergeSort(A []int, left, right int) {
	if left + 1 < right {
		mid := (left + right) / 2
		mergeSort(A, left, mid)
		mergeSort(A, mid, right)
		merge(A, left, mid, right)
	} 
}

func merge(A []int, l, m, r int) {
	n1 := m - l
	n2 := r - m

	L := make([]int, n1+1)
	R := make([]int, n2+1)

	// 分割されたスライスを作成
	for i := 0; i < n1; i++ {
		L[i] = A[l+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[m+i]
	}

	// 番兵を用意
	L[n1] = inf
	R[n2] = inf

	// 分割された2スライスをマージ
	var i, j int
	for k := l; k < r; k++ {
		cnt++
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
		} else {
			A[k] = R[j]
			j++
		}
	}
}

func parseStringSlice(a []int) []string {
	s := make([]string, len(a))
	for i := 0; i < len(a); i++ {
		s[i] = strconv.Itoa(a[i])
	}
	return s
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	A := make([]int, n)

	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	mergeSort(A, 0, n)
	ans := parseStringSlice(A)
	fmt.Println(strings.Join(ans, " "))
	fmt.Println(cnt)
}


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

int main() {
    int n, m, a[100], all = 0, c = 0;
    
    cin >> n >> m;

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

    for (int i = 0; i < n; i++) {
        if (a[i] * (4 * m) >= all) {
            c++;
        }
    }

    if (c >= m) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef long long ll;
#define int ll
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = LONG_LONG_MAX;

void solve() {
	int a,b,c,d,e;
	cin >> a>>b>>c>>d>>e;

	int dist = abs(c-a);
	int speed = b-d;

	
	if(dist <= e*speed) cout << "YES\n";
	else cout << "NO\n";
	
}

int32_t main() {_
	
#ifndef ONLINE_JUDGE
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
#endif

	// tc(t)
		solve();
	cerr << "[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
}



Measured memory_bytes: 3780
#include <bits/stdc++.h>
#define INF 10000000
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
using namespace std;
int main()
{
	long long n, m;
	cin >> n >> m;
	if (n == m)
	{
		cout << 2 << endl;
		return 0;
	}
	long long n1 = 0, n2 = n, m1 = 0, m2 = m;
	int cnt1 = 0;
	while (1)
	{
		long long tmp = min(n1 + n2, m2);
		m2 -= tmp;
		m1 += tmp;
		long long r = (n1 + n2) - tmp;
		m1 -= r;
		if (m1 <= 0 && m2 <= 0)
			break;
		cnt1++;
		long long sum = m1 + m2;
		if (n1 > 0)
		{
			n1--;
			sum--;
		}
		n2 -= sum / 2;
		if (sum % 2 != 0 && n2 > 0)
		{
			n1++;
			n2--;
		}
		if (n1 <= 0 && n2 <= 0)
			break;
		cnt1++;
	}
	int cnt2 = 0;
	n1 = 0;
	n2 = m;
	m1 = 0;
	m2 = n;
	while (1)
	{
		long long sum = m1 + m2;
		if (n1 > 0)
		{
			n1--;
			sum--;
		}
		n2 -= sum / 2;
		if (sum % 2 != 0 && n2 > 0)
		{
			n1++;
			n2--;
		}
		//cout << n1 << " " << n2 << " " << m1 << " " << m2 << endl;;
		if (n1 <= 0 && n2 <= 0)
			break;
		cnt2++;
		long long tmp = min(n1 + n2, m2);
		m2 -= tmp;
		m1 += tmp;
		long long r = (n1 + n2) - tmp;
		m1 -= r;
		//cout << n1 << " " << n2 << " " << m1 << " " << m2 << endl;
		if (m1 <= 0 && m2 <= 0)
			break;
		cnt2++;
	}
	//cout << cnt1 << " " << cnt2 << endl;
	int ans = min(cnt1, cnt2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>

int MAX_prime = 300000;
int a[2000000];

int main(void)
{
	int dummy = 0;
	int n,ans;
	for(int i = 0; i < MAX_prime; i++){
		a[i] = 1;
	}
	for(int i = 2; i < MAX_prime; i++){
		if(a[i]){
			for(int j = i * 2;j < MAX_prime; j = j + i){
					a[j] = 0;
			}
		}
	}
	scanf("%d",&n);
	while(n != 0){
		ans = 0;
		for(int i = n + 1; i <= 2 * n; i++){
			if(a[i]){
				ans++;
			}
		}
		printf("%d\n",ans);
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 2200
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main(void){
	int n, h, t, c=0;
	scanf("%d %d", &n, &h);

	vector<int> katana1;
	vector<int> katana2;

	for(int i = 0;i < n;++i){
		scanf("%d", &t);
		katana1.push_back(t);
		scanf("%d", &t);
		katana2.push_back(t);
	}

	sort(katana1.begin(), katana1.end());
	sort(katana2.begin(), katana2.end());

	int i = 1;

	while(true){
		h -= katana2[n-i];
		++c;++i;

		if(katana2[n-i] < katana1[n-1]) break;

		if(h <= 0){
			printf("%d\n", c);
			return 0;
		}
	}

	printf("%d\n", c + ((int) ceil((double)h/katana1[n-1])));

	return 0;
}

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

using namespace std;

int main()
{
     int n,k;
     cin>>n>>k;
     int c=0;
     int a[n];
     for (int i=0;i<n;i++)
     {
         cin>>a[i];
     }

     for (int i=0;i<n;i++)
     {
         if (a[i]>=k)
         {
             c++;




         }

     }
     cout<<c;

    return 0;
}


Measured memory_bytes: 640
a,b,k=map(int,input().split())
r1=[i for i in range(a,min(b+1,a+k))]
r2=[i for i in range(max(a,b-k+1),b+1)]
r1.extend(r2)
result=set(r1)
for i in sorted(result):
    print(i)

Measured memory_bytes: 3060
/*

結果:
*/
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }

int MAX(int a, int b) { if (a > b) { return a; }return b; }
/*
int min(int a, int b) { if (a<b) { return a; }return b; }
*/
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }



/// /////////////////////////////////////////////
/// <summary> 
/// ユークリッドの互除法
///機　能：ユークリッドの互除法によりa,bの最大公約数を求める
///戻り値: 最大公約数、(自然数以外が指定されたときは-1)
/// </summary> 
/// /////////////////////////////////////////////
int euclid(int a, int b)
{
	int temp;
	if (a < b) { temp = a; a = b; b = temp; }
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return euclid(b, a % b);
}

int main() {
	int N, X,A[100000];
	int a, b,ans;
	scanf("%d%d", &N, &X);
	for (int i = 0; i < N; i++) {
		scanf("%d", &A[i]);
	}
	a = abs(X - A[0]);
	if (N > 1) {
		for (int i = 0; i < N-1; i++) {
			b = abs(X - A[i + 1]);
			a = euclid(a, b);
		}
	}
	ans = a;
	print(a);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

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

const int mod=1000000007;
int n,f[21][1<<19|3],m,x,y,z,K,lim[21][21];

void add(int &x,int y) {x=(x+y>=mod?x+y-mod:x+y);}

int main()
{
	scanf("%d%d%d",&n,&m,&K);
	memset(lim,-1,sizeof(lim));
	for (int i=1; i<=K; i++) scanf("%d%d%d",&x,&y,&z),lim[x][y]=z;
	x=1,y=0,f[n-1][0]=1;
	for (int i=1; i<=m; i++)
	{
		for (int j=0; j<(1<<n-1); j++) f[0][j]=f[n-1][j];
		for (int j=0; j<n-1; j++)
		{
			memset(f[j+1],0,sizeof(f[j+1]));
			for (int k=0; k<(1<<n-1); k++)
			{
				if (lim[i][j+1]!=1&&!((k>>j)&1)) add(f[j+1][k],f[j][k]);
				if (lim[i][j+1]!=0)
				{
					if ((k>>j)&1) add(f[j+1][k],f[j][k]); else
					{
						int t=(k>>j)<<j;
						add(f[j+1][k^(t&-t)^(1<<j)],f[j][k]);
					}
				}
			}
		}
	}
	int ans=0;
	for (int i=0; i<(1<<n-1); i++) ans=(ans+f[n-1][i])%mod;
	return printf("%d\n",ans),0;
}

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

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

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


def main():
    a,b = LI()

    return max(0,a-b*2)


print(main())



Measured memory_bytes: 6480
#include <stdio.h>

int main(void)
{
	int n;
	int a;
	int b;
	
	while (1){
		a = 0;
		b = 0;
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		b = 1000 - n;
		a += b / 500;
		b %= 500;
		a += b / 100;
		b %= 100;
		a += b / 50;
		b %= 50;
		a += b / 10;
		b %= 10;
		a += b / 5;
		b %= 5;
		a += b / 1;
		
		printf("%d\n", a);
	}
	
	return (0);
}

Measured memory_bytes: 1716
#include <stdio.h>
#include <math.h>

#define N 10000

int isPrime(int);

int main(){

  int num[N],n,i,c,count=0;

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

  for(i=0;i<n;i++){
    c=isPrime(num[i]);
    if(c==0) count++;
  }

  printf("%d\n",count);

  return 0;
}

isPrime(int x){

  int i;
  if(x==2) return 0;
  if(x<2 || x%2==0) return 1;
  
  i=3;
  while(i<=sqrt(x)){
    if(x%i==0) return 1;
    i=i+2;
  }
  return 0;
  
}

Measured memory_bytes: 628
a,b,c,x,y = map(int,input().split())

atob = x*a + y*b

maxab = (max(x,y) * 2) * c

if x > y:
    minab = y*c*2 + (x-y)*a
else:
    minab = x*c*2 + (y-x)*b
    
print(min(atob,maxab,minab))

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
using namespace std;
typedef long long ll;

int main(){
	ll a,b,n;
	cin >> a >> b >> n;
	ll m;
	if(n < b){
		m = n;
	}
	else{
		m = b - 1;
	}
	ll ans = m*a/b;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int main(){
	int num;
	scanf("%d",&num);
	if (num%10==2||num%10==4||num%10==5||num%10==7||num%10==9){
		printf("hon\n");
	}
	else if(num%10==0||num%10==1||num%10==6||num%10==8){
		printf("pon\n");
	}
	else if(num%10==3){
		printf("bon\n");
	}
	return 0;
}


Measured memory_bytes: 1656
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main(){
	int a, b; cin >> a >> b;
	if (a + b == 15)cout << "+" << endl;
	else if (a*b == 15)cout << "*" << endl;
	else cout << "x" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res % p;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc;
    tc = 1;
    //cin >> tc;
    while (tc--)
    {
        string s;
        cin >> s;
        string t = s;
        int k;
        cin >> k;
        int ans = 0;
        map<char, int> mp;
        int c = 0;
        for (int i = 0; i < s.size(); i++)
        {
            if (mp[s[i]] == 0)
            {
                mp[s[i]] = 1;
                c++;
            }
        }
        if (c == 1)
        {
            int f = s.size();
            f = f * k;
            f /= 2;
            cout << f << endl;
            continue;
        }
        for (int i = 1; i < s.size(); i++)
        {
            if (s[i] == s[i - 1])
            {
                char ch = 'a';
                if (ch == s[i - 1] || ch == s[(i + 1) % s.size()])
                {
                    ch++;
                }
                if (ch == s[i - 1] || ch == s[(i + 1) % s.size()])
                {
                    ch++;
                }
                s[i] = ch;
                ans++;
            }
        }
        ans = ans * k;
        if (s[0] == s[s.size() - 1])
        {
            int c = 0;
            for (int i = 0; i < t.size();i++){
                if(t[i]==t[0]){
                    c++;
                }
                else
                {
                    break;
                }
                
            }
            reverse(all(t));
            for (int i = 0; i < t.size(); i++)
            {
                if (t[i] == t[0])
                {
                    c++;
                }
                else
                {
                    break;
                }
            }

            if(c%2==0)
            ans += k - 1;
        }
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

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

    vector<int> L(n);
    for (int i = 0; i < n; ++i)
        cin >> L[i];

    sort(L.begin(), L.end(), greater<int>());

    int longest = L[0];
    int remain = 0;
    for (int i = 1; i < n; ++i)
        remain += L[i];
    if (remain > longest)
        cout << "Yes\n";
    else
        cout << "No\n";
}


Measured memory_bytes: 384