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

using namespace std;
int bubbleSort(int,int*);
void show(int,int*,int);

int main(void){
    int n,sw;
    int const MAX=100;
    int num[MAX];
    cin>>n;
    for(int i=0;i<n;++i){
        cin>>num[i];
    }
    sw = bubbleSort(n,num);
    show(n,num,sw);
    return 0;
}

int bubbleSort(int n, int* addr){
    int sw=0;
    for(int i=0;i<n-1;++i){
        for(int j=n-1;j>=i+1;--j){
            if(addr[j]<addr[j-1]){
                swap(addr[j],addr[j-1]);
                ++sw;
            }
        }
    }
    return sw;
}

void show(int n, int* addr, int sw){
    for(int i=0;i<n;++i){
        if(i) printf(" ");
        printf("%d",addr[i]);
    }
    printf("\n");
    printf("%d\n",sw);
}


Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <vector>
 
using namespace std;
typedef long long ll;


ll ans,mx,mn,sum;
int main(){
	string s,t,c;
	cin>>s>>t>>c;
	cout<<"A"<<t[0]<<"C";
}

Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split())) for _ in range(2)]
ans=i=j=0
if n==1:
  print(a[0][0]+a[1][0])
  exit()
for j in range(n):
  ans=max(ans, sum(a[0][:j])+sum(a[1][j-1:]))
print(ans)

Measured memory_bytes: 3060
# Volume5,0501
# Data Conversion

while line = $stdin.gets
	n = line.to_i
	break if n == 0

	table  = Hash.new
	answer = ""
	n.times {
		data = $stdin.gets.split(/\s/)
		table[ data[ 0 ] ] = data[ 1 ]
	}

	m = $stdin.gets.chomp.to_i
	m.times {
		c = $stdin.gets.chomp
		if table.key?( c )
			answer += table[ c ]
		else
			answer += c
		end
	}
	puts answer
end


Measured memory_bytes: 14140
n=int(input())
a=list(map(int,input().split()))
x=int(input())
b=list(map(int,input().split()))
from collections import Counter
c=Counter(a)
d=Counter(b)

for x,y in d.items():
    if y>c[x]:
        print('NO')
        exit()
print('YES')


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  bool can = false;

  for(int i=0; i<B; i++){
    if((A*i) % B == C){
      can = true;
    }
  }

  if(can)cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
S = input()
S = [S[i: i+2] for i in range(0, len(S), 2) ]

L, R = int(S[0]), int(S[1])


if  1 <= L <= 12 and 1 <= R <= 12:
  print('AMBIGUOUS')
elif 1 <= R <= 12:
  print('YYMM')
elif 1 <= L <= 12:
  print('MMYY')
else:
  print('NA')


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
const int MAXN=1e5+5,OO=0x3f3f3f3f;
typedef  long long ll;
vector<int>vc[MAXN]; int arr[MAXN];
int main(){
 int n,m,x,y; scanf("%d%d",&n,&m);
 for(int i=1;i<=n;i++)scanf("%d",arr+i);
 while(m--)
     scanf("%d%d",&x,&y),vc[x].push_back(y),vc[y].push_back(x);
 int ans=0; bool can;
 for(int i=1;i<=n;i++){
     can=1;
     for(auto j:vc[i])
         if(arr[j]>=arr[i]){can=0;break;}
     if(can)ans++;
 }
 printf("%d",ans);
}

Measured memory_bytes: 9332
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    int[] H;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
        H = new int[N];
        for (int i=0; i<N; i++) {
        	H[i] = sc.nextInt();
        }
    }
    
    //解答処理
    private int solve() {
        int count = 1; //1番目は確実に見れるので1
        int highest = H[0];
        
        for (int i=1; i<N; i++) {
        	if (H[i] >= highest) {
        		count++;
        		highest = H[i];
        	}
        }
        
        return count;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35580
n , x = [ int(i) for i in input().split()]

arr =[ 0 for _ in range(n+1)]
arr[1:] = [int(i) for i in input().split()]
for i in range(1,n+1):
	arr[i]+=arr[i-1]


su=0
for i in range(n+1):
	if ( arr[i] <= x):
		su+=1
print(su)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>

using namespace std;
using lli = long long int;


int main(void){
    int roop,stk,K;
    array <int,300000> N; 
    vector<int> M;
    cin >> roop >> K;
    for(int i=0;i<roop;i++){
        cin >> stk;
        N[stk]++;
    }
    for(int i=1;i<roop+10;i++){
        if(N[i] > 0){
            M.push_back(N[i]);
        }
    }
    sort(M.begin(),M.end());
    reverse(M.begin(),M.end());
    int count = 0;
    while(M.size() > K){
        count += *(M.end()-1);
        M.pop_back();
    }
    cout << count << endl;
    return 0;
}


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

int main() {
  string t;
  string s;
  cin >> s;
  cin >> t;
  bool joe = true;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      joe=false;
    }
  }
  if(joe==true){
    cout << "Yes";
  }else{
    cout << "No";
  }
	return 0;
}


Measured memory_bytes: 3604
n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0]
total = abs(a[1])
diff = [0]*n
for i in range(n):
    total += abs(a[i+2]-a[i+1])
    if a[i+2]<=a[i]<=a[i+1] or a[i+1]<=a[i]<=a[i+2]:
        diff[i] = 2*abs(a[i+1]-a[i])
    elif a[i]<=a[i+2]<=a[i+1] or a[i+1]<=a[i+2]<=a[i]:
        diff[i] = 2*abs(a[i+2]-a[i+1])
for i in diff:
    print(total-i)

Measured memory_bytes: 14172
#include <stdio.h>
#include <math.h>
#include <string.h>

int main(){
	int a[13][13], i, j, count, b[12], k, x, l, y;
	while(scanf("%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d%1d", &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], &b[7], &b[8], &b[9], &b[10], &b[11]) != EOF){
		for(i = 0; i < 13; i++){
			for(j = 0; j < 13; j++) a[i][j] = 0;
		}
		count = 0;
		a[1][1] = b[0];
		a[1][2] = b[1];
		a[1][3] = b[2];
		a[1][4] = b[3];
		a[1][5] = b[4];
		a[1][6] = b[5];
		a[1][7] = b[6];
		a[1][8] = b[7];
		a[1][9] = b[8];
		a[1][10] = b[9];
		a[1][11] = b[10];
		a[1][12] = b[11];
		for(i = 2; i < 13; i++){
			for(j = 1; j < 13; j++) scanf("%1d", &a[i][j]);
		}
		for(i = 1; i < 13; i++){
			for(j = 1; j < 13; j++){
				if(a[i][j] == 1){
					a[i][j]++;
					if(a[i - 1][j] != 2 && a[i][j - 1] != 2){
						x = 0;
						for(k = j + 1; k < 13; k++){
							if(a[i - 1][k] == 2){
								x = 1;
								break;
							}
						}
						if(x = 0) k = 0;
						y = 0;
						x = 1;
						for(l = j + 1; l <= k; l++){
							if(a[i][l] != 1){
								y = 1;
								break;
							}
						}
						if(y == 1) x = 0;
						if(x == 0) count++;
					}
				}
			}
		}
		printf("%d\n", count);
	}
	return 0;
}

Measured memory_bytes: 596
ary = Array.new
while line = $stdin.gets
ary << line.chomp.split
end
ary.delete_at(0)
ary.map!{|item| item[0].to_i }
ary.sort!{|a,b| b <=> a}
ary[0] = ary[0]/2
print ary.inject(:+)

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

int main() {
    int a, AC=0, WA=0, TLE=0, RE=0;
    cin >> a;

    vector<string> vec(a);
    for(int i=0; i < a; i++){
        cin >> vec.at(i);
        if(vec.at(i) == "AC"){
            AC += 1;
        }else if(vec.at(i) == "WA"){
            WA += 1;
        }else if(vec.at(i) == "TLE"){
            TLE += 1;
        }else if(vec.at(i) == "RE"){
            RE += 1;
        }
    }
cout << "AC x " << AC <<endl;
cout << "WA x " << WA <<endl;
cout << "TLE x " << TLE <<endl;
cout << "RE x " << RE << endl;

}


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

class Class1
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        int acNum = 0;
        int waNum = 0;
        int tleNum = 0;
        int reNum = 0;

        for (int i = 1; i <= N; i++)
        {
            var judge = Console.ReadLine();
            if (judge.StartsWith("A"))
            {
                acNum++;
                continue;
            }

            if (judge.StartsWith("W"))
            {
                waNum++;
                continue;
            }

            if (judge.StartsWith("T"))
            {
                tleNum++;
                continue;
            }

            if (judge.StartsWith("R"))
            {
                reNum++;
                continue;
            }
        }


        Console.WriteLine($"AC x {acNum}");
        Console.WriteLine($"WA x {waNum}");
        Console.WriteLine($"TLE x {tleNum}");
        Console.WriteLine($"RE x {reNum}");
    }
}

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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0 ) {
    cout << "Possible" << endl;
  }
  else {
    cout << "Impossible" << endl;
  }
return 0;
}

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

const ll MOD = 1e9 + 7;
const ll N_MAX = 1e5 + 10;

ll N, C;
ll glid[501][501], discomfort[31][31], color_dist[3][31], cost[3][31];


void solve(){

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

  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < N; j++){
      color_dist[(i + j)%3][glid[i][j]]++;
    }
  }

  for(ll i = 0; i < 3; i++){
    for(ll j = 0; j < C; j++){
      for(ll k = 0; k < C; k++){
        cost[i][j] += color_dist[i][k] * discomfort[k][j];
      }
    }
  }

  ll ans = 1e18;

  for(ll i = 0; i < C; i++){
    for(ll j = 0; j < C; j++){
      if(j == i) continue;
      for(ll k = 0; k < C; k++){
        if(k == i || k == j) continue;

        ans = min(ans, cost[0][i] + cost[1][j] + cost[2][k]);
        
      }
    }
  }

  cout << ans << endl;
}


int main() {

  memset(color_dist, 0, sizeof(color_dist));
  memset(cost, 0, sizeof(cost));

  cin >> N >> C;

  for(ll i = 0; i < C; i++){
    for(ll j = 0; j < C; j++){
      cin >> discomfort[i][j];
    }
  }

  for(ll i = 0; i < N; i++){
    for(ll j = 0; j < N; j++){
      cin >> glid[i][j];
      glid[i][j]--;
    }
  }

  solve();
}

Measured memory_bytes: 2176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      StringBuilder cards = new StringBuilder();
      int sTimes = 0;
      int cuts = 0;

      while(true){

        if( (line = br.readLine()).equals("-") ) break;

        cards.append(line);
        sTimes = Integer.parseInt(br.readLine());

        for ( int i = 0; i < sTimes; i++ ) {
          cuts = Integer.parseInt(br.readLine());
          cards.append(cards.substring(0, cuts));
          cards.delete(0,cuts);
        }

        System.out.println(cards);

        cards.setLength(0);
      }
    }
  }
}


Measured memory_bytes: 24164
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

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

    std::vector<int> A1(N);
    std::vector<int> A2(N);
    for (int& a1 : A1) {
        std::cin >> a1;
    }
    for (int& a2 : A2) {
        std::cin >> a2;
    }

    int max_candies = 0;
    for (int i = 0; i < N; i ++) {
        int upper_sum = std::accumulate(A1.begin(), A1.begin() + i + 1, 0);
        int lower_sum = std::accumulate(A2.begin() + i, A2.end(), 0);
        max_candies = std::max(upper_sum + lower_sum, max_candies);
    }
    std::cout << max_candies << std::endl;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, map) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, M; cin >> N >> M;
    if(M <= 2 * N){
        cout << M / 2 << endstr;
    }
    else{
        ll ret = N;
        M = M - 2 * N;
        if(M > 0) ret += M / 4;
        cout << ret << endstr;
    }
    return 0;
}


Measured memory_bytes: 256
import math
def main():
    N, M = map(int, input().split())
    l = [int(_) for _ in input().split()]
    summer_vacation_day_count = sum(l)
    if summer_vacation_day_count <= N:
        out = N - summer_vacation_day_count
    else:
        out = -1
    print(out)
main()

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

struct rec {
  int diag, height, width;
  rec(int d, int h, int w) {
    diag = d;
    height = h;
    width = w;
  }

  bool operator < (const rec& rrec) {
    if (diag == rrec.diag) return height < rrec.height;

    return diag < rrec.diag;
  }

  bool operator == (const rec& rrec) {
    return diag==rrec.diag && height==rrec.height && width==rrec.width;
  }

};

int main(void) {
  vector<rec> recs;
  for (int i = 1; i <= 150; i++) {
    for (int j = i+1; j <= 150; j++) {
      recs.push_back(rec(i*i+j*j, i, j));
    }
  }
  sort(recs.begin(), recs.end());

  int h, w;
  while (cin >> h >> w, h||w) {
    int d = h*h+w*w;
    auto iter = find(recs.begin(), recs.end(), rec(d, h, w));
    iter++;
    cout << (*iter).height << " " << (*iter).width << endl;
  }

  return 0;
}

Measured memory_bytes: 3232
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>


using namespace std;

int main()
{
  char c;
  while(true)
  {
    c = getchar();
    if(c == '\n' || c == '\r')
      break;
    if(c >= 'A' && c <= 'Z')
      c = c - 'A' + 'a';
    else if(c >= 'a' && c <= 'z')
      c = c - 'a' + 'A';
    cout << c;
  }
  cout << endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  string s;
  int stp = 0, out = 0, run = 0, ans = 0;

  while(stp < n * 3){
    cin >> s;
    if(s == "OUT"){
      out++;
      stp++;
    }
    else if(s == "HIT"){
      if(run == 3) ans++;
      else run++;
    }
    else{
      ans += run + 1;
      run = 0;
    }
    if(out == 3){
      cout << ans << endl;
      out = 0;
      run = 0;
      ans = 0;
    }
  }
}



Measured memory_bytes: 3072
import qualified Data.Vector as V
import Data.List
f n k=if V.length n == 3 then (if (n V.! 1)-(n V.! 0)<(n V.! 2)-(n V.! 1) then 2*(n V.! 2)-((n V.! 0)+(n V.! 1))
  else (-2)*(n V.! 0)+((n V.! 1)+(n V.! 2))) else
 ((if k==0 then (-2)*(V.head n) else 2*(V.last n))+(if k==0 then (f (V.tail n) 1) else (f (V.init n) 0)))
g n k=if V.length n == 2 then (n V.! 1)-(n V.! 0)
 else ((if k==0 then (-2)*(V.head n) else 2*(V.last n))+(if k==0 then (g (V.tail n) 1) else (g (V.init n) 0)))
main=getContents>>=print.(\n ->if V.length n == 2 then abs(V.head n-(V.head.V.tail) n) else
  if mod (V.length n) 2 == 1 then f n 1 else g n 1).V.fromList.sort.map read.tail.lines

Measured memory_bytes: 17788
S = raw_input() + "end!"

def solve():
    pos = 0
    while True:
        plus_one_flag = 0
        if S[pos:pos+5] == "dream":
            pos += 5
        elif S[pos:pos+5] == "erase":
            pos += 4
            plus_one_flag = 1
        elif S[pos:pos+6] == "end!":
            return True
        else:
            return False

        if S[pos:pos+4] == "erer" or S[pos:pos+4] == "erdr" or S[pos:pos+4] == "eren":
            pos += 2
            plus_one_flag = 0
        pos += plus_one_flag

print "YES" if solve() else "NO"


Measured memory_bytes: 2692
from collections import deque


def cal_distance(a_list, b_list):
    total = 0
    for i in range(len(a_list)):
        total += (a_list[i] - b_list[i]) ** 2
    
    return total**0.5


if __name__ == "__main__":
    N, D = map(int, input().split())

    X = deque()
    for _ in range(N):
        temp = list(map(int, input().split()))
        X.append(temp)

    total = 0
    while X:
        x = X.popleft()
        for temp in X:
            distance = cal_distance(x, temp)
            if distance.is_integer():
                total += 1
                
    print(total)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll a,b;
    cin >> a >> b;
    if(a<=b)cout <<"unsafe";else cout <<"safe";
    return 0;
}


Measured memory_bytes: 3648
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	if (N == 1)cout << "Hello World\n";
	else {
		cin >> M >> K;
		cout << M + K << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
const ll MOD=1000000007;

int main(){
    ll A,B,C,K;
    cin >> A >> B >> C >> K;
    if (K%2==0){
        cout << A-B << endl;
    }
    else {
        cout << B-A << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
int N, D;
vector <int> points[25];
 
bool check(int a, int b) {
  long long eh = 0;
  for(int i = 0; i < D; i++) {
    eh += (points[a][i] - points[b][i]) * (points[a][i] - points[b][i]);
  }
  long long x = sqrt(eh);
  return x * x == eh;
}
 
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> D;
  for(int i = 0; i < N; i++) {
    points[i].resize(D);
    for(int j = 0; j < D; j++)
      cin >> points[i][j];
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    for(int j = i + 1; j < N; j++) {
      ans += check(i, j);
    }
  }
  cout << ans;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

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

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		w = scanner.nextInt();
		h = scanner.nextInt();
		map = new boolean[h + 2][w + 2];
		v = new boolean[h + 2][w + 2];
		for (int i = 1; i <= h; i++)
			for (int j = 1; j <= w; j++)
				map[i][j] = scanner.nextInt() == 1;
		System.out.println(slove(0, 0));
	}

	private int slove(int y, int x) {
		v[y][x] = true;
		int res = 0;
		for (int i = 0; i < 6; i++) {
			int ny = y + dy[i];
			int nx = x + (y % 2 == 1 ? dx1[i] : dx2[i]);
			if (!isOK(ny, nx))
				continue;
			if (map[ny][nx]) {
				res++;
				continue;
			}
			if (v[ny][nx])
				continue;
			res += slove(ny, nx);
		}
		return res;
	}

	private boolean isOK(int ny, int nx) {
		if (0 <= ny && ny <= h + 1 && 0 <= nx && nx <= w + 1)
			return true;
		return false;
	}

	int h, w;
	boolean[][] map;
	boolean[][] v;
	int[] dy = { -1, -1, 0, 0, 1, 1 };
	int[] dx1 = { 0, 1, -1, 1, 0, 1 };
	int[] dx2 = { -1, 0, -1, 1, -1, 0 };
}

Measured memory_bytes: 34688
use io::*;

fn main() {
    let input = read_string();
    let mut sc = Scanner::new(&input);
    let n: usize = sc.next();
    let v: Vec<usize> = sc.next_vec(n);
    let (even,odd): (Vec<(usize,usize)>,Vec<(usize,usize)>) = (0..n).zip(v.into_iter()).partition(|&x| x.0 % 2 == 0);
    let (_, mut ev): (Vec<usize>,Vec<usize>) = even.into_iter().unzip();
    let (_, mut ov): (Vec<usize>,Vec<usize>) = odd.into_iter().unzip();
    let mut ans: Vec<usize> = Vec::new();
    if n % 2 == 0 {
        ov.reverse();
        ans.append(&mut ov);
        ans.append(&mut ev);
    } else {
        ev.reverse();
        ans.append(&mut ev);
        ans.append(&mut ov);
    }
    print!("{}", ans[0]);
    for x in ans[1..].iter() {
        print!(" {}", x);
    }
    print!("\n");
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }

        pub fn next_mat<T: FromStr>(&mut self, w: usize, h: usize) -> Vec<Vec<T>> {
            (0..h).map(|_| self.next_vec(w)).collect()
        }

        pub fn next_vec_char(&mut self) -> Vec<char> {
            self.next::<String>().chars().collect()
        }

        pub fn next_mat_char(&mut self, n: usize) -> Vec<Vec<char>> {
            (0..n).map(|_| self.next_vec_char()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 14588
#include <stdio.h>

int main(void)
{
 long long int n,k,s,p;
  
  scanf("%lld %lld", &n, &k);
  
  s = n%k;
  p = k-s;
  
  if(s<p)
    printf("%lld", s);
  else
    printf("%lld", p);
    
  return 0;
  
}


Measured memory_bytes: 1724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String S = scan.next() ;

		// Sの長さ
		int N = S.length();

		String left = S.substring(0, (N-1)/2);
		String right = S.substring((N+3)/2-1, N);


		if(left.equals(right)){
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int a[3];
	rep(i, 3) cin >> a[i];

	sort(a, a + 3);
	if(a[0] == a[1]){
		cout << a[2] << endl;
	}else{
		cout << a[0] << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int k; cin >> k;
    if(k<10) cout << k << endl;
    queue<ll> q;
    int cnt=0;
    for(int i=1;i<=9;i++) q.push(i);
    cnt+=9;
    while(cnt<k){
        ll d=q.front(); q.pop();
        int a=d%10;
        if(a!=0){
            q.push(10*d+a-1);
            cnt++;
            if(cnt==k){
                cout <<10*d+a-1<<endl;
                return 0;
            }
        }
        q.push(10*d+a);
        cnt++;
        if(cnt==k){
            cout <<10*d+a<<endl;
            return 0;
        }
        if(a!=9){
            q.push(10*d+a+1);
            cnt++;
            if(cnt==k){
                cout <<10*d+a+1<<endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 768
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <map>
using namespace std;

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

int main(){
	int a, b;
	cin >> a >> b;
	if(a >= 13){
		cout << b << endl;
	}
	else if(a >= 6){
		cout << b/2 << endl;
	}
	else{
		cout << 0 << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define Nitroboost  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int 
const int mod=1e9+7;
const int N=2e6+5;

int h[N];

int main()
    {
        Nitroboost;
        #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        #endif

        int n,f;
        cin>>n;
        int g=0;
        for(int i=0;i<n;i++)
        {
            int x;
            cin>>x;
            h[x]=1;
            g=__gcd(x,g);
        }

        if(g!=1)
        {
            cout<<"not coprime";
        }
        else
        {
            int flag=0;
            for(int i=2;i<=1000000;i++)
            {
                int cnt=0;
                for(int j=1;j*i<=1000000;j++)
                    if(h[j*i]>=1){
                        cnt++;
                        //cout<<j<<" ";
                    }

                if(cnt>=2)
                {
                    flag=1;
                    break;
                }
            }


            if(flag==0)
                cout<<"pairwise coprime";
            else
                cout<<"setwise coprime";

        }
    }


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

int dp[25000];

int main(){
    memset(dp, 0x3f, sizeof(dp));
    dp[0] = 0;
    int h, n;
    cin >> h >> n;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        for(int j = a; j < 24000; j++){
            if(dp[j-a] < 1e9)   dp[j] = min(dp[j], dp[j-a]+b);
        }
    }
    int ret = 1<<30;
    for(int j = h; j <= 22000; j++) ret = min(ret, dp[j]);
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 384
package main

import (
	"fmt"
	"io"
	"os"
	"runtime"
)

func run(input io.Reader, output io.Writer) int {
	var s string
	fmt.Scanf("%s\n", &s)
	var q int
	fmt.Scanf("%d\n", &q)

	head := true
	left := make([]byte, 0)
	right := make([]byte, 0)
	for i := 0; i < q; i++ {
		var t int
		fmt.Scanf("%d", &t)

		if t == 1 {
			head = !head
			if runtime.GOOS == "windows" {
				fmt.Scanf("\n")
			}
		} else {
			var f int
			var c byte
			fmt.Scanf("%d %c\n", &f, &c)
			if (head && f == 1) || (!head && f == 2) {
				left = append(left, c)
			} else {
				right = append(right, c)
			}
		}
	}

	if head {
		for i := len(left) - 1; i >= 0; i-- {
			fmt.Printf("%c", left[i])
		}
		fmt.Print(s)
		for i := 0; i < len(right); i++ {
			fmt.Printf("%c", right[i])
		}
		fmt.Println()
	} else {
		for i := len(right) - 1; i >= 0; i-- {
			fmt.Printf("%c", right[i])
		}
		for i := len(s) - 1; i >= 0; i-- {
			fmt.Printf("%c", s[i])
		}
		for i := 0; i < len(left); i++ {
			fmt.Printf("%c", left[i])
		}
		fmt.Println()
	}
	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int [] a=new int [2*n];
		int ans=0;
		for(int i=0;i<2*n;i++)
		{
			a[i]=in.nextInt();
		}
		Arrays.sort(a);
		for(int i=0;i<2*n;i=i+2)
		{
			ans=ans+a[i];
		}
		System.out.println(ans);
	}
}
	

Measured memory_bytes: 23124
using System;
using System.Linq;
class Program{
    static void Main(){
            int t = int.Parse(Console.ReadLine());
            for (int j = 0 ;j < t ;j++){
                int[] nk = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
                int n,k;
                n = nk[0];
                k = nk[1];
                int[] x = Console.ReadLine().Split(' ').Select(s=>int.Parse(s)).ToArray();
                if (n == 1){
                    Console.WriteLine(0);
                }
                else {
                    int[] d = new int[n - 1];
                    for (int i = 0 ;i < n - 1 ;i++)
                        d[i] = x[i + 1] - x[i];
                    Array.Sort(d);
                    Array.Reverse(d);
                    long ans = d.Sum();
                    int elim = (n > k) ? k - 1 : n - 1;
                    for (int i = 0 ;i < elim ;i++)
                        ans -= d[i];
                    Console.WriteLine(ans);
                }
            }
    }
}


Measured memory_bytes: 22304
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  double a, b; cin >> a>> b;
  int ans = 1;
  b-=a;
  a--;
  cout << ans + ceil(b/a) << endl;
  return 0;
}

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

int main() {
	long long int n;
	cin >> n;
	long long int ans = 10000000000000;
	for(int i = 1; 1000001 > i; i++){
		if(n%i == 0){
			ans = min(n/i + i - 2, ans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
// using namespace atcoder;

struct edge {
    int to;
    ll cost;
};


const ll INF = 1e18;

typedef pair<ll, int> P;  // first: 最短距離, second: 頂点番号

vector<vector<edge> > G; // 隣接リスト表現
vector<ll> d;

ll dijkstra(int a, int b) {
    d.assign(G.size(), INF);

    d[a] = 0;

    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, a));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : G[v]) { 
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }

    ll ans = d[b];
    return ans;
}


void Main()
{
    ll n;
    cin >> n;
    vector<vector<ll> > A(n, vector<ll>(n));
    rep(i, n) rep(j, n) cin >> A[i][j];

    G.assign(n, vector<edge>());

    typedef pair<ll, ll> P;
    vector<P> ei;

    for (ll i = 0; i < n - 1; i++) {
        for (ll j = i + 1; j < n; j++) {
            ei.push_back(P(A[i][j], n * i + j));
        }
    }
    sort(all(ei));

    ll res = 0;
    for (auto e: ei) {
        ll i = e.second / n;
        ll j = e.second % n;
        ll cost = e.first;
        ll dist = dijkstra(i, j);
        if (dist < cost) {
            put(-1);
            return;
        }
        if (dist > cost) {
            G[i].push_back(edge{ j, cost });
            G[j].push_back(edge{ i, cost });
            res += cost;
        }
    }

    put(res);
}

signed main(){ Main();return 0;}

Measured memory_bytes: 5024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
char str[N];
int da[N][2];
int main()
{
    scanf("%s",str);
    int len=strlen(str);
    for(int i=0;i<len;i++){
        da[i][0]=1;
        da[i][1]=0;
    }
    for(int i=0;i<len;i++){
        if(str[i]=='R'){
            da[i+1][1]+=da[i][0];
            da[i+1][0]+=da[i][1];
            da[i][0]=0;
            da[i][1]=0;
        }
        else{
            da[i-1][0]+=da[i][1];
            da[i][1]=0;
        }
    }
    for(int i=len-1;i>=0;i--){
        if(str[i]=='L'){
            da[i-1][1]+=da[i][0];
            da[i-1][0]+=da[i][1];
            da[i][0]=0;
            da[i][1]=0;
        }
        else{
            da[i+1][0]+=da[i][1];
            da[i][1]=0;
        }
    }
    for(int i=0;i<len;i++){
        cout<<da[i][0]+da[i][1];
        if(i!=len-1)cout<<" ";
    }
    return 0;
}


Measured memory_bytes: 1280
import java.io.FileNotFoundException;
import java.util.Scanner;

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

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();
		int ans = 1;
		int D = 0;
		for(int i=0;i<N;i++) {
			D += sc.nextInt();
			if(D<=X) {
				ans++;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23508
#include<stdio.h>
#include <string.h>

#define M 1046527
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){

    long long key,i,h;
    key = getKey(str);
    for(i=0 ;; i++)
    {
      h = (h1(key) + i * h2(key)) % M;
      if(strcmp(H[h],str)==0) return 1;
      else if(strlen(H[h])==0) return 0;
    }
    return 0;
}

int insert(char str[]){

    long long key,i,h;
    key = getKey(str);
    for(i=0 ;; i++)
    {
      h=(h1(key)+i*h2(key))%M;
      if(strcmp(H[h],str)==0) return 1;
      else if(strlen(H[h])==0)
      {
        strcpy(H[h],str);
        return 0;
      }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';

    scanf("%d", &n);

    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);

	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 16100
#include<bits/stdc++.h>
using namespace std;
#define INF 10000000000000000LL
long long p[200009];

int main(){
  int n;
  long long sum=0;
  cin>>n;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    p[i]=p[i-1]+a;
    sum+=a;
  }
  long long ans=INF;
  for(int i=1;i<n;i++){
    ans=min(ans,llabs(sum-p[i]*2));
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
    int n,k,x,y,tot;
    scanf("%d %d %d %d", &n, &k, &x, &y);
    if(n>k)
    {
        tot = ((k*x) + (n-k)*y);
        printf("%d\n", tot);
    }
    else
    {
        tot = n * x;
        printf("%d\n", tot);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    int n, k;
    cin >> n >> k;
    vector<int> dp(k+1, 0), pre(k+1, 0);
    // dp[0] = 1;
    for(int j = 0; j <= k; j++) pre[j] = 1;

    for(int j = 0; j < n; j++){
        int X;
        cin >> X;
        vector<int> cur(k+1, 0);

        for(int i = 0; i <= k; i++) {
            // for(int x = 0; x <= X; x ++){
            //     if(i >= x) cur[i] = (cur[i] + dp[i - x]) % mod;
            // }
            int l = max(i - X, 0), r = i;
            cur[i] = (pre[r] - (l > 0? pre[l-1] : 0) + mod) % mod;
        }
        pre[0] = cur[0];
        for(int j = 1; j <= k; j++) pre[j] = (pre[j-1] + cur[j]) % mod;
    }
    cout << (pre[k] - pre[k-1] + mod) % mod;
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
template < typename T > std::string to_string( const T& n ){
	std::ostringstream stm ;
	stm << n ;
	return stm.str() ;
}


int main(void){
	int n,m,l;
	cin >> n>>m>>l;
	int A[n][m];
	int B[m][l];
	long long C[n][l];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cin >> A[i][j];
		}
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < l; j++){
			cin >> B[i][j];
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			long long tmp = 0;
			for(int k = 0; k < m; k++){
				tmp += A[i][k]*B[k][j];
			}
			C[i][j] = tmp;
		}
	}
	for(int i = 0; i < n; i++){
		for(int j = 0; j < l; j++){
			cout << C[i][j];
			if(j != l-1)cout << " ";
			else cout <<"\n";
		}
	}
	
	return 0;
}


Measured memory_bytes: 3240
#include <cstdio>

#include <cstring>

#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cassert>

using namespace std;

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

int N;
bool cached[301][301][301];
double memo[301][301][301];
double E(int n3, int n2, int n1, int n0 = 0) {
   if (n3+n2+n1 == 0)
      return 0.0;

   if (!cached[n3][n2][n1]) {
      double res = 0.0;
      if (n3 > 0)
         res += (1 + E(n3-1, n2+1, n1, n0)) * n3 * 1.0 / N;
      if (n2 > 0)
         res += (1 + E(n3, n2-1, n1+1, n0)) * n2 * 1.0 / N;
      if (n1 > 0)
         res += (1 + E(n3, n2, n1-1, n0+1)) * n1 * 1.0 / N;

      if (n0 > 0)
         res = (res + n0 * 1.0 / N) * N * 1.0 / (N - n0);

      cached[n3][n2][n1] = true;
      memo[n3][n2][n1] = res;
   }
   return memo[n3][n2][n1];
}

int main(int argc, char* argv[]) {
   scanf("%d", &N);
   VI A(N);
   REP(i, N)
      scanf("%d", &A[i]);

   int n3 = 0, n2 = 0, n1 = 0;
   for (int x : A) {
      switch (x) {
         case 3:
            ++n3;
            break;
         case 2:
            ++n2;
            break;
         case 1:
            ++n1;
            break;
         default:
            assert(false);
      }
   }

   double res = E(n3, n2, n1);
   printf("%.10f\n", res);

   return 0;
}


Measured memory_bytes: 239872
import java.util.Scanner;

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

			int n = sc.nextInt();
			
			double[] a = new double[n];
			for(int i = 0 ; i < n ; i++ ) {
				a[i] = sc.nextDouble();
			}
			
			double base = 0;
			for(int i = 0 ; i < n ; i++ ) {
				base += 1f/a[i];
			}
			
			double answer = 1f / base;
			System.out.println(answer);
		}
	}
}


Measured memory_bytes: 22228
n=int(input())
cnt=0
flag=1
for k in range(n):
    i,j= list(map(int, input().split()))
    if i==j:
        cnt+=1
    elif i!=j and cnt!=0:
        cnt=0
    if cnt>2:
        flag=0
if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int mod=1000000007;
const long long int INF=99999999999999999;

string str;
long long int n,h,k,m,a,b,sum=0,res=0,p[200005];
long long int deq[500005],minmin[200005],maxmax[200005];
long long int s,t,fin[200005]={};
int main() {
	cout << fixed << setprecision(10);
	cin>>n>>k;
	for(int i=0;i<n;i++){
		cin>>p[i];
	}
	s=0;
	t=0;
	for(int i=0;i<n;i++){
		while(p[deq[t-1]]>=p[i]&&s<t){
			t--;
		}
		deq[t++]=i;
		if(i-k+2>=0){
			minmin[i-k+2]=p[deq[s]];
		}
		if(deq[s]==i-k+2){
			s++;
		}
	}
	s=0;
	t=0;
	for(int i=0;i<n;i++){
		while(p[deq[t-1]]<=p[i]&&s<t){
			t--;
		}
		deq[t++]=i;
		if(i-k+2>=0){
			maxmax[i-k+2]=p[deq[s]];
		}
		if(deq[s]==i-k+2){
			s++;
		}
	}
	res=n-k+1;
	for(int i=1;i<=n-k;i++){
		if(minmin[i]>=p[i-1]&&maxmax[i]<=p[i+k-1]){
			res--;
		}
	}
	for(int i=0;i<=n-k;i++){
		//cout<<minmin[i]<<" "<<maxmax[i]<<endl;
	}

	
	long long int cou=1,kaburi=0,memo=1;
	p[n]=-INF;
	for(int i=0;i<=n;i++){
		if(p[i]<p[i+1]){
			cou++;
		}else{
			
			if(cou>k-1){kaburi++;}
			cou=1;
		}
	}
	
	kaburi=max(1LL,kaburi);
	//cout<<kaburi<<endl;
	cout<<res-kaburi+1<<endl;
} 


Measured memory_bytes: 8448
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stdint.h>

int64_t left[100005];
int64_t right[100005];

int main(){
  int64_t N;
  scanf("%ld",&N);
  for(int64_t i=0;i<N;i++){
    scanf("%ld %ld",&left[i],&right[i]);
  }
  std::sort(left,left+N+1);
  std::reverse(left,left+N+1);
  std::sort(right,right+N+1);
  int64_t sum=0;
  for(int64_t i=0;i<=N;i++){
    if(left[i]>right[i]){
      sum+=2*(left[i]-right[i]);
    }
  }
  printf("%ld\n",sum);
  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	int sx, sy, tx, ty;
	int x1, x2, y1, y2;

	cin >> sx >> sy >> tx >> ty;

	x1 = tx - sx;
	y1 = ty - sy;

	for (int i = 0; i < y1; i++) {
		cout << "U";

	}
	for (int i = 0; i < x1; i++) {
		cout << "R";

	}
	for (int i = 0; i < y1; i++) {
		cout << "D";

	}
	for (int i = 0; i < x1; i++) {
		cout << "L";

	}

	cout << "L";

	for (int i = 0; i < y1 + 1; i++) {
		cout << "U";

	}
	for (int i = 0; i < x1 + 1; i++) {
		cout << "R";

	}
	cout << "D";
	cout << "R";
	for (int i = 0; i < y1 + 1; i++) {
		cout << "D";

	}
	for (int i = 0; i < x1 + 1; i++) {
		cout << "L";

	}
	cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
res = -float('inf')
n=int(input())
s=input()
for i in range(1,n):
    tmp = 0
    x=s[:i]
    y=s[i:]
    for c in [chr(i) for i in range(97,97+26)]:
        tmp += (c in x) and (c in y)
    res = max(res,tmp)
print(res)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
 
using namespace std;
 
int main()
{
	long long a;
	string s;
	cin >> a >> s;
	
	long long b = 0;
	b += (s[0] - '0') * 100;
	b += (s[2] - '0') * 10;
	b += (s[3] - '0');
	long long ans = a * b;
	cout << ans / 100 << endl;
 
	return 0;
}

Measured memory_bytes: 3624
n, m = map(int, input().split())
cs = [[float('inf')] * n for _ in range(n)]
ns = [[0] * n for _ in range(n)]
for i in range(n):
    cs[i][i] = 0
for _ in range(m):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    cs[a][b] = cs[b][a] = c
    ns[a][b] = b
    ns[b][a] = a
for k in range(n):
    for i in range(n):
        for j in range(n):
            s = cs[i][k] + cs[k][j]
            if s < cs[i][j]:
                cs[i][j] = s
                ns[i][j] = ns[i][k]
used = set()
for i in range(n):
    for j in range(i + 1, n):
        path = [i]
        while path[-1] != j:
            s = path[-1]
            t = ns[s][j]
            path.append(t)
            used.add(tuple(sorted([s, t])))
print(m - len(used))

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MAXN 100010
int a[MAXN],n,cnt,m,fa[MAXN],visit[MAXN],ans;
inline int read(){
    int f(1),x(0);
    char ch(getchar());
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int find(int x){
    while(x!=fa[x]) x=fa[x]=fa[fa[x]];
    return x;
}
int main(){
    n=read();m=read();
    for(register int i(1);i<=n;++i) fa[i]=i;
    for(register int i(1);i<=m;++i){
        int x(read()),y(read()),z(read());
        //if(find(x)!=find(y)) 
        fa[find(x)]=find(y);
    }
    for(register int i(1);i<=n;++i)
        if(!visit[find(i)]) ans++,visit[find(i)]=1;
    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 1024
n = int(input())
def solve(s):
	if int(s)>n:
		return 0
	if s.count('7')>0 and s.count('5')>0 and s.count('3')>0:
		return 1 + solve(s+'7') + solve(s+'5') + solve(s+'3')
	else:
		return solve(s+'7') + solve(s+'5') + solve(s+'3')
print(solve('0'))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

// O(HW)
int H,W;
char maze[1010][1010];
int d[1010][1010];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};


int main(){
    cin>>H>>W;
    queue<pair<int,int>> que;
    rep(i,H){
        rep(j,W){
            d[i][j]=INF;
        }
    }
    rep(i,H){
        rep(j,W){
            cin>>maze[i][j];
            if(maze[i][j]=='#'){
                que.push(make_pair(i,j)); // (0,0)スタート
                d[i][j]=0;
            }
        }
    }

    while(!que.empty()){
        pair<int,int> p=que.front();
        que.pop();
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx && nx<H && 0<=ny && ny<W && maze[nx][ny]!='#' && d[nx][ny]==INF){
                que.push(make_pair(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
            }
        }
    }

    int ans=0;
    rep(i,H){
        rep(j,W){
            ans=max(ans,d[i][j]);
        }
    }

    cout<<ans<<endl;

}

 

Measured memory_bytes: 13456
#include<stdio.h>

int main(void){
    char S[100000];
    scanf("%s", S);
    //printf("%s", S);
    if(S[2] == '\0'){
        printf("0");
        return 0;
    }
    int cnt = 0;
    for(int i = 1; S[i] != '\0'; i++){
        if(S[i-1] == S[i]){
            switch(S[i]){
                case '0':
                    S[i] = '1';
                    break;
                case '1':
                    S[i] = '0';
                    break;
                default:
                    break;
            }
            //printf("%d\n", i);
            cnt++;
        }
        //printf("%c", S[i]);
        //printf("%d\n", i);
    }
    printf("%d", cnt);

    //printf("%s", S);
    return 0;
}

Measured memory_bytes: 256