akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int n,m,big,small;
unsigned long long ans=1;

int main(){
	cin>>n>>m;
	if(n>=m){
		big=n;
		small=m;
	}
	else{
		big=m;
		small=n;
	}
	if(big-small>=2) cout<<"0"<<endl;
	else {
		if(big-small==1){
			for(int i=1;i<=small;i++){
				ans*=i;
				ans%=(1000000000+7);
			}
			for(int i=1;i<=big;i++){
				ans*=i;
				ans%=(1000000000+7);
			}
		}
		else if(big-small==0){
			for(int i=1;i<=big;i++){
				ans*=i;
				ans%=(1000000000+7);
			}
			for(int i=1;i<=big;i++){
				ans*=i;
				ans%=(1000000000+7);
			}
			ans*=2;
			ans%=(1000000000+7);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);
        Integer n = scan.nextInt();
        String s = new String(scan.next());

        int count = 0;
        while(true){
            int i;
            if((i = s.indexOf("ABC")) != -1){
                count++;
                s = s.substring(i+2);
            }else{
                break;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#[allow(unused)]
use proconio::marker::*;
use proconio::{fastout, input};
#[allow(unused)]
use std::cmp::{max, min};
#[allow(unused)]
use std::collections::{HashMap, HashSet, VecDeque};
#[fastout]
fn main() {
    input! {
        a: i32,
        b: i32,
    }
    println!("{}", a * b);
}


Measured memory_bytes: 2140
import bisect


def read():
    N = int(input().strip())
    A_iter = map(int, input().strip().split())
    B_iter = map(int, input().strip().split())
    return N, A_iter, B_iter


def index(a, x):
    i = bisect.bisect_left(a, x)
    return i


def solve(N, A_iter, B_iter):
    C = []
    for a, b in zip(A_iter, B_iter):
        C.append(a - b)
    C = sorted(C)
    zero_index = index(C, 0)
    few = C[:zero_index]
    many = C[zero_index:]

    few_size = len(few)
    few_sum = -sum(few)

    if few_sum == 0:
        return few_size
    for i, m in enumerate(reversed(many)):
        few_sum -= m
        if few_sum <= 0:
            return few_size + i + 1
    return -1


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))


Measured memory_bytes: 22328
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int a[500010];

int main(){
  string s; cin >> s;
  ll k; cin >> k;
  int n=s.size();
  ll cnt=0;
  bool f=1;
  int j1=-1;
  int j2=-1;
  rep(i,n-1){
    if(s[i+1]==s[i]){
      cnt++;
      i++;
    }
    else{
      if(f) j2=i;
      f=0;
      j1=i+1;
    }
  }
  if(s[n-1]!=s[0]){
    cout << cnt*k << endl;
    return 0;
  }
  if(f){
    cout << n*k/2 << endl;
    return 0;
  }
  //
  int cnt3=0;
  for(int i=j1;i<n-1;i++){
    if(s[i+1]==s[i]){
      cnt3++;
      i++;
    }
  }
  int cnt4=0;
  rep(i,j2){
    if(s[i+1]==s[i]){
      cnt4++;
      i++;
    }
  }
  j2=n+j2;
  int cnt2=0;
  string ss=s+s;
  for(int i=j1;i<j2;i++){
    if(ss[i+1]==ss[i]){
      cnt2++;
      i++;
    }
  }
  ll ans=cnt*k+(-cnt3-cnt4+cnt2)*(k-1);
  cout << ans << endl;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
d = deque()
for _i in range(n):
    line = input().split()
    order = line[0]
    if order == 'deleteFirst':
        d.popleft()
    elif order == 'deleteLast':
        d.pop()
    else:
        key = line[1]
        if order == 'insert':
            d.appendleft(key)
        elif order == 'delete':
            try:
                d.remove(key)
            except ValueError:
                pass
        else:
            raise ValueError('Invalid order: {order}')

print(' '.join(d))



Measured memory_bytes: 69732
//@author :  |< U $ |-|
#include<iostream>
#include<vector>
#include<math.h>
#include<unordered_map>
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;

#define ll  long long 

int main(){
    
    #ifndef ONLINE_JUDGE
    TakeInput
    #endif
    
    ll i,j,n,m;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    ll count=0;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            for(ll k=j+1;k<n;k++){
                if(a[i]+a[j] > a[k] && a[i]+a[k] > a[j] && a[k]+a[j] > a[i] && a[i]!=a[j] && a[k]!=a[j] && a[i]!=a[k]){
                    count++;
                    // cout<<a[i]<<" "<<a[j]<< " "<<a[k]<<endl;
                }
            }
        }
    }
    cout<<count;
}
 
 
 

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

int main()
{
	string n;
	cin >> n;
	for(auto c:n)
	{
		if(c=='7')
		{
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {

	public void doIt(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			int d = sc.nextInt();
			int e = sc.nextInt();
			int f = sc.nextInt();
			double temp1 = a * e - d * b;
			double temp2 = c * e - f * b;
			double x = temp2 / temp1;
			double y = ((double)c - x * a) / b;
			if(x == -0.0){
				x = 0.0;
			}
			System.out.printf("%1.3f %1.3f\n", x, y);
		}

	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();
	}
}

Measured memory_bytes: 12000
import sys
input = sys.stdin.readline
input = sys.stdin.buffer.readline

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))


def main():
    A,B,C,D = MI()

    while True:
        C = C-B
        if C <= 0:
            print("Yes")
            break
        A = A - D
        if A <= 0:
            print("No")
            break
    """
    if w>=s:
        print("unsafe")
    else:
        print("safe")
        """




if __name__ == "__main__":
	main()

Measured memory_bytes: 61780
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut line = String::new();
    std::io::stdin().read_to_string(&mut line).unwrap();
    let mut it = line.split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<i64> = it.by_ref().take(n).map(|a| a.parse().unwrap()).collect();
    let mut count = HashMap::new();
    let mut ans: i64 = 0;
    for i in 0..n {
        {
            ans += *count.get(&(i as i64 - a[i])).unwrap_or(&0i64);

        }
        {
            let cnt = count.entry(a[i] + i as i64).or_insert(0i64);
            *cnt += 1;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 11752
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	printf("%d\n", min(a, b) + min(c, d));

	Please AC;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a=="H" && b=="H"){
	cout<<"H\n";
}
	else if(a=="D"&&b=="D"){
	cout<<"H\n";
}
	else{
	cout<<"D\n";
}
}

Measured memory_bytes: 888
N = int(input())
D,X = [int(i) for i in input().split()]
A = [int(input()) for j in range(N)]
ans = 0
for a in A:
  i = 1
  tmp = 0
  while i <= D:
    tmp += 1
    i += a
  ans += tmp
print(ans + X)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int a, b;
	cin >> a >> b;

	if (a * b % 2) {
		cout << "Odd" << endl;
	}
	else {
		cout << "Even" << endl;
	}
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
map<long long,int> cnt;
int n;
int a;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
		cnt[-a]++;
	}
	long long num1=0,num2=0;
	long long numrect=0;
	bool rect=true,one=true,two=true;
	for(__typeof(cnt.begin()) it=cnt.begin();it!=cnt.end();it++){
		if(it->second>=4&&rect){
			numrect=it->first*it->first;
			rect=false;
		}
		if(it->second>=2){
			if(one){
				num1=it->first;
				one=false;
			}
			else if(two){
				num2=it->first;
				two=false;
			}
		}
	}
	cout<<max(numrect,num1*num2)<<endl;
	return 0;
}


Measured memory_bytes: 6528
import sys
n=int(input())
sys.setrecursionlimit(k:=2*n)
T=[[]for _ in"_"*k]
for _ in range(n-1):a,b=map(int,input().split());T[a]+=b,;T[b]+=a,
def d(v,p):
 r=0
 for s in T[v]:
  if s!=p:r^=d(s,v)+1
 return r
print("ABloibc e"[d(1,1)<1::2])

Measured memory_bytes: 121688
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 2001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

int dp[5005];

int main() {
  int n;
  scanf("%d",&n);
  vp a(n);
  cin>>a;
  rep(i,n) a[i].fi += a[i].se;
  sort(rng(a));
  rrep(i,n) dp[i] = INF;
  rep(i,n) {
    drep(j,i+1) {
      if (dp[j] <= a[i].fi-a[i].se) mins(dp[j+1],dp[j]+a[i].se);
    }
  }
  int ans = 0;
  rep(i,n+1) if (dp[i] != INF) ans = i;
  cout<<ans<<endl;
  return 0;
}






















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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    cout << 'A' << b[0] << 'C' << '\n';
    return 0;
}


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

long long int a[200010] = {0LL};
long long int a2[200010] = {0LL};
vector<long long int> v;

int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++) {
        long long int tmp;
        cin >> tmp;
        a[tmp]++;
        v.emplace_back(tmp);
    }

    for(int i = 0; i <= n; i++) {
        if(a[i]>0){
            a2[i] = max(0LL, a[i]*(a[i]-1LL)/2LL);
        }
        else {
            a2[i] = 0LL;
        }
    }

    long long int sum = 0LL;
    for(int i = 0; i <= n; i++) {
        sum += a2[i];
    }

    for(int i = 0; i < n; i++) {
        long long int tmp_sum = sum;
        if(a[v[i]]-1LL >= 0 && a[v[i]]-2LL >= 0LL) {
            tmp_sum -= a2[v[i]];
            tmp_sum += max(0LL, (a[v[i]]-1LL)*(a[v[i]]-2LL)/2LL);
        }
        cout << tmp_sum << endl;
    }
    return 0;
}

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

using namespace std;

const int N = 200 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
vector<int> g[N];

bool read() {
    if (!(cin >> n))
        return false;

    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        cin >> u >> v;
        g[u - 1].emplace_back(v - 1);
        g[v - 1].emplace_back(u - 1);
    }

    return true;
}

pair<int, int> dfs(int v, int pr, int h) {
    pair<int, int> cur = { h, v };
    
    for (auto to : g[v])
        if (to != pr) {
            auto ret = dfs(to, v, h + 1);
            cur = (ret.first > cur.first ? ret : cur);
        }

    return cur;
}

void solve() {
    auto d = dfs(0, 0, 0);
    d = dfs(d.second, d.second, 0);
    cout << (d.first % 3 == 1 ? "Second\n" : "First\n");
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 26880
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

// 参考：https://qiita.com/drken/items/1b7e6e459c24a83bb7fd
// 1-indexed BIT
// add:log(N),sum:log(N),get_k-th:log(N)
// https://codeforces.com/contest/1354/problem/D
struct BIT {
    vector<ll> dat;

    BIT(int n) {
        dat.resize(n + 1);
        for(int i = 0; i < (int)dat.size(); i++)
            dat[i] = 0;
    }

    void init() {
        for(int i = 0; i < (int)dat.size(); i++) {
            dat[i] = 0;
        }
    }

    // a is 1-indexed
    void add(int a, ll x) {
        for(int i = a; i < (int)dat.size(); i += i & -i)
            dat[i] = dat[i] + x;
    }

    // [1,a], a is 1-indexed
    ll sum(int a) {
        ll res = 0;
        for(int i = a; i > 0; i -= i & -i) {
            res = res + dat[i];
        }
        return res;
    }

    // [a,b), a and b are 1-indexed
    ll sum(int a, int b) { return sum(b - 1) - sum(a - 1); }

    // k-th number (k is 1-indexed)
    // lower_bound
    int get(ll k) {
        if(k <= 0)
            return 0;
        int res = 0;
        int N = 1;
        while(N < (int)dat.size())
            N *= 2;
        for(int i = N / 2; i > 0; i /= 2) {
            if(res + i < (int)dat.size() && dat[res + i] < k) {
                k = k - dat[res + i];
                res = res + i;
            }
        }
        return res + 1;
    }
};

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    BIT fenwick(100);
    int res = INF;
    for(int bit = 0; bit < (1 << N); bit++) {
        if(__builtin_popcount(bit) != N / 2)
            continue;
        vector<pii> odd, even;
        rep(i, N) {
            if(bit & (1 << i))
                odd.emplace_back((i % 2 ? A[i] : B[i]), i);
            else
                even.emplace_back((i % 2 ? B[i] : A[i]), i);
        }
        sort(All(odd));
        sort(All(even));
        vector<pii> all;
        for(int i = 0; i < even.size(); i++) {
            all.pb(even[i]);
            if(i < odd.size())
                all.pb(odd[i]);
        }
        bool ok = 1;
        for(int i = 0; i < N - 1; i++) {
            if(all[i].first > all[i + 1].first)
                ok = 0;
        }
        if(ok) {
            vector<int> ids(N);
            rep(i, N) ids[i] = all[i].second + 1;
            fenwick.init();
            int tmp = 0;
            rep(i, N) {
                fenwick.add(ids[i], 1);
                tmp += i + 1 - fenwick.sum(ids[i]);
            }
            res = min(res, tmp);
        }
    }
    cout << (res == INF ? -1 : res) << endl;
    return 0;
}

Measured memory_bytes: 3652
/**
 * Author: AcFunction
 * Date:   2019-02-24 19:56:49
 * Email:  3486942970@qq.com
**/

#include <bits/stdc++.h>
#define ll long long
#define int ll
using namespace std;
const int INF = 1000000000; 
int n, a[10], ans = INF, A, B, C;  
signed main() {
  cin >> n >> A >> B >> C; 
  for(int i = 1; i <= n; i++) {
    cin >> a[i]; 
  }
  for(int s = 0; s < (1 << n) * (1 << n); s++) {
    int t[10] = {}; int cnt = 0;
    int x = s; 
    while(x) {
      t[++cnt] = x % 4; 
      x /= 4; 
    } int AA = 0, BB = 0, CC = 0, q = 0, w = 0, e = 0; 
    for(int i = 1; i <= n / 2; i++) swap(t[i], t[ n - i + 1 ]); 
    for(int i = 1; i <= n; i++) {
      if(t[i] == 1) { AA += a[i]; q++; }
      if(t[i] == 2) { BB += a[i]; w++; } 
      if(t[i] == 3) { CC += a[i]; e++; } 
    } int sum = 0; 
    if(q == 0 || w == 0 || e == 0) continue ; 
    sum += (max(q - 1, 0ll) + max(w - 1, 0ll) + max(e - 1, 0ll)) * 10; 
    sum += abs(AA - A) + abs(BB - B) + abs(CC - C); 
    ans = min(ans, sum);
    // cout << sum << endl;  
  } cout << ans << endl; 
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<int,int> m;
    REP(i,n) {
        int x;
        cin >> x;
        m[x]++;
    }

    cout << ( m.size() % 2 == 0 ? m.size() -1 : m.size() ) << endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d;
    int e,f,g,h;
    cin>>a>>b>>c>>d;
    cin>>e>>f>>g>>h;
    int x=a+b+c+d;
    int y=e+f+g+h;
    if(x>y){
        cout<<x<<endl;
    }
    else{
        cout<<y<<endl;
    }
     
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
const int N=200007;
int n,q,l,r;
long long a[N],v,up,down,ans=0,dif[N];
int main(){
	scanf("%d %d %lld %lld",&n,&q,&up,&down);
	scanf("%lld",&a[0]);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=0;i<n;i++){
		if(a[i]<a[i+1]) ans-=up*abs(a[i]-a[i+1]);
		else ans+=down*abs(a[i]-a[i+1]);
	}
	for(int i=0;i<n;i++){
		dif[i]=a[i]-a[i+1];
	}
	while(q--){
		scanf("%d %d %lld",&l,&r,&v);
		long long old=dif[l-1];
		dif[l-1]-=v;
		if(old<0) ans+=up*(-old);
		else ans-=down*old;
		if(dif[l-1]<0) ans-=up*(-dif[l-1]);
		else ans+=down*dif[l-1];
		if(r<n){
			old=dif[r];
			dif[r]+=v;
			if(old<0) ans+=up*(-old);
			else ans-=down*old;
			if(dif[r]<0) ans-=up*(-dif[r]);
			else ans+=down*dif[r];
		}
		printf("%lld\n",ans);
	}
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{    
    int n,d;
    cin >> n >> d;
    
    int ans = 0;
    int m = 0;
    while(m<n)
    {
        m += 2*d + 1;
        ans++;
    }

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

Measured memory_bytes: 256
# encoding: utf-8

N = int(input())

n_4 = int(N / 4)
n_7 = 0

ans = "No"
while n_4 > 0:
    # print(n_4, n_7)
    if 4 * n_4 + 7 * n_7 == N:
        ans = "Yes"
        break
    else:
        n_4 -= 1
        if N - (4 * n_4 + 7 * n_7) >= 7: n_7 += 1

if 7 * n_7 == N: print("Yes")
else: print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

ll fac[1] = {1}, inv[1] = {1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll mp(ll a,ll b){ll ret=1;while(b){if(b&1)ret=ret*a%MOD;a=a*a%MOD;b>>=1;}return ret;}
ll cmb(ll r, ll c) {return fac[r] * inv[c] % MOD * inv[r - c] % MOD;}

priority_queue<int, vector<int>, greater<int>> pq;
vector<int> v;

int main() {
    int n;
    n = 5;
    for (int i = 0; i < n; i++) {
        int t;
        scanf("%d", &t);
        if (t == 0) return !printf("%d",i+1);
    }
}

Measured memory_bytes: 3712
#!usr/bin/env python3
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    x = I()
    bank = 100
    count = 0
    while bank < x:
        bank *= 101
        bank //= 100
        count += 1
    print(count)
    return


# Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 67808
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define lowbit(x) (x&(-x))
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define MAX 100000000000000000
#define MOD 1000000007
#define pi acos(-1.0)
#define ei exp(1)
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f3f
#define mem(a) (memset(a,0,sizeof(a)))
typedef long long ll;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
bool cmp(int x,int y)
{
    return x>y;
}
const int N=10005;
const int mod=1e9+7;
int main()
{
    std::ios::sync_with_stdio(false);
    char a[101];
    scanf("%s",a);
    int len=strlen(a);
    if(len==1) {
        cout<<"No"<<endl;
        return 0;
    }
    sort(a,a+len);
    int t=1,flag=1;
    for(int i=1;i<len;i++){
        if(a[i]==a[i-1]) t++;
        else {
            if(t%2==1) {
                flag=0;
                break;
            }
            else t=1;
        }
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int s,k,i,j,cnt=0;
    scanf("%d %d",&k,&s);
    for(i=0;i<=k;i++)
    {
        for(j=0;j<=k;j++)
        {
            if((s-i-j<=k)&&(s-i-j)>=0)
                cnt++;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int a = sc.nextInt()-1;
        int b = sc.nextInt()-1;
        int c = sc.nextInt()-1;
        int d = sc.nextInt()-1;
        String s = sc.next();
        boolean[] sf = new boolean[n];
        for(int i=0; i<n; i++){
            sf[i] = (s.charAt(i)=='.');
        }
        
        for(int i=0; i<500_000; i++){
            if(a!=c){
                if(sf[a+1] && a+1!=b){
                    a++;
                }else if(sf[a+2] && a+2!=b){
                    a+=2;
                }else if(b!=d){
                    if(sf[b+1]){
                        b++;
                    }else if(sf[b+2]){
                        b+=2;
                    }
                }
            }else if(b!=d){
                if(sf[b+1]){
                    b++;
                }else if(sf[b+2]){
                    b+=2;
                }
            }
            //System.out.println(a + " ; " + b);
        }
        
        
        
        if(a==c && b==d){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 27440
import java.util.*;


public class Main {

    private static int x ;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] P = new int[N];
        int[] Q = new int[N];
        for (int i = 0; i < N; i++) {
            P[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            Q[i] = sc.nextInt();
        }

        List<Integer> remain = new ArrayList<>();
        for (int i = 1; i <= N; i++) {
            remain.add(i);
        }

        List<Integer> work = new ArrayList<>();
        dfs(remain, 0, work, P);
        int a = x;
        dfs(remain, 0, work, Q);
        int b = x;

        System.out.println(Math.abs(a-b));
    }

    private static int dfs(List<Integer> remain, int n, List<Integer> work, int[] X) {
        if (remain.isEmpty()) {
            boolean match = true;
            for (int i = 0; i < X.length; i++) {
                if (work.get(i) != X[i]) {
                    match = false;
                    break;
                }
            }
            if (match) {
                x = n+1;
            }
            return n+1;
        }

        int nn = n;
        for (int i = 0; i < remain.size(); i++) {

            int tmp = remain.get(i);
            work.add(tmp);
            List<Integer> remain2 = new ArrayList<>();
            for (int j = 0; j < remain.size(); j++) {
                if (j == i) continue;
                remain2.add(remain.get(j));
            }
            nn = dfs(remain2, nn, work, X);

            work.remove(work.size()-1);
        }

        return nn;
    }
}


Measured memory_bytes: 36888
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;
const int N=5e4+10;
int n,K;
char s[N];
struct _SA{
    #define For(i,a,b) for(int i=a;i<=b;i++)
    #define Rof(i,a,b) for(int i=a;i>=b;i--)
    int sa[N],rk[N],c[N],x[N],ht[N],m;
    void init(){
        m=300;
        For(i,1,m)c[i]=0;
        For(i,1,n)sa[i]=rk[i]=ht[i]=0;
    }
    void getsa(){
        For(i,1,n)++c[rk[i]=s[i]];
        For(i,1,m)c[i]+=c[i-1];Rof(i,n,1)sa[c[rk[i]]--]=i;
        for(int k=1;k<=n;k<<=1){
            int p=0;For(i,n-k+1,n)x[++p]=i;
            For(i,1,n)if(sa[i]>k)x[++p]=sa[i]-k;
            For(i,1,m)c[i]=0;For(i,1,n)++c[rk[i]];
            For(i,1,m)c[i]+=c[i-1];
            Rof(i,n,1)sa[c[rk[x[i]]]--]=x[i],x[i]=0;
            swap(rk,x);rk[sa[1]]=1,p=1;
            For(i,2,n)rk[sa[i]]=(x[sa[i]]==x[sa[i-1]]&&x[sa[i]+k]==x[sa[i-1]+k])?p:++p;
            if(p==n)break;m=p;
        }
    }
    void getht(){
        For(i,1,n)rk[sa[i]]=i;int k=0;
        For(i,1,n){
            k=k?k-1:0;int j=sa[rk[i]-1];
            while(s[i+k]==s[j+k]&&i+k<=n&&j+k<=n)k++;
            ht[rk[i]]=k;
        }
        ht[0]=0;
    }
}SA;
bool check(int len){
    int mi=SA.sa[1],mx=SA.sa[1];
    for(int i=2;i<=n;i++){
        if(SA.ht[i]<len)mi=mx=SA.sa[i];
        else{
            mi=min(mi,min(SA.sa[i-1],SA.sa[i]));
            mx=max(mx,max(SA.sa[i-1],SA.sa[i]));
            if(mx-mi>=len)return 1;
        }
    }
    return 0;
}
int main()
{
    scanf("%d",&n);
    scanf("%s",s+1);
    SA.init();SA.getsa();SA.getht();
    //for(int i=1;i<=n;i++)cout<<SA.sa[i]<<" ";cout<<endl;
    int l=1,r=n,ans=0;
    while(l<=r){
        int mid=(l+r)/2;
        if(check(mid)){
            ans=mid;l=mid+1;
        }else{
            r=mid-1;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 768
#include<stdio.h>
int main(void)
{
	int i,N,W[101];
	int sum=0;
	int S1=0;
	int S2=0;
	double ave=0.0;
	int cnt=1;
	scanf("%d",&N);
	for(i=1;i<=N;i++)
	{
		scanf("%d",&W[i]);
	}
	for(i=1;i<=N;i++)
	{
		sum=W[i]+sum;
	}
	ave=sum/2;
	i=1;
	do
	{
		S1=W[i]+S1;
		i++;
		cnt++;
	}while(S1<ave);
	if(ave-(S1-W[i-1])<=S1-ave)
	{
		S1=S1-W[i-1];
		cnt=cnt-1;
	do
	{
		S2=W[cnt]+S2;
		cnt++;
	}while(cnt<=N);
	if(S1>S2)
	printf("%d",S1-S2);
	else
	printf("%d",S2-S1);
	}
	else
	{
		do
	{
		S2=W[cnt]+S2;
		cnt++;
	}while(cnt<=N);
	if(S1>S2)
	printf("%d",S1-S2);
	else
	printf("%d",S2-S1);
	}
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;

namespace CADDi2018
{
    class D
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = new int[N];
            for (int i = 0; i < N; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            if (0 < a.Count(x => x % 2 == 1)) Console.WriteLine("first");
            else Console.WriteLine("second");
        }
    }
}


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

int main() {
  int x, y; cin >>x >>y;
  string ret = "No";
  for (int i = 0; i <= x; i++) {
    if (i*2 + (x-i)*4 == y) {ret = "Yes";}
  }
  cout << ret << endl;
  return 0;
}


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

int main(){
    vector<string>board(50);
    int h,w;
    cin>>h>>w;
    for(int i=0; i<h; i++){
        cin>>board.at(i);
    }
    const vector<int>dx={0,0,1,1,1,-1,-1,-1};
    const vector<int>dy={1,-1,0,1,-1,0,1,-1};

    for(int i=0;i<h;i++){
        for(int j=0; j<w; j++){
            int num = 0;
            if(board.at(i).at(j)=='#')continue;
            for(int k=0; k<8; k++){
                int nx = i+dx.at(k);
                int ny = j+dy.at(k);
                 
                if(nx<0 or h<=nx)continue;
                if(ny<0 or w<=ny)continue;

                if(board.at(nx).at(ny)=='#')num++;
            }
            board.at(i).at(j) = '0'+ num;
        }

    }
    for(int i=0;i<h;i++){
    cout<<board.at(i)<<endl;
    }

}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
a.sort()
m=a[-1]
del a[-1]
if n%2==0:
  for _ in range(n//2-1):
    m+=2*a.pop(-1)
  print(m)  
else:
  for _ in range((n-3)//2):
    m+=2*a.pop(-1)
  m+=a[-1]
  print(m)

Measured memory_bytes: 94144
import java.math.*;
import java.util.*;

class Main{
	static BigInteger lcm(BigInteger a,BigInteger b){
		return a.multiply(b).divide(a.gcd(b));
	}
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNext()){
			int n=sc.nextInt();
			BigInteger[] ds=new BigInteger[n];
			BigInteger[] vs=new BigInteger[n];
			for(int i=0;i<n;i++){
				ds[i]=sc.nextBigInteger();
				vs[i]=sc.nextBigInteger();
			}
			
			BigInteger den=BigInteger.ONE;
			for(int i=0;i<n;i++)
				den=lcm(den,vs[i]);
			BigInteger num=BigInteger.ONE;
			for(int i=0;i<n;i++)
				num=lcm(num,ds[i].multiply(den.divide(vs[i])));
			
			for(int i=0;i<n;i++){
				// num/ds[i]/(den/vs[i])
				BigInteger x=num.divide(ds[i]).divide(den.divide(vs[i]));
				System.out.println(x);
			}
		}
	}
}

Measured memory_bytes: 0
// ALDS1_12_B, ALDS1_12_C: SSSP, nonnegative edges (Dijkstra's)

import java.util.*;

// Given: all nodes are reachable; source is node 0
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    Map<Integer, Integer> cost = new HashMap<Integer, Integer>();
    cost.put(0, 0);

    // representing vertices as int[] with values {id, tentative cost}
    PriorityQueue<int[]> pq =
        new PriorityQueue<int[]>(
            new Comparator<int[]>() {
              public int compare(int[] v1, int[] v2) {
                return Integer.compare(v1[1], v2[1]);
              }
            });

    // populate adjacency list
    // adj[i] = list of all edges from node i
    ArrayList<ArrayList<int[]>> adj = new ArrayList<ArrayList<int[]>>();
    for (int i = 0; i < n; ++i) {
      adj.add(new ArrayList<int[]>());
      sc.nextInt(); // skip id
      int n_nbrs = sc.nextInt();
      for (int j = 0; j < n_nbrs; ++j) {
        int destination = sc.nextInt();
        int edge_cost = sc.nextInt();
        adj.get(i).add(new int[] {i, destination, edge_cost});
      }
    }

    // populate priority queue with neighbors of the source node 0
    for (int[] e : adj.get(0)) {
      pq.add(new int[] {e[1], e[2]});
    }

    while (cost.size() < n) {
      int[] v = pq.remove(); // cheapest vertex
      if (!cost.containsKey(v[0])) {
        cost.put(v[0], v[1]);
        for (int[] e : adj.get(v[0])) {
          pq.add(new int[] {e[1], v[1] + e[2]});
        }
      }
    }

    for (int i = 0; i < n; ++i) {
      System.out.printf("%d %d\n", i, cost.get(i));
    }
  }
}


Measured memory_bytes: 40996
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int n, m;
vector<int> a;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    while(n){
        int temp=n%10;
        if(temp==7){
            yes;
            return 0;
        }
        n/=10;
    }
    no;
}


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

int main()
{
    int x;
    cin >> x;
    int r;

    if (x >= 400 && 599 >= x)
    {
        r = 8;
    }
    else if (x <= 799)
    {
        r = 7;
    }
    else if (x <= 999)
    {
        r = 6;
    }
    else if (x <= 1199)
    {
        r = 5;
    }
    else if (x <= 1399)
    {
        r = 4;
    }
    else if (x <= 1599)
    {
        r = 3;
    }
    else if (x <= 1799)
    {
        r = 2;
    }
    else
    {
        r = 1;
    }

    cout << r << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
string N;
int dp[1<<20][2];
main()
{
	cin>>N;
	reverse(N.begin(),N.end());
	N+="00";
	dp[0][1]=1145141919;
	for(int i=0;i<N.size();i++)
	{
		dp[i+1][0]=dp[i+1][1]=1145141919;
		for(int j=0;j<2;j++)
		{
			for(int k=0;k<10;k++)
			{
				int nj=k+N[i]-'0'+j;
				dp[i+1][nj/10]=min(dp[i+1][nj/10],dp[i][j]+nj%10+k);
			}
		}
	}
	cout<<dp[N.size()][0]<<endl;
}


Measured memory_bytes: 9476
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::*;
use std::cmp::*;
use itertools::Itertools;
use ordered_float::*;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}



fn main() {
    input! {
    n: usize,
    k: i64,
    a: [i64;n]
    }

    let mut l = 0;
    let mut r = 10000000000;

    while  r - l > 1 {
      let x = (l+r)/2;
      if check (x, &a, n, k){
        r = x;
      }else {
        l = x;
      }
    }

    println!("{}", r);
   
}

fn check (x:i64, a:&Vec<i64>, n:usize, k:i64) -> bool {
  let mut now = 0_i64;
  for i in 0..n {
    now += (a[i] - 1) / x; 
  }
  return now <= k;
}


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

using namespace std;

int main() {
    int n, m, p, x, ans;
    cin >> n;
    int t[n];

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

    cin >> m;

    for(int i = 0; i < m; ++i) {
        ans = 0;
        cin >> p >> x;
        for(int i = 0; i < n; ++i) {
            if(i == p - 1) {
                ans += x;
            } else {
                ans += t[i];
            }
        }
        cout << ans << "\n";
    }
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,K;
    cin >>N>>K;
    ll ans=LLINF;

    vector<ll> x(N);
    rep(i,N) cin>>x[i];
    if(K==1)ans=abs(x[0]);
    rep(i,N-K+1){
        if(x[i]<0 && 0<x[i+K-1]){
            chmin(ans,-x[i]*2+x[i+K-1]);
            chmin(ans,-x[i]+x[i+K-1]*2);
        }else if(x[i]<0){
            chmin(ans,-x[i]);
        }else{
            chmin(ans,x[i+K-1]);
        }
    }
    

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

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

// iterator
#define REP(i,from, to) for(lli i=from;i<to;i++)
#define REPE(i,from, to) for(lli i=from;i<=to;i++)
#define REP_R(i,from, to) for(lli i=from;i>to;i--)
#define REPE_R(i,from, to) for(lli i=from;i>=to;i--)
#define REPIT(it,container) for(auto it = container.begin(); it != container.end(); it++)
#define REPIT_R(it,container) for(auto it = container.rbegin(); it != container.rend(); it++)

// input
#define cin1(x)             cin >> x
#define cin2(x, y)          cin >> x >> y
#define cin3(x, y, z)       cin >> x >> y >> z
#define ncin1(n, x)         REP(i, 0, n) {cin1(x[i]);}
#define ncin2(n, x, y)      REP(i, 0, n) {cin2(x[i], y[i]);}
#define ncin3(n, x, y, z)   REP(i, 0, n) {cin3(x[i], y[i], z[i]);}

// output
#define cout1(x)         cout << #x << ": " << x << endl;
#define cout2(x, y)      cout << #x << ": " << x << ", " << #y << ": " << y << endl;
#define cout3(x, y, z)   cout << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << endl;;
#define ncout1(n, x)     REP(i, 0, n) {cout << #x << "[" << i << "]: "<< x[i] << endl;}

#define coutp(p)         cout << #p << ":" <<  " (" << p.first << ", " << p.second << ")" << endl;

// sort
#define sort_r(x, y)        sort(x, y, greater<lli>()); // 降順(5,4,3,,,)

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

typedef long long int lli;
typedef pair<lli, lli> P;
typedef tuple<lli, lli, lli> tup;
typedef vector<lli> vlli;

int main() {
    lli n;
    cin1(n);
    lli c[n-1];
    lli s[n-1];
    lli f[n-1];
    ncin3(n-1,c,s,f);

    vlli x;
    REP(i,0,n-1) {
        lli cur = 0;
        REP(j,i,n-1) {
            if (cur < s[j])
                cur = s[j];
            else {
                // s[j] + f[j] * n が cur を超える最小の n
                lli rest = cur - s[j];
                if (rest % f[j] != 0)
                    cur = s[j] + ((rest/f[j]) + 1) * f[j];
            }
            cur += c[j];
        }
        x.push_back(cur);
    }
    x.push_back(0);
    REPIT(it, x) {
        cout << *it << endl;
    }
}


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

using namespace std;

int main(){
	int N; cin >> N;
	
	vector<int> p;
	for(int i = 0; i < N; i++){
		int num; cin >> num;
		p.push_back(num);
	}

	for(int i = 1; i < N; i++){
		if(p[i] < p[i - 1]){
			break;
		}
		
		if(i == N - 1){
			cout << "YES" << endl;
			return 0;
		}
	}

	for(int i = 0; i < N; i++){
		int swap1 = p[i];
		
		for(int j = 1; j < N; j++){
			vector<int> temp = p;
			int swap2 = p[j];

			temp[j] = swap1;
			temp[i] = swap2;

			for(int k = 1; k < N; k++){
				if(temp[k] < temp[k - 1]){
					break;
				}
				
				if(k == N - 1){
					cout << "YES" << endl;
					return 0;
				}
			} 	
		}
	}
	
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void alert(vector<int> vec){
  int64_t N = vec.size();
  for(int i=0; i<N-1; i++) cout << vec.at(i) << " ";
  cout << vec.at(N-1) << endl;
}
int64_t pow5(int64_t a){
  return a*a*a*a*a;
}

int main(){
  int64_t X; cin >> X;
  for(int64_t a=0; a<=119; a++){
    for(int64_t b=-64; b<=119; b++){
      if(pow5(a)-pow5(b)==X){
        cout << a << " " << b;
        return 0;
      }
    }
  }
}

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

int main() {
  int Q; cin >> Q;

  vector<bool> is_prime(1e5+1, true);
  is_prime[1] = false;

  FOR(i, 2, 1e5+1){
    if(is_prime[i]){
      for(int j = 2*i; j<= 1e5; j+= i){
        is_prime[j] = false;
      }
    }
  }

  vector<int> ans(1e5+1, 0);

  FOR(i, 3, 1e5+1){
    if(is_prime[i] && is_prime[(i+1)/2]){
      ans[i] = ans[i-1] + 1;
    }else{
      ans[i] = ans[i-1];
    }
  }

  REP(i, Q){
    int l, r; cin >> l >> r;
    cout << ans[r] - ans[l-1] << endl;
  }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int x = 0;
    int cnt = 0;
    bool flag = false;
    map<int, int> mp;
    while (!flag && !mp[a[x]])
    {
        cnt++;
        mp[x]++;
        x = a[x];
        if (x == 1)
            flag = true;
    }
    if(flag){
        cout << cnt << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 5376
s = list(input())
k = int(input())
candidate = []
for i in range(len(s)):
    for j in range(k+1):
        candidate.append(s[i:i+j])
for i in range(len(candidate)):
    candidate[i] = "".join(candidate[i])
candidate = list(set(candidate))

candidate.sort()
print(candidate[k])


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

mod = 1000000007

def pow(x, n):
    ret = 1
    while n > 0:
        if (n & 1) == 1:
            ret = (ret * x) % mod
        x = (x * x) % mod
        n //= 2
    return ret

def inv(x):
    return pow(x, mod - 2)

def cmb(n, k):
    ret = 1
    for i in range(k):
        ret = (ret * (n - i) * inv(i + 1)) % mod
    return ret

print((pow(2, n) - cmb(n, a) - cmb(n, b) - 1) % mod)


Measured memory_bytes: 72476
#ABC 070 B Two Switches

a, b, c, d = map(int, input().split())
kaishi = 0
shuryo = 0

if a <= c:
    kaishi = c
else:
    kaishi = a
    
if b <= d:
    shuryo = b
else:
    shuryo = d

if kaishi > shuryo:
    print(0)
else:
    print(shuryo - kaishi)

Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int m,d,t;
	for(;;){
		scanf("%d %d",&m,&d);
		if(m==0 && d==0){break;}
		t=4;
		t=(t+d-1)%7;
		if(m==2){t+=3;}
		else if(m==3){t+=4;}
		else if(m==5){t+=2;}
		else if(m==6){t+=5;}
		else if(m==8){t+=3;}
		else if(m==9){t+=6;}
		else if(m==10){t+=1;}
		else if(m==11){t+=4;}
		else if(m==12){t+=6;}
		t=t%7;
		if(t==0){printf("Sunday\n");}
		else if(t==1){printf("Monday\n");}
		else if(t==2){printf("Tuesday\n");}
		else if(t==3){printf("Wednesday\n");}
		else if(t==4){printf("Thursday\n");}
		else if(t==5){printf("Friday\n");}
		else if(t==6){printf("Saturday\n");}
	}
	return 0;
}

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

int main() {
  int a;
  cin>>a;
  
  if(a<1200){
    cout<<"ABC"<<endl;
  }
  else if(a<2800){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"AGC"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

#define int long long int
using namespace std;

void solve() {
  int M;
  cin >> M;
  int ans = 0;
  int sum = 0;

  while (M--) {
    int c, d; cin >> d >> c;
    ans += c;
    sum += d*c;
  }

  ans -= 1;
  ans += (sum - 1)/9;

  cout << ans << endl;
}

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


Measured memory_bytes: 3180
#include <cstdio>
#include <cstdlib>
#include <cstring>

char s[205050];

int main()
{
	scanf("%s",&s[1]);
	register int ls=strlen(&s[1]);
	register int ans=ls;
	for(register int i=2;i<=ls;i++)
		if(s[i]==s[i-1])
			ans--,i+=2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
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; }

int A, B, C, X, Y;

int main(){
  cin >> A >> B >> C >> X >> Y;
  int a = min(A, 2 * C);
  int b = min(B, 2 * C);
  int ab = min(A + B, 2 * C);
  int res = 0;
  if(X > Y){
    res += Y * ab;
    res += (X - Y) * a;
  }else{
    res += X * ab;
    res += (Y - X) * b;
  }
  cout << res << endl;
}


Measured memory_bytes: 256