akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

const ll limit = 1e6+10;

ll arr[limit];

void sieve(){
	for(ll i = 1; i < limit; i++){
		if(arr[i] > 0){
			for(ll j = i + i; j < limit; j += i){
				arr[j] = 3;	
			}
		}
	}
}

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

	vector<ll> a(n);

	for(auto &x: a) 
	{
		cin >> x;
		arr[x]++;
	}
	sieve();
	ll cnt = 0;
	for(ll i = 0; i < n; i++){
		if(arr[a[i]] == 1){
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            string row = Console.ReadLine();
            string[] szArr = row.Split(' ');
            int a = int.Parse(szArr[0]);
            int b = int.Parse(szArr[1]);
            int c = int.Parse(szArr[2]);
            long x = int.Parse(szArr[3]);
            long y = int.Parse(szArr[4]);

            long minPrice = long.MaxValue;

            long maxZ = Math.Max(x, y)  *2;// 適当に大きう
            for( int z = 0; z <= maxZ; z+=2)
            {
                long price = c * z + a * Math.Max(0, (x - z / 2)) + b * Math.Max(0,(y - z / 2));
                if( price < minPrice)
                {
                    minPrice = price;
                }
            }

            Console.WriteLine(minPrice);
        }
    }
}


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

using namespace std;
/// <summary>
/// Computes lcs for strings a and b starting from position 0 up to (and including) position_in_a / b
/// Fills the provided dp_array
/// </summary>
int compute_lcs(vector<vector<int>>* dp_array, string* a, int position_in_a, string* b, int position_in_b)
{
	if (position_in_a == -1 || position_in_b == -1)
		return 0;
	
	if (dp_array->at(position_in_b)[position_in_a] != -1)
		return dp_array->at(position_in_b)[position_in_a];

	if (a->at(position_in_a) == b->at(position_in_b)) // The last two characters are equal
	{
		int lcs_length = compute_lcs(dp_array, a, position_in_a - 1, b, position_in_b - 1);
		// Because the last two characters are the same the lcs will include it
		dp_array->at(position_in_b)[position_in_a] = lcs_length + 1;
		return lcs_length + 1;
	}
	else
	{
		// Lcs will either end with the last character of a or will not, analogously for b
		// this allows to remove the other last character as it will not hurt the solution
		int lcs_len1 = compute_lcs(dp_array, a, position_in_a - 1, b, position_in_b);
		int lcs_len2 = compute_lcs(dp_array, a, position_in_a, b, position_in_b - 1);
		
		dp_array->at(position_in_b)[position_in_a] = max(lcs_len1, lcs_len2);
		return max(lcs_len1, lcs_len2);
	}
}

/// <summary>
/// Returns the lcs given a filled dp_array, for strings a and b starting from position 0 and continuing 
/// up to (and including) position_in_a / b
/// </summary>
string find_lcs(vector<vector<int>>* dp_array, string* a, int position_in_a, string* b, int position_in_b)
{
	if (position_in_a == -1 || position_in_b == -1)
		return "";
	
	if (a->at(position_in_a) == b->at(position_in_b))
	{
		string lcs = find_lcs(dp_array, a, position_in_a-1, b, position_in_b-1);
		return lcs + a->at(position_in_a);
	}
	else
	{
		int left_solution = -1;
		if (position_in_a > 0)
			left_solution = dp_array->at(position_in_b)[position_in_a - 1];

		int top_solution = -1;
		if (position_in_b > 0)
			top_solution = dp_array->at(position_in_b - 1)[position_in_a];

		if (left_solution > top_solution)
			return find_lcs(dp_array, a, position_in_a - 1, b, position_in_b);
		else
			return find_lcs(dp_array, a, position_in_a, b, position_in_b - 1);
	}
}

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

	vector<vector<int>> lcs_upto = vector<vector<int>>(b.size());
	for (int i = 0; i < b.size(); i++)
		lcs_upto[i] = vector<int>(a.size(), -1);

	compute_lcs(&lcs_upto, &a, a.size() - 1, &b, b.size() - 1);
	string lcs = find_lcs(&lcs_upto, &a, a.size() - 1, &b, b.size() - 1);

	cout << lcs;
	return 0;
}

Measured memory_bytes: 39336
#include<stdio.h>
#include<string.h>


int main(void) {
   char str[30];
   char year[11] = "2019/04/30";

   scanf("%s", str);
   if(strcmp(str, year) <= 0) {
      printf("%s\n", "Heisei");
   } else {
      printf("%s\n", "TBD");
   }


  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   return 0;
}


Measured memory_bytes: 128
import java.lang.Math.min

fun main(args: Array<String>) = p37()

fun p37() {
    val (need) = readLine()!!.split(' ').map { it.toInt() }
    val coins = readLine()!!.split(' ').map { it.toInt() }

    // [value] = minimum number of coins
    val dp = IntArray(need + 1) { Int.MAX_VALUE / 10 }
    dp[0] = 0

    for (coin in coins) {
        for (ni in 0..need - coin) {
            val pay = ni + coin
            dp[pay] = min(dp[pay], dp[ni] + 1)
        }
    }

    val answer = dp.last()

    println(answer)
}



Measured memory_bytes: 34296
#include "bits/stdc++.h"

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;


void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif

	int n, k;
	cin >> n >> k;
	set<char> s;
	rep(i, n) {
		char tmp;
		cin >> tmp;
		s.insert(tmp);
	}

	FOR(i, n, 100001) {
		string str = to_string(i);
		bool flag = true;
		for (auto x : s) {
			if (str.find(x) != string::npos) {
				flag = false;
				break;
			}
		}
		if (flag) {
			cout << i << endl;
			break;
		}
	}

}


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


	solve();
	system("PAUSE");
	return 0;
}

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

int main(){

  double r, p;

  cin >> r;
  p = 3.141592653589;
  cout << fixed << setprecision(6) << r*r*p <<" "<< fixed << setprecision(6) << (r+r)*p << endl;

  return 0;
}

Measured memory_bytes: 3276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef map<int, int> MI;
typedef set<int> SI;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl

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

string ban;

bool judge(int start, int end) {
    for(int i = start; i + 1 < end; i++){
        if(ban[i] == '#' && ban[i + 1] == '#') return false;
    }
    return true;
}

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

    int n, a, b, c, d; cin >> n >> a >> b >> c >> d;
    cin >> ban;
    ban = '#' + ban + '#';

    if(!judge(a, c) || !judge(b, d)) {
        cout << "No" << endl;
        return 0;
    }

    if(c > d) {
        int flg = 0;
        for(int i = b; i <= d; i++) {
            if(ban[i - 1] == '.' && ban[i] == '.' && ban[i + 1] == '.'){
                flg = 1;
            }
        }
        if(!flg) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 720
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NM = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, M) = (NM[0], NM[1]);
        var A = ReadLine().Split(' ').Select(s => int.Parse(s)).OrderByDescending(x => x).ToArray();

        var priorityQueue = new PriorityQueue<int>();

        foreach (var a in A)
            priorityQueue.Push(a);

        for (int i = 0; i < M; i++)
            priorityQueue.Push(priorityQueue.Pop() >> 1);

        var ans = priorityQueue.Sum(x => (long)x);

        WriteLine(ans);

    }
}
public class PriorityQueue<T> : IEnumerable<T>
    where T : IComparable<T>
{
    private List<T> buffer;
    public int Count { get => buffer.Count; }
    public bool IsDescending { get; }
    private int Compare(T a, T b) => IsDescending ? a.CompareTo(b) : b.CompareTo(a);

    public PriorityQueue(bool isDescending = true)
    {
        buffer = new List<T>();
        IsDescending = isDescending;
    }

    public void Push(T item)
    {
        buffer.Add(item);

        var root = 0;
        var child = buffer.Count - 1;

        while (root < child)
        {
            var parent = (child - 1) / 2;

            if (Compare(buffer[parent], buffer[child]) < 0)
                (buffer[parent], buffer[child]) = (buffer[child], buffer[parent]);

            child = parent;
        }
    }

    public T Pop()
    {
        var item = buffer[0];
        buffer[0] = buffer[^1];
        buffer.RemoveAt(buffer.Count - 1);

        var root = 0;
        var parent = root;
        var child = 1;

        while(child < buffer.Count)
        {
            if (child < buffer.Count - 1)
            {
                var leftChild = child;
                var rightChild = child + 1;

                if (Compare(buffer[leftChild], buffer[rightChild]) < 0)
                    child = rightChild;
            }

            if (Compare(buffer[parent], buffer[child]) < 0)
                (buffer[parent], buffer[child]) = (buffer[child], buffer[parent]);

            parent = child;
            child = 2 * parent + 1;
        }

        return item;
    }

    public IEnumerator<T> GetEnumerator()
    {
        return buffer.GetEnumerator();
    }

    IEnumerator IEnumerable.GetEnumerator()
    {
        return this.GetEnumerator();
    }
}


Measured memory_bytes: 40340
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define dl double
#define mod 1000000007
#define sz 205
#define szz 35

using namespace std;

int main()
{
    ll a,b;

    scanf("%lld %lld",&a,&b);

    ll c=a*b;

    if(c%2==0)
        printf("Even\n");

    else
        printf("Odd\n");

    return (0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const lint INF = 1LL << 60;
const int MAX = 1000000;

int n;
lint k;
vec a, f;

bool isOK(lint mid) {
    lint diff = 0;

    rep(i, n) {
        diff += max(0LL, a[i] - mid/f[i]);
    }

    return diff <= k;
}

lint binary_search() {
    lint left = -1;
    lint right = 1000000000010;

    while (right - left > 1) {
        auto mid = left + (right - left) / 2;

        if (isOK(mid)) right = mid;
        else left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

int main() {
    cin >> n >> k;
    a.resize(n);
    f.resize(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> f[i];

    sort(all(a));
    sort(all(f), greater<lint>());

    lint res = binary_search();

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <climits>

using namespace std;

int main(){
    long long a, b, x; cin >> a >> b >> x;
    cout << b/x-a/x+!bool(a%x) << endl;
    return 0;
}


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

int main(){
  string s;
  string t;
  
  cin>>s>>t;
  
  string s1=s;
  string t1=t;
  
  reverse(s.begin(),s.end());
  reverse(t.begin(),t.end());
  
  if(s1==t && t1==s){
    cout << "YES" << endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
#define REP(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for(ll (i)-1 = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for(ll (i) = (m); (i) < (n); (i)++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define _GLIBCXX_DEBUG

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<1000000007>;

const double PI = 3.14159265358979323846;

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

int main()
{
    ll n;
    cin >> n;
    vector<ll> t(n+1);
    vector<ll> x(n+1);
    vector<ll> y(n+1);
    bool ok = true;
    REP(i, n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }
    t[0] = 0;
    x[0] = 0;
    y[0] = 0;

    REP(i, n){
        ll dist = abs(x[i]-x[i+1]) + abs(y[i]-y[i+1]);
        if(dist > abs(t[i]-t[i+1])){
            ok = false;
            break;
        }
        else{
            if(dist % 2 == abs(t[i]-t[i+1]) % 2) continue;
            else{
                ok = false;
                break;
            }
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

// See debug.cc for usage etc
#define DEBUG 0

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#if DEBUG
  #define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
  #define DCALL(func, ...) func(__VA_ARGS__)
#else
  #define DLOG(...)
  #define DCALL(func, ...)
#endif

string S;

int main() {
#if !DEBUG
  ios_base::sync_with_stdio(false);
#endif

  cin >> S;
  ll cnt = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S.at(i) == 'x') cnt++;
  }
  cout << (cnt >= 8 ? "NO" : "YES") << endl;

  return 0;
}



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

int N;
long  a[100000];

long long gcd(long long  a, long long  b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b){
  return a*b / gcd(a,b);
}

void solve(){

  long long ans = 0;
  for(int i = 0; i <N; i++){
    ans += a[i]-1;
  }
  cout << ans << endl;
  return ;
}
int main(){
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }

  solve();
  return 0;
}


Measured memory_bytes: 256
'''
Created on 2020/08/28

@author: harurun
'''
def main():
  import math
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N,X=map(int,pin().split())
  x=list(map(int,pin().split()))
  m=abs(x[0]-X)
  for i in range(1,N):
    m=math.gcd(abs(x[i]-X),m)
  print(m)
  return
main()

Measured memory_bytes: 20256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int x = scan.nextInt();
		scan.close();
		
		long b = -1000;
		while(true) {
			long a = x + (long)Math.pow(b, 5);
			if(is5root(a)) {
				System.out.println((long)Math.pow(a, 0.2) + " " + b);
				return;
			}
			b++;
		}
		
	}
	
	public static boolean is5root(long a) {
		long b = (long)Math.pow(a,0.2);
		long c = (long)Math.pow(b, 5);
		return a == c;
	}

}


Measured memory_bytes: 38748
#include <stdio.h>

int main(void){
    int a,b;
    
    scanf( "%d %d",&a,&b );
    
    if( a + b < 10 ){
        printf("%d", a+b);
    }
    else if( a + b >= 10 ){
        printf("error");
    }

    
  return 0;
}

Measured memory_bytes: 128
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
a,b,q = gets.chomp.split.map(&:to_i)
s = [-INF]
t = [-INF]
a.times do
  s.push gets.chomp.to_i
end
s.push INF
b.times do
  t.push gets.chomp.to_i
end
t.push INF
q.times do
  x = gets.chomp.to_i

  si = s.bsearch_index{|z| z >= x}
  ti = t.bsearch_index{|z| z >= x}
  # p [s,t,si,ti]

  migi = s[si]-x
  migi = t[ti]-x if migi < t[ti]-x
  hidari = x-s[si-1]
  hidari = x-t[ti-1] if hidari < x-t[ti-1]
  lr = (x - t[ti-1]) * 2 + s[si] - x
  lr2 =(x - s[si-1]) * 2 + t[ti] - x
  rl = (t[ti] - x)   * 2 + x - s[si-1]
  rl2 =(s[si] - x)   * 2 + x - t[ti-1]

  ans = migi
  ans = hidari if ans > hidari
  ans = lr if ans > lr
  ans = lr2 if ans > lr2
  ans = rl if ans > rl
  ans = rl2 if ans > rl2

  puts ans
end


Measured memory_bytes: 6908
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
ll bit[100010], num;
ll par[100010], sz[100010];
ll n, a[200010], SUM[200010];
vector<ll> ans;

struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n;
	
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}

	for (ll i = n; i >= 1; i--)
	{
		if (SUM[i] != a[i])
		{
			ans.push_back(i);
			for (int j = 1; j <= sqrt(i); j++)
			{
				if (i % j == 0)
				{
					SUM[j] = (SUM[j] == 0 ? 1 : 0);
					if (i != j * j && j != 1)
					{
						SUM[i / j] = (SUM[i / j] == 0 ? 1 : 0);
					}
				}
			}
		}
	}

	cout << ans.size() << endl;

	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i];
		if (i == ans.size() - 1)
		{
			cout << endl;
		}
		else
		{
			cout << ' ';
		}
	}

	int www;
	cin >> www;
}


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

int main() {
  long long N,ans,c,d,e,f,g,h,p;
  cin >>N;
  p=0;
  ans=0;
  int a[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      a[i][j]=0;
    }
  }
for(int i=1;i<=N;i++){
  if(i<10){
    a[i][i]++;
    ans++;
    continue;
  }
  else{
  g=i;
  c=g%10;
    if(c==0){
      continue;
    }
  while(g>9){
    g/=10;
  }
    a[g][c]++;
    if(a[c][g]==0){
      continue;
    }
    if(g==c){
    ans+=a[c][g]*2-1;
      continue;
    }
    ans+=a[c][g]*2;
  }
}
  cout <<ans<< endl;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
res = 0
a = 0
b = 0
ba = 0
for s in S:
    if s[0] == "B" and s[-1] == "A":
        ba += 1
    elif s[0] == "B":
        b += 1
    elif s[-1] == "A":
        a += 1
    for i in range(len(s)-1):
        if s[i] == "A" and s[i+1] == "B":
            res += 1
if a == 0 and b == 0:
    res += max(ba - 1, 0)
elif a == N and b == N:
    res += N-1 + ba
else:
    res += min(a, b) + ba
print(res)


Measured memory_bytes: 47192
N = int(input())
li=[0]*5
for i in range(N):
    s = input().strip()
    if s[0]=='M':
        li[0]+=1
    if s[0]=='A':
        li[1]+=1
    if s[0]=='R':
        li[2]+=1
    if s[0]=='C':
        li[3]+=1
    if s[0]=='H':
        li[4]+=1
ans=0
for i in range(0,3):
    for j in range(i+1,4):
        for k in range(j+1,5):
            ans+=li[i]*li[j]*li[k]
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T>& a) {
  os << "{";
  for (size_t i = 0; i < a.size(); ++i) os << (i > 0 ? "," : "") << a[i];
  return os << "}";
}

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

ll dp[3003][3003][4];

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  vector<vector<ll>> mono(h, vector<ll>(w));
  rep(i, 0, k) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a, --b;
    mono[a][b] = c;
  }

  rep(i, 0, h) rep(j, 0, w) {
    rep(a, 0, 4) {
      // とる下、とる右、とらない下、とらないみふぃ
      if (a < 3)
        dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][a] + mono[i][j]);
      if (a < 3)
        dp[i][j + 1][a + 1] =
          max(dp[i][j + 1][a + 1], dp[i][j][a] + mono[i][j]);
      dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][a]);
      dp[i][j + 1][a] = max(dp[i][j + 1][a], dp[i][j][a]);
    }
  }

  ll ans = 0;
  rep(i, 0, 4) {
    ll tmp = dp[h - 1][w - 1][i];
    if (i < 3) tmp += mono[h - 1][w - 1];
    ans = max(ans, tmp);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 354888
#include<stdio.h>
#include<string.h>
using namespace std;
char srx[100001];
int main(){
    gets(srx);
    int i,zjq=0;
    for(i=1;i<strlen(srx);i++)
    if(srx[i]!=srx[i-1])
    zjq++;
    printf("%d\n",zjq);
    return 0;
}

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

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

using ll = long long;

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

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

int main() {
  int H,W,N;
  cin>>H>>W>>N;
  vector<int> place(2);
  cin>>place[0]>>place[1];
  string S,T;
  cin>>S>>T;
  reverse(S.begin(),S.end());
  reverse(T.begin(),T.end());
  int u=1,l=1, d=H, r=W;
  bool can = true;
  for(int i = 0; i < N; i++) {
    if(T[i]=='L') r=min(r+1,W);
    if(T[i]=='R') l=max(l-1,1);
    if(T[i]=='U') d=min(d+1,H);
    if(T[i]=='D') u=max(1,u-1);
    if(S[i]=='R') r--;
    if(S[i]=='L') l++;
    if(S[i]=='U') u++;
    if(S[i]=='D') d--;
    if(l>r||u>d) {
      can=false;
      break;
    }
  }
  if(can&&u<=place[0]&&d>=place[0]&&l<=place[1]&&r>=place[1]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int mod=1e9+7;
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[200010],finv[200010],inv[200010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,200010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    combinit();
    ll n;
    cin>>n;
    vector<ll>a(n+1);
    vector<ll>b(n+1);
    ll k=0;
    rep(i,n+1){
        cin>>a[i];
        b[a[i]]++;
        if(b[a[i]]==2)k=a[i];
    }
    ll cnt1=0,cnt2=0;
    rep(i,n+1){
        if(a[i]==k)break;
        cnt1++;
    }
    for(int i=n;i>=0;i--){
        if(a[i]==k)break;
        cnt2++;
    }
    //cout<<comb(4,1)<<endl;
    //cout<<k<<endl;
    //cout<<cnt1<<' '<<cnt2<<endl;
    //cout<<comb(0,1)<<endl;
    REP(i,1,n+1){
        ll ans=comb(n+1,i)-comb(cnt1+cnt2,i-1);
        //cout<<comb(n+1,i)<<' '<<comb(cnt1+cnt2,i-1)<<endl;
        ans%=inf;
        if(ans<0)ans+=inf;
        cout<<ans<<endl;
    }
    cout<<1<<endl;
}

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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

// repetition
// -----------------------------------------------------------------------------
#define FOR(i, a, b) for(int i= (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

// constant
// -----------------------------------------------------------------------------
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    string S; cin >> S;

    ll r = count(S.begin(), S.end(), 'R');
    ll g = count(S.begin(), S.end(), 'G');
    ll b = count(S.begin(), S.end(), 'B');
    ll ans = r * g * b; 

    FOR(j, 1, N) {
        FOR(i, 0, j) {
            int k = j * 2 - i;
            if (k < N) {
                ans -= S[i] != S[j] && S[j] != S[k] && S[k] != S[i];
            }
        }
    }

    cout << ans << "\n";
}

Measured memory_bytes: 3592
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<fstream>       //ファイルストリーム（標準入力変更用）
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

//名前
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef map<string, int> msi;
typedef map<string, ll> msll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pllll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;

//定数
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;

//マクロ
#define rep(i,n) for(int i=0;i<n;i++)
#define reps(i,s,e) for(int i=s;i<e;i++)
#define repse(i,s,e) for(int i=s;i<=e;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define in(x1) cin >> x1
#define in2(x1, x2) cin >> x1 >> x2
#define in3(x1, x2, x3) cin >> x1 >> x2 >> x3
#define inN(x, N) rep(i, N) in(x[i])
#define outl(x) cout << x << endl
#define out2l(x, y) cout << x << " " << y << endl 

//よく使う関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

    int N, M;
    ll K;
    in3(N, M, K);

    vll A(N);
    inN(A, N);

    vll B(M);
    inN(B, M);

    vll X(N + 1);
    rep(i, N) X[i + 1] = X[i] + A[i];

    vll Y(M + 1);
    rep(i, M) Y[i + 1] = Y[i] + B[i];

    int ans = 0;

    rep(i, N + 1)
    {
        int lb = -1;
        int ub = M + 1;

        while (ub > lb + 1)
        {
            int mid = (lb + ub) / 2;

            if (X[i] + Y[mid] <= K)
            {
                lb = mid;
            }
            else
            {
                ub = mid;
            }
        }

        if (lb >= 0 && lb <= M && X[i] + Y[lb] <= K) chmax(ans, i + lb);
    }

    outl(ans);

    return 0;
}

Measured memory_bytes: 9516
from numpy import*;B=searchsorted;a,b=loadtxt(open(0),'i',skiprows=1);c=0;l=2**29
while l:h=l;l//=2;y=sort(hstack((b%h-h,b%h)));c+=sum(B(y,h-a%h)-B(y,l-a%h))%2*l
print(c)

Measured memory_bytes: 63824
#include<iostream>
using namespace std;
int n,a;
char s[1000000];
int main()
{
	cin>>n;
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)
		if(s[i]=='R') a++;
	if(a*2>n) puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
//#define READ_NUMBER(i) scanf("%d",i)
 
int main(){
	string S;
	cin >> S;
    int fivth = S.at(5) - 48;
    int sixth = S.at(6) - 48;
	if(fivth == 1){
		cout << "TBD" << endl;
	}else if(sixth == 5 || sixth == 6 || sixth == 7 || sixth == 8 || sixth == 9){
		cout << "TBD" << endl;
	}else{
		cout << "Heisei" << endl;
	}
}

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def foo(i):
    if i<=p:
        return True
    if a[i]+m < a[p]:
        return False
    q = v-n+i-p
    #ddprint("foo {} call q {}".format(i,q))
    if q<=0:
        return (a[i]+m >= a[p])
    ret = (i-p)*(a[i]+m) >= acc[i-1]-acc[p-1]+m*q
    #ddprint("i {} p {} ai {} m {} ap {} acm {} acp {} q {}".format(i,p,a[i],m,a[p],acc[i-1],acc[p-1],q))
    #ddprint("foo {} returns {}".format(i,ret))
    return ret

n,m,v,p = inm()
a = inl()
a.sort(reverse=True)
a[0:0] = [0] # a1..an
acc = [0]*(n+1)
for i in range(1,n+1):
    acc[i] = acc[i-1]+a[i]
ddprint(a)
ddprint(acc)
mn = p
mx = n+1
while mx-mn>=2:
    #ddprint("loop mn {} mx {}".format(mn,mx))
    mid = (mn+mx)//2
    if foo(mid):
        mn = mid
    else:
        mx = mid
print(mn)


Measured memory_bytes: 62704
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a,b,c,i,ans=0;
    cin>>a>>b>>c;
    for(i=0;i<=b;i++){
        if(a*i%b==c){
            ans=1;
        }
    }
    cout<<(ans==1?"YES":"NO")<<endl;
    return 0;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 3030;

int n, a[N];
vi adj[N];

bool dfs(int u, int p = -1) {
    for (int v : adj[u]) if (v != p && a[v] < a[u] && !dfs(v,u))
        return true;
    return false;
}

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

    cin >> n;
    forn(i,n) cin >> a[i];
    forn(_,n-1) {
        int u,v; cin >> u >> v;
        u--; v--;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    vi ans;
    forn(i,n) if (dfs(i)) ans.pb(i);
    for (auto x : ans) cout << x+1 << ' ';

    return 0;
}


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

int main() {
  string s, t;
  cin >> s >> t;
  int count = 0;
  for (int i = 0; i < s.size(); i++){
    if(s.at(i) != t.at(i)){
      count++;
    }
  }
  cout << count << endl;
}




Measured memory_bytes: 3916
# -*- coding: utf-8 -*-
import math
S = input()[::-1]
remainder = [0] * 2019

# 2つ選ぶ組み合わせにおいて余り0の場合は1つしか選ばなくて良いので
# 2つ目に0を選んだ場合として便宜的に設定
remainder[0] = 1

num = 0
d = 1
for s in S:
  num += int(s) * d
  remainder[num % 2019] += 1
  d *= 10
  
  # numが大きくなりすぎると計算量が膨大になってしまうのを防ぐ
  # num%2019を計算するので、先に%2019で計算しても結果は変わらない
  d %= 2019
ans = 0
for i in range(2019):
  ans += remainder[i] * (remainder[i]-1) // 2
print(ans)

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

int main(void) {
    int A,B;cin>>A>>B;
    int C1 = A + B;
    int C2 = A - B;
    int C3 = A * B;
    int ma = C1;
    ma = (ma < C2) ? C2 : ma;
    ma = (ma < C3) ? C3 : ma;
    cout << ma << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dump(x) cerr << #x << "=" << (x) << endl;
using namespace std;
const int INF = (int)2e9 + 1;
const long long LINF = (long long)9e18 + 1;

char char_plus_N(int N, char c) {
  int diff = c - 'A' + N;
  while (diff > 25) {
    diff -= 26;
  }
  return 'A' + diff;
}

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

  int N;
  string S, ans[10005];
  cin >> N >> S;

  for (int i = 0; i < (int)S.size(); i++) {
    S[i] = char_plus_N(N, S[i]);
  }

  cout << S << endl;

  return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>

using namespace std;

const long long mod = 1e9 + 7;

int main()
{
	long long ans = 1;
	long long N, K; cin >> N >> K;

	for (int i = N; i >= K; --i)
	{
		ans += (1 + (N + 1 - i) * i) % mod;
		ans %= mod;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3636
S=input()
S_odd=S[1::2]
S_even=S[0::2]
ans="Yes"
for s in S_odd:
  if s=="L" or s=="U" or s=="D":
    pass
  else:
    ans="No"
    break
for s in S_even:
  if s=="R" or s=="U" or s=="D":
    pass
  else:
    ans="No"
    break
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

typedef struct {
	int t, h;
} edge;

typedef struct List {
	struct List *next;
	edge *e;
} list;

typedef struct {
	edge *e;
	list **inc;
} graph;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

int main()
{
	int i, N, P[5001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(P[i]));
	
	graph G;
	list *data = (list*)malloc(sizeof(list) * N * 2);
	G.e = (edge*)malloc(sizeof(edge) * N);
	G.inc = (list**)malloc(sizeof(list*) * (N + 1));
	for (i = 0; i < N; i++) {
		if (P[i+1] == -1) continue;
		G.e[i].t = P[i+1];
		G.e[i].h = i + 1;
		data[i*2].e = &(G.e[i]);
		data[i*2+1].e = &(G.e[i]);
		data[i*2].next = G.inc[G.e[i].t];
		data[i*2+1].next = G.inc[G.e[i].h];
		G.inc[G.e[i].t] = &(data[i*2]);
		G.inc[G.e[i].h] = &(data[i*2+1]);
	}
	
	list *p;
	int j, k, K, v, comp[5001] = {}, q[5001], head, tail, size[5001] = {};
	for (i = 1, k = 1; i <= N; i++) {
		if (P[i] != -1) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = G.inc[q[head]]; p != NULL; p = p->next) {
				v = p->e->h;
				if (comp[v] == 0) {
					comp[v] = k;
					q[tail++] = v;
				}
			}
		}
		size[k++] = tail;
	}
	for (i = 1, K = k - 1; i <= N; i++) {
		if (comp[i] != 0) continue;
		comp[i] = k;
		q[0] = i;
		for (head = 0, tail = 1; head < tail; head++) {
			for (p = G.inc[q[head]]; p != NULL; p = p->next) {
				v = (p->e->t == q[head])? p->e->h: p->e->t;
				if (comp[v] == 0) {
					comp[v] = k;
					q[tail++] = v;
				}
			}
		}
		k++;
	}
	
	long long ans = N - k + 1 + K, sym[5001] = {1}, pow[5001][5001] = {}, N_pow[5001] = {1}, tmp;
	for (i = 1; i <= K; i++) {
		ans = ans * (N - 1) % 1000000007;
		N_pow[i] = N_pow[i-1] * (N - 1) % 1000000007;
		sym[1] += size[i];
		for (j = 2, pow[i][1] = size[i]; j <= K; j++) pow[i][j] = pow[i][j-1] * size[i] % 1000000007;
	}
	ans = ((ans + 1000000007) - ((sym[1] - K) * N_pow[K-1] % 1000000007)) % 1000000007;
	pow[0][0] = 1;
	for (i = 1; i <= K; i++) {
		for (j = 1; j <= K; j++) pow[0][i] = (pow[0][i] + pow[j][i]) % 1000000007;
	}
	for (i = 2, tmp = 1; i <= K; i++, tmp = tmp * (i - 1) % 1000000007) {
		sym[i] = sym[i-1] * pow[0][1];
		for (j = 2; j <= i; j++) {
			if (j % 2 == 1) sym[i] = (sym[i] + sym[i-j] * pow[0][j]) % 1000000007;
			else sym[i] = (sym[i] + 1000000007 - (sym[i-j] * pow[0][j]) % 1000000007) % 1000000007;
		}
		sym[i] = div_mod(sym[i], i, 1000000007);
		ans = ((ans + 1000000007) - ((sym[i] * tmp % 1000000007) * N_pow[K-i] % 1000000007)) % 1000000007;
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

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

int main(){
    int n, k, anw = 0, num;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> num;
        if(num >= k){anw++;}
    }
    cout << anw;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stack>
#include<string>
using namespace std;

int main() {
    string s;
    cin >> s;
    int ans = 0;
    stack<char> S;
    for (int i = 0; i < s.length(); i++) {
        if (S.empty()) S.push(s[i]);
        else {
            if ((S.top() == '0' && s[i] == '1') || (S.top() == '1' && s[i] == '0')) {
                ans += 2;
                S.pop();
            }
            else S.push(s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
// Author : Sarthak Kapoor
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define rep(i,n) for(int i=0;i<n;++i)
#define repa(i,a,n) for(int i=a;i<n;++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define repba(i,b,a) for(int i=b;i>=a;--i)
#define repab(i,a,b) for(int i=a;i<b;++i)
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define msi map<string,int>
#define mii map<int,int>
#define viip vector<pair<int,pair<int,int> > > 
#define mp make_pair
#define vip vector<pair<int,int> >
#define pb push_back 
#define po pop_back
#define fi first
#define sec second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define s(v) v.size()
ll mod = 1000000007;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());//use rng()%n for numbers in range [0,n-1]
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
vi v[401];
bool vis[401];
int dis[401];
void bfs(int u){
	vis[u] = 1;
	queue<int> q;
	q.push(u);
	dis[u] = 0;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		for(auto y:v[x]){
			if(!vis[y]){
				dis[y] = dis[x] + 1; 
				vis[y] = true;
				q.push(y);
			}
		}
	}
	// for(auto x:v[u]){
	// 	if(!vis[x]){dis[x] = dis[u]+1;dfs(x);}
	// }
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int h,w;
	cin>>h>>w;
	string s[h];
	rep(i,h){
		cin>>s[i];
	}	
	rep(i,h){
		rep(j,w){
			if(s[i][j] == '.'){
				if(j+1 < w && s[i][j+1] != '#'){v[i*w+j].pb(i*w+j+1);v[i*w+j+1].pb(i*w+j);}
				if(i+1 < h && s[i+1][j] != '#'){v[i*w+j].pb((i+1)*w+j);v[(i+1)*w+j].pb(i*w+j);}
			}
		}
	}
	// rep(i,h*w){
	// 	cout<<i<<" ";
	// 	for(auto x:v[i]){
	// 		cout<<x<<" ";
	// 	}
	// 	cout<<"\n";
	// }
	int max1 = 0;
	rep(i,h*w){
		// dis[]
		bfs(i);
		rep(j,h*w){
			// if(i == 0)cout<<max1<<"\n";
			max1 = max(max1,dis[j]);
		}
		// if(/)
		// cout<<max1<<"\n";
		rep(j,h*w){
			dis[j] = 0;
			vis[j] = 0;
		}
	}
	cout<<max1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    int K = 0;
    string S;
    cin >> K >> S;
    int N = S.length();
    if (N > K) {
        string str = S.substr(0, K) + "...";
        cout << str << endl;
    }
    else cout << S << endl;
}


Measured memory_bytes: 3644
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
    int X[100],Y[100],n;
    double sum[4];
    cin >> n;
    for(int i=0;i<n;i++) cin >> X[i];
    for(int i=0;i<n;i++) cin >> Y[i];
    for(int i=0;i<4;i++) sum[i] = 0.0;
    for(int i=1;i<=3;i++){
        for(int j=0;j<n;j++){
            sum[i] += pow(fabs(X[j]-Y[j]),i);
        }
        sum[i] = pow(sum[i],1.0/i);
    }
    for(int i=0;i<n;i++){
        sum[0] = max(sum[0],fabs(X[i]-Y[i]));
    }
    printf("%f\n%f\n%f\n%f\n",sum[1],sum[2],sum[3],sum[0]);
    return 0;
}


Measured memory_bytes: 3340
//8色以外も自由に取れるのね
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n;
int a[100];
bool used[8]; int usedNum = 0;

signed main() {
	int i;
	
	cin >> n;
	for (i = 0; i < n; i++) cin >> a[i];
	
	int jiyuu = 0;
	for (i = 0; i < n; i++) {
		if (a[i] >= 3200) {
			jiyuu++;
		}
		else if (!used[a[i] / 400]) {
			used[a[i] / 400] = true;
			usedNum++;
		}
	}
	
	if (usedNum == 0) {
		cout << 1 << " " << jiyuu << endl;
		return 0;
	}
	
	cout << usedNum << " " << usedNum + jiyuu << endl;
	return 0;
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

int main() {
	fastio();
	
	LL n, d;
	cin >> n >> d;
	LL c = 0;
	while (n--) {
		LL x, y;
		cin >> x >> y;

		if (x*x + y*y <= d*d) {
			c++;
		}
	}
	cout << c << "\n";

}

Measured memory_bytes: 3652
from sys import exit
from math import gcd
n, m  = map(int, input().split())
A = list(map(int, input().split()))
Count = [0] * n

div_A = [a // 2 for a in A]

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

for i, a in enumerate(div_A):
    while a % 2 == 0:
        Count[i] += 1
        a //= 2
if len(set(Count)) != 1:
    print(0)
    exit()

lcm_num = 1
for div_a in div_A:
    lcm_num = lcm(div_a, lcm_num)
    if lcm_num > m:
        print(0)
        exit()
else:
    print((m + lcm_num) // (2 * lcm_num))



Measured memory_bytes: 91740
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char s;
  string num;
  int N;
  cin >> N;
  num = "Three";
  for(int i = 0;i<N; i++){
    cin >> s;
    if (s == 'Y'){
      num = "Four";
      break;
    }
  }
  cout << num << endl;
}

Measured memory_bytes: 256
def retry(sen):
    sen=sen.replace('apple','-----')
    sen=sen.replace('peach','apple')
    print(sen.replace('-----','peach'))

sen_2=input()
#sen=list(map(str,input().split()))
#for i in range(len(sen)):
#    if i<len(sen)-1:
#        if sen[i]=='apple' or sen[i]=='peach':
#            if sen[i]=='peach':
#                print('apple',end=" ")
#            else:
#                print('peach',end=" ")
#        else:
#            print(sen[i],end=" ")
#    else:
#        if sen[i]=='apple.' or sen[i]=='peach.':
#            if sen[i]=='peach.':
#                print('apple.')
#            else:
#                print('peach.')
#        else:
#            print(sen[i])
    
retry(sen_2)



Measured memory_bytes: 5556
#include<cstdio>

int main(){
	int n,k;
	int cnt[1000];
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++) cnt[i] = 0;
	for(int i=0;i<k;i++){
		int p;
		scanf("%d",&p);
		for(int j=0;j<p;j++){
			int q;
			scanf("%d",&q);
			cnt[q-1]++;
		}
	}
	int ans = 0;
	for(int i=0;i<n;i++){
		if(cnt[i]==0){
			ans++;
		}
	}
	printf("%d\n",ans);
}


Measured memory_bytes: 1740
#include <stdio.h>

    int main()      /*this code is written by 190042146*/
{
    long long int n ,k, tally=0;
    scanf("%lld%lld", &n, &k);

    if (k>n)
    {
        printf("1");
    }

    else
    {
        for (;k<=n+1;k++)
        {
            tally=tally+ k*n-(k-1)*k+1;
        }

        printf("%d",tally%(1000000000+7));
    }

    return 0;
}






Measured memory_bytes: 1732
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=LLIN(N)
    AB.sort(key=lambda x: x[1])

    now = 0    
    for a,b in AB:
        now += a
        if now > b:
            print("No")
            return
    print("Yes")
if __name__ == '__main__':
    main()

Measured memory_bytes: 109272
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i,j;
    int n;
    char a[8],b[4];

    scanf("%s %s", a, b);

    n = atoi(strcat(a,b));
    for(i=0;i<1000;i++){
        if(i*i == n){
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    
    return 0;
}

Measured memory_bytes: 128