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

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int type_a = n;
        int type_b = n;
        int k = in.nextInt();
        int total_dist = 0;
        for (int i = 0; i < n; i++){
            int x = in.nextInt();
            if ( x <= Math.abs(k-x) && type_a >0){
                total_dist += 2*x;
                type_a--;
            }
            else{
                total_dist += 2*Math.abs(k-x);
                type_b--;
            }
        }

        System.out.println(total_dist);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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

int N;
ll bisearch(int n, bool flag, vector<int>& v) {
	ll left=-1,right = N;
	while(right - left > 1) {
		int mid = (right + left) / 2;
		if(flag) {
			if(n > v[mid]) left = mid;
			else right = mid;
		}
		else {
			if(n < v[mid]) left = mid;
			else right = mid;
		}
	}
	return left;
}

int main() {
	cin >> N;
	vector<int> A(N),B(N),C(N);
	rep(i,N) cin >> A[i];
	rep(i,N) cin >> B[i];
	rep(i,N) cin >> C[i];
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	sort(C.begin(), C.end(), greater<int>());
	/*rep(i,N) cout << A[i] << " ";
	cout << endl;
	rep(i,N) cout << B[i] << " ";
	cout << endl;
	rep(i,N) cout << C[i] << " ";
	cout << endl;
	*/

	ll ans = 0;
	rep(i,N) {
		ll temp = 1;
		ll temp2 = bisearch(B[i], true, A), temp3 = bisearch(B[i], false, C);
		//cout << B[i] << " " << temp2 << " " << temp3 << endl;
		temp *= (bisearch(B[i], true, A)+1);
		temp *= (bisearch(B[i], false, C)+1);
		ans += temp;
	}
	cout << ans << endl;

  return 0;
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 100100;

int A[MAX];
int B[MAX];
int C[MAX];

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

	int n;
	scanf("%d", &n);

	FOR (i, 0, n)
	{
		scanf("%d", &A[i]);
	}

	FOR (i, 0, n)
	{
		scanf("%d", &B[i]);
	}

	FOR (i, 0, n)
	{
		scanf("%d", &C[i]);
	}

	sort(A, A+n);
	sort(B, B+n);
	sort(C, C+n);

	LL res = 0;

	FOR (i, 0, n)
	{
		LL a = lower_bound(A, A+n, B[i]) - A;
		LL b = upper_bound(C, C+n, B[i]) - C;

		b = n - b;

		res += a * b;
	}

	cout<<res<<endl;


}


Measured memory_bytes: 1408
from collections import deque
 
n = int(input())
a = list(map(int, input().split()))
 
b = deque()
 
for i in range(n):
    if i % 2 != n % 2:
        b.appendleft(a[i])
    else:
        b.append(a[i])
 
print(" ".join(map(str, b)))

Measured memory_bytes: 29124
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			String x = scanner.next(), y = scanner.next();
			int compare = x.compareTo(y);
			System.out.println((compare > 0) ? ">" : (compare < 0) ? "<" : "=");
		}
	}
}


Measured memory_bytes: 35608
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n,W;
  scanf("%d %d", &n, &W);
  ll dp[n+1][W+1] = {};
  int v[n+1] = {}, w[n+1] = {};
  rep(i,1,n+1) scanf("%d %d", &w[i], &v[i]);
  rep(i,1,n+1)rep(j,0,W+1) {
    if(j >= w[i]) dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
    else dp[i][j] = dp[i-1][j];
  }
  ll ans = dp[n][W];
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 79104
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s; cin >> s;
	int a[4];
	for(int i=0; i<4; i++){
		a[i] = s[i]-'0';
	}
	int b[3]={1,1,1},sum=a[0];
	for(int i=0; i<3; i++){
		sum += a[i+1] * (b[i]?1:-1);
	}
	if(sum==7){
		for(int i=0; i<4; i++){
			if(i==3){
				cout << a[i] << "=7" << endl;
			}else{
				cout << a[i] << (b[i]?"+":"-");
			}
		}
		return 0;
	}
	b[0]=0; 
	do{
		sum=a[0];
		for(int i=0; i<3; i++){
			sum += a[i+1] * (b[i]?1:-1);
		}
		if(sum==7){
			for(int i=0; i<4; i++){
				if(i==3){
					cout << a[i] << "=7" << endl;
				}else{
					cout << a[i] << (b[i]?"+":"-");
				}
			}
			return 0;
		}
	}while(next_permutation(b,b+3));
	b[0]=b[1]=0; b[2]=1;
	do{
		sum=a[0];
		for(int i=0; i<3; i++){
			sum += a[i+1] * (b[i]?1:-1);
		}
		if(sum==7){
			for(int i=0; i<4; i++){
				if(i==3){
					cout << a[i] << "=7" << endl;
				}else{
					cout << a[i] << (b[i]?"+":"-");
				}
			}
			return 0;
		}
	}while(next_permutation(b,b+3));
	for(int i=0; i<4; i++){
		if(i==3){
			cout << a[i] << "=7" << endl;
		}else{
			cout << a[i] << ("-");
		}
	}
}	


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef pair<int,int> P;
int INF = 1<<29;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
long long int i,j;

long long int n,a,b;
long long int x[100005];


bool solve(long long int f){
	long long int sum=0;
	for(i=0;i<n;i++){
		if(x[i]>b*f){
			sum += (x[i]-b*f+a-b-1)/(a-b);
		}
	}
	if(sum<=f){
		return true;
	}else{
		return false;
	}
}



int main(){
	cin>>n>>a>>b;
	for(i=0;i<n;i++){
		cin>>x[i];
	}
	long long int start=0,end=1000000008,look=end/2;
	while(true){
		if(solve(look)==false && solve(look+1)== false){
			start = look;
			look = (start+end)/2;
		}else if(solve(look)==true && solve(look+1) == true){
			end = look;
			look = (start+end)/2;
		}else{
			break;
		}
	}
	cout<<look+1<<endl;
	return 0;
}

Measured memory_bytes: 1152
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int n,a;string s;double sum;
int main(){
//	freopen("1.in","r",stdin);
//	freopen("1.out","w",stdout);
	in(n);
	for(int i=1;i<=n;i++){
		in(a);sum+=1.0/a;
	}
	printf("%.10lf\n",1.0/sum);
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <iterator>
#include <string>
using namespace std;

int main(){
	const string tmp(999998, '0');

	istream_iterator<double> first(cin), last;
	vector<double> v(first, last);
	printf("%f", *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()));
	
	for(int i = 0; i < 10; ++i){
		fputs(tmp.c_str(), stdout);
		fflush(stdout);
	}
	
	puts("");
}

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

using namespace std;

int main() {

    int N; double M; cin >> N >> M;
    vector<double> a(N); for(int i = 0; i < N; i++) cin >> a[i];

    int ch = 0;
    int sum = 0;  for(int i = 0; i < N; i++) sum += a[i];



    for(int i = 0; i < N; i++) {

        if(a[i] >= sum/(4*M)) ch++;

    }

    if(ch >= M) cout << "Yes" << endl;
    else cout << "No" << endl;


    return 0;
}

Measured memory_bytes: 3760
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <random>
#include <set>
#include <stack>

//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater<int>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#include <time.h>
typedef std::pair<int,int> pii;
using namespace std;
using ll = long long;


vector<int> dp;
int ans;

int dfs(int j, vector<vector<int>>& g){
    if (dp[j] != -1) return dp[j];
    if (g[j].size() == 0) return dp[j] = 0;
    int ret = 0;
    for(auto n: g[j]){
        ret = max(ret,dfs(n,g));
    }
    return dp[j] = ret + 1;
}
int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> g(n,vector<int>());
    for(int i = 0; i < m; i++){
        int u,v;
        cin >> u >> v;
        u--;v--;
        g[u].push_back(v);
    }
    
    dp = vector<int> (n,-1);
    ans = 0;
    
    for(int i = 0; i < n; i++){
        if (dp[i] == -1){
            ans = max(ans,dfs(i,g));
        }
    }
    cout << ans;
}









Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll n,K;cin>>n>>K;
  ll x[n],y[n];for(ll i=0;i<n;i++)cin>>x[i]>>y[i];
  ll m=5000000000000000000;
  for(ll i=0;i<n-1;i++){
    for(ll j=i+1;j<n;j++){
      for(ll k=0;k<n-1;k++){
        for(ll l=k+1;l<n;l++){
          ll sum=0;
          for(ll a=0;a<n;a++){
            if((x[a]-x[i])*(x[a]-x[j])<=0&&(y[a]-y[k])*(y[a]-y[l])<=0){
              sum++;
            }
          }
          if(sum>=K){
            ll men=abs(x[i]-x[j])*abs(y[k]-y[l]);
            m=min(m,men);
          }
        }
      }
    }
  }
  cout<<m<<endl;
}

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

typedef long long ll;

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

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

/*qsort(array,num_of_index,sizeof(int),compare_int); */
 int compare_int(const void *a,const void *b){
     return *(int*) a - *(int *) b; 
 } 
 
int main(){
    ll a,b,c,d;
    scanf("%lld %lld %lld %lld",&a,&b,&c,&d);
    ll ans = (-1) * pow(10,18);
    ans = max(ans,a*c);
    ans = max(ans,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    printf("%lld",ans);
}


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

signed main(){
    int N; cin>>N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin>>a[i];
    }

    vector<int> x(N);
    for(int i=0;i<N;i++){
        if(i%2==0) x[0]+=a[i];
        else x[0]-=a[i];
    }

    for(int i=0;i<N-1;i++){
        x[i+1]=2*a[i]-x[i];
    }

    for(int i=0;i<N;i++){
        cout<<x[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int A,B; cin >> A >> B;
    int x = ceil(A/0.08);
    int ans;

    while(true){
        if(floor(x*0.08) == A && floor(x*0.10) == B) {ans=x;break;}
        if(x*0.08>=A+1) {ans = -1;break;}
        x++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
local m = io.read("*n")
local digsum = 0
local quot = 0
local rem = 0
for i = 1, m do
  local d, c = io.read("*n", "*n")
  digsum = digsum + c
  rem = rem + d * c
  if 9 < rem then
    if rem % 9 == 0 then
      quot = rem // 9 + quot - 1
      rem = 9
    else
      quot = rem // 9 + quot
      rem = rem % 9
    end
  end
end
print(digsum - 1 + quot)


Measured memory_bytes: 888
import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {

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

		Scanner scan = new Scanner(System.in);

		int N;
		String lastChar = "";
		N = scan.nextInt();
		java.util.Set<String> set = new LinkedHashSet<>();

		for (int i = 1; i <= N; i++) {
			set.add(scan.next());
		}

		if (N != set.size()) {
			System.out.println("No");
			return;

		}

		for (String item : set) {
			if (!lastChar.equals("")) {
				String firstChar = String.valueOf(item.charAt(0));

				if (!firstChar.equals(lastChar)) {
					System.out.println("No");
					return;
				}
			}

			lastChar = String.valueOf(item.charAt(item.length() - 1));
		}

		System.out.println("Yes");

	}

	//***********************以下共通関数************************************************
	/**
	 * 文字列を反転して返す
	 * @param pStr 文字列
	 * @return 反転した文字列
	 */
	public static String myReverse(String pStr) {
		if (pStr.length() < 1) {
			return "";
		}

		StringBuffer sb = new StringBuffer(pStr);
		return sb.reverse().toString();
	}

	/**
	 * 余りを求める。
	 * @param a
	 * @param b
	 * @return 余り。余りがマイナスの時はプラスで返す。
	 */
	public static long myMod(long a, long b) {
		long ret = 0;

		ret = a % b;

		if (ret < 0) {
			ret += b;
		}

		return ret;
	}

	/**
	 * 乗数を求める ※mod対応
	 * @param kisu 基数
	 * @param josu 乗数
	 * @param primeNumMod_0 法 mod値 使わない場合は「0」
	 * @return
	 */
	public static long myPowWithMod(long kisu, long josu, long primeNumMod_0) {

		long ans = 1;

		//乗数が0の場合→1
		if (josu == 0)
			return 1;

		if (primeNumMod_0 == 0) {
			//modを使わないとき

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= kisu;
					josu = josu / 2;
				} else {
					//累乗が奇数の時
					ans *= kisu;
					josu--;
				}
			}

			return ans;

		} else {
			//modを使うとき

			//初めに桁を落とす
			kisu = myMod(kisu, primeNumMod_0);

			while (josu > 0) {

				if (josu % 2 == 0) {
					//累乗が偶数の時

					kisu *= myMod(kisu, primeNumMod_0);
					josu = josu / 2;

				} else {
					//累乗が奇数の時
					ans *= myMod(kisu, primeNumMod_0);
					josu--;

				}
			}

			return myMod(ans, primeNumMod_0);

		}

	}

}


Measured memory_bytes: 27196
#include <bits/stdc++.h>
using namespace std;
 
int main() 
{
    float a,b,x;
    cin >> a >> b;
    x = (a+b)/2;
    if(x-(int)x > 0)
    {
        x = (int)x + 1;
    }else
    {
        x = (int)x;
    }
    
    cout << x << endl;
}

Measured memory_bytes: 256
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @s = gets.chomp
  end

  def solve
    s.match(/^(hi)+$/)
  end

  def show(ans)
    puts ans ? "Yes" : "No"
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14256
import sys
sys.setrecursionlimit(10 ** 9)

n = int(input())
uvw = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    u -= 1
    v -= 1
    uvw[u].append([v, w])
    uvw[v].append([u, w])
color = [-1 for _ in range(n)]
color[0] = 0
def dfs(before_pos, pos, w):
    color[pos] = w
    for next_pos, next_w in uvw[pos]:
        if next_pos == before_pos:
            continue
        dfs(pos, next_pos, (w + next_w) % 2)
    
dfs(-1, 0, 0)
for c in color:
    print(c)

Measured memory_bytes: 86972
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vpl ab(n);
    rep(i,n){
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ALL(ab));
    ll ans = 0;
    rep(i,n){
        if (ab[i].second >= m) {
            ans += ab[i].first * m;
            break;
        } else
        {
            ans += ab[i].first * ab[i].second;
            m -= ab[i].second;
        }
    }
    cout << ans << endl;
    
    return 0;
}


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

int digit(int x) {
	int y = 0;
	while (x != 0) {
		y += x % 10;
		x /= 10;
	}
	return y;
}
int main() {
	int N, min = 1000;
	cin >> N;
	for (int i = 1; i <= N / 2; i++) {
		int j = N - i;
		int X = digit(i) + digit(j);
		if (X < min) min = X;
	}
	cout << min << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int cnt = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i <N; i++) {
            A[i] = sc.nextInt();
        }
        String ans = "";
        bubbleSort(A, N);
        for (int i = 0; i <N; i++) {
            ans += A[i] + " ";
        }
        System.out.println(ans.substring(0, ans.length()-1));
        System.out.println(cnt);
    }
    static void bubbleSort(int[] A, int N) {
        int pos = 0;
        int tmp;
        while(pos != N-1) {
            for (int i = N - 1; i > pos; i--) {
                if(A[i] < A[i-1]){
                    tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    cnt++;
                }
            }
            pos++;
        }
    }
}



Measured memory_bytes: 26488
#include <cstdio>
#include <iostream>
#include <vector>

int counter = 0;

void swap(int* a, int* b)
{
    int tmp = *a;
    *a = *b;
    *b = tmp;
    counter++;
}

void do_bubble_sort(std::vector<int>& data)
{
    for(int i = 0; i < data.size() - 1; i++) {
        for(int j = 0; j < data.size() - 1 - i; j++) {
            if(data[j + 1] < data[j]) {
                swap(&data[j], &data[j + 1]);
            }
        }
    }
}

void show_data(std::vector<int>& data)
{
    printf("%d", data[0]);
    for(int i = 1; i < data.size(); i++) {
        printf(" %d", data[i]);
    }
    puts("");
}

int main()
{
    int input_size;
    std::cin >> input_size;
    std::vector<int> data(input_size);
    for(int i = 0; i < data.size(); i++) {
        std::cin >> data[i];
    }

    do_bubble_sort(data);

    show_data(data);
    printf("%d\n", counter);

    return 0;
}

Measured memory_bytes: 3224
#include<iostream>
#include<vector>

using namespace std;

int main(void) {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0;i < n; i++) cin >> a[i];
    int cur = 0, num = 1;
    while (cur < a.size()) {
        if (num == a[cur]) num++;
        cur++;
    }
    num != 1 ? cout << a.size() - num + 1 << endl : cout << -1 << endl;
}

Measured memory_bytes: 1024
def isPrime(x):
    if x < 2:
        return False
    elif x == 2:
        return True;
    if x % 2 == 0:
        return False
    
    for i in range(3,int(x),2):
        if i * i > x :
            break;
        if x % i == 0:
            return False
        
    return True
    

while 1:
    try:
        num = (int)(input())
    except EOFError:
        break
print(str(num) + ":",end="")
factor = 2
factors = []
while num != 1:
    # 素数チェック
    if isPrime(num) :
        factors.append(int(num))
        break
    if(num % factor == 0):
        num = num / factor
        factors.append(factor)
    else:
        factor = factor + 1


for i in factors:
    print(" " + str(i),end="")
print()


Measured memory_bytes: 5604
#include <stdio.h>

int gcd(int x, int y){
    int r;
    if(x < y){
        return gcd(y, x);
    }
    r = x % y;
    while(r != 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}
int main(void){
   int x, y;
   scanf("%d%d",&x, &y);
   printf("%d\n",gcd(x, y));
   
   return 0;
}


Measured memory_bytes: 2104
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();
		char[] arr = sc.next().toCharArray();
		ArrayDeque<Integer> deq = new ArrayDeque<>();
		int idx = n;
		while (idx > 0) {
		    int next = Math.max(idx - m, 0);
		    while (arr[next] == '1' && next < idx) {
		        next++;
		    }
		    if (next == idx) {
		        System.out.println(-1);
		        return;
		    }
		    deq.push(idx - next);
		    idx = next;
		}
		boolean flag = false;
		StringBuilder sb = new StringBuilder();
		while (deq.size() > 0) {
		    if (flag) {
		        sb.append(" ");
		    }
		    sb.append(deq.pop());
		    flag = true;
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 30224
m,e,j,s;main(n){for(;--n||scanf("%d",&n)*n;puts(m>99|e>99|j>99|m+e>179|s>239?"A":s<210&&s<150|m<80&e<80?"C":"B"))scanf("%d%d%d",&m,&e,&j),s=m+e+j;}

Measured memory_bytes: 0
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(ALL(x)) - (x).begin())
#define PI          3.14159265358979323846
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define ld          long double
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
ld get_ang(ld h, ld m){
    ld ha = 0.5 * (h * 60 + m);
    ld ma = 6 * m;
    ld ang = abs(ha - ma);
    ang = min(360 - ang, ang);
    return ang;
}
ld angtor(ld ang){
    return ang / 180 * PI;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    ld a, b, h, m;
    cin >> a >> b >> h >> m;
    ld ang = get_ang(h, m);
    ld angr = angtor(ang);
    ld co = cosl(angr);
    ld d = a * a + b * b - 2.0 * b * a * co;
    d = sqrtl(d);
    cout << fixed << setprecision(20) << d;
    return 0;
}
/*
    *** Most Impo.. -> check base case always
    1. Overflow Check (*, +)
    2. Index check (0 - based or 1 - based)
    3. Check for n = 1, 2, 3, 4....
    4. Corner Cases
*/

Measured memory_bytes: 4184
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef pair<int,int> p;
typedef pair<int,p> P;//first>正答数 second.first>ペナルティ second.second>チーム番号

int main()
{
	int t,p,r;
	while(cin>>t>>p>>r,t)
	{
		P res[t];
		int wa[t][11];
		for(int i=0;i<t;i++)
		{
			res[i].first=0;res[i].second.first=0;res[i].second.second=i+1;
		}
		memset(wa,0,sizeof(wa));
		for(int i=0;i<r;i++)
		{
			int tid,pid,tim;
			string mes;
			cin>>tid>>pid>>tim>>mes;
			if(mes=="WRONG")
			{
				wa[tid-1][pid]++;
			}
			else
			{
				res[tid-1].first--;
				res[tid-1].second.first+=wa[tid-1][pid]*1200+tim;
			}
		}

		sort(res,res+t);

		for(int i=0;i<t;i++)
		{
			cout<<res[i].second.second<<" "<<res[i].first*-1<<" "<<res[i].second.first<<endl;
		}
	}
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

const int mod=1e9+7;

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

	long double ans=0;
	for (int i = 1; i <= n; ++i){
		if(i>=k){
			ans+=1/(long double)n;
			continue;
		}
		int cnt=0;
		int dice=i;
		while(dice<k){
			cnt++;
			dice*=2;
		}
		ans+=pow(0.5,cnt)*(1/(long double)n);
	}
	
	cout<<fixed<<setprecision(14)<<ans<<endl; 
	

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7




int main(){


    ll n;
    cin >> n;
    vector<ll> arr(3*n);
    REP(i,3*n){
        cin >> arr[i];
    }
    VSORT(arr);
    ll team_strength = 0;

    for(int i = n;i < arr.size();i+=2){
        team_strength += arr[i];
    }

    cout << team_strength << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <ctype.h>
#include <cstring>
#include <math.h>


int main(){
    double R;
    double A =3.141592653589793;
    scanf("%lf",&R);
    printf("%.15f",A*2*R);


    return 0;
}

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

int a, b;

void input(){
  cin >> a >> b;
}

int solve(){
  input();
  int ans = 0;
  if(a>9 || b>9){
    ans = -1;
  }else{
    ans = a*b;
  }
  cout << ans << endl;
}

int main() {
  solve();
}


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

int main(void){
    string s;
    long long k;
    cin >> s >> k;

    char ans = '1';
    int i = 0;
    while(i<k){
        if(s[i] != '1'){
            ans = s[i];
            break;
        }
        i++;
    }


    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long int
long long  INF=1e9+5;

int main()
{   ios_base::sync_with_stdio(0);
     cin.tie(0);
    ll n,k;
    cin>>n;
    vector<ll> dp(3);
    for(ll day=0;day<n;day++)
    {
        vector<ll> new_dp(3,0);
        vector<ll> c(3);
        for(ll i=0;i<3;i++)
            cin>>c[i];

        for(ll i=0;i<3;i++)
        {
            for(ll j=0;j<3;j++)
                if(i!=j)
                new_dp[j]=max(new_dp[j],dp[i]+c[j]);
        }
        dp=new_dp;
    }

    cout<<max(dp[0],max(dp[1],dp[2]))<<"\n";
    return 0;
}


Measured memory_bytes: 256
/*
___mennat khoday ra azz o va jall ke taatash mojebe ghorbat ast o be shokr andarash mazide nemat.
___har nafasi ke foro miravad momedde hayatast o chon bar miayad mofarrahe zat.
___pas dar har nafasi 2 nemat mojod ast o bar har nematy shokry vajeb.

___az dast o zabane ke barayad ?
___kaz ohdeye shokrash be dar ayad !


___man be to dami gharar natvanam kard
___va ehsane to ra shomar natvanam kard
####################
___gar bar tane man zaban shavad har moyee
___yek shokre to az hezar natvanam kard

*/

#include <bits/stdc++.h>

#define pb push_back
#define SALI main
#define left(x) ((x)*2)
#define right(x) (((x)*2)+1)
#define fuck(x) cout << #x << " : " << x << "   ";
#define findLowVec(v,x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define findUpVec(v,x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define findLowArr(a,n,x) (lower_bound(a, a+n, x) - a)
#define findUpArr(a,n,x) (upper_bound(a, a+n, x) - a)
#define int long long

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef long double ld;

template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p)
{return out << "(" << p.first << ", " << p.second << ")";}

template<class A> ostream& operator <<(ostream& out, const vector<A> &v)
{out << "[";for(int i = 0; i < v.size(); i++) {if(i) out << ", ";out << v[i];}return out << "]";}

template<class A,class B> ostream& operator <<(ostream& out, const set<A,B> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

template<class A> ostream& operator <<(ostream& out, const set<A> &s)
{out << "[";for(auto i = s.begin(); i != s.end(); i++) {out << ", ";out << *i;}return out << "]";}

const int mod = 1e9 + 7;

int32_t SALI()
{
    int n; cin >> n;
    ld p[n+1]; for(int i = 1; i <= n; i++) cin >> p[i];

    ld dp[n+1][n+1]; // dp[i][j] = i taye avval daghighan j tashon head biad head

    for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) dp[i][j] = 0.00000000000;

    dp[1][0] = 1 - p[1];
    dp[1][1] = p[1];

    for(int i = 2; i <= n; i++){
        dp[i][0] = dp[i-1][0] * (1-p[i]);
        for(int j = 1; j <= i; j++){
            dp[i][j] = dp[i-1][j] * (1-p[i]) + dp[i-1][j-1] * p[i];
        }
    }
    ld ans = 0.0000000;
    for(int i = (n/2) + 1; i <= n; i++) ans += dp[n][i];
    cout << fixed << setprecision(10) << ans;
}


/**< WRITEN BY ALI ADELKHAH */



Measured memory_bytes: 144416
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
int main()
{
     cin>>n>>k;
     ans=1;
     for(int i=1;i<=n;i++)
    {
        if(ans>k) ans+=k;
        else ans*=2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
char str[22];
int n,cnta,cntb,cntab;
int main() {
	rd(n); int ans=0;
	for(int i=1;i<=n;++i) {
		scanf("%s",str+1); int len=strlen(str+1);
		for(int j=1;j<len;++j) ans+=str[j]=='A'&&str[j+1]=='B';
		int ty=0;
		if(str[1]=='B') ty+=1;
		if(str[len]=='A') ty+=2;
/*		if(ty==1) {
			if(cnta) cnta--,ans++;
			else if(cntab) cntab--,cntb++,ans++;
			else cntb++;
		}
		else if(ty==2) {
			if(cntb) cntb--,ans++;
			else if(cntab) cntab--,cnta++,ans++;
			else cnta++;
		}
		else if(ty==3) {
			if(cnta||cntb||cntab) ans++;
			else cntab++;
		}*/
		if(ty==1) cntb++;
		else if(ty==2) cnta++;
		else if(ty==3) cntab++;
	//	cout<<cnta<<' '<<cntb<<' '<<cntab<<' '<<ans<<endl;
	}
	int t1=min(cntb,cnta);
	if(t1) {
		ans+=t1,cntb-=t1,cnta-=t1;
		ans+=cntab;
	}
	else if(cnta+cntb) {
		ans+=cntab;
	}
	else if(cntab) ans+=cntab-1;
	printf("%d",ans);
	return 0;
}
		


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),m=sc.nextInt();
		int[] a= new int[n];
		for(int i=0;i<n;i++)a[i]=sc.nextInt();
		int sum=0;
		for(int ele:a)sum+=ele;
		double min = ((double)sum)/(4*m);
		int sat = 0;
		for(double ele:a)if(ele>=min)sat++;
		String ans = ((sat>=m)?"Yes":"No");
		System.out.println(ans);
	}
}

Measured memory_bytes: 22612
//Atcorder

"use strict" //これないとなぜかエラー その１

function main(input){ //入力の箱はじめ
//中身ここから

console.log(input.split('1').length - 1);


//中身ここまで
}//箱おわり
main(require('fs').readFileSync('/dev/stdin', 'utf8')); //これないとなぜかエラー その２

Measured memory_bytes: 7372
#include <iostream>
using namespace std;
int main() {
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    x /= 10;

    int cnt=0;
    for(int i=0; i*50<=x && i<=a; i++) {
        for(int j=0; i*50+j*10<=x && j<=b; j++) {
            if((x-i*50-j*10)%5==0 && (x-i*50-j*10)/5<=c) cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


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

#define INF 10000000
#define NIL -1

struct Node{int parent,left,right;};
Node T[INF];
int n,D[INF];

void print(int u){
  int i,c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].parent==NIL) cout << "root, ";
  else if(T[u].left == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";
  for(i=0,c=T[u].left;c!=NIL;i++,c=T[c].right){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u,int p){
  D[u] = p;
  if(T[u].right != NIL) rec(T[u].right,p);
  if(T[u].left != NIL) rec(T[u].left,p+1);  
}

int main(void){
  int i,j,d,v,c,left,right;

  cin >> n;
  for(i=0;i<n;i++) T[i].parent = T[i].left = T[i].right = NIL;

  for(i=0;i<n;i++){
    cin >> v >> d;
    for(j=0;j<d;j++){
      cin >> c;
      if(j==0) T[v].left = c;
      else T[left].right = c;
      left = c;
      T[c].parent = v;
    }
  }

  for(i=0;i<n;i++) if(T[i].parent==NIL) right = i;
  rec(right,0);

  for(i=0;i<n;i++) print(i);
}

Measured memory_bytes: 7740
n,x,y=map(int,input().split())
 
ans=[0]*n
 
list =[]
for i in range(n):
  for j in range(i):
    b = i+1
    a = j+1
    if a<=x and b>=y:
      k =b-y+x-a+1
    elif a>x and b>=y:
      d =min(a-x+1,y-a)
      k =d+b-y
    elif a<=x and b<y:
      d =min(b-x,y-b+1)
      k =x-a+d
    elif a>x and b<y:
      k = min(b-a,y-b+a-x+1)
    ans[k]+=1
    
for i in range(1,n):
  print(ans[i])

Measured memory_bytes: 3444
#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;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://onlinejudge.u-aizu.ac.jp/services/room.html#ACPC2018Day2/problems/B>
 問題文============================================================
 =================================================================
 解説=============================================================
 
 ukuが優先的にダメージを与えることができる場合と
 牛が優先的にダメージを与えることができる場合をそれぞれ考える

 ================================================================
 */

ll solve(){
    ll res = LINF;
    ll N,M; cin >> N >> M;
    {
        ll num = 0;
        ll uku = 2*N,ei = 2*M;
        ll uku_dame = 0,ei_dame = 0;
        while(true){
            if(num%2 == 0){
                ll uku_num = (uku-uku_dame)/2;
                ei_dame+=uku_num;
            }else{
                ll ei_num = min(M,ei-ei_dame);
                uku_dame+=ei_num;
            }
            if(uku-uku_dame<=0) break;
            if(ei-ei_dame<=0) break;
            num++;
        }
        res = min(res,num);
    }
    {
        ll num = 0;
        ll uku = 2*N,ei = 2*M;
        ll uku_dame = 0,ei_dame = 0;
        while(true){
            if(num%2 == 0){
                ll uku_num = min(N,uku-uku_dame);
                ei_dame+=uku_num;
            }else{
                ll ei_num = (ei-ei_dame)/2;
                uku_dame+=ei_num;
            }
            if(uku-uku_dame<=0) break;
            if(ei-ei_dame<=0) break;
            num++;
        }
        res = min(res,num);

    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cout << solve() << endl;
    return 0;
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define show(x) cout << #x << " = " << (x) << endl;
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
//cout << fixed << setprecision(10);

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

int main () {
  ll a, b;
  cin >> a >> b;
  for (int i = 1; i <= b; ++i) {
    if ((a*i)%b == 0) {
      cout << a*i << endl;
      break;
    }
  }
  return 0;
}

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

const int N = 3005;
int a[N], b[N];
int fr[N][N], ba[N][N]; // fr[i][j] how much max val with j min
int n, t;

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> t;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= t; j++) {
            fr[i][j] = fr[i - 1][j];
            if (j - a[i] >= 0) {
                fr[i][j] = max(fr[i][j], fr[i - 1][j - a[i]] + b[i]);
            }
        }
    }
    for (int i = n; i >= 1; i--) {
        for (int j = 0; j <= t; j++) {
            ba[i][j] = ba[i + 1][j];
            if (j - a[i] >= 0) {
                ba[i][j] = max(ba[i][j], ba[i + 1][j - a[i]] + b[i]);
            }
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= t - 1; j++) {
            ans = max(ans, fr[i - 1][j] + ba[i + 1][t - 1 - j] + b[i]);
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 70784
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
using namespace std;
typedef pair<int, int>p;
p mov[200005];
long long mod = 1e9 + 7;
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	long long n, p;
	cin >> n >> p;
	long long ans = 1;
	for (long long i = 2; i*i <= p; i++) {
		int cnt = 0;
		while (p%i == 0) {
			p /= i;
			cnt += 1;
		}
		long long tmp =1;
		while (cnt>=n) {
			cnt -= n;
			tmp *= i;
		}
		ans *= tmp;
	}
	if (n == 1)ans *= p;
	cout << ans;
}

Measured memory_bytes: 256
from bisect import bisect
X=int(input())
K=int(input())
rs=[0]
for r in input().split():
  rs.append(int(r))
A=[[(0,0),(X,X)]]
min_sup=0
max_inf=X
pre_r=0
for i,r in enumerate(rs[1:]):
  d=r-pre_r
  pre_r=r
  m,M=A[-1][0][0],A[-1][1][0]
  if i%2==0:
    if m-d>=0:
      new_m=m-d
    else:
      new_m=0
      min_sup=min_sup+d-m
    if M-d>0:
      new_M=M-d
    else:
      new_M=0
      max_inf=0
  else:
    if M+d<=X:
      new_M=M+d
    else:
      new_M=X
      max_inf=max_inf-(d-(X-M))
    if m+d<X:
      new_m=m+d
    else:
      new_m=X
      min_sup=X
  if new_m==new_M:
    min_sup=X
    max_inf=0             
  A.append([(new_m,min_sup),(new_M,max_inf)])
Q=int(input())
for q in range(Q):
  t,a=map(int,input().split())
  r_num=bisect(rs,t)-1
  m,min_sup=A[r_num][0]
  M,max_inf=A[r_num][1]
  r=rs[r_num]
  if r_num%2==0:
    if a<=min_sup:
      print(max(m-(t-r),0))
    elif min_sup<a<max_inf:
      print(max(m+(a-min_sup)-(t-r),0))
    else:
      print(max(M-(t-r),0))
  else:
    if a<=min_sup:
      print(min(m+(t-r),X))
    elif min_sup<a<max_inf:
      print(min(m+(a-min_sup)+(t-r),X))
    else:
      print(min(M+(t-r),X))


Measured memory_bytes: 98584
def main():
    N, K = map(int, input().split())
    H = []
    for _ in range(N):
        H.append(int(input()))
    H = sorted(H)
    min_d = float('inf')
    for i in range(N-K+1):
        min_d = min(min_d, H[i+K-1]-H[i])
    return min_d


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 8280
#!/usr/bin/env python3

def main():
    [N, K] = list(map(int, input().split()))
    h = []
    for i in range(N):
        h.append(int(input()))

    h.sort()
    min_d = h[N - 1]
    for i in range(N - K + 1):
        min_d = min(min_d, h[K - 1 + i] - h[i])


    print(min_d)


if __name__ == '__main__':
    main()



Measured memory_bytes: 7384
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

//a_l + a_l+1 + ... + a_r-1 >= S ??¨????????¨??????????????? r-l ???????°????
int smallest_window(const vector<int> &a, int S) {
	int n = a.size(), l = 0, r = 0;
	int sum = 0;
	int ret = INF;
	while (l < n) {
		dump(ret);
		dump(l, r, sum);
		if (r == n) {
			sum -= a[l];
			l++;
		}
		else if (sum + a[r] >= S) {
			chmin(ret, r + 1 - l);
			if (l == r) {
				l++, r++;
			}
			else {
				sum -= a[l];
				l++;
			}
		}
		else {
			sum += a[r];
			r++;
		}
	}
	return ret == INF ? 0 : ret;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, S; cin >> N >> S;
	vector<int> a(N); rep(i, 0, N) { cin >> a[i]; }
	cout << smallest_window(a, S) << endl;
	return 0;
}

Measured memory_bytes: 3344
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	int n;
	cin >> n;
	int a[100];
	for (int i = 0;i < n;i++)cin >> a[i];
	ll m = 10000000000;
	sort(a, a + n);
	for (int i = a[0];i <= a[n - 1];i++) {
		ll cost = 0;
		for (int j = 0;j < n;j++) {
			cost += (a[j] - i)*(a[j] - i);
		}
		m = min(cost, m);
	}
	cout << m << endl;
}

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

int main(){
  int n,ans=1e9,count=0;
  string s;
  cin >> n >> s;
  r(i,n)if(s[i]=='E')count++;
  ans=min(count,ans);
  r(i,n){
    if(s[i]=='E')count--;
    if(s[i-1]=='W')count++;
    ans=min(count,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 900
//#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;
#define AC 0
#define mod 1000000007
vector< vector<int> > mul(const vector< vector<int> >& a, const vector< vector<int> >& b) {
	vector< vector<int> > c(a.size(), vector<int>(a.size()));
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a.size(); j++)
			for (int k = 0; k < a.size(); k++)
				c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j] % mod) % mod;
	return c;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n, ans = 0;
	long long k;
	cin >> n >> k;
	vector< vector<int> > g(n, vector<int>(n)), a(n, vector<int>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			cin >> g[i][j];
	for (int i = 0; i < n; i++) a[i][i] = 1;
	while (k) {
		if (k & 1) a = mul(a, g);
		k >>= 1;
		g = mul(g, g);
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			ans = (ans + a[i][j]) % mod;
	cout << ans << '\n';
	return AC;
}

Measured memory_bytes: 3676
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

using namespace std;

class Increase {
public:
  int n, flowMax = 1000000;
  vector<vector<int>> p;
  vector<int> parent;
  Increase(int _n, vector<vector<int>> _p) {
    n = _n;
    p = _p;
    parent.resize(n);
  }
  int dfs(int id, int from, int flow) {
    if (parent[id] != id)
      return 0;
    parent[id] = from;
    if (id == n - 1)
      return flow;
    for (int i = 0; i < n; i++)
      if (p[id][i] > 0) {
        int next = dfs(i, id, min(flow, p[id][i]));
        if (next > 0)
          return next;
      }
    return 0;
  }
  int solve() {
    int ret = 0, flow;
    for (int i = 0; i < n; i++)
      parent[i] = i;

    while ((flow = dfs(0, -1, flowMax)) > 0) {
      int now = n - 1;
      ret += flow;
      while (parent[now] >= 0) {
        p[parent[now]][now] -= flow;
        p[now][parent[now]] += flow;
        now = parent[now];
      }
      for (int i = 0; i < n; i++)
        parent[i] = i;
    }
    return ret;
  }
};

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> ab(n), cd(n);
  for (int i = 0; i < n; i++)
    cin >> ab[i].first >> ab[i].second;
  for (int i = 0; i < n; i++)
    cin >> cd[i].first >> cd[i].second;

  vector<vector<int>> path(2 * n + 2);
  for (int i = 0; i < 2 * n + 2; i++) {
    path[i].resize(2 * n + 2);
  }
  for (int i = 0; i < n; i++) {
    path[0][i + 1] = 1;
    path[n + 1 + i][2 * n + 1] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (ab[i].first < cd[j].first && ab[i].second < cd[j].second) {
        path[i + 1][n + 1 + j] = 1;
      }
    }
  }
  Increase solver(2 * n + 2, path);
  cout << solver.solve() << endl;
  return 0;
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            for (int i = 0; i < S.Length; i++)
            {
                if (S.Substring(i, S.Length - i) + S.Substring(0, i) == T)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092