akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    ll x,y;
    cin>>x>>y;

    if(x*-1==y){        //ok
        cout << 1 << endl;
        return 0;
    }

    if(x==0){           // ok
        if(y>0){
            cout << y << endl;
        }else if(y<0){
            cout << (-1)*y + 1 << endl;
        }else{
            assert(false);
        }
        return 0;
    }

    if(y==0){           // ok
        if(x<0){
            cout << abs(x) << endl;
        }else if(x>0){
            cout << x + 1 << endl;
        }else{
            assert(false);
        }
        return 0;
    }


    if(x<y){
        if(x<0 and y<0){
            cout << y-x << endl;
            return 0;
        }else if(x>0 and y>0){
            cout << y-x << endl;
            return 0;
        }else if(x<0 and y>0){
            //error
            ll a = y-(-1)*x + 1;
            ll b = y-x;
            ll c = -y-x+1;
            if(abs(x) < y){
                cout << min(b,a) << endl;
            }else{
                cout << min(b,c) << endl;
            }
            return 0;
        }else{
            assert(false);
        }
    }else if(x>y){
        if(x<0 and y<0){
            ll a = abs(y)-x;                // x -> -y -> y
            ll b = abs(y)-abs(x);           // x -> -x -> -y -> y
            cout << min(a+1,b+2) << endl;
        }else if(x>0 and y>0){
            ll a = y-(-1)*x;                // x -> -x -> y
            ll b = y*(-1) - x*(-1);         // x -> -x -> -y -> y
            cout << min(a+1,b+2) << endl;
        }else if(x>0 and y<0){
            if(abs(y)<x){
                cout << y-x*(-1)+1 << endl; // x -> -x -> y
                return 0;
            }else{
                cout << y*(-1)-x+1 << endl;  // x -> -y -> y
                return 0;
            }
        }else{
            assert(false);
        }
    }else{
        assert(false);
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
using namespace std;
int inf = 1000000000;

int main(void) {

  int m;
  while( cin >> m ){
    if( m == 0 ) break;
    vector<int> a(m);
    vector<int> b(m);
    for(int i=0; i<m; i++) cin >> a[i] >> b[i];

    vector< vector<int> > dp(m+1, vector<int> (1001, 0));
    dp[0][0] = 1;
    for(int i=0; i<m; i++){
      for(int j=0; j<1001; j++){
        for(int k=0; k<=b[i]; k++){
          if( j - a[i] * k < 0 ) continue;
          dp[i+1][j] += dp[i][ j-a[i]*k ];
        }
      }
    }
    int g;
    cin >> g;
    for(int i=0; i<g; i++){
      int n; cin >> n;
      cout << dp[m][n] << endl;
    }

  }

  return 0;
}

// EOF

Measured memory_bytes: 3084
from collections import Counter

N,M = map(int, input().split())
H = list(map(int, input().split()))
AB = []
for i in range(M):
    AB.append(list(map(int, input().split())))

l = [True]*N

for m in AB:
    if H[m[0]-1] == H[m[1]-1]:
        l[m[0]-1] = False
        l[m[1]-1] = False
    elif H[m[0]-1] > H[m[1]-1]:
        l[m[1]-1] = False
    else:
        l[m[0]-1] = False

print(Counter(l)[True])

Measured memory_bytes: 32172
#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.141592653589793
#define epsilon 0.000000001
#define INF 1000000000000000000
#define MOD 1000000007

int main(){
    //freopen("grass.in", "r", stdin); freopen("grass.out", "w", stdout);
    string s; cin >> s;
    if(s.find("YAKI") != 0) cout << "No\n";
    else cout << "Yes\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
countlist = []
for i in range(0, 100001):
	countlist.append(0)
for i in range(0, N):
	countlist[A[i]] += 1
max = 0
for i in range(0, 100001):
	sum = countlist[i]
	if i != 0: sum += countlist[i-1]
	if i != 100000: sum += countlist[i+1]
	if max < sum: max = sum
print(max)

Measured memory_bytes: 56260
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		const long MOD = 1000000007;
		static void Main(string[] args)
		{
			var cin = new Scanner2();
			int n = cin.Int();
			long[] t = cin.ArrayLong(n);
			long[] a = cin.ArrayLong(n);

			if (t[n - 1] != a[0] || t[0] > a[0] || t[n - 1] < a[n - 1]) {
				Console.WriteLine(0);
				return;
			}

			for (int i = 1; i < n; i++) {
				if (t[i] > t[i - 1] && t[i] > a[i]) {
					Console.WriteLine(0);
					return;
				}
			}

			for (int i = n - 2; i >= 0; i--) {
				if (a[i] > a[i + 1] && a[i] > t[i]) {
					Console.WriteLine(0);
					return;
				}
			}

			long ans = 1;
			for (int i = 1; i < n - 1; i++) {
				if (t[i] > t[i - 1] && a[i] > a[i + 1]) {
					if (t[i] != a[i]) {
						Console.WriteLine(0);
						return;
					}
				} else if (t[i] > t[i - 1] || a[i] > a[i + 1]) {
				} else {
					long max = Math.Min(t[i], a[i]);
					if (max > 1) {
						ans = (ans * max) % MOD;
					}
				}
			}

			Console.WriteLine(ans);
		}
	}

	public class Scanner2
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private readonly string filePath_;
		private string[] buf_;
		private int index_;
		Func<string> reader_;

		public Scanner2(string file = "")
		{
			if (string.IsNullOrWhiteSpace(file)) {
				reader_ = Console.ReadLine;
			} else {
				filePath_ = file;
				var fs = new StreamReader(file);
				reader_ = fs.ReadLine;
			}
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = reader_();
			while (st == "") {
				st = reader_();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int() => int.Parse(Next());
		public long Long() => long.Parse(Next());
		public double Double() => double.Parse(Next());

		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}

		public void Save(string text)
		{
			if (string.IsNullOrWhiteSpace(filePath_)) {
				return;
			}

			File.WriteAllText(filePath_ + "_output.txt", text);
		}
	}
}

Measured memory_bytes: 33704
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,g;
    cin>>a;
    rep(i,a){
        cin>>b>>c;
        sum+=c-b+1;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3608
import math
S = input()
N = len(S)

ans = [0] * N
R = 1
L = 0
tmp = -1

for i in range(1, N):
  if S[i] == "R":
    R += 1
  else:
    L += 1

  if S[i-1] == "R" and S[i] == "L":
    ans[i-1] += math.ceil(R / 2)
    ans[i] += math.floor(R / 2)

    if i + 1 == N:
      ans[i] += 1

    R = 0
    tmp = i
  elif (S[i-1] == "L" and S[i] == "R") or (i + 1 == N):
    ans[tmp-1] += math.floor(L / 2)
    ans[tmp] += math.ceil(L / 2)
    L = 0
    tmp = -1
    
print(*ans)

Measured memory_bytes: 6400
#include <iostream>
#include <cstdio>
#include <atcoder/fenwicktree>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rep2(i,s,t) for(int i = s; i <= t; ++i)
#define rev(i,n) for(int i = n-1; i >= 0; --i)
#define rev1(i,n) for(int i = n; i > 0; --i)
#define rev2(i,s,t) for(int i = s; i >= t; --i)
#define F first
#define S second
using namespace std;
using namespace atcoder;
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; }
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
int main()
{
  int n,q; scanf("%d %d", &n, &q);

  fenwick_tree<ll> fw(n);
  rep(i,n) {
    ll a; scanf("%lld", &a);
    fw.add(i, a);
  }

  rep(i,q) {
    int t; scanf("%d", &t);
    if(t == 0) {
      ll p, x; scanf("%lld %lld", &p, &x);
      fw.add(p, x);
    }
    else {
      int l, r; cin >> l >> r;
      printf("%lld\n", fw.sum(l, r));
    }
  }
  return 0;
}


Measured memory_bytes: 8260
// D - Sum of Divisors
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	long long  s = 0;
	for(int d=1; d<=N; ++d)
		for(int k=d; k<=N; k+=d) s += k;
	cout<< s <<endl;
}


Measured memory_bytes: 3604
n,m,x=gets.split.map(&:to_i)
mathCosts = Hash[(0..n).map{|k|[k,0]}]
gets.split.map{|pos| mathCosts[pos.to_i]=1}
leftCostSum = (0..x).map{|pos| mathCosts[pos]}.inject(:+)
rightCostSum = (x..n).map{|pos| mathCosts[pos]}.inject(:+)
puts leftCostSum >= rightCostSum ? rightCostSum : leftCostSum

Measured memory_bytes: 1788
import scala.collection.mutable
import scala.io.StdIn._

object Main
  extends App {
  def primeNumbers(stream: Stream[Int] = Stream.from(2)): Stream[Int] = stream match {
    case h #:: tail => h #:: primeNumbers(tail.filter(_ % h != 0))
  }

  def isPrime(n: Int): Boolean =
    if (n == 1) false
    else if (n == 2 || n == 3) true
    else (2 to math.sqrt(n).toInt).forall(n % _ != 0)

  val N = 1000000
  val primeNumbers: mutable.HashSet[Int] = (2 to N).to[mutable.HashSet]
  (2 to math.sqrt(N).toInt).foreach(n =>
    if (primeNumbers.contains(n)) Range(n * n, N, n).foreach(primeNumbers -= _)
  )

//  val primeNumbers = (2 to math.sqrt(N).toInt).foldLeft((2 to N).toSet)((acc, n) =>
//    if (acc.contains(n)) acc.diff(Range(n * n, N, n).toSet) else acc
//  )


  Stream
    .continually(readLine)
    .takeWhile(_ != null)
    .map(_.toInt)
//    .map(n => if (n == 1) 0 else primeNumbers().takeWhile(_ <= n).size)
//    .map(n => (1 to n).count(isPrime))
    .map(n => primeNumbers.count(_ <= n))
    .foreach(println)
}



Measured memory_bytes: 160860
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

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

    Scanner sc = new Scanner(System.in);

    void solve() {
        String s = sc.nextLine();
        String p = sc.nextLine();
        String[] ring = (s + s).split("");
        String[] pArr = p.split("");
        for (int i = 0; i < ring.length; ++i) {
            boolean f = true;
            int cnt = 0;
            for (int j = 0; j < pArr.length && i + j < ring.length; ++j) {
                if (!ring[i + j].equals(pArr[j])) {
                    f = false;
                    break;
                }
                cnt++;
            }
            if (f && cnt == p.length()) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}






Measured memory_bytes: 26324
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
const long long int mod=1e9+7;
typedef long long ll;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
double reabs(double in){
    if(in<0){
        return (-1)*in;
    }else{
        return in;
    }
}

int main(){
    int A,B;
    cin>>A>>B;

    int ans=0;

    for(int i=A;i<=B;i++){
        if(((i/10000)==(i%10)) &&(((i/1000)%10)==((i/10)%10))){
            //cout<<i<<endl;
            ans++;
        }
    }

    cout<<ans<<endl;

    return 0;
}




Measured memory_bytes: 256
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

#define	numberof(a)	(sizeof(a) / sizeof(a[0]))
#define	INF32		INT32_MAX
#define	INF64		INT64_MAX
#define Rep(i,n) for(int i = 0; i < (n); ++i )

using namespace std;

typedef vector< vector<int> > MAT;
typedef pair<int, int> PINT;
typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int32_t s32;
typedef int64_t s64;

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//ll dp[500000 * 2000 + 10];	// dp[i日目]までの勝ち数
vector<ll> output_dist;
void dijkstra(vector< vector< pair<ll, ll> > > & G, ll startNode)
{
	/*
	example).
	vector< vector< pair<ll, ll> > > G(H * W);// G[i][j]:ノードiにつながっているj番目のノード(firstがノード番号, secondがコスト

	G[0].push_back(make_pair(1, 1));
	G[1].push_back(make_pair(2, 1));
	...

	vector<ll> result = dijkstra(G, 0);
	*/
	priority_queue< pair<ll, ll> > searchPQ;	// PQの要素はこれから探索するノード(firstがコスト, secondがノード番号)
	const ll node_number = G.size();
	vector<bool> isChecked(node_number, false);	// trueのときは探索済

	output_dist.resize(node_number);

	Rep(i, node_number) {
		output_dist[i] = INF64;
		isChecked[i] = false;
	}

	// 起点からスタート
	output_dist[startNode] = 0;
	searchPQ.push(make_pair(0, startNode));

	while (!searchPQ.empty())
	{
		pair<ll, ll> search_node = searchPQ.top(); searchPQ.pop();
		ll u = search_node.second;// 調べるノード
		isChecked[u] = true;

		if (output_dist[u] < search_node.first * (-1)) continue;// search_node.firstは負の値にしている

		for (ll j = 0; j < G[u].size(); j++) {
			// uにつながっているノードを探索
			ll v = G[u][j].first;
			if (isChecked[v] == true) continue;
			if (output_dist[v] > output_dist[u] + G[u][j].second) {
				output_dist[v] = output_dist[u] + G[u][j].second;
				searchPQ.push(make_pair(output_dist[v] * (-1), v));//priority_queueはデフォルトで大きい値をpopしてしまうのでマイナスをかける
			}
		}
	}
}

// main function
int main()
{
	ll N = 0;
	ll Q = 0;
	ll K = 0;
	ll ans = 0;

	cin >> N;

	vector< vector< pair<ll, ll> > > G(N);// G[i][j]:ノードiにつながっているj番目のノード(firstがノード番号, secondがコスト)
	Rep(i, N - 1) {
		ll A = 0;
		ll B = 0;
		ll C = 0;

		cin >> A >> B >> C;
		A--;
		B--;
		C;

		// create graph
		G[A].push_back( make_pair(B, C) );
		G[B].push_back(make_pair(A, C));
	}

	cin >> Q >> K;
	K--;
	dijkstra(G, K);
	Rep(i, Q) {
		ll src = 0;
		ll tar = 0;

		cin >> src >> tar;
		src--;
		tar--;

		// solve
		// dist(K - src) + dist(K - tar)
		ans = output_dist[src] + output_dist[tar];

		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 11120
from itertools import product
import numpy as np


N, M, X = list(map(int, input().split()))
INF = 10**5 * 12 + 1
books = np.array([list(map(int, input().split())) for i in range(N)])
ans = INF
for selection in product([0, 1], repeat=N):
    selection = np.array(selection).reshape(N, 1)
    res = (books * selection).sum(axis=0)
    if min(res[1:]) >= X:
        ans = min(ans, res[0])
print(ans if ans != INF else -1)


Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  int r = n % 10;
  string ans;
  if (r == 3) {
    ans = "bon";
  } else if (r == 0 || r == 1 || r == 6 || r == 8) {
    ans = "pon";
  } else {
    ans = "hon";
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3552
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	int a = 1;
	for (int i = N - 1; i >= 0; i--) {
		res += A[i] * a;
		a = -a;
	}
	cout << res << endl;
}

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

int main(){
	int n;
	while(cin>>n,n){
		int mx=0,mn=1e8;
		for(int i=0;i<n;i++){
			int a,b,c,d,e;
			cin>>a>>b>>c>>d>>e;
			mx=max(mx,a+b+c+d+e);
			mn=min(mn,a+b+c+d+e);
			}
			cout<<mx<<' '<<mn<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3076
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int N, L;
    cin >> N >> L;
    vector<string> s(N);
    for(int i=0; i<N; i++) cin >> s[i];
    
    sort(s.begin(), s.end());
    for(int i=0; i<N; i++) cout << s[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
	string s;cin >> s;
	int n = s.size();
	int a = 0;
	for(;a < n && s[a] != 'A';a++);
	int z = n;
	for(;z > 0 && s[z-1] != 'Z';z--);
	cout << z - a << endl;
	return 0;
}

Measured memory_bytes: 3724
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k=int(input())
ml=[i for i in range(k+1)]
n=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            if i==j==l:
                continue
            n+=gcd(i,j,l)         
print(n+sum(ml))

Measured memory_bytes: 69776
Scanf.scanf "%d" (fun n ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a)) in
    Array.sort compare a;
    let f = n mod 2 in
    let rec loop i =
        if i = n then true else (
            if f = 0 then (
                if i / 2 * 2 + 1 = a.(i) then loop (i + 1) else false
            ) else (
                if (i + 1) / 2 * 2 = a.(i) then loop (i + 1) else false
            )
        )
    in
    let z = 1_000_000_007 in
    let ( *@) a b = (a * b) mod z in
    let powmod a b =
        let rec loop r i acc =
            if i = 0 then acc else loop (r *@ r) (i lsr 1) (if i land 1 = 1 then acc *@ r else acc)
        in
        loop a b 1
    in
    Printf.printf "%d\n" @@ if loop 0 then powmod 2 ((n - f) lsr 1) else 0
)

Measured memory_bytes: 6636
#include<iostream>
#include<vector>
#include<string>
#include<set>
using namespace std;

struct Group{
  string name;
  set<string> member;    
};

struct Group group[100];
bool use[100];
int n;

void open(int x){
  bool f;
  set<string>::iterator ite;
  f = false;
  for(ite = group[x].member.begin();ite!=group[x].member.end();ite++){
    if(f)ite = group[x].member.begin();
    f = false;
    for(int i=0;i<n;i++){
      if(group[i].name == *ite){
	//cout << "[" << *ite << "]" << endl;
	group[x].member.erase(ite);
	/*if(!use[i])*/open(i);
	set<string>::iterator j;
	for(j=group[i].member.begin();j!=group[i].member.end();j++){
	  group[x].member.insert(*j);
	}
	f = true;
	break;
      }
    }
  }
  use[x] = true;
}

int main(){
  int i;
  int c;
  string tmp,tmp2;

  while(1){
    cin >> n;
    if(!n)break;

    for(i=0;i<n;i++){
      group[i].name.clear();
      group[i].member.clear();
    }

    for(i=0;i<n;i++){
      cin >> tmp;
      c = 0;
      while(tmp[c]!=':'){
	group[i].name.push_back(tmp[c]);
	c++;
      }
      while(tmp[c] != '.'){
	c++;
	while(tmp[c] != ',' && tmp[c] != '.' ){
	  tmp2.push_back(tmp[c]);
	  c++;
	}
	group[i].member.insert(tmp2);
	tmp2.clear();
      }
    }

    for(i=0;i<n;i++)use[i] = false;
    open(0);
    /*
    for(int i=0;i<n;i++){
      set<string>::iterator ite;
      for(ite = group[i].member.begin();ite!=group[i].member.end();ite++){
	cout<< *ite << " ";
      }
      cout << endl;
    }
    */
    cout << group[0].member.size() << endl;    

  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  ll x;
  cin >> x;
  int y = pow(x, 1.0 / 3.0);
  FOR(i, -y - 1, y + 1) {
    FOR(j, -y - 1, y + 1) {
      if (pow(i, 5) - pow(j, 5) == x) {
        print(i, j);
        return 0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 4096
N = int(input())
A = list(map(int, input().split()))

ans = 0
w_xor,w_sum = A[0],A[0]
l,r = 0,0

while l < N and r < N:
  #print(l,r,w_xor, w_sum)

  if w_xor == w_sum:
    if r < N-1:
    #print(l,r)
      r += 1
      w_xor = w_xor ^ A[r]
      w_sum = w_sum + A[r]
      continue
    else:
      ans += 1+r-l
  else:
    # l,r-1、までがマッチしてたということなので1小さい
    ans += r-l
  w_xor = w_xor ^ A[l] 
  w_sum = w_sum - A[l]
  l += 1
  
print(ans)

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

int main() {
  long long n;
  cin>>n;
  long long ans = n;
  for (int i=1; i<=sqrt(n); i++) {
    if (n % i != 0) {
      continue;
    }
    long long j = n / i;
    ans = min(i - 1 + j - 1, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>
#include <bitset>
#include <atcoder/all>
 
using namespace std;
using namespace atcoder;
 
/* template */
 
using ll = long long;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
 
#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};
 
struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};
 
using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

template <class T>
inline bool chmin(T &a, T b){
    if (a > b){
        a = b;
        return true;
    }
    return false;
}
 
template <class T>
inline bool chmax(T &a, T b){
    if (a < b){
        a = b;
        return true;
    }
    return false;
}
 
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
 
constexpr ll LNF = 1LL<<50;
 
constexpr int INF = 1e9+7;
 
const long double PI=3.14159265358979323846;

vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1,0,-1};

/* template */

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    while(t>0){
        ll n,m,a,b; cin >> n >> m >>  a >> b;
        cout << floor_sum(n,m,a,b) << endl;
        t--;
    }
}


Measured memory_bytes: 3648
import itertools
import sys
import math
import numpy as np
from collections import deque
from itertools import combinations
from functools import reduce
from functools import lru_cache
sys.setrecursionlimit(10**9)

def main():
    N = int(input())
    print(math.ceil(N/2))

if __name__ == "__main__":
  main()


Measured memory_bytes: 21900
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int X, Y, Z;
  while (cin >> X >> Y >> Z) {
    swap(X, Y);
    swap(X, Z);
    cout << X << " " << Y << " " << Z << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input!{a:i64,b:i64};
    println!("{}", (a+b)%24);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long ll;
#define _GLIBCXX_DEBUG
#define int long long
using namespace std;
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MAXIN(x) max_element(ALL(x)) - x.begin();
#define MIN(x) *min_element(ALL(x))
#define MININ(x) min_element(ALL(x)) - x.begin();
#define INF 1000000000000
#define MOD 100000070

#define MAXR 100000
#define PI 3.14159265358979323846

using namespace std;

bool is_product_overflow(int a, int b) {
    int prod = a * b;

    return (prod / b != a);
}

bool over(int a, int b) {
    if (a < LLONG_MAX / b) {
        return false;
    } else {
        return true;
    }
}

signed main() {
    int n;
    cin >> n;
    vector<int> A(n);
    REP(i, n) {
        cin >> A[i];
        if (A[i] == 0) {
            cout << "0" << endl;
            return 0;
        }
    }
    int ans = 1;
    int MM = 1000000000000000000;

    REP(i, n) {
        if (over(ans, A[i])) {
            cout << "-1" << endl;
            return 0;
        }

        ans *= A[i];

        if (ans > MM) {
            cout << "-1" << endl;
            return 0;
        }
    }

    cout << ans << endl;
    cout << " " << endl;
    return 0;
}

Measured memory_bytes: 3988
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> buffer;

int dfs(int m, int sum, int rem){
        if(rem == 0){
                ++(buffer[sum]);
                return 1;
        }
        int retval = 0;
        for(int i = 1; i <= m; ++i){ retval += dfs(m, sum + i, rem - 1); }
        return retval;
}

int main(){
        cout << setprecision(10);
        while(true){
                int n, m, k;
                cin >> n >> m >> k;
                if(n == 0 && m == 0 && k == 0){ break; }
                buffer.resize(n * m + 1);
                fill(buffer.begin(), buffer.end(), 0);
                int num = dfs(m, 0, n);
                double answer = 0.0;
                for(int i = 0; i < buffer.size(); ++i){
                        if(i <= k){
                                answer += 1.0 * buffer[i] / num;
                        }else{
                                answer += (double)(i - k) * buffer[i] / num;
                        }
                }
                cout << answer << endl;
        }
        return 0;
}

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

int main() {
  string s; cin >> s;
  if (s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,k;
    cin >> a >> b >> k;
    vector<int> v;
    while(a % b != 0)
    {
        int r = a % b;
        a = b;
        b = r;
    }
    for(int i = 1;i <= sqrt(b);i++)
    {
        if(b % i == 0)
        {
            v.push_back(i);
            if(i != b / i)
            {
                v.push_back(b / i);
            }
        }
    }
    sort(v.begin(),v.end(),greater<int>());
    cout << v.at(k - 1);

    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappushpop, heapify

N,*A = map(int,read().split())

def from_left(A):
    q = A[:N]
    S = sum(q)
    heapify(q)
    B = [0] * (N+N+N)
    B[N-1] = S
    for i,x in enumerate(A[N:],N):
        S += x
        S -= heappushpop(q,x)
        B[i] = S
    return B

L = from_left(A)
R = [-x for x in from_left([-x for x in A[::-1]])[::-1]]

L = L[N-1:-N]
R = R[::-1][N-1:-N][::-1]
answer = max(l - r for l,r in zip(L,R))
print(answer)

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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];

int last[T];
int score = 0;
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

int FindMaxProfitContest(int day) {
    int max_profit = -1e9, argmax = -1;
    REP(type, T) {
        int profit = 0;
        profit += s[day - 1][type];
        profit += c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

void Commit(int day, int contest) {
    ans.push_back(contest);
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

int main() {
    Input();
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContest(day);
        Commit(day, contest);
    }
    Output();
    return 0;
}


Measured memory_bytes: 3676
n, a = gets.strip.split(' ').map(&:to_i)
x = gets.strip.split(' ').map(&:to_i).map {|x| x-a }.sort

dp=Hash.new(0)
dp[0]=1

n.times do |num|
  copy_dp = dp.dup
  copy_dp.each do |k, v|
    dp[k + x[num]] += v
  end
end

#p x
p dp[0]-1


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

using namespace std;
int main()
{
   int x;
cin>>x;
   if(x>=400 && x<=599)
    cout<<"8"<<endl;
  else  if(x>=600 && x<=799)
    cout<<"7"<<endl;
    else if(x>=800 && x<=999)
    cout<<"6"<<endl;
   else if(x>=1000 && x<=1199)
    cout<<"5"<<endl;
  else if(x>=1200 && x<=1399)
    cout<<"4"<<endl;
    else if(x>=1400 && x<=1599)
    cout<<"3"<<endl;
   else  if(x>=1600 && x<=1799)
    cout<<"2"<<endl;
   else if(x>=1800 && x<=1999)
    cout<<"1"<<endl;

   return 0;
}


Measured memory_bytes: 3540
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    # divisors.sort()
    return divisors

cnt = 0
for i in range(1, N+1, 2):
    divis = make_divisors(i)
    if len(divis) == 8:
        cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int n = s.length();
    vector<int> ans(n, 0);
    
    bool flag = false;
    for(int i = 0; i < n; ++i){
        if(s[i] == 'R'){
            flag = true;
            continue;
        }
        
        if(flag && s[i] == 'L'){
            s[i-1] = 'r';
            s[i] = 'l';
            flag = false;
        }
    }
    
    int index = 0;
    while(index < n){
        if(s[index] == 'r'){
            ++ans[index++];
        }
        else if(s[index] == 'l'){
            ++ans[index++];
        }
        
        else if(s[index] == 'R'){
            int cnt = 1;
            int dist = 1;
            int id = index + 1;
            while(id < n){
                if(s[id] == 'R'){
                    ++cnt;
                    ++dist;
                    ++id;
                }
                else{
                    break;
                }
            }
            int half = cnt / 2;
            if(dist % 2 == 0){
                ans[id] += half;
                ans[id+1] += half;
            }
            else{
                ans[id] += half;
                ans[id+1] += cnt - half;
            }
                    
            index = id;
        }
        
        else{   // s[i] == 'L'
            int cnt = 1;
            int dist = 1;
            int id = index + 1;

            while(id < n){
                if(s[id] == 'L'){
                    ++cnt;
                    ++dist;
                    ++id;
                }
                else{
                    break;
                }
            }
            
            int half = cnt / 2;
            if(dist % 2 == 0){
                ans[index - 1] += half;
                ans[index - 2] += half;
            }
            else{
                ans[index - 1] += half;
                ans[index - 2] += cnt - half;
            }
            
            index = id;
        }
    }
    
    for(int i = 0; i < n; ++i){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int* a = new int[n];
    for(int i = 0; i < n; i++){
        a[i] = 0;
    }
    int d;
    for(int i = 0; i< k; i++){
        cin >> d;
        for(int j = 0; j < d; j++){
            int b;
            cin >> b;
            if(a[b-1] == 0){
                a[b-1] = 1;
            }
        }
    }
    int count = 0;
    for(int i = 0; i< n; i++){
        if(a[i] == 0)   count++;
    }
    cout << count <<  endl;
    delete[] a;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main(void){
    int a,b;
    
    scanf("%d %d",&a,&b);
    
    if (a > b)
        puts("a > b");
    if (a < b)
        puts("a < b");
    if (a == b)
        puts("a == b");
  
    return 0; 
}


Measured memory_bytes: 2044
# -*- coding: utf-8 -*-

n = int(input())
X = [int(i) for i in input().split()]

X.sort()
start = X[0]
finish = X[-1]

def find_sum(x, A):
    summ = 0
    for a in A:
        summ += (a-x)**2
    return summ

res_len = n*((finish-start)**2)
for j in range(start, finish+1):
    len0 = find_sum(j, X)
    if len0 < res_len:
        res_len = len0

print(res_len)

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

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

typedef long long ll;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//これを使うときにはCOMinit();を忘れずに

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    COMinit();
    int N, P; cin >> N >> P;
    int ev = 0, od = 0;
    ll ans = 1;
    rep(i, N){
        int a; cin >> a;
        if(a % 2) od++;
        else ev++;
    }
    if(P == 1 && od == 0) cout << 0 << endl;
    else{
        rep(i, ev) ans*=2;
        if(P == 1){
            ll acc = 0;
            for(int i = 1; i <= od; i+=2) acc += COM(od, i);
            ans *= acc;
        }
        else{
            ll acc = 0;
            for(int i = 0; i <= od; i+=2) acc += COM(od, i);
            ans *= acc;
        }
        cout << ans << endl;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int n; cin >> n;
    map<string,ll> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    ll ans = 0;
    for(auto i : mp){
        ll x = i.second;
        ans += x*(x - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <stdio.h>

#include <iostream>
using namespace std;

int max(int a, int b) {
    return a > b ? a : b;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int main(int argc, const char * argv[]) {
    int count = 0;
    char current, new1;
    cin >> current;
    while ((new1 = getchar()) != '\n') {
        if (new1 != current)
            count++;
        current = new1;
    }
    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	string s,t;
	cin >> s >> t;
	int cnt=0;
	for(int i=0;i<3;i++)
		if(s[i]==t[i])
			cnt++;

	cout << cnt << endl;




}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<bool> prime(100001, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i <= 100000; i++){
    if (prime[i]){
      for (int j = i * 2;  j <= 100000; j += i){
        prime[j] = false;
      }
    }
  }
  vector<int> S(100002, 0);
  for (int i = 0; i <= 100000; i++){
    if (i % 2 == 1 && prime[i] && prime[(i + 1) / 2]){
      S[i + 1] = S[i] + 1;
    } else {
      S[i + 1] = S[i];
    }
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++){
    int l, r;
    cin >> l >> r;
    r++;
    cout << S[r] - S[l] << endl;
  }
}

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

using namespace std;

#define ll long long int

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

ll gcd(ll x, ll y){
	if(x<y) swap(x,y);
	if(y==0) return x;
	return gcd(y,x%y);
}

ll lcm(ll x, ll y){
	return (x*y/gcd(x,y));
}

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	int n;
	cin >> n;
	int a[n];
	REP(i,n) cin >> a[i];
	int ans=0;
	REP(i,n-2){
		if(max({a[i],a[i+1],a[i+2]})!=a[i+1] && min({a[i],a[i+1],a[i+2]})!=a[i+1]){
			ans++;
		}
	}
	cout << ans << endl;
//////////////////////////////////////////////
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
int A, B;

int main() {
  cin >> A >> B;
  if (A <= 8 && B <= 8) {
    cout << "Yay!";
  } else {
    cout << ":(";
  }
}

Measured memory_bytes: 256