akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld h, i;
      cin >> h;
      lld x, p;
      x = log2(h)+1;
      p = 1;
      lld s;
      s = 0;
      foi(i, x)
      {
      	s+= p;
      	p*= 2;
      }
      cout<< s;
      return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

using namespace std;
int main(){
    int N,i;
    scanf("%d",&N);
    int t[N],x[N],y[N];
    for (i = 0; i < N; i++){
        scanf("%d %d %d",&t[i],&x[i],&y[i]);
    }
    bool can =true;
    int check = t[0]-abs(x[0])-abs(y[0]);
    if( check%2 == 1 || check < 0 ) can=false;
    i=1;
    while(can){
        if(i==N) break;
        check = t[i]-t[i-1]-(abs(x[i]-x[i-1]))-(abs(y[i]-y[i-1]));
        if( check%2==1 || check < 0) can=false;
        i++;
    }
    if(can) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#define MAGIC cin.tie(NULL); ios_base::sync_with_stdio(false)
#define endl '\n'
//#define ll long long
#define mod (1000000007)
//#define NCONS 100001
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
//#define MCONS 2001
//#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
#define int long long
//#define double long double
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
typedef long long ll;

int gcd(int a, int b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }

#define YYYY cout << "YES" << endl
#define NNNN cout << "NO" << endl
#define yyyy cout << "Yes" << endl
#define nnnn cout << "No" << endl
int dx[]{0, 1, 0, -1};
int dy[]{1, 0, -1, 0};

//const int NCONS = 3001;
//const int MCONS = 101;

string s;

int32_t main()
{
    MAGIC;
    for(int i = 0; i < 26; i++)
    {
        s += (char)('A' + i);
    }
    int n; cin >> n;
    string str; cin >> str;
    
    for(auto ch : str)
    {
        auto cur_idx = ch - 'A';
        auto nxt_idx = (cur_idx + n) % s.size();
        cout << s[nxt_idx];
    }
    
    return 0;
}



Measured memory_bytes: 888
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>

using namespace std;

const int MAXN = 2000 + 10;

int N, Z, W;
long long int A[MAXN];

int main() {
	cin >> N >> Z >> W;
	for (int i = 0; i < N; i++)
		cin >> A[i];

	if (N == 1)
		cout << abs(A[0] - W) << endl;
	else {
		long long int Ans1 = abs(A[N - 1] - A[N - 2]);

		long long int Ans2 = abs(A[N - 1] - W);

		cout << (Ans1 > Ans2 ? Ans1 : Ans2) << endl;
	}


	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
int main() {

	ll n,x;
	cin>>n>>x;
	vector <int> m(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>m[i];
		sum+=m[i];
	}
	sort(m.begin(),m.end());
	cout<<n+(x-sum)/m[0]<<endl;

	return 0;
}


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, std::vector<long long> A){
    VLL memo(N, -1);
    REP(i, N) {
        auto it = lower_bound(ALL(memo), A[i]);
        memo[it - memo.begin() - 1] = A[i];
    }

    int cnt = 0;
    RREP(i, N-1) {
        if(memo[i] == -1) break;
        cnt++;
    }

    cout << cnt << endl;
}

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i = x; i < (int)(n); i++)
#define rep_ll(i,x,n) for(ll i = x; i < (ll)(n); i++)
using namespace std;
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
const long double PI = (acos(-1));
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, -1, 0, 1};
ll mod = 1000000007;
int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    //cout <<"!!!";
    queue<double> v_;
    v_.push((v[0]+v[1])/2);
    rep(i, 0, n-2){
        double xx=v_.front();
        v_.pop();
        v_.push((xx+v[i+2])/2);
        //cout << xx << " ";
    }
    double ans=v_.front();
    cout << fixed << setprecision(6) << ans;
}

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

using namespace std;
int main() {
    int N;
    int d[100000];
    cin >> N;
    for (int i=0; i<N; i++) cin >> d[i];
    sort(d, d+N);
    cout << d[N/2] - d[N/2-1] << endl;
    return 0;
}



Measured memory_bytes: 640
#pragma warning(disable: 4996)
#define _USE_MATH_DEFINES
#include <iostream>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
using namespace std;

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

	int N;
	string S;
	string ans = "";
	cin >>N >> S;
	for (int i = 0; i < S.size(); ++i) {
		if (N + S[i] > 90) ans += S[i] + N - 26;
		else ans += S[i] + N;
	}
	char c = 'c' + N;
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int x,y,p,q;
    while(cin>>x>>y){
    if(x>y)
        swap(x, y);
    p=x,q=y;
    while(1){
        if(x==0){
            cout<<y<<" ";
            break;
        }
        int t=x;
        x=y%x;
        y=t;
    }
    cout<<p*(q/y)<<endl;
    }
}

Measured memory_bytes: 1160
#include <iostream> 
#include <string>
#include <vector>

using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (b >= c && c >= a){
        cout << "Yes" << endl;
        return 0;
    }
    if (a >= c && c >= b) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def floyd_warshall(G):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                G[i][j]=min(G[i][j],G[i][k]+G[k][j])

import sys
input=sys.stdin.readline
INF=10**30
N,M,L=map(int,input().split())
dp1=[[INF]*N for i in range(N)]
for i in range(N):
    dp1[i][i]=0
for _ in range(M):
    A,B,C=map(int,input().split())
    A,B=A-1,B-1
    dp1[A][B]=C
    dp1[B][A]=C

floyd_warshall(dp1)

dp2=[[INF]*N for i in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            dp2[i][j]=0
        else:
            dp2[i][j]=1 if dp1[i][j]<=L else INF
floyd_warshall(dp2)

Q=int(input())
for _ in range(Q):
    s,t=map(lambda x:int(x)-1,input().split())
    print (dp2[s][t]-1 if dp2[s][t]!=INF else -1)

Measured memory_bytes: 86620
N,K=map(int,input().split())
D=set(map(str,input().split()))

p=N

def check(p,D):
  st=str(p)
  for char in st:
    if char in D:
      return False
  else:
    return True
  
while check(p,D)==False:
  p += 1
  
print(p)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

def main():
  N = int(input())
  vD = list(map(int, input().split()))
  MOD = 998244353

  if vD[0]!=0:
    print(0)
    return

  vD.sort()
  if vD[1]==0:
    print(0)
    return

  res = 1
  p = -1
  pcnt = 1
  ccnt = 1
  for d in vD:
    if d==p+1:
      pcnt = ccnt
      ccnt = 1
    elif d==p:
      ccnt += 1
    else: # d>=p+2
      print(0)
      return

    res *= pcnt
    res %= MOD
    p = d

  print(res)

main()


Measured memory_bytes: 13948
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <time.h>
#include <stdio.h>
#include <vector>
#define int long long
#define endre getchar();getchar();return 0
int inf = 1000000000;
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}
int Max(int x, int y) {
	if (x > y)return x;
	else return y;
}
int Min(int x, int y) {
	if (x < y)return x;
	else return y;
}
int kai(int x) {
	int cnt = 1;
	if (x == 0)return 1;
	cnt = kai(x - 1);
	return x * cnt;
}
int prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
void prime_factor(int n) {
	int cnt = 1;
	map<int, int>res;
	int m = n;
	for (int i = 2; i <= n; i++) {
		if (prime(i)) {
			while (m%i == 0) {
				++res[i];
				m /= i;
			}
		}
	}
	cout << n << ":" << endl;
	for (int i = 2; i <= n; i++) {
		if (res[i]) {
			cout << i << " " << res[i] << endl;
		}
	}
	cout << endl;
}
/*Library End!*/
int n, m;
pair<int, int>P[100005];
pair<int, pair<int,int>>ans[100005];
map<int, int>memo;
map<int, int>mp;
signed main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> P[i].first >> P[i].second;
		ans[i].second.first = P[i].first;
		ans[i].second.second = i;
		ans[i].first = P[i].second;
	}
	sort(ans, ans + m);
	for (int i = 0; i < m; i++) {
		memo[ans[i].second.first]++;
		mp[ans[i].second.second] = memo[ans[i].second.first];
	}
	for (int i = 0; i < m; i++) {
		if (P[i].first >= 100000)cout << P[i].first;
		else if (P[i].first >= 10000)cout << "0" << P[i].first;
		else if (P[i].first >= 1000)cout << "00" << P[i].first;
		else if (P[i].first >= 100)cout << "000" << P[i].first;
		else if (P[i].first >= 10)cout << "0000" << P[i].first;
		else cout << "00000" << P[i].first;
		if (mp[i] >= 100000)cout << mp[i] << endl;
		else if (mp[i] >= 10000)cout << "0" << mp[i] << endl;
		else if (mp[i] >= 1000)cout << "00" << mp[i] << endl;
		else if (mp[i] >= 100)cout << "000" << mp[i] << endl;
		else if (mp[i] >= 10)cout << "0000" << mp[i] << endl;
		else cout << "00000" << mp[i] << endl;
	}
	endre;
}


Measured memory_bytes: 19072
from sys import stdin 
n = int(stdin.readline().rstrip())
s = [int(x) for x in stdin.readline().rstrip().split()]
t = 1
answer = 0
for i in range(n):
    if s[i] == t:
        t += 1
    else:
        answer += 1
if answer == n:
    print(-1)
else:
    print(answer)



Measured memory_bytes: 72400
import  scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    val n: Int = readInt()
    val a: Array[Int] = readLine().split(" ").map(_.toInt)
    println(solve(n, a))
  }
  def time2(i: Int, ans: Int): Int = {
    i % 2 match {
      case 0 => time2(i / 2, ans + 1)
      case 1 => ans
    }
  }


  def solve(i: Int, ints: Array[Int]): Int =
    ints.foldLeft(10000000)((acc: Int, x: Int) => {val a = time2(x, 0)
      if(acc > a) a else acc
    }
    )
}


Measured memory_bytes: 27288
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MOD	1000000007
#define int	long long
#define pii pair<int,int> 
#define vi vector<int>
using namespace std;

int32_t main(){
	deque<char> s;
	string st;
	cin >> st;
	for(auto &x : st)
		s.push_back(x);
	int q;
	cin >> q;
	int cnt = 0;
	while(q--){
		int t;
		cin >> t;
		if(t == 1){
			cnt++;
		}
		else{
			int f;
			char c;
			cin >> f >> c;
			if(cnt % 2){
				if(f == 1)
					s.push_back(c);
				else
					s.push_front(c);

			}
			else{
				if(f == 1)
					s.push_front(c);
				else
					s.push_back(c);
			}
		}
	}
	if(cnt % 2)
		reverse(s.begin(),s.end());
	for(auto x : s)
		cout << x;

	return 0;
}



Measured memory_bytes: 896
#include <stdio.h>

int main(void)
{
	int N, i, k, h[100000], cnt=0;
	
	scanf("%d %d", &N, &k);
	
	for(i=0; i<N; i++){
		scanf("%d", &h[i]);
		if(h[i]>=k){ cnt++; }
	}
	
	printf("%d", cnt);
	
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){ 
	while(true){
		int H,W;
		cin >> H >> W;
		if(H==0 && W==0){
			break;
		}
		for(int i=0;i<W;i++){
			cout << "#";
		}
		cout << endl;
		for(int i=0;i<H-2;i++){
			cout << "#";
			for(int j=0;j<W-2;j++){
				cout << ".";
			}
			cout << "#" << endl;
		}
		for(int i=0;i<W;i++){
			cout << "#";
		}
		cout << endl;
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

#define int long long

const int N=2e5+5;
int n,a[N],ans=1e18;

signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]),a[i]+=a[i-1];
	for(int i=1;i<n;i++) ans=min(ans,abs(a[n]-a[i]-a[i]));
	write(ans);
}

Measured memory_bytes: 5168
def c():
	X = int(input())
	can = [False]*(X+1)
	can[0] = True
	for i in range(X+1):
		for j in [100,101,102,103,104,105]:
			if j > i:
				break
			elif can[i-j]:
				can[i] = True
	print(int(can[X]))
c()

Measured memory_bytes: 3828
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

 
int main(){
  int n,m;
  cin >> n >> m;
  
  if(n%2==1){
      int cntl = n/2;
      int cntr = n/2+1;
    rep(i,m){
      cout << cntl << " " << cntr << endl;
      cntl--;
      cntr++;
    }
    return 0;
  }

  int cnt = 0;
  int cntl = 1;
  int cntr = n/2;
  for(; cnt<m && cnt<n/4; cnt++){
      cout << cntl << " " << cntr << endl;
      cntl++;
      cntr--;
  }
  cntl = n/2+1;
  cntr = n-1;
  for(; cnt<m; cnt++){
      cout << cntl << " " << cntr << endl;
      cntl++;
      cntr--;
  }
  return 0;
}


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

int main() {
    int N, M, num=0, k=100000000, j=0;
    
    cin >> N;
    M = N;

    for(int i=0;i<9;i++) {
        j = M / k;
        num += j;
        M -= j*k;
        k /= 10;
    }

    if (N%num == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let n: usize = get_input().parse().unwrap();

    let mut v: Vec<i64> = Vec::new();
    let vline = get_input();
    for l in vline.split_whitespace() {
        v.push(l.parse().unwrap());
    }

    let mut c: Vec<i64> = Vec::new();
    let cline = get_input();
    for l in cline.split_whitespace() {
        c.push(l.parse().unwrap());
    }

    let ans: i64 = (0..n)
        .filter(|&i| v[i] > c[i])
        .map(|i| v[i] - c[i])
        .sum();

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


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

ans = sum(a)
numbers = [0]*(10**5+1)
for v in a:
    numbers[v] += 1

for _ in range(q):
    b,c = [int(i) for i in input().split()]
    nb = numbers[b]
    ans += (c-b)*nb
    print(ans)
    numbers[b] = 0
    numbers[c] += nb    

Measured memory_bytes: 20960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long

int s[200005];

signed main(){
	
	int n;cin>>n;
	
	rep(i,n)
	{
		int a;cin>>a;
		if(i==0) s[i]=a;
		else s[i] = s[i-1]+a;
	}
	s[n] = 0;
	
	sort(s,s+n+1);
	
	int same = 1;
	int ans = 0;
	FOR(i,1,n)
	{
		if(s[i] == s[i-1])same++;
		else
		{
			if(same == 1) continue;
			
			ans += same * (same-1) /2;
			same =1;			
		}		
	}
	
	if(same != 1)ans += same * (same-1) /2;
	
	
	cout << ans << endl;
}

//cout << ans << endl;

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<int>>v(h,vector<int>(w));
  for(int y=0;y<h;++y){
    for(int x=0;x<w;++x){
      cin>>v[y][x];
    }
  }

  vector<tuple<int,int,int,int>>ans;
  for(int y=0;y<h;++y){
    for(int x=0;x<w-1;++x){
      if(v[y][x]%2!=0){
        --v[y][x];
        ++v[y][x+1];
        ans.push_back(make_tuple(y,x,y,x+1));
      }
    }
    if(y<h-1&&v[y][w-1]%2!=0){
      --v[y][w-1];
      ++v[y+1][w-1];
      ans.push_back(make_tuple(y,w-1,y+1,w-1));
    }
  }

  cout<<ans.size()<<endl;
  for(const auto& t:ans){
    int a,b,c,d;
    tie(a,b,c,d)=t;
    ++a;++b;++c;++d;
    cout<<a<<' '<<b<<' '<<c<<' '<<d<<endl;
  }

  return 0;
}


Measured memory_bytes: 5232
#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::greater<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

void solve(int) {
  int64 a, d;
  cin >> n >> d >> a;
  vector<pair<int64, int64>> b(n);
  for (auto& pr : b) {
    cin >> pr.first >> pr.second;
  }
  sort(begin(b), end(b));
  priority_queue<pair<int64, int64>, vector<pair<int64, int64>>, greater<pair<int64, int64>>> q;
  int64 ans = 0, cur = 0;
  for (const auto& pr : b) {
    while (!q.empty() && q.top().first < pr.first) {
      cur -= q.top().second;
      q.pop();
    }
    int64 dif = pr.second - cur;
    if (dif > 0) {
      int64 v = (dif + a - 1) / a;
      ans += v;
      cur += a * v;
      q.emplace(pr.first + 2 * d, a * v);
    }
  }
  cout << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}



Measured memory_bytes: 5620
#include <iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        if(i%3==0){
            cout<<" "<<i;
        }else{
            int j = i;
            while(j > 0){
                if(j % 10 == 3){
                    cout << " " << i;
                    break;
                } else {
                    j /= 10;
                }
            }
        }
    }
    cout<<endl;
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,h,g,br=0;
    cin >> h >> n;
    for (int i=0;i<n;i++)
    {
        cin >> g;
        br+=g;
    }
    if(br>=h)
        cout << "Yes";
    else
        cout << "No";
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
	Scanner scn = new Scanner(System.in);
	int n =scn.nextInt();
	int W = scn.nextInt();
	int[]v = new int[n];
	int[]w = new int[n];
	for(int i=0;i<n;i++)
	{
		w[i]=scn.nextInt();
		v[i]=scn.nextInt();
	}
	long []dp = new long[W+1];
	
	
		for(int j=0;j<n;j++)
		{
			for(int i=W;i>=w[j];i--)
			{
		     
				dp[i]=Math.max(dp[i], v[j]+dp[i-w[j]]);
		}
	}
	System.out.println(dp[W]);
}
}

Measured memory_bytes: 37596
n = int(input())
l = [list(map(int, input().split())) for i in range(0, n) ]

for i in range(0, n):
    if l[i][2] != 0:
        p = l[i]
        break

for x in range(0, 101):
    for y in range(0, 101):
        h = p[2] + abs(x-p[0]) + abs(y-p[1])
        for i in range(0, n):
            if l[i][2] != max(h - abs(x-l[i][0]) - abs(y-l[i][1]), 0):
                break
        else:
            print(x, y, h)
            exit()

Measured memory_bytes: 3188
# frozen_string_literal: true

n = gets.to_i
m = Math.sqrt(n).to_i
mm = Math.sqrt(n - 1).to_i

if n == 2
  puts 1
  exit
end

def mod1?(n, k)
  x = n
  loop do
    x /= k
    break if x % k != 0
  end
  x % k == 1
end

mmf = (mm**2 == n - 1)
mf = (m**2 == n)
count = 2
(2..mm).each do |i|
  if ((n - 1) % i).zero?
    count += 2
    count -= 1 if (i == mm && mmf) || mm == 2
  elsif (n % i).zero?
    count += 1 if i > 1 && mod1?(n, i)
    if mod1?(n, n / i) && (i != m || !mf)
      count += 1
    end
  end
end
((mm + 1)..m).each do |i|
  if (n % i).zero?
    count += 1 if i > 1 && mod1?(n, i)
    if mod1?(n, n / i) && (i != m || !mf)
      count += 1
    end
  end
end
puts count


Measured memory_bytes: 3836
n = int(input())

result_num = 0
count_dict = {''.join(sorted(str(input()))): 1}

for i in range(n-1):
  word = ''.join(sorted(str(input())))

  if word in count_dict.keys():
    result_num += count_dict[word]
    count_dict[word] += 1
  else:
    count_dict[word] = 1

print(result_num)

Measured memory_bytes: 17852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long[] t = new long[n];
		t[0] = scan.nextLong();
		for (int i = 0; i < n - 1; i++) {

			t[i + 1] = solve(t[i], scan.nextLong());

		}
		System.out.println(t[n - 1]);

	}

	static long solve(long a, long b) {
		long x = a;
		long y = b;
		long ans;
		while (true) {
			if (x > y) {
				if (x % y == 0) {
					ans = x;
					break;
				} else {
					x = x + a;
				}

			} else {
				if (y % x == 0) {
					ans = y;
					break;
				} else {
					y = y + b;
				}

			}
		}

		return ans;
	}

}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  string s;
  vector<string> str;
  while (cin >> s) {
    if (s[s.size() - 1] == '.' || s[s.size() - 1] == ',') {
      s.erase(s.size() - 1);
    }
    if (3 <= s.size() && s.size() <= 6) {
      str.push_back(s);
    }
  }
  for (vector<string>::iterator it = str.begin(); it != str.end(); ++it) {
    if (it == str.end() - 1) cout << *it << endl;
    else cout << *it << ' ';
  }
}

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

int main(){
  int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;
  if(X>Y){
    swap(X,Y);
    swap(A,B);
  }
  ll ans=LLONG_MAX/2;
  for(int i=0;i<=Y*2;i+=2){
    ll tmp=0;
    tmp+=C*i;
    tmp+=A*max(0,(X-i/2));
    tmp+=B*max(0,(Y-i/2));
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


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

int main()
{
    string s;
    cin >> s;

    sort(s.begin(),s.end());
    if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2]){
        puts("Yes");
    }else {
        puts ("No");
    }
    return 0;
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

ll dp[3010][3010][4];

ll items[3010][3010];

void show_table(ll I, ll J, ll k) {
  for (ll i = 0; i <= I; i++) {
    for (ll j = 0; j <= J; j++) {
      cout << dp[i][j][k] << " ";
    }
    cout << "" << endl;
  }
  cout << "" << endl;
}

int main() {
  ll R, C, K;
  scanf("%lld %lld %lld", &R, &C, &K);

  vector<ll> list;
  for (ll i = 0; i < K; i++) {
    ll r, c, v;
    scanf("%lld %lld %lld", &r, &c, &v);

    r--;
    c--;
    items[r][c] = v;
  }

  for (ll r = 0; r < R; r++) {
    for (ll c = 0; c < C; c++) {
      ll v = items[r][c];

      dp[r][c + 1][0] = max(dp[r][c + 1][0], dp[r][c][0]);
      dp[r][c + 1][1] = max(dp[r][c + 1][1], dp[r][c][0] + v);
      dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][0] + v);

      dp[r][c + 1][1] = max(dp[r][c + 1][1], dp[r][c][1]);
      dp[r][c + 1][2] = max(dp[r][c + 1][2], dp[r][c][1] + v);
      dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][1] + v);

      dp[r][c + 1][2] = max(dp[r][c + 1][2], dp[r][c][2]);
      dp[r][c + 1][3] = max(dp[r][c + 1][3], dp[r][c][2] + v);
      dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][2] + v);

      dp[r][c + 1][3] = max(dp[r][c + 1][3], dp[r][c][3]);
      // dp[r][c + 1][4] = max(dp[r][c + 1][2], dp[r][c][3] + 0);
      dp[r + 1][c][0] = max(dp[r + 1][c][0], dp[r][c][3] + 0);
    }
  }

  cout << (dp[R][C - 1][0]) << endl;
  // cout << (dp[R][C - 1][1]) << endl;
  // cout << (dp[R][C - 1][2]) << endl;

  // show_table(3, 5, 0);
  // show_table(3, 5, 1);
  // show_table(3, 5, 2);
  // show_table(3, 5, 3);
}


Measured memory_bytes: 356476
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;cin>>s;
    list<char> lst;
    for(auto i:s)lst.push_back(i);
  
	int n;cin>>n;
	bool change = false;
	for(int i=0;i<n;++i){
		int curr;cin>>curr;
		if(curr==1)change = !change;
		else{
			int op ;cin>>op;
			char ch;cin>>ch;
			if(!change && op==1)lst.push_front(ch);
			if(change && op==2)lst.push_front(ch);
			if(!change && op==2)lst.push_back(ch);
			if(change && op==1)lst.push_back(ch);
		}
	}
	if(change){
		for(auto i=lst.rbegin();i!=lst.rend();++i)cout<<*i;
	}else{
    	for(auto i:lst)cout<<i;
    }
    cout<<endl;
	return 0;
}


Measured memory_bytes: 9984
n,k = map(int,input().split())
p = list(map(int,input().split()))
ans = 0
for i in range(n):
    p[i] = (p[i] + 1)/2
ev = sum(p[:k])
if n == k:
    print(sum(p))
    exit()
for i in range(n - k):
    ev += (p[i + k] - p[i])
    ans = max(ans,ev)
print(ans)



    


Measured memory_bytes: 98984
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int n;
    cin >> n;
    
    string s;
    cin >> s;
    n = s.size();
    
    int b = 0, e = 0;
    for (int i = 0; i < n && s[i] == ')'; i++) b++;
    for (int i = n - 1; i >= 0 && s[i] == '('; i--) e++;
    REP(i,b) s.insert(s.begin(), '(');
    REP(i,e) s.insert(s.end(), ')');
    
    stack<char> st;
    REP(i,s.size()) {
        if (s[i] == '(') {
            st.push(s[i]);
        } else {
            if (!st.empty()) {
                if (st.top() == '(') {
                    st.pop();
                } else {
                    st.push(s[i]);
                }
            } else {
                st.push(s[i]);
            }
        }
    }
    
    b = 0, e = 0;
    while (!st.empty()) {
        if (st.top() == '(') b++;
        else e++;
        st.pop();
    }
    
    REP(i,e) cout << "(";
    cout << s;
    REP(i,b) cout << ")";
    cout << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,m = 100000;

	scanf("%d",&n);

	while(n--){
		m *= 1.05;
		if(m % 1000 != 0) m = (m / 1000) * 1000 + 1000;
	}
	printf("%d\n",m);

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  string S; int W; cin>>S>>W;
  rep(i,0,S.size()){
    if(i%W==0)
      cout<<S[i];
  }
  cout<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;

vector<pair<long long,int>> PF(long long N){
  vector<pair<long long ,int>> ans(1,{0,0});
  long long n=N;
  for(int i=2;i<=sqrt(n);i++){
    if(N%i==0){
      N/=i;
      if(ans.at(ans.size()-1).first==i){
        ans.at(ans.size()-1).second++;
      }
      else{
        ans.push_back({i,1});
      }
      i--;
    }
    if(N==1){
      break;
    }
  }
  if(N!=1){
    ans.push_back({N,1});
  }
  auto itr1=ans.begin();
  ans.erase(itr1);
  return ans;
}

const int N_MAX = 1000010;
ll spf[N_MAX]; // smallest prime factors
void prepare_factorize(){
  rep(i,N_MAX) spf[i] = i;
  for(int p=2; p*p <= N_MAX; p++){
    for(int i=p; i<N_MAX; i+=p){
      if(spf[i]==i) spf[i] = p;
    }
  }
}

// 素因数分解
// その素因数が何個あるかのmapを返す
map<ll, ll> PFP(ll n,vector<ll> &x){
    if(spf[1]==0){
      //p("please initialize");
      exit(0);
    }
    map<ll, ll> mp;
    while(n!=1){
      ll p = spf[n];
      mp[p]++;
      n/=p;
      x.push_back(p);
      
    }
    return mp;
}

int main() {
  void prepare_factorize();
  ll N;
  cin>>N;
  ll ans=0;//cout<<1;
  for(int i=1;i<N;i++){
    ans+=(N-1)/i;
  }
  cout<<ans;
    
}



Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

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

  cout << a + pow(a,2) + pow(a,3) << endl;
  return 0;
}


Measured memory_bytes: 4184
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
int main(){
  ll n;
  cin>>n;
  vector<ll>data(n);
  for(ll i=0;i<n;i++)cin>>data[i];
  ll ans=0;
  for(ll d=0;d<60;d++){
    ll one=0;
    ll zero=0;
    for(ll i=0;i<n;i++){
      if((data[i]>>d)&1)one++;
      else zero++;
    }
    ll tmp=(1ll<<d)%MOD;
    //cout<<tmp<<endl;
    ll pr=one*zero%MOD;
    pr=pr*tmp%MOD;
    ans=(ans+pr)%MOD;

  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

bool a(char c){
  if(c == 'A' || c == 'T' || c == 'G' || c == 'C') return true;
  return false;
}

int main(){
  int N;
  cin >> N;
  vector<double> x(N);
  vector<string> u(N);
  double result = 0;
  cout << fixed << setprecision(8);
  for(int i = 0; i < N; i++){
    cin >> x.at(i) >> u.at(i);
    if(u.at(i) == "BTC") x.at(i) *= 380000.0;
    result += x.at(i);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
#define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        1e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}



int ispal(string s,int a,int b)
{
    int  l = b-a+1;
    
    for(int i=0;i<l/2;i++)
    {
        if(s[i]!=s[l-i-1]) return 0;
    }
    return 1;
}
void solve()
{
  
  string s;
  cin >> s;
  
  int n = sz(s);

  if(ispal(s,0,n-1) && ispal(s,0,(n-1)/2 - 1) && ispal(s,(n+3)/2 -1,n-1)) cout<<"Yes\n";
  else cout<<"No\n";  
}


int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 3600
#include<cstdio>
#define maxn 100010
int cnt[maxn]; 
int main(){
	int n,tmp;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&tmp);
		cnt[tmp]++;
	}
	int max = 0;
	for(int i = 1;i<maxn-1;i++){
		int t = cnt[i-1]+cnt[i]+cnt[i+1];
		max=max>t?max:t;
	}
	printf("%d",max);
}

Measured memory_bytes: 512
n = int(input())

if n >= 64:
    print(64)
elif n >= 32:
    print(32)
elif n >= 16:
    print(16)
elif n >= 8:
    print(8)
elif n >= 4:
    print(4)
elif n >= 2:
    print(2)
else:
    print(1)


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

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  map<long, long> MA;
  for (long i = 0; i < N; i++) {
    cin >> A.at(i);
    MA[A.at(i)]++;
  }
  sort(A.begin(), A.end());
  long mx = A.at(N - 1);
  vector<long> B(mx + 1, 1);
  for (long i = 0; i < N; i++) {
    for (long j = A.at(i) + A.at(i); j <= mx; j += A.at(i)) B.at(j) = 0;
  }
  long ans = 0;
  for (long i = 0; i < N; i++) {
    if (MA[A.at(i)] != 1) continue;
    if (B.at(A.at(i))) ans++;
  }
  cout << ans << "\n";
}

Measured memory_bytes: 24952
#include <bits/stdc++.h>
using namespace std;
#include <stdio.h>
int main() {char s[3],t[3];
    for(int i; i<3; i++){
      cin >> s[i];
    }
  for(int j; j<3; j++){
      cin >> t[j];
    }
  if(s[1]==t[1]&&s[0]==t[2]&&s[2]==t[0]) cout << "YES" << endl;
  else cout << "NO" << endl;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int A, B, X;
	cin >> A >> B >> X;

	if (A > X or A+B < X) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 61)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 n;
map<i64,bool> mp;
bool prime(i64 n){
	if(n < 2) return 0;
	for(i64 i = 2; i*i <= n; i++){
		if(n%i == 0) return 0;
	}
	return 1;
}
void solve(){
	cin >> n;
	i64 m = n;
	
	if(n==1){
		cout << 0 << endl;
		return;
	}
	i64 ans = 0;
	for(i64 i = 2; i*i <= m; i++){
		if(prime(i)){
			int cnt = 0, cc = 1;
			while(n%i==0){
				cnt++;
				n/=i;
				if(cnt == cc){
					ans++;
					cc++;
					cnt = 0;
				}
			}
		}
		i64 j = m/i;
		if(prime(j)){
			int cnt = 0, cc = 1;
			while(n%j==0){
				cnt++;
				n/=j;
				if(cnt == cc){
					ans++;
					cc++;
					cnt = 0;
				}
			}
		}
	}
	if(n != 1) ans++;
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3656
# ??\????????????????????? http://icpc.iisf.or.jp/past-icpc/domestic2013/ ????????????

def less(x,y)
  x[0] < y[0] || (x[0] == y[0] && x[1] < y[1])
end

loop do
  h, w = gets.split.map(&:to_i)

  break if h == 0 && w == 0

  input = [h*h+w*w, h]
  ans = [(151**2)*2, 151]
  answh = [-1, -1]

  (1..150).each do |i|
    (i+1..150).each do |j|
      t = [i*i+j*j, i]

      if less( input, t ) && less( t, ans )
        ans = t
        answh = [i, j]
      end
    end
  end

  puts answh.join(' ')
end

Measured memory_bytes: 8808
import sys
from collections import defaultdict, Counter

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

def main():
    N, *A = map(int, read().split())
    
    N_MAX = 10 ** 6

    min_factor = [0] * (N_MAX + 1)
    min_factor[1] = 1
    for i in range(2, N_MAX + 1):
        if min_factor[i]:
            continue
        for j in range(i, N_MAX + 1, i):
            if not min_factor[j]:
                min_factor[j] = i


    def prime_factorize_fast(n):
        a = Counter()
        while n != 1:
            f = min_factor[n]
            p = 0
            while min_factor[n] == f:
                p += 1
                n //= f
            a[f] = p

        return a

    lcm_prime = Counter()
    for a in A:
        for p, n in prime_factorize_fast(a).items():
            if lcm_prime[p] < n:
                lcm_prime[p] = n

    l = 1
    for p, n in lcm_prime.items():
        l = l * pow(p, n, MOD) % MOD

    ans = 0
    for a in A:
        ans = (ans + pow(a, MOD - 2, MOD)) % MOD

    ans = ans * l % MOD

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 82348
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
Unionかどうか調べればよさそう
どう調べる。
言語が橋
橋と人どっちも作る
人に言語いれる
言語でどこにいけるか探る
もしつながったらその人をtrueに
探索した言語もtrueにするか

言語ごとに、人をいれる
そこにいる人同士で関係つくる
人のUnion判定
はーTLE
N^2はむりなのね
人も言語もポイントとしてみなすのね

*/
vector<bool> seen;
vector<vector<ll>> G;
struct UnionFind{
  vector<ll> par,siz;
  
  UnionFind(ll N):par(N+1),siz(N+1,1){
    for(int i=0; i<=N; i++)
      par[i]=i;
  }
  
  void mkpar1(ll parent, ll n){//親は最上位
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=parent;
      mkpar1(parent, next_n);
    }
  }
  
  void mkpar2(ll n){//親は1個うえ
    for(auto next_n: G[n]){
      if(seen[next_n]) continue;
      seen[next_n]=true;
      par[next_n]=n;
      mkpar2(next_n);
    }
  }
  
  ll root(ll x){
    if(par[x]==x)
      return x;
    return par[x]=root(par[x]);
  }
  
  void unite(ll x, ll y){
    ll rx=root(x), ry=root(y);
    if(rx==ry)
      return;
    par[ry]=rx;
    siz[rx]+=siz[ry];    
  }
  
  bool issame(ll x, ll y){
    return root(x)==root(y);
  }
  
  ll size(ll x){
    return siz[root(x)];
  }
};
int main(){
  ll N,M; cin>>N>>M;
  seen.assign(N+M+1,false);
  G.assign(N+M+1, vector<ll>(0,0));
  for(int i=1; i<=N; i++){
    ll cnt; cin>>cnt;
    while(cnt-->0){
      ll j; cin>>j;
      G[i].emplace_back(N+j);
      G[N+j].emplace_back(i);
    }
  }
  UnionFind tree(N+M);
  tree.mkpar1(1,1);
  for(int i=1; i<N; i++){
    if(tree.issame(i,i+1)==false){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 12020
N,K = map(int,input().split())
R,S,P = map(int,input().split())
T = list(input())

POINT = {"r":P,"s":R,"p":S}
GET = [False] * N

ANS = 0
for i in range(N):
  t = T[i]
  if i <= K-1:
    ANS += POINT[t]
    GET[i] = True
  else:
    if not GET[i-K] or t != T[i-K]:
      ANS += POINT[t]
      GET[i] = True

print(ANS)


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

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

    ll x, y;
    cin >> x >> y;

    int res = 0;

    while(x<=y){
        x *= 2;
        ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define db double

using namespace std;


typedef pair<int, int> pii;
#define X first
#define Y second
 
template <typename T> inline void read(T &x) {
    int c = getchar();
    bool fg = false;
    for (x = 0; !isdigit(c); c = getchar()) {
        if (c == '-') {
            fg = true;
        }
    }
    for (; isdigit(c); c = getchar()) {
        x = x * 10 + c - '0';
    }
    if (fg) {
        x = -x;
    }
}

const int MAXN = 100100;
const int MAXE = 400400;
const int INF = 0x3f3f3f3f;

int n, T;
double A;
double h[MAXN];
const double eps = 0.006;

signed main() {
	read(n);
	read(T), read(A);
	for(int i = 1; i <= n; i++) {
		read(h[i]);
		h[i] = T - eps * (double) h[i];
	}
	double del = 1e20;
	int ans = 0;
	for(int i = 1; i <= n; i++) {
		if(fabs(h[i] - A) < del) {
			ans = i;
			del = fabs(h[i] - A);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int k, t, mx;

int main(){
  cin >> k >> t;
  rep(t){
    int x;
    cin >> x;
    chmax(mx, x);
  }

  if (mx <= (k + 1) / 2) cout << 0 << endl;
  else {
    if (k % 2 == 1) cout << (mx - (k + 1) / 2) * 2 << endl;
    else cout << (mx - k / 2) * 2 - 1 << endl;
  }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int mod = 1_000_000_007;
    // global
    static long fact[];
    static long inverse[];

    static long pow(long a,int n) {
        long res=1;
        while (n>0) {
            if ((n-n/2*2)==1) {
                res=res*a%mod;
            }
            a=a*a%mod;
            n>>=1;
        }
        return res;
    }

    static long modinv(long n) {
        return pow(n, mod-2);
    }

    static long comb(int n,int k){
        if(n<0 || k<0 || n<k)return 0;
        return fact[n]*(inverse[k]*inverse[n-k]%mod) %mod;
    }
    public static void main(String[] args) {
        // main method
        fact=new long[2000000];
        fact[0]=1;
        inverse=new long[2000000];
        inverse[0]=1;
        for(int i=1;i<2000000;i++){
            fact[i]=(fact[i-1]*(long)i)%mod;
            inverse[i]=modinv(fact[i]);
        }
        Scanner sc = new Scanner(System.in);
        int X = Integer.parseInt(sc.next());
        int Y = Integer.parseInt(sc.next());
        long ans = 0;
        if ((X+Y)%3==0 && X>=(X+Y)/3 && Y>=(X+Y)/3) {
            ans = comb((X+Y)/3, X-(X+Y)/3);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 55892