akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    int color = 10000;
    int cnt = 0;
    REP(i, N - 1) {
        if(a[i] == a[i + 1]) {
            a[i + 1] = color;
            color--;
            cnt++;
        }
    }

    cout << cnt << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

string s;

void solve(){
    int n = s.size();
    if(s[0] == s[n-1]) {
        cout << (n % 2 == 0 ? "First" : "Second") << "\n";
        return ;
    }

    cout << (n % 2 == 1 ? "First" : "Second") << "\n";

}

int main() {
    while(cin >> s) solve();
    return 0;
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = [int(input()) for _ in range(N)]
largest_num = 0
largest_ind = -1
second_large_num = 0

for i in range(N):
	if A[i] > largest_num:
		second_large_num = largest_num
		largest_num = A[i]
		largest_ind = i
	elif A[i] > second_large_num:
		second_large_num = A[i]
		
for i in range(N):
	if i == largest_ind:
		print(second_large_num)
	else:
		print(largest_num)

Measured memory_bytes: 58800
import java.io.*
import java.util.*

fun solve(N: Int, S: String){
    var ans =0
    for(i in 1 until N - 1){
        ans = Math.max(ans, calc(S.slice(0 until i), S.slice(i until N)))
    }
    println(ans)
    return
}

fun calc(a: String, b: String): Int{
    return a.toSet().distinct().count{ it in b }
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val S = sc.next()
    solve(N, S)
}



Measured memory_bytes: 33788
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		for(int i = 0; i < str.length(); i++){
			char c = str.charAt(i);
			if(Character.isLowerCase(c)){
				System.out.print(Character.toUpperCase(c));
			}
			else{
				System.out.print(Character.toLowerCase(c));
			}
		}System.out.println();
	}

}

Measured memory_bytes: 17144
from collections import deque
n, d, a = map(int, input().split())

hit = []

for i in range(n):
  x, h = map(int,input().split())
  hit.append([x,h])
hit.sort()

que = []
ans = 0
bomb = 0
for i in range(n):
  while True:
    if len(que) == 0:
      break
    if hit[i][0] <= que[0][0]:
      break
    bomb -= que[0][1]
    que.pop(0)
  r = hit[i][1] - bomb
  if r < 0:
    continue
  c = (r + a - 1)//a
  ans += c
  bomb += c*a
  que.append((hit[i][0]+2*d,c*a))
print (ans)

Measured memory_bytes: 54484
#include <stdio.h>
int main(){
  int flag,j,A[100],N,x=0,temp;

  scanf("%d",&N);
  for(j = 0; j < N; j++){
    scanf("%d",&A[j]);
  }
    
  flag = 1;
  while(flag){
    flag = 0;
    for(j = N-1; j >= 1; j--){
      if(A[j]<A[j-1]){
        temp = A[j];
	A[j] = A[j-1];
	A[j-1] = temp;
	flag = 1;
	 x++;
      }
    }
  }
  
  for(j = 0; j < N; j++){
    printf("%d",A[j]);
    if(j != N-1) printf(" ");
  }
  printf("\n");

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

  return 0;
}



Measured memory_bytes: 2124
// AOJ ALDS1_7_C Tree Walk
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	if (c == '-') {	c = gc();
		do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

typedef struct { int parent; int left, right; } TREE;
TREE tree[30];

void preorder(int node)
{
	printf(" %d", node);
	if (tree[node].left  >= 0) preorder(tree[node].left);
	if (tree[node].right >= 0) preorder(tree[node].right);
}

void inorder(int node)
{
	if (tree[node].left  >= 0) inorder(tree[node].left);
	printf(" %d", node);
	if (tree[node].right >= 0) inorder(tree[node].right);
}

void postorder(int node)
{
	if (tree[node].left  >= 0) postorder(tree[node].left);
	if (tree[node].right >= 0) postorder(tree[node].right);
	printf(" %d", node);
}

int main()
{
	int n, i, id;
	int root, left, right;

	n = in();
	for (i = 0; i < n; i++) {
		id = in();
		tree[id].left  = left =  in();
		tree[id].right = right = in();
		if (tree[id].left  >= 0) tree[left ].parent = id+1;
		if (tree[id].right >= 0) tree[right].parent = id+1;
	}
	for (root = 0; root < n; root++) {
		if (tree[root].parent == 0) break;
	}

	puts("Preorder");
	preorder(root); putchar('\n');
	puts("Inorder");
	inorder(root); putchar('\n');
	puts("Postorder");
	postorder(root); putchar('\n');
	return 0;
}


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

int main() {
    int n; cin >> n;
    pair<int, int> res(0, -1);
    while (n--) {
        int a, b; cin >> a >> b;
        res = max(res, {a, a + b});
    }
    cout << res.second << endl;
    return 0;
}


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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << min(a,b) + min(c,d) << endl;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var value = int.Parse(Console.ReadLine());

            double sqrt = Math.Sqrt(value);
            int max = (int)Math.Round(sqrt);



            for(int i = max; i > 0; i--)
            {
                if(i*i <= value)
                {
                    Console.WriteLine(i*i);
                    break;
                }
                    
            }

        }
    }
}

Measured memory_bytes: 11220
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m = map(int,input().split())
    SC = [tuple(map(int,input().split())) for _ in range(m)]
    for i in range(100001):
        i = str(i)
        if len(i)!=n: continue
        for s, c in SC:
            if i[s-1]!=str(c): break
        else:
            print(i)
            return
    print(-1)
resolve()

Measured memory_bytes: 38512
while True:
    H,W=map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(1,H+1):
        for j in range(1,W+1):
            
            if (i+j)%2==0:
                print("#",end="")
            else:
                print(".",end="")
        print()
    print()    



Measured memory_bytes: 7000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	private class Node {
		int id, pos;
		Node left, right;
		public Node(int id) {
			this.id = id;
			pos = -1;
			left = right = null;
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] pre = new int[n];
		int[] in = new int[n];
		StringTokenizer st1 = new StringTokenizer(reader.readLine());
		StringTokenizer st2 = new StringTokenizer(reader.readLine());
		int rootId = -1;
		int rootPos = -1;
		for (int i = 0; i < n; i++) {
			pre[i] = Integer.parseInt(st1.nextToken());
			in[i] = Integer.parseInt(st2.nextToken());
			if (i == 0) {
				rootId = pre[i];
			}
			if (rootId == in[i]) {
				rootPos = i;
			}
		}
		Node rootNode = new Node(pre[0]);
		rootNode.pos = rootPos;
		for (int i = 1; i < n; i++) {
			addNode(rootNode, new Node(pre[i]), in);
		}
		System.out.println(postOrder(rootNode));
	}

	private String postOrder(Node rootNode) {
		StringBuilder sb = new StringBuilder();
		Stack<Node> stack = new Stack<Node>();
		Node lastVisited = null;
		Node current = rootNode;
		while (current != null || !stack.isEmpty()) {
			if (current != null) {
				stack.push(current);
				current = current.left;
			} else {
				Node peekNode = stack.peek();
				if (peekNode.right != null && peekNode.right != lastVisited) {
					current = peekNode.right;
				} else {
					if (sb.length() != 0) {
						sb.append(" ");
					}
					sb.append(peekNode.id);
					lastVisited = stack.pop();
				}
			}
		}		
		return sb.toString();
	}

	private void addNode(Node rootNode, Node newNode, int[] in) {
		newNode.pos = findPos(newNode.id, in);
		Stack<Node> stack = new Stack<Node>();
		stack.push(rootNode);
		while (!stack.isEmpty()) {
			Node current = stack.pop();
			if (current.pos == -1) {
				current.pos = findPos(current.id, in);
			}
			if (newNode.pos < current.pos) {
				if (current.left == null) {
					current.left = newNode;
				} else {
					stack.push(current.left);
				}
			} else {
				if (current.right == null) {
					current.right = newNode;
				} else {
					stack.push(current.right);
				}
			}
		}
	}

	private int findPos(int id, int[] in) {
		for(int i = 0; i < in.length; i++) {
			if (in[i] == id) return i;
 		}
		return -1;
	}	
}


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

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

#define INF 1000000000000
#define MOD 1000000007
#define MAXR 100000

using namespace std;
typedef long long ll;

int main() {
    int N;
    ll Y;
    cin >> N >> Y;
    int x, y, z;
    x = y = z = -1;
    REP(i, N+1){
        REP(j, N+1-i){
            if((10000*i + 5000*j + 1000*(N - (i+j))) == Y){
                x = i;
                y = j;
                z = N - (i+j);
                break;
            }
        }
    }
    cout << x << " " << y << " " << z;
}

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

int main() {
    const char *a[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    int n = 0;
    while(s != a[n])
        n++;
    cout << 7 - n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define full(c) c.begin(), c.end()
#define vector2d(name, type, h, w, init) vector<vector<type>> name(h, vector<type>(w, init))
typedef signed long long int ll;
typedef unsigned long long int ull;
const int PRIME=1000000007;
using namespace std;

int main(){
  int i,n,g,p,cnt=0;
  string s;
  cin>>s;
  n=s.size();
  g=1;
  p=0;
  for(i=1; i<n; i++){
    if(s[i]=='g'){
      if(g>p) cnt++, p++;
      else cnt, g++;
    }
    else{
      if(g>p) cnt, p++;
      else cnt--, g++;
    }
  }
  cout<<cnt<<endl;
  return 0;
}

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

using namespace std;
using ll = long long;

int main() {
    ll d, n;
    cin >> d >> n;

    if (d == 0) {
        if (n == 100) {
            cout << 101 << endl;
        } else {
            cout << n << endl;
        }
    } else if (d == 1) {
        if (n == 100) {
            cout << 10100 << endl;
        } else {
            cout << 100 * n << endl;
        }
    } else {
        if (n == 100) {
            cout << 1010000 << endl;
        } else {
            cout << 10000 * n << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <stack>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int H, W;
bool S[2000][2000];
int T[2000][2000];
int getHist(vector<int> X) {
  X.pb(0);
  int w = X.size();
  stack<P> S;
  int m = 0;
  rep(x, w) {
    int y = X[x];
    int lx = x;
    while (!S.empty() && S.top()._2 > y) {
      //cout<<(x-S.top()._1) <<"x"<<(S.top()._2)<<"\n";
      m = max(m, (x-S.top()._1+1) * (S.top()._2+1));
      lx = S.top()._1;
      S.pop();
    }
    if (S.empty() || S.top()._2 != y) S.push(P(lx, y));
  }
  //rep(i, w)cout<<X[i]<<",";cout<<" -> "<<m<<"\n";
  return m;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  rep(i, H) rep(j, W) {
    char c; cin >> c;
    S[j][i] = c == '#';
  }
  rep(x, W-1) rep(y, H-1) T[x][y] = S[x][y] ^ S[x+1][y] ^ S[x][y+1] ^ S[x+1][y+1];
  vector<int> X(W-1, 0);
  int m = max(W, H);
  rep(y, H-1) {
    rep(x, W-1) {
      if (T[x][y] == 0) X[x]++;
      else X[x] = 0;
    }
    m = max(m, getHist(X));
  }
  cout << m << "\n";
  return 0;
}


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

int main(){
  int N, K; cin >> N >> K;
  vector<ll> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  ll ans = 1e18;
  for(int i = 0; i <1<<(N - 1); i++){
    bitset<18> bit(i);
    if(bit.count() != K-1)continue;
    ll ans1 = 0;
    ll bound = a[0];
    for(int j = 0; j < N - 1; j++){
      if(bit[j]){
        if(bound >= a[j + 1]){
          ans1 += bound - a[j + 1] + 1;
        }
        bound++;
      }
      bound = max(bound, a[j + 1]);
    }
    ans = min(ans, ans1);
  }
  cout << ans << 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 main(){
    int n;
    cin >> n;
    n = n % 10;
    if(n == 3){
        cout << "bon";
    }else if(n == 0 || n == 1 || n == 6 || n == 8){
        cout << "pon";
    }else{
        cout << "hon";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <math.h>

#define MAX_N 100
#define IN 2
#define ON 1
#define OUT 0
#define EPS (1e-10)

#define DOT(v1, v2) (v1.x * v2.x + v1.y * v2.y)
#define CROSS(v1, v2) (v1.x * v2.y - v1.y * v2.x)

typedef struct { double x, y; } point_t;
typedef point_t vector_t;

static vector_t minus(vector_t v1, vector_t v2) {
  vector_t ret = { v1.x - v2.x, v1.y - v2.y };
  return ret;
}

static int contains(point_t *g, int size, point_t q) {
  vector_t a, b, tmp;
  double c, d;
  int i, intersect;

  for (i = intersect = 0; i < size; ++i) {
    a = minus(g[i], q);
    b = minus(g[(i + 1) % size], q);
    c = CROSS(a, b);
    d = DOT(a, b);
    if (fabs(c) < EPS && d < EPS) return ON;
    if (a.y > b.y) {
      tmp = a;
      a = b;
      b = tmp;
    }
    c = CROSS(a, b);
    d = DOT(a, b);
    if (a.y < EPS && EPS < b.y && c > EPS) ++intersect;
  }

  return intersect % 2 ? IN : OUT;
}

int main(int argc, char **argv) {
  int n, m, i;
  point_t q, g[MAX_N];

  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%lf %lf", &g[i].x, &g[i].y);

  scanf("%d", &m);
  for (i = 0; i < m; ++i) {
    scanf("%lf %lf", &q.x, &q.y);
    printf("%d\n", contains(g, n, q));
  }
}


Measured memory_bytes: 2116
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N, A, B; cin >> N >> A >> B;
		if (N < A + B - 1) { cout << -1 << endl; return; }
		if (N > A * B) { cout << -1 << endl; return; }
		vector<UL> ans;
		UL s = N;
		UL t = 0;
		while (B != t + s) {
			if (A + B - t <= s) {
				s -= A;
				rep(i, A) {
					ans.push_back(s + i + 1);
				}
			}
			else {
				UL l = s - (B - t - 1);
				s -= l;
				rep(i, l) {
					ans.push_back(s + i + 1);
				}
			}
			t++;
		}
		rep(i, s) ans.push_back(s - i);

		rep(i, ans.size()) { if (i) cout << " "; cout << ans[i]; }
		cout << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 3440
#include<iostream>
using namespace std;
long n,a[2<<17],ans;
main()
{
	cin>>n;for(int i=0;i<n;i++)cin>>a[i];
	int f=0;
	long now=0,sum=0;
	for(int i=0;i<n;i++)
	{
		now^=a[i];
		sum+=a[i];
		while(now!=sum)
		{
			sum-=a[f];
			now^=a[f];
			f++;
		}
		ans+=i-f+1;
	}
	cout<<ans<<endl;
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M,L;
double P[100],T[100],V[100];

double p[100][55],t[100][55];

double dp[55][55];

signed main(){
    cin>>N>>M>>L;
    rep(i,N)cin>>P[i]>>T[i]>>V[i],P[i]/=100;

    rep(i,N){
        memset(dp,0,sizeof(dp));
        dp[0][0]=1.0;
        for(int j=0;j<M;j++){
            for(int k=0;k<=j;k++){
                dp[j+1][k+1]+=dp[j][k]*P[i];
                dp[j+1][k]+=dp[j][k]*(1-P[i]);
            }
        }

        for(int j=0;j<=M;j++){
            t[i][j]=L/V[i]+j*T[i];
            p[i][j]=dp[M][j];
        }
    }

    rep(i,N){
        double latte=0.0;
        for(int j=0;j<=M;j++){
            double malta=p[i][j];
            for(int k=0;k<N;k++)if(k!=i){
                double mocha=0.0;
                for(int l=0;l<=M;l++)if(t[k][l]>t[i][j])mocha+=p[k][l];
                malta*=mocha;
            }
            latte+=malta;
        }
        printf("%.20f\n",latte);
    }
    return 0;
}

Measured memory_bytes: 3344
from decimal import Decimal, ROUND_HALF_UP

def Rounding(x):
     return Decimal(str(x)).quantize(Decimal('0.00001'), rounding=ROUND_HALF_UP)

def div(x, y):
    f = Rounding(x / y)
    return x // y, x % y, float(f)

a, b = map(int, input().split())
print(*div(a, b))


Measured memory_bytes: 6404
#define _USE_MAT_DEFINES
#include<iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <functional>
using namespace std;

int main() {

    int N;
    cin >> N;
    vector<int>a(N);
    for (int i = 0; i < N; i++)cin >> a[i];

    long long sum1, sum2, ans1, ans2;
    sum1 = sum2 = ans1 = ans2 = 0;
    for (int i = 0; i < N; i++) {
        sum1 += a[i];
        sum2 += a[i];
        if (i % 2 == 1) {
            if (sum1 >= 0) {
                ans1 += abs(sum1) + 1;
                sum1 = -1;
            }
            if (sum2 <= 0) {
                ans2 += abs(sum2) + 1;
                sum2 = 1;
            }
        }
        if (i % 2 == 0) {
            if (sum1 <= 0) {
                ans1 += abs(sum1) + 1;
                sum1 = 1;
            }
            if (sum2 >= 0) {
                ans2 += abs(sum2) + 1;
                sum2 = -1;
            }
        }
    }

    cout << min(ans1, ans2) << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
// clang-format off
#define FOR(i, n) for (int i=0; i<(int)n; ++i)
#define RFOR(i, n) for (int i=n-1; i>=0; --i)
#define OUTV(x) FOR(j,x.size()) cerr<<x[j]<<(x.size()-j-1?' ':'\n');
#define OUTM(x) FOR(i,x.size()) {OUTV(x[i])}
#define BLE cerr<<"BLE"<<endl;
#define DEBUG(x) cerr<<"DEBUG: "<<#x<<" = "<<x<<endl;
#define PB push_back
#define MP make_pair
// clang-format on
using namespace std;

int N, M;
vector<vector<int>> graph;
vector<int> p;
vector<long long> ans;
vector<int> component;

void merge(int a, int b) {
  if (p[a] > p[b])
    merge(b, a);
  if (p[a] == p[b])
    return;

  queue<int> Q;
  Q.push(b);

  component[p[a]] += component[p[b]];
  component[p[b]] = 0;

  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    p[u] = p[a];
    for (int v : graph[u]) {
      if (p[v] != p[a]) {
        Q.push(v);
      }
    }
  }
}

long long solve(long long res, int a, int b) {

  long long ret = res;
  if (p[a] != p[b])
    ret -= 1LL * component[p[a]] * component[p[b]];
  merge(a, b);
  //  OUTV(component);
  return ret;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  //  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  cin >> N >> M;
  graph.resize(N);
  p.resize(N);
  component.resize(N);
  for (int i = 0; i < N; ++i) {
    p[i] = i;
    component[i] = 1;
  }
  ans.resize(M + 1);
  ans[M] = (1LL * N * (N - 1)) / 2;
  vector<int> A(M), B(M);
  for (int i = 0; i < M; ++i) {
    cin >> A[i];
    A[i]--;
    cin >> B[i];
    B[i]--;
  }

  for (int i = 0; i < M; ++i) {
    graph[A[M - 1 - i]].push_back(B[M - 1 - i]);
    graph[B[M - 1 - i]].push_back(A[M - 1 - i]);
    ans[M - 1 - i] = solve(ans[M - i], A[M - 1 - i], B[M - 1 - i]);
  }
  for (int i = 1; i <= M; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 9580
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;

//////////////////

int const N = 1e5 + 41;

int n;
string s;
int dp[N][2][2], from[N][2][2];
string ans;

char getS(char left, char type, char ans){
	if(type == 'S'){
		if(ans == 'o') return left; else return (left == 'S' ? 'W' : 'S');
	}else{
		if(ans == 'x') return left; else return (left == 'S' ? 'W' : 'S');
	}
}

void solve(){
	cin >> n;
	cin >> s;

	fi(0, 2){
		fj(0, 2){
			ans.clear();
			if(i == 0) ans.pb('S'); else ans.pb('W');
			if(j == 0) ans.pb('S'); else ans.pb('W');
			fk(2, n){
				ans.pb(getS(ans[sz(ans)-2], ans[sz(ans)-1], s[sz(ans)-1]));
			}
			if(getS(ans.back(), ans[0], s[0]) == ans[1] && getS(ans[sz(ans)-2], ans.back(), s.back()) == ans[0]){
				cout << ans << endl;
				exit(0);
			}
		}
	}

	cout << -1 << endl;
}


int main(){

	solve();

	return 0;
}

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

int a, b, c, d, e, f, sum, sug;
double maxi;
bool dp[3001][3001];
int main(){
	cin >> a >> b >> c >> d >> e >> f;
	dp[0][0] = true;
	for(int i = 0;i <= 30 * e - c;i++){
		if(dp[0][i]) dp[0][i+c] = true;
	}
	for(int i = 0;i <= 30 * e - d;i++){
		if(dp[0][i]) dp[0][i+d] = true;
	}
	for(int i=0;i<=3000-a*100;i++){
		for(int j=0;j<=30*e;j++){
			if(dp[i][j]) dp[i+a*100][j] = true;
		}
	}
	for(int i=0;i<=3000-b*100;i++){
		for(int j=0;j<=30*e;j++){
			if(dp[i][j]) dp[i+b*100][j] = true;
		}
	}
	for(int i=100;i<=f;i+=100){
		for(int j=0;j<=f;j++){
			if(i+j<=f&&dp[i][j]&&j<=i*e/100&&maxi < double(j) / double(i+j)){
				sum = i+j;
				sug = j;
				maxi = double(j) / double(i+j);
			}
		}
	}
	if(maxi==0){
		cout << a*100 << " " << 0 << endl;
	}else{
		cout << sum << " " << sug << endl;
	}
	return 0;
}

Measured memory_bytes: 6400
#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 x;
    cin >> x;

    if (x == 0) {
        cout << 1 << endl;
        return 0;
    }
    cout << 0 << endl; return 0;
}

Measured memory_bytes: 3632
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        long min= (long) 1e10;
        int ans=0;
        for(int i=0;i<n;i++){
            long x=sc.nextLong();
            if(x<=min){
                ans++;
                min=x;
            }
        }
        System.out.println(ans);
    }

public static class Scanner {
    StringTokenizer st;
    BufferedReader br;

    public Scanner(InputStream s) {
        br = new BufferedReader(new InputStreamReader(s));
    }

    public String next() throws IOException {
        while (st == null || !st.hasMoreTokens())
            st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    public int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    public long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    public String nextLine() throws IOException {
        return br.readLine();
    }

    public double nextDouble() throws IOException {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if (x.charAt(0) == '-') {
            neg = true;
            start++;
        }
        for (int i = start; i < x.length(); i++)
            if (x.charAt(i) == '.') {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            } else {
                sb.append(x.charAt(i));
                if (dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg ? -1 : 1);
    }

    public boolean ready() throws IOException, IOException {
        return br.ready();
    }

}}

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

using namespace std;

#define    VI       vector<int>
#define    VS       vector<string>
#define    LL       long long int
#define    ML       map<LL,LL>
#define    VLL      vector<LL>
#define    PB       push_back
#define    MP       make_pair
#define    FT       first
#define    SD       second
#define    PI       2*acos(0.0)
#define    F(i,a,n) for(int i=a;i<=n;i++)
#define    MS(a,v)  memset(a,v,sizeof(a));
#define    DEBUG    cout<<" I AM HERE "<<endl
#define    TC       int T;cin>>T;for(int TC=1;TC<=T;TC++)
#define    SORT(v)  sort(v.begin(),v.end())
#define    RSORT(v) sort(v.begin(),v.end(),greater<int>())
#define    FAST     ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
    FAST
    string s;
    cin>>s;
    (s[1]=='R')? cout<<"ABC"<<endl:cout<<"ARC"<<endl;
    return 0;
}


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

int main(){
  double N;
  cin >> N;
  vector<double> lim(5);
  for (ll i = 0; i < 5; ++i){
    cin >> lim[i];
  }
  
  double mi = *min_element(lim.begin(), lim.end());
  ll ans;
  double k = N / mi;
  ans = ceil(k) + 4;
  cout << ans << endl;
}


Measured memory_bytes: 256
/*input
20 100000
14309 -32939
-56855 100340
151364 25430
103789 -113141
147404 -136977
-37006 -30929
188810 -49557
13419 70401
-88280 165170
-196399 137941
-176527 -61904
46659 115261
-153551 114185
98784 -6820
94111 -86268
-30401 61477
-55056 7872
5901 -163796
138819 -185986
-69848 -96669

*/

#include <bits/stdc++.h>

using namespace std;

constexpr int N = 1e5 + 4;

char s[N];
int cnt[2];

int64_t sqr(int x) {
  return (int64_t)x * x;
}

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

  int n, d; cin >> n >> d;
  int64_t dd = sqr(d);
  int ans = 0;
  while (n--) {
    int p, q; cin >> p >> q;
    ans += (sqr(p) + sqr(q) <= dd);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
//                               //
    // author : samars_diary //
    // 16-09-2020 │ 23:37:05 //
//                               //

#include <iostream>
using namespace std;

void solve(){
    int a;
    cin>>a;
    cout<<1-a;
}

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

    //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int t = 1;
    while(t--){
        solve();
    }

    return 0;
}

Measured memory_bytes: 3680
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int num[] = new int[3];
    for (int i = 0; i < 3; i++){
      num[i] = sc.nextInt();
    }
    Arrays.sort(num);
    System.out.println(num[0]==5 && (num[1]==5 && num[2]==7) ? "YES" : "NO");
  }
}

Measured memory_bytes: 35612
import itertools
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for _ in range(m)]
pm = list(map(int, input().split()))
bit = itertools.product([0, 1], repeat=n)
ans = 0
for b in bit:
    flag = True
    for i in range(m):
        on = 0
        for s in ks[i][1:]:
            if b[s-1] == 1:
                on += 1
        if on % 2 != pm[i]:
            flag = False
            break
    if flag:
        ans += 1
print(ans)


Measured memory_bytes: 40560
import java.util.*;

class Main {
	Scanner sc;
	int n, k;
	static final int MOD = 1_000_000_007;
	
	void calc() {
		sc = new Scanner(System.in);
		n = sc.nextInt();
		k = Math.min(n, sc.nextInt());
		
		long s = 1;
		long f = 1;
		long nCi = 1;
		for (int i = 1; i <= k; i++) {
			f = f * (n-i) % MOD * inv(i) % MOD;
			nCi = nCi * (n-i+1) % MOD * inv(i) % MOD;
			s = (s + nCi * f % MOD) % MOD;
		}
		System.out.println(s);
	}
	
	static final long inv(long a) {
		long b = MOD;
		long aa = a, bb = b;
		long x0 = 1, x1 = 0;
		long y0 = 0, y1 = 1;
	
		while (b != 0) {
			long q = a / b;
			long r = a % b;
			long x2 = x0 - q * x1;
			long y2 = y0 - q * y1;
	
			a = b; b = r;
			x0 = x1; x1 = x2;
			y0 = y1; y1 = y2;
		}
		if (bb > 0 && x0 < 0) {
			long n = -x0/bb;
			if (-x0%bb != 0) n++;
			x0 += n*bb; y0 -= n*aa;
		}
	    return x0;
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}
	


Measured memory_bytes: 23892
import copy

num_of_switch, num_of_lights = [int(_) for _ in input().split()]

S = [[int(s) - 1 for s in input().split()[1:]] for i in range(num_of_lights)]
P = [_ == "1" for _ in input().split()]

# i は switch の添字


def rec(switch_idx, lights):
    if switch_idx == num_of_switch:
        if lights == P:
            return 1
        else:
            return 0

    switch_off_result = rec(switch_idx + 1, lights)

    _lights = copy.deepcopy(lights)

    for light_idx in range(num_of_lights):
        # print(f"switch_idx = {switch_idx}, light_idx = {light_idx}")
        is_connect = switch_idx in S[light_idx]
        if is_connect:
            _lights[light_idx] = not _lights[light_idx]

    # print(f"switch_idx = {switch_idx}: not choose = {lights}, choose = {_lights} ")

    switch_on_result = rec(switch_idx + 1, _lights)

    return switch_off_result + switch_on_result


ans = rec(0, [False] * num_of_lights)
print(ans)


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

int main(){
    vector<int> a;
    int s, t;
    cin>>s;
    a.push_back(s);
    t=s;
    for (int i = 0; i < 1000000; i++)
    {
        if (t%2==0)
        {
            t=t/2;          
        }
        else
        {
            t=3*t + 1;
        }
        if (find(a.begin(), a.end(), t) != a.end())
        {
            cout<<i+2;
            break;
        }
        a.push_back(t);
        
        
        
    }
    
    
    
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    ll n, m, x; cin >> n >> m >> x;
    vector<ll> a(m);
    rep(i, m) cin >> a[i];
    ll count = 0;
    rep(i, m) if(a[i] > x)count++;
    cout << min(count, m - count) << endl;
}

Measured memory_bytes: 256
C=(0..gets.to_i).map{[]};$<.map{|l|x,y=l.split.map &:to_i;C[x]<<y;C[y]<<x};d=->i,q{[[0,i],*(C[i]-[q]).map{|j|a,k=d[j,i];[a+4[C[i].size],k]}].max};p~-C.count{|x,y|!y}+d[d[1,0][1],0][0]

Measured memory_bytes: 15612
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N, Q;
    cin >> N >> Q;

    vec<vec<int>> G(N);
    rep(i, N - 1) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    map<ll, ll> mp;
    rep(i, Q) {
        int p, x;
        cin >> p >> x;
        --p;
        mp[p] += x;
    }

    vec<ll> ans(N);
    function<void(int, int, ll)> dfs = [&](int i, int par, ll sm) {
        ans[i] = sm;
        for (auto e : G[i]) {
            if (e == par) continue;
            dfs(e, i, sm + mp[e]);
        }
    };

    dfs(0, -1, mp[0]);
    rep(i, N) {
        cout << ans[i] << ' ';
    }
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}	
	int ok=n,ng=0;
	while(abs(ok-ng)>1)
	{
		int mid=(ok+ng)/2,f=1;
		map<int,int> mp;
		mp[0]=0;
		mp[a[0]]=0;
		for (int i = 1; i < n; ++i)
		{
			if (a[i-1]<a[i])
			{
				if (mp.find(a[i])!=mp.end())
				{
					++mp[a[i]];
				}
				else
				{
					mp[a[i]]=0;
				}
			}	
			else
			{
				if (mp.upper_bound(a[i])!=mp.end())
				{
					mp.erase(mp.upper_bound(a[i]),mp.end());
					++mp[a[i]];
				}
				else
				{
					if (mp.find(a[i])!=mp.end())
					{
						++mp[a[i]];
					}
					else
					{
						mp[a[i]]=0;
					}
				}
				int now=a[i],cnt=0;
				auto itr=mp.lower_bound(a[i]);
				while (itr!=mp.begin())
				{
					if (itr->first!=now-cnt)
					{
						break;
					}
					if ((itr->first==now&&itr->second<mid)||(itr->first!=now&&itr->second<mid-1))
					{
						break;
					}
					if (mid==1)
					{
						mp[0]=1;
						break;
					}
					--itr;
					++cnt;
				}
				++itr;
				mp.erase(itr,mp.end());
				if (cnt>0)
				{
					++mp[now-cnt];
				}
				if (mp[0]>0)
				{
					f=0;
					break;
				}
				if (mp.find(a[i])==mp.end())
				{
					mp[a[i]]=0;
				}
			}
			if (f==0)
			{
				break;
			}
		}
		if (f)
		{
			ok=mid;
		}
		else
		{
			ng=mid;
		}
	}
	cout<<ok<<endl;
	return 0;
}


Measured memory_bytes: 12416
//#define MYDEBUG
#include <bits/stdc++.h>

#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(v,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using std::vector;
using std::cout;
using std::cin;
using std::endl;
using std::max;
using std::min;
using std::swap;
using std::string;
using std::fill;
using std::pair;
using std::sort;
using std::reverse;
using std::pair;
using std::greater;
using std::priority_queue;

template<typename T>
std::ostream& operator<<(std::ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last)
      out << ",";
  }
  out << "]";
  return out;
}

void solve() {
  int r, g, b;
  cin >> r >> g >> b;
  int ans = r * 100 + g * 10 + b;
  cout << (ans % 4 == 0 ? "YES" : "NO") << endl;
}

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


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

int main() {
  int N, A, C=0, min=100000000;
  cin >> N;
  int i=0;
  while(i<N){
    cin >> A;
    if(A%2==1){
      C=0;
      min=0;
      break;
    }
    else{
      while(A%2==0){
        C++;
        A/=2;
      }
    }
    if(min>C)
     min=C;
    i++;
    C=0;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long a, b, x, res;
int main(void){
    // Your code here!
    cin >> a >> b >> x;
    long long rem = a % x, p = a / x, q = b / x;
    res = q - p + (rem == 0 ? 1 : 0);
    cout << res << endl;
}


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

using namespace std;

int main(){
    int ans = 0;
    int N;
    cin >> N;
    pair<int,int> red[N],blue[N+1];
    int INF = 10000;
    blue[N].first = 0;
    blue[N].second = INF;
    for(int i=0;i<N;i++){
        cin >> red[i].first >> red[i].second;
    }
    for(int i=0;i<N;i++){
        cin >> blue[i].first >> blue[i].second;
    }
    sort(red,red+N);
    for(int i=N-1;i>=0;i--){
        int b_min_y = N;
        int x=red[i].first,y=red[i].second;
        for(int j=0;j<N;j++){
            if(blue[j].first > x && blue[j].second > y && blue[j].second < blue[b_min_y].second){
                b_min_y = j;
            }
        }
        if(b_min_y != N){
            blue[b_min_y].second = 0;
            ans ++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

if ((N-1) * (N-2)) // 2 < K:
    print(-1)
else:
    ans = [0] * (N-1)
    for i in range(N-1):
        ans[i] = [i+1, N]
    minus = ((N-1) * (N-2)) // 2 - K
    M = N-1
    for i in range(1, N):
        for j in range(i+1, N):
            if minus > 0:
                ans.append([i, j])
                minus -= 1
                M += 1
    print(M)
    for branch in ans:
        print(' '.join(map(str, branch)))


Measured memory_bytes: 42736
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //int N = int.Parse(Console.ReadLine());

            string[] tmp = Console.ReadLine().Split(' ');
            int W = int.Parse(tmp[0]);
            int a = int.Parse(tmp[1]);
            int b = int.Parse(tmp[2]);

            if (b >= a)
            {
                if (a + W >= b)
                {
                    Console.WriteLine(0);
                }
                else
                {
                    Console.WriteLine(b - (a + W));
                }

            }
            else
            {
                if (b + W >= a) Console.WriteLine(0);
                else Console.WriteLine(a - (b + W));
            }

            Console.ReadLine();


        }
    }
}


Measured memory_bytes: 11092
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    cnt_a = 0
    cnt_b = 0
    for a, b in zip(A, B):
        if a > b:
            cnt_a += a - b
        elif a < b:
            cnt_b += (b - a) // 2

    if cnt_a > cnt_b:
        return "No"
    else:
        return "Yes"


print(solve())


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

int main() 
{
  string str,command;
  int a,b,q;

  cin >> str >> q;

  for(int i=1; i<=q; i++)
  {
    cin >> command >> a >> b;

    if( command == "print" )
      cout << str.substr(a,b-a+1) << endl; 
    else if( command == "reverse" )
    {   
      string tmp = str.substr(a,b-a+1);
      reverse(tmp.begin(), tmp.end());
      str.replace(a, b-a+1, tmp);
    }   
    else if( command == "replace" )
    {   
      string rep;
      cin >> rep;
      str.replace(a, b-a+1, rep);
    }   
  }

  return 0;
}



Measured memory_bytes: 3220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int W = sc.nextInt(),H = sc.nextInt(),N = sc.nextInt();
		int[][] ary = new int[H][W];

		for(int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			int a = sc.nextInt();

			for(int n = 0;n < H;n++) {
				for(int m = 0;m < W;m++) {
					if(a == 1) {
						if(x > m) ary[n][m] = 1;
					}else if(a == 2) {
						if(x < m+1) ary[n][m] = 1;
					}else if(a == 3) {
						if(y > n) ary[n][m] = 1;
					}else {
						if(y < n+1) ary[n][m] = 1;
					}
				}
			}
		}

		int count = 0;
		for (int[] is : ary) {
			for (int p : is) {
				if(p == 0) count++;
			}
		}
		System.out.println(count);
	}
}

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

int main(){
  int N;cin >> N;
  string S;cin >> S;
  int height=0,min_h=0;
  for(int i=0;i<N;i++){
    if(S[i]=='('){
      height ++;
    }else{
      height --;
    }
    min_h = min(min_h,height);
  }
  min_h = -min_h;
  for(int i=0;i<min_h;i++){
    cout << "(";
  }
  cout << S;
  for(int i=0;i<height+min_h;i++){
    cout << ")";
  }
  cout << endl;
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PI 3.1415926535897932384626433832795
#define endl "\n"
#define int long long
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const long long MOD = 998244353;
pair<int,int> dx[4] = {{1,0},{-1,0},{0,1},{0,-1}};
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct chash {int operator()(int x) const { return x ^ RANDOM; }};
string toString(long long x){stringstream ss;ss << x;string str = ss.str();return str;}
long long fastpow(long long x,long long k){if(!k)return 1;if(k & 1)return ((x * fastpow(x,k-1) % MOD) % MOD) % MOD;
long long ans = fastpow(x,k/2);ans %= MOD;ans *= ans;ans %= MOD;return ans;}
long long sumF(long long x){int s = 0;while(x)s += x%10,x /= 10;return s;}
bool isS(char c){return (c >= 'a' && c <= 'z');}
bool isB(char c){return (c >= 'A' && c <= 'Z');}
bool isD(char c){return (c >= '0' && c <= '9');}
bool isSqrt(long long x){ long long f = sqrt((long double)x + 0.5); return f*f == x;}
bool isCubic(long long x) {long long f = cbrt((long double)x + 0.5); return f*f*f == x;}
long long lcm(long long a,long long b){return a * (b / __gcd(a,b));}
vector<long long> divisorsVector(long long x){vector<long long> tmp;for(long long i = 2;1LL*i*i <= x;i++){if(x % i == 0){tmp.push_back(i);if(x / i != i)
tmp.push_back(x / i);}}sort(tmp.begin(),tmp.end());return tmp;}
long long countDiv(long long L,long long R,long long C){return ((R/C) - ((L-1)/C));}
int random_int(int l,int r){return uniform_int_distribution<int>(l,r)(rng);}
bool myCmp(pair<int,int>& a,pair<int,int>& b)
{
    if(a.second != b.second)
        return a.second > b.second;
    return a.first > b.first;
}
int32_t main()
{
    IO;
    int n,m;
    cin >> n >> m;
    vector<pair<int,int> > jobs(n);
    multiset<int> prices;
    for(int i = 0;i < n;i++)
    {
        cin >> jobs[i].first >> jobs[i].second;
    }
    sort(jobs.begin(),jobs.end());
    int start = 0;
    long long ans = 0;
    for(int i = 1;i <= m;i++)
    {
        for(;start < jobs.size() && jobs[start].first <= i;start++)
            prices.insert(jobs[start].second);
        if(prices.size())
        {
            ans += *(prices.rbegin());
            prices.erase(prices.find(*(prices.rbegin())));
        }

    }
    cout << ans;
    return 0;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> sirube(n, 0);
    vector<vector<int>> vec(n, vector<int>());
    rep(i, m){
        int a, b;
        cin >> a >> b;
        vec[a-1].push_back(b-1);
        vec[b-1].push_back(a-1);
    }
    queue<int> que;
    que.push(0);
    sirube[0] = -1;
    while(!que.empty()){
        int room = que.front();
        que.pop();
        rep(i, vec[room].size()){
            int next = vec[room][i];
            if(sirube[next] == 0){
                sirube[next] = room+1;
                que.push(next);
            }
        }
    }
    cout << "Yes" << endl;
    for(int i=1; i<n; i++){
        cout << sirube[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10244
import java.util.*;
import java.io.*;
import java.lang.*;
class Main{
	public static void main(String []args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		int h[]=new int[N];
		for(int i=0;i<N;i++) {
			h[i]=sc.nextInt();
		}
		int dp[]=new int[N];
		dp[0]=0;
		for(int j=1;j<N;j++) {
			dp[j]=Integer.MAX_VALUE;
		}
		for(int k=0;k<N;k++) {
			for(int l=k+1;l<k+K+1;l++) {
				if(l<N) {
					dp[l]=Math.min(dp[l],dp[k]+Math.abs(h[l]-h[k]));
				}
			}
		}
		System.out.println(dp[N-1]);
	}
}

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

int main() {
  string s;cin>>s;
  int count=0;
  rep(i,3) if(s[i]=='1') count++;
  cout << count << endl;
}


Measured memory_bytes: 256