akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
i64 n, m;
vector<vector<int>> g;
vector<i64> sub, par, ans;
void dfs_sub(int u, int p) {
    sub[u] = 1;
    for (int v : g[u]) {
        if (v == p) continue;
        dfs_sub(v, u);
        (sub[u] *= sub[v] + 1) %= m;
    }
}
void dfs_par(int u, int p) {
    i64 x = 1;
    for (int i = 0; i < g[u].size(); ++i) {
        int v = g[u][i];
        if (v == p) continue;
        par[v] = par[u] * x % m;
        (x *= sub[v] + 1) %= m;
    }
    x = 1;
    for (int i = g[u].size() - 1; i >= 0; --i) {
        int v = g[u][i];
        if (v == p) continue;
        par[v] = (par[v] * x + 1) % m;
        (x *= sub[v] + 1) %= m;
    }
    for (int v : g[u]) {
        if (v == p) continue;
        dfs_par(v, u);
    }
}
int main() {
    cin >> n >> m;
    g.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    sub.resize(n + 1);
    par.resize(n + 1);
    dfs_sub(1, 0);    
    par[1] = 1;
    dfs_par(1, 0);
    for (int u = 1; u <= n; ++u) {
        cerr << u << ':' << sub[u] << ',' << par[u] << '\n';
    }
    for (int u = 1; u <= n; ++u) {
        i64 ans = sub[u] * par[u] % m;
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 12672
<?php
$N = fgets(STDIN);
$A = explode(' ', trim(fgets(STDIN)));
$B = explode(' ', trim(fgets(STDIN)));
$C = explode(' ', trim(fgets(STDIN)));

$total = 0;
for ($i = 0; $i < $N; $i++) {
    $total += $B[$A[$i] - 1];
    if ($i !== 0) {
        if ($A[$i] - $A[$i - 1] === 1) {
            $total += $C[$A[$i - 1] - 1];
        }
    }
}
echo($total);

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

struct Lowlink {
  const vector<vector<int>> &g;
  vector<int> ord, low;
  vector<int> articulation;
  vector<P> bridge;
  int k;

  Lowlink(const vector<vector<int>>& g) : g(g) {}

  virtual void dfs(int idx, int par) {
    ord[idx] = k++;
    low[idx] = ord[idx];
    bool is_articulation = false;
    int cnt = 0;
    for(auto to : g[idx]) {
      if(ord[to] < 0) {
        ++cnt;
        dfs(to,idx);
        low[idx] = min(low[idx],low[to]);
        if(par != -1 && low[to] >= ord[idx]) is_articulation = true;
        if(ord[idx] < low[to]) bridge.push_back(P(min(idx,to),max(idx,to)));
      } else if(to != par) {
        low[idx] = min(low[idx],ord[to]);
      }
    }
    if(par == -1 && cnt > 1) is_articulation = true;
    if(is_articulation) articulation.push_back(idx);
  }

  virtual void build() {
    ord.assign(g.size(),-1);
    low.assign(g.size(),0);
    k = 0;
    rep(i,g.size()) {
      if(ord[i] < 0) dfs(i,-1);
    }
  }
};

int main() {
  int n, m, u, v;
  cin >> n >> m;
  vector<vector<int>> g(n);
  rep(i,m) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  Lowlink llink(g);
  llink.build();
  sort(llink.bridge.begin(),llink.bridge.end());
  for(auto x : llink.bridge) cout << x.first << " " << x.second << endl;
}


Measured memory_bytes: 4676
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>

auto& in = std::cin;
auto& out = std::cout;

const long double PI = 3.1415926535897932384626433832795028841971;

const long double DPR = 5.0*PI;
const long double CIR_DIFF = 20.0- DPR;

int32_t N;
int32_t x,y,x2,y2;
int32_t DP[2000001];//長さNの内最小のY
std::pair<int32_t, int32_t> CIR[200000];//X,Y


int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> x >> y >> x2 >> y2;
	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> CIR[i].first >> CIR[i].second;
	}
	std::sort(CIR, CIR + N);
	if (x > x2) { std::swap(x, x2); std::swap(y, y2); }

	if (y < y2) {}
	else {
		y = -y; y2 = -y2;
		for (size_t i = 0; i < N; i++)
		{
			CIR[i].second=-CIR[i].second;
		}
	}

	{
		auto iter = std::lower_bound(CIR, CIR + N, std::pair<int32_t, int32_t>{x, -1000000000});
		auto iter_end = std::upper_bound(CIR, CIR + N, std::pair<int32_t, int32_t>{x2, 1000000000});
		int32_t X_NUM = iter_end - iter;
		int32_t length = 0;
		DP[0] = y;
		for (;iter != iter_end;++iter)
		{
			if (iter->second < y) {
				--X_NUM;
				continue;
			}
			if (iter->second > y2) {
				--X_NUM;
				continue;
			}
			if (DP[length] < iter->second) {
				++length;
				DP[length] = iter->second;
			}
			else if(DP[length] == iter->second){
				if (iter->second >= y2) {
					//continue;//後で例外処理
				}
				++length;
				DP[length] = iter->second+1;
			}
			else {
				auto insert = std::upper_bound(DP, DP + length+1, iter->second);
				if (insert != (DP + length+1)) {
					*insert = iter->second;
					int32_t last = y;
					if (insert != DP) {
						last = *(insert - 1);
					}
					else { throw 0; }
					if (last == iter->second) {
						*insert = iter->second + 1;
					}
				}
				else { throw 0; }
			}
		}

		long double res = (x2 - x) + std::abs(y2 - y);
		res *= 100;
		res -= length*CIR_DIFF;
		if (length > std::min(y2-y,x2 - x)) {
			res += CIR_DIFF;
			res += DPR+ DPR - 20;
		}
		out
			<< std::fixed << std::setprecision(20)
			<< res << endl;
	}


	return 0;
}
#endif


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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> v;
  int ncnt = 0;
  int dmin = 1000000000;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
    if (a < 0) ncnt++;
    if (a >= 0 && dmin > a) dmin = a;
    if (a < 0 && dmin > -a) dmin = -a;
  }

  long long int result = 0;
  for (int i = 0; i < n; i++) {
    result += v[i] >= 0 ? v[i] : -v[i];
  }
  if (ncnt%2 == 1) result -= dmin*2;

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 892
import Control.Monad
import Data.Char
import Data.List
import Data.Maybe

main = sol <$> getN <*> getD >>= print

getN = fmap read . words <$> getLine :: IO [Int]

getD = filter isDigit <$> getLine :: IO [Char]

sol (n:_) ds = fromJust $ find ok [n..]
  where
  ok = all (`notElem` ds) . show

Measured memory_bytes: 1020
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <vector>
#include <cstdlib>
#include <utility>
#include <map>
#include <set>
#include <ios>
#include <iomanip>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    int nums[n];
    int sum = 0;
    for(int i = 0; i < n; i++){
        if(i == 0){
            pair<int, int> p;
            int x;
            cin >> x;
            nums[i] = x;
            p.first = abs(0 - x);
            sum += p.first;
            p.second = 0;
            v.push_back(p);
        }
        else if(i == 1){
            pair<int, int> p;
            int x;
            cin >> x;
            nums[i] = x;
            p.first = abs(nums[i - 1] - x);
            sum += p.first;
            p.second = abs(0 - x);
            v.push_back(p);
        }
        else{
            pair<int, int> p;
            int x;
            cin >> x;
            nums[i] = x;
            p.first = abs(nums[i - 1] - x);
            sum += p.first;
            p.second = abs(nums[i - 2] - x);
            v.push_back(p);
        }
        if(i == n - 1){
            pair<int, int> p;
            p.first = abs(nums[i] - 0);
            sum += p.first;
            p.second = abs(nums[i - 1] - 0);
            v.push_back(p);
        }
    }
    for(int i = 0; i < n; i++){
        cout << sum - v[i].first - v[i + 1].first + v[i + 1].second << "\n";
    }
}


Measured memory_bytes: 2548
// -*- coding:utf-8-unix -*-

use proconio::input;

fn to_rad(f: f64) -> f64 {
    f * std::f64::consts::PI / 180.0
}

fn calcHAngle(h: f64, m: f64) -> f64 {
    let hm = h * 60.0 + m;
    let theta = 0.5 * hm;
    if theta > 90.0 {
        to_rad(450.0 - theta)
    } else {
        to_rad(90.0 - theta)
    }
}

fn calcMAngle(m: f64) -> f64 {
    let theta = 6.0 * m;
    if theta > 90.0 {
        to_rad(450.0 - theta)
    } else {
        to_rad(90.0 - theta)
    }
}

fn calcPoint(l: f64, rad: f64) -> (f64, f64) {
    let x = l * rad.cos();
    let y = l * rad.sin();
    (x, y)
}

fn calcDistance(a: (f64, f64), b: (f64, f64)) -> f64 {
    let x = (b.0 - a.0) * (b.0 - a.0);
    let y = (b.1 - a.1) * (b.1 - a.1);
    let r = x + y;
    r.sqrt()
}

fn main() {
    input! {
        abhm: (f64, f64, f64, f64),
    }
    let a = abhm.0;
    let b = abhm.1;
    let h = abhm.2;
    let m = abhm.3;

    let a_angle = calcHAngle(h, m);
    let b_angle = calcMAngle(m);

    let a_p = calcPoint(a, a_angle);
    let b_p = calcPoint(b, b_angle);

    println!("{}", calcDistance(a_p, b_p));
}


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

double t1,t2;

int main(){
	while(scanf("%lf %lf",&t1,&t2)!=EOF){
		if(t1<35.5 && t2<71.00)printf("AAA\n");
		else if(t1<37.5 && t2<77.00)printf("AA\n");
		else if(t1<40.0 && t2<83.00)printf("A\n");
		else if(t1<43.0 && t2<89.00)printf("B\n");
		else if(t1<50.0 && t2<105.00)printf("C\n");
		else if(t1<55.0 && t2<116.00)printf("D\n");
		else if(t1<70.0 && t2<148.00)printf("E\n");
		else printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 608
import math
def factorization(N):
  tmp=N
  F=[]
  for i in range(2,int(math.sqrt(N))+1):
    if tmp%i==0:
      F.append(i)
      tmp//=i
    while tmp%i==0:
      tmp//=i
    if i>tmp:
      break
  if tmp!=1:
    F.append(tmp)
  return F

N=int(input())
F=factorization(N)
ans=0
for f in F:
  ff=f
  while N%ff==0:
    ans+=1
    N//=ff
    ff*=f
  while N%f==0:
    N//=f
print(ans)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

const ll INF = LLONG_MAX;
const int MAX_V = 100010;

struct edge{int to, cost;};
typedef pair<int, int> P;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(int s){
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0,s));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        for(int i = 0; i < G[v].size(); i++){
            edge e = G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main(){
    ll N, M;
    cin >> N >> M;
    V = N;
    REP(i,M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(edge{b,1});
        G[b].push_back(edge{a,1});
    }

    dijkstra(0);

    vector<ll> ANS(N);
    bool valid = true;
    for(int v = 1; v < N; v++){
        ll dist = d[v];
        ll ans = -1;
        for(auto&& p : G[v]){
            ll tmp = d[p.to];
            if(tmp == dist - 1){
                ans = p.to;
                break;
            }
        }

        if(ans == -1)
            valid = false;
        ANS[v] = ans+1;
    }

    if(!valid)
        cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        for(int v = 1; v < N; v++){
            cout << ANS[v] << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 13648
//itp1_topic9_A
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
using namespace std;
char tolower(char);

int main(){
  int count=0;
  string w;
  cin>>w;
  string str;
  while(1){
    cin>>str;
    if(str=="END_OF_TEXT")break;
    for(int i=0;i<(int)str.size();i++){
      str[i]=tolower(str[i]);
    }
    if(str==w){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}

char tolower(char ch){
  if(ch>='A' && ch<='Z'){
    return ch-'A'+'a';
  }
  else return ch;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define li          long
#define ll          long long
#define ull         unsigned long long
#define ff          first
#define ss          second
#define pii         pair<int,int>
#define pli         pair<li,li>
#define pll         pair<ll,ll>
#define pb          push_back
#define fo(i,k,n)   for(int i = k;i<n; i++)
#define ro(i,k,n)   for(int i = k; i>=n; i--)
#define tc          int t;cin>>t;while(t--)
#define all(v)      v.begin(),v.end()
#define inf         INT_MAX
#define ninf        INT_MIN
#define W(x)        cout<<x<<endl
#define WW(x,y)     cout<<x<<' '<<y<<endl;
#define in(x)       cin>>x
#define v(x)        vector<x>
#define int         long long
#define ar(x,y)       array<x,y>
const ll mod1 = 99844353;
const ll mod2 = 1e9+7;
template <class T>
using oset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

template<class T>
T power(T a,T b){
    T res = (T)1;
    while(b>0){
        if(b&1)res = res*a;
        b>>=1;
        a*=a;
    }
    return res;
}
struct dsu{
  map<int,int> pr,sz;
  dsu(){
    (this->pr).clear();
    (this->sz).clear();
  }
  void make(int x){
    pr[x] = x;
    sz[x] = 1;
  }
  int getpar(int x){
    if(pr[x] == x)return x;
    return pr[x] = getpar(pr[x]);
  }
  void merge(int x,int y){
    x = getpar(x);
    y = getpar(y);
    if(sz[x]<sz[y])swap(x,y);
    pr[y] = x;
    sz[x]+=sz[y];
    sz[y] = 0;
  }
};


void solve(){
  char x;
  cin>>x;
  cout<<(x>'Z'?'a':'A')<<"\n";
}

signed main(){
    fastio();
    int t = 1;
    //cin>>t;
    while(t--){
        solve();
    }
}


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

// 最終チェック
long long N, A[87];
 
int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) cin >> A[i];

	assert(2 <= N && N <= 80);
	for (int i = 1; i <= N; i++) assert(100 <= A[i] && A[i] <= 200);

	long long ret = 1000;
	for (int i = 1; i <= N - 1; i++) {
		if (A[i] >= A[i + 1]) continue;
		long long kabu = ret / A[i];
		ret += (A[i + 1] - A[i]) * kabu;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3552
n = int(input())
a = tuple(map(int,input().split()))

def check(mode):
    ans,s = 0,0
    if mode:##奇数番目が正
        for i in range(n):
            s += a[i]
            if i%2 == 0:
                if s <= 0:
                    ans += abs(s)+1
                    s = 1
            else:
                if s >= 0:
                    ans += abs(s)+1
                    s = -1
    else:
        for i in range(n):
            s += a[i]
            if i%2 == 0:
                if s >= 0:
                    ans += abs(s)+1
                    s = -1
            else:
                if s <= 0:
                    ans += abs(s)+1
                    s = 1
    return ans

print(min(check(True),check(False)))


Measured memory_bytes: 14596
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>

using namespace std;


int main() {
	int i, j, k;
	int n, m, x, y;
	vector<int>xx, yy;
	vector<bool>flag(205, false);

	cin >> n >> m >> x >> y;

	int maxx = -222, miny = 99999;

	for (i = 0; i < n; i++) {
		int num;
		cin >> num;
		xx.push_back(num);
		maxx = max(maxx, num);
	}

	for (i = 0; i < m; i++) {
		int num;
		cin >> num;
		yy.push_back(num);
		miny = min(miny, num);
	}

	bool fflag = false;
	int nnnn;

	for (i = x + 1; i <= y; i++) {
		if (i > maxx && i <= miny) {
			fflag = true;
			nnnn = i;
		}
	}

	if (fflag == false) {
		cout << "War" << endl;
	}
	else {
		cout << "No War" << endl;
	}

	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
S = gets.chomp
ans=true
if S[0]!="A"
    ans=false
end
if S[2..-2].include?("C")
    x=S[1..-2].index("C")
    S[1..-1].split('').each_with_index do |s,i|
        next if i==x
        if s==s.upcase
            ans=false
            break
        end
    end
else
    ans=false
end
puts ans ? "AC" : "WA"

Measured memory_bytes: 14376
#include "bits/stdc++.h"
#define ll long long
#define ull unsigned long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
#define ti4 tuple<int,int,int,int>
int MOD=1000000000+7;
int INF=1e9;
 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");
char a[1000][1000]={};
int h,w,k;
pii search(){
    rep2(i,1,h){
        rep2(j,1,w){
            if(a[i][j]=='S') return {i,j};
        }
    }
}
void start(){
    pii temp=search();
    int m;
    queue<ti3> q;
    q.push(make_tuple(temp.first,temp.second,0));
    rep(j,k){
      	m=q.size();
        rep(i,m){
        ti3 t=q.front();
        q.pop();
        if(get<0>(t)+1!=h+1){if(a[get<0>(t)+1][get<1>(t)]=='.') {
            a[get<0>(t)+1][get<1>(t)]='S';
            q.push(make_tuple(get<0>(t)+1,get<1>(t),get<2>(t)+1));
        }}
        if(get<0>(t)-1!=0){if(a[get<0>(t)-1][get<1>(t)]=='.') {
            a[get<0>(t)-1][get<1>(t)]='S';
            q.push(make_tuple(get<0>(t)-1,get<1>(t),get<2>(t)+1));
        }}
        if(get<1>(t)+1!=w+1){if(a[get<0>(t)][get<1>(t)+1]=='.') {
            a[get<0>(t)][get<1>(t)+1]='S';
            q.push(make_tuple(get<0>(t),get<1>(t)+1,get<2>(t)+1));
        }}
        if(get<1>(t)-1!=0){if(a[get<0>(t)][get<1>(t)-1]=='.') {
            a[get<0>(t)][get<1>(t)-1]='S';
            q.push(make_tuple(get<0>(t),get<1>(t)-1,get<2>(t)+1));
        }}
    }}
}
int GO(){
    int ans=INF;
    rep2(i,1,h){
        rep2(j,1,w){
            if(a[i][j]=='S'){
                if(i==1||i==h||j==1||j==w) ans=0;
                else{
                    ans=min(ans,(min({i-1,h-i,j-1,w-j})+k-1)/k);
                }
            }
        }
    }
    return ans;
}
main(){
    cin>>h>>w>>k;
    rep(i,h+1){
        rep(j,w+1) a[i][j]='#';
    }
    rep2(i,1,h){
        rep2(j,1,w){
            cin>>a[i][j];
        }
    }
    start();
    cout<<GO()+1<<endl;
    return 0;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
int H, W, K;
int items[3000][3000];
long long dp[3000][3000][4];

int main() {
  cin >> H >> W >> K;
  rep(i, K) {
    int x, y, z;
    cin >> x >> y >> z;
    items[--x][--y] = z;
  }
  
  dp[0][0][0] = 0;  
  rep(i, H) {
    rep(j, W) {
      // 現在地で拾う場合
      rep(k, 3) {
        dp[i][j][3-k] = max(dp[i][j][3-k], dp[i][j][2-k] + items[i][j]);
      }
      
      // 右のマスを更新(右で拾わなかった場合）
      if (j + 1 < W) {
        rep(k, 4) {
          dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
        }      
      }
      
      // 下のマスを更新
      if (i + 1 < H) {
        rep(k, 4) {
          dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
        }
      }
    }
  }
  
  long long ans = 0;
  rep(i, 4) {
    ans = max(ans, dp[H-1][W-1][i]);
  }
  cout << ans;
}

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

int gcd(int a, int b);

int main() {

    int K;
    cin >> K;

    int ans = 0;
    for (int a = 1; a <= K; a++) {
        for (int b = 1; b <= K; b++) {
            for (int c = 1; c <= K; c++) {
                ans += gcd(a, gcd(b, c));
            }
        }
    }
    cout << ans << endl;

    return 0;
}

int gcd(int a, int b) {

    if (a % b == 0) return b;
    else return gcd(b, a%b);
}

Measured memory_bytes: 3640
n,k = map(int, input().split())
x = list(map(int, input().split()))
ans = float("inf")
for i in range(n-k+1):
  l = x[i]
  r = x[i+k-1]
  if l >= 0:
    dis = r
  elif r <= 0:
    dis = -l
  else:
    dis = min(r-2*l,r*2-l)
  if dis < ans:
    ans = dis
print(ans)


Measured memory_bytes: 14224
import random

def rotateDice(direction: str, dice: dict) -> dict:
    if direction == 'S':
        dice['S'], dice['F'], dice['N'], dice['B'] = dice['F'], dice['N'], dice['B'], dice['S']
    elif direction == 'E':
        dice['E'], dice['F'], dice['W'], dice['B'] = dice['F'], dice['W'], dice['B'], dice['E']
    elif direction == 'W':
        dice['W'], dice['F'], dice['E'], dice['B'] = dice['F'], dice['E'], dice['B'], dice['W']
    elif direction == 'N':
        dice['N'], dice['F'], dice['S'], dice['B'] = dice['F'], dice['S'], dice['B'], dice['N']
    return dice


dice_list = list(map(int, input().split()))
dice = {'FSEWNB'[i]: dice_list[i] for i in range(6)}
for i in range(int(input())):
    f, s = map(int, input().split())
    while True:
        dice = rotateDice(random.choice(['S', 'E', 'W', 'N']), dice)
        if dice['F'] == f and dice['S'] == s:
            print(dice['E'])
            break



Measured memory_bytes: 8236
main = do
    let readLine = return . map read . words =<< getLine
    [n_,x_] <- readLine
    as <- readLine
    let reduce [a1,a2]
	  | a1+a2 <= x_	= 0
	  | otherwise	= (a1+a2) - x_
	reduce (a1:a2:as)
	  | a1+a2 <= x_	    = reduce (a2:as)
	  | otherwise	    = let   over = (a1+a2)-x_
				    a2' = maximum [0,a2-over]
		in over + reduce (a2':as)
    print $ reduce as

Measured memory_bytes: 36220
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input!{
        n: usize,
        v: [i64; n]
    }
    let mut ans_p = 0;
    let mut sum_p = 0;
    let mut ans_m = 0;
    let mut sum_m = 0;
    for i in 0..n {
        if i % 2 == 0 {
            let d_p = cmp::max(0, 1 - sum_p - v[i]);
            ans_p += d_p;
            sum_p += v[i] + d_p;
            let d_m = cmp::max(0, 1 + sum_m + v[i]);
            ans_m += d_m;
            sum_m += v[i] - d_m;
        } else {
            let d_p = cmp::max(0, 1 + sum_p + v[i]);
            ans_p += d_p;
            sum_p += v[i] - d_p;
            let d_m = cmp::max(0, 1 - sum_m - v[i]);
            ans_m += d_m;
            sum_m += v[i] + d_m;
        }
    }
    println!("{}",cmp::min(ans_p,ans_m));
}


Measured memory_bytes: 4352
def main():
    n,q=map(int,input().split())
    H,V=[0]*(n+1),[0]*(n+1)
    h,v=n,n
    cnt=0
    for _ in range(q):
        s,x=map(int,input().split())
        if s==1:
            if x<v:
                cnt+=h-2
                for i in range(x,v):
                    H[i]=h
                v=x
            else:
                cnt+=H[x]-2
        if s==2:
            if x<h:
                cnt+=v-2
                for i in range(x,h):
                    V[i]=v
                h=x
            else:
                cnt+=V[x]-2
    print((n-2)**2-cnt)
    
if __name__=='__main__':
    main()

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

// 定義
typedef long long         ll;
typedef pair<ll, ll>      P;
#define ALL(x)            (x).begin(),(x).end()
#define REP(i, n)         for(ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)     for(ll i = m ; i < (ll)n ; ++i)
#define REVREP(i, n)      for(ll i = n - 1; i >= 0 ; i--)
#define VL                vector<ll>
#define VVL               vector<vector<ll>>
#define VVVL              vector<vector<vector<ll>>>
#define VC                vector<char>
#define VVC               vector<vector<char>>
#define INF               (ll)2e9
#define INF_LL            1LL<<60
//#define MOD             998244353
#define MOD               1000000007

ll Ceil(ll val, ll div)   { return (val + div - 1) / div; }
ll CeilN(ll val, ll div)  { return Ceil(val, div) * div; }
ll FloorN(ll x, ll n)     { return (x - x % n); }
bool IsOdd(ll x)          { return ((x & 1) == 1); }
bool IsEven(ll x)         { return ((x & 1) == 0); }
template<class T> bool chmax(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }

void Solve()
{
	ll A, B, C, K;
	cin >> A >> B >> C >> K;

	ll cnt = 0;
	while (1) {
		if (A < B) break;
		B *= 2;
		cnt++;
	}
	while (1) {
		if (B < C) break;
		C *= 2;
		cnt++;
	}

	string ans = cnt <= K ? "Yes" : "No";
	cout << ans << endl;
}

// メイン
int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Solve();
	return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  int K;
  cin >> K;
  int wk = 0;
  int multiply = 1;    
  rep(i,K+10) {
    wk += 7 * multiply;
    if (wk % K == 0) {
      cout << i+1 << endl;
      return 0;
    }      
    wk %= K;
    multiply = multiply * 10 % K;
  }
  cout << -1 << endl;
  return 0;
}

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

d = {}
for i in range(n):
  s = input()
  if s in d:
    d[s] += 1
  else:
    d[s] = 1

m = max(d.values())
ans = []

for k, v in d.items():
  if v == m:
    ans.append(k)
ans.sort()
print(*ans, sep = "\n")


Measured memory_bytes: 94864
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[200010], b[200010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=2; i<=n; ++i){
            scanf("%d",a+i);
            ++b[a[i]];
        }
        for(int i=1; i<=n; ++i){
        	// b[i]=b[a[i]]+1;
        	printf("%d\n",b[i]);
        }
    }
  return 0;
}




Measured memory_bytes: 5284
import sys
sys.setrecursionlimit(10**6)
h, w = map(int, input().split())

field = [list(input()) for _ in range(h)]

dp = [[None] * w for _ in range(h)]
# def dfs(hindex=h - 1, windex=w - 1):
#     if field[hindex][windex] == "#":
#         return 0
#     if hindex == windex == 0:
#         return 1
#
#     if dp[hindex][windex] is not None:
#         return dp[hindex][windex]
#     r = (hindex and dfs(hindex - 1, windex)) + (windex and dfs(hindex, windex - 1))
#     dp[hindex][windex] = r
#     return r
#
# print(dfs() % (10**9 + 7))

for hindex in range(h):
    for windex in range(w):
        if hindex == windex == 0:
            dp[hindex][windex] = 1
        elif field[hindex][windex] == "#":
            dp[hindex][windex] = 0
        else:
            dp[hindex][windex] = (hindex and dp[hindex - 1][windex]) + (windex and dp[hindex][windex - 1])
print(dp[hindex][windex] % (10**9 + 7))


Measured memory_bytes: 246364
// inputに入力データ全体が入る
function Main(input) {
  
  var inp = input.split(" ");
  var A = parseInt(inp[0]);
  var B = parseInt(inp[1]);
  var flg = false;
  for (var C = 1; C <= 3; C++){
      if(A * B * C % 2 === 1){
        flg = true;
        break;
      }
  }

  if (flg) {
    console.log('%s', 'Yes');
  } else {
    console.log('%s', 'No');
  }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

using namespace std;

#define ll long long
#define INF 999999999
#define MOD 1000000007

int main()
{
	int x,y;
	cin >> x;
	cin >> y;
	if((x < y) && (x >= 0 || y <= 0)){
		cout << y-x;
	}else if((y < x) && (x < 0 || y > 0)){
		cout << x-y+2;
	}else if((y < x) && (x == 0 || y == 0)){
		cout << x-y+1;
	}else{
		cout << abs(x+y)+1;
	}
}


Measured memory_bytes: 384
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(){
    char search[21], word[21];
    int count=0;
    int i;
    
    scanf("%s", search);
    while(1){
        scanf(" %s", word);
        if(strcmp(word, "END_OF_TEXT")==0)break;
        for(i=0;word[i]!='\0';i++){
            word[i]=tolower(word[i]);
        }
        if(strcmp(word, search)==0){
            count++;
        }
    }
    printf("%d\n", count);

    return 0;
}


Measured memory_bytes: 2820
#include <stdio.h>
#include <string.h>
int main()
{
    int i,a,j,b=0;
    char txt[27];
    scanf("%[^\n]",txt);
    a=strlen(txt);
    for(i=0;i<a;i++){
        for(j=i+1;j<a;j++){
            if(txt[i]==txt[j]){
                b=b+1;
            }
            else b=b;
        }

    }
    if(b>0){
       printf("no\n");

       }
       else printf("yes\n");

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define int64_t long long
constexpr int64_t MOD=1e9+7;
int main() {
    int n;
    cin>>n;
    vector<pair<int,int>>v;
    for(int i=0;i<n;++i){
        int a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }
    sort(v.begin(),v.end());
    int64_t t=0;
    for(int i=0;i<n;++i){
        t+=v[i].second;
        if(t>v[i].first){
            printf("No\n"); return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2420
N = int(input())
L = []
for i in range(N):
    l = list(map(int, input().split()))
    L.append(l)

L.sort(key=lambda x: (x[1],x[0]))

cnt = 0
flag = True
for i in range(N):
    #cnt += L[0][i]
#    print(L[i][0])
    cnt += L[i][0]
    #if cnt <= L[i][1]:
    if cnt > L[i][1]:
        flag = False
        break

if flag == True:
    print("Yes")
else:
    print("No")


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

using namespace std;

const int MAX = 100123;
vector <int> adj[MAX];
int n , m;
int h[100123];
int max_outers_h[100123];
int ans = 0;
int main()
{
    cin.tie(NULL);
    ios_base::sync_with_stdio(0);

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        max_outers_h[i] = INT_MIN;

    for (int i = 1; i <= n; i++)
        cin >> h[i];

    for (int i = 1; i <= m; i++)
    {
        int o1, o2;
        cin >> o1 >> o2;
        adj[o1].push_back(o2);
        if (h[o2] > max_outers_h[o1])
            max_outers_h[o1] = h[o2];
        adj[o2].push_back(o1);
        if (h[o1] > max_outers_h[o2])
            max_outers_h[o2] = h[o1];
    }

    for (int i = 1; i<=n;i++)
    {
        if ((h[i] > max_outers_h[i]) || (adj[i].size() == 0))
            ans++;
    }
    
    cout << ans << endl;

    
    return 0;
}

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

long long dp[1001][4098],ara[1002][13],tra[1002][2],n,m,mx=99999999999;

int on(int x,int ps)
{
    return x | (1<<ps);
}


bool ck(int x,int ps)
{
    return (bool)(x & (1<<ps));
}


long long solve(long long idx,long long mask)
{

    if(idx==m)
    {
        long long z; z=pow(2,n); z--;


        if(mask==z)return 0;
        else{  return mx;  }
    }
    else if(dp[idx][mask]!=-1)return dp[idx][mask];
    else
    {
        long long p,q,s,fr,sc,x,y,sz,cst,j;

        int r;

        p=solve(idx+1,mask);

        sz=tra[idx][1]; cst=tra[idx][0];

        r=mask;

        for(j=0;j<sz;j++)
        {
            s=ara[idx][j];

            if(ck(r,s)==false)
            {
                r=on(r,s);
            }

        }

        q=cst+solve(idx+1,r);

        dp[idx][mask]=min(p,q);  return dp[idx][mask];



    }


}

int main()
{


    long long i,j,a,b,c,ans;
    scanf("%lld %lld",&n,&m);

    for(i=0;i<m;i++)
    {
        scanf("%lld %lld",&a,&b); tra[i][0]=a; tra[i][1]=b;

        for(j=0;j<b;j++)
        {
            scanf("%lld",&c);  ara[i][j]=c-1;

        }

    }

    memset(dp,-1,sizeof dp);

    ans=solve(0,0);

    if(ans<mx)printf("%lld\n",ans);
    else
    {
        printf("-1\n");
    }



    return 0;
}





Measured memory_bytes: 36332
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var m = cin.nextInt();
            var a = cin.ArrayLong(n);

            var sum = a.Sum();
            decimal d = a.Sum() * (decimal)(1 / (4.0 * m));

            Array.Sort(a);
            Array.Reverse(a);

            var count = 0l;
            for (int i = 0; i < n; i++) 
            {
                if (a[i] < d && count < m)
                {
                    Console.WriteLine("No");
                    return;
                }
                count++;
            }
            
            Console.WriteLine("Yes");
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int MAXN = 1e5+7;
#define lop(i,a,b) for(register int i = (a); i <= (b); ++i)
#define dlop(i,a,b) for(register int i = (a); i >= (b); --i)
#define read2(a, b) (read(a), read(b))
#define read3(a, b, c)  (read(a), read(b), read(c))
template<class T> void chmax(T &a, T b) {if (a < b) a = b;}
template<class T> void chmin(T &a, T b) {if (a > b) a = b;}
inline void update(int &x, int y) {x += y; if (x >= mod) x -= mod;}

template<class T> void read(T & x) {
  register int c = getchar(), f = 1; x = 0;
  while(!isdigit(c)) (c=='-')&&(f=-f), c = getchar();
  while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * f;
}
long long a[4];
long long ans;
int k;

int main(void) {
  cin >> a[1] >> a[2] >> a[3] >> k;
  sort(a+1, a+4);
  ans = a[1] + a[2] + a[3]*(1<<k);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 998244353
#define ll long long
using namespace std;
ll dp[3001][3001], pre[3001][3001];

int main(){
    ll n,s;
    cin>>n>>s;
    ll a[n];
    for(ll i=0; i<n; i++){
        cin>>a[i];
    }
    //dp[i][j] stores sum of left ends of all those subsequences having sum sum j and ending at i
    //pre[i][j] stores sum of all left endpoints having sum j and including only upto i terms
    memset(pre, 0, sizeof(pre));
    for(ll j=0; j<=s; j++){
//        cout<<"With Sum "<<j<<": ";
        for(ll i=0; i<=n; i++){
            if(i==0 || j==0){   // i==0 means no element included
                // j==0 means sum 0
                dp[i][j] = 0;
            }
            else if(j==a[i-1]){
                dp[i][j] = i; //Starting and ending at i
            }else if(j>a[i-1]){
                //Ending at 'i' and sum is equal to j
                dp[i][j] = pre[i-1][j-a[i-1]];
            }else{
                dp[i][j] = 0;
            }
            if(i>0){
                pre[i][j] = pre[i-1][j] + dp[i][j];
                pre[i][j] %= mod;
            }
            dp[i][j] %= mod;
//            cout<<dp[i][j]<<" ";
        }
//        cout<<endl;
    }
    ll ans=0;
    for(ll i=1; i<=n; i++){
        ans += (dp[i][s]*(n-i+1))%mod;
        ans %= mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 140928
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	int n; cin >> n;
	vector<int> a(n),b(n),c(n-1);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
		cin >> b[i];
	}
	for(int i=0;i<n-1;i++){
		cin >> c[i];
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(i==0){
			ans+=b[a[i]-1];
		}
		else{
			ans+=b[a[i]-1];
			if(a[i-1]+1==a[i]){
				ans+=c[a[i-1]-1];
			}
		}
	}
	cout << ans << endl;
}

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

unsigned long long b[100], c[100][31];
#define bit(n) (1LL<<(n))

int main()
{
    int n;
    while (cin>>n, n) {
        memset(c, 0, sizeof(c));
        for(int i=0;i<n;++i) {
            int m; cin>>m;
            b[i]=0;
            while (m--) {
                int t; cin>>t; b[i]|=bit(t);
            }
            c[i][0]=bit(i);
        }
        unsigned res=-1u;
        for(unsigned d=1;d<=30;++d) {
            for(int i=0;i<n;++i) {
                c[i][d]=c[i][d-1];
                if (b[i]&bit(d)) for(int j=0;j<n;++j) if ((b[j]&bit(d))) c[i][d]|=c[j][d-1];
                if (c[i][d]==bit(n)-1) {
                    res=d;
                    goto END;
                }
            }
        }
END:
        cout<<(int)res<<endl;
    }
}

Measured memory_bytes: 1192
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * 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;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
            }
            int ans = 0;

            ans = gcd(a[0], a[1]);
            for (int i = 2; i < n; i++) {
                ans = gcd(ans, a[i]);
            }

            // 出力
            out.println(ans);

        }

        public static int gcd(int num1, int num2) {
            if (num2 == 0) return num1;
            else return gcd(num2, num1 % num2);
        }

    }
}



Measured memory_bytes: 60008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200025,inf=0x3f3f3f3f;
int read(){
	int f=1,g=0;
	char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
	for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
	return f*g;
}
int gcd(int x,int y){
	if (!y) return x;
	int r=x%y;
	while (r){
		x=y;y=r;r=x%y;
	}
	return y;
}
int n,a[N],pr[N],m,h[N];
set<int> ans;
void check(int p){
	for (int i=0;i<p-1;i++) h[i]=0;
	for (int i=0;i<=n;i++){
		int x=i%(p-1);
		h[x]=(h[x]+a[i])%p;
	}
	for (int i=0;i<p-1;i++) if (h[i]) return;
	ans.insert(p);
}
int main(){
//	freopen("num.in","r",stdin);
//	freopen("num.out","w",stdout);
	n=read();m=0;
	for (int i=n;i>=0;i--){
		a[i]=read();
		m=gcd(m,abs(a[i]));
	}
	for (int i=2;i*i<=m;i++)
	if (m%i==0){
		ans.insert(i);
		while(m%i==0) m/=i;
	}
	if (m!=1) ans.insert(m);
	for (int i=2;i<=n;i++)
	if (!pr[i]){
		if (a[0]%i==0) check(i);
		for (int j=i+i;j<=n;j+=i) pr[j]=1;
	}
	for (auto x : ans) printf("%d\n",x);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define maxn 200666
using namespace std;
vector<int> X[maxn], Y[maxn], XY[maxn * 2], YX[maxn * 2];
int x[maxn], y[maxn];
char u[maxn];
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d%d %c", x + i, y + i, u + i);
	for(int i = 1; i <= n; ++i) {
		X[x[i]].push_back(i);
		Y[y[i]].push_back(i);
		XY[x[i] + y[i]].push_back(i);
		YX[x[i] - y[i] + maxn].push_back(i);
	}
	for(int i = 0; i < maxn; ++i) {
		sort(X[i].begin(), X[i].end(), [&](int a, int b){return y[a] < y[b];});
		sort(Y[i].begin(), Y[i].end(), [&](int a, int b){return x[a] < x[b];});
	}
	for(int i = 0; i < 2 * maxn; ++i) {
		sort(XY[i].begin(), XY[i].end(), [&](int a, int b){return x[a] < x[b];});
		sort(YX[i].begin(), YX[i].end(), [&](int a, int b){return x[a] < x[b];});
	}
	int Ans = 0x3F3F3F3F;
	for(int i = 0; i < maxn; ++i) {
		if(X[i].size() >= 2) {
			int lasU = -1;
			for(int o : X[i]) {
				if(u[o] == 'U') lasU = o;
				else if(u[o] == 'D') {
					if(lasU != -1) {
						Ans = min(Ans, 5 * (y[o] - y[lasU]));
					}
				}
			}
		}
	}
	for(int i = 0; i < maxn; ++i) {
		if(Y[i].size() >= 2) {
			int lasR = -1;
			for(int o : Y[i]) {
				if(u[o] == 'R') lasR = o;
				else if(u[o] == 'L') {
					if(lasR != -1) {
						Ans = min(Ans, 5 * (x[o] - x[lasR]));
					}
				}
			}
		}
	}
	for(int i = 0; i < 2 * maxn; ++i) {
		if(XY[i].size() >= 2) {
			int lasR = -1, lasD = -1;
			for(int o : XY[i]) {
				if(u[o] == 'R') lasR = o;
				else if(u[o] == 'D') lasD = o;
				else if(u[o] == 'U') {
					if(lasR != -1) {
						Ans = min(Ans, 10 * (x[o] - x[lasR]));
					}
				} else if(u[o] == 'L') {
					if(lasD != -1) {
						Ans = min(Ans, 10 * (x[o] - x[lasD]));
					}
				}
			}
		}
		if(YX[i].size() >= 2) {
			int lasR = -1, lasU = -1;
			for(int o : YX[i]) {
				if(u[o] == 'R') lasR = o;
				else if(u[o] == 'U') lasU = o;
				else if(u[o] == 'D') {
					if(lasR != -1) {
						Ans = min(Ans, 10 * (x[o] - x[lasR]));
					}
				} else if(u[o] == 'L') {
					if(lasU != -1) {
						Ans = min(Ans, 10 * (x[o] - x[lasU]));
					}
				}
			}
		}
	}
	if(Ans == 0x3F3F3F3F) puts("SAFE");
	else printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 52448
def calc():
  n,k=map(int,input().split())
  arr=list(map(int,input().split()))
  flag=format(k,'b')[::-1]
  l=len(flag)
  xor1=0
  xor2=0
  cnt=0
  check=False
  for i in range(l-1,-1,-1):
    if check==False and flag[i]=='0':
      continue
    for j in arr:
      if j&(2**i)!=0:
        cnt+=1
    if cnt<=n//2:
      if i!=l-1:
        xor1+=2**i
      if check==True or flag[i]=='1':
        xor2+=2**i
    else:
      if flag[i]=='1':
        check=True
    cnt=0
  ans1=0
  ans2=0
  for i in arr:
    ans1+=i^xor1
    ans2+=i^xor2
  print(max(ans1,ans2))

calc()

Measured memory_bytes: 15144
h,w,k = map(int,input().split())
c = []
for i in range(h):
    c.append(tuple(input()))
res = 0
for maskh in range(1<<h):
    for maskw in range(1<<w):
        brack = 0
        for i in range(h):
            for j in range(w):
                if (maskh >> i) & 1 and (maskw >> j) & 1:
                    if c[i][j] == '#': brack += 1
        if brack == k:
            res += 1
print(res)

Measured memory_bytes: 9192
import numpy as np

D=int(input())#365
c=list(map(int,input().split()))
s=np.array([])
for i in range(D):
#  if(i<16):
#    print((i+10)%26+1)
#  else:
  s=np.array([input().split()], dtype=np.int64)
  max_space=np.argmax(s)
  print(max_space+1)

Measured memory_bytes: 27132
I=input
n,d,x=map(int,I().split())
w=[list(map(int,I().split()))for i in range(d)];d-=1
p=[[w[i+1][j]-w[i][j]for j in range(n)]for i in range(d)]
b=x
for i in range(d):
    dp = [False for j in range(b+1)]
    dp[0]=0
    for j in range(n):
        for k in range(b):
            if w[i][j]+k<b+1 and id(dp[k])!=False:
                dp[k+w[i][j]]=max(dp[k+w[i][j]],dp[k]+p[i][j])
    b+=max(dp[:b+1])
print(b)

Measured memory_bytes: 8836
#include<bits/stdc++.h>
#include <assert.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int dp[2][(1 << 16)] = {0};
        //memset(dp, -1, sizeof(dp));
        dp[0][0] = 0;

        rep(i,n){
            int m, l;
            int s, e;
            int mask = 0;

            cin >> m >> l;
            rep(j,m){
                cin >> s >> e;
                s-=6;
                e-=6;
                for(int k = s; k < e; k++){
                    mask |= (1 << k);
                }
            }
            rep(j,(1 << 16)){
                if(dp[i % 2][j] == -1) continue;
                if(j & mask) continue;
                dp[(i + 1) % 2][j | mask] = max(dp[(i + 1) % 2][j | mask], dp[i % 2][j] + l);
            }
            memcpy(dp[i % 2], dp[(i + 1) % 2], sizeof(dp[i % 2]));
        }
        int ans = 0;
        rep(i,(1 << 16)){
            ans = max(ans, dp[n % 2][i]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3572
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
  char str[20];
  char mae[6],naka[8],ato[6],com[2],comm[2];

  fgets(mae,6,stdin);
  fgets(com,2,stdin);
  fgets(naka,8,stdin);
  fgets(comm,2,stdin);
  fgets(ato,6,stdin);
  
  printf("%s %s %s",mae,naka,ato);
  return 0;
}


Measured memory_bytes: 128
//JSD
#include<iostream>
#include<vector>
using namespace std;
#define ll long long 
vector<pair< ll ,ll > > v;
 ll n,W;
int main(){
	cin>>n>>W;
	for(int i=0;i<n;i++){
		ll a,b;
		cin>>a>>b;
		v.push_back({a,b});
	}
	ll dp[n+1][W+1];
	for(int i=0;i<=W;i++){
		if(v[n-1].first<=i)
			dp[n][i]=v[n-1].second;
		else
			dp[n][i]=0;
	}
	for(int i=n-1;i>0;i--){
		for(int j=0;j<=W;j++){
			ll p=0;
			if(j-v[i-1].first>=0){
				p=dp[i+1][j-v[i-1].first]+v[i-1].second;
			}
			ll q=dp[i+1][j];
			dp[i][j]=max(p,q);
		}
	}
	cout<<dp[1][W];
	return 0;	
}

Measured memory_bytes: 78336