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

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

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;
struct UnionFind
{
	vector<long long> par;

	void init(long long n) {par.assign(n, -1);}

	long long root(long long x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool merge(long long x, long long y)
	{
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	bool issame(long long x, long long y)
	{
		return root(x) == root(y);
	}

	long long size(long long x)
	{
		return -par[root(x)];
	}
};


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

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N, M; cin >> N >> M;
	UnionFind uf;
	uf.init(100000*2 + 10);
	REP(i, N)
	{
		ll k; cin >> k;
		REP(j, k)
		{
			ll m; cin >> m;
			uf.merge(i, m + N);
		}
	}

	ll ok{true};
	REP(i, N-1)
	{
		if (!uf.issame(i, i+1)) ok = false;
	}

	std::cout << (ok ? "YES" : "NO") << std::endl;
	return 0;
}


Measured memory_bytes: 4772
/***************************************************************
	File name: F.cpp
	Author: huhao
	Create time: Sun 04 Aug 2019 08:44:28 PM CST
***************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=r*10+c-48;
		c=getchar();
	}
	return r*t;
}
#define i64 long long
const i64 N=200010,mod=998244353;
i64 x[N],y[N],a[N],n,b[N],c[N],p2[N],_y[N],ans;
void add(i64 *b,i64 p,i64 v)
{
	while(p)
	{
		b[p]+=v;
		p-=p&(-p);
	}
}
i64 query(i64 *b,i64 p)
{
	i64 r=0;
	while(p<=n)
	{
		r+=b[p];
		p+=p&(-p);
	}
	return r;
}
i64 query(i64 *b,i64 l,i64 r)
{
	return (query(b,l)-query(b,r+1)+mod)%mod;
}
int main()
{
	n=read();
	fr(i,1,n)
	{
		x[i]=read();
		y[i]=read();
		a[i]=x[i];
	}
	sort(a+1,a+n+1);
	fr(i,1,n)
		x[i]=lower_bound(a+1,a+n+1,x[i])-a;
	fr(i,1,n)
		a[i]=y[i];
	sort(a+1,a+n+1);
	fr(i,1,n)
		y[i]=lower_bound(a+1,a+n+1,y[i])-a;
	fr(i,1,n)
		_y[x[i]]=y[i];
	fr(i,1,n)
		y[i]=_y[i];
	p2[0]=1;
	fr(i,1,n)
		p2[i]=p2[i-1]*2%mod;
	fr(i,1,n)
		add(c,y[i],1);
	fr(i,0,n)
		p2[i]=(p2[i]-1+mod)%mod;
	fr(i,1,n)
	{
		ans=(ans+p2[n]-p2[i-1]-p2[n-i]-p2[y[i]-1]-p2[n-y[i]]+4ll*mod)%mod;
		add(c,y[i],-1);
		ans=(ans+p2[query(c,1,y[i]-1)]+p2[query(c,y[i]+1,n)]+p2[query(b,1,y[i]-1)]+p2[query(b,y[i]+1,n)])%mod;
		add(b,y[i],1);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
int x,n;
  cin>>x>>n;
  vin p(n);
  rep(i,0,n) {
    cin>>p[i];
  }
  //
ll ans=inf; 
  int k=0;
  rep(i,0,102){
   if(count(all(p),i)) continue;
    if(ans>abs(x-i)) {
     ans=abs(x-i);
      k=i;
    }
  }
cout<<k<<endl;
}







Measured memory_bytes: 3600
# coding: utf-8
 
 
def main():
 
    in_data = input().split('hi')
 
    if ('' in set(in_data) and 
       len(set(in_data)) == 1 ) :
        print('Yes')
    else:
        print('No')
 
    return 0
  
  
if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main(void){
int N,K;
int ans=1;
scanf("%d %d",&N,&K);
	while(N/K!=0){
		N=N/K;
		ans++;
	}
	printf("%d",ans);
}


Measured memory_bytes: 128
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))

Measured memory_bytes: 6416
#include <stdio.h>
using namespace std;

int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int x = 0;
	for (; a <= b; a++) {
		if (c % a == 0) x++;
	}
	printf("%d\n", x);

	return 0;
}


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

ll N, K;
vector<ll> H;

int main() {
    cin >> N >> K;
    H.resize(N);
    for (int i = 0; i < N; i++) cin >> H[i];
    sort(H.begin(), H.end(), greater<ll>());
    ll cnt = 0;
    for (int i = K; i < N; i++) cnt += H[i];
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 4732
#include <stdio.h>

int main(void)
{
    int number, x, y, z, temp;
    scanf("%d", &number);
    for (int i = number; i > 0; i--){
        scanf("%d %d %d", &x, &y, &z);
        while (x > y || y > z){ //swap until x <= y <= z
            if(y > z){
                temp = y;
                y = z;
                z = temp;
            }
            if(x > y){
                temp = x;
                x = y;
                y = temp;
            }
        }
        if ((x * x) + (y * y) == (z * z)){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
        
    }
    
    return 0;
}
        
    

Measured memory_bytes: 1008
# AOJ 0128 Abacus
# Python3 2018.6.19 bal4u

abacus = [
	[ '*', '*', '*', '*', '*', ' ', ' ', ' ', ' ', ' ' ],
	[ ' ', ' ', ' ', ' ', ' ', '*', '*', '*', '*', '*' ],
	[ '=', '=', '=', '=', '=', '=', '=', '=', '=', '=' ],
	[ ' ', '*', '*', '*', '*', ' ', '*', '*', '*', '*' ],
	[ '*', ' ', '*', '*', '*', '*', ' ', '*', '*', '*' ],
	[ '*', '*', ' ', '*', '*', '*', '*', ' ', '*', '*' ],
	[ '*', '*', '*', ' ', '*', '*', '*', '*', ' ', '*' ],
	[ '*', '*', '*', '*', ' ', '*', '*', '*', '*', ' ' ]]
ans = [['' for c in range(5)] for r in range(8)]

first = True
while True:
	try: n = list(input())
	except: break
	for i in range(5-len(n)):
		for r in range(8): ans[r][i] = abacus[r][0]
	for i in range(len(n)):
		for r in range(8): ans[r][5-len(n)+i] = abacus[r][int(n[i])]
	if first: first = False
	else: print()
	for r in range(8): print(*ans[r], sep='')


Measured memory_bytes: 5628
#include "bits/stdc++.h"
#define YES "YES"
#define Yes "Yes"
#define NO "NO"
#define No "No"
#define YESNO OUT(three(solve(),YES,NO))
#define YesNo OUT(three(solve(),Yes,No))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(a);i>=(LL)(b);i--)
#define REP(i,b) FOR(i,zero,b)
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b-1,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB emplace_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define int long long
#define zero 0LL
#define pb PB
using namespace std;
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
typedef long long LL;
typedef long double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<pr, Vpr, greater<pr> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
int dx[] = { 0,1,0,-1,1,1,-1,-1,0 }, dy[] = { 1,0,-1,0,1,-1,1,-1,0 };
const int SIZE1 = 5e5 + 1000;
const int SIZE2 = 1010;
const int SIZE3 = 188;
const int SIZE = SIZE1;
const LL p = 7 + 1e9;
const LL INF = 1LL << 60;
const long double EPS = 1e-7;
int L;
LL solve(){
	string s;
	int times=0;
	while(cin >> s >> L,L){
		map<LL,int> mp;
		mp[stoi(s)]=1;
		times=1;
		while(true){
			while(s.size()<L) s.push_back('0');
			sort(ALL(s),greater<LL>());
			LL mx=stoi(s);
			sort(ALL(s));
			LL mn=stoi(s);
			LL nx=mx-mn;
			times++;
		//	cout << nx << endl;
			s=to_string(nx);
			if(mp[nx]>=1) break;
			mp[nx]=times;
		}
		cout << mp[stoi(s)]-1<< " "<< s<<" "<< times-mp[stoi(s)] << endl;
	}
	return 0;
}
signed main(){

	solve();

}


Measured memory_bytes: 3212
#include <iostream>
#include <algorithm>

using namespace std;

int N;
int one, two, thr;
double dp[301][301][301];

double solve(int i, int j, int k){
	if(dp[i][j][k] != -1) return dp[i][j][k];
	if(!i && !j && !k) return 0.0;

	double res = 0.0;
	if(i > 0) res += solve(i-1, j, k) * i;
	if(j > 0) res += solve(i+1, j-1, k) * j;
	if(k > 0) res += solve(i, j+1, k-1) * k;
	res += N;
	res *= 1.0 / (i + j + k);

	return dp[i][j][k] = res;
}

int main(void){
	cin >> N;
	one = two = thr = 0;
	for(int i=0; i<N; i++){
		int a; cin >> a;
		if(a == 1) one++;
		else if(a == 2) two++;
		else thr++;
	}

	fill(dp[0][0], dp[301][0], -1);
	printf("%.10f\n", solve(one, two, thr));

}

Measured memory_bytes: 213376
#include "iostream"
#include "string"

int Dice[6];

class DiceMove
{
private:
public:
	DiceMove(){}
	void Move(char dir) {
		int temp;
		if (dir == 'N') {
			temp = Dice[0];
			Dice[0] = Dice[1];
			Dice[1] = Dice[5];
			Dice[5] = Dice[4];
			Dice[4] = temp;
		}
		if (dir == 'S') {
			temp = Dice[0];
			Dice[0] = Dice[4];
			Dice[4] = Dice[5];
			Dice[5] = Dice[1];
			Dice[1] = temp;
		}
		if (dir == 'E') {
			temp = Dice[0];
			Dice[0] = Dice[3];
			Dice[3] = Dice[5];
			Dice[5] = Dice[2];
			Dice[2] = temp;
		}
		if (dir == 'W') {
			temp = Dice[0];
			Dice[0] = Dice[2];
			Dice[2] = Dice[5];
			Dice[5] = Dice[3];
			Dice[3] = temp;
		}
	}
};

int main()
{
	int n, fr, up, count = 0;
	char dir;
	DiceMove move;
	std::string direction;
	for (int i = 0; i < 6; i++)
		std::cin >> Dice[i];
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> up >> fr;
		while (1) {
			if (Dice[1] == up && Dice[0] == fr) {
				move.Move('W');
				move.Move('W');
				move.Move('N');
			}
			if (Dice[0] == up && Dice[1] == fr) break;
			else {
				if (count == 3) {
					move.Move('W');
					count = 0;
				}
				else {
					move.Move('N');
					count++;
				}
			}
		}
		std::cout << Dice[2] << std::endl;
		count = 0;
	}
	return 0;
}

Measured memory_bytes: 3088
import copy
N,K,C = list(map(int, input().split()))
S = list(input())
count = 0
mae = [0]*K
ushiro = [0]*K
hi = 0
youso = 0
S_copy = copy.deepcopy(S)

while True:
    if S_copy[hi] == 'o':
        mae[youso] = hi+1
        youso += 1
        if youso == K:
            break
        for i in range(C):
            if hi+1+i <= N-1:
                S_copy[hi+1+i] = 'x'
    hi += 1

hi = 0
youso = 0
S_copy = copy.deepcopy(S)
S_copy.reverse()

while True:
    if S_copy[hi] == 'o':
        ushiro[youso] = hi-1
        youso += 1
        if youso == K:
            break
        for i in range(C):
            if hi+1+i <= N-1:
                S_copy[hi+1+i] = 'x'
    hi += 1

ushiro = list(map(lambda x: N-x-1, ushiro))
ushiro.reverse()

ans = []

for j in range(len(mae)):
    if mae[j] == ushiro[j]:
        ans.append(mae[j])

if ans:
    for j in range(len(ans)):
        print(ans[j])










Measured memory_bytes: 32388
import java.util.*;


public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int amount = 0;
      	int time = a;  
      
        for(int i = 2; time <= c + 0.5; i++){
            amount += b;
          	time = a * i;
        }
        
        System.out.println(amount);
    }
}

Measured memory_bytes: 22100
unittest
{
	assert( [ "10" ].solve == 5 );
	assert( [ "1111111111111111111" ].solve == 162261460 );
	
	assert( [ "111" ].solve == 27 );		// 追加ケース
	assert( [ "101" ].solve == 15 );		// 追加ケース
	assert( [ "011" ].solve == 9 );		// 追加ケース
	assert( [ "010" ].solve == 5 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto l = input.front.map!( ( a ) => a == '1' ).array;
	
	// 桁DP
	// dp[ i桁目 ][ l未満フラグ ] = パターン数
	const M = 10L ^^ 9 + 7;
	auto dp = new ModWorld!M[][]( 1 + l.length, 2 );
	dp[ 0 ][ 0 ] = 1;
	foreach( i, c; l )
	{
		// a+b==l --> a+b==l の場合
		if( c ) dp[ i + 1 ][ 0 ] = dp[ i ][ 0 ] * 2;		// a[i]=1,b[i]=0 もしくは a[i]=0,b[i]=1
		else    dp[ i + 1 ][ 0 ] = dp[ i ][ 0 ];			// a[i]=0,b[i]=0
		
		// a+b==l --> a+b<l の場合
		if( c ) dp[ i + 1 ][ 1 ] = dp[ i ][ 0 ];			// a[i]=0,b[i]=0
		
		// a+b<l --> a+b<l の場合
		dp[ i + 1 ][ 1 ] += dp[ i ][ 1 ] * 3;				// a[i]=1,b[i]=0 もしくは a[i]=0,b[i]=1 もしくは a[i]=0,b[i]=0
	}
	return dp[ $ - 1 ].sum;
}

// モジュラ整数型（n mod M）
struct ModWorld( long M )
{
	long n;
	
	void opUnary( string OP )() if( OP == "++" ){ this.n = ( this.n + 1 ) % M; }
	void opUnary( string OP )() if( OP == "--" ){ this.n = ( this.n + M - 1 ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "+"  ){ this.n = ( this.n + r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "-"  ){ this.n = ( this.n + M - r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "*"  ){ this.n = ( this.n * r.n ) % M; }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "/"  ){ this *= r ^^ ModWorld( M - 2 ); }
	void opOpAssign( string OP )( ModWorld r ) if( OP == "^^" )
	{
		auto a = this.n;
		this.n = 1L;
		for( auto i = r.n; 0 < i; i >>= 1 )
		{
			if( i & 1 ) this.n = ( this.n * a ) % M;
			a = ( a * a ) % M;
		}
	}
	auto opBinary( string OP )( ModWorld r ){ auto l = this; l.opOpAssign!OP( r ); return l; }
	
	void opAssign( long r ){ this.n = r; }
	void opOpAssign( string OP )( long r ){ this.opOpAssign!OP( ModWorld( r ) ); }
	auto opBinary( string OP )( long r ){ return this.opBinary!OP( ModWorld( r ) ); }
	auto opBinaryRight( string OP )( long l ){ return ModWorld( l ).opBinary!OP( this ); }
	auto opEquals( long r ){ return this.n == r; }
	
	auto toString(){ return this.n.to!string; }
}


Measured memory_bytes: 8020
Number = int(input())
tresure_value = list(map(int , input().split()))
cost = list(map(int , input().split()))
cnt = 0
 
for i in range(len(tresure_value)):
  benefit = tresure_value[i] - cost[i]
  if benefit  > 0:
    cnt = cnt + benefit 
    
print(cnt)


Measured memory_bytes: 3064
#include <iostream>
#include <cfenv>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>

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

int main() {
    int k, x;
    cin >> k >> x;

    if (500 * k >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main() {
 
  int n,x,m,a;
  cin >> n >> x;
  
  a = x;
  
  for ( int i = 0; i < n; i++){
    cin >> m;
    x -= m;
    if ( a > m ){
      a = m;
    }
  }
  
  cout << n + ( x / a ) << endl;   
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int n,a[55],b[55],c[55],sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        cin>>b[i];
    for(int i=0;i<n-1;i++)
        cin>>c[i];
    for(int i=0;i<n-1;i++)
    {
        sum=sum+b[i];
        if(a[i+1]-a[i]==1)
            sum=sum+c[a[i]-1];
    }
    sum=sum+b[n-1];
    cout<<sum;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
typedef long long lng;
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORD(i,b,a) for(int i=(b); i>=(a); --i)
#define REP(i,n) FOR(i,0,n-1)
#define ALL(a) (a).begin(), (a).end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end()) //ATTENTION: <a> must be sorted in advance

lng power(lng b, lng n) {lng sol=1; while(n>0) {if(n&1) {sol=sol*b;} n>>=1; b*= b;} return sol;} //calculate b^n

const int MOD = 1000000007; //10^9+7


/*********** variables ************/
int X, A, B;
/**********************************/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> X >> A >> B;

    if(B-A>X) cout << "dangerous" << endl;
    else if(B-A>0) cout << "safe" << endl;
    else cout << "delicious" << endl;
}


Measured memory_bytes: 256
//c++ テンプレ
#include<bits/stdc++.h>
using namespace std;

typedef long long llint;
typedef long double ld;

#define inf 1e18
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define reverse(v) reverse(v.begin(),v.end())

priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> Que;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
    int n,k;
    cin >> n >> k;
    vector<int>p(n,0);
    for(int i=0;i<n;i++)cin >> p[i];
    sort(p);
    llint ans=0;
    for(int i=0;i<k;i++)ans+=p[i];
    cout << ans << endl;
    
}

int main(){
    solve();
    return 0;
}




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

int main() {
int A, B;
cin >> A >> B;
int ans = 0;
for (int i = A; i <= B; i++) {
  string x = to_string(i);
  reverse(x.begin(), x.end());
  if (x == to_string(i)) ans++;
}
cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <sstream>
#include <deque>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
const int M = 1e9 + 7;
#define ll long long int
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);
using namespace std;

//insta  -------  __ansh7
//MSDIAN

// Basic Template

int main()
{
    fastio

    ll a;
    cin>>a;

    cout<<a+pow(a,2)+pow(a,3)<<"\n";



 

        return 0;
    }

Measured memory_bytes: 4168
import sys
import math
from fractions import gcd
from copy import deepcopy
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

class Node():
    def __init__(self, ch):
        self.ch_list = [ch]
        self.visited = False

N, M = map(int, sys.stdin.readline().split())
node_list = [0] * N

edge_list =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(M)]
for edge in edge_list:
    # リストのインデックスとnodeのidを統一しておく
    edge[0] -= 1
    edge[1] -= 1
for edge in edge_list:
    a, b = edge
    if node_list[a] == 0:
        node_list[a] = Node(b)
    else:
        if b not in node_list[a].ch_list:
            node_list[a].ch_list.append(b)

    if node_list[b] == 0:
        node_list[b] = Node(a)
    else:
        if a not in node_list[b].ch_list:
            node_list[b].ch_list.append(a)

def dfs(current_idx, ch_num, n_list):
    current = n_list[current_idx]
    if current == 0:
        return ch_num
    if current.visited:
        return ch_num
    ch_num += 1
    current.visited = True
    # print(current_idx + 1, list(map(lambda x: x + 1, current.ch_list)), ch_num)
    for idx in current.ch_list:
        # print("before", current_idx + 1, idx + 1, ch_num)
        ch_num = dfs(idx, ch_num, n_list)
        # print("after", current_idx + 1, idx + 1, ch_num)
    return ch_num

base_num = dfs(0, 0, deepcopy(node_list))

cnt = 0
for edge in edge_list:
    nl = deepcopy(node_list)
    a, b = edge
    nl[a].ch_list.remove((b))
    nl[b].ch_list.remove((a))
    num = dfs(0, 0, nl)
    # print(a + 1, b + 1, num)
    if num != base_num:
        cnt += 1

print(cnt)

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int n, x, t;
    cin >> n >> x >> t;
    print((n + x - 1) / x * t);

    return 0;
}


Measured memory_bytes: 3636
N = int(input())
pl = list(map(int, input().split()))

cnt = 0
for i in range(1,N):
    if pl[i-1] == i:
        a = pl[i - 1]
        pl[i - 1] = pl[i]
        pl[i] = a
        cnt += 1
if pl[N-1] == N:
    cnt += 1
print(cnt)


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

int main(){
  int x,y;
  cin >> x >> y;
  if(x==1){
    if(y==1){
      cout << 1000000 << endl;
      return 0;
    }
    else if(y==2){
      cout << 500000 << endl;
      return 0;
    }
    else if(y==3){
      cout << 400000 << endl;
      return 0;
    }
    else{
      cout << 300000 << endl;
      return 0;
    }
  }
  else if(x==2){
    if(y==1){
      cout << 500000 << endl;
      return 0;
    }
    else if(y==2){
      cout << 400000 << endl;
      return 0;
    }
    else if(y==3){
      cout << 300000 << endl;
      return 0;
    }
    else{
      cout << 200000 << endl;
      return 0;
    }
  }
  else if(x==3){
    if(y==1){
      cout << 400000 << endl;
      return 0;
    }
    else if(y==2){
      cout << 300000 << endl;
      return 0;
    }
    else if(y==3){
      cout << 200000 << endl;
      return 0;
    }
    else{
      cout << 100000 << endl;
      return 0;
    }
  }
  else{
    if(y==1){
      cout << 300000 << endl;
      return 0;
    }
    else if(y==2){
      cout << 200000 << endl;
      return 0;
    }
    else if(y==3){
      cout << 100000 << endl;
      return 0;
    }
    else{
      cout << 0 << endl;
      return 0;
    }
  }
}


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

int n;
int dp[100005][3];


int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	cin >> dp[0][0] >> dp[0][1] >> dp[0][2];
	for (int i = 1; i < n; i++) {
		cin >> dp[i][0] >> dp[i][1] >> dp[i][2];
		dp[i][0] += max(dp[i - 1][1], dp[i - 1][2]);
		dp[i][1] += max(dp[i - 1][0], dp[i - 1][2]);
		dp[i][2] += max(dp[i - 1][0], dp[i - 1][1]);
	}	
	cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << '\n';
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
int main(){
    int N;
    scanf("%d", &N);
    int AC = 0;
    int WA = 0;
    int TLE = 0;
    int RE = 0;
    for(int i = 0; i < N ; i++){
        char verdict[100];
        scanf("%s", verdict);
        int L = strlen(verdict);
        if(verdict[0] == 'A'){
            AC++;
        }
        else if(verdict[0] == 'W'){
            WA++;
        }
        else if(verdict[0] == 'T'){
            TLE++;
        }
        else if (verdict[0] == 'R'){
            RE++;
        }
    }
    printf("AC x %d\n", AC);
    printf("WA x %d\n", WA);
    printf("TLE x %d\n", TLE);
    printf("RE x %d\n", RE);
    return 0;
}

Measured memory_bytes: 1708
#include <cstdio>
#include <cstring>
#define MIN(A,B) ((A)<=(B)?(A):(B))
#define MAX(A,B) ((A)>=(B)?(A):(B))
int X,Y,Z,V[4],E[51],A[51];
double dp[51][5001];
int main() {
	while(scanf("%d %d %d",&X,&Y,&Z),X) {
		for(int i=0;i<X;i++) {
			scanf("%d",&V[i]);
		}
		memset(E,0,sizeof(E));
		memset(A,0,sizeof(A));
		for(int i=0;i<Z;i++) {
			int n;
			scanf("%d",&n);
			scanf("%d %d",&E[n],&A[n]);
		}
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		for(int i=0;i<Y;i++) {
			for(int j=0;j<=5000;j++) {
				for(int k=0;k<X;k++) {
					int next=MIN(Y,i+V[k]),money=j;
					if(E[next]==2) money+=A[next];
					if(E[next]==3) money=MAX(0,money-A[next]);
					if(E[next]==1) next=MIN(Y,next+A[next]);
					dp[next][money]+=dp[i][j]/X;
				}
			}
		}
		double sum=0;
		for(int i=0;i<=5000;i++) {
			sum+=i*dp[Y][i];
		}
		printf("%d\n",(int)sum);
	}
}

Measured memory_bytes: 3028
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<limits>
#include<stack>

using namespace std;

typedef unsigned long long ll;
typedef pair<int,int> ii;
typedef vector<pair<int,int> > vii;
typedef vector<vii> vvii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;

int INF = std::numeric_limits<int>::max();
int NINF = std::numeric_limits<int>::min();
int MOD = 1e9+7;

int col[] = {0,-1,0,1,1,1,-1,-1};
int row[] = {-1,0,1,0,1,-1,1,-1};

//knight moves
int cc[] = {1,2,2,1,-1,-1,-2,-2};
int rr[] = {-2,-1,1,2,-2,2,1,-1};

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

    int n;
    cin >> n;

    vvll points(n,vll(3,0));
    ///if the path was needed, just remove the comments
    //vvc path(n,vc(3));

    //char maxAB, maxBC, maxAC;
    //path[0][0] = 'a', path[0][1] = 'b', path[0][2] = 'c';

    for(int i = 0 ; i < n ; ++i)
    {
        cin >> points[i][0] >> points[i][1] >> points[i][2];

        //maxAB = points[i][0] > points[i][1]? 'a' : 'b';
        //maxBC = points[i][1] > points[i][2]? 'b' : 'c';
        //maxAC = points[i][0] > points[i][2]? 'a' : 'c';

        if(i > 0)
        {
            points[i][0] += max(points[i-1][1],points[i-1][2]);
            //path[i][0] = maxBC;

            points[i][1] += max(points[i-1][0],points[i-1][2]);
            //path[i][1] = maxAC;

            points[i][2] += max(points[i-1][1],points[i-1][0]);
            //path[i][2] = maxAB;
        }
    }

    ll maxPath = 0, maxI;
    for(int i = 0 ; i < 3 ; ++i)
        if(points[n-1][i] > maxPath)
        maxI = i, maxPath = points[n-1][i];

    cout << points[n-1][maxI] << endl;

    //for(int i = 0 ; i < n ; ++i)
        //cout << path[i][maxI] << " ";

    return 0;
}


Measured memory_bytes: 8716
S = input()
T = input()
s = []
t = []
n = len(S)
for i in range(n):
  s.append(S[i])
  t.append(T[i])
for i in range(n):
  if s == t:
    print('Yes')
    break
  zero = s[0]
  del s[0]
  s.append(zero)
else:
  print('No')

Measured memory_bytes: 3064
/*B - Resistors in Parallel*/
#include <bits/stdc++.h>
using namespace std;

int main(){

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	double x;
	int tam;

	cin >> tam;

	double ans = 0.0;

	for (int i = 0; i < tam; ++i)
	{
		cin >> x;

		ans += (1.0 / x);
	}

	ans = 1.0 / ans;

	cout << fixed << setprecision(16) << ans ;


	return 0;
}

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

using namespace std;

constexpr static int MOD = 1e9 + 7;
constexpr static int MAXN = 3e5;
int64_t f[MAXN];

int64_t solve(int n, int m) {
    if (n == m)
        return 2 * f[n] * f[m] % MOD;
    if (n + 1 == m)
        return f[n] * f[m] % MOD;
    return 0;
}

int main() {
    f[0] = 1;
    for (int i = 1; i < MAXN; i++)
        f[i] = f[i - 1] * i % MOD;

    int n, m;
    cin >> n >> m;
    if (n > m)
        swap(n, m);

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


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

const int MAXN = 1000 * 1000 + 10;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 10;

long long mod = 1000 * 1000 * 1000 + 7;

int n, w;
long long weight[200], value[200];

long long dp[200][MAXN]; // dp [number of items][total weight]


void update(int items)
{
    //cerr << "item " << items << endl;

    for(int i = 0; i <= w; i++){
        long long ans1, ans2;
        ans1 = 0;
        if(weight[items] <= i) ans1 = value[items] + dp[items - 1][i - weight[items]];
        ans2 = dp[items - 1][i];

        dp[items][i] = max(ans1, ans2);
        /*
        cerr << "i " << i << ' ' << dp[items][i] << endl;
        cerr << ans1 << ' ' << ans2 << endl;
        cerr << value[items] << ' ' << i - weight[items] << ' ' << dp[items - 1][i - weight[items]] << endl;
        */
    }
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(15);


    cin >> n >> w;

    for(int i = 0; i < n; i++){
        cin >> weight[i] >> value[i];
    }

    for(int i = weight[0]; i <= w; i++) dp[0][i] = value[0];

    for(int i = 1; i < n; i++) update(i);

    cout << dp[n - 1][w] << endl;


    return 0;
}



Measured memory_bytes: 82056
from collections import Counter
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
d = [int(i) for i in input().split()] # 配列で数字

m = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
t = [int(i) for i in input().split()]

if n < m:
    print('NO')
else:
    d_c = Counter(d)
    t_c = Counter(t)
    for k, v in t_c.items():
        n = d_c.get(k, 0)
        if n >= v:
            continue
        else:
            print('NO')
            break
    else:
        print('YES')

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

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

using namespace std;


const int IINF = INT_MAX;

int n,t[51],dp[900][900][2],sum[51];


void compute() {
  rep(i,900) rep(j,900) rep(k,2) dp[i][j][k] = IINF;
  sort(t,t+n);
  sum[0] = t[0];
  REP(i,1,n) sum[i] = sum[i-1] + t[i];
  dp[0][0][0] = 0;
  rep(i,n) {
    int cur = i & 1;
    int next = (i+1)&1;
    rep(v1,900) {
      rep(v2,900) {
	if( dp[v1][v2][cur] == IINF ) continue;
	int v3 = ((i-1>=0)?sum[i-1]:0) - ( v1 + v2 );
	//cout << ((i-1>=0)?sum[i-1]:0) <<" - ( "<< v1 << "+" << v2 << ") = " << v3 << endl;
	assert(v3>=0);
	// 1
	if(v1+t[i]<900) {
	  dp[v1+t[i]][v2][next] = min(dp[v1+t[i]][v2][next],
				      max(v1+t[i],max(v2,v3)));
	}
	// 2
	if(v2+t[i]<900) {
	  dp[v1][v2+t[i]][next] = min(dp[v1][v2+t[i]][next],
				max(v1,max(v2+t[i],v3)));
	}
	// 3
	if(v3+t[i]<900) {
	  dp[v1][v2][next] = min(dp[v1][v2][next],
				max(v1,max(v2,v3+t[i])));
	}
      }
    }
    /*
    rep(i,900) rep(j,900) if(dp[i][j][next]>0&&dp[i][j][next]!=IINF){
      cout << dp[i][j][next] << endl;
    } cout << endl;
    */
    rep(i,900) rep(j,900) dp[i][j][cur] = IINF;

  }
  int mini = IINF;
  rep(i,900) rep(j,900) rep(k,2) mini = min(mini,dp[i][j][k]);
  cout << mini << endl;
}

int main() {
  cin >> n;
  rep(i,n) cin >> t[i];
  compute();
  return 0;
}

Measured memory_bytes: 7508
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

#define X first
#define Y second

//#include <boost/unordered_map.hpp>
//using namespace boost;

/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/

namespace io{
	const int L = (1 << 20) + 1;
	
	char buf[L], *S , *T, c;
	 
	char getchar() {
		if(__builtin_expect(S == T, 0)) {
			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;
	}
	
	unsigned inpu()
	{
		unsigned x = 0; char ch;
		for(ch = getchar(); !isdigit(ch); ch = getchar());
		for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
		return x;
	}
	
	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 :: inpu;
using io :: inp_ll;

ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}

const int MAXN = 200010;
const int MOD = 1000000007;
const int INF = 1000000010;

int L;
int tot;
vector<tuple<int, int, int> > e;

void addedge(int x, int y, int w)
{
	e.emplace_back(x, y, w);
}

void build(int L)
{
	if (L == 2)
	{
		tot = 2;
		addedge(1, 2, 0);
		addedge(1, 2, 1);
		return;
	}
	if (L == 3)
	{
		tot = 2;
		addedge(1, 2, 0);
		addedge(1, 2, 1);
		addedge(1, 2, 2);
		return;
	}
	build(L/2);
	addedge(tot, tot+1, 0);
	addedge(tot, tot+1, L/2);
	if (L%2 == 1)
		addedge(1, tot+1, L-1);
	tot ++;
}

int main()
{
	
	cin >> L;
	build(L);
	cout << tot << " " << e.size() << endl;
	for (auto p : e)
	{
		int x, y, w;
		tie(x, y, w) = p;
		cout << x << " " << y << " " << w << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    set<string> st;
    string s;
    cin >> s;
    int k;
    cin >> k;
    int n = sz(s);
    vvi idx(26);
    rep(i, n) idx[s[i]-'a'].pb(i);
    rep(i, 26) {
        set<string> st;
        for (int j : idx[i]) {
            string now;
            rep(l, 5) {
                if (n <= j+l) break;
                now += s[j+l];
                st.insert(now);
            }
        }
        for (auto&& x : st) {
            k--;
            if (k == 0) {
                cout << x << endl;
                return 0;
            }
        }
    }
}

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

const int MAXN = 200010;
int n, K, shl;
char buf[MAXN];
int get(int x) {
	return x + shl <= n ? (shl & 1) ^ buf[x + shl] : n - x & 1;
}
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n >> K >> buf + 1;
	for (int i = 1; i <= n; ++i) buf[i] -= 'A';
	while (K && shl < n) { if (!get(1)) buf[1 + shl] ^= 1; else ++shl; --K; }
	for (int i = 1; i <= n; ++i) buf[i] = get(i);
	if ((n & 1) && (K & 1)) buf[1] ^= 1;
	for (int i = 1; i <= n; ++i)
		std::cout << (char) ('A' + buf[i]);
	std::cout << '\n';
	return 0;
}


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

int main(){
	int n;
	cin >> n;
	string s[n];
	REP(i,n) cin >> s[i];
	int cnt = 0;
	int a = 0,b = 0,ba = 0;
	REP(i,n){
		REP(j,s[i].length()){
			if(s[i][j] == 'A'){
				if(s[i][j + 1] == 'B')cnt++;
			}
		}
		if(s[i][0] == 'B'){
			b++;
			if(s[i][s[i].length() - 1] == 'A') ba ++;
		}
		if(s[i][s[i].length() - 1] == 'A') a++;
	}
	if(b == 0 || a == 0) cout << cnt << endl;
	else if(a == ba && b == ba) cout << cnt + min(a,b) - 1 << endl;
	else cout << cnt + min(a,b) << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, k;
    cin >> n >> k;
    int data[26] = {};
    set<string> st;
    rep(i, 0, n){
        string p;
        cin >> p;
        data[p[0] - 'A']++;
        
        // if(!st.count(p)){
        //     st.insert(p);
        //     data[p[0] - 'A']++;
        // }
    }
    int MAX = n / k, ans = 0;
    rep(i, 1, MAX + 1){
        int now = 0;
        rep(j, 0, 26){
            now += min(i, data[j]);
        }
        if(now >= i * k) ans = i;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import permutations
import math


N = int(input())
town = [tuple(map(int, input().split())) for _ in range(N)]
total_dist = 0

for perm in permutations(town):
    for i in range(N-1):
        total_dist += math.sqrt(
            (perm[i][0] - perm[i+1][0])**2 + 
            (perm[i][1] - perm[i+1][1])**2)


print(total_dist / math.factorial(N))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int Q = sc.nextInt();
		int H = sc.nextInt();
		if(Q <= H) {
			System.out.println(0);
		} else {
			System.out.println(Q - H);
		}
	}
}

Measured memory_bytes: 21972
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func sum(a []int) int {
	ret := 0
	for _, v := range a {
		ret += v
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	n, m := nextInt(), nextInt()
	a := nextInts(m)

	res := n - sum(a)

	if res < 0 {
		puts(-1)
	} else {
		puts(res)
	}
}


Measured memory_bytes: 1956
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    const int XMAX = 50;
    const int NMAX = 50;
    int N, A;  cin >> N >> A;
    vi X(N + 1, 0); 
    FOR(i, 1, N + 1) cin >> X[i];    

    auto dp = vector<vvl>(NMAX + MGN, vvl(NMAX + MGN, vl(XMAX*NMAX + MGN, 0)));
    // dp[i][j][k] : The number of ways to choose
    //   j cards whose sum is k from X[0]..X[i]					

    dp[0][0][0] = 1;
    FOR(i, 1, N + 1) dp[i][0][0] = 1;

    FOR(i, 1, N + 1) {
        FOR(j, 1, i + 1) {
            FOR(k, 0, XMAX*j + 1) {
                if (k >= X[i]) {
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - X[i]];
                } else {
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }

    ll ans = 0;
    FOR(j, 1, N + 1) ans += dp[N][j][A*j];

    cout << ans << endl;

    return 0;
}

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

A,B,C,D = list(map(int,input().split()))

push =[0]*102
push[A+1]+=1
push[B+1] -=1
push[C+1] +=1
push[D+1] -= 1
count = 0
for i in range(1,len(push)):
    push[i] = push[i] + push[i-1]
    if push[i]==2:
        count +=1
print(count)


Measured memory_bytes: 8984
/*input
4 5 2
1 3
2 4
1 2
3 4
2 3
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=100005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

const int N=50005;

int n,m,t;
int x[maxn],y[maxn];
void solve(){
	if(n==2){
		cout<<"-1\n";
		return;
	}
	int cnt[N]={0};
	int id[N];

	REP(i,n) id[i]=i;
	REP(i,n) cnt[i]=1;

	string ans;
	REP(i,m) cin>>x[i]>>y[i];
	REP(i,m) x[i]--,y[i]--;

	for(int i=m-1;i>=0;i--){
		if(cnt[id[x[i]]]>1){
			ans.pb('v');
			cnt[id[x[i]]]--;
			cnt[id[y[i]]]++;
			id[x[i]]=id[y[i]];
		}
		else {
			ans.pb('^');
			cnt[id[y[i]]]--;
			cnt[id[x[i]]]++;
			id[y[i]]=id[x[i]];
		}
	}
	reverse(ALL(ans));
	cout<<ans<<'\n';
	return;
}


bitset<N> a[N]; 
bitset<N> res;
string ans;

int main(){
	IOS;
	cin>>n>>m>>t;
	if(t==2){
		solve();
		return 0;
	}

	REP(i,n) a[i].reset();
	REP(i,n) a[i][i]=true;

	REP(i,m) cin>>x[i]>>y[i];
	REP(i,m) x[i]--,y[i]--;

	reverse(x,x+m);reverse(y,y+m);

	REP(i,m){
		a[x[i]]|=a[y[i]];
		a[y[i]]|=a[x[i]];
		// REP(j,n) REP(k,n) cout<<a[j][k]<<" \n"[k==n-1];
	}
	REP(i,n) a[0]&=a[i];
	int r=-1;
	REP(i,n) if(a[0][i]){
		r=i;
	}
	// cout<<r<<endl;
	if(r==-1){
		cout<<"-1\n";
		return 0;
	}
	res.reset();
	res[r]=1;
	REP(i,m){
		if(res[x[i]]^res[y[i]]){
			if(res[x[i]]) ans.pb('^');
			else ans.pb('v');

			res[x[i]]=res[y[i]]=true;
		}
		else ans.pb('^');
	}
	reverse(ALL(ans));
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 306816
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		long n = sc.nextLong();
		long x = Math.min(n, b - 1);
		System.out.println(a * x / b - a * (x / b));
	}

}


Measured memory_bytes: 35668
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a, b) for(int i = a; i < b; i++)
#define ALL(v) v.begin(), v.end()


int main(){
    int n,x,ans=1,y=0;
    cin>>n>>x;
    rep(i,0,n){
        int l; cin>>l;
        y+=l;
        if(y<=x) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256