akhauriyash/Code-Regression huggingface dataset:
n = int(input())
listS = list(input())

listSeeWSum=[]
index=0
wSum=0
while index < n:
    if index==0:
        listSeeWSum.append(0)
    else:
        if listS[index-1] == "W":
            wSum+=1
        listSeeWSum.append(wSum)
    index+=1

listSeeESum=[]
listS.reverse()
index = 0
eSum = 0
while index < n:
    if index == 0:
        listSeeESum.append(0)
    else:
        if listS[index-1] == "E":
            eSum += 1
        listSeeESum.append(eSum)
    index += 1
listSeeESum.reverse()

listSum=[]
index=0
while index < n:
    listSum.append(listSeeESum[index]+listSeeWSum[index])
    index+=1

print(min(listSum))


Measured memory_bytes: 32692
num = int(input())
list = [int(i) for i in input().split()]
sum = 0
for j in range(num):
  list1 = list[:j+1]
  #print(list1)
  #print(max(list1))
  #print(list1[-1])
  if max(list1) == list1[-1]:
    sum += 1
  else:
    pass
print(sum)

Measured memory_bytes: 3064
#include <iostream> 
#include <vector>
#include <algorithm>

#define MAX_ITEMS 100

using namespace std;

long long infinity = 1e18 + 5;
long long values[MAX_ITEMS];
long long weights[MAX_ITEMS];

int main()
{
    int numberOfItems;
    long long maximumWeight, aValue, aWeight, sumOfValues = 0, answer = 0;
    cin >> numberOfItems >> maximumWeight;
    for(int i = 0; i < numberOfItems; i++)
    {
        cin >> aWeight >> aValue;
        weights[i] = aWeight;
        values[i] = aValue;
        sumOfValues += aValue;
    }

    vector<long long> dp(sumOfValues + 1, infinity); // Another way to create DPs (thanks to Errichto), this one is the minimum weightof items with value i
    dp[0] = 0;
    for(int i = 0; i < numberOfItems; i++)
    {
        for(int j = sumOfValues - values[i]; j >= 0;  j--)
            dp[j+values[i]] = min(dp[j+values[i]], dp[j] + weights[i]);
    }
    for(int i = 0; i <= sumOfValues; i++)
    {
        if(dp[i] <= maximumWeight)
            answer = max(answer, (long long) i);
    }   
    cout << answer;
}

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

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

    int ans = 0;
    for(int i = 0; i < 1000; i++){
        int z[3];
        z[0] = i / 100;
        z[1] = (i / 10) % 10;
        z[2] = i % 10;
        int flag = 0;
        for(int j = 0; j < n; j++){
            if(s[j] == ('0' + z[flag])){
                flag++;
            }

            if(flag == 3){
                break;
            }
        }

        if(flag == 3){
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
// static const ll max_n = 200010;



int main(){
    // int u, v;
    // bool updated = false;
    map<ll, ll> j_dict;
    ll N, A;
    scanf("%lld", &N);

    for(ll i=0;i<N-1;i++){
        scanf("%lld", &A);
        if(j_dict.find(A)==j_dict.end()){
            // printf("not found %lld\n", A);
            j_dict[A] = 1;
        }else{
            j_dict[A] += 1;
        }
    }

    for(ll i=1;i<=N;i++){
        if(j_dict.find(i)==j_dict.end()){
            printf("0\n");
        }else{
            printf("%lld\n", j_dict[i]);
        }
    }

    return 0;

}

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

int main() {
  //値を代入していく
  //Nを代入
  int N;
  cin >> N;
  //T,Aを代入
  int T, A;
  cin >> T >> A;
  //配列を代入
  vector<int> point(N);
  for (int i = 0; i < N; i++) {
    cin >> point.at(i);
  }
  
  //気温を計算し，Aを引き絶対値を取った配列を作る
  vector<double> temp(N);
  for (int i = 0; i < N; i++) {
    temp.at(i) = T - point.at(i) * 0.006 - A;
    if (temp.at(i) < 0) {
      temp.at(i) *= -1;
    }
  }
  
  //絶対値の最小値をもつindexをみつける
  int index = 0;
  for (int i = 1; i < N; i++) {
    if (temp.at(index) >= temp.at(i)) {
      index = i;
    }
  }
  
  cout << index + 1 << endl;
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; i++) cin >> v[i];
    for (int i = 0; i < N; i++) v[i]--;

    int cur = 0;
    int ne;
    for (int i = 0; i < N; i++) {
        ne = v[cur];
        if (ne == 1) {
            cout << i + 1 << '\n';
            return 0;
        }
        cur = ne;
    }
    cout << -1 << '\n';
}


Measured memory_bytes: 640
import sys
sys.setrecursionlimit(10**7)

x,y,a,b,c= map(int,input().split())

pi = [int(i) for i in input().split()]
qi = [int(i) for i in input().split()]
ri = [int(i) for i in input().split()]

pi.sort(reverse=True)
qi.sort(reverse=True)
ri.sort(reverse=True)

import heapq
"""
a = [3,0,2,6]
#listのheap化
#heapはsortではないので順番は割とあべこべになる。最小値は先頭
heapq.heapify(a)
print(a)

#挿入
heapq.heappush(a,3)
print(a)

#最小値を削除&出力
print(heapq.heappop(a))
print(a)
"""
apple = []

for i in range(x):
    heapq.heappush(apple,pi[i])
    
for i in range(y):
    heapq.heappush(apple,qi[i])
    
for i in range(c):
    tmp = heapq.heappop(apple)
    if tmp < ri[i]:
        heapq.heappush(apple,ri[i])
    else:
        heapq.heappush(apple,tmp)
        
print(sum(apple))

Measured memory_bytes: 22592
import sys
sys.setrecursionlimit(100000)

N=int(input())
edges=[[] for _ in range(N)]
for _ in range(N-1):
    A,B=map(int,input().split())
    edges[A-1].append(B-1)
    edges[B-1].append(A-1)
prevs=[0]*N
def dfs(prev,curr):
    prevs[curr]=prev
    if curr == N-1:
        return
    for c in edges[curr]:
        if c!=prev:
            dfs(curr,c)
dfs(-1,0)
paths=[N-1]
tmp=N-1
while tmp!=0:
    paths.append(prevs[tmp])
    tmp=prevs[tmp]
paths=paths[::-1]

points=[0,0]
def count(prev,curr,player):
    points[player]+=1
    for c in edges[curr]:
        if c!=prev:
            count(curr,c,player)

nf = (len(paths)+1)//2
f,s = paths[nf-1],paths[nf]
count(s,f,0)
count(f,s,1)
pf,ps=points
print("Fennec" if pf>ps else "Snuke")


Measured memory_bytes: 180896
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,0,n) cin >> a[i];
    int lo = 1;
    int hi = 1e9+5;
    while(lo<hi) {
        int mid = lo+(hi-lo)/2;
        vector<pair<int,int>> digits;
        int len = 0;
        bool bad = false;
        rep(i,0,n) {
            if(len>=a[i]) {
                if(mid==1) {
                    bad = true;
                    break;
                }
                while(!digits.empty() && digits.back().first>=a[i]) digits.pop_back();
                int j = a[i]-1;
                while(j>=0) {
                    if(mid>1 && (digits.empty() || digits.back().first<j)) {
                        digits.emplace_back(j,1);
                        break;
                    }
                    else if(!digits.empty() && digits.back().second+1<mid) {
                        ++digits.back().second;
                        break;
                    }
                    else {
                        if(!digits.empty()) digits.pop_back();
                        --j;
                    }
                }
                if(j<0) bad = true;
            }
            len = a[i];
            if(bad) break;
        }
        if(bad) lo = mid+1;
        else hi = mid;
    }
    cout<<lo<<"\n";
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
 
#define int long long int
#define pi pair<int, int>
#define fi first
#define se second
#define speed ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define endl '\n'
 
const int N = 3e3 + 5;
const int M = 2e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;

int power(int a, int b){
	int ans = 1;
	while(b){
		if(b&1)
			ans = (ans * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ans;
}

int f[M], invf[M], p[N], q[N];
pi a[N];
int dp[N];

int path(int x1, int y1, int x2, int y2){
	int x = x2 - x1;
	int y = y2 - y1;
	int res = f[x+y];
	res = (res * invf[x]) % mod;
	res = (res * invf[y]) % mod;
	return res;
}

signed main() {
	speed;
	f[0] = 1;
	for(int i = 1; i < M; i++)
		f[i] = (i * f[i-1]) % mod;
	invf[M-1] = power(f[M-1], mod-2) % mod;
	for(int i = M-2; i >= 0; i--)
		invf[i] = ((i+1) * invf[i+1]) % mod;
	int h, w, n;
	cin >> h >> w >> n;	
	map<int, int> x, y;
	for(int i = 1; i <= n; i++){
		cin >> a[i].fi >> a[i].se;
		x[a[i].fi] = 1;
		y[a[i].se] = 1;
	}
	a[0].fi = 1;	a[0].se = 1;
	a[n+1].fi = h;	a[n+1].se = w;
	x[1] = 1;	x[h] = 1;
	y[1] = 1;	y[w] = 1;
	int pp = 0;
	for(auto &i: x){
		pp += i.se;
		p[pp] = i.fi;
		i.se = pp;
	}
	pp = 0;
	for(auto &i: y){
		pp += i.se;
		q[pp] = i.fi;
		i.se = pp;
	}
	for(int i = 0; i <= n+1; i++){
		a[i].fi = x[a[i].fi];
		a[i].se = y[a[i].se];
	}
	sort(a + 1, a + n + 1);

	for(int i = 1; i <= n+1; i++){
		dp[i] = path(1, 1, p[a[i].fi], q[a[i].se]);
		for(int j = 1; j < i; j++){
			int x1 = a[j].fi, y1 = a[j].se;
			int x2 = a[i].fi, y2 = a[i].se;
			if(x1 <= x2 && y1 <= y2){
				dp[i] -= (dp[j]*path(p[x1], q[y1], p[x2], q[y2])) % mod;
				dp[i] = (dp[i] + mod*mod) % mod;;
			}
		}
	}
	cout << dp[n+1];
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;

template <class T>
T gcd(T a, T b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool solve(int N, vector<ll>& A) {
    ll sum = accumulate(A.begin(), A.end(), 0LL);

    // Nが偶数の場合、和の偶奇がそのまま勝敗になる
    if (N % 2 == 0) return sum % 2 != 0;

    // Nが奇数の場合も、和が偶数なら絶対勝てる
    if (sum % 2 == 0) return true;

    // 奇数を前に持っていく
    sort(A.begin(), A.end(), [](int a, int b) { return a % 2 > b % 2; });
    // 奇数が複数個ある、あるいは唯一の奇数が1(減らせない)なら負け
    if (A[0] == 1 || (A[1] & 1) != 0) return false;

    // そうでなければ、唯一の奇数を減らしてシミュレート
    --A[0];
    int g = accumulate(A.begin(), A.end(), 0LL, gcd<ll>);
    for (auto& a : A) a /= g;
    return !solve(N, A);
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (auto& a : A) cin >> a;
    cout << (solve(N, A) ? "First" : "Second") << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int k = scan.nextInt();
        int num = 1;
        for (int i = 0; i < n; i++) {
            if (num < k) {
                num *= 2;
            } else {
                num += k;
            }
        }
        System.out.println(num);
    }
}

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

int main() {
  int h,w;
  cin >> h >> w;
  
  string s;
  for(int i=0; i<w+2; i++)
    cout << "#";
  cout << endl;
  for(int i=0; i<h; i++) {
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  for(int i=0; i<w+2; i++)
    cout << "#";
    cout << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import collections


class Node(object):

  def __init__(self):
    self.edges = []


class Edge(object):

  def __init__(self):
    self.color = -1


def main():
  nodes = [Node() for _ in range(int(input()))]
  edges = [Edge() for _ in range(len(nodes) - 1)]

  for i in range(len(nodes) - 1):
    a, b = map(lambda x: int(x) - 1, input().split())
    nodes[a].edges.append((edges[i], nodes[b]))
    nodes[b].edges.append((edges[i], nodes[a]))

  queue = collections.deque()
  node = nodes[0]

  for i in range(len(node.edges)):
    node.edges[i][0].color = i
    queue.append(node.edges[i][1])

  max_color = len(node.edges) - 1

  while len(queue) != 0:
    node = queue.popleft()
    exist = -1
    index = 0

    for i in range(len(node.edges)):
      if node.edges[i][0].color != -1:
        exist = node.edges[i][0].color
        break

    for i in range(len(node.edges)):
      if index == exist:
        index += 1

      if node.edges[i][0].color != -1:
        continue

      node.edges[i][0].color = index
      index += 1
      queue.append(node.edges[i][1])

    max_color = max(len(node.edges) - 1, max_color)

  print(max_color + 1)
  for e in edges:
    print(e.color + 1)


if __name__ == '__main__':
  main()


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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define f(i,a,b) for(ll i=a;i<b;i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define en '\n'
ll n;
bool func(ll k)
{
    int o=0,z=0;
    while(k!=0)
    {
        if(k%2==1)
            o++;
        else
            z++;
        k/=2;
    }
    if(o==z && o==n)
        return 1;
    else
        return 0;
}
int main()
{
	IOS;
	int t=1;
	//cin>>t;
	while(t--)
	{
       int n,k,p;

       cin>>n>>k;
       f(i,0,n)
       cin>>p;
       int l=0,r=k;
       ll c=1;
       while(r!=n)
       {
           c++;
           l=r;
           r=l+k-1;
           if(r>n)
            r=n;
       }
       cout<<c;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

typedef long long int ll;

int main()
{
// 入力

	int n;
	cin >> n;
	int b;

// 処理

	int sum = 0, prev = 1000000;
	REP(i, n - 1) 
	{
		cin >> b;
		sum += min(prev, b);
		prev = b;
	}
	sum += prev;

// 出力

	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<time.h>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<ll> >;//ll or Edge
using Edge=pair<int,ll>;
//const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// g++ -o a a.cpp -Wall -lm -std=c++14

int main(){
    ll n;ll a[101];cin>>n;rep(i,n)cin>>a[i];
    int ans=0;
    rep(i,n){
        if((i+1)%2 && a[i]%2){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define repc2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    char c;
    cin >> c;
    if ('A' <= c && c <= 'Z') {
        cout << 'A' << endl;
    } else {
        cout << 'a' << endl;
    }

    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct {
	char s[11];
	int p;
	int no;
} data;
int cmpstr(const void *x, const void *y) {
	int res = strcmp(((data *)x)->s, ((data *)y)->s);
	if (res == 0)
		return ((data *)y)->p - ((data *)x)->p;
	else
		return res;
}
int main() {
	int n;
	data d[100];
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s%d", d[i].s, &d[i].p);
		d[i].no = i + 1;
	}
	qsort(d, n, sizeof(data), cmpstr);
	for (int i = 0; i < n; i++) {
		printf("%d\n", d[i].no);
	}
	return 0;
}

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

const int mod = 1000000007;
//const int mod = 998244353;
const int INF = 1001001001;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];
    ll cnt = 0;
    rep(i, 0, n){
        while(a[i]%2 == 0){
            a[i] /= 2;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

#define MAX 2000

using namespace std;


int M,N,now,mx=0;
int s[MAX+1],t[MAX+1];
int dp[MAX+1][MAX+1][2];

int main(){
	scanf("%d %d",&M,&N);
	string st;
	s[M]=-1;
	t[N]=-1;
	cin>>st;
	for(int i=0;i<M;i++){
		s[i]=(st[i]=='I' ? 1:0);
	}
	cin>>st;
	for(int i=0;i<N;i++){
		t[i]=(st[i]=='I' ? 1:0);
	}
	for(int i=M;i>=0;i--){
		for(int j=N;j>=0;j--){
			if(s[i]==0&&t[j]==0)
			now=max(dp[i+1][j][1]+1,dp[i][j+1][1]+1);
			else if(s[i]==0)
			now=dp[i+1][j][1]+1;
			else if(t[j]==0)
			now=dp[i][j+1][1]+1;
			else
			now=0;
			dp[i][j][0]=now;
			//
			if(s[i]==1&&t[j]==1)
			now=max(dp[i+1][j][0]+1,dp[i][j+1][0]+1);
			else if(s[i]==1)
			now=dp[i+1][j][0]+1;
			else if(t[j]==1)
			now=dp[i][j+1][0]+1;
			else
			now=0;
			dp[i][j][1]=now;
		}
	}
	for(int i=0;i<M;i++){
		for(int j=0;j<N;j++){
			if(dp[i][j][1]%2!=0)
			mx=max(dp[i][j][1],mx);
			else
			mx=max(dp[i][j][1]-1,mx);
		}
	}
	printf("%d\n",mx);
}

Measured memory_bytes: 34616
#include <bits/stdc++.h>
//For ordered_set
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define init(arr, val) memset(arr, val, sizeof(arr))
#define loop(i, a, b) for (int i = a; i < b; i++)
#define loopr(i, a, b) for (int i = a; i >= b; i--)
#define loops(i, a, b, step) for (int i = a; i < b; i += step)
#define looprs(i, a, b, step) for (int i = a; i >= b; i -= step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb push_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie();                        \
    cout.tie();
#define FILE_READ_IN freopen("input.txt", "r", stdin);
#define FILE_READ_OUT freopen("output.txt", "w", stdout);
#define all(a) a.begin(), a.end()
using namespace std;
// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll maxn = 1e5;
const ll inf = 1e9;
const double pi = acos(-1);

void solve()
{
    ll n, k;
    cin >> k >> n;
    ll arr[n], sum = 0;
    for (int i = 0; i < n; i++)
        cin >> arr[i],  sum += arr[i];
    if(sum >= k)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    
}

int main()
{
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
# Your code here!

n = int(input())

X = list(map(int, input().split()))
Y = list(map(int, input().split()))

D1 = 0
D2 = 0
D3 = 0
max = 0
for i in range(n):
   diff = abs(X[i] - Y[i])
   D1 += diff
   D2 += diff**2
   D3 += diff**3
   if diff > max:
      max = diff

print('{:.6f}'.format(D1))
print(D2**(1 / 2))
print(D3**(1.0 / 3.0))
print('{:.6f}'.format(max))


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

int main() {
    ll n;
    std::cin >> n;
    string s;
    std::cin >> s;
    ll cnt = 0;
    for (int i = 0; i < n; i++) {
        if(s[i]=='1'){
            cnt++;
        }
    }
    if(cnt==0){
        for (int i = 0; i < n; i++) {
            std::cout << 1 << std::endl;
        }
        return 0;
    }

    ll def0 = 0;
    ll def2 = 0;
    vector<ll> ima0(n,1);
    vector<ll> ima2(n,1);
    
    for (int i = 0; i < n; i++) {
        if(s[n-1-i]=='1'){
            def0 += ima0[i];
            if(cnt!=1)def0 %= cnt-1;
            def2 += ima2[i];
            def2 %= cnt+1;
        }
        if(cnt!=1)if(i<n-1)ima0[i+1] = ima0[i]*2 % (cnt-1);
        if(i<n-1)ima2[i+1] = ima2[i]*2 % (cnt+1);
    }

    for (int i = 0; i < n; i++) {
        ll osae = 0;
        if(s[i]=='1'){
            if(cnt!=1)osae = (def0 - ima0[n-1-i] + cnt-1)%(cnt-1);
            if(cnt==1){
                std::cout << 0 << std::endl;
                continue;
            }
        }else{
            osae = (def2 + ima2[n-1-i] + cnt+1)%(cnt+1);
        }
        
        ll ans = 1;
        while(osae!=0){
            ans++;
            osae = osae%__builtin_popcount(osae);
        }
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 6812
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = int.Parse(Console.ReadLine());
        Console.WriteLine(6 - n - a);
    }
}

Measured memory_bytes: 27540
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;
typedef struct { int x, y; } P;
typedef tuple<int, int, int> TPL;

int main()
{
    int w, h, n; cin >> w >> h >> n;
    int st_x, st_y, ed_x, ed_y;
    cin >> st_x >> st_y >> ed_x >> ed_y;
    int cost[510][510][4];
    fill(cost[0][0], cost[509][509]+4, 1<<29);
    loop (w+1, i) loop (h+1, j) loop (4, k) cost[i][j][k] = 0;

    while (n--) {
        int x, y, t; cin >> x >> y >> t;
        string pat; cin >> pat;
        while (t--) {
            for (char c : pat) {
                if (c == 'L' && x-1 >= 0) {
                    cost[x][y][3]++;
                    cost[x][y+1][1]++;
                    x--;
                }
                if (c == 'U' && y-1 >= 0) {
                    cost[x][y][2]++;
                    cost[x+1][y][0]++;
                    y--;
                }
                if (c == 'R' && x+1 < w) {
                    cost[x+1][y][3]++;
                    cost[x+1][y+1][1]++;
                    x++;
                }
                if (c == 'D' && y+1 < h) {
                    cost[x][y+1][2]++;
                    cost[x+1][y+1][0]++;
                    y++;
                }
            }
        }
    }

    priority_queue<TPL, vector<TPL>, greater<TPL>> Q;
    int vis[510][510] = {};
    Q.push(TPL{ 0, st_x, st_y });
    P dirs[] = { {-1, 0}, {0, -1}, {1, 0}, {0, 1} };
    while (Q.size()) {
        auto top = Q.top(); Q.pop();
        int crr_cost = get<0>(top), crr_x = get<1>(top), crr_y = get<2>(top);
        if (vis[crr_x][crr_y]) continue;
        if (crr_x == ed_x && crr_y == ed_y) {
            cout << crr_cost << endl;
            return 0;
        }
        vis[crr_x][crr_y] = 1;
        loop (4, i) {
            int nxt_x = crr_x + dirs[i].x;
            int nxt_y = crr_y + dirs[i].y;
            if (nxt_x >= 0 && nxt_x <= w && nxt_y >= 0 && nxt_y <= h) {
                Q.push(TPL{
                        crr_cost + cost[crr_x][crr_y][i],
                        nxt_x,
                        nxt_y
                        });
            }
        }
    }
    return 0;
}

Measured memory_bytes: 14184
#include <stdio.h>
#include <string.h>

int main (void){
  char s[10],t[10];
  int a,b;
  char u[10];
  scanf("%s%s%d%d%s",s,t,&a,&b,u);
  if(strcmp(s,u)==0){
    printf("%d %d\n",a-1,b);
  }else{
    printf("%d %d\n",a,b-1);
  }

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <queue>

using namespace std;

int n, m;
std::priority_queue<int> pq;

int main()
{
	int i;
	scanf("%d %d", &n, &m);

	for (i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		pq.push(x);
	}

	for (i = 0; i < m; i++) {
		int price = pq.top(); pq.pop();
		price /= 2;
		pq.push(price);
	}
	long long ans = 0;

	for (i = 0; i < n; i++) {
		ans += pq.top(); pq.pop();
	}

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

	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int n,m;
map<ll,ll> edges[1005];
ll score[1005];

int main()
{
    cin >> n >> m;
    rep(i, n) score[i] = -infl;
    rep(i,m){
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        edges[a][b] = c;
    }
    score[0] = 0;
    queue<pair<ll, set<ll>>> check;
    set<ll> visited;
    check.push(mp(0, visited));
    while (!(check.empty())){
        pair<ll, set<ll>> p = check.front();
        check.pop();
        ll now = p.F;
        visited = p.S;
        for (auto q:edges[now]){
            ll nex = q.F;
            ll d = q.S;
            if (score[nex]==infl){
                continue;
            }
            if (score[nex]<score[now]+d){
                if (score[now]==infl){
                    score[nex] = infl;
                    visited.insert(nex);
                    check.push(mp(nex, visited));
                }
                else if (visited.count(nex)){
                    score[nex] = infl;
                    check.push(mp(nex, visited));
                }
                else {
                    score[nex] = score[now] + d;
                    visited.insert(nex);
                    check.push(mp(nex, visited));
                }
            }
        }
    }
    if (score[n-1]==infl)
        cout << "inf" << endl;
    else 
    cout << score[n - 1] << endl;
}


Measured memory_bytes: 1024
object Main{
  def main(args:Array[String]){
    val sc=new java.util.Scanner(System.in)
    val b=new scala.util.control.Breaks
    b.breakable{
      while(true){
        val m,f,r=sc.nextInt()
        if(m== -1&&f== -1&&r== -1) b.break
        if(m== -1||f== -1) println("F")
        else if(m+f>=80) println("A")
        else if(m+f>=65) println("B")
        else if(m+f>=50||m+f>=30&&r>=50) println("C")
        else if(m+f>=30) println("D")
        else println("F")
      }
    }
  }
}

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

using ll = long long;
using i128 = __int128_t;

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int A, B;
	cin >> A >> B;
	int k;
	cin >> k;
	vector<pair<int,int> > pts(k);
	set<int> verts_x, verts_y;
	verts_x.insert(0); verts_x.insert(A);
	verts_y.insert(0); verts_y.insert(B);
	for(pair<int,int>& p : pts){
		cin >> p.first >> p.second;
		for(int j = 0; j <= 1; j++) verts_x.insert(p.first + j);
		for(int j = 0; j <= 1; j++) verts_y.insert(p.second + j);
	}
	vector<int> loc_x, loc_y;
	for(int x : verts_x) loc_x.push_back(x);
	for(int y : verts_y) loc_y.push_back(y);
	int num_x = (int)loc_x.size() - 1;
	int num_y = (int)loc_y.size() - 1;
	vector<vector<bool> > occ(num_x, vector<bool>(num_y, false));
	for(int i = 0; i < num_x; i++){
		for(int j = 0; j < num_y; j++){
			for(pair<int,int> p : pts){
				if(loc_x[i] == p.first && loc_y[j] == p.second) occ[i][j] = true;
			}
		}
	}

	i128 ans = 0;
	vector<int> dx = {1, 0, -1, 0};
	vector<int> dy = {0, 1, 0, -1};
	for(int x = 0; x < num_x; x++){
		for(int y = 0; y < num_y; y++){
			if(occ[x][y]) continue;
			vector<vector<int> > dist(num_x, vector<int>(num_y, 1e9));
			vector<pair<int,int> > bfs;
			dist[x][y] = 0;
			bfs.push_back({x, y});
			int s = 0;
			while(s < (int)bfs.size()){
				int cx = bfs[s].first;
				int cy = bfs[s].second;
				s++;
				for(int d = 0; d < 4; d++){
					int nx = cx + dx[d];
					int ny = cy + dy[d];
					if(nx < 0 || ny < 0 || nx >= num_x || ny >= num_y) continue;
					if(occ[nx][ny]) continue;
					int new_dist = dist[cx][cy] + 1;
					if(new_dist < dist[nx][ny]){
						dist[nx][ny] = new_dist;
						bfs.push_back({nx, ny});
					}
				}
			}
			for(int nx = 0; nx < num_x; nx++){
				for(int ny = 0; ny < num_y; ny++){
					if(occ[nx][ny]) continue;
					i128 dx0 = loc_x[x + 1] - loc_x[x];
					i128 dy0 = loc_y[y + 1] - loc_y[y];
					i128 dx1 = loc_x[nx + 1] - loc_x[nx];
					i128 dy1 = loc_y[ny + 1] - loc_y[ny];
					if((x == nx && dx0 > 1) || (y == ny && dy0 > 1)){
						// can travel by manhattan distance
						i128 xdist = (x == nx) ? ((dx0 * dx0 * dx0 - dx0) / 3) : 
							dx0 * dx1 * abs(loc_x[nx + 1] + loc_x[nx] - loc_x[x + 1] - loc_x[x]) / 2;
						xdist *= dy0 * dy1;
						i128 ydist = (y == ny) ? ((dy0 * dy0 * dy0 - dy0) / 3) : 
							dy0 * dy1 * abs(loc_y[ny + 1] + loc_y[ny] - loc_y[y + 1] - loc_y[y]) / 2;
						ydist *= dx0 * dx1;
						ans += xdist + ydist;
					} else {
						i128 real_dist = dist[nx][ny] + abs(loc_x[nx] - loc_x[x]) - abs(nx - x) 
														+ abs(loc_y[ny] - loc_y[y]) - abs(ny - y);
						i128 twice_avg = 2 * i128(real_dist)
							+ abs(loc_x[nx + 1] + loc_x[nx] - loc_x[x + 1] - loc_x[x]) - 2 * abs(loc_x[nx] - loc_x[x])
							+ abs(loc_y[ny + 1] + loc_y[ny] - loc_y[y + 1] - loc_y[y]) - 2 * abs(loc_y[ny] - loc_y[y]);
						ans += twice_avg * dx0 * dy0 * dx1 * dy1 / 2;
					}
				}
			}
		}
	}
	ll ans_mod = (ans / 2) % (int(1e9) + 7);
	cout << ans_mod << '\n';
}

Measured memory_bytes: 512
n,m = map(int, input().split())
h = [int(_) for _ in input().split()]
l=['good']*n
for x in range(m):
    a,b = map(int, input().split())
    if h[a - 1] > h[b - 1]:
        l[b - 1] = ''
    elif h[b - 1] > h[a - 1]:
        l[a - 1] = ''
    else:
        l[a-1],l[b-1]='',''

print(l.count('good'))
        

Measured memory_bytes: 20116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    int n; cin >> n;
    string s; cin >> s;
    int ans = 0;
    rep(i,1000){
        string tmp = "";
        if(i < 10) tmp += "00";
        else if(i < 100) tmp += "0";
        tmp += to_string(i);
        int id1 = 300000,id3 = -1;
        bool ok = false;
        rep(j,n){
            if(s[j] == tmp[0]){
                id1 = j;
                break;
            }
        }
        for(int j = n-1; j >= 0; j--){
            if(s[j] == tmp[2]){
                id3 = j;
                break;
            }
        }
        rep(j,n){
            if(s[j] == tmp[1] && id1 < j && j < id3){
                ok = true;
                break;
            }
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3752
#include <stdio.h>

int binarySearch(int A[], int n, int key)
{
  int left = 0;
  int right = n;
  int mid;

  while (left < right)
  {
    mid = (left + right) / 2;
    if (key == A[mid])
    {
      return mid;
    }
    if (key > A[mid])
    {
      left = mid + 1;
    }
    else if (key < A[mid])
    {
      right = mid;
    }
  }

  return -1;
}

int main()
{
  int A[1000000];
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
  {
    scanf("%d", &A[i]);
  }

  int q;
  scanf("%d", &q);
  int t;
  int sum = 0;
  for (int i = 0; i < q; i++)
  {
    scanf("%d", &t);
    if (binarySearch(A, n, t) != -1)
    {
      sum++;
    }
  }

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

  return 0;
}


Measured memory_bytes: 2984
def solve(ABCD):
    for i in range(0, 8):
        ops = "{:03b}".format(i)
        op1 = "+" if ops[0] == "0" else "-"
        op2 = "+" if ops[1] == "0" else "-"
        op3 = "+" if ops[2] == "0" else "-"
        s = ABCD[0] + op1 + ABCD[1] + op2 + ABCD[2] + op3 + ABCD[3]
        if eval(s) == 7:
            return s + "=7"
    return "error"


if __name__ == "__main__":
    ABCD = input()
    print(solve(ABCD))


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <algorithm>

typedef long long ll;
#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

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



#define MOD 998244353
#define PI 3.14159265359


int main()
{
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	cout.precision(15);
	double time = h  + m / 60.0;
	double rad =  2 * PI * m / 60.0 - 2 * PI *  1 / 12.0 * time;
	cout << sqrt(a * a + b*b - 2 * a * b * cos(rad) )<< endl;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string s;
    cin >> s;

    deque<char>  A;
    REP(i, s.length()){
        if(s[i] == 'B'){
            if(!A.empty()){
                A.pop_back();
            }
        }
        if(s[i] == '0'){
            A.push_back('0');
        }
        if(s[i] == '1'){
            A.push_back('1');
        }
    }

    while(!A.empty()){
        cout << A.front();
        A.pop_front();
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n,t=1;
ll ans=0;
vector<vector<int>> G;
vector<int> c;

vector<int> d;

void dfs(int s){
    rep(i,G[s].size()){
        if (d[G[s][i]]!=-1) continue;
        d[G[s][i]]=t;
        t+=1;
        dfs(G[s][i]);
    }
}

void solve(){
    cin >> n;
    G.resize(n,{});
    c.resize(n,0);
    d.resize(n,-1);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    rep(i,n){
        cin >> c[i];
    }
    sort(c.begin(),c.end(),greater<int>());
    rep(i,n-1) ans+=c[i+1];
    d[0]=0;
    dfs(0);
    cout << ans << endl;
    rep(i,n) cout << c[d[i]] << " ";
}

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

Measured memory_bytes: 1280
#include <string>
#include <vector>
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////

//cf: 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);  
    #endif

	int a, b, c;
	cin >> a >> b >> c;
	string ans = (a+b+c)>=22 ? "bust" : "win";
	cout << ans;
        
    #ifndef ONLINE_JUDGE   
    //cout << endl << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    #endif
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}

ll N;
vector<string> A;
vector<int> col;
vector<int> dist;
bool jd=true;

void dfs(int u){
  for(int v=0;v<N;v++){
    if(A[u][v]!='1'){continue;}
    if(col[v]!=0){
      jd&= col[v]==col[u]*-1;
    }
    else{
      col[v]=col[u]*-1;
      dfs(v);
    }
  }
}

ll bfs(int u){
  for(int i=0;i<N;i++){dist[i]=MOD;}
  dist[u]=0;
  queue<int> Q;
  Q.push(u);
  while(!Q.empty()){
    int v=Q.front(); Q.pop();
    for(int nx=0;nx<N;nx++){
      if(A[v][nx]=='1' && dist[nx]>dist[v]+1){
        dist[nx]=dist[v]+1;
        Q.push(nx);
      }
    }
  }
  ll ret=0;
  for(int i=0;i<N;i++){ret=max<ll>(ret,dist[i]);}
  return ret;
}


int main(){
  cin>>N;
  A.resize(N);
  cin>>A;
  col.resize(N,0);
  dist.resize(N);
  col[0]=1;
  dfs(0);
  if(jd){
    ll ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,bfs(i)+1);
    }
    cout<<ans<<endl;
  }
  else{
    cout<<-1<<endl;
  }


  return 0;
}


Measured memory_bytes: 256
S = input()
ans = 'Yes'
for i in range(len(S)):
    if (i+1)%2==1:
        if S[i:i+1] not in ['R', 'U', 'D']:
            ans = 'No'
            break
    else:
        if S[i:i+1] not in ['L', 'U', 'D']:
            ans = 'No'
            break
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
long long int MOD = 1000000000 + 7;
using ll = long long;


int main() {
	ll K, X;
	cin >> K >> X;
	if (K * 500 >= X) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)


def union(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return
    parent[x] = y


def find(x):
    if parent[x] == -1:
        return x
    res = parent[x] = find(parent[x])
    return res




N, M = map(int, input().split())
parent = [-1] * N
for _ in range(M):
    A, B = map(int, input().split())
    union(A - 1, B - 1)

groups = set()
for i in range(N):
    groups.add(find(i))
print(len(groups) - 1)

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

int popcount(int n){
    int res = 0;
    while(n){
        if(n & 1) res++;
        n = n >> 1;
    }
    return res;
}

int func(int n){
    if(n == 0) return 0;
    return func(n % popcount(n)) + 1;
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int pc = 0;
    vector<bool> x(n);
    for(int i = 0; i < n; i++){
        if(s[i] == '1') pc++;
        x[i] = s[i] - '0';
    }
    vector<int> ans(n);
    for(int i = 0; i < 2; i++){
        int npc = pc+1;
        if(i) npc = pc-1;
        if(npc <= 0) continue;
        int num = 0;
        for(int j = 0; j < n; j++){
            num = 2 * num % npc;
            if(x[j] == 1) num += 1;
        }
        int k = npc - pc;
        for(int j = n-1; j >= 0; j--){
            if(x[j] == i){
                ans[j] = func(((num + k) % npc + npc) % npc) + 1;
            }
            k = 2 * k % npc;
        }
    }
    for(auto a : ans) cout << a << endl;
    return 0;
}

Measured memory_bytes: 4456
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func convertInt(str string) int {
	num, e := strconv.Atoi(str)
	if e != nil {
		panic(e)
	}
	return num
}

func main() {
	sc.Split(bufio.ScanWords)
	a, b := nextLine(), nextLine()
	mul := convertInt(a) * convertInt(b)
	if mul%2 == 1 {
		fmt.Println("Odd")
	} else {
		fmt.Println("Even")
	}
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;

int main(){
		int K;
		string n;
		cin >> n;
		cin >> K;
		int count = 0;
		for(int i=0;i<n.length();i++){
				if(K == count) break;
				count++;
				if(n[i]!= '1'){
						cout << n[i] << endl;
						return 0;
				}
		}
		cout << 1 << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    ll n, k;
    cin >> n >> k;
    long double ans = 0;
    for (int i = 1; i <= n; i++)
    {
        ll hoge = i;
        ll cnt = 0;
        while (hoge < k)
        {
            hoge *= 2;
            cnt++;
        }
        ll tmp = n * pow(2, cnt);
        ans += (long double)1 / (long double)tmp;
    }
    cout << setprecision(12) << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  char wday[9],time[9];
  for(int s,n,t,p,m;cin>>s>>n>>t>>wday>>time>>p>>m,s;){
    int hod=24*60;
    double mp=0;
    for(int icm=0;icm<24*60;icm++){
      int cm=icm;
      double fp=1;
      int md=(wday[0]=='A')?7:1;
      int mt=(time[0]=='A')?hod:hod/2;
      for(int j=0;j<m;j++){
	bool f=false;
	for(int i=0;i<=s;i++){
	  int nm=cm+i;
	  int mod=nm%hod;
	  if(nm/hod%7<md){
	    if(wday[0]!='A'&&time[0]=='N'){
	      f|=!(mod<6*60||18*60<=mod);
	    }else{
	      f|=!(mod<mt);
	    }
	  }else{
	    f=true;
	  }
	}
	if(!f){
	  fp*=pow(1-1./p,n);
	}
	mp=max(mp,1-fp);
	cm+=t;
      }
    }
    cout.precision(9);
    cout<<fixed<<mp<<endl;
  }
}

      

Measured memory_bytes: 1284
#include <stdio.h>
#include <string.h>

int main(void){
  int account = 0;
  int wacount = 0;
  int tlecount = 0;
  int recount = 0;
  int n;

  scanf("%d", &n);

  for(int i=0; i<n; i++){
    char str[256];
    scanf("%s", str);
    
    if(!strcmp(str, "AC")){
      account ++;
    }
    if(!strcmp(str, "WA")){
      wacount ++;
    }
    if(!strcmp(str, "TLE")){
      tlecount ++;
    }
    if(!strcmp(str, "RE")){
      recount ++;
    }
  }

  printf("AC x %d\n", account);
  printf("WA x %d\n", wacount);
  printf("TLE x %d\n", tlecount);
  printf("RE x %d\n", recount);
}


Measured memory_bytes: 1688
#include<iostream>

long long n, k,res;

long long sum(long long min,long long max){
	return (min + max) * (max - min + 1) / 2;
}

int main() {

	std::cin >> n >> k;

	for (int i = k; i <= n+1; i++) {
		res += sum(n-i+1,n) - sum(0,i-1)+1;
		res %= 1000000007;
	}

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

	return 0;
}

Measured memory_bytes: 3604