akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  int A, B, C, X;
  cin >> A >> B >> C >> X;
  int cnt = 0;
  for (int i = 0; i <= A; i++)
  {
    for (int j = 0; j <= B; j++)
    {
      for (int k = 0; k <= C; k++)
      {
        if (500 * i + 100 * j + 50 * k == X)
          cnt++;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main(void)
{
    long long int sum=0,range=0,a=0,b=0;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0;
    long long int longnum[200005];
    //vector <int> v;
    //float f,g,h;
    char c,d;
    string s;
    cin>>n>>s;
    for(i=0;i<s.size();i++)
    {
        s[i]+=n;
        if(s[i]>90) s[i]=s[i]-90+64;
        cout<<s[i];
    }
    return 0;
}




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

ll visited[MAX_N];


int dfs(int from, int to, int cost, vector<pair<int,int>> v[]){
    visited[to] = visited[from] + cost;
    for(auto dst : v[to]){
        if(visited[dst.first] != -1){continue;}
        dfs(to, dst.first, dst.second, v);
    }
    return 0;
}

int main() {
    int n;
    cin >> n;
    vector<pair<int,int>> v[MAX_N];
    int a,b,c;
    pair<int,int> tmp1,tmp2;
    for(int i = 0; i < n-1; i++){
        cin >> a >> b >> c;
        v[a].push_back({b,c});
        v[b].push_back({a,c});
    }
    for(int i = 0; i < MAX_N; i++){
        visited[i] = -1;
    }
    int q, k, x, y;
    cin >> q >> k;
    dfs(k, k, 1, v);

    for(int i = 0; i < q; i++){
        cin >> x >> y;
        cout << visited[x] + visited[y] << endl;
    }

    return 0;
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s,t;
cin>>s>>t;
int a,b;
cin>>a>>b;
string val;
cin>>val;
if(val==s)
{
    a-=1;
}
if(val==t)
    b-=1;
cout<<a<<" "<<b<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
read = sys.stdin.read

N, A, B, *h = map(int, read().split())

h = np.array(h, np.int64)

# 2部探索する。n回の爆発で魔物をすべて倒せるか否や
l = 0
r = max(h) // B + 2
a = A - B
while l + 1 < r:
    mid = (l + r) // 2
    w = B * mid
    tmp = h - w
    tmp = tmp[tmp > 0]
    tmp = tmp // a + np.minimum(tmp % a, 1)
    if tmp.sum() <= mid:
        r = mid
    else:
        l = mid

print(r)

Measured memory_bytes: 23112
from sys import stdin


def main():
    A, B = [int(x) for x in stdin.readline().rstrip().split()]
    result = 1
    while True:
        a = int(result * 0.08)
        b = int(result * 0.1)
        if a == A and b == B:
            print(result)
            break
        if A < a and B < b:
            print(-1)
            break
        result += 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int area = a*b;
int length = 2*a+2*b;
System.out.println(area + " " + length); 
}
}

Measured memory_bytes: 26204
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <map>
#include <functional>
#include <cstring>
#include <queue>
#include <cmath>
#include <deque>
#include <list>
#include <iomanip>
#include <fstream>
#include <string>
#include <iterator>
#include <set>
#include <bitset>
using namespace std;

typedef long double LD;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LD, LD> PDD;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<char> VCH;
typedef vector<LD> VLD;
typedef vector<VI> VVI;
typedef vector<VLL> VVLL;
typedef vector<VCH> VVCH;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<PDD> VPDD;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define REP(i, t) FOR(i,0,t)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())

const int MAXN = 1007;
const int MOD = 1000000007;
const int INF = 1000000000;
const LL LINF = INF * (LL)INF;
const LD PI = acos(-1.0);

LL f(LL a, LL b)
{
	LL res = 0;
	if (a > b) swap(a, b);
	while (b % a != 0)
	{
		res += 2 * a * (b / a);
		swap(a, b);
		a %= b;
	}
	return res + 2 * b - a;
}

int main()
{
	ios_base::sync_with_stdio(0);
	//freopen("In.txt", "r", stdin);
	//freopen("hear.in", "r", stdin);
	//freopen("hear.out", "w", stdout);
	LL n, x;
	cin >> n >> x;
	cout << n + f(x, n - x);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  int ans;
  if(a==b) ans=c;
  else if(b==c) ans=a;
  else ans=b;
  cout <<ans<<endl;

      return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int dp[] = new int[31];
	public static void main(String[] args) {
		dp[1] = 1;
		dp[2] = 2;
		dp[3] = 4;
		for (int i = 4; i <= 30; i++) {
			dp[i] = dp[i - 1] + dp[i - 2] + dp[i -3];
		}
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			System.out.println((dp[n] / 3650) + 1);
		}
	}
}

Measured memory_bytes: 17184
X, K, D = map(int, input().split())
X = abs(X)

def solve():
    if X // D >= K:
        return X - D*K
    if ((X//D)%2 == 0) ^ (K%2 == 0):
        return D - (X - D*(X//D))
    else:
        return X - D*(X//D)

if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 9160
N, M = map(int, input().split())

from math import factorial
if N > 1:
    a = factorial(N) // factorial(2) // factorial(N - 2)
else:
    a = 0

if M > 1:
    b = factorial(M) // factorial(2) // factorial(M - 2)
else:
    b = 0

print(a + b)

Measured memory_bytes: 3060
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll H,N;
	while(cin>>H>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll sum=accumulate(ALL(A), 0LL);
		string ans = H<=sum ? "Yes":"No";
		cout<<ans<<endl;
	}
	
	return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

#define UF_NUM 505050

li cnt[2];

int main() {
    string s;
    cin >> s;
    rep(i, sz(s)) {
        cnt[s[i] - '0']++;
    }
    cout << min(cnt[0], cnt[1]) * 2 << endl;

    return 0;
}

Measured memory_bytes: 512
def main(N, moves):
    pre_t = 0
    pre_x = 0
    pre_y = 0 #スタート
    for move in moves: #それぞれの途中地点での各座標
        new_t, new_x, new_y = move[0], move[1], move[2]
        delta_t = new_t - pre_t #各途中地点間の時間差
        delta_x = abs(new_x - pre_x)
        delta_y = abs(new_y - pre_y)
        delta_sum = delta_x + delta_y #各途中地点間の経路差
        remain_time = delta_t - delta_sum #時間と経路差
        if remain_time == 0: #時間差=経路差 ⇒ OK
            pre_t, pre_x, pre_y = new_t, new_x, new_y #次のステップ(途中地点)へ
        elif remain_time > 0: #時間差＞経路差の場合：場合分けが必要
            if remain_time % 2 == 0: #残り時間が偶数 ⇒ 行ったり来たりの往復で時間を潰せばOK
                pre_t, pre_x, pre_y = new_t, new_x, new_y #次のステップへ
            else: 
                return "No" #残り時間が奇数 ⇒ ダメ
        else:
            return "No" #時間差＞経路差の場合 ⇒ 何やってもダメ
    return "Yes"

N = int(input())
moves = [] 
for i in range(N):
    moves.append([int(j) for j in input().split()]) #与えられた途中地点を代入
print(main(N, moves))

Measured memory_bytes: 21052
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

signed main()
{
    string S;cin>>S;
    int a[26]={};
    rep(i,S.size()){
        a[S[i]-'a']=1;
    }
    rep(i,26){
        if (a[i]==0){
            cout<<(char)('a'+i)<<endl;
            return 0;
        }
    }
    cout<<"None\n";
}


Measured memory_bytes: 512
import math

n = int(input())
vote = [0, 0]
# 最初の得票は、最小値を目指すので
# 単純に入力比をそのまま使用
# 各入力に対し、vote[0]<=t*k, vote[1]<=a*kとなる
# 最小のt*k,a*kでvoteを更新
vote = [1, 1]
for i in range(n):
    t, a = [int(i) for i in input().split()]
    if vote[0] % t == 0:
        k = vote[0] // t
    else:
        k = vote[0] // t + 1
    if vote[1] % a == 0:
        k = max(k, vote[1] // a)
    else:
        k = max(k, vote[1] // a + 1)
    # k = max(math.ceil(vote[0] / t), math.ceil(vote[1] / a))
    vote = [t * k, a * k]
    # a / b + (a % b == 0 ? 0: 1)
    # print("i:{} vote:{}".format(i, vote))
print(vote[0] + vote[1])


Measured memory_bytes: 3064
class RootedTree
	attr_accessor :lch, :rsbl, :parent
	
	def format(id)
		puts "node #{id}: parent = #{self.parent}, depth = #{self.get_depth}, #{self.get_type}, #{self.get_children}"
	end
	
	def initialize(parent = -1, lch = nil, rsbl = nil)
		@parent = parent
		@lch = lch
		@rsbl = rsbl
	end
	
	def get_depth
		depth = 0
		i = self.parent
		while true
			return depth if i == -1
			i = $nodes[i].parent
			depth += 1
		end
	end
	
	def get_type
		if self.parent == -1
			return "root"
		else
			if self.lch == nil
				return "leaf"
			else
				return "internal node"
			end
		end
	end
	
	def get_children
		child = self.lch
		r = []
		while child
			r.push(child)
			child = $nodes[child].rsbl
		end
		return r
	end
end

n=gets.chomp.to_i
$nodes = []
n.times{|i|$nodes[i] = RootedTree.new}

n.times do
	node_id, dim, *ch_list = gets.chomp.split(" ").map{|j|j.to_i}
	next if dim == 0
	$nodes[node_id].lch = ch_list[0]
	dim.times do |d|
		$nodes[ch_list[d]].parent = node_id
		$nodes[ch_list[d]].rsbl = ch_list[d+1] if ch_list[d+1]
	end
end

$nodes.each_with_index do |obj,ix|
	obj.format(ix)
end


Measured memory_bytes: 19796
N = int(input())
A = []
XY = []
honest_count = []

for i in range (N):
    a = int(input())
    A.append(a)
    inter = []
    for x in range(a):
        xy = list(map(int, input().split()))
        inter.append(xy)
    XY.append(inter)

for i in range(2 ** N):
    pt = [0] * N
    ck = 1
    for j in range(N):
        if (i >> j) & 1:
            pt[N - j - 1] = 1

    for k in range(N): # k人目が正直者の場合チェック
        if pt[k] == 1:
            for l in range(A[k]):
                if XY[k][l][1] != pt[XY[k][l][0] - 1]:
                    ck = 0
    if ck == 1:
        honest_count.append(sum(pt))


print(max(honest_count))

Measured memory_bytes: 9328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, n) for(ll i = 1; i <= ll(n); i++)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); i++)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); i++)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  vl x(5);
  rep(i, 5) {
    cin >> x[i];
    if(x[i]==0) cout << i + 1 << newl;
  }
  return 0;
}

Measured memory_bytes: 3512
//by xiqiao
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
int n,m;
struct matrix{
	int a[5][5];
	int h,l;
}ans,a,b,A;
matrix operator *(matrix a,matrix b){
	matrix c;
	c.h=a.h;c.l=b.l;
	for(int i=0;i<=c.h;i++){
		for(int j=0;j<=c.l;j++){
			c.a[i][j]=0;
			for(int k=0;k<=a.l;k++){
				c.a[i][j]=(c.a[i][j]+1ll*a.a[i][k]*b.a[k][j]%MOD)%MOD;
			}
		}
	}
	return c;
}
int main(){
	scanf("%d%d",&n,&m);
	a.h=b.h=a.l=b.l=3;
	a.a[0][0]=2;a.a[0][1]=1;a.a[0][2]=1;a.a[0][3]=1;
	a.a[1][0]=1;a.a[1][1]=1;a.a[1][2]=0;a.a[1][3]=1;
	a.a[2][0]=1;a.a[2][1]=0;a.a[2][2]=1;a.a[2][3]=1;
	a.a[3][0]=1;a.a[3][1]=0;a.a[3][2]=0;a.a[3][3]=1;
	A=a;
	b.a[0][0]=1;b.a[0][1]=1;b.a[0][2]=1;b.a[0][3]=1;
	b.a[1][0]=0;b.a[1][1]=1;b.a[1][2]=0;b.a[1][3]=1;
	b.a[2][0]=0;b.a[2][1]=0;b.a[2][2]=1;b.a[2][3]=1;
	b.a[3][0]=0;b.a[3][1]=0;b.a[3][2]=0;b.a[3][3]=1;
	
	ans.h=0;ans.l=3;
	ans.a[0][0]=1;
	int last=0;
	while(m--){
		int x;scanf("%d",&x);
		int t=x-last-1;last=x;
		a=A;
		while(t){
			if(t&1)ans=ans*a;
			a=a*a;
			t>>=1;
		}
//		cout<<" "<<ans.a[0][0]<<" "<<ans.a[0][1]<<" "<<ans.a[0][2]<<" "<<ans.a[0][3]<<endl;
		ans=ans*b;
//		cout<<" "<<ans.a[0][0]<<" "<<ans.a[0][1]<<" "<<ans.a[0][2]<<" "<<ans.a[0][3]<<endl;
	}
	int t=n-last;a=A;
	while(t){
		if(t&1)ans=ans*a;
		a=a*a;t>>=1;
	}
	printf("%d\n",ans.a[0][3]);
	return 0;
}
			

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <stack>
#include <functional>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vi vector<int>
#define INF (int)1e9
#define INFL 1e18
#define MOD 1e9+7
#define pb push_back
#define MP make_pair
typedef long long int ll;
typedef std::pair<int,int> P;
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

using namespace std;


int main() {
    int v[3][3];
    rep(i,0,3)rep(j,0,3){
        cin>>v[i][j];
    }
    bool f=true;
    rep(i,0,101){ // i がa1の値
        rep(j,0,101){  // j がa2の値
            rep(k,0,101){  // k がa3の値
                 //b1,b2,b3について調べる
                if((v[0][0]-i==v[0][1]-j&&v[0][1]-j==v[0][2]-k)&&(v[1][0]-i==v[1][1]-j&&v[1][1]-j==v[1][2]-k)&&(v[2][0]-i==v[2][1]-j&&v[2][1]-j==v[2][2]-k)){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

s = S()
if s[2] == s[3] and s[4] == s[5]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 39664
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define all(z) (z).begin(),(z).end() 
#define MOD 1000000007
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll isprime(ll n)
{
	for(int i=2;i<n;i++)
		if(n%i==0)
		return 0;
		
	return 1;	
}
int main()
{ 
    FAST;
	ll t;
	cin>>t;
	if(t)cout<<0;
	else cout<<1;
	
	
}


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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if(b%a == 0)
    {
        cout << a+b << endl;
    }
    else
    {
        cout << b-a << endl;
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	if ((a[a.size() - 1] == b[0]) && (b[b.size() - 1] == c[0]))cout << "YES" << endl;
	else cout << "NO" << endl;
	int x;
	cin >> x;
}

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

const int BITS = 30;

int N;
vector<long long> A, B;

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

    cin >> N;
    A.resize(N);
    B.resize(N);

    for (auto &a : A)
        cin >> a;

    for (auto &b : B)
        cin >> b;

    long long answer = 0;

    for (int bit = 0; bit < BITS; bit++) {
        long long ones = 0;
        long long full = (1LL << bit) - 1;

        sort(A.begin(), A.end(), [&](long long x, long long y) {
            return (x & full) < (y & full);
        });

        sort(B.begin(), B.end(), [&](long long x, long long y) {
            return (x & full) < (y & full);
        });

        for (int i = 0, j = N; i < N; i++) {
            while (j > 0 && (A[i] & full) + (B[j - 1] & full) > full)
                j--;

            ones += N - j;
        }

        long long a_ones = 0, b_ones = 0;

        for (int i = 0; i < N; i++) {
            a_ones += A[i] >> bit & 1;
            b_ones += B[i] >> bit & 1;
        }

        ones += N * (a_ones + b_ones);

        if (ones % 2 != 0)
            answer |= 1LL << bit;
    }

    cout << answer << '\n';
}


Measured memory_bytes: 3328
import numpy as np

X,N = map(int, input().split())
P = np.array(list(map(int,input().split())), dtype=np.int32)
num = np.arange(0,102)
kouho = np.setdiff1d(num,P)
ans = kouho[np.argmin((np.abs(kouho-X)))]
print(ans)


Measured memory_bytes: 26720
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll int
#define pp pair<ll,ll>
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define sz(v) (ll)(v.size())
#define hell (ll)998244353
#define slld(x) scanf("%lld",&x)
ll t = 1;
const ll inf=hell, N=3005;
ll dp[3005][3005];
inline ll mult(ll x,ll y){return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base);
		expo>>=1;
	}
	return ans;
}
void solve(){
	ll n, s, res=0;
	cin>>n>>s;
	memset(dp,0,sizeof dp);
	vector<ll> v(n+1,0);
	rep(i,1,n+1){
		cin>>v[i];
		dp[i][v[i]]=i;
	}
	rep(i,1,n+1){
		rep(j,0,s+1)
			if(j>=v[i])
				dp[i][j]=add(dp[i][j],dp[i-1][j-v[i]]);
		res=add(res,mult(n-i+1,dp[i][s]));
		rep(j,0,s+1)
			dp[i][j]=add(dp[i][j],dp[i-1][j]);
	}
	cout<<res<<"\n";
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 35584
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

prev_a = -1
sut = 0
for i in range(N):
    a = A[i]
    sut += B[a-1]
    #print("a", a, prev_a, a-prev_a)
    if (a - prev_a) == 1:
        #print("sut")
        sut += C[a-2]
        #print("C", C[i-2])
    prev_a = a
    #print(i, sut)
print(sut)

Measured memory_bytes: 3064
table = {1=>0, 2=>0, 3=>0, 4=>0}
3.times do
  a, b = gets.chomp.split.map(&:to_i)
  table[a]+=1
  table[b]+=1
end
puts table.values.sort! == [1, 1, 2, 2] ? "YES" : "NO"

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
static const int MAX_N = 100000;
static const int MAX_Q = 100000;
static const int NIL = -1;

int N;
int a[MAX_N], b[MAX_N], c[MAX_N];
int Q, K;
int x[MAX_Q], y[MAX_Q];

struct edge{int to, cost;};
vector<edge> G[MAX_N];
ll d[MAX_N];

void bfs(int s){
	for(int i = 0; i < N; i++) d[i] = NIL;
	d[s] = 0;
	queue<int> q;
	q.push(s);
	int u;
	while(!q.empty()){
		u = q.front(); q.pop();
		for(int i = 0; i < G[u].size(); i++){
			edge e = G[u][i];
			if(d[e.to] == NIL){
				d[e.to] = d[u] + e.cost;
				q.push(e.to);
			}
		}
	}
}

void solve(){
	for(int i = 0; i < N - 1; i++){
		G[a[i] - 1].push_back((edge){b[i] - 1, c[i]});
		G[b[i] - 1].push_back((edge){a[i] - 1, c[i]});
	}
	bfs(K - 1);
	for(int i = 0; i < Q; i++) cout << d[x[i] - 1] + d[y[i] - 1] << endl;
}

int main(){
	scanf("%d", &N);
	for(int i = 0; i < N - 1; i++) scanf("%d %d %d", &a[i], &b[i], &c[i]);
	scanf("%d %d", &Q, &K);
	for(int i = 0; i < Q; i++) scanf("%d %d", &x[i], &y[i]);
	solve();
	return 0;
}


Measured memory_bytes: 10740
#include<cstdio>
#include<iostream>
using namespace std;
const int mod=1e9+7;
int mi[1000010],ni[1000010];
int ans,n,num[1000010];
int fast_pow(int x,int a)
{
	int ans=1;
	for (;x;x>>=1,a=1ll*a*a%mod)
		if (x&1) ans=1ll*ans*a%mod;
	return ans;
}
int C(int n,int m)
{
	return 1ll*mi[n]*ni[m]%mod*ni[n-m]%mod;
}
int main()
{
	scanf("%d",&n);mi[0]=1;
	for (int i=1;i<=n;i++) mi[i]=1ll*mi[i-1]*i%mod;
	ni[n]=fast_pow(mod-2,mi[n]);
	for (int i=n-1;i>=0;i--) ni[i]=1ll*ni[i+1]*(i+1)%mod;
	for (int i=(n+1)/2;i<n;i++) num[i]=1ll*C(i-1,n-2-(i-1))*mi[i]%mod*mi[n-1-i]%mod;
	for (int i=(n+1)/2;i<n;i++)
	{
		ans=(1ll*ans+1ll*i*(num[i]-num[i-1]+mod))%mod;
	}
	printf("%d",ans);
}

Measured memory_bytes: 9984
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
        int t = sc.nextInt();
        if(t == 0)break;
            
        int n = sc.nextInt();
        int[] s = new int[n];
        int[] f = new int[n];
        int sum = 0;
        for(int i=0; i < n; i++){
        	s[i] = sc.nextInt();
            f[i] = sc.nextInt();
            sum += f[i] - s[i];
        }
        
        if(sum >= t){
            System.out.println("OK");
        }else{
         	System.out.println(t-sum);   
        }
        }
    }
}



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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    double ans1, ans2, con = -1;
    for (int a = 0; a <= F; a += 100 * A) {
        for (int b = 0; a + b <= F; b += 100 * B) {
            if (a + b == 0) continue;
            for (int c = 0; a + b + c <= F; c += C) {
                for (int d = 0; a + b + c + d <= F; d += D) {
                    double water = a + b;
                    double sugar = c + d;
                    double ncon = 100*sugar / (water+sugar);
                    if (E / 100.0 >= sugar / water && ncon > con) {
                        con = ncon;
                        ans1 = water+sugar;
                        ans2 = sugar;
                    }
                }
            }
        }
    }
    cout << ans1 << " " << ans2 << endl;
    
    return 0;
}

Measured memory_bytes: 256
import Data.Array
main = do
  n <- readLn
  a <- listArray (1,n) . (map read . lines) <$> getContents
  print $ solve 1 a 0

solve :: Int -> Array Int Int -> Int -> Int
solve i a n
  | i == 2 = n
  | n > 100000 = -1
  | otherwise = solve (a ! i) a (n+1)

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

int main(){
  int64_t N;
  string S;
  cin >> N >> S;
  int64_t r=0,g=0,b=0;
  int64_t x=0;
  for(int i=0;i<N;i++){
    if(S.at(i)=='R'){
      r++;
    }else if(S.at(i)=='G'){
      g++;
    }else{
      b++;
    }
    int y=(N-i)/2;
    if((N-i)%2==1) y++;
    for(int j=1;j<y;j++){
      if(S.at(i)!=S.at(i+j)&&S.at(i)!=S.at(i+2*j)&&S.at(i+2*j)!=S.at(i+j)){
        x--;
      }
    }
  }
  x+=r*b*g;
  cout << x << endl;

}

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

bool in_range(int a, int b){
  return a >= 0 && a < b;
}

int simulate(string S, int v, const vector<char> &T, const vector<char> &D, int d){
  int N = S.length();
  for(size_t i = 0; i < T.size(); ++i){
    if(S[v] != T[i]) continue;
    if(D[i] == 'R') v += d;
    else v -= d;
    if(not in_range(v,N)) return v;
  }
  return v;
}

int solve(string S, vector<char> &T, vector<char> &D){
  int N = S.length();
  int ng = N, ok = -1;
  int ans = N;
  while(ng-ok > 1){
    int m = (ok+ng)/2;
    int v_ = simulate(S,m,T,D,1);
    if(v_ == -1) ok = m;
    else ng = m;
  }
  ans -= ng;
  reverse(S.begin(), S.end());
  ng = N, ok = -1;
  while(ng-ok > 1){
    int m = (ok+ng)/2;
    int v_ = simulate(S,m,T,D,-1);
    if(v_ == -1) ok = m;
    else ng = m;
  }
  ans -= ng;
  return ans;
}

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vector<char> T(Q), D(Q);
  for(int i = 0; i < Q; ++i) cin >> T[i] >> D[i];
  cout << solve(S,T,D) << endl;
}


Measured memory_bytes: 1228
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

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

    ll n, p, ans=1LL;
    cin >> n >> p;
    ll d = 2LL;
    if (n >= 40LL) {
        cout << 1 << endl;
        return 0;
    } else if (n == 1LL) {
        cout << p << endl;
        return 0;
    }

    while (p > 1) {
        ll count = 0LL;
        while(p % d == 0) {
            count += 1LL;
            p /= d;
        }
        if (count >= n) {
            for (ll i = 0; i < count/n; i++) {
                ans *= d;
            }
        }
        d += 1LL;
        if (d > 1000000LL) {
            break;
        }
    }

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

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

struct LayeredRangeTree{
    LayeredRangeTree(){}
    LayeredRangeTree(vector<int>&a){init(a);}
    void init(vector<int>&a){
        Size=1;while(Size<a.size())Size*=2;
        data.resize(Size*2);
        toL.resize(Size*2);
        toR.resize(Size*2);


        for(int i=0;i<a.size();i++){
            data[i+Size-1].push_back(a[i]);
        }

        for(int i=Size-2;i>=0;i--){
            data[i].resize(data[i*2+1].size()+data[i*2+2].size());
            toL[i].resize(data[i].size()+1);
            toR[i].resize(data[i].size()+1);
            if(data[i].size()==0)continue;
            merge(data[i*2+1].begin(),data[i*2+1].end(),data[i*2+2].begin(),data[i*2+2].end(),data[i].begin());

            {
                int cur=0;
                for(int j=0;j<data[i].size();j++){
                    while(cur<data[i*2+1].size()&&data[i][j]>data[i*2+1][cur])cur++;
                    toL[i][j]=cur;
                }
                toL[i][data[i].size()]=data[i*2+1].size();
            }

            {
                int cur=0;
                for(int j=0;j<data[i].size();j++){
                    while(cur<data[i*2+2].size()&&data[i][j]>data[i*2+2][cur])cur++;
                    toR[i][j]=cur;
                }
                toR[i][data[i].size()]=data[i*2+2].size();
            }
        }
    }

    int query(int a,int b,int c,int d){
        c=lower_bound(data[0].begin(),data[0].end(),c)-data[0].begin();
        d=lower_bound(data[0].begin(),data[0].end(),d)-data[0].begin();
        return query(a,b,c,d,0,0,Size);
    }

    int query(int a,int b,int c,int d,int k,int l,int r){
        if(r<=a||b<=l)return 0;
        if(a<=l&&r<=b)return d-c;
        return query(a,b,toL[k][c],toL[k][d],k*2+1,l,(l+r)/2)+query(a,b,toR[k][c],toR[k][d],k*2+2,(l+r)/2,r);
    }

    vector<vector<int>>data,toL,toR;
    int Size;
};


signed main(){
    int N;scanf("%lld",&N);
    vint X(N);rep(i,N)scanf("%lld",&X[i]);

    LayeredRangeTree seg;
    seg.init(X);

    int Q;scanf("%lld",&Q);

    while(Q--){
        int l,r,e;
        scanf("%lld%lld%lld",&l,&r,&e);
        l--;

        int a=min(X[l],X[r-1]);
        int b=max(X[l],X[r-1]);
        int tmp=seg.query(l,r,a-e,b+e+1);
        printf("%lld\n",r-l-tmp);
    }
    return 0;
}

Measured memory_bytes: 71768
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>

using namespace std;

const int N = 1e5+7;	
#define ll long long

ll a[N];
int n,m;
ll ans = 0;
map <ll,ll> mp;

int main(){
	scanf("%d%d",&n,&m);
	for(int i = 1; i <= n; i++) {
		scanf("%lld",&a[i]);	
	}
	for(int i = 1; i <= n; i++) a[i] += a[i-1],a[i] %= m;
	mp[0] = 1;
	for(int i = 1; i <= n; i++){
		if(mp[a[i]] == 0) mp[a[i]] = 1;
		else{
			ans = (ans + mp[a[i]]);
			mp[a[i]]++;
	}
	}
	cout << ans; 
}

Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    lint N;
    string S;
    cin >> N >> S;
    set<int> number[10];
    rep(i,N) number[S[i]-'0'].insert(i);
    rep(i,10) number[i].insert(INF);
    int ans=0;
    rep(i,10) rep(j,10) rep(k,10){
        int num=*number[i].lower_bound(-1);
        if(num==INF) continue;
        num=*number[j].upper_bound(num);
        if(num==INF) continue;
        if(*number[k].upper_bound(num)!=INF) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<string>
using namespace std;
#define FOR(S,X) for(int i=S;i<X;i++)
#define FOR2(S,X) for(int j=S;j<X;j++)
const long long int MOD = 1000000007;
int main() {
	unsigned long long int sum=0,n,a;
	vector<unsigned long long int> s, aa;
	cin >> n;
	cin >> a;
	aa.push_back(a);
	s.push_back(a);
	FOR(1,n) {
		cin >> a;
		aa.push_back(a);
		s.push_back((a+s[i-1])%MOD);
	}
	FOR(1, n) {
		sum += (s[i - 1] * aa[i])%MOD;
	}
	cout << sum%MOD<<endl;
	return 0;
}

Measured memory_bytes: 6584
K, T = map(int, input().split())
A = list(map(int, input().split()))
A_max = max(A) 

ans = 0
half_K = (K + 1) // 2
if A_max <= half_K:
  print(ans)
  quit()
else:
  A_ex = K - A_max + 1#A_ex個に一番多いやつを分けることができる。
  K_syo = A_max // A_ex
  K_amari = A_max % A_ex
  ans += (K_syo) * K_amari
  ans += (K_syo - 1) * (A_ex - K_amari)
  print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<set>
#include<cstring>
#include<algorithm>

using namespace std;

int CntData[101][101];
const int INF = 1000000;

void Init() {
	for (int i = 1; i < 101; i++) {
		for (int j = 1; j < 101; j++) {
			CntData[i][j] = INF;
		}
	}
}

void solve(int n) {
	for (int k = 1; k < n; k++) {
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				CntData[i][j] = min(CntData[i][j], CntData[i][k] + CntData[k][j]);
			}
		}
	}
}

int main() {
	int n, p, r, k, t;

	Init();
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> r >> k;
		for (int j = 0; j < k; j++) {
			cin >> t;
			CntData[r][t] = 1;
		}
	}
	solve(n+1);
	
	cin >> p;
	while (p--) {
		cin >> r >> k >> t;
		if (t > CntData[r][k]) {
			cout << CntData[r][k]+1 << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}

	return 0;
}




Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long long unsigned llu;
typedef pair<ll, ll> P;//change when necessary
typedef long double ld;
#define mp make_pair
#define N ll(4003)//change it
#define M ll(0)
const ll OO = 1e18;
const ll md = 1e9 + 7;
ll X[] = { 0,0,1,-1 }, Y[] = { 1,-1,0,0 };
void fast()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n, p[N][N][2], x, co[N][N][2], dp[N][N], res, wh[N][2];
char c;

int sm(int x1, int y1, int x2, int y2,int bo)
{
	if (x2 < x1 || y2 < y1)
		return 0;
	return p[x2][y2][bo] - p[x1-1][y2][bo] - p[x2][y1-1][bo] + p[x1 - 1][y1 - 1][bo];
}
int solve(int w, int b)
{
	if (w + b >= n * 2)
		return 0;
	int &r = dp[w][b], c1, c2;
	c1 = c2 = 1e9;
	if (r != -1)
		return r;
	if (w + 1 <= n)
		c1 = co[w + 1][b][1] + solve(w + 1, b);
	if (b + 1 <= n)
		c2 = co[b + 1][w][0] + solve(w, b + 1);
	return r = min(c1, c2);
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; i++)
	{
		scanf(" %c %d", &c, &x);
		p[i][x][(c == 'W')]++;
		wh[x][(c == 'W')] = i;
	}
	wh[0][0] = wh[0][1] = -1;
	for (int i = 1; i <= n * 2; i++)
		for (int j = 1; j <= n; j++)
			for(int k = 0; k < 2; k++)
				p[i][j][k] += p[i - 1][j][k];
	for (int i = 1; i <= n * 2; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 0; k < 2; k++)
				p[i][j][k] += p[i][j-1][k];
	//p[index][number][color]
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			for (int k = 0; k < 2; k++)
				co[i][j][k] = sm(1, i+1, wh[i][k], n, k) + sm(1, j+1, wh[i][k], n, 1 - k);
	memset(dp, -1, sizeof dp);
	/*while (1)
	{
		int x, y, z;
		cin >> x >> y >> z;
		if (z)
			cout << co[x][y][z];
		else
			cout << co[y][x][z];
		cout << endl;
	}*/
	res = solve(0, 0);
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 253312
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

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

int main()
{
	int N, X;
	cin >> N >> X;
	vector<int> x( N );
	REP( i, N ) cin >> x[ i ];
	sort( x.begin(), x.end() );
	x.erase( unique( x.begin(), x.end() ), x.end() );
	set<int> S;
	S.insert( abs( x[ 0 ] - X ) );
	for( int i = 0; i < x.size() - 1; ++i )
	{
		S.insert( x[ i + 1 ] - x[ i ] );
	}
	int ans = *( S.begin() );
	for( auto gap : S )
	{
		ans = euclidean_gcd( ans, gap );
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
en='ABCDEFGHIJKLMNOPQRSTUVWXYZ'+' .,-\'?' 
de={
' ':'101','\'':'000000',',':'000011','-':'10010001','.':'010001','?':'000001',
'A':'100101','B':'10011010','C':'0101','D':'0001','E':'110','F':'01001',
'G':'10011011','H':'010000','I':'0111','J':'10011000','K':'0110','L':'00100',
'M':'10011001','N':'10011110','O':'00101','P':'111','Q':'10011111','R':'1000',
'S':'00110','T':'00111','U':'10011100','V':'10011101','W':'000010','X':'10010010',
'Y':'10010011','Z':'10010000'
}
while 1:
    try:s=input()
    except:break
    a=b=''
    for x in s:a+=de[x]
    a+='0'*(-len(a)%5)
    for i in range(len(a)//5):b+=en[int(a[i*5:i*5+5],2)]
    print(b)

Measured memory_bytes: 7476
n = int(input())
M = [list(map(int, input().split())) for _ in range(n)]
INF = 100000000000
color = ['White']*n
d = [INF]*n
p = [-1]*n
d[0] = 0
sum = 0

while True:
    minct = INF
    u = -1
    for i in range(n):
        if color[i] != 'Black' and d[i] < minct:
            minct = d[i]
            u = i
    if minct == INF:
        break
    color[u] = 'Black'
    for j in range(n):
        if color[j] != 'Black' and M[u][j] != -1:
            if M[u][j] < d[j]:
                d[j] = M[u][j]
                p[j] = u
                color[j] = 'Gray'
for k in range(n):
    if p[k] != -1:
        sum += M[k][p[k]]
print(sum)



Measured memory_bytes: 5892
import Data.List 
import Control.Monad

main :: IO ()
main = do
    n <- readLn :: IO Int
    w <- replicateM n getLine :: IO [String]
    putStrLn $ if isNotDeplicated w && areMatched w then "Yes" else "No"
              
isNotDeplicated :: Ord a => [a] -> Bool
isNotDeplicated = and . map (== 1) . map length . group . sort

areMatched :: [String] -> Bool
areMatched [_] = True
areMatched (a:b:xs) = isMatched a b && areMatched (b:xs)
  where 
    isMatched f s = last f == head s

Measured memory_bytes: 636
X = int(input())

if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3)
elif 1600 <= X < 1800:
    print(2)
elif 1800 <= X < 2000:
    print(1)


Measured memory_bytes: 9176
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]

ans = 0
a = A[0]
for i in range(N):
    a_next = A[i+1]
    b = B[i]

    ans += min(a, b)

    if b > a:
        ans += min(a_next, (b-a))
        a_next -= min(a_next, (b-a))

    a = a_next

print(ans)


Measured memory_bytes: 19648
#include <cstdio>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

typedef long long int ll;

int N,M;

const int DATA_SIZE=100000;
const ll BIGNUM = 2000000000;

// 値段*美味しさ
pair<ll, ll> sweets[DATA_SIZE];
// 値段*個数
pair<ll,ll> friends[DATA_SIZE+1];

struct Sweet_ptr_comp{

    // 美味しさを下降順
    int operator()(pair<ll, ll> *a, pair<ll, ll> *b)
    {
        return a->second<=b->second;
    }
};

//
typedef priority_queue<pair<ll, ll> *, vector<pair<ll, ll> *>, Sweet_ptr_comp> MaxQueue;

int  main(){

    scanf("%d%d",&N,&M);
    for (int i=0;i<N;i++) 
        scanf("%lld%lld", &sweets[i].first, &sweets[i].second);

    ll prev=BIGNUM;
    for (int i=0;i<M;i++) {
        scanf("%lld%lld", &friends[i].first, &friends[i].second);
        friends[i].second=min(prev,friends[i].second);
        prev = friends[i].second;
    }

    //　仮想の友達
    friends[M]=pair<ll,ll>(BIGNUM,1);

    // indexは探索したお菓子のインデクス
    int index=0;
    ll ans=0;

    // 価値の小さいお菓子をいっぱい持つ
    while (index<N&&sweets[index].first<friends[0].first)
        ans+=sweets[index++].second;
    
    
    // printf("%lld\n",ans);

    MaxQueue Q;
    // 全ての友達にたいする
    for (int i=0;i<M;i++){


        // 値段が今の友達と次の友達の間のお菓子を最大ヒープに追加
        while (
            index<N
            &&sweets[index].first>=friends[i].first
            &&sweets[index].first<friends[i+1].first)
             Q.push(&sweets[index++]);

        // 美味しさの高い奴から
        for (int j=friends[i].second;j>friends[i+1].second&&!Q.empty();j--){

            // printf("%lld %lld\n",Q.top()->first,Q.top()->second);
            ans+=Q.top()->second;
            Q.pop();
        }

    }

    printf("%lld\n",ans);

    return 0;
}


Measured memory_bytes: 6548
while True:
   m, f, r = [int(i) for i in input().split()]
  
   if m == f == r == -1:
      break
   total = m + f
   if m == -1 or f == -1 or total < 30:
      print("F")
    
   elif total < 50 and r < 50:
      print("D")
 
   elif r >= 50 or total < 65:
      print("C")
    
   elif total < 80:
      print("B")
 
   else:
      print("A")

Measured memory_bytes: 7720
package main

import "fmt"

func main() {
  var x, y, ans int
  fmt.Scan(&x, &y)
  pay := make([]int, 206)
  pay[1] = 300000
  pay[2] = 200000
  pay[3] = 100000
  ans = pay[x] + pay[y]
  if x == y && x == 1 {
    ans += 400000
  }
  fmt.Println(ans)
}

Measured memory_bytes: 512
lst = list(input())
for i,num in enumerate(lst):
    lst[i] = int(num)

if lst[0]+lst[1]+lst[2]+lst[3]==7:
    print(str(lst[0])+"+"+str(lst[1])+"+"+str(lst[2])+"+"+str(lst[3])+"=7")
elif lst[0]+lst[1]+lst[2]-lst[3]==7:
    print(str(lst[0])+"+"+str(lst[1])+"+"+str(lst[2])+"-"+str(lst[3])+"=7")
elif lst[0]+lst[1]-lst[2]+lst[3]==7:
    print(str(lst[0])+"+"+str(lst[1])+"-"+str(lst[2])+"+"+str(lst[3])+"=7")
elif lst[0]+lst[1]-lst[2]-lst[3]==7:
    print(str(lst[0])+"+"+str(lst[1])+"-"+str(lst[2])+"-"+str(lst[3])+"=7")
elif lst[0]-lst[1]+lst[2]+lst[3]==7:
    print(str(lst[0])+"-"+str(lst[1])+"+"+str(lst[2])+"+"+str(lst[3])+"=7")
elif lst[0]-lst[1]+lst[2]-lst[3]==7:
    print(str(lst[0])+"-"+str(lst[1])+"+"+str(lst[2])+"-"+str(lst[3])+"=7")
elif lst[0]-lst[1]-lst[2]+lst[3]==7:
    print(str(lst[0])+"-"+str(lst[1])+"-"+str(lst[2])+"+"+str(lst[3])+"=7")
elif lst[0]-lst[1]-lst[2]-lst[3]==7:
    print(str(lst[0])+"-"+str(lst[1])+"-"+str(lst[2])+"-"+str(lst[3])+"=7")

Measured memory_bytes: 62192
n=gets.to_i
a=gets.split.map(&:to_i)
a.sort!
a.reverse!
b=[]
c=[]
n.times do |i|
  if i.even?
    b<<a[i]
  else
    c<<a[i]
  end
end
sumb,sumc=0,0
b.each {|i| sumb += i.to_i }
c.each {|i| sumc += i.to_i }
puts sumb-sumc

Measured memory_bytes: 1788