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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    int n;cin >> n;
    vector<int> x(n),y(n),h(n);
    REP(i, n) { cin >> x[i] >> y[i] >>h[i];}

    queue<vector<int>> q;
    /*
    q.push({1,2,12});
    q.push({5,6,7});
    vector<int> qqq = q.front();
    q.pop();
    REP(i,3){
        cout << qqq[i] <<"\n";
    }
    */

    int C=101;
    REP(cx,C){
        REP(cy,C){
            int preH =0,nowH=0;
            REP(i,n){
                
                if(h[i]!=0){
                    nowH = h[i] + abs(x[i] - cx) + abs(y[i] - cy); //高さの候補
                    //if(nowH>100)break;
                    //cout << cx << " " << cy <<"z"<< preH << " " << nowH << "\n";
                    //cout << nowH << "\n";
                    if (preH!=0&&nowH != preH)
                    {
                        break;
                    }
                    preH = nowH;
                }
                if(i==n-1){
                    q.push({cx, cy, nowH});
                    //cout << cx << " " << cy << " " << nowH<< "\n";return 0;
                }
            }
        }
    }

    while(!q.empty()){
        vector<int> qq = q.front();
        q.pop();
        int X = qq[0], Y = qq[1], H = qq[2];
        REP(i,n){
            if(h[i]==0){
                if (max(H - abs(x[i] - X) - abs(y[i] - Y), 0)!=0){
                    break;
                }
            }
            if(i==n-1){
                cout << X << " " << Y << " " << H << "\n";
                return 0;
            }
        }
    }
    //h = max(H - abs(x - cx) - abs(y - cy), 0);

    return 0;
}

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;

int main() {
    string N;
    cin>>N;
    bool used[26]={false};
    for (int i = 0; i < 26; ++i) {
        used[N[i]-'a']=true;
    }

    if(N.length()<26){
        for(int i=0;i<26;i++){
            if(!used[i]){
                cout<<N+(char)(i+'a')<<endl;
                return 0;
            }
        }
    }

    if(N=="zyxwvutsrqponmlkjihgfedcba"){
        cout<<-1<<endl;
        return 0;
    }

    used[N[25]-'a']=false;
    N.pop_back();
    for(int i=24;i>=0;i--){
        int now=(int)(N[i]-'a');
        used[now]= false;
        N.pop_back();
        for(int j=now+1;j<26;j++){
            if(!used[j]){
                N.push_back((char)(j+'a'));
                cout<<N<<endl;
                return 0;
            }
        }

    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <memory>        // unique_ptr, shared_ptr, weak_ptr

using namespace std;

using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;

#define _LIBCPP_DEBUG 0
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

const int INF = 1<<30;
const ll MOD = 1000000007;

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

  vector<int> v;
  for (size_t i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }

  reverse(v.begin(), v.end());
  for (size_t i = 0; i < n; i++) {
    cout << v.at(i);
    if (i != n-1) cout << " ";
  }
  cout << endl;

  return 0;		 
}


Measured memory_bytes: 3080
nk = input().split()
n = int(nk[0])
k = int(nk[1])
p_s = input().split()
p = [int(s) for s in p_s]
max_val = 0
for i in range(0,k):
    max_val+=p[i]
tmp = max_val
for i in range(k,len(p)):
    tmp = tmp - p[i-k] + p[i]
    if tmp > max_val:
        max_val=tmp
print(max_val/2 + 0.5 * k)

Measured memory_bytes: 32156
#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;

class Edge
{
public:
	int src,dst,cst;
	Edge(int src, int dst, int cst)
		:src(src),dst(dst),cst(cst)
	{}
};

class State
{
public:
	int g, b, c, v;
	State(int g, int b, int c, int v)
		:g(g),b(b),c(c),v(v)
	{}

	bool operator<(const State& s) const
	{
		return c > s.c;
	}

};

typedef vector<vector<Edge> > Graph;

bool vis[50][50][1<<10], same[50];
int d[50], E[50], id[50], N, M;

int solve(Graph& graph, Graph& revgraph)
{
	memset(vis, 0, sizeof(vis));
	priority_queue<State> q;
	q.push(State(0,0,0,0));

	while(!q.empty()) {
		State s = q.top(); q.pop();
		if(s.g == N-1 && s.b == N-1) return s.c;
		if(vis[s.g][s.b][s.v]) continue;
		vis[s.g][s.b][s.v] = 1;

		if(E[s.g] <= E[s.b]) {
			for(int i=0; i<graph[s.g].size(); i++) {
				Edge& e = graph[s.g][i];
				if(E[e.dst] < E[s.g]) continue;

				int nv = s.v;
				int nc = s.c + e.cst;
				int h = max(E[s.g], max(E[s.b], E[e.dst]));
				if(max(E[s.g], E[s.b]) < E[e.dst]) nv = 0;

				if(same[e.dst] && h == E[e.dst]) {
					if(!((nv >> id[e.dst]) & 1)) nc += d[e.dst];
					nv |= (1 << id[e.dst]);

					if(vis[e.dst][s.b][nv]) continue;
					q.push(State(e.dst, s.b, nc, nv));
				}
				else
				{
					if(e.dst != s.b) nc += d[e.dst]; 
					if(vis[e.dst][s.b][nv]) continue;

					q.push(State(e.dst, s.b, nc, nv));
				}
			}
		}

		if(E[s.b] <= E[s.g]) {
			for(int i=0; i<revgraph[s.b].size(); i++) {
				Edge& e = revgraph[s.b][i];
				if(E[e.dst] < E[s.b]) continue;

				int nv = s.v;
				int nc = s.c + e.cst;
				int h = max(E[s.g], max(E[s.b], E[e.dst]));
				if(max(E[s.g], E[s.b]) < E[e.dst]) nv = 0;

				if(same[e.dst] && h == E[e.dst]) {
					if(!((nv >> id[e.dst]) & 1)) nc += d[e.dst];
					 nv |= (1 << id[e.dst]);

					if(vis[s.g][e.dst][nv]) continue;
					q.push(State(s.g, e.dst, nc, nv));
				}
				else
				{
					if(e.dst != s.g) nc += d[e.dst]; 
					if(vis[s.g][e.dst][nv]) continue;

					q.push(State(s.g, e.dst, nc, nv));
				}
			}
		}
	}

	return -1;
}

int main()
{
	while(cin >> N >> M, N||M) {
		E[0] = 0;
		E[N - 1] = 1000;
		d[0] = d[N - 1] = 0;

		for(int i=1; i<N-1; i++)
			cin >> d[i] >> E[i];

		Graph g(N), rg(N);
		for(int i=0; i<M; i++) {
			int a,b,c;
			cin >> a >> b >> c;
			a--; b--;

			g[a].push_back(Edge(a,b,c));
			rg[b].push_back(Edge(b,a,c));
		}

		int cnt = 0;
		memset(same, 0, sizeof(same));
		for(int i=0; i<N-1; i++) {
			if(E[i] == E[i + 1]) {
				if(!same[i]) cnt = 0;

				same[i] = same[i + 1] = true;
				id[i] = cnt;
				id[i + 1] = ++cnt;
			}
		}

		cout << solve(g, rg) << endl;

	}
}

Measured memory_bytes: 63000
#include <stdio.h>

int main(){

  int i,j,m,n,n2,G[1000][1000];

  scanf("%d",&n);

  for(i=0;i<=n;i++){
    for(j=0;j<=n;j++){
      G[i][j] = 0;
    }
  }

  for(i=1;i<=n;i++){
    scanf("%d %d",&G[i][0],&m);
    for(j=1;j<=m;j++){
      scanf("%d",&n2);
      G[i][n2] = 1;
    }
  }

   
  for(i=1;i<=n;i++){
    for(j=1;j<n;j++){
      printf("%d ",G[i][j]);
    }
    printf("%d\n",G[i][n]);
  }

  return 0;
}

Measured memory_bytes: 992
# -*- coding: utf-8 -*-
import sys
import math


def main():
    N,K = list(map(int, sys.stdin.readline().split()))
    A_list = list(map(int, sys.stdin.readline().split()))


    def check(length :int) -> bool:
        cnt = 0

        for a in A_list:
            if a >= length:
                quotient = a / length
                #divide = -(-quotient // 1)  # round up
                divide = math.ceil(quotient)  # round up
                cnt += (divide - 1)
        
        return (True if cnt <= K else False)


    L = 0            # the minimum length
    R = max(A_list)  # the maximum length

    while (R - L) > 1:
        M = L + (R - L) // 2

        if check(M):
            R = M
        else:
            L = M


    print(R)


if __name__ == "__main__":
    main()


Measured memory_bytes: 31924
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
const int mod=1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H,W,h,w;cin >> H >> W >> h >> w;
	cout << H*W-h*W-w*H+h*w << endl;
}

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


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

  int n;
  cin >> n;
  ll ans=0;
  int a[n];
  int b[n],c[n-1];
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    cin >> b[i];
    ans+=b[i];
  }
  rep(i,n-1){
    cin >> c[i];
  }
  //  cout << ans << endl;
  rep(i,n-1){
    if(a[i+1]==a[i]+1) ans+=c[a[i]-1];
  }
  cout << ans << endl;
  
  return 0;
    

}


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

#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using int64 = uint64_t;
using namespace std;

int digits(int64 n) {
    int cnt = 0;
    while (n > 0) {
        n /= 10;
        cnt++;
    }
    return cnt;
}

int main() {
    fastIO;

    int64 n;
    cin >> n;

    // left, right
    int64 digit = 100;
    for (int64 l = 1; l * l <= n; l++) {
        if (n % l == 0) {
            int64 r = n / l;
            int64 max_digit = max(digits(l), digits(r));
            digit = min(digit, max_digit);
        }
    }
    cout << digit << endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;
void solve()
{
	int a, b, k;
	cin>>a>>b>>k;
	
	for(int i=a; i<=b; i++)
	{
		if(i<a+k || i>b-k)
			cout<<i<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3544
/**
* Think twice, code once.
* 1.integer overflow(maybe even long long overflow : (a+b >= c) -> (a >= c-b)
* 2.runtime error
* 3.boundary condition
* ---------------------------------------------------------------------------------------
* Author : zzy
* Date : 2020-03-19-18.25.37 Thursday
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const i64 maxn = (i64)1e5+1000;
i64 N, W, w[maxn], v[maxn], dp[maxn];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> N >> W;
    for1(i, N) cin >> w[i] >> v[i];
    ms(dp, 0);
    for (int i = 1; i <= N; ++i) {
        for (int j = W; j >= w[i]; --j) {
            dp[j] = max(dp[j], dp[j-w[i]]+v[i]);
        }
    }
    cout << dp[W] << '\n';

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
const ll inf = 1e9;
int main(){
    int n; cin >> n;
    vector<ll> a(n);
    rep(i,n)cin >> a[i];
    int m;
    cin >> m;
    vector<ll> b(m);
    rep(i,m)cin >> b[i];
    
    bool a_second, same = true;
    rep(i,min(n,m)){
        if(a[i] != b[i]){
            same = false;
            if(a[i] > b[i])a_second = true;
            else a_second = false;
            break;
        }
    }
    if(same){
        cout << ((n < m)?1:0) << endl;
        //cout << "same" << endl;
    }
    else cout << ((a_second)?0:1) << endl;
    return 0;
} 


Measured memory_bytes: 3100
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>


int a[10000000] = {};

using namespace std;
int main() {

	int n;
	long long int ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int r;
		cin >> r;
		if(r<=n)a[r]++;
		else {
			ans++;
		}
	}
	for (int i = 0; i <= n; i++) {
		if (a[i] != i&&a[i]) {
			if(a[i]>i)ans += abs(i-a[i]);
			else ans += a[i];
		}
	//	cout << ans;
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

typedef long double LD;
#define N 300000

int n,mx,tp,stk[N];
LD a[N],b[N],c[N],f[N],p[N],ans;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;++i){
		scanf("%Lf",a+i);
		if (a[i]>a[mx]) mx=i;
	}
	for (int i=1;i<=n;++i){
		scanf("%Lf",b+i);
	}
	rotate(a+1,a+mx,a+n+1);
	rotate(b+1,b+mx,b+n+1);
	a[n+1]=a[1]; b[n+1]=b[1];
	c[1]=c[2]=0;
	for (int i=2;i<=n;++i){
		c[i+1]=c[i]*2-b[i]*2-c[i-1];
	}
	for (int i=1;i<=n+1;++i){
		p[i]=a[i]+c[i];
		for (;tp>1&&(p[i]-p[stk[tp]])/(i-stk[tp])>(p[stk[tp]]-p[stk[tp-1]])/(stk[tp]-stk[tp-1]);--tp);
		stk[++tp]=i;
	}
	for (int i=1;i<tp;++i){
		int l=stk[i],r=stk[i+1],len=r-l;
		for (int j=l;j<=r;++j){
			f[j]=p[l]*(r-j)/len+p[r]*(j-l)/len;
			f[j]-=c[j];
		}
	}
	for (int i=1;i<=n;++i) ans+=f[i];
	printf("%.12Lf\n",ans/n);
	
	return 0;
}
			

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


int main(){
    int n,m;
    cin >> n >> m;
    int ans = n;
    int sum = 0;
    rep(i,m){
        int a;
        cin >> a;
        sum += a;
    }
    if(sum > n) printf("-1\n");
    else printf("%d\n",ans-sum);
    return 0;
}

Measured memory_bytes: 3764
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] X = new long[N];
        long[] sortedX = new long[N];

        for (int i = 0; i < N; i++) {
            X[i] = sc.nextInt();
            sortedX[i] = X[i];
        }

        Arrays.sort(sortedX);
        long medianSmaller = sortedX[N / 2];
        long medianBigger = sortedX[N / 2 - 1];

        for (int i = 0; i < N; i++) {
            if (medianSmaller > X[i]) {
                out.println(medianSmaller);
            } else {
                out.println(medianBigger);
            }
        }
    }
}

Measured memory_bytes: 93624
N=int(input())
A=[int(i) for i in input().split(" ")]
mod=10**9+7

def GCD(a,b):
    if min(a,b)==0:
        return max(a,b)
    else:
        return GCD(min(a,b),max(a,b)%min(a,b))

def LCM(a,b):
    return int(a*b//GCD(a,b))





lcm=1
for a in A:
    lcm=LCM(lcm,a)


retval=0
for a in A:
    retval+=lcm//a

print(int(retval%mod))


Measured memory_bytes: 4084
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;

//0-indexed!
class strong_components{
private:
    vector<vector<int>> v,rv,nv;
    vector<int> rs,visited,cmp,cmp_size;
    void dfs(int n){
        visited[n] = 1;
        for(auto x:v[n]) if(!visited[x]) dfs(x);
        rs.push_back(n);
    }
    void rdfs(int n,int cnt){
        visited[n] = 1;
        cmp[n] = cnt;
        for(auto x:rv[n]) if(!visited[x]) rdfs(x,cnt);
    }
public:
    strong_components(int N,vector<vector<int>>& graph){
        v = graph;
        rv = vector<vector<int>>(N);
        visited = cmp = cmp_size = vector<int>(N,0);
        for(int i=0;i<N;i++) for(auto x:v[i]) rv[x].push_back(i);
        for(int i=0;i<N;i++) if(!visited[i]) dfs(i);
        for(int i=0;i<N;i++) visited[i] = 0;
        int now = 0;
        for(int i=rs.size()-1;i>=0;i--) if(!visited[rs[i]]) rdfs(rs[i],now++);
        nv = vector<vector<int>>(now+1);
        for(int i=0;i<N;i++){
            for(auto x:v[i]){
                if(cmp[i]!=cmp[x]){
                    nv[cmp[i]].push_back(cmp[x]);
                    cmp_size[cmp[x]]++;
                }
            }
        }
    }
    int find(int n){return cmp[n];}
    bool is_same_group(int a,int b){return cmp[a]==cmp[b];}
};

int N,M,s,t,Q;
int main(){
    cin >> N >> M;
    vector<vector<int>> v(N+1);
    for(int i=0;i<M;i++){
        cin >> s >> t;
        v[s].push_back(t);
    }
    strong_components scc(N,v);
    cin >> Q;
    for(int i=0;i<Q;i++){
        cin >> s >> t;
        cout << (scc.is_same_group(s,t)? 1:0) << endl;
    }
}


Measured memory_bytes: 5104
m1, m2, n1, n2 = map(int, input().split())
n = n1-m1
m = n2-m2
ans = ""
go = "U"*m+"R"*n
back = "D"*m+"L"*n
a1 = "LU"
a2 = "RDRD"
a3 = "LU"
print(go+back+a1+go+a2+back+a3)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
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 <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}

const int N = 55;
typedef long long LL;

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	for(int i = 0; i < 3; i ++)
		if(a[i] % 2 == 0) return puts("0") * 0;
	
	printf("%lld\n", (LL) a[0] * (LL) a[1]);
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int ac=0,wa=0,tle=0,re=0,in;
	char input[10];
	scanf("%d", &in);
	for (int i=0; i<in;i++)
	{
		
	
	scanf("%s", input);
	
		if (input[0]=='A'){
			ac++;
		}
		else if (input[0]=='W'){
			wa++;
		}
		else if (input[0]=='T'){
			tle++;
		}
		else if (input[0]=='R'){
			re++;
		}
	}
	printf("AC x %d \n", ac);
	printf("WA x %d \n", wa);
	printf("TLE x %d \n", tle);
	printf("RE x %d \n", re);	
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 1728
def min_cost(nums, n):
    sorted_list = sorted(nums)
    global_min = sorted_list[0]
    check_list = [False] * n
    cost = 0
    for start_idx in range(n):
        if check_list[start_idx]:
            pass
        else:
            start_num = nums[start_idx]
            cycle_idx = start_idx
            cycle_count = 0
            min_num = start_num
            w_sum = 0
            while True:
                check_list[cycle_idx] = True
                cycle_num = nums[cycle_idx]
                w_sum += cycle_num
                next_idx = sorted_list.index(cycle_num)
                min_num = min(min_num, cycle_num)
                if next_idx == start_idx:
                    break
                cycle_idx = next_idx
                cycle_count += 1
            if cycle_count >= 1:
                cost1 = w_sum + (cycle_count - 1) * min_num
                cost2 = w_sum + min_num + (cycle_count + 2) * global_min
                cost += min(cost1, cost2)
    return cost


def main():
    n = int(input())
    nums = list(map(int, input().split(" ")))
    cost = min_cost(nums, n)
    print(cost)


if __name__ == "__main__":
    main()



Measured memory_bytes: 5632
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    cout << 180 * (n - 2) << endl;
    return 0;
}

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

using namespace std;

int n, x, y;
int a[2010];
int dp[2010][2010][2];

int go(int pos, int last, int player) {
	int ret=abs(a[last]-a[n-1]);
	if (pos==n-1) {
		return ret;
	}
	if (dp[pos][last][player]>=0) return dp[pos][last][player];
	if (player==0) {
		for (int i=pos;i<n-1;i++)
			ret=max(ret, go(i+1, i, 1));
	} else {
		for (int i=pos;i<n-1;i++)
			ret=min(ret, go(i+1, i, 0));
	}
	//cout<<pos<<" "<<last<<" "<<player<<" = "<<ret<<endl;
	return dp[pos][last][player]=ret;
}

int main() {
	cin>>n>>x>>y;
	a[0]=x;
	a[1]=y;
	for (int i=0;i<n;i++) cin>>a[i+2];
	memset(dp,-1,sizeof(dp));
	n+=2;
	cout<<go(2, 1, 0)<<endl;
}


Measured memory_bytes: 31872
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll n, k;
    cin >> n >> k;
    map<ll, ll> m;
    for (ll i = 0; i < n; i++)
    {
        ll a, b;
        cin >> a >> b;
        m[a] += b;
    }
    ll temp = 0;
    for (auto p : m)
    {
        temp += p.second;
        if (temp >= k)
        {
            cout << p.first << endl;
            break;
        }
    }
}

Measured memory_bytes: 4224
#include<iostream>
#include<stdio.h>
#include<string>
#include<cstring>
using namespace std;

int main()
{
  string s, p;
  cin>>s>>p;

  string s2=s+s;
  if(s2.find(p)==-1)
    //findの返り値はbasic_string::npos　　static const size_type npos = -1;
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;

  return 0;
}                 



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

long long INF = 1'000'000'000'000'000;

int main(){
    long long n, m, l;
    cin >> n >> m >> l;
    vector<vector<long long>> d(n, vector<long long>(n, INF));
    long long a, b, c;
    for (int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--; b--;
        d[a][b] = min(d[a][b], c);
        d[b][a] = min(d[b][a], c);
    }
    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
    vector<vector<long long>> ans(n, vector<long long>(n, INF));
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++) if (d[i][j] <= l) ans[i][j] = 1;
    }
    long long x, y;
    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            for (int j = 0; j < n; j++){
                ans[i][j] = min(ans[i][j], ans[i][k] + ans[k][j]);
            }
        }
    }
    int q;
    cin >> q;
    int s, t;
    for (int i = 0; i < q; i++){
        cin >> s >> t;
        s--; t--;
        if (ans[s][t] == INF) cout << - 1 << endl;
        else cout << ans[s][t] - 1 << endl;
    }
}

Measured memory_bytes: 1920
#include<cstdio>
#include<vector>
using namespace std;
 
int n, m, a[200000], b[200000];
char s[200001];
 
vector<int> e[200000];
int ok[200000]; // 0:init 1:ok -1:no
 
bool dfs(int x, int before, int counter) { //before 3:init 1:AA or BB 2:else
  if (ok[x] == -1) return false;
  if (ok[x] == 1 && counter >= 2*n) return true;
  counter++;
  ok[x] = 1;
  for (int i = 0; i < e[x].size(); i++) {
    if (before & 1) {
      if (s[e[x][i]] != s[x]) if (dfs(e[x][i], 2, counter)) return true;;
    }
    if (before & 2) {
      if (s[e[x][i]] == s[x]) if (dfs(e[x][i], 1, counter)) return true;;
    }
  }
  ok[x] = -1;
  return false;
}
 
 
int main() {
  scanf("%d%d%s", &n, &m, s);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i], &b[i]);
    a[i]--; b[i]--;
    e[a[i]].push_back(b[i]);
    e[b[i]].push_back(a[i]);
  }
  for (int i = 0; i < n; i++) ok[i] = 0;
  bool flag = false;
  for (int i = 0; i < n; i++) {
    if (dfs(i, 3, 0)) {
      flag = true;
      break;
    }
  }
  if (flag) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 42368
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

s = 0
pre_food = A[0]
for food in A:
    s += B[food-1]
    if food - pre_food == 1 : s += C[food-2]
    pre_food = food

print(s)

Measured memory_bytes: 38384
/*
author : seryu
title : AGC021A_"Digit Sum2"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	string s;
	cin >> s;
	int n = sz(s);
	if(n == 1)
	{
		cout << s[0] << endl;
		return;
	}
	int last = -1;
	rep(i, n)
	{
		if(s[i] != '9')
		{
			chmax(last, i);
			break;
		}
	}

	if(last < 0)
	{
		cout << n*9 << endl;
	}
	else if(last > 0)
	{
		cout << n*9-1 << endl;
	}
	else
	{
		bool flag = false;
		reps(i,n-1)if(s[i] != '9')flag = true;
		int ans = flag ? int(s[0]-'0')-1+(n-1)*9:int(s[0]-'0')+(n-1)*9;
		cout << ans << endl;
	}
	
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

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

    vector<int> L(2 * N);
    for (int n = 0; n < 2 * N; n++) cin >> L[n];
    sort(L.begin(), L.end());

    int res = 0;
    for (int n = 0; n < N; n++) res += L[2 * n];

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    bn = 10**16
    for i in range(5):
        bn = min(bn, int(input()))
    if bn == 1:
        print(n // bn + 4)
    else:
        print(n // bn + 5)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#define MAX 250

int A[MAX],H;

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
int main(){
  int i;

  scanf("%d",&H);
  for(i=1;i<=H;i++) scanf("%d",&A[i]);

  for(i=1;i<=H;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=H) printf("left key = %d, ",A[left(i)]);
    if(right(i)<=H) printf("right key = %d, ",A[right(i)]);

    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2048
//   PIGMEISTER™   //

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define sidha(i,x,n) for(ll i=(ll)(x);i<(ll)(n);++i)
#define ulta(i,x,n) for(ll i=(ll)(x);i>=(ll)(n);--i)
#define sab(a) a.begin(),a.end()
#define bas(a) a.rbegin(),a.rend()
#define modinv(x) powah(x,mod-2)
#define ncr(n,r) (((fact[n]*modinv(fact[n-r]))%mod*modinv(fact[r]))%mod)
#define factorial fact.pb(1);sidha(i,1,MAX)fact.pb((fact[i-1]*i)%mod)
#define test ll _;cin>>_;while(_--)
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod (ll)1000000007
//#define mod (ll)998244353
#define MAX 100005

int main()
{
    jaldi;
    
    double r;
    cin >> r;
    double pi = 3.1415926535;
    cout << fixed << setprecision(10) << (double)2*pi*r;
    
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
#define ll long long
ll la, lb, lc, ld, le, lf, lg;
ll answer = 0;
ll fl(ll x, ll d){
	x = x - (x%d);
	x /= d;
	return x;
}

int main(){
	scanf("%lld%lld%lld%lld%lld%lld%lld", &la, &lb, &lc, &ld, &le, &lf, &lg);
	if (la > 0 && ld > 0 && le > 0){
		answer = max(answer, (ll)6 + fl(la - 1, 2)*4 + fl(ld - 1, 2)*4 + fl(le - 1, 2)*4 + lb*2);
	}
	answer = max(answer, fl(la, 2)*4 + fl(ld, 2)*4 + fl(le, 2)*4 + lb*2);
	printf("%lld\n", answer/2);
}

Measured memory_bytes: 384
import sys
from collections import Counter

read = sys.stdin.read


# 最小素因数を求める（エラトステネスの篩の亜種？）
def min_factor(n):
    sieve = list(range(n + 1))
    sieve[2::2] = [2] * (n // 2)

    # エラトステネスのふるい
    def sieve_of_eratosthenes(n):
        sieve = [True] * n
        for i in range(3, int(n ** 0.5) + 1, 2):
            if sieve[i]:
                sieve[i * i::2 * i] = [False] * ((n - i * i - 1) // (2 * i) + 1)
        return [i for i in range(3, n, 2) if sieve[i]]

    for i in sieve_of_eratosthenes(int(n ** 0.5) + 2):
        if sieve[i] == i:
            sieve[i * i::2 * i] = [i] * ((n - i * i - 1) // (2 * i) + 1)
    return sieve


# 素因数分解
def prime_factorize(n):
    a = [1]
    while n != 1:
        b = table[n]
        a.append(b)
        n //= b
    return a


N, *A = map(int, read().split())
mod = 10 ** 9 + 7

table = min_factor(10 ** 6)
dic = {}

for i in A:
    for key, value in Counter(prime_factorize(i)).items():
        # print(key, value)
        if dic.get(key):
            if dic[key] < value:
                dic[key] = value
        else:
            dic[key] = value

lcm = 1
for i, j in dic.items():
    lcm *= pow(i, j, mod)
    lcm %= mod

answer = sum(lcm * pow(i, mod - 2, mod) for i in A) % mod
print(answer)


Measured memory_bytes: 51948
n, d = input().split()
a = []
#print(a)
pair = 0
for i in range(int(n)):
    a.append(input().split())
#print('\n', a, '\n')
for i in range(int(n)):
    for j in range(i+1, int(n)):
        t = 0
        for k in range(int(d)):
           # print(int(a[i][k]) , int(a[j][k]))
            t+=(int(a[i][k]) - int(a[j][k])) * (int(a[i][k]) - int(a[j][k]))

        t**=0.5
        if t == int(t):
            pair += 1
print(pair)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int X,t;
	cin>>X>>t;
	ote(max(0, X-t));
}


Measured memory_bytes: 256
N = int(input())

s = []
for a in range(N + 1):
    s.append(sum([int(ch) for ch in str(a)]))

ans = 100000
for a in range(1, N//2 + 1):
    b = N - a
    ans = min(ans, s[a] + s[b])

print(ans)


Measured memory_bytes: 3864
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DPredictionAndRestriction {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        int n, k, r, s, p;
        cin >> n >> k >> r >> s >> p;
        string t;
        cin >> t;

        int score[3] = {r, s, p};
        map<char, int> m = {
                {'r', 0},
                {'s', 1},
                {'p', 2},
        };

        vector<vector<int>> dp(n, vector<int>(3));
        REP(i, n) {
            char c = t[i];
            int to = (m[c] + 2) % 3;
            if (i < k) {
                dp[i][to] += score[to];
            } else {
                REP(j, 3) {
                    int o1 = (j + 1) % 3;
                    int o2 = (j + 2) % 3;
                    dp[i][j] = max(dp[i - k][o1], dp[i - k][o2]);
                    if (j == to) {
                        dp[i][j] += score[j];
                    }
                }
            }
        }

        int res = 0;
        REV(i, n - 1, max(0LL, n - k)) {
            res += max({dp[i][0], dp[i][1], dp[i][2]});
        }
        cout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DPredictionAndRestriction solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 5840
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <random>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

void solve() {
    int x;
    cin >> x;
    x /= 200;
    cout << 10 - x << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 1e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,val;}ee[M*2];
void add(int x,int y){ee[++cnt].nxt=head[x],ee[cnt].to=y,head[x]=cnt;}
*/

char s[110],t[110];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	cin>>s>>t;
  	int n=strlen(s);
  	bool f=true;
  	for(int i=0;i<n;i++)
  	if(s[i]!=t[i])f=false;
  	if(f)cout<<"Yes"<<endl;
  	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<fstream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<cctype>
#include<cassert>
#include<cmath>
#include<ctime>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<iomanip>
#include<utility>

using namespace std;

#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define rg register
#define il inline
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define rep0(i,n) for(register int i=0;i<(n);++i)
#define rep(i,st,ed) for(register int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(register int i=(ed);i>=(st);--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<typename T> inline T qmin(const T a,const T b) {return a<b?a:b;}
template<typename T> inline T qmax(const T a,const T b) {return a>b?a:b;}
template<typename T> inline void getmin(T &a,const T b) {if(a>b) a=b;}
template<typename T> inline void getmax(T &a,const T b) {if(a<b) a=b;}

inline void fileio(string s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e17+7;

int a,b,x,y;
int ans;

int main(){
	scanf("%d%d",&a,&b);
	x=abs(a),y=abs(b);
	if(x>y){
		ans=x-y;
		if(a>0) a=-a+ans,++ans;
		else a+=ans;
	}else if(x<y){
		ans=y-x;
		if(a<0) a=-a+ans,++ans;
		else a+=ans;
	}
	if(a!=b) ++ans;
	printf("%d\n",ans);
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define Cout(s) cout << s << endl;
#define CoutV(vec)        \
    for (auto v : vec)    \
    {                     \
        cout << v << " "; \
    }                     \
    cout << endl;
#define CoutVV(vecvec)      \
    for (auto vec : vecvec) \
        CoutV(vec);

using ll = long long;
using P = pair<int, int>;
#define INF 10000000;

ll MOD = 1e9 + 7;

ll gcd(ll x, ll y) { return (y != 0) ? gcd(y, x % y) : x; }

int main()
{


    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    vector<ll> s(n - k + 1);

    s[0] = 0;

    REP(i, n)
    {
        cin >> x[i];
    }

    ll d = 1 << 30;
    for (int i = 0; i < n - k + 1; i++)
    {
        ll left = x[i];
        ll right = x[i + k - 1];

        d = min(d, min(abs(right - left) + abs(left), abs(right - left) + abs(right)));
    }

    Cout(d);

    return 0;
}


Measured memory_bytes: 1408
#include <stdio.h>
int main() {
	char s[3];
	char t[3];
	int cnt;
	cnt = 0;

	scanf("%s", s);
	scanf("%s", t);

	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			cnt++;
		}
	}
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
// SeeAlso: https://atcoder.jp/contests/abc143/tasks/abc143_c

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define MAX 100000
#define NIL -1
#define MOD 1000000007

typedef int _loop_int;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define debug(x) cout<<#x<<": "<<x<<endl
#define debig_vec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) rep(i, h) { rep(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

const long double PI = acos(-1);

int main() {

    ll N;
    cin >> N;
    ll counter = 0;
    char temp;
    rep(i, N) {
        char a;
        cin >> a;
        if(i>0) {
            if(temp!=a) {
                counter++;
            }
        } else {
            counter++;
        }
        temp = a;
    }

    print(counter);
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define Rint register int
#define mem(a,b) memset(a,(b),sizeof(a))
using namespace std;
typedef long long LL;
template<typename T>inline void read(T &x){
	x=0;T w=1,ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^'0'),ch=getchar();
	x=x*w;
}
inline void File(){
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
}

const int maxn=100+10;
int n=1,m=1;
int A,B;
int G[maxn][maxn];

int main(){
	//File();
	read(A);read(B);A--;B--;
	for(Rint i=1;i<=50;i++)
		for(Rint j=1;j<=100;j++)
			G[i][j]=1;
	for(Rint i=51;i<=100;i++)
		for(Rint j=1;j<=100;j++)
			G[i][j]=0;
	int x=1,y=1;
	while(A--){
		G[x][y]=0;
		y+=2;
		if(y>100)x+=2,y=1;
	}
	x=100,y=1;
	while(B--){
		G[x][y]=1;
		y+=2;
		if(y>100)x-=2,y=1;
	}
	printf("100 100\n");
	for(Rint i=1;i<=100;i++){
		for(Rint j=1;j<=100;j++){
			printf("%c",G[i][j]==1?'#':'.');
		}
		putchar('\n');
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    string a; cin >> a;
    int cnt =0;
    for(int i = 0; i < a.length(); ++i){
        if(cnt == 0 && a[i] == 'C') cnt++;
        else if(cnt == 1 && a[i] == 'F') cnt++;
    }
    cout << (cnt == 2 ?"Yes" : "No") << endl;
}

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

int main(void) {
    uint64_t a,b,x;
    uint64_t cnt = 0;
    cin >> a >> b >> x;

    if((a % x) == 0) {
        cnt++;
    }
    
    cnt += ((b/x) - (a/x));

    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import itertools as it


def main():
    N, M, X = map(int, input().split())

    book = []

    for n in range(N):
        book.append(list(map(int, input().split())))
    
    ok = False

    mini = 10**15
    for n in range(1, N+1):
        for v in it.combinations([x for x in range(1, N+1)], n):

            us = [0]*(M+1)
            flag = True
            for i in list(v):
                for j in range(1, M+1):
                    us[j] += book[i-1][j]
            for i in us[1:]:
                if i < X:
                    flag = False
                    break

            if flag:
                ok = True
                temp = 0
                for i in v:
                    temp += book[i-1][0]
                if mini > temp:
                    mini = temp
    
    if ok:
        print(mini)
    else:
        print(-1)
                    


if __name__ == '__main__':
    main()

Measured memory_bytes: 68776
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[] xl = sc.nextIntArray(n);
        int[] yl = sc.nextIntArray(m);
        for(int i = x+1; i <= y; i++){
            boolean flg = true;
            for(int ax : xl){
                if(ax >= i){
                    flg = false;
                }
            }
            for(int ay : yl){
                if(ay < i){
                    flg = false;
                }
            }
            if(flg){
                pw.println("No War");
                pw.flush();
                return;
            }
        }
        pw.println("War");
        pw.flush();
    }

    static class GeekInteger {
        public static void save_sort(int[] array) {
            shuffle(array);
            Arrays.sort(array);
        }
 
        public static int[] shuffle(int[] array) {
            int n = array.length;
            Random random = new Random();
            for (int i = 0, j; i < n; i++) {
                j = i + random.nextInt(n - i);
                int randomElement = array[j];
                array[j] = array[i];
                array[i] = randomElement;
            }
            return array;
        }
 
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 25336