akhauriyash/Code-Regression huggingface dataset:
n=int(input())
a=sorted(map(int,input().split()))

cum=[0]*(n+1)
for i in range(n):
    cum[i+1]=cum[i]+a[i]
ans=1
for i in reversed(range(n-1)):
    if cum[i+1]*2<a[i+1]:
        break
    else:
        ans+=1
print(ans)

Measured memory_bytes: 14224
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = 0

for i in range(n):
  if 2*(k-x[i]) >= 2*x[i]:
    ans += 2*x[i]
  else:
    ans += 2*(k-x[i])
    
print(ans)

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

int main(){
    long long a,b=0,c;cin >> a;
    vector<long long> v(a);
    for (int i=0;i<a;i++){
        cin >> v[i];
    }
    for (int i=0;i<a;i++){
        for (int o=i+1;o<a;o++){
            for (int u=o+1;u<a;u++){
                if (v[i]==v[o] || v[i]==v[u] || v[u]==v[o]) continue;
                else if ((v[i]+v[o])>v[u] && (v[u]+v[i])>v[o] && (v[o]+v[u])>v[i]){
                b++;
            }
            }
        }
    }
    cout << b;
}


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

typedef long long ll;

struct A {
    int a, b, c;
};

bool cmp(const A& f, const A& g) {
    return f.a - f.b > g.a - g.b;
}

int main() {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);

    int n = x + y + z;
    vector<A> a(n);
    ll sum_c = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d%d%d", &a[i].a, &a[i].b, &a[i].c);
        sum_c += a[i].c;
    }

    sort(a.begin(), a.end(), cmp);
    multiset<int, greater<int>> fi, se, not_in_se;
    ll sum_x = 0, sum_y = 0;
    for (int i = 0; i < n; ++i) {
        sum_y += a[i].b - a[i].c;
        se.insert(a[i].b - a[i].c);
        if (se.size() > y) {
            sum_y -= *se.rbegin();
            not_in_se.insert(*se.rbegin());
            se.erase(--se.end());
        }
    }

    ll ans = 0;
    for (int i = 0; i + y < n; ++i) {
        auto it_del = se.find(a[i].b - a[i].c);
        if (it_del != se.end()) {
            sum_y -= *it_del;
            se.erase(it_del);
        } else {
            it_del = not_in_se.find(a[i].b - a[i].c);
            if (it_del != not_in_se.end()) {
                not_in_se.erase(it_del);
            }
        }
        if (se.size() < y) {
            sum_y += *not_in_se.begin();
            se.insert(*not_in_se.begin());
            not_in_se.erase(not_in_se.begin());
        }
        sum_x += a[i].a - a[i].c;
        fi.insert(a[i].a - a[i].c);
        if (fi.size() > x) {
            sum_x -= *fi.rbegin();
            fi.erase(--fi.end());
        }
        if (fi.size() == x && se.size() == y) {
            ans = max(ans, sum_x + sum_y + sum_c);
        }
    }

    printf("%lld\n", ans);
}


Measured memory_bytes: 6144
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>

using namespace std;

int map[50][50],width,height;
int dx[8] = {-1,0,1,-1,1,-1,0,1},dy[8] = {-1,-1,-1,0,0,1,1,1};

bool rangeCheck(int row,int col){
	if(row >= 0 && row <= height-1 && col >= 0 && col <= width-1)return true;
	else{
		return false;
	}
}

void erase(int row,int col){
	map[row][col] = 0;

	for(int i = 0; i < 8; i++){
		if(rangeCheck(row+dy[i],col+dx[i]) == true && map[row+dy[i]][col+dx[i]] == 1)erase(row+dy[i],col+dx[i]);
	}
}


int main(){

	int count;

	while(true){
		scanf("%d %d",&width,&height);
		if(width == 0 && height == 0)break;

		for(int i = 0; i < height; i++){
			for(int k = 0; k < width; k++){
				scanf("%d",&map[i][k]);
			}
		}

		count = 0;

		for(int row = 0; row < height; row++){
			for(int col = 0; col < width; col++){
				if(map[row][col] == 1){
					count++;
					erase(row,col);
				}
			}
		}


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

	}


	return 0;
}

Measured memory_bytes: 2652
H,W = map(int, input().split())
S = []
def canb(h,w):
    if h > 0:
        if S[h-1][w] == '#':
            return True
    if h < H - 1:
        if S[h+1][w] == '#':
            return True
    if w > 0:
        if S[h][w-1] == '#':
            return True
    if w < W - 1:
        if S[h][w+1] == '#':
            return True
    return False
for h in range(H):
    S.append(input())
check = 'Yes'
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            if canb(h,w) == False:
                check = 'No'
                break
    else:
        continue
    break
print(check)

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

using namespace std;
const int maxn=1e5+5;
int book[maxn];
int h[maxn];
vector<int>edg[maxn];
int main()
{
    int a, b, n, m;
    cin>>n>>m;
    for(int i=1; i<=n; i++)scanf("%d", &h[i]);
    while(m--)
    {
        scanf("%d%d", &a, &b);
        edg[a].push_back(b);
        edg[b].push_back(a);
        if(h[a]>h[b])book[a]++;
        else if(h[b]>h[a])book[b]++;
    }
    int ans=0;
    for(int i=1; i<=n; i++)
    {
        if(edg[i].size()==book[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9672
H,W = map(int,input().split())
A = [[i for i in input()] for _ in range(H)]
A.insert(0,["#"]*(W))
A.insert(H+2,["#"]*(W))
for j in range(len(A)):
  A[j].insert(0,"#")
  A[j].append("#")
for ans in A:
  print("".join(ans))

Measured memory_bytes: 3060
n,m=[int(x) for x in input().rstrip().split()]
dic={}
wa=[0 for i in range(n)]
ac=[0 for i in range(n)]
ans=0
pena=0
for i in range(m):
  p,s=[x for x in input().rstrip().split()]
  p=int(p)
  if p in dic:
    if dic[p]=="WA" and s=="WA":
      wa[p-1]+=1
    elif dic[p]=="WA" and s=="AC":
      ac[p-1]=1
      dic[p]="AC"
      pena+=wa[p-1]

  else:
    if s=="AC":
      ac[p-1]=1
      dic[p]="AC"
    else:
      dic[p]=s
      wa[p-1]=1

print(sum(ac),pena)


Measured memory_bytes: 16620
#include<bits/stdc++.h>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent;
};
  Node *root=NULL,*NIL=NULL;//番兵（何もない）

void insert(int k){
  Node *x_parent=NIL;//xの親
  Node *x=root;//挿入する場所・・・rootから始まる
  Node *node=NIL;//新たに挿入するノード
  node = (Node*)malloc(sizeof(Node));// 
  node->key=k;//    新たに
  node->right=NIL;//　　挿入するノードの
  node->left=NIL;//　　　　要素をセットする
 
 //挿入する位置を決める。
  while(x!=NIL){
    x_parent=x;
    if(node->key<x->key){//親より大きい
      x=x->left;//xを左に
    }else{//小さい
      x=x->right;//xを右に
    }
  }
  node->parent=x_parent;
  if(x_parent==NIL){
    root=node;//木が空の場合
  }else{
    if(node->key < x_parent->key){//親より大きい
      x_parent->left=node;//左にセット
    }else {//小さい
      x_parent->right=node;//右にセット
    }
  }
  return ;
}

void preorder(Node *u){
  if(u==NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

void inorder(Node *u){
  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

int main(){
  int n,x;
  string com;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    cin>>com;
    if(com=="insert"){
      cin>>x;
      insert(x);
    }
    else if(com=="print"){
      inorder(root);
      cout<<endl;
      preorder(root);
      cout<<endl;
    }
  }
  return 0;
}

    




 

Measured memory_bytes: 26744
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    long P=0, Q=0;
    for(size_t i=0;i<N; i++)
    {
        long p;
        cin >> p;
        P += p * pow(10, N-i-1);
    }
    for(size_t i=0;i<N; i++)
    {
        long q;
        cin >> q;
        Q += q * pow(10, N-i-1);
    }
    cerr << P << ":" << Q << endl;
    string m="";
    for(int i=1; i<=N; i++){
        m+=(char)(i+'0');
    }
    int cnt = 0, ans1 ,ans2;
    while(1){
        cnt++;
        if(stol(m)==P) ans1 = cnt;
        if(stol(m)==Q) ans2 = cnt;
        if(!next_permutation(m.begin(), m.end())) break;
    }
    cout << abs(ans1 - ans2) << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

namespace AISB
{
    static class MainClass
    {

        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] input1 = Console.ReadLine().Split(' ');
            int A = int.Parse(input1[0]);
            int B = int.Parse(input1[1]);
            string[] input2 = Console.ReadLine().Split(' ');
            List<int> plst = new List<int>();
            var p1lst = new List<int>();
            var p2lst = new List<int>();
            var p3lst = new List<int>();

            for (int i = 0; i < N; i++)
            {
                int p = int.Parse(input2[i]);
                plst.Add(p);
                if (p <= A)
                {
                    p1lst.Add(p);
                }
                else if (p >= A + 1 && p <= B)
                {
                    p2lst.Add(p);
                }
                else
                {
                    p3lst.Add(p);
                }
            }
            int ans = 0;
            ans = Math.Min(p1lst.Count(), p2lst.Count);
            ans = Math.Min(ans, p3lst.Count());

            Console.WriteLine(ans);

            return;


        }



        public static long Gcd(long a, long b)
        {
            long tmp;
            // a<bにする
            if (a >= b)
            {
                tmp = a;
                a = b;
                b = tmp;
            }

            if (a == 0)
            {
                return b;
            }

            tmp = a;
            a = b % a;
            b = tmp;
            return Gcd(a, b);

        }


        public static IEnumerable<long> PF(long n)
        {
            long i = 2;
            long tmp = n;

            while (i * i <= n) //※1
            {
                if (tmp % i == 0)
                {
                    tmp /= i;
                    yield return i;
                }
                else
                {
                    i++;
                }
            }
            if (tmp != 1) yield return tmp;//最後の素数も返す
        }




    }

}






Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>

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


int main() {
    int r, d, x; cin >> r >> d >> x;
    rep(i,10){
        x = r*x - d;
        cout << x << endl;
    }
}


Measured memory_bytes: 256
i=input()
a=int(i.split()[0])
b=int(i.split()[1])
k=int(i.split()[2])

if a+b<=k:
  print(0,0)
elif a>k:
  print(a-k,b)
elif a==k:
  print(0,b)
else:
  print(0,b-(k-a))

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

const int MAXN = 2010;

int n, sum, a[MAXN];
bitset<MAXN * MAXN> f;

int main()
{
	scanf("%d", &n);
	f[0] = 1;
	for(int i = 1; i <= n; ++i)
	{
		scanf("%d", &a[i]);
		sum += a[i];
		f |= f << a[i];
	}
	for(int i = (sum + 1) / 2; i <= sum; ++i)
		if(f[i]) {printf("%d\n", i); break;}
	return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

// init {{{
struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


const int NM = 201001;//ここを問題の制約を見ながらいじる．配列の確保に使う．
ll P[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．
ll dp[NM];//あまり褒められたことではないが関数の外側に配列を確保すると怒られにくい．

       // Main program
void solve() {
    ll  N;
    cin >> N;
    ll minP = 9999999999;
    ll sum = 0;

    for (ll i = 0; i < N; i++) {
       cin >> P[i];
       minP = min(minP, P[i]);
       dp[i] = minP;
       if (minP  >= P[i]) {
           sum++;
       }
    }
 
    cout << sum;
       
    return;

}

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







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

int main() {
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int hL = h2 - h1;
    int hLM = hL * 60;
    int mL = m2 - m1;
    int t = hLM + mL;
    int ans = t - k;
    cout << ans << endl;
}

Measured memory_bytes: 3636
import numpy as np

N, K = map(int, input().split())

arr = np.zeros((K, N))

for i in range(K):
    d = input()
    lists = list(map(int, input().split()))
    for j in lists:
        arr[i, j-1] = 1
arr = np.sum(arr, axis=0)
count = 0
for i in arr:
    if i == 0:
        count+=1
print(count)



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

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

int main() {
  int h, w;
  cin >> h >> w;

  for (int i = 0; i < w+2; ++i) { cout << "#"; }
  cout << endl;
  
  for (int i = 0; i < h; ++i) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }

  for (int i = 0; i < w+2; ++i) { cout << "#"; }
  cout << endl;

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<string> C(N), A(N), B(N);
    for (int i = 0; i < N; i++){
        cin >> C[i];
        A[i] = C[i];
        B[i] = A[i];
    }
    for (int i = 0; i < N-1; i++){
        for (int j = N-1; j > i; j--){
            if (A[j][1] < A[j-1][1]){
                swap(A[j], A[j-1]);
            }
        }
    }
    for (int i = 0; i < N-1; i++){
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl << "Stable" << endl;
    
    int minj;
    for (int i = 0; i < N; i++) {
        minj = i;
        for (int j = i; j < N; j++){
            if (B[j][1] < B[minj][1]){
                minj = j;
            }
        }
        swap(B[i], B[minj]);
    }
    for (int i = 0; i < N-1; i++){
        cout << B[i] << " ";
    }
    cout << B[N-1] << endl;
    if (A == B){
        cout << "Stable" << endl;
    }
    else {
        cout << "Not stable" << endl;
    }
}


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

int main()
{
    rep(i, 10000)
    {
        int a;
        cin >> a;
        if (a == 0)
            break;
        cout << "Case " << (i + 1) << ": " << a << endl;
        ;
    }
    return 0;
}


Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int aa[11];
ll ans=0;

void next(int m,int i){
  aa[i]++;
  if(i==0)return;
  else if(aa[i]>m){
    next(m,i-1);
    aa[i]=aa[i-1];
  }
  return;
}

int main(){
  int n,m,q;cin>>n>>m>>q;
  ll ab[55][4];
  for(int i=0;i<q;i++)for(int j=0;j<4;j++)cin>>ab[i][j];
  for(int i=0;i<5;i++)aa[i]=1;aa[0]=m;
  
  while(true){
    ll p=0;
    for(int i=0;i<q;i++){
      if(aa[ab[i][1]]-aa[ab[i][0]]==ab[i][2])p+=ab[i][3];
    }
    ans=max(ans,p);
    next(m,n);
    if(aa[0]==m+1){cout<<ans<<endl;return 0;}
  }
}

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

int main()
{
  int t = 1000000007;
  string s;
  cin >> s;

  const int N = 13;
  int size = s.size();
  long long int dp[size + 1][N] = {0};

  dp[0][0] = 1;

  int mul = 1;
  reverse(s.begin(), s.end());
  for (int i = 0; i < size; i++) {
    for (int j = 0; j < N; j++) {
      if (s[i] == '?') {
        for (int k = 0; k < 10; k++) {
          dp[i + 1][(k * mul + j) % N] += dp[i][j];
          dp[i + 1][(k * mul + j) % N] %= t;
        }
      } else {
        int k = s[i] - '0';
        dp[i + 1][(k * mul + j) % N] += dp[i][j];
        dp[i + 1][(k * mul + j) % N] %= t;
      }
    }
    mul *= 10;
    mul %= N;
  }
  cout << dp[size][5] << endl;
}


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

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

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

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n;
    string s;
    read(n, s);
    
    int l = 0, r = n - 1;
    int ans = 0;
    
    while (1) {
        while (l < r && s[l] == 'R') {
            l++;
        }
        while (l < r && s[r] == 'W') {
            r--;
        }
        if (l == r) {
            break;
        }
        swap(s[l], s[r]);
        ++ans;
    }
    
    print(ans);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
    //read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
const long long infty = 1e18;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<pair<int, pair<int, int>>> grh(m);
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    grh[i] = {c, {a, b}};
  }
  vector<long long> dst(n, -infty);
  dst[0] = 0;
  for (int i = 0; i < n; i++) {
    for (auto e : grh) {
      int c = e.first;
      int a = e.second.first;
      int b = e.second.second;
      if (dst[a] != -infty) {
        dst[b] = max(dst[b], dst[a] + c);
      }
    }
  }
  long long ans = dst[n - 1];
  for (int i = 0; i < n; i++) {
    for (auto e : grh) {
      int c = e.first;
      int a = e.second.first;
      int b = e.second.second;
      if (dst[a] != -infty) {
        dst[b] = max(dst[b], dst[a] + c);
      }
    }
  }
  if (dst[n - 1] > ans) {
    cout << "inf" << '\n';
  } else {
    cout << ans << '\n';
  }
  return 0;
}

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

using namespace std;

const int OO = 1e9;
const double EPS = 1e-9;

#define ndl cout << '\n'
#define sz(v) int(v.size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define present(a, x) (a.find(x) != a.end())
#ifdef LOCAL
#define db(...) ({cout << "> Line " << __LINE__  \
		<< ": "; _db(#__VA_ARGS__, __VA_ARGS__);})
#define RNG() rng()
#else
#define db(...) true
#define RNG() true
#endif

template<class T>
void _db(const char *dbStr, T e) {
	cout << dbStr << " = " << e << endl;
}
template<class T, class... L>
void _db(const char *dbStr, T e, L... r) {
  while(*dbStr != ',') cout << *dbStr++;
  cout << " = " << e << ','; _db(dbStr + 1, r...);
}
template<class S, class T>
ostream& operator<<(ostream& o, const map<S, T>& v) {
	o << "["; int i = 0;
	for (const pair<S, T>& pr : v) o << (!i++ ? "" : ", ") << "{"
	<< pr.fs << " : " << pr.sc << "}"; return o << "]";
}
template<template <class, class...> class S, class T, class... L>
ostream& operator<<(ostream& o, const S<T, L...>& v) {
	o << "["; int i = 0;
	for (const auto& e : v) o << (!i++ ? "" : ", ") << e;
	return o << "]";
}
template<class S, class T>
ostream& operator<<(ostream& o, const pair<S, T>& pr) {
	return o << "(" << pr.fs << ", " << pr.sc << ")";
}
ostream& operator<<(ostream& o, const string& s) {
	for (const char& c : s) o << c;
	return o;
}

template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = VV<V<T>>;
using ll = long long;
using pii = pair<int, int>;
using vi = V<int>;
using vii = V<pii>;
using vvi = VV<int>;
using mii = map<int, int>;
using umii = unordered_map<int, int>;
using si = set<int>;
using usi = unordered_set<int>;

int N, M;
V<vii> adj(55);
vi path;
int pid;
int edgeMask[55];	// edgesMask[i] = mask including which
// of the M paths pass through i'th edge
ll dp[55][1 << 21];



void dfs(int u, int p, int w) {
	if (u == w) {
		db(w, path, pid);
		for (auto& e : path) {
			edgeMask[e] |= (1 << pid);
		}
		return;
	}

	for (auto& pr : adj[u]) {
		int v = pr.fs, eid = pr.sc;
		if (v != p) {
			path.pb(eid);
			dfs(v, u, w);
			path.pop_back();
		}
	}
}

int main() {
	#ifdef LOCAL
	auto stTime = clock();
//	freopen("in.txt", "r", stdin);
	mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
	#endif
	ios::sync_with_stdio(false);
	cout.precision(10);
	cin.tie(0);

	cin >> N;

	for (int i = 0; i < N - 1; ++i) {
		int u, v;
		cin >> u >> v;
		adj[u].pb(mp(v, i));
		adj[v].pb(mp(u, i));
	}

	cin >> M;

	for (int i = 0; i < M; ++i) {
		int u, v;
		pid = i;
		cin >> u >> v;
		path.clear();
		dfs(u, -1, v);
	}

	dp[N - 1][(1 << M) - 1] = 1;


	for (int idx = N - 2; idx >= 0; --idx) {
		for (int msk = (1 << M) - 1; msk >= 0; --msk) {
			dp[idx][msk] = dp[idx + 1][msk] + dp[idx + 1][msk | edgeMask[idx]];
		}
	}

	cout << dp[0][0] << '\n';

	#ifdef LOCAL
	cout << "\n\n\nExecution time: " <<
		(clock() - stTime) * 1e3 / CLOCKS_PER_SEC << " ms" << endl;
	#endif
    return 0;
}


Measured memory_bytes: 504064
public class
Main
{
  public static void
  main (
    String[ ] args
    )
  {
    java.util.Scanner cin = new java.util.Scanner ( System.in );

    while ( cin.hasNext ( ) )
    {
      double a, b, c, d, p, q;
      double det;
      
      a = cin.nextDouble ( ); b = cin.nextDouble ( ); p = cin.nextDouble ( );
      c = cin.nextDouble ( ); d = cin.nextDouble ( ); q = cin.nextDouble ( );
      det = a * d - b * c;
      System.out.printf ( "%.3f %.3f\n"
                        , ( d * p - b * q ) / det + 0.
                        , ( a * q - c * p ) / det + 0. );
    }

    return ;
  }
}

Measured memory_bytes: 12000
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define coutd(v) cout<<# v<<" = "<<v<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll k,q;
    cin>>k>>q;
    vector<ll> d(k);
    FOR(i,0,k)cin>>d[i];
    FOR(i,0,q){
        ll n,x,m;
        cin>>n>>x>>m;
        x%=m;
        vector<ll> tmp = d;
        FOR(i,0,k) tmp[i]%=m;
        ll zero = 0;
        ll round_zero = 0;
        FOR(i,0,k)if(tmp[i]==0)round_zero++;
        FOR(i,0,(n-1)%k)if(tmp[i]==0)zero++;
        zero += round_zero*((n-1)/k);
        //coutd(zero);

        ll sum = 0;
        ll round_sum = 0;
        FOR(i,0,k)round_sum += tmp[i];
        FOR(i,0,(n-1)%k)sum += tmp[i];
        sum += round_sum*((n-1)/k);
        //coutd(sum);
        ll res = (sum+x)/m - x/m;
        //coutd(res);
        cout<<n-1-res-zero<<endl;

    }
}

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

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

	long long int output;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
	}
	output = A[0];
	for (int i = 1; i < N; i++) {
		if (1000000000000000000 / A[i] < output) {
			cout << -1 << endl;
			return 0;
		}
		output *= A[i];
	}

	// printf("%lld\n", output);
	cout << output << endl;

	return 0;
}

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

inline void init(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
}

int main() {
	init();
	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t;
}


Measured memory_bytes: 3648
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int 

// Function to sort the vector elements 
// by second element of pairs 
bool sortbysec(const pair<ll, ll>& a, 
			const pair<ll, ll>& b) 
{ 
	return (a.second < b.second); 
} 

// Function to find maximal disjoint set 
void maxDisjointIntervals(vector<pair<ll, ll> > list) 
{ 

	// Sort the list of intervals 
	sort(list.begin(), list.end(), sortbysec); 

	// First Interval will always be 
	// included in set 
	ll ans=1;

	// End point of first interval 
	ll r1 = list[0].second; 

	for (ll i = 1; i < list.size(); i++) { 
		ll l1 = list[i].first; 
		ll r2 = list[i].second; 

		// Check if given interval overlap with 
		// previously included interval, if not 
		// then include this interval and update 
		// the end point of last added interval 
		if (l1 >=r1) { 
			// cout << "[" << l1 << ", "
				// << r2 << "]" << endl;
			ans+=1; 
			r1 = r2; 
		} 
	} 
	cout<<ans<<"\n";
} 

// Driver code 
int main() 
{ 
	ll n;
	cin>>n;
	vector<pair<ll,ll>> intervals;
	for(ll i=0;i<n;i++){
		ll x,l;
		cin>>x>>l;
		intervals.push_back({x-l,x+l});
	}
	maxDisjointIntervals(intervals); 

	return 0; 
} 


Measured memory_bytes: 3440
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct Sieve {
    Sieve(int n) : l(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (!l[i]) p.push_back(l[i] = i);
            for (int q : p) {
                if (q > l[i]) break;
                if (int j = i * q; j <= n) l[j] = q; else break;
            }
        }
    }
    bool is_prime(int i) {
        return l[i] == i;
    }
    vector<int> l, p;
};

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

    int n;
    cin >> n;

    Sieve si(n);
    ll r = 0;

    for (int i = 1; i <= n; i++) {
        int t = i, d = 1;
        while (t > 1) {
            int k = 1;
            int l = si.l[t];
            while (t % l == 0) t /= l, k++;
            d *= k;
        }
        r += (ll)i * d;
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 46488
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
	int a[1000];
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	double res = 0;
	for(int i = 0; i < n; i++) res += 1.0/a[i];
	res = 1.0/res;
	cout << setprecision(10) << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define ull unsigned long long
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)

int main(){
	int A,B,M;
	scanf("%d %d %d",&A,&B,&M);
	int a[A],b[B];
	int minA=200000,minB=200000;
	rep(i,0,A){
		scanf("%d",&a[i]);
		minA = min(minA,a[i]);
	}
	rep(i,0,B){
		scanf("%d",&b[i]);
		minB = min(minB,b[i]);
	}
	int min=minA+minB;
	rep(i,0,M){
		int x,y,c;
		scanf("%d %d %d",&x,&y,&c);
		min = min(min,a[x-1]+b[y-1]-c);
	}
	printf("%d",min);
	return 0;
}

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

int main() {
	int N, i;
	cin >> N >> i;
	cout << N - i + 1;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

一種の植木算なので間違えないようにね
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s1,s2,s3;

int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>s1>>s2>>s3;
char c =toupper(s1[0]);
cout<<c;
 c =toupper(s2[0]);
cout<<c;
 c =toupper(s3[0]);
cout<<c;
return 0;}



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

int main(){
  double b,s[1000],n,x;
  while(1)
  {
    cin>>n;
    if(n==0) break;
    x=0;
    for(int i=0; i<n;i++)
	{
          cin>>s[i];
	  x+=s[i];
	}
    double m=x/n;
    b=0;
    for(int i=0; i<n; i++)
	{
          b+=(s[i]-m)*(s[i]-m);
	}
     printf("%.8lf\n",sqrt(b/n));
}
return 0;
}


Measured memory_bytes: 3300
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> ii;

const int MAXN = 5e5+1; //AREGLAAAAAAAAR!!!!

int main(){
	ll x,y;
	lrii(x,y);
	ll c=0;
	ll num=x;
	while(num<=y){
		c++;
		num*=2;
	}
	printf("%lld\n",c);
}
	

Measured memory_bytes: 256
n = int(input())
f = [list(map(int, input().split())) for i in range(n)]
p = [list(map(int, input().split())) for i in range(n)]

ans = -1234567890
for mask in range(1,2**10):
    tmp = 0
    for i in range(n):
        cnt = 0
        for x in range(10):
            if (mask>>x) % 2 == 1 and f[i][x] == 1: cnt += 1
        tmp += p[i][cnt]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main (void)
{
  string s,t;
  int count=0,ans=10000,ss,tt;
  
  cin>>s>>t;
  ss=s.size();
  tt=t.size();
//  cout<<ss<<" "<<tt<<endl;
  
  for(int i=0;i<=ss-tt;i++)
  {
    for(int j=i;j<i+tt;j++)
    {
      if(s[j]!=t[j-i]){count++;}
  //    cout<<s[j]<<" "<<t[j-i]<<endl;
    }
   // cout<<endl;
    if(count<ans){ans=count;}
    count=0;
  }
    cout<<ans<<endl;
  return 0;
  
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,x,y,m,n,mx,mx1,mx2;
    cin>>a>>b>>c>>d;
    x=a*c;
    y=a*d;
    m=b*c;
    n=b*d;
    mx=max(x,y);
    mx1=max(mx,m);
    mx2=max(mx1,n);
    cout<<mx2<<endl;
    return 0;
}


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

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, k; cin >> n >> k;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    sort(p, p + n);
    int total = 0;
    for (int i = 0; i < k; i++) total += p[i];
    cout << total << '\n';
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define F first
#define S second
#define X real()
#define Y imag()
#define PB push_back 
#define BE(c) c.begin(),c.end()
using namespace std;
typedef long long LL;
typedef complex<int> cld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef vector<ut,pr> ppr;
typedef priority_queue<pr,Vpr,greater<pr> > PQ;
typedef vector<ppr> Vppr;
const int SIZE=100+9*1e+5;
const int INF=1<<30;

int main(){
	int num=0;
	string s;
	cin >> s;
	REP(i,s.size())
		if((num%2==0&&s[i]=='A')||(num%2&& s[i]=='Z')){
			if(s[i]=='Z')
			cout <<"AZ";
			num++;
		}
	if(num<=1) cout <<-1;
	cout << endl;

}

Measured memory_bytes: 1184
from itertools import product

n, m, x = map(int, input().split())
ca = [list(map(int, input().split())) for _ in range(n)]

bit = [0, 1]
ans = float('inf')
for l in product(bit, repeat=n):
    a = [0] * m
    cnt = 0
    for k, i in enumerate(l):
        if i == 1:
            cnt += ca[k][0]
            for i in range(1, m + 1):
                a[i - 1] += ca[k][i]
    if all(i >= x for i in a):
        ans = min(ans, cnt)

print(-1 if ans==float('inf') else ans)



Measured memory_bytes: 68736
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>

using namespace std;

int a, b, c;

int main(){
	cin >> a >> b >> c;
	if (a < b && b < c) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 1156
A,B,K=map(int,input().split())
flag_1=False
flag_2=False
flag_3=False

if (A-K)>=0:
  flag_1=True
elif (A-K)<0 and (B-(K-A))>=0:
  flag_2=True
else:
  flag_3=True
if flag_1==True:
  print(A-K,B)
elif flag_2==True:
  print(0,B-(K-A))
else:
  print(0,0)


Measured memory_bytes: 3064
//Go to School

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a / __gcd(a, b) * b
#define range(a) (a).begin(),(a).end()
const int inf = 2147483647;

int main (){
    int N;cin >> N;
    vector<int> A(N);
    rep(i,0,N)cin >> A[i];
    map<int,int> H{};
    rep(i,0,N){
        H[A[i]]=i+1;
    }
    rep(i,1,N+1){
        cout << H[i] << " ";
    }
    cout << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  int A[2][N];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < N; j++)
      cin >> A[i][j];
  }
  vector<int> S;
  int su = 0;
  for (int i = 0; i < N; i++)
    su += A[0][i];
  int sd = A[1][N-1];
  S.push_back(su + sd);
  for (int i = 1; i < N; i++) {
    su -= A[0][N-i]; sd += A[1][N-1-i];
    S.push_back(su + sd);
  }
  sort(S.begin(), S.end());
  cout << S[N-1] << endl;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>
#include <cstdint>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef unsigned long long		SQWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	ll N, K;
	cin >> N >> K;

	ll evNum = N / K;
	ll sum = evNum * evNum * evNum;

	if (IsEven(K)) {
		ll oddNum = (N + K / 2) / K;
		sum += (oddNum * oddNum * oddNum);
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

deque<int> X;
vi Y;

bitset<17000> dp[8001];
bitset<17000> dp2[8001];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	string s; cin>>s;
	int x,y; cin>>x>>y;
	int n=s.length();
	int cur=1; int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='F')
		{
			cnt++;
		}
		else
		{
			if(cur) X.pb(cnt);
			else Y.pb(cnt);
			cnt=0; cur^=1;
		}
	}
	if(cur) X.pb(cnt);
	else Y.pb(cnt);
	
	if(!X.empty())
	{
		x-=X.front();
		X.pop_front();
		x=abs(x);y=abs(y);
	}
	
	cur=0;
	for(int i=0;i<X.size();i++)
	{
		cur+=X[i];
	}
	int diff1 = cur - x;
	for(int i=0;i<X.size();i++){X[i]*=2;}
	cur=0;
	for(int i=0;i<Y.size();i++)
	{
		cur+=Y[i];
	}
	int diff2=cur-y;
	for(int i=0;i<Y.size();i++) Y[i]*=2;
	dp[0].set(0); 
	if(!X.empty()) dp[0].set(X[0]);
	//cerr<<diff1<<' '<<diff2<<'\n';
	for(int i=1;i<X.size();i++)
	{
		dp[i] = dp[i-1]|(dp[i-1]<<X[i]);
	}
	dp2[0].set(0);
	if(!Y.empty()) dp2[0].set(Y[0]);
	for(int i=1;i<Y.size();i++)
	{
		dp2[i]=dp2[i-1]|(dp2[i-1]<<Y[i]);
	}
	if(X.empty()&&Y.empty())
	{
		if(diff1==0&&diff2==0) cout<<"Yes\n";
		else cout<<"No\n";
		return 0;
	}
	if(Y.empty())
	{
		if(diff1>=0&&diff2==0&&dp[int(X.size())-1][diff1]) cout<<"Yes\n";
		else cout<<"No\n";
		return 0;
	}
	if(X.empty())
	{
		if(diff1>=0&&diff2==0&&dp2[int(Y.size())-1][diff2]) cout<<"Yes\n";
		else cout<<"No\n";
		return 0;
	}
	if(diff1>=0&&diff2>=0&&dp[int(X.size())-1][diff1]&&dp2[int(Y.size())-1][diff2])
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  cin >> s;
  
  int ans = 0, l = 0, r = s.size() - 1;
  while (l < r) {
    if (s.at(l) == s.at(r)) {
      l++;
      r--;
    }
    else {
      if (s.at(l) != 'x' && s.at(r) != 'x') {
        cout << "-1\n";
        return 0;
      }
      else if (s.at(l) == 'x') {
        ans++;
        l++;
      }
      else {
        ans++;
        r--;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 512
def f(n):
    if n % 2 == 0:
        return n // 2
    return 3 * n + 1


def main():
    s = int(input())
    aa = {s}
    a = f(s)
    for i in range(2, 1000001):
        if a in aa:
            print(i)
            break
        aa.add(a)
        a = f(a)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

/*
const ll MOD = (ll)1e9 + 7;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
*/

const int N = 50;
bool a[N][N];

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

	ll x, y;
	scanf("%lld%lld", &x, &y);
	if (abs(x - y) <= 1) {
		printf("Brown\n");
	} else {
		printf("Alice\n");
	}
	return 0;

	for (int s = 1; s < N; s++) {
		for (int x = 0; x <= s; x++) {
			int y = s - x;
			for (int i = 1; 2 * i <= x; i++)
				a[x][y] |= !a[x - 2 * i][y + i];
			for (int i = 1; 2 * i <= y; i++)
				a[x][y] |= !a[x + i][y - 2 * i];
		}
	}
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < 20; j++) {
			printf("%d", (int)a[i][j]);
		}
		printf("\n");
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define llu unsigned long long int
#define Endl endl
#define mod  998244353
#define mkp make_pair
#define pb push_back
#define cin(n) scanf("%d",&n)
#define cout(n) printf("%d ",n)
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d ",n)
#define bitget(n) __builtin_popcountll(n)
ll dx[] = {1,1,0,-1,-1,-1,0,1};
ll dy[] = {0,-1,-1,-1,0,1,1,1};
ll dxx[] = {1,-1,0,0};
ll dyy[] = {0,0,-1,1};
ll modexpo(ll x,ll y){if(y==0)return 1;if(y%2){ll viky=modexpo(x,y/2);
return (((x*viky)%mod)*viky)%mod;}else{ll viky=modexpo(x,y/2);return (viky*viky)%mod;
}}
// ll intpoint(ll x1, ll y1, ll x2, ll y2) { return ( __gcd(abs(x1-x2),abs(y1-y2))+1); }
// bool isvalid(ll x,ll y,ll n,ll m) { return (x>=0&&x<n&&y>=0&&y<m); }
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// int pp = uniform_int_distribution<int>(0, kk-1)(rng);
// ---------------------///////////////---------------------------------
// ---------------------///////////////----------------------------------
// -------------/////////////////---------------------------------///////



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

    ll n;
    string s;
    cin>>n>>s;
    if(n<3200){
        cout<<"red";
    }else{
        cout<<s;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
#include <cmath>
#include <climits>
#include <unordered_map>
using namespace std;

int main() {

int x;
cin>>x;

if (x==0)cout<<"1\n";
else cout<<"0\n";





return 0;
}


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

int main(void)
{
	int n;
	int i;
	scanf("%d",&n);
	for (i = 0; i < n; i += 1)
	{
		double x1,y1,x2,y2,x3,y3,x4,y4;
		scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		x2-=x1;
		y2-=y1;
		x4-=x3;
		y4-=y3;
		if(x2*y4-y2*x4 == 0.0)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    
    '''w,h=MI()
    lis=[LI() for i in range(h)]
    step=[[0,-1],[-1,0],[-1,1],[0,-1],[1,0],[0,1]]
    print(lis)
    for i in range(h):
        for j in range(w):
            if lis[i][j]==0:
                count=0
                for x,y in step:
                    if 0<=i+x<h and 0<=j+y<w and lis[i+x][j+y]==1:
                        count+=1
            if count==6:
                lis[i][j]=1
    ans=0
    for i in range(h):
        for j in range(w):
            if lis[i][j]==1:
                for x,y in step:
                    if not (0<=i+x<h and 0<=j+y<w):
                        ans+=1
                    elif lis[i+x][j+y]==0:
                        ans+=1
            print(ans)
    print(ans)
                        
    print(lis)'''
    n=I()
    if n%2==0:
        print(n//2-1)
    else:
        print((n-1)//2)
if __name__=="__main__":
    main()


Measured memory_bytes: 65872
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
import numpy as np
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

#n players, k points, q rounds
[n,k,q] = inpl()
pcount = defaultdict(int)
for _ in range(q):
    i = inp()
    pcount[i] += 1
    
for _ in range(1,n+1):
    print('Yes' if k-q+pcount[_]>0 else 'No')

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

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

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  int n;cin>>n;
  int p[n],cnt=0;rep(i,n)cin>>p[i];
  rep2(i,1,n-1){
    //cout<<i<<endl;
    if(p[i-1]<p[i] && p[i]<p[i+1])cnt++;
    else if(p[i-1]>p[i] && p[i]>p[i+1]) cnt++;
  }
  cout<<cnt<<endl;
}


Measured memory_bytes: 256