akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}


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

    int ans = 0;
    rep(i,N){
        int x,y;
        cin >> x >> y;

        double d = sqrt(pow(x,2)+pow(y,2));
        if(d <= D)ans++;
    }

    cout << ans << endl;

}



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

const int N=1e2+5;
typedef long long ll;

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int x[3];
    x[0]=abs(a-b);
    x[1]=abs(a-c);
    x[2]=abs(b-c);
    sort(x,x+3);
    cout << x[0]+x[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
using namespace std;

int main() {
	int n;
	cin >> n;
	bool c[4][13] = { };
	REP(i, n){
		char s;
		int x;
		cin >> s >> x;
		if(s == 'S') c[0][x-1] = true;
		if(s == 'H') c[1][x-1] = true;
		if(s == 'C') c[2][x-1] = true;
		if(s == 'D') c[3][x-1] = true;
	}
	REP(i, 4){
		REP(j, 13){
			if(!c[i][j]){
				if(i == 0) cout << "S " << j+1 << endl;
				if(i == 1) cout << "H " << j+1 << endl;
				if(i == 2) cout << "C " << j+1 << endl;
				if(i == 3) cout << "D " << j+1 << endl;
 			}
		}
	}
	return 0;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());

typedef long long ll;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<int>> maze(h+2,vector<int>(w+2,0));
  int n;
  cin >> n;
  queue<int> q;
  rep(i,n){
    int x;
    cin >> x;
    rep(j,x) q.push(i+1);
  }
  stack<pair<int,int>> s;
  s.push(make_pair(1,1));
  while(!s.empty()){
    int x = s.top().first;
    int y = s.top().second;
    s.pop();
    if(maze[x][y]>0) continue;
    if(x<1 || x>h) continue;
    if(y<1 || y>w) continue;
    maze[x][y] = q.front();
    q.pop();
    if(maze[x][y+1] == 0) s.push(make_pair(x,y+1));
    if(maze[x-1][y] == 0) s.push(make_pair(x-1,y));
    if(maze[x+1][y] == 0) s.push(make_pair(x+1,y));
  }//while
  rep1(i,h){
    rep1(j,w) cout << maze[i][j] << " ";
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
#define MAXN 100000
bool red[MAXN+5];
int count[MAXN+5];
int main(){
    int n,m,cnt=0;
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++) count[i]=1;
    red[1]=1;
    for(int i=1;i<=m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        if(red[a]==1&&count[a]==1){
        	red[a]=0;red[b]=1;
		}else if(red[a]==1) red[b]=1;
        count[a]--;count[b]++;
    }
    for(int i=1;i<=n;i++)
        if(count[i]>0&&red[i]==1)
            cnt++;
    printf("%d",cnt);
}

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

int main(void){
  int H,W;
  for(int c=0;;c++){
    cin >> H >> W;
    if(H+W==0)break;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << '#';
    }
    cout << endl;
  }
  cout << endl;
}

  return 0;
}

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

using namespace std;
template<typename T> void in(T &x) { x = 0; bool neg = false; register T c = getchar(); if (c == '-')neg = true, c = getchar(); while ((c < 48) || (c > 57))c = getchar(); for (; c < 48 || c > 57; c = getchar()); for (; c > 47 && c < 58; c = getchar())x = (x << 3) + (x << 1) + (c & 15); if (neg) x *= -1; }
template<typename T> void out(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); }
template<typename T> void outln(T n) { bool neg = 0; if (n < 0)n *= -1, neg = 1; char snum[65]; int i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); --i; if (neg)putchar('-'); while (i >= 0)putchar(snum[i--]); putchar('\n'); }
#define len(_x) (sizeof((_x)) / sizeof(_x)[0])
#define fastIO ios_base::sync_with_stdio(false); cin.tie(false);
#define ll long long
#define itr(_c) for(auto i=_c.begin();i!=_c.end();i++)
#define itrr(_c)for(auto i=_c.begin();i!=_c.end();i++)
#define f1(_x)for (int i = 0; i < _x; ++i)
#define fr(_x)for (int i = _x; i >0; i--)
#define f2(_x,_y)for (int i = _x; i < _y; ++i)
#define fileIO 	freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
typedef vector<int> vi; typedef vector<string> vs; typedef vector<bool> vb; vector<long long>vll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;

template<typename T>
T gcd(T __m, T __n)
{
	while (__n != 0)
	{
		T __t = __m % __n;
		__m = __n;
		__n = __t;
	}
	return __m;
}
vi v,vv;
int main() {	
	int n, k, t; in(n); in(k);
	f1(n){ in(t); v.push_back(t); }
	int fac=accumulate(v.begin(), v.end(),*v.begin(), gcd<int>);
	int mxele = (*max_element(v.begin(), v.end()) - k);
	std::cout << (mxele<0?"IMPOSSIBLE":mxele%fac==0?"POSSIBLE":"IMPOSSIBLE");
	
}


Measured memory_bytes: 892
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
char st[21000];
int main()
{
	scanf("%s",st);
	for(int i=0;i<strlen(st);i++)
	{
		if(st[i]=='9')
		{
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

int main()
{
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    for (ll i = k; i <= n + 1;i++){
        ll add = i * (2 * n - i + 1) / 2 - i * (i - 1) / 2 + 1;
        ans = (ans + add) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>  
#include <complex>
#include <queue>
#include <set>
#include <unordered_set>
#include <list>
#include <chrono>
#include <random>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <fstream>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<ll> v32;
typedef vector<vector<ll> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 1e9+7;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 1e18
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define vvv64 vector<vv32>
#define vvvv64 vector<vvv32>
void solve()
{
	int n;
	cin>>n;
	v64 arr(n+1);
	int maxi=0;
	for (int i=1; i<=n; i++)
	{
		cin>>arr[i];
		if (arr[i]==maxi+1)
			maxi=arr[i];
	}
	if (maxi==0)
		maxi=n+1;
	cout<<n-maxi<<endl;
}   
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1920
h, w, k = map(int, input().split())
C = []
for i in range(h):
    C.append(input())
ans = 0
for i in range(2**h):
    for j in range(2**w):
        counter = 0
        for m in range(h):
            for n in range(w):
                    if (i>>m)&1 == 0 and (j>>n)&1 == 0 and C[m][n] == '#':
                        counter += 1
                    else:
                        continue
                        
        if counter == k:
            ans += 1
print(ans)

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<string>;
using vb = vector<bool>;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;
using Graph = vector<vector<ll>>;
const ll INF = 1LL << 60;
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
#define tl 1'000'000'007
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REREP(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, n) for (ll i = a; i < n; i++)
#define REFOR(i, n, a) for (ll i = n; i >= a; i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() ) //被り削除
#define debug cout << "line : " << __LINE__ << " debug" << endl;
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ind(...) long double __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << endl;} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#define in1(A) REP(i,A.size()) in(A[i]);
#define in2(A,B) REP(i,A.size()) in(A[i],B[i]);
#define in3(s,t,u) REP(i,sz(s)){in(s[i] , t[i] , u[i]);}
#define in4(s,t,u,v) REP(i,sz(s)){in(s[i] , t[i] , u[i] , v[i]);}
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
struct Point{ ld x,y; };
ld dist(Point a, Point b){return sqrt(abs(a.x-b.x)*abs(a.x-b.x)+abs(a.y-b.y)*abs(a.y-b.y));} // ２点間の距離 
ll gcd(ll a, ll b) { return b != 0 ? gcd(b, a % b) : a; }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b;} 
ll fact(ll n){ if(n < 2) return 1; return (n * fact(n-1))%tl; } //階乗
inline ll updiv(ll a,ll b){ return (a + b - 1) / b; } //切り上げ
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
//-------------------------------------------------------------------------------------------------
int main(){
    init();
    inl(a,b,m);
    vl A(a); in1(A); 
    vl B(b); in1(B);
    ll amin=INF;
    ll bmin= INF;
    ll pos=-1;
    REP(i,a){
        if(amin>A[i]) {
            amin= A[i];
            
        }
    }
    REP(i,b){
        if(bmin>B[i]) {
            bmin= B[i];
            
        }
    }  
    ll mm= amin+bmin;
    REP(i,m){
        inl(x,y,c);
        mm= min(mm,A[x-1]+B[y-1]-c);
    }
    out(mm);
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef long long int64;

int main()
{
	int64 a, b, c, k;
	scanf("%lld %lld %lld %lld", &a, &b, &c, &k);
	int64 d = 0;
	
	if (k > a) 
	{
		d += a * 1;
		k -= a * 1;
	}
	else {
		d += k * 1;
		k -= k * 1;
	}
	if (k <= 0)
	{
		printf("%lld", d);
		exit(0);
	}
	k -= b;
	if (k <= 0) 
	{
		printf("%lld", d);
		exit(0);
	}
	else {
		d -= k * 1;
	}
	printf("%lld", d);

	

	return 0;
}

Measured memory_bytes: 1728
A,B,C,X,Y = list(map(int,input().split()))
max_pizza=max(X,Y)#AピザとBピザのうち、必要な枚数の多い方のピザの枚数
ans=10E+10  

for i in range(0,max_pizza*2+2,2):#ABピザをi枚買う(iは偶数)
    
    if (X-i/2)<=0 and (Y-i/2)>0:
        ans_kouho = B*(Y-i/2)+C*(i)
    elif (X-i/2)>0 and(Y-i/2)<=0:
        ans_kouho = A*(X-i/2)+C*(i)
    elif (X-i/2)<=0 and(Y-i/2)<=0:
         ans_kouho = C*(i)
    else:
        ans_kouho = A*(X-i/2)+B*(Y-i/2)+C*(i)

    
    if(ans_kouho<ans):
        ans = ans_kouho

print(int(ans))



Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	double w, h, x, y, ans1, ans2;
	cin >> w >> h >> x >> y;
	ans1 = w * h / 2;
	if (w * h == x * y * 4) {
		ans2 = 1;
	}
	else {
		ans2 = 0;
	}
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
std::vector<int> list;
int f(int n);

int check(int num){
    for(int i =0; i < list.size(); i++){
        if(list[i] == num){
            return list.size() + 1;
        }
    }
    return -1;
}

int f(int n){
    int static count = 1;
    static int max = 0;
    count++;
    int next = -1;
    // 奇数
    if(n % 2){
        next = 3*n + 1;
    }
    // 偶数
    else{
        next = n/2;
    }

    int c = check(next);
    if(c != -1){
        return c;
    }
    else {
        list.push_back(next);
        return f(next);
    }
}

int main(){
    int a = -1;
    cin >> a;
    list.push_back(a);
    cout << f(a) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		boolean[] indexes = indexesOfPrime(50001);
		int[] values = valuesOfPrime(indexes);

		while (!(line = br.readLine()).equals("0")) {

			int n = Integer.parseInt(line);
			int c = 0;

			for (int v : values) {
				if (v * 2 > n) {
					break;
				}
				if (indexes[v] && indexes[n - v]) {
					c++;
				}
			}
			System.out.println(c);
		}

	}

	static boolean[] indexesOfPrime(int max) {

		boolean[] indexes = new boolean[max + 1];
		Arrays.fill(indexes, true);

		for (int i = 2; i < max + 1; i++) {
			if (indexes[i]) {
				for (int j = 2; j <= max / i; j++) {
					indexes[i * j] = false;
				}
			}
		}

		return indexes;

	}

	static int[] valuesOfPrime(boolean[] indexes) {

		int count = 0;
		for (int i = 2; i < indexes.length; i++) {
			if (indexes[i]) {
				count++;
			}
		}

		int[] values = new int[count];
		int j = 0;
		for (int i = 2; i < indexes.length; i++) {
			if (indexes[i]) {
				values[j] = i;
				j++;
			}
		}

		return values;

	}

}

Measured memory_bytes: 24184
#include<iostream>
using namespace std;
int main(){
  int k,s; cin>>k>>s;
  int x,y,z;
  int i,j;
  int ans=0;
  for(i=0;i<=k;i++){
    x=i;
    for(j=0;j<=k;j++){
      y=j;
      z=s-x-y;
      if(0<=z && z<=k)ans+=1;
    }
  }
  cout<<ans<<endl;
}


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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#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)

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 string YES = "Yes";
const string NO = "No";

void func(std::string S){
    if(S.at(2)==S.at(3) && S.at(4) == S.at(5)){
        cout<<YES<<endl;
    }
    else{
        cout<<NO<<endl;
    }
}

int main(){
    // cout << fixed << setprecision(5);

    std::string S;
    std::cin >> S;
    func(S);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	int a[n+5];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int z=0;
	for(int i=0;i<k;i++)
	{
		z+=a[i];
	}
	cout<<z;
}

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

int main(){
    string s,r;
    cin >> s;
    r = s;
    reverse(r.begin(),r.end());
    int ans=0;
    rep(i,(int)(s.size()/2))if(s.at(i)!=r.at(i))ans++;
    cout << ans << endl;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N,M,S[2020],T[2020];

ll i, j, k,ans;
ll mk[2020],mk2[2020];
int main(){
    scanf("%lld%lld", &N, &M);
    fornum(i,0,N){
        scanf("%lld", &S[i]);
    }
    fornum(i,0,M){
        scanf("%lld", &T[i]);
    }
    mk[M] = 1;
    for (i = N - 1; i >= 0;i--){
        k = 0;
        for (j = M; j >= 0;j--){
            ll a = mk[j];
            if(S[i]==T[j]){
                mk[j] = (mk[j]+k) % MOD;
            }
            k = (a+k)%MOD;
            //printf("%lld ", mk[j]);
        }
        //printf("\n");
    }
    fornum(i,0,M+1){
        ans = (ans + mk[i]) % MOD;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
int main() {
  int N;
  cin >> N;
  vector<string> vec(N);
  int S;
  int ans = 0;
  char C = 'X';
  rep(i, N) {
    cin >> vec.at(i);
    if(i == 0) {
      C = vec.at(i).at(0);
    }
    if(vec.at(i).at(0) != C) {
      ans++;
    }
    S = vec.at(i).size();
    C = vec.at(i).at(S-1);
    rep(j, i) {
      if(vec.at(i) == vec.at(j)) {
        ans++;
        break;
      }
    }
    if(ans > 0) {
      break;
    }
    if(i == N - 1) {
      break;
    }
  }
  if(ans > 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 3636
#include<iostream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

struct square{
    long long x1,y1,z1,x2,y2,z2;
};

vector<square> rippous;
set<long long> xs, ys, zs;
map<long long, long long>transx, transy, transz;
long long field[200][200][200];
long long xx[200], yy[200], zz[200], K, n;
long long res;
int main(){
    cin >> n >> K;
    for(long long i = 0;i < n;i++){
	square tmp;
	cin >> tmp.x1 >> tmp.y1 >> tmp.z1 >> tmp.x2 >> tmp.y2 >> tmp.z2;
	rippous.push_back(tmp);
	xs.insert(tmp.x1);xs.insert(tmp.x2);
	ys.insert(tmp.y1);ys.insert(tmp.y2);
	zs.insert(tmp.z1);zs.insert(tmp.z2);
    }
    set<long long>::iterator it = xs.begin();
    long long ii = 0;
    while(it != xs.end()){
	xx[ii] = *it;
	transx[*it] = ii;
	it++;
	ii++;
    }
    ii = 0;
    it = ys.begin();
    while(it != ys.end()){
	yy[ii] = *it;
	transy[*it] = ii;
	it++;
	ii++;
    }
    ii = 0;
    it = zs.begin();
    while(it != zs.end()){
	zz[ii] = *it;
	transz[*it] = ii;
	it++;
	ii++;
    }
    for(long long i = 0;i < rippous.size();i++){
	square tmp = rippous[i];
	tmp.x1 = transx[tmp.x1];
	tmp.x2 = transx[tmp.x2];
	tmp.y1 = transy[tmp.y1];
	tmp.y2 = transy[tmp.y2];
	tmp.z1 = transz[tmp.z1];
	tmp.z2 = transz[tmp.z2];
	field[tmp.x1][tmp.y1][tmp.z1] ++;
	field[tmp.x2][tmp.y1][tmp.z1] --;
	field[tmp.x1][tmp.y2][tmp.z1] --;
	field[tmp.x2][tmp.y2][tmp.z1] ++;
	field[tmp.x1][tmp.y1][tmp.z2] --;
	field[tmp.x2][tmp.y1][tmp.z2] ++;
	field[tmp.x1][tmp.y2][tmp.z2] ++;
	field[tmp.x2][tmp.y2][tmp.z2] --;
    }
    for(long long i = 1;i < xs.size();i++){
	for(long long j = 0;j < ys.size();j++){
	    for(long long k = 0;k < zs.size();k++){
		field[i][j][k] += field[i - 1][j][k];
	    }
	}
    }
    for(long long i = 0;i < xs.size();i++){
	for(long long j = 1;j < ys.size();j++){
	    for(long long k = 0;k < zs.size();k++){
		field[i][j][k] += field[i][j - 1][k];
	    }
	}
    }
    for(long long i = 0;i < xs.size();i++){
	for(long long j = 0;j < ys.size();j++){
	    for(long long k = 1;k < zs.size();k++){
		field[i][j][k] += field[i][j][k - 1];
	    }
	}
    }
    for(long long i = 0;i < xs.size();i++){
	for(long long j = 0;j < ys.size();j++){
	    for(long long k = 0;k < zs.size();k++){
		if(field[i][j][k] >= K) 
		    res += (xx[i + 1] - xx[i]) * (yy[j + 1] - yy[j]) * (zz[k + 1] - zz[k]);
	    }
	}
    } 
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 33080
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
using Graph = vector<vector<P>>;
const ll INF = 1e18;
int main(){
  int n,m,l;
  cin >> n >> m >> l;
  vector<vector<ll>> d(n,vector<ll>(n,INF));
  rep(i,m) {
    int a,b,c;
    cin >> a >> b >> c;
    --a;--b;
    d[a][b] = c;
    d[b][a] = c;
  }
  for (int i = 0; i < n; i++) d[i][i] = 0;

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n ; j++) {
        d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
      }
    }
  }
  vector<vector<ll>> f(n,vector<ll>(n,INF));

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] <= l) f[i][j] = 1LL;
    }
  }

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n ; j++) {
        f[i][j] = min(f[i][j],f[i][k] + f[k][j]);
      }
    }
  }


  int q;
  cin >> q;
  rep(i,q) {
    int s,t;
    cin >> s >> t;
    --s;--t;
    if (f[s][t] == INF) puts("-1");
    else cout << f[s][t] - 1 << endl;
  }  
  
  return 0;
}

Measured memory_bytes: 1920
import java.util.*;
import java.math.BigDecimal;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        double[] l = new double[n];
        double[] a = new double[n];
        double[] b = new double[n];
        for(int i=0; i<n; i++){
            l[i] = sc.nextDouble();
            a[i] = sc.nextDouble();
            b[i] = sc.nextDouble();
        }

        double[][] dist = new double[n][n];
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                double ll = Math.abs(l[i]-l[j]);
                double aa = Math.abs(a[i]-a[j]);
                double bb = Math.abs(b[i]-b[j]);
                double sum = ll*ll+aa*aa+bb*bb;
                dist[i][j] = sum;
                dist[j][i] = sum;
            }
        }

        double max = 0.0;
        for(int bit=0; bit<1<<n; bit++){
            if(Integer.bitCount(bit)!=m) continue;
            double sum = 0.0;
            for(int i=0; i<n; i++){
                if((bit&(1<<i))>0){
                    for(int j=i+1; j<n; j++){
                        if((bit&(1<<j))>0){
                            sum += dist[i][j];
                        }
                    }
                }
            }
            max = Math.max(max, sum);
        }

        BigDecimal bi = new BigDecimal(String.valueOf(max));
        max = bi.setScale(7, BigDecimal.ROUND_HALF_UP).doubleValue();
        System.out.printf("%.6f\n",max);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 20976
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;

int main()
{
	char num[20];
	int i;
	scanf("%s",num);
	i=strlen(num);
	if(i==2){
		printf("%s",num);
		}
	else{
	for(i=strlen(num)-1;i>=0;i--)
	printf("%c",num[i]);
	}
}

Measured memory_bytes: 128
#include <cstring>
#include <algorithm>
#include <cctype>
#include <cstdio>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 2e5+5;
int n, p[N], ans = 2;
bool valid(int mid)
{   
    for(int i = 0; i < n-1; ++i)
        if(max(p[n-i], p[n-i-1]) <= mid||max(p[n+i], p[n+i+1]) <= mid) return true;
        else if(min(p[n-i], p[n-i-1]) > mid||min(p[n+i], p[n+i+1]) > mid) return false;
    return p[1] <= mid;
}
int main()
{
    n = read();
    for(int i = 2*n-1; i; --i) p[i] = read();
    int l = 2, r = 2*n-2;
    while(l <= r)
    {
        int mid = (l+r)>>1;
        if(valid(mid)) r = mid-1, ans = mid;
        else l = mid+1;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 896
n,m=map(int,input().split())
import math 
mod=10**9+7
if n==m:
    x=math.factorial(n)
    x=x%mod
    x=x**2
    x%=mod
    x*=2
    x%=mod
    print(x)
elif abs(n-m)==1:
    x=min(n,m)
    y=max(n,m)
    ans=math.factorial(x)%mod
    ans*=ans
    ans%=mod
    ans=ans*y
    ans%=mod
    print(ans)
else:
    print(0)

Measured memory_bytes: 4100
''' Hey stalker :) '''
INF = 10**10
def main():
    print = out.append
    ''' Cook your dish here! '''
    k, a, b = get_list()
    if 2+a>b or k<a:
        print(k+1)
    else:
        k -= a-1
        bis = a + (k//2)*(b-a) + k%2
        print(bis)



''' Pythonista fLite 1.1 '''
import sys
from collections import defaultdict, Counter
from bisect import bisect_left, bisect_right
#from functools import reduce
import math
#input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


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

/*
提出前に確認!
- setとmultisetを間違えない
*/

/*
N/(26^k)が欲しい
たかだか12個
*/

int	main(void)
{
	long long n;
	cin >> n;
	string ans = "";
	for (int i = 0; i < 13; i++)
	{
		if (!n) break;
		ans += char((n % 26 - 1 + 26) % 26 + 'a');
		n -= (n % 26 - 1 + 26) % 26;
		n /= 26;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return (0);
}

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

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

ll N;
ll A[100005], B[100005], C[100005];

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

	cin >> N;

	for (int i = 0;i < N;i++){
		cin >> A[i];
	}
	for (int i = 0;i < N;i++){
		cin >> B[i];
	}
	for (int i = 0;i < N;i++){
		cin >> C[i];
	}

	sort(A,A+N); sort(C,C+N);

	ll ans = 0;

	for (int i = 0;i < N;i++){
		ll nA = lower_bound(A,A+N,B[i])-A;
		ll nC = C+N-upper_bound(C,C+N,B[i]);
		ans += nA*nC;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 2560
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int stack[100];
int count=0;

int pop()
{
  count--;
  return stack[count];
}

void push(int n)
{
  stack[count]=n;
  count++;
}

int main(void){
  int x,n,m;
  char s[100];
  
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      n=pop();
      m=pop();
      push(n+m);
    } else if ( s[0] == '-' ){
      n=pop();
      m=pop();
      push(m-n);
    } else if ( s[0] == '*' ){
      n=pop();
      m=pop();
      push(n*m);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",stack[count-1]);
  return 0;
}

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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int k;
int n;
int a[200005];
void solve() {
    cin >> k >> n;
    rep(i, n) cin >> a[i];
    int ans = k;
    a[n] = a[0] + k;
    rep(i, n) mins(ans, k - (a[i + 1] - a[i]));
    cout << ans << endl;
}

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


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

using namespace std;

#define mp make_pair
#define fi first
#define se second

map<pair<char, int>, int> GetNum;
map<char, int> GetLen;
typedef string::const_iterator State;
int Error;

int number(State &begin);
int term2(State &begin);

int factor(State &begin) {
  if (isdigit(*begin)) {
    return number(begin);
  } else {
    return term2(begin);
  }
}

int number(State &begin) {
  int ret = 0;
  while (isdigit(*begin)) {
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

pair<char, int> term1(State &begin) {
  char name;
  int idx = -1;
  for (;;) {
    if (('a' <= *begin && *begin <= 'z') || ('A' <= *begin && *begin <= 'Z')) {
      name = *begin;
      begin += 2;
      idx = factor(begin);
      begin++;
    } else {
      break;
    }
  }
  if (idx == -1) {
    Error = 1;
  }
  return mp(name, idx);
}

int term2(State &begin) {
  char name;
  int idx = -1;
  for (;;) {
    if (('a' <= *begin && *begin <= 'z') || ('A' <= *begin && *begin <= 'Z')) {
      name = *begin;
      begin += 2;
      idx = factor(begin);
      begin++;
    } else if (isdigit(*begin)) {
      return number(begin);
    } else {
      break;
    }
  }
  if (GetNum.count(mp(name, idx)) > 0) {
    return GetNum[mp(name, idx)];
  } else {
    Error = 1;
    return -1;
  }
}

pair<pair<char, int>, int> expression(State &begin) {
  pair<char, int> ret1 = term1(begin);
  int ret2 = -1;
  for (;;) {
    if (*begin == '=') {
      ret2 = term2(++begin);
    } else {
      break;
    }
  }
  return mp(ret1, ret2);
}

bool solve() {
  string s;
  getline(cin, s);
  if (s == ".") {
    return false;
  }
  Error = 0;
  GetNum.clear();
  GetLen.clear();
  int cnt = 1;
  bool ng = false;
  while (s != ".") {
    if (ng) {
      getline(cin, s);
      cnt++;
      continue;
    }
    State begin = s.begin();
    pair<pair<char, int>, int> now = expression(begin);
    if (Error == 1) {
      cout << cnt << endl;
      ng = true;
    }
    if (now.se == -1) {
      GetLen[now.fi.fi] = now.fi.se;
    } else {
      if (GetLen[now.fi.fi] > now.fi.se) {
        GetNum[now.fi] = now.se;
      } else {
        Error = 1;
        cout << cnt << endl;
        ng = true;
      }
    }
    getline(cin, s);
    cnt++;
  }
  if (Error == 0) {
    cout << 0 << endl;
  }
  return true;
}

int main()
{
  while (solve());
}


Measured memory_bytes: 3184
H, W, a, b = map(int, input().split())

if H%a or W%b:
    print('Yes')
    k = (H//a) * (W//b)
    x = k+2
    ansss = [[0]*(W) for _ in range(H)]
    for i in range(H//a):
        for j in range(W//b):
            ansss[(i+1)*a-1][(j+1)*b-1] = -x
    for i in range(-(-H//a)):
        for j in range(-(-W//b)):
            ansss[i*a][j*b] = x-1
    print('\n'.join([' '.join(map(str, anss)) for anss in ansss]))
else:
    print('No')


Measured memory_bytes: 18560
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 1e5 + 5;
int deg[N];
    
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n, m;
  cin>>n>>m;
  RE (i, 2 * m) {
    int a;
    cin>>a;
    deg[a]++;
  }
  RE (i, n) {
    if (deg[i] % 2) {
      cout<<"NO\n";
      return 0;
    }
  }
  cout<<"YES"<<endl;

  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
#define MOD 1000000007
typedef long long ll;

using namespace std;

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

  cout << x * x * x << "\n";

  return(0);
}



Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#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>;
using vi = vector<int> ;
using vl = vector<ll>;

int main(){
    int x;
    cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 3592
def test():
    n = int(input())
    a = list(map(int,input().split()))
    b = [a[0]]
    count = 1
    for i in range(1,n):
        for j in range(i):
            b.append(a[j])
        if all(x <= a[i] for x in b):
            count += 1

    print(count)


if __name__ == "__main__":
    test()


Measured memory_bytes: 3060
/*
    Problem 5
    https://atcoder.jp/contests/abc095/tasks/arc096_a
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans = INF;
    for (int i = 0; i <= max(x, y); i++) {
        // 全探索
        // 2 * i枚 C-pizza
        // x - i枚 A-pizza
        // y - i枚 B-pizza
        int sum = 2 * i * c + max(0, x - i) * a + max(0, y - i) * b;
        ans = min(ans, sum);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
const int MAX_N = 1000000;
int prime[MAX_N];
bool is_prime[MAX_N + 1];
int eratos(int n)
{
	int p = 0;
	for (int i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= n; i++)
	{
		if(is_prime[i])
		{
			prime[p++] = i;
			for (int j = 2*i; j <= n; j += i) is_prime[j] = false; 
		}
	}
	return p;
}

int main()
{
	int n;
	while (cin >> n && n)
	{
		cout << eratos(n) << endl;
	}
	return 0;
}

Measured memory_bytes: 2448
#include <stdio.h>

int N;
int a[271828];

int main(void) {
	int i;
	int zenbu = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		if (scanf("%d", &a[i]) != 1) return 1;
		zenbu ^= a[i];
	}
	for (i = 0; i < N; i++) {
		printf(" %d" + (i == 0), zenbu ^ a[i]);
	}
	putchar('\n');
	return 0;
}

/*

※以下、「+」はxorを表す

a b c d

  b+c+d
a  +c+d
a+b  +d
a+b+c

全部xorするとa+b+c+d

*/


Measured memory_bytes: 3212
<?php
$input = STDIN;

$N = trim(fgets($input));

$seq = explode(' ', trim(fgets($input)));

// Selection Sort
$cnt = 0;
for ($i = 0; $i < $N; $i++) {
    $mini = $i;
    for ($j = $i; $j < $N; $j++) {
        if ($seq[$j] < $seq[$mini]) {
            $mini = $j;
        }
    }
    list($seq[$i], $seq[$mini]) = array($seq[$mini], $seq[$i]);
    if ($i != $mini) {
        $cnt++;
    }
}

print implode(' ', $seq) . "\n";
print $cnt . "\n";


Measured memory_bytes: 9264
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            long K = sc.nextLong();
            Set<Long> sunekeSet = new LinkedHashSet<>();
            for (long m =1; m <=10e15; m*=10){
                boolean sunukeCheckFlag = true;
                for(int i = 1; sunukeCheckFlag; i++){
                    long x = i * m + m - 1;
                    long y = (i + 1) * m + m - 1;
                    if (x * Sn(y) <=  y * Sn(x)){
                        sunekeSet.add(x);
                        if (K == sunekeSet.size()){
                            sunekeSet.stream().forEach(System.out::println);
                            return ;
                        }
                    }else{
                        sunukeCheckFlag = false;

                    }
                }
            }
        }
        public static long Sn(long num){
            long Sn = 0;
            while (num != 0){
                Sn += num % 10;
                num /= 10;
            }
            return Sn;
        }
}


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

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

    string s;
    cin >> s;
    int n = s.size();
 
    ll ans = 0;
    
    vector<ll> mods(2019, 0);

    ll cur = 0, coef = 1;
    mods[cur]++;
    rep(i, n) {
        cur = (cur + coef * (s[n - i - 1] - '0') % 2019) % 2019;
        coef = coef * 10 % 2019;
        mods[cur]++;
    }

    rep(i, 2019) {
        ans += mods[i] * (mods[i] - 1) / 2;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
using namespace std;
int main()
{
    #ifdef TarekHasan
        freopen("input.txt","r",stdin);
    #endif // TarekHasan
    int n; cin >> n;
    vector< int > v(n);
    long long int ans = 0;
    for(int i=0;i<n;i++)
    {
        cin >> v[i];
        if(i)
        {
            if(v[i]<v[i-1])
            {
                ans+=abs(v[i]-v[i-1]);
                v[i]=v[i-1];
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3956
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=998244353 ;

ll powmod(ll n,ll k){
    ll ret =1;
    while(k>0){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}

ll fact[5020];
ll invfact[5020];

ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    ll ret=invfact[k]*invfact[n-k]%mod;
    return ret*fact[n]%mod;
}

int main(){
    fact[0]=invfact[0]=1;
    rep(i,5000){
        fact[i+1]=fact[i]*(i+1)%mod;
        invfact[i+1]=powmod(fact[i+1],mod-2);
    }
    int k,n;cin>>k>>n;
    rep(i,2*k-1){
        int sum=i+2;
        if(sum%2){
            int cnt=min((sum-1)/2,(2*k-sum+1)/2);
            ll ret=0;
            ll pos=k-cnt;
            rep(j,cnt+1){
                if(j%2)ret+=mod-(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-1+pos,pos-1)%mod;
                else ret+=(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-1+pos,pos-1)%mod;
                ret%=mod;
                pos--;
            }
            cout<<ret<<endl;
        }
        else{
            int cnt=min(sum/2,(2*k-sum+2)/2);
            ll ret=0;
            ll pos=k-cnt;
            ll pos2=pos;
            cnt--;
            rep(j,cnt+1){
                if(j%2)ret+=mod-(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-1+pos,pos-1)%mod;
                else ret+=(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-1+pos,pos-1)%mod;
                ret%=mod;
                pos--;
            }
            pos=pos2;
            rep(j,cnt+1){
                if(j%2)ret+=mod-(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-2+pos,pos-1)%mod;
                else ret+=(powmod(2,cnt-j)*comb(cnt,j)%mod)*comb(n-2+pos,pos-1)%mod;
                ret%=mod;
                pos--;
            }
            cout<<ret<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;

int main()
{

	ios_base:: sync_with_stdio(false); cin.tie(0);
	int r,g,b,n; cin>>r>>g>>b>>n;
	ll cnt=0;
	for(int R=0; R<=n/r+1; R++) {
		for(int G=0; G<=n/g+1; G++) {
			int lol=n-R*r-G*g;
			if(lol>=0&&lol%b==0) {
				cnt++;
			}
		}
	}

	cout<<cnt<<endl;


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep(i,sz(s)) {
    if(s[i]=='+') ans++;
    else ans--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int h,w,ch,cw,dh,dw;
string s[1000];
const int dx[]={-1,1,0,0};
const int dy[]={0,0,-1,1};

vector<ll> dijkstra(const vector<vector<pair<int,int>>>& graph,int s){
    int n=(int)graph.size();
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
    vector<ll> dist(n,linf);
    dist[s]=0;
    pq.push({0,s});
    while(pq.size()){
        auto p=pq.top();
        pq.pop();
        int v=p.second;
        if(dist[v]<p.first)continue;
        for(auto edge:graph[v]){
            int u=edge.first;
            int w=edge.second;
            if(dist[v]+w<dist[u]){
                dist[u]=dist[v]+w;
                pq.push({dist[u],u});
            }
        }
    }
    return dist;
}

int main(){
    cin>>h>>w>>ch>>cw>>dh>>dw;
    --ch;--cw;--dh;--dw;
    rep(i,h)cin>>s[i];
    vector<vector<pair<int,int>>> g(h*w);
    rep(x,h){
        rep(y,w){
            if(s[x][y]=='#')continue;
            int f=x*w+y;
            for(int i=0;i<4;++i){
                int nx=x+dx[i];
                int ny=y+dy[i];
                int t=nx*w+ny;
                if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
                g[f].push_back({t,0});
                g[t].push_back({f,0});
            }
            for(int i=-2;i<=2;++i){
                int nx=x+i;
                for(int j=-2;j<=2;++j){
                    int ny=y+j;
                    int t=nx*w+ny;
                    if(nx<0||h<=nx||ny<0||w<=ny||s[nx][ny]=='#')continue;
                    g[f].push_back({t,1});
                    g[t].push_back({f,1});
                }
            }
        }
    }
    vector<ll> d=dijkstra(g,ch*w+cw);
    rep(i,h){
        rep(j,w){
            if(d[i*w+j]==linf)d[i*w+j]=-1;
        }
    }
    cout<<d[dh*w+dw]<<endl;
}


Measured memory_bytes: 206792
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;
const ll INF = 2e9 + 10;
const ll MAX = 1e14 + 10;
const ld EPS = 1e-9;
const int N = 3e3 + 10;

int d[N][N];

void solve() {
    string s, t;
    cin >> s >> t;
    frab(i, 1, 1 + s.size())
        frab(j, 1, 1 + t.size()) {
            d[i][j] = max(d[i][j - 1], d[i - 1][j]);
            if (s[i - 1] == t[j - 1])
                d[i][j] = d[i - 1][j - 1] + 1;
        }
    int x = s.size(), y = t.size();
    string ans;
    while (x && y) {
       // cout << x << " " << y << endl;
        if (d[x - 1][y - 1] == d[x][y] - 1 && s[x - 1] == t[y - 1]) {
            ans += s[x - 1];
            x--, y--;
            continue;
        }
        if (d[x - 1][y] == d[x][y])
            x--;
        else
            y--;
    }
    reverse(ans.begin(), ans.end());
    cout << ans;
}



int main() {
    //freopen("a.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 35584