akhauriyash/Code-Regression huggingface dataset:
const int isDebugMode = 1;
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b , a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

int main(){
    ll N; cin >> N;
    vector<ll> l(N);
    ll ans = 0;
    rep(i, N) cin >> l[i];
    rep(k, N)rep(j, k)rep(i, j){
        // pt(i, j, k);
        if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
        if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j]) ans++;
    }
    pt(ans);
}

Measured memory_bytes: 3628
#include <stdio.h>

class Dice4{
public:
	int number[6];

	void roll(char dst){
		switch(dst){
		case 'E':
			setNumber(number[3],number[1],number[0],number[5],number[4],number[2]);
			break;
		case 'N':
			setNumber(number[1],number[5],number[2],number[3],number[0],number[4]);
			break;
		case 'S':
			setNumber(number[4],number[0],number[2],number[3],number[5],number[1]);
			break;
		case 'W':
			setNumber(number[2],number[1],number[5],number[0],number[4],number[3]);
			break;
		}
	};

	bool isSameDice(int inputed[]){
		char order[25] = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < 24; i++){
			roll(order[i]);
			for(int j = 0; j < 6; j++){
				if(inputed[j] != number[j])
					break;
				if(j == 5)
					return true;
			}
		}
		return false;
	}

private:
	void setNumber(int n0,int n1,int n2,int n3,int n4,int n5){
		number[0] = n0;
		number[1] = n1;
		number[2] = n2;
		number[3] = n3;
		number[4] = n4;
		number[5] = n5;
	}

};

int main(){
	int n,k,j;
	scanf("%d",&n);
	Dice4 array[n];
	for(int i = 0; i < n; i++){
		scanf("%d %d %d %d %d %d",&array[i].number[0],&array[i].number[1],&array[i].number[2],
				&array[i].number[3],&array[i].number[4],&array[i].number[5]);
	}
	for(k = 0; k < n-1; k++){
		for(j = k+1; j < n; j++){
			if(array[k].isSameDice(array[j].number))
				break;
		}
		if(j < n) break;
	}
	if(k == n-1){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
}



Measured memory_bytes: 2704
# input
# a = int(input())
# b = int(input())
# c = int(input())
# d = int(input())
# e = int(input())
# k = int(input())
a = [int(input()) for _ in range(5)]
k = int(input())

# solution
if max(a) - min(a) > k: res = ':('
else: res = 'Yay!'

# output
print(res)

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

typedef long long int ll;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0;i < N;i++){
     cin >> A[i];
  }
  int ans = 0;
  vector<pair<int,int>> odd(100010);
  vector<pair<int,int>> even(100010);
  int OM,EM;
  for(int i = 0;i < N;i++){
     if(i % 2 == 0){
        odd[A[i]].first++;
        odd[A[i]].second = A[i];
     }else{
        even[A[i]].first++;
        even[A[i]].second = A[i];
     }
  }
  sort(odd.begin(),odd.end());
  reverse(odd.begin(),odd.end());
  sort(even.begin(),even.end());
  reverse(even.begin(),even.end());
  if(odd[0].second != even[0].second){
     cout << N - odd[0].first - even[0].first << endl;
  }else if(odd[1].first > even[1].first){
     cout << N - odd[1].first - even[0].first << endl;
  }else if(odd[1].first <= even[1].first){
     cout << N - odd[0].first - even[1].first << endl;
  }
  
}

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

int main (){
  int n;
  cin >> n;
  vector<long long> luca(n+1,0);
  luca.at(0)=2;
  luca.at(1)=1;
  for(int i=2;i<n+1;i++)
  {
    luca.at(i)=luca.at(i-1)+luca.at(i-2);
  }
  cout << luca.at(n) << endl;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    while(true){
    cin >> H >> W;
    if(H == 0 && W == 0){
           break;
    }
    for(int j=0;j<W;j++){
        cout << '#';
    }cout << endl;
    for(int i=1;i<H-1;i++){
        cout << '#';
        for(int j=1;j<W-1;j++){
            cout << '.';
        }
        cout << '#' << endl;
        }
        for(int j=0;j<W;j++){
        cout << '#';
    }
    cout << endl <<endl;
    }
}


Measured memory_bytes: 3044
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if(s.equals("Sunny")){
            System.out.println("Cloudy");
        }else if(s.equals("Cloudy")){
            System.out.println("Rainy");
        }else{
            System.out.println("Sunny");
        }
        sc.close();
    }
}

Measured memory_bytes: 35692
import java.util.Scanner;
import java.util.Arrays;
 
class Main{
    public static void main(String[] args){
        Integer[] ary = new Integer[10];
        Scanner sc = new Scanner(System.in);
         
        for(int i = 0; i < ary.length; ++i){
            ary[i] = sc.nextInt();
        }
         
        Arrays.sort( ary );
         
        System.out.println(ary[9]);
        System.out.println(ary[8]);
        System.out.println(ary[7]);
    }
}


Measured memory_bytes: 26064
n, y = map(int, input().split())
y //= 1000
for i in range(n+1):
    for j in range(n-i+1):
        if i*10 + j*5 + (n-i-j) == y:
            print(i, j, n-i-j)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))
_abs = 10 ** 9
place = 0
for i in range(n):
    tem = t - h[i] * 0.006
    if _abs > abs(a - tem):
        _abs = abs(a - tem)
        place = i + 1
print(place)


Measured memory_bytes: 3060
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    
    // int X = 2;
    int X = 0;
    cin >> X;
    
    int sum = 0;
    for(int i = 1; i <= X; i++){
        sum += i;
        if(sum >= X){
            int dis = sum - X;
            if(dis < X){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 256
N = int(input())
F, P = [], []
for i in range(N):
  F.append(list(map(int, input().split())))
for i in range(N):
  P.append(list(map(int, input().split())))
  
ans = -(10**9)
for i in range(1, 2**10):
  l = [0] * N
  for j in range(10):
    if (i>>j) & 1:
      for k in range(N):
        if F[k][j] == 1:
          l[k] += 1
  tmp = 0
  for m in range(N):
    n = l[m]
    tmp += P[m][n]
  ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 9220
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    long double L;
    cin >> L;

    long double s = L/3;

    cout << fixed << setprecision(12) << (L*L*L)/27<< endl;
}

Measured memory_bytes: 256
import std.stdio,
       std.string,
       std.conv,
       std.algorithm;

void main(){
  int count = readln().chomp.to!int;
  string[] lines;
  foreach(i; 0..count){
    lines.length++;
    lines[i] = readln().chomp;
  }

  foreach(line; lines){
    auto num = line.split.map!(to!int);
    int d;

    foreach(n1; num)
      foreach(n2; num)
        foreach(n3; num)
          if((n1*n1) == (n2*n2) + (n3*n3))
            d++;

    if(d != 0)
      writeln("YES");
    else
      writeln("NO");
  }
}

Measured memory_bytes: 1176
while gets
  s,a,o=$_.chomp,"",0
  s.length.times do |i|
    if o>0 then o-=1
    elsif s[i]=="@"
      s[i+1].to_i.times{a<<s[i+2]}
      o+=2
    else a<<s[i]
    end
  end
  puts a
end

Measured memory_bytes: 8684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}

int F(int x) {
  int res = 0;
  while (x%2 == 0) {
    res++;
    x /= 2;
  }
  return res;
}

int main() {
  // 因数2に注目、2で割れる回数が同じが条件、最小公倍数がオーバーフローに注意
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  int time = F(A[0]); // 最初の数が何回2で割れるか
  rep(i, N) {
    if (F(A[i]) != time) {
      cout << 0 << '\n';
      return 0;
    }
    A[i] >>= time;
  }
  ll l = 1;
  rep(i, N) {
    l = lcm(l, A[i]);
    if (l > M) {
      cout << 0 << '\n';
      return 0;
    }
  }
  M >>= (time-1);
  M /= l;
  int ans = (M+1) / 2;
  cout << ans << '\n';  
  return 0;
}

Measured memory_bytes: 3708
import itertools

def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False

"""
itertools.product(range(a+1), range(b+1), range(c+1))
"""

def main():
    (n, _) = list(map(int, input().split()))
    x = []
    for _ in range(n):
        x.append([int(n) for n in input().split()])

    count = 0
    for (a, b) in itertools.combinations(x, 2):
        if is_integer_num(sum((pair[0] - pair[1]) ** 2 for pair in zip(a, b)) ** .5):
            count += 1
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int n,m,ans = 0;
    cin >> n;
    int t[n];
    rep(i, n){cin >> t[i];ans += t[i];}
    cin >> m;
    int p[m],x[m];
    rep(i, m)cin >> p[i] >> x[i];
    rep(i, m){
        cout << (ans - t[p[i] - 1] + x[i]) << endl;
    }
    return 0;
}


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

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

    for (int z = 0; z < q; z++) {
        string X, Y;
        cin >> X >> Y;
        int n = X.size();
        int m = Y.size();
        vector< vector<int> > dp(n+1, vector<int>(m+1));

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (X.at(i) == Y.at(j)) {
                    dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
                } else {
                    dp.at(i+1).at(j+1) = max(dp.at(i).at(j+1), dp.at(i+1).at(j));
                }
            }
        }

        cout << dp.at(n).at(m) << endl;
    }
}




Measured memory_bytes: 6848
#include <stdio.h>
int main() {
	int n, T, ans = 1001, c, t;
	scanf("%d%d", &n, &T);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &c, &t);
		if (t <= T && c < ans) {
			ans = c;
		}
	}
	if (ans == 1001) {
		printf("TLE\n");
	} else {
		printf("%d", ans);
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int comp(const void *a, const void *b) {
    return *(int*)a - *(int*)b;
}
int main() {
  int n,a[300000],i;
  long long x=0;
  scanf("%d",&n);
  for (i=0;i<3*n;i++) {
    scanf("%d",&a[i]);
  }
  qsort(a, 3*n, sizeof(int), comp);
  for (i=n;i<3*n;i+=2) {
    x+=a[i];
  }
  printf("%lld\n",x);
  return 0;
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
using namespace std;
#define el "\n"
#define F first
#define S second
#define PI 3.14159265358979323846  /* pi */
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
#define all(v)  	((v).begin()),((v).end())
#define degreesToRadians(angleDegrees) (angleDegrees * PI / 180.0) // Converts degrees to radians.
#define radiansToDegrees(angleRadians) (angleRadians * 180.0 / PI) // Converts radians to degrees.
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
const double EPS = 1e-9;
const int N = 1e3+2, M = 3e5+5, OO = 0x3f3f3f3f;
// int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
// int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Direction
// int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; // Knight Direction
// int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; // Hexagonal Direction

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
  int n;
  cin>>n;
  string s;
  map<string, int> mp;
  for(int i=0;i<n;i++){
    cin>>s;
    mp[s]++;
  }
  cout<<mp.size()<<endl;
	return 0;

}


Measured memory_bytes: 19248
package main

import (
	"fmt"
)

func main() {
  	var n, x, y int
  	fmt.Scan(&n,&x,&y)
  	x--
    y--
  
  	dist := make(map[int]int)
    for i := 0; i < n-1; i++ {
      for j := i+1; j < n; j++ {
        //fmt.Printf("i=%d,j=%d,j-i=%d,abs(x-i)+1=%d,abs(j-y)=%d\n",i,j,j-i,abs(x-i)+1,abs(j-y))
        d := min(j-i,abs(x-i)+1+abs(j-y))
        dist[d]++
      }
    }
    for i := 1; i < n; i++ {
      fmt.Println(dist[i])
    }
}

func min(a,b int)int {
  if a < b {
  	return a
  }
  return b
}

func abs(a int)int {
    if a < 0 {
      return -a
    }
    return a
}

Measured memory_bytes: 768
import java.util.Arrays;
import java.util.Scanner;

public class Main {

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

        long n = sc.nextLong();
        long[] t = new long[5];

        long ans = 5;

        for (int i = 0; i < 5; i++) {
            t[i] = sc.nextLong();
        }

        Arrays.sort(t);

        sc.close();

        int num = n % t[0] != 0 ? 1 : 0;

        ans = (long) (Math.ceil(n / t[0]) + 4 + num);
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える
	int id[100010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n,m,t;
	scanf("%lld%lld%lld",&n,&m,&t);
	rep(i,0,m){
		ll x,y,c;
		scanf("%lld%lld%lld",&x,&y,&c);
		x--,y--;
		g.e[i].s=x;
		g.e[i].g=y;
		g.e[i].c=-(c-t);
	}
	g.vcnt=n;
	g.ecnt=m;
	qsort(g.e,g.ecnt,sizeof(E),esort);
//	qsort(g.e,g.ecnt,sizeof(E),csort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}


//ベルマンフォード
//グラフと始点を引いて単一始点最短経路を返す
//辺のソートは不要
//O(EV)、負辺ありでもOK
//*
ll d[2510];
void berumanfoodo(ll s){
	rep(i,0,g.vcnt)d[i]=i==s?0:INF;
	rep(nnnn,0,g.vcnt-1)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF)d[g.e[i].g]=min(d[g.e[i].g],d[g.e[i].s]+g.e[i].c);
	rep(nnnn,0,g.vcnt)rep(i,0,g.ecnt)if(d[g.e[i].s]!=INF){
		if(d[g.e[i].g]>d[g.e[i].s]+g.e[i].c)d[g.e[i].g]=-INF;
	}
}
//*/

int main(){
	readgraph();
	berumanfoodo(0);
	printf("%lld",d[g.vcnt-1]==-INF?-1:max(0,-d[g.vcnt-1]));
}

Measured memory_bytes: 380
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 1000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
typedef int64_t i64;

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

i64 N, K; 
string S;
cin >> N >> K >> S;

VI len;
if (S[0] == '0') len.push_back(0);
i64 l = 1;
rep(i, 1, N)
    if (S[i] == S[i - 1]) ++l;
    else {
        len.push_back(l);
        l = 1;
    }
len.push_back(l);
if (S[N-1] == '0') len.push_back(0);
int lens = len.size();

if (K >= lens / 2){
    cout << N << endl;
    return 0;
}

l = 0;
rep(i, 0, K * 2 + 1) l += len[i];
i64 maxi = l;
for(int i = 2; i < lens - K*2 + 1; i += 2) {
    l += len[K * 2 + i] + len[K * 2 + i - 1] - len[i - 1] - len[i - 2];
    maxi = max(maxi, l);
}

cout << maxi << endl;

}
// 書いて考える．場合分け
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

int main()
{
	int N;
	cin >> N;
	vector<int> P( N );
	for( int i = 0; i < N; i++ ) {
		cin >> P[i];
		P[i]--;
	}

	vector<int> Q( N );
	for( int i = 0; i < N; i++ ) {
		Q[ P[i] ] = i;
	}

	int k = 0;
	int kmax = 1;
	for( int i = 0; i < N - 1; i++ ) {
		if( Q[i] < Q[i + 1] ) {
			if( k ) k++;
			else k = 2;
		}
		else k = 0;
		kmax = max( kmax, k );
	}
	int ans = N - kmax;

	cout << ans << endl;
}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//bool f[100001];//1000000以下の素数を調べよう！
//rrep(i,2,100001){
  //      f[i]=false;
    //}
//rrep(i,2,100001){
  //      if(!f[i]){
    //        for(int j=i+i;j<=100000;j+=i){
      //          f[j]=true;
        //    }
        //}
    //}
    //for(int i=3;i<=100000;i+=2){
      //  if(!f[i]){
        //    c[i]++;
      //  }
   // }

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

//-------------------------↓↓↓↓↓↓----------------------------

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

       cin >> a >>b >>c;
       Yes(a+b>=c);
return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ll = long long;

int N, W;
ll w[110], v[110], INF = 1000000000000, dp[100100], V_SUM, ans = 0;;

int main(){
	cin >> N >> W;
	for (int i = 0; i < N; i++)cin >> w[i] >> v[i], V_SUM += v[i];
	for (int i = 0; i <= V_SUM; i++)dp[i] = INF;
	dp[0] = 0;
	for (int i = 0; i < N; i++){
		for (int j = V_SUM; j >= 0 && j >= v[i]; j--){
			dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
		}
	}
	for (int i = 0; i <= V_SUM; i++)ans = (dp[i] <= W ? i : ans);
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define B break
#define R return
#define pb push_back
using namespace std;

ll a[100010],b[100010];

int main()
{
 ll n;
 cin>>n;
 for(ll i=1;i<=n;i++)
 {
     cin>>a[i];
     b[a[i]]=i;
 }
 for(ll i=1;i<=n;i++)
 {
     cout<<b[i]<<' ';
 }
    return 0;
}



Measured memory_bytes: 2432
#include <iostream>
using namespace std;
bool t[10000000] = {false};
int main()
{
	int n, i, j;
	t[0] = true;
	for (i = 2; i * i <= 10000000; i++)
	{
		if (!t[i-1])
		{
			for (j = i+i; j <= 10000000; j+=i)
				t[j-1] = true;
		}
	}
	while (cin >> n, n)
	{
		for (; n >= 13; n--)
		{
			if (!t[n-9] && !t[n-7] && !t[n-3] && !t[n-1])
				break;
		}
		cout << n << endl;
	}
}

Measured memory_bytes: 0
def solve():
    ans = 0
    n=int(input())
    for i in range(1,n+1,2):
        div_list = []
        for j in range(1,int(i**0.5)+1):
            if i%j!=0:
                continue
            if i//j==j:
                div_list.append(j)
            else:
                div_list.append(i//j)
                div_list.append(j)
        if len(div_list)==8:
            ans+=1
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 9340
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node{
  int key; /*値とボンド*/
  Node *right, *left, *parent;
};

Node *root, *NIL;

Node *find(Node* u,int k){
  while(u!=NIL && k!= u->key){
    if(k < u->key) u=u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;

  z =(Node *)malloc(sizeof(Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else {
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root =z;
  } else{
    if(z->key < y->key){
      y->left =z;
    }else{
      y->right =z;
    }
  }
}

void Inorder(Node *u){
  if(u==NIL) return;
  Inorder(u->left);
  printf(" %d", u->key );
  Inorder(u->right);
}

void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d", u->key );
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  string com;

  scanf("%d",&n );
  for(i=0;i<n;i++){
    cin >> com;
    if(com[0]=='f'){
      scanf("%d", &x );
      Node *t=find(root,x);
      if(t!=NIL)printf("yes\n");
      else printf("no\n");
      continue;
    }
    if(com=="insert"){
      scanf("%d",&x );
      insert(x);
    } else if (com=="print"){
      Inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}


Measured memory_bytes: 21968
#include <iostream>
#include<bits/stdc++.h>
#define rep(k,i,n) for(int i=k;i<n;++i)
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin>>A>>B;
    if(A==B){
        cout<<0<<endl;
    }else if((A+B)%2==0){
        cout<<(A+B)/2<<endl;
    }else{
        cout<<"IMPOSSIBLE"<<endl;
    }
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


int x;

void solve()
{
    cin >> x;
    if(x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

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

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int N,M;
vector<int> p;

vector<int> runlen(const string &s) {
    vector<int> res;
    char c=s[0];
    int cnt=1;
    for(int i=1;i<s.size();i++) {
        if(c==s[i]) cnt++;
        else {
            res.pb(cnt);
            c=s[i];
            cnt=1;
        }
    }
    res.pb(cnt);
    return res;
}
void func(string &s, char c) {
    rep(i,M) {
        rep(j,p[i]) {
            s+=c;
        }
        if(c=='0') c='1';
        else c='0';
    }

}

int f(string s1, string s2) {
    // cout<<s1<<","<<s2<<endl;
    int res=0;
    rep(i,s1.size()) {
        if(s1[i]==s2[i]) continue;
        for(int k=i+1;k<s2.size();k++) {
            if(s1[i]==s2[k]) {
                // cout<<i<<","<<k<<endl;
                res+=k-i;
                swap(s2[i],s2[k]);
                break;
            }
        }
    }
    if(s1!=s2) return INF;
    return res;
}

int main() {
    string s;
    cin>>N>>M;
    rep(i,N) {
        char c;
        cin>>c;
        s+=c;
    }
    rep(i,M) {
        int x;
        cin>>x;
        p.pb(x);
    }
    string s0,s1;

    func(s0,'0');
    func(s1,'1');

    cout<<min(f(s,s0),f(s,s1))<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define SUM(x) accumulate(ALL(x), 0)
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000

int main()
{
  int N, K; cin >> N >> K;
  vector<int> A(N, 0);
  REP(i, K) {
    int d; cin >> d;
    vector<int> a(d);
    REP(j, d) {
      cin >> a.at(j);
    }
    REP(j, d) A.at(a.at(j) - 1)--;
  }


  int cnt = 0;
  REP(i, N) {
    if (A.at(i) == 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 3640
# include <cstdio>
# include <algorithm>
# include <cstring>
# include <cmath>
# include <climits>
# include <iostream>
# include <string>
# include <queue>
# include <vector>
# include <set>
# include <map>
# include <cstdlib>
# include <stack>
# include <ctime>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=100;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
	x*=f;
}

int n;
int ans;
int a[N];

int main()
{
	read(n);
	Rep(i,1,n)read(a[i]);
	Rep(i,1,n)
		Rep(j,i+1,n)
			ans+=a[i]*a[j];
	cout<<ans<<endl;
	return 0;	
}

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

const int maxn = 100010;
int a[maxn];

int main()
{
	int n;
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	bool flg = false;
	if (a[n] - a[1] > 1) {}
	else if (a[1] == a[n])
	{
		if (a[1] == n-1) flg = true;
		else if (a[1]*2<=n) flg = true;
	}
	else
	{
		int p = upper_bound(a+1,a+n+1,a[1]) - a;
		int x = p-1, y = n-x;
		if (a[n] >= x+1 && a[n] <= x+y/2) flg = true;
	}
	puts(flg ? "Yes" : "No");
	return 0;
}


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

#define fl(k, n) for(int i = k; i < n; i++)
#define flr(k, n) for(int i = n - 1; i >= k; i--)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define mp make_pair
#define ll long long

using namespace std;

int binary_search(vector<int> nums, int target_val){
  int begin = 0;
  int end = nums.size();
  int mid;

  while(begin <= end){
    mid = begin + (end - begin) / 2;
    if(nums[mid] == target_val)
      return mid;
    else if(nums[mid] <= target_val && nums[mid + 1] > target_val)
      return mid;
    else if(nums[mid] > target_val)
      end = mid - 1;
    else
      begin = mid + 1;
  }

  if(begin == 0)
    return -1;
  else 
    return nums.size();
}

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

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

  vi heights(n);
  fl(0, n)
    cin >> heights[i];

  vi costs(n);

  fl(1, n){
    int min_cost = INT_MAX;
    for(int j = 1; j <= min(i, k); j++){
      int costj = costs[i - j] + abs(heights[i] - heights[i - j]);
      min_cost = min(min_cost, costj);
    }
    costs[i] = min_cost;
  }

  cout << costs[n - 1] << "\n";
}

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

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

  vector<int> cd(n);

  for(int i=0; i<n; i++) {
    cin >> cd.at(i);
  }

  for(int i=0; i<n; i++) {
    
    int z = cd.at(i);
    
    for(int j=i+1; j<n; j++){
      
       if( z < cd.at(j) ) {
         int c = z;
         z = cd.at(j);
         cd.at(j) = c;
       }
      
    }
    
    cd.at(i) = z;
    
  }
  
  int a=0,b=0;
  for (int i=0; i<n; i++) {
    
    if ( i%2 == 0 ) a += cd.at(i);
    else b += cd.at(i);
  }
    cout << a - b << endl; 
}


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

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

  n %= 10;

  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
    cout << "hon\n";
    return 0;
  }

  if (n == 3) {
    cout << "bon\n";
    return 0;
  }

  cout << "pon\n";
}

Measured memory_bytes: 3636
let find_opt p l =
  try Some (List.find p l) with
  | Not_found -> None

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let ss = Scanf.scanf "%s\n" (fun s ->
    Array.init n (fun i ->
      match s.[i] with
      | 'o' -> 1
      | 'x' -> -1)) in
  let ss' =
    Array.to_list (Array.init (n - 2) (fun i -> ss.(i + 1))) in
  [[1; 1]; [1; -1]; [-1; 1]; [-1; -1]]
  |> List.map (fun init ->
      List.fold_left (fun ((t_n :: t_n_1 :: _) as ts) s ->
        s * t_n * t_n_1 :: ts) init ss'
      |> List.rev
      |> Array.of_list)
  |> find_opt (fun ts ->
      ts.(n - 2) * ts.(n - 1) * ts.(0) = ss.(n - 1)
      && ts.(n - 1) * ts.(0) * ts.(1) = ss.(0))
  |> (function
        | None -> "-1"
        | Some ts ->
            String.init n (fun i ->
              match ts.(i) with
              | 1 -> 'S'
              | -1 -> 'W'))
  |> print_endline


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

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const long long LINF = 1e18;

#define NMAX 100010

int main()
{
  int N; cin >> N;
  ll a[NMAX][3];
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }

  ll dp[NMAX][3] = {};

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (j != k) {
          chmax(dp[i+1][k], dp[i][j] + a[i][k]);
        }
      }
    }
  }

  cout << max({dp[N][0], dp[N][1], dp[N][2]}) << endl;
}

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

int main() {
    int n;
    cin >> n;
    auto scores = vector<int>(n);
    for (auto &s_i : scores)
        cin >> s_i;

    auto score_max = 0LL; // when A=n-1, score is 0

    // let c = a - b
    // some k (>=0) exists, a + k*c = n-1
    //   ( k*c < n-1 )
    for (int c = 1; c <= n - 1; c++) {
        auto score = 0LL;
        // when k=0, score is 0.
        for (int k = 1;; k++) {
            int a = (n - 1) - (k * c);
            int b = a - c;
            if (a <= 0 || b <= 0)
                break;

            auto newpos1 = k * c;
            auto newpos2 = (n - 1) - k * c;
            if (newpos2 % c == 0 && newpos2 <= newpos1)
                break;

            score += scores[newpos1] + scores[newpos2];
            score_max = max(score_max, score);
        }
    }

    cout << score_max;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;
int main()
{
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; ++i) cin >> X.at(i);
  int ma = *max_element(X.begin(),X.end());
  int mi = *min_element(X.begin(),X.end());
  int ans = pow(ma, 2) * N;
  for(int i=mi; i<=ma; ++i){
    int sum=0;
    for(int j=0; j<N; ++j){
      sum += pow((X.at(j)-i),2);
    }
    ans = min(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
L = []
for i in range(N):
    L.append(list(map(int, input().split())))
# print(L)

# その日までの幸福度の最大, ではデータが不足
# ∵翌日何の行動がとれるかわからないから
# dp[i][j]:i+1日目に行動jをしたときの幸福度最大値

dp=[[0,0,0] for i in range(N)]
for j in range(3):
    dp[0][j]=L[0][j]
# print(dp)

for i in range(1,N):
    for j in range(3):
        for k in range(3):
            if j != k:
                dp[i][j]=max(dp[i][j], dp[i-1][k] + L[i][j])
    # print(dp[i])
print(max(dp[N-1]))

Measured memory_bytes: 105256
a, b, k = map(int, input().split())

array1 = []
array2 = []

array1 = [i for i in range(1, a+1) if a % i == 0]
array2 = [i for i in range(1, b+1) if b % i == 0]

array = list(set(array1) & set(array2))
array.sort()
print(array[-k])

Measured memory_bytes: 3064
program main
  
   implicit none

   integer :: i,n 
   character(100) :: s
   
   read( *, * ) n
   read( *, * ) s

   if( s(1:int(n/2)) == s(int( n/2 )+1:n) ) then 
     print*, "Yes" 
   else
     print*, "No" 
   end if

end program main


Measured memory_bytes: 256
use strict;
use warnings;

sub main {
    my $i=0;
    my ($N,@A);
    while(<STDIN>){
        chomp;
        if($i==0){
            $N = $_;
        } elsif($i==1) {
            @A = split(/ /, $_);
        }
        $i++;
    }
    print solver($N,\@A);
}
main() unless caller;

sub solver {
    my ($N,$A) = @_;
    my @ans;
    for my $i(0..$N-1){
        $ans[$A->[$i]-1] = $i+1;
    }
    return join " ", @ans;
}

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

bool binarySearch(vector<int> L, int key){
    int left = 0;
    int right = L.size();
    int mid;
    while (left < right){
        mid = (left + right)/2;
        if(L.at(mid) == key){
            return true;
        }else if(L.at(mid) > key){
            right = mid;
        }else{
            left = mid + 1;
        }
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    vector<int> S(n);
    for(int i = 0;i<n;i++){
        cin >> S.at(i);
    }
    sort(S.begin(),S.end());
    int q;
    cin >> q;
    int ans = 0;
    int key;
    for(int i = 0;i<q;i++){
        cin >> key;
        if(binarySearch(S,key)) ans++;
    }
    cout << ans << endl;
}




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

int main(){
    int N;
    cin >> N;
    vector<vector<double>> XY(N);
    for(int i=0; i<N; i++){
        double x, y;
        cin >> x >> y;
        XY[i] = {atan2(x, y), x, y};
    }
    sort(XY.begin(), XY.end());
    double ans = 0;
    for(int i=0; i<N; i++) for(int n=0; n<=N; n++){
        double x = 0, y = 0;
        for(int j=i; j<i+n; j++){
            x += XY[j%N][1];
            y += XY[j%N][2];
        }
        ans = max(ans, sqrt(x*x + y*y));
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long int INF = 1LL << 60;

int N,K;
int x[110000];
int main(){
    cin >> N >> K;
    REP(i,N) cin >> x[i];

    long long ans = INF;
    REP(i,N){
        if(i + K > N) break;
        long long t = abs(x[i]);
        t += x[i + K - 1] - x[i];
        chmin(ans,t);
        t = abs(x[i + K -1]);
        t += x[i + K - 1] - x[i];
        chmin(ans,t);
    }
    cout << ans << endl;
}

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

void print_vec(vector<int> vec)
{
  cout << "[";
  for (int i = 0; i < vec.size(); i++)
  {
    cout << vec.at(i);
    if (i < vec.size() - 1)
    {
      cout << ", ";
    }
  }
  cout << "]...size: " << vec.size() << endl;
}

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

  int x = a / b;
  int y = a % b;
  double z = (double)a / b;

  printf("%d %d %lf\n", x, y, z);
}



Measured memory_bytes: 3216
N = int(input())
L = sorted(list(map(int, input().split())), reverse=True)

def aaa(arr): 
    n = len(arr) 
    arr.sort() 
    count = 0
    for i in range(0,n-2): 
        k = i + 2
        for j in range(i+1,n): 
            while (k < n and arr[i] + arr[j] > arr[k]): 
                k += 1
            if(k>j): 
                count += k - j - 1
  
    return count 

print(aaa(L))

Measured memory_bytes: 3188
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    readInteger()
    val colorCount = IntArray(9)
    val aList = readIntegerList()
    for (a in aList) {
        when (a) {
            in 1..399 -> colorCount[0]++
            in 400..799 -> colorCount[1]++
            in 800..1199 -> colorCount[2]++
            in 1200..1599 -> colorCount[3]++
            in 1600..1999 -> colorCount[4]++
            in 2000..2399 -> colorCount[5]++
            in 2400..2799 -> colorCount[6]++
            in 2800..3199 -> colorCount[7]++
            else -> colorCount[8]++
        }
    }
    var min = colorCount.dropLast(1).count { it > 0 }
    val max = min + colorCount[8]
    if (min == 0 && max > 0) {
        min = 1
    }
    out.println("$min $max")
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 40260
o,k = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp.chars

hp = 0
sw = true
s.inject do |i,j|
  if i == j
    hp += 1
  else
    if 0 < k
      if sw
        sw = false
      else
        sw = true
        k -= 1
        hp += 2
      end
    end
  end
  j
end
unless sw
  if 0 < k
    hp += 1
  end
end
print("#{hp}")

Measured memory_bytes: 6908
A = int(input())
import numpy as np
L = np.arange(1,A+1,2)
count = 0 
countA = 0
for i in L:
    count=0
    for t in range(i):
        count+=1 if i%t==0 else 0
    countA += 1 if count == 8 else 0
print(countA)

Measured memory_bytes: 21360
#include <bits/stdc++.h>
using namespace std;
#define ll          long long
#define vl          vector<ll>
#define vi          vector<int>
#define pi          pair<int,int>
#define pl          pair<ll,ll>
#define all(a)      a.begin(),a.end()
#define mem(a,x)    memset(a,x,sizeof(a))
#define pb          push_back
#define mp          make_pair
#define F           first
#define S           second
#define endl 		"\n"
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define fast_io     std::ios::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define trace(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1) {std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " : " << arg1;
	ZZ(comma, args...);
}

void solve() {
	vi a(5);
	int ans = 0;
	rep(i, 0, 5) {
		cin >> a[i];
		if (a[i] == 0)ans = i + 1;
	}
	cout << ans;
}
int main() {
	fast_io;
	int t = 1;
	// cin>>t;
	while (t--) {
		solve();
	}
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 3648
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#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>

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main() {
  vector<double> m;
  double n;

  while(cin >> n) m.PB(n);

  vector<double>::iterator max_it = max_element(m.begin(), m.end());
  vector<double>::iterator min_it = min_element(m.begin(), m.end());

  printf("%.1lf\n", (*max_it)-(*min_it));
}

Measured memory_bytes: 1256
#include<stdio.h>
int main()
{
	int N;
	int K;
	scanf("%d%d",&N,&K);
	int x[N];
	int sum=0;
	for(int i=0;i<N;i++) scanf("%d",&x[i]);
	for(int i=0;i<N;i++)
	{
		int num=x[i];
		if(num>(K-num))
		{
			sum+=K-num;
			continue;
		}
		sum+=num;
	}
	printf("%d",sum*2);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(void) {
	int a, b;

	cin >> a >> b;

	int sum = 0;

	for (int i = 0; i < 2; i++) {
		int max;
		if (a >= b) {
			max = a;
			a--;
		}
		else {
			max = b;
			b--;
		}
		sum += max;
	}

	cout << sum << endl;

	return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

const int MOD = 1e+9 + 7;

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

    // dp[i][j] = 数列の長さが i で和が j であるものの個数
    long long ans = 0;
    vector<vector<long long>> dp(S, vector<long long>(S+1, 0));
    dp[0][0] = 1;
    REP(i, S-1){
        ans += dp[i][S];
        ans %= MOD;
        // 累積和
        FOR(j, 1, S+1){
            dp[i][j] += dp[i][j-1];
            dp[i][j] %= MOD;
        }
        FOR(j, 3, S+1) dp[i+1][j] = dp[i][j-3];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 34588
#include<bits/stdc++.h>
#include<vector>
#include<map>
#include<set>
using namespace std;

#define mod 1000000007

#define ll long long
#define ff first
#define ss second
#define E endl;
#define PII pair<int, int>
#define PCI pair<char, int>
#define PLL pair<ll, ll>
#define O " "
#define ghur(i, n) for(int i = 0; i < n; i++)
#define pb(x) push_back(x);
#define i_n v.begin(), v.end()
#define dec_v(v) std::vector<int> v;
#define in(x) insert(x)
#define file()  freopen("input.text", "rt", stdin), freopen("out.txt", "wt", stdout);
#define inf INT_MAX
void cin_ar(int n, int ar[]) {for(int i = 0; i < n; i++) cin>>ar[i];}
void cin_ll(int n, ll ar[]) { for(int i = 0; i < n; i++) cin>>ar[i];}
void cin_v(int n, vector<int> v){int x; for(int i = 0; i < n; i++){cin>>x; v.pb(x);}}
bool cmp(int a, int b) {return a>b;}
bool cmp_pair(PII &a, PII &b){return a.ss<b.ss;}
int n, k;
int bs(int x1, int x2)
{
	return abs(2*x2 - x1) - k;
}

void solve()
{
  int n;
  cin>>n;
  ll ar[n];
  cin_ll(n, ar);

  ll cnt = 0;
  ll mx = ar[0];

  for(int i = 1; i < n; i++)
  {
  	if(ar[i] > mx)
  	{
  		mx = ar[i];

  	}
  	else {
  		cnt += mx - ar[i];
  	}
  }

  cout<<cnt<<endl;
}


void solve_2() {int t; cin>>t; while(t--) solve();}

int main()
{   
 	//file();
    
    solve();
    //solve_2();



    return 0;
} 

Measured memory_bytes: 5120