akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
p = list(map(int, input().split()))

tab1 = [0]
tab1_tmp = 0
for pi in range(1, max(p) + 1):
    tab1_tmp += pi
    tab1.append(tab1_tmp)
# print("#", tab1)

tab2 = [0]
for i in range(N):
    tab2.append(tab1[p[i]] / p[i])
# print("#", tab2)

tab3 = [0]
tab3_tmp = 0
for i in range(1, N + 1):
    tab3_tmp += tab2[i]
    tab3.append(tab3_tmp)
# print("#", tab3)

ans = 0
for i in range(N - K + 1):
    ans = max(ans, tab3[i + K] - tab3[i])
print(ans)

Measured memory_bytes: 24804
#include <bits/stdc++.h>
using namespace std;
 
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
static class Program
{
	static int[] ReadInts(this TextReader reader) => reader.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
	static IEnumerable<int[]> ReadInts(this TextReader reader, int count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadInts();
	}

	static IEnumerable<long[]> ReadLongs(this TextReader reader, long count)
	{
		for (long i = 0; i < count; ++i)
			yield return reader.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
	}
	
	public static void Main(string[] args)
	{
		var m = Console.In.ReadInts()[1];
		var a = Console.In.ReadInts();
		var sum = a.Sum();
		var t = sum / (4.0 * m);
		var last = a.OrderByDescending(x => x).Skip(m-1).First();
		Console.WriteLine(last >= t ? "Yes" : "No");
	}
}

Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout(n) cout << fixed << setprecision(n)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acosl(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> inline bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N;
int a[110];
int dp[110][30];


signed main(){
    cin >> N;
    rep(i, 0, N) cin >> a[i];

    dp[1][a[0]] = 1;
    rep(i, 1, N-1) repe(j, 0, 20){
        if(j+a[i] <= 20) dp[i+1][j+a[i]] += dp[i][j];
        if(j-a[i] >= 0) dp[i+1][j-a[i]] += dp[i][j];
    }

    cout << dp[N-1][a[N-1]] << endl;

    return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i,r) for (int i = 0; i < r; i++)
#define isc(n) scanf("%d", &n)

int main() {
  int N;
  isc(N);
  int A[N];
  rep(i,N) isc(A[i]);
  sort(A, A + N);
  rep(i,N - 1) {
    if (A[i] == A[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 1024
M = 998244353
N, S = map(int, input().split())

ans = 0
prev = [0]*S
for i, a in enumerate(map(int, input().split()), 1):
  if a > S:
    continue
  prev[0] = i
  ans += prev[S-a]*(N-i+1)%M
  for j, s in enumerate(prev[:S-a], a):
    if s:
      prev[j] += s
print(ans%M)


Measured memory_bytes: 78684
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
r, g, b, n  = map(int, input().split())
#  = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ans = 0
for r_ in range(n+1):
    for g_ in range(n+1):
        sum_ = n - (r_ * r + g_ * g)
        if sum_ >= 0 and sum_ % b == 0:
            ans += 1

print(ans)




Measured memory_bytes: 40812
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.DataInputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.InputStream;

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

    static class AFrog1 {
        private int[] dp;

        public void solve(int testNumber, Reader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            dp = new int[n];
            Arrays.fill(dp, -1);
            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }
            out.println(minCost(a, n - 1));
        }

        private int minCost(int[] a, int n) {
            if (n < 2) return Math.abs(a[n] - a[0]);

            if (dp[n] != -1) return dp[n];

            int x = Math.abs(a[n] - a[n - 1]) + minCost(a, n - 1);
            int y = Math.abs(a[n] - a[n - 2]) + minCost(a, n - 2);

            return dp[n] = Math.min(x, y);
        }

    }

    static class Reader {
        final private int BUFFER_SIZE = 1 << 16;
        private DataInputStream din;
        private byte[] buffer;
        private int bufferPointer;
        private int bytesRead;

        public Reader(InputStream in) {
            din = new DataInputStream(in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public Reader(String file_name) {
            try {
                din = new DataInputStream(new FileInputStream(file_name));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public int nextInt() {
            int ret = 0;
            byte c = read();
            while (c <= ' ') {
                c = read();
            }
            boolean neg = (c == '-');
            if (neg) {
                c = read();
            }
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg) {
                return -ret;
            }
            return ret;
        }

        private void fillBuffer() {
            try {
                bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
                if (bytesRead == -1) {
                    buffer[0] = -1;
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        private byte read() {
            if (bufferPointer == bytesRead) {
                fillBuffer();
            }
            return buffer[bufferPointer++];
        }

    }
}



Measured memory_bytes: 34004
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> flag(N + 1);
    vector<ll> Ai(N + 1);
    vector<ll> table(N + 1);
    REP(x, N + 1)
    {
        table.at(x) = (x * (x - 1)) / 2;
    }

    REP(i, N)
    {
        cin >> Ai.at(i);
        flag.at(Ai.at(i))++;
    }

    ll ans = 0;
    REP(j, N + 1)
    {
        ans += table.at(flag.at(j));
    }

    REP(k, N)
    {
        ll tmp = ans - flag.at(Ai.at(k)) + 1;
        cout << tmp << "\n";
    }
}

Measured memory_bytes: 7296
#include <stdio.h>
int main(void) {
	int a[3];
	int max = 1;
	int b;
	int c;
	int sum = 0;
	for (int i = 0; i < 3; i++) {
		scanf("%d",&a[i]);
			if (a[i] > max) {
				max = a[i];
				b = i;
			}
	}
	c = 10 * a[b];
	a[b] = 0;
	for (int i = 0; i < 3; i++) {
		sum += a[i];
	}

	printf("%d", sum + c);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll mod = 1000000007;

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

  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  vector<char> x;
  for (int i = 0; i < n; i++) {
    x.push_back(s[i]);
    x.push_back(t[i]);
  }

  for (auto &y: x) cout << y;
  cout << endl;

  return 0;
}


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

#define repfrom(i, from, n) for (ll i = (from); i < (n); i++)
#define rep(i, n) repfrom(i, 0, n)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)

using namespace std;

using ll = long long;
using p  = pair<ll, ll>;
using uc = unsigned char;
constexpr ll INF = 1LL << 62;
constexpr ll MOD = 1e9 + 7;
constexpr ll MAX_N = 1e5;

ll P[MAX_N + 1];
bool used[MAX_N + 1];
vector<ll> G[MAX_N + 1];

void dfs(ll node, vector<ll>& nodes, unordered_set<ll>& nums) {
    if (used[node]) {
        return;
    }
    
    used[node] = true;
    nodes.push_back(node);
    nums.insert(P[node]);
    
    for (auto g : G[node]) {
        dfs(g, nodes, nums);
    }
}

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N, M;
    cin >> N >> M;
    
    reps(i, N) {
        cin >> P[i];
    }
    
    rep(i, M) {
        ll x, y;
        cin >> x >> y;
        G[x].push_back(y);
        G[y].push_back(x);

    }
    
    ll ans = 0;
    reps(i, N) {
        if (!used[i]) {
            vector<ll> nodes;
            unordered_set<ll> nums;
            dfs(i, nodes, nums);
            
            for (auto node : nodes) {
                ans += nums.count(node);
            }
        }
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 15516
import java.util.Scanner;

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

    int H=scan.nextInt();
    int W=scan.nextInt();

    while (H != 0 || W != 0) {

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                System.out.print("#");
            }
            System.out.print("\n");
        }

        System.out.print("\n");
        H=scan.nextInt();
        W=scan.nextInt();
    }
    }
}


Measured memory_bytes: 38052
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int X = scn.nextInt(), A = scn.nextInt(),B = scn.nextInt();
		X -= A;
		X%=B;
		System.out.println(X);
	}

}


Measured memory_bytes: 23764
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int now = 1;
		for (int i = 0; i < n; i++) {
			if(a[i] == now) {
				now++;
			}
		}
		System.out.println(now != 1 ? n-now+1 : -1);
		sc.close();
	}
}

Measured memory_bytes: 85544
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
using namespace std;

unsigned long long gcd(unsigned long long m, unsigned long long n)
{
	while (m != n)
	{
		if (m > n)
		{
			m -= n;
		}
		else
		{
			n -= m;
		}
	}
	return m;
}

int main()
{
	unsigned long long n, m;
	cin >> n >> m;

	unsigned long long g = gcd(m, n);

	char *s = new char[n], *t = new char[m];
	cin >> s >> t;

	unsigned long long l = m * n / g;

	for (unsigned long long i = 0; i < n; i++)
	{
		if (i * m % n == 0 && s[i] != t[i * m / n])
		{
			cout << -1 << endl;
			return 0;
		}
	}
	for (unsigned long long i = 0; i < m; i++)
	{
		if (i * n % m == 0 && t[i] != s[i * n / m])
		{
			cout << -1 << endl;
			return 0;
		}
	}


	cout << l << endl;
	return 0;
}


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

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

  int n;
  int64_t a, b, ans = 0;
  cin >> n >> a >> b;
  vector < int64_t > x(n);
  for (int64_t &y: x)
    cin >> y;
  for (int i = 1; i < n; ++i) 
    ans += min((x[i] - x[i - 1]) * a, b);
  cout << ans << '\n';
}

Measured memory_bytes: 1024
/*
      Ashraful Islam Paran
      27-August-2020
      22:10:03
*/
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i <= 0; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define ull unsigned long long
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    // online submission
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, ans = 0;
    cin >> n;
    int c[10][10] = {{0}};
    fo(i, 1, n + 1)
    {
        int a = i;
        int b = a % 10;
        while (a >= 10)
            a /= 10;
        c[a][b]++;
    }
    f(10)
    {
        fo(j, 0, 10)
        {
            ans += c[i][j] * c[j][i];
        }
    }

    cout << ans << endl;

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

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef int64_t Int;
typedef std::vector<Int> LI;
const double pi = 3.14159265358979323846264338;
const Int mod = 1000000007;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(Int& x) { if( scanf("%" PRId64, &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
template<> void scan1(LI& xs) { for(Int &x : xs) scan1(x); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

template<typename T>
struct Maybe {
   T x;
   bool valid;
   Maybe() : valid(false) {}
   Maybe(T x_) : x(x_), valid(true) {}
   operator T() const {
      assert( valid );
      return x;
   }
};

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string ss, ts; scan(ss, ts);
      std::reverse(ss.begin(), ss.end());
      puts(ss == ts ? "YES" : "NO");
   }
};

int main() {
   loop std::unique_ptr<Solver>(new Solver())->solve();
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007ll
#define INF 1000000000ll
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
#define pb push_back

string a,b,c;
ll n;
ll memo[50][2];

ll dfs(ll pos, ll carry) {
	if(pos==n) {
		if(!carry) return 1;
		else return 0;
	}
	if(memo[pos][carry]!=-1) return memo[pos][carry];
	ll ret=0;
	REP(i,10) REP(j,10) REP(k,10) {
		if(a[pos]!='?'&&a[pos]-'0'!=i) continue;
		if(b[pos]!='?'&&b[pos]-'0'!=j) continue;
		if(c[pos]!='?'&&c[pos]-'0'!=k) continue;
		if(pos==0&&(i==0||j==0||k==0)) continue;
		ll g=k;
		if(carry) g+=10;
		if(i+j+1==g) ret+=dfs(pos+1,1);
		if(i+j==g) ret+=dfs(pos+1,0);
	}
	return memo[pos][carry]=ret%MOD;
}

ll solve() {
	n=(ll)a.size();
	REP(i,50) REP(j,2) memo[i][j]=-1;
	return dfs(0,0);
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1) {
		cin>>a;
		if(a=="0") break;
		cin>>b>>c;
		cout<<solve()<<endl;
	}
}




Measured memory_bytes: 3204
s=input()
t=input()
n=len(t)
lens=len(s)
mx=0
for i,j in enumerate(s):
    if i+n>len(s):
        break
    sm=0
    for k,l in enumerate(t):
        if l==s[i+k]:
            sm+=1
    mx=max(sm, mx)

print(len(t)-mx)

Measured memory_bytes: 9120
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<Integer> set = new HashSet<>();
		String result = "YES";
		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			if (set.contains(num)) {
				result = "NO";
				break;
			}
			set.add(num);
		}
		sc.close();
		System.out.println(result);
	}
}

Measured memory_bytes: 98648
#include <cstdio>
#include <cstring>
#include <algorithm>
int n;
char s[1000];
using namespace std;
int main(){
	scanf("%d", &n);
	scanf("%s", s);
	if(strlen(s)%2==1) {
		printf("No");
		return 0;	
	}
	for(int i = 0; i < strlen(s)/2; i++){
		if(s[i]!=s[i+strlen(s)/2]) {
			printf("No");
			return 0;
		}
	}
	printf("Yes");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
  string s;
  getline(cin, s);
  for (int i = 0; i < s.size(); ++i)
  {
    if (isupper(s[i]))
      s[i] = tolower(s[i]);
    else if (islower(s[i]))
      s[i] = toupper(s[i]);
  }
  cout << s << endl;

  return 0;
}



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

int main()
{
    long long t=1,n,i,a,b,c,d;
    //cin>>t;
    while(t--)
    {
        cin>>a>>b>>c>>d;
        cout<<max(max(a*c,a*d),max(b*c,b*d))<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3616
module Point = struct

  type t = { x : float; y : float }

  let make x y = { x; y }

  let sum a b = { x = a.x +. b.x; y = a.y +. b.y }

  let diff a b = { x = a.x -. b.x; y = a.y -. b.y }

  let multi p k = { x = p.x *. k; y = p.y *. k }

  let norm p = p.x *. p.x +. p.y *. p.y

  let dot a b = a.x *. b.x +. a.y *. b.y

  let project p1 p2 p =
    let base = diff p2 p1 in
    dot (diff p p1) base /. norm base
    |> multi base
    |> sum p1

end

open Point

let () =
  let xp1, yp1, xp2, yp2 = Scanf.scanf "%f %f %f %f " (fun a b c d -> a,b,c,d) in
  let p1 = make xp1 yp1 in
  let p2 = make xp2 yp2 in
  let q = Scanf.scanf "%d " (fun i -> i) in
  for _ = 0 to q - 1 do
    let x, y = Scanf.scanf "%f %f " (fun x y -> x,y) in
    let p = make x y |> project p1 p2 in
    Printf.printf "%.10f %.10f\n" p.x p.y
  done

Measured memory_bytes: 3496
n,k = map(int,input().split())
lst = [int(i) for i in input().split()]

for i in range(n):
    if lst[i] == 1:
        start = i

l = start #1より左側の数字数
r = n - start -1 #１より右側の数字数

if k==1:
    print(n)
elif n==k:
    print(1)

else:
    if l == 0: #numl : 左側領域の試行回数
        numl = 0
    elif l <= k-1:
        numl = 1
    elif l % (k-1) == 0:
        numl = l // (k-1)
    else:
        numl = (l // (k-1)) + 1
    
    if r == 0: #numr : 右側領域の試行回数
        numr = 0
    elif r <= k-1:
        numr = 1
    elif r % (k-1) == 0:
        numr = r // (k-1)
    else:
        numr = (r // (k-1)) + 1
    pat1 = numr + numl
    
    if (n-k)%(k-1)==0:
        pat2 = 1 + (n-k)//(k-1)
    else:
        pat2 = 2 + (n-k)//(k-1)
    print(min(pat1,pat2))

Measured memory_bytes: 13880
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed parsing")
}

use std::cmp::{min};
use std::num;

fn calc_norm(a : &Vec<i64>, b : &Vec<i64>) -> i64 {
    let mut sum = 0;
    for i in 0..a.len() {
        sum += (a[i] - b[i]).pow(2);
    }
    
    sum
}

fn main() {
    
    let n = read::<usize>();
    let d = read::<usize>();
    let x = (0..n).map(|_|{
        (0..d).map(|_|{
            read::<i64>()
        }).collect::<Vec<i64>>()
    }).collect::<Vec<Vec<i64>>>();
    
    
    let mut sum = 0;
    for i in 0..n {
        for j in i..n {
            let a = calc_norm(&x[i], &x[j]);
            let mut cnt = 1;
            loop {
                if cnt * cnt == a { sum += 1; break;}
                else if cnt * cnt > a { break;} 
                
                cnt += 1;
            }
        }
    }
    
    println!("{}",sum);
}

Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 3010;

int n, m;
char s[N][N];
int jc[N][N], oc[N][N];

int main() {
#ifdef LBT
    freopen("test.in", "r", stdin);
    int nol_cl = clock();
#endif

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = m; j; --j) oc[i][j] = oc[i][j + 1] + (s[i][j] == 'O');
    for (int j = 1; j <= m; ++j)
        for (int i = n; i; --i) jc[i][j] = jc[i + 1][j] + (s[i][j] == 'I');
    ll ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            if (s[i][j] == 'J')
                ans += oc[i][j] * jc[i][j];
    printf("%lld\n", ans);

#ifdef LBT
    LOG("Time: %dms\n", int((clock() - nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
    return 0;
}


Measured memory_bytes: 82584
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007
#define mp(a,b) make_pair(a,b)

ll max(ll a, ll b){
    if (a > b) return a;
    else return b;
}

ll N,K;
ll A[200010];
ll B[200010];
set<ll> S;
vector<ll>st;

int main(){
    cin >> N >> K;
    rep(i,N){
        cin >> A[i];
        S.insert(A[i]);
        B[A[i]]++;
    }
    rep(i,200010){
        if(B[i] > 0){
            st.push_back(B[i]);
        }
    }
    sort(all(st));
    ll ans = 0;
    rep(i,max(0,S.size()-K)){
        ans += st[i];
    }
    cout << ans << endl;
   
    return 0;
}


Measured memory_bytes: 14968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

int main(){
    int H, W, N;
    cin >> H >> W >> N;

    int s_r, s_c;
    cin >> s_r >> s_c;
    s_r--;
    s_c--;

    string S, T;
    cin >> S >> T;

    {
        int l = -1, r = W;
        for(int i=N - 1;i>=0;i--){
            if(T[i] == 'L'){
                r = min(W, r + 1);
            }else if(T[i] == 'R'){
                l = max(-1, l - 1);
            }
            if(S[i] == 'R'){
                r--;
            }else if(S[i] == 'L'){
                l++;
            }
            if(r - l <= 1) break;
        }
        if(s_c <= l || r <= s_c){
            cout << "NO" << endl;
            return 0;
        }
    }
    {
        int l = -1, r = H;
        for(int i=N - 1;i>=0;i--){
            if(T[i] == 'U'){
                r = min(H, r + 1);
            }else if(T[i] == 'D'){
                l = max(-1, l - 1);
            }
            if(S[i] == 'D'){
                r--;
            }else if(S[i] == 'U'){
                l++;
            }
            if(r - l <= 1) break;
        }
        if(s_r <= l || r <= s_r){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;

    return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e5+5;
string s;
int n, m;
ll b, c;
vector<P> p;
int g[N];

int main () {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> m;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  rep(i,m) {
    cin >> b >> c;
    p.push_back(P(c,b));
  }
  VSORT(a);
  sort(p.rbegin(), p.rend());
  int j = 0;
  for(auto x : p) {
    int k = 0;
    while(k < x.second && a[j] < x.first) {
      a[j] = x.first;
      k++; j++;
    }
    if(a[j] >= x.first) break;
  }
  // rep(i,p.size()) cout << p[i].first << " : " << p[i].second << endl;
  // rep(i,p.back().first) a[i] = a[i] < p.back().second ? p.back().second : a[i];
  ll result = 0;
  rep(i,n) result += a[i];
  // rep(i,n) cout << a[i] << endl;
  pl(result);
  br();
}


Measured memory_bytes: 2168
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).begin(), (x).end(), greater<int>() )
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int num;
double weight,height;
char trash;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	while(cin >> num >> trash >> weight >> trash >> height){
		if(weight >= height*height*25) cout << num << endl;
	}
}

Measured memory_bytes: 1236
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const long double PI = acos(-1.0L);
const long long MOD = 1000000007LL;
// const long long MOD = 998244353LL;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    while (1) {
		int N,A,B,C,X; cin >> N >> A >> B >> C >> X;
		if (N+A+B+C+X==0) break;
		vector<int> Y(N);
		rep(i,N) cin >> Y[i];

		int now = 0;
		int ans = -1;
		if (X==Y[0]) {
			now++;
			if (now == N) ans = 0;
		}
		rep(i,10000) {
			X = (A*X+B)%C;
			if (now < N && Y[now]==X) {
				now++;
				if (now == N) ans = i+1;
			}
		}
		cout << ans << endl;

	}
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#pragma GCC optimize ("O3")
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#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++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef long double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 188;
const int SIZE = SIZE2;
const LL p = 7 + 1e9;
const LL INF = 1LL << 61;
const long double EPS = 1e-7;
ut N, M, K, L=0,R=1, H, W, Q, D, T;
// ut A,B,C,D,E,F,G,H,I,J,O,P,Q,R,T,U;
VI edges[SIZE];
LL A[SIZE][SIZE];

LL solve() {
	string s;
	cin >> s;
	LL nowA = 0;
	LL ans = 0;
	REP(i, s.size()) {
		if (s[i] == 'A') nowA++;
		else if (s.size() != i + 1 and s[i] == 'B' and s[i + 1] == 'C') {
			ans += nowA;
			i++;
		}
		else {
			nowA = 0;
		}
	}
	cout << ans << endl;
	return 0;
}
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	solve();
	//	cin >> N;
	return 0;
}


Measured memory_bytes: 848
s = str(input())
k = int(input())

n = len(s)
S = set()
import heapq

for i in range(n):
    for j in range(i+1, n+1):
        if j-i > k:
            continue
        t = s[i:j]
        S.add(t)
S = list(S)
#print(S)
S.sort()
print(S[k-1])


Measured memory_bytes: 70488
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    int k = in.ni(), n = in.ni();
    int[] x = new int[n];
    int max = 0;
    for (int i = 0; i < n; i++) {
      x[i] = in.ni();
      if (i > 0) {
        max = Math.max(max, x[i] - x[i - 1]);
      }
    }
    max = Math.max(max, k - x[n - 1] + x[0]);
    out.println(k - max);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


Measured memory_bytes: 48984
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let v: Vec<u32> = read_vec();
    let n = v[0];
    let m = v[1];
    let ab: Vec<Vec<u32>> = read_vec2(m);
    let mut cnt: Vec<u32> = vec![0; n as usize];

    for a in ab {
        for b in a {
            cnt[(b - 1) as usize] += 1;
        }
    }

    for c in cnt {
        println!("{}", c);
    }
}


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

using namespace std;

int main(int argc, char * argv[])
{
	string s;
	while (getline(cin, s)) {
		string::size_type index_c = s.find_first_of('C', 0);
		string::size_type index_f = s.find_first_of('F', index_c);
		if (index_c != string::npos && index_f != string::npos
		  && index_f > index_c) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
/*
author : seryu
title : ABC167D_"Teleporter"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	ll n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {cin >> a[i];a[i]--;}
	vector<bool> been(n, false);
	int loop_start = 0;
	int now = 0;
	int non_loop = 0;
	int loop = 0;
	vector<int> path;
	rep(i, n)
	{
		been[now] = true;
		path.push_back(now);
		now = a[now];
		if(been[now])
		{	
			loop_start = now;
			non_loop = i+1;
			while(true)
			{
				now = a[now];
				loop++;
				if(now == loop_start)break;
			}
			break;
		}
	}
	non_loop -= loop;
	int ans;
	if(k <= non_loop)
	{
		ans = path[k]+1;
	}
	else
	{
		k -= non_loop;
		k %= loop;
		ans = path[non_loop + k]+1;
	}
	cout << ans << endl;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 5104
// Hint: Don't look, No need, Let'em Play.

#pragma optimize("O2")
#include <bits/stdc++.h>
#include "bits/stdc++.h"

using namespace std;

#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

void solve() {
    char c;
    cin >> c;
    if (isupper(c)) cout << char('A');
    else cout << 'a';
}

signed main() {
    fast;
    int t = 1; //cin >> t;
    while (t--) {
        solve();
    }


  return 0;
}

Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static final int MOD = 1_000_000_007;

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

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

        List<Work> works = new ArrayList<>();

        for (int i = 0; i < N; i++) {
//            A[i] = sc.nextInt();
//            B[i] = sc.nextInt();
            works.add(new Work(sc.nextInt(), sc.nextInt()));
        }

        works.sort(Work::compareTo);

        int time = 0;
        for (Work w : works) {
            time += w.cost;
            if (time > w.deadline) {
                System.out.println("No");
                return;
            }
        }

        System.out.println("Yes");

//        for (Work w : works) {
//            System.out.println(w.cost + " " + w.deadline);
//        }
    }

    private static class Work implements Comparable {

        private final int cost, deadline;

        Work(int cost, int deadline) {
            this.cost = cost;
            this.deadline = deadline;
        }

        @Override
        public int compareTo(Object o) {
            Work w = (Work) o;

            if (deadline != w.deadline) {
                return deadline - w.deadline;
            }

            return w.cost - cost;
        }
    }
}


Measured memory_bytes: 105332
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

N, W = map(int, input().split())
w = []
v = []
for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

V = sum(v)

dp = [ [INF for _ in range(V+1)] for _ in range(N+1) ]

dp[0][0] = 0

for i in range(N):
    for j in range(V+1):
        if j - v[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i][j-v[i]]+w[i])

#print(dp[N])

ans = 0
for v in range(V+1):
    if dp[N][v] <= W:
        ans = v

print(ans)


Measured memory_bytes: 314932
#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;

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

const string YES = "yes";
const string NO = "no";

void solve(std::string S)
{
    int loop = S.size();
    REP(i, loop)
    {
        char c = S[0];
        S = S.substr(1);
        if (S.find(c) != string::npos)
        {
            cout << NO << endl;
            return;
        }
    }

    cout << YES << endl;
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


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

for i in range(num):
        orderList = input().split()
        a = int(orderList[1])
        b = int(orderList[2])
        if orderList[0] == "replace":
                s = s[:a] + orderList[3] + s[b + 1:]
        elif orderList[0] == "reverse":
                s = s[:a] + s[a:b + 1][::-1] + s[b + 1:]
        else:
                print(s[a:b + 1])


Measured memory_bytes: 5608
K = int(input())
div50 = K // 50
mod50 = K % 50

print(50)
if mod50 == 0:
    print(" ".join(map(str, [div50 + 49] * 50)))
else:
    ans = []
    for i in range(50):
        base_a = div50 + 49
        if i < mod50:
            ans.append(base_a + 50 - (mod50 - 1))
        else:
            ans.append(base_a - mod50)
    print(" ".join(map(str, ans)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, p;
    cin >> n >> p;
    int a[51];
    rep(i, n) {
        cin >> a[i];
        if (a[i] % 2 != 0){
            ll int ans = (ll int)pow(2, n - 1);
            cout << ans << endl;
            return 0;
        }
    }
    if (p == 1) {
        cout << 0 << endl;
    } else {
        ll int ans = (ll int)pow(2, n);
        cout << ans << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    ll n; cin >> n;
    vector<Pll> happy(n);
    priority_queue<Pll> pq;
    rep(i,n){
        ll a,b; cin >> a >> b;
        happy[i] = Pll(a,b);
        pq.push(Pll(a+b, i));
    }

    ll taka = 0, aoki = 0;
    ll count = 0;
    while(pq.size()){
        Pll p = pq.top();pq.pop();
        if(count%2 == 0)taka += happy[p.second].first;
        else aoki += happy[p.second].second;
        count++;
    }

    cout << taka - aoki << endl;
    return 0;
}

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  
  vector<int> buttons(n);

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

  bool ok = false;
  int cnt = 0;
  int pos = 0;
  while (true) {
    int nextPos = buttons.at(pos);
    cnt++;
    if (nextPos == 2) {
      ok = true;
      break;
    }
    if (nextPos - 1 == pos) {
      break;
    }
    
    if (cnt > n) {
      break;
    }
      
    pos = nextPos - 1;
  }
      
  if (ok) {
    cout << cnt << endl;
  } else {
    cout << -1 << endl;
  }
}

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

int main()
{
  int sx,sy;
  for(;cin>>sx>>sy,sx||sy;)
    {
      //      bool map[10][10];
      //      memset(map,false,sizeof(map));
      int dx[]={-2,-2,-1,0,1,2,2,2,1,0,-1,-2};
      int dy[]={0,-1,-2,-2,-2,-1,0,1,2,2,2,1};
      int n;
      cin>>n;
      int px,py;
      vector<pair<int,int> >pos;
      vector<pair<int,int> >pos2;
      pos.push_back(make_pair(sx,sy));
      bool  flag = true;
      for(int i=0;i<n;i++)
	{
	  cin>>px>>py;

	  for(int j=0;j<pos.size()&&flag;j++)
	    {
	      int x=pos[j].first;
	      int y=pos[j].second;
	      for(int k=0;k<12;k++)
		{
		  if(x+dx[k]>=0 &&x+dx[k]<10 &&
		     y+dy[k]>=0 &&y+dy[k]<10 &&
		     x+dx[k]>=px-1 &&x+dx[k]<=px+1 &&
		     y+dy[k]>=py-1 &&y+dy[k]<=py+1
		     )
		    pos2.push_back(make_pair(x+dx[k],y+dy[k]));
		}
	    }
	  if(pos2.size()<=0)
	    flag=false;
	  else
	    {
	      pos.clear();
	      for(int xx=0;xx<pos2.size();xx++)
		pos.push_back(pos2[xx]);
	      pos2.clear();
	    }
	}
      if(flag)
	cout<<"OK"<<endl;
      else
	cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1200
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <cctype>
#include <iostream>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <utility>
using namespace std;
int size(string x){
	string::size_type size=x.size();
	return size;
}
#define fu(l,k) for(int i=l;i<k;i++)
#define fd(l,k) for(int i=l;i>k;i--)
#define sort(ss) sort(ss.begin(), ss.end())
#define rsort(ss) sort(ss.rbegin(), ss.rend())
typedef  vector<string> vs;
typedef  vector<int> vi;
double pi(){
	return acos(-1.0);
}
typedef set<int> set_i;
typedef set<string> set_s;
int INF=1000000;
int main(){
	string ss;
	cin>>ss;
	int sr=size(ss);
	for(int i=sr-1;i>=0;i--){
		if(i==0) cout<<ss[i]<<endl;
		else cout<<ss[i];
	}
}

Measured memory_bytes: 1176
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  if (N <= 9) {
    std::cout << N << std::endl;
  } else if (N <= 99) {
    std::cout << 9 << std::endl;
  } else if (N <= 999) {
    std::cout << N - 99 + 9 << std::endl;
  } else if (N <= 9999) {
    std::cout << 909 << std::endl;
  } else if (N <= 99999) {
    std::cout << N - 9999 + 909 << std::endl;
  } else if (N <= 100000) {
    std::cout << 90909 << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
namespace practice
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            while (n-- > 0)
            {
                string bun = Console.ReadLine();
                Console.WriteLine(bun.Replace("Hoshino", "Hoshina"));
            }
        }
    }
}

Measured memory_bytes: 8736
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define INF 1000000000000
typedef long long ll;

char masu[6][6];

int main() {
	int h, w, k, ans = 0, sumK = 0;

	cin >> h >> w >> k;
	int flagH = 1 << h, flagW = 1 << w;

	REP(i, h) {
		REP(j, w) {
			cin >> masu[i][j];
		}
	}

	REP(i, flagH) {
		REP(j, flagW) {
			REP(x, h) {
				REP(y, w) {
					if (((i>> x) & 1) == 0 && ((j >> y) & 1) == 0 && masu[x][y]=='#') {
						sumK++;
					}
				}
			}
			if (sumK == k) {
				ans++;
			}
			sumK = 0;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3612