akhauriyash/Code-Regression huggingface dataset:
import sys
from itertools import accumulate
from bisect import bisect_right

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, K, *AB = map(int, read().split())
    A = AB[:N]
    B = AB[N:]

    time_A = [0]
    time_A.extend(accumulate(A))

    time_B = [0]
    time_B.extend(accumulate(B))

    ans = 0
    j = M
    for i, ta in enumerate(time_A):
        while j > 0 and ta + time_B[j] > K:
            j -= 1

        if ta + time_B[j] > K:
            break

        if ans < i + j:
            ans = i + j

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 149896
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
//#define int long long

using namespace std;

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

#define dump(x)  cout << #x << " = " << (x) << endl
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

typedef long long ll;

const ll MOD = 1e9 + 7;

class DTwoSequences {
public:
    void solve(std::istream& in, std::ostream& out) {
        ll N;
        in >> N;
        vector<ll> a(N), b(N);
        REP(i,0,N) in >> a[i];
        REP(i,0,N) in >> b[i];

        ll answer = 0;
        RREP(i,0,29) {
            const ll T = 1LL << i;
            REP(j,0,N) b[j] = b[j] % (2 * T);
            sort(all(b));
            ll cnt = 0;
            REP(j,0,N) { // fix a = a[j]
                const ll modA = a[j] % (2 * T);
                // [T, 2T)
                cnt += distance(lower_bound(all(b), T-modA), lower_bound(all(b), 2*T-modA));
                // [3T, 4T)
                cnt += distance(lower_bound(all(b), 3*T-modA), lower_bound(all(b), 4*T-modA));
            }
            if (cnt % 2 == 1) {
                answer += T;
            }
        }
        out << answer << "\n";
    }
};


signed main() {
    DTwoSequences solver;
    std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3328
import math
from fractions import gcd

def factorization(n):
    arr = []
    tmp = n
    for div in range(2, int(math.sqrt(n)) + 2):
        if tmp % div == 0:
            cnt = 0
            while tmp % div == 0:
                cnt += 1
                tmp //= div
            arr.append([div, cnt])

    if tmp != 1:
        arr.append([tmp, 1])

    if len(arr) == 0:
        arr.append([n, 1])

    return arr

if __name__ == '__main__':
    A, B = map(int, input().split())
    g = gcd(A, B)
    if g == 1:
        print(1)
        exit()
    facts = factorization(g)
    print(len(facts) + 1)

Measured memory_bytes: 5304
a = int(input())
d = e = 0
for i in range(a):
    b, c = map(int, input().split())
    if i == 0:
        d = b
        e = c
    else:
        if d <= b and e <= c:
            d = b
            e = c
        else:
            h = max((b + d - 1) // b, (c + e - 1) // c)
            d = b * h
            e = c * h
print(d + e)


Measured memory_bytes: 3064
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion

void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    ll N;
    cin >> N;
    vec<ll> A(N);
    vec<ll> tmp(N);
    REP(i, N){
        cin >> A[i];
        int cnt = 0;
        while(A[i]%(2ll<<cnt)==0){
            cnt++;
        }
        tmp[i] = cnt;
    }
    cout << *min_element(ALL(tmp)) << el;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

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

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

int main(){

  string s;cin>>s;

  int a,b,c,d;
  a = s[0]-'0';
  b = s[1]-'0';
  c = s[2]-'0';
  d = s[3]-'0';

  bool left,right;
  left = false;
  right = false;
  if(a==1){
    if(b==0||b==1||b==2){
      left = true;
    }
  }else if(a==0&&b!=0){
    left = true;
  }

  if(c==1){
    if(d==0||d==1||d==2){
      right = true;
    }
  }else if(c==0&&d!=0){
    right = true;
  }

  if(left){
    if(right){
      cout<<"AMBIGUOUS"<<endl;
    }else{
      cout<<"MMYY"<<endl;
    }
  }else{
    if(right){
      cout<<"YYMM"<<endl;
    }else{
      cout<<"NA"<<endl;
    }
  }



 

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

const int MOD = 1e9 + 7;
const int INFi = 2e9 + 1;
const lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
const char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


template <class T> void printVector(vector<T> &A){
  int k = A.size() - 1;
  REP(i, k) cout << A.at(i) << ' ';
  cout << A.at(k) << BR;
}


int main(void){
  int n; cin >> n;
  Vlli A(n), B(n);
  const lli Bigger = n + 1;
  lli value = 1;
  REP(i, n){
    A.at(i) = value;
    B.at(n - 1 - i) = value;
    value += Bigger;
  }
  REP(i, n){
    int u; cin >> u;u--;
    A.at(u) += i;
  }
  printVector(A);
  printVector(B);
  return 0;
}

Measured memory_bytes: 896
namespace Coder {
  class Scanner {
    private buffer: string = '';
    private stdinQueue: any = [];

    constructor() {
      process.stdin.resume();
      process.stdin.setEncoding('utf8');
      process.stdin.on(
        'data',
        (chunk): void => {
          this.buffer += chunk;
          while (this.stdinQueue.length > 0) {
            const i = this.buffer.indexOf('\n');
            if (i < 0) {
              break;
            }
            let line = this.buffer.substr(0, i);
            if (line.endsWith('\r')) {
              line = line.slice(0, -1);
            }
            this.buffer = this.buffer.substr(i + 1);
            this.stdinQueue.shift()(line);
          }
        },
      );
    }
    public getLine(): Promise<string> {
      return new Promise((resolve, reject) => {
        const i = this.buffer.indexOf('\n');
        if (i >= 0 && this.stdinQueue.length == 0) {
          let line = this.buffer.substr(0, i);
          if (line.endsWith('\r')) {
            line = line.slice(0, -1);
          }
          this.buffer = this.buffer.substr(i + 1);
          resolve(line);
        } else {
          this.stdinQueue.push(resolve);
        }
      });
    }

    public close(): void {
      process.stdin.pause();
    }
  }
  const f: (n: number) => number = (n: number) => {
    return n % 2 === 0 ? n / 2 : 3 * n + 1;
  };

  async function slove() {
    const sc = new Scanner();
    const s: number = +(await sc.getLine());
    const prog: number[] = [];
    let ans = -1;
    prog.push(s);
    let a = s;
    for (let i = 1; i <= 1000000; i++) {
      let b: number = f(a);
      if (prog.filter((x) => b === x).length > 0) {
        ans = i + 1;
        break;
      }
      prog.push(b);
      a = b;
    }
    console.log(ans);
    sc.close();
  }
  slove();
}


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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define PB push_back
#define MP make_pair
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

int N;
set<int> s;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N;
	vector<int> A(N);
	FOR(i,0,N){
		cin >> A [i];
		if(i % 2 == 0){
			s.insert(A [i]);
		}
	}
	sort(ALL(A));

	int ans = 0;
	FOR(i,0,N){
		if(i % 2 == 0 && s.count(A [i]) == 0){
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
double dp[301][301][301];
int n;
double solve(int x,int y,int z){
    if(x==0 && y==0 && z==0){
        return 0;
    }
    if(x<0 || y<0 || z<0){
        return 0;
    }
    if(dp[x][y][z]>-1){
        return dp[x][y][z];
    }
    double tmp=n+x*solve(x-1,y,z)+y*solve(x+1,y-1,z)+z*solve(x,y+1,z-1);
    return dp[x][y][z]=tmp/(x+y+z);
}

int main() {
    
    cin>>n;
    int one=0,two=0,three=0;
    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        if(tmp==1){
            one++;
        }
        else if(tmp==2){
            two++;
        }
        else{
            three++;
        }
    }
    memset(dp,-1,sizeof dp);
    cout<<fixed<<setprecision(10)<<solve(one,two,three)<<endl;
	return 0;
}

Measured memory_bytes: 216848
#include<stdio.h>
int main()
{
	int n,i,j;
	double d;
	int a[6] = {0};
	scanf("%d",&n);
	while(n--)
	{
		scanf("%lf",&d);
		if(d<165) a[0]++;
		else if(d>=185) a[5]++;
		else
			a[ ((int)d-165)/5 +1] ++;
	}
	for(i=0;i<6;++i)
	{
		printf("%d:",i+1);
		for(j=0;j<a[i];++j)putchar('*');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  v(string) d = v(string){"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int ans = 0;
  rep(i,7) {
    if(d[i] == s) {
      ans = 7-i;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* Coached by Dukkha */
#include <stdio.h>
#include <stdlib.h>

#define N 100

int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int xx[N], yy[N], hh[N];
	int n, i, cx, cy;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &xx[i], &yy[i], &hh[i]);
	for (cx = 0; cx <= 100; cx++)
		for (cy = 0; cy <= 100; cy++) {
			int h, yes;

			for (i = 0; i < n; i++)
				if (hh[i])
					break;
			h = hh[i] + abs(xx[i] - cx) + abs(yy[i] - cy);
			yes = 1;
			for (i = 0; i < n; i++)
				if (max(h - abs(xx[i] - cx) - abs(yy[i] - cy), 0) != hh[i]) {
					yes = 0;
					break;
				}
			if (yes) {
				printf("%d %d %d\n", cx, cy, h);
				return 0;
			}
		}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,v,p;
    cin>>n>>m>>v>>p;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);reverse(a,a+n);
    ll le=p-1,ri=n,mid,sum,nes,num;
    while(ri-le>1LL){
    	mid=(ri+le)/2; num=a[mid]+m; nes=v-(n-mid); sum=0;
    	nes=max(0LL,nes-p+1);
    	for(int i=p-1;i<mid;i++)sum+=min(m,max(0LL,num-a[i]));
    	if(nes*m<=sum&&a[p-1]<=num)le=mid;
    	else ri=mid;
    }
    cout << le+1<<endl;
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++)
    {
        d[i] = 0;
        cin >> d[i];
    }
    
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        for (int j = i + 1; j < N; j++){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
    
  return 0;
}


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

using namespace std;

int main() {
    int x, y;
    cin >> x >> y;
    for (int i = 0; i <= x; i++)
        if ((i * 2 + (x - i) * 4) == y) {
            cout << "Yes";
            return 0;
        }
    cout << "No";
}


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

using namespace std;

int main()
{
    long long int Q,H,S,D,N;cin >> Q >> H >> S >> D>>N;
    long long int most = 0;
    long long int most_ = 0;
    most = min({Q*8,H*4,S*2,D});
    most_ = min({Q*4,H*2,S});
    long long int ans = 0;
    ans += (N/2)*most;
    N %= 2;
    ans += (N/1)*most_;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define sz 100100

ll dp[sz][2];

inline ll mul(ll a, ll b)
{
	a = ((a % MOD) + MOD) % MOD;
	b = ((b % MOD) + MOD) % MOD;
	return (a * b) % MOD;
}

inline ll add(ll a, ll b)
{
	a = ((a % MOD) + MOD) % MOD;
	b = ((b % MOD) + MOD) % MOD;
	return (a + b) % MOD;
}

vector<int>adj[sz];

ll dfs(int rt, bool st, int par)
{

	if (adj[rt].size() == 1 && adj[rt][0] == par)
	{
		if (st)
			return 2;
		return 1;
	}

	ll &ans = dp[rt][st];
	if (ans != -1)
		return ans;

	ans = 1;

	for (auto it : adj[rt])
	{
		if (it == par)
			continue;
		ans = mul(ans, dfs(it, 1, rt));
	}

	if (st)
	{
		ll ans2 = 1;
		for (auto it : adj[rt])
		{
			if (it == par)
				continue;
			ans2 = mul(ans2, dfs(it, 0, rt));
		}
		ans = add(ans, ans2);
	}

	return ans;

}

int main()
{

	memset(dp, -1, sizeof(dp));

	int n, a, b;
	scanf("%d", &n);

	for (int i = 0; i < n - 1; ++i)
	{
		scanf("%d", &a); scanf("%d", &b);
		adj[a].push_back(b);
		adj[b].push_back(a);
	}


	cout << dfs(1, 1, -1);



	return 0;
}

Measured memory_bytes: 15616
typedef struct{double x,y,k;}w;w p[101],b;m,v[100],n,j;z(w*c,w*d){return c->k>d->k?-1:c->k<d->k;}double o(q,r,s){return p[q].x*(p[r].y-p[s].y)+p[r].x*(p[s].y-p[q].y)+p[s].x*(p[q].y-p[r].y);}main(i){double k,t;for(;j=scanf("%d",&n)+~n;){for(m=i=0;i<n;i++)scanf("%lf,%lf",&p[i].x,&p[i].y),p[m].y>p[i].y?m=i:0;b=p[m];p[m]=*p;*p=b;p[100].x=b.x;p[100].y=b.y+1;for(i=1;i<n;i++){k=o(0,i,100);t=(p[i].x-b.x)*(p[i].x-b.x)+(p[i].y-b.y)*(p[i].y-b.y);k*=k/t;if(b.x>p[i].x)k=-k;p[i].k=k;}qsort(p+1,n-1,sizeof(w),z);v[0]=0;v[1]=1;v[2]=j=2;for(i=3;i<n;i++){for(;o(v[j-1],v[j],i)<=0;j--);v[++j]=i;}printf("%d\n",n+~j);}}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;

class Solution
{
    static double Median(long[] x)
    {
        x = x.OrderBy(xx => xx).ToArray();
        var n = x.Length;
        if (n % 2 == 0)
        {
            return (x[n / 2 - 1] + x[n / 2]) / 2;
        }
        else
        {
            return x[n / 2];
        }
    }

    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        a = a.Select((aa, i) => aa - (i + 1)).ToArray();
        var b = (int)Median(a);
        var min = long.MaxValue;
        for (int i = -1; i <= 1; i++)
        {
            var sad = a.Sum(aa => Math.Abs(aa - (b + i)));
            min = Math.Min(min, sad);
        }
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 42756
/*
    to amy
    https://atcoder.jp/contests/abc133/tasks/abc133_d
*/

#include <bits/stdc++.h>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0);
#define pb push_back
#define F first
#define S second
#define MAX 100003

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



int main() {
    IOS
    int n,a;
    while(cin>>n){
        int v[MAX];
        for(int i=1;i<=n;i++){
            cin>>v[i];
        }
        ll x1=0LL, t;
        for(int i=n;i>=0;i--){
            x1 += (1LL* v[i] * ((i%2==0)?-1:1));
        }
        x1 /= 2LL;
        t = v[1] - x1;
        cout<<x1*2LL<<" ";
        for(int i=2;i<=n;i++){
            cout<<2LL * t<<" ";
            t = v[i] - t;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
#define RRep(i, k, n) for (int i = k; i > (int)(n); i--)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define ALL(a)  (a).begin(),(a).end()
#define rALL(a)  (a).rbegin(),(a).rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> void PrintVector(const vector<T> &vec) {for (auto val : vec) cout << val << " "; cout << endl;}
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const double PI = acos(-1); //3.14~
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll n, ans;

void dfs(ll i, int use, ll &ans)
{
    if (i > n) return ;
    if (use == 0b111) ans++;

    dfs(i * 10 + 7, use | 0b001, ans);
    dfs(i * 10 + 5, use | 0b010, ans);
    dfs(i * 10 + 3, use | 0b100, ans);
}

int main()
{
    cin >> n;
    //ll ans = 0;
    dfs(0, 0, ans);
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * Main
 */
public class Main {

  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    List<String> w = new ArrayList<>(Arrays.asList("Sunny", "Cloudy", "Rainy"));
    String s = scan.next();
    int index = (w.indexOf(s) + 1) % 3;
    System.out.println(w.get(index));
    scan.close();
  }
}


Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int sum = 0;
    int k = 1;
    while(sum < n)
    {
        sum += k;
        k++;
    }
    int x = sum - n;
    for(int i = 1;i < k;i++)
    {
        if(i != x)
        {
            cout << i << "\n";
        }
    }

    return 0;
}

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

#define ln                '\n'
#define all(dat)           dat.begin(), dat.end()
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fm, to)    for (int i = fm; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

const int nsz = 2e5;
int n;
num d, a, ans;
pair<num, num> dat[nsz + 5];
vector<num> p;

struct binary_index_tree {
	num tr[nsz + 5];
	
	void inline upd(int u, num w) {
		for (; u; tr[u] += w, u -= u & -u);
	}
	
	void inline upd(int l, int r, num w) {
		upd(r, +w);
		upd(l - 1, -w);
	}
	
	num inline qry(int u) {
		num res = 0;
		for (; u <= n; res += tr[u], u += u & -u);
		return res;
	}
};

binary_index_tree tr;

int main() {
	scanf("%d%d%d", &n, &d, &a);
	d = d + d + 1;
	cont (i, n) {
		scanf("%d%d", &dat[i].first, &dat[i].second);
	}
	sort(dat + 1, dat + n + 1);
	cont (i, n) {
		p.push_back(dat[i].first);
	}
	cont (i, n) {
		int to = lower_bound(all(p), dat[i].first + d) - p.begin();
		num del = tr.qry(i), h = dat[i].second + del, cnt = h <= 0 ? 0 : (h - 1) / a + 1;
		ans += cnt;
		tr.upd(i, to, -cnt * a);
	}
	printf("%lld\n", ans);
}

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

using namespace std;


int main()
{
  int N, S, A[100000];

  scanf("%d %d", &N, &S);
  for(int i = 0; i < N; i++) scanf("%d", &A[i]);

  int tail = 0, sum = 0, ret = 114514;
  for(int i = 0; i < N; i++) {
    while(tail < N && sum < S) {
      sum += A[tail++];
    }
    if(sum >= S) ret = min(ret, tail - i);
    sum -= A[i];
  }

  if(ret == 114514) ret = 0;
  printf("%d\n", ret);
}

Measured memory_bytes: 3536
#include <algorithm>
#include <cstdio>

const int N = 100050;

int n, A[N];

int main() {
  int maxv = 0;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &A[i]);
    maxv = std::max(maxv, A[i]);
  }
  int t = -1;
  for (int i = 0; i < n; ++i)
    if (A[i] != maxv && std::min(A[i], maxv - A[i]) > std::min(t, maxv - t))
      t = A[i];
  printf("%d %d\n", maxv, t);
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int MAX = 100005;
struct Node {
    int parent, left, right;
};
Node T[MAX];
int D[MAX];
void getDepth(int, int);
void printChild(int);
int main() {
    int t, id, k, temp, temp_1, head;
    scanf("%d", &t);
    for(int i = 0; i < t; i++) {
        T[i].parent = -1, T[i].left = -1, T[i].right = -1;
    }
    for(int i = 0; i < t; i++) {
        scanf("%d %d", &id, &k);
        for(int j = 0; j < k; j++) {
            temp_1 = temp;
            scanf("%d", &temp);
            T[temp].parent = id;
            if(!j) T[id].left = temp;
            else T[temp_1].right = temp;
        }
    }
    for(int i = 0; i < t; i++) {
        if(T[i].parent == -1) head = i;
    }
    getDepth(head, 0);
    for(int i = 0; i < t; i++) {
        printf("node %d: parent = %d, depth = %d, ", i, T[i].parent, D[i]);
        if(T[i].parent == -1) printf("root, [");
        else if(T[i].left == -1) printf("leaf, [");
        else printf("internal node, [");
        printChild(i);
    }
    return 0;
}
void getDepth(int u, int p) {
    D[u] = p;
    if(T[u].right != -1) getDepth(T[u].right, p);
    if(T[u].left != -1) getDepth(T[u].left, p+1);
}
void printChild(int u) {
    int c = T[u].left;
    int flag = 0;
    while(c != -1) {
        if(!flag) flag++;
        else printf(", ");
        printf("%d", c);
        c = T[c].right;
    }
    printf("]\n");
}



Measured memory_bytes: 7864
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <cassert>
#include <cmath>
using namespace std;

int main() {
	int n;
	scanf("%d", &n);
	printf("%d\n", n / 3);
        return 0;
}


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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let k: usize = iterator.next().unwrap().parse().unwrap();
    let c: usize = iterator.next().unwrap().parse().unwrap();

    let s: Vec<char> = iterator.next().unwrap().chars().collect();

    let mut i = 0;
    let mut l: Vec<usize> = Vec::new();
    while l.len() < k {
        if s[i] == 'o' {
            l.push(i);
            i += c + 1;
        } else {
            i += 1;
        }
    }

    let mut i: isize = n as isize - 1;
    let mut r: Vec<usize> = Vec::new();
    while r.len() < k {
        if s[i as usize] == 'o' {
            r.push(i as usize);
            i -= c as isize + 1;
        } else {
            i -= 1;
        }
    }

    let mut ans = String::new();
    for (&l, &r) in l.iter().zip(r.iter().rev()) {
        if l == r {
            ans.push_str(&format!("{}\n", l + 1));
        }
    }
    return ans.trim().to_string();
}


Measured memory_bytes: 14584
#include <iostream>
#include <cstdio>
#include<bits/stdc++.h>
#define re register int
using namespace std;

int n;
const int mod=1000000007;

inline long long f(int x)
{
    if(x==1)
        return 1; 
    return ((f(x-1)%mod)*x)%mod; 
}

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

    printf("%lld",f(n));  
    return 0;
}

Measured memory_bytes: 1152
require 'matrix'
include Math

def rotate(angle)
    c = cos(PI * angle / 180)
    s = sin(PI * angle / 180)
    Matrix[
        [c, s],
        [-s,  c]
        ]
end

x = Vector[0, 0]
v = Vector[0, 1]
while gets
    step, angle = $_.split(?,).map(&:to_i)
    break if step == 0 && angle == 0
    x += v * step
    v = rotate(angle) * v
end

puts x.to_a.map(&:to_i)

Measured memory_bytes: 9456
#include <bits/stdc++.h>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

using ull = unsigned long long;
using ll = long long;

using Int = int;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

const double PI  = 3.141592653589793238463;
const int MOD = 1000000007;
const Int INF = numeric_limits<Int>::max() / 3;

template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec){
        is >> x;
    }
    return is;
}

template<typename T>
string join(const vector<T>& vec, string sep = " "){
    stringstream ss;
    for(int i = 0; i < vec.size(); i++){
        ss << vec[i] << (i + 1 == vec.size() ? "" : sep);
    }
    return ss.str();
}

/*
 * X >= n(Y + Z) + Z
 * n <= (X - Z) / (Y + Z)
 */
int solve(int x, int y, int z){
    return (x - z) / (y + z);
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, y, z;
    cin >> x >> y >> z;
    cout << solve(x, y, z) << endl;

    return 0;
}


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

int main() {
 ll n;
 cin >> n;
 ll ans;
 for(ll i = 1; i <= sqrt(n); i++){
   ll a = i;
   if(n%a != 0)continue;
   ll b = n/a;
   ans = a+b-2;
 }
 cout << ans << endl;
}

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

int main() {
    int n,c,k;
    cin >> n >> c >> k;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    sort(a.begin(),a.end());   
    ll ans=1;
    int f=0;
    for(int i = 1; i < n; i++) {
        if(a[i]>a[f]+k){
            f=i;

            ans++;
        }
        else{
            if(i-f==c){
                f=i;

                ans++;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;
    if(s == u) a--;
    else b--;
    cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#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 all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;

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

	string s;
	cin >> s;
	int price = 700;
	if (s[0] == 'o'){
		price += 100;
	}
	if (s[1] == 'o'){
		price += 100;
	}
	if (s[2] == 'o'){
		price += 100;
	}
	cout << price << "\n";
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1001001001;
const long long MOD = 998244353;
const double EPS = 1e-10;

template<typename T>
struct SegTree {
    int n;
    T e;
    vector<T> d;
    SegTree(int n, T e): n(n + 1), e(e), d(2 * n + 2, e) {}
    T op(T x, T y) {
        return max(x, y);
    }
    void update(int i, T x) {
        i += n;
        d[i] = x;
        while(i > 1) {
            i >>= 1;
            d[i] = op(d[i << 1], d[i << 1 | 1]);
        }
    }
    T find(int l, int r) {
        T res = e;
        l += n;
        r += n;
        while(l < r) {
            if(l & 1) res = op(res, d[l++]);
            if(r & 1) res = op(d[--r], res);
            l >>= 1, r >>= 1;
        }
        return res;
    }
};

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

    int n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++)cin>>a[i],a[i]+=300000;
    SegTree<int> sg(1000000,0);
    for(int i=0;i<n;i++){
        int t=sg.find(a[i]-k,a[i]+k+1);
        sg.update(a[i],t+1);
    }
    cout<<sg.find(0,1000000)<<endl;
}

Measured memory_bytes: 13496
import math
a = int(input())
listA = list(map(int, input().split()))

b = int(input())
listB = list(map(int, input().split()))

count = 0
for i in range(b):
    key = listB[i]
    left = 0
    right = a
    while left < right:
        mid = math.floor((left+right)/2)
        if listA[mid] == key:
            count += 1
            break
        elif key < listA[mid]:
            right = mid
        else:
            left = mid + 1

print(count)



Measured memory_bytes: 16768
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	// #ifndef ONLINE_JUDGE
 //    	freopen("input.txt", "r", stdin);
 //    	freopen("output.txt", "w", stdout);
	// #endif
	string s;
	cin>>s;
	int k;
	cin>>k;
	int num = s(s);
	int i = 1;
	ll ans = 0;
	ll c[num+1][3];
	if(num < k){
		cout<<0;
		return 0;
	}
	rep(i,num+1){
		c[i][0] = 1;
		c[i][1] = i;
		c[i][2] = i*(i-1)/2;
	}
	while(i < num){
		if(i < k){i++;continue;}
		ll temp = 0;
		temp += c[i-1][k-1];
		rep(j,k){
			temp *= 9;
		}
		ans += temp;
		i++;
	}	
	if(k == 3){
		int f = 0;
		repa(i,1,num){	
			int f2 = 0;
			repa(j,i+1,num){
				ans += (s[0] - '1')*9*9;
				if(s[i]!='0' && f == 0)ans += (s[i] - '1')*9;
				else if(f == 0);
				else {
					ans += 9*9;
					// if(s[i]!='0')f++;
					if(s[j]!='0')f2++;
					// cout<<i<<" "<<j<<" "<<ans<<"\n";
					continue;
				}
				if(s[i] == '0' && f == 0);
				else if(s[j] == '0' && f+f2==0);
				else if(f + f2 > 0)ans += 9;
				else ans += s[j]-'0';
				
				if(s[j]!='0')f2++;
				// cout<<i<<" "<<j<<" "<<ans<<"\n";
			}
			if(s[i]!='0')f++;
		}
	}
	else if(k == 2){
		int f = 0;
		repa(i,1,num){
			ans += (s[0] - '1')*9;
			if(f == 0){ans += (s[i]-'0');}
			else ans += 9;
			if(s[i]!='0')f++;
		}
	}
	else{
		ans += (s[0]-'0');
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <map>
#include <set>
using namespace std;

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

	string s;
	cin >> s;
	int n = s.size();
	int gn = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'g') gn++;
		else gn--;
	}

	cout << gn / 2 << endl;
}

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

int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }

}

Measured memory_bytes: 3640
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int n,m;
	cin>>n>>m;
	vector<ll>v(m);
	for(int i=0;i<m;i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	if(n>=m){
		cout<<0<<endl;
	}
	else{
		int ans=v[m-1]-v[0];
		vector<int>diff(m-1);
		for(int i=0;i<m-1;i++){
			diff[i]=v[i+1]-v[i];
		}
		sort(diff.begin(),diff.end(),greater<int>());
		for(int i=0;i<n-1;i++){
			ans-=diff[i];
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
#define fr first
#define sc second
#define ii pair<int,int>
#define mp make_pair
#define All(v) v.begin(),v.end()
using namespace std;
int main ()
{
   ll x,y;
   cin>>x>>y;
  
   int ans = 0;
   while(x <= y)
   {
       ans++;
       x = x*2;
   }
   cout<<ans;
}


Measured memory_bytes: 256
function Main(input) {
  let [first, data] = input.trim().split("\n");

  let N = Number(first);
  const arr = [];
  let rst = 0;
  if (first < 3) {
    console.log(0);
  } else {
    data = data.split(" ").map(Number);
    dfs(0, 0);
    console.log(rst);
  }

  function dfs(idx, cnt) {
    if (cnt === 3) {
      const a = data[arr[0]];
      const b = data[arr[1]];
      const c = data[arr[2]];

      if (a !== b && a !== c && b !== c) {
        const [aa, bb, cc] = [a, b, c].sort((a, b) => b - a);
        //삼각혀으이 성립조건
        if (aa < bb + cc) {
          rst++;
        }
      }
      return;
    }

    for (let i = idx; i < N; i++) {
      arr.push(i);
      dfs(i + 1, cnt + 1);
      arr.pop();
    }
  }
}

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


Measured memory_bytes: 35924
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

struct LazySegmentTree {
private:
    int n;
    vector<ll> node, lazy;

public:
    LazySegmentTree(vector<ll> v) {
        int sz = (int)v.size();
        n = 1; while(n < sz) n *= 2;
        node.resize(2*n-1);
        lazy.resize(2*n-1, 0);
        for(int i=0; i<sz; i++) node[i+n-1] = v[i];
        for(int i=n-2; i>=0; i--) node[i] = node[i*2+1] + node[i*2+2];
    }

    void eval(int k, int l, int r) {
        if(lazy[k] != 0) {
            node[k] += lazy[k];
            if(r - l > 1) {
                lazy[2*k+1] += lazy[k] / 2;
                lazy[2*k+2] += lazy[k] / 2;
            }
            lazy[k] = 0;
        }
    }

    void add(int a, int b, ll x, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return;
        if(a <= l && r <= b) {
            lazy[k] += (r - l) * x;
            eval(k, l, r);
        }
        else {
            add(a, b, x, 2*k+1, l, (l+r)/2);
            add(a, b, x, 2*k+2, (l+r)/2, r);
            node[k] = node[2*k+1] + node[2*k+2];
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;
        eval(k, l, r);
        if(b <= l || r <= a) return 0;
        if(a <= l && r <= b) return node[k];
        ll vl = getsum(a, b, 2*k+1, l, (l+r)/2);
        ll vr = getsum(a, b, 2*k+2, (l+r)/2, r);
        return vl + vr;
    }
};

int main(int argc, char const *argv[]) {
  ll n, q;std::cin >> n >> q;
  vll c(n);
  vvl x = VV(n, 0, 0, ll);
  re(i, n) {
    std::cin >> c[i];
    c[i]--;
    x[c[i]].push_back(i);
  }
  LazySegmentTree seg(vll(n+1, 0));
  vll ans(q, 0);
  vector<vector<pair<ll, ll>>> d(n);
  for(int i=0;i<q;i++){
    ll l, r;std::cin >> l >> r;
    l--, r--;
    d[r].push_back(pair<ll, ll>(l, i));
  }
  for(int i=0;i<n;i++){
    ll now = c[i];
    auto itr = lower_bound(all(x[now]), i);
    ll pre = 0;
    if(itr!=x[now].begin()){
      itr--;
      pre = (*itr) + 1;
    }
    // pre ~ i まで + 1
    seg.add(pre, i+1, 1);
    for(auto v:d[i]){
      ll l = v.first;
      ll idx = v.second;
      ans[idx] = seg.getsum(l, l+1);
    }
  }
  re(i, q) std::cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 80172
#include <bits/stdc++.h>
#define ll long long
#define maxn 205 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int s[maxn][maxn];
char inp[maxn];	
int n;
int col[maxn];
int flag = 1;
int q[maxn], lv[maxn];
int main() {

	cin >>n;
	for (int i = 0; i < n; i++)
	{
		scanf("%s", inp);
		for (int j = 0; j < n; j++)
			s[i][j] = inp[j] - '0';
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int fr = 0, ed = 0;
		memset(lv, -1, sizeof(lv));
		q[ed++] = i, lv[i] = 1;
		while (fr < ed) {
			int ns = q[fr];
			fr++;
			for (int j = 0; j < n; j++)
				if (s[ns][j]) {
					if (lv[j] == lv[ns]) {
						cout << -1 << endl;
						return 0;
					}
					if (lv[j] == -1) {
						lv[j] = lv[ns] + 1, q[ed++] = j;
					}
				}
		}
		for (int j = 0; j < n; j++)
			ans = max(ans, lv[j]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    string s;
    cin >> s;
    if(s == "ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}




Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
typedef long long ll;
int a[maxn],l[maxn],r[maxn],ord[maxn];
ll val[maxn],sum[maxn],tot = 0;
int n,x;
bool cmp(int i,int j){
	return val[i]>val[j];
}
inline ll cal(int i,int v){
	if(v<=a[i])return 1LL*v*l[i];
	return 1LL*a[i]*l[i]+1LL*(v-a[i])*r[i];
}
bool check(ll m){
	int t = (m-1)/x,v = m-t*x;
	ll maxi = 0;
	for(int i=1;i<=t;i++){
		int x = ord[i]; 
		ll tmp = sum[t+1] - val[x] + cal(x,v);
		maxi = max(maxi,tmp);
	}
	for(int i=t+1;i<=n;i++){
		ll tmp = sum[t] + cal(ord[i],v);
		maxi = max(maxi,tmp); 
	}
	if(maxi>=tot)return 1;
	return 0;
}
int main()
{
	cin>>n>>x;
	for(int i=1;i<=n;i++)
		scanf("%d%d%d",&a[i],&l[i],&r[i]),
		val[i] = cal(i,x),
		ord[i] = i,
		tot += cal(i,a[i]);
//	cout<<tot<<endl;
	sort(ord+1,ord+n+1,cmp);
	for(int i=1;i<=n;i++)
		sum[i] = sum[i-1]+val[ord[i]];
	ll l = 0,r = 1LL*n*x;
	while(l!=r){
		ll m = (l+r)>>1;
		if(check(m))r = m;
		else l = m+1; 
	}
	cout << l << endl;
	return 0;
} 

Measured memory_bytes: 3328
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
  ll n,m;
  cin>>n>>m;
  vector<vector<ll>> mat(n,vector<ll>(m));
  for(ll i=0;i<n;i++)
    for(ll j=0;j<m;j++)
    {char ch; cin>>ch; mat[i][j] = (ch=='.'?1:0);}
  vector<vector<ll>> dp (n,vector<ll>(m));
  if(mat[0][0] == 0)
    dp[0][0]++;
  for( ll i=1;i<m;i++){
    if(mat[0][i] == 0 && mat[0][i-1]!=0)
      dp[0][i] = dp[0][i-1]+1;
    else dp[0][i] = dp[0][i-1];
  }
  for( ll i=1;i<n;i++){
    if(mat[i][0] == 0 && mat[i-1][0]!=0)
      dp[i][0] = dp[i-1][0]+1;
    else dp[i][0] = dp[i-1][0];
  }
  for(ll i=1;i<n;i++){
    for(ll j=1;j<m;j++){
      if(mat[i][j])
        dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
      else
        dp[i][j] = min(dp[i-1][j] + mat[i-1][j],dp[i][j-1]+ mat[i][j-1]);
    }
  }
  cout<<dp[n-1][m-1];
}

Measured memory_bytes: 3764
# -*- coding: utf-8 -*-
temp=input().split()
N=int(temp[0])
M=int(temp[1])
AB=[[int(j)-1 for j in input().split()] for i in range(M)]

chain=[[] for i in range(N)]#  各頂点の連結先
used=[False for i in range(N)]#使ったかどうか
ans=[]#                        答え（連結順にする）

#連結データ作成
for i in range(M):
	chain[AB[i][0]].append(AB[i][1])
	chain[AB[i][1]].append(AB[i][0])

#少なくとも連結のある頂点を探す
#連結のある頂点をstartに格納
#ansとusedに、使った証拠を残す
#startは後で使うので、nextに移す
start=0
while len(chain[start])==0:
	start+=1
ans.append(start)
used[start]=True
next=start


#連結先が無くなるまで連結する
while True:
	#連結先で、使っていない場所を探す
	for point in chain[next]:
		if used[point]==False:
			break
	else:
		break#for文完走なら、もう完結
	#使ってないところをusedとnextとansに代入して進める
	used[point]=True
	next=point
	ans.append(point)
#逆方向に進める
while True:
	for point in chain[start]:
		if used[point]==False:
			break
	else:
		break
	used[point]=True
	start=point
	ans.insert(0,start)
print(len(ans))
ANS=""
for i in ans:
	ANS+=str(i+1)+" "
print(ANS[:-1])

Measured memory_bytes: 36948
#include<iostream>
#include<algorithm>
using namespace std;
int n, d, x;
int main()
{
	cin >> n >> d >> x;
	int temp;
	while (n--)
	{
		cin >> temp;
		x++;
		int i = 1;
		while (temp*i + 1 <= d)
		{
			x++;
			i++;
		}
	}
	cout << x;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int v[100];
int main() {
    int n; cin >> n;
    int u, k;
    int a;
    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        for (int j = 0; j < k; j++) {
            cin >> a;
            v[a-1] = 1;
        }
        for (int j = 0; j < n; j++) {
            if (j) cout << " ";
            cout << v[j];
            v[j] = 0;
        }
        cout << endl;
        
    }
    
    return 0;
}



Measured memory_bytes: 3072
#include<stdio.h>

int main()
{
	int x;
	int i = 1;
	
	while(1)
	{
		scanf("%d",&x);
		
		if( x == 0 )
		{
			break;
		}
		printf( "Case %d: %d\n",i,x);
		
		i++;
	}
	
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

  sort(p.begin(), p.end(), greater<>());
  int result = 0;
  rep(i, n) {
    if (i == 0) {
      result += p[i] / 2;
    } else {
      result += p[i];
    }
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repR(i, n) for(ll i = n; i >= 0; i--)
#define For(i, m, n) for(ll i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

ll gcd(ll a, ll b){
    ll r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

ll lcm(ll x, ll y)
{
    if(x == 0 || y == 0) {
        return -1;
    }
    
    return (x * y / gcd(x, y));
}

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll nCr(ll n, ll r) {
    if ( r * 2 > n ) r = n - r;
    ll dividend = 1;
    ll divisor  = 1;
    for ( ll i = 1; i <= r; ++i ) {
        dividend *= (n-i+1);
        divisor  *= i;
    }
    return dividend / divisor;
}

//素因数分解
vector<pair<ll, int>>factorize(ll n){
    vector<pair<ll, int>> res;
    for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
            n /= i;
            res.back().second++;
        }
    }
    if(n != 1) res.emplace_back(n, 1);
    return res;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

ll mod = 1e9+7;

int main(){
    ll n;
    cin >> n;
    vector<ll> d(n);
    rep(i, n){
        cin >> d[i];
    }
    
    ll res = 0;
    rep(i, n){
        For(j, i+1, n){
            res += d[i]*d[j];
        }
    }
    
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 256
<?php
list($N, $K) = explode(" ", trim(fgets(STDIN)));
$D = explode(" ", trim(fgets(STDIN)));

for($i = $N; $i <= 99999; $i++){
    foreach($D as $num){
        if (strpos($i, $num) !== false){
            continue 2;
        }
    }
    echo $i;
    break;
}

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
 
    int x,a,b;
    scanf("%d %d %d",&x,&a,&b);
    
    if((a-b)>=0){
    printf("delicious\n");
    
    }else if((a+x)>=b){
    printf("safe\n");
    
    }else{
    printf("dangerous\n");
    }
    return 0;
}

Measured memory_bytes: 128