akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C solver = new C();
        solver.solve(1, in, out);
        out.close();
    }

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = Integer.parseInt(in.next());
            // 整数の入力
            int[] x = new int[N];
            int[] y = new int[N];
            for (int i = 0; i < N; i++) {
                x[i] = Integer.parseInt(in.next());
                y[i] = Integer.parseInt(in.next());
            }
            double ans = 0;

            int X = 2 * factorial(N - 1);

            for (int i = 0; i < N - 1; i++) {
                for (int j = i + 1; j < N; j++) {
                    int xdist = x[i] - x[j];
                    int ydist = y[i] - y[j];
                    double dist = Math.sqrt(xdist * xdist + ydist * ydist);
                    ans += dist * X;

                }
            }
            // 出力
            out.println(ans / factorial(N));

        }

        static int factorial(int n) {
            if (n == 1) {
                return 1;
            }
            return n * factorial(n - 1);
        }

    }
}



Measured memory_bytes: 22612
#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 <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------

int N,M;
vector<vector<int>> G;
vector<bool> used;
vector<int> suzu;
vector<int> A;

void dfs(int v){
    used[v] = true;
    suzu.emplace_back(A[v]);
    for(int nv: G[v]){
        if(used[nv]) continue;
        dfs(nv);
    }
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    G.resize(N);
    A.resize(N);
    for(int i=0; i<N; i++) cin >> A[i];
    used = vector<bool>(N,false);
    for(int i=0; i<M; i++){
        int a,b;
        cin >> a >> b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    if(M == N-1){
        cout << 0 << "\n";
        return 0;
    }
    priority_queue<int,vector<int>,greater<int>> que;
    ll ans = 0;
    int cnt = 0;
    for(int i=0; i<N; i++){
        if(used[i]) continue;
        dfs(i);
        sort(suzu.rbegin(),suzu.rend());
        ans += suzu.back();
        suzu.pop_back();
        while(suzu.size()){
            que.emplace(suzu.back());
            suzu.pop_back();
        }
        cnt++;
    }
    int rem = 2*(cnt-1);
    if(que.size() < rem-cnt){
        cout << "Impossible\n";
    }else{
        for(int i=cnt+1; i<=rem; i++){
            ans += que.top();
            que.pop();
        }
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 7420
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
#define MX 100000
#define mod
#define ll long long
const double pi = acos(-1.0);

using namespace std;

int main()
{
	int a[100000],b[110000];
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	int k;
	cin>>k;
	for(int i=0;i<k;i++){
		int temp;
		scanf("%d",&temp);
		a[temp]++;
	}
	int max=0;
	for(int i=1;i<100000-1;i++){
		b[i]=a[i-1]+a[i]+a[i+1];
		if(b[i]>max)
		max=b[i];
	}
	printf("%d",max);
}




Measured memory_bytes: 1024
package main

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

var (
	sc = bufio.NewReader(os.Stdin)
)

func main() {
	S := scanStr()
	c := 0
	r := 0
	for _, s := range S {
		if s == 'R' {
			c++
			if r < c {
				r = c
			}
		} else {
			c = 0
		}
	}
	fmt.Println(r)
}

func abs(a int) int         { return int(math.Abs(float64(a))) }
func scan(a ...interface{}) { _, err := fmt.Fscan(sc, a...); pnc(err) }
func scanStr() (s string)   { scan(&s); return }
func scanInt() int          { i, err := strconv.Atoi(scanStr()); pnc(err); return i }
func scanFloat() float64    { f, err := strconv.ParseFloat(scanStr(), 64); pnc(err); return f }
func pnc(err error) {
	if err != nil {
		panic(err)
	}
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = n; i >= 0; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define REV(v) sort((v).begin(), (v).end(), greater<int>())
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a * b / gcd(a, b);};

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  int mini = min(a, min(b, c)), maxi = max(a, max(b, c));
  cout << mini << " " << maxi << endl;
  return 0;
}



Measured memory_bytes: 3100
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    n: usize
  };

  let mut res = 0_u64;
  for a in 1..=n {
    match (a % 3 == 0, a % 5 == 0) {
      (false, false) => {
        res += a as u64;
      }
      _ => {}
    }
  }
  println!("{}", res);
}


Measured memory_bytes: 2148
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

        Set<String> map = new HashSet<String>();
        String prev = null;
        for (int i = 0; i < N; i++) {
            String word = sc.next();
            if (map.contains(word)) {
                System.out.println("No"); return;
            }
            if (prev != null) {
                if (prev.charAt(prev.length()-1) != word.charAt(0)) {
                    System.out.println("No"); return;
                }
            }
            map.add(word);
            prev = word;
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23508
# import sys
import math #sqrt,gcd
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import product,permutations,combinations,combinations_with_replacement
# 重複あり順列、順列、組み合わせ、重複あり組み合わせ
# import collections # deque
# from operator import itemgetter,mul
# from fractions import Fraction
# from functools import reduce

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

def readInt():
    return list(map(int,input().split()))

def main():
    r = int(input())
    print(2*math.pi*r)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)

// for debug macro
bool global_debug_flag = false;
#define DEBUG(val) \
  if (global_debug_flag) cout << #val << " = " << val << endl

int main() {
  string s, t;
  string u;
  int x, y;
  read s >> t;
  read x >> y;
  read u;
  if (s == u) {
    x--;
  } else if (t == u) {
    y--;
  }
  cout << x << " " << y << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.ArrayList;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        for(int i=0;i<3;i++){
            char c = S.charAt(i);
            System.out.print(c);
        }
    }
}

Measured memory_bytes: 35400
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
res = 0
for i in range(n):
    res += b[a[i]-1]
for i in range(n-1):
    if a[i] + 1 == a[i+1]:
        res += c[a[i]-1]
print(res)

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

string S,T;
int cnt[26][26];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S>>T;
	FOR(i,S.size()) {
		cnt[S[i]-'a'][T[i]-'a']++;
	}
	
	FOR(i,26) {
		int sum=0;
		FOR(j,26) sum+=cnt[i][j];
		FOR(j,26) {
			if(cnt[i][j] && cnt[i][j]!=sum) return _P("No\n");
		}
		sum=0;
		FOR(j,26) sum+=cnt[j][i];
		FOR(j,26) {
			if(cnt[j][i] && cnt[j][i]!=sum) return _P("No\n");
		}
	}
	cout<<"Yes"<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 916
import java.io.*;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if(0 <= x - r && r + x <= W && 0 <= y - r && r + y <= H)
            System.out.println("Yes");
        else
            System.out.println("No");
      
        sc.close();
    }
}

Measured memory_bytes: 26316
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d,x;
  long long la,lb;
  double da,db;
  string s,ss,sss;
  
  int ans = 0;
  string anss = "";
  
  cin >> a;
  
  int ab [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  int result3 = std::max({a, b, c});
//--------------------------------------------------------------------------------

  b = a/100;
  c = a%100;
  
  if(b >= 1 && b <= 12) {
  	if(c >= 1 && c <= 12) anss = "AMBIGUOUS";
    else anss = "MMYY";
  } else {
  	if(c >= 1 && c <= 12) anss = "YYMM";
    else anss = "NA";
  }
  
  cout << anss << endl;

}

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

int main() {
    lint n, m;
    cin >> n >> m;

    map<lint, lint> wacnt;
    map<lint, bool> isac;
    for(lint i=0; i<m; i++) {
        lint p;
        string s;
        cin >> p >> s;

        if(isac[p])  continue;
        if(s == "AC")  isac[p] = true;
        if(s == "WA")  wacnt[p]++;
    }

    lint ac = 0, wa = 0;
    for(auto e : isac) {
        if(e.second == true)  ac++, wa += wacnt[e.first];
    }

    cout << ac << " " << wa << endl;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long n;
  cin>>n;
  vector<long long>A(n);
  for (long i=0; i<n; i++) cin>>A[i];
  sort(A.begin(), A.end(), greater<long long>());
  long long ans=A[0]; //最大値を格納
  if (n%2==0){
    for (int i=1; i<(n/2); i++){
      ans += A[i]*2;
    }
  }
  else{
    for (int i=1; i<(n/2); i++){
      ans += A[i]*2;
    }
    ans += A[(n/2)];
  }
  cout << ans;
}

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

using namespace std;

int main()
{
    int n;
    cin>>n;
    int j,k;
    j=n%10;
    k=n/10;
    if(j==9||k==9)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
n=int(input())
p=1
while n > 0:
  n-=26**p
  p+=1
else:
  p-=1
  if n==0:
    ans="z"*p
    print(ans)
  else:
    n+=26**p
    num=[]
    for i in range(1,p+1):
      if n%(26**(p-i))==0:
        a=int(n/(26**(p-i)))-1
        q=p-i
        num.append(a)
        break
      else:
        a=n//(26**(p-i))
        num.append(a)
        n-=a*(26**(p-i))
    al=[]
    if n==0:
      for i in range(p-1):
        m=chr(97+num[i])
        al.append(m)
      al.append(chr(96+num[p-1]))
      ans=''.join(al)
    else:
      for i in num:
        m=chr(97+i)
        al.append(m)
      al.append("z"*q)
      ans=''.join(al)
    print(ans)

Measured memory_bytes: 9272
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    map<char,int>a;
    char b;
    rep(i,n){
        cin >> b;
        a[b]++;
    }
    
    if(a.size()==3)cout << "Three";
    else cout << "Four";
}

Measured memory_bytes: 3592
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

// constant value
const ll mod = 1000000007ll;

template<class ll>
inline ll getCeilExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	--a;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

template<class ll>
inline ll getFloorExponent(ll a)
{
	if (a <= 0)
	{
		throw invalid_argument("vaule equal to or less than 0 should not be valid");
	}

	ll index = 0;
	a >>= 1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline ll getGcd(ll a, ll b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

// computational complexity: o(log(max(a, b))) 
template<class ll>
inline pair<ll, ll> getBezoutsIdentitySolution(ll a, ll b)
{
	if (b == 0)
	{
		return { 1, 0 };
	}
	auto sol = getBezoutsIdentitySolution(b, a % b);
	return { sol.second, sol.first - (a / b) * sol.second };
}

inline ll getModValue(ll a, ll m)
{
	return (a % m + m) % m;
}

// computational complexity: o(log(max(a, n))) 
inline ll getModInverse(ll a, ll m)
{
	auto sol = getBezoutsIdentitySolution(a, m);
	if (a * sol.first + m * sol.second != 1)
	{
		return -1;
	}
	return getModValue(sol.first, m);
}

ll getModPower(ll base, unsigned t, ll m)
{
	if (t == 0)
	{
		return 1ll;
	}

	auto res = getModPower(base, t >> 1, m);
	res = getModValue(res * res, m);
	if (t % 2 == 1)
	{
		res = getModValue(res * base, m);
	}
	return res;
}

class ModCombCalculator
{
private:
	ll n_;
	ll mod_;
	vector<ll> values_;
public:
	ModCombCalculator(ll n, ll mod) : n_(n), values_(n + 1LL, -1LL), mod_(mod)
	{
		values_[0] = 1LL;
	}
	
	ll calculate(ll r)
	{
		if (r < 0LL || n_ < r)
		{
			return 0LL;
		}

		if (values_[r] != -1)
		{
			return values_[r];
		}

		ll res;
		if (values_[r - 1] != -1)
		{
			res = values_[r - 1];
		}
		else
		{
			res = calculate(r - 1);
		}

		values_[r] = getModValue(
			getModValue(res * (n_ - r + 1LL), mod_) * getModInverse(r, mod_),
		mod_);

		return values_[r];
	}
};

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

	ll n, k;
	cin >> n >> k;

	cout << (n + 1 - k) << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n;
        int p[] = new int[10];
        n = sc.nextInt();
        for(int i=0;i<n;i++){
            p[i] = sc.nextInt();
        }
        Arrays.sort(p);
        int ans = 0;
        for(int i=0;i<9;i++){
            ans += p[i];
        }
        ans += p[9]/2;
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
from collections import Counter

N = int(input())
X = list(map(int, input().split()))
Q = int(input())
Y = [list(map(int, input().split())) for _ in range(Q)]

ctr = Counter(X)
ans = sum(X)
for b, c in Y:
    n = ctr[b]
    ctr[b] = 0
    ctr[c] += n
    ans = ans - b * n + c * n
    print(ans)


Measured memory_bytes: 107624
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int h,w;
    cin>>h>>w;
    char x;
    const ll t=(1e+9)+7;
    vector<ll>dp(w,0);
    dp[0]=1;
    for(int i=0;i<h;i++){
        cin>>x;
        if(x=='#'){dp[0]=0;}
        for(int j=1;j<w;j++){
            cin>>x;
            if(x=='#'){dp[j]=0;continue;}
            dp[j]=dp[j]+dp[j-1];
            dp[j]=dp[j]%t;
        }
    }
    cout<<dp[w-1];
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define pb push_back
#define xx first
#define yy second
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,k,n) for(int i=k;i<n;i++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> iv;
typedef pair<int,int> iip;
typedef map<int,int> mii;
template <typename T>
void dbg(T t){cerr<<t<<endl ;}
template<typename T, typename... Args>
void dbg(T t, Args... args) {cerr << t <<" ";dbg(args...) ;}

int main(){
	ll a,b,c,d,e;
	ll ans=0;
	cin>>a>>b>>c>>d>>e;
	if(b>a+a)b=a+a;
	if(c>b+b)c=b+b;
	if(d>c+c)d=c+c;
	ans = e/2 * d;
	ans += (e%2)*c;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+100;
typedef long long ll;

int n,jud,cnt,cot,rk[N][2],q[N];
ll ss,res,vs[N],ans=1e18,sum,tp;

struct P{
	ll v;int bel,sd;
	P(ll vv_=0LL,int bel_=0,int sd_=0):v(vv_),bel(bel_),sd(sd_){};
}t[N<<1];

inline bool cmp(const P&A,const P&B)
{return A.v<B.v;}

int main(){
	int i,j,k;ll x,y;
	scanf("%d",&n);
	for(i=1;i<=n;++i){
		scanf("%lld%lld",&x,&y);
		t[++cnt]=P(x,i,0);t[++cnt]=P(y,i,1);
	}
	sort(t+1,t+cnt+1,cmp);
	for(i=1;i<=n;++i){
		ss+=t[i].v;
		if(i>1 && (!jud) && t[i].sd!=t[i-1].sd) jud=1;
		if(!vs[t[i].bel]) vs[t[i].bel]=t[i].v,cot++;
	}
	if(jud && cot==n){
         if(t[n+1].bel!=t[n].bel){
         	ans=min(ans,ss-t[n].v+t[n+1].v);
         }else{
         	for(i=1;i<=cnt;++i)
         	 rk[t[i].bel][t[i].sd]=i;
         	for(i=1;i<=n;++i) sum+=t[i].v;
         	for(i=1;i<=n;++i){
         		j=0;tp=sum;
         		if(rk[i][0]>n) {j++;tp+=t[rk[i][0]].v;}
         		if(rk[i][1]>n) {j++;tp+=t[rk[i][1]].v;}
         		for(k=n;k && j;k--){
         			if(k!=rk[i][0] && k!=rk[i][1]){
         				tp-=t[k].v;j--;
         			}
         		}
         		ans=min(ans,tp);
         	 }
	    }
	}else ans=ss;
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

const int N=100000+5;

int n,k;
ll h[N];
ll dp[N];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>h[i];
        dp[i]=(1LL<<60);
    }
    dp[1]=0;
    for(int i=2;i<=n;i++)
    {
        for(int j=i-k;j<i;j++)
        {
            if(j>=1)
            {
                dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
            }
        }
    ///cout<<i<<" : "<<dp[i]<<"\n";
    }
    cout<<dp[n]<<"\n";
    return 0;
}
/**

**/


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

#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define ALL(obj) (obj).begin(),(obj).end()
#define space <<" "<<
#define ll long long
#define mod %1000000007

using namespace std;

ll powAns(ll,ll);

int main(){
    ll M,N;
    cin>>M>>N;
    cout<<powAns(M,N)<<endl;
}

ll powAns(ll m ,ll n){
    ll res=1;
    while(n>0){
        if(n & 1)res = res*m mod;
        
        m=m*m mod;
        n>>=1;
    }

    return res;
}



Measured memory_bytes: 3108
#include <iostream>

using namespace std;

int main() {
  while(true) {
    //input
    int num;
    cin >> num;
    //if 0 finish
    if(num==0) break;

    //oturi
    num = 1000 - num;

    int ans = 0;

    //500yen
    if(num>=500) {
      ans++;
      num-=500;
    }

    //100yen
    while(num>=100) {
      ans++;
      num-=100;
    }

    //50yen
    if(num>=50) {
      ans++;
      num-=50;
    }

    //10yen
    while(num>=10) {
      ans++;
      num-=10;
    }

    //5yen
    if(num>=5) {
      ans++;
      num-=5;
    }

    //1yen
    while(num>=1) {
      ans++;
      num-=1;
    }

    cout << ans << endl;

  }

  return 0;
}



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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long



int32_t main() {

    string s; cin >> s;
    int l = s.length();

    string k = "keyence";
    int i = 0, j = 7;

    while(i < j) {
        if(k[i] != s[i]) break;
        ++i;
    }

    while(j > i) {
        int ind = l-(7-j)-1;
        if(k[j-1] != s[ind]) break;
        j--;
    }

    if(i == j) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <list>
#include <bitset>

using namespace std;

int main()
{
    int a, b, c ,d;
    cin >> a >> b >> c >> d;
    cout << a - b - c + d << endl;

    return 0;
}


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

int main(){
  int n,l,ans=0,i;
  cin >> n >> l; 
  for(i=1; i<=n; i++){
    ans+=l+i-1;
  }
  if(l<=0 && abs(l)<n){
    cout << ans;
  }else if(l<=0){
    cout << ans-(l+n-1);
  }else{
    cout << ans-l;
  }
    
}
  

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2000)

N, M = map(int, input().split())
sw = [list(map(int, input().split())) for _ in range(M)]
p = list(map(int, input().split()))

def rec(k, lst):
    if k == N:
        b = [0] * M
        for i in range(N):
            if lst[i] == 0:
                continue
            for j in range(M):
                if i + 1 in sw[j][1:]:
                    b[j] += 1
        # print("b, lst :", b, lst)
        return M == sum([b[i] % 2 == p[i] for i in range(M)])
    return rec(k + 1, lst + [0]) + rec(k + 1, lst + [1])

a = rec(1, [0])
b = rec(1, [1])
print(a + b)

Measured memory_bytes: 3064
(let ((s (string (read)))
      (tt (string (read))))
  (labels ((f (x y)
             (cond ((equal x y)
                    (princ "Yes"))
                   ((equal s x)
                    (princ "No"))
                   (t
                    (f (concatenate 'string (subseq x (1- (length x)))
                                          (subseq x 0 (1- (length x))))
                       y)))))
    (if (equal s tt)
        (princ "Yes")
        (f (concatenate 'string (subseq s (1- (length s)))
                              (subseq s 0 (1- (length s))))
           tt))))

Measured memory_bytes: 14560
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**9)

def solve():
    MOD = 10**9 + 7

    N = int(input())
    adjL = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        adjL[a].append(b)
        adjL[b].append(a)

    def getFacts(n, MOD):
        facts = [1] * (n+1)
        for x in range(2, n+1):
            facts[x] = (facts[x-1] * x) % MOD
        return facts
    facts = getFacts(N, MOD)
    def getInvFacts(n, MOD):
        invFacts = [0] * (n+1)
        invFacts[n] = pow(facts[n], MOD-2, MOD)
        for x in reversed(range(n)):
            invFacts[x] = (invFacts[x+1] * (x+1)) % MOD
        return invFacts
    invFacts = getInvFacts(N, MOD)

    def getComb(n, k, MOD):
        if n < k:
            return 0
        return facts[n] * invFacts[k] * invFacts[n-k] % MOD

    dp = [1] * N
    sizes = [0] * N
    def dfsDP(v, vPar):
        sizes[v] = 0
        for v2 in adjL[v]:
            if v2 == vPar: continue
            dp[v] = dp[v] * dfsDP(v2, v) % MOD
            sizes[v] += sizes[v2]
            dp[v] = dp[v] * getComb(sizes[v], sizes[v2], MOD) % MOD
        sizes[v] += 1
        return dp[v]

    anss = [0] * N
    def dfsAns(v, vPar, resPar):
        anss[v] = dp[v] * resPar * getComb(N-1, sizes[v]-1, MOD) % MOD

        for v2 in adjL[v]:
            if v2 == vPar: continue
            coef = dp[v2] * getComb(N-1, sizes[v2], MOD) % MOD
            dfsAns(v2, v, anss[v] * pow(coef, MOD-2, MOD) % MOD)


    dfsDP(0, -1)
    dfsAns(0, -1, 1)

    print('\n'.join(map(str, anss)))


solve()


Measured memory_bytes: 85988
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int n, m, cnt, ans;
int a[1001], b[1001], c[1001];


int main() {

	cin >> n >> m;
	rep(i, m) {
		cin >> a[i] >> b[i];
	}
	rep(i, m) {
		if (a[i] >= n)cnt++;
	}
	sort(a, a + m);
	reverse(a, a + m);
	rep(i, m) {
		if (cnt < m - 1) {
			if (a[i] < n) {
				while (a[i] < n) {
					ans++;
					a[i]++;
				}
				cnt++;
			}
		}
		else break;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3156
#include <algorithm>
#include <tuple>
#include <utility>
#include <iostream>
#include <iomanip>
#include <vector>
using namespace std;

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, Q;
  cin >> N >> Q;
  vector<int> C(N);
  for(int i = 0; i < N; ++i)
    cin >> C[i], --C[i];
  const int b = 1000;
  vector<vector<tuple<int,int,int>>> query(b);
  for(int i = 0; i < Q; ++i){
    int l, r;
    cin >> l >> r;
    --l;
    query[l/b].emplace_back(r,l,i);
  }
  for(auto& q : query)
    sort(q.begin(), q.end());
  vector<int> ans(Q);
  for(const auto& q : query){
    if(q.empty()) continue;
    vector<int> cnt(N);
    int m = 0;
    int ll = get<1>(q[0]), rr = ll;
    for(auto [r, l, i] : q){
      while(rr < r){
        ++cnt[C[rr]];
        if(cnt[C[rr]] == 1)
          ++m;
        ++rr;
      }
      while(ll < l){
        --cnt[C[ll]];
        if(!cnt[C[ll]])
          --m;
        ++ll;
      }
      while(ll > l){
        --ll;
        ++cnt[C[ll]];
        if(cnt[C[ll]] == 1)
          ++m;
      }
      ans[i] = m;
    }
  }
  for(auto e : ans)
    cout << e << '\n';
}


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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define ll long long
//#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 20;
const int inf = 1e9+7;

int n, m, p[N];
vector <pair <int, int> > o;
char c[N][N];

bool OK(int I, int J) {
    o.clear();
    int u[20], cnt = 0;
    for(int i = 1; i <= n; i++) {
        u[i] = 0;
    }
    for(int i = 1; i <= n; i++) {
        if(u[i]) continue;
        int p = -1;
        for(int j = i + 1; j <= n; j++) {
            if(u[j]) continue;
            if(c[i][I] == c[j][J] && c[j][I] == c[i][J]) {
                p = j;
            }
        }
        if(p != -1) {
            u[i] = u[p] = 1;
            o.pb(mk(i, p));
        }
        else {
            if(c[i][I] != c[i][J]) return 0;
            o.pb(mk(i, i));
            cnt++;
        }
    }
    if(cnt > 1) return 0;
    return 1;
}

bool check() {
    vector <string> v;
    for(int i = 1; i <= m; i++) {
        string o = "";
        for(int j = 1; j <= n; j++) {
            o += c[p[j]][i];
        }
        v.pb(o);
    }

    int u[20], cnt = 0;
    for(int i = 0; i < m; i++) {
        u[i] = 0;
    }
    for(int i = 0; i < m; i++) {
        if(u[i]) continue;
        int p = -1;
        for(int j = i + 1; j < m; j++) {
            if(u[j]) continue;
            reverse(all(v[j]));
            if(v[i] == v[j]) {
                p = j;
            }
            reverse(all(v[j]));
        }
        if(p == -1) {
            string O = v[i];
            reverse(all(O));
            if(v[i] == O) {
                cnt++;
            }
            else
                return 0;
        }
        else {
            u[p] = 1;
            u[i] = 1;
        }
    }
    if(cnt > 1) return 0;
    return 1;
}

int main() {
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= m; j++) {
            cin >> c[i][j];
        }
    }
    for(int i = 2; i <= m; i++) {
        if(OK(1, i)) {
            int cnt = 1;
            for(int j = 0; j < sz(o); j++) {
                if(o[j].fr == o[j].sc) {
                    p[n / 2 + 1] = o[j].fr;
                }
                else {
                    p[cnt] = o[j].fr;
                    p[n - cnt + 1] = o[j].sc;
                    cnt++;
                }
            }
            if(check()) {puts("YES");return 0;}
        }
    }
    for(int i = 1; i <= m; i++) {
        if(i == 2) continue;
        if(OK(2, i)) {
            int cnt = 1;
            for(int j = 0; j < sz(o); j++) {
                if(o[j].fr == o[j].sc) {
                    p[n / 2 + 1] = o[j].fr;
                }
                else {
                    p[cnt] = o[j].fr;
                    p[n - cnt + 1] = o[j].sc;
                    cnt++;
                }
            }
            if(check()) {puts("YES");return 0;}
        }
    }
    puts("NO");
}


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

string s, t;

int main(){
  cin >> s >> t;

  //空文字を挿入しておく
  s.insert(s.begin(), ' '); t.insert(t.begin(), ' ');

  //dpテーブルの確保と初期化
  int dp[t.length()][s.length()];
  for(int i=0; i<t.length(); i++){
    for(int j=0; j<s.length(); j++){
      dp[i][j]=0;
      if(i==0) dp[i][j]=j;
      if(j==0) dp[i][j]=i;
    }
  }

  //dp
  for(int i=1; i<t.length(); i++){
    for(int j=1; j<s.length(); j++){
      int add, del, rep;
      add = dp[i-1][j]+1;
      del = dp[i][j-1]+1;
      rep = t[i]==s[j]? dp[i-1][j-1] : dp[i-1][j-1]+1;
      dp[i][j] = min(add, min(del, rep));
    }
  }

  cout << dp[t.length()-1][s.length()-1] << endl;

  return 0;
}



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

bool isPalindrome(string s)
{
	for(int i=0; i<=s.size()/2; i++)
		if(s[i]!=s[s.size()-1-i])
			return false;
	
	return true;
}

int main()
{
	string s;
	cin>>s;
	int n=s.size();
	
	if(isPalindrome(s) && isPalindrome(s.substr(0, n/2)) && isPalindrome(s.substr(n/2+1, n))) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
 
int main(){
	int a[4],b[4];
	int H,B;
     while(cin >> a[0],!cin.eof()){
		H=0,B=0;
		for(int i=1;i<4;i++)
			cin >> a[i];
		for(int i=0;i<4;i++)
			cin >> b[i];
		for(int i=0;i<4;i++){
			for(int j=0;j<4;j++){
				if(a[i]==b[j]){
					if(i==j)
						H++;
					else
						B++;
				}
			}
		}
		cout << H << ' ' << B << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] H = new int[N];

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

    sc.close();

    int count = 0;
    int max = 0;

    for (int i = 0; i < N - 1; i++) {
      if (H[i] >= H[i+1]) {
        count++;
      } else {
        max = Math.max(max, count);
        count = 0;
      }
    }
    
    max = Math.max(max, count);

    System.out.println(max);

  }

}

Measured memory_bytes: 49684
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var A = lines[0].split(" ")[0];
    var B = lines[0].split(" ")[1];

    var ans = Number(A + B);
    if (Math.sqrt(ans) !== Math.floor(Math.sqrt(ans))) { console.log("No") }
    else { console.log("Yes") }
    
});

Measured memory_bytes: 7500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

class Main {

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

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            String[] cellsCount = br.readLine().split(" ");
            Map<String, Long> counted = Arrays.asList(cellsCount).stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
            counted.entrySet().stream().filter(e -> e.getValue() == 1).forEach(e -> System.out.println(e.getKey()));

        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 26836
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>
#include <set>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;

  ll already = min(N, M/2);
  M -= already * 2;

  cout << already + M / 4 << endl;

  return 0;
}


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

string s; 
int next[200005][26],dp[202005],cf[200005],chr[200005];

int main(){
    cin>>s;
    s="-"+s;
    int n=s.size();
    for(int i=0;i<26;++i)next[n][i]=n+i;
    for(int i=n-1;i>=0;--i){
        for(int j=0;j<26;++j)next[i][j]=next[i+1][j];
        next[i][s[i]-'a']=i;
        /* cout<<"next of "<<i<<" : ";
        for(int j=0;j<26;++j)cout<<next[i][j]<<" ";
        cout<<endl; */
    }
    for(int i=n-1;i>=0;--i){
        int val=9988776;
        for(int j=0;j<26;++j){
            // if(i==0)cout<<j<<" "<<next[i+1][j]<<" "<<dp[next[i+1][j]]<<endl;
            if(dp[next[i+1][j]]+1<val){
                val=dp[next[i+1][j]]+1;
                cf[i]=next[i+1][j];
                chr[i]=j;
            }
        }
        dp[i]=val;
        // cout<<i<<" "<<dp[i]<<" "<<cf[i]<<" "<<chr[i]<<endl;
    }
    string ans;
    int now=0;
    while(now<n){
        ans+=char(chr[now]+'a');
        now=cf[now];
    }
    cout<<ans<<endl;
}


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

int main() {
  int N,all,L,R;
  cin >> N;
  all = 0;
  for (int i = 0; i < N; i++){
    cin >> L >> R;
    all += R-L+1;
  }
  cout << all << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int s[7],n;
    for (int i=1;i<=6;i++){
        cin>>s[i];
    }
    cin>>n;
    for (int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a==s[1]&&b==s[2]) cout<<s[3]<<endl;
        if(a==s[1]&&b==s[3]) cout<<s[5]<<endl;
        if(a==s[1]&&b==s[4]) cout<<s[2]<<endl;
        if(a==s[1]&&b==s[5]) cout<<s[4]<<endl;
        if(a==s[2]&&b==s[1]) cout<<s[4]<<endl;
        if(a==s[2]&&b==s[3]) cout<<s[1]<<endl;
        if(a==s[2]&&b==s[4]) cout<<s[6]<<endl;
        if(a==s[2]&&b==s[6]) cout<<s[3]<<endl;
        if(a==s[3]&&b==s[1]) cout<<s[2]<<endl;
        if(a==s[3]&&b==s[2]) cout<<s[6]<<endl;
        if(a==s[3]&&b==s[5]) cout<<s[1]<<endl;
        if(a==s[3]&&b==s[6]) cout<<s[5]<<endl;
        if(a==s[4]&&b==s[1]) cout<<s[5]<<endl;
        if(a==s[4]&&b==s[2]) cout<<s[1]<<endl;
        if(a==s[4]&&b==s[5]) cout<<s[6]<<endl;
        if(a==s[4]&&b==s[6]) cout<<s[2]<<endl;
        if(a==s[5]&&b==s[1]) cout<<s[3]<<endl;
        if(a==s[5]&&b==s[3]) cout<<s[6]<<endl;
        if(a==s[5]&&b==s[4]) cout<<s[1]<<endl;
        if(a==s[5]&&b==s[6]) cout<<s[4]<<endl;
        if(a==s[6]&&b==s[2]) cout<<s[4]<<endl;
        if(a==s[6]&&b==s[3]) cout<<s[2]<<endl;
        if(a==s[6]&&b==s[4]) cout<<s[5]<<endl;
        if(a==s[6]&&b==s[5]) cout<<s[3]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3080
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, maxi = -1;
  string s;
  cin >> n >> s;
  set<char> se;
  REP(i,n) se.insert(s[i]);
  REP(i,n) {
    string t1 = s.substr(0,i);
    string t2 = s.substr(i,s.size()-i);
    set<char> t1s, t2s;
    REP(j,t1.size()) t1s.insert(t1[j]);
    REP(k,t2.size()) t2s.insert(t2[k]);
    maxi = max(maxi, (int)(t1s.size() + t2s.size() - se.size()));
  }
  cout << maxi << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    string S;cin>>S;
    int L=S.size(),a=753,ans=100000;
    for(int l=0;l<=L-3;++l){
        int z=0;
        for(int i=0;i<3;++i){
            z*=10;
            int b=S[l+i]-'0';
            z+=b;
        }
        ans=min(ans,abs(z-a));
    }
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
import java.io.*;

public class Main{
    public static void main(String[]args) throws NumberFormatException, IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        
        int W = Integer.parseInt(str[0]);
        int H = Integer.parseInt(str[1]);
        int x = Integer.parseInt(str[2]);
        int y = Integer.parseInt(str[3]);
        int r = Integer.parseInt(str[4]);
        
        if((x-r>=0) && (y-r>=0) && (y+r<=H) && (x+r<=W)){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
        
    }
}

Measured memory_bytes: 17060
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
 
using namespace std;
 
#define pb(n)	push_back(n)
#define mp(n,m) make_pair(n,m)
#define fi 	first
#define se 	second
#define all(r) (r).begin(),(r).end()
 
#define REP(i,s,e)	for(int i=(s); i<(e); i++)
#define rep(i,n)	REP(i,0,n)
#define REPE(i,s,e)	for(int i=s; i>e; i--)
#define repe(i,n)	REPE(i,n,-1)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<vi> vii;
 
const int IMAX=((1<<30)-1)*2+1;
const int INF=100000000;
const double EPS=1e-10;
//int mod=1000000007
 

 



int main(){
	int v[5];
	while(1){
		rep(i,5) cin>>v[i];
		if(cin.eof()) break;
		vi a(3,0);
		bool f=true;
		for(int i=0; i<5; i++){
			a[v[i]-1]++;
		}
		if(a[0]>0&&a[1]>0&&a[2]>0)f=false;
		for(int i=0; i<3; i++){
			if(a[i]==0&&a[(i+1)%3]==0){
				f=false;
				// rep(j,5){
				// 	cout<<"3"<<endl;
				// }
				break;
			}
		}
		if(f){
			int k;
			for(int i=0; i<3; i++){
				if(a[i]==0){
					k=i+1;
					break;
				}
			}
			for(int i=0; i<5; i++){
				cout<<(v[i]==k%3+1?1:2)<<endl;
			}
		}
		else{
			rep(i,5){
				cout<<3<<endl;
			}
		}
	}
}

Measured memory_bytes: 1192
def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0

    for i in range(N, 0, -1):
        if A[i] > B[i - 1]:
            ans += B[i - 1]
            B[i - 1] = 0
        else:
            B[i - 1] = B[i - 1] - A[i]
            ans += A[i]

        if A[i - 1] < B[i - 1]:
            ans += A[i - 1]
            A[i - 1] = 0
        else:
            A[i - 1] = A[i - 1] - B[i - 1]
            ans += B[i - 1]

    print(ans)

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 19004
import java.util.Arrays;
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 = new int[n];
		Arrays.setAll(a, i -> sc.nextInt());

		int k = 0;
		int num = 1;
		for (int i = 0; i < a.length; i++) {
			if (a[i] == num) {
				k++;
				num++;
			}
		}
		int ans = k != 0 ? n - k : -1;
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 67468
#include <bits/stdc++.h>
#define ld long double
using namespace std;

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

	x *= 1.0;
	x /= 3.0;

	ld res = 1.0 * x * x * x;
	cout<<setprecision(20)<<res<<"\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
 
#pragma GCC optimize("Ofast")
//#pragma GCC optimization("unroll-loops, no-stack-protector")
//#pragma GCC target("avx,avx2,fma")
 
using namespace std;

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define endl '\n';
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T> inline T gcd(T a, T b) { while (b) { a %= b; swap(a, b); } return a; }
template <class T> inline T lcm(T a, T b) { return a * b / gcd(a, b); }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
    #define eprintf(...) 42
#endif

clock_t startTime;
double getCurrentTime() {
    return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const ll MOD = (ll)1e9 + 7, INF = (ll)1e18;;
ll add(ll x, ll y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
ll sub(ll x, ll y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
ll mul(ll x, ll y) {
    return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
    if (p == 0) return 1;
    if (p & 1) return mul(x, bin_pow(x, p - 1));
    return bin_pow(mul(x, x), p / 2);
}

const int N = 100100;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    startTime = clock();
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    
    if (s[s.size() - 1] == 's')
        s += "es";
    else
        s += "s";
    
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3680
#pragma GCC optimize("Ofast")
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include <map>
#include <set>
#include <tuple>
using namespace std;
#define INF 1LL << 30
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,ll> P;
//typedef pair<pair<int,int>,int> p;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
struct edge
{
    ll to, cost, val;
};
template <class T, class U>
bool chmin(T &a, const U &b)
{
    if (a <= b)
        return false;
    a = b;
    return true;
}
template <class T, class U>
bool chmax(T &a, const U &b)
{
    if (a >= b)
        return false;
    a = b;
    return true;
}
//__builtin_popcount(S);
//C.erase(unique(C.begin(),C.end()),C.end());
#define int ll

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

    int a[7],b[7];
    for(int i=0;i<7;i++){
        cin>>a[i];
        b[i]=a[i];
    } 
    int ans=0,temp=a[1];
    if(a[0]>0 && a[3]>0 && a[4]>0){
        a[0]--; a[3]--; a[4]--;
        temp+=3;
        temp+=a[0]/2*2;
        temp+=a[3]/2*2;
        temp+=a[4]/2*2;
    }
    chmax(ans,temp);
    temp=a[1];
    temp+=b[0]/2*2;
    temp+=b[3]/2*2;
    temp+=b[4]/2*2;
    chmax(ans,temp);
    cout<<ans<<endl;

}


Measured memory_bytes: 256