akhauriyash/Code-Regression huggingface dataset:
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Iterator;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	int[] discover;
	int[] finish;
	
	//adjacency list of edges
	public Graph() { 
			totalVertex = 0; 
		}
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		
		for(int i = 0; i < adjMatrix.length; i++) {
			for(int j = 0; j < totalVertex ; j++) {
				adjMatrix[i][j] = 0;
			}
		}
		
		int z = 0;
		//int j = 0;
		
		for(LinkedList<Integer> ll: this.adjList) {
			for(Integer ele : ll) {
				adjMatrix[z][ele] = 1;
			}
			z++;
		}
		
		for(int m = 0; m < adjMatrix.length; m++) {
			for(int n = 0; n < totalVertex; n++) {
				if(n == totalVertex - 1) {
					System.out.println(adjMatrix[m][n]);
				}
				else {
					System.out.print(adjMatrix[m][n] + " ");
				}
				//System.out.print(adjMatrix[m][n] + " ");
			}
		}
	}
	
	public int DFS(int v, int time) {
	    
//		if(discover[v] != -1) {
//			return time;
//		}
		
		discover[v] = time;
		for(Integer ele : this.adjList.get(v)) {
			if(discover[ele] == -1) {
				time += 1;
				time = DFS(ele, time);
			}
		}
			//finish[v] = time + 1;
		
		finish[v] = time + 1;
		return time + 1;
	}
	
	public void BFS() {
		//int iter = 0;
		Queue<Integer> q = new LinkedList<>();
		q.add(0);
		int[] distances = new int[totalVertex];
		distances[0] = 0;
		for(int i = 1; i < distances.length; i++) {
			distances[i] = -1;
		}
		while(q.isEmpty() != true) {
			int u = q.remove();
			//System.out.println(u+1);
			//iter += 1;
			for(Integer ele : this.adjList.get(u)) {
				//System.out.println(u);
				if(distances[ele] == -1) {
					q.add(ele);
					distances[ele] = distances[u]+1;
				}
			}
		}
		
		for(int i = 0; i < distances.length; i++) {
			System.out.println(i + 1 + " " + distances[i]);
		}
	}
	
	public void searchGraph() {
		this.discover = new int[totalVertex];
		for(int i = 0; i < discover.length; i++) {
			discover[i] = -1;
		}
		this.finish = new int[totalVertex];
		
		int dis_time = 0;
		
		for(int i = 0; i < totalVertex; i++){
			if(discover[i] == -1) {
				dis_time = DFS(i, dis_time);
				dis_time += 1;
			}
		}
		
		for(int i = 0; i < totalVertex; i++) {
			System.out.println(i + 1 + " " + (discover[i] + 1) + " " + (finish[i] + 1));
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		//g.BFS();
		//g.printAdjMatrix();
		g.searchGraph();
	}
}


Measured memory_bytes: 28544
a, b, c, d = map(int, input().split())

if a >= 0 and c >= 0:
    print(b*d)
elif a <= 0 and b >= 0 and c >= 0:
    print(b*d)
elif c <= 0 and d >= 0 and a >= 0:
    print(b*d)
elif a <= 0 and b >= 0 and c <= 0 and d >= 0:
    if b*d >= a*c:
        print(b*d)
    else:
        print(a*c)
elif a <= 0 and b >= 0 and d <= 0:
    print(a*c)
elif c <= 0 and d >= 0 and b <= 0:
    print(a*c)
elif b <= 0 and c >= 0:
    print(b*c)
elif a >= 0 and d <= 0:
    print(a*d)
elif b <= 0 and d <= 0:
    print(a*c)

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

int main(void) {
    constexpr long MOD = 998244353;

    long n, a, b, k;
    cin >> n >> a >> b >> k;

    auto inv = [&](){
        map<long,long> c;

        return [&, c](long a) mutable {
            long r = 1, b = MOD-2;
            while(b) {
                if(b&1) r *= a, r %= MOD;
                a *= a, a %= MOD;
                b >>= 1;
            }
            return r;
        };
    }();

    auto comb = [&](){
        map<long,long> c;

        return [&, c](long _, long b) mutable {
            if(c.count(b)) return c[b];

            long a = n;
            long r = 1;
            for(long i=0; i<=n; i++)
                c[i] = r, r *= a-i, r %= MOD, r *= inv(i+1), r %= MOD;
            return c[b];
        };
    }();

    long r = 0;
    for(long x=0; x<=n; x++) {
        if((k-x*a)%b) continue;
        long y = (k - x*a)/b;
        if(y < 0) continue;
        if(y > n) continue;

        // ax + by == k
        r += (comb(n, x) * comb(n, y)) % MOD;
        r %= MOD;
    }
    cout << r << endl;
}


Measured memory_bytes: 18944
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int arr[101][101] = {0};

int main()
{
	int n, k, t=0;
	cin >> n >> k;
	while(n > 0)
	{
		n /= k;
		t++;
	}
	cout << t;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
    // Your code here!
    int X,max,i,p;
    max = 1;
    
    scanf("%d",&X);
    if(X >= 4){
        for(i = 2; i <= (int)sqrt(X); i++)
        {
            p = 2;
            while(pow(i,p) <= X) p++;
            if(pow(i,p-1) > max) max = pow(i,p-1);
        }
    }
    
    printf("%d\n",max);
}


Measured memory_bytes: 128
K = int(input())

def gcd(a, b) :
  if b > a : 
    a, b = b, a
  
  while b != 0 :
    a, b = b, a % b
  return a

ret = 0

x = [0] * (K + 1)
for a in range(1, K + 1) :
  for b in range(1, K + 1) :
    x[gcd(a, b)] += 1

for c in range(1, K + 1) :
  for d in range(1, K + 1) :
    ret += gcd(c, d) * x[d]
    
print(ret)

Measured memory_bytes: 68208
#include<stdio.h>

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

  int ko=0;
  int time=0;
  do{
    time += t;
    ko += x;
  }while(ko<n);

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

  return 0;
}


Measured memory_bytes: 1728
N, W = map(int, input().split())

w, v = [0]*N, [0]*N
for i in range(N):
    w[i], v[i] = map(int, input().split())
V = sum(v)

dp = [[float("inf")] * (V + 1) for _ in range(N + 1)]
dp[0][0] = 0

for i in range(N):
    for j in range(V+1):
        if j - v[i] >= 0:
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j - v[i]] + w[i])
        
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

ans = 0
for i in range(V+1):
    if dp[N][i] <= W:
        ans = i
print(ans)  

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

using ll = long long;

vector<int> A, B, p, C;
int N;

void check() {
	for (int i = 0; i < N-1; i++) assert(A[i] < A[i+1]);
	for (int i = 0; i < N-1; i++) assert(B[i] > B[i+1]);
	for (int i = 0; i < N-1; i++) assert(A[p[i]] + B[p[i]] < A[p[i+1]] + B[p[i+1]]);
}

int main() {
	cin >> N;
	A.resize(N);
	B.resize(N);
	p.resize(N);
	C.resize(N);
	for (int i = 0; i < N; i++) cin >> p[i], p[i]--;
	for (int i = 0; i < N; i++) {
		C[p[i]] = i;
	}
	for (int i = 1; i <= N; i++) {
		A[i-1] = i * 50000;
		B[i-1] = (N-i+1) * 50000;
	}
	for (int i = 0; i < N; i++) {
		A[i] -= N - C[i];
	}
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	for (int i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << B[i];
	}
	cout << endl;
	check();
}

Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <ctime>
#include <iomanip>
#include <set>
#include <iterator>
#include <map>
#include <assert.h>
using namespace std;

#define pb push_back

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define for1(i, n) for(int i = 1; i <= (int)(n); i++)

using ll = long long;

typedef vector<int> vi;

const int INF = 1e9 + 5;

const int nax = 1e5 + 5;

vector<int> edges[nax];
int in_degree[nax];
int dist[nax];
bool is_visited[nax];

void dfs(int a)
{
	assert(!is_visited[a]);
	is_visited[a] = true;
	for (int b : edges[a])
	{
		dist[b] = max(dist[b], dist[a] + 1); //
		in_degree[b]--;
		if (in_degree[b] == 0)
			dfs(b);
	}
}

int main()
{
	int n, m;
	cin >> n >> m;
	while (m--)
	{
		int a, b;
		cin >> a >> b;
		edges[a].push_back(b);
		in_degree[b]++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (!is_visited[i] && in_degree[i] == 0)
			dfs(i);
	}
	int ans = 0;
	for (int i = 1; i <= n; i++)
		ans = max(ans, dist[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9728
# 参考 : https://at274.hatenablog.com/entry/2020/01/15/060000
from functools import reduce
import math


def lcm(x, y):
    return (x * y) // math.gcd(x, y)


def lcm_list(numbers):  # リストを投げると全要素のlcmが返ってくる
    return reduce(lcm, numbers, 1)


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

# 最初、Aの要素は全て偶数。2で割ったものに置き換え
A = [a // 2 for a in A]

# 全ての要素について、２で割れる回数が同じでないと題意は満たせない
count_div_2 = None
for a in A:
    cnt = 0
    while a % 2 == 0:
        a //= 2
        cnt += 1
    # 1個目は無条件で保存
    if count_div_2 is None:
        count_div_2 = cnt
    # 2個目からチェック
    elif cnt != count_div_2:
        print(0)
        exit()

# my_lcm = Aの全要素の最小公倍数。　この奇数倍が題意を満たす。
# my_lcmがMを超えていたら1つも作れない
my_lcm = lcm_list(A)
if my_lcm > M:
    print(0)
    exit()

tmp = M // my_lcm
# my_lcmの1,2,...M倍まで使えるが、偶数は使えない
# tmp=1or2なら1個, 3or4なら2個, 5or6なら3個,...
ans = (tmp + 1) // 2
print(ans)


Measured memory_bytes: 20252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

//全ての要素に対して自身が根となるように初期化, 木の深さは0になる
struct UnionFind{
public:
	vector<int> par;
	vector<int> rank;
	vector<int> s;
	int cnt;
 
	UnionFind(int n){
		rep(i,n){
			par.push_back(i);
			rank.push_back(0);
			s.push_back(1);
		}
		cnt=n;
	}
 
	int find(int x){
		if(par[x]==x) return x;
		else return par[x]=find(par[x]);
	}
 
	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y) return;
		if(rank[x]<rank[y]){
			par[x]=y;
			s[y]+=s[x];
		}else{
			par[y]=x;
			s[x]+=s[y];
			if(rank[x]==rank[y]) rank[x]++;
		}
		cnt--;
	}

	bool same(int x,int y){
		return find(x)==find(y);
	}

	int size(int x){
		return s[find(x)];
	}
};

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	vector<int> p(n),ind(n);
	UnionFind uf(n);
	rep(i,n){
		cin>>p[i];
		p[i]--;
		ind[p[i]]=i;
	}
	rep(i,m){
		int x,y;
		cin>>x>>y;
		x--,y--;
		uf.unite(x,y);
	}
	int ans=0;
	rep(i,n){
		if(uf.same(i,ind[i])){
			ans++;
		}
	}
	cout<<ans<<endl;
}

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

#define task "A"
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define pb push_back
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;

typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;

// Limit

// Struct

// Variables
int n,k,a[100004],res;
// Function

int main()
{
	//freopen(task".in","r",stdin);
	//freopen(task".out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(nullptr);
	cin >> n >> k;
	rep(i,1,n)
	{
	    cin >> a[i];
	    if (a[i]>=k) res++;
	}
	cout << res;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
#define all(x) x.begin(), x.end()
#ifdef _DEBUG
#define dd(x) cout << #x << " : " << x << endl
#else
#define dd(x)
#endif
using namespace std;
using ll = int64_t;

const ll mod = 1e9+7;
struct mint
{
    ll x;
    mint(ll x=0) : x((x%mod+mod)%mod){}
    mint operator-() const {return mint(-x);}
    mint& operator+=(const mint a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    ll val(){ return x; }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}

    friend istream& operator>>(istream& is, mint& a) { return is >> a.x;}
    friend ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
};

int main(){
    int n; cin >> n;
    vector<ll> c(n);
    rep(i, n) cin >> c[i];

    sort(all(c));

    vector<mint> two(n+1);
    two[0] = 1;
    rep(i, n) two[i+1] = two[i]*2;

    mint ans = 0;
    rep(i, n) {
        int l = i, r = n - 1 - i;
        mint tmp = 0;
        tmp += two[r];
        if(r) tmp += two[r-1]*r;
        tmp *= two[l];
        tmp *= c[i];
        ans += tmp;
    }
    ans *= two[n];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6436
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		if(k==1) System.out.println(0);
		else {
			System.out.println((n - (k-1)) - 1);
		}
	}
}

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

template<typename T> void drop(const T &x){cout<<x<<'\n';exit(0);}

void solve() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i = 0; i <= a; ++i) {
    for(int j = 0; j <= b; ++j) {
      for(int k = 0; k <= c; ++k) {
        if(i*500 + j*100 + k*50 == x) ans++;
      }
    }
  }
  cout << ans << '\n';
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt=1;
  //cin >> tt;
  while(tt--) solve();

  return 0;
}


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

ll check_bit(ll x, int i) { return (x & (1LL << i)); }

vector<ll> v;
ll gaussian_elimination() {
  int n = v.size();
  int ind = 0; // Array index
  for (int bit = 60; bit >= 0; bit--) {
  // for (int bit = log2(v[0]); bit >= 0; bit--) {
    int x = ind;
    while (x < n && check_bit(v[x], bit) == 0) x++;
    if (x == n) continue; // skip if there is no number below ind where current bit is 1
    swap(v[ind], v[x]);
    for (int j = 0; j < n; j++) {
      if (j != ind && check_bit(v[j], bit)) v[j] ^= v[ind];
    }
    ind++;
  }
  ll ans = v[0];
  for (int i = 1; i < n; i++) ans = max(ans, ans ^ v[i]);
  return ans;
}

void solve() {
  int n;
  cin >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll x = 0;
  rep(i, n) x ^= a[i];
  dump(a);
  ll ans = x;
  dump(x);
  rep(i, n) a[i] &= ~x;
  rep(i, n) v.push_back(a[i]);
  ll m = gaussian_elimination();
  dump(a);
  dump(v);
  dump(m);
  ans += m * 2;
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 2296
s = tuple(str(input()))

c = 0
f = True

for i in s:
  c += 1
  if c % 2 != 0:
    if i == 'L':
      f = False
      break
  else:
    if i == 'R':
      f = False
      break

if f:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int main() {
    int N; cin >> N;
    pii reds[N], blues[N];

    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        reds[i] = make_pair(x, y);
    } 
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        blues[i] = make_pair(x, y);
    } 

    sort(reds, reds + N, [](pii a, pii b) {
        return a.second > b.second;
    }); 
    sort(blues, blues + N, [](pii a, pii b) {
        return a.first < b.first;
    });

    int ans = 0;
    for (pii blue : blues) {
        for (pii& red : reds) {
            if (red.first < blue.first && red.second < blue.second) {
                ans++;
                red = make_pair(1000, 1000);
                break;
            }
        }
    }

    cout << ans << endl;
}

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

int main() {
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 1;
  char c = S[0];
  for (int i = 1; i < N; ++i) {
    if (c != S[i]) {
      ++ans;
      c = S[i];
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include<vector>
typedef long long ll;
using namespace std;
int main() {
    long long n;
    cin >> n;
    vector<long long > v(n+1,0);
    for(long i=1;i<=n;i++)
    {
        for(ll j=i;j<=n;j+=i)
        v[j]++;
    }
    unsigned long long sum=0;
    for(int i=1;i<=n;i++)
    {
        sum+=(unsigned long long)(i*v[i]);
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 81372
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int cmp(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}


int main(){
  int n;
  int i;
  int max;
  double mid;
  int ans=-10000;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  qsort(a,n,sizeof(int),cmp);
  max=a[n-1];
  mid=(double)max/2;
  for(i=0;i<n;i++){
    ans=(abs((double)ans-mid)>abs((double)a[i]-mid))?a[i]:ans;
  }
  printf("%d %d",max,ans);
  return 0;
}


Measured memory_bytes: 892
import sys
input = sys.stdin.readline

n, q = map(int, input().split())
edges = [[] for _ in range(n)]
for _ in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

count = [0]*n
for _ in range(q):
    p, x = map(int, input().split())
    count[p-1] += x

stack = [0]
visited = [0]*n
while stack:
    v = stack.pop()
    visited[v] = 1
    for v2 in edges[v]:
        if visited[v2] == 1:
            continue
        count[v2] += count[v]
        stack.append(v2)

print(*count)


Measured memory_bytes: 55856
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
struct num {//怪物坐标和生命
	long long x;
	long long h;
};
vector<num> abc;
bool cmp(num a1, num a2) {
	return a1.x < a2.x;//按坐标从小到大排
}
int main() {
	int n;
	long long d, a;
	cin >> n >> d >> a;
	long long count = 0;
	for (int i = 0; i < n; i++) {//每个怪物入vector
		num a;
		cin >> a.x >> a.h;
		abc.push_back(a);
	}
	sort(abc.begin(), abc.end(), cmp);//坐标从小到大，排序
	vector<num>::iterator it=abc.begin();//代表第一个活着的怪兽
	long long endx = abc.back().x;//最末尾怪兽的坐标
	while (1) {//最大坐标怪物没死
		long long j = 0;//炸死第一个活着怪兽的炸弹数目
		j = (it->h) / a;
		if (it->h%a != 0) j++;//如果刚好整除，那么需要炸弹数目为直接整除，否则加一
		long long hurt = j * a;//炸弹的总伤害
		long long tempx = it->x + 2 * d;//最大爆炸范围
		for (auto i = it; i->x <= tempx; i++)//从第一个活着的怪兽开始
		{
			if (i->h>0) i->h -= hurt;
			if (i->x == endx) break;//当到最后一个break,防止越界
		}//每个范围内怪物减少生命
		count += j;//炸弹总数更新
		for (; it->h <= 0&&it->x!=endx; it++) ;//it更新为第一个活着的怪兽
		//此时it有两种情况
		//第一个活着的怪兽
		//或者为最后一个怪兽（不论死活）,然后while会判断，最后一个怪兽还活着吗
		if (it->x + 2 * d >= endx) {
			int max = 0;
			for (auto i = it; ; i++) {
				if (i->h > max) max = i->h;
				if (i->x == endx)
					break;
			}
			long long j = max / a;
			if (max%a) j++;
			count += j;
			break;
		}
	}
	cout << count;
}

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

const int mod=998244353;

int n,k;
int l[15],r[15];
int bit[200005];

int sum(int pos){
    int res=0;
    while(pos>0){
        res=(res+bit[pos])%mod;
        pos-=pos&-pos;
    }
    return res;
}

void add(int pos,int val){
    while(pos<=n){
        bit[pos]=(bit[pos]+val)%mod;
        pos+=pos&-pos;
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n>>k;
    for(int i=1;i<=k;i++){
        cin>>l[i]>>r[i];
    }
    add(1,1);
    add(2,mod-1);
    for(int i=1;i<n;i++){
        int cur=sum(i);
        for(int j=1;j<=k;j++){
            add(i+l[j],cur);
            add(i+r[j]+1,mod-cur);
        }
    }
    cout<<sum(n)<<endl;

    return 0;
}

Measured memory_bytes: 4376
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    char c;
    cin>>c;
    cout<<(char)(c+1);
}

Measured memory_bytes: 3600
<?php
for($i=0;$i<3;$i++){
    fscanf(STDIN, "%d%d%d", $b[$i][0],$b[$i][1],$b[$i][2]);
}
fscanf(STDIN, "%d", $N);
while($N--){
    fscanf(STDIN, "%d", $target);
    for($i=0;$i<3;$i++){
        for($j=0;$j<3;$j++){
            if($b[$i][$j] == $target){
                $b[$i][$j] = -1;
            }
        }
    }
}

if($b[0][0] == -1){
    if($b[1][0] == -1 && $b[2][0] == -1){
        echo "Yes";
        exit;
    }elseif($b[0][1] == -1 && $b[0][2] == -1){
        echo "Yes";
        exit;
    }elseif($b[1][1] == -1 && $b [2][2] == -1){
        echo "Yes";
        exit;
    }
}
if($b[1][0] == -1){
    if($b[1][1] == -1 && $b[1][2] == -1){
        echo "Yes";
        exit;
    }
}
if($b[2][0] == -1){
    if($b[2][1] == -1 && $b[2][2] == -1){
        echo "Yes";
        exit;
    }elseif($b[1][1] == -1 && $b[0][2] == -1){
        echo "Yes";
        exit;
    }
}
if($b[0][1] == -1){
    
    if($b[1][1] == -1 && $b[2][1] == -1){
        echo "Yes";
        exit;
    }
}
if($b[0][2] == -1){
    if($b[1][2] == -1 && $b[2][2] == -1){
        echo "Yes";
        exit;
    }
}
echo "No";

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  llong N, M;
  vector<llong> n(4, -1);

  cin >> N >> M;
  for (int i = 0; i < M; ++i) {
    llong s, c;
    cin >> s >> c;

    if (n[s] == -1) {
      n[s] = c;
    }
    else if (n[s] != c) {
      cout << -1 << endl;
      return 0;
    }
  }

  llong ans = 0;
  if (N > 1 && n[1] == 0) {
    ans = -1;
  }
  else if (N == 1) {
    ans = max(0ll, n[1]);
  }
  else {
    ans = pow(10, N - 1) * max(1ll, n[1]);
    for (int i = 2; i <= N; ++i) {
      ans += pow(10, N - i) * max(0ll, n[i]);
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMaximalValue solver = new CMaximalValue();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMaximalValue {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] b = in.readIntArray(n - 1);

            int[] a = new int[n];
            a[0] = b[0];
            a[n - 1] = b[n - 2];

            for (int i = 1; i < n - 1; i++) {
                a[i] = Math.min(b[i - 1], b[i]);
            }

            long answer = 0;
            for (int x : a)
                answer += x;

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }
}



Measured memory_bytes: 23124
/*
 * Author : Sadi
 * Thu 09/07/2020
 * 21:53:16.66
 */
#include <iostream>
#include <cstdio>
#include <cmath>
#include <climits>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>

using namespace std;

#define    watch(x); cout << "\n" <<  #x << " is: " << x << "\n";
#define    all(a) (a).begin(), (a).end()
#define    fi first
#define    se second

template<class A, class B>
ostream& operator << (ostream& output, const pair<A, B>& p) {
    output << "(" << p.first << ", " << p.second << ")";
    return output;
}

template<class A>
ostream& operator << (ostream& output, const vector<A>& a) {
    output << "[";
    for(auto it = a.begin(); it != a.end(); ++it) {
        if(it != a.begin()) {
            output << ", ";
        }
        output << *it;
    }
    output << "]";
    return output;
}

using lld = long long;
using pii = pair<int, int>;
using pll = pair<lld, lld>;

//const int inf = 1e9;
//const int mod = 1e9 + 7;
//const double PI = acos(-1.0);
//const int mx = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    string s;
    cin >> s;
    int count = 0;
    for(int i = 0, j = 1; i < (int) s.size() or j < (int) s.size(); i += 2, j += 2) {
        if(s[i] == 'R' or s[i] == 'U' or s[i] == 'D') {
            count++;
        }
        if(s[j] == 'L' or s[j] == 'U' or s[j] == 'D') {
            count++;
        }
    }
    if(count == (int) s.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3648
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int N;
int A[101];
int B[101];
int main() {
	cin>>N;
	int R[101]={};
	int L[101]={};
	for(int i=1;i<N+1;i++){
		cin>>A[i];
		R[i]=R[i-1]+A[i];
	}
	for(int i=1;i<N+1;i++){
		cin>>B[i];
		L[i]=L[i-1]+B[i];
	}

	int total=0;
	for(int i=1;i<N+1;i++){
		total=max(total,R[i]+L[N]-L[i-1]);
	}

	cout<<total<<endl;
 	return 0;
}


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

using namespace std;

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  bool f = false;
  if(a[0] + a[1] == a[2] or a[0] == a[1] + a[2] or a[0] + a[2] == a[1]) f = true;
  if(f) cout << "Yes";
  else cout << "No";
}


Measured memory_bytes: 256
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;
import std.container;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
long binarySearch(long min, long max, bool delegate(long) f){
	if(!f(min)) return min - 1; if(f(max)) return max;
	long mid; while(max - min > 1){ mid = min + (max - min) / 2; if(f(mid)) min = mid; else max = mid; } return min;
	}

bool check(long x){
	writeln("? ", x);
	stdout.flush;
	return (readln.chomp == "Y");
	}

void main(){
	
	long[] ms = [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000];
	
	long ans;
	if(check(ms[10])){ // 10...0 の形である
		foreach(m; ms){
			if(check(m + 1)){
				ans = m;
				break;
				}
			}
		}
	else{
		foreach(m; ms){
			if(!check(m * 10)){
				ans = binarySearch(m, m * 10 - 1, x => !check(x * 10)) + 1;
				break;
				}
			}
		}
	
	writeln("! ", ans);
	}




Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m,n,cnt=0;
    char str[10000];
    cin>>m>>n;
    cin>>str;
    for(int i=0;i<strlen(str);i++)
    {
        if(str[i]=='-')cnt++;
    }
    int flag=0;
    if(cnt>1 || cnt<1)flag=1;
    else if(str[m]!='-')flag=1;
    if(flag==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.length() > k) {
    cout << s.substr(0, k) + "..." << endl;
  } else {
    cout << s << endl;
  }
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
using namespace std;
#define ll long long
#define db double
int main()
{
    ll s=0;
    scanf("%lld",&s);
    ll x1=0;
    ll y1=0;
    ll x2=1;
    ll y2=1e9;
    ll x3=s/y2+(s%y2!=0);
    ll y3=y2*x3-s;
    printf("%lld %lld %lld %lld %lld %lld",x1,y1,x2,y2,x3,y3);
    return 0;
}



Measured memory_bytes: 3792
// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/


#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define LET(x, a)  __typeof(a) x(a)
#define foreach(it, v) for(LET(it, v.begin()); it != v.end(); it++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define inf 1000000000000000001

#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

#define int ll



int32_t main(){ _
	int n;
	cin >> n;
	lld t, a;
	cin >> t >> a;
	lld diff_m = 99999999;
	int ind = -1;
	for(int i = 0; i < n; i++){
		int temp;
		cin >> temp;
		lld avg = t - (0.006)*temp;
		lld diff = abs(avg - a);
		if(diff < diff_m){
			diff_m = diff;
			ind = i;
		}
	}
	cout << ind + 1 << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________

	int n;
	cin >> n;
	vi a(n, 0);
	zip(i, 0, n)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int cnt = 0;
	zip(i, 0, n)
	{
		zip(j, i + 1, n)
		{
			int x = a[i] + a[j];
			auto itr = lower_bound(a.begin() + j + 1 , a.end(), x);
			itr--;
			int y = itr - a.begin();
			if ( *itr < x)
			{
				cnt += (y - j);
			}
		}
	}
	cout << cnt << en;

	return 0;
}


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

fcount=0
tcount=0

for i in range(n):
    if a[i]%4==0:
        fcount+=1
    elif a[i]%2==0:
        tcount+=1

ocount=n-(fcount+tcount)

if fcount+tcount>=n:
    print("Yes")
elif ocount<=n//2 and ocount<=fcount:
    print("Yes")
elif n%2!=0 and fcount>=n//2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 20116
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVL vector<vector<ll>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr ll MOD = 1000000007;
using std::cout;
using std::endl;
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::multiset;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2 == 1) {
			ans *= a;
			ans %= MOD;
		}
		b /= 2;
		a *= a;
		a %= MOD;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a - b < b) { return comb(a, a - b); }
	static unordered_map<ll, ll> memo;

	ll c = 1;
	FOR(i, a - b + 1, a + 1) {
		c *= i;
		c %= MOD;
	}
	if (memo.find(b) == memo.end()) {
		ll k = 1;
		FOR(i, 2, b + 1) {
			k *= i;
			k %= MOD;
		}
		memo[b] = pow(k, MOD - 2);
	}
	c *= memo[b];
	return c % MOD;
}
multiset<ll> prime_decomposition(ll n) {
	ll i = 2;
	multiset<ll> table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace(n);
		return table;
	}
	return table;
}
/*
-- bit --
REP(i, (1 << n)) {
	REP(j, n) {
		cout << (1 & (i >> j));
	}
	cout << endl;
}
*/

bool in(ll x1, ll y1, ll x2, ll y2, ll xn, ll yn) {
	return (x1 <= xn && xn <= x2 && y1 <= yn && yn <= y2);
}

int main() {
	ll n, k;
	cin >> n >> k;

	VL v(n);
	REP(i, n) { cin >> v[i]; }

	VL p(n + 1);
	REP(i, n) {
		p[i + 1] = p[i] + v[i];
	}

	vector<std::bitset<40>> bitList;
	bitList.reserve(n*(n + 1) / 2);
	REP(i, n)FOR(j, i, n) {
		bitList.emplace_back(std::bitset<40>(p[j + 1] - p[i]));
	}



	RREP(i, 40) {
		ll count = 0;
		list<int> itr;
		REP(j, bitList.size()) {
			if (bitList[j][i] == 1) {
				++count;
				itr.emplace_back((int)j);
			}
		}
		if (count >= k) {
			vector<std::bitset<40>> newBitList;
			bitList.reserve(n*(n + 1) / 2);
			REPC(j, itr) {
				newBitList.emplace_back(bitList[j]);
			}
			bitList = move(newBitList);
		} 
		if (count == k) {
			std::bitset<40> ans = bitList[0];
			REPC(y, bitList) {
				ans = y & ans;
			}
			cout << ans.to_ullong() << endl;
			return 0;
		}
	}

	std::bitset<40> ans = bitList[0];
	REPC(x, bitList) {
		ans = x & ans;
	}
	cout << ans.to_ullong() << endl;
}

Measured memory_bytes: 8824
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll n,ll m,ll x)
{
    KAKA
    vector<ll> cost(n);
    ll algo[n][m];
    pragi(0,n)
    {
        cin>>cost[i];
        pragj(0,m)
        {
            cin>>algo[i][j];
        }
    }
    /*pragi(0,n)
    {
        pragj(0,m)
        {
            cout<<algo[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    vector<ll> vec;
    vector<ll> skill(m,0);
    ll tot = (1ll << n);
    for(ll mask = 0;mask < tot;mask++)
    {
        /*pragj(0,m)
        {
            cout<<skill[j]<<" ";

        }*/
       // cout<<"\n";
       ll cst = 0;
        for(ll i = 0;i < n;i++)
        {
            ll f = (1ll << i);
            if(mask & f)
            {
                cst += cost[i];
             pragj(0,m)
             {
                 skill[j] += algo[i][j];
             }
            }
        }
        //cout<<cst<<"\n";
        //pragi(0,m)
       // cout<<skill[i]<<" ";
        //cout<<"\n";
        bool flag = true;
       pragj(0,m)
        {
            if(skill[j] < x)
            {
                flag = false;
                break;
            }
        }
        if(flag) vec.eb(cst);
        skill.clear();
        skill.resize(m,0);

    }
    if(!vec.empty()){ll minimcst = *min_element(vec.begin(),vec.end());
    cout<<minimcst<<"\n";}
    else cout<<-1<<"\n";
}
int main()
{
    KAKA
    ll n,m,x;
    cin>>n>>m>>x;
    Compute(n,m,x);
}

Measured memory_bytes: 3696
#include<stdio.h>

int main(){
    int h,w;
    while(scanf("%d %d",&h,&w) && (h != 0 || w != 0)){
        for(int i=0;i < h;i++){
            printf("#");
            for(int j=0;j < w -2 ;j++){
                if(i == 0 || i == h-1){
                    printf("#");
                } else{
                    printf(".");
                }
            }
            printf("#\n");
        }
        printf("\n");
    }
    return 0;
}




Measured memory_bytes: 2680
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int cnt = 0;
  REP(i,m){
    int a; cin >> a;
    if(a<x) cnt++;
  }
  cout << min(cnt,m-cnt) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String luckyNum = sc.next();
		HashSet<String> lockNumSet = new HashSet<>();
		for (char first = '0'; first <= '9'; first++) {
			boolean firstFlag = false;
			int firstIndex = 0;
			for (int i = 0; i < n - 2; i++) {
				if (first == luckyNum.charAt(i)) {
					firstFlag = true;
					firstIndex = i;
					break;
				}
			}
			if (!firstFlag) {
				continue;
			}
			for (char second = '0'; second <= '9'; second++) {
				boolean secondFlag = false;
				int secondIndex = 0;
				for (int i = firstIndex + 1; i < n - 1; i++) {
					if (second == luckyNum.charAt(i)) {
						secondFlag = true;
						secondIndex = i;
						break;
					}
				}
				if (!secondFlag) {
					continue;
				}
				for (char third = '0'; third <= '9'; third++) {
					boolean thirdFlag = false;
					for (int i = secondIndex + 1; i < n; i++) {
						if (third == luckyNum.charAt(i)) {
							thirdFlag = true;
							break;
						}
					}
					if (thirdFlag) {
						String newLock = first + "" + second + "" + third;
						lockNumSet.add(newLock);
					}
				}
			}
		}
		System.out.println(lockNumSet.size());
	}
}


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

int main() {
	long long int n,d;
	cin>>n>>d;
	long long dist=d*d;
	long long x1,y1;
	long long x,y;
	int count=0;
	for(int i=0;i<n;i++){
		cin>>x>>y;
		x1=x*x;
		y1=y*y;
		
		if(x1+y1<=dist)
		  count++;
	}
	cout<<count;
	// your code goes here
	return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
long long n,a[200],k,x,t,j;

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n;
for(int i=0;i<n;i++){
    cin>>a[i];
    if(a[i]%2!=0)k++;}
    if(k>0)cout<<0;
    else {
            for( j=1;j<200;j++){

        for(int i=0;i<n;i++){
            if(a[i]%2==0){
                a[i]/=2;t++;

                if(a[i]%2!=0)x++;
            }

        }if(x>0)break;
        }
        cout<<j;
    }

}



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		double[] x = new double[n];
		String[] u = new String[n];
		
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextDouble();
			u[i] = sc.next();
		}
		
		double sumjp = 0;
		double sumbt = 0;
		for(int i = 0; i < n; i++) {
			if(u[i].equals("JPY"))	sumjp += x[i];
			else	sumbt += x[i]*380000.0;
		}
		
		
		System.out.println(sumjp + sumbt);
		
		sc.close();
	}

}

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

int main() {
	string s;
	cin >> s;
	vector<char> c;
	for (int i=0; i<4; i++) c.push_back(s[i]);
	sort(c.begin(),c.end());
	if (c[0]==c[1] && c[2]==c[3] && c[1]!=c[2]) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
# D - Ki

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

children = [[] for _ in range(N)]
points = [0] * N

for _ in range(N - 1):
    a, b = map(int, input().split())
    children[a - 1].append(b - 1)
    children[b - 1].append(a - 1)

for _ in range(Q):
    p, x = map(int, input().split())
    points[p - 1] += x

stack = []
stack.append(0)
visited = [False] * N
while stack:
    key = stack.pop()
    for child in children[key]:
        if visited[child] == True:
            continue
        points[child] += points[key]
        visited[key] = True
        stack.append(child)

print(*points)


Measured memory_bytes: 55824
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define deb(a) cout << a << ": "
using namespace std;
const int inf = 1e18 + 7;
const int N = 1e6 + 7;
const int md = 1e9 + 7;
void sliczny() {
  int d, t, s;
  cin >> d >> t >> s;
  d = d / s + (d % s > 0);
  if(d <= t) {
    cout << "Yes";
  }
  else cout << "No";
}

int32_t main() 
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  //cin >> T; 
  for(int t = 1; t <= T; t++) {
    //cout << "Case #" << t << ": ";
    sliczny();
  }
  return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

#define FOR(i, n, m) for (int i = (n); i < (m); ++i)
#define FORR(i, n, m) for (int i = (m)-1; i >= (n); --i)

ll N, S;

ll f(ll n, ll x) {
  ll res = 0;
  while (x) res += x%n, x/=n;
  return res;
}

int main() {

  cin >> N >> S;
  if (N == S) {
    cout << N+1 << endl;
    return 0;
  }
  if (N < S) {
    cout << -1 << endl;
    return 0;
  }

  ll K = (ll)sqrt(N);

  FOR (k, 2, K+2) if (f(k, N) == S) {
      cout << k << endl;
      return 0;
  }

  FORR (p, 1, K+10) {
    ll q = S - p;
    ll b = (N-q)/p;
    if (b == 1) continue;
    if (f(b, N) == S) {
      cout << b << endl;
      return 0;
    }
  }
  if (S == 1) {
    cout << N << endl;
    return 0;
  }

  cout << -1 << endl;
  return 0;

}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		String t = sc.next();
		String buff = "";
		if(t.substring(k-1,k).equals("A")) {
			buff = "a";
		}else if(t.substring(k-1,k).equals("B")) {
			buff = "b";
		}else{
			buff = "c";
		}

		System.out.println(t.substring(0,k-1)+buff+t.substring(k,n));
	}
}




Measured memory_bytes: 21716