akhauriyash/Code-Regression huggingface dataset:
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int N=1e5+5;
vi v[N];
int main() {
	ll n,m;cin>>n>>m;
	priority_queue<int>sal;
	loop(n,i,0){
		int a,b;cin>>a>>b;
		if(a>m)continue;
		v[a].pb(b);
	}
	ll res=0;
	for(int i=1;i<=m;i++){
		for(auto x:v[i])
			sal.push(x);
		if(sal.empty())continue;
		res+=sal.top();
		sal.pop();
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 5632
#include<stdio.h>
int sort(int *,int *);
int main(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int h[n+1];
  if(k>=n){printf("0");
           return 0;
          }
  for(int i=0;i<n;i++){
	scanf("%d",&h[i]);
  }
  qsort(h,n,sizeof(int),sort);
  long sum=0;
  for(int i=k;i<n;i++){
    sum+=(long)h[i];
  }
  printf("%ld",sum);
  
  return 0;
}
int sort(int *a,int *b){
  return *b-*a;
}

Measured memory_bytes: 1788
#pragma warning (disable:4996)
#include <stdio.h>
#include <string.h>

int main()
{
	char s[4];
	scanf("%s", &s);
	if (strchr(s, 'A') && strchr(s, 'B')) {
		printf("Yes");
	}
	else { printf("No"); }
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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 long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	VV c(3,V(3));
	V isum(3,0);
	V jsum(3,0);
	int ans=1;
	rep(i,3){
		rep(j,3){
			cin>>c[i][j];
			isum[i]+=c[i][j];
			jsum[j]+=c[i][j];
		}
	}
	ll mi=min(isum[0],min(isum[1],isum[2]));
	ll mj = min(jsum[0],min( jsum[1], jsum[2]));
	rep(i,3){
		isum[i]-=mi;
		jsum[i]-=mj;
		if(isum[i]%3!=0 or jsum[i]%3!=0){
			ans=0;
		}
	}
	cout<<solve(ans)<<endl;
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

h, w, k = LI()
s = SRL(h)
ans = INF
for bits in range(2 ** (h - 1)):
    res = sum([int(j) for j in "{0:b}".format(bits)])
    div_cnt = res + 1
    cnt = [0] * div_cnt
    x = 0
    flg = 0
    while x < w:
        cur = 0
        for y in range(h):
            if s[y][x] == '1':
                cnt[cur] += 1
            if bits >> y & 1:
                cur += 1
        if max(cnt) > k:
            if flg == 0:
                res = INF
                break
            else:
                cnt = [0] * div_cnt
                flg = 0
                res += 1
        else:
            flg = 1
            x += 1
    ans = min(ans, res)


print(ans)





Measured memory_bytes: 45404
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <stack>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

typedef long long ll;
typedef vector<int> VI;

#define FOR(i, a, n) for (ll i = (ll)a; i<(ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

//グラフの隣接リスト
VI g[200010];
//頂点の入次数を管理
int h[100010];
ll N;

int a[200010];
int b[200010];
int c[200010];
ll sum[200010];
signed main(void) {
    cin >> N;
    vector<int> ans;
    int maxn=1;
    while(maxn*(maxn+1)/2<N) maxn++;
    for(int i=1; i<=maxn; ++i){
        if(i!=(maxn+1)*maxn/2-N) printf("%d\n", i);
    }
	return 0;
}


Measured memory_bytes: 7168
#include <iostream>
#include <queue>
#include <set>
using namespace std;

const int MAX_SIZE = 20;
typedef pair<int, int> P;

int calc(char f[][MAX_SIZE], queue<P> q, int W, int H) {
  int n = 0;
  while (q.size()) {
    n++;
    P p = q.front();
    q.pop();
    int di[] = {-1, 1, 0, 0};
    int dj[] = {0, 0, -1, 1};
    for (int k = 0; k < 4; ++k) {
      int i = p.first  + di[k];
      int j = p.second + dj[k];
      if (i >= 0 && j >= 0 && i < H && j < W && f[i][j] == '.') {
        f[i][j] = '#';
        q.push(P(i, j));
      }
    }
  }
  return n;
}
int main() {
  int W, H;
  char f[MAX_SIZE][MAX_SIZE];
  char c[MAX_SIZE + 1];
  while (true) {
    queue<P> q;
    cin >> W >> H;
    if (W == 0 && H == 0) break;
    for (int i = 0; i < H; ++i) {
      cin >> c;
      for (int j = 0; j < W; ++j) {
        f[i][j] = c[j];
        if (f[i][j] == '@') {
          q.push(P(i, j));
        }
      }
    }
    cout << calc(f, q, W, H) << endl;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000LL;
constexpr auto MOD = 1000000007;

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

	int last_a = 0, first_b = 0, b_to_a = 0;
	int cnt = 0;
	rep(i, n) {
		string s;
		cin >> s;
		rep(i, s.size() - 1)if (s[i] == 'A' && s[i + 1] == 'B')cnt++;
		if (s[0] == 'B' && s[s.size() - 1] == 'A')b_to_a++;
		else if (s[s.size() - 1] == 'A')last_a++;
		else if (s[0] == 'B')first_b++;
		
	}

	if (last_a == 0 && first_b == 0 && b_to_a > 0)cnt += b_to_a - 1;
	else cnt += min(last_a, first_b) + b_to_a;

	cout << cnt << endl;

}

Measured memory_bytes: 256
// AOJ 2870 The Diversity of Prime Factorization
// 2018.3.29 bal4u

#include <stdio.h>
#include <string.h>

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define M 1000000007
char prime[1000010];         // prime table
int  q[100005];
int dp[100005];

void mkprime()
{
#define MAX  1000005
#define SQRT 1000	     // sqrt(MAX)
	int i, j;

	memset(prime+2, 1, 1000003);
	for (i = 4; i <= MAX; i += 2) prime[i] = 0;
	for (i = 3; i <= SQRT; i += 2) {
		for (j = i*i; j <= MAX; j += i) prime[j] = 0;  // j = i*i !!!!!
	}
}

int main()
{
	int N, i;

	mkprime();

	N = in();
	for (i = 0; i < N; i++) q[i] = in();
	q[N] = 1000003;

	dp[0] = 1;
	for (i = 0; i < N; i++) if (prime[q[i]]) {
		if (prime[q[i+1]] && q[i] < q[i+1]) {
			dp[i+1] += dp[i]; if (dp[i+1] >= M) dp[i+1] -= M;
		}
		if (prime[q[i+2]] && q[i] < q[i+2]) {
			dp[i+2] += dp[i]; if (dp[i+2] >= M) dp[i+1] -= M;
		}
	}
	printf("%d\n", dp[N]);
	return 0;
}


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

using namespace std;

int n;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    long double x = 1.0 * n / 3;
    long double res = x * x * x;
    cout << fixed << setprecision(8) << res;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod=1000000007;
int quickpow(int x,int y)
{
	long long res=1,base=x;
	while(y)
	{
		if(y&1)res*=base,res%=mod;
		y>>=1;base*=base,base%=mod;
	}
	return res;
}
int inv(int x){return quickpow(x,mod-2);}
int c(int x,int y)
{
	long long ans=1;
	for(int i=1;i<=y;i++)
		ans*=(x-i+1),ans%=mod,ans*=inv(i),ans%=mod;
	return ans;
}
signed main()
{
	int a,b,n,ans=0;
	scanf("%d%d%d",&n,&a,&b);
	ans=quickpow(2,n)-1;
	ans-=c(n,a),ans=(ans+mod)%mod;
	ans-=c(n,b),ans=(ans+mod)%mod;
	printf("%d",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
#define ull unsigned long long int
#define fasterInOut ios::sync_with_stdio(false); cin.tie(0);
#define pi acos(-1)
 
int main()    {
	//freopen("/home/mimi0007/Desktop/Temp/in", "r", stdin);
	fasterInOut;
	ll n;
	cin >> n;
	ll ar[n+2];
	ull sum = 0;
	for(int i = 0; i < n;  i++) {
		cin >> ar[i];
	}
	ll k = LONG_LONG_MIN;
	for(int i = 0; i < n-1;  i++) {
		if(ar[i] > ar[i+1]) {
			k = max(k, ar[i]);
			sum += k - ar[i+1];
		}
		
		else if(ar[i] <= ar[i+1]) {
			k = max(k, ar[i+1]);
			sum += k - ar[i+1];
		}
	}
		
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 5172
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
/*#include <math.h>*/
#include <string.h>

#define N 10005
#define INF 12345678
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

void create_generate_super_makeone_node(int, int, int);

struct node
{
    struct node *next;
    // struct node *prev;
    int vertex;
    int omosa;
};

typedef struct node *NodePointer;
NodePointer nil;

NodePointer data[N];
//int adj[N][N];
int d[N];
int color[N];
//int check[N];
int pi[N];
//int n;
/*
  void MinHeapify(int );
  void BuildMinHeap(void );
  int  ExtractMin(void );
  void HeapDecreace(int, int );
  void dijkstra(int );
*/

int main()
{
    int ex;
    int i, j;
    int n, u, k, vertex, c;
    int uid;
    int mincost;
    int r;

    for (i = 0; i < 10001; i++)
    {
        data[i] = (NodePointer)malloc(sizeof(struct node));
        data[i]->vertex = INF;
        data[i]->omosa = INF;
        data[i]->next = NULL;
        // d[i] = INF;
        // color[i] = WHITE;
        // pi[i] = NIL;
    }

    scanf("%d", &n);

    for (i = 1; i <= n; i++)
    {
        d[i] = INF;
        color[i] = WHITE;
        pi[i] = NIL;

        scanf("%d%d", &uid, &k);
        r = uid;
        for (j = 0; j < k; j++)
        {
            scanf("%d%d", &vertex, &c);
            create_generate_super_makeone_node(r, vertex, c);
        }
    }

    d[0] = 0;
    for (ex = 0;; ex++)
    {
        mincost = INF;
        for (j = 0; j < n; j++)
        {
            if (color[j] != BLACK && d[j] < mincost)
            {
                mincost = d[j];
                u = j;
            }
        }

        if (mincost == INF)
            break;

        color[u] = BLACK;

        nil = data[u]->next;

        while (nil != NULL)
        {
            // if(nil != NULL) break;

            if (color[nil->vertex] != BLACK && d[u] + nil->omosa < d[nil->vertex])
            {
                //	printf("aiueo\n\n");
                pi[nil->vertex] = u;
                d[nil->vertex] = nil->omosa + d[u];
            }
            //if(nil != NULL) break;
            nil = nil->next;
            // if(nil != NULL) break;
        }
    }
    for (i = 0; i < n; i++)
    {
        printf("%d %d\n", i, d[i]);
    }

    return 0;
}

void create_generate_super_makeone_node(int r, int vertex, int c)
{
    NodePointer n;
    n = (NodePointer)malloc(sizeof(struct node));
    n->vertex = vertex;
    n->omosa = c;
    n->next = data[r]->next;
    data[r]->next = n;
}



Measured memory_bytes: 17716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=10, inf=2e9;

int h,w;
char B[MX][MX];
bool vis[MX][MX];

bool valid(int x, int y){
    return 1<=x && x<=h && 1<=y && y<=w && B[x][y]=='#';
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>h>>w;
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            cin>>B[i][j];
    int x=1, y=1;
    while(true){
        B[x][y]='.';
        if(valid(x+1,y)){
            x++; continue;
        }
        if(valid(x,y+1)){
            y++; continue;
        }
        break;
    }
    bool yes=true;
    for(int i=1; i<=h; i++)
        for(int j=1; j<=w; j++)
            yes&=B[i][j]=='.';
    cout<<(yes?"Possible":"Impossible");
    return 0;
}

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

#sys.setrecursionlimit(10**9)

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def LI(): return list(map(int,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

def main():
	h,w,k=MI()
	G=[]
	for i in range(h):
		A=list(map(int,input().rstrip().decode()))
		G.append(A)
	#print(G)

	for i in range(h):
		for j in range(w):
			if i!=0:
				G[i][j]+=G[i-1][j]
			if j!=0:
				G[i][j]+=G[i][j-1]
			if i!=0 and j!=0:
				G[i][j]-=G[i-1][j-1]
	#print(G)

	B=[]
	for i in range(2**(h-1)):
		C=[0,h-1]
		for j in range(h):
			if i&(1<<j):
				C.append(j)
				C.append(j+1)
		C.sort()
		B.append(C)

	#print(B)

	ans=10**10

	def check(x1,y1,x2,y2):
		ret=G[x2][y2]
		if x1 != 0:
			ret -= G[x1-1][y2]
		if y1 != 0:
			ret -= G[x2][y1-1]
		if x1 != 0 and y1 != 0:
			ret += G[x1-1][y1-1]
		return ret

	for D in B:
		#print(d)
		cnt=len(D)//2-1
		l=0
		ww=0
		f=0
		while ww<w and f==0:
			for i,j in zip(D[0::2],D[1::2]):
				#print(i,j)
				if check(i,l,j,ww)>k:
					#print(i,l,j,ww,check(i,l,j,ww))
					if l==ww:
						f=1
					else:
						cnt+=1
						l=ww
					break
			ww+=1
			#print(w,ww,cnt)
		#print(D,cnt)
		if f==0:
			ans=min(ans,cnt)
	print(ans)














if __name__ == "__main__":
	main()

Measured memory_bytes: 44764
N,K=gets.split.map &:to_i
W=$<.map &:to_i
l=0
r=$$**3
m=r/2
def can? m
  i=k=sum=0
  while i<N
    return false if W[i]>m
    sum+=W[i]
    if m<sum
      sum=W[i]
      k+=1
    end
    i+=1
  end
  k<K
end
while l+1<r
can?(m)?r=m :l=m
m=(l+r)/2
end
p r

Measured memory_bytes: 7028
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int main(){
  string s;
  cin>>s;
  int k;
  cin>>k;
  int n=s.size();
  vector<string>all;
  for(int i=0;i<n;i++){
    for(int l=1;l<=10 && i+l<=n;l++){
      all.push_back(s.substr(i,l));
    }
  }
  sort(all.begin(),all.end());
  all.resize(unique(all.begin(),all.end())-all.begin());
  cout<<all[k-1]<<endl;
  return 0;
}


Measured memory_bytes: 2936
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP2(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(v) (v).begin(),(v).end()
#define INF 2e9
typedef long long ll;

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

    vector<bool> f(1e9,0);
    REP(i,n) f[a[i]-1]=((f[a[i]-1])? 0:1);
    int v=0;
    REP(i,1e9) if(f[i]) v++;

    cout<<v<<endl;

	return 0; 
}

Measured memory_bytes: 122752
grid = [[int(i) for i in input().split()] for j in range(3)]

b_patterns = []
for i in range(grid[0][0] + 1):
    b_pattern = [grid[0][j] - i for j in range(3)]
    b_patterns.append(b_pattern)

def patternCecker(grid, b_patterns):
    for pattern in b_patterns:
        a1 = grid[0][0] - pattern[0]
        a2 = grid[1][0] - pattern[0]
        a3 = grid[2][0] - pattern[0]

        a1_row = [a1 + pattern[l] for l in range(3)]
        a2_row = [a2 + pattern[l] for l in range(3)]
        a3_row = [a3 + pattern[l] for l in range(3)]

        if a1_row == grid[0] and a2_row == grid[1] and a3_row == grid[2]:
            return True
    return False

if patternCecker(grid, b_patterns):
    print('Yes')
else :
    print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>

using namespace std;

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

const ll MOD = ll(1e9 + 7);
//const ll INF = LLONG_MAX;
const ll MAX_N = ll(1e3) + 5;
const double EPS = 10e-8;
const double PI = 3.14159265359;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)

ll w, h, n, xs[MAX_N], xe[MAX_N], ys[MAX_N], ye[MAX_N],
    painted[MAX_N * 4][MAX_N * 4]{};
map<ll, ll> zipx, zipy;
vector<ll> X, Y;

void compress(vector<ll> &x, bool isx) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());
    for (ll i = 0; i < x.size(); i++) {
        if (isx) {
            zipx[x[i]] = i;
        } else {
            zipy[x[i]] = i;
        }
    }
}

void bfs(ll py, ll px) {
    painted[py][px] = 1;
    queue<P> que;
    que.push({py, px});

    while (!que.empty()) {
        P p = que.front();
        que.pop();
        REP(i, 4) {
            ll nx = p.second + dx[i], ny = p.first + dy[i];
            if (nx < 0 || ny < 0 || nx >= zipx[w] || ny >= zipy[h]) continue;
            if (painted[ny][nx] == 0) {
                painted[ny][nx] = 1;
                que.push({ny,nx});
            }
        }
    }
}

int main() {
    while (1) {
        cin >> w >> h;
        if (w == 0) break;
        zipx.clear();
        zipy.clear();
        REP(i, MAX_N * 4) {
            REP(j, MAX_N * 4) { painted[i][j] = 0; }
        }
        X.clear();
        Y.clear();
        cin >> n;
        REP(i, n) {
            cin >> xs[i] >> ys[i] >> xe[i] >> ye[i];
            X.push_back(xs[i]);
            if (xs[i] > 0) X.push_back(xs[i] - 1);
            X.push_back(xe[i]);
            if (xe[i] < w) X.push_back(xe[i] + 1);
            Y.push_back(ys[i]);
            if (ys[i] > 0) Y.push_back(ys[i] - 1);
            Y.push_back(ye[i]);
            if (ye[i] < h) Y.push_back(ye[i] + 1);
        }
        X.push_back(0);
        X.push_back(w);
        Y.push_back(0);
        Y.push_back(h);

        compress(X, true);
        compress(Y, false);

        REP(i, n) {
            painted[zipy[ys[i]]][zipx[xs[i]]]++;
            painted[zipy[ys[i]]][zipx[xe[i]]]--;
            painted[zipy[ye[i]]][zipx[xs[i]]]--;
            painted[zipy[ye[i]]][zipx[xe[i]]]++;
        }
        REP(i, zipy[h] + 1) {
            REP(j, zipx[w] + 1) painted[i][j + 1] += painted[i][j];
        }
        REP(j, zipx[w] + 1) {
            REP(i, zipy[h] + 1) painted[i + 1][j] += painted[i][j];
        }
        ll ans = 0;
        REP(i, zipy[h]) {
            REP(j, zipx[w]) {
                if (painted[i][j] == 0) {
                    ans++;
                    bfs(i, j);
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}



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

#define mx 100005

using namespace std;

vector<int> ch[mx];
stack<int> st;
int n, m, a, b, rt, nm[mx], pa[mx];

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n + m - 1; i++) {
		scanf("%d%d", &a, &b);
		ch[a].push_back(b);
		nm[b]++;
	}
	for(rt = 1; nm[rt]; rt++);
	st.push(rt);
	while(!st.empty()){
		int i = st.top(); st.pop();
		for(int it : ch[i]){
			if(!--nm[it]){
				pa[it] = i;
				st.push(it);
			}
		}
	}
	for(int i = 1; i <= n; i++) printf("%d\n", pa[i]);
}

Measured memory_bytes: 7040
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007


int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);
    for(ll &a:A)
        cin >> a;
    for(ll &b:B)
        cin >> b;
    
    ll p = 0;
    ll cp = 0;
    ll m = 0;
    ll cm = 0;
    vector<ll> R;
    R.push_back(0);
    for(int i=0; i<N; i++){
        if(B[i]>A[i]){
            m+=B[i]-A[i];
            cm++;
        }
        else{
            p+=A[i]-B[i];
            R.push_back(A[i]-B[i]);
            cp++;
        }
    }
    
    sort(R.begin(), R.end());
    
    if(m>p) {
        cout << -1 << endl;
        return 0;
    }
    
    ll add = 0;
    if(cm==0){
        cout << cm << endl;
        return 0;
    }

    for(ll i=R.size()-1; i>=0; i--){
        if(R[i]>=m){
            add = R.size()-i-1;
            break;
        } else m-=R[i];
    }
    
    cout << cm + add + 1 << endl;
    return 0;
}










Measured memory_bytes: 2936
#include<bits/stdc++.h>
#include<set>
#define lli long long int
#define pb push_back
#define cio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define rep(i,a,n) for(i=a;i<n;i++)
#define all(v) (v.begin(),v.end())
#define ppb pop_back
#define vsz v.size()
#define pi 3.141592653589793238
using namespace std;
int main()
{
	lli i,n;
	string s="ACL";
	cin>>n;
	for(i=0;i<n;i++){
		cout<<s;
	}	
	return 0;
}

Measured memory_bytes: 3544
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

N = I()
A = LI()

ans = 0
d = defaultdict(int)

ans = 0
for i in range(N):
    ans += d[-A[i]+i]
    d[A[i]+i] += 1
    
print(ans)

Measured memory_bytes: 139404
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int x,n;
    cin >> x;
    n = 0;
	while(x!=0){
        n++;
        cout << "Case " << n << ": " << x << "\n";
        cin >> x;
    }
}


Measured memory_bytes: 3144
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
vector<int> v;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a=0,b,c,d=0,e=0,f=0,g=0,i;
  string s;
  for(int n=0;n<4;n++){
    cin >>s[n];
    if(s[n]=='1') d++;
    if(s[n]=='9') e++;
    if(s[n]=='7') f++;
    if(s[n]=='4') g++;
  }
  if(d>0&&e>0&&f>0&&g>0) cout <<"YES\n";
  else cout <<"NO\n";
  return (0);
}


Measured memory_bytes: 256
n,a,b,c,d=map(int,input().split())
s=input()
if "##" in s[min(a,b)-1:max(c,d)]:
  print("No")
else:
  if c<d:
    print("Yes")
  else:
    if "..." in s[b-2:d+1]:
      print("Yes")
    else:
      print("No")
        


Measured memory_bytes: 3572
#include <stdio.h>

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

    int data[] = {a, b, c};
    int num = 3;

    for(int i=0; i<num-1; i++){
        for(int j=i+1; j<num; j++){
           if(data[i] > data[j]){
                int temp = data[i];
                data[i] = data[j];
                data[j] = temp; 
            }
        }
    }

    for(int i=0; i<num; i++){
        if(i<num-1){
            printf("%d ", data[i]);
        }
        else{
            printf("%d\n", data[i]);
        }
    }

    return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int cnt;

// ??±?????????
void merge(int A[], int n, int left, int mid, int right ){
	int n1 = mid -left; // ??????????????????????????°?????????
	int n2 = right - mid; // ??????????????????????????°?????????
	for(int i=0; i<n1; i++ ) L[i] = A[left+i]; // ????????????L[i]???????´???????
	for(int i=0; i<n2; i++ ) R[i] = A[mid+i];  // ????????????R[i]???????´???????
	L[n1] = R[n2] = SENTINEL;

	int i=0,j=0;
	for(int k=left; k<right; k++){
		cnt++;
		if( L[i]<=R[j] ){ // ???????????°?????????????????°???????????´???
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}

// ????§£??????
void mergeSort(int A[], int n, int left, int right ){
	if( left+1 < right ){
		int mid = (left+right)/2;
		mergeSort(A, n, left, mid);
		mergeSort(A, n, mid, right);
		merge(A, n, left, mid, right);
	}
}


int main(){
	int A[MAX],n;
	cnt = 0;

	cin >> n;
	for(int i=0; i<n; i++) cin >> A[i];

	mergeSort(A,n,0,n);

	for(int i=0; i<n; i++){
		if(i) cout << " ";
		cout << A[i];
	}

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

Measured memory_bytes: 6896
let () =
  let s = read_line () in
  print_endline @@
  string_of_int @@
  match s with
  | "SSS" -> 0
  | "SSR" -> 1
  | "SRS" -> 1
  | "SRR" -> 2
  | "RSS" -> 1
  | "RSR" -> 1
  | "RRS" -> 2
  | "RRR" -> 3



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

int main() {
  vector<int> a(4);
  cin >> a[0] >> a[1] >> a[2] >> a[3];
  sort(a.begin(), a.end());
  if (a[0] != 1 || a[1] != 4 || a[2] != 7 || a[3] != 9) {
    cout << "NO"
         << "\n";
  } else {
    cout << "YES"
         << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
a, b, k = map(int, input().split())
if a <= k:
    k -= a
    a = 0
    if b <= k:
        k -= b
        b = 0
    else:
        b -= k
        k = 0       
else:
    a -= k
    k = 0
    
print('{0} {1}'.format(a, b))

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

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vi a(n);
	int sum = 0;
	rep(i, n) cin >> a[i], sum += a[i] - 1;
	cout << sum << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include<cstdio>
#define MAXN 500000
struct node{
	int key;
	node *ch[2],*fa;
};
node tree[MAXN+5];
node *Root,*ncnt,*NIL;
void Init(){
	NIL=&tree[0];
	NIL->ch[0]=NIL->ch[1]=NIL->fa=NIL;
	ncnt=&tree[1];
	Root=NIL;
}
node *Find(node *rt,int val){
	if(rt==NIL)return NIL;
	if(rt->key==val)return rt;
	int d=(val>=rt->key);
	return Find(rt->ch[d],val);
}
node *FindNext(node *rt){
	if(rt==NIL)return NIL;
	node *y=rt->ch[1];
	while(y->ch[0]!=NIL)
		y=y->ch[0];
	return y;
}
void Delete(node *&rt,int val){
	node *x,*y,*z=Find(rt,val);
	if(z==NIL)return;
	if(z->ch[0]==NIL||z->ch[1]==NIL)
		y=z;
	else 
		y=FindNext(z);
	if(y->ch[0]!=NIL)
		x=y->ch[0];
	else
		x=y->ch[1];
	if(x!=NIL)
		x->fa=y->fa;
	if(y->fa==NIL)
		Root=x;
	else{
		int d=(y==y->fa->ch[1]);
			y->fa->ch[d]=x;
	}
	if(y!=z)
		z->key=y->key;
}
inline node * NewNode(int val){
	node *p=++ncnt;
	p->key=val;
	p->ch[0]=p->ch[1]=NIL;
	return p;
}
void Insert(node *&rt,node *fa,int val){
	if(rt==NIL){
		rt=NewNode(val);
		rt->fa=fa;
		return;
	}
	int d=(val>=rt->key);
	Insert(rt->ch[d],rt,val);
}
void Middle(node *rt){
	if(rt==NIL)return;
	Middle(rt->ch[0]);
	printf(" %d",rt->key);
	Middle(rt->ch[1]);
}
void First(node *rt){
	if(rt==NIL)return;
	printf(" %d",rt->key);
	First(rt->ch[0]);
	First(rt->ch[1]);
}
int main(){
	int n,x;
	char op[100];
	Init();
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%s",op);
		if(op[0]=='i'){
			scanf("%d",&x);
			Insert(Root,NIL,x);
		}
		else if(op[0]=='f'){
			scanf("%d",&x);
			node *p=Find(Root,x);
			if(p==NIL)
				puts("no");
			else
				puts("yes");
		}
		else if(op[0]=='d'){
			scanf("%d",&x);
			Delete(Root,x);
		}
		else{
			Middle(Root);
			puts("");
			First(Root);
			puts("");
		}
	}
	return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

const int MOD = 1000000007;

void diviser(long n, unordered_map<long, long> &mp)
{
    for (long i = 2; i * i <= n; ++i)
    {
        while (n % i == 0)
            n /= i, ++mp[i];
        mp[i] %= MOD;
    }
    if (n != 1)
        ++mp[n];
}

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

    long N;
    cin >> N;

    unordered_map<long, long> mp;

    for (long i = 2; i <= N; ++i)
        diviser(i, mp);

    long ans = 1;
    for (auto p : mp)
        ans *= (1 + p.second), ans %= MOD;

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>	// 全てのヘッダーファイルをinclude
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<set>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR (i,n) for(int i=n;i>0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
const int MOD{ int(1e9 + 7) };	// int 1000000007
const int inf{ int(1e9) };	// inf = 1000000000 // 1e9 はdouble型
using namespace std;
typedef long long ll;

int n, m, k, a, b, c, d;
int sum, cnt;
string s, t, u;


int main(void) {

	
	cin >> n >> k;

	cout << (k==1?0:(n-k+1)-1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n;
string s;

void f(ll p, char q)
{
    if(p >= n) {cout<<s<<endl;return;}
    for(char i = 'a'; i <= q; i++)
    {
        s.push_back(i);
        f(p + 1, q);
        s.pop_back();
    }
    if(q < 'z') s.push_back(q + 1), f(p + 1, q + 1), s.pop_back();
}

int main()
{
    cin>>n;
    s = "a";
    f(1, 'a');
    return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int N;
int A[110];

signed main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
	}
	int ans=1000;
	for(int i=0;i<N;i++){
		int T=1000,R=0;
		R=T/A[i];
		T%=A[i];
		int mode=0;
		for(int j=i+1;j<=N;j++){
			if(mode==0&&A[j-1]>A[j]){
				T+=R*A[j-1];
				R=0;
				mode=1;
			}
			if(mode==1&&A[j-1]<A[j]){
				R=T/A[j-1];
				T%=A[j-1];
				mode=0;
			}
		}
		ans=max(ans,T);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main()
{
int i;
int N;
int p;
bool b;
int iCnt;

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

	cin >> N;

	b = false;
	iCnt = 0;
	for( i = 1; i <= N; i++ )
	{
		cin >> p;

		if( b )
		{
			b = false;

			continue;
		}

		if( p == i )
		{
			b = true;
			iCnt++;
		}
	}

	cout << iCnt << endl;

	return 0;
}




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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  string t;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (t.size() == 0 || t.at(t.size() - 1) == s.at(i))
      t.push_back(s.at(i));
    else {
      t.pop_back();
      cnt += 2;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(int i=0;i<N;++i)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

bool comp(const PII& l, const PII& r){
  return (double)l.second/l.first > (double)r.second/r.first;
}

int main(void){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(15);

  ll N;cin >> N;
  vector<PLL> x(3);
  cin >> x[0].first >> x[1].first >> x[2].first;
  cin >> x[0].second >> x[1].second >> x[2].second;
  vector<PLL> v,w;
  REP(i,3){
    if((double)x[i].second/x[i].first > 1)v.push_back(x[i]);
    else if((double)x[i].second/x[i].first < 1) w.push_back(x[i]);
  }
  if(v.size()>=2){
    int M = v.size();
    //dp[i+1][j]:i番目まで見て,j個ある時の変換後の最大数
    ll dp[M+1][N+1];
    REP(j,N+1) dp[0][j] = N;
    REP(i,M){
      REP(j,N+1){
        if(j < v[i].first){
          dp[i+1][j] = dp[i][j];
        }else{
          dp[i+1][j] = max(dp[i][j], dp[i+1][j-v[i].first] + v[i].second - v[i].first);
        }
      }
    }
    N = dp[M][N];
  }else if(v.size()==1){
    ll n = N/v[0].first;
    N += n*(v[0].second - v[0].first);
  }

  if(w.size()>=2){
    int M = w.size();
    //dp[i+1][j]:i番目まで見て,j個ある時の変換後の最大数
    vector<vector<ll> > dp(M+1,vector<ll>(N+1));
    REP(j,N+1) dp[0][j] = N;
    REP(i,M){
      REP(j,N+1){
        if(j < w[i].second){
          dp[i+1][j] = dp[i][j];
        }else{
          dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i].second] + w[i].first - w[i].second);
        }
      }
    }
    N = dp[M][N];

  }else if(w.size()==1){
    ll n = N/w[0].second;
    N += n*(w[0].first - w[0].second);
  }

  cout << N << endl;
  return 0;
}


Measured memory_bytes: 773504
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 200005;
int n;
int v[N];
int BIT[N];
void add(int idx, int val) {
	while (idx < N) {
		BIT[idx] += val;
		idx += idx&-idx;
	}
}
int get(int idx) {
	int ret = 0;
	while (idx) {
		ret += BIT[idx];
		idx -= idx&-idx;
	}
	return ret;
}
bool check(int m) {
	ll a = 0;
	memset(BIT, 0, sizeof(BIT));
	const int o = 100001;
	add(o, 1);
	int cs = 0;
	for (int i = 0; i < n; ++i) {
		int me = v[i] <= m ? 1 : -1;
		cs += me;
		a += get(cs + o - 1);
		add(cs + o, 1);
	}
	ll all = (ll)n*(n + 1) / 2;
	return a >= all / 2 + 1;
}
int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", v + i);
	vector<int> w(v, v + n);
	sort(w.begin(), w.end());
	int l = 0, r = n - 1, m, res = -1;
	while (l <= r) {
		m = (l + r) / 2;
		if (check(w[m])) {
			res = w[m];
			r = m - 1;
		}
		else
			l = m + 1;
	}
	printf("%d\n", res);
	return 0;
}

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

int n, m, p[100004];

struct dsu {
    int p[100004];
    set<int> s[100004];
    dsu() { iota(p, p+100004, 0); }
    int root(int x) { return p[x] != x ? p[x] = root(p[x]) : x; }
    void connect(int x, int y) {
        x = root(x); y = root(y);
        if (x==y) return;
        if (s[x].size() > s[y].size()) swap(x, y);
        s[y].insert(s[x].begin(), s[x].end());
        p[x] = y;
    }
} d;

int main() {
    cin >> n >> m;
    for (int i=1; i<=n; i++) cin >> p[i], d.s[i].insert(p[i]);

    for (int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        d.connect(x, y);
    }

    int ans = 0;
    for (int i=1; i<=n; i++) ans += d.s[d.root(i)].count(i);

    cout << ans << '\n';
}

Measured memory_bytes: 38400
#include "bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin() , v.end()
#define inputv(v,n) rep(i,n){\
    ll x;\
    cin>>x;\
    v.push_back(x);\
    }
const ll INF = 999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, ans = 0, w, l;
string S;
void input() {
	cin >> S;
}
void solve() {
	vl dp1, dp2;
	n = S.length();
	dp1.push_back(0);
	dp2.push_back(0);
	rep(i, n) {
		if (S[i] == '<')dp1.push_back(max(dp1.back(), 0LL) + 1);
		else dp1.push_back(min(0LL, dp1[i] - 1));
	}
	rep(i, n) {
		if (S[n-1-i] == '>')dp2.push_back(max(dp2.back(), 0LL) + 1);
		else dp2.push_back(min(0LL, dp2[i] - 1));
	}
	reverse(all(dp2));

	rep(i, n + 1) {
		ans += max(0LL, max(dp1[i], dp2[i]));
	}

	cout << ans << endl;
}

int main() {
	input();
	solve();
}

Measured memory_bytes: 12788
#include <iostream>
#include <algorithm>
#include <string>
#include <map>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

int main() {
  int N;
  std::string s;

  cin >> N;
  cin >> s;

  int ans = 0;

  for (int i = 1; i < N - 1; ++i) {
    std::map<char, bool> mp;

    for (int j = 0; j < i; ++j) {
      mp[s[j]] = true;
    }

    int tmp = 0;

    for (int j = i; j < N; ++j) {
      if (mp[s[j]]) {
        tmp++;
        mp[s[j]] = false;
      }
    }

    ans = std::max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


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

int main(){
	int n,k;
	string s;
	cin>>n>>k>>s;
	int flag=0;
	int ans=0;
	for (int i = 0; i < n-1; i++) {
		if (k>0) {
			if (s[i]!=s[i+1]) {
				flag++;
			}
			if (flag==2) {
				k--;
				flag=0;
				ans+=2;
			}
			if(flag==1&&i==n-2){
				ans++;
			}
		}
		if(s[i]==s[i+1]){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(){

	int n, i, j;
	int A[101], key;

	scanf( "%d", &n );

	for( i=0; i<n; i++ ) scanf( "%d", &A[i] );
	

	for( i=0; i<n; i++){

		key = A[i];

		j = i-1;

		while( j>=0 && A[j]>key ){
			A[j+1] = A[j];
			j--;
		}

		A[j+1] = key;

		for( j=0; j<n; j++ ) 
			printf( "%d%c", A[j], j!=(n-1)?' ':'\n' );

	}


	return 0;

}

Measured memory_bytes: 600
#include <iostream>
using namespace std;
  
int rt[200000];
  
int main(){
    ios::sync_with_stdio(false);
    int n;
    int i , j;
    int max,min;
    cin>>n;
    max=0x80000000;
    for(i=0 ; i<n ; i++){
        cin>>rt[i];
    }
    min=rt[0];
    for(i=1 ; i<n ; i++){
        if((rt[i]-min)>max){
            max=rt[i]-min;
        }
        if((rt[i])<min){
            min=rt[i];
        }
    }
    cout << max << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define endl "\n"


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
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;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
ll n;

struct edge{
  ll to, weight;
  edge(ll t=0, ll w=0){ to = t; weight = w; }
};


vector<vector<edge>> graph;
vll dis;

void init(ll N){
  graph.resize(N,vector<edge>());
  dis.resize(N);
}

void bfs(ll s){
  for(ll i=0;i<n;i++) dis[i] = LINF;
  queue<ll> que;
  que.push(s);
  dis[s] = 0;

  while(!que.empty()){
    ll u = que.front(); que.pop();
    for(ll i=0;i<graph[u].size();i++){
      edge e = graph[u][i];
      if(dis[e.to] == LINF){
        dis[e.to] = dis[u] + e.weight;
        que.push(e.to);
      }
    }
  }
}

ll diameter(){
  ll res = 0;
  bfs(0);
  ll tgt = 0;
  for(ll i=0;i<n;i++){
    if(dis[i] == LINF) continue;
    if(res < dis[i]){
      res = dis[i];
      tgt = i;
    }
  }

  bfs(tgt);
  res = 0;
  for(ll i=0;i<n;i++){
    if(dis[i] == LINF) continue;
    res = max(res,dis[i]);
  }

  return res;
}

//-----------------------------------------

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> n;
  init(n);
  REP(i,n-1){
    ll s, t, w;
    cin >> s >> t >> w;
    graph[s].push_back(edge(t,w));
    graph[t].push_back(edge(s,w));
  }
  cout << diameter() <<endl;

  return 0;
}




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

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(" ");

        // N個のスイッチとM個の電球
        var N = int.Parse(inputs[0]);
        var M = int.Parse(inputs[1]);

        // i番目の電球はk個のスイッチに繋がっており、スイッチsのうちonになっているスイッチの個数%2がp[i]に等しい時に点灯する
        var k = new List<int>();
        var s = new List<List<int>>();
        var p = new List<int>();

        for(int i = 0;i < M; i++)
        {
            var switchs = Console.ReadLine().Split(" ");
            k.Add(int.Parse(switchs[0]));
            s.Add(new List<int>());
            for (int j = 1; j <= k[i]; j++)
            {
                s[i].Add(int.Parse(switchs[j]));
            } 
        }

        var ps = Console.ReadLine().Split(" ");
        for(int i = 0; i < M; i++)
        {
            p.Add(int.Parse(ps[i]));
        }

        //　電球の点灯パターンを網羅する
        var switches = new bool[N];
        var numOfPatterns = 0;
        for (int bit = 0; bit < (1 << N); bit++)
        {
            for (int i = 0; i < N; ++i)
            {
                if ((bit & (1 << i)) != 0)
                {
                    switches[i] = true;
                }
                else
                {
                    switches[i] = false;
                }
            }

            // 各電球ごとに判定
            var result = true;
            for (int i = 0; i < M; i++)
            {
                var count = 0;
                for(int j = 0; j < k[i]; j++)
                {
                    if (switches[s[i][j] - 1]) count++;
                }
                
                // 点灯するか判定、点灯しなかったら後ろの電球はチェック不要
                if(count % 2 != p[i])
                {
                    result = false;
                    break;
                } 
            }

            if (result) numOfPatterns++;
        }
        Console.WriteLine(numOfPatterns);
    }
}



Measured memory_bytes: 27516
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#ifdef MBP
#include"stdc++.h"
#else
#include<bits/stdc++.h>
#endif
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

#define FACSIZE 2002

ll invfac[FACSIZE];
ll fac[FACSIZE];

ll mod_pow(ll ,ll );
ll mod_add(ll ,ll );
ll mod_mul(ll ,ll );
ll mod_div(ll ,ll );
void make_fact(ll );
void make_invfact(ll );



int main(void){

  ll n;
  cin>>n;
  vector<ll> A(n);
  rep(i,n) cin>>A[i];

  vector<ll> total(n);
  total[0]=A[0];
  for(ll i=1;i<n;i++) total[i]=total[i-1]+A[i];
  ll ans=0;
  //for(auto x:total) if(x==0) ans++;
  map<ll,ll> m;
  for(auto x:total) m[x]++;

  for(auto p:m){

    if(p.first==0){
      ans+= (p.second)*(p.second+1)/2;
    }
    else{
      ans+= (p.second)*(p.second-1)/2;
    }

  }

  cout << ans << endl;

  return 0;

}

ll mod_pow(ll x,ll r){
  if(r==0) return 1;
  else if(r==1) return x%mod;
  else if(r%2==0){
    ll t=mod_pow(x,r/2)%mod;
    return t*t %mod;
  } 
  else{
    ll t=mod_pow(x,r/2)%mod;
    ll k= t*t %mod;
    return k*x%mod;
  } 
}
ll mod_add(ll a,ll b){
  return (a+b)%mod;
}

ll mod_mul(ll a,ll b){
  return (a*b)%mod;
}

ll mod_div(ll a,ll b){
  return mod_mul(a,mod_pow(b,mod-2));
}

void make_fact(ll n){
  fac[0]=1;
  rep(i,n){
    fac[i+1]=mod_mul(fac[i],i+1);
  }  
}

void make_invfact(ll n){
  invfac[n]= mod_pow( fac[n] ,mod-2);
  for(int i=n-1;i>=0;i--){
    invfac[i]=mod_mul(invfac[i+1],i+1);
  }

}

Measured memory_bytes: 15872
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, m int
	var x []int

	fmt.Scan(&n, &m)
	for i := 0; i < m; i++ {
		var tmp int
		fmt.Scan(&tmp)
		x = append(x, tmp)
	}

	sort.Ints(x)
	var diff []int
	for i := 1; i < m; i++ {
		diff = append(diff, x[i]-x[i-1])
	}
	sort.Ints(diff)

	sum := 0
	for i := 0; i < m-n; i++ {
		sum += diff[i]
	}

	fmt.Println(sum)
}


Measured memory_bytes: 6272