akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <complex>
#define LL long long
using namespace std;
const int M = 300 + 5, INF = 0x3f3f3f3f, mod = 313;
const double PI = acos(-1);
int n,m;
int A[M][M];
int sum[M];
bool mark[M];
bool check(int mid){
    memset(sum,0,sizeof(sum));
    memset(mark,0,sizeof(mark));
    for(int j=1;j<=n;j++){
        sum[A[j][1]]++;
    }
    int ok=1;
    while(ok){
        ok=0;
        for(int j=1;j<=m;j++){
            if(sum[j]>mid){
                mark[j]=1;
                ok=1;
            }
        }
        memset(sum,0,sizeof(sum));
        for(int j=1;j<=n;j++){
            for(int k=1;k<=m;k++){
                if(!mark[A[j][k]]){
                    sum[A[j][k]]++;
                    break;
                }
            }
        }
    }
    for(int j=1;j<=m;j++){
        if(!mark[j]) return 1;
    }
    return 0;
}
int main() {
    while(scanf("%d%d",&n,&m)!=EOF){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=m;k++){
                scanf("%d",&A[j][k]);
            }
        }
        int l=0,r=INF;
        int res=0;
        while(l<=r){
            int mid=(l+r)>>1;
            if(check(mid)){
                r=mid-1;
                res=mid;
            }
            else l=mid+1;
        }
        printf("%d\n",res);
    }
    return 0;
}


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

int main()
{
  int s;
  cin >> s;
  set<int> st;
  st.insert(s);
  for(int i=0; i<1000000; i++)
  {
    if(s % 2 == 0)
      s /= 2;
    else
      s = 3 * s + 1;
    
    if(st.find(s) != st.end())
    {
      cout << i+2 << endl;
      return 0;
    }
    else
      st.insert(s);
  }
}

Measured memory_bytes: 3528
#include <iostream>
#include <string>

int main() {
	int n = 0;
	std::string S;
	std::cin >> S;

	for(char c : S) {
		if(c == '+') {
			n++;
		} else if(c == '-') {
			n--;
		}
	}

	std::cout << n << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
int n,a,b;
ld dp[150000],dp2[150000],ch[150000],par[150000];
vector<int> v[150000],u;
void dfs(int a){
    ld tmp=0.0;
    for(int x:v[a]){
        if(ch[x]!=0)continue;
        ch[x]=1;
        par[x]=a;
        dfs(x);
        tmp+=dp[x]+1.0;
    }
    if(a==0)dp[a]=tmp/(ld)v[a].size();
    else if(v[a].size()>1)dp[a]=tmp/ld(v[a].size()-1.0);
    else u.push_back(a);
    return ;
}
void dfs2(int a){
    if(dp2[a]>0)return ;
    if(a==0)return ;
    //if(dp2[(int)par[a]]==0)この違いよ！
    dfs2(par[a]);
    int b=par[a];
    ld p=v[b].size();
    //cout<<"P"<<p<<" "<<b<<endl;
    if(p==1)dp2[a]=1;
    else if(b==0)dp2[a]=((dp[b]+1)*p-(dp[a]+2))/(p-1);
    else if(p>1)dp2[a]=((dp2[b]+1)+(dp[b]+1)*(p-1)-(dp[a]+2))/(p-1);
    //cout<<a<<" "<<dp2[a]<<endl;
    //cout<<a<<" "<<dp2[a]<<"W"<<endl;
    return ;
}
int main(void){
    cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        a--,b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    for(int i=0;i<n;i++)ch[i]=0;
    ch[0]=1;
    par[0]=-1;
    dfs(0);
    //cout<<"W"<<endl;
  	//for(int i=0;i<n;i++)dp2[i]=0;
    for(auto x:u){
        dfs2(x);
    }
    for(int i=0;i<n;i++){
        //cout<<dp[i]<<" "<<dp2[i]<<endl;
        if(i==0)cout<<setprecision(15)<<dp[i]<<endl;
        else cout<<setprecision(15)<<(dp[i]*ld(v[i].size()-1)+dp2[i])/(ld)v[i].size()<<endl;
    }
}


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

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

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}


int main(){
    double n;
    cin >> n;
    double ans = 0;
    if((int)n % 2 == 0){
        ans = n/2/n;
    }
    else{
        ans = (n/2+0.5)/n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(obj) (obj).begin(),(obj).end()
const int mod=1e9+5;
struct edge{
  int to,id;
};
vector<vector<edge>> g;
vector<int> ans;
void dfs(int v,int c=-1,int p=-1){
  int k=1;
  rep(i,g[v].size()){
    int u=g[v][i].to;int ei=g[v][i].id;
    if(u==p)continue;
    if(c==k)++k;
    ans[ei]=k;++k;
    dfs(u,k-1,v);
  }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    g.resize(n);
    ans.resize(n);
    rep(i,n-1){
      int a,b;cin>>a>>b;
      --a;--b;
      g[a].push_back((edge){b,i});
      g[b].push_back((edge){a,i});
    }
    dfs(0);
    int mx=0;
    rep(i,n)mx=max(mx,int(g[i].size()));
    cout<<mx<<endl;
    rep(i,n-1)cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 8320
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/





int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int t; cin >> t;
  LL n, d;
  vi divs{2, 3, 5};
  LL costs[3];
  while (t--) {
    cin >> n >> costs[0] >> costs[1] >> costs[2] >> d;
    map<LL, LL> table;
    table[n] = 0;
    priority_queue<pll, vector<pll>, greater<pll>> pq;
    pq.emplace(0, n);
    LL ret = LLONG_MAX;
    while(!pq.empty()) {
      pll cur = pq.top(); pq.pop();
      if (cur.first >= ret) break;
      if (table[cur.second] < cur.first) continue;
      if (cur.second * (LD)d + cur.first < 1e15) ret = min(ret, cur.second * d + cur.first);
      for (int i = 0; i < 3; i++) {
        int div = divs[i];
        LL cost = costs[i];
        LL x = cur.first + (cur.second % div) * d + cost;
        LL y = cur.second / div;
        auto it = table.find(y);
        if (it == table.end() || it->second > x) {
          table[y] = x;
          pq.emplace(x, y);
        }
        x = cur.first + (div - cur.second % div) * d + cost;
        y = cur.second / div + 1;
        it = table.find(y);
        if (it == table.end() || it->second > x) {
          table[y] = x;
          pq.emplace(x, y);
        }
      }
    }
    cout << ret << '\n';




  }






/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 4256
import java.util.*;
 public class Main{
   public static void main(String[]srgs){
     Scanner sc = new Scanner(System.in);
     int r = sc.nextInt();
     int d = sc.nextInt();
     int x = sc.nextInt();
     for(int i=0; i<10; i++){
       
       x = r*x-d;
      
      System.out.println(x);
       
     }
   }
 }

Measured memory_bytes: 21844
//Largest Square
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int largestSquare(int h, int w, vector<vector<int>> &G) {
    vector<vector<int>> dp(h+1, vector<int>(w+1, 0));

    int s = 0;
    for(int i=1; i<h+1; i++) {
        for(int j=1; j<w+1; j++) {
            if(G[i][j] == 1) continue;
            dp[i][j] = min(dp[i-1][j-1]+1, min(dp[i-1][j]+1, dp[i][j-1]+1));
            s = max(s, dp[i][j]);
        }
    }
    
    return s*s;
}

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> G(h+1, vector<int>(w+1, 1));
    for(int i=1; i<h+1; i++)
        for(int j=1; j<w+1; j++)
            cin >> G[i][j];

    cout << largestSquare(h, w, G) << endl;

    return 0;
}


Measured memory_bytes: 18096
#include <iostream>
#include <vector>
#include <deque>
#include <tuple>
#define endl '\n'
#define ll long long
using namespace std;

int h, w;
int cx, cy, dx, dy;
vector<string> maze;
vector<vector<int>> d;
vector<int> teleport_x;
vector<int> teleport_y;
int walk_x[4] = { 0, 0, 1, -1 };
int walk_y[4] = { 1, -1, 0, 0 };

void bfs(int sx, int sy) {
	deque<pair<int, int>> q;
	d[sx][sy] = 0;
	q.push_back({ sx, sy });

	int range = teleport_x.size();

	while (!q.empty()) {
		int x, y;
		tie(x, y) = q.front();
		q.pop_front();
		for (int k = 0; k < 4; k++) {
			int nx = x + walk_x[k];
			int ny = y + walk_y[k];

			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (maze[nx][ny] == '#') continue;
			if (d[nx][ny] == -1 || d[nx][ny] > d[x][y]) {
				q.push_front({ nx, ny });
				d[nx][ny] = d[x][y];
			}
		}

		for (int k = 0; k < range; k++) {
			int nx = x + teleport_x[k];
			int ny = y + teleport_y[k];

			if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
			if (maze[nx][ny] == '#') continue;
			if (d[nx][ny] == -1 || d[nx][ny] > d[x][y] + 1) {
				q.push_back({ nx, ny });
				d[nx][ny] = d[x][y] + 1;
			}
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	cin >> h >> w
		>> cx >> cy
		>> dx >> dy;
	cx--; cy--; dx--; dy--;

	maze.resize(h);
	d.resize(h);
	for (int i = 0; i < h; i++) {
		cin >> maze[i];
		d[i].resize(w);
		for (int j = 0; j < w; j++)
			d[i][j] = -1;
	}

	for(int i = -2; i <= 2; i++) 
		for (int j = -2; j <= 2; j++) {
			if (i == 0 && j == 0) continue;
			teleport_x.push_back(i);
			teleport_y.push_back(j);
		}
	bfs(cx, cy);
	cout << d[dx][dy] << endl;

	return 0;
}

Measured memory_bytes: 8732
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans = 0;
  ll prev = 0;
  rep(i, n) {
    ll x;
    cin >> x;
    if (i == 0) {
      prev = x;
      continue;
    }
    ans += min(a * (x - prev), b);
    prev = x;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
## ABC 093 D Worst Case
import math
Q = int(input())
ans = []
for i in range(Q):
    A,B = list(map(int,input().split()))
    C = math.floor(math.sqrt(A*B)-1e-7)
    if A <= B:
        pass
    else:
        t = A
        A = B
        B = t
#解説より、場合分け
# コンテスト成績をA<＝Bとして、A==Bなら、
    if A == B:
        ans.append(2*A-2)
# 2A-2
# A+1==Bなら
    elif (A+1) == B:
        ans.append(2*A-2)
# 2A-2
# C^2 <AB の最大のCで C(C+1) >= ABなら
# 2C-2
    elif C*(C+1) >= A*B:
        ans.append(2*C-2)
# C^2 < ABなら
# 2C-1
    else:
        ans.append(2*C-1)

for a in ans:
    print(a)

Measured memory_bytes: 3064
#include <cctype>
#include <stdio.h>

using namespace std;

int main() {
  char word;

  while (true) {
    scanf("%c", &word);
    if (islower(word)) printf("%c", toupper(word));
    else printf("%c", tolower(word));

    if (word == '\n') break;
  }
  return 0;
}

Measured memory_bytes: 940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static StringBuilder builder = new StringBuilder();

	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(reader.readLine());
		}
		shellSort(a, n);
		for (int i = 0; i < n; i++) {
			builder.append(a[i]).append("\n");
		}
		System.out.print(builder);

	}

	private static void shellSort(int[] a, int n) {
		int[] g = new int[15];
		int m = 0;
		for (int i = 0; i < n; i = i * 3 + 1) {
			for (int j = m; 0 < j; j--) {
				g[j] = g[j - 1];
			}
			g[0] = i;
			m++;
		}
		if (m == 0) {
			g[0] = 1;
			m = 1;
		}
		builder.append(m).append("\n");
		int cnt = 0;
		for (int i = 0; i < m; i++) {
			if (i != 0)
				builder.append(" ");
			builder.append(g[i]);
			cnt += insertionSort(a, n, g[i]);
		}
		builder.append("\n").append(cnt).append("\n");
	}

	private static int insertionSort(int[] a, int n, int g) {
		int cnt = 0;
		for (int i = g; i < n; i++) {
			int key = a[i];
			int j = i - g;
			while (j >= 0 && a[j] > key) {
				a[j + g] = a[j];
				j = j - g;
				cnt++;
			}
			a[j + g] = key;
		}
		return cnt;
	}
}

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

using namespace std;


int main(){
    
    int N;cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    
    double ans = (v[0]+v[1])/2.0;
    
    for (int i = 2; i < N; i++) {
        ans = (ans+double(v[i]))/2.0;
    }
    
    cout << ans << endl;
}


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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)    FOR (i,0,n)
#define ALL(f,x,...) ([&](decltype((x)) ALL) {                          \
            return (f)(begin(ALL), end(ALL), ## __VA_ARGS__); })(x)

using namespace std;
using ll = int64_t;

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

    ll x;
    cin >> x;

    vector<ll> a(N, 0);
    vector<ll> b(N, 0);

    REP(i, N) cin >> a[i];

    b = a;

    ll mincost = x * N + (ll)1000000001 * N;
    REP(i, N)
    {
        ll cost = 0;

        REP(j, N)
        {
            b[j] = min(b[j], a[(j + N - i) % N]);
            cost += b[j];
        }

        mincost = min(mincost, i * x + cost);
    }

    cout << mincost << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,t;
long long check=0;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>s;
    cin>>t;
    for (int i=0;i<s.length();i++)
    if (s[i]!=t[i]) check=1;
    if (!check) cout<<"Yes";
    else
    {
        cout<<"No";
    }
    
}
        




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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vll           vector<ll> 
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
void solve() {
  int n; scanf("%d",&n);
  vll a(n);
  rep(i,0,n) 
    scanf("%lld",&a[i]);
  sort(all(a));
  if (!a[0]) {
    puts("0");
    return;
  }
  ll oo=1e18;
  ll pd=1;
  rep(i,0,n) {
    if (a[i]>(oo/pd)) {
      puts("-1");
      return;
    }
    pd*=a[i];
  }
  if (pd>oo) puts("-1");
  else printf("%lld\n",pd);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  // int _; cin >> _; while(_--)
  solve();
	return 0;
}


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

const int maxn=200005;
int n,pos,top;
long long a[maxn],aa[maxn],b[maxn],c[maxn];
class Point{
public:
	long long x,y;
	Point():x(0),y(0){}
	Point(long long _x,long long _y):x(_x),y(_y){}
	Point operator-(const Point &o)const{return Point(x-o.x,y-o.y);}
}st[maxn];
bool above(Point a,Point b,Point c){
	b=b-a;c=c-a;
	return b.x*c.y-b.y*c.x>=0;
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&aa[i]);
		if(aa[i]>aa[pos])pos=i;
	}
	for(int i=0;i<n;i++){
		a[i]=aa[(pos+i)%n];
		scanf("%d",&b[(i-pos+n)%n]);
	}
	a[n]=a[0];b[n]=b[0];
	for(int i=2;i<=n;i++)c[i]=2LL*(c[i-1]+b[i-1])-c[i-2];
	for(int i=0;i<=n;i++){
		Point p(i,a[i]-c[i]);
		while(top>=2&&above(st[top-2],st[top-1],p))top--;
		st[top++]=p;
	}
	long long ans=0;
	for(int i=1;i<top;i++){
		long long dx=st[i].x-st[i-1].x;
		ans+=st[i-1].y*(dx+1)+st[i].y*(dx-1);
	}
	for(int i=0;i<n;i++)ans+=2*c[i];
	printf("%.12lf\n",double(ans)/(2.0*n));
	return 0;
}

Measured memory_bytes: 13108
#include <iostream>
#include <vector>
#include <set>


int main()
{
	int N, K;
	std::cin >> N >> K;

	int R, S, P;
	std::cin >> R >> S >> P;

	std::string T;
	std::cin >> T;

	std::string Best(T);	// K回前・・・の条件を考えない時の手

	for (int i = 0; i < N; ++i) {
		switch(T[i]){
		case 'r':
			Best[i] = 'p';
			break;

		case 's':
			Best[i] = 'r';
			break;

		case 'p':
			Best[i] = 's';
			break;
		}
	}


	int score = 0;

	// K回前・・・の条件を考えて手を直す。
	for (int i = 0; i < N; ++i) {
		if (i < K) {
			// 勝ちのまま
			switch (Best[i]) {
			case 'r':
				score += R;
				break;

			case 's':
				score += S;
				break;

			case 'p':
				score += P;
				break;
			}

			continue;
		}

		if (Best[i] == Best[i - K]) {
			// K回前の手と同じなら、K回後と違う手を出す。

			if ((i + K) < N) {
				switch (Best[i - K]) {
				case 'r':
					switch (Best[i + K]) {
					case 'r':
						Best[i] = 'p';
						break;

					case 's':
						Best[i] = 'p';
						break;

					case 'p':
						Best[i] = 's';
						break;
					}
					break;

				case 's':
					switch (Best[i + K]) {
					case 'r':
						Best[i] = 'p';
						break;

					case 's':
						Best[i] = 'r';
						break;

					case 'p':
						Best[i] = 'r';
						break;
					}
					break;

				case 'p':
					switch (Best[i + K]) {
					case 'r':
						Best[i] = 's';
						break;

					case 's':
						Best[i] = 'r';
						break;

					case 'p':
						Best[i] = 'r';
						break;
					}
					break;
				}

			}
			else {
				Best[i] = T[i];
			}
		}
		else {
			// 勝ちのまま
			switch (Best[i]) {
			case 'r':
				score += R;
				break;

			case 's':
				score += S;
				break;

			case 'p':
				score += P;
				break;
			}
		}
	}

	std::cout << score << std::endl;

	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
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;}

int main(){
	ll x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vector<pair<ll,ll>> p;
	ll in;
	REP(i,a){
		cin >> in;
		p.push_back(make_pair(-1*in,1));
	}
	REP(i,b){
		cin >> in;
		p.push_back(make_pair(-1*in,2));
	}
	REP(i,c){
		cin >> in;
		p.push_back(make_pair(-1*in,3));
	}
	
	sort(p.begin(),p.end());
	
	ll ans=0, x_count=0, y_count=0;
	ll k = 0;
	for(ll i=0; i<x+y+k; i++){
		if(x_count<x && p[i].second==1){
			ans += p[i].first;
			x_count++;
		}else if(y_count<y && p[i].second==2){
			ans += p[i].first;
			y_count++;
		}else if(p[i].second==3){
			ans += p[i].first;
		}else{
			k++;
		}
	}
	
	cout << abs(ans) << endl;
	
	return 0;
}

Measured memory_bytes: 11676
S = input()
N = len(S)
ans = 0
for l in range(N//2+1):
    flag = True
    for i in range(l):
        if S[i] != S[i+l]:
            flag = False
            break
    if flag:
        if l*2 < N:
            ans = max(ans, l)
print(ans*2)

Measured memory_bytes: 9004
L, R = map(int, (input().split()))
Lmod, Rmod = L%2019, R%2019
result = 2019
if Lmod < Rmod and (R - L >= 2019):
    print(0)
elif Lmod < Rmod and (R - L < 2019):
    for i in range(L,R,1):
        for j in range(i+1, R+1, 1):
            if result > (i*j)%2019:
                result = (i*j)%2019
    print(result)
elif Lmod > Rmod:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define REP(i,a,n) for(int (i)=(a); (i)<(int)(n); (i)++)
#define rep(i,n) REP(i,0,n)
#define vec vector 


int main(){
  int A, B, C;
  cin >> A >> B >> C;
  int sum = A + B + C;
  
  vector<int> target(3);
  target.at(0) = A; target.at(1) = B; target.at(2) = C;
  
  sort(target.begin(), target.end());
  int max_number = target.at(2);
  
  if((max_number*3 - sum)%2 == 0){
    cout << (max_number*3 - sum)/2;
  }else{
    cout << (max_number*3 - sum + 3)/2;
  }
  
}

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

const int MAXN = 2e5;
int parent[MAXN];

int find(int x) {
	if(x == parent[x]) {
		return x;
	}
	else{
		return parent[x] = find(parent[x]);
	}
}

void un(int a, int b) {
	int c = find(a);
	int d = find(b);
	if(c != d) {
		parent[d] = c;
	}
}

int main() {
	int n, m;
	cin >> n >> m;
	for(int i=0; i<n; i++) {
		parent[i] = i;
	}
	for(int i=0; i<m; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		un(a, b);
	}
	map<int, int> cnt;
	for(int i=0; i<n; i++) {
		cnt[find(i)]++;
	}
	int ans = 1;
	for(auto it: cnt) {
		ans = max(ans, it.second);
	}
	cout << ans << endl;
}

Measured memory_bytes: 13628
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef long long int llt;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

char dif = 'A' - 'a';
int mod = 1e9 + 7;
ll inf = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    ll ans = 1;
    if(n>m)
        swap(n, m);
    if(n==m){
        for (int i = 1; i <= n;i++){
            ans *= i;
            ans %= mod;
        }
        ans = ans * ans % mod;
        ans = ans * 2 % mod;
    }
    else if(n==m-1){
        for (int i = 1; i <= n;i++){
            ans *= i;
            ans %= mod;
        }
        ans = ans * ans % mod;
        ans = ans * m % mod;
    }
    else
        ans = 0;
    cout << ans << endl;
    return 0;
}

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

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


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

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

  vector<int> S(M);
  vector<int> C(M);
  for(int i=0; i<M; i++){
    cin >> S[i] >> C[i];
  }

  bool failed = false;
  vector<int> str(N);
  for(int i=0; i<N; i++){
    str[i] = -1;
  }

  for(int i=0; i<M; i++){
    if(S[i] <= N && str[S[i]-1] == -1){
      str[S[i]-1] = C[i];
    }else if(S[i] <= N && str[S[i]-1] == C[i]){
      str[S[i]-1] = C[i];
    }else{
      failed = true;
    }
  }

  int result = 0;
  for(int i=0; i<N; i++){
    if(i==0 && str[i] == 0 && N>1){
      failed = true;
      break;
    }
    int a = 0;
    if(str[i] != -1){
      a = str[i];
    }else if(str[i]==-1 && i==0 && N != 1){
      a = 1;
    }
    result += a * pow(10, N-i-1);
  }
  if(failed){
    cout << "-1" << endl;
  }else{
    cout << result << endl;
  }
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int x=0,ans=0;
  int n;
  scanf("%d",&n);
  char s[n+10];
  scanf("%s",s);
  for(int i=0;i<n;i++){
    if(s[i]=='I'){
      x++;
    }else{
      x--;
    }
    chmax(&ans,x);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1660
n = int(input())
dic = {}
for i in range(n):
    s = input()
    if s in dic.keys():
        dic[s]+=1
    else:  
        dic[s]=1

sorted_dic = sorted(dic.items(), key=lambda x:x[1], reverse=True)
ans = []
max = 0
for sd in sorted_dic:
    if max <= sd[1]:
        ans.append(sd[0])
        max = sd[1]
    else:
        break

print('\r\n'.join(sorted(ans)))

Measured memory_bytes: 50520
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();

    if &s == "ABC" {
        println!("ARC");
    } else {
        println!("ABC");
    }
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define pr pair<int,int>
#define PI 3.1415926535897932384626
#define mod 1000000007
#define fo(i,n) for(i=0;i<n;i++)
#define endl "\n"
#define mset(m,v) memset(m,v,sizeof(m))
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef vector<int>	vi;
#define FAST_IO  ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)

void solve()
{
	int a,b,c,d,x=-1e18;
	cin >> a >> b >> c >> d ;
	x=max(a*c,b*d);
	x=max3(x,a*d,b*c);
	cout << x;
}

int32_t main()
{
	FAST_IO;
	int t=1;//cin>>t;
	for(int i=1;i<=t;i++){	solve();}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
/////////////////////////////////
int main()
{
    int n;
    cin >> n;
    int cnt = 0;
    rep(i, n)
    {
        int k;
        cin >> k;
        if (i + 1 != k)
            cnt++;
    }
    if (cnt < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

Measured memory_bytes: 3684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long ans;

		if(k%2==0) {
			ans=motomeru(n, k)+motomeru(n+k/2, k);
		}
		else {
			ans=motomeru(n, k);
		}

		System.out.print(ans);
	}

	static long motomeru(int n, int t) {
		long kitei=n/t;

		return(kitei+3*kitei*(kitei-1)+kitei*(kitei-1)*(kitei-2));
	}


}


Measured memory_bytes: 22996
#include <stdio.h>

int main(int argc, char **argv)
{
  int sum;
  int min, sec;
  int i, j, k, l;
  scanf("%d\n%d\n%d\n%d", &i, &j, &k, &l);
  sum = i + j + k + l;
  min = sum / 60;
  sec = sum % 60;
  printf("%d\n%d\n", min, sec);
  return 0;
}

Measured memory_bytes: 596
module app;

import core.bitop;

import std.algorithm;
import std.array;
import std.bigint;
import std.conv;
import std.container.rbtree;
import std.stdio;
import std.string;

void main()
{
    Input input = void;
    parseInput(input, stdin);
    auto result = main2(&input);
    writeln(result);
}

auto main2(Input* input)
{
	auto rbt = redBlackTree!("a>b", true, uint)(input.a);
	foreach (i; 0..input.m)
	{
		auto newValue = rbt.front() >> 1;
		rbt.removeFront();
		rbt.insert(newValue);
	}

    BigInt count = 0;
	foreach (a; rbt)
		count += a;
    return count;
}

unittest { writefln("begin unittest"); }

unittest // example1
{
    string example =
`3 3
2 13 8`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == 9);
}

unittest // example2
{
    string example =
`4 4
1 9 3 5`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == 6);
}

unittest // example3
{
    string example =
`1 100000
1000000000`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == 0);
}

unittest // example4
{
    string example =
`10 1
1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000`;
    Input input = void;
    parseExample(input, example);
    auto result = main2(&input);
    assert(result == 9500000000);
}

unittest { writefln("end unittest"); }

struct Input
{
	uint n,m;
    uint[] a;
}

void parseInput(T)(out Input input, T file)
{
    with (file) with (input)
    {
		auto nm = readln().strip().split().map!(a=>a.to!uint).array();
		n = nm[0]; m = nm[1];
        input.a = readln().strip().split().map!(a=>a.to!uint).array();
    }
}

void parseExample(out Input input, string example)
{
    struct Adapter
    {
        import std.string;

        string[] _lines;
        this(string input) { _lines = input.splitLines(); }

        string readln()
        {
            auto line = _lines[0];
            _lines = _lines[1..$];
            return line;
        }
    }
    Adapter a = Adapter(example);
    parseInput(input, a);
}


Measured memory_bytes: 12488
// #pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int n, a;
    cin >> n >> a;
    cout << (a >= n % 500 ? "Yes" : "No") << "\n";
    
    return 0;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0
n = int(readline())
s = readline().rstrip().decode('utf-8')
k = int(readline())

res = s[k-1]
ans = ""
for i in s:
    if i == res:
        ans += i
    else:
        ans += "*"
print(ans)

Measured memory_bytes: 38384
import java.io.IOException;


public class Main {
	static class Lst {
		private	int[]	d = new int[10000];
		private	int		h = 0;
		private	int		t = 0;

		public void add(int e) {
			d[t++] = e;
		}

		public int get(int i) {
			return d[h+i];
		}

		public int size() {
			return t-h;
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Lst	lst = getList();
		int	inp = 0;

		while((inp = parseNum()) != 0) {
			int o = 0;
			for (int i = 0; i+1 <= lst.size() && lst.get(i+1) <= inp; i++) {
				int	a = lst.get(i);
				int	b = lst.get(i+1);

				if (a > inp || b > inp) break;
				if (b-a == 2) o = a;
			}
			System.out.println(o+" "+(o+2));
		}
	}

	private static int parseNum() {
		try {
			int	buf = 0;
			int	num = 0;
			int	mns = 0;
			int	skp = 1;

			// -,0〜9以外は読み飛ばす
			while (true) {
				buf = System.in.read();
				if (buf == '-') {
					mns = 1;
					skp = 0;
				} else if (buf >= '0' && buf <= '9') {
					num = num * 10 + (buf - '0');
					skp = 0;
				} else if ((skp == 0 || buf == -1) && buf != '.') {
					return (mns == 0)?num:num*(-1);
				}
			}
		} catch (IOException e) {}
		return -1;
	}

	private static Lst getList() {
		Lst	lst = new Lst();
		int	lim = 10000;

		lst.add(2);
		for(int num = 3; num <= lim; num += 2) {
			boolean	prm = true;

			for (int i = 0; i < lst.size(); i++) {
				int	nWk = lst.get(i);
				if (nWk <= (int)Math.sqrt((double)num)) {
					if (num % nWk == 0) {
						prm = false;
						break;
					}
				}
				else {
					break;
				}
			}

			if (prm) {
				lst.add(num);
			}
		}

		return lst;
	}
}

Measured memory_bytes: 25116
package main

import (
	"fmt"
)

func main() {
	dishTimes := make([]int, 5)

	for i := 0; i < 5; i++ {
		fmt.Scan(&dishTimes[i])
	}

	plans := make([][]int, 10)
	for _, dishTime := range dishTimes {
		waitTime := dishTime % 10
		if waitTime != 0 {
			waitTime = 10 - waitTime
		}
		plans[waitTime] = append(plans[waitTime], dishTime)
	}

	totalTime := 0
	lastWaitTime := 0

	// excute dish order to wait time
	for waitTime := 0; waitTime < 10; waitTime++ {
		for _, dishTime := range plans[waitTime] {
			totalTime += dishTime
			totalTime += waitTime
			lastWaitTime = waitTime
		}
	}

	fmt.Println(totalTime - lastWaitTime) // Don't need to wait for last dish
}


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

const double INF = 1000 * 1000 * 1000;
int main()
{
    long long n;
    cin >> n;
    vector<long long> v(n);
    vector<long long> cost(n);
    for(long long i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    long long all_cost = 0;
    for(long long i = 0; i < n - 1; ++i)
    {
        cost[i] = abs(v[i] - v[i + 1]);
        all_cost += cost[i];
    }
    for(long long i = 0; i < n; ++i)
    {
        long long ans = all_cost;
        ans -= cost[i];
        if(i > 0 && i != n - 1)
        {
            ans -= cost[i - 1];
            ans += abs(v[i - 1] - v[i + 1]);
            ans += abs(v[n - 1]);
            ans += abs(v[0]);
        }
        else
        {
            if(i == 0)
            {
                ans += abs(v[n - 1]);
                ans += abs(v[1]);
            } else
            {
                ans += abs(v[0]);
                ans -= cost[n - 2];
                ans += abs(v[n - 2]);
            }
        }
        cout << ans << endl;

    }

}

Measured memory_bytes: 2816
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lld;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"NO"<<endl;return 0
const int mod=1000000007;
const int big=1e9+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
const int hi=100000;
int main(void){
	int n,i,ans=0;cin>>n;
	vector<int>a(hi+2);
	for(i=0;i<n;i++){
		int q;cin>>q;q++;
		a[q-1]++;a[q]++;a[q+1]++;
	}
	for(i=0;i<a.size();i++){
		maxeq(ans,a[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1272
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    ll N,A,B; cin >>N>>A>>B;
    ll ans=B*(N-1)+A-A*(N-1)-B+1;
    if ((N==1&&A!=B)||(A>B))ans=0;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
const int N=1e5+10;
ll a[N],dp[N]={0};
int main()
{
	int n,k,i,j;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]); 
	} 
	dp[1]=0;
	for(i=2;i<=n;i++)
	{
		dp[i]=inf;
		for(j=1;j<=k;j++)
		{
			if(i<=j) break;
			dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int64_t H, W, K, ans = pow(10, 6);
vector<string> A(10);

int main()
{
  cin >> H >> W >> K;
  for (int i = 0; i < H; i++)
    cin >> A[i];
  for (int bit = 0; bit < (1 << (H - 1)); bit++)
  {
    vector<pair<int, int>> parts(0);
    int start = 0;
    for (int j = 0; j < H; j++)
    {
      if (j == H - 1)
      {
        parts.push_back(make_pair(start, H - 1));
      }
      else if (bit & (1 << j))
      {
        parts.push_back(make_pair(start, j));
        start = j + 1;
      }
    }
    int64_t cnt = parts.size() - 1;
    vector<int> tmp1(parts.size(), 0);
    for (int w = 0; w < W; w++)
    {
      vector<int> tmp2(parts.size(), 0);
      for (int j = 0; j < parts.size(); j++)
      {
        for (int h = parts.at(j).first; h <= parts.at(j).second; h++)
        {
          if (A.at(h).at(w) == '1')
            tmp2.at(j)++;
        }
      }
      for (int j = 0; j < parts.size(); j++)
      {
        if (tmp2.at(j) > K)
        {
          cnt += pow(10, 6);
          break;
        }
        if (tmp1[j] + tmp2[j] > K)
        {
          for (int k = 0; k < parts.size(); k++)
            tmp1.at(k) = tmp2.at(k);
          cnt++;
          break;
        }
        tmp1.at(j) += tmp2.at(j);
      }
    }
    ans = min(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
N, K = map(int, input().split())
S = input()

seq = [1] if S[0] == '1' else [0, 1]
for i in range(1, N):
    if S[i - 1] == S[i]:
        seq[-1] += 1
    else:
        seq.append(1)
if S[N - 1] == '0':
    seq.append('0')

n0 = (len(seq) - 1) // 2
if n0 <= K:
    ans = N
else:
    total = [0]
    for s in seq:
        total.append(total[-1] + int(s))

    ans = 0
    for i in range(n0 - K + 1):
        ans = max(ans, total[(i + K) * 2 + 1] - total[i * 2])

print(ans)


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

struct Card {char suit;int value;};

void bubble(struct Card A[], int N){
  for(int i=0;i<N;i++){
    for(int j=N-1;j>=i+1;j--){
      if(A[j].value<A[j-1].value){
	Card t=A[j]; A[j]=A[j-1]; A[j-1]=t;
      }
    }
  }
}

void selection(struct Card A[], int N){
  for(int i=0;i<N;i++){
    int minj=i;
    for(int j=i;j<N;j++){
      if(A[j].value<A[minj].value)minj=j;
    }
    Card t=A[i]; A[i]=A[minj]; A[minj]=t;
  }
}

void print(struct Card A[], int N){
  for(int i=0;i<N;i++){
    if(i>0)cout<<" ";
    cout<<A[i].suit<<A[i].value;
  }
  cout<<endl;
}

bool isStable(struct Card C1[], struct Card C2[], int N){
  for(int i=0;i<N;i++){
    if(C1[i].suit!=C2[i].suit)return false;
  }
  return true;
}

int main(){
  Card C1[100], C2[100];
  int N;
  char ch;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>C1[i].suit>>C1[i].value;
  }
  for(int i=0;i<N;i++)C2[i]=C1[i];
  
  bubble(C1,N);
  selection(C2,N);
  print(C1,N);
  cout<<"Stable"<<endl;
  print(C2,N);
  if(isStable(C1,C2,N)){
    cout<<"Stable"<<endl;
  }else{
    cout<<"Not stable"<<endl;
  }
}



Measured memory_bytes: 3092
#include <bits/stdc++.h>
using i64 = long long;

class UF {
    int *par;
    int *rank;

    public:
    UF(int size) : par(new int[size]), rank(new int[size]()) {
        for (int i = 0; i < size; i++) par[i] = i;
    }
    ~UF() { delete[] par; delete[] rank; }

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

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return;

        if (rank[x] < rank[y]) par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y]) rank[x]++;
        }
    }
};

int main() {
    int n, m;
    std::cin >> n >> m;
    UF uft(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        std::cin >> x >> y >> z;
        uft.unite(x - 1, y - 1);
    }
    std::set<int> s;
    for (int i = 0; i < n; i++) s.insert(uft.root(i));
    std::cout << s.size() << std::endl;

    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector <int> h(n);
    rep (i, n) cin >> h[i];

    int ans = 1, macs = h[0];
    range (i, 1, n) {
        if ( macs <= h[i] ) {
            ans++;
            macs = h[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define R register
#define mp make_pair
#define ll long long
#define pii pair<int, int>
using namespace std;

int n;
string s;
map<string, int> app;

template <class T>
inline void read(T &x) {
	x = 0;
	char ch = getchar(), w = 0;
	while (!isdigit(ch)) w = (ch == '-'), ch = getchar();
	while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	x = w ? -x : x;
	return;
}

int main() {
	cin >> n;
	while (n--) {
		cin >> s;
		++app[s];
	}
	int maxV = 0;
	for (auto &k : app) maxV = max(maxV, k.second);
	for (auto &k : app) {
		if (k.second == maxV) cout << k.first << endl;
	}
	return 0;
}

Measured memory_bytes: 25216
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FILL(Itr,n) fill((Itr).begin(),(Itr).end(),n)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

vector<long long> PrimeFactorization(long long n) {
    vector<long long> res;
    long long t = n;
    for(long long i=2;i*i<=t; ){
        if(n%i==0){
            res.push_back(i);
            n/=i;
        }else{
            i++;
        }
    }
    if(n!=1)res.push_back(n);
    return res;
}

int main(){
    
    ll n; cin>>n;
    cout<<n<<": ";
    
    vector<ll> ans = PrimeFactorization(n);
    
    REP(i,ans.size()-1)cout<<ans[i]<<" ";
    cout<<ans[ans.size()-1]<<endl;
    
    return 0;
}

Measured memory_bytes: 3152
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

list = []
for i in range(1, m+1):
    list.append(i)
 
 
wa = 0
ans = 0
 
for i in itertools.combinations_with_replacement(list, n):
    for a,b,c,d in abcd:
        # print(a,b,c,d)
        # if a <= len(i) and b <= len(i):
        if i[b-1]-i[a-1]==c:
            wa += d
            ans = max(ans, wa)
    wa = 0
 
print(ans)

Measured memory_bytes: 9088
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
inline int read(){
	int f=1,ans=0;char c;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
	return ans*f;
}
const int MAXN=100001;
int a[MAXN],n,l;
void work(int x){
	for(int i=n-1;i>x;i--) printf("%d\n",i);
	for(int i=1;i<=x;i++) printf("%d\n",i);
	return;
}
int main(){
	n=read(),l=read();
	for(int i=1;i<=n;i++) a[i]=read();
	for(int i=1;i<n;i++)
	     if(a[i]+a[i+1]>=l){printf("Possible\n");work(i);return 0;}
	printf("Impossible\n");
	return 0; 
}


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

int main() {
	int c, a, n, i, k, j, t = 0;
	cin >> k;
	for(i = 1; i <= k; i++) {
		cin >> c >> a >> n;
		for (j = c; j != 0; j--) {
			if (c != 0 && a != 0 && n != 0) {
				c--;
				a--;
				n--;
				t++;
			}else if (c >= 2 && a != 0) {
				c = c - 2;
				a--;
				t++;
			}else if (c >= 3) {
				c = c - 3;
				t++;
			}
		}
		cout << t << endl;
		t = 0;
	}
}


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

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

    int out = 0;
    int next = 1;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        if (a == next) {
            next++;
        } else {
            out++;
        }
    }

    if (out < n) {
        cout << out << endl;
    } else {
        cout << -1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;



int main() {
    int t;
    cin >>t ;
    string str;
    int ara[4] = {0,0,0,0};
    while(t--) {
        cin >> str;
        if(str == "AC")
            ara[0] += 1;
        else if(str == "WA")
            ara[1] += 1;
        else if(str == "TLE")
            ara[2] += 1;
        else
            ara[3] = ara[3] += 1;
        }

    for(int i=0; i<4; i++) {
        if(i == 0)
            cout << "AC x ";
        else if(i == 1)
            cout << "WA x ";
        else if(i == 2)
            cout << "TLE x ";
        else
            cout << "RE x ";

        cout << ara[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3628
#include <iostream>
#include <string>
using namespace std;
int main()
{
	int N,K;
	string S;
	cin>>N;
	cin>>K;
	cin>>S;
	if(S[K-1]=='A')
		S[K-1]='a';
	else if(S[K-1]=='B')
		S[K-1]='b';
	else
		S[K-1]='c';
	cout<<S;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        // 変数
        int n = 0; // ページ数
        int result = 0; // 印刷枚数

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();

        // 処理
        if (n%2 == 0) {
            result = n/2;
        } else {
            result = (n+1)/2;
        }

        // 出力
        System.out.print(result);
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<stdio.h>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;

int main(){
    long long K, A, B;
    cin >> K >> A >> B;
    K -= A - 1;
    long long S = A;
    if(2 < B - A){
        if(K % 2 != 0) S++;
        S += K / 2 * (B - A);
    }
    else{
        S += K;
    }
    cout << S;
    return 0;
}

Measured memory_bytes: 256