akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc =new Scanner(System.in)){
            int w=sc.nextInt();
            int n =sc.nextInt();
            int[] values = new int[w];
            for(int i=0;i<values.length;i++){
                values[i]=i+1;
            }
            for(int i=0;i<n;i++){
                String str =sc.next();
                String[] ab =str.split(",");
                int a=Integer.parseInt(ab[0])-1;
                int b=Integer.parseInt(ab[1])-1;
                int save =values[a];
                values[a]=values[b];
                values[b]=save;
            }
            for(int i=0;i<values.length;i++){
            System.out.println(values[i]);
            }
        }
    }
}


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

void solve()
{
    long long int N, W, i, j;
    cin>>N>>W;
    vector<long int> v(N+1), w(N+1);
    for(i=1;i<=N;i++) {
        cin>>w[i]>>v[i];
    }
    vector<vector<long long int>> dp(N+1, vector<long long int>(W+1, 0));
    for(i=1;i<=N;i++) {
        for(j=1;j<=W;j++) {
            if(w[i] > j)
                dp[i][j] = dp[i-1][j];
            else
                dp[i][j] = max({dp[i-1][j], v[i] + dp[i-1][j-w[i]]});
        }
    }
    cout<<dp[N][W];
}

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

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

ll c[51][51];

void comb_table(int n){
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= i; j++){
            if(i == j || j == 0) c[i][j] = 1LL;
            else c[i][j] = c[i-1][j-1] + c[i-1][j];
        }
    }
    return;
}

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    ll v[n];
    map<ll, int> mp;
    rep(i, n){
        cin >> v[i];
        mp[v[i]]++;
    }
    sort(v, v + n);
    reverse(v, v + n);

    comb_table(n);

    double max_av = 0.0;
    int cnt = 0;
    rep(i, a){
        max_av += v[i];
        if(v[i] == v[a-1]) cnt++;
    }
    max_av /= a;

    ll pat = 0LL;
    if(cnt == a){
        for(int i = a; i <= min(b, mp[v[a-1]]); i++){
            pat += c[mp[v[a-1]]][i];
        }
    } else {
        pat += c[mp[v[a-1]]][cnt];
    }

    //cout.precision(6);
    //cout << fixed << max_av << endl;
    //cout << max_av << endl;
    printf("%.6f\n", max_av);
    cout << pat << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll MOD = 1000000007;
const double PI = 3.141592653589793238463;
const ll N=2e5+9;
int main()
{
    FASTINOUT;
    int x,m;
    cin>>x>>m;
    map<int,int>mp;
    int l,r;
    vector<int>ans(x,0);
    bool b=true;
    for (int i=0; i<m; i++)
    {
        cin>>l>>r;
        l--;
        if (mp.find(l)!=mp.end())
        {
            if (mp[l]!=r)
            {
                b=false;
                cout<<-1<<endl;
                return 0;
            }
        }
        else
        {
            if (l==0&&r==0&&x>1)
            {
                cout<<-1<<endl;
                return 0;
            }
            mp[l]=r;
            ans[l]=r;
        }
    }
    if (ans[0]==0&&x>1)
        ans[0]=1;
    for (int i=0; i<x; i++)
        cout<<ans[i];
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {
  int h, w;
  while (std::cin >> h >> w, h | w) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        std::cout << "#";
      }
      std::cout << "\n";
    }
    std::cout << std::endl;
  }
}


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define quicker ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;

int main()
{
    quicker
    #ifdef HALO
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int t, n, maxi = -1;
    cin >> t >> n;
    int A[n + 1];
    for (int i = 0; i < n; i++)
      cin >> A[i];
    sort(A, A + n);
    maxi =  abs(A[0]) + abs(t - A[n - 1]);
    // for (int i = 0; i <= n; i++)
    // cout << A[i] << " ";
    for (int i = 0; i < n - 1; i++)
      maxi = max(maxi , abs(A[i + 1] - A[i]));
    cout << (t - maxi);
  }

Measured memory_bytes: 1024
n = int(input())
g = [[-1] * n for _ in range(n)]
for i in range(n):
	a = int(input())
	for _ in range(a):
		x, y = map(int, input().split())
		g[i][x - 1] = y
ans = 0
for m in range(2 ** n):
	f = 1
	for i in range(n):
		for j in range(n):
			if g[i][j] < 0:
				continue
			if (1 << i) & m:
				if g[i][j] != int((1 << j) & m > 0):
					f = 0
					break
	if f:
		ans = max(ans, bin(m).count("1"))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>
using namespace std ;
int main(){
    int n;
    cin >> n;
    int num;
    vector<int> a;
    int i, j;
    int ans = 1000000;
    int sum = 0;
    
    for(i = 0; i < n; i++){
        cin >> num;
        a.push_back(num);
    }
for(i = -100; i <= 100; i++){
        sum = 0;
        for(j = 0; j < n; j++){
            sum += (a[j] - i) * (a[j] - i);
        }
        if(ans > sum){
            ans = sum;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define show(x) cout << #x << " " << x << endl;
#define mid ((s + e) / 2)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>

const int N = 1e5 + 7;

#define int long long

int x[N], d[N], a[N], p[N], nd[N];
int n, m, k;
bool mrk[N];
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x[i];
		p[i] = i;
		d[i - 1] = x[i] - x[i - 1];
	}
	cin >> m >> k;
	for (int i = 1; i <= m; i++) {
		cin >> a[i];
		swap(p[a[i]], p[a[i] - 1]);
	}
	for (int i = 1; i <= n; i++)
	   if (!mrk[i]) {
	   		vector <int> v;
			int t = i;
			int sv = i;
			do {
				v.push_back(t);
				mrk[t] = 1;
				t = p[t];
			} while (sv != t);
			for (int j = 0; j < v.size(); j++) {
				nd[v[j]] = d[v[(j + k) % v.size()]];
			}
	   }	   
	cout << x[1] << ".0" << '\n';
	for (int i = 2; i <= n; i++) {
		x[i] = x[i - 1] + nd[i - 1];
		cout << x[i] << ".0" << '\n';
	}




}


Measured memory_bytes: 5604
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	int N,M;
	Edge[] edges;
	long[] costs;

	private class Edge{
		int from,to;
		long cost;
		public Edge(int from,int to,long cost){
			this.from = from;
			this.to = to;
			this.cost = cost;
		}
	}

	public long bellman_ford(){
		for(int i = 0;i < N;i++){
			for(int j = 0;j < M;j++){
				Edge e = edges[j];
				if(costs[e.to] > costs[e.from]+e.cost){
					costs[e.to] = costs[e.from]+e.cost;
				}

			}
		}
		return costs[N-1];
	}

	public void solve() {
		N = nextInt();
		M = nextInt();

		edges = new Edge[M];

		for(int i = 0;i < M;i++){
			int a = nextInt()-1;
			int b = nextInt()-1;
			int c = nextInt();
			edges[i] = new Edge(a,b,-c);
		}
		costs = new long[N];
		Arrays.fill(costs,Long.MAX_VALUE/2);
		costs[0] = 0;
		long ans1 = bellman_ford();
		long ans2 = bellman_ford();

		if(ans1 != ans2)out.println("inf");
		else out.println(-ans1);
	}

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

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

	public int nextInt() {
		return Integer.parseInt(next());
	}

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 24760
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <cstring> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int main()
{
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int key[200];
		char s[200], right_s[200], ch;
		for(int i = 0; i < n; i++){
			cin >> key[i];
		}
		ch = getchar();
		fgets(s, sizeof(s), stdin);
		int wronglist[200]={0}, rightlist[200];
		for(int i = 0; i < strlen(s)-1; i++){
			wronglist[i] = s[i] - 'A';
			if(wronglist[i] > 25) wronglist[i] -= 6;
			rightlist[i] = wronglist[i] - key[i%n];
			if(rightlist[i] < 0) rightlist[i] = 52 + rightlist[i];
			if(rightlist[i] > 25) rightlist[i] += 6;
			right_s[i] = rightlist[i] + 'A';
		}
		right_s[strlen(s)-1] = '\0';
		cout << right_s << endl;
	}
	return 0;
}

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

int main(){
  int s;
  cin >> s;
  int a, b, c, d;
  a=s/100;
  b=s%100;

  if((a==0||a>12)&&b<13&&b!=0)
   cout << "YYMM" << endl;
  else if((b==0||b>12)&&a<13&&a!=0)
    cout << "MMYY" << endl;
  else if((a!=0&&a<13)||(b!=0&&b<13))
    cout << "AMBIGUOUS" << endl;
  else
    cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int H, W;
	while (1) {
		cin >> H >> W;
		if (H == 0 && W == 0)break;
		for (int i = 0; i < H; i++) {
			if (i != 0 && i != H - 1) {
				for (int j = 0; j < W; j++) {
					if (j == W - 1) {
						cout << "#" << endl;
					}
					else if(j == 0){
						cout << "#";
					}
					else {
						cout << ".";
					}
				}
			}
			else {
				for (int j = 0; j < W; j++) {
					if (j == W - 1) {
						cout << "#" << endl;
					}
					else {
						cout << "#";
					}
				}
			}
		}
		cout << "" << endl;
	}
}

Measured memory_bytes: 1152
import sys
import math
sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

A, B = map(int, input().split())

ans = -1
for i in range(1, 1263):
    if math.floor(i * 0.08) == A and math.floor(i * 0.1) == B:
        ans = i
        break

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll int
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll maxn=1e5+1050;
const ll mod=1e9+7;
const ll inf=1e9+5;

vector<pii> yal;
ll cn=2;
ll rot=1;

void add(ll i){
    yal.pb({cn,rot});
    rot=cn;
    cn++;
    while(cn<=i){
        yal.pb({cn,rot});
        cn++;
    }
}
int main(){
   string s;
   cin>>s;
   s='0'+s;
   ll n=s.size()-1;
   if(s[n]=='1' || s[1]=='0'){
        cout<<-1;
        return 0;
   }

   for(ll i=0;i<=n;i++){
        if(s[i]!=s[n-i]){
            cout<<-1;
            return 0;
        }
   }
   for(ll i=2;2*i<=n;i++){
        if(s[i]=='1'){
            add(i);
        }
   }
   add(n);
   for(auto v:yal){
        cout<<v.F<<' '<<v.S<<endl;
   }
}


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

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

const int mod = 1000000007;
const int inf = 1000000007;

int main() {
  ll a;
  double b;
  cin >> a >> b;
  ll b2 = b * 100 + 0.5;
  //cout << b2 << endl;
  ll ans = a * b2;
  ans /= 100;
  cout << ans << endl;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> v;
pair<int,int> p;
map<int,int> m;
deque<int> d;
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int x[9]={111,222,333,444,555,666,777,888,999};
for(int i=0;i<9;i++)
    if(x[i]>=n){
        cout<<x[i]<<endl;
        break;}
return 0;
}


Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String s = br.readLine();
		int n = Integer.parseInt(s);

		int x = n * 800;
		int y = (n / 15) * 200;

		System.out.println(x - y);

	}
}


Measured memory_bytes: 21204
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int64 INF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  vector<int64> a(n + 1);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[i + 1] = a[i] + x;
  }
  int64 ret = INF;
  vector<int64> A(4);
  for (int k = 2; k <= n - 2; ++k) {
    int64 L = a[k] - a[0];
    int u = lower_bound(a.begin(), a.begin() + k, L / 2) - a.begin();
    int64 best = INF;
    int best_u = -1;
    if (u > 0 && u < k) {
      if (best > abs((a[k] - a[u]) - a[u])) {
        best = abs((a[k] - a[u]) - a[u]);
        best_u = u;
      }
    }
    --u;
    if (u > 0 && u < k) {
      if (best > abs((a[k] - a[u]) - a[u])) {
        best = abs((a[k] - a[u]) - a[u]);
        best_u = u;
      }
    }
    int64 R = a[n] - a[k];
    int v = lower_bound(a.begin() + k, a.end(), R / 2 + a[k]) - a.begin();
    best = INF;
    int best_v = -1;
    if (v > k && v < n) {
      if (best > abs((a[n] - a[v]) - (a[v] - a[k]))) {
        best = abs((a[n] - a[v]) - (a[v] - a[k]));
        best_v = v;
      }
    }
    --v;
    if (v > k && v < n) {
      if (best > abs((a[n] - a[v]) - (a[v] - a[k]))) {
        best = abs((a[n] - a[v]) - (a[v] - a[k]));
        best_v = v;
      }
    }
    A[0] = a[best_u]; A[1] = a[k] - a[best_u];
    A[2] = a[best_v] - a[k]; A[3] = a[n] - a[best_v];
    sort(A.begin(), A.end());
    ret = min(ret, A.back() - *A.begin());
  }
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

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

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    ll x;
    cin >> x;

    ll fh=x/500;
    ll nx=x-fh*500;
    ll f=nx/5;

    cout << fh*1000+f*5 << endl;

    return 0;
}


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

int main(){
    int a, b, c;
    cin >> c;
    a = c / 100;
    b = c % 100;

    if((a == 0 && b >= 13) || (b == 0 && a >= 13) || (a >= 13 && b >= 13) || (a == 0 && b == 0)){
        cout << "NA" << endl;
    }else if(a >= 13 || a == 0){
        cout << "YYMM" << endl;
    }else if(b >= 13 || b == 0){
        cout << "MMYY" << endl;
    }else{
        cout << "AMBIGUOUS" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import numpy as np

all_tree, sel_tree = map(int, input().split())
tree = []
for i in range(all_tree):
    tree.append(int(input()))

tree = np.array(tree)
tree = np.sort(tree)

highest = 10 ** 9
for begin in range(all_tree - sel_tree + 1):
    
    end = begin + sel_tree - 1
    diff = tree[end] - tree[begin]
    highest = min(highest, diff)
    #print(begin, end, highest, diff, tree[end], tree[begin])
    
print(highest)

Measured memory_bytes: 17072
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 H, W;
  cin >> H >> W;
  vector<string> s(H);
  for (i64 i = 0; i < H; i++)
    cin >> s[i];
  vector<vector<i64>> far(H, vector<i64>(W));
  far[0][0] = (s[0][0] == '#');
  for (i64 i = 1; i < W; i++)
    far[0][i] = far[0][i - 1] + (s[0][i - 1] == '.' && s[0][i] == '#');
  for (i64 i = 1; i < H; i++)
  {
    far[i][0] = far[i - 1][0] + (s[i - 1][0] == '.' && s[i][0] == '#');
    for (i64 j = 1; j < W; j++)
      far[i][j] = min(far[i - 1][j] + (s[i - 1][j] == '.' && s[i][j] == '#'), far[i][j - 1] + (s[i][j - 1] == '.' && s[i][j] == '#'));
  }
  cout << far[H - 1][W - 1] << endl;
  return 0;
}


Measured memory_bytes: 384
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b << " " << c;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long n,a[200005],qs[200005],mn=1e18;
vector<long long> v;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		v.push_back(a[i]-i);
	}
	v.push_back(-1e18);
	sort(v.begin(),v.end());
	for(int i=1;i<=n;i++)
	{
		qs[i]=qs[i-1]+v[i];
	}
	for(int i=1;i<=n;i++)
	{
		mn=min(mn,i*v[i]-qs[i]+qs[n]-qs[i]-(n-i)*v[i]);
	}
	printf("%lld",mn);
}

Measured memory_bytes: 7968
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

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

template<typename T>
struct KMP {
    int n;
    T t;
    vector<int> a;
    KMP() {}
    KMP(const T& t) : t(t) {
        n = t.size();
        a = vector<int>(n + 1);
        a[0] = -1;
        int j = -1;
        for (int i = 0; i < n; ++i) {
            while (j != -1 && t[j] != t[i]) j = a[j];
            j++;
            if (t[i + 1] == t[j]) a[i + 1] = a[j];
            else a[i + 1] = j;
        }
    }
    int operator[](int i) { return a[i]; }
    vector<int> findAll(const T& s) {
        vector<int> res;
        int j = 0;
        for (int i = 0; i < s.size(); ++i) {
            while (j != -1 && t[j] != s[i]) j = a[j];
            j++;
            if (j == n) {
                res.push_back(i - j + 1);
                j = a[j];
            }
        }
        return res;
    }
};

int main()
{
	
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	
    string s, t; cin >> s >> t;
    KMP<string> kmp(t);

    vector<int> res = kmp.findAll(s);

    for (ll i = 0; i < res.size(); i++) {
        cout << res[i] << "\n";
    }
	return 0;
}



Measured memory_bytes: 8804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
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 string dir = "DRUL";
*/


int main() {
    ll X;
    cin >> X;
    ll ans = 1;
    for(ll i = 2; i <= X; i++){
        ll rui = i;
        while(rui * i <= X){
            rui *= i;
            chmax(ans, rui);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3552
/*
 * author :Sadik Hassan(_sad_)
 *
*/
#include "bits/stdc++.h"
using namespace std;
using   ll =          long long;
using   ld =          long double;
#define nl            "\n"
#define pb            push_back
#define fi            first
#define se            second
#define MP            make_pair
#define PI            (acos(-1.0))
#define rep1(i,n)     for(int i=1;i<=n;i++)
#define rep(i,n)      for(int i=0;i<n;i++)
#define SZ(s)         (int)s.size()
#define all(x)        (x).begin(), (x).end()
#define rall(x)       (x).rbegin(), (x).rend()
#define w(t)          int t;cin>>t;while(t--)
#define TSU(s)        transform(s.begin(),s.end(),s.begin(),::toupper);
#define TSL(s)        transform(s.begin(),s.end(),s.begin(),::tolower);
#define _SAD()     	  ios::sync_with_stdio(0),cin.tie(0),cout.tie(0),cout<<fixed<<setprecision(15);

typedef vector<int> vi;
typedef vector<ll> vii;
typedef set<int> si;
typedef set<ll> sii;
/*---------------------------------------------------------------------*/

const int N = (int)1e6+1;
const int MOD =(int)1e9+7;
const ll INF = (ll)1e18+5;
vi aa(N,0);

int main()
{
    _SAD()
    int a;
    cin>>a;
    cout<<a+(a*a)+(a*a*a)<<nl;
    return 0;
}


Measured memory_bytes: 7032
N = int(input())
H = list(map(int, input().split()))

oH, minH = [], H[-1]
for i in range(N):
    minH = min(minH, H[-(i + 1)])
    oH.append(H[-(i + 1)] - minH)

print("Yes" if max(oH) <= 1 else "No")


Measured memory_bytes: 14224
#include <stdio.h>

int main(void)
{
	int n;
	int i, j;
	int count = 0;
	int max = 0;
	int max_n = 0;
	
	scanf("%d", &n);
	
	
	
	for (i = 1; i <= n; i++){
		if (n == 1){
			max_n = 1;
			break;
		}
		j = i;
		while (j % 2 == 0){
			j = j / 2;
			count++;
		}
		if (count > max){
			max = count;
			max_n = i;
		}
		count = 0;
	}
	
	printf("%d\n", max_n);
	
	return (0);
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    int heights[N];
    for(int i=0; i<N; i++)
    {
        cin >> heights[i];
    }
    int dp[N];
    for(int i=0; i<N; i++)
    {
        dp[i] = (int)1e9;
    }
    dp[0] = 0;
    dp[1] = abs(heights[0] - heights[1]);
    for(int i=2; i<N; i++)
    {
        dp[i] = min(dp[i], dp[i-1] + abs(heights[i] - heights[i-1]));
        dp[i] = min(dp[i], dp[i-2] + abs(heights[i] - heights[i-2]));
    }
    cout << dp[N-1];
    return 0;
}




Measured memory_bytes: 1024
n=int(input())
h=list(map(float,input().split()))

dp=[[1.0]*(n+1) for i in range(n+1)]
dp[0][0]=1.0

for i in range(1,n+1):
    dp[0][i]=0.0

for i in range(1,n+1):
    dp[i][0]=dp[i-1][0]*(1.0-h[i-1])

for i in range(1,n+1):
    for j in range(1,n+1):
        dp[i][j]= h[i-1]*dp[i-1][j-1]+ (1-h[i-1])*dp[i-1][j]

ans=0
for i in range(n//2+1,n+1):
    ans+=dp[n][i]
print(ans)


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

void Main()
{
  string S,T;
  cin >> S;
  cin >> T;
  int i = 0;
  for (char c : S){
    if (c != T[i]) {cout << "No" << endl; return;}
    i++;
  }
  cout << "Yes" << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 3616
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC116A2
{
    class Program
    {
        static void Main(string[] args)
        {
            
                string a;
                a = Console.ReadLine();
                if (a == "ABC")
                    a = "ARC";
               else
                    a = "ABC";
                Console.WriteLine(a);
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 17288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n, m;
  in2(n, m);
  if(n < m)
    swap(n, m);
  if(m == 1){
    if(n == 1)
      out(1);
    else
      out(n - 2);
  }
  else
    out((m - 2) * (n - 2));
  memi;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;

int main(){
	char x,y;
	cin>>x>>y;
	if(x - '0' > y - '0') cout<<">"<<endl;
	else if(x - '0' < y - '0') cout<<"<"<<endl;
	else cout<<"="<<endl;
	return 0;
}

Measured memory_bytes: 384
// abc129_a
// #include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
	int P, Q, R;
	cin >> P >> Q >> R;
	/*
	int max = P;
	if (max <= Q) {
		max = Q;
	}
	if (max <= R) {
		max = R;
	}
	*/

	cout << P + Q + R - std::max({ P,Q,R }) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr int mo = 1e9+7;
constexpr int  mod = mo;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<62;

int main(){
    int n;
    cin>>n;
    int k;cin>>k;
    string str;
    cin>>str;
    int same = 0;
    int diff = 0;
    for(int i=0;i<n-1;++i){
        if(str[i] == str[i+1])same++;
        else diff++;
    }
    cout << same+min(diff,2*k) << endl;
    return 0;
}



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



int main(){
  long long int N,M;
  cin >> N >> M;
  if(N >= 2 && M >= 2){
    cout << (N - 2) * (M - 2) << endl;
  }
  else{
    if(N == M){
      cout << 1 << endl;
    }
    else{
      cout << (N > 1 ? N - 2 : M - 2 )<< endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
era = [True]*1000001
for i in xrange(2,1000001):
        if era[i-2]:
                for j in xrange(i*2,1000001,i):
                        era[j-2]=False
while True:
        try:
                n = int(raw_input())
                print era[:n-1].count(True)
        except EOFError:
                break

Measured memory_bytes: 20608
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

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;
}

int main()
{
    int n;
    cin >> n;
    multiset<double> v;
    for(int i = 0; i < n; i++){
        double a;
        cin >> a;
        v.insert(a);
    }
    for(int i = 0; i < n-1; i++){
        double x, y;
        x = *v.begin();
        //cout << "x: " << x << endl;
        v.erase(v.find(x));
        y = *v.begin();
        //cout << "y: " << y << endl;
        v.erase(v.find(y));
        double z = (x+y)/2;
        v.insert(z);
    }
    // cout << "size: " << v.size() << endl;
    cout << *v.begin() << endl;
    return 0;
}

Measured memory_bytes: 3832
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstdlib>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n;
    cin >> n;
    int a[n+2];
    rep(i, n) cin >> a[i+1];
    a[0] = 0;
    a[n+1] = 0;
    int sm = 0;
    rep(i, n + 1) sm += abs(a[i+1] - a[i]);
    rep(i, n){
        int ans = sm;
        ans -= abs(a[i] - a[i+1]);
        ans -= abs(a[i+1] - a[i+2]);
        ans += abs(a[i] - a[i+2]);
        cout << ans << endl;
    }
    
}

Measured memory_bytes: 1664
from collections import defaultdict
n = int(input())
d = tuple(map(int, input().split()))
m = int(input())
t = tuple(map(int, input().split()))
l = defaultdict(int)
for x in d:
    l[x] += 1
for y in t:
    if l[y] == 0:
        print('NO')
        exit()
    l[y] -= 1
print('YES')


Measured memory_bytes: 41316
# include <iostream>
using namespace std; 
int main(){
 long long int n,i,sum; 
  cin>>n; 
  int ar[n];
  for(i=0;i<n;i++){
    cin>>ar[i];
  }
  sum=0;
  for(i=1;i<n;i++){
    if(ar[i-1]>ar[i]){
      sum=sum+(ar[i-1]-ar[i]);
      ar[i]=ar[i-1];
    }
  }
  cout<<sum; 
  return 0;
}

Measured memory_bytes: 4376
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,e;
    cin>>a>>b>>c;
    e=a*b;
    if(e>c)
    {
        cout<<c;
    }
    else if(e<=c)
    {
        cout<<e;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define st first
#define nd second
#define mp make_pair
#define pii pair<int,int>

using namespace std;

const int nax = 2005;
const int mod = 1e9 + 7;

ll dp[nax][nax];

ll p[nax];

ll g(ll l,ll r)
{
    if(l > r) return 0;
    ll ans = p[r] - p[l-1];
    if(ans < 0) ans += mod;
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int s; cin>>s;
    for(int i=3;i<=s;i++)
    {
        dp[1][i] = 1;
    }

    for(int i=1;i<=s;i++)
    {
        p[i] = p[i-1] + dp[1][i];
        p[i] %= mod;
    }

    for(int i=2;i<=s;i++)
    {
        for(int j=3;j<=s;j++)
        {
            ll hi = j - 3;
            ll lo = 0;
            dp[i][j] += g(lo,hi);
            dp[i][j] %= mod;
        }

        for(int j=1;j<=s;j++)
        {
            p[j] = p[j-1] + dp[i][j];
            p[j] %= mod;
        }


    }

    ll ans = 0;
    for(int i=1;i<=s;i++)
    {
        ans += dp[i][s];
        ans %= mod;
    }
    cout<<ans;

    return 0;

}



Measured memory_bytes: 34836
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (int i = j; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define n_p(v) next_permutation(v.begin(),v.end())
#define print(a) cout<<(a)<<endl;
#define to_ll(b) stoll(b)
#define MOD 1000000007

int main(){
	ll s; cin>>s;	
	ll ans=0;
	string ss=to_string(s);
	ll k=ss.size();
	rep(i,0,1<<k-1){
		vector<string> K(0);
		string str="";
		rep(j,0,k){
			if(str=="") str.push_back(ss[j]);
			if(i>>j&1){
				K.push_back(str);
				str="";
			}
			else{
				str.push_back(ss[j+1]);
			}
		}
		K.push_back(str);
		//cout<<K.size()<<-1<<endl;
		rep(i,0,K.size()){
			string p=K[i];
			//cout<<p<<endl;
			ll q=to_ll(p);
			ans+=q;
		}
	}
	cout<<ans;
}

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

int main(){
	int c[4][13];
	int t;
	int i;
	for ( t = 0; t<4; t++ ) {
		for ( i = 0; i<13; i++ ) {
			c[t][i]=0;
		}
	}
	char a;
	int b;
	cin >> t;
	for ( i = 0; i<t; i++ ) {
		cin >> a >> b;
		b=b-1;
		if ( a == 'S' ) {
			c[0][b]=1;
		}else if ( a == 'H' ) {
			c[1][b]=1;
		}else if ( a == 'C' ) {
			c[2][b]=1;
		}else if ( a == 'D' ) {
			c[3][b]=1;
		}
	}
	for ( t = 0; t<4; t++ ) {
		if ( t==0 ) {
			a='S';
		}else if ( t==1 ) {
			a='H';
		}else if ( t==2 ) {
			a='C';
		}else if ( t==3 ) {
			a='D';
		}
		for ( i = 0; i<13; i++ ) {
			if ( c[t][i] != 1 ) {
				cout << a << " " << i+1 << endl;
			}
		}
	}
    return 0;
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#include<queue>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N, Q;
	cin >> N >> Q;
	string S;
	cin >> S;
	pair<int, int> cnt[100010];
	for (int i = 0; i < Q; i++) {
		int A, B;
		cin >> A >> B;
		cnt[i] = make_pair(A, B);
	}
	int dp[100010];
	dp[0] = 0;
	for (int i = 0; i < N - 1; i++) {
		if (S.at(i) == 'A' && S.at(i + 1) == 'C') {
			dp[i + 1] = dp[i] + 1;
		}
		else {
			dp[i + 1] = dp[i];
		}
	}
  	dp[N] = dp[N - 1];
	for (int i = 0; i < Q; i++) {
		cout << dp[cnt[i].second - 1] - dp[cnt[i].first - 1] << endl;
	}
}

Measured memory_bytes: 3456
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let mut ans: String = String::new();
    for i in 0..s.len() {
        if s[i] == 'B' {
            ans.pop();
        } else {
            ans.push_str(&s[i].to_string());
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
#include<iostream>
using namespace std;
int main(void) {
	int a, b;
	cin >> a >> b;
	if (a % b==0) {
		cout << a / b << endl;
	}
	if (a % b > 0) {
		cout << (a / b) + (a % b) << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef double ld;

vector<pair<ll,ll>> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}

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

#define MAX_N 100010
bool x[MAX_N];
ll num[MAX_N];

ll fibl[MAX_N]={0};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}

ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    
    return p;
}

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

int main(){
    ll x;
    cin >> x;
    ll ans=x+1;
    for (ll i=1;i*i<=x;i++){
        if (x%i==0){
            ans=min(ans,i+x/i);
        }
    }
    cout << ans-2 << endl;
    return 0;
}


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

int main()
{
	string S;
	cin >> S;
	int n = S.size();
	bool flag = false;
	int c1 = 0, c2 = 0;
	for (int i = 0; i < n; i++) {
		if (S[i] == '0') {
			(flag ? c1 : c2) += 1;
		}
		else {
			(flag ? c2 : c1) += 1;
		}
		flag = !flag;
	}
	cout << min(c1, c2) << endl;
	return 0;
}


Measured memory_bytes: 512
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut v = std::collections::VecDeque::new();
    for a in a {
        let mut l = -1;
        let mut r = v.len() as i64;
        while r - l > 1 {
            let m = ((l + r) / 2) as usize;
            if v[m] >= a {
                r = m as i64;
            } else {
                l = m as i64;
            }
        }

        if r == 0 {
            v.push_front(a);
        } else {
            v[l as usize] = a;
        }
    }

    println!("{}", v.len());
}


Measured memory_bytes: 4352
N,A,B,C,D = map(int,input().split())
S = list(input())
#pre = S[B - 2]
ans = "Yes"
is_reversed = False
flag = False
# cnt = 0
# max_cnt = 0
if D < C:
  is_reversed = True

for i in range(A,max(C,D) -1):
  if S[i] == S[i + 1] == "#":
    ans = "No"
if is_reversed == True:
  for i in range(B - 2,D - 1):
    if S[i] == S[i + 1] == S[i + 2] == ".":
      flag = True
    # if S[i] == ".":
    #   cnt += 1
    # elif S[i] == "#":
    #   cnt = 0
    # max_cnt = max(max_cnt,cnt)
    # pre = S[i]
  # if is_reversed == True and max_cnt < 3:
  #   ans = "No"
  if flag == False:
    ans = "No"
print(ans)

Measured memory_bytes: 4916
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

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

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n, m;cin>>n>>m;
  vector<vector<int> > jobs(m, vector<int>());
  rep(i, n){
    int a, b;cin>>a>>b;a--;
    if(a<m)jobs[a].push_back(b);
  }
  priority_queue<int> que;
  int ans=0;
  rep(i, m){
    for(auto &e: jobs[i])que.push(e);
    if(!que.empty()){ans+=que.top();que.pop();}
  }
  cout<<ans<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 5632
def solve():
    from sys import stdin
    f_i = stdin
    
    n = f_i.readline()
    A = f_i.readline().split()
    q = int(f_i.readline())
    for i in range(q):
        b, e, t = map(int, f_i.readline().split())
        w = e - b
        if b < t:
            A = A[:b] + A[t:t+w] + A[b+w:t] + A[b:b+w] + A[t+w:]
        else:
            A = A[:t] + A[b:b+w] + A[t+w:b] + A[t:t+w] + A[b+w:]
    print(' '.join(A))

solve()


Measured memory_bytes: 5640
#include <iostream>
#include <vector>
#include <stack>
#include <sstream>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
struct P{double x,y;};

void output(double x,double y){
	printf("%.6lf %.6lf\n",x,y);
}
int main(){
	P a,b,r; string s;
	while(getline(cin,s)){
		while(~s.find(","))s[s.find(",")] = ' ';
		stringstream ss(s);
		ss >> a.x >> a.y >> b.x >> b.y >> r.x >> r.y;
		
		double x,y,X = a.x - b.x , Y = a.y - b.y ;
		if(X == 0){
			x = r.x - a.x;
			output(a.x-x,r.y);
		}else if(Y == 0){
			y = r.y - a.y;
			output(r.x,a.y-y);
		}else{
			x = ( r.y -a.y + (Y/X)*a.x + (X/Y)*r.x )/((X*X+Y*Y)/(X*Y));
			y = (Y/X)*(x-a.x) + a.y;
			output(2*x-r.x,2*y-r.y);
		}
	}
}

Measured memory_bytes: 0
/*author : Yashvardhan
Friday, May 31, 2019
9:42 AM
*/

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

typedef long long ll;

#define int ll
#define pb push_back
#define vi vector<int>
#define pi pair<int,int>
#define vpi vector<pi>
#define ff first
#define ss second
#define mp make_pair
#define endl '\n'

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#ifdef __APPLE__
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << "  ";
	__f(comma + 1, args...);}
#else
#define debug(...)
#endif

template <typename T> ostream& operator << (ostream& os,const vector<T>& v){for(int i=0;i<v.size();++i) os<<v[i]<<" ";return os;} 
template <typename T> ostream& operator << (ostream& os,const set<T>& v){for(auto it:v) os<<it<<" ";return os;} 
template <typename T, typename S> ostream& operator << (ostream& os, const pair<T,S>& v) {os<<v.ff<<" "<<v.ss;return os;}

const int mod = 1e9 + 7;
const int inf = 2e18;
const int ninf = -2e18;

int pow(int a, int b, int m)
{
	int ans = 1;
	while (b)
	{
		if (b & 1)
			ans = (ans * a) % m;
		b /= 2;
		a = (a * a) % m;
	}
	return ans;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef __APPLE__
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
		freopen("error.txt","w",stderr);
	#endif

	time_t t1, t2;
	t1 = clock();
	
	int n,m;
	cin>>n>>m;

	int a = ninf;
	int b = inf;
	for(int i = 0; i < m ; i++){
		int x,y;
		cin>>x>>y;
		a = max(x,a);
		b = min(y,b);
	}
	cout<<max((ll)0,(b-a+1))<<endl;
	

	t2 = clock();
	cerr<<endl<<t2-t1<<endl;
	
	return 0;
}



Measured memory_bytes: 512
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
using namespace std;
int main(){
  double a,b,h;
  cin>>a>>b>>h;
  cout<<(a + b) * h / 2;
  system ("pause");
  return 0;
  }

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

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

struct mo_t {
  int n;
  vector<pair<int, int>> lr;
  mo_t(int _n) : n(_n) {}
  void add(int l, int r) { lr.emplace_back(l, r); }
  template <class AL, class AR, class RL, class RR, class O>
  void run(AL add_left, AR add_right, RL remove_left, RR remove_right, O out) {
    int q = size(lr), bs = n / clamp<int>(sqrt(q * 2 / 3), 1, n);
    vector<int> ord(q);
    iota(begin(ord), end(ord), 0);
    sort(begin(ord), end(ord), [&](int i, int j) {
      auto [li, ri] = lr[i];
      auto [lj, rj] = lr[j];
      li /= bs, lj /= bs;
      return li != lj ? li < lj : li & 1 ? ri > rj : ri < rj;
    });
    int l = 0, r = 0;
    for (int i : ord) {
      auto [li, ri] = lr[i];
      while (l > li) add_left(--l);
      while (r < ri) add_right(r++);
      while (l < li) remove_left(l++);
      while (r > ri) remove_right(--r);
      out(i);
    }
  }
};

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> c(n);
  for (auto&& e : c) cin >> e, --e;
  mo_t mo(n);
  vector<int> res(q), cnt(n);
  int cur = 0;
  auto add = [&](int i) {
    cur += cnt[c[i]]++ == 0;
  };
  auto remove = [&](int i) {
    cur -= --cnt[c[i]] == 0;
  };
  auto out = [&](int id) {
    res[id] = cur;
  };
  while (q--) {
    int l, r;
    cin >> l >> r;
    --l;
    mo.add(l, r);
  }
  mo.run(add, add, remove, remove, out);
  for (int e : res) {
    cout << e << '\n';
  }
}


Measured memory_bytes: 15468
S=input()
A=int(S[0:2])
B=int(S[2:4])
if 1<=A<=12:
    if 1<=B<=12:
        ans="AMBIGUOUS"
    else:
        ans="MMYY"
else:
    if 1<=B<=12:
        ans="YYMM"
    else:
        ans="NA"
print(ans)

Measured memory_bytes: 3060