akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int>P;
bool used[100009];
int main(){
	int n,f=0;
	cin>>n;
	int a[n];
	vector<int>v,w,q;
	vector<P>r;
	if(n==3){
		cout<<2<<' '<<5<<' '<<63<<endl;
		return 0;
	}
	for(int i=2;i<=30000;i++){
		if(i%2==0)v.push_back(i);
		else if(i%3==0&&i!=3&&i!=9)w.push_back(i);
	}
	for(int i=0;i<(int)v.size();i++){
		if(v[i]%3==0){
			q.push_back(v[i]);
			v.erase(v.begin()+i);
			i--;
		}
	}
	for(int i=0;i<v.size();i++)if(!used[i]){
		for(int j=v.size()-1;j>i;j--)if(!used[j]){
			if((v[i]+v[j])%3==0){
				used[i]=1;
				used[j]=1;
				r.push_back(P(v[i],v[j]));
				goto L;
			}
		}L:;
	}
	int p=0;
	cout<<3<<' '<<9;
	n-=2;
	while(n){
		if(n>=2&&r.size()>=1){
			cout<<' '<<r[0].first<<' '<<r[0].second;
			r.erase(r.begin());
			n-=2;
		}
		else if(w.size()){
			if(n==1&&p%2==0)goto LL;
			cout<<' '<<w[0];
			w.erase(w.begin());
			n--;
			p++;
		}
		else if(q.size()){
			LL:;
			cout<<' '<<q[0];
			q.erase(q.begin());
			n--;
		}
	}cout<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >


using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=2e5+10,mod=1e9+7;


int main ()
{
    FASTIO
    int n;
    cin >> n;
    string s;
    cin >> s;
    int ans=0;
    for(int i=0;i<n-2;i++){
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')ans++;
    }
    cout << ans << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;


using namespace std;

#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop(i,n) for(int i=0;i<(int)(n);i++)
#define foi(i,k,n) for(int i=(k); i<(int)(n); i+=1)
#define fod(i,n,k) for(int i=k; i>=(int)n; i-=1)
#define fast_io ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define endl "\n"

#define int long long
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

#define fir first
#define sec second
#define pb push_back
#define mp make_pair

typedef long long llint;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<llint> VL;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef set<int> SI;
string tostr(int n) {stringstream rr;rr<<n;return rr.str();}
llint toint(string s) {stringstream ss(s); llint x; ss >> x; return x;}
//typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//gp_hash_table<string, llint> table;


//int mpow(llint base, llint exp) {
  //base %= MOD;
  //llint result = 1;
  //while (exp > 0) {
    //if (exp & 1) result = ((llint)result * base) % MOD;
    //base = ((llint)base * base) % MOD;
    //exp >>= 1;
  //}
  //return result;
//}


//void makegraph(int n, int m){
	//int i, u, v;
	//while(m--){
		//cin>>u>>v;
		//u--, v--;
		//g[u].pb(v);
		//g[v].pb(u);
	//}
//}

//void dfs(int u, int par){
	//for(int v:g[u]){
		//if (v == par) continue;
		//dfs(v, u);
	//}
//}


// ------------------------------------------------------------------ILB----------------------------------------------------------------  //



void solve(){
	char c;
	cin >> c;
	if(c >= 'a' && c <= 'z'){
		cout << 'a';
	}
	else cout <<'A';
}




int32_t main() {
	fast_io;
    int t = 1;
    //cin >> t;
    //int xx = 0
    while(t--) {
		//xx++;
		//cout << "Case ";
      solve();
    }
    return 0;
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  long sum = 0;
  int data;
  for (int i = 0; i < M; i++) {
    cin >> data;
    sum += data;
  }
  N -= sum;
  if (N < 0) {
    cout << -1 << endl;
  } else {
    cout << N << endl;
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a.at(i);
  }
  vector<int> b(n);
  for(int i = 0; i < n; i++){
    cin >> b.at(i);
  }
  vector<int> c(n - 1);
  for(int i = 0; i < n - 1; i++){
    cin >> c.at(i);
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += b.at(i);
  }
  for(int i = 0; i < n - 1; i++){
    if(a.at(i) + 1 == a.at(i + 1)){
      int j = a.at(i) - 1;
      ans += c.at(j);
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
n = gets.to_i

a = gets.split.map(&:to_i)
b = gets.split.map(&:to_i)

h = Hash.new(0)
u = Hash.new(0)
a.each {|e| u[e] += 1}
b.each {|e| h[e] += 1; u[e] += 1}

h = h.sort{|x, y| u[x[0]] != u[y[0]] ? u[y[0]] <=> u[x[0]] : y[0] <=> x[0]}

lim = h.size
i = 0

j = 1
j += 1 while j < lim && h[j][1] == 0

l = 0
ans = []
n.times do |k|
    if a[k] == h[i][0] && j == lim
        l += 1 while a[l] != a[k] && ans[l] == a[k]
        
        if a[l] == a[k]
            puts "No"
            exit
        end
        ans << ans[l]
        ans[l] = h[i][0]
        h[i][1] -= 1
        i += 1 while i < lim && h[i][1] == 0
    elsif a[k] == h[i][0]
        ans << h[j][0]
        h[j][1] -= 1
        j += 1 while j < lim && h[j][1] == 0
    else
        ans << h[i][0]
        h[i][1] -= 1
        i += 1 while i < lim && h[i][1] == 0
        if i >= j
            j = i + 1
            j += 1 while j < lim && h[j][1] == 0
        end
    end
end

puts "Yes"
puts ans * " "


Measured memory_bytes: 61996
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define jkl int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll n;
    ll a[102];
    ll ans = mod, cnt;
    ll min_j;
    cin >> n;
    REP(i, n)cin >> a[i];
    rep(j, -100, 101){
        cnt = 0;
        REP(i, n)cnt += pow(j - a[i], 2);
        if(cnt > ans)continue;
        ans = cnt;
        min_j = j;
    }
    print(ans);
}

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

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

  for (int turn = 0; turn < K; turn++)
  {
    if (turn % 2 == 0)
    {
      if (A % 2 != 0)
      {
        A--;
      }
      B += A / 2;
      A /= 2;
    }
    else
    {
      if (B % 2 != 0)
      {
        B--;
      }
      A += B / 2;
      B /= 2;
    }
  }

  cout << A << " " << B << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
 
def factorize(n):
    a = 2
    fct = []
    while a*a <= n:
        # print('-------')
        while n % a == 0:
            n = n // a
            fct.append(a)
        a += 1
    if n > 1:
        fct.append(n)
    return fct
 
 
n = int(input())
c = Counter(factorize(n))
# print(factorize(n))
# print(c.values())


ans = 0
for v in c.values():
    t = 1
    while v >= t:
        v -= t
        t += 1
        ans += 1
print(ans)

Measured memory_bytes: 9468
n = int(input())


def calc():
    for y in range(1, 3501):
        for z in range(1, 3501):
            up = n * y * z
            dn = 4 * y * z - n * (y + z)
            if dn <= 0:
                continue
            if up % dn == 0:
                ans = [y, z, up // dn]
                return ans


ans = calc()
print(*ans, sep=" ")


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long
using namespace std;

signed main() {
	int N;
	cin >> N;
	if(N < 10) {
		cout << N << endl;
	}
	else if(N < 100) {
		cout << 9 << endl;
	}
	else if(N < 1000) {
		cout << 9 + N - 100 + 1 << endl;
	}
	else if(N < 10000) {
		cout << 909 << endl;
	}
	else if(N < 100000){
		cout << 909 + N - 10000 + 1 << endl;
	}
  	else {
      	cout << 90909 << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll  long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<int,int>
using namespace std;

#define maxn 200005
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
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;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}
ull a[maxn];
const ll maxx=1e18;
bool flow(ull a, ull b) {
    if (ULLONG_MAX/a<b) {
        return true;
    }
    ull ans = a*b;
    if (ans>maxx) {
        return true;
    }
    return false;
}
main() {
    int n;
    cin>>n;
    int f=1;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        if (a[i]==0) f=0;
    }
    if(f==0){
    	cout<<0<<endl;
    	return 0;
	}
    ll ans=1;
    for (int i=0;i<n;i++) {
        if (flow(ans,a[i])) {
            cout<<"-1"<<endl;
            return 0;
        }
        ans*=a[i];
    }
    cout<<ans<<endl;


}
 

Measured memory_bytes: 4392
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main(void) {
  int lenW,lenT[1001],countT,i = 0,j = 0,k,a = 0,b = 0,c;
  char W[11],T[1001][1001],smallT[1001][1001],shortT[11];
  fgets(W,12,stdin);
  lenW = strlen(W) - 1;

  for(j = 0; j < 1001; j++){
    T[i][j] = getchar();
    if(T[i][j - 10] == 'E' && T[i][j - 9] == 'N' && T[i][j - 8] == 'D' && T[i][j - 7] == '_' && T[i][j - 6] == 'O' && T[i][j - 5] == 'F' && T[i][j - 4] == '_' && T[i][j - 3] == 'T' && T[i][j - 2] == 'E' && T[i][j - 1] == 'X' && T[i][j] == 'T'){
      countT = i;
      break;
    }
    smallT[i][j] = tolower(T[i][j]);
    if(T[i][j] == ' ' || T[i][j] == '\n'){
      lenT[i] = j;
      i++;
      j = 0;
    }
  }

  for(i = 0; i < countT; i++){
    if(i == 0)c = 1;
    else c = 0;
    for(j = 0; j < lenW; j++){
      if(lenW != lenT[i] - 1 + c)break;
      if(W[j] == smallT[i][j + 1 - c]){
        b++;
      }
      else{
        b = 0;
        break;
      }
      if(b == lenW){
        a++;
      }
    }
    b = 0;
  }
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)                                 //g++ template.cpp -o template.exe
#define zeroes(x) memset(x,0,sizeof(x))                                        //all elements to 0  |  \
#define all(x) (x).begin(), (x).end()
typedef long long int ll;
typedef long double ld;
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;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;
#define MAX 50







bool sortbysec(const pair<int,int> &a,                         //sorting of elements wrt second
              const pair<int,int> &b)
{
    return (a.second < b.second);
}


void out(long long int n)
{
    char str[MAX];
    long long int i = 0;  
 
    while (n > 0) {
       
        long long int rem = n % 26;
 
         
        if (rem == 0) {
            str[i++] = 'z';
            n = (n / 26) - 1;
        }
        else
        {
            str[i++] = (rem - 1) + 'a';
            n = n / 26;
        }
    }
    str[i] = '\0';
 
   
    reverse(str, str + strlen(str));
    cout << str << endl;
 
    return;
}




int main()
{
long long int n;
cin>>n;
out(n);

return 0;
}

Measured memory_bytes: 3636
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	a := nextInt()
	b := nextInt()
	c := nextInt()

	if a%2 == 0 || b%2 == 0 || c%2 == 0 {
		fmt.Println(0)
		return
	}

	fmt.Println(min(a*b, min(b*c, c*a)))

}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

using namespace std;

int main()
{
    int N, K;
    cin >> N >> K;
    int p[N];
    double kitai[N];
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
        kitai[i] = (p[i] + 1.0) / 2.0;
    }
    double ans = 0.0;
    double memo[K];
    for (int i = 0; i < N - K + 1; i++)
    {
        double tmp = 0.0;
        for (int j = 0; j < K; j++)
        {
            if (i == 0)
            {
                tmp += kitai[i + j];
            }
            else
            {
                tmp = memo[i-1] - kitai[i-1] + kitai[i+K-1];
                break;
            }
            
        }
        memo[i] = tmp;
        ans = max(ans, tmp);
    }
    cout << std::fixed << std::setprecision(15) << ans << endl;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main(void){
        int age, a, b;
        scanf("%d", &age);
        if(age == 1)    printf("Hello World\n");
        else {
                scanf("%d", &a);
                scanf("%d", &b);
                printf("%d\n", a+b);
        }
        return 0;
}

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

typedef long long ll;
const int MAX = 12e5 + 5;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int> (M));
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    int min_cost = MAX;
    for (int mask = 0; mask < (1 << N); mask++) {
        bool possible = true;
        int cost = 0;
        vector<int> level(M);
        for (int i = 0; i < N; i++) {
            if (mask & (1 << i)) {
                for (int j = 0; j < M; j++) {
                    level[j] += A[i][j];
                }
                cost += C[i];
            }
        }
        for (int j = 0; j < M; j++) {
            if (level[j] < X) {
                possible = false;
            }
        }
        if (possible) {
            min_cost = min(cost, min_cost);
        }
    }
    cout << (min_cost == MAX ? -1 : min_cost);
}


Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include<bitset>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int a,b,c,d;
	scan(a>>b>>c>>d);
	rep(i,INF){
		if(i%2==0){
			c-=b;
		}
		else{
			a-=d;
		}
		if(a<=0){
			prin("No");
			return 0;
		}
		else if(c<=0){
			prin("Yes");
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3624
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>
#define typeof(x) __typeof__(x)
#define int long long int
#define mod(x) ((x % MOD) + MOD) % MOD
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);--i)

#define ALL(c) (c).begin(),(c).end()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define PB push_back
#define MP make_pair
#define vec vector

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using namespace std;

typedef pair<int,int> P;
struct edge {
  int to, cost;
};

const int INF = 1e18;
const int MOD = 1e9+7;

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
  int len = v.size();
  s << "[";
  for (int i = 0; i < len; i++) {
    s << v[i]; if (i < len - 1) s << " ";
  }
  s << "]";
  return s;
}

class BIT
{
  private:
    vector<int> bit;
    int len;
  public:
    BIT(int n) {
      len = n+1;
      bit = vector<int>(len);
    }
    void add(int i, int x) {
      i += 1;
      while (i < len) {
        bit[i] += x;
        i += i & -i;
      }
    }
    int sum(int i) {
      i += 1;
      int s = 0;
      while (i > 0) {
        s += bit[i];
        i -= i & -i;
      }
      return s;
    }
};

signed main()
{
  int N, K; cin >> N >> K;
  vec<int> a(N);
  rep(i, 0, N) {
    cin >> a[i];
    a[i] -= K;
  }

  vec<int> s(N+1);
  s[0] = 0;
  rep(i, 0, N) {
    s[i+1] = s[i] + a[i];
  }
  vec<int> s_copy(N+1);
  copy(ALL(s), s_copy.begin());
  UNIQUE(s_copy);

  vec<int> t(N+1);
  rep(i, 0, N+1) {
    t[i] = LB(s_copy, s[i]);
  }


  BIT bit(SZ(s_copy));
  int ans = 0;
  rep(i, 0, N+1) {
    ans += bit.sum(t[i]);
    bit.add(t[i], 1);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8064
//https://atcoder.jp/contests/abc131/tasks/abc131_f

#include<bits/stdc++.h>

using namespace std;

#define int long long
typedef pair<int, int> p;
#define x first
#define y second

vector<int> par;

int find(int a){
	if(par[a] == -1) return a;
	par[a] = find(par[a]);
	return par[a];
}

void merge(int a, int b){
	a = find(a);
	b = find(b);
	if(a == b) return;
	par[b] = a;
}


signed main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin>>n;
	vector<p> a(n);
	vector<vector<int> > hf(1e5+1), vf(1e5+1);
	for(int i = 0; i < n; i++){
		cin>>a[i].x>>a[i].y;
		hf[a[i].x].push_back(i);
		vf[a[i].y].push_back(i);
	}
	par = vector<int>(n, -1);
	for(int i = 0; i < hf.size(); i++){
		for(int j = 0; j < ((int)hf[i].size())-1; j++){
			//cout<<"lol"<<endl;
			//cout<<"MERGING "<<hf[i][j]<<" "<<hf[i][j+1]<<endl;
			merge(hf[i][j], hf[i][j+1]);
		}
	}
	for(int i = 0; i < vf.size(); i++){
		for(int j = 0; j < ((int)vf[i].size())-1; j++){
			merge(vf[i][j], vf[i][j+1]);
		}
	}
	
	//for each point, find the valid component and add it to the set
	vector<int> csz(n);
	vector<set<int> > hs(n), vs(n);
	vector<int> triggered(n, 0);
	for(int i = 0; i < n; i++){
		int lead = find(i);
		//cout<<"COMP "<<i<<" "<<lead<<endl;
		csz[lead]++;
		hs[lead].insert(a[i].x);
		vs[lead].insert(a[i].y);
		if(hf[a[i].x].size() > 1 && vf[a[i].y].size() > 1){
			triggered[lead] = 1;
		}
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(find(i) != i) continue;
		if(triggered[i] == 0) continue;
		ans += ((int)hs[i].size())*((int)(vs[i].size())) - csz[i];
	}
	cout<<ans<<endl;
	
}


Measured memory_bytes: 26624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  char s;
  cin >> s;
  int n=s;
  char ans=s+1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstring>
using namespace std;
const int N=105;
int n,m,x,B[N][N],lf[N],C[N][N],d[N],f[N];
bool vis[N],e[N][N];
vector<int>vec[N][N];
bool dfs(int v){
	for(int i=1;i<=n;++i)
	if(!vis[i]&&e[v][i]){
		vis[i]=1;
		if(!lf[i]||dfs(lf[i])){
			lf[i]=v;
			return 1;
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j)
		cin>>x,vec[i][(x-1)/m+1].push_back(x);
	}
	for(int i=1;i<=m;++i){
		memset(e,0,sizeof e);
		for(int j=1;j<=n;++j)
		for(int k=1;k<=n;++k)e[j][k]=!vec[j][k].empty();
		memset(lf,0,sizeof lf);
		for(int j=1;j<=n;++j){
			memset(vis,0,sizeof vis);
			dfs(j);
		}
		for(int j=1;j<=n;++j){
			d[lf[j]]=f[j]=vec[lf[j]][j].back();
			vec[lf[j]][j].pop_back();
		}
		for(int j=1;j<=n;++j)B[j][i]=d[j],C[j][i]=f[j];
	}
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)
	cout<<B[i][j]<<" \n"[j==m];
	for(int i=1;i<=n;++i)
	for(int j=1;j<=m;++j)
	cout<<C[i][j]<<" \n"[j==m];
	return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;
    string ans = "Yes";
    if(N % 2 == 1) ans = "No";
    N /= 2;
    rep(i, N){
      if(S[i] != S[N + i]) ans = "No";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline void Max(T &a, T b){if(a < b) a = b;}
template <typename T> inline void Min(T &a, T b){if(a > b) a = b;}
const int N = 4e5 + 7;
int n, m, ans;
int adv[N << 2], mx[N << 2];
#define Ls o << 1
#define Rs (o << 1 | 1)
void st1(int o, int v) {
	adv[o] += v;
	mx[o] += v;
}
void pushdown(int o) {
	if(!adv[o]) return;
	st1(Ls, adv[o]);
	st1(Rs, adv[o]);
	adv[o] = 0;
}
void pushup(int o) {
	mx[o] = max(mx[Ls], mx[Rs]);
}
void build(int l, int r,int o){ 
	if(l == r) {
		mx[o] = l;
		return;
	}int mid = l + r >> 1;
	build(l, mid, Ls);
	build(mid + 1, r, Rs);
	pushup(o);
}
void modify(int L, int R, int l, int r,int o, int v) {
	if(L > R) return;
	if(L <= l && r <= R) {
		st1(o, v);
		return;
	}
	pushdown(o);int mid = l + r >> 1;
	if(L <= mid) modify(L, R, l, mid, Ls, v);
	if(R > mid)  modify(L, R, mid + 1, r, Rs, v);
	pushup(o);
}
int query(int L, int R, int l, int r, int o) {
	if(L > R) return 0;
	if(L <= l && r <= R) return mx[o];
	pushdown(o);int mid = l + r >> 1;
	if(R <= mid) return query(L, R, l, mid, Ls);
	if(L > mid)  return query(L, R, mid + 1, r, Rs);
	return max(query(L, R, l, mid, Ls), query(L, R, mid + 1, r, Rs));
}
vector<int> h[N];
int main() {
#ifndef ONLINE_JUDGE
#endif
	n = gi(), m = gi();
	rep(i, 1, n) {
		int l = gi(), r = gi();
		h[l].pb(r);
	}
	build(0, m + 1, 1);
	rep(l, 0, m + 1) {
		for(auto r: h[l] ) {
			modify(0, r, 0, m + 1, 1, 1);
		}
		Max(ans, query(l + 1, m + 1, 0, m + 1, 1) - l - m - 1);
	}
	printf("%d\n", max(n - m, ans));
	return 0;
}

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

//#define DEBUG

void solve(long long N, std::vector<long long> A){
    long long sumDiff = 0;
    long long current = A[0];
    for(long long i = 1; i < A.size(); i++) {
        
        #ifdef DEBUG
            cout << "i=" << i << " A[i]=" << A[i] << " current=" << current << " sumDiff=" << sumDiff << endl;
        #endif

        if(current > A[i]) {
            long long diff = current - A[i];
            current = A[i] + diff;
            sumDiff += diff;
        } else {
            current = A[i];
        }
    }
    cout << sumDiff << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 4860
from itertools import product
s = list(input())
n = len(s)-1

for x in list(product(["+", "-"], repeat=n)):
    x = list(x)
    x.append("")
    
    strs = [i+j for i, j in zip(s, x)]
    if eval("".join(strs)) == 7:
        print("".join(strs) + "=7")
        break


Measured memory_bytes: 3060
n = int(input())
x = [0]*n
l = [0]*n
for i in range(n):
    x[i] , l[i] = map(int, input().split())
itv = [[0 for i in range(2)] for j in range(n)]
for i in range(n):
    a = x[i]+l[i]
    b = x[i]-l[i]
    itv[i][0] = a
    itv[i][1] = b
itv.sort()

ans = 0
curx = -10000000000

for i in range(n):
    if curx <= itv[i][1]:
        curx = itv[i][0]
        ans += 1
        
print(ans)

Measured memory_bytes: 59480
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();

            var A = cin.nextInt();
            var P = cin.nextInt();

            var pies = A * 3;
            var total = pies + P;
           

            Console.WriteLine(total /2);
        }
    }
    
    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }
    public static class ListExtensions
    {

        public static T Dequeue<T>(this IList<T> self)
        {
            var result = self[0];
            self.RemoveAt(0);
            return result;
        }


        public static void Enqueue<T>(this IList<T> self, T item)
        {
            self.Add(item);
        }


        public static T Peek<T>(this IList<T> self)
        {
            return self[0];
        }
    }

}


Measured memory_bytes: 13140
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, M = get_ints
A = get_ints

sum = 0
A.each do |a|
  sum += a
end

if sum > N
  puts '-1'
else
  puts N - sum
end


Measured memory_bytes: 14832
import java.io.File;
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.Scanner;
 
/*
 * メモ
 * Scanner:nextは空白か改行までの単語
 * String[][] c = new String[h][w];
 * TemplateMain,"template_input.txt"
 * 0.5 == 1.0/2
 * Integer.valueOf(char)はダメ、(String)
 */
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a > b){
			int d = b;
			b = a;
			a = d;
		}
		if(a > c){
			int d = a;
			a = c;
			c = d;
		}
		if(b > c){
			int d = b;
			b = c;
			c = d;
		}
		System.out.println(a + " " + b + " " + c);
		
	}
}


Measured memory_bytes: 26248
#include<iostream>
#include<string>
using namespace std;
int main(){
    std:string S;
    int ans=0;
    cin >> S;
    for(int i=0;i<4;i++){
        if(S[i]=='+'){
            ans++;
        }
        else if(S[i]=='-'){
            ans--;
        }
    }
    cout << ans << endl;
    return 0;
}

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


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    long long ans = 0;
    string s;
    map<string, long long> maps;

    cin >> n;

    while (n--) {
        cin >> s;
        sort(s.begin(), s.end());
        maps[s]++;
    }

    for (auto it = maps.begin(); it != maps.end(); it++) {
        ans += (it->second * (it->second-1)) / 2;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 11264
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    string s;
    cin >> s;

    int res = 1e8;

    int cnt = 0;
    REP(i, s.size())
    {
        if ((s[i] == '0') == i % 2)
            cnt++;
    }

    res = min(res, cnt);

    cnt = 0;
    REP(i, s.size())
    {
        if ((s[i] == '1') == i % 2)
            cnt++;
    }

    res = min(res, cnt);

    cout << res << endl;

    return 0;
}

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

int main() {
  ll n, m,k;
  cin >> n >> m >> k;
  vector<ll> a(n+1, 0);
  vector<ll> b(m+2, 0);
  b[m+1] = INF;
  rep(i, n){
    ll num;
    cin >> num;
    a[i + 1] = a[i] + num;
  }
  rep(i, m){
    ll num;
    cin >> num;
    b[i + 1] = b[i] + num;
  }
  int ans = 0;
  rep(i, n+1){
    if(a[i] > k){
      break;
    }
    ll tmp = k - a[i];
    int left = 0;
    int right = m+1;
    while (right - left > 1){
      int mid = (left + right) / 2;
      if(tmp >= b[mid]){
        left = mid;
      }else{
        right = mid;
      }
    }
    ans = max(ans, i + left);
  }
  cout << ans << endl;
}

Measured memory_bytes: 6424
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
map<long long, int> ma;

int main() {
	while (cin >> N) {
		ma.clear();
		for (int i = 0; i < N; ++i) {
			long long a;
			cin >> a;
			ma[-a]++;
		}
		long long big[2] = { 0 };
		for (int i = 0; i < 2; ++i) big[i] = 0;
		int iter = 0;
		for (map<long long, int>::iterator it = ma.begin(); it != ma.end(); ++it) {
			while (it->second >= 2) {
				big[iter++] = it->first;
				it->second -= 2;
				if (iter >= 2) break;
			}
			if (iter >= 2) break;
		}
		cout << big[0] * big[1] << endl;
	}
}

















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

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    if(a + b + c >= 22) cout << "bust" << '\n';
    else cout << "win" << '\n';
}

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


Measured memory_bytes: 256
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]


n = int(input())
power = 1
for i in range(1,n+1):
    power = (power * i)%(10**9+7)

print(power)



Measured memory_bytes: 9144
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        Map<String, Integer> c = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String s = in.next();
            c.put(s, c.getOrDefault(s, new Integer("0")) + 1);
        }

        int m = in.nextInt();
        for (int i = 0; i < m; i++) {
            String s = in.next();
            c.put(s, c.getOrDefault(s, new Integer("0")) - 1);
        }

        int max = 0;
        for (int a : c.values()) {
            max = Math.max(max, a);
        }
        out.println(max);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

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

int main()
{
	double x1,y1,x2,y2,x3,y3,xp,yp;
	char a[40],b[40],c[40],d[40];
	while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp)==8)
	{
		sprintf(a,"%.3lf",fabs(x1*(y2-y3)-x2*(y1-y3)+x3*(y1-y2)));
		sprintf(b,"%.3lf",fabs(x1*(y2-yp)-x2*(y1-yp)+xp*(y1-y2)));
		sprintf(c,"%.3lf",fabs(x1*(yp-y3)-xp*(y1-y3)+x3*(y1-yp)));
		sprintf(d,"%.3lf",fabs(xp*(y2-y3)-x2*(yp-y3)+x3*(yp-y2)));
		sscanf(a,"%lf",&xp);
		sscanf(b,"%lf",&x1);
		sscanf(c,"%lf",&x2);
		sscanf(d,"%lf",&x3);
		if (xp==x1+x2+x3)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}
	return 0;
}

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

using namespace std;

const int N = 1e5 + 6;

vector< int > child[N];
vector< int > depth[N];

int dfs(int v) {
  int ret = 0;
  for (int u : child[v]) {
    depth[v].push_back(dfs(u));
  }
  sort(depth[v].begin(), depth[v].end());
  for (int i = 0; i < depth[v].size(); i++) {
    ret = max(ret, depth[v][i]) + 1;
  }
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    child[p].push_back(i);
  }
  printf("%d\n", dfs(0));

  return 0;
}

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

template<class T> inline bool chmin(T& a, const T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

int h[100010];
int dp[100010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
	}
	const int INF = 1 << 29;
	for(int i = 0; i < n; i++) {
		dp[i] = INF;
	}
	dp[0] = 0;
	dp[1] = abs(h[0]-h[1]);
	for(int i = 2; i < n; i++) {
		chmin(dp[i], dp[i-1] + abs(h[i]-h[i-1]));
		chmin(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
	}
	printf("%d\n", dp[n-1]);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define MAXN 200005
#define mo 994711
//#define ivorysi
using namespace std;
typedef unsigned long long int64;
typedef long double db;
typedef unsigned int u32;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    	if(c == '-') f = -1;
    	c = getchar();
    }
    while(c >= '0' && c <= '9') {
    	res = res * 10 + c - '0';
    	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {putchar('-');x = -x;}
    if(x >= 10) out(x / 10);
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,M,sumE,head[MAXN];
char s[MAXN];
int vis[MAXN][2];
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void Init() {
    read(N);read(M);
    scanf("%s",s + 1);
    int u,v;
    for(int i = 1 ; i <= M ; ++i) {
	read(u);read(v);add(u,v);add(v,u);
    }
}
bool dfs(int u,char c) {
    if(vis[u][c - 'A'] != -1) return vis[u][c - 'A'];
    vis[u][c - 'A'] = 0;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(c == s[v]) {
	    int t = (s[u] - 'A') ^ 1;
	    vis[u][c - 'A'] = 1;
	    bool f = dfs(v,'A' + t);
	    if(!f) {vis[u][c - 'A'] = 0;}
	    else break;
	}
    }
    return vis[u][c - 'A'];
}
void Solve() {
    memset(vis,-1,sizeof(vis));
    for(int i = 1 ; i <= N ; ++i) {
	if(dfs(i,'A') && dfs(i,'B')) {puts("Yes");return;}
    }
    puts("No");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}


Measured memory_bytes: 11904
n = int(input())

w = [0]*n
used = []

for i in range(n):
  w[i] = input()
  
for i in range(n-1):
  if(w[i][-1] != w[i+1][0] or w[i] in used):
    print("No")
    exit()
  used.append(w[i])
#print(w)

if(w[n-1] not in used):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 38512
import scala.io.StdIn._

import Math._
object Main extends App {
  val Seq(xp1, yp1, xp2, yp2) = readLine.split(' ').map(_.toDouble).toList
  val vx1 = xp2 - xp1
  val vy1 = yp2 - yp1


  val q = readLine.toInt
  for (i <- 0 until q) {
    val Seq(x, y) = readLine.split(' ').map(_.toDouble).toList
    val vx2 = x - xp1
    val vy2 = y - yp1

    val c = (vx1 * vx2 + vy1 * vy2) / (vx1 * vx1 + vy1 * vy1)

    val ux = c * vx1 + xp1
    val uy = c * vy1 + yp1

    println("%.10f %.10f".format(2*ux - x, 2*uy - y))
  }
}



Measured memory_bytes: 55120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  string s;
  cin >> s;
  
  int ans = 0;
  rep(i, 6) if (s[i] == '1') ans++;
  cout << ans << '\n';


  

  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<climits>

#define forn(x,n,s) for(int i = x; i < n; i += s )
#define forr(x,n,s) for(int i = x; i>=n; i -= s)

using namespace std;

void go(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  #ifndef ONLINE_JUDGE
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
  #endif
} 
long long int mod = 1e9+7;
int bit;
vector<vector<int>> memo;

int helper(vector<vector<int>>& arr,int index,int mask){
    if(mask == (1<<bit)-1) return 1;
    if(index == arr.size()) return 0;
    if(memo[index][mask]!=-1) return memo[index][mask];
    int include = 0;
    for(int i = 0; i < bit;i++){
        if((mask&(1<<i))==0 and arr[index][i]==1){
            include += helper(arr,index+1,mask|(1<<i)); 
            include %= mod;
        }
    }
    memo[index][mask] = include;
    return include;
}


int main(){
    go(); 

    // code here
   
    int n;cin>>n;
    bit = n;
    vector<vector<int>> arr(n,vector<int>(n));
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n;j++){
            cin>>arr[i][j];
        }
    } 
    memo.resize(n,vector<int>(1<<n,-1));
    int sol = helper(arr,0,0);
    sol %= mod;
    cout<<sol;
   
    
}






Measured memory_bytes: 183512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    cout << (1900 * M + 100 * (N - M) ) * (1LL << M) << endl;
}

Measured memory_bytes: 256
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#define rp(i,a,b) for(int (i)=(int)(a);i<(int)(b);++i)

typedef long long ll;


using namespace std;


int main(){
    int a,b,c;
    vector<int> x;
    cin>>a>>b>>c;
    x.push_back(a);
    x.push_back(b);
    x.push_back(c);
    sort(x.begin(),x.end());
    cout<<x[0]<<" ";
    cout<<x[1]<<" ";
    cout<<x[2]<<endl;
    
    return 0;
};

Measured memory_bytes: 3148
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
#include<cmath>
using namespace std;
typedef pair<int,int> pii;
pii sgs[10];
#define MO 998244353
#define MAXN 200007
int dp[MAXN];
int s[MAXN];
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n,k; cin >> n >> k;
	for(int i=0; i<k; i++) {
		cin>>sgs[i].first>>sgs[i].second;
	}
	dp[1]=1; s[1]=1; s[0]=0;
	for(int i=2; i<=n; i++) {
		dp[i]=0;
		for(int j=0; j<k; j++) {
			if(i-sgs[j].first>0) {
				int r=i-sgs[j].first;
				int l=i-sgs[j].second-1; if(l<0) l=0;
				dp[i]=(dp[i]+s[r]-s[l])%MO;
				if(dp[i]<0) dp[i]+=MO;
			}
		}
		s[i]=(s[i-1]+dp[i])%MO;
	}
	cout << dp[n] << '\n';
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int V,E;


vector<vector<int>> G(15,vector<int>(15,INF));

vector<vector<int>> dp((1<<15), vector<int>(15,-1));

int rec(int bit, int v){

    if (dp[bit][v] >= 0) return dp[bit][v];//メモ化

    if(bit==0){//初期化
        if(v==0){
            return 0;
        }else{
            return INF;
        }
    }

    if((bit&(1<<v)) == 0) return INF;//、矛盾する状態なら

    dp[bit][v] = INF;//ここからdp

    REP(i,V){
        dp[bit][v] = min(dp[bit][v], rec(bit^(1<<v),i) + G[i][v]);
    }
    return dp[bit][v];
}

int main() {
    cin >> V >> E;
    REP(i, E){
        int s,t,d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }

    int ans = rec((1<<V)-1, 0);

    if(ans == INF) ans = -1;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6164