akhauriyash/Code-Regression huggingface dataset:
n,m = map(int, input().split())

connect = [[0 for i in range(n)] for j in range(n)]

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

notbridge = 0


for i in range(n):
    for j in range(n):
        if connect[i][j] == 1:
            connect[i][j] = 0
            connect[j][i] = 0
            stack =[1]
            visited = [1]
            while stack:
                p = stack.pop()
                for k in range(n):
                    if connect[p][k] == 1:
                        if k not in visited:
                            stack.append(k)
                            visited.append(k)
            if len(visited) == n:
                notbridge += 1
            connect[i][j] = 1
            connect[j][i] = 1



print(m-notbridge//2)




Measured memory_bytes: 40432
#include <stdio.h>
#include<stdlib.h>

  int data[200] = {1};
  int top=0;

void push(int a) {
  top++;
  data[top] = a;
}

int pop() {
  int a;

  a = data[top];
  top--;
  return a;

}

int main() {
  char  a[100];
  int b, c;
  int i;

    while(scanf("%s", a) != EOF){
      if(a[0] == '+'){
        b = pop();
        c = pop();
        push(b + c);
      }else if(a[0] == '-'){
        c = pop();
        b = pop();
        push(b - c);
      }else if(a[0] == '*'){
        b = pop();
        c = pop();
        push(b * c);
      }else{
        push(atoi(a));
      }
    }

  printf("%d\n", pop());
  return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
// B - Bishop

using namespace std;

int main() {
    int H,W;

    scanf("%d%d",&H,&W);

    if (H == 1 || W == 1)
        printf("1\n");
    else
        printf("%lld\n",(1LL * H * W + 1) / 2);

    return 0;
}


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

int main() {
	int n, m;
	int matrix[100][100] = { 0 };
	int vector[100] = { 0 };
	long output[100] = { 0 };

	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cin >> matrix[i][j];

	for (int j = 0; j < m; j++)
		cin>>vector[j];

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			output[i] += matrix[i][j] * vector[j];
		}
		cout << output[i] << endl;
	}
}

Measured memory_bytes: 3112
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,M,a[100010];
vector<int> cnte[100010],cntb[100010];

LL cost(LL fr, LL to){
    return (to-fr+M)%M;
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N >> M;

    int i;
    for (i=1; i<=N; i++){
        cin >> a[i];
        if (i>1){
            cntb[a[i-1]].push_back(a[i]),cnte[a[i]].push_back(a[i-1]);
        }
    }

    int x=1,cnt=0; LL cr=0,res;
    for (i=1; i<N; i++){
        cr+=min(cost(a[i],a[i+1]),1+cost(x,a[i+1]));
        if (a[i]>a[i+1]) cnt++;
    }
    res=cr;

    for (x=2; x<=M; x++){
        for (int v : cnte[x-1]){
            cnt--;
            cr+=cost(v,x-1)-1;
        }

        cr-=cnt;
        cnt+=cntb[x-1].size();
        res=min(res,cr);
    }

    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 10368
S_ = input()
T = input()
S = "UNRESTORABLE"
for i, s in enumerate(S_):
    if i + len(T) > len(S_):
        break
    for j in range(len(T)):
        if S_[i+j] != T[j] and S_[i+j] != "?":
            break
    else:
        S = S_[:i] + T + S_[i+len(T):]
        S = S.replace("?", "a")
print(S)

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

const int mn=4005;

int main()
{
	int n,cnt=0,f;
	long long ans=0;
	char s[mn];
	scanf("%d%s",&n,s+1);
	for(int i=1;i<=n;++i) if(s[i]=='B') cnt++;
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j) {
			f=0;
			if(s[i]=='R'&&s[j]=='G') {
				if((i+j)%2==0&&s[(i+j)/2]=='B') f++;
				if(j*2-i>0&&j*2-i<=n&&s[j*2-i]=='B') f++;
				if(i*2-j>0&&i*2-j<=n&&s[i*2-j]=='B') f++;
				ans+=cnt-f;
			}
		}
	cout<<ans;
}

Measured memory_bytes: 3692
#include<stdio.h>
int main(void)
{
	int n, m, l;
	int i, j, k;
	int a[110][110];
	int b[110][110];
	long long c[110][110] = { 0 };
	scanf("%d %d %d", &n, &m, &l);

	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}

	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			scanf("%d", &b[i][j]);
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) {
				c[i][j] += a[i][k] * b[k][j];
			}
			if (j != 0) printf(" ");
			printf("%ld", c[i][j]);
		}
		puts("");
	}

	return(0);
}


Measured memory_bytes: 2136
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] a = new int[n];
    int hantei = 1;
    int cntContinuous = 0;
    for(int i=0; i<n; i++) {
      a[i] = Integer.parseInt(str[i]);
      if(hantei == a[i]) {
        cntContinuous++;
        hantei++;
      }
    }
    
    System.out.println(cntContinuous==0?-1:n-cntContinuous);
  }
}

Measured memory_bytes: 60676
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner scanner = new Scanner(System.in);
       //左に乗せる
       int A = scanner.nextInt();
       int B = scanner.nextInt();
       //右に乗せる
       int C = scanner.nextInt();
       int D = scanner.nextInt();

       String slope = "Balanced";

       if (A+B > C+D) {
           slope = "Left";
       } else if (A+B < C+D) {
           slope = "Right";
       }

       System.out.println(slope);
    }
}

Measured memory_bytes: 22740
#include <stdio.h>

int main(void)
{
        int N;
        int M;
        int i;
        int count=0;
        int b1,b2;
        int max,min;

        scanf("%d %d",&N,&M);
        scanf("%d %d",&min,&max);
        for(i=1;i<M;i++){
                scanf("%d %d",&b1,&b2);
                if(b1>min){
                        min=b1;
                }
                if(b2<max){
                        max=b2;
                }
        }

        for(i=1;i<=N;i++){
                if(i<=max&&i>=min){
                        count++;
                }
        }

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

        return 0;
}




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

int n, a[200004];

int main() {
	cin>>n;
	for(int i = 1;i<=n;i++)	cin>>a[i];
	for(int i = n;i>0;i-=2)	cout<<a[i]<<" ";
	int start;
	if (n%2 == 0) start = 1;
	else	start = 2;
	for(int i = start;i<=n;i+=2)	cout<<a[i]<<" ";
	return 0;
}

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

long long cnt = 0;
vector<int> g;

void insertionSort(int a[], int n, int g) {
  int v;
  for (int i = g; i < n; i++) {
    v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = v;
  }
}

void shellSort(int a[], int n) {
  for (int h = 1;;) {
    if (h > n) break;
    g.push_back(h);
    h = 3 * h + 1;
  }
  for (int i = g.size() - 1; 0 <= i; --i) {
    insertionSort(a, n, g[i]);
  }
}

int main() {
  int n;
  cin >> n;
  int a[n];
  // for (int i = 0; i < n; ++i) {
  //   cin >> a[i];
  // }
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  shellSort(a, n);
  cout << g.size() << endl;
  for (int i = g.size() - 1; 0 <= i; --i) {
    cout << g[i] << ((i == 0) ? '\n' : ' ');
  }
  cout << cnt << endl;
  for (int i = 0; i < n; ++i) {
    cout << a[i] << endl;
  }
}



Measured memory_bytes: 7064
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    const int K_SIZE = 29;

    int N, K;

    gc(N);
    gc(K);

    int64_t ans = 0;

    vector<int> A;
    vector<int> B;

    for (int i = 0; i < N; i++)
    {
        int a, b;
        gc(a);
        gc(b);
        A.push_back(a);
        B.push_back(b);

        // ビットパターンが一致
        if ((a | K) == K) ans += b;
    }

    for (int d = K_SIZE; 0 <= d; d--)
    {
        int64_t tmp = 0;
        if (K & 1 << d)
        {
            tmp = 0;

            // 自分のフラグを倒す、自分を除く上位ビットのフラグ保持
            // 自分を除く下位ビットのフラグを立てる
            int k = K ^ (1 << d) | (1 << d) - 1;

            for (int i = 0; i < N; i++)
            {
                if ((A[i] | k) == k) tmp += B[i];
            }
            ans = max(ans, tmp);
        }
    }

    printf("%" PRId64 "\n", ans);
    return 0;
}


Measured memory_bytes: 1404
import math
# cook your dish here
a,b=list(map(int,input().split()))
l=[1]*a
f=1
s=0
if(b<2):
    print(0)
    exit()
else:
    s=1
while(f==1):
    for i in range(0,a):
        if(sum(l)>=b):
            f=0
            break
        else:
            l[i]=l[i]-1+a
            s=s+1
        #print(l,s)
print(s)

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(Scanner())
	a := make([]int, n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(Scanner())
		m[a[i]]++
	}
	c := make(map[int]int)
	s := 0
	for k, v := range m {
		s += v * (v - 1) / 2
		c[k] = v*(v-1)/2 - (v-1)*(v-2)/2
	}

	for _, i := range a {
		fmt.Println(s - c[i])
	}
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	vector<int> a(n);
	map<int, int> mp;
	int ma = -1, ma2 = -1;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		mp[a[i]]++;

		if (ma < a[i]) {
			ma2 = ma;
			ma = a[i];
		} else if (ma2 < a[i]) {
			ma2 = a[i];
		}
	}

	for (int i = 0; i < n; i++) {
		if (a[i] == ma) {
			cout << (mp[ma] >= 2 ? ma : ma2) << endl;
			continue;
		}

		cout << ma << endl;
	}
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> b(n-1);
    vector<int> a(n);
    for (auto i = 0; i < n-1; i++)
    {
        int bi;
        cin >> bi;
        b[i] = bi;
    }
    a[0] = b[0];
    a[1] = b[0];

    for (auto i = 1; i < n-1; i++)
    {
        if(a[i] > b[i]){
            a[i] = b[i];
        }
        a[i + 1] = b[i];
    }

    long long sum = 0;
    for (auto i = 0; i < n; i++)
    {
        sum += a[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int sum=100*x+10*y+z;
  if(sum%4!=0){
    cout<<"NO"<<endl;
  }else{
    cout<<"YES"<<endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;


int main() {
    int n, d;
    cin >> n >> d;
    vector<vector<int>> x(n, vector<int>(d));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < d; j++) {
            cin >> x[i][j];
        }
    }
    int ans = 0;
    for (int i = 0; i < n-1; i++) {
        for (int j = i+1; j < n; j++) {
            int dis = 0;
            for (int k = 0; k < d; k++) {
                dis += (x[i][k] - x[j][k])*(x[i][k] - x[j][k]);
            }
            double dist = sqrt(dis);
            int int_dist = dist;
            /*
            cout << dist << endl;
            cout << int_dist << endl;
            */
            if (dist == int_dist) {
                ans += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

//FenwickTree↓
int dat[N];
void init(){
    rep(i,N)dat[i]=0;
}
void add(int i,int x){
    for(;i<N;i+=i&-i)dat[i]+=x;
}
int sum(int i){
    int res=0;
    for(;i>0;i-=i&-i)res+=dat[i];
    return res;
}
int rangesum(int l,int r){//[l,r]
    return sum(r)-sum(l-1);
}
//FenwickTree↑

int a[N];
vector<int> ql[N],qid[N];
int ans[N];

int n,q,c[N];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n>>q;
    for(int i=1;i<=n;i++)cin>>c[i];
    rep(i,q){
        int l,r;
        cin>>l>>r;
        ql[r].push_back(l);
        qid[r].push_back(i);
    }
    init();
    for(int i=1;i<=n;i++)a[i]=0;
    for(int i=1;i<=n;i++){
        if(a[c[i]]>0)add(a[c[i]],-1);
        add(i,+1);
        a[c[i]]=i;
        rep(j,ql[i].size()){
            ans[qid[i][j]]=rangesum(ql[i][j],i);
        }
    }
    rep(i,q)cout<<ans[i]<<"\n";
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ll long long
#define PINT pair<int,int>
#define f1 first
#define s2 second
const int INF = 1e9 + 7;

using namespace std;

int main(){
    cin.tie(0), ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int a[n];
    REP(i,n) cin >> a[i];

    sort(a,a+n,greater<int>());
    if(n==2){
        cout << a[0] << " " << a[1] << endl;
        return 0;
    }
    int b = a[0], c=a[0];
    REP(i,n){
        if(abs(a[i]-a[0]/2)<b){
            b = abs(a[i]-a[0]/2);
            c = a[i];
        }
    }

    cout << a[0] << " " << c << endl;

    return 0;
}


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

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

const int INF = 1e9;
const int mod = 1e9+7;

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

    int l = 0,r = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'E') r++;
    }

    int ans = INF;
    for(int i = 0; i < n; i++){
        if(s[i] == 'E') r--; 
        ans = min(ans,r+l);
        //cout << l << r << endl; 
        if(s[i] == 'W') l++;
    }

    cout << ans << endl;

    return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

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

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

int main() {
    int N, X;
    bool flag[200005] = {};
    cin >> N >> X;

    vint vec(2 * N - 1, 0);
    
    if (X == 1 || X == 2 * N - 1) {
        cout << "No" << el;
        return (0);
    }

    cout << "Yes" << el;
    if (N == 2) {
        cout << 1 << el << 2 << el << 3 << el;
        return (0);
    }
    
    int center = N - 1;
    if (X == 2) {
        vec[center] = 2;
        vec[center + 1] = 1;
        vec[center + 2] = 3;
        vec[center - 1] = 4;
        fill_n(flag + 1, 4, true);
    } else {
        vec[center] = X;
        vec[center + 1] = X + 1;
        vec[center + 2] = X - 1;
        vec[center - 1] = X - 2;
        fill_n(flag + X - 2, 4, true);
    }
    
    int cnt = 1;
    for (int i = 0; i < 2 * N - 1; i++) {
        if (vec[i]) {
            cout << vec[i] << el;
            continue;
        }
        while (flag[cnt]) cnt++;
        vec[i] = cnt++;
        cout << vec[i] << el;
    }
    
    return (0);
}

Measured memory_bytes: 2432
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

int calc(vector<int> a, vector<int> b, int c){
    int sum = 0;
    for(int i = 0; i < a.size(); i++){
        sum = sum + a[i] * b[i];
    }
    return sum + c;
}

int main(){
    int N,M,C;
    vector<int> B;
    vector<vector<int>> A;

    cin >> N >> M >> C;


    for(int i = 0; i < M;  i++){
        int tmp;
        scanf(" %d",&tmp);
        B.push_back(tmp);
    }

    for(int i = 0; i < N; i++){
    vector<int> v;
    A.push_back(v);
        for(int j = 0; j < M; j++){
            int tmp;
            scanf(" %d",&tmp);
            (A[i]).push_back(tmp);
        }
    }

    int ans = 0;

    
    for(int i = 0; i < N; i++){
        int tmp = calc(A[i], B, C);
        cerr << tmp << endl;
        if(tmp > 0) ans++;
    }
    

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

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

using namespace std;

#define allof(x) (x).begin(), (x).end()

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



int main(){
    cin.tie(0);
    cin.sync_with_stdio(0);

    int A, B;
    cin >> A >> B;

    cout << max(A - 1, min(A, B));
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
using namespace std;
#define LL long long 
#define LD long double
LL n,ans;
int main()
{
	cin>>n;
	if(n&1)puts("0");
	else
	{
		LL x=1;
		for(int i=1;i<=18;i++)
		{
			x*=10;
			ans+=n/x;
		}
		x=10;
		for(int i=1;;i++)
		{
			if(x*5>n)break;
			x*=5;
			ans+=n/x;
		}
		x=10;
		for(int i=1;;i++)
		{
			if(x*10>n)break;
			x*=10;
			ans-=n/x;
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 256
from collections import defaultdict


def main():
    N = int(input())
    d = defaultdict(int)
    results = ["AC", "WA", "TLE", "RE"]
    for _ in range(N):
        d[input()] += 1

    for r in results:
        print(f"{r} x {d[r]}")


if __name__ == '__main__':
    main()


Measured memory_bytes: 74668
<?php
// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d", $N, $Y);

$k1 = $k5 = $k10 = 0;
$ans = array();

$tmp = $Y / 1000;
$k10max = floor($tmp / 10);
for ($i = $k10max; $i >= 0; $i--) {
    $k1 = $tmp - $i * 10;
    $k10 = $i;

    if ($k10 + $k1 == $N) {
        if (DEBUG) echo "XXXX\n";
        $ans[] = array("k10" => $k10, "k5" => 0, "k1" => $k1);
    } else if ($k10 + $k1 > $N) {
        $rdc = $k10 + $k1 - $N;
        if ($rdc % 4 === 0) {
            $k5 = $rdc / 4;
            $k1 -= $k5 * 5;

            if (DEBUG) echo "answer:{$rdc} {$k10} {$k5} {$k1}\n";
            if ($k1 >= 0) {
                if (DEBUG) echo "XXXX\n";
                $ans[] = array("k10" => $k10, "k5" => $k5, "k1" => $k1);
            } else {
                if (DEBUG) exit('ERR' . "\n");
            }
        }
    }

    if (DEBUG) printf("k10:%d k5:%d k1:%d num:%d\n", $k10, $k5, $k1, $k10+$k5+$k1);
}

if (count($ans) == 0) {
    echo "-1 -1 -1" . "\n";
} else {
    printf("%d %d %d\n", $ans[0]['k10'], $ans[0]['k5'], $ans[0]['k1']);
}
// var_dump($ans);


Measured memory_bytes: 4604
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 200000;
const ll MOD = 1000000007;
ll n;
//string s;

int main() {
    cin >> n;
    string ntos = to_string(n);
    ll cnt = 0;
    ll ten[6] = {1,10,100,1000,10000,100000};
    for(ll a=1;a<=n;a++){
        string atos = to_string(a);
        char atos0 = atos[0];
        int a0 = atos0-'0';
        int a1 = a%10;
        if(a1 != 0){
            if(a0==a1){
                cnt++;
            }
            for(ll i=1; i<ntos.length(); i++){
                ll bbase = a1 * ten[i] + a0;
                if(bbase<=n){
                    for(ll k=0; k<ten[i-1]; k++){
                        ll b = bbase + k*10;
                        if(b<=n)cnt++;
                    }
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n,m= map(int,input().split())
h= list(map(int,input().split()))
ab=[[]*0 for i in range(0,n+2)]
for i in range(0,m):
    a,b= map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

count=0
for i in range(0,n):
    if len(ab[i])==0:
        count+=1
    else:
        maxh=h[ab[i][0]]
        for j in ab[i]:
            maxh=max(maxh,h[j])
        if h[i]>maxh:
            count+=1
print(count)


Measured memory_bytes: 29392
import java.util.Scanner;

/**
 *
 * @author k16075kk
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = 0;
        int y = 0;
        for (int i = 0; i < n; i++) {
            String s1 = sc.next();
            String s2 = sc.next();
            if (s1.compareTo(s2) > 0) {
                x += 3;
            } else if (s1.compareTo(s2) < 0) {
                y += 3;
            } else {
                x++;
                y++;
            }
        }
        System.out.println(x + " " + y);
    }

}



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

int getparent(int* parent , int x){
    if(parent[x] == x) return x ;
    else parent[x] = getparent(parent,parent[x]) ;
    return parent[x] ;
}

void merge(int x ,int y , int* parent , int* rank){
    int p1 = getparent(parent,x) , p2 = getparent(parent,y) ;
    if(rank[p1] >= rank[p2]){ //p2 is smol
        parent[p2] = parent[p1] ;
        rank[p1] += rank[p2] ;
    }else{ //p1 is smol
        parent[p1] = parent[p2] ;
        rank[p2] += rank[p1] ;
    }
}

int main()
{   ios_base :: sync_with_stdio(false) ;
    cin.tie(0) ;
    int n , m ;
    cin >> n >> m ;
    int parent[n] , rank[n] ;
    memset(rank,1,sizeof(rank)) ;
    for(int i = 0 ; i < n ; i++) parent[i] = i ;
    for(int i = 0 ; i < m ; i++){
        int x, y , z ; cin >> x >> y >> z ; x-- , y-- ;
        if(getparent(parent,x)!= getparent(parent,y)){
        	merge(x,y,parent,rank) ;
        }
    }
   set<int> s ;
   for(auto i : parent){
   		s.insert(getparent(parent,i)) ;
   }
	cout << s.size() ;
	return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define REPR(i,n) for (int i = n-1; i >= 0; --i)
#define PB push_back
#define MP make_pair

const int MAX = 3e5;

int N;
bool reserved[MAX];
vii X;
int ans[MAX];

bool solve() {
    int idx = 0;
    REP (i, N) {
        int num = X[i].second, pos = X[i].first;
        REP (n, num-1) {
            while (idx < N*N && ans[idx] != 0) idx++;
            if (idx > pos) return false;
            ans[idx] = num;
        }
    }

    idx = N*N-1;
    REPR (i, N) {
        int num = X[i].second, pos = X[i].first;
        REP (n, N-num) {
            while (idx >= 0 && ans[idx] != 0) idx--;
            if (idx < pos) return false;
            ans[idx] = num;
        }
    }

    return true;
}

int main() {
    cin >> N;
    REP (i, N) {
        int x;
        cin >> x; x--;
        X.PB(MP(x, i+1));
        ans[x] = i+1;
    }
    sort(X.begin(), X.end());
    if (solve()) {
        cout << "Yes" << endl;
        REP (i, N*N-1) cout << ans[i] << " ";
        cout << ans[N*N-1] << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 2176
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>//////////////////////////////////////////
#define deb(...)/////////////////////////////////////////////////
#define DBP(...)/////////////////////////////////////////////////
#ifdef LOC///////////////////////////////////////////////////////
#include"debuglib.h"/////////////////////////////////////////////
#endif///////////////////////////////////////////////////////////
#define x first//////////////////////////////////////////////////
#define y second/////////////////////////////////////////////////
#define pb push_back/////////////////////////////////////////////
#define sz(x)int((x).size())/////////////////////////////////////
#define each(a,x)for(auto&a:(x))/////////////////////////////////
#define all(x)(x).begin(),(x).end()//////////////////////////////
#define rep(i,b,e)for(int i=(b);i<(e);i++)///////////////////////
using namespace std;using ll=long long;using Pii=pair<int,int>;//
using Vi=vector<int>;void run();int main(){cin.sync_with_stdio///
(0);cin.tie(0);cout<<fixed<<setprecision(18);run();return 0;}////
//-------------------------------------------------------------//

constexpr ll MOD = 1e6+3;

struct Zp {
	ll x;
	Zp(ll a = 0) {
		if (a < 0) a = a%MOD + MOD;
		else if (a >= MOD*2) a %= MOD;
		else if (a >= MOD) a -= MOD;
		x = a;
	}
	Zp operator+(Zp r) const{ return x+r.x; }
	Zp operator-(Zp r) const{ return x-r.x+MOD; }
	Zp operator*(Zp r) const{ return x*r.x; }
	Zp operator/(Zp r) const{return x*r.inv().x;}
	Zp operator-()     const{ return MOD-x; }
	Zp inv() const { return pow(MOD-2); }
	Zp pow(ll e) const {
		Zp t = 1, m = *this;
		while (e) {
			if (e & 1) t = t*m;
			e >>= 1; m = m*m;
		}
		return t;
	}
	#define OP(c) Zp& operator c##=(Zp r){ return *this=*this c r; }
	OP(+)OP(-)OP(*)OP(/)
	void print() { cerr << x; }
};

vector<Zp> fact;

void precompute() {
	fact.resize(MOD+1);
	fact[0] = 1;
	rep(i, 1, MOD+1) fact[i] = fact[i-1] * i;
}

Zp solve(int x, int d, int n) {
	if (d == 0) return Zp(x).pow(n);
	Zp k = Zp(x) / d;
	if (k.x+n-1 >= MOD) return 0;
	Zp ret = fact[k.x+n-1];
	if (k.x > 0) ret /= fact[k.x-1];
	ret *= Zp(d).pow(n);
	return ret;
}

void run() {
	precompute();
	int q; cin >> q;
	while (q--) {
		int x, d, n; cin >> x >> d >> n;
		cout << solve(x, d, n).x << '\n';
	}
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

#define oo LLONG_MAX

void solve() {
  int n;
  cin >> n;
  int l = oo, s = 0;
  for (int i = 1; i <= n; i++) {
    int t; cin >> t;
    s += t;
    if (t % 10) l = min(l, t);
  }
  if (s % 10 == 0 && l != oo) s -= l;
  if (s % 10 == 0) cout << 0 << '\n';
  else cout << s << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define all(ppp) ppp.begin(),ppp.end()
#define out(ppp) cout<<(ppp)<<endl
#define out1(ppp) cout<<(ppp) 
#define MAX_CHAR 256

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define pb push_back

typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<vpi> vvpi;

typedef set<pi> spi;

const int INF=INT_MAX;

void solve(){
    int r,d,x;
    cin>>r>>d>>x;
    for(int i=1;i<=10;i++){
        x=r*x-d;
        out(x);
    }

}

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

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int num[26];
set<string> S;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cin>>K;
	FOR(i,N) {
		cin>>s;
		S.insert(s);
	}
	FORR(r,S) num[r[0]-'A']++;
	int ret=0;
	while(1) {
		sort(num,num+26);
		reverse(num,num+26);
		
		if(num[K-1]==0) break;
		FOR(i,K) num[i]--;
		ret++;
	}
	cout<<ret<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1280
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int dp[1000001],dp2[1000001];
int main(void)
{
	int n,p[10001],i,j,nn,x,a,b;
	for(i=1;i<=1000000;i++)	{
		x=i*(i+1)*(i+2)/6;
		if(x>1000000)	break;
		p[i]=x;
	}
	nn=i;
	dp[0]=0;
	for(i=1;i<=1000000;i++)	dp[i]=i;
	for(i=2;i<nn;i++)	{
		if(p[i]>1000000)	break;
		for(j=0;j<1000000;j++)	{
			if(j+p[i]<=1000000)	{
				dp[j+p[i]]=min(dp[j+p[i]],dp[j]+1);
			}
		}
	}	
	dp2[0]=0;
	for(i=1;i<=1000000;i++)	dp2[i]=i;
	for(i=2;i<=nn;i++)	{
		if(p[i]>1000000)	break;
		if(p[i]%2==1)	{
			for(j=0;j<1000000;j++)	{
				if(j+p[i]<=1000000)	{
					dp2[j+p[i]]=min(dp2[j+p[i]],dp2[j]+1);
				}
			}
		}
	}	

	while(1)	{
		scanf("%d",&n);
		if(n==0)	break;
		a=dp[n];
		b=dp2[n];		
		printf("%d %d\n",a,b);
	}
	return 0;
}


Measured memory_bytes: 8844
#include<bits/stdc++.h>
using namespace std;
#define de_x(x) cout<<"debug_val: "<<x<<endl;
#define de_ve(x) for(auto it: x) cout<<it<<" ";
#define rep(i,a,n) for (int i=a;i<n;i++)
#define _rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef double db;
std::mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x ; }
const ll MOD=1e9 +7;
ll ksm(ll a,ll b) {ll res=1;a%=MOD; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
int _;
/***********************/
void run(){
}
const int N = 4e5+5;
ll f[N],invf[N];
ll Con(int n ,int m){
	return f[n]*invf[n-m]%MOD*invf[m]%MOD;
}
int n , k;
int main(){
//	for(scanf("%d",&_); _;_--) run();	
	f[0] = invf[0] = f[1]= invf[1] =1;
	for(int i=2 ;i<N;i++){
		f[i] = f[i-1]*i%MOD;
		invf[i] =(MOD -MOD /i)*invf[MOD%i]%MOD;
	}
	for(int i =2 ;i<N;i++) invf[i] =invf[i-1]*invf[i]%MOD;
	cin>>n>>k;
	k = min(n,k);
	ll ans =0;
	for(int i=0;i<=min(n-1,k);i++)
		ans = (ans+Con(n,i)*Con(n-1,n-i-1)%MOD)%MOD;
	ans = (ans%MOD +MOD)%MOD;
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define fast_io              \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(), (c).end()
#define PRESENT(c, x) ((c).find(x) != (c).end())
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define REP(i, start, end) FOR(i, start, end + 1)
#define SQ(x) (x) * (x)
#define PII pair<int, int>

typedef long long LL;
using namespace std;

const int N = 1e5 + 5;
vector<int> h(N), cost(N, INT_MAX);

int main()
{
    fast_io;
    int n, k;
    cin >> n >> k;
    FOR(i, 0, n)
    cin >> h[i];
    cost[0] = 0;

    FOR(i, 0, n)
    {
        REP(j, 1, k)
        {
            if (i + j < n)
            {
                cost[i + j] = min(cost[i + j], cost[i] + abs(h[i] - h[i + j]));
            }
        }
    }

    cout << cost[n - 1] << endl;
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    var x = readLine()!!.split(" ").map { it.toInt() }[0]
    var flag = 0
    for (i in 0..1000000000){
        if (x >= 500){
            x = x - 500
            flag = flag + 1000
        } else if (x >= 5){
            x = x - 5
            flag = flag + 5
        } else {
            println(flag)
            break
        }
    }
}


Measured memory_bytes: 37880
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = Enumerable.Range(0, 3).Select(i => Console.ReadLine()).Select(int.Parse).Min();
            var j = Enumerable.Range(0, 2).Select(i => Console.ReadLine()).Select(int.Parse).Min();
            Console.WriteLine(p + j - 50);
        }
    }
}

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

int main() {
  int i, j, N, M;
  vector<string> n_strs, m_strs;
  
  cin >> N;
  n_strs = vector<string>(N);
  for (i=0; i<N; i++) {
    cin >> n_strs.at(i);
  }
  cin >> M;
  m_strs = vector<string>(M);
  for (i=0; i<M; i++) {
    cin >> m_strs.at(i);
  }
  
  vector<string> uniq_strs(1);
  bool exist = false;
  uniq_strs.at(0) = n_strs.at(0);
  for (i=1; i<N; i++) {
	exist = false;
    for (j=0; j<uniq_strs.size(); j++) {
      if (uniq_strs.at(j) == n_strs.at(i)) {
        exist = true;
        break;
      }
    }
    if (!exist) {
      uniq_strs.push_back(n_strs.at(i));
    }
  }
  for (i=0; i<M; i++) {
    exist = false;
    for (j=0; j<uniq_strs.size(); j++) {
      if (uniq_strs.at(j) == m_strs.at(i)) {
        exist = true;
        break;
      }
    }
    if (!exist) {
        uniq_strs.push_back(m_strs.at(i));
    }
  }
  int uniq_size = uniq_strs.size();
  vector<int> scores(uniq_size);
  for (i=0; i<N; i++) {
    for (j=0; j<uniq_strs.size(); j++) {
      if (uniq_strs.at(j) == n_strs.at(i)) {
		scores.at(j) += 1;
        break;
      }
    }
  }
  for (i=0; i<M; i++) {
    for (j=0; j<uniq_strs.size(); j++) {
      if (uniq_strs.at(j) == m_strs.at(i)) {
		scores.at(j) -= 1;
        break;
      }
    }
  }
  int max = 0;
  for (j=0; j<scores.size(); j++) {
    // cout << uniq_strs.at(j) + "=" << scores.at(j) << ",";
    if (scores.at(j) > max) {
      max = scores.at(j);
    }
  }
  // cout << endl;
  if (max < 0) max = 0;
  cout << max << endl;
}



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

int main() {
  int N;
  cin >> N;
  int D = N % 10;
  int C = N / 10 % 10;
  int B = N / 100 % 10;
  int A = N / 1000;

  for (int tmp=0; tmp<(1<<3); tmp++) {
    bitset<3> s(tmp);
    int sum = A-B-C-D;
    char op1, op2, op3;
    op1 = op2 = op3 = '-';
    if (s.test(0)) {
      sum += 2*B;
      op1 = '+';
    }
    if (s.test(1)) {
      sum += 2*C;
      op2 = '+';
    }
    if (s.test(2)) {
      sum += 2*D;
      op3 = '+';
    }

    if (sum == 7) {
      cout << A << op1 << B << op2 << C << op3 << D << "=7" << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define PN cout << endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (n-1); i >= (int)(m); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - (a)) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - (a)) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

/*
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
*/

/*
vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}
*/

/*
ll ncr[100][100];
ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

ll npr[100][100]={};
ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

ll nHr(int n,int r){ret nCr(n+r-1,r);}
*/

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



int main(){
    
    int n;
    cin >> n;
    ll a[n];
    inrep(n,a);
    rsort(a,a+n,ll);
    
    ll ans = 0;
    int i = 0,c = 1;
    while(n > 1){
	ans += a[i];
	c++;
	if(c > 1){
	    c = 0;
	    i++;
	}
	n--;
    }
    P(ans);
    
    return  0;
}


Measured memory_bytes: 5204
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
    ll n;
    cin>>n;
    vector<ll> a(n);
    int judge=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]){
            judge=1;
            break;
        }
    }
    if(judge==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}

Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <numeric>


using namespace std;

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)

int main() {
	int H, W;
	cin >> H >> W;

	int a[H][W];

	int dp[H][W];

	rep(y, H) {
		string s;
		cin >> s;
		rep(x, W) {
			a[y][x] = s[x];
			dp[y][x] = 10000000;
		}
	}

	//dp[0][0] = 0;
	//dp[y][x] += (a[y][x] == '.') ? 0 : 1;
	dp[0][0] = (a[0][0] == '.') ? 0 : 1;

	rep(y, H) {
		rep(x, W) {
			if (x > 0) {
				int cur = dp[y][x - 1];
				if (a[y][x - 1] == '.' && a[y][x] == '#') {
					cur++;
				} 
				dp[y][x] = min(dp[y][x],cur);

			}
			if (y > 0) {
				int cur =  dp[y - 1][x];
				if (a[y - 1][x] == '.' && a[y][x] == '#') {
					cur++;
				} 

				dp[y][x] = min(dp[y][x],cur);
			}
		}
	}
	cout << dp[H - 1][W - 1] << endl;

	return 0;
}

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

const int N = 1e5 + 7;

vector <int> ad[N], kid[N];
int n;
bool dp[N][2];

void solve(int v, int p) {
	if (ad[v].size() == 1 && p != 0) {
		dp[v][0] = 1;
		dp[v][1] = 0;
		return;
	}
	int cnt0 = 0, cnt1 = 0;
	for (auto u: ad[v]) {
		if (u == p)
			continue;
		solve(u, v);
		cnt0 += dp[u][0];
		cnt1 += dp[u][1];
		kid[v].push_back(u);
	}
	if (cnt1 == kid[v].size())
		dp[v][0] = 1;
	for (auto u: kid[v]) {
		if (dp[u][0] && cnt1- dp[u][1] == kid[v].size() - 1)
			dp[v][1] = 1;
	}
}

int main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		ad[x].push_back(y);
		ad[y].push_back(x);
	}
	solve(1, 0);
	if (!dp[1][1])
		cout << "First";
	else
		cout << "Second";

	return 0;
}


Measured memory_bytes: 10368
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll mod=1e9+7;

const ll INF=1e10+100;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(9);
    rep(i,n){
        ll x;
        cin >> x;
        ll p=x/400;
        if(p<8) a[p]++;
        else a[8]++;
    }
    ll sum=0;
    rep(i,8){
        if(a[i]){
            sum++;
        }
    }
    cout << max(sum,1LL) << " " << sum+a[8] << endl;
    return 0;
} 

Measured memory_bytes: 3592
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
#define ln '\n'
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int> G[201010];
int c[201010];
ll ans[201010];
ll sub[201010];
map<int, vector<int>> dic[201010];
void dfs(int v, int pv) {
    for (auto nv : G[v]) {
        if (nv==pv) continue;
        dfs(nv,v);
        sub[v] += sub[nv];
        if (!dic[nv].count(c[v])) ans[c[v]] += (sub[nv])*(sub[nv]+1)/2;
        else {
            ll val = 0;
            for (auto j : dic[nv][c[v]]) {
                val += sub[j];
            }
            ans[c[v]] += (sub[nv]-val)*(sub[nv]-val+1)/2;
        }
        if (dic[v].size() < dic[nv].size()) {
            swap(dic[v],dic[nv]);
        }
        for (auto A : dic[nv]) {
            for (auto j : A.second) {
                dic[v][A.first].emplace_back(j);
            }
        }
    }
    dic[v][c[v]].clear();
    dic[v][c[v]].emplace_back(v);
    sub[v]++;
    return;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    ll N; cin >> N;
    set<int> zzz;
    rep(i,N) {
        cin >> c[i];
        --c[i];
        zzz.emplace(c[i]);
    }
    rep(i,N-1) {
        int u,v; cin >> u >>  v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    dfs(0,-1);
    //rep(i,N) cout << ans[i] << ln;
    for (auto i : dic[0]) {
        ll val = 0;
        for (auto j : i.second) {
            val += sub[j];
        }
        ans[i.first] += (sub[0]-val)*(sub[0]-val+1)/2;
    }
    rep(i,N) {
        if (!zzz.count(i)) cout << 0 << ln;
        else cout << (N+1)*N/2 - ans[i] << ln;
    }
}




Measured memory_bytes: 125152
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		while(true) {
			int num = s.length()%2!=0 ? 1:2;
			s = s.substring(0, s.length()-num);
			if(s.substring(0,s.length()/2).equals(s.substring(s.length()/2))) {
				break;
			}
		}
		System.out.println(s.length());
	}
}


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

typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // int t;
    // cin>>t;
    // while(t--)
    // {
        
    // }
    int x,n;
    cin>>x>>n;
    bool f[102] = {false};
    for(int i =0;i<n;i++)
    {
        
       int k;
       cin>>k;
       f[k] = true;

    }
    int d = INT_MAX;
    int ans = INT_MAX;
    for(int i = -101;i<=101;i++)
    {
        if(f[i])continue;
        int t = min(d,abs(i-x));
        if(t < d)
        {
            d = t;
            ans = i;
        }
    }
    cout<<ans<<endl;
    //system("pause");
}

Measured memory_bytes: 3616
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;

typedef struct nod{
    vector<pair<long,long>> edges;
} Node;

void draw(const vector<Node>& nodes,vector<bool>& cs, long cpos,long lastp){
    Node node = nodes[cpos];
    for(auto au = node.edges.begin();au != node.edges.end();++au){
        if((*au).first == lastp)continue;
        cs[(*au).first] = (*au).second % 2 == 0 ? cs[cpos] : !cs[cpos];
        //  cout << "cpos = " << cpos << " to = " << (*au).first << " w = " << (*au).second << " new color = " << cs[(*au).first] << endl;
        draw(nodes,cs,(*au).first,cpos);
    }
}

int main() {
    long n;
    cin >> n;
    vector<Node> nodes(n,{vector<pair<long,long>>()});
    for(int i = 0;i < n - 1;++i){
        long u,v,w;
        cin >> u >> v >> w;
        --u;
        --v;
        nodes[u].edges.push_back(pair<long,long>(v,w));
        nodes[v].edges.push_back(pair<long,long>(u,w));
    }
    vector<bool> cls(n,false);
    cls[0] = true;
    draw(nodes,cls,0,-1);
    for(auto au = cls.begin();au != cls.end();++au){
        cout << (*au) << endl;
    }
}







Measured memory_bytes: 13952
import java.io.File;
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		 Scanner scan = new Scanner(System.in);
		//Scanner scan = new Scanner(new File("D:\\UserArea\\J0124567\\Downloads\\ALDS1_6_A-in9.txt"));

		int n = scan.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];

		int max = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			if (a[i] > max)
				max = a[i];
		}

		Csort(a, b, max);

		StringBuilder s = new StringBuilder(String.valueOf(b[0]));
		for (int i = 1; i < b.length; i++)
			s.append(" " + b[i]);
		System.out.println(s);

		scan.close();
		System.exit(0);
	}

	private static void Csort(int[] a, int[] b, int k) {
		int[] c = new int[k + 1];
		for (int i = 0; i < a.length; i++)
			c[a[i]]++;
		for (int i = 1; i < c.length; i++)
			c[i] += c[i - 1];

		for (int i = a.length - 1; i >= 0; i--) {
			c[a[i]]--;
			b[c[a[i]]] = a[i];
		}
	}
}

Measured memory_bytes: 554172
W, H, N = map(int, input().split())
w = {_ for _ in range(W+1)}
h = {_ for _ in range(H+1)}
x,y,a =[0]*N, [0]*N, [0]*N

for i in range(N):
    x[i], y[i], a[i] = map(int, input().split())

for i in range(N):
    if a[i]==1:
        w = w - {_ for _ in range(x[i])}
    elif a[i]==2:
        w = w - {_ for _ in range(x[i]+1,W+1)}
    elif a[i]==3:
        h = h - {_ for _ in range(y[i])}
    else:
        h = h - {_ for _ in range(y[i]+1, H+1)}
s, t = len(w)-1, len(h)-1
print(0 if s<0 or t<0 else s*t)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#include <queue>
#include <string.h>
#include <bitset>
#define ll long long int
#define ld long double
#define rep(i,n) for(int i = 0;i < n;i++)
#define rep1(i,n) for(int i = 1;i < n;i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "
#define all(x) x.begin(),x.end()
#define allr(x) x.begin(),x.end(),greater<int>()
#define P pair<ll,ll>
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1ll << 60
#define PI 3.14159265359

using namespace std;

int main(){
	vector<int> vec(2);
	cin >> vec[0] >> vec[1];
	sort(all(vec));
	if(vec[0] == 1 && vec[1] == 2){
		cout << 3 << endl;
	}
	else if(vec[0] == 2 && vec[1] == 3){
		cout << 1 << endl;
	}
	else if(vec[0] == 1&& vec[1] == 3){
		cout << 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256