akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define Rep(n) for (ll _ = 0; _ < (ll)(n); _++)

template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
ll min(int a,ll b){return min((ll)a,b);} ll min(ll a,int b){return min(a,(ll)b);}
template <class S> void print(vector<S> &v){for(ll i=0; i<(ll)v.size(); i++){cerr << v[i] << ' ';}cerr << endl;}
template <class S> void print(vector<vector<S>> &v) {for (ll i = 0; i < (ll)v.size(); i++) {for (ll j = 0; j < (ll)v[i].size(); j++) {cerr << v[i][j] << ' ';}cerr << endl;}}

typedef long double ld;

int main(){
	cout << fixed << setprecision(20);
	int n,k; cin >> n >> k;
	map<int,int> m;
	int shift = 0;
	int d = n;
	while(d > 0){
		if(d << shift >= k){
			m[shift]++;
			d--;
		}else{
			shift++;
		}
	}
	ld p = 0;
	for(auto [k,v]: m){
		p += v / (ld)n / (1 << k);
	}
	cout << p << endl;
}

Measured memory_bytes: 3688
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <set>
#include <string>

using namespace std;

int main() {
  long a, b, n;

  cin >> a >> b >> n;

  int max_val = 0;
  double b_reverse = 1 / b;

  int left, right;

  long x = min(b - 1, n);
  left = a * x / b;
  right = x / b;
  cout << left - a * right << endl;

  // if (b > n) {
  //   // b > nの場合、x = nのときに最大となるため、そのまま出力
  //   cout << floor(a * modf((double)n / b, &trash)) << endl;
  // } else {
  //   cout << a * modf((double)(b - 1) / b, &trash) << endl;
  //   // for (int i = 0; i < n / b; i++) {
  //   //   int res = floor(a * modf((double)(i * b - 1) / b, &trash));
  //   //   if (res > max_val) max_val = res;
  //   // }

  //   // cout << max_val << endl;
  // }

  // for (long x = 0; x <= n; x++) {
  //   int res;

  //   int left, right;

  //   left = a * x * b_reverse;
  //   right = x * b_reverse;
  //   res = left - a * right;

  //   if (res > max_val) {
  //     max_val = res;
  //   }
  // }

  // cout << max_val << endl;

  return 0;
}

Measured memory_bytes: 3168
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;
int  main(){
	// #ifndef ONLINE_JUDGE
 //    // for getting input from input.txt
 //    freopen("input.txt", "r", stdin);
 //    // for writing output to output.txt
 //    freopen("output.txt", "w", stdout);
	// #endif
	int a;string s;cin>>a>>s;
	if(a>=3200){
		cout<<s<<endl;
	}
	else{
		cout<<"red"<<endl;
	}
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

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

    int N;
    std::cin >> N;

    vector<int> A(N);
    REP(i, N) {
        std::cin >> A[i];
    }

    vector<int> table(N);
    set<int>    ans;
    for(int i = N; i >= 1; i--) {
        bool flag = A[i - 1];
        int  mul  = 2;
        while(true) {
            if(i * mul <= N) {
                auto itr = ans.find(i * mul);
                if(itr != ans.end()) {
                    flag = !flag;
                }
                mul++;
            }
            else {
                break;
            }
        }

        if(flag) {
            ans.insert(i);
        }
    }

    std::cout << ans.size() << std::endl;
    for(const auto& v : ans) {
        std::cout << v << " ";
    }
    if(ans.size() != 0) std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 8576
/**
 * ICPC Ranking
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

import static java.lang.Integer.parseInt;

public class Main {

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

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int M, T, P, R;
			StringTokenizer st = new StringTokenizer(line);
			M = parseInt(st.nextToken());
			T = parseInt(st.nextToken());
			P = parseInt(st.nextToken());
			R = parseInt(st.nextToken());
			if ((M | T | P | R) == 0) break;

			Team[] teams = new Team[T + 1];
			for (int i = 0; i <= T; i++) {
				teams[i] = new Team(i, P);
			}
			teams[0].passed = -1;

			for (int i = 0; i < R; i++) {
				int m, t, p, j;
				st = new StringTokenizer(br.readLine());
				m = parseInt(st.nextToken());
				t = parseInt(st.nextToken());
				p = parseInt(st.nextToken());
				j = parseInt(st.nextToken());
				teams[t].submit(m, p, j);
			}
			Arrays.sort(teams);

			StringBuilder sb = new StringBuilder();
			for (int i = 0; i < T; i++) {
				if (i == 0) {
					sb.append(teams[i].id);
				} else {
					if (teams[i - 1].passed == teams[i].passed && teams[i - 1].elapsed == teams[i].elapsed) {
						sb.append("=" + teams[i].id);
					} else {
						sb.append("," + teams[i].id);
					}
				}
			}
			System.out.println(sb.toString());
		} //end while
	} //end main
}

class Team implements Comparable<Team> {
	int id;
	int elapsed = 0;
	int passed = 0;
	int[] penalty;

	Team(int id, int problem) {
		this.id = id;
		penalty = new int[problem + 1];
	}

	void submit(int m, int p, int j) {
		if (j == 0) {
			elapsed += m + penalty[p] * 20;
			passed++;
		} else {
			penalty[p]++;
		}
	}

	public String toString() {
		return String.format("%d,%d,%d", id, passed, elapsed);
	}

	@Override
	public int compareTo(Team o) {
		int ret = 0;
		if (this.passed != o.passed) {
			ret = -(this.passed - o.passed);
		} else {
			if (this.elapsed != o.elapsed) {
				ret = this.elapsed - o.elapsed;
			} else {
				ret = -(this.id - o.id);
			}
		}
		return ret;
	}
}

Measured memory_bytes: 26840
#include <iostream>
#include <cstdio>

int main () {
  	int a , b ;
  	std::cin >> a >> b ;
  	if ( b >= a || b * 2 >= a ) return puts ("0") , 0 ;
  	printf ("%d\n" , a - b * 2 ) ;
	return 0 ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long sum=0, ans=0;
    int i,j,n,m;
    cin>>n>>m;
    int *a = new int[n];
    int *b = new int[m];
    for(i=0;i<n;i++){
        cin>>a[i];
        ans+=a[i];
    }
    for(i=0;i<m;i++){
        cin>>b[i];
    }
    for(i=0;i<m;i++){
        sum+=ans*b[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
vector<pii> student;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int a;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		student.push_back({a, i});
	}
	sort(student.begin(), student.end());
	for (int i = 0; i < student.size(); ++i)
		cout << student[i].second << ' ';
	cout << '\n';
	return 0;
}

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

int main(){
	int a,b;
  cin>>a;
  if(a==000) b=0;
  else if(a==100||a==10||a==001) b=1;
  else if(a==110||a==101||a==11) b=2;
  else b=3;
  printf("%d",b);
}

Measured memory_bytes: 3720
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int H, W;
	cin >> H >> W;
	int dp[10][10] = {};
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			int a;
			cin >> a;
			dp[i][j] = a;
		
		}
	}
	for (int k = 0; k < 10; k++) {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
			}
		}
	}
	long long int sum = 0;
	for (int i = 0; i < H * W; i++) {
		int a;
		cin >> a;
		if (a != -1) {
			sum = sum + dp[a][1];
		}
	}
	cout << sum;
}

Measured memory_bytes: 256
N = int(input())
t = 0
for i in range(N):
    a, b = [int(x) for x in input().split()]
    if a != b:
        t = 0
    else:
        t += 1
    if t > 2:
        break
if t > 2:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9164
from fractions import gcd
from functools import reduce

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

MOD = 1000000007

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

a_lcm = lcm(*a) % MOD

def pow(x, y):
    if y == 0:
        return 1
    ans = 1
    while y > 1:
        if y % 2 != 0:
            ans *= x
            ans %= MOD 
        x *= x
        x %= MOD 
        y //= 2
    return ans * x % MOD

ans = 0
for ai in a:
  ans += (a_lcm * pow(ai, MOD - 2)) % MOD
  ans %= MOD

print(ans)


Measured memory_bytes: 6140
#include<stdio.h>

int main(){

int n, x, i=0;
int a, b, c;
while (1) {
 scanf("%d %d", &n, &x);
  if (n == 0 && x == 0) {
   break;
    }
     for (a = 1; a <= n; a++) {
      for (b = a + 1; b <= n; b++) {
      c = x - a - b;
       if (b < c && c <= n) {
       i++;
       }
     }
   }
 printf("%d\n", i);
 i=0;
 }
}

Measured memory_bytes: 2744
import sys
def main():
    input = sys.stdin.readline
    H, W = map(int, input().split())
    A = []
    B = []
    M = 80 * (H + W)
    for _ in range(H):
        a = tuple(map(int, input().split()))
        A.append(a)
    for _ in range(H):
        b = tuple(map(int, input().split()))
        B.append(b)
    AB = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            AB[i][j] = abs(A[i][j] - B[i][j])
    l = [set([]) for _ in range(W)]
    lt = [set([]) for _ in range(W)]
    for i in range(H):
        for j in range(W):
            if i == 0 and j == 0:
                lt[j].add(AB[0][0])
            else:
                t = AB[i][j]
                if i > 0:
                    for k in l[j]:
                        lt[j].add(k+t)
                        lt[j].add(abs(k-t))
                if j > 0:
                    for k in lt[j-1]:
                        lt[j].add(k+t)
                        lt[j].add(abs(k-t))
        l = lt
        lt = [set([]) for _ in range(W)]
    return min(l[-1])
print(main())



Measured memory_bytes: 177800
freq ch [] = 0
freq ch (c:cs) = if ch==c then 1+freq ch cs else freq ch cs

main = do
  s <- getLine
  putStrLn (if (freq 'a' s) == 1 && (freq 'b' s) == 1 && (freq 'c' s) == 1 then "Yes" else "No")


Measured memory_bytes: 380
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)


int main(){
    ll x,y;
    cin>>x>>y;
    if(x*4<y||y%2!=0){
        cout<<"No"<<endl;
        return 0;
    }

    if(x*2>y){
        cout<<"No"<<endl;
        return 0;
    }

     cout<<"Yes"<<endl;
        return 0;




    

}









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

using namespace std;
const int N = 1000;
string s[N];
int color[N][N];
int main(){
  int n,m,k;
  cin>>n>>m>>k;
  for(int i=0;i<n;i++) cin>>s[i];
  int cnt=1;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      if(s[i][j]=='#'){
        color[i][j]=cnt;
        for(int k=j-1;k>=0;k--){
          if(!color[i][k]&&s[i][k]!='#') color[i][k]=cnt;
          else break;
        }
        for(int k=j+1;k<m;k++){
          if(!color[i][k]&&s[i][k]!='#') color[i][k]=cnt;
          else break;          
        }
        cnt++;
      }
    }
  }
  int fir=-1;
  for(int i=0;i<n;i++){
    if(color[i][0]){
      for(int k=i-1;k>=0;k--){
        if(color[k][0]) break;
        for(int j=0;j<m;j++) color[k][j]=color[k+1][j];
      }
    }
  }
  for(int i=n-1;i>=0;i--){
    if(color[i][0]){
      for(int k=i+1;k<n;k++){
        if(color[k][0]) break;
        for(int j=0;j<m;j++) color[k][j]=color[k-1][j];
      }
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cout<<color[i][j]<<' ';
    }
    cout<<endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  set<int> flag;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    if(flag.find(t) != flag.end()) {
      cout << "NO" << endl;
      return 0;
    }
    flag.insert(t);
  }
  cout << "YES" << endl;
}

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


int main() {
  char moji;
  cin >> moji;
  if(moji == 'A' || moji == 'B' || moji == 'C' || moji == 'D'|| moji == 'E'|| moji == 'F'|| moji == 'G'|| moji == 'H'|| moji == 'I'|| moji == 'J'
    || moji == 'K'|| moji == 'L'|| moji == 'M'|| moji == 'N'|| moji == 'O'|| moji == 'P'|| moji == 'Q'|| moji == 'R'
    || moji == 'S'|| moji == 'T'|| moji == 'U'|| moji == 'V'|| moji == 'W'|| moji == 'X'|| moji == 'Y'|| moji == 'Z'){
  	cout << "A" << endl;
  }
  else{
  	cout << "a" << endl;
  }
}

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

int main(){
	int n;
	
	while( cin >> n , n ){
		int sum = -n;
		for(int i=1 ; i*i<=n ; ++i ){
			if( n%i == 0 ){
				sum += i + n/i;
				if( i == n/i ) sum -= i;
			}
		}
		if( n > sum )
			cout << "deficient number" << endl;
		else if( n == sum )
			cout << "perfect number" << endl;
		else
			cout << "abundant number" << endl;
	}
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<ll>;
using P = pair<ll,ll>;


int main(){
    ll n,m;cin >>n>>m;
    cout <<abs((n-2)*(m-2))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;;
int main(){
     int N,sum;
     vector<int> L;
     cin >> N;
     L.resize(N);
     for(int i = 0; i < N; i++){
          cin >> L[i];
     }
     sort(L.begin(),L.end());
     sum = 0;
     for(int i = 0; i < N - 1; i++){
          sum += L[i];
     }
     if(L[N - 1] < sum){
          cout << "Yes" << endl;
     }else{
          cout << "No" << endl;
     }
     return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define sum(a, b) ((a+b)*(b+1-a)/2)

int main(void)
{
    int i, j, n, count;

    while(scanf("%d", &n), n)
    {
        count = 0;

        for(i=1; i<n; i++)
            for(j=i+1; j<n; j++)
                if(sum(i, j) == n) count++;

        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
int sumDigit(int a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int ans = 0;
	for (int i = 1; i < N + 1; i++) {
		int sum = sumDigit(i);
		if (sum >= A && sum <= B) {
			ans += i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n, k;
    string s;
    cin >> n >> s >> k;
    k--;
    rep(i,n){
        cout << (s[k] == s[i] ? s[i] : '*');
    }
    cout << endl;
}

Measured memory_bytes: 3584
N = int(input())
S = [int(input()) for _ in range(N)]

ans = sum(S)
S.sort()
if ans%10 == 0:
    for i in range(N):
        if S[i]%10 == 0:
            continue
        ans -= S[i]
        break

if ans%10 == 0:
    ans = 0
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define MAX_N (200000L)
#define MAX_Q (200000L)

using namespace std;

void dfs(const vector<vector<long>> &adj_lists, const vector<long> &sum_xs,
         vector<long> &cnts, long cur, long par, long sum) {
  const long sum_nxt = sum + sum_xs[cur];
  cnts[cur] = sum_nxt;
  for (long nxt : adj_lists[cur]) {
    if (nxt != par) {
      dfs(adj_lists, sum_xs, cnts, nxt, cur, sum_nxt);
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long N, Q, as[MAX_N], bs[MAX_N], ps[MAX_Q], xs[MAX_Q];
  scanf("%ld %ld", &N, &Q);
  for (long i = 0; i < N - 1; i++) {
    scanf("%ld %ld", &as[i], &bs[i]);
    as[i]--;  // NOTE : modified input
    bs[i]--;  // NOTE : modified input
  }
  for (long q = 0; q < Q; q++) {
    scanf("%ld %ld", &ps[q], &xs[q]);
    ps[q]--;  // NOTE : modified input
  }

  // create graph
  vector<vector<long>> adj_lists(N, vector<long>());
  for (long i = 0; i < N - 1; i++) {
    const long a = as[i], b = bs[i];
    adj_lists[a].push_back(b);
    adj_lists[b].push_back(a);
  }

  // sum of xs for each node
  vector<long> sum_xs(N, 0);
  for (long q = 0; q < Q; q++) {
    const long p = ps[q], x = xs[q];
    sum_xs[p] += x;
  }

  // solve
  vector<long> cnts(N, 0);
  dfs(adj_lists, sum_xs, cnts, 0, -1, 0);

  // print answer
  for (long i = 0; i < N; i++) {
    printf("%ld ", cnts[i]);
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 38272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,sum=0;
	cin>>n>>k;
	int m[n];
	for(int i=0;i<n;i++)
		cin>>m[i];
	for(int i=0;i<n-1;i++)
		for(int j=i+1;j<n;j++)
			if(m[i]<m[j])swap(m[i],m[j]);
	for(int i=0;i<k;i++)
		sum+=m[i];
	cout << sum; 
}

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

const int maxn = 2e5 + 10;

int n, k;
int a[maxn];
long double ans;

void in();
void solve();
void out();

int main(){
    in();
    solve();
    out();
}

void in(){
    ios::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i]++;
    }
}

void solve(){
    int maxsum = 0;
    int sum = 0;
    for(int i = 0; i < k; i++)
        sum += a[i];
    maxsum = sum;
    for(int i = k; i < n; i++){
        sum -= a[i - k] - a[i];
        maxsum = max(maxsum, sum);
    }
    ans = (long double)maxsum / 2;
}

void out(){
    cout << fixed << setprecision(20) << ans;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define SIZE 200005
#define INF 1000000000

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

ll A[SIZE],memo[SIZE];
int right[SIZE];
ll ans[SIZE];
ll sum[SIZE];
ll rt[SIZE];
P pos[SIZE];
int n;

ll get(int s,int t)
{
	return rt[t]-(s==0?0:rt[s-1]);
}
void solve()
{
	for(int i=n-2;i>=0;i--)
	{
		right[i]=0;
		if(A[i]>A[i+1])
		{
			ll now=A[i+1];
			while(now<A[i])
			{
				now*=4LL;
				right[i]++;
			}
		}
		else
		{
			ll now=A[i];
			while(now<=A[i+1])
			{
				now*=4LL;
				right[i]--;
			}
			right[i]++;
		}
	}
	sum[0]=0;
	for(int i=1;i<n;i++) sum[i]=sum[i-1]+(ll) right[i-1];
	for(int i=0;i<n;i++)
	{
		rt[i]=sum[i];
		if(i>0) rt[i]+=rt[i-1];
	}
	int sz=0;
	pos[sz++]=P(-1000000000,n);
	ans[n]=0;
	for(int i=n-1;i>=0;i--)
	{
		while(sz>0&&pos[sz-1].first>=sum[i]) sz--;
		int to=pos[sz-1].second;
		ans[i]=get(i,to-1)-(ll) (to-i)*sum[i]+ans[to];
		pos[sz++]=P(sum[i],i);
	}
	//for(int i=0;i+1<n;i++) printf("%d ",right[i]);puts("");
	//for(int i=0;i<n;i++) printf("%lld ",A[i]);puts("");
	//for(int i=0;i<n;i++) printf("%lld ",ans[i]);puts("");
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%lld",&A[i]);
	if(n==1)
	{
		puts("0");
		return 0;
	}
	solve();
	for(int i=0;i<n;i++) memo[i]=ans[i]*2LL;
	memo[n]=0;
	for(int l=0,r=n-1;l<r;l++,r--) swap(A[l],A[r]);
	solve();
	for(int l=0,r=n-1;l<r;l++,r--) swap(ans[l],ans[r]);
	for(int i=0;i<n;i++) memo[i+1]+=ans[i]*2LL+i+1;
	ll ret=memo[0];
	for(int i=1;i<=n;i++) ret=min(ret,memo[i]);
	printf("%lld\n",ret);
	return 0;
}


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

int main() {
    int n;
    int v[100000];
    int ans = 0;
    int tmp;
    int xh[100000] = {0}, xv, xc = 0, xs = 0;
    int yh[100000] = {0}, yv, yc = 0, ys = 0;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        
        if ((i % 2) == 0) {
            xh[tmp]++;
            
            if (xh[tmp] > xc) {
                xc = xh[tmp];
                xv = tmp;
            }
        }
        else {
            yh[tmp]++;
            
            if (yh[tmp] > yc) {
                yc = yh[tmp];
                yv = tmp;
            }
        }
    }
    
    if (xv == yv) {
        for (int i = 0; i < 100000; i++) {
            if (xv == i) {
                continue;
            }
            
            xs = max(xs, xh[i]);
            ys = max(ys, yh[i]);
        }
        
        ans = n - max((xc + ys), (xs + yc));
    }
    else {
        ans = n - (xc + yc);
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(int i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 998244353
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main(){
	int n, h, w;
	cin >> n >> h >> w;
	cout << max(0, (n-h+1)*(n-w+1)) << endl;
	return 0;
} 

Measured memory_bytes: 768
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])
    RED = [a == 'R' for a in args[1]]
    l, r = 0, n-1
    ret = 0
    while l < r:
        if RED[l]:  # left:red
            l += 1
        elif RED[r]:  # left:white & right:red
            l += 1
            r -= 1
            ret += 1
        elif not RED[r]:  # left: white & right: white
            r -= 1

    return str(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

int helper(int **ar,int n)
{
   /* int **dp = new int*[n];
    for(int i = 0;i<n;i++)
    {
        dp[i] = new int[3];
    }*/
    
    int first = ar[n-1][0];
    int second = ar[n-1][1];
    int third = ar[n-1][2];
    
   /* for(int j = 0;j<3;j++)
    {
        dp[n-1][j] = ar[n-1][j];
    }*/
    
    for(int i = n-2;i>=0;i--)
    {
            int x = first,y = second,z = third;
            first = ar[i][0] + max(y,z);
            second = ar[i][1] + max(x,z);
            third = ar[i][2] + max(x,y);
    }
    return max(first,max(second,third));
}


int main()
{
    int n;
    cin>>n;
    int **ar = new int*[n];
    for(int i = 0;i<n;i++)
    {
        ar[i] = new int[3];
    }
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<3;j++)
        cin>>ar[i][j];
    }
    cout<<helper(ar,n)<<endl;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	int n,k;
	cin>>n>>k;
	int id;
	if(k>=0) id=1;
	else if( k+n-1 < 0 ) id=n;
	else id=-1;
	int sum=0;
	if(id!=-1) sum=-(k+id-1);
	for(int i=1;i<=n;i++)
	{
	    sum+=(k+i-1);
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define repr(i, n) for(int i = n;i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define MOD 1000000007
 
typedef long long ll;
 

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

    string s;
    cin >> s;
    
    sort(s.begin(),s.end());

    rep(i,s.size()){
        if(s[i] == s[i + 1]){
            cout << "no" << endl;
            
            return 0;
        }
    }

    cout << "yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int val;
    cin>>val;
    int arr[4]={};
    while(val--){
        string s;
        cin>>s;
        if(s=="AC") arr[0]+=1;
        else if(s=="WA") arr[1]+=1;
        else if(s=="TLE") arr[2]+=1;
        else if(s=="RE") arr[3]+=1;
    }
    
    cout<<"AC x "<<arr[0]<<'\n';
    cout<<"WA x "<<arr[1]<<'\n';
    cout<<"TLE x "<<arr[2]<<'\n';
    cout<<"RE x "<<arr[3]<<'\n';
}

Measured memory_bytes: 3588
N = int(input())
A = [int(x) for x in input().split()]
mai = 0
for i in range(N):
    if A[i] < 0:
        mai += 1
        A[i] = -A[i]
if mai % 2 == 0:
    print(sum(A))
else:
    A = sorted(A)
    print(sum(A)-2*A[0])


Measured memory_bytes: 14260
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int cost = scanner.nextInt();
    int total = scanner.nextInt();
    int max = scanner.nextInt();
 
    if (cost == 0) {
	  System.out.println(0);
    } else {
      System.out.println(Math.min(max, total / cost));
    }
  }
}


Measured memory_bytes: 23764
// 1文字固定法で3重ループから2重ループにしないと間に合わなくない？
#include<iostream>
using namespace std;
int main(){
  int k,s; cin >> k >> s;
  int ans=0;
  // x+y+z=s が成り立つのを前提に,z=s-x-y が存在するようなx,yの組を求める.
  for(int x=0;x<=k;x++){
    for(int y=0;y<=k;y++){
     if(s-x-y>=0 && s-x-y<=k) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = gets.to_i

SS = N.times.map { gets.chomp! }
ans = { 'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0 }

0.upto(N-1) do |i|
  ans[SS[i].to_sym] += 1
end

ans.each do |k, v|
  puts "#{k} x #{v}"
end


Measured memory_bytes: 20192
#include<iostream>
using namespace std;
const int SIZE=1024*100;
int n,a[SIZE],b[SIZE],c[SIZE],maxa,maxb,max1,max2,ans;
int main(){
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<=n;i++){
		if(i&1){
			b[a[i]]++;
		}else{
			c[a[i]]++;
		}
	}
	for(int i=1;i<SIZE;i++){
		if(b[i]>b[maxa]){
			max1=maxa;
			maxa=i;
		}else if(b[i]>b[max1]){
			max1=i;
		}
		if(c[i]>c[maxb]){
			max2=maxb;
			maxb=i;
		}else if(c[i]>c[max2]){
			max2=i;
		}
	}
	if(maxa==maxb){
		if(b[max1]+c[maxb]>b[maxa]+c[max2]){
			maxa=max1;
		}else{
			maxb=max2;
		}
	}
	for(int i=1;i<=n;i++){
		if(i&1){
			ans+=(a[i]!=maxa);
		}else{
			ans+=(a[i]!=maxb);
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1408
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
typedef long long LL;
using namespace std;
const int maxN = 33;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline int len(int x) {
	int res = 0;
	for (; x; x /= 10) ++ res;
	return res;
}

int C;
int D[maxN];
LL f[2][2], g[2][2];
LL res = 0;

void solve(int L) {
	rep (i, 1, L - len(C)) D[i] = 0;
	for (int t = C, j = L; t; t /= 10, -- j) D[j] = t % 10;

	memset(f, 0, sizeof f); f[0][0] = 1;
	for (int i = 1, j = L; i <= j; ++ i, -- j) {
		memcpy(g, f, sizeof f); memset(f, 0, sizeof f);
		if (i == j) {
			rep (u, 0, 1) rep (v, 0, 1) if (g[u][v]) {
				rep (d, 0, 9) { // n[j]
					if (i == 1 && d == 0) continue;
					int r = v + d + D[j]; // after add
					if (r / 10 != u) continue;
					if (r % 10 != d) continue;
					res += g[u][v];
				}
			}
			break;
		}
		else if (i + 1 == j) {
			rep (u, 0, 1) rep (v, 0, 1) if (g[u][v]) {
				rep (d, 0, 9) { // n[j]
					int r = v + d + D[j]; // after add
					int l = d + u * 10 - D[i] - (r / 10); 
					if (i == 1 && l == 0) continue;
					if (l < 0) continue;
					if (l == r % 10) res += g[u][v];
				}
			}
			break;
		}
		rep (u, 0, 1) rep (v, 0, 1) if (g[u][v]) {
			rep (d, 0, 9) { // n[j]
				int r = v + d + D[j]; // after add
				int l = d + u * 10 - D[i]; 
				if (i == 1 && l == 0) continue;
				if (l < 0) continue;
				if (l == r % 10) f[0][r / 10] += g[u][v];
				-- l;
				if (i == 1 && l == 0) continue;
				if (l < 0) continue;
				if (l == r % 10) f[1][r / 10] += g[u][v];
			}
		}
	}
}

int main() {

	C = ri();
	rep (L, len(C), 30)
		solve(L);
	printf("%lld\n", res);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    if (a%3 && b%3 && (a+b)%3) {
        cout << "Impossible" << endl;
    }
    else {
        cout << "Possible" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    map<string, int> m;
    rep(i, n){
        string c; cin >> c;
        m[c]++;
    }
    cout << "AC x " << m["AC"] << endl; 
    cout << "WA x " << m["WA"] << endl; 
    cout << "TLE x " << m["TLE"] << endl; 
    cout << "RE x " << m["RE"] << endl; 
    return 0;}

Measured memory_bytes: 3628
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>

//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    vector<ll> h;
    cin >> N >> K;
    rep(i, N)
    {
        ll t;
        cin >> t;
        h.push_back(t);
    }
    vector<ll> dp(N,INF_I);
    dp[0] = 0;
    rep(i, N)
    {
        rep(j, K)
        {
            ll t = i - j - 1;
            if (t >= 0)
            {
                chmin(dp[i], dp[t] + abs(h[i] - h[t]));
            }
        }
    }
    cout << dp.back();
}

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

#define ll long long
#define llong long long
#define REP(i,n) for(auto i=0;i<n;++i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define ALL(v) v.begin(),v.end()
#define pb push_back

#define AT "kougekida"
#define DF "mamoru"
#define TAME "tameru"

using namespace std;

int main(){

  int k;
  cin >> k;

  vector<string> I(k), N(k);
  REP(i,k){
    cin >> I[i];
  }
  REP(i,k){
    cin >> N[i];
  }

  int at_1 = 0, at_2 = 0;
  REP(i,k){
    if(I[i] == TAME && N[i] == TAME){
      at_1 = min(5, at_1+1);
      at_2 = min(5, at_2+1);
    }else if(I[i] == AT && N[i] == AT){
      if(at_1 > at_2 || (at_1 != 0 && at_2 == 0)){
        cout << "Isono-kun\n";
        return 0;
      }else if(at_1 < at_2 || (at_1 == 0 && at_2 != 0)){
        cout << "Nakajima-kun\n";
        return 0;
      }else{
        at_1 = 0; at_2 = 0;
      }
    }else if(I[i] == AT && N[i] == TAME){
      if(at_1 == 0){
        cout << "Nakajima-kun\n";
        return 0;
      }
      cout << "Isono-kun\n";
      return 0;
    }else if(I[i] == TAME && N[i] == AT){
      if(at_2 == 0){
        cout << "Isono-kun\n";
        return 0;
      }
      cout << "Nakajima-kun\n";
      return 0;
    }else if(I[i] == DF && N[i] == AT){
      
      if(at_2 == 0){
        cout << "Isono-kun\n";
        return 0;
      }
      
      if(at_2 == 5){
        cout << "Nakajima-kun\n";
        return 0;
      }
      at_2 = 0;
    }else if(I[i] == AT && N[i] == DF){
      if(at_1 == 0){
        cout << "Nakajima-kun\n";
        return 0;
      }
      if(at_1 == 5){
        cout << "Isono-kun\n";
        return 0;
      }
      at_1 = 0;
    }else if(I[i] == DF && N[i] == TAME){
      at_2 = min(5, at_2 + 1);
    }else if(I[i] == TAME && N[i] == DF){
      at_1 = min(5, at_1+1);
    }
  }
  
  cout << "Hikiwake-kun\n";
  return 0;
}




Measured memory_bytes: 3228
//ABC063B
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	string s;
	cin >> s;
	set<char> a;
	for(int i=0;i<s.size();i++){
		a.insert(s.at(i));
	}
	if(a.size() == s.size()){
		cout << "yes" << endl;
	}else{
		cout << "no" << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
#include<string.h>

int main(void){
	char input[1000];

	while(1){
		memset(input,0,sizeof(input));
		scanf("\n%[^\n]",input);
		if( (strlen(input)==1) && (input[0]-'0'==0) ){
			break;
		}
		int sum=0;
		for(int i=0;i<strlen(input);i++){
			sum+=input[i]-'0';
		}
		printf("%d\n",sum);
	}
	return 0;
}



Measured memory_bytes: 2112
from collections import deque
n,m = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
p = a.pop()
sub = deque([p//2])
for i in range (m-1):
    if (len(a) != 0):
        if (a[-1] >= sub[-1]):
            x =a.pop()
            sub.appendleft(x//2)
        else:
            x =sub.pop()
            sub.appendleft(x//2)
    else:
        x =sub.pop()
        sub.appendleft(x//2)
print(sum(a)+sum(sub))
        

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

int main()
{
    int N,count=0,flag=1;
    cin >> N;
    int num[N];
    for(int i=0;i<N;i++){
        cin >> num[i];
        if(num[i]%2){
            flag=0;
            break;
        }
    }
    while(flag){
        for(int i=0;i<N;i++){
            num[i]/=2;
            if(num[i]%2){
                flag=0;
                break;
            }            
        }
        count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)   for(int i=a;i<=b;i++)
#define tez         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int a[10000],b[10000];



void solve() {
int k,x;
cin>>k>>x;
for(int i=x-k+1; i<=x+k-1; i++)
    cout<<i<<" ";

}

signed main() {

  tez;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}


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

using namespace std;
#define int long long 
int n,a[200005],k,f[200005];
main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		f[i]=1e15;
	} 
	f[1]=0;
	f[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=i+k&&j<=n;j++)
		{
			f[j]=min(f[j],f[i]+abs(a[j]-a[i]));
		}
	}
	cout<<f[n];
}

Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

#define ll long long
#define vi vector<int>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int N, A[100005], initial_sum = 0;

void solve(){
    rep(i, N){
        int buff = abs(A[i+2] - A[i]) - abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1]);
        cout << initial_sum + buff << endl;
    }
}

int main(){
    cin >> N;
    A[0] = 0; A[N+1] =0;

    rep(i, N) {
        cin >> A[i+1];
        initial_sum += abs(A[i+1] - A[i]);
    }
    initial_sum += abs(A[N+1] - A[N]);

    solve();
}


Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
int n,k,m,p,q,s,x,pp;
int dist[110001],a,b;
typedef pair<int,int>P;
vector<int>v[110001];
bool ng[101001],used[101001],d[101001];
main(){
  queue<P>q;
  cin>>n>>m>>k>>s>>p>>pp;
  r(i,k){
    cin>>x;
    q.push(P(x,0));
    ng[x]=1;
    used[x]=1;
  }
  r(i,m){
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  while(!q.empty()){
    P t=q.front();q.pop();
    int now=t.first;
    int dis=t.second;
    if(s<=dis)continue;
    r(i,v[now].size()){
      if(!used[v[now][i]]){
        used[v[now][i]]=1;
        d[v[now][i]]=1;
        q.push(P(v[now][i],dis+1));
      }
    }
  }
  priority_queue<P,vector<P>,greater<P> >Q;
  r(i,100011)dist[i]=1e15;
  memset(used,0,sizeof(used));
  Q.push(P(0,1));
  dist[1]=0;
  while(!Q.empty()){
    P t=Q.top();Q.pop();
    int dis=t.first;
    int now=t.second;
    if(dis>dist[now])continue;
    r(i,v[now].size()){
      int e=v[now][i];
      int cost=d[e]?pp:p;
      if(!ng[e]&&dist[now]+cost<dist[e]){
        dist[e]=dist[now]+cost;
        Q.push(P(dist[e],e));
      }
    }
  }
  dist[n]-=d[n]?pp:p;
  cout<<dist[n]<<endl;
}

Measured memory_bytes: 13472
#include<iostream>

#define rep(i, a) for(int i = 0; i < a; i++)
using namespace std;

int main()
{
    int h, w, ct = 0;
    char a[105][105];
    cin >> h >> w;

    rep(i, h) {
        rep(j, w) {
            cin >> a[i][j];
            if (a[i][j] == '.') ++ct;
        }

        if (ct == w) rep(j, w) a[i][j] = '0';
        ct = 0;
    }

    rep(j, w) {
        rep(i, h) if (a[i][j] == '.' || a[i][j] == '0') ct++;
        
        if (ct == h) rep(i, h) a[i][j] = '0';
        ct = 0;
    }

    rep(i, h) {
        rep(j, w) {
            if (a[i][j] != '0') cout << a[i][j];
            else ++ct;
        }

        if(ct != w)cout << endl;
        ct = 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <queue>
#include <map>

int main(){
  long long N;
  scanf("%lld", &N);
  long long ans =0;
  for (long long i=(long long)sqrt(N); i>=2; i--){
    if (N%i==0){
      //printf("i=%lld\n",i);
      ans = (i-1)+(N/i-1);
      printf("%lld\n",ans);
      return 0;
    }
  }
  printf("%lld\n",N-1);
  return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

const char ab=('A'^'B');


int main(void){
	int n,k;
	cin >> n >> k;
	string s;
	cin >> s;

	int flip = 0;
	deque<char> q;
	rep(i,n) q.push_back(s[i]);

	rep(loop,2*n){
		if(k==0) break;
		k--;
		char cur = (flip?q.front()^ab:q.front());
		
		if(cur=='A'){
			char nxt = (flip?'A':'B');
			q.pop_front();
			q.push_front(nxt);
		}else{
			flip^=1;
			char nxt = (flip?'B':'A');
			q.pop_front();
			q.push_back(nxt);
		}
	}

	string ans ="";
	rep(i,n){
		char cur = (flip?q.front()^ab:q.front());
		ans += cur;
		q.pop_front();
	}
		
	if(n%2 == 1 and k%2==1) ans[0]^=ab; 
	cout << ans << endl;

	return 0;
}

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

int main(){
    int N = 0;
    vector<int> A;
    vector<int> answer;
    
  cin >> N;
    
  rep(i, N){
      A.push_back(0);
      answer.push_back(0);
      if(i >= 1){
      cin >> A[i];
      }
  }
    
    rep(i, N){
        if(i >=1){
        answer[A[i]-1]++;
        }
    }
    
    rep(i, N){
        cout << answer[i] << endl;
    }
}

Measured memory_bytes: 5036
#include <iostream>
#include <bitset>
#define ll long long
using namespace std;
const int MDSZ = 2;
const int MD[4] = {1000000007, 1069696919, 701, 1018199999};
int n, k, ar[5001] = {}, rs = 0, a = 0, b = 0;
int dp[5001][MDSZ] = {};
void outDP(string s)
{
	cout << s << " : \n";
	for (int i = 0; i < k; i++)
	{
		cout << i << " " << dp[i][0] << "\n";
	}
}
int main()
{
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k; rs = n;
	for (int i = 0; i < n; i++) 
	{
		cin >> ar[i];
		if (ar[i] >= k) {a++;}
	}
	rs -= a;
	for (int i = 0; i < MDSZ; i++) {dp[0][i] = 1;}
	for (int i = 1; i <= n; i++)
	{
		for (int j = k - 1; j >= ar[i - 1]; j--) 
		{
			for (int kk = 0; kk < MDSZ; kk++)
			{
				dp[j][kk] += dp[j - ar[i - 1]][kk];
				dp[j][kk] %= MD[kk];
			}
		}
	}
	//outDP("ALL");
	for (int i = 1; i <= n; i++)
	{
		if (ar[i - 1] < k)
		{
			for (int j = ar[i - 1]; j < k; j++)
			{
				for (int kk = 0; kk < MDSZ; kk++)
				{
					dp[j][kk] -= dp[j - ar[i - 1]][kk];
					dp[j][kk] %= MD[kk];
					dp[j][kk] = (dp[j][kk] + MD[kk]) % MD[kk];
				}
			}
			//outDP("REM" + to_string(i));
			for (int j = k - ar[i - 1]; j < k; j++)
			{
				bool ck = 1;
				for (int kk = 0; kk < MDSZ; kk++) {ck &= (dp[j][kk] > 0);}
				if (ck) {rs--; break;}
			}
			for (int j = k - 1; j >= ar[i - 1]; j--) 
			{
				for (int kk = 0; kk < MDSZ; kk++)
				{
					dp[j][kk] += dp[j - ar[i - 1]][kk];
					dp[j][kk] %= MD[kk];
				}
			}
			//outDP("FIX" + to_string(i));
		}
	}
	cout << rs << "\n";
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)


const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


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;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE x(n), y(n), z(n); rep(i, n)cin >> x[i] >> y[i] >> z[i];
	rep(i, 101) {
		rep(j, 101) {
			int tmp = 0;
			rep(k, n) {
				if (z[k]) {
					tmp = z[k] + abs(i - x[k]) + abs(j - y[k]);
					break;
				}
			}
			bool ok = true;
			rep(k, n) {
				if (z[k] != max(0LL, tmp - abs(i - x[k]) - abs(j - y[k]))) {
					ok = false; break;
				}
			}
			if (ok) {
				cout << i << " " << j << " " << tmp << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

signed main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  int res, res2, res3;
  res = x * a + y * b;
  res2 = min(x, y) * 2 * c;
  if (x < y) res2 += (y - x) * b;
  else res2 += (x - y) * a;
  res3 = max(x, y) * 2 * c;
  cout << min(min(res, res2), res3) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int h1, h2, m1, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int h = h2 - h1, m = m2 - m1;
  int all = h * 60 + m;
  cout << all-k << endl;
  return 0;
}

Measured memory_bytes: 3640
def main():
    N = int(input())
    pl = tuple(map(float, input().split()))
    mid = (N + 1) // 2
    v = [0.0] * (mid + 1)
    v[0] = 1.0
    for i, p in enumerate(pl[:mid]):
        q = 1 - p
        t = 0.0
        for j, uu in enumerate(v[:i + 2]):
            v[j] = t * p + uu * q
            t = uu
    for i, p in enumerate(pl[mid:], mid):
        q = 1 - p
        t = v[i - mid + 1]
        for j, uu in enumerate(v[i - mid + 2:mid], i - mid + 2):
            v[j] = t * p + uu * q
            t = uu
        v[mid] += t * p
    print(v[mid])

main()


Measured memory_bytes: 3316