akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;

  cin >> N;

  vector<int> H(N);

  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }

  int ans = 0;

  for (int i = 0; i < N; ++i) {
    bool flag = true;
    for (int j = 0; j < i; ++j) {
      if (H[j] > H[i]) {
        flag = false;
      }
    }
    if (flag) {
      ans++;
    }
  }

  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define EPS 1e-14
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};


int main(){
    
    ull n, a[30002], i, lcm, sum=0;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        sum+=(a[i]-1);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    long long int N,M,a[2000],i,c=0,s=0;
    scanf("%d%d",&N,&M);

    for(i=0; i<N; i++)
    {
       scanf("%d",&a[i]);
       s+=a[i];

    }
   double x=s*1.00/4/M;

    for(i=0;i<N;i++)

    {
        if(a[i]>=x)
            c++;

    }
    (c>=M)?printf("Yes\n"):printf("No\n");

    return 0;


}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

  int n;
  cin >> n;
  ll a[100010];
  rep(i, n) cin >> a[i];
  sort(a, a + n);
  ll Max = 0;
  rep(ii, 2)
  {
    ll add1, add2;
    if (ii == 0)
      add1 = -1, add2 = 1;
    else
      add1 = 1, add2 = -1;
    vector<ll> v(n, 0);
    rep(i, n - 1)
    {
      v[i] += add1;
      v[i + 1] += add2;
      swap(add1, add2);
    }
    sort(all(v));
    ll sum = 0;
    rep(i, n) sum += v[i] * a[i];
    Max = max(Max, sum);
  }
  cout << Max << endl;
  return 0;
}

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

int main() {
	int n;
  	cin>>n;
  
  	int AC,WA,TLE,RE;
  	
  	AC=0;
  	WA=0;
  	TLE=0;
  	RE=0;
  	
  	rep(i,n){
      	string s;
      	cin>>s;
    	if(s=="AC")AC++;     
      	else if(s=="WA") WA++;
      	else if(s=="TLE") TLE++;
      	else if(s=="RE")RE++;
    }
  
  cout<<"AC"<<" "<<"x"<<" "<<AC<<endl;
  cout<<"WA"<<" "<<"x"<<" "<<WA<<endl;
  cout<<"TLE"<<" "<<"x"<<" "<<TLE<<endl;  
  cout<<"RE"<<" "<<"x"<<" "<<RE<<endl;   
	
  	
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int s = scanner.nextInt();
        int tmp = 0;
        int before = 0;
        int cnt = 0;
        for(int i=0;i<s;i++) {
        	tmp=scanner.nextInt();
        	if(before<tmp) {
        		cnt+=(tmp-before);
        	}
        	before=tmp;
        }
        System.out.println(cnt);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

Measured memory_bytes: 22100
rooms = [[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n = int(input())
for i in range(n):
    b, f, r, v = list(map(int, input().split()))
    rooms[b - 1][f - 1][r - 1] += v
for i in range(4):
    for j in range(3):
        print(' ', end='')
        print(*[rooms[i][j][k] for k in range(10)])
    if i != 3:    
        print('#' * 20)


Measured memory_bytes: 5624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int Menu[5];
    int except=10;
    for(int i=0; i<5; i++){
        scanf("%d",&Menu[i]);
        if(except>Menu[i]%10 && Menu[i]%10!=0){
            except=Menu[i]%10;
        }
    }
    for(int i=0; i<5; i++){
        if(Menu[i]%10){
            Menu[i]=((Menu[i]/10)+1)*10;
        }
    }
    printf("%d",Menu[0]+Menu[1]+Menu[2]+Menu[3]+Menu[4]-10+except);
    return 0;
}

Measured memory_bytes: 256
using System;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int A = int.Parse(input[0]);
    int B = int.Parse(input[1]);
    int C = int.Parse(input[2]);
    int D = int.Parse(input[3]);
    
    int start = Math.Max(A, C);
    int end = Math.Min(B, D);
    Console.WriteLine(end < start ? 0 : end - start);
  }
}

Measured memory_bytes: 13140
/* Round One */

#include <iostream>
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;

  int ans[3]={0};
  for(int i=0;i<3;i++){
    if(a==i+1) ans[i]=1;
    else if(b==i+1) ans[i]=1;
  }

  for(int i=0;i<3;i++){
    if(ans[i]==0) cout << i+1 << endl;
  }
}


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

int main(void){
    int n;
    cin >> n;

    int ans = 0;
    for(int i=1;i<=n;i++){
        string s = to_string(i);
        if(s.size()%2==1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
///
// File:  d.go
// Author: ymiyamoto
//
// Created on Sat May 26 21:59:20 2018
//
package main

import (
	"fmt"
)

var N uint32
var A []int64

func main() {
	fmt.Scan(&N)

	A = make([]int64, N)
	for i := range A {
		fmt.Scan(&A[i])
	}

	var count int64
	l, r := 0, 0
	var acc int64
	for l < len(A) {
		for r < len(A) && acc^A[r] == acc+A[r] {
			acc += A[r]
			count++
			r++
		}
		acc ^= A[l]
		l++
		count += int64(r - l)
	}

	fmt.Println(count)
}


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

int main(){
  string A;
  cin >> A;
  
  int x = 0;
  for (int i = 0; i < A.size() ; i++){
    if (A.at(i) == '1'){
      x++;
    } 
   }

  cout << x << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<functional>
int w,h;
int xs,ys,xg,yg;
int n;
int c,d,x,y;
int map[101][101];
int flg=0,temp;
void func(int ,int);
using namespace std;
int main(void){
	while(1){
		scanf("%d %d",&w,&h);
		if(w==0 && h==0){
			break;
		}
		int i,j,k;
		for(i=1;i<=100;i++){
			for(j=1;j<=100;j++){
				map[i][j]=0;
			}
		}
		scanf("%d %d %d %d %d",&xs,&ys,&xg,&yg,&n);
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			if(d==0){
				for(k=0;k<=1;k++){
					for(j=0;j<=3;j++){
						map[y+k][x+j]=c;
					}
				}
			}
			if(d==1){
				for(k=0;k<=3;k++){
					for(j=0;j<=1;j++){
						map[y+k][x+j]=c;
					}
				}
			}
			/*for(j=1;j<=10;j++){
				for(k=1;k<=10;k++){
					printf("%d ",map[j][k]);
				}
				printf("\n");
			}
			printf("\n");*/
		}
		flg=0;
		if(map[ys][xs]==map[yg][xg] && map[ys][xs]!=0){
			temp=map[ys][xs];
			map[ys][xs]=0;
			func(ys,xs);
		}/*
		for(i=1;i<=10;i++){
			for(j=1;j<=10;j++){
				printf("%d ",map[i][j]);
			}
			printf("\n");
		}*/
		if(flg==1){
			printf("OK\n");
		}
		else {
			printf("NG\n");
		}
	}
	return 0;
}
void func(int y,int x){
	int dy[4]={0,1,0,-1},dx[4]={1,0,-1,0};
	int i,xx,yy;
	if(flg==0){
		for(i=0;i<4;i++){
			yy=y+dy[i];
			xx=x+dx[i];
			if(yy<=h && yy>=1 && xx<=w && xx>=1 && map[yy][xx]==temp){
				map[yy][xx]=0;
				if(xg==xx && yg==yy){
					flg=1;
					break;
				}
				func(yy,xx);
			}
		}
	}
}

Measured memory_bytes: 1052
#include <stdio.h>

int main(void) {
	int H, W, i=0, j;
	char a[101][101];

	scanf("%d %d", &H, &W);

	for(i=0;i<H;i++) scanf("%s", a[i]);

	for (i = 0; i < H; i++) {
		if (i == 0) {
			for (j = 0; j <= W + 1; j++) printf("#");
			printf("\n");
		}
		printf("#%s#\n", a[i]);
		if (i == H-1 ) {
			for (j = 0; j <= W + 1; j++) printf("#");
			printf("\n");
		}
	}
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

using P = std::pair<int, int>;

int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int N, T;
  cin >> N >> T;
  vector<P> X(N);
  rep(i, N) cin >> X[i].first >> X[i].second;
  int max_cost {INTINF};
  rep(i, N) {
    if (X[i].second <= T) {
      mins(max_cost, X[i].first);
    }
  }
  if (max_cost == INTINF) {
    cout << "TLE\n";
  } else {
    cout << max_cost << '\n';
  }
}


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

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

    string S, T;
    cin >> S >> T;
    map <char, char> s_m;
    map <char, char> t_m;
    set <char> s;

    for (int i = 0; i < T.length(); ++i) {
        char t_c = T[i];

        if (t_m.find(t_c) == t_m.end()) {
            t_m[t_c] = S[i];
            s.insert(S[i]);
        } else if (t_m[t_c] != S[i]){
            cout << "No" << endl;
            return 0;
        }
    }

    if (s.size() == t_m.size()) {
        cout << "Yes" << '\n';
    } else {
        cout << "No" << '\n';
    }

    return 0;
}


Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
long long n,k,a[300000],b[300000],nas,len,j=1;
int main() 
{
  cin>>n>>k;
  for(int i=1;i<=n;i++)
  {
      cin>>a[i];
  }
  b[1]=1;
  int i=1;
  while(true)
  {
      i++;
      if(b[a[j]]==0)
      {
          b[a[j]]=i;
          j=a[j];
      }
      else
      {
          len=i-b[a[j]];
          if(k<=b[a[j]])
          {
              len=k;
              break;
          }
          //cout<<len<<" ";
          k-=b[a[j]]-1;
          //cout<<b[a[j]];
          nas=k%len;
          len=nas+b[a[j]]-1;
          //cout<<len<<" "<<nas<<endl;
          break;
      }
  }
  /*
  for(int i=1;i<=n;i++)
  {

      cout<<i<<"--"<<b[i]<<endl;
  }
  */
  j=1;
  for(int i=0;i<len;i++)
  {
      j=a[j];
  }
  cout<<j;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    if(A+B > A-B){
        if(A+B > A*B){
            cout << A+B << endl;
            return 0;
        }
    }
    else{
        if(A-B > A*B){
            cout << A-B << endl;
            return 0;
        }
    }
    cout << A*B << endl;
}


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

#define MAX_N 2000
// int a = 3;
// int b = 4;

int a;
int b;

int main() {
    cin >> a >> b;
    if (a % 2 == 0 || b % 2 == 0) { 
        cout << "Even" << endl;
        return 0;
    }

    cout << "Odd" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
using namespace std;

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(vtype,var,n) vtype var((uint)n);loop(i,0,n)cin>>var[i];
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

int main(void){
	init(ull, n);

	outl(n*n*n);

	return 0;
}

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

/* define const */

/* finish defineing const */

string o, e;
char c[110];

int main()
{
    cin >> o >> e;
    // input

    int os = o.length();
    int es = e.length();
    int i;

    for (i = 0; i / 2 < os || i / 2 < es; i += 2)
    {
        c[i] = o[i / 2];
        c[i + 1] = e[i / 2];
    }
    if (os > es)
    {
        c[i] = o[i / 2];
    }

    for (int i = 0; i < os + es; i++)
    {
        cout << c[i];
    }
    cout << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
#include<deque>
#include<queue>
#include<set>
#include <functional>
#include <cmath>


//マクロ
/*動かない・・・
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _roverload3(_1,_2,_3,name,...) name
#define _rrep(i,n) repi(i,0,n)
#define rrepi(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(...) _roverload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
//*/
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
//*/
#define All(a) (a).begin(),(a).end()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
//*/
using namespace std;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数
ll n,m;
vector<ll> num;
ll a;

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}
ll gcd(ll a, ll b) {
	if (a < b)return gcd(b, a);
	if (b == 0)return a;
	return gcd(b, a%b);
}

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

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

	cin >> n >> m;
	REP(i, n) {
		ll b;
		cin >> b;
		num.push_back(b);
	}
	sort(All(num));
	a = num[0] / 2;
	REPS(i, n-1) {
		//printf("i=%d\n", i);
		if (num[i] == num[i - 1])continue;
		ll l = lcm(a, num[i]/2);
		//cout << l << endl;
		if ((l/a) % 2 == 1 && (l/(num[i]/2)) % 2 == 1) {
				a = l;
		}
		else {
			//printf("0ぽよ\n");
			cout << 0 << endl;
			return 0;
		}
	}
	//cout << a << endl;
	cout << (m+a)/a/2 << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
const int N = 110, M = 100010;
vector<int>v, u;
int num, n, k, x;
int main()
{
	scanf("%d%d", &n, &k);
	if (n == 1)
		return puts("1\n1\n1"), 0;
	if (k == 1)
	{
		scanf("%d", &x);
		printf("%d\n%d\n%d %d", x, 2, x - 1, 1);
		return 0;
	}
	for (int i = 1; i <= k; i++)
	{
		scanf("%d", &x);
		v.push_back(x);
		if (x & 1)
			swap(v[0], v[i - 1]);
		num += x & 1;
	}
	for (int i = 1; i < k; i++)
		if (v[i] & 1)
			swap(v[i], v[k - 1]);
	if (num > 2)
		puts("Impossible");
	else
	{
		for (int i : v)
			printf("%d ", i);
		printf("\n%d\n", v[0] == 1 ? k - 1 : k);
		if (v[0] != 1)
			printf("%d ", v[0] - 1);
		for (int i = 1; i < k; i++)
			printf("%d ", v[i] + (i == k - 1));
	}
}

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

void fact(int64_t N, vector<int64_t> &prime){
  for (int64_t n=2; n<3; n++){
    if (N%n==0){
      N/=n;
      prime.push_back(n);
      n--;
      continue;
    }
  }
  for (int64_t n=3; n<=sqrt(N); n=n+2){
    if (N%n==0){
      N/=n;
      prime.push_back(n);
      n=n-2;
      continue;
    }
  }
  if (N>2){
    prime.push_back(N);
  }
  return;
}

int main(){
  int64_t N;
  cin>>N;
  vector<int64_t> prime;
  fact(N, prime);
  vector<int> counter;
  int x=0;
  if (count(prime.begin(),prime.end(),2)>0){
    counter.push_back(count(prime.begin(),prime.end(),2));
    N=N/(pow(2,count(prime.begin(),prime.end(),2)));
  }
  for (int64_t i=3; i<=sqrt(N); i=i+2){
    if (count(prime.begin(),prime.end(),i)>0){
      counter.push_back(count(prime.begin(),prime.end(),i));
      N=N/(pow(i,count(prime.begin(),prime.end(),i)));
    }
  }
  if (count(prime.begin(),prime.end(),N)>0){
    counter.push_back(count(prime.begin(),prime.end(),N));
  }
  for (int64_t i=0; i<counter.size(); i++){
    if (1<=counter.at(i)&&counter.at(i)<=2){
      x++;
    } else if (3<=counter.at(i)&&counter.at(i)<=5){
      x=x+2;
    } else if (6<=counter.at(i)&&counter.at(i)<=9){
      x=x+3;
    } else if (10<=counter.at(i)&&counter.at(i)<=14){
      x=x+4;
    } else if (15<=counter.at(i)&&counter.at(i)<=20){
      x=x+5;
    } else if (21<=counter.at(i)&&counter.at(i)<=27){
      x=x+6;
    } else if (28<=counter.at(i)&&counter.at(i)<=35){
      x=x+7;
    } else if (36<=counter.at(i)&&counter.at(i)<=44){
      x=x+8;
    } 
  }
  cout<<x<<endl;
}

Measured memory_bytes: 4120
# region header
import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi
# endregion
N = ri()
K = ri()
x = ri_()
ans = 0
for i in range(N):
    ans += min(x[i], K - x[i]) * 2
print(ans)

Measured memory_bytes: 64492
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var ss = Console.ReadLine().Split();
            var A = int.Parse(ss[0]);
            var P = int.Parse(ss[1]);

            Console.WriteLine((A * 3 + P) / 2);
        }
    }
}

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

int main(){
  int n;
  cin>>n;
  double ans=1;
  if(n%2==0){
    ans/=2;
    cout<<ans<<endl;
  }
  else {
    ans=n+1;
    ans/=2*n;
    cout<<ans<<endl;
  }
  
  return 0;
}

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

int D,x,y;
string a[30];
int p[30];

bool use[30];

int calc(void){
  int sum = 0;
  for(int i=0;i<x;i++){
    if(use[i] && a[i] == "D")sum += p[i];
  }
  for(int i=0;i<y;i++){
    if(use[x+2*i] && use[x+2*i+1] && a[x+i] == "DD")sum += p[x+i];
  }
  return sum;
}

int rec(int depth, int rem){
  if(depth == x+2*y)return calc();

  int res = 0;
  if(depth+rem < x+2*y){
    res = max(res, rec(depth+1,rem) );
  }
  if(rem){
    use[depth] = true;
    res = max(res, rec(depth+1,rem-1) );
    use[depth] = false;
  }
  return res;
}

int main(){
  cin >> D;

  cin >> x;
  for(int i=0;i<x;i++)cin >> a[i] >> p[i];

  cin >> y;
  for(int i=0;i<y;i++)cin >> a[x+i] >> p[x+i];

  D = min(D,x+2*y);
  cout << rec(0,D) << endl;
}

Measured memory_bytes: 1212
/*
把白球当成左括号，把每个颜色的球第一次出现当成右括号
那么方案合法当且仅当括号匹配，直接dp即可 
*/
#include <cstdio>

using namespace std;
const int MOD(1000000000 + 7);
const int Max_N(2050);
const int Max_K(2050);

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

void exgcd(int a, int b, int &x, int &y)
{
	if (b == 0)
		x = 1, y = 0;
	else
		exgcd(b, a % b, y, x), y -= x * (a / b);
}

inline int inverse(int a)
{
	int invx, invy;
	exgcd(a, MOD, invx, invy);
	return (invx % MOD + MOD) % MOD;
}

int N, K, Fac[Max_N * Max_K], Inv[Max_N * Max_K], F[Max_N][Max_N];
//F[i][j]表示已经用了i个白球，有j个白球没有用的方案数 

inline void upd(int &a, int b)
{
	a = Add(a, b);
}

inline int C(int n, int m)
{
	return Mult(Fac[n], Mult(Inv[m], Inv[n - m]));
}

int main()
{
	scanf("%d%d", &N, &K);
	if (K == 1)
	{
		printf("1");
		return 0;
	}
	Fac[0] = 1;
	for (int i = 1;i <= N * K;++i)
		Fac[i] = Mult(Fac[i - 1], i);
	Inv[N * K] = inverse(Fac[N * K]);
	for (int i = N * K - 1;i >= 0;--i)
		Inv[i] = Mult(Inv[i + 1], i + 1);
	F[0][0] = 1;
	for (int i = 0;i <= N;++i)
		for (int j = 0;i + j <= N;++j)
		{
			//添加一个白球
			upd(F[i][j + 1], F[i][j]);
			if (j)
				upd(F[i + 1][j - 1], Mult(F[i][j], C((N - i - j) * K + j * (K - 1) - 1, K - 2)));
		}
	printf("%d", Mult(F[N][0], Fac[N]));
	return 0;
}

Measured memory_bytes: 49280
n = int(input())
a = list(map(int, input().split()))

ans = [0] * n
sum_ = sum(a)
even = 0
odd = 0
for i in range(1, n):
    if i % 2 == 1:
        odd += a[i]
    else:
        even += a[i]

for i in range(n):
    if i % 2 == 1:
        ans[i] = sum_ - 2 * even
        even -= a[(i + 1) % n]
        even += a[(i + 1 + n - 1) % n]
    else:
        ans[i] = sum_ - 2 * odd
        odd -= a[(i + 1) % n]
        odd += a[(i + 1 + n - 1) % n]
print(*ans)

Measured memory_bytes: 65252
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include <sstream>
#include<iomanip>
#include <ctype.h>

//#include<bits/stdc++.h>





using namespace std;
int main() {


	int n;
	cin>>n;
	vector<int>p(n);
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	vector<int>x;
	x = p;
	sort(x.begin(), x.end());
	int a = 0;
	for (int i = 0; i < n; i++) {
		if (x[i] != p[i])a++;
	}
	if (a < 3)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  cout << a * b - a - b + 1 << endl;
  return 0;
}


Measured memory_bytes: 3584
import java.util.Arrays;
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a[] = new int[3];
		for (int i=0; i<3; i++) a[i] = sc.nextInt();
		Arrays.sort(a);
		System.out.printf("%d %d %d\n", a[0], a[1], a[2]);
	}
}

Measured memory_bytes: 26344
#include<iostream>
#include<algorithm>
#include<string>
#include<sstream>
using namespace std;

string replaceAll(string s,string a,string b){
  int pos = 0;
  while(pos = s.find(a,pos),pos!=std::string::npos){
    s.replace(pos,a.size(),b);
    pos += b.size();
  }
  return s;
}

int stoi(string s){
  stringstream ss(s);
  int res; ss >> res; return res;
}

int m;
string s;

int power(int a,int n){
  int res = 1;
  while(n>0){
    if(n&1)res = res * a % m;
    a = a * a % m;
    n >>= 1;
  }
  return res;
}

int parse(int l,int r){
  int a,b,k = 0;
  for(int i=r-1;i>=l;i--){
    if(s[i]=='(')k++;
    else if(s[i]==')')k--;
    if(!k){
      if(s[i] == '+'){
	a = parse(l,i); b = parse(i+1,r);
	if(a<0 || b<0)return -1;
	return (a+b)%m;
      }else if(s[i] == '-'){
	a = parse(l,i); b = parse(i+1,r);
	if(a<0 || b<0)return -1;
	return (a-b+m)%m;
      }
    }
  }

  k = 0;
  for(int i=r-1;i>=l;i--){
    if(s[i]=='(')k++;
    else if(s[i]==')')k--;
    if(!k){
      if(s[i] == '*'){
	a = parse(l,i); b = parse(i+1,r);
	if(a<0 || b<0)return -1;
	return (a*b)%m;
      }else if(s[i] == '/'){
	a = parse(l,i); b = parse(i+1,r);
	if(a<0 || b<0)return -1;
	if(!b)return -1;
	return (a*power(b,m-2))%m;
      }
    }
  }

  if(s[l] == '(' && s[r-1] == ')')return parse(l+1,r-1);

  return stoi(s.substr(l,r-l));
}

int main(){
  while(getline(cin,s)){
    if(s[0]=='0')return 0;
    int c = s.find(":",0);
    m = stoi(s.substr(0,c)); s = s.substr(c+1);
    s = replaceAll(s," ","");

    int res = parse(0,s.size());
    if(res<0)cout << "NG\n";
    else cout << s << " = " << res << " (mod " << m << ")\n"; 
  }
}
  

Measured memory_bytes: 1596
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]uint32, n)
	var x uint32
	for i := 0; i < n; i++ {
		aa[i] = uint32(getNextInt(scanner))
		x = x ^ aa[i]
	}
	for i := 0; i < n; i++ {
		fmt.Fprintln(writer, x^aa[i])
	}
}


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

#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(int i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;--i) // ROF(i,n,0)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで降順
#define SUM(a) accumulate(all(a),int(0))
using ll  = long long;
using vi  = vector<int>;
using vvi = vector<vi>;
using vs  = vector<string>;
using pii = pair<int,int>;
constexpr ll inf = 1ll<<61;
constexpr ll mod = 1e9+7;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>T add(const T &a, const T &b){return (a+b)%mod;}

signed main(){
  int n, k, q; cin >> n >> k >> q;
  vi s(n,k);
  rep(i,q){
    int a; cin >> a; a--;
    s[a]++;
  }
  rep(i,n){
    if(s[i] > q) cout << "Yes";
    else cout << "No";
    cout << endl;
  }
}


Measured memory_bytes: 1408
int main(int argc, const char * argv[]) {
    
    int w=1,h=1,a,b,count=0;
    
    while(w!=0 && h!=0){
        scanf("%d %d",&h,&w);
        if(w==0 && h==0){
            break;
        }
        
        for(a=0;a<h;a++){
            for(b=0;b<w;b++){
                if(count%2==0){ //点とシャープを交互に出す処理
                    printf("#");
                }else{
                    printf(".");
                }
                count++;
            }
            printf("\n");
            if(w%2==0){ //幅が偶数に場合はCOUNTを一個進める
                count++;
            }
        }
        printf("\n");
        count=0;
    }
    
    return 0;
}




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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    cout << n*800-200*(n/15) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.awt.geom.*;
import java.util.*;
import static java.lang.Math.*;
public class Main{
	final Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().init();
	}
	void init(){
		new AOJ1167();
	}
	
	class AOJ1167{
		AOJ1167(){
			while(sc.hasNext()){
				int n=sc.nextInt();
				if(n==0)	break;
				solve(n);
			}
		}
		final int INF=1<<29;
		void solve(int n){
			final int MAX=1000000;
			int[]	a=new int[MAX+1],
					b=new int[MAX+1];
			for(int i=1,j=1; true; ++i){
				a[i]=i*(i+1)*(i+2)/6;
				if(a[i]%2==1)	b[j++]=a[i];
				if(a[i]>=MAX)	break;
			}
			
			int[] dp=new int[n+1];
			for(int i=0; i<=n; ++i)dp[i]=INF;
			dp[0]=0;
			for(int i=1; a[i]<=n; ++i){
				for(int j=0; j<=n; ++j){
					int tmp=j-a[i];
					if(tmp>=0){
						dp[j]=min(dp[j], dp[j-a[i]]+1);
					}
				}
			}
//			System.out.println(Arrays.toString(dp));
			System.out.print(dp[n]);
			
			for(int i=0; i<=n; ++i)dp[i]=INF;
			dp[0]=0;
			for(int i=1; b[i]<=n; ++i){
				for(int j=0; j<=n; ++j){
					int tmp=j-b[i];
					if(tmp>=0){
						dp[j]=min(dp[j], dp[j-b[i]]+1);
					}
				}
			}
//			System.out.println(Arrays.toString(dp));
			System.out.println(" "+dp[n]);
		}
	}
}

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

void trace(int A[], int N) {
  int i;
  for ( i = 0; i < N; i++ ) {
    if ( i > 0 ) printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int bubbleSort(int A[], int N) {
  int flag = 1, j, count = 0;
  while ( flag ) {
    flag = 0;
    for ( j = N - 1; j > 0; j-- ) {
      if ( A[j] < A[j - 1] ) {
        swap(A[j], A[j - 1]);
        count++;
        flag = 1;
      }
    }
  }
  trace(A, N);
  return count;
}

int main() {
	int N, i, count;
  int A[100];

  scanf("%d", &N);
  for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);

  count = bubbleSort(A, N);
  printf("%d\n", count);

  return 0;
}



Measured memory_bytes: 2732
let () =
  let n,k = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let pow a n =
    let rec aux res a n =
      if n = 0 then res else aux (res*a) a (n-1)
    in
    aux 1 a n
  in
  Printf.printf "%d\n" @@
  pow (k-1) (n-1) * k


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n,m,k;
    cin>>n>>m>>k;
    bool f[n*m];
    rep(1,i,n*m)f[i]=false;
    ll tmp1=0,tmp2=0;
    rep(0,i,n+1){
        if(i!=0)tmp1+=m;
        tmp2=tmp1;
        rep(0,j,m+1){
            if(j!=0)tmp2+=(n-2*i);
            //cout<<j<<" "<<i<<" "<<tmp2<<endl;
            f[tmp2]=true;
        }
    }
    if(f[k])cout<<"Yes";
    else cout<<"No";
}

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

const ll mod = 1000000007;

int main()
{
	ll n; cin >> n;
	
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) cin >> a[i];
	
	vector<ll> num(n, 0);
	for (ll i = 0; i < n; i++) num[a[i]]++;
	
	bool can = true;
	
	if (n % 2 == 0) {

		for (ll i = 0; i < n; i++) {

			if (i == 0) {
				if (num[i] == 0) continue;
				else {
					can = false;
					break;
				}
			}
			else { // 1 <= i
				if (i % 2 == 1) {
					if (num[i] == 2) continue;
					else {
						can = false;
						break;
					}
				}
				else {
					if (num[i] == 0) continue;
					else {
						can = false;
						break;
					}
				}
			}
		}

	}
	else { // n % 2 == 1

		for (ll i = 0; i < n; i++) {
		
			if (i == 0) {
				if (num[i] == 1) continue;
				else {
					can = false;
					break;
				}
			}
			else{
				if (i % 2 == 1) {
					if (num[i] == 0) continue;
					else {
						can = false;
						break;
					}
				}
				else {
					if (num[i] == 2) continue;
					else {
						can = false;
						break;
					}
				}
			}
		}

	}

	ll ans = 1;
	for (ll i = 1; i <= n / 2; i++) {
		ans *= 2LL;
		ans %= mod;
	}

	if (can) cout << ans << endl;
	else cout << 0 << endl;
	
	return 0;
}

Measured memory_bytes: 1792
//101
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define ALF "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define LLBIG 1999999999999999999LL
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

LL H, W, h, w, A, B, C, I;
string s;

int main() {
	cin >> s;
	int X = 0;
	for (int i = 0; i < 4; i++)(s[i] == '+' ? X++ : X--);
	//int ans = max(A, max(B, C)) * 10 + A + B + C - max(A, max(B, C));
	cout << X << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = 10 ** 10

n_nodes, m_edges = map(int, input().split())
dist = [[INF] * n_nodes for _ in range(n_nodes)]

for _ in range(m_edges):
    s, t, d = map(int, input().split())
    dist[s][t] = d

memory = {}
end = 2 ** n_nodes - 1


def rec(state, pos):
    if (state, pos) in memory:
        return memory[(state, pos)]

    if state == end:
        return dist[pos][0]

    mask = 1
    res = INF
    for pos_next in range(n_nodes):
        if mask & state:
            mask <<= 1
            continue

        res = min(res, rec(state | mask, pos_next) + dist[pos][pos_next])
        mask <<= 1

    memory[(state, pos)] = res
    return res


res = rec(1, 0)
if res == INF:
    print(-1)
else:
    print(res)



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

int main() {
  int N, K;
  vector<int> A;
  while (cin >> N >> K) {
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    int res = 0;
    int right = 0;
    while (true) {
      if (res == 0) right += K;
      else right += K-1;
      ++res;

      if (right >= N) break;
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

vector<ll> cnt(2,0);
map<vector<int>,int> m;
ll dfs(int z, bool isX, vector<int> &usedX, vector<int> &usedY, vector<vector<int>> &XtoY, vector<vector<int>> &YtoX){
    if(isX&&usedX[z]==1){
        return 0;
    }else if(isX==false&&usedY[z]==1){
        return 0;
    }
    if(isX){
        usedX[z]=1;
    }else{
        usedY[z]=1;
    }
    cnt[isX]++;

    vector<int> tmp;
    ll c=0;
    if(isX){
        tmp=XtoY[z];
    }else{
        tmp=YtoX[z];
    }
    for(auto &e:tmp){
        if(isX){
            if(m.count({z,e})){
                continue;
            }else{
                m[{z,e}]=1;
                c++;
            }
        }else{
            if(m.count({e,z})){
                continue;
            }else{
                m[{e,z}]=1;
                c++;
            }
        }
        c+=dfs(e,!(isX),usedX,usedY,XtoY,YtoX);
    }
    return c;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> XtoY(100001,vector<int>(0));
    vector<vector<int>> YtoX(100001,vector<int>(0));
    vector<vector<int>> vec(N);
    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        XtoY[x].push_back(y);
        YtoX[y].push_back(x);
        vec[i]={x,y};
    }

    vector<int> usedX(100001,0);
    vector<int> usedY(100001,0);
    ll ans=0;
    for(int i=0; i<100001; i++){
        cnt[0]=cnt[1]=0;
        ll tmp=dfs(i,true,usedX,usedY,XtoY,YtoX);
        if(cnt[0]>1&&cnt[1]>1){
            ans+=cnt[0]*cnt[1]-tmp;
        }
    }

    cout << ans << endl;
}

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

using LL = long long;
using LD = long double;
 
LL mod = 998244353;
const LD pi = 3.141592653589793238;

int main()
{
	LL n, m;
	cin >> n >> m;

	vector<vector<LL>> adj(n);
	
	while (m--) {
		LL u, v;
		cin >> u >> v;
		u--, v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	vector<LL> vis(n, 0);
	vector<LL> dist(n, 0);
	vector<LL> parent(n, 0);
	vis[0] = 1;

	queue<LL> q;
	q.push(0);

	while (!q.empty()) {
		LL u = q.front();
		q.pop();
		for (auto e : adj[u]) {
			if (!vis[e]) {
				vis[e] = 1;
				dist[e] = dist[u]+1;
				parent[e] = u;
				q.push(e);
			}
		}
	}

	bool poss = true;
	if (find(vis.begin(), vis.end(), 0) != vis.end()) {
		poss =  false;
	}
	if (poss) {
		cout << "Yes\n";
		for (LL i = 1; i < n; ++i) {
			cout << parent[i]+1 << "\n";
		}
	}
	else {
		cout << "No\n";
	}

}

Measured memory_bytes: 14472
#include <stdio.h>

int main(void) {

  long n,k;
	scanf("%ld %ld", &n, &k);
  char s[n+1];
  scanf("%s", s);
  char head = s[0];
  long count_other = 0;
  for (long i = 1; i < n; i++) {
    if (s[i-1] == head && s[i] != head) {
      count_other++;
    }
  }
  long happy;
  if (s[n-1] == head) {
    happy = n-1-(count_other)*2;
  } else {
    happy = n-(count_other)*2;
  }
  if (count_other <= k) {
    happy = n-1;
  } else {
    happy += k*2;
  }
  printf("%ld\n", happy);

  return 0;
}

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

using namespace std;

int cmp(int a,int b)
{
    return a%10>b%10;
}
int main()
{
    int a[6];
    for(int i=0;i<5;i++)
        cin>>a[i];
    a[5]=0;
    sort(a,a+5,cmp);
    int ans=0;
    for(int i=0;i<5;i++)
    {
        ans+=a[i];
        if(a[i]%10!=0)
        {
            ans+=10-a[i]%10;
        }
    }
    //cout<<ans<<endl;
    for(int i=0;i<6;i++)
    {
        if(a[i]%10==0 && i==0)
        {
            break;
            ans-=10-a[i-1]%10;
            break;
        }
        if(a[i]%10==0 && i!=0)
        {

            ans-=10-a[i-1]%10;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
    int a, b;
    int p, x;
    int N, Q;
    cin >> N >> Q;
    int values[N+1];
    int ans[N+1];
    vector< vector<int> > vertexes(N+1, vector<int>(0));
    for (int i = 0; i < N - 1; i++){
        cin >> a >> b;
        vertexes.at(a).push_back(b);
        vertexes.at(b).push_back(a);
    }
    for (int i = 0; i < N + 1; i++) {
        ans[i] = -1;
    }
    for (int i = 0; i < N + 1; i++) {
        values[i] = 0;
    }

    for (int i = 0; i < Q; i++) {
        cin >> p >> x;
        values[p] += x;
    }


    queue< pair<int, int> > q;
    q.push( pair<int, int>(1, 0) );
    while (q.empty() == false) {
        pair<int, int> i = q.front();
        q.pop();
//        cout << i.first << "," << i.second<< endl;
        int index = i.first;
        int parent_value = i.second;
        int value = parent_value + values[index];

        ans[index] = value;
//        cout << index << ":" << value << endl;

        vector<int> children = vertexes.at(index);
        for (int i = 0; i < children.size(); i++) {
            int child = children.at(i);
            if (ans[child] == -1){
//                cout << child << "#" << value << endl;
                q.push( pair<int, int>(child, value));
            }
        }
    }
    for (int i = 1; i < N+1; i++) {
        cout << ans[i];
        if (i != N){
            cout << " ";
        }
    }
    return 0;
}


Measured memory_bytes: 17124
#include <iostream>

using namespace std;

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

    int d, x;
    cin >> d >> x;

    int ai = 0;//Aiを格納
    int cl = x;//チョコレート
    int ed = 0;//何日食べたか

    for(int i = 0; i < n; i++){
        cin >> ai;
        if(d % ai == 0){
            ed = d / ai;
        }else{
        ed = d / ai + 1;
        }
        cl = cl + ed;
        
    }
    cout << cl << endl;
    return 0;
}

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

int main(){
    long long int n,y;
    cin>>n>>y;
    for(int i=0;i<=n;i++){
        for(int j=0;j+i<=n;j++){
            long long int a;
            a=10000*i+5000*j+1000*(n-j-i);
            if(a==y){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
cout<<"-1 -1 -1";

}


Measured memory_bytes: 256
import java.util.*;

class Main{
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                boolean[][] map = new boolean[9][];
                for(int i = 0; i < 9; i++){
                        String s = sc.nextLine();
                        boolean[] b = new boolean[s.length()];
                        for(int j = 0; j < s.length(); j++){
                                b[j] = s.charAt(j) == '1';
                        }   
                        map[i] = b;
                }   
                sc.close();
                int[] x = new int[2];
                boolean[][][] p = new boolean[5][5][4];
                for(int i = 0; i < 5; i++){
                        for(int j = 0; j < 5; j++){
                                boolean[] b = p[i][j];
                                b[0] = j < 4 ? map[2*i][j] : false;
                                b[1] = i < 4 ? map[2*i+1][j] : false;
                                b[2] = j > 0 ? map[2*i][j-1] : false;
                                b[3] = i > 0 ? map[2*i-1][j] : false;
                        }   
                }   
                do{ 
                        add(x, Direction.next(p[x[0]][x[1]]));
                }while(!Arrays.equals(x, new int[2]));
                System.out.println();
        }   
        static void add(int[] a, int[] b){
                a[0] += b[0];
                a[1] += b[1];
        }   
        static class Direction{
                static int c = 0;
                static int[][] v = {{0,1},{1,0},{0,-1},{-1,0}};
                static String[] s = {"R","D","L","U"};
                static int[] next(boolean[] wall){
                        int tmp = next(next(next(c)));
                        while(!wall[tmp]){
                                tmp = next(tmp);
                        }   
                        c = tmp;
                        System.out.print(s[c]);
                        return v[c];
                }   
                static private int next(int d){
                        if(++d == 4) d = 0;
                        return d;
                }   
        }   
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long d = sc.nextLong();
        d *= d;
        
        int count = 0;
        while(n-- > 0) {
            long x = sc.nextInt();
            long y = sc.nextInt();
            
            long tmp = x * x + y * y;
            
            if (tmp <= d) count++;
        }
        System.out.println(count);
    }
}


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

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

		vector<int> x(N);
		for(int i=0; i<N; i++) {
			cin >> x[i];
		}

		int min_move_step = 0;
		for(int i=0; i<N; i++) {
			if ((K - x[i]) < x[i]) {
				min_move_step += (2 * (K - x[i]));
			} else {
				min_move_step += (2 * x[i]);
			}
		}

		cout << min_move_step << endl;
		return 0;
}


Measured memory_bytes: 256
def main():
    h, w = list(map(int, input().split()))
    board = []
    safe_h = set()
    safe_w = set()
    for i in range(h):
        board.append(list(input()))
    for i in range(h):
        for j in range(w):
            if board[i][j] == '#':
                safe_h.add(i)
                safe_w.add(j)
    for i in safe_h:
        for j in safe_w:
            print(board[i][j], end='')
        print()


if __name__ == '__main__':
    main()

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int R;

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

    std::cin >> R;

    if(R < 1200){
        std::cout << "ABC" << std::endl;
    }else if(R < 2800){
        std::cout << "ARC" << std::endl;
    }else{
        std::cout << "AGC" << std::endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3644
import sys

input = sys.stdin.readline
MOD = 1000000007

Q,H,S,D = map(int,input().split())
N = int(input())

#1L min
min_1L = min(min(4*Q,2*H),S)

min_2L = min(D,2*min_1L)

#num of 2L
print(N//2*min_2L + N%2*min_1L)

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

int map[20][20];
int d[20][20];
int main(){
  int w,h;
  while(1){
  cin>>w>>h;
  if(!w && !h)break;
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      map[i][j]=0;
      d[i][j]=0;
    }
  }
  int kouzisuu;
  int a,b;
  cin>>kouzisuu;
  for(int i=0;i<kouzisuu;i++){
    cin>>a>>b;
    d[b][a]=1;
  }
  map[0][1]=1;
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      if(d[i][j]==1)continue;
      map[i][j]=map[i-1][j]+map[i][j-1];
     
    }
  }
  cout<<map[h][w]<<endl;
}
}

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



int main() {
    int n;
    cin >> n;
    
    vector<int> p(n);
    rep(i,n) {
        cin >> p[i];
    }
    
    vector<int> ans;
    ans.push_back(p[0]);
    for(int i = 1; i < n; i++) {
        if(p[i] <= ans.back())
            ans.push_back(p[i]);
    }
    
    cout << ans.size() << endl;
    
    
    return 0;
}


Measured memory_bytes: 5032