akhauriyash/Code-Regression huggingface dataset:
open Batteries
open Printf

let ($) g f x = g (f x)

module MyList = struct
  include List
  let foldl = fold_left
  let foldli = fold_lefti
  let foldr = fold_right
  let foldri = fold_righti
  
  let flatmap = concat_map

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let swap = Tuple2.swap

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let soc = split_on_char

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

module MySet = struct
  include Set

  let fold' f s z = fold f z s
end

module St = MySet

module MyMap = struct
  include Map

  let apply = find
  let apply_or = find_default
end

module Mp = MyMap


let rds () = read_line ()

let rdi () = atoi @@ rds ()

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdi2 () = match rdhi () with
  | a::b::_ -> (a, b)
  | _ -> (0, 0)

let rdi3 () = match rdhi () with
| a::b::c::_ -> (a, b, c)
| _ -> (0, 0, 0)

let rdi4 () = match rdhi () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0, 0, 0, 0)

let rdi5 () = match rdhi () with
| a::b::c::d::e::_ -> (a, b, c, d, e)
| _ -> (0, 0, 0, 0, 0)

let rdv n rdf =
  let rec rdv' n =
    if n <= 0 then []
    else (
      let s = rdf () in
      s::(rdv' (n - 1))
    )
  in rdv' n

let rdvi n = rdv n rdi
let rdvi2 n = rdv n rdi2
let rdvi3 n = rdv n rdi3
let rdvi4 n = rdv n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let set_power ls =
  let rec set_power' ls pls =
    match ls with
    | [] -> pls
    | hd::tl -> set_power' tl (L.flatmap (fun p -> [p; hd::p]) pls)
  in set_power' ls [[]]


let rdhf () = rdhs () |> L.map atof
let rdf4 () = match rdhf () with
| a::b::c::d::_ -> (a, b, c, d)
| _ -> (0., 0., 0., 0.)


module Graph = struct

  type 'a t = { nb : (int, int St.t) Mp.t; vdt : (int, 'a) Mp.t }

  let nothing = { nb = Mp.empty; vdt = Mp.empty }

  let add_edge (e : int * int) g =
    let (v1, v2) = e in
    let nbvs = g.nb |> Mp.apply_or St.empty v1 in
    let nb1 = g.nb |> Mp.add v1 (nbvs |> St.add v2) in
    { g with nb = nb1 }

  let add_uedge e g =
    add_edge e (add_edge (swap e) g)

  let from_edges es =
    es |> L.foldl (fun g e -> add_edge e g) nothing

  let from_uedges es =
    es |> L.foldl (fun g e -> add_uedge e g) nothing


end

module G = Graph


let _ =
  let t = rds () in
  let result = S.replace_chars (fun c ->
    match c with
    | '?' -> "D"
    | x -> S.of_char x
  ) t in
  puts result
;;


Measured memory_bytes: 14272
N, Q = map(int, input().split())
S = input()

cnt = [0]*N
flag = [0]*N
if S[:2] == 'AC':
  cnt[1] = 1
  flag[1] = 1
  
for i in range(1,N-1):
  if S[i] == 'A' and S[i+1] == 'C':
    cnt[i+1] = cnt[i-1] + 1
    flag[i+1] = 1
  else:
    cnt[i+1] = cnt[i]

for _ in range(Q):
  l, r = map(int, input().split())
  if l == 1:
    print(cnt[r-1])
  else:
    if flag[l-1] == 0:
      print(cnt[r-1]-cnt[l-2])
    else:
      print(cnt[r-1]-cnt[l-2]-1)

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> A(N);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A.at(i);
    }
    
    multiset<int64_t> st = {A[0]};
    for ( int64_t i = 1; i < N; ++i){
        int64_t min = *st.begin();
        if ( A[i] <= min ) {
            st.insert(A[i]);
        } else {
            auto itr = st.lower_bound(A[i]);
            --itr;
            st.erase(itr);
            st.insert(A[i]);
        }
        /*for ( auto s: st){
            cout << i << " " << s << endl;
        }*/
    }
    cout << st.size() << endl;
    
    return 0;
}


Measured memory_bytes: 5760
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int m = sc.nextInt();
        long k = sc.nextLong();
		long [] in = new long [n+1];
        long [] in2 = new long [m+1];
       
        for(int i=1;i<n+1;i++){                               
                               in[i]=in[i-1]+sc.nextLong();
                              }
        for(int i=1;i<m+1;i++){                            
                               in2[i]=in2[i-1]+sc.nextLong();
                              }
        int ans = 0;
        for(int i=0;i<=n;i++){if(in[i]>k){break;}
        int small = 0;
        int big = m+1;
        int point = (small+big)/2;
        int size = point-small;               
        while(big-small>1){size = Math.max(size/2,1);
                         if(k-in[i]>=in2[point]){small=point;point+=size;}
                         else{big=point;point-=size;}                
                        }
        ans=Math.max(ans,i+small);
        }                                                                  
		System.out.println(ans);
	}
}

Measured memory_bytes: 64240
N, = (int(x) for x in input().split())
T,A = (int(x) for x in input().split())
H_arr = [int(x) for x in input().split()]

min_state = (-1, 100000)
for i, H in enumerate(H_arr):
    T_diff = abs(T-H*0.006-A)
    if T_diff < min_state[1]:
        min_state = (i+1, T_diff)

print(min_state[0])


Measured memory_bytes: 3060
n = int(input())
l = [int(i) for i in input().split()]

memo = [0 for _ in range(n+1)]

for i in range(n):
    memo[i+1] = memo[i] + l[i]
    
ans = 10 ** 18

for i in range(1,n):
    ans = min(ans,abs(memo[n] - memo[i]*2))

print(ans)

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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int INF_INT = 1e9;
typedef long long ll;

int main(){
    ll L, R;
    cin >> L >> R;
    ll ans = INF;
    if(R-L >= 2019){
        cout<<0;
    }else{
        for(ll i = L; i < R; i++){
            for(ll j = i+1; j <= R; j++){
                ans = min(ans, i*j%2019);
            }
        }
        cout << ans;
    }
}

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

int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+1]={};
	for(int i=1;i<=n;i++)
	{
	    cin>>a[i];
	}
	vector <int> dp(n+1,INT_MAX);
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
	{
	   
	    
	    for(int j=1;j<=k;j++)
	    {
	        if(i-j>0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	    }
	}
	cout<<dp[n];
}

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

int main() {
  int N, X;
  cin >> N >> X;
  
  int D = 0;
  int ans = 1;
  for (int i=0; i<N; i++) {
    int L;
    cin >> L;
    D += L;
    if (D <= X) {
      ans++;
    }
    else {
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
double a,b;
	cin>>a>>b;
	if(a>b){
		cout<<"GREATER";
	}
	else  {
		if(a<b){
			cout<<"LESS";
		}
		else
		{
			cout<<"EQUAL";
		}
}
}

Measured memory_bytes: 384
# s = input()
# n = int(input())
# A = list(map(int, input().split()))
N, X = map(int, input().split())
L = list(map(int, input().split()))

res = 1
D = 0

for l in L:
    D += l
    if D <= X:
        res += 1

print(res)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
   int H,W;
   for(;;){
     cin >> H >> W;
   if(H!=0||W!=0){
        for(int a=0;a<W-1;a++)
           cout << "#" ;
           cout << "#" << endl;
     for(int i=0;i<H-2;i++){
            cout << "#" ;
        for(int j=0;j<W-2;j++){
            cout << "." ;
        }
        cout << "#" << endl;
     }
      for(int a=0;a<W-1;a++)
           cout << "#" ;
           cout << "#" << endl;
   }
   else break;
   cout << endl;
   }
   return 0;
}



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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
from collections import deque
H, W = map(int, input().split())
grid = np.zeros((H + 2, W + 2), dtype=int)
for i in range(H):
    grid[i+1][1:-1] = [1 if j == "." else 0 for j in input()]
grid = grid.tolist()

mod = 10**9+7
cost = [[0]*(W+2) for _ in range(H+2)]

cost[1][1] = 1
for i in range(1, H + 1):
    for j in range(1, W + 1):
        c = cost[i][j]
        if grid[i+1][j]:
            cost[i+1][j] += c
            cost[i+1][j] %= mod
        if grid[i][j+1]:
            cost[i][j+1] += c
            cost[i][j+1] %= mod

ans = cost[H][W]
print(ans)


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define MAX_N (1<<18)

struct BIT{
  ll bit[MAX_N];

  void init(){
    memset(bit,0,sizeof(bit));
  }

  ll sum(int i){
    ll s=0;
    while(i>0){
      s+=bit[i];
      i-=i&-i;
    }
    return s;
  }

  void add(int i,ll v){
    while(i<=MAX_N){
      bit[i]+=v;
      i+=i&-i;
    }
  }
};

BIT bit1,bit2;

int main(){
	cin.sync_with_stdio(false);
  string s,t;
  bit1.init();
  bit2.init();
  cin>>s>>t;
  rep(i,s.length())if(s[i]=='A')bit1.add(i+1,1);
  rep(i,t.length())if(t[i]=='A')bit2.add(i+1,1);
  int q;
  cin>>q;
  while(q--){
    int l,r,ll,rr;
    cin>>l>>r>>ll>>rr;
    int a=bit1.sum(r)-bit1.sum(l-1);
    int b=r-l+1-a;
    int aa=bit2.sum(rr)-bit2.sum(ll-1);
    int bb=rr-ll+1-aa;
    if((a-b+300000)%3==(aa-bb+300000)%3)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
	return 0;
}


Measured memory_bytes: 5072
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  string A;
  cin >> A;
  int X = A.size();
  int C = 0;
  if(X % 2 == 0) {
    for(int i = 0; i < X; i += 2) {
      if(A.at(i) == 'h' && A.at(i + 1) == 'i') {
        C++;
      }
    }
    if(C == X / 2) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
  }
}
    

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using namespace atcoder;
// cout << fixed << setprecision(10）<<  << endl;

int op(int a, int b) { return max(a, b); }
int e() { return 0; }

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

    segtree<int, op, e> data(900900);
    rep(i,n){
        int num; cin >> num;
        num += 300300;
        int save = data.prod(num - k, num + k + 1);
        data.set(num, save + 1);
    }
    cout << data.all_prod() << endl;
    return 0;
}

Measured memory_bytes: 14908
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n, s1[100000], x[100000], e=0;
	char s[100000];
	scanf("%d", &n);
	scanf("%s", s);
	for(int i=0; i<n; i++){
		if(s[i]=='o'){
			s1[i]=1;
		}else{
			s1[i]=-1;
		}
	}
	x[0]=1, x[1]=1;
	for(int i=1; i<=n-2; i++){
		x[i+1]=x[i]*x[i-1]*s1[i];
	}
	if(x[0]==x[n-1]*x[n-2]*s1[n-1] && x[1]==x[0]*x[n-1]*s1[0]){
		e=1;
		for(int i=0; i<=n-1; i++){
			if(x[i]==1){
				printf("%c", 'S');
			}else{
				printf("%c", 'W');
			}
		}
		printf("\n");
	}
	if(e==0){
	x[0]=1, x[1]=-1;
	for(int i=1; i<=n-2; i++){
		x[i+1]=x[i]*x[i-1]*s1[i];
	}
	if(x[0]==x[n-1]*x[n-2]*s1[n-1] && x[1]==x[0]*x[n-1]*s1[0]){
		e=1;
		for(int i=0; i<=n-1; i++){
			if(x[i]==1){
				printf("%c", 'S');
			}else{
				printf("%c", 'W');
			}
		}
		printf("\n");
	}
	}
	if(e==0){
	x[0]=-1, x[1]=1;
	for(int i=1; i<=n-2; i++){
		x[i+1]=x[i]*x[i-1]*s1[i];
	}
	if(x[0]==x[n-1]*x[n-2]*s1[n-1] && x[1]==x[0]*x[n-1]*s1[0]){
		e=1;
		for(int i=0; i<=n-1; i++){
			if(x[i]==1){
				printf("%c", 'S');
			}else{
				printf("%c", 'W');
			}
		}
		printf("\n");
	}
	}
	if(e==0){
	x[0]=-1, x[1]=-1;
	for(int i=1; i<=n-2; i++){
		x[i+1]=x[i]*x[i-1]*s1[i];
	}
	if(x[0]==x[n-1]*x[n-2]*s1[n-1] && x[1]==x[0]*x[n-1]*s1[0]){
		e=1;
		for(int i=0; i<=n-1; i++){
			if(x[i]==1){
				printf("%c", 'S');
			}else{
				printf("%c", 'W');
			}
		}
		printf("\n");
	}
	}
	if(e==0){
		printf("%d\n", -1);
	}
	return 0;
}

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll cnt[6];
ll ans;
//Mは0 Aは1 Rは2 Cは3 Hは4に

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep(i,N){
	string s;
	cin>>s;
	if(s[0]=='M') cnt[0]++;
	if(s[0]=='A') cnt[1]++;
	if(s[0]=='R') cnt[2]++;
	if(s[0]=='C') cnt[3]++;
	if(s[0]=='H') cnt[4]++;
}

rep(i1,5)rep(i2,5)rep(i3,5){
	if(i1!=i2&&i1!=i3&&i2!=i3) ans+=cnt[i1]*cnt[i2]*cnt[i3];
}

cout<<ans/6<<endl;


}
	


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), m = scan.nextInt(), l = scan.nextInt();
        long[][] a = new long[n][m], b = new long[m][l], c = new long[n][l];

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                a[i][j] = scan.nextInt();
            }
        }

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < l; j++) {
                b[i][j] = scan.nextInt();
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < l; j++) {
                long sum = 0;
                for (int k = 0; k < m; k++) {
                    sum += a[i][k] * b[k][j];
                }
                c[i][j] = sum;
                System.out.print(j == l - 1 ? c[i][j] : c[i][j] + " ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 55456
A, B, K = (int(x) for x in input().split())
if (B - A) / 2 >= K:
  for x in range(A, A + K):
    print(x)
  for x in range(B-K+1, B+1):
    print(x)
else:
  for x in range(A, B+1):
    print(x)


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

int main(){
  int X,A,B,C,D;
  cin >> X >> A >> B;
  if(X>A){
    C=X-A;
  }
  else{
    C=A-X;
  }
  if(X>B){
    D=X-B;
  }
  else{
    D=B-X;
  }
  if(C<D){
    cout << "A" << endl;
  }
  else{
    cout << "B" << endl;
  }
}


Measured memory_bytes: 3628
#Scoring
import numpy as np
D = int(input())
C = np.array(list(map(int, input().split())))
S = np.zeros((D,26),int)
for i in range(D):
    S[i] = list(map(int, input().split()))

t = np.zeros(D,int)
for i in range(D):
    t[i] = int(input())

score = int(0)
ld = -np.ones(26,int)
tscore = np.zeros(26,int)
for i in range(D):
    cid = t[i]-1
    ld[cid] = i
    score -= np.sum(C*(i-ld))
    score += S[i,cid]
    print(score)


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, k;
            ReadInt2(out n, out k);
            long[] H = Enumerable.Repeat(0, n).Select(_ => long.Parse(Console.ReadLine()))
                                 .OrderByDescending(x => x).ToArray();

            long ans = long.MaxValue;
            for (int i = 0; i < H.Length - k + 1; i++)
            {
                ans = Math.Min(ans, H[i] - H[i + k - 1]);
            }

            Console.WriteLine(ans);
        }

        static void ReadInt2(out int first, out int second)
        {
            var array = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            first = array[0];
            second = array[1];
        }
    }
}

Measured memory_bytes: 23004
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;

int main() {
	int n;
	cin >> n;
	ll ans = 1LL;
	rep(i, n) {
		ll t;
		cin >> t;
		ans = lcm(ans, t);
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3548
#include<stdio.h>

int main(){
        long n, k, i, res=0, fir, sec, add;
        scanf("%ld %ld", &n, &k);

        for(i=k; i<=n+1; i++){
                fir=i*(2*n-i+1)/2;
                sec=i*(i-1)/2;
                add=fir-sec+1;
                res=(res+add)%1000000007;
        }

        printf("%ld", res);

        return 0;
}

Measured memory_bytes: 2156
#include<bits/stdc++.h>
using namespace std;
int N, K;
int V[101010];
int main()
{
  scanf("%d%d", &N, &K);
  for(int i=0; i<N; ++i)
    scanf("%d", V+i);
  int ans = 0;
  //0~L, R~N-1
  for(int L=-1; L<=N-1; ++L)
    for(int R=L+1; R<=N; ++R)
    {
      priority_queue<int,vector<int>, greater<int> > Q;
      for(int i=0; i<=L; ++i)
        Q.emplace(V[i]);
      for(int j=R; j<=N-1; ++j)
        Q.emplace(V[j]);
      int cnt = K - (L+1 + N-R);
      int sum = 0;
      //for(int i=L+1; i<=R-1; ++i) sum += V[i];
      if(cnt < 0) continue;
      while(cnt > 0 && !Q.empty() && Q.top() < 0)
      {
        //sum += Q.top();
        Q.pop();
        --cnt;
      }
      while(!Q.empty())
      {
        sum += Q.top();
        Q.pop();
      }
      //printf("%d %d %d %d\n", sum, L, R, cnt);
      ans = max(ans, sum);
    }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200001],b[200001],f[400001];
int ans;
int main(){
	int n,m,k,i,j,l,r;
	cin>>n>>m>>k;
	for(i=1;i<=n;++i){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	for(i=1;i<=m;++i){
		cin>>b[i];
		b[i]+=b[i-1];
	}
	for(l=1;l<=n;++l)if(a[l]>k)break;
	--l;
	for(r=1;r<=m;++r)if(b[r]>k)break;
	--r;
	ans=l;
	for(i=0;i<=l;++i){
		int g=upper_bound(b+1,b+r+1,k-a[i])-b-1;
		//cout<<i<<" "<<g<<endl;
		ans=max(ans,i+g);
	}
	cout<<ans;
} 

Measured memory_bytes: 6732
#include <bits/stdc++.h>
#define FAST_INPUT ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long

using namespace std;

void solve() {
	string s, t;
	cin >> s >> t;
	ll res = 0;

	int n = s.size();
	for (int i = 0; i < n; i++) {
		if (s[i] != t[i]) {
			res++;
		}
	}

	cout << res << endl;
}

int main() {
    FAST_INPUT;

    solve();

    return 0;
}


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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> P(n);
    copy_n(istream_iterator<int>(cin), n, P.begin());

    vector<int> idx(n + 1);
    for (int i = 0; i < n; i++)
        idx[P[i]] = i;

    int cnt = 0, ma = 0, prev = -1;
    for (int i = 1; i <= n; i++){
        if (prev < idx[i]){
            cnt++;
        } else {
            cnt = 1;
        }
        ma = max(ma, cnt);
        prev = idx[i];
    }

    cout << n - ma << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0;
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
vector<char>V,L,L1;
vector<pair<char,ll>>B;
vector<string>Ans;
map<int,int>M;
set<ll>S;
set<char>:: iterator it;
ll n,m,a,b,c,d,e,f,x,y,z,t,l,r,ans,cnt,score;
string   s,winner,temp,p;
ll arr[1001];
bool xy=0;
char bd;
float ans1;
int main()
{
    TIME;
    cin>>n;
    for (int i ='a'; i <='z'; i ++ )
        V.pb(i);
        a=n;
    while (a)
    {
        if (a%26==0)
        {
            s+=V[25],
            a/=26;
            a--;
        }
        else
            s+=V[(a%26)-1],a/=26;
        //if(a==26)
          //  break;
    }
    reverse(s.begin(),s.end());
        cout<<s;


}


Measured memory_bytes: 3656
s = input()
_s = s.replace("x", "")
if _s == _s[::-1]:
	cnt = 0
	lngt = len(s)
	i, j = 0, lngt - 1
	while i < j:
		if s[i] == s[j]:
			i += 1
			j -=1
		elif s[i] == "x":
			i += 1
			cnt += 1
		else:
			j -= 1
			cnt += 1

	print(cnt)
		
else:
	print(-1)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int a[100][2];
int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    int n,ans=0;
    cin>>n;
    for(int i=1; i<n;i++){
        ans+=(n-1)/i;
    }
    cout<<ans<<endl;
    return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//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())

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

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

//main code

int main(int argc, char const* argv[])
{
    int a,b;
    cin >> a >> b;
    if (a % 3 == 0 or b % 3 == 0 or (a+b)  % 3 == 0) {
        cout << "Possible" << endl;
    }
    else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
ans=0
if n<3:
    print(0)
else:
    for i in range(n):
        for j in range(i+1,n):
            for k in range(j+1,n):
                a,b,c=l[i],l[j],l[k]
                if (a!=b and b!=c and c!=a):
                    if max(a,b,c)<(sum([a,b,c])-max(a,b,c)):
                        ans+=1
    print(ans)

Measured memory_bytes: 9164
#include <stdio.h>

int main(int argc, char const *argv[])
{
  int i, j;
  int sum[2001] = {0}, n, count, c;
  for (i = 0; i <= 1000; i++)
    for (j = 0; j <= 1000; j++)
      sum[i+j]++;
  while (EOF != scanf("%d", &n)) {
    for (count=0, c = 0; c <= 2000; c++) {
      if (n-c >= 0 && n-c <= 2000)
        count += sum[c] * sum[n-c];
    }
    printf("%d\n", count);
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    int d;
	while(cin >> d){
	int ans=0;
	for(int i=1;i*d<600;i++){
		ans+=d*(i*d)*(i*d);
	}
	cout << ans << "\n";
	}
    return 0;
}

Measured memory_bytes: 1160
int main(int argc, const char * argv[]) {
    int y,x;
    int i=1;
    while(1){
        scanf("%d %d",&x,&y);
        if(x==0&&y==0){
            break;
        }
        if(0<=x&&x<=10000&&0<=y&&y<=10000){
            if(i<=3000){
                if(x>y){
                    printf("%d %d\n",y,x);
                    i++;
                }else{
                    printf("%d %d\n",x,y);
                    i++;
                }
            }

        }
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
ll chan(ll x){if(x%2)return (x+1)/2%2;else return x|((x+1)/2%2);}
int main(){ll A,B;cin>>A>>B;--A;cout<<(chan(A)^chan(B))<<"\n";}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 300010;

int n, a[MAXN];
llint sol;

int main(void) {
  scanf("%d",&n);
  n *= 3;
  REP(i, n) scanf("%d",&a[i]);
  sort(a, a + n);

  int lo = 0, hi = n - 1;
  while (lo <= hi) {
    sol += a[hi - 1];
    ++lo;
    hi -= 2;
  }

  cout << sol << endl;
  
  return 0;
}


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

#define ll long long
#define ft first
#define sd second
#define pb push_back
using namespace std;
const ll mod = 1e9+7;
// const int N = 1e5+9;


signed main() {  

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
    int n; cin >> n;
    vector<int> a(n+1), b(n+1), c(n+1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++) {
        cin >> c[i];
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += b[a[i]];
        if(i > 1 && a[i] == a[i-1]+1) ans += c[a[i-1]];
    }
    cout << ans << endl;
    return 0;
    
}


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

int main() {

	ll mod = 1000000007;
	ll n; cin >> n;
	vector<ll> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	sort(a.begin(), a.end());
	if (n % 2 == 1) { // odd
		bool can = true;
		if (a[0] != 0) can = false;
		for (int i = 1; i <=  (n - 1)/2; i++) {
			if (!(a[2 * (i- 1) + 1] == i * 2 && a[2 * (i - 1) + 2] == i * 2)) can = false;
		}
		ll cnt = (n - 1) / 2;
		ll ans = 1;
		while (cnt--) {
			ans *= 2;
			ans %= mod;
		}
		if (can) cout << ans << endl;
		else cout << 0 << endl;
	}
	else { // even
		bool can = true;
		for (int i = 0; i < n / 2; i++) {
			if (!(a[2 * i] == 2 * (i + 1) - 1 && a[2 * i + 1] == 2 * (i + 1) - 1)) can = false;
		}
		ll cnt = n / 2;
		ll ans = 1;
		while (cnt--) {
			ans *= 2;
			ans %= mod;
		}
		if (can) cout << ans << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int h,i=0,c=0;
    cin>>h;
    c=log2(h);
    long long int l=pow(2,c+1)-1;
    cout<<l;
    
    return 0;
}
    
    
    
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}



int main(){
    int H,W;
    cin >> H >> W;
        string str;
    for(int i = 0; i < H; i++)
    {
        cin >> str;
        cout << str << endl;
        cout << str << endl;
    }
    return 0;
}


Measured memory_bytes: 256
// "for if God is with them who can be against them."
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
void solve() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	int n = s.size();
	REP(i, 0, n - 1) {
		if (s[i] != t[i])
			ans++;
	}
	cout << ans;
}
int main() {
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	IOS;
	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}


#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll mod = 1000000007;
const int INF = 1<<29;

int main(){
  string S, T; cin >> S >> T;
  int A, B; cin >> A >> B;
  string U; cin >> U;

  if (U == S) cout << A - 1 << " " << B << endl;
  else cout << A << " " << B - 1 << endl;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.Scanner;

public class Main{

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

	Scanner scan;

	private int N;
	private final long MOD = 1000000007;
	private Node[] node;

	private void mainrun() {
		scan = new Scanner(System.in);

		N = scan.nextInt();

		node = new Node[N];

		for(int i = 0;i < N;i++) {
			node[i] = new Node(scan.next());
		}

		for(int i = 0;i < N-1;i++) {
			node[scan.nextInt()-1].child.add(scan.nextInt()-1);
		}

		System.out.println(looprun(node[0]) % MOD);

		scan.close();
	}

	private long looprun(Node n) {
		long ans = 1;

		switch(n.type) {

		case "E":
			for(Integer no : n.child) {
				ans *= looprun(node[no]);
				ans %= MOD;
			}

			if(n.isOption) {
				ans += 1;
			}
			break;

		case "R":
			for(Integer no : n.child) {
				ans *= looprun(node[no]) + 1;
				ans %= MOD;
			}

			if(!n.isOption) {
				ans -= 1;
			}

			break;

		case "A":

			for(Integer no : n.child) {
				ans += looprun(node[no]);
			}

			if(!n.isOption) {
				ans -= 1;
			}
			break;
		}

		return ans;
	}
}

class Node{
	String type;
	boolean isOption;
	LinkedList<Integer> child;

	Node(String str){
		String[] sp = str.split("");
		type = sp[0];
		isOption = (sp.length == 2);
		child = new LinkedList<>();
	}
}



Measured memory_bytes: 37864
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(int i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) (x).begin(),(x).end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;

int main() {
	char a;
	cin >> a;
	if (a == 'a'|| a == 'i' || a == 'u' || a == 'e' || a == 'o') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}
}

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

using namespace std;

int main(void){
    int n=0;
    int k=0;
    string s;

    cin >> n >> k;
    cin >> s;

    if(s[k-1]=='A'){
        s[k-1]='a';
    }else if(s[k-1]=='B'){
        s[k-1]='b';
    }else if(s[k-1]=='C'){
        s[k-1]='c';
    }

    cout << s << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, s: "List[str]"):
    hb = 0
    ta = 0
    hbta = 0
    ab = 0
    for ss in s:
        hb += 1 if (ss[0] == 'B' and ss[-1] != 'A') else 0
        ta += 1 if (ss[0] != 'B' and ss[-1] == 'A') else 0
        hbta += 1 if (ss[0] == 'B' and ss[-1] == 'A') else 0
        ab += ss.count('AB')

    if hb == 0 and 0 < hbta:
        hb += 1
        hbta -= 1
    if ta == 0 and 0 < hbta:
        ta += 1
        hbta -= 1

    if (0 < hb) and (0 < ta):
        ab += hbta + 1
        hb -= 1
        ta -= 1
    ab += min(hb, ta)
    return ab


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    s = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    result = solve(N, s)
    if isinstance(result, Iterable):
        result = '\n'.join([str(v) for v in result])
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long n,count=0;cin >> n;
  vector<long long> a(n);
  for (int i=0;i<n;i++) cin >> a[i];
  for (int i=0;i<n;i++) {
    if (i+1==a[a[i]-1]) count++;
  }
  cout << count/2 << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;cin>>N;
    double ans=0.0;
    rep(i,N){
        double x;
        string s;
        cin>>x>>s;
        if(s=="BTC")x*=380000.0;
        ans+=x;
    }
    printf("%.20f\n",ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n,m;
  cin >> n >> m;
  int a[n];
  rep(i,n) R a[i];
  pr((int)ceil((double)(n-1)/(m-1)));
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 640
#include <iostream>
#include<math.h>

using namespace std;


int main() {

    long long D, N;

    cin >> D >> N;

    // 100 だけ特別
    if (N == 100) {
        cout << (N + 1) * (int) pow(100, D) << endl;
        return 0;
    }

    cout << N * (int) pow(100, D) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define sz(a) ((int)(a).size())
#define rep(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define dec(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> PII;
typedef vector<int> VI;

const int N=1e5+10;
VI adj[N];
int tam[N];
int n;
VI solve(int v,int p) {
	VI ans;
	if(v==n-1) {
	//	cerr<<v<<endl;
		ans.pb(v);
		return ans;
	}
	rep(i,0,sz(adj[v])) {
		int u=adj[v][i];
		if(u!=p) {
			VI aux=solve(u,v);
			if(sz(aux)) {
				aux.pb(v);
				return aux;
			}
		}
	}
	return ans;
}

int set_tam(int v,int p) {
	tam[v]=1;
	rep(i,0,sz(adj[v])) {
		int u=adj[v][i];
		if(u!=p) tam[v]+=set_tam(u,v);
	}
	return tam[v];
}

int main() {
	
	scanf("%d",&n);
	rep(i,0,n-1) {
		int a,b; scanf("%d%d",&a,&b); a--; b--;
		adj[a].pb(b); adj[b].pb(a);
	}
	VI path = solve(0,-1);
	set_tam(0,-1);
	reverse(all(path));
	int i=0,j=sz(path)-1;
	while(1) {
		if(i+1<j)i++;
		if(j-1>i)j--;
		if(j-i<=1)break;
	}
	int a1=i,a2=sz(path)-1-j;
	if(tam[path[j]] > n-tam[path[j]]||((tam[path[j]]*2==n)&& a1==a2)) puts("Snuke");
	else puts("Fennec");
	return 0;
}


Measured memory_bytes: 19064
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
#include <iomanip>
#include <fstream>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<b?(a=b,1):0)
#define chmin(a,b) (a>b?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-10;
const double PI = acos(-1);
typedef long long ll;
typedef pair<int,int> pii;
 
double sq(double a, double b) {
  return a*a+b*b;
}
double dot(double x1, double y1, double x2, double y2) {
  return x1*x2+y1*y2;
}
 
double x[20];
double y[20];
 
int main() {
  int n;
  while(cin >> n, n) {
    double w,h,r,vx,vy;
    cin >> w >> h >> r >> vx >> vy;
    REP(i,n) {
      cin >> x[i] >> y[i];
      x[i]-=r;
      y[i]-=r;
    }
    w -= 2*r;
    h -= 2*r;
    double len = 0;
    double cx = x[0];
    double cy = y[0];
    double dd = hypot(vx,vy);
    vx /= dd;
    vy /= dd;
    int ans = -2;
    while(len<10000) {
      double anst = 1e100;
      int ansID;
      for (int i=1; i<n; ++i) {
        double A = sq(vx,vy);
        double B = 2*dot(vx,vy,cx-x[i],cy-y[i]);
        double C = sq(cx-x[i],cy-y[i]) - 4*r*r;
        double D = B*B-4*A*C;
        if (D>=0) {
          double ts[2] = {(-B+sqrt(D))/2/A, (-B-sqrt(D))/2/A};
          REP(j,2) {
            double t = ts[j];
            if (t >= 0 && len+t<=10000) {
              if (chmin(anst, t)) {
                ansID = i;
              }
            }
          }
        }
      }
      if (anst < 1e90) {
        ans = ansID;
        break;
      }
      double nt = INF;
      // top
      if (vy) {
        double t = (h-cy) / vy;
        if (t>EPS) chmin(nt, t);
      }
      // bottom
      if (vy) {
        double t = (-cy) / vy;
        if (t>EPS) chmin(nt, t);
      }
      // right
      if (vx) {
        double t = (w-cx) / vx;
        if (t>EPS) chmin(nt, t);
      }      
      // left
      if (vx) {
        double t = (-cx) / vx;
        if (t>EPS) chmin(nt, t);
      }
      cx += vx*nt;
      cy += vy*nt;
      if (cx < EPS || cx > w-EPS) vx = -vx;
      if (cy < EPS || cy > h-EPS) vy = -vy;
      len += nt;
    }
    cout << ans+1 << endl;
  }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
int main() {
    string s;
    cin>>s;
    n=s.length();
    ans=1;
    a=n/2;
    rep(i,a){
        if(s[i]!=s[a-1-i])ans=0;
        if(s[n-1-i]!=s[n-a+i])ans=0;
    }

    rep(i,n){
        if(s[i]!=s[n-1-i])ans=0;
    }

    if(ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <limits.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
using namespace std;
using P = pair<int, int>;
using ll = long long;
template <typename T = long long>
vector<T> make_v(size_t a) {
  return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for (int i = k; i < n; i++) {
    if (a[i] > a[i - k])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}


Measured memory_bytes: 3996
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n = int(input().strip())
    c = [0] * (n - 1)
    s = [0] * (n - 1)
    f = [0] * (n - 1)
    for i in range(n-1):
        c[i], s[i], f[i] = list(map(int, input().strip().split()))
    for k in range(n-1):
        t = 0
        for i in range(k, n-1):
            if t < s[i]:
                # ans += s[i] - t
                t = s[i]
            else:
                # ans += f[i] - (t - s[i]) % f[i]
                t = f[i] * ((t + f[i] - 1) // f[i])

            # ans += c[i]
            t += c[i]
        print(t)
    print(0)



if __name__ == '__main__':
    main()


Measured memory_bytes: 40304
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d %d",&a,&b);
  long long int c[b],d;
  for(int i=0; i<b; i++){c[i]=0;}
  for(int i=1; i<=a; i++){c[i%b]++;}
  d=c[0]*c[0]*c[0];
  if(b%2==0){
    d+=c[b/2]*c[b/2]*c[b/2];
  }
  printf("%lld",d);
  return 0;}


Measured memory_bytes: 1664
program get_ac
  implicit none
  integer :: n, q, l, r, a(100000) = 0, i
  character(100000) :: s
  read(*,*) n, q
  read(*,*) s
  do i = 2, n
    a(i) = a(i-1)+merge(1,0,s(i-1:i) == "AC")
  end do
  do i = 1, q
    read(*,*) l, r
    write(*,'(i0)') a(r)-a(l)
  end do
end program get_ac

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

int abc[100001][3];
int dp[100001][3];
int n;

int main(){
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> abc[i][0] >> abc[i][1] >> abc[i][2];
    }
    //dp[i][j]:=前日にjを選ぶ時にi日目までに得られる幸福度の最大値
    //i日目に...
    for(int i=0;i<=n;i++){
        //前日にjを選んでいたとき...
        for(int j=0;j<3;j++){
            //kを選ぶ
            for(int k=0;k<3;k++){
                if(k==j) continue;
                dp[i+1][k]=max(dp[i][j]+abc[i+1][k],dp[i+1][k]);
            }
        }  
    }
    cout << max(max(dp[n][0],dp[n][1]),dp[n][2]) << endl;
    return 0;
}

Measured memory_bytes: 2560
program main; 
var a,b,c,d,e : integer;
begin
    readln(a,b,c,d,e);
    if a = 0 then
        writeln('1');
    if b = 0 then
        writeln('2');
    if c = 0 then
        writeln('3');
    if d = 0 then
        writeln('4');
    if e = 0 then
        writeln('5');
end.

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

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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

int main() {
    ll A, B;
    cin >> A >> B;
    cout << lcm(A,B) << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <set>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    string S;
    set<string> gacha;
    for (int i = 0; i < N; i++)
    {
        cin >> S;
        gacha.insert(S);
    }
    cout << gacha.size();
    return 0;
}


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

using namespace std;
typedef long long ll;
const int inf=1e9+1;
int main(){

    ll n,k;
  cin >> n >>k;
  ll ar[n];
  for (ll i=0;i<n;i++)
  {
    cin >> ar[i];
  }
  vector<ll> dp(n,inf);
  dp[0]=0;
  //dp[1]=abs(ar[1]-ar[0]);
  for (ll i=0;i<n;++i)
  {
      for (ll j=i+1;j<=i+k ;j++)
      {
          if (j<n)
            dp[j]=min(dp[j],dp[i]+abs(ar[i]-ar[j]));
      }
  }
  cout << dp[n-1];

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
const int MOD = 1e9 + 7;

int N, M, K, Q, W, H, R, C;
string S;

int main() {
    cin >> S;
    if ((int)S.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    bool flag = true;
    for (int i = 0; i < (int)S.size(); i += 2) {
        if (!(S[i] == 'h' && S[i + 1] == 'i')) {
            flag = false;
        }
    }
    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int N, P[100005];
 
void connect(int tail, int head) {
  P[tail] = head;
}
 
int find(int node) {
  int cur_node = node, p = P[node];
  while (cur_node != p) {
    P[cur_node] = P[p];
    cur_node = p;
    p = P[p];
  }
  return cur_node;
}

int main() {
  int M; cin >> N >> M;
  int per[N];
  for (int i = 0; i < N; i++) {
    P[i] = i;
    cin >> per[i]; per[i]--;
  }
  int x, y, root_x, root_y;
  for (int i = 0; i < M; i++) {
    cin >> x >> y; x--; y--;
    if ((root_x = find(x)) != (root_y = find(y)))
        connect(root_x, root_y);
  }
  int c = 0;
  for (int i = 0; i < N; i++) {
    if ( find( per[i] ) == find(i) ) c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int r[100005],r2[100005],r3[1000005];
int main()
{
    long long int a,b,c,d,e,f,g,k;

    string s;

    while(cin>>s)
    {
        for(int i=1;i<=26;i++)
        {
            r[i]=0;
        }
     for(int i=0;i<s.size();i++)
     {
         a=s[i]-64;
         r[a]++;
     }
     b=0;
     for(int i=1;i<=26;i++)
     {
         if(r[i]==2)b++;

     }
     if(b==2)cout<<"Yes"<<endl;
     else cout<<"No"<<endl;



    }








    return 0;
}


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

int main() {
  int s,t;
  cin >> s >> t;//.at(0) >> s.at(1) >> s.at(2) >> s.at(3);
  //sort(s.begin(),s.end());
  if(s+t==15) cout << '+' << endl;
  else if(s*t==15) cout << '*' << endl;
  else cout << 'x' << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc =new Scanner(System.in);
        int N=sc.nextInt();
        int M = sc.nextInt();
        Integer A[]=new Integer[N];
        double count=0;
        for(int i=0;i<N;i++){
            A[i]=sc.nextInt();
        
        }
        for(int i=0;i<N;i++){
            count+=A[i];
        }
        double T=0;
        T=count/(4.0*(double)M);
        Arrays.sort(A,Collections.reverseOrder());
        boolean flag = true;
        for(int i=0;i<M;i++){
            if((double)A[i]>=T){
            flag = true;
            }else if((double)A[i]<T){
            flag = false;
            break;
            }
        }
        if(flag==true)
        System.out.println("Yes");
        else if(flag==false)
        System.out.println("No");
    }
}

Measured memory_bytes: 22728