akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>

int main(){
  int i,flag[26]={},j,flag1=0,k;
  char s[26],ss[26];
  scanf("%s",s);
  for(i=0;i<strlen(s);i++){
    flag[s[i]-'a']=1;
  }
  if(strlen(s)!=26){
    for(i=0;i<26;i++){
      if(!flag[i]){
        printf("%s%c\n",s,i+'a');
        break;
      }
    }
  }
  else{
    for(i=0;i<strlen(s);i++){
      flag[s[i]-'a']=i;
    }
    for(i=24;i>=0;i--){
      for(k=s[i]-'a'+1;k<26;k++){
        if(flag[k]>=i){
          for(j=0;j<i;j++) printf("%c",s[j]);
          printf("%c\n",k+'a');
          flag1=1;
          break;
        }
      if(flag1) break;
      }
if(flag1) break;

    }
    if(!flag1) printf("-1\n");
  }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define int long long

const char WHITE = '1';
const int INF = 1e7;
int H, W, K;

signed main(){
    cin >> H >> W >> K;
    
    vector<string> chocolate(H);
    rep(i,H) cin >> chocolate[i];

    bitset<10> column_cut;
    int ans = INT_MAX;
    for(int i = 0; i < 1<<(H-1); i++){
        column_cut = i;
        int cuts = column_cut.count();
        auto area = vector<int>(10,0);
        
        int changed = -1;
        rep(w,W){
            int c = 0;
            rep(h,H){
                if(chocolate[h][w]==WHITE) area[c]++;
                if(column_cut[h]) c++;
            }
            for(int white_chocolates: area){
                if(white_chocolates > K){
                    cuts++;
                    if(changed == w) cuts = INF;
                    rep(a,10) area[a] = 0;
                    changed = w;
                    w--;
                }
            }
            if(cuts >= INF) break;
        }
        ans = min(ans, cuts);
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
import math

def average(l):
    return sum(l) / len(l)

def var(l):
    a = average(l)
    return sum(map(lambda x: (x-a)**2, l)) / len(l)

def std(l):
    return math.sqrt(var(l))

if __name__ == '__main__':
    while True:
        n = int(input())
        if n == 0:
            break
        l = [int(i) for i in input().split()]
        print("{0:.5f}".format(std(l)))

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  for(int i = 0; i < N; i++){
    if(!(S.at(i) == S.at(K-1))) S.at(i) = '*';
  }
  cout << S << endl;
}

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

ans = 0
n = int(input())
A = list(map(int,input().split()))
B = [0] * (10**6+3)
ans = 0
A.sort()
for i in range(n):
    if (i == 0 or A[i] != A[i-1]) and (i == n-1 or A[i] != A[i+1]) and B[A[i]] == 0:
        ans += 1
    if (i == 0 or A[i] != A[i-1]):
        m = A[i]
        while m < len(B):
            B[m] = 1
            m += A[i]
print(ans)

Measured memory_bytes: 104132
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll dp[2010][2010];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    ll S[N];
    ll T[M];
    REP(i, 0, N) {
        cin >> S[i];
    }
    REP(i, 0, M) {
        cin >> T[i];
    }
    fill(dp[0], dp[0] + M + 1, 1);
    REP(i, 1, N + 1) {
        dp[i][0] = 1;
        REP(j, 1, M + 1) {
            dp[i][j] = modadd(dp[i][j - 1], modminus(dp[i - 1][j], dp[i - 1][j - 1]));
            if (S[i - 1] == T[j - 1]) {
                dp[i][j] = modadd(dp[i][j], dp[i - 1][j - 1]);
            }
        }
    }
    // REP(i, 0, N + 1) {
    //     REP(j, 0, M + 1) {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    ll ans = dp[N][M];
    cout << ans << endl;
}


Measured memory_bytes: 31744
import itertools
import math

N = int(input())
x = [input().split(" ") for j in range(N)]
ite = [i for i in range(N)]
iterter = list(itertools.permutations(ite,N))

ans = 0
fact = math.factorial(N)

for i in iterter:
    for j in range(len(i) - 1):
        tmp = math.sqrt(((int(x[i[j]][0]) - int(x[i[j + 1]][0])) ** 2) + ((int(x[i[j]][1]) - int(x[i[j + 1]][1]))**2))
        ans += tmp
    
print(ans / fact)

Measured memory_bytes: 7972
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int A,B,C;
    cin >> A >> B >> C;
    string ans="Yes";
    if(A==B && B==C)ans="No";
    else if(A!=B && B!=C && C!=A) ans="No";
    cout << ans << endl;



}


Measured memory_bytes: 256
#include<math.h>
float x,y,s,t,u,v,a,b,c,X,Y;
main(){
	scanf("%*d");
	for(;~scanf("%f%f%f%f%f%f",&x,&y,&s,&t,&u,&v);
			printf("%.3f %.3f %.3f\n",X,Y,hypot(X-x,Y-y)))
		c=x*x+y*y,a=c-s*s-t*t,b=c-u*u-v*v,
		s-=x,t-=y,u-=x,v-=y,
		c=s*v-t*u,X=(t*b-a*v)/2/c,Y=(a*u-s*b)/2/c;
}

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

int main() {

    int N, N1, sum;
    cin >> N;
    sum = 0;
    N1 = N;

    while(N > 0){
       sum += N % 10;
       N /= 10;

    }

    if (N1 % sum == 0)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a.at(i);
  rep(i, n){
    bool f = false;
    if(i == 0){
      if(a.at(i) != 0) f = true;
    }else{
      if(a.at(i) - a.at(i-1) > 1) f = true;
    }
    if(f == true){
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> ans(n);
  rep(i, n){
    ans.at(i) = i - a.at(i);
  }

  ll aa = 0;
  rrep(i, n){
    if(i == n-1 || ans.at(i) != ans.at(i+1)){
      aa += i - ans.at(i);
    }
  }
  cout << aa << endl;
  return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int INF = 100000;
struct Edge { int from, to, cost; };

int main() {
    int n, m;
    while (cin >> n >> m, n) {
        vector<Edge> G;
        int a, b, cost;
        for (int i=0; i<m; ++i) {
            cin >> a >> b >> cost;
            G.push_back((Edge){ a, b, cost });
            G.push_back((Edge){ b, a, cost });
        }
        int ret = 0;
        bool used[100] = {};
        used[0] = true;
        while (1) {
            int k, mn = INF;
            for (int i=0; i<(int)G.size(); ++i) {
                if (used[G[i].from] && ! used[G[i].to] && G[i].cost < mn) {
                    mn = G[i].cost;
                    k = i;
                }
            }
            if (mn == INF) break;
            used[G[k].to] = true;
            ret += G[k].cost;
        }
        cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
const int maxn=110;
int n,k,x[maxn],y[maxn],h[maxn],li;
inline int myabs(int xx){
    return xx<0?-xx:xx;
}
int main(){
    scanf("%d",&n);
    for(register int i=1;i<=n;i++){
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
        if(h[i]) li=i;
    }
    bool flag;int h0,hi;
    for(register int px=0;px<=100;px++) for(register int py=0;py<=100;py++){
        flag=true;h0=myabs(px-x[li])+myabs(py-y[li])+h[li];
        for(register int i=1;i<=n;i++){
            hi=h0-myabs(px-x[i])-myabs(py-y[i]);
            if(hi<0) hi=0;
            if(hi!=h[i]){
                flag=false;break;
            }
        }
        if(flag&&(h0>=1)){
            printf("%d %d %d\n",px,py,h0);return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <cstdlib>
typedef long long ll;
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
 
using namespace std;
 
int main(){

    ll a,b,c;
    cin >> a >> b >> c;

    if(a%2 == 0 || b%2 == 0 || c%2 ==0)cout << 0;
    else{
        ll x;
        x = min(a*b,a*c);
        x = min(x,b*c);
        cout << x;
    }
}

Measured memory_bytes: 256
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = [0] * (N + 1)
ans = 1
for i in range(1, N + 1):
    D[i] = D[i - 1] + L[i - 1]
    if(D[i] <= X): ans += 1
print(ans)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <cstdio>
 
using namespace std;
 
int main()
{
    string S, T;
    cin >> S >> T;
 
    const int NOT_FOUND = -1;
    int match_location = NOT_FOUND;
 
    for(int i = 0; i + T.size() - 1 < S.size(); i++)
    {
        int match_made = true;
        for(int j = 0; j < T.size(); j++)
        {
            if(S[i + j] != T[j] && S[i + j] != '?')
            {
                match_made = false;
            }
        }
 
        if(match_made)
            match_location = i;
    }
 
    for(int i = 0; i < S.size(); i++)
        if(S[i] == '?')
            S[i] = 'a';
 
    for(int i = 0; i < T.size(); i++)
        S[match_location + i] = T[i];
 
    if(match_location == NOT_FOUND)
        cout << "UNRESTORABLE" << endl;
    else
        cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
$N=<>;
map{
	$t="0"x$N;
	<>=~$",vec($t,$`-1,8)=$'+49 for 1..<>;
	$T[$_-1]=$t;
}1..$N;
printf sort{$b-$a}map{
	$t=$_;
	map{$i=0;/2/&&($t|=$T[$i]),$i++for$t=~/./g}1..5;
	$_=$t;
	!/3/*y/2//
}glob'{0,2}'x$N;

Measured memory_bytes: 6808
import java.util.*;

class Problem {
  int n;
  long[] a;
  long MAX = 1;
  
  public Problem(int n, long[] a) {
    this.n = n;
    this.a = a;
    for (int i = 0; i < 18; i++) MAX *= 10;
  }

  public void solve() {
    System.out.println(calc());
  }

  public long calc() {
    if (hasAnyZero()) return 0;
    long ans = 1;
    for (int i = 0; i < n; i++) {
      if (MAX / ans < a[i]) return -1;
      ans *= a[i];
    }
    return ans;
  }

  public boolean hasAnyZero() {
    for (int i = 0; i < a.length; i++) if (a[i] == 0) return true;
    return false;
  }
}

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] a = new long[n];
    for (int i = 0; i < n; i++) a[i] = sc.nextLong();
    Problem p = new Problem(n, a);
    p.solve();
  }
}



Measured memory_bytes: 61760
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>
#include <random>

//AtCoderC++.cpp

using namespace std;


#define rep(i,from,to) for(int i=from;i<to;i++)
#define ints(name,n) vector<int> name;name.resize(n)

template<typename T> void Show(vector<vector<T>> v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		for (int j = 0; j < v[i].size(); j++) {
			cout << v[i][j];
			if (j != v[i].size() - 1) {
				cout << delimiter;
			} else {
				cout << endl;
			}
		}
	}
}
template<typename T> void Show(vector<T> v, string delimiter = " ") {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i != v.size() - 1) {
			cout << delimiter;
		} else {
			cout << endl;
		}
	}
}
template<typename T> vector<T> getUniform(T value, int n) {
	vector<vector<T>> ts;
	ts.resize(n);
	for (int i = 0; i < n; i++) {
		ts[i] = value;
	}
	return ts;
}
template<typename T> vector<vector<T>> getUniform(T value, int row, int col) {
	vector<vector<T>> ts;
	ts.resize(row);
	for (int i = 0; i < row; i++) {
		ts[i].resize(col);
		for (int j = 0; j < col; j++) {
			ts[i][j] = value;
		}
	}
	return ts;
}
bool All(vector<vector<bool>> ts) {
	int h = ts.size();
	int w = ts[0].size();
	rep(i, 0, h) {
		rep(j, 0, w) {
			if (!ts[i][j])return false;
		}
	}
	return true;
}

int main() {
	int H, W;
	int row, col;
	cin >> H >> W >> row >> col;
	cout << (H - row)*(W - col) << endl;
}

Measured memory_bytes: 256
def main():
    x = int(input())
    L = 500
    lst = [pow(i, 5) for i in range(-L, L+1)]

    for a in range(2*L + 1)[::-1]:
        for b in range(2*L + 1)[::-1]:
            val = lst[a] - lst[b]
            if val == x:
                ansa = a
                ansb = b
                break
    print(ansa-L, ansb-L)
main()

Measured memory_bytes: 65004
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
 
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>ac(n),pena(n);
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        --p;
        if(ac[p])continue;
        if(s=="AC"){
            ac[p]=1;
        }
        else{
            pena[p]++;
        }
    }
    int AC=0, PENA=0;
    rep(i,n){
        AC+=ac[i];
        if(ac[i])PENA+=pena[i];
    }
    cout<<AC<<" "<<PENA<<endl;

}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
const int MOD=1000000007;
int main(){
    int n; cin >> n;
    long long ans=1;
    for (int i=1;i<=n;i++){
        ans = ans * i % MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define clr(x,i) memset(x,i,sizeof(x))
using namespace std;
const int N=200005,inf=1e6;
inline int read()
{
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1; ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0',ch=getchar();}
    return x*f;
}
int n,m,ans;
int t[N*4],lazy[N*4];
#define L(u) (u<<1)
#define R(u) (u<<1|1)
void pushdown(int u,int l,int r)
{
	int &x = lazy[u], mid = (l+r)>>1;
	if(!x) return;
	t[L(u)] = l-x; t[R(u)] = mid+1-x;
	lazy[L(u)] = lazy[R(u)] = x;
	x = 0;
}
void upd(int u,int l,int r,int st,int ed,int v)
{
	if(st<=l && r<=ed) {
		t[u] = l - v; lazy[u] = v;
		return;
	}
	pushdown(u, l, r);
	int mid=(l+r)>>1;
	if(st<=mid) upd(L(u), l, mid, st, ed, v);
	if(ed>mid) upd(R(u), mid+1, r, st, ed, v);
	t[u] = min(t[L(u)], t[R(u)]);
}
int qry(int u,int l,int r,int p)
{
	if(l==r) { return p - t[u]; }
	pushdown(u, l, r);
	int mid=(l+r)>>1;
	if(p<=mid) return qry(L(u), l, mid, p);
	else return qry(R(u), mid+1, r, p);
}
void solve()
{
	n=read(); m=read(); ans=1e9;
//	build(1, 1, n);
	int maxb = 1;
	for(int i=1; i<=n; i++) {
		int a = read(), b = read();
		if(maxb < a) {
			int v = qry(1, 1, m, a-1);
			upd(1, 1, m, a, b, v);
		}
		else if(a <= maxb && maxb <= b) {
			upd(1, 1, m, maxb, b, -inf);
			maxb = b + 1;
		}
		if(maxb > m) puts("-1");
		else printf("%d\n", i+t[1]);
	}
}
int main()
{
	int T=1;
	while(T--) solve();
}

Measured memory_bytes: 7744
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
 
int arr[222222];
lld ans = 0;
int main(void){
	int n,p;
	scanf("%d%d",&n,&p);
	arr[0] = 1;
	for(int e=1;e<n;e++) arr[e] = (arr[e-1]*10)%p;
	string a;
	cin >> a;
	reverse(a.begin(),a.end());
	if(p==2||p==5){
		lld ans = 0;
		for(int e=(int)a.size()-1;e>=0;e--){
			int diff = (int)a.size() - e;
			if((int)(a[e]-'0')%p==0){
				ans += (lld)diff;
			}	
		}
		printf("%lld",ans);
		return 0;
	}
	int val = 0,num = 0,vis[11111];
	memset(vis,0,sizeof(vis));
	vis[0] = 1;
	for(int q=0;q<n;q++){
		val = (val+((int)(a[q]-'0')*arr[q]))%p;
		ans += vis[val];
		vis[val]++;
 	}
	printf("%lld",ans);
	return 0;
}

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

typedef long long ll;

const ll mod = 1e9+7;

vector<ll> arr;
vector<int> pos;

ll fast_pow(ll a, int b) {
    if(b==1) return a;
    ll half = fast_pow(a, b/2);
    ll ret = half*half%mod;
    if(b%2) ret = ret*a%mod;
    return ret;
}

ll mod_inv(ll a) {
    return fast_pow(a, mod-2);
}

int main () {
    ll N;
    scanf("%lld", &N);
    arr.resize(N+2);
    pos = vector<int> (N+1, 0);
    int l = -1, r = -1;
    for(int i=1;i<=N+1;i++) {
        scanf("%lld", &arr[i]);
        if(pos[arr[i]]) {
            l = pos[arr[i]]-1;
            r = i+1;
        }
        pos[arr[i]] = i;
    }
    ll a = l-1+1, b = N+1-r+1;
    ll ca = (N+1)*N/2%mod, cc = (a+b)%mod;
    
    printf("%lld\n", N);
    for(ll k=2;k<=N;k++) {
        ll ret = ca;
        if(a+b>=k-1) {
            ret = ret+mod-cc;
            ret %= mod;
        }
        printf("%lld\n", ret);
        
        ca *= (N+1-k);
        ca %= mod;
        ca *= mod_inv(k+1);
        ca %= mod;
        
        if(a+b> k-1) {
            cc *= (a+b-(k-1));
            cc %= mod;
            cc *= mod_inv(k);
            cc %= mod;
        }
    }
    printf("1");
    return 0;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll fac[500005],inv[500005];
ll power(ll base,ll n)
{
   ll r=1;
   while(n)
   {
       if(n&1) r=r*base%mod;
       base=base*base%mod;
       n/=2;
   }
   return r;
}
void pre()
{
    fac[0]=1;
    for(int i=1;i<=500000;i++)
    {
        fac[i]=fac[i-1]*i%mod;
    }
    inv[500000]=power(fac[500000],mod-2);
    for(int i=499999;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%mod;
    }
}
ll C(ll m,ll n)
{
    return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;
   cin>>n>>k;
   pre();
   k=min(k,n-1);
   ll ans=0;
   for(int i=0;i<=k;i++)
   {
       ans+=C(i,n)*C(n-i-1,n-1)%mod;
   }
   ans%=mod;
   cout<<ans<<'\n';



}


Measured memory_bytes: 8064
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String S = sc.next();
		int max = 0;
		for (int i = 1; i <= N - 1; i++) {
			Set<Character> xset = new HashSet<>();
			Set<Character> yset = new HashSet<>();
			for (int j = 0; j < N; j++) {
				(j < i ? xset : yset).add(S.charAt(j));
			}
			xset.retainAll(yset);
			max = Integer.max(xset.size(), max);
		}
		System.out.println(max);
	}
}

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

#define int long long
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define str string
#define vint vector<int>
#define vvint vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vool vector<bool>
#define vtr vector<str>
#define vvtr vector<vector<str>>
#define pb() pushback
#define elif else if
#define all(x) x.begin(),x.end()

main(){
    int N,X,b,H=0,W=0,count=0,count2=0;
    double d;
    int C='A'-'a';
    char op;
    str S,T;
    cin>>N>>X;
    vint shizuku(N);
    vint A(2*X);
    rep(0,2*X)cin>>A[i];
    REP(1,N+1){
      rep(0,2*X)if(j==A[i])count+=1;
      cout<<count<<endl;
      count=0;
    }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    char a;
    cin >> a;
    if('A' <= a && a <= 'Z'){
        cout << 'A' << endl;
    }else{
        cout << 'a' << endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod) { a %= _mod; b %= _mod; ll res = 1; switch(op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break; } if (res < 0) res += _mod; return res; }


int main()
{
        ll N;
        cin >> N;
        vll a(N);
        rep(i, 0, N) cin >> a[i];

        ll sm = accumulate(all(a), 0LL);

        ll ans = 0;
        ll mn = inf;
        rep(i, 0, N) {
                ll diff = abs(a[i]*N - sm);
                if (mn > diff) {
                        mn = diff;
                        ans = i;
                }
        }

        cout << ans << endl;
}


Measured memory_bytes: 3636
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


int main(){
    int N,C; cin >> N >> C;
    long long D[31][31]; long long map[501][501];

    for(int i=0; i<C; i++){
        for(int j=0; j<C; j++){
            cin >> D[i][j];
        }       
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cin >> map[i][j];
            map[i][j]--;
        }       
    }

    int cost[3][31];
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            for(int c=0; c<C; c++){
                cost[(i+j)%3][c] += D[map[i][j]][c];
            }
        }       
    }

    int ans = INF_INT;
    for(int i=0; i<C; i++){
        for(int j=0; j<C; j++){

            if(i==j) continue;

            for(int k=0; k<C; k++){

                if(k==i || k==j) continue;

                ans = min(ans, cost[0][i]+cost[1][j]+cost[2][k]);
            }
        }       
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 2304
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        n: usize,
        h: [i32; n],
    }
    if n == 1 {
        println!("Yes");
        return;
    }
    let mut h = h;
    h[0] -= 1;
    for i in 1..(n - 1) {
        if h[i] - h[i - 1] >= 1 { h[i] -= 1; }
    }
    if (0..(n - 1)).all(|i| h[i + 1] >= h[i]) {
        println!("Yes");
    } else { println!("No"); }
}



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

struct Node{
  Node () :
    left (nullptr),
    right (nullptr),
    parent (-1),
    sibling (-1),
    id (0),
    depth (0),
    degree (0),
    height (0)
  {}
  int id;
  int depth;
  int parent;
  int sibling;
  int degree;
  int height;
  Node *right, *left;
  //right ==  && left
};


int FindRoot(Node* nodes, int n){
  for(int i=0; i<n; i++){
    if(nodes[i].parent == -1){
      return i;
    }
  }
  return n-1;
}
void ComputeDepth(Node*nodes, int idx, int depth){
  nodes[idx].depth = depth;
  if( nodes[idx].right != nullptr){
    ComputeDepth(nodes, nodes[idx].right->id, depth+1);
  }
  if( nodes[idx].left != nullptr){
     ComputeDepth(nodes, nodes[idx].left->id, depth+1);
  }
}

void ComputeHeight(Node *nodes, int n, int target, int idx, int height){
  nodes[target].height = std::max(nodes[target].height, height); //input max
  if(nodes[idx].left != nullptr){
    ComputeHeight(nodes, n, target, nodes[idx].left->id, height+1);
  }
  if(nodes[idx].right!= nullptr){
    ComputeHeight(nodes, n, target, nodes[idx].right->id, height+1);
  }
}

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

  Node nodes[n];
  for(int i=0; i<n; i++){
    int id, left, right;
    std::cin >> id >> left >> right;
    nodes[id].id = id;
    if( left != -1 ){
      nodes[id].left = &nodes[left];
      nodes[id].degree++;
      nodes[left].parent = id;
    }
    if( right != -1 ){
      nodes[id].right = &nodes[right];
      nodes[id].degree++;
      nodes[right].parent = id;
    }
    if( left != -1 && right != -1 ){
      nodes[left].sibling = right;
      nodes[right].sibling = left;
    }
  }

  //Get root index.
  int root = FindRoot(nodes, n);

  //Compute depth.
   ComputeDepth(nodes, root, 0);

   //Compute height.
   for(int i=0; i<n; i++){
     ComputeHeight(nodes, n, i, i, 0);
   }

  //output
  for(int i=0; i<n; i++){
    std::cout << "node " << nodes[i].id;
    std::cout << ": parent = " << nodes[i].parent;
    std::cout << ", sibling = " << nodes[i].sibling;
    std::cout << ", degree = " << nodes[i].degree;
    std::cout << ", depth = " << nodes[i].depth;
    std::cout << ", height = " << nodes[i].height << ", ";

    if(nodes[i]. parent == -1){ std::cout << "root" << std::endl; }
    else if( nodes[i].degree != 0 ){ std::cout << "internal node" << std::endl; }
    else { std::cout <<"leaf" << std::endl; }
  }
  return 0;
}



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

using namespace std;
#define int            long long
#define f(i,n)        for(int i=0;i<(n);++i)
#define fa(i,a,n)     for(int i=a;i<=(n);++i)
#define fd(i,a,n)     for(int i=a;i>=(n);--i)
#define tc 			  int t;cin>>t;f(testcase,t)
#define pii             pair<int,int>
void c_p_c() {

	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

}
int func(int b, int n)
{
	if (n < b)
		return n;
	if (n >= b)
		return func(b, n / b) + (n % b);
	return 0;
}

int32_t main() {

	c_p_c();
	int n, s;
	cin >> n >> s;
	if (n == s) {
		cout << n + 1;
		return 0;
	}

	bool flag = 0;
	int min = 100000000001;

	fa(i, 1, sqrt(n)) {

		if (i > 1 and func(i, n) == s)
		{
			if (i < min)
				min = i;
			flag = 1;

		}
	}
	if (n > s) {
		fa(i, 1, sqrt(n - s)) {

			if ((n - s) % i == 0) {
				int x = i + 1;
				if (x > 1 and func(x, n) == s) {
					if (x < min )
						min = x;
					flag = 1;
				}
				x = ((n - s) / i) + 1;
				if (x > 1 and func(x, n) == s) {
					if (x < min)
						min = x;
					flag = 1;
				}
			}
		}
	}



	if (flag)
	{	cout << min;
		return 0;
	}


	if (!flag)
		cout << "-1";


	return 0;
}


Measured memory_bytes: 384
from collections import deque

N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10**9 + 7
A.sort(reverse=True)

ans = 1
B = deque(A)

if K % 2 == 1:
    ans *= B.popleft()

for _ in range(K // 2):
    l = B[0] * B[1]
    r = B[-1] * B[-2]
    if l >= r:
        ans *= B.popleft() * B.popleft()
    else:
        ans *= B.pop() * B.pop()
    if ans > 0: ans %= MOD
    else: ans = (ans % MOD) - MOD

if ans < 0:
    ans = 1
    for a in A[:K]:
        ans *= a
        ans %= MOD

print(ans % MOD)


Measured memory_bytes: 32268
#include<cstdio>
#include<cstring>
#include<iostream>

#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)

using namespace std;

const int maxn=1e5+10;

long long n,c,cnt,ans;
long long x[maxn],v[maxn],le[maxn],ri[maxn];

int main()
{
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&v[i]);
	
	for(int i=1;i<=n;i++)
		cnt+=v[i],le[i]=max(le[i-1],cnt-x[i]),ans=max(ans,le[i]);
	
	cnt=0;
	for(int i=n;i;i--)
		cnt+=v[i],ri[i]=max(ri[i+1],cnt-c+x[i]),ans=max(ans,ri[i]);
	
	cnt=0;
	for(int i=1;i<=n;i++)
	{
		cnt+=v[i];
		ans=max(ans,cnt-x[i]*2+ri[i+1]);
	}
	
	cnt=0;
	for(int i=n;i;i--)
	{
		cnt+=v[i];
		ans=max(ans,cnt-(c-x[i])*2+le[i-1]);
	}
	
	printf("%lld",ans);
	
	return 0;
}

Measured memory_bytes: 3328
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    double w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << (w/2.0)*h << " ";
    if(x==w/2.0 && y==h/2.0)
        cout << 1;
    else
        cout << 0;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100000], b[100000];
int main() {
	
	int A, B, M;
	int x, y, c;
	cin >> A >> B >> M;
	int i;
	int amin = 100001, bmin = 100001, MIN = 200002;
	for (i = 0; i < A; i++) {
		cin >> a[i];
		if (a[i] < amin)amin = a[i];
	}
	
	for (i = 0; i < B; i++) {
		cin >> b[i];
		if (b[i] < bmin)bmin = b[i];
	}

	MIN = amin + bmin;

	for (i = 0; i < M; i++) {
		cin >> x >> y >> c;
		if (a[x - 1] + b[y - 1] - c < MIN)MIN = a[x - 1] + b[y - 1] - c;
	}

	cout << MIN << endl;
	return 0;
	//A
	/*
	string hi;
	cin >> hi;
	int i;
	int flag = 0;
	for (i = 0; i < hi.length(); i++) {
		if (hi[i] == 'h') {
			if (flag == 0) {
				flag = 1;
			}
			else {
				cout << "No\n";
				return 0;
			}
		}else if(hi[i] == 'i'){
			if (flag == 1) {
				flag = 0;
			}
			else {
				cout << "No\n";
				return 0;
			}
		}
		else {
			cout << "No\n";
			return 0;
		}

	}
	if (flag == 1) {
		cout << "No\n";
	}
	else {
		cout << "Yes\n";
	}
	return 0;*/

}

Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    string s;
    cin>>s;
    int e=0,w=0,n=0,so=0;
    rep(i,s.size()){
        if(s[i]=='E')++e;
        else if(s[i]=='W')++w;
        else if(s[i]=='N')++n;
        else ++so;
    }
    bool judge1=false,judge2=false;
    if(e==0&&w==0)judge1=true;
    else if(e>0&&w>0)judge1=true;
    if(n==0&&so==0)judge2=true;
    else if(n>0&&so>0)judge2=true;
    if(judge1&&judge2)cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;

/*
*/

ll n,ans=1e18,sum=0,tmp=0,w[100010];

void init(){
	cin>>n;
	rep(i,n)cin>>w[i];
	rep(i,n)sum+=w[i];
}

int main(void){
	init();
	ans=min(ans,abs(sum-2*tmp));
	rep(i,n){
		tmp+=w[i];
		ans=min(ans,abs(sum-2*tmp));
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE OverloadedStrings #-}
import Data.Char
import Data.List
import Control.Monad
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  [a,b] <- parseLine <$> BS.getLine
  BS.putStrLn . BS.pack . show $ solve a b
  where
     parseLine = unfoldr (BS.readInt . BS.dropWhile isSpace)

solve :: Int -> Int -> Int
solve a b
  | null candidates = -1
  | otherwise = head candidates
  where
    makeCandidates x rate = takeWhile ((==x).floor.(*rate).fromIntegral) [(ceiling ((fromIntegral x)/rate))..]
    candidatesA = makeCandidates a 0.08
    candidatesB = makeCandidates b 0.1
    candidates = intersect candidatesA candidatesB

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

int main() {
    long long x;
    cin >> x;
    long long res = 0;
    res = x / 500 * 1000;
    x -= x / 500 * 500;
    res += x - x % 5;
    cout << res << endl;
    return 0;
}


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


public class D
{	
	public static void Main()
	{
		string[] args;
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);
		
		List<int> A = new List<int>(M);
		args = Console.ReadLine().Split(' ');
		for(int i = 0; i < M; i++)
			A.Add(Int32.Parse(args[i]));
		A.Sort((x,y) => y - x);
		
		int[] num = {-1,2,5,5,4,5,6,3,7,6};
		
		int[] dp = new int[N + 1];		
		dp[0] = 0;		
		for(int i = 1; i <= N; i++)
			dp[i] = -1000000000;
		
		for(int i = 1; i <= N; i++)
		{
			for(int j = 0; j < M; j++)
			{
				if(i < num[A[j]])
					continue;
				dp[i] = Math.Max(dp[i], dp[i - num[A[j]]] + 1);
			}				
		}
		
		StringBuilder sb = new StringBuilder();
		int rest = N;
		for(int i = 0; i < dp[N]; i++)
		{
			for(int j = 0; j < M; j++)
			{
				if(rest < num[A[j]])
					continue;
				if(dp[rest - num[A[j]]] != dp[rest] - 1)
					continue;
				sb.Append(A[j].ToString());
				rest -= num[A[j]];
				break;
			}			
		}
		
		Console.WriteLine(sb);		
	}
}





Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
using namespace std;

int n, m;
vector<string> fi;

int main() {
    cin >> n >> m;
    fi.resize(n);
    for (int i = 0; i < n; ++i) cin >> fi[i];
    vector<bool> tate(n, 0), yoko(n, 0);
    for (int i = 0; i < n; ++i) {
        bool tmp = true;
        for (int j = 0; j < m; ++j) if (fi[i][j] == '#') tmp = false;
        if (tmp) tate[i] = true;
    }
    for (int j = 0; j < m; ++j) {
        bool tmp = true;
        for (int i = 0; i < n; ++i) if (fi[i][j] == '#') tmp = false;
        if (tmp) yoko[j] = true;
    }
    for (int i = 0; i < n; ++i) {
        if (tate[i]) continue;
        for (int j = 0; j < m; ++j) {
            if (yoko[j]) continue;
            cout << fi[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
/*
@author: @sancodemonster
*/
 
#include <bits/stdc++.h>
 
#define flash ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define ll long long int
#define ld long double
#define pb push_back 
#define mp make_pair
#define inf 1e17
#define MOD 1000000007
#define f(i,a,b)  for(long long i=a;i<b;i++)
#define all(c) (c).begin(),(c).end() 
using namespace std;

ll n;
ll h[100005];
ll dp[100005]  = {0};
ll k;

ll rec(ll i,ll n)
{     
	if(i == n)
		return 0;
	if(i>n)
		return inf;

	if(dp[i]!=-1)
           return dp[i];
        
        ll val = INT_MAX;
        
        ll j;

        f(j,1,k+1)
        {
        	if(i<=n-j)
        	{
        	    ll x = rec(i+j,n) + abs(h[i+j] - h[i]);
        	    if(x<val)
        	    	val = x;
        	}

        }
       /* if(i<=n-1)
          one = rec(i+1,n) + abs(h[i+1] - h[i]);
	//ll one = rec(i+1,n,cost+ abs(h[i+1] - h[i]));

        if(i<=n-2)
         two = rec(i+2,n) + abs(h[i+2]- h[i]);
	//ll two = rec(i+2,n,cost+ abs(h[i+2] - h[i]));*/

        
        dp[i] = val;

        return dp[i];

}
int main()
{	
  /*#ifndef ONLINE_JUDGE
    freopen("C:\\desktopp\\new coding problems\\in.txt" , "r" , stdin);
    freopen("C:\\desktopp\\new coding problems\\out.txt" , "w" , stdout);
  #endif
  */
     flash;
     /////////////////////////////////////////////////////////////////////////////////////////////////////
       ll i,j;

       cin>>n>>k;
        f(i,1,n+1)
        {
           cin>>h[i];
        }
        
        f(i,0,1e5)
         dp[i] = -1;
        //if(n>2)
        ll ans = rec(1,n);
        cout<<ans;
     /////////////////////////////////////////////////////////////////////////////////////////////////////

     return 0;
}


Measured memory_bytes: 6528
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    //let n = read::<usize>();
    //let n = read::<u32>();
    let v = read_vec::<i32>();
    let a = v[0];
    let b = v[1];
    if a > b {
        println!("a > b");
    } else if a < b {
        println!("a < b");
    } else {
        println!("a == b");
    }
}



Measured memory_bytes: 5024
s = input()
K = int(input())
len_s = len(s)

result = []

for i in range(len_s):
  for j in range(i+1, i+1+5):
    x = s[i:j]
    result.append(x)

result = sorted(result)
len_r = len(result)

if len_r == 1 or K == 1:
  print(result[0])
  exit()

index = 0
for i in range(1, len_r):
  if result[i] != result[i-1]:
    index += 1
  if index == K-1:
    print(result[i])
    exit()

Measured memory_bytes: 4596
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#define f(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)

int main(){
    string s1,s2,ans="";
    cin>>s1>>s2;
    int n = s1.size();
    int m = s2.size();

    int dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    f(i,1,n){
        f(j,1,m){
            if(s1[i-1]==s2[j-1])
                dp[i][j] = dp[i-1][j-1] + 1;
            else
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]); 
        }
    }
    // int i=n,j=m;

    while(n>0 && m>0){
        if(s1[n-1]==s2[m-1]){
            ans = s1[n-1] + ans;
            n--;
            m--;
        }
        else if(dp[n-1][m]>dp[n][m-1])
            n--;
        else
            m--; 
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 35456
#include <stdio.h>

int main(){
  int i,j,N,cnt=1,A[100],num,v,count;
  scanf("%d",&N);
  while(cnt<N+1){
    scanf("%d",&num);
    if(num < 0 || num >1000)return 0;;
    A[cnt] = num;
    cnt++;
  }
  for(i=1;i<N+1;i++){
    count = 1;
    v = A[i];
    j = i - 1;
    while(j >= 0 && A[j] > v){
      A[j+1] = A[j];
      j--;
      A[j+1] = v;
    }
    while(count < N){
      printf("%d ",A[count]);
      count++;
    }
    printf("%d",A[count]);
    printf("\n");
  }
  return 0;
}



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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    string s; cin >> s;
    queue<char> q;
    rep(i,s.size()-1){
        if(s[i] == 'B' && s[i+1] == 'C'){
            q.push('R');
            i++;
        }
        else q.push(s[i]);
    }
    
    ll res=0;
    ll cnt=0;
    //転倒数
    while (!q.empty())
    {
        char c = q.front();q.pop();
        if(c=='A')cnt++;
        else if(c=='R')res+=cnt;
        else cnt = 0;
    }
    cout << res << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

ll dp[3001][7001];
int prev_w[3001][7001];

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

    set<int> use;

    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= t; ++w) {
            if(w >= a[i]){
                if (dp[i+1][w] < dp[i][w-a[i]] + b[i]) {
                    dp[i+1][w] = dp[i][w-a[i]] + b[i];
                    prev_w[i+1][w] = w - a[i];
                }
            }

            if (dp[i+1][w] < dp[i][w]) {
                dp[i+1][w] = dp[i][w];
                prev_w[i+1][w] = w;
            }
        }
    }

    int cur_w = t-1;
    for (int i = n-1; i >= 0; --i) {

        if (prev_w[i+1][cur_w] == cur_w - a[i]) {
            use.insert(i);
        }
        cur_w = prev_w[i+1][cur_w];
    }

    int add = 0;
    rep(i, n){
        if(use.find(i) == use.end()) chmax(add, b[i]);
    }

    ll ans = dp[n][t];
    chmax(ans, dp[n][t-1]+add);

    cout << ans << endl;
}

Measured memory_bytes: 245504
A = []
memo = [-1] * 101
for i in range(3):
    a, b, c = map(int, input().split())
    memo[a] = memo[b] = memo[c] = i
    A.append([a, b, c])
n = int(input())
b = []
for _ in range(n):
    b.append(int(input()))
b = set(b)
ana = [[0] * 3 for _ in range(3)]
for num in b:
    if memo[num] == -1:
        continue
    ana[memo[num]][A[memo[num]].index(num)] = 1
#斜め
if ana[0][0] == 1 and ana[1][1] == 1 and ana[2][2] == 1:
    print("Yes")
    exit()
if ana[0][2] == 1 and ana[1][1] == 1 and ana[2][0] == 1:
    print("Yes")
    exit()
#横 縦
for i in range(3):
    if ana[i][0] == 1 and ana[i][1] == 1 and ana[i][2] == 1:
        print("Yes")
        exit()
    if ana[0][i] == 1 and ana[1][i] == 1 and ana[2][i] == 1:
        print("Yes")
        exit()
print("No")




Measured memory_bytes: 62180
#include<iostream>
#include<cstdio>
#include<bits/stdc++.h>
using namespace std;
char s[1001],a,b;
int l=0,len=0;
int main()
{
	cin>>s;
	for(int i=0;i<strlen(s);i++)
	{
		l=strlen(s)-2;
		len=strlen(s);
		a=s[0];
		b=s[len-1];
	}
	cout<<a<<l<<b<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
#define N_MAX 200002
const ll MOD = 1000000007;

ll inv[N_MAX],fac[N_MAX],finv[N_MAX];

void init(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<N_MAX;i++){
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        fac[i]=fac[i-1]*(ll) i%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll inv_(ll n){
    if(n == 1) return 1;
    else return MOD-inv_(MOD%n)*(MOD/n)%MOD;
}

ll comb(ll n, ll r){
  ll ans;
  if(n < r){
      ans = 0;
  }else{
      ans = (fac[n]*finv[r])%MOD;
      ans = (ans*finv[n-r])%MOD;
      ans = (ans+MOD)%MOD;
  }
  return ans;
}

ll dp[21][1001];
int N, K;
ll a[1001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    init();
    cin >> N >> K;
    for(int i = 0; i < K; i++) cin >> a[i+1];
    dp[0][0] = 1;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <= N; j++){
            // cout << dp[i][j] << ' ';
            for(int k = j; k <= N; k++){
                int rem = k-j;
                if(rem > a[i+1]) continue;
                
                ll c1 = comb(N-j, rem);
                ll c2 = comb(N-rem, a[i+1]-rem);
                dp[i+1][k] += (((dp[i][j]*c1)%MOD)*c2)%MOD;
                dp[i+1][k] %= MOD;
            }
        }
        // cout << endl;
    }
    cout << dp[K][N] << endl;
}

Measured memory_bytes: 5120
n = list(map(int,input().split()))
counter = 0
while True:
	n = sorted(n)
	if n[2] - n[0] == 1:
		n[0] += 1
		n[1] += 1
		counter += 1
	if n[2] - n[0] > 1:
		n[0] += 2
		counter += 1
	if n[0] == n[1] == n[2]:
		break
print(counter)

Measured memory_bytes: 3064