akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, l, r) for(int i = (l), i##end = (r);i <= i##end;++i)
using std::cin; using std::cout;
const int maxn = 200200;
typedef long long ll;
const int mod = 998244353;
inline ll pow(ll a,int b,int ans = 1) {
	for(;b;b >>= 1,a = a * a % mod) if(b & 1)
		ans = ans * a % mod;
	return ans;
}
inline ll inverse(int x){ return pow(x, mod - 2); }
char s[maxn]; int len;
int h0[maxn], pw[maxn];
inline int sub(int l,int r) {
	return (h0[r] + ll(mod - pw[r - l + 1]) * h0[l - 1]) % mod;
}
struct T { ll a[26]; };
inline T add(T x, T y) {
	for(int i = 0;i < 26;++i) {
		x.a[i] += y.a[i];
	}
	return x;
}
inline T sub(T x, T y) {
	for(int i = 0;i < 26;++i) {
		x.a[i] -= y.a[i];
	}
	return x;
}
typedef std::string str;
T sum[maxn], empty;
ll size[maxn];
str b;
int ok[maxn];
inline void init(str s0, str s1) {
	s1 = s0 + s1;
	size[1] = s0.size(), size[2] = s1.size();
	for(char i : s0) ++ sum[1].a[i - 'a'];
	for(char i : s1) ++ sum[2].a[i - 'a'];
	ok[1] = ok[2] = 1;
	for(int i = 3;i <= 100;++i) {
		size[i] = size[i - 1] + size[i - 2];
		ok[i] = ok[i - 1] && size[i] <= 2e18;
		sum[i] = add(sum[i - 1], sum[i - 2]);
	}
}
inline T pre(ll x) {
	T ans = empty;
	for(int j = 100;j >= 0;--j) if(ok[j] && x >= size[j]) {
		ans = add(ans, sum[j]);
		x -= size[j], --j;
	}
	for(int j = 1;j <= x;++j) ++ ans.a[s[j] - 'a'];
	return ans;
}
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	*pw = 1;
	for(int i = 1;i < maxn;++i) {
		pw[i] = pw[i - 1] * 233ll % mod;
	}
	cin >> s + 1, len = strlen(s + 1) >> 1;
	for(int i = 1;i <= len;++i) {
		h0[i] = (h0[i - 1] * 233ll + s[i]) % mod;
	}
	int border = len;
	for(int i = 1;i < len;++i) {
		if(sub(1, i) == sub(len - i + 1, len)) {
			border = i;
		}
	}
	if(border << 1 >= len && len % border == 0) {
		init(str(s + 1, s + len + 1), str(s + 1, s + len + 1));
	} else if(border > 0) {
		init(str(s + 1, s + len + 1), str(s + 1, s + len - border + 1));
	}
	ll l, r;
	cin >> l >> r;
	T ans = sub(pre(r), pre(l - 1));
	for(int i = 0;i < 26;++i) {
		cout << ans.a[i] << ' ';
	}
}


Measured memory_bytes: 4096
#include<stdio.h>

int main() {
	int a, b, c, x, cnt, i, j, left;
	scanf("%d%d%d%d", &a, &b, &c, &x);

	cnt = 0;
	for (i = 0; i < a + 1; i++) {
		for (j = 0; j < b + 1; j++) {
			left = x - 500 * i - 100 * j;
			if (left % 50 == 0 && 0 <= left / 50 && left / 50 <= c) cnt++;
		}
	}

	printf("%d", cnt);
	return 0;
}


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

int main(int argc, char const *argv[])
{
	int n,m;
	while(~scanf("%d %d",&n,&m)){
		vector<int> mm;
		int in,num;
		map<int, int> my_map;
		for (int i = 0; i < n; ++i)
		{
			scanf("%d",&num);
			for (int j = 0; j < num; ++j)
			{
				scanf("%d",&in);
				if (my_map[in])
				{
					my_map[in]++;
				}
				else{
					my_map[in]=1;
					mm.push_back(in);
				}
			}
		}
		int ans=0;
		int sz=mm.size();
		for (int i = 0; i < sz; ++i)
		{
			if ( my_map[ mm[i] ] ==n)
			{
				ans++;
			}
		}
		printf("%d\n",ans );

	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
ans = "No"
count = 0
for _ in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        count += 1
    else:
        if count >= 3:
            ans = "Yes"
        count = 0
if count >= 3:
    ans = "Yes"
print(ans)

Measured memory_bytes: 62312
// ------------------------------------
// Date:2018/ 5/ 5
// Problem:// / / c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 55;

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

int H, W;
string S[MAX_N];
bool state[MAX_N][MAX_N];

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

  cin >> H >> W;
  REP(i, H) {
    cin >> S[i];
  }

  REP(hi, H) {
    REP(wi, W) {
      if (state[hi][wi]) continue;
      if (S[hi][wi] == '#') {
	bool ok = false;
	REP(i, 4) {
	  int y = hi + dy[i];
	  int x = wi + dx[i];
	  if (!(0 <= y && y < H and
		0 <= x && x < W)) continue;

	  if (S[y][x] == '#') {
	    ok = true;
	    state[hi][wi] = true;
	    state[y][x] = true;
	  }
	}
      }
    }
  }

  bool ok = true;
  REP(hi, H) {
    REP(wi, W) {
      if (S[hi][wi] == '#' && !state[hi][wi]) {
	ok = false;
      }
    }
  }

  OK(ok);

  return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    long fact(long n){
        return n == 1 ? 1 : n * fact( n-1 );
    }
    long selection(int n){
        if(n==0 || n==1)
            return 0;
        if(n==2)
            return 1;
        else{
            long k=fact(n);
            long l=fact(n-2);
            long m=fact(2);
            long p=k/(l*m);

            return p;
        }
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        int M=sc.nextInt();
        Main ob1=new Main();
//        System.out.println(ob1.selection(N) + ob1.selection(M));
        System.out.println((N*(N-1)+(M*(M-1)))/2);

    }
}


Measured memory_bytes: 23252
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
// typedef vector<int> v;

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //




int main() {
  int n, m ,k;
  int ans = 0;
  cin >> n >> m;
  rep(i, m){
    cin >> k;
    ans += k;
  }
  if (n - ans >= 0) cout << n-ans << endl;
  else cout << "-1" << endl;
}


Measured memory_bytes: 3172
#include <stdio.h>
#include <stdbool.h>

int main(){
    int A,B,i;
    char S[15];
    bool f,e;
  	f = true;
  	e = false;
    scanf("%d%d%s",&A,&B,S);
    for(i=0;i<=A+B;i++)
    {
        if(S[i]=='-')
        {
            e = true;
          	if(i!=A)
            {
                f=false;
                break;
            }
        }
    }
    if(f&&e)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1728
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

bool isPalindrome(string s) {
    int n = s.length();
    for (int i = 0; i < n / 2; i++) if (s[i] != s[n - 1 - i]) return false;
    return true;
}

int main(void) {
    string s;
    cin >> s;
    int n = s.length();
    cout << ((
        isPalindrome(s)
        && isPalindrome(s.substr(0, n / 2))
        && isPalindrome(s.substr(n / 2 + 1, n / 2))
    ) ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#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)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	REP(i, N) cin >> A[i];

	ll res = 0;
	REP(i, N-1){
		res += A[i]/2;
		A[i] %= 2;
		if(A[i]>0 && A[i+1]>0){
			res++;
			A[i]--;A[i+1]--;
		}
	}
	res += A[N-1]/2;
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
from math import gcd

class SegmentTree:
    """Segment Tree

    Attributes:
        n (int):       要素数
        num (int):     n以上の最小の2の累乗
        ide_ele (int): 単位元
            - RmQ(Range Minimum Query): inf
            - RMQ(Range Maximum Query): -1
            - RSQ(Range Sum Query):     0
            - RPQ(Range Product Query): 1
            - RGQ(Range GCD Query):     0
        seg (list):    要素の格納先
    """
    def __init__(self, a):
        """初期化 O(N)
        
        Args:
            a (list): 対象の配列
        """
        self.n = len(a)
        self.num = 2 ** (self.n - 1).bit_length()
        self.ide_ele = 0
        self.seg = [self.ide_ele] * (2*self.num-1)

        for i in range(self.n):
            self.seg[self.num+i-1] = a[i]    
        for i in range(self.num-2, -1, -1) :
            self.seg[i] = self.st_func(self.seg[2*i+1], self.seg[2*i+2])

    def query(self, a, b, k=0, l=0, r=-1):
        """区間クエリの計算 O(logN)

        Args:
            l (int): 区間の左端
            r (int): 区間の右端
        
        Returns:
            int: [l, r)についての区間クエリ
        """
        if r < 0:
            r = self.num
        
        if r <= a or b <= l:
            return self.ide_ele
        elif a <= l and r <= b:
            return self.seg[k]
        else:
            vl = self.query(a, b, 2*k+1, l, (l+r)//2)
            vr = self.query(a, b, 2*k+2, (l+r)//2, r)
            return self.st_func(vl, vr)
        """
        if r <= l:
            return self.ide_ele
        
        l += self.num - 1
        r += self.num - 2
        res = self.ide_ele

        while r - l > 1:
            if l % 2 == 0:
                res = self.st_func(res, self.seg[l])
            if r % 2 == 1:
                res = self.st_func(res, self.seg[r])
                r -= 1
            l = l // 2
            r = (r - 1) // 2
        
        if l == r:
            res = self.st_func(res, self.seg[l])
        else:
            res = self.st_func(res, self.st_func(self.seg[l], self.seg[r]))
        
        return res
        """

    def update(self, i, v):
        """値の更新 O(logN)

        Args:
            i (int): 更新対象のindex
            v (int): 更新値
        """
        i += self.num - 1
        self.seg[i] = v
        while i > 0:
            i = (i - 1) // 2
            self.seg[i] = self.st_func(self.seg[i*2+1], self.seg[i*2+2])
    
    def st_func(self, x, y):
        """問題に応じた処理

        Returns:
            int: 問題に応じた値
                - RmQ(Range Minimum Query): min(x, y)
                - RMQ(Range Maximum Query): max(x, y)
                - RSQ(Range Sum Query):     x + y
                - RPQ(Range Product Query): x * y
                - RGQ(Range GCD Query):     gcd(x, y)
        """
        return gcd(x, y)


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

st = SegmentTree(a)

res = 0
for i in range(n):
    res = max(res, gcd(st.query(0, i), st.query(i+1, n)))

print(res)

Measured memory_bytes: 90516
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
INF = 10**100
r = range

class infix(object):
    def __init__(self, function):
        self.function = function

    def __ror__(self, other):
        self.left = other
        return self

    def __or__(self, other):
        return self.function(self.left, other)

    def __call__(self, value1, value2):
        return self.function(value1, value2)

@infix
def c(f_t_u, f_u_r): return lambda t: f_u_r(f_t_u(t))

class _Ap(object):
    def __rlshift__(self, other):
        self.value = other
        return self

    def __rshift__(self, other):
        return other(self.value)
Ap = _Ap()
ap = Ap

#d = {1:2, 3:5, 6:10, 1000043:3814}
#zip(d.keys(), d.values())<<ap>>(list |c| sorted |c| reversed |c| list |c| print)

n,m=map(int,input().split())
c=dict()
ret=[]
for i in range(m):
    ret+=map(int,input().split())<<ap>>list

for i in range(n):
    print(ret.count(i+1));


Measured memory_bytes: 12504
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int N, a[21][21], mod=1e9+7, dp[22][(1<<21)];
int fun(int n, int mask){
    if(n == N) return 1;
    if(dp[n][mask] != -1) return dp[n][mask];
    int &ret = dp[n][mask]; ret = 0;
    for(int i=0; i<N; i++)
        if(a[n][i] && !(mask & (1<<i))) ret = (ret + fun(n+1, (mask | (1<<i)))) % mod;
    return ret;
}
int main(){
    scanf("%d", &N);
    for(int i=0; i<N; i++)
        for(int j=0; j<N; j++) scanf("%d", &a[i][j]);
    memset(dp, -1, sizeof(dp));
    printf("%d\n", fun(0, 0));
}

Measured memory_bytes: 180480
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    int num;
    cin >> num;
    vector<string> v;
    string tmp;
    for(int i=0;i<num;i++){
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end());
    tmp = v[0];
    int ans = 1;
    for(int i=1;i<num;i++){
        if(v[i]!=tmp){
            ans ++;
            tmp = v[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll> >
#define pq_max priority_queue<ll>
#define forx(i,a,b) for(ll i=0;i<a;i++)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9 + 7;
const ll N = 1e5 + 5;
ll FactNumInv[N+1];
ll NaturalNumInv[N+1];
ll fact[N+1];
 
void InvofNumber(ll p)
{
   NaturalNumInv[0]=1;
   NaturalNumInv[1]=1;
   
   for(ll i=2;i<=N;i++)
   {
   	  NaturalNumInv[i] = (NaturalNumInv[p%i] * (p - p/i) )%p;
   }
} 
 
void InvofFactorial(ll p)
{
	FactNumInv[0]=1;
	FactNumInv[1]=1;
	for(ll i=2;i<=N;i++)
	{
		FactNumInv[i] = (NaturalNumInv[i] * FactNumInv[i-1])%p;
	}
}
 
void factorial(ll p)
{
	fact[0]=1;
	for(ll i=1;i<=N;i++)
	{
		fact[i] = (fact[i-1] * i)%p;
	}
}
 
ll nCrModp(ll n,ll r,ll p)
{
    if ( r == 0 || n == 0) return 1;
    if ( r == 1 ) return n;
	ll ans = ((fact[n] * FactNumInv[r])%p * FactNumInv[n-r])%p;
	return ans;
}
 
 
 
int main()
{
	fast;
    ll n,m;
    cin>>n>>m;
    ll a[n];
    InvofNumber(mod);
    InvofFactorial(mod);
    factorial(mod);
    for(ll i=0;i<n;i++)
    {
    	cin>>a[i];
	}
	sort(a,a+n);
	ll sum=0;
	ll h=n-2;
	ll ans=0,ans2=0;
	ll s=h;
	for(ll i=m-2;i<=h;i++)
	{
		sum = (sum + nCrModp(i,m-2,mod) )%mod;
	}
	ll g=sum;
	for(ll i=n-1;i>=m-1;i--)
	{
		ans = (ans%mod + ((a[i] * sum + mod )%mod) )%mod;
	//	ll d = ;
		sum = (sum -(nCrModp(s,m-2,mod)%mod) + 2*mod)%mod;
		s--;
	}
	//cout<<ans<<" ";
	sum=g%mod;
	s=h;
	for(ll i=0;i<=n-m;i++)
	{
		ans2 = (ans2%mod + (( ((a[i]*sum)%mod) + mod)%mod))%mod;
		sum = (sum - nCrModp(s,m-2,mod) + 2*mod)%mod;
		s--;
	}
	cout<<(ans - ans2 + 2*mod)%mod;
}

Measured memory_bytes: 3328
package main

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

type io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *io {
	return &io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (io *io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *io) nextString() string {
	for io.nextToken >= len(io.tokens) {
		line := io.nextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *io) nextInt() int {
	i, _ := strconv.Atoi(io.nextString())
	return i
}

func main() {
	io := newIo()
	n := io.nextInt()
	m := io.nextInt()

	start := map[int]struct{}{}
	goal := map[int]struct{}{}

	for range make([]struct{}, m) {
		a := io.nextInt()
		b := io.nextInt()

		if a == 1 {
			start[b] = struct{}{}
		}
		if b == n {
			goal[a] = struct{}{}
		}
	}

	for s := range start {
		if _, in := goal[s]; in {
			fmt.Println("POSSIBLE")
			return
		}
	}
	fmt.Println("IMPOSSIBLE")
}


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

void solve(int N, vector<int> A, vector<int> B, vector<int> C)
{
    int res = 0;
    int prev = N;
    for (int i = 0; i < N; i++)
    {
        res += B.at(A.at(i) - 1);
        if (prev + 1 == A.at(i))
            res += C.at(prev - 1);
        prev = A.at(i);
    }
    cout << res << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    vector<int> B(N);
    for(int i = 0; i < N; i++) {
        cin >> B.at(i);
    }
    vector<int> C(N-1);
    for(int i = 0; i < N-1; i++) {
        cin >> C.at(i);
    }
    solve(N, move(A), move(B), move(C));
    return 0;
}


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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)

#define endl "\n"

int main()
{
	faster;

	int a, b, c;
	int k, cnt = 0;
	cin >> a >> b >> c >> k;

	while (b <= a)
	{
		b *= 2;
		cnt++;
	}

	while (c <= b)
	{
		c *= 2;
		cnt++;
	}

	cout << ((cnt <= k) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
  int n,i,j,tmp,ans=0;
  int d[102]={0};

  cin >> n;

  for(i=0;i<n;i++)
    cin >> d[i];

  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(d[j]>d[j-1]){
	tmp = d[j];
	d[j] = d[j-1];
	d[j-1] = tmp;
      }
    }
  }
  i=0;

  while(d[i]){
    if(d[i]!=d[i+1])ans++;
    i++;
  }
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
int main() {
    ll N, K, a, b;
    map<ll, ll> m;
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        auto itr = m.find(a);
        if (itr == m.end()) m[a] = b;
        else m[a] += b;
    }
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
        K -= itr->second;
        if (K <= 0) {
            cout << itr->first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4224
N = int(input())
A = list(map(int, input().split()))
B = [A[0]]
for i in range(1,N):
  A[i] += A[i-1]

th = min(0, A[0]-1)
ans_pos = abs(th) #正スタート
for i in range(1,N):
  if i % 2 == 1: #負にしたい
    ans_pos += abs(th - max(th, A[i]+1))
    th = max(th, A[i]+1)
  else: #正にしたい
    ans_pos += abs(th - min(th, A[i]-1))
    th = min(th, A[i]-1)
  #print(ans_pos, th, i)

th = max(0, A[0]+1)
ans_neg = abs(th) #負スタート
for i in range(1,N):
  if i % 2 == 1: #正にしたい
    ans_neg += abs(th - min(th, A[i]-1))
    th = min(th, A[i]-1)
  else: #負にしたい
    ans_neg += abs(th - max(th, A[i]+1))
    th = max(th, A[i]+1)
  #print(ans_neg, th, i)

print(min(ans_pos, ans_neg))

Measured memory_bytes: 20168
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a, b) a = (((a)<(b))?(b):(a))

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}


signed main(){
  ll n; cin>>n;
  VL a(n); rep(i,n) cin>>a[i];
  ll ans = 0;
  // int idx = -1;
  // int last = 0;
  pair<ll,ll> tmp;
  tmp = MP(-1,0);
  rep(i,n){
    ll now = a[i];
    if(now==0){
      tmp.first = i; tmp.second = 0;
      continue;
    }
    // if(last){
    //   ans+=(now+1)/2;
    //   last = now%2;
    // else ans += now/2;
    if(tmp.first+1==i) now+=tmp.second;
    ans += now/2;
    tmp.second = now%2;
    // if(now%2) tmp.second = 1-tmp.second;
    // tmp.second = (now%2)-(tmp.second%2);
    tmp.first = i;
    cerr << i SP tmp.second SP ans << endl;
    // ans += a[i]/2;
    // a[i] %= 2;
  }
  // rep(i,n-1){
  //   if(a[i]==1&&a[i+1]==1){
  //     ans++; a[i+1]--;
  //   }
  // }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i < (int)(n+1); i++)
int main() {
    ll N,K;
    cin>>N>>K;
    ll ans=1;
    rep(i,N){
        if(i==0){
            ans*=K;
        }
        else {
          ans*=K-1;
        }
    }
    cout<<ans<<endl;
}

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

class Dice {
public:
  int face[7];

  void roll(int p) {
    int w;
    if (p == 1) {
      w = face[1]; face[1] = face[2]; face[2] = face[6]; face[6] = face[5]; face[5] = w;
    } else if (p == 2) {
      w = face[1]; face[1] = face[4]; face[4] = face[6]; face[6] = face[3]; face[3] = w;
    } else {
      w = face[2]; face[2] = face[3]; face[3] = face[5]; face[5] = face[4]; face[4] = w;
    }
  }

  void print_right(int t, int f) {
    find_top(t);
    find_front(f);
    cout << face[3] << endl;
  }

  void find_top(int t) {
    if (face[1] == t) return;
    for (int i = 0; i < 3; i++) {
      roll(1);
      if (face[1] == t) return;
    }
    for (int i = 0; i < 3; i++) {
      roll(2);
      if (face[1] == t) return;
    }
  }

  void find_front(int f) {
    if (face[2] == f) return;
    for (int i = 0; i < 3; i++) {
      roll(3);
      if (face[2] == f) return;  
    }    
  }
};

int main() {
  Dice dice;
  for (int i = 1; i <= 6; i++) cin >> dice.face[i];

  int q;
  cin >> q;
  int top, front;
  for (int i = 0; i < q; i++) {
    cin >> top >> front;
    dice.print_right(top, front);
  }
  
  return 0;
}


Measured memory_bytes: 3100
import copy
k = int(input())
tmp = [1, 2, 3, 4, 5, 6, 7, 8, 9]
tmp2 = []
if k <= 9:
    print(tmp[k - 1])
    exit()
cnt = 9
while True:
    for t in tmp:
        for i in range(10):
            if abs(int(str(t)[-1]) - i) <= 1:
                tmp2.append(t * 10 + i)
                cnt += 1
                if k == cnt:
                    print(t * 10 + i)
                    exit()
    tmp = copy.copy(tmp2)
    tmp2 = []

Measured memory_bytes: 6940
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        while True:
            s = raw_input()
            if s == '#':
                break
            angle = 0
            count = 0
            while s:
                if count == 0:
                    if s.endswith('north'):
                        angle = 0
                        s = s[:-5]
                    elif s.endswith('west'):
                        angle = 90
                        s = s[:-4]
                else:
                    if s.endswith('north'):
                        angle -= 90.0 / 2 ** count
                        s = s[:-5]
                    elif s.endswith('west'):
                        angle += 90.0 / 2 ** count
                        s = s[:-4]                
                count += 1
            denom = 1
            while angle != int(angle):
                angle *= 2
                denom *= 2
            if denom == 1:
                print int(angle)
            else:
                print '/'.join(map(str, [int(angle), denom]))

                
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4672
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> m(n);
  int count = 0;
  int i;
  for (i = 0; i < n; i++) {
    cin >> m[i];
    x -= m[i];
    count++;
  }
  sort(m.begin(), m.end());
  count += x / m[0];
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <iomanip>

float check(float f) {
	return f == 0 ? 0 : f;
}

int main() {
	float a, b, c, d, e, f;
	while (std::cin >> a >> b >> c >> d >> e >> f) {
		float
			x = (c * e - b * f) / (a * e - b * d),
			y = (c * d - a * f) / (b * d - a * e);

		std::cout
			<< std::fixed << std::setprecision(3) << check(x)
			<< " "
			<< std::fixed << std::setprecision(3) << check(y)
			<< std::endl;

	}
}

Measured memory_bytes: 1280
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}


bool kai(ll A, ll B, ll T,ll N,vector<ll> H) {
	ll an = 0;
	rep(i, N) {
		if (H[i] > B * T) {
			an += max(((H[i] - B * T - 1) / (A - B)) + 1, ll(0));
		}
	}
	if (an <= T) return true;
	else return false;
}

bool isOK(ll A, ll B, ll T, ll N, vector<ll> H) {
	if (kai(A,B,T,N,H)) return true;
	else return false;
}


ll binary_search(ll A,ll B,ll N, vector<ll> H) {
	int left = 0; 
	int right = 1e13; 
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(A,B,mid,N, H)) right = mid;
		else left = mid;
	}

	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	vector<ll> H(N);
	rep(i, N) {
		cin >> H[i];
	}
	
	cout << binary_search(A, B, N, H) << endl;
}


Measured memory_bytes: 6404
import Control.Applicative
import Control.Monad
import Data.List
import Data.Char
import Data.Maybe
strToInt s = (read :: String -> Int) s
strToInteger s = (read :: String -> Integer) s
strToDouble s = (read :: String -> Double) s

main :: IO ()
main = do
    -- スペース区切り整数の入力
    [n, k] <- map strToInt . words <$> getLine
    -- 出力
    putStrLn $ show $ k * ((k-1) ^ (n-1))


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a, b;
    cin >> a >> b;
    if (a == b) yn;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using P = pair<int,int>;
using node = pair<string,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

int main(void) {
  ll k,a,b;
  cin >> k >> a >> b;
  if(k <= a-1 || b-a <= 2){
    cout << k+1 << endl;
  } else {
    ll rest = k - a + 1;
    ll exchange = rest / 2;
    ll hit = rest - exchange*2;
    cout << a + exchange*(b-a) + hit << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vector<int>> mat;

int N;
ll A,B,ans;
vec h(100010);
struct Binary_Search{

    bool b(ll t){
        ll count=0;
        for(int i=0;i<N;i++){
            ll H=h[i];
            H-=(ll)B*(ll)t;
            if(H>0){
                if(H%(A-B)==0) count+=H/(A-B);
                else           count+=H/(A-B)+1;
            }
        }
        return count<=t;
    }

    void bs(ll s,ll t){
        if(t-s==1){
            ans=t;
            return;
        }
        ll r=s+(t-s)/2;
        if(b(r)) bs(s,r);
        else     bs(r,t);

        return;
    }
};

int main(){
    cin>>N>>A>>B;
    for(int i=0;i<N;i++)cin>>h[i];
    Binary_Search BS;
    BS.bs(0,1000000000);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    int a = n/1000;
    int b = (a+1)*1000;
    int c = b-n;
    c%=1000;
    cout << c << "\n";
    return 0;
}


Measured memory_bytes: 3640
package main

import "fmt"

func main() {
	var s, t, u string
	var a, b int

	fmt.Scan(&s, &t)
	fmt.Scan(&a, &b)
	fmt.Scan(&u)

	if u == s {
		fmt.Println(a-1, b)
	} else {
		fmt.Println(a, b-1)
	}
}


Measured memory_bytes: 512
//
//  main.cpp
//  contest
//
//  Created by TmpGuest on 2020/4/18.
//  Copyright © 2020 TmpGuest. All rights reserved.
//

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
ios_base::sync_with_stdio(false);
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int ans=0;
    if(a>=k)
        cout<<k<<endl;
    else {
        ans=a;
        k-=a;
        if(b>=k)
            cout<<ans<<endl;
        else {
            k-=b;
            cout<<ans-k<<endl;
        }
    }
    
    
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mod 1000000007
int main() 
{
    ll n;
    cin>>n;
    map<ll,ll>mp;
    for(ll i=0;i<n-1;i++)
    {
        ll x;
        cin>>x;
        mp[x]++;
    }
    for(int i=1;i<=n;i++)
    {
        cout<<mp[i]<<endl;
    }
}


Measured memory_bytes: 16132
// Why I am so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int a, b, c, d, n;

void solve() {                   
	scanf("%d %d %d %d", &a, &b, &c, &d);
	scanf("%d", &n);

    int c025 = a;
    int c05 = min(b, c025 * 2);
    int c1 = min(c, c05 * 2);
    int c2 = min(d, c1 * 2);

    printf("%lld\n", c2 * 1ll * (n / 2) + c1 * 1ll * (n % 2));
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 256
def main():
    import sys

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

    k,t = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    ans = max(a[0]-1-sum(a[1:]),0)
    print(ans)

    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9188
process.stdin.resume();
process.stdin.setEncoding("utf8");
process.stdin.on("data", (input) => {
    const analyzed = analyzeInput(input);
    const result = getResult(analyzed.K, analyzed.Pk);

    console.log(result);
});

const analyzeInput = (input) => {
  const lines = input.split("\n");
  const line1 = lines[0].split(" ");
  const line2 = lines[1].split(" ");

  const N = line1[0];
  const K = line1[1];

  const pk = line2.map(num => Number(num));

  return {
    N: N,
    K: K,
    Pk: pk,
  };
};

const getResult = (k, pk) => {
  pk.sort((p1, p2) => {
    if (p1 > p2) return 1;
    if (p1 < p2) return -1;
    return 0;
  });

  const sum = pk.slice(0, k).reduce((total, curr) => {
    return total + curr;
  }, 0);

  return sum;
};




Measured memory_bytes: 30032
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;

int main() {
  
  int a,b,c,d;
  string s,ss;
  long long ans = 0;
  
  cin >> s >> ss;

  if(s == "H" && ss == "H" || s == "D" && ss == "D") s = "H";
  else s = "D";
  
  cout << s << endl;

}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll cnt = 0;
  rep(i,n) if(v[i]<0) cnt++;
  ll ans = 0;
  if(cnt%2==0) rep(i,n) ans+=abs(v[i]);
  else {
    ll minus = INF;
    rep(i,n)  minch(minus,abs(v[i]));
    rep(i,n) ans+=abs(v[i]);
    ans  = ans - 2 * abs(minus);
   }
cout<<ans<<endl;
}
int main(){
  solve();
  return 0;
}


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

#ifdef LOCAL
#include "../dump.hpp"
#else
#define dump(...)
#endif

using namespace std;

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;i++)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;i++)
#define ROF(i,a,b) for(int i=(a)-1,i##_cond=(b);i>=i##_cond;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((int)(x).size())
#define pb push_back
#define fst first
#define snd second

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

int main(){
  ll a,b,k; cin >> a >> b >> k;
  if(b - a + 1 < 2 * k){
    FOR(i,a,b+1) cout << i << endl;
  }else{
    FOR(i,a,a+k) cout << i << endl;
    FOR(i,b-k+1,b+1) cout << i << endl;
  } 
}

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

public class Program
{
    public static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ');
        var N = int.Parse(input[0]);
        var K = int.Parse(input[1]);
        Console.WriteLine(Math.Floor(Math.Log10(N) / Math.Log10(K)) + 1);
    }
}


Measured memory_bytes: 11092
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
  ans=ans*a[i]//fractions.gcd(ans,a[i])
check=0
for i in range(n):
  check+=(ans-1)%a[i]
print(check)

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    int ans = 0;
    string st;
    cin >> st;
    
    int p = 0;
    Rep(i, st.size()) {
        if (st[i] != st[p]) {
            p = i;
            ans++;
        }
    }

    cout << ans + 1 << endl;

    return 0;
}


Measured memory_bytes: 512
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.chomp
N_=N.split("").reverse.join("")
if N==N_
    puts "Yes"
else
    puts "No"
end



Measured memory_bytes: 1788
n = int(input())
ta = [[int(i) for i in input().split()] for j in range(n)]

t = ta[0][0]
a = ta[0][1]

for i in range(1,n):
    mag = max((t+ta[i][0]-1)//ta[i][0],(a+ta[i][1]-1)//ta[i][1])
    t = mag*ta[i][0]
    a = mag*ta[i][1]
    #print(t,a,mag)
    
print(t+a)

Measured memory_bytes: 3188
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <vector>
using namespace std;
typedef long long LL;
const LL N = 300005;
const LL MOD = 1000000007;

struct node{
	LL l,r;
}s[N],t[N];
bool cmp(node x,node y){
	return (x.l == y.l ? x.r > y.r : x.l < y.l);    
}

LL n;
struct BIT{
	LL tr[N << 1];
	LL lowbit(LL x){ return (x & (-x)); }
	void modify(LL x,LL v){ for(;x <= n + 1;x += lowbit(x)) tr[x] += v; }
	LL query(LL x){ LL ret = 0; if(!x) return 0; for(;x;x -= lowbit(x)) ret += tr[x]; return ret; }
}b;

LL pr[N],p[N],sr[N];
LL dp[N];
map <LL,LL> mp;

int main(){
	ios::sync_with_stdio(false);
	LL m,u,v,tl,tr,ct = 0;
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++) cin >> pr[i];
	for(LL i = 1;i <= m;i ++) cin >> p[i];
	
	for(LL i = 1;i <= n;i ++){
		if(pr[i] < p[1] || pr[i] > p[m]) continue;
		tl = lower_bound(p + 1,p + 1 + m,pr[i]) - p - 1;
		tr = lower_bound(p + 1,p + 1 + m,pr[i]) - p;
		s[i].l = pr[i] - p[tl]; s[i].r = p[tr] - pr[i];
	}
	sort(s + 1,s + 1 + n,cmp);
	for(LL i = 1;i <= n;i ++){
		if(s[i].l != s[i - 1].l || s[i].r != s[i - 1].r) t[++ ct] = s[i];
	} n = ct; ct = 0;
	for(LL i = 1;i <= n;i ++) sr[i] = t[i].r;
	sort(sr + 1,sr + 1 + n);
	for(LL i = 1;i <= n;i ++) if(mp.find(sr[i]) == mp.end()) mp[sr[i]] = ++ ct;
	for(LL i = 1;i <= n;i ++) t[i].r = mp[t[i].r];
	
	dp[0] = 1; t[0].l = t[0].r = 0; t[n + 1].l = t[n + 1].r = n + 1;
	for(LL i = 1;i <= n + 1;i ++){
//		cout << t[i].l << ' ' << t[i].r << endl;
		dp[i] = 1 + b.query(t[i].r - 1); dp[i] %= MOD;
		b.modify(t[i].r,dp[i]);
	}
	cout << dp[n + 1] << '\n';
	return 0;
}

Measured memory_bytes: 21504
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	double pi = 3.14159265358979;
	double r;
	cin >> r;
	cout << fixed << setprecision(6);
	cout << pi*r*r << " " << 2 * pi*r << endl;
	return 0;
}

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

namespace AOJ
{
    class Program
    {
        struct D { public int Price { get; set; } public int Amount { get; set; } }
        static IEnumerable<D> Read()
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                var s = line.Split(',').Select(int.Parse).ToArray();
                yield return new D {Price = s[0], Amount = s[1]};
            }
        }

        static void Main(string[] args)
        {
            var d = Read().ToArray();
            Console.WriteLine(d.Sum(x => x.Price * x.Amount));
            Console.WriteLine((int)Math.Floor(d.Average(x => (double)x.Amount) + 0.5));
        }
    }
}

Measured memory_bytes: 5976
//shara's here
//私は大きな男の子
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
//fold
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define vl vector<ll>
#define vll vector<vector<ll> >
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
//endfold
int main(){
    ll n,k,sum=0;
    cin>>n>>k;
    vl v(n);
    for(ll i=0;i<n;i++)cin>>v[i];
    sort(v.begin(),v.end());
    for(ll i=n-1;i>=0;i--){
	sum+=v[i];
	k--;
	if(k==0)break;	
	}
	cout<<sum<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
N,K= [int(x) for x in input().split()]
count = [0] * (N+1)
for i in range(K):
    d = int(input())
    l = [int(x) for x in input().split()]
    for j in range(d):
        count[l[j]] = 1
print(count.count(0)-1)

Measured memory_bytes: 9204
/*
[agc027] A - Candy Distribution Again
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 100;

int N, x;
int a[MAX_N];

ll solve() {
    sort(a, a + N);
    ll s = 0;
    for (int i = 0; i < N; i++) {
        s += a[i];
        if (s > x) {
            return i;
        }
    }
    return (s == x ? N : (N - 1));
}

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

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 256