akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define each(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

int n, d[100][100];

int main(){
	cin >> n;
	rep(i, n) rep(j, n) cin >> d[i][j];
	ll ans = 0;
	rep(i, n) rep(j, i) ans += min(d[i][j], d[j][i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(k == 0)  return 1;
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

// the number of ways to choose x_i and x_j so that their difference be d
// is (n-d)*m*m.
// the number of ways to choose n*m-2 cells other than the fixed two 
// is  {n*m-2}C{k-2}.

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

    ModComb mc(n*m+2);
    ll tmp = mc.nCk(n*m-2, k-2);

    ll ans = 0;
    
    // x-axis
    for(ll d = 1; d < n; d++){
        ans += d*(n-d)*m%mod*m%mod*tmp%mod;
        ans %= mod;
    }

    // y-axis
    for(ll d = 1; d < m; d++){
        ans += d*(m-d)*n%mod*n%mod*tmp%mod;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
import Control.Monad
import Data.List
import Data.Bits
import Debug.Trace
import Data.Maybe
import qualified Data.ByteString.Char8 as C

main :: IO ()
main = do
  [a, b, x] <- readIntegers
  print $ solve a b x

solve :: Integer -> Integer -> Integer -> Integer
solve a b x = qb - qa
  where
    qa = a `div` x + (if a `mod` x == 0 then 0 else 1)
    qb = b `div` x + 1

-- 以下ライブラリ

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

readNInts :: Int -> IO [[Int]]
readNInts = flip replicateM readInts

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . C.readInteger) . C.words <$> C.getLine

readNIntegers :: Int -> IO [[Integer]]
readNIntegers = flip replicateM readIntegers

getNLns :: Int -> IO [String]
getNLns = flip replicateM getLine

toTup2 :: [[a]] -> [(a, a)]
toTup2 = map (\ys -> case ys of y : z : zs -> (y, z))

encIdx2 :: Int -> (Int, Int) -> Int
encIdx2 mx (y, x) = y * mx + x

decIdx2 :: Int -> Int -> (Int, Int)
decIdx2 mx idx = (idx `div` mx, idx `mod` mx)

encIdx3 :: (Int, Int) -> (Int, Int, Int) -> Int
encIdx3 (my, mx) (z, y, x) = z * my * mx + y * mx + x

decIdx3 :: (Int, Int) -> Int -> (Int, Int, Int)
decIdx3 (my, mx) idx = (z, y, x)
  where
    basez = my * mx
    z = idx `div` basez
    y = (idx `mod` basez) `div` mx
    x = idx `mod` mx

while :: Monad m => m Bool -> m () -> m ()
while cond body = do
  b <- cond
  when b $ do
    body
    while cond body


Measured memory_bytes: 380
// abc141_a
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N;
    cin >> N;
    
    print(N*N*N);

    return 0;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#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
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int a, b, c;
    cin >> a >> b >> c;
    if(a>b) swap(a,b);
    if(b>c) swap(b,c);
    int sum = 3*c - (a+b+c);
    if(sum%2) sum += 3;
    cout << sum / 2 << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#define LEN 100005
using namespace std;

typedef struct {
char name[100];
int t;
} P;

P Q[LEN];
int head;
int tail;
int n;

void enqueue(P x) {
    Q[tail]=x;
    tail=(tail+1)%LEN;
}
P dequeue() {
    P x=Q[head];
    head=(head+1)%LEN;
    return x;
}
int min(int a,int b) {
    return (a<b?a:b);
}
int main() {
    int elaps=0;
    int c, q;
    P u;
    cin >> n >> q;
    for (int i=1; i<=n; i++) {
        cin >> Q[i].name >> Q[i].t;
    }
    head=1;
    tail=n+1;
    while (head!=tail) {
        u=dequeue();
        c=min(q,u.t);
        u.t-=c;
        elaps+=c;
        if (u.t>0) {
            enqueue(u);
        } else {
            printf("%s %d\n",u.name,elaps);
        }
    }
    return 0;
}

Measured memory_bytes: 13352
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
long long int X,K,D;
long long int ans=0;
int main(){
	cin >> X >> K >> D;
	X=abs(X);
	long long int divide = X/D;
	long long int amari = X%D;
	if(K>divide){
		K=K-divide;
		X=amari;
		if(K%2 == 0){
			ans = X;
		}
		else{
			ans = abs(X-D);

		}
	}
	else{
		ans=X-(K*D);
		ans=abs(ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640
// ARC100
// E - Or Plus Max

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 18;
const int MAX_K = (1 << MAX_N);

class Elm {
public:
    int x[2];
    Elm() { x[0] = x[1] = 0; };
    Elm(int x0, int x1) {
        x[0] = x0;
        x[1] = x1;
    };
    Elm operator+=(Elm e) {
        int tmp[4] = {x[1], x[0], e.x[1], e.x[0]};
        sort(tmp, tmp + 4);
        x[0] = tmp[3];
        x[1] = tmp[2];
        return *this;
    };
    int sum() { return x[0] + x[1]; };
};

vector<Elm> moebius(vector<Elm> f) {
    // get F(S) = \sum_{T \in S} G(T)
    for (int b = 1; b < (int)f.size(); b <<= 1) {
        for (int i = 0; i < (int)f.size(); i++) {
            if (i & b) {
                f[i] += f[i ^ b];
            }
        }
    }
    return f;
}

int N;

int main() {
    cin >> N;

    vector<Elm> f(MAX_K);
    for (int i = 0; i < (1 << N); i++) {
        int a;
        cin >> a;
        f[i].x[0] = a;
    }
    vector<Elm> g = moebius(f);

    int ans = -1;
    for (int i = 1; i < (1 << N); i++) {
        ans = max(ans, g[i].sum());
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 7296
package main

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

type NumSortA struct {
	A      int
	B      int
	IsPair bool
}

type NumAs []NumSortA

func (n NumAs) Len() int {
	return len(n)
}

func (n NumAs) Swap(i, j int) {
	n[i], n[j] = n[j], n[i]
}

func (n NumAs) Less(i, j int) bool {
	return n[i].B > n[j].B
}

type NumSortB struct {
	A      int
	B      int
	IsPair bool
}

type NumBs []NumSortB

func (n NumBs) Len() int {
	return len(n)
}

func (n NumBs) Swap(i, j int) {
	n[i], n[j] = n[j], n[i]
}

func (n NumBs) Less(i, j int) bool {
	return n[i].A < n[j].A
}

func main() {
	s := IOInitialize()
	N := Int(s)
	reds := scanNumAs(s, N)
	sort.Sort(reds)
	blues := scanNumBs(s, N)
	sort.Sort(blues)
	cnt := 0
	for _, blue := range blues {
		for i, red := range reds {
			if blue.A > red.A && blue.B > red.B && !red.IsPair {
				cnt++
				reds[i].IsPair = true
				break
			}
		}
	}
	fmt.Println(cnt)
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

func scanNumAs(s *bufio.Scanner, len int) (numAs NumAs) {
	for i := 0; i < len; i++ {
		numA := Int(s)
		numB := Int(s)
		numAs = append(numAs, NumSortA{A: numA, B: numB, IsPair: false})
	}
	return
}

func scanNumBs(s *bufio.Scanner, len int) (numBs NumBs) {
	for i := 0; i < len; i++ {
		numA := Int(s)
		numB := Int(s)
		numBs = append(numBs, NumSortB{A: numA, B: numB, IsPair: false})
	}
	return
}


Measured memory_bytes: 640
#include <stdio.h>

#define MAX 101
void bubbleSort(int A[],int);

int main(void){
	int A[MAX],i,j,n;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	bubbleSort(A,n);
	return 0;
}

void bubbleSort(int A[],int n){
	int i,j,a,tmp,count=0;
	
	for(i=0;i<n;i++){
		for(j=n-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				tmp=A[j];
				A[j]=A[j-1];
				A[j-1]=tmp;
				count++;
			}
		}
	}
	for(a=0;a<n;a++){
	printf("%d",A[a]);
	if(a!=n-1)printf(" ");
	}
	printf("\n%d\n",count);
}

Measured memory_bytes: 604
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))


N, K = mi()

cnt = 0
for b in range(K+1, N+1):
    #print(cnt)
    for x in range((N-K)//b+1):
        #print('a', min(N-(b*x+K), b-K))
        if b*x+K == 0:
            cnt -= 1
        cnt += min(N-(b*x+K)+1, b-K)
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define ld long double


int main(){

ll n,y;
cin>>n>>y;

for(ll i=0;i<=n;i++){
    for(ll j=0;j<=n;j++){
        if(i+j>n)
        continue;
        ll k= n-(i+j);
        if(i*10000 + j*5000+ k*1000==y){
            cout<<i<<" "<<j<<" "<<k<<endl;
            return 0;
        }
    }
}cout<<-1<<" "<<-1<<" "<<-1;
}

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

int a[1000010], n;

bool binarysearch(int key)
{
    int left = 0;
    int right = n;
    int mid;
    while(left < right)
    {
        mid = (left + right) / 2;
        if(key == a[mid])
        {
            return true;
        }
        else if(key < a[mid])
        {
            right = mid;
        }
        else
        {
            left = mid + 1;
        }
    }

    return false;
}

int main()
{
    int i, q, k, sum=0;
    scanf("%d", &n);
    for(i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }

    sort(a, a + n);

    scanf("%d", &q);
    for(i = 0; i < q; i++)
    {
        scanf("%d", &k);
        if(binarysearch(k))
        {
            sum++;
        }
    }

    printf("%d\n", sum);

    return 0;
}



Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

char s[200010];
char t[200010];
ll sc[30];
ll tc[30];

int main(){
	scanf("%s%s",s,t);
	int n=strlen(s);
	for(int i=0;i<n;i++){
		sc[s[i]-'a']++;
		tc[t[i]-'a']++;
	}
	sortup(sc,26);
	sortup(tc,26);
	int flag=1;
	for(int i=0;i<26;i++)flag&=sc[i]==tc[i];
	puts(flag?"Yes":"No");
}

Measured memory_bytes: 512
#表計算を行うプログラムを作成。

r,c=gets.split(" ").map(&:to_i)
h = Array.new(r+1).map{Array.new(c+1,0)} 

for i in 0..r-1                                       # 変数 i を1からr-1まで増やして繰り返し処理する。(arrayゼロから始めるから)
    
a= gets.split.map(&:to_i)
    for j in 0..c-1                                   # 変数 i を0からc-1回まで増やして繰り返し処理する。
    h[i][j] =  a[j]                                   # array のループひとつづつ足していく
    h[i][c] += a[j]
    h[r][j] += a[j]
    h[r][c] += a[j]
    end
end
for i in 0..r                                       #本ループをくりかえす   row 
    for j in 0..c                                   #本ループをくりかえす   column
      print " " unless j == 0
      print h[i][j]                                 #全体結果
    end
    puts                                            #段落あける
  end




Measured memory_bytes: 7040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner =new Scanner(System.in);
		long num = Long.parseLong(scanner.nextLine());
		scanner.close();

		long numsPiv = (long)Math.sqrt(num);
      
      	int min = 100;
      
		for (long i = 1; i <= numsPiv; i++) {
          	int aLen = 0;
          	int bLen = 0;
          	long a = 0;
           long b = 0;
			if (num % i == 0) {
              a = i;
              b = num / i;
              while(a > 0){
                a = a / 10;
				aLen++;
              }
              
              while(b > 0){
                b = b / 10;
				bLen++;
              }
              if(aLen >= bLen && min > aLen){
                min = aLen;
			}else if(aLen < bLen && min > bLen){
                min = bLen;
              }
		}
	}
      System.out.println(min);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <bitset>
#include <stack>
#include <regex>

#define mod 1000000007
#define INF2 9999999999
#define INF (1 << 30)
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define P pair<int, int>

using namespace std;
using ll = int64_t;

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

void solve(){
    int n, l[11];
    cin >> n;
    int max = 0, sum = 0;
    rep(i, n){
        cin >> l[i];
        if(max < l[i]){
            max = l[i];
        }
        sum += l[i];
    }
    if(max < sum-max){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

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

int main(){
    cpp_dec_float_100 a, b, c;
    cin >> a >> b >> c;
    cout << (sqrt(a) + sqrt(b) < sqrt(c) ? "Yes": "No") << endl;
}

Measured memory_bytes: 384
x = input()

ans = 0
s_cnt = 0

for i in range(len(x)):
    if s_cnt == 0:
        if x[i] == 'T':
            ans += 1
        else:
            s_cnt += 1
    else:
        if x[i] == 'T':
            s_cnt -= 1
        else:
            s_cnt += 1

if s_cnt > 0:
    ans += s_cnt

print(ans)


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

#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  string s;
  while(cin>>s){
    int cnt[128];
    memset(cnt,0,sizeof(cnt));
    rep(i,s.length()){
      cnt[s[i]]++;
    }
    cout<<min(min(cnt['K'],cnt['U']),min(cnt['P'],cnt['C']))<<endl;
  }
}

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

const int MAXN = 100000;

int BobEven(int n, int *A) {
    int M = n / 2;
    int res = INT_MAX;
    for(int i = 1; i <= M; i++)
        res = min(res, A[M+i]-A[i]);
    return res;
}

int AliceOdd(int n, int *A) {
    int M = n / 2;
    for(int i = M + 1; i < n; i++) A[i] = A[i + 1];
    return BobEven(n - 1, A);
}
bool check(int n, int *A, int M) {
    int cnt = 0;
    int last = 1;
    for(int i = 1; i <= n; i++)
        if(A[i] - A[last] >= M)
            cnt++, last = i;
    return cnt >= n / 2;
}
int AliceEven(int n, int *A) {
    int L = 1, H = A[n] - A[1];
    while(L<H) {
        int M = L + H + 1 >> 1;
        if(check(n, A, M))
            L = M;
        else H = M-1;
    }
    return L;
}
int BobOdd(int n, int *A) {
    return min(AliceEven(n - 1, A), AliceEven(n - 1, A + 1));
}

int n, A[MAXN + 10];

int main() {

    string name;
    cin >> n >> name;
    for(int i = 1; i <= n; i++)
        scanf("%d", &A[i]);

    if(name == "Alice") {
        if(n & 1) cout << AliceOdd(n, A) << endl;
        else cout << AliceEven(n, A) << endl;
    }
    else {
        if(n & 1) cout << BobOdd(n, A) << endl;
        else cout << BobEven(n, A) << endl;
    }

    return 0;
}

Measured memory_bytes: 1644
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 2000
using namespace std;
int n, m;
int a[N], c[N];

int dp[1<<13];
int main () {
	cin >> n >> m;
	for (int i = 1; i <= m; i ++) {
		int b; cin >> a[i] >> b;
		for (int j = 1; j <= b; j ++) {
			int x; cin >> x;
			c[i] |= (1 << (x-1));
		}
	}
	
	memset (dp, INF, sizeof (dp));
	dp[0] = 0;
	for (int st = 0; st < (1<<n); st ++) {
		for (int j = 1; j <= m; j ++) {
			dp[st|c[j]] = min (dp[st|c[j]], dp[st] + a[j]);
		}
	}
	
	cout << (dp[(1<<n)-1] == INF ? -1 : dp[(1<<n)-1]) << endl;
}

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



int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<long long> > v(N, vector<long long>(3));
  for (int i=0; i<N; i++) cin >> v[i][0] >> v[i][1] >> v[i][2];
  long long ans = 0;
  vector<int> a={-1,1};
  for(int x: a){
    for(int y: a){
      for (int z: a){
        long long tmp = 0;
        sort(v.begin(), v.end(),
        [x,y,z](auto& v1, auto& v2){return (v1[0]*x+v1[1]*y+v1[2]*z > v2[0]*x+v2[1]*y+v2[2]*z);});
        for (int i=0; i<M; i++) tmp += v[i][0]*x+v[i][1]*y+v[i][2]*z;
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << endl;
}


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

int main(){
	int n;
	cin >> n;
	
	char p[n];
	int x[n],count=0,count2=0;
	
	for(int i=0;i<n;i++){
		cin >> p[i] >> x[i];
	
		if(p[i]=='('){
			count+=x[i]; 
		}else{
			count-=x[i];
		}
		
		if(count<0){
		count2=1;
		}
		
	}
	
	
	if(count==0 && count2==0){
	cout << "YES" << endl;
	}else{
	cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int data[n];
  for(int i=0;i<n;i++) cin >> data[i];
  for(int i=n-1;i>=0;i--) cout << (i!=n-1?" ":"") << data[i];
  cout << endl;
}


Measured memory_bytes: 3076
#include <iostream>
#include<cmath>

using namespace std;

int main()
{
    int n,i;
    cin>>n;
    double res;
    for(i=n; i>=1; i--)
    {
        res=pow(i,0.5);
        if(abs(res-int(res))==0)
        {
            cout<<i;
            return 0;
        }
    }
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

int main(){
  string s; cin >> s;
  int n = s.size();

  string ns = {};
  rep(i, n){
    if(i+1 < n && s[i] == 'B' && s[i+1] == 'C'){
      ns += 'X';
      i++;
    }
    else ns += s[i];
  }

  int nn = ns.size();
  ll ans = 0;
  int cnt = 0;//Xの左にいるAの数を数える
  rep(i, nn){
    if(ns[i] == 'A') cnt++;
    if(ns[i] == 'B' || ns[i] == 'C') cnt = 0;
    if(ns[i] == 'X'){
      if(cnt == 0) cnt = 0;//Xの左にAが無かったなら何もなし
      else ans += cnt;
    }
  }

  std::cout << ans << '\n';
}


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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, K, ans=0, tmp=0;
vector<ll> A;
map<ll,ll> B;

signed main(){
    cin >> N >> K;
    A.push_back(0);
    B[0]++;
    if(K>N) {
        for(int i=0;i<N;i++) {
            ll a;
            cin >> a;
            a--;
            a %= K;
            tmp += a;
            tmp %= K;
            ans += B[tmp];
            A.push_back(tmp);
            B[tmp]++;
        }
    }
    else {
        for(int i=0;i<K-1;i++) {
            ll a;
            cin >> a;
            a--;
            a %= K;
            tmp += a;
            tmp %= K;
            ans += B[tmp];
            A.push_back(tmp);
            B[tmp]++;
        }
        for(int i=0;i<N-K+1;i++) {
            B[A[i]]--;
            ll a;
            cin >> a;
            a--;
            a %= K;
            tmp += a;
            tmp %= K;
            ans += B[tmp];
            A.push_back(tmp);
            B[tmp]++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17276
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a; string s;
  cin >> a >> s;
  cout << (a>=3200 ? s : "red") << '\n';

  return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
int st[500][3];
int main()
{
        int N;
        scanf("%d",&N);
        int i = 0;
        while(i<N-1){
                scanf("%d",&st[i][0]);
                scanf("%d",&st[i][1]);
                scanf("%d",&st[i][2]);
                i++;
        }
        int now = 0;
        while(now<N-1){
                int j,t = 0;
                for(j = now; j<N-1; j++){
                        if(t<st[j][1]) t = st[j][1];
                        int ret = t%st[j][2];
                        if(ret != 0)
                                t+= st[j][2] - ret;
                        t+=st[j][0];
                }
                printf("%d\n",t);
                now++;
        }
        printf("0");
        return 0;
}


Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
)

func main() {
	N, K := ReadInt(), ReadInt()
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		m[ReadInt()]++
	}
	values := make([]int, 0)
	for _, v := range m {
		values = append(values, v)
	}
	sort.Ints(values)
	ans := 0
	for len(values) > K {
		ans += values[0]
		values = values[1:]
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 20064
#include<stdio.h>

int hantei(char x[], char y[]) {
  int xn = 0, yn = 0, flag = 0, i, j, max = 0;
  int c[1001][1001];
  
  while (flag == 0)
  {
    if (x[xn] != '\0')
    {
      xn++;
    }
    else
    {
      flag = 1;
    }
  }
  
  flag = 0;
  
  while (flag == 0)
  {
    if (y[yn] != '\0')
    {
      yn++;
    }
    else
    {
      flag = 1;
    }
  }
  for (i = 1; i < xn + 1; i++) c[i][0] = 0;
  for (j = 1; j < yn + 1; j++) c[0][j] = 0;
  
  for (i = 1; i < xn + 1; i++)
  {
    for (j = 1; j < yn + 1; j++)
    {
      if (x[i - 1] == y[j - 1])
      {
        c[i][j] = c[i - 1][j - 1] + 1;
      }
      else if (c[i - 1][j] >= c[i][j - 1])
      {
        c[i][j] = c[i - 1][j];
      }
      else
      {
        c[i][j] = c[i][j - 1];
      }
      if (max < c[i][j]) max = c[i][j];
    }
  }
  
  return max;
}

int main(void) {
  char x[1000], y[1000];
  int q, i;
  
  scanf("%d", &q);
  
  for (i = 0; i < q; i++)
  {
    scanf("%s", x);
    scanf("%s", y);
    printf("%d\n", hantei(x, y));
  }
  
  return 0;
}

Measured memory_bytes: 6592
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, P):
    ans = 0

    for i in range(N-1):
        if P[i] == i + 1:
            ans += 1
            P[i], P[i+1] = P[i+1], P[i]

    if P[-1] == N:
        ans += 1
    return ans


def main():
    N = read_int()
    P = read_int_n()

    print(slv(N, P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 74288
//
//  atcoder.cpp
//
//
///
#include <bits/stdc++.h>

#define REP(i, N) for(int i=0; i<(N); i++)
#define REC(f, ...) (void)0; const auto f = [&](const auto f, __VA_ARGS__)
using namespace std;

using ll = long long;
template<typename T> class in {
    T value;
public:
    in() { cin >> value; }
    operator const T&() const { return value; }
    operator T&() { return value; }
    in& operator=(T source) { value = source; return *this; }
};
template<> class in<string> : public string {
public:
    in() { cin >> *this; }
};
template<class T> class inseq : public T {
public:
    template<typename... Arg> inseq(Arg... arg) : T(forward<Arg>(arg)...) { for (auto&& i : *this) cin >> i; }
};
template<class T> using invec = inseq<vector<T>>;

auto solve() {
  in<ll> N, K;
  set<int> snu;
  REP(i, N) {
    snu.insert(i+1);
  }
  REP(i,K) {
    int d;
    cin >> d;
    REP(j,d) {
      int A;
      cin >> A;
      
      snu.erase(A);
    }
  }


  return snu.size();
}

template<typename T> void plot(const T& func) { cout << func() << endl; }
template<> void plot<void()>(void(&func)()) { func(); }
template<> void plot<double()>(double(&func)()) { cout << setprecision(9) << func() << endl; }

int main() {
  plot(solve);

  return 0;
}



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

int main(){
   set<string>  s;
   string word;
   int i, n;
   cin >> n;
   
   for(i=1; i<=n; i++){
      cin >> word;
      s.insert(word);   
   } 

   cout << s.size();
   return 0;
}

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

class Dice{
  public:
    vector<int> numbers;
    int buttom_index;
    int top_index;
    int w_index;
    int e_index;
    int s_index;
    int n_index;
  
    void roll_to(char direction){
      int tmp;
      if (direction == 'W'){
        tmp = top_index;
        top_index = e_index;
        e_index = buttom_index;
        buttom_index = w_index;
        w_index = tmp;
      }else if(direction == 'E'){
        // cout << "e" << endl;
        tmp = top_index;
        top_index = w_index;
        w_index = buttom_index;
        buttom_index = e_index;
        e_index = tmp;
      }else if(direction == 'S'){
        // cout << "s" << endl;
        tmp = top_index;
        top_index = n_index;
        n_index = buttom_index;
        buttom_index = s_index;
        s_index = tmp;
      }else{
        tmp = top_index;
        top_index = s_index;
        s_index = buttom_index;
        buttom_index = n_index;
        n_index = tmp;
      }
    }
};

int main(){
  Dice dice;
  int tmp;
  string directions;
  for (int i = 0; i < 6; i++){
    cin >> tmp;
    dice.numbers.push_back(tmp);
  }
  dice.buttom_index = 5;
  dice.top_index = 0;
  dice.w_index = 3;
  dice.e_index = 2;
  dice.s_index = 1;
  dice.n_index = 4;

  cin >> directions;

  for (int i = 0; i < directions.length(); i++){
    dice.roll_to(directions[i]);
  }

  cout << dice.numbers[dice.top_index] << endl;

  // for (int i = 0; i < 6; i++){
  //   cout << dice.numbers[i] << endl;
  // }
  
}


Measured memory_bytes: 3208
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int main(void){
    long long int n,k,i,j,min = 0,sum = 0;
    scanf("%lld%lld",&n,&k);
    for(i=0;i<k-1;i++){
        min += i;
    }
    for(i=k;i<=n+1;i++){
        min += i-1;
        sum += i*n - 2*min +1;
    }
    printf("%lld",sum%(1000000000 +7));
    return 0;
}

Measured memory_bytes: 1728
h, w = map(int, input().split())
a = [list(map(int, input().split())) for i in range(h)]
c = []
hold = False
for y in range(h):
    for x in list(range(w))[::-1+(y % 2 == 0)*2]:
        # print((y + 1, x + 1))
        if hold:
            c.append((back[0], back[1], y + 1, x + 1))
            if a[y][x] % 2 == 1:
                hold = False
                continue
        if not hold and a[y][x] % 2 == 1:
            hold = True
        back = (y + 1, x + 1)
print(len(c))
for i in range(len(c)):
    print(*c[i])


Measured memory_bytes: 26716
#include <cstdio>
#include <iostream>
#include <vector>
#define mod 1000000007
#define MN 1050000

std::vector<int> v[MN];

int n, a[MN];
int b[MN], c[MN];

int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		b[i] = b[i - 1] ^ a[i];
		c[i] = c[i - 1] + (b[i] == 0 ? 1 : 0);
		v[b[i]].push_back(i);
	}
	int ans = 0;
	for(int j = 1; j < (1 << 20); j++)
	{
		int Sumj = 0, Sum0 = 1;
		int S = v[j].size();
		for(int k = 0; k < S; k++)
		{
			if(k) Sum0 = (Sum0 + 1ll * Sumj * (c[v[j][k]] - c[v[j][k - 1]])) % mod;
			Sumj = (Sum0 + Sumj) % mod;
		}
		if(b[n] == j) ans = (ans + Sum0) % mod;
		if(b[n] == 0) ans = (ans + Sumj) % mod;
	}
	if(b[n] == 0)
	{
		int k = 1; 
		for(int j = 1; j <= c[n] - 1; j++) k = k * 2 % mod; 
		ans = (ans + k) % mod;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 40564
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce

def main():
    N, X = map(int, input().split())
    x = list(map(int, input().split()))

    x.append(X)
    x = sorted(x)

    d = []
    for i in range(N):
        d.append(x[i + 1] - x[i])

    print(gcd(*d))


def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

if __name__ == '__main__':
    main()


Measured memory_bytes: 99108
def read_input():
    h, w = map(int, input().split())

    slist = []
    for i in range(h):
        slist.append(input().strip())

    return h, w, slist

def submit():
    h, w, slist = read_input()

    print('#'*(w + 2))
    for s in slist:
        print('#' + s + '#')
    print('#'*(w + 2))

if __name__ == '__main__':
    submit()

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

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

typedef long long ll;
const int MAX_N = 31000;
const int MAX_M = 100010; 
int n,m,arr[MAX_N],mod_sum[MAX_N];
int bit[MAX_M];

int sum(int i) {
  ++i;
  int s = 0;
  while( i > 0 ){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(int i,int x){
  ++i;
  while( i <= m ) {
    bit[i] += x;
    i += i & -i;
  }
}

int getMax(int L,int R){
  int target = sum(R);
  rep(_,65){
    int M = ( L + R ) / 2;
    if( sum(M) >= target ) R = M;
    else                   L = M;
  }
  if( L != R ) {
    int res = -1;
    if( sum(R) >= target ) res = R;
    if( sum(L) >= target ) res = L;
    assert( res != -1 );
    R = res;
  }
  if( R == 0 && sum(R) ) return 0;
  else if( R == 0 )      return -1;
  if( sum(R) - sum(R-1) ) return R;
  return -1;
}

inline int convert(int value,int sub){ return ( value - sub + m ) % m; }

void compute(){
  int maxi = 0;

  rep(i,n) if( arr[i] ) add(mod_sum[i],1), maxi = max(maxi,arr[i]);
  if( maxi == m-1 ) { printf("%d\n",maxi); return; }
  int sub = 0;
  
  rep(i,n) if( arr[i] ) {
    int low  = sub;
    int high = ( m - 1 + sub ) % m;

    if( low < high ) {
      int temp = getMax(low,high);
      if( temp != -1 ) maxi = max(maxi,convert(temp,sub));
    } else {
      int temp = getMax(low,m-1);
      if( temp != -1 ) maxi = max(maxi,convert(temp,sub));
      temp = getMax(0,high);
      if( temp != -1 ) maxi = max(maxi,convert(temp,sub));
    }
    ( sub += arr[i] ) %= m;
    add(mod_sum[i],-1);
    if( maxi == m-1 ) break;
  }
  printf("%d\n",maxi);
}

int main(){
  while( scanf("%d %d",&n,&m), n|m ){
    memset(bit,0,sizeof(bit));
    rep(i,n) {
      scanf("%d",arr+i);
      arr[i] %= m;
      if( i ) mod_sum[i] = ( mod_sum[i-1] + arr[i] ) % m;
      else    mod_sum[i] = arr[i];
    }
    compute();
  }
  return 0;
}

Measured memory_bytes: 1812
package main

import "fmt"

func main() {
	length := 3
	var stations string
	fmt.Scanf("%s", &stations)
	prevStation := ""
	needs := false
	for i := 0; i < length; i++ {
		current := string(stations[i])
		if prevStation == "" {
			prevStation = current
			continue
		}
		needs = prevStation != current
		if needs {
			break
		}
		prevStation = current
	}
	if needs {
		fmt.Print("Yes")
	} else {
		fmt.Print("No")
	}
}


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

int main()
{
  string C1, C2;

  cin >> C1 >> C2;

  if ( C1[0] == C2[2]
    && C1[1] == C2[1]
    && C1[2] == C2[0] )
  {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


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

int main(){
	long long n,a,b,sum,max,min;
	sum = 0;
	max = -1000000;
	min = 1000000;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a;
		if (a > max)max = a;
		if (a < min)min = a;
		sum += a;
	}
	
	cout << min << " " << max << " " << sum << endl;
	
	return 0;
}

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

using namespace std;

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

const double pi = 3.14159265358979323846;

// #define fio() cin.tie(0); ios::sync_with_stdio(false);
// 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 (a>b) { a = b; return 1; } return 0; }
#define MOD 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define TG0 get< 0 >
#define TG1 get< 1 >
#define TG2 get< 2 >
#define F first
#define S second
#define VL vector< ll >

// to_string(123)
// atoi("123"); atoi(s.c_str());
// "abc".size()
// s.find('+') == string::npos
// 1e18

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

  string s;
  cin >> s;

  char last = s[0];

  if (s.length() % 2 == 1) {
    cout << "No" << endl;
    return 0;
  }

  for (ll i = 1; i < s.length(); i++) {
    if (last == 'h' && s[i] == 'i') {

    } else if (last == 'i' && s[i] == 'h') {

    } else {
      cout << "No" << endl;
      return 0;
    }

    last = s[i];
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import itertools
 
H, W, K = map(int, input().split())
S = []
for _ in range(H):
    S.append([int(s) for s in input()])
 
ans = 2000
for t in itertools.product([0, 1], repeat=H - 1):
    cnt = t.count(1)
    lst = [[s for s in S[0]]]
    for h in range(H - 1):
        if t[h]:
            lst.append(S[h + 1])
        else:
            lst[-1] = [lst[-1][i] + S[h + 1][i] for i in range(W)]
    L = len(lst)
    sum_lst = [0] * L
    for w in range(W):
        if max(lst[i][w] for i in range(L)) > K:
            break
        tmp = [sum_lst[i] + lst[i][w] for i in range(L)]
        if max(tmp) > K:
            cnt += 1
            sum_lst = [lst[i][w] for i in range(L)]
        else:
            sum_lst = tmp
    else:
        ans = min(ans, cnt)
print(ans)

Measured memory_bytes: 49372
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

typedef std::pair<int, int> P; //first:最短距離，second:頂点番号

class Edge{
public:
	int from;
	int to;
	int cost;

	Edge(){
		return;
	}
	~Edge(){
		return;
	}
};

#define MAX_COST (1000000000)


int main(int argc, char **argv){
	int n, m, r;
	std::vector<Edge> edges;
	std::vector<long> min_cost;
	std::priority_queue<P, std::vector<P>, std::greater<P> > que;
	bool is_there_negative_cycle = false;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif


#if INPUT_FROM_FILE
	ifs >> n >> m >> r;
#else
	std::cin >> n >> m >> r;
#endif

	edges.resize(m);
	for(int i = 0; i < m; i++){
		int s, t, d;
		Edge edge;

#if INPUT_FROM_FILE
		ifs >> s >> t >> d;
#else
		std::cin >> s >> t >> d;
#endif
		edge.from = s;
		edge.to = t;
		edge.cost = d;
		edges[i] = edge;
	}

	min_cost.clear();
	min_cost.resize(n, MAX_COST);
	min_cost[r] = 0;
	for(int i = 0; i < n; i++){
		bool update = false;
		for(int j = 0; j < m; j++){
			Edge e = edges[j];

			if(min_cost[e.from] != MAX_COST && min_cost[e.to] > min_cost[e.from] + e.cost){
				min_cost[e.to] = min_cost[e.from] + e.cost;
				update = true;

				if(i == n - 1){
					is_there_negative_cycle = true;
					break;
				}
			}
			
		}
		if(!update){ break; }
		if(is_there_negative_cycle){ break; }
	}

	if(is_there_negative_cycle){
		std::cout << "NEGATIVE CYCLE" << std::endl;
	}
	else{
		for(int i = 0; i < n; i++){
			if(min_cost[i] == MAX_COST){
				std::cout << "INF" << std::endl;
			}
			else{
				std::cout << min_cost[i] << std::endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <cstring>
using namespace std;

#define F(i,a,b) for(long long  i =a; i<b; i++)
#define rF(i,a,b) for(long long i=a-1; i>=b;i--)
#define endl "\n"
#define min1(x,y,z) min(x,min(y,z))
#define input_vector(v,n,type) vector<type> v;for(int i=0;i<n;i++){type x;cin>>x;v.push_back(x);}
#define IOS ios_base::sync_with_stdio(false);  cin.tie(NULL);  cout.tie(NULL);
#define int long long
#define inf (1LL<<61)
typedef pair<int,int> ii;
typedef vector<pair<int,int>> vii;
typedef vector<int> vi;


int n,k;
int dp[200005];
int h[200005] = {0};

int minCost(int i)
{
        if(i>=n-1) return 0;
        if(dp[i]!=-1) return dp[i];

        int mCost = inf;
        for(int j = 1; j <= k && i+j<=n-1; j++)
        {
                mCost = min(mCost, abs(h[i+j]-h[i]) + minCost(i+j));
        } 
        return dp[i] = mCost;
}

int32_t main()
{
  IOS;

  cin>>n>>k;

  F(i,0,n)
  {
          int x;
          cin>>x;
          h[i] = x;
  }
        
  memset(dp, -1, sizeof dp);

  cout<<minCost(0)<<endl;

  

  

  



 
  
  

  






























  return 0;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,x,y;
    cin>>a;
    for (int i=0;i<a.size();i++)
    {
    	x=a[i];
        if(x=="C")
        {
            for (int j=i+1;j<a.size();j++)
            {
            	y=a[j];
                if(y=="F")
                {
                    cout<<"Yes";
                    return 0;
                }
            }
        }
    }
    cout<<"No";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;



int main()
{
	string x;

	while (true) {
		cin >> x;
		if (x == "0") break;
		int sum = 0;
		int len = x.length();
		rep(i, len) sum += (x[i] - '0');
		cout << sum << endl;
	}






	return 0;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s, t;
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - i; j++) {
      if (s[j + i] != t[j]) break;
      if (j == n - i - 1) {
        cout << 2*n - (n - i) << endl;
        return 0;
      }
    }
    if (i == n - 1) cout << 2*n << endl;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

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

void solve(std::string C){
  cout<<(char)(C[0]+1)<<endl;
}

int main(){
  std::string C;
  std::cin >> C;
  solve(C);
  return 0;
}


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

using namespace std;
int n,m;
int l,r;

int main()
{
    scanf("%d%d",&n,&m);
    int l1 = 1,r1 = n;
    for(int i = 1;i <= m;i++)
    {
        scanf("%d%d",&l,&r);
        if(l >  l1)
            l1 = l;
        if(r < r1)
            r1 = r;
    }
    if(l1 <= r1)
        printf("%d\n",r1 - l1 + 1);
    else
        printf("0\n");
    return 0;
}


Measured memory_bytes: 256
import copy
N = int(input())
hai = []
hai2 = []
datanum = 1
for i in range(N):
    name, num = input().split()
    num = int(num)
    hai.append(name)
    hai.append(num)
    hai.append(datanum)
    hai3 = copy.copy(hai)
    hai2.append(hai3)
    hai.clear()
    datanum += 1
hai2.sort(key=lambda x:(x[0], -x[1]))


for i in hai2:
    print(i[2])


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#include <boost/dynamic_bitset.hpp>
using namespace std;
using u32 = uint32_t;

void dfs(const vector<vector<u32>>& fs, shared_ptr<boost::dynamic_bitset<>>& ac,
map<u32, shared_ptr<boost::dynamic_bitset<>>>& mm, const u32 n) {
	
	(*ac)[n] = 1;
	for(auto f : fs[n]) {
		if(!(*ac)[f]) {
			dfs(fs, ac, mm, f);
		}
	}
	mm[n] = ac;
}

int main() {
	u32 N, M, K;
	cin >> N >> M >> K;

	vector<vector<u32>> fs(N, vector<u32>());
	vector<vector<u32>> bs(N, vector<u32>());
	
	for(u32 i=0; i<M; i++) {
		u32 A, B;
		cin >> A >> B;
		fs[A-1].push_back(B-1);
		fs[B-1].push_back(A-1);
	}
	
	for(u32 i=0; i<K; i++) {
		u32 C, D;
		cin >> C >> D;
		bs[C-1].push_back(D-1);
		bs[D-1].push_back(C-1);
	}
	
	map<u32, shared_ptr<boost::dynamic_bitset<>>> mm;
	
	for(u32 i=0; i<N; i++) {
		auto itr = mm.find(i);
		boost::dynamic_bitset<> aci;
		
		if(itr == mm.end()) {
			shared_ptr<boost::dynamic_bitset<>> ac(new boost::dynamic_bitset<>(N));
			dfs(fs, ac, mm, i);
			aci = *ac;
		} else {
			aci = *((*itr).second);
		}
		
		for(auto f : fs[i]) aci[f] = 0;
		for(auto b : bs[i]) aci[b] = 0;
		aci[i] = 0;
		cout << aci.count() << " ";
		mm.erase(i);
	}
	
	return 0;
}

Measured memory_bytes: 51712
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <float.h>
#include <iomanip>

using namespace std;
#define ll long long

int main(void){
    int N,K;
    double ans=0.0f,sum=0.0f;
    cin>>N>>K;
    for(int i=1;i<=N;i++){
        double MEM=1;
      int j=i;
        while(j<K){
            j*=2;
            MEM/=2;
        }
        sum+=MEM;
    }
    ans=sum/N;
    cout<<setprecision(12)<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout<< "YES"<<endl;
#define No cout<< "No"<<endl;
#define Yes cout<< "Yes"<<endl;
#define all(a) a.begin(),a.end()
#define P pair<int,int>
#define space ' '
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

const int maxn = 200000;
vector<vector<int> > t(maxn);
vector<vector<int> > r(maxn);
vector<pair<int,int>> g(maxn+1);
ll a[maxn],b[maxn];
bool used[maxn]={0};
map<pair<int,int>,ll> m;

bool compare_by_b(pair<int,int> a,pair<int,int> b){
    if(a.first==b.first)return a.second<b.second;
    else return a.first<b.first;
}


int main(){
    
    int n,k,l;
    cin >> n>>k>>l;
    rep(i,n){
        a[i]=b[i]=i;
    }
    rep(i,k){
        int a,b;cin >> a>>b;
        a--;b--;
        t[a].push_back(b);
        t[b].push_back(a);
    }
    rep(i,l){
        int a,b;cin >> a>>b;
        a--;b--;
        r[a].push_back(b);
        r[b].push_back(a);
    }
    
    rep(i,n){
        if(used[i])continue;
        queue<int> que;
        que.push(i);
        used[i]=true;
        while(!que.empty()){
            int arg = que.front();que.pop();
            rep(j,t[arg].size()){
                if(!used[t[arg][j]]){
                    a[t[arg][j]]=a[arg];
                    que.push(t[arg][j]);
                    used[t[arg][j]]=true;
                }
            }
        }
    }
    
    fill(used,used+n,false);
    rep(i,n){
        if(used[i])continue;
        queue<int> que;
        que.push(i);
        used[i]=true;
        while(!que.empty()){
            int arg = que.front();que.pop();
            rep(j,r[arg].size()){
                if(!used[r[arg][j]]){
                    b[r[arg][j]]=b[arg];
                    que.push(r[arg][j]);
                    used[r[arg][j]]=true;
                }
            }
        }
    }
    
    rep(i,n){
        g[i]=make_pair(a[i],b[i]);
    }
    g[n]=make_pair(INF,INF);
    sort(g.begin(),g.begin()+n,compare_by_b);
    //rep(i,n)cout << g[i].first<<space<<g[i].second<<endl;
    int cnt=1;
    rep(i,n){
        if(g[i]==g[i+1]){
            cnt++;
        }else{
            m[g[i]]=cnt;
            cnt=1;
        }
    }
    
    rep(i,n){
        cout <<m[make_pair(a[i],b[i])]<<space;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 31268