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

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

  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    s.insert(a);
  }
  if(s.size() == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define ll long long
#define SZ(vvv) ((int)vvv.size())
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

const int N = 5e1 + 5, M = 5e2 + 9, MOD = 1e9 + 7;

void runtestcase() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while(k) {
		if(b <= a) {
			b *= 2;
			--k;
			continue;
		}
		if(c <= b) {
			c *= 2;
			--k;
			continue;
		}
		break;
	}
	bool can = (b > a) && (c > b);
	if(can) cout << "Yes";
	else cout << "No";
}


int main() {
	fastIO;
#ifdef LOCAL
	freopen("input.in", "rt", stdin);
//	freopen("output.in", "wt", stdout);
#endif
	int t = 1, tt = 1;
//	cin >> t;
	while(t) {
//		cout << "Case #" << tt << ':' << '\n';
		runtestcase();
		--t, ++tt;
//		cout << '\n';
	}
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
// ascending order
#define asort(array, N) sort(array, array + N)
// descending order
#define asort_r(array, N) sort(array, array + N, greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

ll N;

ll calculateDigit(ll n) {
	ll ans = 0;
	while(n > 0) {
		n /= 10;
		ans += 1;
	}
	return ans;
}

ll F(ll a, ll b) {
	return max(calculateDigit(a), calculateDigit(b));
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> N;
	
	ll ans = INF;
	for(ll a = 1; a <= sqrt(N); a++) {
		if(N % a == 0) {
			ll b = N / a;
			ans = min(ans, F(a, b));
		}
	}
	cout << ans << endl;


}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<string, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>v(n);
	rep(i, n) {
		cin >> v[i];
	}
	ll ans(0);
	rep(l, k+1) {
		rep(r, k - l+1) {
			vector<ll>have;
			int d = k - r - l;
			if (l + r > n)continue;
			rep(i, l)have.push_back(v[i]);
			rep(j, r)have.push_back(v[n - j - 1]);
			sort(have.begin(), have.end());
			rep(p, d) {
				if (p >= have.size())break;
				if (have[p] < 0)have[p] = 0;
			}
			ll can(0);
			rep(p,have.size()) {
				can += have[p];
			}
			ans = max(ans, can);
		}
	}
	cout << ans;
	return 0;
	return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <numeric>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;

static const double pi = 3.141592653589793;

int main(){
    double A, B;
    double H, M;
    double radA, radB;
    double time;
    double ans;

    cin >> A >> B >> H >> M;

    time = M + 60 * H;

    radA = time * pi / 360.0;
    radB = time * pi / 30.0;

    ans = sqrt(A * A + B * B - 2 * A * B * cos(abs(radB - radA)));

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}


Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main(void) {
	string str;
	cin >> str;
	if (((str[0]==str[1])&&(str[1]==str[2]))||((str[1]==str[2])&&(str[2]==str[3]))) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;

int main() {
    int m;
    int d;
    cin >> m >> d;
    int ans = 0;
    for (int month = 1; month <= m; month++) {
        for (int i = 22; i <= d; i++) {
            int ds = i % 10;
            int df = i / 10;
            if (df >= 2 && ds >= 2 && df * ds == month) ++ans;
        }
    }
    cout << ans;
    return 0;
}


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

#define ll          long long
#define F           first
#define S           second
#define pb          push_back
#define mp          make_pair
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    // cin>>t;
    while(t--)
    {
        cout<<setprecision(15);
        ll n;
        cin>>n;
        vector<double> v(n+1);
        v[0]=0.0;
        for (int i = 1; i <= n; ++i)
        {
            cin>>v[i];
        }

        // ll cnt?=0;
        double one=1.0;
        double dp[n+1][n+1]={0.0 };
        // ll cnt[n][2]={0 };

        dp[1][0]=one-v[1];
        // cnt[0][0]=0;
        dp[1][1]=v[1];
        // cnt[0][1]=1;

        for (int i = 2; i <= n; ++i)
        {
            dp[i][0]=dp[i-1][0]*(one-v[i]);
            for(int j=1;j<=i;j++)
            {
                dp[i][j]=(dp[i-1][j]*(one-v[i]))+(dp[i-1][j-1]*v[i]);
            }
        }

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

        cout<<ans;

        
    }

    
    time
    return 0;
}

Measured memory_bytes: 74060
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

// computational complexity : O(E*logV)

struct edge{ int to, cost; };

int V,E;// number of (vertices, edges)
vector<vector<edge>> graph;
vector<int> d;// shortest distances

void Dijkstra(int s){// s = starting point
    priority_queue<
        pair<int, int>// temporarily keeping (shortest distance, vertex)
        , vector<pair<int, int>>, greater<pair<int, int>>// shorter ones first
    > pq;

    // initialize (INF)
    for(int i=0; i<V; i++){
        d[i] = INF;
    }
    d[s] = 0;
    pq.push({0,s});

    // search
    pair<int, int> current;// (shortest-distance confirmed, vertex)
    while(!pq.empty()){
        current = pq.top(); pq.pop();

        int v = current.second;
        if(d[v] < current.first){
            continue;// ignore (not the shortest path)
        }
        // else (need to check)
        for(int i=0; i<(int)graph[v].size(); i++){// adjacent nodes
            edge e = graph[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;// update minimum cost
                pq.push({d[e.to], e.to});
            }
        }
    }
}


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

    vector<int> p(E), q(E), c(E);
    vector<set<int>> station(n+1, {0});
    for (int i=0; i<E; i++){
        cin >> p[i] >> q[i] >> c[i];
        station[p[i]].insert(c[i]);
        station[q[i]].insert(c[i]);
    }

    map<pair<int,int>, int> node_id;
    int id = 1;
    for(int i=1; i<=n; i++){
        for(int c : station[i]){
            node_id[{i,c}] = id;
            id += 1;
        }
    }

    V = id + 1;
    graph.resize(V);
    d.resize(V);
    //cout << V << endl;

    for (int i=0; i<E; i++){
        int u = node_id[{p[i], c[i]}];
        int v = node_id[{q[i], c[i]}];
        graph[u].push_back({v, 0});
        graph[v].push_back({u, 0});
    }

    for(int i=1; i<=n; i++){
        for(auto c : station[i]){
            if(c == 0) continue;
            //cout << c << " ";
            int u = node_id[{i,c}];
            int v = node_id[{i,0}];
            graph[u].push_back({v, 0});
            graph[v].push_back({u, 1});
        }
        //cout << endl;
    }

    for(int c : station[1]) graph[0].push_back({node_id[{1,c}], 1});
    for(int c : station[n]) graph[node_id[{n,c}]].push_back({V-1, 0});

    Dijkstra(0);
    if(d[V-1] != INF) cout << d[V-1] << endl;
    if(d[V-1] == INF) cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 97784
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 M = sc.nextInt();
		int[] a = new int[A];
		int aMin = 100000;
		for(int i = 0; i < A; i++) {
			a[i] = sc.nextInt();
			aMin = Math.min(aMin, a[i]);
		}
		int[] b = new int[B];
		int bMin = 100000;
		for(int i = 0; i < B; i++) {
			b[i] = sc.nextInt();
			bMin = Math.min(bMin, b[i]);
		}

		int waribikigo = 1000000;
		for(int i = 0; i < M; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int c = sc.nextInt();

			int tmp = a[x-1] + b[y-1] - c;
			waribikigo = Math.min(waribikigo, tmp);
		}
		System.out.println(Math.min(waribikigo, aMin+bMin));
	}
}

Measured memory_bytes: 131608
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ieps (int) 1e6
#define eps (int) 1e9
#define int long long
#define pii pair<int,int>


int func(int i , int j , int k , int n){
	if(4*i*j*k == n*(i*j + k*i + j*k)) return 1;
	else if(4*i*j*k < n*(i*j + k*i + j*k)) return -1;
	else return 0;
}



int32_t main(){
	int N;
	scanf("%lld" , &N);
	for(int i = 1;i<=3500;i++){
		for(int j = 1;j<=3500;j++){
			int l = 1 , r = 3500;
			while(l<=r){
				int mid = (l+r)/2LL;
				if(func(i , j , mid , N) == 1){
					cout<<i<<" "<<j<<" "<<mid;
					return 0;
				}
				else if(func(i , j , mid , N) == -1) l = mid + 1;
				else r = mid - 1 ;
			}
		}
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
const ll mod = 998244353;
int n, m;
vector<int>G[N];
int fa[N], d[N];
typedef pair<int, int>pii;
void bfs() {
	memset(d, 0x3f, sizeof(d));
	priority_queue<pii, vector<pii>, greater<pii> >q;
	d[1] = 0;
	q.push(pii(0, 1));
	while (!q.empty()) {
		int u = q.top().second, di = q.top().first; q.pop();
		if (d[u] < di)continue;
		for (int v : G[u]) {
			if (d[v] > d[u] + 1) {
				d[v] = d[u] + 1;
				fa[v] = u;
				q.push(pii(d[v], v));
			}
		}
	}
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	bfs();
	for (int i = 1; i <= n; i++)if (d[i] == INF) { puts("No"); return 0; }
	puts("Yes");
	for (int i = 2; i <= n; i++)printf("%d\n", fa[i]);
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
// constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;



ll K;
int N = 50;
vector<ll> ans(N);

int main(){
  cin >> K;
  REP(i, 50){
    ans[i] = i;
  }
  REP(i, 50){
    ans[i] += K / 50;
  }
  REP(i, K % 50){
    ans[N-1-i]++;
  }
  cout << N << endl;
  REP(i, N){
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d;
    double x,y,z,p,q;
    cin>>n>>d;
    ll arr[n+2][d+2];
    for(i=0; i<n; i++)
    {
        for(j=0; j<d; j++)
        {
            cin>>arr[i][j];
        }
    }
    c=0;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            y=0;
            for(k=0;k<d;k++)
            {
                x=abs(arr[i][k]-arr[j][k]);
                x=pow(x,2);
                y+=x;
            }
            x=sqrt(y);
           // cout<<x<<endl;
            a=x;
            z=a;
            //cout<<z<<endl;
           if(z==x){c++;}

        }

    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
x,N = list(map(int,input().split(" ")))
if N != 0:
  p = list(map(int,input().split(" ")))
  sa = 0
  ans = -100
else:
  ans = x

while True:
  if ans != -100:
    break
  for i in range(N):
    if x-sa == p[i]:
      break
    if i == N-1:
      if x-sa != p[i]:
        ans = x-sa
  if ans != -100:
    break
  for i in range(N):
    if x+sa == p[i]:
      break
    if i == N-1:
      if x+sa != p[i]:
        ans = x+sa
  if ans != -100:
    break
  sa += 1
print(ans)

Measured memory_bytes: 9228
#include <bits/stdc++.h>
#define N 100010
using namespace std;
long long n,q,a,b,c,x,y,k,dist[N];
vector<pair<long long,long long> > pt[N];
vector<long long> ans;
bool book[N]={};
void dfs(long long x,long long pre)
{
	dist[x]=pre;
	long long i;
	for(i=0;i<pt[x].size();i++)
	{
		if(!book[pt[x][i].first])
		{
			book[pt[x][i].first]=true;
			dfs(pt[x][i].first,pre+pt[x][i].second);
		}
	}
}
int main(){
	long long i;
	cin>>n;
	for(i=0;i<n-1;i++)
	{
		cin>>a>>b>>c;
		pt[a].push_back(make_pair(b,c));
		pt[b].push_back(make_pair(a,c));
	}
	cin>>q>>k;
	book[k]=true;
	dfs(k,0);
	for(i=0;i<q;i++)
	{
		cin>>x>>y;
		ans.push_back(dist[x]+dist[y]);
	}
	for(i=0;i<ans.size();i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


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

using namespace std;

long long solve(vector<string> x) {
  long long res = stoll(x[0]);
  for (int i = 1; i < x.size(); ++i) {
    res += stoi(x[i]);
  }
  return res;
}

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

  string s;
  cin >> s;
  int n = s.size();
  if ( n == 1) {
    cout << s << endl;
  } else {
    long long res = 0;
    for (int i = 0; i < (1<<(n-1)); ++i) {
      vector<string> broken;
      int pos = 0;
      for(int j = 0; j < 9; ++j) {
        if ((i&(1<<j)) > 0) {
          string part = s.substr(pos, j+1-pos);
          broken.push_back(part);
          pos = j+1;
        }
      }
      string part = s.substr(pos, n-pos);
      broken.push_back(part);
      res += solve(broken);
    }
    cout << res << endl;
  }

  return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
#include<iostream>
#define NIL -1
using namespace std;
int np = 0; int n, q;
class Node
{
public:
  Node() {}
  int location, l, r;
};
Node T[500005];
class Point
{
public:
  int x, y, id;
  Point() {}
  Point(int id, int x, int y): id(id), x(x), y(y) {}
  bool operator < (const Point &p)
  {
    return id < p.id;
  }
//  void print()
//  {
//    printf("%d\n", id);
//  }
};
Point P[500005];
bool compar_x(const Point &X, const Point &Y)
{
  return X.x < Y.x;
}
bool compar_y(const Point &X, const Point &Y)
{
  return X.y < Y.y;
}
int make2DTree(int l, int r, int depth)
{
  if(!(l<r)) return NIL; //NIL signs NULL node.
  int mid = (l + r) / 2;
  if(depth % 2 == 0 )
  {
    sort(P+l, P+r, compar_x);
  }
  else  sort(P+l, P+r, compar_y);
  int root = np++;
  T[root].location = mid;// root , left , right, create tree in preorder.
  T[root].l = make2DTree(l, mid, depth+1);
  T[root].r = make2DTree(mid+1, r, depth+1);
  return root;
}
void findp(int r, int sx, int tx, int sy, int ty, int depth, vector<int> &ans)
{
  int x, y;
  x = P[T[r].location].x; y = P[T[r].location].y;
  if(x >= sx && x <= tx && y >= sy && y <= ty) ans.push_back(P[T[r].location].id);
  if(depth % 2 == 0)
  {
    if(x >= sx && T[r].l != NIL)
      findp(T[r].l, sx, tx, sy, ty, depth+1, ans);
    if(x <= tx && T[r].r != NIL)
      findp(T[r].r, sx, tx, sy, ty, depth+1, ans);
  }
  else
  {
    if(y >= sy && T[r].l != NIL)
      findp(T[r].l, sx, tx, sy, ty, depth+1, ans);
    if(y <= ty && T[r].r != NIL)
      findp(T[r].r, sx, tx, sy, ty, depth+1, ans);
  }
}
int main()
{
  int x, y;
  scanf("%d", &n);
  for(int i=0; i<n; i++)
  {
    scanf("%d%d", &x, &y);
    P[i] = Point(i, x, y);
    T[i].l = T[i].r = T[i].location = NIL;
  }
  make2DTree(0, n, 0);
  scanf("%d", &q);
  int sx, tx, sy, ty; vector<int> ans;
  for(int i=0; i<q; i++)
  {
    scanf("%d%d%d%d", &sx, &tx, &sy, &ty);
    findp(0, sx, tx, sy, ty, 0, ans);
    sort(ans.begin(), ans.end());
    for(int j=0; j<ans.size(); j++)
      printf("%d\n", ans[j]);
    ans.clear();
    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 14508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

  vll l(n);
  for (ll i = 0; i < n; i++) cin >> l[i];
  sort(all(l));

  ll ans = 0;
  for (ll i = 0; i < k; i++) ans += l[n - 1 - i];
  cout << ans << endl;
}

Measured memory_bytes: 256
N, Y = [ int(i) for i in input().split()]

upper10k = int(Y/10000)
sum10k = 0
num10k, num5k, num1k = [-1,-1,-1]
for i in range(upper10k, -1,-1) :
	restSheet = N - i
	sum10k = i * 10000
	if (Y - sum10k) > (restSheet * 5000) :
		break
	upper5k = min([int((Y-sum10k)/5000), restSheet])
	for j in range(upper5k, -1, -1) :
		total10k5k = sum10k + 5000 * j
		if (Y - total10k5k) > ( (restSheet-j) * 1000) :
			break
		if (Y - total10k5k) == ( (restSheet-j) * 1000) :
			num10k, num5k, num1k = [i,j,restSheet-j]
			break
	if ( num10k != -1 ) and ( num5k != -1 ) and ( num1k != -1 ) :
		break
print("{} {} {}".format(num10k,num5k, num1k))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int half = n/2;
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for(int i=0; i<half; i++){
        if(s[i] != s[i+half]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]

bingo = [[0] * 3 for _ in range(3)]

for i in range(n):
    for j in range(3):
        for k in range(3):
            if a[j][k] == b[i]:
                bingo[j][k] = 1


f = False
for i in range(3):
    tmpf = True
    for j in range(3):
        if bingo[i][j] == 0:
            tmpf = False
    if tmpf:
        f = True

for i in range(3):
    tmpf = True
    for j in range(3):
        if bingo[j][i] == 0:
            tmpf = False
    if tmpf:
        f = True

if bingo[0][0] == 1 and bingo[1][1] == 1 and bingo[2][2] == 1:
    f = True
if bingo[0][2] == 1 and bingo[1][1] == 1 and bingo[2][0] == 1:
    f = True

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


Measured memory_bytes: 3064
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
const int inf1=1e9;
const ll inf2=1e18;
const int N=200010;
using namespace std;
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
ll sz[N];
vector<int>g[N+1];
ll dp[N];
int n;
ll dp2[N];
#define cat
ll fact[2*N+1],infact[2*N+1];
ll xymodp(ll x,ll y,ll p){
    ll a=1;
    x%=p;
    while(y){
        if(y&1)a=(a*x)%p;
        x=(x*x)%p;
        y/=2;
    }
    return a;
}
void init(){
    fact[0]=1;
    rep(i,1,N)fact[i]=(i*fact[i-1])%hell;
    rep(i,1,N)infact[i]=xymodp(fact[i],hell-2,hell);
    infact[0]=1;infact[1]=1;
}
void dfs1(int u=1,int p=0){
      dp[u]++;
      sz[u]++;
      for(auto i:g[u]){
          if(i!=p){
              dfs1(i,u);
              sz[u]+=sz[i];
          }
      }
      dp[u]=dp[u]*fact[sz[u]-1]%hell;
      for(auto i:g[u]){
          if(i==p)continue;
          dp[u]=dp[u]*infact[sz[i]]%hell*dp[i]%hell;
      }
}
void dfs2(int u=1,int p=0,ll cnt=1){
   dp2[u]=dp[u]*fact[n-1]%hell*infact[sz[u]-1]%hell*infact[n-sz[u]]%hell*cnt%hell;
   //cout<<u<<" "<<dp2[u]<<endl;
   for(auto i:g[u]){
       if(i!=p){
        ll c=dp2[u]*xymodp(dp[i],hell-2,hell)%hell*fact[n-1-sz[i]]%hell*fact[sz[i]]%hell*infact[n-1]%hell;  
        //cout<<i<<" "<<c<<endl; 
        dfs2(i,u,c);
       }
   }
}
int solve(){
  cin>>n;          
  rep3(n-1){
      int a,b;cin>>a>>b;
      g[a].pb(b);
      g[b].pb(a);
  }          
  dfs1();
  dfs2();
  for(int i=1;i<=n;i++){
      cout<<dp2[i]<<endl;
  }
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W, K; cin >> H >> W >> K;
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}

	int ans = H-1 + W-1;
	for (int m = 0; m < (1<<(H-1)); m++) {
		int cnd = __builtin_popcount(m);
		vector<int> cnt(H);
		for (int cur = 0; cur < W; cur++) {
			for (int i = 0, j = 0; i < H; i++) {
				cnt[j] += S[i][cur] == '1';
				if (m & (1<<i)) j = i+1;
			}
			bool colGood = true;
			for (int i = 0; i < H; i++) {
				if (cnt[i] > K) colGood = false;
			}
			if (colGood) {
				continue;
			}
			cnd++;
			for (int i = 0; i < H; i++) cnt[i] = 0;

			for (int i = 0, j = 0; i < H; i++) {
				cnt[j] += S[i][cur] == '1';
				if (m & (1<<i)) j = i+1;
			}
			colGood = true;
			for (int i = 0; i < H; i++) {
				if (cnt[i] > K) colGood = false;
			}
			if (colGood) {
				continue;
			}

			cnd += H-1 + W-1;
		}
		ans = min(ans, cnd);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
// #define int long long
using namespace std;
signed main(void) {
    int n, k, q;
    cin >> n >> k >> q;
    int a[n];
    rep(i, n) cin >> a[i];

    int mi = 1e9;

    rep(i, n) {
        int y = a[i];
        vector<vector<int>> sa;
        vector<int> sai;

        rep(j, n) {
            if (a[j] < y) {
                sa.push_back(sai);
                sai.clear();
                continue;
            }
            sai.push_back(a[j]);
        }
        sa.push_back(sai);

        sai.clear();
        rep(j, sa.size()) {
            int left_size = sa[j].size() - k + 1;
            if (left_size <= 0) continue;
            nth_element(sa[j].begin(), sa[j].begin() + left_size, sa[j].end());
            rep(l, left_size) {
                sai.push_back(sa[j][l]);
            }
        }
        if (sai.size() < q) continue;
        nth_element(sai.begin(), sai.begin() + q-1, sai.end());
        int x = sai[q-1];
        mi = min(x-y, mi);
    }
    cout << mi << endl;
}


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


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}

int ans_gu_choki_per(char te, int c, int d, int e ) {
  if(te = "r") return e;
  else if(te = "s") return c;
  else if(te = "p") return d;
  else return 0;
//  return abs(a-b)*abs(a-b);
}
int ans_gu_choki_per_2(char te, int c, int d, int e ) {
  if(te = "r") return c;
  else if(te = "s") return d;
  else if(te = "p") return e;
  else return 0;
//  return abs(a-b)*abs(a-b);
}

//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%d%d", &a, &b);
  if(a<b) {
    tmp = b;
    b = a;
    a = tmp;  
  }
  
  for(i=0;i<a;i++){
    printf("%d", b);
  }
  printf("\n");
  
return 0;
}


Measured memory_bytes: 128
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;


#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}

int main(){
  	ll n,k,ans=0;
    cin >> n >> k;
    vector<ll> a(n,0);
    for(ll i=0;i<k;i++){
        ll d;
        cin >> d;
        for(ll i=0;i<d;i++){
            ll tmp;
            cin >>tmp;
            a[tmp-1]++;
        }
    }
    for(ll i=0;i<n;i++){
        if(a[i]==0) ans++;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
const int INT_INF = 2147483647;
//stoi(s) : string→int stoll(s) :string→longlong  int→string to_string(i)
const double PI = acos(-1.0);
//小数点の表し方 cout << fixed << setprecision(5);
const ll LLMAX = 9223372036854775805;
const ll DOG = 1000000000000001;
char alp[27] = {'a','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y','z'};
char alp2[27] =  {'z','a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y'};
ll num[10] = {1, 26, 676, 17576, 456976, 11881376, 308915776, 8031810176, 208827064576, 5429503678976};


int main(){
    ll n;
    cin >> n;
    vector<ll> p;
    string s = "";

    while(n > 0){
        ll x = n%26;
        p.push_back(x);
        s += alp2[x];
        if(x==0){
            n = (n-1)/26;
            continue;
        }
        n /= 26;
    }


    reverse(s.begin(),s.end());
    reverse(p.begin(),p.end());
    /*
    for(int i=0;i<s.size() - 1;i++){
        s[i]--;
    }
    */


    cout << s << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
#define R(i,n) for(int i=0;i<n;i++)
int n,a=1e9,c[2][20],p[1<<18][51];main(){cin>>n;R(i,n)cin>>c[0][i];R(i,n)cin>>c[1][i];fill(p[1],p[1<<n],1e9);;R(B,1<<n){int o=0,d[n];R(i,n)if(!(B&1<<i))d[i]=o++;R(i,n){int k=c[abs(i-n+o)%2][i];R(j,k+1)p[B|1<<i][k]=min(p[B|1<<i][k],p[B][j]+d[i]);}}R(i,51)a=min(a,p[(1<<n)-1][i]);cout<<(a>1e8?-1:a);}

Measured memory_bytes: 52480
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <cstdio>
#include <cstring>

using namespace std;

const int MOD = 1000000007;
const int MAX = 110000;

long long fac[MAX], finv[MAX], inv[MAX];

void Init() {
	fac[0] = fac[1] = inv[1] = finv[0] = finv[1] = 1;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

int main() {
	Init();
	int n; cin >> n;
	vector<int> x(n);
	for (auto& a : x) cin >> a;
	long long ans = 0, t = 0;
	for (int i = 1; i < n; ++i) {
		(t += inv[i]) %= MOD;
		(ans += t * (x[i] - x[i - 1])) %= MOD;
	}
	(ans *= fac[n - 1]) %= MOD;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3200
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
abs_list = []

for i in range(n):
    tmp = t - h[i] * 0.006
    abs_list.append(abs(a - tmp))

print(abs_list.index(min(abs_list)) + 1)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void) {
	int i;
	char s[4];
	scanf("%s",&s);
	for(i=0;i<5;i++){
		if(s[i]=='9'){
			s[i]='1';
		}else if(s[i]=='1'){
			s[i]='9';
		}
	}
	printf("%s",s);
	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cout << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#define INFILE freopen("input.txt", "r", stdin)
#else
#define debug(x)
#define INFILE
#endif

#define ALL(s) begin(s), end(s)
#define RALL(s) rbegin(s), rend(s)
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define RREP(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL9_MOD = 1000000009LL;
static constexpr ll LL7_MOD = 1000000007LL;
static constexpr ll INF = 1LL << 60;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

char grid[1000][1000];
ll dp[1000][1000];

int main(int argc, char* argv[]) {
  INFILE;

  ll h, w;
  cin >> h >> w;
  REP(i, 0, h) {
    string line;
    cin >> line;
    line.copy(grid[i], w);
  }

  for (int i = 0, wall = 1; i < h; i++) {
    if (grid[i][0] == '#') wall = 0;
    dp[i][0] = ll(wall);
  }

  for (int i = 0, wall = 1; i < w; i++) {
    if (grid[0][i] == '#') wall = 0;
    dp[0][i] = ll(wall);
  }

  REP(i, 1, h) {
    REP(j, 1, w) {
      if (grid[i][j] == '#') {
        dp[i][j] = 0;
        continue;
      }

      dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % LL7_MOD;
    }
  }

  cout << dp[h - 1][w - 1] << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


Measured memory_bytes: 9088
from collections import Counter
n, m = map(int, input().split())
a = list(map(int, input().split()))

cumsum = [0]
for i in a:
    cumsum.append((cumsum[-1] + i) % m)

ans = 0
for v in Counter(cumsum).values():
    ans += v * (v-1) // 2

print(ans)

Measured memory_bytes: 16552
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long int
#define pb push_back
#define fi first
#define se second
using namespace std;
const int MOD=1000000007;
const ll MAX=9187201950435737471;
const int N=100005;
const ll NINF=1e14;

int a[100005];
int n,k;
ll dp[100005];

ll solve(int idx){
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    int m=k;
    for(int i=2;i<n;i++){
        //m=k;
        (i-k<0)?m=i:m=k;
        for(int j=i-1;j>=i-m;j--)
            dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
    }
    return dp[n-1];
}

int main() {
    fastio

    memset(dp,127,sizeof dp);
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];

    cout<<solve(0);
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
using namespace std;
const int MX = 200005;
const long long LINF = 1e15;

long long dp[MX];

int main()
{
    int n, w;
    scanf("%d%d", &n, &w);
    for( int i = 0; i < MX; i++ ) dp[i] = LINF;
    dp[0] = 0;
    for( int i = 0; i < n; i++ )
    {
        int a, b;
        scanf("%d%d", &a, &b);
        for( int j = MX - b - 1; j >= 0; j-- )
        {
            dp[j + b] = min( dp[j + b], dp[j] + a);
        }
    }
    int ans = 0;
    for( int i = 0; i < MX; i++) if (dp[i] <= w) ans = i;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;

namespace ABC052_B_Increment_Decrement
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int x = 0;
			int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();

			int maxValue = x;
			for (int i = 0; i < n; i++)
			{
				if (s.Substring(i, 1) == "I") x++;
				else x--;

				if (maxValue < x) maxValue = x;
			}
			
			Console.WriteLine(maxValue);
		}
	}
}

Measured memory_bytes: 13140
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <fstream>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>

#define ff first
#define ss second
#define ll long long
#define pb push_back
#define mp make_pair
#define inf 1000000007
#define mod 1000000007
#define pii pair <int, int>
#define all(x) x.begin(), x.end()
#define FOR(i, x, y) for (int i = x; i <= y; i++)
//#define tr(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)

//using namespace __gnu_pbds;

using namespace std;

//template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int n, a, b, m, ans;

bool vis[10];

vector <int> E[10];

void dfs(int node, int now)
{
	if (now == n){
		ans++;
		return;
	}
	
	vis[node] = 1;
	for (auto i: E[node])
		if (!vis[i]) dfs(i, now+1);
	vis[node] = 0;
}

int main()
{
	cin >> n >> m;
	
	FOR (i, 1, m) {
		cin >> a >> b;
		
		E[a].pb(b);
		E[b].pb(a);
	}
	
	dfs(1, 1);
	
	cout << ans;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use  std::collections::BTreeSet;
use std::cmp::min;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let a: u64 = read();
    let mut ret = 0;
    for i in 1..(a + 1) {
        if i % 5 == 0 || i % 3 == 0 {
            continue;
        }
        ret += i;
    }
    println!("{}", ret);
}



Measured memory_bytes: 2116
/*
 _____ ____ _____   ___   ___   ___   ___ 
|_   _/ __ \_   _| |__ \ / _ \ |__ \ / _ \
  | || |  | || |      ) | | | |   ) | | | |
  | || |  | || |     / /| | | |  / /| | | |
 _| || |__| || |_   / /_| |_| | / /_| |_| |
|_____\____/_____| |____|\___/ |____|\___/ 
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define per(i, a, b) for (int i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                     \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
// pair<int,int>ert(x==y); gives run time when false
using namespace std;
int main()
{
  CIN;
  int n, x, y;
  cin >> n >> x >> y;
  if (x + y > n + 1)
  {
    cout << -1;
    return 0;
  }
  vi up;
  rep(i, n - x + 1, n + 1)
  {
    up.pb(i);
  }
  vi down;
  per(i, y - 1, 0)
  {
    down.pb(i);
  }
  int last = n - x, nh = 2 * y - 2, bd = y - 1;
  while (1)
  {
    per(i, min(nh, last), bd)
    {
      down.pb(i);
    }
    if (nh >= last)
      break;
    bd = nh;
    nh = bd + y - 1;
  }
  int ch = 1,coco = 0;
  rep(i,0,down.size()){
    if(down[i]==ch){
      ch += y-1;
      coco++;
    }
  }
  if(coco>x){
    cout << -1;
    return 0;
  }
  rep(i, 0, up.size())
  {
    cout << up[i] << " ";
  }
  rep(i, 0, down.size())
  {
    cout << down[i] << " ";
  }
}

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
string S,T;
int main(){
	cin>>S>>T;
	for(int i=0;i<S.size()+T.size();i++){
		if(i%2==0)cout<<S[i/2];else cout<<T[i/2];
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
import copy
n,m,x = map(int,input().split())
listA = []
for _ in range(n):
    listA.append(list(map(int,input().split())))
t = [[0 for i in range(n)]]
for i in range(n):
    l = len(t)
    for j in range(l):
        t.append(copy.copy(t[j]))
        t[len(t)-1][i] = 1
ans = float("inf")
for i in t:
    check = [0 for i in range(m+1)]
    for j in range(n):
        if i[j] == 1:
            for k in range(m+1):
                check[k] = check[k] + listA[j][k]
    an = 0
    for j in range(1,m+1):
        if check[j] < x:
            an += 1
    if an == 0:
        if ans > check[0]:
            ans = check[0]
if ans == float("inf"):
    print(-1)
else:
    print(ans)




Measured memory_bytes: 9588
def Joulist(n, m):
    ans = []
    i = m // 3
    while i <= n:
        ans.append(i)
        i *= m
    return ans


n = int(input())
dp = [1000000] * (n//3 + 1)
dp[0] = 0
for i in range(2, n//3+1):
    kouho = Joulist(i, 6) + Joulist(i, 9)
    dp[i] = min([dp[i-k] for k in kouho]) + 1
if n != 3:
    print(dp[n//3] + n%3)
else:
    print(3)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
char s[maxn];
int main(){
	cin>>s;
	int n=strlen(s);
	int a[4];
	a[1]=a[2]=a[3]=0;
	for (int i=0;i<n;i++)
	{
		if (s[i]=='a')a[1]++;
		if (s[i]=='b')a[2]++;
		if (s[i]=='c')a[3]++;
	}
	sort(a+1,a+1+3);
	if (a[3]-a[1]<=1 && a[2]-a[1]<=1) puts("YES");
	else puts("NO");
}

Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c;
    if(a > b) {
        d = a;
        a = b;
        b = d;
    }
    if(b > c){
        d = b;
        b = c;
        c = d;
    }
    if(a > b) {
        d = a;
        a = b;
        b = d;
    }
    cout << a << " " << b << " " << c << endl;
    
    return 0;
    
}


Measured memory_bytes: 3088
package main

import (
	"fmt"
	"math"
)

func scanNums(len int) []int {
	var num int
	var nums []int
	for i:=0; i <len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func checker(n int, nums []int) string {
	v := float64(nums[1]) / float64(n)
	i := int(math.Floor(v))

	if nums[0] <= i*n && i*n <= nums[1] && i >= 1{
		return "OK"
	}
	return "NG"

}

func main() {
	var N int
	fmt.Scan(&N)
	nums:= scanNums(2)
	result := checker(N, nums)
	fmt.Println(result)
}

Measured memory_bytes: 1760
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
n=n0()
AB=n3(n)
AB.sort(key=lambda x:x[1])

time=0
f=True
for a,b in AB:
    time+=a
    if time<=b:
        pass
    else:
        f=False
        break
p0(f)

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

#define int long long

int n,a,b;
long long v[100000+10];
long long h[100000+10];

bool solve(int x){
    long long y=0;
    for(int i=0;i<n;i++){
        v[i]=h[i];
        v[i]-=b*x;
    }
    
    for(int i=0;i<n;i++){
        if(v[i]>0){
            y+=(v[i]+a-b-1)/(a-b);
        }
    }
    if(y<=x)return true;
    else return false;
}

signed main(void){
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    
    int l=0;
    int r=1e9;
    while(r-l>1){
        int mid=(r+l)/2;
        if(solve(mid))r=mid;
        else l=mid;
    }
    
    cout<<r<<endl;
}


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

using namespace std;

class Node {
public:
	int parent, depth;
	string type;
	vector<int> list;

	Node() {
		parent = -1;
		depth = 0;
		type = "";
		list.clear();
	}
};

Node TreeInfo[100000];

void solve(int n) {
	int len, parent, startId, curId;
	string type;
	queue<int> nodeList;

	for (int id = 0; id < n; ++id) {
		len = TreeInfo[id].list.size();
		parent = TreeInfo[id].parent;
		if (parent == -1) {
			TreeInfo[id].type = "root";
			nodeList.push(id);
		}
		else if (len == 0) {
			TreeInfo[id].type = "leaf";
		}
		else {
			TreeInfo[id].type = "internal node";
		}
	}

	while(!nodeList.empty()) {
		startId = nodeList.front();
		nodeList.pop();

		len = TreeInfo[startId].list.size();
		for (int j = 0; j < len; ++j) {
			curId = TreeInfo[startId].list[j];
			TreeInfo[curId].depth += TreeInfo[startId].depth + 1;
			nodeList.push(curId);
		}
	}
}

void show(int n) {
	int len;

	for (int id = 0; id < n; ++id) {
		cout << "node " << id << ": ";
		cout << "parent = " << TreeInfo[id].parent << ", ";
		cout << "depth = " << TreeInfo[id].depth << ", ";
		cout << TreeInfo[id].type << ", [";
		len = TreeInfo[id].list.size();
		for (int j = 0; j < len; ++j) {
			cout << TreeInfo[id].list[j];
			cout << (j == len - 1 ? "" : ", ");
		}
		cout << "]" << endl;
	}
}

int main() {
	int n, id, k, c;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> id >> k;
		for (int j = 0; j < k; ++j) {
			cin >> c;
			TreeInfo[id].list.push_back(c);
			TreeInfo[c].parent = id;
		}
	}
	solve(n);
	show(n);

	return 0;
}


Measured memory_bytes: 12636
n = int(input())
xor_arr = list(map(int, input().split()))
xor_of_xor = 0
for elm in xor_arr:
    xor_of_xor = xor_of_xor ^ elm
scarf_val = [xor_of_xor ^ elm for elm in xor_arr]
         
print(" ".join(str(x) for x in scarf_val))

Measured memory_bytes: 41668
#include <iostream>
using namespace std;
int bubblesort(int A[],int N){
    int sw = 0;
    bool flag =1;
    for (int i =0; flag;i++){
        flag =0;
        for(int j =N-1;j>=i+1;j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                flag=1;
                sw++;
            }
            }
        }
    return sw;
}
int main(){
    int A[100],N,sw;
    cin>>N;
    for (int i =0;i<N;i++) cin>>A[i];
    sw = bubblesort(A,N);
    for(int i =0;i<N;i++){
        if(i) cout<<" ";
        cout<<A[i];
    }
    cout<<endl;
    cout<<sw<<endl;
    
    return 0;
    
}


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

const int maxn = 505;
int c[maxn],s[maxn],f[maxn];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1; i<n; i++)
    {
        scanf("%d%d%d",&c[i],&s[i],&f[i]);
    }
    for(int i=1; i<n; i++)
    {
        int ans = 0;
        for(int j=i; j<n; j++)
        {
            if(ans<s[j])
                ans = s[j];
            if(ans%f[j]!=0)
                ans+=f[j]-ans%f[j];
            ans+=c[j];
        }
        printf("%d\n",ans);
    }
    printf("0\n");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define f(i, l, r) for(i = l; i < r; i++)
#define fd(i, l, r) for(i = l; i > r; i--)
using namespace std;
#pragma GCC optimize ("-O3")
int main(){
long int a, b;
cin >> a >> b;
if((a+b)%2==1)
  cout << "IMPOSSIBLE";
else cout << (a+b)/2;}

Measured memory_bytes: 256
s=input()
n=len(s)
s1=s[:(n-1)//2]
s2=s[(n+3)//2-1:n]
def kaibun(x):
    ret=1
    for i in range(len(x)//2):
        if x[len(x)-1-i]!=x[i]:
            ret=0
            break
    return ret
if kaibun(s)+kaibun(s1)+kaibun(s2)==3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940