akhauriyash/Code-Regression huggingface dataset:
s = list(str(input()))

aa = 10*int(s[0]) + int(s[1])
bb = 10*int(s[2]) + int(s[3])
if 1 <= aa <= 12 and 1 <= bb <= 12:
    print("AMBIGUOUS") 
elif 0 <= aa <= 99 and 1 <= bb <= 12:
    print("YYMM")
elif 1 <= aa <= 12 and 0 <= bb <= 99:
    print("MMYY")
else:
    print("NA")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<bitset>
using namespace std;

int main() {

	vector<int> val(3, 0);
	cin >> val[0] >> val[1] >> val[2];

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

	cout << 10 * val[2] + val[1] + val[0] << endl;

	return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	ll N;
  cin>>N; N;
  ll K;
  cin>>K; K;
	const int n=N;
	vector<ll> a(n),b(N),c(n);
	rep(i,n) c[i]=K+N+N+i;
	if(N<2*K-1){
		cout<<-1 NL;
		return 0;
	}
	rep(i,N) a[i]=K+i;
	rep(i,N) b[(K+i)%N]=K+N+i;
	vector<int> ind(N); iota(all(ind),0);
	sort(all(ind),[&](int i,int j){ return a[i]+b[i]<a[j]+b[j];});
	out(a,b,c,1);
	rep(i,N) out(a[ind[i]]+b[ind[i]],ind[i],1);
	rep(i,N) assert(a[ind[i]]+b[ind[i]]<=c[i]);
	rep(i,N) cout<<a[ind[i]]<<" "<<b[ind[i]]<<" "<<c[i] NL;
	return 0;
}


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

int main() {
  int A[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  if (A[0][2] - A[0][1] == A[1][2] - A[1][1] && A[1][2] - A[1][1] == A[2][2] - A[2][1] && A[0][1] - A[0][0] == A[1][1] - A[1][0] && A[1][1] - A[1][0] == A[2][1] - A[2][0] && A[2][0] - A[1][0] == A[2][1] - A[1][1] && A[2][1] - A[1][1] == A[2][2] - A[1][2] && A[1][0] - A[0][0] == A[1][1] - A[0][1] && A[1][1] - A[0][1] == A[1][2] - A[0][2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));

int main() {
	string a,b;
	cin >> a>>b;
	int c = stoi(a + b);
	int s = (int)sqrt(c);
	if (s*s == c)cout << "Yes";
	else cout << "No";

	return 0;
}





Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int r=sc.nextInt();
        int c=sc.nextInt();
        char grid[][]=new char[r][c];
        for(int i=0;i<r;i++){
            String str=sc.next();
            for(int j=0;j<c;j++){
                grid[i][j]=str.charAt(j);
            }
        }
        int dp[][]=new int[r+1][c+1];
        dp[1][1]=1;
        for(int i=1;i<=r;i++){
            for(int j=1;j<=c;j++){
                if(i==1&&j==1)
                continue;
                if(grid[i-1][j-1]=='#')
                continue;
                else{
                    dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
                }
            }
        }
        System.out.println(dp[r][c]%1000000007);
    }
}

Measured memory_bytes: 35100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define MOD (int) (1e9+7)
#define INF (int) 2e9
#define LLINF (ll) 2e18

// 逆元のmod MOD
ll rev_mod(ll num){
	ll pow_num = MOD - 2;
	ll mod_num = MOD;
	ll pow_cur = num;
	ll ret = 1;
	while(pow_num > 0){
		if(pow_num % 2 == 1){
			ret *= pow_cur;
			ret %= mod_num;
		}
		pow_cur *= pow_cur;
		pow_cur %= mod_num;
		pow_num /= 2;
	}
	return ret;
}

ll mpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    ll h;
    cin >> h;

	ll cnt = 0;
	while(h>0){
		h/=2;
		cnt++;
	}
	
    cout << mpow(2, cnt)-1 << endl;
    // printf("%d\n", N);
    return 0;
}

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

struct Point{
	int x,y,idx;
	bool operator<(const Point& rhs)const{
		return x==rhs.x?y<rhs.y:x<rhs.x;
	}
}P[100];

bool bad(const Point& p1,const Point& p2,const Point& p3){
	return 1LL*(p3.x-p1.x)*(p2.y-p1.y)-1LL*(p2.x-p1.x)*(p3.y-p1.y)<=0;
}
vector<Point> convex(int n){
	sort(P,P+n);
	vector<Point> res;
	for(int i=0;i<n;i++){
		while(res.size()>=2&&bad(res[res.size()-2],res[res.size()-1],P[i]))
			res.pop_back();
		res.emplace_back(P[i]);
	}
	for(int i=n-2,t=res.size();i>=0;i--){
		while(res.size()>t&&bad(res[res.size()-2],res[res.size()-1],P[i]))
			res.pop_back();
		res.emplace_back(P[i]);
	}
	res.pop_back();
	return res;
}
double ans[100];
const double pi = acos(-1);
inline double dist(int x,int y){
	return sqrt(1LL*x*x+1LL*y*y);
}
double calc(const Point& p1,const Point& p2,const Point& p3){
	long long int dot=1LL*(p3.x-p2.x)*(p2.x-p1.x)+1LL*(p3.y-p2.y)*(p2.y-p1.y);
	double tmp=dot/(double)dist(p2.x-p1.x,p2.y-p1.y)/(double)dist(p3.x-p2.x,p3.y-p2.y);
	double ang = acos(tmp);
	return ang/(2*pi);
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>P[i].x>>P[i].y,P[i].idx=i;
	auto res = convex(n);
	if(res.size()==2){
		ans[res[0].idx]=0.5;
		ans[res[1].idx]=0.5;
	}
	else{
		for(int j=0;j<res.size();j++){
			int i=(j+(res.size()-1))%res.size();
			int k=(j+1)%res.size();
			ans[res[j].idx] = calc(res[i],res[j],res[k]);
		}
	}
	cout<<fixed<<setprecision(10);
	for(int i=0;i<n;i++)
		cout<<ans[i]<<'\n';
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long N = scan.nextLong();
        long limit = 0;
        for (long i = 1; i <= N; i++) {
            if (i * (i + 1) < N * 2) {
                limit = i;
                continue;
            }
            break;
        }
        limit += 1;
        long remain = limit * (limit + 1) / 2 - N;
        for (int i = 1; i <= limit; i++) {
            if (i == remain) {
                continue;
            }
            System.out.println(i);
        }
    }
}


Measured memory_bytes: 25940
// https://abc104.contest.atcoder.jp/tasks/abc104_b

// Todo
// * [x] sを分解する関数
// * [x] sから"AC"か"WA"を返す関数

function parse(s) {
  const lastIndex = s.length - 1

  return [
    s.substring(0, 2), // "ABCDE"から"AB"を取り出す
    s.substring(2, lastIndex), // "ABCDE"から"CD"を取り出す
    s.substring(lastIndex), // "ABCDE"から"E"を取り出す
  ]
}

function f(s) {
  const arr = parse(s)

  return arr[0].match(/^A[a-z]*$/) && arr[1].match(/^[a-z]*C[a-z]*$/) && arr[2].match(/^[a-z]*$/) ? "AC" : "WA"
}

module.exports = {
  parse,
  f,
}

function Main(input) {
  console.log(f(input.trim()))
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"))


Measured memory_bytes: 11468
#include<stdio.h>
#include<string.h>
int main(){
   char S[4];
   scanf("%s",S);

   if(strcmp(S, "ARC")==0){
      printf("%s","ABC");

      }else if(strcmp(S, "ABC")==0){
      printf("%s","ARC");
   }
   return 0;
}


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

int main()
{
    ll a,b,c;
    cin>>a>>b;
    if(a<=2*b)
    {
        cout<<"0"<<endl;
    }
    else
    {
        cout<<a-(2*b)<<endl;
    }
}



Measured memory_bytes: 256
#include<cstdio>
int n;
char a[200005],b[200005];
int la=0,lb=0;
int ans=0;
int main(){
char c=getchar();
while(!(c>='a'&&c<='z')){
c=getchar();
}
while(c>='a'&&c<='z'){
a[la++]=c;
c=getchar();
}
while(!(c>='a'&&c<='z')){
c=getchar();
}
while(c>='a'&&c<='z'){
if(c!=a[lb])ans++;
b[lb++]=c;
c=getchar();
}
printf("%d",ans);
}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) a.begin(),a.end()

int main(void){
    int n;
    cin>>n;
    vector<pair<int,int>> a(n);
    rep(i,n){
        int x;
        cin>>x;
        a[i] = {x,i};
    }
    sort(all(a));
    vector<int> res(n);
    rep(i,n){
        int index = a[i].second;
        res[index] = (i>=n/2) ? a[n/2-1].first : a[n/2].first;
    }
    rep(i,n){
        cout<<res[i]<<endl;
    }

    return 0;
}

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i] = (p[i] + 1) / (double)2;
  }
  int l = 0;
  double ans = 0, t = 0;
  for (int i = 0; i < n; i++) {
    if (i - l < k) {
      t += p[i];
    } else {
      t -= p[l];
      t += p[i];
      l++;
    }
    ans = max(ans, t);
  }
  printf("%.12f\n", ans);

  return 0;
}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int friend = scan.nextInt();
		int height = scan.nextInt();
		int[] Fheight = new int[friend];
		int count = 0;

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

			Fheight[i] = scan.nextInt();
		}

		for(int i=0;i<friend;i++) {
			if(Fheight[i] >= height) {
				count++;
			}
		}
		System.out.println(count);
		scan.close();

	}

}


Measured memory_bytes: 50264
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int t[n];
    for(int i=0;i<n;i++)
        cin>>t[i];
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int pi,ti;
        cin>>pi>>ti;
        int sum = 0;
        for(int j=0;j<n;j++)
        {
            if(j==(pi-1))
                sum+=ti;
            else
                sum+=t[j];

        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int y,m,d;
 
int main()
{
    while(cin>>y>>m>>d)
	{
        if(y>1989)cout<<"heisei "<<y-1988;
        else if(y==1989)
		{
            if(m>1)cout<<"heisei 1";
            else if(d>7)cout<<"heisei 1";
            else cout<<"showa 64";
        }
        else if(y>1926)cout<<"showa "<<y-1925;
        else if(y==1926)
		{
            if(m==12&&d>24)cout<<"showa 1";
            else cout<<"taisho 15";
        }
        else if(y>1912)cout<<"taisho "<<y-1911;
        else if(y==1912)
		{
            if(m>7)cout<<"taisho 1";
            else if(m==7&&d>29)cout<<"taisho 1";
            else cout<<"meiji 45";
        }
        else if(y>1868)cout<<"meiji "<<y-1867;
        else if(y==1868){
            if(m>9)cout<<"meiji 1";
            else if(m==9&&d>7)cout<<"meiji 1";
            else 
			{
				cout<<"pre-meiji"<<endl;continue;
			}
        }
        else 
		{
			cout<<"pre-meiji"<<endl;continue;
		}
        cout<<" "<<m<<" "<<d<<endl;
    }
	return 0;
}

Measured memory_bytes: 1164
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

a1 = (a +9) // 10 * 10
b1 = (b +9) // 10 * 10
c1 = (c +9) // 10 * 10
d1 = (d +9) // 10 * 10
e1 = (e +9) // 10 * 10

tmax = 0
if tmax < a1 - a:
    tmax = a1 - a
if tmax < b1 - b:
    tmax = b1 - b
if tmax < c1 - c:
    tmax = c1 - c
if tmax < d1 - d:
    tmax = d1 - d
if tmax < e1 - e:
    tmax = e1 - e



print(a1+b1+c1+d1+e1-tmax)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a[100005], dp[100005];
int main(){
    int n;
    cin>>n;
    for(int i = 0; i < n; ++i){
        cin>>a[i];
    }
    dp[0] = 0;
    for(int i = 1; i < n; ++i){
        dp[i] = dp[i-1] + abs(a[i] - a[i-1]);
        if(i >= 2) dp[i] = min(dp[i], dp[i-2] + abs(a[i] - a[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;





void one_case() {
    int a, b;
    cin >> a >> b;

    cout <<  (a + b + 1) / 2 << "\n";
}


int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<string, long long> P;
#define All(a) a.begin(), a.end()
string N;
int main(){
    string S;
    cin >> S;
    int K;
    cin >> K;
    vector<vector<vector<long long>>> dp(S.size(), vector<vector<long long>>(2, vector<long long> (K + 1, 0)));
    for(int i = 0; i < S.size(); i++){
        if(i == 0){
            dp[i][0][1] = S[i] - '1';
            dp[i][1][1] = 1;
        }
        else{
            for(int j = 0; j < K; j++){
                dp[i][0][K - j] = dp[i - 1][0][K - j] + dp[i - 1][0][K - j - 1] * 9;
                if(S[i] != '0'){
                    dp[i][0][K - j] += dp[i - 1][1][K - j] + dp[i - 1][1][K - j - 1] * (S[i] - '1');
                    dp[i][1][K - j] = dp[i - 1][1][K - 1 - j];
                }
                else dp[i][1][K - j] = dp[i - 1][1][K - j];
                if(j == K - 1) dp[i][0][K - j] += 9;
            }
        }
    }
    cout << dp[S.size() - 1][0][K] + dp[S.size() - 1][1][K] << endl;
}

Measured memory_bytes: 3632
H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
for i in range(10):
    for k in range(10):
        for l in range(10):
            C[k][l] = min(C[k][l], C[k][i]+C[i][l])
ans = 0
"""
for _ in C:
    print(_)
"""
for i in range(H):
    A = list(map(int,input().split()))
    for j in A:
        if j != -1:
            ans += C[j][1]
print(ans)


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

#define ll long long 
#define ff(i, a, b) for(int i = a; i <= b; i++)
#define fo(i, a, b) for(int i = a; i < b; i++)
#define fod(i, a, b) for(int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

const int INF = 1e9, N = 1010;
const ll INFL = 1e18;

typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;

int n, m, k;
char a[N][N];
int T[N][N];

struct query {
	int X1; int Y1; int X2; int Y2;
	int J; int O; int I;
} q[N * 100];

void upd(int x, int y) { for(int i = x; i <= n; i += i & -i) for (int j = y; j <= m; j += j & -j) T[i][j]++; }
int get(int x, int y) { int res = 0; for (int i = x; i > 0; i -= i & -i) for (int j = y; j > 0; j -= j & -j) res += T[i][j]; return res; }
int get(query qu) { return get(qu.X2, qu.Y2) - get(qu.X1 - 1, qu.Y2) - get(qu.X2, qu.Y1 - 1) + get(qu.X1 - 1, qu.Y1 - 1); }

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n >> m >> k;
	ff(i, 1, n) ff(j, 1, m) cin >> a[i][j];
	ff(i, 1, k) cin >> q[i].X1 >> q[i].Y1 >> q[i].X2 >> q[i].Y2;

	memset(T, 0, sizeof T);
	ff(i, 1, n) ff(j, 1, m) if (a[i][j] == 'J') upd(i, j);
	ff(i, 1, k) q[i].J = get(q[i]);

	memset(T, 0, sizeof T);
	ff(i, 1, n) ff(j, 1, m) if (a[i][j] == 'O') upd(i, j);
	ff(i, 1, k) q[i].O = get(q[i]);

	memset(T, 0, sizeof T);
	ff(i, 1, n) ff(j, 1, m) if (a[i][j] == 'I') upd(i, j);
	ff(i, 1, k) q[i].I = get(q[i]);

	ff(i, 1, k) printf("%d %d %d\n", q[i].J, q[i].O, q[i].I);
}

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

namespace abc170_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]);
            int n = int.Parse(input[1]);

            int[] p = new int[n];
            input = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
            {
                p[i] = int.Parse(input[i]);
            }

            List<int> list = new List<int>(p);

            for (int i = 0; i <= 100; i++)
            {
                if (!list.Contains(x - i))
                {
                    Console.WriteLine(x - i);
                    return;
                }
                else if (!list.Contains(x + i))
                {
                    Console.WriteLine(x + i);
                    return;
                }
            }
        }
    }
}


Measured memory_bytes: 27736
N, W = gets.split.map(&:to_i)
WV = N.times.map{gets.split.map(&:to_i)}.sort_by{|a|[a[0], a[1]]}
 
dp = Hash.new(Float::INFINITY)
dp[0] = 0
que = [0]
 
WV.each do |w, v|
  dp_dup = dp.dup
  dp_dup.each do |dp_v, dp_w|
    nw, nv = w + dp_w, v + dp_v
    next if nw > W
    
    if dp[nv] > nw
      dp[nv] = nw
    end
  end
end
p dp.keys.max

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, m, start;
    while (cin >> n >> m >> start, n|m|start) {
        start--;
        bool hline[1000][100] = {false};
        REP(i, m) {
            int h, p, q;
            cin >> h >> p >> q;
            h--;
            p--;
            q--;
            hline[h][p] = true;
        }
        int p = start;
        for (int i = 1000-1; i >= 0; i--) {
            if (hline[i][p]) {
                p++;
            } else if (p > 0 && hline[i][p-1]) {
                p--;
            }
        }
        cout << p + 1 << endl;
    }
}

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

static const int N = 100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    cin >> n;
    for(int i = 1;i <= n;i++){
        cin >> p[i-1] >> p[i];
    }
    
    for(int i = 1;i <= n;i++) m[i][i] = 0;
    for(int l = 2;l <= n;l++){
        for(int i = 1;i <= n-l+1;i++){
            int j = i+l-1;
            m[i][j] = (1 << 21);
            for(int k = i;k <= j-1;k++){
                m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }
    
    cout << m[1][n] << endl;
    
    return 0;
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
using namespace std;
int n,l[2000],num[10000],sum[10000];
long long ans;
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l[i];
        num[l[i]]++;
    }for(int i=1;i<=10000;i++)sum[i]=sum[i-1]+num[i];
    ans=0LL;
    sort(l,l+n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=max(0,sum[l[i]+l[j]-1]-j-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
def gcd(a, b)
  a, b = b, a if a < b
  r = a % b
  while !r.zero?
    a = b
    b = r
    r = a % b
  end
  b
end

n = gets.to_i
arr = gets.split.map(&:to_i)
a = arr.shift
arr.each { |b| a = gcd(a, b) }

puts a


Measured memory_bytes: 8452
#!/usr/bin/env python3

class UnionFind():
        def __init__(self, n):
            self.parents = list(range(n))
            self.size = [1] * n
    
        def find(self, x):
            if self.parents[x] == x:
                return x
            else:
                self.parents[x] = self.find(self.parents[x])
                return self.parents[x]
    
        def union(self, x, y):
            x = self.find(x)
            y = self.find(y)
            if x != y:
                if self.size[x] < self.size[y]:
                    x, y = y,x
                self.parents[y] = x
                self.size[x] += self.size[y]

def main():
    N, M, K = map(int, input().split())
    friend_adj = [[] for _ in range(N)]
    block_adj = [[] for _ in range(N)]
    uf = UnionFind(N)

    for _ in range(M):
        a, b = map(lambda x: int(x)-1, input().split())
        friend_adj[a].append(b)
        friend_adj[b].append(a)
        uf.union(a,b)
    for _ in range(K):
        c, d = map(lambda x: int(x)-1, input().split())
        if uf.find(c) == uf.find(d):
            friend_adj[c].append(d)
            friend_adj[d].append(c)

    ans = [uf.size[uf.find(i)]-1 for i in range(N)]

    for i in range(N):
        ans[i] -= len(friend_adj[i])        
        # for b in block_adj[i]:
        #     if uf.find(b) == uf.find(i):
        #         ans[i] -= 1
    print(*ans)
    
    
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 44608
a, b, c, d = map(int, input().split())
if (a>=0) and (b>=0) and (c>=0) and (d>=0): #A
    ans=b*d
elif (b<=0) and (d<=0):#E
    ans=a*c
elif (a<=0) and (b>=0) and (c<=0) and (d>=0):#F
    tmp1=a*c
    tmp2=b*d
    if tmp1>tmp2:
        ans=tmp1
    else:
        ans=tmp2
elif (a>=0) and (b>=0) and (d<=0):#H
    ans=a*d
elif (c>=0) and (d>=0) and (b<=0):#C
    ans=b*c
elif (a<=0) and (b>=0) and (c<=0) and (d<=0):#I
    ans=a*c
elif (a<=0) and (b<=0) and (c<=0) and (d>=0):#D
    ans=a*c
elif (a>=0) and (b>=0) and (c<=0) and (d>=0):#G
    ans=b*d
elif (a<=0) and (b>=0) and (c>=0) and (d>=0):#B
    ans=b*d
print(ans)

Measured memory_bytes: 9292
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  
using namespace std;
 
const ll inf = 1e17;
const ll N = 1e5+10;
const ll bits = 30;
const ll mod = 1e9+7;



int main(){
    FASTIO;
    int h,w;
    cin>>h>>w;

    vector<string>arr(h);

    for(int i=0;i<h;i++){
        cin>>arr[i];
    }

    vector< vector<ll> >dp(h,vector<ll>(w));


    if(arr[0][0]!='#')
        dp[0][0] = 1;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(arr[i][j]!='#'){
                if(j+1<w){
                    dp[i][j+1]+=dp[i][j];
                    dp[i][j+1]%=mod;
                }
                
                if(i+1<h){
                    dp[i+1][j]+=dp[i][j];
                    dp[i][j+1]%=mod;
                }
                
            }else{
                dp[i][j] = 0;
            }
            
        }
    }
    
    cout<<dp[h-1][w-1];

    


}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
int dx[]={0,1,0,-1};
int dy[]={-1,0,1,0};

signed main(){
	int n,x;
	cin>>n>>x;
	int s=0;
	int a[n];
	r(i,n)cin>>a[i];
	sort(a,a+n);
	r(i,n){
		if(x>=a[i]){
			x-=a[i];
			s++;
		}
	}
	if(x&&s==n)s--;
	cout<<s<<endl;
}

Measured memory_bytes: 768
/*

  _|_|                              _|  _|    _|
_|    _|  _|  _|_|  _|_|_|_|        _|  _|  _|
_|    _|  _|_|          _|          _|  _|_|
_|    _|  _|          _|      _|    _|  _|  _|
  _|_|    _|        _|_|_|_|    _|_|    _|    _|

*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
//#define ls (rt<<1)
//#define rs (rt<<1|1)
#define vi vector<int>
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a),i##end=(b);i<=i##end;i++)
#define fi first
#define se second
typedef long long ll;
using namespace std;
const int maxn=5005;
int n,a,b;
ll dp[maxn];
int main(){
    ios::sync_with_stdio(0);
    memset(dp,0x3f,sizeof(dp));dp[0]=0;
    cin>>n>>a>>b;
    rep(i,1,n){
        int num;cin>>num;
        ll mi=1e18;
        rep(j,0,num)mi=min(mi,dp[j]);
        rep(j,0,num-1)dp[j]+=a;
        rep(j,num+1,n)dp[j]+=b;
        dp[num]=mi;
    }
    ll ans=1e18;
    rep(i,1,n)ans=min(ans,dp[i]);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3688
Mod = 10**9+7
p = ["XAGC", "XGAC", "XACG"] + ["AGCX", "GACX", "ACGX"] + ["AGXC", "AXGC"]
q = ["A", "G", "C", "T"]
f = []
for s in p:
  for c in q:
    f.append(s.replace("X",c))

r = ["AGC", "GAC", "ACG"]

d = {}
e = {}
for x in q:
  for y in q:
    for z in q:
      s = x+y+z
      if not s in r:
        d[s] = 1
        e[s] = 0
      
n = int(input())
for i in range(n-3):
  for s in e.keys():
    for c in q:
      t = s+c
      if t in f:
        continue
      e[t[1:]] = (e[t[1:]]+d[s])%Mod
  for s in e.keys():
    d[s] = e[s]
    e[s] = 0
    
print(sum(d.values())%Mod)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    char c;
    cin >> c;
    if('A' <= c && c <= 'Z')    cout << "A\n";
    else    cout << "a\n";
}

Measured memory_bytes: 3648
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.NoSuchElementException;

@SuppressWarnings("unchecked")
public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);

        final int N = nextInt();
        final int M = nextInt();

        Integer[] X = new Integer[M];

        for (int i = 0; i < M; i++) X[i] = nextInt();

        int ans = 0;

        if (N < M) {
            Arrays.sort(X);

            Integer[] D = new Integer[M - 1];

            for (int i = 1; i < M; i++) D[i - 1] = X[i] - X[i - 1];

            Arrays.sort(D, Comparator.reverseOrder());

            int cum = 0;

            for (int i = 0; i < N - 1; i++) cum += D[i];

            ans = X[M - 1] - X[0] - cum;
        }

        out.println(ans);

        out.flush();
    }

    // FastScanner start
    static final InputStream in = System.in;
    static final byte[] buffer = new byte[1024];
    static int ptr = 0;
    static int buflen = 0;
    static boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    static int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    static boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    static String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    static long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    static int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    static double nextDouble() {
        return Double.parseDouble(next());
    }
    // FastScanner end
}


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

int main() {
  int ans = 0;
  string S;
  cin >> S;
  for(int i = 0; i < S.size(); i++) {
    if (S[i] == '+') ++ans;
    else
      --ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import Control.Applicative
main = do
  [x,y] <- map read . words <$> getLine :: IO [Int]

  print $ solve x y

  where
    solve x y
      | x == y = 0
      | x < y =
        if x >= 0 then y-x
        else if x < 0 && 0 <= y then if abs x >= abs y then min (-x-y+1) (y-x) else min (y-x) (y+x+1)
        else y-x
      | x > y =
        if y >= 0 then 1 + min (x-y+1) (x+y)
        else if y < 0 && 0 <= x then if abs x <= abs y then -y-x+1 else x+y+1
        else x-y+2


Measured memory_bytes: 508
import sys
import copy
from collections import defaultdict

nesw = [[0, 1], [0, -1], [1, 0], [-1, 0]]
height, width, factory = map(int, input().split(" "))
root = []
start_y, start_x = -1, -1
targets = defaultdict(int)
for h in range(height):
    temp = [n for n in input()]
    if start_y == -1:
        try:
            start_y, start_x = h, temp.index("S")
        except:
            pass
    for i in range(1, factory + 1):
        if not targets[i]:
            try:
                targets[i] = (h, temp.index(str(i)))
            except:
                pass
    root.append(temp)
targets[0] = (start_y, start_x)
fastest_root = {}

# print(targets)

for start in range(factory):
    h, w = targets[start]
    end = start + 1
    end_y, end_x = targets[end]
    used = [[0 for n in range(width)] for m in range(height)]
    queue = [(h, w)]
    used[h][w] = 1
    flag = 0
    turn = 0
    while True:
        new_queue = []
        for q in queue:
            h, w = q
            for t in nesw:
                new_h, new_w = h + t[0], w + t[1]
                if 0 <= new_h < height and 0 <= new_w < width:
                    if new_h == end_y and new_w == end_x:
                        fastest_root[start] = {end:turn + 1}
                        flag = 1
                        break
                    elif not used[new_h][new_w] and root[new_h][new_w] != "X":
                        used[new_h][new_w] = 1
                        new_queue.append((new_h, new_w))
        if flag:
            break
        queue = new_queue
        turn += 1

perm = [n for n in range(0, factory + 1)]
answer = 0
for i in range(factory):
    answer += fastest_root[perm[i]][perm[i + 1]]

print(answer)


Measured memory_bytes: 32776
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
//#define inf 2000000000
#define inf 8000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>

using namespace std;
using namespace __gnu_pbds;

const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
const int maxn=200005;
//i_am_noob
int n;

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n;
    print1(360/__gcd(n,360ll));
    return 0;
}


Measured memory_bytes: 3592
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn primes(n: usize) -> Vec<bool> {
    let mut is_prime = vec![true; n + 1];

    if n >= 1 {
        is_prime[1] = false;
    }

    for i in 2..n + 1 {
        if !is_prime[i] {
            continue;
        }
        let mut cur = i * 2;
        while cur <= n {
            is_prime[cur] = false;
            cur += i;
        }
    }
    is_prime
}

fn main() {
    input! {
        q: usize,
        lr: [(usize, usize); q],
    }
    let mut max_ = 0;
    for i in 0..q {
        max_ = max(max_, lr[i].1);
    }
    let ps = primes(max_);
    let mut cumsum_ = vec![0; ps.len()];
    for i in 1..ps.len() {
        if ps[i] && i % 2 == 1 {
            if ps[(i + 1) / 2] {
                cumsum_[i] += 1;
            }
        }
        cumsum_[i] += cumsum_[i - 1];
    }
    for (l, r) in lr {
        println!("{}", cumsum_[r] - cumsum_[l - 1])
    }
}


Measured memory_bytes: 6780
// Problem : C - Traveling Salesman around Lake
// Contest : AtCoder Beginner Contest 160
// URL : https://atcoder.jp/contests/abc160/tasks/abc160_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//QWsin
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

typedef long long ll;
const int INF=1<<30;

const int maxn=200000+10;
int d[maxn];

int k,n;
int f(int x){return (x%k+k)%k;}

int main()
{
	cin>>k>>n;
	rep(i,1,n) cin>>d[i];
	int M=f(d[1]-d[n]);
	rep(i,1,n-1) M=max(M,f(d[i+1]-d[i]));
	cout<<k-M<<endl;
	return 0;
}


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

int sumd(int n){
  int sum=0;
  for(int i=0;i<6;i++){
    sum+=(n/(int)(pow(10,(double)i)))%10;
  }
  return sum;
}

int main(){
  int n,a,b,i;
  cin>>n>>a>>b;
  int cnt=0;
  for(i=1;i<=n;i++){
    if(sumd(i)>=a && sumd(i)<=b)cnt+=i;
  }
  cout<<cnt;
}

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


int main() {
 ll A, B, C, K;
  cin >> A >> B >> C >> K;
  ll ans = 0;
  //ll flag = 0;
  if(K <= A) {
    ans = K;
  }
  else if(K <= A + B) {
    ans = A;
    //flag++;
  }
  else {
    ans = 2 * A + B - K ;
    //flag += 2;
  }
  cout << ans << endl;
}

    

Measured memory_bytes: 3624
from sys import stdin
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]


def solve(x,k,d):
    di = int(x//d)
    if di >= k: 
        return abs(x) - (k*d)
    x = x - (di*d)
    k -= di
    if k % 2 == 0:
        return abs(x)
    else:
        return abs(x - d)

x,k,d = ip()
print(solve(abs(x),k,d))

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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

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

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

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

int N, Q;
string S;
int type[20001], idx[20001], l[20001], r[20001];
char c[20001];
set<int> st[26];

void input() {
    cin >> N >> S >> Q;
    for (int q = 0; q < Q; ++q) {
        cin >> type[q];
        if (type[q] == 1) {
            cin >> idx[q] >> c[q];
        } else {
            cin >> l[q] >> r[q];
        }
    }
}

void solve() {
    for (int i = 0; i < 26; ++i){
        st[i].clear();
        st[i].insert(N);
    }
    for (int i = 0; i < N; ++i) st[(int)(S[i] - 'a')].insert(i);
    for (int q = 0; q < Q; ++q) {
        if (type[q] == 1) {
            st[(int)(S[idx[q]-1] - 'a')].erase(idx[q]-1);
            S[idx[q]-1] = c[q];
            st[(int)(S[idx[q]-1] - 'a')].insert(idx[q]-1);
        } else {
            int ans = 0;
            for (int i = 0; i < 26; ++i) {
                auto itr = st[i].lower_bound(l[q]-1);
                if (*itr <= r[q]-1) ans++;
            }
            cout << ans << endl;
        }
    }
    return;
}

int main() {
    input();
    solve();
    return 0;
}

Measured memory_bytes: 26628
// https://atcoder.jp/contests/abc107/tasks/arc101_a

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const int X_I_MAX = 1e8;
const int INF = 1e9;

int N, K;
int x[N_MAX];

void solve() {
  int ans = INF;
  FOR(i, 0, N - K) {
    ans = min(ans, abs(x[i]) + x[i + K - 1] - x[i]);
    ans = min(ans, abs(x[i + K - 1]) + x[i + K - 1] - x[i]);
  }
  printf("%d\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d", x + i);
}

int main() {
  input();
  solve();
  return 0;
}


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

int main(){
  int n,k;
  std::cin >> n>>k;
  int i=0;
  while (n/pow(k,i)>=1) {
    i++;
    // std::cout << pow(k,i) << '\n';
  }
  std::cout <<i << '\n';




  return 0;


}


Measured memory_bytes: 256
n, m = map(int, input().split())
S = []
for _ in range(m):
  s = list(map(int, input().split()))
  s.pop(0)
  S.append(s)
P = list(map(int, input().split()))

ans = 0
for i in range(2 ** n):
#  print("i=", i)
  flag = 1
  for j in range(m):
#    print("j=", j)
    cnt = 0
    for k in S[j]:
      cnt += (i >> (k - 1)) & 1
#    print(cnt)
    if cnt % 2 != P[j]:
      flag = 0
      break
  if flag == 1:
    ans += 1
    
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int n, ans = 0;
	string s;
	cin >> n >> s;

	for(int i=0;i<n-2;i++){
		if(s.at(i)=='A' && s.at(i+1)=='B' && s.at(i+2)=='C')
			ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.chomp.to_i         # 単一整数
S = gets.chomp.to_s         # 文字列。chompを付けないと改行文字がついてくる
ans = 0
i = 0
#ABC判定
loop do
    #繰り返す処理
  moji = S.slice(i, 3)
  if moji == "ABC" then
    ans = ans + 1
  end
  i = i + 1
  if i == N then
    break
  end
end
puts ans

Measured memory_bytes: 1788
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

N = gete(int)
h = geta(int)

dp = [0 for _ in range(N)]
dp[0], dp[1] = 0, abs(h[0] - h[1])

for i in range(2, N):
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]),
                dp[i - 1] + abs(h[i] - h[i - 1]))

print(dp[N - 1])


Measured memory_bytes: 52720
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};


/*void dfs(int v, int p = -1) {
	for (int u : to[v]) {
		if (u == p) continue;
		ans[u] += ans[v];
		dfs(u, v);
	}
}*/
int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	int a=0;
	rep(i, n) {
		int b;
		cin >> b;
		if (b != i + 1) a++;
	}
	if (a == 2||a==0) cout << "YES";
	else cout << "NO";
	return 0; 
}









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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    if(n%2==0){
        if(n/2>=k)  puts("YES");
        else    puts("NO");
    }else{
        if (n / 2 +1>= k)
            puts("YES");
        else
            puts("NO");
    }

    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> dy={-1,-1,-1,0,0,1,1,1},dx{-1,-0,1,-1,1,-1,0,1};
int main(){
    int h,w;
    cin>>h>>w;
    vector<string> s(h);
    for(int i=0;i<h;i++)cin>>s.at(i);
    vector<vector<int>>a(h,vector<int>(w,0));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(s.at(i).at(j)=='#'){
                a.at(i).at(j)=-1;
            for(int k=0;k<8;k++){
                int ny=i+dy.at(k);
                int nx=j+dx.at(k);
                if(ny<0||ny>=h||nx<0||nx>=w)continue;
                if(a.at(ny).at(nx)==-1)continue;
                a.at(ny).at(nx)++;
            }
            }
        }
    }
     for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(a.at(i).at(j)==-1)cout<<'#';
            else cout<<a.at(i).at(j);
        }
        cout<<endl;
    }

}

Measured memory_bytes: 256
N,M = map(int,input().split())

ks = []
for i in range(0,M):
    ks.append(list(map(int,input().split())))
ps = list(map(int,input().split()))

def bitfield(n):
    return [int(digit) for digit in bin(n)[2:]]

count = 0
for i in range(1,2**N+1):
    bitarray = bitfield(i)
    bitarray.reverse()
    all_on_flg = True
    for j in range(0,M):
        num_on = sum([bitarray[k-1] if k <= len(bitarray) else 0 for k in ks[j][1:]])
        if num_on % 2 != ps[j]:
            all_on_flg = False
            break
    if all_on_flg:
        count += 1
            
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<map>
#include<utility>
#include<cstdio>
using namespace std;

int main() {
  int n, m;
  char str1;
  char str2;
  char strm;
  char ans[100000];

  while(cin >> n){
    map<char , char> encode;
    if(n == 0) break;
    for(int i = 0; i < n; i++) {
      cin >> str1 >> str2;
      encode[str1] = str2;
    }

    cin >> m;
    int index = 0;
    for(int i = 0; i < m; i++) {
      cin >> strm;
      char foo = encode[strm];
      if(foo){
        ans[index++] = foo;
      }else {
        ans[index++] = strm;
      }
    }

    for(int i = 0; i < index; i++) {
      cout << ans[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 3108