akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = (1<<30);
 
int main() {
  string s;
  cin >> s;
  int sum = 0;
  for(int i = 0; i < 4; i++) {
    if(s[i] == '+') sum++;
    else sum--;
  }
  cout << sum << endl;
}

Measured memory_bytes: 3616
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=100000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}

int op(int a,int b){return max(a,b);}
int e(){return -INF;}
int n,k;
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>k;
    segtree<int,op,e>seg(300001);
    rep(i,300001)seg.set(i,-1000000000);
    rep(i,n){
        int a;
        cin>>a;
        int p=seg.prod(max(0,a-k),min(300001,a+k+1));
        seg.set(a,max({seg.get(a),p+1,1}));
    }
    cout<<seg.all_prod()<<endl;
    return 0;
}


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

int main () {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (a * b > c * d) cout << a * b << endl;
    else if (a * b < c * d) cout << c * d << endl;
    else cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main(void){
	long long x; cin>>x;
	long long ans=x/11*2;
	long long ANS=x%11;
	if(ANS>6){
		cout<<ans+2<<endl;
	}else if(ANS==0){
		cout<<ans<<endl;
	}else{
		cout<<ans+1<<endl;
	}
	
    
}


Measured memory_bytes: 256
//FIRST THINK, THEN CODE.


#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}
 
const ll N=2e6+5;



ll fac[N],inv[N];

ll  c(ll a,ll b,ll p){
  if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*inv[b]%p;
}

int main()
{ 
IOS;

ll k;cin>>k;

string s;cin>>s;

ll p=(ll)1e9+7;

ll ans=0;

ll n=s.size();

ll x=1;

fac[0]=inv[0]=1;

for(int i=1;i<N;i++){
  fac[i]=fac[i-1]*i%p;
  inv[i]=powM(fac[i],p-2,p);
}

//cout<<c(5,2,p)<<endl;

for(ll i=0;i<=k;i++)
{
  ll temp=powM(26,k-i,p)*powM(25,i,p)%p;
 // cout<<temp<<endl;

  temp=temp*c(n+i-1,i,p);
 // cout<<c(n+i-1,i,p)%p;
  ans=ans+temp;
  ans%=p;

}

cout<<ans<<endl;



 return 0;
 
 
 
}

Measured memory_bytes: 35600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5;
int main(){
    ll a[N];
    int n;
    cin>>n;
    map<ll,ll>m,M;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    ll sum=0;
    for(int i=0;i<n;i++){
        if(m[a[i]]>1 && M[a[i]]==0)
        {sum+=m[a[i]]*(m[a[i]]-1)/2;M[a[i]]=1;}
    }
    //cout<<sum<<endl;
    for(int i=0;i<n;i++){
        cout<<sum-m[a[i]]+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 14336
/**
 * @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 N;
  cin >> N;

  const int64_t keys[] = {7, 5, 3};
  int64_t result = 0;
  auto Dfs = [&](auto &&Func, vector<int64_t> num, const int64_t digit) -> void {
    int64_t L = static_cast<int64_t>(num.size());
    if (L == digit) {
      vector<bool> is_okay(3, false);
      for (const auto n : num) {
        if (n == 7) {
          is_okay[0] = true;
        } else if (n == 5) {
          is_okay[1] = true;
        } else if (n == 3) {
          is_okay[2] = true;
        }
      }
      int64_t cval = 0;
      for (const auto v : num) {
        cval *= 10;
        cval += v;
      }
      if (cval <= N && is_okay[0] && is_okay[1] && is_okay[2]) {
        ++result;
      }
    } else {
      for (const auto &key : keys) {
        num.push_back(key);
        Func(Func, num, digit);
        num.pop_back();
      }
    }
  };
  vector<int64_t> nums;

  for (int64_t digit = 1; digit <= 9; ++digit) {
    Dfs(Dfs, nums, digit);
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3656
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	public static void main(String[] args) {
		try {
			Pattern pattern = Pattern.compile("([0-9]+) *([0-9]+)");
			BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
			Matcher matcher;
			String temp;
			int sum;
			while((temp = bf.readLine() ) != null){
				if(temp.length()==0)break;
				matcher = pattern.matcher(temp);
				if(matcher.matches()){
					sum=Integer.parseInt(matcher.group(1))+Integer.parseInt(matcher.group(2));
					temp=Integer.toString(sum);
					System.out.println(temp.length());
				}
			}
		}catch(Exception e){
			System.out.println(e);
		}
	}
}

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

int n, aux;
bool resp=true;

int main(){
 	cin >> n;

 	for(int i=0;i<n;i++){
        cin >> aux;
        if(aux%2==0){
            if(aux%3!=0 && aux%5!=0){
                resp=false;
            }
        }
 	}

 	if(resp) cout << "APPROVED" << endl;
 	else cout << "DENIED" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int a[3], k;
	std::cin >> a[0] >> a[1] >> a[2] >> k;
	
	bool ok = false;
	
	while (k > 0 and a[0] >= a[1]) {
		a[1] *= 2;
		k--;
	}
	
	while (k > 0 and a[1] >= a[2]) {
		a[2] *= 2;
		k--;
	}
	
	if (a[0] < a[1] and a[1] < a[2]) {
		std::cout << "Yes" << '\n';
	} else {
		std::cout << "No" << '\n';
	}
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	vector<vector<int > > events(n, vector<int>(3));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < 3; j++){
			cin >> events[i][j];
		}
	}
	vector<vector<int>> dp(n, vector<int>(3));
	dp[0][0] = events[0][0];
	dp[0][1] = events[0][1];
	dp[0][2] = events[0][2];
	for(int i = 1; i < n; i++){
		dp[i][0] = max(dp[i-1][1], dp[i-1][2])+events[i][0];
		dp[i][1] = max(dp[i-1][0], dp[i-1][2])+events[i][1];
		dp[i][2] = max(dp[i-1][0], dp[i-1][1])+events[i][2];
	}
	cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;
}

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

int main() {
  
  int N;
  cin >> N;
  
  vector<int> A(N);
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  sort(A.begin(), A.end());
  for(int i = 0; i < N; i++) {
//    cout << A.at(i) << endl;
  }
  
  for(int i = 0; i < N-1; i++) {
    if(A.at(i) == A.at(i+1)) {
      cout << "NO" << endl;
      break;
    }
    else if(i == N-2) cout << "YES" << endl;
  }
  
}

Measured memory_bytes: 4016
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	boolean isPrime(int n) {
		if (n < 2) return false;
		for (int i = 2; i * i <= n; i++)
			if (n % i == 0) return false;
			
		return true;
	}
	
	void run() {
		int a, d, n;
		while (true) {
			a = sc.nextInt();
			d = sc.nextInt();
			n = sc.nextInt();
			if (d == 0) break;
			int count = 0;
			int i = 0;
			while (a+i*d <= 1000000) {
				if (isPrime(a+i*d))
					count++;
				if (count == n)
					break;
				i++;
			}
			out.println(a+i*d);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 20964
'use strict'
let input = require("fs").readFileSync("/dev/stdin", "utf8");
input = input.trim().split('\n').map(x=> x*1);
let ans = "Yay!";
let amount = input.pop();

for(let i = 0; i< input.length; i++){
  for(let j = 0; j< input.length; j++){
    if(i == j){
    	continue
    }
    else if(Math.abs(input[i]-input[j]) > amount){
      ans = ":(";
      break;
    };
  }
}

console.log(ans);


Measured memory_bytes: 7372
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll r;cin>>r;
  lfs<<2*r*acos(-1)<<endl;
  return 0;
}

Measured memory_bytes: 3700
const input = require("fs").readFileSync("/dev/stdin", "utf8")
let cin = input.split(/ |\n/), cid = 0
const next = () => cin[cid++]
const nexts = (n) => cin.slice(cid, cid+=n).map(i=>parseInt(i))
const T = next()
const array = T.split('').map((item) => {
    if (item === '?') {
        return 'D'
    } else {
        return item
    }
})
console.log(array.join(''))


Measured memory_bytes: 41976
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> istream& operator>>(istream& is, vector<T>& v);
template<class T> ostream& operator<<(ostream& os, vector<T> const& v);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream&, const tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream& os, const tuple<T...>& t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream& operator<<(ostream& os, const tuple<T...>& t){ _ot<0>(os, t); return os; }
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _it(istream&, tuple<T...>&){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _it(istream& is, tuple<T...>& t){ is >> get<n>(t); _it<n+1>(is, t); }
template<class...T> istream& operator>>(istream& is, tuple<T...>& t){ _it<0>(is, t); return is; }
template<class T> istream& operator>>(istream& is, vector<T>& v){ rep(i,v.size()) is >> v[i]; return is; }
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif


string ans[1<<20];
char s[32];
char t[32];

int main(){
#ifdef LOCAL
    freopen("in","r",stdin);
#endif
    while(cin >> s && s[0]!='#'){
        int sz = 0;
        int n = strlen(s);
        rep(i,n) t[i] = s[i];
        t[n] = 0;
        int change[32];
        rep(mask,1<<n){
            bool ok = true;
            rep(i,n) if(mask>>i & 1) if(s[i]=='z') ok = false;
            if(!ok) continue;
            rep(i,n){
                t[i] = s[i] + (mask>>i & 1);
            }
            rep(i,26){
                change[i] = 30;
            }
            rep(i,n){
                change[t[n-i-1]-'a'] = n-i-1;
            }
            loop(i,1,26) t[change[i]]--;
            if(strcmp(t,s)==0){
                rep(i,n){
                    t[i] = s[i] + (mask>>i&1);
                }
                ans[sz++] = t;
            }
        }
        sort(ans, ans + sz);
        printf("%d\n",sz);
        if(sz > 10){
            rep(i,5) printf("%s\n", ans[i].c_str());
            rep(i,5) printf("%s\n", ans[sz-5+i].c_str());
        } else {
            rep(i,sz){
                printf("%s\n",ans[i].c_str());
            }
        }
    }
}

Measured memory_bytes: 10492
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
using namespace std;
#define MAX 3000005
#define MOD 1000000007
#define EPS 0.00000000001
#define INF 1000000000
char s[MAX];
long long com[MAX][3];
long long int fact[MAX+1],fact_inv[MAX+1];
long long int gcd(long long int a,long long int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
long long int egcd(long long int a, long long int b, long long int & x, long long int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    long long int x1, y1;
    long long int d = egcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
long long int ModuloInverse(long long int a,long long int n)
{
    long long int x,y;
    x=gcd(a,n);
    a=a/x;
    n=n/x;
    long long int res = egcd(a,n,x,y);
    x=(x%n+n)%n;
    return x;
}
void precal()
{
    int i,j;
    fact[0]=fact_inv[0]=1;
    for(i=1;i<=MAX;i++)
    {
        fact[i]=(fact[i-1]*i)%MOD;
        fact_inv[i]=ModuloInverse(fact[i],MOD);
    }
    com[0][0]=com[0][1]=com[0][2]=1;
    for(i=1;i<MAX;i++)
    {
        for(j=0;j<3;j++)
        {
            com[i][j]=(com[i-1][j]*(26-j))%MOD;
        }
    }
}
long long int C(long long int n,long long int r)
{
    long long int res=fact[n];
    res=(res*fact_inv[n-r])%MOD;
    res=(res*fact_inv[r])%MOD;
    return res;
}
int main()
{
    precal();
    int n,i,j,k;
    char c;
    scanf("%d ",&k);
    for(i=0;;i++)
    {
        scanf("%c",&c);
        if(!('a'<=c&&c<='z')) break;
        s[i]=c;
    }
    n=i;
    long long temp,ans=0;
    for(i=0;i<=k;i++)
    {
        temp=C(n+k-i-1,k-i);
        temp=(temp*com[k-i][1])%MOD;
        temp=(temp*com[i][0])%MOD;
        ans=(ans+temp)%MOD;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 121920
#include <iostream>
using namespace std;
typedef long long int LLI;
int main()
{
	int n, k, score = 1;
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		if( score < k )
			score += score;
		else
			score += k;
	cout << score;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
    set<char> tmp;
    for(auto x:S){
        tmp.insert(x);
    }
    if(tmp.count('E') && !tmp.count('W')){
        cout << NO<<endl; return;
    }
    if(tmp.count('W') && !tmp.count('E')){
        cout << NO<<endl; return;
    }
    if(tmp.count('S') && !tmp.count('N')){
        cout << NO<<endl; return;
    }
    if(tmp.count('N') && !tmp.count('S')){
        cout << NO<<endl; return;
    }
    cout << YES<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
color = nl()
g = [list() for _ in range(n)]
for _ in range(n-1):
    a, b = nm()
    g[a-1].append(b-1)
    g[b-1].append(a-1)

size = [1]*n
par = [-1]*n
h = [list() for _ in range(n+1)]
idx = [0]*n
def dfs(v, p):
    h[color[v]].append(v)
    for x in g[v]:
        if x == p: continue
        par[x] = v
        size[v] += dfs(x, v)
        h[color[v]].append(v)
    h[color[v]].append(v)
    return size[v]
dfs(0, -1)
# print(size)
for v in range(n):
    if idx[v] < len(g[v]) and g[v][idx[v]] == par[v]:
        idx[v] += 1
acc = [0]*(n+10)
ans = [n*(n+1)//2]*(n+1)
for col in range(1, n+1):
    # print(h[col])
    acc[-1] = 0
    p = [-1]
    for v in h[col]:
        if p[-1] == v:
            p.pop()
            if idx[v] >= len(g[v]):
                acc[p[-1]] += size[v]
                continue
            q = size[g[v][idx[v]]] - acc[v]
            idx[v] += 1
            if idx[v] < len(g[v]) and g[v][idx[v]] == par[v]:
              idx[v] += 1
            ans[col] -= q*(q+1)//2
            acc[v] = 0
            # print(v, q)
            p.append(v)
        else:
            p.append(v)
    q = n - acc[-1]
    # print(-1, q)
    ans[col] -= q*(q+1)//2
print(*ans[1:], sep='\n')

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

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

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    long long sum = 0;
    long long x = 0;

    int r = 0;
    for (int i = 0; i < n; i++) {
        while (r < n&&(sum^a[r])==(sum+a[r])){
            sum += a[r];
            r++;
        }

        x += r - i;
        if(r==i)
            r++;
        else{
            sum -= a[i];
        }
    }
    cout << x << endl;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define debug(fmt, ...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<llll> vllll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }
template<typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template<typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }


ll solve(int N,int W,vi& w,vi& v) {
    vll dp(W+1, -1);
    dp[0] = 0;
    rep(i,N) {
        int wi = w[i], val = v[i];
        for (int j=W; j>=wi; --j) {
            if (dp[j-wi] == -1) continue;
            amax(dp[j], dp[j-wi] + val);
        }
    }
    return *max_element(ALL(dp));
}

int main() {
    int N,W; scanf("%d%d", &N, &W);
    vi w(N),v(N);
    rep(i,N) scanf("%d%d", &w[i], &v[i]);
    cout << solve(N,W,w,v) << endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;

using namespace std;

const ll inf = (ll)2e16;
const ll maxn = (ll)5e3 + 10;

ll dp[maxn];
ll inv[maxn];
ll p[maxn];
ll n, a, b;


void solve(){
    fill(dp, dp + maxn, inf);
    cin >> n >> a >> b;
    for(ll i = 0; i < n; ++i){
        cin >> p[i];
        p[i]--;
    }
    p[n] = n;
    for(ll i = 0; i <= n; ++i){
        inv[p[i]] = i;
    }
    for(ll i = 0; i <= n; ++i){
        ll adda = 0, addb = 0;
        for(ll j = p[i] - 1; j >= -1; --j){
            if(j == -1){
                dp[i] = min(dp[i], adda * a + addb * b);
            }
            dp[i] = min(dp[i], dp[inv[j]] + adda * a + addb * b);
            if(j != p[i]){
                if(inv[j] < i){
                    adda++;
                } else if(inv[j] > i) {
                    addb++;
                }
            }
        }
    }
    cout << dp[n] << "\n";
}

signed main(){
    srand(time(0));
    ll t = 1;
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else

    #endif// DEBUG
    while(t--){
        solve();
    }
}


Measured memory_bytes: 384
/*
 
Coded and Decoded by : Yash Kapoor
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#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 dl          '\n'
//#define why         (ll)1000000007
#define why         (ll)998244353
#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 = 1e18;
ld pi = 3.141592653589;
ll mod = why;
ll fast_power(ll base,ll power,ll mod)
{
    ll result=1;
    while(power)
    {
        if(power%2)
        result=(result*base)%mod;
        base=(base*base)%mod;
        power/=2;
    }
    return result;
}
 
ll inverse(ll base,ll mod)
{
    return fast_power(base,mod-2,mod);
}
 
ll solve(){ 
    string a; cin>>a;
  	lp(i,0,sz(a))
      if(a[i] == '7')
      {
        cout<<"Yes"; return 0;}
  	cout<<"No";
  return 0;
}  
 
int main(){
    ios
    ll t=1; 
    //cin>>t;
    while(t--){
        solve();
    }
}


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

using namespace std;

int main(){

    int num, i, j, status = 0;

    cin >> num;

    for(i = 1; i < 10; i++){
        if(status == 0){
            for(j = 1; j < 10; j++){
                if(i*j == num){
                    status = 1;
                    break;
                }
            }
        }
        else{
            break;
        }
    }

    if(status == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}



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

using namespace std;

const int N = 123456;

int n, m, color[N], number[3], number_e;
vector<pair<int, int>> adj[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  long long answer = 0;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    adj[x].emplace_back(y, 1);
    adj[y].emplace_back(x, -1);
  }
  bool ok;
  function<void (int, int)> dfs = [&] (int x, int z) {
    ++number[color[x] = z];
    for (auto e : adj[x]) {
      int y = e.first;
      if (e.second == 1) {
        ++number_e;
      }
      if (!~color[y]) {
        dfs(y, (z + e.second + 3) % 3);
      } else if (color[y] != (z + e.second + 3) % 3) {
        ok = false;
      }
    }
  };
  memset(color, -1, sizeof color);
  for (int i = 1; i <= n; ++i) {
    if (!~color[i]) {
      memset(number, 0, sizeof number);
      number_e = 0;
      ok = true;
      dfs(i, 0);
      if (ok && (!number[1] || !number[2])) {
        answer += number_e;
      } else if (ok) {
        answer += (long long) number[0] * number[1];
        answer += (long long) number[1] * number[2];
        answer += (long long) number[2] * number[0];
      } else {
        int all = number[0] + number[1] + number[2];
        answer += (long long) all * all;
      }
    }
  }
  cout << answer << '\n';
  return 0;
}

Measured memory_bytes: 13056
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for( int i = 0; i < H; ++i ) cin >> S[i];

    vector<vector<int>> countRow(H, vector<int>(W));
    for( int j = 0; j < W; ++j ){
        if( S[0][j] == '.' ) countRow[0][j] = 1; 
    }
    for( int i = 0; i < H-1; ++i ){
        for( int j = 0; j < W; ++j ){
            if( S[i+1][j] == '.' ) countRow[i+1][j] = countRow[i][j]+1;
        }
    }
    for( int i = H-1; i > 0; --i ){
        for( int j = 0; j < W; ++j ){
            if( S[i-1][j] == '.' and S[i][j] == '.' ) countRow[i-1][j] = countRow[i][j]; 
        }
    }

    vector<vector<int>> countCol(H, vector<int>(W));
    for( int i = 0; i < H; ++i ){
        if( S[i][0] == '.' ) countCol[i][0] = 1; 
    }
    for( int j = 0; j < W-1; ++j ){
        for( int i = 0; i < H; ++i ){
            if( j == 0 and S[i][j] == '.' ) countCol[i][j] = 1; 
            if( S[i][j+1] == '.' ) countCol[i][j+1] = countCol[i][j]+1;
        }
    }
    for( int j = W-1; j > 0; --j ){
        for( int i = 0; i < H; ++i ){
            if( S[i][j-1] == '.' and S[i][j] == '.' ) countCol[i][j-1] = countCol[i][j];
        }
    }

    int ans = 0;
    for( int i = 0; i < H; ++i ){
        for( int j = 0; j < W; ++j ){
            ans = max(ans, countRow[i][j]+countCol[i][j]-1);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 35840
/** BiSmIlLaHiR rAhMaNiR rAhIm **\

*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*

            \**  DIIT(17th batch) **/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define endl "\n"
#define pb push_back
#define eb emplace_back
#define makep make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define PII pair<ll, ll>
#define pii pair<int, int>
#define what_is(x) cerr<<#x<<" is "<<x<<endl;
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    fio();*/
    ll d,n;
    cin>>d>>n;
    if(d==0){
        if(n==100)
            cout<<101<<endl;
        else
            cout<<n<<endl;
    }
    else
    {
        ll count=0;
        if(d==1)
        {
            for(ll i=100;;i++)
            {
                if(i%100==0)
                {
                    if((i/100)%100!=0)
                    count++;
                }
                if(count==n)
                {
                    cout<<i<<endl,exit(0);
                }
            }
        }
        if(d==2)
        {
            for(ll i=10000;;i++)
            {
                if(i%10000==0)
                {
                    if(((i/100)/100)%100!=0)
                    count++;
                }
                if(count==n)
                {
                    cout<<i<<endl,exit(0);
                }
            }
        }
    }
}


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

int main() {
    string s;
    while(cin >> s, s != "#") {
        const int INF = 1000000000;
        vector <vector <int>> dp(s.size() + 1, vector <int> (2, INF));
        dp[0][0] = dp[0][1] = 0;

        //i := 0, 左足
        //     1, 右足
        rep (i, s.size()) rep (j, 2) if (dp[i][j] != INF) {
            if (i == 0) {
                dp[i + 1][0] = dp[i][j];
                dp[i + 1][1] = dp[i][j];
            }
            else {
                //natural step
                int pre = (s[i - 1] - '0') % 3, now = (s[i] - '0') % 3;
                if ((j == 0 && ((pre == 1)
                              || (pre == 2 && (now == 2 || now == 0))
                              || (pre == 0 && now == 0)))
                 || (j == 1 && ((pre == 0)
                              || (pre == 1 && now == 1)
                              || (pre == 2 && (now == 2 || now == 1))))) {
                    //cout << i << " " << j << " " << s[i - 1] - '0' << " " << s[i] - '0' << endl;
                    dp[i + 1][!j] = min(dp[i + 1][!j], dp[i][j]);
                }

                //force
                if (j == 0) dp[i + 1][0] = min(dp[i + 1][0], dp[i][0] + 1);
                if (j == 1) dp[i + 1][1] = min(dp[i + 1][1], dp[i][1] + 1);
            }

            /*
             rep (I, s.size()) {
                rep (J, 2) cout << dp[I][J] << " ";
                cout << endl;
            }
             cout << endl;
             */
        }

        /*
        rep (i, s.size()) {
            rep (j, 2) cout << dp[i][j] << " ";
            cout << endl;
        }
        */
        cout << min(dp[s.size()][0], dp[s.size()][1]) << endl;
    }
    return 0;
}


Measured memory_bytes: 8516
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 10000000000

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
	int A,B,C,D,X,Y;
	cin>>A>>B>>C>>X>>Y;
	if(X>Y)D=A;
	else D=B;
	int ans=0;
	ans+=min(min(X,Y)*A+min(X,Y)*B,2*C*min(X,Y));
	ans+=min(2*C*(max(X,Y)-min(X,Y)),(max(X,Y)-min(X,Y))*D);
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
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 (a>b) { a=b; return 1; } return 0; }

using Lint=long long;

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

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

    int Q; cin>>Q;
    int ans=0;
    while(Q--){
        int x; cin>>x;
        bool found=false;
        for(int i=0;i<N;i++) if(a[i]==x) found=true;
        if(found) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

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

int d[101];

int main(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        d[i]=0;
    }
    for(int i=0;i<k;i++){
        int tmp;
        cin>>tmp;
        for(int m=0;m<tmp;m++){
            int atmp;
            cin>>atmp;
            d[atmp-1]++;
        }
    }
    int count=0;
    for(int i=0;i<n;i++){
        if(!d[i]){
            count++;
        }
    }
    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 3636
// Copyright [2020] <unknown>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

typedef long long LL;


const int N = 11;

int a[N];
int n;

vector<string> s;

void dfs(int u) {

    vector<int> em;
    for (int i=0; i<n; ++i) {
        if (a[i] == 0) {
            em.push_back(i);
        }   
    }

    // dbg(u, a[0], a[1], a[2], em.size());

    if (em.size() == 0) {

        static char tmp[N];
        for (int i=0; i<n; ++i) {
            // putchar(a[i] + 'a' - 1);
            tmp[i] = a[i] + 'a' - 1;
        }
        tmp[n] = 0;
        s.push_back(string(tmp));
        return;
    }

    int first = em[0];

    a[first] = u;
    if (em.size() == 1) {
        static char tmp[N];
        for (int i=0; i<n; ++i) {
            // putchar(a[i] + 'a' - 1);
            tmp[i] = a[i] + 'a' - 1;
        }
        tmp[n] = 0;
        s.push_back(string(tmp));
        a[first] = 0;
        return;
    }

    int m = em.size() - 1;
    for (int i=(1<<m)-1; i>=0; --i) {
        for (int j=0; j<m; ++j) {
            if ((i >> j) & 1) {
                a[em[m-j]] = u;
            }
        }
        // dbg(u, i);
        dfs(u+1);
        for (int j=0; j<m; ++j) {
            if ((i >> j) & 1) {
                a[em[m-j]] = 0;
            }
        }
    }


    a[first] = 0;
}

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

    cin >> n;
    dfs(1);
    sort(s.begin(), s.end());
    // cout << s[0] << endl;
    for (const auto &p : s)
        cout << p << endl;
    return 0;
}


Measured memory_bytes: 7796
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int x,a,b;
    cin>>x>>a>>b;
    cout<<(x-a)%b<<endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int nu1,nu2,nu3,nu4;
  nu1=n/1000;
  nu2=n/100-nu1*10;
  nu4=n%10;
  nu3=(n%100-nu4)/10;
  if((nu1 == nu2 && nu2 == nu3) || (nu2 == nu3 && nu3 == nu4)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3584
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		System.out.println(Math.min(a,b)+Math.min(c,d));
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <queue>
#include <cstring>
using namespace std;

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

bool f[50][50];
bool h[50][50][50][50];

class State
{
public:
	int lx,ly,rx,ry,c;
	State(int lx, int ly, int rx, int ry, int c)
	:lx(lx),ly(ly),rx(rx),ry(ry),c(c)
	{}
};
int main()
{
	int W,H;
	while(cin >> W >> H, (W||H))
	{
		memset(h,0,sizeof(h));

		int lx,ly,rx,ry;
		cin >> lx >> ly >> rx >> ry;

		lx--; ly--;
		rx--; ry--;

		for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
			cin >> f[j][i];

		queue<State> q;
		q.push(State(lx,ly,rx,ry,0));

		bool g=false;
		while(!q.empty())
		{
			State s = q.front(); q.pop();
			if(s.c >= 100) break;

			if(s.lx==s.rx&&s.ly==s.ry)
			{
				g=true;
				cout << s.c << endl;
				break;
			}

			for(int i=0; i<4; i++)
			{
				int tlx=s.lx+dx[i], tly=s.ly+dy[i];
				int trx=s.rx+dx[(i+2)%4], ttry=s.ry+dy[(i+2)%4];

				if(tlx<0||tlx>=W||tly<0||tly>=H||f[tlx][tly])
				{
					tlx = s.lx;
					tly = s.ly;
				}
				if(trx<0||trx>=W||ttry<0||ttry>=H||f[trx][ttry])
				{
					trx = s.rx;
					ttry = s.ry;
				}

				if(h[tlx][tly][trx][ttry]) continue;
				h[tlx][tly][trx][ttry]=1;
				
				q.push(State(tlx,tly,trx,ttry,s.c+1));

			}
		}

		if(!g) cout << "NA" << endl;

	}
}

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

using namespace std;

#define ll long long
#define ar array


int n, k;
int a[1000];


void solve(){
    
    cin >> n >> k;

    for (int i = 0; i < n; i++)
    {
        cin >>a[i];
    }
    
    sort(a,a+n);

    int ans = 0;
    for (int i = 0; i < k; i++)
    {
        ans += a[i];
    }
    
    cout << ans << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

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

using namespace std;

typedef long long ll;

int N;

struct child {
    ll aval, i;
};

struct child arr[2001];

bool comp(struct child a, struct child b) {
    if(a.aval == b.aval) return a.i < b.i;
    return a.aval > b.aval;
}

ll dp[2001][2001];

ll solve(int l, int r) {
    if(dp[l][r] != -1) {
        return dp[l][r];
    }
    int cur = l + r;
    if(cur >= N) return 0;
    ll left = arr[cur].aval * (arr[cur].i - l) + solve(l + 1, r);
    ll right = arr[cur].aval * (N - 1 - r - arr[cur].i) + solve(l, r + 1);
    return dp[l][r] = max(left, right);
}

int main() {
    cin >> N;
    memset(dp, -1, sizeof(dp));
    for(int i = 0; i < N; ++i) {
        cin >> arr[i].aval;
        arr[i].i = i;
    }
    sort(arr, arr + N, comp);
    cout << solve(0, 0) << "\n";
    return 0;
}


Measured memory_bytes: 35020
#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 N;
std::string A, B, C;
int cnt[26];

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

  std::cin >> N >> A >> B >> C;

  int res = 0;

  for(int i=0;i<N;++i){
      memset(cnt, 0, sizeof(cnt));

      cnt[A[i] - 'a'] += 1;
      cnt[B[i] - 'a'] += 1;
      cnt[C[i] - 'a'] += 1;

      int mx_i = 0;

      for(int j=1;j<26;++j){
          if(cnt[j] > cnt[mx_i]){
              mx_i = j;
          }
      }

      res += 3 - cnt[mx_i];
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[8] = {-1,0,1,0,-1,1,1,-1};
int dx[8] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;

template <int mod>
struct ModInt
{
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p)
    {
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator-=(const ModInt &p)
    {
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }
    ModInt &operator*=(const ModInt &p)
    {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p)
    {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const
    {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0)
        {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e)
    {
        long long a = 1, p = x;
        while (e > 0)
        {
            if (e % 2 == 0)
            {
                p = (p * p) % mod;
                e /= 2;
            }
            else
            {
                a = (a * p) % mod;
                e--;
            }
        }
        return ModInt(a);
    }

    friend ostream &operator<<(ostream &os, const ModInt<mod> &p)
    {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a)
    {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

using modint = ModInt<mod>;
modint f[d5];

void makef()
{
    f[0] = 1;
    for (int i = 1; i < d5; i++)
        f[i] = f[i - 1] * i;
}

modint nCr(int n, int r)
{
    if (n < r || r < 0)
        return 0;
    return f[n] / (f[r] * f[n - r]);
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;
        return 0;
    }
    makef();
    modint res=1;
    if(n!=m){
        res*=f[n];
        res*=f[m];
    }else{
        res*=f[n];
        res*=f[n];
        res*=2;
    }
    cout<<res<<endl;

}


Measured memory_bytes: 1024
#include<cstdio>
struct node {
	double p,max;
} a[220000];
int n,k;
int main() {
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;++i) {
		scanf("%lf",&a[i].max);
		a[i].p=0;
		for (int j=1;j<=a[i].max;++j) a[i].p+=j;
		a[i].p/=a[i].max;
	}
	int l=2,r=k+1;
	double ans=0;
	for (int i=1;i<=k;++i) ans+=a[i].p;
	double max=ans;
	while (r<=n) {
		ans-=a[l-1].p;
		ans+=a[r].p;
		if (max<ans) max=ans;
		++l;++r;
	}
	printf("%.12lf",max);
	return 0;
} 

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int K,N;
	scanf("%d %d", &N,&K);

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

	int ans = 1+(N-K)/(K-1);
	int tmp = (N-K)%(K-1);
	if(tmp>0) ans++;

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	x := sint64()
	printf("%d\n", sol(x))
}

func sol(x int64) int64 {
	return 360 / gcd(360, x)
}


Measured memory_bytes: 1844
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int main(){
  int N,l;
  cin>>N;
  vector<int> v;
  for(int i=0;i<N*2;i++){
    cin>>l;
    v.push_back(l);
  }
  sort(v.begin(),v.end());
  int value=0;
  for(int j=0;j<N*2;j=j+2){
    value+=v[j];
  }
  cout<<value<<endl;
  return 0;
}


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

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359;
#define inf (1 << 21);
#define mod 1000000007;

int main() {
    double N, K; cin >> N >> K;
    double P = 0;
    for (int i = 1; i <= N; i++) {
        if (i < K) {
            double m = log(K / i) / log(2);
            m = ceil(m);
            P += pow(0.5, m) / N;
        }
        else {
            P += 1 / N;
        }
    }
    cout << fixed << setprecision(10);
    cout << P << endl;
    return 0;
}

Measured memory_bytes: 640