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

#define int long long
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)

int MAX = 100000;
int cost_all[200020];
int cost_single[200020];

using pii = pair<int, int>;

using Point = complex<double>;

const double EPS = 1e-6;

double dp[21][21][10010];
double ang(Point a, Point b) {
    Point c = b - a;
    return atan2(c.imag(), c.real());
}
const double pi = acos(-1);
void init() {}
bool canmove[20][20][20];
bool solve() {
    int N;
    cin >> N;
    double r, theta;
    cin >> r >> theta;
    theta = theta / 180 * pi;
    vector<Point> ps(N);
    REP(i, N) {
        double x, y;
        cin >> x >> y;
        ps[i] = {x, y};
    }
    int ans = 0;
    REP(i, N) REP(j, N) REP(c, 10010) dp[i][j][c] = 1e9;
    FOR(i, 1, N) {
        double d = abs(ps[i] - ps[0]);
        dp[0][i][1] = d;
        if (d < r + EPS) ans = 1;
    }

    REP(i, N) REP(j, N) REP(k, N) {
        if (i == j || j == k) continue;
        double t1 = ang(ps[i], ps[j]);
        double t2 = ang(ps[j], ps[k]);
        double t = max(t1, t2) - min(t1, t2);
        if (t > pi + EPS) t = 2 * pi - t;
        if (t < theta + EPS) canmove[i][j][k] = true;
    }
    FOR(c, 1, 10000) {
        REP(i, N) REP(j, N) {
            if (i == j) continue;
            if (dp[i][j][c] > r + EPS) continue;
            REP(k, N) {
                if (k == j) continue;
                if (canmove[i][j][k]) {
                    if (dp[j][k][c + 1] > dp[i][j][c] + abs(ps[j] - ps[k])) {
                        dp[j][k][c + 1] = dp[i][j][c] + abs(ps[j] - ps[k]);
                        if (dp[j][k][c + 1] < r + EPS && c + 1 > ans) ans = c + 1;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return false;
}
signed main() {
    init();
    while (solve())
        ;
}


Measured memory_bytes: 34820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long X = GetLong();
		long N = GetLong();
		var p = GetLongs(N);
		var ng = new bool[102];
		for(long i = 0; i < N; i++)
			ng[p[i]] = true;

		long ans = -1;
		long min = long.MaxValue;
		for(long i = 0; i <= 101; i++)
		{
			if(ng[i])
				continue;

			if(Abs(X - i) < min)
			{
				min = Abs(X - i);
				ans = i;
			}
		}
		WriteLine(ans);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 28388
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(All(A));
    int ans=0;
    ll s=0;
    REP(i,N){
        if(A[i]<=2*s){
            ans++;
        }
        else{
            ans=1;
        }
        s+=A[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
def main():
    n = int(input())
    a = list(map(int, input().split()))
    if 0 in a:
        print(0)
        return
    prod = 1
    for i in a:
        prod *= i
        if prod > 1000000000000000000:
            print(-1)
            return
    print(prod)
main()

Measured memory_bytes: 21596
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    String s[]=new String[n];
	    for(int i=0;i<n;i++) {
	    	s[i]=scan.next();
	    }
	    int m = scan.nextInt();
	    String t[]=new String[m];
	    for(int i=0;i<m;i++) {
	    	t[i]=scan.next();
	    }
	    scan.close();
	    int sum,max=0;
	    for(int i=0;i<n;i++) {
	    	sum=0;
	    	for(int j=0;j<n;j++) {
	    		if(s[i].equals(s[j]))sum+=1;
	    	}
	    	 for(int j=0;j<m;j++) {
	    		 if(s[i].equals(t[j]))sum-=1;
	    	 }
	    	 if(max<sum)max=sum;
	    }
	    System.out.println(max);
	}

}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N;
  N = S.size();
  vector<int> SS(N);
  vector<int> TT(N);
  map<char, int> SSS;
  map<char, int> TTT;
  int j = 0;
  int k = 0;
  for (int i = 0; i < N; i++){
    if(!(SSS.count(S.at(i)))){
      SSS[S.at(i)] = j;
      j++;
    }
    SS.at(i) = SSS.at(S.at(i));
    if(!(TTT.count(T.at(i)))){
      TTT[T.at(i)] = k;
      k++;
    }
    TT.at(i) = TTT.at(T.at(i));
  }
  if (SS == TT){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 2312
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
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; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N; cin >> N;
	VP A(N);
	REP(i, N) {
		cin >> A[i].first;
		A[i].second = i + 1;
	}
	SORT(A);
	set<int>S;
	S.insert(0LL);
	S.insert(N + 1);
	int ans = 0;
	REP(i, N) {
		int a = A[i].first;
		int j = A[i].second;
		int c = *S.upper_bound(j);
		auto b = S.lower_bound(j);
		b--;
		
		//cout << *b << " " << c << endl;
		ans += a * (j - *b)*(c - j);
		S.insert(j);
	}



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



Measured memory_bytes: 12800
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

[K,X] = inpl()
print(*list(range((X-K+1),(X+K))))

Measured memory_bytes: 12456
class RectangleCaliculator
  def calcArea(width, height)
    return width * height
  end
 
  def calcCircumference(width, height)
    return (width + height) * 2
  end
end
 
# 入力の横、縦の長さ取得
inputArray = gets.split(nil)
height = inputArray[0].to_i
width = inputArray[1].to_i
 
# 計算クラスを作成し、面積、周の長さを計算
rect = RectangleCaliculator.new
area = rect.calcArea(width, height)
circumference = rect.calcCircumference(width, height)
 
# 出力
puts area.to_s + " " + circumference.to_s


Measured memory_bytes: 6860
s = input()
o = ["R", "U", "D"]
e = ["L", "U", "D"]
for i, si in enumerate(s):
    if i % 2 == 0:
        if si not in o:
            print("No")
            exit()
    else:
        if si not in e:
            print("No")
            exit()
print("Yes")

Measured memory_bytes: 3060
#include <stdio.h>
 
int main(){
    int a,b,c,d;
    scanf("%d %d %d",&a,&b,&c);

    if(a>b){
        d=a;
        a=b;
        b=d;
    }
    if(b>c){
        d=b;
        b=c;
        c=d;
    }
    if(a>b){
        d=a;
        a=b;
        b=d;
    }
    printf("%d %d %d\n",a,b,c);
    return 0;
}

Measured memory_bytes: 596
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
    int h,w,ans=0; cin>>h>>w;
    vector<vector<char>> mp(h+2,vector<char>(w+2,'0'));
    char ch;
    rep(i,h){
        rep(j,w){
            cin>>ch; mp[i+1][j+1]=ch;
        }
    }
    int dx,dy;
    int cost,x,y,ans_;
    vector<pp> dir={mk(-1,0),mk(0,-1),mk(1,0),mk(0,1)};
    vector<vector<int>> dis;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(mp[i][j]!='.') continue;
            priority_queue<tuple<int,int,int>, vector<tuple<int,int,int>>, greater<tuple<int,int,int>>> pq;
            dis=vector<vector<int>>(h+2,vector<int>(w+2,inf));
            dis[i][j]=0; ans_=0;
            pq.push(make_tuple(0,i,j));
            while(!(pq.empty())){
                tie(cost,x,y)=pq.top(); pq.pop();
                if(cost!=dis[x][y]) continue;
                for(auto p : dir){
                    tie(dx,dy)=p;
                    if(mp[x+dx][y+dy]=='.' && dis[x+dx][y+dy]>cost+1){
                        dis[x+dx][y+dy]=cost+1;
                        pq.push(make_tuple(dis[x+dx][y+dy],x+dx,y+dy));
                        ans_=max(ans_,dis[x+dx][y+dy]);
                    }
                }
            }
            ans=max(ans,ans_);
        }
     }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n,r;
  cin>>n>>r;
  if(n<10){
  cout<<r+100*(10-n)<<endl;
  }
  else{
    cout<<r<<endl;
  }
}


Measured memory_bytes: 3612
B = input().split()

def stackcalc(S):
    now = S.pop()
    if now == '+':
        return stackcalc(S) + stackcalc(S)
    elif now == '-':
        return -(stackcalc(S) - stackcalc(S))
    elif now == '*':
        return stackcalc(S) * stackcalc(S)
    elif now == '/':
        return stackcalc(S) / stackcalc(S)
    else:
        return int(now)


print(stackcalc(B))


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

using namespace std;

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

    sort(a, a + 3);
    cout << a[0] * a[1] / 2 << endl;
    return 0;
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()

ll gcd(ll a, ll b);

ll sum(int n);

void go(){
   int r,D,x;cin>>r>>D>>x;
   for(int i=0;i<10;i++){
      int xi=r*x-D;
      x=xi;
      cout << x << endl;
   }
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

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

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Z,W; cin >> N >> Z>> W;
    VI a(N);
    REP(i,N) cin >> a[i];

    if(N != 1){
        cout << max(abs(W-a[N-1]), abs(a[N-1]-a[N-2])) << endl;
    }
    else{
        cout << abs(a[0]-W) << endl;
    }

}

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

int main(void){
  int n; cin >> n;
  int p[n];
  int q = 0;
  rep(i,n){
    cin >> p[i];
    if(p[i] != i+1) q++;
  }
  if(q > 2) cout << "NO" << endl;
  else cout <<"YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <climits>
using namespace std;
typedef vector<int> vec;

#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))
#define N 100020
#define N2 100000020


//int a[N];
//int p[N2];
//int q[N2];


int main(int argc, const char * argv[]) {
    string s;
    cin>>s;
    int p=-1;
    for (int i=0; i<s.length(); i++) {
        if (s[i]=='C') {
            p=i;
            break;
        }
    }
    if (p==-1) {
        cout<<"No"<<endl;
        return 0;
    }
    for (int i=p; i<s.length(); i++) {
        if (s[i]=='F') {
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}


















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

int main(){
  int N;
  cin >> N;
  bool flag=false;
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    if(a%2==1)  flag=true;
  }
  if(flag)  cout << "first" << endl;
  else  cout << "second" << endl;

  return 0;
}

Measured memory_bytes: 256
S = list(input())
def dfs(t, i):
  if i == len(S) - 1:
    return sum(map(int, t.split("+")))
  return dfs(t + S[i + 1], i + 1) + dfs(t + "+" + S[i + 1], i + 1)
print(dfs(S[0], 0))

Measured memory_bytes: 9008
/**
*    author:  yuya1234
*    created: 15.07.2020 11:49:50
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
long double eps = 1.0E-14;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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; }
template<class T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<class T>T lcm(T a,T b){return gcd(a,b)*(a/gcd(a,b))*(b/gcd(a,b));}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  int n,m;
  cin>>n>>m;

  int ans=0;
  ans=((m*1900)+(n-m)*100)*pow(2,m);

  cout<<ans<<endl;

  return 0;
}

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


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

using namespace std;

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

  string a, b;
  cin >> a >> b;
  int x = stoi(a+b);

  string res = "No";
  for (int i = 1; i*i <= 100100; ++i) {
    if (i*i == x) {
      res = "Yes";
      break;
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
k = gets.chomp.to_i
i = 1
a = 7 % k
h = a
if k != 7
    until a == 0 
        a = (7 + a * 10) % k
        if a == h || i == k
            puts "-1"
            exit
        end
        i += 1
    end
else
    puts "1"
    exit
end
puts i

Measured memory_bytes: 14392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(void){
	int n; cin >> n;
	printf("%d\n", n * 800 - 200 * (n / 15));
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

main :: IO ()
main = do
	[a, b, c] <- readToListN 3 <$> BS.getLine :: IO [Int]
	putStrLn $ if a == b && a == c then
			"No"
		else
			if a == b || a == c || b == c then "Yes" else "No"


Measured memory_bytes: 508
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	int n, a;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
		a = i * i;
	    if(a > n)
	    {
	    	printf("%d\n", (i - 1) * (i - 1));
		    break;
	    }
	    else if(a == n)
	    {
			printf("%d\n", n);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    A, B, C, D = map(int, input().split())
    
    A_C = (A-1)//C
    A_D = (A-1)//D
    A_CD = (A-1)//((C*D)//gcd(C, D))
    A_nCD = (A-1) - (A_C + A_D - A_CD)

    B_C = B//C
    B_D = B//D
    B_CD = B//((C*D)//gcd(C, D))
    B_nCD = B - (B_C + B_D - B_CD)

    print(B_nCD - A_nCD)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5076
from operator import itemgetter

N=int(input())
A=[0]*N
for i in range(N):
    A[i]=input().split()

i=0
while i<N:
    A[i][1]=int(A[i][1])
    i+=1

i=0
while i<N:
    A[i]=tuple(A[i])
    i+=1

B1 = sorted(A, key=itemgetter(1),reverse=True)
B2 = sorted(B1,key=itemgetter(0))

for i in B2:
    print(A.index(i)+1)    

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

using namespace std;

#define ll long long
#define ull unsigned long long
int main()
{
	//ifstream cin("in.txt");
	//ofstream cout("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n; cin>>n;
	string s; cin>>s;
	int x = s.size();

	for (int i = 0; i<x; i++)
	{
		s[i] = 'A' + (s[i]-'A' + n)%26;
	}	
	cout<<s<<endl;
}

Measured memory_bytes: 256
ALL = []
cnt = 0
import math
def decide_sosuu(n):
    if n <= 1:
        return False
    else:
        for i in range(2, int(math.sqrt(n)) + 1):
            if n % i == 0:
                return False
    return True
for i in range(1,int((10**5)/2+2)):
    if decide_sosuu(i):
        if decide_sosuu((i*2)-1):
            cnt += 1
            ALL.append(cnt)
        else:
            ALL.append(cnt)
    else:
        ALL.append(cnt)
Q = int(input())
for _ in range(Q):
    l, r = map(int, input().split())
    if l == 1:
        print(ALL[int(r/2)])
    else:
        print(ALL[int(r/2)] -ALL[int(l/2)-1])

Measured memory_bytes: 9052
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

const int MAX_N = 200005;

vector<int> a, ans;
vector<int> to[MAX_N];
int dp[MAX_N];
void dfs(int v, int p = -1) {
   int i = lower_bound(dp, dp + MAX_N, a[v]) - dp;
   int old = dp[i];
   dp[i] = a[v];
   ans[v] = i;
   if (p != -1) ans[v] = max(ans[v], ans[p]);
   for (int u : to[v]) {
      if (u == p) continue;
      dfs(u, v);
   }
   dp[i] = old;
}
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

   int n;
   cin >> n;
   a = ans = vector<int>(n);
   rep(i, 0, n) cin >> a[i];
   rep(i, 0, n - 1) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      to[v].push_back(u);
      to[u].push_back(v);
   }
   rep(i, 0, MAX_N) dp[i] = INF;
   dp[0] = -INF;
   dfs(0);
   rep(i, 0, n) cout << ans[i] << endl;
   return 0;
}

Measured memory_bytes: 30748
from collections import deque
v, que, k = set(), deque([(1, 1)]), input()
while que:
    n, c = que.popleft()
    if n in (0, k):
        print c
        break
    if n not in v:
        que.append((n + 1, c + 1))
        que.appendleft((n * 10 % k, c))
        v.add(n)


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

using namespace std;

#define lint long long

int main(){
    string S;
    cin >> S;
    
    int ans = 1000000000;
    
    for(int i = 0; i < S.size() - 2; ++ i){
        int a = stoi(S.substr(i, 3));
        ans = min(ans, abs(a - 753));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;

  vector<bool> prime(300000,true);
  for(i=2;i<300000;i++)
    if(i%7==1||i%7==6)
      for(j=2;i*j<300000;j++)
        prime[i*j]=false;
  prime[0]=prime[1]=false;
  while(1){
    cin>>n;
    if(n==1)break;
    cout<<n<<":";
    rep(i,n+1)
      if(prime[i] && (i%7==1 || i%7==6) && n%i==0)
        cout<<" "<<i;
    cout<<endl;
  }
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;

int main() {

  ll n;
  cin >> n;
  vector<ll> x(n);
  vector<ll> y(n);
  vector<ll> h(n);
 
  REP(i,n) cin >> x[i] >> y[i] >> h[i];

  ll lx=-1,ly=-1,lh=-1;

  REP(i,101){
    REP(j,101){
      bool flag = true;
      ll xh=-1;
      REP(k,n){
        ll cdc= abs(i-x[k])+abs(j-y[k])+h[k];
        if(h[k]!=0){
          if(xh==-1){
            xh = cdc;
          }else{
            if(xh!=cdc){
              flag = false;
            }
          }
        }
      }
      REP(k,n){
        if(h[k]==0){
          ll cdcex=abs(i-x[k])+abs(j-y[k]);
          if(cdcex<xh){
            flag = false;
          }
        }
      }

      if(flag){
        lx = i;
        ly = j;
        lh = xh;
      }
    }
  }

  cout << lx << " " << ly << " " << lh << endl;

}

  


Measured memory_bytes: 256
import sys


def resolve():
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for x in [0] * N]

    # 配るDP
    # dp[i][sum_v]はi個の品物の内でsum_v以上となる最小の重量
    V = N * 10 ** 3 + 1  # 価値の最大値
    inf = 10 ** 10
    dp = [[inf] * V for _ in [0] * (N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(V):
            weight, value = lst[i]
            if sum_v - value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - value] + weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)
    

resolve()


Measured memory_bytes: 153120
while True:
  n = int(input())
  if n==0:
    break
  A=[]
  for a in range(n):
    x =list(map(int, input().split()))
    x.append(sum(x))
    A.append(x)
  Y=[]
  for j in range(n+1):
    y=0
    for i in range(n):
      y+=A[i][j]
    Y.append(y)

  A.append(Y)
  
  for i in range(n+1):
    for j in range(n+1):
      a=A[i][j]
      a=str(a)
      a=a.rjust(5)
      print(a,end="")
    print()
      


Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

const double pie = acos(-1.0);
const ll MOD = 1e9 + 7;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a / gcd(a, b) * b;
}

//素数判定
bool is_prime(const unsigned n){
    switch(n){
        case 0: // fall-through
        case 1: return false;
        case 2: // fall-through
        case 3: return true;
    } // n > 3 が保証された
    if(n % 2 == 0 || n % 3 == 0) return false;
    for(unsigned i = 5; i * i <= n; i += 6) {
        if(n % i     == 0) return false; // (6の倍数)-1
        if(n % (i+2) == 0) return false; // (6の倍数)+1
    }
    return true;
}

void solve() {
    ll x; cin >> x;
    ll n = 0;
    Rep(i, 1, x){
        n += i;
        if(n >= x){
            cout << i << endl;
            return;
        }
    }
}

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

    solve();
    return 0;
}


Measured memory_bytes: 256
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    # 1e10

    # 初期値用:十分小さい数(-100億)
    # -1e10
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,K = (int(_) for _ in input().split())
    dict = {}
    ans = 0
    for i in range(N):
        s1,s2 = (int(_) for _ in input().split())
        if s1 not in dict:
            dict[s1] = s2
        else:
            dict[s1] += s2
    index = 0
    for k,v in sorted(dict.items()):
        index += v
        if(index >= K):
            ans = k
            break
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 15052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

struct data {int x, y, value;};

int main() {
    int h, w, d; cin >> h >> w >> d;
    int M = 300*300;
    int m = M+d-1;
    vector<vector<P>> data(d,vector<P>(m/d));
    REP(i,h+1)REP(j,w+1) {
        int x; cin >> x;
        if (x%d != 0) data[x%d][x/d] = P(i,j);
        else data[x%d][x/d-1] = P(i,j);
    }
    vvint dis(d,vint(m/d+1,0));
    rep(i,d) {
        REP(j,m/d+1) {
            int x = abs(data[i][j].second-data[i][j-1].second);
            int y = abs(data[i][j].first-data[i][j-1].first);
            dis[i][j] = dis[i][j-1] + x + y;
        }
    }
    // rep(i,10) cout << data[1][i].first << data[1][i].second << " ";
    // cout << endl;
    // rep(i,10) cout << dis[0][i] << " ";
    int q; cin >> q;
    rep(i,q) {
        int l, r; cin >> l >> r;
        if (r%d != 0) cout << dis[r%d][r/d]-dis[l%d][l/d] << endl;
        else cout << dis[r%d][r/d-1]-dis[l%d][l/d-1] << endl;
    }
}

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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    int t;

    if (n % 2 == 0) {
        t = n / 2;
    } else {
        t = n / 2 + 1;
    }

    cout << fixed << setprecision(10) << (double)t / (double)n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
 
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a,ans,j;
    j=1;
    ans=0;
    cin>>a;
    ll arr[a];
    fr(i,a){
        ll b;
        cin>>b;
        arr[i]=b;
    }
    sort(arr,arr+a,std::greater<>());
    a-=2;
    ans+=arr[0];
    while(a>1){
        ans+=arr[j]*2;
        ++j;
        a-=2;
    }
    if(a==1){
        ans+=arr[j];
    }
    cout<<ans;
}

Measured memory_bytes: 5220
import collections
n = int(input())
V = [int(i) for i in input().split()]
E,O = [],[]
E_cnt2,O_cnt2 = 0,0
for i in range(n):
    if i%2:
        E.append(V[i])
    else:
        O.append(V[i])
e = collections.Counter(E)
tmp = e.most_common()
E_mode,E_cnt = tmp[0][0],tmp[0][1]
if len(tmp)>=2:
    E_cnt2 = tmp[1][1]

o = collections.Counter(O)
tmp = o.most_common()
O_mode,O_cnt = tmp[0][0],tmp[0][1]
if len(tmp)>=2:
    O_cnt2 = tmp[1][1]
if E_mode!=O_mode:
    print(len(E)-E_cnt+len(O)-O_cnt)
else:
    print(min((len(E)-E_cnt+len(O)-O_cnt2),len(E)-E_cnt2+len(O)-O_cnt))




Measured memory_bytes: 24288
a=list(input()+"A")[::-1]
b=list(input()+"B")[::-1]
c=list(input()+"C")[::-1]

turn=a

def game(turn):
    card=turn.pop()
    if len(turn)==0:
        print(card)
    else:
        
    
        if card=="a":
            turn=a
        elif card=="b":
            turn=b
        else:
            turn=c
    
        game(turn)
    
game(turn)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

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

    int a, b;
    cin >> a >> b;
    if (a >= 13)
        cout << b << endl;
    else if (a >= 6)
        cout << b / 2 << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans;
int main(int argc, char* argv[]){
  long int a,b,c;
  scanf("%ld %ld %ld",&a,&b,&c);
  if (a==b) {
    printf("%d",c);
  }else if (a==c) {
    printf("%d",b);
  }else{
    printf("%d\n",a);
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7 ;
LL ans[ 2020 ] , n;
void ditui(){
	ans[5] = 1 ;ans[6] = 2 ; ans[7] = 3 ;
	for (LL i = 8;i <= n;i ++){
		ans[i] = ans[i - 1] + ans[i - 3] ;
		ans[i] %= MOD;
	}
}
int main(){
	cin >> n ;
	if ( n <= 2 ){
		cout << "0" << '\n' ;
		return 0;
	}
	if (n == 3 || n == 4){
		cout << "1" << '\n' ;
		return 0;
	}
	ditui();
	cout << ans[n] % MOD << endl;
	return 0;
}

Measured memory_bytes: 3632
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, usize, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};

fn main() {
    input! {
        n: usize,
        k: usize,
        _arr: [i32; n],
    }
    println!("{}", if k == n { 1 } else if k == 2 { n - 1 } else { (n + k - 3) / (k - 1) });
}


Measured memory_bytes: 4352
import sys
sys.setrecursionlimit(100000)
input=sys.stdin.readline
def intinput():return map(int,input().split())

import itertools
n,a,b,c=intinput()
abc=[a,b,c]
l=[0]*n
for i in range(n):
    l[i]=int(input())
k=list(itertools.product((0,1,2,3),repeat=n))
ans=float("inf")
for i in k:
    if 0 not in i or 1 not in i or 2 not in i:
        continue
    tmp=abc[:]
    cnt=[-1,-1,-1]
    for j in range(n):
        if i[j]==3:
            continue
        tmp[i[j]]-=l[j]
        cnt[i[j]]+=1
    cost=0
    for j in range(3):
        cost+=abs(tmp[j])+10*cnt[j]
    ans=min(ans,cost)
print(ans)

Measured memory_bytes: 51124
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N, K;
ll A[MAX_N];

void solve() {
	cin >> N >> K;
	rep(i, 0, N) cin >> A[i];
	ll res = linf;
	rep(i, 0, N - K + 1) {
		ll l = A[i], r = A[i + K - 1];
		if(r >= 0 && l <= 0) {
			MIN(res, r - l + min(abs(l), abs(r)));
		}
		else {
			MIN(res, max(abs(l), abs(r)));
		}
	}
	cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
	int l[10];
	double v1, v2;
	while (scanf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%lf,%lf", &l[0], &l[1], &l[2], &l[3], &l[4], &l[5], &l[6], &l[7], &l[8], &l[9], &v1, &v2) != EOF) {
		int distance = 0;
		for (int i = 0; i < 10; i++)
			distance += l[i];
//		cout << distance << endl;
		double time = distance / (v1 + v2);
//		printf("%.6lf\n", time);
		double cross = v1 * time;
//		printf("%.6lf\n", cross);
		double sum = 0;
		for (int i = 0; i < 10; i++) {
			sum += l[i];
			if (sum >= cross) {
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define fin freopen("input", "r", stdin);
#define fout freopen("output", "w", stdout);
#define wt(x) cerr << #x << ": " << x << " ";
#define whatis(x) {cerr << #x << ": " << x << endl;}
#define whatis2(x, y) {wt(x); wt(y); cerr << endl;}
#define whatis3(x, y, z) {wt(x); wt(y); wt(z); cerr << endl;}
#define whatis4(x, y, z, a) {wt(x); wt(y); wt(z); wt(a); cerr << endl;}
using namespace std;

typedef long long ll; typedef unsigned long long ull; typedef long double ld;
const ll MOD = 1000000007; const ld PI = acos(-1.0);

template <typename T> inline T bigMod(T A,T B,T M = MOD){A %= M;T ret = 1;while(B){if(B & 1) ret = (ret * A) % M;A = (A * A) % M;B = B >> 1;}return ret;}
template <typename T> inline T invMod (T A,T M = MOD){return bigMod(A,M-2,M);}

int dp[3000 + 2][3000 + 2];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    string s1, s2;
    cin >> s1 >> s2;
    int n = s1.size();
    int m = s2.size();
    s1 = '*' + s1;
    s2 = '-' + s2;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            dp[i][j] = max (dp[i-1][j], dp[i][j-1]);
            if (s1[i] == s2[j]) {
                dp[i][j] = max(dp[i-1][j-1] + 1, dp[i][j]);
            }
        }
    }

    /* for (int i = 0; i <= n; ++i) cout << '\t' << s1[i]; */
    /* cout << endl; */
    /* for (int i = 0; i <= n; ++i) { */
    /*     cout << s2[i] << '\t'; */
    /*     for (int j = 0; j <= m; ++j) { */
    /*         cout << dp[i][j] << '\t'; */
    /*     } */
    /*     cout << endl; */
    /* } */

    string ans = "";
    int i = n, j = m;
    while (i > 0 && j > 0) {
        if (s1[i] == s2[j]) {
            ans += s1[i];
            i -= 1; j -= 1;
        } else if (dp[i][j] == dp[i-1][j]) {
            i -= 1;
        } else {
            j -= 1;
        }
    }

    reverse(ans.begin(), ans.end());

    cout << ans << endl;


    


    return 0;
}


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

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

int main(void)
{
    int n,m;
    ll x;
    cin >> n >> m >> x;
    ll c[n];
    ll a[n][m];
    ll min_money=LLONG_MAX;
    for (int i=0;i<n;i++)
    {
        cin >> c[i];
        for(int j=0;j<m;j++)
        {
            cin >> a[i][j];
        }
    }

    for(int bit=0;bit<pow(2,n);bit++)
    {
        //cout << "bit " << bit << endl;
        ll money=0;
        ll b[m]={};
        int ok=0;
        for(ll i=0;i<n;i++)
        {
            if(bit & (1<<i))
            {
                money+=c[i];
                for(ll j=0;j<m;j++)
                {
                    b[j]+=a[i][j];
                }
            }
        }
        for(ll j=0;j<m;j++)
        {
            if(b[j]>=x)
            {
                ok++;
                //cout << b[j] << endl;
            }
        }
        if(ok==m)
        {
            if(money<min_money)
            {
                min_money=money;
            }
        }
    }
    if(min_money != LLONG_MAX)
    {
        cout << min_money << endl;
    }
    else
    {
        cout << -1 << endl;
    }
    return 0;
}


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

int main(){
  int n,m;
  cin >> n >> m;
  int ans=0;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n;j++){
      if(0<=m-i-j&&m-i-j<=n){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  string ans = "No";

  if (y <= 4 * x && y % 2 == 0) {
    for (int i = 0; i <= x; ++i) {
      if (y == 4 * i + 2 * (x - i)) {
        ans = "Yes";
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3628
main = do
    getLine
    s <- getLine
    let (l,r) = solve (0,0) s
    putStrLn $ replicate r '(' ++ s ++ replicate l ')'

solve (l,r) [] = (l,r)
solve (l,r) (c:cs) | c == '(' = solve (l+1,r) cs
                   | c == ')' = solve (if l > 0 then (l-1,r) else (l,r+1)) cs

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

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1];
	for (int i=1; i<=n; i++)
	   cin>>a[i];
	for (int i=1; i<=n-k; i++)
	{
		if (a[i]<a[i+k])
		  cout<<"Yes"<<endl;
		else
		  cout<<"No"<<endl;
	 }
	return 0;
 }

Measured memory_bytes: 4336
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)

N, Q = map(int, input().split())
AB = [[int(x) for x in input().split()] for _ in range(N-1)]
PX = [[int(x) for x in input().split()] for _ in range(Q)]

# 木構造をリストで表現する
graph = [[] for _ in range(N+1)]

for a, b in AB:
    graph[a].append(b)
    graph[b].append(a)

# 各操作で与えられる値を、各頂点ごとに集計しておく
P = [0] * (N+1)
for p, x in PX:
    P[p] += x


def dfs(v, parent, point):
    # 現在いる頂点vの親までの値をpointとする
    P[v] += point
    for x in graph[v]:
        if x == parent:
            continue
        dfs(x, v, P[v])


dfs(1, 0, 0)

res = ' '.join(map(str, P[1:]))
print(res)

Measured memory_bytes: 285864
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int X, A;
	std::cin >> X >> A;
	if (X < A)
	{
		std::cout << 0 << std::endl;
	}
	else
	{
		std::cout << 10 << std::endl;
	}
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256