akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Long = {
    val N, K = sc.nextInt
    val A = Array.fill(N)(sc.nextInt - 1)
    val Ans = A.map(X => X == -1)
    val leaf = Array.fill(N)(true)
    for (i <- 0 until N) {
      if (A(i) != -1) (leaf(A(i)) = false)
    }
    val memo = Array.fill(N)(K * 2)
    var i = 0
    while (i < N) {
      if (leaf(i)) {
        var now = i
        var idx = 0
        while (now != -1 && idx < K) {
          Ans(now) = true
          now = A(now)
          idx += 1
          if (now != -1) {
            if (memo(now) <= idx) {
              now = -1
            } else {
              memo(now) = idx
            }
          }
        }
      }
      i += 1
    }

    i = 0
    var ans = 0
    while (i < N) {
      if (Ans(i)) {
        ans += 1
      }
      i += 1
    }
    ans
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    println(solve(sc))
  }
}

Measured memory_bytes: 134168
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vpii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
   
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int l,r,d;cin>>l>>r>>d;
        int ans=0;
        for(int i=l;i<=r;i++){
            if(i%d==0){
                ans++;
            }
        }
        cout<<ans;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>
#include <cstdint>
#include <set>
#include <deque>

using namespace std;
using ull = unsigned long long;
using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

#define EPS (1e-7)
#define ALL(x) begin(x), end(x)

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

	struct Restran{
		string city;
		ll score;
		ll page;
	};

	vector<Restran> Rs(N);

	for (size_t i = 0; i < N; i++) {
		cin >> Rs[i].city >> Rs[i].score;
		Rs[i].page = i + 1;
	}

	sort(ALL(Rs), [](auto x, auto y) {
		if (x.city == y.city) {
			return x.score > y.score;
		}
		return x.city < y.city;
	});

	for (size_t i = 0; i < N; i++) {
		cout << Rs[i].page << endl;
	}


	return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

n, m = map(int, input().split())

w = [[] for _ in range(10**5)]

for i in range(n):
  a, b = map(int, input().split())
  w[a-1].append(b)

money = 0
l = []
for i in range(m):
  for item in w[i]:
    heappush(l, item * (-1))
  if len(l) == 0:
    continue

  money += heappop(l) * (-1)

print(money)

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

typedef long long ll;
using namespace std;

int n;
vector<int> g[300];
int flag[300];

int dfs(int a){
	if(flag[a]) return 1;
	flag[a] = 1;
	for (int i = 0;i < g[a].size();i++){
		if(dfs(g[a][i])){flag[a] = 0; return 1;}
	}
	flag[a] = 0;
	return 0;
}

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

	cin >> n;
	for (int i = 0;i < n;i++){
		int a,b; string s;
		cin >> a >> s >> b;
		if(s == "lock"){
			g[a].push_back(b+100);
		}else{
			g[b+100].push_back(a);
		}
	}

	for (int i = 0;i < 300;i++){
		if(dfs(i)){
			cout << 1 << endl;
			return 0;	
		}
		memset(flag,0,sizeof(flag));
	}

	cout << 0 << endl;

	return 0;

}


Measured memory_bytes: 3264
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        int K = sc.nextInt();
        String slist[] = s.split("");
        String check = slist[K-1];
        //System.out.println(check);
        for(int i = 0; i < s.length(); i++){
            if(!(slist[i].equals(check))){
                slist[i] = "*";
            }
        }
        for(int i = 0; i < s.length(); i++){
            System.out.print(slist[i]);
        }
    }
}


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

typedef long lint;
typedef long long llint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) { return arg1.first > arg2.first; }
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; } }

int main(void) {
    llint n, m;
    cin >> n >> m;

    vector<llint> a(n);
    vector<llint> sum(n+1);
    for(llint in=0;in<n;in++) {
        cin >> a.at(in);
        sum.at(in+1) = sum.at(in) + a.at(in);
    }
    
    map<llint, llint> modmap;
    for(int in=0;in<n+1;in++) {
        modmap[sum.at(in)%m]++;
    }
    
    llint ans=0;
    for(auto imap:modmap) {
        llint p = imap.second;
        ans += p*(p-1)/2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

const long MOD = 1e9 + 7;
int main()
{
  long h,w;
  cin >>h >>w;
  // vector <vector<char>> v( h,vector<char> (w,0));

  string mp[h + 2];
  for (int i = 1; i < h+1; ++i)//hは行wは列
  {
    string s;
    cin >> s;
    mp[i]= "." + s +"."; 
  }

  for (int i = 0; i < w+2; ++i){
    mp[0] +=".";
    mp[h+1] +=".";
  }

  bool isAns =true;
  for (int i = 1; i < h+1; ++i)
  {
    for (int j = 1; j < w+1; ++j)
    {
      if ( mp[i][j]=='#' && mp[i-1][j]=='.' && mp[i+1][j]=='.' && mp[i][j-1]=='.' && mp[i][j+1]=='.'){
        isAns=false;
      }
    }
  }

   cout << (isAns?"Yes":"No");

  return 0;
}






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d;
int main()
{
    cin>>a>>b>>c;
    if(b>=a)
    {
        cout<<1<<endl;
        exit(0);
    }
    if(c>=b)
    {
        cout<<-1<<endl;
        return 0;
    }
    if((a-b)%(b-c)>=1)d=1;
    cout<<((a-b)/(b-c)+d)*2+1<<endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#include <random>

using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;

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

	reverse(h.begin(), h.end());
	int ans = 0;
	int preval = 0;
	REP(i, 1, n) {
		if (h[i - 1] <= h[i]) ++preval;
		else preval = 0;
		ans = max(ans, preval);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

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

int main(void){
	long long int n,sum=0;
	cin>>n;
	rep(i,n){
		int num;
		cin>>num;
		sum+=num;
	}	
	cout<<sum/n<<endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define mp make_pair
using namespace std;
int n,x;
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>x;
		if(x%2==0)
		{
			if(x%3!=0&&x%5!=0)
			{
				cout<<"DENIED\n";
				return 0;
			}
		}
	}
	cout<<"APPROVED\n";
	return 0;
}

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

alph = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
ans = ""
for i in range(len(s)):
    idx = (alph.index(s[i]) + n)
    if idx > 25:
        idx -= 26
    ans = ans + alph[idx]
print(ans)

Measured memory_bytes: 3064
H,W,D=gets.split.map &:to_i
S="RYGB".freeze
puts (
  if D % 2 == 0
    H.times.map{|i|W.times.map{|j|
      S[((i+j)/D&1)<<1|(i-j)/D&1]
    }.join}
  else
    H.times.map{|i|W.times.map{|j|
      S[(i^j)&1]
    }.join}
  end
).join ?\n


Measured memory_bytes: 2940
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
string s,t;
int po[100],sum,u=-1,book,j;
int ans;
bool check(int x)
{
	for(int i=x;i<=x+t.size()-1;i++)
	{
		if(s[i]!='?'&&s[i]!=t[i-x])  return false;
	}
	return true;
}
int main()
{
	cin>>s>>t;
	for(int i=0;i<s.size();i++)
	{
		if(check(i)==1)   u=i;
	} 
	if(u==-1)
	{
		cout<<"UNRESTORABLE";
		return 0;
	}
	for(int i=0;i<s.size();i++)
	{
		if(i==u)
		{
			for(j=i;j<=i+t.size()-1;j++)
			{
				cout<<t[j-i];
			}
			i=j-1;
		}
		else if(s[i]=='?')   cout<<"a";
		else                 cout<<s[i];
	}
	return 0;
}

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

int main()
{
	long long n, k;
	cin >> n >> k;
	vector<int> av(n);
	for (auto& i : av) {
		cin >> i;
	}
	vector<int> fv(n);
	for (auto& i : fv) {
		cin >> i;
	}
	sort(av.begin(), av.end());
	sort(fv.rbegin(), fv.rend());

	long long l = -1;
	long long r = LLONG_MAX-2;
	while (r - l != 1) {
		long long sum = 0;
		long long c = (r + l) / 2;
		for (int i = 0; i < n; ++i) {
			sum += max(0LL, av[i] - c / fv[i]);
		}
		if (sum <= k) {
			r = c;
		}
		else {
			l = c;
		}
	}
	cout << r << endl;

	return 0;
}

Measured memory_bytes: 1792
//Solution for aoj 0561:Books
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int n, k, x, y, i, j, save2, sum, roop[11], save3;
int books[11][2001], dp[11][2001], save, books2[11][2001];
int main(){
	cin >> n >> k;
	for (int i = 1; i <= 10; i++)
		roop[i] = 1;
	for (i = 0; i < n; i++){
		cin >> x >> y;
		books[y][roop[y]++] = x;
	}
	for (i = 1; i <= 10; i++){
		sort(books[i], books[i] + roop[i], greater<int>());
	}
	dp[1][1] = books[1][0];
	for (j = 2; j <= roop[1]; j++){
		dp[1][j] = dp[1][j - 1] + books[1][j - 1];
		if (books[1][j])
			dp[1][j] += j * 2 - 2;
	}
	for (i = 1; i <= 10; i++){
		books2[i][1] = books[i][0];
		for (j = 2; j < roop[i]; j++){
			books2[i][j] = books2[i][j - 1] + books[i][j - 1];
			if (books[i][j - 1])
				books2[i][j] += j * 2 - 2;
		}
	}
	for (i = 2; i <= 10; i++){
		save = 1;
		for (j = 1; j <= k; j++){
			x = j;
			y = 0;
			for (int l = 0; l < j; l++){
				dp[i][j] = max(dp[i - 1][x] + books2[i][y], dp[i][j]);
				x--;
				y++;
				dp[i][j] = max(dp[i - 1][x] + books2[i][y], dp[i][j]);
			}
		}
	}
	cout << dp[10][k] << endl;
	return 0;
}

Measured memory_bytes: 1352
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include<cmath>
#include<climits>
#include<iomanip>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
const long long INF = 1LL << 60;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

//約数求める //約数
void divisor(ll n,vector<ll> &ret) {
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			ret.push_back(i);
			if (i * i != n) ret.push_back(n / i);
		}
	}
	sort(ret.begin(), ret.end());
	
}
//階乗
long long factorial(long long n, long long mod) {
	long long ret = 1;
	for (long long i = 1; i <= n; i++) {
		ret = (ret * i) % mod;
	}
	return ret;
}
//モジュラ逆数
long long inv_mod(long long n, long long mod) {
	long long a = n % mod, b = mod - 2, ret = 1;
	while (b > 0) {
		if (b & 1) ret = (ret * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ret;
}

long long nPr(long long n, long long r, long long mod) {
	long long ret = 1;
	for (long long i = n; i >= n - r + 1; i--) {
		ret = ret * (i % mod) % mod;
	}
	return ret;
}

long long nCr(long long n, long long r, long long mod) {
	return nPr(n, r, mod) * inv_mod(factorial(r, mod), mod) % mod;
}

ll gcd(ll m, ll n){
	if (n == 0)return m;
	return gcd(n, m%n);
}//gcd



int main() {

	ll n;
	cin >> n ;
	vector<ll> a(n);
	rep(i, n)cin >> a[i];
	sort(a.begin(), a.end());
	ll sum = a[0];
	ll num = 0;
	for (int i = 1; i < n; i++) {
		if (sum * 2 < a[i]) {
			num = i;
		}
		sum += a[i];
	}
	cout << n - num;
	return 0;
}


Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int[] p = {11, 31, 41, 61, 71, 101, 131, 151, 181, 191, 211, 241, 251, 271, 281, 311, 331, 401, 421, 431, 461, 491, 521, 541, 571, 601, 631, 641, 661, 691, 701, 751, 761, 811, 821, 881, 911, 941, 971, 991, 1021, 1031, 1051, 1061, 1091, 1151, 1171, 1181, 1201, 1231, 1291, 1301, 1321, 1361, 1381};
        int N = in.i();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < N; i++) {
            sb.append(p[i]).append(' ');
        }
        System.out.println(sb);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32032
import Foundation

func readInt() -> Int {
    return Int(readLine()!)!
}

func readString() -> String {
    return readLine()!
}

func readLines(times: Int) -> [String] {
    var array = [String]()
    for _ in 0..<times {
        array.append(readLine()!)
    }
    return array
}

func readSeparatedStrings() -> [String] {
    return readLine()!.split(separator: " ").map({String($0)})
}

func readStringToStrings() -> [String] {
    return readLine()!.map({String($0)})
}

func readSeparatedInts() -> [Int] {
    return readLine()!.split(separator: " ").map({Int($0)!})
}
func readSeparatedDouble() -> [Double] {
    return readLine()!.split(separator: " ").map({Double($0)!})
}

let s = readStringToStrings()
let t = readStringToStrings()

var count: Int = 0
for i in 0..<s.count {
    if !(s[i] == t[i]) {
        count += 1
    }
}

print(count)


Measured memory_bytes: 19484
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,i;
    cin>>t;
     int A[t];
     for(i=0;i<t;i++)
     {
         cin>>A[i];
         if(A[i]%2==0)
        {
            if(A[i]%3!=0 && A[i]%5!=0)
            {
                 cout<<"DENIED"<<endl;
                 return 0;
            }

        }
     }
    cout<<"APPROVED"<<endl;
    return 0;
}


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

typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vint;
typedef vector<uint> vuint;
typedef vector<ull> vull;
typedef vector<ll> vll;

#define init(type,var) type var;cin>>var;
#define vinit(type,var,n) vector<type> var((uint)n);loop(i,0,n)cin>>var[i];
#define linit(type,var,n) list<type> var;loop(i,0,n){type _v;cin>>_v;var.push_back(_v);}
#define range(container) container.begin(),container.end()
#define loop(i,first,end) for(ull i=(first);i<(end);i++)
#define outl(out) cout<<(out)<<endl;

const ull INF = (ull)(-1LL);

typedef ull dint;

typedef vector<dint> vdint;

int main(void){
	init(string, s);
	init(dint, k);

	ull n = s.size();
	ull count = 0;

	if (k >= 2){
		ull cl, co, ce, cr;
		cl = co = ce = cr = 0;

		string _s = s + s + s + s;
		if (k % 2)_s += s;

		loop(i, 0, _s.size() - 1)if (_s[i] == _s[i + 1])_s[i + 1] = '*';

		loop(i, 0, n)if (_s[i] == '*')cl++;
		loop(i, 0, n)if (_s[n + i] == '*')ce++;
		loop(i, 0, n)if (_s[2 * n + i] == '*')co++;
		loop(i, 0, n)if (_s[_s.size() - 1 - i] == '*')cr++;

		count = cl + (ce + co) * ((k - 2) / 2) + cr;
		if (k % 2)count += ce;
	}
	else{
		loop(i, 0, n-1){
			if (s[i] == s[i + 1]){
				count++;
				s[i + 1] = '*';
			}
		}
	}

	outl(count);

	return 0;
}

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

using namespace std;

int main(){
    long long int N,M,ans;
    cin >> N >> M;
    for(int i=M/N;1<=i;i--){
        if(M%i==0){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

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

int main(){
	string s;
	cin >> s;
	
	int c = 0;
	
	if(s[0]=='1') ++c;
	if(s[1]=='1') ++c;
	if(s[2]=='1') ++c;
	
	cout << c << endl;
	
	return 0;
}
		
		

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

/* define*/
#define Yes(X) puts ( X ? "Yes" : "No")
#define YES(X) puts ( X ? "YES" : "NO")
#define FOR(i, a, b) for ( i = a, i < b ; i++)
#define REP(i, n) for ( i = 0; i < n ; i++)
#define DER(i, n) for ( i = 0; n ; i--)
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max3(a, b, c) ((max((a), (b)) > (c)) ? max((a), (b)) : (c))
#define min3(a, b, c) ((min((a), (b)) < (c)) ? min((a), (b)) : (c))

/* const */
const int MOD = 1e9 + 7;

/* alias */
typedef long long ll;

/* function */
int cmp(const int *a, const int *b) {
	return *a - *b;
}
int cmp2(const int *a, const int *b) {
	return *b - *a;
}

//* main */
int i, j, k;

int main() {
	int n, c = 0, a[100000];
	scanf("%d", &n);
	REP(i, n)scanf("%d", &a[i]);
	REP(i, n)if (i + 1 == a[a[i] - 1 ])c++;
	printf("%d", c / 2);
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);


int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int x=0;
  int ans = 0;
  rep(i,n){
    if(s[i]=='I') ++x;
    else --x;
    ans=max(ans,x);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
ab_list = [[int(x) for x in input().split()] for _ in range(N)]
sorted_ab_list = sorted(ab_list, key=lambda ab: ab[1])
t = 0
for a, b in sorted_ab_list:
    t += a
    if (t <= b):
        continue
    else:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 91608
#include <bits/stdc++.h>
using namespace std;
int a,b,c,len;
int main(){
    cin>>a>>b;
    c=b;
    while(c>0){
        c/=10;
        len++;
    }
    a=a*pow(10,len)+b;
    if(sqrt(a)==floor(sqrt(a)))
        cout<<"Yes";
    else
        cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using ll = long long int;

int main(){
    int N; cin >> N;
    ll a[N+1];
    vi res(N+1, 0);
    for(int i=1; i<N+1; i++){
        cin >> a[i];
    }
    for(int i=N; i>0; i--){
        if(i > N/2){
            if(a[i] == 1){
                res[i] = 1;
            }   
            else{continue;}
        }
        else{
            int k = i+i;
            int d = 0;
            while(k<=N){
                if(res[k] == 1){
                    d++;
                }
                k += i;
            }
            int f = d%2;
            if(f == 1){
                if(a[i] == 1){a[i] = 0;}
                else{a[i] = 1;}
            }
            res[i] = a[i];
        }
    }
    vi ans(0);
    ll sum = 0;
    for(int i=1; i<N+1; i++){
        if(res[i] == 1){
            ans.push_back(i);
            sum++;
        }
    }
    cout << sum << endl;
    for(auto x: ans){
        cout << x << endl;
    }
}

Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n;
int A[3010];
int cum[3010];
int dp[3010][3010];

int f(int p1, int p2){
     if(p1==p2) return A[p1];
    int&ans=dp[p1][p2];
    if(ans!=-1) return ans;
    
     ans=0;
     int total;
     if(p1==0) total=cum[p2];
     else total=cum[p2]-cum[p1-1];
     ans =max(ans, total-f(p1+1, p2));
     ans =max(ans, total-f(p1, p2-1));
     return ans;
}

int32_t main(){
     memset(dp, -1, sizeof(dp));
     cin>>n;
     for(int i=0;i<n;i++)cin>>A[i];
     cum[0]=A[0];
     for(int i=1;i<n;i++)cum[i]=cum[i-1]+A[i];
    
     int a=f(0, n-1);
     cout<<a-(cum[n-1]-a);
}

Measured memory_bytes: 71168
from numba import jit, i8, void


def g(n):
    return n * (n + 1) // 2


@jit(i8(i8))
def solve(n):
    ans = 0
    for i in range(1, n + 1):
        ans += i * g(n // i)
    return ans

def main():
    print(solve(int(input())))


main()


Measured memory_bytes: 111372
array = [
  1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
  1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
]
n = gets.to_i
puts array[n-1]

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int angle;
	cin>>angle;
	int lcm=(angle*360)/__gcd(angle,360);
	cout<<lcm/angle;
}



Measured memory_bytes: 3648
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static PriorityQueue<Edge> pq=new PriorityQueue<>();
	static int V, E;
	static int[] par;
	
	static class Edge implements Comparable<Edge>{
		int u, v, cost;
		Edge(int u, int v, int cost){
			this.u=u;
			this.v=v;
			this.cost=cost;
		}
		public int compareTo(Edge e) {
			return this.cost-e.cost;
		}
	}
	
	static void init(int N) {//初期化
		for(int i=0; i<N; i++) {
			par[i]=i;
		}
	}
	
	static int root(int x) {//親を求める
		if(par[x]==x) {
			return x;
		}
		return par[x]=root(par[x]);
	}
	
	static boolean same(int x, int y) {//判定(同グループかどうか)
		return (root(x)==root(y));
	}
	
	static void unite(int x, int y) {//まとめる
		par[root(x)]=root(y);
	}
	
	static int kraskal() {
		init(V);
		int res=0;
		for(int i=0; i<E; i++) {
			Edge e=pq.poll();
			if(!same(e.u, e.v)) {
				unite(e.u, e.v);
				res+=e.cost;
			}
		}
		return res;
	}
	
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			V=sc.nextInt();
			E=sc.nextInt();
			par=new int[V];
			for(int i=0; i<E; i++) {
				int s=sc.nextInt();
				int t=sc.nextInt();
				int w=sc.nextInt();
				pq.add(new Edge(s, t, w));
			}
			System.out.println(kraskal());
			
		}
	}
}


Measured memory_bytes: 105892
#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int ans=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&x),ans+=x;
	ans=n-ans;
	(ans<0)?printf("-1"):printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N,x;
	cin>>N>>x;
	int sum=0;
	int a[N];
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
	sort(a,a+N);
	for(int l=0;l<N;l++){
		sum+=a[l];
		if(sum>x){
			cout<<l<<endl;
			return 0;
		}
	}
	if(sum==x){
		cout<<N<<endl;
	}
	else{
		cout<<N-1<<endl;
	}
}


Measured memory_bytes: 256
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = 10 ** 5 + 10 ** 5
for x, y, c in xyc:
  if a[x - 1] + b[y - 1] - c < ans:
    ans = a[x - 1] + b[y - 1] - c
m_price = min(a) + min(b)

print(ans if ans < m_price else m_price)

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

using namespace std;

const int M = 1e3 + 5; // number of nodes
const int N = M * M;
int vis[N] , low[N] , dfsTime[N] , comp_id[N] , Time;
vector<int> adj[N];
stack<int> st;
vector<vector<int> > comps;

int dfs(int node) { // add par if undirected
    if(vis[node])
        return vis[node] == 1 ? low[node] : 1e9;

    dfsTime[node] = low[node] = Time++;
    vis[node] = 1;
    st.push(node);

    for (int child : adj[node]) // in case of undirected continue if par
        low[node] = min(low[node] , dfs(child));

    if(low[node] == dfsTime[node]) {
        comps.push_back(vector<int>());
        do {
            vis[st.top()] = 2;
            comp_id[st.top()] = comps.size() - 1;
            comps.back().push_back(st.top());
            st.pop();
        } while(comps.back().back() != node);
    }

    return low[node];
}

bool tarjan(int n) {
    for (int i = 1 ;i <= n ;i++) // one based
        if(!vis[i])
            dfs(i);

    for (int i = 0 ;i < comps.size() ;i++)
        if (comps[i].size() > 1)
            return 0;

    return 1;
}


int id[M][M] , in[N];
int memo[N];
int solve (int node) {
    int &ret = memo[node];
    if (~ret)
        return ret;

    ret = 0;
    for (int c : adj[node])
        ret = max(ret , solve(c));

    return ret = ret + 1;
}

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

    int n;
    cin >> n;

    int nxt = 0;
    for (int i = 1 ;i <= n ;i++)
        for (int j = i + 1 ;j <= n ;j++)
            id[i][j] = nxt++;

    for (int i = 1 ;i <= n ;i++) {
        int prev = -1;
        for (int j = 0 ;j < n - 1 ;j++) {
            int a = i , b;
            cin >> b;
            if (a > b) swap(a , b);
            if (~prev) {
                adj[prev].push_back(id[a][b]);
                in[id[a][b]]++;
            }
            prev = id[a][b];
        }
    }

    if (!tarjan(n)) {
        cout << -1;
        return 0;
    }

    memset(memo , -1 , sizeof memo);
    int mx = 0;
    for (int i = 0 ;i < nxt ;i++)
        if (!in[i])
            mx = max(mx , solve(i));

    cout << mx;
}


Measured memory_bytes: 87616
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		String s = sc.next();
		
		System.out.println(solve(s));
	}
	static String solve(String s){
		String[][] str = {{"SSS", "WSW", "SWW", "WWS"}, {"SSW", "WSS", "SWS", "WWW"}};
		int idx = -1;
		if(s.charAt(0)=='o')
			idx = 0;
		else
			idx = 1;
		
		for(int i=0;i<4;i++){
			StringBuilder ans = new StringBuilder(str[idx][i]);
			for(int j=1;j<s.length();j++){
				ans.append(addStr(s.charAt(j), ans.substring(ans.length()-2)));
			}
			
			if(isCorrect(ans)){
				return ans.substring(1, ans.length()-1);
			}
		}
		return "-1";
	}
	static String addStr(char c, String str){
		if(c=='o'){
			if(str.equals("SS"))
				return "S";
			if(str.equals("WS"))
				return "W";
			if(str.equals("SW"))
				return "W";
			if(str.equals("WW"))
				return "S";
		}
		else{
			if(str.equals("SS"))
				return "W";
			if(str.equals("WS"))
				return "S";
			if(str.equals("SW"))
				return "S";
			if(str.equals("WW"))
				return "W";
		}
		return "";
	}
	static boolean isCorrect(StringBuilder s){
		int len = s.length();
		if(s.charAt(0)==s.charAt(len-2) && s.charAt(1)==s.charAt(len-1))
			return true;
		else
			return false;
	}
}


Measured memory_bytes: 42448
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[200010],finv[200010],inv[200010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,200010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n,k;cin>>n>>k;
    combinit();
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll ma=0;
    ll mi=0;
    sort(all(a));
    REP(i,k-1,n){
        ll l=comb(i,k-1)*a[i]%inf;
        ma=(ma+l)%inf;
    }
    reverse(all(a));
    REP(i,k-1,n){
        ll l=comb(i,k-1)*a[i]%inf;
        mi=(mi+l)%inf;
    }
    ll ans=(ma-mi)%inf;
    if(ans<0)ans+=inf;
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var NM = Sarray();
            var N = NM[0];
            var M = NM[1];
            var left = 0;
            var right = N;
            for(var i=0;i<M;i++)
            {
                var tmp = Sarray();
                if (left < tmp[0]) left = tmp[0];
                if (tmp[1] < right) right = tmp[1];
            }
            var ans = right + 1 - left;
            WriteLine(ans<0?0:ans);
        }

    }
}


Measured memory_bytes: 17484
#include<iostream>
using namespace std;
int main(){
	int n,a,b,s=0,g=0;
	cin>>n>>a>>b;
	while(1){
		s+=n;
		if(s%a==b){
			cout<<"YES";
			return 0;
		}
		g++;
		if(g>100) break;
	}
	cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.next();
    let mut xs = sc.vec::<usize>(n);

    let mut ps = vec![false; 2020];
    for &x in &xs {
        ps[x] = true;
    }

    let m: usize = sc.next();
    for _ in 0..m {
        let i = sc.next::<usize>() - 1;
        let x = xs[i];

        if x < 2019 && !ps[x + 1] {
            xs[i] += 1;
            ps[x] = false;
            ps[x + 1] = true;
        }
    }

    for x in xs {
        println!("{}", x);
    }
}

/* ========== Scanner ========== */

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn next<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.read() {
            s
        } else {
            writeln!(stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }

    fn char(&mut self) -> char {
        self.next::<String>().chars().next().unwrap()
    }
}



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

long long gcd(long long a,long long b){
    if(b==0){
        return a;
    }
    long long tmp=b;
    b=a%b;
    a=tmp;
    return gcd(a,b);
}

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

int main(void){
    int n;
    cin>>n;
    vector<long long> num(n);
    for(int i=0;i<n;i++){
        cin>>num[i];
    }
    sort(num.begin(),num.end());
    long long ans=1;
    for(int i=0;i<n;i++){
        ans=lcm(ans,num[i]);
    }
    cout<<ans<<endl;
}


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

using namespace std;

int main() {

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

    int H[N + 1];
    for(int i = 1; i <= N; i++) {
        cin >> H[i];
    }

    int A[M + 1], B[M + 1];
    for(int i = 1; i <= M; i++) {
        cin >> A[i] >> B[i];
    }

    set<int> members;

    for(int i = 1; i <= M; i++) {
        if(H[A[i]] <= H[B[i]]) {
            members.insert(A[i]);
        }

        if(H[B[i]] <= H[A[i]]) {
            members.insert(B[i]);
        }
    }

    int member = members.size();

    cout << N - member << endl;


    return 0;
}

Measured memory_bytes: 7440
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll n; cin >> n;
  ll ans = 1;
  ll num = 1;
  while(n>1){
    n /= 2;
    num *= 2;
    ans += num;
  }

  cout << ans << endl;

  

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String num = sc.nextLine();
      	String[] numSpl = num.split(" ");
      	int n = Integer.parseInt(numSpl[0]);
      	int k = Integer.parseInt(numSpl[1]);
		String s = sc.nextLine();
		

		String[] spl = s.split("");
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < n;i++){
			if(i == k-1){
				sb.append(spl[i].toLowerCase());
			}else{
				sb.append(spl[i]);
			}
		}
		System.out.println(sb);
		sc.close();
	}
}

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

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

		if (n == 0) {
			break;
		}

		vector<vector<bool>> days(31, vector<bool>(n + 1, false));
		vector<vector<vector<bool>>> dp(31, vector<vector<bool>>(n + 1, vector<bool>(n + 1, false)));

		for (int i = 1; i <= n; i++) {
			dp[0][i][i] = true;
		}

		for (int i = 1; i <= n; i++) {
			int count;
			cin >> count;

			for (int j = 1; j <= count; j++) {
				int temp;
				cin >> temp;

				days[temp][i] = true;
			}
		}

		for (int day = 1; day <= 30; day++) {
			for (int i = 1; i <= n; i++) {
				for (int j = 1; j <= n; j++) {
					//???????????????or??¨??\??????????????????
					if ((days[day][i] == true && days[day][j] == true) || i == j) {
						for (int k = 1; k <= n; k++) {
							dp[day][i][k] = (dp[day][i][k] | dp[day - 1][i][k] | dp[day - 1][j][k]);
							dp[day][j][k] = (dp[day][j][k] | dp[day - 1][i][k] | dp[day - 1][j][k]);
						}
					}
				}
			}

			for (int i = 1; i <= n; i++) {
				bool flag = true;

				for (int j = 1; j <= n; j++) {
					if (dp[day][i][j] == false) {
						flag = false;
						break;
					}
				}

				if (flag == true) {
					cout << day << endl;
					goto End;
				}
			}
		}

		cout << -1 << endl;

	End:
		;
	}

	return 0;
}

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

int		main(void){
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	int		sum = 0;
	int i = 0;
	while (i < n){
		cin >> a[i];
		sum += a[i++];
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	i = 0;
	while (i < m){
		if (4 * m * a[i] < sum){
			cout << "No\n";
			return 0;
		}
		i++;
	}
	cout << "Yes\n";
}


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

int in(){int x;cin>>x;return x;}

int main(){
	int N; cin>>N;
	int ans = 0, ix = 1;
	for(int i=0; i<N; ++i) if(ix != in()) ans++; else ix++;
	cout<< (ans<N? ans:-1) <<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>
#include<bitset>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



/******************************************************************************************/


const int IINF = 1e9 + 7;
const ll LINF = 1e18 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


//約数の列挙
template<typename T>
vector<T> divisor(T n) {
	vector<T> res;
	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}


//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

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

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	return x * y / tmp;
}

//素数判定
bool is_prime(ll n) {
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			return false;
		}
	}
	return n != 1;//1の場合は除外
}


ll dp[1 << 14];

int main() {

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

	int N, M;
	cin >> N >> M;
	vector<int> a(M), b(M), c(M, 0);
	

	for (int i = 0; i < M; i++)
	{
		cin >> a[i] >> b[i];

		int cnt = 0;
		for (int j = 0; j < b[i]; j++)
		{
			int t;
			cin >> t;
			cnt += (1 << (t-1));
		}
		c[i] = cnt;
	}
	for (int i = 0; i < 1<<14-1; i++)
	{
		dp[i] = LINF;
	}

	dp[0] = 0;

	//cout << "a" << endl;

	for (int i = 0; i < (1 << N); i++)
	{
		//cout << "i= " << i << endl;
		for (int j = 0; j < M; j++)
		{
			bool can_use = false;

			for (int mask = 13; mask >= 0;mask--) {

				if (!((i >> mask) & 1)) {
					//bitが立っていない（まだ使っていない）
					can_use = true;
					break;
				}
			}

			if (can_use) {
				//j番目を使う
				//cout << "use= " << j << endl;
				
				dp[(i | c[j])] = min(dp[(i | c[j])], dp[i] + a[j]);
				//cout << "a" << endl;
				//cout << "after= " << dp[(i | c[j])] << " " << (i | c[j]) << " dp[i]= " << dp[i] << " a[i]= " << a[j] << " c[i]= " << c[i] << endl;
			}
		}
	}

	//cout << "b" << endl;
	 
	//cout << "abnss= " << (1 << N) - 1 << " kk " << dp[(1<<N)-1] << endl;
	if (dp[(1 << N)-1] == LINF) {
		cout << "-1" << endl;
	}
	else
	{
		cout << dp[(1 << N) - 1] << endl;
	}

}



Measured memory_bytes: 384
n = int(input())
n1 = n//100
n2 = n//10 - n1*10
n3 = n - n1*100 -n2*10

if n1 == 1:
    m1 = 9
if n1 == 9:
    m1 = 1
if n2 == 1:
    m2 = 9
if n2 == 9:
    m2 = 1
if n3 == 1:
    m3 = 9
if n3 == 9:
    m3 = 1

print(m1*100 + m2*10 + m3)


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

int main() {
    int h, m, s, S;
    cin >> S;
    
    s = S % 60;
    m = ((S % 3600) - s) / 60;
    h = (S - m * 60 - s) / 3600;
    
    cout << h << ":" << m << ":" << s <<endl;
}


Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int X,t;
  cin >> X >> t;
  cout<< (X<t?0:X-t) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

char g[2001][2001];
int n,m,maxc[2001][2001],maxr[2001][2001],lst=-1,res,max;

int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)scanf("%s",g[i]);
	for(int i=0;i<n;i++,lst=-1,res=0)for(int j=0;j<=m;j++)
		if(j==m||g[i][j]!='.'){
			for(int k=lst+1;k<j;k++)maxc[i][k]=res;
			res=0,lst=j;
		}
		else res++;
	lst=-1,res=0;
	for(int j=0;j<m;j++,lst=-1,res=0)for(int i=0;i<=n;i++)
		if(i==n||g[i][j]!='.'){
			for(int k=lst+1;k<i;k++)maxr[k][j]=res;
			res=0,lst=i;
		}
		else res++;
	for(int i=0;i<n;i++)for(int j=0;j<m;j++)if(maxc[i][j]+maxr[i][j]>max)max=maxc[i][j]+maxr[i][j];
	printf("%d\n",max-1);
	return 0;
}


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

int main(){
  int N, K; string S;
  cin >> N >> K >> S;

  int happy = 0;
  for(int i=0; i<N-1; i++) if(S[i] ==  S[i+1]) happy++;
  
  cout << min(happy + 2*K, N-1) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

typedef int INT;
typedef vector <INT> VI;
typedef set <INT> SI;

INT P[1002];
INT Q[1002001];

INT solve( int N, INT M ) {
    INT answer = 0;
    for ( int i = 0; i < N; ++ i ) {
        int q = Q[i];
        int L = i;
        int R = N;
        INT m = M - q;
        while ( L < R ) {
            int p = ( R - L ) / 2 + L;
            INT t = q + Q[p];
            if ( t <= M ) answer = max( answer, t );
            if ( Q[p] > m ) {
                R = p - 1;
            } else {
                L = p + 1;
            }
        }
    }
    return answer;
}

int main() {
    int n, m;
    while ( cin >> n >> m ) {
        if ( n == 0 && m == 0 ) break;
        for ( int i = 0; i < n; ++ i ) {
            INT p;
            cin >> p;
            P[i] = p;
        }
        P[n] = 0;
        for ( int i = 0; i < n + 1; ++ i ) {
            for ( int j = 0; j < n + 1; ++ j ) {
                Q[i * ( n + 1 ) + j] = P[i] + P[j];
            }
        }
        int length = ( n + 1 ) * ( n + 1 );
        sort( Q, Q + length );
        cout << solve( length, m ) << endl;
    }
    return 0;
}

Measured memory_bytes: 4780
n,m = map(int, input().split())
h = list(map(int, input().split()))
G = [[] for i in range(n)]
for i in range(m):
    a,b = map(int, input().split())
    a,b = a-1,b-1
    G[a].append(b)
    G[b].append(a)

cnt = 0
for i in range(n):
    if all(h[i]>h[j] for j in G[i]):
        cnt += 1
print(cnt)

Measured memory_bytes: 93596