akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var N = LnInt();
        var n = 1L;
        var result = 0L;
        for (int i = 0; i < N; i++)
        {
            if (n % 5L == 0 && n % 3L == 0)
            {

            }
            else if (n % 5L == 0)
            {

            } else if (n % 3L == 0)
            {

            }
            else
            {
                result += n;
            }
                
            n++;
        }
        Console.WriteLine(result);
    }



    public static int[] LnInts()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        var ins = new int[vs.Length];
        for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]);
        return ins;
    }

    public static int LnInt()
    {
        var vs = Console.ReadLine().Trim();
        return int.Parse(vs);
    }

    public static string[] LnStrs()
    {
        var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
        return vs;
    }
    public static string LnStr()
    {
        var vs = Console.ReadLine().Trim();
        return vs;
    }
}

Measured memory_bytes: 27532
from sys import stdin
data = stdin.readlines()

n = list(data[0].split())[0]
k = int(list(data[0].split())[1])

l = [int(s) for s in data[1].split()]
l_sorted = sorted(l)

i = 1
price = 0
while i <= k:
    price += l_sorted[i-1]
    i += 1

print(price)

Measured memory_bytes: 8944
from operator import itemgetter
n,m = map(int,input().split())
lists = [list(map(int,input().split())) for i in range(m)]
for i in range(m):
    lists[i].append(i)
sort_lists = sorted(lists,key=itemgetter(0,1))
cnt = 1
ans = []
for i in range(m-1):
    tmp = sort_lists[i][0]
    left =  '{0:06d}'.format(tmp)
    right = '{0:06d}'.format(cnt)
    if tmp == sort_lists[i+1][0]:
        cnt += 1
    else:
        cnt = 1
    ans.append([str(left) + str(right),sort_lists[i][2]] )
tmp = sort_lists[-1][0]
left = '{0:06d}'.format(tmp)
right = '{0:06d}'.format(cnt)
ans.append([str(left) + str(right), sort_lists[-1][2] ])
ans.sort(key = itemgetter(1))
for i in range(m):
    print(ans[i][0])


#3 4
#1 45
#2 34
#3 56
#1 65

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

int main(){
while(1){
	int a,b,c,n,d[1000][4],ans[302];
	fill(ans,ans+302,2);
	scanf("%d%d%d",&a,&b,&c);
	if(a==0&&b==0&&c==0)break;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&d[i][0],&d[i][1],&d[i][2],&d[i][3]);
		if(d[i][3]==1){
			ans[d[i][0]]=1;
			ans[d[i][1]]=1;
			ans[d[i][2]]=1;
		}
	}
	for(int i=0;i<n;i++){
		if(d[i][3]==0)for(int j=0;j<3;j++){
			if(ans[d[i][(j+1)%3]]==1&&ans[d[i][(j+2)%3]]==1)ans[d[i][j]]=0;
		}
	}
	for(int i=1;i<a+b+c+1;i++){
		printf("%d\n",ans[i]);
	}
}
}

Measured memory_bytes: 1188
#include<stdio.h>
#include<math.h>
#include<map>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;

const int maxn = 200000 + 10;

struct Node
{
    int x, num;
    Node(){}
    Node(int x, int num)
    {
        this->x = x;
        this->num = num;
    }
    bool operator < (const Node & a) const {
        return this-> num < a.num;
    }
}a[maxn];

int main()
{
    int n,k;
    while(~scanf("%d%d",&n,&k) )
    {
        map<int, int> m;
        int cnt = 0;
        for(int i = 0; i < n; i++)
        {
            int x;
            scanf("%d",&x);
            if(m.count(x) == 0)
            {
                m[x] = cnt;
                a[cnt++] = Node(x,1);
            }
            else a[m[x]].num++;
        }

        sort(a, a+cnt);

        int count = 0;
        int i = 0;
        while(cnt > k)
        {
            cnt--;
            count += a[i++].num;
        }
        cout << count << endl;
    }
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;

#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define present(c,x) 	((c).find(x) != (c).end())
#define rep(i,n)        for(ll i=0LL; i<(n); i++)

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

//Maths functions
ll Digit(ll N){ll res=0;while(N) res++, N/=10;return res;}
ll Gcd(ll a,ll b){ return b?Gcd(b,a%b):abs(a); }


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

	set<ll> s;
	ll n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		ll x;
		cin>>x;
		s.insert(x);
	}
	if(s.size() != n)
		cout<<"NO";
	else cout<<"YES";
	
	return 0;
}

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

#include<iostream>
#include<set>
using namespace std;

int main() {
  int N;
  cin >> N;
  int  A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N);

  cout << A[N - 1] - A[0] << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

H, W = map(int, input().split())
S = [input() for i in range(H)]
visited = [[0] * W for i in range(H)]

def dfs(y, x):
    b, w = 0, 0
    if S[y][x] == '#': b += 1
    else: w += 1
    for dy, dx in ((0,1), (1,0), (0,-1), (-1,0)):
        ny, nx = y + dy, x + dx
        if ny < 0 or ny >= H or nx < 0 or nx >= W: continue
        if S[y][x] == S[ny][nx] or visited[ny][nx]: continue
        visited[ny][nx] = 1
        n, m = dfs(ny, nx)
        b += n
        w += m
    return (b, w)

ans = 0
for i in range(H):
    for j in range(W):
        if not visited[i][j]:
            visited[i][j] = 1
            b, w = dfs(i, j)
            ans += b * w
print(ans)


Measured memory_bytes: 156228
#include<iostream>

using namespace std;
int main()
{
	int n,ans = 1;
	cin >> n;
	for(int i=1; i<=n; i++){
		if(i == 64) ans = i;
		else if(i == 32) ans = i;
		else if(i == 16) ans = i;
		else if(i == 8) ans = i;
		else if(i == 4) ans = i;
		else if(i == 2) ans = i;
	}
	cout << ans << endl;
	
	return 0;
}


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

typedef long long ll;

int main()
{
    ll n,m;
    int i,j,k;
    cin >> n >> m;
    int a,b;
    ll c;
    vector<pair<ll,ll>> key;
    for(i = 0;i < m;++i){
        cin >> a >> b;
        ll s = 0;
        for(j = 0;j < b;++j){
            cin >> c;
            --c;
            s |= 1 << c;
        }
        key.emplace_back(s,a);
    }
    vector<ll> dp(1 << n,1e9);
    dp.at(0) = 0;
    for(i = 0;i < 1 << n;++i){
        for(j = 0;j < m;++j){
            ll tmp = i | key.at(j).first;
            dp.at(tmp) = min(dp.at(tmp),dp.at(i)+key.at(j).second);
        }
    }
    if(dp.back() == 1e9){
        cout << -1 << endl;
    }else{
        cout << dp.back() << endl;
    }
    return 0;
}

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

int n, k, a[200200];

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> a[i];
	for(int i=k+1;i<=n;i++) cout << (a[i] > a[i-k] ? "Yes" : "No") << "\n";
}

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

const int MOD = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	
	// 人数をカウント
	int red = 0;
	int blue = 0;
	int green = 0;
	
	ll res = 1;
	
	rep(i,n){
		int tmp = 0;
		if(a[i] == red){
			tmp++;
			if(tmp == 1) red++;
		}
		if(a[i] == blue){
			tmp++;
			if(tmp == 1) blue++;
		}
		if(a[i] == green){
			tmp++;
			if(tmp == 1) green++;
		}
		
		res = res * tmp % MOD;
	}
	
	cout << res << endl;
	return 0;
}

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

const int N = 1000001;
bool ip[N]; vector<int> ps;

int c[N];
vector<int> g[N];

int main(void) {
    fill_n(ip, N, 1); ip[1] = 0;
    for (int i = 2; i < N; ++i) {
        if (ip[i]) ps.push_back(i);
        for (int j : ps) {
            if (i * j >= N) break;
            ip[i * j] = 0;
            if (i % j == 0) break;
        }
    }

    for (int p : ps)
        for (int i = p; i < N; i += p)
            g[i].push_back(p);

    int n; scanf("%d", &n);
    int r = 0;
    for (int i = 1; i <= n; ++i) {
        int a; scanf("%d", &a);
        r = __gcd(r, a);
        for (int p : g[a])
            c[p]++;
    }

    int m = 0;
    for (int p : ps) m = max(m, c[p]);

    if (m <= 1) printf("pairwise coprime\n");
    else if (r == 1) printf("setwise coprime\n");
    else printf("not coprime\n");

    return 0;
}

Measured memory_bytes: 63944
import java.util.*;

public class Main {
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			int n = sc.nextInt();
			int m = sc.nextInt();
			double [][] data = new double[n][3];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < 3; j++){
					data[i][j] = sc.nextDouble();
				}
			}
			double totalmax = 0;
			for(int i = 0; i < (1 << n); i++){
				ArrayList<Integer> list = new ArrayList<Integer>();
				for(int j = 0; j < n; j++){
					if((i & (1 << j)) == 0) continue;
					list.add(j);
				}
				if(list.size() != m) continue;
				double sum = 0;
				for(int j = 0; j < list.size(); j++){
					for(int k = j + 1; k < list.size(); k++){
						int indj = list.get(j);
						int indk = list.get(k);
						double a = data[indj][0] - data[indk][0];
						double b = data[indj][1] - data[indk][1];
						double c = data[indj][2] - data[indk][2];
						double sumsq = a * a + b * b + c * c;
						sum += sumsq;
					}
				}
				totalmax = Math.max(totalmax, sum);
			}

			System.out.printf("%.8f\n",totalmax);
		}
	}
	
	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	FOR(i, 1, 10) FOR(j, 1, 10) {
		cout << i << "x" << j << "=" << i*j << endl;
	}
}

Measured memory_bytes: 3140
#include <iostream>

using namespace std;

int main()
{
  int a[4], b[4];
  int blow, hit;
  
  while(cin >> a[0]){
    cin >> a[1] >> a[2] >> a[3];
    cin >> b[0] >> b[1] >> b[2] >> b[3];
    hit = blow = 0;
    for(int i = 0; i < 4; i++){
      if(a[i] == b[i]){
        hit += 1;
      }
    }
    for(int i = 0; i < 4; i++){
      for(int n = 0; n < 4; n++){
        if(a[i] != b[i] && a[i] == b[n]){
          blow++;
        }
      }
    }
    cout << hit << " " << blow << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
  
  
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int maxN = 2e5 + 10;
const int MOD = 1e9 + 7;
const int M = 100000;
const int INF = 1e9;

char s[maxN];
char t[maxN]; 
int n,m;
int gcd(int x,int y)
{
	if(y==0)
	{
		return x;
	}
	int t = x%y;
	x = y;
	y = t;
	return gcd(x,y);
}
int main()
{
	scanf("%d %d",&n,&m);
	scanf("%s",s+1);
	scanf("%s",t+1);
	if(s[1] != t[1])
	{
		puts("-1");
		return 0;
	}
	int x = n;
	int y = m;
	if(x < y) swap(x,y);
	int g = gcd(x,y);
	ll f = (ll)x*y;
	f /= g;
	vector<ll> p;
	vector<ll> q;
	for(ll i=1;i<n;i++)
	{
		p.push_back(i*f/n + 1);
		//cout<<(i*f/n + 1)<<" ";
	}
	//cout<<endl;
	for(ll i=1;i<m;i++)
	{
		q.push_back(i*f/m + 1);
	//	cout<<(i*f/m + 1)<<" ";
	}
	//cout<<endl;
    for(int i=0;i<p.size();i++)
    {
    	int k = lower_bound(q.begin(),q.end(),p[i]) - q.begin();
    	if(p[i] != q[k]) continue;
    	else
    	{
    		if(s[i+2] != t[k+2])
    		{
    			puts("-1");
    			return 0;
			}
		}
	}
	printf("%lld\n",f);
	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	string s1, s2, s3;
	ll a = 0;
	ll b = 0;
	ll c = 0;
	string turn = "a";

	cin >> s1 >> s2 >> s3;

	s1 = s1 + "x";
	s2 = s2 + "x";
	s3 = s3 + "x";

	while (true) {
		if (turn == "a") {
			turn = s1[a];
			a++;
		}
		else if (turn == "b") {
			turn = s2[b];
			b++;
		}
		else if (turn == "c") {
			turn = s3[c];
			c++;
		}

		if (s1.size() - a == 0) {
			cout << "A" << endl;
			break;
		}else if (s2.size() - b == 0) {
			cout << "B" << endl;
			break;
		}else if (s3.size() - c == 0) {
			cout << "C" << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int aR = sc.nextInt();
    int bG = sc.nextInt();
    int cB = sc.nextInt();
    int k = sc.nextInt();

    for (int i = 0; i < k; i++) {
      if (aR >= bG) {
        bG = bG * 2;
        continue;
      }
      if (bG >= cB) {
        cB = cB * 2;
        continue;
      }
      break;
    }

    System.out.println(cB > bG && bG > aR ? "Yes" : "No");
  }
}

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


int main (){
    int N;
    cin>>N;
    vector<int> Vec(N);
    int count = 0;
    for(int i=0; i<N; i++){
        cin>>Vec.at(i);
        if(!(i+1==Vec.at(i))){
            count ++;
        }
    }
    if(count <3){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define INF 0x7FFFFFFF//or 0x3f3f3f3f ? -Wall
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n, m;
int a[N];
int vis[N];

int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++) a[i] = 1; vis[1] = 1;
	for (int i = 1, x, y; i <= m; i++) {
		read(x), read(y);
		vis[y] |= vis[x];
		a[x]--; a[y]++;
		if (a[x] == 0) vis[x] = 0;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) if (vis[i]) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        char[] chars = s.next().toCharArray();
        ArrayList<Integer> list = new ArrayList<>();
        for (char c : chars) {
            list.add(Character.getNumericValue(c));
        }
        long i = list.stream()
                .filter(n -> n == 0)
                .count();
        System.out.println(Math.min(i, list.size() - i) * 2);
    }
}

Measured memory_bytes: 29080
package main

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

// repr state of visited node
// WHITE yet visit
// GEAY  visiting
// BLACK visited
const (
	WHITE int = iota
	GRAY
	BLACK
)

type dfsGraph struct {
	g      [][]int
	colors []int
	stime  []int // Start time of visiting node
	ftime  []int // Finish time of visiting node
}

var time int

func makeAdjList() [][]int {
	var n int
	fmt.Scanf("%d", &n)

	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, n)
	}

	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		sc.Scan()
		nodeInfo := strings.Split(sc.Text(), " ")
		outDegree, _ := strconv.Atoi(nodeInfo[1])

		if outDegree > 0 {
			for k := 0; k < outDegree; k++ {
				j, _ := strconv.Atoi(nodeInfo[k+2])
				j-- // convert 1 based to 0 based
				adj[i][j] = 1
			}
		}
	}

	return adj
}

func (dg dfsGraph) dfsVisit(u int) {
	// 頂点uを訪問中に設定
	dg.colors[u] = GRAY
	time++
	dg.stime[u] = time

	// uの隣接nodeを訪問
	for v := 0; v < len(dg.g); v++ {
		if dg.g[u][v] == 0 {
			continue // 辺がなければスキップ
		}

		// vが未訪問なら訪問
		if dg.colors[v] == WHITE {
			dg.dfsVisit(v)
		}
	}

	// 頂点uを訪問済みに設定
	dg.colors[u] = BLACK
	time++
	dg.ftime[u] = time
}

func (dg dfsGraph) dfs() {
	for i := 0; i < len(dg.g); i++ {
		if dg.colors[i] == WHITE {
			dg.dfsVisit(i)
		}
	}
}

func (dg dfsGraph) printDfsTime() {
	for i := 0; i < len(dg.g); i++ {
		fmt.Printf("%d %d %d\n", i+1, dg.stime[i], dg.ftime[i])
	}
}

func main() {
	adj := makeAdjList()
	colors := make([]int, len(adj))
	stime := make([]int, len(adj))
	ftime := make([]int, len(adj))
	graph := dfsGraph{adj, colors, stime, ftime}
	graph.dfs()
	graph.printDfsTime()
}



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

using namespace std;

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

    if (min(B, D) - max(A, C) > 0)
    {

        cout << min(B, D) - max(A, C);
    }

    else
    {
        cout << 0;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
static const int MAX = 10000;

int solve_coin_changing1(vector<int> coins, int target) {
  vector<vector<int>> com = {{0}};
  com.push_back(coins);
  bool data[50000] = {false};

  for (int n = 2; n <= 10000; n++) {
    vector<int> b;
    cout << n << endl;
    for (int i = 1; i <= n / 2; i++) {
      for (int j = 0; j < com[i].size(); j++) {
        for (int k = j; k < com[n - i].size(); k++) {
          int val = com[i][j] + com[n - i][k];
          if (val == target) {
            return n;
          }
          if (!data[val]) {
            b.push_back(val);
            data[val] = true;
          }
        }
      }
    }
    cout << b.size() << endl;
    com.push_back(b);
  }
  return -1;
}
int solve_coin_changing2(vector<int> coins, int target) {
  int need_ncoin[50001];
  sort(coins.begin(), coins.end());
  auto cp = coins.begin();

  for (int i = 1; i <= target; i++) {
    if (*cp == i) {
      need_ncoin[i] = 1;
      cp++;
      continue;
    }
    int minimum = 50000;
    for (int j = 1; j <= i / 2; j++) {
      int ncoin = need_ncoin[i - j] + need_ncoin[j];
      minimum = min(minimum, ncoin);
      if (ncoin == 2)
        break;
    }
    need_ncoin[i] = minimum;
  }
  return need_ncoin[target];
}

#define T_NMAX 50000
#define NCOIN_MAX 20
int solve_coin_changing(vector<int> coins, int target) {
  sort(coins.begin(), coins.end());
  int need_ncoin[NCOIN_MAX][T_NMAX + 1];

  for (int j = 1; j <= target; j++) {
    need_ncoin[0][j] = j;
  }
  for (int i = 0; i <= coins.size(); i++) {
    need_ncoin[i][0] = 0;
  }

  for (int i = 1; i < coins.size(); i++) {
    for (int j = 1; j <= target; j++) {
      int use_i, not_use_i;
      not_use_i = need_ncoin[i - 1][j];
      use_i = j - coins[i] >= 0 ? need_ncoin[i][j - coins[i]] + 1 : T_NMAX;
      need_ncoin[i][j] = min(use_i, not_use_i);
    }
  }
  return need_ncoin[coins.size() - 1][target];
}

int main() {
  int ncoin, target;
  cin >> target >> ncoin;
  vector<int> coins;
  for (int i = 0; i < ncoin; i++) {
    int val;
    cin >> val;
    coins.push_back(val);
  }
  cout << solve_coin_changing(coins, target) << endl;
}

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

int my_fact(int i) {
    return i ? my_fact(i-1) * i : 1;
}

int my_func(vector<int> a) {
    int result = 0;
    int c_pow = a.size() - 1;

    for (int i = 0; i < a.size(); i++) {
        result += a.at(i) * pow(10, c_pow--);
    }

    return result;
}

int main() {
    int n;
    cin >> n;
    int fact_n = my_fact(n);

    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p.at(i);
    int p_n = my_func(p);
    vector<int> q(n);
    for (int i = 0; i < n; i++) cin >> q.at(i);
    int q_n = my_func(q);
    
    sort(p.begin(), p.end());

    vector<int> r(fact_n);
    int index = 0;
    do {
        r.at(index++) = my_func(p);
    } while (next_permutation(p.begin(), p.end()));

    int p_i, q_i;
    for (int i = 0; i < fact_n; i++) {
        if (p_n == r.at(i)) p_i = i;
        if (q_n == r.at(i)) q_i = i;
    }

    if (p_i > q_i) {
        cout << p_i - q_i << endl;
    } else {
        cout << q_i - p_i << endl;
    }

    return 0;
}


Measured memory_bytes: 3964
//専用ライブラリ
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
#define INF 10e6
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define PI acos(-1.0)
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int cmp(P a,P b){
        if(a.fi!=b.fi)
        return a.fi>b.fi;
        else
        return a.se<b.se;
}
//---------------------------------------------------------------------------
#define WHITE 0
#define GRAY 1
#define BLACK 2
int n;
vector<pair<int,int> >adj[10001];//邻接表表示法
void dijkstra(){
    priority_queue<pair<int,int> > pq;
    int color[10001];
    int d[10001];
    for(int i=0;i<n;i++){
        d[i]=INF;
        color[i]=WHITE;
    }
    d[0]=0;
    pq.push(make_pair(0,0));
    color[0]=GRAY;
    while(!pq.empty()){
        pair<int,int> f=pq.top();
        pq.pop();
        int u=f.second;
        color[u]=BLACK;
        if(d[u]<f.first*(-1))
            continue;
        for(int j=0;j<adj[u].size();j++){
            int v=adj[u][j].first;
            if(color[v]==BLACK)
                continue;
            if(d[v]>d[u]+adj[u][j].second){
                d[v]=d[u]+adj[u][j].second;
                pq.push(make_pair(d[v]*(-1),v));
                color[v]=GRAY;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<(d[i]==INF?-1:d[i])<<endl;
    }
}
//---------------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    cin>>n;
    
    int k,c,u,v;
    for(int i=0;i<n;i++){
        cin>>u>>k;
        for(int j=0;j<k;j++){
            cin>>v>>c;
            adj[u].push_back(make_pair(v,c));
        }
    }
    dijkstra();
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------



Measured memory_bytes: 8180
"use strict";

const main = arg => {
    const inputList = arg.trim().split("\n");
    // 回答を記述
    const target = parseInt(inputList[0]);
    const INTEREST = 1.01;
    let saveing = 100;
    let year = 0;
    while(true) {
        year++
        saveing = Math.floor(saveing * INTEREST);
        if (saveing >= target) {
            break;
        }
    }
    console.log(year)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29724
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int cl(int a, int b) {
	return (a - (a%b)) / b;//b=0だと積む
}
int up(int a, int b) {
	return cl(a + b - 1, b);//b=0だと積む
}
int ord(int a, int p) {
	if (a%p == 0) {
		return ord(a / p, p) + 1;
	}
	else {
		return 0;
	}
}
long long ruin(int a, int n, long long  p) {
	if (n == 0) {
		return (1%p);
	}
	else {
	long long x = ruin(a, (n - (n % 2)) / 2, p);
		if (n % 2 == 0) {
			return (x*x) % p;
		}
		else {
			return (((x*x) % p)*a) % p;
			
		}
	
	}
	
}
long long com(int n, int r, int p) {
	if (r == 0) {
		return (1%p);
	}
	else {
		long long x = com(n, r - 1, p);
		return (x*(n - r) / r) % p;
	}
}
long long sum(long long n, long long p) {
	if (n == 0) {
		return 0;
	}
	else {
		long long x = (n%p) + sum((n - (n%p)) / p, p);
		return x;
	}
}
int main() 
{
	int n, kai; long long ans = 0;
	cin >> n;
	vector<int> a(n - 1);
	for (int i = 0; i < n - 1; i++) {
		cin >> a[i];
	}
	cin >> kai;
	vector<long long> c(21,0);
	c[a[0]] = 1;
	vector<long long> yob(21);
	vector<long long>zer(21, 0);
	for (int i = 1; i < n - 1; i++) {
		yob = c;
		int x = a[i];
		c = zer;
		for (int j = 0; j <= 20; j++) {
			if (j >= x) {
				c[j - x] = c[j - x] + yob[j];
			}
			if (20 >= j + x) {
				c[j + x] = c[j + x] + yob[j];
			}
		}
	}
	cout << c[kai] << endl;
}



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

int main() {
	int t=1;
	//cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    vector<int> x(n),y(n);
	    vector<long long> pps(8,INT_MIN);
	    long long xs=0,ys=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>x[i]>>y[i];
	        xs+=x[i];
	        ys+=y[i];
	    }
	    xs/=n;
	    ys/=n;
	    for(int i=0;i<n;i++)
	    {
	        x[i]=x[i]-xs;
	        y[i]=y[i]-ys;
	        int qx,qy;
	        if(x[i]>0&&y[i]>0)//q1
	        {
	            qx=0;
	            qy=1;
	        }
	        else if(x[i]<=0&&y[i]>0)//q2
	        {
	            qx=2;
	            qy=3;
	        }
	        else if(x[i]<=0&&y[i]<=0)//q3
	        {
	            qx=4;
	            qy=5;
	        }
	        else //q4
	        {
	            qx=6;
	            qy=7;
	        }
	        if((pps[qx]==INT_MIN&&pps[qy]==INT_MIN)||(abs(pps[qx])+abs(pps[qy])<abs(x[i])+abs(y[i])))
            {
                pps[qx]=x[i];
                pps[qy]=y[i];
            }
	    }
	    
	    
	    long long ans=0;
	    for(int i=0;i<4;i++)
	    {
	        int qx=2*i;
	        int qy=qx+1;
	        //cout<<"for q"<<i+1<<" qx,qy="<<pps[qx]<<","<<pps[qy]<<"\n";
	        if(pps[qx]==INT_MIN&&pps[qy]==INT_MIN)
	            continue;
	        for(int j=0;j<n;j++)
	        {
	            //cout<<abs(pps[qx]-x[j])+abs(pps[qy]-y[j])<<" ";
	            ans=max(ans,abs(pps[qx]-x[j])+abs(pps[qy]-y[j]));
	        }
	        //cout<<endl;
	    }
	    
	    cout<<ans<<endl;
	    
	}
	return 0;
}

Measured memory_bytes: 4844
#include<stdio.h>

int main(void){

int a,b;
scanf("%d %d",&a,&b);
if(a<b){
printf("a < b\n");
}
else{
if(a>b){
printf("a > b\n");
}
else{
printf("a == b\n");
}

}

return 0;
}

Measured memory_bytes: 580
#include <iostream>
using namespace std;
int main(void){
double a,b;
cin >> a >> b;
double A = (a + b) / 2.0;
int  B = (a + b)/2;
double T = (a + b) / 2.0 - B;
if(T == 0.0)
cout << A <<endl;
else
cout << A - T + 1 << endl;

}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
const int MAXN=2e5+5;
int mp[MAXN],val[MAXN];
bool vis[MAXN];
struct edge
{
	int next,to,v;
}e[MAXN*10];
struct node
{
	int x,v;
	bool operator <(const node& a)const{
		return v>a.v;
	};
};
int cnt=0,n;
void add(int x,int y,int v)
{
	cnt++;
	e[cnt].v=v;
	e[cnt].to=y;
	e[cnt].next=mp[x];
	mp[x]=cnt;
}
priority_queue<node> q;
void dis()
{
	node k;
	k.v=0;k.x=n+1;
	q.push(k);
	while(!q.empty()){
		k=q.top();
		q.pop();
		if(vis[k.x]) continue;
		vis[k.x]=1;
		val[k.x]=k.v;
		for(int i=mp[k.x];i;i=e[i].next)
		if(!vis[e[i].to]){
			node p;
			p.x=e[i].to;
			p.v=k.v+e[i].v;
			q.push(p);
		}
	}
}
int main()
{
	int i,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	for(j=0;j<=9;j++)
	add(i,(i*10+j)%n,j);
	for(i=1;i<=9;i++) add(n+1,i,i);
	dis();
    printf("%d\n",val[0]);
    return 0;
 } 

Measured memory_bytes: 20976
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define ALL(v) (v).begin(),(v).end()
const ll MOD = 1e9 + 7;
 
int main() {
	int H, W, N;
	cin >> H >> W >> N;
	int sr, sc;
	cin >> sr >> sc;
	sr--; sc--;
	string S, T;
	cin >> S >> T;
	int l = 0, r = W - 1;
	if (S[N - 1] == 'L') l++;
	else if (S[N - 1] == 'R') r--;
	bool ok = 1;
	for (int i = N - 2; i >= 0; i--) {
		if (T[i] == 'L') r = min(r + 1, W - 1);
		else if (T[i] == 'R') l = max(l - 1, 0);
		if (S[i] == 'L') l++;
		else if (S[i] == 'R') r--;
		if (l > r) {
			ok = 0;
			break;
		}
	}
	if (l > sc || r < sc) ok = 0;
	l = 0, r = H - 1;
	if (S[N - 1] == 'U') l++;
	else if (S[N - 1] == 'D') r--;
	for (int i = N - 2; i >= 0; i--) {
		if (T[i] == 'U') r = min(r + 1, H - 1);
		else if (T[i] == 'D') l = max(l - 1, 0);
		if (S[i] == 'U') l++;
		else if (S[i] == 'D') r--;
		if (l > r) {
			ok = 0;
			break;
		}
	}
	if (l > sr || r < sr) ok = 0;
	if (ok) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 776
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    
    cout << (T / A)*B << endl;


    return 0;
}

Measured memory_bytes: 256
// ConsoleApplication12.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
using namespace std;

long long c[200005];
long long dp[2];
long long save[200005];

int main()
{
    int n;
    cin >> n;
    int now = -1;
    for (int i = 0; i != n; i++)
    {
        cin >> c[i];
        if (c[i] == now)
        {
            i--; n--;
        }
        now = c[i];
    }
    dp[0] = 1;
    save[c[0]] = 1;
    for (int i = 1; i != n; i++)
    {
        dp[i & 1] = (dp[!(i & 1)] + save[c[i]]) % 1000000007;
        save[c[i]] += dp[!(i & 1)];
        save[c[i]] %= 1000000007;
    }
    cout << dp[!(n&1)];
}



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



int main(){
  char c;
  cin>>c;

  if(c=='A') cout<<'T'<<endl;
  if(c=='T') cout<<'A'<<endl;
  if(c=='C') cout<<'G'<<endl;
  if(c=='G') cout<<'C'<<endl;

}


Measured memory_bytes: 256
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long R, long long G);

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

void Main(){
    long long R;
    scanf("%lld",&R);
    long long G;
    scanf("%lld",&G);
    solve(R, G);
}

void solve(long long R, long long G){
    cout << G*2-R << el;
}



Measured memory_bytes: 256
#include <iostream>
int items[1010];
int data[1010][4];

int main(){
    while(true){
        int a, b, c, n;
        std::fill(items, items+1010, 0);
        std::cin >> a >> b >> c;
        if(!a) break;
        std::cin >> n;
        for(int i = 1; i <= n; i++){
            std::cin >> data[i][0] >> data[i][1] >> data[i][2] >> data[i][3];
            if(data[i][3]){
                items[data[i][0]] = 1;
                items[data[i][1]] = 1;
                items[data[i][2]] = 1;
            }
        }
    //    int t;
    //    std::cin >>t>>t>>t;
        for(int j = 1; j <= n; j++){
            if(items[data[j][0]]+items[data[j][1]]+items[data[j][2]] == 2){
                if(!items[data[j][0]]) items[data[j][0]] = -1;
                if(!items[data[j][1]]) items[data[j][1]] = -1;
                if(!items[data[j][2]]) items[data[j][2]] = -1;
            }
        }

        for(int i = 1; i <= a+b+c; i++){
            switch (items[i]) {
            case 1:
                std::cout << 1 << std::endl;
                break;
            case 0:
                std::cout << 2 << std::endl;
                break;
            case -1:
                std::cout << 0 << std::endl;
                break;
            default:
                break;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 3048
import sys
def input():
	return sys.stdin.readline()[:-1]
sys.setrecursionlimit(10 ** 6)
 
class UnionFind():
	def __init__(self, size):
		self.length = size
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]
 
	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]
 
	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0
 
		return

	def get_size(self):
		cnt = 0
		for i in range(self.length):
			if self.table[i] < 0:
				cnt += 1
		return cnt

n, m = map(int, input().split())
uf = UnionFind(n)

for _ in range(m):
	x, y, z = map(int, input().split())
	uf.unite(x-1, y-1)

print(uf.get_size())

Measured memory_bytes: 7800
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, M: int, p: "List[int]", S: "List[str]"):
    seito = 0
    pena = 0

    AC = [False] * (N+1)
    WA = [0]*(N+1)
    for pp, ss in zip(p, S):
        if ss == "AC":
            if AC[pp] == False:
                AC[pp] = True
        else:
            if AC[pp] == False:
                WA[pp] += 1
    tot = 0
    for i in range(N+1):
        if AC[i]:
            tot += WA[i]
    print(sum(AC), tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    p = [int()] * (M)  # type: "List[int]"
    S = [str()] * (M)  # type: "List[str]"
    for i in range(M):
        p[i] = int(next(tokens))
        S[i] = next(tokens)
    solve(N, M, p, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 48348
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::cmp::max;

fn main() {
    let a: i64 = read();
    let b: i64 = read();
    let c: i64 = read();
    println!("{}", a + b+ c - max(a, max(b, c)));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;

int convert(string s){
  int n,sum=0;
  n=1;
  REP(i,s.size()){
    if(s[i] == 'm')sum += n*1000;
    else if(s[i] == 'c')sum += n*100;
    else if(s[i] == 'x')sum += n*10;
    else if(s[i] == 'i')sum += n;
    if('9'-s[i]>=0 && '9'-s[i]<8){n=s[i]-'0';}
    else n=1;
  }
  return sum;
}

int main(){
  int n;
  string s1,s2;
  cin >> n;
  REP(k,n){
    cin >> s1 >> s2;
    int sum = convert(s1) + convert(s2);
    int m = sum / 1000, c = (sum%1000)/100, x = sum%100/10, i = sum%10;
    if(m>1)cout << m << "m";
    else if(m==1) cout << "m";
    if(c>1)cout << c << "c";
    else if(c==1) cout << "c";
    if(x>1)cout << x << "x";
    else if(x==1) cout << "x";
    if(i>1)cout << i << "i";
    else if(i==1) cout << "i";
    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 3004
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
int mod = 998244353;
long double PI = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998626034825342117;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
#define int long long
using namespace std;
signed ae(long long b, long long c) {
    if (c == 1)return b;
    return (ae(b, c - 1)*b)%mod;
}
signed main() {
    int N; cin >> N;
    vector<long long>D(N);
    vector<long long>count(N);
    long long A = 0;
    rep(i, N) {
        cin >> D[i];
        count[D[i]]++;
        A = max(A, D[i]);
    }
    if (count[0] != 1||D[0]!=0) { puts ("0"); return 0; }
    long long ans = 1;
    REP(i, A + 1) {
        if (count[i] == 0) { puts("0"); return 0; }
        ans *= ae(count[i-1],count[i]);
        ans %= mod;
    }
    cout <<ans << endl;
}

Measured memory_bytes: 6244
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d,x,a[110],cnt=0;
  cin>>n>>d>>x;
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=0;i<n;i++){
    int t=1;
    while(t<=d){
      t+=a[i];
      cnt++;
    }
  }
  cout<<cnt+x;
}


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

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

int main() {
        int N;
        cin >> N;
        int result[4]={};
        string prompt[4]={"AC","WA","TLE","RE"};
        string dum;

        rep(i,N){
                cin >> dum;
                rep(i,4){
                        if(prompt[i] == dum) result[i]++;
                }
        }

        rep(i,4) cout << prompt[i] << " x " << result[i] << endl;
}

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

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair
#define pb push_back

int n;

vector <string> ans;
string tmp = "";

void rek(char c) {
  if ((int)tmp.size() == n) {
    ans.pb(tmp);
    return;
  }
  FOR(i, 'a', c + 2) {
    if (i <= 'z') {
      tmp += i;
      rek(max(c, (char)i));
      tmp.pop_back();
    }
  }
}

int main() {
  cin >> n;

  tmp += 'a';
  rek('a');

  sort(all(ans));
  ans.erase(unique(all(ans)), ans.end());
  for (auto t : ans) cout << t << endl;
  return 0;
}



Measured memory_bytes: 9588
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int N; string S; cin >> N >> S;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < S.size(); j++) {
			S[j]++;
			if (S[j] > 'Z') S[j] = 'A';
		}
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
def kth_smallest(a, k):
    accum = 0
    for elem in a:
        accum += elem[1]
        if accum >= k:
            return elem[0]


if __name__ == '__main__':
    n, k = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(n)]
    a.sort()
    print(kth_smallest(a, k))


Measured memory_bytes: 27872
#include <bits/stdc++.h> 
using namespace std;  
long INF=1000000000000000;
int main() {
    set<long> po={-1,-4,-8,-9,-16,-25,-27,-32,-36,-49,-64,-81,-100,-121,-125,-128,
    -144,-169,-196,-216,-225,-243,-256,-289,-324,-343,-361,-400,-441,-484,-512,-529,
    -576,-625,-676,-729,-784,-841,-900,-961,-1000};
    
    long X;
    cin>>X;
    
    cout<<-*(po.lower_bound(-X))<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
#include<numeric>
#include<iomanip>
#include<climits>
#include<queue>

using namespace std;
using ll = long long;

int main() {
    int v, e, r;
    cin >> v >> e >> r;
    vector<vector<pair<int, int>>> graph(v, vector<pair<int, int>>());
    vector<int> cost(v, INT_MAX);
    for (int i=0; i<e; ++i) {
        int s, t, d;
        cin >> s >> t >> d;
        graph[s].push_back(make_pair(t, d));
    }
    priority_queue<int> q;
    q.push(r);
    cost[r] = 0;
    while (!q.empty()) {
        int curr = q.top();
        q.pop();
        for (auto&e : graph[curr]) {
            if (cost[curr] + e.second < cost[e.first]) {
                cost[e.first] = cost[curr] + e.second;
                q.push(e.first);
            }
        }
    }
    for (auto& e: cost) {
        if (e == INT_MAX)
            cout << "INF" << endl;
        else
            cout << e << endl;
    }
}



Measured memory_bytes: 16252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x, mn = 1000000;
  cin >> n >> x;
  vector<int> m(n);
  for(int i=0; i<n; i++){
    cin >> m[i];
    x-=m[i];
    mn = min(mn,m[i]);
  }
  cout << n + x/mn << endl;  
}

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

int main() {
    string s;
    cin >> s;
    string gp = "gp";
    int wins = 0;
    int idx = 1;
    for (auto c : s){
        idx = 1 - idx;
        if (c == gp[idx]) continue;
        wins += 2 * idx - 1;
    }
    cout << wins << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using cd = complex <double>;

const long long INF = 1e18; 
const int mod = 1e9 + 7;//200003;786433;998244353;
const double Pi = acos(-1);
  
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int a[200005], b[200005];

signed main()
{
	Fastio();
	cin >> n;
	for(int i = 1; i <= 2 * n - 1; i++)
	{
		cin >> a[i];
	}
	int l = 1, r = 2 * n - 1;
	while(l < r)
	{
		int mid = (l + r + 1) >> 1;
		int ll = 1, rr = 2 * n - 1;
		for(int i = n; i > 1; i--)
		{
			if(a[i] >= mid && a[i - 1] >= mid)
			{
				ll = i;
				break;
			}
			else if(a[i] < mid && a[i - 1] < mid)
			{
				ll = i;
				break;
			}
		}
		for(int i = n; i < 2 * n - 1; i++)
		{
			if(a[i] >= mid && a[i + 1] >= mid)
			{
				rr = i;
				break;
			}
			else if(a[i] < mid && a[i + 1] < mid)
			{
				rr = i;
				break;
			}
		}
		if(n - ll <= rr - n)
		{
			if(a[ll] >= mid)
			{
				l = mid;
			}
			else
			{
				r = mid - 1;
			}
		}
		else
		{
			if(a[rr] >= mid)
			{
				l = mid;
			}
			else
			{
				r = mid - 1;
			}
		}
	}
	cout << l;
}

Measured memory_bytes: 4388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N,M;
int P[100000],Y[100000]; vector<int> yd[100001];
int main(){
  cin>>N>>M;

  
  for(long long int i=0;i<M;i++){
cin>>P[i]>>Y[i];
 yd[P[i]].push_back(Y[i]);
  }

  for(ll i=0;i<N;i++){
    sort(yd[i+1].begin(),yd[i+1].end());
  }
  
  for(ll i=0;i<M;i++){
    printf("%06d",P[i]);
    printf("%06d",int(lower_bound(yd[P[i]].begin(),yd[P[i]].end(),Y[i])-yd[P[i]].begin())+1);
    printf("\n");
  }
}

Measured memory_bytes: 7808
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    long long ans = 0;
    long long cnt = 0;
    for (const auto& c : s) {
        if (c == 'B') cnt++;
        else ans += cnt;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3476