akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

struct Dice{
	int me[6];
	
	void Init(int a[6]){
		for (int i = 0; i < 6; i++){
			me[i] = a[i];
		}
	}

	bool check(Dice d2){
		for (int i = 0; i < 6; i++){
			if (d2.me[i] != me[i])return false;
		}
		return true;
	}

	void print(){
		for (int i = 0; i < 6; i++){
			cout << me[i] << " ";
		}
		cout << endl;
	}
};

int a[6], q, n;
Dice d[110];

int main(){
	cin >> n;
	REP(i, n){
		REP(j, 6)cin >> a[j];
		d[i].Init(a);
	}
	bool f = 0;
	REP(k, n){
		FOR(l, k + 1, n){
			REP(i, 4){
				REP(j, 4){
					if (d[k].check(d[l]))f = 1;
					swap(d[k].me[1], d[k].me[2]);
					swap(d[k].me[2], d[k].me[4]);
					swap(d[k].me[4], d[k].me[3]);
				}
				REP(j, 4){
					if (d[k].check(d[l]))f = 1;
					swap(d[k].me[0], d[k].me[1]);
					swap(d[k].me[1], d[k].me[5]);
					swap(d[k].me[5], d[k].me[4]);
				}
				swap(d[k].me[0], d[k].me[2]);
				swap(d[k].me[2], d[k].me[5]);
				swap(d[k].me[5], d[k].me[3]);
			}
		}
	}
	if (!f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1156
n=int(input())
a=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(a[1]-a[0])
for i in range(2,n):
  dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]))
print(dp[n-1])


Measured memory_bytes: 13928
n, k = map(int, input().split())
W = [int(input()) for i in range(n)]

left = max(W)-1; right = sum(W)
while left+1 < right:
    mid = (left + right) // 2
    cnt = 1; cur = 0
    for w in W:
        if mid < cur + w:
            cur = w
            cnt += 1
        else:
            cur += w
    if cnt <= k:
        right = mid
    else:
        left = mid
print(right)

Measured memory_bytes: 11624
import bisect

while True:
    n,m = map(int,input().split())
    if [n,m] == [0,0]:
        break
    
    a = list(map(int,input().split()))
    a.sort()
    res = -1
    
    for i in range(n):
        k = bisect.bisect_right(a,m-a[i])
        if k == i+1:
            k -= 1
        if k != 0:
            res = max(res,a[i]+a[k-1])
    if res == -1:
        print('NONE')
    else:
        print(res)


Measured memory_bytes: 5668
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

int main(){
	int n, k; cin >> n >> k;
	vector<int> p(n);
	for( auto &e : p ) cin >> e;
	vector<int> sum(n);
	sum[0] = 0;
	for( int i = 0; i < n-1; ++i ){
		int diff;
		if( p[i] < p[i+1] ) diff = 1;
		else diff = -1;
		sum[i+1] = sum[i] + diff;
	}
	/*
	for( int l = 0; l+k-1 < n; ++l ){
		if( s[l+k-1]-s[l] == k-1 ){
			cout << "croissant" << endl;
		} else {
			cout << "décroissant" << endl;
		}
	}
	*/
	bool gcrssnt = false;
	set<int> s;
	int cnt = 1;
	for( int i = 0; i < k; ++i ) s.insert(p[i]);
	if( sum[k-1]-sum[0] == k-1 ) gcrssnt = true;
	for( int l = 1; l+k-1 < n; ++l ){
		bool crssnt = false;
		bool anders = false;
		if(  sum[l+k-1]-sum[l] == k-1 ) crssnt = true;
		int m = *(s.begin());
		s.erase(p[l-1]);
		if( *(s.begin()) == m ) anders = true;
		int M = *(s.rbegin());
		s.insert(p[l+k-1]);
		if( *(s.rbegin()) == M ) anders = true;
		if( ( anders && !crssnt ) || ( anders && ( crssnt && !gcrssnt ) ) ){
			++cnt;
		}
		if( crssnt && !gcrssnt) gcrssnt = true;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 11136
#include <algorithm>
#include <vector>
#include <cmath>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#include <iostream>
#include <set>

using namespace std;

int main() {

    string S;
    cin >> S;
    int n = S.length();

    int m = 753 - 111;

    for (int i = 0; i <= n - 3; i++) {
        int x = stoi(S.substr(i, 3));
        m = min(m, abs(x - 753));
    }

    cout << m << "\n";

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define INF 100000000
#define MOD 100000007
int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if(b%a==0){
        cout<<a+b<<endl;
    }else{
        cout<<b-a<<endl;
    }
   return 0;
}

Measured memory_bytes: 256
import sys
from collections import Counter, deque, defaultdict
from math import factorial
import heapq, bisect
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))

n = INT()
a = LIST()

b = [0]*n
b[0] = a[0]
for i in range(1,n):
    b[i] = a[i] - b[i-1]
c = [0]*(n-1)
for i in range(n-1):
    c[i] = b[i]*2 + ((-1)**(i+1))*b[n-1]

print(str(b[n-1]) + " ",end = "")
for i in range(n-1):
    print(str(c[i]) + " ", end = "")

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector<int> data;
	int N,K;	cin>>N>>K;
	int P;
	FOR(i,0,N){
		cin>>P;
		data.push_back(P);
	}
	sort(range(data));
	cout<<accumulate(data.begin(), data.begin()+K, 0)<<endl;

    return 0;
}




Measured memory_bytes: 3636
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

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

	long long ans = 0;
	for (long long i = 1; i*i < n; i++) {
		if ((n - i) % i == 0) {
			if ((n - i) / i > i)
				ans += (n - i) / i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N,M;
ll A[300][300];
ll c[300];
bool f[300];

int main(){
    cin >> N >> M;
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin >> A[i][j];
            A[i][j]--;
        }
    }
    for(int i=0;i<M;i++) f[i] = true;
    ll min_q = 1e9;
    for(int i=0;i<M;i++){
        for(int j=0;j<M;j++) c[j] = 0;
        for(int n=0;n<N;n++){
            for(int m=0;m<M;m++){
                if(f[A[n][m]]){
                    c[A[n][m]]++;
                    break;
                }
            }
        }
        ll q = 0;
        ll arg_q = -1;
        for(int m=0;m<M;m++){
            if(q < c[m]){
                q = c[m];
                arg_q = m;
            }
        }
        min_q = min(min_q, q);
        f[arg_q] = false;
    }
    cout << min_q << endl;
    return 0;
}

Measured memory_bytes: 896
N = int(input())
A = list(map(int,input().split()))
ans = []
mx = max(A)
mn = min(A)
ans = []
if abs(mx) > abs(mn):
    for i in range(1, N+1):
        ans += [[A.index(mx)+1, i]]
    for i in range(1, N):
        ans += [[i, i+1]]
else:
    for i in range(1, N+1):
        ans += [[A.index(mn)+1, i]]
    for i in range(N, 1, -1):
        ans += [[i, i-1]]
 
print(len(ans))
for x, y in ans:
    print(x, y)

Measured memory_bytes: 62240
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

ll calc(ll k,ll num){
  if(k == 0){
    return num;
  }
  ll cnt = 0;
  ll piv = k;
  while(piv != 0){
    if(piv & 1){
      cnt++;
    }
    piv = piv / 2;
  }
  return calc(k % cnt,num+1);
}

int main(){
  ll n;
  string x;
  cin >> n;
  cin >> x;
  ll cnt = 0;
  vector<ll> vec1(n+1,0);
  vector<ll> vec2(n+1,0);
  rep(i,n){
    if(x[i] == '1'){
      cnt++;
    }
  }
  ll sum1 = 0;
  ll sum2 = 0;
  ll p1 = cnt+1;
  ll p2 = cnt-1;
  vec1[0] = 1;
  vec2[0] = 1;
  rep(i,n){
    vec1[i+1] = vec1[i] * 2 % p1;
    if(x[n-i-1] == '1'){
      sum1 += vec1[i];
      sum1 %= p1;
    }
  }
  if(p2 != 0){
    rep(i,n){
      vec2[i+1] = vec2[i] * 2 % p2;
      if(x[n-i-1] == '1'){
        sum2 += vec2[i];
        sum2 %= p2;
      }
    }
  }
  rep(i,n){
    ll ans;
    if(x[i] == '1'){
      if(p2 == 0){
        ans = 0;
      }else{
        t1 = sum2 - vec2[n-i-1] + p2;
        t1 = t1 % p2;
        ans = calc(t1,1);
      }
    }else{
      //cout << sum1 << " " << vec1[n-i-1] << " " << p1 << endl;
      t1 = sum1 + vec1[n-i-1];
      t1 %= p1;
      ans = calc(t1,1);
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 6824
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
using namespace std;
int n,k,ans;
int main(){
	scanf("%d%d",&n,&k);
	ans=1;
	for(int i=1;i<=n;i++) ans+=min(ans,k);
	printf("%d\n",ans);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
static const int NIL = -1;
static const int NumberChild = 2;
class Tree {
private:
	int id;
	int parent;
	int child[NumberChild];

public:
	Tree() {
		id = child[0] = child[1] = parent = NIL;
	}
	void AddParent(int ID) {
		parent = ID;
		return;
	}
	void AddID(int ID) {
		id = ID;
		return;
	}
	void AddChild(std::vector<int>&Child) {
		for (unsigned int i = 0; i < Child.size(); ++i) {
			child[i] = Child[i];

		}

		return;
	}
	int GetRoot(std::vector<Tree> nodes, int ID) {
		int RootID = ID;
		if (RootID != NIL&&nodes[RootID].parent != NIL) {
			RootID=GetRoot(nodes, nodes[RootID].parent);
		}
		return RootID;
	}
	void PreorderTreeWalk(std::vector<Tree> nodes, int ID) {
		if (ID != NIL) {
			std::cout << " " << ID;
			PreorderTreeWalk(nodes, nodes[ID].child[0]);
			PreorderTreeWalk(nodes, nodes[ID].child[1]);
		}

		return;
	}
	void InorderTreeWalk(std::vector<Tree> nodes, int ID) {
		if (ID != NIL) {
			InorderTreeWalk(nodes, nodes[ID].child[0]);
			std::cout << " " << ID;
			InorderTreeWalk(nodes, nodes[ID].child[1]);
		}

		return;
	}
	void PostorderTreeWalk(std::vector<Tree> nodes, int ID) {
		if (ID != NIL) {

			PostorderTreeWalk(nodes, nodes[ID].child[0]);
			PostorderTreeWalk(nodes, nodes[ID].child[1]);
			std::cout << " " << ID;
		}

		return;
	}
};
int main(void) {
	int n;
	std::cin >> n;
	std::vector<Tree>nodes(n);
	int ID;
	std::vector<int> child(NumberChild);
	for (int i = 0; i < n; ++i) {
		std::cin >> ID;
		nodes[ID].AddID(ID);
		for (int i = 0; i < 2; ++i) {
			std::cin >> child[i];
			if (child[i] != NIL) {
				nodes[child[i]].AddParent(ID);
			}
		}
		nodes[ID].AddChild(child);

	}
	int ROOTID = nodes[0].GetRoot(nodes, 0);
	std::cout << "Preorder\n";
	nodes[0].PreorderTreeWalk(nodes, ROOTID);
	std::cout << "\nInorder\n";
	nodes[0].InorderTreeWalk(nodes, ROOTID);
	std::cout << "\nPostorder\n";
	nodes[0].PostorderTreeWalk(nodes, ROOTID);
	std::cout << "\n";
	//system("pause");
	return 0;
}

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

int const MAX = 200005;

long long a[MAX];

int main() {
	long long n;
	cin >> n;
	for (long long i = 1; i <= n; i++) {
		long long x;
		cin >> x;
		a[i] = x - i;
	}
	sort(a + 1, a + n + 1);
	int p;
	if (n % 2 == 0) {
		p = n / 2;
	}
	else {
		p = n / 2 + 1;
	}
	long long cnt = 0;
	for (int i = 1; i <= n; i++) {
		cnt += abs(a[i] - a[p]);
	}
	cout << cnt << endl;

	/*
	long long cnt=0;
	for (int i = 1; i <= n; i++) {
		cnt += a[i];
	}
	cnt /= n;
	long long ans1,ans2,ans3;
	ans1 = ans2 = ans3 = 0;
	for (int i = 1; i <= n; i++) {
		ans1 += abs(a[i] - cnt);
	}for (int i = 1; i <= n; i++) {
		ans2 += abs(a[i] - cnt - 1);
	}for (int i = 1; i <= n; i++) {
		ans3 += abs(a[i] - cnt + 1);
	}
	cout << min(ans3,min(ans1, ans2)) << endl;
	*/
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
import sys


def solve(L: int, R: int, d: int):
    ans = 0
    for i in range(L, R+1):
        if i % d ==0 : ans+=1

    print(ans)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    solve(L, R, d)

if __name__ == '__main__':
    main()


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

int main(){
	int N,K;
	cin>>N>>K;
	int A[N];
	for(int i=0;i<N;++i){
		A[i]=0;
	}
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		A[tmp-1]++;
	}
	sort(A,A+N);
	int M=0;
	for(int i=0;i<N;++i){
		if(A[i]!=0)M++;
	}
	int ans=0;
	int i=0;
	int j=0;
	while(true){
		if(A[j]!=0){
			ans+=A[j];
			i++;
		}
		j++;
		if (i>=M-K) break;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=4e5+10;
int wn[N],n;
long long ans;
int main()
{
	scanf("%d",&n);
	for (int nn=n;nn;nn/=10) wn[0]++;
	for (int j=wn[0],nn=n;j>0;nn/=10,j--) wn[j]=nn%10;
	for (int i=3;i<wn[0];i++) wn[2]=wn[2]*10+wn[i];
	for (int i=1;i<=n;i++)
	{
		if (i%10==0) continue;
		int l=0,r=i%10,w=0,ii=i;
		while (ii) l=ii%10, ii/=10, w++;
		if (l==r&&r<=n) ans++;
		if (wn[0]>=2&&l+r*10<=n) ans++;
		if (wn[0]>=3)
		{
			int k=10;
			for (int j=1;j<wn[0]-2+(r<wn[1]);j++,k*=10) ans+=k;
			if (r!=wn[1]) continue;
			ans+=wn[2]+(l<=wn[wn[0]]);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 256
//#pragma warning(disable:4996)
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//#include <stdio.h>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
typedef long long LL;
typedef long double LD;
//typedef boost::multiprecision::cpp_int bigint;
typedef pair<LL, LL> PLL;
typedef pair<int, int> PI;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef unsigned long long ULL;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int A, B, C;
	cin >> A >> B >> C;
	int K;
	cin >> K;
	int t = 0;
	while (A >= B) {
		B *= 2;
		t++;
	}
	while (B >= C) {
		C *= 2;
		t++;
	}
	if (t <= K)cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

signed main(){

	lli k,s;
	cin>>k>>s;

	lli cnt=0;

	REP(x,0,k+1){
		REP(y,0,k+1){
			lli z = s - (x+y);
			if(0<=z && z <= k)cnt++;
		}
	}
	cout<<cnt<<endl;


	return 0;
}

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

int main() {
  int n; std::cin >> n;
  std::vector<int> cnt(3);
  for (int i = 0; i < n; i++) {
    int a; std::cin >> a;
    cnt[a - 1]++;
  }
  double dp[302][302][302];
  std::memset(dp, 0, sizeof(dp));
  auto func = [&](const auto &self, int a, int b, int c) {
    if (a < 0 || b < 0 || c < 0) return 0.;
    if (a == 0 && b == 0 && c == 0) return 0.;
    if (dp[a][b][c] != 0) return dp[a][b][c];
    double s = a + b + c;
    double ret = 0.;
    ret += a / s * self(self, a - 1, b, c);
    ret += b / s * self(self, a + 1, b - 1, c);
    ret += c / s * self(self, a, b + 1, c - 1);
    ret += n / s;
    return dp[a][b][c] = ret;
  };
  std::cout << std::fixed << std::setprecision(15)
    << func(func, cnt[0], cnt[1], cnt[2]) << std::endl;
  return 0;
}


Measured memory_bytes: 215552
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int n,a[100000]={},ans=0;
  bool up=false,down=false;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=0; i<n-1; i++) {
    if(a[i]==a[i+1]) {
      continue;
    }
    else if(a[i]<a[i+1]) {
      up=true;
    }
    else {
      down=true;
    }
    if(up&&down) {
      ans++;
      up=false,down=false;
    }
  }
  cout << ans+1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
	ll n, ans;
	cin >> n ;
	vector<ll> v(5,0);
	cin >> v[0];
	ll m = v[0];
	
	for (int i = 1;i < 5;++i){
		cin >> v[i];
		m = min(m,v[i]);
	}
	
	ans = 5 + n/m;
	if (n % m == 0){
		ans -= 1;
	}
	cout << ans << endl;
}

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

using namespace std;

using i32 = int32_t;
using u32 = uint32_t;
using f32 = float;
using f64 = double;
using i64 = int64_t; 
using u64 = uint64_t; 

#define SELECTER(_1, _2, _3, _4, _5, _6, _7, _8, SELECT, ...) SELECT

#define _FC1(func, type, _1)      func(type, _1) 
#define _FC2(func, type, _1, ...) func(type, _1); _FC1(func, type, __VA_ARGS__)
#define _FC3(func, type, _1, ...) func(type, _1); _FC2(func, type, __VA_ARGS__) 
#define _FC4(func, type, _1, ...) func(type, _1); _FC3(func, type, __VA_ARGS__)
#define _FC5(func, type, _1, ...) func(type, _1); _FC4(func, type, __VA_ARGS__)
#define _FC6(func, type, _1, ...) func(type, _1); _FC5(func, type, __VA_ARGS__)
#define _FC7(func, type, _1, ...) func(type, _1); _FC6(func, type, __VA_ARGS__)
#define _FC8(func, type, _1, ...) func(type, _1); _FC7(func, type, __VA_ARGS__)

#define _FCN(func, type, ...) SELECTER(__VA_ARGS__, _FC8, _FC7, _FC6, _FC5, _FC4, _FC3, _FC2, _FC1)(func, type, __VA_ARGS__)

constexpr const char *type2fmt(const char *fmt) {
  if(strcmp(fmt, "i32") == 0) return "%d";
  if(strcmp(fmt, "u32") == 0) return "%u";
  if(strcmp(fmt, "f32") == 0) return "%f";
  if(strcmp(fmt, "f64") == 0) return "%lf";
  if(strcmp(fmt, "i64") == 0) return "%lld";
  if(strcmp(fmt, "u64") == 0) return "%llu";
  return "";
}

#define _R(type, _1) type _1; { type _t; scanf(type2fmt(#type), &_t); _1 = _t; }
#define _P(type, _1) { const type _t = (_1); printf(type2fmt(#type), _t); putchar('\n'); }

#define RI(...)   _FCN(_R, i32, __VA_ARGS__)
#define RUI(...)  _FCN(_R, u32, __VA_ARGS__)
#define RF(...)   _FCN(_R, f32, __VA_ARGS__)
#define RD(...)   _FCN(_R, f64, __VA_ARGS__)
#define RLL(...)  _FCN(_R, i64, __VA_ARGS__)
#define RULL(...) _FCN(_R, u64, __VA_ARGS__)

#define PI(...)   _FCN(_P, i32, __VA_ARGS__)
#define PUI(...)  _FCN(_P, u32, __VA_ARGS__)
#define PF(...)   _FCN(_P, f32, __VA_ARGS__)
#define PD(...)   _FCN(_P, f64, __VA_ARGS__)
#define PLL(...)  _FCN(_P, i64, __VA_ARGS__)
#define PULL(...) _FCN(_P, u64, __VA_ARGS__)

#define REP(n) for (int _i = 0; _i < n; _i++)

const u64 mod = 1000000007;

int main() {
  RULL(m);
  if (m == 1) {
     cout << "Hello World" << endl;
  }
  else if (m == 2) {
    RULL(A, B);
    PULL(A + B);   
  }
}


Measured memory_bytes: 256
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
 
#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    int res = n;
    vector<int> ans;
    while(res != 0){
        ans.push_back(abs(res % 2));
        if(res > 0){
            res /= (-2);
        }else{
            res = (abs(res) - 1) / 2 + 1;
        }
    }
    repr(i, ans.size()){
        cout << ans[i];
    }
    if(ans.size() == 0){
        cout << 0;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * Road to ROI
**/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define sc second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
const ll MOD=1e9+7;
const ll INF=1e10;
int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ll a,b;
 ll  n,w, mval=0;
    vector<pair<ll,ll>> v;
    cin>>n>>w;
    for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        mval+=b;
        v.pb(make_pair(a,b));
    }
    vector<ll> arr(mval+7,INF);
    arr[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=mval-v[i].sc;j>=0;j--)
        {
            arr[j+v[i].sc]=min(arr[j+v[i].sc],arr[j]+v[i].f);
        }
    }
    ll ans=0;
    for(int i=0;i<=mval;i++)
    {
        if(arr[i]<=w)
            ans=i;
    }
    cout<<ans;
    return 0;
  
}

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

int main(){
  int h, w;
  cin >> h >> w;
  
  vector<vector<char>> data(h+2, vector<char>(w+2));
  vector<vector<int>> data1(h+2, vector<int>(w+2));
  
  for (int i = 1; i < h+1; i++){
    for (int j = 1; j < w+1; j++){
      cin >> data.at(i).at(j);
      if (data.at(i).at(j) == '.')
        data1.at(i).at(j) = 0;
      
    }
  }
  
  for (int i = 1; i < h+1; i++){
    for (int j = 1; j < w+1; j++){
     
      if (data.at(i).at(j) == '#'){
        data1.at(i-1).at(j-1)++;
        data1.at(i-1).at(j)++;
        data1.at(i-1).at(j+1)++;
        data1.at(i).at(j-1)++;
        data1.at(i).at(j+1)++;
        data1.at(i+1).at(j-1)++;
        data1.at(i+1).at(j)++;
        data1.at(i+1).at(j+1)++;
      }
    }
  }
  for (int i = 1; i < h+1; i++){
    for (int j = 1; j < w+1; j++){
      if (data.at(i).at(j) == '#')
        cout << '#';
      else
        cout << data1.at(i).at(j);
      
    }
    cout << endl;
  }
  
}

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

using namespace std;

int main(){
	int n;
	cin >> n;
	
	vector<int> a;
	for(int i = 0;i < n;i++){
		int ta;
		cin >> ta;
		a.push_back(ta);
	}
	
	sort(a.begin(),a.end());
	
	int bign = a[a.size() - 1];
	
	int smalln = 0;
	for(int i = 0;i < n;i++){
		if(abs(bign - a[i] * 2) < abs(bign - smalln * 2)){
			smalln = a[i];
		}
	}
	
	cout << bign << " " << smalln << endl;
	return 0;
}

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

#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
typedef long long ll;
using namespace std;
int N,D;
int main() {
	cin>>N>>D;
    if(N%((D*2)+1)!=0){
    	cout<<N/((D*2)+1)+1<<endl;
    }else{
    	cout<<N/((D*2)+1)<<endl;
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int solve(int x)
{
	if(x==1)return 1;
	return solve(x/2)*2+1;
}
signed main()
{
	int n,k,sum=0;
	scanf("%lld",&n);
	printf("%lld",solve(n));
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define rep(i,a,b) for(register int i=(a),i##_end=(b);i<=i##_end;++i)
#define per(i,a,b) for(register int i=(a),i##_st=(b);i>=i##_st;--i)
#define rpg(i,x) for(register int i=fir[x];i;i=e[i].nxt)
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define bin(i) (1<<i)
#define cls(x,y) memset(x,y,sizeof x)
typedef pair<int,int> pa;
typedef long long LL;
const int INF = 0x7fffffff;
const int oo = 0x3f3f3f3f;
/*const int _L = 1e6+5;
char ibuf[_L],*ih=ibuf+_L;
inline char gc(){return (ih==ibuf+_L?fread(ibuf,1,_L,stdin),ih=ibuf:0),*ih++;}
#define  getchar() gc() //*/
template <typename T>
inline void rd(T &x) {
    x = 0; int f = 1; char CH = getchar();
    while(!isdigit(CH)) {if(CH=='-')f=0;CH=getchar();}
    while(isdigit(CH)) {x=((x+(x<<2))<<1)+(CH-48);CH=getchar();}
    x=(f==1)?x:-x;  return;
}
const int MXN = 2e5 + 5;
int n,a[MXN],sum[MXN],Sum[MXN];
int main()
{
#ifdef iloi
//	   freopen("test.in","r",stdin);
#endif
	rd(n); rep(i,1,n) rd(a[i]),sum[i]=sum[i-1]+a[i],Sum[i]=Sum[i-1]^a[i];
	LL ans=0;
	int i=1,j=1;
	for(;j<=n;++j) {
		for(;((sum[j]-sum[i-1])!=(Sum[j]^Sum[i-1]));i++);
		ans+=j-i+1;
	}
	cout<<ans;
	
#ifdef iloi
	debug("\nMy Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;


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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0;j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0]-lost+c[0]*(i+1-last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j]-lost+c[j]*(i+1-last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
	#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    string s;
    cin>>s;
    string t=s;
    reverse(t.begin(),t.end());
    cout<<((s==t)?"Yes":"No");
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)


int main() {
    int n,m; cin >> n >> m;
    int a[50]={}; int b[50]={};
    rep(i,m) cin >> a[i] >> b[i];
    int cnt[51]={};
    rep(i, m){
        cnt[a[i]--]++;
        cnt[b[i]--]++;
    }
    for(int i=1;i<=n;i++){
        cout << cnt[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#define MAX_SIZE 1000
#define MAX_W 10000
#define MAX_N 100

using namespace std;
int N,W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_N + 1][MAX_W + 1];

void solve() {
  cin >> N >> W;
  for(int i = 0; i < N; i++) {
    cin >> v[i] >> w[i];
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < (W + 1); j++) {
      if(j < w[i]) {
        dp[i + 1][j] = dp[i][j];
      } else {
        dp[i + 1][j] = max(dp[i][j], dp[i + 1][j - w[i]] + v[i]);
      }
    }
  }
  printf("%d\n", dp[N][W]);
	return;
}

int main(int args, char* argv[]) {
	solve();
}



Measured memory_bytes: 7136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i))
#define mat(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define each(x,y) for(auto &(x):(y))
#define var(type, ...)type __VA_ARGS__;Scan(__VA_ARGS__);
template<typename T> void Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void Scan(First& first, Rest&...rest) { cin >> first; Scan(rest...); }
#define vec(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define em emplace
#define pb pop_back
#define fi first
#define se second
#define get(a, i) get<i>(a)
#define bit_count __builtin_popcount
#define mt make_tuple
inline string zero(int a,string s,char c='0'){return string(a-len(s),c)+s;}
inline string zero(int a,int t,char c='0'){return zero(a, to_string(t), c);}
inline string zero(int a,ll t,char c='0'){return zero(a, to_string(t), c);}
#define mini min_element
#define maxi max_element
#define sum accumulate
#define chmax(a,b) if(a<b)a=b
#define chmin(a,b) if(a>b)a=b
template <class T> inline void print(T t){cout << t << '\n';}
template <class H, class... T> inline void print(H h, T... t){cout << h << " ";print(t...);}
int main() {
	var(string, s);
	if (string(3, s[0]) >= s) {
		print(string(3, s[0]));
	} else {
		print(string(3, s[0] + 1));
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 123456789012


int main(){
    ll i,j;
    string s;
    cin>>s;
    if(s[0]=='S') cout<<"Cloudy"<<endl;
    else if(s[0]=='C') cout<<"Rainy"<<endl;
    else cout<<"Sunny"<<endl;

    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n, m, ans = 0;
    cin >> n >> m;
    vector<int> a(n);

    rep(i, m) {
        int k;
        cin >> k;
        rep(j, k) {
            int s;
            cin >> s;
            s--;
            a[s] |= 1 << i;
        }
    }

    int p = 0;
    rep(i, m) {
        int x;
        cin >> x;
        p |= x << i;
    }

    for(int b = 0; b < (1 << n); b++) {
        int t = 0;
        rep(i, n) {
            if(b >> i & 1) {
                t ^= a[i];
            }
        }

        if(t == p) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left #bisect_left(list, value)
#from fractions import gcd
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, M = map(int, input().split())
A = list(map(int, input().split()))

s = sum(A)
cnt = 0
for a in A:
    if a >= s/(4*M):
        cnt += 1

if cnt >= M:
    print('Yes')
else:
    print('No')





Measured memory_bytes: 3316
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
CB = []
for i in range(M):
    B, C = list(map(int, input().split()))
    CB.append([C, B])

A.sort()
A.reverse()
CB.sort()
CB.reverse()

ans = 0
a_index = 0
cb_index = 0
CB.append([0, 0])

while True:
    if A[a_index] >= CB[cb_index][0]:
        ans += A[a_index]
        a_index += 1
        N -= 1
        if N == 0:
            break
    else:
        if N <= CB[cb_index][1]:
            ans += CB[cb_index][0] * N
            break
        else:
            ans += CB[cb_index][0] * CB[cb_index][1]
            N -= CB[cb_index][1]
            cb_index += 1

print(ans)






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

a=[]
a.append(int(input()))
i=1
while True:
  b=f(a[-1])
  i+=1
  if b in a:
    print(i)
    break
  a.append(b)


Measured memory_bytes: 2940
N = int(input())
n = 11**5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)
print(min([i for i in primes if i >= N]))

Measured memory_bytes: 16360
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ll = long long;
using ii = pair <ll , ll>;
void in(ll &x);
const ll N = 3005;
ll n;
ll a[N], dp[N][N];

ll f(ll l , ll r) {
  if (l > r) return 0;
  ll &sol = dp[l][r];
  if (sol != -1) return sol;
  sol = a[l] - f(l + 1 , r);
  sol = max(sol , a[r] - f(l , r - 1));
  return sol;
}

int main() {
  in(n);
  for (ll i = 1 ; i <= n ; i++) {
    in(a[i]);
  }
  memset (dp , -1 , sizeof dp);
  printf("%lld\n" , f(1 , n));
  return 0;
}

void in(ll &x){
	bool neg = false;
	register ll c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 74404
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		
		if ( N % 500 <= A ) {
			System.out.println("Yes");
			
		} else {			
		System.out.println("No");

		}
	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;

#define rep(i, N)  for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back

template<typename T> 
void chmax(T &a, T b){ a = max(a, b); };
template<typename T> 
void chmin(T &a, T b){ a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const ll LINF = 10000000000000000;
const int MOD = 1000000007;
const int dx[9] = { 0, 1,  0, -1, 1,  1, -1, -1, 0};
const int dy[9] = { 1, 0, -1,  0, 1, -1, -1,  1, 0};
//--------------------------------------//
int N;

void solve(){
	int n = 1;
	while(n <= N)
		n *= 2;
	cout << n / 2 << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
 
using namespace std;
int main() {
    double n;
    cin >> n;
    
    cout << 2*n*3.14 << endl;
    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ll x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
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; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n, k;
    cin >> n >> k;
    vll x(n);
    rep(i, n){
        cin >> x[i];
    }
    ll ans = INF;
    rep(i, n-k+1){
        ll l = x[i+k-1] - x[i];
        chmin(ans, abs(x[i])+l);
        chmin(ans, abs(x[i+k-1])+l);
    }
    cout << ans << endl;
    return 0;
}

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

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

  ll n, k;
  cin >> n >> k;
  ll mod = n % k;
  ll modEdit = k - mod;
  cout << min(mod, modEdit) << endl;
  return 0;
}

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

using namespace std;


int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for(int i=0;i<N;i++) cin >> a[i];
    for(int i=0;i<N;i++) cin >> b[i];
    int res = 0;
    for(int digit=29;digit>=0;digit--){
        int h = 1<<(digit+1), l = 1<<(digit);
        for(int i=0;i<N;i++){
            a[i] %= h;
            b[i] %= h;
        }
        sort(b.begin(), b.end());
        long long num = 0;
        for(int i=0;i<N;i++){
            int add = 0;
            if(l - a[i] >= 0){
                add += lower_bound(b.begin(), b.end(), h-a[i])
                    - lower_bound(b.begin(), b.end(), l-a[i]);
            }else{
                add += lower_bound(b.begin(), b.end(), h-a[i])-b.begin();
                add += lower_bound(b.begin(), b.end(), h)-lower_bound(b.begin(),b.end(),h+l-a[i]);
            }
            num += add;
        }
        if(num & 1) res += l;
    }
    cout << res << endl;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++)  cin >> a[i];
    int q;
    cin >> q;
    int b, m, e;
    for(int i = 0; i < q; i++){
        cin >> b >> m >> e;
        rotate(a + b, a + m, a + e);
    }
    for(int i = 0; i < n; i++)  cout << a[i] << " \n"[i == n-1];
}



Measured memory_bytes: 3164
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var a = nextstr();
  return a.charCodeAt()-97>=0?"a":"A";
}

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

#define N 11

using namespace std;

struct food{
	string name;
	int w;
	int s;
};

void dfs(int n, const vector<food> &f, bool flag[N], vector<food> &now, double &bestG, vector<food> &ans){
	int sumwG_denom = 0;
	int sumwG_numer = 0;
	double nowG = 0;

	for(unsigned int i = 0; i < now.size(); ++i){
		int sumw = 0;
		sumwG_numer += (i+1)*now[i].w;
		sumwG_denom += now[i].w;
		for(unsigned int j = i + 1; j < now.size(); ++j){
			sumw += now[j].w;
		}
		if( sumw > now[i].s )
			return ;
	}
	if( sumwG_denom > 0 ){
		nowG = sumwG_numer / (double)sumwG_denom;
		
		
		/*if( now.size() == n ){
			cout << " ------------------ \n";
			for(unsigned int i = 0; i < now.size(); ++i){
				cout << now[i].name << endl;
			}
			cout << "BEST : " << bestG << " G: " << nowG << endl;
		}*/
		

		if( now.size() == n && nowG < bestG ){
			bestG = nowG;
			ans = now;
		}
	}
	
	for(unsigned int i = 0; i < f.size(); ++i){
		if( !flag[i] ){
			flag[i] = true;
			now.push_back( f[i] );
			dfs( n, f, flag, now, bestG, ans );
			now.erase( now.end() - 1 );
			flag[i] = false;
		}
	}
}

int main(){
	while(true){
		int n;
		double bestG = 1000000;
		bool flag[N] = {false,};
		vector< food > vfoods, init, ans;
		
		cin>>n;
		if(n==0)break;
		for(int i = 0; i < n; ++i){
			food f;
			cin>>f.name>>f.w>>f.s;
			vfoods.push_back( f );
		}
		dfs( n, vfoods, flag, init, bestG, ans );
		for(unsigned int i = 0; i < ans.size(); ++i){
			cout << ans[i].name << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 920
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	ArrayList<Vertex> undiscovered = new ArrayList<>(); // What we haven't searched yet. 
	ArrayList<Vertex> vertices = new ArrayList<>(); // We will use this to access the time values at the end
	int time = 1;	
	
	public static void main(String[] args) {
			
		Main test = new Main();
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		// Initialize the vertices for the specified number of vertices. (Neighbors are not set yet)
		for (int i = 0; i < n; i++) {
			Vertex v = new Vertex(i + 1);
			test.undiscovered.add(v);
			test.vertices.add(v);
		}
		
		// Now we will initialize the neighbors by reading through our input lines
		for (int i = 0; i < n; i++) {
			String[] holder = in.nextLine().split(" ");
			Vertex v = test.undiscovered.get(Integer.parseInt(holder[0]) - 1);
			for (int j = 2; j < holder.length; j++) {
				Vertex neighbor = test.undiscovered.get(Integer.parseInt(holder[j]) - 1);
				v.addNeighbor(neighbor);
			}
		}
		for (Vertex v : test.vertices) {
			test.depthFS(v);
		}		
		for (Vertex v : test.vertices) {
			System.out.println(v.value + " " + v.dv + " " + v.df);
		}
		
		
	}
	
	public void depthFS(Vertex curr) {
		
		// We start by making sure that we still have undiscovered nodes
		if (undiscovered.isEmpty()) {
			return; // If it's empty, then we are done
		}
		
		// Now we check to make sure we haven't already seen the current node. ie. If it's not in undiscovered, we break
		if (curr.disc) {
			return; // We've already seen the node, so we break
		}

		// This node has been discovered now
		this.undiscovered.remove(curr);
		curr.disc = true;
		
		// Now we set the discovery value of the current node to our current time
		curr.dv = time;
		time += 1;
		// Now we are going to expand curr and go through its children
		for (Vertex child : curr.neighbors) {
			this.depthFS(child);
		}		
		curr.df = time;
		time += 1;
	}
	
	
}

class Vertex {
	public ArrayList<Vertex> neighbors = new ArrayList<>();
	public int value;
	public int dv;
	public int df;
	public boolean disc;
	
	public Vertex(int val) {
		value = val;
		disc = false;
	}
	
	public void addNeighbor (Vertex n) {
		neighbors.add(n);
	}
	
	public String toString() {
		return "" + this.value + " " + this.dv + " " + this.df;
	}
}



Measured memory_bytes: 26636
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

typedef pair<int, int>   Point;
typedef pair<int, Point> State;

int field[10][10];
int dx[] = {-2, -2, -2, -1, 0, 1, 2, 2,  2,  1,  0, -1};
int dy[] = {-1, -0,  1,  2, 2, 2, 1, 0, -1, -2, -2, -2};
vector<Point> waters;

bool in_field(int x, int y)
{
    return (x >= 0 && x < 10 && y >= 0 && y < 10);
}

bool check(int x, int y, int step) 
{
    if (in_field(x, y)) {
        int lx = abs(waters[step].first - x);
        int ly = abs(waters[step].second - y);
        return (lx <= 1 && ly <= 1);
    }
    return false;
}

int main()
{
    int sx, sy, w;
    while (cin >> sx >> sy && sx && sy) {
        cin >> w;
        waters.resize(w + 1);
        waters[0] = Point(sx, sy);
        for (int i = 0; i < w; i++) {
            int x, y;
            cin >> x >> y;
            waters[i + 1] = Point(x, y);
        }

        queue<State> que;
        que.push(State(0, Point(sx, sy)));
        bool goal = false;
        while (!que.empty()) {
            State s = que.front(); que.pop();
            int step = s.first;
            int x = s.second.first, y = s.second.second;
            if(!check(x, y, step)) {
                continue;
            }

            if(step == w) {
                goal = true;
                break;
            }

            for(int i = 0; i < 12; i++) {
                int nx = x + dx[i], ny = y + dy[i];
                que.push(State(step + 1, Point(nx, ny)));
            }
        }

        if (goal) {
            cout << "OK" << endl;
        } else {
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 0
#include <stdio.h>

struct student
{
    struct student* prev;
    struct student* next;
    char flag;
};

struct student s[400000];
int a[400000];

int main(void)
{
    int n, m, q;
    int i, j;
    struct student *current;

    scanf("%d %d %d", &n, &m, &q);
    for (i = 0; i < m; i++) scanf("%d", a + i);
    for (i = 0; i < n; i++){
        s[i].prev = s + (i - 1 + n) % n;
        s[i].next = s + (i + 1) % n;
        s[i].flag = 1;
    }
    current = s;
    for (i = 0; i < m; i++){
        if (a[i] % 2){
            for (j = 0; j < a[i]; j++){
                current = current->prev;
            }
        }
        else {
            for (j = 0; j < a[i]; j++){
                current = current->next;
            }
        }
        current->flag = 0;
        current->prev->next = current->next;
        current->next->prev = current->prev;
        current =current->next;
    }

    while (q-- > 0){
        int t;

        scanf("%d", &t);
        printf("%d\n", s[t].flag);
    }

    return 0;
}

Measured memory_bytes: 8008