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

using namespace std;

#define fst first
#define snd second
#define mp make_pair
#define squ(x) ((LL)(x) * (x))
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef pair<int, int> pii;

template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }

inline int read() {
	int sum = 0, fg = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') fg = -1;
	for (; isdigit(c); c = getchar()) sum = (sum << 3) + (sum << 1) + (c ^ 0x30);
	return fg * sum;
}

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;

vector<pii> S[20];

int n, V, a[maxn];

int main() {
#ifdef xunzhen
	freopen("agc012e.in", "r", stdin);
	freopen("agc012e.out", "w", stdout);
#endif

	n = read(), V = read();
	for (int i = 1; i <= n; i++) a[i] = read();

	int N = 0, k = V;
	while (1) {
		int lst = 1;
		for (int j = 2; j <= n; j++)
			if (abs(a[j] - a[j - 1]) > k)
				S[N].push_back(mp(lst, j - 1)), lst = j;
		S[N].push_back(mp(lst, n));
		if (!k) break; k >>= 1, ++N;
	}

	static int F[1 << 18], G[1 << 18];
	memset(F, -0x3f, sizeof F), F[0] = 0;
	for (int s = 0, all = 1 << N; s < all; s++) {
		if (F[s] == -inf) continue;
		for (int i = 0; i < N; i++) {
			if ((s >> i) & 1) continue;
			int l = 0, r = S[i + 1].size() - 1;
			while (l <= r) {
				int mid = (l + r) >> 1;
				if (S[i + 1][mid].fst <= F[s] + 1) l = mid + 1;
				else r = mid - 1;
			}
			chkmax(F[s | (1 << i)], max(F[s], S[i + 1][l - 1].snd));
		}
	}

	memset(G, 0x3f, sizeof G), G[0] = n + 1;
	for (int s = 0, all = 1 << N; s < all; s++) {
		if (G[s] == inf) continue;
		for (int i = 0; i < N; i++) {
			if ((s >> i) & 1) continue;
			int l = 0, r = S[i + 1].size() - 1;
			while (l <= r) {
				int mid = (l + r) >> 1;
				if (S[i + 1][mid].snd >= G[s] - 1) r = mid - 1;
				else l = mid + 1;
			}
			chkmin(G[s | (1 << i)], min(G[s], S[i + 1][r + 1].fst));
		}
	}

	static int c[maxn];
	memset(c, 0x3f, sizeof c);
	for (int s = 0, all = (1 << N) - 1; s <= all; s++)
		if (F[s] >= 0) chkmin(c[F[s]], G[all ^ s]);
	for (int i = n - 1; ~i; i--) chkmin(c[i], c[i + 1]);

	static bool ans[maxn];
	for (pii t : S[0]) {
		if (c[t.fst - 1] <= t.snd + 1)
			for (int i = t.fst; i <= t.snd; i++) ans[i] = 1;
	}

	for (int i = 1; i <= n; i++) printf(ans[i] ? "Possible\n" : "Impossible\n");

	return 0;
}

Measured memory_bytes: 9072
#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(){
	int n;
	int ans=0;
	cin >>n;
	vector<int>a(n),b(n);
	rep(i,n){
		cin>>a[i];
		if(i!=0){
			a[i]+=a[i-1];
		}
	//	clog<<a[i]<<" ";
	}
	//clog<<endl;
	rep(i, n)

	{
		cin >> b[i];
		if (i != 0)
		{
			b[i] += b[i-1];
		}

	}
	//rep(i,n){
	//	clog<<b[i]<<" ";
	//}
	//clog<<endl;
	rep(i, n)
	{
		if(i!=0){
		chmax(ans,a[i]+b[n-1]-b[i-1]);
		}
		else{
			chmax(ans,a[i]+b[n-1]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
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<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#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 sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

ll N;
vl A;
int M[2*MX];

ll get(int m) {
    memset(M,0,sizeof M);
    ll csum = MX-1, tmp = 0, res = 0;
    M[csum] = 1;
    F0R(i,sz(A)) {
        if (A[i] < m) tmp -= M[--csum];
        else tmp += M[csum++];
        res += tmp+M[csum]; M[csum] ++; 
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> N; A.resize(N);
    F0R(i,N) cin >> A[i];
    
    int l = 1, r = 1000000000;
    while (l < r) {
        int m = (l+r+1)/2;
        if (2*get(m) >= N*(N+1)/2) l = m;
        else r = m-1;
    }
    cout << l;
}

/* Look for:
* the exact constraints (multiple sets are too slow for n=10^6 :( ) 
* special cases (n=1?)
* overflow (ll vs int?)
* array bounds
* if you have no idea just guess the appropriate well-known algo instead of doing nothing :/
*/

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << (x) << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, T b) { return b > a ? a = b, 1 : 0; }

inline int read() {
    int x(0), sgn(1); char ch(getchar());
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') sgn = -1;
    for (; isdigit(ch); ch = getchar()) x = (x * 10) + (ch ^ 48);
    return x * sgn;
}

void File() {
#ifdef zjp_shadow
	freopen ("F.in", "r", stdin);
	freopen ("F.out", "w", stdout);
#endif
}

const int N = 5e5 + 1e3;

char str[N]; int fail[N], len;

void Get_Fail(char *str, bool *Pass) {
	For (i, 2, len) {
		static int j;
		for (j = fail[i - 1]; j && str[j + 1] != str[i]; j = fail[j]);
		fail[i] = j + (str[j + 1] == str[i]);
	}
	For (i, 1, len)
		if (!fail[i] || i % (i - fail[i])) Pass[i] = true;
}

bool f[N], g[N];

int main () {

	File();

	scanf ("%s", str + 1);

	len = strlen(str + 1);
	Get_Fail(str, f);
	reverse(str + 1, str + len + 1);
	Get_Fail(str, g);
	reverse(g + 1, g + len + 1);

	if (f[len])
		return puts("1\n1"), 0;

	int ans = 0;
	For (i, 1, len - 1)
		if (f[i] && g[i + 1]) ++ ans;
	if (ans) printf ("2\n%d\n", ans);
	else printf ("%d\n1", len);

	return 0;

}


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

int k, a, b;

void solve() {
  cin >> k >> a >> b;
  cout << (a/k!=b/k||!(a%k)||!(b%k)?"OK":"NG") << endl;
}

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

  solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(void){
  int x;
  cin >> x;

  if (x < 1200){
    cout << "ABC" << endl;
  }else{
    cout << "ARC" << endl;
  }
}


Measured memory_bytes: 3612
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,res=0,ans,p,q;
		string word;
		cin>>word;
		N=word.size();
		string ant,sig;
		ant=word[0];
		sig=word[1];	
		res=1;
		for(i=2;i<N;){
			//cout<<ant<<" "<<sig<<"\n";
			if(ant==sig){
				sig.push_back(word[i]);
				i++;
			}
			else {
				ant=sig;
				res+=1;
				sig=word[i];
				i+=1;
			}
		}
		if(ant!=sig)res+=1;
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 640
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')

def main():
  r = int(readline())
  print(3*(r**2))
  
  
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5076
import sys
input = sys.stdin.readline

c = [[int(x) for x in input().split()] for _ in range(3)]

for i in range(101):
    for j in range(101):
        for k in range(101):
            b1, b2, b3 = [x - i for x in c[0]]
            if [b1 + j, b2 + j, b3 + j] == c[1] and [b1 + k, b2 + k, b3 + k] == c[2]:
                print("Yes")
                sys.exit()
print("No")



Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
using namespace std;
ll n,t;

int main(){
      ios_base::sync_with_stdio(false); cin.tie(NULL);
      cin>>n>>t;
      ll ans=0;
      while(n){
        ans++;n/=t;};
      cout<<ans;    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

void print_a(VI v)
{
    if(v.size()) cout<<v[0];
    loop(i,1,v.size()) cout<<' '<<v[i];
    cout<<'\n';
}

VVI init_vvi(int n, int m, int val)
{
    return VVI(n,VI(m,val));
}

VVL init_vvl(int n, int m, LL val)
{
    return VVL(n,VL(m,val));
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int a,b,c,k;
    cin>>a>>b>>c>>k;
    while(k && a >= b) {--k; b = b*2;}
    while(k && b >= c) {--k; c = c*2;}
    if(a < b && b < c) cout<<"Yes\n";
    else cout<<"No\n";

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3636
s = input()

right = 0
left = 0

li = []
count = 0
li_count = [0]

for i in s:
    if i == "R" and left == 0:
        right += 1
    elif i == "R":
        li.append([right,left])
        li_count.append(count)
        right = 1
        left = 0
    elif i == "L":
        left += 1
    count += 1
    if count == len(s):
        li.append([right,left])

ans_li = [0 for i in range(len(s))]

for i in range(len(li_count)):
    num = li_count[i] + li[i][0] - 1
    ans_li[num] = (li[i][0] + 1) // 2 + li[i][1] // 2
    ans_li[num + 1] = li[i][0] // 2 + (li[i][1] + 1) // 2
    
print(*ans_li)

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

long long int mob[101][4];

long long int gcd(long long int x, long long int y){
  if(x == 0)return y;
  else return gcd(y % x, x);
}

long long int lcf(long long int x, long long int y){
  return (x * y) / gcd(x, y);
}

long long int dfs(int x){
  if(x == 0)return 1;
  long long int r = mob[x][0] * dfs(mob[x][2]);
  long long int b = mob[x][1] * dfs(mob[x][3]);
  long long int m = lcf(r, b);
  return m / mob[x][0] +  m / mob[x][1];
  
}

int main(){
  while(1){
    int n, i, notTop[101], top;
    memset(notTop, 0, sizeof(notTop));
    memset(mob, 0, sizeof(mob));
    scanf("%d", &n);
    if(n == 0)return 0;
    for(i = 1;i <= n;i++){
      int p, q, r, b;
      scanf("%d%d%d%d", &p, &q, &r, &b);
      notTop[r] = notTop[b] = 1;
      mob[i][0] = p;
      mob[i][1] = q;
      mob[i][2] = r;
      mob[i][3] = b;
    }
    for(i = 1;i <= n;i++){
      if(notTop[i] == 0){
	top = i;
	break;
      }
    }
    printf("%lld\n", dfs(top));
  }
}

Measured memory_bytes: 600
unittest
{
	assert( [ "6", "ooxoox" ].parse.expand.solve == "SSSWWS" );
	assert( [ "3", "oox" ].parse.expand.solve == "-1" );
	assert( [ "10", "oxooxoxoox" ].parse.expand.solve == "SSWWSSSWWS" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto s = input.front;
	return tuple( s );
}

auto solve( string s )
{
	// 最初の二匹を仮定して整合性が取れるか判定
	foreach( a; [ "SS", "SW", "WW", "WS" ] )
	{
		auto ans = solve2( s, a );
		if( ans ) return ans.idup;
	}
	return "-1";
}

auto solve2( string s, string a )
{
	s ~= s[ 0 ];
	auto anss = new char[ s.length + 1 ];
	anss[ 0 .. 2 ] = a;
	for( auto i = 1L; i < s.length; i++ )
	{
		final switch( anss[ i - 1 .. i + 1 ] )
		{
			case "SS": anss[ i + 1 ] = ( s[ i ] == 'o' ) ? 'S' : 'W'; break;
			case "SW": anss[ i + 1 ] = ( s[ i ] == 'o' ) ? 'W' : 'S'; break;
			case "WW": anss[ i + 1 ] = ( s[ i ] == 'o' ) ? 'S' : 'W'; break;
			case "WS": anss[ i + 1 ] = ( s[ i ] == 'o' ) ? 'W' : 'S'; break;
		}
	}
	return ( anss[ 0 .. 2 ] == anss[ $ - 2 .. $ ] ) ? anss[ 0 .. $ - 2 ] : null;
}


Measured memory_bytes: 2812
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

const int magic = 50;

bool Get(long long used0, long long used1, int ind) {
	if (ind < magic) {
		return ((used0 >> ind) & 1);
	}
	return ((used1 >> (ind - magic)) & 1);
}

void Or(long long& used0, long long& used1, int ind) {
	if (ind < magic) {
		used0 |= (1LL << ind);
	} else {
		used1 |= (1LL << (ind - magic));
	}
}

long long Go(const vector<int>& a, int n, long long used0, long long used1, int ind) {
	if ((ind + 1) * 3 > n) {
		long long res = 0;
		for (int i = ind; i < n; ++i) {
			if (Get(used0, used1, i)) {
				continue;
			}

			if ((i & 1) && ((i - 1) >> 1) >= ind) {
				continue;
			}

			if (2 * i + 1 < n) {
				if (Get(used0, used1, 2 * i + 1)) {
					res += max(a[i], 0);
				} else {
					res += max(a[i] + a[2 * i + 1], max(a[i], 0));
				}
			} else {
				res += max(a[i], 0);
			}
		}
		return res;
	}

	if (Get(used0, used1, ind)) {
		return Go(a, n, used0, used1, ind + 1);
	}

	long long new_used0 = used0;
	long long new_used1 = used1;
	for (int x = ind + 1; x <= n; x += (ind + 1)) {
		Or(new_used0, new_used1, x - 1);
	}

	return max(a[ind] + Go(a, n, used0, used1, ind + 1), Go(a, n, new_used0, new_used1, ind + 1));
}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	int n;
	cin >> n;

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

	long long res = Go(a, n, 0, 0, 0);
	cout << res << endl;

	return 0;
}


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

using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define repd(i, a, b) for(int i = (a); i > (b); i--)
#define forRev(it, a) for(__typeof((a).rbegin()) it = (a).rbegin(); it != (a).rend(); it++)
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define sz(a) (int)(a).size()
#define bc(n) __builtin_popcountll(n)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;

const int N = 100 + 7;
const int M = 350;
const int inf = 1e9 + 7;
const long long linf = 1e18 + 7;
const double pi = acos(-1);
const double eps = 1e-7;
const bool multipleTest = 0;

int n, m, k;
int res[N][N];
int a[N * N];

void solve() {
    cin >> n >> m >> k;
    int dir = 0;
    for (int j = 0; j < k; ++j) scanf("%d", a + j);
    int i = 0, j = 0;
    for (int t = 0; t < k; ++t) {
        while (a[t]--) {
            res[i][j] = t + 1;
            if (dir == 0) {
                if (j + 1 < m) ++j;
                else {
                    ++i; dir = 1;
                }
            } else {
                if (j > 0) --j;
                else {
                    ++i; dir = 0;
                }
            }
        }
    }
    rep(i, 0, n) {
        rep(j, 0, m) cout << res[i][j] << ' ';
        puts("");
    }
    
}

void test() {
}

int main() {
#ifdef _LOCAL_
    freopen("in.txt", "r", stdin);
    //    freopen("out.txt", "w", stdout);
#endif
    int Test = 1;
    if (multipleTest) {
        cin >> Test;
    }
    for(int i = 0; i < Test; ++i) {
//        test();
        solve();
    }
    
#ifdef _LOCAL_
    cout<<"\n" << 1.0 * clock() / CLOCKS_PER_SEC <<endl;
#endif
}


Measured memory_bytes: 384
// Why am I so dumb? :c
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair

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

#define fi first
#define se second

using namespace std;

typedef long long ll;

const int MAXN = (int)1e5 + 5;

pair<int, int> p[MAXN * 2];

pair<int, int> arr[MAXN];

int a[MAXN], b[MAXN];

ll ans;	

int n;

void solve() {
	scanf("%d", &n);

	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", &a[i], &b[i]);
	}

	for (int i = 1; i <= n; ++i) {
		p[i] = mp(a[i], i);
		p[n + i] = mp(b[i], n + i);
	}	
	
	sort(p + 1, p + (2 * n) + 1);

	for (int i = 1; i <= (2 * n); ++i) {
		if (p[i].se > n) {
			arr[p[i].se - n].se = i;
		}
		else {
			arr[p[i].se].fi = i;
		}
	}

	ans = (ll)1e18;

	{
		ll s1 = 0, s2 = 0;

		for (int i = 1; i <= n; ++i) {
			s1 += a[i];
			s2 += b[i];
		}

		ans = min(ans, s1);
		ans = min(ans, s2);
	}

	ll S = 0;

	for (int i = 1; i <= n - 2; ++i) {
		S += p[i].fi;
	}

	for (int i = 1; i <= n; ++i) {
		if (arr[i].fi > n - 2 && arr[i].se > n - 2) {
			ans = min(ans, S + a[i] + b[i]);
			continue;
		}

		if (arr[i].fi <= n - 2 && arr[i].se <= n - 2) {
			ans = min(ans, S + p[n - 1].fi + p[n].fi);
			continue;
		}        

		if (arr[i].fi <= n - 2) {
			if (arr[i].se == n - 1) {
				ans = min(ans, S + p[n].fi + b[i]);
			}
			else {
				ans = min(ans, S + p[n - 1].fi + b[i]);
			}
		}
		else {
			if (arr[i].fi == n - 1) {
				ans = min(ans, S + p[n].fi + a[i]);
			}
			else {
				ans = min(ans, S + p[n - 1].fi + a[i]);
			}
		}
    }

	printf("%lld\n", ans);
}

int main() {
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int a, p, b;
	
	scanf("%d %d", &a, &p);
	
	b=3*a;
	
	printf("%d", (b+p)/2);
	
	return 0;
}

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

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fore(x,a,b) for(int x=a, qwerty=b; x<qwerty; x++)
#define ALL(a) (a).begin(),(a).end()
#define SZ(a) ((int)(a).size())
#define pb push_back
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fst first
#define snd second
#define mset(a,v) memset((a),(v),sizeof(a))
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
using namespace std;
typedef long long ll;
ll dp[512][512],sp[512][512],a[512],n;
int main(){FIN;
	cin>>n;
	fore(i,0,n)cin>>a[i];
	fore(i,0,n)fore(j,i,n){
		ll s=0;fore(k,i,j+1)s+=a[k];
		sp[i][j]=s;
	}
	fore(l,1,n){
		fore(i,0,n){
			int j=min(ll(i+l),n-1);
			if(i==j)continue;
			ll &r=dp[i][j];
			r=dp[i][i]+dp[i+1][j]+a[i]+sp[i+1][j];
			fore(k,i+1,j)r=min(r,dp[i][k]+dp[k+1][j]+sp[i][j]);
		}
	}
	cout<<dp[0][n-1]<<"\n";
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
#define MOD 1000000007
#define mp make_pair
#define fir first
#define sec second
#define MAXN 310
using namespace std;
typedef pair<int,int> par;
inline int read ()
{
	int s=0,w=1;
	char ch=getchar ();
	while (ch<'0'||ch>'9'){if (ch=='-') w=-1;ch=getchar ();}
	while ('0'<=ch&&ch<='9') s=(s<<1)+(s<<3)+(ch^48),ch=getchar ();
	return s*w;
}
int n,m,ans,Ans;
int f[MAXN][MAXN][MAXN];
vector<par>a[MAXN];
void inc (int &x,int y){x=x+y>=MOD?x+y-MOD:x+y;}
int main()
{
	n=read (),m=read ();
	for (int i=1;i<=m;i++)
	{
		int l=read (),r=read (),x=read ();
		a[r].push_back (mp (l,x));
	}
	f[1][0][0]=1;
	for (int i=1;i<=n;i++)
	{
		for (int j=0;j<a[i].size();j++)
		{
			int l=a[i][j].fir,x=a[i][j].sec;
			for (int k=0;k<i;k++)
				for (int p=0;p<=max (0,k-1);p++)
				{
					if (x==1)
					{
						if(l<=k) f[i][k][p]=0;
					}
					else if (x==2)
					{
						if(k<l||l<=p) f[i][k][p]=0;
					}
					else
					{
						if(p<l) f[i][k][p]=0;
					}
				}
		}
		if (i==n) break;
		for (int j=0;j<i;j++)
			for (int k=0;k<=max (0,j-1);k++)
				if (!f[i][j][k]) continue;
				else
				{
					inc (f[i+1][j][k],f[i][j][k]);
					inc (f[i+1][i][k],f[i][j][k]);
					inc (f[i+1][i][j],f[i][j][k]);
				}
	}
	for (int j=0;j<n;j++)
		for (int k=0;k<=max (0,j-1);k++) inc (ans,f[n][j][k]);
	inc (Ans,ans),inc (Ans,ans),inc (Ans,ans);
	printf ("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 113024
N = int(input())
H = list(map(int, input().split()))
ans = 0
c = 0
H.reverse()

for i in range(1, len(H)):
    if H[i] >= H[i - 1]:
        c += 1
    else:
        c = 0
    ans = max(c, ans)

print(ans)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  int mi=1<<30;
  int ma=0;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    mi =min(a.at(i),mi);
    ma =max(a.at(i),ma);
  }
  int ans = 1<<30;
  for(int i=mi;i<=ma;i++){
    int sum =0;
    for(int j=0;j<n;j++){
      sum += (i-a.at(j))*(i-a.at(j));
    }
    ans = min(ans,sum);
  }
  cout << ans <<endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    VI A(N);
    REP(i,N) cin >> A[i];
    int ans = 0;
    REP(i,N){
        if(i%2 == 0 and A[i]%2 == 1) ans++;
    }
    cout << ans << endl;

}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i=0;i<N;++i){
        cin >> d.at(i);
    }

    int ans=0;
    for(int i=0;i<N;++i){
        for(int j=i+1;j<N;++j){
            ans += d[i] * d[j];
        }
    }
    cout << ans << endl;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	int n, ma, mb;
	cin >> n >> ma >> mb;

	vector<vector<ll>> dp(401, vector<ll>(401, IINF));
	dp[0][0] = 0;
	rep(k, n){
		int a, b, c;
		cin >> a >> b >> c;
		for(int i = 400; i >= 0; i--){
			for(int j = 400; j >= 0; j--){
				int na = i+a;
				int nb = j+b;
				if(400 < na || 400 < nb) continue;
				dp[na][nb] = min(dp[na][nb], dp[i][j] + c);
			}
		}
	}

	ll ans = IINF;
	for(int i = 1; i * max(ma, mb) <= 400; i++){
		ans = min(ans, dp[ma*i][mb*i]);
	}

	cout << (ans != IINF ? ans : -1) << endl;

	return 0;
}


Measured memory_bytes: 1536
def solve(i, m):
  if dp[i][m] != -1:
    return dp[i][m]

  if m == 0:
    dp[i][m] = 1
  elif i >= n:
    dp[i][m] = 0
  elif solve(i+1, m):
    dp[i][m] = 1
  elif solve(i+1, m-A[i]):
    dp[i][m] = 1
  else:
    dp[i][m] = 0

  return dp[i][m]



n = input()
A = map(int, raw_input().split())
p = input()
m = map(int, raw_input().split())

dp = [[-1 for col in range(2000)] for row in range(n+1)]

for i in range(p):
  if solve(0, m[i]):
    print 'yes'
  else:
    print 'no'

Measured memory_bytes: 6688
import sys
def main():
    a, b, c, d= map(int, input().split())
    flag = 1
    while True:
        if flag:
            c -= b
        else:
            a -= d

        flag ^= 1
        if a <= 0 or c <= 0:
            if a <= 0:
                print('No')
                sys.exit()
            else:
                print('Yes')
                sys.exit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#include <math.h>
int n,m,i,j,k,count1=0,count2=0;
using namespace std;
void ABC120(void);
void ABC121(void);
void ABC122(void);
void ABC123(void);
void ABC124(void);
void ABC125(void);
void ABC126(void);
void ABC127(void);
void ABC128(void);
void ABC129(void);

int main(void){
    ABC126();
}

void ABC126(){
    string s;
    cin>>s;
    int a,b,ad=0,bd=0;
    a=stoi(s.substr(0,2));
    b=stoi(s.substr(2,2));
    cerr<<a<<" "<<b<<endl;
    if(a>0&&a<=12)ad=1;
    if(b>0&&b<=12)bd=1;
    if(ad==1&&bd==1)cout<<"AMBIGUOUS"<<endl;
    if(ad==1&&bd==0)cout<<"MMYY"<<endl;
    if(ad==0&&bd==1)cout<<"YYMM"<<endl;
    if(ad==0&&bd==0)cout<<"NA"<<endl;
}

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

int main(){
   string s,t;
   cin >> s >> t;
   int c=0;
    if(s[0]==t[0])
        c++;
    if(s[1]==t[1])
        c++;
        if(s[2]==t[2])
        c++;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
int a[N];
int main()
{
    std::ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    for(int i=2;i<=n;i++)
    {
        int ii=i;
        for(int j=2;j<=i;j++)
        {
            while(ii%j==0)
            {
                a[j]++;
                ii/=j;
            }
        }
    }
    ll ans=1;
    for(int i=2;i<=n;i++)
    {
    //    cout<<a[i]<<endl;
        ans=(ans*(a[i]+1))%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int sum = 0;
void bubbleSort(int A[], int n)
{
	int i,j;
	int t;
	for (i = 0; i < n; i++)
	{
		for(j=n-1;j>=i+1;j--)
			if (A[j] < A[j - 1])
			{
				sum++;
				t = A[j];
				A[j] = A[j - 1];
				A[j-1] = t;
			}
	}
}
int main()
{
	int i, n, A[100];

	scanf("%d",&n);

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

	for (i = 1; i < n; i++)
	{
		printf(" %d", A[i]);
	}
	printf("\n");
	printf("%d\n",sum);

	return 0;
}


Measured memory_bytes: 2720
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s, t;
    cin >> s >> t;

    sort(all(s));
    sort(all(t));
    reverse(all(t));

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define DEBUG

using namespace std;

const ll N = 1e5 + 7;
const ll mod = 1e18 + 7;

ll a, b, res;

int main()
{
    speed;
    /// Author: Dilshod--Imomov
    #ifdef DEBUGc
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif // DEBUG
    cin >> a >> b;
    ll g = __gcd(a, b);
    bool ok;
    for ( ll i = 2; i * i <= g; i++ ) {
        ok = false;
        while ( g % i == 0 ) {
            g /= i;
            ok = true;
        }
        res += ok;
    }
    res++;
    res += (g > 1);
    cout << res;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
A = sorted(A ,reverse = True)
i = 0
ans = 0
while N > 1:
  if i == 0:
    ans += A[i]
    i += 1
    N -= 1
  elif N == 2:
    ans += A[i]
    break
  else:
    ans += A[i] * 2
    i += 1
    N -= 2
print(ans)
    

Measured memory_bytes: 105288
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int r;
  cin >> r;
  cout << 3*r*r<<endl;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"

using namespace std;
using namespace __gnu_pbds;

#define ll long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
vector<pair<ll, ll>> v[20];
ll	 cur[20];
int main(void)
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, temp, ans = 0;
    cin>>n;
    ll i, j;
    for(i=0; i<n; i++) {
    	cin>>temp;
    	while(temp--) {
    		ll x, y;
    		cin>>x>>y;
    		x--;
    		v[i].pb(mp(x, y));
    	}
    }
    for(i=1; i < (1<<n); i++) {
		bitset<20> b(i);
    	ll flag = 1;
    	for(j=0; j<n; j++) {
    		cur[j] = -1;
    	}
    	for(j=0; j<n; j++) {
    		if(i & (1 << j)) {
    			for(auto u: v[j]) {
    				if(u.ss == 0 && (i & (1 << u.ff))) {
    					flag = 0;
    					goto here;
    				} 
    				if(u.ss == 1 && !(i & (1 << u.ff))) {
    					flag = 0;
    					goto here;
    				}
    				if(cur[u.ff] == -1) {
    					cur[u.ff] = u.ss;
    				}
    				else if(cur[u.ff] != u.ss) {
    					flag = 0;
    					goto here;
    				}
    			}
    		}
    	}
    	here:
    	if(flag) {
    		ans = max(ans, (ll)b.count());
    	}
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String S = in.next();
            out.println(S.substring(0, 3));

        }

    }
}



Measured memory_bytes: 35648
#include "bits/stdc++.h"
using namespace std;

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
const int inf = 1000000001;
const ll INF = 2e18 * 2;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };


#define MAXM 100010
vl fact(MAXM);
vl C(MAXM);

ll mod_pow(ll x, ll p, ll M) {
	ll a = 1;
	while (p) {
		if (p % 2)
			a = a*x%MOD;
		x = x*x%MOD;
		p /= 2;
	}
	return a;
}

ll mod_inverse(ll a, ll m) {
	return mod_pow(a, m - 2, m);
}

ll nCr(ll n, ll r) {
	ll ret = fact[n];
	ret = (ret*mod_inverse(fact[r], MOD)) % MOD;
	ret = (ret*mod_inverse(fact[n - r], MOD)) % MOD;
	return ret;
}


int main() {
	ll n, m, i, j;
	cin >> n >> m;
	
	fact[0] = fact[1] = 1LL;
	for (i = 2; i < max(n, m) + 1; i++) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	vl x(n), y(m);
	for (i = 0; i < n; i++) {
		cin >> x[i];
	}
	for (j = 0; j < m; j++) {
		cin >> y[j];
	}
	vl sx(n - 1);
	ll sumx = 0;
	for (i = 0; i < n - 1; i++) {
		sx[i] = x[i + 1] - x[i];
		sx[i] = sx[i] * (i + 1) % MOD * (n - i - 1) % MOD;
		(sumx += sx[i]) %= MOD;
	}

	vl sy(m - 1);
	ll ans = 0;
	for (i = 0; i < m - 1; i++) {
		sy[i] = y[i + 1] - y[i];
		sy[i] = sy[i] * (i + 1) % MOD * (m - i - 1) % MOD;
		(ans += sy[i] * sumx % MOD) %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4992
import java.lang.reflect.Array;
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int t=in.nextInt();
		while(t-->0)
		{
			int n=in.nextInt();//家の数
			int k=in.nextInt();//発電機
			int a[]=new int[n];//家の位置
			int cnt=0;
			for(int i=0;i<n;i++)
				a[i]=in.nextInt();
			int dis[]=new int[n-1];
			for(int i=0;i<n-1;i++)
				dis[i]=a[i+1]-a[i];
			Arrays.sort(dis);
			for(int i=0;i<dis.length-k+1;i++)
				cnt+=dis[i];
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 112108
#include <bits/stdc++.h>    
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//using namespace __gnu_pbds; 
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cout<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define endl "\n"
#define int long long 
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
const ll MOD     = 1000*1000*1000+7;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7;
const ll MOD2    = 998244353;
const ll N       = 1000 * 100 + 10;
const ll N2      = 70;
const ld PI  = 3.141592653589793;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);} 
ll power(ll x,ll y,ll p = LLONG_MAX ){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
ll lcm(ll a , ll b){return (a*b)/gcd(a,b);}

signed main()
{
    fastio();
    //cout<<fixed<<setprecision(20);
    //CHECK for LONG LONG and LONG DOUBLE
    //*comment for all except cc/cf    
    #ifndef ONLINE_JUDGE    
           freopen("input.txt","r",stdin);
           freopen("output.txt","w",stdout);
    #endif//*/
    int n;
    cin>>n;
    string s;
    cin>>s;
    int ans = 0;
    for (int i = 0; i < n; ++i)
    {
        set<char> s1,s2;
        for (int j = 0; j <=i; ++j)
        {
            s1.insert(s[j]); 
        }
        for(int j = i+1  ; j<n ; j++)
        {
            s2.insert(s[j]);
        }
        set<char> ss;
        for(auto x : s1)
            ss.insert(x);
        for(auto x : s2)
            ss.insert(x);

        int c = s1.size() + s2.size() - ss.size();

        ans = max((int)ans,c);
    }
    cout<<ans;



    printclock;
    return 0;
}


Measured memory_bytes: 3848
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define SQ(x) (x)*(x)
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

// #define int ll

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}

ll mpow(ll a, ll n){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mod;
        a = a*a %mod;
        n>>=1;
    }
    return re;
}

ll inv (ll b){
    if (b==1) return b;
    return (mod-mod/b) * inv(mod%b) % mod;
}

const int maxn = 2505;

// vector<pii> g[maxn];
vector<pair<pii, int> > e;
int mx[maxn];

main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, m, p; cin>>n>>m>>p;

    REP(i,m){
        int a, b, w; cin>>a>>b>>w; a--; b--; w-=p;
        // g[a].pb({b,w});
        e.pb({{a,b},w});
    }

    fill(mx, mx+n, -iinf);
    mx[0]=0;
    REP(i,n+2){
        for (auto &x : e){
            MXTO(mx[x.f.s], mx[x.f.f] + x.s);
        }
    }
    int nval = mx[n-1];
    REP(i,n){
        for (auto &x : e){
            MXTO(mx[x.f.s], mx[x.f.f] + x.s);
        }
    }
    if (nval<mx[n-1]){
        // cout<<mx[n-1]<<endl;
        cout<<-1<<endl; return 0;
    }
    cout<<max(mx[n-1],0)<<endl;
} 

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

int main(void)
{
	int N;
	cin >> N;

	int *a = new int[N];
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	sort(a, a + N);

	int tmp = a[0], cnt = 1, sum = 0;
	for (int i = 1; i < N; ++i) {
		if (tmp == a[i]) {
			++cnt;
			continue;
		} else {
			if (cnt < tmp)	sum += cnt;
			else sum += cnt - tmp;
			tmp = a[i];
			cnt = 1;
		}
	}
	if (cnt < tmp)	sum += cnt;
	else sum += cnt - tmp;

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 5e3 + 5;
const ll LINF = 1e18 + 5;
int n;
char s[N];
int nxt[N];
void kmp_pre(char s[], int m, int nxt[])
{
	int i = 0, j = nxt[0] = -1;
	while(i<m)
	{
		while(j!=-1&&s[i]!=s[j]) j = nxt[j];
		nxt[++i] = ++j;
	}
}
bool kmp_work(char s[], int n, char t[], int m) 
{
	int i = 0, j = 0;
	kmp_pre(s, n, nxt);
	while(i<m)
	{
		while(j!=-1&&t[i]!=s[j]) j = nxt[j];
		i++; j++;
		if(j>=n) return 1;
	}
	return 0; 
}
bool check(int x)
{
	for(int i=0; i+2*x-1<n; i++)
		if(kmp_work(s+i, x, s+i+x, n-i-x)) return 1;
	return 0;
}
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n >> s;
 	int l = 1, r = n/2, ans = 0;
 	while(l<=r)
 	{
 		int mid = (l+r)>>1;
 		if(check(mid)) ans = mid, l = mid + 1;
 		else r = mid - 1;
 	}
 	cout << ans;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}

pll operator+(pll a,pll b){
  return {a.first+b.first,a.second+b.second};
}
class UF{
  vector<int> par,rank,size_uf;
public:
  UF(int size){
    for (int i = 0; i < size; i++) {
      par.push_back(i);
      rank.push_back(0);
      size_uf.push_back(1);
    }
  }
  int find(int x){
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y]){
      par[x]=y;
      size_uf[y]+=size_uf[x];
    }
    else{
      par[y]=x;
      size_uf[x]+=size_uf[y];
      if(rank[x]==rank[y])rank[x]++;
    }
  }
  bool same(int x,int y){
    return find(x)==find(y);
  }
  int operator [](int x){
    return this->find(x);
  }
  int size(int x){
    x=find(x);
    return size_uf[x];
  }
};

void solve(long long N, std::vector<long long> x, std::vector<long long> y)
{
  vector<pll> B(N);
  REP(N)
  {
    B[i].first = x[i];
    B[i].second = y[i];
  }
  sort(B.begin(), B.end());
  ll ans = 0;
  for (long long i = 0; i < N; i++)
  {
    for (long long j = i + 1; j < N; j++)
    {
      pll dist;
      dist.first = B[j].first - B[i].first;
      dist.second = B[j].second - B[i].second;
      UF uf(N);
      for (long long k = 0; k < N; k++)
      {
        if (binary_search(B.begin(), B.end(), B[k] + dist))
        {
          auto l=lower_bound(B.begin(), B.end(), B[k] + dist) - B.begin();
          uf.unite(k,l);
        }
      }
      set<ll> s;
      For(k,N){
        s.insert(uf.find(k));
      }
      ll tmp=0;
      for (auto &&k : s)
      {
        tmp+=uf.size(k)-1;
      }
      ans=max(ans,tmp);
    }
  }
  cout<<N-ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    solve(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
N=int(input())
A=[0]+list(map(int,input().split()))+[0]
cost=sum(abs(A[i+1]-A[i]) for i in range(N+1))
for i in range(1,N+1):
    print(cost-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))+abs(A[i-1]-A[i+1]))

Measured memory_bytes: 14048
def resolve():
    '''
    code here
    '''

    N, M = [int(item) for item in input().split()]
    bridges = [[int(item) for item in input().split()] for _ in range(M)]

    bridges = sorted(bridges, key=lambda x:x[1])
    res = 1

    prev = bridges[0][1]
    for a, b in bridges:
        if a >= prev:
            res +=1
            prev = b

    print(res)    



if __name__ == "__main__":
    resolve()


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

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;


int main(void) {
	
	int a, b;

	cin >> a >> b;

	cout << max(a + b, max(a - b, a*b)) << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=n; s=a[0]; r=0
for l in range(n-1):
    while r<n-1 and not(s&a[r+1]):
        s^=a[r+1]
        r+=1
    ans+=r-l
    s^=a[l]
print(ans)


Measured memory_bytes: 77772
#s = int(input())
#first = s//100
#second = s%100
s=input()
first = int(s[:2])
second = int(s[2:])
#print(first,second)

if (first > 12 or first < 1) and (second > 12 or second < 1):
  print('NA') # YY/YY
elif (first > 12 or first == 0) and (second > 0 and second <=12):
  print('YYMM')
elif (first > 0 and first <= 12) and (second ==0 or second > 12):
  print('MMYY')
else:
  print('AMBIGUOUS')

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, x, y;

struct union_find {//1-origin
    vector<int> rnk, par;
    union_find(int n) {
        rnk.resize(n+1);
        par.resize(n+1);
        for(int i = 1; i <= n; i++){
            par[i] = i;
            rnk[i] = 0;
        }
    }
    
    int find(int x) {
        if (par[x] == x) return x;
        return par[x] = find(par[x]);
    }
 
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rnk[x] < rnk[y]) {
            par[x] = y;
        }
        else {
            par[y] = x;
            if (rnk[x] == rnk[y])rnk[x]++;
        }
    }
    
    bool same(int x, int y) {
        return (find(x) == find(y));
    }
};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
	    
    cin >> n;
    ll m = 100000;
    union_find uf(2*m);

    rep(i, 1, n){
        cin >> x >> y;
		uf.unite(x, y+m);
    }
    
    ll szt[m+1], szy[m+1];
    memset(szt, 0, sizeof(szt));
    memset(szy, 0, sizeof(szy));
    rep(i, 1, m){
        szt[uf.find(i)]++;
    }
    rep(i, m+1, 2*m){
    	if(uf.find(i) <= m){
    		szy[uf.find(i)]++;
    	}
    }

    ll ans = 0;
    rep(i, 1, m){
        ans += szt[i]*szy[i];
    }
    ans -= n;
    print(ans)
    return 0;
}

Measured memory_bytes: 3456