akhauriyash/Code-Regression huggingface dataset:
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element : vec) {
        is >> element;
    }
    return is;
}
template <class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main(std::istream &in, std::ostream &out) {
    int K, N;
    in >> K >> N;
    vi a(N);
    cin >> a;

    int diff = K - a[N - 1] + a[0];
    REP(i, N - 1) {
        chmax(diff, a[i + 1] - a[i]);
    }
    out << K - diff;
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    //cin.tie(nullptr);
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    Main(in, out);
    //cout << flush;
}
#pragma endregion


Measured memory_bytes: 4768
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <deque>
using namespace std;
typedef long long int ll;
typedef pair<int,int> ii;
const ll inf = 1e18;

void solve()
{
    ll a;
    string b;
    cin >> a >> b;
    ll k = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0')*1;
    cout << (a*k)/100 << '\n';
}

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

Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	ps := make([]int, n)
	for i := range ps {
		fmt.Scan(&ps[i])
	}

	ans := 0
	for i := 0; i < n; i++ {
		count := 0
		if ps[i] == i+1 {
			count++
			for j := i + 1; j < n && ps[j] == j+1; j++ {
				count++
				i = j
			}
			ans += (count + 1) / 2
		}
	}
	fmt.Println(ans)
}


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

#ifndef ONLINE_JUDGE
#include "myfile.h"
#endif

#define int long long
#define pb push_back
#define range(v) v.begin(),v.end()
#define mod (int)(1e9 + 7)
#define inf (int)(1e15)
#define N (int)(2e5 + 10)

using namespace std;


void solve() {
	int n;
	cin >> n;
	vector<int> a(n);
	for (int &i : a) cin >> i;
	sort(range(a), greater<int>());
	int j = 1;
	int cur = 0;
	int ans = a[0];
	for (int i = 2; i < n; i++) {
		ans += a[j];
		cur++;
		if (cur == 2) j++, cur = 0;
	}

	cout << ans << endl;
}

int32_t main() {
	ios_base::sync_with_stdio(false), cin.tie(nullptr), cin.tie(nullptr);
	int t_c = 1;
//	cin >> t_c;
	while (t_c--)
		solve();
}

Measured memory_bytes: 4788
#include <bits/stdc++.h>
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
    char s[100];
    cin >> s;

    int ans = 0;
    for (int i = 0; i < 4; i++)
    {
        if (s[i] == '+') ++ans;
        else --ans;
    }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int r;
    cin>>r;
    cout<<(2*3.14*r)<<"\n";

    return 0;
}

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

const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> A){
    unordered_map<int, int> m;
    long long res = 1;
    for (auto a : A) {
	m[a]++;
    }
    if (N % 2 != 0) {
      if (m[0] != 1) {
	  cout << 0 << endl;
	  return;
      }
      for (int i = 2; i < N; i += 2) {
	  if (m[i] != 2) {
	    cout << 0 << endl;
	    return;
	  }
      }
    } else {
      for (int i = 1; i < N; i += 2) {
	  if (m[i] != 2) {
	    cout << 0 << endl;
	    return;
	  }
      }
    }
    for (int i = 0; i < N / 2; i++) {
	res *= 2;
	res %= MOD;
    }
    cout << res << endl;
}

// 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)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4492
fun main(args: Array<String>) {

    val n = readLine()!!.toLong()


    var (i,j) = test(n)

    var ans = ""
    while (true){
       ans =  ('a'+j.toInt()) + ans
        if(i == 0L){
            break
        }
        val p = test(i)
        i = p.first
        j = p.second
    }

    println(ans)
}

fun test(n: Long) = (n-1) / 26 to (n-1 ) % 26



Measured memory_bytes: 34728
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

int main(){
  long N , K;
  std::cin>>N>>K;

  std::vector<long> l;
  double Q = 0;
  for(long i = 1 ; i <= N ; i++ ){
    if(i<K){
      double ln = (double)K/i;
      l.push_back(std::ceil(std::log2(ln)));
    }
    if(i == K){
      Q = (N - K + 1.0) / N;
      break;
    }
  }
  double result = std::accumulate(l.begin(),l.end(),0.0,[](double acc, double i){return acc + std::pow(0.5,i);})/N;
  printf("%.13lf\n",result + Q);
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin >> n;
    ll cnt =0;
    for(ll i=0;i<n;i++){
        ll a,b;
        cin >> a >> b;
        if(a==b){
            cnt++;
            if(cnt==3){
                cout << "Yes";
                return 0;
            }
        }else{
            cnt=0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3632
import sys
import math
sys.setrecursionlimit(1000000)
 
n,d = map(int,input().split())
x = [ [int(i) for i in input().split()] for j in range(n)]

ans = 0
tmp = 0

for i in range(n):
    for j in range(1,n):
        #print(i,j)
        tmp = 0
        if i+j >= n:
            break
        for k in range(d):
            tmp += (x[i][k]-x[i+j][k]) ** 2
        if math.sqrt(tmp).is_integer():
            ans += 1
            
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int N, M, K, ptr[100009]; long long dp[309][100009];
int main() {
	scanf("%d %d %d", &N, &M, &K);
	for (int i = 0; i < N; i++) scanf("%lld", &dp[0][i]);
	for (int i = 1; i < K; i++) {
		int pl = 0, pr = 0;
		for (int j = 0; j < N; j++) {
			if (j >= i) dp[i][j] = dp[i - 1][ptr[pl]] + 1LL * (i + 1) * dp[0][j];
			if (ptr[pl] == j - M) pl++;
			while (pl < pr && dp[i - 1][ptr[pr - 1]] < dp[i - 1][j]) pr--;
			ptr[pr++] = j;
		}
	}
	printf("%lld\n", *max_element(dp[K - 1], dp[K - 1] + N));
	return 0;
}

Measured memory_bytes: 237824
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

const double PI = 2 * acos(0);

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<double, double> pdd;
typedef pair<double, pdd> pddd;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

char buf[105];
ll k;

int main() {
    scanf("%s%lld", buf, &k);
    for(int i = 0; i < strlen(buf); i++) {
        if(buf[i] > '1') {
            printf("%c\n", buf[i]);
            return 0;
        }
        if(i+1 == k) {
            printf("%c\n", buf[i]);
            return 0;
        }
    }
    printf("1\n");
}


Measured memory_bytes: 256
N = int(input())
T, A = input().split()
T = int(T)
A = int(A)

HList = [int(i) for i in input().split()]

score = 99999
position = 1
result = 1
for h in HList :
    avg = T - (h * 0.006)
    if(abs(avg - A) < score) :
        score = abs(avg - A)
        result = position
    position+=1
        
print(result)

Measured memory_bytes: 3064
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))

A.append(A[0])
B.append(B[0])

AX=[]
BX=[]
for i in range(N):
    AX.append(A[i]^A[i+1])
    BX.append(B[i]^B[i+1])

AX+=AX+[AX[0]]

# Rolling Hashで。

p=1<<30
mod=(1<<62)+1 # Hashがぶつからない, pと互いに素な数を適当に指定

A_TABLE=[0] # Rolling Hashのテーブル. 最初は0
B_TABLE=[0] # Rolling Hashのテーブル. 最初は0

for i in range(len(AX)):
    A_TABLE.append((p*A_TABLE[-1]%mod+AX[i])%mod) # テーブルを埋める

for i in range(len(BX)):
    B_TABLE.append((p*B_TABLE[-1]%mod+BX[i])%mod) # テーブルを埋める

def hash(i,j): # [i,j)のハッシュ値を求める
    return (A_TABLE[j]-A_TABLE[i]*pow(p,j-i,mod))%mod

BH=B_TABLE[-1]
ANS=[]
for i in range(N):
    if hash(i,i+N)==BH:
        ANS.append((i,A[i]^B[0]))

for a in ANS:
    print(*a)

Measured memory_bytes: 64956
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <math.h>
#include <map>
#include <time.h>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
    string s;
    cin >> s;
    int ans = 0;
    if(s == "SUN") ans = 7;
    if(s == "MON") ans = 6;
    if(s == "TUE") ans = 5;
    if(s == "WED") ans = 4;
    if(s == "THU") ans = 3;
    if(s == "FRI") ans = 2;
    if(s == "SAT") ans = 1;

    cout << ans << endl;
}


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

struct R{
	int first;
	int second;
	int third;
};

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

	R ar[n];
	for(int i=0;i<n;i++){
		cin>>ar[i].first>>ar[i].second>>ar[i].third;
	}

	R dp[n];
	dp[0] = ar[0];

	for(int i=1;i<n;i++){
		dp[i].first = (ar[i].first + max(dp[i-1].second,dp[i-1].third));
		dp[i].second = (ar[i].second + max(dp[i-1].first,dp[i-1].third));
		dp[i].third=  (ar[i].third + max(dp[i-1].second,dp[i-1].first));
	}
	cout<<max(dp[n-1].first,(max(dp[n-1].second,dp[n-1].third)));
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;

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

	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++)
		cin >> a[i];
	vector<int> dp(N, INF);
	dp[0] = 0;
	for (int i = 1; i < N; i++)
		for (int j = 1; j <= K; j++)
			if (j <= i)
				dp[i] = min(dp[i], dp[i - j] + abs(a[i] - a[i - j]));
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 3924
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

h=n0()

c=1
s=0
while h>0:
    if h>1:
        h=int(h/2)
        s=s+c
        c=c*2
    else:
        h=0
        s=s+c
print(s)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<map>
const int MAX = 100000;

int main(){
    int n;
    std::cin >> n;
    std::map<int, int> mp;
    for(int i = 0; i < n; i++){
        int a;
        std::cin >> a;
        mp[a]++;
    }

    int maxMatch = 0;
    for(int x = 0; x <= MAX; x++){
        // iはいくつになるか
        int match = mp[x - 1] + mp[x] + mp[x + 1];
        maxMatch = std::max(maxMatch, match);
    }

    std::cout << maxMatch << std::endl;
    
    return 0;
}


Measured memory_bytes: 4992
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0];
    const T = arg[1];
    
    for(let i=S.length - T.length; i>=0; i--) {
        let flag = true;
        let sub  = S.substr(i, T.length);
 
        for(let j=0; j<T.length; j++) {
            if(sub.charAt(j) !== T.charAt(j) && sub.charAt(j) !== "?") {
                flag = false;
                break;
            }
        }
        
        if(flag === true) {
            let answer = S.substring(0, i) + T + S.substring(parseInt(i) + T.length);
            answer = answer.replace(/\?/g, "a");
            console.log(answer);
            return;
        }
    }
    
    console.log("UNRESTORABLE");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, t) for(int i = 0; i < t; i++)

int main()
{
    string db[110];
    int H, W;
    cin >> H >> W;
    REP(i, H) cin >> db[i];
    REP(i, H) cout << db[i] << endl << db[i] << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    N, K = map(int, input().split())
    X = list(map(int, input().split()))
    D = [0]*(N - 1)
    for i in range(1, N):
        D[i-1] = X[i] - X[i - 1]
    ans = 0
    t = 0
    T = [0]*(N - K + 1)
    for i in range(1, N):
        t += D[i-1]
        if i < K:
            if i == K - 1:
                T[0] = t
            continue
        t -= D[i - K]
        T[i - K + 1] = t
    # print(D, T)
    ans = K * 10**8
    for i in range(N - K + 1):
        a = T[i] + min(abs(X[i]), abs(X[i + K - 1]))
        ans = min(a, ans)
    print(ans)

if __name__ == '__main__':
    main()


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

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

  if(x == 1 || x == 2 * N - 1){
    cout << "No" << endl;
    return 0;
  }

  int ans[2 * N - 1];
  ans[N - 2] = x - 1;
  ans[N - 1] = x;
  ans[N] = x + 1;

  vector<int> vec;
  for(int i = 1; i < 2 * N; i++){
    if(i != x - 1 && i != x && i != x + 1){
      vec.push_back(i);
    }
  }

  int ind = 0;
  for(int i = 0; i < N - 2; i++){
    ans[i] = vec[ind];
    ind++;
  }
  for(int i = N + 1; i < 2 * N - 1; i++){
    ans[i] = vec[ind];
    ind++;
  }

  cout << "Yes" << endl;
  for(int i = 0; i < 2 * N - 1; i++){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3188
#include <stdio.h>

int main(){
	int a,b,k,i;
	scanf("%d%d%d",&a,&b,&k);
	for(i = 0;i < k;i++){
	if(i % 2 == 0){
		if(a % 2 == 0)
				a = a;
		if(a % 2 != 0)
				a -= 1;
	b += a / 2;
	a -= a / 2;
	}
	if(i % 2 == 1){
	if(b % 2 == 0)
				b = b;
		if(b % 2 != 0)
				b -= 1;
	a += b / 2;
	b -= b / 2;
	}
	}
	printf("%d %d",a,b);
	return 0;
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N, 0);
  for (int i = 1; i < N; i++) {
    int a;
    cin >> a;
    A[a - 1]++;
  }
  for (int i = 0; i < N; i++) {
    cout << A[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4052
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
using ll  = long long;

int main(){
	ll n;
  	cin >> n;
  	ll res = 1;
    ll ans = 1;
  	for(ll i = 0; i < n; i++){
      ll k; cin >> k;
      if(k == 0){ans = 0; break;}
      if(k > 1000000000 && res > 1000000000){res = 0; ans = -1;}
      res *= k;
      //cout << res << endl;
      if(res > 1000000000000000000){res = 0; ans = -1;}
      //cout << ans << endl;
    }
  if(ans == 1){ans = res;}
  cout << ans << endl;
  	
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int si=100;

int main(){
    int a,b; cin >> a >> b;
    char ans[si][si];
    rep(i,si)rep(j,si) ans[i][j]='.';
    bool ok=false;
    for(int i=1; i<si; i=i+2){
        for(int j=1; j<si; j=j+2){
            if(a--==1){
                ok=true;
                break;
            }
            ans[i][j]='#';
            ans[i-1][j]='#';
            ans[i][j-1]='#';
        }
        if(ok) break;
    }
    if(ans[1][1]=='#') b--;
    ok=false;
    for(int i=si-1; i>=0; i=i-2){
        for(int j=0; j<si; j=j+2){
            if(b--==0){
                ok=true;
                break;
            }
            ans[i][j]='#';
        }
        if(ok) break;
    }

    cout << 100 << ' ' << 100 << endl;
    rep(i,si){
        cout << endl;
        rep(j,si){
            printf("%c",ans[i][j]);
        }
    }
return 0;
}



Measured memory_bytes: 3624
#include<iostream>
#include<iomanip>
#include<algorithm>

using namespace std;

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

int main(){
    int H,W;
    cin >> H >> W;
    char C[H][W];
    REP(i,H){
        if(i!=0){
            cout << "\n";
        }
        REP(j,W){
            cin >> C[i][j];
            cout << C[i][j];
        }
        cout << "\n";
        REP(j,W){
            cout << C[i][j];
        }
        if(i!=H){
            cout << "\n";
        }
    }
}

Measured memory_bytes: 256
conv '2' = "hon"
conv '4' = "hon"
conv '5' = "hon"
conv '7' = "hon"
conv '9' = "hon"
conv '0' = "pon"
conv '1' = "pon"
conv '6' = "pon"
conv '8' = "pon"
conv '3' = "bon"
conv _ = "hoge"

main = do
    l <- getLine
    putStrLn (conv (last l))

Measured memory_bytes: 3764
s = gets.chomp

s.gsub!(/BC/, "D")

k = s.split(/[BC]++/)

count = 0
a = 0

k.each{ |str|
  str.length.times{|i|
    if str[i] == "A" then
      a += 1
    elsif str[i] == "D" then
      count += a
    end
  }
  a = 0
}

p count


Measured memory_bytes: 6328
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] h; readA(n, h);

  h ~= 0;
  for (auto i = 0; ; ++i) {
    auto l = h.countUntil!"a>0";
    if (l == -1) {
      writeln(i);
      return;
    }
    auto c = h[l..$].countUntil(0);
    --h[l..l+c];
  }    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cerr << #x << " " << x << endl;
#define debl(x) std::cerr << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
//const ll LINF = 1001002003004005006ll;
//const int INF = 1001001001;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
// constexpr int MOD = 1e9 + 7;
constexpr int mxN = 1e5;
int dp[2][mxN];
void solve(){
    int n, k;
    read(n,k);
    vi a(n);
    REP(i,n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    int smallest = a[0];
    for(int i = 0 ; i < smallest ; i++){
        dp[0][i] = 0;
        dp[1][i] = 0;
    }
    for(int i = smallest ; i <= k ; i++){
        dp[0][i] = 0;
        dp[1][i] = 0;
        for(const auto & move : a){
            if( move <= i){
                if( dp[1][i-move] == 0){
                    dp[0][i] = 1;
                }
                if( dp[0][i-move] == 0){
                    dp[1][i] = 1;
                }
            }
        }
    }
    if( dp[0][k] ){
        cout << "First" << endl;
    }else{
        cout << "Second" << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}



Measured memory_bytes: 4380
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

struct uf
{
    int n;
    vector<int> par, tree_size;

    uf(int size) : n(size), par(), tree_size(size, 1)
    {
        par.reserve(size);
        rep(i, size)
        {
            par.push_back(i);
        }
    }

    int root(int u)
    {
        if (u == par[u])
        {
            return u;
        }
        return par[u] = root(par[u]);
    }

    void unite(int u, int v)
    {
        u = root(u);
        v = root(v);
        if (u == v)
        {
            return;
        }
        par[v] = u;
        tree_size[u] += tree_size[v];
    }

    bool same(int u, int v)
    {
        return root(u) == root(v);
    }

    int component_size(int u)
    {
        u = root(u);
        return tree_size[u];
    }
};

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << fixed << setprecision(15);

    int n, m, k;
    cin >> n >> m >> k;

    vector<int> tomo(n, 0), ans(n, 0);
    uf siriai(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ++tomo[a];
        ++tomo[b];
        siriai.unite(a, b);
    }

    rep(i, n)
    {
        ans[i] = siriai.component_size(i) - 1 - tomo[i];
    }

    rep(i, k)
    {
        int c, d;
        cin >> c >> d;
        --c;
        --d;
        if (siriai.same(c, d))
        {
            --ans[c];
            --ans[d];
        }
    }

    rep(i, n)
    {
        cout << ans[i] << " ";
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 6008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
std::cin >> x;
std::vector<int> v(x);
std::vector<int> vv(x);
rep(i,x){
  std::cin >> v[i];
}
while(1){
  rep(i,x){
    if(v[i]!=vv[i])y++;
  }
  if(y!=0){
    rep(i,x){
      if(v[i]!=vv[i]){
        vv[i]++;
        z++;
      }else{
        if(z!=0){
          break;
        }
      }
    }
    z=0;
    y=0;
  }else{
    std::cout << n << '\n';
    return 0;
  }
  n++;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=nxt();
    vector <int> v(n);
    generate(all(v),nxt);
    int m=nxt();
    int sum=0;
    for(int i=0;i<n;i++)
        sum+=v[i];
    while(m--){
        int p=nxt(),x=nxt();
        cout<<sum-v[p-1]+x<<endl;
    }
    
    
    return 0;   
}




 
 


Measured memory_bytes: 256
def main():
    import math
    import numpy as np
    A, B, H, M = [int(x) for x in input().split()]

    omegaA = 2*math.pi / (60*12)
    omegaB = 2*math.pi / 60
    t = H*60 + M
    thetaA = omegaA*t
    thetaB = omegaB*t

    zA = A * np.exp(1j * thetaA)
    zB = B * np.exp(1j * thetaB)

    print(abs(zA-zB))
 
 
if __name__ == '__main__':
    import sys
    sys.setrecursionlimit(10000)
    main()

Measured memory_bytes: 27124
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	          ll N,A,B;
	          cin >> N >> A >> B;

	          if(A>B){
	        	  cout << 0 << endl;
	        	  return 0;
	          }
	          if(N==1 && A!=B){
	        	  cout << 0 << endl;
	        	  return 0;
	          }

	          cout << B*(N-1)+A-(B+A*(N-1)-1) << endl;

	          return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
int cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        ll a[100010]={1};
        for(int i=0;i<n;++i)
        {
            scanf("%lld",&a[i]);
        }
        sort(a,a+n,cmp);
        int ans1,ans2;
        ans1=ans2=0;
        int flag = 0;
        ll sum = 1;
        for(int i=1;i<n;++i)
        {
            if(a[i] == a[i-1])
            {
                sum*=a[i];
                ++i;
                flag++;
            }
            if(flag == 2)
                break;
        }
        if(sum == 1 && flag != 2)
            printf("0\n");
        else
            printf("%lld\n",sum);
    }
}

Measured memory_bytes: 1024
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nw = readWords { Int($0)! }
    let n = nw[0]
    let w = nw[1]

    let items: [(w: Int, v: Int)] = (1...n).map { _ in 
        let wv = readWords { Int($0)! }
        return (w: wv[0], v: wv[1])    
    }
    var dp: [[Int]] = (0...n).map {_ in [Int](repeating: 0, count: w+1) }

    for i in 0..<n {
        for weight in 0...w {
            if items[i].w <= weight {
                dp[i+1][weight] = max(dp[i][weight-items[i].w] + items[i].v, dp[i][weight])
            } else {
                dp[i+1][weight] = dp[i][weight]
            }
        }
    }

    print(dp[n][w])
}


main()

Measured memory_bytes: 92156
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

struct modint{
    using i64=int_fast64_t;
    i64 a;
    static constexpr i64 MOD=1e9+7;
    modint(){a=0;}
    modint(i64 a_){
        a=a_%MOD;
        if(a<0) a+=MOD;
    }
    modint inv()const{
        i64 n=1,m=MOD-2,A=a;
        while(m){
            if(m&1)(n*=A)%=MOD;
            (A*=A)%=MOD;
            m>>=1;
        }
        modint y;
        y.a=n;
        return y;
    }
    bool operator==(const modint& x){
        return a==x.a;
    }
    bool operator!=(const modint& x){
        return a!=x.a;
    }
    modint& operator=(const modint& x){
        a=x.a;
        return *this;
    }
    modint operator+(const modint& x){
        modint y;
        y.a=a+x.a;
        if(y.a>MOD) y.a-=MOD;
        return y;
    }
    modint operator-(const modint& x){
        modint y;
        y.a=a-x.a;
        if(y.a<0) y.a+=MOD;
        return y;
    }
    modint operator*(const modint& x){
        modint y;
        y.a=(a*x.a)%MOD;
        return y;
    }
    modint operator/(const modint& x){
        modint y;
        y.a=(a*x.inv().a)%MOD;
        return y;
    }
    modint& operator+=(const modint& x){
        a+=x.a;
        if(a>=MOD) a-=MOD;
        return *this;
    }
    modint& operator-=(const modint& x){
        a-=x.a;
        if(a<0) a+=MOD;
        return *this;
    }
    modint& operator*=(const modint& x){
        (a*=x.a)%=MOD;
        return *this;
    }
    modint& operator/=(const modint& x){
        (a*=x.inv().a)%=MOD;
        return *this;
    }
};
istream& operator>>(istream &in,modint& x){
    int_fast64_t a_;
    in>>a_;
    modint y(a_);
    x=y;
    return in;
}
ostream& operator<<(ostream &out,const modint& x){
    out<<x.a;
    return out;
}
modint pwr(int_fast64_t a,int_fast64_t b){
    modint _;
    int_fast64_t n=1,A=a;
    while(b){
        if(b&1) (n*=A)%=modint::MOD;
        (A*=A)%=modint::MOD;
        b>>=1;
    }
    _.a=n;
    return _;
}

modint comb(int n,int r){
    modint ans{1},tmp{1};
    Fr(i,r) ans*=n-i+1,tmp*=i;
    return ans/tmp;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n,a,b;
    in>>n>>a>>b;
    cout<<pwr(2,n)-1-comb(n,a)-comb(n,b)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    bool flag=0;
    string s;int q;
    cin>>s>>q;
    REP(i,q){
        int t;cin>>t;
        if(t==1)flag=!flag;
        if(t==2){
            int f;char c;
            cin>>f>>c;f--;
            if(flag^f)
                s.push_back(c);
            else
                s.insert(s.begin(),c);
        }
    }
    if(flag)
        for(int i=s.size()-1;i>=0;i--)cout<<s[i];
    else
        cout<<s;
    cout<<endl;
}

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


Measured memory_bytes: 912
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll k, s;
    cin >> k >> s;
    ll ans = 0;
    REP(x, k + 1){
        REP(y, k + 1){
            if((s - x - y) >= 0 && (s - x - y) <= k){
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0 ; i < n; i++){
    cin >> h.at(i);
  }
  if(n <= k){
    cout << 0 << endl;
    return 0;
  }
   if(k == 0){
    long long sum = 0;
   for(int i = 0 ; i < n; i++){
     sum += h.at(i);
   }
    cout << sum << endl;
    return 0;
  }
  sort(h.begin(), h.end());
  reverse(h.begin(), h.end());
  for(int i = 0 ; i < k; i++){
    h.at(i) = 0;
  }
  long long hit = 0;
  for(int i = 0 ; i < n; i++){
    if(h.at(i) != 0) hit += h.at(i);
  }
  cout << hit << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n = int(input())
point_set = set()
point_dict1 = {}
point_dict2 = {}
for i in range(n):
    x, y = map(int, input().split())
    point_set.add((x, y))
    point_dict1[x + y] = (x, y)
    point_dict2[y - x] = (x, y)
if len(point_set) == 1:
    print(0)
else:
    min_point1 = min(point_dict1)
    max_point1 = max(point_dict1)
    min_point2 = min(point_dict2)
    max_point2 = max(point_dict2)
    print(max(max_point1 - min_point1, max_point2 - min_point2))


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

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

	rep(i,0,s.size()-8){
		printf("%c",s[i]);
	}printf("\n");
	return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
a = []

for i in range(r):
    a.append(list(map(int, input().split())))
    a[i].append(sum(a[i]))

for i in range(r):
    print(" ".join(list(map(str, a[i]))))

col_sum = []
for j in range(c+1):
    su = 0
    for i in range(r):
        su += a[i][j]
    col_sum.append(su)

print(" ".join(list(map(str, col_sum))))



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

int main() {

	map<int,long long int> freq;
	long long int n,k;
	cin >> n >> k;
	for(int i=0;i<n;i++) {
		int x, f;
		cin >> x >> f;
		freq[x]+=f;
	}
	for(auto p : freq) {
		k-=p.second;
		if(k<=0) {
			cout << p.first << endl;
			return 0;
		}
	}

}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

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

  vector<vector<ll>> g(n);
  for (ll i = 0; i < m; ++i) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  vector<ll> seen(n, -1);
  queue<ll> q;
  q.push(0);
  seen[0] = 0;
  while (!q.empty()) {
    ll pos = q.front();
    q.pop();

    each (v, g[pos]) {
      if (seen[v] >= 0) continue;
      seen[v] = pos;
      q.push(v);
    }
  }

  each (i, seen) {
    if (i == -1) {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
  for (ll i = 1; i < n; ++i) {
    cout << seen[i]+1 << endl;
  }
  
  return 0;
}


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

signed main() {
  int A, B, W;
  cin >> W >> A >> B;
  
  if( (A<=B && B<=A+W) || (A<=B+W && B+W<=A+W) ){
    cout << 0 << endl;
    return 0;
  }else{
    if( B > A+W ) cout << B-(A+W) << endl;
    else if( B+W < A ) cout << A-(B+W) << endl;
  }
  
  
}


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

int main() {
    int n, k, a,p;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a == 1) p = i + 1;
    }
    cout << (n - 2) / (k - 1) + 1 << endl;
}

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

using namespace std;

typedef long long ll;

int main() {
	char c[100];
	c['A'] = 'T';
	c['T'] = 'A';
	c['C'] = 'G';
	c['G'] = 'C';

	char x; cin >> x;
	cout << c[x];

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll _n): num((_n + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


int main(void){
    int Y, X;
    cin >> Y >> X;
    vector<int> max_y(Y+1),max_x(X+1); 
    rep(y,Y) cin >> max_y[y];
    rep(x,X) cin >> max_x[x];
    sort(all(max_y),greater<int>());
    sort(all(max_x),greater<int>());

    modint res = 1;
    int y = 0, x = 0;
    for (int yx = Y*X; yx > 0; yx--) {
        if (max_y[y] == yx && max_x[x] == yx) {
            y++;
            x++;
        } else if (max_y[y] == yx) {
            res *= modint(x);
            y++;
        } else if (max_x[x] == yx) {
            res *= modint(y);
            x++;
        } else {
            res *= modint((x)*(y)-(Y*X-yx));
        }
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(c) (c).begin(),(c).end()
typedef pair<char,int> P;
P c[9];
bool able(vector<int> num){
	rep(i,7){
		if(num[i]){
			num[i]--;
			if(num[i+1]==0 || num[i+2]==0) return false;
			num[i+1]--;
			num[i+2]--;
			i--;
		}
	}
	if(num[7]==0 && num[8]==0) return true;
	else return false;
}
bool ans(char ch){
		vector<int> num(9);
		vector<int> three;
		rep(i,9) if(c[i].first==ch) num[c[i].second]++;
		rep(i,9) if(num[i]>=3) three.push_back(i);
		if(three.size()==3) return true;
		if(three.size()==2){
			vector<int> cop=num;
			if(able(num)) return true;
			num[three[0]]-=3;
			if(able(num)) return true;
			num=cop;
			num[three[1]]-=3;
			if(able(num)) return true;
			num[three[0]]-=3;
			if(able(num)) return true;
			return false;
		}
		if(three.size()==1){
			if(able(num)) return true;
			num[three[0]]-=3;
			if(able(num)) return true;
			return false;
		}
		if(three.size()==0){
			if(able(num)) return true;
			return false;
		}
}
int main(){
	int t;
	cin >> t;
	rep(k,t){
		rep(i,9) cin >> c[i].second;
		rep(i,9) cin >> c[i].first;
		rep(i,9) c[i].second--;
		sort(c,c+9);
		if(ans('R')&&ans('G')&&ans('B')) cout << 1 << endl;
		else cout << 0 << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;
/*

*/
int main()
{
    //連想行列定義
    map<int, long long> mp;
    int temp;
    for(int i = 0 ; i < 3; i++){
        cin >> temp;
        mp[temp]++;
    }
    if(mp[5] == 2&& mp[7]==1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
N = int(input())
A = list(map(int, input().split()))

A.sort()
ans = A.pop()

cnt = N - 2
f = 0
while cnt:
    cnt -= 1
    ans += A[-1]
    if f & 1:
        f = 0
        A.pop()
    else:
        f ^= 1

print(ans)

Measured memory_bytes: 31436
#include<cstdio>
using namespace std;

long n,ans,keta=0,f[10];

int dfs(int a){
    long flag=1,b=0,c=0,fl[3]={};
    for(int i=a-1;i>=0;i--){
        c*=10;
        c+=f[i];
    }
    if(c>n||c<0){
        return 0;
    }
    if(a>=10){
        for(int i=0;i<a;i++){
            if(f[i]==3){
                fl[0]=1;
            }
            else if(f[i]==5){
                fl[1]=1;
            }
            else if(f[i]==7){
                fl[2]=1;
            }
        }
        if(fl[0]&&fl[1]&&fl[2]){
            //printf("%ld\n",c);
            return 1;
        }
        else{
            return 0;
        }
    }
    for(int i=0;i<a;i++){
        if(f[i]==0){
            f[a]=0;
            return dfs(a+1);
        }
    }
    if(a>2){
        f[a]=0;
        b=dfs(a+1);
    }
    f[a]=3;
    b+=dfs(a+1);
    f[a]=5;
    b+=dfs(a+1);
    f[a]=7;
    b+=dfs(a+1);
    return b;
}

int main(){
    scanf("%ld",&n);
    printf("%d\n",dfs(0));
}

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

string s[100000];
unordered_map<string,int> wordcnt;

void Main()
{
  int N;
  cin >> N;
  rep(i,N) {
    cin >> s[i];
    /*
    rep(j, s[i].size()) {
      if (wordcnt[i].find(s[i][j]) == wordcnt[i].end()) wordcnt[i][s[i][j]] = 1;
      else wordcnt[i][s[i][j]]++;
    }
    */
    sort(s[i].begin(), s[i].end());
    if (wordcnt.find(s[i]) == wordcnt.end()) wordcnt[s[i]] = 1;
    else wordcnt[s[i]]++;
  }
  /*
  ll ans = 0;
  rep(i,N) {
   	for (int j = i+1; j < N; j++) {
      if (wordcnt[i] == wordcnt[j]) ans++;
    }
  }
  */
  ll ans = 0;
  for ( auto it = wordcnt.begin(); it != wordcnt.end(); ++it ) {
    ans += (ll)it->second * (ll)(it->second-1) / 2;
  }
  cout << ans << endl;

}

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

Measured memory_bytes: 16036
#include <iostream>
#include <string>
#include <map>
#define V multimap<int,string>::value_type
using namespace std;
int main()
{
  int n,w,l,d;
  string s;
  bool p = false;
  for(;;){
    cin >> n;
    if(n == 0) break;
    if(p) cout << endl;
    multimap<int,string, greater<int> > m;
    while(n--){
      cin >> s >> w >> l >> d;
      m.insert( V(w*3+d*1,s) );
    }
    multimap<int,string>::iterator it = m.begin();
    while(it != m.end()){
      cout << (*it).second << "," << (*it).first << endl;
      it++;
    }
    p = true;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n= Integer.parseInt(sc.next()),k=Integer.parseInt(sc.next());
		double[] e=new double[n];
		double[] res=new double[n];
		double flag=0,sum=0,max=0,buff;
		int count=0;
		for(int i=0;i<n;i++) {
			buff=Integer.parseInt(sc.next());
			e[i]=(0.5*buff*(buff+1))/buff;
			sum+=e[i];
			if(i>=k) {
				sum-=e[count];
				count++;
			}
			max=Math.max(max, sum);
			//System.out.println(sum);
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 63888
n,k = [int(i) for i in input().split()]
s = input()
diff = 0

before = s[0]
for i in range(1,n):
    if before!=s[i]:
        diff += 1
    before = s[i]

diff -= 2*k
diff = max(0,diff) + 1
print(n-diff)


Measured memory_bytes: 3316