akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
using namespace std;

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

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
using static Func;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	uint[] GU => Strs.Select(uint.Parse).ToArray();
	decimal[] GD => Strs.Select(decimal.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	static T[] ConstantArray<T>(int n, T val) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = val; return a; }
	static T[] MakeArray<T>(int n, Func<int, T> f) { var a = new T[n]; for (var i = 0; i < n; i++) a[i] = f(i); return a; }
	static T[] Recurse<T>(int n, T a0, Func<int, T, T> f) { var a = new T[n]; a[0] = a0; for (var i = 1; i < n; i++) a[i] = f(i, a[i - 1]); return a; }
	static T[] Accumulate<T>(IList<T> a, T zero, Func<T, T, T> f) { var s = new T[a.Count + 1]; s[0] = zero; for (var i = 0; i < a.Count; i++) s[i + 1] = f(s[i], a[i]); return s; }
	static ulong One(int k) => 1ul << k;
	static ulong All(int k) => One(k) - 1;
	static bool Has(ulong s, int k) => (s & One(k)) != 0;
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var S = Str;
		var a = int.Parse(S.Substring(0, 2));
		var b = int.Parse(S.Substring(2, 2));
		var f = 1 <= a && a <= 12;
		var g = 1 <= b && b <= 12;
		WriteLine(f && g ? "AMBIGUOUS" : !f && !g ? "NA" : f ? "MMYY" : "YYMM");
	}
}
static class Func { }


Measured memory_bytes: 11092
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

int p[20];

int main () {
	int n;
	while (scanf("%d", &n) != EOF) {
		int sum = 0;
		for (int i = 0; i < n; ++i) {
			cin >> p[i];
			sum += p[i];
		}
		sort(p, p + n);
		sum -= p[n - 1] / 2;
		cout << sum << endl;
	} 
	return 0;
}


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

using namespace std;

//https://atcoder.jp/contests/abc065/tasks/abc065_b

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

    vector<int> a(N);

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

    int light = 1; 
    int count = 0;

    for(int i=0;i<N;i++){
        if(light == 2) break;
        light = a.at(light-1) ;
        count++;
    }

    if(light !=2) count = -1;
    cout << count << endl; 

    return 0;
}

Measured memory_bytes: 640
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

module ModOp = struct
  let prime = 1_000_000_007
  let (-) a b = (a + prime - b) mod prime
  let (+) a b = (a + b) mod prime
  let ( * ) a b = (a * b) mod prime

  let rec pow x n =
    if n = 0 then 1
    else if n mod 2 = 0 then pow (x*x) (n/2)
    else x * pow (x*x) (n/2)
end

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let atoi c = Char.code c - Char.code '0'

let rec powerset = function
  | [] -> [[]]
  | hd::tl ->
    let pws =  powerset tl in
    pws @ ListL.map pws ~f:(fun pw -> hd::pw)

let permutations l =
  let rec interleave x = function
    | [] -> [[x]]
    | (hd::tl) as l ->
      (x::l) :: (interleave x tl |> ListL.map ~f:(fun l -> hd::l)) in
  let rec aux = function
    | [] -> [[]]
    | a::rest ->
      aux rest |> ListL.map ~f:(interleave a) |> List.concat in
  aux l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m) = scan "%d %d" Tuple2.make
let arr = scan_array ~sep:' ' Int.of_string

let () =
  if n < Array.sum arr then Printf.printf "-1\n"
  else Printf.printf "%d\n" @@ n - Array.sum arr


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

int mmax(int a,int b,int c){
  if(a<b){
    return max(b,c);
  }else{
    return max(a,c);
  }
}

long long euclidean_gcd(long long a, long long b) {
  if(a < b) return euclidean_gcd(b, a);
  long long r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  long i,A,B,C,X,Y,p,ansf,anss;
cin>>A>>B>>C>>X>>Y;
  if(A+B<C+C){
    ansf=A*X+B*Y;
    printf("%ld",ansf);
  }else{
    if(X<Y){
      ansf=C*X*2;
      if(B>C*2){
        anss=(Y-X)*2*C;
      }else{
        anss=(Y-X)*B;
      }
    }else{
      ansf=C*Y*2;
      if(A>C*2){
        anss=(X-Y)*2*C;
      }else{
        anss=(X-Y)*A;
      }
    }
    printf("%ld\n",ansf+anss);
  }
  return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
x = sorted([0] + list(map(int, input().split())))

ans = float("inf")
for i in range(n-k+1):
    ans = min(ans, min(abs(x[i]), abs(x[i+k])) + abs(x[i+k]-x[i]))

print(ans)

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

using namespace std;

int main()
{
    vector < int > has1, hasn;
    int n, m;
    cin >> n >> m;
    has1.resize(n, 0);
    hasn.resize(n, 0);
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        if(a == 0 || b == 0){
            has1[a] = 1;
            has1[b] = 1;
        }
        if(a == n - 1 || b == n - 1){
            hasn[a] = 1;
            hasn[b] = 1;
        }
    }
    for(int i = 1; i < n - 1; ++i){
        if(has1[i] && hasn[i]){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
}



Measured memory_bytes: 1792
import sys
from itertools import accumulate
read = sys.stdin.read

N, T, *A = map(int, read().split())
a_maximum = list(reversed(list(accumulate(reversed(A), max))))
a = [j - i for i, j in zip(A, a_maximum[1:])]
minimum = max(a)

print(a.count(minimum))

Measured memory_bytes: 14436
class SegmentTree():
    """一点更新、区間取得クエリをそれぞれO(logN)で答えるデータ構造を構築する
    update: i番目をvalに変更する
    get_min: 区間[begin, end)の最小値を求める
    """
    def __init__(self, n):
        self.n = n
        self.INF = 0
        self.size = 1
        while self.size < n:
            self.size *= 2
        self.node = [self.INF] * (2*self.size - 1)

    def update(self, i, val):
        i += (self.size - 1)
        self.node[i] = val
        while i > 0:
            i = (i - 1) // 2
            self.node[i] = max(self.node[2*i + 1], self.node[2*i + 2])

    def get_max(self, begin, end):
        begin += (self.size - 1)
        end += (self.size - 1)
        s = self.INF
        while begin < end:
            if (end - 1) & 1:
                end -= 1
                s = max(s, self.node[end])
            if (begin - 1) & 1:
                s = max(s, self.node[begin])
                begin += 1
            begin = (begin - 1) // 2
            end = (end - 1) // 2
        return s

n = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

memo = {}
for i in range(n):
    memo[h[i]-1] = i
st = SegmentTree(n)

for i in range(n):
    ind = memo[i]
    st.update(ind, st.get_max(0, ind) + a[ind])
ans = 0
for i in range(n):
    ans = max(ans, st.get_max(i, i+1))
print(ans)

Measured memory_bytes: 122832
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n, x; cin >> n >> x;
	vector<int> l(n);
	vector<int> d(n + 1, 0);
	int ans = 0;
	rep(i, 0, n - 1)cin >> l[i];
	rep(i, 1, n)
	{
		d[i] = d[i - 1] + l[i - 1];
		if (d[i] <= x)ans = i + 1;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int H, W, K;
	cin >> H >> W >> K;
	vector<string> c(H);
	REP(i, H) {
		cin >> c[i];
	}
	int res = 0;
	for (int bit1 = 0; bit1 < (1 << H); ++bit1) {
		for (int bit2 = 0; bit2 < (1 << W); ++bit2) {
			vector<string> copy = c;
			REP(i, H) {
				if (bit1 >> i & 1) {
					REP(k, W) {
						copy[i][k] = '.';
					}
				}
			}
			REP(j, W) {
				if (bit2 >> j & 1) {
					REP(k, H) {
						copy[k][j] = '.';
					}
				}
			}
			int sum = 0;
			REP(i, H) {
				REP(j, W) {
					sum += copy[i][j] == '#';
				}
			}
			if (sum == K) ++res;
		}
	}
	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3656
import java.util.*;
public class Main{
	public static void main(String args[]){
     Scanner sc=new Scanner(System.in);
     int row=sc.nextInt();
     int col=sc.nextInt();
     int n=sc.nextInt();
     int m=sc.nextInt();
     row=row-n;
     col=col-m;
     System.out.println(row*col); 
    } 
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#include <iomanip>
using namespace std;
using ll = long long;

int main(){
  int N; cin >> N;
  map<ll,ll> mp;
  for(int i = 0; i < N; i++){
      ll a; cin >> a;
      mp[a]++;
  }
  
  ll x = 0, y = 0; // x >= y
  for(auto it : mp){
      if(it.second < 2) continue;
    if(it.first > x){
        if(it.second >= 4) y = it.first;
        else y = x;
        x = it.first;
    }else if(it.first > y){
        y = it.second;
    }
  }
  cout << x * y << endl;
}



Measured memory_bytes: 6528
def solve():
    N = [int(x) for x in list(input())]

    if 7 + N[2] + N[3] == N[0] + N[1]: #A+B
        N = [str(x) for x in N]
        operators = ["+", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] + N[1]:
        N = [str(x) for x in N]
        operators = ["+", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] + N[3] == N[0] - N[1]: #A - B
        N = [str(x) for x in N]
        operators = ["-", "-", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 + N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "-", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] + N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "-"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))
    elif 7 - N[2] - N[3] == N[0] - N[1]:
        N = [str(x) for x in N]
        operators = ["-", "+", "+"]
        ans = []
        ans.append(N[0])
        del N[0]
        for n, op in zip(N, operators):
            ans.append(op)
            ans.append(n)
        ans.append("=")
        ans.append(str(7))
        print("".join(ans))


solve()

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }




int main() {
    int n; cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int ans = 1;
    int now = p[0];
    FOR(i, 1, n) {
        if(now >= p[i]) {
            ans++;
        }
        chmin(now, p[i]);
    }
    cout << ans << endl;
    return 0;
}


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

#define int long long

using P = pair<int, int>;

int M, W;
vector<int> bm, bw;

int dp[12][1<<12];

int dfs(int m, int b) {
  if ( m == M ) return 0;
  if ( dp[m][b] >= 0 ) return dp[m][b];

  int ret = dfs(m+1, b);  
  for ( int i = 0; i < W; i++ ) {
    if ( (1<<i)&b ) continue;
    int add = abs(bm[m]-bw[i]) * pow(abs(bm[m]-bw[i])-30, 2);    
    ret = max(ret, dfs(m+1, b|(1<<i))+add);    
  }

  return dp[m][b] = ret;  
}

signed main() {
  while ( cin >> M >> W, M ) {
    fill_n(*dp, 12*(1<<12), -1);

    bm = vector<int>(M);
    bw = vector<int>(W);
    
    for ( int i = 0; i < M; i++ ) {
      cin >> bm[i];
    }
    
    for ( int i = 0; i < W; i++ ) {
      cin >> bw[i];    
    }

    cout << dfs(0, 0) << endl;    
  }
  
  return 0;
}



Measured memory_bytes: 3484
#include <cstdio>
#include <iostream>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
	int ans=0;
	char t;
	for(int i=1; i<=3; i++){
		scanf("%c",&t); 
		if(t=='1') ans++;
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 384
class Abc073b
  def self.count_audience
    groups = gets.chomp.to_i
    count = 0
    groups.times do
      start_no, end_no = gets.chomp.split(' ')
      count += end_no.to_i - start_no.to_i + 1
    end
    count
  end
end

print Abc073b.count_audience


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

int main()
{
  long long int N, K;
  cin >> N >> K;
  map<long long int, long long int> mp;
  for (int i = 0; i < N; i++)
  {
    long long int a, b;
    cin >> a >> b;
    mp[a] += b;
  }
  long long int cnt = 0;
  long long int ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++)
  {
    cnt += itr->second;
    if (cnt >= K)
    {
      ans = itr->first;
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4224
N, K = [int(x) for x in input().split()]

mx = (N - 1) * (N - 2) // 2
if mx < K:
	print(-1)
else:
	ans = []
	for i in range(N - 1):
		ans.append([i + 1, N])
	add = mx - K
	edge = []
	for i in range(N - 1):
		for j in range(i):
			edge.append([i + 1, j + 1])
	for i in range(add):
		ans.append(edge[i])
	print(len(ans))
	for i in ans:
		print(i[0],end='')
		print(' ',end='')
		print(i[1])

Measured memory_bytes: 4436
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
  ll x,k,d,ans=0;cin>>x>>k>>d;
  if(x<0)x=-x;
  ll num=x/d;
  if(num>=k)ans=x-k*d;
  else {
  		k-=num;x=x-num*d;
  		if(k%2==0)ans=x;
  		else ans=d-x;
  }
  if(ans<0)ans=-ans;
  cout<<ans; 
   return 0;
} 

Measured memory_bytes: 3596
from collections import defaultdict
import sys
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
input = sys.stdin.readline


def inp():
    return int(input())


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


N, M = inpl()

if N % 2 == 1:
    for i in range(M):
        print(i + 1, N - i - 1)
else:
    if M == 1:
        print(1, 2)
    else:
        for i in range(M):
            a, b = i + 1, N - i
            if b - a <= N // 2:
                b -= 1

            print(a, b)


Measured memory_bytes: 9840
from typing import List, Iterator, Tuple


class Rectangle(object):
    def __init__(self, xy1: Tuple[int, int], xy2: Tuple[int, int]) -> None:
        self.topleft = xy1
        self.bottomright = xy2

    def area(self) -> int:
        x1, y1 = self.topleft
        x2, y2 = self.bottomright
        return (x2 - x1) * (y2 - y1)


class MergetdRectangles(object):
    def __init__(self) -> None:
        self.rects: List[Rectangle] = []

    def _intersect(self, base_rect: Rectangle, new_rect: Rectangle) -> bool:
        x1, y1 = base_rect.topleft
        x2, y2 = base_rect.bottomright
        xn1, yn1 = new_rect.topleft
        xn2, yn2 = new_rect.bottomright

        if (xn2 <= x1 or x2 <= xn1):
            return False

        if (yn2 <= y1 or y2 <= yn1):
            return False

        return True

    def _sub(self, base_rect: Rectangle, new_rect: Rectangle) -> Iterator[Rectangle]:
        x1, y1 = base_rect.topleft
        x2, y2 = base_rect.bottomright
        xn1, yn1 = new_rect.topleft
        xn2, yn2 = new_rect.bottomright
        if (x1 < xn1):
            yield Rectangle((x1, y1), (xn1, y2))
        if (xn2 < x2):
            yield Rectangle((xn2, y1), (x2, y2))
        if (y1 < yn1):
            yield Rectangle((max(x1, xn1), y1), (min(x2, xn2), yn1))
        if (yn2 < y2):
            yield Rectangle((max(x1, xn1), yn2), (min(x2, xn2), y2))

    def add(self, new_rect: Rectangle) -> None:
        rects: List[Rectangle] = []
        for r in self.rects:
            if self._intersect(r, new_rect):
                rects.extend(self._sub(r, new_rect))
            else:
                rects.append(r)
        rects.append(new_rect)
        self.rects = rects

    def total_area(self) -> int:
        return sum([r.area() for r in self.rects])


if __name__ == "__main__":
    N = int(input())
    rects = MergetdRectangles()
    for _ in range(N):
        x1, y1, x2, y2 = map(lambda x: int(x), input().split())
        rects.add(Rectangle((x1, y1), (x2, y2)))
    print(rects.total_area())



Measured memory_bytes: 7424
a, b, c, d = map(int, input().split())


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def lcm(a, b):
    return a*b//gcd(a, b)


def interval(a, b, c):
    a1 = (a-1)//c
    b1 = b//c
    return b1 - a1


l = lcm(c, d)

print(int(b-a+1 - (interval(a, b, c) + interval(a, b, d) - interval(a, b, l))))


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main{
public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int sum=-N;
for(int i=0;i<N;i++){
  int a = sc.nextInt();
  sum += a;
}
  System.out.println(sum);
}
}


Measured memory_bytes: 27884
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

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

    int n = sc.nextInt();
    int k = sc.nextInt();

    long[] dp = new long[n];
    Arrays.fill(dp, Long.MAX_VALUE);

    int[] h = new int[n];
    for (int i = 0; i < n; i++) {
        h[i] = sc.nextInt();
    }

    dp[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i+j < dp.length) {
                dp[i+j] = Math.min(dp[i+j], Math.abs(dp[i] + Math.abs(h[i] - h[i+j])));
            }
        }
    }

    System.out.println(dp[n-1]);
  }
}

Measured memory_bytes: 58760
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn=  1000000+10;
const int maxm = 1000+10;
//Pretests passed
int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    string s;
    cin>>s;
    if(s.find("YAKI")==0)puts("Yes");
        else puts("No");
    return 0;
}


Measured memory_bytes: 256
"use strict";
const Main = function(input){
	let xs = input.trim().split(' ').map(v=>parseInt(v,10));
    let ans = xs[0] + xs[1];
    if(ans>=24){
    	console.log(ans-24);
    }else{
    	console.log(ans);
    }
                               
  
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

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

// ProblemSet: Easy Linear Programming
void solve() {
	int a ,b,c,k;
	// a  = 1 b = 0 c = -1

	cin >> a >> b >> c >> k;
	if(k<=a)
		cout << k << endl;
	else if(k <= a+b ) cout << a << endl;
	else cout << a - (k-a-b)<< endl;

}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
/**
    int t;
    cin >> t;
    while(t--) {
      solve();
    }
**/
solve();
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  string s;
  cin >> s;
  rep(i, sz(s) - 1) {
    if (s[i] == s[i + 1]) {
      cout << "Bad" << endl;
      return;
    }
  }
  cout << "Good" << endl;
}


Measured memory_bytes: 256
s = input()
k = int(input())


first = 0

for i in range(1, len(s)):
    if s[i] != s[0]:
        first = i
        break

if first == 0:
    if len(s) % 2 == 0:
        print((len(s) // 2) * k)
    else:
        print(len(s) * k // 2)
    exit()

ans = 0
cnt = 1
i = 0

while i < len(s) - 1:
    if s[i] == s[i+1]:
        cnt += 1
        if i == len(s) - 2:
            ans += cnt // 2
    else:
        ans += cnt // 2
        cnt = 1
    i += 1

ans *= k

if s[0] == s[-1] and first % 2 == 1 and cnt % 2 == 1:
    ans += k - 1

print(ans)


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

int main(void)
{
	long int A,B,C,K;
	cin >> A >> B >> C >> K;

	long int sum = 0;
	for (int i = 0; i < K; i++) {
		if (i < A) {
			sum += 1;
		}
		else if (i - A < B) {
			sum += 0;

		}
		else {
			sum += -1;

		}

	}
	cout << sum << endl;



	return 0;
}

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

using namespace std;

typedef long long ll;

namespace comb {
	ll fact[500001];
	ll fact_inv[500001];
	const ll MOD = 1000000007;

	ll modpow(ll a, ll b) {
		ll base = 1, kakeru = a;
		while (b > 0) {
			if (b & 1)base *= kakeru, base %= MOD;
			kakeru *= kakeru, kakeru %= MOD;
			b >>= 1;
		}
		return base;
	}

	void setup() {
		fact[0] = 1, fact[1] = 1;
		for (int i = 2; i <= 500000; i++) {
			fact[i] = (fact[i - 1] * i) % MOD;
		}

		fact_inv[500000] = modpow(fact[500000], MOD - 2);

		for (int i = 499999; i >= 0; i--) {
			fact_inv[i] = fact_inv[i + 1] * (i + 1);
			fact_inv[i] %= MOD;
		}

	}

	ll combination(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[b], ret %= MOD;
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll permutation(int a, int b) {
		if (a - b < 0)return 0;
		ll ret = fact[a];
		ret *= fact_inv[a - b], ret %= MOD;
		return ret;
	}

	ll homogeneous(int a, int b) {
		return combination(a + b - 1, b);
	}

}

const ll MOD = 1000000007;

int N, K;
ll A[100000 + 100];

int main() {
	cin >> N >> K;
	for (int i = 0; i < N; i++)cin >> A[i];

	comb::setup();
	sort(A, A + N);
	if (K == 1) {
		cout << 0 << endl;
		return 0;
	}

	ll ans = 0;
	for (int i = 0; i < N; i++) {
		//この数字が最小の要素であるのはのべ何通りか？
		if (i + K <= N) {
			ll tmp = A[i] * comb::combination(N - 1 - i, K - 1);
			if (tmp >= 0) {
				tmp %= MOD;
				tmp = MOD - tmp;
			}
			else {
				tmp *= -1;
				tmp %= MOD;
			}
			ans += tmp;
			ans %= MOD;
		}

		//この数字が最大の要素であるのはのべ何通りか？
		if (i + 1 >= K) {
			ll tmp = A[i] * comb::combination(i, K - 1);
			if (tmp >= 0) {
				tmp %= MOD;
			}
			else {
				tmp *= -1;
				tmp %= MOD;
				tmp = MOD - tmp;
			}
			ans += tmp;
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9088
import collections
n = int(input())
v = list(input().split())
v0 = []
v1 = []
for i in range(n):
  if i%2 == 0:
    v0.append(v[i])
  else:
    v1.append(v[i])
V0 = collections.Counter(v0)
V1 = collections.Counter(v1)
if V0.most_common()[0][0]==V1.most_common()[0][0]:
  a,b = n,n
  if len(V0)==1:
    a = len(v0)+len(v1)-V1.most_common()[0][1]
  else:
    a = len(v0)+len(v1)-V0.most_common()[1][1]-V1.most_common()[0][1]
  if len(V1)==1:
    b = len(v0)+len(v1)-V0.most_common()[0][1]
  else:
    b = len(v0)+len(v1)-V0.most_common()[0][1]-V1.most_common()[1][1]
  print(min(a,b))
else:
  print(len(v0)+len(v1)-V0.most_common()[0][1]-V1.most_common()[0][1])

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

int main() {
    int N, M, Q;
    cin >> N >> M >> Q;
    int base[N + 1][N + 1] = {{0}};
    for (int i = 0; i < M; i++) {
        int L, R;
        cin >> L >> R;
        base[L][R]++;
    }

    int c[N + 1][N + 1] = {{0}};
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            c[i][j] = c[i][j - 1] + base[i][j];
        }
    }

    for (int i = 0; i < Q; i++) {
        int p, q;
        cin >> p >> q;
        int sum = 0;
        for (int i = p; i <= q; i++) {
            sum += c[i][q] - c[i][p - 1];
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
 int A,B,C,X,x,i,j,k,count=0;
 char str[20];
  
  fgets(str,sizeof(str),stdin);
  A=atoi(str);
  fgets(str,sizeof(str),stdin);
  B=atoi(str);
  fgets(str,sizeof(str),stdin);
  C=atoi(str);
  fgets(str,sizeof(str),stdin);
  X=atoi(str);
  
  x=X/50;
  
  for(i=0;i<=A;i++){
   for(j=0;j<=B;j++){
     for(k=0;k<=C;k++){
       if( 10*i+2*j+k==x){
        count++; 
       
       }
     
     }
     
   }
  }
  
  printf("%d\n",count);
  
  return 0;
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

long long INF = 1LL<<60;
int main( ){
    string s;
    cin>>s;
    int n=s.size();
    string t=s.substr(0,n/2);
    string u=s.substr((n+3)/2-1,n/2);
    if(t==u)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}




Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	char p[4],f[4];
	int i;
	int day=0;
	
	scanf("%s%s",p,f);
	
	for(i=0;i<3;i++){
		if(p[i]==f[i])
			day++;
	}
	
	printf("%d",day);
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main
{

    public void run( )
    {
        Scanner sc = new Scanner( System.in );
        int n = sc.nextInt( );
        int[] ar = new int[ n ];

        int max = Integer.MIN_VALUE;
        int maxId = -1;
        for ( int i = 0; i < n; i++ )
        {
            ar[ i ] = sc.nextInt( );
            if ( max < ar[ i ] )
            {
                max = ar[ i ];
                maxId = i;
            }
        }

        int opt = Integer.MIN_VALUE;
        int optId = -1;
        for ( int i = 0; i < n; i++ )
        {
            if ( i == maxId ) continue;

            int temp = Math.min( ar[ i ], max - ar[ i ] );
            if ( temp > opt )
            {
                opt = temp;
                optId = i;
            }
        }

        System.out.println( max + " " + ar[ optId ] );
    }

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

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

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

using namespace std;

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

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

const i64 maxn = 2*(i64)1e5 + 1000;
const i64 mod = 998244353;
i64 n, rmost[maxn], dp[maxn], a[maxn], tVal[maxn<<4];
struct node {
    i64 l, d;
} rev[maxn];

int query(int node, int l, int r, int ql, int qr) {
  //  if (ql > qr) return 0;
    if (l >= ql && r <= qr) return tVal[node];
    int mid = (l+r) >> 1;
    int res = 1;
    if (ql <= mid) res = max(res, query(node<<1, l, mid, ql, qr));
    if (mid < qr) res = max(res, query(node<<1|1, mid+1, r, ql, qr));
    return res;
}
int pushUp(int node) {
    tVal[node] = max(tVal[node<<1], tVal[node<<1|1]);
}
void update(int node, int l, int r, int pos, int val) {
    if (l == r) {
        tVal[node] = val;
        return;
    }
    int mid = (l+r) >> 1;
    if (pos <= mid) update(node<<1, l, mid, pos, val);
    else update(node<<1|1, mid+1, r, pos, val);
    pushUp(node);
}

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

    ms(rmost, 0);
    cin >> n;
    for1(i, n) {
        cin >> rev[i].l >> rev[i].d;
    }
    sort(rev+1, rev+1+n, [&](node n1, node n2) {
        return n1.l<n2.l;
    });
    for1(i, n) a[i] = rev[i].l;
    for (int i = n; i >= 1; --i) {
        int idx = lower_bound(a+1+i, a+1+n, a[i]+rev[i].d)-a-1;
        if (idx == i) rmost[i] = i;
        else rmost[i] = query(1, 1, n, i+1, idx);
        update(1, 1, n, i, rmost[i]);
    }
    ms(dp, 0);
    dp[n+1] = 1;
    for (int i = n; i >= 1; --i) {
        dp[i] = (dp[i+1]+dp[rmost[i]+1])%mod;
        //cerr << i << ' ' << dp[i] << ' ' << rmost[i] << endl;
    }
    cout << dp[1] << endl;

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


Measured memory_bytes: 14848
#include <iostream>
#include <vector>

const int MAX_N = 50;
int N, M;
int bridge[MAX_N][MAX_N];
bool visit[MAX_N];

void dfs(int x){
   visit[x] = true;
   for(int i=0; i<N; ++i){
      if(!bridge[x][i]) continue;
      if(visit[i]) continue;
      dfs(i);
   }
   return;
}

int main(){
   std::cin >> N >> M;
   int a[M], b[M];
   for(int i=0; i<M; ++i){
      std::cin >> a[i] >> b[i];
      --a[i];
      --b[i];
      bridge[a[i]][b[i]] = true;
      bridge[b[i]][a[i]] = true;
   }

   int ans = 0;
   for(int i=0; i<M; ++i){
      bridge[a[i]][b[i]] = false; 
      bridge[b[i]][a[i]] = false; 
      for(int j=0; j<N; ++j)
	 visit[j] = false;

      dfs(0);

      for(int j=0; j<N; ++j){
	 if(!visit[j]){
	    ++ans;
	    break;
	 }
      }
      bridge[a[i]][b[i]] = true; 
      bridge[b[i]][a[i]] = true; 
   }
   std::cout << ans << std::endl;
   return 0;
}


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

using namespace std;

const int N = 50 + 5;

int n;
int a[N], b[N];
int dis[N][N];
int con[N][N];
int go[N][N];

bool can(int d, vector<int> &ops)
{
    memset(con, 0, sizeof con);
    memset(go, 0, sizeof go);

    for(int k = 1; k < d; ++ k) {
        for(int i = 0; i < N; ++ i) {
            go[i][i % k] = true;
        }
    }
    for(int k = 0; k < (int)ops.size(); ++ k) {
        for(int i = 0; i < N; ++ i) {
            go[i][i % ops[k]] = true;
        }
    }

    //cout << go[19][0] << endl;
    //cout << con[19][0] << endl;


    for(int s = 0; s < N; ++ s) {
        con[s][s] = 1;
        vector<int> que;
        que.push_back(s);
        for(int i = 0; i < (int)que.size(); ++ i) {
            int u = que[i];
            for(int v = u - 1; v >= 0; -- v) {
                if (go[u][v] && !con[s][v]) {
                    con[s][v] = 1;
                    que.push_back(v);
                }
            }
        }
    }

    for(int i = 0; i < n; ++ i) {
        if (!con[a[i]][b[i]]) {
            //cout << i << endl;
            return false;
        }
    }
    return true;
}

void solve()
{
    cin >> n;
    for(int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    for(int i = 0; i < n; ++ i) {
        cin >> b[i];
    }
    memset(dis, -1, sizeof dis);
    for(int i = 0; i < N; ++ i) dis[i][i] = 0;

    for(int k = 1; k <= 50; ++ k) {
        for(int i = 0; i < N; ++ i) {
            int j = i % k;
            if (dis[i][j] == -1) {
                dis[i][j] = k;
            }
        }
    }

    vector<int> ops;
    long long ans = 0;

    if (! can(51, ops)) {
        cout << -1 << endl;
        return;
    }

    for(int i = 50; i >= 1; --i) {
        if (can(i, ops)) continue;
        ops.push_back(i);
        ans += 1ll << i;
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	int n, a[1000];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	cout << a[n - 1] - a[0] << endl;
	int x;
	cin >> x;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    char c;
    while(cin>>a>>c>>b)
    {
        if(c=='+') cout<<a+b<<endl;
        else if(c=='-') cout<<a-b<<endl;
        else if(c=='*') cout<<a*b<<endl;
        else if(c=='/') cout<<a/b<<endl;
        else if(c=='?') continue;
    }
    return 0;
}


Measured memory_bytes: 3084
# B - String Palindrome
S = input()
N = len(S)

# 文字列をリストに
S_org = list(S)
S_org
S_org_r = reversed(S_org)
S_former = S_org[0:int((N-1)/2)]
S_former_r = reversed(S_former)
S_latter = S_org[int((N+3)/2)-1:N+1]
S_latter_r = reversed(S_latter)

# リストを文字列に
S_org_str = ''.join(S_org)
S_org_r_str = ''.join(S_org_r)
S_former_str = ''.join(S_former)
S_former_r_str = ''.join(S_former_r)
S_latter_str = ''.join(S_latter)
S_latter_r_str = ''.join(S_latter_r)

# 条件判定
if S_org_str == S_org_r_str and S_former_str == S_former_r_str  and S_latter_str == S_latter_r_str:
    print('Yes')
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 100000000000000009
#define int long long
using P = pair<int,int>;
signed main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(c-a-b > 0 && 4*a*b < (c-a-b)*(c-a-b)) cout << "Yes" << endl;
  else cout << "No" << endl; 
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
using namespace std;
long long mod = 1e9 + 7;
long long tmp[53];
long long comb(long long a, long long b) {
	long long ans = 1;
	for (int i = 0; i < 53; i++) {
		tmp[i] = 0;
	}
	for (int i = 2; i <= a; i++){
		int now = i;
		for (int j = 2; j <= 50; j++) {
			while (now%j == 0) {
				tmp[j] += 1;
				now /= j;
			}
		}
	}
	for (int i = 2; i <= b; i++) {
		int now = i;
		for (int j = 2; j <= 50; j++) {
			while (now%j == 0) {
				tmp[j] -= 1;
				now /= j;
			}
		}
	}
	for (int i = 2; i <= a-b; i++) {
		int now = i;
		for (int j = 2; j <= 50; j++) {
			while (now%j == 0) {
				tmp[j] -= 1;
				now /= j;
			}
		}
	}
	for (int i = 2; i <= 50; i++) {
		while (tmp[i] > 0) {
			tmp[i] -= 1;
			ans *= i;
		}
	}
	return ans;
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	int n, a, b;
	cin >> n >> a >> b;
	long long v[53];
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	sort(v, v + n, greater<long long>());
	int cnt2 = 0;
	int judge = 0;
	long long sum = v[0];
	for (int i = 1; i < a; i++) {
		sum += v[i];
		if (v[i] == v[a - 1])cnt2 += 1;
		if (v[i] != v[i - 1]) {
			judge = 1; 
		}
	}
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (v[i] == v[a - 1])cnt += 1;
	}
	if (judge == 1) {
		cout << (double)sum / a << "\n" << comb(cnt, cnt2);
		return 0;
	}
	unsigned long long  ans = 0;
	for (int i = a-1; i < b; i++) {
		if (i>0&&v[i] != v[i - 1])break;
		ans += comb(cnt, i+1);
	}
	cout << (double)sum / a << "\n" << ans;
}

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

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

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	int x, n, c1, c2, tmp;
	vector<int> v(110);

	cin>> x >> n;

	rep(i, n){
		cin >> tmp;
		v[tmp]=1;
	}

	c1=x;
	c2=x;

	while(1){
		if(v[c1]==0){
			cout<< c1 <<endl;
			return 0;
		}
		if(v[c2]==0){
			cout<< c2 <<endl;
			return 0;
		}
		c1--;
		c2++;
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    int a, b, h, w;
    int nm = 0;
    cin >> h >> w;
    int chart[h + 2][w + 2];
    int water[h + 2][w + 2][2];
    for(int i = 0; i < h + 2; i++) {
        for(int j = 0; j < w + 2; j++) {
            if(j == 0 || j == w + 1 || i == 0 || i == h + 1)
                chart[i][j] = h * w + 1;
            else
                cin >> chart[i][j];
            water[i][j][0] = 0;
            water[i][j][1] = 0;
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(chart[i + 1][j + 1] < chart[i][j + 1] &&
               chart[i + 1][j + 1] < chart[i + 2][j + 1] &&
               chart[i + 1][j + 1] < chart[i + 1][j] &&
               chart[i + 1][j + 1] < chart[i + 1][j + 2]) {
                for(int x = 0; x < h; x++) {
                    for(int y = 0; y < w; y++)
                        water[x + 1][y + 1][1] = 0;
                }

                queue<pair<int, int>> q;
                q.push(make_pair(i + 1, j + 1));
                while(q.empty() == false) {
                    pair<int, int> tmp = q.front();
                    a = tmp.first;
                    b = tmp.second;
                    q.pop();
                    if(water[a][b][1] == 1)
                        continue;

                    water[a][b][0]++;
                    water[a][b][1] = 1;

                    if(chart[a][b] < chart[a][b + 1] &&
                       water[a][b + 1][1] == 0 && water[a][b + 1][0] < 2)
                        q.push(make_pair(a, b + 1));
                    if(chart[a][b] < chart[a][b - 1] &&
                       water[a][b - 1][1] == 0 && water[a][b - 1][0] < 2)
                        q.push(make_pair(a, b - 1));
                    if(chart[a][b] < chart[a + 1][b] &&
                       water[a + 1][b][1] == 0 && water[a + 1][b][0] < 2)
                        q.push(make_pair(a + 1, b));
                    if(chart[a][b] < chart[a - 1][b] &&
                       water[a - 1][b][1] == 0 && water[a - 1][b][0] < 2)
                        q.push(make_pair(a - 1, b));
                }
            }
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(water[i + 1][j + 1][0] >= 2)
                nm++;
        }
    }
    cout << nm << endl;
    return 0;
    
}



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

using namespace std;
#define INF 1000007
#define MOD 1000000007
#define maxn 101
#define maxh 1001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
const int dx[4] = {0, 1, -1, 0}, dy[4] = {1, 0, 0, -1};
typedef std::pair<int, int> P;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *) array, (T *) (array + N), val);
}

vector<bool> prime(maxn + 1, true); //素数テーブル
void prime_table(void) {
    prime[0] = false;
    prime[1] = false;
    for (int i = 2; i * i <= maxn; i++) {
        if (!prime[i]) {
            continue;
        }
        for (int j = i + i; j <= maxn; j += j + i) {
            prime[j] = false;
        }
    }
}

int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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

bool IsPrime(int num) //素数判定
{
    if (num < 2)
        return false;
    else if (num == 2)
        return true;
    else if (num % 2 == 0)
        return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
}

vector<int> divisor(int n) //約数列挙
{
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i - 1);
            if (i * i != n) {
                ret.push_back((n / i) - 1);
            }
        }
    }
    sort(ret.begin(), ret.end());
    return (ret);
}

int a, b;

void f(int x) {
    while (x) {
        a++;
        b = x;
        x /= 10;
    }
}

signed main() {
    int N;
    cin >> N;
    vector<P> XL(N);
    int X[N];
    int L[N];
    rep(i, N) {
        cin >> X[i] >> L[i];
    }
    rep(i, N) {
        XL[i] = P(X[i] + L[i], X[i] - L[i]);
    }
    sort(XL.begin(), XL.end());
    int x = XL[0].first;
    int ans = 1;
    rep(i, N - 1) {
        if (x <= XL[i + 1].second) {
            ans++;
            x = XL[i + 1].first;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 1792