akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long 
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

vector<pair<int,int>> v;
int dp[101][100008];

int knapsack(int i, int n, int c){
	if(i==n) return 0;
	if(dp[i][c]!=-1) return dp[i][c];

	if(v[i].first<=c){
		int take_it = knapsack(i+1,n,c-v[i].first)+v[i].second;
		int reject_it = knapsack(i+1,n,c);

		return dp[i][c]=max(take_it, reject_it);
	}

	return dp[i][c]=knapsack(i+1,n,c);
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  	
  	int items,capacity;
  	cin>>items>>capacity;
  	v.resize(items,{-1,-1});
  	memset(dp,-1,sizeof(dp));

  	for(int i=0; i<items; i++) {
  		cin>>v[i].first>>v[i].second;
  	}
  	
  	int ans = knapsack(0,items,capacity);

  	cout<<ans<<'\n';


    return 0;
}

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


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

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

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

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



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

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

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
  int sosuu[46] ={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199};
  int min =100000001;
  int len=0;
  int l=0;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long  ans=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%lf", &a);
  printf("%lf\n", 3.14*2*a);
  
return 0;
}


Measured memory_bytes: 1740
import java.util.Scanner;
import java.util.Stack;
import java.util.ArrayDeque;

public class Main{
    public static void main(String[] aaa){
        Scanner s = new Scanner(System.in);
        Stack<Integer> x =new Stack <Integer>();
        Stack<Integer> y =new Stack <Integer>();
        int h,w,i,j,k,l,count=0,xx,yy,nx,ny;
        int[][] memo = new int[51][51];
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h==0&&w==0)break;
        for(i=1;i<=w;i++){
            for(j=1;j<=h;j++){
                memo[i][j] = s.nextInt();
            }
        }
        for(i=1;i<=w;i++){
            for(j=1;j<=h;j++){
                if(memo[i][j]==1){
                   // System.out.println("b"+(i)+" "+(j));
                    memo[i][j]=0;
                    x.push(i);
                    y.push(j);
                    //System.out.println("now"+now.x+" "+now.y);
                    while(x.size()>0&&y.size()>0){
                        nx=x.pop();
                        ny=y.pop();
                        
                        //System.out.println("a"+now.x+" "+now.y);
                        for(k=-1;k<=1;k++){
                            for(l=-1;l<=1;l++){
                                //if(nx==1)System.out.println("c"+(nx+k)+" "+(ny+l));
                                if((nx+k)>=1&&(nx+k)<=w&&(ny+l)>=1&&(ny+l)<=h&&memo[nx+k][ny+l]==1){
                                    memo[nx+k][ny+l]=0;
                                    x.push(nx+k);
                                    y.push(ny+l);
                                    //System.out.println("a"+(nx+k)+" "+(ny+l));
                                    //System.out.println(x.size()+" "+y.size());
                                }
                            }
                        }
                    }
                    count++;
                }
            }
        }
        System.out.println(count);
        count =0;
        for(i=1;i<=50;i++)for(j=1;j<=50;j++)memo[i][j]=0;
    }
    }
}


Measured memory_bytes: 49168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979
using ll = long long;
using P = pair<int,int>;

ll divisor=1e9+7;
int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	int now=1;
	now=a[now-1];
	int count=1;
	while(now!=2){
		if(now==1||count>n){
			puts(-1);
			return 0;
		}
		now=a[now-1];
		count++;
		
	}
	puts(count);
}

Measured memory_bytes: 640
L,R = list(map(int,input().split()))
if R-L+1 >= 2019:
    ans = 0
else:
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            s = (i*j)%2019
            ans = min(s,ans)
print(ans)


Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod998 = 998244353;
const ll intmax = 2147483647;
const ll llmax = 9223372036854775807;
const char sp = ' ';

int N, A[100000], c[3];
ll res;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	res = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 4; j++) {
			if (j == 3) {
				cout << 0 << endl;
				return 0;
			}
			if (c[j] == A[i]) {
				int t = 0;
				for (int k = 0; k < 3; k++) {
					if (c[k] == A[i])t++;
				}
				c[j]++;
				res *= t;
				res %= mod;
				break;
			}
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 640
/*
memo for solution
*/
#include <cstdlib> 
#include <numeric>
#include <cstring>
#include <cstdio> 
#include <cfloat> 
#include <map> 
#include <cassert>
#include <cmath> 
#include <climits> 
#include <utility> 
#include <set> 
#include <iostream> 
#include <memory> 
#include <string> 
#include <vector> 
#include <algorithm> 
#include <functional> 
#include <sstream> 
#include <complex> 
#include <stack> 
#include <queue> 
#include <iomanip>
#include<sys/time.h>
using namespace std; 
double e_time(void){static struct timeval now;gettimeofday(&now, NULL);return (double)(now.tv_sec  + now.tv_usec/1000000.0);}
#define REP(i,b,n) for(int i=b;i<n;i++) 
#define rep(i,n)      REP(i,0,n) 
#define pb push_back  
#define mp make_pair 
#define ALL(C)   (C).begin(),(C).end() 
#define fe(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr != (c).end();itr++)
#define BITSHIFT(X)     ( (1<<(X)) )
#define CONTAIN(S,X) ( ((S)&BITSHIFT(X)) != 0)
typedef complex<double>P; 
typedef long long ll; 
typedef unsigned long long ull; 
typedef pair<int,int> pii; 
typedef vector<int> vint;
template<class T> void vp(T &a,int p){rep(i,p)cout << a[i]<<" ";cout << endl;}  
template<class T> T ceilUp(const T& a,const T& b){return (a+b-1)/b;}
const ll mod =   1000000009;
inline ll modadd(ll a,ll b){a %= mod;b %= mod;return (a+b)%mod;}
inline ll modsub(ll a,ll b){a %= mod;b %= mod;a-=b;a%=mod;if (a<0)a+=mod;return a;}
inline ll modmul(ll a,ll b){a %= mod;b %= mod;return (a*b)%mod;}
inline ll modeq(ll a,ll b,ll m){a = (a%m+m)%m; b = (b%m+m)%m;return a == b;}
//ll modpow(ll n,ll p){if (p == 0)return 1;if (p == 1)return n;ll ret=mypow(n,p/2);ret=ret*ret%mod;if (p&1)ret=ret*n%mod;return ret;}
//ll getinv(ll a){return mypow(a,mod-2);}

int main(){
  string s;
  int w;
  cin >> s >> w;
  for(int i = 0;i < (int)s.size();i++){
    if (i%w == 0)cout << s[i];
  }
  cout << endl;
}



Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long; using ld = long double;
using P = pair<int, int>;
long long n, m, x, y, z;
const long long template_arry_size = 1000625;
long long a[template_arry_size];
long long b[template_arry_size];
long long c[template_arry_size];
string s, t;
long long ans = 0;
long long mod = 1'000'000'007;

ll A = 1000005;

//最大公約数を求める ユークリッドの互除法を使用
int gcd(int a, int b) {if (a < b) swap(a,b); if(b == 0) return a; else return gcd(b, a % b);}

//最小公倍数を求める 最大公約数を使用
int lcm(int a, int b) {int d = gcd(a, b); return a / d * b;}


void solve() {
    cin >> n ;
    rep(i,n) {
        cin >> a[i];
        c[a[i]]++;
    }

    bool pairwize = true;
    for (int i = 2; i < A; ++i) {
        int cnt = 0;
        for (int j = i; j < A; j+=i) {
            cnt += c[j];
        }
        if (cnt > 1) pairwize = false;
    }
    
    if (pairwize) {
        cout << "pairwise coprime" << endl;
        return;
    }

    int g = 0;
    rep(i,n) g = gcd(g,a[i]);
    if (g == 1) {
        cout << "setwise coprime" << endl;
        return;
    }

    cout << "not coprime" << endl;
    return;
}

int main(){

    solve();
    
}

Measured memory_bytes: 19192
#include<cstdio>
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;

int main(void) {
	set<int> penkis;
	for (int i = 0; i < 3; i++) {
		int penki;
		scanf("%d", &penki);
		penkis.insert(penki);
	}
	printf("%d", penkis.size());
	return 0;
}


Measured memory_bytes: 3772
#include <iostream>
#include <vector>
#include <algorithm>
#define Int int64_t
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> a(N, 0);


	for (int i = 1; i <= N; i++) {
		cin >> a.at(i - 1);
	}

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	Int sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += a.at(i - 1);
	}

	if (a.at(M-1) * 4 * M >= sum) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		int K = scan.nextInt();

		long answer = 0;
		for (long i = K; i <= N + 1; i++) {
			long temp = 0;
			temp += i * (2 * (N - i + 1) + (i - 1)) / 2;
			temp -= (i * (i - 1) / 2) - 1;

			answer += temp % 1000000007;
		}

		System.out.println(answer % 1000000007);
	}
}

Measured memory_bytes: 35772
h,w = map(int,input().split())
ls = []
side = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
for i in range(h):
  ls.append(list(input()))
for i in range(h):
  ans2 = ""
  for j in range(w):
    ans = 0
    if ls[i][j] == "#":
      ans2 += "#"
    else:
      for k in range(8):
        if i+side[k][0] < 0 or j+side[k][1] < 0 or h <=i+side[k][0] or w <= j+side[k][1]:
          continue
        else:
          ans += (1 if ls[i+side[k][0]][j+side[k][1]] == "#" else 0)
      ans2 += str(ans)
  print(ans2)


Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define pb push_back
 
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
const int N = 205;

int col[N];
bool good = 1;

void dfs(vector<vector<int>> &g, int u, int c)
{
	col[u] = c;
	for (auto v : g[u])
	{
		if (col[v] == -1) dfs(g, v, c^1);
		else if (col[v] == c) good = 0;
	}
}

int bfs(vector<vector<int>> &g, int start)
{
	int dep[N];
	memset(dep, 0, sizeof dep);
	queue<int> q;
	dep[start] = 1;
	q.push(start);
	while (!q.empty())
	{
		auto u = q.front();
		q.pop();
		for (auto v : g[u])
		{
			if (dep[v]) continue;
			q.push(v);
			dep[v] = 1 + dep[u];
		}
	}
	return *max_element(dep, dep + N);
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	vector<vector<int>> g(n+1);
	memset(col, -1, sizeof col);
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			char x; cin >> x;
			if (x == '1') g[i+1].pb(j+1);
		}
	}
	dfs(g, 1, 0);
	if (!good)
	{
		cout << -1;
		return 0;
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i)
		ans = max(ans, bfs(g, i));
	cout << ans;
}

Measured memory_bytes: 512
def getChoco(choco, w, t):
  for h in range(H):
    if S[h][w] == '1':
      choco[t[h]] += 1
  return choco

def solve(i):
  t = dict()
  t[0] = 0
  g = 0 # group index
  for h in range(H-1):
    if (i>>h)%2 == 1: 
      g += 1 # バイナリ表示したときに1となる桁で区切る（次のグループに移る）
      t[h+1] = g
    else:
      t[h+1] = g
  
  ret = g
  choco = [0 for _ in range(g+1)]
  # print(i, t, choco)
  for w in range(W):
    choco = getChoco(choco,w,t)
    if any(c>K for c in choco):
      # 分割を実行（chocoをリセット，wの分割を1増やす）
      choco = getChoco([0 for _ in range(g+1)],w,t)
      if any(c>K for c in choco): 
        return 10**9 # 分割した直後に条件を満たさない場合には，H方向の分割が不足しているため，解とならない
      else:
        ret += 1
  return ret

H,W,K = map(int, input().split())
S = [input() for _ in range(H)]

ans = H + W - 2
for i in range(2**(H - 1)):
    ans = min(ans, solve(i))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

int main(){
    long n;
    std::cin >> n;

    long val = 0;    
    long nBuf = n;
    while(0 != nBuf){
        val += nBuf % 10;
        nBuf = nBuf / 10;
    }

    if(0 == n % val){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch MultipleTestcases | diff MultipleTestcases.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address MultipleTestcases.cpp && ./a.out

/*
 
 8/5/2018
 
 24:30-24:56 analysis
 24:57-25:06 AC
 
 Editorials:
  - https://img.atcoder.jp/abc099/editorial.pdf
  - https://youtu.be/I-8BnRkq6Ow?t=1845
 
 Summary:
  - It takes too much time in analysis
  - C is small. State can be reduced to few buckets
 
 4/26/2020
 
 solve again
 
 */

const int MAX_N=500+1;
int A[MAX_N][MAX_N],D[31][31];
int N,C;

void solve() {
  VV<int> X(3);
  REP(i,N)REP(j,N) {
    X[(i+j)%3].push_back(--A[i][j]);
  }
  VV<int> cost(3,VI(C));
  REP(c,C)REP(i,3) {
    int sum=0;
    FORR(x,X[i]) sum+=D[x][c];
    cost[i][c]=sum;
  }
  
  int res=1e9;
  REP(c1,C)REP(c2,C)if(c1!=c2)REP(c3,C)if(c2!=c3&&c3!=c1) {
    int sum=cost[0][c1]+cost[1][c2]+cost[2][c3];
    SMIN(res,sum);
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>C;
  REP(i,C)REP(j,C) cin>>D[i][j];
  REP(i,N)REP(j,N) cin>>A[i][j];
  solve();
  
  return 0;
}


Measured memory_bytes: 2544
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        a: u64,
        b: u64,
        c: u64,
    }
    println!("{}", if a + b >= c { "Yes" } else { "No" });
}


Measured memory_bytes: 4352
n=int(input())
a=[int(i) for i in input().split()]
b=a.copy()
b.sort()

m1=b[int(n/2)-1]
m2=b[int(n/2)]
mm=(m1+m2)/2
for i in a:
  if i<=mm:
    print(m2)
  else:
    print(m1)

Measured memory_bytes: 25220
#include <bits/stdc++.h>
//#pragma GCC optimize(2)

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define nfor(i, a, b) for (int i = a; i >= b; --i)
#define pii pair<int, int>
#define MS0(X) memset(X, 0, sizeof(X))
#define MSf(X) memset(X, false, sizeof(X))
#define MS1(X) memset(X, -1, sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i, a, b) for (Rint i = a; i <= b; ++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI = atan(1.) * 4.;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double e = 2.71828182845904523536;
int dirx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int diry[8] = {0, 1, 0, -1, 1, 1, -1, -1};

int n;
LL a[maxn], b[maxn];
LL k, sum;
//priority_queue<int> q;


bool check(LL x)
{
    LL times=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]*b[i]<=x)
            continue;
        else
        {
            LL need=x/b[i];
            times+=a[i]-need;
            //DEBUG(need);DEBUG(a[i]);
        }
    }
    //DEBUG(times);
    if(times<=k)
        return true;
    else 
        return false; 
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    sort(a,a+n);
    sort(b, b + n,greater<LL>());
    if (sum <= k)
    {
        cout << 0 << "\n";
        return 0;
    }
    else
    {
        LL l=0,r=1e12,m,ans=0;
        while(l<=r){
            m=(r-l)/2+l;
            if(check(m))
                r=m-1,ans=m;
            else
                l=m+1;      
            //DEBUG(ans);      
        }
        cout<<ans<<"\n";
    }

    return 0;
}

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

int main()	{
	int n, k;
	cin >> n >> k;
	long long array[n];
	for(int i = 0; i < n; i++)	{
		cin >> array[i];
	}
	long long dp[n];
	dp[0] = 0;
	for(int i = 1; i <= min(n, k); i++)	{
		dp[i] = abs(array[i] - array[0]);		
	}
	
	for(int i = k+1; i < n; i++)	{
		dp[i] = INT_MAX;
		for(int j = 1; j <= k; j++)
			dp[i] = min((long long)abs(array[i] - array[i - j]) + dp[i - j], (long long)dp[i]);
	}
	cout << dp[n - 1];
}

Measured memory_bytes: 1792
var input=require("fs").readFileSync(0,"utf8").split("\n");
var s=input[0];
var t=input[1];
var ans=false;
for(var i=s.length;i--;){
  if(s===t){ans=true;break;}
  s=s.slice(1)+s[0];
}
console.log(ans?"Yes":"No");


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
constexpr char el = '\n';
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;

int main() {
  ll n;
  cin >> n;
  vl a(n);
  cin >> a;

  ll sum = 0;
  rep(i, n) {
    sum ^= a[i];
  }

  rep(i, n) {
    cout << (sum ^ a[i]) << " ";
  }
  cout << el;
}


Measured memory_bytes: 4764
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) { cin >> s[i]; }

  int a = 0, b = 0, c = 0;
  int result = 0;
  rep(i, N) {
    if (s[i].back() == 'A') {
      if (s[i].front() == 'B') {
        c++;
      } else {
        a++;
      }
    } else if (s[i].front() == 'B') {
      b++;
    }

    rep(j, s[i].size() - 1) {
      if (s[i][j] == 'A' && s[i][j + 1] == 'B') {
        result++;
      }
    }
  }
  cerr << result << endl;

  if (c > 0) {
    result += c - 1;
    if (a > 0) {
      result++;
    } else {
      a = 1;
    }
    result += min(a, b);
  } else {
    result += min(a, b);
  }

  cerr << a << " " << b << " " << c << endl;
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 768
from itertools import product

S = input()

ans = 0
Stack = []
for pat in product((0,1), repeat = len(S)-1):
  subtotal = 0
  for i in range(len(S)-1):
    if pat[i] == 0:
      Stack.append(int(S[i]))
    else:
      subtotal += int(S[i])
      power = 1
      while Stack:
        subtotal += Stack.pop() * (10 ** power)
        power += 1
  Stack.append(int(S[len(S)-1]))
  power = 0
  while Stack:
    subtotal += Stack.pop() * (10 ** power)
    power += 1     
  #print(pat, subtotal)
  ans += subtotal
  
print(ans)
    

Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

int main() {
    long long H;
    cin >> H;
    // 2^i <= H < 2^(i+1)
    long long x = 1;
    while (x * 2 <= H) {
        x *= 2;
    }
    cout << 2 * x - 1 << endl;
}


Measured memory_bytes: 256
#include <math.h>
#include <regex>
#include "bits/stdc++.h"
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define INF (INT_MAX / 2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX / 2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vs = vector<string>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using psi = pair<string, int>;

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

  int N; cin >> N;
  
  double ans = 0;
  if (N%2==0) ans = 0.5;
  else ans = (N/2 + 1) / (double)N;

  printf("%.10f\n", ans);

  return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  int b[n];
  for(int i=0;i<n;i++){
    b[i]=0;
  }
  for(int i=1;i<n;i++){
    cin >> a[i];
    int x = a[i];
    b[x-1] += 1;
  }
  for(int i=0;i<n;i++){
    cout << b[i] << endl;
  }
}

Measured memory_bytes: 5152
import java.util.Scanner;

public class Main {	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		x = x-a;
		while (x-b>=0) {
			x = x - b;
		}
		System.out.println(x);
	}
}


Measured memory_bytes: 21844
import numpy as np
a = []
for i in range(3):
    a.append(list(map(int, input().split())))
n = int(input())
b = []
for i in range(n):
    b.append(int(input()))
a = np.array(a)
for i in range(n):
    a[np.where(a == b[i])] = bool(b[i] in a)
def check(i,j):
    if i >= 0 and i < 3 and j >= 0 and j < 3:
        if a[i][j] == 1:
            return True
    return False
for i in range(3):
    if ((a[i][0] == 1 and a[i][1] == 1 and a[i][2] == 1) or (a[0][i] == 1 and a[1][i] == 1 and a[2][i] == 1)):
        print('Yes')
        break
else:
    if ((a[0][0] == 1 and a[1][1] == 1 and a[2][2] == 1) or (a[0][2] == 1 and a[1][1] == 1 and a[2][0] == 1)):
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 12496
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main(){
    string s;cin>>s;
    int sum=0;
    char pre=s[0];
    for(int i=1; i<s.size(); i++){
        if(s[i]!=pre)sum++;
        pre=s[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>



int main (void){
    int i,j;
    char s1 = 0,s2 = 0; 
    int a,b; 
    int n;
   

    scanf("%c %c",&s1,&s2);

    if(s1 == 'A'){
        a = 10;
    }else if (s1 == 'B'){
        a = 11;
    }else if (s1 == 'C'){
        a = 12;
    }else if (s1 == 'D'){
        a = 13;
    }else if (s1 == 'E'){
        a = 14;
    }else if (s1 == 'F'){
        a = 15;
    }
    if(s2 == 'A'){
        b = 10;
    }else if (s2 == 'B'){
        b = 11;
    }else if (s2 == 'C'){
        b = 12;
    }else if (s2 == 'D'){
        b = 13;
    }else if (s2 == 'E'){
        b = 14;
    }else if (s2 == 'F'){
        b = 15;
    }
    if(a<b){
        printf("<\n");
    }else if (a > b){
        printf(">\n");
    }else{
        printf("=\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define int long long

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    int z = 0;
    for(int i=0; i<n; i++){
        int d1, d2;
        cin >> d1 >> d2;
        if(d1 == d2) z++;
        else z = 0;
        if(z == 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;


    return 0;
}

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

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


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S == "Sunny"){
      cout << "Cloudy" << endl;
  }else if(S == "Cloudy"){
      cout << "Rainy" << endl;
  }else{
      cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,i,j,k,c=0,num;
    string s;
    cin>>s;
    cin>>n;
    for(i=0;i<s.size();i++)
    {
        if(s[i]=='1')
            c++;
        else if(s[i]!='1')
        {
            k=i;
            break;
        }
    }
    if(c==s.size())
        cout<<"1"<<endl;
    else if(c>=n)
        cout<<"1"<<endl;
    else
        cout<<s[k]<<endl;
}

Measured memory_bytes: 256
tmp = [int(e) for e in input().split()]

a = tmp[0]
b = tmp[1]
c = tmp[2]
d = tmp[3]

res = a * c

tmp = a * d

if tmp > res:
    res = tmp

tmp = b * c

if tmp > res:
    res = tmp

tmp = b * d

if tmp > res:
    res = tmp

print(res)


Measured memory_bytes: 9032
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> island(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    island[a].push_back(b);
    island[b].push_back(a);
  }
  for (int i = 0; i < island[0].size(); i++) {
    for (int j = 0; j < island[island[0][i]].size(); j++) {
      if (island[island[0][i]][j] == n - 1) {
        cout << "POSSIBLE" << endl;
        return 0;
      }
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 15012
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int D;
  cin>>D;
  vector<int> c(26);
  for(int &i:c)
    cin>>i;
  vector<vector<int>> s(D,vector<int>(26));
  for(vector<int> &v:s)
    for(int &i:v)
      cin>>i;
  vector<int> t(D);
  vector<int> A(26,0);
  int mzint=0;
  for(int i=0;i<D;i++){
    int mzi=mzint,mzin=0,k;
    for(int j=0;j<26;j++)
      mzi-=(i+1-A[j])*c[j];
    for(int j=0;j<26;j++){
      int l=mzi+s[i][j]-(i+1-A[j])*c[j];
      if(l>mzin){
        k=j;
        mzin=l;
      }
    }
    A[k]=i+1;
    mzint=mzin;
    t[i]=k+1;
  }
  int M=6000000,ans=mzint;
  while(M--){
    vector<pair<int,int>> AAA={make_pair(rand()%D,rand()%26),make_pair(rand()%D,rand()%26)};
    vector<int> BBB={t[AAA[0].first],t[AAA[1].first]};
    int ans2=ans;
    for(int aaa=0;aaa<2;aaa++){
    int d=AAA[aaa].first,q=AAA[aaa].second;
    ans+=s[d][q]-s[d][t[d]-1];
    int mae=-1,ato=D;
    for(int i=d-1;i>=0;i--){
      if(t[i]==t[d]){
        mae=i;
        break;
      }
    }
    for(int i=d+1;i<D;i++){
      if(t[i]==t[d]){
        ato=i;
        break;
      }
    }
    ans-=(ato-d)*(d-mae)*c[t[d]-1];
    mae=-1,ato=D;
    for(int i=d;i>=0;i--){
      if(t[i]==q+1){
        mae=i;
        break;
      }
    }
    for(int i=d;i<D;i++){
      if(t[i]==q+1){
        ato=i;
        break;
      }
    }
    ans+=(ato-d)*(d-mae)*c[q];
    t[d]=q+1;
    }
    if(ans2>ans){
      ans=ans2;
      t[AAA[0].first]=BBB[0];
      t[AAA[1].first]=BBB[1];
    }
  }
  for(int i:t)
    cout<<i<<endl;
}

Measured memory_bytes: 3724
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    string = dict()
    ans = 0
    for _ in range(n):
        s = ''.join(sorted(input()))
        if s in string:
            string[s] += 1
        else:
            string[s] = 1
    for i in string.values():
        if i > 1:
            ans += math.factorial(i)//(2*math.factorial(i-2))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 22316
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def ret_ans(n):
    li = [1]
    li.extend([6 ** i for i in range(1, 15) if 6 ** i <= n])
    li.extend([9 ** i for i in range(1, 15) if 9 ** i <= n])
    li.sort(reverse=True)
    
    s = set([n])
    cnt = 1
    while True:
        ts = set(s)
        for e in li:
            for c in s:
                if c - e == 0:
                    return cnt
                if c - e > 0:
                    ts.add(c - e)
        s = ts
        cnt += 1
 

def solve():
    print(ret_ans(int(input())))

if __name__=="__main__":
    solve()


Measured memory_bytes: 65636
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin >> a >> b;
	if(max({a,b}) < 9) cout << "Yay!" << "\n";
	else cout << ":(" << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	// your code goes here
    int n,m;
    cin>>n>>m;
    int dp[n][m];
    memset(dp,0,sizeof(dp));
    int a[n][m];
    char k;
    for(int i=0;i<n;i++)
    {
       for(int j=0;j<m;j++)
       {
           cin>>k;
           if(k=='.')
            a[i][j]=1;
           else a[i][j]=0;
       }
    }
    for(int i=0;i<n;i++)
    {
        if(a[i][0]==0)
        {
            break;
        }
        else dp[i][0]=1;
    }
    for(int i=0;i<m;i++)
    {
        if(a[0][i]==0)
        {
            break;
        }
        else dp[0][i]=1;
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(a[i][j]!=0)
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%(1000000007);
        }
    }
    
    cout<<dp[n-1][m-1]<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define BUF_SIZE 200

int count_both_char_kind(const char* a, const char* b)
{
  char table[256];
  int result = 0;
  memset(table, 0, sizeof(table));

  for(size_t i = 0; i < strlen(a); i++) {
    table[a[i]] = 1;
  }
  for(size_t i = 0; i < strlen(b); i++) {
    result += table[b[i]];
    table[b[i]] = 0;
  }
  return result;
}

int try_candidate(const char* s, size_t size)
{
  char buf1[BUF_SIZE];
  char buf2[BUF_SIZE];
  memset(buf1, 0, sizeof(buf1));
  memset(buf2, 0, sizeof(buf2));
  strncpy(buf1, s, size);
  strcpy(buf2, s+size);
  return count_both_char_kind(buf1, buf2);
}

int solve(const char* s)
{
  int result = 0;
  for(size_t i = 1; i < strlen(s); i++) {
    result = max(result, try_candidate(s, i));
  }
  return result;
}

int main()
{
  int n;
  char lf;
  char buf[BUF_SIZE];

  scanf("%d%c", &n, &lf);
  fgets(buf, sizeof(buf), stdin);
  printf("%d\n", solve(buf));
  return 0;
}


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

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		while (scanner.hasNext()) {
			int year = scanner.nextInt();
			int month = scanner.nextInt();
			int date = scanner.nextInt();

			Calendar calendar = Calendar.getInstance();
			calendar.set(year, month - 1, date);
			Calendar heisei = Calendar.getInstance();
			heisei.set(1989, 0, 8);
			Calendar showa = Calendar.getInstance();
			showa.set(1926, 11, 25);
			Calendar taisho = Calendar.getInstance();
			taisho.set(1912, 6, 30);
			Calendar meiji = Calendar.getInstance();
			meiji.set(1868, 8, 8);

			if (calendar.compareTo(heisei) >= 0) {
				System.out.println(String.format("heisei %d %d %d", year
						- heisei.get(Calendar.YEAR) + 1, month, date));
			} else if (calendar.compareTo(showa) >= 0) {
				System.out.println(String.format("showa %d %d %d",
						year - showa.get(Calendar.YEAR) + 1, month, date));
			} else if (calendar.compareTo(taisho) >= 0) {
				System.out.println(String.format("taisho %d %d %d", year
						- taisho.get(Calendar.YEAR) + 1, month, date));
			} else if (calendar.compareTo(meiji) >= 0) {
				System.out.println(String.format("meiji %d %d %d",
						year - meiji.get(Calendar.YEAR) + 1, month, date));
			} else {
				System.out.println("pre-meiji");
			}
		}
	}
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define endl "\n"

string mul(string a)
{
  int n = (int)a.size();
  string res = "";
  bool up = false;
  for (int i = n - 1; i >= 0; i--)
  {
    int tmp = (int)(a[i] - '0');
    tmp *= 2;
    if (up)
      tmp++;
    up = false;
    string tmp2 = to_string(tmp);
    res += tmp2[tmp2.size() - 1];
    if (tmp2.size() > 1)
      up = true;
  }
  if (up)
    res += '1';
  reverse(all(res));
  return res;
}

string add(string a) {
  int n = (int)a.size();
  string res = "";
  bool up = true;
  for (int i = n - 1; i >= 0; i--) {
    if (!up) {
      res += a[i];
      continue;
    }
    int tmp = (int)(a[i] - '0');
    tmp++;
    string tmp2 = to_string(tmp);
    res += tmp2[tmp2.size() - 1];
    if (tmp2.size() > 1) up = true;
    else up = false;
  }
  if (up) res += '1';
  reverse(all(res));
  return res;
}

map<string, int> NumA, NumB;

void parseA(string idx, string s)
{
  int n = (int)s.size();
  stack<char> st;
  int res = 0;
  int left = -1, right = -1;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == '(')
      st.push('(');
    else if (s[i] == ')')
      st.pop();
    else if (isdigit(s[i]) && st.empty())
    {
      res *= 10;
      res += (int)(s[i] - '0');
    }
    else if (s[i] == '[' && st.empty() && i - 2 > 0)
    {
      parseA(mul(idx), s.substr(1, i - 2));
    }
    else if (s[i] == ']' && st.empty() && i + 2 < n - 1)
    {
      parseA(add(mul(idx)), s.substr(i + 2, n - i - 3));
      break;
    }
  }
  NumA[idx] = res;
}

void parseB(string idx, string s)
{
  int n = (int)s.size();
  stack<char> st;
  int res = 0;
  for (int i = 0; i < n; i++)
  {
    if (s[i] == '(')
      st.push('(');
    else if (s[i] == ')')
      st.pop();
    else if (isdigit(s[i]) && st.empty())
    {
      res *= 10;
      res += (int)(s[i] - '0');
    }
    else if (s[i] == '[' && st.empty() && i - 2 > 0)
    {
      parseB(mul(idx), s.substr(1, i - 2));
    }
    else if (s[i] == ']' && st.empty() && i + 2 < n - 1)
    {
      parseB(add(mul(idx)), s.substr(i + 2, n - i - 3));
      break;
    }
  }
  NumB[idx] = res;
}

string a, b;
map<string, int> NumS;

string construct(string idx)
{
  if (NumS.count(idx) == 0)
    return "";
  return "(" + construct(mul(idx)) + ")[" + to_string(NumS[idx]) + "](" + construct(add(mul(idx))) + ")";
}

int main()
{
  cin >> a >> b;
  parseA("1", a);
  parseB("1", b);
  for (auto ite = NumA.begin(); ite != NumA.end(); ite++) {
    for (auto ite2 = NumB.begin(); ite2 != NumB.end(); ite2++) {
      if (ite->fi == ite2->fi) {
        NumS[ite->fi] = ite->se + ite2->se;
      }
    }
  }
  string ans = construct("1");
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3568
N = int(input())
# initialize
count = []
for i in range(0, 10):
  count.append([])
  for j in range(0, 10):
    count[i].append(0)

for i in range(1, N+1):
  count[int(str(i)[0])][int(str(i)[-1])] += 1

realCount = 0
for i in range(1, 10):
  for j in range(1, 10):
    realCount += (count[i][j] * count[j][i])
print(realCount)
    

Measured memory_bytes: 67812
#include<iostream>
#include<string>
#include<algorithm>
#include <stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int s=max({a,c});
  int t=min({b,d});
  cout <<max({t-s,0})<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
#include <vector>
#include <utility>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?(c=getchar()):0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=131072;
namespace T{
	const int E=N<<1;
	int to[E],bro[E],val[E],head[N],e=0;
	lint dep[N];
	inline void init(){
		memset(head,-1,sizeof(head));
	}
	inline void ae(int u,int v,int w){
		to[e]=v,bro[e]=head[u],val[e]=w,head[u]=e++;
	}
	inline void add(int u,int v,int w){
		ae(u,v,w),ae(v,u,w);
	}
	lint mx;
	inline void psh(vector<pair<lint,lint> >&vec,pair<lint,lint>p){
		if(!vec.empty()){
			pair<lint,lint>&lp=vec[vec.size()-1];
			if(lp.second<=p.second){
				return;
			}
			if(lp.first==p.first){
				lp=p;
				return;
			}
		}
		vec.push_back(p);
	}
	void dfs(int x,int fa,vector<pair<lint,lint> >&ans){
		if(bro[head[x]]==-1){
			ans.push_back(make_pair(dep[x],dep[x]));
			return;
		}
		int son1=0,son2;
		for(int i=head[x];~i;i=bro[i]){
			if(to[i]!=fa){
				son1^=i,son2=i;
			}
		}
		son1^=son2;
		vector<pair<lint,lint> >pool[2],*vec1=pool,*vec2=pool+1,ans1,ans2;
		dep[to[son1]]=dep[x]+val[son1],dfs(to[son1],x,*vec1);
		dep[to[son2]]=dep[x]+val[son2],dfs(to[son2],x,*vec2);
		if(vec1->size()>vec2->size()){
			swap(son1,son2),swap(vec1,vec2);
		}
		for(int i=0,j=0,n2=vec2->size(),k=0,n=vec1->size();i<n;i++){
			for(;j<n2&&(*vec1)[i].second+(*vec2)[j].first-(dep[x]<<1)<=mx;j++);
			for(;k<n2&&(*vec2)[k].second+(*vec1)[i].first-(dep[x]<<1)>mx;k++);
			if(j){
				ans1.push_back(make_pair((*vec1)[i].first,(*vec2)[j-1].second));
			}
			if(k<n2){
				ans2.push_back(make_pair((*vec2)[k].first,(*vec1)[i].second));
			}
		}
		for(int i=1,n1=ans1.size(),n2=ans2.size(),j=0,k=0,n=n1+n2;i<=n;i++){
			if(k==n2||(j<n1&&ans1[j].first<ans2[k].first)){
				psh(ans,ans1[j++]);
			}else{
				psh(ans,ans2[k++]);
			}
		}
	}
}
inline bool check(lint mx){
	T::mx=mx;
	vector<pair<lint,lint> >ans;
	T::dfs(1,0,ans);
	return !ans.empty();
}
int main(){
	int n=ni;
	T::init();
	lint l=0,r=0;
	for(int i=2,u,w;i<=n;u=ni,w=ni,r+=w,T::add(i++,u,w));
	for(lint m;l<r;m=(l+r)>>1,check(m)?(r=m):(l=m+1));
	printf("%lld\n",l);
	return 0;
}

Measured memory_bytes: 20224
#include<stdio.h>
int main(){
	int a,b,d,r;
	double fa,fb,f;
	scanf("%d %d",&a,&b);
	fa = a * 1;
	fb = b * 1;
	d = a / b;
	r = a % b;
	f = fa / fb;
	printf("%d %d %f\n",d,r,f);
return 0;
}


Measured memory_bytes: 2044
dest = input().rstrip("\n")

suffixes = ["dream", "dreamer", "erase", "eraser"]
cut_lens = [-5, -7, -5, -6]

while True:
    for suffix, cut_len in zip(suffixes, cut_lens):
        if dest.endswith(suffix):
            dest = dest[:cut_len]
            break
    else:
        break

print("YES" if not dest else "NO")


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

//mod逆元を使ったnCkの計算(速)
const int64_t MAX = 510000;
const int64_t MOD = 1000000007;


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

//繰り返し二乗法
int64_t pown(int64_t x, int64_t n) { 
  int64_t ans = 1;
  while (n > 0) {
    if ((n & 1) == 1) {
      ans = ans * x;
      ans %= MOD;
    }
    x = x * x;//一周する度にx, x^2, x^4, x^8となる
    x %= MOD;
    n >>= 1; //桁をずらす n = n >> 1
  }
  return ans;
}

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
int64_t COM(int64_t n, int64_t k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int64_t N, K;
  cin >> N >> K;
  COMinit();
  vector<int64_t> cnt(K,0);
  int64_t ans = 0;
  for(int i=K; i>=1; i--){
    int64_t x = K/i; //何個ある？
    int64_t plus = pown(x,N);
    for(int j=2; j<=x; j++){
      plus -= cnt.at(i*j-1);
      if(plus < 0){
        plus += MOD;
      }
      plus %= MOD;
    }
    ans += plus*i;
    cnt[i-1] = plus;
    ans %= MOD;
  }
  cout << ans << endl;  
}

Measured memory_bytes: 15932
#include <iostream>

using namespace std;

int main(){
  
  int string_len[3];
  int five = 0, seven = 0;
  cin >> string_len[0] >> string_len[1] >> string_len[2];
  
  for (int i=0; i<3; i++){
    if(string_len[i]==5){
      five++;
    }
    else if(string_len[i]==7){
      seven++;
    }
  }
  
  if((five==2)&(seven==1)){
    cout << "YES" << endl; 
  } else {
    cout << "NO" << endl;
  }
  
  return 0;

}

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

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back

using namespace std;

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

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;

template <typename T>
struct UnionFindTree{
  T par[MAX_N],rank[MAX_N],size[MAX_N];
  UnionFindTree(int N){
    fill(rank,rank+N,0);
    fill(size,size+N,1);
    rep(i,N) par[i] = i;
  }
  T find(T x){
    if(par[x]==x) return x;
    else return par[x] = find(par[x]);
  }
  void unite(T x,T y){
    x = find(x);
    y = find(y);
    if(x==y)  return ;
    if(rank[x] < rank[y]){
      par[x] = y;
    }else{
      par[y] = x;
      if(rank[x]==rank[y])  ++rank[x];
    }
    size[x] = size[y] = size[x] + size[y];
  }
  bool same(T x,T y){
    return find(x)==find(y);
  }
};

Pl a[MAX_N];
bool used[MAX_N];

int main(){
  int N,M; cin >> N >> M;
  UnionFindTree<int> uft(N);
  rep(i,N){
    scanf("%lld",&a[i].first);
    a[i].second = i;
  }
  rep(i,M){
    int x,y; scanf("%d%d",&x,&y);
    uft.unite(x,y);
  }
  if(2*(N-M-1)>N){
    cout << "Impossible" << endl;
    return 0;
  }else if(M==N-1){
    cout << "0" << endl;
    return 0;
  }
  sort(a,a+N);
  unordered_set<int> st;
  ll ans = 0LL; int cnt = 0;
  rep(i,N){
    if(st.count(uft.find(a[i].second))){
      if(cnt < N-M-2) ans += a[i].first, cnt++;
    }else{
      st.insert(uft.find(a[i].second));
      ans += a[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5004
#include <iostream>
using namespace std;
int counter(int);
int main(int argc, char const *argv[]) {
  int n;
  cin>>n;
  int ans=0;
  for(int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    if(tmp%2==0)  ans+=counter(tmp);
  }
  cout<<ans<<endl;
  return 0;
}

int counter(int a){
  int count=0;
  while(1){
    if(a%2==0){
      count++;
      a=a/2;
    }else{
      break;
    }
  }
  return  count;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define mod 1000000007
#define vll vector<ll>
#define pll vector<pair<ll,ll>>

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
    //cin>>t;
    t=1;
	start:
	while(t--){

         ll n;
         cin>>n;
         pll v;
      // ll c=0;
         for(ll i=0;i<n;i++){
            ll a,b;
            cin>>a>>b;
            v.pb({a,b});

         }
         for(ll i=0;i<=n-3;i++){
            if(v[i].f==v[i].s && v[i+1].f==v[i+1].s && v[i+2].f==v[i+2].s){
                cout<<"Yes"<<endl;
                goto start;
            }
         }
          cout<<"No"<<endl;

      }
	return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
typedef long long int ll;
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
int gcd(int a,int b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int n,k;
  scanf("%d %d",&n,&k);
  int a,cnt=0;
  FOR(n){
    scanf("%d",&a);
    if(a<k)cnt++;
  }
  PRN(n-cnt);
  return 0;
}


Measured memory_bytes: 128