akhauriyash/Code-Regression huggingface dataset:
import sys
import heapq
from operator import itemgetter
from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

def sol():
    x, y = map(int, input().split())

    a = 0
    if y < x:
        a = abs(x - y) + 2
    else:
        a = abs(x - y)

    ans = min(a, abs(x + y) + 1)
    print(ans)


sol()

Measured memory_bytes: 3408
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

int main(){
	string S;
	cin >> S;
	for(int i = 0; i < S.size() - 1; i++){
		if(S[i] == S[i+1]){
			cout << i+1<< " " << i + 2<< endl;
			return 0;
		}
	}
	for(int i = 0; i < S.size() - 2; i++){
		if(S[i] == S[i+2]){
			cout << i+1<< " " << i + 3<< endl;
			return 0;
		}
	}

	cout << -1 << " " << -1 << endl;
	return 0;
}


Measured memory_bytes: 512
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n = readline() |> parseInt
	it = 1
	ia = 1
	f = 1
	for i in 1:n
		t,a = readline() |> split |> parseMap
    	tf = it%t==0?div(it,t):div(it,t)+1
    	af = ia%a==0?div(ia,a):div(ia,a)+1
		f = max(tf,af)
		it = f*t
		ia = f*a
	end
	println(it+ia)
end

main()

Measured memory_bytes: 114592
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n, y;
	scanf("%d %d", &n, &y);
	for(int i = 0; i <= n; i++)
	{
		for(int j = 0; j <= n - i; j++)
		{
			if(y == 10000 * i + 5000 * j + 1000 * (n - i - j))
			{
				printf("%d %d %d\n", i, j, (n - i - j));
				return 0;
			}
		}
	}	
	printf("-1 -1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define vi vector<int>
#define pii pair<int,int>
using namespace std;

vector<int> ans;
vector<vi> edge;

void FindDepth(const int & n,int v){
	vector<bool> isVisit(n);
	vector<int> dis(n);	
	queue<pii> que;
	que.push(make_pair(v,0));
	isVisit[v] = true;
	while(!que.empty()){
		int curX = que.front().first;
		int cur_val = que.front().second;
		que.pop();
		dis[cur_val]++;
		for(int i=0;i<edge[curX].size();i++){
			int next = edge[curX][i];
			if(isVisit[next]) continue;
			que.push(make_pair(next,cur_val+1));
			isVisit[next] = true;
		}
	}
	for(int i=1;i<n;i++){
		ans[i] += dis[i];
	}
}	

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n,x,y; cin>>n>>x>>y;
	ans = vi(n);
	edge = vector<vi>(n);
	for(int i=0;i<n-1;i++){
		edge[i].push_back(i+1);
		edge[i+1].push_back(i);
	}
	edge[x-1].push_back(y-1);
	edge[y-1].push_back(x-1);
	for(int i=0;i<n;i++){FindDepth(n,i);}
	for(int i=1;i<n;i++)cout<<ans[i]/2<<'\n';
}

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

// Shabdan Batyrkulov

using namespace std;

#define MAX 107
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double

const long long N = (int)1e5 + 7;
const int inf = (int)1e9 + 7;

int main () {
        string a, b, c; cin >> a >> b >> c;
        char l_a = a[a.size() - 1];
        char l_b = b[b.size() - 1];
        int sz = min(int(b.size()), int(c.size()));
        for (int i = 0; i < sz; i++) {
                if (l_a == b[i]) {
                        if (l_b == c[i]){
                                puts("YES");
                                return 0;
                        }
                }
        }
        puts("NO");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>
#include <set>
#include <deque>
#include <bitset>
//#include "mylib.h"

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOREACH(i, v) for(auto i = v.begin(); i != v.end(); i++)
#define PRINT(n) cout << n << endl

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    int n, x[30], y[30];
    string s[55];
    cin >> n;
    REP(i, n)	cin >> s[i];
	REP(i, 26){
		x[i] = 0, y[i] = 0;
	}
	for(int i = 0; i < s[0].length(); i++){
		x[s[0][i]-'a']++;
	}
	for(int i = 1; i < n; i++){
		for(int j = 0; j < s[i].length(); j++){
			y[s[i][j]-'a']++;
		}
		REP(k, 26) x[k] = min(x[k], y[k]);
		REP(k, 26) y[k] = 0;
	}

	for(int i = 0; i < 26; i++){
		for(int j = 0; j < x[i]; j++){
			if(x[i] > 0){
				cout << (char)('a'+i);
			}
		}
	}
	cout << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int N;
    cin >> N;
    int tmp=0;
    for(int i=0; i<N; i++){
        int h;
        cin >> h;
        //cout << tmp << ' ' << h << endl;
        if(tmp<=h){
            tmp=h;
        }else if(tmp==h+1){
            continue;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    if ((x == (W / 2.0)) && (y == (H / 2.0))){ // ドンピシャで中点の時，x軸 or y軸で割れる
        cout << H * W / 2.0 << " " << 1 << endl;
    } else { // そうでない時は(x, y) と中点を通るものは必ずピッタリ２つに分割してくれる
        cout << H * W / 2.0 << " " << 0 << endl;
    }
}

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


Measured memory_bytes: 256
n = int(input())
s = input()

x = 0
x_max = 0
s_list = []

for i in s:
    s_list.append(i)

# print(s_list)

for i in s_list:
    if i == 'I':
        x += 1
        if x > x_max:
            x_max = x
    elif i == 'D':
        x -= 1


print(x_max)


Measured memory_bytes: 9104
#include <stdio.h>
#include <ctype.h>
int main(void){
    char ch;
    while(1){
        scanf("%c",&ch);
        if(islower(ch))
        {
            ch=toupper(ch);
        }else {
            ch=tolower(ch);
        }
        printf("%c",ch);
        if(ch=='\n')break;
    }
        return 0;
}
 



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

#define ll long long
#define lli long long int
#define loop(i,x,n) for(lli i=x; i<=n; i++)
#define rloop(i,n,x) for(lli i=n; i>=x; i--)

typedef vector<ll> v64;
typedef vector<pair<ll,ll>> vp64;
typedef vector<bool> vbo;
typedef set<ll> s64;
typedef set<bool> sbo;
typedef unordered_set<ll> us64;
typedef map<ll,ll> m64;
typedef unordered_map<ll,ll> um64;

int main(){
    int n;
    cin>>n;
    ll ans = 0;
    if(n&1){
        // n--;
        ans = ((n-1)/2);
        ans *= n;
        // ans++;
    }   
    else{
        ans = (n/2);
        ans*=n-1;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
n, m, c = map(int, input().split())
bs = np.array(list(map(int, input().split())))

ans = 0

for i in range(n):
  as_ = np.array(list(map(int, input().split())))
  if np.sum(as_*bs)+c > 0:
    ans += 1
print(ans)

Measured memory_bytes: 12488
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1<<19;
const double th=2*M_PI/N;
typedef complex<double> P;
 
void FFT(P a[],double t) {
  for(int m=N;m>=2;m>>=1,t*=2) {
    int mh=m>>1;
    for(int i=0;i<mh;i++) {
      P w=exp(t*i*P(0,1));
      for(int j=i;j<N;j+=m) {int k=j+mh;P x=a[j]-a[k];a[j]+=a[k];a[k]=w*x;}
    }
  }
  for(int j=1,i=0;j<N-1;j++){for(int k=N>>1;k>(i^=k);k>>=1);if(j<i)swap(a[i],a[j]);}
}

ll a[N],b[N],aa[N],bb[N];P c[N],d[N];
void solve() {
  for(int i=0;i<N;i++)c[i]=P(a[i],0),d[i]=P(b[i],0);
  FFT(c,th);FFT(d,th);
  for(int i=0;i<N;i++)c[i]*=d[i];
  FFT(c,-th);
  for(int i=0;i<N;i++)a[i]=round(c[i].real()/N);
}

int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  int n,m,q,M=210000;
  cin >> n >> m >> q;
  int x[n],y[m];
  for(int i=0; i<n; i++) cin >> x[i];
  for(int i=0; i<m; i++) cin >> y[i];
  int cc[n+1],dd[m+1];
  cc[0]=dd[0]=0;
  for(int i=0; i<n; i++) cc[i+1]=cc[i]+x[i];
  for(int i=0; i<m; i++) dd[i+1]=dd[i]+y[i];
  for(int i=0; i<=n; i++) {
    a[cc[i]]++;
    b[M-cc[i]]++;
  }
  solve();
  for(int i=0; i<M; i++) aa[i]=a[M-i];
  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));
  for(int i=0; i<=m; i++) {
    a[dd[i]]++;
    b[M-dd[i]]++;
  }
  solve();
  for(int i=0; i<M; i++) bb[i]=a[M-i];
  memset(a,0,sizeof(a));
  memset(b,0,sizeof(b));
  for(int i=0; i<M; i++) {
    a[i]=aa[i];
    b[M-i]=bb[i];
  }
  a[0]=b[M]=0;
  solve();
  while(q--) {
    int k;
    cin >> k;
    if(k) cout << a[M-k]+a[M+k] << endl;
    else cout << a[M] << endl;
  }
  return 0;
}


Measured memory_bytes: 31976
import java.util.Scanner;

public class Main {

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

		int year = scan.nextInt();
		if (year == 1) {
			System.out.println("Hello World");
		} else {
			int first = scan.nextInt();
			int second = scan.nextInt();
			System.out.println(first + second);
		}
	}
}

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

int main(){
  string s;
  cin >> s;
  int C0 = count(s.begin(), s.end(), '0');
  int C1 = count(s.begin(), s.end(), '1');
  cout << 2 * min(C0, C1) << endl;
  return 0;
}


Measured memory_bytes: 512
//templates
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>
#include <map>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

//main
int main(){
  int N;
  cin >> N;
  vector<int> W(N);
  vector<int> ans(N-1);
  rep(i,N) cin >> W[i];
  int sum = accumulate(ALL(W),0);
  int psum;
  rep(i,N-1){
    psum = accumulate(W.begin(),W.begin()+i+1,0);
    ans[i] = abs(sum-2*psum);
  }
  cout << *min_element(ALL(ans)) << endl;
}



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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();
		
		StringBuffer inputBf = new StringBuffer(input);
		StringBuffer reverse = inputBf.reverse();
		String reverseStr = reverse.toString();
		
		if(input.equals(reverseStr)){
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}

	}

}


Measured memory_bytes: 22484
#include <bits/stdc++.h>
#include <atcoder/all>

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

using namespace std;
using namespace atcoder;
using ll = long long;

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

    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    int a;
    rep(i, n) {
        cin >> a;
        fw.add(i, a);
    }
    int s, l, r;
    rep(i, q) {
        cin >> s >> l >> r;
        if(s) {
            printf("%lld\n", fw.sum(l, r));
        } else {
            fw.add(l, r);
        }
    }

    return 0;
}

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

int main()
{
	map<string,int> memo;
	int n;
	while(cin >> n){
		if(n==0)
			break;
		string str;
		int prise;
		for(int i=0;i<n;i++){
			cin >> str >> prise;
			memo[str] = prise;
		}
		int resipi;
		cin >> resipi;
		map<string,int> resi;
		int count;
		string o;
		for(int i=0;i<resipi;i++){
			cin >> str >> count;
			resi[str] = 0;
			for(int j=0;j<count;j++){
				cin >> o;
				resi[str] += memo[o];
			}
			if(resi[str] < memo[str])
				memo[str] = resi[str];
		}
		string final;
		cin >> final;
		cout << memo[final] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
from networkx import*
_,*s=open(i:=0)
g=[]
for t in s:
 i+=1;j=0
 for u in t:g+=[(k:=i*20+j,k+20)]*(u>'#'<(s+['#'*k])[i][j])+[(k,k+1)]*(u>'#'<t[j+1]);j+=1
print(max(t[i]for _,t in shortest_path_length(Graph(g))for i in t))

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

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


Measured memory_bytes: 256
s = input()
n = int(input())
for i in range(n):
	t = input().split()
	a = int(t[1])
	b = int(t[2])
	if t[0] == "print":
		print(s[a:b + 1])
	elif t[0] == "replace":
		s = s[0 : a] + t[3] + s[b + 1 : len(s)]
	elif t[0] == "reverse":
		u = s[a : b + 1]
		s = s[0 : a] + u[ : : -1] + s[b + 1 : len(s)]


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

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

int main(){
  map<string,int> vec;
  int n;
  cin>>n;
  string s;
  vector<string> vecb(n);
  for(int i=0;i<n;i++){
    cin>>vecb.at(i);
  }
  for(int i=0;i<n;i++){
    vec[vecb.at(i)]++;
  }
  int z=0;
  for(int i=0;i<n;i++){
    z=max(z,vec.at(vecb.at(i)));
  }
  sort(vecb.begin(),vecb.end());
  for(int i=0;i<n;i++){
    if(i==0){
      if(vec.at(vecb.at(i))==z){
        cout<<vecb.at(i)<<endl;
      }
      continue;
    }
    if(vecb.at(i)!=vecb.at(i-1)&&vec.at(vecb.at(i))==z){
      cout<<vecb.at(i)<<endl;
    }
  }
}

Measured memory_bytes: 27136
N = int(input())
m = list(map(int, input().split()))
b = list(map(int, input().split()))
s = 0
for i in range(N):
  l = min(m[i],b[i])
  s += l
  m[i] -= l
  b[i] -= l
  
  r = min(m[i+1],b[i])
  s += r
  m[i+1] -= r
print(s)

Measured memory_bytes: 18624
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		List<Integer> result = new ArrayList<Integer>();
		String[] n;

		while (true) {

			String line = sc.nextLine();
			n = line.split(" ");

			if (n[1].equals("?")) {
				break;
			}

			int a = Integer.parseInt(n[0]);
			int b = Integer.parseInt(n[2]);
			if (n[1].equals("+")) {
				result.add(a + b);
			} else if (n[1].equals("-")) {
				result.add(a - b);
			} else if (n[1].equals("*")) {
				result.add(a * b);
			} else if (n[1].equals("/")) {
				result.add(a / b);

			}

		}// whileここまで
		for (Integer i : result) {
			System.out.println(i);

		}

	}

}



Measured memory_bytes: 26176
#include<stdio.h>
int main(){
    int a,b,x;
    scanf("%d %d",&a,&b);
    x=a+b;
    if(x<a-b){
        x=a-b;
    }
    if(x<a*b){
        x=a*b;
    }
    printf("%d\n",x);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    ll x;
    cin >> x;
    ll ary[n];
    rep(i,n) cin >> ary[i];

    sort(ary, ary+n);
    int ans = 0;
    rep(i,n)
    {
        if (x>=ary[i])
        {
            x-=ary[i];
            ans++;
        }
        else
        {
            break;
        }
    }
    if (ans==n && x!=0) ans--;
    cout << ans << endl;
    
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    ll min_a = 1e+10;
    ll max_a = 0;

    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;

        min_a = min(min_a, a);
        max_a = max(max_a, a);
    }

    cout << max_a - min_a << endl;

    return 0;
}


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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "Yes" : "No");}
//----------------------------------------------------------------

int main(void) {
  int h, w, k;
  cin >> h >> w >> k;
  vecll2(dp, h+1, w+2);
  dp[0][1]=1;
  vecll num={1,2,3,5,8,13,21};
  rep(i,h){
    REP(j,1,w+1){
      ll p = max(0ll, j-2-1);
      ll q = max(0ll, w-(j+1));
      dp[i+1][j] += dp[i][j-1]*num[p]*num[q];
      dp[i+1][j] %= MOD;

      p = max(0ll, j-1-1);
      dp[i+1][j] += dp[i][j]*num[p]*num[q];
      dp[i+1][j] %= MOD;

      q = max(0ll, w-(j+2));
      dp[i+1][j] += dp[i][j+1]*num[p]*num[q];
      dp[i+1][j] %= MOD;
    }
  }

  prt(dp[h][k]);
}


Measured memory_bytes: 3588
import numpy as np
N, M, X = map(int, input().split())
CA = []
for _ in range(N):
  CA.append(list(map(int, input().split())))

CA = np.array(CA)
ans = []
for i in range(2 ** N):
  tmp = [False] * (N)
  pattern = []
  for j in range(N):
    if i >> j & 1:
      tmp[j] = True
  if len(CA[tmp]) == 0:
    continue
  pattern = CA[tmp]
  pattern = pattern.reshape(-1, M+1)
  if sum(pattern[:, 1:M+1].sum(axis=0) >= X) == M:
    price = pattern[:, 0].sum()
    ans.append(price)
if len(ans) == 0:
  print(-1)
  exit()
print(min(ans))

Measured memory_bytes: 27488
// In the nAme Of Allah
#include<bits/stdc++.h>
#define pb push_back
#define ins insert
#define f first
#define pp pop_back
#define ll long long int
#define fst  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
ll a,b,c;
int main()
{
   fst;
   cin>>a>>b>>c;
   if(a<=(b*c))
   {
       cout<<"Yes";
   }
   else
   {
       cout<<"No";
   }
   return 0;
}


Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>

typedef long long ll;
using namespace std;

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> l(n);
    for(int& lc : l) cin >> lc;
    int ctr = 0;
    int ret = n+1;
    for(int i=0; i<n; ++i){
        ctr += l[i];
        if(ctr > x){ret = i+1; break;}
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int k, n;
	cin>>k>>n;
	vector<int> v;
	int a;
	rep(i, n){
		cin>>a;
		v.push_back(a);
	}
	int b=0;
	rep(i, n){
		if(i==n-1){
			b=max(b, k+v[0]-v[i]);
		}
		else{
			b=max(b, v[i+1]-v[i]);
		}
	}
	cout<<k-b<<endl;
	return 0;
}

Measured memory_bytes: 1400
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.TreeMap;
import java.util.ArrayDeque;
import java.awt.Point;
 
class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int T = sc.nextInt();
        int[] A = new int[N];
        for(int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }
        int min = A[0];
        int B = 0;
        int ans = 0;
        for(int i=1; i<N; i++) {
            min = Math.min(min, A[i - 1]);
            if(B==A[i]-min) {
                ans++;
            }
            else{
                B = Math.max(B, A[i] - min);
                if(B==A[i]-min) {
                    ans = 1;
                }
            }
        }
        System.out.println(ans);
    } 
}

Measured memory_bytes: 50492
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] H = new int[N+1];
        for (int i = 1; i <= N; i++) {
                H[i] = sc.nextInt();
        }
        boolean[] b = new boolean[N+1];
        for (int i = 0; i < M; i++) {
                int A1 = sc.nextInt();
                int B1 = sc.nextInt();
                if (H[A1] < H[B1]) {
                        b[A1] = true;
                } else if (H[A1] > H[B1]) {
                        b[B1] = true;
                } else {
                        b[A1] = true;
                        b[B1] = true;
                }
        }
        int count = 0;
        for (int i = 1; i < b.length; i++) {
                if (!b[i]) count++;
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 59316
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define INF INT_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n,m,c;cin >> n >> m >> c;
  int a[100][100],b[100];
  rep(i,m) cin >> b[i];
  rep(i,n) rep(j,m) cin >> a[i][j];

  int ans=0;
  rep(i,n){
    int sum=0;
    rep(j,m){
      sum+=a[i][j]*b[j];
    }
    if(sum+c>0) ans++;
  }

  cout << ans << endl;

}

Measured memory_bytes: 256
def make_divisors(n):
    divisors = set()
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.add(i)
            if i != n // i:
                divisors.add(n//i)
    return divisors

X = int(input())
for i in range(X,99992):
    if len(make_divisors(i)) == 2:
        print(i)
        break
else:
    print(100003)

Measured memory_bytes: 9280
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<vector<int>> in(n);
  for (int i = 0; i < n; i++) {
    int t, d;
    cin >> t >> d;
    in[--t].push_back(d);
  }
  for (int i = 0; i < n; i++) sort(in[i].rbegin(), in[i].rend());
  long long cur = 0;
  long long ans = 0;
  priority_queue<int, vector<int>, greater<int>> que;
  sort(in.rbegin(), in.rend());
  // for (int i = 0; i < n; i++) {
  //   for (int j : in[i]) cerr << j << " ";
  //   cerr << endl;
  // }
  for (int i = 0; i < min(n, k); i++) {
    if (in[i].empty()) continue;
    cur += in[i][0];
    for (int j = 1; j < (int) in[i].size(); j++) {
      que.push(in[i][j]);
      cur += in[i][j];
    }
    while ((int) que.size() > max(0, k - (i + 1))) {
      cur -= que.top();
      que.pop();
    }
    ans = max(ans, cur + 1LL * (i + 1) * (i + 1));
  }
  cout << ans << endl;
  return 0;
}

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

 int main() {
   int N;
   int A=0;
   int B=0;
   cin>>N;
  vector<int> test(N);
  
  for(int i=0;i<N;i++){
   cin>>test.at(i);
   }
   sort(test.rbegin(),test.rend());
  
 for(int i=0;i<N;i=i+2){
   A=A+test.at(i);
 }
 for(int i=1;i<N;i=i+2){
   B=B+test.at(i);
 }
   cout<<A-B<<endl;
 }

Measured memory_bytes: 3572
#include<stdio.h>
 
int main() {
    long long n, num = 0;
    scanf("%lld", &n);
    if (n % 2 == 1) printf("0\n");
    else {
        n = n / 10;
        while (n) {
            num += n;
            n /= 5;
        }

        printf("%lld\n", num);
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>>
using namespace std;
int main(){
  string o,e;
  cin>>o>>e;
  int a,b;
  a = o.length();
  b = e.length();
  if(a==b){
    for(int i=0;i<a;++i){
      cout<<o[i]<<e[i];
    }
  }
  else{
    for(int i=0;i<b;++i){
      cout<<o[i]<<e[i];
    }
    cout<<o[a-1];
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        long A = sc.nextLong();
        long B = sc.nextLong();

        long ans = xorToX(A - 1) ^ xorToX(B);

        System.out.println(ans);
    }

    private static long xorToX(long A) {
        if (A <= 0) return 0;
        A++;
        long ans = 0;
        for (int i = 0; i <= 50; i++) {
            long loop = (1l << (i + 1));
            long numOfOne = (A / loop) * (loop / 2) + Math.max(0, (A % loop) - (loop / 2));
            if (numOfOne % 2 == 1) {
                ans += (1l << i);
            }
        }
        return ans;
    }
}

Measured memory_bytes: 22612
#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string.h>
#include <stdlib.h>
#include <limits>
#include <iomanip>
using namespace std;

int main(){

    int N, M;
    cin >> N >> M;

    int pena[N] = {};
    int AC[N] = {};

    for( int i = 0 ; i < M ; i++ ){
        int tmp_p; string tmp_S;
        cin >> tmp_p >> tmp_S;

        if(       tmp_S == "AC" && AC[tmp_p - 1] == 0 ){

            AC[tmp_p-1] = 1;

        }else if( tmp_S == "WA" && AC[tmp_p - 1] == 0 ){

            pena[tmp_p-1]++;

        }

    }

    int sum_pena = 0; int sum_AC = 0;
    for( int i = 0 ; i < N ; i++ ){
        sum_AC  += AC[i];
        if( AC[i] == 0){
            continue;
        }else{
            sum_pena += pena[i];
        }
    }

    cout << sum_AC << "\t" << sum_pena << endl;

}


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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if((a == b && b != c) || (b == c && c != a) || (a == c && c != b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import sys
import fractions


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    a, b = list(map(int, input().rstrip('\n').split()))
    gcd = fractions.gcd(a, b)
    cnt = 1
    for i in range(2, int(gcd ** 0.5) + 1):
        if gcd % i == 0:
            cnt += 1
            while True:
                if gcd % i == 0:
                    gcd //= i
                else:
                    break
    print(cnt + 1 if gcd != 1 else cnt)


if __name__ == '__main__':
    solve()


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

int main() {
  unsigned long long x;
  int i=0;
  unsigned long long a=100;
  cin>>x>>i>>a;
  while(a<x){
    i++;
    a=a+a/100;
  }
  cout<<i<<endl;
      
    



}

Measured memory_bytes: 3592
import java.util.*;

class Main{
	static final int nbits = 32;
	static BitSet bs;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		BitSet bsa = new BitSet(nbits);
		BitSet bsb = new BitSet(nbits);
		for(int i = 0; i < nbits; i++){
			if((a & (1 << i)) != 0) bsa.set(i);
		}
		for(int i = 0; i < nbits; i++){
			if((b & (1 << i)) != 0) bsb.set(i);
		}
		makeBitSet(bsa);
		bs.and(bsb);
		printBitSet(bs);
		System.out.print("\n");
		makeBitSet(bsa);
		bs.or(bsb);
		printBitSet(bs);
		System.out.print("\n");
		makeBitSet(bsa);
		bs.xor(bsb);
		printBitSet(bs);
		System.out.print("\n");
	}
	static void makeBitSet(BitSet b){
		bs = new BitSet(nbits);
		for(int i = 0; i < nbits; i++){
			if(b.get(i)) bs.set(i);
		}
	}
	static void printBitSet(BitSet b){
		for(int i = nbits - 1; i >= 0; i--){
			if(b.get(i)) System.out.print(1);
			else System.out.print(0);
		}
	}
}



Measured memory_bytes: 26248
N, Y = map(int, input().rstrip().split())
x, y, z = -1, -1, -1
for i in range(N+1):
    for j in range(N-i+1):
        res = 10000*i + 5000*j + 1000*(N-i-j)
        if res > Y:
            break
        elif res == Y:
            x, y, z = i, j, N-i-j
        if x != -1:
            break
    if x != -1:
        break
print(x,y,z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
map<int, string> mp;

/* function */
/* main */
int main(){
    mp[2] = "hon";
    mp[4] = "hon";
    mp[5] = "hon";
    mp[7] = "hon";
    mp[9] = "hon";
    mp[0] = "pon";
    mp[1] = "pon";
    mp[6] = "pon";
    mp[8] = "pon";
    mp[3] = "bon";
    int N;
    cin >> N;
    int d = N % 10;
    cout << mp[d] << '\n';
}


Measured memory_bytes: 3640
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] a = new int[n];
		for(int i=0;i<n;i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int ans = 0;
		int num = a[0];
		int count = 1;
		for(int i=1;i<n;i++) {
			if(a[i]!=num) {
				if(count%2==1) ans++;
				num = a[i];
				count = 1;
			}else {
				count++;
			}
		}
		if(count%2==1) ans++;
		
		System.out.println(ans);
		in.close();
	}

}


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

using namespace std;
using ll = long long;

int main() {
    ll N = 0;
    cin >> N;
    vector<ll> A(N + 1,0);
    vector<ll> a(N + 1,0);
    for(ll i = 0; i < N + 1; i++) {
        cin >> A.at(i);
    }
    vector<ll> B(N,0);
    vector<ll> b(N,0);
    for(ll i = 0; i < N; i++) {
        cin >> B.at(i);
    }
    a = A;
    b = B;
    ll ans = 0;
    for(ll i = 0; i < N; i++) {
        ans += min(A.at(i), B.at(i));
        B.at(i) -= min(A.at(i), B.at(i));
        ans += min(A.at(i + 1), B.at(i));
        A.at(i + 1) -= min(A.at(i + 1), B.at(i));
    }
    
    ll anss = 0;
    A = a;
    B = b;
    reverse(A.begin(),A.end());
    reverse(B.begin(),B.end());
    for(ll i = 0; i < N; i++) {
        anss += min(A.at(i), B.at(i));
        B.at(i) -= min(A.at(i), B.at(i));
        anss += min(A.at(i + 1), B.at(i));
        A.at(i + 1) -= min(A.at(i + 1), B.at(i));
    }

    cout << max(ans, anss) << endl;

    return 0;
}

Measured memory_bytes: 6336
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
from fractions import gcd
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

from itertools import permutations
from math import factorial, hypot

#############
# Main Code #
#############

N = getN()

ans = []
sq = math.floor(math.sqrt(N))
for i in range(sq, 0, -1):
    if N % i == 0:
        ans = [i, N // i]
        break
print(max(len(str(ans[0])), len(str(ans[1]))))

Measured memory_bytes: 64108
#include <stdio.h>
#include <math.h>
int main(){
    int i, j;
    int n, temp, count = 0;
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &temp);
        for(j = 2; j <= sqrt(temp); j++){
            if (temp%j == 0) break;
        }
        if (j>sqrt(temp) || sqrt(temp)<2){
count++; }
}
    printf("%d\n", count);
return 0; }


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

int main()
{
	int n;
	cin >> n;
	vector<int> as(n), bs(n), cs(n - 1);
	for (auto &&a : as)
	{
		cin >> a;
		a--;
	}
	for (auto &&b : bs)
	{
		cin >> b;
	}
	for (auto &&c : cs)
	{
		cin >> c;
	}

	int ans = bs[as[n - 1]];

	for (int i = 0; i < n - 1; i++)
	{
		if (as[i] + 1 == as[i + 1])
		{
			ans += cs[as[i]];
		}
		ans += bs[as[i]];
	}

	cout << ans << endl;

	return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin>>n>>q;
    int s[200005], t[200005], x[200005];
    set<int>v;
    pair<int,int>a[1000005];
    for(int i=0;i<n;i++){
        cin>>s[i]>>t[i]>>x[i];
        a[2*i]=make_pair(s[i]-x[i],x[i]);
        a[2*i+1]=make_pair(t[i]-x[i],-x[i]);
    }
    int i=0;
    n*=2;
    sort(a,a+n);
   
    while(q--){
        int d;
        cin>>d;
        while(i<n && a[i].first<=d){
            
            if(a[i].second>0){ v.insert(a[i].second);}
            else v.erase((-1)*a[i].second);
            
            i++;
        }
        if(v.empty())
              cout<<-1<<endl;
        else 
            cout<<*v.begin()<<endl;
    }
}
    
    


Measured memory_bytes: 23136
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string, copy
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7
ans = inf
count = 0; pro = 1

d, g = map(int, input().split())
g //= 100
dp=[[inf]*(10**5+10000) for i in range(11)]
dp[0][0]=0
for i in range(d):
    p,c=map(int,input().split());c//=100
    for j in range(10**5+10000):
        if dp[i][j]!=inf:
            dp[i+1][j]=min(dp[i+1][j],dp[i][j])
            for k in range(1,p):
                dp[i+1][j+(i+1)*k]=min(dp[i+1][j+(i+1)*k],dp[i][j]+k)
            dp[i+1][j+(i+1)*p+c] = min(dp[i+1][j+(i+1)*p+c],dp[i][j]+p)
for i in range(g,10**5+10000):
    ans=min(ans,dp[d][i])
print(ans)




# for i in range(1, d+1):
#     p, c = map(int, input().split())
#     c //= 100
#     # for key, value in tuple(D.items()):
#     #     print(D[key],p)
#     #     D[key+i*p+c//100] = min(D[key+i*p+c//100], D[key]+p)
#     S = D.copy()
#     for key, value in S.items():
#         for k in range(1, p):
#             # print(D[key+i])
#             D[key+i*k] = min(D[key+i*k], S[key]+k)
#         D[key+i*p+c] = min(D[key+i*p+c], S[key]+p)
# ans = inf
# for key, value in D.items():
#     # print(key,value)
#     if key >= g:
#         ans = min(ans, value)
# print(ans)


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

int P, Q, R;
const char *p;

int formula() {
  
  p++;

  switch( *p ) {
  case '-': return 2 - formula();
  case 'P': return P;
  case 'Q': return Q;
  case 'R': return R;
  case '0': return 0;
  case '1': return 1;
  case '2': return 2;
    
  case '(':
    int form1 = formula();
    int form2;
    p++;
    switch( *p ) {
    case '*':
      form2 = formula();
      p ++;
      return min( form1, form2 );
    case '+':
      form2 = formula();
      p++;
      return max( form1, form2 );
    }
  }
  
  return 0;
}

int main() {
  string str;
  
  while(getline(cin, str)) {
    int cnt = 0;
    if( str == "." ) break;
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
	for(int k=0; k<3; k++) {
	  P = i, Q = j, R = k;
	  p = &str[0]-1;
	  if( formula() == 2 ) cnt ++;
	}
      }
    }
    
    cout << cnt << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1184
#include <stdio.h>

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

void sort(int A[], int N){
  int i,j,v;
  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j] > v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    display(A,N);
  }
}

int main(){
  int N,i,j;
  int A[100];

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

  display(A,N);
  sort(A,N);

  return 0;
}



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

using namespace std;
typedef long long ll;
map<char,string>mp;
int main()
{
   mp['2']=mp['4']=mp['5']=mp['7']=mp['9']="hon";
   mp['0']=mp['1']=mp['6']=mp['8']=mp['8']="pon";
   mp['3']="bon";
   string s;
   cin>>s;
   cout<<mp[s.back()];
   return 0; 
}


Measured memory_bytes: 3596
n=int(input())
num=sorted(list(map(int,input().split())),reverse=True)
a=[]
b=[]
flag=True
for i in range(n):
  l=max(num)
  num.remove(l)
  if flag:
    a.append(l)
    flag=False
  else:
    b.append(l)
    flag=True
print(sum(a)-sum(b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

int main()
{
    string a,b;
    cin >> a >> b;
    for(int i = 0;i < b.size();i++)
    {
        cout << a[i] << b[i];
    }
    if(a.size() != b.size())
        cout << a[a.size() - 1];
    cout << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
#define mod 1000000007

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1;
    while(t--){
        int n,k; cin>>n>>k; int arr[n+1];
        for(int i=1;i<=n;i++) cin>> arr[i];
        for(int i=k+1;i<=n;i++){
            if(arr[i]>arr[i-k]){
                cout<<"Yes"<<endl;
            }else cout<<"No"<<endl;
        }

    }

}


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

using namespace std;

int main()
{
  string S;
  cin >> S;
  int p = 0, g = 0;
  int score = 0;
  for (auto c : S) {
    if (c == 'p') {
      if (p < g) p++;
      else g++, score--;
    } else {
      if (p < g) p++, score++;
      else g++;
    }
  }
  cout << score << endl;

  return 0;
}

Measured memory_bytes: 512
n = int(input())
d = sorted(list(map(int,input().split())))
m = int(input())
t = sorted(list(map(int,input().split())))
didx = 0
tidx = 0
while tidx < m and didx < n:
    if d[didx] == t[tidx]:
        didx += 1; tidx += 1
    elif d[didx] < t[tidx]:
        didx += 1
    else:
        print("NO")
        break
else:
    if tidx == m:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 36820
n = int(input())

P = list(map(int, input().split()))

Q = [0 for i in range(len(P))]

m = max(P)

def CountingSort(A, B, k):
  C = [0 for i in range(k+1)]

  for j in range(len(A)):
    C[A[j]] += 1

  for i in range(1, k+1):
    C[i] += C[i-1]

  for j in range(len(A)):
    B[C[A[j]]-1] = A[j]
    C[A[j]] -= 1

CountingSort(P, Q, m)

print(" ".join(map(str, Q)))



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

#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define MEGA_MIND ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
#define M_PI 3.14159265358979323846
#define mod 1000000007
#define endl "\n"
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;


const int N = 5e5 + 6, inf = 2e9;
int n,k;
int arr[N], dp[N];
int main()
{
	MEGA_MIND

		cin >> n >>k;
	for (int i = 0; i < n; i++)
	{
		dp[i] = inf;
		cin >> arr[i];
	}

	dp[0] = 0;
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j <= i + k; j++)
		{
			if(j<n)
				dp[j] = min(abs(arr[i] - arr[j]) + dp[i], dp[j]);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <string>
#include <vector>
#include <algorithm>

std::string parse(std::string const& s, size_t& i,
                  std::vector<std::string> const& ops, size_t preced = 0) {

  if (preced == ops.size()) {
    if (s[i] == '(') {
      auto res = parse(s, ++i, ops, 0);
      assert(s[i] == ')');
      ++i;
      return res;
    }
    assert(isalpha(s[i]));
    return std::string(1, s[i++]);
  }

  auto res = parse(s, i, ops, preced+1);
  int left = (ops[preced][0] == 'L');
  size_t leftparen = 0;
  while (i < s.length()) {
    char op = s[i];
    if (!std::count(ops[preced].begin()+1, ops[preced].end(), op)) break;
    auto tmp = parse(s, ++i, ops, preced+left);
    ++leftparen;
    res += op + tmp + ")";
  }
  return std::string(leftparen, '(') + res;
}

void solve_testcase() {
  size_t G;
  scanf("%zu", &G);

  std::vector<std::string> ops(G);
  for (size_t i = 0; i < G; ++i) {
    char A;
    size_t M;
    scanf(" %c %zu", &A, &M);
    ops[i] += A;
    for (size_t j = 0; j < M; ++j) {
      char op;
      scanf(" %c", &op);
      ops[i] += op;
    }
  }

  size_t N;
  scanf("%zu", &N);
  for (size_t i = 0; i < N; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string s = buf;
    size_t j = 0;
    printf("%s\n", parse(s, j, ops).c_str());
  }
}

int main() {
  int D;
  scanf("%d", &D);
  for (int i = 0; i < D; ++i) {
    if (i > 0) puts("");
    solve_testcase();
  }
}



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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int gcd(int x, int y){
    if(y == 0) return x;
    return gcd(y, x%y);
}

int lcm(int x, int y){
    return x / gcd(x, y) * y;
}

int div2(int x){
    int cnt = 0;
    while(!(x%2)){
        x /= 2;
        cnt++;
    }
    return cnt;
}

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    ll alcm = 1;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] /= 2;
        alcm = lcm(alcm, a[i]);
    }

    bool flag = true;
    /*
    int v = div2(a[0]);
    for (int i = 1; i < n; ++i) {
        if(v != div2(a[i])) flag = false;
    }*/
    for (int i = 0; i < n; ++i) {
        if((alcm / a[i]) % 2 != 1) flag = false;
    }

    if(flag){
        if(alcm > m) cout << 0 << endl;
        else cout << 1 + (m - alcm) / (2 * alcm) << endl;
    }
    else cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i, c=0;
    char s[3];
    cin>> s;
    for(i=0; i<2; i++)
    {
        if(s[i]!= s[i+1])
        {
            c=1;;
            break;
        }
    }
    if(c==0)
        cout<<"No"<< endl;
    else if(c==1)
        cout<<"Yes"<< endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::*;
use std::cmp::min;

fn main() {
    input! {
        n: usize,
        d: usize,
        p: [[i64; d]; n],
    }
    let mut res = 0i64;
    for i in 0..n {
        for j in i + 1..n {
            let mut dist = 0i64;
            for k in 0..d {
                dist += (p[i][k] - p[j][k]) * (p[i][k] - p[j][k]);
            }

            let mut f = false;
            for k in 0..200 {
                f ^= dist == k * k;
            }

            if f {
                res += 1;
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#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 IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


signed main() {
  int H, W;
  cin >> H >> W;

  vector<vector<int>> C(H, vector<int>(W));
  REP(i, H) REP(j, W) cin >> C[i][j];
  int b;
  REP(i, H) REP(j, W){
    cin >> b;
    C[i][j] -= b;
    C[i][j] = abs(C[i][j]);
  }

  vector<vector<vector<int>>> vec(H, vector<vector<int>>(W, vector<int>(12800, 0)));
  vec[0][0][C[0][0]] = 1;
  REP(i, H){
    REP(j, W){
      REP(k, 12800){
        if(vec[i][j][k] == 0) continue;

        if(j+1 < W){
          vec[i][j+1][abs(C[i][j+1]-k)] = 1;
          vec[i][j+1][C[i][j+1]+k] = 1;
        }
        if(i+1 < H){
          vec[i+1][j][abs(C[i+1][j]-k)] = 1;
          vec[i+1][j][C[i+1][j]+k] = 1;
        }
      }
    }
  }

  REP(i, 12800){
    if(vec[H-1][W-1][i]){
      cout << i << endl;
      return 0;
    }
  }


  return 0;
}

Measured memory_bytes: 648704
from heapq import heappush, heappop
class UnionFind:
  def __init__(self, n):
    self.par = [i for i in range(n)]
    self.rank = [0]*n
  def find(self, x):
    if self.par[x]==x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]
  def unit(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x==y:
      return
    elif self.rank[x]<self.rank[y]:
      self.par[x] = y
      return
    elif self.rank[y]<self.rank[x]:
      self.par[y] = x
    else:
      self.par[y] = x
      self.rank[x] += 1 
  def same(self, x, y):
    return self.find(x)==self.find(y)
  
N = int(input())
X = []
Y = []
for i in range(N):
  x, y = map(int, input().split())
  X += [(x,y,i)]
  Y += [(x,y,i)]
X.sort()
Y.sort(key=lambda x:x[1])
hq = []
for i in range(N-1):
  x1, y1, i1 = X[i]
  x2, y2, i2 = X[i+1]
  heappush(hq, (x2-x1,i1,i2))
  x1, y1, i1 = Y[i]
  x2, y2, i2 = Y[i+1]
  heappush(hq, (y2-y1,i1,i2))

u  = UnionFind(N)
cnt = 1
ans = 0
while cnt<N:
  c, i1, i2 = heappop(hq)
  if u.same(i1,i2):
    continue
  ans += c
  cnt += 1
  u.unit(i1,i2)
print(ans)

Measured memory_bytes: 56032