akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ld,ld> pd;
typedef vector<ll,ll> vll;
typedef pair<ll,ll> pll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	vi h(n);
	M00(i, n) cin >> h[i];
	vi DP(n);
	DP[0] = 0;
	DP[1] = abs(h[0] - h[1]);
	for(int i = 2; i < n; i++) {
		DP[i] = min(DP[i-2] + abs(h[i-2] - h[i]), DP[i-1] + abs(h[i-1] - h[i]));
	}
	finish(DP[n-1]);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

ll calc(ll T, int n, const vector<ll> &s, const vector<ll> &t)
{
    vector<ll> sum(n+1);
    rep(i,n) sum[i+1] = sum[i]+(t[i]-s[i]);

    ll ret = 0;

    rep(i,n)
    {
        ll F = s[i]+T;
        int idx = lower_bound(all(s),F)-s.begin()-1;

        ll x = sum[idx]-sum[i];
        if(idx<n)
        {
            if(s[idx]<F) x+=(min(F,t[idx])-s[idx]);
        }

        // printf(" %d %d , x= %lld\n", i,idx,x);
        ret = max(ret,x);
    }

    return ret;
}

int main()
{
    ll T;
    int n;
    cin >>T >>n;
    vector<ll> s(n),t(n);
    rep(i,n) cin >>s[i] >>t[i];

    ll ans = 0;
    ans = max(ans, calc(T,n,s,t));

    rep(i,n)
    {
        s[i] = -s[i];
        t[i] = -t[i];
        swap(s[i],t[i]);
    }
    reverse(all(s));
    reverse(all(t));

    // rep(i,n) printf(" %d: %d ~ %d\n", i,s[i],t[i]);
    ans = max(ans, calc(T,n,s,t));

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

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

int main()
{
    int n; cin>>n;
    vector<int> c(n-1), s(n-1), f(n-1);
    for(int i=0; i<n-1; ++i) cin>>c[i]>>s[i]>>f[i];

    vector<int> res(n);
    for(int i=0; i<n-1; ++i) {
        int t=s[i]+c[i];
        for(int j=i+1; j<n-1; ++j) {
            if (t<=s[j])
                t=s[j];
            else
                t=s[j]+(t-s[j]+f[j]-1)/f[j]*f[j];
            t+=c[j];
        }
        res[i]=t;
    }
    for(int e: res) cout<<e<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

//プロセスを表す構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    //全てのプロセスをキューに順番に追加する。
    for (int i=1; i<=n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;

    //シミュレーション
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t); //qまたは必要な時間u.tだけ処理を行う
        u.t -= c; //残りの必要時間を計算
        elaps += c; //経過時間を加算
        if (u.t > 0) enqueue(u); //処理が完了してなければキューに追加
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }

    return 0;
}


Measured memory_bytes: 12868
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  in sum=0;
  int n;
  cin>>n;
  in T;
  cin>>T;
  vector<long> t(n);
  rep(i,n)
    cin>>t.at(i);
  
  rep(i,n-1){
    sum-=max(T-(t.at(i+1)-t.at(i)),(in)0);
  }
  cout<<sum+n*T<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();

bool normalize(vector<ll> &basis, ll val) {
	const int n = basis.size();
	const int m = 60;

	rep(i, n) {
		ll cmax = basis[i], pos = i;
		rep(j, i + 1, n) if(chmax(cmax, basis[j])) pos = j;
		if(cmax == 0) break;
		swap(basis[i], basis[pos]);
		
		int col = m - 1;
		while(col >= 0 and (((basis[i] >> col) & 1) == 0)) col--;

		rep(j, i + 1, n) {
			if((basis[j] >> col) & 1) {
				basis[j] ^= basis[i];
			}
		}
		
		if((val >> col) & 1) {
			val ^= basis[i];
		}
	}

	return (val == 0LL);
}

int main(void){
	int t;
	cin >> t;
	rep(loop, t) {
		int n;
		cin >> n;

		vector<ll> a(n);
		rep(i, n) cin >> a[i];
		string s;
		cin >> s;
		
		int ans = 0;
		vector<ll> zero;

		rrep(i, n) {
			if(s[i] == '1') {
				if(normalize(zero, a[i]) == false) {
					ans = 1;
				}
			} else {
				zero.push_back(a[i]);
			}
		}
				
		cout << ans << endl;
	}
	return 0;
}

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

typedef pair<ll, int> P;
ll a[300000];

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

	int N;
	cin >> N;
	for(int i = 0; i < 3 * N; i++) {
		cin >> a[i];
	}

	set<P> s1, s2, nxt;
	ll sum1 = 0, sum2 = 0;
	for(int i = 0; i < N; i++) {
		s1.insert({ a[i], i });
		sum1 += a[i];
	}
	for(int i = N; i < 3 * N; i++) {
		s2.insert({ a[i], i });
		sum2 += a[i];
	}
	for(int i = 0; i < N; i++) {
		auto it = s2.end();
		--it;
		nxt.insert(*it);
		sum2 -= it->first;
		s2.erase(it);
	}

	ll ans = -1LL << 60;
	ans = max(ans, sum1 - sum2);
	for(int i = N; i < 2 * N; i++) {
		cerr << i << endl;
		ans = max(ans, sum1 - sum2);
		s1.insert({ a[i], i });
		sum1 += a[i];
		sum1 -= s1.begin()->first;
		s1.erase(s1.begin());
		if(s2.count({ a[i], i })) {
			s2.erase({ a[i], i });
			sum2 -= a[i];
			s2.insert(*nxt.begin());
			sum2 += nxt.begin()->first;
			nxt.erase(nxt.begin());
		}
		else {
			nxt.erase({ a[i], i });
		}
	}
	ans = max(ans, sum1 - sum2);

	cout << ans << endl;
}

Measured memory_bytes: 21376
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
#include <cstdlib>
#include <map>
#include <utility>
//using
using namespace std;
using vi = vector <int>;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vvc = vector<vector<char> >;
//vector<vector<char> > hyou(N, vector<char>(N));
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
 //各位の和　
int wa(ll x)
{
ll sum = 0;
while(x!=0){
  sum += x% 10;
  x /= 10;
}
return sum;
}
/*順列生成
do {
  // 順列に対する処理
} while (next_permutation(配列変数.begin(), 配列変数.end()));*/

//絶対値　abs()
//文字→数字　'0' アルファベット→数字　'a'　'A'が65番,'a'が97番だわ
//型キャスト　char('a'+1)
//reverse 回文
//if(isupper('A'))->大なら真


//グローバル変数宣言
ll p=0,q=0,r=0;

int main()
{
  ll n;
  cin>>n;
  vl a1(n),a2(n);
  rep(i,n)
  {
    cin>>a1[i];
    p+=a1[i];
  }
  rep(i,n)
  {
    cin>>a2[i];
  }

  for (int i = n-1; i >=0; i--)
  {
    q+=a2[i]-a1[i];
    r=max(q+a1[i],r);
  }

  print(p+r);
}

Measured memory_bytes: 3588
N = int(input())
S = input()

w = 0
b = 0
for i in range(len(S)):
    if S[i] == ".":
        w += 1

c = w
for i in range(len(S)):
    if S[i] == ".":
        w -=1
    else:
        b += 1
    if c > w + b:
        c = w + b
print(c)





Measured memory_bytes: 3500
n=int(input())
l=[]

for i in range(1,n+1):
  s,p=input().split()
  l.append([s,int(p),i])
  
l.sort(key=lambda x:x[1],reverse = True)
l.sort(key=lambda x:x[0])

for ll in l:
  print(ll[2])

Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
	while(1){
		long int sum = 0.0;
		double mean;
		double sigma2 = 0;
		int n, temp;
		cin >> n;
		if(n==0)
			break;
		int *data = new int[n]();

		for(int i=0; i<n; i++){
			cin >> temp;
			data[i] = temp;
		}

		for(int i=0; i<n; i++){
			sum += data[i];
		}
		mean = (float)sum / (float)n;

		for(int i=0; i<n; i++){
			sigma2 += pow(data[i]-mean, 2);
		}
		sigma2 /= (float)n;
		cout << fixed << setprecision(10) << sqrt(sigma2) << endl;
	}
	return 0;
}

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    long long int n;
    cin>>n;
    vector<long long int> a(n);
    REP(i,n) cin>>a[i];
    sort(a.begin(),a.end());
    vector<long long int> b;
    int c=1;
    REP(i,n-1){
        if(a[i]!=a[i+1]){
            if(c>1){
                if(c>3){
                    b.push_back(a[i]);
                    b.push_back(a[i]);
                  c=1;
                }else{
                b.push_back(a[i]);
                c=1;
                }
            }
        }else{
            c++;
        }
    }
    if(c>3){
        b.push_back(a[n-1]);
        b.push_back(a[n-1]);
    }else if(c>1){
        b.push_back(a[n-1]);
    }
    sort(b.begin(),b.end(),greater<int>());
    if(b.size()<2){
        cout<<0;
    }else{
        cout<<b[0]*b[1];
    }
    return 0;
}


Measured memory_bytes: 1660
#include <stdio.h>

#define MAX 10000

int main(void)
{
  char S[MAX];
  int N;
  int i=0;

  scanf("%d",&N);
  scanf("%s",S);

  while(S[i]!='\0'){
    if(S[i]+N<='Z')S[i] += N;
    else S[i] -= 26-N;
    i++;
  }
  printf("%s\n",S);

  return 0;
}




Measured memory_bytes: 128
A, B = map(int, input().split())

def check(x):
    a = int(x * 0.08)
    b = int(x * 0.10)
    if (a == A) and (b == B):
        return True
    else:
        return False

for i in range(1, 10000):
    if check(i):
        print (i)
        exit()
print (-1)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef signed long long sll;
sll a[200005];
sll h,k,i,ans;

int main(){
	cin>>h>>k;
	
	for(i=1;i<=h;i++)
	cin>>a[i];
	
	sort(a+1,a+h+1);
	for(i=1;i<=h-k;i++)
	ans+=a[i];
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  char S[51], T[51];
  cin >> S >> T;

  if(strlen(S)<strlen(T)) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  int pos = -1;
  FOR(i,0,strlen(S)-strlen(T)) {
    bool match=true;
    //cout << "----" << endl;                                                   
    for (int j=0;j<strlen(T);j++) {
      if (S[i+j]!='?' && S[i+j]!=T[j]) {
        match=false;
        //cout << "false:" << S[i+j] << " " << T[j] << endl;                    
      }
    }
    if(match) pos = i;
  }

  if(pos==-1) {
    cout << "UNRESTORABLE" << endl;
  }
  else{
    rep(i,strlen(S)){
      if(pos<=i &&  i<pos+strlen(T)) cout << T[i-pos];
      else if(S[i]=='?') cout << 'a';
      else cout << S[i];
    }
    cout << endl;
  }
  return 0;

}


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

using namespace std;

int main(int argc, char const *argv[])
{
  int n; cin >> n;
  vector<int> w(n);
  int sum=0;
  for(int i=0;i<n;++i) { 
    cin >> w[i]; sum+=w[i];
  }
  int s2 = sum, d = sum;
  for(int i=0;i<n;++i) {
    s2 -= w[i];
    d = min(d, max(s2*2-sum, sum-s2*2));
  }
  cout << d << endl;
  return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string S, T;
  map<char, vl> M;
  cin >> S >> T;
  ll SS = S.size();

  REP(i, SS) {
    if (M.find(S[i]) == M.end()) {
      vl A;
      A.push_back(i);
      M[S[i]] = A;
    } else {
      M[S[i]].push_back(i);
    }
  }
  // cout << M['c'].size() << endl;

  ll now = -1;
  bool ok = true;
  ll loop = 0;
  REP(i, T.size()) {
    if (M.find(T[i]) == M.end()) {
      ok = false;
      break;
    } else {
      ll a = upper_bound(ALL(M[T[i]]), now) - M[T[i]].begin();
      if (a >= 0 && a < M[T[i]].size()) {
        now = M[T[i]][a];
      } else {
        now = M[T[i]][0];
        loop++;
      }
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }
  cout << (loop * SS) + now + 1LL << endl;

  return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main() {
    ll N;
    cin >> N;
    vector <ll> A(N);
    for(ll i = 0; i < N; i++){
        cin >> A.at(i);
    }
    sort(A.begin() , A.end());
    ll P , Q;
    while(P < N){
        ll stag = A.at(P) , deer = 0;
        while(P < N && A.at(P) == stag){
            P++;
            deer++;
        }
        Q+=deer % 2;
    }
    cout << Q << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int wa(int n) {
int sum=0;
if (n<0) return 0;
while (n>0) {
sum += n%10;
n /= 10;
}
return sum;
}

int main(void){
	int n;
	cin >> n;
	//n=a+b
	//nの桁数をmとしたとき， m=(int)(log10(n)+1)
	//m-1=log10(n)
	//10^(m-1)=n

	//aがp_1*10^n+p_2*10^(n-1)+...
	//bがq_1*....とすると，
	//p_1+...+p_n+q_1+q_nの最小値を求める
	//Aが1から,BがN-Aからはじめて，全探索
	int a, b;
	//vector<int> arr(n);
	int arr[n];
	for(int i=1;i<n;i++){
		//a=i
		//b = n - i;

		//arr.push_back(wa(i) + wa(n-i));
		arr[i] = wa(i) + wa(n-i);
		//cout << wa(i) + wa(n-i) << endl;
		//cout << i << " " << n-i  << " " << wa(n-i) << endl;
	}
	//sort(arr.begin(),arr.end());
	sort(arr,arr+n);
	cout << arr[1] << endl;

	return 0;
}


Measured memory_bytes: 640
def f(n):
    if n%2 ==0:
        return n/2
    else:
        return 3*n+1

s = int(input())
a = [0] * 1
a[0] = s
ans = 1

for i in a:
    b = f(i)
    ans += 1
    if b in a:
        break
    a.append(b)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);

		int x[] = new int[5];

		for(int i = 0;i<5;i++) {
			x[i] = sc.nextInt();
		}

		for(int i = 0;i<5;i++) {
			if(x[i]==0) {
				System.out.println(i+1);
		}
		}

	}

}


Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;

int main(){
  int N, K;
  cin >> N >> K;
  int x[N];
  for(int i = 0; i < N; i++){
    cin >> x[i];
  }
  int ans = INF;
  for(int i = 0; i <= N - K; i++){
    ans = min(ans, min(abs(x[i])+ abs(x[i+K-1]-x[i]), abs(x[i+K-1])+abs(x[i+K-1]-x[i])));
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
    int d = n/x;
    if(n%x!=0){
      d=d+1;
    }
    System.out.println(d*t);
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a[i];
  long double sum=0;
  for(int i=0; i<N; i++) sum+=(long double)1/a[i];
  long double ans=1/sum;
  cout << setprecision(10)<<ans<<endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A=[int(input()) for _ in range(M)]


#Sは階段を示す、0は壊れている
#0段目を仮置きする

S = [1] * (N+1)
for a in A:
    S[a] = 0

#i段目にたどり着く手は、i-1段目とi-2段目にたどり着く手の合計
#階段の値が0の場合は0のまま
for i in range(2,N+1):
    S[i] = (S[i-1] + S[i-2]) * S[i]

print(S[-1]%1000000007)


Measured memory_bytes: 462708
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int a, b;
    cin >> a >> b;
    
    int compare[2] = { a - b, a * b}, max = a + b;

    for (int count = 0; count < 2; count++){
        if (compare[count] > max){
            max = compare[count];
        }
    }
    cout << max << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n;
    cin>>n;
    ll i,a[n];ll aa[100000]={0};ll sum=0;
    for(i=0;i<n;i++)
   { cin>>a[i];sum+=a[i];aa[a[i]-1]++;}
    ll q;
    cin>>q;ll e;
    while(q--)
    {
        ll z,x;
        cin>>z>>x;
    if(aa[z-1]>0)
    {
        e=z*aa[z-1];
        sum-=e;
        sum+=x*aa[z-1];
        aa[x-1]+=aa[z-1];
        aa[z-1]=0;
    }
    cout<<sum<<endl;
    }
}

Measured memory_bytes: 5156
#include <stdio.h>
#include <string.h>
#define LENGTH 1000

int ctoi(char input)
{
  int i;
  i = input - '0';
  return i;
}

int main()
{
  char st[LENGTH] = {};
  char output_st[LENGTH] = {};
  int i = 0, j = 0, k = 0;

  for( k = 0 ; k < 50 ; k++ )
  {
    if( (scanf("%s", st)) != EOF )
    {
      i = 0;
      while( st[i] != '\0' )
      {
        if( st[i] == '@' )
        {
          i++;
          j = ctoi(st[i]);
          i++;
          for( ; j > 0 ; j-- )
            sprintf(output_st, "%s%c", output_st, st[i]);
        }

        else
          sprintf(output_st, "%s%c", output_st, st[i]);
        i++;
      }
      printf("%s\n", output_st);
      memset(output_st, '\0', LENGTH);
    }
    else
      return 0;
  }
}



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


#define ll long long
#define MOD 1000000007



int main(){
    int n,k;
    cin>>n>>k;

    vector<int> p(n);

    for(int i=0;i<n;i++)cin>>p.at(i);

    sort(p.begin(),p.end());


    int ans=0;
    for(int i=0;i<k;i++){
        ans += p.at(i);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

  int n,m;
  vector<int> p;

  int sum;

  
  while(cin >> n >> m) {

    if(n==0 && m==0) break;

    p.clear();

    for(int i=0;i<n;i++) {

      int temp;

      cin >> temp;

      p.push_back(temp);

    }

    sort(p.begin(),p.end(),greater<int>());

    //for(int i=0;i<(int)p.size();i++) cout << p[i] << " ";

    sum=0;

    for(int i=0;i<(int)p.size();i++) {

      if(i%m!=m-1) sum+=p[i];

    }

    cout << sum << endl;

  }

  return 0;

}

Measured memory_bytes: 0
fun main(args: Array<String>) {
    val mod = 1000000007
    fun pow(x: Long, y: Long): Long {
        if (y == 0L) {
            return 1L
        } else if (y % 2 == 0L) {
            val a = pow(x, y / 2)
            return a * a % mod
        } else {
            val a = pow(x, y / 2)
            return a * a % mod * x % mod
        }
    }

    fun div(x: Long, y: Long): Long {
        return x * pow(y, (mod - 2).toLong()) % mod
    }

    val (n, a, b, c) = readLine()!!.split(' ').map(String::toLong)
    val aPct = div(a, a + b)
    val bPct = div(b, a + b)

    var comb = 1L
    var ans = 0L
    for (i in 0 until n) {
        ans += pow(aPct, n) * pow(bPct, i) % mod * comb % mod * (n + i) % mod
        ans %= mod.toLong()
        ans += pow(bPct, n) * pow(aPct, i) % mod * comb % mod * (n + i) % mod
        ans %= mod.toLong()
        comb = div(comb * (n + i) % mod, (i + 1))
    }
    val l = div(a + b, 100)
    println(div(ans, l))
}


Measured memory_bytes: 40676
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	ts := getIntSlice(n)

	ans := 1
	for _, t := range ts {
		ans = lcm(ans, t)
	}
	fmt.Fprintln(wr, ans)
}

func lcm(a, b int) int {
	d := gcd(a, b)
	return a / d * b
}

func gcd(a, b int) int {
	if a%b == 0 {
		return b
	}
	return gcd(b, a%b)
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


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

//降順
int s_dsort(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(void) {

	long H;   //体力 10**9
	int  N,A[100000];
	int  i;

//入力
    scanf("%ld %d",&H,&N);
    for(i=0;i<N;i++)
	    scanf("%d",&A[i]);

//降順に並べる
	qsort((void*)A,N,sizeof(int),s_dsort);

//やっつける！
	for(i=0;i<N;i++) {
		if(H<=0) break;
		H-=A[i];
	}
	if(H>0) printf("No");
	else    printf("Yes");

	return 0;
}


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

using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;

    if (k <= a) { cout << k; return 0;}
    k -= a;
    sum += a;

    if (k <= b) { cout << sum; return 0;}
    k -= b;

    if (k <= c) { 
        cout << (sum - k);
    } else {
        cout << (sum - c);
    }
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N;
vector<ll> A(100001, 0);
vector<P> edge;

int main(void){
    
    scanf("%d", &N);
    for(int i = 0; i < N; ++i) scanf("%lld", &A[i]);
    sort(A.begin(), A.begin() + N, greater<ll>());
    
    ll num = 0;
    for(int i = 0; i < N; ++i){
        if(num != A[i]){
            num = A[i];
            edge.push_back(make_pair(num, 1));
        }
        else ++edge.back().second;    
    }
    
    for(int i = 0; i < edge.size(); ++i){
        if(edge[i].second >= 4) { printf("%lld\n", edge[i].first * edge[i].first); return 0; }
        if(edge[i].second < 2) continue;
        for(int j = i + 1; j < edge.size(); ++j) if(edge[j].second >= 2) { printf("%lld\n", edge[i].first * edge[j].first); return 0; }
    }
    printf("0\n");
    
    return 0;
}


Measured memory_bytes: 3188
#n = int(input())
#n,k = map(int,input().split())
#x = list(map(int,input().split()))





def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    
    cnt = 0
    for i in range(1,N):
        if A[i-1]==A[i]:
            cnt += 1
    
    if cnt%2==0:
        print(N-cnt)
    else:
        print(N-cnt-1)




if __name__ == "__main__":
    main()






Measured memory_bytes: 14396
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rrep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define maxe(x) *max_element(all(x))
#define mine(x) *min_element(all(x))
#define Size(x) ((int)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
long long MOD = 1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<class T> inline bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
    }
    template<class T> inline bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo,gyakugen
//mint,dijkstra

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll n,x;
        cin>>n>>x;
        cout<<n*x<<endl;
    }

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 || W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    System.out.printf("#");
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }

}


Measured memory_bytes: 62120
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<LL, LL> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(LL i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(LL i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const LL oo = 0x3f3f3f3f;
const LL maxn = 100000 + 10;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

LL ans = 0, Min = LLONG_MAX;
vector<pii> G[maxn];
LL sz[maxn];

LL n;
bool flag;
void dfs(LL u, LL f = 0) {
    sz[u] = 1;

    bool _flag = 1;
    for(LL i = 0; i < int(G[u].size()); ++i) {
        LL v = G[u][i].fst, w = G[u][i].snd;
        if(v == f) continue;
        dfs(v, u);
        if(sz[v] == n - sz[v]) flag = 1;
        ans += (2LL * min(sz[v], n - sz[v]) - ((sz[v] == n-sz[v]) ? 1 : 0)) * w; 
        sz[u] += sz[v];

        _flag &= (sz[v]*2 <= n);
    }
    _flag &= (2*(n-sz[u]) <= n);
    if(_flag) {
        for(int i = 0; i < int(G[u].size()); ++i) {
            Min = min(Min, G[u][i].snd);
        }
    }
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
    
    cin >> n;
    for(LL i = 1; i < n; ++i) {
        LL a, b, c;
        cin >> a >> b >> c;
        G[a].pb(pii(b, c));
        G[b].pb(pii(a, c));
    }
    dfs(1);
    if(flag) printf("%lld\n", ans); 
    else printf("%lld\n", ans - Min);

    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <string>
#include <stddef.h>
#include <stack>
#include <queue>

using namespace std;


int main() {
	int n, m;
	int a[100][100];
	int b[100];
	int c[100];
	fill(c, c + 100, 0);
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			c[i] += a[i][j] * b[j];
		}

	}
	for (int i = 0; i < n; i++) {
		cout << c[i] << endl;
	}
	cin >> n;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
bool issq(int i) {
	int t  =(int)sqrt(i);
	return t*t == i;
}
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, d;
	cin >> n >> d;
	vector<vector<int>> adj(n, vector<int>(d));
	for(int i=0; i<n; i++) {
		for(int j=0; j<d; j++) {
			cin >> adj[i][j];
		}
	}
	int ans = 0;
	for(int i=0; i<n; i++) {
		for(int j=i+1; j<n; j++) {
			int ac = 0;
			for(int p=0; p<d; p++) {
				ac += abs(adj[i][p]-adj[j][p])*abs(adj[i][p]-adj[j][p]);
			}
			ans += issq(ac);
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
import fileinput


GROUPS = list(enumerate([{1,3,5,7,8,10,12}, {4,6,9,11}, {2}]))


def group(n):
    for i, g in GROUPS:
        if n in g:
            return i
    return -1


def algorithm(input_lines):
    x, y = [int(n) for n in input_lines[0]]
    return "Yes" if group(x) == group(y) else "No"


def run():
    out = algorithm([l.strip().split(" ") for l in fileinput.input()])
    print(out)


run()


Measured memory_bytes: 3188
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define wl(n) while(n--)
#define fl(i,a,b) for(i=a; i<b; i++)
#define rev(i,a,b) for(i=a; i>=b; i--)

#define si(n) scanf("%d", &n)
#define sll(l) scanf("%lld",&l)
#define ss(s) scanf("%s", s)
#define sc(c) scanf("%c", &c)
#define sd(f) scanf("%lf", &f)

#define pi(n) printf("%d\n", n)
#define pll(l) printf("%lld\n", l)
#define ps(s) printf("%s\n", s)
#define pc(c) printf("%c\n", c)
#define pd(f) printf("%lf\n", f)

#define debug(x) cout<<"\n#("<<x<<")#\n"
#define nline printf("\n")

#define mem(a,i) memset(a,i,sizeof(a))

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define PB push_back
#define SZ size
#define MP make_pair

const int MAX_LIMIT = 100005;

int arr[MAX_LIMIT];
int N;
int main()
{
	int i, j;

	cin >> N;

	fl(i,0,N)
	{
		cin >> arr[i];
		arr[i]--;
	}

	int ans = 0;

	fl(i,0,N)
	{
		int thisLikes = arr[i];
		int thatLikes = arr[arr[i]];
		if(thatLikes == i)
			ans++;
	}

	cout << ans / 2;


	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 640
//https://beta.atcoder.jp/contests/abc110/tasks/abc110_a
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<string> v( 3 );
    for( auto &x : v )
    {
        cin >> x;
    }
    int res{};
    for( int i = 0; i < 6; ++i )
    {
        res = max( res, stoi( v[ 0 ] ) + stoi( v[ 1 ] + v[ 2 ] ) );
        next_permutation( begin( v ), end( v ) );
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#include <algorithm>
#define CHAR_NUM 100

using namespace std;

int main(void) {
    char str[CHAR_NUM];
    int i;
    int sum = 0, count = 0;
    
    while(scanf("%s", str) != EOF) {
        int len = (int)strlen(str);
        for(i = len - 1; i >= 0; i--) {
            if(isdigit(str[i]))
                sum += pow(10, (count++)) * ((int)str[i] - '0');
            else
                count = 0;
        }
        count = 0;
    }
    
    cout << sum << endl;
    
    return(0);
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

    int n;
    cin >> n;
    vector<double> v(n);
    rep(i, n) { cin >> v[i]; }
    sort(all(v));

    int k = n;
    while (k > 1) {
        double m = (v[0] + v[1]) / 2;
        v.erase(v.begin() + 1);
        v.erase(v.begin());
        v.push_back(m);
        sort(all(v));
        k--;
    }

    cout << v[0] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 998244353;

struct bracket{
    ll open,close;
    bool operator<(const bracket& rhs) const{
        return open-close > rhs.open-rhs.close;
    }
};

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n;
    cin >> n;
    vector <string> arr(n);
    for (int z=0;z<n;z++){
        cin >> arr[z];
    }
    vector <bracket> lol;
    ll open = 0;
    ll close = 0;
    for (int z=0;z<n;z++){
        ll open1 = 0;
        ll close1 = 0;
        for (int x=0;x<arr[z].size();x++){
            if (arr[z][x] == '(') open1++;
            if (arr[z][x] == ')') {
                if (open1 == 0) close1++;
                else open1--;
            }
        }
        ll open2 = 0;
        ll close2 = 0;
        for (int x=arr[z].size()-1;x>=0;x--){
            if (arr[z][x] == ')') close2++;
            if (arr[z][x] == '('){
                if (close2 == 0) open2++;
                else close2--;
            }
        }
        if (close1 == 0 && open2 == 0) continue;
        else if (close1 == 0){
            open += open2;
        }
        else if (open2 == 0){
            close += close1;
        } else {
            bracket temp;
            temp.open = open2;
            temp.close = close1;
            lol.push_back(temp);
        }
    }
    sort(lol.begin(),lol.end());
    bool ok = true;
    for (int z=0;z<lol.size() && ok;z++){
        open -= lol[z].close;
        if (open < 0) ok = false;
        open += lol[z].open;
    }
    if (open-close != 0) ok = false;
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
} 


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

int main() {
  
  double x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
  
  cout << fixed << setprecision(10);
  
  cout << sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2)) << endl;
  
}


Measured memory_bytes: 3296
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int x1,x2,x3,x4,y1,y2,y3,y4;
  scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  x4=x1+y1-y2;
  y4=y1+x2-x1;
  x3=x4+x2-x1;
  y3=y4+y2-y1;
  printf("%d %d %d %d\n",x3,y3,x4,y4);
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#define ll long long
#define inf 1000000000
#define mod 1000000007
#define eps 1e-10
#define N 200005
#define rep(i, l, r) for(int i=l; i<r; ++i)
const double pi=acos(-1.0);

using namespace std;
int t;
int n, k;
int a[N];
int main(){
	scanf("%d%d", &n, &k);
	rep(i, 1, n+1) scanf("%d", &a[i]);
	int l=1, r=inf;
	while(l<r){
		int mid=(l+r)/2;
		ll sum=0;
		rep(i, 1, n+1) sum+=(a[i]-1)/mid;
		if(sum>k) l=mid+1;
		else r=mid;
	}
	printf("%d", l);
	return 0;
}

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

int a, b;

int main(void){
	cin >> a >> b;
	int ans = 0;
	for(int i = a; i <= b; i++){
		string s1, s2;
		s1 = to_string(i);
		s2 = s1;
		reverse(s2.begin(), s2.end());
		if(s1 == s2) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3696
def main():
  import sys
  input = sys.stdin.readline
  n = int(input())
  s = list(input())

  def segfunc(x,y):
      return x|y

  def init(init_val):
      #set_val
      for i in range(n):
          seg[i+num-1]=init_val[i]    
      #built
      for i in range(num-2,-1,-1) :
          seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
      
  def update(k,x):
      k += num-1
      seg[k] = x
      while k:
          k = (k-1)//2
          seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
      
  def query(p,q):
      if q<=p:
          return ide_ele
      p += num-1
      q += num-2
      res=ide_ele
      while q-p>1:
          if p&1 == 0:
              res = segfunc(res,seg[p])
          if q&1 == 1:
              res = segfunc(res,seg[q])
              q -= 1
          p = p//2
          q = (q-1)//2
      if p == q:
          res = segfunc(res,seg[p])
      else:
          res = segfunc(segfunc(res,seg[p]),seg[q])
      return res

  #####単位元######
  ide_ele = 0

  #num:n以上の最小の2のべき乗
  num =2**(n-1).bit_length()
  seg=[ide_ele]*2*num

  A = []
  for i in range(n):
    A.append(1<<(ord(s[i])-96))
  init(A)
  q = int(input())
  for _ in range(q):
    p,a,b = input().split()
    if p == "1":
      update(int(a)-1,1<<(ord(b)-96))
    if p == "2":
      print(bin(query(int(a)-1,int(b))).count("1"))
main()

Measured memory_bytes: 110472
#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,m,tmp,ans;
vector<int>a;
int main()
{
	scanf("%d%d",&n,&m);
	for(reg int i=1;i<=n;i++)scanf("%d",&tmp),a.push_back(tmp);
	sort(a.begin(),a.end());
	for(reg int i=n-1;i>=n-m;i--)ans+=a[i];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main 
{
    
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        
        Double radius = sc.nextDouble();
        
        Double R = radius * radius * Math.PI;
        Double D = 2 * Math.PI * radius;
        
        System.out.println(String.format("%.6f",R) + " " + String.format("%.6f",D));
        
    }
}


Measured memory_bytes: 28284
open System
let R T = stdin.ReadLine()|> T
let RS T = stdin.ReadLine().Split()|>Array.map T
let Mod = (1e9|>int64)+7L
[<EntryPoint>]
let main argv =
    let rec gcd a b = if a%b=0L then b else (gcd b (a%b))
    let A,B = RS int64|>fun c -> c.[0],c.[1]
    A*B/(gcd A B)
    |>stdout.WriteLine
    0


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

const long long int MOD = 1e9 + 7;

long long int dfs(const int &K, const vector<vector<int>> &graph, const int &now, const int &from){

    int can_use_color_num;
    if(from == -1){
        can_use_color_num = K - 1;
    }else{
        can_use_color_num = K - 2;
    }

    if(K < graph[now].size()){
        return 0;
    }else{
        long long int case_num = 1;
        //現在地から子の方向に繋がっているnodeの数を積の形で数えてる
        for(auto e: graph[now]){
            if(e == from) continue;

            case_num *= can_use_color_num;
            can_use_color_num--;
            case_num %= MOD;
        }
        //dfsでさらに深く潜る
        for(auto e: graph[now]){
            if(e == from) continue;
            case_num *= dfs(K, graph, e, now);
            case_num %= MOD;
        }
        return case_num;
    }
}

int main(){
    int N, K; cin >> N >> K;

    vector<vector<int>> graph(N);
    for(int i = 0; i < N - 1; i++){
        int a, b; cin >> a >> b;a--, b--;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    long long int answer = K * dfs(K, graph, 0, -1);
    answer %= MOD;
    cout << answer << endl;
    return 0;
}


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

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N, K; cin >> N >> K;
    vector<bool> ngFlags(N, true);
    for (int i = 0; i < K; ++i)
    {
        int di; cin >> di;
        for (int j = 0; j < di; ++j)
        {
            int Aij; cin >> Aij; --Aij;
            ngFlags[Aij] = false;
        }
    }
    cout << count(ngFlags.begin(), ngFlags.end(), true) << endl;
}


Measured memory_bytes: 3596
#include"bits/stdc++.h"
using namespace std;

long gcd(long x, long y)
{
    if (y == 0) {
        return x;
    }
    else {
        return gcd(y, x % y);
    }
}

int main()
{
    long A, B = 0;
    cin >> A >> B;

    cout << A * B / gcd(A, B) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdexcept>
#include <algorithm>
#include <vector>
#include <functional>
#include <time.h>
#include <math.h>

using namespace std;


int main() {

	string s;
	cin >> s;

	if (s == "SUN") {
		cout << 7;
	}
	else if (s == "MON") {
		cout << 6;
	}
	else if (s == "TUE") {
		cout << 5;
	}
	else if (s == "WED") {
		cout << 4;
	}
	else if (s == "THU") {
		cout << 3;
	}
	else if (s == "FRI") {
		cout << 2;
	}
	else if (s == "SAT") {
		cout << 1;
	}
	
	




	}



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

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    double total = 0;
    for(int i = 0; i < n; ++i){
        double x;
        string u;
        cin >> x;
        getline(cin, u);
        if(u.find("JPY") != string::npos){
            total += x;
        }else{
            total += x * 380000.0;
        }
    }
    printf("%.5f\n", total);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
void riffle(int n,int card[]);
void cut(int k,int n,int card[]);
int main(){
int n,m,k,i;
cin>>n>>m;
int card[n*2];
for(i=0;i<n*2;i++)card[i]=i+1;


for(i=0;i<m;i++){
cin>>k;
if(k!=0)cut(k,n,card);else riffle(n,card);
}
for(i=0;i<2*n;i++)cout<<card[i]<<endl;
return 0;
}
void cut(int k,int n,int card[]){
int a[n*2],b[n*2],i;
for(i=0;i<k;i++)a[i]=card[i];

for(i=k;i<2*n;i++)b[i-k]=card[i];

for(i=k;i<2*n;i++)card[i-k]=b[i-k];
for(i=0;i<k;i++)card[i+(2*n)-k]=a[i];
}
void riffle(int n,int card[]){
    int a[n],b[n],i,j=0;
for(i=0;i<n;i++)a[i]=card[i];
for(i=n;i<2*n;i++)b[i-n]=card[i];
for(i=0;i<n;i++){
    card[j]=a[i];
    card[j+1]=b[i];
    j+=2;
}
}

Measured memory_bytes: 3116
// https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_b

#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1e9 + 7)
#define LINF (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

// long gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// long lcm(long a, long b) { return a * b / gcd(a, b); }

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

    string s;
    cin >> s;
    int cnt = count(s.cbegin(), s.cend(), 'x');
    // 負けた回数が8以上ならNO
    if (cnt >= 8) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int K, N, i, AM;
	AM = 0;
	
	scanf("%d %d", &K, &N);

	int A[200000] = {};
	
	for(i = 1; i<=N; i++){
		scanf("%d", &A[i]);
	}
	
	for(i = 1; i<=N; i++){
		if(i == N){
			if(AM < (K-A[N])+A[1]) AM = (K-A[N])+A[1];
		}
		
		else if(AM < A[i+1] - A[i]) AM = A[i+1] - A[i];
	}
	
	printf("\n%d", K - AM);
	
	return 0;
}

Measured memory_bytes: 896