akhauriyash/Code-Regression huggingface dataset:
// Problem : C - H and V
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_c
// Memory Limit : 1024 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int h,w,k;
		cin>>h>>w>>k;
		char arr[h][w];
		for(int i=0;i<h;++i)
		{
			for(int j=0;j<w;++j)
			{
				cin>>arr[i][j];
			}
		}
		vector<int> row,col;
		for(int i=0;i<(1<<h);++i)
		{
			row.pb(i);
		}
		for(int i=0;i<(1<<w);++i)
		{
			col.pb(i);
		}
		int ans = 0;
		for(int i=0;i<(int)row.size();++i)
		{
			for(int j=0;j<(int)col.size();++j)
			{
				int cnt = 0;
				for(int kk=0;kk<h;++kk)
				{
					if((1<<kk)&(row[i]))
					continue;
					for(int l=0;l<w;++l)
					{
						if((1<<l)&(col[j]))
						continue;
						if(arr[kk][l]=='#')
						++cnt;
					}
				}
				if(cnt==k)
				++ans;
			}
		}
		cout<<ans<<"\n";		
    }
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[500001];
typedef pair<LL,int>P;
P T1[500001];
P T2[500001];

void cha(int x,int y){
	vector<P>v;
	v.push_back(T1[x]);
	v.push_back(T2[x]);
	v.push_back(T1[y]);
	v.push_back(T2[y]);
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	reverse(v.begin(),v.end());
	T1[x]=v[0];
	T2[x]=v[1];
}

int main(){
	cin>>N;
	A[300001]=-1;
	REP(i,(1<<N)){
		cin>>A[i];
		T1[i]=P(A[i],i);
		T2[i]=P(-1,-1);
	}
	REP(i,(1<<N)){
		REP(j,N){
			if((i>>j)&1){
				cha(i,(i^(1<<j)));
			}else{
			}
		}
	}
	LL ans=0;
	REP(i,(1<<N)){
		if(i==0)continue;
		ans=max(ans,T1[i].first+T2[i].first);
		cout<<ans<<endl;
	}
	return(0);
}

Measured memory_bytes: 19456
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define repb(i, r, l) for (int i = r; i >= l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define ret(a) {cout << a; exit(0);}
 
using namespace std;                                                                                  
using namespace __gnu_pbds; 
mt19937 mrand(random_device{}()); 
const ll mod = 1e9 + 7;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
 
typedef pair < int , int > pii ;                                            
typedef pair < long long  , long long > pll ;

typedef tree<
pii,
null_type,
less<pii>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int N = 3e5 + 123;

int n, m, l;

int a[N];
int A,B;
bool check(int x){
	int mn = x * B;
	for(int i = 1; i <= n; i++){
		if(a[i] - mn <= 0)
			continue;
		x -= (a[i] - mn+A - 1)/A;
	}
	return x >= 0;
}
main(){

	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> A >> B;
	A -= B;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	int l = 1 , r = 1e9;
	int res = 1e9;
	while(l <= r){
		int m = (l + r) >> 1;
		if(check(m))
			r = m - 1 , res = m;
		else l = m + 1;
	}
    ret(res);


}
 


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  int n;
  cin>>n;
  vector<ll>v(n),sum(n + 1);
  rep(i,n)cin>>v[i];
   if(n == 2){
    cout << abs(v[0] - v[1]) << endl;
    return 0;
  }
  rep(i,n)sum[i + 1] = sum[i] + v[i];
  ll ans = INF;
  REP(i,1,n){
    ll a = sum[i],b = sum[n] - sum[i];
    ans = min(ans,abs(a - b));
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

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

#define INF int(1e9)
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef pair<int,int> pii;

const int maxn=305;
const int maxm=maxn*maxn*4;
int n,len;
pii val[maxm];
vector<int>edge[maxm];
int col[maxm],cnt[4];
bool vis[maxm];

void dfs(int x,int tp,int c){
	vis[x]=true;
	col[x]|=((1<<tp)*c);
	rep(i,int(edge[x].size())){
		int y=edge[x][i];
		if(!vis[y])dfs(y,tp,c^1);
	}
}

int main(){
	scanf("%d",&n);
	rep(tp,2){
		int d;
		scanf("%d",&d);
		rep(i,4*n*n){
			edge[i].clear();
			vis[i]=false;
		}
		len=0;
		rep(i,2*n+1){
			if(i*i>d)break;
			int j=sqrt(d-i*i);
			if(j*j+i*i==d&&j<=2*n){
				val[len++]=mp(i,j);
				if(i)val[len++]=mp(-i,j);
				if(j)val[len++]=mp(i,-j);
				if(i&&j)val[len++]=mp(-i,-j);
			}
		}
		rep(i,2*n)rep(j,2*n){
			rep(k,len){
				int ni=i+val[k].fst,nj=j+val[k].snd;
				if(ni>=0&&ni<2*n&&nj>=0&&nj<2*n)edge[i*2*n+j].pb(ni*2*n+nj);
			}
		}
		rep(i,4*n*n)if(!vis[i])dfs(i,tp,0); 
	}
	rep(i,4*n*n)cnt[col[i]]++;
	int mxid=-1;
	rep(i,4)if(mxid<0||cnt[i]>cnt[mxid])mxid=i;
	int tot=0;
	rep(i,2*n)rep(j,2*n)if(col[i*2*n+j]==mxid){
		printf("%d %d\n",i,j);
		tot++;
		if(tot==n*n)return 0;
	}
	return 0;
}

Measured memory_bytes: 82432
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<sstream>
#include<math.h>
#define rep(i,n) for(int i =0;i<(int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int r;
	cin >> r;
	cout << 3 * r*r << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

//main function
fn main() {
    let n:usize = read();
    let m:usize = read();
    let c:i32 = read();
    let mut sum:i32;
    let mut count:i32 = 0;
    let mut b: Vec<i32> = Vec::with_capacity(m);
    unsafe{
	b.set_len(m);
    }
    for i in 0..m{
	let number:i32 = read();
	b[i] = number;
    }
    for _i in 0..n{
	sum = c;
	for j in 0..m{
	    let a:i32 = read();
	    sum += a*b[j];
	}
	if sum > 0 {
	    count+=1;
	}
    }
    println!("{}",count);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
/*
int main(){
    int N, Y;
    cin >> N >> Y;
    int max_money = 10000 * N;
    if(Y > max_money)
    {
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    else
    {
        if(Y == max_money)
        {

        }
        int num_10000, num_5000, num_1000;
        num_10000 = Y / 10000;
        Y %= 10000;
        num_5000 = Y / 5000;
        Y %= 5000;
        num_1000 = Y /1000;
        cout << num_10000 << ' ' << num_5000 << ' ' << num_1000 << endl;
    }
    return 0;
}
*/

//2重ループ
int main(){
    int N, Y;
    cin >> N >> Y;

    for(int i = 0; i <= N; i++){//10000円札の枚数
        for(int j = 0; j <= N; j++){//5000円札の枚数
            if(i + j > N) break;
            int k = N - i - j;
            if((10000 * i + 5000 * j + 1000 * k) == Y){//貰ったお年玉金額と一致
                cout << i << ' ' << j << ' ' << k << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).ok();
    let mut it = buf.split_whitespace();
    let n = it.next().unwrap().parse::<usize>().unwrap();
    let a = (0..n).map(|_| it.next().unwrap().parse::<i64>().unwrap()).collect::<Vec<_>>();
    let m = 1_000_000_007;
    let mut inv = vec![1;n+1];
    for i in 2..n+1 {
		inv[i] = inv[m as usize % i] * (m - m / i as i64) % m;
    }
    let mut inv_sum = vec![1; n+1];
    for i in 1..n {
        inv_sum[i] = (inv_sum[i-1] + inv[i+1]) % m;
    }
    let mut res = 0;
    for i in 0..n {
        res += (inv_sum[i] + inv_sum[n-1-i] - 1) * a[i];
        res %= m;
    }
    for i in 1..n {
        res = ((i + 1) as i64 * res) % m;
    }
    println!("{}", res);
}


Measured memory_bytes: 8444
import copy
from collections import deque
def bfs(count, x, y, cheese):
    q = deque()
    q.append((count,x,y))
    tempVisited = copy.deepcopy(visited)
    tempVisited[x][y] = True
    
    while len(q)>0:
        tempc,tempx,tempy = q.popleft()
        if geo[tempx][tempy] == cheese:
            return tempc,tempx,tempy
        for i in range(4):
            neox = tempx+dx[i]
            neoy = tempy+dy[i]
            if canGoTo(neox,neoy, tempVisited):
                if (tempc+1,neox,neoy) not in q:
                    q.append((tempc+1,neox,neoy))
                    tempVisited[neox][neoy]=True
    return (-1,-1,-1)

def canGoTo(x,y,tempVisited):
    if 0<=x<H and 0<=y<W:
        return not tempVisited[x][y]
    return False

dx = [0,1,0,-1]
dy = [-1,0,1,0]

data = input().split(' ')
H,W,N = map(int, data)

#maps
geo = [[None for i in range(W)] for j in range(H)]
visited = [[False for i in range(W)] for j in range(H)]

x,y=-1,-1
for i in range(H):
    line = input()
    for j in range(W):
        p = line[j:j+1]
        geo[i][j] = p
        if p == 'X':
            visited[i][j] = True
        elif p == 'S':
            x,y, = i,j
            
count = 0
for n in range(1,N+1):
    count,x,y = bfs(count,x,y,str(n))
print(count)

Measured memory_bytes: 34744
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Map<String, ArrayList<int[]>> map = new HashMap<>();
        Set<String> set = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            String s = sc.next();
            set.add(s);
            int p = sc.nextInt();
            if(!map.containsKey(s)) map.put(s, new ArrayList<>());
            map.get(s).add(new int[]{p, i+1});
        }
        for(String name : set){
            ArrayList<int[]> list = map.get(name);
            Collections.sort(list, (x, y) -> Integer.compare(y[0], x[0]));
            for (int i = 0; i < list.size(); i++) {
                System.out.println(list.get(i)[1]);
            }
        }
        sc.close();

    }

}


Measured memory_bytes: 26708
s = input()
n = len(s)

def dfs(i: int, t: str):
    if i == n - 1:
        return sum(list(map(int, t.split('+'))))
    return dfs(i + 1, t + s[i + 1]) + dfs(i + 1, t + '+' + s[i + 1])

print(dfs(0, s[0]))

Measured memory_bytes: 9124
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
	string s;
	while(cin>>s){
		int len=strlen(s.c_str()),i,count=0,flag=1;
		if(s[0]!='A'){
			cout<<"WA"<<endl;
			continue;
		}
		for(i=2;i<len-1;i++){
			if(s[i]=='C'){
				count++;				
			}
		}
		if(count!=1){
			cout<<"WA"<<endl;
			continue;
		}
		for(i=0;i<len;i++){
			if(s[i]=='B'||(s[i]>='D'&&s[i]<='Z')){
				cout<<"WA"<<endl;
				flag=0;
				break;
			}
		}
		if(flag){
			cout<<"AC"<<endl;
		}		
	}
	return 0;
}

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

long long N, K;
vector<long long> A, F;

bool able(long long x){
    long long K_needed = 0;
    for(int i = 0; i < N; i++){
        //A_tmp[i] * F[i] <= x
        K_needed += max(0LL, A[i] - x / F[i]);
    }
    return (K_needed <= K);
}

long long bs(long long ng, long long ok){
    if(ok - ng == 1){
        return ok;
    }
    long long mid = (ng + ok) / 2;
    if(able(mid)){
        return bs(ng, mid);
    }else{
        return bs(mid, ok);
    }
}

int main(){
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        long long a;
        cin >> a;
        A.push_back(a);
    }
    for(int i = 0; i < N; i++){
        long long f;
        cin >> f;
        F.push_back(f);
    }
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());

    long long ret = bs(-1, 1000000000000ll);
    cout << ret << endl;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  if (n < 1200)
    cout << "ABC" << endl;
  else
    cout << "ARC" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a > b){
    if(a > c){
      cout << b * c / 2 << endl;
    }
    else{
      cout << a * b / 2 << endl;
    }
  }
  else{
    if(b > c){
      cout << a * c / 2 << endl;
    }
    else{
      cout << a * b / 2 << endl;
    }
  }
}


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

int main(){
  int N, D;cin >> N >> D;
  int X[11][11];
  for(int i = 0;i < N;i++){
    for(int j = 0;j < D;j++){
      cin >> X[i][j];
    }
  }
  double sum = 0;
  int cnt = 0;
  for(int i = 0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      sum = 0;
      for(int k = 0;k<D;k++){
        sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      if(ceil(sqrt(sum)) == floor(sqrt(sum)))
        cnt++;
    }
  }
  cout << cnt;
}


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;
ll GCD(ll a,ll b){
    if(b==0) return a;
    return GCD(b,a%b);
}
int main() {
    int n;
    cin>>n;
    vector<ll> a(n);
    ll lcm,gcd;
    rep(i,n){
        cin>>a[i];
        if(i==0) lcm=a[i];
        else{
            gcd=GCD(lcm,a[i]);
            lcm=(lcm/gcd)*a[i];
        }
    }
    cout<<lcm;
}

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

#ifndef U_L_LONG
typedef unsigned long long U_L_LONG;
#endif
#ifndef L_LONG
typedef long long L_LONG;
#endif

#ifndef LL_ABS
#define LL_ABS(x) (((((x) < 0) ? ((x) * (-1)) : (x))))
#endif

static void D_Problem();

int main()
{
	D_Problem();
	
	fflush(stdout);
	return 0;
}

static void D_Problem()
{
	int N = 0;
	
	scanf(" %d", &N);
	
	bool zeroExist = false;
	int minusCount = 0;
	L_LONG minNum = LLONG_MAX;
	L_LONG sum = 0;
	auto A = new L_LONG[N + 4];
	for (int i = 0; i < N; i++) {
		scanf(" %lld", &A[i]);
		
		if (A[i] < 0) {
			minusCount++;
		}
		else if (A[i] == 0) {
			zeroExist = true;
		}
		L_LONG absVal = LL_ABS(A[i]);
		if (minNum > absVal) {
			minNum = absVal;
		}
		sum += absVal;
	}

	if ((!zeroExist) && (minusCount % 2)) {
		sum -= minNum * 2;
	}
	printf("%lld\n", sum);
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b < 0) {
		ps(No);
		return 0;
	}
	if ((c - a - b)*(c - a - b) > 4 * a*b) {
		ps(Yes)
	}
	else {
		ps(No)
	}
	return 0;
}

Measured memory_bytes: 3604
n,m=map(int,input().split())
D=dict()
for i in range(n):
  D[i]=[]
for i in range(m):
  a,b=map(int,input().split())
  D[a-1].append([b-1])
  D[b-1].append([a-1])
for i in range(n):
  print(len(D[i]))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vvi vector <vi>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
using namespace std;

int main(){

#ifndef ONLINE_JUDGE 
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout); 
#endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    bool isvalid = true;
    if (b<=a){
        int temp = log2((double)a/b);
        temp++;
        if (temp>k){
            isvalid = false;
        }
        else {
            b = b*pow(2, temp);
            k-=temp;
        }
    }    
    if (c<=b){
        int temp = log2((double)b/c);
        temp++;
        if (temp>k){
            isvalid=false;
        }
        else k-=temp;
    }
    if (isvalid) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    // cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
    return 0;
}


Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll a,b,n;
    cin >> a >> b >> n;
    if(b-1 <= n){
        cout << floor(a*(b-1)/b) << endl;
    }
    else{
        cout << floor(a*n/b) << endl;
    }
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int K,N;cin >> K >> N;
    if(K*500 >= N)cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

using pint = pair<int,int>;

int main(){
    int n,t;
    cin >> n;
    vector<vector<pint>>v;
    v.assign(n, vector<pint>());
    REP(i,n){
        cin >> t;
        v[i].resize(t);
        REP(j,t){
            cin >> v[i][j].first >> v[i][j].second;
            --v[i][j].first;
        }
    }
    
    int max1 = 0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> vec;
        vector<int> vec1;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                vec.push_back(i);
                vec1.push_back(1);
            }
            else vec1.push_back(0);
        }
        bool flag = true;
        for(const int x:vec){
            for(int j=0;j<v[x].size();j++){
                if(v[x][j].second!=vec1[v[x][j].first]){
                    flag = false;
                    break;
                }
            }
        }
        if(flag)max1=max(max1,__builtin_popcount(bit));
    }
    COUT(max1);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

int main(void)
{
    using namespace std;
    int n, max = -1000000, min = 1000000, i, t;
    long long sum = 0;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> t;
        sum += t;
        max = (max > t? max: t);
        min = (min < t? min: t);
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)
const int inf = 1<<29;

int main(){
    int N; cin >> N;
    vector<vector<ll>> v(10,vector<ll>(10,0));
    REP(i,N+1) {
        string s = to_string(i);
        int a = s[0] - '0';
        int b = s[s.size()-1] - '0';
        v[a][b] ++;
    }
    ll ans = 0;
    FOR(i,1,10)FOR(j,1,10){
        ans += v[i][j]*v[j][i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

unsigned GetDigit(unsigned num) {
    if (num == 0) return 1;
    return log10(num) + 1;
}

int main() {
    LL N;cin >> N;
    vector<LL> A(N);
    rep(i,N)cin >> A[i];

    sort(rall(A));

    LL ma = 1000000000000000000 / A[0];
    LL ans = A[0];

    rep(i,N-1){
        if(ma < A[i+1]){
            ans = -1;
            break;
        }
        ans *= A[i+1];
        ma /= A[i+1];
    }

    rep(i,N){
        if(A[i] == 0){
            ans = 0;
            break;
        }
    }
    cout << ans << endl;
}

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

long long N, A, B;
int main(){
	cin >> N >> A >> B;

	long long ans = 0;
	ans += (N/(A+B)) * A;
	N %= (A+B);

	ans += min(N, A);

	cout << ans << endl;

}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
#define int long long int
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);
constexpr int M = 405;
lli dp[M][M] = {};
lli sum[M][M] = {};
void solve(long long N, std::vector<long long> a)
{
  rep(i, M) rep(j, M) dp[i][j] = 1e18;
  rep(i, N) dp[i][i + 1] = 0;
  rep(i, N) for (int j = i + 1; j <= N; j++)
  {
    // sum of a[j, i)
    sum[i][j] = sum[i][j - 1] + a[j - 1];
  }
  for (int r = 2; r <= N; r++)
  {
    rep(i, N)
    {
      // [i, i+r)
      for (int k = i + 1; k < i + r && i + r <= N; k++)
        chmin(dp[i][i + r], dp[i][k] + dp[k][i + r] + sum[i][k] + sum[k][i + r]);
    }
  }
  cout << dp[0][N] << endl;
}

signed main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
  }
  solve(N, std::move(a));
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ina(x,n) rep(x_i,n) cin>>x[x_i]

typedef long long ll;
typedef vector<ll> vl;

const int MOD = 1e9+7;

ll power(ll a, ll b) {
  ll res = 1, base = a;
  while (b > 0) {
    if (b & 1) (res *= base) %= MOD;
    (base *= base) %= MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  int n; cin >> n;
  vl x(n); ina(x,n);
  ll ans = 0, c = 0;
  rep(i,n-1) {
    c += power(i+1, MOD-2);
    c %= MOD;
    ans += c * (x[i+1] - x[i]);
    ans %= MOD;
  }
  rep(i,n-1) {
    ans *= (i+1);
    ans %= MOD;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

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

int main() {
    int a, b, C;
    cin >> a >> b >> C;
    double S, L, h;
    S = 0.5 * a * b * sin(C * acos(-1) / 180);
    h = S * 2 / a;
    L = a + b + sqrt(a*a + b*b - 2*a*b*cos(C * acos(-1) / 180));
    printf("%6f\n%6f\n%6f\n", S, L, h);
    return 0;
}

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

int dp[100001];

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

	int n, W;
	cin >> n >> W;
	int w[n], v[n];
	for(int i=0; i<n; ++i)
		cin >> w[i] >> v[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[0]=0;
	for(int i=0; i<n; ++i) {
		for(int j=100000-v[i]; j>=0; --j)
			dp[j+v[i]]=min(dp[j]+w[i], dp[j+v[i]]);
	}
	for(int i=100000; i>=0; --i) {
		if(dp[i]<=W) {
			cout << i;
			break;
		}
	}
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for(int i=0; i<N; i++)
        for(int j=0; j<D; j++)
            cin >> X[i][j];

    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            int d2 = 0;
            for(int k=0; k<D; k++){
                int tmp = X[i][k] - X[j][k];
                d2 += tmp*tmp;
            }
            int d = sqrt(d2);
            for(int k=max(d-2, 0); k<=d+2; k++){
                if(k*k == d2)
                    ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

struct comp {
    bool operator()(const pair<string, int>& a, const pair<string, int>& b) const {
        if (a.first != b.first) return a.first < b.first;
        return a.second > b.second;
    }
};

int main() {
    ios::sync_with_stdio(false);
    int n, p;
    string s;
    map< pair<string, int>, int, comp > m;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> s >> p;
        m[{s, p}] = i;
    }
    for (auto i = m.begin(); i != m.end(); ++i) cout << (*i).second << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    int A,B;
    cin >> A >>B;
    if(A < B){
        for(int i = 0; i < B; i++){
            cout << A;
        }
        cout << endl;
    }else{
        for(int i = 0; i < A; i++){
            cout << B;
        }
        cout << endl;
    }
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, D, d[500000], Q, q[500000];

LL p[500001];
LL f[500001];

int main() {
	cin >> n >> D;
	inc(i, n) { cin >> d[i]; }
	cin >> Q;
	inc(i, Q) { cin >> q[i]; }
	
	p[0] = D;
	inc(i, n) {
		p[i + 1] = min(p[i], abs(p[i] - d[i]));
	}
	
	LL e = 1;
	dec(i, n) {
		if(p[i] >= e) { f[i] = true; }
		if(d[i] / 2 < e) {
			e += d[i];
		}
	}
	
	inc(i, Q) {
		cout << (f[ q[i] - 1 ] ? "YES" : "NO") << "\n";
	}
	
	return 0;
}


Measured memory_bytes: 17536
import sys
import numpy as np


def input():
    return sys.stdin.readline().rstrip()


def main():
    n = int(input())
    a = [int(e) for e in input().split()]
    x = [0 for _ in range(n)]
    x[0] = sum(a) - (sum(a[1:n:2]) * 2)
    for i in range(2, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    x[1] = sum(a) - (sum(a[2:n:2]) * 2)
    for i in range(3, n, 2):
        x[i] = x[i-2] + ((a[i-1] - a[i-2]) * 2)
    print(*x)


main()


Measured memory_bytes: 23132
#!/usr/bin/python

import sys

def main(argv):
    line = sys.stdin.readline()
    while line:
        N = int(line)
        K = int(sys.stdin.readline())
        value = 1
        for i in xrange(N):
            value = min(2 * value, value + K)
        print(value)

        line = sys.stdin.readline()

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2568
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)

	writer := bufio.NewWriter(os.Stdout)

	x := getNextInt64(scanner)

	ans := (x / 11) * 2
	if x%11 > 0 {
		ans += (x%11-1)/6 + 1
	}
	fmt.Fprintln(writer, ans)

	writer.Flush()
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>

int main() {
    unsigned long long N, A, B;
    cin >> N >> A >> B;
    unsigned long long sum ;
    unsigned long long roop ;
    if(A==0){
        cout << 0 << endl ;
    }
    else if (B==0){
        cout << N << endl;
    }
    else {
        roop = N / (A + B);

        sum = N - (A + B) * roop;
        if (sum >= A) {
            cout << roop * A + A << endl;
        }
        else {
            cout << roop * A + sum << endl;
        }
    }
}

Measured memory_bytes: 256
h, w = map(int, input().split())
s = [input() for _ in range(h)]

ans = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            for x in (-1, 0, 1):
                for y in (-1, 0, 1):
                    if 0 <= i+x < h and 0 <= j+y < w:
                        if s[i+x][j+y] == "#":
                            ans[i+x][j+y] = "#"
                        else:
                            ans[i+x][j+y] += 1

for i in ans:
    for j in i:
        print(j, end = "")
    print("\n", end = "")

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

using namespace std;

int main(){
 int p[210];
 int m,nm,nM,sub=0,ans;
 while(1){
  cin >> m >> nm >> nM;
  if(m==0)break;
  sub = 0;
  int i;
  for(i=1;i<=m;i++){
   cin >> p[i];
   if(nm<i && i<=nM+1){
    if(p[i-1]-p[i] >= sub){
     sub=p[i-1]-p[i];
     ans=i-1;
    }
   }
  }
  cout << ans << endl;
 }
 return 0;
}


Measured memory_bytes: 3048
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()

ans = INF

for i in range(2):
    if i == 1:
        H, W = W, H
    for a in range(1, H):
        bc = H - a
        b = int(bc/2)
        c = bc - b
        sa, sb, sc = a * W, b * W, c * W
        s = max(sa, sb, sc) - min(sa, sb, sc)
        ans = min(s, ans)
    for a in range(1, H):
        bc = H - a
        b = int(W/2)
        c = W - b
        sa, sb, sc = a * W, b * bc, c * bc
        s = max(sa, sb, sc) - min(sa, sb, sc)
        ans = min(s, ans)
print(ans)

Measured memory_bytes: 5200
n=int(input())
W=list(map(int,input().split()))
Wtot=sum(W)
D=[]
W1=0
for i in range(len(W)):
  for j in range (i+1):
    W1=W1+W[j]
  D.append(abs(2*W1-Wtot))
  W1=0
print(min(D))
    

Measured memory_bytes: 3060
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        MyReader r = new MyReader();  
        int N = r.i();
        ArrayList<Integer>[] A = new ArrayList[N+1];
        Set<Integer> list = new HashSet<>();
        for (int i = 1; i <= N; i++){
            A[i] = r.ii();
            list.add(i);
        }
        for (int day = 1, count = N*(N-1)/2; ; day++) {
            Set<Integer> tmp = new HashSet<>();
            for (int i : list) {
                if (!tmp.contains(i) && A[i].size() > 0 && A[A[i].get(0)].get(0) == i){
                    tmp.add(i);
                    tmp.add(A[i].get(0));
                    count--;
                }
            }
            if (count == 0) {
                println(day);
                return;
            } else if (tmp.size() == 0){
                println(-1);
                return;
            } 
            for (int i : tmp) {
                A[i].remove(0);
            }
            list = tmp;
        }
    }

    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        ArrayList<Integer> ii() throws IOException{
            String[] ss = ss();
            ArrayList<Integer> ii = new ArrayList<>();
            for(String s : ss) ii.add(Integer.parseInt(s));
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long.parseLong(ss[j]);            
            return ll;
        }
    }
}

Measured memory_bytes: 111900
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
//ilya and queries
int main()
{
        long long int n,k;
        cin>>n>>k;
        while(abs(n-k)<n)
        {
            if(n>k)
            n=n-(k*(n/k));
            else if(n<k)
                 n=k-(n*(k/n));
            else
                n=0;
        }
        cout<<n<<endl;
        return 0;
    }


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  int n;
  cin >> n;
  int a[10] = {1,1,0,2,0,0,1,0,1,0};
  char d[3] = {'h','p','b'};
  cout << d[a[n%10]] << "on" << endl;
  return 0;
}


Measured memory_bytes: 3640
import collections

def search_topdown(node, elems, tree, depth):
    elems[node]['depth'] = depth
    if elems[node]['parent'] == -1:
        state = 'root'
    elif tree[node][0] == tree[node][1] == -1:
        state = 'leaf'
    else:
        state = 'internal node'
    elems[node]['state'] = state
    elems[node]['degree'] = len([x for x in tree[node] if x != -1])
    depth += 1
    for c in tree[node]:
        if c == -1:
            continue
        search_topdown(c, elems, tree, depth)

def search_bottomup(node, elems, tree, height):
    if 'height' in elems[node]:
        elems[node]['height'] = max(height, elems[node]['height'])
    else:
        elems[node]['height'] = height
    p = elems[node]['parent']
    if p != -1:
        sibling, another = tree[p]
        if sibling == node:
            sibling = another
    else:
        sibling = -1
    elems[node]['sibling'] = sibling
    height += 1
    if p != -1:
        search_bottomup(p, elems, tree, height)
        
if __name__ == '__main__':
    n = int(input())
    tree = collections.defaultdict(list)
    elems = collections.defaultdict(dict)
    #elems key:id, value: parent, sibling, degree, depth, height, state
    parents = list()
    leaves = set()
    node_list = list()
    for _ in range(n):
        hoge = [int(x) for x in input().split()]
        node_list.append(hoge[0])
        tree[hoge[0]].append(hoge[1])
        tree[hoge[0]].append(hoge[2])
    
    for key, value in tree.items():
        for v in value:
            if v != -1:
                elems[v]['parent'] = key
            else:
                leaves.add(key)
    
    for node in node_list:
        if not elems[node]:
            parents.append(node)
            elems[node]['parent'] = -1
    
    for p in parents:
        search_topdown(p, elems, tree, 0)
    
    for l in leaves:
        search_bottomup(l, elems, tree, 0)
    
    for key, value in sorted(elems.items()):
        print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(key, value['parent'], value['sibling'], value['degree'], value['depth'], value['height'], value['state']))



Measured memory_bytes: 6028
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()

ans=0
prev=['']*k
for i in range(n):
    if t[i]!=prev[i%k]:
        prev[i%k]=t[i]
        if t[i]=='r':
            ans+=p
        elif t[i]=='p':
            ans+=s
        elif t[i]=='s':
            ans+=r
    else:
        prev[i%k]=''
print(ans)


Measured memory_bytes: 3828
n, m, k = map(int, input().split())
ab = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(m)]
cd = [tuple(map(lambda x: int(x)-1, input().split())) for _ in range(k)]

class UnionFind:
    def __init__(self, n):
        self.parent = [-1] * n

    def find(self, x):
        if self.parent[x] < 0: return x
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y: return
        if self.size(x) < self.size(y): x, y = y, x
        self.parent[x] += self.parent[y]
        self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return -self.parent[self.find(x)]
    
uf = UnionFind(n)
for a, b in ab: uf.unite(a, b)
ans = [uf.size(i)-1 for i in range(n)]

for a, b in ab:
    if uf.same(a, b): ans[a] -= 1; ans[b] -= 1
for c, d in cd:
    if uf.same(c, d): ans[c] -= 1; ans[d] -= 1

print(*ans)


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

int main() {
  string s;

  cin >> s;
  if (s.find("a") != string::npos &&
      s.find("b") != string::npos &&
      s.find("c") != string::npos) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t; cin>>s>>t;
  int ans=t.size();
  for(int i=0;i<s.size()-t.size()+1;i++){
    int cnt=t.size();
    for(int j=0;j<t.size();j++){
      if(s[i+j]==t[j]){
        cnt-=1;
      }
    }
    ans=min(ans,cnt);
  }
  cout<<ans<<endl;
  return 0;
}
      

Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    vector<int> y(n);
    for(int i=0;i<n;++i){
        cin >> x[i] >> y[i];
    }
    long long ans=LLONG_MAX;
    for(int xi=0;xi<n;++xi){
        for(int xj=0;xj<n;++xj){
            if(x[xi]>=x[xj])
                continue;
            for(int yi=0;yi<n;++yi){
                for(int yj=0;yj<n;++yj){
                    if(y[yi]>=y[yj])
                        continue;
                    int count=0;
                    for(int i=0;i<n;++i){
                        if(x[xi]<=x[i] && x[i]<=x[xj] && y[yi]<=y[i] && y[i]<=y[yj])
                            ++count;
                    }
                    if(count>=k)
                        ans = min(ans, (long long)(x[xj]-x[xi])*(y[yj]-y[yi]));
                }
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
import math


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def f(b, n):
    S = 0
    while n != 0:
        S += n%b
        n //= b
    return S


def solve():
    """
    87654
    138
    -----
    100

    87654
    45678
    -----
    -1

    """
    n = read_int()
    s = read_int()
    for b in range(2, math.ceil(math.sqrt(n))+1):
        if f(b, n) == s:
            return b
    """
    16

    4
    if b>math.sqrt(n) then n=pb+q, p, q < b
                           s=p+q
    n-s=p*(b-1), b-1 >= p
    """
    if n-s < 0:
        return -1
    if n == s:
        return n+1
    for p in range(math.ceil(math.sqrt(n-s)), 0, -1):
        if (n-s)%p == 0 and f((n-s)//p+1, n) == s:
            return (n-s)//p+1
    return -1


if __name__ == '__main__':
    #print(f(10, 87654))
    #print(f(100, 87654))
    print(solve())


Measured memory_bytes: 67676
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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


int N;
ll a[400];

ll csum[400][400];
ll dp[400][400];

ll dfs(int left, int right)
{
    if (dp[left][right] != -1) {
        return dp[left][right];
    }
    else if (left == right) {
        return 0;
    }
    else if (left + 1 == right) {
        dp[left][right] = csum[left][right];
        return csum[left][right];
    }
    else {
        ll minCost = 1000000000000000;
        for (int m = left; m < right; ++m) {
            ll t = dfs(left, m) + dfs(m + 1, right) +(csum[left][m] + csum[m + 1][right]);
            if (t < minCost) minCost = t;
        }
        dp[left][right] = minCost;
        return minCost;
    }
}

int main(int argc, char **argv)
{
    cin >> N;
    REP(i, N) cin >> a[i];

    REP(i, N) {
        FOR(j, i, N) {
            ll s = 0;
            FOR(k, i, j + 1) {
                s += a[k];
            }
            csum[i][j] = s;
        }
    }

    REP(i, 400) REP(j, 400) dp[i][j] = -1;
    cout << dfs(0, N - 1) << endl;

    return 0;
}


Measured memory_bytes: 2816
#include <stdio.h>
long long a [100010];
int main (){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%lld",&a[i]);
int zero =0;
for(int i=0;i<n;i++)if(a[i]==0) zero ++;
if(zero >0){
// a[i] contains 0
printf("0\n");
return 0;
}
long long prod =1;
for(int i=0;i<n;i++){
if(a[i ] <=1000000000000000000/ prod ){
// This condition is equivalent to prod*a[i] <=10ˆ18
prod *=a[i];
}else{
printf("-1\n");
return 0;
}
}
printf("%lld\n",prod );
}


Measured memory_bytes: 2516
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
	cin>>s;
	int n=s.length();
	for(int i=0;i<n;i++)if(s[i]!=s[n-i-1])return puts("No"),0;
	for(int i=0;i<(n-1)/2;i++)if(s[i]!=s[(n-1)/2-i-1])return puts("No"),0;
	for(int i=(n+1)/2;i<n;i++)if(s[i]!=s[n-1-(i-(n+1)/2)])return puts("No"),0;
	return puts("Yes"),0;
}


Measured memory_bytes: 256