akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,tot[205000],res=0;
int main() {
    cin>>n>>k;
    if(k&1) {
        ll ans=n/k;
        cout<<ans*ans*ans<<endl;
    }
    else {
        int ans=k/2;
        for(int i=1;i<=n;i++)
            tot[i%k]++;
        for(int i=0;i<k;i++)
            if(i==ans&&tot[i]||i==0&&tot[i])
            res+=tot[i]*tot[i]*tot[i];
        cout<<res<<endl;
    }

    
}

Measured memory_bytes: 1024
def main():
    h, w = map(int, input().split())

    if h == 1 or w == 1:
        ans = 1
    elif h * w % 2 == 0:
        ans = h * w // 2
    else:
        ans = h * w // 2 + 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 61568
#include <bits/stdc++.h>
using namespace std;
const int maxn = 234567;
int a[maxn], v[maxn];
int main(){
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	int ans = 1;
	multiset<int> good; good.insert(a[1]);
	for(int i = 2; i <= n; i++){
		auto it = good.lower_bound(a[i]);
		if(it == good.begin()){
			ans++;
		} else {
			it--;
			good.erase(it);
		}
		good.insert(a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5376
#define _USE_MATH_DEFINES
#pragma region include

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
#pragma endregion //#include
/////////

#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LD A;
	cin >> A;
	cout << A * A * A / 27 << endl;
}

#pragma region main
signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()


Measured memory_bytes: 384
#[allow(unused_imports)]
use {
    itertools::Itertools,
    proconio::{fastout, input, marker::*},
    std::cmp::*,
    std::collections::*,
    std::io::Write,
    std::ops::*,
};

macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

#[fastout]
fn main() {
    input! {
        n: usize,
    }
    if n == 0 {
        println!("1");
    } else {
        println!("0");
    }
}


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

vector<vector<int>> tree;

void dfs(int n, int p, vector<int>& dist){
    for(int u : tree[n]){
        if(u == p) continue;
        dist[u] = min(dist[u], dist[n] + 1);
        dfs(u, n, dist);
    }
}

int main(){
    int N, u, v;  cin >> N >> u >> v;
    u--;  v--;
    tree.resize(N);
    for(int i=0; i<N-1; i++){
        int a, b;  cin >> a >> b;
        a--;  b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    vector<int> dt(N, 1e9), da(N, 1e9);
    dt[u] = 0;  da[v] = 0;
    dfs(u, -1, dt);
    dfs(v, -1, da);

    vector<int> goal;
    for(int i=0; i<N; i++){
        if(da[i] > dt[i] && tree[i].size() == 1){
            goal.push_back(i);
        }
    }

    int ans = 0;
    for(int g: goal){
        ans = max(ans, dt[g] + da[g] - dt[g] - 1);
    }
    cout << ans << endl;
}

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

int main(void) {
    string s;
    cin >> s;
    int max = 0;
    int count = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'A' || s[i] == 'G'|| s[i] == 'C' || s[i] == 'T') {
            count++;
            if(max < count) max = count;
        } else {
            if(max < count) max = count;
            count = 0;
        }
        

    }
    cout << max << endl;
    return 0;
}

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

long long N, C[1 << 18], dp[1 << 18], prev_[1 << 18], mod = 1000000007;
long long rem[1 << 18];

int main() {
	cin >> N;
	for (int i = 1; i <= 200000; i++) rem[i] = -1;
	for (int i = 1; i <= N; i++) cin >> C[i];
	for (int i = 1; i <= N; i++) { prev_[i] = rem[C[i]]; rem[C[i]] = i; }
	dp[0] = 1;
	for (int i = 1; i <= N; i++) {
		dp[i] = dp[i - 1];
		if (prev_[i] >= 1 && prev_[i] != i - 1) dp[i] += dp[prev_[i]];
		dp[i] %= mod;
	}
	cout << dp[N] << endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;

int main(){
    long a, b, k;
    cin >> a >> b >> k;
    if(k > a){
        if(k - a > b){
            cout << 0 << " " << 0;
        }else{
            cout << 0 << " " << b - (k - a);
        }
    }else{
    cout << a - k << " " << b;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
// double power(double num, double g) {
// 	if (g == 0)return 1;
// 	if (g % 2 == 1)return (num * power((num * num), g / 2));
// 	return power( (num * num) , g / 2);
// }

int main(){
	ll a, b, n, x;
	cin >> a>> b >> n;
	if (n >= b-1) x= b -1;
	else x = n;
	cout << (a*x)/b;
}



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

#define ll long long
#define llu unsigned long long
#define ld long double
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pf push_front
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define vvi(v, n, m) vector<vi> v(n, vi(m))
#define vvll(v, n, m) vector<vll> v(n, vll(m))
#define all(x) (x).begin(), (x).end()
#define present(v,x) (v).find(x) != (v).end()
#define cpresent(v,x) (find(all(v),x) != (v).end())
#define mset(x,v) memset(x, v, sizeof(x))
#define sz(x) (int)x.size()

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
void debug_out() { cout << ""; }
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
#define pr(v, n) {for(int j=0; j<n; j++){debug_out(v[j]); if(j<n-1) cout<<",";}}
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); { cout << endl; }
#define dbg1d(v, n) cout << "[" << #v << "]: {"; pr(v, n); {cout << " }" << endl;}
#define dbg2d(v, n, m) cout<<"["<<#v<<"]:"<<endl;{for(int i=0; i<n; i++){cout<<right<<setw(10)<<"["+to_string(i)+"] {";pr(v[i],m);{cout<<" }"<<endl;}}}
#define shout()  {cout << "I'm Here...!!!" << endl;}

inline ll fpow(ll n, ll k, int p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, int p = MOD) {return fpow(a, p - 2, p);}
inline int addmod(int a, int val, int p = MOD) {{if ((a = (a + val)) >= p) a -= p;} return a;}
inline int submod(int a, int val, int p = MOD) {{if ((a = (a - val)) < 0) a += p;}return a;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

#define MAXN 200005
ll t[4*MAXN];

ll maxSeg(int v, int tl, int tr, int l, int r){
	if(l>r)
		return 0;
	if(l==tl and r==tr)
		return t[v];
	int tm = (tl + tr)/2;
	return max(maxSeg(v*2, tl, tm, l, min(r, tm)), maxSeg(v*2+1, tm+1, tr, max(l, tm+1), r));
}

void updateSeg(int v, int tl, int tr, int pos, ll new_val){
	if(tl==tr)
		t[v] = new_val;
	else{
		int tm = (tl+tr)/2;
		if(pos<=tm)
			updateSeg(v*2, tl, tm, pos, new_val);
		else
			updateSeg(v*2+1, tm+1, tr, pos, new_val);
		t[v] = max(t[v*2], t[v*2 + 1]);
	}
}

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

	int n;
	cin >> n;
	vector<int> h(n), a(n);
	for(int i=0; i<n; i++)
		cin >> h[i];
	for(int i=0; i<n; i++)
		cin >> a[i];

	for(int i=0; i<n; i++)
		updateSeg(1, 1, n, h[i], maxSeg(1, 1, n, 1, h[i])+a[i]);

	cout << maxSeg(1, 1, n, 1, n) << endl;

	return 0;
}

Measured memory_bytes: 7936
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int n;

int factorization(int n){
	if(n==1) return 0;
	cout << n << ": ";
	for(int i = 2; i <= sqrt(n); i++){
		if(n % i == 0){
			cout << i <<  " ";
			n = n / i;
			i = 1;
		}
	}
	cout << n << endl;
	return 0;
}

void solve(){
	cin >> n;
	factorization(n);
}

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

Measured memory_bytes: 1196
import java.util.*;

public class Main {
    public static void main(String[] args) {	
	Main main = new Main();
    	main.solveA();
    }
    
    private void solveA() {
    	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int a,b;

	if (n%10 == 0){
	    a = b = n/2;
	}
	else{
	    int d = 10;
	    while(d*10 <= n){
		d *= 10;
	    }
	    a = (n/d) * d;
	    b = n%d;
	}
	
	int ans = 0;
	while(a != 0){
	    ans += a%10;
	    a /= 10;
	}

	while(b != 0){
	    ans += b%10;
	    b /= 10;
	}
	
    	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int test = 1;
    while (test--)
    {
        int n, m;
        cin >> n >> m;
        if (m >= n)
        {
            cout << "unsafe";
        }
        else
        {
            cout << "safe";
        }
    }
    return 0;
}

Measured memory_bytes: 3612
solve k a b = f list
  where
    list = filter (\n -> n `mod` k == 0) [a..b]
    f [] = "NG"
    f _ = "OK"

main = do
  k <- readLn :: IO Int
  [a,b] <- map read . words <$> getLine
  putStrLn $ solve k a b


Measured memory_bytes: 3944
h, w = map(int, input().split())
maze = [[i for i in input()] for _ in range(h)]
move = [(-1, 0), (1, 0), (0, -1), (0, 1)]

dist = [[-1] * w for _ in range(h)]
dist[0][0] = 0
from collections import deque
d = deque()
d.append((0, 0))

count = 0
for i in range(h):
  for j in range(w):
    if maze[i][j] == ".":
      count += 1

while d:
  x, y = d.popleft()
  for m in move:
    i = x + m[0]
    j = y + m[1]
    if i >=0 and i < h and j >= 0 and j < w:
      if maze[i][j] == "#":
        continue
      if dist[i][j] != -1:
        continue
      dist[i][j] = dist[x][y] + 1
      d.append((i, j))
mindist = dist[h-1][w-1]
if mindist == -1:
  print(-1)
else:
  print(count-mindist -1)


Measured memory_bytes: 74116
from sys import stdin
import collections
from sys import  setrecursionlimit
setrecursionlimit(30000)

[H, W] = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for line in range(H):
    temp = stdin.readline().rstrip()
    temp_arr = []
    for j in range(len(temp)):
        temp_arr.append(temp[j])
    data.append(temp_arr)


#幅優先探索で最短経路を探す

visited = []
candidates = collections.deque()

def wfs(data, start_pos, visited, candidates):
    index = start_pos[2]
    visited.append([start_pos[0],start_pos[1]])

    #goal
    if start_pos[0] == H-1 and start_pos[1] == W-1:
        return start_pos[2]
    
    #candidates
    for i in range(-1,2):
        for j in range(-1,2):
            if abs(i)+ abs(j)!=1:
                continue
            new_pos = [start_pos[0]+i, start_pos[1]+j,index+1]
            if new_pos[0]<0 or new_pos[0]>=H or new_pos[1]<0 or new_pos[1]>=W:
                continue
            if new_pos[:2] in visited:
                continue
            if data[new_pos[0]][new_pos[1]]==".":
#            if True:
                candidates.append(new_pos)
    
    while(True):
        if len(candidates)==0:
            return -1
        next_pos = candidates.popleft()
        if next_pos[:2] not in visited:
            break
        
    result = wfs(data, next_pos, visited,candidates)

    return result

def check_number(data):
    count = 0
    for i in range(H):
        for j in range(W):
            if data[i][j]==".":
                count+=1
    return count


result = wfs(data,[0,0,0],visited, candidates)
if result==-1:
    print(-1)
else:
    print(check_number(data)-result-1)
                

    




Measured memory_bytes: 5872
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  long long n,a,b,ans;
  cin >> n >> a >> b;
  if(a>b||(n==1&&a!=b)) {
    cout << 0 << endl;
  }
  else {
    ans=(b-a)*(n-2)+1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(g.size(), INF);

  using Pi = pair< T, int >;
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  dist[s] = 0;
  que.emplace(dist[s], s);
  while(!que.empty()) {
    T cost;
    int idx;
    tie(cost, idx) = que.top();
    que.pop();
    if(dist[idx] < cost) continue;
    for(auto &e : g[idx]) {
      auto next_cost = cost + e.cost;
      if(dist[e.to] <= next_cost) continue;
      dist[e.to] = next_cost;
      que.emplace(dist[e.to], e.to);
    }
  }
  return dist;
}


int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    ll ans = 0;
    rep (i, n) {
        ans += a[i] / 2;
        if (a[i] % 2 && i != n-1 && a[i+1] > 0) {
            a[i+1]++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
<?php
while($line = fgets(STDIN)){
	$arr = explode(" ", $line);
	
	if($arr[0] == 0 && $arr[1] == 0 && $arr[2] == 0) exit;
	
	$arr[0] = intval($arr[0]);
	$arr[1] = intval($arr[1]);
	$arr[2] = intval($arr[2]);
	// ??????????????????
	sort($arr);
	
	// ????????§????????¢???????°?????????¢???????§????????????????2???
	$c = $arr[0] * $arr[0] + $arr[1] * $arr[1];
	
	$num = intval(fgets(STDIN));
	for($i = 0; $i < $num; $i++){
		$r = 2 * intval(fgets(STDIN));	// ??´???
		if($c < $r * $r){
			echo "OK\n";
		}else{
			echo "NA\n";
		}
	}
}

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

ll a[10],b[10],num[10];

int main(){
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		num[i]=i+1;
	}
	for(int i=0;i<n;i++)cin>>b[i];
	ll cnt=0,ansa,ansb;
	do{
		cnt++;
		bool fa=1,fb=1;
		for(int i=0;i<n;i++){
			if(a[i]!=num[i])fa=0;
			if(b[i]!=num[i])fb=0;
		}
		if(fa)ansa=cnt;
		if(fb)ansb=cnt;
	}while(next_permutation(num,num+n));
	cout<<abs(ansa-ansb);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>

using namespace std;

int main () {
  int N;
  cin >> N;
  int d;
  set <int> sd;
  for (int i = 0; i < N; i++){
    cin >> d;
    sd.insert(d);
  }
  cout << sd.size() << endl;
  return 0;
}

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

using namespace std;

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;

signed main()
{
    int k;
    string s;
    cin >> k >> s;

    int l = s.size();

    if (l <= k)
    {
        cout << s << endl;
    }
    else
    {
        string temp = s.substr(0, k);
        cout << temp << "..." << endl;
    }

    return 0;
}


Measured memory_bytes: 3632
import java.util.Scanner;

public class Main{
	public static void main(String args[]){

		Scanner sc = new Scanner (System.in);
		int ary[]= new int[3];
		for (int i=0;i<=2;++i){
			ary[i]= sc.nextInt();
		}
		int a,b;

		for ( int i =1;i>=0;--i){
		if (ary[i+1]<ary[i]){
			a=ary[i];
			b=ary[i+1];
			ary[i]=b;
			ary[i+1]=a;
		}
		}
		if (ary[2]<ary[1]){
			a=ary[1];
			b=ary[2];
			ary[1]=b;
			ary[2]=a;
		}
		System.out.println(ary[0]+" "+ary[1]+" "+ary[2]);
	}
}


Measured memory_bytes: 26200
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
#define PB push_back
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int First = 1, Second = 2;
int toggle(int p) {
  if (p == First)
    return Second;
  return First;
}
int main() {
  int N, K;
  cin >> N >> K;

  VI A;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    A.PB(a);
  }
  SORT(A);
  int min_A = A[0];
  VI dp(K + 1, 0); // dp[i] = 山がi個のときに勝つほう

  REP(k,min_A)
    dp[k] = Second;
  dp[min_A] = First;

  FOR(k, min_A+1, K+1) {
    bool can_win = false;
    for (VI::iterator it = A.begin(); it != A.end(); ++it) {
      if (k - (*it) >= 0 && dp[k - (*it)] == Second)
        can_win = true;
    }
    if (can_win)
      dp[k] = First;
    else
      dp[k] = Second;
  }
  cout << (dp[K] == First ? "First" : "Second") << endl;
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{

  //ll t;
  //cin>>t;
  //while(t--)
  {
 string s;cin>>s;
 for(ll i=0;i<s.size();i++)
    cout<<'x';
 cout<<endl;
  }
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  if(n==1||n==2||n==3||n==5||n==6||n==9||n==10||n==13||n==17){
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

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

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

inline double nCr(const int n, int r)
{

    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

//----------------------------------------------------------------

int main()
{
    ll n;
    cin >> n;
    vector<ll> g(5);
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s.at(0) == 'M')
        {
            g[0]++;
        }
        if (s.at(0) == 'A')
        {
            g[1]++;
        }
        if (s.at(0) == 'R')
        {
            g[2]++;
        }
        if (s.at(0) == 'C')
        {
            g[3]++;
        }
        if (s.at(0) == 'H')
        {
            g[4]++;
        }
    }
    ll sum = 0;
    for (int i = 0; i < 3; i++)
    {
        for (int j = i + 1; j < 4; j++)
        {
            for (int k = j + 1; k < 5; k++)
            {
                sum += g[i] * g[j] * g[k];
            }
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

a,b=get_i
target=0
lp=0
if a>b
    target=b
    lp=a
else
    target=a
    lp=b
end
ans=""
lp.times do|i|
    ans+=target.to_s
end
puts ans

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

#define rep(i, n) for(int i = 0; i < (n); i++)
using ll = long long;
constexpr ll INF = 1000000000;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c, x, y; cin >> a >> b >> c >> x >> y;

	vector<ll>ans(3);

	ans[0] = a * x + b * y;

	if (x > y) {
		ans[1] = 2 * y * c + (x - y) * a;
	}
	else {
		ans[1] = 2 * x * c + (y - x) * b;
	}

	ans[2] = max(x, y) * 2 * c;
	sort(ans.begin(), ans.end());
	cout << ans[0] << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC026A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c;

            var word = Console.ReadLine().Split(' ');

            a = int.Parse(word[0]);
            b = int.Parse(word[1]);
            c = int.Parse(word[2]);

            if (a<=b && b<=c || b<=a && a<=c)
                Console.WriteLine(a+b);

            else if (a <= c && c <= b || c<=a && a<=b)
                Console.WriteLine(a + c);

            else
                Console.WriteLine(b+c);


            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
using namespace std;
int main(){
    long long N,M=0,A=0,R=0,C=0,H=0;
    long long ans = 0;
    cin >> N;
    string s[N];
    for(int i=0;i<N;i++){
        cin >> s[i];
    }
    for(int i=0;i<N;i++){
        if(s[i][0]=='M'){
            M++;
        }else if(s[i][0]=='A'){
            A++;
        }else if(s[i][0]=='R'){
            R++;
        }else if(s[i][0]=='C'){
            C++;
        }else if(s[i][0]=='H'){
            H++;
        }
    }
    ans = M*A*R+M*A*C+M*A*H+M*R*C+M*R*H+M*C*H+A*R*C+A*R*H+A*C*H+R*C*H;
    cout << ans << endl;
}



Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define forn(i, k, n) for (int i = k+1; i < int(n); i++)
typedef long long LL;
typedef pair<int, int> PII;

int digit(long n){
	int dig = 1;
  	while(n / 10 > 0){
		n /= 10;
      	dig++;
    }  
  	return dig;
}

long search_mul(long small, long big, long n){
    long a,b;
    int i;
    for(i = small + 1; i < big; i++){
        if(n % i == 0){
            a = i;
            b = n/a;
            if(n % (a * small) == 0 && a*small < n/(a*small)){
                a = a * small;
                b = n/a;
                //cout << a << " * " << b << endl;
                return search_mul(a,b,n);
            }
            //cout << a << " * " << b << endl;
            //return min(digit(b), search_mul(a,b,n));
            return search_mul(a,b,n);
        }
    }
    //cout << small << " * " << big << " ,ans :";
    return big;
}
void f(long n) {
  int ans;
  long temp = sqrt(n)+1;
  long ret;

  ret = search_mul(1,temp,n);
  
  if(ret == temp)
    ans = digit(n);
  else
    ans = digit(ret);
  cout << ans << endl; 
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long n;
  cin >> n;
  f(n);
  return 0;
}

Measured memory_bytes: 3592
N, K = map(int, input().split())
S = input()

l = []
bef = ""
start = 0

for i, s in enumerate(S):
    if bef=="":
        start = i
    elif bef!=s:
        l.append(i-start)
        start = i
    bef = s
l.append(i-start+1)

size = len(l)
ans = 0
for i in range(min(2*K+1, size)):
    ans += l[i]
ans -= 1
for i in range(min(2*K+1, size), size):
    ans += l[i]-1
print(ans)


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

double eps = 1e-8;

struct Point {
  double x, y;
  Point(double x = 0.0, double y = 0.0) : x(x), y(y) {}  
  double norm() {return sqrt(x*x + y*y);}
};

Point operator + (const Point &p, const Point &q) {return Point(p.x + q.x, p.y + q.y);};
Point operator - (const Point &p, const Point &q) {return Point(p.x - q.x, p.y - q.y);};
double operator * (const Point &p, const Point q) {return p.x * q.x + p.y * q.y;};
bool operator == (const Point &p, const Point &q) {return (abs(p.x - q.x) < eps && abs(p.y - q.y) < eps);};
bool operator != (const Point &p, const Point &q) {return !(p == q);};

struct Line {
  double a, b, c;
  Line(double a, double b, double c) : a(a), b(b), c(c) {}
  Line(Point p, Point q) {
    a = q.y - p.y;
    b = p.x - q.x;
    c = q.x * p.y - p.x * q.y;
  }
};

struct Circle {
  double r;
  Point p;
  Circle(Point p = Point(0.0, 0.0), double r = 0.0) : p(p), r(r) {}
};

vector<Point> circle_line_cross(Line l, Circle c) {
  vector<Point> vp;
  Point h;
  h.x = c.p.x - l.a * (l.a*c.p.x + l.b*c.p.y + l.c) / (l.a*l.a + l.b*l.b);
  h.y = c.p.y - l.b * (l.a*c.p.x + l.b*c.p.y + l.c) / (l.a*l.a + l.b*l.b);

  double d = l.a*c.p.x + l.b*c.p.y + l.c;
  double q = c.r*c.r - d*d / (l.a*l.a + l.b*l.b);
  Point p1, p2;
  p1.x = h.x + sqrt(q) * l.b / sqrt(l.a*l.a + l.b*l.b);
  p1.y = h.y - sqrt(q) * l.a / sqrt(l.a*l.a + l.b*l.b);
  p2.x = h.x - sqrt(q) * l.b / sqrt(l.a*l.a + l.b*l.b);
  p2.y = h.y + sqrt(q) * l.a / sqrt(l.a*l.a + l.b*l.b);
  if(abs(l.b) < eps) {
    if(l.a > 0) {
      vp.push_back(p1);
      vp.push_back(p2);
    } else {
      vp.push_back(p2);
      vp.push_back(p1);
    }
  } else if(l.b > eps) {
    vp.push_back(p2);
    vp.push_back(p1);
  } else {
    vp.push_back(p1);
    vp.push_back(p2);
  }
  return vp;
} 

int main(){
  double cx, cy, r;
  cin >> cx >> cy >> r;
  Circle c(Point(cx,cy),r);
  int q;
  cin >> q;
  rep(i,q) {
    double x1, x2, y1, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    Line l(Point(x1,y1),Point(x2,y2));
    vector<Point> ans = circle_line_cross(l,c);
    printf("%.9lf %.9lf %.9lf %.9lf\n",ans[0].x,ans[0].y,ans[1].x,ans[1].y);
  }
  return 0;
}


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

void Select_Figure( char s[14][14] )
{
    for( int i = 3; i < 11; i++ )
    {
        for( int j = 3; j < 11; j++ )
        {
            if( s[i][j] == '1' )
            {
                if( s[i][j+1] == '1' && s[i+1][j] == '1' && s[i+1][j+1] == '1' )
                    cout << 'A' << endl;
                else if ( s[i+1][j] == '1' && s[i+2][j] == '1' && s[i+3][j] == '1' )
                    cout << 'B' << endl;
                else if ( s[i][j+1] == '1' && s[i][j+2] == '1' && s[i][j+3] == '1' )
                    cout << 'C' << endl;
                else if ( s[i+1][j] == '1' && s[i+1][j-1] == '1' && s[i+2][j-1] == '1' )
                    cout << 'D' << endl;
                else if ( s[i][j+1] == '1' && s[i+1][j+1] == '1' && s[i+1][j+2] == '1' )
                    cout << 'E' << endl;
                else if ( s[i+1][j] == '1' && s[i+1][j+1] == '1' && s[i+2][j+1] == '1' )
                    cout << 'F' << endl;
                else if ( s[i][j+1] == '1' && s[i+1][j] == '1' && s[i+1][j-1] == '1' )
                    cout << 'G' << endl;
                else;
                return;
            }
        }
    }
}

int main()
{
    char s[14][14];         //数字の間に区切りが無いからchar型で読み込む。大事。
    
    for( int k = 0; k < 50; k++ )
    {
        //初期化
        for( int i = 0; i < 14; i++ )
            for( int j = 0; j < 14; j++ )
                s[i][j] = 0;
        
        for( int i = 3; i < 11; i++ )
            for( int j = 3; j < 11; j++ )
                cin >> s[i][j];
            
        Select_Figure( s );
    }

    return 0;
}


Measured memory_bytes: 2988
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string S;
  int K;
  cin >> S >> K;
  set<string> SS;
  REP(i, S.size()) {
    REP(j, 5) {
      string T = "";
      REP(k, j+1) {
        if (i+k < S.size()) {
          T += S[i+k];  
        }
      }
      SS.insert(T);
    }
  }
 set<string>:: iterator it = SS.begin();
 advance(it, K-1);
 cout << *it << endl;

  return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}


vector<ll> fac(300001); //n!(mod MOD)
vector<ll> ifac(300001); //k!^{M-2} (mod MOD)
//a,bの範囲的にこれだけ配列を用意していけば十分
ll mpow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  fac[0] = 1;
  ifac[0] = 1;
  for(ll i = 0; i<300000; i++){
      fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod MOD)
      ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{MOD-2} (mod OD) ←累乗にmpowを採用
  }
  bool judge = true;
  ll n,k;cin>>n>>k;
  ll p=n-k;  
  for(i=1;i<=k;i++){
    ll a=comb(p+1,i)%MOD;
    ll b=comb(k-1,k-i)%MOD;
    qmod(res,a,b);
    cout<<res<<endl;
  }

  
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;

int main(){
    int n,t;cin>>n>>t;
    ll mini=mod;
    lol(i,n){
	ll a,b;cin>>a>>b;
	if(b<=t)mini=min(mini,a);
    }
    if(mini==mod)cout<<"TLE"<<endl;
    else cout<<mini<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>

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

int main() {
	
	while (1) {
		string x;
		cin >> x;
		if (x.size()==1&&x[0]=='0') break;
		int sum = 0;

		for (int i = 0; i < x.size(); i++) {
			sum += x[i] - '0';
		}
		cout << sum << endl;
	}

	return 0;
}


Measured memory_bytes: 3164
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265359

using namespace std;

/*ll powMod(ll a, ll y)
{
    ll ans = 1;
    
    while (y > 0) 
    { 
        if (y & 1) 
            ans = (ans*a) % MOD; 
  
        y = y>>1;
        a = (a*a) % MOD; 
    } 
    return ans;
}*/

/*ll modInv(ll a)
{
    return powMod(a, MOD-2);	
}*/

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> v(n);
    for (int &x : v)cin >> x;
    sort (v.begin(), v.end());
    ll sum = 0;
    for (int i = 0; i < k; i++) sum += v[i];
    cout << sum;
    return 0;
}




Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    
    int M = N;
    int sum = 0;
    while (M > 0) {
        sum += M % 10;
        M /= 10;
    }
    
    if (N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

typedef long long ll;

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

    ll n; cin >> n;
    vector<ll> x(n);
    for(ll i=0;i<n;i++) cin >> x[i];
    ll ans = 1LL << 60;
    for(ll i=-100000;i<100000;i++){
        ll sum = 0;
        for(ll j=0;j<n;j++){
            sum += (x[j]-i)*(x[j]-i);
        }
        ans = min(ans,sum);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* https://atcoder.jp/contests/abc101/tasks/arc099_a */

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

int solve(const int N, const int K, std::vector<int> &A)
{
  return (N - 1 + (K - 2))/(K - 1);
}

int main(int argc, char **argv)
{
  // Input
  int N, K;

  std::cin >> N >> K;

  std::vector<int> A(N);

  for (auto& e: A)
    std::cin >> e;

  // Output
  std::cout << solve(N, K, A) << std::endl;

  return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    set<int> a;
    int x, y, z;
    cin >> x >> y >> z;
    a.insert(x);
    a.insert(y);
    a.insert(z);

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

    return 0;
}

Measured memory_bytes: 3552
#[allow(dead_code)]
fn main() {
    let (n, m) = i::u2();
    let ab = i::uv2(n);
    let mut cost = Vec::new();
    let mut map: HashMap<usize, usize> = HashMap::new();
    for (a, b) in ab {
        if map.contains_key(&a.clone()) {
            *map.entry(a).or_insert(0) += b;
        } else {
            cost.push(a);
            map.insert(a.clone(), b);
        }
    }
    cost.sort();
    let mut ans = 0;
    let mut count = 0;
    for c in cost {
        let cc = map[&c];
        if count + cc < m {
            ans += cc * c;
            count += cc;
            continue;
        }
        ans += (m - count) * c;
        break;
    }
    println!("{}", ans);
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


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

void run() {
    int k;
    cin >> k;
    int x = 0;
    for (int i = 1; i <= 2000000; i++) {
        x = (x * 10 + 7) % k;
        if (x == 0) {
            cout << i << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    run();
    return 0;
}


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

int main() {
  int n,k,s; cin>>n>>k>>s;
  if(s!=1000000000){
    rep(i,k){cout<<s<<" ";}
    rep(i,n-k){cout<<s+1<<" ";}
  }
  else{
    rep(i,k){cout<<s<<" ";}
    rep(i,n-k){cout<<1<<" ";}
  }
}
     

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

using namespace std;


void solve() {
    int n; cin >> n;
    int x = (n+1)/2;
    cout << fixed<< setprecision(8) <<double(x)/n;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) cin >> B[i];
    sort(B.begin(), B.end());
    for (int i = 0; i < N; i++) cin >> C[i];
    sort(C.begin(), C.end());

    long long ans = 0;
    for (int i = 0; i < N; i++) {
        auto j = lower_bound(A.begin(), A.end(), B[i]);
        auto k = upper_bound(C.begin(), C.end(), B[i]);
        long long cnt = distance(A.begin(), j);
        cnt *= distance(k, C.end());
        ans += cnt;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4556
#include <iostream>
#include <vector>

int main()
{
    int n, q;
    std::string s;
    std::cin >> n >> q >> s;
    std::vector<int> cnt(n, 0);
    for (int i=1; i<n; ++i)
    {
        cnt[i] = cnt[i-1];
        if (s[i-1] == 'A' && s[i] == 'C')
        {
            cnt[i]++;
        }
    }
    std::vector<int> ans;
    for (int i=0; i<q; ++i)
    {
        int l, r;
        std::cin >> l >> r;
        l--; r--;
        ans.push_back(cnt[r] - cnt[l]);
    }
    for (int i: ans)
    {
        std::cout << i << std::endl;
    }
}

Measured memory_bytes: 1912
#include<stdio.h>
int main(void){
int H,W,i,t;
	for(;;){
		
		scanf("%d %d",&H,&W);
		if(H==0&&W==0){
			break;
		}
		for(i=1;i<=H;i++){
			for(t=1;t<=W;t++){
				if(i%2==1){
					if(t%2==1){
						printf("#");
					}else{
						printf(".");
					}
				}else{
					if(t%2==1){
						printf(".");
					}else{
						printf("#");
					}
				}
			}
			printf("\n");
		}
		printf("\n");
}
	
	return 0;
}

Measured memory_bytes: 2660
package main

import (
	"bufio"
	"fmt"
	"os"
	"strings"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var s string
	fmt.Fscan(r, &s)

	var st Stack
	for i := 0; i < len(s); i++ {
		if s[i] == '0' {
			st.push("0")
		} else if s[i] == '1' {
			st.push("1")
		} else if s[i] == 'B' {
			st.pop()
		}
	}

	fmt.Println(strings.Join(st, ""))
}

// Stack ...
type Stack []string

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i string) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (string, bool) {
	if s.empty() {
		return "", false
	}
	index := len(*s) - 1
	res := (*s)[index]
	*s = (*s)[:index]
	return res, true
}


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

using ll=long long;

void solve(long long a, long long b){
  if(a<b) swap(a,b);
  for(ll i=0;i<a;i++){
    cout<<b;
  }
  cout<<endl;
}

int main(){
  long long a;
  scanf("%lld",&a);
  long long b;
  scanf("%lld",&b);
  solve(a, b);
  return 0;
}


Measured memory_bytes: 256
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if j==0 or i==0 or j==W-1 or i==H-1:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()   



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

struct data {
  int x, y;
  bool operator<(const data& r) const {
    if(x != r.x) return x < r.x;
    return y < r.y;
  }
};

int d[4] = {0, 1, 0, -1};
int h1, h2, w1, w2;
vector<string> s1, s2;
vector<vector<bool>> b1, b2;
string mp = ".#";

bool isvalid(int h, int w, data now) {
  return now.x >= 0 && now.x < h && now.y >= 0 && now.y < w;
}
string solve(int& h, int& w, vector<vector<bool>>& b);
string dfs(int& h, int& w, vector<vector<bool>>& b,
           vector<vector<bool>>& used, data now);

int main() {
  while(1) {
    cin >> h1 >> w1;
    if(h1 + w1 == 0) break;
    s1.resize(h1 + 2);
    for(int i = 0; i < h1; ++i) cin >> s1[i];
    b1.assign(h1 + 2, vector<bool>(w1 + 2, 0));
    for(int i = 0; i < h1; ++i)
      for(int j = 0; j < w1; ++j)
        b1[i + 1][j + 1] = s1[i][j] == '#';
    cin >> h2 >> w2;
    s2.resize(h2);
    for(int i = 0; i < h2; ++i) cin >> s2[i];
    b2.assign(h2 + 2, vector<bool>(w2 + 2, 0));
    for(int i = 0; i < h2; ++i)
      for(int j = 0; j < w2; ++j)
        b2[i + 1][j + 1] = s2[i][j] == '#';
    h1 += 2;
    w1 += 2;
    h2 += 2;
    w2 += 2;
    if(solve(h1, w1, b1) == solve(h2, w2, b2))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }
  return 0;
}

string solve(int& h, int& w, vector<vector<bool>>& b) {
  vector<vector<bool>> used(h, vector<bool>(w, 0));
  //  string res = dfs(h, w, b, used, {0, 0});
  return dfs(h, w, b, used, {0, 0});
}
string dfs(int& h, int& w, vector<vector<bool>>& b,
           vector<vector<bool>>& used, data now) {
  string res = "(";
  res += mp[b[now.x][now.y]];
  vector<string> chil;
  set<data> to;
  queue<data> qu;
  qu.push(now);
  used[now.x][now.y] = 1;
  while(qu.size()) {
    now = qu.front();
    qu.pop();
    // black part
    if(b[now.x][now.y]) {
      for(int i = -1; i <= 1; ++i)
        for(int j = -1; j <= 1; ++j)
          if(i != j || i != 0) {
            data nextp = now;
            nextp.x += i;
            nextp.y += j;
            if(!isvalid(h, w, nextp) ||
               used[nextp.x][nextp.y])
              continue;
            if(b[nextp.x][nextp.y]) {
              used[nextp.x][nextp.y] = 1;
              qu.push(nextp);
            }
            else
              to.insert(nextp);
          }
    }
    // white part
    else {
      for(int i = 0; i < 4; ++i) {
        data nextp = now;
        nextp.x += d[i];
        nextp.y += d[1 ^ i];
        if(!isvalid(h, w, nextp) || used[nextp.x][nextp.y])
          continue;
        if(!b[nextp.x][nextp.y]) {
          used[nextp.x][nextp.y] = 1;
          qu.push(nextp);
        }
        else
          to.insert(nextp);
      }
    }
  }

  for(auto p : to)
    if(!used[p.x][p.y])
      chil.push_back(dfs(h, w, b, used, p));
  sort(chil.begin(), chil.end());
  for(auto& t : chil) res += t;
  return res + ")";
}


Measured memory_bytes: 3472
N = int(raw_input())

l = ['0']
count = 0

while l:
    s = l.pop()
    if N < int(s):
        continue
    if s[0] == '0':
        s = s[1:]
    count_3 = 0
    count_5 = 0
    count_7 = 0
    for i in s:
        if i == '3':
            count_3 += 1
        elif i == '5':
            count_5 += 1
        elif i == '7':
            count_7 += 1
    if len(s) == (count_3 + count_5 + count_7) and count_3 and count_5 and count_7:
        count += 1
    for j in '357':
        l.append(s+j)

print count


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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 1e5;

ll GCD(ll a, ll b)
{
    return b == 0 ? a : GCD(b, a % b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll a, b;
    cin >> a >> b;
    cout << a / GCD(a, b) * b;
    return 0;
}


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

int main () {
  int a , b , c ;
  cin >> a >> b >> c ;
  
  bool ans = false ;
  
  for( int i = 0 ; i < b ; i++ ) {
    if( a * i % b == c ) ans = true ;
  }
  
  if(ans) cout << "YES" << endl ;
  else cout << "NO" << endl ;
  
}

Measured memory_bytes: 256
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
P=[0]*(N+1)
for i in range(N):
    P[i+1]=P[i]+A[i]
    
H=set()
for i in range(N+1):
    for j in range(i+1,N+1):
        H.add(P[j]-P[i])
L=[i for i in H]
a=max(L)
s=len(bin(a))-2

K1=[0]*s
t=1<<(s-1)
A=L
for i in range(s):
    T=A
    A=[a for a in T if (a&t)!=0]
    if len(A)>=K:
        K1[i]=1
    else:
        A=T
    t=t>>1
ans=0
u=1<<(s-1)
for i in range(s):
    if K1[i]==1:
        ans+=u
    u=u>>1
print(ans)

Measured memory_bytes: 101600