akhauriyash/Code-Regression huggingface dataset:
/* monkukui 競技プログラミング用のテンプレート  (ここから) */
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
using ll = long long int;
using lnt = long long int;
using Graph = vector<vector<int>>;
using Wgraph = vector<vector<pair<int, long long int>>>;
constexpr long long int INF = 1001001001001001LL;
constexpr long long int MOD = 1000000007LL;
constexpr double PI = 3.1415926535897932;
constexpr long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
constexpr long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
inline void yes(){ cout << "yes" << endl; }
inline void Yes(){ cout << "Yes" << endl; }
inline void YES(){ cout << "YES" << endl; }
inline void no(){ cout << "no" << endl; }
inline void No(){ cout << "No" << endl; }
inline void NO(){ cout << "NO" << endl; }
inline void possible(){ cout << "possible" << endl; }
inline void Possible(){ cout << "Possible" << endl; }
inline void POSSIBLE(){ cout << "POSSIBLE" << endl; }
inline void impossible(){ cout << "impossible" << endl; }
inline void Impossible(){ cout << "Impossible" << endl; }
inline void IMPOSSIBLE(){ cout << "IMPOSSIBLE" << endl; }

#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = 1; i <= (n); i++)
#define DREP(i,n) for(int i = (n)-1; i >= 0; i--)
#define SREP(i,s,t) for(int i = s; i < t; i++)
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define PB push_back

/* monkukui 競技プログラミング用のテンプレート (ここまで)*/

int main(){
  
  while(1) {
    int n, m; cin >> n >> m;
    if(n == 0) break;
    vector<lnt> c(m);
    for(int i = 0; i < m; i++) cin >> c[i];
    vector<lnt> x(n);
    for(int i = 0; i < n; i++) cin >> x[i];

    // DP 
    vector<vector<lnt>> dp(n + 1, vector<lnt> (256, INF));
    dp[0][128] = 0;
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 256; j++) {
        if(dp[i][j] == INF) continue;

        lnt val = j;
        for(int k = 0; k < m; k++) {
          int nxtVal = val + c[k];
          if(nxtVal < 0) nxtVal = 0;
          if(nxtVal > 255) nxtVal = 255;
          dp[i + 1][nxtVal] = min(dp[i + 1][nxtVal], dp[i][val] + (nxtVal - x[i]) * (nxtVal - x[i]));
        }
      }
    }
    
    lnt ans = INF;
    for(int j = 0; j < 256; j++) ans = min(ans, dp[n][j]);
    cout << ans << endl;

    
  }
  return 0;
}



Measured memory_bytes: 43736
object Main {

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

    val N = sc.nextInt()
    val G = Array.fill(N)(new scala.collection.mutable.ArrayBuffer[(Int, Int)]())
    var i = 0
    while (i < N) {
      val u, k = sc.nextInt()
      var j = 0
      val buffer = G(u)
      while (j < k) {
        val v, c = sc.nextInt()
        buffer.append((v, c))
        j += 1
      }
      i += 1
    }

    def dijkstra(s: Int): Array[Int] = {
      val INF = Int.MaxValue
      val distance = Array.fill(N)(INF)
      distance(s) = 0

      val queue = scala.collection.mutable.PriorityQueue[Int](s)(
        Ordering.by[Int, Int](v => distance(v))(Ordering.Int.reverse))

      def relax(u: Int, v: Int, w: Int): Unit =
        if (distance(u) != INF && distance(u) + w < distance(v)) {
          distance(v) = distance(u) + w
          queue.enqueue(v)
        }

      while (queue.nonEmpty) {
        val u = queue.dequeue()
        G(u) foreach { case (v, w) =>
          relax(u, v, w)
        }
      }
      distance
    }

    val res = dijkstra(0).zipWithIndex.map(u => u._2 + " " + u._1).mkString("\n")
    println(res)
  }

}



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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;

typedef long long LL;

LL GCD(LL x, LL y){
        LL r=0;

        if( x<y ) swap(x, y);
        r = x % y;
        while(r!=0){
                x = y;
                y = r;
                r = x % y;
        }
        return y;
}

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

	int N;
	long long A[100002] = {0};

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

	long long ans = GCD(A[1], A[2]);
	for(int i = 3; i <= N; i++){
		ans = GCD(ans, A[i]);
	}
	cout << ans << endl ;
	return 0;
}

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

int main() {
  int N,A,x;
  cin >> N >> A;
  
  
  x=N%500;

  if (x==0){
      cout << "Yes" << endl;
  }
  
  else if (x <= A) {
    cout <<  "Yes" << endl;
  }

  else {
    cout << "No" << endl;
  }
}


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

int main(){
  stack<int> S;
  int a,b,x;
  string s;
  
  while(cin>>s){
  	if(s[0]=='+'){
    	a=S.top();S.pop();
      	b=S.top();S.pop();
      	S.push(a+b);
    }else if(s[0]=='-'){
    	b=S.top();S.pop();
      	a=S.top();S.pop();
      	S.push(a-b);
    }else if(s[0]=='*'){
    	a=S.top();S.pop();
      	b=S.top();S.pop();
      	S.push(a*b);
    }else{
    	S.push(atoi(s.c_str()));    
    }  
  }
  cout<<S.top()<<endl;
}


Measured memory_bytes: 3212
#include "stdio.h"
int main(void) {
  int r, g, b;
  scanf("%d %d %d", &r, &g, &b );
  if ((100 * r + 10 * g + b) % 4 == 0) printf("YES\n" );
  else printf("NO\n" );
  return 0;
}

Measured memory_bytes: 128
/*input
5
1 - 20 - 13 + 14 - 5
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back

#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < (int)n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)

#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

int raise(int a,int n,int m = MOD){
  if(n == 0)return 1;
  if(n == 1)return a;
  int x = 1;
    x *= raise(a,n/2,m);
    x %= m;
    x *= x;
    x %= m;
    if(n%2)x*= a;
    x %= m;
    return x;
}

int floor1(int n,int k){
    if(n%k == 0 || n >= 0)return n/k;
    return (n/k)-1;
}

int ceil1(int n,int k){
    return floor1(n+k-1,k);
}

const int N = 1e5+1;
int prefr[N];
int prefa[N];
int n;
int a[N];
int op[N];

void solve(){
  	cin >> n;
  	op[1] = 1;
  	cin >> a[1];
  	prefr[1] = prefa[1] = a[1];
  	for(int i = 2;i <= n;i++){
  		char o;cin >> o;
  		op[i] = -1+2*(o == '+');
  		cin >> a[i];
  		prefr[i] = prefr[i-1]+a[i]*op[i];
  		prefa[i] = prefa[i-1]+a[i];
  	}
  	int ans = prefr[n];
  	for(int i = 1;i <= n;i++){
  		if(op[i] == -1){
  			for(int j = i+1;j <= n;j++){
  				if(op[j] == -1){
  					int one = prefr[i-1]+prefa[n]-prefa[j-1]-(prefa[j-1]-prefa[i-1]);
  				//	cout << i << " " << j << " " << one << endl;
  					ans = max(ans,one);
  					break;
  				}
  			}
  		}
  	}
  	cout << ans;
}

signed main(){
  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  //freopen(".in","r",stdin);freopen(".out","w",stdout);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }
  return 0;
}

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

int main(){
  int N, L;
  cin >> N >> L;

  vector<string> S(N);
  for_each(S.begin(), S.end(),
           [](auto &v){cin >> v;});

  sort(S.begin(), S.end());
  for_each(S.begin(), S.end(),
           [](auto v){cout << v;});
  cout << endl;
}


Measured memory_bytes: 256
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll a, b;
    cin >> a >> b;
    cout << (a + b + 1) / 2;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

int main(){
	
	string a,b; cin>>a>>b;
	int c,d; cin>>c>>d;
	string s; cin>>s;
	if(s == a) c--;
	if(s == b) d--;
	cout<<c<<" "<<d<<"\n";
	
	
}

Measured memory_bytes: 256
def is_month(n: int)->bool:
    return 1 <= n and n <= 12


def yymm_or_mmyy(S: str)->str:
    first = int(S[:2])
    second = int(S[2:])

    if is_month(first) and is_month(second):
        return "AMBIGUOUS"
    elif is_month(first):
        return "MMYY"
    elif is_month(second):
        return "YYMM"

    return "NA"


if __name__ == "__main__":
    S = input()

    ans = yymm_or_mmyy(S)
    print(ans)


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    string s;
    cin >> s;

    int num = s.size();

    int ans;
    ans = 9 * (num - 1);
    if(s[0] != 0) ans += s[0] - '0' - 1;

    int cnt = 0;
    REP(i, num) if (s[i] == '9') cnt++;
    if (cnt == num) ans = 9 * num;

    if (num == 1) ans = stoi(s);

    string t = s.substr(1, s.size());
    cnt = 0;
    REP(i, num - 1) if (t[i] == '9') cnt++;
    if (cnt == num - 1) {
        ans = 9 * (num - 1);
        ans += s[0] - '0';
    }

    cout << ans << '\n';
    return 0;
}


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

using namespace std;

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

int modpow(int A, int n) {
    int64_t res = 1, a;
    a = A%mod;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int N, K;
    cin >> N >> K;
	int i, j, num, ci;
    vector<bool> checked(K+1, false);
    vector<int> count(K+1, 0);
    int64_t subsum;
    int modsubsum;
    for(i=K; i>0; i--){
        num = K/i;
        ci = num;
        subsum = 0;
        while(ci>1){
          subsum += count.at(ci*i);
          ci--;
        }
        modsubsum = subsum%mod;
        count.at(i) = modpow(num,N)-modsubsum;
    }
    int64_t ans=0;
    for(i=1; i<=K; i++){
      ans += (int64_t)count.at(i)*i;
      ans = ans%mod;
    }
    if(ans<0) ans += mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 3768
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    /**
     * 整数K
     */
    private static int K;

    /**
     * ある町へ転送するテレポータが設置されている町のリスト
     */
    private static List<List<Integer>> vec = new ArrayList<>();

    /**
     * 転送先を変えなければならないテレポータの数
     */
    private static int ans = 0;

    public static void main(String args[]) {
        //スタックサイズ2^24で処理を行う
        new Thread(null, () -> {
            //try-with-resources文(カッコ内で宣言した変数はtry句を抜けると自動的に閉じられる)
            try (Scanner sc = new Scanner(System.in)) {
                int n = sc.nextInt();
                K = sc.nextInt();
                for (int i = 0; i < n; i++) {
                    vec.add(new ArrayList<>());
                }
                for (int i = 0; i < n; i++) {
                    int a = sc.nextInt() - 1;
                    if (i != 0) {
                        vec.get(a).add(i);
                    } else if (a != 0) {
                        ans++;
                    }
                }
            }

            dfs(0, 0);
            System.out.println(ans);
        }, "", 1 << 24).start();
    }

    /**
     * 転送回数を算出する
     *
     * @param v   着目する町
     * @param pre 1つ前の町
     * @return 転送回数
     */
    private static int dfs(int v, int pre) {
        int height = 0;

        //拡張for文(リストや配列から要素を1つずつ取り出す)
        for (int j : vec.get(v)) {
            height = Math.max(height, dfs(j, v));
        }

        if (pre != 0 && height == K - 1) {
            height = 0;
            ans++;
        } else {
            height++;
        }

        return height;
    }
}

Measured memory_bytes: 46072
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    h,w,a,b = map(int,ipt().split())
    mod = 10**9+7

    #nCrをmodで割った余りを求める。Nに最大値を入れて使用。
    N = 2*10**5
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル
    def cmb(n,r,mod):
        if r<0 or r>n :
            return 0
        r = min(r,n-r)
        return g1[n]*g2[r]*g2[n-r]%mod
    for i in range(2,N+1):
        g1.append((g1[-1]*i)%mod)
        inverse.append((-inverse[mod % i]*(mod//i))%mod)
        g2.append((g2[-1]*inverse[-1])%mod)

    ans = cmb(h+w-2,h-1,mod)
    for i in range(max(a,b)):
        ans = (ans-cmb(b+h-a-1,b-1-i,mod)*cmb(a+w-b-1,a-1-i,mod)%mod)%mod
    print(ans)



    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 81260
#include<iostream>
using namespace std;
 
int main(){
 int N,W;
 cin>>N>>W;
 
 int v[N],w[N];
 
 for(int i=0;i<N;i++){
    cin>>v[i]>>w[i];
 }
 
 int DP[N+1][W+1];
 
 for(int j=0;j<=W;j++){
    DP[0][j]=0;
 }
 
 for(int i=1;i<=N;i++){
    for(int j=0;j<=W;j++){
        if(j<w[i-1]){
            DP[i][j]=DP[i-1][j];
        }else{
            if(DP[i-1][j]>DP[i][j-w[i-1]]+v[i-1]){
                DP[i][j]=DP[i-1][j];
            }else{
                DP[i][j]=DP[i][j-w[i-1]]+v[i-1];
            }
        }
    }
 }
 cout<<DP[N][W]<<endl;

return 0;
}

Measured memory_bytes: 7012
if __name__ == '__main__':
    s = list(input())
    ss = s + s
    k = int(input())
    if len(set(s)) == 1:
        print(len(s) * k // 2)
        exit(0)

    tmp, tmp2 = 0, 0
    for i in range(len(s) - 1):
        if s[i] == s[i + 1]:
            tmp += 1
            s[i + 1] = '-1'
    for i in range(len(s) * 2 - 1):
        if ss[i] == ss[i + 1]:
            tmp2 += 1
            ss[i + 1] = '-1'
    print(tmp + (tmp2 - tmp) * (k - 1))


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

lli funFrogJump(lli n,lli *dp,lli *values){
	if(n==0||n==1){
		dp[n] = n;
		return 0;
	}
	if(n==2){
		dp[n] = abs(values[n-1]-values[n-2]);
		return dp[n];
	}
	if(dp[n]!=-1) return dp[n];
	dp[n] = min(funFrogJump(n-1,dp,values)+abs(values[n-1]-values[n-2]),funFrogJump(n-2,dp,values)+abs(values[n-1]-values[n-3]));
	return dp[n];
}

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

Measured memory_bytes: 5760
#ifdef LOCAL
#include "libs/debug/print_list.hpp"
#define debug(x) (cout << # x ": " << x << endl)
#define dev(v, m, n) for(int i=0;i<n;++i){for(int j=0;j<m;++j){cout<<"|"<<v[j][i];}cout<<"|"<<endl;}
#else
#define debug(x) ;
#define dev(v, m, n) ;
#endif

// :----------------------------------------

#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;
using Graph = vector<vector<int>>;

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

#define P (1'000'000'007)

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

    Graph g(n, vi());
    Graph ge(n, vi());

    rep(i, n - 1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u; --v;

        if (w % 2 == 0) {
            ge[u].push_back(v);
            ge[v].push_back(u);
        } else {
            g[u].push_back(v);
            g[v].push_back(u);
        }
    }

    vi vc(n, -1);

    queue<int> q;
    q.push(0);
    int p = 0;
    vc[0] = 0;

    while (!q.empty()) {
        auto x = q.front(); q.pop();

        for (auto v: g[x]) {
            if (vc[v] == -1) {
                vc[v] = 1 - vc[x];
                q.push(v);
            }
        }
        for (auto v: ge[x]) {
            if (vc[v] == -1) {
                vc[v] = vc[x];
                q.push(v);
            }
        }

        if (q.empty()) {
            while (++p < n) {
                if (vc[p] == -1) {
                    q.push(p);
                    vc[p] = 0;
                    break;
                }
            }
        }
    }

    for(auto c: vc) {
        cout << c << endl;
    }
    
    return 0;
}


Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>
#include <queue>
#include <cctype>
#include <stack>


#define rep(i,p,q) for(ll i = p;i < q;++i)
#define ll long long

using namespace std;

//C

int main(void) {
	ll l, r;
	cin >> l >> r;
	if (r - l >= 2018) cout << 0 << endl;
	else {
		ll ans = 4e18;
		rep(i, l, r) {
			rep(j, i + 1, r + 1) {
				ans = min(ans, (i % (ll) 2019) * (j % (ll)2019) % (ll)2019);
			}
		}
		cout << ans << endl;
	}
	
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int h,w,x,y,z,i;
for(z=0;1;z++){
    scanf("%d%d",&h,&w);
  if(h==0 && w==0)break;
      for(y=0;y<w;y++){
      printf("#");
    }
    printf("\n");
                  for(i=0;i<h-2;i++){
       printf("#");
          for(x=0;x<w-2;x++){
            printf(".");
                                }
      printf("#\n");
        }
    for(i=0;i<w;i++){
      printf("#");
          }
    printf("\n\n");
        }

 
  return 0;
}

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

#define INF 1e9
#define LLINF 1e18
#define pi 3.14159265358979323
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int gcd(int a, int b) {
    if(a % b == 0) {
        return b;
    }
    else {
        return(gcd(b, a % b));
    }
}


int main() {
    int n;
    cin >> n;
    vector<char> c(n);
    int r = 0;
    int w = 0;
    rep(i, n) {
        cin >> c.at(i);
        if (c.at(i) == 'R') r++;
        else w++;
    }
    int lw = 0;
    rep(i, r) {
        if (c.at(i) == 'W') lw++;
    }
    cout << min(w, min(r, lw)) << endl;
}

Measured memory_bytes: 3624
n,m = map(int, input().split())
h = list(map(int, input().split()))
h.insert(0,0)
l = [0]*(n+1)
l[0]=1

for _ in range(m):
  a,b = map(int, input().split())
  if h[a] > h[b]:
    l[b]=1
  elif h[a] == h[b]:
    l[a]=1
    l[b]=1
  else:
    l[a]=1
else:
  print(l.count(0))
    
  

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

// ソルバー
class Abc140d {
    public:
    int solve(int n, int k, std::string s);
};

int Abc140d::solve(int n, int k, std::string s) {
    int num_rl = 0;
    int num_lr = 0;
    int ans = 0;

    char prev = s.at(0);
    for (int i=1;i<s.length();i++) {
        if (prev == s.at(i)) {
            ans ++;
        } else if (prev == 'R' && s.at(i) == 'L') {
            num_rl ++;
        } else if (prev == 'L' && s.at(i) == 'R') {
            num_lr ++;
        }
        prev = s.at(i);
    }

    int m1 = std::min(num_rl, num_lr);
    int m2 = std::max(num_rl, num_lr);

    if (k <= m1) {
        ans += 2 * k;
    } else if (m1 < k && k <= m2 ) {
        ans += m1 + k;
    } else {
        ans += m1 + m2;
    }
    return ans;
}

// 実行
int main () {
    int n, k;
    std::string s;
    std::cin >> n;
    std::cin >> k;
    std::cin >> s;

    Abc140d p;
    std::cout << p.solve(n, k, s) << std::endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
     
    int main(){
      int n;
      scanf("%d",&n);
      int l[n],r[n];
      for(int i=0;i<n;i++){
        scanf("%d %d",&l[i],&r[i]);
      }
      int count=0;
      for(int i=0;i<n;i++){
        count += (r[i] - l[i])+1;
      }
      printf("%d\n",count);
      return 0;
    }

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


int main(){
  int n,i,ans,mi;
  cin >> n;
  ans=0;
  mi=1000;
  vector<int> s(n);
  for(i=0;i<n;++i){
    cin >> s[i];
  }
  sort(s.begin(),s.end(),greater<int>());
  for(i=0;i<n;++i){
    ans=ans+s[i];
    if(s[i]%10!=0){
      mi=min(mi,s[i]);
    }
  }
  if(ans%10==0){
    if(mi==1000){
      ans=0;
    }else{
      ans=ans-mi;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	int H, W;
	cin >> H >> W;
	vector<bool> col(W, 0), row(H, 0);
	vector<string> grid(H);

	rep(i, H){
		rep(j, W){
			char a; cin >> a;
			grid[i].push_back(a);
		}
	}

	rep(i, H){
		bool ok = true;
		rep(j, W){
			if(grid[i][j] != '.') ok = false;
		}
		if(ok){
			row[i] = true;
		}
	}

	rep(j, W){
		bool ok = true;
		rep(i, H){
			if(grid[i][j] != '.') ok = false;
		}
		if(ok){
			col[j] = true;
		}
	}

	rep(i, H){
		if(row[i]) continue;
		rep(j, W){
			if(col[j]) continue;
			cout << grid[i][j];
		}
		cout << endl;
	}

	// print(grid);

	return 0;
}


Measured memory_bytes: 3604
from collections import defaultdict, deque

N, K = map(int, input().split())
A = list(map(int, input().split()))

cumA = [0] * (N + 1)
for i in range(1, N + 1):
    cumA[i] = cumA[i - 1] + A[i - 1]

cnt = defaultdict(int)
que = deque([])
ans = 0

for i, c in enumerate(cumA):
    while que and que[0][0] <= i - K:
        cnt[que.popleft()[1]] -= 1
    diff = (i - c) % K
    ans += cnt[diff]
    cnt[diff] += 1
    que.append((i, diff))
print(ans)

Measured memory_bytes: 65032
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int main(void)
{
	int i, j, n, c[502], f[502], b;
	unsigned long int s[502], ans;
	b = scanf("%d", &n);
	for(i = 1; i < n; i++){
		b = scanf("%d %lu %d", &c[i], &s[i], &f[i]);
	}
	for(i = 1; i <= n; i++){
		ans = 0;
		for(j = i; j < n; j++){
			if(ans <= s[j]){
				ans = s[j];
				ans += c[j];
			}
			else{
				if(ans % f[j] == 0){
					ans += c[j];
				}
				else{
					//ans += (ans % f[j]);
					ans = ans + f[j] - (ans%f[j]);
					ans += c[j];
				}
			}
		}
		printf("%lu\n", ans);
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
	 
const ll INF=(ll)2e18;
		
		
const int N=2e5+5;
	
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}	
		
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
				
	string s;
	cin>>s;
	ll cnt1=0,cnt2=0,ans=0;
	ll cnt=0;
	for(ll i=0;i<s.length();i++)
	{
		if(s[i]=='A')
			cnt1+=binpow(3LL,cnt,mod);
		else if(s[i]=='B')
			cnt2+=cnt1;
		else if(s[i]=='C')
			ans+=cnt2;
		else
		{
			cnt++;
			ans=(ans*3)+cnt2;	
			cnt2=(((cnt2*3))+cnt1);
			cnt1=cnt1*3;
			cnt1+=binpow(3LL,cnt-1,mod);
		}	
		cnt1%=mod;
		ans%=mod;
		cnt2%=mod;
		cnt%=mod;
		
		
			
	}
	ans%=mod;
	cout<<ans;
				
}


Measured memory_bytes: 512
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<priority_queue<ll>> v(1e5+1);
    priority_queue<P> que;
    ll ans=0;
    FOR(i,0,n){
      ll in1,in2;
      cin>>in1>>in2;
      v[in1].push(in2);
    }

    FOR(i,1,m+1){
      if(!v[i].empty()){
        que.push(P(v[i].top(), i));
        v[i].pop();
      }

      if(!que.empty()){
        P p = que.top();
        que.pop();
        ans += p.first;
//        cout<<"i = "<<i<<" "<<p.first<<endl;
        ll po = p.second;
        if(!v[po].empty()){
          que.push(P(v[po].top(), po));
          v[po].pop();
        }
      }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n;
	double h,w,bmi;
	while(scanf("%d,%lf,%lf",&n,&w,&h)!=EOF){
		bmi=w/(h*h);
		if(bmi>=25) o(n);
	}
}

Measured memory_bytes: 1232
n = int(input())
an = []
cnt = 1

for i in range(n):
  an.append(int(input()))
  
sorted_an = sorted(an, reverse=True)

for i in range(len(sorted_an)-1):
  if sorted_an[i] > sorted_an[i+1]:
    cnt += 1

print(cnt)

Measured memory_bytes: 3064
S=input()

ans=[1]*len(S)
for i in range(1,len(S)):
  if S[i-1]==S[i]=='R':
    ans[i+1]+=ans[i-1]
    ans[i-1]=0
for i in range(len(S)-2,0,-1):
  if S[i+1]==S[i]=='L':
    ans[i-1]+=ans[i+1]
    ans[i+1]=0
print(*ans)

Measured memory_bytes: 6512
program knapsack1;

uses math;

const
  fi='knapsack1.inp';
  fo='knapsack1.out';

var
  n,m: longint;
  v,w: array[0..100000] of int64;
  f:array[0..100,0..100000] of int64;

procedure nhap;
var i: longint;
begin

  read(n,m);
  for i:=1 to n do read(w[i],v[i]);

end;

procedure xuli;
var i,j: longint;
begin

  fillchar(f,sizeof(f),0);
  for i:=1 to n do begin
    for j:=1 to m do begin
      if j>=w[i] then f[i][j]:=max(f[i-1][j],f[i-1][j-w[i]]+v[i])
      else f[i][j]:=f[i-1][j];
    end;
  end;

  write(f[n][m]);

end;

begin

  //assign(input,fi);  reset(input);
  //assign(output,fo); rewrite(output);

  nhap;
  xuli;

  //close(input);      close(output);

end.


Measured memory_bytes: 79104
import sys
#import string
#from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    A = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    #word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    money = 1000
    kabu = 0
    down = 0
    up = 0
    kijun = A[0]
    for i in range(1,n):
        a = A[i]
        if i == 1:
            if kijun < a:
                buy = kijun
                katta = money//buy
                kabu += katta
                money -= katta*buy
                down = 0
                up = 1
                kijun = a
            elif kijun > a:
                down = 1
                kijun = a
        if up == 1:
            if kijun > a:
                sell = kijun
                money += sell * kabu
                kabu = 0
                up = 0
                down = 1
                kijun = a
            else:
                kijun = a
        elif down == 1:
            if kijun < a:
                buy = kijun
                katta = money//buy
                kabu += katta
                money -= katta*buy
                down = 0
                up = 1
                kijun = a
            else:
                kijun = a
        else:
            if kijun < a:
                buy = kijun
                katta = money//buy
                kabu += katta
                money -= katta*buy
                down = 0
                up = 1
                kijun = a
            elif kijun > a:
                sell = kijun
                money += sell * kabu
                kabu = 0
                up = 0
                down = 1
                kijun = a
    if kabu > 0:
        money += kabu * A[-1]
    print(money)




if __name__ == '__main__':
    solve()


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

#define int long long

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n;
	cin >> n;

	int ac = 0;
	int wa = 0;
	int tle = 0;
	int re = 0;


	while (n--) {
		string str;
		cin >> str;
		if (str == "AC") {
			ac++;
		}
		else if (str == "WA") {
			wa++;
		}
		else if (str == "TLE") {
			tle++;
		}
		else {
			re++;
		}
	}
	cout << "AC " << "x " << ac << endl;
	cout << "WA " << "x " << wa << endl;
	cout << "TLE " << "x " << tle << endl;
	cout << "RE " << "x " << re << endl;

	return 0;
}


Measured memory_bytes: 3656
import os
import sys
from collections import deque, Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


R, C, N = list(map(int, sys.stdin.buffer.readline().split()))
XY = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(N)]

# 入力と答えの制約より、もし長方形の制限がなければ任意の点まで行ける
# 長方形の辺上にある点だけ考えればいい

p1 = []
p2 = []
p3 = []
p4 = []
for i, (x1, y1, x2, y2) in enumerate(XY):
    for x, y in ((x1, y1), (x2, y2)):
        if y == 0:
            p1.append((x, i))
        elif x == R:
            p2.append((y, i))
        elif y == C:
            p3.append((x, i))
        elif x == 0:
            p4.append((y, i))
# 順番に並ぶようにする
p1.sort()
p2.sort()
p3.sort(reverse=True)
p4.sort(reverse=True)

points = p1 + p2 + p3 + p4
counts = Counter([i for _, i in points])
que = deque()
for _, i in points:
    if counts[i] <= 1:
        continue
    if que and que[-1] == i:
        que.pop()
    else:
        que.append(i)

while len(que) >= 2 and que[0] == que[-1]:
    que.popleft()
    que.pop()

ok = len(que) == 0
if ok:
    print('YES')
else:
    print('NO')


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

cnt = n
prev = a[0]
trend ='N'

for i in range(1, n):
    if a[i] > prev:
        if (trend == 'U' or trend == 'N'):
            cnt -= 1
            trend ='U'
        else:
            trend = 'N'
    if a[i] < prev:
        if (trend == 'D' or trend == 'N'):
            cnt -= 1
            trend = 'D'
        else:
            trend = 'N'
    if a[i] == prev:
        cnt -= 1
    prev = a[i]
print(cnt)

Measured memory_bytes: 19992
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double

using namespace std;

    const ll N = 1e7;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-9;



void solve(){
    string s , t;
    cin >> s >> t;
    int cnt =0 ;
    for(int i = 0; i < s.size(); ++ i){
        if(s[i] != t[i])
            cnt ++;
    }
    cout << cnt;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3764
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
static const int MAX = 10000, INFTY = (1 << 20), WHITE = 0, GRAY = 1, BLACK = 2;

int N;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
	priority_queue<pair<int, int> > PQ;
	int D[MAX], C[MAX];

	for (int i = 0; i < N; i++) {
		D[i] = INFTY;
		C[i] = WHITE;
	}

	D[0] = 0;
	PQ.push(make_pair(0, 0));
	C[0] = GRAY;
	while (!PQ.empty()) {
		pair<int, int> F = PQ.top(); PQ.pop();
		int u = F.second;
		C[u] = BLACK;

		if (D[u] < F.first * (-1)) continue;

		for (int j = 0; j < adj[u].size(); j++) {
			int v = adj[u][j].first;
			if (C[v] == BLACK) continue;
			if (D[v] > D[u] + adj[u][j].second) {
				D[v] = D[u] + adj[u][j].second;
				PQ.push(make_pair(D[v] * (-1), v));
				C[v] = GRAY;
			}
		}
	}
	for (int i = 0; i < N; i++) {
		cout << i << ' ' << (D[i] == INFTY ? -1 : D[i]) << endl;
	}
}

int main() {
	cin >> N;
	int k, c, u, v;
	for (int i = 0; i < N; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			adj[u].push_back(make_pair(v, c));
		}
	}
	dijkstra();
}


Measured memory_bytes: 8036
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,cnt,u,v,tot,ans,c[100020],head[100020],sum[3];
bool vis[100020],f;
struct edge{
	int next,v;
}node[200020];
void add(int u,int v){
	tot++;
	node[tot].v=v;
	node[tot].next=head[u];
	head[u]=tot;
}
void dfs(int u,int col){
	cnt++;
	c[u]=col;
	sum[col]++;
	vis[u]=true;
	for(int i=head[u];i;i=node[i].next){
		int v=node[i].v;
		if(!vis[v]) dfs(v,3-col);
		else if(c[u]==c[v]) f=true;
	}
}
signed main(){
	scanf("%lld%lld",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%lld%lld",&u,&v);
		add(u,v);
		add(v,u);
	}
	for(int i=1;i<=n;i++){
		if(!vis[i]){
			dfs(i,1);
			if(!f) ans+=sum[1]*sum[2];
			else ans+=(cnt-1)*cnt/2;
			sum[1]=sum[2]=cnt=f=0;
		}
	}
	printf("%lld",ans-m);
} 

Measured memory_bytes: 5632
#include<stdio.h>
int main()
{
	int sum,i;
	char a[4],c;
	sum=0;
	gets(a);
	for(i=0;i<4;i++)
	{
		c=a[i];
		switch(c)
		{
			case '+':sum=sum+1;break;
			default :sum=sum-1;
		}
	}
	printf("%d",sum);
} 

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int A,B;
    cin >> A >> B;
    if(A + B == 15)cout << "+" << endl;
    else if(A * B == 15)cout << "*" << endl;
    else                cout << "x" << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<string>

using namespace std;


int main(){
	
	char A[200] = {};
	
	cin.getline(A, 200);
	
	string B;
	
	B = A;
	
	for(int i=0;i<B.length();i++) {
		
		if ( B[i] >= 'A' && B[i] <= 'Z')
		B[i] += ' ';
		else if ( B[i] >= 'a' && B[i] <= 'z')
		B[i] -= ' ';
	}
	cout << B << "\n";
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;
const int maxn = 105;

int n, m, s = 0;
int a[maxn];

int main(void) {
    fastio;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    int cnt = 0;
    for(int i = 1; i <= n; ++i) {
        if(s <= a[i] * m * 4)   ++cnt;
    }
    cout << (cnt >= m ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int a, v, b, w, t;
  cin >> a >> v >> b >> w >> t;

  if (a > b) {
    int tmp = a;
    a = b;
    b = tmp;
  }

  if (w >= v) {
    cout << "NO" << endl;
    return 0;
  }

  int rel_v = v - w;
  int catch_up = (b - a) / rel_v;
  if ((b - a) % rel_v != 0) {
    catch_up++;
  }

  if (catch_up > t) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }

  return 0;
}


Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>//"geometry.cpp"
using namespace std;
#define pb push_back//Can be used for STRING
#define fi first
#define sc second
#define mp make_pair
#define is insert
typedef pair<int,int> pii;//Add other types in the same way.

const int n=50;

int main(){
	long long k,a[50];
	cin>>k;
	for(int i=0;i<n;++i) a[i]=(k/50)+i;
	k%=50;
	for(int i=0;i<k;++i){
		a[i]+=n;
		for(int j=0;j<n;++j) if(i!=j) a[j]-=1;
	}
	cout<<n<<endl;
	for(int i=0;i<n;++i) cout<<a[i]<<" ";
	cout<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            string s = ReadLine();
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                int tmp = 0;
                string X = s.Substring(0, i);
                string Y = s.Substring(i, n - i);
                var xh = new HashSet<char>();
                for (int j = 0; j < X.Length; j++)
                {
                    xh.Add(X[j]);
                }
                var yh = new HashSet<char>();
                for (int j = 0; j < Y.Length; j++)
                {
                    yh.Add(Y[j]);
                }
                foreach (var item in yh)
                {
                    if (xh.Contains(item))
                    {
                        tmp++;
                    }
                }
                ans = Max(ans, tmp);
            }
            WriteLine(ans);
        }

    }

}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(n), bs(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
        bs[i]=as[i];
    }
    sort(bs.begin(), bs.end());
    for(int i=0; i<n; ++i){
        if(as[i]==bs[n-1]) cout << bs[n-2] << endl;
        else cout << bs[n-1] << endl;
    }
    return 0;
}



Measured memory_bytes: 3200
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#include <map>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;


int main(void) {

  int n, m;
  cin >> n >> m;
  ll x[1010][3];
  rep(i, n) cin >> x[i][0] >> x[i][1] >> x[i][2];

  int X = 1 << 3;
  ll ans = 0;
  rep(asd, X) {
    int p[3];
    rep(i, 3) {
      if (((asd >> i) & 1) == 1) p[i] = 1;
      else p[i] = -1;
    }

    vector<ll> r(n);
    rep(i, n) {
      ll d = 0;
      rep(j, 3) d += p[j] * x[i][j];
      r[i] = d;
    }
    sort(r.begin(), r.end());
    ll res = 0;
    rep(i, m) res += r[n - 1 - i];
    ans = max(ans, res);
  }

  cout << ans << endl;

  return 0;

}
      


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

void insetrtionsort(int a[], int n);
void printarray(int n, int a[]);
void babblesort(int n, int a[]);
void selectionsort(int n, int a[]);

void insetrtionsort(int a[], int n)
{
    int j, v;
    for (int i = 1; i < n; i++)
    {
        v = a[i];
        j = i - 1;
        while (j >= 0 && a[j] > v)
        {
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for (int i = 0; i < n; i++)
        {
            cout << a[i] << " ";
        }
        cout << endl;
    }
}

void babblesort(int n, int a[])
{
    int flag = 1;
    int counter = 0;
    int tmp;
    while (flag)
    {
        flag = 0;
        for (int j = n - 1; j > 0; j--)
        {
            if (a[j] < a[j - 1])
            {
                swap(a[j], a[j - 1]);
                counter++;
                flag = 1;
            }
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void selectionsort(int n, int a[])
{
    int minj;
    int counter = 0;
    for (int i = 0; i < n; i++)
    {
        minj = i;
        for (int j = i; j < n; j++)
        {
            if (a[j] < a[minj])
                minj = j;
        }
      	if (i != minj)
        {
        swap(a[minj], a[i]);
        counter++;
        }
    }
    printarray(n, a);
    cout << counter << endl;
}

void printarray(int n, int a[])
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i];
        if (i != n - 1)
            cout << " ";
    }
    cout << endl;
}

int gcd(int a, int b)
{
    if (a < b)
    {
        int t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << endl;
    if (b == 0)
        return a;
    else
        return gcd(b, b % a);
}

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



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

using namespace std;

const int INF = 1e9;

int main() {
    int N, K; cin >> N >> K;
    vector<int> x(N); for (int i = 0; i < N; i++) cin >> x[i];

    int ans = INF;
    for (int i = 0; i <= N - K; i++) {
        int left = i;
        int right = i + K - 1;
        int cost_left = abs(x[left]) + abs(x[left] - x[right]);
        int cost_right = abs(x[right]) + abs(x[right] - x[left]);
        ans = min(ans, min(cost_left, cost_right));
    }

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

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    vector<bool> roop(n, false);
    int cnt = 0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        a[i]--;
    }
    int now = 0;
    while (1) {
        cnt++;
        int next = a[now];
        if (roop[next]) {
            cout << -1 << endl;
            return 0;
        }
        if (next == 1) {
            cout << cnt << endl;
            return 0;
        }
        roop[now] = true;
        now = next;
    }
}

Measured memory_bytes: 768
import java.util.*;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    double x = 0;
    double y = 0;

    for(int i = 0;i < n;i++){
      a[i] = sc.nextInt();
    }

    for(int i = 0;i < n;i++){
      x += 1 / (double)a[i];
    }

    y = 1 / (double)x;

    System.out.println(y);

  }

}


Measured memory_bytes: 23380