akhauriyash/Code-Regression huggingface dataset:
from sys import stdin
readline = stdin.readline


def main():
    v, e = map(int, readline().split())
    from collections import defaultdict
    g = defaultdict(list)

    for _ in range(e):
        s, t = map(int, readline().split())
        g[s].append(t)
        g[t].append(s)

    visited = set()
    lowest = [None] * v
    parent = [None] * v
    prenum = [None] * v
    child = defaultdict(list)
    root = 0

    # dfs??§tree?????????
    stack = [(root, None)]
    while stack:
        u, prev = stack.pop()
        if u not in visited:
            parent[u] = prev
            if prev is not None:
                child[prev].append(u)
            visited |= {u}
            prenum[u] = lowest[u] = len(visited)

        stack.extend([(v, u) for v in g[u] if v not in visited])

    # lowest????¨????
    from collections import Counter
    leaf = [i for i in range(v) if not child[i]]
    unfinished = Counter()
    for li in leaf:
        while li is not None:
            candidate = [prenum[li]] + [prenum[i] for i in g[li] if i != parent[li]] + [lowest[i] for i in child[li]]
            lowest[li] = min(candidate)
            li = parent[li]
            if li is not None and 1 < len(child[li]):
                unfinished[li] += 1
                if unfinished[li] < len(child[li]):
                    break

    # ????????????
    bridge = []
    for i in range(v):
        if child[i]:
            for j in child[i]:
                if prenum[i] < lowest[j]:
                    bridge.append((i, j) if i < j else (j, i))
    bridge.sort()
    for bi in bridge:
        print(*bi)

main()

Measured memory_bytes: 18880
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

vector<vector<int>> graph;
vector<vector<ll>> cost;
vector<bool> ans;

void dfs(int u, int pre = -1, ll c = 0){

    rep(i, graph[u].size()){
        int v = graph[u][i];
        ll w = cost[u][i];
        if(v == pre){
            continue;
        }
        if((w+c) % 2 == 0){
            ans[v] = 0;
        }
        else{
            ans[v] = 1;
        }
        dfs(v, u, w+c);
    }
}

int main() {

    int n;
    cin >> n;
    graph.resize(n);
    cost.resize(n);
    rep(i, n-1){
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;
        w %= 2;
        graph[u].push_back(v);
        graph[v].push_back(u);
        cost[u].push_back(w);
        cost[v].push_back(w);
    }

    ans.resize(n);
    dfs(0);
    
    rep(i, n){
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 13696
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,cnt=0,i,j,k;
  cin>>n;
  long long a[n];
  for(i=0;i<n;i++)
  {
      cin>>a[i];
  }
  sort(a,a+n);
  for(i=0;i<n-2;i++)
  {
    for(j=i+1;j<n-1;j++)
    {
        for(k=n-1;k>=j+1;k--)
        {
            if(a[k]<a[i]+a[j])
            {
               cnt++;
            }
        }
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 256
function main(input) {
    const args = input.split(' ');
    const N = parseInt(args[0], 10),
          A = parseInt(args[1], 10),
          B = parseInt(args[2], 10);

    const nums = Array.from(new Array(N), (v, i) => ++i).filter((i) => {
        var n = i.toString().split('').reduce((p, c) => p + parseInt(c), 0);
        return (n >= A && n <= B);
    });

    console.log(nums.reduce((p, c) => p + c, 0));
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 9968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>>(h, vector<type>(w)) v; rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

void solve() {
  rd(int, n, d);
  d = 1 + d + d;
  pr((n + d - 1) / d);
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

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

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

template<class T>
bool chmax(T &a, initializer_list<T> l)
{
	return chmax(a, *max_element(l.begin(), l.end()));
}

template<class T>
bool chmin(T &a, initializer_list<T> l)
{
	return chmin(a, *min_element(l.begin(), l.end));
}


ll MAX_B = 50;
ll dp[100][2];

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	REP(i, 100) dp[i][0] = dp[i][1] = -1;
	**dp = 0;

	REP(b, MAX_B)
	{
		ll mask = 1ll << (MAX_B - b - 1);

		ll cnt1{0};
		REP(i, N)
		{
			if (mask & A[i]) ++cnt1;
		}

		ll add0 = cnt1 * mask;
		ll add1 = (N - cnt1) * mask;

		if (dp[b][true] != -1)
			chmax(dp[b+1][true], dp[b][true]+max(add0, add1));

		if (dp[b][false] != -1)
			if (mask & K)
				chmax(dp[b+1][true], dp[b][false]+add0);

		if (dp[b][false] != -1)
		{
			if (mask & K)
				chmax(dp[b+1][false], dp[b][false] + add1);
			else
				chmax(dp[b+1][false], dp[b][false] + add0);
		}
	}

	std::cout << max(dp[MAX_B][true], dp[MAX_B][false] )<< std::endl;
}


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

char s[100] = {};

int main()
{
	int n;
	scanf("%s", s);
	n = strlen(s);
	printf("%c",s[0]);
	printf("%d", n - 2);
	printf("%c", s[n - 1]);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
M=int(input())
DC=[tuple(map(int,input().split())) for i in range(M)]

A=0
keta=0
for d,c in DC:
    A+=d*c
    keta+=c

ANS=A//10+keta-1

A=A//10+A%10

while A>=10:
    ANS+=A//10
    A=A//10+A%10

print(ANS)

Measured memory_bytes: 70876
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int m,f,b;
    cin >> m >> f >> b;
    int dif = b - m;
    if(dif<0)dif=0;
    if(dif>f)cout<<"NA";
    else cout<<dif;
    cout << endl;
    return 0;
}


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

using namespace std;

main(){
  int n;
  char data[105][105];
  int dx[] = {0, 1, 0, -1};
  int dy[] = {-1, 0, 1, 0};
  int t;
  cin >> t;
  //t = 100;
  for(int tc=0;tc<t;tc++){
    cin >> n;
    //n = tc+1;
    if(tc != 0) cout << endl;
    if(n == 1){
      cout << "#" << endl;
      continue;
    }
    int y = n-1;
    int x = 0;
    fill(data[0], data[100], ' ');
    data[y][x] = '#';
    int d = 0;
    while(1){
      int ty = y + dy[d];
      int tx = x + dx[d];
      if(ty<0 || ty>=n){ d = (d+1)%4; continue; }
      if(tx<0 || tx>=n){ d = (d+1)%4; continue; }
      if(data[ty][tx] == '#') break;
      int tty = ty + dy[d];
      int ttx = tx + dx[d];
      if((tty>=0 || tty<n) && (ttx>=0 || ttx<n)){
	if(data[tty][ttx] == '#'){
	  d = (d+1)%4; 
	  continue; 
	}
      }
      int cnt = 0;
      for(int i=0;i<4;i++){
	int tty = ty + dy[i];
	int ttx = tx + dx[i];
	if(tty<0 || tty>=n) continue;
	if(ttx<0 || ttx>=n) continue;
	if(data[tty][ttx] == '#') cnt++;
      }
      if(cnt > 1) break;
      data[ty][tx] = '#';
      y = ty;
      x = tx;
    }
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cout << data[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
 
using namespace std;
 
#define PB(x)	push_back(x)
#define ALL(x)	(x).begin(), (x).end()
#define ALLR(x)	(x).rbegin(), (x).rend()
#define MP(x)	make_pair(x)
 
#define debug(_x)		cerr << #_x << '=' << _x << endl;
#define debug2(_x, _y)	cerr << #_x << '=' << _x << ' ' << #_y << '=' << _y << endl;
#define debugn(_a)		cerr << #_a << ": "; for (const auto _x: _a) cerr << _x << ' '; cerr << endl;

#define FAST_IO ios::sync_with_stdio(false); cin.tie(0)

#define int long long int

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef unsigned long long ull;
 
const int INF = LONG_LONG_MAX;
const int NINF = LONG_LONG_MIN;

int32_t main() {
	FAST_IO;
	
	int n;
	cin >> n;
	
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i%3 == 0 || i%5 == 0) {
		
		} else {
			ans += i;
		}
	}
	cout << ans << endl;
}
// g++ -Wall -Wextra -Wshadow -fsanitize=undefined



Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

  if (!(A % 3) || !(B % 3) || !((A + B) % 3))
    cout << "Possible" << endl;
  else
    cout << "Impossible" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef vector <string> vs;

vs split(const string &text, char delim=' '){
int start = 0, end = 0;
vs tokens;

for (int i=0; i<(int)text.size(); i++)
	if (text[i] == delim){
		end = i;
		tokens.push_back(text.substr(start, end - start));
		start = end + 1;
	}
	tokens.push_back(text.substr(start));
	return tokens;
}

int rot(string &text){
	for (int i=0; i<(int)text.size(); i++){
		char c=text[i];
		if (islower(c))
			if (c=='z') text[i]='a';
			else text[i]++;
	}
	return 0;
}

bool check(string text){
	vs words = split(text);
	for (int i=0; i<(int)words.size(); i++){
		string tmp = words[i];
		if (tmp=="the" || tmp=="this" || tmp=="that")
			return true;
	}
	return false;
}

int main(void){
	string text;
	while (true){
		getline(cin, text);
		if (cin.eof()) break;
		for (int i=0; i<26; i++){
			if (check(text)) break;
			else rot(text);
		}
		cout<<text<<endl;
	}
	return 0;
}

Measured memory_bytes: 1196
n = gets.to_i
adj=[]
n.times do |i|
  adj[i] = gets.split.map &:to_i
end

def adj.adjacency_list_to_adjacency_matrices
  matrices = Array.new(self.length) {Array.new(self.length,0)}
  self.each do |adj|
    u, k, *v = adj[0], adj[1], adj[2..-1]
    v.flatten.each do |v|
      matrices[u-1][v-1] = 1
    end
  end
  matrices
end

result =  adj.adjacency_list_to_adjacency_matrices
result.each{|r| puts r.join " "}



Measured memory_bytes: 7012
#include<stdio.h>

int main(void)
{
	int r, x, y, W, H;

//	printf("????????¢??????W????¨?H?????????x??§?¨????y??§?¨??????????r?????\???");
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

	if (x + r <= W && x - r >= 0 ){
		if (y + r <= H && y - r >= 0){
			printf("Yes\n");
		}
		else printf("No\n");
	}
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 584
<?php
list($K) = ints();
$sum6 = 0;
for($i = 1; $i <= $K; ++$i)
for($j = 1; $j <= $i; ++$j)
$memo[$i][$j] = $memo[$j][$i] = (int)gmp_gcd($i, $j);

for($i = 1; $i <= $K; ++$i)
for($j = $i+1; $j <= $K; ++$j){
    $mij = $memo[$memo[$i][$j]];
    for($k = $j+1; $k <= $K; ++$k)
        $sum6+=$mij[$k];
}

for($i = 1; $i <= $K; ++$i){
  $mi = $memo[$i];
  for($j = $i+1; $j <= $K; ++$j)
    $sum6+=$mi[$j];
}

echo $sum6*6+$K*($K+1)/2;

function ints(){return array_map('intval',explode(' ',trim(fgets(STDIN))));}


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

void solve(long long even , long long odd , long long p , long long n){
	long long ans = 0; 
	if(even == n){
		if(p == 0){
			ans = pow(2 , n);
		}
		else if(p == 1){
			ans = 0;
		}
	}
	else{
		ans = pow(2 , n-1);
	}
	cout << ans << endl; 
}

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

	long long num;
	long long even = 0; 
	long long odd = 0; 
	for(long long i = 0; i < n; i++){
		cin >> num;
		if(num % 2 == 0){
			even++;
		}
		else{
			odd++;
		}
	}
	solve(even , odd , p , n);
}

Measured memory_bytes: 3292
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

ll gcd(ll a, ll b) {return (!b ? a : gcd(b, a % b));}
ll lcm(ll a, ll b) {return ((a*b)/gcd(a,b));}
bool cmp(int a,int b){return a>b;}

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;
const int N = 1e6 + 10;

long long modpow(long long n, long long k, long long mod)
{
if (k == 0) return 1;
long long r = modpow(n * n % mod, k >> 1, mod);
if (k & 1) r = r * n % mod;
return r;
}
const int dx[4] = {0,0,1,-1};
const int dy[4] = {1,-1,0,0};
void solve(){
  int h,w,x1,y1,x2,y2;
  cin >> h >> w >> x1 >> y1 >> x2 >> y2;
  x1--;y1--;x2--;y2--;
  vector<string>s(h);
  for(int i = 0;i<h;i++) cin >> s[i];
  deque<pii>q;
  vector<vector<int>>dis(h,vector<int>(w,-1));
  dis[x1][y1] = 0;
  q.push_back({x1,y1});
  while(!q.empty()){
    auto pos = q.front();
    q.pop_front();
    int x = pos.first;
    int y = pos.second;
    for(int i = 0;i<4;i++){
        int nx = x+dx[i];
        int ny = y+dy[i];
        if(nx<0||ny<0||nx>=h||ny>=w) continue;
        if(s[nx][ny]=='#') continue;
        if(dis[nx][ny]<=dis[x][y]&&dis[nx][ny]!=-1) continue;
        dis[nx][ny] = dis[x][y];
        q.push_front({nx,ny});
    }
    for(int i = -2;i<=2;i++){
        for(int j = -2;j<=2;j++){
            int nx = x+i;
            int ny = y+j;
            if(nx<0||ny<0||nx>=h||ny>=w) continue;
            if(s[nx][ny]=='#') continue;
            if(dis[nx][ny]<=dis[x][y]+1&&dis[nx][ny]!=-1) continue;
            dis[nx][ny] = dis[x][y]+1;
            q.push_back({nx,ny});
        }
    }
  }
  cout << dis[x2][y2];
}



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


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

#define MAX 100000

int main() {
	int N, K;

	cin >> N >> K;

	int k = 0;
	int ans = 0;
	for( int i = 1; i <= N; i += 2 ) {
		k++;
		if( k >= K ) {
			ans = 1;
			break;
		}
	}

	if( ans ) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


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

int main() {
    string str1,str2;cin>>str1>>str2;
    int n=str1.size();
    pair<string ,string>a[n];
    pair<string ,string>b[n];
    for(int i=0;i<n;++i){
        a[i].first = str1[i];
        a[i].second= str2[i];
        b[i].first = str2[i];
        b[i].second= str1[i];
    }
    sort(a,a+n);
    sort(b,b+n);
    int ans=0;
    for(int i=0;i<n-1;++i){
        if(a[i].first == a[i+1].first && a[i].second != a[i+1].second){
            ans=1;
            break;
        }
        if(b[i].first == b[i+1].first && b[i].second != b[i+1].second){
            ans=1;
            break;
        }
    }
    if(ans==1)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 44424
import java.util.Comparator

fun main(args: Array<String>) {
    val (n, d, a) = readLine()!!.split(' ').map { it.toLong() }
    val ms = (0 until n).map {
        val (x, h) = readLine()!!.split(' ').map { it.toLong() }
        x to h
    }.sortedBy { it.first }

    var ans = 0L
    val hs = LongArray(n.toInt() + 2)

    for (i in 0 until n.toInt()) {
        val j = ms.binarySearch(
                ms[i].first + 2 * d to 0,
                Comparator { o1, o2 -> if (o1.first > o2.first) 1 else -1 }
        ).let { -(it + 1) }

        hs[i + 1] += hs[i]
        val h = Math.max(ms[i].second + hs[i + 1], 0)
        val c = (h + a - 1) / a

        ans += c
        hs[i + 1] -= a * c
        hs[j + 1] += a * c
    }

    println(ans)
}


Measured memory_bytes: 133956
n = int(input())
s = [input() for x in range(n)]

m = int(input())
t = [input() for x in range(m)]

tmpList = []
getMoneyList = [0]
for i in range(n):
  if s[i] in tmpList:
    continue
  si = s[i]
  tmpList.append(si)
  cnts = s.count(si)
  cntt = t.count(si)
  if cnts - cntt > 0:
    getMoneyList.append(cnts - cntt)

print(max(getMoneyList))

Measured memory_bytes: 3064
#include<stdio.h>

int main(void)
{
  //宣言
  int N;
  //読み込み
  scanf("%d",&N);
  //結果
  if(N%10==2||N%10==4||N%10==5||N%10==7||N%10==9)
  {
  	printf("hon");
  }else if(N%10==0||N%10==1||N%10==6||N%10==8){
    printf("pon");
  }else{
  	printf("bon");
  }
  
  return 0;

}

Measured memory_bytes: 1732
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cmath>
using namespace std;

#define all(c) c.begin(),c.end()
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n) FOR(i,0,n)
#define MAX(x, y)  ((x > y)? x : y);
#define MIN(x, y)  ((x < y)? x : y);
#define dump(x)  cout << #x" = " << x << endl;
#define debug(x) cout << #x" = " << x << " (" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
typedef vector<int> vi;

int main() {
	string s;
	vector<string> vs;
	cin >> s;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			vs.push_back("0");
		}
		else if (s[i] == '1') {
			vs.push_back("1");
		}
		else {
			if (!vs.empty()) {
				//vs[vs.size() - 1].clear();
				vs.erase(vs.end() - 1);
			}
		}
	}

	for (int i = 0; i < vs.size(); i++) {
		cout << vs[i];
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            String S = in.next();
            String T = in.next();
            int ans = 0;
            for (int i = 0; i < S.length(); i++) {
                if (S.charAt(i) != T.charAt(i))
                    ans++;
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
            this.bufPointer = 0;
            this.bufLength = 0;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isPrintableChar(int c) {
            return c >= 33 && c <= 126;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();

            int b = readByte();
            while (!isPrintableChar(b))
                b = readByte();

            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }

            return sb.toString();
        }

    }
}



Measured memory_bytes: 35196
/* Just_Do_It ___________ICARUS__________________*/
                     
    #include <bits/stdc++.h>
    using namespace std;
           
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(int i=a;i<n;i++)
    #define per(i,n,a) for (int i=n;i>a;i--)
    #define te int t; std::cin >> t; while(t--)
    #define SZ 200010
    //# define M_PIl  3.141592653589793238462643383279502884L 
    /*   Proceed with CAUTION   */
    
    int main(){
        fastio;
        ll n; string s;
        cin>>s;
        n = s.size();
        if(s[0]=='0' || s[n-1]=='1') return cout<<-1<<endl ,0;
        rep(i,1,n-1) if(s[i-1]!=s[n-i-1]) return cout<<-1<<endl ,0;
        ll p=n;
        per(i,n-1,0) {
          cout<<i<<" "<<p<<endl;
          if(s[i-1]=='1') p=i;
        }
    }



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

int main() {
  int N;
  int K;
  
  cin >> N >> K;
  
  int score = 1;
  
  for (int i=0; i < N; i++) {
   
    if (score * 2 > score + K) {
        score += K;
    }
    else {
        score *= 2;
    }
  }
  
  cout << score << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;
int main(void) {
  int r;
  cin >> r;
  cout << r * r << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <math.h>

#define mp                  make_pair
#define F                   first
#define S                   second
#define pb                  push_back
#define FOR(i,j,n)          for(int i=j;i<n;i++)
#define F0R(i,j,n)          for(int i=j;i<=n;i++)
#define RFOR(i,j,n)         for(int i=n-1;i>=j;i--)
#define RF0R(i,j,n)         for(int i=n;i>=j;i--)
#define FOREACH(x,v)        for(auto x:v)
#define ITFOR(it,v)         for(__typeof(v.begin()) it =v.begin();it!=v.end();++it)
#define __in_arr__(a,j,n)   FOR(i,j,n)cin >> a[i];
#define __out_arr__(a,j,n)  FOR(i,j,n)cout << a[i];
#define LOG                 cout << "[ !" << __LINE__ << "L ] " << endl;
#define PLOG(x)             cout << "[ !" << __LINE__ << "L ] " \<<x<<endl;

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;

const int MAXN = 55;
char c[MAXN][MAXN];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    int n,m;
    cin >> n >> m;
    F0R(i,1,n)
        F0R(j,1,m)
        cin >> c[i][j];
#define T(i,j) (c[i][j] == '#')
    F0R(i,1,n) {
        F0R(j,1,m) {
            if(c[i][j] =='#') {
                cout << "#";
                continue;
            }
            int ans = T(i-1,j) + T(i-1,j-1) + T(i-1,j+1) + T(i,j+1) + T(i,j-1) + T(i+1,j) + T(i+1,j-1) + T(i+1,j+1);
            cout << ans;
        }
        cout << endl;
    }
    return 0;
}


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

long long int points[100000][3];
long long int dp[100000][3];

long long int max_points(int p, int n) {
    if (n < 0) {
        return 0;
    }
    if (p != -1 && dp[n][p] != -1) {
        return dp[n][p];
    }
    long long int current = LLONG_MIN;
    for (int i = 0; i < 3; i++) {
        if (p != i) {
            current = max(current, max_points(i, n - 1) + points[n][i]);
        }
    }
    return dp[n][p] = current;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> points[i][0] >> points[i][1] >> points[i][2];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            dp[i][j] = -1;
        }
    }
    cout << max_points(-1, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 11264
#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> vll;
typedef pair<ll,ll> pll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	int n;
	cin >> n;
	vi freq(n);
	M00(i, n-1) {
		int x;
		cin >> x;
		freq[x-1]++;
	}
	M00(i, n) cout << freq[i] << endl;
}


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

int main() 
{
    char x;
    cin >> x;
    bool z = false;
    for (int i=1; i<4;i++)
    {
        char y;
        cin >> y;
        if (x==y)
            z = true;
        x = y;
    }
    cout << (z?"Bad":"Good");
    return 0;
}

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

int main() {
    long int INF = 2147483647;
    long int N, W;
    cin >> N >> W;
    vector<long int> weights(1+N, 0);
    vector<long int> values(1+N, 0);

    for (long int i=0; i<N; i++) {cin >> weights.at(1+i); cin >> values.at(1+i);}

    vector<vector<long int>> dp(N+1, vector<long int>(accumulate(values.begin(), values.end(), 0)+1, INF));
    long int answer = 0;

    for (long int i=0; i<N; i++) {
        dp.at(i).at(0) = 0;
        for (long int j=0; j<1+accumulate(values.begin(), values.end(), 0); j++) {
            if (values.at(i+1) > j) dp.at(i+1).at(j) = dp.at(i).at(j);
            else {
                dp.at(i+1).at(j) = min(
                    dp.at(i).at(j-values.at(i+1)) + weights.at(i+1),
                    dp.at(i).at(j)
                );
                if (dp.at(i+1).at(j) <= W) answer = max(answer, j);
            }
        }
    }    
    cout << answer << endl;
}


Measured memory_bytes: 80256
while 1:
  a,op,b=raw_input().split()
  a, b=int(a), int(b)
  if op == "+":
    print a+b
  elif op == "-":
    print a-b
  elif op == "*":
    print a*b
  elif op == "/":
    print a/b
  elif op == "?":
    break

Measured memory_bytes: 6432
def find(n):
  dif = 0
  i = 0
  while dif <=n:
    i+=1
    dif=i**5-(i-1)**5
  return i


X= int(input())
lim = find(X)
condition = True
for i in range(lim):
  if condition:
    puissance = i**5-X
    signe = (abs(puissance)//puissance)
    entier = int(((puissance*signe)**(1/5)))
    if entier**5 == signe*puissance:
      print(i, entier*signe)
      condition = False


Measured memory_bytes: 9392
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int h,a,c=0;
    cin>>h>>a;
    while(h>0){
        h -= a;
        c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
n, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(n)]

INF = 10 ** 9


def dfs(cur, a, b, c):
    if cur == n:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF

    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)


print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
//#include <random>
#include <map>
//#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <time.h>
//#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
//#include <type_traits>
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
double pi = 3.141592653589793;
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
	}

	vector < int> x(1000005);
	int c1 = 0;
	rep(i, n) {
		x[a[i]]++;
		if (a[i] == 1) {
			c1++;
		}
	}

	if (c1 > 1) {
		cout << 0 << endl;
		return 0;
	}

	if (c1 == 1) {
		cout << 1 << endl;
		return 0;
	}

	int ans = 0;
	rep(i, n) {
		int t = a[i];

		vector<int> s;

		for (int k = 2; k * k <= a[i]; k++) {
			if (t % k == 0) {
				s.push_back(k);
				if (k * k != t) {
					s.push_back(t / k);
				}
			}
		}

		int flg = 1;
		rep(j, s.size()) {
			if (x[s[j]]) {
				flg = 0;
				break;
			}
		}
		if (x[a[i]] > 1) {
			flg = 0;
		}

		if (flg) {
			ans++;
		}

	}
	cout << ans << endl;

}






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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    if(a[0] % 2 == a[1] % 2) {
        cout << (a[2] * 2 - a[0] - a[1]) / 2 << endl;
    } else {
        cout << (a[2] * 2 - a[0] - a[1]) / 2 + 2 << endl;
    }
}

Measured memory_bytes: 256
<?php
  list($n, $k) = explode(" ", trim(fgets(STDIN)));
  $h = explode(" ", trim(fgets(STDIN)));
  
  $dp = [];

  $dp[0]=0;
  for($i=1;$i<$n;$i++){
    $dp[$i]=PHP_INT_MAX;
    for($j=1;$j<=$k;$j++){
      if(($i-$j) < 0){
        continue;
      }
      $jump=abs($h[$i-$j]-$h[$i])+$dp[$i-$j];
      if($jump < $dp[$i]){
        $dp[$i]=$jump;
      }
    }
  }
  echo $dp[$n-1];

Measured memory_bytes: 18932
from collections import defaultdict
from collections import deque
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

def comb(n,r):
  return math.factorial(n)//math.factorial(r)//math.factorial(n-r)

def cula(a):
  ans = 0
  for i in range(a+1):
    ans+=comb(a,i)
  return ans

def culb(b):
  ans = 0
  for i in range(p,b+1,2):
    ans+=comb(b,i)
  return ans

n,p = readInts()
a = [0,0]
for i in readInts():
  if i%2==0:
    a[0]+=1
  else:
    a[1]+=1

print(cula(a[0])*culb(a[1]))

Measured memory_bytes: 9464
#include <stdio.h>

const int STD = 1000000007;

int             main(void)
{
        int     s;
        int     i, j;
        int     df[2001] = {0};

        scanf("%d", &s);
        df[0] = 0;
        df[1] = 0;
        df[2] = 0;
        df[3] = 1;
        df[4] = 1;
        df[5] = 1;
        for (i = 6; i <= s; i++)
        {
                df[i] = 1;
                for (j = i - 3; j >= 3; j--)
                {
                        df[i] = (df[i] + df[j]) % STD;
                }
        }
        printf("%d\n", df[s]);
        return (0);
}

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

using namespace std;
typedef long long int ll;



int main() {

  int A,B;
  cin>>A>>B;
  if( A%3 && B%3 && (A+B)%3 ){
    cout<<"Impossible"<<endl;
  }else{
    cout<<"Possible"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct Pt{
	double x,y;
	Pt(){x=y=0;}
	Pt(double X,double Y){x=X;y=Y;}
};
Pt rot(Pt a){
	Pt ret=Pt(cos(0.01)*a.x+sin(0.01)*a.y,-sin(0.01)*a.x+cos(0.01)*a.y);
	return ret;
}
inline bool operator<(const Pt&a,const Pt&b){return a.x<b.x;}
Pt c[200];
Pt d[200];
int sz;
int S[11000];
double dp[11000];
double EPS=1e-9;
Pt r[11000];
inline double dist(Pt a,Pt b){
	return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		for(int i=0;i<a;i++){
			double x,y;
			scanf("%lf%lf",&x,&y);
			c[i]=Pt(x,y);
		}
		for(int i=0;i<b;i++){
			double x,y;
			scanf("%lf%lf",&x,&y);
			d[i]=Pt(x,y);
		}
		for(int i=0;i<a;i++)c[i]=rot(c[i]);
		for(int i=0;i<b;i++)d[i]=rot(d[i]);
		std::sort(d,d+b);
		sz=0;
		for(int i=0;i<a-1;i++){
			if(c[i].x<c[i+1].x){
				for(int j=0;j<b;j++){
					if(c[i].x>d[j].x||c[i+1].x<d[j].x)continue;
					double ey=c[i].y+(c[i+1].y-c[i].y)*(d[j].x-c[i].x)/(c[i+1].x-c[i].x);
					if(ey>d[j].y){
			//			printf("%d R\n",j*2);
						if(sz>0&&S[sz-1]==j*2){
							sz--;
						}else{
							S[sz++]=j*2;
						}
					}else{
			//			printf("%d R\n",j*2+1);
						if(sz>0&&S[sz-1]==j*2+1){
							sz--;
						}else{
							S[sz++]=j*2+1;
						}
					}
				}
			}else{
				for(int j=b-1;j>=0;j--){
					if(c[i+1].x>d[j].x||c[i].x<d[j].x)continue;
					double ey=c[i].y+(c[i+1].y-c[i].y)*(d[j].x-c[i].x)/(c[i+1].x-c[i].x);
					if(ey>d[j].y){
			//			printf("%d L\n",j*2);
						if(sz>0&&S[sz-1]==j*2){
							sz--;
						}else{
							S[sz++]=j*2;
						}
					}else{
			//			printf("%d L\n",j*2+1);
						if(sz>0&&S[sz-1]==j*2+1){
							sz--;
						}else{
							S[sz++]=j*2+1;
						}
					}
				}
			}
		}
		r[0]=c[0];
		r[sz+1]=c[a-1];
		for(int i=0;i<sz;i++){
			r[i+1]=d[S[i]/2];
		}
	//	for(int i=0;i<sz;i++){
	//		printf("%d ",S[i]);
//		}printf("\n");
		for(int i=0;i<sz+2;i++)dp[i]=999999999;
		dp[0]=0;
		
		for(int i=1;i<sz+2;i++){
			if(dist(r[i],r[i-1])<EPS){
				dp[i]=dp[i-1];
				continue;
			}
			double L=-999999999;
			double R=999999999;
			for(int j=i-1;j>=0;j--){
			//	printf("%d, %d: (%f, %f)\n",j,i,L,R);
				if(dist(r[j],r[i])<EPS)break;
				double f=(r[j].y-r[i].y)/(r[j].x-r[i].x);
				if(L+EPS<f&&f+EPS<R){
			//		printf("%d %d\n",j,i);
					dp[i]=min(dp[i],dp[j]+dist(r[i],r[j]));
				}
				if(j){
					if(S[j-1]%2){
						if(r[i].x<r[j].x){
							R=min(f,R);
						}else{
							L=max(L,f);
						}
					}else{
						if(r[i].x<r[j].x){
							L=max(L,f);
						}else{
							R=min(R,f);
						}
					}
				}
				if(L+EPS>R)break;
			}
		}
		printf("%.12f\n",dp[sz+1]);
	}
}

Measured memory_bytes: 1300
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        // code goes here
        int[] in = nextIntArray(br, 2);
        int n = in[0];
        long k = in[1];
        int[] p = nextIntArray(br, n);
        int[] c = nextIntArray(br, n);

        int[][] vals = new int[n][n];
        int[] limits = new int[n];
        boolean[][] visited = new boolean[n][n];
        for(int i = 0; i < n; i++){
            int next = p[i];
            boolean s = false;
            for(int j = 0; j < n; j++){
                visited[i][next - 1] = true;
                vals[i][j] = c[next - 1];
                next = p[next - 1];
                if(visited[i][next - 1]){
                    limits[i] = j + 1;
                    s = true;
                    break;
                }
            }

            if(!s){
                limits[i] = n + 1;
            }
        }

        long totalMax = Long.MIN_VALUE;
        for(int i = 0; i < n; i++){
            long acc = 0;
            for(int j = 0; j < Math.min(limits[i], k); j++){
                acc += vals[i][j];
                totalMax = Math.max(totalMax, acc);
            }
            if(limits[i] >= k){
                continue;
            }

            long rem = 0;
            if(k%limits[i] > 0){
                acc = (k/limits[i])*acc;
                totalMax = Math.max(totalMax, acc);
                rem = k % limits[i];
            }else {
                acc = (k/limits[i] - 1)*acc;
                totalMax = Math.max(totalMax, acc);
                rem = limits[i];
            }
            for(int j = 0; j < rem; j++){
                acc += vals[i][j];
                totalMax = Math.max(totalMax, acc);
            }
        }
        sb.append(totalMax);
        System.out.print(sb.toString());
    }

    private static int nextInt(BufferedReader br) throws IOException{
        return Integer.parseInt(br.readLine());
    }

    private static int[] nextIntArray(BufferedReader br, int n) throws IOException{
        StringTokenizer st = new StringTokenizer(br.readLine());
        int[] arr = new int[n];
        for(int i = 0; i < n; i++){
            arr[i] = Integer.parseInt(st.nextToken());
        }
        return arr;
    }

    static class Pair<A, B>{
        A first;
        B second;
        public Pair(A first, B second){
            this.first = first;
            this.second = second;
        }
    }
}


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


//defines...
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define in insert
#define pi 2*acos(0.0)1
#define srt(s) sort(s.begin(),s.end())
#define all(x) x.begin(),x.end()

const ll mod=1e9+7;
const ll MX=2e5+5;

//code goes from here...



int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);

    freopen("output.txt", "w", stdout);
#endif

    boost
    //---------------------------------
    int n;
    cin >> n;
    vector <int > v(n);
    for(auto &i : v) cin >> i;
    srt(v);
    ll s=v[0],l=v[n-1],ss=INT_MAX;
    for(int i=s;i<=l;i++)
    {
        ll cur=0;
        for(int j=0;j<n;j++)
        {
            cur+=((v[j]-i)*(v[j]-i));
        }
        ss=min(ss,cur);
    }
    cout << ss<< endl;
    
    //---------------------------------
    
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll a,b; cin >> a >> b;
  if(a*b %2 == 1) cout << "Odd" << endl;
  else cout << "Even" << endl;
}

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

typedef long long ll;

using namespace std;

int main() {
    ll n, k, ans = 1e15;
    cin >> n >> k;
    vector<ll> x(n);
    for (ll i = 0; i < n; ++i) cin >> x.at(i);
    for (ll i = 0; i <= n - k; ++i) {
        ll l = x.at(i), r = x.at(i + k - 1), now = 0;
        if (l < 0 && r > 0) now = abs(l) + abs(r) + min(abs(l), abs(r));
        else now = max(abs(l), abs(r));
        ans = min(ans, now);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    n = 1
    while True:
        if n * 1000 >= N:
            print((n * 1000) - N)
            exit()
        else:
            n += 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 10220
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
int n;

int berapa(int x){
	int total=0;
	while(x%2==0){
		x/=2;
		total++;
	}
	return total;
}

int main(){
	IOS
	cin >> n;
	int maks=-1;
	int temp;
	for(int i=1;i<=n;i++){
		int jumlah=berapa(i);
		if(jumlah>maks){
			maks=jumlah;
			temp=i;
		}
	}
	cout << temp << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#define int long long
using namespace std;
const int INF = 1000000000000;
const int mod = 1000000007;
int par[213456];//親
int depth[213456];//木の深さ
//n要素で初期化
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(int x, int y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(int x, int y) {
	return find(x) == find(y);
}
signed main() {
	int n, m, k, l; cin >> n >> m; init(n);
	vector<vector<int>>a(m + 1);
	for (int h = 1; h <= n; h++) {
		cin >> k;
		for (int i = 0; i < k; i++) {
			cin >> l; a[l].push_back(h);
		}
	}
	for (int h = 1; h <= m; h++) {
		for (int i = 1; i < a[h].size(); i++) {
			unite(a[h][i - 1], a[h][i]);
			//cout << h << ' ' << a[h][i - 1] << ' ' << a[h][i] << endl;
		}
	}
	for (int h = 2; h <= n; h++) {
		if (same(h - 1, h) == false) { cout << "NO" << endl; return 0; }
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 5240
#include<iostream>
#include<vector>
#include<cctype>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a + b <= b + c && a + b <= a + c){
        cout << a + b << endl;
    }else if(b + c <= a + b && b + c <= a + c){
        cout << b + c << endl;
    }else{
        cout << a + c << endl;
    }
}

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

const int MAXN = 1010;
int fa[MAXN], A[MAXN], f[MAXN], g[5010], h[5010], n;
void gmin(int & x, int y) { x > y ? x = y : 0; }
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 2; i <= n; ++i) std::cin >> fa[i];
	for (int i = 1; i <= n; ++i) std::cin >> A[i];
	for (int i = n; i; --i) {
		memset(g, 0x3f, A[i] + 1 << 2); const int I = *g; *g = 0;
		for (int j = i + 1; j <= n; ++j) if (fa[j] == i) {
			int n1 = I, n2 = I;
			for (int k = 0; k <= A[i]; ++k) {
				if (k >= f[j]) gmin(n1, g[k - f[j]]);
				if (k >= A[j]) gmin(n2, g[k - A[j]]);
				h[k] = std::min(std::min(n1 + A[j], n2 + f[j]), I);
			}
			memcpy(g, h, A[i] + 1 << 2);
		}
		f[i] = *std::min_element(g, g + A[i] + 1);
		if (f[i] == I) return std::cout << "IMPOSSIBLE" << std::endl, 0;
	}
	std::cout << "POSSIBLE" << std::endl;
	return 0;
}


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

#include <iostream>
#include<string>
#include<vector>
#include<cmath>
#include<map>
using namespace std;

int next(int x) {
    for (int i = 2; i*i <= x; i++) {
        if (x % i == 0) {
            return x / i;
        }

       
    }
    return 1;
}
int gcd(int a, int b) {
    if (b == 0)return a;

    return gcd(b, a % b);
}
int main()
{
    int n,x;

    cin >> n >> x;
    vector<int> X(n);
    vector<int>sa(n);
    int min = 1000000008;
    for (int i = 0; i < n; i++) {
        cin >> X[i];
 /*       if (min > abs(X[i] - x)) {
            min = abs(X[i] - x);
        }*/
        sa[i] = abs(X[i] - x);
    }
   // bool ok = false;
    //while (ok==false && min > 1) {

    //    for (int i = 0; i < n; i++) {
    //        if (abs(X[i] - x) % min != 0) {
    //            ok = false;
    //            min = next(min);
    //            break;
    //        }
    //        ok = true;
    //    }
    //    
    //}
    int ans =sa[0];
    for (int i = 1; i < n; i++) {
        ans = gcd(ans, sa[i]);
    }

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



Measured memory_bytes: 4004
#include <stdio.h>

int main(){
  
  int N,K;
  scanf("%d%d",&N,&K);
  
  long ans,x = N / K ,y = (N + K / 2) / K;
  
  if(K % 2 == 0){
    ans = x * x * x + y * y * y;
  }else{
    ans = x * x * x;
  }
  printf("%ld",ans);
    
  return 0;
}
  

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

namespace ABC
{
    class APC2020B
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            var N = RI();
            var Ia = RIa(N);

            int cnt = 0;
            for (int i = 0; i < N; i += 2)
            {
                if (Ia[i] % 2 == 1)
                {
                    ++cnt;
                }
            }
            Console.WriteLine(cnt);


#if DEBUG
            Console.WriteLine("*** end ***");
            Console.SetIn(Console.In);
            Console.ReadKey();
            Console.WriteLine();
#endif
        }

        static int RI()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] RIa(int n)
        {
            string[] sa = Console.ReadLine().Split(' ');
            int[] la = new int[n];
            for (int i = 0; i < n; ++i)
            {
                la[i] = int.Parse(sa[i]);
            }
            return la;
        }
    }
}


Measured memory_bytes: 27324