akhauriyash/Code-Regression huggingface dataset:
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    int n = input<int>();
    int m = input<int>();

    vector<vector<int>> tm(n, vector<int>(m, -1));

    std::queue<pair<int, int>> q;
    for (int i = 0; i != n; ++i)
        for (int j = 0; j != m; ++j)
            if (input<char>() == '#') {
                tm[i][j] = 0;
                q.emplace(i, j);
            }

    int ans = 0;
    while (not q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        q.pop();
        
        int dx[4] = {-1, +1, 0, 0};
        int dy[4] = {0, 0, -1, +1};

        for (int t = 0; t != 4; ++t)
            if (0 <= i + dx[t] and i + dx[t] < n and 0 <= j + dy[t] and j + dy[t] < m and tm[i + dx[t]][j + dy[t]] == -1) {
                tm[i + dx[t]][j + dy[t]] = tm[i][j] + 1;
                ans = max(ans, tm[i][j] + 1);
                q.emplace(i + dx[t], j + dy[t]);
            }
    }


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


Measured memory_bytes: 12432
# -*- coding: utf-8 -*-

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

l = [0] * (N + 1)
l[0] = (p[0] + 1) / 2
for i in range(1, N + 1):
    l[i] = l[i - 1] + (p[i - 1] + 1) / 2

ans = 0
for i in range(N - K + 1):
    if ans < l[i + K] - l[i]:
        ans = l[i + K] - l[i]

print(ans)


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

int main() {
    ios::sync_with_stdio(false);
    long long a, b;
    char c;
    cin >> a >> c >> b;
    if (c == '+')
        cout << a + b << "\n";
    else if (c == '-')
        cout << a - b << "\n";
    
    return 0;
}

Measured memory_bytes: 256
/*
[abc130] E - Common Subsequence
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;

const int MAX_N = 2e3;
const int MOD = 1e9 + 7;

class gf {
public:
    int n;
    gf() : n(0) {}
    gf(int n) : n(n % MOD) {}
    gf operator+(const gf x) const { return gf((n + x.n) % MOD); }
    gf operator-(const gf x) const { return gf((n - x.n + MOD) % MOD); }
};

int N, M;
int s[MAX_N], t[MAX_N];
gf dp[MAX_N + 1][MAX_N + 1], sum[MAX_N + 1][MAX_N + 1];

ll solve() {
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = sum[i - 1][j - 1] + 1;
            }
            sum[i][j] =
                sum[i - 1][j] + sum[i][j - 1] - sum[i - 1][j - 1] + dp[i][j];
        }
    }

    gf ans = sum[N][M] + 1;
    return ans.n;
}

int main() {
    cin >> N >> M;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
    }
    for (int j = 0; j < M; j++) {
        cin >> t[j];
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 31616
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

int erase(vvi &m) {
  int score = 0;
  rep(i, m.size()) {
    vi &ln = m[i];
    rep(j, 3) {
      if (ln[j] == 0) continue;
      if (ln[j] != ln[j + 1] || ln[j + 1] != ln[j + 2]) continue;
      if (j >= 2 || ln[j + 2] != ln[j + 3]) {
        score += ln[j] * 3;
        loop(k, j, j + 3) ln[k] = 0;
        break;
      }
      if (j >= 1 || ln[j + 3] != ln[j + 4]) {
        score += ln[j] * 4;
        loop(k, j, j + 4) ln[k] = 0;
        break;
      }
      score += ln[j] * 5;
      loop(k, j, j + 5) ln[k] = 0;
      break;
    }
  }
  return score;
}

void fall(vvi &m) {
  for (;;) {
    bool updated = false;
    for (int i = m.size() - 1; i > 0; i--) {
      rep(j, 5) if (m[i][j] == 0) {
        if (m[i - 1][j] != 0) {
          updated = true;
          for (int k = i; k > 0; k--) m[k][j] = m[k - 1][j];
          m[0][j]                             = 0;
        }
      }
    }
    if (!updated) break;
  }
}

void solve() {
  int h;
  while (cin >> h, h) {
    vvi m(h, vi(5));
    rep(i, h) rep(j, 5) cin >> m[i][j];
    int score = 0;
    for (;;) {
      bool updated             = false;
      int erased               = erase(m);
      if (erased != 0) updated = true;
      score += erased;
      fall(m);
      if (!updated) break;
    }
    cout << score << endl;
  }
}

Measured memory_bytes: 3116
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#include <cmath>
const int N = 1005;
typedef long long ll;
typedef long double db; 
const ll INF = 0x3f3f3f3f3f3f3f3f; 
#define mp(i, j) make_pair(i, j)
#define pdi pair<db, int>
#define fir first
#define sec second
using namespace std;

int sx, sy, tx, ty, x[N], y[N], r[N], S, T, n, vis[N];
db dis[N], d[N][N]; 
priority_queue<pdi, vector<pdi >, greater<pdi > > q; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

void dijkstra()
{
	for(int i = 1; i <= T; i++) dis[i] = INF * 2; 
	dis[S] = 0, q.push(mp(dis[S], S)); 
	while(!q.empty())
	{
		int u = q.top().sec; q.pop();
		if(vis[u]) continue; vis[u] = 1;
		for(int v = 1; v <= T; v++)
		{
			if(v == u) continue; 
			if(dis[v] > dis[u] + d[u][v]) dis[v] = dis[u] + d[u][v], q.push(mp(dis[v], v)); 
		}
	}
}

db getdis(int x1, int y1, int x2, int y2)
{
	return sqrt(1ll * (x1 - x2) * (x1 - x2) + 1ll * (y1 - y2) * (y1 - y2)); 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin); 
#endif
	sx = read <int> (), sy = read <int> (), tx = read <int> (), ty = read <int> (); 
	n = read <int> (), S = n + 1, T = S + 1, x[S] = sx, y[S] = sy, x[T] = tx, y[T] = ty; 
	for(int i = 1; i <= n; i++)
		x[i] = read <int> (), y[i] = read <int> (), r[i] = read <int> ();
	for(int i = 1; i <= T; i++)
		for(int j = 1; j <= T; j++)
		{
			d[i][j] = getdis(x[i], y[i], x[j], y[j]) - r[i] - r[j];
			if(d[i][j] < 0) d[i][j] = 0; 
		}
	dijkstra(), printf("%.10Lf\n", dis[T]); 
	return 0; 
}


Measured memory_bytes: 26804
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>
#include <string>
#include <locale>
#include <iomanip>
#include <cstring>

#define nl '\n'

using namespace std;

long long n, k, h, x;

vector<long long> v;


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

    if(k >= n){
        cout << 0;
        return 0;
    }

    for(long long i = 0; i < n; i++){
        cin >> h;
        v.push_back(h);
    }

    sort(v.rbegin(), v.rend());


    for(long long i = k; i < n; i++){
        x = x + v[i];
    }

    cout << x;





}

//g++ -std=c++14 comp.cpp -o b; ./b.exe
//g++ -std=c++14 comp.cpp && ./a.out

Measured memory_bytes: 2420
def examA():
    N = I()
    A = LI()
    cur = 0
    for a in A:
        cur ^= a
    if cur==0:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)
    return

def examB():
    N, M = LI()
    V = [[]for _ in range(N)]
    for _ in range(M):
        a, b = LI()
        a -= 1; b -= 1
        V[a].append(b)
        V[b].append(a)
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':
    examA()

"""

"""

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

int main(){

    ll n,k;
    cin >> n >> k;

    ll t = n%k;
    cout << min(t, k-t) << endl;
    
    return 0;
} 


Measured memory_bytes: 3628
import java.util.Scanner;
import java.util.Stack;

/**
 * @author yousack
 */
public class Main {
    static Scanner in = new Scanner(System.in);

    public static void main(String[] args) {
        String s;
        while (!(s = in.nextLine()).equals(".")) {
            Stack<Character> parens = new Stack<Character>();
            boolean ok = true;
            
            for (char c : s.toCharArray()) {
                if (c == '(' || c == '[') {
                    parens.push(c);
                } else if (c == ')') {
                    if (!parens.empty() && parens.peek() == '(') {
                        parens.pop();
                    } else {
                        ok = false;
                        break;
                    }
                } else if (c == ']') {
                    if (!parens.empty() && parens.peek() == '[') {
                        parens.pop();
                    } else {
                        ok = false;
                        break;
                    }
                }
            }

            if (ok && parens.empty()) {
                System.out.println("yes");
            } else {
                System.out.println("no");
            }
        }
    }
}

Measured memory_bytes: 34228
x, y = map(int, input().split())
     
A = [1, 3, 5, 7, 8, 10, 12]
B = [4, 6, 9, 11]
C = [2]
     
if (x in A and y in A) or (x in B and y in B) or (x in C and y in C):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i, n) for(int i = 0; i < (int)n; i++)
 
typedef long long ll;
ll mod=998244353;
ll dp[310][90010];
ll dp2[310][90010];
int main()
{
	int n;
	int a[310];
	int sum=0;
	cin >> n;
	rep(i, n)
	{
		cin >> a[i];
		sum+=a[i];
	}
	ll beki=1;
	rep(i, n) beki=(beki*2)%mod;
	dp[0][0]=beki;
	ll inv=(mod+1)/2;
	rep(i, n)
	{
		rep(j, 90001) dp[i+1][j]=dp[i][j];
		rep(j, 90001-a[i]) dp[i+1][j+a[i]]=(dp[i+1][j+a[i]]+inv*dp[i][j])%mod;
	}
	dp2[0][0]=mod-2;
	rep(i, n)
	{
		rep(j, 90001) dp2[i+1][j]=dp2[i][j];
		rep(j, 90001-a[i]) dp2[i+1][j+a[i]]=(dp2[i+1][j+a[i]]+dp2[i][j])%mod;
	}
	ll tmp=0;
	rep(i, 90001)
	{
		if(2*i>=sum)
		{
			tmp=(tmp+dp[n][i])%mod;
			tmp=(tmp+dp2[n][i])%mod;
		}
	}
	tmp=(3*tmp)%mod;
	ll feki=1;
	rep(i, n) feki=(feki*3)%mod;
	ll ans=(3*mod+feki-3*beki+3)%mod;
	ans=(ans+mod-tmp)%mod;
	ans=(ans+mod-3)%mod;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main() {
  int N, H, a, MA{}, ans{};
  cin >> N >> H;
  vector<int> b(N);
  for (int i = 0; i != N; ++i) {
    cin >> a >> b[i];
    MA = max(MA, a);
  }
  sort(rbegin(b), rend(b));
  for (int i = 0; i != N; ++i) {
    if (H <= 0 || b[i] < MA) break;
    ++ans;
    H -= b[i];
  }
  if (H > 0) ans += (H-1) / MA + 1;
  cout << ans << endl;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
 
#define rep(i,x) for(int i=0;i<x;i++)    
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rep_to(a,i,x) for(int i=a;i<x;i++)
 
using namespace std;
 
int main()
{
    int N,Q;
    while(cin >> N >> Q && N)
    {
        int M;
        int data[100000]={};
        int day=0,ans=0,mx=0;
         
        while(N--)
        {
            cin >> M;
            while(M--)
            {   
                cin >> day;
                data[day]++;
            	if(mx < data[day] && Q <= data[day])
            	{
            		mx=data[day];
            		ans=day;
            	}
            	else if(mx == data[day])ans=min(day,ans);
            }
        }
 
        if(M)cout << ans << endl;
        else cout << "0" << endl;
    }
 
    return 0;
}

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

int main(){
    
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a>=c){
        if(b<d){
            cout << max(0,b-a) << endl;
            return 0;
        }else{
            cout << max(0,d-a) << endl;
            return 0;
        }
    }else{
        if(b<d){
            cout << max(0,b-c) << endl;
            return 0;
        }else{
            cout << max(0,d-c) << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 384
#include <stdio.h>

void swap ( int *x, int *y ) {
  int temp = *y;
  *y = *x;
  *x = temp;
}

void trace ( int A[], int N ) {
  for ( int i = 0; i < N ; i++ ) {
    printf ( "%d", A[i] );
    if ( i == N - 1 )
      break;
    printf( " " );
  }
  putchar ( '\n' );
}

void bubble ( int A[], int N, int cnt ) {
  for ( int i = 0; i < N - 1; i++ ) {
    for (int j = 0; j < N - 1 - i; j++ ) {
      if ( A[j] > A[j+1] ) {
        swap ( &A[j], &A[j+1]);
        cnt++;
      }
    }
  }
  trace ( A, N );
  printf( "%d\n", cnt );
}

int main ( void ) {
  int i, N; int cnt = 0;
  int A[100];
  scanf ( "%d", &N );
  for ( i = 0; i < N; i++ ) {
    scanf ( "%d", &A[i] );
  }
  bubble ( A, N, cnt );

}



Measured memory_bytes: 2080
import java.awt.Point;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			char[] msg = sc.next().toCharArray();
			Point swap[] = new Point[n];
			for (int i = n - 1; i >= 0; i--) {
				swap[i] = new Point(sc.nextInt(), sc.nextInt());
			}
			for (int i = 0; i < n; i++) {
				int a = swap[i].x;
				int b = swap[i].y;
				int dis = Math.abs(a - b);
				msg[a - 1] = (char) ('a' + (((msg[a - 1] - 'a') + dis) % 26));
				msg[b - 1] = (char) ('a' + (((msg[b - 1] - 'a') + dis) % 26));
				char c = msg[a - 1];
				msg[a - 1] = msg[b - 1];
				msg[b - 1] = c;
			}
			StringBuilder sb = new StringBuilder();
			sb.append(msg);
			System.out.println(sb.toString());
		}
	}

}

Measured memory_bytes: 12000
#include <stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
	int p,l,r;
}; 

struct Node T[MAX];

int n;

//??????
void inParse(int u){
	if(u==NIL) return;
	inParse(T[u].l);
	printf(" %d",u);
	inParse(T[u].r);
} 

//??????
void postParse(int u){
	if(u==NIL) return;
	postParse(T[u].l);
	postParse(T[u].r);
	printf(" %d",u);
} 

//??????
void preParse(int u){
	if(u==NIL) return;
	printf(" %d",u);
	preParse(T[u].l);
	preParse(T[u].r);
} 

int main(){
	int i,j,v,l,r,root;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		T[i].p=NIL;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].l=l;
		T[v].r=r;
		if(l!=NIL) T[l].p=v;
		if(r!=NIL) T[r].p=v;
	}
	
	for(i=0;i<n;i++)  if(T[i].p==NIL) root=i;
	
		printf("Preorder\n");
		preParse(root);
		printf("\n");
		printf("Inorder\n");
		inParse(root);
		printf("\n");
		printf("Postorder\n");
		postParse(root);
		printf("\n");
	return 0;
}

Measured memory_bytes: 620
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

uint32_t popcnt(uint32_t val){
  uint32_t cnt = 0;
  while(val){
    cnt += val % 2;
    val /= 2;
  }
  return cnt;
}

int main() {
  uint32_t N = 0;
  std::cin >> N;
  std::string X;
  std::cin >> X;

  uint32_t X_cnt = 0;
  for(size_t i = 0; i < N; i++) if(X[i]=='1') X_cnt++;

  std::vector<std::vector<uint32_t>> digit_mod(2, std::vector<uint32_t>(N+1,0));
  for (size_t f = 0; f < 2; f++)
  {
    if(X_cnt <= 1 && f == 1) continue;
    uint32_t mod = X_cnt + (f ? -1 : 1), X_mod = 0;

    for (size_t i = 0, val = 1; i < N; val *= 2, i++){
      digit_mod[f][i] = val % mod;
      val = digit_mod[f][i];
      if(X[N-1-i]=='1') X_mod = (X_mod + val) % mod;
    }
    digit_mod[f][N] = X_mod;
  }

  for (size_t i = 0; i < N; i++)
  {
    bool flag = (X[i] == '1');
    uint32_t mod = X_cnt + (flag ? -1 : 1), Xi_mod = digit_mod[flag][N];

    if(mod == 0){
      std::cout << 0 << std::endl;
      continue;
    }

    if(flag){
      if(Xi_mod >= digit_mod[flag][N-1-i]){
        Xi_mod = (Xi_mod - digit_mod[flag][N-1-i]) % mod;
      }else{
        Xi_mod = (mod + Xi_mod - digit_mod[flag][N-1-i]) % mod;
      }
    }else{
      Xi_mod = (Xi_mod + digit_mod[flag][N-1-i]) % mod;
    }

    uint32_t func = 1;
    while(Xi_mod > 0){
      mod = popcnt(Xi_mod);
      Xi_mod %= mod;
      func++;
    }

    std::cout << func << std::endl;
  }

  return 0;
}

Measured memory_bytes: 5968
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const double PI = acos(-1.0);

/* typedef */

template <typename T>
struct Pt {
  T x, y;

  Pt() {}
  Pt(T _x, T _y) : x(_x), y(_y) {}
  Pt(const Pt& pt) : x(pt.x), y(pt.y) {}

  bool operator==(const Pt pt) const { return x == pt.x && y == pt.y; }
  Pt<T> operator+(const Pt pt) const { return Pt<T>(x + pt.x, y + pt.y); }
  Pt<T> operator-() const { return Pt<T>(-x, -y); }
  Pt<T> operator-(const Pt pt) const { return Pt<T>(x - pt.x, y - pt.y); }
  Pt<T> operator*(T t) const { return Pt<T>(x * t, y * t); }
  Pt<T> operator/(T t) const { return Pt<T>(x / t, y / t); }
  T dot(Pt v) const { return x * v.x + y * v.y; }
  T cross(Pt v) const { return x * v.y - y * v.x; }
  Pt<T> mid(const Pt pt) { return Pt<T>((x + pt.x) / 2, (y + pt.y) / 2); }
  T d2() { return x * x + y * y; }
  double d() { return sqrt(d2()); }

  Pt<T> rot(double th) {
    double c = cos(th), s = sin(th);
    return Pt<T>(c * x - s * y, s * x + c * y);
  }

  Pt<T> rot90() { return Pt<T>(-y, x); }

  bool operator<(const Pt& pt) const {
    return x < pt.x || (x == pt.x && y < pt.y);
  }

  void print(string format) {
    printf(("(" + format + ", " + format + ")\n").c_str(), x, y);
  }
  void print() { print("%.6lf"); }
};

typedef Pt<double> pt;

/* global variables */

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    double d;
    cin >> n >> d;
    if (n == 0) break;
    //printf("n=%d, d=%d\n", n, (int)d);

    pt lp(-d, 0), rp(d, 0);

    while (n--) {
      //cout << "lp:"; lp.print();
      //cout << "rp:"; rp.print();
      
      double lsp, rsp, t;
      cin >> lsp >> rsp >> t;
      //printf("lsp=%lf, rsp=%lf, t=%lf\n", lsp, rsp, t);

      pt cp = (lp + rp) / 2;
      pt v = rp - lp;
      pt dv = v / v.d();

      if (lsp == rsp) {
	pt nv = dv.rot90();
	//cout << "nv:"; nv.print();
	double len = t * lsp * PI / 180;
	pt nlv = nv * len;
	//cout << "nlv:"; nlv.print();
	lp = lp + nlv;
	rp = rp + nlv;
      }
      else {
	double r = (lsp + rsp) * d / (lsp - rsp);
	//printf("r=%lf\n", r);
	pt rc = cp + dv * r;
	double th =
	  t * PI / 180 * ((lsp != 0.0) ? -lsp / (r + d): -rsp / (r - d));
	lp = (lp - rc).rot(th) + rc;
	rp = (rp - rc).rot(th) + rc;
      }
    }

    pt fp = (lp + rp) / 2;

    printf("%.5lf\n", fp.x);
    printf("%.5lf\n", fp.y);
  }

  return 0;
}

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

struct UnionFind{
  Int n;
  vector<Int> r,p;
  UnionFind(){}
  UnionFind(Int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
  Int find(Int x){
    return (x==p[x]?x:p[x]=find(p[x]));
  }
  bool same(Int x,Int y){
    return find(x)==find(y);
  }
  void unite(Int x,Int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(r[x]<r[y]) swap(x,y);
    r[x]+=r[y];
    p[y]=x;
  }
};

//INSERT ABOVE HERE
using P = pair<Int, Int>;
map<P, Int> mem;
Int cnt=0;
Int ask(Int a,Int b){
  if(mem.count(P(a,b))) return mem[P(a,b)];
  cnt++;
  cout<<"? "<<a<<" "<<b<<endl;
  string c;
  cin>>c;
  return mem[P(a,b)]=(c=="Y");
}

signed main(){
  Int a,b;
  cin>>a>>b;
  if(a<=b){
    cout<<"Impossible"<<endl;
    return 0;
  }
  Int n=a+b;
  UnionFind uf(n);
  queue<Int> q;
  for(Int i=0;i<n;i++) q.emplace(i);
  Int h=-1;
  while(!q.empty()){
    queue<Int> nx;
    while(q.size()>1u){
      Int x=q.front();q.pop();
      Int y=q.front();q.pop();
      Int u=ask(x,y);
      if(!u) continue;
      Int v=ask(y,x);
      if(!v) continue;
      nx.emplace(x);
      uf.unite(x,y);
    }
    if(nx.empty()){
      h=q.front();q.pop();
      break;
    }
    if(!q.empty()&&(nx.size()%2==0)){
      nx.emplace(q.front());q.pop();
    }
    swap(q,nx);
    //cout<<"----"<<endl;
  }
  
  string ans;
  for(Int i=0;i<n;i++) ans+=char('0'+ask(h,uf.find(i)));
  cout<<"! "<<ans<<endl;
  //while(cnt>n*2);
  return 0;
}


Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int  main()
{
	int a,b,c; cin >> a >> b >> c;
	if (a + b == c)
		cout << "Yes" << endl;
	else if (a + c == b)
		cout << "Yes" << endl;
	else if (b + c == a)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

int main()
{

    ll n,i;
    cin>>n;
    ll arr[n];
    ll sum=0;
    map<ll,ll>m;
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        sum+=arr[i];
        m[arr[i]]+=1;
    }
    ll q;
    cin>>q;
    while(q--)
    {
        ll a,b;
        cin>>a>>b;
        sum-=m[a]*a;
        sum+=m[a]*b;
        m[b]+=m[a];
        m[a]=0;
        cout<<sum<<'\n';
    }
    return 0;
}

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

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


  int A[n][m];
  int b[m];
  int t;

  for (int i = 0; i <= n-1; i++){
    for (int j = 0; j <= m-1; j++){
      cin >> t;
      A[i][j] = t;
    }
  }

  for (int j = 0; j <= m-1; j++){
    cin >> t;
    b[j] = t;
  }

  //int c[n] = {};
  for (int i = 0; i <= n-1; i++){
    t = 0;

    for (int j = 0; j <= m-1; j++){
      t += A[i][j] * b[j];
    }
    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 3140
/*input
10
2184 2126 1721 1800 1024 2528 3360 1945 1280 1776
*/
#include<bits/stdc++.h>
using namespace std;

#define int long long 
#define double long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define RE(i,n) for (int i = 1; i <= n; i++)
#define RED(i,n) for (int i = n; i > 0; i--)
#define REPS(i,n) for(int i = 1; (i*i) <= n; i++)
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define WL(t) while(t --)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define print(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout << *it << " "; cout << endl;
#define debug(x) cout << x << endl;
#define debug2(x,y) cout << x << " " << y << endl;
#define debug3(x,y,z) cout << x << " " << y << " " << z << endl;
const int INF = 1e18+1;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;

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


void solve(){
     int n;cin >> n;
     int ans = 0;
     while(n--){
        int x;cin >> x;
        ans += log2(x&(-x));
     }
     cout << ans;
}

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

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

b = [0] * 60
for i in a:
    for j in range(60):
        b[j] += bool(i & (1 << j))
#print(b[j])
ans = 0
inf = int(1e9 + 7)
for i in range(60):
    ans += b[i] * (n - b[i]) * (1 << i) % inf
    ans %= inf
print(ans)

Measured memory_bytes: 122936
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    int b[n], c[n];
    rep(i, n) cin >> b[i];
    rep(i, n - 1) cin >> c[i];
    int ans = 0;
    rep(i, n){
        ans += b[a[i] - 1];
        if(i + 1 < n)if(a[i + 1] - a[i] == 1 ){
            ans += c[a[i] - 1];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main(){
  int p,q,r;
  cin >> p >> q >> r;
  int min = p+q;
  if(q+r<min) min = q+r;
  if(p+r<min) min = p+r;
  cout << min << endl;

}


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

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

	vector<int> v(n);
	for (auto& i : v) {
		cin >> i;
	}

	sort(v.rbegin(), v.rend());

	long long ret = 0;
	priority_queue<pair<int,pair<int,int>>> q;
	q.push({ v[1], { v[1], v[0] } });
	q.push({ v[1], { v[1], v[0] } });
	ret = v[0];

	for (int i = 2; i < n; ++i) {
		const pair<int, pair<int, int>>& t = q.top();
		ret += t.first;
		q.push({ v[i], { v[i], t.second.first } });
		q.push({ v[i], { v[i], t.second.second } });
		q.pop();
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 7200
while True:
    M,T,P,R=map(int,raw_input().split())
    if M==T==P==R==0:break
    PB=[[False]*P for i in range(T+1)]
    PN=[[0]*P for i in range(T+1)]
    TM=[M]*(T+1)
    for i in range(R):
        m,t,p,r=map(int,raw_input().split())
        if r==0:
            PB[t][p-1]=True
            TM[t]+=m
        else:
            PN[t][p-1]+=1
    for i in range(1,T+1):
        for j in range(P):
            if PB[i][j]:
                TM[i]+=PN[i][j]*20
    solved=[sum(i) for i in PB]
    ans=[]
    for i in range(1,T+1):
        ans.append((-solved[i],TM[i],i))
    import operator
    ans=ans[::-1]
    ans.sort(key=operator.itemgetter(1))
    ans.sort(key=operator.itemgetter(0))
    s=str(ans[0][2])
    for i in range(1,T):
        if (ans[i][0]!=ans[i-1][0]) or (ans[i][1]!=ans[i-1][1]):
            s+=","+str(ans[i][2])
            continue
        s+="="+str(ans[i][2])
    print s

Measured memory_bytes: 4452
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int d1,d2;
	int a[2][n];
	for(int i=0;i<n;i++)
	{
		cin>>a[0][i]>>a[1][i];
	}
	int flag=0;
	for(int i=2;i<n;i++)
	{
		if((a[0][i-2]==a[1][i-2])&&(a[0][i-1]==a[1][i-1])&&(a[0][i]==a[1][i]))
		{
			flag=1;
			break;
		}
	}
	if(flag==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

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

int main() {
  int n;
  cin >> n;
  for(int i = 1;i < 10;i++){
    for(int j = 1;j < 10;j++){
      if(i*j == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
 
  main(){
    int x[5],y[5],min=1000,s=0,sum=0,i; 
    
    for(i=0;i<5;i++){
     scanf("%d",&x[i]);
     y[i]=x[i];
    }
    
    for(i=0;i<5;i++){
        x[i]=x[i]%10;
          if(min>x[i]&&x[i]!=0){
            min=x[i];
             s=i;  
          }
    }
    
     for(i=0;i<5;i++){
      if(i!=s){
        if(y[i]%10!=0)
        sum +=(y[i]/10+1)*10;
        else
          sum +=y[i];
      }
    }
    printf("%d",sum+y[s]);
} 


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
}
template<class T> inline void chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
}

typedef complex<long double> co;
const long double EPS = 1e-10;
bool EQ(long double a, long double b) {
    return (abs(a-b) < EPS);
}
bool EQV(co a, co b) {
    return EQ(a.real(), b.real()) and EQ(a.imag(), b.imag());
}

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

    ll N;
    cin >> N;
    vector<co> points(N);
    Rep (i, N) {
        long double a, b;
        cin >> a >> b;

        points[i] = {a, b};
    }

    long double xl = 0, xr = 1000;
    long double ans = inf;
    Rep (i, 100) {
        long double x1 = (2*xl + xr) / 3;
        long double x2 = (xl + 2*xr) / 3;
        long double yl = 0, yr = 1000;
        Rep (j, 100) {
            long double y1 = (2*yl + yr) / 3;
            long double y2 = (yl + 2*yr) / 3;
            long double f1 = 0, f2 = 0;
            Rep (k, N) {
                chmax(f1, abs(co(x1, y1) - points[k]));
                chmax(f2, abs(co(x1, y2) - points[k]));
            }
            if (f1 < f2) yr = y2;
            else yl = y1;
        }

        long double g1 = 0, g2 = 0;
        Rep (k, N) {
            chmax(g1, abs(co(x1, yr) - points[k]));
        }

        yl = 0; yr = 1000;
        Rep (j, 100) {
            long double y1 = (2*yl + yr) / 3;
            long double y2 = (yl + 2*yr) / 3;
            long double f1 = 0, f2 = 0;
            Rep (k, N) {
                chmax(f1, abs(co(x2, y1) - points[k]));
                chmax(f2, abs(co(x2, y2) - points[k]));
            }
            if (f1 < f2) yr = y2;
            else yl = y1;
        }

        Rep (k, N) {
            chmax(g2, abs(co(x2, yr) - points[k]));
        }

        if (g1 < g2) {
            xr = x2;
        } else xl = x1;

        chmin(ans, g1);
        chmin(ans, g2);        
    }

    // cout << xl << " " << xr << "\n";

    cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 256
from collections import deque
def main():
  N, M, *L = map(int, open(0).read().split())
  dic = [[] for i in range(N+1)]
  par =  ['0']*N
  cnt = [0]*(N+1)
  cnt[0] = 1
  for a,b in zip(*[iter(L)]*2):
    dic[a].append(b)
    cnt[b] += 1

  for i, m in enumerate(cnt):
    if m==0:
      q = deque([i])
      break
  
  while q:
    m = q.popleft()
    for c in dic[m]:
      cnt[c] -= 1
      if cnt[c]==0:
        par[c-1] = str(m)
        q.append(c)

  ans = '\n'.join(par)
  print(ans)
  
if __name__== '__main__':
  main()

Measured memory_bytes: 31860
import java.util.Scanner;

/** AOJ_No.1192 ICPC_2014_A */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			int x = sc.nextInt();/* 変更前消費税率(%) */
			int y = sc.nextInt();/* 変更後消費税率(%) */
			int s = sc.nextInt();/* 消費税変更前、2商品合計価格 */
			if(x == 0) break;
			
			int max = 0;/* 消費税変更後、2商品合計の最大額 */
			for(int i = 1; i < s; i++) {
				for(int j = s - 1; j > 0; j--) {
					/* 各値段で小数点切り下げする事に注意 */
											
					/* 消費税変更前、2商品の価格の割り出し */
					int tmp = (int)((i * (100 + x)) / 100.0) + (int)((j * (100 + x)) / 100.0);
					if(tmp == s) {
						/* 税込み合計が同じなので、条件を満たす
						 * 変更後の税込み後を計算 */
						int sum = (int)((i * (100 + y)) / 100.0) + (int)((j * (100 + y)) / 100.0);
						if(max < sum) max = sum;
					}
				}
			}
			System.out.println(max);
		}
	}
}



Measured memory_bytes: 28844
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int A, B;
  cin >> A >> B;
  long long int ans = A;
  long long int cnt = 1;
  while (true)
  { if(B==1){
      cout << 0 << endl;
      break;
    }else{
      if(ans>=B){
        cout << cnt << endl;
        break;
      }else{
        ans -= 1;
        ans += A;
        cnt++;
      }
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>
#include <set>
#include <string>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;

using namespace std;

set<string> ss;

void dfs(int index, string s, string e){
    if(s.size()  == index){
        // sの末端まで見終わったらeをsetへ
        ss.insert(e);
        return;
    }
    if(s[index] == 'A'){
        // Aを加えない.
        dfs(index + 1, s, e);
    }
    dfs(index + 1, s, e + s[index]);
}

int main(){
    string s;
    cin >> s;
    string o = "AKIHABARA";
    dfs(0, o, "");
    cout << (ss.count(s) ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a,n,c=1;
int main()
{
    cin>>a>>n;
    for(int i=0;i<a;i++)
    {
        if(c>n)
        c+=n;
        else 
        c+=c;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
from collections import deque
n,u,v=map(int,input().split())
edge=[[] for i in range(n)]
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    edge[a].append(b)
    edge[b].append(a)
visitedu=[-1]*n
visitedv=[-1]*n
def bfs(s,visited):
    q=deque([s])
    visited[s]=0
    while q:
        x=q.popleft()
        for nx in edge[x]:
            if visited[nx]==-1:
                visited[nx]=visited[x]+1
                q.append(nx)
    return
bfs(u-1,visitedu)
bfs(v-1,visitedv)
a=0
b=10**10
for i in range(n):
    if visitedu[i]<visitedv[i]:
        a=max(a,visitedv[i])
    elif visitedu[i]==visitedv[i]:
        b=min(b,visitedv[i])
#print(visitedv)
#print(visitedu)
if b==10**10:
    b=-1
if a<=b:
    print(b)
else:
    print(a-1)

Measured memory_bytes: 29336
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

vector<pair<long long, long long> > prime_factorize(long long n) {
  vector<pair<long long, long long> > res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) { ++num; n /= p; }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}

void solve(long long N){
  ll ans = 0;
  vector<pair<ll,ll>> v = prime_factorize(N);
  for(auto p : v) {
    for(int i=1; p.second-i >= 0;i++) {
      p.second -= i;
      ans++;
    }
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  solve(N);
  return 0;
}



Measured memory_bytes: 3700
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

vi T = {0, 0, 1, 1};

vi color;
vector<vi> G;
vi used;
vector<vi> cnt;

void del(int v){
	used[v] = true;
	for(auto& nv : G[v]){
		if(used[nv]) continue;

		cnt[nv][color[v]]--;
    	if(cnt[nv][0] == 0 or cnt[nv][1] == 0){
    		del(nv);
    	}
	}
}

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

    int n, m; cin >> n >> m;
    color = vi(n);
    {
    	string in; cin >> in;
    	rep(i, n){
    		color[i] = (in[i] == 'A' ? 0:1);
    	}
    }

    G = vector<vi>(n);
    cnt = vector<vi>(n, vi(2));
    rep(loop, m){
    	int a, b; cin >> a >> b;
    	a--, b--;
    	G[a].emplace_back(b);
    	G[b].emplace_back(a);

    	cnt[a][color[b]]++;
    	cnt[b][color[a]]++;
    }

    used = vi(n);
    rep(i, n){
    	if(used[i]) continue;
    	if(cnt[i][0] == 0 or cnt[i][1] == 0){
    		del(i);
    	}
    }
    string res = "No";
    rep(i, n){
    	if(not used[i]) res = "Yes";
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 21908
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int n;
  cin>>n>>s;
  int i;
  if(s.size()<=n)
    cout<<s;
  else
  {
    for(i=0;i<n;i++)cout<<s[i];
    cout<<"...";
  }
  return 0;
}
  

Measured memory_bytes: 3620
n,k=map(int, input().split())
lst = []
for i in range(k):
    d = input()
    a = list(map(int, input().split()))
    for i in a:
        if i not in lst:
            lst.append(i)

ans = 0
for i in range(1, n+1):
    if i not in lst:
        ans += 1
print(ans)


Measured memory_bytes: 9184
def hoge(lst,i):
    if lst[i]==lst[i+1] and len(lst)>i+2:
        return hoge(lst,i+1)
    if lst[i]>lst[i+1]:return True
    if lst[i]<lst[i+1]:return False

N = int(input())
H = list(map(int,input().split()))
det=0

for i in range(N-1):
    if H[i]-1>H[i+1]:
        det+=1
        print("No")
        break
    if i+2<=N-1:
        if H[i]>H[i+1] and H[i+1] > H[i+2]:
            det+=1
            print("No")
            break
        if H[i]>H[i+1] and hoge(H,i+1):
            det+=1
            print("No")
            break
if det==0:print("Yes")

Measured memory_bytes: 14704
#include<iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;


int main()
{
    int h,w,k;
    cin >> h>>w>>k;

    vector<vector<int>> c(7, vector<int>(7, 0));
    vector<int> sumh(7, 0);
    vector<int> sumw(7, 0);

    for (int i = 0; i < h; i++) {
        char ch;
        for (int j = 0; j < w; j++) {
            cin >> ch;
            if (ch == '#') {
                c[i][j] = 1;
                sumh[i]++;
                sumw[j]++;
            }
        }
    }

    int bith, bitw;
    int total = 0, count = 0;

    for (bith = 0; bith < (1 << h); ++bith) {
        for (bitw = 0; bitw < (1 << w); ++bitw) {

            for (int i = 0; i < h; i++) {
                if (!(bith & 1 << i)) {
                    for (int j = 0; j < w; j++) {
                        if (!(bitw & 1 << j)) {
                            total += c[i][j];
                        }
                    }
                }
            }

            if (total == k) count++;
            total = 0;
        }
    }

    cout << count;

    return 0;
}



Measured memory_bytes: 3604
h,w,k = map(int,input().split())
s = [list(map(int,input().strip())) for i in range(h)]
from copy import deepcopy

ss = deepcopy(s)
for i in range(h):
    for j in range(w-1):
        ss[i][j+1] += ss[i][j]


def gru_hol(HOL): # セットから切り方を作る
    groups_a = []
    group_a = [0]
    for i in range(h-1):
        if(HOL[i] == 1):
            groups_a.append(group_a)
            group_a = [i+1]
        else:
            group_a.append(i+1)
    groups_a.append(group_a)
    return groups_a

def nex_hol(HOL): #次のセットを作る
    for j in range(h-1):
        if(HOL[j] == 0):
            HOL[j] = 1
            for k in range(0,j):
                HOL[k] = 0
            break
    return HOL

def cutsum(grp,lscut,nxcut): #groupのlastcut~nextcutのホワイトチョコを数える
    count = 0
    for i in grp:
        if(lscut != 0):
            count = count + ss[i][nxcut-1] - ss[i][lscut-1]
        else:
            count += ss[i][nxcut-1] 
    return count

def cutcheck(grp_a,lscut_a): #切ってもダメかチェック
    ct_a = 0
    for i in grp_a:
        ct_a += s[i][lscut_a]
    if(ct_a > k):
        return False
    else:
        return True

min_cut = h + w - 2
hol = [0]*(h-1)
for i in range(2**(h-1)):
    fl_ag = 0
    lastcut = 0
    cuts = 0 #切る回数
    groups = gru_hol(hol) #groupsを作る
    for j in range(1,w):
        flag = 0
        for group in groups:
            if(cutsum(group,lastcut,j+1) > k):
                if(cutcheck(group,lastcut) == False):
                    fl_ag = 1 #groupからやり直し
                    break
                else:
                    flag = 1
        if(fl_ag == 1):
            break
        if(flag == 1):
            cuts += 1
            lastcut = j

    if(cutcheck(group,w-1) == True):
        min_cut = min(min_cut,cuts+sum(hol))
    nex_hol(hol)

print(min_cut)

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

#define maxn 100005

int n,l[maxn<<1],r[maxn<<1],w[maxn<<1],cnt,rk[maxn<<1];

struct Node{
	int x,y,id;
}a[maxn];

bool cmp1(Node a,Node b)
{
	return a.x<b.x;
}


bool cmp2(Node a,Node b)
{
	return a.y<b.y;
}

int Dst(Node a,Node b)
{return min(abs(a.x-b.x),abs(a.y-b.y));}

bool cmp3(int a,int b)
{
	return w[a]<w[b];
}

int fa[maxn<<1];

int gf(int k)
{
	if (fa[k]==k) return k;
	else return fa[k]=gf(fa[k]);
}

int main()
{
	
	#ifdef WXL
	freopen("in.txt","r",stdin);
	#endif
	
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d%d",&a[i].x,&a[i].y),a[i].id=i;
	sort(a+1,a+n+1,cmp1);
	for (int i=1;i<n;++i) l[++cnt]=a[i].id,r[cnt]=a[i+1].id,w[cnt]=Dst(a[i],a[i+1]);
	sort(a+1,a+n+1,cmp2);
	for (int i=1;i<n;++i) l[++cnt]=a[i].id,r[cnt]=a[i+1].id,w[cnt]=Dst(a[i],a[i+1]);
	
	for (int i=1;i<=cnt;++i) rk[i]=i;
	sort(rk+1,rk+cnt+1,cmp3);
	
	long long ans=0;
	
	for (int i=1;i<=n;++i )fa[i]=i;

	for (int i=1;i<=cnt;++i){
		int L=l[rk[i]],R=r[rk[i]];
		if (gf(L)!=gf(R)){
			ans+=w[rk[i]];
			fa[gf(L)]=gf(R);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define fill(a,val)  memset(a,val, sizeof (a))
#define sort_unique(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(cont) cont.begin(), cont.end()
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define max4(a,b,c,d) max(max(a,d),max(b,c))
#define MAX   1e9
#define MIN  -1e9
#define PI 3.14159265358979
#define eps 1e-9
typedef map<int,int> mpi;
typedef set<int> seti;
typedef multiset<int> mseti;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i, n)    for(long long int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(long long int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(long long int i = a; i >= (n); --i)
#define repn(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define trav(a, x) for(auto& a : x)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define inp(a,start,len) for(long long int i = start;i < len;i++) cin>>a[i]
struct Interval{ll start,end;};
bool compare(Interval i1, Interval i2) {return (i1.start < i2.start);}

ll vish[200001],visv[200001];

int main(){
	fio;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll T = 1;
	// cin>>T;
	while(T--){
		ll n,q;
		cin>>n>>q;
		ll white = 2*n-1;
		set<pll> horiz,ver;
		ver.insert({n,n});
		horiz.insert({n,n});// length and then respective coordinate
		vish[n] = 1;
		visv[n] = 1;
		rep(i,q){
			ll type,x;
			cin>>type>>x;
			// cout<<white<<"\n";
			if(type == 1){// horizontally check in ver
				if(vish[x])
					continue;
				auto it = ver.lower_bound({x,MIN});
				white+=it->s-1;
				horiz.insert({it->s,x});
				vish[x] = 1;
			}
			else{
				if(visv[x])
					continue;
				auto it = horiz.lower_bound({x,MIN});
				white+=it->s-1;
				ver.insert({it->s,x});
				visv[x] = 1;
			}
		}
		ll notVis = 1;
		repA(i,2,n){
			if(!vish[i])
				notVis++;
			if(!visv[i])
				notVis++;
		}
		// cout<<white<<"\n";
		cout<<n*n-notVis-white;
	}
	return 0;
}


Measured memory_bytes: 19232