akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1e9;

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

    vector<int> dp(n+1, INF);
    dp[n] = 0;
    
    queue<int> Q;
    Q.push(0);
    for(int i = n-1; i >= 0; i--) {
        while(1) {
        if(Q.size() == 0) {
            cout << -1 << endl;
            return 0;
        }
        if(Q.front() != INF && Q.size() <= m) {
            break;
        } 
        Q.pop();
        }
        if(s[i] == '0') {
            dp[i] = Q.front() + 1;
        } 
        Q.push(dp[i]);
    }
    
    vector<int> ans;
    int x = 0;
    int rest = dp[0];
    while(x < n) {
        rest--;
        int i = 1;
        while(dp[x+i] != rest) {
            i++;
        } 
        ans.push_back(i);
        x += i;
    }

    rep(i, ans.size()) {
        cout << ans[i];
        if(i < ans.size() - 1) {
            cout << " ";
        }
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
  int n;

  while(cin >> n){
	int f[2][n];
	string str;
	int cur=0, prv=1;
	int ret=0;

	if(!n) break;
	for(int i=0;i<n;i++){
	  cin >> str;
	  for(int j=0;j<n;j++){
		if(i == 0 || j == 0){ // first line
		  if(str[j] == '.'){
			f[cur][j] = 1;
		  }else{
			f[cur][j] = 0;
		  }
		}else{
		  if(str[j] == '.'){
			f[cur][j] = min(f[cur][j-1], min(f[prv][j], f[prv][j-1])) + 1;
		  }else{
			f[cur][j] = 0;
		  }
		}
		//cout << f[cur][j];
		ret = max(ret, f[cur][j]);
	  }
	  //cout << endl;
	  cur = 1 - cur;
	  prv = 1 - prv;
	}
	cout << ret << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

int main(void){
    int n;
    vector <string> str;
    string sub;
    long ans = 0;
    vector <int> cnt;
    
    cnt.resize(5);
    
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> sub;
        str.push_back(sub);
        if(str[i][0] == 'M')        cnt[0]++;
        if(str[i][0] == 'A')        cnt[1]++;
        if(str[i][0] == 'R')        cnt[2]++;
        if(str[i][0] == 'C')        cnt[3]++;
        if(str[i][0] == 'H')        cnt[4]++;
    }
    
    int alpha_cnt = 0;
    for(int i = 0; i < 5; i++){
        if(cnt[i])      alpha_cnt++;
    }
    
    if(alpha_cnt < 3){
        cout << 0 << endl;
        return 0;
    }
    
    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 5100
def main():
    n = int(input())
    c = input()
    l = 0
    r = n - 1
    cnt = 0
    while True:
        ok = True
        while c[l] != "W":
            l += 1
            if l == r:
                ok = False
                break
        if not ok:
            break
        while c[r] != "R":
            r -= 1
            if l == r:
                ok = False
                break
        if not ok:
            break
        cnt += 1
        l += 1
        r -= 1
        if r <= l:
            break
    print(cnt)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9328
#include <iostream>
using namespace std;
int  main(){

	int H, W;

	for (;;){

		cin >> H >> W;
		if (H == 0 && W == 0)break;

		for (int q = 0;q != H;q++){

			for (int p = 0; p != W; p++){
				cout << "#";

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

Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		String message = "No";
		if(x == 1 || x == 3 || x == 5 || x == 7
				|| x == 8 || x == 10 || x == 12) {
			if(y == 1 || y == 3 || y == 5 || y == 7
					|| y == 8 || y == 10 || y == 12) {
				message = "Yes";
			}
		} else if(x == 4 || x == 6 || x == 9 || x == 11) {
			if(y == 4 || y == 6 || y == 9 || y == 11) {
				message = "Yes";
			}
		} else if(x == 2) {
			if(y == 2) {
				message = "Yes";
			}
		}
		System.out.println(message);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <cstring>
#include <cctype>
#include <ios>
#include <iomanip>
#include <bitset>
#include <cstdlib>

#define INF 200000000
#define MOD 1000000007
//#define int long long int
#define ll long long int
#define _tilde_ ~

using namespace std;

int main()
{
    int D, G;
    cin >> D >> G;
    vector<int> P, C;
    P.resize(D); C.resize(D);       //resizeをつかうと簡単になる
    for (int i = 0; i < D; i++)
    {
        cin >> P[i] >> C[i];
    }

    int ans = INF;
    for (int bits = 0; bits < (1 << D); ++bits)
    {
        int tmp_sum = 0, tmp_ans = 0;
        for (int i = 0; i < D; ++i)
        {
            if (bits & (1 << i))
            {
                tmp_sum += 100 * (i+1) * P[i] + C[i];   //iを係数にするために＋１しなきゃいけない（0-indexなので）
                tmp_ans += P[i];
            }
        }

        if (tmp_sum < G)
        {
            for (int i = D - 1; i >= 0; --i)
            {
                if(!(bits & (1 << i)))      //bitのフラグが消えているかどうかを確かめるときは，！を使ってTRUE,FALSEの反転を行う
                {
                    for(int j = 0;j<P[i];j++)
                    {
                        tmp_sum += 100*(i+1);       //iを係数にするために＋１しなきゃいけない（0-indexなので）
                        tmp_ans ++;

                        if(tmp_sum >= G)        //実際,最後まで行ったらボーナスも考えないといけないのでは？となるけど
                        {                       //中途半端に解く問題を全完しなければ目標点を超えないとなった時点で，
                                                //bit全探索での全完問題に関しての選択ミスとわかるため以降の処理を飛ばしてもいいとおもう
                            break;
                        }
                    }
                }

                if(tmp_sum >= G)
                {
                    break;
                }

                
            }

        }
        
        ans = min(tmp_ans,ans);
    }

    cout << ans << endl;

    return 0;
}
		

Measured memory_bytes: 256
import numpy as np

def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    N = ii()
    A = lii()
    A = [-1] + A  # 1 indexing

    ans = 0
    p = [0 for i in range(20)]
    min_l = 0
    for i in range(1, N+1):
        m = i
        for d in range(20):
            if (A[i] >> d) % 2 == 1:
                m = min(m, i - p[d])
                p[d] = i
        min_l = max(min_l, i  - m)
        m = min(m, i - min_l)
        # print(i, bin(A[i]), m, min_l)
        ans += m

    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 33740
Scanf.scanf "%d %d" (fun n q ->
    let nei = Array.make n [] in
    for i = 1 to n - 1 do
        Scanf.scanf " %d %d" (fun a b ->
            let a = a - 1 in
            let b = b - 1 in
            nei.(a) <- b :: nei.(a);
            nei.(b) <- a :: nei.(b);
        )
    done;
    let counter = Array.make n 0 in
    for i = 1 to q do
        Scanf.scanf " %d %d" (fun p x ->
            let p = p - 1 in
            counter.(p) <- counter.(p) + x
        )
    done;

    let parent = Array.make n (-1) in
    let rec parse_parent par cur =
        parent.(cur) <- par;
        List.iter (fun v -> if v <> par then parse_parent cur v) nei.(cur)
    in
    parse_parent (-1) 0;
    let score = Array.make n (-1) in
    score.(0) <- counter.(0);
    let rec calc p =
        if score.(p) >= 0 then score.(p) else
            let s = calc parent.(p) + counter.(p) in
            let () = score.(p) <- s in
            s
    in
    for i = 0 to n - 1 do
        Printf.printf "%d "@@ calc i
    done;
    print_newline ()
)

Measured memory_bytes: 37372
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int x = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		long ans = 0;
		for (int i = 0; i < n - 1; i++) {
			int sum = a[i] + a[i + 1];
			if (sum > x) {
				int diff = sum - x;
				ans += diff;
				a[i + 1] = a[i + 1] < diff ? 0 : a[i + 1] - diff;
			}
		}
		System.out.println(ans);
		in.close();
	}
}

Measured memory_bytes: 50040
n = int(input())
t, a = map(int, input().split())
h_list = list(map(int, input().split()))
ans = 1000
ansi = 0

for ix, x in enumerate(h_list):
    tmp = t - x * 0.006
    if ans > abs(a - tmp):
        ans = abs(a - tmp)
        ansi = ix + 1
print(ansi)

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

using namespace std;

int main()
{
	for(int n,m;cin>>n>>m,n;){
		int p[1001];	p[0]=0;
		for(int i=1;i<=n;i++)	cin>>p[i];

		int nn=0;
		static int xp[1001*1001];
		for(int i=0;i<=n;i++)for(int j=i;j<=n;j++)	xp[nn++]=p[i]+p[j];
		n=nn;
		sort(xp,xp+n);

		int maxscore=0;
		for(int i=0;i<n;i++){
			if(m-xp[i]>=0)
				maxscore=max(maxscore,xp[i]+upper_bound(xp,xp+n,m-xp[i])[-1]);
		}
		cout<<maxscore<<endl;
	}

	return 0;
}

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

#define int long long
#define endl '\n'

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int m; cin >> m;
    int ans = 0, sum = 0;
    for (int i = 0; i < m; i++) {
        int d, c; cin >> d >> c;
        ans += c;
        sum += d * c;
    }
    ans--;
    ans += (sum - 1) / 9;
    cout << ans;
}


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

using namespace std;

int x, y;

int Solve(int x, int y) { if (x <= y) return y - x; return x - y + 2; }

int main()
{
    cin >> x >> y;
    cout<<min(Solve(x, y), min(Solve(-x, y) + 1, min(Solve(x, -y) + 1, Solve(-x, -y) + 2))) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int32_t main()
{
	// fast;
	// cout<<"HEY"<<endl;
	string s;
	cin>>s;
	// cout<<"HEY"<<endl;
	// cout<<s<<endl;
	int n=s.size();
	vector<pair<int, int>> v1;
	vector<int> v(n, 0);
	char ch='R';
	// int c=0;
	int ind=0;
	for(int i=0;i<n;i++)
	{
		// cout<<"EY"<<endl;
		if(s[i]==ch)
		{
			// c++;
			continue;
		}
		else
		{
			v1.push_back({ind, i-1});
			ch=s[i];
			ind=i;
			// c=1;
		}
	}
	v1.push_back({ind, n-1});
	ind=0;
	// for(int i=0;i<v1.size();i++)
	// 	cout<<v1[i].first<<' '<<v1[i].second<<endl;
	for(int i=0;i<n;i++)
	{
		if(i>v1[ind].second)
			ind++;
		// cout<<ind<<endl;
		if(s[i]=='R')
		{
			int x=v1[ind+1].first-i;
			// cout<<x<<endl;
			if(x%2==0)
			{
				v[v1[ind+1].first]++;
			}
			else
			{
				v[v1[ind].second]++;
			}
		}
		else
		{
			int x=i-v1[ind-1].second;
			// cout<<x<<endl;
			if(x%2!=0)
			{
				v[v1[ind].first]++;
			}
			else
			{
				v[v1[ind-1].second]++;
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		cout<<v[i]<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3316
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        HashSet<Integer> hashSet = new HashSet<>();
        for (int i = 0; i < n; i++) hashSet.add(scanner.nextInt());
        System.out.println(hashSet.size());

    }
}


Measured memory_bytes: 21332
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
//#include <cmath>
//#include <cstdlib>
using namespace std;

bool is_war(const vector<int> &x, const vector<int> &y) {
	for (int Z = -100; Z <= 100; ++Z) {
		bool is_ok = true;
		for (int i = 0; i < x.size(); ++i) {
			if (x[i] >= Z)
				is_ok = false;
		}
		for (int i = 0; i < y.size(); ++i) {
			if (y[i] < Z)
				is_ok = false;
		}
		if (is_ok)	return false;
	}
	return true;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> x(N + 1), y(M + 1);
	cin >> x[0] >> y[0];
	for (int i = 0; i < N; ++i) {
		cin >> x[i + 1];
	}
	for (int i = 0; i < M; ++i) {
		cin >> y[i + 1];
	}
	if (is_war(x, y)) {
		cout << "War" << endl;
	} else {
		cout << "No War" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
typedef long long ll;
using namespace std;
int main(){
    int a,b,k;cin>>a>>b>>k;
    int ki=0;
    int num=1;
    for(int i=100;i>=0;i--){
        if((a%i==0)*(b%i==0)){
            ki++;
        }
        if(ki==k){
            cout<<i<<endl;
            break;
        }   
    }
    return 0;
}

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



bool visited[200001];
void dfs(vector<long long int >adj[],int i,long long int A[],long long int &sum)
{
    visited[i]=true;
    long long int j,k;
    sum=sum+A[i];
    for(auto j:adj[i])
    {
        if(!visited[j])
        {
            dfs(adj,j,A,sum);
              A[j]+=sum;
        }
       
        
    }
    sum=sum-A[i];
    
}
int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long int i,j,k,l=0,m,n,p,x,y,sum=0,cnt=0,diff,q;
    cin>>n>>q;
   long long  int A[n+1];
    for(i=0;i<=200000;i++)
    {

        visited[i]=false;
    }
    for(i=0;i<=n;i++)
    {
       A[i]=0;
    }
   vector<long long int> adj[n+1];
    for(i=1;i<n;i++)
    {
        cin>>x>>y;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }
    for(i=0;i<q;i++)
    {
        cin>>x>>y;
        A[x]+=y;
    }
    dfs(adj,1,A,sum);
    for(i=1;i<=n;i++)
    {
        cout<<A[i]<<" ";
    }

    
}


Measured memory_bytes: 30720
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pi pair<int,int>
#define ll long long
#define rep(i,a,b) for(int i=int(a); i<=int(b);i++)
#define repv(vec,v) for(v=(vec).begin(); v!=(vec).end();v++)
#define sz(vec) (int)(vec).size()
#define PB push_back
#define F first()
#define S second()


int a,b ;
void solve(){
	rep(i,2,2000){
		if(int(i*0.08) == a && int(i*0.1) == b){
			cout << i;
			return;
		}
	}
	cout << "-1";
}


int main(){
	cin >> a >> b;

	solve();
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n,p=2019;
	string s;
	cin>>s;
  n=s.size();
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
	}
	map<ll,ll> m;
	m[0]=1;
	ll out=0;
	ll t=0;
	ll ten=1;
	if(p!=2 && p!=5)
	{
	for(ll i=n-1;i>-1;i--)
	{
		t=((t)+(a[i]*ten)%p)%p;
		t=t%p;
		out+=m[t];
		m[t]++;
		ten=(ten*10)%p;
	}
	cout<<out;
	}
	else
	{
		ll out=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i]%p==0)
			{
				out+=i+1;
			}
			
		}
		cout<<out;
	}
	return 0;
}


Measured memory_bytes: 5260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
 
int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};
 
int main(){
    int n;
    cin >> n;
    vector<int> a;
    a.push_back(300);
    rep(i,n) {
        int ai;
        cin >> ai;
        a.push_back(ai);
    }
    a.push_back(-1);
 
    int soko = 1, top = 0;
    ll mon = 1000;
    while(true){
        bool ok = false;
        for(int j = top+1; j <= n; j++){
            if (a[j-1] >= a[j] && a[j] < a[j+1] && !ok){
                ok = true;
                soko = j;
            }
            else if(a[j-1] < a[j] && a[j] >= a[j+1] && ok){
                top = j;
                break;
            }
        }
        if (!ok) break;
        ll kabu = mon / a[soko];
        mon %= a[soko];
        mon += kabu * a[top];
    }
    cout << mon << endl;
}

Measured memory_bytes: 3492
s = input()

if "SSS" in s:
    print(0)
elif "RRR" in s:
    print(3)
elif "SSR" in s:
    print(1)
elif "SRR" in s:
    print(2)
elif "SRS" in s:
    print(1)
elif "RSS" in s:
    print(1)
elif "RSR" in s:
    print(1)
elif "RRS" in s:
    print(2)

Measured memory_bytes: 9060
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, X = MAP()

# a_0 = 1, p_0 = 1
a, p = [1], [1]
for i in range(N):
    # 漸化式
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        if X <= 0:
            return 0
        if X > 0:
            return 1
    elif X <= a[N-1] + 1:
        return f(N-1, X-1)
    elif X > a[N-1] + 1:
        return p[N-1] + 1 + f(N-1, X - (a[N-1] + 1 + 1))

print(f(N, X))


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

const char NL = '\n';
const int MOD = 1e9 + 7;

void solve()
{
    string s; cin >> s;
    int ans = 0, curr = 0;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'R') {
            ++curr;
            ans = max(ans, curr);
        } else {
            curr = 0;
        }
    }
    cout << ans << NL;
}

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

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin>>n;
    ll ans=0;
    for(ll i=1; i*i<=n; i++){
        ans = i*i;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hope the code can get more points.

	Algorithm: 

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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;

int a[MAXN];
ll f[MAXN][2][2];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri, o = 0, t = 1;
	ll inf = 1LL << 62;
	for(int i = 1; i <= n; i++) {
		a[i] = ri;
		for(int x = 0; x < 2; x++)
			for(int y = 0; y < 2; y++)
				f[i][x][y] = -inf;
	}
	for(int i = 1; i <= n; i++) {
		chkmax(f[i][1][0], max(f[i - 1][0][0], f[i - 1][0][1]));
		chkmax(f[i][1][1], max(f[i - 1][0][0], f[i - 1][0][1]));
		if(i > 1) {
			for(int t = 0; t < 2; t++) {
				chkmax(f[i][t][0], f[i - 2][t][0] + a[i - 1]);
				chkmax(f[i][t][1], max(f[i - 2][t][0], f[i - 2][t][1]) + a[i]);
			}
		}
	}
	if(n & 1) cout << max(f[n][1][0], f[n][1][1]) << endl;
	else cout << max(f[n][0][0], f[n][0][1]) << endl;
	return 0;
}

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

typedef pair <int, int> PII;
typedef stack <PII> STACK;

int main() {
    int n;
    while ( cin >> n ) {
        if ( n == 0 ) break;
        STACK S;
        for ( int i = 0; i < n; ++ i ) {
            int g;
            cin >> g;
            if ( i % 2 == 0 ) {
                if ( S.empty() ) {
                    S.push( PII( 1, g ) );
                } else {
                    PII last = S.top();
                    if ( last.second != g ) {
                        S.push( PII( 1, g ) );
                    } else {
                        S.pop();
                        S.push( PII( last.first + 1, g ) );
                    }
                }
            } else {
                PII last = S.top();
                if ( last.second != g ) {
                    int con = 0;
                    while ( last.second != g ) {
                        S.pop();
                        con += last.first;
                        if ( S.empty() ) break;
                        last = S.top();
                    }
                    S.push( PII( con + 1, g ) );
                } else {
                    S.pop();
                    S.push( PII( last.first + 1, g ) );
                }
            }
        }
        
        int answer = 0;
        while ( ! S.empty() ) {
            PII state = S.top();
            S.pop();
            if ( state.second == 0 ) {
                answer += state.first;
            }
        }
        cout << answer << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn lcm(a:i64, b:i64) -> i64 {
    fn gcd(a:i64, b:i64) -> i64 {
        if b==0 { return a; }
        gcd(b, a%b)
    }
    a / gcd(a,b) * b
}

fn main() {
    input!{n:usize, t:[i64;n]};

    let mut ans = 1i64;
    for i in 0..n {
        ans = lcm(ans, t[i]);
    }

    println!("{}", ans);

}

Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
a,b,c,d = LI()
print(max(a*b,c*d))
"""
#B
n = I()
s = S()
ans = 0
x = 0
for i in s:
    if i == "I":x += 1
    else:x-=1
    ans = max(ans,x)
print(ans)
#C
"""
def factor(n):
    i = 2
    m = n
    while m >= i:
        while m%i == 0:
            m //= i
            d[i] += 1
            d[i] %= mod
            if m < i:break
        i += 1
n = I()
d = defaultdict(int)
for i in range(2,n+1):
    factor(i)
ans = 1
for i in d.values():
    ans *= i+1
    ans %= mod
print(ans)
"""

#D
"""
n,a,b = LI()
x = LI()
ans = 0
for i in range(n-1):
    if a*(x[i+1]-x[i]) > b:
        ans += b
    else:
        ans += a*(x[i+1]-x[i])
print(ans)
"""
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 38512
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vii vector<ll> 
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
const int MOD = 1e9 + 7, N = 1e7 + 3;
ll fac[N];

void seive(){
	for(int i = 1; i < N; ++i){
		for(int j = i; j < N; j += i){
			fac[j]++;
		}
	}
}
 
int main(){
    fast;
    unsigned ll n;
    cin >> n;
    unsigned ll ans = 0;
    seive();
    for(int i = 1; i <= n; ++i){
    	// cout << fac[i] << ' ';
    	ans += (i*fac[i]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 81760
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int main() {
  long long x;
  cin >> x;
  long long ans = x;
  while (x > 100) {
    ans = min(ans, abs(753 - (x % 1000)));
    x /= 10;
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
	string s;
	cin >> s;
	vector<bool> al(26);
	rep(i, 26) al.at(i) = false;
	
	rep(i,s.size()){
		al.at((s.at(i)-'a')) = true;
	}

	rep(i, 26){
		if(!al.at(i)){
			cout << (char)(i+'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
 
int main() {
	int n; cin >> n; bool OK = false;
	for (int j = 0; j <= n / 4; j++) {
		for (int k = 0; k <= n / 7; k++) {
			if (4 * j + 7 * k == n) OK = true;
		}
	}
	if (OK == false) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict
from itertools import chain


def fast_prime_set(n):
    # nまでの素数リスト高速版 setで返す
    # chainの読み込みが必要！
    if n < 4:
        return ({}, {}, {2}, {2, 3})[n]
    n_sqrt = int(n ** 0.5) + 1
    primes = {2, 3} | set(chain(range(5, n + 1, 6), range(7, n + 1, 6)))
    for i in range(5, n_sqrt, 2):
        if i in primes:
            primes.difference_update(range(i * i, n, i * 2))
    return primes


def prime_factorization(x):
    # 素因数分解
    # 事前に素数のセットが必要
    primes = fast_prime_set(100)

    fact = defaultdict(int)
    for prime in primes:
        while x % prime == 0:
            fact[prime] += 1
            x //= prime
        if x == 1:
            break
        if x in primes:
            fact[x] += 1
            break
    return fact


n = int(input())
div_c = defaultdict(int)

for i in range(1, n+1):
    for item, cnt in prime_factorization(i).items():
        div_c[item] += cnt

div_c[1] = 0
cnt_div = defaultdict(int)

for c in div_c.values():
    for j in [2,4,14,24,74]:
        cnt_div[j] += c >= j

ans = 0
if cnt_div[4]:
    ans += cnt_div[4] * (cnt_div[4] - 1) // 2 * (cnt_div[2] - 2)
ans += cnt_div[14] * (cnt_div[4] - 1)
ans += cnt_div[24] * (cnt_div[2] - 1)
ans += cnt_div[74]

print(ans)


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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;


int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (b%a==0)cout << a + b << "\n";
    else cout <<  b- a << "\n";
    return 0;
}

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

using namespace std;

int main() {
  double a, b, x; cin >> a >> b >> x;
  
  cout << std::fixed << setprecision(6);
  
  if (x <= a * a * b / 2) {
    cout << atan(b / ((x / a) * 2 / b)) * 180 / M_PI << endl;
  } else {
    cout << atan((((a * a * b - x) / a ) * 2 / a) / a) * 180 / M_PI << endl;
  }
}

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

typedef vector<int> Lista;

const int INF = 1 << 30;

// Nodos indexados de 0 a n - 1.

struct Grafo {

	int n; bool bi;
	vector<Lista> aristas;
	Grafo(int N, bool B = true) : n(N),
		bi(B), aristas(N, vector<int>()) {}

	void AgregarArista(int u, int v) {
		if (bi) aristas[v].push_back(u);
		aristas[u].push_back(v);
	}

	// Detecta un ciclo en la componente conexa
	// del nodo u. Devuelve true si hay ciclo o false
	// si no existe. Al final, si existe un ciclo,
	// este queda guardado en el vector "ciclo".

	Lista ciclo;
	vector<char> color;

	void DetectarCiclo(int u, int p) {
		color[u] = ciclo.empty()? 'G': 'N';

		for (int v : aristas[u]) {
			if (bi && v == p) continue;
			if (ciclo.empty() && color[v] == 'G')
				color[v] = 'A', ciclo.push_back(v),
				color[u] = 'R', ciclo.push_back(u);
			if (color[v] != 'B') continue;

			DetectarCiclo(v, u);
			if (color[u] == 'G' && color[v] == 'R')
				color[u] = 'R', ciclo.push_back(u);
		}
		if (color[u] == 'G') color[u] = 'N';
	}

	bool DetectarCiclo(int u) {
		color.resize(n, 'B'); ciclo = Lista();
		if (color[u] == 'B') DetectarCiclo(u, u);
		reverse(ciclo.begin(), ciclo.end());
		return !ciclo.empty();
	}

	// Busqueda en amplitud.

	Lista BFS(int o) {
		queue<int> q; q.push(o);
	    Lista dist(n, INF); dist[o] = 0;
	    while (!q.empty()) {
	        int u = q.front(); q.pop();
	        for (int v : aristas[u])
	            if (dist[u] + 1 < dist[v])
	                dist[v] = dist[u] + 1,
	                q.push(v);
	    }
	    return dist;
	}

	// Detecta los puentes y puntos de articulacion en
	// un grafo bidireccional. Indices de 0 a n - 1.

	int tiempo;
	Lista low, label;

	vector<Lista> puentes;
	vector<bool> articulaciones;

	int PuentesArticulacion(int u, int p) {
		int hijos = 0;
		label[u] = low[u] = ++tiempo;
		for (int v : aristas[u]) {
			if (v == p) continue;
			if (label[v]) low[u] = min(low[u], label[v]);
			else {
				++hijos;
				PuentesArticulacion(v, u);
				if (label[u] > low[v]) {
					puentes[u].push_back(v);
					puentes[v].push_back(u);
				}
				if (label[u] >= low[v]) {
					articulaciones[u] = true;
				}
				low[u] = min(low[u], low[v]);
			}
		}
		return hijos;
	}

	int PuentesArticulacion() {
		tiempo = 0;
		low = Lista(n);
		label = Lista(n);

		puentes = vector<Lista>(n, Lista());
		articulaciones = vector<bool>(n);

		for (int u = 0; u < n; ++u) {
			if (label[u]) continue;
			int hijos = PuentesArticulacion(u, u);
			articulaciones[u] = hijos > 1;
		}
	}

};

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

	Grafo G(n, false);
	for (int i = 0; i < m; ++i) {
		scanf("%d%d", &u, &v);
		G.AgregarArista(u, v);
	}

	bool ciclo = false;
	for (int i = 0; i < n; ++i)
		ciclo |= G.DetectarCiclo(i);
	printf("%d\n", ciclo);
	return 0;
}

Measured memory_bytes: 3256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if (a + b >= c) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23892
X, K, D = map(int, input().split())

ans = 0

if X < 0:
    X = -X

count = X // D

if count > K:
    ans = X - K * D
else:
    K -= count
    X -= count * D
    if K % 2 == 1:
        K -= 1
        X -= D
    if X < 0:
        X = -X

    if K == 0:
        ans = X
    else:
        ans = min(X, 2 * D - X)

print(ans)

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

const int N = 100000;

int n, a[N];

bool solve() {
  std::vector<int> nums[2];
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    nums[a[i] & 1].push_back(a[i]);
  }
  if (static_cast<int>(nums[1].size()) > 2) {
    return false;
  }
  std::vector<int> a, b;
  if (static_cast<int>(nums[1].size()) >= 2) {
    a.push_back(nums[1][1]);
  }
  for (auto &&x : nums[0]) {
    a.push_back(x);
  }
  if (static_cast<int>(nums[1].size()) >= 1) {
    a.push_back(nums[1][0]);
  }
  for (int i = 0; i < n; ++i) {
    printf("%d%c", a[i], " \n"[i == n - 1]);
  }
  if (n == 1) {
    if (a[0] > 1) {
      b.push_back(a[0] - 1);
    }
    b.push_back(1);
  } else {
    if (a[0] > 1) {
      b.push_back(a[0] - 1);
    }
    for (int i = 1; i < n - 1; ++i) {
      b.push_back(a[i]);
    }
    b.push_back(a[n - 1] + 1);
  }
  int m = static_cast<int>(b.size());
  printf("%d\n", m);
  for (int i = 0; i < m; ++i) {
    printf("%d%c", b[i], " \n"[i == m - 1]);
  }
  return true;
}

int main() {
  while (scanf("%*d%d", &n) == 1) {
    if (!solve()) {
      puts("Impossible");
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;
const int MOD = 1000000007;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}


int main() {
    int n,q; cin >> n >> q;
    string s; cin >> s; int ans = 0;vector<int> v(n,0);
    for(int i = 1;i < s.length();i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            v[i] = v[i-1] + 1;
        }else{
            v[i] = v[i-1];
        }
    }
    for(int i = 0;i < q;i++){
        int d,f; cin >> d >> f;
        cout << v[f-1]-v[d-1] << endl;
    }
}


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

int main() {
  string S;
  cin>>S;
  vector<string> A{"SUN","MON","TUE","WED","THU","FRI","SAT"};
  int j;
  rep(i,7){
    if(S==A.at(i)){
      j=i;
    }
  }
  cout<<7-j<<endl;
  
}



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

int n;
int a[(int)2e5];

int main() {
    cin >> n;
    rep(i, n) cin >> a[i];

    int middle = n / 2;
    if (n % 2 == 0) middle--;

    for (int i = 0; i <= middle; i++) {
        printf("%d ", a[n - 1 - 2 * i]);
    }

    int size = (n - 1) - middle;
    for (int i = 0; i < size; i++) {
        printf("%d ", a[n - size * 2 + i * 2]);
    }
}

Measured memory_bytes: 2944
#include <stdio.h>

int n;

int main() {
    while(true) {
        scanf("%d",&n);
        if(n<=0) break;
        int ans = 0;
        bool up = true;
        int l=0,r=0;
        for(int i = 0; i < n; i++) {
            char act[4];
            scanf("%s",&act);
            bool isl = act[0]=='l';
            bool isu = act[1]=='u';
            if(isl) l+=(isu^up)?-1:1;
            else r+=(isu^up)?-1:1;
            if(l+r==2) {
                ans += 1;
                l=0; r=0;
                up=!up;
            }
            //printf("%3d%3d%3d\n",l,r,ans);
        }
        //ans += l+r;
        printf("%d\n",ans);
    }
}


Measured memory_bytes: 2648
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
    int n;
    int w;
    cin >> n >> w;
    vector<int> weight(n);
    vector<int> value(n);
    vector<vector<long long>> dp(n+1, vector<long long>(w+1));
    rep(i, n) {
        rep(j, w) {
            dp[i][j] = 0;
        }
    }
    
    rep(i, n) {
        cin >> weight[i];
        cin >> value[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= w; j++) {
            if(j - weight[i] >= 0) { 
                dp[i+1][j] = max(dp[i][j], dp[i][j-weight[i]] + value[i]);
            }
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
        }
    }
    cout << dp[n][w] << endl;
    return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using  namespace std;
typedef long long ll;
#define RAP(i, n) for(ll i=0;i<(n);i++)
#define FOR(i, a, b) for(ll i=(a);i<(b);i++)

ll gcd(ll a, ll b){
  ll temp;
  while(a%b != 0){
    temp = b;
    b = a%b;
    a = temp;
  }
  return b;
}
ll pf(ll x){
  ll count = 1;
  ll temp = x;
  bool check;
  for(ll i=2;i*i<x;i++){
    check = false;
    while(temp%i==0){
      temp /= i;
      check =true;
    }
    if(check){
      count++;
    }
  }
  if(temp!=1){
    count++;
  }
  return count;
}

int main(){
  ll a, b;
  cin >> a >> b;
  cout << pf(gcd(a, b)) << endl;
  return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    vector<int> a(n, 0), b(n, 0);
    vector<vector<int> > g(n);
    for (int i = 0; i < m; ++i) {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < g[i].size(); ++j) {
            int to = g[i][j];
            if (s[to] == 'A')
                ++a[i];
            else
                ++b[i];
        }
    }
    vector<int> bad(n, 0);
    queue<int> q;
    for (int i = 0; i < n; ++i) {
        if ((a[i] == 0) || (b[i] == 0)) {
            bad[i] = 1;
            q.push(i);
        }
    }
    while (!q.empty()) {
        int v = q.front();
        q.pop();
        for (int i = 0; i < g[v].size(); ++i) {
            int to = g[v][i];
            if (s[v] == 'A')
                --a[to];
            else
                --b[to];
            if ((a[to] == 0) || (b[to] == 0)) {
                if (bad[to] == 0) {
                    bad[to] = 1;
                    q.push(to);
                }
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (bad[i] == 0) {
            cout << "Yes\n";
            return;
        }
    }
    cout << "No\n";

    
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 12880
from sys import stdin,setrecursionlimit
import heapq

x,y,a,b,c = map(int,stdin.readline().rstrip().split())

p = list(map(int,stdin.readline().rstrip().split()))
q = list(map(int,stdin.readline().rstrip().split()))
r = list(map(int,stdin.readline().rstrip().split()))

p.sort()
q.sort()
r.sort(reverse = True)

p = p[a-x:]
q = q[b-y:]

heapq.heapify(p)
heapq.heapify(q)

for i in r:
    if p[0] <= q[0]:
        if i > p[0]:
            heapq.heappop(p)
            heapq.heappush(p,i)
    else:
        if i > q[0]:
            heapq.heappop(q)
            heapq.heappush(q,i)

print(sum(p)+sum(q))

Measured memory_bytes: 103072
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a:A) cin >> a;} 

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


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

int N, u, v; cin >> N >> u >> v;
VVI G(N+1);
rep(_, 0, N-1){
    int a, b; cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
}

VI Adist(N+1, -INF); 
VI Tdist(N+1, -INF); 
Adist[v] = 0; // 初期条件
Tdist[u] = 0; // 初期条件
queue<int> que;
que.push(u);
while (!que.empty()) {
    int v = que.front(); 
    que.pop();
    for (int nv : G[v]) {
        if (Tdist[nv] != -INF) continue;
        Tdist[nv] = Tdist[v] + 1;
        que.push(nv);
    }
}

que.push(v); 
while (!que.empty()) {
    int v = que.front(); 
    que.pop();
    for (int nv : G[v]) {
        if (Adist[nv] != -INF) continue;
        Adist[nv] = Adist[v] + 1;
        que.push(nv);
    }
}


i64 d = 0;
rep(i, 1, N+1){
    if (Adist[i] >= Tdist[i])
        d = max(d, Adist[i]);
}

cout <<d - 1 << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索。逆から考える。
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
const lint mod=1e9+7;

int main()
{
  std::vector<std::vector<int>> a(3,std::vector<int>(3));
  REP(i,3) cin >> a[i][0] >> a[i][1] >> a[i][2];
  int n;
  cin >> n;
  std::vector<int> b(n);
  REP(i,n) cin >> b[i];

  std::vector<std::vector<int>> res(3,std::vector<int>(3,0));
  REP(i,n){
    REP(j,3){
      REP(k,3){
        if(a[j][k] == b[i]) res[j][k] = 1;
      }
    }
  }

  bool flg = false;
  REP(i,3){
    if(res[i][0] == 1 && res[i][1] == 1 && res[i][2] == 1) flg = true;
    if(res[0][i] == 1 && res[1][i] == 1 && res[2][i] == 1) flg = true;
  }
  if(res[0][0] == 1 && res[1][1] == 1 && res[2][2] == 1) flg = true;
  if(res[0][2] == 1 && res[1][1] == 1 && res[2][0] == 1) flg = true;

  if(flg) cout << "Yes\n";
  else cout << "No\n";
  return 0;
}


Measured memory_bytes: 256
# B - Shift only
# coding: utf-8

N = int(raw_input())
A = map(int, raw_input().split())
result = 0

while True:
  flug = 0
  for i in range(N):
    if A[i] %2 == 1 : flug = 1
    A[i] = A[i] / 2
  if flug == 1 :break
  result += 1

print result

Measured memory_bytes: 2696
#include<stdio.h>
int main(){
 int i,j,k,l,m;
 int n[1000],x[1000];
 int sum;
 int num[1000];

 for(i=0;i<=1000;i++){
  scanf("%d %d",&n[i],&x[i]);
  if(n[i]==0 && x[i]==0){
   l=i;
   break;
  }
 }

for(m=0;m<l;m++){

 for(i=1;i<=n[m]-2;i++){

  for(j=i+1;j<=n[m]-1;j++){

   for(k=j+1;k<=n[m];k++){
    sum=0;
    sum+=i+j+k;
    if(sum==x[m]){
     num[m]+=1;
    }
   }
  
  }

 }
}

for(m=0;m<l;m++){
 printf("%d\n",num[m]);
}

return 0;
}

Measured memory_bytes: 612