akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
const long long inf=2e18;
#define N 2050
#define res register int
#define ll long long
using namespace std;
ll a[N],x,n,m,f[N][N],sum,ans;
int main()
{
	scanf("%lld%lld",&n,&x);
	for(res i=1;i<=n;i++)
	scanf("%lld",&a[i]);
	sum=inf;
	for(res i=1;i<=n;i++)
	f[i][0]=a[i];
	
	for(res i=1;i<=n;i++)
	{
		for(res j=1;j<=n-1;j++)
		{
			ll tim=i-j;
			if(tim<=0) tim+=n;
			f[i][j]=min(f[i][j-1],a[tim]);
		}
	}
	
	for(res i=0;i<=n-1;i++)
	{
		ans=0;
		for(res j=1;j<=n;j++)
		ans+=f[j][i];
		sum=min(sum,ans+x*i);
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 33024
import scala.io.StdIn

/**
  * AOJ
  */
object Main {

  def main(args: Array[String]): Unit = {

    val in = StdIn.readLine().split(" ").map(s => s.toInt)

    println((in(0) * in(1)).toString + " " + (in(0) + in(1)) * 2)
  }
}

Measured memory_bytes: 43584
import java.io.*;

public class Main{
	public static void main(String[] args)
	{
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int n = Integer.parseInt(br.readLine());
			String[] str =  br.readLine().split(" ") ;
			int[] ar = new int[n];
			for(int i= 0; i<n; i++)
			{
				ar[i] = Integer.parseInt(str[i]);
			}
			araiSort(ar,ar.length);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public static void araiSort(int[] a ,int len)
	{
		int min,temp,cou=0;
		for(int i = 0; i < len-1; i++)
		{
			min = i ;
			for(int j = i+1; j<len ; j++)
			{
				if(a[j] < a[min])
				{
					min = j;
				}
			}
			if(min != i)
			{
				temp = a[min];
				a[min] = a[i];
				a[i] = temp;
				cou++;
			}
		}
		show(a,cou);
		
		
	}
	public static void show(int[] b,int co)
	{
		StringBuilder sb = new StringBuilder();
		for(int i = 0 ; i < b.length ; i++ ){
			sb.append(b[i]).append(" ");
		}
		sb.deleteCharAt(sb.length()-1);
		sb.append("\n").append(co);
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 24452
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int i,count;
  for(i=0;i<4;i++){
    if(n%10==2){
      count++;
    }
    n/=10;
  }
  printf("%d\n",count);
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define ld long double
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n; cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    
    ll ans=0,res1=0,res2=0;

    rep(i,n){
        if(i%2==0){
            if(a[i]<=0) res1+=(1-a[i]),a[i]=1;
            if(b[i]>=0) res2+=(b[i]+1),b[i]=-1;
        }else{
            if(a[i]>=0) res1+=(1+a[i]),a[i]=-1;
            if(b[i]<=0) res2+=(1-b[i]),b[i]=1;
        }

        if(i!=n-1){
            a[i+1]+=a[i];
            b[i+1]+=b[i];
        }
    }

    ans=min(res1,res2);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4816
#include <bits/stdc++.h>
#define maxn 405

using namespace std;

struct Node{
	int a[4];
	
	inline int & operator [] (int i){
		return a[i];
	}
	
	friend inline bool operator < (Node x, Node y){
		for(register int i = 0;i < 4;i++){
			if(x[i] ^ y[i]) return x[i] < y[i];
		}
		return false;
	}
}a[maxn];

map<Node, int> mp;

inline void add(Node &x, int y){
	Node a;
	for(register int i = 0;i < 4;i++){
		for(register int j = 0;j < 4;j++){
			a[j] = x[(i + j) % 4];
		} 
		mp[a] += y; 
	}
}

int n;
long long ans;

int main(){
	scanf("%d", &n);
	for(register int i = 1;i <= n;i++){
		for(register int j = 0;j < 4;j++){
			scanf("%d", &a[i][j]);
		}
		add(a[i], 1);
	}
	for(register int i = 1;i <= n;i++){
		add(a[i], -1), reverse(a[i].a, a[i].a + 4);
		for(register int j = 1;j < i;j++){
			add(a[j], -1);
			//printf("%d %d %d %d--||\n", a[i][0], a[i][1], a[i][2], a[i][3]);
			//printf("%d %d %d %d--||\n", a[j][0], a[j][1], a[j][2], a[j][3]);
			for(register int k = 0;k < 4;k++){
				long long sum = 1;
				Node b[4];
				bool tag[4] = {0};
				for(register int l = 0;l < 4;l++){
					b[l] = (Node){a[i][l], a[i][(l + 1) % 4], a[j][(l + 1 + k) % 4], a[j][(l + k) % 4]};
					//printf("%d %d %d %d %d--\n", a[i][l], a[i][(l + 1) % 4], a[j][(l + 1 + k) % 4], a[j][(l + k) % 4], mp[b]);
					int x = mp[b[l]];
					if(!x){
						sum = 0;
						break;
					}
					sum *= mp[b[l]], tag[l] = true;
					add(b[l], -1);
				}
				ans += sum;
				for(register int l = 0;l < 4;l++) if(tag[l]) add(b[l], 1);
			} 
			add(a[j], 1);
		}
		reverse(a[i].a, a[i].a + 4), add(a[i], 1);
	}
	printf("%lld", ans / 3);
}

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

int a,b,k,x,y;

int main()
{
	scanf("%d%d%d",&k,&a,&b);
	if(k==1||(a%k==0||b%k==0))
	{
		printf("OK\n");
		return 0;
	}
	x=a/k,y=b/k;
	if(x==y) printf("NG\n");
	else printf("OK\n");
}

Measured memory_bytes: 3688
# C
import numpy as np
N, P = map(int, input().split())

primes = np.ones(10**6)
primes[:2] = 0
for p in range(2, 10**3):
    if primes[p] == 1:
        primes[2*p::p] = 0

prim = np.where(primes == 1)[0]

if N == 1:
    res = P
    print(res)
else:
    res = 1
    for p in prim:
        k = 0
        while P % p == 0:
            k += 1
            P = P // p
        res *= p ** (k//N)
    print(res)

Measured memory_bytes: 30964
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ParsaAlizadeh
 */

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

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

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define file_io         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 100 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;

ll n, k;
vector<pll> E;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    cin >> n >> k;
    if (k > (n - 1) * (n - 2) / 2)
        kill(-1);
    for (ll i = 2; i <= n; i++) {
        E.emplace_back(1, i);
        for (ll j = i + 1; j <= n; j++) {
            if (k > 0) k--;
            else E.emplace_back(i, j);
        }
    }
    cout << E.size() << endl;
    for (pll e : E) {
        cout << e.X << sep << e.Y << endl;
    }
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

string s;
const int N = 100002;
long long memo[N][13];
const long long M = 1000000007;
long long dp(int p, int m)
{
    if (memo[p][m] != -1) return memo[p][m];
    if (p == s.length()) {
        return memo[p][m] = (m==5 ? 1 : 0);
    }
    if (s[p]=='?') {
        long long a = 0;
        for (int i=0; i <= 9; ++i) {
           a = (a + dp(p+1, (m*10 + i) % 13)) % M;
        }
        return memo[p][m] = a;
    }
    else {
        int c = s[p]-'0';
        return memo[p][m] = dp(p+1, (m * 10 + c) % 13);
    }
}

int main()
{
    cin >> s;
    int n;
    n = s.length();
    fill(&memo[0][0], &memo[N-1][13], -1);
    cout << dp(0, 0) << endl;

    return 0;
}

Measured memory_bytes: 18432
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

int solve(const string& s, int& k)
{
    ++ k;
    if(s[k] != '['){
        int ret = 0;
        while(s[k] != ']'){
            ret *= 10;
            ret += s[k] - '0';
            ++ k;
        }
        ++ k;
        return (ret + 1) / 2;
    }

    vector<int> a;

    for(;;){
        if(s[k] == ']')
            break;
        a.push_back(solve(s, k));
    }
    ++ k;

    sort(a.begin(), a.end());
    int ret = accumulate(a.begin(), a.begin()+a.size()/2+1, 0);
    return ret;
}

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

    while(--n >= 0){
        string s;
        cin >> s;
        int k = 0;
        cout << solve(s, k) << endl;
    }

    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <cmath>

using namespace std;

#define rip(i,n,s) for (int i=(s);i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int,int> P;

int main(){
    string s;
    cin >> s;
    map<char,int> ma;
    int n=s.size();
    rip(i,n,0){
        if(ma.count(s[i])){
            ma[s[i]]++;
        }
        else{
            ma[s[i]]=1;
        }
    }
    if(ma.size()==1){
        cout << n << endl;
        return 0;
    }
    priority_queue<P,vector<P>,greater<P> > q;
    for (auto i:ma){
        q.push(make_pair(i.second,0));
    }
    P x,y;
    while(q.size()>1){
        x=q.top();
        q.pop();
        y=q.top();
        q.pop();
        q.push(make_pair(x.first+y.first,x.first+y.first+x.second+y.second));
    }
    cout << q.top().second << endl;
}


Measured memory_bytes: 3332
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
#define cycle_per_sec 2806192512
int main() {
	int n;
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		long long c;
		cin >> c;
		while (c % 2 == 0) {
			ans++;
			c /= 2;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;

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

const int maxn = 5e5 + 10;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

#define dbg(x1) cout<<#x1<<" = "<<(x1)<<endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<(x1)<<" "<<#x2<<" = "<<(x2)<<" "<<#x3<<" = "<<(x3)<<endl
ll dp[maxn];
ll pos[maxn];
int d[maxn];
int main() {
    //freopen(".in", "r", stdin);
    int n,q,D;scanf("%d%d",&n,&D);
    for(int i=1;i<=n;i++) scanf("%d",&d[i]);
    pos[0]=D;
    for(int i=1;i<=n;i++)
    {
        if(pos[i-1]>=d[i]) pos[i]=pos[i-1]-d[i];
        else pos[i]=min(pos[i-1],d[i]-pos[i-1]);
    }
    scanf("%d",&q);
    dp[n+1]=1;
    for(int i=n;i>=1;i--)
    {
        if(2LL*dp[i+1]>d[i]) dp[i]=dp[i+1]+d[i];
        else dp[i]=dp[i+1];
    }
    while(q--)
    {
        int x;scanf("%d",&x);
        if(pos[x-1]>=dp[x+1]) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 11648
import * as fs from "fs";

const main = (input: string): void => {
  const numbers = input.split(" ").map((string) => parseInt(string, 10));
  let fives = 0;
  let sevens = 0;

  numbers.forEach((num) => {
    if (num === 5) fives += 1;
    if (num === 7) sevens += 1;
  });

  if (fives === 2 && sevens === 1) console.log("YES");
  else console.log("NO");
};

fs.readFile("/dev/stdin", (err, data) => {
  if (err) {
    main(fs.readFileSync("./input.txt", "utf8"));
    return null;
  }
  main(data.toString());
  return null;
});


Measured memory_bytes: 29608
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 C = sc.nextInt();
      int[] B = new int[M];
      for(int x=0;x<M;x++){
    	  B[x] = sc.nextInt();
      }
      int[] A = new int[M];
      int total;
      int count = 0;
      for(int y=0;y<N;y++){
    	total = 0;
    	for(int z=0;z<M;z++){
    		A[z] = sc.nextInt();
    		total = total + A[z]*B[z];
    	}
    	total = total + C;
    	if(0<total){
    		count++;
    	}
      }
      System.out.println(count);
    }
}

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

int main(){
	string s;	cin>>s;
	int n=s.length();	vector<int> ans(n,0);

	for(int i=0;i<n; ){
		int L=i;
		while(i<n && s[i]=='R')i++;
		// RRRRRR"L"LLLLL
		// この"L"のポジまでiを持ってくる
		int m=i;
		while(i<n && s[i]=='L')i++;
		// RRRRRRLLLLLL"."
		// RR...LLLのひとかたまりから脱出
		int R=i;

		// ...RL... の部分に値が集まる！
		ans[m-1]=(m-L+1)/2 + (R-m)/2;
		/*
			Rのほう
			(自分含めた)Rのうち半分 + Lのうち半分
		*/

		ans[m  ]=(m-L)/2 + (R-m+1)/2;
		/*
			Lのほう
			Rのうち半分 + (自分含めた)Lのうち半分
		*/

	}

	for(int i=0;i<n;i++){
		if(i)cout<<" ";
		cout<<ans[i];
	}cout<<endl;

	return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    set<char> st[2][26];
    string s,t;
    cin>>s>>t;
    rep(i,s.size()){
        st[0][s[i]-'a'].insert(t[i]);
        st[1][t[i]-'a'].insert(s[i]);
    }
    
    rep(i,2){
        for(auto elm:st[i]){
            if(elm.size()>=2){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 776
<?php
fscanf(STDIN, "%d %d", $N, $M);
$a =array();
$f =array();
for($i=0;$i<$M;$i++){
  fscanf(STDIN, "%d", $a[]);
}
$i=0;
$f[0]=1;

$f[1]=1;
if(isset($a[0])&&$a[0]==1){
 $f[1] = 0; 
 $i++;
}
for($j=2;$j<=$N;$j++){
  $f[$j]=($f[$j-1]+$f[$j-2])%1000000007;
  if(isset($a[$i])&&$a[$i]==$j){
    $i++;
    $f[$j]=0;
  }
}


  echo  ($f[$N]%1000000007)."\n";

?>



Measured memory_bytes: 16884
#include <bits/stdc++.h>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	string s;
	cin>>s;
	if(s.size()<=n){
		cout <<s;
		return 0;
	}
	for(ll i=0;i<n;i++){
		cout <<s[i];
	}
		cout << "...";
	// your code goes here
	return 0;
}

Measured memory_bytes: 3624
S = int(input())
S1=S%10
S2=(S%100-S1)/10
S3=(S%1000-S2*10-S1)/100
S4=(S-S3*100-S2*10-S1)/1000
#print("{}{}{}{}".format(S1,S2,S3,S4))
if S1==S2 or S2==S3 or S3==S4:
    print("Bad")
else:
    print("Good")


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include <vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

vll ans(200000 + 1);

void dfs(int n, int p, Graph& g) {
	for (auto c : g[n]) {
		if (c == p) continue;
		ans[c] += ans[n];
		dfs(c, n, g);
	}
	return;
}

int main() {
	int n, q;
	cin >> n >> q;
	Graph g(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	rep(i, q) {
		int p, x;
		cin >> p >> x;
		p--;
		ans[p] += x;
	}
	dfs(0, -1, g);
	rep(i, n) {
		cout << ans[i] << " ";
	}
	cout << endl;
}

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

int main(){
    int n, l0=2, l1=1;
    long int l_i1, l_i2, l;
    cin >> n;

    if(n>1){
        l_i1 = l1;
        l_i2 = l0;

        for(int i=2; i<=n; i++){
            l = l_i1 + l_i2;
            l_i2 = l_i1;
            l_i1 = l;
        }

        cout << l << endl;
    }else if(n==1){
        cout << l1 <<endl;
    }


}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    if(a % 2 == 0 || b % 2 == 0 || c % 2 == 0){
        cout << 0 << endl;
        return 0;
    }
    cout << min({b*c, a*c, a*b}) << endl;

    return 0;
}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t A, B, C, K;
  cin >> A >> B >> C >> K;
  // const int64_t L = static_cast<int64_t>(T.length());
  int64_t result = 0;
  while (B <= A) {
    ++result;
    B *= 2;
  }
  while (C <= B) {
    ++result;
    C *= 2;
  }
  // cerr << result << endl;
  if (result <= K) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589
int main(void)
{
    double r,S,L;
    scanf("%lf",&r);
    S=PI*r*r;
    L=2*PI*r;
    printf("%f %f\n", S, L);
     return 0;
}


Measured memory_bytes: 2684
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <time.h>
#include <random>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
vector<int> vertexs[2][200000];
int connectivity[2][200000] = {};
map<pair<int, int>,int> wow;
int main() {
	int n,k,l;
	cin >> n >> k >> l;
	REP(i, k) {
		int a, b;
		cin >> a >> b;
		vertexs[0][a].push_back(b);
		vertexs[0][b].push_back(a);
	}
	REP(i, l) {
		int a, b;
		cin >> a >> b;
		vertexs[1][a].push_back(b);
		vertexs[1][b].push_back(a);
	}
	for (int i = 0;i < 2;++i) {
		int cnt = 1;
		for (int q = 1;q <= n;++q) {
			if (connectivity[i][q] == 0) {
				connectivity[i][q] = cnt;
				queue<int> tmp;
				tmp.push(q);
				while (tmp.empty() == false) {
					int woa = tmp.front();
					tmp.pop();
					for (int j = 0;j < vertexs[i][woa].size();++j) {
						if (connectivity[i][vertexs[i][woa][j]] == false) {
							connectivity[i][vertexs[i][woa][j]] = cnt;
							tmp.push(vertexs[i][woa][j]);
						}
					}
				}
				cnt++;
			}
		}
	}
	for (int i = 1;i <= n;++i) {
		wow[make_pair(connectivity[0][i], connectivity[1][i])]++;
	}
	for (int i = 1;i <= n;++i) {
		cout << wow[make_pair(connectivity[0][i], connectivity[1][i])] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 27940
#include<bits/stdc++.h> //ABC 136_a
using namespace std;
int main(){
	int A,B,C,ans;
	cin>>A>>B>>C;
	ans=C-(A-B);
	if(ans<0){
		cout<<0; return 0;
	}
	else
		cout<<ans;	
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
src_all = [input().split() for _ in range(n)]
# src = [['2', '1', '3'], ['3', '1', '2', '3'], ['2', '3', '2']]
tmp = {}
for src in src_all:
    for i,s in enumerate(src):
        if i != 0:
            if s in tmp:
                tmp[s] += 1
            else:
                tmp[s] = 1
count = 0
for t in tmp.values():
    if t == n:
        count +=1
print(count)

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int R, G, B, N;

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

    std::cin >> R >> G >> B >> N;

    int res = 0;

    for(int r=0;R*r<=N;++r){
        for(int g=0;R*r+G*g<=N;++g){
            if((N - (R * r + G * g)) % B == 0){
                res += 1;
            }
        }
    }

    std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    VI cnt(26);
    REP(i,0,n) cnt[s[i] - 'a']++;
    LL ans = 0;
    REP(i,0,26) {
        LL tmp = cnt[i];
        REP(j,i+1,26) tmp = (tmp * (cnt[j] + 1)) % MOD;
        ans = (ans + tmp) % MOD;
    }
    cout << ans << endl;
}

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

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

int main(void)
{
	int a,b,c;
	long long sum=0;
	scanf("%d",&a);
	b=a/500;
	sum+=1000*b;
	a%=500;
	c=a/5;
	sum+=c*5;
	printf("%lld\n",sum);
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = list(input())

    flag = False

    for i in range(N):
        T1 = S[:i]
        T2 = S[i:N]

        if(T1 == T2):
            flag = True
            #print('Yes')
            break

        # print(T1)
        # print(T2)
    if(flag):
        print('Yes')
    else:
        print('No')
if __name__ == "__main__":
    main()

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

int main(){
  int a,b,c,x,ans=0;cin>>a>>b>>c>>x;
  REP(i,a) REP(j,b) REP(k,c) if(500*i+100*j+50*k==x) ans++;
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <math.h>
#include <algorithm>
#include <float.h>
#include <limits>
#include <vector> 
#include <string.h>
#include <iomanip>

#define rep(i,a,n) for(ll int (i) = (a);(i) < (n);(i)++)
#define urep(i,a,n) for(ll int (i) = (a);(i) > (n);(i)--)
#define MOD 1000000007
#define Imax 2147483647
#define ll long long
#define asort(a) sort(a.begin(),a.end());

using namespace::std;

int jo(ll int jxo, ll int jyo){//累乗
	ll int jhogeo = 1;
	rep(jinto,0,jyo) jhogeo=jhogeo*jxo;
	return jhogeo;
}
char tobig(char toxbig){//char大文字化
  return (toxbig-0x20);
}
char tolow(char toxlow){//char小文字化
  return (toxlow+0x20);
}
int ctoi(char cctoi){//char->int
  if('0' <= cctoi && cctoi <= '9') return (cctoi-'0');
  return -1;
}
int gcd(int gcad, int gcbd) {//最大公約数
  if(gcad < gcbd) return gcd(gcbd, gcad);
  int gcrd;
  while ((gcrd=gcad%gcbd)) {
    gcad = gcbd;
    gcbd = gcrd;
  }
  return gcbd;
}
int lcm(int lcam, int lcbm){//最小公倍数
 return (lcam*lcbm)/gcd(lcam,lcbm);
}


int main(){
  int N,T;
  cin>>N>>T;
  vector<int> c(N);
  vector<int> t(N);
  rep(i,0,N) cin>>c[i]>>t[i];
  int cost=Imax;
  rep(i,0,N){
    if(t[i]<=T&&c[i]<cost) cost=c[i];
  }
  if(cost==Imax) cout<<"TLE";
  else cout<<cost;
      
  
}
// int *p = new int[N];

//  vector<int> 変数名(要素数);
//  sort(変数名.begin(),変数名.end());//昇順ソート

// vector<vector<int>> 変数名(左の個数, vector<int>(右の個数));

//


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

using namespace std;
typedef long long ll;

int main(){
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> a(m);
    for(int i=0;i<m;i++){
        cin >> a[i];
    }
    int lb = lower_bound(a.begin(),a.end(),x) - a.begin();
    if(lb<m-lb)cout << lb << endl;
    else cout << m-lb << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll          long long
#define ld          long double
#define pb          push_back
#define pf          push_front
#define mp          make_pair
#define pll         pair<ll,ll>
#define vl          vector<ll>
#define sl          set<ll> 
#define vll         vector<pll>
#define ml          map<ll,ll>
#define mll         map<pll,ll>
#define all(a)      a.begin(),a.end()
#define x           first
#define y           second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define mod         (ll)1000000007
#define lp(i,a,b)   for(ll i=a;i<b;++i)
#define lpr(i,a,b)  for(ll i=a;i>=b;i--)
#define lpd(i,x)    for(auto i:x)
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll inf = (ll)1e18;
ld pi = 3.141592653589;
using namespace std;

ll bpow(ll x, ll v) {	
	if (v == 0)
		return 1 % mod;
	if (v % 2 == 1)
		return (x * bpow(x, v - 1)) % mod;
	ll r = bpow(x, v / 2);
	return (r * r) % mod;	
}

ll lcm(ll a,ll b)
{
	ll ret=(a*b)/__gcd(a,b);
	return ret;
} 

ll solve(){ 
	ll h,n,s=0; cin>>h>>n;
	lp(i,0,n){
		ll p; cin>>p;
		s+=p;
	}
	if(s>=h) cout<<"Yes";
	else cout<<"No";
}
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
    	solve();
    }
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  int n,ans=0,k=0;cin>>n;
  vi v(n);
  rep(i,n)cin>>v[i];
  rep(i,n-1){
    if(v[i]==v[i+1])k++;
    else{
      ans+=(k+1)/2;
      k=0;
    }
  }
  ans+=(k+1)/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int par[100100],idx[100100];
vector<int> G[100100],tps,g[100100];
bool ok[100100];
void dfs(int x){
  ok[x]=false;
  for(int i:G[x])
    if(ok[i])dfs(i);
  tps.push_back(x);
}
signed main(){
  int N,M;
  cin>>N>>M;
  for(int i=0;i<N-1+M;i++){
    int a,b;
    cin>>a>>b;
    G[a-1].push_back(b-1);
    g[b-1].push_back(a-1);
  }
  for(int i=0;i<N;i++)ok[i]=true;
  for(int i=0;i<N;i++)
    if(ok[i])dfs(i);
  reverse(tps.begin(),tps.end());
  idx[N]=-1;
  for(int i=0;i<N;i++){
    par[tps[i]]=N;
    for(int j:g[tps[i]])
      if(idx[par[tps[i]]]<idx[j])par[tps[i]]=j;
    idx[tps[i]]=i;
    if(i==0)par[tps[i]]=-1;
  }
  for(int i=0;i<N;i++)cout<<par[i]+1<<endl;
}

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

int main(){
  int a,b,c,d; cin>>a >>b >>c >>d;
  if(a+b == c+d){
    cout<<"Balanced"<<endl;
  }else if(a+b > c+d){
    cout<<"Left"<<endl;
  }else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
import java.text.*;
import java.util.*;

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

    private void doit()
    {
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final String title = sc.next();
        int count = 0;
        for(int i = 0; i < N; ++i)
        {
            final String old = sc.next();
            if(this.creatable(title, old))
            {
                ++count;
            }
        }
        System.out.println(count);
    }

    private boolean creatable(final String title, final String old)
    {
        for(int bi = old.indexOf(title.charAt(0)); bi != -1; bi = old.indexOf(title.charAt(0), bi + 1))
        {
            for(int dif = 1; dif <= (old.length() - bi - 1) / (title.length() - 1); ++dif)
            {
                for(int ti = 1; ti < title.length(); ++ti)
                {
                    if(title.charAt(ti) != old.charAt(bi + dif * ti))
                    {
                        break;
                    }
                    else if(ti == title.length() - 1)
                    {
                        return true;
                    }
                }
            }
        }
        return false;
    }
}

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

int main(){
    int n;
    string s1, s2;
    int a = 0, b = 0;
    cin >> n;

    for(int i = 0; i < n; i++){
       cin >> s1 >> s2;
      if(s1 > s2)a+=3;
       else if(s1 < s2)b+=3;
       else{
        a++; b++;
    }
}

    cout << a <<" "<< b << endl;

    return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <numeric>
#include <climits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <utility>
#include <cctype>
#include <iterator>
////////////////////////////////////////////////
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int n, k;
  cin >> n >> k;
  vecint p(n);
  REPe(e, p) cin >> e;
  sort(all(p));
  int ans = 0;
  REP(i, k) { ans += p[i];
   }
  cout << ans << endl;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
    static int MOD = 365;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        // k: コンテストの種類数
        int k = 26;
        
        // n: 1日目～n日目にコンテストが開催される
        int n = sc.nextInt();
        
        // c[i]: タイプiのコンテストのマイナス係数
        int[] c = new int[k];
        for (int i = 0; i < k; i++) {
            c[i] = sc.nextInt();
        }
        
        // s[d][i]: タイプiをd日目に開催したときに増加する満足度
        int[][] s = new int[n+1][k];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j < k; j++) {
                s[i][j] = sc.nextInt();
            }
        }
        
        // t[i]: i日目に開かれるコンテストのタイプ
        int[] t = new int[n+1];
        // for (int i = 1; i <= n; i++) {
        //     t[i] = sc.nextInt() - 1;
        // }
        
        // last[i]: タイプiのコンテストが最近何日目に開かれたか
        int[] last = new int[k];
        
        // 満足度計算
        long score = 0;
        for (int i = 1; i <= n; i++) {
            long max = -1;
            int choice = -1;
            for (int contest = 0; contest < k; contest++) {
                // int contest = t[i];
                
                long tmp = 0;
                
                // UP
                tmp += s[i][contest];
                // last[contest] = i;
                
                // DOWN
                for (int j = 0; j < k; j++) {
                    tmp -= c[j] * (i-last[j]);
                }
                tmp += c[contest] * (i-last[contest]);
                
                // System.out.println(score);
                
                if (contest == 0 || tmp > max) {
                    choice = contest;
                    max = tmp;
                }
                
                // System.out.println(contest + " " + choice + " " + tmp + " " + max);
            }
            
            score += max;
            last[choice] = i;
            t[i] = choice;
        }
        
        for (int i = 1; i <= n; i++) {
            System.out.println(t[i] + 1);
        }
    }
    
    static public class Test {
        Test() {
            System.out.println(MOD);
        }
        
    }
}


Measured memory_bytes: 47000
import sys
read = sys.stdin.readline


def readln():
    return list(map(int, read().split()))


N, M = readln()

A = []
B = []
data = {}
for _ in range(N):
    a, b = readln()
    A.append(a)
    B.append(b)
    data[a] = 0

for a, b in zip(A, B):
    data[a] += b

ans = 0
drink = 0
for k, v in sorted(data.items()):
    ans += k * v
    drink += v
    if drink > M:
        break
print(ans-k*(drink-M))


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

int main(){
  int N,M,A;
  cin>>N>>M;
  vector<int> L(M),R(M);
  for (int i = 0; i < M; i++) {
    cin >> L.at(i) >> R.at(i);
  }
  sort(L.begin(),L.end());
  sort(R.begin(),R.end());
  A=R.at(0)-L.at(M-1)+1;
  if(A<0) A=0;
  cout<<A<<endl;
}

Measured memory_bytes: 1024
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

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

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...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

	long long n, m; cin >> n >> m;
	priority_queue<long long> pq;

	for (long long i = 1; i <= n; i++) {
		long long a; cin >> a;
		pq.push(a);
	}

	while (m--) {
		long long t = pq.top(); pq.pop();
		pq.push(t / 2);
	}

	long long ans = 0;
	while (!pq.empty()) ans += pq.top(), pq.pop();
	cout << ans;

	return 0;
}

Measured memory_bytes: 4260
import math

n = int(input())

a = 0
b = 0
c = 0
d = 0
max = -9999999999

x = list(map(int, input().split()))
y = list(map(int, input().split()))

for i in range(n):
    if x[i] - y[i] < 0:
        a += y[i] - x[i]
    else:
        a += x[i] - y[i]

for i in range(n):
    b += (x[i] - y[i]) ** 2

c = math.sqrt(b)

for i in range(n):
    if x[i] - y[i] > 0:
        d += (x[i] - y[i]) ** 3
    else:
        d += (y[i] - x[i]) ** 3

e = d ** (1 / 3)

for i in range(n):
    if x[i] - y[i] < 0:
        if y[i] - x[i] > max:
            max = y[i] - x[i]
    else:
        if x[i] - y[i] > max:
            max = x[i] - y[i]

print("{:.6f}".format(a))
print("{:.6f}".format(c))
print("{:.6f}".format(e))
print("{:.6f}".format(max))


Measured memory_bytes: 5704
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $mod=1000000007;

  $ten=1;
  $nine=1;
  $eight=1;
  for($i=1;$i<=$n;$i++){
    $ten*=10;
    $ten%=$mod;
    $nine*=9;
    $nine%=$mod;
    $eight*=8;
    $eight%=$mod;
  }

  $ans=$ten-$nine;
  if($ans < $mod) $ans+=$mod;
  $ans-=$nine;
  if($ans < $mod) $ans+=$mod;
  $ans+=$eight;
  $ans%=$mod;

  echo $ans;

Measured memory_bytes: 16176
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<=(n);++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const double Pi = acos(-1);
const ll mod=1e9+7;

int main(){
    char s;
    cin >>s;
    if(isupper(s)){
        cout << 'A' <<endl;
    }else{
        cout << 'a' <<endl;
    }

    return 0;
}

Measured memory_bytes: 3620
n = int(input())
b = list(map(int, input().split()))
b.reverse()
a = [0]*(n-1)
a[0] = b[0]
for i in range(1,n-1):
	if b[i] > b[i-1]:
		a[i] = b[i-1]
	else:
		a[i] = b[i]
if len(b) > 1 and b[-1] > b[-2]:
	print (sum(a) + b[-1])
else:
	print (sum(a)+a[-1])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int n,tmp,ans=0;
std::vector<int> data;



void solve(){
  sort(data.begin(),data.end());
  reverse(data.begin(),data.end());
  for(int i=0;i<n-2;i++){
    for(int j=i+1;j<n-1;j++){
      if(data.at(i)>data.at(j)*2){
        break;
      }
      for(int k=j+1;k<n;k++){
        if(data.at(i)<data.at(j)+data.at(k)){
          ans++;
        }else{
          break;
        }
      }
    }
  }

  cout<<ans<<endl;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>tmp;
    data.push_back(tmp);
  }

  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	 int n;
	 while(cin>>n)
	 {  int maxx=n/4;
	 int maxy=n/7;
	 int flag=0;
	 	 for(int i=0;i<=maxx;i++)
	 	   {
	 	   	  for(int j=0;j<=maxy;j++)
	 	   	  {
	 	   	  	 if(i*4+j*7==n)
	 	   	  	   {
	 	   	  	   	 flag=1;
	 	   	  	   	 break;
						 }
				  }
				  if(flag)break;
			}
			if(flag)printf("Yes\n");
			else printf("No\n");
	 }
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N, A = map(int, input().split())
    X = list(sorted(list(map(int, input().split()))))

    dp = [[0] * (50 * 50 + 2) for _ in range(52)]
    dp[0][0] = 1
    for i in range(N):
        x = X[i]
        for j in range(N, -1, -1):
            for k in range(len(dp[0])):
                if dp[j][k] != 0 and k + x < len(dp[0]):
                    dp[j + 1][k + x] += dp[j][k]

    ans = 0
    for i in range(1, N + 1):
        for j in range(len(dp[0])):
            if dp[i][j] != 0 and j == A * i:
                ans += dp[i][j]
    print(ans)


if __name__ == '__main__':
    main()


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int d,e;

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>d>>e;
		if(d==0)break;
		double res=10000000;
		rep(x,d+1){
			int y=d-x;
			minch(res,abs(sqrt(x*x+y*y)-(double)e));
		}
		printf("%.10f\n", res);
	}
	return 0;
}

Measured memory_bytes: 3132
n = int(input())
t = [tuple(map(int, input().split())) for _ in range(n)]
s = set(t)
cnt = 0
for i in range(n-1):
  for j in range(i+1,n):
    u,v = t[i]
    x,y = t[j]
    p = u-x; q = v-y
    c = sum((x-p, y-q) in s for x,y in t)
    if cnt < c: cnt = c
print(n-cnt)


Measured memory_bytes: 3064
S = list(input())

#勝利数
win = S.count("o")
#これから勝つ必要のある試合
korekara = 8 - win
#戦った試合
match = len(S)
#残り試合
nokori = 15 - match

if korekara <= 0:
    print("YES")
elif nokori >= korekara:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

N = int(input())
k = 0
while k * (k+1) // 2 < N:
  k += 1
while N > 0:
  print(min(k, N))
  N -= min(k, N)
  k -= 1


Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{

    ll n,m,i,j,k,p,q,o,l,s,t;
   string a,b;
   cin>>n>>a>>b;
   for(i=0;i<n;i++)
   {
       cout<<a[i]<<b[i];
   }
   cout<<endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    proconio::input! {
        x: i64,
    }
    for a in 0..1000 {
        let d=a*a*a*a*a-x;
        let mut l=0;
        let mut r=1000;
        while l<r {
            let m=(l+r)/2;
            let v=m*m*m*m*m;
            if d.abs()<v {
                r=m;
            }
            else if d.abs()>v {
                l=m+1;
            }
            else {
                println!("{} {}",a,if d<0 {-m} else {m});
                return;
            }
        }
    }
    println!("0 0");
}

Measured memory_bytes: 2140
#include <iostream>

using namespace std;

int main(){

  int N, K;
  cin >> N >> K;

  int a[100] = {};
  int character_number;
  int hold_num;

  for(int i = 0; i < K; ++i){
    cin >> hold_num;
    for(int j = 0; j < hold_num; ++j){
      cin >> character_number;
      a[character_number-1]++;
    }
  }

  int counter = 0;
  for(int i = 0; i < N; ++i){
    if(a[i] == 0) counter++;
  }
  cout << counter << endl;

  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int num;
  string S;
  cin >> S;
  vector<int> A(S.size()), num1(S.size() - 2);
  for (int i = 0; i < S.size(); i++)
  {
    if (S[i] == '1')
    {
      A[i] = 1;
    }
    else if (S[i] == '2')
    {
      A[i] = 2;
    }
    else if (S[i] == '3')
    {
      A[i] = 3;
    }
    else if (S[i] == '4')
    {
      A[i] = 4;
    }
    else if (S[i] == '5')
    {
      A[i] = 5;
    }
    else if (S[i] == '6')
    {
      A[i] = 6;
    }
    else if (S[i] == '7')
    {
      A[i] = 7;
    }
    else if (S[i] == '8')
    {
      A[i] = 8;
    }
    else if (S[i] == '9')
    {
      A[i] = 9;
    }
  }
  for (int i = 0; i < S.size() - 2; i++)
  {
    num = A[i] * 100 + A[i + 1] * 10 + A[i + 2];
    num1[i] = 753 - num;
    if (num1[i] < 0)
    {
      num1[i] *= (-1);
    }
  }
  sort(num1.begin(), num1.end());
  cout << num1[0] << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


ll mod = 1000000007;
ll factorial[101010];
int main() {
	int N;
	string S;
	cin >> N >> S;
	factorial[0] = 1;
	for (int i = 1; i <= N; i++) {
		factorial[i] = i * factorial[i - 1];
		factorial[i] %= mod;
	}


	ll ans = 1;
	int cnt = 0;
	for (int i = 0; i < 2*N; i++) {
		if (cnt % 2) {
			if (S[i] == 'W')cnt++;
			else {
				ans *= cnt;
				cnt--;
			}
		}
		else {
			if (S[i] == 'W') {
				ans *= cnt;
				cnt--;
			}
			else cnt++;
		}
		ans %= mod;
	}
	if (cnt != 0)ans = 0;
	ans *= factorial[N];
	ans %= mod;
	puts(ans);

	return 0;
}

Measured memory_bytes: 1412
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
//#pragma GCC target("avx,tune=native")
#include<bits/stdc++.h>
#define int long long
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
int n;
int a[100005];
int b[100005],pre[100005];
int ll[100005],rr[100005];
int mergesort(int l,int r){
	if(l==r)return 0;
	int mid=l+r>>1;
	int ret=mergesort(l,mid);
	ret+=mergesort(mid+1,r);
	for(int i=l;i<=(l+r)/2;i++)ll[i]=pre[i];
	for(int i=(l+r)/2+1;i<=r;i++)rr[i]=pre[i];
	int pos=l,lpos=l,rpos=mid+1;
	while(lpos!=mid+1||rpos!=r+1){
		if(lpos==mid+1){pre[pos++]=rr[rpos++];continue;}
		if(rpos==r+1){pre[pos++]=ll[lpos++];continue;}
		if(ll[lpos]<=rr[rpos]){
			ret+=(r+1-rpos);
			pre[pos++]=ll[lpos++];
		}else{
			pre[pos++]=rr[rpos++];
		}
	}
	return ret;
}
bool check(int v){
	for(int i=1;i<=n;i++)b[i]=(a[i]>=v?1:-1);
	pre[0]=0;
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+b[i];
	int sum=mergesort(0,n);
//	cerr<<v<<" "<<sum<<endl;
	return sum>=1ll*n*(n+1)/4;
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	if(n==1){
		cout<<a[1]<<endl;
		return 0;
	}
	int l=-1,r=2e9;
	while(r-l>1){
		int mid=l+r>>1;
		if(check(mid))l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 4224
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	int N, K;
	cin >> N >> K;
	if (K == 1) {
		cout << 0 << endl;
	}
	else {
		int big = N - K + 1;
		cout << big - 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256