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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  for(int i=0;i<=a;++i){
    for(int j=0;j<=b;++j){
      for(int k=0;k<=c;++k){
        int total = 500*i+100*j+50*k;
        if(total == x) ++ans;
      }
    }
  }
  cout << ans << endl;
        
}


Measured memory_bytes: 256
#include <cstdio>

int N;
int cnt[100005];

int main()
{
	int tmp;
	int max = 0;
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &tmp);
		cnt[tmp]++;
		cnt[tmp + 1]++;
		cnt[tmp + 2]++;
	}
	for (int i = 0; i < 100002; i++) {
		if (cnt[i] > max)
			max = cnt[i];
	}
	printf("%d\n", max);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
#define fir first
#define sec second
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int a[5];
	rep(i,0,5) cin >> a[i];
	int k;
	cin >> k;

	rep(i,0,5){
		rep(j,i+1,5){
			if( a[j] - a[i] > k ){
				cout << ":(" << endl;
				ret 0;
			}
		}
	}

	cout << "Yay!" << endl;
	ret 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func receive() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	n, x := receive(), receive()

	child := make([]int, n)
	var sum int
	for i := 0; i < n; i++ {
		t := receive()
		child[i] = t
		sum += t
	}

	switch {
	case x == sum:
		fmt.Println(n)
	case x > sum:
		fmt.Println(n - 1)
	default:
		sort.Ints(child)
		var ans int
		for i := 0; i < n; i++ {
			x -= child[i]
			if x < 0 {
				break
			}
			ans++
		}
		fmt.Println(ans)
	}
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 100;
int rate[NMAX+1];

// Problem Specific Parameter:

int main() {
  int n; cin >> n;
  vector<int> a(n);
  int cnt = 0;
  int ambiguous = 0;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    if(a[i]/400 < 8 && rate[a[i]/400] == 0) cnt++, rate[a[i]/400]=1;
    else if(a[i] / 400 >= 8) ambiguous++;
  }
  if(cnt==0) {
    cout << 1 << " " << cnt + ambiguous << endl;
  } else {
    cout << cnt << " " << cnt + ambiguous << endl;
  }

  return 0;
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    //good luck kittu!
    int n, x; cin>>n;
    bool ok = 1;
    for(int i = 0; i<n; i++){
        cin>>x;
        if(x&1^1){
            if(x%3!=0 && x%5!=0) ok = 0;
        }
    }
    cout<<(ok?"APPROVED\n":"DENIED\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> p(n);
    vector<int> p2(n);
    rep(i,n)
    {
        cin>>p[i];
        p2[i]=p[i];
    }
    sort(p2.begin(),p2.end());
    if(p2==p)
    {
        cout<<"YES"<<endl;
        return 0;
    }
    for (int i = 0; i < p.size()-1; i++)
    {
        for (int j = i+1; j < p.size(); j++)
        {
            vector<int> a=p;
            swap(a[i],a[j]);
            if(a==p2)
            {
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;

    return 0;
}

Measured memory_bytes: 632
n= int(input())
d=list(map(int,input().split()))
d2=sorted(d)
k=0
count=0
for i in range(n-1):
  if d[i]>d[i+1] and count==0:
    k=d[i]
    count+=1
    for j in range(i+2,n):
      if d[i+1]>d[j]:
        d[i]=d[j]
        d[j]=k
        break
if d2==d:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        int n=gi();
        int[] A =new int[n];
        int[] A2 =new int[n];
        LinkedList<Integer> B =new LinkedList<Integer>();

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

        Arrays.sort(A);
        for (int i=0; i<A.length;i++) {
        	A2[i]=A[n-i-1];
        }

        long m=0;
        B.add(A2[0]);
        for (int i=1; i<n;i++) {
        	int co=A2[i];
        	long mk=B.pollFirst();
        	B.add(co);
        	B.add(co);
        	m+=mk;
        }

	    System.out.println(m);

//	    if (isNumber(s1) && isNumber(s2) && s.charAt(a) == '-') {
//	    	System.out.print("Yes");
//	    }else {
//	    	System.out.print("No");
//	    }



	}

	public static long d(long n) {
		String a=String.valueOf(n);
		return (long)a.length();
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 65420
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;

int main(){
    ll a=0,b=0,c=0,d=0,n;
    //VI a(N);
    string s,s2;
    cin >> c;
    a = c/100;
    b = c%100;

    if(1<=a&&a<=12){
        if(1<=b&&b<=12){
            cout << "AMBIGUOUS" << endl;
        }
        else {
            cout << "MMYY" << endl;
        }
    }
    else{
        if(1<=b&&b<=12){
            cout << "YYMM" << endl;
        }       
        else{
             cout << "NA" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
#define mod 1000000007
//#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)

int main()
{
	fast;
	int n,i,j,m,k;
	cin>>n>>m>>k;
	string s[n];
	for(i=0;i<n;i++)
	{
		cin>>s[i];
	}
	int ans=0;
	int x=0;
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			if(s[i][j]=='#')
			x++;
		}
	}
	int i1,j1;
	for(i=0;i<(1<<n);i++)
	{
		int a[n][m];
		mem(a,0);
		int y=0;
		for(i1=0;i1<n;i1++)
		{
			
			if((i>>i1)&1)
			{
				for(j=0;j<m;j++)
				{
					if(s[i1][j]=='#')
					{
						y++;
						a[i1][j]=1;
					}
				}
			
			
			}
		}
		int z=0;
		for(j=0;j<(1<<m);j++)
		{
			z=0;
			for(j1=0;j1<m;j1++)
			{
				if((j>>j1)&1)
				{
					for(int i2=0;i2<n;i2++)
					{
						if(s[i2][j1]=='#'&&a[i2][j1]!=1)
						{
							z++;
						}
					
					}
				}
			}
			if(x-(y+z)==k)
			{
				ans++;
			}
		}
	}
	cout<<ans;
    
    
}

Measured memory_bytes: 3644
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    l = len(s)
    n = int(s)
    m = inf
    r = 0
    t = 10**l
    for a in itertools.permutations(range(10), l):
        b = 0
        for c in a:
            b = b * 10 + c
        tm = max(abs(n-b),t-abs(n-b))
        if m > tm:
            m = tm
            r = ''.join(map(str,a))

    return r


print(main())




Measured memory_bytes: 9032
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main() {
	ios;
	int n,x,y,i,j;
	cin>>n>>x>>y;
	int d[n+1][n+1];
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		d[i][j]=abs(i-j);
	}
	for(i=1;i<=n;i++)
	{
		if(d[x][i]>d[y][i]+1)
		{
			d[x][i]=d[y][i]+1;
			d[i][x]=d[x][i];
		}
		else {
		d[y][i]=min(d[y][i],d[x][i]+1);
		d[i][y]=d[y][i];
	}
	}
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		d[i][j]=min(d[i][j],min(d[i][x]+d[x][j],d[i][y]+d[y][j]));
	}
	
	vector<int> ans(n);
	for(i=1;i<n;i++) ans[i]=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		ans[d[i][j]]++;
	}
	for(i=1;i<n;i++) cout<<ans[i]/2<<"\n";
	
	return 0;
}

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

int main(){

    double a;
    
    cin >> a;
    
    cout <<fixed<<setprecision(6)<< (double)a * a * 3.14159265358979 << " " <<fixed<<setprecision(6)<< (double)a * 2 * 3.14159265358979 <<endl;

    return 0;
}


Measured memory_bytes: 3240
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

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

	vector<int> h(N);
	for(auto &x : h) {
		cin >> x;
	}

	const auto cost = [&](int from, int to) {
		return abs(h[from] - h[to]);
	};

	// minCost[i]: iまでの最小コスト
	vector<int> minCost(N);
	minCost[0] = 0;
	minCost[1] = cost(0, 1);
	for(int i = 2; i < N; i++) {
		minCost[i] = min(
			minCost[i - 1] + cost(i - 1, i),
			minCost[i - 2] + cost(i - 2, i)
		);
	}

	cout << minCost[N - 1] << endl;

	return 0;
}


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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll N, K;
    cin >> N >> K;

    ll a = N % K;
    ll b = K - a;

    cout << min(a, b) << endl;

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools
import operator
from functools import reduce  # Required in Python 3


def solve(X:int):
    for a in range(1, 125):
        for b in range(-125, 125):
            if a ** 5 - b ** 5 == X:
                print(a, b)
                return

def prod(iterable):
    return reduce(operator.mul, iterable, 1)

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def solve_wrong(X: int):
    insu = [1] + prime_factorize(X)
    N = len(insu)
    ans_a = -99999999
    ans_b = -99999999
    for n in range(N):
        tmp = itertools.combinations(insu, n)
        for t in tmp:
            print(t)
            product = prod(t)
            b = 0
            while True:
                left = (b + product) ** 4 + (b + product) ** 3 * b + (b + product) ** 2 * (b ** 2) + (b + product) * (b ** 3) + b ** 4
                right = X // product
                if left == right:
                    ans_a = b + product
                    ans_b = b
                    break
                if left > right:
                    break
                b += 1
            b = 0
            while True:
                left = (b + product) ** 4 + (b + product) ** 3 * b + (b + product) ** 2 * (b ** 2) + (b + product) * (b ** 3) + b ** 4
                right = X // product
                if left == right:
                    ans_a = b + product
                    ans_b = b
                    break
                if left > right:
                    break
                b -= 1
            if ans_b != -99999999:
                break
        if ans_b > 0:
            break
    print(ans_a, ans_b)



    return


# 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)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9568
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;

int main()
{
	int n; cin>>n;
    string s; cin>>s;
    vector<int> vr, vg, vb;
    for(int i=0; i<3*n; i++){
        if(s[i]=='R') vr.push_back(i);
        else if(s[i]=='G') vg.push_back(i);
        else vb.push_back(i);
    }
    reverse(vr.begin(), vr.end());
    reverse(vg.begin(), vg.end());
    reverse(vb.begin(), vb.end());
    int a[300010];
    for(int i=0; i<n; i++){
        int r[3];
        r[0]=vr.back(), r[1]=vg.back(), r[2]=vb.back();
        vr.pop_back(); vg.pop_back(); vb.pop_back();
        sort(r, r+3);
        a[r[0]]=0, a[r[1]]=1, a[r[2]]=2;
    }
    ll c=0;
    ll dp1[300030]={};
    for(int i=0; i<3*n; i++){
        if(a[i]==0) c++;
        else if(a[i]==1){
            dp1[i]=c;
            c--;
        }
    }
    c=0;
    ll ans=1;
    for(int i=3*n-1; i>=0; i--){
        if(a[i]==2){
            c++;
        }else if(a[i]==1){
            (ans*=dp1[i]*c%MOD)%=MOD;
            c--;
        }
    }
    for(ll i=1; i<=n; i++) ans=ans*i%MOD;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5756
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int cards[50];
int n, r;

void cut(int p, int c) {
	vector<int> temp(c);
	for (int i = 0; i < c; i++) {
		temp[i] = cards[p + i - 1];
	}

	for (int i = p - 2; i >= 0; i--) {
		cards[i + c] = cards[i];
	}

	for (int i = 0; i < c; i++) {
		cards[i] = temp[i];
	}
}

int main() {
	while (true) {
		cin >> n >> r;
		if (!n && !r) break;

		for (int i = 0; i < n; i++) {
			cards[i] = n - i;
		}

		for (int i = 0; i < r; i++) {
			int p, c;
			cin >> p >> c;
			cut(p, c);
		}

		cout << cards[0] << endl;
	}

	return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll a,ll b){
  if(a==1||b==1)
    return 1;
  if(a==0)
    return b;
  if(b==0)
    return a;
  if(a>=b)
    return gcd(a%b,b);
  return gcd(b%a,a);
}
int main(){
  ll l=1;
  int n;
  cin >> n;
  rep(i,n){
    ll a;
    cin >> a;
    l=(l/gcd(l,a))*a;
  }
  cout << l << endl;
}

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

int main() {
	long long a,b,c,d;
	cin>>a>>b>>c>>d;
	long long mx=0;
	mx=max(a*c,a*d);
	mx=max(mx,b*d);
	mx=max(mx,b*c);
	cout<<mx;
	return 0;
}

Measured memory_bytes: 3192
/*A - Circle Pond*/
#include <bits/stdc++.h>

using namespace std;

int main(){

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

	double radio;
	cin >> radio;

	cout << fixed << setprecision(20) << M_PI * (radio + radio) << endl;

	
	return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define lb long double
#define eps 1e-10
using namespace std;
struct Po{lb x,y;};
struct circ{Po x;lb r;}c1,c2;
void get(Po &x){scanf("%Lf %Lf",&x.x,&x.y);}
Po operator -(Po x,Po y){return (Po){x.x-y.x,x.y-y.y};}
lb que(Po x){return sqrtl(x.x*x.x+x.y*x.y);}
int main(){
	get(c1.x);scanf("%Lf",&c1.r);
	get(c2.x);scanf("%Lf",&c2.r);
	lb dis=que(c1.x-c2.x);
	if (dis>c1.r+c2.r+eps) puts("4");
	else if (fabs(dis-c1.r-c2.r)<eps)puts("3");
	else if (dis>fabs(c1.r-c2.r)+eps)puts("2");
	else if (fabs(dis-fabs(c1.r-c2.r))<eps) puts("1");
	else puts("0");
	return 0;
}


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define y1 dhwjdshg

using namespace std;

const int N = 1000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n)
        cin >> a[i];
    int pos_max = -1;
    rep(i, 0, n)
        if (pos_max == -1 || a[i] > a[pos_max])
            pos_max = i;
    if (a[pos_max] <= 0)
    {
        vector<int> out;
        repb(i, n - 1, pos_max)
            out.push_back(i);
        rep(i, 0, pos_max)
            out.push_back(0);
        cout << a[pos_max] << "\n";
        cout << sz(out) << "\n";
        for (int i : out)
            cout << i + 1 << "\n";
        return 0;
    }
    ll sum0 = 0, sum1 = 0;
    rep(i, 0, n)
        if (i % 2 == 0)
        {
            if (a[i] >= 0)
                sum0 += a[i];
        }
        else
        {
            if (a[i] >= 0)
                sum1 += a[i];
        }
    vector<int> out;
    if (sum1 > sum0)
    {
        out.push_back(0);
        rep(i, 0, n - 1)
            a[i] = a[i + 1];
        a.pop_back(); n--;
        sum0 = sum1;
    }
    if (n % 2 == 0)
    {
        out.push_back(n - 1);
        a.pop_back(); n--;
    }
    int cnt_less = 0;
    for (int i = 0; i < n; i += 2)
    {
        if (a[i] < 0)
        {
            if (cnt_less == 0)
            {
                out.push_back(0);
                out.push_back(0);
            }
            else if (i == n - 1)
            {
                out.push_back(cnt_less);
                out.push_back(cnt_less - 1);
                cnt_less--;
            }
            else
            {
                out.push_back(cnt_less);
            }
        }
        else
        {
            if (i == n - 1)
                cnt_less++;
            else
                cnt_less += 2;
        }
    }
    rep(i, 0, (cnt_less - 1) / 2)
        out.push_back(1);
    cout << sum0 << "\n";
    cout << sz(out) << "\n";
    for (int i : out)
        cout << i + 1 << "\n";
    return 0;
}

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

#define M 2010
int sumL[M][M] = {};
int sumR[M][M] = {};
int sumU[M][M] = {};
int sumD[M][M] = {};

int main(void){
    int Y,X;
    cin >> Y >> X;
    vector<string> s(Y);
    rep(y,Y) cin >> s[y];

    rep(yy,Y){
        int cnt = 0;
        rep(xx,X){
            int y = yy, x = xx;
            if (s[y][x] == '#') cnt = 0;
            else {
                sumL[y][x] = cnt;
                cnt++;
            }
        }
    }

    rep(yy,Y){
        int cnt = 0;
        rep(xx,X){
            int y = yy, x = X - 1 - xx;
            if (s[y][x] == '#') cnt = 0;
            else {
                sumR[y][x] = cnt;
                cnt++;
            }
        }
    }

    rep(xx,X){
        int cnt = 0;
        rep(yy,Y){
            int y = yy, x = xx;
            if (s[y][x] == '#') cnt = 0;
            else {
                sumD[y][x] = cnt;
                cnt++;
            }
        }
    }

    rep(xx,X){
        int cnt = 0;
        rep(yy,Y){
            int y = Y - 1 - yy, x = xx;
            if (s[y][x] == '#') cnt = 0;
            else {
                sumU[y][x] = cnt;
                cnt++;
            }
        }
    }
    int res = 0;
    rep(y,Y)rep(x,X){
        if (s[y][x] == '.') {
            res = max(res, 1 + sumL[y][x] + sumR[y][x] + sumD[y][x] + sumU[y][x]);
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 67456
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

int N;
char buf[314514];
LL ans = 0;
LL cnt = 0;

int main() {
  scanf("%s", buf);
  N = strlen(buf);

  rrep(i, N) {
    if (buf[i] == 'B') {
      ans += cnt;
    } else if (buf[i] == 'W') {
      cnt++;
    } else assert(0);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int deg[100001];
char s[100001];
int i, j;
int main(){
  scanf("%s", s);
  int l = strlen(s);
  i=0;
  int tmp=1;
  int tmp_r;
  int r_ind;
  while(i<l){
    if(s[i]==s[i+1]){
      tmp+=1;
    }else if((strncmp(&s[l-1], &s[i], 1))==0){
      tmp+=1;
      if(tmp%2==0){
        deg[r_ind]=tmp/2;
        deg[r_ind+1]=tmp/2;
      }else{
        if((tmp-tmp_r)%2==0){
          deg[r_ind]=tmp/2+1;
          deg[r_ind+1]=tmp/2;
        }else{
          deg[r_ind]=tmp/2;
          deg[r_ind+1]=tmp/2+1;
        }
      }

      tmp=1;
    }else if((strncmp(&s[0], &s[i], 1))==0){
      tmp_r=tmp;
      r_ind = i;
    }
    i+=1;
  }

  for(i=0;i<l;i++)printf("%d ", deg[i]);
  printf("\n");

  return 0;
}


Measured memory_bytes: 896
s = int(input())
x = []
while True:
	d = s % 10
	x.append(d)
	s //= 10
	if s == 0:
		break
n = len(x)
m = 10000
for i in range(n-2):
	y = abs((x[n-1-i] - 7) * 100 + (x[n-1-i-1] - 5) * 10 + x[n-1-i-2] - 3)
	if y < m:
		m = y
print(m)


Measured memory_bytes: 3060
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
using namespace std;

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

	vector<int> cnt(M, 0);
	for(int i=0; i<N; i++){
		int K;
		cin >> K;

		int a;
		for(int j=0; j<K; j++){
			cin >> a;

			a--;
			cnt[a]++;
		}
	}

	int ans = count(cnt.begin(), cnt.end(), N);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
for i in range(-1,len(ais)):
	if i >= 0: cumul += ais[i][1]
	r = min(r, i+1 + int(math.ceil(max(0,h - cumul) /  float(m))))
print r


Measured memory_bytes: 94516
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(), s.end()
#define rAll(s) s.rbegin(), s.rend()
#define REP(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main(){
    int n, ans = 0;
    cin >> n;
    vi p(n);
    rep(i, n){
        cin >> p[i];
        if(i>=2&&min({p[i-2],p[i-1],p[i]})==min(p[i-2],p[i])&&max({p[i-2],p[i-1],p[i]})==max(p[i-2],p[i]))ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
# 標準入力を取得
N, M = list(map(int, input().split()))
requests = []
for i in range(M):
    a_i, b_i = list(map(int, input().split()))
    requests.append((a_i, b_i))

# 求解処理
requests = sorted(requests, key=lambda x: x[1])
bridge = 0
ans = 0
for i in range(M):
    a_i, b_i = requests[i]
    if a_i > bridge:
        bridge = b_i - 1
        ans += 1

# 結果出力
print(ans)


Measured memory_bytes: 24640
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 998244353
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

#コンビネーション
def cmb(n, r):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % mod

N = 3 * (10 ** 5)  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod // i)) % mod)
    factinv.append((factinv[-1] * inv[-1]) % mod)

n, m, k = MAP()

ans = m * pow(m - 1, n - 1, mod)
ans %= mod
for i in range(1, k + 1):
    #debug(i, tmp, m * pow(m - 1, n - i - 1, mod) * tmp)
    ans += m * pow(m - 1, n - i - 1, mod) * cmb(n - 1, i)
    ans %= mod
print(ans)
#debug(479519525)

Measured memory_bytes: 133568
n = int(input())
d = [int(input()) for _ in range(n)]
d.sort()

flg = 0


for i,j in enumerate(d):
    if i == 0:
        flg += 1
    else:
        if d[i-1] != d[i]:
            flg += 1
        else:
            pass
print(flg)

Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int n;
int x[1050],y[1050];
char ans[1050][35];
int ln[1005],suf[35];
int seq[35],sc;

long long getmanhattan(long long xx,long long yy,long long xxx,long long yyy)
{
	return abs(xx - xxx) + abs(yy - yyy);
}

signed main()
{
	scanf("%d",&n);
	for(int i = 1;i <= n; ++ i) scanf("%d%d",&x[i],&y[i]);
	for(int i = 2;i <= n; ++ i)
		if(abs((x[i] + y[i]) % 2) != abs((x[i - 1] + y[i - 1]) % 2))
		{
			printf("-1\n");
			return 0;
		}
	if((x[1] + y[1]) % 2 == 0)
	{
		seq[++ sc] = 1;
		for(int i = 1;i <= n; ++ i)
		{
			y[i] --;
			ans[i][ln[i] ++] = 'U'; 
		}
	}
	suf[1] = 1;
	for(int i = 2;i <= 31; ++ i)
		suf[i] = suf[i - 1] * 2;
	int st = sc + 1;
	for(int i = 31;i >= 1; -- i)
		seq[++ sc] = suf[i];
	reverse(suf + 1,suf + 1 + 31);
	for(int i = 30;i >= 1; -- i) suf[i] += suf[i + 1];
	for(int p = 1;p <= n; ++ p)
	{
		int curx = 0,cury = 0;
		for(int i = st;i <= sc; ++ i)
		{
			curx += seq[i];
			if(getmanhattan(curx,cury,x[p],y[p]) <= suf[i - st + 2])
			{
				ans[p][ln[p] ++] = 'R';
				continue;
			}
			curx -= 2 * seq[i];
			if(getmanhattan(curx,cury,x[p],y[p]) <= suf[i - st + 2])
			{
				ans[p][ln[p] ++] = 'L';
				continue;
			}
			curx += seq[i];
			cury += seq[i];
			if(getmanhattan(curx,cury,x[p],y[p]) <= suf[i - st + 2])
			{
				ans[p][ln[p] ++] = 'U';
				continue;
			}
			cury -= 2 * seq[i];
			ans[p][ln[p] ++] = 'D';
		}
		if(curx != x[p] || cury != y[p]) printf("FUCK\n");
	}
	printf("%d\n",sc);
	for(int i = 1;i <= sc; ++ i)
		printf("%d ",seq[i]);
	printf("\n");
	for(int i = 1;i <= n; ++ i)
		printf("%s\n",ans[i]);
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t1 = scanner.nextInt();
        int n1 = scanner.nextInt();
        int c1 = 0;
        int t2 = scanner.nextInt();
        int n2 = scanner.nextInt();
        int c2 = 0;
        int t3 = scanner.nextInt();
        int n3 = scanner.nextInt();
        int c3 = 0;
        int t4 = scanner.nextInt();
        int n4 = scanner.nextInt();
        int c4 = 0;
        if (t1 == 1) {
            c1 = 6000 * n1;
        } else if (t1 == 2) {
            c1 = 4000 * n1;
        } else if (t1 == 3) {
            c1 = 3000 * n1;
        } else {
            c1 = 2000 * n1;
        }
        if (t2 == 1) {
            c2 = 6000 * n2;
        } else if (t2 == 2) {
            c2 = 4000 * n2;
        } else if (t2 == 3) {
            c2 = 3000 * n2;
        } else {
            c2 = 2000 * n2;
        }
        if (t3 == 1) {
            c3 = 6000 * n3;
        } else if (t3 == 2) {
            c3 = 4000 * n3;
        } else if (t3 == 3) {
            c3 = 3000 * n3;
        } else {
            c3 = 2000 * n3;
        }
        if (t4 == 1) {
            c4 = 6000 * n4;
        } else if (t4 == 2) {
            c4 = 4000 * n4;
        } else if (t4 == 3) {
            c4 = 3000 * n4;
        } else {
            c4 = 2000 * n4;
        }
        System.out.println(c1);
        System.out.println(c2);
        System.out.println(c3);
        System.out.println(c4);
    }
}


Measured memory_bytes: 26336
import numpy as np
even = np.zeros(100001, dtype=int)
odd = np.zeros(100001, dtype=int)

n = int(input())
v = list(map(int, input().split()))

for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1
    else:
        odd[v[i]] += 1

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)


Measured memory_bytes: 30600
N = int(input())
H = list(map(int, input().split()))
count = 0
answer = 0
for j in range(N-1):
    if H[j+1] <= H[j]:
        count += 1
    else:
        answer = max(count, answer)
        count = 0
answer = max(count, answer)
print(answer)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
    #define debug(...) printf(__VA_ARGS__)
#else
    #define debug(...) (void)0
#endif
#define mp make_pair
#define pb push_back
#define LL long long
#define pii pair<int,int>
#define PII pair<long long, long long>
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
const int inf = 0x7fffffff; //beware overflow
const LL INF = 0x7fffffffffffffff; //beware overflow
#define mem(x, y) memset(x, (y), sizeof(x) );
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
template<typename A, typename B>
ostream& operator <<(ostream &s, const pair<A,B> &p) {
     return s<<"("<<p.first<<","<<p.second<<")";
}
template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c) {
    s << "[ ";
    for (auto it : c) s << it << " ";
    s << "]";
    return s;
}
template<typename T>
ostream& operator << (ostream &o, const set<T> &st) {
    o << "{";
    for (auto it=st.begin(); it!=st.end(); it++) o << (it==st.begin() ? "" : ", ") << *it;
    return o << "}";
}
template<typename T1, typename T2>
ostream& operator << (ostream &o, const map<T1, T2> &mp) {
    o << "{";
    for (auto it=mp.begin(); it!=mp.end(); it++) {
        o << (it==mp.begin()?"":", ") << it->fi << ":" << it->se;
    }
    o << "}";
    return o;
}
#define maxn 100005
int par[maxn], n, k;
bool vis[maxn];
vector<int> G[maxn];
vector<pii> depth;

void dfs(int u, int dep) {
    depth.pb( mp(dep, u) );
    for(int v : G[u] ) {
        dfs(v, dep+1);
    }
}
void mark(int u) {
    vis[u] = true;
    for(int v : G[u] )if(!vis[v]) mark(v);
}
int main() {
    cin>>n>>k;mem(vis, 0);
    for(int i = 0;i < n; i++) {
        int x;scanf("%d", &x);x--;
        par[i] = x;
        if(i) G[ par[i] ].pb( i );
    }
    int ans = ( par[0]!=0 ) ;
    par[0] = 0;
    dfs(0, 0);
    sort(all(depth), greater<pii>());

    for(auto p : depth) if( !vis[p.se] ) {
        if( p.fi <= k) break;
        int dep = 0;
        int cur = p.se;
        if( dep == k-1 && par[cur]!=0) { par[cur] = 0, ans++; mark(cur); continue; }
        while( cur!=0 ) {
            cur = par[cur], dep++;
            if( dep == k-1 && par[cur]!=0) { par[cur] = 0, ans++; mark(cur); break; }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11764
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))
a_all=[]
c=[[""]*W for i in range(H)]

for i in range(N):
    b=[i+1]*a[i]
    a_all.extend(b)

i=0
for j in range(H):
    if j%2==0:
        for k in range(W):
            c[j][k]=str(a_all[i])
            i+=1
    else:
        for k in range(W-1,-1,-1):
            c[j][k]=str(a_all[i])
            i+=1

for i in range(H):
    print(" ".join(c[i]))



Measured memory_bytes: 4084
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 1e5;

int n;
LL aa, bb, hi[maxn+2];

bool check(LL cont) {
	LL rem, tt, cc = cont;
	for(int i = 1; i <= n; ++i) {
		rem = hi[i] - bb * cont;
		if(rem > 0) {
			tt = rem / aa;
			if(tt * aa < rem) ++tt;
			if(cc < tt) return false;
			cc -= tt;
		}
	}
	return true;
}

int main() {
	scanf("%d%lld%lld", &n, &aa, &bb);
	aa = aa - bb;
	for(int i = 1; i <= n; ++i)
		scanf("%lld", hi + i);
	LL ll = 1, rr = 1e9, ans = 1e9;
	while(ll <= rr) {
		LL mid = (ll + rr) >> 1;
		if(check(mid))
			ans = mid, rr = mid - 1;
		else ll = mid + 1;
	}
	printf("%lld\n", ans);
	return 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    map<int, int> cnt;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      ++cnt[a];
    }
    int x = 0;
    each (i, cnt) {
      x += i.second % 2;
    }
    cout << x << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4992
#include<stdio.h>

int main(){

int x[32]={1,2,4};
for(int i=3;i<31;i++)
x[i]=x[i-1]+x[i-2]+x[i-3];

int n;
while(1){
scanf("%d",&n);if(n==0)break;
int d=x[n-1];
int y=d/365/10+1;
printf("%d\n",y);
}
return 0;
}

Measured memory_bytes: 1028
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import math
from bisect import bisect_left

def eratosthenes(limit):
    limit += 10 ** 3
    A = [i for i in range(2, limit + 1)]
    P = []

    for i in range(limit):
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)
        for j in range(limit):
            if j >= len(A):
                break
            if A[j] % prime == 0:
                A.pop(j)
                continue

    for a in A:
        P.append(a)

    return P


x = int(readline())
ans = eratosthenes(x)
print(ans[bisect_left(ans, x)])


Measured memory_bytes: 7088
N=int(input())
A=list(map(int,input().split()))
count=0
for i in range(N):
    minj=i
    for j in range(i+1, N):
        if(A[j] <  A[minj]):
            minj=j

    if(minj !=i):
        tmp=A[i]
        A[i]=A[minj]
        A[minj]=tmp
        count=count+1

print(' '.join([str(a) for a in A]))
print("{}".format(count))



Measured memory_bytes: 5608
#include <iostream> // cin, cout, cerr
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota
#include <cstdio> // printf, scanf
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <iomanip> // cout<<setprecision(n)
#include <functional> // function<void(int)>

#ifdef DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

struct UnionFind
{
  int n;
  std::vector<int> par,size;
  UnionFind(int sz) : n(sz), par(sz,0), size(sz,1) {
    std::iota(par.begin(),par.end(),0);
  }
  int find(int x) {
    if(par[x]==x) return x;
    return par[x] = find(par[x]);
  }
  void unite(int x, int y) {
    x=find(x);y=find(y);
    if(x==y) return;
    if(size[x]<size[y]) std::swap(x,y);
    size[x]+=size[y];
    par[y]=x;
  }
};


signed main() {
	int n,k,l;
	std::cin >> n >> k >> l;
	UnionFind car(n), train(n);
	rep(i,k) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		car.unite(a,b);
	}
	rep(i,l) {
		int a,b;
		std::cin >> a >> b;
		a--;b--;
		train.unite(a,b);
	}
	std::map<std::pair<int,int>, int> map;
	rep(i,n) {
		map[std::make_pair(car.find(i),train.find(i))]++;
	}
	rep(i,n) {
		std::cout << map[std::make_pair(car.find(i),train.find(i))] << ' ';
	}
	std::cout << ENDL;
	return 0;
}


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

using namespace std;

int main() {
  long long N;
  cin >> N;
  vector<long long> A(N);
  vector<long long> sum(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    if (i == 0) {
      sum[0] = A[0];
    } else {
      sum[i] = sum[i-1]+A[i];
    }
  }
  //cout << sum[N-1] << endl;

  vector<long long> F(N);
  long long ix = 0;
  long long ix2 = 2;
  long long mm = 1000000000000;
  for (long long i = 1; i < N-2; i++) {
    for (long long j = ix; j < i; j++) {
      if (abs(sum[j]-(sum[i]-sum[j])) < abs(sum[j+1]-(sum[i]-sum[j+1]))) {
        ix = j;
        break;
      }
    }
    for (long long j = ix2; j < N-1; j++) {
      if (abs(sum[N-1]-sum[j]-(sum[j]-sum[i])) < abs(sum[N-1]-sum[j+1]-(sum[j+1]-sum[i]))) {
        ix2 = j;
        break;
      }
    }
    auto lst = {sum[ix], sum[i]-sum[ix], sum[N-1]-sum[ix2], sum[ix2]-sum[i]};
    long long check = sum[ix] + (sum[i]-sum[ix]) + sum[N-1]-sum[ix2] + sum[ix2]-sum[i];
    //cout << check << endl;
    long long res = max(lst)-min(lst);
    //cout << max(lst)-min(lst) << endl;
    mm = mm > res ? res : mm;
  }
  cout << mm << endl;
  return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    string ans;
    if ((A * B) % 2 == 1) {
        ans = "Yes";
    } else {
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

  vector<vector<int>> a(3, vector<int>(3));
  vector<vector<bool>> chc(3, vector<bool>(3, false));
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < n; ++k) {
        if (a[i][j] == b[k]) {
          chc[i][j] = true;
          break;
        }
      }
    }
  }
  for (int i = 0; i < 3; ++i) {
    if ((chc[i][0] && chc[i][1] && chc[i][2]) ||
        (chc[0][i] && chc[1][i] && chc[2][i])) {
      cout << "Yes" << '\n';
      return 0;
    }
  }
  if ((chc[0][0] && chc[1][1] && chc[2][2]) ||
      (chc[0][2] && chc[1][1] && chc[2][0])) {
    cout << "Yes" << '\n';
    return 0;
  }
  cout << "No" << '\n';

  return 0;
}


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

import numpy as np

n = int(readline())
a = np.array(readline().split(), np.int64)

ai = np.argsort(a)[::-1]
a = a[ai]
ai += 1

dp = np.zeros(n + 1, np.int64)
for k, (i, e) in enumerate(zip(ai, a), 1):
    dp_new = dp.copy()

    add_left = e * abs(np.arange(1, k + 1) - i)
    dp_new[1:k+1] = np.maximum(dp_new[1:k+1], dp[:k] + add_left)

    add_right = e * abs(np.arange(n - k + 1, n + 1) - i)
    dp_new[:k] = np.maximum(dp_new[:k], dp[:k] + add_right)

    dp = dp_new.copy()

ans = max(dp)
print(ans)


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

typedef pair<int,int> pii;
const int N = 1e5;

int par[N+5];

int find_par(int x){
	if(par[x] == x) return x;
	return par[x] = find_par(par[x]);
}

int n,m;
vector<int> adj[N+5];
vector<pii> ans;
vector<int> nadj[N+5];
int deg[N+5];

void dfs(int x, int bef){
	for(int i=0;i<nadj[x].size();i++){
		int now = nadj[x][i];
		if(now == bef) continue;
		dfs(now,x);
	}
	if(bef == -1) return;
	if(deg[x]&1){
		ans.push_back(make_pair(x,bef));
		deg[x]++;
	} else {
		ans.push_back(make_pair(bef,x));
		deg[bef]++;
	}
	return;
}

int main(){
	scanf("%d%d",&n,&m);
	if(m&1){
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n;i++) par[i] = i;
	for(int i=1;i<=m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		int pu = find_par(u);
		int pv = find_par(v);
		if(pu!=pv){
			par[pu] = pv;
			nadj[u].push_back(v);
			nadj[v].push_back(u);
		} else {
			deg[u]++;
			ans.push_back(make_pair(u,v));
		}
	}
	
	dfs(1,-1);
	
	for(int i=1;i<=n;i++){
		if(deg[i]&1){
			printf("-1\n");
			return 0;
		}
	}
	
	for(int i=0;i<ans.size();i++){
		printf("%d %d\n",ans[i].first,ans[i].second);
	}
	
	return 0;
}


Measured memory_bytes: 17524