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

int N, M;
int a[50];
int b[50];

int sum[51][51][51][51];
int dp[2][3][51][51][51][51];

const int INF = 1e9;

int calc(int p, int ai, int an, int bi, int bn) {
	int& s = sum[ai][an][bi][bn];
	if(s != INF) return s;
	s = 0;
	int at = ai - 1, bt = bi - 1;
	p = 1 - p;
	bool ng0 = false, ng1 = false;
	while(at >= ai - an || bt >= bi - bn) {
		if(p == 0) {
			if(a[at] == -1) ng1 = true;
			else if(!ng0) s += a[at];
			at--;
		}
		else {
			if(b[bt] == -1) ng0 = true;
			else if(!ng1) s -= b[bt];
			bt--;
		}
		p = 1 - p;
	}
	return s;
}

int f(int p, int pass, int ai, int an, int bi, int bn, int asum, int bsum) {
	int& d = dp[p][pass][ai][an][bi][bn];
	if(d != INF) return d;
	// pass
	int s = asum - bsum;
	int npass = pass;
	if(an == 0 && bn == 0) npass++;

	if(p == 0) {
		d = -INF;
		if(npass == 2) {
			d = max(d, s);
		}
		else {
			d = max(d, s + f(1 - p, npass, ai, 0, bi, 0, 0, 0));
		}
		// put
		if(ai < N) {
			int nasum = asum, nbsum = bsum;
			if(a[ai] == -1) nbsum = 0;
			else nasum += a[ai];
			d = max(d, f(1 - p, 0, ai + 1, an + 1, bi, bn, nasum, nbsum));
		}
	}
	else {
		d = INF;
		if(npass == 2) {
			d = min(d, s);
		}
		else {
			d = min(d, s + f(1 - p, npass, ai, 0, bi, 0, 0, 0));
		}
		// put
		if(bi < M) {
			int nasum = asum, nbsum = bsum;
			if(b[bi] == -1) nasum = 0;
			else nbsum += b[bi];
			d = min(d, f(1 - p, 0, ai, an, bi + 1, bn + 1, nasum, nbsum));
		}
	}
	return d;
}

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

	while(cin >> N >> M) {
		for(int i = 0; i < N; i++) {
			cin >> a[i];
		}
		for(int i = 0; i < M; i++) {
			cin >> b[i];
		}
		fill((int*)begin(dp), (int*)end(dp), INF);
		fill((int*)begin(sum), (int*)end(sum), INF);
		cout << f(0, 0, 0, 0, 0, 0, 0, 0) << endl;
	}
}

Measured memory_bytes: 188208
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int mod = 1000000007;
int N, M;
LL f[100010], g[100010], base[100010];
char s[100010];
int main(){
	cin>>s + 1;
	N = strlen(s + 1);
	f[1] = 2;g[1] = 1;
	for(int i = 2;i <= N; i++){
		if(s[i] == '0'){
			g[i] += g[i-1] * 3 % mod;
			f[i] += f[i-1];
		}
		else{
			(g[i] += g[i-1] * 3 % mod + f[i-1] ) %= mod;
//			if(g[i] == 0 && )g[i] = 3;
			f[i] += 2 * f[i-1] % mod; 
		}
//		printf("i=%d f=%d g=%d\n", i, f[i], g[i]);
	}
	cout<<(f[N] + g[N]) % mod;
	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>
int z[9999],r[9999];
int f(int a,int b){
	printf("? %d %d\n",a,b);
	fflush(stdout);
	char c[2];
	scanf("%s",c);
	return *c=='Y';
}
int main(){
	int a,b,c=0,h,i=0;
	scanf("%d%d",&a,&b);
	if(a<=b){puts("Impossible");return 0;}
	for(a+=b;i<a;i++)if(!c||f(z[c-1],i))z[c++]=i;else c--;
	h=z[c-1];
	for(i=0;i<a;i++)r[i]=h==i||f(h,i);
	printf("! ");
	for(i=0;i<a;i++)printf("%d",r[i]);
	puts("");
}

Measured memory_bytes: 692
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    ll x; cin >> x;
    ll ans=0, res = x / 500;

    ans += 1000 * res;
    x -= res * 500;

    //cout << "x= " << x << endl;

    ans += 5 * (x / 5); 

    cout << ans << endl;
    

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <algorithm>

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>
 
using namespace std;

const int N=200010;
int n,m,x,y;
int a[N];
int cnt[N];
bool vis[N];
int s[N<<2];

void push(int x) {
    s[x<<1]+=s[x];
    s[(x<<1)+1]+=s[x];
    s[x]=0;
}

void upd(int x,int l,int r,int lq,int rq,int val) {//printf("upd l:%d r:%d lq:%d rq:%d val:%d\n",l,r,lq,rq,val);
    if (lq<=l&&r<=rq) {
        s[x]+=val;
        return;
    }
    if (l>rq||lq>r) return;
    int mid=(l+r)>>1;
    push(x);
    upd(x<<1,l,mid,lq,rq,val);
    upd((x<<1)+1,mid+1,r,lq,rq,val);
}

int query(int x,int l,int r,int p) {//printf("query l:%d r:%d p:%d\n",l,r,p);
    if (l==r) {
        return s[x];
    }
    int mid=(l+r)>>1;
    push(x);
    if (p<=mid) return query(x<<1,l,mid,p);
    else return query((x<<1)+1,mid+1,r,p);
}

int main() {
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++) {
        scanf("%d",a+i);
        cnt[a[i]]++;
    }
    for (int i=1;i<=n;i++) {
        if (cnt[i]>0) {
            upd(1,1,n,max(1,i+1-cnt[i]),i,1);
            for (int j=i+1-cnt[i];j<=i;j++) {
                vis[j]=1;
            }
        }
    }
    int ans=0;
    for (int i=1;i<=n;i++) {
        if (!vis[i]) ans++;
    }
    for (int i=0;i<m;i++) {//printf("i:%d\n",i);
        scanf("%d%d",&x,&y);
        int num=a[x];
        a[x]=y;
        int pos=num+1-cnt[num];
        if (pos>0) {
            if (query(1,1,n,pos)==1) ans++;
            upd(1,1,n,pos,pos,-1);
        }
        cnt[num]--;
        pos=y-cnt[y];//printf("i:%d pos:%d\n",i,pos);
        if (pos>0) {
            int tmp=query(1,1,n,pos);//printf("tmp:%d\n",tmp);
            if (query(1,1,n,pos)==0) ans--;
            upd(1,1,n,pos,pos,1);
        }
        cnt[y]++;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 6400
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
A = LI()

c = collections.Counter(A)


cnt = 0
for _ in c:
    cnt += c[_] * (c[_] - 1) // 2

for i in range(N):
    a = c[A[i]]
    print(cnt - (a - 1))


Measured memory_bytes: 114032
S = input()
North = S.count("N")
South = S.count("S")
East = S.count("E")
West = S.count("W")
if ((North > 0 and South > 0) or (North == 0 and South == 0)) and ((East > 0 and West > 0) or (East == 0 and West == 0)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=1e5+10; 
const int mod=1e9+7;
int n,k,x,y,ans;
int head[N],v[N*2],nex[N*2],cnt;
void link(int x,int y){v[++cnt]=y;nex[cnt]=head[x];head[x]=cnt;}
void dfs(int u,int fa,int d,int bro)
{
	if(!ans)return;//无解 
	int par=(d>2)?2:d,son=0;
	int col=(k-par-bro);
	if(col<0)col=0;
	ans=(1ll*ans*col)%mod;
	if(!ans)return;
	for(int i=head[u];i;i=nex[i])
	{
		int to=v[i];
		if(to==fa)continue;
		dfs(to,u,d+1,son);
		son++;
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	ans=1; 
	for(int i=1;i<n;++i)
	{
		scanf("%d%d",&x,&y);
		link(x,y);link(y,x);
	}
	dfs(1,-1,0,0);
	printf("%d\n",ans);
	return 0;
} 

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int a[5];

int main()
{
    _FastIO;
    cin >> a[0] >> a[1] >> a[2];
    sort(a , a + 3);
    cout << a[0] + a[1] << endl;
    return 0;
}


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

int main() {
  int K, T;
  cin >> K >> T;
  vector<int> a(T);
  for (int i=0; i<T; i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << max((2*a[T-1]-K-1),0) << endl;
}

Measured memory_bytes: 3636
s = input()
for i in range(8):
    fom_lst = []
    for j in range(3):
        if (i >> j) & 1:
            fom_lst.append('+')
        else:
            fom_lst.append('-')
        S = ''
    for num, fom in zip(s, fom_lst):
        S += num + fom
    S += s[-1]
    if eval(S) == 7:
        print(S + '=7')
        break

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(shoki,i,n) for(int i=shoki; i<n; i++)
#define _GLIBCXX_DEBUG
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vector<int>>;

int main(){
    ll N,A,B; cin>>N>>A>>B;
    ll mod = N%(A+B);
    ll divide = N/(A+B);
    ll ans;
    if(mod >= A){
        ans = A * (divide+1);
    }else if(mod < A){
        ans = A * divide + mod;
    }

    cout << ans << endl;
}


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

int n;

vi Wafrelka(vi a){
	int t=0;
	priority_queue<int,vi,greater<int>> pq;
	vi res;
	REP(i,3*n){
		t+=a[i];
		pq.push(a[i]);
		if(int(pq.size())>n){
			int v=pq.top();pq.pop();
			t-=v;
		}
		res.PB(t);
	}
	return res;
}

signed main(){
	n=read();
	vi a,b;
	REP(i,3*n){
		int x=read();
		a.PB(x);
		b.PB(-x);
	}
	reverse(ALL(b));
	vi x=Wafrelka(a),y=Wafrelka(b);
	int ans=-inf;
	FOR(i,n-1,2*n)chmax(ans,x[i]+y[3*n-(i+1)-1]);
	cout<<ans<<endl;
}

Measured memory_bytes: 22756
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
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")
    };
}

//

fn run() {
    input! {
        n: usize,
        a: [u64; n],
    }
    let mut s = a.clone();
    s.push(0);
    for i in (0..n).rev() {
        s[i] += s[i + 1];
    }
    let mut dp = vec![vec![0; n + 1]; n + 1];
    for l in (0..n).rev() {
        for r in (l + 1)..(n + 1) {
            if r - l == 1 {
                continue;
            }
            let mut val = std::u64::MAX;
            for k in (l + 1)..r {
                val = std::cmp::min(val, dp[l][k] + dp[k][r]);
            }
            dp[l][r] = val + s[l] - s[r];
        }
    }
    let ans = dp[0][n];
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;
typedef pair<string, int> P;

bool comp(P lhs, P rhs){
  return lhs.second > rhs.second;
}
int main()
{
  int N;
  string S[210000];
  int res=0;
  cin >> N;
  rep(i,N) cin >> S[i];
  sort(S,S+N);

  vector<P> v;
  string prev=S[0];
  int cnt=1;
  FOR(i,1,N-1){
    if(prev==S[i]) {
      cnt++;
    }
    else {
      v.push_back(make_pair(prev, cnt));
      cnt = 1;
    }
    prev = S[i];
  }
  v.push_back(make_pair(prev, cnt));
  sort(v.begin(), v.end(), comp);
  vector<string> w;
  int  n = v[0].second;
  w.push_back(v[0].first);
  FOR(i,1,v.size()-1){
    if (n==v[i].second) w.push_back(v[i].first);
    else break;
  }
  sort(w.begin(),w.end());
  for(auto it:w){
    cout << it << endl;
  }
  return 0;
}


Measured memory_bytes: 21360
/*
    author  : real_rpg  
    country : India
    time    : 00:51:12 IST
*/
 
#include "bits/stdc++.h" 
#define ll long long
#define ld long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define fld(i,a,b,c) for(ld i=a; i<b; i+=c)
#define fl(i,a,b,c) for(ll i=a; i<b; i+=c)
#define rfl(i,a,b,c) for(ll i=a; i>=b; i-=c) 
#define endt (double)(clock() - tStart)/CLOCKS_PER_SEC
#define rep(i,n) fl(i,0,n,1)
#define rrep(i,n) rfl(i,n-1,0,1)
#define sas int tt; cin >> tt; rep(tc,tt) 
#define pb  push_back
#define ep emplace_back
#define F first
#define S second
using namespace std; 
const int md = 1e9 + 7;
const int MAX = 1e5 + 5;
const int MAXN = 1e6 + 5;

void solve() {  
	ll x1,x2,y1,y2;
	cin>>x1>>y1>>x2>>y2;
	ll dx=x2-x1;
	ll dy=y2-y1;
	cout<<x2-dy<<" "<<y2+dx<<" "<<x1-dy<<" "<<y1+dx;


}

int main() {             
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); cout.tie(NULL); 
    //clock_t tStart = clock(); 
    solve(); 
    //printf("\n%.6f\n", endt);
    return 0; 
}

Measured memory_bytes: 256
using System.Linq;using c=System.Console;class P{static void Main(){var a=new string[]{}.ToList();int n=int.Parse(c.ReadLine()),i;foreach(var e in"SHCD")for(i=1;i<14;a.Add($"{e} {i++}"));for(i=0;i++<n;a.Remove(c.ReadLine()));if(a.Count!=0)c.WriteLine(string.Join("\n",a));}}


Measured memory_bytes: 18156
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;

int main(){
    int n; cin >> n;
    
    vector<long long int> nums(n);
    for(auto &val : nums) cin >> val;
    
    auto begin = nums.begin();
    auto end = nums.end();
    
    cout << *(min_element(begin, end)) << " " << *(max_element(begin, end))
        << " " << accumulate(begin, end, (long long int)0) << endl;
    
    return 0;
}

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

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

  if (t * s >= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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


int main() {
  
  int n ;
  cin >> n ;
  
  vector<int>vec(n);
  for(int i=0;i<n;i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int sum=0;
  for(int i=0;i<n-1;i++){
    sum+=vec.at(i);
  }
  
  sum+=vec.at(n-1)/2;
  
  cout << sum << endl;
}
    

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
 
 
int main(int argc, char* argv[])
{
    int n,a,b;
    scanf("%d%d%d", &n, &a, &b);

    printf("%d %d\n", MIN(a,b), MAX(0,a+b-n));

    return 0;
}

Measured memory_bytes: 128
N=int(input())
abc_list=[]
for i in range(N) :
  k=input().split()
  abc_list.append([int(i) for i in k])
n_list=  [[0 for i in range(3)] for j in range(N)]

n_list[0]=abc_list[0]
for i in range(1,N) :
  n_list[i][0]=max(n_list[i-1][1],n_list[i-1][2])+abc_list[i][0]
  
  n_list[i][1]=max(n_list[i-1][0],n_list[i-1][2])+abc_list[i][1]
  
  n_list[i][2]=max(n_list[i-1][0],n_list[i-1][1])+abc_list[i][2]
  

print(max(n_list[-1]))

Measured memory_bytes: 76632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

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

    int N; cin >> N; 
    vei rev(N);
    rep(i,N) {
        int p; cin >> p; p--;
        rev[p] = i;
    }

    int cnt = 1; int ans = 1;
    rep1(i,N){
        if(rev[i-1] < rev[i]) cnt++;
        else cnt = 1;
        ans = max(ans, cnt);
    }
    cout << N - ans << endl;
    return 0;
}



Measured memory_bytes: 1024
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using LayoutKind = System.Runtime.InteropServices.LayoutKind;
using StructLayoutAttribute = System.Runtime.InteropServices.StructLayoutAttribute;
using FieldOffsetAttribute = System.Runtime.InteropServices.FieldOffsetAttribute;


static class P
{
    static void Main()
    {
        var abcdef = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var a = abcdef[0] * 100;
        var b = abcdef[1] * 100;
        var c = abcdef[2];
        var d = abcdef[3];
        var e = abcdef[4];
        var f = abcdef[5];
        List<int> possibleSugarWeights = new List<int>();
        for (int i = 0; c * i <= f; i++)
            for (int j = 0; c * i + d * j <= f; j++)
                possibleSugarWeights.Add(c * i + d * j);
        possibleSugarWeights = possibleSugarWeights.Distinct().OrderBy(x => x).ToList();

        double maxDense = -1;
        Tuple<int, int> maxStatus = new Tuple<int, int>(-1, -1);
        for (int i = 0; a * i <= f; i++)
        {
            for (int j = 0; a * i + b * j <= f; j++)
            {
                var waterWeight = a * i + b * j;
                var maxSugar = Min(f - waterWeight, waterWeight * e / 100);
                var sugarInd = possibleSugarWeights.BinarySearch(maxSugar);
                if (sugarInd < 0) sugarInd = (~sugarInd) - 1;
                if (sugarInd < 0) continue;
                var sugarWeight = possibleSugarWeights[sugarInd];
                var sugarWaterWeight = sugarWeight + waterWeight;
                var dense = (double)sugarWeight / sugarWaterWeight;
                if (dense > maxDense)
                {
                    maxDense = dense;
                    maxStatus = new Tuple<int, int>(sugarWaterWeight, sugarWeight);
                }
            }
        }
        Console.WriteLine($"{maxStatus.Item1}\n{maxStatus.Item2}");
    }
}


Measured memory_bytes: 14176
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  long long K,A,B;
  long long bis=1;
  cin>>K>>A>>B;
  if(B-A<=2 || K+1<=A){
    cout<<1+K<<"\n";
  }
  else{
    //Aまいのビスケットがないと始まらない
    if(A>1){
    K-=(A-1);
    }
    //この時点でAまいのビスケット、0円を所持
    bis=A;
    //A矢印Bは２回で人セットなので、Kが奇数なら1回叩く
    if(K%2==1){
      K-=1;
      bis+=1;
    }
    bis+=(K/2)*(B-A);
    cout<<bis;
  }
return 0;
}


Measured memory_bytes: 256
# 754~
# 解法 801
# ソートO(10*log10)して，連想配列のkeyにソートされた文字列，valueにその文字列の出現回数 O(N)
import math
N = int(input())
S=[]
for _ in range(N):
    S.append(input())

dic = {}
for s in S:
    s = list(s)
    s.sort()
    s = ''.join(s)
    if not s in dic:
        dic[s] = 1
        continue
    dic[s] += 1

ans = 0
for v in dic.values():
    if v >= 2:
        ans += int(v*(v-1)/2)
print(ans)



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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const int INF=1e9;
const int MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define ALL(v) v.begin(), v.end()
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbgmap(mp) for (auto i = mp.begin(); i != mp.end(); ++i) { cout << i->first <<":"<<i->second << endl;}
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<" ";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin>>n>>x;
//    ll a[n];
//    for(ll i=0; i<n; i++) {
//       cin>>a[i];
//    }
    ll coordinate = 0;
    ll cnt = 1;
    ll a;

    for(ll i=0; i < n; i++) {
        cin>>a;
        coordinate = coordinate + a;
        if (coordinate>x){
            break;
        }
        cnt++;
    }

    cout<<cnt<<endl;
    return  0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define ITR(c,it)  for(auto it = c.begin(); it != c.end(); it++)

typedef long long ll;

const int N_MAX = 50;

int N, K;
int x[N_MAX];
int y[N_MAX];

int H, W;
ll rx[N_MAX];
ll ry[N_MAX];
int acc[N_MAX + 1][N_MAX + 1];

void compress(int *z, ll *rz, int *n) {
  map<int, int> mp;
  REP(i, N) mp[z[i]] = 1;
  int k = 0;
  ITR(mp, it) {
    it->second = k;
    rz[k] = it->first;
    k++;
  }
  REP(i, N) z[i] = mp[z[i]];
  *n = mp.size();
}

void solve() {
  compress(x, rx, &W);
  compress(y, ry, &H);
  REP(i, N) acc[y[i] + 1][x[i] + 1] = 1;
  REP(i, H + 1) REP(j, W) acc[i][j + 1] += acc[i][j];
  REP(i, H) REP(j, W + 1) acc[i + 1][j] += acc[i][j];
  ll ans = 4e18;
  FOR(i2, 1, H) REP(i1, i2) FOR(j2, 1, W) REP(j1, j2) {
    int cnt = acc[i2][j2] - acc[i2][j1] - acc[i1][j2] + acc[i1][j1];
    if (cnt >= K) {
      ll dx = max(1LL, rx[j2 - 1] - rx[j1]);
      ll dy = max(1LL, ry[i2 - 1] - ry[i1]);
      ans = min(ans, dx * dy);
    }
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%d", &N, &K);
  REP(i, N) scanf("%d%d", x + i, y + i);
}

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int N, K, S;
	cin >> N >> K >> S;

	int T = 1000 * 1000 * 1000;
	if (S == T) {
		--T;
	}

	for (int i = 0; i < K; ++i) {
		cout << S << " ";
	}
	for (int i = K; i < N; ++i) {
		cout << T << " ";
	}
	cout << endl;
}


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

struct state {
  ll v, r, cost;
  bool operator>(const state s) const { return cost > s.cost; }
};

int main(void) {
  ll W, H, N;
  cin >> W >> H >> N;
  vector<ll> X(N), Y(N);
  REP(i, 0, N) cin >> X[i] >> Y[i];

  const ll INF = 1LL << 60;
  vector<vector<ll> > dp(N, vector<ll>(1000, INF));
  priority_queue<state, vector<state>, greater<state> > q;
  REP(i, 0, N) {
    ll dist = (X[i] - 1) + (Y[i] - 1);
    q.push((state) { i, dist, dist });
  }
  ll ans = INF;
  while(!q.empty()) {
    ll v = q.top().v, r = q.top().r, cost = q.top().cost;
    // cout << v << " " << r << " " << cost << endl;
    q.pop();
    if(dp[v][r] <= cost) continue;
    dp[v][r] = cost;
    ans = min(ans, cost + max((W - X[v]) + (H - Y[v]) - r, 0LL));
    REP(nv, 0, N) if(nv != v) {
      ll dist = abs(X[nv] - X[v]) + abs(Y[nv] - Y[v]);
      ll nr = max(dist - r - 1, 0LL), ncost = cost + max(dist - r - 1, 0LL);
      if(dp[nv][nr] > ncost) q.push((state) { nv, nr, ncost });
    }
  }
  cout << ans << endl;
}



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

vector<int> Solve(const vector<tuple<int, int, int>> &x) {
    int sum = 0;
    for (int i = 0; i < x.size(); ++i) sum += get<2>(x[i]) * get<1>(x[i]);
    constexpr int kInf = 1'010'000'000;
    vector<int> dp(sum + 1, kInf);
    dp[0] = 0;
    for (auto k : x) {
        int vl, sz, cs;
        tie(vl, sz, cs) = k;
        vector<int> nxt(sum + 1, kInf);
        for (int i = 0; i <= sum; ++i) {
            if (dp[i] == kInf) continue;
            for (int j = 0; j <= cs && i + j * sz <= sum; ++j) {
                if (dp[i] + 1LL * j * vl > kInf) continue;
                nxt[i + j * sz] = min(nxt[i + j * sz], dp[i] + j * vl);
            }
        }
        dp = nxt;
    }
    return dp;
}

int main() {
    int n, x, d; scanf("%d%d%d", &n, &x, &d);
    d = min(d, x);
    vector<int> m(n), p(n, -1), sz(n, 0);
    vector<long long> sum(n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &m[i]);
        if (i > 0) scanf("%d", &p[i]), p[i]--;
    }
    for (int i = 0; i < n; ++i) {
        sum[i] = m[i];
        sz[i] = 1;
    }
    for (int i = n - 1; i > 0; --i) {
        sum[p[i]] += sum[i];
        sz[p[i]] += sz[i];
    }
    for (int i = 0; i < n; ++i) assert(sz[i] <= n);
    vector<tuple<int, int, int>> v;
    for (int i = 0; i < n; ++i) {
        if (sum[i] > x) continue;
        if (i == 0) v.emplace_back(sum[i], n, x);
        else v.emplace_back(sum[i], sz[i], d);
    }
    vector<tuple<int, int, int>> a, b;
    for (int i = 0; i < v.size(); ++i) {
        if (get<2>(v[i]) <= n + n) {
            a.push_back(v[i]);
        } else {
            a.emplace_back(get<0>(v[i]), get<1>(v[i]), n + n);
            b.emplace_back(get<0>(v[i]), get<1>(v[i]), get<2>(v[i]) - n - n);
        }
    }
    auto dp = Solve(a);
    sort(b.begin(), b.end(), [&](auto i, auto j) {
        return 1LL * get<0>(i) * get<1>(j) < 1LL * get<0>(j) * get<1>(i);
    });

    int ans = 0;
    for (int i = 0; i < dp.size(); ++i) {
        if (dp[i] > x) continue;
        // printf("dp[%d] = %d\n", i, dp[i]);
        int c = i, e = dp[i];
        for (int j = 0; e < x && j < b.size(); ++j) {
            int g = min(get<2>(b[j]), (x - e) / get<0>(b[j]));
            c += get<1>(b[j]) * g;
            e += get<0>(b[j]) * g;
        }
        assert(e <= x);
        ans = max(ans, c);
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1292
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

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

double ex[200005];
double sum[200005];
int main(){
    int N, K;
    cin >> N >> K;
    for(int i = 1; i <= N; i++){
        double p;
        cin >> p;
        ex[i] = (p+1)/2.0;
        sum[i] = sum[i-1] + ex[i];
    }
    double ans = 0.0;
    for(int i = 0; i <= N-K; i++){
        ans = max(ans, sum[i+K]-sum[i]);
    }
    printf("%f", ans);
}


Measured memory_bytes: 3328
/*
AuThOr GaRyMr
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int n;
int strangefact[1000000+20];
bool c(int A,int B){
	return !bool((strangefact[A]-strangefact[B]-strangefact[A-B])>0);
}
int main(){
	fastio;
	cin>>n;
	vector<int> a(n);
	rb(i,1,n){
		strangefact[i]=strangefact[i-1];
		int tmp=i;
		while(tmp%2==0){
			strangefact[i]++;
			tmp/=2;
		} 
	}
	rep(i,n){
		char num;
		cin>>num;
		a[i]=num-'0';
	}
	vector<int> vv(n-1);
	rep(i,n-1)
		vv[i]=abs(a[i]-a[i+1]);
	a=vv;
	n--;
	vector<int> b(n);
	rep(i,n){
		b[i]=a[i]%2;
	}
	bool sum=0;
	rep(i,n){
		sum^=b[i]*c(n-1,i);
	} 
	if(sum){
		cout<<1<<endl;
	}
	else{
		int ok=1;
		rep(i,n){
			if(a[i]==1){
				ok=0;
			}
		}
		if(ok){
			rep(i,n){
				a[i]/=2;
				b[i]=a[i]%2;
			}
			sum=0;
			rep(i,n){
				sum^=b[i]*c(n-1,i);
			} 
			if(sum){
				cout<<2<<endl;
			}
			else{
				cout<<0<<endl;
			}
			
		}
		else{
			cout<<0<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 15872
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

int gcd(int a, int b)
{
  if (a < b) {
    return gcd(b, a);
  } else if (b == 0) {
    return a;
  } else {
    return gcd(b, a % b);
  }
}

int main()
{
  int n, x, tmp;
  cin >> n >> x;
  vector<int> xi, diff;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    xi.push_back(tmp);
    diff.push_back(abs(xi[i] - x));
  }

  if (n == 1) {
    cout << diff[0] << endl;
  } else {
    int tmp_gcd = gcd(diff[0], diff[1]);
    for (int i = 2; i < n; i++) {
      tmp_gcd = gcd(tmp_gcd, diff[i]);
    }
    cout << tmp_gcd << endl;
  }
  return 0;
}


Measured memory_bytes: 1276
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int main(){
    int n;
    int stack[10] = {0};
    int index = 0;
    while(cin >> n){
        switch(n){
            case 0 : {
                index--;
                cout << stack[index] << endl;
                break;
            }
            default : {
                stack[index] = n;
                index++;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>
#include <cstring>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;

#define double long double
double EPS = 1e-12;


double g(double x,double A,double B,double C){

	return A*x*x+B*x+C;
}
double f(double x,double A,double B){
	double t = 2*A*x+B;
	return sqrt(1+t*t);
	//return 0.5*(t*sqrt(t*t+1)+log(abs(t+sqrt(1+t*t))))/(2.*A);
}
double integral(double a,double b,double A,double B){
	double S = 500;
	double d = (b-a) / S;
	double ans = 0;
	for(int i = 0 ; i <= S ; i++){
		double x = a + d * i;
		if( i == 0 || i == S ) ans += f(x,A,B);
		else if( i % 2 == 0 ) ans += 2*f(x,A,B);
		else ans += 4 * f(x,A,B);
		
	}
	return ans * d / 3.0;
	return f(b,A,B) - f(a,A,B);
}
vector<double> cp;
void crosspoint(double a,double b,double c){
	if( fabs(a) < EPS ){ cp.push_back(-c/b); return; }
	if( b*b-4*a*c < EPS ) return;
	cp.push_back((-b-sqrt(b*b-4*a*c))/(2*a));
	cp.push_back((-b+sqrt(b*b-4*a*c))/(2*a));
}
double A[100] = {} , P[100] = {} , Q[100] = {};
double B[100] , C[100] = {};
int main(){
	double W,H;
	int N;
	cin >> W >> H >> N;
	for(int i = 0; i < N; i++){
		cin >> A[i] >> P[i] >> Q[i];
		B[i] = -2.0*P[i]*A[i];
		C[i] = A[i] * P[i] * P[i] + Q[i];
		
	}
	for(int i = 0 ; i < N ; i++){
		crosspoint(A[i],B[i],C[i]);
	}
	
	for(int i = 0 ; i < N ; i++)
		for(int j = i+1 ; j < N ; j++)
			crosspoint(A[i]-A[j],B[i]-B[j],C[i]-C[j]);
	cp.push_back(0);
	cp.push_back(W);
	sort(cp.begin(),cp.end());
	double previous_x = 0;
	double ans = 0;
	for(int i = 0 ; i < cp.size() ; i++){
		if( cp[i] < -EPS || cp[i] > W + EPS) continue;
		double height = 0;
		int idx = -1;
		double a = previous_x;
		double b = cp[i];
		for(int j = 0 ; j < N ; j++){
			if( g(a+(b-a)*0.1,A[j],B[j],C[j]) > height + EPS ){
				idx = j;
				height = g(a+(b-a)*0.1,A[j],B[j],C[j]);
			}
		}
		if( idx >= 0 ){
			//cout <<  integral(a,b,A[idx],B[idx]) << endl;
			ans += integral(a,b,A[idx],B[idx]);
		}
		previous_x = cp[i];
	}
	printf("%.15Lf\n",ans);
}

Measured memory_bytes: 1380
h,w=map(int,input().split())
l=[list(map(int,input().split())) for i in range(10)]
a=[list(map(int,input().split())) for i in range(h)]
for i in range(10):
  for j in range(10):
    for k in range(10):
      l[j][k]=min(l[j][k],l[j][i]+l[i][k])
ansL=[l[i][1] for i in range(10)]

ct=0
for i in range(h):
  for j in range(w):
    if a[i][j]>=0:
      ct+=ansL[a[i][j]]
print(ct)

Measured memory_bytes: 3444
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<string>
#include<complex>
#include<algorithm>
#include<vector>
#include<math.h>
#include<set>
#include<map>

int main()
{
	int n, k, a, one_i, count{};
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a);
		if (a == 1)
			one_i = i;
	}
	count = (one_i + k - 2) / (k - 1);
	count += (n - count * (k - 1) + k - 3) / (k - 1);
	printf("%d\n", count);
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep( i, a, b ) for( int i = (a); i <= (b); ++i )
#define dep( i, a, b ) for( int i = (a); i >= (b); --i )
using namespace std;
typedef long long ll;
const int N = 1e6+9, INF = 0x3f3f3f3f;
int n, m, dt[29], num;

bool cxk( int i, int sum ) {
    if( sum == 0 ) return true;
    if( i == n ) return false;
    return cxk( i + 1, sum ) || cxk( i + 1, sum - dt[i] );
}

int main( void ) {
    ios::sync_with_stdio( false );
    cin >> n;
    for( int i = 0; i < n; ++i ) cin >> dt[i];
    cin >> m;
    for( int i = 0; i < m; ++i ) {
        cin >> num;
        cout << ( cxk( 0, num ) ? "yes" : "no" ) << '\n';
    }
    return 0;
}


Measured memory_bytes: 3216
/*

Coded and Decoded by : Yash Kapoor

*/
#include <bits/stdc++.h>
using namespace std;

#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define dl          '\n'
//#define why         (ll)1000000007
#define why         (ll)998244353
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod)
{
    ll result=1;
    while(power)
    {
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}

ll inverse(ll base,ll mod)
{
    return fast_power(base,mod-2,mod);
}

ll solve(){ 
    ll n; cin>>n;
    ll ans = n*(n+1)/2;
    ll th = n/3;
    ll fi = n/5;
    ll t = n/15;
    ans -= ((th)*(6 + 3*(th-1)))/2;
    ans -= ((fi)*(10 + 5*(fi-1)))/2;
    ans += ((t)*(30 + 15*(t-1)))/2;
    cout<<ans;
  return 0;
}  

int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
//#define ll long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;

using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200) cout << s;
    else cout << "red";
}


Measured memory_bytes: 256
import java.util.Scanner;
        
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int k = sc.nextInt();
        String s = sc.next();
        int sx = s.length();

        if (k >= sx) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }
}

Measured memory_bytes: 38640
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>
#define		fast			ios::sync_with_stdio(false);cin.tie(0);cout.tie(NULL);
#define		rep(i,n)		for(int i = 1; i<=n; i++)
#define		all(p)			p.begin(),p.end()
#define		mem(ar,val)		memset(ar, val, sizeof(ar))
#define		sz(c)			(int)c.size()
#define		pb(x)			push_back(x)
#define		mkp(x,y)		make_pair(x,y)
#define 	deb			cout<<"hehehe\n"
#define		ff			first
#define		ss			second
#define 	pf 			printf
#define 	sf 			scanf
#define		ll			long long
#define		pii			pair<int, int>
#define 	pll			pair<ll, ll>
#define 	vll			vector<long long>
#define 	vi			vector<int>
#define		nl			"\n"
#define		pnl			printf("\n");
#define		S(a)			scanf("%lld",&a)
#define		SS(a,b)			scanf("%lld %lld",&a,&b)
#define		SSS(a,b,c)			scanf("%lld %lld %lld",&a,&b,&c)
#define		P(a)			printf("%lld\n",a)
#define		PP(a,b)			printf("%lld %lld\n",a,b)
#define 	total_bit(a)		__builtin_popcount(a)
#define 	UNIQUE(a)		sort(all(a)); a.erase(unique(all(a)), a.end())
#define		FI			freopen("input.txt", "r", stdin);
#define 	FO			freopen("output.txt", "w", stdout);
using namespace std;
const double pi = acos(-1.0);
const int INF = 0x7f7f7f7f;
const int M = 1e9 + 7;
const int N = 1e6+7;
void solve()
{
	ll n;
	S(n);
	string s = "";
	while(n>0)
	{
		ll r = n%26;
		if(r == 0)
		{
			s += 'z';
			n = n/26 - 1; 
		}
		else
		{
			s += (r - 1) + 'a';
			n /= 26; 
		}
	}
	reverse(s.begin(),s.end());
	cout<<s<<nl;
}
int main()
{
	solve();
	return 0;
}


Measured memory_bytes: 3664
#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>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define in(x, a, b) a <= x && x < b
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
//const ll mod = 1000000009;
const double 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 };




class WeightedUF {
public:
  vi par, ran, num;
  vl diff_weight; //親ノード(根ノードではない)との値の差分
  
  WeightedUF(int n) {
    par.resize(n); ran.resize(n);
    num.resize(n); diff_weight.resize(n);
    for (int i = 0; i < n; i++) {
      par[i] = i; ran[i] = 0;
      num[i] = 1; diff_weight[i] = 0;
    }
  }

  //木の根を求める
  int find(int x) {
    if (par[x] == x) {
      return x;
    }
    else {
      int root = find(par[x]);
      diff_weight[x] += diff_weight[par[x]];
      return par[x] = root;
    }
  }

  ll weight(int x) {
    find(x); //経路圧縮
    return diff_weight[x];
  }

  //xからみたyの重み
  ll diff(int x, int y) {
    if (!same(x, y)) {
      return -INF;
    }
    else {
      return weight(y) - weight(x);
    }
  }
  
  //xからみたyの重みがwになるように併合
  bool unite(int x, int y, ll w) {
    w += weight(x); w -= weight(y);
    x = find(x); y = find(y);
    int numsum = num[x] + num[y];
    if (x == y) {
      if (diff(x, y) == w) {
	return true;
      }
      else {
	return false;
      }
    }
    if (ran[x]<ran[y]) {
      swap(x, y);
      w = -w;
    }
    par[y] = x;
    if (ran[x] == ran[y]) {
	ran[x]++;
    }
    diff_weight[y] = w;
    num[x] = num[y] = numsum;
    return true;
  }

  //xとyが同じ集合に属するか否か
  bool same(int x, int y) {
    return find(x) == find(y);
  }

};


int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) {
      return 0;
    }
    WeightedUF uf(n);
    rep (i, m) {
      char c;
      cin >> c;
      if (c == '!') {
	int l, r, d;
	cin >> l >> r >> d;
	l--; r--;
	assert(uf.unite(l, r, d));
      }
      else {
	int l, r;
	cin >> l >> r;
	l--; r--;
	ll res = uf.diff(l, r);
	if (res == -INF) {
	  cout << "UNKNOWN" << endl;
	}
	else {
	  cout << res << endl;
	}
      }
    }
  }
}



Measured memory_bytes: 4744
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type_a,class Type_b> void chmax(Type_a &a,const Type_b &b){if(a<b)a=b;}
template<class Type_a,class Type_b> void chmin(Type_a &a,const Type_b &b){if(a>b)a=b;}
template<class Type> Type igcd(Type x,Type y){if(x==0||y==0)return (x>y)?x:y;return (y%x)?igcd(y%x,x):x;}
template<class Type> Type ilcm(Type x,Type y){return x/igcd(x,y)*y;}
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

template<class Type,class Type_k>
Type nCk(Type n,Type_k k){//nCk.
	if(n<k) return 0;
	if(n<0 or k<0) return 0;
	Type res=1;
	for(Type i=0;i<k;++i) res*=n-i, res/=i+1;
	return res;
}

llong f(string s,int k){
	if(s.size()<k) return 0;//前提.
	
	llong res=0;
	
	if(k==1){//再帰の終了条件.
		res+=9*(s.size()-1);
		res+=s[0]-'0';
		return res;
	}
	
	res+=nCk(s.size()-1,k)*pow(9,k);//sの桁未満の場合の数.
	res+=(s[0]-'0'-1)*(nCk(s.size()-1,k-1)*pow(9,k-1));//最大の位が選ばれた場合(ただし,最大値は考慮しない).
	
	int p;
	for(p=1;p<s.size();++p){
		if(s[p]=='0'){}
		else break;
	}
	string t=s.substr(p,s.size()-p);
	res+=f(t,k-1);//最大の位の最大値の場合.
	
	return res;
}

int main(){
	string s;
	int k;
	cin>>s>>k;
	
	cout<<f(s,k)<<endl;
}

Measured memory_bytes: 384
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces1038D
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
ll gcd(ll a, ll b){ return b?gcd(b, a % b):a; }
ll lcm(ll a, ll b){ return (a*b)/gcd(a, b); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }
ll n, q; 
vector<ll> g[222222];
ll c[222222];
bool vis[222222];
void dfs(int v, ll x) {
	if (vis[v]) return;
	vis[v] = true;
	c[v] += x;
	for (ll e : g[v]) {
		dfs(e, c[v]);
	}
}

int main(){
	FASTIO;
	cin >> n >> q;
	ll x, y;
	for ( int k = 0; k < n - 1; k++ ){
		cin >> x >> y;
		g[x].pb(y);
		g[y].pb(x);
	}
	for ( int k = 0; k < q; k++ ){
		cin >> x >> y;
		c[x] += y;
	}
	dfs(1, 0);
	for ( int k = 1; k <= n; k++ ) cout << c[k] << " "; cout << endl;
	return 0;
}

Measured memory_bytes: 21888
N,Y=map(int,input().split())

x=-1
y=-1
z=-1
for a in range(N+1):
    for b in range(N+1):
        c=N-a-b
        if c<0:
            continue
        if Y==(10000*a+5000*b+1000*c):
            x=a
            y=b
            z=c
print(x,y,z)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;


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

	int n,k; cin >> n >> k;

	int x[n],y[n];
	int sx[n],sy[n];
	for(int i=0;i<n;i++){
		cin >> x[i] >> y[i];
		sx[i] = x[i];
		sy[i] = y[i];
	}
	sort(sx,sx+n); sort(sy,sy+n);

	long long ans=9e18;
	int num;
	for(int l=0;l<n-1;l++){
		for(int r=l+1;r<n;r++){
			for(int b=0;b<n-1;b++){
				for(int u=b+1;u<n;u++){
					num = 0;	
					for(int i=0;i<n;i++){
						if(sx[l] <= x[i] && x[i] <= sx[r] && 
								sy[b] <= y[i] && y[i] <= sy[u]) num++;
					}
					if(num >= k) ans = min(ans,1LL*(sx[r]-sx[l])*(sy[u]-sy[b]));
				}
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256