akhauriyash/Code-Regression huggingface dataset:
require 'set'

def main
  n = gets.to_i
  s = gets.chomp

  ansset = Set.new
  (0..9).each do |a|
    s_a = a.to_s
    idx_a = s.index(s_a)
    next if idx_a.nil?
    (0..9).each do |b|
      s_b = b.to_s
      idx_b = s.index(s_b,idx_a+1)
      next if idx_b.nil?
      (0..9).each do |c|
        s_c = c.to_s
        idx_c = s.index(s_c,idx_b+1)
        ansset.add(s_a+s_b+s_c) unless idx_c.nil?
      end
    end
  end
  puts ansset.size
end

main



Measured memory_bytes: 14660
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll h=0,w=0,c=0,d=0,n,m,k,ans=0,y;
    string s,s2;
    cin >> n;
    Vl a(n);
    rep(i,n)cin >> a[i];
    sort(ALL(a));
    cout << a[n-1]-a[0] <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() 
{
	int n,a,b;
  	cin >> n;
  	a = n / 100;//(kami2)
  	b = n % 100;//(simo2)
	
	if(0<a && a<=12){
		if(0<b && b<=12){
			cout << "AMBIGUOUS" << endl;
		}
		else{
			cout << "MMYY" << endl;
		}
	}
	else if(0<b && b<=12){
		cout << "YYMM" << endl;
	}
	else{
		cout << "NA" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct Edge{
  int to;
  int id;
};
vector<vector<Edge>>G;
vector<int>color;
void dfs(int v,int p=-1,int parent_color=-1){
  int k=1;
  for(auto nextv:G[v]){
    if(nextv.to==p)continue;
    if(color[nextv.id]!=-1)continue;
    if(parent_color==k)k++;
    color[nextv.id]=k;
    //cout<<"nextv"<<nextv.to<<endl;
    //cout<<"parent_coor"<<parent_color<<endl;
    k++;
    dfs(nextv.to,v,color[nextv.id]);
  }
}
int main(){
  int N;
  cin>>N;
  G.resize(N);
  color=vector<int>(N-1,-1);
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    a--,b--;
    G[a].push_back(Edge{b,i});
    G[b].push_back(Edge{a,i});
  }
  dfs(0);
  int max_degree=0;
  for(int i=0;i<N;i++){
    max_degree=max(max_degree,(int)G[i].size());
  }
  cout<<max_degree<<endl;
  for(int i=0;i<N-1;i++){
    cout<<color[i]<<endl;
  }
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
typedef int in;
#define int long long
using namespace std;

int solve(vector<int>arr){
	vector<int>dp;
	int n = arr.size();
	dp.resize(n);
	dp[0] = 0;
	if (n >= 2) {
		dp[1] = abs(arr[1] - arr[0]);
	}
	if (n >= 3) {
		dp[2] = abs(arr[2] - arr[0]);
	}

	for (int i = 3; i < n; i++) {
		dp[i] = min(dp[i - 2] + abs(arr[i] - arr[i - 2]), dp[i - 1] + abs(arr[i] - arr[i - 1]));
	}

	return dp[n - 1];

}

in main() {

	// cout << "hoho";
	int n;
	cin >> n;
	vector<int>arr;
	arr.resize(n);
	vector<int>dp;
	dp.resize(n);
	for (int i = 0; i < n; i++)
		dp[i] = -1;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
	}

	cout << solve(arr);

}



Measured memory_bytes: 6272
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

std::vector<LL>divisor(LL num)
{
	std::vector<LL>res;
	for (LL i = 1; i*i <= num; ++i)
	{
		if (num % i == 0)
		{
			res.push_back(i);
			if ((num / i) != i)
			{
				res.push_back(num / i);
			}
		}
	}
	return res;
}

int main()
{
	LL N;
	in >> N;
	std::vector<LL>t(N);
	rep(i, N) in >> t[i];

	std::sort(t.begin(), t.end());
	auto divs = divisor(t[N - 1]);
	std::sort(divs.begin(), divs.end());

	LL ans = 0;
	rep(i, N)
	{
		auto it = std::lower_bound(divs.begin(), divs.end(), t[i]);
		ans += *it - t[i];
	}

	out << ans << std::endl;
	return 0;
}



Measured memory_bytes: 3552
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    n, k = map(int, input().split())
    d = set(map(int, input().split()))
    safe = set(range(10)) - d

    def test(n):
        return set(int(x) for x in str(n)) <= safe

    def f(n):
        while n % 10:
            if test(n):
                return n
            n += 1
        x = f(n//10)
        y = min(safe)
        return 10 * x + y

    ans = f(n)
    print(ans)


   


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  Tmp(int N);
};

Tmp::Tmp(int N){}

void solve(void)
{
  int K; cin >> K;
  constexpr int A[] = {
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  cout << A[K-1] << CRLF;
  return;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <set>
//#include
#include <numeric>
#define pb push_back
#include <queue>
#include <stack>
#include <iomanip>
#include <map>
#include <iterator>
#include <unordered_set>
#include <climits>
#include <math.h>


using namespace std;


int main()
{
    double t; cin >> t;
    cout << 2*M_PI*t;
//    while(t--){
//        solve();
//    }

    return 0;
}



Measured memory_bytes: 3784
using System;

namespace PrintaChessboard
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			while (true)
			{
				string[] data = Console.ReadLine().Split(' ');
				int H = int.Parse(data[0]);
				int W = int.Parse(data[1]);
				if (H == 0 && W == 0)
				{
					return;
				}

				string line = "";
				string line2 = "";
				for (int i = 0; i < W; i++)
				{
					if (i % 2 == 0)
					{
						line = line + ".";
						line2 = line2 + "#";
					}
					else
					{
						line = line + "#";
						line2 = line2 + ".";
					}
				}

				for (int i = 0; i < H; i++)
				{
					if (i % 2 == 0)
					{
						Console.WriteLine(line2);
					}
					else
					{
						Console.WriteLine(line);
					}
				}
				Console.WriteLine();
			}
		}
	}
}

Measured memory_bytes: 5312
#include <iostream>

 
int gcd(int a, int b){
   if(a<b) return gcd(b,a);
   int r;
   while(r=a%b){
      a = b;
      b = r;
   }
   return b;
}

int gcd(int a, int b, int c){
   return gcd(gcd(a, b), c);
}

int main(){
   int K;
   std::cin >> K;

   int sum = 0;
   for(int i=1; i<=K; ++i){
      for(int j=1; j<=K; ++j){
	 for(int k=1; k<=K; ++k){
	    sum += gcd(i,j,k);
	 }
      }
   }
   std::cout << sum << std::endl;
   return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <cstring>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <math.h>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int ans=1;
    for(int i=0; i<n; i++){
        ans=min(ans*2, ans+k);
    }
    cout << ans;
    
    return 0;
}

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

struct union_find {
	int n;
	vector<int> tree;
	
	union_find(int n) : n(n), tree(n, -1) {
		
	}
	
	int size(int x) {
		assert(0 <= x && x < n);
		return -tree[root(x)];
	}
	
	int root(int x) {
		assert(0 <= x && x < n);
		if (tree[x] < 0) {
			return x;
		}
		return tree[x] = root(tree[x]);
	}
	
	bool same(int x, int y) {
		assert(0 <= x && x < n && 0 <= y && y < n);
		return root(x) == root(y);
	}
	
	bool merge(int x, int y) {
		assert(0 <= x && x < n && 0 <= y && y < n);
		x = root(x);
		y = root(y);
		if (x == y) {
			return false;
		}
		if (tree[x] > tree[y]) {
			swap(x, y);
		}
		tree[x] += tree[y];
		tree[y] = x;
		return true;
	}
};

int main() {
	int64_t n, m;
	cin >> n >> m;
	if (n - 1 <= m) {
		cout << 0 << endl;
		return 0;
	} else if (n < 2 * (n - m - 1)) {
		cout << "Impossible" << endl;
		return 0;
	}
	vector<int64_t> a(n);
	for (auto &i : a) {
		cin >> i;
	}
	union_find uf(n);
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		uf.merge(x, y);
	}
	map<int, priority_queue<int64_t, vector<int64_t>, greater<>>> map;
	for (int i = 0; i < n; i++) {
		map[uf.root(i)].emplace(a[i]);
	}
	priority_queue<int64_t, vector<int64_t>, greater<>> pq;
	int64_t ans = 0;
	for (auto &p : map) {
		auto &q = p.second;
		ans += q.top();
		q.pop();
		while (!q.empty()) {
			pq.emplace(q.top());
			q.pop();
		}
	}
	for (int i = 0; i < 2 * (n - m - 1) - map.size(); i++) {
		assert(!pq.empty());
		ans += pq.top();
		pq.pop();
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7936
import sys
n = int(input())
a = list(map(int, input().split()))
b = []
count = 0
for i in range (len(a)):
    if (a[i] < 3200):
        b.append(a[i]//400)
    else:
        count += 1
if (len(b)==0):
    print(*[1,count])
    sys.exit()
b_set = set(b)
ans = [len(b_set),len(b_set)+count]
print(*ans)

Measured memory_bytes: 3064
using System;

namespace AtcoderABC044A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = int.Parse(Console.ReadLine());
            d = int.Parse(Console.ReadLine());
            if (a > b)
            {
                Console.WriteLine(c * b + d * (a - b));
            }
            else if(a <= b)
            {
                Console.WriteLine(a * c);
            }
            
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;int tc = 1;
#define happy ios::sync_with_stdio(false);
#define coding  cin.tie(0);
#define mp make_pair
#define ll long long
#define Pi atan(1)*4
#define pb  push_back
#define vpr vector<pr> 
#define pr pair<int, int> 
#define vi std::vector<int>
#define vll std::vector<ll>
#define YES printf("YES\n");
#define NO printf("NO\n");
#define Yes printf("Yes\n");
#define No printf("No\n");
#define all(n) n.begin(),n.end()
#define point(x) setprecision(x)
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())

const int M = 1e9 + 7;
const ll  Inf = (ll)2e18 + 5;
const int N   = 2e5 + 5;

int solve() 
{
	//happy coding
	int n;
	cin>>n;
	map<string,int>m;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		m[s]++;
	}
	cout<<m.size()<<endl;
	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 19100
<?php
$n=trim(fgets(STDIN));
$i=0;
$a=(int)1;
$b=(int)1;
$c=(int)1;
$mod=(int)pow(10,9)+7;
while($i<$n){
  $a=($a*10)%$mod;
  $b=($b*8)%$mod;
  $c=($c*9)%$mod;
  ++$i;
}
$ans=$a+$b-2*$c;
while($ans<0){
  $ans+=$mod;
}
echo $ans;

Measured memory_bytes: 16268
#include<iostream>
using namespace std;
int main(){
    int n,m,b,d;
long long c;
    bool a=false;
    cin>>n>>m>>b;c=b;
    for(int i=0;i<150000000;i++){
        if(c%(n+m)<=n && a==false){
            a=true;
            d=i;
        }
        c+=60;
    }
    if(a==false){
        cout<<"-1"<<endl;
    }
    else{
        c=b+d*60;
        cout<<c<<endl;
    }
    return 0;
} 

Measured memory_bytes: 3084
from itertools import product

N=int(input())
S=list(input())
t=["0","1","2","3","4","5","6","7","8","9"]

u=product(t,repeat=3)
ans=0
for com in u:
  x=com[0]
  y=com[1]
  z=com[2]
  
  if x in set(S):
    idx_x = S.index(x)
    tmp1 = S[idx_x+1:]
    if y in set(tmp1):
      idx_y = tmp1.index(y)
      tmp2 = tmp1[idx_y+1:]
      if z in set(tmp2):
        ans+=1
        continue
        
print(ans)

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

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        int k = 0;
        int count = 1;
        boolean fin = false;
        for(int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(br.readLine());
        }
        for(int i = 0; i < n; i++) {
            if(a[k] != 2 && !fin) {
                count++;
                k = a[k] - 1;
            } else {
                fin = true;
            }
        }
        if(fin) {
            System.out.println(count);
        } else {
            System.out.println("-1");
        }
    }
}

Measured memory_bytes: 32456
/*
  AOJ 0104
  Title:Magical tiles
  @kankichi573
*/
#include <stdio.h>

char board[101][101];

int W,H;

int solve(int *x,int *y)
{
  int x0,y0;
  char c;
  x0=y0=0;
  while((c=board[y0][x0])!='.')
    {
      if(c=='x')
	return(-1);
      board[y0][x0]='x';
      if(c=='v')
	y0++;
      else if(c=='^')
	y0--;
      else if(c=='>')
	x0++;
      else if(c=='<')
	x0--;
    }
  *x=x0;
  *y=y0;
  return(0);
}
main()
{
  int i,x,y,ret;
  while(scanf("%d %d",&H,&W) && (W||H))
    {
      for(i=0;i<H;i++)
	scanf("%s",&board[i][0]);
      ret=solve(&x,&y);
      if(ret==-1)
	printf("LOOP\n");
      else
	printf("%d %d\n",x,y);
    }
  return(0);
}

Measured memory_bytes: 624
from collections import Counter
from itertools import combinations

N = int(input())
sticks = [int(i) for i in input().split()]
c = Counter(sticks)
length_pattern = c.keys()
length_combinations = combinations(length_pattern, 3)

cnt = 0
for comb in length_combinations:
    if comb[0] < comb[1] + comb[2] and comb[1] < comb[2] + comb[0] and comb[2] < comb[0] + comb[1]:
        cnt += c[comb[0]] * c[comb[1]] * c[comb[2]]
    
print(cnt)

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

using namespace std;

struct Qt {
        int v, d, c;
        Qt( ) { }
        Qt( int _v, int _d, int _c ) {
                v = _v, d = _d, c = _c;
        }
};

int ans[ 100005 ];
int dp[ 100005 ][ 12 ];
vector< int > G[ 100005 ];

void color( int u, int d, int c ) {

        if( !ans[ u ] )
                ans[ u ] = c;

        if( d == 0 ) return ;
        if( dp[ u ][ d ] != -1 ) return;

        dp[ u ][ d ] = 1;

        for( auto v : G[ u ] ) {
                if( dp[ v ][ d - 1 ] == -1 ) {
                        color( v, d - 1, c );
                }
        }
}

int main( ) {

        int n, m; cin >> n >> m;

        for( int i = 0; i < m; i ++ ) {
                int x, y; cin >> x >> y;
                G[ x ].push_back( y );
                G[ y ].push_back( x );
        }

        int q; cin >> q;

        memset( dp, -1, sizeof dp );

        vector< Qt > vv;

        for( int i = 0; i < q; i ++ ) {
                int v, d, c;
                cin >> v >> d >> c;
                vv.push_back( Qt( v, d, c ) );
        }

        reverse( vv.begin( ), vv.end( ) );

        for( auto x : vv )
                color( x.v, x.d, x.c );

        for( int i = 1; i <= n; i ++ )
                cout << ans[ i ] << "\n";

        return 0;
}


Measured memory_bytes: 13168
n = int(raw_input())
a = [0 for i in xrange(n)]
adj = [[0 for i in xrange(n)] for j in xrange(n)]
for i in xrange(n):
	a[i] = map(int,raw_input().split())
for i in xrange(n):
	for j in xrange(2, a[i][1]*2+1, 2):
		adj[a[i][0]][a[a[i][0]][j]] = a[a[i][0]][j+1]
MAX = 100000000
end = [1] * n
cost = [MAX] * n
cost[0] = 0
prev = [0] * n
start = 0
while 1:
	min = MAX
	next = -1
	end[start] = 0
	for i in xrange(n):
		if end[i]:
			if adj[start][i]:
				d = cost[start] + adj[start][i]
				if d < cost[i]:
					cost[i] = d
			if min > cost[i]:
				min = cost[i]
				next = i
	start = next
	if next < 0:
		break
for i in xrange(n):
	print i, cost[i]

Measured memory_bytes: 6696
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  long long  N, A, B;
  long long  ans = 0;
  string s;

  cin >> N >> A >> B;

  long long abn = N/(A + B);

//  cout << abn << endl;
  ans += A * abn;
  long long tmp = N - abn * (A+B);
  if(tmp < A){
    ans += tmp;
  }else{
    ans += A;
  }
  cout << ans << endl;
}


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

MAX = 55555


def create_prime_list(n):
    if n < 2:
        return []
    prime_list = [2]
    x = 3
    while x <= n:
        flag = False
        for p in prime_list:
            if x < p ** 2:
                flag = True
                break
            if x % p == 0:
                break
        if flag:
            prime_list.append(x)
        x += 2
    return prime_list


def main():
    prime_list = create_prime_list(MAX)
    w = [x for x in prime_list if x % 5 == 1]
    print(*w[:N])
    

if __name__ == "__main__":
    main()


Measured memory_bytes: 9160
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN = 300;

int n;
char s[MAXN][MAXN + 1];

void run() {
	scanf("%d", &n); REP(x, n) scanf("%s", s[x]);

	// t[i][j]=t[j][i] -> s[i-A][j-B]=s[j-A][i-B]
	// let delta=B-A, then s[i][j-delta]=s[j][i-delta]
	int ret = 0;
	REP(delta, n) {
		bool ok = true; REP(i, n) REP(j, n) if (s[i][(j - delta + n) % n] != s[j][(i - delta + n) % n]) ok = false;
		if (ok) ret += n;
	}
	printf("%d\n", ret);
}

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


Measured memory_bytes: 384
A, B, C, D = gets.chomp.split.map(&:to_i)
c = B / C - (A - 1) / C
d = B / D - (A - 1) / D
cd = B / C.lcm(D) - (A - 1) / C.lcm(D)
puts (A..B).size - (c + d - cd)


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

int main() {
	ll N;
	cin >> N;
	cout << (N - 1) / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#define pb push_back
#define INF 1000000000

using namespace std;
int main(){
	int n,r;
	while(cin>>n>>r,n||r){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			v[i]=n-i;
		}
		
		int p,c;
		for(int i=0;i<r;i++){
			cin>>p>>c;
			vector<int> x;
			for(int j=0;j<p-1;j++){
				x.pb(v[j]);
			}
			vector<int> y;
			for(int j=p-1;j<c+p-1;j++){
				y.pb(v[j]);
			}
			for(int j=0;j<c;j++){
				v[j]=y[j];
			}
			for(int j=c;j<c+p-1;j++){
				v[j]=x[j-c];
			}
		}
		cout<<v[0]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
def solve():
    N = int(input())
    d = [[float('inf')]*N for _ in range(N)]
    A = [list(map(int, input().split())) for _ in range(N)]
    for i in range(N):
        for j in range(N):
            d[i][j] = A[i][j]

    #三重ループ
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])

    for i in range(N):
        for j in range(N):
            if d[i][j] < A[i][j]:
                return -1
    ans = 0
    for i in range(N):
        for j in range(i+1,N):
            ans += A[i][j]
            for k in range(N):
                if k!= i and k!=j and A[i][j]==A[i][k]+A[k][j]:
                    ans -= A[i][j]
                    break
    return ans
print(solve())
    

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

int cul( int n1, int n2, string ss ) {
	int ret;
	if ( ss == "+" ) ret = n1 + n2;
	if ( ss == "-" ) ret = n1 - n2;
	if ( ss == "*" ) ret = n1 * n2;
	return ret;
}

int main() {
	stack<int> s;
	string st;
	int m1, m2;
	while ( cin >> st ) {
		if ( st == "+" || st == "-" || st == "*" ) {
			m2 = s.top();
			s.pop();
			m1 = s.top();
			s.pop();
			s.push( cul( m1, m2, st ) );
		} else {
			s.push( atoi( st.c_str() ) );
		}
	}
	cout << s.top() << endl;
}

Measured memory_bytes: 1204
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();
    let week: Vec<&str> = "SUN,MON,TUE,WED,THU,FRI,SAT".split(',').collect();
    let position = week.iter().position(|day| day == &&s).unwrap();
    println!("{}", 7 - position);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,e,zx,xc,i,j,pas,k;
int main(){
    ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>a>>b>>c>>d>>k;
    zx=a*60+b;
    xc=c*60+d;
    pas=xc-zx-k;
    cout<<pas;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

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

typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

int R, W[2], H[2], X[2], Y[2];
int Room[2][500][500];
std::map<int, int> maxR[2]; // maxR[i][j]: 事務所iでj番目に小さいレベルで行ける部屋の数
int used[500][500];

void travel(int r){
    REP(j, H[r]){
        REP(k, W[r]){
            used[j][k] = 0;
        }
    }
    
    std::priority_queue<State, std::vector<State>, std::greater<State>> q;
    q.push(mp(1, mp(X[r], Y[r])));

    while(!q.empty()){
        State s = q.top(); q.pop();
        int l = s.first;
        P p = s.second;
        int x = p.first, y = p.second;

        if(used[y][x]){continue;}
        else{used[y][x] = 1;}

        maxR[r][l]++;

        //std::cout << x << "," << y << "," << l << std::endl;

        REP(i, 4){
            int nx = x + dx[i], ny = y + dy[i];
            if(0 <= nx && nx < W[r] && 0 <= ny && ny < H[r] && !used[ny][nx]){

                int nl = std::max(l, Room[r][ny][nx]);
                q.push(mp(nl, mp(nx, ny)));
            }
        }
    }
}

int main(){
    while(std::cin >> R, R){
        REP(i, 2){
            std::cin >> W[i] >> H[i] >> X[i] >> Y[i];
            X[i]--; Y[i]--;

            maxR[i].clear();
            maxR[i][0] = 0;

            REP(j, H[i]){
                REP(k, W[i]){
                    std::cin >> Room[i][j][k];
                }
            }
        }

        REP(i, 2){
            travel(i);
        }
        
        std::vector<int> u, v;
        int prev = 0;
        for(auto it=maxR[0].begin();it!=maxR[0].end();it++){
            u.push_back(it->first);
            v.push_back(prev + it->second);
            prev += it->second;
        }

        int res = INF;
        prev = 0;
        for(auto it=maxR[1].begin();it!=maxR[1].end();it++){
            int r2 = prev + it->second,
                r1_index = std::lower_bound(v.begin(), v.end(), R-r2) - v.begin();
        
            if(r1_index == v.size()){
                continue;
            }

            res = std::min(res, it->first + u[r1_index]);
            prev += it->second;
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 15864
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

H,W,A,B=get_i
ans=array(W,0,H)
B.times do|i|
  A.times do|j|
    ans[i][j]=1
  end
end
B.upto(H-1) do|i|
  A.upto(W-1) do|j|
      ans[i][j]=1
  end
end
H.times do|i|
    puts ans[i].join("")
end

Measured memory_bytes: 22116
import java.io.*;
import java.util.*;
public class Main {
	
	static class Word implements Comparable<Word> {
		String word;
		int length;
		
		public Word(String w, int l) {
			word = w;
			length = l;
		}
		
		public int compareTo(Word w) {
			for (int i=0; i<length; i++) {
				if (word.charAt(i) == w.word.charAt(i))
					continue;
				return word.charAt(i) > w.word.charAt(i) ? 1 : -1;
			}
			return 0;
		}
	}
	
	public static void main(String[] args) {
		InputReader in = new InputReader();
		int n = in.nextInt();
		int l = in.nextInt();
		
		Word[] words = new Word[n];
		for (int i=0; i<n; i++)
			words[i] = new Word(in.next(), l);
		
		Arrays.sort(words);
		
		StringBuffer sb = new StringBuffer();
		for (Word w: words)
			sb.append(w.word);
		System.out.println(sb);
	}
	
	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;
		
		public InputReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = null;
		}
		
		public String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


Measured memory_bytes: 21588
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static int count_min=10000;
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int coin[] = new int [m];
		for(int i=0;i<m;++i){
			coin[i]=scan.nextInt();
		}
		Arrays.sort(coin);
		int flag=0;
		while(n>coin[m-1]*10){
			n-=coin[m-1];
			flag++;
		}
		countWaysDP(coin,n,m,flag);
		System.out.println(count_min);
	}
	
	public static void countWaysDP(int[] coin,int n, int m, int count){
		if(count_min>count){
			int flag=1;
			int[] map = new int[m];
			for(int i=0;i<m;++i){
				map[i]=n;
			}
			count++;
			for(int i=m-1;i>=0;--i){
				if(flag==0){
					break;
				}
				map[i]=map[i]-coin[i];
				if(map[i]<0){
					m--;
				}
				if(map[i]==0){
					flag=0;
					m=0;
					count_min=count;
				}
			}
			for(int i=m-1;i>=0;--i){
				if(m>0&&flag==1){
					countWaysDP(coin,map[i],i+1,count);
				}
			}
		}
	}
}

Measured memory_bytes: 135420
#include <stdio.h>

int main(void){
 int a,b,c,k,x;
 scanf("%d %d %d %d",&a,&b,&c,&k);
 x=k-a;
 if(x<=0){
   printf("%d",k);
 }else if(b>=x){
     printf("%d",a);
 }else{
   printf("%d",2*a+b-k);
 }
  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 3e5 + 10 ;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
 
long long n  , l[mxn]; 
long long mxu[mxn] , mn[mxn] , ans , mxd[mxn];
int main(){
	cin>>n ; 
	for (int i = 0 ; i <= n ; i++)
		cin>>l[i] ; 
	mxu[0] = 1 , mn[0] = 0 ; 
	for (int i = 0 ; i <= n; i++){
		if (l[i] > mxu[i] or l[i] < mn[i]){
			cout<<-1 ; 
			return 0 ; 
		}
		long long  k = mxu[i] - l[i] ; 
		mxu[i+1] = min((ll)inf , k*2); 
		mn[i+1] = max((ll)0 , mn[i]-l[i]) ; 
	}
	mxd[n] = l[n] ;
	for (int i = n-1 ; i>=0 ; i--)
		mxd[i] = min(mxd[i+1] + l[i] , inf)  ; 
	for (int i = 0 ; i <= n ; i++)
		ans+=(min (mxd[i] , mxu[i])) ; 
	cout<<ans ; 
}



Measured memory_bytes: 6756
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, M = map(int, input().split())
PATH = [[] for _ in range(N + 1)]

for _ in range(M):
    A, B = map(int, input().split())
    PATH[A].append(B)
    PATH[B].append(A)


USED = [False] * (N + 1)
MARK = [None] * (N + 1)

Q = [1]
Q = deque(Q)

while Q:
    node = Q.popleft()

    for v in PATH[node]:
        if USED[v]:
            continue

        MARK[v] = node
        USED[v] = True
        Q.append(v)

print("Yes")
print("\n".join(map(str, MARK[2:])))


Measured memory_bytes: 42560
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5;
int n,m,tot=1,flag,key,cnt;
int pre[maxn*2+8],now[maxn+8],son[maxn*2+8];
int dep[maxn+8],fa[maxn+8],f[maxn+8],v[maxn+8],tmp[maxn+8];

int read()
{
    int x=0,f=1;char ch=getchar();
    for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
    for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
    return x*f;
}

void add(int u,int v)
{
    pre[++tot]=now[u];
    now[u]=tot;
    son[tot]=v;
}

void check(int x)
{
    dep[x]=dep[fa[x]]+1;
    v[x]=(dep[x]&1)*2-1;
    f[x]=v[x];
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    if (fa[x]==child) continue;
	    if (fa[child]) {flag=((dep[x]-dep[child]+1)&1)+1,key=p;continue;}
	    fa[child]=x;
	    check(child);
	    f[x]+=f[child];
	}
}

void dfs(int x)
{
    f[x]=v[x];
    for (int p=now[x];p;p=pre[p])
	{
	    int child=son[p];
	    if ((p|1)==(key|1)||fa[x]==child) continue;
	    dfs(child);
	    f[x]+=f[child];
	}
}

int main()
{
    n=read(),m=read();
    for (int i=1;i<=m;i++)
	{
	    int u=read(),v=read();
	    add(u,v),add(v,u);
	}
    fa[1]=1;
    check(1);
    if (!flag)
	{
	    if (f[1])
		{
		    puts("-1");
		    return 0;
		}
	    ll ans=0;
	    for (int i=1;i<=n;i++) ans+=abs(f[i]);
	    printf("%lld\n",ans);
	}
    if (flag==2)
	{
	    if (f[1]&1)
		{
		    puts("-1");
		    return 0;
		}
	    //for (int i=1;i<=n;i++) printf("%d ",dep[i]);puts("");
	    //printf("check:%d %d %d\n",f[1],son[key],son[key^1]);
	    //printf("%d %d\n",v[son[key]],v[son[key^1]]);
	    v[son[key]]-=f[1]/2;
	    v[son[key^1]]-=f[1]/2;
	    ll ans=abs(f[1]/2);
	    //printf("%d %d\n",v[son[key]],v[son[key^1]]);
	    dfs(1);
	    //printf("check:%d\n",f[1]);
	    for (int i=1;i<=n;i++) ans+=abs(f[i]);
	    printf("%lld\n",ans);
	}
    if (flag==1)
	{
	    if (f[1])
		{
		    puts("-1");
		    return 0;
		}
	    if (dep[son[key]]<dep[son[key^1]]) key^=1;
	    int x=son[key];
	    tmp[++cnt]=0;
	    while(x!=son[key^1]) tmp[++cnt]=f[x],x=fa[x];
	    sort(tmp+1,tmp+cnt+1);
	    ll ans=tmp[(cnt+1)/2];
	    v[son[key]]-=ans;
	    v[son[key^1]]+=ans;
	    dfs(1);
	    ans=abs(ans);
	    for (int i=1;i<=n;i++) ans+=abs(f[i]);
	    printf("%lld\n",ans);
	}
    return 0;
}


Measured memory_bytes: 8832
#include<iostream>
#include<vector>
#include<algorithm>


using sll = signed long long;

template<class T>
auto right(const std::vector<T>& tab, int index ) {
	auto r_index = (index +1)* 2;
	auto b = static_cast<decltype(tab.size())>(r_index )< tab.size();

	return
		std::make_pair(b, b ? r_index : index);
}


template<class T>
auto left(const std::vector<T>& tab, int index) {
	auto l_index = (index + 1) * 2 - 1;
	auto b = static_cast<decltype(tab.size())>(l_index) < tab.size();

	return
		std::make_pair(b, b ? l_index : index);
}

template<class T>
auto make_max_heap(std::vector<T>*const tp, int index)->void {
	auto & tab = *tp;
	auto lnode = left(tab, index);
	auto rnode = right(tab, index);

	auto lv = lnode.first ? lnode.second : std::min( sll{}, tab[index] );
	auto rv = rnode.first ? rnode.second : std::min( sll{}, tab[index] );
	
	sll max_index
		= lnode.first && tab[index] < tab[lnode.second]
		? lnode.second : sll{ index };

	max_index
		= rnode.first && tab[max_index] < tab[rnode.second]
			? rnode.second : max_index;

	if (max_index != index) {
		std::swap(tab[index], tab[max_index]);
		make_max_heap(tp, max_index);
	}
}

int main() {

	int H;
	std::cin >> H;

	std::vector<sll> tab(H);
	for (auto&e : tab)
		std::cin >> e;

	for (int i{ H / 2 }; i >= 0; --i) {
		make_max_heap(&tab, i);
	}

	for (const auto&e : tab) {
		std::cout <<" "<<e;
	}std::cout << "\n";

	return 0;
}


Measured memory_bytes: 6620
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl
using namespace std;
using ll = long long;
const int INFINT = 1 << 30;
const ll INFLL = 1LL << 60;
const int MOD = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a%b) : a;}

int main() {


	string s;
	cin >> s;
	vector<int>v(s.size());
	REP(i, s.size()) {
		v[i] = s[i] - '0';
	}

	int max = 1;
	REP(i, s.size() - 1) max *= 2;
	max -= 1;

	long long ans = 0;
	REP(i, max + 1) {
		long long sum = 0;
		int b = i;
		vector<int> v;
		int idx = 0;
		REP(j, s.size() - 1) {
			if (b & 1) {
				sum += stoi(s.substr(idx, j - idx + 1));
				idx = j + 1;
			}
			b = b>> 1;
		}
		sum += stoll(s.substr(idx));
		ans += sum;
	}

	cout << ans NL;

	return 0;
}

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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	clock_t start = clock();
#endif

	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	f(step,0,40) {
		bool found = 0;
		f(i,0,3) found |= a[i]&1;
		if (found) {
			cout << step << endl;
			return 0;
		}
		int b[3] = {a[1]+a[2],a[0]+a[2],a[0]+a[1]};
		f(i,0,3) a[i] = b[i]/2;
		sort(a,a+3);
	}
	cout << -1 << endl;

#ifdef LOCAL
	cout << setprecision(12) << (long double)(clock()-start) / CLOCKS_PER_SEC << endl;
#endif
	
	return 0;
}



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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define RALL(a)     (a).rbegin(),(a).rend()
#define PRINT(a)   cout << (a) << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

using ll = long long int;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

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

const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

int main(){
  int n,m;
  cin >> n >> m;
  vi sum(n+1,0);
  REP(i,m){
    int l,r;
    cin >> l >> r;
    l--;r--;
    sum[l]++;
    sum[r+1]--;
  }
  REP(i,n){
    sum[i+1] += sum[i];
  }
  int ans=0;
  REP(i,n+1){
    if(sum[i]==m)ans++;
  }
  cout << ans << endl;
}




Measured memory_bytes: 3696
#include <stdio.h> 
int main(void)
{ 
     int x, y; 
     while(1){ 
         scanf("%d %d", &x, &y); 
         if(x==0 && y==0)break; 
         if(x<y){ 
             printf("%d %d\n", x, y); 
        }
        else{ 
             printf("%d %d\n", y, x); 
        } 
    } 
     return 0; 
} 


Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
#define ff first
#define dd second
#define mp make_pair
#define pb push_back
#define pp pair<int,int>
#define N 100007 // check
#define M 10000
#define K 76
#define ll long long
using namespace std;

int n;
string s;
vector<array<int,4>> elements;

int hashe(vector<int> x) {
    int mod = 1e9+9;
    int res = 0;
    int p = 29;
    for(int i = 0; i < x.size(); ++i) {
        res *= p;
        res += x[i];
        res %= mod;
    }
    return res;
}

int ile(array<int,4> temp) {
    return upper_bound(elements.begin(), elements.end(), temp) - lower_bound(elements.begin(), elements.end(), temp);
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> s;

    int ans = 0;

    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> left; vector<int> right;
        for(int i = 0; i < n; ++i) {
            if(mask & (1<<i)) {
                left.pb(s[i]-'a');
            } else {
                right.pb(s[i] - 'a');
            }
        }

        reverse(right.begin(), right.end());
        elements.pb({(int)left.size(), (int)right.size(), hashe(left), hashe(right)});
    }

    sort(elements.begin(), elements.end());

    for(int mask = 0; mask < (1 << n); ++mask) {
        vector<int> left; vector<int> right;
        for(int i = 0; i < n; ++i) {
            if(mask & (1<<i)) {
                left.pb(s[i+n]-'a');
            } else {
                right.pb(s[i+n] - 'a');
            }
        }

        reverse(right.begin(), right.end());
        ans += ile({right.size(), left.size(), hashe(right), hashe(left)});
    }
    cout << ans << "\n";
}

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

using namespace std;

int main() {
	int N, D, X;
	cin >> N >> D >> X;
	vector<int>A(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int ans = X;
	
	for (int i = 0; i < N; i++) {
		int tmp = (D - 1) / A[i] + 1;
		ans += tmp;
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int point[5] = {0, 0, 60, 70, 80};
void get(int v[], int S){
  /*
  printf("%d: ", S);
  REP(i, 5) printf("%d ", v[i]);
  printf("->");
  */
  REP(i, 4){
    if(v[i] > 0){
      v[i] += S & 3;
      if(v[i] > 4) v[i] -= 4;
    }
    if(v[i + 1] > 0){
      v[i + 1] += S & 3;
      if(v[i + 1] > 4) v[i + 1] -= 4;
    }
    S >>= 2;
  }
  /*
  REP(i, 5) printf("%d ", v[i]);
  cout<<endl;
  */
}

int main(){
  int N;
  cin>>N;
  while(N--){
    int a[5][5];
    REP(i, 5)REP(j, 5){
      cin>>a[i][j];
    }
    int dp[5][256] = {}; //[5][4^5]
    int from[5][256] = {};
    REP(S, 256){
      int v[5]; 
      memcpy(v, a[0], sizeof(v));
      get(v, S);
      REP(i, 5) dp[0][S] += point[v[i]];
    }
    FOR(i, 1, 4){
      REP(FS, 256)REP(S, 256){
        int v[5]; 
        memcpy(v, a[i], sizeof(v));
        get(v, S);
        get(v, FS);
        int sum = 0;
        REP(j, 5) sum += point[v[j]];
        if(dp[i][S] < dp[i - 1][FS] + sum){
          dp[i][S] = dp[i - 1][FS] + sum;
          from[i][S] = FS;
        }
      }
    }
    int ans = 0;
    REP(S, 256){
      int v[5]; 
      memcpy(v, a[4], sizeof(v));
      get(v, S);
      int sum = 0;
      REP(j, 5) sum += point[v[j]];
      ans = max(ans, dp[3][S] + sum);
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d  long double
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (int)1e18
#define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;


 
signed main()
{
    haha
   string s;
   cin>>s;
   int f=0;
   int q;
   cin>>q;
   while(q--)
   {
      // cout<<s<<endl;
       int t;
       cin>>t;
       if(t==1)
       {
           f^=1;
       }
       else
       {
           int f1;char c;
           cin>>f1;
           cin>>c;
           string h="";
           h+=c;
           if(f==1)
           {
               if(f1==1)
               s+=c;
               else
               s.insert(0,h);
           }
           else
           {
               if(f1==1)
               s.insert(0,h);
               else
               s+=c;
              
              
           }
          
          // cout<<s<<endl;
           
           
       }
      
       
       
       
       
       
   }
    if(f==1)
       {
      reverse(s.begin(),s.end());
       cout<<s;
       }
       else
       cout<<s;
       
       
    
    
    
}

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

int main(){
    int N, M;
    cin >> N >> M;
    priority_queue<int> A;
    for(int i = 0; i < N; i++){
        int t;
        cin >> t;
        A.push(t);
    }
    for(int i = 0; i < M; i++){
        int tmp = A.top();
        tmp /= 2;
        A.pop();
        A.push(tmp);
    }
    long ans = 0;
    while(!A.empty()){
        ans += A.top();
        A.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define ll long long
#define MAXN 10000
#define INF 0x3f3f3f3f
#define ld long double
using namespace std;
ll num[200005]={0};
ll a[200005];

int main(){
    ios::sync_with_stdio(false);
    #define int ll
    int n;
    cin>>n;
    map<int,int>s;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        num[i]=a[i]-i;
        s[num[i]]+=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++){

        int tp=0-i-a[i];
        ans+=s[tp];
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 29480
#include <bits/stdc++.h>
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; for(int cnt = 0; getline(stream,res,sp_word); cnt++)
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
#define digit(x) ((int)log10((double)(x)) + 1)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
using namespace std;
const int MOD = 1000000007; 
typedef long long ll;
typedef string str;
 
int main(){
  ll a,b,x;
  cin >> a >> b >> x;
  ll n = b / x;
  ll m = a / x;
  cout << n - m + (a % x == 0 ? 1 : 0);
  return 0;
}

Measured memory_bytes: 256