akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e9+7;

vector<ll> a,ans;

vector<vector<ll>> to(200005);
vector<ll> dp(200005);

void dfs(ll v,ll p=-1){
    ll i=lower_bound(dp.begin(),dp.end(),a[v])-dp.begin();
    ll old=dp[i];
    dp[i]=a[v];
    ll len=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();
    ans[v]=len;
    for(auto x:to[v]){
        if(x==p) continue;
        dfs(x,v);
    }
    dp[i]=old;
    return ;
}


int main()
{
    ll n;
    cin >> n;
    a=vector<ll>(n);
    ans=vector<ll>(n);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n-1){
        ll u,v;
        cin >> u >> v;
        u--; v--;
        to[u].push_back(v);
        to[v].push_back(u);
    }
    rep(i,200005){
        dp[i]=INF;
    }
    dfs(0);
    rep(i,n){
        cout << ans[i] << endl;
    }
    return 0;
} 


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

using namespace std;

int main()
{
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K <= A){
        cout<<K<<endl;
    }else if(K == A+B){
        cout<<A<<endl;
    }else if(K > A+B){
        cout<<A-(K-(A+B))<<endl;
    }
    return 0;
}


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

int main(){
  int n; cin>>n;
  vector<pair<int,int>> s(n),t(n);
  for(int i=0;i<n;i++){
    int x,y; cin>>x>>y;
    s[i]=pair<int,int>(x,y);
  }
  for(int i=0;i<n;i++){
    int x,y; cin>>x>>y;
    t[i]=pair<int,int>(x,y);
  }sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  int ans=0;
  for(int i=0;i<n;i++){
    int log=-1;
    for(int j=0;j<n;j++){
      if(s[j].first>t[i].first) break;
      if(t[i].second<s[j].second) continue;
      if(log==-1){
        log=j; ans++;
      }else{
        if(s[log].second<s[j].second) log=j;
      }
    }if(log!=-1)  s[log].second=100000;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()
typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

main()
{
  int x[3][3];
  int tmp[3][3];
  int A, B, C;
  cin >> A >> B >> C;
  
  x[0][0] = tmp[0][0] = A;
  x[0][1] = tmp[0][1] = B;
  x[1][1] = tmp[1][1] = C;

  int sum = max(A+B, max(B+C, C+A)) + 1;
  bool flag = true;
  while( flag ) {
    tmp[0][2] = sum - (A + B);
    tmp[2][1] = sum - (B + C);
    tmp[2][2] = sum - (C + A);

    tmp[1][2] = sum - (tmp[0][2] + tmp[2][2]);
    tmp[1][0] = sum - (tmp[1][1] + tmp[1][2]);
    tmp[2][0] = sum - (tmp[0][0] + tmp[1][0]);

    /*if( flag ) {
      sum++;
      continue;
      }*/
    int conf[2][3] = {{0}};
    Rep(i, 3) Rep(j, 3) conf[0][i] += tmp[i][j];
    Rep(i, 3) Rep(j, 3) conf[1][j] += tmp[i][j];
    bool flag2 = true;
    if( tmp[0][0] + tmp[1][1] + tmp[2][2] != sum ||
	tmp[0][2] + tmp[1][1] + tmp[2][0] != sum ) {
      flag2 = false;
    }
    
    if( flag2 ) break;
    else flag = true;
    sum++;
  }

  Rep(i, 3) {
    Rep(j, 3) {
      cout << tmp[i][j] << " ";
    }
    cout << endl;
  }
}


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

const int N = 200005, P = 1e9 + 7;
int T, n;
long long a[N], x, y;
int main()
{
	scanf("%d", &n);
	for(int i = 0; i < n; ++i) scanf("%d", &a[i]);
	for(int i = 0; i < n; ++i)
	{
		x = (x + a[i]) % P;
		y = (y + a[i] * a[i]) % P;
	}
	x = (x * x - y + P) % P;
	if(x & 1) x += P;
	x >>= 1;
	cout << x << endl;
	return 0;
}


Measured memory_bytes: 5320
A_1_list = list(map(int, input().split()))
A_1_set = set(A_1_list)
A_2_list = list(map(int, input().split()))
A_2_set = set(A_2_list)
A_3_list = list(map(int, input().split()))
A_3_set = set(A_3_list)
N = int(input())
b_set = {int(input()) for i in range(N)}
A_i_1_set = {A_1_list[0], A_2_list[0], A_3_list[0]}
A_i_2_set = {A_1_list[1], A_2_list[1], A_3_list[1]}
A_i_3_set = {A_1_list[2], A_2_list[2], A_3_list[2]}
A_d_1_set = {A_1_list[0], A_2_list[1], A_3_list[2]} #左上から右下
A_d_2_set = {A_1_list[2], A_2_list[1], A_3_list[0]} #右上から左下

#横１列が揃ったビンゴ
if A_1_set <= b_set or A_2_set <= b_set or A_3_set <= b_set:
    print('Yes')
#縦一列のビンゴ
elif A_i_1_set <= b_set or A_i_2_set <= b_set or A_i_3_set <= b_set:
    print('Yes')
#斜めのビンゴ
elif A_d_1_set <= b_set or A_d_2_set <= b_set:
    print('Yes')
else:
    print('No')


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

#define ll long long
#define ar array
#define vi vector<int>
#define INF 1000000000

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int R; cin >> R;				
	double pi = 3.14159265358979323846;
	double circumfrence = 2 * pi * R  ;
	printf("%.18lf", circumfrence);
	cout << endl;
	return 0;
}


Measured memory_bytes: 3724
#include<iostream>
#include<vector>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
ll n, m, x;
ll c[12], a[12][12], maxsum[12];
bool check(bool l[]) {
    ll skill[m];
    for (int j = 0; j < m; j++) {
        skill[j]  = 0;
    }
    for (int i = 0; i < n; i++) {
        if (l[i]) {
            for (int j = 0; j < m; j++) {
                skill[j] += a[i][j];
            }
        }
    }
    bool check = true;
    for (int j = 0; j < m; j++) {
        if (skill[j] < x) {
            check = false;
            break;
        }
    }
    return check;
}

ll costSum(bool l[]) {
    if (check(l)) {
        ll count = 0;
        for (int i = 0; i < n; i++) {
            if (l[i]) {
                count += c[i];
            }
        }
        return count;
    } else {
        return 1300000;
    }
}
ll search(bool l[], ll p) {
    if (p == n) {
        return costSum(l);
    } else {
        bool copyl[n], copyl2[n];
        for (int i = 0; i < n; i++) {
            if (l[i]) {
                copyl[i] = true;
                copyl2[i] = true;
            } else {
                copyl[i] = false;
                copyl2[i] = false;
            }
        }
        copyl2[p] = true;
        p++;
        ll g = search(copyl, p);
        ll o = search(copyl2, p);
        return min(g, o);
    }
}

int main() {
    cin >> n >> m >> x;
    for (int j = 0; j < m; j++) {
        maxsum[j] = 0;
    }
    for (ll i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            maxsum[j] += a[i][j];
        }
    }
    bool check = true;
    for (int j = 0; j < m; j++) {
        if (maxsum[j] < x) {
            check = false;
            break;
        }
    }
    if (!check) {
        cout << -1 << endl;
    } else {
        bool l[n];
        rep(i, n) l[i] = false;
        cout << search(l, 0) << endl;
    }
}


Measured memory_bytes: 3640
N = int(input())
L = list(map(int, input().split()))

ans = 0

for k in range(2, N):
    for j in range(1, k):
        for i in range(j):
            if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]:
                continue
            elif L[i] + L[j] > L[k] and L[j] + L[k] > L[i] and L[k] + L[i] > L[j]:
                ans += 1

print(ans)

Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;

ll gcd(ll a, ll b){
    return b?gcd(b, a%b):a;
}

int main() {
    ll k;
    cin >> k;
    ll res = 0;
    for (ll a = 1; a <= k; ++a) {
        for (ll b = 1; b <= k; ++b) {
            auto ab = gcd(a,b);
            for (ll c = 1; c <= k; ++c) {
                res += gcd(ab, c);
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
#define forn(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using namespace std;

const int MAXN = 50;
ll a[MAXN + 1];
int n;

bool check() {
    for(int i = 0; i < n; i++)
        if(a[i] >= n)
            return false;
    return true;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    ll ans = 0;
    while(!check()) {
        ll sum = 0;
        for(int i = 0; i < n; i++)
            sum += a[i] / n;
        ans += sum;
        for(int i = 0; i < n; i++)
            a[i] = a[i] % n + sum - a[i] / n;
    }
    cout << ans << "\n";
    return 0;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int[] tmp = new int[n];
		int[] max = new int[n];
		for (int i =0;i<n;i++) {
			array[i]=sc.nextInt();
			tmp[i]=array[i];
			max[i]=0;
		}

		Arrays.sort(tmp);
		int a = tmp[n-1];
		int b = tmp[n-2];

		for(int i=0;i < n; i++) {
			if(a == array[i]) {
				max[i] = b;
			}else max[i] =a;
		}

		for(int i=0; i < n; i++)
		System.out.println(max[i]);

		sc.close();
	}
}


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



int main(){
	string S;
	cin>>S;
	if(S[5]=='1'||S[6]>='5'){
		cout<<"TBD"<<endl;
	}
	else{
		cout<<"Heisei"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
signed main()
{
int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x>>y;
if(x==1&&y==1){
  std::cout << "Draw" << '\n';
}else if(x==1||y==1){
  if(x==1){
    std::cout << "Alice" << '\n';
  }else std::cout << "Bob" << '\n';
}else {
  if(x>y){
    std::cout << "Alice" << '\n';
  }else if(x==y){
    std::cout << "Draw" << '\n';
  }else std::cout << "Bob" << '\n';
}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,x,a=0;
    cin>>n>>m>>x;
    vector<int> s(m);
    for(int i=0;i<m;i++){
        cin>>s.at(i);
        if(s.at(i)<x){
            a+=1;
        }
    }
    cout<<min(a,m-a)<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
using namespace std;

#define FOR(i,n) for(int i=0;i<n;i++)
#define PRINT(a) cout<<a<<"\n"
#define QUO(x,y) (x-x%y)/y	//x÷yの商
 
int main(){

	char a[10],b[10],c[10];
	cin>>a>>b>>c;

	

	cout<<(char)toupper(a[0])
		<<(char)toupper(b[0])
		<<(char)toupper(c[0])<<endl;
	
	
	

	return 0;
}

Measured memory_bytes: 256
# coding:utf-8

INF = float('inf')
def inpl(): return list(map(int, input().split()))


n = int(input())

ans = 0
for i in range(9, n+1, 2):
    count = 0
    for j in range(1, i+1, 2):
        if i % j == 0: count += 1

    if count == 8:
        ans += 1

print(ans)

Measured memory_bytes: 3060
(let ((*read-default-float-format* 'double-float)
      (a (read))
      (b (read))
      (h (read))
      (m (read)))
  (let* ((m-hand (* (/ m 60) 2 pi))
         (h-hand (* (/ (+ h (/ m 60)) 12) 2 pi))
         (angle (- (max m-hand h-hand)
                   (min m-hand h-hand))))
    (format t "~16,16f~%"
            (sqrt (+ (* a a)
                     (* b b)
                     (* -2 a b (cos angle)))))))


Measured memory_bytes: 24148
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(int i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 5206


signed main(){
	int a,b,c,d,t=1;
	cin>>t;
	vector<int> v;
	For(i,0,t){
		cin>>a;	v.pb(a);
	}
	int dp[t];
	if(t==2)
		cout<<v[1]-v[0];
	else{
		dp[0]=0;
		dp[1]=abs(v[1]-v[0]);
		For(j,2,t){
			dp[j]=min(dp[j-1]+abs(v[j]-v[j-1]),dp[j-2]+abs(v[j]-v[j-2]));
		}
		cout<<dp[t-1];
	}

}

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

int main() {
  long long n,a,b,c = 0;
  cin >> n >> a >> b;
  if((a + b) != 0){
    c = n / (a + b);
    n = n % (a + b);
  }
  if (n > a){
    cout << a * (c + 1) << endl;
  }
  else{
    cout << c * a + n  << endl;
  }
}

Measured memory_bytes: 256
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,t,temp,x,y;
string str;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll dp[n+1000];
	ll k;
	cin>>k;
	for(int i=0;i<=n;i++)
	dp[i]=llmax;
	vll v(n);
	read(v);
	dp[1]=0;
	for(int i=2;i<=1+k;i++)
	{
	    dp[i]=min(dp[i],dp[1]+abs(v[i-1]-v[0]));
	}
	for(int i=2;i<=n;i++)
	{
	    for(int j=i+1;j<=i+k;j++)
	    dp[j]=min(dp[j],dp[i]+abs(v[j-1]-v[i-1]));
	}
	cout<<dp[n];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n) a[i] = a[i]-1;
    int ans = 1;
    int p1=a[0];
    rep(i,100000){
        if(p1 == 1){
            cout << ans << endl;
            return 0;
        }
        p1 = a[p1];
        ans++;
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3796
#include<cstdio>

int main(){
  int n,q,c = 0;
  int s[10000];
  int t[500];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",s+i);
  }
  scanf("%d",&q);
  for(int i=0;i<q;i++){
    scanf("%d",t+i);
  }
  for(int i=0;i<q;i++){
    for(int j=0;j<n;j++){
      if(s[j]==t[i]){
        c++;
        break;
      }
    }
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 2720
/*
██████╗  ███████╗  
██╔══██╗ ██╔════╝ 
██████╔╝ ███████╗ 
██╔══██╗ ╚════██║  
██║  ██║ ███████║      
╚═╝  ╚═╝ ╚══════╝                                                                                                             
*/

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define haha(j,a,n) for(int j=a;j<n;j++)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define endl "\n"
#define bc(v) v.begin(),v.end()
#define vl vector<ll>
#define vi vector<int>
#define mod 1000000007
#define NUM 100005
#define F first
#define S second
#define bhar(a) rep(i,a.size()) cin>>a[i];
#define show(a) rep(i,a.size()) cout<<a[i]<<" ";
#define sott(a) sort(bc(a))
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define mapp map<ll,ll>
#define dkac cout<<fixed<<setprecision(15);
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define yeah(n) while(n--)
ll gcd(int a, int b){if(b==0) return a; else return gcd(b,a%b);}
ll bitfun(ll x){
    return (x&(-x));
}
void solve(){
    string s,t; cin>>s>>t;
    if(s.size()==t.size()-1){
        string x = t.substr(0,s.size());
        if(x==s){
            cout<<"Yes"; return ;
        }
    }
    cout<<"No";
}
int main(){
    ios
    int t=1; 
    //cin>>t;
    yeah(t){
        solve();
    }
}

Measured memory_bytes: 3644
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int same = 0;
    if (a == b) { same++; }
    if (a == c) { same++; }
    if (b == c) { same++; }

    if (same == 1) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int x,a[200000],i,n,r=-1e9,r0;

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

  for(i=1;i<n;i++){
    r0=a[i]-x;
    if(r<r0) r=r0;
    if(x>a[i]) x=a[i];
  }

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

  return 0;

}



Measured memory_bytes: 2576
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		for (int N = sc.nextInt() ; N > 0; N--) {
			int[] data = new int[10];
			Tube t1 = new Tube();
			Tube t2 = new Tube();
			boolean flag = true;

			for (int i=0; i < 10; i++) {
				data[i] = sc.nextInt();
				if (data[i] > t1.look()) {
					t1.dropBall(data[i]);
				} else if (data[i] > t2.look()) {
					t2.dropBall(data[i]);
				} else {
					flag = false;
				}
			}

			if (flag) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

	public static class Tube {
		int[] tube;

		int pointer;

		public Tube() {
			tube = new int[11];
			tube[0] = -1;
			pointer = 0;
		}

		public int look() {
			return tube[pointer];
		}

		public void dropBall(int b) {
			pointer++;
			tube[pointer] = b;
		}
	}
}

Measured memory_bytes: 26224
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL inf = 11234567890123;
LL N, W;
std::vector<LL>w, v;
std::vector<std::vector<LL>>memo;

LL dp(LL i, LL j)
{
	if (j == 0) return 0;
	if (i == -1) return inf;
	if (memo[i][j] != -1) return memo[i][j];
	LL res;
	if (j < v[i]) res = dp(i - 1, j);
	else res = std::min(dp(i - 1, j - v[i]) + w[i], dp(i - 1, j));
	return memo[i][j] = res;
}

int main()
{
	in >> N >> W;
	w.resize(N); v.resize(N);
	rep(i, N) in >> w[i] >> v[i];

	memo.resize(N);
	rep(i, memo.size()) memo[i].resize(112345, -1);
	LL ans = 0;
	for (LL j = 0; j < 112345; ++j)
	{
		if (dp(N - 1, j) <= W) ans = std::max(ans, j);
	}
	out << ans << std::endl;
}


Measured memory_bytes: 88316
#include <stdio.h>
#define MAX 500000
#define SENTINEL 2000000000
  
int l[MAX/2+2], r[MAX/2+2];
int count = 0;
  
void merge(int [], int, int, int, int);
void mergeSort(int [], int, int, int);
  
int main(){
  int a[MAX], n, i;
  
  scanf("%d", &n);
  for(i = 0;i < n;i++){
    scanf("%d", &a[i]);
  }
  mergeSort(a, n, 0, n);
  for(i = 0;i < n;i++){
    if(i) printf(" ");
    printf("%d", a[i]);
  }
  printf("\n");
  printf("%d\n", count);
  return 0;
}
  
void merge(int a[], int n, int left, int mid, int right){
  int n1, n2, i, j, k;
  
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0;i < n1;i++){
    l[i] = a[left+i];
  }
  for(i = 0;i < n2;i++){
    r[i] = a[mid+i];
  }
  l[n1] = r[n2] = SENTINEL;
  i = j = 0;
  for(k = left;k < right;k++){
    count++;
    if(l[i] <= r[j]){
      a[k] = l[i++];
    }
    else a[k] = r[j++];
  }
}
  
void mergeSort(int a[], int n, int left, int right){
  int mid;
  
  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(a, n, left, mid);
    mergeSort(a, n, mid, right);
    merge(a, n, left, mid, right);
  }
}

Measured memory_bytes: 4508
#include <iostream>

using namespace std;

int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        if(a>c){
            cout<<"A";
        }
        else{
            cout<<"C";
        }
    }
    else if(b>c){
        cout<<"B";
    }
    else{
        cout<<"C";
    }
    
    cout<<endl;
    
    return 0;
}


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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par,sz,vis;
vector<vi> graph;

void init(li n)
{
    par.resize(n);
    sz.resize(n);
    vis.resize(n);
    graph.resize(n);

    f(i,0,n-1)
    {
        par[i]=i;
        sz[i]=1;
    }
}

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    li r_a=root(a);
    li r_b=root(b);

    if(par[r_a]!=r_b)
    { 
        if(sz[r_a]<sz[r_b])
        {
            par[r_a]=par[r_b];
            sz[r_b]+=sz[r_a];
            sz[r_a]=0;
        }
        else
        {
            par[r_b]=par[r_a];
            sz[r_a]+=sz[r_b];
            sz[r_b]=0;
        }
    }
}

int main()
{    
   

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li n;

    cin>>n;

    li a[n];

    for(li i=0;i<n;i++)
        cin>>a[i];

    vi mn(n);

    fill(mn.B,mn.E,INT_MAX);

    li cnt=0;

    mn[0]=a[0];

    f(i,1,n-1)
    {
        if(mn[i-1]>=a[i])
        {
            cnt++;
        }

        mn[i]=min(mn[i-1],a[i]);
    }

    cout<<cnt+1;

    return 0;
}

Measured memory_bytes: 3328
n,k=map(int,input().split())
z=[list(map(int,input().split()))for _ in range(n)]
x=[]
y=[]
for i,j in z:
    x.append(i)
    y.append(j)
x.sort()
y.sort()
a=10**20
for i,l in enumerate(x):
    for r in x[i+1:]:
        for v,d in enumerate(y):
            for u in y[v+1:]:
                if sum([1for i,j in z if l<=i<=r and d<=j<=u])>=k:
                    a=min(a,(r-l)*(u-d))
print(a)

Measured memory_bytes: 62172
from collections import deque

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
write = sys.stdout.write
N = int(readline())
G = [None]*N
for i in range(N):
    k, *c = map(int, readline().split())
    G[i] = c

H = [0]*N
prv = [None]*N
def dfs(v):
    s = 1; heavy = None; m = 0
    for w in G[v]:
        prv[w] = v
        c = dfs(w)
        if m < c:
            heavy = w
            m = c
        s += c
    H[v] = heavy
    return s
dfs(0)


SS = []
D = []
L = [0]*N
I = [0]*N
que = deque([(0, 0)])
while que:
    v, d = que.popleft()
    S = []
    k = len(SS)
    while v is not None:
        I[v] = len(S)
        S.append(v)
        L[v] = k
        h = H[v]
        for w in G[v]:
            if h == w:
                continue
            que.append((w, d+1))
        v = h
    SS.append(S)
    D.append(d)


C = list(map(len, SS))
DS0 = [[0]*(c+1) for c in C]
DS1 = [[0]*(c+1) for c in C]
def add(K, data, k, x):
    while k <= K:
        data[k] += x
        k += k & -k
def get(K, data, k):
    s = 0
    while k:
        s += data[k]
        k -= k & -k
    return s

def query_add(v, x):
    while v is not None:
        l = L[v]; i = I[v]
        add(C[l], DS1[l], i+1, -x)
        add(C[l], DS1[l], 1, x)
        add(C[l], DS0[l], i+1, x*(i+1))
        v = prv[SS[l][0]]

def query_sum(v):
    s = - get(C[0], DS1[L[0]], 1) - get(C[0], DS0[L[0]], 1)
    while v is not None:
        l = L[v]; i = I[v]
        s += get(C[l], DS1[l], i+1)*(i+1) + get(C[l], DS0[l], i+1)
        v = prv[SS[l][0]]
    return s


Q = int(readline())
ans = []
for q in range(Q):
    t, *cmd = map(int, readline().split())
    if t:
        ans.append(str(query_sum(cmd[0])))
    else:
        v, w = cmd
        query_add(v, w)
write("\n".join(ans))
write("\n")



Measured memory_bytes: 124836
#include <cstdio>
int main(){
    int n, b, f, r, v;
    int rooms[4][3][10] = {};
    
    scanf("%d", &n);
    int infos[n][4];
    for (int i = 0; i < n; i++){
        scanf("%d%d%d%d", &infos[i][0], &infos[i][1], &infos[i][2], &infos[i][3]);
    }
    for (int i = 0; i < n; i++){
        rooms[infos[i][0]-1][infos[i][1]-1][infos[i][2]-1] += infos[i][3];
    }
    for (int i = 0; i < 4; i++){
        for (int j = 0; j < 3; j++){
            for (int k = 0; k < 10; k++){
                printf(" %d", rooms[i][j][k]);
            }
            printf("\n");
        }
        if (i != 3) printf("####################\n");
    }
    return 0;
}

Measured memory_bytes: 2744
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

vector<vector<int>> v(200020);
ll used[200020];
ll r;
ll fs;
ll st;
void dfs(int p,int d){
    used[p] = d;
    for(auto i:v[p]){
        if(!used[i])dfs(i,d+1);
        else{
            fs = used[i]-1;
            r = d+1-used[i];
            st = i;
            return;      
        }
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        a[i]--;
        v[i].push_back(a[i]);
    }
    used[0] = 1;
    dfs(0,1);
    if(k <= fs){
        ll now = 0;
        ll cnt = 0;
        while(cnt < k){
            now = a[now];
            cnt++;
        }
        cout << now +1 << endl;
        return 0;
    }
    k -= fs;
    k %= r;
    ll now = st;
    ll cnt = 0;
    while(cnt < k){
        now=a[now];
        cnt++;
    }

    cout << now+1 << endl;


}

Measured memory_bytes: 26372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <array>

using namespace std;

#define ll long long
#define all(v) v.begin(),v.end()
#define bootstrap ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
// custom hash can be a standalone function object:
struct MyHash
{
    std::size_t operator()(pair<long, long> const& p) const noexcept
    {
        std::size_t h1 = std::hash<long>{}(p.first);
        std::size_t h2 = std::hash<long>{}(p.second);
        return h1 ^ (h2 << 1); // or use boost::hash_combine (see Discussion)
    }
};

struct MyComp
{
    template<typename T>
    std::size_t operator()(T &l, T &r) const noexcept
    {
        return l < r;
    }
};

void solve() {
    int n;
    cin >> n;
    ll total = 0;
    for(int i = 1; i< n; i ++) {
        total += (n - 1) / i;
    }
    cout << total;
}

int main() {
    bootstrap
    solve();
}


Measured memory_bytes: 3192
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	ll k;
	int n;
	string s;
	cin>>s>>k;
	n=s.size();
	int cnt=1;
	vector<int> v;
	for(int i=1; i<n; i++){
		if(s[i]!=s[i-1]){
			v.push_back(cnt);
			cnt=0;
		}
		cnt++;
	}
	v.push_back(cnt);
	ll ans=0;
	if(s.back()!=s[0]){
		for(auto x:v){
			ans+=x/2;
		}
		ans*=k;
		cout<<ans<<endl;
		return 0;
	}
	if(v.size()==1){
		cout<<(ll)n*k/2<<endl;
		return 0;
	}
	for(int i=1; i<(int)v.size()-1; i++){
		ans+=v[i]/2;
	}
	ans*=k;
	ans+=(k-1)*((v.back()+v[0])/2);
	ans+=v[0]/2;
	ans+=v.back()/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll ans = 0;
ll d[55] = {};
ll v[55] = {};
void check(ll n, ll x){
    x--;
    if(x == 0) return;
    if(x >= v[n-1]){
        ans += d[n-1];
        x -= v[n-1];
    }else{
        check(n-1, x);
        return;
    }
    if(x >= 1){
        ans++;
        x--;
    }else{
        return;
    }
    if(x == 0) return;
    if(x >= v[n-1]){
        ans += d[n-1];
        x -= v[n-1];
    }else{
        check(n-1, x);
        return;
    }
    x--;
    return;

}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X;
    cin >> N >> X;
    d[0] = 1;
    rep(i,1,51){
        d[i] = 2 * d[i-1] + 1;
    }
    v[0] = 1;
    rep(i,1,51){
        v[i] = 2 * v[i-1] + 3;
    }
    ll x = X;
    check(N, X);
    print(ans);
}


Measured memory_bytes: 256
#include<stdio.h>

int p(int);
int l(int);
int r(int);

int main(){
  int key,i,a[100001];

  scanf("%d",&key);

  for(i=0;i<key;i++){
    scanf("%d",&a[i+1]);
  }

  for(i=0;i<key;i++){
    printf("node %d: key = %d, ",i+1,a[i+1]);

    if(p(i+1)>=1) printf("parent key = %d, ",a[p(i+1)]);
    if(l(i+1)<=key) printf("left key = %d, ",a[l(i+1)]);
    if(r(i+1)<=key) printf("right key = %d, ",a[r(i+1)]);

    printf("\n");
  }
    
  return 0;
}

int p(int n){
  return n/2;
}

int l(int n){
  return 2*n;
}

int r(int n){
  return 2*n+1;
}



Measured memory_bytes: 2036
N,P=map(int,input().split())
S=input()
list=[0 for _ in range(P)]
list[0]=1
now=0
a=0
if P==2 or P==5:
  M=len(S)
  S=reversed(S)
  l=0
  for s in S:
    if int(s)%P==0:
      a+=M-l
      l+=1
    else:
      l+=1
  print(a)
    

else:
  b=1
  h=0
  for s in reversed(S):
    h=h+b*int(s)
    list[h%P]+=1
    b=b*10%P
    
  c=0
  for i in range(len(list)):
    c+=list[i]*(list[i]-1)/2
  print(int(c))

Measured memory_bytes: 3500
/**
 *  winners never quit
**/

#include <bits/stdc++.h>

using namespace std;

#define pb push_back
#define pp pop_back
#define mp make_pair
typedef long long Long;
void FastIO(){
  ios::sync_with_stdio(0);
  cin.tie(0);cout.tie(0);
}

const int N = 1e5;

int main()
{
  FastIO();
  int tc, ca = 0;
  Long n;
  cin >> n;
  Long ans = 1e15;
  for (Long i = 1;i*i <= n;i++){
    if (n%i == 0){
      ans = min(ans, (i-1)+(n/i-1));
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3652
n, m = map(int, input().split())
t = [tuple(map(int, input().split())) for i in range(m)]
t1 = [tt[0] for tt in t]
t2 = [tt[1] for tt in t]
r = min(t2) - max(t1) + 1
r = r if r >= 0 else 0
print(r)


Measured memory_bytes: 18184
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn gcm(a: i32, b: i32) -> i32{
    if b == 0{
        a
    }else{
        gcm(b, a%b)
    }
}

fn main(){
    let line: Vec<i32> = read_as_vec();
    let (_, x) = (line[0], line[1]);

    let cities: Vec<i32> = read_as_vec();
    let mut ans = (cities[0] - x).abs();
    for city in &cities{
        ans = gcm(ans, (city-x).abs());
    }
    println!("{}", ans);
    
}


Measured memory_bytes: 4352
const Main = ipt => {
  const [ k, S ] = ipt.split('\n');
  const K = Number(k);
  if(S.length <= K) {
    console.log(S)
    return;
  }
  else {
    console.log(`${S.slice(0,K)}...`);
    return;
  }
};

Main(require('fs').readFileSync('/dev/stdin', 'utf8'))

/*Main(`7
nikoandsolstice`)*/


Measured memory_bytes: 29624
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int N;
    string s[2];
    cin >> N >> s[0] >> s[1];

    long long ans = 1LL;
    const long long MOD = 1000000007;
    rep (i, N) {
        if (s[0][i] == s[1][i]) {
            if (!i) {
                (ans *= 3LL) %= MOD;
            }
            else {
                if (s[0][i - 1] != s[1][i - 1]) {
                    (ans *= 1LL) %= MOD;
                }
                else {
                    (ans *= 2LL) %= MOD;
                }
            }
        }
        else {
            if (!i) {
                (ans *= 6LL) %= MOD;
            }
            else {
                if (s[0][i - 1] != s[1][i - 1]) {
                    (ans *= 3LL) %= MOD;
                }
                else {
                    (ans *= 2LL) %= MOD;
                }
            }
            i++;
        }
    }

    cout << ans << endl;
    return 0;
}

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

int main() {
    char ch;
    cin >> ch;
    if(ch < 94) cout << "A" << endl;
    else cout << "a" << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
#define bitSearch(bit, n) for(int bit = 0; bit < (1 << N); bit++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;

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

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

ll inf = 10000000;
ll mod = 1000000007;

int main() {
    char a, b, c, d;
    cin >> a >> b >> c >> d;
    bool ok = false;
    if (a == b && a != c && c == d) { ok = true; }
    if (a == c && a != d && b == d) { ok = true; }
    if (a == d && a != b && c == b) { ok = true; }
    if (ok) { cout << "Yes" << endl; } else { cout << "No" << endl; }

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

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

q, k = map(int, input().split())
depth = [-1 for _ in range(n)]

def dfs(v, p, d):
  depth[v] = d
  for to, c in ablist[v]:
    if to == p:
      continue
    dfs(to, v, d + c)

dfs(k-1, -1, 0)
for _ in range(q):
  x, y = map(int, input().split())
  print(depth[x-1] + depth[y-1])


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

int main(){
    int x, y;
    while(1){
        cin >> x >> y;
        if(x==0 && y==0){
            break;
        }else{
            if(x>y){ cout << y << " " << x << endl; }
            else{ cout << x << " " << y << endl; }
        }
    }
    return 0;
}

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

int main() {
	int n, a[100002], ans,k,s,j;
	cin >> n;
	ans = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	a[n] = -1;
	sort(a, a + n);
	k = 0;
	while (k < n) {
		j = k+1;
		s = 1;
		while (a[k] == a[j]) {
			s++;
			j++;
		}
		if(s % 2 == 1)ans++;
		k = j;
	}
	cout << ans << endl;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K,C; string S; cin >> N >> K >> C >> S;
    vector<int> dp(N+1,0);
    for (int i=N-1;i>=0;--i){
        if (S[i]=='o') dp[i]=dp[min(N,i+C+1)]+1;
        else dp[i]=dp[i+1];
    }
    int now=0;
    for (int i=0;i<N;++i){
        if (S[i]=='o'){
            if (now+dp[i+1]<K){
                cout << i+1 << '\n';
            }
            i+=C; ++now;
        }
    }
}

Measured memory_bytes: 2580
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;
int main(void){
    // Your code here!
    int n,k;
    cin >> n >> k;
    double p=0;
    for(int i=0; i < n;i++){
        double t=log((double)k/(i+1))/log(2);
        if(t>0)p+=pow(0.5,ceil(t))/n;
        else p+=(double)1/n;
    }
    printf("%.10lf\n", p);
    
    return 0;
}

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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[5];
		for(int i = 0; i < a.length; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[4]+" "+a[3]+" "+a[2]+" "+a[1]+" "+a[0]);
	}
}

Measured memory_bytes: 17332
N, K, Q = map(int, input().split())
A = [ int(input()) for _ in range(Q) ]

point_list = [0 for _ in range(N)]

for q in range(Q):
    point_list[A[q] - 1] += 1

for n in range(N):
    print('No' if Q - point_list[n] >= K else 'Yes')

Measured memory_bytes: 8644
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

const INF: isize = 1_000_000_000_000_000;

fn main() {
    let nm = readn::<usize>(" ");
    let n = nm[0];
    let m = nm[1];
    let edge = (0..m).map(|_| readn::<isize>(" ")).collect::<Vec<Vec<isize>>>();
    let mut d = vec![0; n];

    let mut count = 0;
    let mut n_update = false;
    while count <= n {
        let mut flg = true;
        for e in edge.iter() {
            let a = (e[0] - 1) as usize;
            let b = (e[1] - 1) as usize;
            let c = e[2];
            if d[b] < d[a] + c {
                flg = false;
                d[b] = d[a] + c;
                if b == n - 1 && count == n {
                    n_update = true;
                }
            }
        }
        if flg { break; }
        count += 1;
    }
    if !n_update {
        let mut d = vec![INF; n];
        let mut count = 0;
        d[0] = 0;
        while count < n {
            let mut flg = true;
            for e in edge.iter() {
                let a = (e[0] - 1) as usize;
                let b = (e[1] - 1) as usize;
                let c = e[2];
                if d[b] > d[a] - c {
                    flg = false;
                    d[b] = d[a] - c;
                }
            }
            if flg { break; }
            count += 1;
        }
        println!("{}", d[n-1] * -1);
    } else {
        println!("inf");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)

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

template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}
//******************************************************************************

int N,K;
signed main()
{
	//IOS();
	cin>>N>>K;
	double ans = 0;
	rep(i,1,N+1){
		int t = i;
		double res = 1.0/N;
		while(t<K){
			res /= 2.0;
			t*=2;
		}
		ans += res;
	}
	printf("%.20lf",ans);
}


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

bool has3(int x){
    while(x){
        if ( x % 10 == 3) return true;
        x /= 10;
    }
    return false;
}
void call (int n){
    for (int x = 1; x <= n; x++){
        if (x % 3 == 0 || has3(x) ){
            cout << " " << x;
        }
    }
    cout << endl;
}

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

    return 0;
}


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

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

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String s = in.nextString();
            int bCnt = 0;
            long ans = 0;
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) == 'B') {
                    bCnt++;
                } else {
                    ans += bCnt;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

    }
}



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

using namespace std;

using ll = long long int;

int main(){
  int n, w;
  cin >> n >> w;
  vector<int> ws(n);
  vector<int> vs(n);
  for(int i = 0; i < n; i++)
  {
    cin >> ws[i] >> vs[i];
  }
  vector<vector<ll>> dp(n, vector<ll>(w + 1, 0));
  for(int i = 0; i < n; i++)
  {
    for(int j = 0; j <= w; j++)
    {
      if(ws[i] <= j)
      {
        if(i == 0)
        {
          dp[i][j] = vs[i];
        }else{
          dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - ws[i]] + vs[i]);
        }
      }else{
        if(i == 0)
        {
          dp[i][j] = 0;
        }else{
          dp[i][j] = dp[i - 1][j];
        }
      }
    }
  }
  cout << dp[n - 1][w] << endl;
}


Measured memory_bytes: 79488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define printV(v) for(int i=0;i<v.size();i++){cout << v[i] << " ";} cout << endl
#define printRev(v) for(int i=v.size()-1;i >= 0;i--){cout << v[i] << " ";} cout << endl
#define sortV(v) sort(v.begin(),v.end())
ll a,b,c,d,e,f,g,n,m,k,t,p;

ll mod = 1000000007;


struct LCA {
    vector<int> height, euler, first, segtree;
    vector<bool> visited;
    int n;
 
    LCA(vector<vector<int>> &adj, int root = 0) {
        n = adj.size();
        height.resize(n);
        first.resize(n);
        euler.reserve(n * 2);
        visited.assign(n, false);
        dfs(adj, root);
        int m = euler.size();
        segtree.resize(m * 4);
        build(1, 0, m - 1);
    }
 
    void dfs(vector<vector<int>> &adj, int node, int h = 0) {
        visited[node] = true;
        height[node] = h;
        first[node] = euler.size();
        euler.push_back(node);
        for (auto to : adj[node]) {
            if (!visited[to]) {
                dfs(adj, to, h + 1);
                euler.push_back(node);
            }
        }
    }
 
    void build(int node, int b, int e) {
        if (b == e) {
            segtree[node] = euler[b];
        } else {
            int mid = (b + e) / 2;
            build(node << 1, b, mid);
            build(node << 1 | 1, mid + 1, e);
            int l = segtree[node << 1], r = segtree[node << 1 | 1];
            segtree[node] = (height[l] < height[r]) ? l : r;
        }
    }
 
    int query(int node, int b, int e, int L, int R) {
        if (b > R || e < L)
            return -1;
        if (b >= L && e <= R)
            return segtree[node];
        int mid = (b + e) >> 1;
 
        int left = query(node << 1, b, mid, L, R);
        int right = query(node << 1 | 1, mid + 1, e, L, R);
        if (left == -1) return right;
        if (right == -1) return left;
        return height[left] < height[right] ? left : right;
    }
 
    int lca(int u, int v) {
        int left = first[u], right = first[v];
        if (left > right)
            swap(left, right);
        return query(1, 0, euler.size() - 1, left, right);
    }
};
 
 






void solve(){
   cin >> a >> b;
   ll last = -1;
   int L = 1; int R = 1000;
   while(L <= R){
       ll mid = (L + R)/2;
       if( mid * 8 / 100 == a && mid/10 == b){
           if(last == -1){
               last = mid;
           }else{
               last = min(last,mid);
           }
           R = mid - 1;
       }else if(mid * 8 / 100 > a || mid/10 > b){
           R = mid -1;
       }else if(mid * 8 / 100 < a || mid/10 < b){
           L = mid + 1;
       }
   }
   cout << last;
}

int main(){
    ios_base::sync_with_stdio(false);
   
    int cases = 1; 
    //cin >> cases;

    while(cases--){
        solve();
    }
    return 0;

}

Measured memory_bytes: 256