akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

ll edge[114123];
ll* graph[114123];
ll* ednum[114123];
ll ans[114123];

void pushGraph(ll v1, ll v2, ll num){
    graph[v1] = realloc( graph[v1] , sizeof(ll)*(edge[v1]+1) );
    ednum[v1] = realloc( ednum[v1] , sizeof(ll)*(edge[v1]+1) );
    
    graph[v1][edge[v1]] = v2;
    ednum[v1][edge[v1]] = num;
    edge[v1]++;

    graph[v2] = realloc( graph[v2] , sizeof(ll)*(edge[v2]+1) );
    ednum[v2] = realloc( ednum[v2] , sizeof(ll)*(edge[v2]+1) );
    
    graph[v2][edge[v2]] = v1;
    ednum[v2][edge[v2]] = num;
    edge[v2]++;
}

void dfs(ll curV, ll from, ll preC){
    ll nextcol = 1;
    rep(i,0,edge[curV]){
        if(graph[curV][i]==from) continue;
        // ll color;
        if(nextcol==preC) nextcol++;
        ans[ednum[curV][i]] = nextcol;
        // printf("%lld %lld %lld\n",graph[curV][i],curV,color);
        dfs(graph[curV][i],curV,nextcol++);
    }
}

int main(void){
    // char ;
    ll n;
    // ll ans=0;
    scanf("%lld",&n);
    ll a,b;
    rep(i,0,n-1){
        scanf("%lld%lld",&a,&b);
        pushGraph(a-1,b-1,i);
    }

    printf("%lld\n",maxn(114123,edge));
    
    dfs(0,0,0);
    rep(i,0,n-1){
        printf("%lld\n",ans[i]);
    }
    rep(i,0,n){
        free(graph[i]);
    }
    // printf("%lld\n");
    return 0;
}


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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n , x , t ;
  cin >> n >> x >> t ;
  
  if(n%x == 0) {
    cout << (n/x) * t ;
  }
  else cout << (n/x + 1) * t ;


}


Measured memory_bytes: 3632
N = int(input())
A = list(map(int,input().split()))
s = []

for i in range(N):
  s.append([A[i],i+1])
s.sort()

ans = ''
for i in range(N):
  ans += str(s[i][1])
  if(i != N-1): 
    ans += ' '
print(ans)
  


Measured memory_bytes: 22016
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
ll dp[2][4];
int now = 0;
int t[3];
ll p2[32];

int main() {
	int n;
	cin >> n;
	int lr = n % 2;
	ll v[200010];
	int l = n / 2;
	int r = n / 2 + 1;
	if (n % 2 == 1) {
		l++;
		r++;
	}
	for (size_t i = 0; i < n; i++)
	{
		int a;
		cin >> a;
		if (lr == 0) {
			v[r++] = a;
		}
		else v[l--] = a;
		lr = (lr + 1) % 2;
	}

	for (size_t i = 1; i <= n; i++)
	{
		if (i > 1) cout << " ";
		cout << v[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

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

	    long A=Long.parseLong(scanner.next());
	    long B=Long.parseLong(scanner.next());
	    long C=Long.parseLong(scanner.next());
	    long D=Long.parseLong(scanner.next());

	    long ax= Math.floorDiv(A,C);
	    long bx= Math.floorDiv(B,C);
	    long ay= Math.floorDiv(A,D);
	    long by= Math.floorDiv(B,D);

	    long cd = C * D / f(C, D);
        long az=Math.floorDiv(A,cd);
        long bz=Math.floorDiv(B,cd);

        long ac= A-ax-ay+az;
        long bc= B-bx-by+bz;
        long c=bc-ac;
        if ((A%C)!=0 && (A%D)!=0)c++;
	    System.out.println(c);

	}

	public static long f(long m, long n) {
		if (m<n) {
			m^=n;
			n^=m;
			m^=n;
		}

		while(true) {
			long t=m%n;
			if (t==0) {
				return n;
			} else {
				m=n;
				n=t;
			}
		}
	}
}

Measured memory_bytes: 35732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        final int N = Integer.parseInt(reader.readLine());
        Map<String, Integer> map = new LinkedHashMap<>();
        Long count = (long) 0;
        for (int i = 0; i < N; i++) {
            String str = reader.readLine();
            char[] chars = str.toCharArray();
            Arrays.parallelSort(chars);
            str = new String(chars);
            if (map.containsKey(str)) {
                count += map.get(str);
                map.put(str, map.get(str) + 1);
            } else {
                map.put(str, 1);
            }
        }
        System.out.println(count);
        reader.close();

    }

}


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

#define SWAP(type, a, b){type tmp=a;a=b;b=tmp;}

long gcd(long m, long n){
    if(m < n) SWAP(long, m, n);
    while(n != 0){
        long tmp = m % n;
        m = n;
        n = tmp;
    }
    return m;
}

int main(){
    int N;
    long X, xtmp;
    long dist[100002];

    cin >> N >> X;
    for(int i=0;i<N;i++){
        cin >> xtmp;
        dist[i] = abs(X - xtmp);
    }
    long ans = dist[0];
    for(int i=0;i<N;i++){
        ans = gcd(ans, dist[i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
import numpy as np
h, w = map(int, input().split())
grid = np.array([list(input()) for _ in range(h)], dtype="str")

hgrid = np.zeros((h, w), dtype="int")

for hi in range(h):
    hdot = np.array(grid[hi] == ".", dtype="int")
    hgrid[hi] = hgrid[hi-1] * hdot + hdot
    
for hi in range(h-2, -1, -1):
    hi_1 = np.minimum(hgrid[hi+1], hgrid[hi] * hgrid[hi+1])
    hgrid[hi] = np.maximum(hgrid[hi], hi_1)
    
wgrid = np.zeros((h, w), dtype="int")

for wi in range(w):
    wdot = np.array(grid[:, wi] == ".", dtype="int")
    wgrid[:, wi] = wgrid[:, wi-1] * wdot + wdot
    
for wi in range(w-2, -1, -1):
    wi_1 = np.minimum(wgrid[:, wi+1], wgrid[:, wi] * wgrid[:, wi+1])
    wgrid[:, wi] = np.maximum(wgrid[:, wi], wi_1)

print(np.max(wgrid + hgrid) - 1)

Measured memory_bytes: 141728
#include <iostream>
#include <vector>

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)

using namespace std;

void call(int n){
	for(int i = 1; i <= n; ++i) {
		int x = i;
		if (x % 3 == 0){
			cout << " " << i;
			continue;
		}
		while(x > 0) {
			if (x % 10 == 3) {
				cout << " " << i;
				break;
			}
			x /= 10;
		}
	}
	cout << endl;
}

int main(void) {
	int in;
	cin >> in;
	call(in);

	return 0;
}


Measured memory_bytes: 3096
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]

for i in l:
    if i[2] != 0:
        x,y,h = i
# print(x,y,h)

for cx in range(101):
    for cy in range(101):
        h_pre = h+abs(x-cx)+abs(y-cy)
        flag = True
        for i in range(n):
            X,Y,H = l[i]
            if H != max(h_pre-abs(X-cx)-abs(Y-cy),0):
                flag = False
        if flag:
            print(cx,cy,h_pre)
            exit()

Measured memory_bytes: 74392
#include <iostream>
#include <math.h>

typedef long long ll;

#define FOR(i,a,b) for(ll i = (a);i < (b);++i)
#define REP(i,n) FOR(i,0,n)

#define debug(x) cout << #x << "=" << x << endl;

using namespace std;

int N,A,B;
int enemyLP[100000];

bool check(ll mid){

    ll cnt = 0;
    int addDmg = A-B;
    int splashDmg = B;

    ll T = mid;

    REP(i,N){
        
        if(enemyLP[i] > splashDmg * mid){
            cnt += (enemyLP[i] - splashDmg * mid) / addDmg;
            if((enemyLP[i] - splashDmg * mid) % addDmg != 0) cnt++;
        }
        
    }
    if(cnt <= mid){
        return true;
    }else{
        return false;
    }
}

int main(void){

    cin >> N >> A >> B;

    REP(i,N){
        cin >> enemyLP[i];
    }

    int ok = (int)1e+9;
    int ng = -1;
    
    while(abs(ok - ng) > 1){

        ll mid = (ok + ng) / 2;

        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }

    cout << ok << endl;
    
    return 0;
}


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

// #define multitest 1
// #define Debug 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

typedef long long ll;
typedef long double ld;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;

void solve()
{
	int n;
	cin >> n;
	vector<int> dp(3), inp(3);
	for (int i = 0; i < n; ++i)
	{
		cin >> inp[0] >> inp[1] >> inp[2];
		vector<int> newDp(3);
		newDp[0] = inp[0] + max(dp[1], dp[2]);
		newDp[1] = inp[1] + max(dp[0], dp[2]);
		newDp[2] = inp[2] + max(dp[1], dp[0]);
		dp = newDp;
	}
	cout << max(max(dp[0], dp[1]), dp[2]);
}

int main()
{
#ifndef Debug
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#endif
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

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

typedef long long ll;

ll a, b;

void main2() {
    scanf("%lld %lld", &a, &b);
    if(a > b) swap(a, b);

    if(a == b) {
        printf("%lld\n", 2 * (a - 1));
        return;
    }

    ll r = sqrt(a * b);
    if(r * r == a * b) {
        printf("%lld\n", 2 * (r - 1) - 1);
    }
    else if(r * (r + 1) < a * b) {
        printf("%lld\n", 2 * r - 1);
    }
    else printf("%lld\n", 2 * (r - 1));
}

int Q;
int main() {
    scanf("%d", &Q);
    while(Q--) main2();
}


Measured memory_bytes: 256
def test():
    n,k = map(int,input().split())
    a = []; ans = 0
    for i in range(1,n+1):
        result = i
        count = 1
        while result < k:
            result *= 2
            count /= 2
        ans += count
    print("{:.12f}".format((1/n)*ans))



if __name__ == "__main__":
    test()


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  int H,W;
  cin >> H >> W;
  char grid[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> grid[i][j];
    }
  }

  bool iex[H];
  bool jex[W];
  fill(iex,iex+H,true);
  fill(jex,jex+W,true);

  for(int i=0;i<H;i++){
    bool isok=true;
    for(int j=0;j<W;j++){
      if(grid[i][j]=='#'){
        isok=false;
        break;
      }
    }
    if(isok) iex[i]=false;
  }
  for(int j=0;j<W;j++){
    bool isok=true;
    for(int i=0;i<H;i++){
      if(grid[i][j]=='#'){
        isok=false;
        break;
      }
    }
    if(isok) jex[j]=false;
  }

  /*for(int i=0;i<H;i++){
    cout << iex[i] << endl;
  }*/

  for(int i=0;i<H;i++){
    if(iex[i]){
      for(int j=0;j<W;j++){
        if(jex[j]) cout << grid[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);
	lli x;
	cin >> x;
	for (int a = 1; a<1000; ++a){
		lli a5 = 1;
		rep(i,5) a5*=a;
		for(int b = -1000; b < 1000; ++b){
			lli b5 = 1;
			rep(i,5) b5*=b;
			if(a5 - b5 == x){
				cout << a << " " << b << endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3628
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

bool iseven(string s){
	int n = s.size()/2;
	return s.substr(0,n) == s.substr(n);
}

void Main()
{
	string s;
	cin >> s;
	int n = s.size();
  	int m = n;
	rep(i,m){
		n -= 2;
		s = s.substr(0, n);
      	// cout << i << ": " << s << ": " << iseven(s) << endl;
		if(iseven(s)) break;
	}
	cout << s.size() << endl;
	return;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, start, end) for(int i = start; i < end; i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cout << (x) << endl;
typedef long long ll;
const int MAX = 999999999;

int main(){
    string s, t;
    cin >> s >> t;

    sort(all(s));
    sort(all(t));
    reverse(all(t));

    if(s < t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

struct edge {
    ll u, v, a, b;
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m, s;
    cin >> n >> m >> s;
    const int mx = 3000;
    s = min(s, mx - 1);
    vector<vector<pair<ll, int>>> g(mx * n);
    for (int i = 0; i < m; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        for (int j = a; j < mx; j++) {
            g[u * mx + j].emplace_back(b, v * mx + j - a);
            g[v * mx + j].emplace_back(b, u * mx + j - a);
        }
    }
    for (int i = 0; i < n; i++) {
        int c, d;
        cin >> c >> d;
        for (int j = 0; j < 2600; j++) {
            int to = i * mx + min(mx - 1, j + c);
            g[i * mx + j].emplace_back(d, to);
        }
    }
    vector<ll> d(mx * n, 1e18);
    d[s] = 0;
    priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
    pq.push(pair<ll, int>(0, s));
    while (!pq.empty()) {
        pair<ll, int> p = pq.top();
        pq.pop();
        int v = p.second;
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : g[v]) {
            if (d[e.second] > d[v] + e.first) {
                d[e.second] = d[v] + e.first;
                pq.push(pair<ll, int>(d[e.second], e.second));
            }
        }
    }
    for (int i = 1; i < n; i++) {
        ll ans = 1e18;
        for (int j = 0; j < mx; j++) {
            ans = min(ans, d[i * mx + j]);
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 27140
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();
		String str[] = s.split("");

		if (kaibun(str)) {
			String s1[] = s.substring(0, (str.length - 1) / 2).split("");
			String s2[] = s.substring((str.length + 3) / 2 - 1, str.length).split("");
			if (kaibun(s1) && kaibun(s2)) {
				System.out.println("Yes");
			} else {
				System.out.println("No");
			}
		} else {
			System.out.println("No");
		}
	}

	static boolean kaibun(String str[]) {
		for (int i = 0; i < str.length; i++) {
			if (!str[i].equals(str[str.length - i - 1])) {
				return false;
			}
		}
		return true;
	}
}

Measured memory_bytes: 32920
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

using P = pair<int, int>;
#define fi first
#define se second

int main() {
    int n;
    cin >> n;
    int b = (1 << n);
    vector<P> test[n];
    for (int i=0, ai; i<n; i++) {
        cin >> ai;
        for (int j=0, x, y; j<ai; j++) {
            cin >> x >> y;
            x--;
            test[i].push_back({x, y});
        }
    }
    int ans = 0, cnt;
    for (int i=0; i<b; i++) {
        cnt = 0;
        bool yes = true;
        for (int j=0; j<n; j++) {
            if (i & (1 << j)) {
                cnt++;
                for (auto &ti:test[j]) {
                    if (ti.se != ((i >> ti.fi) & 1)) yes = false;
                }
            }
        }
        if (yes) {
            ans = max(ans, cnt);
        }
    }
    cout << ans << '\n';
    return 0;
}

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

int main()
{
    string S;
    cin >> S;
    if (S.at(0) == 'S' && S.at(1) == 'S' && S.at(2) == 'S')
    {
        cout << 0 << endl;
    }
    else if (S.at(0) == 'S' && S.at(1) == 'S' && S.at(2) == 'R')
    {
        cout << 1 << endl;
    }
    else if (S.at(0) == 'S' && S.at(1) == 'R' && S.at(2) == 'S')
    {
        cout << 1 << endl;
    }
    else if (S.at(0) == 'S' && S.at(1) == 'R' && S.at(2) == 'R')
    {
        cout << 2 << endl;
    }
    else if (S.at(0) == 'R' && S.at(1) == 'S' && S.at(2) == 'S')
    {
        cout << 1 << endl;
    }
    else if (S.at(0) == 'R' && S.at(1) == 'S' && S.at(2) == 'R')
    {
        cout << 1 << endl;
    }
    else if (S.at(0) == 'R' && S.at(1) == 'R' && S.at(2) == 'S')
    {
        cout << 2 << endl;
    }
    else if (S.at(0) == 'R' && S.at(1) == 'R' && S.at(2) == 'R')
    {
        cout << 3 << endl;
    }
    return 0;
}

Measured memory_bytes: 3632
n, k  = gets.chomp.split(" ").map(&:to_i)
s = gets.chomp
pre = s[0]
dif = 0
same = 0
1.upto(n-1) do |i|
  if pre == s[i]
    same += 1
  else
    dif += 1
  end
  pre = s[i]
end
if k*2 < dif
  same += k*2
else
  same += dif
end
puts same

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],ans=n;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int j=0;j<n-1;j++){
    for(int k=j+1;k<n;k++){
      if(a[j]>a[k]){
        int tmp=0;
        tmp=a[j];
        a[j]=a[k];
        a[k]=tmp;
      }
    }
  }
  for(int l=0;l<n-1;l++){
    if(a[l]==a[l+1]){
      ans--;
    }
  }
  if(ans==0){
    ans++;
  }
  cout << ans << endl;
  return 0;
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BFizzBuzzSum solver = new BFizzBuzzSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class BFizzBuzzSum {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long n = in.nextLong();
            long total = 0;
            for (int i = 1; i <= n; i++) {
                if (i % 3 != 0 && i % 5 != 0) {
                    total += i;
                }
            }

            out.println(total);


        }

    }

    static class Scanner {
        private final InputStream in;
        private final byte[] buffer;
        private int ptr;
        private int buflen;

        public Scanner(InputStream in) {
            this.in = in;
            this.buffer = new byte[1024];
            this.ptr = 0;
            this.buflen = 0;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) return true;
            else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) return false;
            }
            return true;
        }

        private byte readByte() {
            if (hasNextByte()) return buffer[ptr++];
            return -1;
        }

        private boolean isPrintableChar(byte c) {
            return '!' <= c && c <= '~';
        }

        private void skipUnprintable() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
        }

        public boolean hasNext() {
            skipUnprintable();
            return hasNextByte();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            byte b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 25860
import math

def is_prime(n):
    if n == 1: return False
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

Q = int(input())
s = [0] * (10**5+1)
for i in range(1, 10**5):
    s[i+1] = s[i] + int(is_prime(i) and is_prime((i+1)//2))
for _ in range(Q):
    left, right = map(int, input().split())
    print(s[right+1]-s[left])

Measured memory_bytes: 52316
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <iostream>
#include <stdlib.h>
using namespace std;

int h,w,k;
bool locked[801][801]={};
bool found[801][801]={};
int depth[801][801]={};
pair<int , int> parent[801][801]={};


int main()
{

  cin >> h >> w >> k;

  //入力する
  int s,t;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      char tmp;
      cin >> tmp;
      if(tmp == '.')
        locked[i][j] = 0;
      else if(tmp == '#')
        locked[i][j] = 1;
      else{
        locked[i][j] = 0;
        s = i;
        t = j;
      }
    }
  }


  queue<pair<int ,int>> q;
  q.push(make_pair(s,t));
  found[s][t] = 1;
  //sからbfsを実施し、距離k以内で行ける点の距離を計算する

  while(!q.empty()){
    pair<int ,int> p = q.front();
    q.pop();
    if(p.first > 0){
      //上を調査
      if(!found[p.first - 1][p.second] && !locked[p.first - 1][p.second]){
        q.push(make_pair(p.first - 1,p.second));
        found[p.first - 1][p.second] = true;
        depth[p.first - 1][p.second] = depth[p.first][p.second] + 1;
      }
    }
    if(p.first < h-1){
      //下を調査
      if(!found[p.first + 1][p.second] && !locked[p.first + 1][p.second]){
        q.push(make_pair(p.first + 1,p.second));
        found[p.first + 1][p.second] = true;
        depth[p.first + 1][p.second] = depth[p.first][p.second] + 1;
      }
    }
    if(p.second > 0){
      //左を調査
      if(!found[p.first][p.second - 1] && !locked[p.first][p.second -1]){
        q.push(make_pair(p.first,p.second - 1));
        found[p.first][p.second - 1] = true;
        depth[p.first][p.second - 1] = depth[p.first][p.second] + 1;
      }
    }
    if(p.second < w-1){
      //右を調査
      if(!found[p.first][p.second + 1] && !locked[p.first][p.second +1]){
        q.push(make_pair(p.first,p.second + 1));
        found[p.first][p.second + 1] = true;
        depth[p.first][p.second + 1] = depth[p.first][p.second] + 1;
      }
    }
  }

  //最小値を出力する

  int ans = 2000;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(found[i][j] && depth[i][j] <= k ){
        if(i == 0 || i == h-1 || j == 0 || j == w-1 ){
          ans = 1;
        }
        else{
          int tmp = 2000;
          tmp = min(min( i , h - 1 -i ),min( j , w - 1 - j));
          ans = min(ans, 1 + tmp/k + (tmp%k > 0 ));
        }
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9088
from collections import deque
while True:
    W,H = map(int,input().split())
    if W == 0: break
    src = [list(map(int,input().split())) for i in range(H)]
    visited = [[0 for x in range(W)] for y in range(H)]
    dxy = [(1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)]
    ans = 0
    for y in range(H):
        for x in range(W):
            if visited[y][x] or not(src[y][x]): continue
            ans += 1
            visited[y][x] = 1
            q = deque([(x,y)])
            while q:
                x0,y0 = q.popleft()
                for dx,dy in dxy:
                    nx,ny = x0+dx, y0+dy
                    if not(0 <= nx < W) or not(0 <= ny < H): continue
                    if visited[ny][nx] or not(src[ny][nx]): continue
                    visited[ny][nx] = 1
                    q.append((nx,ny))
    print(ans)

Measured memory_bytes: 6048
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back
 
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int x,t,ans;
int main(){
	cin>>x>>t;
	ans=x-t;
	if(ans<0){
		cout<<"0"<<endl;
		return 0;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc106/tasks/abc106_c

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

string S;
ll K, r;

int main()
{
  cin >> S >> K;

  if (S[0] == '1')
  {
    int i = 0;
    while (i < min(K - 1, (ll)S.length()) && '1' == S[i])
      i++;
    r = S[i] - '0';
  }
  else
  {
    r = S[0] - '0';
  }

  cout << r << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int n, a, b;
  cin >> n >> a >> b;

  int ans = min(n * a, b);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
a, speedA = map(int, input().split())
b, speedB = map(int, input().split())
t = int(input())
def do():
    if speedB >= speedA:
        print("NO")
        return 0

    d = abs(a - b)
    x = speedA - speedB
    #if d % x != 0:
    #    print("NO")
    #    return 0

    reachTime = d / x
    if reachTime <= t:
        print("YES")
        return 0
    else:
        print("NO")
        return 0
do()


Measured memory_bytes: 61708
#include<iostream>
using namespace std;
int main(){
    int N, V[20], C[20];
    cin>>N;
    for(int i=0; i<N; i++) cin>>V[i];
    for(int i=0; i<N; i++) cin>>C[i];
    int sum = 0;
    for(int i=0; i<N; i++)
    {
        if(V[i]>C[i]) sum+=V[i]-C[i];
    }
    cout<<sum;
    return 0;
}

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

using namespace std;

void outStr(vector<int>& ary) {

	string aryStr = "";
	for (int i = 0; i < ary.size(); i++)
	{
		aryStr = aryStr + to_string(ary[i]);
		if (i < ary.size() - 1) aryStr = aryStr + " ";
	}

	cout << aryStr << endl;
	return;
}


int insertSort(vector<int>& ary, int g) {

	int v = 0;; int j = 0; int cnt = 0;
	for (int i = g; i < ary.size();i++) {
		v = ary[i];
		j = i - g;

		while (j >= 0 && ary[j] > v)
		{
			ary[j + g] = ary[j];
			j = j - g;
			cnt++;
		}
		ary[j + g] = v;

	}

	return cnt;
}



int main() {

	int N;
	cin >> N;
	vector<int> ary(N);
	for (int i = 0; i < N; i++) {
		cin >> ary[i];
	}

	vector<int> G;
	int h = 0;
	while (h <= N /5)
	{
		h = 3 * h + 1;
		G.push_back(h);
	}
	reverse(G.begin(), G.end());

	int cnt = 0;
	int m = G.size();

	for (int i = 0;i < m;i++) {
		cnt += insertSort(ary, G[i]);
	}


	cout << m << endl;
	outStr(G);
	cout << cnt << endl;

	for (int i = 0; i < N; i++) {
		cout << ary[i] << endl;

	}

	return 0;
}



Measured memory_bytes: 6732
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll K;
  cin >> K;
  ll ans = 0;
  for (int i = 1; i <= K; i++) {
    for (int j = i + 1; j <= K; j++) {
      if (i % 2 != j % 2) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
//author-micheal corleone
//the godfaher
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>

#include <set> 
#include<algorithm>
#define ll long long int


#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;
 
 bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 
 

ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 
int main()
{
   cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
     ll t;
    // cin>>t;
     t=1;
   while(t--)
    {
        ll n,i1,i2,k,m,j,j1,f,a1,i31,i3,j2,i5,i4,i6,i7,i;    
       i4=INT_MIN,i1=0;
       f=0;
      // string s1,s2,s3;
      ll res,res1,ans;
      ll s1,s2,s3;
      s2=0;
      s1=0;
      ll q;
      i31=0;
       cin>>n>>q;
       
	   
	   	  s1=s1+((n)*(n-1))/2;
	      s1=s1+((q)*(q-1))/2;
	   cout<<s1;
	   
       
      
	 //  cout<<q<<endl;
	  
	  
	  
	  
	 
      
     
      
   }
}

       
  

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;

const int md = 1000000007;

inline int add(int a, int b) 
{
	a += b;
	if (a >= md) a -= md;
	return a;
}
inline int sub(int a, int b) 
{
	a -= b;
	if (a < 0) a += md;
	return a;
}
inline int mul(int a, int b) 
{
	return (int)((long long)a * b % md);
}
inline int po(int a, int b) 
{
	int r = 1;
	while (b) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
		b >>= 1;
	}
	return r;
}
inline int inv(int a) 
{
	return po(a, md - 2);
}
inline int di(int a, int b) 
{
	return mul(a, inv(b));
}

const int N = 200000;
pair<int, bool> a[N];
int n, k;

int neg() {
	int p = 1;
	for (int i = n - 1; i >= n - k; --i) p = mul(p, a[i].first);
	p = sub(0, p);
	return p;
}

int main() 
{
	scanf("%d%d", &n, &k);
	int v;
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		if (v >= 0) a[i] = make_pair(v, 1);
		else a[i] = make_pair(-v, 0);
	}
	sort(a, a + n, greater<pair<int, bool> >());
	int p = 1;
	bool pos = true;
	for (int i = 0; i < k; ++i) {
		p = mul(p, a[i].first);
		pos = !((pos || a[i].second) && !(pos && a[i].second));
	}
	if (pos == 1) printf("%d\n", p);
	else {
		int fl1, fr1;
		bool ok1;
		for (fl1 = k - 1; fl1 >= 0 && a[fl1].second; --fl1);
		for (fr1 = k; fr1 < n && !a[fr1].second; ++fr1);
		if (fl1 >= 0 && fr1 < n) ok1 = true;
		else ok1 = false;
		
		int fl2, fr2;
		bool ok2;
		for (fl2 = k - 1; fl2 >= 0 && !a[fl2].second; --fl2);
		for (fr2 = k; fr2 < n && a[fr2].second; ++fr2);
		if (fl2 >= 0 && fr2 < n) ok2 = true;
		else ok2 = false;
		
		if (!ok1 && !ok2) printf("%d\n", neg());
		else {
			if ((ok1 && !ok2) || (ok1 && ok2 && (long long)a[fr1].first * a[fl2].first >= (long long)a[fr2].first * a[fl1].first)) printf("%d\n", mul(di(p, a[fl1].first), a[fr1].first));
			else printf("%d\n", mul(di(p, a[fl2].first), a[fr2].first));
		}
	}
	return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> x(n);
  rep(i,n) cin >> x.at(i);
  ll l = 0, r = 0, z = 0;//0より左の数の個数, ,0のインデックス
  rep(i,n){
    if(x.at(i)<0)l++;
    else if(x.at(i)<0) r++;
    z++;
  }

  ll ans = 200000000000;

  //大きさkの部分集合ltor,rtol両方を考える。
  for(ll i = 0; i <= n-k; i++){
    ll tl = i, tr = i+k-1, tmp = 0;
    if(0<=x.at(tl))tmp = x.at(tr);
    else if(x.at(tr)<=0)tmp = -x.at(tl);
    else{
      tmp = min(abs(x.at(tl)*2)+x.at(tr),abs(x.at(tr)*2)+abs(x.at(tl)));
    }
    ans = min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <queue>

#define MAX_N 5000

using namespace std;

int N;
int E;
vector<int > in[MAX_N + 1];
vector<int > out[MAX_N + 1];
queue<int > S;
queue<int > L;

bool multi_flag;

bool in_exist(int v){
	bool flag = false;
	if(in[v].empty()) return false;
	for(int i = 0;i < in[v].size();i++){
		if(in[v][i] != -1) return true;
	}
	return false;
}

void solve(){
	for(int i = 1;i <= N;i++){
		if(in_exist(i) == false) S.push(i);
	}

	while(!S.empty()){
		int u = S.front();S.pop();
		L.push(u);
		int entered = 0;
		for(int i = 0;i < out[u].size();i++){
			int to = out[u][i];
			for(int i = 0;i < in[to].size();i++){
				if(in[to][i] == u) in[to][i] = -1;
			}
			
			if(in_exist(to) == false){
				S.push(to);
				entered++;
			}
		}
		if(entered >= 2) multi_flag = true;
	}

	return ;
}

int main(){

	scanf("%d",&N);
	scanf("%d",&E);
	//for(int i = 0;i <= MAX_N;i++){
	//	for(int j = 0;j <= MAX_N;j++){
	//		edge[i][j] = false;
	//	}
	//}
	int _u,_v;
	for(int i = 0;i < E;i++){
		scanf("%d%d",&_u,&_v);
		in[_v].push_back(_u);
		out[_u].push_back(_v);
	}

	solve();

	while(!L.empty()){
		int team = L.front();L.pop();
		printf("%d\n",team);
	}
	if(multi_flag) puts("1");
	else puts("0");

	return 0;
}

Measured memory_bytes: 2732
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<queue> 
#include<algorithm>
using namespace std;
#define maxn 100005
#define ll long long
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,m;
int a[maxn];
int main(){
	n=read();
	for(int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	int A=0,B=0,C=0;
	C=1;
	int ans=0;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1]) C++;
		else if(a[i]-a[i-1]>1){
			if(A+B+C>ans) ans=A+B+C;
			A=B=0;C=1;
		}else  if(a[i]!=a[i-1]){
			if(A+B+C>ans) ans=A+B+C;	
			swap(A,B);swap(B,C);C=1;
		}
	}
	if(A+B+C>ans) ans=A+B+C;
	printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main()
{
	int f;
	double a[10000];
	double sum=0;
	scanf("%d",&f);
	while(f!=0)
	{
		double sum=0;
		for(int i=1;i<=f;i++)
		{
			scanf("%lf",&a[i]);
			sum+=a[i];
		}
		double m=0;
		m=sum/f;
		sum=0;
		for(int i=1;i<=f;i++)
		{
			sum+=(a[i]-m)*(a[i]-m);
		}
		double g;
		g=sum/f;
		g=sqrt(g);
		printf("%.20lf\n",g);
		scanf("%d",&f);
	}
	return 0;
} 


Measured memory_bytes: 2776
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>
#include <set>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <deque>
using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define f first
#define s second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

const int inf = (int)1e9;
const int mod = inf+7;
	
int n, a[110], b[10];

int main(){

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

	for(int i=0;i<n;i++){
		if(a[i]>=1 && a[i]<=399){
			b[1] = 1;
		}else if(a[i]>=400 && a[i]<=799){
			b[2] = 1;
		}else if(a[i]>=800 && a[i]<=1199){
			b[3] = 1;
		}else if(a[i]>=1200 && a[i]<=1599){
			b[4] = 1;
		}else if(a[i]>=1600 && a[i]<=1999){
			b[5] = 1;
		}else if(a[i]>=2000 && a[i]<=2399){
			b[6] = 1;
		}else if(a[i]>=2400 && a[i]<=2799){
			b[7] = 1;
		}else if(a[i]>=2800 && a[i]<=3199){
			b[8] = 1;
		}
	}

	int minN = 0;
	int maxX = 0;
	for(int i=1;i<=8;i++){
		if(b[i]==1){
			minN++;
		}
	}

	for(int i=0;i<n;i++){
		if(a[i]>=3200){
			maxX++;
		}
	}

	if(minN == 0){
		cout << "1 " << maxX;
	}else{
		cout << minN << " " << minN + maxX;
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    n,x,m = map(int,input().split())
    if n == 1:
        print(x)
        return
    
    start = x
    arr = [x]
    visited = set()
    visited.add(x)
    prev = x
    curr = pow(prev,2,m)
    while curr not in visited:
        visited.add(curr)
        arr.append(curr)
        prev = curr
        curr = pow(prev,2,m)

    total = 0
    index = 0
    while n > 0 and index < len(arr):
        total += arr[index]
        n -= 1
        index += 1

    while arr[0] != curr:
        arr.pop(0)

    total += sum(arr)*(n//len(arr))
    for i in range(n%len(arr)):
        total += arr[i]

    print(total)

main()


Measured memory_bytes: 75400
#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <string>
#include <stack>
#include <set>
#include <deque>
#define mp make_pair
typedef long long ll;
using namespace std;
int a,b,k;
string str[105];
int main(){
	cin>>a>>b;
	b--;
	a--;
	for (int i=0;i<99;i++){
		str[0]+='#';
	}
	k=2;
	while (a>0){
		for (int i=0;i<33;i++){
			str[k]+="###";
			if (a>0){
				a--;
				str[k-1]+="#.#";
			}else{
				str[k-1]+="###";
			}
		}
		k+=2;
	}
	k--;
	for (int i=0;i<99;i++){
		str[k]+='.';
	}
	k+=2;
	while (b>0){
		for (int i=0;i<33;i++){
			str[k]+="...";
			if (b>0){
				b--;
				str[k-1]+=".#.";
			}else{
				str[k-1]+="...";
			}
		}
		k+=2;
	}
	cout<<k-1<<' '<<99<<endl;
	for (int i=0;i<k-1;i++){
		cout<<str[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <utility>
#include<bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define ld long double
// #define loop(i,a,b) for(ll i=a;i<b;i++)
// #define inll(n) ll n;cin>>n;
// #define instr(s)  string s;cin>>s;
// #define inarr(a,n)  ll*a = new ll[n];loop(i,0,n)cin>>a[i]; 
// #define invec(v,n)  vector<ll> v(n);loop(i,0,n)inll(v[i])
// #define arr(a,n) ll*a = new ll[n];
// #define outarr(a,n) loop(i,0,n)cout<<a[i]<<" ";cout<<endl;
#define pb push_back
#define mp make_pair
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector <int>
#define vb vector <bool>
#define vll vector <ll>
#define vc vector <char>
#define clr(a) memset(a,0,sizeof(a))
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define infd 1e+18
#define inf 101901199101
#define mod 1000000007
using namespace std;
inline ll min(ll a,ll b)
{
    return (a<b?a:b);
}
inline ll max(ll a,ll b)
{
    return (a<b?b:a);
}


void swap(ll*a,ll*b)
{
    ll t  = *a;
    *a =*b;
    *b = t;
}
void revere(string &s)
{
    for(ll i = s.length()-1;i>=ceil(s.length()/2);i--)
     swap(s[i],s[s.length()-1-i]);
}
bool isValidParenthesis(string s)
{
    int c = 0;
    for(char i:s)c = (i=='('?c+1:c-1);
    if(c!=0)return 0;
    return 1;
}


string substr(string s,int i,int j)
{
    if(i>j)return "";
    string n;
    for(int k = i;k<j;k++)
    {
        n+=s[k];
    }
    return n;
}

int ans(string s, int i,int j)
{
    if(i==j||j>s.length()||i>j||s.length()==0||s.length()==1)return 0;
    if(substr(s,i,j)=="()")return 1;
    if(isValidParenthesis(substr(s,i+1,j-1))) return 2*ans(s,i+1,j-1);
    int ind = i;
    for(int k = i+1;k<j;k++)
    {
        if(isValidParenthesis(substr(s,i,k+1)))
        {
            ind = k+1;
            break;
        }
    }
    return ans(s,i,ind) + ans(s,ind,s.length());
}

int main()
{
    ll n;cin>>n;
    ll a[n] = {0};
    for(ll i = 0;i<n;i++)cin>>a[i];
    ll dp[n] = {0};
    dp[1] =  abs(a[1] - a[0]);
    for(ll i =2;i<n;i++)
    {
        dp[i] = min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1792
import itertools
n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

path=[[] for _ in range(n)]
for a,b in AB:
  a,b=a-1,b-1
  path[a].append(b)
  path[b].append(a)
ans=0
for ptn in itertools.permutations(range(1,n)):
  s=0
  for nex in ptn:
    if s not in path[nex]: break
    s=nex
  else:
    ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
      	//入力
        int N = sc.nextInt();
        String S = sc.next();
      	//種類数の最大値入れ物
        int max = 0;
        //区切り位置ごと
        for (int i=1;i<N;i++){
          	//S.substring…文字列Sの0～i番目まで切り出す
            String str1 = S.substring(0,i);
            String str2 = S.substring(i);
            int count = 0;
          	//a~z文字
            boolean[] ar1 = new boolean[26];
            boolean[] ar2 = new boolean[26];
          	//左列
            for (int j=0;j<str1.length();j++){
              	//charAt(j)…j番目の文字を抜き出す
              	//-'a'…「a」はJavaの整数97
                ar1[str1.charAt(j)-'a']=true;
            }
          	//右列
            for (int j=0;j<str2.length();j++){
                ar2[str2.charAt(j)-'a']=true;
            }
          	//両方に同じ文字あるか
            for (int j=0;j<26;j++){
                if (ar1[j]&&ar2[j]){
                  count++;
                }
            }
            max = Math.max(max,count);
        }
        System.out.println(max);
    }
}

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

int main() {
    string S;
    cin >> S;

    int cntW = 0;
    long long ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] == 'W') {
            ++cntW;
            ans += i - (cntW - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>

using namespace std;

using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;

int main()
{
	i64 n, k;
	scanf("%lld %lld", &n, &k);

	vector<ii64> item(n);

	for (int i = 0; i < n; i++)
	{
		scanf("%lld %lld", &item[i].first, &item[i].second);
	}

	i64 res = 0;

	for (auto& i : item)
	{
		if ((i.first & k) != i.first)
			continue;

		res += i.second;
	}

	for (int zero = 0; zero <= 31; zero++)
	{
		i64 sum = 0;

		i64 back = 1 << zero;
		i64 kmask = k & (~((back << 1) - 1));

		if (back > k)
			break;

		if ((k & back) == 0)
			continue;

		for (auto& i : item)
		{
			if (i.first > k)
				continue;

			if ((i.first & back) != 0)
				continue;

			i64 mask = i.first & (~((back << 1) - 1));

			if ((kmask & mask) != mask)
				continue;

			sum += i.second;
		}

		res = max(res, sum);
	}

	printf("%lld", res);

	return 0;
}

Measured memory_bytes: 1792
/* ex4_3
   kohei0713 */

#include <stdio.h>

int calculateSnowfall(int westHeight, int eastHeight);

int main(void){
    
    int westHeight, eastHeight;
    
    //input
    scanf("%d %d", &westHeight, &eastHeight);

    //関数calculateSnowfallの値をanswerに
    int answer = calculateSnowfall(westHeight, eastHeight);

    //answerを表示
    printf("%d\n", answer);

    return 0;
}

int calculateSnowfall(int westHeight, int eastHeight){
    //西と東の塔の高さの差を計算
    int height = eastHeight - westHeight;
    int westTowerHeight;

    //西の塔の高さを計算
    for(int i = 1; i < height; i++){
        westTowerHeight = westTowerHeight + i;
    }

    //雪の高さを計算
    int snowfall = westTowerHeight - westHeight;

    //雪の高さを返す
    return snowfall;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
#define mod 998244353
int main()
{
    string s;
    string t;
    cin>>s>>t;
    bool j=true;
    for(int x=0;x<s.length();x++)
    {
        if(s[x]!=t[x])
            j=false;
    }
    if(j)
        cout<<"Yes";
    else
        cout<<"No";
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"
using namespace std;

////////////// Prewritten code follows. Look down for solution. ////////////////
#define x first
#define y second
#define len(x) ((int)(x).size())
using pii = pair<int, int>;
using ll = long long;
using llu = long long unsigned;
using ld = long double;

const ld EPS = 1e-9;
inline int cmp(ld x, ld y = 0, ld tol = EPS) {
	return (x <= y + tol) ? (x + tol < y) ? -1 : 0 : 1;
}

const int MOD = 1;
inline int mod (ll x, int m = MOD) {
	return (int)(((x%m) + m)%m);
}

////////////////////////// Solution starts below. //////////////////////////////

const int N = 3010;

double dp[N][N];
int n;
double pos[N];
bool vis[N][N];

double solve (int p, int h) {
	if (p > n)
		return h > n/2;
	
	double &r = dp[p][h];
	if (vis[p][h]) return r;
	vis[p][h] = true;
	return r = pos[p]*solve (p+1, h+1) +  (1-pos[p])*solve (p+1, h);
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf ("%lf", &pos[i]);
	printf ("%0.16lf\n", solve (0, 0));

	return 0;
}


Measured memory_bytes: 79872