akhauriyash/Code-Regression huggingface dataset:
fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(java.util.Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: java.util.Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val S = sc.next()

        var n = 0
        val L = (0 until N).map {
            val prev = n
            if (S[it] == 'W') {
                n += 1
            }
            prev
        }
        n = 0
        val R = (0 until N).map {
            val prev = n
            if (S[N - it - 1] == 'E') {
                n += 1
            }
            prev
        }

        val LR = (0 until N).map {
            L[it] + R[N - it - 1]
        }

        //println(L.joinToString(", "))
        //println(R.joinToString(", "))
        //println(LR.joinToString(", "))
        pw.println(LR.min()!!)
    }
}


Measured memory_bytes: 77820
#include <iostream>
using namespace std;
int main() {
	int n;
	cin >> n;
	string str;
	int num[] = {0,0,0,0};
	while(n--){
		cin >> str;
		if ("AC" == str){
			num[0]++;
		}
		if ("WA" == str){
			num[1]++;
		}
		if ("TLE" == str){
			num[2]++;
		}
		if ("RE" == str){
			num[3]++;
		}
	}
	cout << "AC x " << num[0] << endl;
	cout << "WA x " << num[1] << endl;
	cout << "TLE x " << num[2] << endl;
	cout << "RE x " << num[3] << endl;
}

Measured memory_bytes: 3596
N, M = map(int, input().split())

def make_divisor_list(num, N):

    if num < 1:
        return 0
    elif num == 1:
        return 1
    else:
        max_num = 1
        for i in reversed(range(2, num // N + 1)):
            if num % i == 0:
                # 割り切れる=約数
                if num / i >= N:
                    max_num = i
                    break
                #else:
                #    break
        return max_num

print(make_divisor_list(M, N))

Measured memory_bytes: 3060
import java.util.*;
class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int arr[] = {111,222,333,444,555,666,777,888,999};
		int n = sc.nextInt();
		for(int i=0 ; i<9 ; i++){
		    if(n<=arr[i]){
		        System.out.println(arr[i]);
		        break;
		    }
		}
	}
}

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

using namespace std;

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

  long long n, k, a, b;
  cin >> n >> k;
  map<int, long long> hash;
  for (int i = 0; i < n; ++i) {
    cin >> a >> b;
    hash[a] += b;
  }
  long long sum = 0;
  for (auto &h : hash) {
    sum += h.second;
    if (sum >= k) {
      cout << h.first << endl;
      break;
    }
  }

  return 0;
}



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

int main(){
  int A,B;
  cin >> A >> B;
  if(A<=5){
    cout << 0 << endl;
  }
  else if(A<=12){
    cout << B/2 << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication7
{
    class Program
    {
        static void Main()
        {
            string[] s_num = Console.ReadLine().Split(' ');
            int[] num = new int[s_num.Length];
            foreach (var x in Enumerable.Range(0, s_num.Length)) num[x] = int.Parse(s_num[x]);
            double ave = num.Average();
            
            double ceiling = Math.Ceiling(ave);
            Console.WriteLine(ceiling);
        }
    }
}

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

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

ll MOD = 1e+9 + 7;

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    vector<ll> a(n + 1, 0), totalMin(n + 10, 0), totalMax(n + 10, 0);
    rep(i, n + 1) a[i] = i;

    totalMin[1] = 0; // k = 1
    totalMax[1] = n;
    for (int i = 2; i <= n; i++) {
        totalMin[i] += totalMin[i - 1] + i - 1;
        totalMax[i] += totalMax[i - 1] + n - (i - 1);
    }

/*
    cout << "total min" << endl;
    rep(i, n + 1) cout << totalMin[i] << " ";
    cout << endl;

    cout << "total max" << endl;
    rep(i, n + 1) cout << totalMax[i] << " ";
    cout << endl;
*/

    for (; k <= n; k++) ans += (totalMax[k] - totalMin[k] + 1) % MOD;
    ans = (ans + 1) % MOD;

    cout << ans << endl;

    return 0;
}

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

long long gcd(long long a, long long b){
    if(a < b) swap(a, b);
    long long d = a / b;
    long long r = a % b;
    if(r == 0) return b;
    else return gcd(b, r);
}

long long lcm(long long a, long long b){
    long long g = gcd(a, b);
    return a / g * b;
}

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

    int n;
    cin >> n;

    long long ans = 1LL;
    vector<long long> T(n);
    for(int i = 0; i < n; i++){
        cin >> T[i];
        ans = lcm(ans, T[i]);
    }

    cout << ans << endl;


    return 0;
}

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

int n,m;

void solve()
{
	int dp[11][15001] = {};
	int num,how;
	int res = 0;

	for(int i = 0; i < n; i++){
		cin >> num >> how;
		
		for(int j = 1; j <= how; j++){
			dp[i+1][num*j]++;
		}
		for(int j = 1; j <= 10000; j++){
			if(dp[i][j]){
				dp[i+1][j] += dp[i][j];
				for(int k = 1; k <= how && j+num*k < 10000; k++){
					dp[i+1][j+num*k] += dp[i][j];
				}
			}
		}
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> num;
		cout << dp[n][num] << endl;
	}

	
	
}

int main(void)
{
	while(cin >> n, n){
		solve();
	}
	return 0;
}

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

using namespace std;

string s1, s2;
int n;

int main()
{
  	ios::sync_with_stdio(false);
  	cin.tie(NULL);
  
  	int i, j;
  	
  	cin >> n >> s1 >> s2;
  	
  	for(i=0; i<n; i++){
      	for(j=i; j<n; j++){
          	if(s1[j] != s2[j - i]) break;
        }
      	if(j == n) break;
    }
  
  	cout << i + n << endl;
  
  	return 0;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
answer = -1, -1, -1

for x in range(N+1):
    for y in range(N-x+1):
        z = N - x - y
        if x*10000 + y*5000 + z*1000 == Y:
            answer = x, y, z
            break
    else:
        continue
    break

print(*answer)

Measured memory_bytes: 3060
package main

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

var scan = bufio.NewScanner(os.Stdin)

func nextInt() int {
    scan.Scan()
    i, err := strconv.Atoi(scan.Text());
    if err != nil {
        panic(err)
    }
    return i
}

func digitSum(x int) int {
    sum := 0
    for x / 10 > 0 {
        sum += x % 10
        x = x / 10
    }
    sum += x
    return sum
}

func main() {
    scan.Split(bufio.ScanWords)
    n := nextInt()
    a := nextInt()
    b := nextInt()

    sum := 0
    for i := 1; i < n + 1; i++ {
        digit_sum := digitSum(i)
        if digit_sum >= a && digit_sum <= b {
            sum += i
        } 
    }

    fmt.Println(sum)
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Objects;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) {
		FastScanner cin = new FastScanner();
		PrintWriter cout = new PrintWriter(System.out);
		solve(cin, cout);
		cout.flush();
	}

	private static void solve(FastScanner cin, PrintWriter cout) {
		// 自前の例
		assert Objects.equals(
				solve(4, 5, new int[][] { { 1, 4, 1 }, { 2, 3, 1 }, { 3, 2, 1 }, { 3, 4, 1 }, { 1, 2, 1 } }), "inf");
		// 問題の例
		assert Objects.equals(solve(3, 3, new int[][] { { 1, 2, 4 }, { 2, 3, 3 }, { 1, 3, 5 } }), "7");
		assert Objects.equals(solve(2, 2, new int[][] { { 1, 2, 1 }, { 2, 1, 1 } }), "inf");
		assert Objects.equals(solve(6, 5, new int[][] { { 1, 2, -1000000000 }, { 2, 3, -1000000000 },
				{ 3, 4, -1000000000 }, { 4, 5, -1000000000 }, { 5, 6, -1000000000 } }), "-5000000000");

		int n = cin.nextInt();
		int m = cin.nextInt();
		int[][] abcs = new int[m][];
		for (int i = 0; i < abcs.length; i++)
			abcs[i] = new int[] { cin.nextInt(), cin.nextInt(), cin.nextInt() };

		String ans = solve(n, m, abcs);
		cout.println(ans);
	}

	private static String solve(int n, int m, int[][] abcs) {
		int[][] edges = new int[abcs.length][];
		for (int i = 0; i < abcs.length; i++)
			edges[i] = new int[] { abcs[i][0] - 1, abcs[i][1] - 1, -abcs[i][2] };
		long[] costs = new long[n];
		Arrays.fill(costs, Long.MAX_VALUE / 2);
		costs[0] = 0;
		for (int i = 0; i < n; i++)
			for (int[] e : edges)
				costs[e[1]] = Math.min(costs[e[1]], costs[e[0]] + e[2]);
		long ans1 = costs[n - 1];
		for (int i = 0; i < n; i++)
			for (int[] e : edges)
				costs[e[1]] = Math.min(costs[e[1]], costs[e[0]] + e[2]);
		long ans2 = costs[n - 1];

		if (ans1 != ans2)
			return "inf";
		else
			return Long.toString(-ans1);
	}

	/**
	 * How to read input in Java — tutorial <br />
	 * By Flatfoot<br />
	 * http://codeforces.com/blog/entry/7018
	 */
	static class FastScanner {
		private BufferedReader br;
		private StringTokenizer st;

		FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new IllegalStateException(e);
				}
			return st.nextToken();
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				throw new IllegalStateException(e);
			}
			return str;
		}

		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


Measured memory_bytes: 23764
N,M=map(int,input().split())
A=list(map(int,input().split()))
l=[]
for i in A:
    l.append([i,1])
for i in range(M):
    B,C=map(int,input().split())
    l.append([C,B])
l.sort(reverse=True)
a,t=0,0
while True:
    if l[t][1]>=N:
        a+=l[t][0]*N
        break
    else:
        a+=l[t][0]*l[t][1]
        N-=l[t][1]
        t+=1
print(a)

Measured memory_bytes: 87832
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n;
    cin>>n;
    lli sum=0;
    for(int i=1;i<=n;++i) {
        int x=i;
        if((x%3!=0)&&(x%5!=0)) {
            sum+=i;
        }
    }

    cout<<sum<<endl;

    // (det)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007

int main(){
  int N;
  string s,t;
  cin>>N>>s>>t;
  bool flag=false;
  for(int i=0;i<N;i++){
    bool sub=true;
    for(int j=i;j<N;j++){
      if(s.at(j)!=t.at(j-i)){
        sub=false;
        break;
      }
    }
    if(sub){
      flag=true;
      cout<<N+i<<endl;
      break;
    }
  }
  if(!flag){
    cout<<2*N<<endl;
  }
}


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

int main() {
	int alpha[30] = { 0 };
	string s;

	cin >> s;

	int i = 0;
	while (1) {
		if (s[i] == '\0') break;
		alpha[(int)(s[i] - 'a')]++;
		i++;
	}

	int j;
	for (j = 0; j < 26; j++) {
		if (alpha[j] >= 2) break;
	}

	if(j==26) cout << "yes" << endl;
	else cout << "no" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
using P = pair<ll, ll>;


void solve(long long A, long long B, long long C){
    int p1 = min((A + B), C);
    int p2 = (C - p1 > 0) ? 1 : 0;
    cout << p1 + B + p2 << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include<cstring>
#include<tuple>


#define rep(i,p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

/*
//119 D

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

int main(void) {
	ll n,k;
	cin >> n >> k;
	const ll MAX_DIGIT = 41;
	vector<ll> a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	ll dp[MAX_DIGIT+1][2];
	memset(dp, -1, sizeof(dp));
	dp[0][0] = 0;
	rep(i, 0, MAX_DIGIT) {
		ll mask = (ll)1 << (MAX_DIGIT - i - 1);

		int num = 0;
		rep(j, 0, n) if (a[j] & mask)	++num;

		ll cost0 = mask * num;
		ll cost1 = mask * (n - num);

		if (dp[i][1] != -1) {
			chmax(dp[i+1][1], dp[i][1] + max(cost0, cost1));
		}

		if (dp[i][0] != -1) {
			if (k & mask) {
				chmax(dp[i + 1][1], dp[i][0] + cost0);		
 			}

			if (k & mask) chmax(dp[i + 1][0], dp[i][0] + cost1);
			else chmax(dp[i + 1][0], dp[i][0] + cost0);
		}
	}

	cout << max(dp[MAX_DIGIT][0], dp[MAX_DIGIT][1]) << endl;
	
	
}
*/

bool tupleHGreater(tuple<ll,ll,ll>a, tuple<ll,ll,ll> b) {
	return get<2>(a) > get<2>(b);
}

//112 C
int main(void) {
	ll n;
	cin >> n;
	vector<tuple<ll, ll, ll>> pylamids = vector<tuple<ll, ll, ll>>();
	rep(i, 0, n) {
		ll x, y, h;
		cin >> x >> y >> h;
		pylamids.push_back(make_tuple(x, y, h));
	}
	ll ansX = 0, ansY = 0, ansH = 0;
	bool isAns = true;
	sort(pylamids.begin(), pylamids.end(), tupleHGreater);
	rep(cx, 0, 101) {
		ansX = cx;
		rep(cy, 0, 101) {
			ansY = cy;
			ansH = 0;
			isAns = true;
			rep(i, 0, n) {
				tuple<ll, ll, ll> pylamid = pylamids[i];
				ll x = get<0>(pylamid);
				ll y = get<1>(pylamid);
				ll h = get<2>(pylamid);
				if (h == 0) {
					if (ansH > abs(x - cx) + abs(y - cy)) {
						isAns = false;
						break;
					}
				}
				else {
					if (ansH == 0) {
						ansH = h + abs(x - cx) + abs(y - cy);
					}
					else {
						if (ansH != h + abs(x - cx) + abs(y - cy)) {
							isAns = false;
							break;
						}
					}
				}
			}
			if (isAns)break;
		}
		if (isAns)break;
	}
	cout << ansX << " " << ansY  << " " << ansH << endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007



n, k = LI()

ans = 0
for i in range(1,n+1):
    cnt = 0
    while i < k:
        i *= 2
        cnt += 1
    ans += (1 / 2 ** cnt)



print(ans / n)

Measured memory_bytes: 39792
#include <queue>
#include <utility>
#include <vector>
#include <unordered_map>
#include <map>
// #include <fstream>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
const long long mod = 1000000007;
const int INF = 2147483647;
int n,m;

typedef pair<int, pair<int, int>> pii;
int test(int i, int j, vector<vector<int>> DP) {
    int ans = 0;
    priority_queue<pii, vector<pii>, greater<pii>> pq;
    pq.push({0, {i, j}});
    vector<pair<int,int>> mm = {{-1,0}, {1, 0}, {0,-1},{0,1}};
    while (!pq.empty()) {
        auto x = pq.top();
        pq.pop();
        i = x.second.first;
        j = x.second.second;
        if (DP[i][j] == INF) {
            continue;
        }
        ans = max(ans, x.first);
        DP[i][j] = INF;
        for (int k = 0; k < 4; k++) {
            int ii = i + mm[k].first;
            int jj = j + mm[k].second;
            if (ii >= 0 && ii < n && jj >= 0 && jj < m && DP[ii][jj] != INF) {
                pq.push({x.first+1, {ii,jj}});
            }
        }
    }

    return ans;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    vector<string> v(n);
    vector<vector<int>> DP(n, vector<int>(m, 0));
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        for (int j = 0; j < m; j++) {
            if (v[i][j] == '#') {
                DP[i][j] = INF;
            }
        }
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (v[i][j] == '.') {
                ans = max(ans, test(i,j, DP));
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <vector>
#include <stack>
#include <cstdio>
#include <string>
#include <bitset>
#include <list>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <functional>
#include <queue>
#include <regex>
#include <cassert>
#include <map>
// #include "bits/stdc++.h"

using namespace std;
//debug

#define rep(i, N, M) for (ll i = N; i < M; ++i)
#define rrep(i, N, M) for (ll i = N; i < M; --i)
#define pb push_back


typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef priority_queue<ll> pqll;
typedef priority_queue<pll, vector<pll>> pqpll;
typedef priority_queue<ll, vll, greater<ll>> pqll_greater;
typedef priority_queue<pll, vector<pll>, greater<pll>> pqpll_greater;


#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define vec(a) vector<a>
#define _CRT_SECURE_NO_WARNINGS

template<class T, class S>
T atbit(T n, S i) {
	return (n >> i) % i;
}

template<class T>
T getbit(T i) {
	return 1LL << i;
}
template<class T>
T POW(T n, T m) {
	T res=1;
	rep(i, 0, m) {
		res *= n;
	}
	return res;
}

//#define TRANSFORM(v,w,func) decltype(v) w ; transform((v).begin(),(v).end(),back_inserter(w),func);

using namespace std;


int main() {
	ll N, x;
	cin >> N >> x;
	vll a(N);
	rep(i, 0, N) cin >> a[i];
	sort(all(a));
	ll cnt = 0;
	for(ll i=0; i<N;i++){
		x -= a[i];
		if(x>=0 && i!=N-1)++cnt;
		if (i == N - 1 && x == 0)++cnt;
	}
	cout<<cnt;
}


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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<int> bsum(n);
    bsum[0] = (s[0]=='#' ? 1 : 0);
    for(int i=1;i<n;i++) bsum[i] = bsum[i-1] + (s[i] == '#' ? 1 : 0);
    int ans = min(bsum[n-1], n-bsum[n-1]);
    for(int i=0;i<n;i++){
        int m = i+1;
        ans = min(bsum[i] + (n - m) - (bsum[n-1] - bsum[i]), ans);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1412
import java.util.*;
import java.util.ArrayList;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        int m = 0;
        int min = 1000000001;
        long sum = 0;

        for(int i=0; i<N; i++){
            A[i] = sc.nextInt();
            sum += Math.abs(A[i]);
            min = Math.min(min, Math.abs(A[i]));
            if(A[i]<0){
                m += 1;
            }
        }
        if(m%2==0){
            System.out.println(sum);
        }
        else{
            System.out.println(sum - 2 * min);
        }
    }
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#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 int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(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 ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}


const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
        // 1 2 3 4 5 6 7 8 9
int f[] = {2,5,5,4,5,6,3,7,6};

int dp[10005]; // dp[i]:=マッチをi個使うときの桁数の最大

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  int n,m;
  cin>>n>>m;
  vi a(m);
  rep(i,m) cin>>a[i];
  vsort(a);
  
  rep(i,m) {
    dp[f[a[i]-1]]=1;
  }
  rep(i,n+1){
    rep(j,m) {
      if(dp[max(0,i-f[a[j]-1])]==0) continue;
      chmax(dp[i],dp[max(0,i-f[a[j]-1])]+1);
    }
  }
  // cout<<dp[n]<<endl;
  // rep(i,n+1){
  //   cout<<i<<" "<<dp[i]<<endl;
  // }
  
  string ans="";
  int remain=dp[n];
  int match=n;
  while(match>0){
    for(int i=m-1; i>=0; i--){
      // cout<<ans<<endl;
      // if(match-f[a[i]-1]<0) continue;
      if(remain==1){
        if(f[a[i]-1]==match){
          ans+='0'+a[i];
          match-=f[a[i]-1];
          remain--;
          break;
        }
      }
      else if(dp[match-f[a[i]-1]]==remain-1){
        // cout<<match<<" "<<match-f[a[i]-1]<<" "<<dp[match-f[a[i]-1]]<<" "<<a[i]<<" "<<f[a[i]-1]<<" "<<remain<<endl;
        // if(f[a[i]-1]>match) continue;
        ans+='0'+a[i];
        match-=f[a[i]-1];
        remain--;
        break;
        // cout<<a[i]<<endl;
      }
    }
  }
  cout<<ans<<endl;
}


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

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

  if(A>=C && B>=D && D>A)
    cout << D-A << endl;

  else if(A<=C && B<=D && B>=C)
    cout << B-C << endl;

  else if(A>=C && B<=D)
    cout << B-A << endl;

  else if(A<=C && B>=D)
    cout << D-C << endl;

  else if(A>=C && B>=D && D<=A)
    cout << "0" << endl;

  else if(A<=C && B<=D && B<C)
    cout << "0" << endl;
}
            

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

int main(){
    int N,t;
    string in;
    cin>>N;
    pair<pair<string,int>,int> p[120];
    for(int i=0;i<N;i++){
        cin>>in>>t;
        p[i]=make_pair(make_pair(in,-t),i);
    }
    sort(p,p+N);
    for(int i=0;i<N;i++){
        cout<<p[i].second+1<<endl;
    }
}

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;

#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define pi  3.14159265359
#define mod 1000000007

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t;
    cin>>n>>x>>t;
    if(n%x==0){
        cout<<(n/x)*t;
    }else{
     cout<<((n/x)+1)*t;

    }




}



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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(int64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

// 最小公倍数lcm=m*n/gcd
uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// nCm
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

signed main() {
  int64_t a, b, m;
  string s = "";
  cin >> a >> b >> m;
  
  vector<int64_t> aPrice(a);
  vector<int64_t> bPrice(b);

  int64_t minA = INF;
  int64_t minB = INF;

  for(int64_t i=0; i<a; i++){
    cin >> aPrice[i];
    if(minA > aPrice[i]) {
      minA = aPrice[i];
    }
  }
  for(int64_t i=0; i<b; i++){
    cin >> bPrice[i];
    if(minB > bPrice[i]) {
      minB = bPrice[i];
    }
  }
  int64_t minPrice = minA+minB;
  int64_t x,y,c;
  for(int64_t i=0; i<m; i++){
    cin >> x >> y >> c;
    x -= 1;
    y -= 1;
    if(aPrice[x]+bPrice[y]-c < minPrice) {
      minPrice = aPrice[x]+bPrice[y]-c;
    }
  }

  cout << minPrice << endl;
  
  return 0;
}

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

int main() {
	int n, m, A[100][100], b[100], c[100];

	//配列の初期化
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			A[i][j] = 0;
		}
	}
	for (int i = 0; i < m; i++) {
		b[i] = 0;
	}

	cin >> n >> m;
	
	//二次元配列Aの入力
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> A[i][j];
		}
	}
	
	//一次元配列bの入力
	for (int i = 0; i < m; i++) {
		cin >> b[i];
	}

	for (int i = 0; i < n; i++) {
		c[i] = 0; //一次元配列cの初期化
		for (int j = 0; j < m; j++) {
			c[i] += A[i][j] * b[j];
		}
	}

	for (int i = 0; i < n; i++) cout << c[i] << endl;

	return 0;
}


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

int main () {
  string S;
  string ans[3] = {"Sunny", "Cloudy", "Rainy"};
  cin >> S ;
  if(S==ans[0]) cout << ans[1] << endl ;
  else if (S == ans[1]) cout << ans[2] << endl ;
  else cout << ans[0] << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n;
    cin>>n;
    vector<int> a(n);
        rep(i,n) cin>>a.at(i);
    //dp[i]:=i+1文字の増加部分列の最後の文字の位置の最小値
    vector<int> dp(n,inf);
    rep(i,n) *lower_bound(all(dp),a[i])=a[i];
    cout<<lower_bound(all(dp),inf)-dp.begin()<<endl;
}


Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<long long> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    vector<int> ind(N);
    for(int i = 0; i < N; i++) ind[i] = i;
    sort(ind.begin(), ind.end(), [&](int x, int y){
        return P[x] > P[y];
    });
    set<int> s;
    long long ans = 0;
    s.insert(ind[0]);
    long long a, b, c, d;
    for(int i = 1; i < N; i++){
        s.insert(ind[i]);
        auto ite = s.find(ind[i]);
        auto ite2 = ite;
        a = (++ite == s.end()) ? N : *ite;
        if(ite == s.end()) ite--;
        b = (++ite == s.end()) ? N : *ite;
        c = (ite2 == s.begin()) ? -1 : *(--ite2);
        d = (ite2 == s.begin()) ? -1 : *(--ite2);
        long long temp = (ind[i] - c) * (b - a) + (a - ind[i]) * (c - d);
        ans += temp * P[ind[i]];
    }
    cout << ans << endl;
}

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

using namespace std;

int n,k;
vector<int> a;

bool ok(int p) {
	if(a[p]>=k) return true;
	vector<vector<char> > dp(n+1,vector<char>(k));
	dp[0][0]=true;
	for(int i=0;i<n;++i) {
		for(int j=0;j<k;++j) {
			dp[i+1][j]|=dp[i][j];
			if(i==p||j+a[i]>=k) continue;
			dp[i+1][j+a[i]]|=dp[i][j];
			if(j+a[i]>=k-a[p]&&dp[i+1][j+a[i]]) return true;
		}
	}
	return false;
}

int main() {
	cin >> n >> k;
	a.resize(n);
	for(auto&e:a) cin >> e;
	sort(a.begin(),a.end());
	int l=-1,r=n;
	while(r-l>1) {
		int mid=(l+r)/2;
		if(ok(mid)) r=mid;
		else l=mid;
	}
	cout << r << endl;
	
	return 0;
}

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

int dp[1 << 26];

int main()
{
	string s;
	cin >> s;
	for (int i = 0; i < (1 << 26); i++) {
		dp[i] = s.size();
	}
	int X = 0;
	dp[0] = 0;
	for (auto c : s) {
		int b = c - 'a';
		X ^= 1 << b;
		int nv = dp[X] + 1;
		for (int i = 0; i < 26; i++) {
			nv = min(nv, dp[X ^ (1 << i)] + 1);
		}
		dp[X] = min(dp[X], nv);
	}
	cout << max(dp[X], 1) << endl;
	return 0;
}


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

int main() {
  int d, n;
  cin >> d >> n;
  if (n == 100)
    ++n;
  int base = (d == 0) ? 1 : (d == 1) ? 100 : 10000;
  cout << n * base << "\n";
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
for i in range(len(a)):
    if a[i]==1:
        p=i+1
        break
ans=0
ans+=p//(k-1)+1
right=n-(i+1)-(k-(i+1)%(k-1))
ans+=-(-right//(k-1))
print(ans)

Measured memory_bytes: 13880
#include <iostream>

using namespace std;
using ll = long long;

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

	ll ans = 0;
	if (A > K) {
		A -= K;
	}
	else {
		K -= A;
		A = 0;
		if (B > K) {
			B -= K;
		}
		else {
			K -= B;
			B = 0;
		}
	}

	cout << A << " " << B << endl;

	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <stdio.h>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int num[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
bool uru(int checkyear){if(checkyear%4==0){if(checkyear%100!=0||checkyear%400==0)return true;}return false;}
int gcd( int x, int y ){return y ? gcd(y, x%y) : x;}
bool pairCompare(const pairint& firstElof, const pairint& secondElof)
{
  if(firstElof.second!= secondElof.second)    return firstElof.second> secondElof.second;
  else return firstElof.first< secondElof.first;
}
signed main() {
int x=0,y=0,z=0,w=0,n=0,m=0;
string v;
std::cin >> v;
sort(all(v));
if(v=="abc")std::cout << "Yes" << '\n';
else std::cout << "No" << '\n';
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first
#define S second

void solve(){
	
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double r; cin >> r;
	cout << 2*r*M_PI;

	
	return 0;
}


Measured memory_bytes: 3780
def main
  n = STDIN.gets.chomp.to_i
  ns = STDIN.gets.split(' ').map(&:to_i).sort

  half = n / 2 
  return 0 if half == 0

  result = 0
  ((ns[half - 1] + 1)..ns[half]).each do |target|
    result += 1 if target > ns[half - 1] && target <= ns[half]
  end
  return result
end

puts main

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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define dbg(x) cout<<#x<<"="<<x<<endl

#define fi first
#define se second

vector<vector<int>> g;
vector<bool> vis;
int cnt=0;

void dfs(int v){
  vis[v]=true;
  cnt++;
  for(int nv : g[v]){
    if(vis[nv])continue;
    dfs(nv);
  }
}

int V;
vector<int> G[2010];
int match[2010];
bool used[2010];

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}

bool dfs2(int v){
  used[v]=true;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i];
    int w=match[u];
    if(w<0||(!used[w]&&dfs2(w))){
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}

int bipart(){
  int res=0;
  memset(match,-1,sizeof(match));
  rep(v,V){
    if(match[v]<0){
      memset(used,0,sizeof(used));
      if(dfs2(v))res++;
    }
  }
  return res;
}

int main(){

  int N,M;
  cin>>N>>M;
  vector<int> X(M),Y(M);
  g.resize(M);
  vis.resize(M,false);

  rep(i,M){
    cin>>X[i]>>Y[i];
    X[i]--; Y[i]--;
  }

  rep(i,M)rep(j,i){
    if(X[i]==X[j]||Y[i]==Y[j]){
      g[i].push_back(j);
      g[j].push_back(i);
    }
  }

  int resmx=0;
  rep(i,M){
    if(!vis[i]){
      cnt=0;
      dfs(i);
      resmx+=cnt-1;
    }
  }

  V=2*N;
  rep(i,M){
    add_edge(X[i],Y[i]+N);
  }

  int resmn=M - bipart();
  cout<<resmn<<" "<<resmx<<endl;

  return 0;
}



Measured memory_bytes: 7052
#include<iostream>
#include <math.h>
using namespace std;

int main(){
    int N, x, c;c=0;
    cin >> N;
    for (int i = 1; i <= N; i++) {
       cin >> x;
       int fc;fc=0;
        for (int j =1; j <= sqrt(x); j++) {
         if (x%j==0) {
           fc+=1;
         }
       }
       if (fc==1) c+=1;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = ((ll)(x) - 1); i >= 0; i--)

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

//ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
//ll lcm(ll x, ll y) {return x / gcd(x, y) * y;}
/*bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}*/

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

const ll mod = 1e9 + 7;
const ll IMF = 1LL<<29;
const double PI = 3.14159265358979323846;


// ******************************CODE**********************************//

vector<vector<int>> sum;
int N, M , Q;

void buildSumTable(vector<int> L, vector<int> R){
        sum = vector<vector<int>> (N+1 , vector<int>(N+1, 0));
        //入力された場所にプラス１する。
        for(int i = 0; i < M; i++)
        {
                sum[L[i]][R[i]]++;
        }

        //二次元累積和
        for(int i = 1; i <= N; i++)
        {
                for(int j = 1; j <= N; j++)
                {
                        sum[i][j] += sum[i-1][j];
                        sum[i][j] += sum[i][j-1];
                        sum[i][j] -= sum[i-1][j-1];
                }
        }
}

int getSumRange(int L, int R){
        int ans = sum[R][R] - sum[R][L-1] - sum[L-1][R] + sum[L-1][L-1];
        return ans;
}



int main(){


        cin >> N >> M >> Q;
        vector<int> L(M);
        vector<int> R(M);
        for(int i = 0; i < M; i++)
        {
                cin >> L[i] >> R[i];
        }
        vector<int> p(Q);
        vector<int> q(Q);
        for(int i = 0; i < Q; i++)
        {
                cin >> p[i] >> q[i];
        }

        buildSumTable(L,R);

        for(int i = 0; i < Q; i++)
        {
                int ans = getSumRange(p[i], q[i]);
                cout << ans << endl;
        }

        return 0;



}


Measured memory_bytes: 5120
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return(a)
A,B,C,D=map(int,input().split())
CD=C*D//gcd(C,D)
print((B-A+1-(B//C-(A-1)//C)-(B//D-(A-1)//D)+(B//CD-(A-1)//CD)))

Measured memory_bytes: 3060
n = int(input())
for i in range(9 * len(str(n)), 0, -1):
    if i <= 9:
        i_min = i
    else:
        i_min = int(str(i % 9) + '9' * (i // 9))
    if i_min <= n:
        print(i)
        exit()

Measured memory_bytes: 2940
def bubble_sort(data):
    for i in range(len(data) - 1):
        for j in range(len(data) - 1, i, -1):
            if int(data[j][1]) < int(data[j - 1][1]):
                data[j], data[j - 1] = data[j - 1], data[j]

def selection_sort(data):
    for i in range(len(data)):
        min_j = i
        for j in range(i, len(data)):
            if int(data[j][1]) < int(data[min_j][1]):
                min_j = j
        if min_j != i:
            data[i], data[min_j] = data[min_j], data[i]

input()
cards = [x for x in input().split()]
cards_b = cards.copy()
cards_s = cards.copy()
bubble_sort(cards_b)
selection_sort(cards_s)
for data in [cards_b, cards_s]:
    print(' '.join(data))
    if data == cards_b:
        print("Stable")
    else:
        print("Not stable")

Measured memory_bytes: 7716
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
int main(){

  double y,r;
  int b,n,t,i,j;
  pair <double,int> bank[50];

  while(cin>>n,n){
    cin>>y;

    for(i=0;i<n;i++){
      
      cin>>b>>r>>t;
      
      if(t==1) bank[i]=make_pair(1+y*r/100,b);
      else{
        double blank=1;
        for(j=0;j<y;j++) blank*=1+r/100;
        bank[i]=make_pair(blank,b);
      }  
    }
    
    sort(bank,bank+n);
    cout<<bank[n-1].second<<endl;
  }
  return 0;
  
}
  

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

int main() {
    int N;
    cin >> N;
    
    vector<int> a(N,0);
    rep(i, N) cin >> a.at(i);
    rep(i, N) a.at(i)--;
    
    vector<int> flag(N, 0);
    int temp = 0, sum = 0;

    rep(i, N) {
        if (flag.at(a.at(temp)) == 0) {
            flag.at(temp)++, sum++;
            temp = a.at(temp);
        }else {
            cout << -1 << endl;
            return 0;
        }

        if (temp == 1) {
            cout << sum << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


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

using ll = long long;
using pll = pair<ll, ll>;
using pii = pair<int, int>;
using ull = unsigned long long;

#define NL '\n'
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sii(x, y) scanf("%d%d",&x, &y)
#define sll(x, y) scanf("%lld%lld",&x, &y)

#define xx first
#define yy second
#define ins insert
#define mp make_pair
#define pb push_back
#define mdx ((l+r)>>1)
#define ldx ((idx<<1))
#define rdx ((idx<<1)|1)
#define sz(x) x.size()
#define pi 2.0*acos(0.0)
#define sqr(x)  ((x) * 1ll * (x))
#define all(x) (x).begin(),(x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define file_in(); freopen("input.txt", "r", stdin);
#define file_out(); freopen("output.txt", "w", stdout);
#define file_err(); freopen("serr.txt", "w", stderr);
#define rep(ii,aa,bb) for(ll (ii)=ll(aa);(ii)<(ll)(bb);++(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define _runtime() cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"

template<class T> T setbit(T n, T pos){n=n|(1<<pos); return n;}
template<class T> T checkbit(T n, T pos){n=n&(1<<pos); return n;}
template<class T> T gcd(T a, T b ) {return b<=0?a:gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return ((a / gcd(a,b) ) * b);}





const int mxx = 1e5+9;
int n, a[mxx], b[mxx], c[mxx], dp[mxx][3];


int f(int pos, int prev){
	if(pos >= n) return 0;
	int &ret = dp[pos][prev];
	if(ret != -1) return ret;
	if(prev == 0) ret = max(ret, max(b[pos] + f(pos + 1, 1), c[pos] + f(pos + 1, 2)));
	else if(prev == 1) ret = max(ret, max(c[pos] + f(pos + 1, 2), a[pos] + f(pos + 1, 0)));
	else if(prev == 2) ret = max(ret, max(a[pos] + f(pos + 1, 0), b[pos] + f(pos + 1, 1)));
	else ret = max(ret, max(a[pos] + f(pos + 1, 0), max(b[pos] + f(pos + 1, 1), c[pos] + f(pos + 1, 2))));
	return ret;
}

int main(){
	_fastIO();
	rep(i, 0, mxx) dp[i][0] = -1, dp[i][1] = -1, dp[i][2] = -1;
	cin >> n;
	rep(i, 0, n) cin >> a[i] >> b[i] >> c[i];
	cout << f(0, 3) << NL;
}

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

#define INFTY 10000000

int d[1001][1001],n;
char map[1001][1001];
int h,w;
pair< int,int > T[10];

int bfs( pair<int, int> p1, pair<int, int> p2 ) {
  
  queue< pair<int,int> > Q;
  
  for ( int i = 1; i <= h; i++ ) {
    for ( int j = 1; j <= w; j++ ) d[i][j] = INFTY;
  }
  
  d[p1.first][p1.second] = 0;
  Q.push(p1);   
  int u,v;
    
  while ( !Q.empty() ) {
    p1 = Q.front(); Q.pop();
    u = p1.first;
    v = p1.second;
        	
    if ( map[u+1][v] != 'X' &&  u+1 <= h && d[u+1][v] == INFTY ) {
	p1.first = u+1;
	p1.second = v;
	d[u+1][v] = d[u][v]+1;
	Q.push(p1);
    } 
    if ( map[u][v+1] != 'X' && v+1 <= w && d[u][v+1] == INFTY ) {
	p1.first = u;
	p1.second = v+1;
	d[u][v+1] = d[u][v]+1;
	Q.push(p1);
    } 
    if ( map[u-1][v] != 'X' && u-1 >= 1 && d[u-1][v] == INFTY ) {
	p1.first = u-1;
	p1.second = v;
	d[u-1][v] = d[u][v]+1;
	Q.push(p1);
    } 
    if ( map[u][v-1] != 'X' && v-1 >= 1 && d[u][v-1] == INFTY ) {
	p1.first = u;
	p1.second = v-1;
	d[u][v-1] = d[u][v]+1;
	Q.push(p1);
      }
	
  }
  
  /* for ( int i = 1; i <= h; i++ ) {
    for ( int j = 1; j <= w; j++ )  cout << d[i][j] << " ";
    cout << endl;
  }

  cout << endl;
  */
  return d[p2.first][p2.second];

}

int main() {
  
  cin >> h >> w >> n;
  for ( int i = 1; i <= h; i++ ){
    for ( int j = 1; j <= w; j++ ) {
      cin >> map[i][j];
      if ( map[i][j] == 'S' ){
	T[0].first = i;
	T[0].second = j;
      }
    }
  }
  
  for ( int i = 1; i <= h; i++ ) {
    for ( int j = 1; j <= w; j++ ) {
      if ( map[i][j] >= '1' && map[i][j] <= '9' ) {
	T[ map[i][j]-'0' ].first = i;
	T[ map[i][j]-'0' ].second = j;
      }
    }
  }

  int ans = 0;
  for ( int i = 0; i < n; i++ ) ans += bfs( T[i], T[i+1] );

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

Measured memory_bytes: 6108
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 2e9
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main()
{
	int n, ans = 0, s, max;
	cin >> n;
	vector<int>x(n);
	rep(i, 0, n)cin >> x[i];
	sort(x.begin(), x.end());
	max = x[n - 1];
	vector<int>b(max+1, 0);
	for (int i = n-1; i >= 0; i--)
	{
		b[x[i]]++;
		s = 2;
		while (x[i] * s <= max)
		{
			if (b[x[i] * s] >= 1)b[x[i] * s]++;
			s++;
		}
	}
	rep(i, 1, max + 1)if (b[i] == 1)ans++;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

ll digitSum(ll n){
    ll sum = 0;
    while(n>0){
        sum += n%10;
        n /= 10;
    }
    return sum;
}

int main(){
    Init();
    ll n, a, b; cin >> n >> a >> b;

    ll ans = 0;
    for(ll i=1; i<=n; i++){
        ll tmp = digitSum(i);
        if(tmp >=a && tmp<=b) ans += i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256