akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
long long int dp[3001][3001];
long long int min(long long int a,long long int b)
{
    if(a>b) return b;
    return a;
}
long long int max(long long int a,long long int b)
{
    if(a>b) return a;
    return b;
}
long long int util(vector<long long int>&v,int i,int j)
{
    if(i==j) return v[i];
    if(i+1==j) return max(v[i],v[j]);
    if(dp[i][j]!=-1) return dp[i][j];
    long long int ma = max(v[i]+min(util(v,i+1,j-1),util(v,i+2,j)),v[j]+min(util(v,i,j-2),util(v,i+1,j-1)));
    dp[i][j]=ma;
    return ma;
}
int main() {
	int n;
	cin>>n;
	vector<long long int>v(n);
	memset(dp,-1,sizeof(dp));
	long long int tot=0;
	for(int i=0;i<n;i++)
	{
	    cin>>v[i];
	    tot+=v[i];
	}
	long long int ret = util(v,0,n-1);
	cout<<(2*1LL*ret-tot)<<endl;
	return 0;
}

Measured memory_bytes: 74124
import java.util.*;

public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		int[] arr = new int[t];
		for(int i=0;i<t;i++)
		{
			arr[i] = sc.nextInt();
		}

		int[] dp = new int[t];

		dp[0] = 0;
		dp[1] = Math.abs(arr[1]-arr[0]);

		for(int i=2;i<t;i++)
		{
			dp[i] = Math.min(dp[i-1]+Math.abs(arr[i]-arr[i-1]),dp[i-2]+Math.abs(arr[i]-arr[i-2]));
		}

		System.out.println(dp[t-1]);
	}
}

Measured memory_bytes: 59148
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <queue>
#include <map>
using namespace std;
typedef long long LL;

LL n,k,a[200005];
LL pre[200005] = {0};
map <LL,LL> mp;
LL tot = 0;

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> k;
	for(LL i = 1;i <= n;i ++){
		cin >> a[i]; a[i] --; a[i] %= k;
		pre[i] = pre[i - 1] + a[i]; pre[i] %= k;
    }
	mp[pre[0]] = 1;
	for(LL i = 1;i <= n;i ++){
		if(i >= k) mp[pre[i - k]] --; 
		tot += mp[pre[i]]; 
		mp[pre[i]] ++; 
	}
	cout << tot << endl;
	return 0;
}

Measured memory_bytes: 19184
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]       
k=int(input())
print(L[k-1])            


Measured memory_bytes: 39760
N,K = map(int, input().split())
L = [[int(a) for a in input().split()] for _ in range(N)]

M = len(bin(K))-3
ans = 0
for l in L:
    if l[0] | K == K:
        ans += l[1]
k = 0
for i in range(M, -1, -1):
    if K & (1<<i) > 0:
        k += (1<<i)-1
        temp = 0
        for l in L:
            if l[0] | k <= K:
                temp += l[1]
        ans = max(ans, temp)
        k += 1

print(ans)

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

typedef long long lli; 

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
	lli N; 
	cin >> N; 

	vector<char> S(N);
	
	set<lli> positions[26]; 

	for (lli i = 0; i < N; ++i) {
		cin >> S[i]; 
		positions[S[i]-'a'].insert(i); 
	}
	
	lli Q; 
	cin >> Q; 

	while (Q-- > 0) {
		lli t; 
		cin >> t; 

		if (t == 1) {
			lli i; 
			char c; 

			cin >> i >> c;
			--i; 
		
			char old = S[i]; 
			S[i] = c; 

			positions[old-'a'].erase(i); 
			positions[c-'a'].insert(i); 

		} else {
			/* Count stuff */
			lli l, r; 
			cin >> l >> r; 

			--l; --r; 

			int in = 0; 			
			for (int i = 0; i < 26; ++i) {
				auto it = positions[i].lower_bound(l);
				if (it != positions[i].end() && *it <= r) ++in; 
			}	

			cout << in << endl; 
		}
	}

  return 0;
}


Measured memory_bytes: 24192
from collections import deque
import itertools
def bfs(G,visited,sy,sx):
    queue=deque([[sy,sx]])
    visited[sy][sx]=0
    while queue:
        y,x=queue.popleft()
        if (y,x)== (H-1,W-1):
            return visited[y][x]
        for j,k in ([1,0],[0,1],[-1,0],[0,-1]):
            tmp_y,tmp_x = y+j,x+k
            if 0<=tmp_y<=H-1 and 0<=tmp_x<=W-1 and  G[tmp_y][tmp_x]!='#':
                if visited[tmp_y][tmp_x]==-1:
                    visited[tmp_y][tmp_x]=visited[y][x]+1
                    queue.append([tmp_y,tmp_x])
    return -1
if __name__  =="__main__":
    H,W =map(int,input().split())
    G=[list(input()) for _ in range(H)]
    sy,sx =0,0
    dist=0
    visited=[[-1]*W for _ in range(H)]
    dist=bfs(G,visited,sy,sx)
    if dist==-1:
        print(-1)
    else:
        print(list(itertools.chain.from_iterable(G)).count('.')-dist-1)


Measured memory_bytes: 9360
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
#include<iterator>
using namespace std;

const int MAX_N = 100;
const int INF = INT_MAX / 2;

struct edge { int to, cap, weight, rev; };
typedef vector<edge> Edges;
typedef vector<Edges> Graph;

Graph G(MAX_N);
vector<int> dist(MAX_N);
vector<int> prevv(MAX_N);
vector<int> preve(MAX_N);


void add_edge(int s, int t, int cap, int weight) {
	edge e = { t,cap,weight,G[t].size() };
	G[s].push_back(e);
	edge f = { s, 0, -weight, G[s].size() - 1 };
	G[t].push_back(f);
}

void WarshallFloyd(int s) {
	fill(dist.begin(), dist.end(), INF);
	dist[s] = 0;
	bool update = true;
	while (update) {
		update = false;
		for (int j = 0; j<MAX_N; j++) {
			for (int k = 0; k<G[j].size(); k++) {
				edge e = G[j][k];
				if (e.cap>0 && dist[e.to]>dist[j] + e.weight) {
					dist[e.to] = dist[j] + e.weight;
					prevv[e.to] = j;
					preve[e.to] = k;
					update = true;
				}
			}
		}
	}
}

int MinimumCostFlow_wf(int s, int t, int f) {
	int cost = 0;
	while (f>0) {
		WarshallFloyd(s);
		if (dist[t] == INF) {
			return -1;
		}

		int d = f;
		for (int v = t; v != s; v = prevv[v]) {
			d = min(d, G[prevv[v]][preve[v]].cap);
		}

		f -= d;
		cost += d*dist[t];
		for (int v = t; v != s; v = prevv[v]) {
			edge &e = G[prevv[v]][preve[v]];
			e.cap -= d;
			G[v][e.rev].cap += d;
		}
	}
	return cost;
}


int main() {
	int V, E, F, s, t, cap, weight;

	cin >> V >> E >> F;
	for (int i = 0; i<E; i++) {
		cin >> s >> t >> cap >> weight;
		add_edge(s, t, cap, weight);
	}

	cout << MinimumCostFlow_wf(0, V - 1, F) << endl;
}

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

int main(){	
		
	map<ll, ll> m;
	ll n, sum=0;
	cin>>n;
	
	for(ll i=0; i<n; i++){
		
		ll x;
		cin>>x;
		sum+=x;
		m[x]++;
	}
	
	ll q;
	cin>>q;
	
	while(q--){
		
		ll b,c;
		cin>>b>>c;
		sum=sum+m[b]*(c-b);
		cout<<sum<<endl;
		
		map<ll, ll>:: iterator i=m.find(b);
		if(i!=m.end()){
			
			ll value=i->second;
			m.erase(i);
			m[c]=value+m[c];
		}
	}
}

Measured memory_bytes: 7496
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        if(y / 2 * 2 != y){
            System.out.println("No");
        }else if(y / 2 < x){
            System.out.println("No");
        }else if(4 * x < y){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        sc.close();
    }
}

Measured memory_bytes: 35960
#include<stdio.h>

int selectionSort(int A[], int N){
  int i,j,t,sw=0,minj;
    for(i = 0 ; i < N - 1 ; i++)
      {
	minj = i;
	for(j = i ; j < N ; j++){
	  if(A[j] < A[minj])minj = j;
	}
	t = A[i];
	A[i] = A[minj];
	A[minj] = t;
	if(i!=minj) sw++;
      }
  return sw;
}

int main(){
  int A[100],N,i,sw;
  
  scanf("%d",&N);
  for(i = 0 ; i < N ; i++) scanf("%d",&A[i]);

  sw = selectionSort(A,N);
  
  for(i = 0 ; i < N ; i++){
    if(i > 0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n", sw);
  
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    int n; cin >> n;
    vector<int> vc(3);
    rep(i, n) {
        int a; cin >> a;
        if(a%4==0) vc[2]++;
        else if(a%2==0) vc[1]++;
        else vc[0]++;
    }
    if(vc[1]==0&&vc[0]-vc[2]<=1) cout << "Yes";
    else {
        if(vc[2] >= vc[0]) cout << "Yes";
        else cout << "No";
    }puts("");
}


Measured memory_bytes: 384
def main():
  n = int(input())
  A = list(map(int, input().split()))
  
  num = [0] * n + [0]
  
  # for i in range(0, n-1):
  #   for k in range(0, len(A)):
  #     if A[k] == i+1:
  #       num[i] += 1
  
  for i in range(0, n-1):
    num[A[i]] += 1
  
  for k in range(1, n+1):    
    print(num[k])
  
main()

Measured memory_bytes: 32312
A, B, C, D, E, F = map(int, input().split())
con = -1
ans0 = -1
ans1 = -1
 
for a in range(31):
    for b in range(31):
        if a==0 and b==0:
            continue
        
        for c in range(3001):
            for d in range(3001):
                water = 100*A*a+100*B*b
                sugar = C*c+D*d
                
                if water+sugar>F:
                    break
                
                if sugar>(A*a+B*b)*E:
                    break
                
                if 100*sugar/(water+sugar)>con:
                    con = 100*sugar/(water+sugar)
                    ans0 = water+sugar
                    ans1 = sugar
 
print(ans0, ans1)

Measured memory_bytes: 43756
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (n, k) = listOfInt()
    val ll = listOfInt().sortedDescending()
    println(ll.slice(0 until k).sum())
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37808
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,f,l,nl;
    string s;
    cin>>s;
    for(i=0;i<s.length();i++)
        if(s[i]=='A'){
            f=i;
            break;
    }
    for(j=f;j<s.length();j++)
        if(s[j]=='Z')
            l=j;
    nl=l-f+1;
    printf("%d",nl);
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define M 1101
#define MOD 1000000007
#define fi first
#define se second
#define vi vector<int>
#define vl vector<ll>
#define all(v) v.begin(),v.end()
#define repl(i,l,r) for(long long i=l;i<=r;++i)
#define rep(i,l,r) for(int i=l;i<=r;++i)
#define ins insert
#define inf INT_MAX
#define vp vector< pair<int,int> >

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;cin>>n;
    int x=n/100;
    int y=n%100;
    bool check1=0,check2=0;
    bool check=1;
    if(y<=12&& y>0)
    {
        if(x<=99)
        {
            check1=1;
        }
        if(x<=12&& x>0)
        {
            check2=1;
        }


    }
    else
    {
        if(y<=99)
        {
            if(x<=12 && x>0)
            {
                check2=1;
            }
            else
            {
                check=0;
            }
        }
        else
        {
            check=0;
        }
    }
    if(check1==1 && check2==1)
    {
        cout<<"AMBIGUOUS"<<"\n";
    }
    else
    if(check1==1)
    {
        cout<<"YYMM"<<"\n";
    }
    else
    if(check2==1)
    {
        cout<<"MMYY"<<"\n";
    }
    else
    {
        cout<<"NA"<<"\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string s;
    int res = 0;
    cin>>s;
    if(s.size()<=1)
        cout<<0<<endl;
    else{
        for(int i=0;i<=s.size()/2-1;i++){
            if(s[i]!=s[s.size()-1-i])
                res++;
        }
        cout<<res<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
let f(a,b)=(b,a)and s=ref(Scanf.scanf"%d %d %d %d %d %d
"(fun a b c d e f->[(a,f);(b,e);(c,d)]));;Bytes.iter(fun c->s:=match!s with[x;y;z]->(match c with|'N'->[y;f x;z]|'S'->[f y;x;z]|'E'->[f z;y;x]|'W'->[z;y;f x]|_->[])|_->[])(Scanf.scanf"%s"(fun l->l));Printf.printf"%d
"(fst(List.hd!s))

Measured memory_bytes: 2416
#include <bits/stdc++.h>
using namespace std;
int main(){
  string mark;
  int card [4][13] = {} ;
  int n , number;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> mark >> number;

    if(mark == "S")card[0][number - 1] = 1   ;
    if(mark == "H")card[1][number - 1] = 1   ;
    if(mark == "C")card[2][number - 1] = 1   ;
    if(mark == "D")card[3][number - 1] = 1   ;
  }
    string markA[4] = {"S","H","C","D"};
    for(int i=0;i<4;i++){
      for(int j=0; j<13 ;j++){
	if(card[i][j] == 1)continue;
	cout << markA[i] <<" " << j + 1<< endl ;}
    }
      
      
    return 0;
  }


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

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

    int sz, k;
    cin >> sz >> k;
    vector<int> xs(sz, 0);
    for (auto &x : xs) cin >> x;
    sort(xs.begin(), xs.end());
    int ans = accumulate(xs.cbegin(), xs.cbegin() + k, 0);

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


Measured memory_bytes: 3648
#include <stdio.h>
int main(void){
	int n,a[10000],i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	while(--i>0){
		printf("%d",a[i]);
		if(i==1)break;
		printf(" ");
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 2052
N = int(input())
mod = 10 ** 9 + 7

memo = [{} for i in range(N+1)]


def ok(last4):
    for i in range(4):
        t = list(last4)
        if i >= 1:
            t[i-1], t[i] = t[i], t[i-1]
        if ''.join(t).count('AGC') >= 1:
            return False
    return True


def dfs(cur, last3):
    if last3 in memo[cur]:
        return memo[cur][last3]
    if cur == N:
        return 1
    ret = 0
    for c in 'ATCG':
        if ok(last3 + c):
            ret = (ret + dfs(cur + 1, last3[1:]+c)) % mod
    memo[cur][last3] = ret
    #print(memo, cur)
    return ret


print(dfs(0, 'TTT'))

Measured memory_bytes: 47320
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<Character> list = new ArrayList<>();
		
		for (int i = 0; i < n; i++) {
			list.add(scan.next().charAt(0));
		}
		
		if (list.contains('Y')) {
			System.out.println("Four");
		} else {
			System.out.println("Three");
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <utility>


#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;


int main(){
    int n;
    cin >> n;
    vector<pii> p(n);
    vector<int> a(n),b(n),diff(n);
    ll ress = 0;
    ll sum_a=0,sum_b=0;

    int cnt = 0;
    rep(i,n){cin >> a[i];
        sum_a += a[i];
    }
    rep(i,n){
        cin >> b[i];
        sum_b += b[i];

        diff[i] = max(0,a[i] - b[i]);
        if(a[i]<b[i]){ 
            cnt++;
            ress += (b[i]-a[i]);
        }
    }
    if(sum_a < sum_b){
        cout << "-1" << endl;
        return 0;
    }
    sort(diff.begin(),diff.end(),greater<int>() );

    // cout << ress << endl;
    rep(i,n){
        if(ress <= 0){
                cout << cnt << endl;
                return 0;
        }
        if(diff[i] > 0){
            ress -= diff[i];
            cnt++;
        }
        // cout << diff[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2176
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
using namespace std;
using ll=long long;
using ld=long double;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
struct edge{ll to,cost;};
struct edge2{ll from,to,cost;};

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

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

const ll MXV=1e5;
vl color(MXV,-1);
vl G[MXV];
vl MX(MXV,INF),MN(MXV,-INF);

void coloring(ll v,ll c){
    color[v]=c;
    ll k=G[v].size();
    rep(i,k){
        if(color[G[v][i]]==-1){
            coloring(G[v][i],c^1);
        }
    }
}

void dfs(ll v,ll p){
    if(p!=-1){
      	bool b=chmin(MX[v],MX[p]+1),c=chmax(MN[v],MN[p]-1);
        if(!(b||c)){
            return;
        }
    }
    ll k=G[v].size();
    rep(i,k){
        if(G[v][i]!=p){
            dfs(G[v][i],v);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    //n=100000;
    rep(i,n-1){
        int u,v;
        cin >> u >> v;
        //u=i+1,v=i+2;
        u--;v--;
        G[u].pb(v);
        G[v].pb(u);
    }
    int k;
    cin >> k;
  	//k=100000;
    vl v(k),p(k);
    rep(i,k){
        cin >> v[i] >> p[i];
      	//v[i]=i+1;
      	//p[i]=i+1;
      	v[i]--;
    }
    rep(t,2e7){
        int i=rand()%(k),j=rand()%(k);
        swap(v[i],v[j]);
        swap(p[i],p[j]);
    }
    rep(i,k){
        if(i==0){
            coloring(v[i],p[i]%2);
        }
        if(color[v[i]]!=p[i]%2){
            cout << "No" << endl;
            return 0;
        }
        if(!(MN[v[i]]<=p[i]&&p[i]<=MX[v[i]])){
            cout << "No" << endl;
            return 0;
        }
        MN[v[i]]=MX[v[i]]=p[i];
        dfs(v[i],-1);
    }
    cout << "Yes" << '\n';
    rep(i,n){
        cout << MN[i] << '\n';
    }
}

Measured memory_bytes: 15512
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, ans, p;
double sum;
int arr[105];

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    sum = 0;
    forn(i,n){
        cin >> arr[i];
        sum += arr[i];
    }
    sum = sum/n;
    sum += 0.5;
    p = (int)sum;

    ans = 0;

    forn(i,n){
        ans += ( (arr[i]-p) * (arr[i]-p) );
    }

    int temp = 0;

    forn(i,n){
        temp += ( (arr[i]-p-1) * (arr[i]-p-1) );
    }

    ans = min(ans,temp);

    temp = 0;

    forn(i,n){
        temp += ( (arr[i]-p+1) * (arr[i]-p+1) );
    }

    ans = min(ans,temp);

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>
#include <sstream>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;
#define maxn 100005
int main()
{
	int a,b,c,k,ans=0;
	cin >> a >> b >> c;
	cin >> k;
	k++;
	while (k--)
	{
		if (a < b && b < c)
		{
			ans=1;
			cout << "Yes" << endl;
			break;
		}
		else
		{
			if (a>=b) b=b*2;
			else if (b>=c) c=c*2;
		}
	}
	if (ans==0) cout << "No" << endl;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

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













int main(){
    ll k, x;
    cin >> k >> x;
    for(ll i = x - k + 1; i <= x + k - 1; i++){
        cout << i << " \n"[i == x + k - 1];
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>

using namespace std;
using ll = long long;

int main() {
	ll a, b, c;
	cin >> a >> b >> c;
	for (ll i = 0; i < b; i++)
	{
		if (a * i % b == c) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int max(int a, int b){
  return a >= b ? a : b;
}
int min(int a, int b){
  return b >= a ? a : b;
}
int factorial(int n) {
    if (n > 0) return n*factorial(n - 1);
		else return 1;
}
int compare_up_int(const void *a, const void *b){
   return *(int*)a - *(int*)b;
}
int compare_down_int(const void *a, const void *b){
   return *(int*)b - *(int*)a;
}
int euclid(int a, int b){
  if(a < b){int tmp = a;a = b;b = tmp;}
  int r = a % b;
  if(r < 0) r += b;
  while(r != 0){
    a = b;b = r;r = a % b;
    if(r < 0) r += b;
  }
  return b;
}

int main(){
  int N,count=0;
  scanf("%d",&N);
  int num[N];
  for(int i=0;i<N;i++) scanf("%d ",&num[i]);
  qsort(num,N,sizeof(int),compare_up_int);
  for(int i=0;i<N-1;i++) count += num[i];
  if(count > num[N-1]){
    printf("Yes\n");
  }
  if(count < num[N-1]){
    printf("No\n");
  }
  if(count == num[N-1]){
    printf("No\n");
  }
  return 0;
}


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

int main(){
  int a,b;
  cin >> a >> b;
  if (a>=13){
    cout << b;
  }
  else if (6<=a && a<=12){
    cout << b/2;
  }
  else{
    cout << 0;
  }
  return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>
int main(void)
{
	double r;
        double s,x;
	
	scanf("%lf",&r);
	
	s = r*r*3.14159265359;
	x = 2*3.14159265359*r;
	
	printf("%lf %lf\n",s,x);
	return 0;
}

Measured memory_bytes: 648
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/

string S;
//---------------------------------------------------------------------------------------------------
string solve() {
    int N = S.length();
    rep(i, 0, N) {
        if(i % 2 == 0) {
            // 奇数番目
            if(S[i] == 'L')
                return "No";
        }
        else {
            // 偶数番目
            if (S[i] == 'R')
                return "No";
        }
    }
    return "Yes";
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    cout << solve() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
 
int main(){
    ll N,M;
    cin >> N >> M;
    ll ans;
    ans = ((2 * N) + M) / 4;
    if(2*N > M) ans = M/2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

string s;

bool ch(int n) {
    n = n >> 1;
    for (int j = 0; j < n; j++) {
        if (s[j] != s[j + n]) {
            return false;
        }
    }
    return true;
}
int main()
{
    cin >> s;
    int n = s.length();
    int m = n;
    if (n % 2)
        n--;
    else
        n -= 2;
    while (!ch(n))
        n -= 2;
    cout << n;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define rall(x) x.rbegin(),x.rend()
#define mu(x) x.resize(unique(all(x))-x.begin());
#define srt(x) sort(all(x));
#define sum(x) accumulate(all(x),0ll);
#define rev(x) reverse(all(x));
#define each(x,a) for(auto& x:a)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define PER(i,a,b) for(int i=a;i>=b;i--)
#define debug(x) cerr<<#x<<" "<<x<<"\n";
#define debug_v(x) { cout<<#x<<"\n";  each(y,x) cout<<y<<" "; cout<<'\n';}
#define debug_vp(x) { cout<<#x<<"\n";  each(y,x) cout<<y.ff<<" "<<y.ss<<'\n'; cout<<'\n';}
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vb;
int main(){
	fastio;
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=1;i*i<=n-1;i++){
    if((n-1)%i==0){
      if((n-1)/i==i)ans++;
      else ans+=2;
    }
  }
  ans--;
  for(ll i=1;i*i<=n;i++){
    if(n%i!=0)continue;
    ll x=n;
    ll k=i;
    if(k!=1){
      while(x%k==0)x/=k;
      if(x%k==1)ans++;
      if(n/i==i)continue;
    }
    x=n;
    k=n/i;
    while(x%k==0)x/=k;
    if(x%k==1)ans++;
  }
  cout<<ans;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int d; cin >> d;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int> > s(d);
    rep(i,d)rep(j,26){
        int a; cin >> a;
        s[i].push_back(a);
    }

    vector<int> ld(26,0);
    vector<vector<int> > ds(26);
    //rep(i,26) ds[i].push_back(0);
    vector<int> days(d);

    ll ans=0;
    rep(i,d){
        int t; cin >> t;
        t--;
        days[i]=t;
        ds[t].push_back(i);
        ld[t]=i+1;
        ans+=s[i][t];
        rep(j,26){
            ans-=c[j]*(i+1-ld[j]);
        }
    }

    int m; cin >> m;
    rep(i,m){
        int D,Q; cin >> D >> Q;
        D--; Q--;
        int pd=days[D];
        days[D]=Q;
        ans+=s[D][Q];
        ans-=s[D][pd];
        int be,af;
        int r,l;
        l=-1;
        r=ds[pd].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[pd][c]<=D) l=c;
            else r=c;
        }
        if(r==ds[pd].size()) af=d;
        else af=ds[pd][r];
        l=-1;
        r=ds[pd].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[pd][c]>=D) r=c;
            else l=c;
        }
        if(l==-1) be=-1;
        else be=ds[pd][l];
        ds[pd].erase(ds[pd].begin()+l+1);
        ans-=c[pd]*(D-be)*(af-D);
        l=-1;
        r=ds[Q].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[Q][c]<=D) l=c;
            else r=c;
        }
        if(r==ds[Q].size()) af=d;
        else af=ds[Q][r];
        l=-1;
        r=ds[Q].size();
        while(l+1<r){
            int c=(l+r)/2;
            if(ds[Q][c]>=D) r=c;
            else l=c;
        }
        if(l==-1) be=-1;
        else be=ds[Q][l];
        ds[Q].insert(ds[Q].begin()+l+1,D);
        ans+=c[Q]*(D-be)*(af-D);
        cout << ans << endl;
    }
return 0;
}

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

int main() {
  int N,fin;
  vector<int> vec(100);
  cin >> N;
  for(int i=0;i < N;i++){
    cin >> vec.at(i);
  }
  fin = N;
  
  for(int i=0;i < N;i++){
    for(int j = i + 1;j < N;j++){
      if(vec.at(i) == 0) continue;
      if(vec.at(i) == vec.at(j)){
        fin--;
        vec.at(j) = 0;
      }
    }
  }
  cout << fin;
      
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<cmath>
#include<cstdio>
#define rep(i,n) for(int i=0; i<(n); ++i)
using namespace std;
using ll =long long;
using P = pair<int,int>;

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> p(m);
    rep(i,m) cin >> p[i].first >> p[i].second;
    rep(x,1000){
        int k = 1;
        int nx = x / 10;
        vector<int> d(1,x%10);
        while(nx){
            k++;
            d.push_back(nx%10);
            nx /= 10;
        }
        if(k != n) continue;
        bool ok = true;
        reverse(d.begin(), d.end());
        rep(i,m){
            if(d[p[i].first-1] != p[i].second) ok = false;
        }
        if(ok){
            cout << x << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
n,q=map(int, input().split())
s=input()
sn=""
ans=[0]*(n+1)

for i in range(n):
    if s[i:i+2]=="AC":
        ans[i+1]=ans[i]+1
    else:
        ans[i+1]=ans[i]

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


Measured memory_bytes: 6060
n = gets.chomp.to_i
s = gets.chomp.split('')

r, g, b = 0, 0, 0
reject_count = 0
s.each_with_index do |val_i, ind_i|
  if val_i == 'R'
    r += 1
  elsif val_i == 'G'
    g += 1
  else
    b += 1
  end
  
  s[ind_i+1..n-1].each.with_index(ind_i+1) do |val_j, ind_j|
    next if val_i == val_j
    
    ind_k = 2 * ind_j - ind_i
    reject_count += 1 if ind_k < n && s[ind_k] != val_i && s[ind_k] != val_j
  end
end

all = r * g * b

puts all - reject_count


Measured memory_bytes: 14648
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountll((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzll(x))
#define rep(i, n) for(int i = 0; i < n; i++)
const int inf9 = 1e9; const lint inf18 = 1e18;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ double y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } double euclidean(double first, double second){ return sqrt(first * first + second * second); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint P(int n, int r){ if(r < 0 || n < r) return 0; return (fact[n] * inv[n - r] % mod); } lint C(int p, int q){ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }
inline int at(lint i, int j){ return (i >> j) & 1; }

int main(){
    int N;
    cin >> N;
    set<int> A;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        A.insert(a);
    }
    YES(A.size() == N);
}


Measured memory_bytes: 9600
from math import ceil
N, K = map(int, input().split())
P = list(map(int, input().split()))
E = [0]
E.append(sum([i for i in range(1, P[0] + 1)])/P[0])
for i in range(1,N):
    p = P[i]
    E.append(E[i] + ((1+p) / 2))
r = K
ans = 0
while r < N + 1:
    ans = max(ans, E[r] - E[r - K])
    r += 1
print(ans)

Measured memory_bytes: 25064
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

struct C
{
	int k,l,r;
	C(int k, int l, int r) : k(k),l(l),r(r) {}
};

int main() {
	int t;
	std::cin >> t;
	rep(tt,t) {
		int n;
		std::cin >> n;
		std::vector<C> v;
		rep(i,n) {
			int a,b,c;
			std::cin >> a >> b >> c;
			v.emplace_back(a,b,c);
		}
		std::vector<std::pair<int,int> > L,R;
		lnt sum=0;
		rep(i,n) {
			if(v[i].l>v[i].r) {
				sum+=v[i].r;
				L.emplace_back(v[i].l-v[i].r,v[i].k);
			} else {
				sum+=v[i].l;
				R.emplace_back(v[i].r-v[i].l,n-v[i].k);
			}
		}
		if(!L.empty()) {
			std::sort(all(L),[](std::pair<int,int> a, std::pair<int,int> b) { if(a.second!=b.second) return a.second<b.second; else return a.first<b.first; });
			std::priority_queue<std::pair<int,int>,std::vector<std::pair<int,int> >, std::greater<> > que;
			for(auto x:L) {
				if(x.second>que.size()) que.emplace(x);
				else if(!que.empty()) {
					if(que.top().first<x.first) {
						que.pop();
						que.emplace(x);
					}
				}
			}
			while(!que.empty()) {
				sum+=que.top().first;
				que.pop();
			}
		}
		if(!R.empty()) {
			std::sort(all(R),[](std::pair<int,int> a, std::pair<int,int> b) { if(a.second!=b.second) return a.second<b.second; else return a.first<b.first; });
			std::priority_queue<std::pair<int,int>,std::vector<std::pair<int,int> >, std::greater<> > que;
			for(auto x:R) {
				if(x.second>que.size()) que.emplace(x);
				else if(!que.empty()) {
					if(que.top().first<x.first) {
						que.pop();
						que.emplace(x);
					}
				}
			}
			while(!que.empty()) {
				sum+=que.top().first;
				que.pop();
			}
		}
		print(sum);
	}
}


Measured memory_bytes: 9412
N=int(input())
A=sorted(list(map(int,input().split())))
l=[]
s=set()
for i in range(N):
    if A[N-i-1] in s:
        l.append(A[N-i-1])
        s.discard(A[N-i-1])
    else:
        s.add(A[N-i-1])
l.sort()
print(0 if len(l)<2 else l[-1]*l[-2])

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


bool check(long long);

int main()
{
    bool prime[1000000];
    fill(prime, prime+1000000, false);
    //create prime table
    prime[0] = prime[1] = false;
    for(long long i=2;i<=1000000;i++)
    {
        if(check(i) == true)
        {
            prime[i] = true;
        }
    }

    int a,d,n;

    cin>>a>>d>>n;
    while(a!=0 && d != 0 && n != 0)
    {
        int cnt = 0;
        long long m;
        for(m = a;cnt < n; m += d)
        {
            if(prime[m] == true)
                cnt++;
        }
        cout<<m - d<<endl;
        cin>>a>>d>>n;
    }
}

bool check(long long i)
{
    if(i%2 == 0 && i != 2) return false;
    for(long long j = 3;j*j <= i;j += 2)
        if(i%j == 0)
            return false;
    return true;
}

Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >> n;
  n=n%10;
  if(n==2||n==4||n==5||n==7||n==9)
    cout<<"hon\n";
  else if(n==0||n==1||n==6||n==8)
    cout <<"pon\n";
  else
    cout<<"bon\n";
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int N;
    cin >> N;
    vector<int> a(N);
    REP (i, 0, N) cin >> a[i];
    vector<int> s(9, 0);

    REP (i, 0, N) {
        if (a[i] < 3200) {
            s[a[i] / 400] = 1;
        } else {
            s[8]++;
        }
    }
    int cnt = 0;
    REP (i, 0, 8) cnt += s[i];
    if (cnt == 0) {
        cnt = 1;
        s[8]--;
    }
    cout << cnt << ' ' << cnt + s[8] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>void print(T x){cout << x << endl;}
template<class T>void printvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }

ll power(ll m, ll n, ll mod){
    ll res=1;
    while(n>0){
        if(n & 1) res = res * m % mod;
        m = m*m%mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    ll n, m;
    cin >> m >> n;

    printf("%lld\n", power(m, n, MOD));
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll mod = 1e9+7;
int inf = 1000000000; //10e9
 
int main() {

    int N, K;
    cin >> N >> K;
    vector<int> x(N);
    rep(i,N) cin >> x[i];

    int ans = 0;
    rep(i,N){
        int distA = 2*x[i];
        int distB = 2*abs(x[i]-K);
        ans += min(distA,distB);
    }

    cout << ans <<endl;

    return 0;

}

Measured memory_bytes: 3628
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

x,y,z = LI()
print(z,x,y)

Measured memory_bytes: 38384
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;

int main(){
  int i;

  while( 1 ){
    int n, s[1000] = {};
    double sd = 0, avg = 0, disp = 0;
    // ?¨?????????? standard deviation, ?????£ dispersion
    cin >> n;
    if( n == 0 ) break;
    
    for( i = 0; i < n; i++ ){
      cin >> s[i];
      avg += s[i];
    }
    avg = avg / n;

    for( i = 0; i < n; i++ ){
      disp += ( s[i] - avg )*( s[i] - avg );
    }

    printf("%lf\n", sqrt( disp / n ));
  }
  
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

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

int dp[MAXN + 1], arr[MAXN + 1];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> arr[i];
        dp[arr[i]] = dp[arr[i] - 1] + 1;
    }
    int ans = MAXN;
    for(i = 1; i <= n; i++) {
        ans = min(ans, n - i + i - dp[i]);
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 1792
import Data.Array.IArray

main = putStrLn . unwords . map show . solve . drop 1 . map read . words =<< getContents

solve :: [Int] -> [Int]
solve xs =
    let xs' = listArray (0,length xs) xs :: Array Int Int
        n = [xs'!k | k <- takeWhile ((>) $ length xs) [0, 2..]]
        r = [xs'!k | k <- takeWhile ((>) $ length xs) [1, 3..]]
    in if odd $ length xs then reverse n ++ r else reverse r ++ n


Measured memory_bytes: 110332
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  string str;
  cin >> str;
  int q,i;
  cin >> q;
  string s1,s2;
  int a,b;
  for(i=0;i<q;i++){
    //cout << str << endl;
    cin >> s1 >> a >> b;
    if(s1=="print"){
      cout << str.substr(a,b-a+1) << endl;
    }else if(s1=="reverse"){
      string s3=str.substr(a,b-a+1);
      reverse(s3.begin(),s3.end());
      str=str.substr(0,a)+s3+str.substr(b+1,str.size()-a-1);
    }else{
      cin >> s2;
      str=str.substr(0,a)+s2+str.substr(b+1,str.size()-a-1);
    }
  }
}



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


int main() {
 long long H, W;
  cin >> H >> W;
  long long a = H/2;
  long long b = W/2;
  long long c = (b+1)*a;
  long long d = b*a;
  if(H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  if(W % 2 == 1){
    if(H % 2 == 0){
      cout << c + d<< endl;
    }
    if(H % 2 == 1){
      cout << c + d + b + 1 << endl;
    }
  }
  if(W % 2 == 0){
    cout << b*H << endl;
  }
}

Measured memory_bytes: 256
//In the name of Allah :)
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 2e5 + 10;


int main(){
	ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);
	long long i = 1 , n , now = 100;
	cin >> n;
	for(; now < n ; i++){
		now = now + now / 100;
	}
	cout << --i << '\n';

}


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

int compare_int(const void * a, const void * b){
    return *(int*)b - *(int*)a;
}

int a[101];
int main(){
    int N;
    scanf("%d",&N);
    
    int tmp;
    for(int n = 0; n < N; n++){
        scanf("%d", &tmp);
        a[n] = tmp;
    }
    
    qsort(a,N,sizeof(int),compare_int);
    
    int alice = 0, bob = 0;
    for(int n = 0; n < N; n++){
        if(n%2==0) alice+=a[n];
        else       bob  +=a[n];
    }
    printf("%d\n",alice-bob);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define watch(x) cout << #x << " is " << x << endl;
#define print(a, l, r) \
    for (int i = l; i < r; i++) cout << a[i] << (i == (r - 1) ? endl : " ");
const long long M = 1000000007;

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

    int n, m;
    cin >> n >> m;

    int c = 0, p = 0;
    bool f[n + 1] = {false};
    int pn[n + 1] = {0};
    for (int i = 0; i < m; i++) {
        int pno;
        string v;
        cin >> pno >> v;

        if (!f[pno]) {
            if (v == "AC") {
                c++;
                f[pno] = true;
            } else {
                pn[pno]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        if (f[i]) {
            p += pn[i];
        }
    }
    cout << c << " " << p << endl;
    return 0;
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ull unsigned long long
#define ld long double

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) rep2(i, 0, n)
#define rep1(i, n) rep1(i, 1, n + 1)

// #define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
// #define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()  //

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(15);
    //    cout << std::setfill('0') << std::setw(2);

    long long H;
    std::cin >> H;
    long long W;
    std::cin >> W;
    std::vector<std::string> S(H);
    for (int i = 0; i < H; i++) {
        std::cin >> S[i];
    }
    rep(i, H) rep(j, W) {
        if (S[i][j] == '#') continue;
        int c = 0;
        rep(k, 8) {
            int y = i + dy[k], x = j + dx[k];
            if (y < 0 || x < 0 || y >= H || x >= W) continue;
            if (S[i + dy[k]][j + dx[k]] == '#') c++;
        }
        S[i][j] = c + '0';
    }
    rep(i, H) { cout << S[i] << endl; }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#include<stdlib.h>
using namespace std;
struct Process { char name[10]; int time; };

int main() {
  int n, q;
  scanf("%d", &n);
  scanf("%d", &q);

  Process process[n];
  queue<Process> processList;

  for ( int i = 0; i < n; i++ ) {
    scanf("%s", process[i].name);
    scanf("%d", &process[i].time);
    processList.push(process[i]);
  }

  int elapsedTime = 0;
  while ( !processList.empty() ) {
    Process nowProcess = processList.front();
    if ( nowProcess.time <= q ) {
      elapsedTime += nowProcess.time;
      printf("%s %d\n", nowProcess.name, elapsedTime);
      processList.pop();
    } else {
      elapsedTime += q;
      nowProcess.time -= q;
      processList.pop();
      processList.push(nowProcess);
    }
  }

  return 0;
}



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

#define REP(i, s,  n) for(int i = s;i < (n);i++)
#define VSORT(v) sort(v.begin(), v.end());
#define int64 long long
#define pb(a) push_back(a)
#define REP64(i, s,  n) for(int64 i = s;i < (n);i++)
#define INF 999999999
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> PP;

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

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

int N, H;
multimap<int, int> AB;

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

	cin >> N >> H;
	int a, b;
	REP(i, 0, N) {
		cin >> a >> b;
		AB.insert(make_pair(a, -1));
		AB.insert(make_pair(b, 1));
	}
	
	int ans = 0;
	int wk;
	for(auto itr = AB.rbegin(); itr != AB.rend(); ++itr) {
	    if(itr->second == -1) {
	        wk = (H / itr->first);
	        H -= (wk * itr->first);
	        if(H > 0) {
	            H -= itr->first;
	            wk++;
	        }
	        ans += wk;
	    } else {
			H -= itr->first;
			ans++;
	    }
		if(H <= 0)	break;
    }
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 9600
import math
N=int(input())
for i in range(N):
	x1,y1,x2,y2,x3,y3=[float(e) for e in input().split()]
	a1=2*x2-2*x1
	b1=2*y2-2*y1
	c1=x1*x1-x2*x2+y1*y1-y2*y2
	a2=2*x3-2*x1
	b2=2*y3-2*y1
	c2=x1*x1-x3*x3+y1*y1-y3*y3
	x=(b1*c2-b2*c1)/(a1*b2-a2*b1)
	y=(c1*a2-c2*a1)/(a1*b2-a2*b1)
	print('%.3f %.3f %.3f'%(x,y,math.hypot(x1-x,y1-y)))


Measured memory_bytes: 5688
N, K = map(int, input().split())
x = list(map(int, input().split()))
N_minus = len([m for m in x if m < 0])
ans = float('inf')

for i in range(N):
    left = i
    right = i + K - 1
    if right >= N:
        break

    if x[right] <= 0:
        ans = min(x[left] * (-1), ans)
    elif x[left] < 0:
        ans = min(x[left] * (-1) * 2 + x[right], ans)
        ans = min(x[left] * (-1) + x[right] * 2, ans)
    else:
        ans = min(x[right], ans)

print(ans)

Measured memory_bytes: 14224