akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define rep(i,n) for(int i=0;i<n;i++)

typedef complex<double> P;

int N;
double sx,sy,ex,ey,mx,my,Mx,My,h;

double dot(P a, P b) {
  return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b) {
  return (a.real() * b.imag() - a.imag() * b.real());
}

int insected(P a1, P a2, P b1, P b2) {
	if(fabs(cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1))<EPS){
	return dot(b1-a1,b1-a2)*dot(b2-a1,b2-a2)<EPS;
	}
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

double dist(P a, P b, P c) {
  if ( dot(b-a, c-a) < EPS ) return abs(c-a);
  if ( dot(a-b, c-b) < EPS ) return abs(c-b);
  return
	abs(cross(b-a, c-a)) / abs(b-a);
}

int main(){
	/*FILE *out1157;         // oÍXg[
  out1157 = fopen("out1157", "w");  // t@Cð«ÝpÉI[v(J­)
  if (out1157 == NULL) {          // I[vÉ¸sµ½ê
    printf("cannot open\n");         // G[bZ[WðoµÄ
    exit(1);                         // ÙíI¹
  }int cn=0;*/
	while(cin>>N&&N){
		//cn++;
		cin>>sx>>sy>>ex>>ey;//cout<<cn<<endl;if(cn==59)cout<<sx<<" "<<sy<<" "<<ex<<" "<<ey<<endl;
		P s(sx,sy),e(ex,ey);
		double ans=1e9;
		rep(i,N){
			cin>>mx>>my>>Mx>>My>>h;
			P a(mx,my),b(Mx,my),c(Mx,My),d(mx,My);
			if(mx<=min(sx,ex)&&Mx>=max(sx,ex)&&my<=min(sy,ey)&&My>=max(sy,ey)){ans=0;/*cout<<"tutumu ans=0"<<endl;*/}
			else if(insected(s,e,a,b)||insected(s,e,b,c)||insected(s,e,c,d)||insected(s,e,d,a)){ans=0;/*cout<<"majiwaru ans=0"<<" "<<insected(s,e,a,b)<<" "<<insected(s,e,b,c)<<" "<<insected(s,e,c,d)<<" "<<insected(s,e,d,a)<<endl;*/}
			else{
				double D=1e9;
				if(Mx<=min(sx,ex)){
					if(my<=sy&&sy<=My)D=min(D,sx-Mx);
					if(my<=ey&&ey<=My)D=min(D,ex-Mx);
				}
				if(mx>=max(sx,ex)){
					if(my<=sy&&sy<=My)D=min(D,mx-sx);
					if(my<=ey&&ey<=My)D=min(D,mx-ex);
				}
				if(My<=min(sy,ey)){
					if(mx<=sx&&sx<=Mx)D=min(D,sy-My);
					if(mx<=ex&&ex<=Mx)D=min(D,ey-My);
				}
				if(my>=max(sy,ey)){
					if(mx<=sx&&sx<=Mx)D=min(D,my-sy);
					if(mx<=ex&&ex<=Mx)D=min(D,my-ey);
				}
				D=min(D,min(dist(s,e,a),min(dist(s,e,b),min(dist(s,e,c),dist(s,e,d)))));
				if(h>D){ans=min(ans,D);/*cout<<D<<endl;*/}
				else {/*cout<<"MIN"<<ans<<" ";*/ans=min(ans,(D*D+h*h)/2/h);/*cout<<(D*D+h*h)/2/h<<endl;*/}
				//cout<<"ans"<<ans<<endl;
			}
		}
		printf("%.4f\n",ans);
	}
	//fclose(out1157);
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());

        int digits=1;
        int next=N/K;

        while(next != 0){
            next = next/K;
            digits = digits + 1;
        }
        System.out.println(digits);   

        
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,a,n) for(int i=a;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
#define vi vector<int>

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int x,y,z,k;
    cin>>x>>y>>z>>k;
    vi a(x),b(y),c(z);
    rep(i,0,x){cin>>a[i];}
    rep(i,0,y){cin>>b[i];}
    rep(i,0,z){cin>>c[i];}
    sort(lla(a));
    sort(lla(b));
    sort(lla(c));
    vi d;
    rep(i,0,x){
        rep(j,0,y){
            d.push_back(a[i]+b[j]);
        }
    }
    sort(lla(d));
    vi e;
    for(int i=0;i<min(k,(int)d.size());i++){
        rep(j,0,z){
            e.push_back(d[i]+c[j]);
        }
    }
    sort(lla(e));
    rep(i,0,k){
        cout<<e[i]<<'\n';
    }
}

Measured memory_bytes: 43240
m, d = map(int, input().split())
c = 0
for i in range(1, m+1):
    for j in range(1, d+1):
        d1 = j%10
        d10 = j//10
        if d1 > 1 and d10 > 1 and (d1 * d10 == i):
            c += 1
print(c)

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = ll(1e9) + 7;
const int INF = int(1e9);


int main() {
	cin.sync_with_stdio(false);
	bool f[250000] = {};
	reps(i, 2, 250000) {
		if (f[i] == 1)continue;
		reps(j, i + 1, 250000) {
			if (j%i == 0)f[j] = 1;
		}
	}
	int cnt = 0;
	while (1) {
		int Q;
		cin >> Q;
		if (Q == 0)return 0;
		int cnt1 = 0, cnt2 = 0;
		reps(i,2, Q * 2+1) {
			if (f[i] == 0) {
				if (i <= Q)cnt1++;
				cnt2++;
			}
		}
		cout << cnt2 - cnt1 << endl;
	}
	return 0;
}



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

int N, W;
map < int , int > memo[105];
int w[105], v[105];

int dfs(int node, int wei)
{
	if ( node == N ) {
		return ( 0 );
	}
	if ( memo[node].count(wei) > 0 ) {
		return ( memo[node][wei] );
	}
	memo[node][wei] = dfs(node + 1, wei);
	if ( wei + w[node] <= W ) {
		memo[node][wei] = max(memo[node][wei], dfs(node + 1, wei + w[node]) + v[node]);
	}

	return ( memo[node][wei] );
}

int main()
{
	cin >> N >> W;

	for ( int i = 0; i < N; i++ ) {
		cin >> w[i] >> v[i];
	}

	cout << dfs(0, 0) << endl;

	return ( 0 );
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
const int inf=1e5+5;
typedef long long ll;
double mx=-123456789;
ll n,m;
vector<double>v;
int main()
{
   cin>>n;
   int a[n+1];
   for(int i=1;i<=n;i++){
    cin>>a[i];
   }
   vector<int>gcd1(n+1,0);
   vector<int>gcd2(n+2,0);
   for(int i=1;i<=n;i++){
    gcd1[i]=__gcd(gcd1[i-1],a[i]);
   }
   for(int i=n;i>=1;i--){
    gcd2[i]=__gcd(gcd2[i+1],a[i]);
   }
   int mx=INT_MIN;
   for(int i=1;i<=n;i++){
        int k=__gcd(gcd1[i-1],gcd2[i+1]);
        mx=max(mx,k);
   }
   cout<<mx<<endl;
}


Measured memory_bytes: 1408
s = gets.chomp

lengths = []
s.length.times do |i|
    length = 0
    (i..s.length).each do |j|
        ok = true
        case s[j]
        when "A", "C", "T", "G"
            length += 1
        else
            break
            ok = false
        end
        break if !ok
    end
    lengths << length
end

puts lengths.max

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long int
#define inf 3e18+1
#define all(v) (v).begin(),(v).end() 
#define N 200005
#define F first 
#define S second 
using namespace std;
ll mod=1e9+7;
// ll parent[N];  
// ll size[N]; 
// ll find(ll i){
//     if(parent[i]!=i) {
//         parent[i]=find(parent[i]);
//     }
//     return parent[i];
// }
// void Union(ll x,ll y){
//     ll a=find(x);
//     ll b=find(y);
//     if(a==b) return;
//     parent[a]=parent[b];
// }
int main()
{
    // added the two lines below 
    ios_base::sync_with_stdio (false); 
    cin.tie(NULL);
    cout.tie(0);    
    ll test=1;//cin>>test;
    while(test--){
        string s,t;
        cin>>s>>t;
        ll n=s.size();
        ll m=t.size();
        ll dp[n+1][m+1];
        memset(dp,0,sizeof(dp));
        string ans;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=m;j++){
                if(s[i-1]==t[j-1]){
                    dp[i][j]=1+dp[i-1][j-1];
                }
                else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
        int i=n,j=m;
        while(i>0 and j>0){
            if(s[i-1]==t[j-1]){
                ans+=s[i-1];
                i--;
                j--;
            }
            else {
                if(dp[i-1][j]<dp[i][j-1]){
                    j--;
                }
                else i--;
            }
        }
        reverse(ans.begin(),ans.end());
        cout<<ans;


        
    }
    return 0;
    
}




Measured memory_bytes: 73992
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60

typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-9, pi = acos(-1.0);
namespace std {
    bool operator<(const Point &lhs, const Point &rhs) {
        if (lhs.real() < rhs.real() - eps) return true;
        if (lhs.real() > rhs.real() + eps) return false;
        return lhs.imag() < rhs.imag();
    }
}
Point input_point() {ld x, y; cin >> x >> y; return Point(x, y);} // ????????\???
bool eq(ld a, ld b) {return (abs(a - b) < eps);} // ????????????????????????
ld dot(Point a, Point b) {return real(conj(a) * b);} // ??????
ld cross(Point a, Point b) {return imag(conj(a) * b);} // ??????

// ??´????????????
class Line {
public:
    Point a, b;
    Line() : a(Point(0, 0)), b(Point(0, 0)) {}
    Line(Point a, Point b) : a(a), b(b) {}
    Point operator[](const int _num) {
        if (_num == 0)return a;
        else if (_num == 1)return b;
        else assert(false);
    }
};

// ????????????
class Circle {
public:
    Point p;
    ld r;
    Circle() : p(Point(0, 0)), r(0) {}
    Circle(Point p, ld r) : p(p), r(r) {}
};

/* ????§???¢ */
typedef vector<Point> Polygon;
// ??¢???
ld area(const Polygon &p) {
    ld res = 0;
    int n = (int)p.size();
    for (int j = 0;j < n;j++) res += cross(p[j], p[(j + 1) % n]);
    return res / 2;
}

int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    Polygon ps;
    for(int i = 0; i < n;i++) ps.emplace_back(input_point());
    cout << fixed << setprecision(1) << area(ps) << endl;
    return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  string p, q;
  for (int i = 0; i < n; i++) {
    string k;
    cin >> k;
    p += k;
  }
  for (int i = 0; i < n; i++) {
    string k;
    cin >> k;
    q += k;
  }
  vector<string> a(1000000);
  int cnt = 1;
  vector<int> v;
  for (int i = 1; i <= n; i++) v.push_back(i);
  do {
    cnt++;
    for (int i = 0; i < v.size(); i++) {
      a[cnt] += to_string(v[i]);
    }
  } while (next_permutation(v.begin(), v.end()));
  int ans1, ans2;
  for (int i = 1; i < 1000000; i++) {
    if (a[i] == p) ans1 = i;
    if (a[i] == q) ans2 = i;
  }
  cout << abs(ans1 - ans2) << endl;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
#define MAXN 100
int gr[MAXN+1];
int main(){
   FILE*fi,*fout;
   int i,n,m,x,y;
  // fi=fopen("A.in" ,"r");
  // fout=fopen("A.out" ,"w");
   fi=stdin;
   fout=stdout;
   fscanf(fi,"%d%d" ,&n,&m);
   for(i=1;i<=m;i++){
      fscanf(fi,"%d%d" ,&x,&y);
      gr[x]++;
      gr[y]++;
   }
   for(i=1;i<=n;i++)
      fprintf(fout,"%d\n" ,gr[i]);
   //fclose(fi);
   //fclose(fout);
   return 0;
}


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

int A,B,C,X,Y;

int main(){
    cin>>A>>B>>C>>X>>Y;
    if(2*C<A+B){
        if(X>Y){
            int ans1=2*C*Y+(X-Y)*A;
            int ans2=2*C*X;
            cout<<min(ans1,ans2)<<endl;
    
        }
        else{
            int ans1=2*C*X+(Y-X)*B;
            int ans2=2*C*Y;
            cout<<min(ans1,ans2)<<endl;
        }
    }
    else{
        cout<<X*A+Y*B<<endl;
    }
}

Measured memory_bytes: 256
import collections
N = int(input())
A = list(map(int,input().split()))
cnt = sorted(collections.Counter(A).items())
cnt_2 = [x for x in cnt if x[1] >= 2]
if len(cnt_2) == 0:
    print(0)
elif cnt_2[-1][1] >= 4:
    print((cnt_2[-1][0])**2)
else:
    if len(cnt_2) == 1:
        print(0)
    else:
        print(cnt_2[-1][0]*cnt_2[-2][0])

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

using namespace std;

void solve()
{
	vector<int> Vec1;
	vector<int> Vec2;
	int a, b;
	while(~scanf("%d,%d", &a,&b))
	{
		Vec1.push_back(a);
		Vec2.push_back(b);
	}
	int sum = 0;
	double Ave = 0;
	int n = Vec1.size();
	for(int i = 0; i < n; ++i)
	{
		sum += Vec1[i] * Vec2[i];
		Ave += Vec2[i];
	}
	cout << sum << endl;
	cout << (int)(Ave / n + 0.5) << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void)
{
    int cent;
    scanf("%d", &cent);

    int n = cent / 25;
    cent -= (cent / 25) * 25;
    n += cent / 10;
    cent -= (cent / 10) * 10;
    n += cent / 5;
    cent -= (cent / 5) * 5;
    n += cent;

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

    return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B;
  int sum=0;
  cin>>A>>B;
  int maxA=A/1000;
  int minA=A%100;
  int ABnosa=B/100-A/100;
  int kaibunA=(maxA%10)*10+maxA/10;
  int kaibunB=(B/1000%10)*10+(B/10000);
 if(ABnosa==0){
   for(int i=0;i<(B%1000-minA)/100;i++){
     if(i==0&&minA<maxA)sum++;
     sum++;
   }
 }else if(ABnosa > 0){
   sum+=ABnosa+1;
   if(minA>kaibunA)sum--;
   if(kaibunB>B%100)sum--;
 }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N;
string s[10010];

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

  cin >> N;
  REP(i,N) cin >> s[i];
  int ans = 0;
  REP(i,N) REP(j,s[i].size()-1) {
    if (s[i].substr(j,2) == "AB") ans++;
  }
  int a = 0, b = 0, c = 0;
  REP(i,N) {
    if (s[i][0] == 'B' && s[i].back() == 'A') c++;
    else if (s[i][0] == 'B') b++;
    else if (s[i].back() == 'A') a++;
  }
  if (c > 0) {
    ans += c-1;
    if (a > 0) ans++, a--;
    if (b > 0) ans++, b--;
  }
  ans += min(a,b);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;

int main() {
  int n,m,c;
  cin>>n>>m>>c;
  vector<int> B(m);
  rep(i,m) cin>>B[i];
  int ans=0;
  rep(i,n){
    int sum=c;
    rep(j,m){
      int a;
      cin>>a;
      sum+=a*B[j];
    }
    if(sum>0) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main(){
   string st;

   cin>>st;

   if(st.length()==2){
   	for (int i = 0; i < st.size(); ++i)
   	{
   		cout<<st[i];
   	}
   		cout<<endl;
   }else{
   	for (int i = st.size()-1; i >=0; --i)
   	{
   		cout<<st[i];
   	}
  		cout<<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 REP(i, n) for(int i = 1; i < n; i++)
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

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

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(c <= a+b) cout << "Yes" << endl;
  else cout << "No" << endl;
}






Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        int a,b,c,k;
        Scanner sc=new Scanner(System.in);
        a=sc.nextInt();
        b=sc.nextInt();
        c=sc.nextInt();
        k=sc.nextInt();
        int sum=0;
      //  int total=(a*1)+()
        for(int i=0;i<k;i++)
        {
            if(a!=0)
            {
                sum=sum+1;
                a--;
            }
            else if(b!=0)
            {
                sum+=0;
                b--;
            }
            else
            {
                sum=sum-1;
                c--;
            }
        }
        
        System.out.println(sum);
    }
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll k = b - a;
    ll ans = 0;
    if(a > b){
        cout << 0 << endl;
    }else if(a == b){
        cout << 1 << endl;
    }else{
        if(n == 1){
            cout << 0 << endl;
        }else{
            n -= 2;
            if(n == 0){
                cout << 1 << endl;
            }else{
                ans = k * n + 1;
                cout << ans << endl;
            }
            
        }
    }
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

D,G = map(int,input().split())
p,c = [],[]
res = 1<<30
for i in range(D):
    x,y = map(int,input().split())
    p.append(x)
    c.append(y)
for i in range(2**D):
    sum_x,cnt = 0,0
    for j in range(D):
        if i&(1<<j):
            sum_x+=c[j]+p[j]*100*(j+1)
            cnt+=p[j]
    if(sum_x<=G):
        for j in reversed(range(D)):
            if i&(1<<j): continue
            for k in range(p[j]):
                if sum_x>=G: break
                sum_x+=100*(j+1)
                cnt+=1
    if(res>cnt): res=cnt
print(res)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define REP(i, n) for(int i = 0; i < n; ++i)
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N, X, T; cin >> N >> X >> T;
	cout << ((N + X - 1) / X) * T << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <algorithm>
#include <utility>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pll pair<long long, long long>
#define ff first
#define ss second

using namespace std;

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

    int n, t; cin >> n >> t; --t;
    pii x[n]; for(int i = 0; i < n; ++i) cin >> x[i].ff >> x[i].ss;
    sort(x, x + n);
    int dp[t + 3001]{};
    for(int i = 0; i < n; ++i)
    {
        for(int j = t + 3000; j >= 0; --j)
        {
            if(j >= x[i].ff && j - x[i].ff <= t)
                dp[j] = max(dp[j], dp[j - x[i].ff] + x[i].ss);
        }
    }

    int ans = -1;
    for(auto i : dp) ans = max(ans, i);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int A, B, C;
  scanf("%d %d %d", &A, &B, &C);

  int K;
  scanf("%d", &K);

  int t=0;
  while( A >= B){
    B *= 2;
    t++;
  }
  while( B >= C){
    C *= 2;
    t++;
  }

  if(t <= K) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 1660
using System;

namespace _0124
{
    class Program
    {
        static void Main(string[] args)
        {
            bool flag = false;
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0) break;
                if (flag) Console.WriteLine();
                flag = true;
                string[] country = new string[n];
                int[] point = new int[n];
                for (int i = 0; i < n; i++)
                {
                    string[] s = Console.ReadLine().Split();
                    country[i] = s[0];
                    point[i] = 3 * int.Parse(s[1]) + int.Parse(s[3]);
                }
                for (int i = 300; i >= 0; i--)
                {
                    for (int j = 0; j < n; j++)
                    {
                        if (point[j] == i)
                        {
                            Console.WriteLine(country[j] + "," + point[j]);
                        }
                    }
                }
            }
        }
    }
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

ll n,a,b,c,d;

int main(){
  cin>>n>>a>>b>>c>>d;
  if(a>b)swap(a,b);
  ll aaa = b-a;
  --n;
  REP(x,n+1){
    ll y = n-x;
    ll low = c*x-d*y;
    ll high = d*x-c*y;
    if(low<=aaa && aaa<=high){
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 256
p = int(input())
aaa = list(map(int, input().split()))

coefs = [0] * p
coefs[0] = sum(aaa)
invs = [pow(x, p - 2, p) for x in range(p + 1)]
for i, a in enumerate(aaa):
    if a == 0:
        continue

    b = 1
    c = 1
    for j in range(p - 1, -1, -1):
        coefs[j] = (coefs[j] - b * c) % p
        b = -b * i % p
        c = c * j * invs[p - j] % p

print(*coefs)


Measured memory_bytes: 44124
#include<stdio.h>
int main()
{
	int A,B,C;
	char op;
	scanf("%d %c %d",&A,&op,&B);
	if(op=='+')
	C=A+B;
	if(op=='-')
	C=A-B;
	printf("%d",C);
	return 0;	
} 

Measured memory_bytes: 128
#include <stdio.h>

int main () {
	int a, b;
	scanf ("%d %d", &a, &b);
	
	int x[a], y[b];
	x[0] = 2, y[0] = 1;
	
	int max = 0;
	if (a > b) {
		max = a;
	} else max = b;
	
	if (a > 1) {
		for (int i = 1; i < a; i++) {
			x[i] = x[i-1] + 2;
		}
	}
	
	if (b > 1) {
		for (int i = 1; i < b; i++) {
			y[i] = y[i-1] + 2;
		}
	}
	
	int sum[max*max];
	int k = 0, fin = 0;
	if (a > 1) {
		for (int i = 0; i < a; i++) { //even
			for (int j = i+1; j < a; j++) {
				sum[k] = x[i] + x[j];
				if (sum[k] % 2 == 0) {
					fin++;
				}
				k++;
			}		
		}
	}
	
	if (b > 1) {
		for (int i = 0; i < b; i++) { //odd
			for (int j = i+1; j < b; j++) {
				sum[k] = y[i] + y[j];
				if (sum[k] % 2 == 0) {
					fin++;
				}
				k++;
			}		
		}
	}
		
	
	printf ("%d\n", fin);
}

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

#define fastIO ios_base::sync_with_stdio(0); cin.tie(0);
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define forn(i, a, b) for (int i = (a); i < (b); i++)
#define ford(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define szof(x) ((int)(x).size())
#define rsz resize
#define lb lower_bound
#define ub upper_bound
#define INF (int)1e9
#define INFL (long long)1e18
#define re return
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector <int> >
#define VVLL vector<vector <long long> >
#define VLL vector <long long>
#define mt make_tuple

using namespace std;

int n,a,b;
vector <int> h;
int delta;

bool f(int m) {
    vector <ll> c;
    ll otn = m*1ll*b;
    for (auto elem : h) {
        if (elem - otn > 0) {
            c.pb(elem - otn);
        }
    }
    ll cur = 0;
    for (auto elem : c) {
        cur += ceil(1.00*elem/delta);
      //  cout << elem << " " << delta << '\n';
    }
   // cout << m << " " << cur << '\n';
    return cur <= m;
}

int main() {
    fastIO;
    cin >> n >> a >> b;
    h.rsz(n);
    for (auto & x : h) {
        cin >> x;
    }
    delta = a-b;
    ll l = -1;
    ll r = 1e9+1;
    while(r-l > 1) {
        int m = (l+r)/2;
        if (f(m)) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r << "\n";
	return 0;
}


Measured memory_bytes: 2528
// warm heart, wagging tail,and a smile just for you!
//                                                                     ███████████
//                                                                   ███╬╬╬╬╬╬╬╬╬╬███
//                                                                ███╬╬╬╬╬████╬╬╬╬╬╬███
//                                            ███████████       ██╬╬╬╬╬████╬╬████╬╬╬╬╬██
//                                      █████████╬╬╬╬╬████████████╬╬╬╬╬██╬╬╬╬╬╬███╬╬╬╬╬██
//                               ████████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬██╬╬╬╬╬╬╬██
//                             ████╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████████╬╬╬╬╬╬╬╬╬╬╬██
//                           ███╬╬╬█╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬███╬╬╬╬╬╬╬█████
//                         ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬████████╬╬╬╬╬██
//                       ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬╬╬╬╬███
//                     ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬██
//                 ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬████
//     █████████████╬╬╬╬╬╬╬╬██╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬██████
//   ████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬██████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████╬╬╬╬╬╬╬███████████╬╬╬╬╬╬╬╬██╬╬╬██╬╬╬██
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████╬╬╬╬╬╬╬╬╬╬╬█╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬██
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬▓▓▓▓▓▓╬╬╬████╬╬████╬╬╬╬╬╬╬▓▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬███
// ██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██████▓▓▓▓▓▓▓╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬▓▓▓▓▓▓▓██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██╬╬╬╬█████
// ███╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████████
//   ███╬╬╬╬╬╬╬╬╬╬╬╬╬█████╬╬╬╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬███╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬██
//       ██████████████  ████╬╬╬╬╬╬███████████████████████████╬╬╬╬╬██╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬╬████
//                         ███████                           █████  ███████████████████  
//
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF (1LL<<60)
#define fs first
#define sc second
#define int long long
#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(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
#define MSB(x) (63-__builtin_clzll(x))
#define pcnt(x) (__builtin_popcountll(x))
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

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

  int n;
  string s;
  cin >> n >> s;

  REP(i,s.size()){
    int num = s[i]-'A';
    num = (num+n)%26;
    s[i] = num+'A';
  }

  cout << s << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
//using Graph = vector<vector<Edge>>;
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;
const double PI = acos(-1.0);

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1}, dy[8] = {-1, 0, 1, 1, -1, 1, 0, -1};

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, W;
  cin >> N >> W;
  vector<ll> v(N), w(N);
  for (int i = 0; i < N; i++)
  {
    cin >> v[i] >> w[i];
  }
  static ll dp[10010][10010];
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j <= W; j++)
    {
      if (j < w[i])
        dp[i + 1][j] = dp[i][j];
      else
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
    }
  }
  cout << dp[N][W] << endl;
  return 0;
}



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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template <typename T1, typename T2> 
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

struct Sum{
  ll u = 0;
  ll d = 0;
  ll l = 0;
  ll r = 0;
};

ll calc(Sum p) { return p.u + p.d + p.l + p.r; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, w;
  cin >> h >> w;
  string board[h];
  rep(i, h) { cin >> board[i]; }

  struct Sum point[h][w];

  // l -> r
  rep(i,h){
    ll cnt = 0;
    rep(j, w) {
      point[i][j].l = cnt;
      if(board[i][j] == '.') {
        cnt++;
      }else{
        cnt = 0;
      }
    }
  }

  // r -> l
  rep(i, h) {
    ll cnt = 0;
    for(int j = w - 1; j >= 0; j--) {
      point[i][j].r = cnt;
      if(board[i][j] == '.') {
        cnt++;
      } else {
        cnt = 0;
      }
    }
  }

  // u -> d
  rep(j, w) {
    ll cnt = 0;
    rep(i, h) {
      point[i][j].u = cnt;
      if(board[i][j] == '.') {
        cnt++;
      } else {
        cnt = 0;
      }
    }
  }

  // d -> u
  rep(j, w) {
    ll cnt = 0;
    for(int i = h - 1; i >= 0; i--) {
      point[i][j].d = cnt;
      if(board[i][j] == '.') {
        cnt++;
      } else {
        cnt = 0;
      }
    }
  }

  ll ans = 0;
  rep(i, h)rep(j, w) {
    if(board[i][j] == '#') continue;
    chmax(ans, calc(point[i][j]) + 1);
  }

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


Measured memory_bytes: 132704
#include <stdio.h>

#define MAX 2000

int solve(int,int,int *,int);

int main() {
  int n,q;
  int A[MAX],m[MAX];
  int i;

  scanf("%d", &n);
  for ( i = 0; i < n; i++) {
    /* code */
    scanf("%d", &A[i]);
  }
    scanf("%d", &q);
  for ( i = 0; i < q; i++) {
    /* code */
    scanf("%d", &m[i]);
  }
  for (i = 0; i < q; i++) {
    /* code */
    if(solve(0,m[i],A,n)){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }



  return 0;
}

int solve(int i,int m,int *A,int n){
  int res=0;

  if (m==0) {
    /* code */
    return 1;
  }else if(i>=n){
    /* code */
    return 0;

  }else if(solve(i+1,m,A,n) || solve(i+1,m-A[i],A,n)){

    return 1;

  }else {

    return 0;
  }

}



Measured memory_bytes: 2108
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long x = n * k;
  map<int, vector<int>> mp;
  for (int i = 0; i < n; i++) {
    mp[a[i]].push_back(i);
  }
  vector<long long> vf(n);
  for (auto& m : mp) {
    auto& v = m.second;
    v.push_back(v[0] + n);
    for (int i = 0; i + 1 < (int) v.size(); i++) {
      vf[v[i]] = v[i + 1] - v[i] + 1;
    }
  }
  const long long INF = 1LL << 60;
  vector<vector<long long>> table = {vf};
  for (int u = 1; u <= 60; u++) {
    vector<long long>& cur = table.back();
    vector<long long> nxt(n);
    for (int i = 0; i < n; i++) {
      nxt[i] = min(INF, cur[i] + cur[(i + (cur[i])) % n]);
    }
    table.push_back(nxt);
  }
  long long cur = 0;
  for (int i = (int) table.size() - 1; i >= 0; i--) {
    if (cur + table[i][cur % n] <= x) {
      cur += table[i][cur % n];
    }
  }
  if (cur == k) {
    return 0;
  }
  vector<int> ans;
  set<int> st;
  for (int i = cur % n; i < n; i++) {
    if (st.count(a[i])) {
      while (true) {
        int t = ans.back();
        ans.pop_back();
        st.erase(t);
        if (t == a[i]) break;
      }
    } else {
      ans.push_back(a[i]);
      st.insert(a[i]);
    }
  }
  for (int i = 0; i < (int) ans.size(); i++) {
    if (i > 0) cout << " ";
    cout << ans[i];
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 131172
n,q = map(int,input().split())
s = list(input())
cum = [0 for i in range(n+1)]
i = 0
while i < n:
    if i < n-1 and s[i] == "A" and s[i+1] == "C":
        cum[i+1] = cum[i]
        cum[i+2] = 1+cum[i+1]
        i += 2
    else:
        cum[i+1] = cum[i]
        i += 1

for i in range(q):
    l,r = map(int,input().split())
    print(cum[r]-cum[l])

Measured memory_bytes: 6800
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int x,a,b; cin>>x>>a>>b;
  if(b-a<=0)
  puts("delicious");
  else if(b-a<=x)
  puts("safe");
  else
  puts("dangerous");

  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>
#include<list>
#include<cstdio>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)


using namespace std;

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




const int INF = 1e9 + 7;


/******************************************************************************************/



vector<int> G[105];
int dist[105];


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n;
	cin >> n;

	for (int i = 0; i < 105; i++)
	{
		dist[i] = INF;
	}

	for (int i = 0; i < n; i++)
	{
		int node, out;
		cin >> node >> out;
		for (int j = 0; j < out; j++)
		{
			int c;
			cin >> c;
			G[node].push_back(c);
		}
	}


	queue<int> que;

	que.push(1);
	dist[1] = 0;

	while (!que.empty()) {

		int now = que.front();
		que.pop();

		if (dist[now] == INF)continue;
		for (int nxt : G[now]) {

			if (dist[nxt] > dist[now] + 1) {
				dist[nxt] = dist[now] + 1;
				que.push(nxt);
			}
		}
	}

	for (int i = 1; i <= n; i++)
	{
		if (dist[i] == INF) {
			cout << i << " " << -1 << endl;
		}
		else
		{
			cout << i << " " << dist[i] << endl;
		}
	}
	
	return 0;
}



Measured memory_bytes: 3220
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
 
#define fr first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define forn(i, n) for (int i = 0; i < n; ++i)
#define forln(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = 3.14159265358979323846264;
const ld eps = 1e-8;
const ll mod = 998244353;
const ll ns = 97;
const int maxc = 3000 + 20;

random_device rd;
mt19937 SuperRandom(rd());

int dp[maxc][maxc];

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n, s;
	cin >> n >> s;
	vector<int> goo (n);
	cinv (goo);
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		int x = goo[i - 1];
		dp[i][x] = i;
		for (int j = 0; j <= s; ++j) {
			dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
			if (j - x >= 0) {
				dp[i][j] = (dp[i][j] + dp[i - 1][j - x]) % mod;
			}
		}
		ans = (ans + dp[i][s]) % mod;
	}
	cout << ans;









}

Measured memory_bytes: 71040
#include <stdio.h>              //including stdio.h for printf and other functions


int main()                        //default function for call
{
	int a[50],n,i,j;
  scanf("%d",&n);

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

	for (int i = 0; i < n; i++)                     //Loop for ascending ordering
	{
		for (int j = 0; j < n; j++)             //Loop for comparing other values
		{
			if (a[j] > a[i])                //Comparing other array elements
			{
				int tmp = a[i];         //Using temporary variable for storing last value
				a[i] = a[j];            //replacing value
				a[j] = tmp;             //storing last value
			}
		}
	}

  float sum = a[0];                //Printing message
	for (int i = 0; i < n-1; i++)                     //Loop for printing array data after sorting
	{
		sum=(sum + a[i+1])/2;
	}

  printf("%f",sum);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		if (B % A == 0) {
			System.out.println(A+B);
		} else {
			System.out.println(B - A);
		}



	}
}

Measured memory_bytes: 21588
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;

const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {-1, 0, 1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};
void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}

ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 3e3 + 5;
const double PI = acos(-1.0);
const ll mod = 1000000007;
/*************************************************************************/

ll n,a,b;
void solve() {
    cin>>a>>b;
    REPP(i,1,1000000) {
        
        if(i*0.08 < a+1 && i*0.1 < b+1 && i*0.08 >= a && i*0.1 >= b ) {
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int main()
{

  solve();
  return 0;
}





Measured memory_bytes: 256
import java.util.Arrays;

public class Main {

  private static void solve() {
    int n = ni();
    int[] a = na(n);
    Arrays.sort(a);
    
    
    int[] score = new int[3];
    for (int i = n - 1, p = 0; i >= 0; i --, p ++) {
      score[p % 2] += a[i];
    }
    
    System.out.println(score[0] - score[1]);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = System.getProperty("debug");
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

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

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 23252
/**
 *    author:  FromDihPout
 *    created: 2020-06-24
**/

#include <bits/stdc++.h>
using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    
    int remaining = n;
    int left = 0, right = n - 1;
    while (right - left > 1) {
        if (a[left + 1] != a[left]) {
            left++;
        }
        else if (a[right - 1] != a[right]) {
            right--;
        }
        else {
            left++;
            right--;
            remaining -= 2;
        }
    }
    
    if (a[left] == a[right] && left != right) {
        remaining -= 2;
    }
    cout << remaining << endl;
    return 0;
}

Measured memory_bytes: 3700
import java.util.Scanner;

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


Measured memory_bytes: 23124