akhauriyash/Code-Regression huggingface dataset:
<?php
class Line {
    protected $lineData;
    protected $pointer;
    public function __construct(array $line)
    {
        $this->lineData = $line;
        $this->pointer = 0;
        $this->count = count($line);
    }

    public function next()
    {
        if ($this->count > $this->pointer) {
            return $this->lineData[$this->pointer++];
        }
        return false;
    }

    public function nextInt()
    {
        return (int)$this->next();
    }
}

class IOW {
    /**
     * @return Line
     */
    public static function nl()
    {
        $str = trim(fgets(STDIN));
        return new Line(explode(' ', $str));
    }

    public static function out($data)
    {
        echo $data . PHP_EOL;
    }
}

$count = (int)IOW::nl()->next();
$tree = [];

for ($i = 1; $i < $count; $i++) {
    $line = IOW::nl();
    $u = $line->nextInt();
    $v = $line->nextInt();
    $mod = $line->nextInt() % 2;
    $tree[$u][$v] = $mod;
    $tree[$v][$u] = $mod;
}

$ans[1] = 0;
$queue = [1];


while ($v = current($queue)) {
    foreach ($tree[$v] as $u => $w) {
        if (isset($ans[$u])) {
            continue;
        }
        $ans[$u] = ($ans[$v] + $w) % 2;
        $queue[] = $u;
    }
    next($queue);
}

ksort($ans);
foreach ($ans as $color) {
    IOW::out($color);
}

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

bool isYYMM(int a, int b) {
    if(1 <= b && b <= 12) return true;
    else return false;
}

bool isMMYY(int a, int b) {
    if(1 <= a && a <= 12) return true;
    else return false;
}

int main() {
    string s;
    cin >> s;
    int a[4];
    for(int i = 0; i < 4; i++) a[i] = s[i] - '0';
    int L = 10 * a[0] + a[1];
    int R = 10 * a[2] + a[3];

    if(isYYMM(L, R) && !isMMYY(L, R)) cout << "YYMM" << endl;
    if(!isYYMM(L, R) && isMMYY(L, R)) cout << "MMYY" << endl;
    if(isYYMM(L, R) && isMMYY(L, R)) cout << "AMBIGUOUS" << endl;
    if(!isYYMM(L, R) && !isMMYY(L, R)) cout << "NA" << endl;  

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  map<string, int> mp;
  rep(i,n) {
    cin >> s;
    mp[s]++;
  }
  cout << "AC x " << mp["AC"] << endl;
  cout << "WA x " << mp["WA"] << endl;
  cout << "TLE x " << mp["TLE"] << endl;
  cout << "RE x " << mp["RE"] << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[100005];

void solve()
{
    int n, a, b;
    scanf("%d%d%d%s", &n, &a, &b, str);
    int cnt = 0, cnt1 = 0;
    int i;
    vector<int> flag(n);
    for (i = 0; i < n; i++) {
        if (str[i] == 'a') {
            if (cnt < a + b) {
                flag[i] = 1; cnt++;
            }
        }
        else if (str[i] == 'b') {
            if (cnt < a + b && cnt1<b) {
                flag[i] = 1; cnt++; cnt1++;
            }
        }
    }

    for (i = 0; i < n; i++) {
        if (flag[i]) printf("Yes\n");
        else printf("No\n");
    }


    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}



Measured memory_bytes: 1152
//#undef DEBUG
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
const char lf = '\n', splf[] = " \n";
#define all(x) begin(x), end(x)
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
#define TCC template<class C
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
#define ENI typename enable_if<
#define DTOR , Dbg&>::type operator<<
#define RIS return *this
TCC> static auto o(C *x)->decltype(os << *x, 0);
TCC> static char o(...);
TCC> ENI sizeof o<C>(0)!=1 DTOR(const C &x) {os<<x; RIS;}
TCC> Dbg &dump(C b, C e) {
    int ii = 0;
    for(C i = (os << "\n[", b); i!=e and ii<26; i++, ii++) *this << ", "+2*(i==b) << *i;
    RIS << ']';
}
TCC> ENI sizeof o<C>(0)==1 DTOR(const C &x) {
    return dump(all(x));
}
TCC, size_t X> ENI !is_same<C, const char>::value DTOR(C (&x)[X]) {
    return dump(all(x));
}
TCC, class D> Dbg &operator<<(const pair<C, D> &x) {RIS<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(ostream&)) { os << x; RIS; }
} dbg;
void err(istringstream *iss) { delete iss; }
TCC, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#ifdef DEBUG
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#else
#define bug(args...) void()
#define cbug(a, args...)
#endif
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
int T = 1, Q, cn;
const int inf = 1000000007, mxn = -1;
class DSU//{
{
    vector<int> dsupar;
public:
    int cntDSU;
    vector<int> siz;

    void reset(int nd) {
        for (int i = 0; i <= nd; i++) dsupar[i] = i, siz[i] = 1;
        cntDSU = nd;
    }

    DSU(int N, int noOfSets = -1) {
        dsupar.resize(N+5), siz.resize(N+5);
        reset(N+4);
        cntDSU = noOfSets==-1 ? N : noOfSets;
    }

    int find(int x) {
        return dsupar[x]==x ? x : dsupar[x] = find(dsupar[x]);
    }

    void union_(int u, int v) {
        if ((u = find(u))==(v = find(v))) return;
        if (siz[u]<siz[v]) swap(u, v);
        dsupar[v] = u, siz[u] += siz[v], siz[v] = 0;
        cntDSU--;
    }
};//}


signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    //cin >> T;
    auto kase = [&]()->void {   // if T>1, inputAll + resetAll -> solution
        //cout << "Case " << cn << ":";
        int n,m;
        cin>>n>>m;
        DSU dsu(n);
        for(int i=0,a,b;i<m;++i)cin>>a>>b,dsu.union_(a,b);
        int ans=0;
        for(int i=1;i<=n;++i)ans=max(ans,dsu.siz[i]);
        cout<<ans<<lf;
    };
    while (cn++!=T) kase();
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
int n,arr[100009][3];
int dp[100009][3];
int bt(int x,int tur)
{
    if(x==n)
        return 0;
    if(dp[x][tur]!=-1)
        return dp[x][tur];
    int &ret=dp[x][tur];
    ret=arr[x][tur];
    int mx=0;
    for(int i=0;i<3;i++)
    {
        if(i==tur)
            continue;
        mx=max(mx,bt(x+1,i));
    }
    ret+=mx;
    return ret;
}
int main()
{
    cin>>n;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<n;i++)
    {
        cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
    }
    cout<<max(bt(0,0),max(bt(0,1),bt(0,2)));
}


Measured memory_bytes: 8832
// B.

#include <iostream>
#include <sstream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[]) {
	cout.precision(6);
	int n;
	cin >> n;
	double ans = 0;
	for (int i = 0; i < n; ++i) {
		double a;
		string t;
		cin >> a >> t;
		if (t == "JPY") {
			ans += a;
		}
		if (t == "BTC") {
			ans += a * 380000;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
const int SIZE=1234;
const int INF=10+1e9;
const LL p=7+1e9;
int main(){
	LL N,M;
	cin >> N >> M;
	cout << min((N*2+M)/4,M/2) << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
cA = input()

wCounter = 0
for i in range(n):
    if cA[i] == "W":
        wCounter+=1

flag = 0
count = 0
for i in range(n-1, -1, -1):
    if flag == 0 and cA[i] == "R":
        flag = 1
    if flag == 1 and i < n-wCounter and cA[i] == "W":
        count+=1
print(count)

Measured memory_bytes: 9348
package main

import (
	"fmt"
	"math"
	"sort"
	"strings"
)

func main() {
	n := SInt()
	nn := make([]Pair, 0, n)
	for index := 0; index < n; index++ {
		nn = append(nn, Pair{
			Key:   index + 1,
			Value: SInt(),
		})
	}

	sort.Sort(ByValue(nn))
	for _, item := range nn {
		fmt.Printf("%v ", item.Key)
	}
}

func SInt() int {
	var n int
	fmt.Scan(&n)
	return n
}

func DInt() (int, int) {
	var n int
	fmt.Scan(&n)

	var m int
	fmt.Scan(&m)
	return n, m
}

func SStr() string {
	var s string
	fmt.Scan(&s)
	return s
}

func SIntSlice(n int) []int {
	re := make([]int, 0, n)
	for i := 0; i < n; i++ {
		re = append(re, SInt())
	}
	return re
}

func StrSlice() []string {
	var s string
	fmt.Scan(&s)
	return strings.Split(s, "")
}

func Min(nums ...int) int {
	if len(nums) == 0 {
		panic("function min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("function max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

type Int64Slice []int64

func (p Int64Slice) Len() int           { return len(p) }
func (p Int64Slice) Less(i, j int) bool { return p[i] < p[j] }
func (p Int64Slice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

type IntSlice []int

func (p IntSlice) Len() int           { return len(p) }
func (p IntSlice) Less(i, j int) bool { return p[i] < p[j] }
func (p IntSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

// An IntHeap is a min-heap of ints.
type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

type Pair struct {
	Key   int
	Value int
}

// sort.Sort(ByKey(pairs))
type ByKey []Pair

func (s ByKey) Len() int {
	return len(s)
}

func (s ByKey) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s ByKey) Less(i, j int) bool {
	return s[i].Key < s[j].Key
}

// sort.Sort(ByValue(pairs))
type ByValue []Pair

func (s ByValue) Len() int {
	return len(s)
}

func (s ByValue) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}

func (s ByValue) Less(i, j int) bool {
	return s[i].Value < s[j].Value
}


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

using namespace std;

char str[1010];
int i,n,s,w,e;

int main()
{
	scanf("%s",str);
	
	for(i=0;str[i];i++){
		if(str[i] == 'N') n ++;
		if(str[i] == 'S') s ++;
		if(str[i] == 'W') w ++;
		if(str[i] == 'E') e ++;
	}
	
	if(((n && s) || (!n && !s)) && ((w && e) || (!w && !e))) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner s=new Scanner(System.in);
		while(s.hasNext()){
			BigInteger a = BigInteger.valueOf(s.nextInt());
			BigInteger b = BigInteger.valueOf(s.nextInt());
			BigInteger g = a.gcd(b);
			System.out.println(g);
		}	
	}	
}

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;
    cin >> n;
    n = n + (n * n) + (n * n * n);
    cout << n << "\n";
    return 0;
}


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

#define FILE
#define fr first
#define se second

using namespace std;

const long long N = 2e5 + 7;
const long long inf = 1e9 + 7;
const long long mod = 1e9 + 7;

int n;
int m;
int a[N];
long long sum;
int main()
{
    ios_base::sync_with_stdio(false);

    cin >> n >> m;
    for(int i = 1; i <= m; i ++){
        cin >> a[i];
        sum += a[i];
    }
    if(sum > n){
        cout << "-1\n";
    }
    else{
        cout << n - sum << "\n";
    }
}



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

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double degree = abs(h * 30 + m * 0.5 - m * 6);
  degree *= 2 * M_PI / 360;
  double c = sqrt(a * a + b * b - 2 * a * b * cos(degree));
  cout << fixed << setprecision(15) << c << endl;
}

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

using namespace std;

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    vector < int > d = {a, b, c};
    sort(d.begin(), d.end());
    if (d[0] == d[2]) cout << "No" << '\n';
    else {
        for (int i = 0; i < 2; ++i) {
            if (d[i] == d[i + 1]) {
                cout << "Yes";
                return 0;
            }
        }
        cout << "No";
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    long long a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << *min_element(a, a + n) << ' ' << *max_element(a, a + n) << ' ' << accumulate(a, a + n, 0ll) << endl;
}

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

#define int long long
#define CASET int _T; cin >> _T; REP(caset, 0, _T)
#define REP(i, l, r) for (int i=(l); i<(r); ++i)
#define RREP(i, r, l) for (int i=(r); i>(l); --i)
#define print(x) cout << to_string(x) << ' '
#define println(x) cout << to_string(x) << '\n'
#define vi vector<int>
#define vb vector<bool>
#define vs vector<string>
#define pii pair<int,int>
#define mii map<int,int>
#define sq(x) (x)*(x)
#define inv(x) powa(x, MOD-2)

int INF = 1LL<<60;
int MOD = 998244353;

string to_string(string &s) {return s;}
string to_string(const char s[]) {return (string)s;}
template <class C> string to_string(C &v) {
    string res;
    for (auto &i : v) res += to_string(i) + ' ';
    return res; 
}
template <typename A> istream &operator>>(istream &is, vector<A> &v) {for (auto &x : v) is >> x; return is;}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &v);
template <typename A> ostream &operator<<(ostream &os, vector<A> &v) {bool f=1;os << '['; for (auto &x : v){if(!f) os << ", "; f=0; os << x;} os << ']';}
template <typename A> ostream &operator<<(ostream &os, set<A> &v) {bool f=1;os << '['; for (auto &x : v){if(!f) os << ", "; f=0; os << x;} os << ']';}
template <typename A> ostream &operator<<(ostream &os, multiset<A> &v) {bool f=1;os << '['; for (auto &x : v){if(!f) os << ", "; f=0; os << x;} os << ']';}
template <typename A, typename B> ostream &operator<<(ostream &os, map<A,B> &v) {bool f=1;os << '['; for (auto &x : v){if(!f) os << ", "; f=0; os << x;} os << ']';}
template <typename A, typename B> ostream &operator<<(ostream &os, pair<A, B> &pr) {os << '(' << pr.first << ", " << pr.second << ')';}
string bin_string(int x) {
    const int d = 32;
    string res(d, ' ');
    REP(i, 0, d) res[d-1-i] = '0'+(x>>i & 1LL);
    return res;
}
int powa(int base, int exp) {
    int res = 1;
    while (exp) {
        if (exp&1) res = res*base % MOD;
        base = base*base % MOD;
        exp >>= 1;
    }
    return res;
}

main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    
    int n;
    cin >> n;
    vs s(n);
    vi t(n);
    REP(i, 0, n) {
        cin >> s[i] >> t[i];
    }
    string x;
    cin >> x;

    int res = 0;
    bool flag = false;
    REP(i, 0, n) {
        if (flag) res += t[i];
        if (s[i] == x) flag = true;
    }
    println(res);
}


Measured memory_bytes: 764
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

ans=0
S=input()
for i in range(4):
    if S[i]=="+":
        ans+=1
    else:
        ans-=1
print(ans)

Measured memory_bytes: 38384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h=sc.nextInt();
		int w=sc.nextInt();
		int d=sc.nextInt();
		int[][] a=new int[h][w];
		int[] index=new int[h*w+1];
		for(int i=0;i<h;i++) {
			for(int j=0;j<w;j++) {
				a[i][j]=sc.nextInt();
				index[a[i][j]]=w*i+j;
			}
		}
		int magic[]=new int[h*w+1];
		for(int i=1;i<=h*w-d;i++) {
			magic[i]=Math.abs(index[i]/w-index[i+d]/w)+
					Math.abs(index[i]%w-index[i+d]%w);
		}
		
		for(int i=h*w-d;i>=0;i--) {
			magic[i]+=magic[i+d];
		}
		int q=sc.nextInt();
		
		for(int i=0;i<q;i++) {
			
			System.out.println(magic[sc.nextInt()]-magic[sc.nextInt()]);
		}
		
		
	}
}


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

vector<long long> buns_num(51);
vector<long long> paty_num(51);

long long buns(int N, long long X)
{
    if (N == 0)
    {
        return 1;
    }

    long long ans = 0;
    if (X == 1)
    {
        return ans;
    }
    else if (X <= buns_num[N - 1] + 1)
    {
        X -= 1;
        ans += buns(N - 1, X);
        return ans;
    }
    else if (X == buns_num[N - 1] + 2)
    {
        ans += paty_num[N - 1] + 1;
        return ans;
    }
    else if (X <= 2 * buns_num[N - 1] + 2)
    {
        ans += paty_num[N - 1] + 1;
        X -= buns_num[N - 1] + 2;
        ans += buns(N - 1, X);
        return ans;
    }
    else if (X == 2 * buns_num[N - 1] + 3)
    {
        ans += 2 * paty_num[N - 1] + 1;
        return ans;
    }

    cout << "error" << endl;
    return -1;
}

int main()
{
    buns_num[0] = 1;
    paty_num[0] = 1;
    rep(i, 50)
    {
        buns_num[i + 1] = 3 + 2 * buns_num[i];
        paty_num[i + 1] = 1 + 2 * paty_num[i];
    }

    long long N, X;
    cin >> N >> X;

    long long ans = buns(N, X);
    cout << ans << endl;
    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint A(N), B(N), C(N);
	cin >> A >> B >> C;
	int sum = 0;
	sum += B[0]; A[0]--;
	for (int i = 1; i < N; i++) {
		A[i]--;
		sum += B[i];
		if (A[i-1] + 1 == A[i]) sum += C[A[i-1]];
	}
	cout << sum << endl;
}

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


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <queue>

using namespace std;

typedef struct coord{
	int x, y;
}coord;

int map[1000][1000];

queue <coord> q;

int main() {
	int h, w, count = 0;
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			char temp;
			scanf("%c", &temp);
			if (temp == '#') {
				map[i][j] = 1;
				q.push({ i,j });
				count++;
			}
			else if (temp == '.') map[i][j] = 0;
			else j--;
		}
	}
	if (h*w == count) {
		printf("0");
		return 0;
	}
	coord cur;
	while (!q.empty()) {
		cur = q.front();
		q.pop();
		int dir[4][2] = { {cur.x + 1, cur.y},{ cur.x, cur.y+1 },{ cur.x - 1, cur.y },{ cur.x, cur.y-1 } };
		for (int i = 0; i < 4; i++) {
			if (dir[i][0] < 0 || h <= dir[i][0] || dir[i][1] < 0 || w <= dir[i][1]) continue;
			if (map[dir[i][0]][dir[i][1]] == 0) {
				count++;
				if (h*w == count) {
					printf("%d", map[cur.x][cur.y]);
					break;
				}
				map[dir[i][0]][dir[i][1]] = map[cur.x][cur.y]+1;
				q.push({ dir[i][0] ,dir[i][1] });
			}
		}
		if (h*w == count) break;
	}
	return 0;
}

Measured memory_bytes: 12304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> t(N);
  int ans = 0;
  for(int i = 0; i< N; i++){
    cin >> t.at(i);
    ans += t.at(i);
  }
  int M;
  cin >> M;
  int i = 0;
  while(i<M){
    int p,x;
    cin >> p >> x;
    cout << ans-t.at(p-1) +x << endl;
    i++;
  }
  

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define INF 2147483647

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

	int res;
	int c;
	if (a > b) {
		c = a;
		a = b;
		b = c;
	}

	if (a + w < b) {
		res = b - (a + w);
	}
	else {
		res = 0;
	}

	cout << res << endl;

	return (0);
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<vector>
#include<climits>
using namespace std;

int main(void){

    int n;
    cin>>n;
    int r = 1;
    int max;

    vector<int> v;
    for(int i=0;i<n;i++){
        int h;
        cin>>h;
        v.push_back(h);
    }
    
    max = v[0];

    for(int i=1;i<n;i++){
        if(max <= v[i]){
            max = v[i];
            r++;
        }
    }

    cout<<r<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a,b;
    
    scanf("%d",&a);
    scanf("%d",&b);
    
    if(a==b)
        printf("a == b\n");    
    else if(a<b)
        printf("a < b\n");
    else
        printf("a > b\n");
    
    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n, x, t;
    cin >> n >> x >> t;
    ll kam = n / x + (n % x != 0);
    cout << kam * t;

    return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	vector<int>v;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		v.push_back(x);

	}
	sort(v.begin(), v.end());
	int ans=0;
	for(int i=0;i<k;i++){
		ans+=v[i];
	}
	cout<<ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < int(n); i++)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FOREACH(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define SIZE(v) ((int)(v).size())
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define ll long long
#define llint long long
#define pii pair<int, int>
#define UNVISITED -1


template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}
 
template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
 
class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

int getVal(deque<pii>& data, int val) {
    int l = 0, r = (int)data.size() - 1;
    while(l != r) {
        int m = (l + r)/2;
        if(data[m].first > val) r = m;
        else l = m + 1;
    }
    return data[l].second - 2;
}



int main() {
    int N, Q; scanf("%d %d", &N, &Q);
    set<int> usedO, usedT;

    ll ans = 1ll*(N - 2)*(N - 2);
    int O = N, T = N;
    deque<pii> dataO, dataT;
    dataO.pb(mp(N, N));
    dataT.pb(mp(N, N));

    REP(i, Q) {
        int t, x; scanf("%d %d", &t, &x);
        if(t == 1) {
            if(usedO.count(x) == 1) continue;
            usedO.insert(x);
            ans -= getVal(dataO, x);
            if(x < O) {

                O = x;
                if(T == dataT[0].first) dataT[0].second = O;
                else dataT.push_front(mp(T, O));
            }
        }
        else {
            if(usedT.count(x) == 1) continue;
            usedT.insert(x);
            ans -= getVal(dataT, x);
            if(x < T) {

                T = x;
                if(O == dataO[0].first) dataO[0].second = T;
                else dataO.push_front(mp(O, T));
            }
        }
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 13908
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using graph = vector<vector<int>>;
using wgraph = vector<vector<pair<int, lint>>>;
const lint INF = 1001001001001001LL;
const lint MOD = 1000000007LL;
const double PI = 3.1415926535897932;
int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

void yes(){ cout << "yes" << endl; }
void Yes(){ cout << "Yes" << endl; }
void YES(){ cout << "YES" << endl; }
void no(){ cout << "no" << endl; }
void No(){ cout << "No" << endl; }
void NO(){ cout << "NO" << endl; }
void possible(){ cout << "possible" << endl; }
void Possible(){ cout << "Possible" << endl; }
void POSSIBLE(){ cout << "POSSIBLE" << endl; }
void impossible(){ cout << "impossible" << endl; }
void Impossible(){ cout << "Impossible" << endl; }
void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for(int i = s; i < t; i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()


int main(){
  
  lint n; cin >> n;
  cin >> n;
  vector<pair<lint, lint>> vp(n);
  rep(i, n){
    lint a, b; cin >> a >> b;
    vp[i].first = b;
    vp[i].second = a;
  } 

  sort(all(vp));
  lint ans = 0;
  lint pre = 0;
  rep(i, n){
    cerr << pre << " " << vp[i].second << " " << vp[i].first << endl;
    if(vp[i].second <= pre) continue;
    else{
      cerr << "cut!!" << endl;
      pre = vp[i].first - 1;
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}

int main (){
    int n;
    int ans=0;
    int mn=inf;
    cin >> n;
    rep(i,n){
        int s;
        cin >> s;
        ans+=s;
        if(s%10!=0)mn=min(mn,s);
    }
    if(mn==inf) cout << 0 <<endl;
    else if(ans%10!=0) cout << ans <<endl;
    else cout << ans-mn <<endl;
    return 0;
}



Measured memory_bytes: 256
S=input()
l = len(S)
#keyencexxxxx
if S[:7]=="keyence":
  print("YES")
#kxxxxxeyence
elif S[:1]=="k" and S[l-6:]=="eyence":
  print("YES")
#kexxxxxyence
elif S[:2]=="ke" and S[l-5:]=="yence":
  print("YES")
#keyxxxxxence
elif S[:3]=="key" and S[l-4:]=="ence":
  print("YES")
#keyexxxxxnce
elif S[:4]=="keye" and S[l-3:]=="nce":
  print("YES")
#keyenxxxxxce
elif S[:5]=="keyen" and S[l-2:]=="ce":
  print("YES")
#keyencxxxxxe
elif S[:6]=="keyenc" and S[l-1:]=="e":
  print("YES")
#xxxxxkeyence
elif S[l-7:]=="keyence":
  print("YES")
else:
  print("NO")


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

int main() {
	int N, M, sum = 0; cin >> N;
	vector<int> T(N);
	for( int &k : T ) cin >> k;
	for( int k : T ) sum += k;
	cin >> M;
	int p, x, ssum;
	for( int i = 0; i < M; i++ ){
		cin >> p >> x;
		ssum = sum;
		ssum += x;
		ssum -= T[p-1];
		cout << ssum << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>

int i,j,k;
int n,a[5010],x,ans=0;

int main(){
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		a[0]=a[1]=0;ans=-100001;
		for(i=1;i<=n;i++){
			scanf("%d",&x);
			a[i]+=x;
			a[i+1]=a[i];
		}
		for(i=0;i<=n-1;i++){
			for(j=i+1;j<=n;j++){
				if(a[j]-a[i]>ans)ans=a[j]-a[i];
			}
		}
		printf("%d\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
bool pri[100100];
int lik[100100];
int main()
{
	memset(pri,false,sizeof(pri));
	for(int i=2;i<100100;i++){
		if(pri[i]) continue;
		for(int j=i+i;j<100100;j+=i) pri[j]=true;
	}
	lik[0]=0;
	rep(i,100100){
		lik[i+1]=lik[i];
		if(i%2==1 && i>2 && !pri[i] && !pri[(i+1)/2]){
			//if(i<20) cout<<i<<endl;
			lik[i+1]++;
		}
	}
	int q,l,r;
	cin>>q;
	rep(i,q){
		cin>>l>>r;
		cout<<lik[r+1]-lik[l]<<endl;
	}
}


Measured memory_bytes: 1152
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    string S;
    cin >> S;

    if (S == "ABC") {
        cout << "ARC" << endl;
    } else {
        cout << "ABC" << endl;
    }

    return 0;
}



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

const int MAX_TOWN = 50;

int main()
{
	int N, M;
	cin >> N >> M;
	vector<int> r(MAX_TOWN + 1, 0);

	for ( int i = 0; i < M; ++i ) {
		int a, b;
		cin >> a >> b;
		r[a]++;
		r[b]++;
	}

	for ( int i = 1; i <= N; ++i ) {
		cout << r[i] << endl;
	}

	return 0;
}

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

int main() {
    int H;//高さ
    int W;//幅
    string sharp = "#";
    cin >> H >> W;
    vector<string> pixel(H);
    
    for(int i = 0;i < W + 2; i++){//上段の＃を出力
        cout << sharp;
    }
    cout << endl;
    for(int i = 0; i < H; i++){//文字のある行を出力
        string pixel;
        cin >> pixel;
        cout << sharp;
        for(int j = 0;j < W; j++){
            cout << pixel.at(j); 
        }
        cout << sharp <<endl;
    }
    
    for(int i = 0;i < W + 2; i++){//下段の＃を出力
        cout << sharp;
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <stdio.h>
#include <cmath>
#include <sstream>
#include <algorithm>
#include <iomanip>

#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define vi vector<int>
#define vl vector<long long>
#define sz size()
#define x first
#define y second
#define pii pair<int, int>
#define pll pair<ll, ll>


using namespace std;
stack<char> st;
string s;

int main() {
	//freopen("", "r", stdin);                
	//freopen("", "w", stdout);
	cin >> s;
	
	for(int i = 0; i < s.sz; i++) {
		if(s[i] == 'S') st.push(s[i]);
		else {
			if(!st.empty() && st.top() == 'S') st.pop();
			else	st.push(s[i]);
		}
	}
	if(!st.empty()) cout << st.sz;
	else cout << 0;
	return 0;
}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
int main(){
	for(;;){
		int H,W;
		cin>>H>>W;
		if(H==0&&W==0)break;
		for(int i=0;i<W;i++){
			cout<<'#';
		}
		cout<<endl;
		for(int j=0;j<H-2;j++){
			cout<<'#';
			for(int k=0;k<W-2;k++){
				cout<<'.';
			}
			cout<<'#'<<endl;
		}
		for(int l=0;l<W;l++){
			cout<<'#';
		}
		cout<<endl<<endl;
	}
}



Measured memory_bytes: 3056
import java.util.*;

public class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	long n = sc.nextLong();
	long a = sc.nextLong();
	long b = sc.nextLong();
	System.out.print(n / (a+b) * a + Math.min(n%(a+b), a));
    }
}


Measured memory_bytes: 35516
n,m,p = map(int, input().split())
es = []
g1 = [[]for _ in range(n)]
g2 = [[] for _ in range(n)]
li = []
for i in range(m):
  a,b,c = map(int, input().split())
  li.append((a - 1,b - 1,c))
  g1[a - 1].append((b - 1,(c-p)*-1))
  g2[b - 1].append((a - 1,(c-p)*-1))
done1 = [0] * n
done1[0] = 1
s = [0]
while s:
  d = s.pop()
  for node,_ in g1[d]:
    if not done1[node]:
      done1[node] = 1
      s.append(node)
done2 = [0] * n
done2[n - 1] = 1
s = [n - 1]
while s:
  d = s.pop()
  for node, _ in g2[d]:
    if not done2[node]:
      done2[node] = 1
      s.append(node)
done = [0] * n
for i in range(n):
  done[i] = done1[i] & done2[i]
for a,b,c in li:
  if done[a] & done[b]:
    es.append((a,b,(c-p)*-1))
m = len(es)
d = [0]*n
for i in range(n):
  for j in range(m):
    f, t, c = es[j]
    if d[t] > d[f] + c:
      d[t] = d[f] + c
      if i == n - 1:
        print(-1)
        exit(0)
d = [float('inf')] * n
d[0] = 0
while(True):
  update = False
  for i in range(m):
    f, t, c = es[i]
    if d[f] != float('inf') and d[t] > d[f] + c:
      d[t] = d[f] + c
      update = True
  if not update:
    break
print(max(0, -d[n - 1]))

Measured memory_bytes: 55380
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<string> 
#include<queue>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
	int n,i,x,min=1e9+5,item=0,a[100005];
	cin>>n;
	for(i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	x=(a[n-1]+1)/2;
	for(i=0;i<n-1;i++)
	{
		if(abs(x-a[i])<min)
		{
			min=abs(x-a[i]);
			item=i;
		}
	}
	printf("%d %d\n",a[n-1],a[item]);
	return 0;
} 

Measured memory_bytes: 640
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    int n = 0;
    cin >> n;
    int buf = 0;
    int cnt_free = 0, cnt = 0;
    vector<bool> color(8, false);
    for (int i=0; i<n; i++) {
        cin >> buf;
        if (buf >= 3200) {
            cnt_free++;
        }
        else if (buf >= 2800) {
            if (!color.at(7)) {
                color.at(7) = true;
                cnt++;
            }
        }
        else if (buf >= 2400) {
            if (!color.at(6)) {
                color.at(6) = true;
                cnt++;
            }
        }
        else if (buf >= 2000) {
            if (!color.at(5)) {
                color.at(5) = true;
                cnt++;
            }
        }
        else if (buf >= 1600) {
            if (!color.at(4)) {
                color.at(4) = true;
                cnt++;
            }
        }
        else if (buf >= 1200) {
            if (!color.at(3)) {
                color.at(3) = true;
                cnt++;
            }
        }
        else if (buf >= 800) {
            if (!color.at(2)) {
                color.at(2) = true;
                cnt++;
            }
        }
        else if (buf >= 400) {
            if (!color.at(1)) {
                color.at(1) = true;
                cnt++;
            }
        }
        else if (buf >= 0) {
            if (!color.at(0)) {
                color.at(0) = true;
                cnt++;
            }
        }
    }
    if (cnt == 0) {
        cout << 1 << " " << cnt_free << endl;
    }
    else {
        cout << cnt << " " << cnt+cnt_free << endl;
    }
    return 0;
}


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

int main(){
  int N;
  int A = 0, B = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      A += vec.at(i);
    }
    if(i % 2 == 1){
      B += vec.at(i);
    }
  }
  
  cout << A - B << endl;
}


Measured memory_bytes: 256
from bisect import bisect, bisect_left
N = int(input())
L = list(map(int, input().split()))

L.sort()
cnt = 0
for i in range(N-1):
    for j in range(i):
        a, b = L[i], L[j] 
        r = bisect_left(L[i+1:], a+b) + i+1
        cnt += max(r - i - 1, 0)
            
print(cnt)            

Measured memory_bytes: 50140
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	rep(i, 0, s.size()) {
		int x = (s[i] - 'A' + n) % 26;
		cout << char(x+'A');
	}
	cout << endl;
}


Measured memory_bytes: 3576
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char

main = do
  n <- (read :: String -> Int) <$> getLine
  let base = ord 'a'
  ans <- foldM
    (\acc i -> do
      arr <- map ord . sort <$> getLine
      let counts = count arr [0] base
      return . map (uncurry min) $ zip counts acc
    )
    (take 26 [50, 50..])
    [1 .. n]
  putStrLn . concatMap (\(c, i) -> [ chr (base + c) | i <- [1 .. i] ]) $ zip
    [0 ..]
    ans

count :: [Int] -> [Int] -> Int -> [Int]
count (x : xs) (y : ys) n = if x == n
  then count xs (y + 1 : ys) n
  else count (x : xs) (0 : y : ys) (n + 1)
count [] y n = reverse y




Measured memory_bytes: 1020
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll LINF = LLONG_MAX;
// const ll MOD = 1e9+7;
const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

ll modPow(ll x, ll n){ //x^n(mod M) ←普通にpow(x,n)では溢れてしまうため，随時mod計算
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

struct Combination {
    vector<ll> fac, finv, inv;
    Combination (int MAX) {
        fac.resize(MAX);
        finv.resize(MAX);
        inv.resize(MAX);
    }
    void COMinit(int MAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < MAX; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }

    // 二項係数計算
    ll COM(int n, int k){
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int N,M,K;
    cin >> N >> M >> K;

    // resolve
    if (N==1) {
        cout << M << endl;
        return 0;
    }
    Combination cb(N);
    cb.COMinit(N);
    ll ans = 0;
    for (int i=0; i<=K; i++) {
        ll ans_tmp = M;
        ans_tmp *= modPow(M-1, N-1-i);
        ans_tmp %= MOD;
        ans_tmp *= cb.COM(N-1,i);
        ans += ans_tmp;
        ans %= MOD;
    }

    // output
    cout << ans%MOD << endl;

    return 0;
}


Measured memory_bytes: 7924
import sys
input = sys.stdin.buffer.readline

def main():
    N,x = map(int,input().split())
    
    if N == 2:
        if x == 2:
            print("Yes")
            print(1)
            print(2)
            print(3)
        else:
            print("No")
    else:
        if x == 1 or x == 2*N-1:
            print("No")
        elif x == 2*N-2:
            print("Yes")
            ans = [i+1 for i in range(2*N-1)]
            ans[N-1],ans[2*N-2] = ans[2*N-2],ans[N-1]
            ans[N-2],ans[2*N-3] = ans[2*N-3],ans[N-2]
            for num in ans:
                print(num)
        else:
            print("Yes")
            b = [True for _ in range(2*N-1)]
            use = [x+1,x-1,x,x+2]
            ans = []
            for num in use:
                b[num-1] = False
            p = 0
            while len(ans)<N-3:
                if b[p]:
                    ans.append(p+1)
                    b[p] = False
                p += 1
            ans += use
            while len(ans)<2*N-1:
                if b[p]:
                    ans.append(p+1)
                    b[p] = False
                p += 1
            for num in ans:
                print(num)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 14076
from collections import*
n,k=[int(i) for i in input().split()]
l=input().split()
a=Counter(l)
ca=a.most_common()
val=len(set(l))
s=0
if val < k:
	k=val
for i in range(k):
	s +=ca[i][1]
print(n-s)

Measured memory_bytes: 115276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()

int main(){
  string S;cin>>S;
  if(S=="RRR")cout<<3<<endl;
  else if(S=="RRS" || S=="SRR") cout<<2<<endl;
  else if(S=="SSS") cout<<0<<endl;
  else cout<<1<<endl;
}

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

int main(){
    int K;
    cin >> K;
    queue<int64_t> lunlun;
    for(int i=1; i<10; i++) lunlun.push(i);

    int64_t t;
    for(int i=0; i<(K-1); i++){
        t = lunlun.front();
        lunlun.pop();
        if(t%10 != 0) lunlun.push(t * 10 + (t % 10 - 1));
        lunlun.push(t * 10 + t % 10);
        if(t%10 != 9) lunlun.push(t * 10 + (t % 10 + 1));
    }

    cout << lunlun.front() << endl;
}

Measured memory_bytes: 5024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define pint pair<int,int>
#define pll pair<ll,ll>
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int n;
  cin >> n;
  ll a[n];
  rep(i,n)cin >> a[i];
  ll sum[n]={},sum2[n]={};
  ll temp=0,temp2=0;
  rep(i,n){
    if(i==0){
      sum[i]=a[i];
      if(a[i]<=0){
        temp+=-a[i]+1;
        sum[i]=1;
      }
    }
    else{
      sum[i]=a[i]+sum[i-1];
      if(sum[i]*sum[i-1]>=0){
        if(i%2==0){
          temp+=-sum[i]+1;
          sum[i]=1;
        }else{
          temp+=sum[i]+1;
          sum[i]=-1;
        }
      }
    }
  }
  rep(i,n){
    if(i==0){
      sum2[i]=a[i];
      if(sum2[i]>=0){
        temp2+=a[i]+1;
        sum2[i]=-1;
      }
    }
    else{
      sum2[i]=a[i]+sum2[i-1];
      if(sum2[i]*sum2[i-1]>=0){
        if(i%2==0){
          temp2+=sum2[i]+1;
          sum2[i]=-1;
        }else{
          temp2+=-sum2[i]+1;
          sum2[i]=1;
        }
      }
    }
  }
//  cout << temp << ' ' << temp2 << endl;
  cout << min(temp,temp2) << endl;
return 0;}

Measured memory_bytes: 2560
n,m=map(int,input().split())
number_dict=dict()
a=list(map(int,input().split()))
for i in a:
  if i in number_dict:
    number_dict[i]+=1
  else:
    number_dict[i]=1

for i in range(m):
  b,c=map(int,input().split())
  if c in number_dict:
    number_dict[c]+=b
  else:
    number_dict[c]=b
number_dict_sort=sorted(number_dict,reverse=True)
#print(number_dict_sort)
#print(number_dict)
ans=0
for i in number_dict_sort:
  #print(i,ans)
  if n-number_dict[i]>=0:
    n-=number_dict[i]
    ans+=i*number_dict[i]
  else:
    ans+=n*i
    break
print(ans)




Measured memory_bytes: 32064
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin>>h>>w;
    vector<vector<string>> s(h);
    rep(i, h)
    {
        s[i].resize(w);
        rep(j, w)
                cin >>
            s[i][j];
    }
    rep(i, h)
    {
        rep(j,w)
        {
            if (s[i][j]=="snuke"){
                cout<<char('A'+j)<<i+1<<"\n";
                return 0;
            }
        }
    }
}


Measured memory_bytes: 256