akhauriyash/Code-Regression huggingface dataset:
# Setup
import sys
sys.setrecursionlimit(4100000)

n,k= [int(i) for i in input().split()]
pts = {}
pts["s"],pts["p"],pts["r"] = [int(i) for i in input().split()]
t = input()
take,notake, chose = [0 for _ in range(n)], [0 for _ in range(n)], ["w" for _ in range(n)]
for i in range(len(t)):
    if i == 0:
        take[0] = pts[t[i]]
        notake[0] = 0
        chose[0] = t[i]
    else:
        if t[i] == chose[i-k]:
            take[i] = max(take[i-1],notake[i-1])
            notake[i] = max(take[i-1],notake[i-1])
        else:
            take[i] = take[i-1] + pts[t[i]]
            notake[i] = max(take[i-1],notake[i-1])
            chose[i] = t[i]
#     print(take,notake,chose)
# print(take,notake,chose,pts)
print(max(take[-1],notake[-1]))

Measured memory_bytes: 8732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	for(int i = 1;i<=5;i++)
    {
      int a;
      cin>>a;
      if(a==0)
      {
        cout<<i;
      }
    }
	return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
    int n, x;
    int a, b ,c;
    int ans;
    
    while(1){
        scanf("%d %d", &n, &x);
        if(n==0 && x==0) break;
        ans = 0;
        for(a=1; a<=n; a++){
            for(b=a+1; b<=n; b++){
                c = x-a-b;
                if(c>b && c<=n) ans++;
            }
        }
        printf("%d\n", ans);
    }
    
}



Measured memory_bytes: 2000
#include <iostream>

int main(){
	int N;
	int a[100010];
	std::cin>>N;
	for(int i=0;i<N;++i)std::cin>>a[i];

	int fing=0;
	int count=0;
	while(true){
		count++;	
		int Bnum = a[fing];
		if(Bnum == 0){std::cout<<(-1);return 0;}
		if(Bnum == 2){std::cout<<count;return 0;}
		a[fing] = 0;
		fing = Bnum -1;
	}
	return 0;
}


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

void bubbleSort(int a[], int n) {
    int count = 0;
    int flag = 1;
    while (flag) {
        flag = 0;
        for (int i = n - 1; 0 < i; i--) {
            if (a[i] < a[i-1]) {
                int temp = a[i];
                a[i] = a[i-1];
                a[i-1] = temp;
                count++;
                flag = 1;
            }
        }
    }
    
    for (int i = 0; i < n; i++) {
        printf("%d", a[i]);
        if (i == n-1) {
            printf("\n");
        }
        else {
            printf(" ");
        }
    }
    printf("%d\n", count);
}

int main(void){
    // Your code here!
    int N;
    scanf("%d", &N);
    int A[100];
    
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    bubbleSort(A, N);
    
}



Measured memory_bytes: 3212
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const auto mod=1e9+7;



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n,m; cin >> n >> m;
  vector<int> a(m);
  int ans=0;
  rep(i,0,m){
    cin >> a[i];
    ans+=a[i];
  } 
  if(ans<=n) cout << n-ans << endl;
  else cout << -1 << endl;
}

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

#define MODSIZE 1000000007

char s[100006];
ll dp[100005][13];

int main(){
  ll n;

  scanf("%s", s);
  n = strlen(s);

  int i,j;

  for(i = 0;i <= n;i++){
    for(j = 0;j <= 12;j++) dp[i][j] = 0;
  }

  dp[0][0] = 1;

  int k;

  for(i = 0;i < n;i++){
    for(j = 0;j < 13;j++){
      if(s[i] == '?'){
        for(k = 0;k < 10;k++){
          dp[i + 1][(j*10 + k) % 13] = (dp[i + 1][(j*10 + k) % 13] + dp[i][j]) % MODSIZE;
        }
      }

      else {
        k = s[i] - '0';
        dp[i + 1][(j*10 + k) % 13] = (dp[i + 1][(j*10 + k) % 13] + dp[i][j]) % MODSIZE;
      }
    }
  }

  printf("%lld\n", dp[n][5]);

  return  0;
}


Measured memory_bytes: 10496
//#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 97;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

//typedef uint64_t hash_t;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int HASH_COUNT = 2;
//const hash_t HASH_P = (uint32_t)-13337;
//uniform_int_distribution<hash_t> MULT_DIST(0.25 * HASH_P, 0.75 * HASH_P);
//const hash_t HASH_MULT[HASH_COUNT] = {MULT_DIST(rng), MULT_DIST(rng)};

int main(){
  int n, m;
  fastScan(n);
  fastScan(m);
  printf("%d\n", (n / m) + (n % m != 0));
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	
	int N=in();
	vector<int> V(N);
	iota(ALL(V),1);
	int Q=in();
	REP(i,Q){
		int a,b;
		scanf("%d,%d",&a,&b);
		swap(V[a-1],V[b-1]);
	}
	for(auto& x:V){
		out(x);
	}

	return 0;
}


Measured memory_bytes: 3136
h1,m1,h2,m2,k = map(int,input().split())
dum1 = h1*60 + m1
dum2 = h2*60 + m2
dum3 = dum2 -dum1
if dum3-k > 0:
    print(dum3-k)
else:
    print(0)

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

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

typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;

vector<vector<int>> to;
vector<int> visited;

struct TT {
  int v, c, cnt;
  TT() : v(0), c(0), cnt(0) {}
  TT(int _v, int _c, int _cnt) : v(_v), c(_c), cnt(_cnt) {}
};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("e.1", "r", stdin);
  
  int N, M;
  cin >> N >> M;
  to = vector<vector<int>>(N + 1);
  // to.resize(N + 1);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    to[u].push_back(v);
  }
  int S, T;
  cin >> S >> T;
  const int SZ = N + 1;
  visited = vector<int>(SZ * 3, -1);
  queue<TT> q;
  q.push(TT(S, 2, 0));
  while (!q.empty()) {
    int v = q.front().v;
    int c = q.front().c;
    int cnt = q.front().cnt;
    dumpv(v, c, cnt, visited);
    q.pop();
    if (c == 2) {
      if (visited[v + SZ * c] != -1)
        continue;
      visited[v + SZ * c] = cnt;
      for (int u : to[v]) {
        q.push(TT(u, 0, cnt + 1));
      }
    } else {
      if (visited[v + SZ * c] != -1)
        continue;
      visited[v + SZ * c] = cnt;
      for (int u : to[v]) {
        q.push(TT(u, c + 1, cnt));
      }
    }
  }
  cout << visited[T + SZ * 2] << endl;
  return 0;
}

Measured memory_bytes: 6912
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE BangPatterns #-}

-- Default Imports

import Control.Monad
import Control.Monad.ST
import Control.Monad.Trans.Class

import qualified Control.Monad.Reader as Reader
import Control.Monad.Reader (Reader, ReaderT, runReader, runReaderT)

import qualified Data.Array.MArray as MArray
import qualified Data.Array.ST as STArray
import Data.Array.ST (STArray, STUArray, runSTArray, runSTUArray)
import Data.Ix (Ix)

import qualified Data.Bits as Bits
import Data.Bits ((.&.), (.|.))

import qualified Data.ByteString.Char8 as BS
import Data.ByteString.Char8 (ByteString)

import qualified Data.Char as Char
import qualified Data.List as List
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import qualified Data.Maybe as Maybe
import qualified Data.Set as Set
import Data.Set (Set)

import qualified Data.Vector as Vector
import qualified Data.Vector.Generic as GVector
import qualified Data.Vector.Mutable as MVector
import Data.Vector.Mutable (STVector)
import qualified Data.Vector.Unboxed as UVector

import Numeric

import Debug.Trace
-- ----------

-- Custom Import Here


-- ----------

-- Default Definitions

type Vector = Vector.Vector
-- type GVector = GVector.Vector
type UVector = UVector.Vector

readIntToList :: ByteString -> [Int]
readIntToList = List.unfoldr (fmap (second $ BS.dropWhile Char.isSpace) . BS.readInt)

readToList :: Read a => ByteString -> [a]
readToList = List.unfoldr $ fmap (mapTaken . mapRemain) . span' (not . Char.isSpace)
	where
		mapTaken  = first $ read . BS.unpack
		mapRemain = second $ BS.dropWhile Char.isSpace
		span' pred s
			| BS.null taken = Nothing
			| otherwise     = Just (taken, remain')
			where
				(taken, remain) = BS.span pred s
				remain' = BS.dropWhile Char.isSpace remain

readToListN :: Read a => Int -> ByteString -> [a]
readToListN n = take n . readToList

readIntToVector :: ByteString -> Vector Int
readIntToVector = Vector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVector :: ByteString -> UVector.Vector Int
readIntToUVector = UVector.unfoldr (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToVectorN :: Int -> ByteString -> Vector.Vector Int
readIntToVectorN n = Vector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace

readIntToUVectorN :: Int -> ByteString -> UVector.Vector Int
readIntToUVectorN n = UVector.unfoldrN n (fmap stripRemain . BS.readInt)
	where stripRemain = second $ BS.dropWhile Char.isSpace


first :: (a -> a') -> (a, b) -> (a', b)
first f (a, b) = (f a, b)

second :: (b -> b') -> (a, b) -> (a, b')
second f (a, b) = (a, f b)

average :: Fractional a => [a] -> a
average xs = sum xs / (fromIntegral . length) xs

-- ----------

calc a b x = a * x `div` b - a * (x `div` b)

cand b n = max 0 $ (n `div` b) * b - 1

main :: IO ()
main = do
	[a, b, n] <- readIntToList <$> BS.getLine
	print $ max (calc a b n) (calc a b (cand b n))

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

using namespace std;

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

int main(void) {
    li N, A, B;
    cin >> N >> A >> B;
    li X[N];
    FOR(i, 0, N) {
        cin >> X[i];
    }

    li cost = 0;
    FOR(i, 0, N-1) {
        li distance = X[i+1] - X[i];
        if (B < distance * A) {
            cost += B;
        } else {
            cost += distance * A;
        }
    }

    cout << cost;

    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<tuple<string, int, int>> a;

	for(int i = 1; i <= n; i++){
		string s;
		int p;
		cin >> s >> p;
		p = -p;
		a.push_back(tie(s,p,i));
	}

	sort(a.begin(), a.end());
	for(int i = 0; i < n; i++){
		cout << get<2>(a.at(i)) << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
enum FACE {FRONT, RIGHT, TOP, BOTTOM, LEFT, BACK};
void roll(int v[6], int a, int b, int c, int d){
  int tmp = v[a];
  v[a] = v[b]; v[b] = v[c]; v[c] = v[d]; v[d] = tmp;
}
void roll_x(int v[6]){
  roll(v, TOP, BACK, BOTTOM, FRONT);
}
void roll_y(int v[6]){
  roll(v, TOP, LEFT, BOTTOM, RIGHT);
}
void roll_z(int v[6]){
  roll(v, FRONT, RIGHT, BACK, LEFT);
}
int N;
int dice[4][6];
string dice_str[4][6];
int min_ans;
void dfs(int k){
  if(k == N){
    int res = 0;
    for(int i = 0; i < 6; i++){
      int cnt[100] = {};
      int max_c = 0;
      for(int j = 0; j < N; j++){
        cnt[dice[j][i]]++;
        max_c = max(max_c, cnt[dice[j][i]]);
      }
      res += N - max_c;
      if(res >= min_ans) return;
    }
    min_ans = res;
  }else{
    for(int i = 0; i < 6; (i & 1 ? roll_x(dice[k]) : roll_y(dice[k])), ++i){
      for(int j = 0; j < 4; roll_z(dice[k]), ++j){
        dfs(k + 1);
      }
    }
  }
}
struct ID{
  map<string, int> provider;
  int get(string s){
    if(provider.count(s)) return provider[s];
    int t = provider.size();
    return provider[s] = t;
  }
};

int main(){
  while(cin >> N && N){
    REP(i, N) REP(j, 6) cin >> dice_str[i][j];
    ID id;
    REP(i, N) REP(j, 6){
      dice[i][j] = id.get(dice_str[i][j]);
    }
    min_ans = INF;
    dfs(0);
    cout << min_ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.NoSuchElementException;
public class Main {
	public static void main(String[] args)throws Exception{
		PrintWriter out = new PrintWriter(System.out);
		int N=nextInt();
		int A=0,B=0,C=0,D=0;
		for(int i=0;i<N;i++){
			String a=next();
			if(a.equals("AC"))
				A++;
			if(a.equals("WA"))
				B++;
			if(a.equals("TLE"))
				C++;
			if(a.equals("RE"))
				D++;
		}
		System.out.println("AC x "+A);
		System.out.println("WA x "+B);
		System.out.println("TLE x "+C);
		System.out.println("RE x "+D);
	}
	static boolean isOK(int index,int key,ArrayList<Integer>a){
		if (a.get(index) >= key) return true;
	    else return false;
	}
	static int binary_search(int key,ArrayList<Integer> a) {
	    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	    int ok = (int)a.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	    while (Math.abs(ok - ng) > 1) {
	        int mid = (ok + ng) / 2;

	        if (isOK(mid,key,a)) ok = mid;
	        else ng = mid;
	    }
	    return ok;
	}
	//FastScanner
	static InputStream in = System.in;
	static  byte[] buffer = new byte[1024];
	static int length = 0, p = 0;
	public static boolean hasNextByte () {
		if (p < length) return true;
		else {
			p = 0;
			try {length = in.read(buffer);}
			catch (Exception e) {e.printStackTrace();}
			if (length == 0) return false;
		}
		return true;
	}
	public static int readByte () {
		if (hasNextByte() == true) return buffer[p++];
		return -1;
	}
	public static boolean isPrintable (int n) {return 33<=n&&n<=126;}
	public static void skip () {
		while (hasNextByte() && !isPrintable(buffer[p])) p++;
	}
	public static boolean hasNext () {skip(); return hasNextByte();}
	public static String next () {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int temp = readByte();
		while (isPrintable(temp)) {
			sb.appendCodePoint(temp);
			temp = readByte();
		}
		return sb.toString();
	}
	public static int nextInt () {return Math.toIntExact(nextLong());}
	public static int[] nextInts (int n) {
		int[] ar = new int[n];
		for (int i=0; i<n; i++) ar[i] = nextInt();
		return ar;
	}
	public static long nextLong () {
		if (!hasNext()) throw new NoSuchElementException();
		boolean minus = false;
		int temp = readByte();
		if (temp == '-') {
			minus = true;
			temp = readByte();
		}
		if (temp<'0' || '9'<temp) throw new NumberFormatException();
		long n = 0;
		while (isPrintable(temp)) {
			if ('0'<=temp && temp<='9') {
				n *= 10;
				n += temp - '0';
			}
			temp = readByte();
		}
		return minus? -n : n;
	}
}



Measured memory_bytes: 46248
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(int[]);
    auto BS = readln.split.to!(int[]);
    auto CS = readln.split.to!(int[]);
    sort(AS);
    sort(BS);
    sort(CS);

    auto XS = new long[](N);
    long j;
    foreach (i, b; BS) {
        while (j < N && CS[j] <= b) ++j;
        XS[i] = N - j;
    }
    foreach_reverse (i; 1..N) XS[i-1] += XS[i];
    j = 0;
    long r;
    foreach (i, a; AS) {
        while (j < N && BS[j] <= a) ++j;
        r += (j == N ? 0 : XS[j]);
    }
    writeln(r);
}

Measured memory_bytes: 12616
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<unsigned char, unsigned char> pcc;
typedef pair<double, double> pdd;
typedef vector<vector<ll>> matrix;

int par[200005];
int find(int x) {
  return par[x] == x ? x : (par[x] = find(par[x]));
}
void merge(int x, int y) {
  par[find(x)] = find(y);
}

ll facs[200005];
ll ifacs[200005];
const int MOD = 1000000007;

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}
void init() {
  facs[0] = 1;
  for(int i = 1; i <= 200000; i++) {
    facs[i] = facs[i-1] * i;
    facs[i] %= MOD;
  }
  ifacs[200000] = modpow(facs[200000], MOD-2, MOD);
  for(int i = 199999; i >= 0; i--) {
    ifacs[i] = ifacs[i+1] * (i+1);
    ifacs[i] %= MOD;
  }
}

int color[200005];
int weight[200005];
vector<pii> colorToPair[200005];
vector<int> parentToColor[200005];

void solve() {
  int n, x, y;
  cin >> n >> x >> y;
  for(int i = 0; i < n; i++) {
    par[i] = i;
    cin >> color[i] >> weight[i];
    colorToPair[--color[i]].push_back({weight[i], i});
  }
  vector<pii> all;
  for(int i = 0; i < n; i++) {
    if(colorToPair[i].empty()) continue;
    sort(colorToPair[i].begin(), colorToPair[i].end());
    all.push_back(colorToPair[i][0]);
    for(int j = 1; j < colorToPair[i].size(); j++) {
      if(colorToPair[i][0].first + colorToPair[i][j].first <= x) {
        merge(colorToPair[i][0].second, colorToPair[i][j].second);
      }
      else {
        break;
      }
    }
  }
  sort(all.begin(), all.end());
  for(int i = 0; i < 2; i++) {
    for(int a = 0; a < n; a++) {
      if(weight[all[i].second] + weight[a] <= y && color[all[i].second] != color[a]) {
        merge(all[i].second, a);
      }
    }
  }
  ll ret = 1;
  for(int i = 0; i < n; i++) {
    parentToColor[find(i)].push_back(color[i]);
  }
  for(int i = 0; i < n; i++) {
    if(parentToColor[i].size() <= 1) continue;
    sort(parentToColor[i].begin(), parentToColor[i].end());
    ll inc = facs[parentToColor[i].size()];
    for(int j = 0; j < parentToColor[i].size();) {
      int k = j;
      while(k < parentToColor[i].size() && parentToColor[i][j] == parentToColor[i][k]) {
        k++;
      }
      inc *= ifacs[k-j];
      inc %= MOD;
      j = k;
    }
    ret *= inc;
    ret %= MOD;
  }
  cout << ret << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ":" << "\n";
    solve();
  }
}

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


Measured memory_bytes: 26228
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const ll INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int d[100000];
int main(void){
    int n; cin >> n; for(int i = 0;i < n;i++)cin >> d[i];
    sort(d, d + n);
    cout << d[n/2] - d[n/2-1] << endl;
	return 0;
}

Measured memory_bytes: 640
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
s = Counter(a)
q = int(input())
for i in range(q):
    b, c = map(int, input().split())
    ans += s[b]*(c-b)
    print(ans)
    s[c] += s[b]
    s[b] = 0

Measured memory_bytes: 87852
package main

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

var fsc = NewFastScanner()

func main() {
	N, K := fsc.NextInt(), fsc.NextInt()
	if N%K == 0 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}

func (s *FastScanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
n = int(input())
s = [list(input()), list(input())]

MOD = 1000000007

dp = [0]*n
if s[0][0] == s[1][0]: # tate
    dp[0] = 3
else: # yoko
    dp[0] = 6

for i in range(1,n):
    if s[0][i] == s[0][i-1]:
        dp[i] = dp[i-1]
    elif s[0][i-1] == s[1][i-1] and s[0][i] == s[1][i]: # tate & tate
        dp[i] = dp[i-1] * 2 % MOD
    elif s[0][i-1] == s[1][i-1] and s[0][i] != s[1][i]: # tate & yoko
        dp[i] = dp[i-1] * 2 % MOD
    elif s[0][i-1] != s[1][i-1] and s[0][i] == s[1][i]: # yoko & tate
        dp[i] = dp[i-1] 
    else: # yoko & yoko
        dp[i] = dp[i-1] * 3 % MOD
print(dp[n-1])

Measured memory_bytes: 9272
#include <stdio.h>
int main(void){
    int kotae[114514]={};
    int N;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        int a;
        scanf("%d",&a);
        kotae[a]++;
    }
    int ans=0;
    int kisuu_num=0;//偶数の数
    for(int i=1;i<=114510;i++){
    if(kotae[i]!=0){
        ans++;
        if(kotae[i]%2==0)kisuu_num++;
    }
    }
    if(kisuu_num%2==1)ans--;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#define ll long long
#define rep(i, a, b) for(int i = a; i <= b; i++)
void read(int &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
void read(ll &x) {
    x = 0; int flag = 1; char ch = ' ';
    while(ch < '0' || ch > '9') { if(ch == '-') flag = -1; ch = getchar(); }
    while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
    x *= flag;
}
using namespace std;
const int maxn = 21, mod = 1e9 + 7;
int n, g[maxn][maxn];
ll dp[1 << maxn];
int main()
{
    read(n);
    rep(i, 0, n - 1) rep(j, 0, n - 1) read(g[i][j]);
    dp[0] = 1;
    rep(msk, 1, (1 << n) - 1) {
        int tmp = __builtin_popcount(msk) - 1;
        rep(j, 0, n - 1)
            if((msk & (1 << j)) && g[tmp][j])
                dp[msk] = (dp[msk] + dp[msk ^ (1 << j)]) % mod;
    }
    printf("%lld\n", dp[(1 << n) - 1]);
    return 0;
}

Measured memory_bytes: 16640
//libraries
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//namespace
using namespace std;
using namespace __gnu_pbds;

//typedef
//typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//define
#define i(X) cin>>X;
#define ol(X) cout<<X<<endl;
#define os(X) cout<<X<<" ";
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define line cout<<"\n";
#define pbp(a,b) push_back(make_pair(a,b));
#define vll(A) vector<ll> A;
#define ivt(A,n,p) vector<ll> A(n,p);
#define vst(A) sort(A.begin(),A.end());
#define rvst(A) sort(A.rbegin(),A.rend());
#define forin(i,a,b) for(ll i=a;i<=b;i++)
#define forde(i,a,b) for(ll i=a;i>=b;i--)
#define fio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const long long inf=(long long)1e18;
long long MOD=(long long)(1e9+7);

ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2) % MOD;
    p = (p * p) % MOD;

    return (y%2 == 0)? p : (x * p) % MOD;
}
ll modInverse(ll a)
{
   return power(a,MOD-2);
}

int main() 
{
	// #ifndef ONLINE_JUDGE
    //    freopen ("input.txt" , "r" , stdin);
	// 	// freopen ("OUTPUT.txt" , "w" , stdout);
	// #endif
	fio;
	ll testcase=1;
	//cin>>testcase;
	while(testcase--)
	{
		ll n;
		cin>>n;
		if(n>=30)
		cout<<"Yes\n";
		else
		{
			cout<<"No\n";
		}
		
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#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 erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n;
  cin >> n;
  vint A(n);
  rep(i,0,n) cin >> A[i];
  int ans = 1;
  bool flag = true;
  rep(i,0,n){
    if(A[i] == 0){
      ans = 0;
      break;
    }
    else if(1000000000000000000/ans >= A[i] & flag) ans *= A[i];
    else{
      ans = -1;
      flag = false;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3980
#include <iostream>

using namespace std;
using ll = long long;

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

ll dp[105][2][5];

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

  int n = s.size();
  dp[0][0][0] = 1;

  rep(i, n) {
    int t = s[i] - '0';
    rep(j, 2) for (int k = 0; k <= M; ++k) {
      for (int d = 0; d <= (j ? 9 : t); ++d) {
        dp[i + 1][j || (d < t)][min(k + (d != 0), M + 1)] += dp[i][j][k];
      }
    }
  }

  cout << dp[n][1][M] + dp[n][0][M] << endl;
  return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
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; }
const long long INF = 1LL<<60;
 
// 入力
int N, M;
vector<vector<int> > G; // グラフ
vector<int> deg; // 各頂点の入次数
 
int dp[100100];
int main() {
    // 入力受け取り, 入次数も管理する
    cin >> N >> M;
    G.assign(N, vector<int>());
    deg.assign(N, 0);
    for (int i = 0; i < M; ++i) {
        int x, y; cin >> x >> y;
        --x, --y; // 0-indexed にする
        G[x].push_back(y);
        deg[y]++;
    }
 
    // source をキューに突っ込む
    queue<int> que;
    for (int v = 0; v < N; ++v) if (deg[v] == 0) que.push(v);
 
    // BFS
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
          	dp[nv] = dp[v] + 1;
            deg[nv]--; // エッジ (v, nv) を破壊する
            if (deg[nv] == 0) {
                que.push(nv); // それによって入次数が 0 にあったならキューに突っ込む
            }
        }
    }
 
    // 答え
    int res = 0;
    for (int v = 0; v < N; ++v) chmax(res, dp[v]);
    cout << res << endl;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N;
vint G[1111];
int X[1111];
int dp[1111];

bool dfs(int v){
    vint a;
    int s=0;
    int t=0;
    for(auto u:G[v]){
        if(!dfs(u))return false;
        int x=min(X[u],dp[u]);
        int y=max(X[u],dp[u]);
        s+=x;
        t+=y;
        a.pb(y-x);
    }
    bitset<5555>latte;
    latte[0]=1;
    rep(i,a.size())latte|=latte<<a[i];

    for(int i=X[v]-s;i>=0;i--)if(latte[i]){
        dp[v]=t-i;
        return true;
    }
    return false;
}

signed main(){
    cin>>N;
    for(int i=1;i<N;i++){
        int p;cin>>p;
        p--;
        G[p].pb(i);
    }

    rep(i,N)cin>>X[i];

    if(dfs(0))cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, k;
  cin >> n >> k;
  int sum = 0;
  rep(i, n) {
    int x;
    cin >> x;
    sum += min(x, k - x);
  }
  cout << sum * 2 << endl;
}

Measured memory_bytes: 256
# Nと数列pを受け取る
N = int(input())
p = list(map(int, input().split()))

# pがすでに昇順だったら、YESにする
result = 'NO'
sorted_p = sorted(p)
# if p == sorted_p:
#   result = 'YES'
# else:
#   # pから2つの要素を入れ替えて昇順になったら、YESにする
#   count = 0
#   for i in range(N):
#     if p[i] != sorted_p[i]:
#       count += 1
#   if count == 2:
#     result = 'YES'

# pから2つの要素を入れ替えて昇順になったら、YESにする
count = 0
for i in range(N):
  if p[i] != sorted_p[i]:
    count += 1
if count <= 2:
  result = 'YES'

# 出力する
print(result)

Measured memory_bytes: 9164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_147
{
    class D
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            long n = ReadInt();
            long[] array = ReadLongs();
            long[] cnts = new long[60];
            for(int i = 0; i < n; i++)
            {
                long tmp = array[i];
                long div = 1;
                for (int j = 0; j < cnts.Length; j++)
                {
                    if ((tmp & div) > 0) cnts[j]++;
                    div *= 2;
                }
            }
            long res = 0;
            long digValue = 1;
            long mask = 1000000000 + 7;
            for(int i = 0; i < cnts.Length; i++)
            {
                long tmp = n - cnts[i];
                tmp *= digValue;
                tmp %= mask;
                tmp *= cnts[i];
                tmp %= mask;
                res += tmp;
                res %= mask;
                digValue *= 2;
                digValue %= mask;
            }
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 52040
def uncompress(text, L):
    newText = ''
    pos = 0
    while True:
        if len(newText) > L:
            break
        if pos >= len(text):
            break
        if text[pos].isdigit():
            endDigit = getEndDigit(text, pos)
            num = int(text[pos : endDigit])
            if text[endDigit] == '(':
                endPar = getEndParenthesis(text, endDigit)
                insideText = uncompress(text[endDigit + 1 : endPar - 1], L - len(newText))
                for _ in range(num):
                    newText += insideText
                    if len(newText) > L:
                        break
                pos = endPar
            else:
                newText += (text[endDigit] * num)
                pos = endDigit + 1
        else:
            newText += text[pos]
            pos += 1
    return newText

def getEndParenthesis(text, pos):
    count = 0
    while True:
        if text[pos] == '(':
            count += 1
        elif text[pos] == ')':
            count -= 1
        if count == 0:
            return pos + 1
        pos += 1

def getEndDigit(text, pos):
    while True:
        if not text[pos].isdigit():
            return pos
        pos += 1

if __name__ == '__main__':
    while True:
        text, idx = input().strip().split()
        if text == '0' and idx == '0':
            break

        text = uncompress(text, int(idx))
        print(text[int(idx)] if len(text) > int(idx) else 0)


Measured memory_bytes: 9172
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ld a, b;
	cin >> a >> b;
	ld l = 0, r = 1e17;
	while(l < r){
		ll mid = (l + r + 1) / 2;
		ld mid1 = mid;
		if((((ld)(a * b)) - mid1) >= -(1e-3)) l = mid1;
		else r = mid1 - 1;
	}
	cout << (ll)l << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/



Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

vl dvs(ll a){
	vl ret;
	for(ll i = 1; i*i <= a; i++){
		if(a%i) continue;
		if(i > 1)   ret.EB(i);
		if(i*i < a) ret.EB(a/i);
	}
	return ret;
}

int main(){
	ll n; scanf("%lld", &n);
	ll ans = dvs(n-1).size();
	for(ll i : dvs(n)){
		ll a = n;
		while(a%i == 0) a /= i;
		if(a%i == 1) ans++;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include <iostream>

int main() {
int n;
char mark;
int num;
int S[13] = {0};
int H[13] = {0};
int C[13] = {0};
int D[13] = {0};

std::cin >> n;

for(int i = 0; i < n; i++){
std::cin >> mark >> num;
if(mark == 'S'){
S[num-1] = num;
}
else if(mark == 'H'){
H[num-1] = num;
}
else if(mark == 'C'){
C[num-1] = num;
}
else if(mark == 'D'){
D[num-1] = num;
}
}

for(int j = 0; j < 13; j++){
if(S[j] == 0){
std::cout << 'S' << ' ' << j + 1 << std::endl;
}
}
for(int k = 0; k < 13; k++){
if(H[k] == 0){
std::cout << 'H' << ' ' << k + 1 << std::endl;
}
}
for(int l = 0; l < 13; l++){
if(C[l] == 0){
std::cout << 'C' << ' ' << l + 1 << std::endl;
}
}
for(int m = 0; m < 13; m++){
if(D[m] == 0){
std::cout << 'D' << ' ' << m + 1 << std::endl;
}
}
}

Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define vint vector<int>
#define pri_que priority_queue
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    string s; cin >> s;
    int one=0,zero=0;
    rep(i,s.size()){
        if(s[i]=='0') zero++;
        else one++;
    }
    cout<<zero+one-abs(zero-one)<<endl;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n;
  cin>>m;
  if(n<=m)
  {
    for(int i=0;i<m;i++)
    cout<<n;
    cout<<endl;
  }
  else
  {
    for(int i=0;i<n;i++)
    cout<<m;
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
char str[233];
int res;

int main() {
	while(~scanf("%s", str)) {
		int ln = strlen(str);
		for(int i = ln - 2; i >= 0; i--) {
			bool flg = 0;
			if(!(i & 1)) continue;
			else {
				flg = 1;
				for(int j = 0, k = i / 2 + 1; j <= i / 2, k <= i; j++, k++) {
					if(str[j] != str[k]) {
						flg = 0;
						break;
					}
				}
			}
			if(!flg) continue;
			else {
				res = i + 1; 
				break;
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 128
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define vi vector<int>
#define VS vector<string>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define pb push_back

using namespace std;

int main(){
    int n, S;
    while(cin >> n >> S, n+S){
        vi r;
        for(int i=0; i < n; i++){
            int m;
            cin >> m;
            r.push_back(m);
        }
        int ans = 0;
        for(int i=0; i < r.size(); i++){
            for(int j=0; j < i; j++){
                if(S < r[i]+r[j]) ans++;
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1320
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int n,m;
vector<vector<int>> g;
vector<bool> checked;
vector<int> a,b;

void dfs(int v,bool f){
    if(f) a.push_back(v);
    else  b.push_back(v);
    checked[v]=true;
    for(auto x:g[v]){
        if(checked[x]) continue;
        dfs(x,f);
        break;
    }
    return;
}

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

    cin>>n>>m;
    g.resize(n);
    checked=vector<bool>(n,false);
    rep(i,m){
        int a,b;
        cin>>a>>b;a--,b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    checked[0]=true;
    int cnt=0;
    dfs(g[0][0],true);
    for(int i=0;i<g[0].size();i++){
        if(checked[g[0][i]]) continue;
        dfs(g[0][i],false);
        break;
    }
    vector<int> ans;
    reverse(ALL(a));
    for(auto x:a) ans.push_back(x);
    ans.push_back(0);
    for(auto x:b) ans.push_back(x);

    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i]+1;
        cout<<(i==ans.size()-1?'\n':' ');
    }
    return 0;
}


Measured memory_bytes: 10168
#include   <bits/stdc++.h>
using      namespace        std;
#define    int              long long int
#define    sz(a)            (int)a.size()
#define    w(x)              int T; cin>>T; while(T -- > 0)
#define    ff                first
#define    ss                second

/*	hon when the digit in the one's place of N is 2, 4, 5, 7, or 9
;
pon when the digit in the one's place of N
is 0, 1, 6 or 8
;
bon when the digit in the one's place of N
is 3.*/

void solveTC(){

	int n;
	cin>>n;

	string str;
	cin>>str;

	if(str.size()>n){
		for(int i=0;i<n;i++)
			cout<<str[i];
		cout<<"...";
		cout<<endl;
	}
	else
	{
		cout<<str<<endl;
	}

}

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

 //   w(x){  solveTC();  } // with TestCases

   solveTC();          //  without TestCases

    return 0;

}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL x[100010], v[100010];
LL a[100010], b[100010];
int main() {
	int N;
	LL C;
	cin >> N >> C;
	for (int i = 1; i <= N; i++) cin >> x[i] >> v[i];
	x[N + 1] = C;
	for (int i = 1; i <= N; i++) a[i] = a[i - 1] + v[i] - (x[i] - x[i - 1]);
	for (int i = 1; i <= N; i++) a[i] = max(a[i], a[i - 1]);
	for (int i = N; i >= 1; i--) b[i] = b[i + 1] + v[i] - (x[i + 1] - x[i]);
	for (int i = N; i >= 1; i--) b[i] = max(b[i], b[i + 1]);
	LL ans = 0;
	for (int i = 1; i <= N; i++) {
		ans = max(ans, a[i]);
		ans = max(ans, b[i]);
		ans = max(ans, a[i] + b[i + 1] - x[i]);
		ans = max(ans, b[i] + a[i - 1] - (C - x[i]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdint>

using namespace std;

inline int min(int a, int b) {
  return a < b ? a : b;
}

inline int max(int a, int b) {
  return a > b ? a : b;
}

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

  int x_min = 0;
  int x_max = 0;
  int64_t sum = 0;

  int x;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (i == 0) {
      x_min = x;
      x_max = x;
    }
    x_min = min(x_min, x);
    x_max = max(x_max, x);
    sum += x;
  }
  cout << x_min << " " << x_max << " " << sum << endl;

  return 0;
}

Measured memory_bytes: 3084
#include<stdio.h>
int main()
{
    int a,b,c,d;

    scanf("%d %d %d",&a,&b,&c);

    d = b/a;

    if(d>c || d==c) printf("%d\n",c);

    else if(c>d && d>0) printf("%d\n",d);

    else if(d==0 || c==0) printf("0\n",d);

    return 0;
}

Measured memory_bytes: 1708
#include <iostream>
#include <cstdint>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <random>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define loop(i, a, b) for (int i = a; i < (int)(b); i++)


const int MAX_COUNT = 100010;
int dp[MAX_COUNT];
const int INF = 1000000007;

int solve(int n, vector <int> h) {
    rep(i, MAX_COUNT) {
        dp[i] = INF;
    }
    dp[0] = 0;
    loop(i, 0, n) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
    }
    return dp[n - 1];
}


int main() {
    int n;
    vector<int> h;
    cin >> n;
    rep(i, n) {
        int a;
        cin >> a;
        h.push_back(a);
    }
    int ans = solve(n, h);
    cout << ans << "\n";
}


Measured memory_bytes: 1528
from itertools import accumulate
from collections import Counter
N,K,*A = map(int, open(0).read().split())
A = [a-1 for a in A]
B = [0]+[b%K for b in accumulate(A)]
if K>N:
  Cnt = Counter(B)
  ans = sum(v*(v-1)//2 for v in Cnt.values())
else:
  Cnt = Counter(B[:K])
  ans = sum(v*(v-1)//2 for v in Cnt.values())
  for i in range(N+1-K):
    Cnt[B[i]] -= 1
    ans += Cnt[B[i+K]]
    Cnt[B[i+K]] += 1
print(ans)

Measured memory_bytes: 40728