akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

//以下回答
int main(){
    ll N,M;
    cin>>N>>M;
    map<ll,ll> m;
    string S="1";
    rep(i,N-1){
        S+='0';
    }
    if(N==1&&M==0){
        cout<<0<<endl;
        return 0;
    }
    rep(i,M){
        ll a;
        char b;
        cin>>a>>b;
        m[a]++;
        if(m[a]>1&&S.at(a-1)!=b){
            cout<<-1<<endl;
            return 0;
        }
        S.at(a-1)=b;
    }
    if(S=="0"){
        cout<<S<<endl;
    }
    else if(S.at(0)=='0'){
        cout<<-1<<endl;
    }else{
        cout<<S<<endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int n, m;
	LinkedList<E>[] edges;
	
	@SuppressWarnings("unchecked")
	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		m = sc.nextInt();
		
		edges = new LinkedList[n];
		for(int i=0;i<n;i++) edges[i] = new LinkedList<E>();
		
		for(int i=0;i<m;i++) {
			String[] strs = sc.next().split(",");
			int[] vals = new int[4];
			
			for (int j = 0; j < 4; j++) {
				vals[j] = Integer.parseInt(strs[j]);
			}
			
			edges[vals[0]-1].add(new E(vals[1]-1, vals[2]));
			edges[vals[1]-1].add(new E(vals[0]-1, vals[3]));
		}
		
		String[] strs = sc.next().split(",");
		int[] vals = new int[4];
		
		for (int j = 0; j < 4; j++) {
			vals[j] = Integer.parseInt(strs[j]);
		}
		int val = dijkstra(vals[0]-1, vals[1]-1) + dijkstra(vals[1]-1, vals[0]-1);
		System.out.println( (vals[2] - vals[3] - val) );
	}
	
	int dijkstra(int s, int g) {
		int d[] = new int[n];
		fill(d, INF);
		d[s] = 0;
		PriorityQueue<E> que = new PriorityQueue<E>();
		que.add(new E(s, 0));
		
		for(;;) {
			E now = que.poll();
			
			if(now.to == g) return now.cost;
			if(now.cost != d[now.to]) continue;
			for(E edge: edges[now.to] ) if( d[edge.to] > d[now.to] + edge.cost ){
				que.add(new E(edge.to, d[now.to]+edge.cost));
				d[edge.to] = d[now.to]+edge.cost;
			}
		}
	}
	
	class E implements Comparable<E>{
		int to, cost;
		E(int to, int cost) {
			this.to = to;
			this.cost = cost;
		}
		@Override
		public int compareTo(E o) {
			// TODO 自動生成されたメソッド・スタブ
			return cost - o.cost;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
n,m = map(int,input().split())
e = [0]*m

for i in range(m):
    a,b = map(int,input().split())
    e[m-1-i] = [a-1,b-1]

root = [-1]*n
rank = [0]*n
    
def find(x):
    if root[x] < 0:
        return x
    else:
        root[x] = find(root[x])
        return root[x]

def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return
    elif rank[x] > rank[y]:
        root[x] += root[y]
        root[y] = x
    else:
        root[y] += root[x]
        root[x] = y
        if rank[x] == rank[y]:
            rank[y] += 1

def same(x,y):
    return find(x) == find(y)

def cnt(x):
    return root[find(x)]


ans = [0]*m
ans[0] = n*(n-1) // 2

for i in range(1,m):
    if same(e[i-1][0],e[i-1][1]):
        ans[i] = ans[i-1]
    else:
        ans[i] = ans[i-1] - cnt(e[i-1][0]) * cnt(e[i-1][1])
    unite(e[i-1][0],e[i-1][1])

for i in range(m):
    print(ans[m-1-i])

Measured memory_bytes: 26392
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_069_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(7).
    01 n      PIC 9(3).
    01 m      PIC 9(3).

    01 tmp    PIC 9(4).

    01 ans    PIC X(4).

    01 ZS     PIC Z(5).
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO n m.

    SUBTRACT 1 FROM n.
    SUBTRACT 1 FROM m.

    MULTIPLY n BY m GIVING tmp.

    MOVE tmp TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 384
/**
 * @author torith
 * @date 2018-10-26
 */

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    int four = 0, two = 0;
    for (int i = 0; i < N; ++i) {
        int t; cin >> t;
        if (t % 4 == 0) four ++;
        else if(t % 2 == 0) two ++;
    }

    if(two/2 + four >= N / 2){
        cout << "Yes" << "\n";
    }else{
        cout << "No" << "\n";
    }

    return 0;
}



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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

int h, w, k;

map<pair<int, int>, long long> dp;

long long dfs(int now, int x) {
	if (now == h) return x == k - 1;
	auto status = make_pair(now, x);
	if (dp.count(status)) return dp[status];
	long long res = 0;
	for (int i = 0; i < 1 << (w - 1); i++) {
		bool check = true;
		for (int j = 0; j < w - 2; j++) {
			if ((i >> j & 1) && (i >> (j + 1) & 1)) {
				check = false;
				break;
			}
		}
		if (check) {
			if (0 < x && (i >> (x - 1) & 1)) {
				res += dfs(now + 1, x - 1);
				res %= INF;
			}
			else if (x + 1 < w && ((i >> x) & 1)) {
				res += dfs(now + 1, x + 1);
				res %= INF;
			}
			else {
				res += dfs(now + 1, x);
				res %= INF;
			}
		}
	}
	return dp[status] = res;
}

void hawawa()
{
	int n, k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double cnt = 1. / n;
		for (int j = i; j < k; j *= 2) {
			cnt /= 2;
		}
		ans += cnt;
	}
	cout << fixed << setprecision(10) << ans << "\n";
}


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


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

int calc(){
	
	return 0;
}

int main(){
	int a, b = 0, c;
	cin >> a;
	c = a;
	for(int i = 0;a != 0;i++){
		b += a % 10;
		a = (a-(a%10))/10;
	}
	//cout << endl << b << endl;
	if(c % b == 0 || b % c == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    ll x[n], y[n];
    ll xa[n], ya[n];
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        xa[i] = x[i];
        ya[i] = y[i];
    }
    sort(xa, xa + n);
    sort(ya, ya + n);
    ll ans = (xa[n - 1] - xa[0]) * (ya[n - 1] - ya[0]);
    for (int xi = 0; xi < n; xi++) {
        for (int xj = n - 1; xj > xi; xj--) {
            for (int yi = 0; yi < n; yi++) {
                for (int yj = n - 1; yj > yi; yj--) {
                    ll lx = xa[xi], rx = xa[xj];
                    ll ly = ya[yi], ry = ya[yj];
                    int c = 0;
                    for (int i = 0; i < n; i++) {
                        if (lx <= x[i] && x[i] <= rx && ly <= y[i] && y[i] <= ry) c++;
                    }
                    if (c >= k) ans = min(ans, (rx - lx) * (ry - ly));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int n, m, l;
	(void)scanf("%d %d %d", &n, &m, &l);
	vector<vector<int> > a(n, vector<int>(m, 0));
	vector<vector<int> > b(m, vector<int>(l, 0));
	vector<vector<long> > c(n, vector<long>(l, 0));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			(void)scanf("%d", &a[i][j]);
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			(void)scanf("%d", &b[i][j]);
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	for (int j = 0; j < n; j++) {
		for (int k = 0; k < l; k++) {
			printf("%ld", c[j][k]);
			if (k == l - 1) printf("\n");
			else printf(" ");
		}
	}
	return 0;
}


Measured memory_bytes: 2872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const ll MOD = 1e9 + 7;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int a, b;
  cin >> a >> b;
  int a_min, a_max, b_min, b_max;
  a_min = a*12.5; a_max = (a+1)*12.5;
  if (a%2!=0) a_min++;
  if ((a+1)%2==0) a_max--;
  b_min = b*10; b_max = (b+1)*10 - 1;
  int ans = 0;
  if (a_max < b_min || b_max < a_min) ans = -1;
  else if (b_min <= a_max && a_min <= b_min && a_max <= b_max) ans = b_min;
  else if (a_min <= b_max && b_min <= a_min && b_max <= a_max) ans = a_min;
  else if (a_min <= b_min && b_max <= a_max) ans = b_min;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


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

int main() {
  long A, B, K; cin >> A >> B >> K;
  long a, b, k;

  a = max(A-K, 0L);
  k = max(K-A, 0L);
  b = max(B-k, 0L);
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int l,r,d;
  cin>>l>>r>>d;
  int cnt=0;
  for (int i = l; i <= r; ++i)
  {
    if(i%d==0) cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 3612
import itertools
def main():
    n,m,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    b=[int(i) for i in input().split()]
    a = [0]+list(itertools.accumulate(a))
    b = [0]+list(itertools.accumulate(b))
    res = 0
    j = m
    best=0
    i=0

    while(i<n+1):
        if(a[i]>k):
            break
        while(b[j]+a[i]>k):
            j-=1
        res = max(res,i+j)
        i+=1
    print(res)



if __name__ == '__main__':
    main()


Measured memory_bytes: 41624
;;cyclone-loop
(defun cyclone-reader (stream char)
  (declare (ignore char))
  `(loop ,@(read stream t nil t) do ,(read stream t nil t)))
(set-macro-character #\CYCLONE #'cyclone-reader)
;;

;;unnamed-block
(defun block-reader (stream char)
  (declare (ignore char))
  `(progn ,@(read-delimited-list #\} stream t)))
(set-macro-character #\{ #'block-reader)
(set-macro-character #\} (get-macro-character #\)))
;;

(let ((n (read))
      (m (read))
      (k (read))
      (ans "No"))
  🌀 (for r to n)
  🌀 (for l to m
            :for black = 0)
  {(incf black (* l n))
   (incf black (* r m))
   (decf black (* 2 l r))
   (when (= black k) (setf ans "Yes")) }
  (format t "~A~%" ans))

Measured memory_bytes: 16996
S = list(map(int, input()))
score = 0
length = len(S)

for i in range(length):
	goal = lambda x : 0 if x % 2 == 0 else 1
	score += abs(S[i] - goal(i))
	
if score < length / 2:
	print(score)
else:
	print(length - score)

Measured memory_bytes: 45020
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	int ans = 0, cur = 2;
	for (int i = 2; i <= 1e6; i++) {
		if (n % i == 0) {
			int cnt = 0;
			while (n % i == 0) {
				n /= i;
				cnt++;
			}
			for (int j = 1; 1; j++) {
				if (cnt >= j) {
					ans++;
					cnt -= j;
				}
				else break;
			}
		}
	}
	if (n > 1) ans++;
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <string>
int main(){
	std::string s,x;
	int a=0;
	while(std::cin>>s){
		int i=0,n=s.size();
		x="";
		for (;i<n;i++)
			if (isdigit(s[i])) x+=s[i];
			else
				if (!x.empty()){
					a+=atoi(x.c_str());
					x="";
				}
		if (!x.empty())a+=atoi(x.c_str());
	}
	std::cout<<a<<"\n";
}

Measured memory_bytes: 1196
<?php
fscanf(STDIN,"%s",$s);

$a[0]=substr($s,0,1);
$a[1]=substr($s,1,1);
$a[2]=substr($s,2,1);
$a[3]=substr($s,3,1);

sort($a,SORT_ASC);

if($a[0]==$a[1] && $a[2]==$a[3] && $a[0]<>$a[3]){
	echo "Yes";
}else{
	echo "No";
}

?>

Measured memory_bytes: 3828
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rrep(i, n) for(int i=n-1; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010][2];

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

    dp[0][0] = 1;
    dp[0][1] = 2;
    for (int i = 1; i < n; i++) {
        int now = s[i] - '0';

        dp[i][0] = 3 * dp[i-1][0];
        dp[i][0] %= MOD;

        if (now == 1) {
            dp[i][0] += dp[i-1][1];
            dp[i][0] %= MOD;
        }

        if (now == 0) {
            dp[i][1] = dp[i-1][1];
        } else {
            dp[i][1] = dp[i-1][1] * 2;
            dp[i][1] %= MOD;
        }
    }

    cout << (dp[n-1][0] + dp[n-1][1]) % MOD << endl;
}


Measured memory_bytes: 2048
cal_list = input().split()

while cal_list[1] != "?":
    if cal_list[1] == "+":
        print(int(cal_list[0]) + int(cal_list[2]))
    elif cal_list[1] == "-":
        print(int(cal_list[0]) - int(cal_list[2]))
    elif cal_list[1] == "/":
        ans = int(cal_list[0]) / int(cal_list[2])
        print(int(ans))
    else:
        print(int(cal_list[0]) * int(cal_list[2]))
    cal_list = input().split()


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define line                    cout << "\n===================\n"

int main ()
{
    // freopen ("input.txt", "r", stdin);
    //freopen ("output.txt", "w", stdout);
    //fastRead;
	string s;
	cin >> s;
	int len = s.size();
	int res = 0;
	for (int i = 0, j = len - 1; i < len / 2; i++, j--){
		if (s[i] != s[j]){
			res++;
		}
	}
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
m = [300000, 200000, 100000, 0]
if x > 3:
    x = 4
if y > 3:
    y = 4
ans = m[x - 1] + m[y - 1]
if ans == 600000:
    print(ans + 400000)
else:
    print(ans)


Measured memory_bytes: 2940
import sys
import collections

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = tin()
	#s = input()
	tree = [[] for _ in range(n)]
	for _ in range(n-1):
		a, b = tin()
		tree[a-1].append(b-1)
		tree[b-1].append(a-1)
	
	ret = k
	qq = collections.deque()
	qq.append([0, -1])
	opened = set()
	opened.add(0)
	while qq:
		pos, parent = qq.popleft()
		i=0
		for np in tree[pos]:
			if np == parent:
				continue
			qq.append((np, pos))
			
			add = 0
			if parent == -1:
				add = 1
			
			ret *= k-i-2+(add)
			ret %= mod
			i+=1
			#pa((ret, add, parent))
			
	print(ret)
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	string s; cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << '\n';
	}
	else cout << "No" << '\n';


}

Measured memory_bytes: 256
#include <iostream>
    #include <string>
    #include <set>  
    #include <stack>
    #include <algorithm>
    #include <vector>
    #include <cmath>
    #include <queue>
    #include <deque>
    #include <cstring>
    #include <cstdio>
    #include <map>
    #include <numeric>
    #include <cassert>
    #include <iomanip>
    #include <sstream>
    #include <ctime>
    #include <bitset> 
    #include <unordered_map>
using namespace std;
#define for1(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,maxn) for1(i,0,maxn)
#define ford(i,b,a) for(int i=(int)(b)-1;i>=a;--i)
typedef long long ll;
typedef unsigned long long int128;
typedef pair<int,int> pii;
typedef pair<int,pii > piii;
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3f
#define mod1 1000000007
#define mod2 998244353
#define eps 1e-10
#define pi acos(-1)
#define st first
#define nd second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define dprintf(...) printf(__VA_ARGS__)
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1^1)
#define abs(x) ((x)>0?(x):(-(x)))
ll C[4040][4040];
void initC()
{
	C[0][0]=1;
	for(int i=1;i<4040;i++)
	{
		C[i][0]=C[i][i]=1;
		for(int j=1;j<i;j++)
			C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod2;
	}
}
int n,k,tmp;
vector<int> cnt_t[2020];
ll ans[4040];
int main()
{
	initC();
	scanf("%d%d",&k,&n);
	for(int i=2;i<=2*k;i++)
	{
		tmp=min(i-1,k)-(i+1)/2+1;
	//	cout<<i<<" "<<tmp<<endl;
		cnt_t[tmp].pb(i);
	}
	ll res,buf;
	for(int i=1;i<=(k+1)/2;i++)
	{
		if(cnt_t[i].empty())continue;
		res=0;
		tmp=min(i,n/2);
		for(int j=0;j<=tmp;j++)
		{
			buf=C[n+k-1-j*2][k-1]*1ll*C[i][j]%mod2;
			if(j&1)buf=-buf;
			buf=(buf+mod2)%mod2;
		//	cout<<i<<" "<<j<<" "<<buf<<endl;
		//	system("pause");
			res=(res+buf)%mod2;
		}
		res=(res+mod2)%mod2;
		rep(j,cnt_t[i].size())
			ans[cnt_t[i][j]]=res;
	}
	for(int i=2;i<=2*k;i++)
		printf("%lld\n",ans[i]);
	return 0;
}

Measured memory_bytes: 126208
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		char[] alp = new char[]{'M','A','R','C','H'};
		long[] count = new long[5];
		for( int i=1; i<=N; i++ ){
			String ss = sc.next();
			char cc = ss.charAt(0);
			for( int j=0; j<=4; j++ ){
				if( cc==alp[j] ){
					count[j]++;
					break;
				}
			}
		}
		long ans = 0;
		for( int i=0; i<=2; i++ ){
			for( int j=i+1; j<=3; j++ ){
				for( int k=j+1; k<=4; k++ ){
					ans += count[i]*count[j]*count[k];
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 45556
#include<stdio.h>

int main(){
  long long a,b,k; scanf("%lld%lld%lld",&a,&b,&k);
  if(a-k>0) printf("%lld %lld\n",a-k,b);
  else if(b-k+a>0)printf("0 %lld\n",b-k+a);
  else printf("0 0\n");
  return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const ll mod = 1e9+7;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



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

	ll ans =0;
	int h, w;
	cin >>h >>w;
	if(h <300 && w<300){
		vector<VI> ba(h, VI(w, 1));
		rep(i,h) rep(j,w){
			rep2(s,-1,2) rep2(t,-1,2){
				if(i+s<0||i+s>=h||j+t<0||j+t>=w)continue;
				ba[i+s][j+t]++;
			}
		}
		
		//for(auto xl: ba){for(auto x :xl) printf("%2d ",x); puts("");}
		rep(i,h) rep(j,w) if(ba[i][j]%2==0) ans++;
		cout << ans <<endl;
		return 0;
	}
	if(h==2 || w==2) cout << 0 <<"\n";
	else if(min(h,w)==1) cout << max(h,w)-2 <<"\n";
	else cout << (h-2LL) * (w-2LL) <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
  
#define MAX 500000
  
int Tree[MAX];  
int n;
  
void maxHeapify(int i){
  int largest ,exchange, l, r;
  l = getLeft(i);
  r = getRight(i);
    
  if((n+1 >l) && (Tree[l] > Tree[i])) largest = l;
  
  else largest = i;
    
  if((n+1 > r) && (Tree[r] > Tree[largest])) largest = r;
  
  if (largest != i){
  
    exchange = Tree[i];
    Tree[i] = Tree[largest];
    Tree[largest] = exchange;
    maxHeapify(largest);
  
  } 
}
  
void buildMaxHeap(){
  int i;
  for (i=(n/2); i+1>1; i--){
    maxHeapify(i);
     }
}
   
int getLeft(int i){
  return (2*i);
}
  
int getRight(int i){
  return (2*i + 1);
}
int getParent(int i){
  return i/2;
}
 
  
int main()
{
  int i;
  scanf("%d",&n);
  
  for(i=1; i<=n; i++){
  
    scanf("%d",&Tree[i]);
  
  }
  
  buildMaxHeap();
  
  for(i=1; i<=n; i++){
      
    printf(" %d",Tree[i]);
  
  }
  
  printf("\n");
  
  return 0;
}



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

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

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

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

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  int D,G,p[11],c[11];
  cin>>D>>G;
  rep(i,D) cin>>p[i]>>c[i];
  int ans = 1e9;
  for(int mask = 0; mask < (1 << D); ++mask){
    int s=0,num=0,rest_max=-1;
    rep(i,D) {
      if(mask>>i&1) {
      s += 100 * (i+1)*p[i] +c[i];
      num += p[i];
    } else {
      rest_max=i;
    }
  }
    if(s<G){
      int s1 = 100*(rest_max+1);
      int need = (G-s+s1-1)/s1;
      if(need>=p[rest_max]) continue;
      num+=need;
    }
    minch(ans,num);
  }
  cout<<ans<<endl;

}

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


Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

A,B,M = map(int,input().split(' '))
l_a = list(map(int, input().split()))
l_b = list(map(int, input().split()))
l_c = [list(map(int,input().split())) for _ in range(M)]

min_a = min(l_a)
min_b = min(l_b)

MIN = min_a+min_b

for i in range(M):
    k = l_c[i]
    x = k[0]
    y = k[1]
    c = k[2]
    m = l_a[x-1]+l_b[y-1]-c
    MIN = min(MIN,m)
print(MIN)

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

#define int int_least64_t

signed main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);

  int a, b, c, n; cin >> a >> b >> c >> n;
  int cnt=0;
  for (int i = 0; i <= n; i += a) {
    for (int j = 0; i+j <= n; j += b) {
      int need = n-(i+j);
      if (need%c == 0)
        ++cnt;
    }
  }
  cout << cnt << '\n';
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
  char str[21];
  char after[21];
  int i;
  /* reset */
  memset(str, '\0', sizeof(str));
  memset(after, '\0', sizeof(after));

  //fgets(str, sizeof(str), stdin);
  //str[strlen(str)-1] = '\0';
  gets(str);
  for (i=0; i < strlen(str); i++)
    {
      after[strlen(str)-1-i] = str[i];
    }

  printf("%s\n", after);

  return 0;
}

Measured memory_bytes: 524
n, m, x, y = map(int, input().split())
lx = list(map(int, input().split()))
ly = list(map(int, input().split()))

for z in range(x+1, y+1):
    if max(lx) < z and min(ly) >= z:
        print('No War')
        exit()

print('War')

Measured memory_bytes: 9096
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
using namespace std;


int main(){
    int n, m;
    vector<pair<int, int> > p(0);
    cin >> n >> m;
    
    for(int i=1;i*i<=m;i++){
        if(m % i == 0){
            p.push_back(make_pair(i, m/i));
            p.push_back(make_pair(m/i, i));
        }
    }
    sort(p.begin(), p.end());

    for(int i=0;i<p.size();i++){
        if(p[i].second < n){
            cout << p[i-1].first << endl;
            return 0;
        }
    }
    cout << p[p.size()-1].first << endl;

	return 0;
}


Measured memory_bytes: 256
from copy import deepcopy
H, W, K = map(int, input().split())

def clear(row, start, end, mult):
    if end - start + 1 < K:
        return 0
    gain = 0
    for i in range(start, end + 1):
        gain += mult * row[i]
        row[i] = 0
    return gain

def drop(board):
    for x in range(W):
        wp = 0
        for y in range(H):
            if board[y][x] > 0:
                board[wp][x] = board[y][x]
                if wp != y:
                    board[y][x] = 0
                wp += 1

def proceed(board, mult):
    gain = 0
    for row in board:
        start = -1
        num = -1
        for i in range(W):
            if row[i] == num:
                continue
            else:
                gain += clear(row, start, i-1, mult)
                num = row[i]
                start = i
        if num > 0:
            gain += clear(row, start, W-1, mult)
    drop(board)
    return gain

board_ = []
for _ in range(H):
    board_.append(list(map(int, input())))
board_.reverse()

ans = 0
for y in range(H):
    for x in range(W):
        board = deepcopy(board_)
        board[y][x] = 0
        drop(board)
        mult = 1
        cand = 0
        while True:
            gain = proceed(board, mult)
            if gain == 0:
                break
            cand += gain
            mult *= 2
        ans = max(ans, cand)
print(ans)


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

long long fact(int a){
  long long x = 1;
  for(int i=2;i<=a;++i) x*=i;
  return x;
}

int main(void){
  string s;
  cin>>s;
  map<char,int> hist;
  for(int i=0;i<s.length();++i){
    if(hist.find(s[i])!=hist.end()) ++hist[s[i]];
    else hist[s[i]]=1;
  }
  int even_count=0,odd_count=0;
  for(map<char,int>::iterator it=hist.begin();it!=hist.end();++it){
    if((*it).second%2) ++odd_count;
    else ++even_count;
  }
  long long ans=0;
  if( ( s.length()%2 && odd_count==1 ) || 
    (s.length()%2==0 && odd_count==0) )
  {
    ans = fact(s.length()/2);
    for(map<char,int>::iterator it=hist.begin();it!=hist.end();++it){
      ans /= fact((*it).second/2);
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
  vector<vector<int>> V(3,vector<int>(3,0));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++)
      cin >> V.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> W(N);
  for (int k = 0; k < N; k++)
    cin >> W.at(k);
  
  for (int l = 0; l < N; l++) {
    for (int m = 0; m < 3; m++) {
      for (int n = 0; n < 3; n++) {
        if (W.at(l) == V.at(m).at(n))
          V.at(m).at(n) = 0;
      }
    }
  }

  int count = 0;
  for (int o = 0; o < 3; o++) {
    if (V.at(o).at(0) == V.at(o).at(1) && V.at(o).at(0) == V.at(o).at(2) && V.at(o).at(2) == V.at(o).at(1))
      count++;
    if (V.at(0).at(o) == V.at(1).at(o) && V.at(1).at(o) == V.at(2).at(o) && V.at(2).at(o) == V.at(0).at(o))
      count++;
  }
  if (V.at(0).at(0) == V.at(1).at(1) && V.at(2).at(2) == V.at(1).at(1) && V.at(0).at(0) == V.at(2).at(2))
    count++;
  if (V.at(2).at(0) == V.at(1).at(1) && V.at(2).at(0) == V.at(0).at(2) && V.at(0).at(2) == V.at(1).at(1))
    count++;
  
  if (count > 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
    
} 


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

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

using namespace std;

template<typename T>
T gcd(T a, T b) {
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

int main()
{
    typedef pair<int, int> p;
    vector<p> input;

    while (1) {
        int a, b;
        cin >> a >> b;
        if (a == 0 && b == 0) {
            break;
        }
        input.push_back(p(a, b));
    }

    for (int a = 0; a < input.size(); ++a) {
        int cnt = 0;
        for (int i = 1; i <= input[a].first-2; ++i) {
            for (int j = i + 1; j <= input[a].first-1; ++j) {
                for (int k = j + 1; k <= input[a].first; ++k) {
                    if (i + j + k == input[a].second) {
                        cnt++;
                    }
                }
            }
        }
        cout << cnt << endl;
    }
}



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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

  int n;
  string s;
  cin >> n >> s;

  if (n & 1) {
    cout << "No" << endl;
    return 0;
  }

  string s1, s2;
  s1 = s.substr(0, n / 2);
  s2 = s.substr(n / 2, n / 2);

  if (s1 == s2) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

int main(void)
{
  int a,b;
  cin>>a>>b;
  cout<<(a-1)*(b-1)<<endl;
  return 0;
}


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

from collections import Counter
C=Counter(A)
ANS=0
for i in C.values():
    ANS+=i*(i-1)//2

for a in A:
    k=C[a]

    print(ANS-(k*(k-1)//2)+((k-1)*(k-2)//2))


Measured memory_bytes: 24996
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    while(cin >> n >> k and n and k) {
        vector<int> a(k);
        cin >> a;
        sort(a.begin(), a.end());
        vector<int> longest_L(k, 1), longest_R(k, 1);
        for(int i = 1; i < k; i++) {
            longest_L[i] = a[i - 1] != 0 and a[i - 1] + 1 == a[i] ? longest_L[i - 1] + 1 : 1;
        }
        for(int i = k - 2; i >= 0; i--) {
            longest_R[i] = a[i + 1] - 1 == a[i] ? longest_R[i + 1] + 1 : 1;
        }
        if(a[0] == 0) {
            int ans = 0;
            for(int i = 1; i < k; i++) {
                if(a[i] > 1) {
                    ans = max(ans, longest_R[i] + 1);
                }
                if(a[i] < n) {
                    ans = max(ans, longest_L[i] + 1);
                }
                if(i + 1 < k and a[i] + 2 == a[i + 1]) {
                    ans = max(ans, longest_L[i] + 1 + longest_R[i + 1]);
                }
            }
            cout << ans << endl;
        } else {
            cout << max(*max_element(longest_L.begin(), longest_L.end()), 
                        *max_element(longest_R.begin(), longest_R.end())) << endl; 
        }
    }
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  int arr[n];

  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }

  for (int i = n-1; i >= 0; i--) {
    cout << arr[i];
    if (i != 0) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}



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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int w, h;
int n;
vector<int> x, y;
vector<int> sx, sy;
int mx[4], my[4];
int tmp[4];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> w >> h;
    cin >> n;
    rep(i, n) {
        int xx, yy;
        cin >> xx >> yy;
        x.push_back(xx);
        y.push_back(yy);
    }
    sx = x;
    sy = y;
    sort(all(sx));
    sort(all(sy));
    mx[0] = sx[(n - 1) / 2]; my[0] = sy[(n - 1) / 2];
    mx[1] = sx[(n - 1) / 2]; my[1] = sy[n / 2];
    mx[2] = sx[n / 2]; my[2] = sy[(n - 1) / 2];
    mx[3] = sx[n / 2]; my[3] = sy[n / 2];
    vector<int> dist1, dist2, dist3, dist4;
    rep(i, n) {
        dist1.push_back(abs(x[i] - mx[0]) + abs(y[i] - my[0]));
        dist2.push_back(abs(x[i] - mx[1]) + abs(y[i] - my[1]));
        dist3.push_back(abs(x[i] - mx[2]) + abs(y[i] - my[2]));
        dist4.push_back(abs(x[i] - mx[3]) + abs(y[i] - my[3]));
    }
    sort(all(dist1));
    sort(all(dist2));
    sort(all(dist3));
    sort(all(dist4));
    rep(i, n - 1) {
        tmp[0] += 2 * dist1[i];
        tmp[1] += 2 * dist2[i];
        tmp[2] += 2 * dist3[i];
        tmp[3] += 2 * dist4[i];
    }
    tmp[0] += dist1[n - 1];
    tmp[1] += dist2[n - 1];
    tmp[2] += dist3[n - 1];
    tmp[3] += dist4[n - 1];
    int ans = 1e16;
    int ansx = 0, ansy = 0;
    rep(i, 4) {
        if (tmp[i] < ans) {
            ans = tmp[i];
            ansx = mx[i];
            ansy = my[i];
        }
    }
    cout << ans << endl;
    cout << ansx << ' ' << ansy << endl;

}

Measured memory_bytes: 10664
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
using ll=long long;

ll power(ll n,ll m)
{
    ll ans=1;
    for (int r=0;m>>r>0;r++)
    {
        if ((m>>r)&1) ans=ans*n%mod;
        n=n*n%mod;
    }
    return ans;
}

int main()
{
    ll n,m;cin >> n >> m;
    cout << power(n,m) << endl;
    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>

using namespace std;

vector<int> cups;

const int LEFT = 0;
const int CENTER = 1;
const int RIGHT = 2;

bool isMovement(int deepness, int deepest, int tray) {
	int pos = cups[deepness];
	int oppositePos = RIGHT - tray;
	if (pos == tray)
		return true;
	for (int i = deepness+1; i < deepest; i++) {
		int bigCupPos = cups[deepness];
		if (bigCupPos == tray) {
			return false;
		} else if (pos == oppositePos && bigCupPos != tray) {
			return false;
		} else if (pos == CENTER && bigCupPos == CENTER) {
			return false;
		}
	}
	return true;
}

int sortCup(int deepness, int deepest, int tray) {
	int pos = cups[deepness];
	int oppositePos = RIGHT - tray;
	int ret = 0;

	if (isMovement(deepness, deepest, tray) == true) {
		if (pos == oppositePos) {
			ret += 2;
		} else if (pos == CENTER) {
			ret += 1;
		}
		cups[deepness] = tray;
		return ret;
	}

	if (pos == oppositePos) {
		for (int i = deepness+1; i < deepest; i++) {
			ret += sortCup(i, deepest, tray);
		}
		pos = cups[deepness] = CENTER;
		ret++;
	}

	for (int i = deepness+1; i < deepest; i++) {
		ret += sortCup(i,  deepest, oppositePos);
	}
	ret++;
	cups[deepness] = tray;

	return ret;
}

int main(void) {
	int n = 0, m = 0;
	vector<int> answers;
	while ((cin >> n >> m) && n != 0 && m != 0) {
		cups.clear();
		for (int i = 0; i < n; i++) {
			cups.push_back(0);
		}

		int trayCup = 0;
		for (int j = 0; j < 3; j++) {
			cin >> trayCup;
			for (int i = 0; i < trayCup; i++) {
				int tmpCupSize = 0;
				cin >> tmpCupSize;
				cups[tmpCupSize-1] = j;
			}
		}
		int answerLeft = 0;
		vector<int> tmpCup(cups);
		for (int i = 0; i < n; i++) {
			answerLeft += sortCup(i, n, LEFT);
		}
		cups.swap(tmpCup);
		int answerRight = 0;
		for (int i = 0; i < n; i++) {
			answerRight += sortCup(i, n, RIGHT);
		}
		int answerMin = min(answerLeft, answerRight);
		if (answerMin <= m) {
			answers.push_back(answerMin);
		} else {
			answers.push_back(-1);
		}
	}

	for (int i = 0; i < answers.size(); i++) {
		cout << answers[i] << endl;
	}

	int i = 0;
	cin >> i;
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
map<string,int>cnt;
int main()
{
	int n;
	cin >>n;
	while(n--)
	{
		string a;
		cin>>a;
		cnt[a]++;
	}
	int k=0;
	for(map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	k=max(k,(*it).second);
	for(map<string,int>::iterator it=cnt.begin();it!=cnt.end();it++)
	if(k==(*it).second)
	cout<<(*it).first<<endl;
	

	return 0;
 } 

Measured memory_bytes: 25216
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N, M;
  cin>>N>>M;
  vector<Int> H(N);
  cin>>H;
  vector<vector<Int> >G(N);
  for(Int i=0;i<M;i++){
    Int a, b;
    cin>>a>>b; a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  Int ans = 0;
  for(Int i=0;i<N;i++){
    Int ok = 1;
    for(Int to:G[i]){
      if(H[i] <= H[to]) ok = 0;
    }
    ans += ok;
  }

  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9796
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	fmt.Println(min(solve(true, a), solve(false, a)))
}

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

func solve(p bool, a []int) int {
	var sum, cnt int
	m, n := 1, 0
	if p {
		m, n = 0, 1
	}
	for i := 0; i < len(a); i++ {
		sum += a[i]
		if i%2 == m && sum <= 0 {
			cnt += 1 - sum
			sum = 1
		}
		if i%2 == n && sum >= 0 {
			cnt += sum + 1
			sum = -1
		}
	}
	return cnt
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    string result;

    int countAC = 0, countWA = 0, countTLE = 0, countRE = 0;

    for (int i = 0; i < N; i++)
    {
        cin >> result;

        if (result == "AC")
        {
            countAC += 1;
        }
        else if (result == "WA")
        {
            countWA += 1;
        }
        else if (result == "TLE")
        {
            countTLE += 1;
        }
        else if (result == "RE")
        {
            countRE += 1;
        }
    }

    cout << "AC x " << countAC << endl;
    cout << "WA x " << countWA << endl;
    cout << "TLE x " << countTLE << endl;
    cout << "RE x " << countRE << endl;

    return 0;
}

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) {
				if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k];
			}
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << 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;

int b[10][10000];
int main() {
	int r, c;
	while (scanf("%d%d", &r, &c), r) {
		rep(i, r)rep(j, c)scanf("%d", &b[i][j]);
		int Max = 0;
		rep(i, 1 << r) {
			int sum = 0;
			rep(j, c) {
				int a[2]{};
				rep(k, r) {
					if (i >> k & 1)a[!b[k][j]]++;
					else a[b[k][j]]++;
				}
				sum += max(a[0], a[1]);
			}
			Max = max(Max, sum);
		}
		printf("%d\n", Max);
	}
}

Measured memory_bytes: 3592