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

#define rep(i,a,b) for(int i=a;i<b;i++)
typedef map<string, string> mss;
typedef pair<string, string> pss;

int solve(int n)
{
	mss translate;
	string from, to;
	rep(i, 0, n)
	{
		string a, b;
		cin >> a >> b;
		translate[a] = b;
	}
	cin >> from >> to;

	set<string> prev, next;
	prev.insert(from);
	rep(i, 1, 11)
	{
		for (pss p : translate) for (string s : prev)
		{
			string a = p.first, b = p.second;
			int index;
			string ss = "";
			while ((index = s.find(a)) != string::npos)
			{
				ss += s.substr(0, index);
				ss += b;
				s = s.substr(index + a.length());
			}
			ss += s;
			if (to == ss) return i;
			next.insert(ss);
		}

		prev = next;
		next = set<string>();
	}

	return -1;
}

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		cout << solve(n) << endl;
	}
}

Measured memory_bytes: 4192
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
G = [set() for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    G[A].add(B)
    G[B].add(A)

G_comp = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if i != j and j not in G[i]:
            G_comp[i].append(j)

color = [-1] * N
A = []
dp = set([0])
for i in range(N):
    if color[i] != -1:
        continue
    cnt = [1, 0]
    color[i] = 0
    stack = [i]
    while stack:
        v = stack.pop()
        for u in G_comp[v]:
            if color[u] == -1:
                color[u] = 1 - color[v]
                stack.append(u)
                cnt[color[u]] += 1
            if color[u] == color[v]:
                print(-1)
                exit()
    ndp = set()
    for a in dp:
        ndp.add(a + cnt[0])
        ndp.add(a + cnt[1])
    dp = ndp
ans = float('inf')
for a in dp:
    ans = min(ans, a * (a - 1) // 2 + (N - a) * (N - a - 1) // 2)
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> h(n);
  rep(i, n) cin >> h[i];

  /* しゃくとり法 */
  int ans = 0;
  int right = 1;  // [0, 1) は確実に条件を満たす
  for (int left = 0; left < n; ++left) {
    // right を 1 個進めたものが条件を満たすかどうか
    while (right < n && (right <= left || h[right - 1] >= h[right])) {
      ++right;
    }
    ans = max(ans, right - left - 1);
    if (left == right) ++right;
  }

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

Measured memory_bytes: 3724
import sys
input = lambda: sys.stdin.readline().rstrip()

from heapq import *

H, W = map(int, input().split())
m1 = lambda s: int(s)-1
sy, sx = map(m1, input().split())
fy, fx = map(m1, input().split())
G = [list(input()) for _ in range(H)]
D = [[10 ** 18] * W for _ in range(H)]

D[sy][sx] = 0
Q = [(0, sx, sy)]
while Q:
	d, x, y = heappop(Q)
	if D[y][x] < d: continue

	if (x, y) == (fx, fy):
		print(d)
		break

	for dx in range(-2, 3):
		for dy in range(-2, 3):
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= W or ny >= H or G[ny][nx] == '#': continue
			nd = d + (0 if abs(dx) + abs(dy) == 1 else 1)
			if nd >= D[ny][nx]: continue
			D[ny][nx] = nd
			heappush(Q, (nd, nx, ny))
else:
	print(-1)


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

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

vector<vector<int>> As;

// current_a: A_1, A_2, ..., A_(N - remain)
// remain: 残りの数
void dfs(const vector<int>& current_a, const int remain, const int &max) {
  if (remain == 0) {
    As.push_back(current_a);
    return;
  }

  int min = 1;
  if (not current_a.empty()) min = current_a.back();

  for (int i = min; i <= max; ++i) {
    vector<int> next_a(current_a.begin(), current_a.end());
    next_a.push_back(i);
    dfs(next_a, remain - 1, max);
  }
}

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

  // 与えられた関数は、x が B の倍数であるとき 0 となり、B 周期で単調非減少となる。
  // https://i.imgur.com/q1o6p6I.png
  // そのため、x が B - 1 以上の任意の整数を取れる場合、x = B - 1 とするのが最適である。
  // N が B - 1 未満の場合は、x = N とするのが最適である。

  long x = B - 1;
  if (x > N) x = N;

  cout << (A * x / B) - A * (x / B) << endl;
}


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

using namespace std;

#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'

mt19937 rng((int) chrono::steady_clock::now().time_since_epoch().count());

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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int main(){ _
	int n, m, x;
	cin >> n >> m >> x;
	vector<int> c(n);
	vector<vector<int>> a(n, vector<int>(m));
	for (int i = 0; i < n; i++){
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	int ans = INF;
	for (int mask = 0; mask < (1 << n); mask++){
		int cost = 0;
		vector<int> sum(m, 0);
		for (int i = 0; i < n; i++) if (mask&(1 << i)){
			cost += c[i];
			for (int j = 0; j < m; j++) sum[j] += a[i][j];
		}
		bool ok = true;
		for (int j = 0; j < m; j++)
			ok &= (sum[j] >= x);
		if (ok) ans = min(ans, cost);
	}
	if (ans == INF) ans = -1;
	cout << ans << endl;
	
	exit(0);
}


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

int main() {
    int n, m;
    cin >> n >> m;
    ll sum = 0;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        sum += x;
    }
    if (sum > n) cout << -1 << endl;
    else cout << n - sum << endl;
}


Measured memory_bytes: 3636
import sys
input = sys.stdin.readline

def solve(init: int, K: int, acc: int):
    while abs(init - K) < init:
        init = abs(init - K)
    return init

    # temp = abs(init - K)
    # if temp > acc:
    #     return init
    # else:
    #     return solve(temp, K, temp)



def main():
    N, K = map(int, input().rstrip().split())
    N -= K * (N  // K)
    res = solve(N, K, N)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
n = int(input())
s = [input()for _ in range(n)]
alp = [chr(ord('a')+i)for i in range(26)]
cnt = [10**9]*26
for i in range(26):
    for x in s:
        cnt[i] = min(cnt[i],x.count(alp[i]))

ans = ""
for i in range(26):
    ans += alp[i]*cnt[i]
print(ans)   
    

Measured memory_bytes: 3060
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();

        boolean ret = solver(str);
        System.out.println(ret ? "Yes" : "No");
        return;
    }

    private static boolean solver(String s) {
        int sn = s.chars().map(c -> c - '0').sum();
        int n = Integer.parseInt(s);
        return n % sn == 0;
    }
}

Measured memory_bytes: 27604
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pi 3.14159265358979323846264
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define vi vector <int>
#define vl vector <long long>
#define vpii vector <pair <int, int> >
#define ll long long
#define fi first
#define se second
ll a, b;
int cnt;
int main() {
    cin >> a >> b;
    while (a <= b) {
        a *= 2;
        cnt++;
    }
    printf("%d\n", cnt);
    return 0;    
}

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

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

	int min_num = 1000;
	int max_num = 0;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a.at(i);
		min_num = min({ min_num,a.at(i) });
		max_num = max({ max_num,a.at(i) });
	}

	cout << max_num - min_num << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n; cin >> n;
    map<ll,int> ma;
    rep(i,n){
        int a; cin >> a;
        ma[-a]++;
    }
    vector<ll> big;
    ll ans = 0;
    auto itr = ma.begin();
    if(itr->second >= 4){
        ans = itr->first * itr->first;
        cout << ans << endl;
        return 0;
    }
    for(auto elem : ma){
        ll key = -1 * elem.first;
        int value = elem.second;
        if(value >= 2) big.push_back(key);
        if(big.size() == 2) break;
    }
    if(big.size() < 2){
        cout << 0 << endl;
        return 0;
    }
    ans = big[0] * big[1];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9840
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <set>
#define F first
#define S second
using namespace std;

int n, s;
set<int> b;
struct st {
	int c1, c2, z;
} a[205];

bool comp(st p, st q) {
	return p.c1 < q.c1;
}
int main()
{
	int i;
	set<int>::iterator it;
	cin >> n;
	for (i = 0; i < n * 2; i++) {
		scanf ("%d %d", &a[i].c1, &a[i].c2);
		a[i].z = i;
	}
	sort(a, a + n * 2, comp);
	for (i = 0; i < n * 2; i++) {
		if (a[i].z < n) {
			b.insert(a[i].c2);
		} else {
			it = b.lower_bound(a[i].c2);
			if (it != b.begin()) {
				it--;
				b.erase(it);
				s++;
			}
		}
	}
	cout << s;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
//    val mod = 1000000007L
    val mod = 2019
//    val N = readLine()!!.toInt()
    val (A,B) = readLine()!!.split(" ").map(String::toLong)
    var ans = "IMPOSSIBLE"

    for (k in 0..Math.max(A,B)) {
        if (Math.abs(A-k) != Math.abs(B-k)) continue
        ans = "$k"
        break
    }
    println(ans)
}

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

signed main(){

  int n,k; cin >> n >> k;

  static int dp[101010][21]; //iが最大でj個の集合の数
  for(int i = 1; i <= n; i++) dp[i][1] = 1;
  for(int i = 2; i <= n; i++){
    for(int j = 1; j*j <= i; j++){
      if(i%j == 0){
        for(int k = 1; k < 20; k++){
          dp[i][k+1] += dp[j][k];
          if(j*j == i || j == 1) continue;
          dp[i][k+1] += dp[i/j][k];
        }
      }
    }
  }

  int ans = 0;
  for(int i = 1; i <= n; i++){
    ans += dp[i][k];
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 19304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;


int N, C;
int s[100010],t[100010], c[100010];
vector<pair<int, int>> st[33];
// vector<int> S[33];
// vector<int> T[33];
int imos[32][200010];

int main(void) {
	cin >> N >> C;
	rep(i, N) cin >> s[i] >> t[i] >> c[i];
	rep(i, N) c[i]--;
	rep(i, N) {
		// S[c[i]].pb(s[i]), T[c[i]].pb(t[i]);
		st[c[i]].pb(mp(s[i], t[i]));
	}
	rep(i, C) sort(all(st[i]));

	rep(i, C) {
		rep(j, st[i].size()) {
			if(j > 0 && st[i][j].fi == st[i][j - 1].se) imos[i][st[i][j - 1].se * 2] = 0;
			else imos[i][st[i][j].fi * 2 - 1]++;
			imos[i][st[i][j].se * 2]--;
		}
	}

	/*
	rep(i, C){
		rep(j, 20) printf("%d ", imos[i][j]);
		printf("\n");
	}
	*/
	

	rep(i, C)rep(j, 200000) imos[i][j + 1] += imos[i][j];

	/*
	printf("\n");
	rep(i, C){
		rep(j, 20) printf("%d ", imos[i][j]);
		printf("\n");
	}
	*/

	ll ans = 0;
	rep(j, 200010){
		ll tmp = 0;
		rep(i, C) tmp += imos[i][j];
		chmax(ans, tmp);
	}

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

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

int main() {
  int W[10], K[10];
  for (int i = 0; i < 10; i++) cin >> W[i];
  for (int i = 0; i < 10; i++) cin >> K[i];
  sort(W, W + 10, greater<int>());
  sort(K, K + 10, greater<int>());
  cout << W[0] + W[1] + W[2] << " " << K[0] + K[1] + K[2] << endl;
  return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
int memo[N];
bool vis[N];
vector<int> g[N];

int dp(int u){
	if(vis[u]) return memo[u];
	int ans=0;
	for(auto v: g[u]){
	    ans=max(ans, dp(v) + 1);
	}
	vis[u]=true;
	return memo[u]=ans;
}

int main() {
    int n,m;
	cin>>n>>m;
	int a,b;
	for(int i=0;i<m;i++){
		cin>>a>>b;
		g[a].push_back(b);
	}
	int res=0;
	for(int i=1;i<=n;i++){
	    res=max(res,dp(i));
	}
	cout<<res<<"\n";
	return 0;
}



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

int main() {
  int ans=0;
  vector<int> vec(5);
  rep(i,5){
    cin>>vec[i];
    ans+=(vec[i]+9)/10*10;
  }
  int cnt=1e9;
  bool as=false;
  rep(i,5){
    if(vec[i]%10!=0){
      cnt=min(cnt,vec[i]%10);
      as=true;
  }
  }
    if(as)cout<<ans-10+cnt<<endl;
  else cout<<ans<<endl;
}

Measured memory_bytes: 3608
import numpy as np
import sys
# import copy


def xnxn(n=0, flag="v"):
    """
    args:
        int n: a number of lows to read
    example:
        input   1
        retrun  1

        input   1 2 3
        return  [1,2,3]
        input   1 2 3
                4
        return  [[1,2,3],
                [4]]
    """
    if n == 0:
        temp = list(map(int, input().split()))
        if len(temp) == 1:
            if flag == "l":
                return temp
            else:
                return temp[0]
        elif len(temp) > 1:
            return temp
    else:
        temp = [list(map(int, input().split())) for _ in range(n)]
        return temp


a, v = xnxn()
b, w = xnxn()
t = xnxn()


# for i in range(t):
#     if b - a > 0:
#         b = min(b + w, 10 ** 9)
#         a = min(a + v, 10 ** 9)
#         if b == a:
#             print("YES")
#             sys.exit()
#     elif b - a < 0:
#         b = max(b - w, 10 ** 9)
#         a = max(a - v, 10 ** 9)
#         if b == a:
#             print("YES")
#             sys.exit()

# print("NO")

if b - a > 0:
    # b_f = min(b+t*w, 10 ** 9)
    # a_f = min(a + t * v, 10 ** 9)
    b_f = b+t*w
    a_f = a+t*v
    if b_f > a_f:
        print("NO")
    else:
        print("YES")


else:
    # b_f = max(b-t*w, -10 ** 9)
    # a_f = max(a-t*v, -10 ** 9)
    b_f = b-t*w
    a_f = a-t*v

    if b_f < a_f:
        print("NO")
    else:
        print("YES")


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

bool is_prime(int n)
{
    if (n == 0 || n == 1)
        return (false);
    if (n % 2 == 0 && n != 2)
        return (false);
    for (int i = 3; i * i < n + 1; i += 2)
    {
        if (n % i == 0)
        {
            return (false);
        }
    }
    return (true);
}

int main()
{
    int n, q;
    string s;
    cin >> n >> q >> s;
    vector<int> cum(n + 1, 0);
    for (int i = 0; i < n - 1; i++)
    {
        if (s.substr(i, 2) == "AC" && i < n - 1)
        {
            cum[i + 2] = cum[i + 1] + 1;
        }
        else
        {
            cum[i + 2] = cum[i + 1];
        }
    }

    for (int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        cout << cum[r] - cum[l] << '\n';
    }

    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include<string>
#include<algorithm>
#include<vector>
 
using namespace std;
 
int main() 
{
int q,n,l,r;
string s;
vector<int>f;
 
cin>>n>>q;
cin>>s;
int cnt=0;
int j; 
	for(j=0;j<n;)
	{
					if(s[j]=='A' && s[j+1]=='C')
					{
						cnt+=1;
						f.push_back(cnt-1);
												f.push_back(cnt);
												j= j + 2;
					}
					else{
						f.push_back(cnt);
						j  = j +1;
					}
			}
			

for(int i=j;i<n+1;i++)
{
f.push_back(cnt);
}
	
 
for(int i=0;i<q;i++)
{
	cin>>l>>r;
	cout<<f[r-1]-f[l-1]<<endl;
}
 
 
}

Measured memory_bytes: 1528
open System
open System.Collections.Generic

module InputUtility =
    let InputTokens = new Queue<string>()

    let EnsureInput () =
        if InputTokens.Count = 0 then
            let input = Console.ReadLine ()
            let s = input.Split ([|' '|], StringSplitOptions.RemoveEmptyEntries)
            if s.Length > 0 then
                for x in s do InputTokens.Enqueue(x)
                true
            else false
        else true

    let rec ReadNext () =
        if EnsureInput () then InputTokens.Dequeue ()
        else ReadNext ()

    let ReadNextInt () = ReadNext () |> int

    let Read2Int () = ReadNextInt (), ReadNextInt ()

    let Read3Int () = ReadNextInt (), ReadNextInt (), ReadNextInt ()

    let ReadListOf f n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop ((ReadNext () |> f) :: acc) (c-1)
        loop [] n

    let MultipleCaseWithId f =
        let caseNum = ReadNextInt ()
        let rec loop index =
            if index = caseNum then ()
            else
                f index
                loop (index + 1)
        loop 0

    let MultipleCase f = MultipleCaseWithId (fun _ -> f ())

    let ReadList n =
        let rec loop acc = function
            | 0 -> List.rev acc
            | c -> loop (ReadNext () :: acc) (c-1)
        loop [] n

open InputUtility

module AGC017 =
    let private Biscuits () =
        let md = 2
        let n, p = Read2Int ()
        let rec loop (f: _ array) (g: _ array) = function
            | [] -> f.[p]
            | h :: t ->
                let b = h % md
                for i in [0..md-1] do
                    g.[i] <- f.[i]
                for i in [0..md-1] do
                    let nb = (i + b) % md
                    g.[nb] <- g.[nb] + f.[i]
                //printfn "%d: %A" h g
                loop g f t
        let gv () = Array.init md (fun i -> if i = 0 then 1L else 0L)
        loop (gv ()) (gv ()) (ReadListOf int n)
        |> printfn "%d"

    let Entry = Biscuits

AGC017.Entry ()

Measured memory_bytes: 12240
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc *bufio.Scanner
var out *bufio.Writer

const INF = 1 << 30

func main() {
	sc = bufio.NewScanner(os.Stdin)
	//bytes, _ := ioutil.ReadFile("./stdin.txt")
	//sc = bufio.NewScanner(strings.NewReader(string(bytes)))
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1<<20)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	N, K, L := nextInt3()
	G1 := make([][]int, N+1)
	G2 := make([][]int, N+1)
	for i := 0; i < K; i++ {
		p, q := nextInt2()
		G1[p] = append(G1[p], q)
		G1[q] = append(G1[q], p)
	}
	for i := 0; i < L; i++ {
		r, s := nextInt2()
		G2[r] = append(G2[r], s)
		G2[s] = append(G2[s], r)
	}
	group1 := make([]int, N+1)
	id := 1
	for i := 1; i < len(group1); i++ {
		if group1[i] == 0 {
			dfs(G1, group1, i, id)
			id++
		}
	}
	group2 := make([]int, N+1)
	id = 1
	for i := 1; i < len(group2); i++ {
		if group2[i] == 0 {
			dfs(G2, group2, i, id)
			id++
		}
	}
	cnt := make([]map[int]int, N+1)
	for i := 1; i < N+1; i++ {
		cnt[i] = make(map[int]int)
	}
	for i := 1; i < N+1; i++ {
		cnt[group1[i]][group2[i]]++
	}
	for i := 1; i <= N; i++ {
		fmt.Fprint(out, cnt[group1[i]][group2[i]])
		if i != N {
			fmt.Fprint(out, " ")
		} else {
			fmt.Fprintln(out, "")
		}
	}
}

func dfs(G [][]int, group []int, u, id int) {
	group[u] = id
	for e := 0; e < len(G[u]); e++ {
		v := G[u][e]
		if group[v] == 0 {
			dfs(G, group, v, id)
		}
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}
func nextInt2() (int, int)      { return nextInt(), nextInt() }
func nextInt3() (int, int, int) { return nextInt(), nextInt(), nextInt() }
func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func cond(condition bool, t, f int) int {
	if condition {
		return t
	}
	return f
}
func abs(a int) int { return cond(a < 0, -a, a) }
func min(a ...int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		chmin(&ret, a[i])
	}
	return ret
}
func max(a ...int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		chmax(&ret, a[i])
	}
	return ret
}
func chmin(a *int, b int) { *a = cond(*a < b, *a, b) }
func chmax(a *int, b int) { *a = cond(*a > b, *a, b) }


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

using namespace std;

void Main() {
    string S;
    cin >> S;

    int ans = 1000;
    for (int i = 0; i < S.size() - 2; ++i) {
        int lunlun = atoi(S.substr(i, 3).c_str());
        ans = min(ans, abs(lunlun - 753));
    }
    cout << ans << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

vector<bool> num(1000001);

void calc0(int n, vector<int>& yakusuu)
{
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			yakusuu.push_back(i);
			if (i * i != n) {
				yakusuu.push_back(n / i);
			}
		}
	}
	sort(yakusuu.begin(), yakusuu.end());
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a.at(i);
	}

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

	int ans = 0;
	for (int i = 0; i < a.size(); i++) {
		if (i != a.size() - 1 && a.at(i) == a.at(i + 1)) {
			num.at(a.at(i)) = true;
			continue;
		}
		vector<int> yakusuu;
		calc0(a.at(i), yakusuu);
		bool flag = true;
		for (auto yakusuu_ele : yakusuu) {
			if (num.at(yakusuu_ele) == true) {
				flag = false;
				break;
			}
		}
		if (flag == true) {
			ans++;
		}
		num.at(a.at(i)) = true;
	}

	cout << ans << endl;
}


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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  ll N, X, M;
  cin >> N >> X >> M;

  map<ll, pair<ll, ll>> seen;
  ll ans = 0;
  ll turn = 0;
  while (N) {
    if (seen.count(X)) {
      ll dist = turn - seen[X].first;
      ll times = N / dist;
      N %= dist;
      ans += (ans - seen[X].second) * times;
    }
    if (N) {
      seen[X] = {turn++, ans};
      ans += X;
      X = X * X % M;
      N--;
    }
  }

  cout << ans;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

Measured memory_bytes: 6708
n = int(input())
trump = input().split()

def bubbleSort(trump, n):
    c = trump[::]
    for i in range(n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]
    print(' '.join(c))
    print('Stable')
    return c

def selectionSort(trump, n):
    c = trump[::]
    for i in range(n):
        minj = i
        for j in range(i+1, n):
            if int(c[j][1]) < int(c[minj][1]):
                minj = j
        c[i], c[minj] = c[minj], c[i]
    print(' '.join(c))
    return c

if bubbleSort(trump, n) == selectionSort(trump, n):
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5608
#include <stdio.h>
#define N 1000001

int Partition(int, int );
int A[N];

int main(void){
int i,n,y;
 
 scanf("%d",&n);

 for(i=1;i<=n;i++){
   scanf("%d",&A[i]);
 }
 
 y=Partition(1,(n));
 
 for(i=1;i<n;i++){

   if (i==y){
     printf("[%d] ",A[i]);
   }
   else printf("%d ",A[i]);
 }
 
 printf("%d\n",A[n]);
 
 return 0;
 
}

int Partition(int p, int r){
  int i, j, x, k;
  
  x=A[r];
  i=p-1;
  for(j=p;j<=r-1;j++){

    if(A[j]<=x){
      i++;      
      k=A[i];
      A[i]=A[j];
      A[j]=k; 
    }

  }
  k=A[i+1];
  A[i + 1] = A[r];
  A[r]=k;
  return i+1;
  
}

Measured memory_bytes: 988
#include<bits/stdc++.h>
	using namespace std;
	#define ll long long int 
	#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	char b[7][7];
	char a[7][7];
	int n,m,k;

	void copy_array()
	{
		for (int i = 0; i < n; ++i)
		{
		   for(int j=0;j<m;j++)
		   {
		   		b[i][j]=a[i][j];
		   }
		}
	}

	void color(int i,int j)
	{

		for(int k=0;k<n;k++)
		{
			if(i&(1<<k))
			{
				for(int j=0;j<m;j++)
				{
					b[k][j]='$';
				}
			}
		}

		for(int k=0;k<m;k++)
		{
			if(j&(1<<k))
			{
				for(int x=0;x<n;x++)
				{
					b[x][k]='$';
				}
			}
		}
	}
bool check()
{	
	int count=0;
	for (int i = 0; i <n; ++i)
		{
			for (int j = 0; j <m; ++j)
			{
				 if(b[i][j]=='#')
				 	count++;

			}
		}
		if(count==k)
			return true;
		return false;
}


	int main()
	{
		fastio;
		
		cin>>n>>m>>k;
		
		for (int i = 0; i < n; ++i)
		{
		   for(int j=0;j<m;j++)
		   {
		   		cin>>a[i][j];
		   }
		}

  		ll total=0;


		
		for (int i = 0; i <(1<<n); ++i)
		{
			for (int j = 0; j <(1<<m); ++j)
			{
				 copy_array();
				 color(i,j);
				 if(check())
				 	total++;

			}
		}

		cout<<total;
		return 0;
	}





Measured memory_bytes: 3644
#include<iostream>

using namespace std;

int main()
{
  int n;
  cin>>n;
  int a[100];
  for (int i=1;i<=n;i++){
        cin>>a[i];
  }
  for (int i=n;i>1;i--){  
      cout<<a[i]<<" ";
  }
  cout<<a[1]<<endl;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>


typedef long long ll;


ll f(ll n);

ll *mem, *inp, N;

int main()
{
    ll i, dist1, dist2;
    scanf("%lld", &N);

    mem =(ll*) malloc(N * sizeof(ll));
    inp =(ll*) malloc(N * sizeof(ll));

    for(i = 0; i<N; ++i){
        scanf("%lld", inp+i);
    }

    *(mem+N-2) = llabs(*(inp+N-2) - *(inp+N-1));
    //printf("%lld: %lld\n", N-2,*(mem+N-2));
    if(N>2){
        *(mem+N-3) = llabs(*(inp+N-3) - *(inp+N-1));
        //printf("%lld: %lld\n", N-3, *(mem+N-3));

        for(i = N-4; i>=0; --i){
            dist1 = llabs(*(inp+i) - *(inp+i+1)) + *(mem+i+1);
            dist2 = llabs(*(inp+i) - *(inp+i+2)) + *(mem+i+2);

            if (dist1<dist2) *(mem+i) = dist1;
            else *(mem+i) = dist2;

            //printf("%lld: %lld, d1: %lld, d2 %lld\n", i, *(mem+i), dist1, dist2);
        }
    }

    printf("%lld\n", *mem);

    return 0;
}




Measured memory_bytes: 1792
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    val h = (0 until n).map { sc.next().toLong() }

    println(problem136c(n, h))
}

fun problem136c(n: Long, h:List<Long>): String {
    var max = 0L
    h.forEachIndexed { i, hi ->
        if (i == 0) return@forEachIndexed
        max = Math.max(h[i - 1].toDouble(), max.toDouble()).toLong()
        if (hi + 1 < max) {
            return "No"
        }
    }
    return "Yes"
}

Measured memory_bytes: 49748
import Data.List

--zeros = listArray ('a', 'z') (repeat 0)

count :: String -> [(Char, Int)]
count = map (\cs -> (head cs, length cs)). group . sort

minCount :: [(Char, Int)] -> [(Char, Int)] -> [(Char, Int)]
minCount [] _ = []
minCount _ [] = []
minCount (hd1 : tl1) (hd2 : tl2)
  | fst hd1 == fst hd2 = (fst hd1, min (snd hd1) (snd hd2)) : minCount tl1 tl2
  | fst hd1 < fst hd2 = minCount tl1 (hd2 : tl2)
  | otherwise = minCount (hd1 : tl1) tl2

main = do
  (tail . lines) <$> getContents >>=
    putStrLn . concatMap (uncurry (flip replicate)) . foldl1 minCount . map count



Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1e9+7LL;

int main() {
    string S; cin >> S;
    int cnt = 0;
    rep(i, 3){
        if(S.at(i)=='R') cnt++;
    }
    if(cnt==2 && S.at(1)=='S') cnt = 1;
    cout << cnt << endl;
}

Measured memory_bytes: 3596
#include<stdio.h>

int main()
{
    long long n, temp, sum=0;
    scanf("%lld", &n);
    temp=n;
    while(temp!=0)
    {
        sum+=(temp%10);
        temp/=10;
    }
    if(n%sum==0)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 128
using System;
using System.Linq;

public class AtCoder_155_B
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        bool isOK = true;

        for (int i = 0; i < n; i++)
        {
            if (a[i] % 2 == 0)
            {
                if (a[i] % 3 != 0 && a[i] % 5 != 0)
                {
                    isOK = false;
                }
            }
        }

        if (isOK)
        {
            Console.WriteLine("APPROVED");
        }
        else
        {
            Console.WriteLine("DENIED");
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>

using namespace std;

int main() {
    int n, ans = 1;
    cin >> n;
    int count = 0;
    for (int i = 1; i <= n; i++) {
        int tmp = i;
        int c =0;
        while (tmp % 2 == 0 && tmp > 0) {
            c++;
            tmp /= 2;
        }
        if (count < c)  {
            ans = i;
            count = c;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner keyboardScanner=new Scanner(System.in);
		int a=keyboardScanner.nextInt();
		int b=keyboardScanner.nextInt();
		if((a*b)%2==0) {System.out.println("No");
	}else {System.out.println("Yes");}
}
}

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

int main(){
    int d, n;
    cin >> d >> n;

    int ans = 1;
    for(int i = 0; i < d; i++)  ans *= 100;

    if(n == 100) ans *= n+1;
    else         ans *= n;

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

Measured memory_bytes: 256
#include<string.h>
#include<iostream>

int n, k;
int dp[101][4][2];
int pasta[101];

int main()
{
	std::cin >> n >> k;
	for( int i = 0; i < k; i++ ){
		int a, b;
		std::cin >> a >> b;
		pasta[a] = b;
	}
	
	if( pasta[1] ){
	 	dp[1][pasta[1]][0] = 1; 
	}
	else{
		dp[1][1][0] = dp[1][2][0] = dp[1][3][0] = 1; 
	}
	
	for( int i = 2; i <= n; i++ ){
		if( !pasta[i] ){
		 	dp[i][1][0] = ( dp[i-1][2][0] + dp[i-1][2][1] + dp[i-1][3][0] + dp[i-1][3][1] ) % 10000;
			dp[i][1][1] = dp[i-1][1][0];
			dp[i][2][0] = ( dp[i-1][1][0] + dp[i-1][1][1] + dp[i-1][3][0] + dp[i-1][3][1] ) % 10000;
			dp[i][2][1] = dp[i-1][2][0];
			dp[i][3][0] = ( dp[i-1][1][0] + dp[i-1][1][1] + dp[i-1][2][0] + dp[i-1][2][1] ) % 10000;
			dp[i][3][1] = dp[i-1][3][0];
		}
		else{
			for( int j = 1; j <= 3; j++ ){
				if( j != pasta[i] ) dp[i][pasta[i]][0] += ( dp[i-1][j][0] + dp[i-1][j][1] ) % 10000;
			}
			dp[i][pasta[i]][1] = dp[i-1][pasta[i]][0];
		}
	}
	
	std::cout << ( dp[n][1][0] + dp[n][1][1] + dp[n][2][0] + dp[n][2][1] + dp[n][3][0] + dp[n][3][1] ) % 10000 << std::endl;

 	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(long long int i=a; i<b; i++ )
#define REP(i,n) rep(i,0,n)
 
int main(){
  double R; cin >> R;
  cout << 2.0*R*M_PI <<endl;
  return 0;
}

Measured memory_bytes: 3776
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;

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

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

int H, W;
char B[Maxn][Maxn];
char upd[Maxn][Maxn];
ll res;

ii Get(int r, int c, char ex)
{
    if (r < 0 || r >= H || c < 0 || c >= W || upd[r][c] != ex) return ii(0, 0);
    upd[r][c] = '?';
    ii res = B[r][c] == '#'? ii(1, 0): ii(0, 1);
    for (int i = 0; i < Maxd; i++) {
        ii got = Get(r + dy[i], c + dx[i], ex);
        res.first += got.first;
        res.second += got.second;
    }
    return res;
}

int main()
{
    scanf("%d %d", &H, &W);
    for (int i = 0; i < H; i++) {
        scanf("%s", B[i]);
        for (int j = 0; j < W; j++)
            if ((i + j) % 2) upd[i][j] = B[i][j] == '#'? '.': '#';
            else upd[i][j] = B[i][j];
    }
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++) if (upd[i][j] != '?') {
            ii got = Get(i, j, upd[i][j]);
            res += ll(got.first) * got.second;
        }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 13056
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import sys

input = sys.stdin.readline

def main():
    A = int(input())
    B = int(input())
    if A > B:
        print("GREATER")
    elif A < B:
        print("LESS")
    else:
        print("EQUAL")

main()


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

int main() {
  int N, K;
  cin >> N >> K;
  int s = 1;
    for (int i = 0; i < N; i++){
      if (s <= K)
        s *= 2;
      else
        s += K;
    }
	cout << s << endl;

}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
#define DEBUG_MODE
#define endl '\n'
#ifdef DEBUG_MODE
#define DEBUG(X) debug_func(X, #X)
#define DEBUG_ENDL endl
#define DEBUG_SEPARATOR_LINE cout<<"=================\n"
#else
#define DEBUG(X) 0
#define DEBUG_ENDL 0
#define DEBUG_SEPARATOR_LINE 0
#endif
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
#define DEBUG_ENDL_S(S) ((S).size() ? "\n" : "")
template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename Head, typename... Tail> const Head& var_min(const Head &head, const Tail&... tail) { return min(head, var_min(tail...)); }
template <typename Head, typename... Tail> const Head& var_max(const Head &head, const Tail&... tail) { return max(head, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
void debug_func_preffix(const string &s) { if(s.size()) cout << s << " = "; }
template <typename T>
void debug_func(const T &t, const string &s = "") {
    debug_func_preffix(s);
    cout << t << DEBUG_ENDL_S(s);
}
template <typename T, typename U>
void debug_func(const P<T, U> &p, const string &s = "") {
    debug_func_preffix(s);
    cout << "(";
    debug_func(p.first);
    cout << ", ";
    debug_func(p.second);
    cout << ")" << DEBUG_ENDL_S(s);
}
template <typename T>
void debug_func(const V<T> &v, const string &s = "") {
    for(ll i = 0; i < v.size(); i++) {
        string t = s + "[" + to_string(i) + "]";
        debug_func(v[i], t);
    }
}

int main() {
    string S;
    cin >> S;
    ll cnt0 = 0, cnt1 = 0;
    string s1, s2;
    for(ll i = 0; i < S.size(); i++) {
        s1 += (i == 0 ? '0' : '1');
        s2 += (i == 0 ? '1' : '0');
        cnt0 += (S[i] == '0');
        cnt1 += (S[i] == '1');
    }
    if(s1 == S || s2 == S) cout << 0 << endl;
    else cout << 2 * min(cnt0, cnt1) << endl;
    return 0;
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    ld A, B, H, M;
    cin >> A >> B >> H >> M;
    ld rad = ((M/60.0) - (H/12.0 + M/720) )*(2.0*3.141592653589793238);
    coutd(12) << std::sqrt(A*A + B*B - 2*A*B*std::cos(rad)) << endl;
}

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

// #define int long long
#define rep(i, n) for (ll i = (ll)(0); i < (ll)(n); ++i)
#define reps(i, n) for (ll i = (ll)(1); i <= (ll)(n); ++i)
#define rrep(i, n) for (ll i = ((ll)(n)-1); i >= 0; i--)
#define rreps(i, n) for (ll i = ((ll)(n)); i > 0; i--)
#define irep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define ireps(i, m, n) for (ll i = (ll)(m); i <= (ll)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) ll(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e15;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n,k; 
vll a;

bool isOk(ll mid){
  ll cnt=0;
  rep(i,n-1){
    if(a[i]>0){
      if(a[i]*a[i+1]>mid) continue;
      ll ok=i+1,ng=n;
      while(abs(ok-ng)>1){
        ll imid=(ok+ng)/2;
        if(a[i]*a[imid]<=mid) ok=imid;
        else ng=imid;
      }
      cnt+=ok-i;
    }else if(a[i]<0){
      if(a[i]*a[n-1]>mid) continue; // a[i]<0 ならば、掛ける値は大きい方が積は小さくなるため
      ll ok=n-1, ng=i;
      while(abs(ok-ng)>1){
        ll imid=(ok+ng)/2;
        if(a[i]*a[imid]<=mid) ok=imid;
        else ng=imid;
      }
      cnt+=n-ok;
    }else{
      if(mid>=0){
        cnt+=n-i-1;
      }
    }
  }
  return cnt>=k;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n>>k;
  a.resize(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ok=1e18, ng=-1e18-1;
  while(abs(ok-ng)>1){
    ll mid=(ok+ng)/2;
    if(isOk(mid)) ok=mid;
    else ng=mid;
  }
  cout<<ok<<endl;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 24 20:50:58 2019

@author: Yamazaki Kenichi
"""

N,Q = map(int,input().split())
S = input()
A = [list(map(int,input().split())) for i in range(Q)]

res = [0]
flg = False
for c in S:
    if flg:
        if c == 'C':
            res.append(res[-1]+1)
            flg = False
        elif c == 'A':
            res.append(res[-1])
        else:
            res.append(res[-1])
            flg = False
    elif c == 'A':
        res.append(res[-1])
        flg = True
    else:
        res.append(res[-1])
#    print(c,res)
for a in A:
    print(res[a[1]]-res[a[0]])


Measured memory_bytes: 30656
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main(){
    int d, n; cin >> d >> n;
    if(d == 0){
        if(n == 100)cout << 101 << endl;
        else cout << n << endl;
    }
    if(d == 1){
        if(n == 100)cout << 10100 << endl;
        else cout << n * 100 << endl;
    }
    if(d == 2){
        if(n == 100)cout << 1010000 << endl;
        else cout << n * 10000 << endl;
    }
}

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

int main(){
  int n;
  string s,ans;

  while(1){
    cin>>n;
    if(n==0) break;
    cin>>s;

    for(int i=0;i<n;i++){
      int k=0;
      int count=0;
      for(int j=1;j<s.size();j++){

	if(count==0&&s[j]==s[j-1]) count+=2;
	else if(s[j]==s[j-1])count++;

	if(j==s.size()-1&&count!=0&&s[j-1]==s[j]){
	  if(count<10)ans+=(count+'0');
	  else if(10<=count&&count<100){
	    ans+=(count/10+'0');
	    ans+=(count%10+'0');
	  }else if(count==100){
	    ans+='1';
	    ans+='0';
	    ans+='0';
	  }
	  ans.push_back(s[j]);
	  count=0;
	}else if(j==s.size()-1&&count!=0&&s[j-1]!=s[j]){
	  if(count<10)ans+=(count+'0');
	  else if(10<=count&&count<100){
	    ans+=(count/10+'0');
	    ans+=(count%10+'0');
	  }else if(count==100){
	    ans+='1';
	    ans+='0';
	    ans+='0';
	  }
	  ans+=(s[j-1]);
	  ans+='1';
	  ans+=s[j];
	  count=0;
	}else if(s[j-1]!=s[j]&&count==0&&j==s.size()-1){
	  ans+='1';
	  ans+=s[j-1];
	  ans+='1';
	  ans+=s[j];
	}else if(s[j-1]!=s[j]&&count==0&&j!=s.size()-1){
	  ans+='1';
	  ans+=s[j-1];
	}else if(s[j-1]!=s[j]&&count!=0&&j!=s.size()-1){
	  if(count<10)ans+=(count+'0');
	  else if(10<=count&&count<100){
	    ans+=(count/10+'0');
	    ans+=(count%10+'0');
	  }else if(count==100){
	    ans+='1';
	    ans+='0';
	    ans+='0';
	  }
	  ans+=s[j-1];
	  count=0;
	}

      }
      s.clear();
      s=ans;
      ans.clear();
      // cout<<s<<endl;
    }
    cout<<s<<endl;
  }
  
  return 0;
}

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

int main()
{
	string S;
	while (cin >> S, S != ".") {
		int P;
		cin >> P;
		reverse(S.begin(), S.end());
		vector<int> hs(10000);
		for (int x = 0; x < 10000; x++) {
			vector<int> v = { x / 1000, x % 1000 / 100, x % 100 / 10, x % 10 };
			vector<int> vs;
			for (auto c : S) {
				if ('a' <= c && c <= 'd') {
					vs.push_back(v[c - 'a']);
				}
				if (c == '+') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a | b);
				}
				if (c == '*') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a & b);
				}
				if (c == '^') {
					int a = vs.back(); vs.pop_back();
					int b = vs.back(); vs.pop_back();
					vs.push_back(a ^ b);
				}
			}
			hs[x] = vs.back();
		}
		cout << hs[P] << ' ' << count(hs.begin(), hs.end(), hs[P]) << endl;
	}
	return 0;
}



Measured memory_bytes: 3044
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
 
int main(){
    ll N, A, B;
    cin >> N >> A >> B;

    ll sum=A+B;

    ll warare=N/sum;
    ll b = warare*A;

    // cout << b << endl;

    if(N%sum < A){
        b += N%sum;
    }else{
        b += A;
    }
    
    cout << b << endl;

    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
     (source = $s:expr, $($r:tt)*) => {
         let mut iter = $s.split_whitespace();
         input_inner!{iter, $($r)*}
     };
     ($($r:tt)*) => {
         let s = {
             use std::io::Read;
         let mut s = String::new();
         std::io::stdin().read_to_string(&mut s).unwrap();
         s
     };
     let mut iter = s.split_whitespace();
     input_inner!{iter, $($r)*}
     };
}
     
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

const ALPHABETS_L: &'static str = "abcdefghijklmnopqrstuvwxyz";
//#[proconio::fastout]
fn main() {
    input!{
        s: String,
    }
    let charset: Vec<char> = ALPHABETS_L.chars().collect();
    let s: Vec<char> = s.chars().collect();
    let mut counter = 0;
    let mut i = 0;
    for j in 2..(s.len() - 1) {
        if s[j] == 'C' {
            counter += 1;
            i = j;
        }
    }
    if counter == 0 || counter > 1 || s[0] != 'A' {
        println!("WA");
        return;
    }
    if !(s[1..i].iter().all(|c| charset.contains(c)) && s[(i + 1)..s.len()].iter().all(|c| charset.contains(c))) {
        println!("WA");
        return;
    }
    println!("AC");
}


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

#define first  fs
#define second se
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)

using pii = pair<int, int>;
using vi = vector<int>;
using lint = long long;

const int inf = 1001001001;
const lint linf = 1001001001001001001ll;
const int mod = 1e9 + 7;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};

template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; } return a > b; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; } return a < b; }
template<typename T> inline void print(const T &x, char s = '\n') { cout << x << s; }
template<typename T> inline void print(const vector<T> &v, string s = " ") 
{ rep(i, v.size()) cout << v[i] << (i + 1 == v.size() ? "\n" : s); }
inline bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }
inline lint in() { lint x; std::cin>>x; return x; }

int main() {
	int n = in();

	cout << n * 800 - 200 * (n / 15) << endl;
}



Measured memory_bytes: 256
n = int(input())
arr = []
for i in range(2, int(-(-n**0.5//1))+1):
    if n%i==0:
        cnt=0
        while n%i==0:
            cnt+=1
            n //= i
        arr.append([i, cnt])

if n!=1:
    arr.append([n, 1])

# if arr==[]:
#     arr.append([n, 1])


ans = 0
for i in range(len(arr)):
    k = 1
    while True:
        if arr[i][1] >= k:
            ans += 1
            arr[i][1] -= k
            k += 1
        else:
            break

print(ans)

Measured memory_bytes: 9448
lines = $stdin.read
array = lines.split("\n")
 
N   = array[0].to_i
ans = true
 
pos  = [0,0]
before_time = 0
 
array[1..N+1].each_with_index do |str,i|
 
  next_time, next_x, next_y = str.split(" ").map(&:to_i)
  dist_x = [pos.first, next_x].max - [pos.first, next_x].min
  dist_y = [pos.last , next_y].max - [pos.last,  next_y].min
  dist = dist_x + dist_y
  time = next_time - before_time
 
  #puts "s[#{pos.first},#{pos.last}]=>d[#{next_x},#{next_y}] = dist #{dist} with time = #{time}"
 
  if time < dist
    puts "No"
    exit 0
  elsif time == dist
    # just in time
    pos,before_time = [next_x, next_y],next_time
    next
  elsif i+1 == N and time >= dist
    next
  else
    # time > dist
    rest = time - dist
    if rest % 2 == 0
      pos = [next_x, next_y]
      next
    else
      puts "No"
      exit 0
    end
  end
end
 
puts "Yes"

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

using namespace std;

const int N = 1e5 + 100;

vector<int> vec;
int cnt[N];
bool p[N];
int q;

int main() {
    memset(p, true, sizeof p);
    for (int i = 2; i < N; i++)
	if (p[i])
	    for (int j = 2 * i; j < N; j += i)
		p[j] = false;
    for (int i = 3; i < N; i += 2)
	if (p[i] && p[(i + 1) / 2])
	    cnt[i]++;
    for (int i = 1; i < N; i++)
	cnt[i] += cnt[i - 1];
    cin >> q;
    while (q--) {
	int l, r;
	cin >> l >> r;
	cout << cnt[r] - cnt[l - 1] << '\n';
    }
}

Measured memory_bytes: 1152
#include<stdio.h>
#define MAX 102
int main(){
  int box[MAX][MAX];
  int tmp[MAX][MAX];
  int i,j,n,m,l;
for(i=1;i<MAX;i++){
  for(j=1;j<MAX;j++){
    box[i][j]=0;
    tmp[i][j]=0;
  } 
 }


  
  scanf("%d",&n);//頂点数の入力
  //入力
  for(i=1;i<=n;i++){
      scanf("%d",&m);
      scanf("%d",&l);
      for(j=1;j<=l;j++){
	
	scanf("%d",&tmp[i][j]);//隣接する頂点の番号の保持
      }
  }
  
  
  //隣接の判定
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(tmp[i][j]!=0){
	box[i][tmp[i][j]]=1;
      }
    }
  }

  //出力
  for(i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      if(j!=n){
      printf("%d ",box[i][j]);
      }
      else {
	printf("%d\n",box[i][j]);
      }
    }
  }
  return 0;
}



Measured memory_bytes: 2108