akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

//Spiral Footrace
public class Main{

	class P{
		int x, y;
		public P(int x, int y) {
			this.x = x;
			this.y = y;
		}
	}
	
	
	void run(){
		double EPS = 1e-6;
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			P[] p = new P[n];
			for(int i=0;i<n;i++)p[i]=new P(sc.nextInt(), sc.nextInt());
			boolean[] u = new boolean[n];
			P t = new P(0, 0);
			P h = new P(0, 1);
			P pre = new P(0, 0);
			double res = 0;
			for(int i=0;i<n;i++){
				int id = -1;
				double min = 360;
				double d = 1<<29;
				for(int j=0;j<n;j++){
					if(u[j])continue;
					double dist = Math.hypot(p[j].x-pre.x, p[j].y-pre.y);
					double x1 = p[j].x-pre.x;
					double y1 = p[j].y-pre.y;
					double x2 = h.x-t.x;
					double y2 = h.y-t.y;
//					double thita = Math.acos((x1*x2+y1*y2)/(Math.hypot(x1, y1)*Math.hypot(x2, y2)));
					double thita = Math.atan2(x1*y2-x2*y1, x1*x2+y1*y2);
//					System.out.println("ID:" + j + " THIA:" + thita);
					if(thita+EPS<min){
						id = j;
						min = thita;
						d = dist;
					}
					else if(Math.abs(thita-min)<EPS&&dist<d){
						id = j;
						d = dist;
					}
				}
//				System.out.println("P: (" +p[id].x+","+p[id].y+")" + " D:" + d);
				u[id] = true;
				res += d;
				pre = p[id];
				if(i==0){
					h = p[id];
				}
				else{
					t = h;
					h = p[id];
				}
			}
			System.out.printf("%.1f\n", res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>

using namespace std;

int main(void) {
  int n, *v, sub;
  int tmp;
  
  sub = 0;
  cin >> n;
  v = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    if (v[i] - tmp > 0) sub += (v[i] - tmp);
  }
  
  cout << sub << endl;
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  if(a>=13)
    cout << b << endl;
  else if(a >= 6 && a <= 12)
    cout << b/2 << endl;
  else
    cout << 0 << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int i = 0;
  char s1, s2, s3;
  int sum = 0;

  cin >> s1 >> s2 >> s3;

  vector<char> vec = {s1, s2, s3};

  for(int i = 0; i < 3; i++){
    if(vec.at(i) == '1'){
      sum++;
    }
  }

  cout << sum << endl;

}

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

using namespace std;

const int N=1e5+10,MOD=1e9+7;

int n,m,x[N],y[N],f[N];

struct Point{
    int x,y;
    Point(int x=0,int y=0):x(x),y(y){}
}p[N];
bool operator==(const Point&a,const Point&b){return a.x==b.x&&a.y==b.y;}
bool cmp(const Point&a,const Point&b){return a.x<b.x||(a.x==b.x&&a.y>b.y);}
struct Discretization{
    static bool cmp(int*a,int*b){return *a<*b;}
    int tot,*val[N],mv;
    void add(int&x){val[++tot]=&x;}
    void work(){
        sort(val+1,val+1+tot,cmp);
        for(int i=1,last=0;i<=tot;++i){
            if(*val[i]>last)++mv;
            last=*val[i];
            *val[i]=mv;
        }
    }
}Dl,Dr;
struct BIT{
    int arr[N];
    int lowbit(int x){return x&-x;}
    void add(int x,int t){
        for(;x<=Dr.mv;x+=lowbit(x))arr[x]=(arr[x]+t)%MOD;
    }
    int get(int x){
        int ret=0;
        for(;x;x-=lowbit(x))ret=(ret+arr[x])%MOD;
        return ret;
    }
}a;

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;++i)scanf("%d",&x[i]);
    for(int i=1;i<=m;++i)scanf("%d",&y[i]);
    int tot=0;
    for(int i=1;i<=n;++i){
        int t=lower_bound(y+1,y+1+m,x[i])-y;
        if(t==m+1||t==1)continue;
        p[++tot]=Point(x[i]-y[t-1],y[t]-x[i]);
        Dl.add(p[tot].x);
        Dr.add(p[tot].y);
    }
    n=tot;
    Dl.work();
    Dr.work();
    sort(p+1,p+1+n,cmp);
    n=unique(p+1,p+1+n)-p-1;
    int ans=1;
    for(int i=1;i<=n;++i){
        f[i]=(1+a.get(p[i].y-1))%MOD;
        ans=(ans+f[i])%MOD;
        a.add(p[i].y,f[i]);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>
 
int main(){
    int n,k,i;
    char s[11];
    scanf("%d",&n);
    scanf("%s",&s);
    scanf("%d",&k);
	for(i=0;i<n;i++){
		if(s[k-1]==s[i]) printf("%c",s[i]);
		else printf("*");
	}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define MAX (2000000)

char prime[MAX + 1];

int main(void)
{
	int i, j;
	int a, d, n;
	
	prime[0] = prime[1] = 0;
	for (i = 2; i <= MAX; i++){
		prime[i] = 1;
	}
	
	for (i = 2; i * i <= MAX; i++){
		for (j = i * i; j <= MAX; j += i){
			prime[j] = 0;
		}
	}
	
	while (1){
		scanf("%d %d %d", &a, &d, &n);
		
		if (!a && !d && !n){
			break;
		}
		
		i = 0;
		while (1){
			if (prime[a]){
				i++;
			}
			
			if (i == n){
				break;
			}
			
			a += d;
		}
		
		printf("%d\n", a);
	}
	
	return (0);
}

Measured memory_bytes: 2552
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

class BIT:
  def __init__(self, n):
    self._size = n
    self._body = [0] * (n+1)
  def __repr__(self):
    return ("BIT([" + ", ".join(str(x) for x in self._body) + "])")
  def size(self):
    return self._size
  def add(self, i, v):
    assert 0 <= i < self.size()
    i += 1
    while(i <= self.size()):
      self._body[i] += v
      i += i & -i
  def sum(self, *args):
    assert 1 <= len(args) <= 2
    if len(args) == 1: # [0, i)の和をとる
      i = args[0]
      assert 0 <= i <= self.size()
      s = 0
      while(i > 0):
        s += self._body[i]
        i -= i & -i
      return s
    else: # [i, j)の和をとる
      (i, j) = args
      return self.sum(j) - self.sum(i)

N, K = reads()
A = []
for _ in range(N):
  a = read()
  A.append(a-K)

psum = [0] + list(accumulate(A))

inv = sorted(set(psum))
L = len(inv)
invd = {inv[i]: i for i in range(L)}
bt = BIT(L)

ans = 0
for s in psum:
  c = invd[s]
  ans += bt.sum(c+1)
  bt.add(c, 1)
print(ans)


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

#define ll long long
#define mod 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;

int main() {
	ll n, k;
	cin>>n>>k;
	map<ll, ll> mp;
	for(int i=0;i<n;i++) {
		string s;
		cin>>s;
		mp[s[0]-'A'] ++;
	}
	map<ll, ll>::iterator it;
	vector<ll> v;
	for(it = mp.begin(); it != mp.end(); it ++) {
		v.push_back(it->second);
	}
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	ll ans = 0;
	while(1) {
		ll kk = k;
		sort(v.begin(), v.end());
		reverse(v.begin(), v.end());
		for(int i=0;i<v.size();i++) {
			if(v[i] != 0) {
				v[i] --;
				kk --;
			}
			if(kk == 0) {
				// cout<<i<<" "<<v[i]<<" here\n";
				break;
			}
		}
		if(kk != 0)	break;
		ans ++;
	}
	cout<<ans<<"\n";
	return 0;
}

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

using namespace std;

double distance(int a, int b, int c, int d){
    double dx = c - a;
    double dy = d - b;
    double dis = pow(dx*dx+dy*dy, 0.5);
    return dis;
}

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

    vector<int> x(n+1), y(n+1), v(n);
    x[0] = 0, y[0] = 0;

    for(int i = 0; i < n; i++){
        cin >> x[i+1] >> y[i+1];
        v[i] = i+1;
    }

    double sum_of_distance = 0.0;

    do{
        for(int i = 0; i < n-1; i++){
            double length_of_path = distance(x[v[i]], y[v[i]], x[v[i+1]], y[v[i+1]]);
            sum_of_distance += length_of_path;
        }
    }while(next_permutation(v.begin(), v.end()));

    double factorial = 1;
    for(int i = 2; i <= n; i++) factorial *= i;

    double ans = sum_of_distance / (double)factorial;

    printf("%lf\n", ans);

}



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

typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<ll> v(n*3);
    for(int i=0; i<n*3; i++){
        cin >> v.at(i);
    }
    sort(v.rbegin(), v.rend());
    ll ans = 0;
    for(int i=0; i<n; i++){
        ans += v.at(i*2+1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int MAXN=110,MAXK=100010;
const long long M=1e9+7;
int n,k,a[MAXN];
long long s[MAXK],dp[MAXN][MAXK];

int main(){
	cin>>n>>k,dp[0][0]=1;
	for(int i=1;i<=n;cin>>a[i],dp[i][0]=1,++i);
	for(int i=1;i<=n;++i){
		for(int j=1;j<=k+1;++j) (s[j]=s[j-1]+dp[i-1][j-1])%=M;
		for(int j=1;j<=k;++j) (dp[i][j]=s[j+1]-s[max(0,j-a[i])]+M)%=M;
	}
	cout<<dp[n][k]<<endl;
	return 0;
}

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

int main(){
  
  int N;
  cin >> N;
  
  vector<int> A(N),B(N),C(N);
  for(int i=0;i<N;i++){
    int a,b,c;
    cin >>a>>b>>c;
    A[i]=a;
    B[i]=b;
    C[i]=c;
  }
  
  vector<vector<int>> dp(3,vector<int>(N,0));
  
  dp[0][0] = A[0];
  dp[1][0] = B[0];
  dp[2][0] = C[0];
  
  for(int i=1;i<N;i++){
    int way1,way2;
    way1 = dp[1][i-1]+A[i];
    way2 = dp[2][i-1]+A[i];
    dp[0][i] = max(way1,way2);
    way1 = dp[0][i-1]+B[i];
    way2 = dp[2][i-1]+B[i];
    dp[1][i] = max(way1,way2);
    way1 = dp[0][i-1]+C[i];
    way2 = dp[1][i-1]+C[i];
    dp[2][i] = max(way1,way2);
    //for(int j=0;j<3;j++){
    //  for(int k=0;k<N;k++){
    //    cout << dp[j][k] << " ";
    //  }
    //  cout << endl;
    //}
    //cout << endl;
  }
  
  cout << max(dp[0][N-1],max(dp[1][N-1],dp[2][N-1])) <<  endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A;
  int B;
  int N;
  int count = 0;
  cin >> N >> A >> B;
  for (int i = 1; i <= N; i++) {
    int C = i / 10000 + (i % 10000) / 1000 + (i % 1000) / 100 + (i % 100) / 10 + i % 10;
    if (A <= C && C <= B) {
      count += i;
    }
  }
  cout << count << endl;  
}


Measured memory_bytes: 3624
# -*- coding: utf-8 -*-

N = int(input())

ans = N
for i in range(N+1):
    n = i
    m = N - i
    res = 0

    nine = 1
    while nine*9 <= n:
        nine *= 9
    while nine != 1:
        res += n // nine
        n %= nine
        nine /= 9
    res += n

    six = 1
    while six*6 <= m:
        six *= 6
    while six != 1:
        res += m // six
        m %= six
        six /= 6
    res += m

    ans = min(ans, int(res))

print(ans)


Measured memory_bytes: 9268
'use strict'

const INF = 900719925474099;


function Main(input){
    let temp = input.trim().split('\n');
    let temp2 = temp[0].split(' ').map((v)=>parseInt(v));
    let n = temp2.shift();
    let m = temp2.shift();

    let maxl = 0;
    let minr = INF;
    for(let i=1;i<=m;i++){
        temp2 = temp[i].split(' ').map((v)=>parseInt(v));
        maxl = Math.max(maxl,temp2[0]);
        minr = Math.min(minr,temp2[1]);
    }
    console.log(Math.max(minr - maxl + 1,0));
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

long int M = 1e+9+7;
int main(void){
    int n,m;
    cin >> n >> m;
    vi x(m), y(m);
    vvi go(n+1,vi(0));
    vvi come(n+1,vi(0));
    //縦・横の順

    rep(i,m){
        cin >> x[i] >> y[i];
        //come[i][j]はjからiにいける行く
        //go[i][j]はiからjに行ける
        go[x[i]].push_back(y[i]);
        come[y[i]].push_back(x[i]);
    }

    vector<int> mae,ato;
    vector<int> from(n+1);
    rep(i,n+1) from[i]=come[i].size();
    vi dp(n+1,-1);
    rrep(i,n){
        if(!come[i].size()){
            mae.push_back(0);
            ato.push_back(i);
        }
    }
    rep(i,mae.size()){
        int golen=go[ato[i]].size();
        rep(j,golen){
            if(--from[go[ato[i]][j]] == 0){
                mae.push_back(ato[i]);
                ato.push_back(go[ato[i]][j]);
            }
        }
        chmax(dp[ato[i]],dp[mae[i]]+1);
    }
    int ans=0;
    rep(i,n+1){
        chmax(ans,dp[i]);
    }
    cout << ans << endl;
    /*
    set<int> tmp,tmp2;
    int cnt=0;
    rrep(i,n){
        if(!come[i].size()) tmp.insert(i);
    }
    while(tmp.size()){
        for(auto x : tmp){
            int golen = go[x].size();
            rep(i,golen){
                tmp2.insert(go[x][i]);
            }
        }
        tmp=tmp2;
        tmp2.clear();
        cnt++;
    }
    cout << --cnt << endl;
    */

    return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  int h,w,k; cin >> h >> w >> k;
  int sr,sc,gr,gc; cin >> sr >> sc >> gr >> gc;
  sr--;sc--;gr--;gc--;
  static string s[1000000];
  for(int i = 0; i < h; ++i)cin >> s[i];
  vector<vector<int>> dis(h,vector<int>(w,-1));
  int mr[] = {-1, 0, 1, 0};
  int mc[] = {0, 1, 0, -1};
  queue<P<int,int>> que;
  que.emplace(sr,sc);
  dis[sr][sc] = 0;
  while(!que.empty()){
    auto now = que.front();
    que.pop();
    for(int i = 0; i < 4; ++i){
      for(int j = 1; j <= k; ++j){
	int nr = now.first + mr[i]*j;
	int nc = now.second + mc[i]*j;
	if(nr >= h || nr < 0 || nc >= w || nc < 0 || s[nr][nc] == '@')break;
	if(dis[nr][nc] != -1 && dis[nr][nc] <= dis[now.first][now.second])break;
	if(dis[nr][nc] == dis[now.first][now.second]+1)continue;
	dis[nr][nc] = dis[now.first][now.second] + 1;
	que.emplace(nr,nc);
      }
    }
  }
  cout << dis[gr][gc] << endl; 
  return 0;
}


Measured memory_bytes: 43348
w, a, b = map(int, input().split())

if a <= b and b <= a + w:
    print(0)
elif a <= b + w and b + w <= a + w:
    print(0)
elif b+w < a:
    print(a - (b+w))
elif a+w < b:
    print(b - (a+w))


Measured memory_bytes: 3316
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int devider = 1000000007;
        if (Math.abs(n - m) > 1) {
            System.out.println(0);
            return;
        }
        long count = 1;
        if (n == m) {
            while(n != 1) {
                count *= n;
                count %= devider;
                count *= m;
                count %= devider;
                n--;
                m--;
            }
            count *= 2;
            count %= devider;
        } else {
            int large = Math.max(n, m);
            int small = Math.min(n, m);
            while(large != 1) {
                count *= large;
                count %= devider;
                count *= small;
                count %= devider;
                large--;
                small--;
            }
        }
        System.out.println(count);
    }
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<int, int> P;


ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

ll N;
ll dp[100010];

ll dpf(int val){
  if(dp[val]>0){
    return dp[val];
  }else{
    if(val<6){
      dp[val]=val;
      return dp[val];
    }else{
      dp[val] = 1e10;
      int i=1;
      while(pow(6, i)<=val){
        dp[val] = min(dp[val], dpf(val-pow(6,i))+1);
        i++;
      }
      i=1;
      while(pow(9, i)<=val){
        dp[val] = min(dp[val], dpf(val-pow(9,i))+1);
        i++;
      }

      return dp[val];
    }
  }
}


/******************************************
** A main function is start from here  ****
*******************************************/
int main(){
  cin >> N;
  cout << dpf(N);
  
  return 0;
}


Measured memory_bytes: 1792
import itertools
r = 110000
s = int(r*0.5)
p = [1] * r
p[0] = 0
for i in range(1,s):
	if p[i]:
		p[2*i+1::i+1] = [0 for x in range(2*i+1,r,i+1)]
		
while 1:
	N,P = map(int,raw_input().split())
	if N == -1: break
	i = N + 1
	prime = [0]*24
	j = 0
	while j < 24:
		if p[i-1] == 1:
			prime[j] = i
			j += 1
		i += 1
	wa = sorted([sum(comb) for comb in itertools.combinations(prime,2)] + [2*a for a in prime])
	print wa[P-1]

Measured memory_bytes: 9024
#include"bits/stdc++.h"
//#include"atcoder.h"
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const ll inf = ll(1e18) + 1;
const ll mod = pow(10,9)+7;

ll powmod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) {
		res = res * x % mod;
	}
	return res;
}

int main() {
	ll n;
	cin >> n;

	ll result = powmod(10,n);
	result -= powmod(9,n);
	result -= powmod(9, n);
	result += powmod(8, n);

	result %= mod;
	result = (result + mod) % mod;

	cout << result << endl;

	return 0;
}


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

int	main()
{
	double a, b, x;
	cin >> a >> b >> x;
	x /= a;
	double result;
	if (x < 0.5 * a * b) {
		double c = 2 * x / b;
		result = atan(b / c);
	} else {
		double c = 2 * (b - x / a);
		result = atan(c / a);
	}
	result = result / M_PI * 180;
	cout << setprecision(10) << result << endl;
}


Measured memory_bytes: 384
A, B, K = map(int, input().split())

L = []
s = [i for i in range(A, min(A+K, B+1))]
l = [j for j in range(B, max(A-1, B-K), -1)]
L += s + l
L = list(set(L))
L.sort()

for i in L:
    print(i)

Measured memory_bytes: 9196
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		int[] a = new int[3];
		for(int i = 0; i < 3; i++) {
			a[i] = sc.nextInt();		
		}
		
		Arrays.sort(a);
		
		if(a[0] == 5 && a[1] == 5 && a[2] == 7)	System.out.println("YES");
		else									System.out.println("NO");
	}
}

Measured memory_bytes: 8788
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll N;
pair < deque < int >, deque < int > > solve(ll N, int who) {
    if (N == 1) {
        deque < int >f1;
        f1.push_back(who);
        return make_pair(f1, f1);
    }
    else {
        if (N % 2 == 0) {
            auto p = solve(N - 1, who + 1);
            p.first.push_back(who);
            p.second.push_front(who);
            return p;
        }
        else {
            auto p = solve((N - 1) / 2, who + 1);
            p.first.push_back(who);
            p.second.push_back(who);
            return p;
        }
    }

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> N;
    auto t = solve(N, 1);
    cout << 2 * t.first.size() << endl;
    for (int v : t.first) cout << v << " ";
    for (int v : t.second) cout << v << " ";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n;
	int x;
	int box[101];
	int cnt;
	int i;
	cin>>n;
	for(i=0;i<101;i++)	box[i]=0;
	for(i=0;i<n;i++){
		cin>>x;
		box[x]++;
	}
	cnt=0;
	for(i=0;i<101;i++)	if(box[i]>0)	cnt++;
	cout<<cnt<<endl;
	return 0;
}
		

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b) {
        cout << (b == c ? 1 : 2) << endl;
    } else {
        cout << (a != c && b != c ? 3 : 2) << endl;
    }

    return 0;
}

Measured memory_bytes: 256
def dist(a,b):
    ans = 0
    for i in range(D):
        ans += (b[i] - a[i])**2
    ans **= 0.5

    return ans

N,D = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

count = 0
for i in range(N-1):
    for j in range(i+1, N):
        if dist(X[i],X[j]).is_integer():
            count += 1

print(count)

Measured memory_bytes: 9436
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N), B(N), margin(N);
	bool flag_finish = true;

	REP(i, N) {
		cin >> A[i] >> B[i];
		margin[i] = B[i] - A[i];
		if (margin[i] < 0) {
			flag_finish = false;
		}
	}

	vector<pair<int, pair<int, int>>> job(N);

	REP(i, N) {
		job[i].first = B[i];
		job[i].second.first = A[i];
		job[i].second.second = B[i];
	}

	sort(job.begin(), job.end());

	int now_time = 0;
	REP(i, N) {
		now_time += job[i].second.first;
		if (now_time > job[i].second.second) {
			flag_finish = false;
		}
	}

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

	return 0;
}


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

using namespace std;

struct Data{
  string name;
  int num;
  bool operator < ( const Data &data) const {
    if( name==data.name ){
      if(num < data.num)return true;
      else return false;
    }else{
      if(name < data.name)return true;
      else return false;
    }
  }
};

int main(){
  
  Data a[100000];
  int n=0;
  string str;
  int id;
  while( cin>>str>>id ){
    a[n]= (Data){ str, id };
    n++;
  }
  sort(a,a+n);

  string key="";
  
  for(int i=0;i<n;i++){
    if(key!=a[i].name){
      key=a[i].name;
      if(i>0){
        cout<<endl;
      }
      cout<<key<<endl;
      cout<<a[i].num;
    }else{
      cout<<' '<<a[i].num;
    }
  }

  cout<<endl;
  
  return 0;
}

Measured memory_bytes: 4608
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
 
alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");
 
T lread(T = long)()
{
    return readln.chomp.to!T();
}
 
T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}
 
void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    long a,b;
    scan(a,b);
    if(a > 8 || b > 8)
    {
        writeln(":(");
    }
    else
    {
        writeln("Yay!");
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n, a[50], b[50], c[50];
string str;

int main(){
	cin >> n;
	for(ll i = 1; i <= n; i++){cin >> a[i];}
	for(ll i = 1; i <= n; i++){cin >> b[i];}
	for(ll i = 1; i <= n-1; i++){cin >> c[i];}
	
	ll ans = 0;
	for(ll i = 1; i <= n-1; i++){
		ans += b[a[i]];
		if(a[i]+1 == a[i+1]){
			ans += c[a[i]];
		}
	}
	ans += b[a[n]];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		FS fs = new FS();
		while(true) {
			int n = fs.nextInt();
			if(n==0) break;
			if(n==1) {
				double x = fs.nextDouble();
				double y = fs.nextDouble();
				System.out.println(1);
				continue;
			}
			double[] px = new double[n];
			double[] py = new double[n];
			for(int i=0; i<n; i++) {
				px[i] = fs.nextDouble();
				py[i] = fs.nextDouble();
			}
			ArrayList<Double> csx = new ArrayList<Double>();
			ArrayList<Double> csy = new ArrayList<Double>();
			for(int i=0; i<n-1; i++) {
				for(int j=i+1; j<n; j++) {
					double vx = px[j]-px[i];
					double vy = py[j]-py[i];
					double l = Math.sqrt(Math.pow(vx,2.0)+Math.pow(vy,2.0));
					if(l > 2.0) continue;
					double r = Math.sqrt(1.0 - Math.pow(l/2.0, 2.0));
					vx = vx/l*r;
					vy = vy/l*r;
					double mx = (px[i]+px[j])/2.0;
					double my = (py[i]+py[j])/2.0;
					csx.add(mx-vy);
					csy.add(my+vx);
					csx.add(mx+vy);
					csy.add(my-vx);
				}
			}
			int maxCount = 1;
			for(int i=0; i<csx.size(); i++) {
				int count = 0;
				for(int j=0; j<n; j++) {
					if(Math.pow(csx.get(i)-px[j],2.0)+Math.pow(csy.get(i)-py[j],2.0) <= 1.0000000001) {
						count++;
					}
				}
				maxCount = Math.max(maxCount, count);
			}
			System.out.println(maxCount);
		}
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int 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 int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int 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: 57148
import sys

n = int(input())
a = list(map(int, input().split()))

a = sorted(a, reverse=True)

multi = 1

if 0 in a:
  print('0')
  sys.exit()

for i in a:
  multi *= i
  if multi > 10**18:
    print('-1')
    sys.exit()

print(multi)

Measured memory_bytes: 21596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

ll hpow(ll x,ll y){
    ll ans=1;
    ll i=x;
    if(y==0)return 1;
    while(y>0){
        if(y%2==1){
            ans=(ans*i)%i_7;
        }
        i=(i*i)%i_7;
        y=y/2;
        
    }
    return ans;
}

ll kake(ll x,ll y){
    ll a=1;
    rep(i,x,y){
        a=(a*i)%i_7;
    }
    return a;
}

ll comb(ll n,ll k){
    ll ans=(kake(n-k+1,n)*hpow(kake(1,k),i_7-2))%i_7;
    return ans;
}

int main(){
    ll n,a,b;cin>>n>>a>>b;
    cout<<((hpow(2,n)-comb(n,a)-comb(n,b)-1)%i_7+i_7)%i_7<<endl;
    
    return 0;
}



Measured memory_bytes: 256
# include<bits/stdc++.h>
#define ll long long
using namespace std ;
int main( ){
	int tjk = 1 ;
	// cin >> tjk ;
	while( tjk -- ){
        int n ;
        cin >> n ;
        if( n == 1 ){
            cout << 0 << endl ;
        }else{
            cout << 1 << endl ;
        }
	}
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 112345;
int x[MAX_N];

int nxt[18][MAX_N]; // [i][j] := 2^i 日で j からいける最も右の位置

bool possible(int mid, int a, int b) {
  int p = a;
  while (mid > 0) {
    int d = 0;
    for (; (1 << (d+1)) <= mid; d++);
    p = nxt[d][p];
    mid -= (1<<d);
  }
  return p >= b;
}

int main2() {
  int N = nextInt();
  REP(i, N) x[i] = nextInt();
  int L = nextInt();

  REP(i, N) {
    int idx = (int)(upper_bound(x+i+1, x+N, x[i]+L) - x) - 1;
    nxt[0][i] = idx;
  }
  // pv(nxt[0], nxt[0] + N);
  for (int d = 1; d < 18; d++) {
    REP(i, N) nxt[d][i] = nxt[d-1][nxt[d-1][i]];
  }
  int Q = nextInt();
  REP(qqq, Q) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    if (a > b) swap(a, b);
    int hi = 200000;
    int lo = 0;
    while (hi - lo > 1) {
      int mid = (hi + lo) / 2;
      if (possible(mid, a, b)) hi = mid; else lo = mid;
    }
    printf("%d\n", hi);
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 8960
#include <iostream>
#include <algorithm>
#define INF 100000000000000
#define ll long long
using namespace std;

int main(){

  ll H, W;
  cin >> H >> W;
  ll a, b, c, res = INF;
  for(ll i = 1; i < H; i++){
    a = i * W;
    b = (H - i) * (W / 2);
    c = (H - i) * W - b;
    res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
    b = (H - i) / 2 * W;
    c = (H - i) * W - b;
    res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
  }
  for(ll i = 1; i < W; i++){
    a = i * H;
    b = (W - i) * (H / 2);
    c = (W - i) * H - b;
    res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
    b = (W - i) / 2 * H;
    c = (W - i) * H - b;
    res = min(res, max(a, max(b, c)) - min(a, min(b, c)));
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

#define lld long long int 
#define vll vector<long long int>
#define vs vector<string> 
#define vint vector<int> 
#define vp vector<pair<int,int>>
#define vpll vector<pair<long long int , long long int>>
//#define tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
#define forl(i,a,b) for(int i = a ; i <= b ; i++)
#define forln(i,a,b) for(int i = a; i < b ; i++)
lld mod = 1e9 + 7;
#define ps push_back
#define B begin
#define E end
#define mk make_pair
#define F first 
#define S second 
#define FAST ios_base::sync_with_stdio(false),cin.tie(NULL)
#define sv()                  int t; scanf("%d",&t); while(t--)



lld power(lld x, lld y) 
{ lld temp; if( y == 0) return 1; temp = power((x%mod), (y%mod)/2); if (y%2 == 0) return ((temp%mod)*(temp%mod))%mod;else return (((x%mod)*(temp%mod))%mod*(temp%mod))%mod;} 

using namespace std;

void solution( void );

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

void solution()
{
	set<string>st;
	lld n;
	string s;
	cin>>n;
	forln(i,0,n){
		cin>>s;
		st.insert(s);
	}
	cout<<st.size();
}



Measured memory_bytes: 19268
#include<iostream>
typedef long long ll;
using namespace std;
ll a[1000005]; 
int main()
{
	ll n;
	cin>>n;
	ll sum=0;
	for(ll i=1;i<=n;i++)
	{
		if(i%3==0||i%5==0)
		    a[i]=0;
		else
		    a[i]=i;
		sum+=a[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 11376
class Factorial():
    def __init__(self, n, mod):
        self.mod = mod
        self.fct = [0 for _ in range(n + 1)]
        self.inv = [0 for _ in range(n + 1)]
        self.fct[0] = 1
        self.inv[0] = 1
        for i in range(n):
            self.fct[i + 1] = self.fct[i] * (i + 1) % mod
        self.inv[n] = pow(self.fct[n], mod - 2, mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i + 1] * (i + 1) % mod

    def fact(self, m):
        return self.fct[m]

    def invf(self, m):
        return self.inv[m]

    def perm(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[m - k] % self.mod

    def comb(self, m, k):
        if m < k: return 0
        return self.fct[m] * self.inv[k] * self.inv[m - k] % self.mod

    def hcmb(self, m, k):
        if m + k == 0: return 1
        return self.comb(m + k - 1, k)

N, M, K = map(int, input().split())
MOD = 998244353

F = Factorial(max(N, M) + 1, MOD)

res = pow(M, N, MOD)

for i in range(N - 1 - K):
    res -= F.comb(N - 1, i) * M * pow(M - 1, i, MOD)
    res %= MOD

print(res)

Measured memory_bytes: 94168
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <random>
#include <algorithm>
#include <functional>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int M,D;
  cin>>M>>D;
  int ans=0;
  FOR(i,1,M+1){
    FOR(j,1,D+1){
      int d1=j/10;
      int d2=j%10;
      if(d1>1 && d2>1 && d1*d2==i){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF						(int)2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	int len = S.size();
	vector<int> rCnt(len, 0);
	vector<int> lCnt(len, 0);
	vector<int> ans(len, 0);

	int cnt = 0;
	REP(i, len) {
		if (S[i] == 'R') {
			cnt++;
		} else {
			rCnt[i] = cnt;
			cnt = 0;
		}
	}

	cnt = 0;
	for (int i = len - 1; i >= 0; i--) {
		if (S[i] == 'L') {
			cnt++;
		} else {
			lCnt[i] = cnt;
			cnt = 0;
		}
	}

	REP(i, len) {
		int posCnt;
		if (rCnt[i]) {
			posCnt = rCnt[i] / 2;
			ans[i] += posCnt;
			ans[i - 1] += rCnt[i] - posCnt;
		}
		if (lCnt[i]) {
			posCnt = lCnt[i] / 2;
			ans[i] += posCnt;
			ans[i + 1] += lCnt[i] - posCnt;
		}
	}

	REP(i, len) {
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.*;

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

    int H,W,h,w,all_cell,a,b;

    H=sc.nextInt();
    W=sc.nextInt();

    h=sc.nextInt();
    w=sc.nextInt();

    all_cell=H*W;
    a=W*h;
    b=H*w-h*w;


    if(H==h||W==w){
      System.out.println(0);
    }else{
      System.out.println(all_cell-a-b);
    }


  }
}


Measured memory_bytes: 22732
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
//const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int N, Q;
string S;
char t[202020], d[202020];

bool left(int m){
    int cur = m;
    REP(i,Q){
        if(t[i] == S[cur]){
            if(d[i] == 'L') cur--;
            else cur++;
        }
        if(cur < 0) return true;
    }
    return false;
}

bool right(int m){
    int cur = m;
    REP(i,Q){
        if(t[i] == S[cur]){
            if(d[i] == 'L') cur--;
            else cur++;
        }
        if(cur >= N) return true;
    }
    return false;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Q >> S;
    REP(i,Q) cin >> t[i] >> d[i];

    int l = -1, r = N;
    while(r - l > 1){
        int m = (l + r) / 2;
        if(left(m)) l = m;
        else r = m;
    }
    int vanished = l + 1;
    //cout << l << " " << r << endl;
    //cout << vanished << endl;
    l = -1, r = N;
    while(r - l > 1){
        int m = (l + r) / 2;
        if(right(m)) r = m;
        else l = m;
    }
    vanished += N - r;
    cout << N - vanished << endl;
}

Measured memory_bytes: 976
#include<bits/stdc++.h>
#define ll long long
#define int long long
#define M 1000000007
#define sz(c) c.size()
#define fr first
#define sc second
#define pb push_back
#define sz(c) c.size()
#define ppb  pop_back
#define mp make_pair
#define all(a)      (a).begin(),(a).end()
#define rep(i,a,n)   for( int i=a ; i<n ; i++)
#define what_is(x)  cout << #x << " is " << x << endl;
#define U 1000000007
#define N 100005
using namespace std;
signed main()
{
  ios_base::sync_with_stdio(false);
 
  string s;
  int n;
  cin>>n;
  cin>>s;
  int ans=0;
  rep(i,0,n-1)
  {
    if(s[i]==s[i+1]) continue;
    else ans++;
  }
  cout<<ans+1;


}


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

int main(){
	ll n, a, b; 
	cin>>n>>a>>b;
	if(a==0)cout<<0<<endl;
	else if(n%(a+b) == 0){
		ll op = n/(a+b);
		cout<<1ll*a*op<<endl;
	}
	else{
		ll x = n/(a+b), y = n%(a+b);
		ll rta = a*x;
		rta+=min(y, a);
		cout<<rta<<endl;
	}
}



Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
// << fixed << setprecision(0) <<
// sort(ALL(),greater<int>());

int main() {
ll n;
cin >> n;
map<string,ll> m;
string s;
REP(i,n) {
  cin >> s;
  sort(ALL(s));
  m[s]++;
}
ll ans=0;
ll x;
for(auto i:m) {
  x=i.second;
  ans+=(x-1)*x/2;
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,b,a) for(ll i = b;i>=a;i--)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define mpll map<pll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pair<ll,ll> >
#define mp(x,y)  make_pair(x,y)
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 1e6;


int main() {
    
    ll tc;
    tc = 1;
    //cin>>tc;
    while(tc--){
        ll k;
        cin>>k;
        ll rem = 0,p = 1;
        For(i,1,MAX+3){
            rem = (rem * 10 + 7)%k;
            if(rem == 0){
                cout<<i<<endl;
                return 0;
            }
        }
        cout<<-1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 3500
# Your code here!
def putList(l)
    print l[0]
    for i in 1...l.length do
        print " "
        print l[i]
    end
    print "\n"
end

def sort(l)
    for i in 1...l.length do
        v = l[i]
        j = i - 1
        while (j >= 0 && l[j].to_i > v.to_i) do
            l[j+1] = l[j]
            j -= 1
        end 
        l[j+1] = v
        putList(l)
    end
end

n = gets
line = gets
list = line.split(" ")

putList(list)
sort(list)



Measured memory_bytes: 6872
MOD=10**9+7
N,M=map(int,input().split())

def fact_mod(x):
  ret=1
  for i in range(2,x+1):
    ret*=i
    ret%=MOD
  return ret

N,M=max(N,M),min(N,M)
if N-M>=2:
  print(0)
elif N==M:
  fact=fact_mod(N)
  print(2*fact**2%MOD)
else:
  fact1=fact_mod(M)
  fact2=fact_mod(N)
  print(fact1*fact2%MOD)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main(){
    int a, b;
    cin >> a >> b;

    int c;
    if(b == 100){
        c = a*1000 + b;
    }else if(b/10 >= 1){
        c = a*100 + b;
    }else{
        c = a*10 + b;
    }

    int d = sqrt(c);
    if(d*d == c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():

    n, k = input_int_list()
    D = input_int_list()

    # N < 10000のため、嫌いな数字にかかわらず、
    # N <= ans < 100000の範囲に答えは収まる。
    # 計算量はO(n) (max_n = 5 * 10**4)

    for i in range(n, 100000):
        flag = True
        for j in str(i):
            if int(j) in D:
                flag = False
            if not flag:
                break
        if flag:
            print(i)
            return

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 67688
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    int n = s.length();
    for(int i=0;i<n;i++){
        int num = s[i] - '0';
        ans += num;
        ans %= 9;
    }
    if(ans == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3780
import java.util.Scanner;
public class Main {
public static void main(String[] args){
		
		{
	       
	         double r;
	         Scanner sc = new Scanner(System.in);
	         
		     
	 		r = sc.nextDouble();
	 		
	 		
	 		double d=r*r*Math.PI;
	 		double t=2*r*Math.PI;
	 		 System.out.printf("%.6f",d);
	 		 System.out.print(" ");
	 		 System.out.printf("%.6f",t);
	 		 
	         sc.close();
}}}



Measured memory_bytes: 28288
N,W=map(int,input().split())
nap=[]
for i in range(N):
    nap.append(list(map(int,input().split())))
search_m=[[0 for i in range(N+1)] for j in range(W+1)]
for i in range(N)[::-1]:
    for j in range(W+1):
        search_m[j][i]=search_m[j][i+1]
        if j+nap[i][1]>W:
            continue
        else:
            search_m[j][i]=max(search_m[j][i],search_m[j+nap[i][1]][i+1]+nap[i][0])
print(max(search_m[0]))


Measured memory_bytes: 25460
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    double ans = 0;
    for(int i = 0; i < n; i++)
    {
        double x; string s;
        cin >> x >> s;
        if(s == "JPY") ans += x;
        else ans += x * 380000.0;
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
    int n;
    int p;
    int cnt = 0;

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p;
        if (p > i + 1) cnt++;
        if (cnt == 2) break;
    }

    cout << (cnt < 2 ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
from collections import deque
s = deque(input())
q = int(input())

cnt = 1
for i in range(q):
    t_f_c = list(input().split())
    if t_f_c[0] == "1":
        cnt *= -1
    elif t_f_c[0] == "2":
        if cnt == 1: #反転-
            if t_f_c[1] == "1":
                s.appendleft(t_f_c[2])
            elif t_f_c[1] == "2":
                s.append(t_f_c[2])
        elif cnt == -1:  #反転+
             if t_f_c[1] == "2":
                s.appendleft(t_f_c[2])
             elif t_f_c[1] == "1":
                s.append(t_f_c[2])
if cnt == 1:
    print("".join(s))
elif cnt == -1:
    s.reverse()
    print("".join(s))

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

using namespace std;
typedef long long ll;

int main(void) {
  int n, K; cin >> n >> K;

  //int a, b, c; cin >> a >> b >> c;
  
  vector<ll> vs;

  for (int i = 0; i < n; i++) {
     ll v; cin >> v; vs.push_back(v);
  }

  ll maxs = 0;
  int mk, mt, mtl;
  for (int k = 0; k <= K; k++) {
    for (int t = 0; t <= k && t <= n; t++) {
      int s = k - t;
      for (int tl = 0; tl <= t; tl++) {
        //cout << "k:" << k << " ";
        ll sum = 0;
        int tr = t - tl;
        //cout << "tl tr: " << tl << " " << tr << " ";
        priority_queue<ll, vector<ll>, greater<ll> > minus;
        //cout << "lpick: ";
        for (int i = 0; i < tl && i < n; i++) {
          sum += vs[i];
          //cout << vs[i] << " ";
          if (vs[i] < 0) minus.push(vs[i]);
        }
        //cout << "rpick: ";
        for (int i = n - 1; (n - tr) <= i && 0 <= i; i--) {
          //cout << vs[i] << " ";
          sum += vs[i];
          if (vs[i] < 0) minus.push(vs[i]);
        }
        //cout << "throw: ";
        for (int i = 0; i < s; i++) {
          if (minus.empty()) break;
          //cout << minus.top() << " ";
          sum -= minus.top();
          minus.pop();
        }
        //cout << "sum: " << sum;
        //cout << endl;
        if (maxs < sum) {
          maxs = sum;
        }
      }
    }
  }

  cout << maxs << endl;

  return 0;
}

Measured memory_bytes: 256