akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
using ll = long long;
using namespace std;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}

int D=365;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26));

ll calc(const vector<int>& t, int d, int q){
  ll res = 0;
  vector<int> lst(26,-1);
  rep(i,D){
    if(i!=d){
      if(t[i]!=-1){
        res += s[i][t[i]];
        lst[t[i]] = i;
      }
    }
    else{
      res += s[i][q];
      lst[q]=i;
    }
    rep(j,26){
      res -= c[j]*(i-lst[j]);
    }
  }
  //cerr << res << '\n';
  return res;
}



int main(){
  /*
  ifstream in("input.in");
  cin.rdbuf(in.rdbuf());
  ofstream ofs("output.txt");
  cout.rdbuf(ofs.rdbuf());
  //*/

  chrono::system_clock::time_point start, end;
  start = chrono::system_clock::now();
  mt19937 mt(18414);
  cin >> D;
  rep(i,26) cin >> c[i];
  rep(y,D) rep(x,26) cin >> s[y][x];
  vector<int> t(D,-1);
  ll now = calc(t, -1, -1);
  rep(d,D){
    int k=-1;
    ll prenow=-1;
    rep(q,26){
      ll pre = calc(t,d,q);
      if(now < pre){
        if(mt()&1 || mt()&1) {
          now = pre;
          t[d] = q;
        }
        if(k==-1) {k=q; prenow = pre;}
      }
      if(chmax(now,calc(t,d,q))){
        t[d]=q;
      }
      end = chrono::system_clock::now();
      double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
      if(ela>1900) break;
    }
    if(t[d]==-1) {
      t[d]=k;
      now = prenow;
    }
    // timer
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1900) break;
  }
  while(1){
    int d=mt()%365, q=mt()%26;
    if(chmax(now,calc(t,d,q))){
      t[d]=q;
    }
    end = chrono::system_clock::now();
    double ela = chrono::duration_cast<chrono::milliseconds> (end-start).count();
    if(ela>1970) break;
  }
  rep(i,D) cout << t[i]+1 << '\n';
  return 0;
}


Measured memory_bytes: 3692
#include <stdio.h>
#include <math.h>

int N, A, B, C, l[8];

int imin(int a, int b, int c, int d) {
	if (a <= b && a <= c && a <= d) {
		return a;
	}
	else if (b <= a && b <= c && b <= d) {
		return b;
	}
	else if (c <= a && c <= b && c <= d){
		return c;
	}
	else {
		return d;
	}
}

int rec(int a, int b, int c, int i) {
	int res0, res1, res2, res3;

	if (a != 0 && b != 0 && c != 0 && i == N) {
		return abs(A - a) + abs(B - b) + abs(C - c) - 30;
	}
	else if (i == N) {
		return 1000000000;
	}
	else {
		res0 = rec(a, b, c, i + 1);
		res1 = rec(a + l[i], b, c, i + 1) + 10;
		res2 = rec(a, b + l[i], c, i + 1) + 10;
		res3 = rec(a, b, c + l[i], i + 1) + 10;
		return imin(res0, res1, res2, res3);
	}
}

int main() {
	int i, mp;

	scanf("%d %d %d %d", &N, &A, &B, &C);
	for (i = 0; i < N; i++) {
		scanf("%d", &l[i]);
	}

	mp = rec(0, 0, 0, 0);

	printf("%d", mp);

	return 0;
}

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

int main() {
int N,K,i,n=1,min;
  cin>>N>>K;
  min=K*N+2;
  for(i=0;i<=N;i++){
    if(min>n+K*(N-i))
      min=n+K*(N-i);
    n*=2;
    }
  cout<<min<<endl;
  }

Measured memory_bytes: 256
/*
AizuOnline A1209
Title
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
//#include <limits.h>
//Global data section

//
int square_pay(int total)
{
  square_pay_1(total,17);
}
int square_pay_1(int total,int maxcoinroot)
{
  int i,sum;
  if(total==0)
    return(1);
  if(maxcoinroot==1)
    return(1);
  sum=0;
  for(i=0;maxcoinroot*maxcoinroot*i<=total;i++)
    sum += square_pay_1(total-maxcoinroot*maxcoinroot*i, maxcoinroot-1);
  return(sum);
}

main()
{
  int t;

  while(EOF!=scanf("%d",&t) && t)
    {
      printf("%d\n",square_pay(t));
    }
return(0);
}

Measured memory_bytes: 596
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
using namespace std;

const int MAXN = 1004;
int N;
int A[MAXN], B[MAXN];

int main() {
  while(cin >> N) {
    for(int i = 0; i < N; ++i) {
      cin >> A[i] >> B[i];
    }
    vector<pair<int,int> > v;
    for(int i = 0; i < N; ++i) {
      v.push_back(make_pair(B[i]-A[i], -B[i]));
    }
    sort(v.begin(), v.end(), greater<pair<int,int> >());
    int res = 0;
    for(int i = 0; i < v.size(); ++i) {
      if(v[i].first < 0) continue;
      ++res;
      for(int j = i+1; j < v.size(); ++j) {
        v[j].first -= min(
                          max(0, (-v[j].second)-v[i].first),
                          (-v[i].second)-v[i].first
                          );
      }
      sort(v.begin(), v.end(), greater<pair<int,int> >());
    }
    cout << res << endl;
  }
}

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

int main() {
    int n, k;
    int r, s, p;
    string t;
    cin >> n >> k >> r >> s >> p >> t;

    int score = 0;
    for (int i = 0; i < k; i++)
    {
        for (int j = i; j < n; j += k)
        {
            if (j < k)
            {
                if (t[i] == 'r')
                    score += p;
                if (t[i] == 's')
                    score += r;
                if (t[i] == 'p')
                    score += s;
                continue;
            }

            if (t[j] == t[j-k]) t[j] = 'a';

            if (t[j] == 'r')
                score += p;
            if (t[j] == 's')
                score += r;
            if (t[j] == 'p')
                score += s;
        }
        
    }
    cout << score << endl;
    return 0;
}

Measured memory_bytes: 512
const input = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n')
const [X, N] = input[0].split(' ').map(Number)

const solver = () => {
  if (N === 0) return X
  const p = input[1].split(' ').map(Number).map(v => v - X)
  if (!p.includes(0)) return X
  for (let i = 1; ; i++) {
    if (!p.includes(-i)) return X - i
    if (!p.includes(i)) return X + i
  }
}

console.log(solver())

Measured memory_bytes: 29640
a, b, c = map(int, input().split())
k = int(input())

while b <= a:
    if k == 0:
        print("No")
        exit()
    b *= 2
    k -= 1

while c <= b:
    if k == 0:
        print("No")
        exit()
    c *= 2
    k -= 1

print("Yes")


Measured memory_bytes: 61628
n = int(input())
ans = "Yes"
t,x,y = 0,0,0
for i in range(n):
    t1,x1,y1 = map(int,input().split())
    td,dis = t1-t,x1+y1-x-y
    if td%2 != dis%2 or td < dis:
        ans = "No"
        break
    t,x,y = t1,x1,y1
print(ans)

Measured memory_bytes: 3060
from collections import deque
n, m = int(input()), int(input())
B, S = 0, m
d = deque([0]*m)
for _ in range(n):
    cars = list(map(int, input().split()))
    for _ in range(cars[0]): d.append(0)
    try:
        for _ in range(cars[1]): d.pop()
    except IndexError:
        B = 1
    S = max(S, len(d))
print(0 if B else S)

Measured memory_bytes: 8028
#include <stdio.h>

int main(void)
{
	int n;
	
	scanf("%d", &n);
	while (n != 0){
		int table[10][10] = {{0}};
		int i, j;
		int sum[10] = {0};
		int all_sum = 0;
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				scanf("%d", &table[i][j]);
				sum[i] += table[i][j];
				all_sum += table[i][j];
			}
		}
		
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				printf("%5d", table[i][j]);
			}
			printf("%5d\n", sum[i]);
			sum[i] = 0;
		}
		for (i = 0; i < n; i++){
			for (j = 0; j < n; j++){
				sum[j] += table[i][j];
			}
		}
		for (i = 0; i < n; i++){
			printf("%5d", sum[i]);
		}
		printf("%5d\n", all_sum);
		
		scanf("%d", &n);
	}
	
	return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;
using boost::irange;

using ll = int64_t;

ll powi(int n, int k) {
    ll p = 1;
    for (int i = 0; i < k; i++) {
        p *= n;
    }
    return p;
}

int N, N2;
list<int> digit;

// digit以下の数字で、frontで始まりbackで終わるものの数
ll countWhen(int front, int back) {
    ll count = 0;
    // 1桁の数
    if (front == back) {
        if (digit.size() > 1) {
           count += 1;
        } else if (digit.front() == front) {
           count += 1;
        }
    }
    // 2～digit桁-1 までの桁の数
    for (int d = 2; d < digit.size(); d++) {
        count += powi(10, d - 2);
    }
    // digit桁の数
    if (digit.size() > 1) {
        if (front < digit.front()) {
            count += powi(10, digit.size() - 2);
        } else if (front == digit.front()) {
            count += N2;
            if (back <= digit.back()) {
                count += 1;
            }
        }
    }
    return count;
}

int main() {
    cin >> N;
    for (int n = N; n != 0; n /= 10) {
        digit.push_front(n % 10);
    }
    N2 = (N % powi(10, digit.size() - 1)) / 10;
    ll count = 0;
    for (int f : irange(1, 10)) {
        for (int b : irange(1, 10)) {
            ll as = countWhen(f, b);
            ll bs = countWhen(b, f);
            // cout << f << "-" << b << " : " << as << "*" << bs << "=" << as * bs << endl;
            count += as * bs;
        }
    }
    cout << count << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)
#define int long long

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, x, y, a, b, c;
int p[N], Q[N], r[N];
int nx, ny;
int sx, sy;
priority_queue <PII> q;
LL sum;

inline bool cmp(int gg, int hh) {return gg > hh;}

signed main()
{
	//File("");
	x = gi(), y = gi(), a = gi(), b = gi(), c = gi();
	for (int i = 1; i <= a; i+=1) p[i] = gi();
	for (int i = 1; i <= b; i+=1) Q[i] = gi();
	for (int i = 1; i <= c; i+=1) r[i] = gi(), q.push(make_pair(r[i], 3));
	sort(p + 1, p + 1 + a, cmp); sort(Q + 1, Q + 1 + b, cmp); sort(r + 1, r + 1 + c, cmp);
	for (int i = 1; i <= x; i+=1) q.push(make_pair(p[i], 1));
	for (int i = 1; i <= y; i+=1) q.push(make_pair(Q[i], 2));
	for (int i = 1; i <= x + y; i+=1)
	    sum += q.top().first, q.pop();
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 11756
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#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 <numeric>
#include <list>
#include <iomanip>
#include <iterator>

using namespace std;

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

 
int main(){
	int t;
	string s;
	cin>>t;
		getline(cin,s);
	while(t--){
		getline(cin,s);
		int x;
		while((x = s.find("Hoshino")) != string::npos){
			s[x+6] = 'a';
		}
		cout << s << endl;
	}
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin >> n;
   string s[n];
   int ac=0,tle=0,wa=0,re=0;
   for(int i = 0 ;i <n;i++){
   	cin>>s[i];
   }// AC, WA, TLE, or RE.
   for(int i = 0 ; i< n;i++){
   	if(s[i]=="AC"){
   		ac++;
   	}else if(s[i]=="WA"){
   		wa++;
   	}else if(s[i]=="TLE"){
   		tle++;
   	}else if(s[i]=="RE"){
   		re++;
   	}
   }
   cout <<"AC x "<<ac<<endl;
   cout <<"WA x "<<wa<<endl;
   cout <<"TLE x "<<tle<<endl;
   cout <<"RE x "<<re<<endl;
}


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

using namespace std;
using ll = long long;

int main() {
int k;
cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)cout<<s<<endl;
    else cout<<s.substr(0,k)+"..."<<endl;
    return 0;
}


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

map<int,int> prime(ll n){  
    map<int,int> mp;
    for(ll i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n!=1)mp[n]++;
    return mp;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(1010);
    for(int i=1;i<=n;i++){
        map<int,int> t = prime(i);
        for(auto e : t){
            v[e.first] += e.second;
        }
    }
    ll ans = 1;
    for(int i=0;i<=n;i++){
        if(v[i]>=1){
            ans = (ans * (v[i]+1))%MOD;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-

import sys

def main():
    numbers=[]
    n = int(input())
    numbers = [[int(i) for i in input().split()] for _ in range(n)]
    count=0
    dp=[]

    for idx,number in enumerate(numbers):
        if number[0] == number[1]:
            count+=1
            if idx==len(numbers)-1:
                dp.append(count)
        else:
            dp.append(count)
            count=0
    if max(dp)>=3:
        print("Yes")
    else:
        print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;
	int a, b ; cin>>a>>b ; 
	cout<<a+b/2 ; 
}

//////
////////
///////////



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		String s = sc.next();

		String ans;
		if (s.length() == a + b + 1) {
			ans = "Yes";
			for (int i = 0; i < s.length(); i++) {
				if (i == a) {
					if (s.charAt(i) != '-') {
						ans = "No";
						break;
					}
				} else {
					if (s.charAt(i) == '-') {
						ans = "No";
						break;
					}
				}
			}
		} else {
			ans = "No";
		}
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 23508
from sys import stdin
readline = stdin.readline

R, C, K = map(int, readline().split())

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

n = [0] * (C + 1)
for i in range(R):
    c = [0] * 4
    c[0] = n[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1]

print(max(c))


Measured memory_bytes: 145068
import java.util.Scanner;

class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long N = Long.parseLong(sc.next());
		long A = Long.parseLong(sc.next());
		long B = Long.parseLong(sc.next());
//		String S = sc.next();
		if(A == 0) {
			System.out.println(0);
			return;
		}

		long block = A + B;
		long aa = N / block;
		long aaa = N % block;

		System.out.println(aa * A + Math.min(A,aaa));

	}
}


Measured memory_bytes: 23764
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::{i32, i64, i128, u32, u64, u128, f64};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        a: u64,
        b: f64,
    }
    println!("{}", (a * ((1000.0 * b) as u64)) / 1000);
}


Measured memory_bytes: 2224
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	vector<long long> l(3);

	cin >> l[0] >> l[1] >> l[2];
	sort(l.begin(), l.end());

	auto small = l[2] / 2;
	auto big = l[2] - small;
	auto ans = (big - small) * l[0] * l[1];

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define vi vector<int>
#define ll long long
#define mod 100000007
const int N=1e5+2;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;int weight;
    cin>>n>>weight;int w[n+1],value[n+1];
    vector<vector<ll>> dp(n+1,vector<ll>(weight+1,0));
    for(int i=1;i<=n;i++){
        cin>>w[i];
        cin>>value[i];
    }
     for(int j=0;j<=weight;j++){
         dp[1][j]=0;
     }
    dp[1][w[1]]=value[1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=weight;j++){
            
         if(j>=w[i]){
     dp[i][j]=max(dp[i-1][j],value[i]+dp[i-1][j-w[i]]);
         }
         else{
             dp[i][j]=dp[i-1][j];
         }  
        }
    }
    cout<<dp[n][weight]<<endl;
}

Measured memory_bytes: 80256
// ConsoleApplication3.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include <algorithm>
using namespace std;
double n,t,x;
int main(){
	cin >> t >> x;
	n = t / x;
	cout << n << endl;
}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

using lint = long long;

int main() {
    lint N;
    cin >> N;
    vector<lint> A(5);
    for (int i = 0; i < 5; i++) {
        cin >> A[i];
    }
    lint min = *min_element(A.begin(), A.end());
    lint ans = 4 + (N + min - 1)/min;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#ifdef __LOCAL
  #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b) {if(a<b) {a=b; return true;} return false;}
template<typename T> bool chmin(T &a,T b) {if(a>b) {a=b; return true;} return false;}
#define itn int
#define fi first
#define se second
#define intmax numeric_limits<int>::max()
#define llmax numeric_limits<ll>::max()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sortt(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

int main(){
  ll n; cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n){
    cin >> x[i] >> y[i];
    a[i]=abs(x[i]-1)+abs(y[i]-1);
    b[i]=abs(x[i]-1e9)+abs(y[i]-1);
  }
  sortt(a);
  sortt(b);
  ll ans=0;
  chmax(ans,a[n-1]-a[0]);
  chmax(ans,b[n-1]-b[0]);
  cout << ans << endl;
}

Measured memory_bytes: 9564
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

vector<string>sts{
	"light fly!	    00.00kg@48.00 kg ",
	"fly!	        48.00kg@51.00 kg ",
	"bantam!	    51.00kg@54.00 kg ",
	"feather!	    54.00kg@57.00 kg ",
	"light!	        57.00kg@60.00 kg ",
	"light welter!	60.00kg@64.00 kg ",
	"welter!	    64.00kg@69.00 kg ",
	"light middle!	69.00kg@75.00 kg ",
	"middle!	    75.00kg@81.00 kg ",
	"light heavy!	81.00kg@91.00 kg ",
	"heavy!	        91.00kg@99999 kg ",
};

int main() {
	string st;
	while (cin >> st) {
		ld d=stold(st);
		d-=eps;

		for (int i = 0; i < sts.size(); ++i) {
			int k=sts[i].find('@', sts[i].find('!') + 1);
			string need=sts[i].substr(k+1,5);
			ld amax=stold(need);
			if (d < amax) {
				string name;
				int aa = sts[i].find('!');
				name = sts[i].substr(0, aa);
	
				cout<<name<<endl;
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(size_t i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    int X,A,B;
    cin >>X>>A>>B;
    if(A-B>=0){
        cout <<"delicious"<<endl;
    }
    else
    {if(X+A-B>=0){
        cout <<"safe"<<endl;
    }
    else{
        cout <<"dangerous"<<endl;
    }
    }
}

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

int main(){
    ios::sync_with_stdio(false);
    string s,t;
    cin>>s>>t;
    if(s.size()<t.size()){
        cout<<"UNRESTORABLE\n";
        return 0;
    }
    bool a=true;
    vector<int>b;
    for(int i=0;i<=s.size()-t.size();i++){
        if(s[i]=='?'||s[i]==t[0]){
            for(int j=0;j<t.size();j++){
                if(s[i+j]==t[j]||s[i+j]=='?'){
                    a=true;
                }else{
                    a=false;
                    break;
                }
            }
            if(a){
                b.push_back(i);
            }
            a=true;
        }
    }
    if(b.empty()==1){
        cout<<"UNRESTORABLE\n";
        return 0;
    }
    int last=b.back();
    for(int i=last;i<last+t.size();i++){
        s[i]=t[i-last];
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='?'){
            s[i]='a';
        }
    }
    cout<<s<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 1e9 + 7, two = (mod+1)>>1;
int n, sz[N], f[N];
vector <int> G[N];
ll p[N], ans;
ll powmod(ll a,ll b) 
{
	ll ans = 1;
	while(b)
	{
		if(b&1) ans = ans*a%mod;
		a = a*a%mod;
		b >>= 1;
	}
	return ans;
}
ll inv(ll a)
{
	return powmod(a, mod-2);
}
//ll inv(ll a) 
//{
//	a %= mod;
//	if(a<0) a += mod;
//	ll b = mod, u = 0, v = 1;
//	while(a) 
//	{
//		ll t = b / a;
//		b -= a * t;
//		swap(a, b);
//		u -= v * t;
//		swap(u, v);
//	}
//	if(u<0) u += mod;
//	return u;
//}
void dfs(int u, int fa)
{
	sz[u] = 1;
	f[u] = fa;
	int sub = 0;
	for(int v : G[u])
	{
		if(v==fa) continue;
		dfs(v, u);
		sz[u] += sz[v];
		sub++;
	}
	p[u] = inv(powmod(2, sz[u]));
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<n; i++)
 	{
 		int u, v;
 		cin >> u >> v;
 		G[u].pb(v); G[v].pb(u);
 	}
 	dfs(1, 0);
 	for(int u=1; u<=n; u++)
 	{
 		if(sz(G[u])<=1) continue;;
		ll cur = 1;
		ll tmp = p[f[u]];
		p[f[u]] = inv(powmod(2, n-sz[u]));
		for(int v : G[u]) cur = cur*p[v]%mod;
		ll res = cur;
		for(int v : G[u])
		{
			ll tmp = cur*inv(p[v])%mod*(1-p[v]+mod)%mod;
			res = (res + tmp)%mod;
		}
		res = (1 - res + mod)%mod;
		res = res*two%mod;
		p[f[u]] = tmp;
		ans = (ans + res)%mod;
	}
	ans = (ans + mod)%mod;
 	cout << ans;
	return 0;
}


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

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

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

int min_cost(int *arr,int n,int k){

	int *dp = new int[n+1];
	

	dp[0] = 0;
	dp[1] = 0;
	dp[2] =  abs(arr[1]-arr[2]);

	

	for(int i=3;i<=n;++i){
		int temp = INT_MAX;
		for(int j=1;j<=k && (i-j)>0;++j){
			temp = min(temp,abs(arr[i]-arr[i-j]) + dp[i-j]);
		}
		
		dp[i]  = temp;
	}

	
	
	int ans = dp[n];
	delete [] dp;
	return ans;

}


int main(){

	int n,k;
	cin>> n>>k;
	int arr[n+1];
	arr[0] = 0;
	for(int i=1;i<=n;++i){
		cin>>arr[i];
	}

	
	cout << min_cost(arr,n,k);

	

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main() {
    long long int a,b,c,d;
    scanf("%lld %lld %lld %lld\n",&a,&b,&c,&d);
    long long int num=a*c;
    if (b*c>num) {
        num=b*c;
    }
    if(a*d>num){
        num=a*d;
    }
    if(b*d>num){
        num=b*d;
    }
    printf("%lld",num);
}


Measured memory_bytes: 3224
S = input()
D = {chr(i):[] for i in range(97,123)}
def main():
	max_c = 0
	for d in D:
		i = 0
		while i != -1 :
			t = S[i:].find(d)
			if t != -1:
				t += i
				D[d].append(t)
				i = t + 1 
			else:
				break
		max_c = max(len(D[d]),max_c)
	if max_c == 1:
		return len(S) // 2
	else:
		ans = len(S) // 2
		for d in D:
			if len(D[d]) < 2:
				continue
			if min(D[d]) >= len(S)//2 or max(D[d]) < len(S) // 2:
				continue
			max_len = D[d][0]
			for j in range(len(D[d]) -1):
				max_len = max(max_len,D[d][j + 1] - D[d][j] - 1)
			max_len = max(max_len,len(S) - D[d][-1] - 1)
			ans = min(max_len,ans)
		return ans
print(main())

Measured memory_bytes: 3064
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
  int n;
  cin >> n;
  int a[n];
  int ans = 0;
  for (int i = 0;i < n; i++) {
    cin >> a[i];
    ans += (a[i] - 1) / 2;
    a[i] -= 2 * ((a[i] - 1) / 2);
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 2) {
      ans++;
    } else if (a[i] == 1 && i + 1 < n) {
      int mn = min(a[i], a[i + 1]);
      ans += mn;
      a[i + 1] -= mn;
    }
  }
  cout << ans << "\n";
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define maxn 100
#define maxm 100001
using namespace std;
typedef long long LL;

LL ans;
int n,m;
int w[maxn];
int v[maxn];
LL dp[maxm];

int main() {
	scanf("%d%d",&n,&m);
	for( int i = 0 ; i < n ; i++ )
		scanf("%d%d",&w[i],&v[i]);
	memset(dp, -1, sizeof(dp));
	dp[0] = 0;
	for( int i = 0 ; i < n ; i++ )
		for( int j = m - w[i] ; j >= 0 ; j-- )
			if( dp[j] != -1 )
				dp[j+w[i]] = max( dp[j+w[i]] , dp[j]+v[i] );
	for( int i = 0 ; i <= m ; i++ )
		ans = max( ans , dp[i] );
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
#include <unordered_map>
#define INF 9999999
using namespace std;
typedef unsigned long long int ll;

int main() {
	string S;
	cin >> S;
	if (S[0] == 'A') {
		int cnt = 0;
		int a;
		for (int i = 2; i < S.size() - 1; i++) {
			if (S[i] == 'C') {
				cnt++;
				a = i;
			}
		}
		if (cnt == 1) {
			for (int i = 1; i < S.size(); i++) {
				if (i == a)continue;
				if (S[i] >= 65 && S[i] <= 90) {
					cout << "WA" << endl;
					return 0;
				}
			}
			cout << "AC" << endl;
		}
		else if (cnt == 0 || 1 < cnt) {
			cout << "WA" << endl;
		}
	}
	else {
		cout << "WA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
R, G, B, N = map(int, input().split())

ans = 0
b = 0
for r in range(N+1):
    for g in range(N+1):
        b = (N - r*R - g*G)//B
        if r*R + g*G + b*B == N and b >= 0:
            ans += 1
print(ans)

Measured memory_bytes: 68080
/*************************************************\
           In the name of almighty ALLAH
                 MD.Faysal Hasan
                Comilla Univesity
\*************************************************/

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

#define     ikarus_101  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef     long long             ll;
typedef     long double           ld;
typedef     unsigned long long    ull;
typedef     vector<ll>            vll;
typedef     pair<ll,ll>           pll;
typedef     vector<pll>           vpl;
typedef     map<ll,ll>            mll;
typedef     multiset<ll>          msl;
typedef     multimap<ll,ll>       Mll;
using pqboro=priority_queue<ll,vll,less<ll>>;
using pqchoto=priority_queue<ll,vll,greater<ll>>;

#define    all(str)       str.begin(),str.end()
#define    sajo(str)      sort(str.begin(),str.end())
#define    rev(str)       reverse(str.begin(),str.end())
#define    usajo(str)     sort(str.rbegin(),str.rend())
#define    vin(a)         for(auto &it : a) cin>>it
#define    vout(a)        for(auto it:a) cout<<it<<' ';cout<<nn
#define    vmax(a)        *max_element(all(a))
#define    vmin(a)        *min_element(all(a))
#define    pb             push_back
#define    eb             emplace_back
#define    mkp(x,y)       make_pair(x,y)
#define    F              first
#define    S              second
#define    yes            cout<<"Yes"<<nn
#define    no             cout<<"No"<<nn
#define    nn             "\n" ///endl
#define    rep(i,n)       for (i=0;i<n;++i )
#define    rep1(i,n)      for (i=1;i<=n;++i )

#define    min3(a,b,c)    min(a,min(b,c))
#define    max3(a,b,c)    max(a,max(b,c))
#define    sqr(x)         ((x)*(x))
#define    pi             2*acos(0.0)
#define    gcd(a,b)       __gcd(a,b)
#define    lcm(a,b)       (a/gcd(a,b))*b
#define    mem(a,b)       memset(a,b,sizeof (a))
#define    dec(x)         cout<<fixed<<setprecision(x)
#define    none(n)         __builtin_popcountll(n)

template < typename T > string toString ( T Number ) { stringstream ss ; ss << Number ; return ss.str() ; }
template < typename T > ll toll ( T str ) { stringstream ss ; ss << str ; ll num ; ss >> num ; return num ; }

const   int  N   =   2e5+7;
const   int  M   =   1e9+7;
const   ll  inf  =   0x7f7f7f7f7f7f7f7f;
const   int dx[] =   {+1,+2,+2,+1,-1,-2,-2,-1};
const   int dy[] =   {-2,-1,+1,+2,+2,+1,-1,-2};

int main() {ikarus_101

    ll  n , m , i , j , k , x ;

    string s = "ACL";
    cin >> n;
    rep(i,n)
    cout << s ;
    cout << endl;





    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INFTY 1<<20
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
int main(){

ll a,b,g;
cin>>a>>b;
g = gcd(a,b);
vector<ll> num;
for(ll i=2;i*i<=g;++i){
    if(g%i==0){
        num.emplace_back(i);
        while(g%i==0){
            g/=i;
        }
    }
}
if(g!=1)num.emplace_back(g);
cout<<num.size()+1<<endl;
return 0;
}

Measured memory_bytes: 256
import Data.List 

main :: IO ()
main = do
    n <- read <$> getLine
    aa <- scanl (+) 0           . map read . words <$> getLine :: IO [Int]
    ab <- (0:) . reverse . scanl (+) 0 . reverse . map read . words <$> getLine :: IO [Int]

    print . maximum $ map (\i-> aa!!i + ab!!i) [1..n]

Measured memory_bytes: 1020
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] num1 = new int[n];
        int[] num2 = new int[n];
        
        int middle = 0;
        if(n % 2 != 0) middle = n / 2 + 1;
        
        for(int i = 0; i < n; i++) {
            num1[i] = scan.nextInt();
            if(i+1 == middle) num2[i] = num1[0];
        }
        
        for(int i = 0; i < n/2; i++) {
            num2[0+i] = num1[n-i*2-1];
            num2[n-1-i] = num1[n-i*2-2];
        }
        
        for(int i = 0; i < n; i++) {
            if(i != n-1) System.out.print(num2[i] + " ");
            else System.out.println(num2[i]);
        }
    }
}


Measured memory_bytes: 96276
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;

ll a[100003];

int main() {
	int k; cin >> k;
	for (int i = 0; i < k; ++i) cin >> a[i];
	if (a[k - 1] != 2) {
		cout << -1 << endl;
		return 0;
	}
	ll ansmin = 2, ansmax = 3;
	for (int i = k - 2; i >= 0; --i) {
		ansmin = (ansmin/a[i] + (ansmin % a[i] == 0 ? 0 : 1))*a[i];
		ansmax = ansmax/a[i] * a[i] + a[i] - 1;
	}
	
	ll nmin = ansmin, nmax = ansmax;
	for (int i = 0; i < k; ++i) {
		nmin = nmin / a[i] * a[i];
		nmax = nmax / a[i] * a[i];
	}
	if (nmin == 2 && nmax == 2) cout << ansmin << " " << ansmax << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication6
{

    class Program
    {
        static void Main(string[] args)
        {
            var D = RL2IE().ToList();
            var N = D[0];
            var K = D[1];
            var Ai = RL2IE().ToList();
            for (int i = 0; i < N - K; i++)
            {
                Console.WriteLine(bool2ret(Ai[i] < Ai[K + i]));
            }
            //Console.WriteLine(bool2ret(ret));
            Console.ReadLine();

        }

        static IEnumerable<int> RL2IE() { return spr(RL()).Select(x => (int)c2i(x)); }
        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "Yes" : "No"; }
    }
}


Measured memory_bytes: 46532
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(i,e) for(ll i=0;i<e;i++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
ll i;
long long euclid(long long x,long long y){
    long long a=max(x,y);
    long long b=min(x,y);
    if(a%b==0)return b;
    else{
        return euclid(b,a%b);
    }
}

int main(){
    ll N,K;
    cin>>N>>K;
    if(N==K)cout<<0;
    else if(N>K){
        if(N%K==0)cout<<0;
        else cout<<min(N%K,(K-N%K)%K);
    }
    else{
        cout<<min(N,K-N);
    }
    cout<<endl;
     
}


Measured memory_bytes: 256
//Bouquet problem

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define sd second
#define ft first
#define ios                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

vector<vector<int>> f;
vector<int> meme;
vector<int> count_meme;
vector<bool> vis;
vector<int> a;
int cnt = 1;

void dfs(int s)
{
    if (vis[s])
        return;
    vis[s] = true;
    meme[s] = cnt;
    for (auto x : f[s])
        dfs(x);
}

int32_t main()
{
    ios;
    int n, k, m;
    cin >> n >> k >> m;
    f = vector<vector<int>>(n + 1);
    a = vector<int>(n + 1, 0);
    vis = vector<bool>(n + 1, false);
    meme = vector<int>(n + 1, 0);
    count_meme = vector<int>(n + 1, 0);
    for (int i = 0; i < k; i++)
    {
        int u, v;
        cin >> u >> v;
        f[u].push_back(v);
        f[v].push_back(u);
    }

    for (int i = 1; i < (n + 1); i++)
    {
        dfs(i);
        cnt++;
    }
    for (int i = 1; i < (n + 1); i++)
    {
        count_meme[meme[i]]++;
    }
    for (int i = 1; i < (n + 1); i++)
    {
        a[i] = count_meme[meme[i]] - f[i].size() - 1;
    }
    for (int i = 0; i < m; i++)
    {
        int u, v;
        cin >> u >> v;
        if (meme[u] == meme[v])
        {
            a[u]--;
            a[v]--;
        }
    }
    for (int i = 1; i < (n + 1); i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 12144
#include <stdio.h>
#include <string.h>

int lcs(char *, char *);

main() {
  int i, n, result[1001];
  char X[1001], Y[1001];
  
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%s", X);
    scanf("%s", Y);
    result[i] = lcs(X, Y);
  }
  for(i = 0; i < n; i++) {
    printf("%d\n", result[i]);
  }
  return 0;
}

int lcs(char *x, char *y) {
  int c[1001][1001];
  int i, j, m, n; 
  m = strlen(x);
  n = strlen(y);
  for(i = 1; i < m + 1; i++) {
    c[i][0] = 0;
  }
  for(j = 0; j < n + 1; j++) {
    c[0][j] = 0;
  }
  for(i = 1; i < m + 1; i++) {
    for(j = 1; j < n + 1; j++) {
      if(x[i - 1] == y[j - 1]) {
	c[i][j] = c[i - 1][j - 1] + 1;
      }
      else if(c[i - 1][j] >= c[i][j - 1]) {
	c[i][j] = c[i - 1][j];
	}
      else {
	c[i][j] = c[i][j - 1];
      }
    }
  }
  return c[m][n];
}

Measured memory_bytes: 4528
public class Circle_in_a_Rectangle {
  
  static void Main(string[] args) {
    
    var line = System.Console.ReadLine().Trim().Split(' ');

    int w = int.Parse(line[0]);
    int h = int.Parse(line[1]);
    int x = int.Parse(line[2]);
    int y = int.Parse(line[3]);
    int r = int.Parse(line[4]);

    string result = "No";

    if (r <= x && x <= w - r && r <= y && y <= h - r) {
      result = "Yes";
    }

    System.Console.WriteLine(result);
    
  }

}

Measured memory_bytes: 8984
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write('\n'.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = 998244353
INF=float('inf')


def construct_sum(segtree,a,n,func=max):
    for i in range(n):
        segtree[n + i] = a[i]
    for i in range(n - 1, 0, -1):
        segtree[i] = func(segtree[2 * i], segtree[2 * i + 1])

def update(pos, x, func=max):
    pos += n-1
    segtree[pos] = x
    while (pos>1):
        pos>>=1
        segtree[pos] = func(segtree[2 * pos], segtree[2 * pos + 1])

def get(l, r, func=max):
    l += n-1
    r += n-1
    s = 0
    while (l <= r):
        if l & 1:
            s = func(segtree[l],s)
            l+=1
        if (r+1) & 1:
            s = func(segtree[r],s)
            r-=1
        l >>= 1
        r >>= 1
    return s

n,k=mdata()
a=[int(data()) for i in range(n)]
n=max(a)+1
segtree = [0]*(2*n)
construct_sum(segtree,[0]*n,n)
ans=0
for i in a:
    a1=get(max(i-k+1,1),min(i+k+1,n))+1
    update(i+1,a1)
    ans=max(ans,a1)
out(ans)








Measured memory_bytes: 96176
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

void dfs(const vector<vector<int>>&g,vector<int>&memo, const int now) {
	for (auto e : g[now]) {
		if (memo[e] == -1) {
			memo[e] = memo[now];
			dfs(g, memo, e);
		}
		else if (memo[e] == memo[now])continue;
		else {
			throw(false);
		}
	}
}

int main() {
	int N, M, K; cin >> N >> M >> K;
	vector<vector<int>>g(N);
	int ans = 0;
	vector<int>memo(N,-1);
	for (int i = 0; i < K; ++i) {
		int t; cin >> t;
		int a, b; cin >> a >> b; a--; b--;
		if (t == 1) {
			g[a].push_back(b);
			g[b].push_back(a);
			if (memo[a] != -1 && memo[b] != -1) {
				if (memo[a] == memo[b])continue;
				else {
					ans = i + 1;
					break;
				}
			}
			else if (memo[a] != -1 & memo[b] == -1) {
				memo[b] = memo[a];
				dfs(g, memo, b);
			}
			else if (memo[a] == -1 && memo[b] != -1) {
				memo[a] = memo[b];
				dfs(g, memo, a);
			}
			else {
				continue;
			}
		}
		else {
			if (memo[a] == -1) {
				memo[a] = b;
				dfs(g, memo, a);
			}
			else {
				if (memo[a] == b)continue;
				else {
					ans = i + 1;
					break;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9616
#include <cstdio>

using namespace std;

int findLast(int n, int k)
{
	if (n == 1) return (0);
	return ((findLast(n - 1, k) + k) % n);
}

int main()
{
	int n, k;
	
	while (scanf("%d %d", &n, &k), n)
	    printf("%d\n", findLast(n, k) + 1);
    return (0);
}

Measured memory_bytes: 1056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int main() {
  // reverseはひっくり返して変数にいれることができないので
  // コピーをつくってやることで対処した
  string s;
  cin >> s;
  int n = s.size();
  bool can = true;
  string rs1,rs2,rs3;
  string s2 = s.substr(0,(n-1)/2);
  // cout << s2 << endl;
  string s3 = s.substr((n+3)/2-1,n-1);
  // cout << s3 << endl;
  rs1 = s;
  rs2 = s2;
  rs3 = s3;
  reverse(s.begin(),s.end());
  reverse(s2.begin(),s2.end());
  reverse(s3.begin(),s3.end());
  if(s!=rs1) can = false;
  if(s2!=rs2) can = false;
  if(s3!=rs3) can = false;
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3616
def resolve():
    numbers = int(input())
    number_list = list(map(int, input().split()))
    answer = 0
    num2 = sum(number_list)
    for num1 in number_list:
        num2 = num2 - num1
        answer += num1*num2
    print(answer%1000000007)
resolve()

Measured memory_bytes: 94276
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    ll n, d;
    cin >> n >> d;
    int cnt = 0;
    rep(i, n) {
        ll x, y;
        cin >> x >> y;
        if (x*x + y*y <= d*d) cnt++;
    }
    cout << cnt << endl;
}

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


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

//#include "All.h"

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

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

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

double A, B, H, M;

int main() {
    cin >> A >> B >> H >> M;
    double a = ((H + (M / 60)) / 12) * 2 * PI;
    double b = (H + (M / 60)) * 2 * PI;
    double C2 = A * A + B * B - 2 * A * B * cos(b - a);
    cout << setprecision(15) << sqrt(C2) << endl;
}

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

using namespace std;

#define INF 1000007
#define MOD 1000000007
#define int long long int
#define maxn 100
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)

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

int lcm(int a, int b) { return a / gcd(a, b) * b; }

int mpow(int N, int P, int M) //繰り返し自乗法
{
    if (P == 0)
        return 1;
    if (P % 2 == 0) {
        int t = mpow(N, P / 2, M);
        return t * t % M;
    }
    return N * mpow(N, P - 1, M) % M;
}

int counter(int x) //bit計算
{
    if (x == 0)
        return 0;
    return counter(x >> 1) + (x & 1);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

signed main() {
    int N, M;
    cin >> N >> M;
    int n = N * (N - 1) / 2;
    int m = M * (M - 1) / 2;
    cout << n + m << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a, b;
    cin >> a;
    cin >> b;
    if (a < b)
    	cout << "a < b\n";
    else if (a > b)
    	cout << "a > b\n";
    else if (a == b)
    	cout << "a == b\n";
    return 0;
}


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

int main() {
    ll N;
    cin >> N;
    vector<long double> p(N);
    for (ll i = 0; i < N; i++) {
        cin >> p[i];
    }

    vector<vector<long double>> dp(N + 1, vector<long double>(N + 1, 0));
    dp[0][0] = 1.0;
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < N; j++) {
            dp[i + 1][j + 1] += dp[i][j] * p[i];
            dp[i + 1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    long double ans = 0.0;
    for (ll i = N / 2 + 1; i <= N; i++) {
        ans += dp[N][i];
    }
    cout << fixed << setprecision(15) << ans << endl;
}

Measured memory_bytes: 141056
#include "stdio.h"

int D;

int r;

int result[10] = {};


int Algae(int n, int x){
  if(n == 0){
    return x;
  }
  return r * Algae(n -1, x) - D;

}

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

  scanf("%d", &D);

  scanf("%d", &x);

  for(int i = 1; i < 11; i++){
    printf("%d\n", Algae(i, x));
  }

  return 0;
}


Measured memory_bytes: 128