akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

#define ll long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define PI 3.141592653589

using namespace std;

int gcd(int a, int b);
int lcm(int a, int b);

void solve_A(){
    int h, a;
    cin >> h >> a;

    cout << (h + a - 1)/a;
}

void solve_B(){
    int h, n, sum = 0;
    cin >> h >> n;
    int a[n];
    REP(i,n){
        cin >> a[i];
        sum += a[i];
    }

    if(sum >= h) cout << "Yes";
    else cout << "No";

}

void solve_C(){
    ll n, k;
    cin >> n >> k;
    ll h[n];
    REP(i,n) cin >> h[i];

    sort(h, h+n);
    
    ll sum = 0;

    REP(i,n-k){
        sum += h[i];
    }

    cout << sum;
}

void solve_D_muri(){
    ll h;
    cin >> h;

    if(h == 1) cout << 1;
    else{
        ll m;
        for(ll i = 0; i < ceil(log2(1000000000000))+1; i++){
            if(2 <= h && h <= 3) m = 1;
            else if(4 <= h && h <= 5) m = 2;
            else if(i >= 3){
                ll x = pow(2,i-1)-2;
                // cout <<pow(2,i)-x <<" " << pow(2,i) << endl;
                if(pow(2,i) - x <= h && h <= pow(2,i) + 1){
                    m = i;
                    break;
                }
            }
        }
        
        
        printf("%.0f",pow(2,m+1) - 1);
        
    }
}

ll solve(ll n){
    if(n==1) return 1;
    else return 2*solve(n/2)+1;
}

int main(void){
    ll h;
    cin >> h;

    cout << solve(h);

    
    //solve_D();
    
    return 0;
}

int gcd(int a, int b){
    if(a < b) swap(a, b);

    int r = a % b;
    while(r != 0){
        a = b;  b = r;  r = a % b;
    }
    return b;
}

int lcm(int a, int b){
    return a * b / gcd(a, b);
}

Measured memory_bytes: 256
fun main (args : Array<String>) {
	val s = readLine()
	val S : String = s.toString()
	var list : MutableList<Int> = mutableListOf()
	for (i in S) {
		list.add(i.toInt())
	}
	for (i in 0..2) {
		if (list[i] == list[i + 1]) {
			return println("Bad")
		}
	}
	println("Good")
}

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

int main(){

long long x, cnt = 0;
  cin >> x;
  
  if(x > 10){
    cnt = x / 11;
    x %= 11;
  }
  
  if(x == 0) cout << cnt * 2 << endl;
  else if((x < 7) && (x > 0)) cout << 1 + cnt * 2 << endl;
  else if((x < 11) && (x > 6)) cout << 2 + cnt * 2 << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <stdio.h>
char S[100002];
int ACsum[100002];
int main(void)
{
  int N, Q, i;
  int l, r, pos;
  int ans = 0;
  scanf("%d%d", &N, &Q);
  scanf("%s", &S[1]);
  
  ACsum[0] = ACsum[1] = 0;
  for (i = 0; i <= 100000; i++) {
    if (S[i]=='A' && S[i+1]=='C') {
      ACsum[i+1] = ACsum[i]+1;
    } else {
      ACsum[i+1] = ACsum[i];
    }
  }
  
  for (i = 0; i < Q; i++) {
    scanf("%d%d", &l, &r);
    printf("%d\n", ACsum[r]-ACsum[l]);
  }
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
using namespace std;
typedef long long int lli;
int main() {
  int N,K;
  cin>>N>>K;
  lli a=0;
  if (K==0) {
    a=(lli)N*N;
  } else {
    for (int b=K+1; b<=N; b++) {
      int p=N/b;
      int r=N%b;
      a+=(b-K)*p;
      a+=max(0,r+1-K);
    }
  }
  lli ans=a;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import numpy as np


def solve(N: int, T: "List[int]", V: "List[int]"):
    t_period = [0 for i in range(N+1)]
    for i in range(N):
        t_period[i+1] = t_period[i] + T[i]*2

    V = [0] + V + [0]
    limit = np.zeros((N+2,t_period[N]+1))
    line = np.arange(0, t_period[N]/2+0.5, 0.5)
    for i in range(N+2):
        if i == 0:
            l, r = 0, 0
        elif i == N+1:
            l, r = t_period[N], t_period[N]
        else:
            l, r = t_period[i-1], t_period[i]
        limit[i] = np.max([-line + l * 0.5, line * 0, line - r * 0.5], axis=0) + V[i]
    speed = np.min(limit, axis=0)

    total = 0
    for t in range(t_period[N]):
        total += (speed[t] + speed[t+1]) * 0.5 * 0.5

    print(total)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    t = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    v = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, t, v)

if __name__ == '__main__':
    main()


Measured memory_bytes: 46484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}
int main()
{
	int k;
	scanf("%d", &k);
	int sum = 0;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= k; j++) 
		{
			for (int l = 1; l <= k; l++) {
				sum += gcd(i, gcd(j, l));
			}
		}
	}
	printf("%d", sum);
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

ll S(ll x){
	ll S = 0;
	while(x>0){
		S += x%10;
		x /= 10;
	}
	return S;
}

double snuke(ll x){
	return double(x)/S(x);
}

int main(){
	ll K;
	cin >> K;
	vector<ll> cand;
	ll b = 1;
	for(int i=0;i<15;i++){
		for (int j=1;j<150;j++){
			cand.push_back(b * (j+1) - 1);
		}
		b *= 10;
	}
	sort(cand.begin(), cand.end());
	cand.erase(unique(cand.begin(), cand.end()), cand.end());
	for(ll i=0;i<cand.size();i++){
		for(ll j=i+1;j<cand.size();j++){
			if (snuke(cand[i]) > snuke(cand[j])){
				cand.erase(cand.begin() + i);
				i--;
				break;
			}
		}
	}

	REP(i, K){
		cout << cand[i] << endl;
	}
    return 0;
}

Measured memory_bytes: 256
A=[input().split() for i in range(3)]
N=int(input())
b=[0]*N
for i in range(N):
    b[i]=int(input())
    
for i in range(3):
    for j in range(3):
        for k in range(N):
            if int(A[i][j])-b[k]==0:
                A[i][j]=0

flag=0    
if A[0][0]==0 and A[0][1]==0 and A[0][2]==0:
    flag+=1
elif A[0][0]==0 and A[1][0]==0 and A[2][0]==0:
    flag+=1
elif A[0][0]==0 and A[1][1]==0 and A[2][2]==0:
    flag+=1
elif A[0][1]==0 and A[1][1]==0 and A[2][1]==0:
    flag+=1
elif A[0][2]==0 and A[1][2]==0 and A[2][2]==0:
    flag+=1
elif A[0][2]==0 and A[1][1]==0 and A[2][0]==0:
    flag+=1
elif A[1][0]==0 and A[1][1]==0 and A[1][2]==0:
    flag+=1
elif A[2][0]==0 and A[2][1]==0 and A[2][2]==0:
    flag+=1

if flag==0:
    print('No')
else :
    print('Yes')

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int solve(int a[],int n,int k)
{
    int dp[n];
    memset(dp,-1,sizeof(dp));
    dp[n-1]=0;
    for(int i=n-2;i>=0;i--)
    {
       for(int j=1;j<=k;j++)
       {   
           int steps=INT_MAX; 
           if((i+j)<n) 
           steps=abs(a[i]-a[i+j])+dp[i+j];   
           if(dp[i]==-1)
           dp[i]=steps;
           else
           dp[i]=min(dp[i],steps);       
       }
    }
    return dp[0];
}
int main() 
{
   int n,k;
   cin>>n>>k;
   int a[n];
   for(int i=0;i<n;i++)
   cin>>a[i];
   cout<<solve(a,n,k);
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A,B;
    cin>>A>>B;
    cout<<max(A-2*B,0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i, 0, n)cin >> a[i];
    ll stock = 0;
    ll money = 1000;
    rep(i, 0, n-1){
        if(a[i]<a[i+1]){
            stock += money/a[i];
            money -= stock*a[i];
            money += a[i+1]*stock;
            stock=0;
        }
    }
    cout << money << endl;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main()
{
    int i,j,a,b,c=0,l=0,t,x,y,n;
    cin>>n>>x>>t;
    if(n%x==0)
        i=n/x;
    else i=(n/x)+1;
    cout<<i*t<<endl;


 return 0;
}


Measured memory_bytes: 3524
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    vvi x(n, vi(3));
    for(int i=0; i<n; i++){
        cin >> x.at(i).at(0) >> x.at(i).at(1) >> x.at(i).at(2);
    }
    vvi res(n, vi(3, 0));
    res.at(0).at(0) = x.at(0).at(0);
    res.at(0).at(1) = x.at(0).at(1);
    res.at(0).at(2) = x.at(0).at(2);
    for(int i=1; i<n; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(j==k) continue;
                res.at(i).at(j) = max(res.at(i-1).at(k) + x.at(i).at(j), res.at(i).at(j));
            }
        }
    }
    cout << max(max(res.at(n-1).at(0), res.at(n-1).at(1)), res.at(n-1).at(2)) << endl;
}


Measured memory_bytes: 11264
pub fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let dg = readn::<usize>(" ");
    let d = dg[0];
    let g = dg[1];
    let mut p = Vec::with_capacity(d);
    let mut c = Vec::with_capacity(d);

    for _ in 0..d {
        let pc = readn::<usize>(" ");
        p.push(pc[0]);
        c.push(pc[1]);
    }

    let mut ans = p.iter().sum::<usize>();
    for i in 0..2_usize.pow(d as u32) {
        let mut score = 0;
        let mut half = d;
        let mut num = 0;
        for j in 0..d {
            let bit = i >> j & 1;
            if bit == 1 {
                score += p[j] * 100 * (j + 1) + c[j];
                num += p[j];
            } else {
                half = j;
            }
        }
        if half < 10 {
            if score < g {
                let half_num = ((g - score) + 100 * (half + 1) - 1) / (100 * (half + 1));
                score += 100 * (half + 1) * std::cmp::min(half_num, p[half]);
                num += half_num;
            }
        }
        if score >= g && num < ans {
            ans = num;
        }
    }

    println!("{}", ans);
}

Measured memory_bytes: 4352
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
using namespace std;

signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int a, b;
    cin >> a >> b;
    cout << 6 - a - b;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b, idx = zip(*sorted(zip(a, range(1, n + 1))))
if b[-1] < 0:
    print(n - 1)
    # 全て負の数なので後ろから累積和をとる
    for i in range(n - 1):
        print(n - i, n - i - 1)
elif b[0] >= 0:
    print(n - 1)
    for i in range(n - 1):
        print(i + 1, i + 2)
else:
    # max or min を足して全て正の数に直す
    print(2 * n - 2)
    if b[-1] > abs(b[0]):
        # add max
        for i in range(n):
            if i + 1 != idx[-1]:
                print(idx[-1], i + 1)
        for i in range(n - 1):
            print(i + 1, i + 2)
    else:
        for i in range(n):
            if i + 1 != idx[0]:
                print(idx[0], i + 1)
        for i in range(n - 1):
            print(n - i, n - i - 1)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String num = sc.nextLine();
		String[] numSpl = num.split(" ");
		int n = Integer.parseInt(numSpl[0]);
		int k = Integer.parseInt(numSpl[1]);
		int point = 0;
		int count = 0;
		double p = 0;
		double out = 0;
		
		for(int i = 1; i <= n;i++){
			point = i;
			while(point < k){
				point = point *2;
				count++;
			}
			p = (1/(double)n) * Math.pow(0.5, count);
			out = out + p;
			count = 0;
		}
		System.out.println(out);
	}
}

Measured memory_bytes: 22100
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(N * N * N)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using lint=long long;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n;std::cin>>n;
    std::vector<lint>q(n);
    for(lint i=0;i<n;i++){
        lint x;std::cin>>x;
        q.at(x-1)=i;
    }
    std::vector<lint>a(n,1),b(n,n*n);
    for(lint i=1;i<n;i++){
        a.at(i)=a.at(i-1)+q.at(i)+1;
        b.at(i)=b.at(i-1)-q.at(i-1)-1;
    }
    for(lint i=0;i<n;i++){
        std::cout<<(i?" ":"")<<a.at(i);
    }
    std::cout<<'\n';
    for(lint i=0;i<n;i++){
        std::cout<<(i?" ":"")<<b.at(i);
    }
    std::cout<<'\n';
}


Measured memory_bytes: 1152
n=int(input())
s=[input() for _ in range(n)]
m=int(input())
t=[input() for _ in range(m)]
ans=0
buf=0
s.sort()
t.sort()
for i in range(n):
    buf=0
    for j in range(i,n):
        if s[i]==s[j]:
            buf+=1
        elif s[i]<s[j]:
            break
    for j in range(m):
        if s[i]==t[j]:
            buf-=1
        elif s[i]<t[j]:
            break
    if buf>ans:
        ans=buf
print(ans)  

Measured memory_bytes: 3064
#include <iomanip>
#include <iostream>

using namespace std;

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

    double r = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        r += (1.0 / a);
    }

    cout << setprecision(12) << fixed << (1.0 / r) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100000
int A[MAX],n;
int partition(int p,int r){
  int x,i,j,t;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      t=A[i];A[i]=A[j];A[j]=t;
    }
  }
  t=A[i+1];A[i+1]=A[r];A[r]=t;
  return i+1;
}
int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&A[i]);
  q=partition(0,n-1);
  for(i=0;i<n;i++){
    if(i)printf(" ");
    if(i==q)printf("[");
    printf("%d",A[i]);
    if(i==q)printf("]");
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2244
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll bit[1000010];
ll n, k, a[200010], sum[200010], t[200010], ans;

void add(ll a, ll w) {
	for (int x = a; x <= n + 2; x += x & -x) bit[x] += w;
}
int SUM(ll a) {
	ll ret = 0;
	for (int x = a; x > 0; x -= x & -x) ret += bit[x];
	return ret;
}

int main() {
	cin >> n >> k;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		a[i] -= k;//(sum[j]-sum[i])/(j-i)>=k  sum[j]>=sum[i]
		sum[i + 1] = t[i + 1] = sum[i] + a[i];
	}
	sort(t, t + n + 1);//座圧の準備
	ll p = unique(t, t + n + 1) - t;
	for (int i = 0;i <= n;i++) {//座圧　にぶたんしてその数が何番目のイテレータか探す
		sum[i] = lower_bound(t, t + p + 1, sum[i]) - t + 1;
	}
	for (int i = 0;i <= n;i++) {
		ans += SUM(sum[i]);//自分より左側の、自分以下の数の合計を加算
		add(sum[i], 1);//自分を合計管理の要素に加える
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8448
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	map<string,int> m;
	string str;
	for(int i=0;i<n;i++)
	{
		cin>>str;
		m[str]++;
	}
	map<string,int>::iterator it;
	vector<pair<int,string>> v;
	int maxi=0;
	for(it=m.begin();it!=m.end();it++)
	{
	    maxi=max(maxi,it->second);
		v.push_back(make_pair(it->second,it->first));
	}
	m.clear();
	sort(v.begin(),v.end());
	int l=v.size();
	for(int i=0-1;i<l;i++)
	{
	    if(v[i].first==maxi)
	    {
		    cout<<v[i].second<<"\n";
	    }
	    
	}
	return 0;
}

Measured memory_bytes: 29168
#![allow(unused_imports)]
#![allow(dead_code)]
use std::io::prelude::*;
use std::cmp::{max, min};

const MOD: i64 = 1e9 as i64 + 7; 

fn main(){
    let s: Vec<char> = read::<String>().chars().collect();
    let n: usize = s.len();
    let mut rl: Vec<usize> = vec![];
    for i in 0..n - 1{
        if s[i] == 'R' && s[i + 1] == 'L'{
            rl.push(i);
        }
    }
    rl.push(n);
    let mut l: usize = 0;
    let mut r: usize = 0;
    let mut ans: Vec<isize> = vec![0; n];
    for i in 0..n{
        if s[i] == 'L'{
            let p: usize = (((rl[l] as isize - (i as isize)).abs()) % 2) as usize;  
            ans[rl[l] + p] += 1;
        }else{
            let p: usize = (((rl[r] as isize - (i as isize)).abs()) % 2) as usize;  
            ans[rl[r] + p] += 1;
        }
        if i == rl[r]{
            l = r;
            r += 1;
        }
    }
    print!("{}", ans[0]);
    for i in 1..n{
        print!(" {}", ans[i]);
    }
    println!();
}

fn read<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 6524
from sys import stdin
def main():
    #入力
    readline=stdin.readline
    K=int(readline())
    A,B=map(int,readline().split())
    if A%K==0:
        print("OK")
    elif A//K<B//K:
        print("OK")
    else:
        print("NG")
if __name__=="__main__":
    main()

Measured memory_bytes: 9140
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();

        var k = 0;
        var l = -1;
        for (int i = 1; i < s.Length; i++)
        {
            if (s[i] != s[i - 1])
            {
                continue;
            }

            if (l < 0)
            {
                l = i;
                continue;
            }
            
            k += Math.Max(i - l, 1);
            l = -1;
        }
        if (l > 0)
        {
            k += s.Length - l;
        }
        Console.WriteLine(k);
    }
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int ans = 0;
  for (int i = 0; i < N; i++){
    ans += (A.at(i) - 1);
  }

    cout << ans << endl;
}

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

#define ll long long int
#define ff first
#define ss second

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(10);

	int n;
	cin >> n;
	pair<int, int> po[n];

	for (int i = 0; i < n; ++i)
	{
		cin >> po[i].ff >> po[i].ss;
	}

	double dist[n][n] = {};

	for (int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			dist[i][j] = sqrt((po[i].ff - po[j].ff) * (po[i].ff - po[j].ff) + (po[i].ss - po[j].ss) * (po[i].ss - po[j].ss));
		}
	}

	int k = 1;
	for(int i = n - 2; i > 0; --i)
		k *= i;

	double sum = 0;
	for(int i = 0; i < n; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			sum += dist[i][j] * k * (n - 1);
			// cout << dist[i][j] << " \n"[j == n - 1];
		}
	}

	// cout << sum << "\n";
	sum = (sum) / (k * (n - 1) * n);
	cout << fixed << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define chmax(a,b) (a<(b)?(a=b,1):0)
#define chmin(a,b) (a>(b)?(a=b,1):0)
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
const int INF = 1<<29;
const double EPS = 1e-8;
const double PI = acos(-1);
typedef pair<int,int> pii;
typedef long long ll;

char a[50][50];
int dp[50][50][4][1<<11];
bool visited[50][50][4][1<<11];
int bitMap[4][1<<11][4];
bool canGet[4][1<<11][4];
vector<pii> needCells[4];

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

int h,w,K;

int solve(int y, int x, int k, int S){
  int &r = dp[y][x][k][S];
  if (visited[y][x][k][S]) return r;
  visited[y][x][k][S] = 1;
  int res = -INF;
  if (y==h-1&&x==w-1) res = 0;
  REP(d,4) {
    int nk = k+(d>=2);
    if (nk>K) continue;
    int ny = y+dy[d];
    int nx = x+dx[d];
    if (!valid(ny,nx,h,w)) continue;
    if (a[ny][nx] == '#') continue;
    int score = canGet[k][S][d]&&isdigit(a[ny][nx]) ? a[ny][nx]-'0' : 0;
    chmax(res, solve(ny,nx,nk,bitMap[k][S][d]) + score);
  }
  return r = res;
}

int main() {
  REP(k,4) {
    for (int y=-3; y<=3; ++y) {
      for (int x=-3; x<=3; ++x) {
        if ((y||x) && -min(y,0)-min(x,0) <= 3-k && max(0,y)+max(0,x) <= k)
          needCells[k].push_back(pii(y,x));
      }
    }
  }
  REP(k,4) {
    int n = needCells[k].size();
    REP(S,1<<n) {
      REP(d,4) {
        int nk = k+(d>=2);
        if (nk == 4) continue;
        int T = 0;
        REP(i,n) {
          if (S>>i&1) {
            pii p = needCells[k][i];
            p.first -= dy[d];
            p.second -= dx[d];
            REP(j,needCells[nk].size()) {
              if (needCells[nk][j] == p) {
                T |= 1 << j;
              }
            }
          }
        }
        REP(j,needCells[nk].size()) {
          if (needCells[nk][j] == pii(-dy[d],-dx[d])) {
            T |= 1 << j;
          }
        }
        bitMap[k][S][d] = T;

        canGet[k][S][d] = 1;
        REP(i,n)
          if (S>>i&1 && needCells[k][i]==pii(dy[d],dx[d]))
            canGet[k][S][d] = 0;
      }
    }
  }
  while(cin>>h>>w>>K) {
    REP(i,h) REP(j,w) cin >> a[i][j];
    cout << solve(0,0,0,0) << endl;
  }
  
}

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

int main(){
  int a,b;
  cin >> a >> b;
  double fa=a,fb=b;
  //cout << (a/b) <<" "<<(a%b)<<" "<<(fa/fb)<<endl;
  printf("%d %d %.5f\n",(a/b),(a%b),(fa/fb));
  return 0;
}


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

int main(){
	int i,a[105]={0},s=0,x,n;
	
	cin>>n;
	
	for(i=1;i<=n;i++)
	{
		cin>>x;
		a[x]=1;
	}
	for(i=1;i<=105;i++){
		if(a[i]==1){
			s++;
		}
	}
	cout<<s<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int limit = 100010;
using edge = struct {
  int to; //行先
  ll cost; //距離
};
vector<edge> tree[limit];
ll depth[limit];
void dfs(int v, int p, ll d) { //v:行先,p:ひとつ前,d:累積距離
  depth[v] = d;
  for (auto &e : tree[v]) {
    if (e.to == p) continue; //逆戻り不可
    dfs(e.to, v, d + e.cost); //次の行き先,現在地,累積距離
  }
}
int main(void) {
  int n;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    tree[a].push_back({b, c}); //aからbへの距離
    tree[b].push_back({a, c}); //bからaへの距離
  }
  int q, k;
  cin >> q >> k;
  k--;
  dfs(k, -1, 0); //kから各方面への距離
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    cout << depth[x] + depth[y] << endl;
  }
  return 0;
}


Measured memory_bytes: 15744
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	vector<int> v(2), v2(2);
	
	for (int i = 0; i < 2; i++){
		cin >> v[i];
	}
	
	for (int i = 0; i < 2; i++){
		cin >> v2[i];
	}
	
	sort(v.begin(), v.end());
	sort(v2.begin(), v2.end());
	
	cout << v[0] + v2[0] << endl;
}

Measured memory_bytes: 256
import math

K=int(input())
ans=0
for i in range(1,K+1):
    for j in range(1,i+1):
        for k in range(1,j+1):
            temp=math.gcd(i,math.gcd(j,k))
            if i==j==k:
                ans+=temp
            elif i==j or j==k:
                ans+=temp*3
            else:
                ans+=temp*6
print(ans)

Measured memory_bytes: 9192
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    bool flag = 0;
    for (int i = 0; i <= 25; i++) {
        for (int j = 0; j <= 14; j++) {
            if (i * 4 + j * 7 == n) {
                flag = 1;
                break;
            }

        }
    }
    if (flag==1) cout << "Yes" << endl;
    else cout << "No" << endl;
}


    

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
namespace CodeIQ
{
	public class Solver
	{
		public Solver() { }
		private static int IsPrime(int n)
		{
			int i;
			if (n < 2) return 0;
			else if (n == 2) return 1;
			if (n % 2 == 0) return 0;
			for (i = 3; i <= n / i; i += 2)
				if (n % i == 0) return 0;
			return 1;
		}

		public static int Main()
		{
			string sep = " ./";
			var N = Console.ReadLine().Trim().Split(sep.ToCharArray()).Select(x => int.Parse(x)).ToList();
			int n = 0;
			for (n = 0; n * (n + 1) / 2 < N[0]; n++) { }
			int sum = n * (n + 1) / 2;
			int diff = sum - N[0];
			for (int i = 1; i <= n; i++)
			{
				if (diff == i)
				{
					continue;
				}
				Console.WriteLine(i);
			}
			return 0;
		}
	}
}

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

static const ll MOD = (int)1e9 + 7;

ll dp[100010][13];

int main(int argc, char const *argv[])
{
	string s; cin >> s;

	dp[0][0] = 1;

	rep(i, (int)s.size()) {
		if (s[i] == '?') {
			rep(j, 13) {
				rep(k, 10) { // ? にいれる数
					(dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
				}
			}
		} else {
			int k = s[i] - '0';
			rep(j, 13) {
				(dp[i + 1][(j * 10 + k) % 13] += dp[i][j]) %= MOD;
			}
		}
	}
	cout << dp[(int)s.size()][5] << endl;
	return 0;
}


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


void solve() {
  int A,B;
  scanf("%d %d", &A,&B);
  int min = B-A+1;
  int max = B+A-1;
  
  for (int i = min; i <= max; i++) {
    printf("%d ", i);
  }

}

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


Measured memory_bytes: 256
W, a, b = map(int, input().split())

if a+W < b:
  tmp = b-a-W
  if tmp <= 0:
    print(0)
  else:
    print(tmp)
elif a > b+W:
  tmp = a-W-b
  if tmp <= 0:
    print(0)
  else:
    print(tmp)
else:
  print(0)

Measured memory_bytes: 3060
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    int H,W;
    vector<vector<int> > cost(10,vector<int>(10));
    GI(H);GI(W);
    REP(i,10)
        REP(j,10)
            GI(cost[i][j]);
    REP(k,10)
        REP(i,10)
            REP(j,10)
                cost[i][j]=min(cost[i][j],cost[i][k]+cost[k][j]);
    int ans=0;
    REP(i,H)REP(j,W){
        int a;
        GI(a);
        if(0<=a)
            ans+=cost[a][1];
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 256
function main(input) {
  input = input.trim().split("\n");
  const n = Number(input[0]);
  const as = input[1].split(" ").map(n => Number(n));
  let result = 0;
  for(const a of as){
    let num = a;
    while (num%2 === 0) {
      result++;
      num /= 2;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7756
import os, sys, re, math

S = input()

A = ('01' * 50000)[:len(S)]
B = ('10' * 50000)[:len(S)]

countA = 0
countB = 0
for i in range(len(S)):
    if A[i] != S[i]:
        countA += 1
    if B[i] != S[i]:
        countB += 1

print(min(countA, countB))


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<string> vec(H);
  for (int i=0; i < H; i++) {
    cin >> vec.at(i);
  }
  
  int count;
  char buf;
  // main loop
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (vec.at(i).at(j) == '.') { 
        count = 0;
        for (int di = -1; di <= 1; di++) {
          for (int dj = -1; dj <= 1; dj++) {
            if (i + di >= 0 && i + di < H && j + dj >= 0 && j + dj < W) {
              if (vec.at(i+di).at(j+dj) == '#') {
                count++;
              }
            }
          }
        }
        vec.at(i).at(j) = to_string(count).at(0);
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    cout << vec.at(i) << endl;
  }
}


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

int main(){
	string s;
	cin >> s;
	int N = s.length();
	if(s[0] == s[N - 1]){
		if(N % 2 == 0) cout << "First" << endl;
		else cout << "Second" << endl;
	}else{
		if(N % 2 == 0) cout << "Second" << endl;
		else cout << "First" << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 998244353
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 2500100

long long kai[N];
long long rkai[N];
long long xx[30];
int yy[30];

void kaiz(void) {
	kai[0] = 1;
	f(i, N - 1) {
		kai[i + 1] = kai[i] * (i + 1);
		kai[i + 1] = kai[i + 1] % MOD;
	}
	int x = MOD - 2;
	f(i, 30) {
		if (x % 2 == 1)yy[i] = 1;
		else yy[i] = 0;
		x = x / 2;
	}
	f(i, N) {
		xx[0] = kai[i];
		f(j, 29) {
			xx[j + 1] = xx[j] * xx[j];
			xx[j + 1] = xx[j + 1] % MOD;
		}
		rkai[i] = 1;
		f(j, 30) {
			if (yy[j] == 1) {
				rkai[i] = rkai[i] * xx[j];
				rkai[i] = rkai[i] % MOD;
			}
		}
	}
}

long long ni(long long x, long long y) {
	if (x < 0 || y<0 || y>x)return 0;
	long long re = kai[x];
	re = re * rkai[x - y];
	re = re % MOD;
	re = re * rkai[y];
	re = re % MOD;
	return re;
}


int main() {
	long long q, n, m, k;
	long long x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	kaiz();

	scanf("%lld %lld", &n, &m);
	k = m % 2;
	s = 0;
	for (long long i = 0; i <= ((m - k) / 2); i++) {
		x = ni(n - 2 + i, n - 2);
		s = (s + x) % MOD;
	}
	ans = 0;
	while (k <= m&&k<=n) {
		x = (3 * m) - k;
      x=x/2;
		x = ni(x + n - 1, n - 1);
		y = (n * s) % MOD;
		x = (x - y + MOD) % MOD;
		y = (m - k) / 2;
		y = ni(n + y - 2, n - 2);
		y = (y*(n - k)) % MOD;
		x = (x + y) % MOD;

		z = ni(n, k);
		z = (z * x) % MOD;

		ans = (ans + z) % MOD;

		x = (m - k) / 2;
		x = ni(x + n - 2, n - 2);
		s = (s - x + MOD) % MOD;

		k += 2;
	}
	printf("%lld\n", ans);


	return 0;
}

Measured memory_bytes: 39168
N = int(input())
XU = [input().split() for i in range(N)]

ans = 0.0 
for i in range(N):
    x = float(XU[i][0])
    u = XU[i][1]
    if u == 'JPY':
        ans += x
    else:
        ans += x * 380000.0

print(ans)

Measured memory_bytes: 2940
def init_table(s)
  table = Hash.new { |h, k| h[k] = [] }
  s.size.times { |i| table[s[i]] << i }
  table
end

hs = init_table(gets.strip)
ht = init_table(gets.strip)

puts hs.values == ht.values ? 'Yes' : 'No'


Measured memory_bytes: 7116
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

void insertionSort(int A[],int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0 && A[j]>v){
      A[j+g]=A[j];
      j-=g;
      cnt++;
    }
    A[j+g]=v;
  }
}

void shellSort(int A[],int n){
  for(int h=1;;){
    if(h>n)break;
    G.push_back(h);
    h=3*h+1;
  }

  for(int i=G.size()-1;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++)scanf("%d",&A[i]);
  cnt=0;

  shellSort(A,n);

  cout<<G.size()<<endl;
  for(int i=G.size()-1;i>=0;i--){
    printf("%d",G[i]);
    if(i)printf(" ");
  }
  printf("\n");
  printf("%d\n",cnt);
  for(int i=0;i<n;i++)printf("%d\n",A[i]);

  return 0;
}



Measured memory_bytes: 7192
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    n: usize,
    k: usize
    }
    let mut ans = 0;
    for i in k..n {
        ans += n / (i + 1) * (i + 1 - k);
        ans += (n % (i + 1)).checked_sub(k.checked_sub(1).unwrap_or(k)).unwrap_or(0);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <iostream>
#include <fstream>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <functional>
#include <cstdlib>
#include <iomanip>
#include <climits>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 2e9 + 1e8;
const ll INF = 2e18 + 1e17;
const int mod = 998244353;
const int MOD = 1e9 + 7;
 
ll gcd(ll a, ll b) {
	return (b == 0 ? a : gcd(b, a % b));
}
bool is_prime(ll x) {
	if (x == 1 || (x % 2 == 0 && x > 2))     return false;
	for (int i = 3; i*i <= x; i += 2) {
		if (!(x % i)) {
			return false;
		}
	}
	return true;
}
 
/**************************************************************************************
***************************************************************************************/
const int MAXN = 100010;

int N;
int ans = 0;

int main (){
    ios_base::sync_with_stdio(false);   cin.tie(false);
    int mn = inf;
    cin>>N;
    for (int i = 0; i<N; i++){
        int x;  cin>>x;
        mn = min(mn, x);
        if (x <= mn){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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


def gcd(x, y):
    while x % y:
        x, y = y, x % y
    return y


def lcm(x, y):
    return x * y // gcd(x, y)


n = int(input())
t = [int(input()) for _ in range(n)]

ans = 1
for ele in t:
    ans = lcm(ans, ele)

print(ans)


Measured memory_bytes: 3060
n,k = map(int,input().split())
m = []
l = []
for _ in range(k):
    i = int(input())
    m.append(i)
    j = list(map(int,input().split()))
    l.append(j)

l = [e for row in l for e in row]
l = set(l)

cnt = 0
for i in range(n+1):
    for j in l:
        if i == j:
            cnt += 1

print(n-cnt)

Measured memory_bytes: 9204
from collections import deque

H,W = map(int,input().split())
src = [input() for _ in range(H)]

dxy = [(0,1),(1,0),(0,-1),(-1,0)]

dist = [[-1]*W for _ in range(H)]
d = deque([])

for h in range(H):
    for w in range(W):
        if src[h][w]=="#":
            dist[h][w]=0
            d.append((w,h))
while d:
    x,y = d.popleft()
    for dx, dy in dxy:
        nx,ny = x+dx, y+dy
        if not 0<=nx<W: continue
        if not 0<=ny<H: continue
        if src[ny][nx] == "#": continue
        if dist[ny][nx] > 0: continue
        dist[ny][nx] = dist[y][x] + 1
        d.append((nx,ny))
print(max(map(max,dist)))

Measured memory_bytes: 87004
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());

        int ans = 0;
        
        for(int i = 3; i <= N; i += 2) {

            int divisor = 0;
            for(int j = 1; j * j < i; j += 2) {
                if(i % j == 0) {
                    divisor += 2;
                }
            }

            if(divisor == 8) {
                ans += 1;
                // pw.println(i);
            }
            
        }

        pw.print(ans);
        br.close();
        pw.close();
    }
}

Measured memory_bytes: 32916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >>s;
  if (s[2]==s[3]&&s[4]==s[5]){
    cout<< "Yes"<< endl;
    return 0;
  }
  else{
    cout << "No" << endl;
  return 0;
  }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i, n) for(int i = (int)(n); i >= 0; i--)
#define repm(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define repmr(i, m, n) for(int i = (int)(n); i >= (int)(m); i--)
#define all(x) (x).begin(),(x).end()
#define inf 2e9

using namespace std;
typedef long long int lli;
typedef long long ll;

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

    int ans;
    if(a*n > b) ans = b;
    else ans = a*n;

    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=LL(n)
l.sort(key=lambda x:-x[1])
from heapq import heappush,heappop,heapify
s=set()
q=[]
oisisa=0
syu=0
for t,d in l[:k]:
    if t in s:
        heappush(q,d)
    else:
        s.add(t)
        syu+=1
    oisisa+=d
ans=oisisa+syu**2
for t,d in l[k:]:
    if q and not t in s:
        syu+=1
        oisisa+=d-heappop(q)
        s.add(t)
    ans=max(ans,oisisa+syu**2)
print(ans)

Measured memory_bytes: 95000
//this is simple traversal can be done in bottom up manner as well
#include<bits/stdc++.h>
using namespace std;
#define ll long long 

int main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    int mod = 1e9+7;
    int n,m;
    cin>>n>>m;
    char ptr[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            char a; cin>>a;
            ptr[i][j] = a;
        }
    }

    ll ans[n][m];
    ans[0][0]=1;
    for(int i=1;i<n;i++){
        ans[i][0]=ans[i-1][0];
        if(ptr[i][0]=='#'){
            ans[i][0]=0;
        }
    }
    for(int j=1;j<m;j++){
         ans[0][j]=ans[0][j-1];
        if(ptr[0][j]=='#'){
            ans[0][j]=0;
        }
    }
    for(int i=1;i<n;i++){
        for(int j=1;j<m;j++){
            if(ptr[i][j]=='#'){
                ans[i][j]=0;
            }else{
                (ans[i][j]=ans[i-1][j]+ ans[i][j-1])%=mod;
            }
        }
    }
    cout<<ans[n-1][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 12380
#include <bits/stdc++.h>
# include <string>
# include <math.h>
using namespace std;
typedef long long int ll;
vector<vector<int>> ug;
vector<bool> visited;
vector<int> tims;
vector<int> path;
int tim = 0;
int dfs(int u){
	if(visited[u]) return tims[u];
	visited[u] = true;
	path.push_back(u);
	tims[u] = tim;tim++;
	return dfs(ug[u][0]);
}

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
	
	long long int n,k; cin >> n >> k;
	ug.resize(n+1);
	visited.assign(n+1,false);
	tims.resize(n+1);

	for(int i =1;i<n+1;i++){
		ug[i].resize(1);
		cin >> ug[i][0];
	}
	int c_s = dfs(1);
	long long int l = path.size();
	if( k < l){
		cout << path[k];
	}
	else{
		k -= c_s;
		int c_len = path.size()-c_s;
		cout << path[k%c_len + c_s];
	}




}


Measured memory_bytes: 21760
#include <iostream>
using namespace std;
//AOJ0033

int Data[10];

bool dfs(int a,int left,int right) {
	//cout << a << "/" << left << "/" << right << endl;
	if (a == 10) return true; 
	if (Data[a] > left) {
		//Add a to the left
		if(dfs(a+1,Data[a],right)) return true;
	}
	else if (Data[a] > right) {
		//Add a to the right
		if(dfs(a+1,left,Data[a])) return true;
	}
	return false;
}

int main() {
	int N;
	cin >> N;
	for (int i = 0;i < N;i++) {
		for (int j = 0;j < 10;j++) {
			cin >> Data[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define ll   long long int  
#define pb push_back
const int M=1e9 + 7;
using namespace std;
int N=1000000+1;
int main() {
   
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,K;cin>>n>>K;
    ll* a=new ll[n+1];
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
	}
    ll* dp=new ll[n+1];
    dp[0]=0;
    dp[1]=0;
    dp[2]=abs(a[1]-a[2]);
    for(int i=3;i<=n;i++)
    {   
        dp[i]=-1;
    	for(int k=1;k<=K;k++)
    	{ 
    		if(i-k>=1)
    		{
    			if(dp[i]==-1)
			{
				dp[i]=abs(a[i]-a[i-k])+dp[i-k];
				continue;
			}
			dp[i]=min(dp[i],abs(a[i]-a[i-k])+dp[i-k]);
			}
			
		}
	}
	cout<<dp[n]<<endl;
  	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

			while (sc.hasNext()) {
				int n = Integer.parseInt(sc.next());
					if (n == 0) {
						break;
					} else {
						judge(n);
					}
			}
		sc.close();
	}

	private static void judge(int n) {
		int a = 0;
		int b = 0;
		int A = 0;
		int B = 0;

			for (int i = 0; i < n; i++) {
				a = Integer.parseInt(sc.next());
				b = Integer.parseInt(sc.next());

				if (a > b) {
					A += a + b;
				} else if (a < b) {
					B += a + b;
				} else {
					A += a;
					B += b;
				}
			}

		System.out.printf("%d %d\n", A, B);
	}

}


Measured memory_bytes: 44168
#include<stdio.h>
 
int main(){
  int n,tmp;
  int sum=0;
  
  
  scanf("%d",&n);
  int p[n];
  
  for(int i=0;i<n;i++){
    scanf("%d",&p[i]);
  }
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(p[i]<p[j]){
        tmp=p[i];
        p[i]=p[j];
        p[j]=tmp;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    if(i==0){
      sum+=p[i]/2;
    }else{
      sum+=p[i];
    }
  }
  
  printf("%d",sum);
  return 0;
}

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


int main()
{
	int x = 0;
	int N;
	int a[1000];
	int max = 0;
	char S;

	cin >> N;
	
	for(int i = 0; i <= N-1; i++) {

		cin >> S;

		if (S == 'I') {
			x++;
		}
		else {
			x--;
		}
		a[i] = x;
		if (a[i] > max)
			max = a[i];
	}
	
	
	cout << max << endl;
	return 0;
}

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

  char number[1001];
  int i,num,sum;
  sum = 0;

  while(1){

    scanf("%s", number);

    for ( i = 0 ; i < strlen(number) ; i++ ){

      num = number[i] - '0';
      sum = sum + num;

    }

    if ( sum == 0 ) break;
    printf("%d\n", sum);
    sum = 0;
    
  }

  return 0;
  
}

Measured memory_bytes: 536
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll c[51][51];
void comb(int x){
    for(int i=0;i<=x;i++){
        c[i][0]=1;
        c[i][i]=1;
    }
    for(int i=1;i<=x;i++){
        for(int j=1;j<=i;j++){
            c[i][j]=c[i-1][j-1]+c[i-1][j];
        }
    }
    return ;
}

int main(void){
    comb(50);
    ll n,a,b,ans=0;
    cin>>n>>a>>b;
    ll s[n];
    for(int i=0;i<n;i++){
        cin>>s[i];
    }
    ll cnt1=0,cnt2=0;
    sort(s,s+n);
    reverse(s,s+n);
    ll lim=s[a-1];
    ll tot=0;
    for(int i=0;i<n;i++){
        if(i<a)tot+=s[i];
        if(s[i]>lim)cnt1++;
        else if(s[i]==lim)cnt2++;
    }
    cout<<setprecision(25)<<(double)tot/(double)a<<endl;
    if(cnt1){
        cout<<c[cnt2][a-cnt1]<<endl;
    }
    else{
        for(int i=a;i<=min(b,cnt2);i++){
            ans+=c[cnt2][i];
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readc(n, a, b);
	readarr(p, n);
	int x = 0, y = 0, z = 0;
	
	FOR (i, 1, n)
	    if (p[i] <= a) x++;
	    else if (p[i] <= b) y++;
	    else z++;
	
	cout << min({x, y, z});
}



















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

#define f first
#define s second
#define ins insert
#define pb push_back
#define endl '\n'
#define ll long long
#define ld long double
#define vi vector<int>
#define vl vector<ll>
#define ii pair<int,int>
#define no cout << "NO" << endl 
#define yes cout << "YES" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (int) (c).size()
#define trav(x,c) for (auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define db(x) cout << #x << ": " << x << endl;
#define _db(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios_base::sync_with_stdio(0); cin.tie(0);

int main() { 
    godspeed;
    char A;
    cin >> A;
    if(A>='A' && A<='Z')
        cout << 'A' << '\n';
    else
        cout << 'a' << '\n';
}

Measured memory_bytes: 3632