akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())



void init() {

}

void input() {

}

void solve() {
  int a, b, c;
  scanf("%d/%d/%d", &a, &b, &c);
  if (b <= 4) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}

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


Measured memory_bytes: 256
n,m = gets.chomp.split(" ").map(&:to_i)
p = n.times.map{gets.chomp.split(" ").map(&:to_i)}
ans = 0
for s in 0..7
  i,j,k = (-1)**(s%2),(-1)**(s/2%2),(-1)**(s/2/2%2)
  p = p.sort_by{|x,y,z|x*i+y*j+z*k}
  x,y,z = 0,0,0
  for l in 0..m-1
    x += p[l][0]
    y += p[l][1]
    z += p[l][2]
  end
  ans = [ans,x.abs+y.abs+z.abs].max
end
puts ans

Measured memory_bytes: 2040
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N, K; cin >> N >> K;

    vector<ll> nmods(K, 0);
    rep(i, 1, N+1) nmods[i%K]++;

    ll res = 0;
    res += nmods[0] * nmods[0] * nmods[0];
    if (K%2 == 0) res += nmods[K/2] * nmods[K/2] * nmods[K/2];

    cout << res << endl;
}

Measured memory_bytes: 1792
from collections import Counter,defaultdict

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

if N%2 == 0:
    a = defaultdict(int)
    for i,j in zip(c.keys(),c.values()):
        a[i] = j
    
    for i in range(N//2):
        if a[i*2+1] != 2:
            print(0)
            exit()
    
    print(pow(2,N//2,int(1e9+7)))

else:
    a = defaultdict(int)
    for i,j in zip(c.keys(),c.values()):
        a[i] = j

    for i in range(N//2+1):
        if i == 0:
            if a[i] != 1:
                print(0)
                exit()
        else:
            if a[2*i] != 2:
                print(0)
                exit()

    print(pow(2,N//2,int(1e9+7)))

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

int main(){
  int X,Y;
  cin >> X >> Y;
  for(int i=0;i<=X;i++)
    if(Y == i*2 + (X-i)*4){cout << "Yes" << endl; return 0;}
  cout << "No" << endl;
}


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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

ll axes[200];

int main ()
{
    ll r, d, x; cin >> r >> d >> x;
    axes[0] = x;
    for (int i = 1; i <= 10; i++) {
        cout << (axes[i] = r * axes[i-1] - d) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

	int a ,b;
	char op;
	while(1){
		scanf("%d %s %d",&a,&op,&b);
		if(op=='?') break;
		else if(op=='+')printf("%d\n",a + b);
		else if(op=='-')printf("%d\n",a - b);
		else if(op=='*')printf("%d\n",a * b);
		else if(op=='/')printf("%d\n",a / b);
	}
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    int A[9];
    int B[105];
    int check[8]={0};
    for (int i=0; i<9; i++) {
        scanf("%d",&A[i]);
    }
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&B[i]);
        for (int j=0; j<9; j++) {
            if (A[j] == B[i]) {
                A[j]=0;
                j=9;
            }
        }
    }

    for (int i=0; i<9; i++) {
        if (A[i] == 0) {
            check[i%3]++;
            check[i/3+3]++;
        }
    }
    if (A[0] == A[4] && A[4] == A[8]) check[6]=3;
    if (A[2] == A[4] && A[4] == A[6]) check[7]=3;
    for (int i=0; i<8; i++) {
        if (check[i] == 3) {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
}


Measured memory_bytes: 128
#include<stdio.h>
#define MAX 500
#define INFTY  (1<<21)
#define NIL -1
main(){
  int n, i, j, e, sum,k,a,v1;
  int min,pi[MAX],v[MAX],u,c[MAX],M[MAX][MAX];
  
  scanf("%d", &n);

  for(i=0;i<n;i++){
    c[i]=INFTY;
    pi[i]=NIL;
    v[i]=0;
  }
  c[0]=0;

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      M[i][j] = INFTY;
    }
  }
  
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v1, &a);
      M[u][v1] = a;
    }
  }
  while(1){
    min=INFTY;
    u=NIL;
    for(i=0;i<n;i++){
      if(min>c[i] && !v[i]){
	u=i;
	min=c[i];
      }
    }
    if(u==NIL)break;
    v[u]=1;
    for(j=0;j<n;j++){
      if(M[u][j]+c[u]<c[j] && !v[j]){
	pi[j]=u;
	c[j]=c[u]+M[u][j];
      }
    }
  }
  
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (c[i]==INFTY?-1:c[i]));
  }
  
  return 0;
}

Measured memory_bytes: 800
N, K = map(int, input().split())

c = 0
d = 0

for i in range(1, N+1):
	if i%K==0:
		c = c+1
	elif i%K==K//2:
		d = d+1

if K%2==0:
	print(c*c*c+d*d*d)
else:
	print(c*c*c)

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	int n;
	int a,i;
	double b;
	scanf("%d",&n);
	a=0;
	for(i=1;i<=n;i++){
		if (i%2!=0)
		a=a+1;
	}
	b=a*1.0/n;
	printf("%.10f",b);
return 0;
}

Measured memory_bytes: 128
N,M,X,Y=list(map(int, input().split()))
xc=list(map(int, input().split()))
xc.append(X)
yc=list(map(int, input().split()))
yc.append(Y)
xc.sort()
yc.sort()
if xc[-1]>=yc[0]:
  print('War')
else:
  print('No War')

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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v),v.end()));
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	cout << (a + b) % 24 << endl;

	return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <stdlib.h>
#include <vector>
#include <stack>

using namespace std;


int main(){

	int n, r;

	while(1){
		cin >> n;
		cin >> r;
		if(n==0 && r==0) break;

		int a[n];
		int temp[n];
		int count = n-1;
		for(int i=1 ; i<=n ; i++){
			a[count] = i;
			count--;
		}

		int p, c;
		for(int i=0 ; i<r ; i++){
			cin >> p >> c;
			for(int j=0 ; j<c ; j++){
				temp[j] = a[p-1+j];
			}
			for(int j=0 ; j<p-1 ; j++){
				temp[c+j] = a[j];
			}
			for(int j=c+p-1 ; j<n ; j++){
				temp[j] = a[j];
			}

			for(int j=0 ; j<n ; j++){
				a[j] = temp[j];
			}
		}
		cout << a[0] << endl;

	}

	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll X; cin>>X;
	ll i=0;
	while((1+i)*i/2<X){
		i++;
	}
	cout<<i;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue> //priority_queue 优先队列
#include <map>
#include <set> //multiset  set<int>::reverse_iterator rit; for(rit=s.rbegin();rit!=s.rend();rit++)
#include <vector>
#include <stack>
#include <cmath>
#include <utility>
#include <sstream>
#include <string>
#define mod 1000000007
typedef unsigned long long ull;
typedef long long ll;
typedef double db;
const db eps=1e-6;
const int INF = 0x3f3f3f3f;
const ll inf=0x3f3f3f3f3f3f3f3f;
const int N=1e6+5;
using namespace std;

int n,m,ans=0;
string a;
map<string,int> mp;
map<string,int>::iterator it;
int main(){
	scanf("%d",&n);
	while(n--){
		cin>>a;
		mp[a]++;
		ans=max(ans,mp[a]);
	}
	it = mp.begin();
    while(it != mp.end()){
        if(it->second==ans) cout<<it->first<<endl;
        it++;
    }

	return 0;
}

Measured memory_bytes: 17664
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }


int main() {
	int C[3][3];
	int x[3];
	int y[3];
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			scanf("%d", &C[i][j]);
		}
	}
	x[0] = 0;
	for (int i = 0; i < 3; i++) {
		y[i] = C[0][i] - x[0];
	}
	for (int i = 0; i < 3; i++) {
		x[i] = C[i][0] - y[0];
	}
	bool good = true;

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (x[i] + y[j] != C[i][j]) {
				good = false;
			}
		}
	}
	if (good) {
		puts("Yes");
	}
	else {
		puts("No");
	}

#ifdef DEBUGF
	getch();
#endif
	return 0;
	}

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

ball = [0]*(n+1)
for j in range(n//2+1, n+1):
    ball[j] = a[j-1]
for i in range(n//2, 0, -1):
    summ = 0
    for k in range(2, n+1):
        if i*k > n:
            break
        else:
            summ += ball[i*k]
    if a[i-1] == (summ%2):
        ball[i] = 0
    else:
        ball[i] = 1

print(sum(ball))
if sum(ball) > 0:
    ans = []
    for l in range(1, n+1):
        if ball[l] == 1:
            ans.append(l)
    print(' '.join(map(str, ans)))


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll n; cin >> n;
  vector<ll> y(n);
  vector<ll> x(n); REP(i, n) {cin >> x[i]; y[i] = x[i];}

  sort(x.begin(), x.end());
  ll mi = x[n/2-1];
  REP(i, n) {
    if(y[i] > mi) {
      cout << x[n/2-1] << endl;
    } else {
      cout << x[n/2] << endl;
    }
  }
      
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
	cin >> n;
	vector<int> a(n, 0);deque<int> b;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) 
			b.push_back(a[i]);
		else 
			b.push_front(a[i]);
	}

	if (n % 2 != 0)  		reverse(b.begin(),b.end());
	for (int i = 0; i < n; i++) {
		cout << b[i] << " " ;
	}
}


Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
int main(){
	int n,s=0;
	char a[100];
	scanf("%d%s",&n,a);
	for(int i=0;i<n-2;i++){
        if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
            s++;
	}
	printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll n;
  in(n);
  if(n > 29)
    out("Yes");
  else
    out("No");
  memi;
}

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

int main(){
    int n;cin >> n;
    cout << n << ":";
    for (int i = 2; i *i<=n ; ++i)
    {
        if(n==1) break;
        if(n%i!=0)continue;
        while(n%i==0){
            n = n/i;
            cout<<" " <<i;
        }
    }
if (n!=1)
{
   cout << " "<<n;
}
cout << endl;

    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define v2i vector<vector<int>>
#define v2l vector<vector<ll>>
#define ppi pair<int,int>
#define vpi vector<ppi>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/

int main()
{
    fast


        
    int n;
    cin>>n;

    ll sum = 0;    
    int k;
    int maxi = 0;
    forn(i,0,n)
    {
        cin>>k;
        sum += k;
        maxi = max(maxi,k);
    }

    if((sum-maxi) > maxi)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }








    return 0;
}

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

int main() {
	// your code goes here
	unordered_map<long, bool> umap; 
	int n;
	long a;
	bool unique =true;
	
	cin >> n;
	while(n--){
		cin >> a;
		if(umap[a])
			unique=false;
		umap[a]=true;
	}
  
	if(unique)
		cout<<"YES"<<endl;
	else
	
		cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 8520
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define mod 1000000007
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	
//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
	
	int n,i;
	cin>>n;
	vector<int> a(n),b(n);
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		b[i+1]=b[i]+a[i];
	}
	int ans=0,k=0;
	for(i=0;i<n;i++)
	{
		k=a[i]*((b[n]-b[i+1])%mod);
		ans+=k;
		ans=ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6344
#include <iostream>
#include <string>
#include <cmath>

#include <list>
#include <queue>
#include <algorithm>

#define INF 1000000000

using namespace std;

int main(void)
{
    long long x,k,d;
    cin >> x >> k >> d;
    x = abs(x);
    long long q = x / d;
    long long m = x % d;
    if (q == k) {
        cout << m;
    }else if (q < k) {
        if ((k - q) % 2 == 0) {
            cout << m;
        } else {
            cout << abs(m - d);
        }
    } else {
        cout << x - (k * d);
    }

    return 0;
}

Measured memory_bytes: 3640
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
string s;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cin >> s;
	int n = s.size();
	int ret = n;
	for (int i = 1; i < n; i++) {
		if (s[i] != s[i - 1]) {
			if (i <= n / 2) ret = min(ret, n - i);
			else ret = min(ret, i);
		}
	}
	cout << ret << '\n';
	return 0;
}

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

class Main {
    public static void main(String [] args) {
        Solver s = new Solver();
        s.solve();
    }
}

class Solver {
    Reader in = new Reader ();
    Writer out = new Writer ();

    void solve () {
        long h = in.nextLong();
        int n = in.nextInt();
        long sum = 0;
        for(int i = 0; i < n; i++) {
            sum += in.nextInt();
        }
        if(sum >= h) System.out.println("Yes");
        else System.out.println("No");
    }
}

class Reader {
    private StringTokenizer a;
    private BufferedReader b;
    Reader () {
        a = null;
        try {
            b = new BufferedReader (new InputStreamReader (System.in)); // for file IO, replace this with new FileReader ("in.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public String next () {
        while(a == null || !a.hasMoreTokens()) {
            try {
                a = new StringTokenizer (b.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return a.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(this.next());
    }
    public long nextLong () {
        return Long.parseLong(this.next());
    }
    public double nextDouble () {
        return Double.parseDouble(this.next());
    }
    public String nextLine() {
        try {
            return b.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
class Writer {
    private PrintWriter a;
    private StringBuffer b;
    Writer () {
        try {
            a = new PrintWriter (System.out); // for file IO, replace this with new FileWriter ("out.txt")
        } catch (Exception e) {
            e.printStackTrace();
        }
        b = new StringBuffer ("");
    }
    public void write (Object s) {
        b.append(s);
    }
    public void writeln(Object s) {
        b.append(s).append('\n');
    }
    public void flush () {
        a.print(b);
        a.flush();
        a.close();
    }
}


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

int main(){
	long n, a, min, max, sum;
	cin >> n;
	cin >> a;
	min = a;
	max = a;
	sum = a;
	for (int i=1; i<n; i++) {
		cin >> a;
		if (a < min) {
			min = a;
		}
		else if (a > max){
			max = a;
		}
		sum += a;
	}
	cout << min << " " << max << " " << sum << endl;
	return 0;
} 


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

using namespace std;

int main() {
int n;
cin>>n;
long long a[n];
long long count=0;
for(int i=0;i<n;i++)
{cin>>a[i];
if(a[i]<0)
count++;
}
long long sum=0;
    long long min=1000000000000;
    for(int i=0;i<n;i++)
    {
        sum+=abs(a[i]);
        if(abs(a[i])<min)
        min=abs(a[i]);
        
    }
    if(count%2==0)
    cout<<sum;
    else
    cout<<sum-(2*min);
    
    
    return 0;
}

Measured memory_bytes: 1024
# coding: utf-8
# Here your code !
import sys
import collections
import math
import unittest

def calculate_distance():
    try:
        [x1, y1, x2, y2] = [float(value) for value in input().rstrip().split()]
    except:
        __input_error()
    
    print(math.hypot(x1-x2, y1-y2))

def __input_error():
    print("input error")
    return -1

class __TestValueClass(unittest.TestCase):
    def testEqual(self,func,tuples):
        self.testFunction(self.assertEqual,func,tuples)
    
    def testFunction(self,assertfunc,func,tuples):
        #tuples[index] = ([*arguments of func], compared value)
        for item in tuples:
            try:
                if isinstance(item[0], collections.Iterable):
                    assertfunc(func(*item[0]),item[1])
                else:
                    assertfunc(func(item[0]),item[1])
            except Exception as msg:
                swidth = 15
                print("="*50)
                print("-- Assertion Error in '" + func.__name__ + "' --")
                print("arguments".ljust(swidth)+":",item[0])
                print("compared value".ljust(swidth)+":",item[1])
                print("message".ljust(swidth)+":")
                print(msg)
                sys.exit()
        print(func.__name__,": succeeded")
        
#test
if __name__ == "__main__" :

    calculate_distance()
#    test = __TestValueClass()

Measured memory_bytes: 10396
import java.util.Scanner;

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

		// 入力値の取得
		int N = sc.nextInt();
		long[] A = new long[N];

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong();
			if (A[i] == 0) {
				System.out.println(0);
				sc.close();
				return;
			}
		}

		long product = 1;
		for (long a : A) {
			try {
				product = Math.multiplyExact(product, a);

				if (product > (long) Math.pow(10, 18)) {
					System.out.println(-1);
					sc.close();
					return;
				}
			} catch (Exception e) {
				System.out.println(-1);
				sc.close();
				return;
			}
		}

		// 結果の出力
		System.out.println(product);

		sc.close();
	}
}


Measured memory_bytes: 50744
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <bitset>
#include <cstring>
#include <map>
#include <math.h>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1<<30;
const ll LINF = 1LL<<58;
const int mod = 1000000007;

int main(){
	int a, b, q;
	cin >> a >> b >> q;
	vector<ll> S, T;
	S.pb(-LINF);T.pb(-LINF);
	rep(i,a){
		ll s;
		cin >> s;
		S.pb(s);
	}
	rep(i,b){
		ll t;
		cin >> t;
		T.pb(t);
	}
	S.pb(LINF);T.pb(LINF);
	rep(i,q){
		ll x, ans = LINF;
		cin >> x;
	    vector<ll> s(2), t(2);
		rep(i, 2){
			s[i] = lower_bound(all(S), x) - S.begin() - i;
			t[i] = lower_bound(all(T), x) - T.begin() - i;
		}
		rep(i,2) rep(j,2){
			chmin(ans, abs(x-S[s[i]])+abs(S[s[i]]-T[t[j]]));
			chmin(ans, abs(x-T[t[j]])+abs(T[t[j]]-S[s[i]]));
		}
		cout << ans << endl;
	}
}


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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int a,b,x=1,y=0;
  cin>>a>>b;

  while(x<b) {
    x += a-1;
    y++;
  }

  cout << y << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll>P;

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct etree { ll from, to, cost; };
struct people { ll v, k, year; };
bool comp(const etree& e1, const etree& e2) {
	return e1.cost < e2.cost;
}
bool comp2(const people& e1, const people& e2) {
	return e1.year < e2.year;
}
#define ALL(x) (x).begin(),(x).end()

int main() {
	ll n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	for (ll i = 0;i < n-1;i++) {
		ll l = i*-1 * d + c*(n - i - 1);
		ll r = i*-1 * c + d*(n - i - 1);
		if (l <= b - a&&b - a <= r) {
			cout << "YES" << endl;
			exit(0);
		}
	}
	cout << "NO" << endl;
}

Measured memory_bytes: 256
import sys
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

w = input()

c = Counter(w)

for i in tuple(c):
    if c[i] % 2 == 1:
        print("No")
        exit()

print("Yes")


Measured memory_bytes: 64524
from fractions import gcd # python 3.4
# from math import gcd # from python 3.5 
def lcm(a,b):
    return int(a*b/gcd(a,b))

N,M = map(int, input().split())
S = input()
T = input()
L= lcm(N,M)
ans = dict()
for i in range(N):
    idx = i*(L//N)
    ans[idx] = S[i]

for j in range(M):
    idx = j*(L//M)
    if idx in ans.keys():
        if ans[idx]==T[j]:
            continue
        else:
            print(-1)
            break
else:
    print(L)

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

using namespace std;

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

#define FOR(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define DOW(i,b,a) for (int i = (b); i >= (a); i--)
#define pb(a) push_back(a)
#define ALL(a) (a).begin(),(a).end()
#define fi first
#define se second

template<typename T>
void print_array(T* arr, int num) {
   FOR(i, 0, num) cout << arr[i] << ' ';
   cout << endl;
}

template<typename T> 
void print_vector(vector<T> vec) {
   FOR(i,0,vec.size()) cout << vec[i] << ' ';
   cout << endl;
}

const int INF = 1e9 + 7;
int n,k,x,y, off, we[110], val[110];
map<int, int> dp[110];

int bt1(int idx, int left) {
    if (left < 0) return -INF;
    if (idx == n) return 0;
    if (dp[idx].count(left) > 0) return dp[idx][left];
    return dp[idx][left] = max(val[idx] + bt1(idx + 1, left - we[idx]), bt1(idx + 1, left));
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    //freopen("test.txt", "r", stdin);
    cin >> n >> k;
    FOR(i,0,n) cin >> we[i] >> val[i];
    cout << bt1(0,k);
}

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

int main(){
    int k;
    cin>>k;
    int val=7%k;
    for(int i=1;i<1e7;i++){
        if(val==0){
            cout<<i;
            return 0;
        }
        else{
            val=(val*10+7)%k;
            }
    }
    cout<<"-1";
}


Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;

#define ul unsigned long int
#define ull unsigned long long
#define li long long int

int main()
{
  ul s[1000],n,sum=0;
  cin>>n;
  double m,a2;

  cout <<fixed<<setprecision(16);

  while (n!=0) {
    sum=0;
    a2=0.0;
    for (ul i = 0; i < n; i++)
    {
      cin >> s[i];
      sum += s[i];
    }
    m=(double)sum/(double)n;
    for (ul i=0;i<n;i++) {
      a2 += ((double)s[i] - m) * ((double)s[i] - m);
    }
    a2/=(double)n;

    //cout<<m<<endl;
    cout << sqrt(a2)<<endl;

    cin >> n;
  }





  return 0;
}



Measured memory_bytes: 3292
import fractions
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
X.append(M)
X = sorted(X)
diff = [X[i+1]-X[i] for i in range(len(X)-1)]
max_gcd = diff[0]
for i in range(1, len(diff)):
  max_gcd = fractions.gcd(diff[i], max_gcd)
print(max_gcd)

Measured memory_bytes: 16280
#include <iostream>
#include <limits.h>
using namespace std;
int n, c, v;
long x;
int D[31][31] = {};
int K[3][31] = {};
int T[3][31] = {};

int main()
{
	scanf("%d %d", &n, &c);
	for (int i = 1; i <= c; ++i) {
		for (int j = 1; j <= c; ++j)
			scanf("%d", &D[i][j]);
			
	}
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			scanf("%d", &v);
			++K[(i + j) % 3][v];
		}
	}
	for (int i = 0; i < 3; ++i) {
		for (int j = 1; j <= c; ++j) {
			for (int s = 1; s <= c; ++s)
				T[i][j] += K[i][s] * D[s][j];
		}
	}
	x = LONG_MAX;
	for (int i = 1; i <= c; ++i) {
		for (int j = 1; j <= c; ++j) {
			if (i == j) continue;
			for (int k = 1; k <= c; ++k) {
				if (i == k || j == k)continue;
				v = T[0][i] + T[1][j] + T[2][k];
				if (x > v)
					x = v;
			}
		}
	}
	printf("%ld\n", x);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int se(int*,int,int);

int main(){
  int i,j,s,t,n[1000000],q[50000],cnt=0;
  scanf("%d",&s);
  for(i=0;i<s;i++){
    scanf("%d",&n[i]);
  }
  scanf("%d",&t);
  for(i=0;i<t;i++){
    scanf("%d",&q[i]);
    //printf("%d ",q[s]);
  }
  for(j=0;j<t;j++){
    if (se(n,q[j],s)) cnt++; 
  }
  printf("%d\n",cnt);

  
  
}
int se(int *n,int key,int s){
  int l,r,m;
  l=0;
  r=s;
  m=s/2;
  while(n[m] != key){
    if(key <n[l] ||key >n[r-1]) return 0;
    if(n[m]>key)r=m;
    else l=m+1;
    m=(l+r)/2;
  }
  //  printf("%d %d - \n",n[m],key);
  return 1;
  
}


Measured memory_bytes: 2324
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int parse(string part)
{
    int t = part[0] - '0';
    return t * 10 + part[1] - '0';
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string date;
    cin >> date;

    int month = parse(date.substr(5, 2));
    int day = parse(date.substr(8, 2));

    if (month <= 4)
        cout << "Heisei";
    else
        cout << "TBD";
    cout << endl;
    return 0;
};


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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define sz(x) int(x.size())
const int INF = 1001001001;
const ll mod = 998244353;
const ll INFL = 1001001001001001000;



int main() {
    int n,m; cin >> n >> m;
    dsu uf(n);
    int ans = n;
    rep(i,m) {
        int a,b; cin >> a >> b;
        a--; b--;
        if (uf.same(a,b)) continue;
        uf.merge(a,b); ans--;
    }
    cout << max(ans-1, 0) << endl;
    return 0;
}

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

int n, k;
vector <int> A;
main() {
  cin>>n>>k;
  A.assign(n, 0);
  for (int i=0; i<n; i++) cin>>A[i];
  int l = 1, r = 1000000007;
  while (r>l) {
    int mid = (l+r)/2;
    int t = 0;
    for (int i = 0; i < n; i++) t += (A[i] - 1)/mid;
    if (t>k) l = mid+1;
    else r = mid;
  }
  cout<<l;
}

Measured memory_bytes: 4752
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> LtoR;
vector<int> RtoL;
vector<char> S;
int main()
{
	char tt;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>tt;
		S.push_back(tt);
	}
	int t=0,t_sum=0;
	for(int i=0;i<n;i++)
	{
		if(S[i] == 'W')
			t = 1;
		else 
			t = 0;
		t_sum +=t;
		LtoR.push_back(t_sum);
	}
	t_sum=0;
	for(int i=n-1;i>=0;i--)
	{
		if(S[i] == 'E')
			t = 1;
		else 
			t = 0;
		t_sum +=t;
		RtoL.push_back(t_sum);
	}
	int Sum =3e5;
	for(int i=0;i<n;i++)
	{
		if(i==0)
		{
			t=RtoL[n-1];
		}
		else if(i==n-1)
		{
			t=LtoR[n-1];
		}
		else
			t = LtoR[i-1] + RtoL[n-2-i];
		Sum = min(Sum,t);
	}
	cout<<Sum<<endl;
	return 0;
}

Measured memory_bytes: 4720
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

int main(void) {
	int R, G;
	cin >> R >> G;

	cout << 2 * G - R << endl;

	return 0;
}

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

#define SENTINEL 1000000000

int count=0;

void mergeSort(int A[],int left,int right){
  int i,mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}



void merge(int A[],int left,int mid,int right){
  int n1,n2,i,j,k;
  int *L,*R;
  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<=n1-1;i++){
    L[i]=A[left+i];
  }
  for(j=0;j<=n2-1;j++){
    R[j]=A[mid+j];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
   if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
      count++;
    }
    else{
      A[k]=R[j];
      j++;
      count++;
    }
  }
  free(L);
  free(R);
}


main(){
  int A[500000];
  int n,i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  mergeSort(A,0,n);
  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i<n-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

   

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define MOD 10000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
const int INF=1e9;
int main(){
      int a[3],cnt[4];
      memset(cnt,0,sizeof(cnt));
      while(cin>>a[0]>>a[1]>>a[2]){
            sort(a,a+3);
            if(a[0]+a[1]<=a[2]){
                  REP(i,4)printf("%d%c",cnt[i],i==3?'\n':' ');
                  break;
            }
            cnt[0]++;
            if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2])cnt[1]++;
            else if(a[0]*a[0]+a[1]*a[1]>a[2]*a[2])cnt[2]++;
            else cnt[3]++;
      }
}

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

int main() {
	int n;
	cin >> n;
	vector<int64_t> h(n);
	for (auto &i : h) {
		cin >> i;
	}
	h.emplace_back(0);
	int64_t ans = 0;
	stack<pair<int64_t, int>> st;
	for (int i = 0; i <= n; i++) {
		if (st.empty() || st.top().first < h[i]) {
			st.emplace(make_pair(h[i], i));
		} else {
			if (h[i] < st.top().first) {
				int target = i;
				while (!st.empty() && h[i] <= st.top().first) {
					int64_t height = st.top().first;
					int pos = st.top().second;
					st.pop();
					int64_t area = height * (i - pos);
					ans = max(ans, area);
					target = pos;
				}
				st.emplace(make_pair(h[i], target));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5252
#include<bits/stdc++.h>
using namespace std;
 
int main () {
  char n1, n2, n3, n4;
  cin >> n1 >> n2 >> n3 >> n4;
  
  if (n1 == n2 && n2 == n3) {
    cout << "Yes" << endl;
  }
  else if (n2 == n3 && n3 == n4) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
const int N = 1e5 + 5;
char s[N];
int n, a[N], deg[N], f[N], res;
bool vis[N];
vector<int> g[N];
//
void dfs(int x, int p) {
  if (vis[x]) return;
  f[x] = a[x];
  for (int to : g[x]) if (to != p) {
    dfs(to, x);
    res = max(res, f[x] + f[to]);
    f[x] = max(f[x], f[to] + a[x]);
  }
}
int main() {
  n = getint();
  rep(i, n - 1) {
    int x = getint() - 1, y = getint() - 1;
    g[x].emplace_back(y);
    g[y].emplace_back(x);
    deg[x]++; deg[y]++;
  }
  int c = 0;
  scanf("%s", s);
  rep(i, n) {
    a[i] = (s[i] == 'W');
    c += a[i];
  }
  if (c <= 1) return !printf("%d\n", c);
  int st = 0; vector<int> qu;
  rep(i, n) if (deg[i] == 1 && !a[i]) {
    qu.emplace_back(i);
    vis[i] = true;
  }
  while (st < qu.size()) {
    int u = qu[st++];
    for (int to : g[u]) {
      --deg[to];
      if (deg[to] == 1 && !a[to]) {
        qu.emplace_back(to);
        vis[to] = true;
      }
    }
  }
  c = 0;
  rep(i, n) if (!vis[i]) {
    int x = 0;
    for (int to : g[i]) x ^= (!vis[to]);
    c += (a[i] ^= x);
  }
  n -= qu.size();
  int s = 0;
  rep(i, n) if (!vis[i]) { s = i; break; }
  dfs(s, -1);
  printf("%d\n", 2 * (n - 1) + c - 2 * res);
  return 0;
}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
#include<stdio.h>
#include<stdlib.h>

using namespace std;
#define endl "\n"
#define FILEIO freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define LL long long 
#define mod 1000000007LL
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back
//#define p push
#define I insert
#define bg begin()
#define ed end()
#define sz size()
#define all(v) v.begin(),v.end()
typedef vector<LL> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef map<LL ,LL > mii;
//typedef priority_queue<int> pq;
typedef queue<int>que;
typedef stack<int>stk;
#define Inf 100000005LL
#define f first
#define s second





vi vect_2pow;
void pow_of_2(){
    vect_2pow.assign(32,0);
      for(int i=0;i<=32;i++){
           LL y = 1<<i;
           vect_2pow[i]=y;
      }
}
bool Ispalindrome(string str){
        LL len = str.size();
		bool flag;
		for(int i=0;i<len/2;i++){
				if(str[i]==str[len-i-1])
				     {
						 flag=0;
						 continue;
					 }
					 else 
					    {
							flag=1;
							break;
						}
			}
		if (flag==1)
		  return false;
		else return true;  
		
}
vector<LL> prime_check;
mii get_high_prime;
int high_prime_factor(){
	//cout<<"ecd";
	LL max_prime=0;
	for(int i=2;i<100000;i++)
	{
		LL n=i;
		
		while(n%2==0)
		{
			max_prime=2;
			n>>=1;
		}
		for(int j=3;j<=sqrt(n);j++)
		{
			while(n%j==0){
				max_prime=j;
				n/=j;
			}
		}
		if(n>2)
		  max_prime=n;
		  
		//prime_check.pb(max_prime);
		get_high_prime[i]=max_prime;
	}
	
			
}

//const LL inf = 10e+9;

int main()
{
	int n;
	cin>>n;
	int arr[n+1][4];
	int dp[n+1][3];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	}
	dp[0][0]=dp[0][1]=dp[0][2]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=arr[i][1]+max(dp[i-1][2],dp[i-1][0]);
		dp[i][2]=arr[i][2]+max(dp[i-1][1],dp[i-1][0]);
		
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
	


}

Measured memory_bytes: 2944
def divisors(n):
    ret=[]
    for i in range(1,int(n**0.5)+1):
        if n%i==0:
            ret.append(i)
            if i!=n//i:
                ret.append(n//i)
    return ret

mod=10**9+7    
n,k=map(int,input().split())
cnt=[0]*(k+1)
for i in range(k,1,-1):
    divs=divisors(i)
    cnt[i]+=pow(k//i,n,mod)
    for val in divs:
        if val==i:
            continue
        else:
            cnt[val]-=cnt[i]
cnt[1]+=pow(k,n,mod)
ans=0
for i in range(1,k+1):
    ans+=i*(cnt[i])%mod
    ans%=mod
print(ans)

Measured memory_bytes: 69916
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

import static java.util.stream.Collectors.toList;

public class Main {
    private static final Scanner scanner = new Scanner(System.in);
    private static final Consumer<List<String>> consumer = solve();

    public static void main(String[] args) {
        consumer.accept(readInput());
    }

    private static List<String> readInput() {
        final List<String> lineList = new ArrayList<>();
        while (scanner.hasNextLine()) {
            lineList.add(scanner.nextLine());
        }
        return lineList;
    }

    private static Consumer<List<String>> solve() {
        return args -> {
            final List<Long> numList = Arrays.stream(args.get(0).split(" ")).map(Long::valueOf).collect(toList());
            if (numList.get(0) > numList.get(1)) {
                System.out.println(2 * numList.get(0) - 1);
            } else if (numList.get(1) > numList.get(0)) {
                System.out.println(2 * numList.get(1) - 1);
            } else {
                System.out.println(2 * numList.get(0));
            }
        };
    }

}


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

int main(){

    string T; cin >> T;

    rep(i, T.size()){
        if(T[i]=='?') T[i]='D';
    }

    cout << T << endl;

}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

int main() {
    int N;
    cin >> N;
    
    vec<int> h(N+3);
    rep(i, N) cin >> h[i];
    vec<int> dp(N+3,1e9+7);
    dp[1] = 0;
    for(int i=1;i<=N-1;++i){
        dp[i+2] = min(dp[i+2],dp[i]+abs(h[i-1]-h[i+1]));
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i-1]-h[i]));
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 4024
#include "bits/stdc++.h"
using namespace std;
 
////////////// Prewritten code follows. Look down for solution. ////////////////

#define fs first
#define sc second
#define pb push_back
#define mp(a, b) make_pair(a, b)
#define len(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> pll;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
template<typename T>
inline T mod(T n, T mod){ T res = n%mod; if(res < 0) res += mod; return res; }

/// command for char arrays with spaces -> scanf(" %[^\n]", text);
 
////////////////////////// Solution starts below. //////////////////////////////

int main(){
	fastio;
	int n;
	cin >> n;
	vector<ll> d(n);
	for(int i = 0; i < n; i++) cin >> d[i];
	ll sum = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			sum += d[i]*d[j];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>

using namespace std;

/*
 * 
 */
int main(int argc, char** argv) {
    //???????????¨???????????¨?????????
    int N,M,h,m;
    cin >> N;
    int* l1 = new int[N+1];
    for(int i=0;i<N;i++){
        cin >> h >> m;
        l1[i] = h*60+m;
    }
    l1[N]=2000;
    cin >> M;
    int* l2 = new int[M+1];
    for(int i=0;i<M;i++){
        cin >> h >> m;
        l2[i] = h*60+m;
    }
    l2[M]=2000;
    
    //??±?????????????????¨?????????
    int p1=0,p2=0,p3=0,tmp;
    int* l3 = new int[N+M+1];
    l3[0]=-1;
    for(int i=0;i<N+M;i++){
        if(l1[p1]<=l2[p2]){
            tmp = l1[p1++];
        }else{
            tmp = l2[p2++];
        }
        if(l3[p3]==tmp)continue;
        l3[++p3]=tmp;
    }
    
    //??¨???
    for(int i=1;i<=p3;i++){
        h = l3[i]/60;
        m = l3[i]%60;
        cout << h << ':';
        if(m<10)cout << 0;
        cout << m;
        if(i!=p3){
            cout << " ";
        }else{
            cout << endl;
        }
    }
    delete[] l1,l2,l3;
    return 0;
}

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

int main() {
  ll n, k, q;
  cin >> n >> k >> q;
  vector<ll> vec(q);
  rep(i, q) cin >> vec.at(i);
  vector<ll> ans(n, 0);
  rep(i,q) ans.at(vec.at(i)-1)++;
  rep(i,n) {
    if(ans.at(i) >= q-k+1) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 2176