akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
write = sys.stdout.write
# template


def solve():
    ofs = 700
    h, w = map(int, readline().split())
    A = [list(map(int, readline().split())) for i in range(h)]
    B = [list(map(int, readline().split())) for i in range(h)]
    dp = [0 for _ in range(w+1)]
    x = abs(A[0][0]-B[0][0])
    dp[0] = 1 << ofs

    for i in range(h):
        for j in range(w):
            x = abs(A[i][j]-B[i][j])
            t = dp[j] | dp[j-1]
            dp[j] = (t << x) | (t >> x)

    b = list(map(lambda s: s == '1', list(bin(dp[w-1])[-ofs-1:-ofs+100])))
    for i, s in enumerate(b):
        if(s):
            print(i)
            return


if __name__ == "__main__":
    solve()


Measured memory_bytes: 41452
n, a, b = map(int, input().split())

MOD = 1000000007


def combination(n, r, mod=10 ** 9 + 7):
    n1, r = n + 1, min(r, n - r)
    numer = denom = 1

    for i in range(1, r + 1):
        numer = (numer * (n1 - i)) % mod
        denom = (denom * i) % mod
    return numer * pow(denom, mod - 2, mod) % mod


def func(a, n, p):
    bi = str(format(n, "b"))
    res = 1

    for i in range(len(bi)):
        res = (res * res) % p
        if bi[i] == "1":
            res = (res * a) % p

    return res


s = func(2, n, MOD) - 1
xa = combination(n, a)
xb = combination(n, b)

p = (s - xa - xb) % MOD

if p < 0:
    print(p + MOD)
else:
    print(p)


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

ll comb(ll n) {
  ll r = 2;
  if (n == 0 && r == 0) return 1;
  if (n < r || n < 0) return 0;
  return (n*(n-1)) / r;
}

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

  vector<ll> a(n);
  for (ll i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<ll> c(200010, 0);
  for (ll i = 0; i < n; ++i) {
    c[a[i]]++;
  }

  ll sum = 0;
  for (ll i = 0; i < c.size(); ++i) {
    sum += comb(c[i]);
  }

  for (ll i = 0; i < n; ++i) {
    ll ci = c[a[i]];
    ll dec = comb(ci);
    ll inc = comb(ci-1);
    cout << (sum-dec+inc) << endl;
  }

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include "bits/stdc++.h"
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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



int main() {
    string s;
    cin>>s;
    for(char i='a';i<='z';i++){
        if(s.find(i)==-1){
            cout<<i;
            return 0;
        }
    }
    cout<<"None";
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main(){
    int n,m,k;
    cin >> n >> m >> k;
    int *a = (int *)malloc(sizeof(int)*(n+1));
    int *b = (int *)malloc(sizeof(int)*(m+1));
    int i, j;
    a[0]=0;
    for(i=1;i<=n;i++){
        cin >> a[i];
        a[i] = (a[i-1]>k) ? a[i-1] : a[i-1]+a[i];
    } 
    b[0]=0;
    for(i=1;i<=m;i++){
        cin >> b[i];
        b[i] = (b[i-1]>k) ? b[i-1] : b[i-1]+b[i];
    }
    for(i=0;i<n;i++){
        if(a[i+1]>k)break;
    }
    int bc=i;
    j=0;
    for(;i>=0;i--){
        for(;j<m;j++){
            if(a[i]+b[j+1]>k)break;
        }
        if(i+j>bc){
            bc = i+j;
        }
    }
    cout << bc << endl;
    return 0;
}

Measured memory_bytes: 5196
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define REPS(i,n) for(int i=1;i<=(n);i++)
#define RREPS(i,n) for(int i=(n);i>0;i--)
#define mp make_pair
#define pb(a) push_back(a)
typedef long long ll;

int main(){
    string S;
    cin >> S;
    bool a = false;
    bool b = false;
    bool c = false;
    REP(i,3){
        if(S[i] == 'a') a = true;
        if(S[i] == 'b') b = true;
        if(S[i] == 'c') c = true;
    }
    if(a && b && c) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;

  ll dx = x2 - x1, dy = y2 - y1;
  ll x3 = x2 - dy, y3 = y2 + dx, x4 = x1 - dy, y4 = y1 + dx;
  cout << x3 << " " << y3 << " " << x4 << " " << y4;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[10];

int main(){

    for(int i=0;i<4;i++)cin >> a[i];
    a[4]=a[0]+a[1]+a[2]+a[3];
    cout << a[4]/60 << endl << a[4]%60 << endl;
return 0;
}

Measured memory_bytes: 3068
n,m=map(int,input().split(" "))
s=[input().split() for i in range(n)]
d=[]
for j in s:
    j=j[1:]
    for k in j:
        d.append(k)
f=[]
for h in d:
    if d.count(h)==n:
        f.append(h)
print(len(set(f)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std ; 
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fast ios_base:: sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int 
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define f first
#define s second


int main(){
    fast;
    int n; cin >> n;
    int in[n+1][3];
    in[0][0]=0, in[0][1]=0, in[0][2]=0;
    for(int i=1 ; i<n+1 ; i++)
        cin >> in[i][0]  >> in[i][1]  >> in[i][2];

    int a[n+1][3];
    a[0][0]=0, a[0][1]=0, a[0][2]=0;
    cout << endl;
    for(int i=1; i<n+1 ; i++){
        a[i][0] = in[i][0] + max(a[i-1][1],a[i-1][2]);
        a[i][1] = in[i][1] + max(a[i-1][0],a[i-1][2]);
        a[i][2] = in[i][2] + max(a[i-1][0],a[i-1][1]);
    }
    cout << max(a[n][0], max(a[n][1],a[n][2])) << endl;
}

Measured memory_bytes: 2560
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String s = br.readLine();
        String[] days = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
        
        for(int i = 0; i < 7; i++){
            if(s.equals(days[i])){
                out.println(7 - i);
                break;
            }
        }
        
        out.close();
        
    }
}

Measured memory_bytes: 32516
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int rev(int x,int t) {
	int z[6];
	for (int i = 0; i < t; i++) {
		z[i] = x % 10;
		x /= 10;
	}
	sort(z, z+t);
	int ma = 0; int mi = 0;
	for (int i = 0; i < t; i++) {
		ma += z[i]*(int)(pow(10, i)+0.0001);
		mi += z[i] * (int)(pow(10, t-1-i) + 0.0001);
	}
	return ma - mi;
}
int main() {
	int a, l;
	while (cin >> a >> l) {
		if (l == 0)break;
		vector<int>A;
		A.push_back(a);
		bool f = true;
		while (f) {
			a = rev(a, l);
			for (int i = 0; i < (int)A.size(); i++) {
				if (a == A[i]) {
					cout << i << " " << a <<" "<< (int)A.size()-i << endl;
					f = false;
				}
				if (!f)break;
			}
			A.push_back(a);
		}
	}
	return 0;
}



Measured memory_bytes: 3276
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;
typedef long long ll; typedef long double db;
const int N = 3e5 + 5, M = 1e9 + 7;

int main() {
  ll n, d;
  cin >> n >> d;
  ll ans = 0, x, y;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    if (d * d >= (x * x + y * y)) ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  int K;cin>>K;
  string S;cin>>S;
  if(S.size()<=K) cout<<S<<endl;
  else{
    string tmp = "...";
    string tmps = S.substr(0,K);
    cout << tmps+tmp << endl;
  }
}

Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<string>

using namespace std;

int main(void) {

	string s;
	int n = 0;

	for (int k = 0; k < 4; k++) {
		cin >> s[k];
		if (s[k] == '+')n++;
		else if (s[k] == '-')n--;
	}

	cout << n << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace At
{
    class Program
    {
        static void Main(string[] args)
        {
            var ans = 0;
            var input = ReadInts();
            var a = input[0];
            var b = input[1];
            for (int i = 0; i < 2; i++)
            {

                if (a > b)
                {
                    ans += a;
                    a--;
                }
                else
                {
                    ans += b;
                    b--;
                }
            }
            WriteLine(ans);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    if (s == string(s.rbegin(), s.rend())) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int h, w, i, j;
	for(;;){scanf("%d %d", &h, &w);
		if(h == 0 && w == 0){
			break;}
		for(i=1;i<=h;i++){
			for(j=1;j<=w;j++){
				if((i+j)%2==0){
					printf("#");
				}
				else if((i+j)%2==1){
					printf(".");
				}
			}
			printf("\n");
	}
		printf("\n");
	}
return 0;
	}


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
inline void max_self(long long &a, long long b){
	a = max(a,b);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,w;
	cin>>n>>w;
	vector<int> val(n), wt(n);

	for (int i=0; i<n;i++)cin>>wt[i]>>val[i];

	long long dp[n+1][w+1];
	
	for (int i=0;i<=n;i++)
		dp[i][0]=0;
	for (int i=0;i<=w;i++)dp[0][i]=0;
	
	for (int item=1; item<=n; item++){	

		for (int weight=1;weight<=w; weight++){

			dp[item][weight] = dp[item-1][weight];
			if(weight >= wt[item-1]){
				max_self(dp[item][weight], val[item-1]+dp[item-1][weight- wt[item-1]]);
			}			
		}
	}
	cout<<dp[n][w];

	return 0;
};


Measured memory_bytes: 82476
N = int(input())
numList = list(map(int, input().split()))
numList.sort(reverse = True)

target1 = False
target2 = False

i = 0

while i < N-1:
    if numList[i] == numList[i+1]:
        if target1 == False:
            num1 = numList[i]
            target1 = True
            i += 1
        elif target1 == True:
            num2 = numList[i]
            target2 = True
    if target1 == True and target2 == True:
        break
    i += 1

if target2 == False:
    print("0")
else:
    print(num1 * num2)


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

int main()
{
  while (true)
  {
    char board[8][8];
    for (int i=0; i<8; i++)
    {
      for (int j=0; j<8; j++)
      {
        cin >> board[i][j];
      }
    }

    bool flag = false;
    for (int i=0; i<8; i++)
    {
      for (int j=0; j<8; j++)
      {
        if ( board[i][j] == '1' )   //  ブロックがあれば
        {
          if ( board[i+3][j] == '1' )
          {
            cout << 'B' << endl;
          }
          else if ( board[i][j+3] == '1' )
          {
            cout << 'C' << endl;
          }
          else if ( board[i+2][j-1] == '1' )
          {
            cout << 'D' << endl;
          }
          else if ( board[i+1][j+2] == '1' )
          {
            cout << 'E' << endl;
          }
          else if ( board[i+2][j+1] == '1' )
          {
            cout << 'F' << endl;
          }
          else if ( board[i+1][j-1] == '1' )
          {
            cout << 'G' << endl;
          }
          else
          {
            cout << 'A' << endl;
          }
          flag = true;
        }
        if (flag) break;
      }
      if (flag) break;
    }

    char dummy;
    cin >> noskipws;
    cin >> dummy >> dummy;
    cin >> skipws;
    if ( cin.eof() ) break;
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1, 0);
  REP1(i, N) cin >> A[i];
  sort(ALL(A));
  vector<ll> sum(N + 1, 0);
  REP1(i, N) sum[i] = sum[i - 1] + A[i];
  int ng = 0;
  REP1(i, N - 1) {
    if (2 * sum[i] < 1ll * A[i + 1]) ng = i;
  }
  cout << N - ng << endl;
  return 0;
}

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

using namespace std;

int main() {
		int N;
		cin >> N;
		vector<int> v(N, 0);
		vector<int> even_c(100001, 0);
		vector<int> odd_c(100001, 0);
		for (int i = 0; i < N; i++) {
				cin >> v[i];
				if (i%2 == 0) even_c[v[i]]++;
				else odd_c[v[i]]++;
		}
		
		int even_first_c = 0, odd_first_c = 0, even_second_c = 0, odd_second_c = 0;
		int even_first, odd_first;
		for (int i = 1; i <= 100000; i++) {
				if (even_first_c < even_c[i]) {
						even_first = i;
						even_second_c = even_first_c;
						even_first_c = even_c[i];
				} else if (even_second_c < even_c[i]) {
						even_second_c = even_c[i];
				}

				if (odd_first_c < odd_c[i]) {
						odd_first = i;
						odd_second_c = odd_first_c;
						odd_first_c = odd_c[i];
				} else if (odd_second_c < odd_c[i]) {
						odd_second_c = odd_c[i];
				}
		}

		if (even_first == odd_first) cout << N - max(even_first_c+odd_second_c, odd_first_c+even_second_c) << endl;
		else cout << N - even_first_c - odd_first_c << endl;

		return 0;
}


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


int main(){


    string a, b, c;

    int n, i;

    int k = 0;

    set<char> s;

 
    cin >> n >> a >> b >> c;


    for( i = 0 ; i < n ; i = i + 1 ){

         s.insert( a.at(i) );

         s.insert( b.at(i) );

         s.insert( c.at(i) );

         k += s.size() - 1;

         s.clear();

         }


    cout << k << endl;


    return 0;


    }

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

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template
str s;
int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

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

    cin>>s;
    for(int i=0;i<s.size();i++) if(s[i]==',') s[i]=' ';
    cout<<s<<newl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#ifdef __linux__
#define getchar getchar_unlocked
#endif
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
#ifdef ztzshiwo
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
#endif
}
int n,now,ans;
char s[10];
inline int Query(int x)
{
	printf("%d\n",x-1); fflush(stdout);
	scanf("%s",s);
	if(s[0]=='V')exit(0);
	return s[0]=='M';
}
int main()
{
	//file();
	read(n);
	now=Query(1);
	int l=1,r=n;
	while(l<=r)
	{
		int mid=(l+r)>>1;
		if(((Query(mid)^mid)&1)!=(now^1))r=mid-1;
		else l=mid+1,ans=mid;
	}
	Query(ans+1);
	return 0;
}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

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

    ll cur = sz(s)-1;

    while(cur>=0)
    {
        if(s[cur]=='r')
        {
            if(cur>=5 && s[cur-1]=='e' && s[cur-2]=='s' && s[cur-3]=='a' && s[cur-4]=='r' && s[cur-5]=='e')
            {
                cur-=6;
            }

            else if(cur>=6 && s[cur-1]=='e' && s[cur-2]=='m' && s[cur-3]=='a' && s[cur-4]=='e' && s[cur-5]=='r' && s[cur-6]=='d')
            {
                cur-=7;
            }

            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }

        else if(s[cur]=='e')
        {
            if(cur>=4 && s[cur-1]=='s' && s[cur-2]=='a' && s[cur-3]=='r' && s[cur-4]=='e')
            {
                cur-=5;
            }

            else
            {
                cout << "NO" << endl;
                return 0;
            } 
        }

        else if(s[cur]=='m')
        {
            if(cur>=4 && s[cur-1]=='a' && s[cur-2]=='e' && s[cur-3]=='r' && s[cur-4]=='d')
            {
                cur-=5;
            }

            else
            {
                cout << "NO" << endl;
                return 0;
            }
        }

        else
        {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 512
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define MOD 998244353
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
#define ar array
#define ld long double
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
char c[4]={'D' , 'R' , 'U' , 'L'};
const ll maxN=2e5+5;
ll n  , a[maxN] , dp[maxN];
void solve(){
	cin>> n ;
	for(ll i=0;i<n ; i++)cin>>a[i];
	for(ll i=1;i<n ;i++){
		dp[i]=inf;
		for(ll j=1;j<=2; j++){
			if(i-j>=0)
				dp[i]=min(dp[i] , dp[i-j]+abs(a[i]-a[i-j]));
		}
	}	
	cout<<dp[n-1]<<endl;
}
int main(){
	//mahakal();
	fast;
	ll t =1 ;
	//cin>> t ; 
	while(t--)solve();
	//cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl; 
	return 0;
}

Measured memory_bytes: 5220
#include <stdio.h>

int main(void) {
	int M, N;
	char map[128][128] = {{0}};
	char dame[128][128] = {{0}};
	int i, j;
	int count = 0;
	if (scanf("%d%d", &M, &N) != 2) return 1;
	for (i = 1; i <= M; i++) {
		if (scanf("%126s", &map[i][1]) != 1) return 1;
	}
	for (j = 1; j <= N; j++) dame[1][j] = 1;
	for (i = 1; i <= M; i++) {
		for (j = 1; j <= N; j++) {
			int k, l;
			if (map[i][j] == 'o') {
				for (l = -1; l <= 1; l++) dame[i][j + l] = 1;
			} else if (map[i][j] == 'x') {
				for (k = -1; k <= 1; k++) {
					for (l = -1; l <= 1; l++) dame[i + k][j + l] = 1;
				}
			}
		}
	}
	for (i = 1; i <= M; i++) {
		for (j = 1; j <= N; j++) {
			if (!dame[i][j]) count++;
		}
	}
	printf("%d\n", count);
	return 0;
}



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

int main() {
  int H, W;
  cin >> H >> W;

  for (int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < H; i++){
    string str;
    cin >> str;
    cout << "#" << str << "#" << endl;
  }
  
  for (int i = 0; i < W + 2; i++){
    cout << "#";
  }
  cout << endl;
}


Measured memory_bytes: 256
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
)

func main() {
    var fp *os.File = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)

    line := readLine(reader)
    arr := strings.Split(line, " ")
    H, _ := strconv.Atoi(arr[0])
    W, _ := strconv.Atoi(arr[1])

    h := H + 2
    w := W + 2
    var str string

    for y := 0; y < h; y++ {
        if y > 0 && y < h - 1 {
            str = readLine(reader)
        } else {
            str = ""
        }

        for x := 0; x < w; x++ {
            if x > 0 && x < w -1 && str != "" {
                fmt.Print(string(str[x-1]))
            } else {
                fmt.Print("#")
            }

            if x == w - 1 {
                fmt.Println()
            }
        }
    }
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1024)

    for {
        l, p, _ := reader.ReadLine()

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

// 1からnまでの整数の約数の個数を計算する関数
// O(logn)、3の約数の個数はres[3]
vector<ll> CalcDivisorNum(ll n) {
    vector<ll> res(n+1, 0);
    for (ll i = 1; i <= n; i++) {
        for (ll j = 1; (i*j) <= n ; j++) {
            res[i * j]++;
        }
    }
    return res;
}

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

    vector<ll> d_num = CalcDivisorNum(n);
    ll ans = 0;
    for (ll i = 1; i <= n; i++) {
        ans += i * d_num[i];
    }
    cout << ans << endl;
    return 0;
}

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

    using namespace std;
    template <typename T>
    void debug(string t, T input) {
        cout<<t<<"-> "<<input<<"\n";
    }
    template <typename T>
    void debug(int i,string t, T input) {
        cout<<"Case#"<<i<<" "<<t<<"-> "<<input<<"\n";
    }

    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        long long x;
        cin>>x;
        for(long long i=-2000;i<=2000;i++){
            for(long long j=-2000;j<=2000;j++){
                long long a=i*i*i*i*i;
                long long b=j*j*j*j*j;
                if(a-b==x){
                    cout<<i<<" "<<j;
                    return 0;
                }
            }
        }
        return 0;
    }


Measured memory_bytes: 3636
import numpy as np

N, M = [int(i) for i in input().split()]
X = [int(i) for i in input().split()]

if N >= M:
    print(0)
    exit(0)

X = np.sort(X)
diff = []
for i in range(len(X) - 1):
    diff.append(X[i + 1] - X[i])

diff = np.sort(diff)
result = 0
for i in range(len(diff) - N + 1):
    result += diff[i]
print(result)


Measured memory_bytes: 25020
#include <stdio.h>

int main(void) {
	int w,t = 0,n,i,j,h,p,a,b,c[1024][1024] = {0};
	while(scanf("%d",&w) , w != 0){
		a = 0;
		b = 1024;
		t++;
		scanf("%d",&n);
		for(i = 1;i <= n;i++){
			scanf("%d,%d",&p,&h);
			for(j = 0;j <= w;j++){
				if (h <= j){
					if(c[i - 1][j - h] + p > c[i - 1][j]){
						c[i][j] = c[i - 1][j - h] + p;
					}
					else{
						c[i][j] = c[i - 1][j];
					}
				}
				else{
					c[i][j] = c[i - 1][j];
				}
			}
		}
		for(i = w;i >= 0;i--){
			if(c[n][i] >= a){
				if(i < b){
					a = c[n][i];
					b = i;
				}
			}
		}
		printf("Case %d:\n%d\n%d\n",t,a,b);
	}
	return 0;
}

Measured memory_bytes: 4700
def remainder_minimization_2019(L: int, R: int)->int:
    if R-L < 2018:
        ans = float('inf')
        for i in range(L, R):
            for j in range(i+1, R+1):
                ans = min(ans, (i * j) % 2019)

        return ans

    return 0


if __name__ == "__main__":
    L, R = map(int, input().split())

    ans = remainder_minimization_2019(L, R)
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <deque>
#include <queue>

using namespace std;
const int kMaxN = 1e5 + 10;
typedef long long int64;

void solve() {
	int64 x, y;
	cin >> x >> y;

	if (abs(x-y) <= 1) {
		cout << "Brown";
	} else {
		cout << "Alice";
	}
	cout << "\n";
}

void reset() {
}

int main() {
	int tests = 1;

	for (;tests; --tests) {
		solve();
	}
}

Measured memory_bytes: 256
n, m = map(int, input().split())

maxl = 0
minr = 10 ** 6
for i in range(m):
    l, r = map(int, input().split())
    maxl = max(maxl,l)
    minr = min(minr,r)

if minr < maxl:
    print(0)
else:
    print(minr-maxl+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
int v[N];
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    fast;
    
    int n,m;
    cin >> n >> m;
    char v[n][n], arr[m][m];
    fore(i, 0, n){
        string aux;
        cin >> aux;
        fore(j, 0, sz(aux))
            v[i][j] = aux[j];
    }

    fore(i, 0, m){
        string aux;
        cin >> aux;
        fore(j, 0, sz(aux))
            arr[i][j] = aux[j];
    }

    bool flag = 0;
    for(int i = 0; i < n - m + 1 && !flag; i++){
        for(int j = 0; j < n - m + 1 && !flag; j++){
            bool sw = 1;
            int x = 0,y = 0;
            for(int k = i; k < m + i; k++){
                for(int l = j; l < m + j; l++){
                    //cout << arr[k - i][l - j];
                    if(v[k][l] != arr[k - i][l - j]){
                        sw = 0;
                        break;
                    }
                }
            }
            if(sw)
                flag = 1;
        }
    }
    cout << (flag ? "Yes":"No") << '\n';
    return 0;   
}

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

typedef long long ll;
const int maxn = 5010;
struct data {
	int h, p;
	bool operator < (const data &other) const {
		return h + p < other.h + other.p;
	}
} a[maxn];
ll dp[maxn];
int n, res;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d %d", &a[i].h, &a[i].p);
		dp[i] = 1e18;
	}
	sort(a + 1, a + n + 1);
	for (int i = 1; i <= n; i++) {
		for (int j = n; j >= 1; j--) {
			if (dp[j - 1] <= a[i].h) {
				dp[j] = min(dp[j], dp[j - 1] + a[i].p);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		if (dp[i] != 1e18) {
			res = i;
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define PII pair<int, int>
#define VI vector<int>
#define VPII vector<PII>
#define LL long long
#define LD long double
#define f first
#define s second
#define MP make_pair
#define PB push_back
#define endl '\n'
#define ALL(c) (c).begin(), (c).end()
#define SIZ(c) (int)(c).size()
#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 FORD(i, b, e) for(int i = (b); i >= (int)(e); --i)

#define sim template<class n
sim, class s> ostream & operator << (ostream &p, pair<n, s> x)
{return p << "<" << x.f << ", " << x.s << ">";}
sim> auto operator << (ostream &p, n y) ->
typename enable_if<!is_same<n, string>::value, decltype(y.begin(), p)>::type 
{int o = 0; p << "{"; for(auto c: y) {if(o++) p << ", "; p << c;} return p << "}";}
void dor() {cerr << endl;}
sim, class...s> void dor(n p, s...y) {cerr << p << " "; dor(y...);}
sim, class s> void mini(n &p, s y) {if(p>y) p = y;}
sim, class s> void maxi(n &p, s y) {if(p<y) p = y;}
#ifdef DEB
#define debug(...) dor(__FUNCTION__, ":", __LINE__, ": ", __VA_ARGS__)
#else
#define debug(...)
#endif 

#define I(x) #x " =", (x), " "
#define A(a, i) #a "[" #i " =", i, "] =", a[i], " "

int main()
  {
  int k;
  string s;
  cin >> k >> s;
  if(s.size() <= k)cout << s << endl;
  else
    {
    while(s.size() > k)s.pop_back();
    s += "...";
    cout << s << endl;
    }

  }


Measured memory_bytes: 3628
import math


class Dice:
    def __init__(self, top, south, east, west, north, bottom):
        self.top = top
        self.south = south
        self.east = east
        self.west = west
        self.north = north
        self.bottom = bottom

    def roll_east(self):
        tmp = self.top
        self.top = self.west
        self.west = self.bottom
        self.bottom = self.east
        self.east = tmp

    def roll_north(self):
        tmp = self.top
        self.top = self.south
        self.south = self.bottom
        self.bottom = self.north
        self.north = tmp

    def roll_south(self):
        tmp = self.top
        self.top = self.north
        self.north = self.bottom
        self.bottom = self.south
        self.south = tmp

    def roll_west(self):
        tmp = self.top
        self.top = self.east
        self.east = self.bottom
        self.bottom = self.west
        self.west = tmp

    def spin_left(self):
        tmp = self.north
        self.north = self.east
        self.east = self.south
        self.south = self.west
        self.west = tmp

    def check(self, dice2):
        ans = False
        for x in range(4):
            if dice2.south == self.south:
                if dice2.east == self.east and dice2.west == self.west and \
                        dice2.north == self.north and dice2.bottom == self.bottom:
                    ans = True
            self.spin_left()
        return ans

    def top_check(self, dice2):
        ans = False
        if dice2.top == self.top:
            ans |= self.check(dice2)
        if dice2.top == self.south:
            self.roll_north()
            ans |= self.check(dice2)
        if dice2.top == self.east:
            self.roll_west()
            ans |= self.check(dice2)
        if dice2.top == self.west:
            self.roll_east()
            ans |= self.check(dice2)
        if dice2.top == self.north:
            self.roll_south()
            ans |= self.check(dice2)
        if dice2.top == self.bottom:
            self.roll_south()
            self.roll_south()
            ans |= self.check(dice2)
        if ans:
            print("Yes")
        else:
            print("No")


a, b, c, d, e, f = map(int, input().split())
dice = Dice(a, b, c, d, e, f)
a, b, c, d, e, f = map(int, input().split())
dice2 = Dice(a, b, c, d, e, f)
dice.top_check(dice2)



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

using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;

ll mul(ll a, ll b) { return a * b % MOD; }
 
ll add(ll a, ll b) { return (a + b) % MOD; }
 
ll sub(ll a, ll b) { return (a - b + MOD) % MOD; }

ll my_pow(ll a, ll b, ll r = 1){
    if (b != 1){
        if (b%2 == 1){r = mul(r,a);}
        return my_pow(mul(a,a), b/2, r);
    }else{
        return mul(r, a);
    }
}


int main(){
    ll n, k, ans=0;
    cin >> n >> k;
    vector<ll> arr(k+1,0);
    for(ll i=k; i>0; i--){
        arr[i] = my_pow((k/i),n);
        for(ll j = 2 * i; j <= k; j += i){
            arr[i] -= arr[j];
        }
    }
    for(ll i=1; i<=k; i++){
        ans = add(ans, mul(arr[i],i));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m,n,x,y;
	cin>>n>>m>>x>>y;
	int nn[101],mm[101];
	for (int i=0;i<n;i++) cin>>nn[i];
	for (int i=0;i<m;i++) cin>>mm[i];
	if (x>=y){cout<<"War"<<endl;return 0;}
	sort(nn,nn+n);
	sort(mm,mm+m);
	if (nn[n-1]>=mm[0]){cout<<"War"<<endl;return 0;}
	if (nn[n-1]>=y||mm[0]<=x){cout<<"War"<<endl;return 0;}
	cout<<"No War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){

    int N, M;
    cin >> N;
    cin >> M;

    vector<int> p(M);
    vector<string> S(M);

    for(int i=0; i<M; i++){
        cin >> p[i];
        cin >> S[i];
    }

    // vector<int> wa_time(N, 0);
    vector<bool> ac_or_not(N, false);
    vector<int> tmp_wa_number(N, 0);
    
    int wa_number = 0;
    int correct_number = 0;

    for(int i=0; i<M; i++){
        if((ac_or_not[p[i] - 1] == false) && (S[i] == "WA")){
            tmp_wa_number[p[i] - 1] += 1;
        }else if((ac_or_not[p[i] - 1] == false) && (S[i] == "AC")){
            correct_number += 1;
            wa_number += tmp_wa_number[p[i] - 1];
            ac_or_not[p[i] - 1] = true;
        }
    }

    cout << correct_number;
    cout << " ";
    cout << wa_number << endl;

    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int n, k;
    cin >> n >> k;

    int a[n];
    for (int& e: a) cin >> e;

    vector<int> dp(n, 1e9);
    dp[0] = 0;

    for (int i=1; i<n; i++) {
        for (int j=1; j<=k; j++) {
            if (j > i) break;
            dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
        }
    }
    cout << dp[n-1] << "\n";
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		 Scanner scan = new Scanner(System.in);
		 int n;	//使う数字の範囲
		 int x;	//合計の目的指数
		 int cnt;	//組み合わせの数
		 while(true){
			 n = Integer.parseInt(scan.next());
			 x = Integer.parseInt(scan.next());
			 cnt = 0;
			 if(x == 0 && n == 0){
				 break;
			 }else{
				 for(int i = 1; i <= n; i++ ){
					 for(int l = i + 1; l <= n; l++ ){
						 for(int k = l + 1; k <= n; k++ ){
							 if((i + l + k) == x){
								 cnt++;
							 }
						 }
					 }
				 }
		 }//while 
			 System.out.println(cnt);
		 }
	}
}

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

int main() {
	int n,j = 0;
	cin >> n;
	for (int i = 1; i <= 9; i++) {
		for (int o = 1; o <= 9; o++) {
			if (i * o == n) {
				j = 1;
			}
		}
	}
	if (j == 1) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

#define box 10000

int main()
{
	int i,num=0;

	int data[box];

	while(1){
		scanf("%d",&i);
		if(i==0) break;
		data[num]=i;
		num++;
	}
	
	for(i=0;i<num;i++) printf("Case %d: %d\n",i+1,data[i]);

	return 0;
}
		

	


Measured memory_bytes: 2048
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#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 ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    ll n, k; cin >> n >> k;
    vector<ll> v(n, 0);
    REP(i, n) {
        cin >> v[i];
    }

    ll res = 10e10;
    FOR(i, 0, n-k) {
        ll left = v[i];
        ll right = v[i+k-1];

        if (left == right) {
            res = min(res, abs(left));
        } else if (left < 0 && right <= 0) {
            res = min(res, abs(left));
        } else if (left >= 0 && right > 0) {
            res = min(res, abs(right));
        } else if (abs(left) < abs(right)) {
            res = min(res, abs(left)*2 + abs(right));
        } else {
            res = min(res, abs(right)*2 + abs(left));
        }
    }
    cout << res << endl;
    // 5 3
    // -30 -10 10 20 50

    // 0がない場合: 左右合わせてkをつける
    // 0がある場合: 左右合わせてk-1をつける
    // コスト計算はそれぞれ端だけ考えれば良い
    // 0 -> -10 -> 20: 40
    return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)

static const double PI = 3.14159265358979;
static const ll MOD = 1e9 + 7;
static const ll INF = (ll)1 << 62;

char m[501][501] = {};
int h, w;
int y_1[1000000] = {};
int x1[1000000] = {};
int y2[1000000] = {};
int x2[1000000] = {};
int p = 0;

int main() {
	cin >> h >> w;
	repe(i, 1, h)repe(j, 1, w)cin >> m[i][j];

	repe(i, 1, h) {
		repe(j, 1, w - 1) {
			if (m[i][j] & 1) {
				m[i][j + 1]++;
				y_1[p] = i;
				x1[p] = j;
				y2[p] = i;
				x2[p] = j + 1;
				p++;
			}
		}
	}
	repe(i, 1, h - 1) {
		if (m[i][w] & 1) {
			m[i + 1][w]++;
			y_1[p] = i;
			x1[p] = w;
			y2[p] = i + 1;
			x2[p] = w;
			p++;
		}
	}
	cout << p << endl;
	rep(i, 0, p) {
		cout << y_1[i] << " " << x1[i] << " " << y2[i] << " " << x2[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 13056
#!/usr/bin/env python
# coding: utf-8

# In[4]:


N = int(input())
T = list(map(int, input().split()))
M = int(input())
for _ in range(M):
    p,x = map(int, input().split())
    ans = sum(T) - T[p-1] + x
    print(ans)



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    bool a = 0;
    for(int i = 0; i < n/4 + 1; i++){
        for(int j = 0; j < n/7 + 1; j++){
            if(n == 4 * i + 7 * j){
                a = 1;
            }
        }
    }
    if(a == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int a, p; readV(a, p);
  writeln((a*3+p)/2);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;





int main(){

	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);

	if(a+b == c || a+c == b || b+c == a){

		printf("Yes\n");

	}else{

		printf("No\n");
	}

	return 0;
}


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

int dx[] = {1, 0};
int dy[] = {0, 1};

int main() {
    int H, W; cin >> H >> W;
    vector<vector<int>> A(H, vector<int>(W));
    REP(i, 0, H) REP(j, 0, W) cin >> A[i][j];

    vector<pair<pair<int, int>, pair<int, int>>> ans;
    REP(i, 0, H) {
        REP(j, 0, W) {
            if (A[i][j] % 2 == 0) continue;

            bool moved = false;
            int mi = -1, mj = -1;
            REP(k, 0, 2) {
                int ni = i + dx[k];
                int nj = j + dy[k];
                if (ni >= H || nj >= W) continue;
                if (A[ni][nj] % 2 == 1) {
                    moved = true;
                    A[ni][nj]++;
                    A[i][j]--;
                    ans.push_back({{i + 1, j + 1}, {ni + 1, nj + 1}});
                    break;
                }
                mi = ni; mj = nj;
            }
            if (!moved && mi != -1 && mj != -1) {
                A[mi][mj]++;
                A[i][j]--;
                ans.push_back({{i + 1, j + 1}, {mi + 1, mj + 1}});
            }
        }
    }
    cout << ans.size() << endl;
    for (auto a : ans) cout << a.first.first << " " << a.first.second << " " << a.second.first << " " << a.second.second << endl;

    // cout << "---" << endl;
    // REP(i, 0, H) {
    //     REP(j, 0, W) {
    //         cout << A[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 5232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int k = sc.nextInt();

		int result = k;

		for(int i = 1; i < n; i++){
			result *= k - 1;
		}

		System.out.println(result);
	}
}

Measured memory_bytes: 21716
N = int(input())
N_List = sorted(list(map(int,input().split())))
flg = 0
ans = 1
if N % 2 == 1:
    if N_List[0] != 0:
        flg = 1
    else:
        for i in range(2,N,2):
            if i*2 != sum(N_List[i-1:i+1]):
                flg = 1
                break
            else:
                ans = (ans * 2) % ((10**9) +7)
        

else:
    for i in range(1,N,2):
        if i*2 != sum(N_List[i-1:i+1]):
            flg = 1
            break
        else:
            ans = (ans * 2) % ((10**9) +7)

if flg == 0:
    print(ans)
else:
    print(0)

                


Measured memory_bytes: 20652
N = int(input())
M = int(N**0.5)
l = []
if N <= 3:
  print(1)
else:
  for a in range(1, M+1):
    if N % a == 0:
      b = int(N/a)
    else:
      continue
    l.append(max(len(str(a)), len(str(b))))
  print(min(l))

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

#define mx 100005
#define ll long long 

void IO()
{
     #ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif
}

int ar[mx];
char ch[mx];

int m,n,k,ii;


void solve()
{
	double a,b,c,need;
	cin>>a>>b>>c;
    need=a/c;
    if(b>=need)printf("Yes\n");
    else printf("No\n");
}

int main()
{
	IO();

	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
int main(void){
    int a,b;
    char op;
        while(1){
            scanf("%d %c %d",&a,&op,&b);
            if(op=='?') break;
            if(op=='+'){
                printf("%d\n",a+b);
            }
            if(op=='-'){
                printf("%d\n",a-b);
            }
            if(op=='*'){
                printf("%d\n",a*b);
            }
            if(op=='/'){
                printf("%d\n",a/b);
            }
        }
    return 0;
}


Measured memory_bytes: 2748
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

#define ll         long long
#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

int a, b;

int main(){
    cin >> a >> b;
    if (a * b % 2 == 0) {
      cout << "Even";
    } else {
      cout << "Odd";    
    }
    return 0;
}


Measured memory_bytes: 256