akhauriyash/Code-Regression huggingface dataset:
void main()
{
    string n = readln.chomp;

    n.count('2').writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

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

    int n, q, l, r, sum = 0;
    string s;
    cin >> n >> q >> s;
    int length = s.size();
    vector<int> yes(length);

    for (int i = 0; i < length-1; i++) {
        if ((s[i] == 'A') && (s[i+1] == 'C')) {
            yes[i] = sum;
            yes[++i] = ++sum;
        }
        else yes[i] = sum;
    }
    yes[length-1] = sum;

    while (q--) {
        cin >> l >> r;
        cout << (yes[r-1] - yes[l-1]) << endl;
    }
    return 0;
}

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

int n,a[300010],t[300010];
long long s1,s2;

void add(int x) {for (; x; x-=(x&-x)) t[x]++;}
int query(int x) {int ans=0; for (; x<=n; x+=(x&-x)) ans+=t[x]; return ans;}

int main()
{
	scanf("%d",&n),s1=s2=0;
	for (int i=1; i<=n; i++) 
	{
		scanf("%d",&a[i]);
		if ((a[i]&1)!=(i&1)) return puts("No"),0;
	}
	memset(t,0,sizeof(t));
	for (int i=1; i<=n; i++) s1+=query(a[i]),add(a[i]);
	if (s1%3!=0) return puts("No"),0;
	memset(t,0,sizeof(t));
	for (int i=1; i<=n; i+=2) s2+=query(a[i]),add(a[i]);
	memset(t,0,sizeof(t));
	for (int i=2; i<=n; i+=2) s2+=query(a[i]),add(a[i]);
	if (s2!=s1/3) return puts("No"),0;
	return puts("Yes"),0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

/**
 * C5
 */
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        double[] vec1 = {0, 0};
        double[] vec2 = {100, 0};
        print(vec1);
        koh(vec1, vec2, n);
        print(vec2);
    }

    public static double[] rotate(double[] vec1, double[] vec2){
        double[] vec3 = new double[2];
        vec3[0] = 0.5*(vec2[0]-vec1[0]-root3*vec2[1]+root3*vec1[1]) + vec1[0];
        vec3[1] = 0.5*(vec2[1]-vec1[1]+root3*vec2[0]-root3*vec1[0]) + vec1[1];
        return vec3;
    }

    private static double root3 = Math.pow(3, 0.5);

    private static void koh(double[] vec1, double[] vec2, int time){
        if(--time < 0) return;
        double[] vecl = {(2*vec1[0]+vec2[0])/3, (2*vec1[1]+vec2[1])/3};
        double[] vecr = {(vec1[0]+2*vec2[0])/3, (vec1[1]+2*vec2[1])/3};
        double[] vecc = rotate(vecl, vecr);
        koh(vec1, vecl, time);
        print(vecl);
        koh(vecl, vecc, time);
        print(vecc);
        koh(vecc, vecr, time);
        print(vecr);
        koh(vecr, vec2, time);
    }

    private static void print(double[] vec){
        System.out.println(vec[0] + " " + vec[1]);
    }
}



Measured memory_bytes: 32572
#include<bits/stdc++.h>
using namespace std;
char buf[1<<20],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))? 0 : *fs++;
}
inline int read()
{
    int s=0,w=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*w;
}
const long long mod=1e9+7;
int a[100100],n,kk;
long long fac[100100],inv[100100],ans=0;
inline long long poww(long long a,long long b)
{
	long long res=1;
	while(b)
	{
		if(b&1) res=res*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return res;
}
inline long long getcc(long long n,long long m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
int main()
{
	n=read();
	kk=read();
	fac[0]=1;
	int i=1;
	while(i<=n)
	{
		a[i]=read();
		fac[i]=fac[i-1]*i%mod;
		++i;
	}
	inv[n]=poww(fac[n],mod-2);
	i=n-1;
	while(i>=0)
	{
		inv[i]=inv[i+1]*(i+1)%mod;
		--i;
	}
	sort(a+1,a+n+1);
	i=n;
	while(i>=1)
	{
		if(n-i+1>=kk) ans-=getcc(n-i,kk-1)*a[i]%mod;
		ans%=mod;
		if(i>=kk) ans+=getcc(i-1,kk-1)*a[i]%mod;
		ans%=mod;
		--i;
	}
	ans+=mod;
	ans%=mod;
	printf("%lld\n",ans);
	return 0;
}
/*
1996Äê£º¶«·½ÁéÒì´«£¨TOH1£©
1997Äê£º¶«·½·âÄ§Â¼£¨TOH2£©
1997Äê£º¶«·½ÃÎÊ±¿Õ£¨TOH3£©
1998Äê£º¶«·½»ÃÏëÏç£¨TOH4£©
1998Äê£º¶«·½¹Öç²Ì¸£¨TOH5£©
2002Äê£º¶«·½ºìÄ§Ïç£¨TOH6£©
2003Äê£º¶«·½ÑýÑýÃÎ£¨TOH7£©
2004Äê£º¶«·½ÝÍÃÎÏë£¨TOH7.5£©
2004Äê£º¶«·½ÓÀÒ¹³­£¨TOH8£©
2005Äê£º¶«·½»¨Ó³Ú££¨TOH9£©
2005Äê£º¶«·½ÎÄ»¨Ìû£¨TOH9.5£©
2007Äê£º¶«·½·çÉñÂ¼£¨TOH10£©
2008Äê£º¶«·½ç³ÏëÌì£¨TOH10.5£©
2008Äê£º¶«·½µØÁéµî£¨TOH11£©
2009Äê£º¶«·½ÐÇÁ«´¬£¨TOH12£©
2009Äê£º¶«·½·ÇÏëÌìÔò£¨TOH12.3£©
2010Äê£º¶«·½ÎÄ»¨ÌûDS£¨TOH12.5£©
2010Äê£º¶«·½ÈýÔÂ¾«£¨TOH12.8£©
2011Äê£º¶«·½ÉñÁéÃí£¨TOH13£©
2013Äê£º¶«·½ÐÄç²Â¥£¨TOH13.5£©
2013Äê£º¶«·½»ÔÕë³Ç£¨TOH14£©
2014Äê£ºµ¯Ä»ÌìÐ°¹í£¨TOH14.3£©
2014Äê£º¶«·½ÉîÃØÂ¼£¨TOH14.5£©
2015Äê£º¶«·½ç¤Öé´«£¨TOH15£©
2017Äê£º¶«·½Æ¾ÒÀ»ª£¨TOH15.5£©
2017Äê£º¶«·½Ìì¿Õè°£¨TOH16£©
*/

Measured memory_bytes: 2176
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    ABC = LI()

    ABC.sort()

    print(ABC[0] + ABC[1] + 10 * ABC[2])

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10080
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,k = iim()
n = n%k
print(min(n,abs(n-k)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	int n;
	cin>>n;
	vector<int> a(n);
	ll s1=0,s2=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		s1+=a[i];
	}
	ll ans=INT_MAX;
	for(int i=0;i<n;i++)
	{
		s2+=a[i];
		ans = min(ans,static_cast<ll>(abs(s2*2-s1)));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int r = 0;
    int w = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == 'R') r++;
        else w++;
    }
    int ans = 0;
    for(int i = 0; i < r; i++)
    {
        if(s[i] == 'W') ans++;
    }
    cout << ans << endl;

}




Measured memory_bytes: 3716
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
 
int main() {
    int N;
    cin >> N;
    int A[2][N];
    rep(i, 2) {
        rep(j, N) {
            cin >> A[i][j];
        }
    }
    int counter = 0;
    int ans = 0;
 
    rep(j, N) {
        rep(k, j+1) {
            counter += A[0][k];
        }
        for(int k = j; k < N; k++) {
            counter += A[1][k];
        }
        if(ans < counter) {
            ans = counter;
        }
        counter = 0;
    }
 
    cout << ans;
    
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  int a[N];
  REP(i, N) cin >> a[i];

  ll ans = 0;
  REP(i, N) {
    ans += a[i] / 2;
    if(i == N - 1) break;
    if(a[i] % 2 == 1 && a[i + 1] >= 1) {
      ans++;
      a[i]--;
      a[i + 1]--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 768
from sys import setrecursionlimit
setrecursionlimit(10 ** 9)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.d = [-1] * n

    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.d[x]
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return False
        else:
            if self.d[x] > self.d[y]:
                x, y = y, x
            self.d[x] += self.d[y]
            self.d[y] = x
            return True

    def same(self, x, y):
        return self.find(x) == self.find(y)


    def size(self, x):
        return -self.d[self.find(x)]


n, m, k = map(int,input().split())
fb = [0] * n
uf = UnionFind(n)
for i in range(m):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    uf.unite(a, b)
    fb[a] += 1
    fb[b] += 1

for j in range(k):
    c, d = map(int, input().split())
    c -= 1
    d -= 1
    if uf.same(c, d) == True:
        fb[c] += 1
        fb[d] += 1

for i in range(n):
    print(uf.size(i) - fb[i] - 1)

Measured memory_bytes: 94936
from collections import deque
ans = deque()
n = int(input())
al = list(map(int,input().split()))

r = True

for i in al:
  if r:
    r = False
    ans.append(i)
  else:
    r = True
    ans.appendleft(i)
s = [str(i) for i in ans]
if len(al) % 2 == 1:
  s.reverse()
print(' '.join(s))

Measured memory_bytes: 32964
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
using namespace std;

int n, used[100000];
pair<int, int> w[100000], s[100000];
int check[2][100000];

bool ok(int d){
  memset(check, 0, sizeof(check));
  

  check[0][w[0].second] = 2;
  int upper = w[0].first, under = w[n - 1].first;
  for(int i = 0;i < n;i++){
    if(abs(upper - w[i].first) > d && abs(under - w[i].first) > d){
      return false;
    }
    if(abs(upper - w[i].first) > d ){
      check[0][w[i].second] = 1;
    }
    if(abs(under - w[i].first) > d){
      check[0][w[i].second] = 2;
    }
  }
  
  check[1][s[0].second] = 2;
  upper = s[0].first;
  under = s[n - 1].first;
  for(int i = 0;i < n;i++){
    if(abs(upper - s[i].first) > d && abs(under - s[i].first) > d){
      return false;
    }
    if(abs(upper - s[i].first) > d){
      check[1][s[i].second] = 1;
    }
    if(abs(under - s[i].first) > d){
      check[1][s[i].second] = 2;
    }
  }
  int differ = 0, both = 0;
  for(int i = 0;i < n;i++){
    if(check[0][i] == 0 || check[1][i] == 0)both++;
    else if(check[0][i] != check[1][i])differ++;
  }
  return (differ == 0 || both + differ == n);
  
}

int main(){
  scanf("%d", &n);
  for(int i = 0;i < n;i++){
    int x, y;
    scanf("%d%d", &x, &y);
    w[i] = make_pair(x + y, i);
    s[i] = make_pair(x - y, i);
  }
  sort(w, w + n);
  sort(s, s + n);
  int up = 1 << 20, down = 0;
  while(up - down > 5){
    int mid = (up + down) / 2;
    if(ok(mid)){
      up = mid;
    }
    else{
      down = mid;
    }
  }
  while(ok(--up));
  printf("%d\n", up + 1);
  return 0;
}

Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> pii;
const int INF = 1e9;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> g(h);
	rep(i,h) cin >> g[i];
	queue<pii> q;
	vector<vector<int>> dist(h, vector<int>(w,INF));
	auto push = [&](int i, int j, int k) {
		if (i < 0 || i >= h || j < 0 || j >= w) return;
		if (g[i][j] == '#') return;
		if (dist[i][j] != INF) return;
		dist[i][j] = k + 1;
		q.push(pii(i,j));
	};
	push(0,0,0);
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		rep(d,4) {
			push(p.first + dy[d], p.second + dx[d], dist[p.first][p.second]);
		}
	}
	if (dist[h-1][w-1] == INF) cout << -1 << endl;
	else {
		int cnt = 0;
		rep(i,h) rep(j,w) if (g[i][j] == '#') cnt++;
		cout << h * w - dist[h-1][w-1] - cnt << endl;
	}
}

Measured memory_bytes: 3560
#include <iostream>
#include<algorithm>
#define INF 2000001;
using namespace std;
int main(void){
    int N;
    long long int cnt =0,ans =0;
    cin >> N;
    int a,b,temp;
    long long int d_digit[10][10] = {};
    for(int i=1;i<=N;i++){
        temp = 1;
        cnt = 0;
        a = i % 10;
        if(a == 0)continue;
        b = i;
        while(b / 10 != 0){
            b /= 10;
            temp *= b;
            temp *= 10;
            cnt++;
        }
        d_digit[a][b]++;
    }
    for(int i=1;i<10;i++)for(int j=1;j<10;j++){
    ans += d_digit[i][j] * d_digit[j][i];
    }
    /*
    for(int i=1;i<10;i++){for(int j=1;j<10;j++){
        cout <<  d_digit[i][j] * d_digit[j][i] << " ";
    }
    cout << endl;
    }
    */
    cout << ans<< endl;
   // for(int i=0;i<10;i++)cout << digit[i] << " ";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int A, B;
	scanf("%d %d", &A, &B);
	
	int x, count = 0;
	for (x = A; x <= B; x++) {
		if ((x / 10000) % 10 != x % 10) continue;
		if ((x / 1000) % 10 != (x / 10) % 10) continue;
		count++;
	}
	
	printf("%d\n", count);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(){
	int k,t,result=0;
	while(1){
		cin >> k;
		if(k==0) break;
		for(int i=0;i<k*(k-1)/2;i++){
			cin >> t;
			result+=t;
		}
		cout << result/(k-1) << endl;
		result=0;
	}
}

Measured memory_bytes: 0
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,k=LI()
  
  l=[0]*(n+1)
  for _ in range(k):
    a,b=LI()
    l[a-1]+=1
    l[b]-=1

  for i in range(n-1):
    l[i+1]+=l[i]

  ans=0
  for x in l[:-1]:
    if x==k:
      ans+=1

  return ans

print(main())


Measured memory_bytes: 10180
# coding: utf-8

import sys
import bisect


def solve(N, a):
    dp = [float("inf")] * N
    for i in range(N):
        ins_p = bisect.bisect_left(dp, a[i])
        if dp[ins_p] != a[i]:
            dp[ins_p] = a[i]
    # sys.stderr.write(str(dp) + "\n")
    for i in range(N):
        if dp[i] == float("inf"):
            return i
    return N


def main():
    N = int(input())
    a = [None] * N
    for i in range(N):
        a[i] = int(input())

    print(solve(N, a))


main()

Measured memory_bytes: 12316
from sys import stdin

n = int(stdin.readline().rstrip())
d = sorted([int(x) for x in stdin.readline().rstrip().split()])

a = d[(n//2)-1]
b = d[n//2]

if a == b:
    print(0)
else:
    c = [i for i in range(a+1, b+1)]
    print(len(c))


Measured memory_bytes: 14556
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define int long long
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N=1e4+5;
int n,a[N],b[N],cur=0;
signed main() {
	#ifdef aome
	in("aome.inp");	
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	fw (i,0,n) cin>>a[i];
	fw (i,0,n) cin>>b[i];
	/*
	Call c[i] and d[i] the number of operations that was applied on the ith element of a and b
	Then: 2 * c[i] - d[i] = b[i] - a[i]
	We have to assign c and d values so that their total sum is equal
	For all negative b - a, assign d = b - a. Get their total sum, then keep incrementing c on positive
	ones.
	*/
	fw (i,0,n) {
		if (b[i]-a[i]<0) cur+=(a[i]-b[i]);
	}
	int cur2=0;
	fw (i,0,n) if (b[i]-a[i]>=0) {
		cur2+=(b[i]-a[i])/2;	
	}
	//cout<<"cur = "<<cur<<", cur2 = "<<cur2<<"\n";
	if (cur<=cur2) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

using namespace std;

template <typename T>
using Ve = vector<T>;

typedef long double ld;
typedef long long ll;

#define FO(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define FOll(i, N) for (ll (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";
#define MP(x, y) (make_pair((x), (y)))
#define MT(...) make_tuple(__VA_ARGS__)
#define G(i, x) get<i>(x)
#define ALL(x) begin(x), end(x)

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

	ll A,B,C,X,Y;
	cin >> A>>B>>C>>X>>Y;

	ll ans = 1e18;

	FOll(i, 300000) {
		ll makea = i/2, makeb = i/2;

		ll rema = X-makea, remb = Y-makeb;

		if (rema < 0) {
			rema = 0;
		}

		remb = max(0ll, remb);

		ans = min(ans, i*C + rema*A + remb*B);
	}

	cout<< ans << endl;


	
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = [0,0]
ans[0]=A[-1]
import bisect

mid = ans[0]/2
ind = bisect.bisect(A,mid)
ans[1]=A[ind-1] if mid-A[ind-1]<=A[ind]-mid else A[ind]

print(*ans)

Measured memory_bytes: 14052
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,K,uc=0;
    string S;
    cin>>N>>K;
    string s[N];
    cin>>S;
    rep(0,i,N)s[i]=S.substr(i,1);
    rep(0,i,N){
        if((i==0 &&s[i]=="L")||(i==N-1&&s[i]=="R")){
            ++uc;
        }else{
            if(s[i]=="L"){
                if(s[i]!=s[i-1])++uc;
            }else{
                if(s[i]!=s[i+1])++uc;
            }
        }
    }
    ll ans=N-(uc-2*K);
    if(ans<N-1){
        cout<<ans<<endl;
    }else{
        cout<<N-1<<endl;
    }
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
using namespace std;

int main(){
	int D,N;
	cin >> D>>N;
	int ans = N;
	if (N == 100)ans = 101;
	for (int i = 0; i < D; i++) {
		ans *= 100;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
INF = 10 ** 20
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


class Dinic:
    """ 最大流(Dinic) """


    def __init__(self, n):
        self.n = n
        self.links = [[] for _ in range(n)]
        self.depth = None
        self.progress = None

    def add_link(self, _from, to, cap):
        self.links[_from].append([cap, to, len(self.links[to])])
        self.links[to].append([0, _from, len(self.links[_from]) - 1])

    def bfs(self, s):
        from collections import deque

        depth = [-1] * self.n
        depth[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for cap, to, rev in self.links[v]:
                if cap > 0 and depth[to] < 0:
                    depth[to] = depth[v] + 1
                    q.append(to)
        self.depth = depth

    def dfs(self, v, t, flow):
        if v == t:
            return flow
        links_v = self.links[v]
        for i in range(self.progress[v], len(links_v)):
            self.progress[v] = i
            cap, to, rev = link = links_v[i]
            if cap == 0 or self.depth[v] >= self.depth[to]:
                continue
            d = self.dfs(to, t, min(flow, cap))
            if d == 0:
                continue
            link[0] -= d
            self.links[to][rev][0] += d
            return d
        return 0

    def max_flow(self, s, t):
        flow = 0
        while True:
            self.bfs(s)
            if self.depth[t] < 0:
                return flow
            self.progress = [0] * self.n
            current_flow = self.dfs(s, t, INF)
            while current_flow > 0:
                flow += current_flow
                current_flow = self.dfs(s, t, INF)


def main():
    N = NI()
    R = [NLI() for _ in range(N)]
    B = [NLI() for _ in range(N)]
    din = Dinic(2*N+2)
    for a, b in R:
        for c, d in B:
            if a >= c or b >= d: continue
            din.add_link(a, c, 1)
    for a, b in R:
        din.add_link(2*N, a, 1)
    for c, d in B:
        din.add_link(c, 2*N+1, 1)
    print(din.max_flow(2*N, 2*N+1))



if __name__ == "__main__":
    main()

Measured memory_bytes: 9772
#include<bits/stdc++.h>
#define rp(i,n) for(long long i=0; i<n; i++)
using namespace std;
using ll=long long;
ll com2 (ll n){
  return (n*(n-1)/2);}
int main(){
  ll n;
  cin >>n;
  
  vector <ll> p(n+1,0);
  vector <ll> a(n);
  vector <ll> ans(n+1,0);
  
  rp(i,n){
    cin >> a.at(i);
  }
  rp(i,n){
    p.at(a.at(i))++;
  }
  ll sum=0;
  
  for(ll i=1; i<=n; i++){
    sum+=com2(p.at(i));
  }
  rp(i,n)
    cout<< sum+1-p.at(a.at(i)) <<endl;
  return 0;
}


Measured memory_bytes: 7296
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            List<Integer> m_f_r = Stream.of(sc.nextLine().split(" "))
                    .map(Integer::parseInt)
                    .collect(Collectors.toList());
            if (m_f_r.stream().allMatch(i -> i == -1)) {
                break;
            }

            int m = m_f_r.get(0);
            int f = m_f_r.get(1);
            int m_f = m + f;
            int r = m_f_r.get(2);

            if (m == -1 || f == -1) {
                System.out.println('F');
            } else if (m_f >= 80) {
                System.out.println('A');
            } else if(m_f >= 65) {
                System.out.println('B');
            } else if (m_f >= 50 || r >= 50) {
                System.out.println('C');
            } else if (m_f >= 30) {
                System.out.println('D');
            } else {
                System.out.println('F');
            }
        }
    }
}




Measured memory_bytes: 32236
import math
N = int(input())
A = [int(x) for x in input().split()]
B = A.copy()
max =-1
for i in range(len(A)):
    if(A[i] > max):
        max = A[i]
        B[i] = A[i]
    else:
        B[i] = max

C = [B[i] - A[i] for i in range(len(A))]

print(sum(C))


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

/*
evenness - min humps
no reason to overlap
"already paying"
no reason to not match an adj column? -> no bridging
same as deleting k columns -> adding a row can only worse the situation, so we always want to delete
always want to delete -> which ones?
could do dp (range & left & right) -> N^4 states, O(1) trans
if you include 1 everything else lesser is free, however everything else you include you possibility
-> state of "current height, current position, #used" 
for each state either use or don't use the next one O(n^3) states, O(1) trans
*/
typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,k;	
	cin >> n >> k;
	int a[n+1];
	a[0] = 0;
	for(int i = 1;i <= n; ++i)cin >> a[i];
	ll dp[n+1][n+1][k+1] = {};
	const ll inf = 1LL << 60;
	fill(&dp[0][0][0], &dp[0][0][0] + sizeof(dp)/sizeof(dp[0][0][0]), inf);
	dp[0][0][0] = 0;
	for(int i = 0;i < n; ++i){
		for(int h = 0;h < n; ++h){
			for(int nk = 0; nk <= k; ++nk){
				// take	
				dp[i+1][i+1][nk] = min(dp[i+1][i+1][nk], dp[i][h][nk] + max(a[i+1] - a[h], 0));
				// dont
				if(nk != k){
					dp[i+1][h][nk+1] = min(dp[i+1][h][nk+1], dp[i][h][nk]);
				}
			}
		}
	}
	ll ans = *min_element(&dp[n][0][0], (&dp[n][n][k]) + 1);
	cout << ans << '\n';
}


Measured memory_bytes: 213376
from collections import deque
H, W = map(int, input().split())
s = []
for _ in range(H):
    s.append(input())
queue = deque([[0,0]])
dist = [[-1 for j in range(W)] for i in range(H)]
dist[0][0] = 0
dh = [0, 0, 1, -1]
dw = [1, -1, 0, 0]
while len(queue) != 0:
    now = queue.popleft()
    h = now[0]
    w = now[1]
    for i in range(4):
        nh = h + dh[i]
        nw = w + dw[i]
        if nh < 0 or nw < 0 or nh >= H or nw >= W:
            continue
        elif dist[nh][nw] == -1 and s[nh][nw] == ".":
            queue.append([nh, nw])
            dist[nh][nw] = dist[h][w] + 1
ans = 0
if dist[H-1][W-1] == -1:
    print(-1)
    exit()

for i in range(H):
    for j in range(W):
        if s[i][j] == ".":
            ans += 1
ans = ans - dist[H-1][W-1] -1
print(ans)

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

int main(){
    
    while(1){
        string input;
        cin >> input;
        if(input == "-") break;
        int snum;
        cin >> snum;
        for(int i = 0; i < snum; i++){
            int move;
            cin >> move;
            string movestr = input.substr(0, move);
            input.erase(0, move);
            input += movestr;
        }
        cout << input << endl;
    }
    return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define ub upper_bound
#define lb lower_bound
#define F first
#define S second

int main(){
    fastio;
    ll n,k;
    cin >> n >> k;
    vector<ll> t(n+1);
    
    for(ll i=1; i<=n; i++){
        cin >> t[i];
    }

    map<ll, bool> v;
    map<ll, ll> s;

    ll cur = 1, i;

    for(i=1; i<=k; i++){
        if(v[cur]) break;
        v[cur] = true;
        s[cur] = i;
        cur = t[cur];
    }

    ll stt = k-i+1;
    ll loops = i - s[cur];
    if(loops == 0){
        cout << cur << endl;
        return 0;
    }    

    stt%= loops;

    for(i=1;i<= stt; i++){
        cur = t[cur];
    }
    cout << cur << endl;
    return 0;
}

Measured memory_bytes: 24752
#include<iostream>
 #include<vector>
#include<algorithm>
#include<stdio.h>
using namespace std ;
int arr[100005][2],k[100005];
int main()
{
    int n,m,a=0,w=0;
    cin >> n >> m ;
    for(int i=0;i<m;i++)
    {
        int x ;
        string s ;
        cin >> x >> s ;
        if(s=="WA" && arr[x][1]==0){k[x]++;}
        if(s=="AC" && arr[x][1]==0){a++;arr[x][1]=1;w+=k[x];}
    }
    cout << a << " " << w << endl;
    return 0 ;
}



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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

bool p[110][110];
int l[110];

int main(void){
	int n;
	while(cin >>n){
		if(n==0)
			break;
		rep(i,110)rep(j,110) p[i][j]=false;
		range(i,1,n+1){
			int m;
			cin >> m;
			rep(j,m){
				int in;
				cin >> in;
				p[i][in]=true;
			}
		}
		int k;
		cin >> k;
		rep(i,k) cin >> l[i];
		int ans=-1,num=0;
		range(i,1,n+1){
			bool ok=true;
			rep(j,k) if(!p[i][l[j]]) ok=false;
			if(ok)
				num++,ans=i;
		}
		if(num==1)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int A = 0;
		int B = 0;
		String S = scan.next();
		String[] str = S.split("");
		for(int i = 0; i < S.length(); i++) {
			if(str[i].equals("A")) {
				A = i;
				break;
			}
		}
		for(int j = S.length()-1; j > 0; j--) {
			if(str[j].equals("Z")) {
				B = j;
				break;
			}
		}
		System.out.println(B - A + 1);
		scan.close();
	}
}


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

using namespace std;
typedef long long ll;

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

    int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }

    vector<int> a(100001);
    for (int i = 1; i < 100000; i++) {
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    vector<int> s(100001);
    for (int i = 0; i < 100001; i++) {
        s[i+1] = s[i] + a[i];
    }


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


Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            String[] S = new String[N];
            for (int i = 0; i < N; i++) {
                S[i] = sc.next();
            }

            Map<String, Integer> map = new HashMap<>();
            for (int i = 0; i < N; i++) {
                Integer count = map.get(S[i]);
                if (count == null) {
                    count = 1;
                } else {
                    count = count + 1;
                }

                map.put(S[i], count);
            }

            int max = 0;
            for (Integer count : map.values()) {
                max = Math.max(max, count);
            }

            List<String> list = new ArrayList<>();
            for (Entry<String, Integer> entry : map.entrySet()) {
                if (entry.getValue() == max) {
                    list.add(entry.getKey());
                }
            }

            Collections.sort(list);

            StringBuilder ans = new StringBuilder();
            for (String s : list) {
                ans.append(s).append("\n");
            }

            System.out.print(ans.toString());
        }
    }

}


Measured memory_bytes: 83560
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	char s[200],t[200],ans[300];
	cin>>n;
	for(int i=1;i<=n;i++) cin>>s[i];
	for(int j=1;j<=n;j++) cin>>t[j];
	for(int i=1;i<=n;i++){
		cout<<s[i]<<t[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
#include<bitset>
#include<vector>
#include<deque>
using namespace std;
#define re register int
inline int read(){
	int x=0,ff=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')ff=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return x*ff;
}
int n,k,a[100005],x,y,z,ans;
char c[100005];
int main(){
	n=read();k=read();x=read();y=read();z=read();
	scanf("%s",c+1);
	for(re i=1;i<=n;i++){
		if(c[i]=='s'){
			if(i<=k){
				ans+=x;a[i]=1;
			}
			else {
				if(a[i-k]==1){
					a[i]=-1;
				}
				else {
					ans+=x;a[i]=1;
				}
			}
		}
		if(c[i]=='p'){
			if(i<=k){
				ans+=y;a[i]=2;
			}
			else {
				if(a[i-k]==2){
					a[i]=-1;
				}
				else {
					ans+=y;a[i]=2;
				}
			}
		}
		if(c[i]=='r'){
			if(i<=k){
				ans+=z;a[i]=3;
			}
			else {
				if(a[i-k]==3){
					a[i]=-1;
				}
				else {
					ans+=z;a[i]=3;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}
 

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

int N, K;

long long solver() {
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    int k = K;
    long long tmp = i - K;
    if (tmp < 0) {
      tmp = 0;
    }
    if(k > 0){
      k--;
    }
    long long tmp2 = (N % i - k);
    if (tmp2 < 0 || (N % i == 0)) {
      tmp2 = 0;
    }
    ans += N / i * tmp + tmp2;
  }
  return ans;
}

int solver2() {
  long long ans = 0;
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (j % i >= K) {
        cout << i << " " << j << endl;
        ans++;
      }
    }
  }
  return ans;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  cin >> N >> K;
  cout << solver() << endl;
  //cout << solver2() <<endl;
}


Measured memory_bytes: 3628
S = input() + "$"
L = len(S)
SS = []
E = []
i = 0
while i < L:
    if S[i] == 'A':
        E.append(0)
        i += 1
        continue
    if S[i:i+2] == 'BC':
        E.append(1)
        i += 2
        continue
    if E:
        SS.append(E)
        E = []
    i += 1

ans = 0
for E in SS:
    cur = 0
    for c in reversed(E):
        if c:
            cur += 1
        else:
            ans += cur
print(ans)

Measured memory_bytes: 9064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        for (int i=0;i<N;i++) {
            int A = sc.nextInt();
            H-=A;
            if (H<=0) {
                System.out.println("Yes");
                return;
            }
        }
        System.out.println("No");
    }
}

Measured memory_bytes: 46288
#include<iostream>
using namespace std;
int main (void){
    
    long x,a = 100;
    int cnt = 0;
    cin >> x;


    while(1){

        if(a >= x)
            break;

        a = a + (a * 0.01);
        cnt++;
    }

    cout << cnt << endl;
    return 0;
}

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

bool a[100010],r[100010];
int n;

void solve(){
	for(int i=1;i<n;i++){
		if(r[i]==1){
			if(a[i]==0) a[i+1]=a[i-1];
			else a[i+1]=1-a[i-1];
		}
		else{
			if(a[i]==0) a[i+1]=1-a[i-1];
			else a[i+1]=a[i-1];
		}
	}
	int x;
	if(r[0]==1){
		if(a[0]==0) x=a[1];
		else x=1-a[1];
	}
	else{
		if(a[0]==0) x=1-a[1];
		else x=a[1];
	}
	if(a[n]==a[0]&&a[n-1]==x){
		for(int i=0;i<n;i++){
			if(a[i]==0) cout<<"S";
			else cout<<"W";
		}
		exit(0);
	}
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		char x;
		cin>>x;
		if(x=='o') r[i]=1;
		else r[i]=0;
	}
	memset(a,0,sizeof(a));
	a[0]=0;
	a[1]=0;
	solve();
	memset(a,0,sizeof(a));
	a[0]=0;
	a[1]=1;
	solve();
	memset(a,0,sizeof(a));
	a[0]=1;
	a[1]=0;
	solve();
	memset(a,0,sizeof(a));
	a[0]=1;
	a[1]=1;
	solve();
	cout<<"-1"<<endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();


        Map<Integer, Boolean> map = new HashMap<>();

        for (int i = 0; i < N; i++) {
            map.put(i + 1, false);
        }

        for (int j = 0; j < K; j++) {
            int d = scanner.nextInt();
            for (int i = 0; i < d; i++) {
                map.put(scanner.nextInt(), true);
            }
        }

        int result = 0;
        for (Integer integer : map.keySet()) {
            if (map.get(integer).equals(false)) {
                result += 1;
            }
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 37460
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include <iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;ll mod=1000000007;
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 vector<ll>a;
 ll b;
 rep(i,0,3*n){
  cin>>b;
  push(a,b);
 }
 sort(all(a));
 reverse(all(a));
 ll ans=0;
 rep(i,0,n)ans+=a[2*i+1];
 pr(ans);
return 0;}


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

typedef long long ll;
const ll mod = 998244353;

ll modpow(ll a, ll b, ll p = 998244353){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    ll n, a, b, k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    ModComb mc(n+1);
    for(int i = 0; i <= n; i++){
        if(a*i > k) break;
        if((k-a*i)%b)   continue;
        if((k-a*i)/b > n)   continue;
        ans += mc.nCk(n, i) * mc.nCk(n, (k-a*i)/b) % mod;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k; --k;
    vector<int> x(n);
    REP(i,n) cin >> x[i];
    ll ans = LLONG_MAX;
    FOR(i,k,n) {
        int tmp = abs(x[i]-x[i-k]) + min(abs(x[i]),abs(x[i-k]));
        chmin(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std; 
#define REP(i, n) for (int i = 0; i < (n); i++)

typedef long long ll;
int main(int argc, char const *argv[])
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll X; cin >> X;
    for (ll i = -1000; i <= 1000; i++) {
        for (ll j = -1000; j <= 1000; j++) {
            if (i*i*i*i*i - j*j*j*j*j == X) {
                cout << i << " " << j << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int i;
  long n;
  cin>>n;
  int sum[n];
  int a[n-1];
  for(i=0;i<n;i++){
    sum[i]=0;
  }
  for(i=1;i<n;i++){
    cin>>a[i];
    sum[a[i]-1]++;
  }
  for(i=0;i<n;i++){
    cout<<sum[i]<<endl;
  }
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    int n;
    scanf("%d", &n);
    int arrd1[n];
    int arrd2[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d %d", &arrd1[i], &arrd2[i]);
    }
    
    for (int i = 0; i < n-2; i++)
    {
        if(arrd2[i]==arrd1[i] && arrd1[i+1]==arrd2[i+1] && arrd1[i+2]==arrd2[i+2]){
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    
}

Measured memory_bytes: 3684
n, m = map(int, input().split())

students = [tuple(map(int, input().split())) for i in range(n)]
checkpoints = [tuple(map(int, input().split())) for j in range(m)]

def distance(u, v):
    return abs(u[0] - v[0]) + abs(u[1] - v[1])


for s in students:
    j = -1
    v = 2*10**9
    for i, cp in enumerate(checkpoints):
        d = distance(s, cp)
        if d < v:
            j = i
            v = d
    print(j+1)


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

using namespace std;

int main(){

  double x,y,a,b,c,d,e,f;

  while(cin >> a >> b >> c >> d >> e >> f){
    
    x = (c * e - b * f) / (a * e - b * d);
    y = (c * d - a * f) / (b * d - a * e);

    x += 0;
    y += 0;
    
    printf("%0.3lf",x);
    cout << " ";
    printf("%0.3lf",y);
    cout << endl;
    
  }

}



Measured memory_bytes: 3108
/*
 * すぬけ君は 1,2,3 の番号がついた 3 つのマスからなるマス目を持っています。 各マスには 0 か 1 が書かれており、マス i には si が書かれています。
 * 
 * すぬけ君は 1 が書かれたマスにビー玉を置きます。 ビー玉が置かれるマスがいくつあるか求めてください。
 */

import java.util.*;
    public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            int a = Integer.parseInt(sc.next());
            // 出力
            System.out.println(a/100 + (a/10)%10 + a%10);
            sc.close();
        }
    }
	

Measured memory_bytes: 21716
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    vector<int> s3;
    rep(i, 1e6){
        if(i == 0){
            s3.push_back(0);
            continue;
        }
        s3.push_back(s3[i-1] + i);
        if(s3[i] >= 1e6){
            break;
        }
    }


    vector<int> s4;
    for(int i = 0; s3[i] < 1e6; i++){
        if(i == 0){
            s4.push_back(0);
            continue;
        }
        s4.push_back(s4[i-1] + s3[i]);
        if(s4[i] > 1e6){
            break;
        }
    }

    int n = (int)s4.size();
    vector<int> dp1(1e6, INF);
    dp1[0] = 0;
    for(int i = 1; i < n; i++){
        rep(j, 1e6){
            if(j + s4[i] >= 1e6 || dp1[j] == INF){
                continue;
            }
            dp1[j + s4[i]] = min(dp1[j + s4[i]], dp1[j] + 1);
        }
    }

    vector<int> dp2(1e6, INF);
    dp2[0] = 0;
    for(int i = 1; i < n; i++){
        if(s4[i] % 2 == 0){
            continue;
        }
        rep(j, 1e6){
            if(j + s4[i] >= 1e6 || dp2[j] == INF){
                continue;
            }
            dp2[j + s4[i]] = min(dp2[j + s4[i]], dp2[j] + 1);
        }
    }

    while(true){
        int x;
        cin >> x;

        if(x == 0){
            break;
        }
        cout << dp1[x] << " " << dp2[x] << endl;
    }

    return 0;
}



Measured memory_bytes: 18152
from collections import deque

N, M = map(int, input().split())

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

list_step = [-1] * N
list_step[0] = 0
queue = deque([0])
while len(queue) > 0:
    parent = queue.popleft()
    for i in range(len(list_road[parent])):
        tmp = list_road[parent][i]
        if list_step[tmp] == -1:
            list_step[tmp] = parent
            queue.append(tmp)

if -1 in list_step:
    print('No')
else:
    print('Yes')
    for i in range(1, N):
        print(list_step[i]+1)

Measured memory_bytes: 34208
#include <stdio.h>

int main(void)
{
	int array[3];
	int min;
	int i;
	int j;
	int temp;
	int index;

	scanf("%d %d %d", &array[0], &array[1], &array[2]);

	for(i = 0; i < 3; i++){
		min = i;
		for(j = i + 1; j < 3; j++){
			if(array[j] < array[min]){
				min = j;
			}
		}
		if(min != i){
			temp = array[i];
			array[i] = array[min];
			array[min] = temp;
		}
	}

	printf("%d %d %d\n", array[0], array[1], array[2]);

	return 0;
}

Measured memory_bytes: 596