akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
 
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 

const double EPS=0.00001;
const long double PI = acos(-1.0);
 

 
int main() {
    long N;cin>>N;
    vector<long> A(N),B(N),C(N);
    REP(i,N)cin>>A[i];
    REP(i,N)cin>>B[i];
    REP(i,N)cin>>C[i];
    SORT(A);SORT(B);SORT(C);
    LL res=0;
    vector<long>acnt,bcnt,bsum;
    bsum.PB(0L);
    for(long b:B){
        long tmp=N-(upper_bound(C.begin(),C.end(),b)-C.begin());//Bからみて条件を満たすCの数
        bsum.PB(tmp+bsum.back());
    }

    for(long a:A){
        long tmp=N-(upper_bound(B.begin(),B.end(),a)-B.begin());//条件を満たすBの数
        //cout<<bsum.back()<<" "<<bsum[tmp]<<endl;
        res+=bsum.back()-bsum[N-tmp];
    }
    cout<<res<<endl;
    return 0;
}
/*
2
1 5
1 2
3 6
*/

Measured memory_bytes: 5368
h,w=map(int,input().split());s=[list(input()) for _ in range(h)]
for i in range(h):
    moji = ''
    for j in range(w):
        cnt = 0
        if s[i][j] == '#':
            moji += '#'
        else:
            for ih in [-1, 0, 1]:
                for jw in [-1, 0, 1]:
                    if 0 <= i + ih < h and 0 <= j + jw < w:
                        if ih == 0 and jw == 0:
                            pass
                        elif s[i + ih][j + jw] == '#':
                            cnt += 1
                        else:
                            pass
            moji += str(cnt)
    print(moji)

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

typedef long long int ll;

ll a[100010];
ll sum[100010];
int n;

int fun(ll num, int start){
	long long int * ind = lower_bound(a, a + n, 2*num);
	if(ind == a + n){
		return 1;
	}

	if(a[ind - a] > 2 * num){
		ind--;
	}
	if(ind - a == start) return 0;

	num = sum[(ind - a)];
	if(start != -1){
		num -= sum[start];
	}

	start = ind - a;

	return fun(num, start);
}

int main(){
	int i, j;

	cin>>n;
	for(i =0 ; i < n; i++){
		cin>>a[i];
	}
	sort(a, a + n);
	

	sum[0] = a[0];

	for(i = 1; i < n; i++){
		sum[i] = sum[i - 1] + a[i];
	}

	int ans = 0;

	for(i = 0 ; i < n; i++){
		ll num = a[i];
		ans += fun(num, -1);
	}

	cout<<ans<<endl;


	return 0;
}


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> map(H);
    string s(W+2, '#');
    for (int i = 0; i < H; ++i) cin >> map.at(i);
    cout << s << endl;
    for (int i = 0; i < H; ++i) cout << '#' << map.at(i) << '#' << endl;
    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	var D int
	if sc.Scan() {
		D, _ = strconv.Atoi(sc.Text())
	}

	if D == 25 {
		fmt.Println("Christmas")
	} else if D == 24 {
		fmt.Println("Christmas Eve")
	} else if D == 23 {
		fmt.Println("Christmas Eve Eve")
	} else if D == 22 {
		fmt.Println("Christmas Eve Eve Eve")
	}
}


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

int main(){

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

    int res = 0;
    for (int i = a; i <= b; i++) {
        if (c % i == 0) res++;
    }
    cout << res << endl;
  return 0;
}


Measured memory_bytes: 3116
//g++ -std=c++14 test.cpp -o test.out

//ポイント：「商を決める→あまりを決める」でダメなら順序を変えて、「あまりを決める→商を決める」にしてみる
 
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <stack>
#include <map> 
#include <unordered_map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N,K;
LL P[5001],C[5001];

LL ans = -INF;

void solve(){
	//点iから行って戻ってくるまでにかかる操作回数
	vector<LL> loop(N+1);
	//点iから行って戻ってくるまでに稼げるスコア
	//もし負なら0としておく
	vector<LL> score_per_loop(N+1);
	for(int i=1;i<=N;i++){
		LL score = 0;
		LL point = i;
		LL numof_loop = 0;
		while(1){
			point = P[point];
			score += C[point];
			numof_loop++;
			if(i==point) break;
		}
		loop[i] = numof_loop;
		score_per_loop[i] = max(0LL,score);
	}

	for(int i=1;i<=N;i++){
		//各点iから初めて、0~K回操作を行った時のスコアの最大値を求める
		LL point = i;
		LL score = 0;
		for(int operation=1;operation<=min(K,loop[i]);operation++){
			point = P[point];
			score += C[point];
			ans = max(ans,score + max(0LL,((K-operation)/loop[i]))*score_per_loop[i]);
		}
	}
}
 
int main(){
	cin >> N >> K;
	for(int i=1;i<=N;i++) cin >> P[i];
	for(int i=1;i<=N;i++) cin >> C[i];
 
    solve();

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

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ull unsigned long long
#define M 1000000007

using namespace std;
int main(){
    int n;cin>>n;
    vector <ll> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    //vector <ll> arr(n);
    ll x=0;
    for(int i=0;i<n-1;i=i+2){
        x=x^(v[i]^v[i+1]);  
    }
    for(int i=0;i<n;i++){
        ll k=v[i]^x;
        cout<<k<<" ";
    }
    cout<<endl;
    
}

Measured memory_bytes: 4696
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
#define MODn 1000000009;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  std::cin >> N;
  std::vector<int> d(N);
  for(int i=0;i<N;i++) std::cin >> d[i];
  sort(d.begin(), d.end());
  std::cout << d[N/2]-d[(N/2)-1] << '\n';
  return 0;
}


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

using namespace std;

bool IsPrime(int num)
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			// 素数ではない
			return false;
		}
	}

	// 素数である
	return true;
}

int main() {
	
	vector<int> a(100010);
	for (int i = 3; i <= 100000; i=i+2) {

		a[i] = a[i - 2] + (IsPrime(i) && IsPrime((i + 1) / 2));
	}


	int q;
	cin >> q;
	int l, r;
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		if (l != 1) {
			cout << a[r] - a[l - 2] << endl;
		}
		else {
			cout << a[r] << endl;
		}
	}



}

Measured memory_bytes: 3668
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int n;
    double[] s;
    int i;
    double a, ave;

    for(;;){
      n = sc.nextInt();
      if(n == 0)break;
      s = new double[n];
      for(i = 0;i < n;i++){
        s[i] = sc.nextDouble();
      }

      ave = 0.0;
      for(i = 0;i < n;i++){
        ave += (double)s[i];
      }
      ave /= (double)n;

      a = 0.0;
      for(i = 0;i < n;i++){
        a += (s[i] - ave) * (s[i] - ave);
      }
      a /= (double)n;
      System.out.println(Math.sqrt(a));
    }

    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}

Measured memory_bytes: 28428
#include <cstdio>
#include <algorithm>
#include <map>
using namespace std;
int arr[12], arr2[12];

int main(){
    int n, idx;
    bool flag;
    for(; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        idx = 0;
        for (int i = 0; i < n; i++) scanf("%d", &arr[i]);

        for (; ;) {
            map<int, int> m;
            for (int i = 0; i < n; i++) {
                if (m.find(arr[i]) == m.end()) m.insert({arr[i], 1});
                else m[arr[i]]++;
            }
            for (int i = 0; i < n; i++) arr2[i] = m[arr[i]];
            flag = true;
            for (int i = 0; i < n; i++) if (arr[i] != arr2[i]) { flag = false; arr[i] = arr2[i]; };
            if (flag) break;
            else idx++;
        }
        printf("%d\n", idx);
        for (int i = 0; i < n; i++) { if(i) printf(" "); printf("%d", arr2[i]); }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2768
#include<bits/stdc++.h>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;

void print(vector<vector<int>> v) {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 540; j <= 1260; j++) {
			cout << v[i][j];;
		}
		cout  << endl;
	}
}

int main() {

	while(1) {
		int N,M; cin >> N >> M;
		if (N + M == 0) break;
		int r; cin >> r;

		vector<vector<int>> use(M+1,vector<int>(1260,0));

		for (int i = 0; i < r; i++) {
			int t,n,m,s; cin >> t >> n >> m >> s;
			if (s == 1) {
				use[m][t] += 1;
			}else if (s == 0) {
				use[m][t] -= 1;
			}
		}

		for (int i = 1; i <= M; i++) {
			for (int j = 541; j <= 1260; j++) {
				use[i][j] += use[i][j-1];
			}
		}
		//print(use);

		int q; cin >> q;
		for (int i = 0; i < q; i++) {
			int ts,te,m; cin >> ts >> te >> m;
			int ans = 0;
			for (int j = ts; j < te; j++) {
				if (use[m][j] > 0) {
					ans++;
				}
			}
			cout << ans << endl;
		}
	}

	return 0;
}

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

int BubbleSort(vector<int> &A, int N){
  int flag = 1;
  int cnt = 0;
  while(flag == 1){
    flag = 0;
    for(int j = N-1; j >= 1; j--){
      if(A.at(j) < A.at(j-1)){
        swap(A.at(j), A.at(j-1));
        flag = 1;
        cnt++;
      }
    }
  }
  return cnt;
}

int main(){
	int n;
  cin >> n;
  vector<int> A(n);

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

  int result = BubbleSort(A, n);

  for (size_t i = 0; i < n-1; i++) {
    std::cout << A.at(i) << " ";
  }
  std::cout << A.at(n-1) << '\n';

  std::cout << result << '\n';

}



Measured memory_bytes: 3128
open Hashtbl
let n = read_int ()
let h, ans, a_s = create n, ref 0, Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let _ = Array.iter (fun a -> replace h a @@ try find h a + 1 with _ -> 1) a_s; iter (fun a c -> ans := !ans + if a > c then c else min c @@ c - a) h; Printf.printf "%d\n" !ans

Measured memory_bytes: 7424
"""
arr = list(map(int, input().split()))
n,k=map(int, input().split())
"""
import math
import sys
# input = sys.stdin.readline

############ ---- Input Functions ---- ############
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) - 1]))
def invr():
    return(map(int,input().split()))

n = int(input())
matrix = []
for _ in range(n):
    temp = inlt()
    matrix.append(temp)
dp = matrix[0]
m = [0]*3
for i in range(n - 1):
    for j in range(3):
        m[j] = max(dp[(j+1)%3]  + matrix[i+1][j], dp[(j+2)% 3]+ matrix[i+1][j])
    dp = m
    m = [0] * 3
print(max(dp))


Measured memory_bytes: 62552
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long
//#define scanf scanf_s

int main()
{
	double n;
	while (cin >> n)
	{
		FOR(i, 1, 114514)
		{
			int h = i * 5 - 5;
			double t = sqrt(h / 4.9);
			double v = 9.8*t;
			if (v > n)
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

vector <int> adia[100010];
int see[100010];
int maxim = 0, total;

int lsb(int x, int i)
{
    for (; ; i++)
        if ((1 << i) & x)
            return i;
}

int msb(int x)
{
    for (int i = 30; ; i--)
        if ((1 << i) & x)
            return i;
}

int dfs(int nod, int tata)
{
    int ce_pun = 0;
    for (auto i : adia[nod]) {
        if (i != tata) {
            int m = dfs(i, nod);
            if (m & see[nod])
                ce_pun = max(ce_pun, msb(m & see[nod]));
            see[nod] |= m;
        }
    }
    ce_pun = lsb(~see[nod], ce_pun);
    maxim = max(maxim, ce_pun);

    see[nod] |= (1 << ce_pun);
    for (int i = 0; i < ce_pun; i++)
        see[nod] &= ~(1 << i);

    return see[nod];
}

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

    while (--n) {
        cin >> a >> b;
        adia[a].push_back(b);
        adia[b].push_back(a);
    }

    dfs(1, 0);

    cout << maxim << '\n';
}


Measured memory_bytes: 10624
import numpy as np
A, B, M=map(int, input().split())
a=list(map(int, input().split()))
b=list(map(int, input().split()))
out=min(a)+min(b)
for i in range(M):
  x, y, c=map(int, input().split())
  tmp=a[x-1]+b[y-1]-c
  out=min(tmp, out)
print(out)

Measured memory_bytes: 27508
#include <stdio.h>

int main(void){
  int n,d,x,c,cn=0,b;
  scanf("%d %d %d",&n,&d,&x);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i =0;i < n;i++){
    c = a[i];
    b=1;
    while(c < d){
      c = b * a[i] + 1;
      b++;
      if(c <= d){
      cn++;
      }
      //printf("> %d\n",c);
    }
    //printf("%d：%d\n",i+1,cn);
  }
  printf("%d\n",cn+x+n);
  return 0;
}

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

using namespace std;

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

class UnionFind {
public:
	vector<ll> uni;
	UnionFind(ll s) : uni(s, -1) { }
	ll root(ll a) {
		if (uni[a] < 0) return a;
		return uni[a] = root(uni[a]);
	}
	bool connect(int a,int b) {
		a = root(a);
		b = root(b);
		if (a == b) return false;
		if (uni[a] > uni[b]) {
			a ^= b;
			b ^= a;
			a ^= b;
		}
		uni[a] = uni[a] + uni[b];
		uni[b] = a;
		return true;
	}
	bool isConnect(ll a,ll b) {
		return root(a) == root(b);
	}
	ll size(ll a) {
		return -uni[root(a)];
	}
};

int main(){
    int n, m;
    cin >> n >> m;
	UnionFind cards(n);
	int x, y, z;
	for(int i = 0; i < m; i++){
		cin >> x >> y >> z;
		cards.connect(x-1, y-1);
	}
	int number[100005]={0};
	ll ans = 0;
	for(int i = 0; i < n; i++){
		int num = cards.size(i);
		if(number[num] == 0){
			number[num]=num-1;
			ans++;
		}
		else{
			number[num]--;
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807
#define MOD 1000000007



void solve()
{
  int A,B;
  cin>>A>>B;
  cout<<(A-1)*(B-1)<<endl;
  
}

int32_t main(int32_t argc, const char *argv[])
{
 
  solve();
 
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
#define rep_r(i,s,n)for(ll i = n-1;i>s;i--)
#define rep_re(i,s,n)for(ll i = n-1;i>=s;i--)
ll MOD = 1e9 + 7;

int X[200001] = {};
int main() {
	ll x; cin >> x;
	ll a[6] = { 100,101,102,103,104,105 };

	X[0] = 1;

	repe(j, 0, 100000) {
		rep(i, 0, 6) {
			X[j+a[i]] |= X[j];
		}
	}

	cout << X[x] << endl;

	return 0;
}


Measured memory_bytes: 640
a, b = map(int, input().split())

def shouhi(n,a,b):
    if (int(n * 1.08) -n == a) & (int(n * 1.1) -n== b):
        return True
    return False
ou = False
for n in range(int(a / 0.08), int(a / 0.08) + 13):
    if shouhi(n,a,b):
        print(n)
        ou = True
        break
if not ou:
    print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int h,n; cin >> h >> n;
  vi a(n),b(n); rep(i,n) cin >> a[i] >> b[i];
  vi dp(h+1,INF);
  dp[0] = 0;
  rep(i,h+1){
    rep(j,n){
      chmin(dp[min(h,i+a[j])],dp[i]+b[j]);
    }
  }
  cout << dp[h];
  cout << "\n";
  return 0;
}


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

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

    if(a + b >= c){
        cout << "No" << endl;
    }else{
        c -= (a + b);
        c *= c;
        a *= b;
        a *= 4;
        if(c > a){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const ll LINF = 1LL<<60;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }

    int n, k; cin >> n >> k;
    set<int> s;
    for (int i = 0; i < k; i++) {
        int d; cin >> d;
        for (int j = 0; j < d; j++) {
            int a; cin >> a; s.insert(a);
        }
    }

    cout << (n-s.size()) << endl;

    return 0;
}

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

int main() {
    int N;
    string result;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;

    //cout << "OK" << endl;

    cin >> N;
    for(int i =0; i < N; i++){
        cin >> result;
        if(result == "AC"){
            ac++;
        }else if(result == "WA"){
            wa++;
        }else if(result == "TLE"){
            tle++;
        }else if(result == "RE"){
            re++;
        }   
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    return 0;
}

Measured memory_bytes: 3636
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,k = LI()
    s = S()
    r = 0
    a = 0
    t = '-'
    for c in s:
        if c == t:
            r += 1
        else:
            a += 1
        t = c
    kk = k * 2
    if a > kk:
        r += kk
    else:
        r += a - 1

    return r


print(main())



Measured memory_bytes: 5716
# -*- coding: utf-8 -*-
from heapq import heappush, heapreplace
from itertools import count, chain, cycle
from functools import partial
from math import floor, ceil, sqrt
from fractions import gcd
from collections import defaultdict, deque

def Primes_fnct():
    def b_search(L,t):
        #増大列LについてL[:+1]の要素すべてがt以下であるような最大のi<len(L)を返す。
        search_range = [-1, len(L)]
        update_range = lambda mid: search_range.__setitem__(t<L[mid], mid)
        for _ in [0]*search_range[1].bit_length():
            update_range(sum(search_range)//2)
        return search_range[0]
    
    P = [2,]
    Pappend = P.append
    Q = deque([])
    Qappend = Q.append
    Qpopleft = Q.popleft
    hq = [] 
    integer = count(3,2)
    current_i = 1
    valid_range = 1
    def Primes(*, max_int=None):
        nonlocal valid_range, current_i
        if max_int is None:
            return P[:]

        if  max_int - current_i <= 1:
            return P[:b_search(P,max_int)+1]

        for i in integer:
            if i >= valid_range:
                if Q:
                    q = Qpopleft()
                    heappush(hq, (q**2,q))
                valid_range = Q[0]**2 if Q else i**2

            m,r = hq[0] if hq else (0,0)
            if i != m:
                Pappend(i)
                Qappend(i)

            while m == i:
                heapreplace(hq, (m+2*r, r))
                m,r = hq[0]

            current_i = i
            if max_int - current_i <=1:
                break 
        return P[:]
    return Primes

def factorization(m, Primes=None):
    F = defaultdict(int)
    if m < 2:
        return F

    while not m&1:
        F[2] += 1
        m >>= 1

    if Primes is None:
        Primes = Primes_fnct()

    Primes = deque(Primes(max_int=ceil(sqrt(m))+1))
    Primespopleft = Primes.popleft

    while m > 1 and Primes:
        p = Primespopleft()
        while not m%p:
            m //= p
            F[p] += 1

    if m > 1:
        F[m] += 1
    return F

def solve():
    N = int(input())
    F = factorization(N)
    Q = sorted(F.items())
    P = [q[0] for q in Q]
    I = [q[1] for q in Q]
    i = [0 for _ in range(len(P)+1)]
    m = 1
    res = 0
    while any(a<b for a,b in zip(i,I)):
        if i[0] < I[0]:
            i[0] += 1
            m *= P[0]
        else:
            for j in range(0, len(P)):
                if i[j] < I[j]:
                    i[j] += 1
                    m *= P[j]
                    break
                else:
                    m //= P[j]**i[j]
                    i[j] = 0
        if N%(m-1) == N//(m-1):
            res += (m-1)

    return str(res)

if __name__ == '__main__':
    print(solve())




Measured memory_bytes: 9664
from collections import Counter

def main():
    n = int(input())
    a = Counter(map(int, input().split()))
    temp, a = listed(a)
    q = int(input())
    bc = [tuple(map(int, input().split())) for _ in range(q)]
    
    for b, c in bc:
        t = a[b]
        if t == 0:
            print(temp)
            continue
        a[b] = 0
        temp -= b*t
        a[c] += t
        temp += c*t
        print(temp)

def listed(a):
    x = [0] * (10**5 + 1)
    kei = 0
    for i,v in a.items():
        x[i] = v
        kei += i*v
    return kei, x

if __name__ == '__main__':
    main()

Measured memory_bytes: 24068
using System;

namespace ALDS1_2_B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] numbers = new int[n];
            int counter = 0;
            for (int i = 0; i < n; i++)
                numbers[i] = int.Parse(str[i]);

            for (int i = 0; i < n - 1; i++)
            {
                int minj = i;
                for (int j = i+1; j < n ; j++)
                {
                    if (numbers[j] < numbers[minj])
                        minj = j;
                }
                if (i != minj)
                {
                    int a = numbers[i];
                    numbers[i] = numbers[minj];
                    numbers[minj] = a;
                    counter++;
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (i == n - 1)
                {
                    Console.WriteLine("{0}", numbers[i]);
                    break;
                }
                Console.Write("{0} ", numbers[i]);
            }
            Console.WriteLine(counter);
        }
    }
}



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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

ll gcd(ll n, ll k)
{
    ll mod = n % k;
    if (mod == 0)
	return k;
    else
	return gcd(k, mod);

}

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

    int n;
    cin >> n;
    vector<ll> a(n);
    rep (i, 0, n)
	cin >> a[i];

    ll first = a[0];
    rep (i, 1, n) {
	first = gcd(first, a[i]);
    }

    cout << first << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 998244353;

int xcomp(pii& a, pii& b) {
	return a.first < b.first;
}

#define XSORT(c) sort((c).begin(),(c).end(),xcomp)

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

  LL N;
  cin >> N;
  vector<pii> v(N);
  REP(i,N){
    LL a;
    cin >> a;
    v[i] = {a, i};
  }

  XSORT(v);

  LL sum = 0;

  REP(i,N){
    if((v[i].second%2)^(i%2)){
      sum++;
    }
  }

  cout << sum/2 << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
using namespace std;


int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    double d, t, s;
    cin >> d >> t >> s;
    if(d/s <= t) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 3736
#include <stdio.h>

int A[1000];
int max,min;
int a,t,maxcnt,mincnt=0;
int sum,avg=0;
int result[1000];

//int w,h,x,y,r;

int main(void) {
  while(1){
    if(scanf("%d",&a) && a!=0){
      for(int i=0;i<a;i++){
        scanf("%d",&A[i]);
    }
    max=A[0];
    min=A[0];
      for(int i=1;i<a;i++){
        if(A[i]>max){
          max=A[i];
          maxcnt=i;
        }
        else if(A[i]<min){
          min=A[i];
          mincnt=i;
        }
      }
      A[maxcnt]=0;
      A[mincnt]=0;
      for(int i=0;i<a;i++){
        sum = sum + A[i];
      }
      avg=sum/(a-2);
      result[t] = avg;
      t++;
      max=0;
      min=0;
      maxcnt=0;
      mincnt=0;
      sum=0;
      avg=0;
    }
    else break;;
}

for(int i=0;i<t;i++){
printf("%d\n",result[i]);
}


    return 0;
  }



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

int main() {
    int N, K;
    cin >> N >> K;
    int l[N];
    for (int i=0; i<N; ++i) cin >> l[i];

    sort(l, l+N, greater<int>());
    int ans = 0;
    for (int i=0; i<K; ++i) ans += l[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>

using namespace std;

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

    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;

    int ans[n];
    fill(ans, ans+n, 0);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            ans[min(abs(i - j), abs(i - x) + abs(j - y) + 1)]++;
        }
    }

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

    return 0;
}


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

vector<int> a(200001);
int n;

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(),a.begin()+n);
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1024
let solve a b =
  if a mod 2 > 0 && b mod 2 > 0 then "Yes" else "No"

let () =
  let rec read () =
    try let ans = (Scanf.scanf "%d %d\n" solve) in
        Printf.printf "%s\n" ans
    with End_of_file -> ()
  in
  read ()
;;


Measured memory_bytes: 384
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
#include <queue>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = a+b;
    int y = c+d;
    if (x > y) cout << "Left" << std::endl;
    else if (x < y) cout << "Right" << std::endl;
    else cout << "Balanced" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	ll n,a,b,c,d,e;
	cin >> n >> a >> b >> c >> d >> e;
	ll tmp=min({a,b,c,d,e});
	if(tmp>=n) cout << 5 << endl;
	else if(n%tmp==0) cout << n/tmp+4 << endl;
	else cout << n/tmp+5 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,ans;
signed main(){
	ans=read();
	n=read();m=read();
	for(re int i=n;i<=m;++i){
		if(i%ans==0){
			puts("OK");
			return 0;
		}
	}
	return puts("NG"),0;
}


Measured memory_bytes: 3600
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 19 Jan 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String temp = br.readLine();
        st = new StringTokenizer(temp, " ");
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        br.close();

        if (a < b) for (int i = 0; i < b; i++) System.out.print(a);
        else for (int j = 0; j < a; j++) System.out.print(b);
    }
}


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

int main(){
    int a,b; cin>>a>>b;
    if(a>b){
        for(int i=0; i<a; i++) cout<<b;
        cout<<endl;
    }
    else{
        for(int i=0; i<b; i++) cout<<a;
        cout<<endl;
    }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            int N = fs.nextInt();
            int A = fs.nextInt();
            System.out.println(N % 500 <= A ? "Yes" : "No");
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 23380
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    xx = MII()
    xx_s = sorted(xx)
    ml = xx_s[n//2-1]
    mr = xx_s[n//2]
    # print(xx_s)
    # print(ml, mr)
    for x in xx:
        if x < mr: print(mr)
        elif x >= ml: print(ml)

if __name__ == '__main__':
    main()


Measured memory_bytes: 26772
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]

from collections import Counter
list_=[]

for i in range(N):
    for j in range(i+1,N):
        if xy[i][0]-xy[j][0]==0:
            list_.append(((xy[i][0]-xy[j][0]),abs(xy[i][1]-xy[j][1])))
        elif xy[i][0]-xy[j][0]<0:
            list_.append((-(xy[i][0]-xy[j][0]),-(xy[i][1]-xy[j][1])))
        else:
            list_.append((xy[i][0]-xy[j][0],xy[i][1]-xy[j][1]))

if N==1:
    print(1)
else:
    print(N-Counter(list_).most_common()[0][1])

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

int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
        long a, b, c, d, n;
        cin >> n >> a >> b >> c >> d;
        priority_queue<pair<long, long>, vector<pair<long, long>>, greater<>> q;
        q.emplace(0, n);
        map<long, long> m;
        m[n] = 0;
        while(q.top().second) {
            auto u = q.top().second;
            q.pop();
            auto v = u / 2;
            auto y = a + !!(u % 2) * d;
            auto l = m[u] + (y / d < u - v ? y : (u - v) * d);
            if(m.find(v) == m.end() || m[v] > l)
                q.emplace(m[v] = l, v);
            if(u % 2) {
                v = u / 2 + 1;
                l = m[u] + (y / d < u - v ? y : (u - v) * d);
                if(m.find(v) == m.end() || m[v] > l)
                    q.emplace(m[v] = l, v);
            }
            v = (u + 1) / 3;
            y = b + !!(u % 3) * d;
            l = m[u] + (y / d < u - v ? y : (u - v) * d);
            if(m.find(v) == m.end() || m[v] > l)
                q.emplace(m[v] = l, v);
            int x[] = {0, 1, 2, 2, 1};
            v = (u + 2) / 5;
            y = c + x[u % 5] * d;
            l = m[u] + (y / d < u - v ? y : (u - v) * d);
            if(m.find(v) == m.end() || m[v] > l)
                q.emplace(m[v] = l, v);
        }
        cout << m[0] << '\n';
    }
    return 0;
}


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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            char[] S = Console.ReadLine().ToArray();
            int K = int.Parse(Console.ReadLine());
            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] != S[K - 1]) 
                {
                    S[i] = '*';
                }
                Console.Write(S[i]);
            }

        }
    }
}

Measured memory_bytes: 11220
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

const int MAX_N = 100050;
const long long MOD = 1000000007;

int N;
std::string S;

long long cnt[30] = {};

int main(int argc, char **argv) {
    std::cin >> N;
    std::cin >> S;

    for (int i = 0; i < S.size(); i++) {
        cnt[S[i] - 'a']++;
    }

    long long ret = 1;
    for (int i = 0; i < 30; i++) {
        ret = (ret * (cnt[i] + 1)) % MOD;
    }

    std::cout << (ret - 1 + MOD) % MOD << std::endl;

    return 0;
}


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

void fnInput(llong& rnNum)
{
  cin >> rnNum;
}

void fnNumToName(llong nNum)
{
  const int cnnDivisor = 26;
  vector<int> vnRemain;
  llong nDividend = nNum;

  while ( nDividend )
  {
    --nDividend;
    int nRemain = nDividend % cnnDivisor;
    vnRemain.push_back( nRemain );

    nDividend /= cnnDivisor;
  }
  reverse(begin(vnRemain), end(vnRemain));

  for (int nRemain : vnRemain)
    cout << (char)('a' + nRemain);

  cout << endl;
}
  
int main()
{
  llong nNum;
  fnInput(nNum);
  fnNumToName(nNum);

  return 0;
}

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

#define rep(i, n) for(int i=0; i < n; i++)
#define REP(i, n, m) for(int i=n; i < m; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)

using namespace std;
using ll=long long;

ll mod=1000000007;

const ll INF = 1LL << 60;

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

int a,b,c,x,y;

int main() {
  cin>>a>>b>>c>>x>>y;
  int n=a*x+b*y;

  int mx=max(x,y)*2*c;
  int mi=min(x,y)*2*c+abs(x-y)*(x>y?a:b);
  cout << min(n,min(mx,mi));
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a,b,c,max=-1,ans,x,y;
    scanf("%i %i %i",&a,&b,&c);
    if(a>max){max=a;x=b;y=c;}
    if(b>max){max=b;x=a;y=c;}
    if(c>max){max=c;x=a;y=b;}
    x=max-x;
    y=max-y;
    if(x%2==0&&y%2==0)ans=x/2+y/2;
    else if(x%2==1&&y%2==1)ans=x/2+y/2+1;
    else
    {
        x++;
        if(x%2)ans=x/2+y/2+2;
        else
        ans=x/2+y/2+1;
    }
    printf("%i",ans);
    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<queue>
#include<climits> //INT_MIN/MAX
using namespace std;

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
#define debug(x) cout<<#x<<": "<<x<<endl
typedef long long ll;

/* 2017/01/21 問題 ----- ABC046 C /Link http://abc046.contest.atcoder.jp/tasks/arc062_a */
/* -----解説等-----
問題: シカのAtCoDeerくんは選挙速報を見ています。
選挙には二人の候補高橋くんと青木くんが出ています。
速報では、現在の二人の得票数の比が表示されていますが、得票数そのものは表示されていません。
AtCoDeerくんは N 回画面を見て、 i(1≦i≦N) 回目に見たときに表示されている比は Ti:Ai でした。
ここで、AtCoDeerくんが選挙速報の画面を1回目に見た段階で既にどちらの候補にも少なくとも一票は入っていたことがわかっています。
N 回目に画面を見たときの投票数(二人の得票数の和)として考えられるもののうち最小となるものを求めてください。
ただし、得票数が途中で減ることはありません。

1≦N≦1000
1≦Ti,Ai≦1000(1≦i≦N)
Ti と Ai は互いに素 (1≦i≦N)
答えが 10^18 以下になることは保証されている


*/

int N;
int T[1000], A[1000];
ll ans = 0;
ll nt, na, r;

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


    cin >> N;
    cin >> T[0] >> A[0];
    r = 1; nt = T[0]; na = A[0];

    FOR(i, 1, N) {
        cin >> T[i] >> A[i];
        r = max((nt + T[i] - 1) / T[i], (na + A[i] - 1) / A[i]);
        nt = T[i] * r;
        na = A[i] * r;
    }
    ans = nt + na;
    cout << ans << endl;

    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 51;
int n, m;
ii s[N], c[N];

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> s[i].first >> s[i].second;
    }
    for (int i = 0; i < m; ++i) {
        cin >> c[i].first >> c[i].second;
    }
    for (int i = 0; i < n; ++i) {
        ll ans = LLONG_MAX;
        ll ri = 0;
        for (int j = 0; j < m; ++j) {
            ll x = abs(s[i].first - c[j].first);
            ll y = abs(s[i].second - c[j].second);
            if (x + y < ans) {
                ans = x + y;
                ri = j;
            }
        }
        cout << ri + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

long factorization(long N);

int main(void){
  long N;
  char str[100];
  
  fgets(str,sizeof(str),stdin);
  N=atol(str);
  
  
  printf("%ld\n",factorization(N));
  
  
  return 0;
}

long factorization(long N){
  long ans,i;
  
  if(N==2){
    return 0;
  }
  
  for(i=1,ans=0;i*(i+1)<N;i++){
    if(N%i==0){
      ans+=N/i-1;
    }
  }
  
  return ans;
  
}

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

#define N1 4
#define N2 16

typedef struct{
  int a[N2],space,m;
}Puz;

int dx[4]={0,-1,0,1},dy[4]={1,0,-1,0},MDT[N2][N2],lim,path[100];

Puz st;

int getAllMD(Puz Z){
  int i,sum=0;

  for( i=0 ; i<N2 ; i++ ){
    if( Z.a[i] == N2 ) continue;
    sum+=MDT[i][Z.a[i]-1];
  }
  return sum;
}

void swap(int *a,int *b){
  int tmp;

  tmp=*a;
  *a=*b;
  *b=tmp;

}

char dfs(int df,int p){
  int sx,sy,tx,ty,i,max,min;
  Puz tmp;

  if( st.m==0 )return 1;
  if( df+st.m>lim )return 0;

  sx=st.space/N1;
  sy=st.space%N1;

  for( i=0 ; i<4 ; i++ ){
    tx=sx+dx[i];
    ty=sy+dy[i];

    if( tx<0||tx>=N1||ty<0||ty>=N1) 
        continue;

    if( p>i ){
        max=p;min=i;
        }
    else {
        max=i;min=p;
        }
    
    if( max-min==2 )
        continue;

    tmp=st;

    st.m-=MDT[tx*N1+ty][st.a[tx*N1+ty]-1];
    st.m+=MDT[sx*N1+sy][st.a[tx*N1+ty]-1];


    swap(&st.a[tx*N1+ty],&st.a[sx*N1+sy]);

    st.space=tx*N1+ty;
    if(dfs(df+1,i)){
      path[df]=i;
      return 1;
    }
    st=tmp;
  }
  return 0;
}

int id(Puz in){
  int i,anser=0;

  in.m=getAllMD(in);

  for(lim=in.m;lim<=100;lim++){
    st=in;
    if( dfs(0,-100) ){
      for( i=0  ; i<lim ; i++) 
         anser++;
      return anser;
    }
  }
  return -1;
}

int main(){
  int i,j;
  Puz in; 

  for( i=0 ; i<N2 ; i++ )
    for( j=0 ; j<N2 ; j++ )
      MDT[i][j]=abs(i/N1-j/N1)+abs(i%N1-j%N1);
  
  for( i=0 ; i<N2 ; i++ ){
    scanf("%d",&in.a[i]);
    if(in.a[i]==0){
      in.a[i]=N2;
      in.space=i;
    }
  }
  
  
  printf("%d\n",id(in));

  return 0;
}








Measured memory_bytes: 2140
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
template<typename X,typename M>
  struct segtree{
    using FX=function<X(X,X)>;
    using FA=function<X(X,M)>;
    using FM=function<M(M,M)>;
    int n;
    FX fx;
    FA fa;
    FM fm;
    const X ex;
    const M em;
    vector<X> dat;
    vector<M> lazy;
    segtree(int n_,FX fx_,FA fa_,FM fm_,X ex_,M em_)
      :n(),fx(fx_),fa(fa_),fm(fm_),ex(ex_),em(em_),dat(n_*4,ex),lazy(n_*4,em){
        int x=1;
        while(n_>x){
          x*=2;
        }
        n=x;
      }
    void set(int i,X x){
      dat[i+n-1]=x;
    }
    void build(){
      for(int k=n-2;k>=0;k--){
        dat[k]=fx(dat[2*k+1],dat[2*k+2]);
      }
    }
    void eval(int k){
      if(lazy[k]==em){
        return;
      }
      if(k<n-1){
        lazy[k*2+1]=fm(lazy[k*2+1],lazy[k]);
        lazy[k*2+2]=fm(lazy[k*2+2],lazy[k]);
      }
      dat[k]=fa(dat[k],lazy[k]);
      lazy[k]=em;
    }
    void update(int a,int b,M x,int k,int l,int r){
      eval(k);
      if(a<=l && r<=b){
        lazy[k]=fm(lazy[k],x);
        eval(k);
      }
      else if(a<r && l<b){
        update(a,b,x,k*2+1,l,(l+r)/2);
        update(a,b,x,k*2+2,(l+r)/2,r);
        dat[k]=fx(dat[k*2+1],dat[k*2+2]);
      }
    }
    void update(int a,int b,M x){
      update(a,b,x,0,0,n);
    }
    X query_sub(int a,int b,int k,int l,int r){
      eval(k);
      if(r<=a  || b<=l){
        return ex;
      }
      else if(a<=l && r<=b){
        return dat[k];
      }
      else{
        X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
        X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
        return fx(vl,vr);
      }
    }
    X query(int a,int b){
      return query_sub(a,b,0,0,n);
    }
  };
int main(){
  using X=int;
  using M=int;
  auto fx=[](X x1,X x2) -> X{return min(x1,x2);};
  auto fa=[](X x,M m) -> X{return x+m;};
  auto fm=[](M m1,M m2) -> M{return m1+m2;};
  int ex=numeric_limits<int>::max();
  int em=0;
  segtree<X,M> seg(100010,fx,fa,fm,ex,em);
  int i,n,q,a,b,c,d;
  cin >> n >> q;
  for(i=0;i<n;i++){
    seg.set(i,0);
  }
  seg.build();
  for(i=0;i<q;i++){
    cin >> a;
    if(a==0){
      cin >> b >> c >> d;
      seg.update(b,c+1,d);
    }
    else{
      cin >> b >> c;
      cout << seg.query(b,c+1) << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 5840