akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
	int N, K, R, S, P;
	string T, t;
	cin >> N >> K >> R >> S >> P;
	cin >> T;
	int a = 0;
	char b;
	for (int i = 0; i < N; i++) {
		if (T[i] == 'r')	b = 'p';
		else if (T[i] == 's')	b = 'r';
		else if (T[i] == 'p')	b = 's';

		if (K <= i) {
			if (t[i - K] == b) {
				if (i < N - K) {
					if (T[i + K] == 'p')	t.push_back('r');
					if (T[i + K] == 's')	t.push_back('p');
					if (T[i + K] == 'r')	t.push_back('s');
				}
				continue;
			}
		}
		if (T[i] == 'r')	a += P;
		else if (T[i] == 's')	a += R;
		else if (T[i] == 'p')	a += S;
		t.push_back(b);
	}
	cout << a << endl;
	return 0;
}

Measured memory_bytes: 640
N , M = map(int , input().split())
if (N == 2) or (M == 2):
    print(0)
elif(N == 1 and M == 1):
    print(1)
elif (N == 1) or (M == 1):
    print(max(N * M - 2 ,0))
else:
    print(max((N - 2)*( M - 2),0))

Measured memory_bytes: 3060
import std.stdio : writeln, writefln;
import std.array;
import std.range;
import std.math : sqrt, acos, PI;

double d(double[2] a){
	return sqrt(a[0]*a[0] + a[1]*a[1]);
}

void swap(T)(ref T a, ref T b){
	T tmp = a;
	a = b;
	b = tmp;
}

void main(){
	delim = ",";
	while(hasNext){
		double[2] a = [next!double(), next!double()];
		double[2] b = [next!double(), next!double()];
		double[2] q = [next!double(), next!double()];
		
		double[2] v = a;
		v[]-=q[];
		
		double[2] r = [b[1]-a[1], -(b[0]-a[0])];
		r[]*=1.0/r.d;
		
		double cos_ = (v[0]*r[0] + v[1]*r[1])/(v.d*r.d);
		double h = v.d*cos_;
		
		r[]*=2.0*h;
		r[]+=q[];
		
		writefln("%.6f %.6f", r[0], r[1]);
	}
}


import std.stdio : readln, chomp;
import std.conv : to;
import std.string : split;
shared string[] input;
shared string delim = " ";
T next(T)()
in
{
	assert(hasNext());
}
out
{
	input.popFront;
}
body
{
	return input.front.to!T;
}

void next(T)(ref T v){
	v = next!T();
}

bool hasNext(){
	if(input.length > 0){
		return true;
	}
	
	string str = readln;
	if(str.length > 0){
		input ~= str.chomp.split(delim);
		return true;
	}else{
		return false;
	}
}


void dbg(T...)(T vs)
{
	import std.stdio : stderr;
	foreach(v; vs)
		stderr.write(v.to!string ~ " ");
	stderr.write("\n");
}

T clone(T)(T v){
	T v_;
	static if(isInputRange!(T)){
		foreach(ite; v){
			v_ ~= ite.clone;
		}
	}else{
		v_ = v;
	}
	
	return v_;
}

Measured memory_bytes: 1088
import java.util.*;
public class Main {
	public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
      //取得
      String S = sc.next();
      //文字列比較
     if(S.equals("AAA") || S.equals("BBB")){
       System.out.println("No");
     }else{
       System.out.println("Yes");
     }
    }
}

Measured memory_bytes: 35676
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	if(n>=400&&n<600) cout<<8;
	else if(n>=600&&n<800) cout<<7;
	else if(n>=800&&n<1000) cout<<6;
	else if(n>=1000&&n<1200) cout<<5;
	else if(n>=1200&&n<1400) cout<<4;
	else if(n>=1400&&n<1600) cout<<3;
	else if(n>=1600&&n<1800) cout<<2;
	else if(n>=1800&&n<2000) cout<<1;
	return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,m,a,b,c,d,e,i,j;
  cin>>n>>m;
  vector<vector<int>> dp(m+1,vector<int>(1<<n));
  for(j=1;j<(1<<n);j++) dp.at(0).at(j)=1e9;
  for(i=1;i<=m;i++){
    cin>>a>>b;
    d=0;
    for(j=0;j<b;j++){
      cin>>c;
      d+=(1<<(c-1));
    }
    for(j=0;j<(1<<n);j++) dp.at(i).at(j)=dp.at(i-1).at(j);
    for(j=0;j<(1<<n);j++){
      e=min(dp.at(i-1).at(j|d),dp.at(i-1).at(j)+a);
      if(e<dp.at(i).at(j|d)) dp.at(i).at(j|d)=e;
    }
  }
  if(dp.at(m).at((1<<n)-1)==1e9) cout<<-1<<endl;
  else cout<<dp.at(m).at((1<<n)-1)<<endl;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int n,m,i,j,x,y;
	cin>>n>>m>>x>>y;
	int x1[n],y1[m];
	for(i=0;i<n;i++)
		cin>>x1[i];
	for(i=0;i<m;i++)
		cin>>y1[i];
	sort(x1,x1+n);
	sort(y1,y1+m);
	if(x1[n-1]>=y1[0])
	{
		cout<<"War"<<endl;
		return 0;
	}
	int z = max(x1[n-1],y1[0]);
	if(z == x1[n-1] || z == x || (y<z) || (x>z))
	{
		cout<<"War"<<endl;
		return 0;
	}
	cout<<"No War"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define all(v) v.begin(), v.end()
#define sz size()
#define mp make_pair
#define pb push_back
#define rep(p, a, b) for (ll p = a; p < b; p++)
#define rap(p, a, b) for (ll p = a; p <= b; p++)
#define per(p, a, b) for (ll p = a; p >= b; p--)
#define F first
#define S second
using namespace std;

typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<ll, ll> pll;

int main()
{
    ll t, i, j, k, ans, n;

    //cin>>t;
    t = 1;
    while (t--)
    {
        string s;
        cin>>s;
        string a(s.sz,'x');
        cout<<a;
    }

    return 0;
}

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

#define BUF_SIZE 13

int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int table[256] = {
    ['A'] = 1,
    ['T'] = 1,
    ['G'] = 1,
    ['C'] = 1,
};

#define max(a, b) ((a) > (b) ? (a) : (b))

int main(void) {
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    size_t len = strlen(str);

    int ans = 0;
    int idx = 0;
    int count = 0;
    while(idx<=len) {
        // skip
        while(table[(int)str[idx++]]) count++;
        // do something
        ans = max(ans, count);
        count = 0;
    }
    // for(i = 0; i <= len; i++) {
    //     // last character hits this condition!
    //     if(!table[(int)str[i]]) {
    //         ans = max(ans, count);
    //         count = 0;
    //         continue;
    //     }
    //     count++;
    // }
    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <string>

int main(){

    int rowNum, columnNum;
    scanf("%d %d", &rowNum, &columnNum);

    // initialize
    int** table = new int*[rowNum + 1];
    for(int row = 0; row < rowNum + 1; row++){
        table[row] = new int[columnNum + 1];
    }

    // input
    int value;
    for (int r = 0; r < rowNum; r++) {
        for (int c = 0; c < columnNum; c++) {
            scanf(" %d", &value);
            table[r][c] = value;
        }
    }

    // sum
    for (int row = 0; row < rowNum; ++row) {
        for (int col = 0; col < columnNum + 1; ++col) {
            if (col != columnNum){
                table[row][columnNum] += table[row][col];
            }
            table[rowNum][col] += table[row][col];
        }
    }

    // output
    for (int row = 0; row <= rowNum; ++row) {
        for (int col = 0; col <= columnNum; ++col) {
            printf("%d", table[row][col]);
            if(columnNum != col) printf(" ");
        }
        printf("\n");
    }
   
}



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

int main(int argc, const char * argv[]) {
    uint64_t N;
    cin >> N;
    
    string S;
    cin >> S;
    
    uint64_t R = 0;
    uint64_t G = 0;
    uint64_t B = 0;
    for (char s : S) {
        if (s == 'R') {
            R++;
        }else if (s == 'G') {
            G++;
        }else {
            B++;
        }
    }
    
    uint64_t ans = R * G * B;  // 組み合わせ全通り。
    
    // 条件に合わないものを引く。
    uint64_t sub = 0;
    for (uint64_t i = 0; i < N-2; i++) {
        for (uint64_t j = i+1; j < N-1; j++) {
            uint64_t k = j + (j - i);   // jを挟んでiと対象となるものの数を数える。
            if (k < N) {
                if ((S[i] != S[j]) &&
                    (S[i] != S[k]) &&
                    (S[j] != S[k])) {
                    sub += 1;
                }
            }
        }
    }
    
    std::cout << ans - sub;
    
    return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

#define endl '\n'
#define ll long long

using namespace std;

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

	int p[200001] = { 0, };
	int n, a;
	cin >> n;

	for (int i = 2; i <= n; i++)
	{
		cin >> a;
		p[a]++;
	}

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


	return 0;
}

Measured memory_bytes: 4400
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)n;i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1001001001; const long long INFLL=1001001001001001001ll;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : " "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
    #ifdef int
        cerr<<"\x1b[7m"<<"'int' is defined as 'long long' !!!!"<<"\x1b[m"<<endl;
    #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(12)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

vector<bool> is_prime;
void eratosthenes(int N) {
    is_prime.resize(N+1);
    fill(ALL(is_prime),true);
	FOR(i,2,sqrt(N)+1)
        if(is_prime[i])
            for(int j=2; i*j<=N; j++)
                is_prime[i*j]=false;
}
vector<int> get_prime(int N) {
    eratosthenes(N);
    vector<int> prime;
    FOR(i,2,N+1) if(is_prime[i]) prime.push_back(i);
    return prime;
}
const int MOD=1e9+7;
signed main() {
    int n;
    cin>>n;
    vi prime=get_prime(n);
    vi num(SZ(prime),0);
    FOR(k,1,n+1) {
        int a=k;
        for(int i=0;i<SZ(prime);) {
            if(a%prime[i]==0) {
                num[i]++;
                a/=prime[i];
            }
            else {
                i++;
            }
        }
    }

    int ans=1;
    FORE(x,num) {
        ans*=(x+1)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
from sys import exit
l,r=map(int,input().split())
res=1000000000000
if r-l>2020:
	print("0")
	exit()
else:
	for i in range(l%2019,r%2019):
		for j in range(i+1,r%2019+1):
			res=min(res,(i*j)%2019)
print(res)

Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
llint a[1<<20];

void zeta_transform(llint a[], int n)
{
	int S = 1<<n;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < S; j++){
			if((j&(1<<i))) a[j] += a[j^(1<<i)];
		}
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k;
	for(int i = 0; i < n; i++) cin >> a[1<<i];
	
	zeta_transform(a, n);
	for(int i = 0; i < (1<<n); i++){
		if(a[i] == k) a[i] = 1;
		else a[i] = 0;
	}
	zeta_transform(a, n);
	
	llint ans = n+1;
	for(int i = 0; i < (1<<n); i++){
		if(a[i]) continue;
		llint cnt = 0;
		for(int j = 0; j < n; j++){
			if(i & (1<<j)) cnt++;
		}
		ans = min(ans, n-cnt);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 11392
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>

using namespace std;

double EPS = 1e-4;

struct Edge {
	int to, dist;
	Edge(int _t, int _d) : to(_t), dist(_d) {}
};

struct Path {
	int cur;
	double cost;
	int ticket;
	Path(int _c, double _co, int _ti) : cur(_c), cost(_co), ticket(_ti) {}
};

bool operator < (const Path& p1, const Path& p2) {
	if (p1.cost < p2.cost) return true;
	else if (p1.cur < p2.cur) return true;
	return p1.ticket < p2.ticket;
}
bool operator == (const Path& p1, const Path& p2) {
	if (p1.cur == p2.cur && p1.cost == p2.cost && p1.ticket == p2.ticket) return true;
	return false;
}
bool operator != (const Path& p1, const Path& p2) { return !(p1 == p2); }
bool operator > (const Path& p1, const Path& p2) { return (p1 != p2) && !(p1 < p2); }
bool operator <= (const Path& p1, const Path& p2) { return (p1 < p2) || (p1 == p2); }
bool operator >= (const Path& p1, const Path& p2) { return (p1 > p2) || (p1 == p2); }

int n, m, p, a, b;
double t[10];

double INF = 1e9;
double d[50][2050];
bool v[50][2050];

void solve() {
	vector< vector<Edge> > G(m+1, vector<Edge>());
	
	for (int i=0; i<p; i++) {
		int x, y, z; cin >> x >> y >> z;
		G[x].push_back( Edge(y, z) );
		G[y].push_back( Edge(x, z) );
	}
	
	for (int i=0; i<=m; i++) fill(d[i], d[i]+2050, INF);
	memset(v, 0, sizeof(v));
	
	priority_queue<Path, vector<Path>, greater<Path> > q;
	q.push( Path(a, 0, 0) );
	
	while (!q.empty()) {
		Path p = q.top(); q.pop();
		
		for (int i=0; i<(int)G[p.cur].size(); i++) {
			Edge e = G[p.cur][i];
			
			for (int c = 0; c < n; c++) {
				if ( !(p.ticket>>c & 1) ) {
					if (d[e.to][p.ticket | 1<<c] > p.cost + e.dist/t[c]) {
						d[e.to][p.ticket | 1<<c] = p.cost + e.dist/t[c];
						q.push( Path(e.to, p.cost + e.dist/t[c], p.ticket | 1<<c ) );
					}
				}
			}
		}
	}
	
	double ans = INF;
	for (int c=0; c<(1<<n); c++) ans = min(ans, d[b][c]);
	if (abs(INF-ans)<=EPS) cout << "Impossible" << endl;
	else cout << ans << endl;
}

int main() {
	while (1) {
		cin >> n >> m >> p >> a >> b;
		if (n==0 && m==0 && p==0 && a==0 && b==0) break;
		for (int i=0; i<n; i++) cin >> t[i];
		
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main()
{
    int n;
    string s;
    cin >> n;
    cin >> s;
    int lbl[200001], lwh[200001];
    int bl = 0;
    int wh = 0;
    for(int i = 0; i < n; i++){
        lbl[i] = bl;
        lwh[i] = wh;
        if(s[i] == '#'){
            bl++;
        }
        else{
            wh++;
        }
    }
    lbl[n] = bl;
    lwh[n] = wh;
    int ans = n;
    for(int i = 0; i <= n; i++){
        ans = min(ans, lbl[i] + wh - lwh[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 2180
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
long long a, b, n, ans;
int main(){
	scanf("%lld%lld%lld", &n, &a, &b);
	if(a > b)printf("0\n");
	else {
		if((b - a) * (n - 2) + 1 < 0)ans = 0;
		else ans = (b - a) * (n - 2) + 1;
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 128
S = list(input())
count1 = 0
count0 = 0
if len(S) == 1:
    print(0)
    exit()
for i in range(len(S)):
    if S[i] == "1":
        count1 += 1
    else:
        count0 += 1
ans = 2*min(count1,count0)
print(ans)

Measured memory_bytes: 3956
#include<cstdio>

int main(){
    int H,W;
    int i,j,s;
    while (1){
    scanf("%d %d",&H,&W);
    if (H == 0 && W == 0) break;
for ( i = 0;i < H;i++){
for ( j = 0;j < W ;j++){
    s = i + j;
    if(s % 2 == 0){
        printf("#");
    }
    else{
        printf(".");
        }
    }
    printf ("\n");
}
printf ("\n");
}
}


Measured memory_bytes: 2596
import sys


def main(argv):
    n, m = [int(i) for i in sys.stdin.readline().rstrip("\n").split(" ")]
    a = [int(i) for i in sys.stdin.readline().rstrip("\n").split(" ")]
    s = sum(a)
    items = list(filter(lambda i: True if i >= s / (4 * m) else False, a))
    print("Yes" if len(items) >= m else "No")
    return 0
    
    
if __name__ == "__main__":
    sys.exit(main(sys.argv))


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
    int dice[101][6],subdice[6],i,j,k,l,n;
    scanf("%d",&n);
    for(i=0;i<n;i++) for(j=0;j<6;j++) scanf("%d",&dice[i][j]);
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(dice[i][0]==dice[j][0]);
            else if(dice[i][0]==dice[j][1]||dice[i][0]==dice[j][4]){
                for(k=0;k<6;k++){
                    subdice[0]=dice[j][4];
                    subdice[4]=dice[j][5];
                    subdice[5]=dice[j][1];
                    subdice[1]=dice[j][0];
                    subdice[2]=dice[j][2];
                    subdice[3]=dice[j][3];
 
                    for(l=0;l<6;l++){
                        dice[j][l]=subdice[l];
                    }
                    if(dice[i][0]==dice[j][0]) break;
                }
            }else if(dice[i][0]==dice[j][2]||dice[i][0]==dice[j][3]||dice[i][0]==dice[j][5]){
                for(k=0;k<6;k++){
                    subdice[0]=dice[j][2];
                    subdice[2]=dice[j][5];
                    subdice[5]=dice[j][3];
                    subdice[3]=dice[j][0];
                    subdice[1]=dice[j][1];
                    subdice[4]=dice[j][4];
                    for(l=0;l<6;l++){
                        dice[j][l]=subdice[l];
                    }
                    if(dice[i][0]==dice[j][0]) break;
                }
            }
            for(k=0;k<4;k++){
                subdice[1]=dice[j][2];
                subdice[2]=dice[j][4];
                subdice[4]=dice[j][3];
                subdice[3]=dice[j][1];
                for(l=1;l<5;l++){
                    dice[j][l]=subdice[l];
                }
                if(dice[i][1]==dice[j][1]){
                    if(dice[i][0]==dice[j][0]&&dice[i][2]==dice[j][2]&&dice[i][3]==dice[j][3]&&dice[i][4]==dice[j][4]&&dice[i][5]==dice[j][5] ){
                        printf("No\n");
                        return 0;
                    }
                }
            }
        }
    }
    if(i==n&&j==n)printf("Yes\n");
 
    return 0;
}


Measured memory_bytes: 2148
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		int answer = 0;
		String s[] = new String[3];
		Scanner sc = new Scanner(System.in);
		
		while(true){//入力があったら繰り返し開始
			for(int i = 0; i<s.length; i++){
				s[i] = sc.next();
			}
			int a = Integer.parseInt(s[0]);
			String op = s[1];
			int b = Integer.parseInt(s[2]);
			if(op.equals("?")){
				break;
			}else if(op.equals("+")){
				answer=a+b;System.out.println(answer);
			}else if(op.equals("-")){
				answer=a-b;System.out.println(answer);
			}else if(op.equals("*")){
				answer=a*b;System.out.println(answer);
			}else if(op.equals("/")){
				answer=a/b;System.out.println(answer);
			}
		}
		sc.close();
	}
}

Measured memory_bytes: 17196
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>

using namespace std;

#define eps 10e-9
#define max 105

int pow(int x,int n) {
	if( x == 0 ) return 0;
	if( n == 0 ) return 1;
	if( n == 1 ) return x;
	if( n & 1 ) {
		int y = pow( x, (n-1)/2 );
		return x * y * y;
	} else {
		int y = pow( x, n / 2 );
		return y * y;
	}
}

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1){
		int n, m, k;
		cin >> n >> m >> k;
		if( n == 0 && m == 0 && k == 0 ) break;

		double e = 0;
		int lim = pow(m, n);
		vector<int> fact;
		for(int i = 0; i <= n; i++) {
			fact.push_back(pow(m, i));
		}

		//m進数変換
		for(int i = 0; i < lim; i++) {
			int sum = 0;
			for(int j = 0; j < n; j++) {
				sum += ( ( i % fact[j+1] ) / fact[j] + 1);
			}
			sum -= k;
			if( sum <= 1 ) sum = 1;
			e += (double)(sum * 1.0) / (double) lim;
		}
		printf("%.8lf\n", e);
	}
	//swhile(1){}
	return 0;
}

Measured memory_bytes: 1240
#include<bits/stdc++.h>
#include<queue>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
using namespace std;
#include<vector>
#include <algorithm>


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

  vector<int> L;
  int b;
  REP(i,N){
    cin>>b;
    L.push_back(b);
  }
  sort(L.begin(),L.end());
  //cout<<L[0]<<endl;

  int a=0;
  REP(i,N-1){
    a+=L[i];
  }

  if(L[N-1]<a){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}


Measured memory_bytes: 256
X,Y = map(int,input().split())
e = 0
temp_X = X
if Y%2 != 0:
    print("No")
    quit()
else:
    while temp_X >= 0:
        i = (temp_X*2) + (e*4)
        if i == Y:
            print("Yes")
            quit()
        temp_X -= 1
        e += 1
print("No")


Measured memory_bytes: 9176
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();
        boolean isOdd = true;
        String ret = "Yes";
        for (char c : s.toCharArray()) {
            if (isOdd && c == 'L' || !isOdd && c == 'R') {
                ret = "No";
                break;
            }
            isOdd = !isOdd;
        }
        System.out.println(ret);
    }
}


Measured memory_bytes: 23124
import sys
import itertools
# import numpy as np
import time
import math
from heapq import heappop, heappush
from collections import defaultdict
from collections import Counter
from collections import deque
from itertools import permutations
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
N, M = map(int, input().split())
prices = [0] * M
ks = [0] * M
for i in range(M):
    a, b = map(int, input().split())
    C = list(map(int, input().split()))
    prices[i] = a
    ks[i] = C

dp = [INF] * (1 << N)
dp[0] = 0
for i in range(M):
    key_bit = 0
    for k in ks[i]:
        key_bit |= 1 << (k - 1)
    for bit in range((1 << N) - 1, -1, -1):
        if dp[bit] != INF:
            nx_bit = bit | key_bit
            dp[nx_bit] = min(dp[nx_bit], dp[bit] + prices[i])
if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])




Measured memory_bytes: 9636
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(; scanner.hasNext();)
		{		
			String input = scanner.nextLine();
			
			String sign = "";
			for(int i=0; i<input.length(); i++)
			{
				sign += toSign(input.substring(i, i+1));
			}
			if(sign.length()%5 != 0)
			{
				int s = sign.length()%5;
				for(int i=0; i<5-s; i++)
				{
					sign += "0";
				}
			}
			
			String output = "";
			for(int i=0; i<sign.length(); i+=5)
			{
				output += toChar(sign.substring(i, i+5));
			}
			
			System.out.println(output);
		}
	}
	
	static String toSign(String str)
	{
		switch(str)
		{
			case " ":
				return "101";
			case "'":
				return "000000";
			case ",":
				return "000011";
			case "-":
				return "10010001";
			case ".":
				return "010001";
			case "?":
				return "000001";
			case "A":
				return "100101";
			case "B":
				return "10011010";
			case "C":
				return "0101";
			case "D":
				return "0001";
			case "E":
				return "110";
			case "F":
				return "01001";
			case "G":
				return "10011011";
			case "H":
				return "010000";
			case "I":
				return "0111";
			case "J":
				return "10011000";
			case "K":
				return "0110";
			case "L":
				return "00100";
			case "M":
				return "10011001";
			case "N":
				return "10011110";
			case "O":
				return "00101";
			case "P":
				return "111";
			case "Q":
				return "10011111";
			case "R":
				return "1000";
			case "S":
				return "00110";
			case "T":
				return "00111";
			case "U":
				return "10011100";
			case "V":
				return "10011101";
			case "W":
				return "000010";
			case "X":
				return "10010010";
			case "Y":
				return "10010011";
			case "Z":
				return "10010000";
		}
		return "";
	}
	
	static String toChar(String str)
	{
		int n = 0;
		for(int i=0; i<str.length(); i++)
		{
			n += str.substring(str.length()-i-1, str.length()-i).equals("1") ? Math.pow(2, i) : 0;
		}
		if(n < 26)
		{
			return Character.toString((char)('A'+n));
		}
		else
		{
			switch (n)
			{
				case 26:
					return " ";
				case 27:
					return ".";
				case 28:
					return ",";
				case 29:
					return "-";
				case 30:
					return "'";
				case 31:
					return "?";
			}
		}
		
		return "";
	}
}

Measured memory_bytes: 56212
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            bool[] s = new bool[13];
            bool[] h = new bool[13];
            var c = new bool[13];
            var d = new bool[13];

            for(int i = 0; i < n; i++)
            {
                string[] str = Console.ReadLine().Split(' ');
                switch (str[0]) {
                    case "S":
                        s[int.Parse(str[1]) - 1] = true;
                        break;
                    case "H":
                        h[int.Parse(str[1]) - 1] = true;
                        break;
                    case "C":
                        c[int.Parse(str[1]) - 1] = true;
                        break;
                    case "D":
                        d[int.Parse(str[1]) - 1] = true;
                        break;
                }
            }
            for(int i = 0; i < 13; i++)
            {
                if (!s[i])
                {
                    Console.WriteLine("S "+(i+1));
                }
            }
            for (int i = 0; i < 13; i++)
            {
                if (!h[i])
                {
                    Console.WriteLine("H " + (i + 1));
                }
            }
            for (int i = 0; i < 13; i++)
            {
                if (!c[i])
                {
                    Console.WriteLine("C " + (i + 1));
                }
            }
            for (int i = 0; i < 13; i++)
            {
                if (!d[i])
                {
                    Console.WriteLine("D " + (i + 1));
                }
            }

        }
    }
}

Measured memory_bytes: 9180
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			if (op.equals("?"))break;
			
			int ans =0;
			
			switch (op) {
			case "+":
				ans = a+b;
				break;
				
			case "-":
				ans = a-b;
				break;
			
			case "*":
				ans = a*b;
				break;
			
			case "/":
				ans = a/b;
				break;			
			}
			
			System.out.println(ans);
		}

	}

}



Measured memory_bytes: 26172
import re

s = input()

p = re.compile('R+L+')
p2 = re.compile('RL')
flagments = re.findall(p, s)

result = []
for el in flagments:
    length = len(el)
    il, _ = p2.search(el).span()

    r = l = length // 2
    if length % 2 == 0:
        pass
    elif il % 2 == 0:
        r += 1
    else:
        l += 1
    
    result.extend([0]*il + [r, l] + [0]*(length - il - 2))

print(' '.join(map(str, result)))


Measured memory_bytes: 13812
N,K = map(int,input().split())
XY = [list(map(int,input().split())) for i in range(N)]

ans = float("inf")
for i in range(N):
    x1,y1 = XY[i]
    for j in range(i+1,N):
        x2,y2 = XY[j]
        u2 = max(y1,y2)
        d2 = min(y1,y2)
        r2 = max(x1,x2)
        l2 = min(x1,x2)
        for k in range(j+1,N):
            x3,y3 = XY[k]
            u3 = max(u2,y3)
            d3 = min(d2,y3)
            r3 = max(r2,x3)
            l3 = min(l2,x3)
            for kk in range(k+1,N):
                x4,y4 = XY[kk]
                u4 = max(u3,y4)
                d4 = min(d3,y4)
                r4 = max(r3,x4)
                l4 = min(l3,x4)
                num = 0
                for m in range(N):
                    x,y = XY[m]
                    if l4<=x<=r4 and d4<=y<=u4:
                        num += 1
                if num >= K:
                    tmp = (u4-d4)*(r4-l4)
                    if tmp < ans:
                        ans = tmp
            num = 0
            for m in range(N):
                x,y = XY[m]
                if l3<=x<=r3 and d3<=y<=u3:
                    num += 1
            if num >= K:
                tmp = (u3-d3)*(r3-l3)
                if tmp < ans:
                    ans = tmp
        num = 0
        for m in range(N):
            x,y = XY[m]
            if l2<=x<=r2 and d2<=y<=u2:
                num += 1
        if num >= K:
            tmp = (u2-d2)*(r2-l2)
            if tmp < ans:
                ans = tmp
print(ans)

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s,t;

int main(){
  cin >> s >> t;
  VSORT(s);VSORT(t);
  bool flag=true;
  rep(i,s.length()){
    if(s[i]!=t[i]) flag=false;
  }
  if(flag&&s.length()<t.length()) cout << "Yes" << endl;
  else if(t.back()<=s[0]) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main {
	static int n; // length of target array
	static int[] D; // segment tree

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

		// Initialize segment tree
		initSegTree(N);

		// Build segment tree
		int val;
		for(int i = 0; i < N; i++) {
			val = scanner.nextInt();
			update(i, val);
		}

		// Find sliding minimum elements
		for(int i = 0; i <= N-L; i++) {
			System.out.print(RMQ(i, i+L-1));
			if(i < N-L)
				System.out.print(" ");
		}
		System.out.println();
	}

	public static void initSegTree(int _n) {
		n = 1;
		while(n < _n) {
			n *= 2;
		}

		D = new int[2*n-1];
		Arrays.fill(D, Integer.MAX_VALUE);
	}

	public static void update(int i, int val) {
		// Convert array index to tree index
		i = i + n - 1;

		// Update the target position
		D[i] = val;

		// Update all of its ascendants
		while(i > 0) {
			i = (i-1)/2;
			D[i] = Math.min(D[2*i+1], D[2*i+2]);
		}
	}

	public static int RMQ(int s, int t) {
		return query(s, t+1, 0, 0, n);
	}

	private static int query(int s, int t, int k, int l, int r) {
		if(l >= t || r <= s)
			return Integer.MAX_VALUE;

		else if(l >= s && r <= t)
			return D[k];

		else {
			int left = query(s, t, 2*k+1, l, (l+r)/2);
			int right = query(s, t, 2*k+2, (l+r)/2, r);
			return Math.min(left, right);
		}
	}
}


Measured memory_bytes: 302332
using System;

namespace AOJ_DPL_2_knapsack
{
    class Program
    {
        static int n;
        static int size;
        static int[] v;
        static int[] w;
        static int[,] dp;
        static void Main(string[] args)
        {
            String[] str = Console.ReadLine().Split(' ');
            n = int.Parse(str[0]);
            size = int.Parse(str[1]);
            v = new int[n];
            w = new int[n];
            dp=new int[n+1,size+1];
            for (int i = 0; i < n; i++) {
                String[]str_t = Console.ReadLine().Split(' ');
                v[i] = int.Parse(str_t[0]);
                w[i] = int.Parse(str_t[1]);
            }
            Console.WriteLine(knapsack());
        }
        static int knapsack(){
            for (int j = 0; j < size; j++) {
                dp[n,j] = 0;
            }
            for(int i = n-1; 0<=i; i--){
                for (int j = 0; j <= size; j++)
                {
                    if (j < w[i])
                    {
                        dp[i, j] = dp[i + 1, j];
                    }
                    else
                    {
                        dp[i, j] = Math.Max(dp[i + 1, j], dp[i + 1, j - w[i]] + v[i]);
                    }
                }
            }
            return dp[0,size];
        }
    }
}

Measured memory_bytes: 13140
package main

// にぶたん使うらしいんだけどどうやってつかうの どうせ結果をソートするんだったらインデックスで参照できるじゃん

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

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

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	n := nextInt()
	ans := 0
	for i := 1; i <= n; i += 2 {
		tmp := 0
		for j := 1; j <= i; j++ {
			if i%j == 0 {
				tmp += 1
			}
		}
		if tmp == 8 {
			ans += 1
		}
	}
	fmt.Fprintln(out, ans)
}

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

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

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){

  char moji[120];
  int k,i;
  /* 文字列の入力 */
  scanf("%d%s",&k, moji);
 
  for(i=0; moji[i]!='\0'; ++i){
   
    if(i==k){
      printf("...\n");
      return 0;
    }
     printf("%c",moji[i]);
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 1664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String str = in.readLine();
    if(str.equals("RRR"))
      System.out.println(3);
    else if(str.equals("RRS") || str.equals("SRR"))
      System.out.println(2);
    else if(str.equals("SSS"))
      System.out.println(0);
    else
      System.out.println(1);
  }
}

Measured memory_bytes: 32496
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using i64 = int64_t;
using u64 = uint64_t;

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

constexpr int64_t MOD = 1'000'000'007LL;

#define INT(NAME) int NAME; cin>>NAME;
#define INT64(NAME) int64_t NAME; cin>>NAME;
#define VECTOR(NAME, TYPE, SIZE) std::vector<TYPE> NAME((SIZE));\
    for(int xxxx_i=0; xxxx_i<SIZE; xxxx_i++) cin>>NAME[xxxx_i];
#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)    

char getother(char a, char b) {
    char x = min(a, b);
    char y = max(a, b);
    assert(x != y);

    if (x=='G'&&y=='R') return 'B';
    if (x=='B'&&y=='G') return 'R';
    else return 'G';
}

void solve() {
    INT(K)
    ull ans = 0;
    FOR(i,1,K+1) {
        FOR(j,1,K+1) {
            FOR(k, 1,K+1) {
                ans+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
}

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string> 
#include <stdio.h>
using namespace std; 
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long int
#define REPI(a, b, i, inc) for(ll i = a; i < b; i = i + inc)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define F first
#define S second
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define testi ll t; cin>>t; REP(tc,1,t+1)
#define vec vector
#define veci vector<ll>
#define pi pair<ll,ll>
#define mp make_pair
#define all(v) v.begin(), v.end()
#define uset unordered_set
#define umap unordered_map

#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

#include <iostream>
 using namespace std;
 long long N, A[87], CurrentMoney = 1000;
int main() {
 cin >> N;
 for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 1; i <= N - 1; i++) {
 long long Stocks = 0;
 if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
 CurrentMoney += (A[i + 1] - A[i]) * Stocks;
}
 cout << CurrentMoney << endl;
 return 0;
}


Measured memory_bytes: 3608
import java.util.Scanner;
             
        public class Main {
        	public static void main(String[] args) {
                Scanner scan = new Scanner(System.in);
                String[] str = scan.nextLine().split(" ");
                Integer joinCount = new Integer(str[0]);
                Integer displayCount = new Integer(str[1]);
                Integer internalCount = 0;
                if(joinCount >= 10){
                  internalCount = displayCount;
                }else{
                  internalCount = (100*(10-joinCount))+displayCount;
                }
             	
                System.out.println(internalCount);
                scan.close();
            }
        }

Measured memory_bytes: 21844
from collections import Counter
n=int(input())
inp = list(map(int,input().split()))
c=Counter(inp)
ans=0
for item in c.values():
    ans+=(item*(item-1))//2
for i in range(len(inp)):
    x=c[inp[i]]
    y=(x-1)
    print (ans-(x*(x-1))//2+(y*(y-1))//2)

Measured memory_bytes: 26780
from math import *



M,K = tuple(map(int,input().split()))


def core():
    if 2**M <= K:
        return [-1]

    if M==0:
        return [0,0]

    if M==1:
        if K==0:
            return [0,0,1,1]
        if K==1:
            return [-1]

    if K==0:
        re = []
        for i in range(2**M):
            re.append(i)
            re.append(i)
        return re

    re = []
    for i in range(2**M):
        if i!=K:
            re.append(i)
    re.append(K)
    for i in range(2**M-1,-1,-1):
        if i!=K:
            re.append(i)
    re.append(K)
    return re


print(" ".join(map(str,core())))

Measured memory_bytes: 30132
#include<bits/stdc++.h>
using namespace std;
int main(){
    string t;
    cin >> t;
    for(int i = 0; i < t.size(); i++){
        if(t[i] == '?')
            cout << 'D';
        else 
            cout << t[i];
    }
    return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (ll (i) = (s); (i) < (e); ++(i))
#define per(i, s, e) for (ll (i) = (s); (i) >= (e); --(i))
#define all(x) x.begin(),x.end()
 

vector<pair<ll, ll>> factorize(ll n) {
    vector<pair<ll, ll>> res;
    for (ll i = 2; i*i <= n; i++) {
        if (n % i) continue;
        res.emplace_back(i, 0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main(void) {
    ll a, b; cin >> a >> b;
    ll g = __gcd(a, b);
    auto f = factorize(g);
    ll ans = f.size() + 1;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
    ll n;
    cin >> n;
    cout << n * n * n << endl;
}

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

#define int long long
using ll = long long;
using ld = long double;
using intpair = pair<int, int>;
using intmap = map<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
const int MOD = 1e9 + 7;
inline int mod (ll a, int m = MOD) { return (a % m + m) % m; }
inline bool bit (ll b, ll i) { return b & (1 << i); }
inline ll ceiv (ll a, ll b) { return (a + b - 1) / b; }
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define debug(x) cerr << #x << ": " << x << '\n'
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()

class UnionFind {
    vector<int> par, treesize;
    int groups;
    
public:
    UnionFind(int n){
        rep(i, n) par.push_back(i);
        treesize = vector<int>(n,1);
        groups = n;
    }
    
    int root(int x){
        if(x == par[x]) return x;
        return par[x] = root(par[x]);
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        if(same(x,y)) return;
        int rx = root(x), ry = root(y);
        treesize[ry] += treesize[rx];
        treesize[rx] = 0;
        groups--;
        par[rx] = ry;
    }
    
    int get_size(int x){
        return treesize[root(x)];
    }
    
    int get_groups(){ return groups; }
};

signed main(){
    int n, k;
    cin >> n >> k;
    vi p(n), c(n);
    rep(i,n){
        cin >> p[i]; p[i]--;
    }
    rep(i,n) cin >> c[i];
    
    UnionFind loop_union(n);
    vi loop_score(n);
    rep(i,n){
        if(loop_union.get_size(i) != 1) continue;
        int j = p[i];
        int score = c[i];
        while(j != i) {
            loop_union.unite(j, p[j]);
            score += c[j];
            j = p[j];
        }
        loop_score[loop_union.root(i)] = score;
    }
    
    int ans = -9e18;
    rep(i,n){
        int t_score = 0;
        const int LOOPSIZE = loop_union.get_size(i);
        
        int j = i;
        rep(_, min(k, LOOPSIZE)){
            j = p[j];
            t_score += c[j];
            ans = max(ans, t_score);
        }
        
        const int LOOPS = k / LOOPSIZE;
        t_score = (LOOPS - 1) * loop_score[loop_union.root(i)];
        
        const int STEPS = k - ((LOOPS - 1) * LOOPSIZE);
        if(LOOPS == 0) continue;
        
        j = i;
        rep(_, STEPS){
            j = p[j];
            t_score += c[j];
            ans = max(ans, t_score);
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3952
def main():
    n,p = map(int,input().split())
    s = input()
    if p == 2:
        ans = 0
        for i in range(n):
            if int(s[i])%2 == 0:
                ans += i+1
        print(ans)
        return
    if p == 5:
        ans = 0
        for i in range(n):
            if int(s[i])%5 == 0:
                ans += i+1
        print(ans)
        return
    dp = [0 for _ in range(p)]
    dp[0] += 1
    x = 0
    
    for i in range(n):
        x = (x+int(s[n-1-i])*pow(10,i,p))%p
        dp[x] += 1
    ans = 0
    for i in range(p):
        ans += (dp[i]*(dp[i]-1))//2
    print(ans)
 
if __name__ == "__main__":
    main()

Measured memory_bytes: 3500
from sys import stdin
INF = 1<<21
WHITE, GRAY, BLACK = 0, 1, 2
n = int(stdin.readline())
M = [[INF] * n for _ in range(n)]
for i in range(0, n):
    for j, e in enumerate(list(map(int, stdin.readline().split()))):
        if e != -1: M[i][j] = e
d = [INF] * n
d[0] = 0
color = [False] * n
def prim():
    while True:
        minv = INF
        u = -1
        for i in range(0, n):
            if minv > d[i] and color[i] != True:
                u = i
                minv = d[i]
        if u == -1: break
        color[u] = True
        for v in range(0, n):
            if color[v] != True and d[v] > M[u][v]:
                d[v] = M[u][v]
    return sum(d)
print(prim())

Measured memory_bytes: 7824
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int K = sc.nextInt();
        String S = sc.next();

        char moji[] =S.toCharArray();
        switch(moji[K - 1]) {
            case 'A':
                moji[K - 1] = 'a';
                break;
            case 'B':
                moji[K - 1] = 'b';
                break;
            case 'C':
                moji[K -1 ] = 'c';
        }
        for(int i = 0;i < N;i++){
            System.out.print(moji[i]);
        }
    }
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x;
    cin >> x;
    if(x < 1200){
        cout << "ABC";
    } else {
        cout << "ARC";
    }
    return 0;
}


Measured memory_bytes: 764
sx, sy, tx, ty = map(int, input().split())
dx, dy = tx-sx, ty-sy
ans = []
for _ in range(dy):
    ans.append('U')
for _ in range(dx):
    ans.append('R')
for _ in range(dy):
    ans.append('D')
for _ in range(dx):
    ans.append('L')
ans.append('L')
for _ in range(dy+1):
    ans.append('U')
for _ in range(dx+1):
    ans.append('R')
ans.append('D')
ans.append('R')
for _ in range(dy+1):
    ans.append('D')
for _ in range(dx+1):
    ans.append('L')
ans.append('U')
print(''.join(ans))

Measured memory_bytes: 3188
# coding: utf-8
# Your code here!
N,K=map(int,input().split())

A=list(map(int,input().split()))


for _ in range(K):
    ans=[0]*len(A)
    start=[0]*len(A)
    end=[0]*len(A)
    
    for index,item in enumerate(A):
        start[max(0,index-item)]+=1
        end[min(len(end)-1,index+item)]+=1
    
    #print(start)
    #print(end)
    
    temp=0
    for i in range(len(ans)):
        temp+=start[i]
        ans[i]=temp
        temp-=end[i]
    
    if A==ans:
        break
    else:
        A=ans[:]

print(*ans)

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

int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  
  cout<<(char)(s1.at(0)-0x20)<<(char)(s2.at(0)-0x20)<<(char)(s3.at(0)-0x20)<<endl;
}

Measured memory_bytes: 384
/*
 鶴亀算
 動物の総数x匹 1<=x<=100
 足の総数y本 1<=y<=100
 */

/*
 普通に連立方程式解かせればいい…？
 c+t=x
 2c+4t=y
 2c+2t=2x
 */
/*
 足の本数を2で割って
 鶴…1本、亀…2本
 総数…y/2本
 一旦x全部鶴だとして……
 */
#include<stdio.h>
 
int main(void){
    int x,y;
    //int ka = 4,tu = 2;
    scanf("%d %d",&x,&y);
    /*if(x < 1 || x > 100 || y < 1 || y > 100){
        goto end;
    }*/
    int t,k,as,flag = 0;
    for(t = 0; t <= x;t++){
        k = x - t;
        as = t * 2 + k * 4;
        if(as == y){
            flag++;
            break;
        }
    }
    switch (flag){
        case 0:
            printf("No\n");
            break;
        case 1:
            printf("Yes\n");
            break;
    }
    return 0;
}


Measured memory_bytes: 1624
A,B =[int(i) for i in input().split()]

def zo(n):
    if n % 2 == 0:
        return 0
    else:
        return 1

if A % 2 == 0 and B % 2 == 0:
    print(zo((B - A) // 2 ) ^ B)
elif A % 2 == 0 and B % 2 != 0:
    print(zo((B - A + 1) // 2))
elif A % 2 != 0 and B % 2 == 0:
    print(A ^ zo((B - A - 1) // 2) ^ B)
else:
    print(A ^ zo((B - A) // 2))

Measured memory_bytes: 3064
#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(0);
    
    ll n, m;
    cin >> n >> m;
    // Sがn個、cがm個
    ll scc = min(n, m/2);
    ll cccc = (m - scc*2) / 4;
    cout << scc + cccc << endl;
}

Measured memory_bytes: 3612