akhauriyash/Code-Regression huggingface dataset:
def solve():
    if k == n: return P + M

    P.sort(reverse = True)
    M.sort()
    P.append(-1)
    M.append(1) # add endpoint
    p, m = [], []
    while len(p) + len(m) < k:
        if P[len(p)] < -M[len(m)]:
            m.append(M[len(m)])
        else:
            p.append(P[len(p)])

    if len(m)%2 == 0: return p + m

    exist_p = len(p) > 0
    exist_m = len(m) > 0
    remain_P = len(P) - 1 > len(p)
    remain_M = len(M) - 1 > len(m)
    if exist_p & exist_m & remain_P & remain_M:
        if abs(p[-1] * P[len(p)]) < abs(m[-1] * M[len(m)]):
            p.pop()
            m.append(M[len(m)])
        else:
            m.pop()
            p.append(P[len(p)])
    elif exist_m & remain_P:
        m.pop()
        p.append(P[len(p)])
    elif exist_p & remain_M:
        p.pop()
        m.append(M[len(m)])
    elif k%2:
        M.pop()
        m = sorted(M, reverse = True)[:k]

    return p + m

n, k = map(int, input().split())
P, M = [], [] # plus, minus
for a in map(int, input().split()):
    if a < 0: M.append(a)
    else: P.append(a)
ans, MOD = 1, 10**9 + 7
for a in solve(): ans *= a; ans %= MOD
ans += MOD; ans %= MOD
print(ans)


Measured memory_bytes: 32380
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
#include<algorithm>
#include<set>
#include<map>
#include<cmath>
#include<string>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int N,C;
int s[100001],t[100001],c[100001];
int ss[200002],tt[200002];
int main(){
    cin >> N >> C;
    for(int i = 0; i < N; i++){
        cin >> s[i] >> t[i] >> c[i];
    }
    for(int i = 1; i <= C; i++){
        for(int j = 0; j < 200002; j++) tt[j] = 0;
        for(int j = 0; j < N; j++){
            if(c[j] == i){
                tt[s[j]*2 - 1]++;
                tt[t[j]*2]--;
            }
        }
        for(int j = 1; j < 200002; j++){
            tt[j] += tt[j-1];
        }
        for(int j = 0; j< 200002; j++){
            if(tt[j] > 0){
                ss[j]++;
            }
        }
    }
    int mx = 0;
    for(int j = 0; j < 200002; j++){
        mx = max(mx,ss[j]);
    }
    cout << mx << endl;
}



Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int p[3]; cin >> p[0] >> p[1] >> p[2];
  int mina = 200;
  for(int i = 0; i < 3; i++){
    int ans = 0;
    for(int j = 0; j < 3; j++){
      if(j == i) continue;
      ans += p[j];
    }
    mina = min(ans, mina);
  }
  cout << mina << endl;

  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,ll> P;
typedef vector<P> vip;

void solve(){
    ll a,b;
    scanf("%lld %lld",&a,&b);
    int cnt = 0;
    while(2*a>0&&a<=b){
        cnt++;
        a*=2;
    }
    cout << (cnt?cnt:1) << endl;
}

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


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

public class Main {

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] R = new int[n];
		for(int x=0; x<n; x++) {
			R[x] = scanner.nextInt();
		}
		scanner.close();
		//System.out.println(Arrays.toString(R));
		//int xx = compute_maxprofit(n,R);
		compute_maxprofit(n,R);
	}
	
	
	public static void compute_maxprofit(int n, int[] R) {
		int min = R[0];  //first number
		int max = Integer.MIN_VALUE;
		for(int x=1; x<n; x++) {
			/*if( R[x] - min> max) {
				max = R[x] - min;
			}*/
			max = Math.max(R[x] - min, max);
			if(R[x] < min) {
				min = R[x];
			}
		}
		System.out.println(max);
		//return max;
	}
}


Measured memory_bytes: 101856
import sys
string = []
words = [0] * 26
for line in sys.stdin.readlines():
    string.append(list(line))
for i in range(len(string)):
    for j in range(len(string[i])):
        code = int(ord(string[i][j].lower())) - 97
        if code >= 0 and code < 26:
            words[code] += 1
for k in range(26):
    print("{} : {}".format(chr(k+97), words[k]))


Measured memory_bytes: 5568
#include <stdio.h>
#include <string.h>
#define rep(i,l,n) for(i=l;i<n;i++)

char change(char n){
	if(n>='A' && n<='Z') return n+'a'-'A';
	else return n;
}


int main(void){
	char w[11];
	int i,len,ans=0;
	
	scanf("%s",w);
	
	
	while(1){
		char t[1001];
		scanf("%s",t);
		if(strcmp(t,"END_OF_TEXT")==0) break;
		
		len=strlen(t);
		
		rep(i,0,len){
			t[i]=change(t[i]);
		}
		
		
		if(strcmp(t,w)==0) ans++;
	}
	printf("%d\n",ans);
	
	return 0;
}

Measured memory_bytes: 548
N, K = map(int, input().split())
As = list(map(int, input().split()))

def isOK(L):
    num = 0
    for A in As:
        num += -(-A // L) - 1
    return num <= K

ng, ok = 0, 10**9
while abs(ok-ng) > 10**-6:
    mid = (ng+ok) / 2
    if isOK(mid):
        ok = mid
    else:
        ng = mid

k = int(-(-ok // 1))
#print('ok:', ok, '/ k:', k)

for L in range(max(1, k-2), k+3):
    if isOK(L):
        print(L)
        break


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

using namespace std;
using ll = long long;

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

	vector<int> v;
	int cnt = 1;
	for (int i = 1; i < N; ++i) {
		if (s[i] != s[i - 1]) {
			v.push_back(cnt);
			cnt = 0;
		}
		++cnt;
	}
	v.push_back(cnt);

	vector<ll> d(v.size() + 2, 0);
	for (int i = 1; i <= v.size(); ++i) {
		d[i] += d[i - 1] + v[i - 1];
	}
	d[d.size() - 1] = d[d.size() - 2];

	int k = 0;
	int flg = 1 - (int)(s[0] - '0');
	ll res = 0;
	for (int i = 1; i < d.size(); ++i) {
		if (i % 2 == flg) { ++k; }
		if (k <= K) {
			res = max(res, d[i]);
		} else {
			ll tmp = d[i];
			if (i % 2 == flg) { tmp -= d[i - 2 * K]; }
			else { tmp -= d[i - 2 * K - 1]; }
			res = max(res, tmp);
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1656
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
 
class Main{
 
    public static void main(String[] args){
 
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        List<String> list = new ArrayList<>();
        for(int i=0; i<n; i++){
            list.add(scanner.next());
        }
        scanner.close();
        Map<String, Integer> map = new HashMap<>();
        for (String val : list) {
           map.put(val, 0);
        }
        System.out.println(map.size());
    }
 
}

Measured memory_bytes: 70624
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

vi E[100'050];

int memo[100'050];

int dp(int at) {
  if (memo[at] != -1) return memo[at];
  int bst = 0;
  for (int e : E[at]) {
    bst = max(bst, dp(e) + 1);
  }
  return memo[at] = bst;
}

int main() {
  // code
  memset(memo, -1, sizeof(memo));

  int n, m;
  cin >> n >> m;

  rep(i, 0, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    E[x].pb(y);
  }

  int bst = 0;
  rep(i, 0, n) { bst = max(bst, dp(i)); }

  cout << bst << endl;

  // codend
}


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

const int MN = 4012345, MOD = 998244353;
int fac[MN], ivf[MN];

int tav(int a, int b) {
	if (!b)
		return 1;
	int x = tav(a, b / 2);
	return 1ll * x * x % MOD * (b % 2? a: 1) % MOD;
}

int C(int k, int n) {
	return 1ll * fac[n] * ivf[k] % MOD * ivf[n - k] % MOD;
}

void pre() {
	fac[0] = 1;
	ivf[0] = 1;
	for (int i = 1; i < MN; i++) {
		fac[i] = 1ll * fac[i - 1] * i % MOD;
		ivf[i] = tav(fac[i], MOD - 2);
	}
}

int main() {
	pre();
	int n, m;
	cin >> n >> m;
	if (n > m)
		swap(n, m);
	int ans = 0;
	for (int i = 1; i <= n; i++) 
		(ans += 1ll * C(i, 2 * i) * C(n - i, n + m - 2 * i) % MOD) %= MOD;
	ans = 1ll * ans * tav(C(n, n + m) * 2 % MOD, MOD - 2) % MOD;
	cout << ans + m;
}


Measured memory_bytes: 34988
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<map>
#define maxn 200005
using namespace std;
int n,k,l;
int father1[maxn];
int father2[maxn];
map<pair<int,int>,int>mp;
int find1(int x)
{
    if(father1[x]!=x)
       father1[x]=find1(father1[x]);
    return father1[x];
}
int find2(int x)
{
    if(father2[x]!=x)
        father2[x]=find2(father2[x]);
    return father2[x];
}
void unionn1(int x,int y)
{
    int fa=find1(x);
    int fb=find1(y);
    if(fa!=fb)
        father1[fa]=fb;
}
void unionn2(int x,int y)
{
    int fa=find2(x);
    int fb=find2(y);
    if(fa!=fb)
        father2[fa]=fb;
}
int main()
{scanf("%d%d%d",&n,&k,&l);
for(int i=0;i<=n;i++)
    {father1[i]=i;
    father2[i]=i;
    }
int p,q;
for(int i=1;i<=k;i++)
{scanf("%d%d",&p,&q);
    unionn1(p,q);
}
int r,s;
for(int i=1;i<=l;i++)
{scanf("%d%d",&r,&s);
unionn2(r,s);
}
for(int i=1;i<=n;i++)
mp[make_pair(find1(i),find2(i))]++;
for(int i=1;i<=n;i++)
    if(i!=n)
    printf("%d ",mp[make_pair(find1(i),find2(i))]);
else
    printf("%d\n",mp[make_pair(find1(i),find2(i))]);
return 0;
}


Measured memory_bytes: 13568
import java.util.Scanner;

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();

        System.out.println((a == b) ? c : (a == c) ? b : a);
    }
}


Measured memory_bytes: 23764
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	int n;cin>>n;
	int arr[n+1],cum[n+1]={},Xo[n+1]={};
	loop(n+1,i,1){
		cin>>arr[i];
		cum[i]=cum[i-1]+arr[i];
		Xo[i]=(Xo[i-1]^arr[i]);
	}
	ll res=0;
	loop(n+1,i,1){
		int l=i,r=n,len=i;
		while(l<=r){
			int mid=(l+r)/2;
			if(cum[mid]-cum[i-1]==(Xo[mid]^Xo[i-1])){
				len=mid;
				l=mid+1;
			}
			else r=mid-1;
		}
		res+=(len-i+1);
	}
	cout<<res<<endl;
}


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

void solve(long long K)
{
    vector<long long> a(200000 + 1, 0LL);
    int n = 9;
    for (size_t i = 1; i <= n; i++)
    {
        a[i] = i;
    }
    int j = 1, k = 10;
    while (k <= 150000)
    {
        if (a[j] % 10 == 0)
        {
            a[k] = 10 * a[j];
            a[k + 1] = 10 * a[j] + 1;
            k += 2;
        }
        else if (a[j] % 10 == 9)
        {
            a[k] = 10 * a[j] + 8;
            a[k + 1] = 10 * a[j] + 9;
            k += 2;
        }
        else
        {
            a[k] = 10 * a[j] + a[j] % 10 - 1;
            a[k + 1] = 10 * a[j] + a[j] % 10;
            a[k + 2] = 10 * a[j] + a[j] % 10 + 1;
            k += 3;
        }
        j++;
    }

    cout << a[K] << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    int vf[200005]={}, n,x;
    cin >> n;
    
    for(int i=2;i<=n;i++){
        cin >>x;
        vf[x]++;
    }
    
    for(int i=1;i<=n;i++){
        cout<<vf[i]<<endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

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

	ll n, h;
	cin >> n >> h;

	vector<pair<ll, ll>> sword(n);
	vector<ll> b(n);
	for (int i = 0; i < n; i++) {
		cin >> sword[i].first >> sword[i].second;
		b[i] = sword[i].second;
	}
	sort(sword.begin(), sword.end(), greater<pair<ll, ll>>());
	sort(b.begin(), b.end(), greater<ll>());

	int attackCnt = 0;
	ll excalibur = sword[0].first;
	for (int i = 0; i < n; i++) {
		if (excalibur <= b[i]) {
			h -= b[i];
			attackCnt++;
		}

		if (h <= 0) {
			cout << attackCnt << endl;
			return 0;
		}
	}

	attackCnt += h / excalibur;
	attackCnt += (bool)(h % excalibur);
	cout << attackCnt << endl;
	return 0;
}


Measured memory_bytes: 2560
#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[i];
    }

    int ans = 100100100;
    for(int i = -100; i <= 100; i++){
        int num = i;

        int cost = 0;
        for(int j = 0; j < n; j++){

            cost += (num - a[j])*(num - a[j]);
        }

        ans = min(ans, cost);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()

print("yes" if len(set(S))==len(S) else "no")


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

int main(){
    int n,ac = 0,wa = 0,tle = 0,re = 0;
    string s;

    cin >> n;

    for( int i = 0; i < n; i++){
        cin >> s;
        if( s == "AC" ){
            ac++;
        }
        else if( s == "WA" )
        {
            wa++;
        }
        else if( s == "TLE" )
        {
            tle++;
        }
        else if( s == "RE" )
        {
            re++;
        }
    }

    cout << "AC x " << ac << "\n";
    cout << "WA x " << wa << "\n";
    cout << "TLE x " << tle << "\n";
    cout << "RE x " << re << "\n";


    return 0;
}

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

int a[200005],n;

int main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+n+1);
    for(int i=1;i<n;i++) {
        if(a[i]==a[i+1]) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

Measured memory_bytes: 1152
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    N, M, X, Y = map(int, input().split())
    x = sorted(list(map(int, input().split())))
    y = sorted(list(map(int, input().split())))

    arr = x + y
    arr = [i for i in arr if X < i < Y]
    arr = [i for i in arr if x[-1] < i]
    arr = [i for i in arr if y[0] >= i]

    if arr:
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
#define MAX_N 10000
#define MAX_V 60000000
#define INF 10000000000

int n, A[MAX_N], s, B[MAX_N], T[MAX_V], cur, S, m, x; bool V[MAX_N];

int minimum_cost_sort() {
	int ans = 0;
	for (int i = 0; i < MAX_V; i++) { V[i] = false; }
	for (int i = 0; i < n; i++) { B[i] = A[i]; }
	sort(B, B + n);
	for (int i = 0; i < n; i++) { T[B[i]] = i; }
	for (int i = 0; i < n; i++) {
		if (V[i] == true) { goto owata; }
		cur = i;
		S = 0;
		m = INF;
		x = 0;
		while (1) {
			V[cur] = true;
			x++;
			int v = A[cur];
			m = min(m, v);
			S += v;
			cur = T[v];
			if (V[cur]) { break; }
		}
		ans += min(S + (x - 2)*m, m + S + (x + 1)*s);
	owata:;
	}
	return ans;
}

int main() {
	cin >> n;
	s = INF;
	for (int i = 0; i < n; i++){
		cin >> A[i];
		s = min(s, A[i]);
	}
	cout << minimum_cost_sort() << endl;
	return 0;
}

Measured memory_bytes: 60580
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << endl;
}
const int mod = 1e9 + 7;

vvl dp(1000005,vl(2,linf));

int main(){
	string s; cin >> s;
	ll n = s.size();
	reverse(all(s));
	dp[0][0] = 0;
	dp[0][1] = 1;
	rep(i,n){
		ll t = s[i] - '0';
		chmin(dp[i+1][0],dp[i][0] + t);
		chmin(dp[i+1][1],dp[i][0] + 10 - t);
		chmin(dp[i+1][0],dp[i][1] + t + 1);
		chmin(dp[i+1][1],dp[i][1] + 10 - t - 1);
	}
	//print2(dp[n][0],dp[n][1]);
	cout << min(dp[n][0],dp[n][1]+1) << endl;
	//print2(dp[1][0],dp[1][1]);
}

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

using namespace std;

typedef long long LL;
#define N 120000

LL n,m,cnt[3],E,col[N][3],ans;
bool vis[N];
vector<LL> g[N],h[N];

void dfs(LL u,LL c){
	if (!vis[u]){vis[u]=1; E+=g[u].size();}
	if (col[u][c]) return;
	col[u][c]=1; ++cnt[c];
	for (LL v:g[u]) dfs(v,(c+1)%3);
	for (LL v:h[u]) dfs(v,(c+2)%3);
}

int main(){
	scanf("%lld%lld",&n,&m);
	for (LL i=1;i<=m;++i){
		LL x,y; scanf("%lld%lld",&x,&y);
		g[x].push_back(y);
		h[y].push_back(x);
	}
	for (LL i=1;i<=n;++i)
		if (!vis[i]){
			cnt[0]=cnt[1]=cnt[2]=E=0;
			dfs(i,0);
			if (!cnt[1]||!cnt[2]) ans+=E;
			else{
				if (col[i][0]&&col[i][1]) ans+=cnt[0]*cnt[0];
				else ans+=cnt[0]*cnt[2]+cnt[1]*cnt[0]+cnt[2]*cnt[1];
			}
		}
	printf("%lld\n",ans);
	
	return 0;
}
			

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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    bool ans = false;
    REP(i,26){
        REP(j,16){
            int a = 4 * i + 7 * j;
            if(a==N) ans = true;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

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

    int count = 0;
    for (int i = 0; i <= a; i++) {
        for (int j = 0; j <= b; j++) {
            for (int k = 0; k <= c; k++) {
                if (500 * i + 100 * j + 50 * k == x) {
                    count++;
                }
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a,b,c=0,d;
	int yama[10];
	int hyama[3];
	for(a=0;a<10;a++){
		cin >> yama[a];
	}
	for(a=0;;a++){
		if(a == 9){
			a = 0;
			c = 0;
		}
		if(yama[a] < yama[a+1]){
			b = yama[a];
			yama[a] = yama[a+1];
			yama[a+1] = b;
		} 
		else {
			c++;
		}
		if(c == 9) {
			break;
		}
	}
	for(a=0;a<3;a++) {
		cout << yama[a] << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int cnt[26], cnt2[26],zas[214514];
priority_queue<int> places[26];
int nn;
ll seg[530000]; // 0-indexed!!
void init(int n_){
	nn = 1;
	while(nn<n_)nn*=2;
	for(int i=0;i<2*nn-1;i++)seg[i]=0;
}

void update(int k,int a){
	k += nn-1;
	seg[k]+=a;
	while(k>0){
		k = (k-1)/2;
		seg[k] = seg[k*2+1]+ seg[k*2+2];
	}
}

ll query(int a,int b, int k, int l, int r){
	if(r<=a || b<=l) return 0;
	if(a<=l && r<=b) return seg[k];
	else{
		ll vl = query(a,b,k*2+1,l,(l+r)/2);
		ll vr = query(a,b,k*2+2,(l+r)/2,r);
		return vl+vr;
	}
}
signed main(){
	string s;
	cin>>s;
	int n = s.size();
	for(int i=0;i<s.size();i++){
		cnt[ s[i] - 'a' ]++;
	}
	int checker = 0;
	for(int i=0;i<26;i++){
		if( cnt[i] % 2 == 1)checker ++;
	}
	if( checker >= 2){
		cout<<-1<<endl;
		return 0;
	}
	int cur = 0;
	int ans = 0;
	for(int i=0;i<n;i++){
		int c = s[i] - 'a';
		cnt2[ c ] ++;
		if( cnt[c] % 2 == 1 && cnt2[c]*2-1 == cnt[c] ){
			zas[i] = (n-1)/2;
		}
		else if( cnt2[c] <= cnt[c] / 2){
			zas[i] = cur;
			places[c].push(cur);
			cur ++ ;
		}
		else{
			int za = places[c].top(); places[c].pop();
			zas[i] = n-1-za;
		}
	}
	init(215000);
	for(int i=n-1;i>=0;i--){
		ans += query( 0, zas[i], 0, 0, nn);
		update( zas[i], 1 );
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef pair<ld,ld> id;

#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define ROF(i, a, b) for(int i=(a); i>=(b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define FILL(x, n, v) fill(x, x+n, v);
#define ALL(x) x.begin(), x.end()
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define f first
#define s second
#define ins insert
#define e emplace
#define eb emplace_back
#define ef emplace_front
#define p push
#define pf push_front
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ft front
#define bk back
#define pp pop
#define ppb pop_back
#define ppf pop_front

#define db cout<<"YEET\n";
#define ct(x) cout<<x<<'\n';

const ll MOD = 1e9+7; //998244353
const ll MAXN = 10000;
const ll INF = 1e18;
const ld PI = acos((ld)-1);

int main(){
    FAST
    ll n, x, y;
    cin >> n >> x >> y;
    vector<ll> adjlist[MAXN];
    ll ans[MAXN];
    MEM(ans, 0);

    adjlist[x].pb(y);
    adjlist[y].pb(x);

    bool visited[MAXN];
    FOR(i,1,n-1){
        adjlist[i].pb(i+1);
        adjlist[i+1].pb(i);
    }

    FOR(i, 1, n){
        MEM(visited, false);
        queue<ii> bfs;
        ll mindist[MAXN];
        MEM(mindist, 10000);

        bfs.e(i,0);
        mindist[i] = 0;

        while (!bfs.empty()){
            ll u = bfs.front().f;
            ll dist = bfs.front().s;
            bfs.pop();
            for (auto v : adjlist[u]){
                if (visited[v]) continue;
                else {
                    visited[v] = 1;
                    mindist[v] = min(mindist[v], dist+1);
                    bfs.e(v,dist+1);
                }
            }
        }

        FOR(j, i, n) ans[mindist[j]]++;
    }

    FOR(i,1,n-1){
        cout << ans[i] << '\n';
    }
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 200010;
const int N = 200010;

int main() {
	int n;cin>>n;
	ll c[N];
	rep(i,n) cin>>c[i];
	sort(c,c+n,greater<ll>());
	ll d=1;
	rep(i,n-1) d=(d*4)%MOD;
	ll ans=0;
	rep(i,n) ans=(ans+(i+2)*c[i])%MOD;
	ans=(ans*d)%MOD;
	cout<<ans<<endl;
}


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

int main(){
  
  int A;
  int B;
  
  cin >> A;
  cin >> B;
  
    if( A % 2 == 0 || B % 2 == 0){
     cout << "No" <<endl;
    } else{
      cout << "Yes" <<endl;
    }

  return 0;     
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    int n;
    cin>>n;
    if(n<1200){
        cout<<"ABC"<<endl;
    }else if(n>=1200 && n<2800){
        cout<<"ARC"<<endl;
    }else{
        cout<<"AGC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
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;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,n;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++)cin>>a[i];
	double ave=0;
	for(i=0;i<n;i++)ave+=a[i];
	ave=round(ave/(double)n);
	int ans=0;
	for(i=0;i<n;i++){
		ans+=(a[i]-ave)*(a[i]-ave);
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 512
from sys import stdin
from math import factorial as f
N = int(input())
words = []
for s in stdin:
    words.append(
        ''.join(sorted(s.strip()))
    )

words = sorted(words)
ans = 0
p = words[0]
streak = 1
s = []

for i in range(1, N):
    if p == words[i]:
        streak += 1
    else:
        s.append(streak)
        streak = 1
        p = words[i]

s.append(streak)

for n in s:
    if n == 1:
        continue
    elif n == 2:
        ans += 1
    else:
        ans += f(n) // (2 * f(n - 2))

print(ans)

Measured memory_bytes: 11468
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
now=-100000000000
for i in range(1,n+1):
    retu=[]
    sum1=0
    sum2=0
    sum3=0
    max1=-1000000000000
    max2=-1000000000000
    flag=0
    x=i
    while(flag==0):
        x=p[x-1]
        sum1+=c[x-1]
        retu.append(c[x-1])
        if x==i:
            flag=1
    if len(retu)>=k: #操作回数が周期未満
        for j in range(k):
            sum2+=retu[j]
            if sum2>max1:
                max1=sum2
        ans=max1
    elif sum1<=0: #周期和が負
        for j in range(len(retu)):
            sum3+=retu[j]
            if sum3>max2:
                max2=sum3
        ans=max2
    else:
        w=k%len(retu)
        
        if w==0:
            w=len(retu)
        for j in range(w):
            sum2+=retu[j]
            if sum2>max1:
                max1=sum2
        for j in range(len(retu)):
            sum3+=retu[j]
            if sum3>max2:
                max2=sum3
        if max1+sum1>max2:
            ans=sum1*(k-w)//len(retu)+max1
        else:
            ans=sum1*((k-w)//len(retu)-1)+max2
    now=max(now,ans)
print(now)

Measured memory_bytes: 80904
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pii pair<ll,ll>
#define F first
#define S second
#define pb push_back
#define int ll
template <typename T>
using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll mod1=998244353,mod2=(ll)1e9+7;
ll power(ll n,ll k,ll mod){ll ans=1; n=n%mod;while(k>0){if(k&1)ans=(ans*n)%mod;n=(n*n)%mod;k>>=1;}return (ans+mod)%mod;}//negative nos & 0^0
struct triplet{ll a,b,c;};bool operator < (const triplet &t1,const triplet &t2){if(t1.a<t2.a)return true;if(t1.a==t2.a && t1.b <t2.b)return true;if(t1.a==t2.a && t1.b ==t2.b && t1.c<t2.c)return true;return false;}

int32_t main()
{
    fio;
    int n,k;
    cin>>n>>k;
    int ans=0;
    for(int x=k;x<=n+1;x++)
    {
        ans=(ans+n*(n+1)/2-(n-x)*(n-x+1)/2-(x)*(x-1)/2+1)%mod2;
    }
    cout<<ans;
}


Measured memory_bytes: 3652
n,m=map(int,input().split())
H=list(map(int,input().split()))
L=[1]*n

for i in range(m):
    a,b=map(int,input().split())

    if H[a-1]>=H[b-1]:
        L[b-1]=0
    if H[b-1]>=H[a-1]:
        L[a-1]=0

print(sum(L))

Measured memory_bytes: 20108
import sys
from bisect import bisect_right as bsr
from collections import Counter as cnt
from collections import defaultdict as dd
from collections import deque
from fractions import gcd
from itertools import combinations as comb
from itertools import permutations as perm
from math import ceil, factorial, floor
from operator import itemgetter as ig

sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    D = input([int, N])
    dcomb = comb(D, 2)
    ans = 0
    for d in dcomb:
        ans += d[0] * d[1]
    print(ans)


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 5048
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換

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

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N;
    cin >> N;

    vector<int> ans;
    int acu=0;
    int count = 1;
    int res;

    while(1)
    {
        int amari = N % LL(pow(2,count));
        dump(count)
        dump(pow(2,count))
        dump(amari)
        if(amari >= 0)
        {
            if(amari == (acu >= 0 ? acu : acu + LL(pow(2,count)))) res = 0;
            else res = 1;
        }
        else
        {
            if(amari+LL(pow(2,count)) == (acu >= 0 ? acu : acu + LL(pow(2,count)))) res = 0;
            else res = 1;
        }
        dump(res)
        acu += res * LL(pow(-2,count-1));
        dump(acu)
        ans.push_back(res);
        count++;

        if(acu == N) break;
        //if(count == 30) break;

    }

    for(auto i = 0; i < ans.size(); i++)
    {
        cout << ans[ans.size()-i-1];
    }
    cout << endl;
}


Measured memory_bytes: 256
import queue
import collections

N = int(input())
Ss = [input() for i in range(N)]

mc = collections.Counter(Ss).most_common()
_, prev = mc[0]
q = queue.PriorityQueue()
for k, v in mc:
    if prev != v:
        break
    q.put(k)
    prev = v

while not(q.empty()):
    print(q.get())


Measured memory_bytes: 126844
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main() {
    int N;
    string S;
    cin >> N >> S;
    for (char &c : S) {
        int a = (c - 'A');
        a = (a + N) % 26;
        c = 'A' + a;
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 3624
N,M=map(int, input().split())

class UnionFind():
    def __init__(self, n):
        self.n = n # ノード数
        self.parents = [-1]*n # 各ノードごとのparent

    def find(self, x):
        # 自身が根であれば
        if self.parents[x]<0:
            return x
        # そうでなければ、再帰的に繰り返し、自身の根を探索
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        # それぞれの根
        x = self.find(x)
        y = self.find(y)

        # 根が同一であれば
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x,y = y,x
        self.parents[x]+=self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

uf = UnionFind(N)
for _ in range(M):
    i, j = map(int, input().split())
    i-=1
    j-=1
    uf.union(i,j)

max_size = 0
for i in range(N):
    if uf.parents[i]<0:
        size = uf.size(i)
        if max_size<size:
            max_size = size
print(max_size)


Measured memory_bytes: 14532
h, w = map(int, input().split())
s = [input() for i in range(h)]
for y in range(h):
    for x in range(w):
        if s[y][x] == '#':
            cnt = 0
            cnt += 1 if 0 < x and s[y][x - 1] == '#' else 0
            cnt += 1 if x < w - 1 and s[y][x + 1] == '#' else 0
            cnt += 1 if 0 < y and s[y - 1][x] == '#' else 0
            cnt += 1 if y < h - 1 and s[y + 1][x] == '#' else 0
            if cnt == 0:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
import math

while True:
    n = int(input())
    if n == 0:
        break
    s = input().split()

    m = 0.0
    for i in range(n):
        m += int(s[i])
    m /= n

    d = 0.0
    for i in range(n):
        d += (int(s[i]) - m) ** 2
    d = math.sqrt(d / n)

    print(d)



Measured memory_bytes: 5780
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
static int n = int.Parse(Console.ReadLine());
static int[] nums = new int[n-1];
static List<int>[] childrenList = new List<int>[n+1];
static List<int>[] answerList = new List<int>[n+1];
static int[] answers = new int[n+1];

	static void Main()
	{
    for(int i = 0; i <= n; i++)
    {
      answers[i] = -1;
      childrenList[i] = new List<int>();
      answerList[i] = new List<int>();
    }
  
		for(int i = 0; i < n-1; i++)
    {
      nums[i] = int.Parse(Console.ReadLine());
      childrenList[nums[i]].Add(i+2);
    }
    
		Console.WriteLine(DP(1));
	}

  static int DP(int num)
  {
    if(answers[num] != -1) return answers[num];
    int answer = 0;

    for(int i = 0; i < childrenList[num].Count(); i++)
    {
      answerList[num].Add(DP(childrenList[num][i]));
    }
    answerList[num].Sort((a, b) => b.CompareTo(a));//降順にソート
    
    for(int i = 0; i < childrenList[num].Count(); i++)
    {
      answer = Math.Max(answer, i+1+answerList[num][i]);
    }

    return answers[num] = answer;
  }
}

Measured memory_bytes: 42848
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    string s;
    std::cin >> s;
    ll canp=0;
    ll result=0;
    for (int i = 0; i < s.length(); i++) {
        if(s[i]=='g'){
            if(canp>0){
                result++;
                canp--;
            }else{
                canp++;
            }
        }else{
            if(canp>0){
                canp--;
            }else{
                result--;
                canp++;
            }
        }
    }
    std::cout << result << std::endl;
    
}


Measured memory_bytes: 512
#define __STDC_FORMAT_MACROS
#define p64 PRId64

#include <cinttypes>
#include <cstdio>
#include <string>

using namespace std;
using ll = int64_t;

int main()
{
    ll N, M;
    if (scanf("%" p64 "%" p64, &N, &M) < 2) return 0;

    if (N == 1)
    {
        if (M == 1)
        {
            printf("%" p64 "\n", (ll)1);
        }
        else
        {
            printf("%" p64 "\n", M - 2);
        }
    }
    else
    {
        if (M == 1)
        {
            printf("%" p64 "\n", N - 2);
        }
        else
        {
            printf("%" p64 "\n", (N - 2) * (M - 2));
        }
    }

    return 0;
}


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

const int D = 1e9+1;

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

    int dp[100001];
    for(int i = 0; i < 100001; i++) dp[i] = D;
    dp[0] = 0;

    int w, v;
    for(int i = 0; i < n; i++){
        cin >> w >> v;
        for(int j = 100001; j >= v; j--){
            if(dp[j-v] == D)    continue;
            dp[j] = min(dp[j], dp[j-v]+w);
        }
    }

    int ans = 0;
    for(int i = 0; i < 100001; i++) if(dp[i] <= W)  ans = max(ans, i);

    cout << ans << endl;

    return 0;
}

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

int main(){
    int n;cin>>n;
    ll a[1000010];
    ll ans=0;
    for(int i=0;i<n;++i)cin>>a[i];
    for(int i=1;i<n;++i){
        if(a[i-1]>a[i]){
            ans+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 5128
n, k = map(int,input().split())
a = list(map(int,input().split()))

num = [0] * (n+1)
for i in range(n):
   num[a[i]] += 1

nonzero = sorted([i for i in num if i!=0])

sumR = max(0, len(nonzero) - k)
ans = sum(nonzero[:sumR])
print(ans)

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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>M;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n
#define pl(n) cout<<n
const int mod=1e9+7;
const int sze=1e5+2;
const int inf=1e19;
void solve(){
 int h,n;
 sl(h);sl(n);
 int sum=0;
 for(int i=0;i<n;i++){
	 int num;
	 sl(num);
	 sum+=num;
 }
 if(sum>=h)cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

}

signed main(){
   int test=1;
   //sl(test);
   while(test--){
      solve();

   }
  return 0;
}


Measured memory_bytes: 256
X = int(input())

s = [0,1,2,3]

if (X == 9-7-1):
  print('fri')
elif (X == 9-7):
  print('sat')
elif (X == 9-7+1):
  print('sun')
elif (X == 9-7+2):
  print('mon')
elif (X == 9-7+3):
  print('tue')
elif (X == 9-7+4):
  print('wed')
elif (X == 9-7+5):
  print('thu')
elif (X == 9-7+6):
  print('fri')

for i in s:
  if(X == 9+7*i):
    print('sat')
  elif (X == (9+7*i)+1):
    print('sun')
  elif (X == (9+7*i)+2):
    print('mon')
  elif (X == (9+7*i)+3):
    print('tue')
  elif (X == (9+7*i)+4):
    print('wed')
  elif (X == (9+7*i)+5):
    print('thu')
  elif (X == (9+7*i)+6):
    print('fri')



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll D;
  cin >> D;
  vector<ll> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<ll>> s(D,vector<ll>(26));
  rep(i,D)
  {
    rep(j,26)
    {
      cin >> s[i][j];
    }
  }
  vector<int> t(D);
  vector<int> lastday(26);
  rep(i,26) lastday[i] = -1;
  rep(i,D) 
  {
    cin >> t[i];
    t[i] --;
  }
  ll satisfy = 0;
  rep(i,D)
  {
    ll dissatisfy = 0;
    satisfy += s[i][t[i]];
    lastday[t[i]] = i;
    rep(j,26)
    {
      dissatisfy += c[j] * (i-lastday[j]);
    }
    satisfy -= dissatisfy;
    cout << satisfy << endl;
  }
  return 0;
}


Measured memory_bytes: 3676
import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val S = sc.next

    val weeks = Array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT")

    for (i <- weeks.indices) {
      if (S == weeks(i)) {
        return (7 - i).toString
      }
    }
    ""
  }
}


Measured memory_bytes: 25532
#include<bits/stdc++.h>
using namespace std;
int p[200009];

int find(int x){
  if(p[x]==x)return x;
  return p[x]=find(p[x]);
}

int same(int x,int y){
  if(find(x)==find(y))return 1;
  return 0;
}

void unite(int x,int y){
  x=find(x);
  y=find(y);
  p[x]=y;
}

int main(){
  int n,m,cnt=0;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    int q;
    cin>>q;
    p[q]=q;
    p[n+i]=q;
  }
  for(int i=0;i<m;i++){
    int s,t;
    cin>>s>>t;
    unite(s,t);
  }
  for(int i=1;i<=n;i++){
    if(same(i,i+n))cnt++;
  }
  cout<<cnt<<endl;
  return(0);
}

    


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
    string S, T;

    cin >> S >> T;

    for(int i=0; i < S.size(); i++) {
        if(T.at(i) == S.at(0)) {
            bool flag = true;
            for(int j=0; j < S.size(); j++) {
                int tmp = i+j;
                if(tmp >= S.size()) tmp -= S.size();
                if(S.at(j) != T.at(tmp)) {
                    flag = false;
                    break;
                }
            }
            if(flag) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }


    cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=300005;
const ll INF=0x3f3f3f3f;
const ll MOD=998244353;
ll n,ans,fact[MAX],finv[MAX],a,b,k;
ll power(ll x,ll y){
    if(y==0) return 1;
    ll t=power(x,y/2);
    if(y%2) return t*t%MOD*x%MOD;
    return t*t%MOD;
}
ll comb(ll x,ll y){
    return fact[x]*finv[x-y]%MOD*finv[y]%MOD;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    fact[0]=1;
    for(ll i=1;i<=n;i++) fact[i]=fact[i-1]*i%MOD;
    for(ll i=0;i<=n;i++) finv[i]=power(fact[i],MOD-2);
    for(ll i=0;a*i<=k&&i<=n;i++) if((k-a*i)%b==0&&(k-a*i)/b<=n){
        ll t1=i,t2=(k-a*i)/b;
        ans+=comb(n,t1)*comb(n,t2),ans%=MOD;
    }
    printf("%lld\n",ans);
}


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

using namespace std;

int main(){
    int A, B, K;
    cin >> A >> B >> K;

    int min;
    if (A < B) {
        min = A;
    }else{
        min = B;
    }

    vector <int> number(min);
    int k = 0;

    for(int i = 1; i < min + 1; i++){
        if (A % i == 0 && B % i == 0) {
            number[k] = i;
            k += 1;
        }
    }
    
    cout << number[k - K] << endl;

    return 0;
}

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

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

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    string sub = s.substr(i, 3);
    if (sub == "ABC")
      ++cnt;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split()]
nb = 0
da = 0
for i in range(len(A)-1):
    if A[i] > A[i+1] and da > 0:
        nb += 1
        da = 0
    elif A[i] < A[i+1] and da < 0:
        nb += 1
        da = 0
    else:
        if A[i+1] - A[i] != 0:
            da = A[i+1] - A[i]
print(nb + 1)

Measured memory_bytes: 20524
from collections import defaultdict
from collections import Counter

H, W, N = map(int, input().split())

# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
       [-1, 0], [-1, -1], [0, -1], [1, -1]]

# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)

for i in range(N):
    a, b = map(int, input().split())
    for dy, dx in dir:
        # 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
        if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
            dict[(a + dy, b + dx)] += 1

c = Counter(dict.values())
ans = [0 for _ in range(10)]

# ans[1], ans[2], ..., ans[9]を確定させる（ans[0]は後述）
for k, v in c.items():
    if v > 0:
        ans[k] = v

# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])

for i in range(10):
    print(ans[i])


Measured memory_bytes: 164288
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define pb push_back
#define mp make_pair

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int main() {
  string s;
  cin >> s;
  LL k;
  scanf("%lld",&k);
  char ans = '1';
  rep(i,0,s.size()) {
    if(s[i] != '1') {
      ans = s[i];
      break;
    }
    if(i + 1 == k) {
      break;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
long long dp[1000000];
int main(){
  long long n,m,ans=0,k=0;
  cin>>n>>m;
  long long truee[n+1];
  for(int i=0;i<=n;i++){
    truee[i] = 1;
    dp[i] = 0;
  }
  dp[0]=1;
  long long t;
  for(int i=0;i<m;i++) {cin>>t; truee[t]=0;}
  for(int i=1;i<=n;i++){
    if(truee[i]==1) {dp[i] += dp[i-1];}
      if(i>1){
        if(truee[i]==1){
          dp[i] += dp[i-2];
        }
      }
    dp[i]%=1000000007;
  }
  cout<<dp[n]<<endl;
  //for(int i=0;i<n;i++) cout<<dp[i]<<endl;
}

Measured memory_bytes: 1792